ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/PhotonTools.cc
Revision: 1.24
Committed: Thu Mar 22 16:25:19 2012 UTC (13 years, 1 month ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_028, Mit_027, Mit_027a, Mit_025e, Mit_025d
Changes since 1.23: +3 -1 lines
Log Message:
additional gamma gamma synchronization for reload

File Contents

# User Rev Content
1 bendavid 1.24 // $Id: PhotonTools.cc,v 1.23 2011/12/17 22:29:31 bendavid 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 fabstoec 1.4 Double_t PhotonTools::ElectronVetoCiC(const Photon *p, const ElectronCol *els) {
176    
177     for (UInt_t i=0; i<els->GetEntries(); ++i) {
178     const Electron *e = els->At(i);
179 fabstoec 1.5 if (e->SCluster()==p->SCluster() ) {
180     //if( e->GsfTrk()->NExpectedHitsInner()==0 && e->GsfTrk()->Pt() > 2.5 ) {
181     if( e->GsfTrk()->NExpectedHitsInner()==0 ) {
182     double dEta = e->DeltaEtaSuperClusterTrackAtVtx();
183     double dPhi = e->DeltaPhiSuperClusterTrackAtVtx();
184     double dR = TMath::Sqrt(dEta*dEta+dPhi*dPhi);
185     return dR;
186     }
187     }
188     }
189     return 99.;
190 fabstoec 1.4 }
191    
192     //--------------------------------------------------------------------------------------------------
193 bendavid 1.1 Bool_t PhotonTools::PassElectronVetoConvRecovery(const Photon *p, const ElectronCol *els, const DecayParticleCol *conversions, const BaseVertex *v) {
194    
195     Bool_t pass = kTRUE;
196     for (UInt_t i=0; i<els->GetEntries(); ++i) {
197     const Electron *e = els->At(i);
198     if (e->SCluster()==p->SCluster() && e->GsfTrk()->NExpectedHitsInner()==0 && ElectronTools::PassConversionFilter(e, conversions,
199     v, 0, 1e-6, 2.0, kFALSE, kFALSE) ) {
200     pass = kFALSE;
201     }
202     }
203    
204     return pass;
205     }
206    
207     //--------------------------------------------------------------------------------------------------
208     Bool_t PhotonTools::PassTriggerMatching(const Photon *p, const TriggerObjectCol *trigobjs)
209     {
210    
211     for (UInt_t i=0; i<trigobjs->GetEntries(); ++i) {
212     const TriggerObject *trigobj = trigobjs->At(i);
213     if (trigobj->TriggerType()==TriggerObject::TriggerCluster || trigobj->TriggerType()==TriggerObject::TriggerElectron || trigobj->TriggerType()==TriggerObject::TriggerPhoton) {
214     if (MathUtils::DeltaR(p->SCluster(),trigobj)<0.3) {
215     return kTRUE;
216     }
217     }
218     }
219    
220     return kFALSE;
221    
222    
223     }
224    
225     //--------------------------------------------------------------------------------------------------
226     const DecayParticle *PhotonTools::MatchedConversion(const Photon *p, const DecayParticleCol *conversions,
227     const BaseVertex *vtx, Int_t nWrongHitsMax, Double_t probMin,
228     Double_t lxyMin, Double_t dRMin) {
229    
230 bendavid 1.13 return MatchedConversion(p->SCluster(), conversions, vtx, nWrongHitsMax, probMin, lxyMin, dRMin);
231    
232     }
233    
234     //--------------------------------------------------------------------------------------------------
235     const DecayParticle *PhotonTools::MatchedConversion(const SuperCluster *sc, const DecayParticleCol *conversions,
236     const BaseVertex *vtx, Int_t nWrongHitsMax, Double_t probMin,
237     Double_t lxyMin, Double_t dRMin) {
238    
239 bendavid 1.1 const DecayParticle *match = 0;
240 bendavid 1.3 Double_t rhosmallest = 999.;
241 bendavid 1.1 for (UInt_t i=0; i<conversions->GetEntries(); ++i) {
242     const DecayParticle *c = conversions->At(i);
243 bendavid 1.13 ThreeVector dirconvsc = ThreeVector(sc->Point()) - c->Position();
244 bendavid 1.1 Double_t dr = MathUtils::DeltaR(*c,dirconvsc);
245 bendavid 1.3 Double_t rho = c->Position().Rho();
246     if (dr<dRMin && rho<rhosmallest && c->Prob()>probMin && c->LxyCorrected(vtx)>lxyMin) {
247 bendavid 1.1 Int_t nhb1 = dynamic_cast<const StableData*>(c->DaughterDat(0))->NHitsBeforeVtx();
248     Int_t nhb2 = dynamic_cast<const StableData*>(c->DaughterDat(1))->NHitsBeforeVtx();
249     if (TMath::Max(nhb1,nhb2)<=nWrongHitsMax) {
250 bendavid 1.3 rhosmallest = rho;
251 bendavid 1.1 match = c;
252     }
253     }
254    
255     }
256    
257     return match;
258    
259     }
260    
261 bendavid 1.2 //--------------------------------------------------------------------------------------------------
262     const DecayParticle *PhotonTools::MatchedConversion(const Track *t, const DecayParticleCol *conversions,
263     const BaseVertex *vtx, Int_t nWrongHitsMax, Double_t probMin,
264     Double_t lxyMin) {
265    
266     for (UInt_t i=0; i<conversions->GetEntries(); ++i) {
267     const DecayParticle *c = conversions->At(i);
268     if (c->Prob()>probMin && c->LxyCorrected(vtx)>lxyMin) {
269     Int_t nhb1 = dynamic_cast<const StableData*>(c->DaughterDat(0))->NHitsBeforeVtx();
270     Int_t nhb2 = dynamic_cast<const StableData*>(c->DaughterDat(1))->NHitsBeforeVtx();
271     if (TMath::Max(nhb1,nhb2)<=nWrongHitsMax) {
272     const Track *ct1 = dynamic_cast<const ChargedParticle*>(c->Daughter(0))->Trk();
273     const Track *ct2 = dynamic_cast<const ChargedParticle*>(c->Daughter(1))->Trk();
274     if (t==ct1 || t==ct2) return c;
275     }
276     }
277    
278     }
279    
280     return 0;
281    
282     }
283    
284 bendavid 1.1 PhotonTools::DiphotonR9EtaCats PhotonTools::DiphotonR9EtaCat(const Photon *p1, const Photon *p2) {
285    
286     if (p1->IsEB() && p2->IsEB()) {
287     if (p1->R9()>0.93 && p2->R9()>0.93) return kCat1;
288     else return kCat2;
289    
290     }
291     else {
292     if (p1->R9()>0.93 && p2->R9()>0.93) return kCat3;
293     else return kCat4;
294     }
295    
296     }
297    
298     PhotonTools::DiphotonR9EtaConversionCats PhotonTools::DiphotonR9EtaConversionCat(const Photon *p1, const Photon *p2, const DecayParticleCol *conversions, const BaseVertex *v) {
299    
300     const DecayParticle *conv1 = MatchedConversion(p1, conversions, v);
301     const DecayParticle *conv2 = MatchedConversion(p2, conversions, v);
302    
303     if (p1->IsEB() && p2->IsEB()) {
304     if (p1->R9()>0.93 && p2->R9()>0.93) return kNewCat1;
305     else if (conv1||conv2) return kNewCat2;
306     else return kNewCat3;
307    
308     }
309     else {
310     if (p1->R9()>0.93 && p2->R9()>0.93) return kNewCat4;
311     else if (conv1||conv2) return kNewCat5;
312     else return kNewCat6;
313     }
314    
315 fabstoec 1.4 }
316    
317     PhotonTools::CiCBaseLineCats PhotonTools::CiCBaseLineCat(const Photon *p) {
318 bendavid 1.12 if( p->SCluster()->AbsEta()<1.5 ) {
319 fabstoec 1.4 if ( p->R9() > 0.94 ) return kCiCCat1;
320     else return kCiCCat2;
321     } else {
322     if ( p->R9() > 0.94 ) return kCiCCat3;
323     else return kCiCCat4;
324     }
325 fabstoec 1.8
326     // shoud NEVER happen, but you never know...
327     return kCiCNoCat;
328 fabstoec 1.4 }
329 fabstoec 1.5
330     //--------------------------------------------------------------------------------------------------
331     const DecayParticle *PhotonTools::MatchedCiCConversion(const Photon *p, const DecayParticleCol *conversions,
332     Double_t dPhiMin,
333 fabstoec 1.7 Double_t dEtaMin,
334     Double_t dRMin,
335     bool print) {
336 fabstoec 1.5
337 fabstoec 1.8 // if there are no conversons, return
338     if ( !p || !conversions) return NULL;
339    
340 fabstoec 1.6 const DecayParticle *match = NULL;
341    
342     double minDeta = 999.;
343     double minDphi = 999.;
344 fabstoec 1.7 double minDR = 999.;
345 fabstoec 1.6
346     double phPhi = p->SCluster()->Phi();
347     double phEta = p->SCluster()->Eta();
348 fabstoec 1.7
349     if(print)
350     std::cout<<" --- conv match photon eta = "<<phEta<<" phi = "<<phPhi<<std::endl;
351    
352    
353 fabstoec 1.5 for (UInt_t i=0; i<conversions->GetEntries(); ++i) {
354     const DecayParticle *c = conversions->At(i);
355 fabstoec 1.6
356 fabstoec 1.7 if(print)
357     std::cout<< " c "<<i+1<<" pt = "<<c->Pt()<<std::endl;
358    
359 fabstoec 1.6 if(c->Pt() < 1. ) continue; // is this refittedPirMomentum?
360    
361 bendavid 1.24 if (c->Prob() < 1e-6) continue;
362    
363 fabstoec 1.6 //ThreeVector dirconvsc = ThreeVector(p->SCluster()->Point()) - c->Position();
364     //ThreeVector dirconvsc = p->CaloPos() - c->Position();
365    
366     double convPhi = c->Phi();
367     double convEta = c->Eta();
368 fabstoec 1.7
369 fabstoec 1.6 const ThreeVector wrong(0,0,0);
370     double Zvertex = c->DzCorrected(wrong);
371     // ------------------ FROM GLOBE ----------------------
372     //---Definitions for ECAL
373     const float R_ECAL = 136.5;
374     const float Z_Endcap = 328.0;
375     const float etaBarrelEndcap = 1.479;
376 fabstoec 1.7
377 fabstoec 1.6 //---ETA correction
378     float Theta = 0.0 ;
379     float ZEcal = R_ECAL*sinh(convEta)+Zvertex;
380 fabstoec 1.7
381 fabstoec 1.6 if(ZEcal != 0.0) Theta = TMath::ATan(R_ECAL/ZEcal);
382     if(Theta<0.0) Theta = Theta+M_PI;
383     double fEta = - TMath::Log(TMath::Tan(0.5*Theta));
384 fabstoec 1.5
385 fabstoec 1.6 if( fabs(fEta) > etaBarrelEndcap ) {
386     float Zend = Z_Endcap ;
387     if(convEta<0.0 ) Zend = -Zend ;
388     float Zlen = Zend - Zvertex ;
389     float RR = Zlen/TMath::SinH(convEta);
390     Theta = TMath::ATan(RR/Zend);
391     if(Theta<0.0) Theta = Theta+M_PI;
392     fEta = -TMath::Log(TMath::Tan(0.5*Theta));
393     }
394     // ---------------------------------------------------
395    
396 fabstoec 1.7 if(print) {
397     std::cout<<" eta bare = "<<convEta<<std::endl;
398     std::cout<<" eta new = "<<fEta<<std::endl;
399     std::cout<<" phi = "<<convPhi<<std::endl;
400     }
401    
402     convEta = fEta;
403    
404 fabstoec 1.6 Double_t dphi = TMath::Abs(phPhi - convPhi);
405     if(dphi > M_PI) dphi = 2.*M_PI-dphi;
406     //Double_t deta = c->Eta()-dirconvsc.Eta();
407     Double_t deta = TMath::Abs(convEta-phEta);
408 fabstoec 1.7 Double_t dR = TMath::Sqrt(dphi*dphi+deta*deta);
409     //if(dphi < minDphi && TMath::Abs(deta)<minDeta) {
410     if(dR < minDR) {
411     minDR = dR;
412     minDphi = dphi;
413     minDeta = TMath::Abs(deta);
414     match = c;
415    
416     if(print)
417     std::cout<<" conv "<<i+1<<" matches with dPhi = "<<minDphi<<" dEta = "<<minDeta<<std::endl;
418    
419 fabstoec 1.6 }
420 fabstoec 1.5 }
421    
422 fabstoec 1.7 //if(minDphi < dPhiMin && minDeta < dEtaMin)
423     if(minDR < dRMin)
424     return match;
425     else
426     return NULL;
427 fabstoec 1.5 }
428    
429 fabstoec 1.9 bool PhotonTools::PassCiCSelection(const Photon* ph, const Vertex* vtx,
430     const TrackCol* trackCol,
431     const ElectronCol* eleCol,
432     const VertexCol* vtxCol,
433 fabstoec 1.5 double rho, double ptmin,
434 fabstoec 1.9 bool applyEleVeto,
435 fabstoec 1.5 bool print, float* kin) {
436 fabstoec 1.9
437 fabstoec 1.5
438     // these values are taken from the H2GGlobe code... (actually from Marco/s mail)
439     float cic4_allcuts_temp_sublead[] = {
440     3.8, 2.2, 1.77, 1.29,
441     11.7, 3.4, 3.9, 1.84,
442     3.5, 2.2, 2.3, 1.45,
443     0.0106, 0.0097, 0.028, 0.027,
444     0.082, 0.062, 0.065, 0.048,
445     0.94, 0.36, 0.94, 0.32,
446     1., 0.062, 0.97, 0.97,
447     1.5, 1.5, 1.5, 1.5 }; // the last line is PixelmatchVeto and un-used
448    
449     // cut on Et instead of Pt???
450     Bool_t isbarrel = ph->SCluster()->AbsEta()<1.5;
451    
452     // compute all relevant observables first
453     double ecalIso3 = ph->EcalRecHitIsoDr03();
454     double ecalIso4 = ph->EcalRecHitIsoDr04();
455     double hcalIso4 = ph->HcalTowerSumEtDr04();
456    
457     unsigned int wVtxInd = 0;
458    
459     double trackIso1 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol);
460    
461     // track iso only
462     double trackIso3 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol);
463    
464     // track iso worst vtx
465     double trackIso2 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, &wVtxInd, vtxCol);
466    
467     double combIso1 = ecalIso3+hcalIso4+trackIso1 - 0.17*rho;
468     double combIso2 = ecalIso4+hcalIso4+trackIso2 - 0.52*rho;
469    
470     double tIso1 = (combIso1) *50./ph->Et();
471     double tIso2 = (combIso2) *50./(ph->MomVtx(vtxCol->At(wVtxInd)->Position()).Pt());
472     //double tIso2 = (combIso2) *50./ph->Et();
473     double tIso3 = (trackIso3)*50./ph->Et();
474    
475     double covIEtaIEta =ph->CoviEtaiEta();
476     double HoE = ph->HadOverEm();
477    
478     double R9 = ph->R9();
479    
480     double dRTrack = PhotonTools::ElectronVetoCiC(ph, eleCol);
481    
482     // check which category it is ...
483     int _tCat = 1;
484     if ( !isbarrel ) _tCat = 3;
485     if ( R9 < 0.94 ) _tCat++;
486    
487     if(print) {
488     std::cout<<" -------------------------- "<<std::endl;
489 fabstoec 1.15
490     std::cout<<" trackIso1 = "<<trackIso1<<std::endl;
491     std::cout<<" trackIso2 = "<<trackIso2<<std::endl;
492     std::cout<<" trackIso3 = "<<trackIso3<<std::endl;
493     std::cout<<" ecalIso3 = "<<ecalIso3<<std::endl;
494     std::cout<<" ecalIso4 = "<<ecalIso4<<std::endl;
495     std::cout<<" hcalIso4 = "<<hcalIso4<<std::endl;
496    
497 fabstoec 1.5 std::cout<<" photon Et = "<<ph->Et()<<std::endl;
498 mingyang 1.17 std::cout<<" Eta = "<<ph->SCluster()->Eta()<<std::endl;
499 fabstoec 1.15 std::cout<<" HoE = "<<HoE<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+4*4]<<")"<<std::endl;
500     std::cout<<" R9 = "<<R9<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+5*4]<<")"<<std::endl;
501     std::cout<<" dR = "<<dRTrack<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+6*4]<<")"<<std::endl;
502     std::cout<<" iso1 = "<<tIso1<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+0*4]<<")"<<std::endl;
503     std::cout<<" iso2 = "<<tIso2<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+1*4]<<")"<<std::endl;
504     std::cout<<" iso3 = "<<tIso3<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+2*4]<<")"<<std::endl;
505 fabstoec 1.5 }
506    
507     if(kin) {
508     kin[0] = tIso1;
509     kin[1] = tIso2;
510     kin[2] = tIso3;
511     kin[3] = covIEtaIEta;
512     kin[4] = HoE;
513     kin[5] = R9;
514     kin[6] = dRTrack;
515     kin[7] = (float) ph->Pt();
516     kin[8] = (float) ph->Eta();
517     kin[9] = (float) ph->Phi();
518    
519     // iso quantities separate
520     kin[10] = ecalIso3;
521     kin[11] = ecalIso4;
522     kin[12] = hcalIso4;
523     kin[13] = trackIso1;
524     kin[14] = trackIso2;
525     kin[15] = trackIso3;
526    
527     kin[16] = (float) ph->Et();
528     kin[17] = (float) ph->E();
529    
530 bendavid 1.11 kin[18] = (float) ph->SCluster()->Eta();
531     kin[19] = (float) ph->SCluster()->Phi();
532 fabstoec 1.5 }
533    
534     float passCuts = 1.;
535    
536     if ( ph->Pt() <= ptmin ) passCuts = -1.;
537    
538     // not needed anymore, do in pre-selection...
539     //if ( ph->SCluster()->AbsEta()>=2.5 || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) passCuts = -1.;
540    
541     if( ! ( tIso1 < cic4_allcuts_temp_sublead[_tCat-1+0*4]
542     && tIso2 < cic4_allcuts_temp_sublead[_tCat-1+1*4]
543     && tIso3 < cic4_allcuts_temp_sublead[_tCat-1+2*4]
544     && covIEtaIEta < cic4_allcuts_temp_sublead[_tCat-1+3*4]
545     && HoE < cic4_allcuts_temp_sublead[_tCat-1+4*4]
546     && R9 > cic4_allcuts_temp_sublead[_tCat-1+5*4]
547 fabstoec 1.9 && ( dRTrack > cic4_allcuts_temp_sublead[_tCat-1+6*4] || !applyEleVeto ) ) ) passCuts = -1.;
548 fabstoec 1.5
549 fabstoec 1.15 if(print) std::cout<<" ---> "<<passCuts<<std::endl;
550    
551 fabstoec 1.5 if(kin) {
552 bendavid 1.11 kin[20] = passCuts;
553     kin[21] = (float) _tCat;
554 fabstoec 1.5 }
555    
556     if(passCuts > 0.) return true;
557     return false;
558     }
559 bendavid 1.11
560 bendavid 1.13 const MCParticle *PhotonTools::MatchMC(const Particle *ph, const MCParticleCol *c, Bool_t matchElectrons) {
561    
562     // printf("Start loop\n");
563 bendavid 1.11 for (UInt_t i=0; i<c->GetEntries(); ++i) {
564     const MCParticle *p = c->At(i);
565 bendavid 1.13 // if (p->IsGenerated() && p->AbsPdgId()==11 && (p->DistinctMother()->AbsPdgId()==23|| p->DistinctMother()->AbsPdgId()==24)) {
566     // printf("pdgid = %i, status = %i, pt = %5f, mother pdgid = %i\n",p->PdgId(),p->Status(),p->Pt(),p->Mother()->PdgId());
567 bendavid 1.12 // }
568     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)) {
569     return p;
570     }
571 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) ) {
572     return p;
573     }
574     }
575     return 0;
576 bendavid 1.12 }
577    
578     PhotonTools::DiphotonR9EtaPtCats PhotonTools::DiphotonR9EtaPtCat(const Photon *p1, const Photon *p2) {
579    
580     PhotonTools::CiCBaseLineCats cat1 = CiCBaseLineCat(p1);
581     PhotonTools::CiCBaseLineCats cat2 = CiCBaseLineCat(p2);
582    
583     PhotonTools::DiphotonR9EtaPtCats evtcat = PhotonTools::kOctCat0;
584    
585     bool ph1IsEB = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat2);
586     bool ph2IsEB = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat2);
587    
588     bool ph1IsHR9 = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat3);
589     bool ph2IsHR9 = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat3);
590    
591     if( ph1IsEB && ph2IsEB )
592     evtcat = ( ph1IsHR9 && ph2IsHR9 ? PhotonTools::kOctCat0 : PhotonTools::kOctCat1);
593     else
594     evtcat = ( ph1IsHR9 && ph2IsHR9 ? PhotonTools::kOctCat2 : PhotonTools::kOctCat3);
595    
596     float ptgg = (p1->Mom()+p2->Mom()).Pt();
597     if (ptgg<40.0) evtcat = PhotonTools::DiphotonR9EtaPtCats(evtcat + 4);
598    
599    
600     return evtcat;
601 fabstoec 1.15 }
602 mingyang 1.17
603 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) {
604 mingyang 1.17 float ScEta=p->SCluster()->Eta();
605     float Et=p->Et();
606     float R9=p->R9();
607     float HoE=p->HadOverEm();
608     float CovIEtaIEta=p->CoviEtaiEta();
609     float EcalIsoDr03=p->EcalRecHitIsoDr03();
610     float HcalIsoDr03=p->HcalTowerSumEtDr03();
611     float TrkIsoHollowDr03=p->HollowConeTrkIsoDr03();
612     float NewEcalIso=EcalIsoDr03-0.012*Et;
613     float NewHcalIso=HcalIsoDr03-0.005*Et;
614     float NewTrkIsoHollowDr03=TrkIsoHollowDr03-0.002*Et;
615     Bool_t IsBarrel=kFALSE;
616     Bool_t IsEndcap=kFALSE;
617 bendavid 1.22 Bool_t PassEleVetoRaw = PhotonTools::PassElectronVetoConvRecovery(p, els, conversions, bs);
618 bendavid 1.20 Bool_t PassEleVeto = (!applyElectronVeto && !invertElectronVeto) || (applyElectronVeto && !invertElectronVeto && PassEleVetoRaw) || (!applyElectronVeto && invertElectronVeto && !PassEleVetoRaw);
619 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) );
620 mingyang 1.18 float HcalEcalPUCorr=EcalIsoDr03+HcalIsoDr03-0.17*rho;
621    
622 mingyang 1.17 if(fabs(ScEta)<1.4442){IsBarrel=kTRUE;}
623     if(fabs(ScEta)>1.566 && fabs(ScEta)<2.5){IsEndcap=kTRUE;}
624     if((!IsBarrel) && (!IsEndcap)){
625     return kFALSE;
626     }
627     if(!PassEleVeto){
628     return kFALSE;
629     }
630     if(R9<=0.9){
631 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) {
632 mingyang 1.17 return kTRUE;
633     }
634     }
635     if(R9>0.9){
636 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) {
637 mingyang 1.17 return kTRUE;
638     }
639     }
640     return kFALSE;
641     }