1 |
// $Id: PhotonIDMod.cc,v 1.25 2011/08/03 17:15:43 bendavid Exp $
|
2 |
|
3 |
#include "TDataMember.h"
|
4 |
#include "TTree.h"
|
5 |
#include "MitPhysics/Mods/interface/PhotonIDMod.h"
|
6 |
#include "MitAna/DataTree/interface/PhotonCol.h"
|
7 |
#include "MitPhysics/Init/interface/ModNames.h"
|
8 |
#include "MitPhysics/Utils/interface/IsolationTools.h"
|
9 |
#include "MitPhysics/Utils/interface/PhotonTools.h"
|
10 |
|
11 |
#include <TSystem.h>
|
12 |
|
13 |
using namespace mithep;
|
14 |
|
15 |
ClassImp(mithep::PhotonIDMod)
|
16 |
|
17 |
//--------------------------------------------------------------------------------------------------
|
18 |
PhotonIDMod::PhotonIDMod(const char *name, const char *title) :
|
19 |
BaseMod(name,title),
|
20 |
fPhotonBranchName (Names::gkPhotonBrn),
|
21 |
fGoodPhotonsName (ModNames::gkGoodPhotonsName),
|
22 |
fTrackBranchName (Names::gkTrackBrn),
|
23 |
fBeamspotBranchName(Names::gkBeamSpotBrn),
|
24 |
fPileUpDenName (Names::gkPileupEnergyDensityBrn),
|
25 |
fConversionName ("MergedConversions"),
|
26 |
fElectronName ("Electrons"),
|
27 |
fGoodElectronName ("Electrons"),
|
28 |
fPVName (Names::gkPVBeamSpotBrn),
|
29 |
// MC specific stuff...
|
30 |
fMCParticleName (Names::gkMCPartBrn),
|
31 |
fPileUpName (Names::gkPileupInfoBrn),
|
32 |
|
33 |
fPhotonIDType ("Custom"),
|
34 |
fPhotonIsoType ("Custom"),
|
35 |
fPhotonPtMin (15.0),
|
36 |
fHadOverEmMax (0.02),
|
37 |
fApplySpikeRemoval (kFALSE),
|
38 |
fApplyPixelSeed (kTRUE),
|
39 |
fApplyElectronVeto (kFALSE),
|
40 |
fInvertElectronVeto(kFALSE),
|
41 |
fApplyElectronVetoConvRecovery(kFALSE),
|
42 |
fApplyConversionId (kFALSE),
|
43 |
fApplyTriggerMatching(kFALSE),
|
44 |
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 |
fPhotons(0),
|
62 |
fTracks(0),
|
63 |
fBeamspots(0),
|
64 |
fPileUpDen(0),
|
65 |
fConversions(0),
|
66 |
fElectrons(0),
|
67 |
fGoodElectrons(0),
|
68 |
fPV(0),
|
69 |
fMCParticles (0),
|
70 |
fPileUp (0),
|
71 |
|
72 |
// 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 |
fPVFromBranch (true),
|
81 |
fGoodElectronsFromBranch (kTRUE),
|
82 |
fIsData(false)
|
83 |
|
84 |
{
|
85 |
// Constructor.
|
86 |
}
|
87 |
|
88 |
//--------------------------------------------------------------------------------------------------
|
89 |
void PhotonIDMod::Process()
|
90 |
{
|
91 |
// Process entries of the tree.
|
92 |
|
93 |
LoadEventObject(fPhotonBranchName, fPhotons);
|
94 |
|
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 |
LoadEventObject(fPileUpDenName, fPileUpDen);
|
102 |
LoadEventObject(fConversionName, fConversions);
|
103 |
LoadEventObject(fElectronName, fElectrons);
|
104 |
LoadEventObject(fGoodElectronName, fGoodElectrons);
|
105 |
LoadEventObject(fPVName, fPV);
|
106 |
|
107 |
if(fBeamspots->GetEntries() > 0)
|
108 |
bsp = fBeamspots->At(0);
|
109 |
|
110 |
if(fPileUpDen->GetEntries() > 0)
|
111 |
_tRho = (Double_t) fPileUpDen->At(0)->RhoRandomLowEta();
|
112 |
|
113 |
|
114 |
//get trigger object collection if trigger matching is enabled
|
115 |
if (fApplyTriggerMatching) {
|
116 |
trigObjs = GetHLTObjects(fTrigObjectsName);
|
117 |
}
|
118 |
|
119 |
}
|
120 |
|
121 |
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 |
|
128 |
if (fFiduciality == kTRUE &&
|
129 |
(ph->SCluster()->AbsEta()>=2.5 || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566) ) )
|
130 |
continue;
|
131 |
|
132 |
if (fInvertElectronVeto && PhotonTools::PassElectronVeto(ph,fGoodElectrons)) {
|
133 |
continue;
|
134 |
}
|
135 |
|
136 |
// ---------------------------------------------------------------------
|
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 |
// 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 |
if (ph->Pt() <= fPhotonPtMin)
|
154 |
continue; // add good electron
|
155 |
|
156 |
Bool_t isbarrel = ph->SCluster()->AbsEta()<1.5;
|
157 |
|
158 |
Bool_t passSpikeRemovalFilter = kTRUE;
|
159 |
|
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 |
}
|
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 |
if (ph->HadOverEm() >= fHadOverEmMax)
|
177 |
continue;
|
178 |
|
179 |
if (fApplyPixelSeed == kTRUE &&
|
180 |
ph->HasPixelSeed() == kTRUE)
|
181 |
continue;
|
182 |
|
183 |
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 |
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 |
idcut = kTRUE;
|
204 |
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 |
case kCombinedIso:
|
217 |
{
|
218 |
Double_t totalIso = ph->HollowConeTrkIsoDr04()+
|
219 |
ph->EcalRecHitIsoDr04() +
|
220 |
ph->HcalTowerSumEtDr04();
|
221 |
if (totalIso/ph->Pt() < 0.25)
|
222 |
isocut = kTRUE;
|
223 |
}
|
224 |
break;
|
225 |
case kCustomIso:
|
226 |
{
|
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 |
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 |
Double_t fEffAreaEcal = fEffAreaEcalEB;
|
238 |
Double_t fEffAreaHcal = fEffAreaHcalEB;
|
239 |
Double_t fEffAreaTrack = fEffAreaTrackEB;
|
240 |
|
241 |
if( !isbarrel ) {
|
242 |
fEffAreaEcal = fEffAreaEcalEE;
|
243 |
fEffAreaHcal = fEffAreaHcalEE;
|
244 |
fEffAreaTrack = fEffAreaTrackEE;
|
245 |
}
|
246 |
|
247 |
//std::cout<<"-----------------------------------"<<std::endl;
|
248 |
//std::cout<<" MIT phooton Et = "<<ph->Et()<<std::endl;
|
249 |
Double_t EcalCorrISO = ph->EcalRecHitIsoDr04();
|
250 |
//std::cout<<" ecaliso4 = "<<EcalCorrISO<<std::endl;
|
251 |
if(_tRho > -0.5 ) EcalCorrISO -= _tRho * fEffAreaEcal;
|
252 |
//std::cout<<" ecaliso4Corr = "<<EcalCorrISO<<" ("<<2.0+0.006*ph->Pt()<<")"<<std::endl;
|
253 |
if ( EcalCorrISO > (2.0+0.006*ph->Pt()) ) isocut = kFALSE;
|
254 |
if ( isocut || true ) {
|
255 |
Double_t HcalCorrISO = ph->HcalTowerSumEtDr04();
|
256 |
//std::cout<<" hcaliso4 = "<<HcalCorrISO<<std::endl;
|
257 |
if(_tRho > -0.5 ) HcalCorrISO -= _tRho * fEffAreaHcal;
|
258 |
//std::cout<<" hcaliso4Corr = "<<HcalCorrISO<<" ("<<2.0+0.0025*ph->Pt()<<")"<<std::endl;
|
259 |
if ( HcalCorrISO > (2.0+0.0025*ph->Pt()) ) isocut = kFALSE;
|
260 |
}
|
261 |
if ( isocut || true ) {
|
262 |
Double_t TrackCorrISO = IsolationTools::TrackIsolationNoPV(ph, bsp, 0.4, 0.04, 0.0, 0.015, 0.1, TrackQuality::highPurity, fTracks);
|
263 |
//std::cout<<" TrackIso = "<<TrackCorrISO<<std::endl;
|
264 |
if(_tRho > -0.5 )
|
265 |
TrackCorrISO -= _tRho * fEffAreaTrack;
|
266 |
//std::cout<<" TrackIsoCorr = "<<TrackCorrISO<<" ("<<1.5 + 0.001*ph->Pt()<<")"<<std::endl;
|
267 |
if ( TrackCorrISO > (1.5 + 0.001*ph->Pt()) ) isocut = kFALSE;
|
268 |
//std::cout<<" passes ? "<<isocut<<std::endl;
|
269 |
}
|
270 |
break;
|
271 |
}
|
272 |
default:
|
273 |
break;
|
274 |
}
|
275 |
|
276 |
if (!isocut)
|
277 |
continue;
|
278 |
|
279 |
if ( fApplyR9Min && ph->R9() <= fPhotonR9Min)
|
280 |
continue;
|
281 |
|
282 |
if ((isbarrel && ph->CoviEtaiEta() >= fEtaWidthEB) ||
|
283 |
(!isbarrel && ph->CoviEtaiEta() >= fEtaWidthEE))
|
284 |
continue;
|
285 |
|
286 |
if (ph->AbsEta() >= fAbsEtaMax)
|
287 |
continue;
|
288 |
|
289 |
|
290 |
// add good electron
|
291 |
GoodPhotons->Add(fPhotons->At(i));
|
292 |
}
|
293 |
|
294 |
// sort according to pt
|
295 |
GoodPhotons->Sort();
|
296 |
|
297 |
// add to event for other modules to use
|
298 |
AddObjThisEvt(GoodPhotons);
|
299 |
|
300 |
return;
|
301 |
|
302 |
}
|
303 |
|
304 |
//--------------------------------------------------------------------------------------------------
|
305 |
void PhotonIDMod::SlaveBegin()
|
306 |
{
|
307 |
// Run startup code on the computer (slave) doing the actual analysis. Here,
|
308 |
// we just request the photon collection branch.
|
309 |
|
310 |
ReqEventObject(fPhotonBranchName, fPhotons, kTRUE);
|
311 |
ReqEventObject(fTrackBranchName, fTracks, kTRUE);
|
312 |
ReqEventObject(fBeamspotBranchName, fBeamspots, kTRUE);
|
313 |
ReqEventObject(fConversionName, fConversions, kTRUE);
|
314 |
ReqEventObject(fElectronName, fElectrons, kTRUE);
|
315 |
ReqEventObject(fGoodElectronName, fGoodElectrons, fGoodElectronsFromBranch);
|
316 |
ReqEventObject(fPVName, fPV, fPVFromBranch);
|
317 |
ReqEventObject(fPileUpDenName, fPileUpDen, kTRUE);
|
318 |
if (!fIsData) {
|
319 |
ReqBranch(fPileUpName, fPileUp);
|
320 |
ReqBranch(fMCParticleName, fMCParticles);
|
321 |
}
|
322 |
|
323 |
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 |
else if (fPhotonIDType.CompareTo("Custom") == 0)
|
330 |
fPhIdType = kCustomId;
|
331 |
else if (fPhotonIDType.CompareTo("BaseLineCiC") == 0) {
|
332 |
fPhIdType = kBaseLineCiC;
|
333 |
fPhotonIsoType = "NoIso";
|
334 |
}
|
335 |
else if (fPhotonIDType.CompareTo("MITMVAId") == 0) {
|
336 |
fPhIdType = kMITMVAId;
|
337 |
fPhotonIsoType = "NoIso";
|
338 |
fTool.InitializeMVA(fVariableType,fEndcapWeights,fBarrelWeights);
|
339 |
} else {
|
340 |
SendError(kAbortAnalysis, "SlaveBegin",
|
341 |
"The specified photon identification %s is not defined.",
|
342 |
fPhotonIDType.Data());
|
343 |
return;
|
344 |
}
|
345 |
|
346 |
if (fPhotonIsoType.CompareTo("NoIso") == 0 )
|
347 |
fPhIsoType = kNoIso;
|
348 |
else if (fPhotonIsoType.CompareTo("CombinedIso") == 0 )
|
349 |
fPhIsoType = kCombinedIso;
|
350 |
else if (fPhotonIsoType.CompareTo("Custom") == 0 )
|
351 |
fPhIsoType = kCustomIso;
|
352 |
else if (fPhotonIsoType.CompareTo("MITPUCorrected") == 0 )
|
353 |
fPhIsoType = kMITPUCorrected;
|
354 |
else {
|
355 |
SendError(kAbortAnalysis, "SlaveBegin",
|
356 |
"The specified photon isolation %s is not defined.",
|
357 |
fPhotonIsoType.Data());
|
358 |
return;
|
359 |
}
|
360 |
|
361 |
|
362 |
}
|