ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/plugins/L1RpcTreeMaker.cc
Revision: 1.19
Committed: Fri May 17 13:02:12 2013 UTC (11 years, 11 months ago) by konec
Content type: text/plain
Branch: MAIN
CVS Tags: Artur_28_06_2013
Changes since 1.18: +40 -8 lines
Log Message:
*** empty log message ***

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 konec 1.19 l1ObjColl(0),hitSpec(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     theTree->Branch("digSpec",&digSpec);
83 konec 1.1
84     theHelper.SetOwner();
85     theBestMuonFinder.initHistos(theHelper);
86     theDetHitCollector.initHistos(theHelper);
87     theSynchroGrabber.initHistos(theHelper);
88 konec 1.19 theDetHitDigiGrabber.initHistos(theHelper);
89 konec 1.1 }
90    
91     void L1RpcTreeMaker::endJob()
92     {
93     theFile->Write();
94     delete theFile;
95    
96     std::string helperFile = theConfig.getParameter<std::string>("histoFileName");
97     TFile f(helperFile.c_str(),"RECREATE");
98     theHelper.Write();
99     f.Close();
100     }
101    
102     L1RpcTreeMaker::~L1RpcTreeMaker()
103     {
104     std::cout <<"L1RpcTreeMaker: Event counter is: "<<theCounter<<std::endl;
105     }
106    
107     void L1RpcTreeMaker::analyze(const edm::Event &ev, const edm::EventSetup &es)
108     {
109 konec 1.19
110 konec 1.1 //
111     // check reference muon
112     //
113     const reco::Muon * theMuon = theBestMuonFinder.result(ev,es);
114 konec 1.15 if (theConfig.getParameter<bool>("onlyBestMuEvents") && (!theMuon) ) return;
115 konec 1.1 theCounter++;
116    
117     //
118     // fill event information
119     //
120     event = new EventObj;
121     event->bx = ev.bunchCrossing();
122     event->orbit = ev.orbitNumber();
123     event->time = ev.time().value();
124     event->id = ev.id().event();
125     event->run = ev.run();
126     event->lumi = ev.luminosityBlock();
127 konec 1.19 //std::cout <<"-----------------------"<< *event << std::endl;
128 konec 1.1
129     //
130     // create other objects structure
131     //
132     muon = new MuonObj();
133 konec 1.19 simu = new TrackObj();
134 konec 1.4
135     bitsL1 = new TriggerMenuResultObj();
136     bitsHLT = new TriggerMenuResultObj();
137    
138 konec 1.1 counts = std::vector<SynchroCountsObj>();
139     detsCrossedByMuon = std::vector<uint32_t>();
140     detsCrossedByMuonDeepInside = std::vector<uint32_t>();
141 konec 1.6 detsHitsCompatibleWithMuon = std::vector<DetCluDigiObj>();
142 konec 1.1 detsSIMU = std::vector<uint32_t>();
143 konec 1.6
144 konec 1.10 l1ObjColl = new L1ObjColl;
145 konec 1.19 hitSpec = new HitSpecObj();
146     digSpec = std::vector< std::pair<uint32_t, uint32_t> >();
147    
148     //
149     // fill Simulated Mu Info
150     //
151     const SimTrack* aSimMuon = BestSimulatedMuonFinder().result(ev,es);
152     if (aSimMuon) {
153     int charge = (abs(aSimMuon->type()) == 13) ? aSimMuon->type()/-13 : 0;
154     simu->setKine(aSimMuon->momentum().pt(), aSimMuon->momentum().eta(),aSimMuon->momentum().phi(), charge);
155     }
156     // std::cout << *simu << std::endl;
157 konec 1.1
158     //
159     // fill muon info
160     //
161 konec 1.15 muon->isUnique = theBestMuonFinder.isUnique(ev,es);
162     muon->nAllMuons = theBestMuonFinder.numberOfAllMuons(ev,es);
163 konec 1.17 muon->nRPCHits = theBestMuonFinder.numberOfValidMuonRPCHits();
164     muon->nDTHits = theBestMuonFinder.numberOfValidMuonDTHits();
165     muon->nCSCHits = theBestMuonFinder.numberOfValidMuonCSCHits();
166     muon->nTrackerHits = theBestMuonFinder.numberOfValidTrackerHits();
167 konec 1.14 if (theMuon) {
168 konec 1.16 muon->setKine(theMuon->bestTrack()->pt(), theMuon->bestTrack()->eta(), theMuon->bestTrack()->phi(), theMuon->bestTrack()->charge());
169 konec 1.14 muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
170     muon->nMatchedStations = theMuon->numberOfMatchedStations();
171     }
172 konec 1.1
173 konec 1.5 //
174     // fill algoBits info
175     //
176     static edm::RunNumber_t lastRun = 0;
177     if (ev.run() != lastRun) {
178     lastRun = ev.run();
179     bitsL1->names = theMenuInspector.namesAlgoL1();
180     bitsHLT->names = theMenuInspector.namesAlgoHLT();
181     }
182     bitsL1->firedAlgos = theMenuInspector.firedAlgosL1(ev,es);
183     bitsHLT->firedAlgos = theMenuInspector.firedAlgosHLT(ev,es);
184    
185 konec 1.1
186 konec 1.18 /* tmp
187     edm::Handle<RPCRecHitCollection> recHits;
188     ev.getByLabel("rpcRecHits", recHits);
189     typedef RPCRecHitCollection::const_iterator IH;
190     std::cout <<"Event: " << *event << std::endl;
191     for (IH ih=recHits->begin(); ih != recHits->end(); ++ih) {
192     std::cout <<"Det: "<< ih->rpcId()<<"is valid: "<< ih->isValid()<< "BX= "<<ih->BunchX() << std::endl;
193     }
194     */
195    
196 konec 1.1 //
197     // hits and detectors compatible with muon track
198     //
199 konec 1.16 if (theMuon && muon->pt() > 10. && theMuon->isGlobalMuon()) {
200 konec 1.6 detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
201 konec 1.1 detsCrossedByMuon = theDetHitCollector.compatibleDets( theMuon, ev, es, false);
202     detsCrossedByMuonDeepInside = theDetHitCollector.compatibleDets( theMuon, ev, es, true);
203     if (theConfig.getParameter<bool>("checkDestSIMU")) detsSIMU = theDetHitCollector.compatibleSIMU( theMuon, ev, es);
204     }
205    
206    
207     //
208     // fill LinkSynchroAnalysis data
209     //
210 konec 1.16 if (theMuon && theMuon->isGlobalMuon()) {
211 konec 1.14 theSynchroGrabber.setMuon(theMuon);
212     RPCRawSynchro::ProdItem rawCounts = theSynchroGrabber.counts(ev,es);
213     counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
214     }
215 konec 1.1
216    
217     //
218 konec 1.10 // fill L1 info
219     //
220     std::vector<L1Obj> l1Obj = theL1ObjMaker(ev);
221     l1ObjColl->set( l1Obj);
222     std::vector<bool> matching(l1Obj.size(), false);
223 konec 1.15 std::vector<double> deltaR(l1Obj.size(), 999.);
224 konec 1.11 TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
225 konec 1.16 if (theMuon && theMuon->isGlobalMuon()){
226 konec 1.14 for(unsigned int i=0; i< l1Obj.size(); ++i) {
227     if (matcher(l1Obj[i].eta, l1Obj[i].phi, theMuon, ev,es)) matching[i]=true;
228     TrackToL1ObjMatcher::LastResult result = matcher.lastResult();
229     deltaR[i] = sqrt( sqr(result.deltaEta) + sqr(result.deltaPhi) );
230     }
231 konec 1.10 }
232     l1ObjColl->set( matching );
233     l1ObjColl->set( deltaR );
234 konec 1.19
235 konec 1.15 // std::cout <<*l1ObjColl << std::endl;
236 konec 1.10
237 konec 1.1 //
238 konec 1.19 // det HIT+DIGI grabber
239     //
240     *hitSpec = theDetHitDigiGrabber.rpcDetHits(ev,es,simu);
241     digSpec = theDetHitDigiGrabber.digiCollector(ev,es);
242    
243    
244     //
245 konec 1.1 // fill ntuple + cleanup
246     //
247 konec 1.19 // std::cout <<"THIS event written!" << std::endl;
248 konec 1.1 theTree->Fill();
249     delete event; event = 0;
250     delete muon; muon = 0;
251 konec 1.19 delete simu; simu = 0;
252 konec 1.4 delete bitsL1; bitsL1= 0;
253     delete bitsHLT; bitsHLT= 0;
254 konec 1.10 delete l1ObjColl; l1ObjColl = 0;
255 konec 1.19 delete hitSpec; hitSpec = 0;
256 konec 1.1 }
257