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.3 by konec, Mon Oct 8 07:09:24 2012 UTC vs.
Revision 1.20 by akalinow, Thu Jul 11 11:25:22 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), counts(0),
42 <    l1RpcColl(0) , l1OtherColl(0), l1RpcCollEmu(0),
41 >  : theConfig(cfg), theTree(0), event(0), muon(0), simu(0),
42 >    bitsL1(0), bitsHLT(0),
43 >    counts(0),
44 >    l1ObjColl(0),hitSpec(0), hitSpecSt1(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 48 | 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);
73  
74    theTree->Branch("counts",&counts);
75    theTree->Branch("detsCrossedByMuon",&detsCrossedByMuon);
76    theTree->Branch("detsCrossedByMuonDeepInside",&detsCrossedByMuonDeepInside);
77    theTree->Branch("detsHitsCompatibleWithMuon",&detsHitsCompatibleWithMuon);
78    theTree->Branch("detsSIMU",&detsSIMU);
58  theTree->Branch("nDigisCompDets",&nDigisCompDets);
59  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("hitSpecSt1","HitSpecObj",&hitSpecSt1,32000,99);
83 >  theTree->Branch("digSpec",&digSpec);
84  
85    theHelper.SetOwner();
86    theBestMuonFinder.initHistos(theHelper);
87    theDetHitCollector.initHistos(theHelper);
88    theSynchroGrabber.initHistos(theHelper);
89 +  theDetHitDigiGrabber.initHistos(theHelper);
90   }
91  
92   void L1RpcTreeMaker::endJob()
# Line 87 | Line 108 | L1RpcTreeMaker::~L1RpcTreeMaker()
108   void L1RpcTreeMaker::analyze(const edm::Event &ev, const edm::EventSetup &es)
109   {
110  
90
111    //
112    // check reference muon
113    //
114    const reco::Muon * theMuon = theBestMuonFinder.result(ev,es);
115 <  if (!theMuon || !theBestMuonFinder.isUnique(ev,es) ) return;
115 >  if (theConfig.getParameter<bool>("onlyBestMuEvents") && (!theMuon) ) return;
116    theCounter++;
117  
118    //
# Line 105 | Line 125 | void L1RpcTreeMaker::analyze(const edm::
125    event->id = ev.id().event();
126    event->run = ev.run();
127    event->lumi = ev.luminosityBlock();
128 +  //std::cout <<"-----------------------"<< *event << std::endl;
129  
130    //
131    // create other objects structure
132    //
133    muon = new MuonObj();
134 <  track = new TrackObj();
135 < //  counts = new SynchroCountsObjVect;
134 >  simu = new TrackObj();
135 >
136 >  bitsL1 = new TriggerMenuResultObj();
137 >  bitsHLT = new TriggerMenuResultObj();
138 >
139    counts = std::vector<SynchroCountsObj>();
140    detsCrossedByMuon = std::vector<uint32_t>();
141    detsCrossedByMuonDeepInside = std::vector<uint32_t>();
142 <  detsHitsCompatibleWithMuon = std::vector<uint32_t>();
142 >  detsHitsCompatibleWithMuon = std::vector<DetCluDigiObj>();
143    detsSIMU = std::vector<uint32_t>();
144 <  nDigisCompDets = std::vector<uint32_t>();
145 <  clSizeCompDets = std::vector<uint32_t>();
146 <  l1RpcColl = new L1ObjColl;
147 <  l1OtherColl = new L1ObjColl;
148 <  l1RpcCollEmu = new L1ObjColl;
144 >
145 >  l1ObjColl = new L1ObjColl;
146 >  hitSpec = new HitSpecObj();
147 >  hitSpecSt1 = new HitSpecObj();
148 >  digSpec = std::vector< std::pair<uint32_t, uint32_t> >();
149 >
150 >  //
151 >  // fill Simulated Mu Info
152 >  //
153 >  const SimTrack* aSimMuon = BestSimulatedMuonFinder().result(ev,es);
154 >  if (aSimMuon) {
155 >    int charge = (abs(aSimMuon->type()) == 13) ? aSimMuon->type()/-13 : 0;
156 >    simu->setKine(aSimMuon->momentum().pt(), aSimMuon->momentum().eta(),aSimMuon->momentum().phi(), charge);
157 >  }
158 >  //  std::cout << *simu << std::endl;
159  
160    //
161    // fill muon info
162    //
163 <  muon->setKine(theMuon->track()->pt(), theMuon->track()->eta(), theMuon->track()->phi(), theMuon->track()->charge());
164 <  muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
165 <  muon->nMatchedStations = theMuon->numberOfMatchedStations();
166 <  if (theMuon->isGlobalMuon()) {
167 <    const reco::HitPattern& hp = (theMuon->combinedMuon())->hitPattern();
168 <    muon->nRPCHits = hp.numberOfValidMuonRPCHits();
169 <    muon->nDTHits  = hp.numberOfValidMuonDTHits();
170 <    muon->nCSCHits = hp.numberOfValidMuonCSCHits();
171 <  } else  muon->nRPCHits = muon->nDTHits = muon->nCSCHits = 0;
172 <  muon->nTrackerHits = theMuon->isTrackerMuon() ? (theMuon->innerTrack())->hitPattern().numberOfValidTrackerHits() : 0;
163 >  muon->isUnique = theBestMuonFinder.isUnique(ev,es);
164 >  muon->nAllMuons = theBestMuonFinder.numberOfAllMuons(ev,es);
165 >  muon->nRPCHits = theBestMuonFinder.numberOfValidMuonRPCHits();
166 >  muon->nDTHits  = theBestMuonFinder.numberOfValidMuonDTHits();
167 >  muon->nCSCHits = theBestMuonFinder.numberOfValidMuonCSCHits();
168 >  muon->nTrackerHits = theBestMuonFinder.numberOfValidTrackerHits();
169 >  if (theMuon) {
170 >    muon->setKine(theMuon->bestTrack()->pt(), theMuon->bestTrack()->eta(), theMuon->bestTrack()->phi(), theMuon->bestTrack()->charge());
171 >    muon->setBits(theMuon->isGlobalMuon(), theMuon->isTrackerMuon(), theMuon->isStandAloneMuon(), theMuon->isCaloMuon(), theMuon->isMatchesValid());
172 >    muon->nMatchedStations = theMuon->numberOfMatchedStations();
173 >  }
174 >
175 >  //
176 >  // fill algoBits info
177 >  //
178 >  static edm::RunNumber_t lastRun = 0;
179 >  if (ev.run() != lastRun) {
180 >    lastRun = ev.run();
181 >    bitsL1->names  = theMenuInspector.namesAlgoL1();
182 >    bitsHLT->names = theMenuInspector.namesAlgoHLT();
183 >  }
184 >  bitsL1->firedAlgos = theMenuInspector.firedAlgosL1(ev,es);
185 >  bitsHLT->firedAlgos = theMenuInspector.firedAlgosHLT(ev,es);
186 >  
187  
188 + /* tmp
189 +  edm::Handle<RPCRecHitCollection> recHits;
190 +  ev.getByLabel("rpcRecHits", recHits);
191 +  typedef RPCRecHitCollection::const_iterator IH;
192 +  std::cout <<"Event: " << *event << std::endl;
193 +  for (IH ih=recHits->begin(); ih != recHits->end(); ++ih) {
194 +    std::cout <<"Det: "<< ih->rpcId()<<"is valid: "<< ih->isValid()<< "BX= "<<ih->BunchX() << std::endl;
195 + }
196 + */
197  
198    //
199    // hits and detectors compatible with muon track
200    //
201 <  if ( muon->pt() > 10.) {
202 <    detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
201 >  if (theMuon &&  muon->pt() > 10. && theMuon->isGlobalMuon()) {
202 >    detsHitsCompatibleWithMuon = theDetHitCollector.compatibleHits( theMuon, ev, es);
203      detsCrossedByMuon = theDetHitCollector.compatibleDets( theMuon, ev, es, false);
204      detsCrossedByMuonDeepInside = theDetHitCollector.compatibleDets( theMuon, ev, es, true);
205      if (theConfig.getParameter<bool>("checkDestSIMU")) detsSIMU = theDetHitCollector.compatibleSIMU( theMuon, ev, es);
149    nDigisCompDets = theDetHitCollector.nDigisCompDets(detsHitsCompatibleWithMuon, ev, es);
150    clSizeCompDets = theDetHitCollector.clSizeCompDets(detsHitsCompatibleWithMuon, ev, es);
151
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    }
206    }
207  
208    
209    //
210    // fill LinkSynchroAnalysis data
211    //
212 <  theSynchroGrabber.setMuon(theMuon);
213 <  RPCRawSynchro::ProdItem rawCounts  = theSynchroGrabber.counts(ev,es);
214 <  counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
212 >  if (theMuon && theMuon->isGlobalMuon()) {
213 >    theSynchroGrabber.setMuon(theMuon);
214 >    RPCRawSynchro::ProdItem rawCounts  = theSynchroGrabber.counts(ev,es);
215 >    counts = ConverterRPCRawSynchroSynchroCountsObj::toSynchroObj(rawCounts);
216 >  }
217    
218  
219    //
220 <  // fill L1 RPCemu
220 >  // fill L1 info
221    //
222 <  if (theConfig.exists("l1RpcEmu") ) {
223 <    TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
224 <    L1ObjMakerRpcEmu l1RpcsFromEmu( theConfig.getParameter<edm::InputTag>("l1RpcEmu"), ev);
225 <    std::vector<L1Obj> l1RpcsEmu = l1RpcsFromEmu();
226 <    std::vector<bool> l1RpcsEmuMatching(l1RpcsEmu.size(), false);
227 <    for(unsigned int i=0; i< l1RpcsEmu.size(); ++i) if (matcher(l1RpcsEmu[i].eta, l1RpcsEmu[i].phi, theMuon, ev,es)) l1RpcsEmuMatching[i]=true;
228 <    l1RpcCollEmu->set(l1RpcsEmu);
229 <    l1RpcCollEmu->set(l1RpcsEmuMatching);
222 >  std::vector<L1Obj> l1Obj = theL1ObjMaker(ev);
223 >  l1ObjColl->set( l1Obj);
224 >  std::vector<bool> matching(l1Obj.size(), false);
225 >  std::vector<double> deltaR(l1Obj.size(), 999.);
226 >  TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
227 >  if (theMuon && theMuon->isGlobalMuon()){
228 >    for(unsigned int i=0; i< l1Obj.size(); ++i) {
229 >      if (matcher(l1Obj[i].eta, l1Obj[i].phi, theMuon, ev,es)) matching[i]=true;
230 >      TrackToL1ObjMatcher::LastResult result = matcher.lastResult();
231 >      deltaR[i] = sqrt( sqr(result.deltaEta) + sqr(result.deltaPhi) );
232 >    }
233    }
234 +  l1ObjColl->set( matching );
235 +  l1ObjColl->set( deltaR );
236 +
237 + //  std::cout <<*l1ObjColl << std::endl;
238  
239    //
240 <  // fill L1 objects (Rpc,Oth)
240 >  // det HIT+DIGI grabber
241    //
242 <  L1ObjMaker l1( theConfig.getParameter<edm::InputTag>("l1MuReadout"), ev);
243 <  TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
244 <  std::vector<L1Obj> l1Rpcs = l1(L1ObjMaker::RPCB,L1ObjMaker::RPCF);
245 <  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();
242 >  *hitSpec = theDetHitDigiGrabber.rpcDetHits(ev,es,simu,2);
243 >  *hitSpecSt1 = theDetHitDigiGrabber.rpcDetHits(ev,es,simu,1);
244 >  digSpec  = theDetHitDigiGrabber.digiCollector(ev,es);
245 >  
246  
247    //
248    // fill ntuple + cleanup
249    //
250 <  //std::cout <<" THIS event written!" << std::endl;
250 > //  std::cout <<"THIS event written!" << std::endl;
251    theTree->Fill();
252    delete event; event = 0;
253    delete muon;  muon = 0;
254 <  delete track; track = 0;
255 <  delete l1RpcColl; l1RpcColl = 0;
256 <  delete l1OtherColl; l1OtherColl = 0;
257 <  delete l1RpcCollEmu; l1RpcCollEmu = 0;
254 >  delete simu;  simu = 0;
255 >  delete bitsL1;  bitsL1= 0;
256 >  delete bitsHLT;  bitsHLT= 0;
257 >  delete l1ObjColl; l1ObjColl = 0;
258 >  delete hitSpec; hitSpec = 0;
259 >  delete hitSpecSt1; hitSpecSt1 = 0;
260   }
261                                  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines