ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.51
Committed: Sat Aug 31 05:37:04 2013 UTC (11 years, 8 months ago) by veverka
Content type: text/plain
Branch: MAIN
Changes since 1.50: +312 -128 lines
Log Message:
Fist crack at the VH(lep) tag

File Contents

# Content
1 #include "MitPhysics/Mods/interface/PhotonTreeWriter.h"
2 #include "MitAna/DataTree/interface/PhotonCol.h"
3 #include "MitAna/DataTree/interface/PFCandidateCol.h"
4 #include "MitAna/DataTree/interface/StableData.h"
5 #include "MitAna/DataTree/interface/StableParticle.h"
6 #include "MitAna/DataTree/interface/PFMet.h"
7 #include "MitPhysics/Init/interface/ModNames.h"
8 #include "MitPhysics/Utils/interface/IsolationTools.h"
9 #include "MitPhysics/Utils/interface/PhotonTools.h"
10 #include "MitPhysics/Utils/interface/VertexTools.h"
11 #include "MitPhysics/Utils/interface/PFMetCorrectionTools.h"
12 #include "MitPhysics/Utils/interface/JetTools.h"
13 #include "MitAna/DataTree/interface/PFJetCol.h"
14 #include "MitAna/DataTree/interface/GenJetCol.h"
15 #include "TDataMember.h"
16 #include "TFile.h"
17 #include <TNtuple.h>
18 #include <TRandom3.h>
19 #include <TSystem.h>
20
21 using namespace mithep;
22
23 ClassImp(mithep::PhotonTreeWriter)
24 templateClassImp(mithep::PhotonTreeWriterPhoton)//ming: what's this?
25 ClassImp(mithep::PhotonTreeWriterDiphotonEvent)
26
27 //--------------------------------------------------------------------------------------------------
28 PhotonTreeWriter::PhotonTreeWriter(const char *name, const char *title) :
29 // Base Module...
30 BaseMod (name,title),
31 // define all the Branches to load
32 fPhotonBranchName (Names::gkPhotonBrn),
33 fPFPhotonName ("PFPhotons"),
34 fElectronName (Names::gkElectronBrn),
35 fGoodElectronName (Names::gkElectronBrn),
36 fConversionName (Names::gkMvfConversionBrn),
37 fPFConversionName ("PFPhotonConversions"),
38 fTrackBranchName (Names::gkTrackBrn),
39 fPileUpDenName (Names::gkPileupEnergyDensityBrn),
40 fPVName (Names::gkPVBeamSpotBrn),
41 fBeamspotName (Names::gkBeamSpotBrn),
42 fPFCandName (Names::gkPFCandidatesBrn),
43 fPFNoPileUpName ("PFNoPileUp"),
44 fPFPileUpName ("PFPileUp"),
45 fMCParticleName (Names::gkMCPartBrn),
46 fMCEventInfoName (Names::gkMCEvtInfoBrn),
47 fPileUpName (Names::gkPileupInfoBrn),
48 fSuperClusterName ("PFSuperClusters"),
49 fPFMetName ("PFMet"),
50 fPFJetName (Names::gkPFJetBrn),
51 funcorrPFJetName ("AKt5PFJets"),
52 fGenJetName ("AKT5GenJets"),
53 fLeptonTagElectronsName ("HggLeptonTagElectrons"),
54 fLeptonTagMuonsName ("HggLeptonTagMuons"),
55 fLeptonTagSoftElectronsName ("HggLeptonTagSoftElectrons"),
56 fLeptonTagSoftMuonsName ("HggLeptonTagSoftMuons"),
57
58 fIsData (false),
59 fPhotonsFromBranch (kTRUE),
60 fPVFromBranch (kTRUE),
61 fGoodElectronsFromBranch(kTRUE),
62 fPFJetsFromBranch (kTRUE),
63 // ----------------------------------------
64 // flag for synchronization, adds vertex variables
65 // should be on for synching trees
66 fDoSynching (kFALSE),
67
68 // ----------------------------------------
69 // collections....
70 fPhotons (0),
71 fPFPhotons (0),
72 fElectrons (0),
73 fConversions (0),
74 fPFConversions (0),
75 fTracks (0),
76 fPileUpDen (0),
77 fPV (0),
78 fBeamspot (0),
79 fPFCands (0),
80 fMCParticles (0),
81 fMCEventInfo (0),
82 fPileUp (0),
83 fSuperClusters (0),
84 fPFJets (0),
85 fGenJets (0),
86 funcorrPFJets (0),
87
88 fLeptonTagElectrons (0),
89 fLeptonTagMuons (0),
90 fPFNoPileUpCands (0),
91 fPFPileUpCands (0),
92
93 fLoopOnGoodElectrons (kFALSE),
94 fApplyElectronVeto (kTRUE),
95 fWriteDiphotonTree (kTRUE),
96 fWriteSingleTree (kTRUE),
97 fEnablePFPhotons (kTRUE),
98 fExcludeSinglePrompt (kFALSE),
99 fExcludeDoublePrompt (kFALSE),
100 fEnableJets (kFALSE),
101 fEnableGenJets (kFALSE),
102 fApplyJetId (kFALSE),
103 fApplyLeptonTag (kFALSE),
104 fApplyVHLepTag (kFALSE),
105 fApplyVBFTag (kFALSE),
106 fApplyTTHTag (kFALSE),
107 fApplyBTag (kFALSE),
108 fApplyPFMetCorrections (kFALSE),
109 fFillClusterArrays (kFALSE),
110 fFillVertexTree (kFALSE),
111 fDo2012LepTag (kFALSE),
112 fVerbosityLevel (0),
113 fPhFixDataFile (gSystem->Getenv("CMSSW_BASE") +
114 TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat")),
115 fBeamspotWidth (5.8),
116 fTmpFile (0),
117
118 // JV: moved up the initializtion of fTupleName to avoid compilation warning
119 fTupleName ("hPhotonTree"),
120
121 fElectronIDMVA(0),
122 fElectronMVAWeights_Subdet0Pt10To20(""),
123 fElectronMVAWeights_Subdet1Pt10To20(""),
124 fElectronMVAWeights_Subdet2Pt10To20(""),
125 fElectronMVAWeights_Subdet0Pt20ToInf(""),
126 fElectronMVAWeights_Subdet1Pt20ToInf(""),
127 fElectronMVAWeights_Subdet2Pt20ToInf(""),
128
129 fTheRhoType(RhoUtilities::DEFAULT)
130
131 {
132 // Constructor
133 }
134
135 PhotonTreeWriter::~PhotonTreeWriter()
136 {
137 // Destructor
138 // Deal with the temporary file here?
139 // fTmpFile->Write();
140 fTmpFile->Close();
141 TString shellcmd = TString("rm ") + TString(fTmpFile->GetName());
142 delete fTmpFile;
143 cout << shellcmd.Data() << endl;
144 gSystem->Exec(shellcmd.Data());
145
146 }
147
148 //--------------------------------------------------------------------------------------------------
149 void PhotonTreeWriter::Process()
150 {
151
152 //if(GetEventHeader()->EvtNum()==9008 || GetEventHeader()->EvtNum()==9008 || GetEventHeader()->EvtNum()==9010){
153 // printf("check photontreewriter 0\n");
154 // }
155 // ------------------------------------------------------------
156 // Process entries of the tree.
157 LoadEventObject(fPhotonBranchName, fPhotons);
158 LoadEventObject(fGoodElectronName, fGoodElectrons);
159
160 // lepton tag collections
161 if( fApplyLeptonTag || fApplyVHLepTag ) {
162 LoadEventObject(fLeptonTagElectronsName, fLeptonTagElectrons);
163 LoadEventObject(fLeptonTagMuonsName, fLeptonTagMuons);
164 }
165
166 if( fApplyVHLepTag ) {
167 LoadEventObject(fLeptonTagSoftElectronsName, fLeptonTagSoftElectrons);
168 LoadEventObject(fLeptonTagSoftMuonsName, fLeptonTagSoftMuons);
169 }
170
171 const BaseCollection *egcol = 0;
172 if (fLoopOnGoodElectrons)
173 egcol = fGoodElectrons;
174 else
175 egcol = fPhotons;
176 if (egcol->GetEntries()<1)
177 return;
178
179 if (fEnablePFPhotons) LoadEventObject(fPFPhotonName, fPFPhotons);
180 LoadEventObject(fElectronName, fElectrons);
181 LoadEventObject(fConversionName, fConversions);
182 if ( fDoSynching ) LoadEventObject(fPFConversionName, fPFConversions);
183 LoadEventObject(fTrackBranchName, fTracks);
184 LoadEventObject(fPileUpDenName, fPileUpDen);
185 LoadEventObject(fPVName, fPV);
186 LoadEventObject(fBeamspotName, fBeamspot);
187 LoadEventObject(fPFCandName, fPFCands);
188 LoadEventObject(fSuperClusterName, fSuperClusters);
189 LoadEventObject(fPFMetName, fPFMet);
190 // LoadEventObject(fPFNoPileUpName, fPFNoPileUpCands);
191 // LoadEventObject(fPFPileUpName, fPFPileUpCands);
192
193 if (fEnableJets){
194 LoadEventObject(fPFJetName, fPFJets);
195 //LoadEventObject(funcorrPFJetName, funcorrPFJets);
196 LoadBranch(funcorrPFJetName);
197 // if(!fIsData) LoadEventObject(fGenJetName, fGenJets);
198 }
199
200
201 // ------------------------------------------------------------
202 // load event based information
203 Int_t _numPU = -1.; // some sensible default values....
204 Int_t _numPUminus = -1.; // some sensible default values....
205 Int_t _numPUplus = -1.; // some sensible default values....
206
207 Float_t rho = -99.;
208 if( fPileUpDen->GetEntries() > 0 )
209 rho = (Double_t) fPileUpDen->At(0)->RhoRandomLowEta();//m
210
211 const BaseVertex *bsp = dynamic_cast<const BaseVertex*>(fBeamspot->At(0));//ming:what's this?
212
213 if( !fIsData ) {
214 LoadBranch(fMCParticleName);
215 LoadBranch(fMCEventInfoName);
216 LoadBranch(fPileUpName);
217 if (fEnableGenJets) LoadEventObject(fGenJetName, fGenJets);
218 } else fGenJets = NULL;
219
220 if( !fIsData ) {
221 for (UInt_t i=0; i<fPileUp->GetEntries(); ++i) {
222 const PileupInfo *puinfo = fPileUp->At(i);
223 if (puinfo->GetBunchCrossing()==0) _numPU = puinfo->GetPU_NumInteractions();
224 else if (puinfo->GetBunchCrossing() == -1) _numPUminus = puinfo->GetPU_NumInteractions();
225 else if (puinfo->GetBunchCrossing() == 1) _numPUplus = puinfo->GetPU_NumInteractions();
226 }
227 }
228
229 // in case of a MC event, try to find Higgs and Higgs decay Z poisition
230 Float_t _pth = -100.;
231 Float_t _decayZ = -100.;
232 Float_t _genmass = -100.;
233 if (!fIsData)
234 FindHiggsPtAndZ(_pth, _decayZ, _genmass);
235
236
237 fDiphotonEvent->genz = -999.;
238 if (!fIsData) {
239 fDiphotonEvent->genz = fMCParticles->At(0)->DecayVertex().Z();
240 }
241
242 fDiphotonEvent->mcprocid = -999;
243 if (!fIsData) {
244 fDiphotonEvent->mcprocid = fMCEventInfo->ProcessId();
245 fDiphotonEvent->mcweight = fMCEventInfo->Weight();
246 }
247
248 Double_t _evt = GetEventHeader()->EvtNum();
249
250 Double_t _spfMet = fPFMet->At(0)->SumEt();
251
252 fDiphotonEvent->leptonTag = -1; // disabled
253 fDiphotonEvent->VHLepTag = -1; // disabled
254
255 // ====================================================
256 // Vtx synching stuff...
257 fDiphotonEvent->vtxInd1 = -1;
258 fDiphotonEvent->vtxInd2 = -1;
259 fDiphotonEvent->vtxInd3 = -1;
260
261 fDiphotonEvent->vtxBestPtbal = -1.;
262 fDiphotonEvent->vtxBestPtasym = -1.;
263 fDiphotonEvent->vtxBestSumpt2 = -1.;
264 fDiphotonEvent->vtxBestP2Conv = -1.;
265
266 fDiphotonEvent->vtxMva1 = -1.;
267 fDiphotonEvent->vtxMva2 = -1.;
268 fDiphotonEvent->vtxMva3 = -1.;
269
270 fDiphotonEvent->vtxNleg1 = -1;
271 fDiphotonEvent->vtxNleg2 = -1;
272 fDiphotonEvent->vtxNconv = -1;
273 // ====================================================
274
275
276 fDiphotonEvent->rho = fPileUpDen->At(0)->RhoKt6PFJets();
277 fDiphotonEvent->rho25 = fPileUpDen->At(0)->RhoRandomLowEta();
278 fDiphotonEvent->rhoold = fPileUpDen->At(0)->Rho();
279 fDiphotonEvent->genHiggspt = _pth;
280 fDiphotonEvent->genHiggsZ = _decayZ;
281 fDiphotonEvent->genmass = _genmass;
282 fDiphotonEvent->gencostheta = -99.;
283 fDiphotonEvent->nVtx = fPV->GetEntries();
284 fDiphotonEvent->bsX = fBeamspot->At(0)->X();
285 fDiphotonEvent->bsY = fBeamspot->At(0)->Y();
286 fDiphotonEvent->bsZ = fBeamspot->At(0)->Z();
287 fDiphotonEvent->bsSigmaZ = fBeamspot->At(0)->SigmaZ();
288 fDiphotonEvent->vtxX = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->X() : -99.;
289 fDiphotonEvent->vtxY = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->Y() : -99.;
290 fDiphotonEvent->vtxZ = (fDiphotonEvent->nVtx>0) ? fPV->At(0)->Z() : -99.;
291 fDiphotonEvent->numPU = _numPU;
292 fDiphotonEvent->numPUminus = _numPUminus;
293 fDiphotonEvent->numPUplus = _numPUplus;
294 fDiphotonEvent->mass = -99.;
295 fDiphotonEvent->ptgg = -99.;
296 fDiphotonEvent->costheta = -99.;
297 fDiphotonEvent->mt = -99.;
298 fDiphotonEvent->cosphimet = -99.;
299 fDiphotonEvent->mtele = -99.;
300 fDiphotonEvent->cosphimetele = -99.;
301 fDiphotonEvent->evt = GetEventHeader()->EvtNum();
302 fDiphotonEvent->run = GetEventHeader()->RunNum();
303 fDiphotonEvent->lumi = GetEventHeader()->LumiSec();
304 fDiphotonEvent->evtcat = -99;
305 fDiphotonEvent->nobj = fPhotons->GetEntries();
306 fDiphotonEvent->pfmet = fPFMet->At(0)->Pt();
307 fDiphotonEvent->pfmetphi = fPFMet->At(0)->Phi();
308 fDiphotonEvent->pfmetx = fPFMet->At(0)->Px();
309 fDiphotonEvent->pfmety = fPFMet->At(0)->Py();
310 fDiphotonEvent->spfMet = _spfMet;
311 fDiphotonEvent->masscor = -99.;
312 fDiphotonEvent->masscorerr = -99.;
313 fDiphotonEvent->masscorele = -99.;
314 fDiphotonEvent->masscoreleerr = -99.;
315 fDiphotonEvent->ismc = GetEventHeader()->IsMC();
316
317 //jets
318 const Jet *jet1 = 0;
319 const Jet *jet2 = 0;
320 const Jet *jetcentral = 0;
321
322 fDiphotonEvent->jetleadNoIDpt = -99.;
323 fDiphotonEvent->jetleadNoIDeta = -99.;
324 fDiphotonEvent->jetleadNoIDphi = -99.;
325 fDiphotonEvent->jetleadNoIDmass = -99.;
326 fDiphotonEvent->jet1pt = -99.;
327 fDiphotonEvent->jet1eta = -99.;
328 fDiphotonEvent->jet1phi = -99.;
329 fDiphotonEvent->jet1mass = -99.;
330 fDiphotonEvent->jet2pt = -99.;
331 fDiphotonEvent->jet2eta = -99.;
332 fDiphotonEvent->jet2phi = -99.;
333 fDiphotonEvent->jet2mass = -99.;
334 fDiphotonEvent->jetcentralpt = -99.;
335 fDiphotonEvent->jetcentraleta = -99.;
336 fDiphotonEvent->jetcentralphi = -99.;
337 fDiphotonEvent->jetcentralmass = -99.;
338 fDiphotonEvent->dijetpt = -99.;
339 fDiphotonEvent->dijeteta = -99.;
340 fDiphotonEvent->dijetphi = -99.;
341 fDiphotonEvent->dijetmass = -99.;
342 fDiphotonEvent->jetetaplus = -99.;
343 fDiphotonEvent->jetetaminus = -99.;
344 fDiphotonEvent->zeppenfeld = -99.;
345 fDiphotonEvent->dphidijetgg = -99.;
346
347 //uncorrected jets
348 // const Jet *uncorrjet1 = 0;
349 // const Jet *uncorrjet2 = 0;
350 // const Jet *uncorrjetcentral = 0;
351
352 // fDiphotonEvent->uncorrjet1pt = -99.;
353 // fDiphotonEvent->uncorrjet1eta = -99.;
354 // fDiphotonEvent->uncorrjet1phi = -99.;
355 // fDiphotonEvent->uncorrjet1mass = -99.;
356 // fDiphotonEvent->uncorrjet2pt = -99.;
357 // fDiphotonEvent->uncorrjet2eta = -99.;
358 // fDiphotonEvent->uncorrjet2phi = -99.;
359 // fDiphotonEvent->uncorrjet2mass = -99.;
360 // fDiphotonEvent->uncorrjetcentralpt = -99.;
361 // fDiphotonEvent->uncorrjetcentraleta = -99.;
362 // fDiphotonEvent->uncorrjetcentralphi = -99.;
363 // fDiphotonEvent->uncorrjetcentralmass = -99.;
364 // fDiphotonEvent->diuncorrjetpt = -99.;
365 // fDiphotonEvent->diuncorrjeteta = -99.;
366 // fDiphotonEvent->diuncorrjetphi = -99.;
367 // fDiphotonEvent->diuncorrjetmass = -99.;
368
369
370
371 Int_t nhitsbeforevtxmax = 1;
372 if (!fApplyElectronVeto)
373 nhitsbeforevtxmax = 999;
374
375 if (egcol->GetEntries()>=2) {
376 const Particle *p1 = 0;
377 const Particle *p2 = 0;
378 const Photon *phHard = 0;
379 const Photon *phSoft = 0;
380 const Electron *ele1 = 0;
381 const Electron *ele2 = 0;
382 const SuperCluster *sc1 = 0;
383 const SuperCluster *sc2 = 0;
384
385 if (fLoopOnGoodElectrons) {
386 ele1 = fGoodElectrons->At(0);
387 ele2 = fGoodElectrons->At(1);
388 p1 = ele1;
389 p2 = ele2;
390 sc1 = ele1->SCluster();
391 sc2 = ele2->SCluster();
392 phHard = PhotonTools::MatchedPhoton(ele1,fPhotons);
393 phSoft = PhotonTools::MatchedPhoton(ele2,fPhotons);
394 }
395 else {
396 phHard = fPhotons->At(0);
397 phSoft = fPhotons->At(1);
398 p1 = phHard;
399 p2 = phSoft;
400 sc1 = phHard->SCluster();
401 sc2 = phSoft->SCluster();
402 ele1 = PhotonTools::MatchedElectron(phHard,fGoodElectrons);
403 ele2 = PhotonTools::MatchedElectron(phSoft,fGoodElectrons);
404 }
405
406 const DecayParticle *conv1 = PhotonTools::MatchedConversion(sc1,fConversions,bsp,
407 nhitsbeforevtxmax);
408 const DecayParticle *conv2 = PhotonTools::MatchedConversion(sc2,fConversions,bsp,
409 nhitsbeforevtxmax);
410
411 const SuperCluster *pfsc1 = PhotonTools::MatchedPFSC(sc1,fPFPhotons, fElectrons);
412 const SuperCluster *pfsc2 = PhotonTools::MatchedPFSC(sc2,fPFPhotons, fElectrons);
413
414 const MCParticle *phgen1 = 0;
415 const MCParticle *phgen2 = 0;
416 if (!fIsData) {
417 phgen1 = PhotonTools::MatchMC(p1,fMCParticles,!fApplyElectronVeto);
418 phgen2 = PhotonTools::MatchMC(p2,fMCParticles,!fApplyElectronVeto);
419 }
420
421 if (fExcludeSinglePrompt && (phgen1 || phgen2))
422 return;
423 if (fExcludeDoublePrompt && (phgen1 && phgen2))
424 return;
425
426 if (!fLoopOnGoodElectrons && phHard->HasPV()) {
427 fDiphotonEvent->vtxX = phHard->PV()->X();
428 fDiphotonEvent->vtxY = phHard->PV()->Y();
429 fDiphotonEvent->vtxZ = phHard->PV()->Z();
430 fDiphotonEvent->vtxprob = phHard->VtxProb();
431 }
432
433 // fill Btag information... set to true if One jet fullfills
434 fDiphotonEvent -> btagJet1 = -1.;
435 fDiphotonEvent -> btagJet1Pt = -99.;
436 fDiphotonEvent -> btagJet1Eta = -99.;
437
438 fDiphotonEvent -> btagJet2 = -1.;
439 fDiphotonEvent -> btagJet2Pt = -99.;
440 fDiphotonEvent -> btagJet2Eta = -99.;
441
442 if( fApplyBTag && fEnableJets ) {
443 float highTag = 0.;
444 float highJetPt = 0.;
445 float highJetEta = 0.;
446
447 float trailTag = 0.;
448 float trailJetPt = 0.;
449 float trailJetEta = 0.;
450
451 for (UInt_t ijet=0; ijet<fPFJets->GetEntries();++ijet) {
452 const Jet *jet = fPFJets->At(ijet);
453 if ( jet->Pt() < 20. || jet->AbsEta() > 2.4 ) continue;
454 if ( jet->CombinedSecondaryVertexBJetTagsDisc() > highTag ) {
455
456 trailTag = highTag;
457 trailJetPt = highJetPt;
458 trailJetEta = highJetEta;
459
460 highTag = jet->CombinedSecondaryVertexBJetTagsDisc();
461 highJetPt = jet->Pt();
462 highJetEta = jet->Eta();
463
464 } else if ( jet->CombinedSecondaryVertexBJetTagsDisc() > trailTag ) {
465
466 trailTag = jet->CombinedSecondaryVertexBJetTagsDisc();
467 trailJetPt = jet->Pt();
468 trailJetEta = jet->Eta();
469 }
470 }
471 fDiphotonEvent -> btagJet1 = highTag;
472 fDiphotonEvent -> btagJet1Pt = highJetPt;
473 fDiphotonEvent -> btagJet1Eta = highJetEta;
474
475 fDiphotonEvent -> btagJet2 = trailTag;
476 fDiphotonEvent -> btagJet2Pt = trailJetPt;
477 fDiphotonEvent -> btagJet2Eta = trailJetEta;
478
479 }
480
481
482 //fill jet variables
483 const Vertex *selvtx = fPV->At(0);
484 if (!fLoopOnGoodElectrons && phHard->HasPV()) selvtx = phHard->PV();
485 if (fEnableJets) {
486 for (UInt_t ijet=0; ijet<fPFJets->GetEntries();++ijet) {
487 const Jet *jet = fPFJets->At(ijet);
488 if (jet->AbsEta()<4.7 && MathUtils::DeltaR(jet,p1)>0.5 && MathUtils::DeltaR(jet,p2)>0.5) {
489 const PFJet *pfjet = dynamic_cast<const PFJet*>(jet);
490 if (!pfjet) continue;
491 if (fApplyJetId && !fJetId.passCut(pfjet,selvtx,fPV)) continue;
492 if (!jet1) jet1 = jet;
493 else if (!jet2) jet2 = jet;
494 else if (!jetcentral && 0) jetcentral = jet;
495 }
496 if (jet1&&jet2&&jetcentral) break;
497 }
498
499 for(UInt_t ijet=0; ijet<fPFJets->GetEntries();++ijet){
500
501 const Jet *jet = fPFJets->At(ijet);
502 if (MathUtils::DeltaR(jet,p1)>0.5 && MathUtils::DeltaR(jet,p2)>0.5) {
503 fDiphotonEvent->jetleadNoIDpt = jet->Pt();
504 fDiphotonEvent->jetleadNoIDeta = jet->Eta();
505 fDiphotonEvent->jetleadNoIDphi = jet->Phi();
506 fDiphotonEvent->jetleadNoIDmass = jet->Mass();
507 break;
508 }
509 }
510
511 if (jet1) {
512 fDiphotonEvent->jet1pt = jet1->Pt();
513 fDiphotonEvent->jet1eta = jet1->Eta();
514 fDiphotonEvent->jet1phi = jet1->Phi();
515 fDiphotonEvent->jet1mass = jet1->Mass();
516 }
517
518 if (jet2) {
519 fDiphotonEvent->jet2pt = jet2->Pt();
520 fDiphotonEvent->jet2eta = jet2->Eta();
521 fDiphotonEvent->jet2phi = jet2->Phi();
522 fDiphotonEvent->jet2mass = jet2->Mass();
523 }
524
525 if (jetcentral) {
526 fDiphotonEvent->jetcentralpt = jetcentral->Pt();
527 fDiphotonEvent->jetcentraleta = jetcentral->Eta();
528 fDiphotonEvent->jetcentralphi = jetcentral->Phi();
529 fDiphotonEvent->jetcentralmass = jetcentral->Mass();
530 }
531
532 if (jet1&&jet2){
533 FourVectorM momjj = (jet1->Mom() + jet2->Mom());
534
535 fDiphotonEvent->dijetpt = momjj.Pt();
536 fDiphotonEvent->dijeteta = momjj.Eta();
537 fDiphotonEvent->dijetphi = momjj.Phi();
538 fDiphotonEvent->dijetmass = momjj.M();
539
540 if (jet1->Eta()>jet2->Eta()) {
541 fDiphotonEvent->jetetaplus = jet1->Eta();
542 fDiphotonEvent->jetetaminus = jet2->Eta();
543 }
544 else {
545 fDiphotonEvent->jetetaplus = jet2->Eta();
546 fDiphotonEvent->jetetaminus = jet1->Eta();
547 }
548 }
549 }
550
551 //added gen. info of whether a lep. or nutrino is from W or Z --Heng 02/14/2012 12:30 EST
552 Double_t _fromZ = -99;
553 Double_t _fromW = -99;
554 Float_t _zpt = -99;
555 Float_t _zEta = -99;
556 Float_t _allZpt = -99;
557 Float_t _allZEta = -99;
558
559 if( !fIsData ){
560
561 // loop over all GEN particles and look for nutrinos whoes mother is Z
562 for(UInt_t j=0; j<fMCParticles->GetEntries(); ++j) {
563 const MCParticle* p = fMCParticles->At(j);
564 if( p->AbsPdgId()==23 ||p->AbsPdgId()==32 || p->AbsPdgId()==33 ) {
565 _allZpt=p->Pt();
566 _allZEta=p->Eta();
567 if (p->HasDaughter(12,kFALSE) || p->HasDaughter(14,kFALSE) || p->HasDaughter(16,kFALSE) ||p->HasDaughter(18,kFALSE) ) {
568 _fromZ=1;
569 _zpt=p->Pt();
570 _zEta=p->Eta();
571 }
572 }
573 else _fromW=1;
574 }
575 }
576
577 fDiphotonEvent->fromZ = _fromZ;
578 fDiphotonEvent->fromW = _fromW;
579 fDiphotonEvent->zpt = _zpt;
580 fDiphotonEvent->zEta = _zEta;
581 fDiphotonEvent->allZpt = _allZpt;
582 fDiphotonEvent->allZEta = _allZEta;
583
584 Double_t _dphiMetgg = -99;
585 Double_t _cosdphiMetgg = -99;
586 Double_t _dphiPhPh = -99;
587
588 Double_t _mass = -99.;
589 Double_t _masserr = -99.;
590 Double_t _masserrsmeared = -99.;
591 Double_t _masserrwrongvtx = -99.;
592 Double_t _masserrsmearedwrongvtx = -99.;
593 Double_t _ptgg = -99.;
594 Double_t _etagg = -99.;
595 Double_t _phigg = -99.;
596 Double_t _costheta = -99.;
597 PhotonTools::DiphotonR9EtaPtCats _evtcat = PhotonTools::kOctCat0;
598
599 const Vertex* realVtx = NULL;
600
601 if (phHard && phSoft) {
602 _dphiMetgg = MathUtils::DeltaPhi((phHard->Mom()+phSoft->Mom()).Phi(),fPFMet->At(0)->Phi());
603 _cosdphiMetgg = TMath::Cos(_dphiMetgg);
604 _dphiPhPh = MathUtils::DeltaPhi((phHard->Mom()).Phi(),(phSoft->Mom()).Phi());
605 _mass = (phHard->Mom()+phSoft->Mom()).M();
606 _masserr = 0.5*_mass*TMath::Sqrt(phHard->EnergyErr()*phHard->EnergyErr()/phHard->E()/phHard->E() + phSoft->EnergyErr()*phSoft->EnergyErr()/phSoft->E()/phSoft->E());
607 _masserrsmeared = 0.5*_mass*TMath::Sqrt(phHard->EnergyErrSmeared()*phHard->EnergyErrSmeared()/phHard->E()/phHard->E() + phSoft->EnergyErrSmeared()*phSoft->EnergyErrSmeared()/phSoft->E()/phSoft->E());
608 _ptgg = (phHard->Mom()+phSoft->Mom()).Pt();
609 _etagg = (phHard->Mom()+phSoft->Mom()).Eta();
610 _phigg = (phHard->Mom()+phSoft->Mom()).Phi();
611 _costheta = ThreeVector(phHard->Mom()).Unit().Dot(ThreeVector(phSoft->Mom()).Unit());
612 _evtcat = PhotonTools::DiphotonR9EtaPtCat(phHard,phSoft);
613
614 const Double_t dz = sqrt(2.0)*fBeamspotWidth;
615 Double_t deltamvtx = _mass*VertexTools::DeltaMassVtx(phHard->CaloPos().X(),
616 phHard->CaloPos().Y(),
617 phHard->CaloPos().Z(),
618 phSoft->CaloPos().X(),
619 phSoft->CaloPos().Y(),
620 phSoft->CaloPos().Z(),
621 fDiphotonEvent->vtxX,
622 fDiphotonEvent->vtxY,
623 fDiphotonEvent->vtxZ,
624 dz);
625 fDiphotonEvent->deltamvtx = deltamvtx;
626
627 _masserrwrongvtx = TMath::Sqrt(_masserr*_masserr + deltamvtx*deltamvtx);
628 _masserrsmearedwrongvtx = TMath::Sqrt(_masserrsmeared*_masserrsmeared + deltamvtx*deltamvtx);
629
630
631
632 // =================================================================================
633 // this is for synching the Vtx stuff
634 if ( fDoSynching ) {
635 //fill conversion collection for vertex selection, adding single leg conversions if needed
636 //note that momentum of single leg conversions needs to be recomputed from the track
637 //as it is not filled properly
638 DecayParticleOArr vtxconversions;
639 if ( true ) {
640 vtxconversions.SetOwner(kTRUE);
641 for (UInt_t iconv=0; iconv<fConversions->GetEntries(); ++iconv) {
642 DecayParticle *conv = new DecayParticle(*fConversions->At(iconv));
643 vtxconversions.AddOwned(conv);
644 }
645
646 for (UInt_t iconv=0; iconv<fPFConversions->GetEntries(); ++iconv) {
647 const DecayParticle *c = fPFConversions->At(iconv);
648 if (c->NDaughters()!=1) continue;
649
650 DecayParticle *conv = new DecayParticle(*c);
651 const Track *trk = static_cast<const StableParticle*>(conv->Daughter(0))->Trk();
652 conv->SetMom(trk->Px(), trk->Py(), trk->Pz(), trk->P());
653 vtxconversions.AddOwned(conv);
654 }
655 }
656 else {
657 for (UInt_t iconv=0; iconv<fConversions->GetEntries(); ++iconv) {
658 const DecayParticle *c = fConversions->At(iconv);
659 vtxconversions.Add(c);
660 }
661 }
662
663
664 const BaseVertex *bsp = dynamic_cast<const BaseVertex*>(fBeamspot->At(0));
665 double tmpVtxProb = 0.;
666
667 std::vector<int> debugInds; // this hold the Vtx indices for the first three guys
668 std::vector<double> debugVals; // this holds hte mva input/output for the best ranked
669 std::vector<int> debugConv; // this holds number of legs for frist and second photon (0 if no conversion) and total number of conversions
670
671
672 realVtx = fVtxTools.findVtxBasicRanking(phHard, phSoft, bsp, fPV,
673 &vtxconversions,kTRUE,tmpVtxProb,
674 &debugInds, &debugVals, &debugConv
675 );
676
677 fDiphotonEvent->vtxInd1 = debugInds[0];
678 fDiphotonEvent->vtxInd2 = debugInds[1];
679 fDiphotonEvent->vtxInd3 = debugInds[2];
680
681 fDiphotonEvent->vtxConv1Z = debugVals[0];
682 fDiphotonEvent->vtxConv1DZ = debugVals[1];
683 fDiphotonEvent->vtxConv1Prob = debugVals[2];
684
685 fDiphotonEvent->vtxConv2Z = debugVals[3];
686 fDiphotonEvent->vtxConv2DZ = debugVals[4];
687 fDiphotonEvent->vtxConv2Prob = debugVals[5];
688
689
690 fDiphotonEvent->vtxBestPtbal = debugVals[6];
691 fDiphotonEvent->vtxBestPtasym = debugVals[7];
692 fDiphotonEvent->vtxBestSumpt2 = debugVals[8];
693 fDiphotonEvent->vtxBestP2Conv = debugVals[9];
694
695 fDiphotonEvent->vtxMva1Z = debugVals[10];
696 fDiphotonEvent->vtxMva2Z = debugVals[11];
697 fDiphotonEvent->vtxMva3Z = debugVals[12];
698
699 fDiphotonEvent->vtxMva1 = debugVals[13];
700 fDiphotonEvent->vtxMva2 = debugVals[14];
701 fDiphotonEvent->vtxMva3 = debugVals[15];
702
703 fDiphotonEvent->vtxNleg1 = debugConv[0];
704 fDiphotonEvent->vtxNleg2 = debugConv[1];
705 fDiphotonEvent->vtxConvIdx1 = debugConv[2];
706 fDiphotonEvent->vtxConvIdx2 = debugConv[3];
707
708 fDiphotonEvent->vtxNconv = debugConv[4];
709
710 if( false ) {
711 printf("---------------------------------------------------------------------\n");
712 printf("FINAL\nvtx %i: ptbal = %5f, ptasym = %5f, logsumpt2 = %5f, limpulltoconv = %5f, nconv = %i, mva = %5f\n",fDiphotonEvent->vtxInd1,fDiphotonEvent->vtxBestPtbal,fDiphotonEvent->vtxBestPtasym,fDiphotonEvent->vtxBestSumpt2,fDiphotonEvent->vtxBestP2Conv,fDiphotonEvent->vtxNconv,fDiphotonEvent->vtxMva1);
713 printf("---------------------------------------------------------------------\n");
714 }
715 }
716
717 // end of Vtx synching stuff ...
718 // =================================================================================
719
720 PFJetOArr pfjets;
721 if (fEnableJets){
722 if (jet1 && jet2) {
723 fDiphotonEvent->zeppenfeld = TMath::Abs(_etagg - 0.5*(jet1->Eta()+jet2->Eta()));
724 fDiphotonEvent->dphidijetgg = MathUtils::DeltaPhi( (jet1->Mom()+jet2->Mom()).Phi(), _phigg );
725 }
726
727 //PFJetOArr pfjets;
728 for (UInt_t ijet=0; ijet<fPFJets->GetEntries(); ++ijet) {
729 const PFJet *pfjet = dynamic_cast<const PFJet*>(fPFJets->At(ijet));
730 if (pfjet && MathUtils::DeltaR(*pfjet,*phHard)>0.3 && MathUtils::DeltaR(*pfjet,*phSoft)>0.3) pfjets.Add(pfjet);
731 }
732 }
733
734 PFCandidateOArr pfcands;
735 for (UInt_t icand=0; icand<fPFCands->GetEntries(); ++icand) {
736 const PFCandidate *pfcand = fPFCands->At(icand);
737 if (MathUtils::DeltaR(*pfcand,*phHard)>0.1 && MathUtils::DeltaR(*pfcand,*phSoft)>0.1) pfcands.Add(pfcand);
738 }
739
740 const Vertex *firstvtx = fPV->At(0);
741 const Vertex *selvtx = fPV->At(0);
742
743 if (!fLoopOnGoodElectrons && phHard->HasPV()) {
744 selvtx = phHard->PV();
745 }
746
747 if (0) //disable for now for performance reasons
748 {
749 Met mmet = fMVAMet.GetMet( false,
750 0.,0.,0.,
751 0.,0.,0.,
752 fPFMet->At(0),
753 &pfcands,selvtx,fPV, fPileUpDen->At(0)->Rho(),
754 &pfjets,
755 int(fPV->GetEntries()),
756 kFALSE);
757
758 TMatrixD *metcov = fMVAMet.GetMetCovariance();
759
760 ThreeVector fullmet(mmet.Px() - phHard->Px() - phSoft->Px(),
761 mmet.Py() - phHard->Py() - phSoft->Py(),
762 0.);
763
764 ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > mcov;
765 mcov(0,0) = (*metcov)(0,0);
766 mcov(0,1) = (*metcov)(0,1);
767 mcov(1,0) = (*metcov)(1,0);
768 mcov(1,1) = (*metcov)(1,1);
769 ROOT::Math::SVector<double,2> vmet;
770 vmet(0) = fullmet.X();
771 vmet(1) = fullmet.Y();
772 mcov.Invert();
773 Double_t metsig = sqrt(ROOT::Math::Similarity(mcov,vmet));
774
775 fDiphotonEvent->mvametsel = fullmet.Rho();
776 fDiphotonEvent->mvametselphi = fullmet.Phi();
777 fDiphotonEvent->mvametselx = fullmet.X();
778 fDiphotonEvent->mvametsely = fullmet.Y();
779 fDiphotonEvent->mvametselsig = metsig;
780 }
781
782 if (0) //disable for now for performance reasons
783 {
784 Met mmet = fMVAMet.GetMet( false,
785 0.,0.,0.,
786 0.,0.,0.,
787 fPFMet->At(0),
788 &pfcands,firstvtx,fPV, fPileUpDen->At(0)->Rho(),
789 &pfjets,
790 int(fPV->GetEntries()),
791 kFALSE);
792
793 TMatrixD *metcov = fMVAMet.GetMetCovariance();
794
795 ThreeVector fullmet(mmet.Px() - phHard->Px() - phSoft->Px(),
796 mmet.Py() - phHard->Py() - phSoft->Py(),
797 0.);
798
799 ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2> > mcov;
800 mcov(0,0) = (*metcov)(0,0);
801 mcov(0,1) = (*metcov)(0,1);
802 mcov(1,0) = (*metcov)(1,0);
803 mcov(1,1) = (*metcov)(1,1);
804 ROOT::Math::SVector<double,2> vmet;
805 vmet(0) = fullmet.X();
806 vmet(1) = fullmet.Y();
807 mcov.Invert();
808 Double_t metsig = sqrt(ROOT::Math::Similarity(mcov,vmet));
809
810 fDiphotonEvent->mvametfirst = fullmet.Rho();
811 fDiphotonEvent->mvametfirstphi = fullmet.Phi();
812 fDiphotonEvent->mvametfirstx = fullmet.X();
813 fDiphotonEvent->mvametfirsty = fullmet.Y();
814 fDiphotonEvent->mvametfirstsig = metsig;
815 }
816
817 }
818
819 fDiphotonEvent->corrpfmet = -99.;
820 fDiphotonEvent->corrpfmetphi = -99.;
821 fDiphotonEvent->corrpfmetx = -99.;
822 fDiphotonEvent->corrpfmety = -99.;
823
824 Met *corrMet =NULL;
825
826 if (fApplyPFMetCorrections){
827 corrMet = new Met(fPFMet->At(0)->Px(),fPFMet->At(0)->Py());
828
829 if (!fIsData){
830 PFMetCorrectionTools::correctMet(corrMet,phHard,phSoft,1,0,funcorrPFJets,fGenJets,fPFJets,_evt);
831 PFMetCorrectionTools::shiftMet(corrMet,fIsData,_spfMet);
832 }
833 else {
834 PFMetCorrectionTools::shiftMet(corrMet,fIsData,_spfMet);
835 PFMetCorrectionTools::correctMet(corrMet,phHard,phSoft,0,1,funcorrPFJets,fGenJets,fPFJets,_evt);
836 }
837
838 fDiphotonEvent->corrpfmet = corrMet->Pt();
839 fDiphotonEvent->corrpfmetphi = corrMet->Phi();
840 fDiphotonEvent->corrpfmetx = corrMet->Px();
841 fDiphotonEvent->corrpfmety = corrMet->Py();
842
843 delete corrMet;
844 }
845
846
847 Float_t _massele = -99.;
848 Float_t _ptee = -99.;
849 Float_t _costhetaele = -99.;
850 if (ele1 && ele2) {
851 _massele = (ele1->Mom()+ele2->Mom()).M();
852 _ptee = (ele1->Mom()+ele2->Mom()).Pt();
853 _costhetaele = ThreeVector(ele1->Mom()).Unit().Dot(ThreeVector(ele2->Mom()).Unit());
854 }
855
856 Float_t _gencostheta = -99.;
857 if (phgen1 && phgen2) {
858 _gencostheta = ThreeVector(phgen1->Mom()).Unit().Dot(ThreeVector(phgen2->Mom()).Unit());
859 }
860
861 fDiphotonEvent->gencostheta = _gencostheta;
862 fDiphotonEvent->dphiMetgg = _dphiMetgg;
863 fDiphotonEvent->cosdphiMetgg = _cosdphiMetgg;
864 fDiphotonEvent->dphiPhPh = _dphiPhPh;
865 fDiphotonEvent->mass = _mass;
866 fDiphotonEvent->masserr = _masserr;
867 fDiphotonEvent->masserrsmeared = _masserrsmeared;
868 fDiphotonEvent->masserrwrongvtx = _masserrwrongvtx;
869 fDiphotonEvent->masserrsmearedwrongvtx = _masserrsmearedwrongvtx;
870 fDiphotonEvent->ptgg = _ptgg;
871 fDiphotonEvent->etagg = _etagg;
872 fDiphotonEvent->phigg = _phigg;
873 fDiphotonEvent->costheta = _costheta;;
874 fDiphotonEvent->massele = _massele;
875 fDiphotonEvent->ptee = _ptee;
876 fDiphotonEvent->costhetaele = _costhetaele;
877 fDiphotonEvent->evtcat = _evtcat;
878
879 fDiphotonEvent->photons[0].SetVars(phHard,conv1,ele1,pfsc1,phgen1,fPhfixph,fPhfixele,fTracks,fPV,fPFCands,rho,fFillClusterArrays,fElectrons,fConversions,bsp,fApplyElectronVeto,realVtx);
880 fDiphotonEvent->photons[1].SetVars(phSoft,conv2,ele2,pfsc2,phgen2,fPhfixph,fPhfixele,fTracks,fPV,fPFCands,rho,fFillClusterArrays,fElectrons,fConversions,bsp,fApplyElectronVeto,realVtx);
881
882 Float_t ph1ecor = fDiphotonEvent->photons[0].Ecor();
883 Float_t ph1ecorerr = fDiphotonEvent->photons[0].Ecorerr();
884 Float_t ph2ecor = fDiphotonEvent->photons[1].Ecor();
885 Float_t ph2ecorerr = fDiphotonEvent->photons[1].Ecorerr();
886
887 Float_t ph1ecorele = fDiphotonEvent->photons[0].Ecorele();
888 Float_t ph1ecoreleerr = fDiphotonEvent->photons[0].Ecoreleerr();
889 Float_t ph2ecorele = fDiphotonEvent->photons[1].Ecorele();
890 Float_t ph2ecoreleerr = fDiphotonEvent->photons[1].Ecoreleerr();
891
892 fDiphotonEvent->masscor = TMath::Sqrt(2.0*ph1ecor*ph2ecor*(1.0-fDiphotonEvent->costheta));
893 fDiphotonEvent->masscorerr = 0.5*fDiphotonEvent->masscor*
894 TMath::Sqrt(ph1ecorerr*ph1ecorerr/ph1ecor/ph1ecor + ph2ecorerr*ph2ecorerr/ph2ecor/ph2ecor);
895
896 fDiphotonEvent->masscorele = TMath::Sqrt(2.0*ph1ecorele*ph2ecorele*
897 (1.0-fDiphotonEvent->costheta));
898 fDiphotonEvent->masscoreleerr = 0.5*fDiphotonEvent->masscorele*
899 TMath::Sqrt(ph1ecoreleerr*ph1ecoreleerr/ph1ecorele/ph1ecorele +
900 ph2ecoreleerr*ph2ecoreleerr/ph2ecorele/ph2ecorele);
901
902 //printf("r9 = %5f, photon sigieie = %5f, seed sigieie = %5f\n",phHard->R9(),
903 // phHard->CoviEtaiEta(),sqrt(phHard->SCluster()->Seed()->CoviEtaiEta()));
904
905 // MuonStuff
906 fDiphotonEvent-> muonPt = -99.;
907 fDiphotonEvent-> muonEta = -99.;
908 fDiphotonEvent-> muDR1 = -99.;
909 fDiphotonEvent-> muDR2 = -99.;
910 fDiphotonEvent-> muIso1 = -99.;
911 fDiphotonEvent-> muIso2 = -99.;
912 fDiphotonEvent-> muIso3 = -99.;
913 fDiphotonEvent-> muIso4 = -99.;
914 fDiphotonEvent-> muD0 = -99.;
915 fDiphotonEvent-> muDZ = -99.;
916 fDiphotonEvent-> muChi2 = -99.;
917 fDiphotonEvent-> muNhits = -99;
918 fDiphotonEvent-> muNpixhits = -99;
919 fDiphotonEvent-> muNegs = -99;
920 fDiphotonEvent-> muNMatch = -99;
921
922 // Electron Stuff
923 fDiphotonEvent-> elePt = -99.;
924 fDiphotonEvent-> eleEta = -99.;
925 fDiphotonEvent-> eleSCEta = -99.;
926 fDiphotonEvent-> eleIso1 = -99.;
927 fDiphotonEvent-> eleIso2 = -99.;
928 fDiphotonEvent-> eleIso3 = -99.;
929 fDiphotonEvent-> eleIso4 = -99.;
930 fDiphotonEvent-> eleDist = -99.;
931 fDiphotonEvent-> eleDcot = -99.;
932 fDiphotonEvent-> eleCoviee = -99.;
933 fDiphotonEvent-> eleDphiin = -99.;
934 fDiphotonEvent-> eleDetain = -99.;
935 fDiphotonEvent-> eleDR1 = -99.;
936 fDiphotonEvent-> eleDR2 = -99.;
937 fDiphotonEvent-> eleMass1 = -99.;
938 fDiphotonEvent-> eleMass2 = -99.;
939 fDiphotonEvent-> eleNinnerHits = -99;
940
941 fDiphotonEvent-> eleIdMva = -99.;
942
943
944 if( fApplyLeptonTag ) {
945 ApplyLeptonTag(phHard, phSoft, selvtx);
946 }
947
948 if( fApplyVHLepTag ) {
949 ApplyVHLepTag(phHard, phSoft, selvtx);
950 }
951
952 //vbf tag
953 fDiphotonEvent->vbfTag = -1;
954 fDiphotonEvent->vbfbdt = -99;
955 if(fApplyVBFTag){
956 fDiphotonEvent->vbfTag = 0;
957 jet1pt_vbf = fDiphotonEvent->jet1pt;
958 jet2pt_vbf = fDiphotonEvent->jet2pt;
959 deltajeteta_vbf = TMath::Abs(fDiphotonEvent->jet1eta - fDiphotonEvent->jet2eta);
960 dijetmass_vbf = fDiphotonEvent->dijetmass;
961 zeppenfeld_vbf = TMath::Abs(fDiphotonEvent->zeppenfeld);
962 dphidijetgg_vbf = TMath::Abs(fDiphotonEvent->dphidijetgg);
963 diphoptOverdiphomass_vbf = fDiphotonEvent->ptgg/fDiphotonEvent->mass;
964 pho1ptOverdiphomass_vbf = phHard->Pt()/fDiphotonEvent->mass;
965 pho2ptOverdiphomass_vbf = phSoft->Pt()/fDiphotonEvent->mass;
966
967 if(jet1 && jet2 && (pho1ptOverdiphomass_vbf > 40./120.) && (pho2ptOverdiphomass_vbf > 30./120.) && (jet1pt_vbf > 30) && (jet2pt_vbf > 20) && (dijetmass_vbf > 250)){
968 fDiphotonEvent->vbfbdt = fMVAVBF.GetMVAbdtValue(jet1pt_vbf,jet2pt_vbf,deltajeteta_vbf,dijetmass_vbf,zeppenfeld_vbf,dphidijetgg_vbf,diphoptOverdiphomass_vbf,pho1ptOverdiphomass_vbf,pho2ptOverdiphomass_vbf);
969
970 if((fDiphotonEvent->vbfbdt>=0.985) && (fDiphotonEvent->vbfbdt<=1)){
971 fDiphotonEvent->vbfTag = 2;
972 }
973 if((fDiphotonEvent->vbfbdt>=0.93) && (fDiphotonEvent->vbfbdt<0.985)){
974 fDiphotonEvent->vbfTag = 1;
975 }
976 }
977 } // End of VBF tag stuff
978
979 // ttH tag stuff
980 fDiphotonEvent->tthTag = -1;
981 if (fApplyTTHTag && phHard && phSoft && selvtx) {
982 ApplyTTHTag(phHard, phSoft, selvtx);
983 }
984
985 //printf("vbfbdt:%f\n",fDiphotonEvent->vbfbdt);
986 if (fWriteDiphotonTree)
987 hCiCTuple->Fill();
988
989 if (fFillVertexTree && phHard && phSoft) {
990 for (UInt_t ivtx = 0; ivtx<fPV->GetEntries(); ++ivtx) {
991 const Vertex *v = fPV->At(ivtx);
992 fDiphotonVtx->SetVars(v,phHard,phSoft,fPFCands,ivtx,fPV->GetEntries(),_decayZ);
993 hVtxTree->Fill();
994 }
995 }
996 }
997
998 if (!fWriteSingleTree)
999 return;
1000
1001 for (UInt_t iph = 0; iph<egcol->GetEntries(); ++iph) {
1002 const Particle *p = 0;
1003 const Photon *ph = 0;
1004 const Electron *ele = 0;
1005 const SuperCluster *sc = 0;
1006 if (fLoopOnGoodElectrons) {
1007 ele = fGoodElectrons->At(iph);
1008 p = ele;
1009 sc = ele->SCluster();
1010 ph = PhotonTools::MatchedPhoton(ele,fPhotons);
1011 }
1012 else {
1013 ph = fPhotons->At(iph);
1014 p = ph;
1015 sc = ph->SCluster();
1016 ele = PhotonTools::MatchedElectron(ph,fGoodElectrons);
1017 }
1018
1019 const DecayParticle *conv = PhotonTools::MatchedConversion(sc,fConversions,bsp,
1020 nhitsbeforevtxmax);
1021 const SuperCluster *pfsc = PhotonTools::MatchedPFSC(sc,fPFPhotons, fElectrons);
1022
1023 if (!fLoopOnGoodElectrons && ph->HasPV()) {
1024 fDiphotonEvent->vtxZ = ph->PV()->Z();
1025 }
1026
1027 const MCParticle *phgen = 0;
1028 if( !fIsData ) {
1029 phgen = PhotonTools::MatchMC(p,fMCParticles,!fApplyElectronVeto);
1030 }
1031
1032 if (fExcludeSinglePrompt && phgen) return;
1033
1034 fDiphotonEvent->mt = -99.;
1035 fDiphotonEvent->cosphimet = -99.;
1036 fDiphotonEvent->mtele = -99.;
1037 fDiphotonEvent->cosphimetele = -99.;
1038
1039 if (ph) {
1040 fDiphotonEvent->cosphimet = TMath::Cos(ph->Phi()-fPFMet->At(0)->Phi());
1041 fDiphotonEvent->mt = TMath::Sqrt(2.0*fPFMet->At(0)->Pt()*ph->Pt()*
1042 (1.0-fDiphotonEvent->cosphimet));
1043 }
1044
1045 if (ele) {
1046 fDiphotonEvent->cosphimetele = TMath::Cos(ele->Phi()-fPFMet->At(0)->Phi());
1047 fDiphotonEvent->mtele = TMath::Sqrt(2.0*fPFMet->At(0)->Pt()*ele->Pt()*
1048 (1.0-fDiphotonEvent->cosphimetele));
1049 }
1050
1051 fSinglePhoton->SetVars(ph,conv,ele,pfsc,phgen,fPhfixph,fPhfixele,fTracks,fPV,fPFCands,rho,fFillClusterArrays,
1052 fElectrons,fConversions,bsp,fApplyElectronVeto);
1053 hCiCTupleSingle->Fill();
1054 }
1055
1056
1057
1058 return;
1059 }
1060
1061 //--------------------------------------------------------------------------------------------------
1062 void PhotonTreeWriter::SlaveBegin()
1063 {
1064 // Run startup code on the computer (slave) doing the actual analysis. Here,
1065 // we just request the photon collection branch.
1066
1067 if( fApplyLeptonTag || fApplyVHLepTag ) {
1068 ReqEventObject(fLeptonTagElectronsName, fLeptonTagElectrons, false);
1069 ReqEventObject(fLeptonTagMuonsName, fLeptonTagMuons, false);
1070 }
1071
1072 if( fApplyVHLepTag ) {
1073 ReqEventObject(fLeptonTagSoftElectronsName, fLeptonTagSoftElectrons, false);
1074 ReqEventObject(fLeptonTagSoftMuonsName, fLeptonTagSoftMuons, false);
1075 }
1076
1077 // ReqEventObject(fPFNoPileUpName, fPFNoPileUpCands, false);
1078 // ReqEventObject(fPFPileUpName, fPFPileUpCands, false);
1079
1080 ReqEventObject(fPhotonBranchName,fPhotons, fPhotonsFromBranch);
1081 if (fEnablePFPhotons) ReqEventObject(fPFPhotonName,fPFPhotons, true);
1082 ReqEventObject(fTrackBranchName, fTracks, true);
1083 ReqEventObject(fElectronName, fElectrons, true);
1084 ReqEventObject(fGoodElectronName,fGoodElectrons,fGoodElectronsFromBranch);
1085 ReqEventObject(fPileUpDenName, fPileUpDen, true);
1086 ReqEventObject(fPVName, fPV, fPVFromBranch);
1087 ReqEventObject(fConversionName, fConversions, true);
1088 if ( fDoSynching ) ReqEventObject(fPFConversionName, fPFConversions, true);
1089 ReqEventObject(fBeamspotName, fBeamspot, true);
1090 ReqEventObject(fPFCandName, fPFCands, true);
1091 ReqEventObject(fSuperClusterName,fSuperClusters,true);
1092 ReqEventObject(fPFMetName, fPFMet, true);
1093 if (fEnableJets){
1094 ReqEventObject(fPFJetName, fPFJets, fPFJetsFromBranch);
1095 ReqBranch(funcorrPFJetName, funcorrPFJets);
1096 // if (!fIsData) ReqEventObject(fGenJetName, fGenJets, true);
1097 }
1098 if (!fIsData) {
1099 ReqBranch(fPileUpName, fPileUp);
1100 ReqBranch(fMCParticleName, fMCParticles);
1101 ReqBranch(fMCEventInfoName, fMCEventInfo);
1102 if (fEnableGenJets) ReqEventObject(fGenJetName, fGenJets, true);
1103 }
1104 if (fIsData) {
1105 fPhFixDataFile = gSystem->Getenv("CMSSW_BASE") +
1106 TString("/src/MitPhysics/data/PhotonFixGRPV22.dat");
1107 }
1108 else {
1109 fPhFixDataFile = gSystem->Getenv("CMSSW_BASE") +
1110 TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat");
1111 }
1112
1113 fPhfixph.initialise("4_2",std::string(fPhFixDataFile));
1114 fPhfixele.initialise("4_2e",std::string(fPhFixDataFile));
1115
1116 // fMVAMet.Initialize(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_lowpt.weights.xml"))),
1117 // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_highpt.weights.xml"))),
1118 // TString(getenv("CMSSW_BASE")+string("/src/MitPhysics/Utils/python/JetIdParams_cfi.py")),
1119 // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmet_42.root"))),
1120 // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetphi_42.root"))),
1121 // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetu1_42.root"))),
1122 // TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetu2_42.root")))
1123 // );
1124
1125 fMVAMet.Initialize(TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_lowpt.weights.xml"))),
1126 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_highpt.weights.xml"))),
1127 TString(getenv("CMSSW_BASE")+string("/src/MitPhysics/Utils/python/JetIdParams_cfi.py")),
1128 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmet_52.root"))),
1129 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetphi_52.root"))),
1130 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetu1cov_52.root"))),
1131 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/gbrmetu2cov_52.root")))
1132 );
1133
1134 fJetId.Initialize(JetIDMVA::kMedium,
1135 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_lowpt.weights.xml"))),
1136 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/data/mva_JetID_highpt.weights.xml"))),
1137 JetIDMVA::kCut,
1138 TString((getenv("CMSSW_BASE")+string("/src/MitPhysics/Utils/python/JetIdParams_cfi.py")))
1139
1140 );
1141
1142 fMVAVBF.InitializeMVA();
1143
1144
1145 if( fDoSynching ) {
1146 fVtxTools.InitP(2);
1147 fElectronIDMVA = new ElectronIDMVA();
1148 fElectronIDMVA->Initialize("BDTG method",
1149 fElectronMVAWeights_Subdet0Pt10To20,
1150 fElectronMVAWeights_Subdet1Pt10To20,
1151 fElectronMVAWeights_Subdet2Pt10To20,
1152 fElectronMVAWeights_Subdet0Pt20ToInf,
1153 fElectronMVAWeights_Subdet1Pt20ToInf,
1154 fElectronMVAWeights_Subdet2Pt20ToInf,
1155 ElectronIDMVA::kIDEGamma2012NonTrigV1,
1156 fTheRhoType);
1157 }
1158
1159
1160 fDiphotonEvent = new PhotonTreeWriterDiphotonEvent;
1161 fSinglePhoton = new PhotonTreeWriterPhoton<16>;
1162
1163 fTmpFile = TFile::Open(TString::Format("%s_tmp.root",GetName()),"RECREATE");
1164
1165 if (fWriteDiphotonTree) {
1166 hCiCTuple = new TTree(fTupleName.Data(),fTupleName.Data());
1167 hCiCTuple->SetAutoSave(300e9);
1168 }
1169 TString singlename = fTupleName + TString("Single");
1170 if (fWriteSingleTree) {
1171 hCiCTupleSingle = new TTree(singlename,singlename);
1172 hCiCTupleSingle->SetAutoSave(300e9);
1173 }
1174
1175 //make flattish tree from classes so we don't have to rely on dictionaries for reading later
1176 TClass *eclass = TClass::GetClass("mithep::PhotonTreeWriterDiphotonEvent");
1177 TClass *pclass = TClass::GetClass("mithep::PhotonTreeWriterPhoton<16>");
1178 TList *elist = eclass->GetListOfDataMembers();
1179 TList *plist = pclass->GetListOfDataMembers();
1180
1181 for (int i=0; i<elist->GetEntries(); ++i) {
1182 const TDataMember *tdm = static_cast<const TDataMember*>(elist->At(i));//ming
1183 if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
1184 TString typestring;
1185 if (TString(tdm->GetTypeName()).BeginsWith("Char_t")) typestring = "B";
1186 else if (TString(tdm->GetTypeName()).BeginsWith("UChar_t")) typestring = "b";
1187 else if (TString(tdm->GetTypeName()).BeginsWith("Short_t")) typestring = "S";
1188 else if (TString(tdm->GetTypeName()).BeginsWith("UShort_t")) typestring = "s";
1189 else if (TString(tdm->GetTypeName()).BeginsWith("Int_t")) typestring = "I";
1190 else if (TString(tdm->GetTypeName()).BeginsWith("UInt_t")) typestring = "i";
1191 else if (TString(tdm->GetTypeName()).BeginsWith("Float_t")) typestring = "F";
1192 else if (TString(tdm->GetTypeName()).BeginsWith("Double_t")) typestring = "D";
1193 else if (TString(tdm->GetTypeName()).BeginsWith("Long64_t")) typestring = "L";
1194 else if (TString(tdm->GetTypeName()).BeginsWith("ULong64_t")) typestring = "l";
1195 else if (TString(tdm->GetTypeName()).BeginsWith("Bool_t")) typestring = "O";
1196 else continue;
1197 //printf("%s %s: %i\n",tdm->GetTypeName(),tdm->GetName(),int(tdm->GetOffset()));
1198 Char_t *addr = (Char_t*)fDiphotonEvent;//ming:?
1199 assert(sizeof(Char_t)==1);
1200 if (fWriteDiphotonTree) hCiCTuple->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
1201 if (fWriteSingleTree) hCiCTupleSingle->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
1202 }
1203
1204 for (int iph=0; iph<2; ++iph) {
1205 for (int i=0; i<plist->GetEntries(); ++i) {
1206 const TDataMember *tdm = static_cast<const TDataMember*>(plist->At(i));
1207 if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
1208 TString typestring;
1209 if (TString(tdm->GetTypeName()).BeginsWith("Char_t")) typestring = "B";
1210 else if (TString(tdm->GetTypeName()).BeginsWith("UChar_t")) typestring = "b";
1211 else if (TString(tdm->GetTypeName()).BeginsWith("Short_t")) typestring = "S";
1212 else if (TString(tdm->GetTypeName()).BeginsWith("UShort_t")) typestring = "s";
1213 else if (TString(tdm->GetTypeName()).BeginsWith("Int_t")) typestring = "I";
1214 else if (TString(tdm->GetTypeName()).BeginsWith("UInt_t")) typestring = "i";
1215 else if (TString(tdm->GetTypeName()).BeginsWith("Float_t")) typestring = "F";
1216 else if (TString(tdm->GetTypeName()).BeginsWith("Double_t")) typestring = "D";
1217 else if (TString(tdm->GetTypeName()).BeginsWith("Long64_t")) typestring = "L";
1218 else if (TString(tdm->GetTypeName()).BeginsWith("ULong64_t")) typestring = "l";
1219 else if (TString(tdm->GetTypeName()).BeginsWith("Bool_t")) typestring = "O";
1220 else continue;
1221 //printf("%s\n",tdm->GetTypeName());
1222 TString varname = TString::Format("ph%d.%s",iph+1,tdm->GetName());
1223 if (tdm->GetArrayDim()==1) {
1224 varname = TString::Format("%s[%i]",varname.Data(),tdm->GetMaxIndex(0));
1225 }
1226
1227 //printf("typename = %s, arraydim = %i, arraysize = %i,varname = %s\n", tdm->GetTypeName(), tdm->GetArrayDim(), tdm->GetMaxIndex(0), varname.Data());
1228
1229 Char_t *addr = (Char_t*)&fDiphotonEvent->photons[iph];
1230 assert(sizeof(Char_t)==1);
1231 if (fWriteDiphotonTree) hCiCTuple->Branch(varname,addr+tdm->GetOffset(),TString::Format("%s/%s",varname.Data(),typestring.Data()));
1232
1233 if (iph==0) {
1234 TString singlename = TString::Format("ph.%s",tdm->GetName());
1235 if (tdm->GetArrayDim()==1) {
1236 singlename = TString::Format("%s[%i]",singlename.Data(),tdm->GetMaxIndex(0));
1237 }
1238 Char_t *addrsingle = (Char_t*)fSinglePhoton;
1239 if (fWriteSingleTree) hCiCTupleSingle->Branch(singlename,addrsingle+tdm->GetOffset(),TString::Format("%s/%s",singlename.Data(),typestring.Data()));
1240 }
1241 }
1242 }
1243
1244 if (fWriteDiphotonTree)
1245 AddOutput(hCiCTuple);
1246 if (fWriteSingleTree)
1247 AddOutput(hCiCTupleSingle);
1248
1249 if (fFillVertexTree) {
1250 fDiphotonVtx = new PhotonTreeWriterVtx;
1251 hVtxTree = new TTree("hVtxTree","hVtxTree");
1252 hVtxTree->SetAutoSave(300e9);
1253 AddOutput(hVtxTree);
1254
1255 TClass *vclass = TClass::GetClass("mithep::PhotonTreeWriterVtx");
1256 TList *vlist = vclass->GetListOfDataMembers();
1257
1258 for (int i=0; i<vlist->GetEntries(); ++i) {
1259 const TDataMember *tdm = static_cast<const TDataMember*>(vlist->At(i));
1260 if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
1261 TString typestring;
1262 if (TString(tdm->GetTypeName()).BeginsWith("Char_t")) typestring = "B";
1263 else if (TString(tdm->GetTypeName()).BeginsWith("UChar_t")) typestring = "b";
1264 else if (TString(tdm->GetTypeName()).BeginsWith("Short_t")) typestring = "S";
1265 else if (TString(tdm->GetTypeName()).BeginsWith("UShort_t")) typestring = "s";
1266 else if (TString(tdm->GetTypeName()).BeginsWith("Int_t")) typestring = "I";
1267 else if (TString(tdm->GetTypeName()).BeginsWith("UInt_t")) typestring = "i";
1268 else if (TString(tdm->GetTypeName()).BeginsWith("Float_t")) typestring = "F";
1269 else if (TString(tdm->GetTypeName()).BeginsWith("Double_t")) typestring = "D";
1270 else if (TString(tdm->GetTypeName()).BeginsWith("Long64_t")) typestring = "L";
1271 else if (TString(tdm->GetTypeName()).BeginsWith("ULong64_t")) typestring = "l";
1272 else if (TString(tdm->GetTypeName()).BeginsWith("Bool_t")) typestring = "O";
1273 else continue;
1274 //printf("%s %s: %i\n",tdm->GetTypeName(),tdm->GetName(),int(tdm->GetOffset()));
1275 Char_t *addr = (Char_t*)fDiphotonVtx;
1276 assert(sizeof(Char_t)==1);
1277 hVtxTree->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
1278 }
1279 }
1280
1281 }
1282
1283 // ----------------------------------------------------------------------------------------
1284 // some helpfer functions....
1285 void PhotonTreeWriter::FindHiggsPtAndZ(Float_t& pt, Float_t& decayZ, Float_t& mass)
1286 {
1287 pt = -999.;
1288 decayZ = -999.;
1289 mass = -999.;
1290
1291 // loop over all GEN particles and look for status 1 photons
1292 for(UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
1293 const MCParticle* p = fMCParticles->At(i);
1294 if (p->Is(MCParticle::kH) || (!fApplyElectronVeto &&
1295 (p->AbsPdgId()==23 || p->AbsPdgId()==24))) {
1296 pt = p->Pt();
1297 decayZ = p->DecayVertex().Z();
1298 mass = p->Mass();
1299 break;
1300 }
1301 }
1302
1303 return;
1304 }
1305
1306
1307 Float_t PhotonTreeWriter::GetEventCat(PhotonTools::CiCBaseLineCats cat1,
1308 PhotonTools::CiCBaseLineCats cat2) {
1309
1310 bool ph1IsEB = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat2);
1311 bool ph2IsEB = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat2);
1312
1313 bool ph1IsHR9 = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat3);
1314 bool ph2IsHR9 = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat3);
1315
1316 if( ph1IsEB && ph2IsEB )
1317 return ( ph1IsHR9 && ph2IsHR9 ? 0. : 1.);
1318
1319 return ( ph1IsHR9 && ph2IsHR9 ? 2. : 3.);
1320 }
1321
1322 template <int NClus>
1323 void PhotonTreeWriterPhoton<NClus>::SetVars(const Photon *p, const DecayParticle *c, const Electron *ele,
1324 const SuperCluster *pfsc, const MCParticle *m,
1325 PhotonFix &phfixph, PhotonFix &phfixele,
1326 const TrackCol* trackCol,const VertexCol* vtxCol,
1327 const PFCandidateCol* fPFCands,
1328 Double_t rho,
1329 Bool_t fillclusterarrays,
1330 const ElectronCol* els, const DecayParticleCol *convs, const BaseVertex *bs, Bool_t applyElectronVeto, const Vertex* realVtx) {
1331
1332 const SuperCluster *s = 0;
1333 if (p)
1334 s = p->SCluster();
1335 else
1336 s = ele->SCluster();
1337 const BasicCluster *b = s->Seed();
1338 const BasicCluster *b2 = 0;
1339 Double_t ebcmax = -99.;
1340 for (UInt_t i=0; i<s->ClusterSize(); ++i) {
1341 const BasicCluster *bc = s->Cluster(i);
1342 if (bc->Energy() > ebcmax && bc !=b) {
1343 b2 = bc;
1344 ebcmax = bc->Energy();
1345 }
1346 }
1347
1348 const BasicCluster *bclast = 0;
1349 Double_t ebcmin = 1e6;
1350 for (UInt_t i=0; i<s->ClusterSize(); ++i) {
1351 const BasicCluster *bc = s->Cluster(i);
1352 if (bc->Energy() < ebcmin && bc !=b) {
1353 bclast = bc;
1354 ebcmin = bc->Energy();
1355 }
1356 }
1357
1358 const BasicCluster *bclast2 = 0;
1359 ebcmin = 1e6;
1360 for (UInt_t i=0; i<s->ClusterSize(); ++i) {
1361 const BasicCluster *bc = s->Cluster(i);
1362 if (bc->Energy() < ebcmin && bc !=b && bc!=bclast) {
1363 bclast2 = bc;
1364 ebcmin = bc->Energy();
1365 }
1366 }
1367
1368 if (p) {
1369 hasphoton = kTRUE;
1370 e = p->E();
1371 pt = p->Pt();
1372 eta = p->Eta();
1373 phi = p->Phi();
1374 r9 = p->R9();
1375 e3x3 = p->E33();
1376 e5x5 = p->E55();
1377 hovere = p->HadOverEm();
1378 hoveretower = p->HadOverEmTow();
1379 sigietaieta = p->CoviEtaiEta();
1380 phcat = PhotonTools::CiCBaseLineCat(p);
1381 eerr = p->EnergyErr();
1382 eerrsmeared = p->EnergyErrSmeared();
1383 esmearing = p->EnergySmearing();
1384 idmva = p->IdMva();
1385 hcalisodr03 = p->HcalTowerSumEtDr03();
1386 ecalisodr03 = p->EcalRecHitIsoDr03();
1387 trkisohollowdr03 = p->HollowConeTrkIsoDr03();
1388 hcalisodr04 = p->HcalTowerSumEtDr04();
1389 ecalisodr04 = p->EcalRecHitIsoDr04();
1390 trkisohollowdr04 = p->HollowConeTrkIsoDr04();
1391
1392 passeleveto = PhotonTools::PassElectronVetoConvRecovery(p, els, convs, bs);
1393
1394 const Vertex *vtx = vtxCol->At(0);
1395 if (p->HasPV()) vtx = p->PV();
1396 if ( realVtx ) vtx = realVtx;
1397
1398 UInt_t wVtxInd = 0;
1399
1400 trackiso1 = IsolationTools::CiCTrackIsolation(p,vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0,
1401 trackCol, NULL, NULL,
1402 (!applyElectronVeto ? els : NULL) );
1403 //Question Ming:whyfPV->At(0) instead of selected vertex using ranking method?
1404
1405 // track iso worst vtx
1406 trackiso2 = IsolationTools::CiCTrackIsolation(p,vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0,
1407 trackCol, &wVtxInd,vtxCol,
1408 (!applyElectronVeto ? els : NULL) );
1409 combiso1 = ecalisodr03+hcalisodr04+trackiso1 - 0.17*rho;
1410 combiso2 = ecalisodr04+hcalisodr04+trackiso2 - 0.52*rho;
1411
1412
1413 // -----------------------------------------------------
1414 // PF-CiC4 Debug Stuff
1415 std::vector<double> debugVals;
1416 PhotonTools::PassCiCPFIsoSelection(p, vtx, fPFCands, vtxCol, rho, 20., &debugVals);
1417 if( debugVals.size() == 13 ) {
1418 pfcic4_tIso1 = debugVals[0];
1419 pfcic4_tIso2 = debugVals[1];
1420 pfcic4_tIso3 = debugVals[2];
1421 pfcic4_covIEtaIEta = debugVals[3];
1422 pfcic4_HoE = debugVals[4];
1423 pfcic4_R9 = debugVals[5];
1424 pfcic4_wVtxInd = debugVals[6];
1425 pfcic4_ecalIso3 = debugVals[7];
1426 pfcic4_ecalIso4 = debugVals[8];
1427 pfcic4_trackIsoSel03 = debugVals[9];
1428 pfcic4_trackIsoWorst04 = debugVals[10];
1429 pfcic4_combIso1 = debugVals[11];
1430 pfcic4_combIso2 = debugVals[12];
1431 }
1432 // -----------------------------------------------------
1433 //id mva
1434 //2011
1435 idmva_tIso1abs=combiso1;
1436 idmva_tIso2abs=combiso2;
1437 idmva_tIso3abs=trackiso1;
1438 idmva_absIsoEcal=ecalisodr03;
1439 idmva_absIsoHcal=hcalisodr04;
1440 //2012
1441 idmva_CoviEtaiPhi=p->SCluster()->Seed()->CoviEtaiPhi();
1442 idmva_s4ratio=p->S4Ratio();
1443 idmva_GammaIso=IsolationTools::PFGammaIsolation(p,0.3,0,fPFCands);
1444 idmva_ChargedIso_selvtx=IsolationTools::PFChargedIsolation(p,vtx,0.3,0.,fPFCands);
1445 idmva_ChargedIso_0p2_selvtx=IsolationTools::PFChargedIsolation(p,vtx,0.2,0.,fPFCands);
1446 idmva_ChargedIso_worstvtx=IsolationTools::PFChargedIsolation(p,vtx,0.3,0.,fPFCands,&wVtxInd,vtxCol);
1447 idmva_PsEffWidthSigmaRR=p->EffSigmaRR();
1448 }
1449 else {
1450 hasphoton = kFALSE;
1451 e = -99.;
1452 pt = -99.;
1453 eta = -99.;
1454 phi = -99.;
1455 r9 = b->E3x3()/s->RawEnergy();
1456 e3x3 = b->E3x3();
1457 e5x5 = b->E5x5();
1458 hovere = ele->HadronicOverEm();
1459 sigietaieta = ele->CoviEtaiEta();
1460 phcat = -99;
1461 eerr = -99.;
1462 eerrsmeared = -99.;
1463 esmearing = 0.;
1464 idmva = -99.;
1465 hcalisodr03 = -99;
1466 ecalisodr03 = -99;
1467 trkisohollowdr03 = -99;
1468 hcalisodr04 = -99;
1469 ecalisodr04 = -99;
1470 trkisohollowdr04 = -99;
1471 trackiso1 = -99.;
1472 trackiso2 = -99.;
1473 combiso1 = -99.;
1474 combiso2 = -99.;
1475 }
1476
1477 sce = s->Energy();
1478 scrawe = s->RawEnergy();
1479 scpse = s->PreshowerEnergy();
1480 scpssigmaxx = s->PsEffWidthSigmaXX();
1481 scpssigmayy = s->PsEffWidthSigmaYY();
1482 sceta = s->Eta();
1483 scphi = s->Phi();
1484 scnclusters = s->ClusterSize();
1485 scnhits = s->NHits();
1486 scetawidth = -99.;
1487 scphiwidth = -99.;
1488 if (p) {
1489 scetawidth = p->EtaWidth();
1490 scphiwidth = p->PhiWidth();
1491 }
1492 else {
1493 scetawidth = s->EtaWidth();
1494 scphiwidth = s->PhiWidth();
1495 }
1496 isbarrel = (s->AbsEta()<1.5);
1497 isr9reco = (isbarrel && r9>0.94) || (!isbarrel && r9>0.95);
1498 isr9cat = (r9>0.94);
1499
1500 eseed = b->Energy();
1501 etaseed = b->Eta();
1502 phiseed = b->Phi();
1503 ietaseed = b->IEta();
1504 iphiseed = b->IPhi();
1505 ixseed = b->IX();
1506 iyseed = b->IY();
1507 etacryseed = b->EtaCry();
1508 phicryseed = b->PhiCry();
1509 xcryseed = b->XCry();
1510 ycryseed = b->YCry();
1511 thetaaxisseed = b->ThetaAxis();
1512 phiaxisseed = b->PhiAxis();
1513 sigietaietaseed = TMath::Sqrt(b->CoviEtaiEta());
1514 sigiphiphiseed = TMath::Sqrt(b->CoviPhiiPhi());
1515 if (isnan(sigiphiphiseed)) sigiphiphiseed = -99.;
1516 covietaiphiseed = b->CoviEtaiPhi();
1517 if (isnan(covietaiphiseed)) covietaiphiseed = -99.;
1518 e3x3seed = b->E3x3();
1519 e5x5seed = b->E5x5();
1520 emaxseed = b->EMax();
1521 e2ndseed = b->E2nd();
1522 etopseed = b->ETop();
1523 ebottomseed = b->EBottom();
1524 eleftseed = b->ELeft();
1525 erightseed = b->ERight();
1526 e1x3seed = b->E1x3();
1527 e3x1seed = b->E3x1();
1528 e1x5seed = b->E1x5();
1529 e2x2seed = b->E2x2();
1530 e4x4seed = b->E4x4();
1531 e2x5maxseed = b->E2x5Max();
1532 e2x5topseed = b->E2x5Top();
1533 e2x5bottomseed = b->E2x5Bottom();
1534 e2x5leftseed = b->E2x5Left();
1535 e2x5rightseed = b->E2x5Right();
1536 xseedseed = b->Pos().X();
1537 yseedseed = b->Pos().Y();
1538 zseedseed = b->Pos().Z();
1539 nhitsseed = b->NHits();
1540
1541 if (b2) {
1542 ebc2 = b2->Energy();
1543 etabc2 = b2->Eta();
1544 phibc2 = b2->Phi();
1545 ietabc2 = b2->IEta();
1546 iphibc2 = b2->IPhi();
1547 ixbc2 = b2->IX();
1548 iybc2 = b2->IY();
1549 etacrybc2 = b2->EtaCry();
1550 phicrybc2 = b2->PhiCry();
1551 xcrybc2 = b2->XCry();
1552 ycrybc2 = b2->YCry();
1553 thetaaxisbc2 = b2->ThetaAxis();
1554 phiaxisbc2 = b2->PhiAxis();
1555 sigietaietabc2 = TMath::Sqrt(b2->CoviEtaiEta());
1556 sigiphiphibc2 = TMath::Sqrt(b2->CoviPhiiPhi());
1557 if (isnan(sigiphiphibc2)) sigiphiphibc2 = -99.;
1558 covietaiphibc2 = b2->CoviEtaiPhi();
1559 if (isnan(covietaiphibc2)) covietaiphibc2 = -99.;
1560 e3x3bc2 = b2->E3x3();
1561 e5x5bc2 = b2->E5x5();
1562 emaxbc2 = b2->EMax();
1563 e2ndbc2 = b2->E2nd();
1564 etopbc2 = b2->ETop();
1565 ebottombc2 = b2->EBottom();
1566 eleftbc2 = b2->ELeft();
1567 erightbc2 = b2->ERight();
1568 e1x3bc2 = b2->E1x3();
1569 e3x1bc2 = b2->E3x1();
1570 e1x5bc2 = b2->E1x5();
1571 e2x2bc2 = b2->E2x2();
1572 e4x4bc2 = b2->E4x4();
1573 e2x5maxbc2 = b2->E2x5Max();
1574 e2x5topbc2 = b2->E2x5Top();
1575 e2x5bottombc2 = b2->E2x5Bottom();
1576 e2x5leftbc2 = b2->E2x5Left();
1577 e2x5rightbc2 = b2->E2x5Right();
1578 xbc2bc2 = b2->Pos().X();
1579 ybc2bc2 = b2->Pos().Y();
1580 zbc2bc2 = b2->Pos().Z();
1581 nhitsbc2= b2->NHits();
1582 }
1583 else {
1584 ebc2 = 0;
1585 etabc2 = 0;
1586 phibc2 = 0;
1587 ietabc2 = 0;
1588 iphibc2 = 0;
1589 ixbc2 = 0;
1590 iybc2 = 0;
1591 etacrybc2 = 0;
1592 phicrybc2 = 0;
1593 xcrybc2 = 0;
1594 ycrybc2 = 0;
1595 thetaaxisbc2 = 0;
1596 phiaxisbc2 = 0;
1597 sigietaietabc2 = 0;
1598 sigiphiphibc2 = 0;
1599 covietaiphibc2 = 0;
1600 e3x3bc2 = 0;
1601 e5x5bc2 = 0;
1602 emaxbc2 = 0;
1603 e2ndbc2 = 0;
1604 etopbc2 = 0;
1605 ebottombc2 = 0;
1606 eleftbc2 = 0;
1607 erightbc2 = 0;
1608 e1x3bc2 = 0;
1609 e3x1bc2 = 0;
1610 e1x5bc2 = 0;
1611 e2x2bc2 = 0;
1612 e4x4bc2 = 0;
1613 e2x5maxbc2 = 0;
1614 e2x5topbc2 = 0;
1615 e2x5bottombc2 = 0;
1616 e2x5leftbc2 = 0;
1617 e2x5rightbc2 = 0;
1618 xbc2bc2 = 0;
1619 ybc2bc2 = 0;
1620 zbc2bc2 = 0;
1621 nhitsbc2 = 0;
1622 }
1623
1624 if (bclast) {
1625 ebclast = bclast->Energy();
1626 etabclast = bclast->Eta();
1627 phibclast = bclast->Phi();
1628 ietabclast = bclast->IEta();
1629 iphibclast = bclast->IPhi();
1630 ixbclast = bclast->IX();
1631 iybclast = bclast->IY();
1632 etacrybclast = bclast->EtaCry();
1633 phicrybclast = bclast->PhiCry();
1634 xcrybclast = bclast->XCry();
1635 ycrybclast = bclast->YCry();
1636 thetaaxisbclast = bclast->ThetaAxis();
1637 phiaxisbclast = bclast->PhiAxis();
1638 sigietaietabclast = TMath::Sqrt(bclast->CoviEtaiEta());
1639 sigiphiphibclast = TMath::Sqrt(bclast->CoviPhiiPhi());
1640 if (isnan(sigiphiphibclast)) sigiphiphibclast = -99.;
1641 covietaiphibclast = bclast->CoviEtaiPhi();
1642 if (isnan(covietaiphibclast)) covietaiphibclast = -99.;
1643 e3x3bclast = bclast->E3x3();
1644 nhitsbclast = bclast->NHits();
1645 }
1646 else {
1647 ebclast = 0;
1648 etabclast = 0;
1649 phibclast = 0;
1650 ietabclast = 0;
1651 iphibclast = 0;
1652 ixbclast = 0;
1653 iybclast = 0;
1654 etacrybclast = 0;
1655 phicrybclast = 0;
1656 xcrybclast = 0;
1657 ycrybclast = 0;
1658 thetaaxisbclast = 0;
1659 phiaxisbclast = 0;
1660 sigietaietabclast = 0;
1661 sigiphiphibclast = 0;
1662 covietaiphibclast = 0;
1663 e3x3bclast = 0;
1664 nhitsbclast = 0;
1665 }
1666
1667 if (bclast2) {
1668 ebclast2 = bclast2->Energy();
1669 etabclast2 = bclast2->Eta();
1670 phibclast2 = bclast2->Phi();
1671 ietabclast2 = bclast2->IEta();
1672 iphibclast2 = bclast2->IPhi();
1673 ixbclast2 = bclast2->IX();
1674 iybclast2 = bclast2->IY();
1675 etacrybclast2 = bclast2->EtaCry();
1676 phicrybclast2 = bclast2->PhiCry();
1677 xcrybclast2 = bclast2->XCry();
1678 ycrybclast2 = bclast2->YCry();
1679 thetaaxisbclast2 = bclast2->ThetaAxis();
1680 phiaxisbclast2 = bclast2->PhiAxis();
1681 sigietaietabclast2 = TMath::Sqrt(bclast2->CoviEtaiEta());
1682 sigiphiphibclast2 = TMath::Sqrt(bclast2->CoviPhiiPhi());
1683 if (isnan(sigiphiphibclast2)) sigiphiphibclast2 = -99.;
1684 covietaiphibclast2 = bclast2->CoviEtaiPhi();
1685 if (isnan(covietaiphibclast2)) covietaiphibclast2 = -99.;
1686 e3x3bclast2 = bclast2->E3x3();
1687 nhitsbclast2 = bclast2->NHits();
1688 }
1689 else {
1690 ebclast2 = 0;
1691 etabclast2 = 0;
1692 phibclast2 = 0;
1693 ietabclast2 = 0;
1694 iphibclast2 = 0;
1695 ixbclast2 = 0;
1696 iybclast2 = 0;
1697 etacrybclast2 = 0;
1698 phicrybclast2 = 0;
1699 xcrybclast2 = 0;
1700 ycrybclast2 = 0;
1701 thetaaxisbclast2 = 0;
1702 phiaxisbclast2 = 0;
1703 sigietaietabclast2 = 0;
1704 sigiphiphibclast2 = 0;
1705 covietaiphibclast2 = 0;
1706 e3x3bclast2 = 0;
1707 nhitsbclast2 = 0;
1708 }
1709
1710 for (UInt_t iclus=0; iclus<NClus; ++iclus) {
1711 if (fillclusterarrays && iclus < s->ClusterSize() ) {
1712 const BasicCluster *ib =s->Cluster(iclus);
1713
1714 ebcs[iclus] = ib->Energy();
1715 etabcs[iclus] = ib->Eta();
1716 phibcs[iclus] = ib->Phi();
1717 ietabcs[iclus] = ib->IEta();
1718 iphibcs[iclus] = ib->IPhi();
1719 ixbcs[iclus] = ib->IX();
1720 iybcs[iclus] = ib->IY();
1721 etacrybcs[iclus] = ib->EtaCry();
1722 phicrybcs[iclus] = ib->PhiCry();
1723 xcrybcs[iclus] = ib->XCry();
1724 ycrybcs[iclus] = ib->YCry();
1725 sigietaietabcs[iclus] = TMath::Sqrt(ib->CoviEtaiEta());
1726 sigiphiphibcs[iclus] = TMath::Sqrt(ib->CoviPhiiPhi());
1727 covietaiphibcs[iclus] = ib->CoviEtaiPhi();
1728 sigetaetabcs[iclus] = TMath::Sqrt(ib->CovEtaEta());
1729 sigphiphibcs[iclus] = TMath::Sqrt(ib->CovPhiPhi());
1730 covetaphibcs[iclus] = ib->CovEtaPhi();
1731 e3x3bcs[iclus] = ib->E3x3();
1732 e5x5bcs[iclus] = ib->E5x5();
1733 emaxbcs[iclus] = ib->EMax();
1734 e2ndbcs[iclus] = ib->E2nd();
1735 etopbcs[iclus] = ib->ETop();
1736 ebottombcs[iclus] = ib->EBottom();
1737 eleftbcs[iclus] = ib->ELeft();
1738 erightbcs[iclus] = ib->ERight();
1739 e1x3bcs[iclus] = ib->E1x3();
1740 e3x1bcs[iclus] = ib->E3x1();
1741 e1x5bcs[iclus] = ib->E1x5();
1742 e2x2bcs[iclus] = ib->E2x2();
1743 e4x4bcs[iclus] = ib->E4x4();
1744 e2x5maxbcs[iclus] = ib->E2x5Max();
1745 e2x5topbcs[iclus] = ib->E2x5Top();
1746 e2x5bottombcs[iclus] = ib->E2x5Bottom();
1747 e2x5leftbcs[iclus] = ib->E2x5Left();
1748 e2x5rightbcs[iclus] = ib->E2x5Right();
1749 nhitsbcs[iclus]= ib->NHits();
1750 }
1751 else {
1752 ebcs[iclus] = -999;
1753 etabcs[iclus] = -999;
1754 phibcs[iclus] = -999;
1755 ietabcs[iclus] = -999;
1756 iphibcs[iclus] = -999;
1757 ixbcs[iclus] = -999;
1758 iybcs[iclus] = -999;
1759 etacrybcs[iclus] = -999;
1760 phicrybcs[iclus] = -999;
1761 xcrybcs[iclus] = -999;
1762 ycrybcs[iclus] = -999;
1763 sigietaietabcs[iclus] = -999;
1764 sigiphiphibcs[iclus] = -999;
1765 covietaiphibcs[iclus] = -999;
1766 sigetaetabcs[iclus] = -999;
1767 sigphiphibcs[iclus] = -999;
1768 covetaphibcs[iclus] = -999;
1769 e3x3bcs[iclus] = -999;
1770 e5x5bcs[iclus] = -999;
1771 emaxbcs[iclus] = -999;
1772 e2ndbcs[iclus] = -999;
1773 etopbcs[iclus] = -999;
1774 ebottombcs[iclus] = -999;
1775 eleftbcs[iclus] = -999;
1776 erightbcs[iclus] = -999;
1777 e1x3bcs[iclus] = -999;
1778 e3x1bcs[iclus] = -999;
1779 e1x5bcs[iclus] = -999;
1780 e2x2bcs[iclus] = -999;
1781 e4x4bcs[iclus] = -999;
1782 e2x5maxbcs[iclus] = -999;
1783 e2x5topbcs[iclus] = -999;
1784 e2x5bottombcs[iclus] = -999;
1785 e2x5leftbcs[iclus] = -999;
1786 e2x5rightbcs[iclus] = -999;
1787 nhitsbcs[iclus] = -999;
1788 }
1789 }
1790
1791 for (UInt_t iclus=0; iclus<NClus; ++iclus) {
1792 if (fillclusterarrays && pfsc && iclus < pfsc->ClusterSize() ) {
1793 const BasicCluster *ib =pfsc->Cluster(iclus);
1794
1795 epfbcs[iclus] = ib->Energy();
1796 etapfbcs[iclus] = ib->Eta();
1797 phipfbcs[iclus] = ib->Phi();
1798 ietapfbcs[iclus] = ib->IEta();
1799 iphipfbcs[iclus] = ib->IPhi();
1800 ixpfbcs[iclus] = ib->IX();
1801 iypfbcs[iclus] = ib->IY();
1802 etacrypfbcs[iclus] = ib->EtaCry();
1803 phicrypfbcs[iclus] = ib->PhiCry();
1804 xcrypfbcs[iclus] = ib->XCry();
1805 ycrypfbcs[iclus] = ib->YCry();
1806 sigietaietapfbcs[iclus] = TMath::Sqrt(ib->CoviEtaiEta());
1807 sigiphiphipfbcs[iclus] = TMath::Sqrt(ib->CoviPhiiPhi());
1808 covietaiphipfbcs[iclus] = ib->CoviEtaiPhi();
1809 sigetaetapfbcs[iclus] = TMath::Sqrt(ib->CovEtaEta());
1810 sigphiphipfbcs[iclus] = TMath::Sqrt(ib->CovPhiPhi());
1811 covetaphipfbcs[iclus] = ib->CovEtaPhi();
1812 e3x3pfbcs[iclus] = ib->E3x3();
1813 e5x5pfbcs[iclus] = ib->E5x5();
1814 emaxpfbcs[iclus] = ib->EMax();
1815 e2ndpfbcs[iclus] = ib->E2nd();
1816 etoppfbcs[iclus] = ib->ETop();
1817 ebottompfbcs[iclus] = ib->EBottom();
1818 eleftpfbcs[iclus] = ib->ELeft();
1819 erightpfbcs[iclus] = ib->ERight();
1820 e1x3pfbcs[iclus] = ib->E1x3();
1821 e3x1pfbcs[iclus] = ib->E3x1();
1822 e1x5pfbcs[iclus] = ib->E1x5();
1823 e2x2pfbcs[iclus] = ib->E2x2();
1824 e4x4pfbcs[iclus] = ib->E4x4();
1825 e2x5maxpfbcs[iclus] = ib->E2x5Max();
1826 e2x5toppfbcs[iclus] = ib->E2x5Top();
1827 e2x5bottompfbcs[iclus] = ib->E2x5Bottom();
1828 e2x5leftpfbcs[iclus] = ib->E2x5Left();
1829 e2x5rightpfbcs[iclus] = ib->E2x5Right();
1830 nhitspfbcs[iclus]= ib->NHits();
1831 }
1832 else {
1833 epfbcs[iclus] = -999;
1834 etapfbcs[iclus] = -999;
1835 phipfbcs[iclus] = -999;
1836 ietapfbcs[iclus] = -999;
1837 iphipfbcs[iclus] = -999;
1838 ixpfbcs[iclus] = -999;
1839 iypfbcs[iclus] = -999;
1840 etacrypfbcs[iclus] = -999;
1841 phicrypfbcs[iclus] = -999;
1842 xcrypfbcs[iclus] = -999;
1843 ycrypfbcs[iclus] = -999;
1844 sigietaietapfbcs[iclus] = -999;
1845 sigiphiphipfbcs[iclus] = -999;
1846 covietaiphipfbcs[iclus] = -999;
1847 sigetaetapfbcs[iclus] = -999;
1848 sigphiphipfbcs[iclus] = -999;
1849 covetaphipfbcs[iclus] = -999;
1850 e3x3pfbcs[iclus] = -999;
1851 e5x5pfbcs[iclus] = -999;
1852 emaxpfbcs[iclus] = -999;
1853 e2ndpfbcs[iclus] = -999;
1854 etoppfbcs[iclus] = -999;
1855 ebottompfbcs[iclus] = -999;
1856 eleftpfbcs[iclus] = -999;
1857 erightpfbcs[iclus] = -999;
1858 e1x3pfbcs[iclus] = -999;
1859 e3x1pfbcs[iclus] = -999;
1860 e1x5pfbcs[iclus] = -999;
1861 e2x2pfbcs[iclus] = -999;
1862 e4x4pfbcs[iclus] = -999;
1863 e2x5maxpfbcs[iclus] = -999;
1864 e2x5toppfbcs[iclus] = -999;
1865 e2x5bottompfbcs[iclus] = -999;
1866 e2x5leftpfbcs[iclus] = -999;
1867 e2x5rightpfbcs[iclus] = -999;
1868 nhitspfbcs[iclus] = -999;
1869 }
1870 }
1871
1872 for (UInt_t iclus=0; iclus<100; ++iclus) {
1873 if (fillclusterarrays && pfsc && iclus < pfsc->NPsClusts() ) {
1874 const PsCluster *ib = pfsc->PsClust(iclus);
1875
1876 epsc[iclus] = ib->Energy();
1877 etapsc[iclus] = ib->Eta();
1878 phipsc[iclus] = ib->Phi();
1879 planepsc[iclus] = ib->PsPlane();
1880 }
1881 else {
1882 epsc[iclus] = -999;
1883 etapsc[iclus] = -999;
1884 phipsc[iclus] = -999;
1885 planepsc[iclus] = 0;
1886 }
1887 }
1888
1889 //initialize photon energy corrections if needed
1890 /*if (!PhotonFix::initialised()) {
1891 PhotonFix::initialise("4_2",std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFix.dat")).Data()));
1892 }*/
1893
1894 phfixph.setup(e,sceta,scphi,r9);
1895 phfixele.setup(e,sceta,scphi,r9);
1896
1897 const Float_t dval = -99.;
1898 ecor = phfixph.fixedEnergy();
1899 ecorerr = phfixph.sigmaEnergy();
1900 ecorele = phfixele.fixedEnergy();
1901 ecoreleerr = phfixele.sigmaEnergy();
1902 if (phfixph.isbarrel()) {
1903 etac = phfixph.etaC();
1904 etas = phfixph.etaS();
1905 etam = phfixph.etaM();
1906 phic = phfixph.phiC();
1907 phis = phfixph.phiS();
1908 phim = phfixph.phiM();
1909 xz = dval;
1910 xc = dval;
1911 xs = dval;
1912 xm = dval;
1913 yz = dval;
1914 yc = dval;
1915 ys = dval;
1916 ym = dval;
1917 }
1918 else {
1919 etac = dval;
1920 etas = dval;
1921 etam = dval;
1922 phic = dval;
1923 phis = dval;
1924 phim = dval;
1925 xz = phfixph.xZ();
1926 xc = phfixph.xC();
1927 xs = phfixph.xS();
1928 xm = phfixph.xM();
1929 yz = phfixph.yZ();
1930 yc = phfixph.yC();
1931 ys = phfixph.yS();
1932 ym = phfixph.yM();
1933 }
1934
1935 if (c) {
1936 hasconversion = kTRUE;
1937 convp = c->P();
1938 convpt = c->Pt();
1939 conveta = c->Eta();
1940 convphi = c->Phi();
1941 ThreeVector dirconvsc = ThreeVector(s->Point()) - c->Position();
1942 convdeta = c->Eta() - dirconvsc.Eta();
1943 convdphi = MathUtils::DeltaPhi(c->Phi(),dirconvsc.Phi());
1944 convvtxrho = c->Position().Rho();
1945 convvtxz = c->Position().Z();
1946 convvtxphi = c->Position().Phi();
1947
1948 const StableData *leadsd = dynamic_cast<const StableData*>(c->DaughterDat(0));
1949 const StableData *trailsd = dynamic_cast<const StableData*>(c->DaughterDat(1));
1950 if (leadsd->Pt()<trailsd->Pt()) {
1951 const StableData *sdtmp = leadsd;
1952 leadsd = trailsd;
1953 trailsd = sdtmp;
1954 }
1955
1956 const Track *leadtrack = dynamic_cast<const StableParticle*>(leadsd->Original())->Trk();
1957 const Track *trailtrack = dynamic_cast<const StableParticle*>(trailsd->Original())->Trk();
1958
1959 convleadpt = leadsd->Pt();
1960 convtrailpt = trailsd->Pt();
1961 convleadtrackpt = leadtrack->Pt();
1962 convleadtrackalgo = leadtrack->Algo();
1963 if (convleadtrackalgo==29) convleadtrackalgos=2; //gsf track
1964 else if (convleadtrackalgo==15 ||convleadtrackalgo==16) convleadtrackalgos=1; //ecal-seeded track
1965 else convleadtrackalgos = 0; //std iterative track
1966 convleadtrackcharge = leadtrack->Charge();
1967 convtrailtrackpt = trailtrack->Pt();
1968 convtrailtrackalgo = trailtrack->Algo();
1969 if (convtrailtrackalgo==29) convtrailtrackalgos=2; //gsf track
1970 else if (convtrailtrackalgo==15 ||convtrailtrackalgo==16) convtrailtrackalgos=1; //ecal-seeded track
1971 else convtrailtrackalgos = 0; //std iterative track
1972 trailtrackcharge = trailtrack->Charge();
1973 }
1974 else {
1975 hasconversion = kFALSE;
1976 convp = -99.;
1977 convpt = -99.;
1978 conveta = -99.;
1979 convphi = -99.;
1980 convdeta = -99.;
1981 convdphi = -99.;
1982 convvtxrho = -99.;
1983 convvtxz = -999.;
1984 convvtxphi = -99.;
1985 convleadpt = -99.;
1986 convtrailpt = -99.;
1987 convleadtrackpt = -99.;
1988 convleadtrackalgo = -99;
1989 convleadtrackalgos = -99;
1990 convleadtrackcharge = 0;
1991 convtrailtrackpt = -99.;
1992 convtrailtrackalgo = -99;
1993 convtrailtrackalgos = -99;
1994 trailtrackcharge = 0;
1995 }
1996
1997 //electron quantities
1998 if (ele) {
1999 haselectron = kTRUE;
2000 eleisecaldriven = ele->IsEcalDriven();
2001 eleistrackerdriven = ele->IsTrackerDriven();
2002 elee = ele->E();
2003 elept = ele->Pt();
2004 eleeta = ele->Eta();
2005 elephi = ele->Phi();
2006 elecharge = ele->Charge();
2007 elefbrem = ele->FBrem();
2008 eledeta = ele->DeltaEtaSuperClusterTrackAtVtx();
2009 eledphi = ele->DeltaPhiSuperClusterTrackAtVtx();
2010 elep = s->Energy()/ele->ESuperClusterOverP();
2011 elepin = ele->PIn();
2012 elepout = ele->POut();
2013 }
2014 else {
2015 haselectron = kFALSE;
2016 eleisecaldriven = kFALSE;
2017 eleistrackerdriven = kFALSE;
2018 elee = -99.;
2019 elept = -99.;
2020 eleeta = -99.;
2021 elephi = -99.;
2022 elecharge = -99;
2023 elefbrem = -99.;
2024 eledeta = -99.;
2025 eledphi = -99.;
2026 elep = -99.;
2027 elepin = -99.;
2028 elepout = -99.;
2029 }
2030
2031 //pf supercluster quantities
2032 if (pfsc) {
2033 haspfsc = kTRUE;
2034 pfsce = pfsc->Energy();
2035 pfscrawe = pfsc->RawEnergy();
2036 pfsceta = pfsc->Eta();
2037 pfscphi = pfsc->Phi();
2038 pfscnclusters = pfsc->NClusters();
2039 pfscnhits = pfsc->NHits();
2040 pfscetawidth = pfsc->EtaWidth();
2041 pfscphiwidth = pfsc->PhiWidth();
2042 pfscnpsclusters = pfsc->NPsClusts();
2043 }
2044 else {
2045 haspfsc = kFALSE;
2046 pfsce = -99.;
2047 pfscrawe = -99.;
2048 pfsceta = -99.;
2049 pfscphi = -99.;
2050 pfscnclusters = 0;
2051 pfscnhits = 0;
2052 pfscetawidth = -99.;
2053 pfscphiwidth = -99.;
2054 pfscnpsclusters = 0;
2055 }
2056
2057 genz = -99.;
2058 if (m) {
2059 ispromptgen = kTRUE;
2060 gene = m->E();
2061 genpt = m->Pt();
2062 geneta = m->Eta();
2063 genphi = m->Phi();
2064 const MCParticle *mm = m->DistinctMother();
2065 if (mm) genz = mm->DecayVertex().Z();
2066 pdgid = m->PdgId();
2067 if (mm) motherpdgid = mm->PdgId();
2068 else motherpdgid = -99;
2069 }
2070 else {
2071 ispromptgen = kFALSE;
2072 gene = -99.;
2073 genpt = -99.;
2074 geneta = -99.;
2075 genphi = -99.;
2076 pdgid = -99;
2077 motherpdgid = -99;
2078 }
2079 }
2080
2081 void PhotonTreeWriterVtx::SetVars(const Vertex *v, const Photon *p1, const Photon *p2, const PFCandidateCol *pfcands, Int_t idx, Int_t numvtx, Float_t genvtxz)
2082 {
2083
2084 //printf("start\n");
2085
2086 n = idx;
2087 nvtx = numvtx;
2088 zgen = genvtxz;
2089
2090 x = v->X();
2091 y = v->Y();
2092 z = v->Z();
2093
2094 Double_t dsumpt = 0.;
2095 Double_t dsumptsq = 0.;
2096
2097 nchalltoward = 0;
2098 nchalltransverse = 0;
2099 nchallaway = 0;
2100 nchcuttoward = 0;
2101 nchcuttransverse = 0;
2102 nchcutaway = 0;
2103
2104 ThreeVector vtxmom;
2105
2106 //printf("mom\n");
2107 FourVectorM diphoton = p1->MomVtx(v->Position()) + p2->MomVtx(v->Position());
2108 //printf("done mom\n");
2109 ptgg = diphoton.Pt();
2110 phigg = diphoton.Phi();
2111 etagg = diphoton.Eta();
2112 mgg = diphoton.M();
2113 pxgg = diphoton.Px();
2114 pygg = diphoton.Py();
2115 pzgg = diphoton.Pz();
2116
2117 //printf("loop\n");
2118
2119 for (UInt_t i = 0; i<pfcands->GetEntries(); ++i) {
2120 const PFCandidate *pfc = pfcands->At(i);
2121 if (pfc->PFType()!=PFCandidate::eHadron || !pfc->HasTrackerTrk()) continue;
2122 if (TMath::Abs( pfc->TrackerTrk()->DzCorrected(*v) ) > 0.2) continue;
2123 if (TMath::Abs( pfc->TrackerTrk()->D0Corrected(*v) ) > 0.1) continue;
2124
2125 vtxmom += ThreeVector(pfc->Px(),pfc->Py(),pfc->Pz());
2126
2127 dsumpt += pfc->Pt();
2128 dsumptsq += pfc->Pt()*pfc->Pt();
2129
2130 Double_t dphi = TMath::Abs(MathUtils::DeltaPhi(*pfc,diphoton));
2131 if (dphi<(TMath::Pi()/3.0)) {
2132 ++nchalltoward;
2133 if (pfc->Pt()>0.5) ++nchcuttoward;
2134 }
2135 else if (dphi>(2.0*TMath::Pi()/3.0)) {
2136 ++nchallaway;
2137 if (pfc->Pt()>0.5) ++nchcutaway;
2138 }
2139 else {
2140 ++nchalltransverse;
2141 if (pfc->Pt()>0.5) ++nchcuttransverse;
2142 }
2143
2144 }
2145
2146 //printf("doneloop\n");
2147
2148
2149 sumpt = dsumpt;
2150 sumptsq = dsumptsq;
2151
2152 pt = vtxmom.Rho();
2153 phi = vtxmom.Phi();
2154 eta = vtxmom.Eta();
2155 px = vtxmom.X();
2156 py = vtxmom.Y();
2157 pz = vtxmom.Z();
2158
2159 //printf("done\n");
2160
2161 return;
2162
2163 }
2164
2165
2166 //_____________________________________________________________________________
2167 void PhotonTreeWriter::ApplyLeptonTag(const Photon *phHard,
2168 const Photon *phSoft,
2169 const Vertex *selvtx)
2170 {
2171 // perform flavor-based lepton tagging (used before the legacy paper of 2013)
2172 // the diphoton event record will have one more entry; i.e. leptonTag
2173 // leptonTag = -1 -> lepton-taggng was swicthed off
2174 // = 0 -> event tagged as 'non-lepton-event'
2175 // = +1 -> event tagged as muon-event
2176 // = +2 -> event tagged as electron-event
2177 fDiphotonEvent->leptonTag = 0;
2178 Int_t closestVtx = 0;
2179 const Muon *muon = GetLeptonTagMuon(phHard, phSoft);
2180 if (muon) {
2181 // muon tagged
2182 fDiphotonEvent->leptonTag = 2;
2183 SetLeptonTagMuonVars(phHard, phSoft, muon);
2184 }
2185
2186 const Electron *electron = 0;
2187 if (fDiphotonEvent->leptonTag < 1) {
2188 electron = GetLeptonTagElectron(phHard, phSoft);
2189 }
2190
2191 if (electron &&
2192 MassOfPairIsWithinWindowAroundMZ(phHard, electron, 10) == false &&
2193 MassOfPairIsWithinWindowAroundMZ(phSoft, electron, 10) == false) {
2194 // electron tagged
2195 fDiphotonEvent->leptonTag = 1;
2196
2197 fDiphotonEvent-> elePt = fLeptonTagElectrons->At(0)->Pt();
2198 fDiphotonEvent-> eleEta = fLeptonTagElectrons->At(0)->Eta();
2199 fDiphotonEvent-> eleSCEta = fLeptonTagElectrons->At(0)->SCluster()->Eta();
2200 fDiphotonEvent-> eleIso1 = (fLeptonTagElectrons->At(0)->TrackIsolationDr03() + fLeptonTagElectrons->At(0)->EcalRecHitIsoDr03() + fLeptonTagElectrons->At(0)->HcalTowerSumEtDr03() - fPileUpDen->At(0)->RhoRandomLowEta() * TMath::Pi() * 0.3 * 0.3)/fDiphotonEvent-> elePt;
2201
2202 fDiphotonEvent-> eleIso2 = -99.;
2203
2204 if ( fDoSynching ) {
2205 Double_t distVtx = 999.0;
2206 for(UInt_t nv=0; nv<fPV->GetEntries(); nv++){
2207 double dz = TMath::Abs(fLeptonTagElectrons->At(0)->GsfTrk()->DzCorrected(*fPV->At(nv)));
2208 if(dz < distVtx) {
2209 distVtx = dz;
2210 closestVtx = nv;
2211 }
2212 }
2213 fDiphotonEvent-> eleIdMva = fElectronIDMVA->MVAValue(fLeptonTagElectrons->At(0), fPV->At(closestVtx));
2214 }
2215
2216
2217 fDiphotonEvent-> eleIso3 = (fLeptonTagElectrons->At(0)->TrackIsolationDr03() + fLeptonTagElectrons->At(0)->EcalRecHitIsoDr03() + fLeptonTagElectrons->At(0)->HcalTowerSumEtDr03() - fPileUpDen->At(0)->RhoLowEta() * TMath::Pi() * 0.3 * 0.3)/fDiphotonEvent-> elePt;
2218 fDiphotonEvent-> eleIso4 = (fLeptonTagElectrons->At(0)->TrackIsolationDr03() + fLeptonTagElectrons->At(0)->EcalRecHitIsoDr03() + fLeptonTagElectrons->At(0)->HcalTowerSumEtDr03() - fPileUpDen->At(0)->Rho() * TMath::Pi() * 0.3 * 0.3)/fDiphotonEvent-> elePt;
2219 fDiphotonEvent-> eleDist = fLeptonTagElectrons->At(0)->ConvPartnerDist();
2220 fDiphotonEvent-> eleDcot = fLeptonTagElectrons->At(0)->ConvPartnerDCotTheta();
2221 fDiphotonEvent-> eleCoviee = fLeptonTagElectrons->At(0)->CoviEtaiEta();
2222 fDiphotonEvent-> eleDphiin = TMath::Abs(fLeptonTagElectrons->At(0)->DeltaPhiSuperClusterTrackAtVtx());
2223 fDiphotonEvent-> eleDetain = TMath::Abs(fLeptonTagElectrons->At(0)->DeltaEtaSuperClusterTrackAtVtx());
2224 fDiphotonEvent-> eleDR1 = MathUtils::DeltaR(fLeptonTagElectrons->At(0),phHard);
2225 fDiphotonEvent-> eleDR2 = MathUtils::DeltaR(fLeptonTagElectrons->At(0),phSoft);
2226 fDiphotonEvent-> eleMass1 = (phHard->Mom()+fLeptonTagElectrons->At(0)->Mom()).M();
2227 fDiphotonEvent-> eleMass2 = (phSoft->Mom()+fLeptonTagElectrons->At(0)->Mom()).M();
2228 fDiphotonEvent-> eleNinnerHits = fLeptonTagElectrons->At(0)->Trk()->NExpectedHitsInner();
2229 } // electron tagged
2230
2231 if(false){
2232 if(fDiphotonEvent->evt==79737729 || fDiphotonEvent->evt== 871378986 || fDiphotonEvent->evt==528937923 || fDiphotonEvent->evt== 261543921){
2233 printf("ming sync check ele: run:%d evt:%d lumi:%d leptonTag:%d numelectrons:%d idmva:%f mass:%f\n elePt:%f eleEta:%f eleSCEta:%f vtx:%d\n",fDiphotonEvent->run,fDiphotonEvent->evt,fDiphotonEvent->lumi,fDiphotonEvent->leptonTag,fLeptonTagElectrons->GetEntries(),fDiphotonEvent->eleIdMva,fDiphotonEvent->mass,fDiphotonEvent->elePt,fDiphotonEvent->eleEta,fDiphotonEvent->eleSCEta,closestVtx);
2234 //return;
2235 }
2236 if(fDiphotonEvent->evt==333643114 || fDiphotonEvent->evt==89022540 || fDiphotonEvent->evt==8983064 || fDiphotonEvent->evt==876316897 || fDiphotonEvent->evt==541603559 || fDiphotonEvent->evt==223740859) {
2237 printf("ming sync check muon: run:%d evt:%d lumi:%d leptonTag:%d numMuons:%d mass:%f\n muonPt:%f muonEta:%f\n\n",fDiphotonEvent->run,fDiphotonEvent->evt,fDiphotonEvent->lumi,fDiphotonEvent->leptonTag,fLeptonTagMuons->GetEntries(),fDiphotonEvent->mass,fDiphotonEvent->muonPt,fDiphotonEvent->muonEta);
2238 //return;
2239 }
2240 }
2241 } // void PhotonTreeWriter::ApplyLeptonTag(..)
2242
2243
2244 //_____________________________________________________________________________
2245 const Muon* PhotonTreeWriter::GetLeptonTagMuon(const Photon *phHard,
2246 const Photon *phSoft)
2247 {
2248 // need to have dR > 1 for with respect to both photons ***changed to 0.7 for 2012
2249 if (fLeptonTagMuons->GetEntries() > 0 &&
2250 fLeptonTagMuons->At(0) != 0 &&
2251 MathUtils::DeltaR(fLeptonTagMuons->At(0), phHard) >= 1.0 &&
2252 MathUtils::DeltaR(fLeptonTagMuons->At(0), phSoft) >= 1.0) {
2253 return fLeptonTagMuons->At(0);
2254 } else {
2255 return 0;
2256 }
2257 } // const Muon* PhotonTreeWriter::GetLeptonTagMuon(..)
2258
2259
2260 //_____________________________________________________________________________
2261 void PhotonTreeWriter::SetLeptonTagMuonVars(const Photon *phHard,
2262 const Photon *phSoft,
2263 const Muon *muon)
2264 {
2265 fDiphotonEvent-> muonPt = muon->Pt();
2266 fDiphotonEvent-> muonEta = muon->Eta();
2267 fDiphotonEvent-> muDR1 = MathUtils::DeltaR(muon, phHard);
2268 fDiphotonEvent-> muDR2 = MathUtils::DeltaR(muon, phSoft);
2269
2270 Float_t combinedIso = (muon->IsoR03SumPt() +
2271 muon->IsoR03EmEt() +
2272 muon->IsoR03HadEt());
2273
2274 Float_t coneArea = TMath::Pi() * 0.3 * 0.3;
2275
2276 Float_t rho1 = fPileUpDen->At(0)->RhoRandomLowEta();
2277 Float_t rho2 = fPileUpDen->At(0)->RhoRandom();
2278 Float_t rho3 = fPileUpDen->At(0)->RhoLowEta();
2279 Float_t rho4 = fPileUpDen->At(0)->Rho();
2280
2281 fDiphotonEvent-> muIso1 = (combinedIso - rho1 * coneArea) / muon->Pt();
2282 fDiphotonEvent-> muIso2 = (combinedIso - rho2 * coneArea) / muon->Pt();
2283 fDiphotonEvent-> muIso3 = (combinedIso - rho3 * coneArea) / muon->Pt();
2284 fDiphotonEvent-> muIso4 = (combinedIso - rho4 * coneArea) / muon->Pt();
2285
2286 fDiphotonEvent-> muD0 = TMath::Abs(muon->BestTrk()->D0Corrected(*fPV->At(0)));
2287 fDiphotonEvent-> muDZ = TMath::Abs(muon->BestTrk()->DzCorrected(*fPV->At(0)));
2288 fDiphotonEvent-> muChi2 = muon->GlobalTrk()->Chi2()/muon->GlobalTrk()->Ndof();
2289
2290 fDiphotonEvent-> muNhits = muon->BestTrk()->NHits();
2291 fDiphotonEvent-> muNpixhits = muon->BestTrk()->NPixelHits();
2292 fDiphotonEvent-> muNegs = muon->NSegments();
2293 fDiphotonEvent-> muNMatch = muon->NMatches();
2294 } // void PhotonTreeWriter::SetLeptonTagMuonVars(..)
2295
2296
2297 //_____________________________________________________________________________
2298 const Electron* PhotonTreeWriter::GetLeptonTagElectron(const Photon *phHard,
2299 const Photon *phSoft)
2300 {
2301 // need to have dR > 1 for with respect to both photons ***changed to 0.7 for 2012
2302 if (fLeptonTagElectrons->GetEntries() > 0 &&
2303 fLeptonTagElectrons->At(0) != 0 &&
2304 PhotonTools::ElectronVetoCiC(phHard, fLeptonTagElectrons) >= 1 &&
2305 PhotonTools::ElectronVetoCiC(phSoft, fLeptonTagElectrons) >= 1 &&
2306 PhotonTools::ElectronVetoCiC(phHard, fElectrons) >= 1 &&
2307 PhotonTools::ElectronVetoCiC(phSoft, fElectrons) >= 1 &&
2308 MathUtils::DeltaR(fLeptonTagElectrons->At(0), phHard) >= 1 &&
2309 MathUtils::DeltaR(fLeptonTagElectrons->At(0), phSoft) >= 1){
2310 return fLeptonTagElectrons->At(0);
2311 } else {
2312 return 0;
2313 }
2314 } // const Electron* PhotonTreeWriter::GetLeptonTagElectron(..)
2315
2316
2317 //_____________________________________________________________________________
2318 bool PhotonTreeWriter::MassOfPairIsWithinWindowAroundMZ(
2319 const Particle * particle1,
2320 const Particle * particle2,
2321 Float_t halfWindowSize,
2322 Float_t MZ
2323 ) {
2324 Float_t mass = (particle1->Mom() + particle2->Mom()).M();
2325 return TMath::Abs(mass - MZ) < halfWindowSize;
2326 } // bool PhotonTreeWriter::MassOfPairIsWithinWindowAroundMZ(..)
2327
2328
2329 //_____________________________________________________________________________
2330 void PhotonTreeWriter::ApplyVHLepTag(const Photon *phHard,
2331 const Photon *phSoft,
2332 const Vertex *selvtx)
2333 {
2334
2335 // perform flavor-based lepton tagging (used since the legacy paper of 2013)
2336 // the diphoton event record will have one more entry; i.e. leptonTag
2337 // VHLepTag = -1 -> lepton-taggng was swicthed off
2338 // = 0 -> event tagged as 'non-lepton event'
2339 // = +1 -> event tagged as a low-MET high-S/sqrt(B) event
2340 // = +2 -> event tagged as a high-MET low-S/sqrt(B) event
2341 // TODO: Set the selected vertex to the lepton vertex if tagged as a
2342 // VH(lep) event.
2343
2344 fDiphotonEvent->VHLepTag = 0; // non-lepton event
2345
2346 if (VHHasDielectron(phHard, phSoft)) {
2347 fDiphotonEvent->VHLepTag = 2; // high MET
2348 return;
2349 }
2350
2351 if (VHHasDimuon(phHard, phSoft)) {
2352 fDiphotonEvent->VHLepTag = 2; // high MET
2353 return;
2354 }
2355
2356 if (fDiphotonEvent->leptonTag < 0) {
2357 ApplyLeptonTag(phHard, phSoft, selvtx);
2358 }
2359
2360 const Muon *muon = GetLeptonTagMuon(phHard, phSoft);
2361 if (muon &&
2362 VHNumberOfJets(phHard, phSoft, selvtx, muon) <= 2) {
2363 // Found a good VH(lep) tag muon.
2364 if (fDiphotonEvent->corrpfmet > 45.) {
2365 fDiphotonEvent->VHLepTag = 2; // high MET event
2366 } else {
2367 fDiphotonEvent->VHLepTag = 1; // low MET event
2368 }
2369 return;
2370 } // Found a good VH(lep) tag muon.
2371
2372 const Electron *electron = GetLeptonTagElectron(phHard, phSoft);
2373 if (electron &&
2374 VHNumberOfJets(phHard, phSoft, selvtx, electron) <= 2) {
2375 // Found a good VH(lep) tag electron.
2376 if (fDiphotonEvent->corrpfmet > 45.) {
2377 // High MET event.
2378 fDiphotonEvent->VHLepTag = 2;
2379 } else {
2380 // Low MET event. Exclude Z->ee(->gamma) candidates based on mass
2381 if (MassOfPairIsWithinWindowAroundMZ(phHard, electron, 10) == false &&
2382 MassOfPairIsWithinWindowAroundMZ(phSoft, electron, 10) == false) {
2383 fDiphotonEvent->VHLepTag = 1; // low MET event
2384 } else {
2385 // Reject because m(e,g) is within 10 GeV of MZ
2386 fDiphotonEvent->VHLepTag = 0; // non-lepton event
2387 }
2388 } // Low MET event.
2389 } // Found a good VH(lep) tag electron.
2390
2391 } // void PhotonTreeWriter::ApplyVHLepTag(..)
2392
2393
2394 //_____________________________________________________________________________
2395 bool PhotonTreeWriter::VHHasDielectron(const Photon *phHard,
2396 const Photon *phSoft) {
2397 if (fLeptonTagSoftElectrons->GetEntries() < 2) return false;
2398
2399 if (fVerbosityLevel > 0) {
2400 cout << "JV PhotonTreeWriter::VHHasDielectron: Found >= 2 electrons!"
2401 << endl;
2402 }
2403
2404 vector<UInt_t> goodElectrons;
2405
2406 // Loop over electrons.
2407 for (UInt_t iele=0; iele < fLeptonTagSoftElectrons->GetEntries(); ++iele){
2408 const Electron *ele = fLeptonTagSoftElectrons->At(iele);
2409 if (MathUtils::DeltaR(ele, phHard) < 0.5) continue;
2410 if (MathUtils::DeltaR(ele, phSoft) < 0.5) continue;
2411 goodElectrons.push_back(iele);
2412 }
2413
2414 // Loop over electron pairs.
2415 for (UInt_t iele1 = 0; iele1 < goodElectrons.size() - 1; ++iele1) {
2416 const Electron *ele1 = fLeptonTagSoftElectrons->At(iele1);
2417 for (UInt_t iele2 = iele1; iele2 < goodElectrons.size(); ++iele2) {
2418 const Electron *ele2 = fLeptonTagSoftElectrons->At(iele2);
2419 Double_t mass12 = (ele1->Mom() + ele2->Mom()).M();
2420 if (mass12 < 70. || 110. < mass12) continue;
2421 return true;
2422 }
2423 }
2424
2425 return false;
2426
2427 } // bool PhotonTreeWriter::VHHasDielectron(..)
2428
2429
2430 //_____________________________________________________________________________
2431 bool PhotonTreeWriter::VHHasDimuon(const Photon *phHard,
2432 const Photon *phSoft) {
2433 if (fLeptonTagSoftMuons->GetEntries() < 2) return false;
2434
2435 if (fVerbosityLevel > 0) {
2436 cout << "JV PhotonTreeWriter::VHHasDimuon: Found >= 2 muons!" << endl;
2437 }
2438
2439 vector<UInt_t> goodMuons;
2440
2441 // Loop over muons and apply the cut Delta R (mu, pho) > 0.5 .
2442 for (UInt_t imu=0; imu < fLeptonTagSoftMuons->GetEntries(); ++imu){
2443 const Muon *mu = fLeptonTagSoftMuons->At(imu);
2444 if (MathUtils::DeltaR(mu, phHard) < 0.5) continue;
2445 if (MathUtils::DeltaR(mu, phSoft) < 0.5) continue;
2446 goodMuons.push_back(imu);
2447 }
2448
2449 // Loop over muon pairs and apply the cut 70 < mass(mu1, mu2) < 110.
2450 for (UInt_t imu1 = 0; imu1 < goodMuons.size() - 1; ++imu1) {
2451 const Muon *mu1 = fLeptonTagSoftMuons->At(imu1);
2452 for (UInt_t imu2 = imu1; imu2 < goodMuons.size(); ++imu2) {
2453 const Muon *mu2 = fLeptonTagSoftMuons->At(imu2);
2454 Double_t mass12 = (mu1->Mom() + mu2->Mom()).M();
2455 if (mass12 < 70. || 110. < mass12) continue;
2456 return true;
2457 }
2458 }
2459
2460 return false;
2461
2462 } // PhotonTreeWriter::VHHasDimuon(..)
2463
2464
2465 //_____________________________________________________________________________
2466 UInt_t PhotonTreeWriter::VHNumberOfJets(const Photon *phHard,
2467 const Photon *phSoft,
2468 const Vertex *selvtx,
2469 const Particle *lepton) {
2470
2471 UInt_t nJets = 0;
2472
2473 // Loop over jets, count those passing selection
2474 // Use same ID as for the tth tag
2475 for(UInt_t ijet=0; ijet < fPFJets->GetEntries(); ++ijet){
2476 const Jet *jet = fPFJets->At(ijet);
2477 // Apply jet selection, see L116 and L125 of the AN
2478 if (jet->Pt() < 20. || jet->AbsEta() > 2.4) continue;
2479 // Apply the cut Delta R(photon, jet) < 0.5.
2480 if (MathUtils::DeltaR(jet, phHard) < 0.5) continue;
2481 if (MathUtils::DeltaR(jet, phSoft) < 0.5) continue;
2482 // Apply the cut Delta R(photon, lepton) < 0.5.
2483 if (MathUtils::DeltaR(jet, lepton) < 0.5) continue;
2484 // Make sure we have a PF jet
2485 const PFJet *pfjet = dynamic_cast<const PFJet*>(jet);
2486 if (!pfjet) continue;
2487 if (!JetTools::passPFLooseId(pfjet)) continue;
2488 // Apply the jet ID / pileup removal as given in Table 4
2489 Double_t betaStar = JetTools::betaStarClassic(pfjet, selvtx, fPV);
2490 if (betaStar > 0.2 * log(fPV->GetEntries() - 0.64)) continue;
2491 if (JetTools::dR2Mean(pfjet, -1) > 0.065) continue;
2492 // this jet passes, count it in
2493 ++nJets;
2494 } // End of loop over jets
2495
2496 return nJets;
2497
2498 } // PhotonTreeWriter::VHNumberOfJets(..)
2499
2500
2501 //_____________________________________________________________________________
2502 // Applies the ttH tag given precelected leading and trailing photons
2503 // phHard and phSoft and the corresponding (pre?) selected vertex selvtx.
2504 // The result is stored as an integer value of the tthTag variable
2505 // entering the diphoton event record.
2506 void PhotonTreeWriter::ApplyTTHTag(const Photon *phHard,
2507 const Photon *phSoft,
2508 const Vertex *selvtx)
2509 {
2510 // ttH tag = -1 .. not applied
2511 // 0 .. not tagged
2512 // 1 .. tagged as a leptonic ttH event
2513 // 2 .. tagged as a hadronic ttH event
2514 fDiphotonEvent->tthTag = 0;
2515
2516 // Selection taken from the AN2012_480_V6 of 24 April 2013, further
2517 // refferred to as "the AN"
2518
2519 // Check the pt of the photons, see L141 and L142 of the AN
2520 if (phHard->Pt() < 33.) return;
2521 if (phSoft->Pt() < 25.) return;
2522
2523 // Init final-state object counters
2524 UInt_t nJets = 0;
2525 UInt_t nBJets = 0;
2526 UInt_t nElectrons = 0;
2527 UInt_t nMuons = 0;
2528
2529 // Loop over jets, count those passing selection.
2530 // No Delta R(gamma, j) requirement!?
2531 for(UInt_t ijet=0; ijet < fPFJets->GetEntries(); ++ijet){
2532 const Jet *jet = fPFJets->At(ijet);
2533 // Apply jet selection, see L116 and L125 of the AN
2534 if (jet->Pt() < 25. || jet->AbsEta() > 2.4) continue;
2535 // Make sure we have a PF jet
2536 const PFJet *pfjet = dynamic_cast<const PFJet*>(jet);
2537 if (!pfjet) continue;
2538 if (!JetTools::passPFLooseId(pfjet)) continue;
2539 // Apply the jet ID as given in Table 4
2540 Double_t betaStar = JetTools::betaStarClassic(pfjet, selvtx, fPV);
2541 if (betaStar > 0.2 * log(fPV->GetEntries() - 0.64)) continue;
2542 if (JetTools::dR2Mean(pfjet, -1) > 0.065) continue;
2543 // this jet passes, count it in
2544 ++nJets;
2545 // Select b-jets that pass the CSV medium working point, see L128 of the AN
2546 // and https://twiki.cern.ch/twiki/bin/viewauth/CMS/BTagPerformanceOP
2547 if (jet->CombinedSecondaryVertexBJetTagsDisc() < 0.679) continue;
2548 ++nBJets;
2549 } // End of loop over jets
2550
2551 // Check the number of selected jets, see Table 7 near L196 of the AN
2552 if (nJets < 2) return;
2553
2554 // Check the number of b-tagged jets, see Table 7 near L196 of the AN
2555 if (nBJets < 1) return;
2556
2557 // Loop over electrons
2558 for (UInt_t iele=0; iele < fLeptonTagElectrons->GetEntries(); ++iele) {
2559 const Electron *ele = fLeptonTagElectrons->At(iele);
2560 // Apply kinematic cuts, see L133 and L134 of the AN
2561 if (ele->Pt() < 20. || ele->AbsEta() < 2.5) continue;
2562 ++nElectrons;
2563 }
2564
2565 // Loop over muons
2566 for (UInt_t imu=0; imu < fLeptonTagMuons->GetEntries(); ++imu) {
2567 const Muon *mu = fLeptonTagMuons->At(imu);
2568 // Apply kinematic cuts, see L132 and L134 of the AN
2569 if (mu->Pt() < 20. || mu->AbsEta() > 2.4) continue;
2570 // Require separation between this muon and both photons,
2571 // see the slide 7, bullet 2
2572 // Also confirmed by Francesco Micheli in an e-mail from 15 July 2013
2573 if (MathUtils::DeltaR(mu, phHard) < 1.0) continue;
2574 if (MathUtils::DeltaR(mu, phSoft) < 1.0) continue;
2575 ++nMuons;
2576 }
2577
2578 // Check the lepton tag, see Table 7 near L196 of the AN
2579 // It has a precedence if both the leptonic and hadronic tags pass.
2580 // (private e-mail from Francesco Micheli on 15 July 2013).
2581 if (nElectrons + nMuons >= 1) {
2582 // apply the leptonic tth tag
2583 fDiphotonEvent->tthTag = 1;
2584 return;
2585 }
2586
2587 // Check the hadron tag, see Table 7 near L196 of the AN
2588 if (nJets >= 5) {
2589 // apply the hadronic tth tag
2590 fDiphotonEvent->tthTag = 2;
2591 return;
2592 }
2593
2594 } // void PhotonTreeWriter::ApplyTTHTag()
2595
2596
2597 //_____________________________________________________________________________
2598 void PhotonTreeWriter::Terminate()
2599 {
2600 // Run finishing code on the computer (slave) that did the analysis
2601 }
2602
2603