CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
54 
55 #include "TH1F.h"
56 #include "TH2F.h"
57 //
58 // class decleration
59 //
60 
61 
63 public:
66 
67 private:
68  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
69  virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
70  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
71 
72  // ----------member data ---------------------------
73 
74  TH1F* m_ptp;
75  TH1F* m_etatp;
76  TH1F* m_nhits;
77  TH1F* m_nrechits;
79  TH1F* m_nassotk;
80  TH1F* m_pdgid;
81  TH1F* m_llbit;
82  TH1F* m_statustp;
83 
84  std::vector<TH1F*> m_simhitytecr;
85  std::vector<TH1F*> m_assosimhitytecr;
86 
87 
90 };
91 
92 //
93 // constants, enums and typedefs
94 //
95 
96 //
97 // static data member definitions
98 //
99 
100 //
101 // constructors and destructor
102 //
104  m_simhitytecr(), m_assosimhitytecr(),
105  m_tpcollToken(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticlesCollection"))),
106  m_trkcollToken(consumes<edm::View<reco::Track> >(iConfig.getParameter<edm::InputTag>("trackCollection")))
107 
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 
175  // TrackAssociator ESHandle
176 
178  iSetup.get<TrackAssociatorRecord>().get("TrackAssociatorByHits",tahandle);
179 
180  // associate reco to sim tracks
181 
182  reco::SimToRecoCollection srcoll = tahandle->associateSimToReco(trkcoll,tpcoll,&iEvent,&iSetup);
183 
184  // loop on Handle with index and use find
185 
186  for(unsigned int index=0 ; index != tpcoll->size() ; ++index) {
187 
188  // get TrackingParticleRef
189 
190  const TrackingParticleRef tp(tpcoll,index);
191 
192  if(std::abs(tp->pdgId())!=13) continue;
193 
194  // get the SimHIt from tracker only
195 
196  // Commented since the new TP's do not have this method
197  // std::vector<PSimHit> tksimhits = tp->trackPSimHit(DetId::Tracker);
198 
199 
200  m_ptp->Fill(tp->p());
201  m_etatp->Fill(tp->eta());
202  // m_nhits->Fill(tp->matchedHit());
203  // With the new Tracking Particles I have to use a different method
204  // m_nhits->Fill(tksimhits.size());
205  m_nhits->Fill(tp->numberOfTrackerHits());
206 
207 
208  m_pdgid->Fill(tp->pdgId());
209  m_llbit->Fill(tp->longLived());
210  m_statustp->Fill(tp->status());
211 
212  // prepare a vector of TrackingRecHit from the associated reco tracks
213 
214  std::vector<DetId> rechits;
215 
216  // look at associated tracks
217 
218  if(srcoll.find(tp) != srcoll.end()) {
219  reco::SimToRecoCollection::result_type trks = srcoll[tp];
220  m_nassotk->Fill(trks.size());
221 
222  // loop on associated tracks and fill TrackingRecHit vector
223  for(reco::SimToRecoCollection::result_type::const_iterator trk = trks.begin();trk!=trks.end();++trk) {
224  for(trackingRecHit_iterator rh = trk->first->recHitsBegin() ; rh!=trk->first->recHitsEnd() ; ++rh) {
225  rechits.push_back((*rh)->geographicalId());
226  }
227 
228  }
229 
230  }
231  else {
232  m_nassotk->Fill(0.);
233  edm::LogInfo("NoAssociatedRecoTrack") << "No associated reco track for TP with p = " << tp->p()
234  << " and eta = " << tp->eta() ;
235  }
236 
237  m_nrechits->Fill(rechits.size());
238  // new method used to be compliant with the new TP's
239  m_nrecvssimhits->Fill(tp->numberOfTrackerHits(),rechits.size());
240 
241  LogDebug("RecHitDetId") << "List of " << rechits.size() << " rechits detid from muon with p = " << tp->p()
242  << "and eta = " << tp->eta();
243  for(unsigned int i=0;i<rechits.size();++i) {
244  LogTrace("RecHitDetId") << rechits[i].rawId();
245  }
246 
247 
248  // loop on sim hits
249 
250 
251  LogDebug("SimHitDetId") << "List of " << tp->numberOfTrackerHits() << " simhits detid from muon with p = " << tp->p()
252  << "and eta = " << tp->eta();
253 
254  // commented since with the new TP's I don't know how to loop on PSimHits
255 
256  /*
257  for( std::vector<PSimHit>::const_iterator sh = tksimhits.begin(); sh!= tksimhits.end(); ++sh) {
258 
259  // check if the SimHit is Tracker and TEC
260 
261  LogTrace("SimHitDetId") << sh->detUnitId();
262 
263  TECDetId det(sh->detUnitId());
264  if(det.subDetector() == SiStripDetId::TEC) {
265 
266  unsigned int iring = det.ring() - 1;
267  m_simhitytecr[iring]->Fill(sh->entryPoint().y());
268 
269  // check if there is a TrackingRecHit in the same detid and if this is the case fill the histos
270 
271  for(std::vector<DetId>::const_iterator rhdet = rechits.begin(); rhdet!= rechits.end() ; ++rhdet) {
272  if(det==*rhdet) {
273  m_assosimhitytecr[iring]->Fill(sh->entryPoint().y());
274  break;
275  }
276  }
277 
278  }
279  }
280  */
281  }
282 
283 }
284 
285 void
287 {
288 }
289 
290 void
292 {
293 }
294 
295 
296 
297 //define this as a plug-in
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< TrackingParticle > TrackingParticleCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
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
const T & get() const
Definition: EventSetup.h:55
std::vector< TH1F * > m_assosimhitytecr
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
Definition: Run.h:41