ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/PhotonTools.cc
Revision: 1.19
Committed: Sun Dec 11 00:03:05 2011 UTC (13 years, 4 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.18: +11 -5 lines
Log Message:
more photon updates for mva plus id analysis

File Contents

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