ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonPairSelector.cc
Revision: 1.7
Committed: Wed Jul 27 17:50:52 2011 UTC (13 years, 9 months ago) by fabstoec
Content type: text/plain
Branch: MAIN
Changes since 1.6: +10 -5 lines
Log Message:
*** empty log message ***

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 bendavid 1.6 #include "MitPhysics/Utils/interface/PhotonFix.h"
9 bendavid 1.5 #include "TDataMember.h"
10 fabstoec 1.1 #include <TNtuple.h>
11     #include <TRandom3.h>
12 bendavid 1.6 #include <TSystem.h>
13 fabstoec 1.1
14     using namespace mithep;
15    
16     ClassImp(mithep::PhotonPairSelector)
17 bendavid 1.4 ClassImp(mithep::PhotonPairSelectorPhoton)
18     ClassImp(mithep::PhotonPairSelectorDiphotonEvent)
19    
20 fabstoec 1.1
21     //--------------------------------------------------------------------------------------------------
22     PhotonPairSelector::PhotonPairSelector(const char *name, const char *title) :
23     // Base Module...
24     BaseMod (name,title),
25    
26     // define all the Branches to load
27     fPhotonBranchName (Names::gkPhotonBrn),
28     fElectronName (Names::gkElectronBrn),
29     fConversionName (Names::gkMvfConversionBrn),
30     fTrackBranchName (Names::gkTrackBrn),
31     fPileUpDenName (Names::gkPileupEnergyDensityBrn),
32     fPVName (Names::gkPVBeamSpotBrn),
33     fBeamspotName (Names::gkBeamSpotBrn),
34     fPFCandName (Names::gkPFCandidatesBrn),
35     // MC specific stuff...
36     fMCParticleName (Names::gkMCPartBrn),
37     fPileUpName (Names::gkPileupInfoBrn),
38    
39     fGoodPhotonsName (ModNames::gkGoodPhotonsName),
40    
41     // ----------------------------------------
42     // Selection Types
43     fPhotonSelType ("NoSelection"),
44     fVertexSelType ("StdSelection"),
45     fPhSelType (kNoPhSelection),
46     fVtxSelType (kStdVtxSelection),
47    
48     // ----------------------------------------
49     fPhotonPtMin (20.0),
50     fPhotonEtaMax (2.5),
51    
52     fLeadingPtMin (40.0),
53     fTrailingPtMin (30.0),
54    
55     fIsData (false),
56     fPhotonsFromBranch (true),
57     fPVFromBranch (true),
58    
59     // ----------------------------------------
60     // collections....
61     fPhotons (0),
62     fElectrons (0),
63     fConversions (0),
64     fTracks (0),
65     fPileUpDen (0),
66     fPV (0),
67     fBeamspot (0),
68     fPFCands (0),
69     fMCParticles (0),
70     fPileUp (0),
71    
72     // ---------------------------------------
73     fDataEnCorr_EB_hR9 (0.),
74     fDataEnCorr_EB_lR9 (0.),
75     fDataEnCorr_EE_hR9 (0.),
76     fDataEnCorr_EE_lR9 (0.),
77    
78     fRunStart (0),
79     fRunEnd (0),
80    
81     fMCSmear_EB_hR9 (0.),
82     fMCSmear_EB_lR9 (0.),
83     fMCSmear_EE_hR9 (0.),
84     fMCSmear_EE_lR9 (0.),
85    
86     // ---------------------------------------
87     rng (new TRandom3()),
88    
89     // ---------------------------------------
90     fDoDataEneCorr (true),
91     fDoMCSmear (true),
92 fabstoec 1.2 fDoVtxSelection (true),
93     fApplyEleVeto (true),
94    
95     fTupleName ("hCiCtuple")
96 fabstoec 1.1
97     {
98     // Constructor.
99     }
100    
101     PhotonPairSelector::~PhotonPairSelector(){
102     if(rng) delete rng;
103     }
104    
105     //--------------------------------------------------------------------------------------------------
106     void PhotonPairSelector::Process()
107     {
108     // ------------------------------------------------------------
109     // Process entries of the tree.
110     LoadEventObject(fPhotonBranchName, fPhotons);
111     LoadEventObject(fElectronName, fElectrons);
112     LoadEventObject(fConversionName, fConversions);
113     LoadEventObject(fTrackBranchName, fTracks);
114     LoadEventObject(fPileUpDenName, fPileUpDen);
115     LoadEventObject(fPVName, fPV);
116     LoadEventObject(fBeamspotName, fBeamspot);
117     LoadEventObject(fPFCandName, fPFCands);
118    
119 bendavid 1.6
120 fabstoec 1.1
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 bendavid 1.6
138    
139 fabstoec 1.2
140 fabstoec 1.1 const BaseVertex *bsp = dynamic_cast<const BaseVertex*>(fBeamspot->At(0));
141    
142     // ------------------------------------------------------------
143     // Get Event header for Run info etc.
144     const EventHeader* evtHead = this->GetEventHeader();
145     unsigned int evtNum = evtHead->EvtNum();
146 fabstoec 1.7 //Float_t _evtNum1 = (Float_t) ( (int) (evtNum/10000.) );
147     //Float_t _evtNum2 = (Float_t) ( (int) (evtNum % 10000) );
148 fabstoec 1.1 UInt_t runNumber = evtHead->RunNum();
149     Float_t _runNum = (Float_t) runNumber;
150     Float_t _lumiSec = (Float_t) evtHead->LumiSec();
151    
152     // ------------------------------------------------------------
153     // here we'll store the preselected Photons (and which CiCCategory they are...)
154     PhotonOArr* preselPh = new PhotonOArr;
155     std::vector<PhotonTools::CiCBaseLineCats> preselCat;
156     preselCat.resize(0);
157    
158     // 1. we do the pre-selection; but keep the non-passing photons in a secont container...
159     for (UInt_t i=0; i<fPhotons->GetEntries(); ++i) {
160     const Photon *ph = fPhotons->At(i);
161    
162     if(ph->SCluster()->AbsEta()>= fPhotonEtaMax || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) continue;
163     if(ph->Et() < fPhotonPtMin) continue;
164     if(ph->HadOverEm() > 0.15) continue;
165     if(ph->IsEB()) {
166     if(ph->CoviEtaiEta() > 0.013) continue;
167     } else {
168     if(ph->CoviEtaiEta() > 0.03) continue;
169     }
170     preselPh->Add(ph);
171 fabstoec 1.2 }
172    
173     // Sorry... need the second loop here in order to sort & assign the right Categories..
174     preselPh->Sort();
175     for(unsigned int iPh = 0; iPh <preselPh->GetEntries(); ++iPh) {
176     const Photon* ph = preselPh->At(iPh);
177 fabstoec 1.1 preselCat.push_back(PhotonTools::CiCBaseLineCat(ph));
178     }
179    
180     // ------------------------------------------------------------
181     // compute how many pairs there are ...
182     unsigned int numPairs = 0;
183     if( preselPh->GetEntries() > 0) numPairs = (preselPh->GetEntries()-1)*preselPh->GetEntries()/2;
184     // ... and create all possible pairs of pre-selected photons
185     std::vector<unsigned int> idx1st;
186     std::vector<unsigned int> idx2nd;
187     std::vector<PhotonTools::CiCBaseLineCats> cat1st;
188     std::vector<PhotonTools::CiCBaseLineCats> cat2nd;
189     // ... this will be used to store whether a givne pair passes the cuts
190     std::vector<bool> pairPasses;
191    
192     if(numPairs > 0) {
193     for(unsigned int i1st = 0; i1st <preselPh->GetEntries() - 1; ++i1st) {
194     for(unsigned int i2nd = i1st + 1; i2nd <preselPh->GetEntries(); ++i2nd) {
195     idx1st.push_back(i1st);
196     idx2nd.push_back(i2nd);
197     pairPasses.push_back(true);
198     }
199     }
200     }
201    
202     // ------------------------------------------------------------
203     // array to store the index of 'chosen Vtx' for each pair
204     const Vertex** theVtx = new const Vertex*[numPairs]; // holds the 'chosen' Vtx for each Pair
205     Photon** fixPh1st = new Photon*[numPairs]; // holds the 1st Photon for each Pair
206     Photon** fixPh2nd = new Photon*[numPairs]; // holds the 2nd photon for each Pair
207    
208    
209     // store pair-indices for pairs passing the selection
210     std::vector<unsigned int> passPairs;
211     passPairs.resize(0);
212    
213     // ------------------------------------------------------------
214     // Loop over all Pairs and to the 'incredible machine' running....
215     for(unsigned int iPair = 0; iPair < numPairs; ++iPair) {
216    
217     // first we need a hard copy of the incoming photons
218     fixPh1st[iPair] = new Photon(*preselPh->At(idx1st[iPair]));
219     fixPh2nd[iPair] = new Photon(*preselPh->At(idx2nd[iPair]));
220     // we also store the category, so we don't have to ask all the time...
221     cat1st.push_back(preselCat[idx1st[iPair]]);
222     cat2nd.push_back(preselCat[idx2nd[iPair]]);
223    
224     // now we dicide if we either scale (Data) or Smear (MC) the Photons
225     if (fIsData) {
226     if(fDoDataEneCorr) {
227     // statring with scale = 1.
228     double scaleFac1 = 1.;
229     double scaleFac2 = 1.;
230     // checking the run Rangees ...
231     Int_t runRange = FindRunRangeIdx(runNumber);
232     if(runRange > -1) {
233     scaleFac1 += GetDataEnCorr(runRange, cat1st[iPair]);
234     scaleFac2 += GetDataEnCorr(runRange, cat2nd[iPair]);
235     }
236     PhotonTools::ScalePhoton(fixPh1st[iPair], scaleFac1);
237     PhotonTools::ScalePhoton(fixPh2nd[iPair], scaleFac2);
238     }
239     } else {
240     if(fDoMCSmear) {
241     // get the seed to do deterministic smearing...
242     UInt_t seedBase = (UInt_t) evtNum + (UInt_t) _runNum + (UInt_t) _lumiSec;
243     UInt_t seed1 = seedBase + (UInt_t) fixPh1st[iPair]->E() + (UInt_t) (TMath::Abs(10.*fixPh1st[iPair]->SCluster()->Eta()));
244     UInt_t seed2 = seedBase + (UInt_t) fixPh2nd[iPair]->E() + (UInt_t) (TMath::Abs(10.*fixPh2nd[iPair]->SCluster()->Eta()));
245     // get the smearing for MC photons..
246 fabstoec 1.3
247 fabstoec 1.1 double width1 = GetMCSmearFac(cat1st[iPair]);
248     double width2 = GetMCSmearFac(cat2nd[iPair]);
249 fabstoec 1.3
250 fabstoec 1.1 PhotonTools::SmearPhoton(fixPh1st[iPair], rng, width1, seed1);
251     PhotonTools::SmearPhoton(fixPh2nd[iPair], rng, width2, seed2);
252 fabstoec 1.3
253 fabstoec 1.1 }
254     }
255    
256     // store the vertex for this pair
257     switch( fVtxSelType ){
258     case kStdVtxSelection:
259     theVtx[iPair] = fPV->At(0);
260     break;
261     case kCiCVtxSelection:
262     theVtx[iPair] = VertexTools::findVtxBasicRanking(fixPh1st[iPair],fixPh2nd[iPair], bsp, fPV, fConversions);
263     break;
264     case kMITVtxSelection:
265     // need PFCandidate Collection
266     theVtx[iPair] = VertexTools::BestVtx(fPFCands, fPV, bsp, mithep::FourVector((fixPh1st[iPair]->Mom()+fixPh2nd[iPair]->Mom())));
267     break;
268     default:
269     theVtx[iPair] = fPV->At(0);
270 fabstoec 1.2
271 fabstoec 1.1 }
272 fabstoec 1.2
273 fabstoec 1.1 // fix the kinematics for both events
274     FourVectorM newMom1st = fixPh1st[iPair]->MomVtx(theVtx[iPair]->Position());
275     FourVectorM newMom2nd = fixPh2nd[iPair]->MomVtx(theVtx[iPair]->Position());
276     fixPh1st[iPair]->SetMom(newMom1st.X(), newMom1st.Y(), newMom1st.Z(), newMom1st.E());
277     fixPh2nd[iPair]->SetMom(newMom2nd.X(), newMom2nd.Y(), newMom2nd.Z(), newMom2nd.E());
278    
279     // check if both photons pass the CiC selection
280     // FIX-ME: Add other possibilities....
281     bool pass1 = false;
282     bool pass2 = false;
283     switch( fVtxSelType ){
284     case kNoPhSelection:
285     pass1 = ( fixPh1st[iPair]->Pt() > fLeadingPtMin );
286     pass2 = ( fixPh2nd[iPair]->Pt() > fTrailingPtMin );
287     break;
288     case kCiCPhSelection:
289 fabstoec 1.3
290    
291 fabstoec 1.2 pass1 = PhotonTools::PassCiCSelection(fixPh1st[iPair], theVtx[iPair], fTracks, fElectrons, fPV, _tRho, fLeadingPtMin, fApplyEleVeto);
292     if(pass1) pass2 = PhotonTools::PassCiCSelection(fixPh2nd[iPair], theVtx[iPair], fTracks, fElectrons, fPV, _tRho, fTrailingPtMin, fApplyEleVeto);
293 fabstoec 1.3
294 fabstoec 1.1 break;
295     case kMITPhSelection:
296 fabstoec 1.3 // FIX-ME: This is a place-holder.. MIT guys: Please work hard... ;)
297 fabstoec 1.1 pass1 = ( fixPh1st[iPair]->Pt() > fLeadingPtMin );
298     pass2 = ( fixPh2nd[iPair]->Pt() > fTrailingPtMin );
299     break;
300     default:
301     pass1 = true;
302     pass2 = true;
303     }
304     // finally, if both Photons pass the selections, add the pair to the 'passing Pairs)
305     if( pass1 && pass2 ) passPairs.push_back(iPair);
306     }
307    
308    
309     // ---------------------------------------------------------------
310     // ... we're almost done, stau focused...
311     // loop over all passing pairs and find the one with the highest sum Et
312     const Vertex* _theVtx = NULL;
313     Photon* phHard = NULL;
314     Photon* phSoft = NULL;
315    
316     PhotonTools::CiCBaseLineCats catPh1 = PhotonTools::kCiCNoCat;
317     PhotonTools::CiCBaseLineCats catPh2 = PhotonTools::kCiCNoCat;
318    
319     double maxSumEt = 0.;
320     for(unsigned int iPair=0; iPair<passPairs.size(); ++iPair){
321     double sumEt = fixPh1st[passPairs[iPair]]->Et();
322     sumEt += fixPh2nd[passPairs[iPair]]->Et();
323     if( sumEt > maxSumEt ) {
324     maxSumEt = sumEt;
325     phHard = fixPh1st[passPairs[iPair]];
326     phSoft = fixPh2nd[passPairs[iPair]];
327     catPh1 = cat1st[passPairs[iPair]];
328     catPh2 = cat2nd[passPairs[iPair]];
329     _theVtx = theVtx[iPair];
330     }
331     }
332    
333     // ---------------------------------------------------------------
334     // we have the Photons (*PARTY*)... compute some useful qunatities
335    
336     Float_t _theVtxZ = -999.;
337    
338     if(phHard && phSoft) {
339     GoodPhotons->AddOwned(phHard);
340     GoodPhotons->AddOwned(phSoft);
341     }
342    
343     if(_theVtx) _theVtxZ=_theVtx->Position().Z();
344    
345     // sort according to pt
346     GoodPhotons->Sort();
347    
348     // add to event for other modules to use
349     AddObjThisEvt(GoodPhotons);
350    
351     // delete auxiliary photon collection...
352     delete preselPh;
353     delete[] theVtx;
354    
355     // Fill the useful information (mass and di-photon pt)
356     bool doFill = ( phHard && phSoft );
357 bendavid 1.4 if (!doFill) return;
358 bendavid 1.6
359     if( !fIsData ) {
360     LoadBranch(fMCParticleName);
361     LoadBranch(fPileUpName);
362     }
363 bendavid 1.4
364 bendavid 1.6 if( !fIsData ) {
365     for (UInt_t i=0; i<fPileUp->GetEntries(); ++i) {
366     const PileupInfo *puinfo = fPileUp->At(i);
367     if (puinfo->GetBunchCrossing()==0) _numPU = puinfo->GetPU_NumInteractions();
368     else if (puinfo->GetBunchCrossing() == -1) _numPUminus = puinfo->GetPU_NumInteractions();
369     else if (puinfo->GetBunchCrossing() == 1) _numPUplus = puinfo->GetPU_NumInteractions();
370     }
371     }
372    
373 fabstoec 1.1 Float_t _mass = ( doFill ? (phHard->Mom()+phSoft->Mom()).M() : -100.);
374     Float_t _ptgg = ( doFill ? (phHard->Mom()+phSoft->Mom()).Pt() : -100.);
375 bendavid 1.4
376 fabstoec 1.1 // in case of a MC event, try to find Higgs and Higgs decay Z poisition
377     Float_t _pth = -100.;
378     Float_t _decayZ = -100.;
379     if( !fIsData ) FindHiggsPtAndZ(_pth, _decayZ);
380    
381     Float_t evtCat = -1.;
382     if( doFill ) {
383     evtCat = GetEventCat(catPh1, catPh2);
384     if(_ptgg < 40.) evtCat += 4.;
385     }
386 bendavid 1.4
387 fabstoec 1.7 const MCParticle *phgen1 = NULL;
388     const MCParticle *phgen2 = NULL;
389    
390     if(!fIsData) {
391     phgen1 = PhotonTools::MatchMC(phHard,fMCParticles);
392     phgen2 = PhotonTools::MatchMC(phSoft,fMCParticles);
393     }
394 fabstoec 1.1
395 bendavid 1.4 Float_t _gencostheta = -99.;
396     if (phgen1 && phgen2) {
397     _gencostheta = ThreeVector(phgen1->Mom()).Unit().Dot(ThreeVector(phgen2->Mom()).Unit());
398     }
399    
400     if(_mass > 0.) {
401     fDiphotonEvent->rho = _tRho;
402     fDiphotonEvent->genHiggspt = _pth;
403     fDiphotonEvent->genHiggsZ = _decayZ;
404     fDiphotonEvent->gencostheta = _gencostheta;
405     fDiphotonEvent->vtxZ = _theVtxZ;
406 bendavid 1.6 fDiphotonEvent->nVtx = fPV->GetEntries();
407 bendavid 1.4 fDiphotonEvent->numPU = _numPU;
408     fDiphotonEvent->numPUminus = _numPUminus;
409     fDiphotonEvent->numPUplus = _numPUplus;
410     fDiphotonEvent->mass = _mass;
411     fDiphotonEvent->ptgg = _ptgg;
412     fDiphotonEvent->costheta = ThreeVector(phHard->Mom()).Unit().Dot(ThreeVector(phSoft->Mom()).Unit());
413     fDiphotonEvent->evt = GetEventHeader()->EvtNum();
414     fDiphotonEvent->run = GetEventHeader()->RunNum();
415     fDiphotonEvent->lumi = GetEventHeader()->LumiSec();
416     fDiphotonEvent->evtcat = evtCat;
417 bendavid 1.5
418     fDiphotonEvent->photons[0].SetVars(phHard,phgen1);
419     fDiphotonEvent->photons[1].SetVars(phSoft,phgen2);
420 bendavid 1.4
421 bendavid 1.6 Float_t ph1ecor = fDiphotonEvent->photons[0].Ecor();
422     Float_t ph1ecorerr = fDiphotonEvent->photons[0].Ecorerr();
423     Float_t ph2ecor = fDiphotonEvent->photons[1].Ecor();
424     Float_t ph2ecorerr = fDiphotonEvent->photons[1].Ecorerr();
425    
426     fDiphotonEvent->masscor = TMath::Sqrt(2.0*ph1ecor*ph2ecor*(1.0-fDiphotonEvent->costheta));
427     fDiphotonEvent->masscorerr = 0.5*fDiphotonEvent->masscor*TMath::Sqrt(ph1ecorerr*ph1ecorerr/ph1ecor/ph1ecor + ph2ecorerr*ph2ecorerr/ph2ecor/ph2ecor);
428    
429     //printf("r9 = %5f, photon sigieie = %5f, seed sigieie = %5f\n",phHard->R9(),phHard->CoviEtaiEta(),sqrt(phHard->SCluster()->Seed()->CoviEtaiEta()));
430 bendavid 1.4
431 bendavid 1.5 hCiCTuple->Fill();
432 bendavid 1.4
433 bendavid 1.5 fSinglePhoton->SetVars(phHard,phgen1);
434     hCiCTupleSingle->Fill();
435     fSinglePhoton->SetVars(phSoft,phgen2);
436     hCiCTupleSingle->Fill();
437 bendavid 1.4
438 bendavid 1.5 }
439 bendavid 1.4
440 fabstoec 1.1 return;
441    
442     }
443    
444     //--------------------------------------------------------------------------------------------------
445     void PhotonPairSelector::SlaveBegin()
446     {
447     // Run startup code on the computer (slave) doing the actual analysis. Here,
448     // we just request the photon collection branch.
449    
450     ReqEventObject(fPhotonBranchName, fPhotons, fPhotonsFromBranch);
451     ReqEventObject(fTrackBranchName, fTracks, true);
452     ReqEventObject(fElectronName, fElectrons, true);
453     ReqEventObject(fPileUpDenName, fPileUpDen, true);
454     ReqEventObject(fPVName, fPV, fPVFromBranch);
455     ReqEventObject(fConversionName, fConversions,true);
456     ReqEventObject(fBeamspotName, fBeamspot, true);
457     ReqEventObject(fPFCandName, fPFCands, true);
458    
459     if (!fIsData) {
460     ReqBranch(fPileUpName, fPileUp);
461     ReqBranch(fMCParticleName, fMCParticles);
462     }
463    
464     if (fPhotonSelType.CompareTo("CiCSelection") == 0)
465     fPhSelType = kCiCPhSelection;
466     else if (fPhotonSelType.CompareTo("MITSelection") == 0)
467     fPhSelType = kMITPhSelection;
468     else
469     fPhSelType = kNoPhSelection;
470    
471     if (fVertexSelType.CompareTo("CiCSelection") == 0)
472     fVtxSelType = kCiCVtxSelection;
473     else if (fVertexSelType.CompareTo("MITSelection") == 0)
474     fVtxSelType = kMITVtxSelection;
475     else
476     fVtxSelType = kStdVtxSelection;
477    
478 bendavid 1.6
479     //initialize photon energy corrections
480     //PhotonFix::initialise("4_2",std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFix.dat")).Data()));
481 bendavid 1.4
482     fDiphotonEvent = new PhotonPairSelectorDiphotonEvent;
483 bendavid 1.5 fSinglePhoton = new PhotonPairSelectorPhoton;
484    
485    
486 bendavid 1.4 hCiCTuple = new TTree(fTupleName.Data(),fTupleName.Data());
487 bendavid 1.5 TString singlename = fTupleName + TString("Single");
488     hCiCTupleSingle = new TTree(singlename,singlename);
489 fabstoec 1.1
490 bendavid 1.5 //make flattish tree from classes so we don't have to rely on dictionaries for reading later
491     TClass *eclass = TClass::GetClass("mithep::PhotonPairSelectorDiphotonEvent");
492     TClass *pclass = TClass::GetClass("mithep::PhotonPairSelectorPhoton");
493     TList *elist = eclass->GetListOfDataMembers();
494     TList *plist = pclass->GetListOfDataMembers();
495    
496     for (int i=0; i<elist->GetEntries(); ++i) {
497     const TDataMember *tdm = static_cast<const TDataMember*>(elist->At(i));
498     if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
499     TString typestring;
500     if (TString(tdm->GetTypeName())=="Char_t") typestring = "B";
501     else if (TString(tdm->GetTypeName())=="UChar_t") typestring = "b";
502     else if (TString(tdm->GetTypeName())=="Short_t") typestring = "S";
503     else if (TString(tdm->GetTypeName())=="UShort_t") typestring = "s";
504     else if (TString(tdm->GetTypeName())=="Int_t") typestring = "I";
505     else if (TString(tdm->GetTypeName())=="UInt_t") typestring = "i";
506     else if (TString(tdm->GetTypeName())=="Float_t") typestring = "F";
507     else if (TString(tdm->GetTypeName())=="Double_t") typestring = "D";
508     else if (TString(tdm->GetTypeName())=="Long64_t") typestring = "L";
509     else if (TString(tdm->GetTypeName())=="ULong64_t") typestring = "l";
510     else if (TString(tdm->GetTypeName())=="Bool_t") typestring = "O";
511     else continue;
512     //printf("%s %s: %i\n",tdm->GetTypeName(),tdm->GetName(),int(tdm->GetOffset()));
513     Char_t *addr = (Char_t*)fDiphotonEvent;
514     assert(sizeof(Char_t)==1);
515     hCiCTuple->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
516     hCiCTupleSingle->Branch(tdm->GetName(),addr + tdm->GetOffset(),TString::Format("%s/%s",tdm->GetName(),typestring.Data()));
517     }
518    
519     for (int iph=0; iph<2; ++iph) {
520     for (int i=0; i<plist->GetEntries(); ++i) {
521     const TDataMember *tdm = static_cast<const TDataMember*>(plist->At(i));
522     if (!(tdm->IsBasic() && tdm->IsPersistent())) continue;
523     TString typestring;
524     if (TString(tdm->GetTypeName())=="Char_t") typestring = "B";
525     else if (TString(tdm->GetTypeName())=="UChar_t") typestring = "b";
526     else if (TString(tdm->GetTypeName())=="Short_t") typestring = "S";
527     else if (TString(tdm->GetTypeName())=="UShort_t") typestring = "s";
528     else if (TString(tdm->GetTypeName())=="Int_t") typestring = "I";
529     else if (TString(tdm->GetTypeName())=="UInt_t") typestring = "i";
530     else if (TString(tdm->GetTypeName())=="Float_t") typestring = "F";
531     else if (TString(tdm->GetTypeName())=="Double_t") typestring = "D";
532     else if (TString(tdm->GetTypeName())=="Long64_t") typestring = "L";
533     else if (TString(tdm->GetTypeName())=="ULong64_t") typestring = "l";
534     else if (TString(tdm->GetTypeName())=="Bool_t") typestring = "O";
535     else continue;
536     //printf("%s\n",tdm->GetTypeName());
537     TString varname = TString::Format("ph%d.%s",iph+1,tdm->GetName());
538    
539     Char_t *addr = (Char_t*)&fDiphotonEvent->photons[iph];
540     assert(sizeof(Char_t)==1);
541     hCiCTuple->Branch(varname,addr+tdm->GetOffset(),TString::Format("%s/%s",varname.Data(),typestring.Data()));
542    
543     if (iph==0) {
544     TString singlename = TString::Format("ph.%s",tdm->GetName());
545     Char_t *addrsingle = (Char_t*)fSinglePhoton;
546     hCiCTupleSingle->Branch(singlename,addrsingle+tdm->GetOffset(),TString::Format("%s/%s",singlename.Data(),typestring.Data()));
547     }
548     }
549     }
550    
551    
552 fabstoec 1.1 AddOutput(hCiCTuple);
553 bendavid 1.5 AddOutput(hCiCTupleSingle);
554    
555 fabstoec 1.1
556     }
557    
558     // ----------------------------------------------------------------------------------------
559     // some helpfer functions....
560     void PhotonPairSelector::FindHiggsPtAndZ(Float_t& pt, Float_t& decayZ) {
561    
562     pt = -999.;
563     decayZ = -999.;
564    
565     // loop over all GEN particles and look for status 1 photons
566     for(UInt_t i=0; i<fMCParticles->GetEntries(); ++i) {
567     const MCParticle* p = fMCParticles->At(i);
568     if( !(p->Is(MCParticle::kH)) ) continue;
569     pt=p->Pt();
570     decayZ = p->DecayVertex().Z();
571     break;
572     }
573    
574     return;
575     }
576    
577     // this routine looks for the idx of the run-range
578     Int_t PhotonPairSelector::FindRunRangeIdx(UInt_t run) {
579     Int_t runRange=-1;
580     for(UInt_t iRun = 0; iRun<fRunStart.size(); ++iRun) {
581     if( run >= fRunStart[iRun] && run <= fRunEnd[iRun]) {
582     runRange = (Int_t) iRun;
583     return runRange;
584     }
585     }
586     return runRange;
587     }
588    
589    
590     Double_t PhotonPairSelector::GetDataEnCorr(Int_t runRange, PhotonTools::CiCBaseLineCats cat) {
591     switch( cat ) {
592     case PhotonTools::kCiCCat1:
593     return fDataEnCorr_EB_hR9[runRange];
594     case PhotonTools::kCiCCat2:
595     return fDataEnCorr_EB_lR9[runRange];
596     case PhotonTools::kCiCCat3:
597     return fDataEnCorr_EE_hR9[runRange];
598     case PhotonTools::kCiCCat4:
599     return fDataEnCorr_EE_lR9[runRange];
600     default:
601     return 1.;
602     }
603     }
604    
605    
606     Double_t PhotonPairSelector::GetMCSmearFac(PhotonTools::CiCBaseLineCats cat) {
607     switch( cat ) {
608     case PhotonTools::kCiCCat1:
609     return fMCSmear_EB_hR9;
610     case PhotonTools::kCiCCat2:
611     return fMCSmear_EB_lR9;
612     case PhotonTools::kCiCCat3:
613     return fMCSmear_EE_hR9;
614     case PhotonTools::kCiCCat4:
615     return fMCSmear_EE_lR9;
616     default:
617     return 1.;
618     }
619     }
620    
621     Float_t PhotonPairSelector::GetEventCat(PhotonTools::CiCBaseLineCats cat1, PhotonTools::CiCBaseLineCats cat2) {
622    
623     bool ph1IsEB = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat2);
624     bool ph2IsEB = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat2);
625    
626     bool ph1IsHR9 = (cat1 == PhotonTools::kCiCCat1 || cat1 == PhotonTools::kCiCCat3);
627     bool ph2IsHR9 = (cat2 == PhotonTools::kCiCCat1 || cat2 == PhotonTools::kCiCCat3);
628    
629     if( ph1IsEB && ph2IsEB )
630     return ( ph1IsHR9 && ph2IsHR9 ? 0. : 1.);
631    
632     return ( ph1IsHR9 && ph2IsHR9 ? 2. : 3.);
633     }
634 bendavid 1.4
635     void PhotonPairSelectorPhoton::SetVars(const Photon *p, const MCParticle *m) {
636     e = p->E();
637     pt = p->Pt();
638     eta = p->Eta();
639     phi = p->Phi();
640     r9 = p->R9();
641 bendavid 1.6 e3x3 = p->E33();
642 bendavid 1.4 e5x5 = p->E55();
643     const SuperCluster *s = p->SCluster();
644     sce = s->Energy();
645     scrawe = s->RawEnergy();
646     scpse = s->PreshowerEnergy();
647     sceta = s->Eta();
648     scphi = s->Phi();
649 bendavid 1.6 scnclusters = s->ClusterSize();
650     scnhits = s->NHits();
651     hovere = p->HadOverEm();
652     sigietaieta = p->CoviEtaiEta();
653 bendavid 1.4 isbarrel = (s->AbsEta()<1.5);
654     isr9reco = (isbarrel && r9>0.94) || (!isbarrel && r9>0.95);
655     isr9cat = (r9>0.94);
656    
657     if (isbarrel) {
658     if (isr9cat) phcat = 1;
659     else phcat = 2;
660     }
661     else {
662     if (isr9cat) phcat = 3;
663     else phcat = 4;
664     }
665    
666 bendavid 1.6 const BasicCluster *b = s->Seed();
667     sigiphiphi = TMath::Sqrt(b->CoviPhiiPhi());
668     if (isnan(sigiphiphi)) sigiphiphi = -99.;
669     covietaiphi = b->CoviEtaiPhi();
670     if (isnan(covietaiphi)) covietaiphi = -99.;
671     emax = b->EMax();
672     e2nd = b->E2nd();
673     etop = b->ETop();
674     ebottom = b->EBottom();
675     eleft = b->ELeft();
676     eright = b->ERight();
677     e1x3 = b->E1x3();
678     e3x1 = b->E3x1();
679     e1x5 = b->E1x5();
680     e2x2 = b->E2x2();
681     e4x4 = b->E4x4();
682     e2x5max = b->E2x5Max();
683     e2x5top = b->E2x5Top();
684     e2x5bottom = b->E2x5Bottom();
685     e2x5left = b->E2x5Left();
686     e2x5right = b->E2x5Right();
687    
688     //initialize photon energy corrections if needed
689     if (!PhotonFix::initialised()) {
690     PhotonFix::initialise("4_2",std::string((gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFix.dat")).Data()));
691     }
692    
693     PhotonFix fix(e,sceta,scphi,r9);
694     const Float_t dval = -99.;
695     ecor = fix.fixedEnergy();
696     ecorerr = fix.sigmaEnergy();
697     if (isbarrel) {
698     etac = fix.etaC();
699     etas = fix.etaS();
700     etam = fix.etaM();
701     phic = fix.phiC();
702     phis = fix.phiS();
703     phim = fix.phiM();
704     xz = dval;
705     xc = dval;
706     xs = dval;
707     xm = dval;
708     yz = dval;
709     yc = dval;
710     ys = dval;
711     ym = dval;
712     }
713     else {
714     etac = dval;
715     etas = dval;
716     etam = dval;
717     phic = dval;
718     phis = dval;
719     phim = dval;
720     xz = fix.xZ();
721     xc = fix.xC();
722     xs = fix.xS();
723     xm = fix.xM();
724     yz = fix.yZ();
725     yc = fix.yC();
726     ys = fix.yS();
727     ym = fix.yM();
728     }
729    
730     genz = -99.;
731 bendavid 1.4 if (m) {
732     ispromptgen = kTRUE;
733     gene = m->E();
734     genpt = m->Pt();
735     geneta = m->Eta();
736     genphi = m->Phi();
737 bendavid 1.6 const MCParticle *mm = m->DistinctMother();
738     if (mm) genz = mm->DecayVertex().Z();
739 bendavid 1.4 }
740     else {
741     ispromptgen = kFALSE;
742     gene = -99.;
743     genpt = -99.;
744     geneta = -99.;
745     genphi = -99.;
746     }
747    
748 fabstoec 1.7 }