ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonTreeWriter.cc
Revision: 1.74
Committed: Wed Dec 11 00:43:03 2013 UTC (11 years, 5 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.73: +11 -24 lines
Log Message:
jet id fixes and improved lepton tagged photon pair selection logic

File Contents

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