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