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.12 by kiesel, Tue Apr 16 15:11:20 2013 UTC vs.
Revision 1.27 by kiesel, Thu Apr 25 18:17:04 2013 UTC

# Line 1 | Line 1
1 #include<iostream>
2 #include<math.h>
3 #include<string>
4
5 #include "TSystem.h"
6
1   #include "treeWriter.h"
2  
3   using namespace std;
4  
5 < TreeWriter::TreeWriter( TString inputName, TString outputName, int loggingVerbosity_ ) {
5 > TreeWriter::TreeWriter( std::string inputName, std::string outputName, int loggingVerbosity_ ) {
6          // read the input file
7          inputTree = new TChain("susyTree");
8          if (loggingVerbosity_ > 0)
9                  std::cout << "Add files to chain" << std::endl;
10 <        inputTree->Add( inputName );
10 >        inputTree->Add( inputName.c_str() );
11          Init( outputName, loggingVerbosity_ );
12   }
13  
14 < TreeWriter::TreeWriter( TChain* inputTree_, TString outputName, int loggingVerbosity_ ) {
14 > TreeWriter::TreeWriter( TChain* inputTree_, std::string outputName, int loggingVerbosity_ ) {
15          inputTree = inputTree_;
16          Init( outputName, loggingVerbosity_ );
17   }
18  
19 <
26 < void TreeWriter::Init( TString outputName, int loggingVerbosity_ ) {
19 > void TreeWriter::Init( std::string outputName, int loggingVerbosity_ ) {
20  
21          if (loggingVerbosity_ > 0)
22                  std::cout << "Set Branch Address of susy::Event" << std::endl;
23          event = new susy::Event;
24          inputTree->SetBranchAddress("susyEvent", &event);
25  
26 +        // Here the number of proceeded events will be stored. For plotting, simply use L*sigma/eventNumber
27 +        eventNumbers = new TH1F("eventNumbers", "Histogram containing number of generated events", 1, 0, 1);
28 +        eventNumbers->GetXaxis()->SetBinLabel(1,"Number of generated events");
29 +
30          // open the output file
31          if (loggingVerbosity_>0)
32                  std::cout << "Open file " << outputName << " for writing." << std::endl;
33 <        outFile = new TFile( outputName, "recreate" );
33 >        outFile = new TFile( outputName.c_str(), "recreate" );
34          tree = new TTree("susyTree","Tree for single photon analysis");
35  
36          // set default parameter
# Line 53 | Line 50 | TreeWriter::~TreeWriter() {
50          if (pileupHisto != 0 )
51                  delete pileupHisto;
52          inputTree->GetCurrentFile()->Close();
53 +        delete inputTree;
54 +        delete event;
55 +        delete outFile;
56 +        delete tree;
57 + }
58 +
59 + template<class Type>
60 + std::vector<Type>* getVectorFromMap( map<TString, vector<Type> > myMap, TString search ){
61 +        // if nothing is found, return a empty vector (which has to be deleted never the less)
62 +        std::vector<Type>* vec;
63 +        typename map<TString, vector<Type> >::iterator mapIt = myMap.find( search );
64 +        if( mapIt == myMap.end() ) {
65 +                cout << "ERROR: Collection \"" << search << "\" not found!" << endl;
66 +                vec = new std::vector<Type>;
67 +        } else
68 +                vec = &mapIt->second;
69 +        cout << vec->size() << endl;
70 +        return vec;
71 + }
72 +
73 + float deltaPhi( float phi1, float phi2) {
74 +        float result = phi1 - phi2;
75 +        while (result > M_PI) result -= 2*M_PI;
76 +        while (result <= -M_PI) result += 2*M_PI;
77 +        return result;
78   }
79  
80   // useful functions
81 < float TreeWriter::deltaR( TLorentzVector v1, TLorentzVector v2 ) {
82 <        return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) );
81 > float deltaR( const TLorentzVector& v1, const TLorentzVector& v2 ) {
82 >        // deltaR  = sqrt ( deltaEta^2 + deltaPhi^2 )
83 >        return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(deltaPhi(v1.Phi(),v2.Phi()), 2) );
84   }
85  
86   float effectiveAreaElectron( float eta ) {
87 +        // needed by calculating the isolation for electrons
88          // see https://twiki.cern.ch/twiki/bin/view/CMS/EgammaEARhoCorrection
89          // only for Delta R = 0.3 on 2012 Data
90          eta = fabs( eta );
# Line 76 | Line 100 | float effectiveAreaElectron( float eta )
100   }
101  
102   // correct iso, see https://twiki.cern.ch/twiki/bin/view/CMS/CutBasedPhotonID2012
103 < float chargedHadronIso_corrected(susy::Photon gamma, float rho) {
103 > float chargedHadronIso_corrected(const susy::Photon& gamma, float rho) {
104          float eta = fabs(gamma.caloPosition.Eta());
105          float ea;
106  
# Line 94 | Line 118 | float chargedHadronIso_corrected(susy::P
118          return iso;
119   }
120  
121 < float neutralHadronIso_corrected(susy::Photon gamma, float rho) {
121 > float neutralHadronIso_corrected(const susy::Photon& gamma, float rho) {
122          float eta = fabs(gamma.caloPosition.Eta());
123          float ea;
124  
# Line 112 | Line 136 | float neutralHadronIso_corrected(susy::P
136          return iso;
137   }
138  
139 < float photonIso_corrected(susy::Photon gamma, float rho) {
139 > float photonIso_corrected(const susy::Photon& gamma, float rho) {
140          float eta = fabs(gamma.caloPosition.Eta());
141          float ea;
142  
# Line 130 | Line 154 | float photonIso_corrected(susy::Photon g
154          return iso;
155   }
156  
157 < float TreeWriter::getPtFromMatchedJet( susy::Photon myPhoton, susy::Event myEvent ) {
157 > float d0correction( const susy::Electron& electron, const susy::Event& event ) {
158 >        // copied from Brian Francis
159 >        TVector3 beamspot = event.vertices[0].position;
160 >        susy::Track track = event.tracks[electron.gsfTrackIndex];
161 >        float d0 = track.d0() - beamspot.X()*sin(track.phi()) + beamspot.Y()*cos(track.phi());
162 >        return d0;
163 > }
164 >
165 > float dZcorrection( const susy::Electron& electron, const susy::Event& event ) {
166 >        // copied from Brian Francis
167 >        TVector3 beamspot = event.vertices[0].position;
168 >        susy::Track track = event.tracks[electron.gsfTrackIndex];
169 >
170 >        if(track.momentum.Pt() == 0.) return 1.e6;
171 >        float dz = (track.vertex.Z() - beamspot.Z()) - ((track.vertex.X() - beamspot.X())*track.momentum.Px() + (track.vertex.Y() - beamspot.Y())*track.momentum.Py()) / track.momentum.Pt() * (track.momentum.Pz() / track.momentum.Pt());
172 >        return dz;
173 > }
174 >
175 > float getPtFromMatchedJet( const susy::Photon& myPhoton, const susy::PFJetCollection& jetColl, int loggingVerbosity = 0 ) {
176          /**
177           * \brief Takes jet p_T as photon p_T
178           *
# Line 142 | Line 184 | float TreeWriter::getPtFromMatchedJet( s
184          std::vector<susy::PFJet> nearJets;
185          nearJets.clear();
186  
187 <        std::map<TString,susy::PFJetCollection>::iterator pfJets_it = myEvent.pfJets.find("ak5");
188 <        if(pfJets_it == myEvent.pfJets.end()){
189 <                if(myEvent.pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
190 <        } else {
191 <                susy::PFJetCollection& jetColl = pfJets_it->second;
192 <                for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
193 <                                it != jetColl.end(); ++it) {
194 <                        std::map<TString,Float_t>::iterator s_it = it->jecScaleFactors.find("L2L3");
195 <                        if (s_it == it->jecScaleFactors.end()) {
196 <                                std::cout << "JEC is not available for this jet!!!" << std::endl;
197 <                                continue;
198 <                        }
199 <                        float scale = s_it->second;
200 <                        TLorentzVector corrP4 = scale * it->momentum;
201 <                        float deltaR_ = deltaR(myPhoton.momentum, corrP4 );
202 <                        if (deltaR_ > 0.3) continue;
203 <                        if( loggingVerbosity > 0 )
162 <                                std::cout << "gamma pt jet matching factor = " << it->momentum.Et() / myPhoton.momentum.Et() << std::endl;
163 <                        nearJets.push_back( *it );
164 <                }// for jet
165 <        }// if, else
187 >        for(std::vector<susy::PFJet>::const_iterator it = jetColl.begin();
188 >                        it != jetColl.end(); ++it) {
189 >                float scale = 1.;
190 >                std::map<TString,Float_t>::const_iterator s_it = it->jecScaleFactors.find("L2L3");
191 >                if (s_it == it->jecScaleFactors.end()) {
192 >                        std::cout << "JEC is not available for this jet!!!" << std::endl;
193 >                        continue;
194 >                } else {
195 >                        scale = s_it->second;
196 >                }
197 >                TLorentzVector corrP4 = scale * it->momentum;
198 >                float deltaR_ = deltaR(myPhoton.momentum, corrP4 );
199 >                if (deltaR_ > 0.3) continue;
200 >                if( loggingVerbosity > 2 )
201 >                        std::cout << " pT_jet / pT_gamma = " << it->momentum.Et() / myPhoton.momentum.Et() << std::endl;
202 >                nearJets.push_back( *it );
203 >        }// for jet
204  
205          if ( nearJets.size() == 0 ) {
206                  if( loggingVerbosity > 1 )
# Line 190 | Line 228 | float TreeWriter::getPtFromMatchedJet( s
228  
229  
230   void TreeWriter::Loop() {
231 +        /**
232 +         * \brief Loops over input chain and fills tree
233 +         *
234 +         * This is the major function of treeWriter, which initialize the output, loops
235 +         * over all events and fill the tree. In the end, the tree is saved to the
236 +         * output File
237 +         */
238  
239          // here the event loop is implemented and the tree is filled
240          if (inputTree == 0) return;
241  
242          // get number of events to be proceeded
243          Long64_t nentries = inputTree->GetEntries();
244 +        // store them in histo
245 +        eventNumbers->Fill( "Number of generated events", nentries );
246          if(processNEvents <= 0 || processNEvents > nentries) processNEvents = nentries;
247  
248          if( loggingVerbosity > 0 )
249                  std::cout << "Processing " << processNEvents << " ouf of "
250                          << nentries << " events. " << std::endl;
251  
205        tree::Photon *thisphoton = new tree::Photon();
206        tree::Jet *thisjet = new tree::Jet();
207
252          tree->Branch("photon", &photon);
253          tree->Branch("jet", &jet);
254          tree->Branch("electron", &electron);
# Line 216 | Line 260 | void TreeWriter::Loop() {
260          tree->Branch("ht", &ht, "ht/F");
261          tree->Branch("nVertex", &nVertex, "nVertex/I");
262          tree->Branch("pu_weight", &pu_weight, "pu_weight/F");
263 +        tree->Branch("genElectron", &genElectron);
264 +        tree->Branch("genPhoton", &genPhoton);
265  
266 <
267 <        for (long jentry=0; jentry < processNEvents; ++jentry) {
222 <                if ( loggingVerbosity>0 && jentry%reportEvery==0 )
266 >        for (unsigned long jentry=0; jentry < processNEvents; ++jentry) {
267 >                if ( loggingVerbosity>1 || jentry%reportEvery==0 )
268                          std::cout << jentry << " / " << processNEvents << std :: endl;
269 <                inputTree->GetEntry(jentry);
269 >                inputTree->LoadTree( jentry );
270 >                inputTree->GetEntry( jentry );
271  
272                  photon.clear();
273                  jet.clear();
274                  electron.clear();
275                  muon.clear();
276 +                genElectron.clear();
277 +                genPhoton.clear();
278                  ht = 0;
279  
280                  // weights
# Line 242 | Line 290 | void TreeWriter::Loop() {
290                          pu_weight = pileupHisto->GetBinContent( pileupHisto->FindBin( trueNumInteractions ) );
291                  }
292  
293 +                // get ak5 jets
294 +                std::vector<susy::PFJet> jetVector = event->pfJets["ak5"];
295  
296                  // photons
297 <                if( loggingVerbosity > 1 )
298 <                        std::cout << "Process photons" << std::endl;
299 <                std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
300 <                for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
301 <                                it != phoMap->second.end() && phoMap != event->photons.end(); ++it ) {
252 <                        if( !(it->isEB() || it->isEE()) && skim )
297 >                std::vector<susy::Photon> photonVector = event->photons["photons"];
298 >
299 >                for(std::vector<susy::Photon>::iterator it = photonVector.begin();
300 >                                it != photonVector.end(); ++it ) {
301 >                        if( !(it->isEE() || it->isEB()) && it->isEBEtaGap() && it->isEBPhiGap() && it->isEERingGap() && it->isEEDeeGap() && it->isEBEEGap() && skim )
302                                  continue;
303 <                        thisphoton->pt = getPtFromMatchedJet( *it, *event );
303 >                        tree::Photon thisphoton;
304 >                        thisphoton.pt = getPtFromMatchedJet( *it, jetVector, loggingVerbosity );
305  
306 <                        thisphoton->chargedIso = chargedHadronIso_corrected(*it, event->rho25);
307 <                        thisphoton->neutralIso = neutralHadronIso_corrected(*it, event->rho25);
308 <                        thisphoton->photonIso = photonIso_corrected(*it, event->rho25);
306 >                        thisphoton.chargedIso = chargedHadronIso_corrected(*it, event->rho25);
307 >                        thisphoton.neutralIso = neutralHadronIso_corrected(*it, event->rho25);
308 >                        thisphoton.photonIso = photonIso_corrected(*it, event->rho25);
309  
310 <                        bool loose_photon_barrel = thisphoton->pt>20
310 >                        bool loose_photon_barrel = thisphoton.pt>20
311                                  && it->isEB()
262                                && it->passelectronveto
312                                  && it->hadTowOverEm<0.05
313                                  && it->sigmaIetaIeta<0.012
314 <                                && thisphoton->chargedIso<2.6
315 <                                && thisphoton->neutralIso<3.5+0.04*thisphoton->pt
316 <                                && thisphoton->photonIso<1.3+0.005*thisphoton->pt;
317 <                        bool loose_photon_endcap = thisphoton->pt > 20
314 >                                && thisphoton.chargedIso<2.6
315 >                                && thisphoton.neutralIso<3.5+0.04*thisphoton.pt
316 >                                && thisphoton.photonIso<1.3+0.005*thisphoton.pt;
317 >                        bool loose_photon_endcap = thisphoton.pt > 20
318                                  && it->isEE()
270                                && it->passelectronveto
319                                  && it->hadTowOverEm<0.05
320                                  && it->sigmaIetaIeta<0.034
321 <                                && thisphoton->chargedIso<2.3
322 <                                && thisphoton->neutralIso<2.9+0.04*thisphoton->pt;
323 <                        if(!(loose_photon_endcap || loose_photon_barrel || thisphoton->pt > 75 ) && skim )
321 >                                && thisphoton.chargedIso<2.3
322 >                                && thisphoton.neutralIso<2.9+0.04*thisphoton.pt;
323 >
324 >                        if(!(loose_photon_endcap || loose_photon_barrel || thisphoton.pt > 75 ) && skim )
325                                  continue;
326 <                        thisphoton->eta = it->momentum.Eta();
327 <                        thisphoton->phi = it->momentum.Phi();
328 <                        thisphoton->r9 = it->r9;
329 <                        thisphoton->sigmaIetaIeta = it->sigmaIetaIeta;
330 <                        thisphoton->hadTowOverEm = it->hadTowOverEm;
331 <                        thisphoton->pixelseed = it->nPixelSeeds;
332 <                        thisphoton->conversionSafeVeto = it->passelectronveto;
333 <                        photon.push_back( *thisphoton );
326 >                        thisphoton.eta = it->momentum.Eta();
327 >                        thisphoton.phi = it->momentum.Phi();
328 >                        thisphoton.r9 = it->r9;
329 >                        thisphoton.sigmaIetaIeta = it->sigmaIetaIeta;
330 >                        thisphoton.hadTowOverEm = it->hadTowOverEm;
331 >                        thisphoton.pixelseed = it->nPixelSeeds;
332 >                        thisphoton.conversionSafeVeto = it->passelectronveto;
333 >                        photon.push_back( thisphoton );
334                          if( loggingVerbosity > 2 )
335 <                                std::cout << " p_T, gamma = " << thisphoton->pt << std::endl;
335 >                                std::cout << " p_T, gamma = " << thisphoton.pt << std::endl;
336                  }
337  
338                  if( photon.size() == 0 && skim )
# Line 293 | Line 342 | void TreeWriter::Loop() {
342                          std::cout << "Found " << photon.size() << " photons" << std::endl;
343  
344                  // jets
296                std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event->pfJets.find("ak5");
297                if(pfJets_it == event->pfJets.end()){
298                        if(event->pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
299                } else {
345  
301                        susy::PFJetCollection& jetColl = pfJets_it->second;
346  
347 <                        for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
348 <                                        it != jetColl.end(); ++it) {
349 <                                std::map<TString,Float_t>::iterator s_it = it->jecScaleFactors.find("L2L3");
350 <                                if (s_it == it->jecScaleFactors.end()) {
351 <                                        std::cout << "JEC is not available for this jet!!!" << std::endl;
352 <                                        continue;
353 <                                }
354 <                                float scale = s_it->second;
355 <                                TLorentzVector corrP4 = scale * it->momentum;
347 >                for(std::vector<susy::PFJet>::iterator it = jetVector.begin();
348 >                                it != jetVector.end(); ++it) {
349 >                        tree::Jet thisjet;
350 >
351 >                        // scale with JEC
352 >                        float scale = 1.;
353 >                        if(it->jecScaleFactors.count("L2L3") == 0)
354 >                                std::cout << "ERROR: JEC is not available for this jet" << std::endl;
355 >                        else
356 >                                scale = it->jecScaleFactors.find("L2L3")->second;
357 >                        TLorentzVector corrP4 = scale * it->momentum;
358 >
359 >                        // Calculate HT.
360 >                        // The definiton differs from the saved jet, since trigger is described better
361 >                        if( std::abs( corrP4.Eta() ) < 3 && corrP4.Pt() > 40 )
362 >                                ht += thisjet.pt;
363 >
364 >                        if(std::abs(corrP4.Eta()) > 2.6 && skim ) continue;
365 >                        if(corrP4.Pt() < 30 && skim ) continue;
366 >                        thisjet.pt = corrP4.Pt();
367 >                        thisjet.eta = corrP4.Eta();
368 >                        thisjet.phi = corrP4.Phi();
369 >                        thisjet.bCSV = it->bTagDiscriminators[susy::kCSV];
370 >                        // jet composition
371 >                        thisjet.chargedHadronEnergy = it->chargedHadronEnergy;
372 >                        thisjet.neutralHadronEnergy = it->neutralHadronEnergy;
373 >                        thisjet.photonEnergy = it->photonEnergy;
374 >                        thisjet.electronEnergy = it->electronEnergy;
375 >                        thisjet.muonEnergy = it->muonEnergy;
376 >                        thisjet.HFHadronEnergy = it->HFHadronEnergy;
377 >                        thisjet.HFEMEnergy = it->HFEMEnergy;
378 >                        thisjet.chargedEmEnergy = it->chargedEmEnergy;
379 >                        thisjet.chargedMuEnergy = it->chargedMuEnergy;
380 >                        thisjet.neutralEmEnergy = it->neutralEmEnergy;
381  
382 <                                if(std::abs(corrP4.Eta()) > 3.0 && skim ) continue;
383 <                                if(corrP4.Et() < 30 && skim ) continue;
384 <                                thisjet->pt = corrP4.Et();
385 <                                thisjet->eta = corrP4.Eta();
386 <                                thisjet->phi = corrP4.Phi();
318 <                                thisjet->bCSV = it->bTagDiscriminators[susy::kCSV];
319 <                                // jet composition
320 <                                thisjet->chargedHadronEnergy = it->chargedHadronEnergy;
321 <                                thisjet->neutralHadronEnergy = it->neutralHadronEnergy;
322 <                                thisjet->photonEnergy = it->photonEnergy;
323 <                                thisjet->electronEnergy = it->electronEnergy;
324 <                                thisjet->muonEnergy = it->muonEnergy;
325 <                                thisjet->HFHadronEnergy = it->HFHadronEnergy;
326 <                                thisjet->HFEMEnergy = it->HFEMEnergy;
327 <                                thisjet->chargedEmEnergy = it->chargedEmEnergy;
328 <                                thisjet->chargedMuEnergy = it->chargedMuEnergy;
329 <                                thisjet->neutralEmEnergy = it->neutralEmEnergy;
330 <
331 <                                if( loggingVerbosity > 2 )
332 <                                        std::cout << " p_T, jet = " << thisjet->pt << std::endl;
333 <
334 <                                jet.push_back( *thisjet );
335 <                                ht += thisjet->pt;
336 <                        }// for jet
337 <                }// if, else
382 >                        if( loggingVerbosity > 2 )
383 >                                std::cout << " p_T, jet = " << thisjet.pt << std::endl;
384 >
385 >                        jet.push_back( thisjet );
386 >                }// for jet
387                  if( jet.size() < 2 && skim )
388                          continue;
389                  std::sort( jet.begin(), jet.end(), tree::EtGreater);
390                  if( loggingVerbosity > 1 )
391                          std::cout << "Found " << jet.size() << " jets" << std::endl;
392  
393 +                if( ht < 450 && skim)
394 +                        continue;
395 +
396 +
397  
398                  // met
399                  std::map<TString, susy::MET>::iterator met_it = event->metMap.find("pfMet");
# Line 358 | Line 411 | void TreeWriter::Loop() {
411                          std::cout << " type1met = " << type1met << std::endl;
412  
413                  // electrons
414 <                tree::Particle* thiselectron = new tree::Particle();
415 <                map<TString, vector<susy::Electron> >::iterator eleMap = event->electrons.find("gsfElectrons");
416 <                if(eleMap == event->electrons.end() && loggingVerbosity > 0) {
417 <                        cout << "gsfElectrons not found!" << endl;
418 <                } else {
419 <                        for(vector<susy::Electron>::iterator it = eleMap->second.begin(); it < eleMap->second.end(); ++it) {
420 <                                // for cuts see https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaCutBasedIdentification
421 <                                float iso = ( it->chargedHadronIso + max(it->neutralHadronIso+it->photonIso
422 <                                                                                                                        -effectiveAreaElectron(it->momentum.Eta())*event->rho25, (Float_t)0. )
423 <                                                        ) / it->momentum.Pt();
424 <                                if ( it->isEE() ){
425 <                                        if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.007
426 <                                                        || fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.15
427 <                                                        || it->sigmaIetaIeta > 0.01
428 <                                                        || it->hcalOverEcalBc > 0.12
429 <                                                        || it->vertex.Perp() > 0.02
430 <                                                        || it->vertex.Z() > 0.2
431 <                                                        || fabs(1./(it->ecalEnergy) - 1./(it->trackMomentums["AtVtx"].P())) > 0.05
432 <                                                        || it->convFlags() // not official, but perhaps substitude?
433 <                                                        || iso > 0.15 )
434 <                                                continue;
382 <                                        }
383 <                                else if( it->isEB() ) {
384 <                                        if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.009
385 <                                                        || fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.10
386 <                                                        || it->sigmaIetaIeta > 0.03
387 <                                                        || it->hcalOverEcalBc > 0.10
388 <                                                        || it->vertex.Perp() > 0.02
389 <                                                        || it->vertex.Z() > 0.2
390 <                                                        || fabs(1./(it->ecalEnergy) - 1./(it->trackMomentums["AtVtx"].P())) > 0.05
391 <                                                        || it->convFlags() // not official, but perhaps substitude?
392 <                                                        || iso > 0.15 )
393 <                                                continue;
394 <                                        }
395 <                                else // not in barrel nor in endcap
414 >                std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"];
415 >                for(std::vector<susy::Electron>::iterator it = eVector.begin(); it < eVector.end(); ++it) {
416 >                        tree::Particle thiselectron;
417 >                        if( loggingVerbosity > 2 )
418 >                                cout << " electron pt = " << it->momentum.Pt() << endl;
419 >                        // for cuts see https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaCutBasedIdentification
420 >                        // use veto electrons
421 >                        if( it->momentum.Pt() < 20  || it->momentum.Pt() > 1e6 )
422 >                                continue; // spike rejection
423 >                        float iso = ( it->chargedHadronIso + max(it->neutralHadronIso+it->photonIso - effectiveAreaElectron(it->momentum.Eta())*event->rho25, (float)0. )
424 >                                                ) / it->momentum.Pt();
425 >                        float d0 = d0correction( *it, *event );
426 >                        float dZ = std::abs( dZcorrection( *it, *event ) );
427 >                        if ( it->isEB() ){
428 >                                if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.007
429 >                                                || fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.8
430 >                                                || it->sigmaIetaIeta > 0.01
431 >                                                || it->hcalOverEcalBc > 0.15
432 >                                                || d0 > 0.04
433 >                                                || dZ > 0.2
434 >                                                || iso > 0.15 )
435                                          continue;
436 <                                // TODO: conversion rejection information not implemented yet, see twiki for more details
437 <
438 <                                thiselectron->pt = it->momentum.Et();
439 <                                if( thiselectron->pt < 20 )
436 >                                }
437 >                        else if( it->isEE() ) {
438 >                                if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.01
439 >                                                || fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.7
440 >                                                || it->sigmaIetaIeta > 0.03
441 >                                                || d0 > 0.04
442 >                                                || dZ > 0.2
443 >                                                || iso > 0.15 )
444                                          continue;
445 <                                if( loggingVerbosity > 2 )
446 <                                        std::cout << " p_T, electron = " << it->momentum.Et() << std::endl;
447 <                                thiselectron->eta = it->momentum.Eta();
448 <                                thiselectron->phi = it->momentum.Phi();
449 <                                electron.push_back( *thiselectron );
450 <                        }
445 >                                }
446 >                        else // not in barrel nor in endcap
447 >                                continue;
448 >
449 >                        thiselectron.pt = it->momentum.Pt();
450 >                        if( loggingVerbosity > 2 )
451 >                                std::cout << " p_T, electron = " << it->momentum.Et() << std::endl;
452 >                        thiselectron.eta = it->momentum.Eta();
453 >                        thiselectron.phi = it->momentum.Phi();
454 >                        electron.push_back( thiselectron );
455                  }
456                  if( loggingVerbosity > 1 )
457                          std::cout << "Found " << electron.size() << " electrons" << std::endl;
458  
459                  // muons
460 +                tree::Particle thismuon;
461                  std::vector<susy::Muon> mVector = event->muons["muons"];
414                tree::Particle* thismuon = new tree::Particle();
462                  for( std::vector<susy::Muon>::iterator it = mVector.begin(); it != mVector.end(); ++it) {
463                          if( !( it->isPFMuon() && ( it->isGlobalMuon() || it->isTrackerMuon() ) ) )
464                                  continue; // see https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideMuonId#Loose_Muon
465 <                        thismuon->pt = it->momentum.Et();
466 <                        if( thismuon->pt < 20 )
465 >                        thismuon.pt = it->momentum.Et();
466 >                        if( thismuon.pt < 20 )
467                                  continue;
468 <                        thismuon->eta = it->momentum.Eta();
469 <                        thismuon->phi = it->momentum.Phi();
470 <                        muon.push_back( *thismuon );
468 >                        thismuon.eta = it->momentum.Eta();
469 >                        thismuon.phi = it->momentum.Phi();
470 >                        muon.push_back( thismuon );
471                  }
472                  if( loggingVerbosity > 1 )
473                          std::cout << "Found " << muon.size() << " muons" << std::endl;
474  
428
475                  // vertices
476                  nVertex = event->vertices.size();
477  
478 <                if( ht < 450 && skim)
479 <                        continue;
478 >                tree::Particle thisGenParticle;
479 >                for( std::vector<susy::Particle>::iterator it = event->genParticles.begin(); it != event->genParticles.end(); ++it ) {
480 >                        if( it->momentum.Pt() < 20 ) continue;
481 >                        thisGenParticle.pt = it->momentum.Pt();
482 >                        thisGenParticle.eta = it->momentum.Eta();
483 >                        thisGenParticle.phi = it->momentum.Phi();
484 >                        switch( std::abs(it->pdgId) ) {
485 >                                case 22: // photon
486 >                                        genPhoton.push_back( thisGenParticle );
487 >                                        break;
488 >                                case 11: // electron
489 >                                        // Demand a W boson as mother particle of electron
490 >                                        if( abs(event->genParticles[it->motherIndex].pdgId) == 24 )
491 >                                                genElectron.push_back( thisGenParticle );
492 >                                        break;
493 >                        }
494 >                }
495  
496                  tree->Fill();
497          } // for jentry
498  
499  
500          outFile->cd();
501 +        eventNumbers->Write();
502          tree->Write();
503          outFile->Write();
504          outFile->Close();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines