ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/plugins/L1RpcTreeMaker.cc
Revision: 1.3
Committed: Mon Oct 8 07:09:24 2012 UTC (12 years, 6 months ago) by konec
Content type: text/plain
Branch: MAIN
Changes since 1.2: +4 -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/L1ObjMakerRpcEmu.h"
20     #include "UserCode/L1RpcTriggerAnalysis/interface/TrackToL1ObjMatcher.h"
21     #include "DataFormats/RPCDigi/interface/RPCRawSynchro.h"
22     #include "UserCode/L1RpcTriggerAnalysis/interface/ConverterRPCRawSynchroSynchroCountsObj.h"
23    
24    
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     : theConfig(cfg), theTree(0), event(0), muon(0), track(0), counts(0),
33     l1RpcColl(0) , l1OtherColl(0), l1RpcCollEmu(0),
34     theCounter(0),
35     theBestMuonFinder(cfg.getParameter<edm::ParameterSet>("bestMuonFinder")),
36     theDetHitCollector(cfg.getParameter<edm::ParameterSet>("detHitCollector")),
37     theSynchroGrabber(cfg.getParameter<edm::ParameterSet>("linkSynchroGrabber"))
38     { }
39    
40     void L1RpcTreeMaker::beginRun( const edm::Run &ru, const edm::EventSetup &es)
41     {
42     }
43    
44     void L1RpcTreeMaker::beginJob()
45     {
46     theFile = new TFile(theConfig.getParameter<std::string>("treeFileName").c_str(),"RECREATE");
47     theTree = new TTree("tL1Rpc","L1RpcEfficciency");
48    
49     theTree->Branch("event","EventObj",&event,32000,99);
50     theTree->Branch("muon","MuonObj",&muon,32000,99);
51     theTree->Branch("track", "TrackObj",&track,32000,99);
52    
53     theTree->Branch("counts",&counts);
54     theTree->Branch("detsCrossedByMuon",&detsCrossedByMuon);
55     theTree->Branch("detsCrossedByMuonDeepInside",&detsCrossedByMuonDeepInside);
56     theTree->Branch("detsHitsCompatibleWithMuon",&detsHitsCompatibleWithMuon);
57     theTree->Branch("detsSIMU",&detsSIMU);
58     theTree->Branch("nDigisCompDets",&nDigisCompDets);
59 konec 1.2 theTree->Branch("clSizeCompDets",&clSizeCompDets);
60 konec 1.1
61     theTree->Branch("l1RpcColl","L1ObjColl",&l1RpcColl,32000,99);
62     theTree->Branch("l1RpcCollEmu","L1ObjColl",&l1RpcCollEmu,32000,99);
63     theTree->Branch("l1OtherColl","L1ObjColl",&l1OtherColl,32000,99);
64    
65     theHelper.SetOwner();
66     theBestMuonFinder.initHistos(theHelper);
67     theDetHitCollector.initHistos(theHelper);
68     theSynchroGrabber.initHistos(theHelper);
69     }
70    
71     void L1RpcTreeMaker::endJob()
72     {
73     theFile->Write();
74     delete theFile;
75    
76     std::string helperFile = theConfig.getParameter<std::string>("histoFileName");
77     TFile f(helperFile.c_str(),"RECREATE");
78     theHelper.Write();
79     f.Close();
80     }
81    
82     L1RpcTreeMaker::~L1RpcTreeMaker()
83     {
84     std::cout <<"L1RpcTreeMaker: Event counter is: "<<theCounter<<std::endl;
85     }
86    
87     void L1RpcTreeMaker::analyze(const edm::Event &ev, const edm::EventSetup &es)
88     {
89    
90    
91     //
92     // check reference muon
93     //
94     const reco::Muon * theMuon = theBestMuonFinder.result(ev,es);
95     if (!theMuon || !theBestMuonFinder.isUnique(ev,es) ) return;
96     theCounter++;
97    
98     //
99     // fill event information
100     //
101     event = new EventObj;
102     event->bx = ev.bunchCrossing();
103     event->orbit = ev.orbitNumber();
104     event->time = ev.time().value();
105     event->id = ev.id().event();
106     event->run = ev.run();
107     event->lumi = ev.luminosityBlock();
108    
109     //
110     // create other objects structure
111     //
112     muon = new MuonObj();
113     track = new TrackObj();
114     // counts = new SynchroCountsObjVect;
115     counts = std::vector<SynchroCountsObj>();
116     detsCrossedByMuon = std::vector<uint32_t>();
117     detsCrossedByMuonDeepInside = std::vector<uint32_t>();
118     detsHitsCompatibleWithMuon = std::vector<uint32_t>();
119     detsSIMU = std::vector<uint32_t>();
120     nDigisCompDets = std::vector<uint32_t>();
121 konec 1.2 clSizeCompDets = std::vector<uint32_t>();
122 konec 1.1 l1RpcColl = new L1ObjColl;
123     l1OtherColl = new L1ObjColl;
124     l1RpcCollEmu = new L1ObjColl;
125    
126     //
127     // fill muon info
128     //
129     muon->setKine(theMuon->track()->pt(), theMuon->track()->eta(), theMuon->track()->phi(), theMuon->track()->charge());
130     muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
131     muon->nMatchedStations = theMuon->numberOfMatchedStations();
132     if (theMuon->isGlobalMuon()) {
133     const reco::HitPattern& hp = (theMuon->combinedMuon())->hitPattern();
134     muon->nRPCHits = hp.numberOfValidMuonRPCHits();
135     muon->nDTHits = hp.numberOfValidMuonDTHits();
136     muon->nCSCHits = hp.numberOfValidMuonCSCHits();
137     } else muon->nRPCHits = muon->nDTHits = muon->nCSCHits = 0;
138     muon->nTrackerHits = theMuon->isTrackerMuon() ? (theMuon->innerTrack())->hitPattern().numberOfValidTrackerHits() : 0;
139    
140    
141     //
142     // hits and detectors compatible with muon track
143     //
144     if ( muon->pt() > 10.) {
145     detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
146     detsCrossedByMuon = theDetHitCollector.compatibleDets( theMuon, ev, es, false);
147     detsCrossedByMuonDeepInside = theDetHitCollector.compatibleDets( theMuon, ev, es, true);
148     if (theConfig.getParameter<bool>("checkDestSIMU")) detsSIMU = theDetHitCollector.compatibleSIMU( theMuon, ev, es);
149     nDigisCompDets = theDetHitCollector.nDigisCompDets(detsHitsCompatibleWithMuon, ev, es);
150 konec 1.2 clSizeCompDets = theDetHitCollector.clSizeCompDets(detsHitsCompatibleWithMuon, ev, es);
151 konec 1.3
152     for (uint32_t i=0; i< nDigisCompDets.size(); i++) {
153     if (clSizeCompDets[i] > nDigisCompDets[i]) std::cout <<" PROBLEM, event: "<<theCounter<<" cl:"<<clSizeCompDets[i]<<" nDigis:"<<nDigisCompDets[i]<<std::endl;
154     }
155 konec 1.1 }
156    
157    
158     //
159     // fill LinkSynchroAnalysis data
160     //
161     theSynchroGrabber.setMuon(theMuon);
162     RPCRawSynchro::ProdItem rawCounts = theSynchroGrabber.counts(ev,es);
163     counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
164    
165    
166     //
167     // fill L1 RPCemu
168     //
169     if (theConfig.exists("l1RpcEmu") ) {
170     TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
171     L1ObjMakerRpcEmu l1RpcsFromEmu( theConfig.getParameter<edm::InputTag>("l1RpcEmu"), ev);
172     std::vector<L1Obj> l1RpcsEmu = l1RpcsFromEmu();
173     std::vector<bool> l1RpcsEmuMatching(l1RpcsEmu.size(), false);
174     for(unsigned int i=0; i< l1RpcsEmu.size(); ++i) if (matcher(l1RpcsEmu[i].eta, l1RpcsEmu[i].phi, theMuon, ev,es)) l1RpcsEmuMatching[i]=true;
175     l1RpcCollEmu->set(l1RpcsEmu);
176     l1RpcCollEmu->set(l1RpcsEmuMatching);
177     }
178    
179     //
180     // fill L1 objects (Rpc,Oth)
181     //
182     L1ObjMaker l1( theConfig.getParameter<edm::InputTag>("l1MuReadout"), ev);
183     TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
184     std::vector<L1Obj> l1Rpcs = l1(L1ObjMaker::RPCB,L1ObjMaker::RPCF);
185     std::vector<L1Obj> l1Others = l1(L1ObjMaker::DT,L1ObjMaker::CSC);
186     std::vector<bool> l1RpcsMatching(l1Rpcs.size(), false);
187     std::vector<bool> l1OthersMatching(l1Others.size(), false);
188     for(unsigned int i=0; i< l1Rpcs.size(); ++i) if (matcher(l1Rpcs[i].eta, l1Rpcs[i].phi, theMuon, ev,es)) l1RpcsMatching[i]=true;
189     for(unsigned int i=0; i< l1Others.size(); ++i) if (matcher(l1Others[i].eta, l1Others[i].phi, theMuon, ev,es)) l1OthersMatching[i]=true;
190     l1RpcColl->set(l1Rpcs);
191     l1RpcColl->set(l1RpcsMatching);
192     l1OtherColl->set(l1Others);
193     l1OtherColl->set(l1OthersMatching);
194    
195     // std::cout <<"RPCColl:"<<std::endl; l1RpcColl->print();
196     // std::cout <<"RPCCollEmu:"<<std::endl; l1RpcCollEmu->print();
197    
198     //
199     // fill ntuple + cleanup
200     //
201     //std::cout <<" THIS event written!" << std::endl;
202     theTree->Fill();
203     delete event; event = 0;
204     delete muon; muon = 0;
205     delete track; track = 0;
206     delete l1RpcColl; l1RpcColl = 0;
207     delete l1OtherColl; l1OtherColl = 0;
208     delete l1RpcCollEmu; l1RpcCollEmu = 0;
209     }
210