ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/PhotonTools.cc
Revision: 1.18
Committed: Tue Dec 6 23:27:31 2011 UTC (13 years, 5 months ago) by mingyang
Content type: text/plain
Branch: MAIN
Changes since 1.17: +8 -4 lines
Log Message:
presel cuts changed

File Contents

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