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()) )
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 // -- BeginRun
60 //---------------------------------------------------------------------------------//
61 void dEdxAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
62 {
63 
64  // Initialize the GenericTriggerEventFlag
65  if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
66 }
67 
68 
70 {
71  // parameters from the configuration
72  std::string MEFolderName = conf_.getParameter<std::string>("FolderName");
73 
74  // get binning from the configuration
75  TrackHitMin = conf_.getParameter<double>("TrackHitMin");
76  HIPdEdxMin = conf_.getParameter<double>("HIPdEdxMin");
77 
78  dEdxK = conf_.getParameter<double>("dEdxK");
79  dEdxC = conf_.getParameter<double>("dEdxC");
80 
81 
82  int dEdxNHitBin = conf_.getParameter<int>( "dEdxNHitBin");
83  double dEdxNHitMin = conf_.getParameter<double>("dEdxNHitMin");
84  double dEdxNHitMax = conf_.getParameter<double>("dEdxNHitMax");
85 
86  int dEdxBin = conf_.getParameter<int>( "dEdxBin");
87  double dEdxMin = conf_.getParameter<double>("dEdxMin");
88  double dEdxMax = conf_.getParameter<double>("dEdxMax");
89 
90  int dEdxHIPmassBin = conf_.getParameter<int>( "dEdxHIPmassBin");
91  double dEdxHIPmassMin = conf_.getParameter<double>("dEdxHIPmassMin");
92  double dEdxHIPmassMax = conf_.getParameter<double>("dEdxHIPmassMax");
93 
94  int dEdxMIPmassBin = conf_.getParameter<int>( "dEdxMIPmassBin");
95  double dEdxMIPmassMin = conf_.getParameter<double>("dEdxMIPmassMin");
96  double dEdxMIPmassMax = conf_.getParameter<double>("dEdxMIPmassMax");
97 
98  dqmStore_->setCurrentFolder(MEFolderName);
99 
100  // book the Hit Property histograms
101  // ---------------------------------------------------------------------------------//
102 
103  if ( doDeDxPlots_ || doAllPlots_ ){
104  for(unsigned int i=0;i<dEdxInputList_.size();i++){
105  dqmStore_->setCurrentFolder(MEFolderName+"/"+ dEdxInputList_[i]);
106  dEdxMEsVector.push_back(dEdxMEs() );
107 
108  histname = "MIP_dEdxPerTrack_";
109  dEdxMEsVector[i].ME_MipDeDx = dqmStore_->book1D(histname, histname, dEdxBin, dEdxMin, dEdxMax);
110  dEdxMEsVector[i].ME_MipDeDx->setAxisTitle("dEdx of each MIP Track (MeV/cm)");
111  dEdxMEsVector[i].ME_MipDeDx->setAxisTitle("Number of Tracks", 2);
112 
113  histname = "MIP_NumberOfdEdxHitsPerTrack_";
114  dEdxMEsVector[i].ME_MipDeDxNHits = dqmStore_->book1D(histname, histname, dEdxNHitBin, dEdxNHitMin, dEdxNHitMax);
115  dEdxMEsVector[i].ME_MipDeDxNHits->setAxisTitle("Number of dEdxHits of each MIP Track");
116  dEdxMEsVector[i].ME_MipDeDxNHits->setAxisTitle("Number of Tracks", 2);
117 
118  histname = "MIP_FractionOfSaturateddEdxHitsPerTrack_";
119  dEdxMEsVector[i].ME_MipDeDxNSatHits = dqmStore_->book1D(histname, histname,2*dEdxNHitBin, 0, 1);
120  dEdxMEsVector[i].ME_MipDeDxNSatHits->setAxisTitle("Fraction of Saturated dEdxHits of each MIP Track");
121  dEdxMEsVector[i].ME_MipDeDxNSatHits->setAxisTitle("Number of Tracks", 2);
122 
123  histname = "MIP_MassPerTrack_";
124  dEdxMEsVector[i].ME_MipDeDxMass = dqmStore_->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 = dqmStore_->book1D(histname, histname, dEdxHIPmassBin, dEdxHIPmassMin, dEdxHIPmassMax);
130  dEdxMEsVector[i].ME_HipDeDxMass->setAxisTitle("dEdx Mass of each HIP Track (GeV/c^{2})");
131  dEdxMEsVector[i].ME_HipDeDxMass->setAxisTitle("Number of Tracks", 2);
132 
133  }
134  }
135 }
136 
137 
138 double dEdxAnalyzer::mass(double P, double I){
139  if(I-dEdxC<0)return -1;
140  return sqrt((I-dEdxC)/dEdxK)*P;
141 }
142 
143 // -- Analyse
144 // ---------------------------------------------------------------------------------//
146 {
147 
148  // Filter out events if Trigger Filtering is requested
149  if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
150 
151 
152  if ( doDeDxPlots_ || doAllPlots_ ){
153  edm::Handle<reco::TrackCollection> trackCollectionHandle;
154  // iEvent.getByLabel(TrackName,trackCollectionHandle);
155  iEvent.getByToken(trackToken_, trackCollectionHandle );
156  if(!trackCollectionHandle.isValid())return;
157 
158  for(unsigned int i=0;i<dEdxInputList_.size();i++){
159  edm::Handle<reco::DeDxDataValueMap> dEdxObjectHandle;
160  // iEvent.getByLabel(AlgoNames[i],dEdxObjectHandle);
161  iEvent.getByToken(dEdxTokenList_[i], dEdxObjectHandle );
162  if(!dEdxObjectHandle.isValid())continue;
163  const edm::ValueMap<reco::DeDxData> dEdxColl = *dEdxObjectHandle.product();
164 
165 
166  for(unsigned int t=0; t<trackCollectionHandle->size(); t++){
167  reco::TrackRef track = reco::TrackRef( trackCollectionHandle, t );
168 
169 
170  if(track->quality(reco::TrackBase::highPurity) ) {
171  //MIPs
172  if( track->pt() >= 5.0 && track->numberOfValidHits()>TrackHitMin){
173  dEdxMEsVector[i].ME_MipDeDx ->Fill(dEdxColl[track].dEdx());
174  dEdxMEsVector[i].ME_MipDeDxNHits ->Fill(dEdxColl[track].numberOfMeasurements());
175  if (dEdxColl[track].numberOfMeasurements()!=0)
176  dEdxMEsVector[i].ME_MipDeDxNSatHits->Fill((1.0*dEdxColl[track].numberOfSaturatedMeasurements())/dEdxColl[track].numberOfMeasurements());
177  dEdxMEsVector[i].ME_MipDeDxMass ->Fill(mass(track->p(), dEdxColl[track].dEdx()));
178 
179  //HighlyIonizing particles
180  }else if(track->pt()<2 && dEdxColl[track].dEdx()>HIPdEdxMin){
181  dEdxMEsVector[i].ME_HipDeDxMass ->Fill(mass(track->p(), dEdxColl[track].dEdx()));
182  }
183  }
184  }
185  }
186  }
187 }
188 
189 
190 
191 void
193 {
194 }
195 
196 // ------------ method called when ending the processing of a luminosity block ------------
197 void
199 {
200 }
201 
202 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
203 void
205  //The following says we do not know what parameters are allowed so do no validation
206  // Please change this to state exactly what you do use, even if it is no parameters
208  desc.setUnknown();
209  descriptions.addDefault(desc);
210 }
211 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: dEdxAnalyzer.cc:61
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
edm::EDGetTokenT< reco::TrackCollection > trackToken_
Definition: dEdxAnalyzer.h:80
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double dEdxC
Definition: dEdxAnalyzer.h:77
double TrackHitMin
Definition: dEdxAnalyzer.h:76
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:54
virtual void beginJob()
Definition: dEdxAnalyzer.cc:69
double dEdxK
Definition: dEdxAnalyzer.h:77
dEdxAnalyzer(const edm::ParameterSet &)
Definition: dEdxAnalyzer.cc:22
int iEvent
Definition: GenABIO.cc:243
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< std::string > dEdxInputList_
Definition: dEdxAnalyzer.h:82
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.
GenericTriggerEventFlag * genTriggerEventFlag_
Definition: dEdxAnalyzer.h:90
const std::complex< double > I
Definition: I.h:8
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2296
bool doAllPlots_
Definition: dEdxAnalyzer.h:56
bool isValid() const
Definition: HandleBase.h:76
bool doDeDxPlots_
Definition: dEdxAnalyzer.h:57
edm::InputTag trackInputTag_
Definition: dEdxAnalyzer.h:79
std::vector< dEdxMEs > dEdxMEsVector
Definition: dEdxAnalyzer.h:87
double mass(double P, double I)
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
virtual void endJob()
Definition: dEdxAnalyzer.cc:48
DQMStore * dqmStore_
Definition: dEdxAnalyzer.h:52
T const * product() const
Definition: Handle.h:81
double HIPdEdxMin
Definition: dEdxAnalyzer.h:76
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
std::string histname
Definition: dEdxAnalyzer.h:88
std::vector< edm::EDGetTokenT< reco::DeDxDataValueMap > > dEdxTokenList_
Definition: dEdxAnalyzer.h:83
void showDirStructure(void) const
Definition: DQMStore.cc:2961
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: Run.h:41