CMS 3D CMS Logo

DigiInvestigatorHistogramMaker.cc
Go to the documentation of this file.
7 #include "TProfile.h"
8 #include "TH1F.h"
9 
11 
12 
14  _hitname(), _nbins(500), m_maxLS(100), m_LSfrac(4), _scalefact(), _runHisto(true), _fillHisto(false), _binmax(), _labels(), _rhm(iC), _fhm(iC,true), _nmultvsorbrun(),
15  _nmultvsbxrun(), _nmultvsbxfill(), _nmult() { }
16 
18  _hitname(iConfig.getUntrackedParameter<std::string>("hitName","digi")),
19  _nbins(iConfig.getUntrackedParameter<int>("numberOfBins",500)),
20  m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin",100)),
21  m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction",4)),
22  _scalefact(iConfig.getUntrackedParameter<int>("scaleFactor",5)),
23  _runHisto(iConfig.getUntrackedParameter<bool>("runHisto",true)),
24  _fillHisto(iConfig.getUntrackedParameter<bool>("fillHisto",false)),
26 {
27 
28  std::vector<edm::ParameterSet>
29  wantedsubds(iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >("wantedSubDets",std::vector<edm::ParameterSet>()));
30 
31  for(std::vector<edm::ParameterSet>::iterator ps=wantedsubds.begin();ps!=wantedsubds.end();++ps) {
32  _labels[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<std::string>("detLabel");
33  _binmax[ps->getParameter<unsigned int>("detSelection")] = ps->getParameter<int>("binMax");
34  }
35 
36 
37 }
38 
39 
41 
42  for(std::map<unsigned int,std::string>::const_iterator lab=_labels.begin();lab!=_labels.end();lab++) {
43 
44  const unsigned int i = lab->first; const std::string slab = lab->second;
45 
46  delete _subdirs[i];
47  }
48 
49 }
50 
51 
52 
53 void DigiInvestigatorHistogramMaker::book(const std::string dirname, const std::map<unsigned int, std::string>& labels) {
54 
55  _labels = labels;
56  book(dirname);
57 
58 }
59 
61 
63  TFileDirectory subev = tfserv->mkdir(dirname);
64 
65  SiStripTKNumbers trnumb;
66 
67  edm::LogInfo("NumberOfBins") << "Number of Bins: " << _nbins;
68  edm::LogInfo("NumberOfMaxLS") << "Max number of LS before rebinning: " << m_maxLS;
69  edm::LogInfo("StartingLSFrac") << "Fraction of LS in one bin before rebinning: " << m_LSfrac;
70  edm::LogInfo("ScaleFactors") << "x-axis range scale factor: " << _scalefact;
71  edm::LogInfo("BinMaxValue") << "Setting bin max values";
72 
73  for(std::map<unsigned int,std::string>::const_iterator lab=_labels.begin();lab!=_labels.end();lab++) {
74 
75  const unsigned int i = lab->first; const std::string slab = lab->second;
76 
77  if(_binmax.find(i)==_binmax.end()) {
78  edm::LogVerbatim("NotConfiguredBinMax") << "Bin max for " << lab->second
79  << " not configured: " << trnumb.nstrips(i) << " used";
80  _binmax[i] = trnumb.nstrips(i);
81  }
82 
83  edm::LogVerbatim("BinMaxValue") << "Bin max for " << lab->second << " is " << _binmax[i];
84 
85  }
86 
87  for(std::map<unsigned int,std::string>::const_iterator lab=_labels.begin();lab!=_labels.end();++lab) {
88 
89  const int i = lab->first; const std::string slab = lab->second;
90 
91  char name[200];
92  char title[500];
93 
94  _subdirs[i] = new TFileDirectory(subev.mkdir(slab));
95 
96  if(_subdirs[i]) {
97  sprintf(name,"n%sdigi",slab.c_str());
98  sprintf(title,"%s %s multiplicity",slab.c_str(),_hitname.c_str());
99  _nmult[i] = _subdirs[i]->make<TH1F>(name,title,_nbins,0.,(1+_binmax[i]/(_scalefact*_nbins))*_nbins);
100  _nmult[i]->GetXaxis()->SetTitle("Number of Hits"); _nmult[i]->GetYaxis()->SetTitle("Events");
101 
102  if(_runHisto) {
103  sprintf(name,"n%sdigivsorbrun",slab.c_str());
104  sprintf(title,"%s %s mean multiplicity vs orbit",slab.c_str(),_hitname.c_str());
105  _nmultvsorbrun[i] = _rhm.makeTProfile(name,title,m_LSfrac*m_maxLS,0,m_maxLS*262144);
106  sprintf(name,"n%sdigivsbxrun",slab.c_str());
107  sprintf(title,"%s %s mean multiplicity vs BX",slab.c_str(),_hitname.c_str());
108  _nmultvsbxrun[i] = _rhm.makeTProfile(name,title,3564,-0.5,3563.5);
109  }
110  if(_fillHisto) {
111  sprintf(name,"n%sdigivsbxfill",slab.c_str());
112  sprintf(title,"%s %s mean multiplicity vs BX",slab.c_str(),_hitname.c_str());
113  _nmultvsbxfill[i] = _fhm.makeTProfile(name,title,3564,-0.5,3563.5);
114  }
115 
116  }
117 
118  }
119 
120 
121 }
122 
124 
125  // char runname[100];
126  // sprintf(runname,"run_%d",nrun);
127 
129 
130  // currdir = &(*tfserv);
131  // _rhm.beginRun(nrun,*currdir);
132 
133  _rhm.beginRun(iRun,tfserv->tFileDirectory());
134  _fhm.beginRun(iRun,tfserv->tFileDirectory());
135 
136 
137  for(std::map<unsigned int,std::string>::const_iterator lab=_labels.begin();lab!=_labels.end();++lab) {
138 
139  const int i = lab->first; const std::string slab = lab->second;
140 
141  // char name[200];
142  // char title[500];
143 
144  // TFileDirectory subd =_subdirs[i]->mkdir(runname);
145 
146  // sprintf(name,"n%sdigivsorbrun",slab.c_str());
147  // sprintf(title,"%s %s mean multiplicity vs orbit",slab.c_str(),_hitname.c_str());
148  // _nmultvsorbrun[i] = subd.make<TProfile>(name,title,_norbbin,0.5,11223*_norbbin+0.5);
149  if(_runHisto) {
150  if(*_nmultvsorbrun[i]) {
151  (*_nmultvsorbrun[i])->GetXaxis()->SetTitle("time [orbit#]"); (*_nmultvsorbrun[i])->GetYaxis()->SetTitle("Hits");
152  (*_nmultvsorbrun[i])->SetCanExtend(TH1::kXaxis);
153  }
154  if(*_nmultvsbxrun[i]) {
155  (*_nmultvsbxrun[i])->GetXaxis()->SetTitle("BX#"); (*_nmultvsbxrun[i])->GetYaxis()->SetTitle("Mean Number of Hits");
156  }
157  }
158  if(_fillHisto) {
159  if(*_nmultvsbxfill[i]) {
160  (*_nmultvsbxfill[i])->GetXaxis()->SetTitle("BX#"); (*_nmultvsbxfill[i])->GetYaxis()->SetTitle("Mean Number of Hits");
161  }
162  }
163  }
164 
165 
166 }
167 
168 void DigiInvestigatorHistogramMaker::fill(const edm::Event& iEvent, const std::map<unsigned int,int>& ndigi) {
169 
170  for(std::map<unsigned int,int>::const_iterator digi=ndigi.begin();digi!=ndigi.end();digi++) {
171 
172  if(_labels.find(digi->first) != _labels.end()) {
173 
174  const unsigned int i=digi->first;
175 
176  _nmult[i]->Fill(digi->second);
177  if(_runHisto) {
178  if(_nmultvsorbrun[i] && *_nmultvsorbrun[i]) (*_nmultvsorbrun[i])->Fill(iEvent.orbitNumber(),digi->second);
179  if(_nmultvsbxrun[i] && *_nmultvsbxrun[i]) (*_nmultvsbxrun[i])->Fill(iEvent.bunchCrossing()%3564,digi->second);
180  }
181  if(_fillHisto) {
182  if(_nmultvsbxfill[i] && *_nmultvsbxfill[i]) (*_nmultvsbxfill[i])->Fill(iEvent.bunchCrossing()%3564,digi->second);
183  }
184  }
185 
186  }
187 }
188 
T getUntrackedParameter(std::string const &, T const &) const
std::map< unsigned int, TProfile ** > _nmultvsbxrun
std::map< unsigned int, TH1F * > _nmult
void book(const std::string dirname, const std::map< unsigned int, std::string > &labels)
int bunchCrossing() const
Definition: EventBase.h:66
std::map< unsigned int, std::string > _labels
TFileDirectory & tFileDirectory()
Definition: TFileService.h:42
int iEvent
Definition: GenABIO.cc:230
int nstrips(const DetId &detid) const
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
int orbitNumber() const
Definition: EventBase.h:67
std::map< unsigned int, TProfile ** > _nmultvsbxfill
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
void beginRun(const edm::Run &iRun)
void fill(const edm::Event &iEvent, const std::map< unsigned int, int > &ndigi)
DigiInvestigatorHistogramMaker(edm::ConsumesCollector &&iC)
std::map< unsigned int, TFileDirectory * > _subdirs
std::map< unsigned int, TProfile ** > _nmultvsorbrun
Definition: Run.h:44