ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/L1RpcTriggerAnalysis/plugins/L1RpcTreeMaker.cc
(Generate patch)

Comparing UserCode/L1RpcTriggerAnalysis/plugins/L1RpcTreeMaker.cc (file contents):
Revision 1.4 by konec, Tue Oct 23 11:12:48 2012 UTC vs.
Revision 1.19 by konec, Fri May 17 13:02:12 2013 UTC

# Line 11 | Line 11
11   #include "DataFormats/MuonReco/interface/MuonSelectors.h"
12   #include "DataFormats/TrackReco/interface/TrackFwd.h"
13   #include "DataFormats/TrackReco/interface/Track.h"
14 + #include "SimDataFormats/Track/interface/SimTrack.h"
15 +
16  
17  
18   #include "UserCode/L1RpcTriggerAnalysis/interface/BestMuonFinder.h"
19   #include "UserCode/L1RpcTriggerAnalysis/interface/DetHitCompatibleCollector.h"
20   #include "UserCode/L1RpcTriggerAnalysis/interface/L1ObjMaker.h"
19 #include "UserCode/L1RpcTriggerAnalysis/interface/L1ObjMakerRpcEmu.h"
21   #include "UserCode/L1RpcTriggerAnalysis/interface/TrackToL1ObjMatcher.h"
22   #include "DataFormats/RPCDigi/interface/RPCRawSynchro.h"
23   #include "UserCode/L1RpcTriggerAnalysis/interface/ConverterRPCRawSynchroSynchroCountsObj.h"
24   #include "UserCode/L1RpcTriggerAnalysis/interface/TriggerMenuResultObj.h"
25  
26 + #include "UserCode/L1RpcTriggerAnalysis/interface/BestSimulatedMuonFinder.h"
27 +
28   #include "TFile.h"
29   #include "TTree.h"
30  
31 < template <class T> T sqr( T t) {return t*t;}
31 > //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 + template <class T> T sqr( T t) {return t*t;}
39 +
40   L1RpcTreeMaker::L1RpcTreeMaker(const edm::ParameterSet& cfg)
41 <  : theConfig(cfg), theTree(0), event(0), muon(0), track(0),
41 >  : theConfig(cfg), theTree(0), event(0), muon(0), simu(0),
42      bitsL1(0), bitsHLT(0),
43      counts(0),
44 <    l1RpcColl(0) , l1OtherColl(0), l1RpcCollEmu(0),
44 >    l1ObjColl(0),hitSpec(0),
45      theCounter(0),
46      theBestMuonFinder(cfg.getParameter<edm::ParameterSet>("bestMuonFinder")),
47      theDetHitCollector(cfg.getParameter<edm::ParameterSet>("detHitCollector")),
48 <    theSynchroGrabber(cfg.getParameter<edm::ParameterSet>("linkSynchroGrabber"))
48 >    theSynchroGrabber(cfg.getParameter<edm::ParameterSet>("linkSynchroGrabber")),
49 >    theL1ObjMaker(cfg.getParameter<edm::ParameterSet>("l1ObjMaker")),
50 >    theMenuInspector( cfg.exists("menuInspector")
51 >                      ?  cfg.getParameter<edm::ParameterSet>("menuInspector")
52 >                      : edm::ParameterSet() ),
53 >    theDetHitDigiGrabber( cfg.getParameter<edm::ParameterSet>("detHitDigiGrabber") )
54   { }
55  
56 < void L1RpcTreeMaker::beginRun( const edm::Run &ru, const edm::EventSetup &es)
56 > void L1RpcTreeMaker::beginRun(const edm::Run &ru, const edm::EventSetup &es)
57   {
58 +  std::cout <<" L1RpcTreeMaker::beginRun CALLED" << std::endl;
59 +  theMenuInspector.checkRun(ru,es);
60   }
61  
62   void L1RpcTreeMaker::beginJob()
# Line 50 | Line 66 | void L1RpcTreeMaker::beginJob()
66  
67    theTree->Branch("event","EventObj",&event,32000,99);
68    theTree->Branch("muon","MuonObj",&muon,32000,99);
69 <  theTree->Branch("track", "TrackObj",&track,32000,99);
69 >  theTree->Branch("simu", "TrackObj",&simu,32000,99);
70  
71    theTree->Branch("bitsL1" ,"TriggerMenuResultObj",&bitsL1 ,32000,99);
72    theTree->Branch("bitsHLT","TriggerMenuResultObj",&bitsHLT,32000,99);
# Line 60 | Line 76 | void L1RpcTreeMaker::beginJob()
76    theTree->Branch("detsCrossedByMuonDeepInside",&detsCrossedByMuonDeepInside);
77    theTree->Branch("detsHitsCompatibleWithMuon",&detsHitsCompatibleWithMuon);
78    theTree->Branch("detsSIMU",&detsSIMU);
63  theTree->Branch("nDigisCompDets",&nDigisCompDets);
64  theTree->Branch("clSizeCompDets",&clSizeCompDets);
79  
80 <  theTree->Branch("l1RpcColl","L1ObjColl",&l1RpcColl,32000,99);
81 <  theTree->Branch("l1RpcCollEmu","L1ObjColl",&l1RpcCollEmu,32000,99);
82 <  theTree->Branch("l1OtherColl","L1ObjColl",&l1OtherColl,32000,99);
80 >  theTree->Branch("l1ObjColl","L1ObjColl",&l1ObjColl,32000,99);
81 >  theTree->Branch("hitSpec","HitSpecObj",&hitSpec,32000,99);
82 >  theTree->Branch("digSpec",&digSpec);
83  
84    theHelper.SetOwner();
85    theBestMuonFinder.initHistos(theHelper);
86    theDetHitCollector.initHistos(theHelper);
87    theSynchroGrabber.initHistos(theHelper);
88 +  theDetHitDigiGrabber.initHistos(theHelper);
89   }
90  
91   void L1RpcTreeMaker::endJob()
# Line 92 | Line 107 | L1RpcTreeMaker::~L1RpcTreeMaker()
107   void L1RpcTreeMaker::analyze(const edm::Event &ev, const edm::EventSetup &es)
108   {
109  
95
110    //
111    // check reference muon
112    //
113    const reco::Muon * theMuon = theBestMuonFinder.result(ev,es);
114 <  if (!theMuon || !theBestMuonFinder.isUnique(ev,es) ) return;
114 >  if (theConfig.getParameter<bool>("onlyBestMuEvents") && (!theMuon) ) return;
115    theCounter++;
116  
117    //
# Line 110 | Line 124 | void L1RpcTreeMaker::analyze(const edm::
124    event->id = ev.id().event();
125    event->run = ev.run();
126    event->lumi = ev.luminosityBlock();
127 +  //std::cout <<"-----------------------"<< *event << std::endl;
128  
129    //
130    // create other objects structure
131    //
132    muon = new MuonObj();
133 <  track = new TrackObj();
133 >  simu = new TrackObj();
134  
135    bitsL1 = new TriggerMenuResultObj();
136    bitsHLT = new TriggerMenuResultObj();
137  
123 //  counts = new SynchroCountsObjVect;
138    counts = std::vector<SynchroCountsObj>();
139    detsCrossedByMuon = std::vector<uint32_t>();
140    detsCrossedByMuonDeepInside = std::vector<uint32_t>();
141 <  detsHitsCompatibleWithMuon = std::vector<uint32_t>();
141 >  detsHitsCompatibleWithMuon = std::vector<DetCluDigiObj>();
142    detsSIMU = std::vector<uint32_t>();
143 <  nDigisCompDets = std::vector<uint32_t>();
144 <  clSizeCompDets = std::vector<uint32_t>();
145 <  l1RpcColl = new L1ObjColl;
146 <  l1OtherColl = new L1ObjColl;
147 <  l1RpcCollEmu = new L1ObjColl;
143 >
144 >  l1ObjColl = new L1ObjColl;
145 >  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  
158    //
159    // fill muon info
160    //
161 <  muon->setKine(theMuon->track()->pt(), theMuon->track()->eta(), theMuon->track()->phi(), theMuon->track()->charge());
162 <  muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
163 <  muon->nMatchedStations = theMuon->numberOfMatchedStations();
164 <  if (theMuon->isGlobalMuon()) {
165 <    const reco::HitPattern& hp = (theMuon->combinedMuon())->hitPattern();
166 <    muon->nRPCHits = hp.numberOfValidMuonRPCHits();
167 <    muon->nDTHits  = hp.numberOfValidMuonDTHits();
168 <    muon->nCSCHits = hp.numberOfValidMuonCSCHits();
169 <  } else  muon->nRPCHits = muon->nDTHits = muon->nCSCHits = 0;
170 <  muon->nTrackerHits = theMuon->isTrackerMuon() ? (theMuon->innerTrack())->hitPattern().numberOfValidTrackerHits() : 0;
161 >  muon->isUnique = theBestMuonFinder.isUnique(ev,es);
162 >  muon->nAllMuons = theBestMuonFinder.numberOfAllMuons(ev,es);
163 >  muon->nRPCHits = theBestMuonFinder.numberOfValidMuonRPCHits();
164 >  muon->nDTHits  = theBestMuonFinder.numberOfValidMuonDTHits();
165 >  muon->nCSCHits = theBestMuonFinder.numberOfValidMuonCSCHits();
166 >  muon->nTrackerHits = theBestMuonFinder.numberOfValidTrackerHits();
167 >  if (theMuon) {
168 >    muon->setKine(theMuon->bestTrack()->pt(), theMuon->bestTrack()->eta(), theMuon->bestTrack()->phi(), theMuon->bestTrack()->charge());
169 >    muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
170 >    muon->nMatchedStations = theMuon->numberOfMatchedStations();
171 >  }
172  
173 +  //
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 +
186 + /* 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    //
197    // hits and detectors compatible with muon track
198    //
199 <  if ( muon->pt() > 10.) {
200 <    detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
199 >  if (theMuon &&  muon->pt() > 10. && theMuon->isGlobalMuon()) {
200 >    detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
201      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);
158    nDigisCompDets = theDetHitCollector.nDigisCompDets(detsHitsCompatibleWithMuon, ev, es);
159    clSizeCompDets = theDetHitCollector.clSizeCompDets(detsHitsCompatibleWithMuon, ev, es);
160
161    for (uint32_t i=0; i< nDigisCompDets.size(); i++) {
162      if (clSizeCompDets[i] > nDigisCompDets[i]) std::cout <<" PROBLEM, event: "<<theCounter<<" cl:"<<clSizeCompDets[i]<<" nDigis:"<<nDigisCompDets[i]<<std::endl;
163    }
204    }
205  
206    
207    //
208    // fill LinkSynchroAnalysis data
209    //
210 <  theSynchroGrabber.setMuon(theMuon);
211 <  RPCRawSynchro::ProdItem rawCounts  = theSynchroGrabber.counts(ev,es);
212 <  counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
210 >  if (theMuon && theMuon->isGlobalMuon()) {
211 >    theSynchroGrabber.setMuon(theMuon);
212 >    RPCRawSynchro::ProdItem rawCounts  = theSynchroGrabber.counts(ev,es);
213 >    counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
214 >  }
215    
216  
217    //
218 <  // fill L1 RPCemu
218 >  // fill L1 info
219    //
220 <  if (theConfig.exists("l1RpcEmu") ) {
221 <    TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
222 <    L1ObjMakerRpcEmu l1RpcsFromEmu( theConfig.getParameter<edm::InputTag>("l1RpcEmu"), ev);
223 <    std::vector<L1Obj> l1RpcsEmu = l1RpcsFromEmu();
224 <    std::vector<bool> l1RpcsEmuMatching(l1RpcsEmu.size(), false);
225 <    for(unsigned int i=0; i< l1RpcsEmu.size(); ++i) if (matcher(l1RpcsEmu[i].eta, l1RpcsEmu[i].phi, theMuon, ev,es)) l1RpcsEmuMatching[i]=true;
226 <    l1RpcCollEmu->set(l1RpcsEmu);
227 <    l1RpcCollEmu->set(l1RpcsEmuMatching);
220 >  std::vector<L1Obj> l1Obj = theL1ObjMaker(ev);
221 >  l1ObjColl->set( l1Obj);
222 >  std::vector<bool> matching(l1Obj.size(), false);
223 >  std::vector<double> deltaR(l1Obj.size(), 999.);
224 >  TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
225 >  if (theMuon && theMuon->isGlobalMuon()){
226 >    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    }
232 +  l1ObjColl->set( matching );
233 +  l1ObjColl->set( deltaR );
234 +
235 + //  std::cout <<*l1ObjColl << std::endl;
236  
237    //
238 <  // fill L1 objects (Rpc,Oth)
238 >  // det HIT+DIGI grabber
239    //
240 <  L1ObjMaker l1( theConfig.getParameter<edm::InputTag>("l1MuReadout"), ev);
241 <  TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
242 <  std::vector<L1Obj> l1Rpcs = l1(L1ObjMaker::RPCB,L1ObjMaker::RPCF);
194 <  std::vector<L1Obj> l1Others = l1(L1ObjMaker::DT,L1ObjMaker::CSC);
195 <  std::vector<bool> l1RpcsMatching(l1Rpcs.size(), false);
196 <  std::vector<bool> l1OthersMatching(l1Others.size(), false);
197 <  for(unsigned int i=0; i< l1Rpcs.size(); ++i) if (matcher(l1Rpcs[i].eta, l1Rpcs[i].phi, theMuon, ev,es)) l1RpcsMatching[i]=true;
198 <  for(unsigned int i=0; i< l1Others.size(); ++i) if (matcher(l1Others[i].eta, l1Others[i].phi, theMuon, ev,es)) l1OthersMatching[i]=true;
199 <  l1RpcColl->set(l1Rpcs);
200 <  l1RpcColl->set(l1RpcsMatching);
201 <  l1OtherColl->set(l1Others);
202 <  l1OtherColl->set(l1OthersMatching);
203 <
204 < //  std::cout <<"RPCColl:"<<std::endl; l1RpcColl->print();
205 < //  std::cout <<"RPCCollEmu:"<<std::endl; l1RpcCollEmu->print();
240 >  *hitSpec = theDetHitDigiGrabber.rpcDetHits(ev,es,simu);
241 >  digSpec  = theDetHitDigiGrabber.digiCollector(ev,es);
242 >  
243  
244    //
245    // fill ntuple + cleanup
246    //
247 <  //std::cout <<" THIS event written!" << std::endl;
247 > //  std::cout <<"THIS event written!" << std::endl;
248    theTree->Fill();
249    delete event; event = 0;
250    delete muon;  muon = 0;
251 <  delete track; track = 0;
251 >  delete simu;  simu = 0;
252    delete bitsL1;  bitsL1= 0;
253    delete bitsHLT;  bitsHLT= 0;
254 <  delete l1RpcColl; l1RpcColl = 0;
255 <  delete l1OtherColl; l1OtherColl = 0;
219 <  delete l1RpcCollEmu; l1RpcCollEmu = 0;
254 >  delete l1ObjColl; l1ObjColl = 0;
255 >  delete hitSpec; hitSpec = 0;
256   }
257                                  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines