ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/plugins/L1RpcTreeMaker.cc
Revision: 1.18
Committed: Mon Apr 29 10:15:06 2013 UTC (12 years ago) by konec
Content type: text/plain
Branch: MAIN
Changes since 1.17: +17 -0 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    
15    
16     #include "UserCode/L1RpcTriggerAnalysis/interface/BestMuonFinder.h"
17     #include "UserCode/L1RpcTriggerAnalysis/interface/DetHitCompatibleCollector.h"
18     #include "UserCode/L1RpcTriggerAnalysis/interface/L1ObjMaker.h"
19     #include "UserCode/L1RpcTriggerAnalysis/interface/TrackToL1ObjMatcher.h"
20     #include "DataFormats/RPCDigi/interface/RPCRawSynchro.h"
21     #include "UserCode/L1RpcTriggerAnalysis/interface/ConverterRPCRawSynchroSynchroCountsObj.h"
22 konec 1.4 #include "UserCode/L1RpcTriggerAnalysis/interface/TriggerMenuResultObj.h"
23 konec 1.1
24     #include "TFile.h"
25     #include "TTree.h"
26    
27 konec 1.18 //tmp
28     //#include "Geometry/CommonDetUnit/interface/GeomDet.h"
29     //#include "DataFormats/MuonDetId/interface/RPCDetId.h"
30     //#include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
31     //#include "DataFormats/DetId/interface/DetIdCollection.h"
32    
33    
34 konec 1.1 template <class T> T sqr( T t) {return t*t;}
35    
36     L1RpcTreeMaker::L1RpcTreeMaker(const edm::ParameterSet& cfg)
37 konec 1.4 : theConfig(cfg), theTree(0), event(0), muon(0), track(0),
38     bitsL1(0), bitsHLT(0),
39     counts(0),
40 konec 1.10 l1ObjColl(0),
41 konec 1.1 theCounter(0),
42     theBestMuonFinder(cfg.getParameter<edm::ParameterSet>("bestMuonFinder")),
43     theDetHitCollector(cfg.getParameter<edm::ParameterSet>("detHitCollector")),
44 konec 1.5 theSynchroGrabber(cfg.getParameter<edm::ParameterSet>("linkSynchroGrabber")),
45 konec 1.10 theL1ObjMaker(cfg.getParameter<edm::ParameterSet>("l1ObjMaker")),
46 konec 1.5 theMenuInspector(edm::ParameterSet())
47 konec 1.1 { }
48    
49 konec 1.5 void L1RpcTreeMaker::beginRun(const edm::Run &ru, const edm::EventSetup &es)
50 konec 1.1 {
51 konec 1.5 std::cout <<" L1RpcTreeMaker::beginRun CALLED" << std::endl;
52     theMenuInspector.checkRun(ru,es);
53 konec 1.1 }
54    
55     void L1RpcTreeMaker::beginJob()
56     {
57     theFile = new TFile(theConfig.getParameter<std::string>("treeFileName").c_str(),"RECREATE");
58     theTree = new TTree("tL1Rpc","L1RpcEfficciency");
59    
60     theTree->Branch("event","EventObj",&event,32000,99);
61     theTree->Branch("muon","MuonObj",&muon,32000,99);
62     theTree->Branch("track", "TrackObj",&track,32000,99);
63    
64 konec 1.4 theTree->Branch("bitsL1" ,"TriggerMenuResultObj",&bitsL1 ,32000,99);
65     theTree->Branch("bitsHLT","TriggerMenuResultObj",&bitsHLT,32000,99);
66    
67 konec 1.1 theTree->Branch("counts",&counts);
68     theTree->Branch("detsCrossedByMuon",&detsCrossedByMuon);
69     theTree->Branch("detsCrossedByMuonDeepInside",&detsCrossedByMuonDeepInside);
70     theTree->Branch("detsHitsCompatibleWithMuon",&detsHitsCompatibleWithMuon);
71     theTree->Branch("detsSIMU",&detsSIMU);
72    
73 konec 1.10 theTree->Branch("l1ObjColl","L1ObjColl",&l1ObjColl,32000,99);
74 konec 1.1
75     theHelper.SetOwner();
76     theBestMuonFinder.initHistos(theHelper);
77     theDetHitCollector.initHistos(theHelper);
78     theSynchroGrabber.initHistos(theHelper);
79     }
80    
81     void L1RpcTreeMaker::endJob()
82     {
83     theFile->Write();
84     delete theFile;
85    
86     std::string helperFile = theConfig.getParameter<std::string>("histoFileName");
87     TFile f(helperFile.c_str(),"RECREATE");
88     theHelper.Write();
89     f.Close();
90     }
91    
92     L1RpcTreeMaker::~L1RpcTreeMaker()
93     {
94     std::cout <<"L1RpcTreeMaker: Event counter is: "<<theCounter<<std::endl;
95     }
96    
97     void L1RpcTreeMaker::analyze(const edm::Event &ev, const edm::EventSetup &es)
98     {
99     //
100     // check reference muon
101     //
102     const reco::Muon * theMuon = theBestMuonFinder.result(ev,es);
103 konec 1.15 if (theConfig.getParameter<bool>("onlyBestMuEvents") && (!theMuon) ) return;
104 konec 1.1 theCounter++;
105    
106     //
107     // fill event information
108     //
109     event = new EventObj;
110     event->bx = ev.bunchCrossing();
111     event->orbit = ev.orbitNumber();
112     event->time = ev.time().value();
113     event->id = ev.id().event();
114     event->run = ev.run();
115     event->lumi = ev.luminosityBlock();
116    
117     //
118     // create other objects structure
119     //
120     muon = new MuonObj();
121     track = new TrackObj();
122 konec 1.4
123     bitsL1 = new TriggerMenuResultObj();
124     bitsHLT = new TriggerMenuResultObj();
125    
126 konec 1.1 counts = std::vector<SynchroCountsObj>();
127     detsCrossedByMuon = std::vector<uint32_t>();
128     detsCrossedByMuonDeepInside = std::vector<uint32_t>();
129 konec 1.6 detsHitsCompatibleWithMuon = std::vector<DetCluDigiObj>();
130 konec 1.1 detsSIMU = std::vector<uint32_t>();
131 konec 1.6
132 konec 1.10 l1ObjColl = new L1ObjColl;
133 konec 1.1
134     //
135     // fill muon info
136     //
137 konec 1.15 muon->isUnique = theBestMuonFinder.isUnique(ev,es);
138     muon->nAllMuons = theBestMuonFinder.numberOfAllMuons(ev,es);
139 konec 1.17 muon->nRPCHits = theBestMuonFinder.numberOfValidMuonRPCHits();
140     muon->nDTHits = theBestMuonFinder.numberOfValidMuonDTHits();
141     muon->nCSCHits = theBestMuonFinder.numberOfValidMuonCSCHits();
142     muon->nTrackerHits = theBestMuonFinder.numberOfValidTrackerHits();
143 konec 1.14 if (theMuon) {
144 konec 1.16 muon->setKine(theMuon->bestTrack()->pt(), theMuon->bestTrack()->eta(), theMuon->bestTrack()->phi(), theMuon->bestTrack()->charge());
145 konec 1.14 muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
146     muon->nMatchedStations = theMuon->numberOfMatchedStations();
147     }
148 konec 1.1
149 konec 1.5 //
150     // fill algoBits info
151     //
152     static edm::RunNumber_t lastRun = 0;
153     if (ev.run() != lastRun) {
154     lastRun = ev.run();
155     bitsL1->names = theMenuInspector.namesAlgoL1();
156     bitsHLT->names = theMenuInspector.namesAlgoHLT();
157     }
158     bitsL1->firedAlgos = theMenuInspector.firedAlgosL1(ev,es);
159     bitsHLT->firedAlgos = theMenuInspector.firedAlgosHLT(ev,es);
160    
161 konec 1.1
162 konec 1.18 /* tmp
163     edm::Handle<RPCRecHitCollection> recHits;
164     ev.getByLabel("rpcRecHits", recHits);
165     typedef RPCRecHitCollection::const_iterator IH;
166     std::cout <<"Event: " << *event << std::endl;
167     for (IH ih=recHits->begin(); ih != recHits->end(); ++ih) {
168     std::cout <<"Det: "<< ih->rpcId()<<"is valid: "<< ih->isValid()<< "BX= "<<ih->BunchX() << std::endl;
169     }
170     */
171    
172 konec 1.1 //
173     // hits and detectors compatible with muon track
174     //
175 konec 1.16 if (theMuon && muon->pt() > 10. && theMuon->isGlobalMuon()) {
176 konec 1.6 detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
177 konec 1.1 detsCrossedByMuon = theDetHitCollector.compatibleDets( theMuon, ev, es, false);
178     detsCrossedByMuonDeepInside = theDetHitCollector.compatibleDets( theMuon, ev, es, true);
179     if (theConfig.getParameter<bool>("checkDestSIMU")) detsSIMU = theDetHitCollector.compatibleSIMU( theMuon, ev, es);
180     }
181    
182    
183     //
184     // fill LinkSynchroAnalysis data
185     //
186 konec 1.16 if (theMuon && theMuon->isGlobalMuon()) {
187 konec 1.14 theSynchroGrabber.setMuon(theMuon);
188     RPCRawSynchro::ProdItem rawCounts = theSynchroGrabber.counts(ev,es);
189     counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
190     }
191 konec 1.1
192    
193     //
194 konec 1.10 // fill L1 info
195     //
196     std::vector<L1Obj> l1Obj = theL1ObjMaker(ev);
197     l1ObjColl->set( l1Obj);
198     std::vector<bool> matching(l1Obj.size(), false);
199 konec 1.15 std::vector<double> deltaR(l1Obj.size(), 999.);
200 konec 1.11 TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
201 konec 1.16 if (theMuon && theMuon->isGlobalMuon()){
202 konec 1.14 for(unsigned int i=0; i< l1Obj.size(); ++i) {
203     if (matcher(l1Obj[i].eta, l1Obj[i].phi, theMuon, ev,es)) matching[i]=true;
204     TrackToL1ObjMatcher::LastResult result = matcher.lastResult();
205     deltaR[i] = sqrt( sqr(result.deltaEta) + sqr(result.deltaPhi) );
206     }
207 konec 1.10 }
208     l1ObjColl->set( matching );
209     l1ObjColl->set( deltaR );
210 konec 1.15 // std::cout <<"----------"<<std::endl;
211     // std::cout <<*l1ObjColl << std::endl;
212 konec 1.10
213 konec 1.1 //
214     // fill ntuple + cleanup
215     //
216     //std::cout <<" THIS event written!" << std::endl;
217     theTree->Fill();
218     delete event; event = 0;
219     delete muon; muon = 0;
220     delete track; track = 0;
221 konec 1.4 delete bitsL1; bitsL1= 0;
222     delete bitsHLT; bitsHLT= 0;
223 konec 1.10 delete l1ObjColl; l1ObjColl = 0;
224 konec 1.1 }
225