CMS 3D CMS Logo

HcalRecHitsDQMClient.cc
Go to the documentation of this file.
3 
8 
10 
12 {
13 
14  outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root");
15  debug_ = false;
16  verbose_ = false;
17  dirName_=iConfig.getParameter<std::string>("DQMDirName");
18 }
19 
20 
22 {
23 
24 }
25 
27 {
28 
29 
30 }
31 
32 
34 
36  es.get<HcalRecNumberingRecord>().get( pHRNDC );
37  hcons = &(*pHRNDC);
42 
44 
45  es.get<CaloGeometryRecord > ().get(geometry);
46 
47  const std::vector<DetId>& hbCells = geometry->getValidDetIds(DetId::Hcal, HcalBarrel);
48  const std::vector<DetId>& heCells = geometry->getValidDetIds(DetId::Hcal, HcalEndcap);
49  const std::vector<DetId>& hoCells = geometry->getValidDetIds(DetId::Hcal, HcalOuter);
50  const std::vector<DetId>& hfCells = geometry->getValidDetIds(DetId::Hcal, HcalForward);
51 
52  nChannels_[1] = hbCells.size();
53  nChannels_[2] = heCells.size();
54  nChannels_[3] = hoCells.size();
55  nChannels_[4] = hfCells.size();
56  nChannels_[0] = nChannels_[1] + nChannels_[2] + nChannels_[3] + nChannels_[4];
57 
58  //std::cout << "Channels HB:" << nChannels_[1] << " HE:" << nChannels_[2] << " HO:" << nChannels_[3] << " HF:" << nChannels_[4] << std::endl;
59 
60  //We hardcode the HF depths because in the dual readout configuration, rechits are not defined for depths 3&4
61  maxDepthHF_ = (maxDepthHF_ > 2 ? 2 : maxDepthHF_); //We reatin the dynamic possibility that HF might have 0 or 1 depths
62 
65 
66 }
67 
69 {
70  igetter.setCurrentFolder(dirName_);
71 
72  if (verbose_) std::cout << "\nrunClient" << std::endl;
73 
74  std::vector<MonitorElement*> hcalMEs;
75 
76  // Since out folders are fixed to three, we can just go over these three folders
77  // i.e., CaloTowersD/CaloTowersTask, HcalRecHitsD/HcalRecHitTask, NoiseRatesV/NoiseRatesTask.
78  std::vector<std::string> fullPathHLTFolders = igetter.getSubdirs();
79  for(unsigned int i=0;i<fullPathHLTFolders.size();i++) {
80 
81  if (verbose_) std::cout <<"\nfullPath: "<< fullPathHLTFolders[i] << std::endl;
82  igetter.setCurrentFolder(fullPathHLTFolders[i]);
83 
84  std::vector<std::string> fullSubPathHLTFolders = igetter.getSubdirs();
85  for(unsigned int j=0;j<fullSubPathHLTFolders.size();j++) {
86 
87  if (verbose_) std::cout <<"fullSub: "<<fullSubPathHLTFolders[j] << std::endl;
88 
89  if( strcmp(fullSubPathHLTFolders[j].c_str(), "HcalRecHitsD/HcalRecHitTask") ==0 ){
90  hcalMEs = igetter.getContents(fullSubPathHLTFolders[j]);
91  if (verbose_) std::cout <<"hltMES size : "<<hcalMEs.size()<<std::endl;
92  if( !HcalRecHitsEndjob(hcalMEs) ) std::cout<<"\nError in HcalRecHitsEndjob!"<<std::endl<<std::endl;
93  }
94 
95  }
96 
97  }
98 
99 }
100 
101 
102 // called after entering the HcalRecHitsD/HcalRecHitTask directory
103 // hcalMEs are within that directory
104 int HcalRecHitsDQMClient::HcalRecHitsEndjob(const std::vector<MonitorElement*> &hcalMEs){
105 
106  MonitorElement* Nhf=0;
107 
108  //Search for emap histograms, and collect them into this vector
109  //All subdtectors are plotted together in these histograms. We only need to look for different depths
110  std::vector<MonitorElement*> emap_depths;
111 
112  //This vector is filled occupancy_maps identified by both subdetector and depth
113  std::vector<MonitorElement*> occupancy_maps;
114  std::vector<std::string> occupancyID;
115 
116  //This vector is filled with emean_vs_ieta histograms, they are divided by both subdetector and depth
117  std::vector<MonitorElement*> emean_vs_ieta;
118 
119  //These are the only histograms filled in this module; however, the histograms are created empty in HcalRecHitsAnalyzer
120  //occupancy_vs_ieta, divided by both subdetector and depth
121  std::vector<MonitorElement*> occupancy_vs_ieta;
122  std::vector<std::string> occupancy_vs_ietaID;
123 
124  //RecHit_StatusWord & RecHit_Aux_StatusWord
125  //Divided by subdectector
126  std::vector<MonitorElement*> RecHit_StatusWord;
127  std::vector<float> RecHit_StatusWord_Channels;
128  std::vector<MonitorElement*> RecHit_Aux_StatusWord;
129  std::vector<float> RecHit_Aux_StatusWord_Channels;
130 
131  for(unsigned int ih=0; ih<hcalMEs.size(); ih++){
132 
133  //N_HF is not special, it is just convient to get the total number of events
134  //The number of entries in N_HF is equal to the number of events
135  if( hcalMEs[ih]->getName() == "N_HF" ){
136  Nhf= hcalMEs[ih];
137  continue;
138  }
139 
140  // ***********************
141  // * We fill the various MonitorElement vectors by searching for a matching substring
142  // * The methods that are used are agnostic to the ordering of vectors
143  // ***********************
144 
145  if( hcalMEs[ih]->getName().find("emap_depth") != std::string::npos ){
146  emap_depths.push_back(hcalMEs[ih]);
147  continue;
148  }
149 
150  if( hcalMEs[ih]->getName().find("occupancy_map_H") != std::string::npos ){
151  occupancy_maps.push_back(hcalMEs[ih]);
152 
153  // Use occupancyID to save the subdetector and depth information
154  // This will help preserve both indifference to vector ordering and specific details of the detector topology
155  // The position in occupancyID must correspond to the histogram position in occupancy_maps
156 
157  // Save the string after "occupancy_map_"
158 
159  std::string prefix = "occupancy_map_";
160 
161  occupancyID.push_back( hcalMEs[ih]->getName().substr(prefix.size()) );
162 
163  continue;
164  }
165 
166  if( hcalMEs[ih]->getName().find("emean_vs_ieta_H") != std::string::npos ){
167  emean_vs_ieta.push_back(hcalMEs[ih]);
168  continue;
169  }
170 
171  if( hcalMEs[ih]->getName().find("occupancy_vs_ieta_H") != std::string::npos ){
172  occupancy_vs_ieta.push_back(hcalMEs[ih]);
173 
174  // Use occupancy_vs_ietaID to save the subdetector and depth information
175  // This will help preserve both indifference to vector ordering and specific details of the detector topology
176  // The position in occupancyID must correspond to the histogram position in occupancy_vs_ieta
177 
178  // Save the string after "occupancy_vs_ieta_"
179 
180  std::string prefix = "occupancy_vs_ieta_";
181 
182  occupancy_vs_ietaID.push_back( hcalMEs[ih]->getName().substr(prefix.size()) );
183 
184  continue;
185  }
186 
187  if( hcalMEs[ih]->getName().find("HcalRecHitTask_RecHit_StatusWord_H") != std::string::npos ){
188  RecHit_StatusWord.push_back(hcalMEs[ih]);
189 
190  if(hcalMEs[ih]->getName().find("HB") != std::string::npos ){
191  RecHit_StatusWord_Channels.push_back((float)nChannels_[1]);
192  }else if(hcalMEs[ih]->getName().find("HE") != std::string::npos ){
193  RecHit_StatusWord_Channels.push_back((float)nChannels_[2]);
194  }else if(hcalMEs[ih]->getName().find("H0") != std::string::npos ){
195  RecHit_StatusWord_Channels.push_back((float)nChannels_[3]);
196  }else if(hcalMEs[ih]->getName().find("HF") != std::string::npos ){
197  RecHit_StatusWord_Channels.push_back((float)nChannels_[4]);
198  } else {
199  RecHit_StatusWord_Channels.push_back(1.);
200  }
201 
202  continue;
203  }
204 
205  if( hcalMEs[ih]->getName().find("HcalRecHitTask_RecHit_Aux_StatusWord_H") != std::string::npos ){
206  RecHit_Aux_StatusWord.push_back(hcalMEs[ih]);
207 
208  if(hcalMEs[ih]->getName().find("HB") != std::string::npos ){
209  RecHit_Aux_StatusWord_Channels.push_back((float)nChannels_[1]);
210  }else if(hcalMEs[ih]->getName().find("HE") != std::string::npos ){
211  RecHit_Aux_StatusWord_Channels.push_back((float)nChannels_[2]);
212  }else if(hcalMEs[ih]->getName().find("H0") != std::string::npos ){
213  RecHit_Aux_StatusWord_Channels.push_back((float)nChannels_[3]);
214  }else if(hcalMEs[ih]->getName().find("HF") != std::string::npos ){
215  RecHit_Aux_StatusWord_Channels.push_back((float)nChannels_[4]);
216  } else {
217  RecHit_Aux_StatusWord_Channels.push_back(1.);
218  }
219 
220  continue;
221  }
222 
223  }
224 
225  // mean energies and occupancies evaluation
226 
227  double nevtot = Nhf->getEntries(); // Use the number of entries in the Nhf histogram to give the total number of events
228 
229  if(verbose_) std::cout<<"nevtot : "<<nevtot<<std::endl;
230 
231  // emap histograms are scaled by the number of events
232  float fev = float (nevtot);
233  double scaleBynevtot = 1 / fev;
234 
235  // In this and the following histogram vectors, recognize that the for-loop index
236  // does not have to correspond to any particular depth
237  for(unsigned int depthIdx = 0; depthIdx < emap_depths.size(); depthIdx++){
238 
239  int nx = emap_depths[depthIdx]->getNbinsX();
240  int ny = emap_depths[depthIdx]->getNbinsY();
241 
242  float cnorm;
243  float enorm;
244 
245  for (int i = 1; i <= nx; i++) {
246  for (int j = 1; j <= ny; j++) {
247  cnorm = emap_depths[depthIdx]->getBinContent(i,j) * scaleBynevtot;
248  enorm = emap_depths[depthIdx]->getBinError(i,j) * scaleBynevtot;
249  emap_depths[depthIdx]->setBinContent(i,j,cnorm);
250  emap_depths[depthIdx]->setBinError(i,j,enorm);
251 
252  }
253  }
254  }
255 
256  // occupancy_maps & matched occupancy_vs_ieta
257 
258  bool omatched = false;
259 
260  for(unsigned int occupancyIdx = 0; occupancyIdx < occupancy_maps.size(); occupancyIdx++){
261 
262  int nx = occupancy_maps[occupancyIdx]->getNbinsX();
263  int ny = occupancy_maps[occupancyIdx]->getNbinsY();
264 
265  float cnorm;
266  float enorm;
267 
268  unsigned int vsIetaIdx = occupancy_vs_ieta.size();
269  omatched = false;
270 
271  for(vsIetaIdx = 0; vsIetaIdx < occupancy_vs_ieta.size(); vsIetaIdx++){
272  if(occupancyID[occupancyIdx] == occupancy_vs_ietaID[vsIetaIdx]){
273  omatched = true;
274  break;
275  }
276  }// match occupancy_vs_ieta histogram
277 
278  for (int i = 1; i <= nx; i++) {
279  for (int j = 1; j <= ny; j++) {
280  cnorm = occupancy_maps[occupancyIdx]->getBinContent(i,j) * scaleBynevtot;
281  enorm = occupancy_maps[occupancyIdx]->getBinError(i,j) * scaleBynevtot;
282  occupancy_maps[occupancyIdx]->setBinContent(i,j,cnorm);
283  occupancy_maps[occupancyIdx]->setBinError(i,j,enorm);
284 
285  }
286  }
287 
288  //Fill occupancy_vs_ieta
289 
290  if(omatched){
291 
292  //We run over all of the ieta values
293  for (int ieta = -41; ieta <= 41; ieta++) {
294  float phi_factor = 1.;
295  float sumphi = 0.;
296 
297  if(ieta == 0) continue; //ieta=0 is not defined
298 
299  phi_factor = phifactor(ieta);
300 
301  //the rechits occupancy map defines iphi as 0..71
302  for (int iphi = 0; iphi <= 71; iphi++) {
303  int binIeta = occupancy_maps[occupancyIdx]->getTH2F()->GetXaxis()->FindBin(float(ieta));
304  int binIphi = occupancy_maps[occupancyIdx]->getTH2F()->GetYaxis()->FindBin(float(iphi));
305 
306  float content = occupancy_maps[occupancyIdx]->getBinContent(binIeta,binIphi);
307 
308  sumphi += content;
309  }//for loop over phi
310 
311  double deta = double(ieta);
312 
313  // fill occupancies vs ieta
314  cnorm = sumphi / phi_factor;
315  occupancy_vs_ieta[vsIetaIdx]->Fill(deta, cnorm);
316 
317  }//Fill occupancy_vs_ieta
318  }//if omatched
319  }
320 
321  // Status Word
322  // Normalized by number of events and by number of channels per subdetector as well
323 
324  for(unsigned int StatusWordIdx = 0; StatusWordIdx < RecHit_StatusWord.size(); StatusWordIdx++){
325 
326  int nx = RecHit_StatusWord[StatusWordIdx]->getNbinsX();
327 
328  float cnorm;
329  float enorm;
330 
331  for (int i = 1; i <= nx; i++) {
332  cnorm = RecHit_StatusWord[StatusWordIdx]->getBinContent(i) * scaleBynevtot / RecHit_StatusWord_Channels[StatusWordIdx];
333  enorm = RecHit_StatusWord[StatusWordIdx]->getBinError(i) * scaleBynevtot / RecHit_StatusWord_Channels[StatusWordIdx];
334  RecHit_StatusWord[StatusWordIdx]->setBinContent(i,cnorm);
335  RecHit_StatusWord[StatusWordIdx]->setBinError(i,enorm);
336 
337  }
338 
339  }
340 
341  for(unsigned int AuxStatusWordIdx = 0; AuxStatusWordIdx < RecHit_Aux_StatusWord.size(); AuxStatusWordIdx++){
342 
343  int nx = RecHit_Aux_StatusWord[AuxStatusWordIdx]->getNbinsX();
344 
345  float cnorm;
346  float enorm;
347 
348  for (int i = 1; i <= nx; i++) {
349  cnorm = RecHit_Aux_StatusWord[AuxStatusWordIdx]->getBinContent(i) * scaleBynevtot / RecHit_Aux_StatusWord_Channels[AuxStatusWordIdx];
350  enorm = RecHit_Aux_StatusWord[AuxStatusWordIdx]->getBinError(i) * scaleBynevtot / RecHit_Aux_StatusWord_Channels[AuxStatusWordIdx];
351  RecHit_Aux_StatusWord[AuxStatusWordIdx]->setBinContent(i,cnorm);
352  RecHit_Aux_StatusWord[AuxStatusWordIdx]->setBinError(i,enorm);
353 
354  }
355 
356 
357  }
358 
359  return 1;
360 }
361 
363 
364  float phi_factor_;
365 
366  if(ieta >= -20 && ieta <= 20 ){
367  phi_factor_ = 72.;
368  } else {
369  if(ieta >= 40 || ieta <= -40 ){
370  phi_factor_ = 18.;
371  } else {
372  phi_factor_ = 36.;
373  }
374  }
375 
376  return phi_factor_;
377 
378 }
379 
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:197
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const HcalDDDRecConstants * hcons
double getEntries(void) const
get # of entries
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
virtual void beginJob(void) override
int HcalRecHitsEndjob(const std::vector< MonitorElement * > &hcalMEs)
int getMaxDepth(const int &type) const
const T & get() const
Definition: EventSetup.h:55
HcalRecHitsDQMClient(const edm::ParameterSet &)
virtual void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:92
std::vector< std::string > getSubdirs(void)
Definition: DQMStore.cc:323
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:347
ESHandle< TrackerGeometry > geometry
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:42