CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
98  std::vector<edm::EDGetTokenT<TrajectorySeedCollection>> _seedcollTokens;
99  std::vector<unsigned int> _seedbins;
100  std::vector<double> _seedmax;
101  std::vector<FromTrackRefSeedFilter> _seedfilters;
102  std::vector<edm::EDGetTokenT<std::map<unsigned int, int>>> _multiplicityMapTokens;
103  std::vector<std::string> _labels;
104  std::vector<unsigned int> _selections;
105  std::vector<unsigned int> _binsmult;
106  std::vector<unsigned int> _binseta;
107  std::vector<double> _maxs;
108  std::vector<TH1F*> _hseedmult;
109  std::vector<TH1F*> _hseedeta;
110  std::vector<TH2F*> _hseedphieta;
111  std::vector<TH1F*> _hpixelrhmult;
112  std::vector<TH2F*> _hbpixclusleneta;
113  std::vector<TH2F*> _hfpixclusleneta;
114  std::vector<TH2F*> _hbpixcluslenangle;
115  std::vector<TH2F*> _hfpixcluslenangle;
116  std::vector<std::vector<TH2F*>> _hseedmult2D;
117  std::vector<std::vector<TH2F*>> _hseedeta2D;
118 };
119 
120 //
121 // constants, enums and typedefs
122 //
123 
124 //
125 // static data member definitions
126 //
127 
128 //
129 // constructors and destructor
130 //
132  : _magFieldToken(esConsumes(edm::ESInputTag{"", iConfig.getParameter<std::string>("TTRHBuilder")})),
134  _seedcollTokens(),
135  _seedbins(),
136  _seedmax(),
137  _seedfilters(),
139  _labels(),
140  _selections(),
141  _binsmult(),
142  _binseta(),
143  _maxs(),
144  _hseedmult2D(),
145  _hseedeta2D() {
146  //now do what ever initialization is needed
147 
148  //
149 
150  std::vector<edm::ParameterSet> seedCollectionConfigs =
151  iConfig.getParameter<std::vector<edm::ParameterSet>>("seedCollections");
152 
153  for (std::vector<edm::ParameterSet>::const_iterator scps = seedCollectionConfigs.begin();
154  scps != seedCollectionConfigs.end();
155  ++scps) {
156  _seedcollTokens.push_back(consumes<TrajectorySeedCollection>(scps->getParameter<edm::InputTag>("src")));
157  _seedbins.push_back(scps->getUntrackedParameter<unsigned int>("nBins", 1000));
158  _seedmax.push_back(scps->getUntrackedParameter<double>("maxValue", 100000.));
159 
160  if (scps->exists("trackFilter")) {
161  _seedfilters.push_back(
162  FromTrackRefSeedFilter(consumesCollector(), scps->getParameter<edm::ParameterSet>("trackFilter")));
163  } else {
165  }
166  }
167 
168  std::vector<edm::ParameterSet> correlationConfigs =
169  iConfig.getParameter<std::vector<edm::ParameterSet>>("multiplicityCorrelations");
170 
171  for (std::vector<edm::ParameterSet>::const_iterator ps = correlationConfigs.begin(); ps != correlationConfigs.end();
172  ++ps) {
173  _multiplicityMapTokens.push_back(
174  consumes<std::map<unsigned int, int>>(ps->getParameter<edm::InputTag>("multiplicityMap")));
175  _labels.push_back(ps->getParameter<std::string>("detLabel"));
176  _selections.push_back(ps->getParameter<unsigned int>("detSelection"));
177  _binsmult.push_back(ps->getParameter<unsigned int>("nBins"));
178  _binseta.push_back(ps->getParameter<unsigned int>("nBinsEta"));
179  _maxs.push_back(ps->getParameter<double>("maxValue"));
180  }
181 
183 
184  std::vector<unsigned int>::const_iterator nseedbins = _seedbins.begin();
185  std::vector<double>::const_iterator seedmax = _seedmax.begin();
186  std::vector<FromTrackRefSeedFilter>::const_iterator filter = _seedfilters.begin();
187 
188  for (std::vector<edm::ParameterSet>::const_iterator scps = seedCollectionConfigs.begin();
189  scps != seedCollectionConfigs.end();
190  ++scps, ++nseedbins, ++seedmax, ++filter) {
191  std::string extendedlabel = std::string(scps->getParameter<edm::InputTag>("src").encode()) + filter->suffix();
192 
193  std::string hname = extendedlabel + std::string("_mult");
194  std::string htitle = extendedlabel + std::string(" seed multiplicity");
195  _hseedmult.push_back(tfserv->make<TH1F>(
196  hname.c_str(), htitle.c_str(), *nseedbins + 1, 0.5 - *seedmax / (*nseedbins), *seedmax + 0.5));
197  _hseedmult[_hseedmult.size() - 1]->GetXaxis()->SetTitle("seeds");
198  _hseedmult[_hseedmult.size() - 1]->GetYaxis()->SetTitle("events");
199 
200  hname = extendedlabel + std::string("_eta");
201  htitle = extendedlabel + std::string(" seed pseudorapidity");
202  _hseedeta.push_back(tfserv->make<TH1F>(hname.c_str(), htitle.c_str(), 80, -4., 4.));
203  _hseedeta[_hseedeta.size() - 1]->GetXaxis()->SetTitle("#eta");
204  _hseedeta[_hseedeta.size() - 1]->GetYaxis()->SetTitle("seeds");
205 
206  hname = extendedlabel + std::string("_phieta");
207  htitle = extendedlabel + std::string(" seed phi vs pseudorapidity");
208  _hseedphieta.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 80, -4., 4., 80, -M_PI, M_PI));
209  _hseedphieta[_hseedphieta.size() - 1]->GetXaxis()->SetTitle("#eta");
210  _hseedphieta[_hseedphieta.size() - 1]->GetYaxis()->SetTitle("#phi");
211 
212  _hseedmult2D.push_back(std::vector<TH2F*>());
213  _hseedeta2D.push_back(std::vector<TH2F*>());
214 
215  hname = extendedlabel + std::string("_npixelrh");
216  htitle = extendedlabel + std::string(" seed SiPixelRecHit multiplicity");
217  _hpixelrhmult.push_back(tfserv->make<TH1F>(hname.c_str(), htitle.c_str(), 5, -.5, 4.5));
218  _hpixelrhmult[_hpixelrhmult.size() - 1]->GetXaxis()->SetTitle("NRecHits");
219  _hpixelrhmult[_hpixelrhmult.size() - 1]->GetYaxis()->SetTitle("seeds");
220 
221  hname = extendedlabel + std::string("_bpixleneta");
222  htitle = extendedlabel + std::string(" seed BPIX cluster length vs pseudorapidity");
223  _hbpixclusleneta.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 80, -4., 4., 40, -0.5, 39.5));
224  _hbpixclusleneta[_hbpixclusleneta.size() - 1]->GetXaxis()->SetTitle("#eta");
225  _hbpixclusleneta[_hbpixclusleneta.size() - 1]->GetYaxis()->SetTitle("length");
226 
227  hname = extendedlabel + std::string("_fpixleneta");
228  htitle = extendedlabel + std::string(" seed FPIX cluster length vs pseudorapidity");
229  _hfpixclusleneta.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 80, -4., 4., 40, -0.5, 39.5));
230  _hfpixclusleneta[_hfpixclusleneta.size() - 1]->GetXaxis()->SetTitle("#eta");
231  _hfpixclusleneta[_hfpixclusleneta.size() - 1]->GetYaxis()->SetTitle("length");
232 
233  hname = extendedlabel + std::string("_bpixlenangle");
234  htitle = extendedlabel + std::string(" seed BPIX cluster length vs track projection");
235  _hbpixcluslenangle.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 200, -1., 1., 40, -0.5, 39.5));
236  _hbpixcluslenangle[_hbpixcluslenangle.size() - 1]->GetXaxis()->SetTitle("projection");
237  _hbpixcluslenangle[_hbpixcluslenangle.size() - 1]->GetYaxis()->SetTitle("length");
238 
239  hname = extendedlabel + std::string("_fpixlenangle");
240  htitle = extendedlabel + std::string(" seed FPIX cluster length vs track projection");
241  _hfpixcluslenangle.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 200, -1., 1., 40, -0.5, 39.5));
242  _hfpixcluslenangle[_hfpixcluslenangle.size() - 1]->GetXaxis()->SetTitle("projection");
243  _hfpixcluslenangle[_hfpixcluslenangle.size() - 1]->GetYaxis()->SetTitle("length");
244 
245  for (unsigned int i = 0; i < _multiplicityMapTokens.size(); ++i) {
246  std::string hname2D = extendedlabel + _labels[i];
247  hname2D += "_mult";
248  std::string htitle2D = extendedlabel + " seeds multiplicity";
249  htitle2D += " vs ";
250  htitle2D += _labels[i];
251  htitle2D += " hits";
252  _hseedmult2D[_hseedmult2D.size() - 1].push_back(tfserv->make<TH2F>(hname2D.c_str(),
253  htitle2D.c_str(),
254  _binsmult[i],
255  0.,
256  _maxs[i],
257  *nseedbins + 1,
258  0.5 - *seedmax / (*nseedbins),
259  *seedmax + 0.5));
260  _hseedmult2D[_hseedmult2D.size() - 1][_hseedmult2D[_hseedmult2D.size() - 1].size() - 1]->GetXaxis()->SetTitle(
261  "hits");
262  _hseedmult2D[_hseedmult2D.size() - 1][_hseedmult2D[_hseedmult2D.size() - 1].size() - 1]->GetYaxis()->SetTitle(
263  "seeds");
264 
265  hname2D = extendedlabel + _labels[i];
266  hname2D += "_eta";
267  htitle2D = extendedlabel + " seeds pseudorapidity";
268  htitle2D += " vs ";
269  htitle2D += _labels[i];
270  htitle2D += " hits";
271  _hseedeta2D[_hseedeta2D.size() - 1].push_back(
272  tfserv->make<TH2F>(hname2D.c_str(), htitle2D.c_str(), _binseta[i], 0., _maxs[i], 80, -4., 4.));
273  _hseedeta2D[_hseedeta2D.size() - 1][_hseedeta2D[_hseedeta2D.size() - 1].size() - 1]->GetXaxis()->SetTitle("hits");
274  _hseedeta2D[_hseedeta2D.size() - 1][_hseedeta2D[_hseedeta2D.size() - 1].size() - 1]->GetYaxis()->SetTitle("#eta");
275  }
276  }
277 }
278 
280  // do anything here that needs to be done at desctruction time
281  // (e.g. close files, deallocate resources etc.)
282 }
283 
284 //
285 // member functions
286 //
287 
288 // ------------ method called to for each event ------------
290  using namespace edm;
291 
292  // compute cluster multiplicities
293 
294  std::vector<int> tmpmult(_multiplicityMapTokens.size(), -1);
295  for (unsigned int i = 0; i < _multiplicityMapTokens.size(); ++i) {
297  iEvent.getByToken(_multiplicityMapTokens[i], mults);
298 
299  // check if the selection exists
300 
301  std::map<unsigned int, int>::const_iterator mult = mults->find(_selections[i]);
302 
303  if (mult != mults->end()) {
304  tmpmult[i] = mult->second;
305  } else {
306  edm::LogWarning("DetSelectionNotFound") << " DetSelection " << _selections[i] << " not found";
307  }
308  }
309 
310  // preparation for loop on seeds
311 
312  // TrajectoryStateTransform tsTransform;
313  TSCBLBuilderNoMaterial tscblBuilder; // I could have used TSCBLBuilderWithPropagator
314 
315  const auto theMF = &iSetup.getData(_magFieldToken);
316  const auto& theTTRHBuilder = iSetup.getData(_TTRHBuilderToken);
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() && histomult != _hseedmult.end() && histomult2D != _hseedmult2D.end() &&
337  histoeta != _hseedeta.end() && histoeta2D != _hseedeta2D.end() && histophieta != _hseedphieta.end() &&
338  hpixelrhmult != _hpixelrhmult.end() && histobpixleneta != _hbpixclusleneta.end() &&
339  histofpixleneta != _hfpixclusleneta.end() && histobpixlenangle != _hbpixcluslenangle.end() &&
340  histofpixlenangle != _hfpixcluslenangle.end();
341  ++coll,
342  ++histomult,
343  ++histomult2D,
344  ++histoeta,
345  ++histophieta,
346  ++histoeta2D,
347  ++hpixelrhmult,
348  ++histobpixleneta,
349  ++histofpixleneta,
350  ++histobpixlenangle,
351  ++histofpixlenangle,
352  ++filter) {
353  filter->prepareEvent(iEvent);
354 
356  iEvent.getByToken(*coll, seeds);
357 
358  /*
359  (*histomult)->Fill(seeds->size());
360 
361  for(unsigned int i=0;i<_multiplicityMaps.size();++i) {
362  if(tmpmult[i]>=0) (*histomult2D)[i]->Fill(tmpmult[i],seeds->size());
363  }
364  */
365 
366  // loop on seeds
367 
368  unsigned int nseeds = 0;
369  unsigned int iseed = 0;
370  for (TrajectorySeedCollection::const_iterator seed = seeds->begin(); seed != seeds->end(); ++seed, ++iseed) {
371  if (filter->isSelected(iseed)) {
372  ++nseeds;
373 
374  TransientTrackingRecHit::RecHitPointer recHit = theTTRHBuilder.build(&*(seed->recHits().end() - 1));
376  trajectoryStateTransform::transientState(seed->startingState(), recHit->surface(), theMF);
377  // TrajectoryStateClosestToBeamLine tsAtClosestApproachSeed = tscblBuilder(*state.freeState(),bs); // here I need them BS
378 
379  double eta = state.globalMomentum().eta();
380  double phi = state.globalMomentum().phi();
381 
382  (*histoeta)->Fill(eta);
383  (*histophieta)->Fill(eta, phi);
384 
385  for (unsigned int i = 0; i < _multiplicityMapTokens.size(); ++i) {
386  if (tmpmult[i] >= 0)
387  (*histoeta2D)[i]->Fill(tmpmult[i], eta);
388  }
389 
390  int npixelrh = 0;
391  for (auto const& hit : seed->recHits()) {
392  const SiPixelRecHit* sphit = dynamic_cast<const SiPixelRecHit*>(&hit);
393  if (sphit) {
394  ++npixelrh;
395  // compute state on recHit surface
396  TransientTrackingRecHit::RecHitPointer ttrhit = theTTRHBuilder.build(&hit);
398  trajectoryStateTransform::transientState(seed->startingState(), ttrhit->surface(), theMF);
399 
400  if (sphit->geographicalId().det() == DetId::Tracker &&
402  (*histobpixleneta)->Fill(eta, sphit->cluster()->sizeY());
403  if (tsos.isValid()) {
404  // double normdx = sin(atan2(tsos.localMomentum().x(),tsos.localMomentum().z()));
405  double normdx = tsos.localMomentum().x() / sqrt(tsos.localMomentum().x() * tsos.localMomentum().x() +
406  tsos.localMomentum().z() * tsos.localMomentum().z());
407  (*histobpixlenangle)->Fill(normdx, sphit->cluster()->sizeY());
408  }
409  } else if (sphit->geographicalId().det() == DetId::Tracker &&
411  (*histofpixleneta)->Fill(eta, sphit->cluster()->sizeX());
412  if (tsos.isValid()) {
413  // double normdy = sin(atan2(tsos.localMomentum().y(),tsos.localMomentum().z()));
414  double normdy = tsos.localMomentum().y() / sqrt(tsos.localMomentum().y() * tsos.localMomentum().y() +
415  tsos.localMomentum().z() * tsos.localMomentum().z());
416  (*histofpixlenangle)->Fill(normdy, sphit->cluster()->sizeX());
417  }
418  } else {
419  edm::LogError("InconsistentSiPixelRecHit")
420  << "SiPixelRecHit with a non-pixel DetId " << sphit->geographicalId().rawId();
421  }
422  }
423  }
424  (*hpixelrhmult)->Fill(npixelrh);
425  }
426  }
427  (*histomult)->Fill(nseeds);
428 
429  for (unsigned int i = 0; i < _multiplicityMapTokens.size(); ++i) {
430  if (tmpmult[i] >= 0)
431  (*histomult2D)[i]->Fill(tmpmult[i], nseeds);
432  }
433  }
434 }
435 
437  : m_suffix(""), m_passthrough(true), m_trackcollToken(), m_seltrackrefcollToken(), m_tracks(), m_seltrackrefs() {}
438 
440  const edm::ParameterSet& iConfig)
441  : m_suffix(iConfig.getParameter<std::string>("suffix")),
442  m_passthrough(false),
443  m_trackcollToken(iC.consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trkCollection"))),
444  m_seltrackrefcollToken(
445  iC.consumes<reco::TrackRefVector>(iConfig.getParameter<edm::InputTag>("selRefTrkCollection"))),
446  m_tracks(),
447  m_seltrackrefs() {}
448 
450 
452  if (!m_passthrough) {
453  iEvent.getByToken(m_trackcollToken, m_tracks);
454  iEvent.getByToken(m_seltrackrefcollToken, m_seltrackrefs);
455  }
456 
457  return;
458 }
459 
461  if (m_passthrough) {
462  return true;
463  } else {
464  // create a reference for the element iseed of the track collection
465  const reco::TrackRef trkref(m_tracks, iseed);
466 
467  // loop on the selected trackref to check if there is the same track
468  for (reco::TrackRefVector::const_iterator seltrkref = m_seltrackrefs->begin(); seltrkref != m_seltrackrefs->end();
469  ++seltrkref) {
470  if (trkref == *seltrkref)
471  return true;
472  }
473  }
474  return false;
475 }
476 
477 //define this as a plug-in
SeedMultiplicityAnalyzer(const edm::ParameterSet &)
std::vector< FromTrackRefSeedFilter > _seedfilters
std::vector< unsigned int > _binseta
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
Log< level::Error, false > LogError
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
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::EDGetTokenT< TrajectorySeedCollection > > _seedcollTokens
LocalVector localMomentum() const
bool getData(T &iHolder) const
Definition: EventSetup.h:128
int iEvent
Definition: GenABIO.cc:224
std::vector< unsigned int > _seedbins
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
#define M_PI
std::vector< TH2F * > _hseedphieta
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
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::vector< TH2F * > > _hseedmult2D
T eta() const
Definition: PV3DBase.h:73
GlobalVector globalMomentum() const
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > _magFieldToken
DetId geographicalId() const
Log< level::Warning, false > LogWarning
T x() const
Definition: PV3DBase.h:59
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
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
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > _TTRHBuilderToken