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 
69 class SeedMultiplicityAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
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")})),
133  _TTRHBuilderToken(esConsumes()),
134  _seedcollTokens(),
135  _seedbins(),
136  _seedmax(),
137  _seedfilters(),
138  _multiplicityMapTokens(),
139  _labels(),
140  _selections(),
141  _binsmult(),
142  _binseta(),
143  _maxs(),
144  _hseedmult2D(),
145  _hseedeta2D() {
146  //now do what ever initialization is needed
147  usesResource(TFileService::kSharedResource);
148 
149  //
150 
151  std::vector<edm::ParameterSet> seedCollectionConfigs =
152  iConfig.getParameter<std::vector<edm::ParameterSet>>("seedCollections");
153 
154  for (std::vector<edm::ParameterSet>::const_iterator scps = seedCollectionConfigs.begin();
155  scps != seedCollectionConfigs.end();
156  ++scps) {
157  _seedcollTokens.push_back(consumes<TrajectorySeedCollection>(scps->getParameter<edm::InputTag>("src")));
158  _seedbins.push_back(scps->getUntrackedParameter<unsigned int>("nBins", 1000));
159  _seedmax.push_back(scps->getUntrackedParameter<double>("maxValue", 100000.));
160 
161  if (scps->exists("trackFilter")) {
162  _seedfilters.push_back(
163  FromTrackRefSeedFilter(consumesCollector(), scps->getParameter<edm::ParameterSet>("trackFilter")));
164  } else {
165  _seedfilters.push_back(FromTrackRefSeedFilter());
166  }
167  }
168 
169  std::vector<edm::ParameterSet> correlationConfigs =
170  iConfig.getParameter<std::vector<edm::ParameterSet>>("multiplicityCorrelations");
171 
172  for (std::vector<edm::ParameterSet>::const_iterator ps = correlationConfigs.begin(); ps != correlationConfigs.end();
173  ++ps) {
174  _multiplicityMapTokens.push_back(
175  consumes<std::map<unsigned int, int>>(ps->getParameter<edm::InputTag>("multiplicityMap")));
176  _labels.push_back(ps->getParameter<std::string>("detLabel"));
177  _selections.push_back(ps->getParameter<unsigned int>("detSelection"));
178  _binsmult.push_back(ps->getParameter<unsigned int>("nBins"));
179  _binseta.push_back(ps->getParameter<unsigned int>("nBinsEta"));
180  _maxs.push_back(ps->getParameter<double>("maxValue"));
181  }
182 
184 
185  std::vector<unsigned int>::const_iterator nseedbins = _seedbins.begin();
186  std::vector<double>::const_iterator seedmax = _seedmax.begin();
187  std::vector<FromTrackRefSeedFilter>::const_iterator filter = _seedfilters.begin();
188 
189  for (std::vector<edm::ParameterSet>::const_iterator scps = seedCollectionConfigs.begin();
190  scps != seedCollectionConfigs.end();
191  ++scps, ++nseedbins, ++seedmax, ++filter) {
192  std::string extendedlabel = std::string(scps->getParameter<edm::InputTag>("src").encode()) + filter->suffix();
193 
194  std::string hname = extendedlabel + std::string("_mult");
195  std::string htitle = extendedlabel + std::string(" seed multiplicity");
196  _hseedmult.push_back(tfserv->make<TH1F>(
197  hname.c_str(), htitle.c_str(), *nseedbins + 1, 0.5 - *seedmax / (*nseedbins), *seedmax + 0.5));
198  _hseedmult[_hseedmult.size() - 1]->GetXaxis()->SetTitle("seeds");
199  _hseedmult[_hseedmult.size() - 1]->GetYaxis()->SetTitle("events");
200 
201  hname = extendedlabel + std::string("_eta");
202  htitle = extendedlabel + std::string(" seed pseudorapidity");
203  _hseedeta.push_back(tfserv->make<TH1F>(hname.c_str(), htitle.c_str(), 80, -4., 4.));
204  _hseedeta[_hseedeta.size() - 1]->GetXaxis()->SetTitle("#eta");
205  _hseedeta[_hseedeta.size() - 1]->GetYaxis()->SetTitle("seeds");
206 
207  hname = extendedlabel + std::string("_phieta");
208  htitle = extendedlabel + std::string(" seed phi vs pseudorapidity");
209  _hseedphieta.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 80, -4., 4., 80, -M_PI, M_PI));
210  _hseedphieta[_hseedphieta.size() - 1]->GetXaxis()->SetTitle("#eta");
211  _hseedphieta[_hseedphieta.size() - 1]->GetYaxis()->SetTitle("#phi");
212 
213  _hseedmult2D.push_back(std::vector<TH2F*>());
214  _hseedeta2D.push_back(std::vector<TH2F*>());
215 
216  hname = extendedlabel + std::string("_npixelrh");
217  htitle = extendedlabel + std::string(" seed SiPixelRecHit multiplicity");
218  _hpixelrhmult.push_back(tfserv->make<TH1F>(hname.c_str(), htitle.c_str(), 5, -.5, 4.5));
219  _hpixelrhmult[_hpixelrhmult.size() - 1]->GetXaxis()->SetTitle("NRecHits");
220  _hpixelrhmult[_hpixelrhmult.size() - 1]->GetYaxis()->SetTitle("seeds");
221 
222  hname = extendedlabel + std::string("_bpixleneta");
223  htitle = extendedlabel + std::string(" seed BPIX cluster length vs pseudorapidity");
224  _hbpixclusleneta.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 80, -4., 4., 40, -0.5, 39.5));
225  _hbpixclusleneta[_hbpixclusleneta.size() - 1]->GetXaxis()->SetTitle("#eta");
226  _hbpixclusleneta[_hbpixclusleneta.size() - 1]->GetYaxis()->SetTitle("length");
227 
228  hname = extendedlabel + std::string("_fpixleneta");
229  htitle = extendedlabel + std::string(" seed FPIX cluster length vs pseudorapidity");
230  _hfpixclusleneta.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 80, -4., 4., 40, -0.5, 39.5));
231  _hfpixclusleneta[_hfpixclusleneta.size() - 1]->GetXaxis()->SetTitle("#eta");
232  _hfpixclusleneta[_hfpixclusleneta.size() - 1]->GetYaxis()->SetTitle("length");
233 
234  hname = extendedlabel + std::string("_bpixlenangle");
235  htitle = extendedlabel + std::string(" seed BPIX cluster length vs track projection");
236  _hbpixcluslenangle.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 200, -1., 1., 40, -0.5, 39.5));
237  _hbpixcluslenangle[_hbpixcluslenangle.size() - 1]->GetXaxis()->SetTitle("projection");
238  _hbpixcluslenangle[_hbpixcluslenangle.size() - 1]->GetYaxis()->SetTitle("length");
239 
240  hname = extendedlabel + std::string("_fpixlenangle");
241  htitle = extendedlabel + std::string(" seed FPIX cluster length vs track projection");
242  _hfpixcluslenangle.push_back(tfserv->make<TH2F>(hname.c_str(), htitle.c_str(), 200, -1., 1., 40, -0.5, 39.5));
243  _hfpixcluslenangle[_hfpixcluslenangle.size() - 1]->GetXaxis()->SetTitle("projection");
244  _hfpixcluslenangle[_hfpixcluslenangle.size() - 1]->GetYaxis()->SetTitle("length");
245 
246  for (unsigned int i = 0; i < _multiplicityMapTokens.size(); ++i) {
247  std::string hname2D = extendedlabel + _labels[i];
248  hname2D += "_mult";
249  std::string htitle2D = extendedlabel + " seeds multiplicity";
250  htitle2D += " vs ";
251  htitle2D += _labels[i];
252  htitle2D += " hits";
253  _hseedmult2D[_hseedmult2D.size() - 1].push_back(tfserv->make<TH2F>(hname2D.c_str(),
254  htitle2D.c_str(),
255  _binsmult[i],
256  0.,
257  _maxs[i],
258  *nseedbins + 1,
259  0.5 - *seedmax / (*nseedbins),
260  *seedmax + 0.5));
261  _hseedmult2D[_hseedmult2D.size() - 1][_hseedmult2D[_hseedmult2D.size() - 1].size() - 1]->GetXaxis()->SetTitle(
262  "hits");
263  _hseedmult2D[_hseedmult2D.size() - 1][_hseedmult2D[_hseedmult2D.size() - 1].size() - 1]->GetYaxis()->SetTitle(
264  "seeds");
265 
266  hname2D = extendedlabel + _labels[i];
267  hname2D += "_eta";
268  htitle2D = extendedlabel + " seeds pseudorapidity";
269  htitle2D += " vs ";
270  htitle2D += _labels[i];
271  htitle2D += " hits";
272  _hseedeta2D[_hseedeta2D.size() - 1].push_back(
273  tfserv->make<TH2F>(hname2D.c_str(), htitle2D.c_str(), _binseta[i], 0., _maxs[i], 80, -4., 4.));
274  _hseedeta2D[_hseedeta2D.size() - 1][_hseedeta2D[_hseedeta2D.size() - 1].size() - 1]->GetXaxis()->SetTitle("hits");
275  _hseedeta2D[_hseedeta2D.size() - 1][_hseedeta2D[_hseedeta2D.size() - 1].size() - 1]->GetYaxis()->SetTitle("#eta");
276  }
277  }
278 }
279 
281  // do anything here that needs to be done at desctruction time
282  // (e.g. close files, deallocate resources etc.)
283 }
284 
285 //
286 // member functions
287 //
288 
289 // ------------ method called to for each event ------------
291  using namespace edm;
292 
293  // compute cluster multiplicities
294 
295  std::vector<int> tmpmult(_multiplicityMapTokens.size(), -1);
296  for (unsigned int i = 0; i < _multiplicityMapTokens.size(); ++i) {
298  iEvent.getByToken(_multiplicityMapTokens[i], mults);
299 
300  // check if the selection exists
301 
302  std::map<unsigned int, int>::const_iterator mult = mults->find(_selections[i]);
303 
304  if (mult != mults->end()) {
305  tmpmult[i] = mult->second;
306  } else {
307  edm::LogWarning("DetSelectionNotFound") << " DetSelection " << _selections[i] << " not found";
308  }
309  }
310 
311  // preparation for loop on seeds
312 
313  // TrajectoryStateTransform tsTransform;
314  TSCBLBuilderNoMaterial tscblBuilder; // I could have used TSCBLBuilderWithPropagator
315 
316  const auto theMF = &iSetup.getData(_magFieldToken);
317  const auto& theTTRHBuilder = iSetup.getData(_TTRHBuilderToken);
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().end() - 1));
377  trajectoryStateTransform::transientState(seed->startingState(), recHit->surface(), theMF);
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  int npixelrh = 0;
392  for (auto const& hit : seed->recHits()) {
393  const SiPixelRecHit* sphit = dynamic_cast<const SiPixelRecHit*>(&hit);
394  if (sphit) {
395  ++npixelrh;
396  // compute state on recHit surface
397  TransientTrackingRecHit::RecHitPointer ttrhit = theTTRHBuilder.build(&hit);
399  trajectoryStateTransform::transientState(seed->startingState(), ttrhit->surface(), theMF);
400 
401  if (sphit->geographicalId().det() == DetId::Tracker &&
403  (*histobpixleneta)->Fill(eta, sphit->cluster()->sizeY());
404  if (tsos.isValid()) {
405  // double normdx = sin(atan2(tsos.localMomentum().x(),tsos.localMomentum().z()));
406  double normdx = tsos.localMomentum().x() / sqrt(tsos.localMomentum().x() * tsos.localMomentum().x() +
407  tsos.localMomentum().z() * tsos.localMomentum().z());
408  (*histobpixlenangle)->Fill(normdx, sphit->cluster()->sizeY());
409  }
410  } else if (sphit->geographicalId().det() == DetId::Tracker &&
412  (*histofpixleneta)->Fill(eta, sphit->cluster()->sizeX());
413  if (tsos.isValid()) {
414  // double normdy = sin(atan2(tsos.localMomentum().y(),tsos.localMomentum().z()));
415  double normdy = tsos.localMomentum().y() / sqrt(tsos.localMomentum().y() * tsos.localMomentum().y() +
416  tsos.localMomentum().z() * tsos.localMomentum().z());
417  (*histofpixlenangle)->Fill(normdy, sphit->cluster()->sizeX());
418  }
419  } else {
420  edm::LogError("InconsistentSiPixelRecHit")
421  << "SiPixelRecHit with a non-pixel DetId " << sphit->geographicalId().rawId();
422  }
423  }
424  }
425  (*hpixelrhmult)->Fill(npixelrh);
426  }
427  }
428  (*histomult)->Fill(nseeds);
429 
430  for (unsigned int i = 0; i < _multiplicityMapTokens.size(); ++i) {
431  if (tmpmult[i] >= 0)
432  (*histomult2D)[i]->Fill(tmpmult[i], nseeds);
433  }
434  }
435 }
436 
438  : m_suffix(""), m_passthrough(true), m_trackcollToken(), m_seltrackrefcollToken(), m_tracks(), m_seltrackrefs() {}
439 
441  const edm::ParameterSet& iConfig)
442  : m_suffix(iConfig.getParameter<std::string>("suffix")),
443  m_passthrough(false),
444  m_trackcollToken(iC.consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trkCollection"))),
445  m_seltrackrefcollToken(
446  iC.consumes<reco::TrackRefVector>(iConfig.getParameter<edm::InputTag>("selRefTrkCollection"))),
447  m_tracks(),
448  m_seltrackrefs() {}
449 
451 
453  if (!m_passthrough) {
454  iEvent.getByToken(m_trackcollToken, m_tracks);
455  iEvent.getByToken(m_seltrackrefcollToken, m_seltrackrefs);
456  }
457 
458  return;
459 }
460 
462  if (m_passthrough) {
463  return true;
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();
470  ++seltrkref) {
471  if (trkref == *seltrkref)
472  return true;
473  }
474  }
475  return false;
476 }
477 
478 //define this as a plug-in
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
static const std::string kSharedResource
Definition: TFileService.h:76
SeedMultiplicityAnalyzer(const edm::ParameterSet &)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< FromTrackRefSeedFilter > _seedfilters
std::vector< unsigned int > _binseta
T z() const
Definition: PV3DBase.h:61
std::string encode() const
Definition: InputTag.cc:159
std::vector< unsigned int > _selections
std::vector< std::string > _labels
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< TH2F * > _hfpixcluslenangle
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
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
std::vector< edm::EDGetTokenT< std::map< unsigned int, int > > > _multiplicityMapTokens
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::EDGetTokenT< TrajectorySeedCollection > > _seedcollTokens
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
std::vector< unsigned int > _seedbins
edm::EDGetTokenT< reco::TrackRefVector > m_seltrackrefcollToken
T sqrt(T t)
Definition: SSEVec.h:19
edm::EDGetTokenT< reco::TrackCollection > m_trackcollToken
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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)
DetId geographicalId() const
std::vector< TH2F * > _hbpixcluslenangle
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< std::vector< TH2F * > > _hseedmult2D
fixed size matrix
HLT enums.
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > _magFieldToken
Log< level::Warning, false > LogWarning
std::vector< TH2F * > _hbpixclusleneta
Our base class.
Definition: SiPixelRecHit.h:23
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > _TTRHBuilderToken