CMS 3D CMS Logo

dEdxHitAnalyzer.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Loic Quertenmont
5  */
7 
12 
14 
18 
19 #include <string>
20 #include "TMath.h"
21 
23  : fullconf_(iConfig),
24  conf_(fullconf_.getParameter<edm::ParameterSet>("dEdxParameters")),
25  doAllPlots_(conf_.getParameter<bool>("doAllPlots")),
26  doDeDxPlots_(conf_.getParameter<bool>("doDeDxPlots")),
27  genTriggerEventFlag_(new GenericTriggerEventFlag(
28  conf_.getParameter<edm::ParameterSet>("genericTriggerEventPSet"), consumesCollector(), *this)) {
30  trackToken_ = consumes<reco::TrackCollection>(trackInputTag_);
31 
32  dEdxInputList_ = conf_.getParameter<std::vector<std::string> >("deDxHitProducers");
33  for (auto const& tag : dEdxInputList_) {
34  dEdxTokenList_.push_back(consumes<reco::DeDxHitInfoAss>(edm::InputTag(tag)));
35  }
36 
37  // parameters from the configuration
38  MEFolderName = conf_.getParameter<std::string>("FolderName");
39 
40  dEdxNHitBin = conf_.getParameter<int>("dEdxNHitBin");
41  dEdxNHitMin = conf_.getParameter<double>("dEdxNHitMin");
42  dEdxNHitMax = conf_.getParameter<double>("dEdxNHitMax");
43 
44  dEdxStripBin = conf_.getParameter<int>("dEdxStripBin");
45  dEdxStripMin = conf_.getParameter<double>("dEdxStripMin");
46  dEdxStripMax = conf_.getParameter<double>("dEdxStripMax");
47 
48  dEdxPixelBin = conf_.getParameter<int>("dEdxPixelBin");
49  dEdxPixelMin = conf_.getParameter<double>("dEdxPixelMin");
50  dEdxPixelMax = conf_.getParameter<double>("dEdxPixelMax");
51 
52  dEdxHarm2Bin = conf_.getParameter<int>("dEdxHarm2Bin");
53  dEdxHarm2Min = conf_.getParameter<double>("dEdxHarm2Min");
54  dEdxHarm2Max = conf_.getParameter<double>("dEdxHarm2Max");
55 }
56 
59  delete genTriggerEventFlag_;
60 }
61 
62 // -- BeginRun
63 //---------------------------------------------------------------------------------//
64 void dEdxHitAnalyzer::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
65  // Initialize the GenericTriggerEventFlag
66  if (genTriggerEventFlag_->on())
67  genTriggerEventFlag_->initRun(iRun, iSetup);
68 }
69 
70 void dEdxHitAnalyzer::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
72 
73  // book the Hit Property histograms
74  // ---------------------------------------------------------------------------------//
75 
76  if (doDeDxPlots_ || doAllPlots_) {
77  for (unsigned int i = 0; i < dEdxInputList_.size(); i++) {
79  dEdxMEsVector.push_back(dEdxMEs());
80 
81  histname = "Strip_dEdxPerCluster_";
83  dEdxMEsVector[i].ME_StripHitDeDx->setAxisTitle("dEdx of on-track strip cluster (ADC)");
84  dEdxMEsVector[i].ME_StripHitDeDx->setAxisTitle("Number of Strip clusters", 2);
85 
86  histname = "Pixel_dEdxPerCluster_";
88  dEdxMEsVector[i].ME_PixelHitDeDx->setAxisTitle("dEdx of on-track pixel cluster (ADC)");
89  dEdxMEsVector[i].ME_PixelHitDeDx->setAxisTitle("Number of Pixel clusters", 2);
90 
91  histname = "NumberOfdEdxHitsPerTrack_";
93  dEdxMEsVector[i].ME_NHitDeDx->setAxisTitle("Number of dEdxHits per Track");
94  dEdxMEsVector[i].ME_NHitDeDx->setAxisTitle("Number of Tracks", 2);
95 
96  histname = "Harm2_dEdxPerTrack_";
98  dEdxMEsVector[i].ME_Harm2DeDx->setAxisTitle("Harmonic2 dEdx estimator for each Track");
99  dEdxMEsVector[i].ME_Harm2DeDx->setAxisTitle("Number of Tracks", 2);
100  }
101  }
102 }
103 
105  if (!dedxHits)
106  return -1;
107  std::vector<double> vect;
108  for (unsigned int h = 0; h < dedxHits->size(); h++) {
109  DetId detid(dedxHits->detId(h));
110  double Norm = (detid.subdetId() < 3) ? 3.61e-06 : 3.61e-06 * 265;
111  double ChargeOverPathlength = Norm * dedxHits->charge(h) / dedxHits->pathlength(h);
112  vect.push_back(ChargeOverPathlength); //save charge
113  }
114 
115  int size = vect.size();
116  if (size <= 0)
117  return -1;
118  double result = 0;
119  double expo = -2;
120  for (int i = 0; i < size; i++) {
121  result += pow(vect[i], expo);
122  }
123  return pow(result / size, 1. / expo);
124 }
125 
126 // -- Analyse
127 // ---------------------------------------------------------------------------------//
129  // Filter out events if Trigger Filtering is requested
131  return;
132 
133  if (doDeDxPlots_ || doAllPlots_) {
134  edm::Handle<reco::TrackCollection> trackCollectionHandle = iEvent.getHandle(trackToken_);
135  if (!trackCollectionHandle.isValid())
136  return;
137 
138  for (unsigned int i = 0; i < dEdxInputList_.size(); i++) {
139  edm::Handle<reco::DeDxHitInfoAss> dEdxObjectHandle = iEvent.getHandle(dEdxTokenList_[i]);
140  if (!dEdxObjectHandle.isValid())
141  continue;
142 
143  for (unsigned int t = 0; t < trackCollectionHandle->size(); t++) {
144  reco::TrackRef track = reco::TrackRef(trackCollectionHandle, t);
145 
146  if (track->quality(reco::TrackBase::highPurity)) {
147  const reco::DeDxHitInfo* dedxHits = nullptr;
148  if (!track.isNull()) {
149  reco::DeDxHitInfoRef dedxHitsRef = (*dEdxObjectHandle)[track];
150  if (!dedxHitsRef.isNull())
151  dedxHits = &(*dedxHitsRef);
152  }
153  if (!dedxHits)
154  continue;
155 
156  for (unsigned int h = 0; h < dedxHits->size(); h++) {
157  DetId detid(dedxHits->detId(h));
158  if (detid.subdetId() >= 3)
159  dEdxMEsVector[i].ME_StripHitDeDx->Fill(dedxHits->charge(h));
160  if (detid.subdetId() < 3)
161  dEdxMEsVector[i].ME_PixelHitDeDx->Fill(dedxHits->charge(h));
162  }
163  dEdxMEsVector[i].ME_NHitDeDx->Fill(dedxHits->size());
164  dEdxMEsVector[i].ME_Harm2DeDx->Fill(harmonic2(dedxHits));
165  }
166  }
167  }
168  }
169 }
170 
171 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
173  //The following says we do not know what parameters are allowed so do no validation
174  // Please change this to state exactly what you do use, even if it is no parameters
176  desc.setUnknown();
177  descriptions.addDefault(desc);
178 }
179 
size
Write out results.
float pathlength(size_t i) const
Definition: DeDxHitInfo.h:43
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::TrackCollection > trackToken_
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
std::vector< std::string > dEdxInputList_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
~dEdxHitAnalyzer() override
std::string histname
std::vector< dEdxMEs > dEdxMEsVector
int iEvent
Definition: GenABIO.cc:224
dEdxHitAnalyzer(const edm::ParameterSet &)
void addDefault(ParameterSetDescription const &psetDescription)
edm::InputTag trackInputTag_
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
GenericTriggerEventFlag * genTriggerEventFlag_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DetId detId(size_t i) const
Definition: DeDxHitInfo.h:44
bool isNull() const
Checks for null.
Definition: Ref.h:235
std::vector< edm::EDGetTokenT< reco::DeDxHitInfoAss > > dEdxTokenList_
double harmonic2(const reco::DeDxHitInfo *dedxHits)
Definition: DetId.h:17
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
size_t size() const
Definition: DeDxHitInfo.h:41
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
float charge(size_t i) const
Definition: DeDxHitInfo.h:42
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
edm::ParameterSet conf_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
std::string MEFolderName
Definition: Run.h:45