ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/PhotonTools.cc
Revision: 1.23
Committed: Sat Dec 17 22:29:31 2011 UTC (13 years, 4 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.22: +1 -0 lines
Log Message:
further small gamma gamma updates

File Contents

# User Rev Content
1 bendavid 1.21 // $Id: PhotonTools.cc,v 1.20 2011/12/13 21:13:23 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     //ThreeVector dirconvsc = ThreeVector(p->SCluster()->Point()) - c->Position();
362     //ThreeVector dirconvsc = p->CaloPos() - c->Position();
363    
364     double convPhi = c->Phi();
365     double convEta = c->Eta();
366 fabstoec 1.7
367 fabstoec 1.6 const ThreeVector wrong(0,0,0);
368     double Zvertex = c->DzCorrected(wrong);
369     // ------------------ FROM GLOBE ----------------------
370     //---Definitions for ECAL
371     const float R_ECAL = 136.5;
372     const float Z_Endcap = 328.0;
373     const float etaBarrelEndcap = 1.479;
374 fabstoec 1.7
375 fabstoec 1.6 //---ETA correction
376     float Theta = 0.0 ;
377     float ZEcal = R_ECAL*sinh(convEta)+Zvertex;
378 fabstoec 1.7
379 fabstoec 1.6 if(ZEcal != 0.0) Theta = TMath::ATan(R_ECAL/ZEcal);
380     if(Theta<0.0) Theta = Theta+M_PI;
381     double fEta = - TMath::Log(TMath::Tan(0.5*Theta));
382 fabstoec 1.5
383 fabstoec 1.6 if( fabs(fEta) > etaBarrelEndcap ) {
384     float Zend = Z_Endcap ;
385     if(convEta<0.0 ) Zend = -Zend ;
386     float Zlen = Zend - Zvertex ;
387     float RR = Zlen/TMath::SinH(convEta);
388     Theta = TMath::ATan(RR/Zend);
389     if(Theta<0.0) Theta = Theta+M_PI;
390     fEta = -TMath::Log(TMath::Tan(0.5*Theta));
391     }
392     // ---------------------------------------------------
393    
394 fabstoec 1.7 if(print) {
395     std::cout<<" eta bare = "<<convEta<<std::endl;
396     std::cout<<" eta new = "<<fEta<<std::endl;
397     std::cout<<" phi = "<<convPhi<<std::endl;
398     }
399    
400     convEta = fEta;
401    
402 fabstoec 1.6 Double_t dphi = TMath::Abs(phPhi - convPhi);
403     if(dphi > M_PI) dphi = 2.*M_PI-dphi;
404     //Double_t deta = c->Eta()-dirconvsc.Eta();
405     Double_t deta = TMath::Abs(convEta-phEta);
406 fabstoec 1.7 Double_t dR = TMath::Sqrt(dphi*dphi+deta*deta);
407     //if(dphi < minDphi && TMath::Abs(deta)<minDeta) {
408     if(dR < minDR) {
409     minDR = dR;
410     minDphi = dphi;
411     minDeta = TMath::Abs(deta);
412     match = c;
413    
414     if(print)
415     std::cout<<" conv "<<i+1<<" matches with dPhi = "<<minDphi<<" dEta = "<<minDeta<<std::endl;
416    
417 fabstoec 1.6 }
418 fabstoec 1.5 }
419    
420 fabstoec 1.7 //if(minDphi < dPhiMin && minDeta < dEtaMin)
421     if(minDR < dRMin)
422     return match;
423     else
424     return NULL;
425 fabstoec 1.5 }
426    
427 fabstoec 1.9 bool PhotonTools::PassCiCSelection(const Photon* ph, const Vertex* vtx,
428     const TrackCol* trackCol,
429     const ElectronCol* eleCol,
430     const VertexCol* vtxCol,
431 fabstoec 1.5 double rho, double ptmin,
432 fabstoec 1.9 bool applyEleVeto,
433 fabstoec 1.5 bool print, float* kin) {
434 fabstoec 1.9
435 fabstoec 1.5
436     // these values are taken from the H2GGlobe code... (actually from Marco/s mail)
437     float cic4_allcuts_temp_sublead[] = {
438     3.8, 2.2, 1.77, 1.29,
439     11.7, 3.4, 3.9, 1.84,
440     3.5, 2.2, 2.3, 1.45,
441     0.0106, 0.0097, 0.028, 0.027,
442     0.082, 0.062, 0.065, 0.048,
443     0.94, 0.36, 0.94, 0.32,
444     1., 0.062, 0.97, 0.97,
445     1.5, 1.5, 1.5, 1.5 }; // the last line is PixelmatchVeto and un-used
446    
447     // cut on Et instead of Pt???
448     Bool_t isbarrel = ph->SCluster()->AbsEta()<1.5;
449    
450     // compute all relevant observables first
451     double ecalIso3 = ph->EcalRecHitIsoDr03();
452     double ecalIso4 = ph->EcalRecHitIsoDr04();
453     double hcalIso4 = ph->HcalTowerSumEtDr04();
454    
455     unsigned int wVtxInd = 0;
456    
457     double trackIso1 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol);
458    
459     // track iso only
460     double trackIso3 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol);
461    
462     // track iso worst vtx
463     double trackIso2 = IsolationTools::CiCTrackIsolation(ph, vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, &wVtxInd, vtxCol);
464    
465     double combIso1 = ecalIso3+hcalIso4+trackIso1 - 0.17*rho;
466     double combIso2 = ecalIso4+hcalIso4+trackIso2 - 0.52*rho;
467    
468     double tIso1 = (combIso1) *50./ph->Et();
469     double tIso2 = (combIso2) *50./(ph->MomVtx(vtxCol->At(wVtxInd)->Position()).Pt());
470     //double tIso2 = (combIso2) *50./ph->Et();
471     double tIso3 = (trackIso3)*50./ph->Et();
472    
473     double covIEtaIEta =ph->CoviEtaiEta();
474     double HoE = ph->HadOverEm();
475    
476     double R9 = ph->R9();
477    
478     double dRTrack = PhotonTools::ElectronVetoCiC(ph, eleCol);
479    
480     // check which category it is ...
481     int _tCat = 1;
482     if ( !isbarrel ) _tCat = 3;
483     if ( R9 < 0.94 ) _tCat++;
484    
485     if(print) {
486     std::cout<<" -------------------------- "<<std::endl;
487 fabstoec 1.15
488     std::cout<<" trackIso1 = "<<trackIso1<<std::endl;
489     std::cout<<" trackIso2 = "<<trackIso2<<std::endl;
490     std::cout<<" trackIso3 = "<<trackIso3<<std::endl;
491     std::cout<<" ecalIso3 = "<<ecalIso3<<std::endl;
492     std::cout<<" ecalIso4 = "<<ecalIso4<<std::endl;
493     std::cout<<" hcalIso4 = "<<hcalIso4<<std::endl;
494    
495 fabstoec 1.5 std::cout<<" photon Et = "<<ph->Et()<<std::endl;
496 mingyang 1.17 std::cout<<" Eta = "<<ph->SCluster()->Eta()<<std::endl;
497 fabstoec 1.15 std::cout<<" HoE = "<<HoE<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+4*4]<<")"<<std::endl;
498     std::cout<<" R9 = "<<R9<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+5*4]<<")"<<std::endl;
499     std::cout<<" dR = "<<dRTrack<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+6*4]<<")"<<std::endl;
500     std::cout<<" iso1 = "<<tIso1<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+0*4]<<")"<<std::endl;
501     std::cout<<" iso2 = "<<tIso2<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+1*4]<<")"<<std::endl;
502     std::cout<<" iso3 = "<<tIso3<<" ("<<cic4_allcuts_temp_sublead[_tCat-1+2*4]<<")"<<std::endl;
503 fabstoec 1.5 }
504    
505     if(kin) {
506     kin[0] = tIso1;
507     kin[1] = tIso2;
508     kin[2] = tIso3;
509     kin[3] = covIEtaIEta;
510     kin[4] = HoE;
511     kin[5] = R9;
512     kin[6] = dRTrack;
513     kin[7] = (float) ph->Pt();
514     kin[8] = (float) ph->Eta();
515     kin[9] = (float) ph->Phi();
516    
517     // iso quantities separate
518     kin[10] = ecalIso3;
519     kin[11] = ecalIso4;
520     kin[12] = hcalIso4;
521     kin[13] = trackIso1;
522     kin[14] = trackIso2;
523     kin[15] = trackIso3;
524    
525     kin[16] = (float) ph->Et();
526     kin[17] = (float) ph->E();
527    
528 bendavid 1.11 kin[18] = (float) ph->SCluster()->Eta();
529     kin[19] = (float) ph->SCluster()->Phi();
530 fabstoec 1.5 }
531    
532     float passCuts = 1.;
533    
534     if ( ph->Pt() <= ptmin ) passCuts = -1.;
535    
536     // not needed anymore, do in pre-selection...
537     //if ( ph->SCluster()->AbsEta()>=2.5 || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) passCuts = -1.;
538    
539     if( ! ( tIso1 < cic4_allcuts_temp_sublead[_tCat-1+0*4]
540     && tIso2 < cic4_allcuts_temp_sublead[_tCat-1+1*4]
541     && tIso3 < cic4_allcuts_temp_sublead[_tCat-1+2*4]
542     && covIEtaIEta < cic4_allcuts_temp_sublead[_tCat-1+3*4]
543     && HoE < cic4_allcuts_temp_sublead[_tCat-1+4*4]
544     && R9 > cic4_allcuts_temp_sublead[_tCat-1+5*4]
545 fabstoec 1.9 && ( dRTrack > cic4_allcuts_temp_sublead[_tCat-1+6*4] || !applyEleVeto ) ) ) passCuts = -1.;
546 fabstoec 1.5
547 fabstoec 1.15 if(print) std::cout<<" ---> "<<passCuts<<std::endl;
548    
549 fabstoec 1.5 if(kin) {
550 bendavid 1.11 kin[20] = passCuts;
551     kin[21] = (float) _tCat;
552 fabstoec 1.5 }
553    
554     if(passCuts > 0.) return true;
555     return false;
556     }
557 bendavid 1.11
558 bendavid 1.13 const MCParticle *PhotonTools::MatchMC(const Particle *ph, const MCParticleCol *c, Bool_t matchElectrons) {
559    
560     // printf("Start loop\n");
561 bendavid 1.11 for (UInt_t i=0; i<c->GetEntries(); ++i) {
562     const MCParticle *p = c->At(i);
563 bendavid 1.13 // if (p->IsGenerated() && p->AbsPdgId()==11 && (p->DistinctMother()->AbsPdgId()==23|| p->DistinctMother()->AbsPdgId()==24)) {
564     // printf("pdgid = %i, status = %i, pt = %5f, mother pdgid = %i\n",p->PdgId(),p->Status(),p->Pt(),p->Mother()->PdgId());
565 bendavid 1.12 // }
566     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)) {
567     return p;
568     }
569 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) ) {
570     return p;
571     }
572     }
573     return 0;
574 bendavid 1.12 }
575    
576     PhotonTools::DiphotonR9EtaPtCats PhotonTools::DiphotonR9EtaPtCat(const Photon *p1, const Photon *p2) {
577    
578     PhotonTools::CiCBaseLineCats cat1 = CiCBaseLineCat(p1);
579     PhotonTools::CiCBaseLineCats cat2 = CiCBaseLineCat(p2);
580    
581     PhotonTools::DiphotonR9EtaPtCats evtcat = PhotonTools::kOctCat0;
582    
583     bool ph1IsEB = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat2);
584     bool ph2IsEB = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat2);
585    
586     bool ph1IsHR9 = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat3);
587     bool ph2IsHR9 = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat3);
588    
589     if( ph1IsEB && ph2IsEB )
590     evtcat = ( ph1IsHR9 && ph2IsHR9 ? PhotonTools::kOctCat0 : PhotonTools::kOctCat1);
591     else
592     evtcat = ( ph1IsHR9 && ph2IsHR9 ? PhotonTools::kOctCat2 : PhotonTools::kOctCat3);
593    
594     float ptgg = (p1->Mom()+p2->Mom()).Pt();
595     if (ptgg<40.0) evtcat = PhotonTools::DiphotonR9EtaPtCats(evtcat + 4);
596    
597    
598     return evtcat;
599 fabstoec 1.15 }
600 mingyang 1.17
601 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) {
602 mingyang 1.17 float ScEta=p->SCluster()->Eta();
603     float Et=p->Et();
604     float R9=p->R9();
605     float HoE=p->HadOverEm();
606     float CovIEtaIEta=p->CoviEtaiEta();
607     float EcalIsoDr03=p->EcalRecHitIsoDr03();
608     float HcalIsoDr03=p->HcalTowerSumEtDr03();
609     float TrkIsoHollowDr03=p->HollowConeTrkIsoDr03();
610     float NewEcalIso=EcalIsoDr03-0.012*Et;
611     float NewHcalIso=HcalIsoDr03-0.005*Et;
612     float NewTrkIsoHollowDr03=TrkIsoHollowDr03-0.002*Et;
613     Bool_t IsBarrel=kFALSE;
614     Bool_t IsEndcap=kFALSE;
615 bendavid 1.22 Bool_t PassEleVetoRaw = PhotonTools::PassElectronVetoConvRecovery(p, els, conversions, bs);
616 bendavid 1.20 Bool_t PassEleVeto = (!applyElectronVeto && !invertElectronVeto) || (applyElectronVeto && !invertElectronVeto && PassEleVetoRaw) || (!applyElectronVeto && invertElectronVeto && !PassEleVetoRaw);
617 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) );
618 mingyang 1.18 float HcalEcalPUCorr=EcalIsoDr03+HcalIsoDr03-0.17*rho;
619    
620 mingyang 1.17 if(fabs(ScEta)<1.4442){IsBarrel=kTRUE;}
621     if(fabs(ScEta)>1.566 && fabs(ScEta)<2.5){IsEndcap=kTRUE;}
622     if((!IsBarrel) && (!IsEndcap)){
623     return kFALSE;
624     }
625     if(!PassEleVeto){
626     return kFALSE;
627     }
628     if(R9<=0.9){
629 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) {
630 mingyang 1.17 return kTRUE;
631     }
632     }
633     if(R9>0.9){
634 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) {
635 mingyang 1.17 return kTRUE;
636     }
637     }
638     return kFALSE;
639     }