ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonIDMod.cc
Revision: 1.35
Committed: Thu Aug 2 12:59:10 2012 UTC (12 years, 9 months ago) by fabstoec
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a
Changes since 1.34: +28 -5 lines
Log Message:
added Rho Choice function

File Contents

# User Rev Content
1 fabstoec 1.30
2 fabstoec 1.35 // $Id: PhotonIDMod.cc,v 1.34 2012/08/02 12:30:55 fabstoec Exp $
3 sixie 1.1
4 bendavid 1.24 #include "TDataMember.h"
5     #include "TTree.h"
6 fabstoec 1.32 #include "TRandom3.h"
7 sixie 1.1 #include "MitPhysics/Mods/interface/PhotonIDMod.h"
8 loizides 1.7 #include "MitAna/DataTree/interface/PhotonCol.h"
9 sixie 1.1 #include "MitPhysics/Init/interface/ModNames.h"
10 fabstoec 1.17 #include "MitPhysics/Utils/interface/IsolationTools.h"
11 bendavid 1.19 #include "MitPhysics/Utils/interface/PhotonTools.h"
12 sixie 1.1
13 fabstoec 1.26 #include <TSystem.h>
14    
15 sixie 1.1 using namespace mithep;
16    
17     ClassImp(mithep::PhotonIDMod)
18 fabstoec 1.32
19 sixie 1.1 //--------------------------------------------------------------------------------------------------
20     PhotonIDMod::PhotonIDMod(const char *name, const char *title) :
21     BaseMod(name,title),
22 fabstoec 1.17 fPhotonBranchName (Names::gkPhotonBrn),
23     fGoodPhotonsName (ModNames::gkGoodPhotonsName),
24     fTrackBranchName (Names::gkTrackBrn),
25     fBeamspotBranchName(Names::gkBeamSpotBrn),
26 fabstoec 1.18 fPileUpDenName (Names::gkPileupEnergyDensityBrn),
27 bendavid 1.19 fConversionName ("MergedConversions"),
28     fElectronName ("Electrons"),
29 bendavid 1.25 fGoodElectronName ("Electrons"),
30 fabstoec 1.22 fPVName (Names::gkPVBeamSpotBrn),
31 bendavid 1.24 // MC specific stuff...
32     fMCParticleName (Names::gkMCPartBrn),
33     fPileUpName (Names::gkPileupInfoBrn),
34 bendavid 1.31 fPFCandsName ("PFCandidates"),
35 fabstoec 1.32
36 fabstoec 1.22 fPhotonIDType ("Custom"),
37     fPhotonIsoType ("Custom"),
38     fPhotonPtMin (15.0),
39     fHadOverEmMax (0.02),
40     fApplySpikeRemoval (kFALSE),
41     fApplyPixelSeed (kTRUE),
42     fApplyElectronVeto (kFALSE),
43 bendavid 1.25 fInvertElectronVeto(kFALSE),
44 bendavid 1.19 fApplyElectronVetoConvRecovery(kFALSE),
45 fabstoec 1.22 fApplyConversionId (kFALSE),
46 bendavid 1.19 fApplyTriggerMatching(kFALSE),
47 fabstoec 1.22 fPhotonR9Min (0.5),
48     fPhIdType (kIdUndef),
49     fPhIsoType (kIsoUndef),
50     fFiduciality (kTRUE),
51     fEtaWidthEB (0.01),
52     fEtaWidthEE (0.028),
53     fAbsEtaMax (999.99),
54     fApplyR9Min (kFALSE),
55 fabstoec 1.32
56 fabstoec 1.22 fEffAreaEcalEE (0.089),
57     fEffAreaHcalEE (0.156),
58     fEffAreaTrackEE (0.261),
59 fabstoec 1.32
60 fabstoec 1.22 fEffAreaEcalEB (0.183),
61     fEffAreaHcalEB (0.062),
62     fEffAreaTrackEB (0.306),
63 fabstoec 1.32
64 fabstoec 1.17 fPhotons(0),
65     fTracks(0),
66     fBeamspots(0),
67 bendavid 1.19 fPileUpDen(0),
68     fConversions(0),
69 fabstoec 1.22 fElectrons(0),
70 bendavid 1.25 fGoodElectrons(0),
71 fabstoec 1.22 fPV(0),
72 bendavid 1.24 fMCParticles (0),
73     fPileUp (0),
74 bendavid 1.31 fPFCands (0),
75 fabstoec 1.32
76 fabstoec 1.26 // MVA ID Stuff
77 bendavid 1.27 fbdtCutBarrel (0.0744), //cuts give the same effiiciency (relative to preselection) with cic
78     fbdtCutEndcap (0.0959), //cuts give the same effiiciency (relative to preselection) with cic
79 fabstoec 1.34
80     // ------------------------------------------------------------------------------
81     // this stuff should go away ..... (fab)
82     fVariableType (10), //please use 4 which is the correct type
83 bendavid 1.29 fEndcapWeights (gSystem->Getenv("CMSSW_BASE")+TString("/src/MitPhysics/data/TMVAClassificationPhotonID_Endcap_PassPreSel_Variable_10_BDTnCuts2000_BDT.weights.xml")),
84     fBarrelWeights (gSystem->Getenv("CMSSW_BASE")+TString("/src/MitPhysics/data/TMVAClassificationPhotonID_Barrel_PassPreSel_Variable_10_BDTnCuts2000_BDT.weights.xml")),
85 fabstoec 1.34 // ------------------------------------------------------------------------------
86    
87     fIdMVATypeName ("2011IdMVA"),
88     fIdMVAType (MVATools::k2011IdMVA),
89    
90 fabstoec 1.32 // fDoMCR9Scaling (kFALSE),
91     // fMCR9ScaleEB (1.0),
92     // fMCR9ScaleEE (1.0),
93     // fDoMCSigIEtaIEtaScaling(kFALSE),
94     // fDoMCWidthScaling (kFALSE),
95    
96     fDoMCErrScaling (kFALSE),
97     fMCErrScaleEB (1.0),
98     fMCErrScaleEE (1.0),
99    
100 fabstoec 1.30 fPhotonsFromBranch(true),
101 bendavid 1.24 fPVFromBranch (true),
102 bendavid 1.25 fGoodElectronsFromBranch (kTRUE),
103 fabstoec 1.32 fIsData(false),
104    
105     // ------------------------------------------------
106     // added by fab: smearing/scaling options...
107     fDoDataEneCorr (false),
108     fDoMCSmear (false),
109    
110     fDoShowerShapeScaling (false),
111     // ------------------------------------------------
112     fDataEnCorr_EBlowEta_hR9central(0.),
113     fDataEnCorr_EBlowEta_hR9gap (0.),
114     fDataEnCorr_EBlowEta_lR9 (0.),
115     fDataEnCorr_EBhighEta_hR9 (0.),
116     fDataEnCorr_EBhighEta_lR9 (0.),
117     fDataEnCorr_EElowEta_hR9 (0.),
118     fDataEnCorr_EElowEta_lR9 (0.),
119     fDataEnCorr_EEhighEta_hR9 (0.),
120     fDataEnCorr_EEhighEta_lR9 (0.),
121     fRunStart (0),
122     fRunEnd (0),
123     fMCSmear_EBlowEta_hR9central (0.),
124     fMCSmear_EBlowEta_hR9gap (0.),
125     fMCSmear_EBlowEta_lR9 (0.),
126     fMCSmear_EBhighEta_hR9 (0.),
127     fMCSmear_EBhighEta_lR9 (0.),
128     fMCSmear_EElowEta_hR9 (0.),
129     fMCSmear_EElowEta_lR9 (0.),
130     fMCSmear_EEhighEta_hR9 (0.),
131     fMCSmear_EEhighEta_lR9 (0.),
132 fabstoec 1.17
133 fabstoec 1.35 fRng (new TRandom3()),
134    
135     fRhoType (RhoUtilities::CMS_RHO_RHOKT6PFJETS)
136    
137 sixie 1.1 {
138     // Constructor.
139     }
140    
141     //--------------------------------------------------------------------------------------------------
142     void PhotonIDMod::Process()
143     {
144     // Process entries of the tree.
145    
146 fabstoec 1.17 LoadEventObject(fPhotonBranchName, fPhotons);
147 bendavid 1.19
148     const BaseVertex *bsp = NULL;
149     Double_t _tRho = -1.;
150 bendavid 1.31 Float_t rho2012 = -99;
151 bendavid 1.19 const TriggerObjectCol *trigObjs = 0;
152     if (fPhotons->GetEntries()>0) {
153     LoadEventObject(fTrackBranchName, fTracks);
154     LoadEventObject(fBeamspotBranchName, fBeamspots);
155 bendavid 1.24 LoadEventObject(fPileUpDenName, fPileUpDen);
156 bendavid 1.19 LoadEventObject(fConversionName, fConversions);
157     LoadEventObject(fElectronName, fElectrons);
158 fabstoec 1.26 LoadEventObject(fGoodElectronName, fGoodElectrons);
159 bendavid 1.24 LoadEventObject(fPVName, fPV);
160 bendavid 1.31 LoadEventObject(fPFCandsName, fPFCands);
161    
162 bendavid 1.19
163     if(fBeamspots->GetEntries() > 0)
164     bsp = fBeamspots->At(0);
165 fabstoec 1.17
166 bendavid 1.24 if(fPileUpDen->GetEntries() > 0)
167 fabstoec 1.23 _tRho = (Double_t) fPileUpDen->At(0)->RhoRandomLowEta();
168 fabstoec 1.26
169 bendavid 1.31 if (fPileUpDen->At(0)->RhoKt6PFJets()>0.) rho2012 = fPileUpDen->At(0)->RhoKt6PFJets();
170     else rho2012 = fPileUpDen->At(0)->Rho();
171 bendavid 1.19
172     //get trigger object collection if trigger matching is enabled
173     if (fApplyTriggerMatching) {
174     trigObjs = GetHLTObjects(fTrigObjectsName);
175     }
176    
177     }
178 fabstoec 1.17
179 fabstoec 1.35 Float_t theRho = _tRho;
180     switch (fRhoType) {
181     case RhoUtilities::CMS_RHO_RHOKT6PFJETS:
182     theRho = rho2012;
183     break;
184     case RhoUtilities::MIT_RHO_VORONOI_LOW_ETA:
185     theRho = ( fPileUpDen->GetEntries() ? fPileUpDen->At(0)->RhoLowEta(): _tRho);
186     break;
187     case RhoUtilities::MIT_RHO_VORONOI_HIGH_ETA:
188     theRho = ( fPileUpDen->GetEntries() ? fPileUpDen->At(0)->Rho() : _tRho);
189     break;
190     case RhoUtilities::MIT_RHO_RANDOM_LOW_ETA:
191     theRho = ( fPileUpDen->GetEntries() ? fPileUpDen->At(0)->RhoRandomLowEta() : _tRho);
192     break;
193     case RhoUtilities::MIT_RHO_RANDOM_HIGH_ETA:
194     theRho = ( fPileUpDen->GetEntries() ? fPileUpDen->At(0)->RhoRandom() : _tRho);
195     break;
196     default:
197     theRho = _tRho;
198     }
199    
200 fabstoec 1.32
201     // ------------------------------------------------------------
202     // Get Event header for Run info etc.
203     const EventHeader* evtHead = this->GetEventHeader();
204     unsigned int evtNum = evtHead->EvtNum();
205     UInt_t runNumber = evtHead->RunNum();
206     Float_t _runNum = (Float_t) runNumber;
207     Float_t _lumiSec = (Float_t) evtHead->LumiSec();
208    
209 sixie 1.1 PhotonOArr *GoodPhotons = new PhotonOArr;
210     GoodPhotons->SetName(fGoodPhotonsName);
211 fabstoec 1.30 GoodPhotons->SetOwner(kTRUE);
212 sixie 1.1
213     for (UInt_t i=0; i<fPhotons->GetEntries(); ++i) {
214 fabstoec 1.30 // need to cpoy the photon in order to be able to scale R9 etc.
215     Photon *ph = new Photon(*fPhotons->At(i));
216 bendavid 1.24
217     if (fFiduciality == kTRUE &&
218     (ph->SCluster()->AbsEta()>=2.5 || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566) ) )
219     continue;
220    
221 fabstoec 1.30 if (fInvertElectronVeto && PhotonTools::PassElectronVeto(ph,fGoodElectrons) && false) {
222 bendavid 1.25 continue;
223     }
224    
225 fabstoec 1.30 // -----------------------------------------------------------------------------------
226     // Do all the scaling ....
227     if (fDoMCErrScaling && !fIsData) {
228     if (ph->SCluster()->AbsEta()<1.5) PhotonTools::ScalePhotonError(ph,fMCErrScaleEB);
229     else PhotonTools::ScalePhotonError(ph,fMCErrScaleEE);
230     }
231 fabstoec 1.34
232 fabstoec 1.32 if (fDoShowerShapeScaling && !fIsData) {
233     PhotonTools::ScalePhotonShowerShapes(ph,fSSType);
234 fabstoec 1.30 }
235    
236 fabstoec 1.32 // fab: replaced by shower-shape scaling above...
237     // if (fDoMCR9Scaling && !fIsData) {
238     // if (ph->SCluster()->AbsEta()<1.5) PhotonTools::ScalePhotonR9(ph,fMCR9ScaleEB);
239     // else PhotonTools::ScalePhotonR9(ph,fMCR9ScaleEE);
240     // }
241    
242     // if (fDoMCSigIEtaIEtaScaling && !fIsData) {
243     // if (ph->SCluster()->AbsEta()<1.5) ph->SetCoviEtaiEta(0.87*ph->CoviEtaiEta() + 0.0011);
244     // else ph->SetCoviEtaiEta(0.99*ph->CoviEtaiEta());
245     // }
246    
247     // if (fDoMCWidthScaling && !fIsData) {
248     // ph->SetEtaWidth(0.99*ph->EtaWidth());
249     // ph->SetPhiWidth(0.99*ph->PhiWidth());
250     // }
251 fabstoec 1.33
252 fabstoec 1.32 PhotonTools::eScaleCats escalecat = PhotonTools::EScaleCat(ph);
253    
254     // now we dicide if we either scale (Data) or Smear (MC) the Photons
255     if (fIsData) {
256     if (fDoDataEneCorr) {
257     // starting with scale = 1.
258     double scaleFac = 1.;
259     // checking the run Rangees ...
260     Int_t runRange = FindRunRangeIdx(runNumber);
261     if(runRange > -1) {
262     scaleFac *= GetDataEnCorr(runRange, escalecat);
263     }
264     PhotonTools::ScalePhoton(ph, scaleFac);
265     }
266 fabstoec 1.30 }
267 fabstoec 1.32
268     if (fDoMCSmear) {
269     double width = GetMCSmearFac(escalecat);
270     if (!fIsData) {
271     // get the seed to do deterministic smearing...
272     UInt_t seedBase = (UInt_t) evtNum + (UInt_t) _runNum + (UInt_t) _lumiSec;
273     UInt_t seed = seedBase + (UInt_t) ph->E() +
274     (UInt_t) (TMath::Abs(10.*ph->SCluster()->Eta()));
275     // get the smearing for MC photons..
276     PhotonTools::SmearPhoton(ph, fRng, width, seed);
277     }
278     PhotonTools::SmearPhotonError(ph, width);
279 fabstoec 1.30 }
280 fabstoec 1.33
281     // ---------------------------------------------------------------------
282 fabstoec 1.34 // set the photonIdMVA value of requested...
283 fabstoec 1.35 double idMvaVal = fTool.GetMVAbdtValue(ph,fPV->At(0),fTracks, fPV, theRho, fPFCands, fElectrons, fApplyElectronVeto);
284 fabstoec 1.34 ph->SetIdMva(idMvaVal);
285    
286     // ---------------------------------------------------------------------
287     // check if we use the Vgamma2011 Selection. If yes, bypass all the below...
288     if( fPhIdType == kTrivialSelection ) {
289     if( ph->Pt() > fPhotonPtMin && ph->SCluster()->AbsEta() <= fAbsEtaMax )
290     GoodPhotons->AddOwned(ph);
291     continue; // go to next Photons
292     }
293    
294     // ---------------------------------------------------------------------
295 fabstoec 1.33 // check if we use the Vgamma2011 Selection. If yes, bypass all the below...
296     if( fPhIdType == kVgamma2011Selection ) {
297 fabstoec 1.34 if( ph->Pt() > fPhotonPtMin && ph->SCluster()->AbsEta() <= fAbsEtaMax && PhotonTools::PassVgamma2011Selection(ph, _tRho) )
298 fabstoec 1.33 GoodPhotons->AddOwned(ph);
299     continue; // go to next Photons
300     }
301 fabstoec 1.30
302 fabstoec 1.22 // ---------------------------------------------------------------------
303     // check if we use the CiC Selection. If yes, bypass all the below...
304     if(fPhIdType == kBaseLineCiC) {
305     if( PhotonTools::PassCiCSelection(ph, fPV->At(0), fTracks, fElectrons, fPV, _tRho, fPhotonPtMin, fApplyElectronVeto) )
306 fabstoec 1.30 GoodPhotons->AddOwned(ph);
307 fabstoec 1.22 continue; // go to next Photons
308     }
309 bendavid 1.31
310     if(fPhIdType == kBaseLineCiCPF) {
311     if( PhotonTools::PassSinglePhotonPreselPFISO(ph,fElectrons,fConversions,bsp,fTracks,fPV->At(0),rho2012,fPFCands,fApplyElectronVeto,fInvertElectronVeto) && PhotonTools::PassCiCPFIsoSelection(ph, fPV->At(0), fPFCands, fPV, rho2012, fPhotonPtMin) )
312     GoodPhotons->AddOwned(ph);
313     continue; // go to next Photons
314     }
315 fabstoec 1.22 // ---------------------------------------------------------------------
316    
317 bendavid 1.27 //loose photon preselection for subsequent mva
318     if(fPhIdType == kMITPhSelection ) {
319 fabstoec 1.30 if( ph->Pt()>fPhotonPtMin && PhotonTools::PassSinglePhotonPresel(ph,fElectrons,fConversions,bsp,fTracks,fPV->At(0),_tRho,fApplyElectronVeto,fInvertElectronVeto) ) {
320     GoodPhotons->AddOwned(ph);
321 bendavid 1.27 }
322     continue;
323     }
324    
325 bendavid 1.31 //loose photon preselection for subsequent mva
326     if(fPhIdType == kMITPFPhSelection ) {
327     if( ph->Pt()>fPhotonPtMin && PhotonTools::PassSinglePhotonPreselPFISO(ph,fElectrons,fConversions,bsp,fTracks,fPV->At(0),rho2012,fPFCands,fApplyElectronVeto,fInvertElectronVeto) ) {
328     GoodPhotons->AddOwned(ph);
329     }
330     continue;
331     }
332 fabstoec 1.34
333     //loose photon preselection for subsequent mva
334     if(fPhIdType == kMITPFPhSelection_NoTrigger ) {
335     if( ph->Pt()>fPhotonPtMin && PhotonTools::PassSinglePhotonPreselPFISO_NoTrigger(ph,fElectrons,fConversions,bsp,fTracks,fPV->At(0),rho2012,fPFCands,fApplyElectronVeto,fInvertElectronVeto) ) {
336     GoodPhotons->AddOwned(ph);
337     }
338     continue;
339     }
340    
341    
342     Bool_t isbarrel = ph->SCluster()->AbsEta()<1.5;
343 bendavid 1.31
344 fabstoec 1.26 // add MingMings MVA ID on single Photon level
345     if(fPhIdType == kMITMVAId ) {
346 fabstoec 1.34 // we compute the bdt val already before, so use it ...
347 fabstoec 1.35 //if( ph->Pt()>fPhotonPtMin && PhotonTools::PassSinglePhotonPresel(ph,fElectrons,fConversions,bsp,fTracks,fPV->At(0),_tRho,fApplyElectronVeto) && fTool.PassMVASelection(ph, fPV->At(0) ,fTracks, fPV, _t_TRho,fbdtCutBarrel,fbdtCutEndcap, fElectrons, fApplyElectronVeto) ) {
348 fabstoec 1.34
349     if( ph->Pt()>fPhotonPtMin && PhotonTools::PassSinglePhotonPresel(ph,fElectrons,fConversions,bsp,fTracks,fPV->At(0),_tRho,fApplyElectronVeto) && ( ( isbarrel && ph->IdMva() > fbdtCutBarrel ) || ( ph->IdMva() > fbdtCutEndcap ) ) )
350 fabstoec 1.30 GoodPhotons->AddOwned(ph);
351 fabstoec 1.34
352 fabstoec 1.26 continue;
353     } // go to next Photon
354 fabstoec 1.34
355 sixie 1.1 if (ph->Pt() <= fPhotonPtMin)
356 fabstoec 1.22 continue; // add good electron
357 sixie 1.1
358 sixie 1.13 Bool_t passSpikeRemovalFilter = kTRUE;
359 fabstoec 1.32
360 sixie 1.15 if (ph->SCluster() && ph->SCluster()->Seed()) {
361     if(ph->SCluster()->Seed()->Energy() > 5.0 &&
362     ph->SCluster()->Seed()->EMax() / ph->SCluster()->Seed()->E3x3() > 0.95
363 fabstoec 1.32 ) {
364 sixie 1.15 passSpikeRemovalFilter = kFALSE;
365     }
366 sixie 1.13 }
367 fabstoec 1.32
368 sixie 1.13 // For Now Only use the EMax/E3x3 prescription.
369     //if(ph->SCluster()->Seed()->Energy() > 5.0 &&
370     // (1 - (ph->SCluster()->Seed()->E1x3() + ph->SCluster()->Seed()->E3x1() - 2*ph->SCluster()->Seed()->EMax())) > 0.95
371     // ) {
372     // passSpikeRemovalFilter = kFALSE;
373     //}
374 fabstoec 1.32
375 sixie 1.13 if (fApplySpikeRemoval && !passSpikeRemovalFilter) continue;
376    
377 ceballos 1.2 if (ph->HadOverEm() >= fHadOverEmMax)
378     continue;
379 ceballos 1.14
380 ceballos 1.2 if (fApplyPixelSeed == kTRUE &&
381     ph->HasPixelSeed() == kTRUE)
382     continue;
383 ceballos 1.14
384 bendavid 1.19 if (fApplyElectronVeto && !PhotonTools::PassElectronVeto(ph,fElectrons) ) continue;
385    
386     if (fApplyElectronVetoConvRecovery && !PhotonTools::PassElectronVetoConvRecovery(ph,fElectrons,fConversions,bsp) ) continue;
387    
388     if (fApplyConversionId && !PhotonTools::PassConversionId(ph,PhotonTools::MatchedConversion(ph,fConversions,bsp))) continue;
389    
390     if (fApplyTriggerMatching && !PhotonTools::PassTriggerMatching(ph,trigObjs)) continue;
391    
392 sixie 1.1 Bool_t idcut = kFALSE;
393     switch (fPhIdType) {
394     case kTight:
395     idcut = ph->IsTightPhoton();
396     break;
397     case kLoose:
398     idcut = ph->IsLoosePhoton();
399     break;
400     case kLooseEM:
401     idcut = ph->IsLooseEM();
402     break;
403     case kCustomId:
404 ceballos 1.5 idcut = kTRUE;
405 sixie 1.1 default:
406     break;
407     }
408    
409     if (!idcut)
410     continue;
411    
412     Bool_t isocut = kFALSE;
413     switch (fPhIsoType) {
414     case kNoIso:
415     isocut = kTRUE;
416     break;
417 ceballos 1.2 case kCombinedIso:
418 bendavid 1.12 {
419     Double_t totalIso = ph->HollowConeTrkIsoDr04()+
420     ph->EcalRecHitIsoDr04() +
421     ph->HcalTowerSumEtDr04();
422     if (totalIso/ph->Pt() < 0.25)
423     isocut = kTRUE;
424     }
425 ceballos 1.2 break;
426 sixie 1.1 case kCustomIso:
427 bendavid 1.16 {
428     if ( ph->HollowConeTrkIsoDr04() < (1.5 + 0.001*ph->Pt()) && ph->EcalRecHitIsoDr04()<(2.0+0.006*ph->Pt()) && ph->HcalTowerSumEtDr04()<(2.0+0.0025*ph->Pt()) )
429     isocut = kTRUE;
430     }
431 fabstoec 1.17 break;
432    
433     case kMITPUCorrected:
434     {
435     // compute the PU corrections only if Rho is available
436 fabstoec 1.32 // ... otherwise (_tRho = 0.0) it's the std isolation
437 fabstoec 1.17 isocut = kTRUE;
438 fabstoec 1.20 Double_t fEffAreaEcal = fEffAreaEcalEB;
439     Double_t fEffAreaHcal = fEffAreaHcalEB;
440     Double_t fEffAreaTrack = fEffAreaTrackEB;
441    
442 bendavid 1.21 if( !isbarrel ) {
443 fabstoec 1.20 fEffAreaEcal = fEffAreaEcalEE;
444     fEffAreaHcal = fEffAreaHcalEE;
445     fEffAreaTrack = fEffAreaTrackEE;
446     }
447 fabstoec 1.26
448 fabstoec 1.17 Double_t EcalCorrISO = ph->EcalRecHitIsoDr04();
449     if(_tRho > -0.5 ) EcalCorrISO -= _tRho * fEffAreaEcal;
450     if ( EcalCorrISO > (2.0+0.006*ph->Pt()) ) isocut = kFALSE;
451 fabstoec 1.26 if ( isocut || true ) {
452 fabstoec 1.17 Double_t HcalCorrISO = ph->HcalTowerSumEtDr04();
453     if(_tRho > -0.5 ) HcalCorrISO -= _tRho * fEffAreaHcal;
454     if ( HcalCorrISO > (2.0+0.0025*ph->Pt()) ) isocut = kFALSE;
455     }
456 fabstoec 1.26 if ( isocut || true ) {
457 fabstoec 1.17 Double_t TrackCorrISO = IsolationTools::TrackIsolationNoPV(ph, bsp, 0.4, 0.04, 0.0, 0.015, 0.1, TrackQuality::highPurity, fTracks);
458     if(_tRho > -0.5 )
459     TrackCorrISO -= _tRho * fEffAreaTrack;
460     if ( TrackCorrISO > (1.5 + 0.001*ph->Pt()) ) isocut = kFALSE;
461     }
462     break;
463     }
464     default:
465     break;
466 sixie 1.1 }
467 fabstoec 1.17
468 sixie 1.1 if (!isocut)
469     continue;
470 fabstoec 1.17
471 bendavid 1.16 if ( fApplyR9Min && ph->R9() <= fPhotonR9Min)
472 ceballos 1.5 continue;
473    
474 bendavid 1.21 if ((isbarrel && ph->CoviEtaiEta() >= fEtaWidthEB) ||
475     (!isbarrel && ph->CoviEtaiEta() >= fEtaWidthEE))
476 ceballos 1.10 continue;
477    
478 ceballos 1.11 if (ph->AbsEta() >= fAbsEtaMax)
479     continue;
480 bendavid 1.25
481 sixie 1.1 // add good electron
482 fabstoec 1.30 GoodPhotons->AddOwned(ph);
483 sixie 1.1 }
484    
485 loizides 1.4 // sort according to pt
486     GoodPhotons->Sort();
487    
488 sixie 1.1 // add to event for other modules to use
489     AddObjThisEvt(GoodPhotons);
490 bendavid 1.24
491 bendavid 1.25 return;
492 bendavid 1.24
493 sixie 1.1 }
494    
495     //--------------------------------------------------------------------------------------------------
496     void PhotonIDMod::SlaveBegin()
497     {
498     // Run startup code on the computer (slave) doing the actual analysis. Here,
499 loizides 1.3 // we just request the photon collection branch.
500 sixie 1.1
501 fabstoec 1.30 ReqEventObject(fPhotonBranchName, fPhotons, fPhotonsFromBranch);
502 fabstoec 1.22 ReqEventObject(fTrackBranchName, fTracks, kTRUE);
503     ReqEventObject(fBeamspotBranchName, fBeamspots, kTRUE);
504 bendavid 1.19 ReqEventObject(fConversionName, fConversions, kTRUE);
505 fabstoec 1.22 ReqEventObject(fElectronName, fElectrons, kTRUE);
506 bendavid 1.25 ReqEventObject(fGoodElectronName, fGoodElectrons, fGoodElectronsFromBranch);
507 bendavid 1.24 ReqEventObject(fPVName, fPV, fPVFromBranch);
508     ReqEventObject(fPileUpDenName, fPileUpDen, kTRUE);
509 bendavid 1.31 ReqEventObject(fPFCandsName, fPFCands, kTRUE);
510 fabstoec 1.30
511 bendavid 1.24 if (!fIsData) {
512     ReqBranch(fPileUpName, fPileUp);
513     ReqBranch(fMCParticleName, fMCParticles);
514     }
515    
516 sixie 1.1 if (fPhotonIDType.CompareTo("Tight") == 0)
517     fPhIdType = kTight;
518     else if (fPhotonIDType.CompareTo("Loose") == 0)
519     fPhIdType = kLoose;
520     else if (fPhotonIDType.CompareTo("LooseEM") == 0)
521     fPhIdType = kLooseEM;
522 fabstoec 1.22 else if (fPhotonIDType.CompareTo("Custom") == 0)
523 sixie 1.1 fPhIdType = kCustomId;
524 fabstoec 1.22 else if (fPhotonIDType.CompareTo("BaseLineCiC") == 0) {
525     fPhIdType = kBaseLineCiC;
526     fPhotonIsoType = "NoIso";
527 fabstoec 1.26 }
528 bendavid 1.31 else if (fPhotonIDType.CompareTo("BaseLineCiCPF") == 0) {
529     fPhIdType = kBaseLineCiCPF;
530     fPhotonIsoType = "NoIso";
531     }
532 fabstoec 1.26 else if (fPhotonIDType.CompareTo("MITMVAId") == 0) {
533     fPhIdType = kMITMVAId;
534     fPhotonIsoType = "NoIso";
535 fabstoec 1.34 // this is now a 'generic' MVAId: set the MVAType using 'SetIdMVAType(const char*)' (fab)
536     //fTool.InitializeMVA(fVariableType,fEndcapWeights,fBarrelWeights); // moved down for after we know which MVA type to load...
537 bendavid 1.27 }
538     else if (fPhotonIDType.CompareTo("MITSelection") == 0) {
539     fPhIdType = kMITPhSelection;
540     fPhotonIsoType = "NoIso";
541     }
542 bendavid 1.31 else if (fPhotonIDType.CompareTo("MITPFSelection") == 0) {
543     fPhIdType = kMITPFPhSelection;
544     fPhotonIsoType = "NoIso";
545     }
546 fabstoec 1.34 else if (fPhotonIDType.CompareTo("MITPFSelection_NoTrigger") == 0) {
547     fPhIdType = kMITPFPhSelection_NoTrigger;
548     fPhotonIsoType = "NoIso";
549     }
550 fabstoec 1.33 else if (fPhotonIDType.CompareTo("Vgamma2011Selection") == 0) {
551     fPhIdType = kVgamma2011Selection;
552     fPhotonIsoType = "NoIso";
553     }
554 fabstoec 1.34 else if (fPhotonIDType.CompareTo("TrivialSelection") == 0) {
555     fPhIdType = kTrivialSelection;
556     fPhotonIsoType = "NoIso";
557     }
558 bendavid 1.27 else {
559 sixie 1.1 SendError(kAbortAnalysis, "SlaveBegin",
560 ceballos 1.2 "The specified photon identification %s is not defined.",
561 sixie 1.1 fPhotonIDType.Data());
562     return;
563     }
564    
565     if (fPhotonIsoType.CompareTo("NoIso") == 0 )
566     fPhIsoType = kNoIso;
567 ceballos 1.2 else if (fPhotonIsoType.CompareTo("CombinedIso") == 0 )
568     fPhIsoType = kCombinedIso;
569 fabstoec 1.17 else if (fPhotonIsoType.CompareTo("Custom") == 0 )
570 sixie 1.1 fPhIsoType = kCustomIso;
571 fabstoec 1.17 else if (fPhotonIsoType.CompareTo("MITPUCorrected") == 0 )
572     fPhIsoType = kMITPUCorrected;
573     else {
574 sixie 1.1 SendError(kAbortAnalysis, "SlaveBegin",
575 ceballos 1.2 "The specified photon isolation %s is not defined.",
576 sixie 1.1 fPhotonIsoType.Data());
577     return;
578     }
579 fabstoec 1.34
580 fabstoec 1.32 if (fShowerShapeType.CompareTo("None") == 0)
581     fSSType = PhotonTools::kNoShowerShapeScaling;
582     else if (fShowerShapeType.CompareTo("2011ShowerShape") == 0)
583     fSSType = PhotonTools::k2011ShowerShape;
584     else if (fShowerShapeType.CompareTo("2012ShowerShape") == 0)
585     fSSType = PhotonTools::k2012ShowerShape;
586     else {
587     std::cerr<<"shower shape scale "<<fShowerShapeType<<" not implemented."<<std::endl;
588     return;
589     }
590 bendavid 1.24
591 fabstoec 1.34 if (fIdMVATypeName.CompareTo("2011IdMVA") == 0)
592     fIdMVAType = MVATools::k2011IdMVA;
593     else if (fIdMVATypeName.CompareTo("2012IdMVA_globe") == 0)
594     fIdMVAType = MVATools::k2012IdMVA_globe;
595     else if (fIdMVATypeName.CompareTo("2012IdMVA") == 0)
596     fIdMVAType = MVATools::k2012IdMVA;
597     else if (fIdMVATypeName.CompareTo("2011IdMVA_HZg") == 0)
598     fIdMVAType = MVATools::k2011IdMVA_HZg;
599     else if (fIdMVATypeName.CompareTo("None") == 0)
600     fIdMVAType = MVATools::kNone;
601     else {
602     std::cerr<<" Id MVA "<<fIdMVATypeName<<" not implemented."<<std::endl;
603     return;
604     }
605    
606     // ------------------------------------------------------------------------------------
607     // we fill ALWAYS the bdt varible with some value... so initialize the BDT if not set to 'None' (will be handeled by MVATools) (fab)
608     fTool.InitializeMVA(fIdMVAType);
609     // ------------------------------------------------------------------------------------
610    
611 sixie 1.1 }
612 fabstoec 1.32
613    
614     //---------------------------------------------------------------------------------------------------
615     Int_t PhotonIDMod::FindRunRangeIdx(UInt_t run)
616     {
617     // this routine looks for the idx of the run-range
618     Int_t runRange=-1;
619     for (UInt_t iRun = 0; iRun<fRunStart.size(); ++iRun) {
620     if (run >= fRunStart[iRun] && run <= fRunEnd[iRun]) {
621     runRange = (Int_t) iRun;
622     return runRange;
623     }
624     }
625     return runRange;
626     }
627    
628     //---------------------------------------------------------------------------------------------------
629     Double_t PhotonIDMod::GetDataEnCorr(Int_t runRange, PhotonTools::eScaleCats cat)
630     {
631     switch (cat) {
632     case PhotonTools::kEBhighEtaGold:
633     return fDataEnCorr_EBhighEta_hR9[runRange];
634     case PhotonTools::kEBhighEtaBad:
635     return fDataEnCorr_EBhighEta_lR9[runRange];
636     case PhotonTools::kEBlowEtaGoldCenter:
637     return fDataEnCorr_EBlowEta_hR9central[runRange];
638     case PhotonTools::kEBlowEtaGoldGap:
639     return fDataEnCorr_EBlowEta_hR9gap[runRange];
640     case PhotonTools::kEBlowEtaBad:
641     return fDataEnCorr_EBlowEta_lR9[runRange];
642     case PhotonTools::kEEhighEtaGold:
643     return fDataEnCorr_EEhighEta_hR9[runRange];
644     case PhotonTools::kEEhighEtaBad:
645     return fDataEnCorr_EEhighEta_lR9[runRange];
646     case PhotonTools::kEElowEtaGold:
647     return fDataEnCorr_EElowEta_hR9[runRange];
648     case PhotonTools::kEElowEtaBad:
649     return fDataEnCorr_EElowEta_lR9[runRange];
650     default:
651     return 1.;
652     }
653     }
654    
655     //---------------------------------------------------------------------------------------------------
656     Double_t PhotonIDMod::GetMCSmearFac(PhotonTools::eScaleCats cat)
657     {
658     switch (cat) {
659     case PhotonTools::kEBhighEtaGold:
660     return fMCSmear_EBhighEta_hR9;
661     case PhotonTools::kEBhighEtaBad:
662     return fMCSmear_EBhighEta_lR9;
663     case PhotonTools::kEBlowEtaGoldCenter:
664     return fMCSmear_EBlowEta_hR9central;
665     case PhotonTools::kEBlowEtaGoldGap:
666     return fMCSmear_EBlowEta_hR9gap;
667     case PhotonTools::kEBlowEtaBad:
668     return fMCSmear_EBlowEta_lR9;
669     case PhotonTools::kEEhighEtaGold:
670     return fMCSmear_EEhighEta_hR9;
671     case PhotonTools::kEEhighEtaBad:
672     return fMCSmear_EEhighEta_lR9;
673     case PhotonTools::kEElowEtaGold:
674     return fMCSmear_EElowEta_hR9;
675     case PhotonTools::kEElowEtaBad:
676     return fMCSmear_EElowEta_lR9;
677     default:
678     return 1.;
679     }
680     }