ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/PhotonTools.cc
Revision: 1.14
Committed: Fri Oct 7 09:56:37 2011 UTC (13 years, 7 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025
Changes since 1.13: +5 -1 lines
Log Message:
misc updates

File Contents

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