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.11 by kiesel, Mon Apr 15 16:01:40 2013 UTC vs.
Revision 1.13 by kiesel, Tue Apr 16 18:53:55 2013 UTC

# Line 60 | Line 60 | float TreeWriter::deltaR( TLorentzVector
60          return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) );
61   }
62  
63 + float effectiveAreaElectron( float eta ) {
64 +        // see https://twiki.cern.ch/twiki/bin/view/CMS/EgammaEARhoCorrection
65 +        // only for Delta R = 0.3 on 2012 Data
66 +        eta = fabs( eta );
67 +        float ea;
68 +        if( eta < 1.0 ) ea = 0.13;
69 +        else if( eta < 1.479 ) ea = 0.14;
70 +        else if( eta < 2.0 ) ea = 0.07;
71 +        else if( eta < 2.2 ) ea = 0.09;
72 +        else if( eta < 2.3 ) ea = 0.11;
73 +        else if( eta < 2.4 ) ea = 0.11;
74 +        else ea = 0.14;
75 +        return ea;
76 + }
77 +
78   // correct iso, see https://twiki.cern.ch/twiki/bin/view/CMS/CutBasedPhotonID2012
79   float chargedHadronIso_corrected(susy::Photon gamma, float rho) {
80 <  float eta = fabs(gamma.caloPosition.Eta());
81 <  float ea;
80 >        float eta = fabs(gamma.caloPosition.Eta());
81 >        float ea;
82  
83 <  if(eta < 1.0) ea = 0.012;
84 <  else if(eta < 1.479) ea = 0.010;
85 <  else if(eta < 2.0) ea = 0.014;
86 <  else if(eta < 2.2) ea = 0.012;
87 <  else if(eta < 2.3) ea = 0.016;
88 <  else if(eta < 2.4) ea = 0.020;
89 <  else ea = 0.012;
83 >        if(eta < 1.0) ea = 0.012;
84 >        else if(eta < 1.479) ea = 0.010;
85 >        else if(eta < 2.0) ea = 0.014;
86 >        else if(eta < 2.2) ea = 0.012;
87 >        else if(eta < 2.3) ea = 0.016;
88 >        else if(eta < 2.4) ea = 0.020;
89 >        else ea = 0.012;
90  
91 <  float iso = gamma.chargedHadronIso;
92 <  iso = max(iso - rho*ea, (float)0.);
91 >        float iso = gamma.chargedHadronIso;
92 >        iso = max(iso - rho*ea, (float)0.);
93  
94 <  return iso;
94 >        return iso;
95   }
96  
97   float neutralHadronIso_corrected(susy::Photon gamma, float rho) {
98 <  float eta = fabs(gamma.caloPosition.Eta());
99 <  float ea;
98 >        float eta = fabs(gamma.caloPosition.Eta());
99 >        float ea;
100  
101 <  if(eta < 1.0) ea = 0.030;
102 <  else if(eta < 1.479) ea = 0.057;
103 <  else if(eta < 2.0) ea = 0.039;
104 <  else if(eta < 2.2) ea = 0.015;
105 <  else if(eta < 2.3) ea = 0.024;
106 <  else if(eta < 2.4) ea = 0.039;
107 <  else ea = 0.072;
101 >        if(eta < 1.0) ea = 0.030;
102 >        else if(eta < 1.479) ea = 0.057;
103 >        else if(eta < 2.0) ea = 0.039;
104 >        else if(eta < 2.2) ea = 0.015;
105 >        else if(eta < 2.3) ea = 0.024;
106 >        else if(eta < 2.4) ea = 0.039;
107 >        else ea = 0.072;
108  
109 <  float iso = gamma.neutralHadronIso;
110 <  iso = max(iso - rho*ea, (float)0.);
109 >        float iso = gamma.neutralHadronIso;
110 >        iso = max(iso - rho*ea, (float)0.);
111  
112 <  return iso;
112 >        return iso;
113   }
114  
115   float photonIso_corrected(susy::Photon gamma, float rho) {
116 <  float eta = fabs(gamma.caloPosition.Eta());
117 <  float ea;
116 >        float eta = fabs(gamma.caloPosition.Eta());
117 >        float ea;
118  
119 <  if(eta < 1.0) ea = 0.148;
120 <  else if(eta < 1.479) ea = 0.130;
121 <  else if(eta < 2.0) ea = 0.112;
122 <  else if(eta < 2.2) ea = 0.216;
123 <  else if(eta < 2.3) ea = 0.262;
124 <  else if(eta < 2.4) ea = 0.260;
125 <  else ea = 0.266;
119 >        if(eta < 1.0) ea = 0.148;
120 >        else if(eta < 1.479) ea = 0.130;
121 >        else if(eta < 2.0) ea = 0.112;
122 >        else if(eta < 2.2) ea = 0.216;
123 >        else if(eta < 2.3) ea = 0.262;
124 >        else if(eta < 2.4) ea = 0.260;
125 >        else ea = 0.266;
126  
127 <  float iso = gamma.photonIso;
128 <  iso = max(iso - rho*ea, (float)0.);
127 >        float iso = gamma.photonIso;
128 >        iso = max(iso - rho*ea, (float)0.);
129  
130 <  return iso;
130 >        return iso;
131   }
132  
133   float TreeWriter::getPtFromMatchedJet( susy::Photon myPhoton, susy::Event myEvent ) {
# Line 150 | Line 165 | float TreeWriter::getPtFromMatchedJet( s
165          }// if, else
166  
167          if ( nearJets.size() == 0 ) {
168 <                //std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl;
168 >                if( loggingVerbosity > 1 )
169 >                        std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl;
170                  return myPhoton.momentum.Et();
171          }
172  
# Line 191 | Line 207 | void TreeWriter::Loop() {
207  
208          tree->Branch("photon", &photon);
209          tree->Branch("jet", &jet);
210 <        //tree->Branch("electron", &electron);
210 >        tree->Branch("electron", &electron);
211          tree->Branch("muon", &muon);
212          tree->Branch("met", &met, "met/F");
213          tree->Branch("metPhi", &met_phi, "metPhi/F");
# Line 233 | Line 249 | void TreeWriter::Loop() {
249                  std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
250                  for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
251                                  it != phoMap->second.end() && phoMap != event->photons.end(); ++it ) {
252 <                        if( ! it->isEB() && skim )
252 >                        if( !(it->isEB() || it->isEE()) && skim )
253                                  continue;
254                          thisphoton->pt = getPtFromMatchedJet( *it, *event );
255 <                        if( thisphoton->pt < 80 && skim )
240 <                                continue;
241 <                        thisphoton->eta = it->momentum.Eta();
242 <                        thisphoton->phi = it->momentum.Phi();
255 >
256                          thisphoton->chargedIso = chargedHadronIso_corrected(*it, event->rho25);
257                          thisphoton->neutralIso = neutralHadronIso_corrected(*it, event->rho25);
258                          thisphoton->photonIso = photonIso_corrected(*it, event->rho25);
259 +
260 +                        bool loose_photon_barrel = thisphoton->pt>20
261 +                                && it->isEB()
262 +                                && it->passelectronveto
263 +                                && it->hadTowOverEm<0.05
264 +                                && it->sigmaIetaIeta<0.012
265 +                                && thisphoton->chargedIso<2.6
266 +                                && thisphoton->neutralIso<3.5+0.04*thisphoton->pt
267 +                                && thisphoton->photonIso<1.3+0.005*thisphoton->pt;
268 +                        bool loose_photon_endcap = thisphoton->pt > 20
269 +                                && it->isEE()
270 +                                && it->passelectronveto
271 +                                && it->hadTowOverEm<0.05
272 +                                && it->sigmaIetaIeta<0.034
273 +                                && thisphoton->chargedIso<2.3
274 +                                && thisphoton->neutralIso<2.9+0.04*thisphoton->pt;
275 +                        if(!(loose_photon_endcap || loose_photon_barrel || thisphoton->pt > 75 ) && skim )
276 +                                continue;
277 +                        thisphoton->eta = it->momentum.Eta();
278 +                        thisphoton->phi = it->momentum.Phi();
279                          thisphoton->r9 = it->r9;
280                          thisphoton->sigmaIetaIeta = it->sigmaIetaIeta;
281                          thisphoton->hadTowOverEm = it->hadTowOverEm;
# Line 283 | Line 316 | void TreeWriter::Loop() {
316                                  thisjet->eta = corrP4.Eta();
317                                  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  
# Line 313 | Line 358 | void TreeWriter::Loop() {
358                          std::cout << " type1met = " << type1met << std::endl;
359  
360                  // electrons
316                /*
361                  tree::Particle* thiselectron = new tree::Particle();
362                  map<TString, vector<susy::Electron> >::iterator eleMap = event->electrons.find("gsfElectrons");
363                  if(eleMap == event->electrons.end() && loggingVerbosity > 0) {
364                          cout << "gsfElectrons not found!" << endl;
365                  } else {
366                          for(vector<susy::Electron>::iterator it = eleMap->second.begin(); it < eleMap->second.end(); ++it) {
367 <                                thiselectron->pt = it->momentum.Et();
367 >                                // for cuts see https://twiki.cern.ch/twiki/bin/viewauth/CMS/EgammaCutBasedIdentification
368 >                                if( loggingVerbosity > 0)
369 >                                        std::cout << "TODO: piAtVtx is not calculated correctly" << std::endl;
370 >                                //float pAtVtx = it->trackMomentums.find("AtVtxWithConstraint")->second.P();
371 >                                float pAtVtx = it->ecalEnergy;
372 >                                if( it->momentum.Pt() < 1  || it->momentum.Pt() > 1e6 || pAtVtx == 0 )
373 >                                        continue;
374 >                                float iso = ( it->chargedHadronIso + max(it->neutralHadronIso+it->photonIso
375 >                                                                                                                        - effectiveAreaElectron(it->momentum.Eta())*event->rho25, (Float_t)0. )
376 >                                                        ) / it->momentum.Pt();
377 >                                if ( it->isEE() ){
378 >                                        if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.007
379 >                                                        || fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.15
380 >                                                        || it->sigmaIetaIeta > 0.01
381 >                                                        || it->hcalOverEcalBc > 0.12
382 >                                                        || it->vertex.Perp() > 0.02
383 >                                                        || it->vertex.Z() > 0.2
384 >                                                        || fabs(1./it->ecalEnergy - 1./pAtVtx ) > 0.05
385 >                                                        || iso > 0.15 )
386 >                                                continue;
387 >                                        }
388 >                                else if( it->isEB() ) {
389 >                                        if ( fabs(it->deltaEtaSuperClusterTrackAtVtx) > 0.009
390 >                                                        || fabs(it->deltaPhiSuperClusterTrackAtVtx) > 0.10
391 >                                                        || it->sigmaIetaIeta > 0.03
392 >                                                        || it->hcalOverEcalBc > 0.10
393 >                                                        || it->vertex.Perp() > 0.02
394 >                                                        || it->vertex.Z() > 0.2
395 >                                                        || fabs(1./it->ecalEnergy - 1./pAtVtx) > 0.05
396 >                                                        || iso > 0.15 )
397 >                                                continue;
398 >                                        }
399 >                                else // not in barrel nor in endcap
400 >                                        continue;
401 >                                // TODO: conversion rejection information not implemented yet, see twiki for more details
402 >
403 >                                thiselectron->pt = it->momentum.Pt();
404                                  if( thiselectron->pt < 20 )
405                                          continue;
406                                  if( loggingVerbosity > 2 )
# Line 332 | Line 412 | void TreeWriter::Loop() {
412                  }
413                  if( loggingVerbosity > 1 )
414                          std::cout << "Found " << electron.size() << " electrons" << std::endl;
335                */
336
337                // this seems not to work yet, where is the bug?
338                /*
339                std::vector<susy::Electron> eVector = event->electrons["gsfElectronsx"];
340                for( std::vector<susy::Electron>::iterator it = eVector.begin(); it != eVector.end(); ++it) {
341                        thiselectron->pt = it->momentum.Et();
342                        if( thiselectron->pt < 20 )
343                                continue;
344                        if( loggingVerbosity > 2 )
345                                std::cout << " p_T, electron = " << it->momentum.Et() << std::endl;
346                        thiselectron->eta = it->momentum.Eta();
347                        thiselectron->phi = it->momentum.Phi();
348                        electron.push_back( *thiselectron );
349                }
350                */
415  
416                  // muons
417                  std::vector<susy::Muon> mVector = event->muons["muons"];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines