ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/plugins/L1RpcTreeMaker.cc
Revision: 1.20
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_B, Artur_11_07_2013_A, Artur_11_07_2013, HEAD
Changes since 1.19: +6 -2 lines
Log Message:
*last commit before migration to Git.

File Contents

# User Rev Content
1 konec 1.1 #include "L1RpcTreeMaker.h"
2     #include <vector>
3    
4     #include "FWCore/Framework/interface/Event.h"
5     #include "FWCore/Framework/interface/EventSetup.h"
6     #include "FWCore/Framework/interface/ESHandle.h"
7     #include "DataFormats/Common/interface/Handle.h"
8    
9     #include "DataFormats/MuonReco/interface/Muon.h"
10     #include "DataFormats/MuonReco/interface/MuonFwd.h"
11     #include "DataFormats/MuonReco/interface/MuonSelectors.h"
12     #include "DataFormats/TrackReco/interface/TrackFwd.h"
13     #include "DataFormats/TrackReco/interface/Track.h"
14 konec 1.19 #include "SimDataFormats/Track/interface/SimTrack.h"
15    
16 konec 1.1
17    
18     #include "UserCode/L1RpcTriggerAnalysis/interface/BestMuonFinder.h"
19     #include "UserCode/L1RpcTriggerAnalysis/interface/DetHitCompatibleCollector.h"
20     #include "UserCode/L1RpcTriggerAnalysis/interface/L1ObjMaker.h"
21     #include "UserCode/L1RpcTriggerAnalysis/interface/TrackToL1ObjMatcher.h"
22     #include "DataFormats/RPCDigi/interface/RPCRawSynchro.h"
23     #include "UserCode/L1RpcTriggerAnalysis/interface/ConverterRPCRawSynchroSynchroCountsObj.h"
24 konec 1.4 #include "UserCode/L1RpcTriggerAnalysis/interface/TriggerMenuResultObj.h"
25 konec 1.1
26 konec 1.19 #include "UserCode/L1RpcTriggerAnalysis/interface/BestSimulatedMuonFinder.h"
27    
28 konec 1.1 #include "TFile.h"
29     #include "TTree.h"
30    
31 konec 1.18 //tmp
32     //#include "Geometry/CommonDetUnit/interface/GeomDet.h"
33     //#include "DataFormats/MuonDetId/interface/RPCDetId.h"
34     //#include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
35     //#include "DataFormats/DetId/interface/DetIdCollection.h"
36    
37    
38 konec 1.1 template <class T> T sqr( T t) {return t*t;}
39    
40     L1RpcTreeMaker::L1RpcTreeMaker(const edm::ParameterSet& cfg)
41 konec 1.19 : theConfig(cfg), theTree(0), event(0), muon(0), simu(0),
42 konec 1.4 bitsL1(0), bitsHLT(0),
43     counts(0),
44 akalinow 1.20 l1ObjColl(0),hitSpec(0), hitSpecSt1(0),
45 konec 1.1 theCounter(0),
46     theBestMuonFinder(cfg.getParameter<edm::ParameterSet>("bestMuonFinder")),
47     theDetHitCollector(cfg.getParameter<edm::ParameterSet>("detHitCollector")),
48 konec 1.5 theSynchroGrabber(cfg.getParameter<edm::ParameterSet>("linkSynchroGrabber")),
49 konec 1.10 theL1ObjMaker(cfg.getParameter<edm::ParameterSet>("l1ObjMaker")),
50 konec 1.19 theMenuInspector( cfg.exists("menuInspector")
51     ? cfg.getParameter<edm::ParameterSet>("menuInspector")
52     : edm::ParameterSet() ),
53     theDetHitDigiGrabber( cfg.getParameter<edm::ParameterSet>("detHitDigiGrabber") )
54 konec 1.1 { }
55    
56 konec 1.5 void L1RpcTreeMaker::beginRun(const edm::Run &ru, const edm::EventSetup &es)
57 konec 1.1 {
58 konec 1.5 std::cout <<" L1RpcTreeMaker::beginRun CALLED" << std::endl;
59     theMenuInspector.checkRun(ru,es);
60 konec 1.1 }
61    
62     void L1RpcTreeMaker::beginJob()
63     {
64     theFile = new TFile(theConfig.getParameter<std::string>("treeFileName").c_str(),"RECREATE");
65     theTree = new TTree("tL1Rpc","L1RpcEfficciency");
66    
67     theTree->Branch("event","EventObj",&event,32000,99);
68     theTree->Branch("muon","MuonObj",&muon,32000,99);
69 konec 1.19 theTree->Branch("simu", "TrackObj",&simu,32000,99);
70 konec 1.1
71 konec 1.4 theTree->Branch("bitsL1" ,"TriggerMenuResultObj",&bitsL1 ,32000,99);
72     theTree->Branch("bitsHLT","TriggerMenuResultObj",&bitsHLT,32000,99);
73    
74 konec 1.1 theTree->Branch("counts",&counts);
75     theTree->Branch("detsCrossedByMuon",&detsCrossedByMuon);
76     theTree->Branch("detsCrossedByMuonDeepInside",&detsCrossedByMuonDeepInside);
77     theTree->Branch("detsHitsCompatibleWithMuon",&detsHitsCompatibleWithMuon);
78     theTree->Branch("detsSIMU",&detsSIMU);
79    
80 konec 1.10 theTree->Branch("l1ObjColl","L1ObjColl",&l1ObjColl,32000,99);
81 konec 1.19 theTree->Branch("hitSpec","HitSpecObj",&hitSpec,32000,99);
82 akalinow 1.20 theTree->Branch("hitSpecSt1","HitSpecObj",&hitSpecSt1,32000,99);
83 konec 1.19 theTree->Branch("digSpec",&digSpec);
84 konec 1.1
85     theHelper.SetOwner();
86     theBestMuonFinder.initHistos(theHelper);
87     theDetHitCollector.initHistos(theHelper);
88     theSynchroGrabber.initHistos(theHelper);
89 konec 1.19 theDetHitDigiGrabber.initHistos(theHelper);
90 konec 1.1 }
91    
92     void L1RpcTreeMaker::endJob()
93     {
94     theFile->Write();
95     delete theFile;
96    
97     std::string helperFile = theConfig.getParameter<std::string>("histoFileName");
98     TFile f(helperFile.c_str(),"RECREATE");
99     theHelper.Write();
100     f.Close();
101     }
102    
103     L1RpcTreeMaker::~L1RpcTreeMaker()
104     {
105     std::cout <<"L1RpcTreeMaker: Event counter is: "<<theCounter<<std::endl;
106     }
107    
108     void L1RpcTreeMaker::analyze(const edm::Event &ev, const edm::EventSetup &es)
109     {
110 konec 1.19
111 konec 1.1 //
112     // check reference muon
113     //
114     const reco::Muon * theMuon = theBestMuonFinder.result(ev,es);
115 konec 1.15 if (theConfig.getParameter<bool>("onlyBestMuEvents") && (!theMuon) ) return;
116 konec 1.1 theCounter++;
117    
118     //
119     // fill event information
120     //
121     event = new EventObj;
122     event->bx = ev.bunchCrossing();
123     event->orbit = ev.orbitNumber();
124     event->time = ev.time().value();
125     event->id = ev.id().event();
126     event->run = ev.run();
127     event->lumi = ev.luminosityBlock();
128 konec 1.19 //std::cout <<"-----------------------"<< *event << std::endl;
129 konec 1.1
130     //
131     // create other objects structure
132     //
133     muon = new MuonObj();
134 konec 1.19 simu = new TrackObj();
135 konec 1.4
136     bitsL1 = new TriggerMenuResultObj();
137     bitsHLT = new TriggerMenuResultObj();
138    
139 konec 1.1 counts = std::vector<SynchroCountsObj>();
140     detsCrossedByMuon = std::vector<uint32_t>();
141     detsCrossedByMuonDeepInside = std::vector<uint32_t>();
142 konec 1.6 detsHitsCompatibleWithMuon = std::vector<DetCluDigiObj>();
143 konec 1.1 detsSIMU = std::vector<uint32_t>();
144 konec 1.6
145 konec 1.10 l1ObjColl = new L1ObjColl;
146 konec 1.19 hitSpec = new HitSpecObj();
147 akalinow 1.20 hitSpecSt1 = new HitSpecObj();
148 konec 1.19 digSpec = std::vector< std::pair<uint32_t, uint32_t> >();
149    
150     //
151     // fill Simulated Mu Info
152     //
153     const SimTrack* aSimMuon = BestSimulatedMuonFinder().result(ev,es);
154     if (aSimMuon) {
155     int charge = (abs(aSimMuon->type()) == 13) ? aSimMuon->type()/-13 : 0;
156     simu->setKine(aSimMuon->momentum().pt(), aSimMuon->momentum().eta(),aSimMuon->momentum().phi(), charge);
157     }
158     // std::cout << *simu << std::endl;
159 konec 1.1
160     //
161     // fill muon info
162     //
163 konec 1.15 muon->isUnique = theBestMuonFinder.isUnique(ev,es);
164     muon->nAllMuons = theBestMuonFinder.numberOfAllMuons(ev,es);
165 konec 1.17 muon->nRPCHits = theBestMuonFinder.numberOfValidMuonRPCHits();
166     muon->nDTHits = theBestMuonFinder.numberOfValidMuonDTHits();
167     muon->nCSCHits = theBestMuonFinder.numberOfValidMuonCSCHits();
168     muon->nTrackerHits = theBestMuonFinder.numberOfValidTrackerHits();
169 konec 1.14 if (theMuon) {
170 konec 1.16 muon->setKine(theMuon->bestTrack()->pt(), theMuon->bestTrack()->eta(), theMuon->bestTrack()->phi(), theMuon->bestTrack()->charge());
171 konec 1.14 muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
172     muon->nMatchedStations = theMuon->numberOfMatchedStations();
173     }
174 konec 1.1
175 konec 1.5 //
176     // fill algoBits info
177     //
178     static edm::RunNumber_t lastRun = 0;
179     if (ev.run() != lastRun) {
180     lastRun = ev.run();
181     bitsL1->names = theMenuInspector.namesAlgoL1();
182     bitsHLT->names = theMenuInspector.namesAlgoHLT();
183     }
184     bitsL1->firedAlgos = theMenuInspector.firedAlgosL1(ev,es);
185     bitsHLT->firedAlgos = theMenuInspector.firedAlgosHLT(ev,es);
186    
187 konec 1.1
188 konec 1.18 /* tmp
189     edm::Handle<RPCRecHitCollection> recHits;
190     ev.getByLabel("rpcRecHits", recHits);
191     typedef RPCRecHitCollection::const_iterator IH;
192     std::cout <<"Event: " << *event << std::endl;
193     for (IH ih=recHits->begin(); ih != recHits->end(); ++ih) {
194     std::cout <<"Det: "<< ih->rpcId()<<"is valid: "<< ih->isValid()<< "BX= "<<ih->BunchX() << std::endl;
195     }
196     */
197    
198 konec 1.1 //
199     // hits and detectors compatible with muon track
200     //
201 konec 1.16 if (theMuon && muon->pt() > 10. && theMuon->isGlobalMuon()) {
202 konec 1.6 detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
203 konec 1.1 detsCrossedByMuon = theDetHitCollector.compatibleDets( theMuon, ev, es, false);
204     detsCrossedByMuonDeepInside = theDetHitCollector.compatibleDets( theMuon, ev, es, true);
205     if (theConfig.getParameter<bool>("checkDestSIMU")) detsSIMU = theDetHitCollector.compatibleSIMU( theMuon, ev, es);
206     }
207    
208    
209     //
210     // fill LinkSynchroAnalysis data
211     //
212 konec 1.16 if (theMuon && theMuon->isGlobalMuon()) {
213 konec 1.14 theSynchroGrabber.setMuon(theMuon);
214     RPCRawSynchro::ProdItem rawCounts = theSynchroGrabber.counts(ev,es);
215     counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
216     }
217 konec 1.1
218    
219     //
220 konec 1.10 // fill L1 info
221     //
222     std::vector<L1Obj> l1Obj = theL1ObjMaker(ev);
223     l1ObjColl->set( l1Obj);
224     std::vector<bool> matching(l1Obj.size(), false);
225 konec 1.15 std::vector<double> deltaR(l1Obj.size(), 999.);
226 konec 1.11 TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
227 konec 1.16 if (theMuon && theMuon->isGlobalMuon()){
228 konec 1.14 for(unsigned int i=0; i< l1Obj.size(); ++i) {
229     if (matcher(l1Obj[i].eta, l1Obj[i].phi, theMuon, ev,es)) matching[i]=true;
230     TrackToL1ObjMatcher::LastResult result = matcher.lastResult();
231     deltaR[i] = sqrt( sqr(result.deltaEta) + sqr(result.deltaPhi) );
232     }
233 konec 1.10 }
234     l1ObjColl->set( matching );
235     l1ObjColl->set( deltaR );
236 konec 1.19
237 konec 1.15 // std::cout <<*l1ObjColl << std::endl;
238 konec 1.10
239 konec 1.1 //
240 konec 1.19 // det HIT+DIGI grabber
241     //
242 akalinow 1.20 *hitSpec = theDetHitDigiGrabber.rpcDetHits(ev,es,simu,2);
243     *hitSpecSt1 = theDetHitDigiGrabber.rpcDetHits(ev,es,simu,1);
244 konec 1.19 digSpec = theDetHitDigiGrabber.digiCollector(ev,es);
245    
246    
247     //
248 konec 1.1 // fill ntuple + cleanup
249     //
250 konec 1.19 // std::cout <<"THIS event written!" << std::endl;
251 konec 1.1 theTree->Fill();
252     delete event; event = 0;
253     delete muon; muon = 0;
254 konec 1.19 delete simu; simu = 0;
255 konec 1.4 delete bitsL1; bitsL1= 0;
256     delete bitsHLT; bitsHLT= 0;
257 konec 1.10 delete l1ObjColl; l1ObjColl = 0;
258 konec 1.19 delete hitSpec; hitSpec = 0;
259 akalinow 1.20 delete hitSpecSt1; hitSpecSt1 = 0;
260 konec 1.1 }
261