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.13 by konec, Tue Apr 23 09:27:55 2013 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"
# Line 21 | Line 23
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 + //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 <    l1ObjColl(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")),
49      theL1ObjMaker(cfg.getParameter<edm::ParameterSet>("l1ObjMaker")),
50 <    theMenuInspector(edm::ParameterSet())
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)
# Line 52 | 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 64 | Line 78 | void L1RpcTreeMaker::beginJob()
78    theTree->Branch("detsSIMU",&detsSIMU);
79  
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 89 | Line 107 | L1RpcTreeMaker::~L1RpcTreeMaker()
107  
108   void L1RpcTreeMaker::analyze(const edm::Event &ev, const edm::EventSetup &es)
109   {
110 +
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 106 | 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();
134 >  simu = new TrackObj();
135  
136    bitsL1 = new TriggerMenuResultObj();
137    bitsHLT = new TriggerMenuResultObj();
# Line 123 | Line 143 | void L1RpcTreeMaker::analyze(const edm::
143    detsSIMU = std::vector<uint32_t>();
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
# Line 151 | Line 185 | void L1RpcTreeMaker::analyze(const edm::
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.) {
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);
# Line 165 | Line 209 | void L1RpcTreeMaker::analyze(const edm::
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    //
# Line 176 | Line 222 | void L1RpcTreeMaker::analyze(const edm::
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(), 0.);
225 >  std::vector<double> deltaR(l1Obj.size(), 999.);
226    TrackToL1ObjMatcher matcher(theConfig.getParameter<edm::ParameterSet>("matcherPSet"));
227 <  for(unsigned int i=0; i< l1Obj.size(); ++i) {
228 <    if (matcher(l1Obj[i].eta, l1Obj[i].phi, theMuon, ev,es)) matching[i]=true;
229 <    TrackToL1ObjMatcher::LastResult result = matcher.lastResult();
230 <    deltaR[i] = sqrt( sqr(result.deltaEta) + sqr(result.deltaPhi) );
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 <  std::cout <<"----------"<<std::endl;
237 <  std::cout <<*l1ObjColl << std::endl;
236 >
237 > //  std::cout <<*l1ObjColl << std::endl;
238 >
239 >  //
240 >  // det HIT+DIGI grabber
241 >  //
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;
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