CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiplicityTimeCorrelations.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MultiplicityTimeCorrelations
4 // Class: MultiplicityTimeCorrelations
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Mon Oct 27 17:37:53 CET 2008
16 // $Id: MultiplicityTimeCorrelations.cc,v 1.1 2011/03/10 16:15:13 venturia Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
25 
26 #include <vector>
27 #include <map>
28 #include <limits.h>
29 
32 
36 
38 
39 #include "TH1F.h"
40 
42 
45 
47 
49 
52 
56 
57 //
58 // class decleration
59 //
60 
62  public:
65 
66 
67 private:
68  virtual void beginJob() override ;
69  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
70  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
71  virtual void endJob() override ;
72 
73  // ----------member data ---------------------------
74 
77 
78  std::map<int,std::map<unsigned int,TH1F*> > _dbxhistos;
79  /*
80  std::map<int,TH1F*> _dbxtkhistos;
81  std::map<int,TH1F*> _dbxtibhistos;
82  std::map<int,TH1F*> _dbxtidhistos;
83  std::map<int,TH1F*> _dbxtobhistos;
84  std::map<int,TH1F*> _dbxtechistos;
85  */
86 
91  std::map<unsigned int, std::string> _subdets;
92  std::map<unsigned int, int> _binmax;
93 
94  int _loworbit;
96 
97  int _mindbx;
99 
101 
102  std::vector<int> _dbxbins;
103 
104 };
105 
106 //
107 // constants, enums and typedefs
108 //
109 
110 //
111 // static data member definitions
112 //
113 
114 //
115 // constructors and destructor
116 //
118  _digibxcorrhmevent(iConfig, consumesCollector()),
119  _evfilter(),
120  _hecollection(iConfig.getParameter<edm::InputTag>("historyProduct")),
121  _hecollectionToken(consumes<EventWithHistory>(_hecollection)),
122  _apvphasecollToken(consumes<APVCyclePhaseCollection>(iConfig.getParameter<edm::InputTag>("apvPhaseCollection"))),
123  _multiplicityMapToken(mayConsume<std::map<unsigned int, int> >(iConfig.getParameter<edm::InputTag>("multiplicityMap"))),
124  _subdets(),
125  _binmax(),
126  _loworbit(iConfig.getUntrackedParameter<int>("lowedgeOrbit")),
127  _highorbit(iConfig.getUntrackedParameter<int>("highedgeOrbit")),
128  _mindbx(iConfig.getUntrackedParameter<int>("minDBX")),
129  _mintrpltdbx(iConfig.getUntrackedParameter<int>("minTripletDBX")),
130  _trnumb(),
131  _dbxbins(iConfig.getUntrackedParameter<std::vector<int> >("dbxBins"))
132 {
133  //now do what ever initialization is needed
134 
135  // configure the filter
136 
137  edm::ParameterSet filterConfig;
138  filterConfig.addUntrackedParameter<edm::InputTag>("historyProduct",_hecollection);
139  if(_mindbx>0) {
140  std::vector<int> dbxrange;
141  dbxrange.push_back(_mindbx+1);
142  dbxrange.push_back(-1);
143  filterConfig.addUntrackedParameter<std::vector<int> >("dbxRange",dbxrange);
144  }
145  if(_mintrpltdbx>0) {
146  std::vector<int> dbxtrpltrange;
147  dbxtrpltrange.push_back(_mintrpltdbx+1);
148  dbxtrpltrange.push_back(-1);
149  filterConfig.addUntrackedParameter<std::vector<int> >("dbxTripletRange",dbxtrpltrange);
150  }
151 
152  _evfilter.set(filterConfig, consumesCollector());
153 
154  //
155 
157 
158  // create map of labels
159 
160  std::vector<edm::ParameterSet> wantedsubds(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >("wantedSubDets"));
161 
162  for(std::vector<edm::ParameterSet>::iterator ps=wantedsubds.begin();ps!=wantedsubds.end();++ps) {
163  _subdets[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
164  _binmax[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int>("binMax");
165  }
166  std::map<int,std::string> labels;
167 
168  for(std::map<unsigned int,std::string>::const_iterator subd=_subdets.begin();subd!=_subdets.end();++subd) {
169  labels[int(subd->first)] = subd->second;
170  }
171 
172  //
173 
174  _digibxcorrhmevent.book("EventProcs",labels);
175 
176  TFileDirectory subdbxbin = tfserv->mkdir("DBXDebugging");
177 
178  for(std::vector<int>::const_iterator bin=_dbxbins.begin();bin!=_dbxbins.end();bin++) {
179  char hname[200]; char htitle[200];
180 
181  edm::LogInfo("DBXHistosBinMaxValue") << "Setting bin max values";
182 
183  for(std::map<unsigned int, std::string>::const_iterator subd=_subdets.begin();subd!=_subdets.end();++subd) {
184  if(_binmax.find(subd->first)==_binmax.end()) {
185  edm::LogVerbatim("DBXHistosNotConfiguredBinMax") << "Bin max for " << subd->second
186  << " not configured: " << _trnumb.nstrips(int(subd->first)) << " used";
187  _binmax[subd->first] = _trnumb.nstrips(int(subd->first));
188  }
189 
190  edm::LogVerbatim("DBXHistosBinMaxValue") << "Bin max for " << subd->second << " is " << _binmax[subd->first];
191 
192 
193 
194  sprintf(hname,"sumn%sdigi_%d",subd->second.c_str(),*bin);
195  sprintf(htitle,"%s digi multiplicity at DBX = %d",subd->second.c_str(),*bin);
196  LogDebug("DBXDebug") << "creating histogram " << hname << " " << htitle;
197  _dbxhistos[*bin][subd->first]= subdbxbin.make<TH1F>(hname,htitle,1000,0.,_binmax[subd->first]/(20*1000)*1000);
198  _dbxhistos[*bin][subd->first]->GetXaxis()->SetTitle("Number of Digis");
199  }
200  /*
201  sprintf(hname,"sumntkdigi_%d",*bin);
202  sprintf(htitle,"TK digi multiplicity at DBX = %d",*bin);
203  LogDebug("DBXDebug") << "creating histogram " << hname << " " << htitle;
204  _dbxtkhistos[*bin]= subdbxbin.make<TH1F>(hname,htitle,1000,0.,_trnumb.nstrips(0)/(20*1000)*1000);
205  _dbxtkhistos[*bin]->GetXaxis()->SetTitle("Number of Digis");
206 
207  sprintf(hname,"sumntibdigi_%d",*bin);
208  sprintf(htitle,"TIB digi multiplicity at DBX = %d",*bin);
209  LogDebug("DBXDebug") << "creating histogram " << hname << " " << htitle;
210  _dbxtibhistos[*bin]= subdbxbin.make<TH1F>(hname,htitle,1000,0.,_trnumb.nstrips(SiStripDetId::TIB)/(20*1000)*1000);
211  _dbxtibhistos[*bin]->GetXaxis()->SetTitle("Number of Digis");
212 
213  sprintf(hname,"sumntiddigi_%d",*bin);
214  sprintf(htitle,"TID digi multiplicity at DBX = %d",*bin);
215  LogDebug("DBXDebug") << "creating histogram " << hname << " " << htitle;
216  _dbxtidhistos[*bin]= subdbxbin.make<TH1F>(hname,htitle,1000,0.,_trnumb.nstrips(SiStripDetId::TID)/(20*1000)*1000);
217  _dbxtidhistos[*bin]->GetXaxis()->SetTitle("Number of Digis");
218 
219  sprintf(hname,"sumntobdigi_%d",*bin);
220  sprintf(htitle,"TOB digi multiplicity at DBX = %d",*bin);
221  LogDebug("DBXDebug") << "creating histogram " << hname << " " << htitle;
222  _dbxtobhistos[*bin]= subdbxbin.make<TH1F>(hname,htitle,1000,0.,_trnumb.nstrips(SiStripDetId::TOB)/(20*1000)*1000);
223  _dbxtobhistos[*bin]->GetXaxis()->SetTitle("Number of Digis");
224 
225  sprintf(hname,"sumntecdigi_%d",*bin);
226  sprintf(htitle,"TEC digi multiplicity at DBX = %d",*bin);
227  LogDebug("DBXDebug") << "creating histogram " << hname << " " << htitle;
228  _dbxtechistos[*bin]= subdbxbin.make<TH1F>(hname,htitle,1000,0.,_trnumb.nstrips(SiStripDetId::TEC)/(20*1000)*1000);
229  _dbxtechistos[*bin]->GetXaxis()->SetTitle("Number of Digis");
230  */
231  }
232 
233 }
234 
235 
237 {
238 
239  // do anything here that needs to be done at desctruction time
240  // (e.g. close files, deallocate resources etc.)
241 
242 }
243 
244 
245 //
246 // member functions
247 //
248 
249 // ------------ method called to for each event ------------
250 void
252 {
253  using namespace edm;
254 
255  // get Phase
256 
258  iEvent.getByToken(_apvphasecollToken,apvphase);
259 
260  // get HE
261 
263  iEvent.getByToken(_hecollectionToken,he);
264 
265  // check if the event is selected
266 
267  if((_loworbit < 0 || iEvent.orbitNumber() >= _loworbit) &&
268  (_highorbit < 0 || iEvent.orbitNumber() <= _highorbit)) {
269 
270  if(_evfilter.selected(iEvent,iSetup)) {
271 
272 
273  //Compute digi multiplicity
274  /*
275  int ntkdigi=0;
276  int ntibdigi=0;
277  int ntiddigi=0;
278  int ntobdigi=0;
279  int ntecdigi=0;
280  */
282  iEvent.getByToken(_multiplicityMapToken,mults);
283 
284  // create map of digi multiplicity
285 
286  std::map<int,int> digimap;
287  for(std::map<unsigned int, int>::const_iterator mult=mults->begin();mult!=mults->end();++mult) {
288  if(_subdets.find(mult->first)!=_subdets.end()) digimap[int(mult->first)] = mult->second;
289  }
290 
291  _digibxcorrhmevent.fill(*he,digimap,apvphase);
292 
293  // fill debug histos
294 
295  if(he->depth()!=0) {
296 
297  long long dbx = he->deltaBX();
298 
299  if(_dbxhistos.find(dbx)!=_dbxhistos.end()) {
300  for(std::map<unsigned int,int>::const_iterator ndigi=mults->begin();ndigi!=mults->end();++ndigi) {
301  _dbxhistos[dbx][ndigi->first]->Fill(ndigi->second);
302  }
303  }
304  if(_dbxhistos.find(-1)!=_dbxhistos.end()) {
305  for(std::map<unsigned int,int>::const_iterator ndigi=mults->begin();ndigi!=mults->end();++ndigi) {
306  _dbxhistos[-1][ndigi->first]->Fill(ndigi->second);
307  }
308  }
309  /*
310  if(_dbxtkhistos.find(dbx)!=_dbxtkhistos.end()) {
311  _dbxtkhistos[dbx]->Fill(ntkdigi);
312  }
313  if(_dbxtkhistos.find(-1)!=_dbxtkhistos.end()) {
314  _dbxtkhistos[-1]->Fill(ntkdigi);
315  }
316 
317  if(_dbxtibhistos.find(dbx)!=_dbxtibhistos.end()) {
318  _dbxtibhistos[dbx]->Fill(ntibdigi);
319  }
320  if(_dbxtibhistos.find(-1)!=_dbxtibhistos.end()) {
321  _dbxtibhistos[-1]->Fill(ntibdigi);
322  }
323 
324  if(_dbxtidhistos.find(dbx)!=_dbxtidhistos.end()) {
325  _dbxtidhistos[dbx]->Fill(ntiddigi);
326  }
327  if(_dbxtidhistos.find(-1)!=_dbxtidhistos.end()) {
328  _dbxtidhistos[-1]->Fill(ntiddigi);
329  }
330  if(_dbxtobhistos.find(dbx)!=_dbxtobhistos.end()) {
331  _dbxtobhistos[dbx]->Fill(ntobdigi);
332  }
333  if(_dbxtobhistos.find(-1)!=_dbxtobhistos.end()) {
334  _dbxtobhistos[-1]->Fill(ntobdigi);
335  }
336  if(_dbxtechistos.find(dbx)!=_dbxtechistos.end()) {
337  _dbxtechistos[dbx]->Fill(ntecdigi);
338  }
339  if(_dbxtechistos.find(-1)!=_dbxtechistos.end()) {
340  _dbxtechistos[-1]->Fill(ntecdigi);
341  }
342  */
343  }
344  }
345  }
346 }
347 
348 
349 // ------------ method called once each job just before starting event loop ------------
350 void
352 {
353 
354  LogDebug("IntegerDebug") << " int max and min " << INT_MIN << " " << INT_MAX;
355  LogDebug("IntegerDebug") << " uint max and min " << UINT_MAX;
356  LogDebug("IntegerDebug") << " long max and min " << LONG_MIN << " " << LONG_MAX;
357  LogDebug("IntegerDebug") << " ulong max and min " << ULONG_MAX;
358  LogDebug("IntegerDebug") << " long long max and min " << LLONG_MIN << " " << LLONG_MAX;
359  LogDebug("IntegerDebug") << " u long long max and min " << ULLONG_MAX;
360 
361 
362  edm::LogInfo("MultiplicityTimeCorrelations") << " Correlation studies performed only in the orbit # range " << _loworbit << " " << _highorbit ;
363 
364 }
365 
366 void
368 
370 
371 }
372 // ------------ method called once each job just after ending the event loop ------------
373 void
375 }
376 //define this as a plug-in
#define LogDebug(id)
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
T getUntrackedParameter(std::string const &, T const &) const
RunNumber_t run() const
Definition: RunBase.h:42
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
MultiplicityTimeCorrelations(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< unsigned int, int > _binmax
DigiBXCorrHistogramMaker< EventWithHistory > _digibxcorrhmevent
std::map< unsigned int, std::string > _subdets
std::map< int, std::map< unsigned int, TH1F * > > _dbxhistos
int nstrips(const SiStripDetId &detid) const
void set(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
void book(const char *dirname, const std::map< int, std::string > &labels)
int iEvent
Definition: GenABIO.cc:230
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
edm::EDGetTokenT< EventWithHistory > _hecollectionToken
T * make(const Args &...args) const
make new ROOT object
int orbitNumber() const
Definition: EventBase.h:67
const bool selected(const EventWithHistory &he, const edm::EventSetup &iSetup) const
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
edm::EDGetTokenT< std::map< unsigned int, int > > _multiplicityMapToken
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:208
edm::EDGetTokenT< APVCyclePhaseCollection > _apvphasecollToken
void fill(const T &he, const std::map< int, int > &ndigi, const edm::Handle< APVCyclePhaseCollection > &phase)
Definition: Run.h:43
void beginRun(const unsigned int nrun)