ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/plugins/L1RpcTreeAnalysis.cc
Revision: 1.27
Committed: Thu Jul 11 11:25:22 2013 UTC (11 years, 9 months ago) by akalinow
Content type: text/plain
Branch: MAIN
CVS Tags: Artur_11_07_2013
Changes since 1.26: +4 -26 lines
Log Message:
*last commit before migration to Git.

File Contents

# User Rev Content
1 konec 1.1 #include "L1RpcTreeAnalysis.h"
2    
3     #include <vector>
4     #include <iostream>
5     #include <cmath>
6     #include <iomanip>
7    
8     #include "TFile.h"
9     #include "TChain.h"
10     #include "TTree.h"
11     #include "TProfile.h"
12     #include "TH2F.h"
13     #include "TH1D.h"
14     #include "TGraphErrors.h"
15     #include "TF1.h"
16    
17     #include "UserCode/L1RpcTriggerAnalysis/interface/L1Obj.h"
18     #include "UserCode/L1RpcTriggerAnalysis/interface/EventObj.h"
19 konec 1.12 #include "UserCode/L1RpcTriggerAnalysis/interface/EventObjBXExtra.h"
20 konec 1.1 #include "UserCode/L1RpcTriggerAnalysis/interface/TrackObj.h"
21     #include "UserCode/L1RpcTriggerAnalysis/interface/MuonObj.h"
22     #include "UserCode/L1RpcTriggerAnalysis/interface/L1ObjColl.h"
23     #include "UserCode/L1RpcTriggerAnalysis/interface/SynchroCountsObj.h"
24 konec 1.7 #include "UserCode/L1RpcTriggerAnalysis/interface/DetCluDigiObj.h"
25 konec 1.5 #include "UserCode/L1RpcTriggerAnalysis/interface/TriggerMenuResultObj.h"
26 konec 1.17 #include "UserCode/L1RpcTriggerAnalysis/interface/HitSpecObj.h"
27 konec 1.1
28 konec 1.12
29 konec 1.1 #include "UserCode/L1RpcTriggerAnalysis/interface/ConverterRPCRawSynchroSynchroCountsObj.h"
30    
31 konec 1.9 L1RpcTreeAnalysis::L1RpcTreeAnalysis(const edm::ParameterSet & cfg)
32     : theConfig(cfg),
33 konec 1.17 theAnaMuonDistribution(0),
34     theAnaRpcVsOth(0),
35     theAnaRpcMisc(0),
36     theAnaEff(0),
37     theAnaDet(0),
38     theAnaEmu(0),
39     theAnaSynch(0),
40     theAnaClu(0),
41     theAnaTimingL1(0),
42     theAnaMenu(0),
43     theAnaEvent(0),
44     theAnaDigiSpec(0),
45     theAnaHitSpec(0),
46     thePatternProducer(0),
47 konec 1.18 thePatternProvider(0),
48     theAnaSiMuDistribution(0),
49 konec 1.19 theAnaOtfEff(0)
50 konec 1.17 {
51 konec 1.18 if (theConfig.exists("anaMuonDistribution")) theAnaMuonDistribution = new AnaMuonDistribution( cfg.getParameter<edm::ParameterSet>("anaMuonDistribution"));
52 konec 1.17 if (theConfig.exists("anaMenu")) theAnaMenu = new AnaMenu(theConfig.getParameter<edm::ParameterSet>("anaMenu"));
53     if (theConfig.exists("anaTimingL1")) theAnaTimingL1 = new AnaTimingL1( theConfig.getParameter<edm::ParameterSet>("anaTimingL1") );
54     if (theConfig.exists("anaEvent")) theAnaEvent = new AnaEvent(cfg.getParameter<edm::ParameterSet>("anaEvent") );
55     if (theConfig.exists("anaDigiSpec")) theAnaDigiSpec = new AnaDigiSpec(cfg.getParameter<edm::ParameterSet>("anaDigiSpec"));
56     if (theConfig.exists("anaHitSpec")) theAnaHitSpec = new AnaHitSpec(cfg.getParameter<edm::ParameterSet>("anaHitSpec"));
57     if (theConfig.exists("patternProducer")) thePatternProducer = new PatternManager(cfg.getParameter<edm::ParameterSet>("patternProducer"));
58     if (theConfig.exists("patternProvider")) thePatternProvider = new PatternManager(cfg.getParameter<edm::ParameterSet>("patternProvider"));
59 konec 1.18 if (theConfig.exists("anaSiMuDistribution")) theAnaSiMuDistribution = new AnaSiMuDistribution( cfg.getParameter<edm::ParameterSet>("anaSiMuDistribution"));
60 konec 1.19 if (theConfig.exists("anaOtfEff")) theAnaOtfEff = new AnaOtfEff( cfg.getParameter<edm::ParameterSet>("anaOtfEff"));
61 konec 1.20 if (theConfig.exists("anaEff")) theAnaEff = new AnaEff(cfg.getParameter<edm::ParameterSet>("anaEff") );
62     if (theConfig.exists("anaRpcVsOth")) theAnaRpcVsOth = new AnaRpcVsOth(cfg.getParameter<edm::ParameterSet>("anaRpcVsOth") );
63 konec 1.17
64     }
65 konec 1.1
66     void L1RpcTreeAnalysis::beginJob()
67     {
68     theHistos.SetOwner();
69    
70 konec 1.17 if (theAnaMuonDistribution) theAnaMuonDistribution->init(theHistos);
71     if (theAnaRpcVsOth) theAnaRpcVsOth->init(theHistos);
72     if (theAnaRpcMisc) theAnaRpcMisc->init(theHistos);
73     if (theAnaEff) theAnaEff->init(theHistos);
74     if (theAnaDet) theAnaDet->init(theHistos);
75     if (theAnaEmu) theAnaEmu->init(theHistos);
76     if (theAnaSynch) theAnaSynch->init(theHistos);
77     if (theAnaClu) theAnaClu->init(theHistos);
78     if (theAnaTimingL1) theAnaTimingL1->init(theHistos);
79     if (theAnaEvent) theAnaEvent->init(theHistos);
80     if (theAnaMenu) theAnaMenu->init(theHistos);
81     if (theAnaDigiSpec) theAnaDigiSpec->init(theHistos);
82     if (theAnaHitSpec) theAnaHitSpec->init(theHistos);
83 konec 1.18 if (theAnaSiMuDistribution) theAnaSiMuDistribution->init(theHistos);
84 konec 1.19 if (theAnaOtfEff) theAnaOtfEff->init(theHistos);
85 konec 1.17
86     if (thePatternProvider) thePatternProvider->beginJob();
87 konec 1.1 }
88    
89     void L1RpcTreeAnalysis::beginRun(const edm::Run& ru, const edm::EventSetup& es)
90     {
91 konec 1.17 if (theAnaSynch) theAnaSynch->beginRun(ru,es);
92 konec 1.1 }
93    
94     void L1RpcTreeAnalysis::analyze(const edm::Event&, const edm::EventSetup&)
95     {
96     //
97     // prevent multievent execution
98     //
99     static bool the_EMERGENCY_STOP = false;
100     if (the_EMERGENCY_STOP) {
101     std::cout <<"** L1RpcTreeAnalysis::analyze EMERGENCY_STOP fired, skip" << std::endl;
102     return;
103     }
104     the_EMERGENCY_STOP = true;
105    
106     //
107     // define input chain
108     //
109     TChain chain("tL1Rpc");
110     std::vector<std::string> treeFileNames = theConfig.getParameter<std::vector<std::string> >("treeFileNames");
111     for (std::vector<std::string>::const_iterator it = treeFileNames.begin(); it != treeFileNames.end(); ++it) chain.Add((*it).c_str() );
112    
113 akalinow 1.25
114 konec 1.1 //
115     // prepare datastructures and branches
116     //
117     std::vector<SynchroCountsObj> *counts= 0;
118     std::vector<uint32_t> *detsCrossedByMuon = 0;
119     std::vector<uint32_t> *detsCrossedByMuonDeepInside = 0;
120 konec 1.7 std::vector<DetCluDigiObj> *detsHitsCompatibleWithMuon = 0;
121 konec 1.1 std::vector<uint32_t> *detsSIMU = 0;
122 konec 1.17 std::vector<std::pair<uint32_t, uint32_t> > *digSpec = 0;
123 konec 1.1
124     EventObj * event = 0;
125     MuonObj * muon = 0;
126 konec 1.17 TrackObj * simu = 0;
127 konec 1.1
128 konec 1.5 TriggerMenuResultObj *bitsL1 = 0;
129     TriggerMenuResultObj *bitsHLT = 0;
130    
131 konec 1.1 TBranch *bcounts=0;
132     TBranch *bdetsCrossedByMuon =0;
133     TBranch *bdetsCrossedByMuonDeepInside =0;
134     TBranch *bdetsHitsCompatibleWithMuon = 0;
135     TBranch *bdetsSIMU =0;
136 konec 1.17 TBranch *bdigSpec = 0;
137 konec 1.1
138 konec 1.9 L1ObjColl* l1ObjColl = 0;
139 konec 1.17 HitSpecObj* hitSpec = 0;
140    
141 konec 1.1
142     chain.SetBranchAddress("event",&event);
143     chain.SetBranchAddress("muon",&muon);
144 konec 1.17 chain.SetBranchAddress("simu",&simu);
145 konec 1.1
146 konec 1.5 chain.SetBranchAddress("bitsL1",&bitsL1);
147     chain.SetBranchAddress("bitsHLT",&bitsHLT);
148    
149 konec 1.1 chain.SetBranchAddress("counts",&counts,&bcounts);
150     chain.SetBranchAddress("detsCrossedByMuon",&detsCrossedByMuon,&bdetsCrossedByMuon);
151     chain.SetBranchAddress("detsCrossedByMuonDeepInside",&detsCrossedByMuonDeepInside,&bdetsCrossedByMuonDeepInside);
152     chain.SetBranchAddress("detsHitsCompatibleWithMuon",&detsHitsCompatibleWithMuon,&bdetsHitsCompatibleWithMuon);
153     chain.SetBranchAddress("detsSIMU",&detsSIMU,&bdetsSIMU);
154 konec 1.17 chain.SetBranchAddress("digSpec",&digSpec,&bdigSpec);
155 konec 1.1
156 konec 1.9 chain.SetBranchAddress("l1ObjColl",&l1ObjColl);
157 konec 1.17 chain.SetBranchAddress("hitSpec",&hitSpec);
158 konec 1.1
159 akalinow 1.25
160 konec 1.1 //
161 konec 1.5 // number of events
162 konec 1.1 //
163     Int_t nentries = (Int_t) chain.GetEntries();
164     std::cout <<" ENTRIES: " << nentries << std::endl;
165 akalinow 1.27 //nentries = 10938;
166 konec 1.1 //
167     // main loop
168     //
169     unsigned int lastRun = 0;
170 akalinow 1.27 for (int ev=0; ev<nentries; ev+=10) {
171 konec 1.1 chain.GetEntry(ev);
172 konec 1.17 if (theAnaMenu) theAnaMenu->updateMenu(bitsL1->names, bitsHLT->names);
173 konec 1.1
174 akalinow 1.27 if ( (lastRun != (*event).run) || (ev%1000000==0) ) {
175 konec 1.1 lastRun = (*event).run;
176     std::cout <<"RUN:" << std::setw(7) << (*event).run
177     <<" event:" << std::setw(8) << ev
178 konec 1.11 <<" done:" << std::setw(6)<< std::setiosflags(std::ios::fixed) << std::setprecision(2) << ev*100./nentries<<"%";
179     std::cout<<std::endl;
180 konec 1.1 }
181    
182 konec 1.12 // EVENT NUMBER, BX structure etc.
183     EventObjBXExtra eventBx(*event);
184 konec 1.17 if ( theAnaEvent && !theAnaEvent->filter(&eventBx) && theConfig.getParameter<bool>("filterByAnaEvent") ) continue;
185 konec 1.9 // ANALYSE AND FILTER KINEMCTICS
186 konec 1.17 if ( theAnaMuonDistribution && !theAnaMuonDistribution->filter(muon) && theConfig.getParameter<bool>("filterByAnaMuonDistribution") ) continue;
187 konec 1.9 // ANALYSE AND FILTER TRIGGER MENU
188 konec 1.17 if ( theAnaMenu && !theAnaMenu->filter(event, muon, bitsL1, bitsHLT) && theConfig.getParameter<bool>("filterByAnaMenu") ) continue;
189 konec 1.18 // ANALYSE AND FILTER SIMU KONEMATICs
190     if ( theAnaSiMuDistribution && !theAnaSiMuDistribution->filter(event, simu, hitSpec) && theConfig.getParameter<bool>("filterByAnaSiMuDistribution") ) continue;
191 konec 1.1
192 konec 1.20 const TrackObj * refTrack = theConfig.getParameter<bool>("useSiMuReference") ? simu : muon;
193    
194 konec 1.17 // ANALYSES
195 konec 1.20 if (theAnaRpcVsOth) theAnaRpcVsOth->run(refTrack,l1ObjColl);
196    
197     // std::cout <<"refTrack: "<< *refTrack<<std::endl;
198     // std::cout <<"l1ObjColl: "<< *l1ObjColl << std::endl;
199    
200 konec 1.17 if (theAnaRpcMisc) theAnaRpcMisc->run(event,muon,l1ObjColl);
201     if (theAnaDet) theAnaDet->run( muon, *detsHitsCompatibleWithMuon, *detsCrossedByMuon, *detsCrossedByMuonDeepInside);
202     if (theAnaEmu) theAnaEmu->run ( event, muon, l1ObjColl);
203     if (theAnaSynch) theAnaSynch->run( event, muon, ConverterRPCRawSynchroSynchroCountsObj::toRawSynchro( *counts));
204     if (theAnaClu) theAnaClu->run( event, muon, l1ObjColl, *detsHitsCompatibleWithMuon);
205     if (theAnaTimingL1) theAnaTimingL1->run( &eventBx, muon, l1ObjColl);
206    
207 konec 1.20 // HITPATTERN ANALYSES & OTF EFFICIENCY
208 konec 1.17 if (theAnaHitSpec) theAnaHitSpec->run(event, simu, hitSpec);
209     if (theAnaDigiSpec) theAnaDigiSpec->run(event, simu, hitSpec, *digSpec);
210     if (thePatternProducer) thePatternProducer->run(event, simu, hitSpec, *digSpec);
211 konec 1.18 L1Obj l1otf;
212     if (thePatternProvider) l1otf=thePatternProvider->check(event, simu, hitSpec, *digSpec);
213 konec 1.19 if (theAnaOtfEff) theAnaOtfEff->run(event,simu,l1otf);
214 konec 1.22 L1ObjColl myL1ObjColl = *l1ObjColl;
215     myL1ObjColl.push_back(l1otf, false, 0.);
216 akalinow 1.27 if (theAnaEff) theAnaEff->run(refTrack, &myL1ObjColl, hitSpec);
217 konec 1.1 }
218     }
219    
220     void L1RpcTreeAnalysis::endJob()
221     {
222     std::cout <<"ENDJOB, summaries:"<<std::endl;
223 konec 1.17 TGraph* hGraph_DetEff = (theAnaDet) ? theAnaDet->resume() : 0;
224     TGraph* hGraph_RunClu = (theAnaClu) ? theAnaClu->resume(): 0;
225     if (theAnaRpcMisc) theAnaRpcMisc->resume(theHistos);
226     if (theAnaTimingL1) theAnaTimingL1->resume(theHistos);
227     if (theAnaMenu) theAnaMenu->resume(theHistos);
228     if (theAnaMenu) theAnaEvent->resume(theHistos);
229     if (theAnaHitSpec) theAnaHitSpec->resume(theHistos);
230     if (theAnaDigiSpec) theAnaDigiSpec->resume(theHistos);
231    
232     if (theAnaSynch) theAnaSynch->endJob();
233     if (thePatternProducer) thePatternProducer->endJob();
234     if (thePatternProvider) thePatternProvider->endJob();
235 konec 1.1
236     std::string histoFile = theConfig.getParameter<std::string>("histoFileName");
237     TFile f(histoFile.c_str(),"RECREATE");
238     theHistos.Write();
239 konec 1.17 if (hGraph_DetEff) hGraph_DetEff->Write("hGraph_DetEff");
240     if (hGraph_RunClu) hGraph_RunClu->Write("hGraph_RunClu");
241 konec 1.1 f.Close();
242     std::cout <<"END"<<std::endl;
243 konec 1.17
244     delete theAnaMuonDistribution;
245     delete theAnaRpcVsOth;
246     delete theAnaRpcMisc;
247     delete theAnaEff;
248     delete theAnaDet;
249     delete theAnaEmu;
250     delete theAnaSynch;
251     delete theAnaClu;
252     delete theAnaTimingL1;
253     delete theAnaMenu;
254     delete theAnaEvent;
255     delete theAnaDigiSpec;
256     delete theAnaHitSpec;
257     delete thePatternProducer;
258     delete thePatternProvider;
259 konec 1.19 delete theAnaSiMuDistribution;
260     delete theAnaOtfEff;
261 konec 1.1 }