ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/PhotonTools.cc
Revision: 1.35
Committed: Wed Jul 25 15:42:59 2012 UTC (12 years, 9 months ago) by fabstoec
Content type: text/plain
Branch: MAIN
Changes since 1.34: +3 -2 lines
Log Message:
minor fix in Vgamma ID

File Contents

# User Rev Content
1 fabstoec 1.35 // $Id: PhotonTools.cc,v 1.34 2012/07/25 15:00:41 fabstoec Exp $
2 bendavid 1.1
3     #include "MitPhysics/Utils/interface/PhotonTools.h"
4     #include "MitPhysics/Utils/interface/ElectronTools.h"
5 fabstoec 1.5 #include "MitPhysics/Utils/interface/IsolationTools.h"
6 bendavid 1.1 #include "MitAna/DataTree/interface/StableData.h"
7     #include <TFile.h>
8 fabstoec 1.8 #include <TRandom3.h>
9 bendavid 1.1
10     ClassImp(mithep::PhotonTools)
11    
12     using namespace mithep;
13    
14     //--------------------------------------------------------------------------------------------------
15     PhotonTools::PhotonTools()
16     {
17     // Constructor.
18     }
19    
20 bendavid 1.16 //--------------------------------------------------------------------------------------------------
21     PhotonTools::eScaleCats PhotonTools::EScaleCat(const Photon *p)
22     {
23     if (p->SCluster()->AbsEta()<1.0) {
24 bendavid 1.19 if (p->R9()>0.94) {
25     Int_t ieta = p->SCluster()->Seed()->IEta();
26     Int_t iphi = p->SCluster()->Seed()->IPhi();
27     Bool_t central = ( ((std::abs(ieta)-1)/5+1 >= 2 && (std::abs(ieta)-1)/5+1 < 5) || ((std::abs(ieta)-1)/5+1 >= 7 && (std::abs(ieta)-1)/5+1 < 9 ) || ((std::abs(ieta)-1)/5+1 >= 11 && (std::abs(ieta)-1)/5+1 < 13) || ((std::abs(ieta)-1)/5+1 >= 15 && (std::abs(ieta)-1)/5+1 < 17) ) && (iphi %20) > 5 && (iphi%20) <16;
28    
29     if (central) return kEBlowEtaGoldCenter;
30     else return kEBlowEtaGoldGap;
31     }
32 bendavid 1.16 else return kEBlowEtaBad;
33     }
34     else if (p->SCluster()->AbsEta()<1.5) {
35     if (p->R9()>0.94) return kEBhighEtaGold;
36     else return kEBhighEtaBad;
37     }
38     else if (p->SCluster()->AbsEta()<2.0) {
39     if (p->R9()>0.94) return kEElowEtaGold;
40     else return kEElowEtaBad;
41     }
42     else {
43     if (p->R9()>0.94) return kEEhighEtaGold;
44     else return kEEhighEtaBad;
45     }
46    
47     }
48 fabstoec 1.8
49     void PhotonTools::ScalePhoton(Photon* p, Double_t scale) {
50     if( !p ) return;
51     FourVectorM mom = p->Mom();
52     p->SetMom(scale*mom.X(), scale*mom.Y(), scale*mom.Z(), scale*mom.E());
53    
54     }
55    
56     void PhotonTools::SmearPhoton(Photon* p, TRandom3* rng, Double_t width, UInt_t iSeed) {
57    
58     if( !p ) return;
59     if( !rng) return;
60     if( width < 0.) return;
61    
62 fabstoec 1.10 rng->SetSeed(iSeed);
63 fabstoec 1.8 FourVectorM mom = p->Mom();
64     Double_t scale = rng->Gaus(1.,width);
65 fabstoec 1.10
66 fabstoec 1.8 if( scale > 0)
67     p->SetMom(scale*mom.X(), scale*mom.Y(), scale*mom.Z(), scale*mom.E());
68 bendavid 1.13
69     return;
70     }
71 fabstoec 1.8
72 bendavid 1.13 void PhotonTools::SmearPhotonError(Photon* p, Double_t width) {
73    
74     if( !p ) return;
75     if( width < 0.) return;
76    
77 bendavid 1.14
78     Double_t smear = p->EnergySmearing();
79     p->SetEnergySmearing(TMath::Sqrt(smear*smear+width*width*p->E()*p->E()));
80    
81 bendavid 1.13 Double_t err = p->EnergyErrSmeared();
82     if (err>=0.0) {
83     p->SetEnergyErrSmeared(TMath::Sqrt(err*err + width*width*p->E()*p->E()));
84     }
85    
86 fabstoec 1.8 }
87    
88 bendavid 1.16 void PhotonTools::ScalePhotonR9(Photon* p, Double_t scale) {
89     p->SetR9(scale*p->R9());
90     }
91    
92 bendavid 1.23
93 bendavid 1.16 void PhotonTools::ScalePhotonError(Photon* p, Double_t scale) {
94     p->SetEnergyErrSmeared(scale*p->EnergyErrSmeared());
95     }
96    
97 bendavid 1.1 //--------------------------------------------------------------------------------------------------
98     Bool_t PhotonTools::PassConversionId(const Photon *p, const DecayParticle *c) {
99    
100     if (!c) return kTRUE;
101    
102     ThreeVector dirconvsc = ThreeVector(p->SCluster()->Point()) - c->Position();
103     Double_t deta = c->Eta()-dirconvsc.Eta();
104     Double_t dphi = MathUtils::DeltaPhi(c->Phi(),dirconvsc.Phi());
105     Double_t eoverp = p->SCluster()->Energy()/c->P();
106    
107     if (p->IsEB() && eoverp>2.0) return kFALSE;
108     if (p->IsEE() && eoverp>3.0) return kFALSE;
109    
110     if (p->IsEE() && TMath::Abs(deta)>0.01) return kFALSE;
111     if (p->IsEE() && TMath::Abs(dphi)>0.01) return kFALSE;
112    
113     return kTRUE;
114    
115     }
116    
117     //--------------------------------------------------------------------------------------------------
118     Bool_t PhotonTools::PassElectronVeto(const Photon *p, const ElectronCol *els) {
119    
120     Bool_t pass = kTRUE;
121     for (UInt_t i=0; i<els->GetEntries(); ++i) {
122     const Electron *e = els->At(i);
123     if (e->SCluster()==p->SCluster() && e->GsfTrk()->NExpectedHitsInner()==0) {
124     pass = kFALSE;
125     }
126     }
127    
128     return pass;
129     }
130    
131     //--------------------------------------------------------------------------------------------------
132 bendavid 1.13 const Electron *PhotonTools::MatchedElectron(const Photon *p, const ElectronCol *els) {
133    
134     for (UInt_t i=0; i<els->GetEntries(); ++i) {
135     const Electron *e = els->At(i);
136     if ( e->SCluster()==p->SCluster() ) {
137     return e;
138     }
139     }
140    
141     return 0;
142     }
143    
144     //--------------------------------------------------------------------------------------------------
145     const Photon *PhotonTools::MatchedPhoton(const Electron *e, const PhotonCol *phs) {
146    
147     for (UInt_t i=0; i<phs->GetEntries(); ++i) {
148     const Photon *p = phs->At(i);
149     if ( p->SCluster()==e->SCluster() ) {
150     return p;
151     }
152     }
153    
154     return 0;
155     }
156    
157     //--------------------------------------------------------------------------------------------------
158     const SuperCluster *PhotonTools::MatchedSC(const SuperCluster *psc, const SuperClusterCol *scs, Double_t drMin) {
159    
160     Double_t drsmallest = 999.;
161     const SuperCluster *match = 0;
162     for (UInt_t i=0; i<scs->GetEntries(); ++i) {
163     const SuperCluster *sc = scs->At(i);
164     Double_t dr = MathUtils::DeltaR(*sc,*psc);
165     if ( dr<drsmallest && dr<drMin ) {
166     drsmallest = dr;
167     match = sc;
168     }
169     }
170    
171     return match;
172     }
173    
174     //--------------------------------------------------------------------------------------------------
175 bendavid 1.25 const SuperCluster *PhotonTools::MatchedPFSC(const SuperCluster *psc, const PhotonCol *pfphos, const ElectronCol *eles, Double_t drMin) {
176    
177    
178     if (pfphos) {
179     for (UInt_t i=0; i<pfphos->GetEntries(); ++i) {
180     const Photon *pfpho = pfphos->At(i);
181     if (psc == pfpho->SCluster() && pfpho->PFSCluster()) return pfpho->PFSCluster();
182     }
183     }
184    
185     for (UInt_t i=0; i<eles->GetEntries(); ++i) {
186     const Electron *ele = eles->At(i);
187     if (psc == ele->SCluster() && ele->PFSCluster()) return ele->PFSCluster();
188     }
189    
190     Double_t drsmallest = 999.;
191     const SuperCluster *match = 0;
192     for (UInt_t i=0; i<eles->GetEntries(); ++i) {
193     const Electron *ele = eles->At(i);
194     //if (psc == ele->SCluster() && ele->HasPFSCluster()) return ele->PFSCluster();
195     if (!ele->PFSCluster()) continue;
196    
197     Double_t dr = MathUtils::DeltaR(*ele->PFSCluster(),*psc);
198     if ( dr<drsmallest && dr<drMin ) {
199     drsmallest = dr;
200     match = ele->PFSCluster();
201     }
202     }
203    
204     return match;
205     }
206    
207     //--------------------------------------------------------------------------------------------------
208 fabstoec 1.4 Double_t PhotonTools::ElectronVetoCiC(const Photon *p, const ElectronCol *els) {
209    
210     for (UInt_t i=0; i<els->GetEntries(); ++i) {
211     const Electron *e = els->At(i);
212 fabstoec 1.5 if (e->SCluster()==p->SCluster() ) {
213     //if( e->GsfTrk()->NExpectedHitsInner()==0 && e->GsfTrk()->Pt() > 2.5 ) {
214     if( e->GsfTrk()->NExpectedHitsInner()==0 ) {
215     double dEta = e->DeltaEtaSuperClusterTrackAtVtx();
216     double dPhi = e->DeltaPhiSuperClusterTrackAtVtx();
217     double dR = TMath::Sqrt(dEta*dEta+dPhi*dPhi);
218     return dR;
219     }
220     }
221     }
222     return 99.;
223 fabstoec 1.4 }
224    
225     //--------------------------------------------------------------------------------------------------
226 bendavid 1.1 Bool_t PhotonTools::PassElectronVetoConvRecovery(const Photon *p, const ElectronCol *els, const DecayParticleCol *conversions, const BaseVertex *v) {
227    
228     Bool_t pass = kTRUE;
229     for (UInt_t i=0; i<els->GetEntries(); ++i) {
230     const Electron *e = els->At(i);
231 fabstoec 1.34
232     // HACVK to match CMSSW bug...
233 bendavid 1.1 if (e->SCluster()==p->SCluster() && e->GsfTrk()->NExpectedHitsInner()==0 && ElectronTools::PassConversionFilter(e, conversions,
234 fabstoec 1.31 v, 0, 0., 1e-6, kTRUE, kFALSE) ) {
235 fabstoec 1.34 // v, 0, 1e-6, 2.0, kFALSE, kFALSE) ) {
236 bendavid 1.1 pass = kFALSE;
237     }
238     }
239    
240     return pass;
241     }
242    
243     //--------------------------------------------------------------------------------------------------
244     Bool_t PhotonTools::PassTriggerMatching(const Photon *p, const TriggerObjectCol *trigobjs)
245     {
246    
247     for (UInt_t i=0; i<trigobjs->GetEntries(); ++i) {
248     const TriggerObject *trigobj = trigobjs->At(i);
249     if (trigobj->TriggerType()==TriggerObject::TriggerCluster || trigobj->TriggerType()==TriggerObject::TriggerElectron || trigobj->TriggerType()==TriggerObject::TriggerPhoton) {
250     if (MathUtils::DeltaR(p->SCluster(),trigobj)<0.3) {
251     return kTRUE;
252     }
253     }
254     }
255    
256     return kFALSE;
257    
258    
259     }
260    
261     //--------------------------------------------------------------------------------------------------
262     const DecayParticle *PhotonTools::MatchedConversion(const Photon *p, const DecayParticleCol *conversions,
263     const BaseVertex *vtx, Int_t nWrongHitsMax, Double_t probMin,
264     Double_t lxyMin, Double_t dRMin) {
265    
266 bendavid 1.13 return MatchedConversion(p->SCluster(), conversions, vtx, nWrongHitsMax, probMin, lxyMin, dRMin);
267    
268     }
269    
270     //--------------------------------------------------------------------------------------------------
271     const DecayParticle *PhotonTools::MatchedConversion(const SuperCluster *sc, const DecayParticleCol *conversions,
272     const BaseVertex *vtx, Int_t nWrongHitsMax, Double_t probMin,
273     Double_t lxyMin, Double_t dRMin) {
274    
275 bendavid 1.1 const DecayParticle *match = 0;
276 bendavid 1.3 Double_t rhosmallest = 999.;
277 bendavid 1.1 for (UInt_t i=0; i<conversions->GetEntries(); ++i) {
278     const DecayParticle *c = conversions->At(i);
279 bendavid 1.13 ThreeVector dirconvsc = ThreeVector(sc->Point()) - c->Position();
280 bendavid 1.1 Double_t dr = MathUtils::DeltaR(*c,dirconvsc);
281 bendavid 1.3 Double_t rho = c->Position().Rho();
282     if (dr<dRMin && rho<rhosmallest && c->Prob()>probMin && c->LxyCorrected(vtx)>lxyMin) {
283 bendavid 1.1 Int_t nhb1 = dynamic_cast<const StableData*>(c->DaughterDat(0))->NHitsBeforeVtx();
284     Int_t nhb2 = dynamic_cast<const StableData*>(c->DaughterDat(1))->NHitsBeforeVtx();
285     if (TMath::Max(nhb1,nhb2)<=nWrongHitsMax) {
286 bendavid 1.3 rhosmallest = rho;
287 bendavid 1.1 match = c;
288     }
289     }
290    
291     }
292    
293     return match;
294    
295     }
296    
297 bendavid 1.2 //--------------------------------------------------------------------------------------------------
298     const DecayParticle *PhotonTools::MatchedConversion(const Track *t, const DecayParticleCol *conversions,
299     const BaseVertex *vtx, Int_t nWrongHitsMax, Double_t probMin,
300     Double_t lxyMin) {
301    
302     for (UInt_t i=0; i<conversions->GetEntries(); ++i) {
303     const DecayParticle *c = conversions->At(i);
304     if (c->Prob()>probMin && c->LxyCorrected(vtx)>lxyMin) {
305     Int_t nhb1 = dynamic_cast<const StableData*>(c->DaughterDat(0))->NHitsBeforeVtx();
306     Int_t nhb2 = dynamic_cast<const StableData*>(c->DaughterDat(1))->NHitsBeforeVtx();
307     if (TMath::Max(nhb1,nhb2)<=nWrongHitsMax) {
308     const Track *ct1 = dynamic_cast<const ChargedParticle*>(c->Daughter(0))->Trk();
309     const Track *ct2 = dynamic_cast<const ChargedParticle*>(c->Daughter(1))->Trk();
310     if (t==ct1 || t==ct2) return c;
311     }
312     }
313    
314     }
315    
316     return 0;
317    
318     }
319    
320 bendavid 1.1 PhotonTools::DiphotonR9EtaCats PhotonTools::DiphotonR9EtaCat(const Photon *p1, const Photon *p2) {
321    
322     if (p1->IsEB() && p2->IsEB()) {
323     if (p1->R9()>0.93 && p2->R9()>0.93) return kCat1;
324     else return kCat2;
325    
326     }
327     else {
328     if (p1->R9()>0.93 && p2->R9()>0.93) return kCat3;
329     else return kCat4;
330     }
331    
332     }
333    
334     PhotonTools::DiphotonR9EtaConversionCats PhotonTools::DiphotonR9EtaConversionCat(const Photon *p1, const Photon *p2, const DecayParticleCol *conversions, const BaseVertex *v) {
335    
336     const DecayParticle *conv1 = MatchedConversion(p1, conversions, v);
337     const DecayParticle *conv2 = MatchedConversion(p2, conversions, v);
338    
339     if (p1->IsEB() && p2->IsEB()) {
340     if (p1->R9()>0.93 && p2->R9()>0.93) return kNewCat1;
341     else if (conv1||conv2) return kNewCat2;
342     else return kNewCat3;
343    
344     }
345     else {
346     if (p1->R9()>0.93 && p2->R9()>0.93) return kNewCat4;
347     else if (conv1||conv2) return kNewCat5;
348     else return kNewCat6;
349     }
350    
351 fabstoec 1.4 }
352    
353     PhotonTools::CiCBaseLineCats PhotonTools::CiCBaseLineCat(const Photon *p) {
354 bendavid 1.12 if( p->SCluster()->AbsEta()<1.5 ) {
355 fabstoec 1.4 if ( p->R9() > 0.94 ) return kCiCCat1;
356     else return kCiCCat2;
357     } else {
358     if ( p->R9() > 0.94 ) return kCiCCat3;
359     else return kCiCCat4;
360     }
361 fabstoec 1.8
362     // shoud NEVER happen, but you never know...
363     return kCiCNoCat;
364 fabstoec 1.4 }
365 fabstoec 1.5
366     //--------------------------------------------------------------------------------------------------
367     const DecayParticle *PhotonTools::MatchedCiCConversion(const Photon *p, const DecayParticleCol *conversions,
368     Double_t dPhiMin,
369 fabstoec 1.7 Double_t dEtaMin,
370     Double_t dRMin,
371     bool print) {
372 fabstoec 1.5
373 fabstoec 1.8 // if there are no conversons, return
374     if ( !p || !conversions) return NULL;
375    
376 fabstoec 1.6 const DecayParticle *match = NULL;
377    
378     double minDeta = 999.;
379     double minDphi = 999.;
380 fabstoec 1.7 double minDR = 999.;
381 fabstoec 1.6
382     double phPhi = p->SCluster()->Phi();
383     double phEta = p->SCluster()->Eta();
384 fabstoec 1.7
385     if(print)
386     std::cout<<" --- conv match photon eta = "<<phEta<<" phi = "<<phPhi<<std::endl;
387    
388    
389 fabstoec 1.5 for (UInt_t i=0; i<conversions->GetEntries(); ++i) {
390     const DecayParticle *c = conversions->At(i);
391 fabstoec 1.6
392 fabstoec 1.7 if(print)
393     std::cout<< " c "<<i+1<<" pt = "<<c->Pt()<<std::endl;
394 fabstoec 1.34
395     if (c->Pt() < 1. ) continue; // is this refittedPairMomentum?
396 bendavid 1.29 if (c->NDaughters()==2 && c->Prob() < 1e-6) continue;
397 bendavid 1.24
398 fabstoec 1.6 //ThreeVector dirconvsc = ThreeVector(p->SCluster()->Point()) - c->Position();
399     //ThreeVector dirconvsc = p->CaloPos() - c->Position();
400    
401     double convPhi = c->Phi();
402     double convEta = c->Eta();
403 fabstoec 1.7
404 fabstoec 1.6 const ThreeVector wrong(0,0,0);
405     double Zvertex = c->DzCorrected(wrong);
406     // ------------------ FROM GLOBE ----------------------
407     //---Definitions for ECAL
408     const float R_ECAL = 136.5;
409     const float Z_Endcap = 328.0;
410     const float etaBarrelEndcap = 1.479;
411 fabstoec 1.7
412 fabstoec 1.6 //---ETA correction
413     float Theta = 0.0 ;
414     float ZEcal = R_ECAL*sinh(convEta)+Zvertex;
415 fabstoec 1.7
416 fabstoec 1.6 if(ZEcal != 0.0) Theta = TMath::ATan(R_ECAL/ZEcal);
417     if(Theta<0.0) Theta = Theta+M_PI;
418     double fEta = - TMath::Log(TMath::Tan(0.5*Theta));
419 fabstoec 1.5
420 fabstoec 1.6 if( fabs(fEta) > etaBarrelEndcap ) {
421     float Zend = Z_Endcap ;
422     if(convEta<0.0 ) Zend = -Zend ;
423     float Zlen = Zend - Zvertex ;
424     float RR = Zlen/TMath::SinH(convEta);
425     Theta = TMath::ATan(RR/Zend);
426     if(Theta<0.0) Theta = Theta+M_PI;
427     fEta = -TMath::Log(TMath::Tan(0.5*Theta));
428     }
429     // ---------------------------------------------------
430    
431 fabstoec 1.7 if(print) {
432     std::cout<<" eta bare = "<<convEta<<std::endl;
433     std::cout<<" eta new = "<<fEta<<std::endl;
434     std::cout<<" phi = "<<convPhi<<std::endl;
435     }
436    
437     convEta = fEta;
438    
439 fabstoec 1.6 Double_t dphi = TMath::Abs(phPhi - convPhi);
440     if(dphi > M_PI) dphi = 2.*M_PI-dphi;
441     //Double_t deta = c->Eta()-dirconvsc.Eta();
442     Double_t deta = TMath::Abs(convEta-phEta);
443 fabstoec 1.7 Double_t dR = TMath::Sqrt(dphi*dphi+deta*deta);
444     //if(dphi < minDphi && TMath::Abs(deta)<minDeta) {
445     if(dR < minDR) {
446     minDR = dR;
447     minDphi = dphi;
448     minDeta = TMath::Abs(deta);
449     match = c;
450    
451     if(print)
452     std::cout<<" conv "<<i+1<<" matches with dPhi = "<<minDphi<<" dEta = "<<minDeta<<std::endl;
453    
454 fabstoec 1.6 }
455 fabstoec 1.5 }
456    
457 fabstoec 1.7 //if(minDphi < dPhiMin && minDeta < dEtaMin)
458     if(minDR < dRMin)
459     return match;
460     else
461     return NULL;
462 fabstoec 1.5 }
463    
464 fabstoec 1.9 bool PhotonTools::PassCiCSelection(const Photon* ph, const Vertex* vtx,
465     const TrackCol* trackCol,
466     const ElectronCol* eleCol,
467     const VertexCol* vtxCol,
468 fabstoec 1.5 double rho, double ptmin,
469 fabstoec 1.9 bool applyEleVeto,
470 fabstoec 1.5 bool print, float* kin) {
471 fabstoec 1.9
472 fabstoec 1.5
473     // these values are taken from the H2GGlobe code... (actually from Marco/s mail)
474     float cic4_allcuts_temp_sublead[] = {
475     3.8, 2.2, 1.77, 1.29,
476     11.7, 3.4, 3.9, 1.84,
477     3.5, 2.2, 2.3, 1.45,
478     0.0106, 0.0097, 0.028, 0.027,
479     0.082, 0.062, 0.065, 0.048,
480     0.94, 0.36, 0.94, 0.32,
481     1., 0.062, 0.97, 0.97,
482     1.5, 1.5, 1.5, 1.5 }; // the last line is PixelmatchVeto and un-used
483    
484     // cut on Et instead of Pt???
485     Bool_t isbarrel = ph->SCluster()->AbsEta()<1.5;
486    
487     // compute all relevant observables first
488     double ecalIso3 = ph->EcalRecHitIsoDr03();
489     double ecalIso4 = ph->EcalRecHitIsoDr04();
490     double hcalIso4 = ph->HcalTowerSumEtDr04();
491    
492     unsigned int wVtxInd = 0;
493    
494     double trackIso1 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol);
495    
496     // track iso only
497     double trackIso3 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol);
498    
499     // track iso worst vtx
500     double trackIso2 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, &wVtxInd, vtxCol);
501    
502     double combIso1 = ecalIso3+hcalIso4+trackIso1 - 0.17*rho;
503     double combIso2 = ecalIso4+hcalIso4+trackIso2 - 0.52*rho;
504    
505     double tIso1 = (combIso1) *50./ph->Et();
506     double tIso2 = (combIso2) *50./(ph->MomVtx(vtxCol->At(wVtxInd)->Position()).Pt());
507     //double tIso2 = (combIso2) *50./ph->Et();
508     double tIso3 = (trackIso3)*50./ph->Et();
509    
510     double covIEtaIEta =ph->CoviEtaiEta();
511     double HoE = ph->HadOverEm();
512    
513     double R9 = ph->R9();
514    
515     double dRTrack = PhotonTools::ElectronVetoCiC(ph, eleCol);
516    
517     // check which category it is ...
518     int _tCat = 1;
519     if ( !isbarrel ) _tCat = 3;
520     if ( R9 < 0.94 ) _tCat++;
521    
522     if(print) {
523     std::cout<<" -------------------------- "<<std::endl;
524 fabstoec 1.15
525     std::cout<<" trackIso1 = "<<trackIso1<<std::endl;
526     std::cout<<" trackIso2 = "<<trackIso2<<std::endl;
527     std::cout<<" trackIso3 = "<<trackIso3<<std::endl;
528     std::cout<<" ecalIso3 = "<<ecalIso3<<std::endl;
529     std::cout<<" ecalIso4 = "<<ecalIso4<<std::endl;
530     std::cout<<" hcalIso4 = "<<hcalIso4<<std::endl;
531    
532 fabstoec 1.5 std::cout<<" photon Et = "<<ph->Et()<<std::endl;
533 fabstoec 1.30 std::cout<<" Eta = "<<ph->SCluster()->Eta()<<std::endl;
534 fabstoec 1.15 std::cout<<" HoE = "<<HoE<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+4*4]<<")"<<std::endl;
535     std::cout<<" R9 = "<<R9<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+5*4]<<")"<<std::endl;
536     std::cout<<" dR = "<<dRTrack<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+6*4]<<")"<<std::endl;
537     std::cout<<" iso1 = "<<tIso1<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+0*4]<<")"<<std::endl;
538     std::cout<<" iso2 = "<<tIso2<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+1*4]<<")"<<std::endl;
539     std::cout<<" iso3 = "<<tIso3<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+2*4]<<")"<<std::endl;
540 fabstoec 1.5 }
541    
542     if(kin) {
543     kin[0] = tIso1;
544     kin[1] = tIso2;
545     kin[2] = tIso3;
546     kin[3] = covIEtaIEta;
547     kin[4] = HoE;
548     kin[5] = R9;
549     kin[6] = dRTrack;
550     kin[7] = (float) ph->Pt();
551     kin[8] = (float) ph->Eta();
552     kin[9] = (float) ph->Phi();
553    
554     // iso quantities separate
555     kin[10] = ecalIso3;
556     kin[11] = ecalIso4;
557     kin[12] = hcalIso4;
558     kin[13] = trackIso1;
559     kin[14] = trackIso2;
560     kin[15] = trackIso3;
561    
562     kin[16] = (float) ph->Et();
563     kin[17] = (float) ph->E();
564    
565 bendavid 1.11 kin[18] = (float) ph->SCluster()->Eta();
566     kin[19] = (float) ph->SCluster()->Phi();
567 fabstoec 1.5 }
568    
569     float passCuts = 1.;
570    
571     if ( ph->Pt() <= ptmin ) passCuts = -1.;
572    
573     // not needed anymore, do in pre-selection...
574     //if ( ph->SCluster()->AbsEta()>=2.5 || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) passCuts = -1.;
575    
576     if( ! ( tIso1 < cic4_allcuts_temp_sublead[_tCat-1+0*4]
577     && tIso2 < cic4_allcuts_temp_sublead[_tCat-1+1*4]
578     && tIso3 < cic4_allcuts_temp_sublead[_tCat-1+2*4]
579     && covIEtaIEta < cic4_allcuts_temp_sublead[_tCat-1+3*4]
580     && HoE < cic4_allcuts_temp_sublead[_tCat-1+4*4]
581     && R9 > cic4_allcuts_temp_sublead[_tCat-1+5*4]
582 fabstoec 1.9 && ( dRTrack > cic4_allcuts_temp_sublead[_tCat-1+6*4] || !applyEleVeto ) ) ) passCuts = -1.;
583 fabstoec 1.5
584 fabstoec 1.15 if(print) std::cout<<" ---> "<<passCuts<<std::endl;
585    
586 fabstoec 1.5 if(kin) {
587 bendavid 1.11 kin[20] = passCuts;
588     kin[21] = (float) _tCat;
589 fabstoec 1.5 }
590    
591     if(passCuts > 0.) return true;
592     return false;
593     }
594 bendavid 1.11
595 bendavid 1.27 bool PhotonTools::PassCiCPFIsoSelection(const Photon* ph,
596 fabstoec 1.30 const Vertex* vtx,
597     const PFCandidateCol* pfCol,
598     const VertexCol* vtxCol,
599     double rho, double ptmin,
600     std::vector<double>* kin // store variables for debugging...
601     ) {
602 bendavid 1.27
603     // these values are taken from the H2GGlobe code... (actually from Marco/s mail)
604     float cic4_allcuts_temp_sublead[] = {
605     6.0, 4.7, 5.6, 3.6,
606     10.0, 6.5, 5.6, 4.4,
607     3.8, 2.5, 3.1, 2.2,
608     0.0108, 0.0102, 0.028, 0.028,
609     0.124, 0.092, 0.142, 0.063,
610 fabstoec 1.30 0.94, 0.28, 0.94, 0.24 };
611 bendavid 1.27
612     // cut on Et instead of Pt???
613     Bool_t isbarrel = ph->SCluster()->AbsEta()<1.5;
614    
615    
616    
617     // compute all relevant observables first
618     double ecalIso3 = IsolationTools::PFGammaIsolation(ph, 0.3, 0.0, pfCol);
619     double ecalIso4 = IsolationTools::PFGammaIsolation(ph, 0.4, 0.0, pfCol);
620    
621     unsigned int wVtxInd = 0;
622    
623     double trackIsoSel03 = IsolationTools::PFChargedIsolation(ph, vtx, 0.3, 0.0, pfCol);
624    
625     // track iso worst vtx
626     double trackIsoWorst04 = IsolationTools::PFChargedIsolation(ph, vtx, 0.4, 0.00, pfCol, &wVtxInd, vtxCol);
627    
628 fabstoec 1.30 double combIso1 = ecalIso3+trackIsoSel03 + 2.5 - 0.09*rho;
629     double combIso2 = ecalIso4+trackIsoWorst04 + 2.5 - 0.23*rho;
630 bendavid 1.27
631     double tIso1 = (combIso1) *50./ph->Et();
632     double tIso2 = (combIso2) *50./(ph->MomVtx(vtxCol->At(wVtxInd)->Position()).Pt());
633     //double tIso2 = (combIso2) *50./ph->Et();
634     double tIso3 = (trackIsoSel03)*50./ph->Et();
635    
636     double covIEtaIEta =ph->CoviEtaiEta();
637     double HoE = ph->HadOverEm();
638    
639     double R9 = ph->R9();
640    
641     // check which category it is ...
642     int _tCat = 1;
643     if ( !isbarrel ) _tCat = 3;
644     if ( R9 < 0.94 ) _tCat++;
645    
646     float passCuts = 1.;
647    
648 fabstoec 1.30 if( kin ) {
649     kin->resize(0);
650    
651     kin->push_back(tIso1);
652     kin->push_back(tIso2);
653     kin->push_back(tIso3);
654     kin->push_back(covIEtaIEta);
655     kin->push_back(HoE);
656     kin->push_back(R9);
657    
658     kin->push_back( (double) wVtxInd );
659     kin->push_back( ecalIso3 );
660     kin->push_back( ecalIso4 );
661    
662     kin->push_back( trackIsoSel03 );
663     kin->push_back( trackIsoWorst04 );
664    
665     kin->push_back( combIso1 );
666     kin->push_back( combIso2 );
667     }
668    
669    
670 bendavid 1.27 if ( ph->Pt() <= ptmin ) passCuts = -1.;
671    
672     // not needed anymore, do in pre-selection...
673     //if ( ph->SCluster()->AbsEta()>=2.5 || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) passCuts = -1.;
674    
675     if( ! ( tIso1 < cic4_allcuts_temp_sublead[_tCat-1+0*4]
676     && tIso2 < cic4_allcuts_temp_sublead[_tCat-1+1*4]
677     && tIso3 < cic4_allcuts_temp_sublead[_tCat-1+2*4]
678     && covIEtaIEta < cic4_allcuts_temp_sublead[_tCat-1+3*4]
679     && HoE < cic4_allcuts_temp_sublead[_tCat-1+4*4]
680     && R9 > cic4_allcuts_temp_sublead[_tCat-1+5*4] ) ) passCuts = -1.;
681    
682    
683     if(passCuts > 0.) return true;
684     return false;
685     }
686    
687    
688    
689    
690    
691 bendavid 1.13 const MCParticle *PhotonTools::MatchMC(const Particle *ph, const MCParticleCol *c, Bool_t matchElectrons) {
692    
693     // printf("Start loop\n");
694 bendavid 1.11 for (UInt_t i=0; i<c->GetEntries(); ++i) {
695     const MCParticle *p = c->At(i);
696 bendavid 1.13 // if (p->IsGenerated() && p->AbsPdgId()==11 && (p->DistinctMother()->AbsPdgId()==23|| p->DistinctMother()->AbsPdgId()==24)) {
697     // printf("pdgid = %i, status = %i, pt = %5f, mother pdgid = %i\n",p->PdgId(),p->Status(),p->Pt(),p->Mother()->PdgId());
698 bendavid 1.12 // }
699     if (matchElectrons && p->AbsPdgId()==11 && p->IsGenerated() && p->Status()==3 && MathUtils::DeltaR(*ph,*p) < 0.3 && p->Mother() && (p->Mother()->AbsPdgId()==23 || p->Mother()->AbsPdgId()==24 || p->Mother()->AbsPdgId()==22)) {
700     return p;
701     }
702 bendavid 1.11 if ( p->AbsPdgId()==22 && p->IsGenerated() && MathUtils::DeltaR(*ph,*p) < 0.3 && p->Mother() && (p->Mother()->AbsPdgId()==25 || p->Mother()->AbsPdgId()<=21) ) {
703     return p;
704     }
705     }
706     return 0;
707 bendavid 1.12 }
708    
709     PhotonTools::DiphotonR9EtaPtCats PhotonTools::DiphotonR9EtaPtCat(const Photon *p1, const Photon *p2) {
710    
711     PhotonTools::CiCBaseLineCats cat1 = CiCBaseLineCat(p1);
712     PhotonTools::CiCBaseLineCats cat2 = CiCBaseLineCat(p2);
713    
714     PhotonTools::DiphotonR9EtaPtCats evtcat = PhotonTools::kOctCat0;
715    
716     bool ph1IsEB = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat2);
717     bool ph2IsEB = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat2);
718    
719     bool ph1IsHR9 = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat3);
720     bool ph2IsHR9 = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat3);
721    
722     if( ph1IsEB && ph2IsEB )
723     evtcat = ( ph1IsHR9 && ph2IsHR9 ? PhotonTools::kOctCat0 : PhotonTools::kOctCat1);
724     else
725     evtcat = ( ph1IsHR9 && ph2IsHR9 ? PhotonTools::kOctCat2 : PhotonTools::kOctCat3);
726    
727     float ptgg = (p1->Mom()+p2->Mom()).Pt();
728     if (ptgg<40.0) evtcat = PhotonTools::DiphotonR9EtaPtCats(evtcat + 4);
729    
730    
731     return evtcat;
732 fabstoec 1.15 }
733 mingyang 1.17
734 bendavid 1.22 Bool_t PhotonTools::PassSinglePhotonPresel(const Photon *p,const ElectronCol *els, const DecayParticleCol *conversions, const BaseVertex *bs, const TrackCol* trackCol,const Vertex *vtx, double rho, Bool_t applyElectronVeto, Bool_t invertElectronVeto) {
735 mingyang 1.17 float ScEta=p->SCluster()->Eta();
736     float Et=p->Et();
737     float R9=p->R9();
738     float HoE=p->HadOverEm();
739     float CovIEtaIEta=p->CoviEtaiEta();
740     float EcalIsoDr03=p->EcalRecHitIsoDr03();
741     float HcalIsoDr03=p->HcalTowerSumEtDr03();
742     float TrkIsoHollowDr03=p->HollowConeTrkIsoDr03();
743     float NewEcalIso=EcalIsoDr03-0.012*Et;
744     float NewHcalIso=HcalIsoDr03-0.005*Et;
745     float NewTrkIsoHollowDr03=TrkIsoHollowDr03-0.002*Et;
746     Bool_t IsBarrel=kFALSE;
747     Bool_t IsEndcap=kFALSE;
748 bendavid 1.22 Bool_t PassEleVetoRaw = PhotonTools::PassElectronVetoConvRecovery(p, els, conversions, bs);
749 bendavid 1.20 Bool_t PassEleVeto = (!applyElectronVeto && !invertElectronVeto) || (applyElectronVeto && !invertElectronVeto && PassEleVetoRaw) || (!applyElectronVeto && invertElectronVeto && !PassEleVetoRaw);
750 bendavid 1.22 float AbsTrackIsoCIC=IsolationTools::CiCTrackIsolation(p,vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0,trackCol, NULL, NULL, (!applyElectronVeto ? els : NULL) );
751 mingyang 1.18 float HcalEcalPUCorr=EcalIsoDr03+HcalIsoDr03-0.17*rho;
752    
753 mingyang 1.17 if(fabs(ScEta)<1.4442){IsBarrel=kTRUE;}
754     if(fabs(ScEta)>1.566 && fabs(ScEta)<2.5){IsEndcap=kTRUE;}
755     if((!IsBarrel) && (!IsEndcap)){
756     return kFALSE;
757     }
758     if(!PassEleVeto){
759     return kFALSE;
760     }
761     if(R9<=0.9){
762 bendavid 1.21 if(HoE<0.075 && ((IsBarrel && CovIEtaIEta<0.014) || (IsEndcap && CovIEtaIEta<0.034)) && NewEcalIso<4 && NewHcalIso<4 && NewTrkIsoHollowDr03<4 && HcalEcalPUCorr<3 && AbsTrackIsoCIC<2.8 && TrkIsoHollowDr03<4.0) {
763 mingyang 1.17 return kTRUE;
764     }
765     }
766     if(R9>0.9){
767 bendavid 1.21 if(((IsBarrel && HoE<0.082 && CovIEtaIEta<0.014) || (IsEndcap && HoE <0.075 && CovIEtaIEta<0.034)) && NewEcalIso<50 && NewHcalIso<50 && NewTrkIsoHollowDr03<50 && HcalEcalPUCorr<3 && AbsTrackIsoCIC<2.8 && TrkIsoHollowDr03<4.0) {
768 mingyang 1.17 return kTRUE;
769     }
770     }
771     return kFALSE;
772     }
773 mingyang 1.26
774     Bool_t PhotonTools::PassSinglePhotonPreselPFISO(const Photon *p,const ElectronCol *els, const DecayParticleCol *conversions, const BaseVertex *bs, const TrackCol* trackCol,const Vertex *vtx, double rho, const PFCandidateCol *fPFCands, Bool_t applyElectronVeto, Bool_t invertElectronVeto) {
775 fabstoec 1.34
776    
777 mingyang 1.26 float ScEta=p->SCluster()->Eta();
778     float Et=p->Et();
779     float R9=p->R9();
780     float HoE=p->HadOverEm();
781     float CovIEtaIEta=p->CoviEtaiEta();
782     float EcalIsoDr03=p->EcalRecHitIsoDr03();
783     float HcalIsoDr03=p->HcalTowerSumEtDr03();
784     float TrkIsoHollowDr03=p->HollowConeTrkIsoDr03();
785 fabstoec 1.34
786 mingyang 1.26 float NewEcalIso=EcalIsoDr03-0.012*Et;
787     float NewHcalIso=HcalIsoDr03-0.005*Et;
788     float NewTrkIsoHollowDr03=TrkIsoHollowDr03-0.002*Et;
789 fabstoec 1.34
790    
791 mingyang 1.26 Bool_t IsBarrel=kFALSE;
792     Bool_t IsEndcap=kFALSE;
793     Bool_t PassEleVetoRaw = PhotonTools::PassElectronVetoConvRecovery(p, els, conversions, bs);
794     Bool_t PassEleVeto = (!applyElectronVeto && !invertElectronVeto) || (applyElectronVeto && !invertElectronVeto && PassEleVetoRaw) || (!applyElectronVeto && invertElectronVeto && !PassEleVetoRaw);
795 bendavid 1.27 float ChargedIso_selvtx_DR002To0p02=IsolationTools::PFChargedIsolation(p,vtx, 0.2, 0.,fPFCands);
796 mingyang 1.26 if(fabs(ScEta)<1.4442){IsBarrel=kTRUE;}
797     if(fabs(ScEta)>1.566 && fabs(ScEta)<2.5){IsEndcap=kTRUE;}
798     if((!IsBarrel) && (!IsEndcap)){
799     return kFALSE;
800     }
801     if(!PassEleVeto){
802     return kFALSE;
803     }
804     if(R9<=0.9){
805     if(HoE<0.075 && ((IsBarrel && CovIEtaIEta<0.014) || (IsEndcap && CovIEtaIEta<0.034)) && NewEcalIso<4 && NewHcalIso<4 && NewTrkIsoHollowDr03<4 && ChargedIso_selvtx_DR002To0p02<4) {
806     return kTRUE;
807     }
808     }
809     if(R9>0.9){
810     if(((IsBarrel && HoE<0.082 && CovIEtaIEta<0.014) || (IsEndcap && HoE <0.075 && CovIEtaIEta<0.034)) && NewEcalIso<50 && NewHcalIso<50 && NewTrkIsoHollowDr03<50 && ChargedIso_selvtx_DR002To0p02<4) {
811     return kTRUE;
812     }
813     }
814     return kFALSE;
815     }
816 fabstoec 1.32
817 fabstoec 1.34 bool PhotonTools::PassVgamma2011Selection(const Photon* ph, double rho) {
818    
819     bool isEB = (ph->SCluster()->AbsEta()<1.5);
820    
821     if (ph->HasPixelSeed()) return false; // ? is this what we want ?
822     if (ph->HadOverEm() > 0.05) return false;
823     if (ph->CoviEtaiEta() > (isEB ? 0.011 : 0.03) ) return false;
824     if (ph->HollowConeTrkIsoDr04() > ( 2.0 + 0.001 *ph->Pt() +
825     (isEB ? 0.0167 : 0.032)*rho )) return false;
826     if (ph->EcalRecHitIsoDr04() > ( 4.2 + 0.006 *ph->Pt() +
827     (isEB ? 0.183 : 0.090)*rho )) return false;
828     if (ph->HcalTowerSumEtDr04() > ( 2.2 + 0.0025*ph->Pt() +
829     (isEB ? 0.062 : 0.180)*rho )) return false;
830    
831     // spike cleaning...
832 fabstoec 1.35 if ( ph->CoviEtaiEta() < 0.001 && TMath::Sqrt(TMath::Abs(ph->SCluster()->Seed()->CoviPhiiPhi())) < 0.001)
833     return false;
834 fabstoec 1.34
835     return true;
836     }
837 fabstoec 1.32
838     void PhotonTools::ScalePhotonShowerShapes(Photon* p, PhotonTools::ShowerShapeScales scale) {
839    
840     switch(scale) {
841    
842     case kNoShowerShapeScaling:
843     break;
844    
845     case k2011ShowerShape:
846     //regression sigmaE
847     if (p->SCluster()->AbsEta()<1.5)
848     PhotonTools::ScalePhotonError(p,1.07);
849     else
850     PhotonTools::ScalePhotonError(p,1.045);
851    
852     //R9
853     if (p->SCluster()->AbsEta()<1.5) p->SetR9(1.0035*p->R9());
854     else p->SetR9(1.0035*p->R9());
855     //CoviEtaiEta(SigiEtaiEta)
856     if (p->SCluster()->AbsEta()<1.5) p->SetCoviEtaiEta(0.87*p->CoviEtaiEta()+0.0011);
857     else p->SetCoviEtaiEta(0.99*p->CoviEtaiEta());
858     //EtaWidth
859     if (p->SCluster()->AbsEta()<1.5) p->SetEtaWidth(0.99*p->EtaWidth());
860     else p->SetEtaWidth(0.99*p->EtaWidth());
861     //PhiWidth
862     if (p->SCluster()->AbsEta()<1.5) p->SetPhiWidth(0.99*p->PhiWidth());
863     else p->SetPhiWidth(0.99*p->PhiWidth());
864     break;
865    
866 bendavid 1.33 case k2012ShowerShape:
867 fabstoec 1.32 //R9
868     if (p->SCluster()->AbsEta()<1.5) p->SetR9(1.0045*p->R9()+0.001);
869     else p->SetR9(1.0086*p->R9()-0.0007);
870     //CoviEtaiEta(SigiEtaiEta)
871     if (p->SCluster()->AbsEta()<1.5) p->SetCoviEtaiEta(0.891832*p->CoviEtaiEta()+0.0009133);
872     else p->SetCoviEtaiEta(0.9947*p->CoviEtaiEta()+0.00003);
873     //EtaWidth
874     if (p->SCluster()->AbsEta()<1.5) p->SetEtaWidth(1.04302*p->EtaWidth()- 0.000618);
875     else p->SetEtaWidth(0.903254*p->EtaWidth()+ 0.001346);
876     //PhiWidth
877     if (p->SCluster()->AbsEta()<1.5) p->SetPhiWidth(1.00002*p->PhiWidth()- 0.000371);
878     else p->SetPhiWidth(0.99992*p->PhiWidth()+ 4.8e-07);
879     //s4Ratio
880     if (p->SCluster()->AbsEta()<1.5) p->SetS4Ratio(1.01894*p->S4Ratio()-0.01034);
881     else p->SetS4Ratio(1.04969*p->S4Ratio()-0.03642);
882     break;
883     default:
884     break;
885    
886     }
887     return;
888     }
889