ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonPairSelector.cc
Revision: 1.4
Committed: Sat Jul 23 01:42:41 2011 UTC (13 years, 9 months ago) by bendavid
Content type: text/plain
Branch: MAIN
Changes since 1.3: +132 -24 lines
Log Message:
add fancy tree to PhotonPairSelector

File Contents

# User Rev Content
1 fabstoec 1.1 #include "MitPhysics/Mods/interface/PhotonPairSelector.h"
2     #include "MitAna/DataTree/interface/PhotonCol.h"
3     #include "MitAna/DataTree/interface/PFCandidateCol.h"
4     #include "MitPhysics/Init/interface/ModNames.h"
5     #include "MitPhysics/Utils/interface/IsolationTools.h"
6     #include "MitPhysics/Utils/interface/PhotonTools.h"
7     #include "MitPhysics/Utils/interface/VertexTools.h"
8     #include <TNtuple.h>
9     #include <TRandom3.h>
10    
11     using namespace mithep;
12    
13     ClassImp(mithep::PhotonPairSelector)
14 bendavid 1.4 ClassImp(mithep::PhotonPairSelectorPhoton)
15     ClassImp(mithep::PhotonPairSelectorDiphotonEvent)
16    
17 fabstoec 1.1
18     //--------------------------------------------------------------------------------------------------
19     PhotonPairSelector::PhotonPairSelector(const char *name, const char *title) :
20     // Base Module...
21     BaseMod (name,title),
22    
23     // define all the Branches to load
24     fPhotonBranchName (Names::gkPhotonBrn),
25     fElectronName (Names::gkElectronBrn),
26     fConversionName (Names::gkMvfConversionBrn),
27     fTrackBranchName (Names::gkTrackBrn),
28     fPileUpDenName (Names::gkPileupEnergyDensityBrn),
29     fPVName (Names::gkPVBeamSpotBrn),
30     fBeamspotName (Names::gkBeamSpotBrn),
31     fPFCandName (Names::gkPFCandidatesBrn),
32     // MC specific stuff...
33     fMCParticleName (Names::gkMCPartBrn),
34     fPileUpName (Names::gkPileupInfoBrn),
35    
36     fGoodPhotonsName (ModNames::gkGoodPhotonsName),
37    
38     // ----------------------------------------
39     // Selection Types
40     fPhotonSelType ("NoSelection"),
41     fVertexSelType ("StdSelection"),
42     fPhSelType (kNoPhSelection),
43     fVtxSelType (kStdVtxSelection),
44    
45     // ----------------------------------------
46     fPhotonPtMin (20.0),
47     fPhotonEtaMax (2.5),
48    
49     fLeadingPtMin (40.0),
50     fTrailingPtMin (30.0),
51    
52     fIsData (false),
53     fPhotonsFromBranch (true),
54     fPVFromBranch (true),
55    
56     // ----------------------------------------
57     // collections....
58     fPhotons (0),
59     fElectrons (0),
60     fConversions (0),
61     fTracks (0),
62     fPileUpDen (0),
63     fPV (0),
64     fBeamspot (0),
65     fPFCands (0),
66     fMCParticles (0),
67     fPileUp (0),
68    
69     // ---------------------------------------
70     fDataEnCorr_EB_hR9 (0.),
71     fDataEnCorr_EB_lR9 (0.),
72     fDataEnCorr_EE_hR9 (0.),
73     fDataEnCorr_EE_lR9 (0.),
74    
75     fRunStart (0),
76     fRunEnd (0),
77    
78     fMCSmear_EB_hR9 (0.),
79     fMCSmear_EB_lR9 (0.),
80     fMCSmear_EE_hR9 (0.),
81     fMCSmear_EE_lR9 (0.),
82    
83     // ---------------------------------------
84     rng (new TRandom3()),
85    
86     // ---------------------------------------
87     fDoDataEneCorr (true),
88     fDoMCSmear (true),
89 fabstoec 1.2 fDoVtxSelection (true),
90     fApplyEleVeto (true),
91    
92     fTupleName ("hCiCtuple")
93 fabstoec 1.1
94     {
95     // Constructor.
96     }
97    
98     PhotonPairSelector::~PhotonPairSelector(){
99     if(rng) delete rng;
100     }
101    
102     //--------------------------------------------------------------------------------------------------
103     void PhotonPairSelector::Process()
104     {
105     // ------------------------------------------------------------
106     // Process entries of the tree.
107     LoadEventObject(fPhotonBranchName, fPhotons);
108     LoadEventObject(fElectronName, fElectrons);
109     LoadEventObject(fConversionName, fConversions);
110     LoadEventObject(fTrackBranchName, fTracks);
111     LoadEventObject(fPileUpDenName, fPileUpDen);
112     LoadEventObject(fPVName, fPV);
113     LoadEventObject(fBeamspotName, fBeamspot);
114     LoadEventObject(fPFCandName, fPFCands);
115    
116     if( !fIsData ) {
117     LoadBranch(fMCParticleName);
118     LoadBranch(fPileUpName);
119     }
120    
121     // -----------------------------------------------------------
122     // OUtput Photon Collection. It will ALWAYS conatrin either 0 or 2 Photons
123     PhotonOArr *GoodPhotons = new PhotonOArr;
124     GoodPhotons->SetName(fGoodPhotonsName);
125     GoodPhotons->SetOwner(kTRUE);
126    
127    
128     // ------------------------------------------------------------
129     // load event based information
130 bendavid 1.4 Int_t _numPU = -1.; // some sensible default values....
131     Int_t _numPUminus = -1.; // some sensible default values....
132     Int_t _numPUplus = -1.; // some sensible default values....
133    
134 fabstoec 1.1 Float_t _tRho = -99.;
135 fabstoec 1.2 if( fPileUpDen->GetEntries() > 0 )
136     _tRho = (Double_t) fPileUpDen->At(0)->RhoRandomLowEta();
137    
138     if( !fIsData ) {
139     for (UInt_t i=0; i<fPileUp->GetEntries(); ++i) {
140     const PileupInfo *puinfo = fPileUp->At(i);
141 bendavid 1.4 if (puinfo->GetBunchCrossing()==0) _numPU = puinfo->GetPU_NumInteractions();
142     else if (puinfo->GetBunchCrossing() == -1) _numPUminus = puinfo->GetPU_NumInteractions();
143     else if (puinfo->GetBunchCrossing() == 1) _numPUplus = puinfo->GetPU_NumInteractions();
144 fabstoec 1.2 }
145     }
146    
147 fabstoec 1.1 const BaseVertex *bsp = dynamic_cast<const BaseVertex*>(fBeamspot->At(0));
148    
149     // ------------------------------------------------------------
150     // Get Event header for Run info etc.
151     const EventHeader* evtHead = this->GetEventHeader();
152     unsigned int evtNum = evtHead->EvtNum();
153     Float_t _evtNum1 = (Float_t) ( (int) (evtNum/10000.) );
154     Float_t _evtNum2 = (Float_t) ( (int) (evtNum % 10000) );
155     UInt_t runNumber = evtHead->RunNum();
156     Float_t _runNum = (Float_t) runNumber;
157     Float_t _lumiSec = (Float_t) evtHead->LumiSec();
158    
159     // ------------------------------------------------------------
160     // here we'll store the preselected Photons (and which CiCCategory they are...)
161     PhotonOArr* preselPh = new PhotonOArr;
162     std::vector<PhotonTools::CiCBaseLineCats> preselCat;
163     preselCat.resize(0);
164    
165     // 1. we do the pre-selection; but keep the non-passing photons in a secont container...
166     for (UInt_t i=0; i<fPhotons->GetEntries(); ++i) {
167     const Photon *ph = fPhotons->At(i);
168    
169     if(ph->SCluster()->AbsEta()>= fPhotonEtaMax || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) continue;
170     if(ph->Et() < fPhotonPtMin) continue;
171     if(ph->HadOverEm() > 0.15) continue;
172     if(ph->IsEB()) {
173     if(ph->CoviEtaiEta() > 0.013) continue;
174     } else {
175     if(ph->CoviEtaiEta() > 0.03) continue;
176     }
177     preselPh->Add(ph);
178 fabstoec 1.2 }
179    
180     // Sorry... need the second loop here in order to sort & assign the right Categories..
181     preselPh->Sort();
182     for(unsigned int iPh = 0; iPh <preselPh->GetEntries(); ++iPh) {
183     const Photon* ph = preselPh->At(iPh);
184 fabstoec 1.1 preselCat.push_back(PhotonTools::CiCBaseLineCat(ph));
185     }
186    
187     // ------------------------------------------------------------
188     // compute how many pairs there are ...
189     unsigned int numPairs = 0;
190     if( preselPh->GetEntries() > 0) numPairs = (preselPh->GetEntries()-1)*preselPh->GetEntries()/2;
191     // ... and create all possible pairs of pre-selected photons
192     std::vector<unsigned int> idx1st;
193     std::vector<unsigned int> idx2nd;
194     std::vector<PhotonTools::CiCBaseLineCats> cat1st;
195     std::vector<PhotonTools::CiCBaseLineCats> cat2nd;
196     // ... this will be used to store whether a givne pair passes the cuts
197     std::vector<bool> pairPasses;
198    
199     if(numPairs > 0) {
200     for(unsigned int i1st = 0; i1st <preselPh->GetEntries() - 1; ++i1st) {
201     for(unsigned int i2nd = i1st + 1; i2nd <preselPh->GetEntries(); ++i2nd) {
202     idx1st.push_back(i1st);
203     idx2nd.push_back(i2nd);
204     pairPasses.push_back(true);
205     }
206     }
207     }
208    
209     // ------------------------------------------------------------
210     // array to store the index of 'chosen Vtx' for each pair
211     const Vertex** theVtx = new const Vertex*[numPairs]; // holds the 'chosen' Vtx for each Pair
212     Photon** fixPh1st = new Photon*[numPairs]; // holds the 1st Photon for each Pair
213     Photon** fixPh2nd = new Photon*[numPairs]; // holds the 2nd photon for each Pair
214    
215    
216     // store pair-indices for pairs passing the selection
217     std::vector<unsigned int> passPairs;
218     passPairs.resize(0);
219    
220     // ------------------------------------------------------------
221     // Loop over all Pairs and to the 'incredible machine' running....
222     for(unsigned int iPair = 0; iPair < numPairs; ++iPair) {
223    
224     // first we need a hard copy of the incoming photons
225     fixPh1st[iPair] = new Photon(*preselPh->At(idx1st[iPair]));
226     fixPh2nd[iPair] = new Photon(*preselPh->At(idx2nd[iPair]));
227     // we also store the category, so we don't have to ask all the time...
228     cat1st.push_back(preselCat[idx1st[iPair]]);
229     cat2nd.push_back(preselCat[idx2nd[iPair]]);
230    
231     // now we dicide if we either scale (Data) or Smear (MC) the Photons
232     if (fIsData) {
233     if(fDoDataEneCorr) {
234     // statring with scale = 1.
235     double scaleFac1 = 1.;
236     double scaleFac2 = 1.;
237     // checking the run Rangees ...
238     Int_t runRange = FindRunRangeIdx(runNumber);
239     if(runRange > -1) {
240     scaleFac1 += GetDataEnCorr(runRange, cat1st[iPair]);
241     scaleFac2 += GetDataEnCorr(runRange, cat2nd[iPair]);
242     }
243     PhotonTools::ScalePhoton(fixPh1st[iPair], scaleFac1);
244     PhotonTools::ScalePhoton(fixPh2nd[iPair], scaleFac2);
245     }
246     } else {
247     if(fDoMCSmear) {
248     // get the seed to do deterministic smearing...
249     UInt_t seedBase = (UInt_t) evtNum + (UInt_t) _runNum + (UInt_t) _lumiSec;
250     UInt_t seed1 = seedBase + (UInt_t) fixPh1st[iPair]->E() + (UInt_t) (TMath::Abs(10.*fixPh1st[iPair]->SCluster()->Eta()));
251     UInt_t seed2 = seedBase + (UInt_t) fixPh2nd[iPair]->E() + (UInt_t) (TMath::Abs(10.*fixPh2nd[iPair]->SCluster()->Eta()));
252     // get the smearing for MC photons..
253 fabstoec 1.3
254 fabstoec 1.1 double width1 = GetMCSmearFac(cat1st[iPair]);
255     double width2 = GetMCSmearFac(cat2nd[iPair]);
256 fabstoec 1.3
257 fabstoec 1.1 PhotonTools::SmearPhoton(fixPh1st[iPair], rng, width1, seed1);
258     PhotonTools::SmearPhoton(fixPh2nd[iPair], rng, width2, seed2);
259 fabstoec 1.3
260 fabstoec 1.1 }
261     }
262    
263     // store the vertex for this pair
264     switch( fVtxSelType ){
265     case kStdVtxSelection:
266     theVtx[iPair] = fPV->At(0);
267     break;
268     case kCiCVtxSelection:
269     theVtx[iPair] = VertexTools::findVtxBasicRanking(fixPh1st[iPair],fixPh2nd[iPair], bsp, fPV, fConversions);
270     break;
271     case kMITVtxSelection:
272     // need PFCandidate Collection
273     theVtx[iPair] = VertexTools::BestVtx(fPFCands, fPV, bsp, mithep::FourVector((fixPh1st[iPair]->Mom()+fixPh2nd[iPair]->Mom())));
274     break;
275     default:
276     theVtx[iPair] = fPV->At(0);
277 fabstoec 1.2
278 fabstoec 1.1 }
279 fabstoec 1.2
280 fabstoec 1.1 // fix the kinematics for both events
281     FourVectorM newMom1st = fixPh1st[iPair]->MomVtx(theVtx[iPair]->Position());
282     FourVectorM newMom2nd = fixPh2nd[iPair]->MomVtx(theVtx[iPair]->Position());
283     fixPh1st[iPair]->SetMom(newMom1st.X(), newMom1st.Y(), newMom1st.Z(), newMom1st.E());
284     fixPh2nd[iPair]->SetMom(newMom2nd.X(), newMom2nd.Y(), newMom2nd.Z(), newMom2nd.E());
285    
286     // check if both photons pass the CiC selection
287     // FIX-ME: Add other possibilities....
288     bool pass1 = false;
289     bool pass2 = false;
290     switch( fVtxSelType ){
291     case kNoPhSelection:
292     pass1 = ( fixPh1st[iPair]->Pt() > fLeadingPtMin );
293     pass2 = ( fixPh2nd[iPair]->Pt() > fTrailingPtMin );
294     break;
295     case kCiCPhSelection:
296 fabstoec 1.3
297    
298 fabstoec 1.2 pass1 = PhotonTools::PassCiCSelection(fixPh1st[iPair], theVtx[iPair], fTracks, fElectrons, fPV, _tRho, fLeadingPtMin, fApplyEleVeto);
299     if(pass1) pass2 = PhotonTools::PassCiCSelection(fixPh2nd[iPair], theVtx[iPair], fTracks, fElectrons, fPV, _tRho, fTrailingPtMin, fApplyEleVeto);
300 fabstoec 1.3
301 fabstoec 1.1 break;
302     case kMITPhSelection:
303 fabstoec 1.3 // FIX-ME: This is a place-holder.. MIT guys: Please work hard... ;)
304 fabstoec 1.1 pass1 = ( fixPh1st[iPair]->Pt() > fLeadingPtMin );
305     pass2 = ( fixPh2nd[iPair]->Pt() > fTrailingPtMin );
306     break;
307     default:
308     pass1 = true;
309     pass2 = true;
310     }
311     // finally, if both Photons pass the selections, add the pair to the 'passing Pairs)
312     if( pass1 && pass2 ) passPairs.push_back(iPair);
313     }
314    
315    
316     // ---------------------------------------------------------------
317     // ... we're almost done, stau focused...
318     // loop over all passing pairs and find the one with the highest sum Et
319     const Vertex* _theVtx = NULL;
320     Photon* phHard = NULL;
321     Photon* phSoft = NULL;
322    
323     PhotonTools::CiCBaseLineCats catPh1 = PhotonTools::kCiCNoCat;
324     PhotonTools::CiCBaseLineCats catPh2 = PhotonTools::kCiCNoCat;
325    
326     double maxSumEt = 0.;
327     for(unsigned int iPair=0; iPair<passPairs.size(); ++iPair){
328     double sumEt = fixPh1st[passPairs[iPair]]->Et();
329     sumEt += fixPh2nd[passPairs[iPair]]->Et();
330     if( sumEt > maxSumEt ) {
331     maxSumEt = sumEt;
332     phHard = fixPh1st[passPairs[iPair]];
333     phSoft = fixPh2nd[passPairs[iPair]];
334     catPh1 = cat1st[passPairs[iPair]];
335     catPh2 = cat2nd[passPairs[iPair]];
336     _theVtx = theVtx[iPair];
337     }
338     }
339    
340     // ---------------------------------------------------------------
341     // we have the Photons (*PARTY*)... compute some useful qunatities
342    
343     Float_t _theVtxZ = -999.;
344    
345     if(phHard && phSoft) {
346     GoodPhotons->AddOwned(phHard);
347     GoodPhotons->AddOwned(phSoft);
348     }
349    
350     if(_theVtx) _theVtxZ=_theVtx->Position().Z();
351    
352     // sort according to pt
353     GoodPhotons->Sort();
354    
355     // add to event for other modules to use
356     AddObjThisEvt(GoodPhotons);
357    
358     // delete auxiliary photon collection...
359     delete preselPh;
360     delete[] theVtx;
361    
362     // Fill the useful information (mass and di-photon pt)
363     bool doFill = ( phHard && phSoft );
364 bendavid 1.4 if (!doFill) return;
365    
366 fabstoec 1.1 Float_t _mass = ( doFill ? (phHard->Mom()+phSoft->Mom()).M() : -100.);
367     Float_t _ptgg = ( doFill ? (phHard->Mom()+phSoft->Mom()).Pt() : -100.);
368 bendavid 1.4
369 fabstoec 1.1 // in case of a MC event, try to find Higgs and Higgs decay Z poisition
370     Float_t _pth = -100.;
371     Float_t _decayZ = -100.;
372     if( !fIsData ) FindHiggsPtAndZ(_pth, _decayZ);
373    
374     Float_t evtCat = -1.;
375     if( doFill ) {
376     evtCat = GetEventCat(catPh1, catPh2);
377     if(_ptgg < 40.) evtCat += 4.;
378     }
379 bendavid 1.4
380     const MCParticle *phgen1 = MatchMC(phHard);
381     const MCParticle *phgen2 = MatchMC(phSoft);
382 fabstoec 1.1
383 bendavid 1.4 Float_t _gencostheta = -99.;
384     if (phgen1 && phgen2) {
385     _gencostheta = ThreeVector(phgen1->Mom()).Unit().Dot(ThreeVector(phgen2->Mom()).Unit());
386     }
387    
388     if(_mass > 0.) {
389     fDiphotonEvent->rho = _tRho;
390     fDiphotonEvent->genHiggspt = _pth;
391     fDiphotonEvent->genHiggsZ = _decayZ;
392     fDiphotonEvent->gencostheta = _gencostheta;
393     fDiphotonEvent->vtxZ = _theVtxZ;
394     fDiphotonEvent->numPU = _numPU;
395     fDiphotonEvent->numPUminus = _numPUminus;
396     fDiphotonEvent->numPUplus = _numPUplus;
397     fDiphotonEvent->mass = _mass;
398     fDiphotonEvent->ptgg = _ptgg;
399     fDiphotonEvent->costheta = ThreeVector(phHard->Mom()).Unit().Dot(ThreeVector(phSoft->Mom()).Unit());
400     fDiphotonEvent->evt = GetEventHeader()->EvtNum();
401     fDiphotonEvent->run = GetEventHeader()->RunNum();
402     fDiphotonEvent->lumi = GetEventHeader()->LumiSec();
403     fDiphotonEvent->evtcat = evtCat;
404    
405     PhotonPairSelectorPhoton *ph1 = static_cast<PhotonPairSelectorPhoton*>(fDiphotonEvent->photons[0]);
406     ph1->SetVars(phHard,phgen1);
407    
408     PhotonPairSelectorPhoton *ph2 = static_cast<PhotonPairSelectorPhoton*>(fDiphotonEvent->photons[1]);
409     ph2->SetVars(phSoft,phgen2);
410    
411     hCiCTuple->Fill();
412     }
413    
414     // Float_t fillEvent[] = { _tRho,
415     // _pth,
416     // _decayZ,
417     // _theVtxZ,
418     // _numPU,
419     // _mass,
420     // _ptgg,
421     // _evtNum1,
422     // _evtNum2,
423     // _runNum,
424     // _lumiSec,
425     // (Float_t) catPh1,
426     // (Float_t) catPh2,
427     // evtCat
428     // };
429 fabstoec 1.1
430     // to keep the Tree slim, only add in case we haqve found a passing pair...
431 bendavid 1.4 // if(_mass > 0.) {
432     // hCiCTuple->Fill(fillEvent);
433 fabstoec 1.1
434 bendavid 1.4
435    
436    
437 fabstoec 1.1 return;
438    
439     }
440    
441     //--------------------------------------------------------------------------------------------------
442     void PhotonPairSelector::SlaveBegin()
443     {
444     // Run startup code on the computer (slave) doing the actual analysis. Here,
445     // we just request the photon collection branch.
446    
447     ReqEventObject(fPhotonBranchName, fPhotons, fPhotonsFromBranch);
448     ReqEventObject(fTrackBranchName, fTracks, true);
449     ReqEventObject(fElectronName, fElectrons, true);
450     ReqEventObject(fPileUpDenName, fPileUpDen, true);
451     ReqEventObject(fPVName, fPV, fPVFromBranch);
452     ReqEventObject(fConversionName, fConversions,true);
453     ReqEventObject(fBeamspotName, fBeamspot, true);
454     ReqEventObject(fPFCandName, fPFCands, true);
455    
456     if (!fIsData) {
457     ReqBranch(fPileUpName, fPileUp);
458     ReqBranch(fMCParticleName, fMCParticles);
459     }
460    
461     if (fPhotonSelType.CompareTo("CiCSelection") == 0)
462     fPhSelType = kCiCPhSelection;
463     else if (fPhotonSelType.CompareTo("MITSelection") == 0)
464     fPhSelType = kMITPhSelection;
465     else
466     fPhSelType = kNoPhSelection;
467    
468     if (fVertexSelType.CompareTo("CiCSelection") == 0)
469     fVtxSelType = kCiCVtxSelection;
470     else if (fVertexSelType.CompareTo("MITSelection") == 0)
471     fVtxSelType = kMITVtxSelection;
472     else
473     fVtxSelType = kStdVtxSelection;
474    
475 bendavid 1.4 PhotonPairSelectorDiphotonEvent::Class()->IgnoreTObjectStreamer();
476     PhotonPairSelectorPhoton::Class()->IgnoreTObjectStreamer();
477    
478     fDiphotonEvent = new PhotonPairSelectorDiphotonEvent;
479     hCiCTuple = new TTree(fTupleName.Data(),fTupleName.Data());
480     hCiCTuple->Branch("dphevent",fDiphotonEvent);
481    
482    
483     //hCiCTuple = new TNtuple(fTupleName.Data(),fTupleName.Data(),"rho:higgspt:higgsZ:vtxZ:numPU:mass:ptgg:evtnum1:evtnum2:runnum:lumisec:ph1Cat:ph2Cat:evtCat");
484 fabstoec 1.1
485     AddOutput(hCiCTuple);
486    
487     }
488    
489     // ----------------------------------------------------------------------------------------
490     // some helpfer functions....
491     void PhotonPairSelector::FindHiggsPtAndZ(Float_t& pt, Float_t& decayZ) {
492    
493     pt = -999.;
494     decayZ = -999.;
495    
496     // loop over all GEN particles and look for status 1 photons
497     for(UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
498     const MCParticle* p = fMCParticles->At(i);
499     if( !(p->Is(MCParticle::kH)) ) continue;
500     pt=p->Pt();
501     decayZ = p->DecayVertex().Z();
502     break;
503     }
504    
505     return;
506     }
507    
508     // this routine looks for the idx of the run-range
509     Int_t PhotonPairSelector::FindRunRangeIdx(UInt_t run) {
510     Int_t runRange=-1;
511     for(UInt_t iRun = 0; iRun<fRunStart.size(); ++iRun) {
512     if( run >= fRunStart[iRun] && run <= fRunEnd[iRun]) {
513     runRange = (Int_t) iRun;
514     return runRange;
515     }
516     }
517     return runRange;
518     }
519    
520    
521     Double_t PhotonPairSelector::GetDataEnCorr(Int_t runRange, PhotonTools::CiCBaseLineCats cat) {
522     switch( cat ) {
523     case PhotonTools::kCiCCat1:
524     return fDataEnCorr_EB_hR9[runRange];
525     case PhotonTools::kCiCCat2:
526     return fDataEnCorr_EB_lR9[runRange];
527     case PhotonTools::kCiCCat3:
528     return fDataEnCorr_EE_hR9[runRange];
529     case PhotonTools::kCiCCat4:
530     return fDataEnCorr_EE_lR9[runRange];
531     default:
532     return 1.;
533     }
534     }
535    
536    
537     Double_t PhotonPairSelector::GetMCSmearFac(PhotonTools::CiCBaseLineCats cat) {
538     switch( cat ) {
539     case PhotonTools::kCiCCat1:
540     return fMCSmear_EB_hR9;
541     case PhotonTools::kCiCCat2:
542     return fMCSmear_EB_lR9;
543     case PhotonTools::kCiCCat3:
544     return fMCSmear_EE_hR9;
545     case PhotonTools::kCiCCat4:
546     return fMCSmear_EE_lR9;
547     default:
548     return 1.;
549     }
550     }
551    
552     Float_t PhotonPairSelector::GetEventCat(PhotonTools::CiCBaseLineCats cat1, PhotonTools::CiCBaseLineCats cat2) {
553    
554     bool ph1IsEB = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat2);
555     bool ph2IsEB = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat2);
556    
557     bool ph1IsHR9 = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat3);
558     bool ph2IsHR9 = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat3);
559    
560     if( ph1IsEB && ph2IsEB )
561     return ( ph1IsHR9 && ph2IsHR9 ? 0. : 1.);
562    
563     return ( ph1IsHR9 && ph2IsHR9 ? 2. : 3.);
564     }
565 bendavid 1.4
566     const MCParticle *PhotonPairSelector::MatchMC(const Photon *ph) const
567     {
568    
569     for (UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
570     const MCParticle *p = fMCParticles->At(i);
571     if ( p->AbsPdgId()==22 && p->IsGenerated() && MathUtils::DeltaR(*ph,*p) < 0.3 && p->Mother() && (p->Mother()->AbsPdgId()==25 || p->Mother()->AbsPdgId()<=21) ) {
572     return p;
573     }
574     }
575     return 0;
576    
577     }
578    
579     void PhotonPairSelectorPhoton::SetVars(const Photon *p, const MCParticle *m) {
580     e = p->E();
581     pt = p->Pt();
582     eta = p->Eta();
583     phi = p->Phi();
584     r9 = p->R9();
585     e5x5 = p->E55();
586     const SuperCluster *s = p->SCluster();
587     sce = s->Energy();
588     scrawe = s->RawEnergy();
589     scpse = s->PreshowerEnergy();
590     sceta = s->Eta();
591     scphi = s->Phi();
592     isbarrel = (s->AbsEta()<1.5);
593     isr9reco = (isbarrel && r9>0.94) || (!isbarrel && r9>0.95);
594     isr9cat = (r9>0.94);
595    
596     if (isbarrel) {
597     if (isr9cat) phcat = 1;
598     else phcat = 2;
599     }
600     else {
601     if (isr9cat) phcat = 3;
602     else phcat = 4;
603     }
604    
605     if (m) {
606     ispromptgen = kTRUE;
607     gene = m->E();
608     genpt = m->Pt();
609     geneta = m->Eta();
610     genphi = m->Phi();
611     }
612     else {
613     ispromptgen = kFALSE;
614     gene = -99.;
615     genpt = -99.;
616     geneta = -99.;
617     genphi = -99.;
618     }
619    
620     }