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(conf_.getParameter<edm::ParameterSet>("genericTriggerEventPSet"),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 
156 
157 double dEdxAnalyzer::mass(double P, double I){
158  if(I-dEdxC<0)return -1;
159  return sqrt((I-dEdxC)/dEdxK)*P;
160 }
161 
162 // -- Analyse
163 // ---------------------------------------------------------------------------------//
165 {
166 
167  // Filter out events if Trigger Filtering is requested
168  if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
169 
170 
171  if ( doDeDxPlots_ || doAllPlots_ ){
172  edm::Handle<reco::TrackCollection> trackCollectionHandle;
173  iEvent.getByToken(trackToken_, trackCollectionHandle );
174  if(!trackCollectionHandle.isValid())return;
175 
176  for(unsigned int i=0;i<dEdxInputList_.size();i++){
177  edm::Handle<reco::DeDxDataValueMap> dEdxObjectHandle;
178  iEvent.getByToken(dEdxTokenList_[i], dEdxObjectHandle );
179  if(!dEdxObjectHandle.isValid())continue;
180  const edm::ValueMap<reco::DeDxData> dEdxColl = *dEdxObjectHandle.product();
181 
182 
183  for(unsigned int t=0; t<trackCollectionHandle->size(); t++){
184  reco::TrackRef track = reco::TrackRef( trackCollectionHandle, t );
185 
186 
187  if(track->quality(reco::TrackBase::highPurity) ) {
188  //MIPs
189  if( track->pt() >= 5.0 && track->numberOfValidHits()>TrackHitMin){
190  dEdxMEsVector[i].ME_MipDeDx ->Fill(dEdxColl[track].dEdx());
191  dEdxMEsVector[i].ME_MipDeDxNHits ->Fill(dEdxColl[track].numberOfMeasurements());
192  if (dEdxColl[track].numberOfMeasurements()!=0)
193  dEdxMEsVector[i].ME_MipDeDxNSatHits->Fill((1.0*dEdxColl[track].numberOfSaturatedMeasurements())/dEdxColl[track].numberOfMeasurements());
194  dEdxMEsVector[i].ME_MipDeDxMass ->Fill(mass(track->p(), dEdxColl[track].dEdx()));
195 
196 
197  if(track->pt() >= HighPtThreshold){
198  dEdxMEsVector[i].ME_MipHighPtDeDx ->Fill(dEdxColl[track].dEdx());
199  dEdxMEsVector[i].ME_MipHighPtDeDxNHits ->Fill(dEdxColl[track].numberOfMeasurements());
200  }
201 
202  //HighlyIonizing particles
203  }else if(track->pt()<2 && dEdxColl[track].dEdx()>HIPdEdxMin){
204  dEdxMEsVector[i].ME_HipDeDxMass ->Fill(mass(track->p(), dEdxColl[track].dEdx()));
205  }
206  }
207  }
208  }
209  }
210 }
211 
212 
213 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
214 void
216  //The following says we do not know what parameters are allowed so do no validation
217  // Please change this to state exactly what you do use, even if it is no parameters
219  desc.setUnknown();
220  descriptions.addDefault(desc);
221 }
222 
T getParameter(std::string const &) const
double HighPtThreshold
Definition: dEdxAnalyzer.h:78
~dEdxAnalyzer() override
Definition: dEdxAnalyzer.cc:40
edm::EDGetTokenT< reco::TrackCollection > trackToken_
Definition: dEdxAnalyzer.h:82
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double dEdxC
Definition: dEdxAnalyzer.h:79
double TrackHitMin
Definition: dEdxAnalyzer.h:78
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
edm::ParameterSet conf_
Definition: dEdxAnalyzer.h:52
double dEdxK
Definition: dEdxAnalyzer.h:79
dEdxAnalyzer(const edm::ParameterSet &)
Definition: dEdxAnalyzer.cc:22
void endJob() override
Definition: dEdxAnalyzer.cc:48
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
std::vector< std::string > dEdxInputList_
Definition: dEdxAnalyzer.h:84
T sqrt(T t)
Definition: SSEVec.h:18
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
GenericTriggerEventFlag * genTriggerEventFlag_
Definition: dEdxAnalyzer.h:92
const std::complex< double > I
Definition: I.h:8
bool doAllPlots_
Definition: dEdxAnalyzer.h:54
bool isValid() const
Definition: HandleBase.h:74
bool doDeDxPlots_
Definition: dEdxAnalyzer.h:55
edm::InputTag trackInputTag_
Definition: dEdxAnalyzer.h:81
std::vector< dEdxMEs > dEdxMEsVector
Definition: dEdxAnalyzer.h:89
double mass(double P, double I)
void showDirStructure() const
Definition: DQMStore.cc:3307
T const * product() const
Definition: Handle.h:74
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:21
DQMStore * dqmStore_
Definition: dEdxAnalyzer.h:50
std::pair< OmniClusterRef, TrackingParticleRef > P
double HIPdEdxMin
Definition: dEdxAnalyzer.h:78
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:2465
std::string histname
Definition: dEdxAnalyzer.h:90
std::vector< edm::EDGetTokenT< reco::DeDxDataValueMap > > dEdxTokenList_
Definition: dEdxAnalyzer.h:85
HLT enums.
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
Definition: Run.h:45