CMS 3D CMS Logo

SeedMultiplicityAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackRecoMonitoring
4 // Class: SeedMultiplicityAnalyzer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Mon Oct 27 17:37:53 CET 2008
16 // $Id: SeedMultiplicityAnalyzer.cc,v 1.8 2012/04/21 14:03:26 venturia Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
25 
26 #include <vector>
27 #include <string>
28 #include <numeric>
29 
33 
37 
39 
42 #include "TH1F.h"
43 #include "TH2F.h"
44 
46 
48 
55 
58 
62 
65 
66 
67 
68 //
69 // class decleration
70 //
71 
73 public:
75  ~SeedMultiplicityAnalyzer() override;
76 
78  public:
81  const std::string& suffix() const;
82  void prepareEvent(const edm::Event& iEvent);
83  bool isSelected(const unsigned int iseed) const;
84 
85  private:
86 
93 
94  };
95 
96 private:
97  void analyze(const edm::Event&, const edm::EventSetup&) override;
98 
99  // ----------member data ---------------------------
100 
102  std::vector<edm::EDGetTokenT<TrajectorySeedCollection> > _seedcollTokens;
103  std::vector<unsigned int> _seedbins;
104  std::vector<double> _seedmax;
105  std::vector<FromTrackRefSeedFilter> _seedfilters;
106  std::vector<edm::EDGetTokenT<std::map<unsigned int, int> > > _multiplicityMapTokens;
107  std::vector<std::string> _labels;
108  std::vector<unsigned int> _selections;
109  std::vector<unsigned int> _binsmult;
110  std::vector<unsigned int> _binseta;
111  std::vector<double> _maxs;
112  std::vector<TH1F*> _hseedmult;
113  std::vector<TH1F*> _hseedeta;
114  std::vector<TH2F*> _hseedphieta;
115  std::vector<TH1F*> _hpixelrhmult;
116  std::vector<TH2F*> _hbpixclusleneta;
117  std::vector<TH2F*> _hfpixclusleneta;
118  std::vector<TH2F*> _hbpixcluslenangle;
119  std::vector<TH2F*> _hfpixcluslenangle;
120  std::vector<std::vector<TH2F*> > _hseedmult2D;
121  std::vector<std::vector<TH2F*> > _hseedeta2D;
122 
123 
124 };
125 
126 //
127 // constants, enums and typedefs
128 //
129 
130 //
131 // static data member definitions
132 //
133 
134 //
135 // constructors and destructor
136 //
138  _buildername(iConfig.getParameter<std::string>("TTRHBuilder")),
141 {
142  //now do what ever initialization is needed
143 
144  //
145 
146 
147  std::vector<edm::ParameterSet> seedCollectionConfigs =
148  iConfig.getParameter<std::vector<edm::ParameterSet> >("seedCollections");
149 
150  for(std::vector<edm::ParameterSet>::const_iterator scps=seedCollectionConfigs.begin();scps!=seedCollectionConfigs.end();++scps) {
151 
152  _seedcollTokens.push_back(consumes<TrajectorySeedCollection>(scps->getParameter<edm::InputTag>("src")));
153  _seedbins.push_back(scps->getUntrackedParameter<unsigned int>("nBins",1000));
154  _seedmax.push_back(scps->getUntrackedParameter<double>("maxValue",100000.));
155 
156  if(scps->exists("trackFilter")) {
157  _seedfilters.push_back(FromTrackRefSeedFilter(consumesCollector(),scps->getParameter<edm::ParameterSet>("trackFilter")));
158  }
159  else {
161  }
162  }
163 
164  std::vector<edm::ParameterSet> correlationConfigs =
165  iConfig.getParameter<std::vector<edm::ParameterSet> >("multiplicityCorrelations");
166 
167  for(std::vector<edm::ParameterSet>::const_iterator ps=correlationConfigs.begin();ps!=correlationConfigs.end();++ps) {
168 
169  _multiplicityMapTokens.push_back(consumes<std::map<unsigned int, int> >(ps->getParameter<edm::InputTag>("multiplicityMap")));
170  _labels.push_back(ps->getParameter<std::string>("detLabel"));
171  _selections.push_back(ps->getParameter<unsigned int>("detSelection"));
172  _binsmult.push_back(ps->getParameter<unsigned int>("nBins"));
173  _binseta.push_back(ps->getParameter<unsigned int>("nBinsEta"));
174  _maxs.push_back(ps->getParameter<double>("maxValue"));
175 
176  }
177 
178 
179 
181 
182  std::vector<unsigned int>::const_iterator nseedbins = _seedbins.begin();
183  std::vector<double>::const_iterator seedmax = _seedmax.begin();
184  std::vector<FromTrackRefSeedFilter>::const_iterator filter = _seedfilters.begin();
185 
186  for(std::vector<edm::ParameterSet>::const_iterator scps=seedCollectionConfigs.begin();scps!=seedCollectionConfigs.end();++scps,++nseedbins,++seedmax,++filter) {
187 
188  std::string extendedlabel = std::string(scps->getParameter<edm::InputTag>("src").encode()) + filter->suffix();
189 
190  std::string hname = extendedlabel + std::string("_mult");
191  std::string htitle = extendedlabel + std::string(" seed multiplicity");
192  _hseedmult.push_back(tfserv->make<TH1F>(hname.c_str(),htitle.c_str(),*nseedbins+1,0.5-*seedmax/(*nseedbins),*seedmax+0.5));
193  _hseedmult[_hseedmult.size()-1]->GetXaxis()->SetTitle("seeds"); _hseedmult[_hseedmult.size()-1]->GetYaxis()->SetTitle("events");
194 
195  hname = extendedlabel + std::string("_eta");
196  htitle = extendedlabel + std::string(" seed pseudorapidity");
197  _hseedeta.push_back(tfserv->make<TH1F>(hname.c_str(),htitle.c_str(),80,-4.,4.));
198  _hseedeta[_hseedeta.size()-1]->GetXaxis()->SetTitle("#eta"); _hseedeta[_hseedeta.size()-1]->GetYaxis()->SetTitle("seeds");
199 
200  hname = extendedlabel + std::string("_phieta");
201  htitle = extendedlabel + std::string(" seed phi vs pseudorapidity");
202  _hseedphieta.push_back(tfserv->make<TH2F>(hname.c_str(),htitle.c_str(),80,-4.,4.,80,-M_PI,M_PI));
203  _hseedphieta[_hseedphieta.size()-1]->GetXaxis()->SetTitle("#eta"); _hseedphieta[_hseedphieta.size()-1]->GetYaxis()->SetTitle("#phi");
204 
205  _hseedmult2D.push_back(std::vector<TH2F*>());
206  _hseedeta2D.push_back(std::vector<TH2F*>());
207 
208 
209  hname = extendedlabel + std::string("_npixelrh");
210  htitle = extendedlabel + std::string(" seed SiPixelRecHit multiplicity");
211  _hpixelrhmult.push_back(tfserv->make<TH1F>(hname.c_str(),htitle.c_str(),5,-.5,4.5));
212  _hpixelrhmult[_hpixelrhmult.size()-1]->GetXaxis()->SetTitle("NRecHits"); _hpixelrhmult[_hpixelrhmult.size()-1]->GetYaxis()->SetTitle("seeds");
213 
214  hname = extendedlabel + std::string("_bpixleneta");
215  htitle = extendedlabel + std::string(" seed BPIX cluster length vs pseudorapidity");
216  _hbpixclusleneta.push_back(tfserv->make<TH2F>(hname.c_str(),htitle.c_str(),80,-4.,4.,40,-0.5,39.5));
217  _hbpixclusleneta[_hbpixclusleneta.size()-1]->GetXaxis()->SetTitle("#eta"); _hbpixclusleneta[_hbpixclusleneta.size()-1]->GetYaxis()->SetTitle("length");
218 
219  hname = extendedlabel + std::string("_fpixleneta");
220  htitle = extendedlabel + std::string(" seed FPIX cluster length vs pseudorapidity");
221  _hfpixclusleneta.push_back(tfserv->make<TH2F>(hname.c_str(),htitle.c_str(),80,-4.,4.,40,-0.5,39.5));
222  _hfpixclusleneta[_hfpixclusleneta.size()-1]->GetXaxis()->SetTitle("#eta"); _hfpixclusleneta[_hfpixclusleneta.size()-1]->GetYaxis()->SetTitle("length");
223 
224  hname = extendedlabel + std::string("_bpixlenangle");
225  htitle = extendedlabel + std::string(" seed BPIX cluster length vs track projection");
226  _hbpixcluslenangle.push_back(tfserv->make<TH2F>(hname.c_str(),htitle.c_str(),200,-1.,1.,40,-0.5,39.5));
227  _hbpixcluslenangle[_hbpixcluslenangle.size()-1]->GetXaxis()->SetTitle("projection"); _hbpixcluslenangle[_hbpixcluslenangle.size()-1]->GetYaxis()->SetTitle("length");
228 
229  hname = extendedlabel + std::string("_fpixlenangle");
230  htitle = extendedlabel + std::string(" seed FPIX cluster length vs track projection");
231  _hfpixcluslenangle.push_back(tfserv->make<TH2F>(hname.c_str(),htitle.c_str(),200,-1.,1.,40,-0.5,39.5));
232  _hfpixcluslenangle[_hfpixcluslenangle.size()-1]->GetXaxis()->SetTitle("projection"); _hfpixcluslenangle[_hfpixcluslenangle.size()-1]->GetYaxis()->SetTitle("length");
233 
234 
235  for(unsigned int i=0;i< _multiplicityMapTokens.size() ; ++i) {
236 
237 
238  std::string hname2D = extendedlabel + _labels[i];
239  hname2D += "_mult";
240  std::string htitle2D = extendedlabel + " seeds multiplicity";
241  htitle2D += " vs ";
242  htitle2D += _labels[i];
243  htitle2D += " hits";
244  _hseedmult2D[_hseedmult2D.size()-1].push_back(tfserv->make<TH2F>(hname2D.c_str(),htitle2D.c_str(),_binsmult[i],0.,_maxs[i],
245  *nseedbins+1,0.5-*seedmax/(*nseedbins),*seedmax+0.5));
246  _hseedmult2D[_hseedmult2D.size()-1][_hseedmult2D[_hseedmult2D.size()-1].size()-1]->GetXaxis()->SetTitle("hits");
247  _hseedmult2D[_hseedmult2D.size()-1][_hseedmult2D[_hseedmult2D.size()-1].size()-1]->GetYaxis()->SetTitle("seeds");
248 
249  hname2D = extendedlabel + _labels[i];
250  hname2D += "_eta";
251  htitle2D = extendedlabel + " seeds pseudorapidity";
252  htitle2D += " vs ";
253  htitle2D += _labels[i];
254  htitle2D += " hits";
255  _hseedeta2D[_hseedeta2D.size()-1].push_back(tfserv->make<TH2F>(hname2D.c_str(),htitle2D.c_str(),_binseta[i],0.,_maxs[i],
256  80,-4.,4.));
257  _hseedeta2D[_hseedeta2D.size()-1][_hseedeta2D[_hseedeta2D.size()-1].size()-1]->GetXaxis()->SetTitle("hits");
258  _hseedeta2D[_hseedeta2D.size()-1][_hseedeta2D[_hseedeta2D.size()-1].size()-1]->GetYaxis()->SetTitle("#eta");
259 
260 
261  }
262 
263  }
264 
265 }
266 
267 
269 {
270 
271  // do anything here that needs to be done at desctruction time
272  // (e.g. close files, deallocate resources etc.)
273 
274 }
275 
276 
277 //
278 // member functions
279 //
280 
281 // ------------ method called to for each event ------------
282 void
284 {
285  using namespace edm;
286 
287  // compute cluster multiplicities
288 
289  std::vector<int> tmpmult(_multiplicityMapTokens.size(),-1);
290  for(unsigned int i=0;i<_multiplicityMapTokens.size();++i) {
292  iEvent.getByToken(_multiplicityMapTokens[i],mults);
293 
294  // check if the selection exists
295 
296  std::map<unsigned int, int>::const_iterator mult = mults->find(_selections[i]);
297 
298  if(mult!=mults->end()) {
299  tmpmult[i]=mult->second;
300  }
301  else {
302  edm::LogWarning("DetSelectionNotFound") << " DetSelection "
303  << _selections[i] << " not found";
304  }
305  }
306 
307  // preparation for loop on seeds
308 
309  // TrajectoryStateTransform tsTransform;
310  TSCBLBuilderNoMaterial tscblBuilder; // I could have used TSCBLBuilderWithPropagator
311 
313  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
314 
316  iSetup.get<TransientRecHitRecord>().get(_buildername,theTTRHBuilder);
317 
318  // I need:
319  // - beamspot bs POSTPONED
320 
321  std::vector<TH1F*>::iterator histomult=_hseedmult.begin();
322  std::vector<std::vector<TH2F*> >::iterator histomult2D=_hseedmult2D.begin();
323  std::vector<TH1F*>::iterator histoeta=_hseedeta.begin();
324  std::vector<TH2F*>::iterator histophieta=_hseedphieta.begin();
325  std::vector<std::vector<TH2F*> >::iterator histoeta2D=_hseedeta2D.begin();
326  std::vector<TH1F*>::iterator hpixelrhmult=_hpixelrhmult.begin();
327  std::vector<TH2F*>::iterator histobpixleneta=_hbpixclusleneta.begin();
328  std::vector<TH2F*>::iterator histofpixleneta=_hfpixclusleneta.begin();
329  std::vector<TH2F*>::iterator histobpixlenangle=_hbpixcluslenangle.begin();
330  std::vector<TH2F*>::iterator histofpixlenangle=_hfpixcluslenangle.begin();
331  std::vector<FromTrackRefSeedFilter>::iterator filter=_seedfilters.begin();
332 
333  // loop on seed collections
334 
335  for(std::vector<edm::EDGetTokenT<TrajectorySeedCollection>>::const_iterator coll=_seedcollTokens.begin();
336  coll!=_seedcollTokens.end() &&
337  histomult!=_hseedmult.end() && histomult2D!=_hseedmult2D.end() &&
338  histoeta!=_hseedeta.end() && histoeta2D!=_hseedeta2D.end() &&
339  histophieta!=_hseedphieta.end() &&
340  hpixelrhmult!= _hpixelrhmult.end() &&
341  histobpixleneta != _hbpixclusleneta.end() && histofpixleneta != _hfpixclusleneta.end() &&
342  histobpixlenangle != _hbpixcluslenangle.end() && histofpixlenangle != _hfpixcluslenangle.end() ;
343  ++coll,++histomult,++histomult2D,++histoeta,++histophieta,++histoeta2D,++hpixelrhmult,
344  ++histobpixleneta,++histofpixleneta,++histobpixlenangle,++histofpixlenangle,++filter) {
345 
346  filter->prepareEvent(iEvent);
347 
349  iEvent.getByToken(*coll,seeds);
350 
351  /*
352  (*histomult)->Fill(seeds->size());
353 
354  for(unsigned int i=0;i<_multiplicityMaps.size();++i) {
355  if(tmpmult[i]>=0) (*histomult2D)[i]->Fill(tmpmult[i],seeds->size());
356  }
357  */
358 
359  // loop on seeds
360 
361  unsigned int nseeds=0;
362  unsigned int iseed=0;
363  for(TrajectorySeedCollection::const_iterator seed= seeds->begin(); seed!=seeds->end(); ++seed,++iseed) {
364 
365  if(filter->isSelected(iseed)) {
366 
367  ++nseeds;
368 
369  TransientTrackingRecHit::RecHitPointer recHit = theTTRHBuilder->build(&*(seed->recHits().second-1));
370  TrajectoryStateOnSurface state = trajectoryStateTransform::transientState( seed->startingState(), recHit->surface(), theMF.product());
371  // TrajectoryStateClosestToBeamLine tsAtClosestApproachSeed = tscblBuilder(*state.freeState(),bs); // here I need them BS
372 
373  double eta = state.globalMomentum().eta();
374  double phi = state.globalMomentum().phi();
375 
376  (*histoeta)->Fill(eta);
377  (*histophieta)->Fill(eta,phi);
378 
379  for(unsigned int i=0;i<_multiplicityMapTokens.size();++i) {
380  if(tmpmult[i]>=0) (*histoeta2D)[i]->Fill(tmpmult[i],eta);
381  }
382 
383  // loop on rec hits
384 
385  TrajectorySeed::range rechits = seed->recHits();
386 
387  int npixelrh = 0;
388  for(TrajectorySeed::const_iterator hit = rechits.first; hit!= rechits.second; ++hit) {
389  const SiPixelRecHit* sphit = dynamic_cast<const SiPixelRecHit*>(&(*hit));
390  if(sphit) {
391  ++npixelrh;
392  // compute state on recHit surface
393  TransientTrackingRecHit::RecHitPointer ttrhit = theTTRHBuilder->build(&*hit);
394  TrajectoryStateOnSurface tsos = trajectoryStateTransform::transientState( seed->startingState(), ttrhit->surface(), theMF.product());
395 
397  (*histobpixleneta)->Fill(eta,sphit->cluster()->sizeY());
398  if(tsos.isValid()) {
399  // double normdx = sin(atan2(tsos.localMomentum().x(),tsos.localMomentum().z()));
400  double normdx = tsos.localMomentum().x()/sqrt(tsos.localMomentum().x()*tsos.localMomentum().x()+
401  tsos.localMomentum().z()*tsos.localMomentum().z());
402  (*histobpixlenangle)->Fill(normdx,sphit->cluster()->sizeY());
403  }
404  }
406  (*histofpixleneta)->Fill(eta,sphit->cluster()->sizeX());
407  if(tsos.isValid()) {
408  // double normdy = sin(atan2(tsos.localMomentum().y(),tsos.localMomentum().z()));
409  double normdy = tsos.localMomentum().y()/sqrt(tsos.localMomentum().y()*tsos.localMomentum().y()+
410  tsos.localMomentum().z()*tsos.localMomentum().z());
411  (*histofpixlenangle)->Fill(normdy,sphit->cluster()->sizeX());
412  }
413  }
414  else {
415  edm::LogError("InconsistentSiPixelRecHit") << "SiPixelRecHit with a non-pixel DetId " << sphit->geographicalId().rawId();
416  }
417  }
418  }
419  (*hpixelrhmult)->Fill(npixelrh);
420  }
421  }
422  (*histomult)->Fill(nseeds);
423 
424  for(unsigned int i=0;i<_multiplicityMapTokens.size();++i) {
425  if(tmpmult[i]>=0) (*histomult2D)[i]->Fill(tmpmult[i],nseeds);
426  }
427 
428  }
429 }
430 
431 
432 
433 
435  m_suffix(""),m_passthrough(true),
436  m_trackcollToken(),m_seltrackrefcollToken(),m_tracks(),m_seltrackrefs() { }
437 
439  m_suffix(iConfig.getParameter<std::string>("suffix")),
441  m_trackcollToken(iC.consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trkCollection"))),
442  m_seltrackrefcollToken(iC.consumes<reco::TrackRefVector>(iConfig.getParameter<edm::InputTag>("selRefTrkCollection"))),
443  m_tracks(),m_seltrackrefs() { }
444 
446 
448 
449  if(!m_passthrough) {
450 
453 
454  }
455 
456  return;
457 }
458 
460 
461  if(m_passthrough) {
462  return true;
463  }
464  else {
465  // create a reference for the element iseed of the track collection
466  const reco::TrackRef trkref(m_tracks,iseed);
467 
468  // loop on the selected trackref to check if there is the same track
469  for(reco::TrackRefVector::const_iterator seltrkref=m_seltrackrefs->begin();seltrkref!=m_seltrackrefs->end();++seltrkref) {
470  if(trkref==*seltrkref) return true;
471  }
472 
473  }
474  return false;
475 }
476 
477 
478 
479 //define this as a plug-in
T getParameter(std::string const &) const
SeedMultiplicityAnalyzer(const edm::ParameterSet &)
std::vector< FromTrackRefSeedFilter > _seedfilters
std::vector< unsigned int > _binseta
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< unsigned int > _selections
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< std::string > _labels
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
T y() const
Definition: PV3DBase.h:63
std::vector< TH2F * > _hfpixcluslenangle
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::vector< std::vector< TH2F * > > _hseedeta2D
std::vector< TH2F * > _hfpixclusleneta
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< unsigned int > _binsmult
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:253
edm::RefVector< TrackCollection > TrackRefVector
vector of reference to Track in the same collection
Definition: TrackFwd.h:26
std::string encode() const
Definition: InputTag.cc:166
std::vector< edm::EDGetTokenT< std::map< unsigned int, int > > > _multiplicityMapTokens
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::EDGetTokenT< TrajectorySeedCollection > > _seedcollTokens
LocalVector localMomentum() const
int iEvent
Definition: GenABIO.cc:230
std::vector< unsigned int > _seedbins
recHitContainer::const_iterator const_iterator
edm::EDGetTokenT< reco::TrackRefVector > m_seltrackrefcollToken
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
edm::EDGetTokenT< reco::TrackCollection > m_trackcollToken
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
std::pair< const_iterator, const_iterator > range
std::shared_ptr< TrackingRecHit const > RecHitPointer
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
#define M_PI
std::vector< TH2F * > _hseedphieta
JetCorrectorParametersCollection coll
Definition: classes.h:10
std::vector< TH1F * > _hpixelrhmult
int iseed
Definition: AMPTWrapper.h:124
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
std::vector< TH2F * > _hbpixcluslenangle
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
std::vector< std::vector< TH2F * > > _hseedmult2D
T eta() const
Definition: PV3DBase.h:76
fixed size matrix
HLT enums.
GlobalVector globalMomentum() const
T get() const
Definition: EventSetup.h:62
DetId geographicalId() const
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
std::vector< TH2F * > _hbpixclusleneta
Our base class.
Definition: SiPixelRecHit.h:23
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39