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 /*
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 
86  dEdxK = conf_.getParameter<double>("dEdxK");
87  dEdxC = conf_.getParameter<double>("dEdxC");
88 
89 
90  int dEdxNHitBin = conf_.getParameter<int>( "dEdxNHitBin");
91  double dEdxNHitMin = conf_.getParameter<double>("dEdxNHitMin");
92  double dEdxNHitMax = conf_.getParameter<double>("dEdxNHitMax");
93 
94  int dEdxBin = conf_.getParameter<int>( "dEdxBin");
95  double dEdxMin = conf_.getParameter<double>("dEdxMin");
96  double dEdxMax = conf_.getParameter<double>("dEdxMax");
97 
98  int dEdxHIPmassBin = conf_.getParameter<int>( "dEdxHIPmassBin");
99  double dEdxHIPmassMin = conf_.getParameter<double>("dEdxHIPmassMin");
100  double dEdxHIPmassMax = conf_.getParameter<double>("dEdxHIPmassMax");
101 
102  int dEdxMIPmassBin = conf_.getParameter<int>( "dEdxMIPmassBin");
103  double dEdxMIPmassMin = conf_.getParameter<double>("dEdxMIPmassMin");
104  double dEdxMIPmassMax = conf_.getParameter<double>("dEdxMIPmassMax");
105 
106  ibooker.setCurrentFolder(MEFolderName);
107 
108  // book the Hit Property histograms
109  // ---------------------------------------------------------------------------------//
110 
111  if ( doDeDxPlots_ || doAllPlots_ ){
112  for(unsigned int i=0;i<dEdxInputList_.size();i++){
113  ibooker.setCurrentFolder(MEFolderName+"/"+ dEdxInputList_[i]);
114  dEdxMEsVector.push_back(dEdxMEs() );
115 
116  histname = "MIP_dEdxPerTrack_";
117  dEdxMEsVector[i].ME_MipDeDx = ibooker.book1D(histname, histname, dEdxBin, dEdxMin, dEdxMax);
118  dEdxMEsVector[i].ME_MipDeDx->setAxisTitle("dEdx of each MIP Track (MeV/cm)");
119  dEdxMEsVector[i].ME_MipDeDx->setAxisTitle("Number of Tracks", 2);
120 
121  histname = "MIP_NumberOfdEdxHitsPerTrack_";
122  dEdxMEsVector[i].ME_MipDeDxNHits = ibooker.book1D(histname, histname, dEdxNHitBin, dEdxNHitMin, dEdxNHitMax);
123  dEdxMEsVector[i].ME_MipDeDxNHits->setAxisTitle("Number of dEdxHits of each MIP Track");
124  dEdxMEsVector[i].ME_MipDeDxNHits->setAxisTitle("Number of Tracks", 2);
125 
126  histname = "MIP_FractionOfSaturateddEdxHitsPerTrack_";
127  dEdxMEsVector[i].ME_MipDeDxNSatHits = ibooker.book1D(histname, histname,2*dEdxNHitBin, 0, 1);
128  dEdxMEsVector[i].ME_MipDeDxNSatHits->setAxisTitle("Fraction of Saturated dEdxHits of each MIP Track");
129  dEdxMEsVector[i].ME_MipDeDxNSatHits->setAxisTitle("Number of Tracks", 2);
130 
131  histname = "MIP_MassPerTrack_";
132  dEdxMEsVector[i].ME_MipDeDxMass = ibooker.book1D(histname, histname, dEdxMIPmassBin, dEdxMIPmassMin, dEdxMIPmassMax);
133  dEdxMEsVector[i].ME_MipDeDxMass->setAxisTitle("dEdx Mass of each MIP Track (GeV/c^{2})");
134  dEdxMEsVector[i].ME_MipDeDxMass->setAxisTitle("Number of Tracks", 2);
135 
136  histname = "HIP_MassPerTrack_";
137  dEdxMEsVector[i].ME_HipDeDxMass = ibooker.book1D(histname, histname, dEdxHIPmassBin, dEdxHIPmassMin, dEdxHIPmassMax);
138  dEdxMEsVector[i].ME_HipDeDxMass->setAxisTitle("dEdx Mass of each HIP Track (GeV/c^{2})");
139  dEdxMEsVector[i].ME_HipDeDxMass->setAxisTitle("Number of Tracks", 2);
140 
141  }
142  }
143 
144 }
145 
147 {
148 }
149 
150 
151 double dEdxAnalyzer::mass(double P, double I){
152  if(I-dEdxC<0)return -1;
153  return sqrt((I-dEdxC)/dEdxK)*P;
154 }
155 
156 // -- Analyse
157 // ---------------------------------------------------------------------------------//
159 {
160 
161  // Filter out events if Trigger Filtering is requested
162  if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
163 
164 
165  if ( doDeDxPlots_ || doAllPlots_ ){
166  edm::Handle<reco::TrackCollection> trackCollectionHandle;
167  iEvent.getByToken(trackToken_, trackCollectionHandle );
168  if(!trackCollectionHandle.isValid())return;
169 
170  for(unsigned int i=0;i<dEdxInputList_.size();i++){
171  edm::Handle<reco::DeDxDataValueMap> dEdxObjectHandle;
172  iEvent.getByToken(dEdxTokenList_[i], dEdxObjectHandle );
173  if(!dEdxObjectHandle.isValid())continue;
174  const edm::ValueMap<reco::DeDxData> dEdxColl = *dEdxObjectHandle.product();
175 
176 
177  for(unsigned int t=0; t<trackCollectionHandle->size(); t++){
178  reco::TrackRef track = reco::TrackRef( trackCollectionHandle, t );
179 
180 
181  if(track->quality(reco::TrackBase::highPurity) ) {
182  //MIPs
183  if( track->pt() >= 5.0 && track->numberOfValidHits()>TrackHitMin){
184  dEdxMEsVector[i].ME_MipDeDx ->Fill(dEdxColl[track].dEdx());
185  dEdxMEsVector[i].ME_MipDeDxNHits ->Fill(dEdxColl[track].numberOfMeasurements());
186  if (dEdxColl[track].numberOfMeasurements()!=0)
187  dEdxMEsVector[i].ME_MipDeDxNSatHits->Fill((1.0*dEdxColl[track].numberOfSaturatedMeasurements())/dEdxColl[track].numberOfMeasurements());
188  dEdxMEsVector[i].ME_MipDeDxMass ->Fill(mass(track->p(), dEdxColl[track].dEdx()));
189 
190  //HighlyIonizing particles
191  }else if(track->pt()<2 && dEdxColl[track].dEdx()>HIPdEdxMin){
192  dEdxMEsVector[i].ME_HipDeDxMass ->Fill(mass(track->p(), dEdxColl[track].dEdx()));
193  }
194  }
195  }
196  }
197  }
198 }
199 
200 
201 
202 void
204 {
205 }
206 
207 // ------------ method called when ending the processing of a luminosity block ------------
208 void
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
int i
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< reco::TrackCollection > trackToken_
Definition: dEdxAnalyzer.h:84
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:81
double TrackHitMin
Definition: dEdxAnalyzer.h:80
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:81
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:86
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:113
GenericTriggerEventFlag * genTriggerEventFlag_
Definition: dEdxAnalyzer.h:94
const std::complex< double > I
Definition: I.h:8
bool doAllPlots_
Definition: dEdxAnalyzer.h:60
bool isValid() const
Definition: HandleBase.h:76
bool doDeDxPlots_
Definition: dEdxAnalyzer.h:61
edm::InputTag trackInputTag_
Definition: dEdxAnalyzer.h:83
std::vector< dEdxMEs > dEdxMEsVector
Definition: dEdxAnalyzer.h:91
double mass(double P, double I)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
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:14
virtual void endJob()
Definition: dEdxAnalyzer.cc:48
DQMStore * dqmStore_
Definition: dEdxAnalyzer.h:56
T const * product() const
Definition: Handle.h:81
double HIPdEdxMin
Definition: dEdxAnalyzer.h:80
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
std::string histname
Definition: dEdxAnalyzer.h:92
std::vector< edm::EDGetTokenT< reco::DeDxDataValueMap > > dEdxTokenList_
Definition: dEdxAnalyzer.h:87
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:2540
void showDirStructure(void) const
Definition: DQMStore.cc:3332
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:41