ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonMvaMod.cc
Revision: 1.5
Committed: Tue May 29 16:22:41 2012 UTC (12 years, 11 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_028a
Changes since 1.4: +3 -1 lines
Log Message:
add ability to disable regression simply

File Contents

# User Rev Content
1 bendavid 1.1 #include "MitPhysics/Mods/interface/PhotonMvaMod.h"
2     #include "MitAna/DataTree/interface/PhotonCol.h"
3     #include "MitAna/DataTree/interface/PFCandidateCol.h"
4     #include "MitAna/DataTree/interface/StableData.h"
5     #include "MitAna/DataTree/interface/StableParticle.h"
6     #include "MitPhysics/Init/interface/ModNames.h"
7     #include "MitPhysics/Utils/interface/IsolationTools.h"
8     #include "MitPhysics/Utils/interface/PhotonTools.h"
9     #include "MitPhysics/Utils/interface/VertexTools.h"
10     #include "MitPhysics/Utils/interface/PhotonFix.h"
11     #include "MitPhysics/Utils/interface/MVATools.h"
12     #include "TDataMember.h"
13     #include <TNtuple.h>
14     #include <TRandom3.h>
15     #include <TSystem.h>
16     #include <TH1D.h>
17    
18     using namespace mithep;
19    
20     ClassImp(mithep::PhotonMvaMod)
21    
22     //--------------------------------------------------------------------------------------------------
23     PhotonMvaMod::PhotonMvaMod(const char *name, const char *title) :
24     // Base Module...
25     BaseMod (name,title),
26    
27     // define all the Branches to load
28     fPhotonBranchName (Names::gkPhotonBrn),
29     fElectronName (Names::gkElectronBrn),
30     fGoodElectronName (Names::gkElectronBrn),
31     fConversionName (Names::gkMvfConversionBrn),
32     fTrackBranchName (Names::gkTrackBrn),
33     fPileUpDenName (Names::gkPileupEnergyDensityBrn),
34     fPVName (Names::gkPVBeamSpotBrn),
35     fBeamspotName (Names::gkBeamSpotBrn),
36     fPFCandName (Names::gkPFCandidatesBrn),
37     // MC specific stuff...
38     fMCParticleName (Names::gkMCPartBrn),
39     fPileUpName (Names::gkPileupInfoBrn),
40    
41     fGoodPhotonsName (ModNames::gkGoodPhotonsName),
42    
43    
44    
45     // ----------------------------------------
46     fPhotonPtMin (20.0),
47     fPhotonEtaMax (2.5),
48    
49     fIsData (false),
50     fPhotonsFromBranch (true),
51     fPVFromBranch (true),
52     fGoodElectronsFromBranch (kTRUE),
53    
54     // ----------------------------------------
55     // collections....
56     fPhotons (0),
57     fElectrons (0),
58     fConversions (0),
59     fTracks (0),
60     fPileUpDen (0),
61     fPV (0),
62     fBeamspot (0),
63     fPFCands (0),
64     fMCParticles (0),
65     fPileUp (0),
66    
67     // ---------------------------------------
68     fDoRegression (kTRUE),
69     fPhFixString ("4_2"),
70 bendavid 1.2 fRegWeights (gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/gbrv2ph_52x.root")),
71 bendavid 1.1 // ---------------------------------------
72     fApplyEleVeto (true),
73     //MVA
74     fRegressionVersion(2)
75     {
76     // Constructor.
77     }
78    
79     PhotonMvaMod::~PhotonMvaMod(){
80    
81     }
82    
83     //--------------------------------------------------------------------------------------------------
84     void PhotonMvaMod::Process()
85     {
86     // ------------------------------------------------------------
87     // Process entries of the tree.
88     LoadEventObject(fPhotonBranchName, fPhotons);
89    
90     // -----------------------------------------------------------
91     // OUtput Photon Collection. It will ALWAYS conatrin either 0 or 2 Photons
92     PhotonOArr *GoodPhotons = new PhotonOArr;
93     GoodPhotons->SetName(fGoodPhotonsName);
94     GoodPhotons->SetOwner(kTRUE);
95     // add to event for other modules to use
96     AddObjThisEvt(GoodPhotons);
97    
98     if (fPhotons->GetEntries()<2) return;
99    
100     LoadEventObject(fPVName, fPV);
101 bendavid 1.4 LoadEventObject(fPileUpDenName, fPileUpDen);
102 bendavid 1.1
103     // ------------------------------------------------------------
104     // here we'll store the preselected Photons (and which CiCCategory they are...)
105     PhotonOArr* preselPh = new PhotonOArr;
106    
107     // 1. we do the pre-selection; but keep the non-passing photons in a secont container...
108     for (UInt_t i=0; i<fPhotons->GetEntries(); ++i) {
109     const Photon *ph = fPhotons->At(i);
110    
111     if(ph->SCluster()->AbsEta()>= fPhotonEtaMax || (ph->SCluster()->AbsEta()>=1.4442 && ph->SCluster()->AbsEta()<=1.566)) continue;
112     if(ph->Et() < fPhotonPtMin) continue;
113     if(ph->HadOverEm() > 0.15) continue;
114     if(ph->IsEB()) {
115 bendavid 1.3 if(ph->CoviEtaiEta() > 0.015) continue;
116 bendavid 1.1 } else {
117 bendavid 1.3 if(ph->CoviEtaiEta() > 0.035) continue;
118 bendavid 1.1 }
119    
120     preselPh->Add(ph);
121     }
122    
123     if (preselPh->GetEntries()<2) return;
124    
125     // Sorry... need the second loop here in order to sort & assign the right Categories..
126     //preselPh->Sort();
127     for(unsigned int iPh = 0; iPh <preselPh->GetEntries(); ++iPh) {
128     const Photon* ph = preselPh->At(iPh);
129     Photon *outph = new Photon(*ph);
130    
131     if (fDoRegression) {
132     if (!egcor.IsInitialized()) {
133 bendavid 1.2 egcor.Initialize(fPhFixString,fPhFixFile,fRegWeights);
134 bendavid 1.1 }
135    
136 bendavid 1.5 if (fRegressionVersion>0)
137     egcor.CorrectEnergyWithError(outph,fPV,fPileUpDen->At(0)->RhoKt6PFJets(),fRegressionVersion);
138    
139 bendavid 1.1 ThreeVectorC scpos = outph->SCluster()->Point();
140     outph->SetCaloPosXYZ(scpos.X(),scpos.Y(),scpos.Z());
141    
142     }
143    
144     GoodPhotons->AddOwned(outph);
145    
146     }
147    
148    
149    
150     // sort according to pt
151     GoodPhotons->Sort();
152    
153     // delete auxiliary photon collection...
154     delete preselPh;
155     //delete[] theVtx;
156    
157     return;
158    
159     }
160    
161     //--------------------------------------------------------------------------------------------------
162     void PhotonMvaMod::SlaveBegin()
163     {
164     // Run startup code on the computer (slave) doing the actual analysis. Here,
165     // we just request the photon collection branch.
166    
167     ReqEventObject(fPhotonBranchName, fPhotons, fPhotonsFromBranch);
168     ReqEventObject(fTrackBranchName, fTracks, true);
169     ReqEventObject(fElectronName, fElectrons, true);
170     ReqEventObject(fGoodElectronName, fGoodElectrons, fGoodElectronsFromBranch);
171     ReqEventObject(fPileUpDenName, fPileUpDen, true);
172     ReqEventObject(fPVName, fPV, fPVFromBranch);
173     ReqEventObject(fConversionName, fConversions,true);
174     ReqEventObject(fBeamspotName, fBeamspot, true);
175     ReqEventObject(fPFCandName, fPFCands, true);
176    
177     if (!fIsData) {
178     ReqBranch(fPileUpName, fPileUp);
179     ReqBranch(fMCParticleName, fMCParticles);
180     }
181    
182    
183     if (fIsData) {
184     fPhFixFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixGRPV22.dat");
185     }
186     else {
187     fPhFixFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat");
188     }
189    
190    
191     }
192