ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/kiesel/TreeWriter/treeWriter.cc
(Generate patch)

Comparing UserCode/kiesel/TreeWriter/treeWriter.cc (file contents):
Revision 1.3 by kiesel, Thu Mar 21 09:01:14 2013 UTC vs.
Revision 1.4 by kiesel, Mon Mar 25 12:00:06 2013 UTC

# Line 1 | Line 1
1   #include<iostream>
2 + #include<math.h>
3  
4   #include "TFile.h"
5   #include "TTree.h"
# Line 24 | Line 25 | class TreeWriter {
25                  TFile *outFile;
26                  TTree *tree;
27  
28 +                float getPtFromMatchedJet( susy::Photon, susy::Event );
29 +                float deltaR( TLorentzVector, TLorentzVector );
30 +
31          private:
32                  int processNEvents; // number of events to be processed
33                  int reportEvery;
# Line 34 | Line 38 | class TreeWriter {
38                  std::vector<tree::Jet> jet;
39                  float met;
40                  int nVertex;
41 +                int nElectron;
42                  float weight;
38                float leadingPhotonPt;
43   };
44  
41
45   TreeWriter::TreeWriter(TString inputName, TString outputName) {
46          // read the input file
47          inputFile = new TFile( inputName, "read" );
# Line 62 | Line 65 | TreeWriter::~TreeWriter() {
65          delete inputTree->GetCurrentFile();
66   }
67  
68 + float TreeWriter::deltaR( TLorentzVector v1, TLorentzVector v2 ) {
69 +        return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) );
70 + }
71 +
72 + float TreeWriter::getPtFromMatchedJet( susy::Photon photon, susy::Event event ) {
73 +        /**
74 +         * \brief Takes jet p_T as photon p_T
75 +         *
76 +         * At first all jets with DeltaR < 0.3 (isolation cone) are searched.
77 +         * If several jets are found, take the one with the minimal pt difference
78 +         * compared to the photon. If no such jets are found, return 0
79 +         * TODO: remove photon matched jet from jet-selection?
80 +         */
81 +        std::vector<susy::PFJet> nearJets;
82 +        nearJets.clear();
83 +
84 +        std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event.pfJets.find("ak5");
85 +        if(pfJets_it == event.pfJets.end()){
86 +                if(event.pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
87 +        } else {
88 +                susy::PFJetCollection& jetColl = pfJets_it->second;
89 +                for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
90 +                                it != jetColl.end(); it++) {
91 +                        std::map<TString,Float_t>::iterator s_it = it->jecScaleFactors.find("L2L3");
92 +                        if (s_it == it->jecScaleFactors.end()) {
93 +                                std::cout << "JEC is not available for this jet!!!" << std::endl;
94 +                                continue;
95 +                        }
96 +                        float scale = s_it->second;
97 +                        TLorentzVector corrP4 = scale * it->momentum;
98 +                        float deltaR_ = deltaR(photon.momentum, corrP4 );
99 +                        if (deltaR_ > 0.3) continue;
100 +                        nearJets.push_back( *it );
101 +                }// for jet
102 +        }// if, else
103 +
104 +        if ( nearJets.size() == 0 ) {
105 +                std::cout << "No jet with ΔR < .3 found, set p_T to 0" << std::endl;
106 +                return 0;
107 +        }
108 +
109 +        float pt = 0;
110 +        float minPtDifferenz = 1E20; // should be very high
111 +        for( std::vector<susy::PFJet>::iterator it = nearJets.begin(), jetEnd = nearJets.end();
112 +                        it != jetEnd; it++ ) {
113 +                float ptDiff = fabs(photon.momentum.Et() - it->momentum.Et());
114 +                if (  ptDiff < minPtDifferenz ) {
115 +                        minPtDifferenz = ptDiff;
116 +                        pt = it->momentum.Et();
117 +                }
118 +        }
119 +
120 +        // testing
121 +        if( nearJets.size() > 1 )
122 +                std::cout << "There are several jets matching to this photon. "
123 +                                        << "Please check if the upper assumtion is reasonable" << std::endl;
124 +        return pt;
125 + }
126 +
127 +
128   void TreeWriter::Loop() {
129 +        // only for testing
130 +        bool skim = true;
131 +
132          // here the event loop is implemented and the tree is filled
133          if (inputTree == 0) return;
134  
# Line 82 | Line 148 | void TreeWriter::Loop() {
148          tree->Branch("met", &met, "met/F");
149          tree->Branch("nVertex", &nVertex, "nVertex/I");
150          tree->Branch("weigth", &weight, "weight/F");
151 <        tree->Branch("photonPt", &leadingPhotonPt, "photonPt/F");
151 >        tree->Branch("nElectron", &nElectron, "nElectron/I");
152  
153  
154          for (long jentry=0; jentry < processNEvents; jentry++) {
155 <                if (jentry%reportEvery==0)
155 >                if ( loggingVerbosity>0 && jentry%reportEvery==0 )
156                          std::cout << jentry << " / " << processNEvents << std :: endl;
157                  inputTree->GetEntry(jentry);
158  
# Line 97 | Line 163 | void TreeWriter::Loop() {
163                  std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
164                  for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
165                                  it != phoMap->second.end() && phoMap != event->photons.end(); it++ ) {
166 <                        if( ! it->isEB() )
166 >                        if( ! it->isEB() && skim )
167                                  continue;
168 <                        thisphoton->pt = it->momentum.Et();
169 <                        if( thisphoton->pt < 80 )
168 >                        thisphoton->pt = getPtFromMatchedJet( *it, *event );
169 >                        if( thisphoton->pt < 80 && skim )
170                                  continue;
171                          thisphoton->eta = it->momentum.Eta();
172 +                        thisphoton->phi = it->momentum.Phi();
173                          thisphoton->chargedIso = it->chargedHadronIso;
174                          thisphoton->neutralIso = it->neutralHadronIso;
175                          thisphoton->photonIso = it->photonIso;
176 <                        if ( it->r9 > 1 ) // if == 1 ?
176 >                        if ( it->r9 > 1 && skim ) // if == 1 ?
177                                  continue;
178                          thisphoton->r9 = it->r9;
179                          thisphoton->sigmaIetaIeta = it->sigmaIetaIeta;
# Line 114 | Line 181 | void TreeWriter::Loop() {
181                          thisphoton->pixelseed = it->nPixelSeeds;
182                          photon.push_back( *thisphoton );
183                  }
184 <                if( photon.size() == 0 )
184 >                if( photon.size() == 0 && skim )
185                          continue;
186                  std::sort( photon.begin(), photon.end(), tree::EtGreater);
120                //leadingPhotonPt = photon.at(0)->pt;
121
187  
188                  // jets
189                  std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event->pfJets.find("ak5");
# Line 138 | Line 203 | void TreeWriter::Loop() {
203                                  float scale = s_it->second;
204                                  TLorentzVector corrP4 = scale * it->momentum;
205  
206 <                                if(std::abs(corrP4.Eta()) > 3.0) continue;
206 >                                if(std::abs(corrP4.Eta()) > 3.0 && skim ) continue;
207                                  thisjet->pt = corrP4.Et();
208                                  thisjet->eta = corrP4.Eta();
209 +                                thisjet->phi = corrP4.Phi();
210                                  jet.push_back( *thisjet );
211                          }// for jet
212                  }// if, else
213 <                if( jet.size() == 0 )
214 <                        std::cout << "error, no jets found " << std::endl;
215 <                else
150 <                        std::sort( jet.begin(), jet.end(), tree::EtGreater);
213 >                if( jet.size() < 2 && skim )
214 >                        continue;
215 >                std::sort( jet.begin(), jet.end(), tree::EtGreater);
216  
217                  // met
218                  std::map<TString, susy::MET>::iterator met_it = event->metMap.find("pfMet");
219                  susy::MET* metobj = &(met_it->second);
220                  met = metobj->met();
221  
222 +                // electrons
223 +                std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"];
224 +                nElectron = eVector.size();
225 +
226                  // vertices
227  
228                  nVertex = event->vertices.size();
229                  weight = 1;
230  
231 +                // bjets
232 +
233                  tree->Fill();
234          } // for jentry
235  
# Line 171 | Line 242 | void TreeWriter::Loop() {
242   }
243  
244   int main(int argc, char** argv) {
245 <        TreeWriter *tw = new TreeWriter("qcd-1000-nTuple-test.root", "myQCDTree.root");
246 <        tw->SetProcessNEvents(10);
245 >        TreeWriter *tw = new TreeWriter("../root-files/susyEvents_qcd_1000-inf_part.root", "myTree.root");
246 >        tw->SetProcessNEvents(-1);
247          tw->Loop();
248   }
249  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines