CMS 3D CMS Logo

OverlapProblemTPAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: OverlapProblemTPAnalyzer
4 // Class: OverlapProblemTPAnalyzer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Thu Dec 16 16:32:56 CEST 2010
16 // $Id: OverlapProblemTPAnalyzer.cc,v 1.1 2011/01/22 17:59:36 venturia Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 #include <numeric>
24 #include <vector>
25 
26 // user include files
29 
34 
36 
38 
41 
43 
46 
51 
53 
54 #include "TH1F.h"
55 #include "TH2F.h"
56 //
57 // class decleration
58 //
59 
60 
62 public:
65 
66 private:
67  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
68  virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
69  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
70 
71  // ----------member data ---------------------------
72 
73  TH1F* m_ptp;
74  TH1F* m_etatp;
75  TH1F* m_nhits;
76  TH1F* m_nrechits;
78  TH1F* m_nassotk;
79  TH1F* m_pdgid;
80  TH1F* m_llbit;
81  TH1F* m_statustp;
82 
83  std::vector<TH1F*> m_simhitytecr;
84  std::vector<TH1F*> m_assosimhitytecr;
85 
86 
90 };
91 
92 //
93 // constants, enums and typedefs
94 //
95 
96 //
97 // static data member definitions
98 //
99 
100 //
101 // constructors and destructor
102 //
105  m_tpcollToken(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticlesCollection"))),
106  m_trkcollToken(consumes<edm::View<reco::Track> >(iConfig.getParameter<edm::InputTag>("trackCollection"))),
107  m_associatorToken(consumes<reco::TrackToTrackingParticleAssociator>(edm::InputTag("trackAssociatorByHits")))
108 {
109  //now do what ever initialization is needed
110 
111 
112 
114 
115  m_ptp = tfserv->make<TH1F>("tpmomentum","Tracking Particle momentum",100,0.,200.);
116  m_etatp = tfserv->make<TH1F>("tpeta","Tracking Particle pseudorapidity",100,-4.,4.);
117  m_nhits = tfserv->make<TH1F>("nhits","Tracking Particle associated hits",100,-0.5,99.5);
118  m_nrechits = tfserv->make<TH1F>("nrechits","Tracking Particle associated rec hits",100,-0.5,99.5);
119  m_nrecvssimhits = tfserv->make<TH2F>("nrecvssimhits","Tracking Particle associated rec hits vs sim hits",
120  100,-0.5,99.5,100,-0.5,99.5);
121  m_nassotk = tfserv->make<TH1F>("nassotk","Number of assocated reco tracks",10,-0.5,9.5);
122 
123  m_pdgid = tfserv->make<TH1F>("pdgid","Tracking Particle PDG id",1000,-500.5,499.5);
124  m_llbit = tfserv->make<TH1F>("llbit","Tracking Particle LongLived bit",2,-0.5,1.5);
125  m_statustp = tfserv->make<TH1F>("statustp","Tracking Particle status",2000,-1000.5,999.5);
126 
127  for(unsigned int ring=0;ring<7;++ring) {
128 
129  char name[100];
130  char title[100];
131 
132  sprintf(name,"simytecr_%d",ring+1);
133  sprintf(title,"SimHit local Y TEC ring %d",ring+1);
134 
135  m_simhitytecr.push_back(tfserv->make<TH1F>(name,title,200,-20.,20.));
136 
137  sprintf(name,"assosimytecr_%d",ring+1);
138  sprintf(title,"SimHit local Y TEC ring %d with associated RecHit",ring+1);
139 
140  m_assosimhitytecr.push_back(tfserv->make<TH1F>(name,title,200,-20.,20.));
141 
142  }
143 
144 }
145 
146 
148 {
149 
150  // do anything here that needs to be done at desctruction time
151  // (e.g. close files, deallocate resources etc.)
152 
153 }
154 
155 
156 //
157 // member functions
158 //
159 
160 // ------------ method called to for each event ------------
161 void
163 {
164  using namespace edm;
165 
166  // reco track Handle
167 
168  // Handle<reco::TrackCollection> trkcoll;
170  iEvent.getByToken(m_trkcollToken,trkcoll);
171 
173  iEvent.getByToken(m_tpcollToken,tpcoll);
174 
176  iEvent.getByToken(m_associatorToken,tahandle);
177 
178  // associate reco to sim tracks
179 
180  reco::SimToRecoCollection srcoll = tahandle->associateSimToReco(trkcoll,tpcoll);
181 
182  // loop on Handle with index and use find
183 
184  for(unsigned int index=0 ; index != tpcoll->size() ; ++index) {
185 
186  // get TrackingParticleRef
187 
188  const TrackingParticleRef tp(tpcoll,index);
189 
190  if(std::abs(tp->pdgId())!=13) continue;
191 
192  // get the SimHIt from tracker only
193 
194  // Commented since the new TP's do not have this method
195  // std::vector<PSimHit> tksimhits = tp->trackPSimHit(DetId::Tracker);
196 
197 
198  m_ptp->Fill(tp->p());
199  m_etatp->Fill(tp->eta());
200  // m_nhits->Fill(tp->matchedHit());
201  // With the new Tracking Particles I have to use a different method
202  // m_nhits->Fill(tksimhits.size());
203  m_nhits->Fill(tp->numberOfTrackerHits());
204 
205 
206  m_pdgid->Fill(tp->pdgId());
207  m_llbit->Fill(tp->longLived());
208  m_statustp->Fill(tp->status());
209 
210  // prepare a vector of TrackingRecHit from the associated reco tracks
211 
212  std::vector<DetId> rechits;
213 
214  // look at associated tracks
215 
216  if(srcoll.find(tp) != srcoll.end()) {
217  reco::SimToRecoCollection::result_type trks = srcoll[tp];
218  m_nassotk->Fill(trks.size());
219 
220  // loop on associated tracks and fill TrackingRecHit vector
221  for(reco::SimToRecoCollection::result_type::const_iterator trk = trks.begin();trk!=trks.end();++trk) {
222  for(trackingRecHit_iterator rh = trk->first->recHitsBegin() ; rh!=trk->first->recHitsEnd() ; ++rh) {
223  rechits.push_back((*rh)->geographicalId());
224  }
225 
226  }
227 
228  }
229  else {
230  m_nassotk->Fill(0.);
231  edm::LogInfo("NoAssociatedRecoTrack") << "No associated reco track for TP with p = " << tp->p()
232  << " and eta = " << tp->eta() ;
233  }
234 
235  m_nrechits->Fill(rechits.size());
236  // new method used to be compliant with the new TP's
237  m_nrecvssimhits->Fill(tp->numberOfTrackerHits(),rechits.size());
238 
239  LogDebug("RecHitDetId") << "List of " << rechits.size() << " rechits detid from muon with p = " << tp->p()
240  << "and eta = " << tp->eta();
241  for(unsigned int i=0;i<rechits.size();++i) {
242  LogTrace("RecHitDetId") << rechits[i].rawId();
243  }
244 
245 
246  // loop on sim hits
247 
248 
249  LogDebug("SimHitDetId") << "List of " << tp->numberOfTrackerHits() << " simhits detid from muon with p = " << tp->p()
250  << "and eta = " << tp->eta();
251 
252  // commented since with the new TP's I don't know how to loop on PSimHits
253 
254  /*
255  for( std::vector<PSimHit>::const_iterator sh = tksimhits.begin(); sh!= tksimhits.end(); ++sh) {
256 
257  // check if the SimHit is Tracker and TEC
258 
259  LogTrace("SimHitDetId") << sh->detUnitId();
260 
261  TECDetId det(sh->detUnitId());
262  if(det.subDetector() == SiStripDetId::TEC) {
263 
264  unsigned int iring = det.ring() - 1;
265  m_simhitytecr[iring]->Fill(sh->entryPoint().y());
266 
267  // check if there is a TrackingRecHit in the same detid and if this is the case fill the histos
268 
269  for(std::vector<DetId>::const_iterator rhdet = rechits.begin(); rhdet!= rechits.end() ; ++rhdet) {
270  if(det==*rhdet) {
271  m_assosimhitytecr[iring]->Fill(sh->entryPoint().y());
272  break;
273  }
274  }
275 
276  }
277  }
278  */
279  }
280 
281 }
282 
283 void
285 {
286 }
287 
288 void
290 {
291 }
292 
293 
294 
295 //define this as a plug-in
#define LogDebug(id)
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< TrackingParticle > TrackingParticleCollection
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const_iterator find(const key_type &k) const
find element with specified reference key
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
edm::EDGetTokenT< TrackingParticleCollection > m_tpcollToken
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edm::View< reco::Track > > m_trkcollToken
int iEvent
Definition: GenABIO.cc:230
OverlapProblemTPAnalyzer(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define LogTrace(id)
std::vector< TH1F * > m_simhitytecr
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > m_associatorToken
fixed size matrix
HLT enums.
std::vector< TH1F * > m_assosimhitytecr
reco::SimToRecoCollection associateSimToReco(const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
Definition: Run.h:42