ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Mods/src/PhotonMvaMod.cc
Revision: 1.1
Committed: Sun Dec 11 00:03:04 2011 UTC (13 years, 4 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025e, Mit_025d
Log Message:
more photon updates for mva plus id analysis

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     fRegWeights (gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/gbrv2ph.root")),
71     // ---------------------------------------
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    
102    
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     if(ph->CoviEtaiEta() > 0.014) continue;
116     } else {
117     if(ph->CoviEtaiEta() > 0.034) continue;
118     }
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     egcor.Initialize(!fIsData,fPhFixString,fPhFixFile,fRegWeights);
134     }
135    
136     egcor.CorrectEnergyWithError(outph,fPV,fRegressionVersion);
137     ThreeVectorC scpos = outph->SCluster()->Point();
138     outph->SetCaloPosXYZ(scpos.X(),scpos.Y(),scpos.Z());
139    
140     }
141    
142     GoodPhotons->AddOwned(outph);
143    
144     }
145    
146    
147    
148     // sort according to pt
149     GoodPhotons->Sort();
150    
151     // delete auxiliary photon collection...
152     delete preselPh;
153     //delete[] theVtx;
154    
155     return;
156    
157     }
158    
159     //--------------------------------------------------------------------------------------------------
160     void PhotonMvaMod::SlaveBegin()
161     {
162     // Run startup code on the computer (slave) doing the actual analysis. Here,
163     // we just request the photon collection branch.
164    
165     ReqEventObject(fPhotonBranchName, fPhotons, fPhotonsFromBranch);
166     ReqEventObject(fTrackBranchName, fTracks, true);
167     ReqEventObject(fElectronName, fElectrons, true);
168     ReqEventObject(fGoodElectronName, fGoodElectrons, fGoodElectronsFromBranch);
169     ReqEventObject(fPileUpDenName, fPileUpDen, true);
170     ReqEventObject(fPVName, fPV, fPVFromBranch);
171     ReqEventObject(fConversionName, fConversions,true);
172     ReqEventObject(fBeamspotName, fBeamspot, true);
173     ReqEventObject(fPFCandName, fPFCands, true);
174    
175     if (!fIsData) {
176     ReqBranch(fPileUpName, fPileUp);
177     ReqBranch(fMCParticleName, fMCParticles);
178     }
179    
180    
181     if (fIsData) {
182     fPhFixFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixGRPV22.dat");
183     }
184     else {
185     fPhFixFile = gSystem->Getenv("CMSSW_BASE") + TString("/src/MitPhysics/data/PhotonFixSTART42V13.dat");
186     }
187    
188    
189     }
190