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.2 by kiesel, Wed Mar 20 11:04:30 2013 UTC vs.
Revision 1.17 by kiesel, Fri Apr 19 10:13:02 2013 UTC

# Line 1 | Line 1
1 < #include<iostream>
1 > #include "treeWriter.h"
2  
3 < #include "TFile.h"
4 < #include "TTree.h"
5 < #include "TString.h"
6 < #include "TLorentzVector.h"
3 > using namespace std;
4  
5 < #include "SusyEvent.h"
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.c_str() );
11 >        Init( outputName, loggingVerbosity_ );
12 > }
13  
14 + TreeWriter::TreeWriter( TChain* inputTree_, std::string outputName, int loggingVerbosity_ ) {
15 +        inputTree = inputTree_;
16 +        Init( outputName, loggingVerbosity_ );
17 + }
18  
19 < namespace tree {
12 < // In this namespace classes for the trees are defined.
19 > void TreeWriter::Init( std::string outputName, int loggingVerbosity_ ) {
20  
21 < class Particle {
22 <        public:
23 <                float pt, eta, phi;
24 < };
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 < class Photon : public Particle {
27 <        public:
28 <                float r9, sigmaIetaIeta, hadTowOverEm, pixelseed;
22 <                float chargedIso, neutralIso, photonIso;
23 < };
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 < class Jet : public Particle{
31 <        public:
32 <                float pt, eta;
33 < };
30 >        // open the output file
31 >        if (loggingVerbosity_>0)
32 >                std::cout << "Open file " << outputName << " for writing." << std::endl;
33 >        outFile = new TFile( outputName.c_str(), "recreate" );
34 >        tree = new TTree("susyTree","Tree for single photon analysis");
35  
36 < bool EtGreater(const tree::Particle p1, const tree::Particle p2) {
37 <  return p1.pt > p2.pt;
36 >        // set default parameter
37 >        processNEvents = -1;
38 >        reportEvery = 1000;
39 >        loggingVerbosity = loggingVerbosity_;
40 >        skim = true;
41 >        pileupHisto = 0;
42   }
43  
44 < } // end namespace definition
44 > void TreeWriter::PileUpWeightFile( string pileupFileName ) {
45 >        TFile *puFile = new TFile( pileupFileName.c_str() );
46 >        pileupHisto = (TH1F*) puFile->Get("pileup");
47 > }
48  
49 < class TreeWriter {
50 <        public :
51 <                TreeWriter(TString inputName, TString outputName );
52 <                virtual ~TreeWriter();
53 <                virtual void Loop();
49 > 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 <                void SetProcessNEvents(int nEvents) { processNEvents = nEvents; }
60 <                void SetReportEvents(int nEvents) { reportEvery = nEvents; }
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 <                TFile *inputFile;
74 <                TTree *inputTree;
75 <                susy::Event *event;
73 > // useful functions
74 > float deltaR( const TLorentzVector& v1, const TLorentzVector& v2 ) {
75 >        // deltaR  = sqrt ( deltaEta^2 + deltaPhi^2 )
76 >        return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) );
77 > }
78  
79 <                TFile *outFile;
80 <                TTree *tree;
79 > float effectiveAreaElectron( float eta ) {
80 >        // needed by calculating the isolation for electrons
81 >        // see https://twiki.cern.ch/twiki/bin/view/CMS/EgammaEARhoCorrection
82 >        // only for Delta R = 0.3 on 2012 Data
83 >        eta = fabs( eta );
84 >        float ea;
85 >        if( eta < 1.0 ) ea = 0.13;
86 >        else if( eta < 1.479 ) ea = 0.14;
87 >        else if( eta < 2.0 ) ea = 0.07;
88 >        else if( eta < 2.2 ) ea = 0.09;
89 >        else if( eta < 2.3 ) ea = 0.11;
90 >        else if( eta < 2.4 ) ea = 0.11;
91 >        else ea = 0.14;
92 >        return ea;
93 > }
94  
95 <        private:
96 <                int processNEvents; // number of events to be processed
97 <                int reportEvery;
98 <                int loggingVerbosity;
95 > // correct iso, see https://twiki.cern.ch/twiki/bin/view/CMS/CutBasedPhotonID2012
96 > float chargedHadronIso_corrected(const susy::Photon& gamma, float rho) {
97 >        float eta = fabs(gamma.caloPosition.Eta());
98 >        float ea;
99 >
100 >        if(eta < 1.0) ea = 0.012;
101 >        else if(eta < 1.479) ea = 0.010;
102 >        else if(eta < 2.0) ea = 0.014;
103 >        else if(eta < 2.2) ea = 0.012;
104 >        else if(eta < 2.3) ea = 0.016;
105 >        else if(eta < 2.4) ea = 0.020;
106 >        else ea = 0.012;
107  
108 <                // variables which will be stored in the tree
109 <                std::vector<tree::Photon> photon;
59 <                std::vector<tree::Jet> jet;
60 <                float met;
61 <                int nVertex;
62 <                float weight;
63 < };
108 >        float iso = gamma.chargedHadronIso;
109 >        iso = max(iso - rho*ea, (float)0.);
110  
111 +        return iso;
112 + }
113  
114 < TreeWriter::TreeWriter(TString inputName, TString outputName) {
115 <        // read the input file
116 <        inputFile = new TFile( inputName, "read" );
117 <        inputTree = (TTree*) inputFile->Get("susyTree");
118 <        event = new susy::Event;
119 <        inputTree->SetBranchAddress("susyEvent", &event);
114 > float neutralHadronIso_corrected(const susy::Photon& gamma, float rho) {
115 >        float eta = fabs(gamma.caloPosition.Eta());
116 >        float ea;
117 >
118 >        if(eta < 1.0) ea = 0.030;
119 >        else if(eta < 1.479) ea = 0.057;
120 >        else if(eta < 2.0) ea = 0.039;
121 >        else if(eta < 2.2) ea = 0.015;
122 >        else if(eta < 2.3) ea = 0.024;
123 >        else if(eta < 2.4) ea = 0.039;
124 >        else ea = 0.072;
125  
126 <        // open the output file
127 <        outFile = new TFile( outputName, "recreate" );
75 <        tree = new TTree("susyTree","Tree for single photon analysis");
126 >        float iso = gamma.neutralHadronIso;
127 >        iso = max(iso - rho*ea, (float)0.);
128  
129 <        // set default parameter
130 <        processNEvents = -1;
131 <        reportEvery = 1000;
132 <        loggingVerbosity = 0;
129 >        return iso;
130 > }
131 >
132 > float photonIso_corrected(const susy::Photon& gamma, float rho) {
133 >        float eta = fabs(gamma.caloPosition.Eta());
134 >        float ea;
135 >
136 >        if(eta < 1.0) ea = 0.148;
137 >        else if(eta < 1.479) ea = 0.130;
138 >        else if(eta < 2.0) ea = 0.112;
139 >        else if(eta < 2.2) ea = 0.216;
140 >        else if(eta < 2.3) ea = 0.262;
141 >        else if(eta < 2.4) ea = 0.260;
142 >        else ea = 0.266;
143  
144 +        float iso = gamma.photonIso;
145 +        iso = max(iso - rho*ea, (float)0.);
146 +
147 +        return iso;
148   }
149  
150 < TreeWriter::~TreeWriter() {
151 <        if (!inputTree) return;
152 <        delete inputTree->GetCurrentFile();
150 > float d0correction( const susy::Electron& electron, const susy::Event& event ) {
151 >        // copied from Brian Francis
152 >        TVector3 beamspot = event.vertices[0].position;
153 >        susy::Track track = event.tracks[electron.gsfTrackIndex];
154 >        float d0 = track.d0() - beamspot.X()*sin(track.phi()) + beamspot.Y()*cos(track.phi());
155 >        return d0;
156 > }
157 >
158 > float dZcorrection( const susy::Electron& electron, const susy::Event& event ) {
159 >        // copied from Brian Francis
160 >        TVector3 beamspot = event.vertices[0].position;
161 >        susy::Track track = event.tracks[electron.gsfTrackIndex];
162 >
163 >        if(track.momentum.Pt() == 0.) return 1.e6;
164 >        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());
165 >        return dz;
166 > }
167 >
168 > float getPtFromMatchedJet( const susy::Photon& myPhoton, const susy::PFJetCollection& jetColl, int loggingVerbosity = 0 ) {
169 >        /**
170 >         * \brief Takes jet p_T as photon p_T
171 >         *
172 >         * At first all jets with DeltaR < 0.3 (isolation cone) are searched.
173 >         * If several jets are found, take the one with the minimal pt difference
174 >         * compared to the photon. If no such jets are found, keep the photon_pt
175 >         * TODO: remove photon matched jet from jet-selection?
176 >         */
177 >        std::vector<susy::PFJet> nearJets;
178 >        nearJets.clear();
179 >
180 >        for(std::vector<susy::PFJet>::const_iterator it = jetColl.begin();
181 >                        it != jetColl.end(); ++it) {
182 >                float scale = 1.;
183 >                std::map<TString,Float_t>::const_iterator s_it = it->jecScaleFactors.find("L2L3");
184 >                if (s_it == it->jecScaleFactors.end()) {
185 >                        std::cout << "JEC is not available for this jet!!!" << std::endl;
186 >                        continue;
187 >                } else {
188 >                        scale = s_it->second;
189 >                }
190 >                TLorentzVector corrP4 = scale * it->momentum;
191 >                float deltaR_ = deltaR(myPhoton.momentum, corrP4 );
192 >                if (deltaR_ > 0.3) continue;
193 >                if( loggingVerbosity > 2 )
194 >                        std::cout << " pT_jet / pT_gamma = " << it->momentum.Et() / myPhoton.momentum.Et() << std::endl;
195 >                nearJets.push_back( *it );
196 >        }// for jet
197 >
198 >        if ( nearJets.size() == 0 ) {
199 >                if( loggingVerbosity > 1 )
200 >                        std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl;
201 >                return myPhoton.momentum.Et();
202 >        }
203 >
204 >        float pt = 0;
205 >        float minPtDifferenz = 1E20; // should be very high
206 >        for( std::vector<susy::PFJet>::iterator it = nearJets.begin(), jetEnd = nearJets.end();
207 >                        it != jetEnd; ++it ) {
208 >                float ptDiff = fabs(myPhoton.momentum.Et() - it->momentum.Et());
209 >                if (  ptDiff < minPtDifferenz ) {
210 >                        minPtDifferenz = ptDiff;
211 >                        pt = it->momentum.Et();
212 >                }
213 >        }
214 >
215 >        // testing
216 >        if( nearJets.size() > 1 && loggingVerbosity > 0 )
217 >                std::cout << "There are several jets matching to this photon. "
218 >                                        << "Please check if jet-matching is correct." << std::endl;
219 >        return pt;
220   }
221  
222 +
223   void TreeWriter::Loop() {
224 +        /**
225 +         * \brief Loops over input chain and fills tree
226 +         *
227 +         * This is the major function of treeWriter, which initialize the output, loops
228 +         * over all events and fill the tree. In the end, the tree is saved to the
229 +         * output File
230 +         */
231 +
232          // here the event loop is implemented and the tree is filled
233          if (inputTree == 0) return;
234  
235          // get number of events to be proceeded
236          Long64_t nentries = inputTree->GetEntries();
237 +        // store them in histo
238 +        eventNumbers->Fill( "Number of generated events", nentries );
239          if(processNEvents <= 0 || processNEvents > nentries) processNEvents = nentries;
240  
241          if( loggingVerbosity > 0 )
242                  std::cout << "Processing " << processNEvents << " ouf of "
243                          << nentries << " events. " << std::endl;
244  
101        tree::Photon *thisphoton = new tree::Photon();
102        tree::Jet *thisjet = new tree::Jet();
103
245          tree->Branch("photon", &photon);
246          tree->Branch("jet", &jet);
247 +        tree->Branch("electron", &electron);
248 +        tree->Branch("muon", &muon);
249          tree->Branch("met", &met, "met/F");
250 +        tree->Branch("metPhi", &met_phi, "metPhi/F");
251 +        tree->Branch("type1met", &type1met, "type1met/F");
252 +        tree->Branch("type1metPhi", &type1met_phi, "type1metPhi/F");
253 +        tree->Branch("ht", &ht, "ht/F");
254          tree->Branch("nVertex", &nVertex, "nVertex/I");
255 <        tree->Branch("weigth", &weight, "weight/F");
255 >        tree->Branch("pu_weight", &pu_weight, "pu_weight/F");
256  
257  
258 <        for (long jentry=0; jentry < processNEvents; jentry++) {
259 <                if (jentry%reportEvery==0)
258 >        for (unsigned long jentry=0; jentry < processNEvents; ++jentry) {
259 >                if ( loggingVerbosity>1 || jentry%reportEvery==0 )
260                          std::cout << jentry << " / " << processNEvents << std :: endl;
261 <                inputTree->GetEntry(jentry);
261 >                inputTree->LoadTree( jentry );
262 >                inputTree->GetEntry( jentry );
263  
264                  photon.clear();
265                  jet.clear();
266 +                electron.clear();
267 +                muon.clear();
268 +                ht = 0;
269 +
270 +                // weights
271 +                if (pileupHisto == 0) {
272 +                        pu_weight = 1.;
273 +                } else {
274 +                        float trueNumInteractions = -1;
275 +                        for( susy::PUSummaryInfoCollection::const_iterator iBX = event->pu.begin();
276 +                                        iBX != event->pu.end() && trueNumInteractions < 0; ++iBX) {
277 +                                if (iBX->BX == 0)
278 +                                        trueNumInteractions = iBX->trueNumInteractions;
279 +                        }
280 +                        pu_weight = pileupHisto->GetBinContent( pileupHisto->FindBin( trueNumInteractions ) );
281 +                }
282 +
283 +                // get ak5 jets
284 +                std::vector<susy::PFJet> jetVector = event->pfJets["ak5"];
285  
286                  // photons
287 <                std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
288 <                for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
289 <                                it != phoMap->second.end() && phoMap != event->photons.end(); it++ ) {
290 <                        if( ! it->isEB() )
291 <                                continue;
125 <                        thisphoton->pt = it->momentum.Et();
126 <                        if( thisphoton->pt < 80 )
287 >                std::vector<susy::Photon> photonVector = event->photons["photons"];
288 >
289 >                for(std::vector<susy::Photon>::iterator it = photonVector.begin();
290 >                                it != photonVector.end(); ++it ) {
291 >                        if( !(it->isEB() || it->isEE()) && skim )
292                                  continue;
293 <                        thisphoton->eta = it->momentum.Eta();
294 <                        thisphoton->chargedIso = it->chargedHadronIso;
295 <                        thisphoton->neutralIso = it->neutralHadronIso;
296 <                        thisphoton->photonIso = it->photonIso;
297 <                        if ( it->r9 > 1 ) // if == 1 ?
293 >                        tree::Photon thisphoton;
294 >                        thisphoton.pt = getPtFromMatchedJet( *it, jetVector, loggingVerbosity );
295 >
296 >                        thisphoton.chargedIso = chargedHadronIso_corrected(*it, event->rho25);
297 >                        thisphoton.neutralIso = neutralHadronIso_corrected(*it, event->rho25);
298 >                        thisphoton.photonIso = photonIso_corrected(*it, event->rho25);
299 >
300 >                        bool loose_photon_barrel = thisphoton.pt>20
301 >                                && it->isEB()
302 >                                && it->passelectronveto
303 >                                && it->hadTowOverEm<0.05
304 >                                && it->sigmaIetaIeta<0.012
305 >                                && thisphoton.chargedIso<2.6
306 >                                && thisphoton.neutralIso<3.5+0.04*thisphoton.pt
307 >                                && thisphoton.photonIso<1.3+0.005*thisphoton.pt;
308 >                        bool loose_photon_endcap = thisphoton.pt > 20
309 >                                && it->isEE()
310 >                                && it->passelectronveto
311 >                                && it->hadTowOverEm<0.05
312 >                                && it->sigmaIetaIeta<0.034
313 >                                && thisphoton.chargedIso<2.3
314 >                                && thisphoton.neutralIso<2.9+0.04*thisphoton.pt;
315 >                        if(!(loose_photon_endcap || loose_photon_barrel || thisphoton.pt > 75 ) && skim )
316                                  continue;
317 <                        thisphoton->r9 = it->r9;
318 <                        thisphoton->sigmaIetaIeta = it->sigmaIetaIeta;
319 <                        thisphoton->hadTowOverEm = it->hadTowOverEm;
320 <                        thisphoton->pixelseed = it->nPixelSeeds;
321 <                        photon.push_back( *thisphoton );
317 >                        thisphoton.eta = it->momentum.Eta();
318 >                        thisphoton.phi = it->momentum.Phi();
319 >                        thisphoton.r9 = it->r9;
320 >                        thisphoton.sigmaIetaIeta = it->sigmaIetaIeta;
321 >                        thisphoton.hadTowOverEm = it->hadTowOverEm;
322 >                        thisphoton.pixelseed = it->nPixelSeeds;
323 >                        thisphoton.conversionSafeVeto = it->passelectronveto;
324 >                        photon.push_back( thisphoton );
325 >                        if( loggingVerbosity > 2 )
326 >                                std::cout << " p_T, gamma = " << thisphoton.pt << std::endl;
327                  }
328 <                if( photon.size() == 0 )
328 >
329 >                if( photon.size() == 0 && skim )
330                          continue;
331                  std::sort( photon.begin(), photon.end(), tree::EtGreater);
332 <
332 >                if( loggingVerbosity > 1 )
333 >                        std::cout << "Found " << photon.size() << " photons" << std::endl;
334  
335                  // jets
146                std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event->pfJets.find("ak5");
147                if(pfJets_it == event->pfJets.end()){
148                        if(event->pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
149                } else {
336  
151                        susy::PFJetCollection& jetColl = pfJets_it->second;
337  
338 <                        for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
339 <                                        it != jetColl.end(); it++) {
340 <                                std::map<TString,Float_t>::iterator s_it = it->jecScaleFactors.find("L2L3");
341 <                                if (s_it == it->jecScaleFactors.end()) {
342 <                                        std::cout << "JEC is not available for this jet!!!" << std::endl;
343 <                                        continue;
344 <                                }
345 <                                float scale = s_it->second;
346 <                                TLorentzVector corrP4 = scale * it->momentum;
338 >                for(std::vector<susy::PFJet>::iterator it = jetVector.begin();
339 >                                it != jetVector.end(); ++it) {
340 >                        tree::Jet thisjet;
341 >
342 >                        // scale with JEC
343 >                        float scale = 1.;
344 >                        if(it->jecScaleFactors.count("L2L3") == 0)
345 >                                std::cout << "ERROR: JEC is not available for this jet" << std::endl;
346 >                        else
347 >                                scale = it->jecScaleFactors.find("L2L3")->second;
348 >                        TLorentzVector corrP4 = scale * it->momentum;
349 >
350 >                        if(std::abs(corrP4.Eta()) > 3.0 && skim ) continue;
351 >                        if(corrP4.Pt() < 30 && skim ) continue;
352 >                        thisjet.pt = corrP4.Pt();
353 >                        thisjet.eta = corrP4.Eta();
354 >                        thisjet.phi = corrP4.Phi();
355 >                        thisjet.bCSV = it->bTagDiscriminators[susy::kCSV];
356 >                        // jet composition
357 >                        thisjet.chargedHadronEnergy = it->chargedHadronEnergy;
358 >                        thisjet.neutralHadronEnergy = it->neutralHadronEnergy;
359 >                        thisjet.photonEnergy = it->photonEnergy;
360 >                        thisjet.electronEnergy = it->electronEnergy;
361 >                        thisjet.muonEnergy = it->muonEnergy;
362 >                        thisjet.HFHadronEnergy = it->HFHadronEnergy;
363 >                        thisjet.HFEMEnergy = it->HFEMEnergy;
364 >                        thisjet.chargedEmEnergy = it->chargedEmEnergy;
365 >                        thisjet.chargedMuEnergy = it->chargedMuEnergy;
366 >                        thisjet.neutralEmEnergy = it->neutralEmEnergy;
367 >
368 >                        if( loggingVerbosity > 2 )
369 >                                std::cout << " p_T, jet = " << thisjet.pt << std::endl;
370 >
371 >                        jet.push_back( thisjet );
372 >                        ht += thisjet.pt;
373 >                }// for jet
374 >                if( jet.size() < 2 && skim )
375 >                        continue;
376 >                std::sort( jet.begin(), jet.end(), tree::EtGreater);
377 >                if( loggingVerbosity > 1 )
378 >                        std::cout << "Found " << jet.size() << " jets" << std::endl;
379  
163                                if(std::abs(corrP4.Eta()) > 3.0) continue;
164                                thisjet->pt = corrP4.Et();
165                                thisjet->eta = corrP4.Eta();
166                                jet.push_back( *thisjet );
167                        }// for jet
168                }// if, else
169                if( jet.size() == 0 )
170                        std::cout << "error, no jets found " << std::endl;
171                else
172                        std::sort( jet.begin(), jet.end(), tree::EtGreater);
380  
381                  // met
382                  std::map<TString, susy::MET>::iterator met_it = event->metMap.find("pfMet");
383                  susy::MET* metobj = &(met_it->second);
384                  met = metobj->met();
385 +                met_phi = metobj->mEt.Phi();
386 +                if( loggingVerbosity > 2 )
387 +                        std::cout << " met = " << met << std::endl;
388 +
389 +                std::map<TString, susy::MET>::iterator type1met_it = event->metMap.find("pfType1CorrectedMet");
390 +                susy::MET* type1metobj = &(type1met_it->second);
391 +                type1met = type1metobj->met();
392 +                type1met_phi = type1metobj->mEt.Phi();
393 +                if( loggingVerbosity > 2 )
394 +                        std::cout << " type1met = " << type1met << std::endl;
395 +
396 +                // electrons
397 +                std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"];
398 +                for(std::vector<susy::Electron>::iterator it = eVector.begin(); it < eVector.end(); ++it) {
399 +                        tree::Particle thiselectron;
400 +                        if( loggingVerbosity > 2 )
401 +                                cout << " electron pt = " << it->momentum.Pt() << endl;
402 +                        // for cuts see https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaCutBasedIdentification
403 +                        // use veto electrons
404 +                        if( it->momentum.Pt() < 20  || it->momentum.Pt() > 1e6 )
405 +                                continue; // spike rejection
406 +                        float iso = ( it->chargedHadronIso + max(it->neutralHadronIso+it->photonIso
407 +                                                                                                                - effectiveAreaElectron(it->momentum.Eta())*event->rho25, (Float_t)0. )
408 +                                                ) / it->momentum.Pt();
409 +                        float d0 = d0correction( *it, *event );
410 +                        float dZ = std::abs( dZcorrection( *it, *event ) );
411 +                        if ( it->isEB() ){
412 +                                if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.007
413 +                                                || fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.8
414 +                                                || it->sigmaIetaIeta > 0.01
415 +                                                || it->hcalOverEcalBc > 0.15
416 +                                                || d0 > 0.04
417 +                                                || dZ > 0.2
418 +                                                || iso > 0.15 )
419 +                                        continue;
420 +                                }
421 +                        else if( it->isEE() ) {
422 +                                if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.01
423 +                                                || fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.7
424 +                                                || it->sigmaIetaIeta > 0.03
425 +                                                || d0 > 0.04
426 +                                                || dZ > 0.2
427 +                                                || iso > 0.15 )
428 +                                        continue;
429 +                                }
430 +                        else // not in barrel nor in endcap
431 +                                continue;
432  
433 <                // vertices
433 >                        thiselectron.pt = it->momentum.Pt();
434 >                        if( loggingVerbosity > 2 )
435 >                                std::cout << " p_T, electron = " << it->momentum.Et() << std::endl;
436 >                        thiselectron.eta = it->momentum.Eta();
437 >                        thiselectron.phi = it->momentum.Phi();
438 >                        electron.push_back( thiselectron );
439 >                }
440 >                if( loggingVerbosity > 1 )
441 >                        std::cout << "Found " << electron.size() << " electrons" << std::endl;
442 >
443 >                // muons
444 >                tree::Particle thismuon;
445 >                std::vector<susy::Muon> mVector = event->muons["muons"];
446 >                for( std::vector<susy::Muon>::iterator it = mVector.begin(); it != mVector.end(); ++it) {
447 >                        if( !( it->isPFMuon() && ( it->isGlobalMuon() || it->isTrackerMuon() ) ) )
448 >                                continue; // see https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideMuonId#Loose_Muon
449 >                        thismuon.pt = it->momentum.Et();
450 >                        if( thismuon.pt < 20 )
451 >                                continue;
452 >                        thismuon.eta = it->momentum.Eta();
453 >                        thismuon.phi = it->momentum.Phi();
454 >                        muon.push_back( thismuon );
455 >                }
456 >                if( loggingVerbosity > 1 )
457 >                        std::cout << "Found " << muon.size() << " muons" << std::endl;
458  
459 +                // vertices
460                  nVertex = event->vertices.size();
461 <                weight = 1;
461 >
462 >                if( ht < 450 && skim)
463 >                        continue;
464 >
465  
466                  tree->Fill();
467          } // for jentry
468  
469  
188
189        tree->Write();
470          outFile->cd();
471 +        eventNumbers->Write();
472 +        tree->Write();
473          outFile->Write();
474          outFile->Close();
475   }
476 < /*
195 < int main(int argc, char** argv) {
196 <        TreeWriter *tw = new TreeWriter("qcd-1000-nTuple-test.root", "myQCDTree.root");
197 <        tw->SetProcessNEvents(10);
198 <        tw->Loop();
199 < }
200 < */
476 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines