ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonIDMod.cc
Revision: 1.26
Committed: Tue Oct 18 11:27:19 2011 UTC (13 years, 6 months ago) by fabstoec
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025c, Mit_025b, Mit_025a
Changes since 1.25: +38 -5 lines
Log Message:
Added electron Veto inversion to CiCTrackIso & MVA Tools

File Contents

# User Rev Content
1 fabstoec 1.26 // $Id: PhotonIDMod.cc,v 1.25 2011/08/03 17:15:43 bendavid Exp $
2 sixie 1.1
3 bendavid 1.24 #include "TDataMember.h"
4     #include "TTree.h"
5 sixie 1.1 #include "MitPhysics/Mods/interface/PhotonIDMod.h"
6 loizides 1.7 #include "MitAna/DataTree/interface/PhotonCol.h"
7 sixie 1.1 #include "MitPhysics/Init/interface/ModNames.h"
8 fabstoec 1.17 #include "MitPhysics/Utils/interface/IsolationTools.h"
9 bendavid 1.19 #include "MitPhysics/Utils/interface/PhotonTools.h"
10 sixie 1.1
11 fabstoec 1.26 #include <TSystem.h>
12    
13 sixie 1.1 using namespace mithep;
14    
15     ClassImp(mithep::PhotonIDMod)
16    
17     //--------------------------------------------------------------------------------------------------
18     PhotonIDMod::PhotonIDMod(const char *name, const char *title) :
19     BaseMod(name,title),
20 fabstoec 1.17 fPhotonBranchName (Names::gkPhotonBrn),
21     fGoodPhotonsName (ModNames::gkGoodPhotonsName),
22     fTrackBranchName (Names::gkTrackBrn),
23     fBeamspotBranchName(Names::gkBeamSpotBrn),
24 fabstoec 1.18 fPileUpDenName (Names::gkPileupEnergyDensityBrn),
25 bendavid 1.19 fConversionName ("MergedConversions"),
26     fElectronName ("Electrons"),
27 bendavid 1.25 fGoodElectronName ("Electrons"),
28 fabstoec 1.22 fPVName (Names::gkPVBeamSpotBrn),
29 bendavid 1.24 // MC specific stuff...
30     fMCParticleName (Names::gkMCPartBrn),
31     fPileUpName (Names::gkPileupInfoBrn),
32 fabstoec 1.22
33     fPhotonIDType ("Custom"),
34     fPhotonIsoType ("Custom"),
35     fPhotonPtMin (15.0),
36     fHadOverEmMax (0.02),
37     fApplySpikeRemoval (kFALSE),
38     fApplyPixelSeed (kTRUE),
39     fApplyElectronVeto (kFALSE),
40 bendavid 1.25 fInvertElectronVeto(kFALSE),
41 bendavid 1.19 fApplyElectronVetoConvRecovery(kFALSE),
42 fabstoec 1.22 fApplyConversionId (kFALSE),
43 bendavid 1.19 fApplyTriggerMatching(kFALSE),
44 fabstoec 1.22 fPhotonR9Min (0.5),
45     fPhIdType (kIdUndef),
46     fPhIsoType (kIsoUndef),
47     fFiduciality (kTRUE),
48     fEtaWidthEB (0.01),
49     fEtaWidthEE (0.028),
50     fAbsEtaMax (999.99),
51     fApplyR9Min (kFALSE),
52    
53     fEffAreaEcalEE (0.089),
54     fEffAreaHcalEE (0.156),
55     fEffAreaTrackEE (0.261),
56    
57     fEffAreaEcalEB (0.183),
58     fEffAreaHcalEB (0.062),
59     fEffAreaTrackEB (0.306),
60    
61 fabstoec 1.17 fPhotons(0),
62     fTracks(0),
63     fBeamspots(0),
64 bendavid 1.19 fPileUpDen(0),
65     fConversions(0),
66 fabstoec 1.22 fElectrons(0),
67 bendavid 1.25 fGoodElectrons(0),
68 fabstoec 1.22 fPV(0),
69 bendavid 1.24 fMCParticles (0),
70     fPileUp (0),
71 fabstoec 1.22
72 fabstoec 1.26 // MVA ID Stuff
73     fbdtCutBarrel (-0.01),
74     fbdtCutEndcap (-0.02),
75     fVariableType (2),
76     fEndcapWeights (gSystem->Getenv("CMSSW_BASE")+TString("/src/MitPhysics/data/TMVAClassificationPhotonID_NewMotherId_Endcap_PtMin30_IsoCut250_VariableType2_BDTnCuts2000_ApplyElecVeto1_PuWeight_BDT.weights.xml")),
77     fBarrelWeights (gSystem->Getenv("CMSSW_BASE")+TString("/src/MitPhysics/data/TMVAClassificationPhotonID_NewMotherId_Barrel_PtMin30_IsoCut250_VariableType2_BDTnCuts2000_ApplyElecVeto1_PuWeight_BDT.weights.xml")),
78    
79    
80 bendavid 1.24 fPVFromBranch (true),
81 bendavid 1.25 fGoodElectronsFromBranch (kTRUE),
82     fIsData(false)
83 fabstoec 1.17
84 sixie 1.1 {
85     // Constructor.
86     }
87    
88     //--------------------------------------------------------------------------------------------------
89     void PhotonIDMod::Process()
90     {
91     // Process entries of the tree.
92    
93 fabstoec 1.17 LoadEventObject(fPhotonBranchName, fPhotons);
94 bendavid 1.19
95     const BaseVertex *bsp = NULL;
96     Double_t _tRho = -1.;
97     const TriggerObjectCol *trigObjs = 0;
98     if (fPhotons->GetEntries()>0) {
99     LoadEventObject(fTrackBranchName, fTracks);
100     LoadEventObject(fBeamspotBranchName, fBeamspots);
101 bendavid 1.24 LoadEventObject(fPileUpDenName, fPileUpDen);
102 bendavid 1.19 LoadEventObject(fConversionName, fConversions);
103     LoadEventObject(fElectronName, fElectrons);
104 fabstoec 1.26 LoadEventObject(fGoodElectronName, fGoodElectrons);
105 bendavid 1.24 LoadEventObject(fPVName, fPV);
106 bendavid 1.19
107     if(fBeamspots->GetEntries() > 0)
108     bsp = fBeamspots->At(0);
109 fabstoec 1.17
110 bendavid 1.24 if(fPileUpDen->GetEntries() > 0)
111 fabstoec 1.23 _tRho = (Double_t) fPileUpDen->At(0)->RhoRandomLowEta();
112 fabstoec 1.26
113 bendavid 1.19
114     //get trigger object collection if trigger matching is enabled
115     if (fApplyTriggerMatching) {
116     trigObjs = GetHLTObjects(fTrigObjectsName);
117     }
118    
119     }
120 fabstoec 1.17
121 sixie 1.1 PhotonOArr *GoodPhotons = new PhotonOArr;
122     GoodPhotons->SetName(fGoodPhotonsName);
123    
124     for (UInt_t i=0; i<fPhotons->GetEntries(); ++i) {
125     const Photon *ph = fPhotons->At(i);
126    
127 bendavid 1.24
128     if (fFiduciality == kTRUE &&
129     (ph->SCluster()->AbsEta()>=2.5 || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566) ) )
130     continue;
131    
132 bendavid 1.25 if (fInvertElectronVeto && PhotonTools::PassElectronVeto(ph,fGoodElectrons)) {
133     continue;
134     }
135    
136 fabstoec 1.22 // ---------------------------------------------------------------------
137     // check if we use the CiC Selection. If yes, bypass all the below...
138     if(fPhIdType == kBaseLineCiC) {
139     if( PhotonTools::PassCiCSelection(ph, fPV->At(0), fTracks, fElectrons, fPV, _tRho, fPhotonPtMin, fApplyElectronVeto) )
140     GoodPhotons->Add(fPhotons->At(i));
141     continue; // go to next Photons
142     }
143     // ---------------------------------------------------------------------
144    
145 fabstoec 1.26 // add MingMings MVA ID on single Photon level
146     if(fPhIdType == kMITMVAId ) {
147     if( fTool.PassMVASelection(ph, fPV->At(0) ,fTracks, fPV, _tRho, fElectrons, fPhotonPtMin ,fbdtCutBarrel,fbdtCutEndcap, fApplyElectronVeto) ) {
148     GoodPhotons->Add(fPhotons->At(i));
149     }
150     continue;
151     } // go to next Photon
152    
153 sixie 1.1 if (ph->Pt() <= fPhotonPtMin)
154 fabstoec 1.22 continue; // add good electron
155 sixie 1.13
156 bendavid 1.21 Bool_t isbarrel = ph->SCluster()->AbsEta()<1.5;
157 sixie 1.1
158 sixie 1.13 Bool_t passSpikeRemovalFilter = kTRUE;
159 sixie 1.15
160     if (ph->SCluster() && ph->SCluster()->Seed()) {
161     if(ph->SCluster()->Seed()->Energy() > 5.0 &&
162     ph->SCluster()->Seed()->EMax() / ph->SCluster()->Seed()->E3x3() > 0.95
163     ) {
164     passSpikeRemovalFilter = kFALSE;
165     }
166 sixie 1.13 }
167    
168     // For Now Only use the EMax/E3x3 prescription.
169     //if(ph->SCluster()->Seed()->Energy() > 5.0 &&
170     // (1 - (ph->SCluster()->Seed()->E1x3() + ph->SCluster()->Seed()->E3x1() - 2*ph->SCluster()->Seed()->EMax())) > 0.95
171     // ) {
172     // passSpikeRemovalFilter = kFALSE;
173     //}
174     if (fApplySpikeRemoval && !passSpikeRemovalFilter) continue;
175    
176 ceballos 1.2 if (ph->HadOverEm() >= fHadOverEmMax)
177     continue;
178 ceballos 1.14
179 ceballos 1.2 if (fApplyPixelSeed == kTRUE &&
180     ph->HasPixelSeed() == kTRUE)
181     continue;
182 ceballos 1.14
183 bendavid 1.19 if (fApplyElectronVeto && !PhotonTools::PassElectronVeto(ph,fElectrons) ) continue;
184    
185     if (fApplyElectronVetoConvRecovery && !PhotonTools::PassElectronVetoConvRecovery(ph,fElectrons,fConversions,bsp) ) continue;
186    
187     if (fApplyConversionId && !PhotonTools::PassConversionId(ph,PhotonTools::MatchedConversion(ph,fConversions,bsp))) continue;
188    
189     if (fApplyTriggerMatching && !PhotonTools::PassTriggerMatching(ph,trigObjs)) continue;
190    
191 sixie 1.1 Bool_t idcut = kFALSE;
192     switch (fPhIdType) {
193     case kTight:
194     idcut = ph->IsTightPhoton();
195     break;
196     case kLoose:
197     idcut = ph->IsLoosePhoton();
198     break;
199     case kLooseEM:
200     idcut = ph->IsLooseEM();
201     break;
202     case kCustomId:
203 ceballos 1.5 idcut = kTRUE;
204 sixie 1.1 default:
205     break;
206     }
207    
208     if (!idcut)
209     continue;
210    
211     Bool_t isocut = kFALSE;
212     switch (fPhIsoType) {
213     case kNoIso:
214     isocut = kTRUE;
215     break;
216 ceballos 1.2 case kCombinedIso:
217 bendavid 1.12 {
218     Double_t totalIso = ph->HollowConeTrkIsoDr04()+
219     ph->EcalRecHitIsoDr04() +
220     ph->HcalTowerSumEtDr04();
221     if (totalIso/ph->Pt() < 0.25)
222     isocut = kTRUE;
223     }
224 ceballos 1.2 break;
225 sixie 1.1 case kCustomIso:
226 bendavid 1.16 {
227     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()) )
228     isocut = kTRUE;
229     }
230 fabstoec 1.17 break;
231    
232     case kMITPUCorrected:
233     {
234     // compute the PU corrections only if Rho is available
235     // ... otherwise (_tRho = -1.0) it's the std isolation
236     isocut = kTRUE;
237 fabstoec 1.20 Double_t fEffAreaEcal = fEffAreaEcalEB;
238     Double_t fEffAreaHcal = fEffAreaHcalEB;
239     Double_t fEffAreaTrack = fEffAreaTrackEB;
240    
241 bendavid 1.21 if( !isbarrel ) {
242 fabstoec 1.20 fEffAreaEcal = fEffAreaEcalEE;
243     fEffAreaHcal = fEffAreaHcalEE;
244     fEffAreaTrack = fEffAreaTrackEE;
245     }
246 fabstoec 1.26
247     //std::cout<<"-----------------------------------"<<std::endl;
248     //std::cout<<" MIT phooton Et = "<<ph->Et()<<std::endl;
249 fabstoec 1.17 Double_t EcalCorrISO = ph->EcalRecHitIsoDr04();
250 fabstoec 1.26 //std::cout<<" ecaliso4 = "<<EcalCorrISO<<std::endl;
251 fabstoec 1.17 if(_tRho > -0.5 ) EcalCorrISO -= _tRho * fEffAreaEcal;
252 fabstoec 1.26 //std::cout<<" ecaliso4Corr = "<<EcalCorrISO<<" ("<<2.0+0.006*ph->Pt()<<")"<<std::endl;
253 fabstoec 1.17 if ( EcalCorrISO > (2.0+0.006*ph->Pt()) ) isocut = kFALSE;
254 fabstoec 1.26 if ( isocut || true ) {
255 fabstoec 1.17 Double_t HcalCorrISO = ph->HcalTowerSumEtDr04();
256 fabstoec 1.26 //std::cout<<" hcaliso4 = "<<HcalCorrISO<<std::endl;
257 fabstoec 1.17 if(_tRho > -0.5 ) HcalCorrISO -= _tRho * fEffAreaHcal;
258 fabstoec 1.26 //std::cout<<" hcaliso4Corr = "<<HcalCorrISO<<" ("<<2.0+0.0025*ph->Pt()<<")"<<std::endl;
259 fabstoec 1.17 if ( HcalCorrISO > (2.0+0.0025*ph->Pt()) ) isocut = kFALSE;
260     }
261 fabstoec 1.26 if ( isocut || true ) {
262 fabstoec 1.17 Double_t TrackCorrISO = IsolationTools::TrackIsolationNoPV(ph, bsp, 0.4, 0.04, 0.0, 0.015, 0.1, TrackQuality::highPurity, fTracks);
263 fabstoec 1.26 //std::cout<<" TrackIso = "<<TrackCorrISO<<std::endl;
264 fabstoec 1.17 if(_tRho > -0.5 )
265     TrackCorrISO -= _tRho * fEffAreaTrack;
266 fabstoec 1.26 //std::cout<<" TrackIsoCorr = "<<TrackCorrISO<<" ("<<1.5 + 0.001*ph->Pt()<<")"<<std::endl;
267 fabstoec 1.17 if ( TrackCorrISO > (1.5 + 0.001*ph->Pt()) ) isocut = kFALSE;
268 fabstoec 1.26 //std::cout<<" passes ? "<<isocut<<std::endl;
269 fabstoec 1.17 }
270     break;
271     }
272     default:
273     break;
274 sixie 1.1 }
275 fabstoec 1.17
276 sixie 1.1 if (!isocut)
277     continue;
278 fabstoec 1.17
279 bendavid 1.16 if ( fApplyR9Min && ph->R9() <= fPhotonR9Min)
280 ceballos 1.5 continue;
281    
282 bendavid 1.21 if ((isbarrel && ph->CoviEtaiEta() >= fEtaWidthEB) ||
283     (!isbarrel && ph->CoviEtaiEta() >= fEtaWidthEE))
284 ceballos 1.10 continue;
285    
286 ceballos 1.11 if (ph->AbsEta() >= fAbsEtaMax)
287     continue;
288 bendavid 1.25
289    
290 sixie 1.1 // add good electron
291     GoodPhotons->Add(fPhotons->At(i));
292     }
293    
294 loizides 1.4 // sort according to pt
295     GoodPhotons->Sort();
296    
297 sixie 1.1 // add to event for other modules to use
298     AddObjThisEvt(GoodPhotons);
299 bendavid 1.24
300 bendavid 1.25 return;
301 bendavid 1.24
302 sixie 1.1 }
303    
304     //--------------------------------------------------------------------------------------------------
305     void PhotonIDMod::SlaveBegin()
306     {
307     // Run startup code on the computer (slave) doing the actual analysis. Here,
308 loizides 1.3 // we just request the photon collection branch.
309 sixie 1.1
310 fabstoec 1.22 ReqEventObject(fPhotonBranchName, fPhotons, kTRUE);
311     ReqEventObject(fTrackBranchName, fTracks, kTRUE);
312     ReqEventObject(fBeamspotBranchName, fBeamspots, kTRUE);
313 bendavid 1.19 ReqEventObject(fConversionName, fConversions, kTRUE);
314 fabstoec 1.22 ReqEventObject(fElectronName, fElectrons, kTRUE);
315 bendavid 1.25 ReqEventObject(fGoodElectronName, fGoodElectrons, fGoodElectronsFromBranch);
316 bendavid 1.24 ReqEventObject(fPVName, fPV, fPVFromBranch);
317     ReqEventObject(fPileUpDenName, fPileUpDen, kTRUE);
318     if (!fIsData) {
319     ReqBranch(fPileUpName, fPileUp);
320     ReqBranch(fMCParticleName, fMCParticles);
321     }
322    
323 sixie 1.1 if (fPhotonIDType.CompareTo("Tight") == 0)
324     fPhIdType = kTight;
325     else if (fPhotonIDType.CompareTo("Loose") == 0)
326     fPhIdType = kLoose;
327     else if (fPhotonIDType.CompareTo("LooseEM") == 0)
328     fPhIdType = kLooseEM;
329 fabstoec 1.22 else if (fPhotonIDType.CompareTo("Custom") == 0)
330 sixie 1.1 fPhIdType = kCustomId;
331 fabstoec 1.22 else if (fPhotonIDType.CompareTo("BaseLineCiC") == 0) {
332     fPhIdType = kBaseLineCiC;
333     fPhotonIsoType = "NoIso";
334 fabstoec 1.26 }
335     else if (fPhotonIDType.CompareTo("MITMVAId") == 0) {
336     fPhIdType = kMITMVAId;
337     fPhotonIsoType = "NoIso";
338     fTool.InitializeMVA(fVariableType,fEndcapWeights,fBarrelWeights);
339 sixie 1.1 } else {
340     SendError(kAbortAnalysis, "SlaveBegin",
341 ceballos 1.2 "The specified photon identification %s is not defined.",
342 sixie 1.1 fPhotonIDType.Data());
343     return;
344     }
345    
346     if (fPhotonIsoType.CompareTo("NoIso") == 0 )
347     fPhIsoType = kNoIso;
348 ceballos 1.2 else if (fPhotonIsoType.CompareTo("CombinedIso") == 0 )
349     fPhIsoType = kCombinedIso;
350 fabstoec 1.17 else if (fPhotonIsoType.CompareTo("Custom") == 0 )
351 sixie 1.1 fPhIsoType = kCustomIso;
352 fabstoec 1.17 else if (fPhotonIsoType.CompareTo("MITPUCorrected") == 0 )
353     fPhIsoType = kMITPUCorrected;
354     else {
355 sixie 1.1 SendError(kAbortAnalysis, "SlaveBegin",
356 ceballos 1.2 "The specified photon isolation %s is not defined.",
357 sixie 1.1 fPhotonIsoType.Data());
358     return;
359     }
360 bendavid 1.25
361 bendavid 1.24
362 sixie 1.1 }