CMS 3D CMS Logo

dEdxAnalyzer.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  : dqmStore_(edm::Service<DQMStore>().operator->()),
24  fullconf_(iConfig),
25  conf_(fullconf_.getParameter<edm::ParameterSet>("dEdxParameters")),
26  doAllPlots_(conf_.getParameter<bool>("doAllPlots")),
27  doDeDxPlots_(conf_.getParameter<bool>("doDeDxPlots")),
28  genTriggerEventFlag_(new GenericTriggerEventFlag(
29  conf_.getParameter<edm::ParameterSet>("genericTriggerEventPSet"), consumesCollector(), *this)) {
31  trackToken_ = consumes<reco::TrackCollection>(trackInputTag_);
32 
33  dEdxInputList_ = conf_.getParameter<std::vector<std::string> >("deDxProducers");
34  for (auto const& tag : dEdxInputList_) {
35  dEdxTokenList_.push_back(consumes<reco::DeDxDataValueMap>(edm::InputTag(tag)));
36  }
37 }
38 
41  delete genTriggerEventFlag_;
42 }
43 
44 // ------------ method called once each job just after ending the event loop ------------
46  bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
48  if (outputMEsInRootFile) {
50  dqmStore_->save(outputFileName);
51  }
52 }
53 
54 /*
55 // -- BeginRun
56 //---------------------------------------------------------------------------------//
57 void dEdxAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
58 {
59 
60  // Initialize the GenericTriggerEventFlag
61  if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
62 }
63 */
64 
65 void dEdxAnalyzer::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
66  // Initialize the GenericTriggerEventFlag
67  if (genTriggerEventFlag_->on())
68  genTriggerEventFlag_->initRun(iRun, iSetup);
69 
70  // parameters from the configuration
71  std::string MEFolderName = conf_.getParameter<std::string>("FolderName");
72 
73  // get binning from the configuration
74  TrackHitMin = conf_.getParameter<double>("TrackHitMin");
75  HIPdEdxMin = conf_.getParameter<double>("HIPdEdxMin");
76  HighPtThreshold = conf_.getParameter<double>("HighPtThreshold");
77 
78  dEdxK = conf_.getParameter<double>("dEdxK");
79  dEdxC = conf_.getParameter<double>("dEdxC");
80 
81  int dEdxNHitBin = conf_.getParameter<int>("dEdxNHitBin");
82  double dEdxNHitMin = conf_.getParameter<double>("dEdxNHitMin");
83  double dEdxNHitMax = conf_.getParameter<double>("dEdxNHitMax");
84 
85  int dEdxBin = conf_.getParameter<int>("dEdxBin");
86  double dEdxMin = conf_.getParameter<double>("dEdxMin");
87  double dEdxMax = conf_.getParameter<double>("dEdxMax");
88 
89  int dEdxHIPmassBin = conf_.getParameter<int>("dEdxHIPmassBin");
90  double dEdxHIPmassMin = conf_.getParameter<double>("dEdxHIPmassMin");
91  double dEdxHIPmassMax = conf_.getParameter<double>("dEdxHIPmassMax");
92 
93  int dEdxMIPmassBin = conf_.getParameter<int>("dEdxMIPmassBin");
94  double dEdxMIPmassMin = conf_.getParameter<double>("dEdxMIPmassMin");
95  double dEdxMIPmassMax = conf_.getParameter<double>("dEdxMIPmassMax");
96 
97  ibooker.setCurrentFolder(MEFolderName);
98 
99  // book the Hit Property histograms
100  // ---------------------------------------------------------------------------------//
101 
102  if (doDeDxPlots_ || doAllPlots_) {
103  for (unsigned int i = 0; i < dEdxInputList_.size(); i++) {
104  ibooker.setCurrentFolder(MEFolderName + "/" + dEdxInputList_[i]);
105  dEdxMEsVector.push_back(dEdxMEs());
106 
107  histname = "MIP_dEdxPerTrack_";
108  dEdxMEsVector[i].ME_MipDeDx = ibooker.book1D(histname, histname, dEdxBin, dEdxMin, dEdxMax);
109  dEdxMEsVector[i].ME_MipDeDx->setAxisTitle("dEdx of each MIP Track (MeV/cm)");
110  dEdxMEsVector[i].ME_MipDeDx->setAxisTitle("Number of Tracks", 2);
111 
112  histname = "MIP_NumberOfdEdxHitsPerTrack_";
113  dEdxMEsVector[i].ME_MipDeDxNHits = ibooker.book1D(histname, histname, dEdxNHitBin, dEdxNHitMin, dEdxNHitMax);
114  dEdxMEsVector[i].ME_MipDeDxNHits->setAxisTitle("Number of dEdxHits of each MIP Track");
115  dEdxMEsVector[i].ME_MipDeDxNHits->setAxisTitle("Number of Tracks", 2);
116 
117  histname = "MIP_FractionOfSaturateddEdxHitsPerTrack_";
118  dEdxMEsVector[i].ME_MipDeDxNSatHits = ibooker.book1D(histname, histname, 2 * dEdxNHitBin, 0, 1);
119  dEdxMEsVector[i].ME_MipDeDxNSatHits->setAxisTitle("Fraction of Saturated dEdxHits of each MIP Track");
120  dEdxMEsVector[i].ME_MipDeDxNSatHits->setAxisTitle("Number of Tracks", 2);
121 
122  histname = "MIP_MassPerTrack_";
123  dEdxMEsVector[i].ME_MipDeDxMass =
124  ibooker.book1D(histname, histname, dEdxMIPmassBin, dEdxMIPmassMin, dEdxMIPmassMax);
125  dEdxMEsVector[i].ME_MipDeDxMass->setAxisTitle("dEdx Mass of each MIP Track (GeV/c^{2})");
126  dEdxMEsVector[i].ME_MipDeDxMass->setAxisTitle("Number of Tracks", 2);
127 
128  histname = "HIP_MassPerTrack_";
129  dEdxMEsVector[i].ME_HipDeDxMass =
130  ibooker.book1D(histname, histname, dEdxHIPmassBin, dEdxHIPmassMin, dEdxHIPmassMax);
131  dEdxMEsVector[i].ME_HipDeDxMass->setAxisTitle("dEdx Mass of each HIP Track (GeV/c^{2})");
132  dEdxMEsVector[i].ME_HipDeDxMass->setAxisTitle("Number of Tracks", 2);
133 
134  histname = "MIPOfHighPt_dEdxPerTrack_";
135  dEdxMEsVector[i].ME_MipHighPtDeDx = ibooker.book1D(histname, histname, dEdxBin, dEdxMin, dEdxMax);
136  dEdxMEsVector[i].ME_MipHighPtDeDx->setAxisTitle("dEdx of each MIP (of High pT) Track (MeV/cm)");
137  dEdxMEsVector[i].ME_MipHighPtDeDx->setAxisTitle("Number of Tracks", 2);
138 
139  histname = "MIPOfHighPt_NumberOfdEdxHitsPerTrack_";
140  dEdxMEsVector[i].ME_MipHighPtDeDxNHits =
141  ibooker.book1D(histname, histname, dEdxNHitBin, dEdxNHitMin, dEdxNHitMax);
142  dEdxMEsVector[i].ME_MipHighPtDeDxNHits->setAxisTitle("Number of dEdxHits of each MIP (of High pT) Track");
143  dEdxMEsVector[i].ME_MipHighPtDeDxNHits->setAxisTitle("Number of Tracks", 2);
144  }
145  }
146 }
147 
148 double dEdxAnalyzer::mass(double P, double I) {
149  if (I - dEdxC < 0)
150  return -1;
151  return sqrt((I - dEdxC) / dEdxK) * P;
152 }
153 
154 // -- Analyse
155 // ---------------------------------------------------------------------------------//
157  // Filter out events if Trigger Filtering is requested
158  if (genTriggerEventFlag_->on() && !genTriggerEventFlag_->accept(iEvent, iSetup))
159  return;
160 
161  if (doDeDxPlots_ || doAllPlots_) {
162  edm::Handle<reco::TrackCollection> trackCollectionHandle;
163  iEvent.getByToken(trackToken_, trackCollectionHandle);
164  if (!trackCollectionHandle.isValid())
165  return;
166 
167  for (unsigned int i = 0; i < dEdxInputList_.size(); i++) {
168  edm::Handle<reco::DeDxDataValueMap> dEdxObjectHandle;
169  iEvent.getByToken(dEdxTokenList_[i], dEdxObjectHandle);
170  if (!dEdxObjectHandle.isValid())
171  continue;
172  const edm::ValueMap<reco::DeDxData> dEdxColl = *dEdxObjectHandle.product();
173 
174  for (unsigned int t = 0; t < trackCollectionHandle->size(); t++) {
175  reco::TrackRef track = reco::TrackRef(trackCollectionHandle, t);
176 
177  if (track->quality(reco::TrackBase::highPurity)) {
178  //MIPs
179  if (track->pt() >= 5.0 && track->numberOfValidHits() > TrackHitMin) {
180  dEdxMEsVector[i].ME_MipDeDx->Fill(dEdxColl[track].dEdx());
181  dEdxMEsVector[i].ME_MipDeDxNHits->Fill(dEdxColl[track].numberOfMeasurements());
182  if (dEdxColl[track].numberOfMeasurements() != 0)
183  dEdxMEsVector[i].ME_MipDeDxNSatHits->Fill((1.0 * dEdxColl[track].numberOfSaturatedMeasurements()) /
184  dEdxColl[track].numberOfMeasurements());
185  dEdxMEsVector[i].ME_MipDeDxMass->Fill(mass(track->p(), dEdxColl[track].dEdx()));
186 
187  if (track->pt() >= HighPtThreshold) {
188  dEdxMEsVector[i].ME_MipHighPtDeDx->Fill(dEdxColl[track].dEdx());
189  dEdxMEsVector[i].ME_MipHighPtDeDxNHits->Fill(dEdxColl[track].numberOfMeasurements());
190  }
191 
192  //HighlyIonizing particles
193  } else if (track->pt() < 2 && dEdxColl[track].dEdx() > HIPdEdxMin) {
194  dEdxMEsVector[i].ME_HipDeDxMass->Fill(mass(track->p(), dEdxColl[track].dEdx()));
195  }
196  }
197  }
198  }
199  }
200 }
201 
202 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
204  //The following says we do not know what parameters are allowed so do no validation
205  // Please change this to state exactly what you do use, even if it is no parameters
207  desc.setUnknown();
208  descriptions.addDefault(desc);
209 }
210 
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
double HighPtThreshold
Definition: dEdxAnalyzer.h:75
~dEdxAnalyzer() override
Definition: dEdxAnalyzer.cc:39
edm::EDGetTokenT< reco::TrackCollection > trackToken_
Definition: dEdxAnalyzer.h:79
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
double dEdxC
Definition: dEdxAnalyzer.h:76
double TrackHitMin
Definition: dEdxAnalyzer.h:75
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
edm::ParameterSet conf_
Definition: dEdxAnalyzer.h:51
double dEdxK
Definition: dEdxAnalyzer.h:76
dEdxAnalyzer(const edm::ParameterSet &)
Definition: dEdxAnalyzer.cc:22
void endJob() override
Definition: dEdxAnalyzer.cc:45
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< std::string > dEdxInputList_
Definition: dEdxAnalyzer.h:81
T sqrt(T t)
Definition: SSEVec.h:19
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
GenericTriggerEventFlag * genTriggerEventFlag_
Definition: dEdxAnalyzer.h:89
const std::complex< double > I
Definition: I.h:8
bool doAllPlots_
Definition: dEdxAnalyzer.h:53
bool isValid() const
Definition: HandleBase.h:70
bool doDeDxPlots_
Definition: dEdxAnalyzer.h:54
edm::InputTag trackInputTag_
Definition: dEdxAnalyzer.h:78
double mass(double P, double I)
T const * product() const
Definition: Handle.h:69
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: dEdxAnalyzer.cc:65
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
DQMStore * dqmStore_
Definition: dEdxAnalyzer.h:49
std::pair< OmniClusterRef, TrackingParticleRef > P
double HIPdEdxMin
Definition: dEdxAnalyzer.h:75
std::string histname
Definition: dEdxAnalyzer.h:87
std::vector< edm::EDGetTokenT< reco::DeDxDataValueMap > > dEdxTokenList_
Definition: dEdxAnalyzer.h:82
HLT enums.
void showDirStructure() const
Definition: DQMStore.cc:2926
std::vector< dEdxMEs > dEdxMEsVector
Definition: dEdxAnalyzer.h:86
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2244
Definition: Run.h:45