CMS 3D CMS Logo

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