ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/plugins/L1RpcTreeMaker.cc
Revision: 1.5
Committed: Tue Oct 23 16:14:05 2012 UTC (12 years, 6 months ago) by konec
Content type: text/plain
Branch: MAIN
Changes since 1.4: +17 -2 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/L1ObjMakerRpcEmu.h"
20     #include "UserCode/L1RpcTriggerAnalysis/interface/TrackToL1ObjMatcher.h"
21     #include "DataFormats/RPCDigi/interface/RPCRawSynchro.h"
22     #include "UserCode/L1RpcTriggerAnalysis/interface/ConverterRPCRawSynchroSynchroCountsObj.h"
23 konec 1.4 #include "UserCode/L1RpcTriggerAnalysis/interface/TriggerMenuResultObj.h"
24 konec 1.1
25     #include "TFile.h"
26     #include "TTree.h"
27    
28     template <class T> T sqr( T t) {return t*t;}
29    
30    
31     L1RpcTreeMaker::L1RpcTreeMaker(const edm::ParameterSet& cfg)
32 konec 1.4 : theConfig(cfg), theTree(0), event(0), muon(0), track(0),
33     bitsL1(0), bitsHLT(0),
34     counts(0),
35 konec 1.1 l1RpcColl(0) , l1OtherColl(0), l1RpcCollEmu(0),
36     theCounter(0),
37     theBestMuonFinder(cfg.getParameter<edm::ParameterSet>("bestMuonFinder")),
38     theDetHitCollector(cfg.getParameter<edm::ParameterSet>("detHitCollector")),
39 konec 1.5 theSynchroGrabber(cfg.getParameter<edm::ParameterSet>("linkSynchroGrabber")),
40     theMenuInspector(edm::ParameterSet())
41 konec 1.1 { }
42    
43 konec 1.5 void L1RpcTreeMaker::beginRun(const edm::Run &ru, const edm::EventSetup &es)
44 konec 1.1 {
45 konec 1.5 std::cout <<" L1RpcTreeMaker::beginRun CALLED" << std::endl;
46     theMenuInspector.checkRun(ru,es);
47 konec 1.1 }
48    
49     void L1RpcTreeMaker::beginJob()
50     {
51     theFile = new TFile(theConfig.getParameter<std::string>("treeFileName").c_str(),"RECREATE");
52     theTree = new TTree("tL1Rpc","L1RpcEfficciency");
53    
54     theTree->Branch("event","EventObj",&event,32000,99);
55     theTree->Branch("muon","MuonObj",&muon,32000,99);
56     theTree->Branch("track", "TrackObj",&track,32000,99);
57    
58 konec 1.4 theTree->Branch("bitsL1" ,"TriggerMenuResultObj",&bitsL1 ,32000,99);
59     theTree->Branch("bitsHLT","TriggerMenuResultObj",&bitsHLT,32000,99);
60    
61 konec 1.1 theTree->Branch("counts",&counts);
62     theTree->Branch("detsCrossedByMuon",&detsCrossedByMuon);
63     theTree->Branch("detsCrossedByMuonDeepInside",&detsCrossedByMuonDeepInside);
64     theTree->Branch("detsHitsCompatibleWithMuon",&detsHitsCompatibleWithMuon);
65     theTree->Branch("detsSIMU",&detsSIMU);
66     theTree->Branch("nDigisCompDets",&nDigisCompDets);
67 konec 1.2 theTree->Branch("clSizeCompDets",&clSizeCompDets);
68 konec 1.1
69     theTree->Branch("l1RpcColl","L1ObjColl",&l1RpcColl,32000,99);
70     theTree->Branch("l1RpcCollEmu","L1ObjColl",&l1RpcCollEmu,32000,99);
71     theTree->Branch("l1OtherColl","L1ObjColl",&l1OtherColl,32000,99);
72    
73     theHelper.SetOwner();
74     theBestMuonFinder.initHistos(theHelper);
75     theDetHitCollector.initHistos(theHelper);
76     theSynchroGrabber.initHistos(theHelper);
77     }
78    
79     void L1RpcTreeMaker::endJob()
80     {
81     theFile->Write();
82     delete theFile;
83    
84     std::string helperFile = theConfig.getParameter<std::string>("histoFileName");
85     TFile f(helperFile.c_str(),"RECREATE");
86     theHelper.Write();
87     f.Close();
88     }
89    
90     L1RpcTreeMaker::~L1RpcTreeMaker()
91     {
92     std::cout <<"L1RpcTreeMaker: Event counter is: "<<theCounter<<std::endl;
93     }
94    
95     void L1RpcTreeMaker::analyze(const edm::Event &ev, const edm::EventSetup &es)
96     {
97    
98    
99     //
100     // check reference muon
101     //
102     const reco::Muon * theMuon = theBestMuonFinder.result(ev,es);
103     if (!theMuon || !theBestMuonFinder.isUnique(ev,es) ) return;
104     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 = new SynchroCountsObjVect;
127     counts = std::vector<SynchroCountsObj>();
128     detsCrossedByMuon = std::vector<uint32_t>();
129     detsCrossedByMuonDeepInside = std::vector<uint32_t>();
130     detsHitsCompatibleWithMuon = std::vector<uint32_t>();
131     detsSIMU = std::vector<uint32_t>();
132     nDigisCompDets = std::vector<uint32_t>();
133 konec 1.2 clSizeCompDets = std::vector<uint32_t>();
134 konec 1.1 l1RpcColl = new L1ObjColl;
135     l1OtherColl = new L1ObjColl;
136     l1RpcCollEmu = new L1ObjColl;
137    
138     //
139     // fill muon info
140     //
141     muon->setKine(theMuon->track()->pt(), theMuon->track()->eta(), theMuon->track()->phi(), theMuon->track()->charge());
142     muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
143     muon->nMatchedStations = theMuon->numberOfMatchedStations();
144     if (theMuon->isGlobalMuon()) {
145     const reco::HitPattern& hp = (theMuon->combinedMuon())->hitPattern();
146     muon->nRPCHits = hp.numberOfValidMuonRPCHits();
147     muon->nDTHits = hp.numberOfValidMuonDTHits();
148     muon->nCSCHits = hp.numberOfValidMuonCSCHits();
149     } else muon->nRPCHits = muon->nDTHits = muon->nCSCHits = 0;
150     muon->nTrackerHits = theMuon->isTrackerMuon() ? (theMuon->innerTrack())->hitPattern().numberOfValidTrackerHits() : 0;
151    
152 konec 1.5 //
153     // fill algoBits info
154     //
155     static edm::RunNumber_t lastRun = 0;
156     if (ev.run() != lastRun) {
157     lastRun = ev.run();
158     bitsL1->names = theMenuInspector.namesAlgoL1();
159     bitsHLT->names = theMenuInspector.namesAlgoHLT();
160     }
161     bitsL1->firedAlgos = theMenuInspector.firedAlgosL1(ev,es);
162     bitsHLT->firedAlgos = theMenuInspector.firedAlgosHLT(ev,es);
163    
164 konec 1.1
165     //
166     // hits and detectors compatible with muon track
167     //
168     if ( muon->pt() > 10.) {
169     detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
170     detsCrossedByMuon = theDetHitCollector.compatibleDets( theMuon, ev, es, false);
171     detsCrossedByMuonDeepInside = theDetHitCollector.compatibleDets( theMuon, ev, es, true);
172     if (theConfig.getParameter<bool>("checkDestSIMU")) detsSIMU = theDetHitCollector.compatibleSIMU( theMuon, ev, es);
173     nDigisCompDets = theDetHitCollector.nDigisCompDets(detsHitsCompatibleWithMuon, ev, es);
174 konec 1.2 clSizeCompDets = theDetHitCollector.clSizeCompDets(detsHitsCompatibleWithMuon, ev, es);
175 konec 1.3
176     for (uint32_t i=0; i< nDigisCompDets.size(); i++) {
177     if (clSizeCompDets[i] > nDigisCompDets[i]) std::cout <<" PROBLEM, event: "<<theCounter<<" cl:"<<clSizeCompDets[i]<<" nDigis:"<<nDigisCompDets[i]<<std::endl;
178     }
179 konec 1.1 }
180    
181    
182     //
183     // fill LinkSynchroAnalysis data
184     //
185     theSynchroGrabber.setMuon(theMuon);
186     RPCRawSynchro::ProdItem rawCounts = theSynchroGrabber.counts(ev,es);
187     counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
188    
189    
190     //
191     // fill L1 RPCemu
192     //
193     if (theConfig.exists("l1RpcEmu") ) {
194     TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
195     L1ObjMakerRpcEmu l1RpcsFromEmu( theConfig.getParameter<edm::InputTag>("l1RpcEmu"), ev);
196     std::vector<L1Obj> l1RpcsEmu = l1RpcsFromEmu();
197     std::vector<bool> l1RpcsEmuMatching(l1RpcsEmu.size(), false);
198     for(unsigned int i=0; i< l1RpcsEmu.size(); ++i) if (matcher(l1RpcsEmu[i].eta, l1RpcsEmu[i].phi, theMuon, ev,es)) l1RpcsEmuMatching[i]=true;
199     l1RpcCollEmu->set(l1RpcsEmu);
200     l1RpcCollEmu->set(l1RpcsEmuMatching);
201     }
202    
203     //
204     // fill L1 objects (Rpc,Oth)
205     //
206     L1ObjMaker l1( theConfig.getParameter<edm::InputTag>("l1MuReadout"), ev);
207     TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
208     std::vector<L1Obj> l1Rpcs = l1(L1ObjMaker::RPCB,L1ObjMaker::RPCF);
209     std::vector<L1Obj> l1Others = l1(L1ObjMaker::DT,L1ObjMaker::CSC);
210     std::vector<bool> l1RpcsMatching(l1Rpcs.size(), false);
211     std::vector<bool> l1OthersMatching(l1Others.size(), false);
212     for(unsigned int i=0; i< l1Rpcs.size(); ++i) if (matcher(l1Rpcs[i].eta, l1Rpcs[i].phi, theMuon, ev,es)) l1RpcsMatching[i]=true;
213     for(unsigned int i=0; i< l1Others.size(); ++i) if (matcher(l1Others[i].eta, l1Others[i].phi, theMuon, ev,es)) l1OthersMatching[i]=true;
214     l1RpcColl->set(l1Rpcs);
215     l1RpcColl->set(l1RpcsMatching);
216     l1OtherColl->set(l1Others);
217     l1OtherColl->set(l1OthersMatching);
218    
219     // std::cout <<"RPCColl:"<<std::endl; l1RpcColl->print();
220     // std::cout <<"RPCCollEmu:"<<std::endl; l1RpcCollEmu->print();
221    
222     //
223     // fill ntuple + cleanup
224     //
225     //std::cout <<" THIS event written!" << std::endl;
226     theTree->Fill();
227     delete event; event = 0;
228     delete muon; muon = 0;
229     delete track; track = 0;
230 konec 1.4 delete bitsL1; bitsL1= 0;
231     delete bitsHLT; bitsHLT= 0;
232 konec 1.1 delete l1RpcColl; l1RpcColl = 0;
233     delete l1OtherColl; l1OtherColl = 0;
234     delete l1RpcCollEmu; l1RpcCollEmu = 0;
235     }
236