CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZDCDigiStudy.cc
Go to the documentation of this file.
1 // Package: ZDCDigiStudy
3 // Class: ZDCDigiStudy
4 //
5 /*
6  Description:
7  This code has been developed to be a check for the ZDC sim. In 2009, it was found that the ZDC Simulation was unrealistic and needed repair. The aim of this code is to show the user the input and output of a ZDC MinBias simulation.
8 
9  Implementation:
10  First a MinBias simulation should be run, it could be pythia,hijin,or hydjet. This will output a .root file which should have information about recoGenParticles, hcalunsuppresseddigis. Use this .root file as the input into the cfg.py which is found in the main directory of this package. This output will be another .root file which is meant to be viewed in a TBrowser.
11 
12 */
13 //
14 // Original Author: Jaime Gomez (U. of Maryland) with SIGNIFICANT assistance of Dr. Jefferey Temple (U. of Maryland)
15 //
16 //
17 // Created: Summer 2012
19 
20 
21 
22 
23 
26 
28 #include "CLHEP/Units/GlobalSystemOfUnits.h"
29 
31 
32  zdcHits = ps.getUntrackedParameter<std::string>("HitCollection","ZdcHits");
33  outFile_ = ps.getUntrackedParameter<std::string>("outputFile", "zdcHitStudy.root");
34  verbose_ = ps.getUntrackedParameter<bool>("Verbose", false);
35  checkHit_= true;
36 
37  tok_zdc_ = consumes<ZDCDigiCollection>(edm::InputTag("simHcalUnsuppressedDigis"));
38 
39  edm::LogInfo("ZDCDigiStudy")
40  //std::cout
41  << " Hits: "
42  << zdcHits << " / "<< checkHit_
43  << " Output: " << outFile_;
44 
46  if (dbe_) {
47  if (verbose_) {
48  dbe_->setVerbose(1);
49  sleep (3);
51  } else {
52  dbe_->setVerbose(0);
53  }
54  }
55 }
56 
58 
60  if (dbe_) {
61  dbe_->setCurrentFolder("ZDCDigiValidation");
62  //Histograms for Hits
64 //# Below we are filling the histograms made in the .h file. The syntax is as follows: #
65 //# plot_code_name = dbe_->TypeofPlot[(1,2,3)-D,(F,I,D)]("Name as it will appear","Title",axis options); #
66 //# They will be stored in the TFile subdirectory set by : dbe_->setCurrentFolder("FolderIwant") #
67 //# axis options are like (#ofbins,min,max) #
69 
70 
71  if (checkHit_) {
72 
73 
75 
77  dbe_->setCurrentFolder("ZDCDigiValidation/ZDC_Digis/1D_fC");
78  meZdcfCPHAD = dbe_->book1D("PHAD_TotalfC","PZDC_HAD_TotalfC",1000,-50,950);
79  meZdcfCPHAD->setAxisTitle("Counts",2);
80  meZdcfCPHAD->setAxisTitle("fC",1);
82  meZdcfCPTOT = dbe_->book1D("PZDC_TotalfC","PZDC_TotalfC",1000,-50,950);
83  meZdcfCPTOT->setAxisTitle("Counts",2);
84  meZdcfCPTOT->setAxisTitle("fC",1);
86  meZdcfCNHAD = dbe_->book1D("NHAD_TotalfC","NZDC_HAD_TotalfC",1000,-50,950);
87  meZdcfCNHAD->setAxisTitle("Counts",2);
88  meZdcfCNHAD->setAxisTitle("fC",1);
90  meZdcfCNTOT = dbe_->book1D("NZDC_TotalfC","NZDC_TotalfC",1000,-50,950);
91  meZdcfCNTOT->setAxisTitle("Counts",2);
92  meZdcfCNTOT->setAxisTitle("fC",1);
94 
96  dbe_->setCurrentFolder("ZDCDigiValidation/ZDC_Digis/fCvsTS/PZDC");
97 
99  meZdcPEM1fCvsTS = dbe_->book1D("PEM1_fCvsTS","P-EM1_AveragefC_vsTS",10,0,9);
100  meZdcPEM1fCvsTS->setAxisTitle("fC",2);
101  meZdcPEM1fCvsTS->setAxisTitle("TS",1);
104  meZdcPEM2fCvsTS = dbe_->book1D("PEM2_fCvsTS","P-EM2_AveragefC_vsTS",10,0,9);
105  meZdcPEM2fCvsTS->setAxisTitle("fC",2);
106  meZdcPEM2fCvsTS->setAxisTitle("TS",1);
109  meZdcPEM3fCvsTS = dbe_->book1D("PEM3_fCvsTS","P-EM3_AveragefC_vsTS",10,0,9);
110  meZdcPEM3fCvsTS->setAxisTitle("fC",2);
111  meZdcPEM3fCvsTS->setAxisTitle("TS",1);
114  meZdcPEM4fCvsTS = dbe_->book1D("PEM4_fCvsTS","P-EM4_AveragefC_vsTS",10,0,9);
115  meZdcPEM4fCvsTS->setAxisTitle("fC",2);
116  meZdcPEM4fCvsTS->setAxisTitle("TS",1);
119  meZdcPEM5fCvsTS = dbe_->book1D("PEM5_fCvsTS","P-EM5_AveragefC_vsTS",10,0,9);
120  meZdcPEM5fCvsTS->setAxisTitle("fC",2);
121  meZdcPEM5fCvsTS->setAxisTitle("TS",1);
124  meZdcPHAD1fCvsTS = dbe_->book1D("PHAD1_fCvsTS","P-HAD1_AveragefC_vsTS",10,0,9);
129  meZdcPHAD2fCvsTS = dbe_->book1D("PHAD2_fCvsTS","P-HAD2_AveragefC_vsTS",10,0,9);
134  meZdcPHAD3fCvsTS = dbe_->book1D("PHAD3_fCvsTS","P-HAD3_AveragefC_vsTS",10,0,9);
139  meZdcPHAD4fCvsTS = dbe_->book1D("PHAD4_fCvsTS","P-HAD4_AveragefC_vsTS",10,0,9);
143  dbe_->setCurrentFolder("ZDCDigiValidation/ZDC_Digis/fCvsTS/NZDC");
144 
146  meZdcNEM1fCvsTS = dbe_->book1D("NEM1_fCvsTS","N-EM1_AveragefC_vsTS",10,0,9);
147  meZdcNEM1fCvsTS->setAxisTitle("fC",2);
148  meZdcNEM1fCvsTS->setAxisTitle("TS",1);
151  meZdcNEM2fCvsTS = dbe_->book1D("NEM2_fCvsTS","N-EM2_AveragefC_vsTS",10,0,9);
152  meZdcNEM2fCvsTS->setAxisTitle("fC",2);
153  meZdcNEM2fCvsTS->setAxisTitle("TS",1);
156  meZdcNEM3fCvsTS = dbe_->book1D("NEM3_fCvsTS","N-EM3_AveragefC_vsTS",10,0,9);
157  meZdcNEM3fCvsTS->setAxisTitle("fC",2);
158  meZdcNEM3fCvsTS->setAxisTitle("TS",1);
161  meZdcNEM4fCvsTS = dbe_->book1D("NEM4_fCvsTS","N-EM4_AveragefC_vsTS",10,0,9);
162  meZdcNEM4fCvsTS->setAxisTitle("fC",2);
163  meZdcNEM4fCvsTS->setAxisTitle("TS",1);
166  meZdcNEM5fCvsTS = dbe_->book1D("NEM5_fCvsTS","N-EM5_AveragefC_vsTS",10,0,9);
167  meZdcNEM5fCvsTS->setAxisTitle("fC",2);
168  meZdcNEM5fCvsTS->setAxisTitle("TS",1);
171  meZdcNHAD1fCvsTS = dbe_->book1D("NHAD1_fCvsTS","N-HAD1_AveragefC_vsTS",10,0,9);
176  meZdcNHAD2fCvsTS = dbe_->book1D("NHAD2_fCvsTS","N-HAD2_AveragefC_vsTS",10,0,9);
181  meZdcNHAD3fCvsTS = dbe_->book1D("NHAD3_fCvsTS","N-HAD3_AveragefC_vsTS",10,0,9);
186  meZdcNHAD4fCvsTS = dbe_->book1D("NHAD4_fCvsTS","N-HAD4_AveragefC_vsTS",10,0,9);
190 
192  dbe_->setCurrentFolder("ZDCDigiValidation/ZDC_Digis/2D_EMvHAD");
195  meZdcfCPEMvHAD = dbe_->book2D("PEMvPHAD","PZDC_EMvHAD",1000,-25,1000,1000,-25,1000);
196  meZdcfCPEMvHAD->setAxisTitle("SumEM_fC",2);
197  meZdcfCPEMvHAD->setAxisTitle("SumHAD_fC",1);
198  meZdcfCPEMvHAD->getTH2F()->SetOption("colz");
200  meZdcfCNEMvHAD = dbe_->book2D("NEMvNHAD","NZDC_EMvHAD",1000,-25,1000,1000,-25,1000);
201  meZdcfCNEMvHAD->setAxisTitle("SumEM_fC",2);
202  meZdcfCNEMvHAD->setAxisTitle("SumHAD_fC",1);
203  meZdcfCNEMvHAD->getTH2F()->SetOption("colz");
205 
206  }
207  }
208 }
209 
211  if (dbe_ && outFile_.size() > 0) dbe_->save(outFile_);
212 }
213 
214 //void ZDCDigiStudy::analyze(const edm::Event& e, const edm::EventSetup& ) {
217 
218  using namespace edm;
219  bool gotZDCDigis=true;
220 
221 
222  Handle<ZDCDigiCollection> zdchandle;
223  if (!(iEvent.getByToken(tok_zdc_,zdchandle)))
224  {
225  gotZDCDigis=false; //this is a boolean set up to check if there are ZDCDigis in the input root file
226  }
227  if (!(zdchandle.isValid()))
228  {
229  gotZDCDigis=false; //if it is not there, leave it false
230  }
231 
232  double totalPHADCharge=0;
233  double totalNHADCharge=0;
234  double totalPEMCharge=0;
235  double totalNEMCharge=0;
236  double totalPCharge=0;
237  double totalNCharge=0;
238 
239 
241  if (gotZDCDigis==true){
242  for (ZDCDigiCollection::const_iterator zdc = zdchandle->begin();
243  zdc!=zdchandle->end();
244  ++zdc)
245  {
246  const ZDCDataFrame digi = (const ZDCDataFrame)(*zdc);
247  //std::cout <<"CHANNEL = "<<zdc->id().channel()<<std::endl;
248 
249 
250 
252 
253  if (digi.id().section()==2){ // require HAD
254  if (digi.id().zside()==1)
255  { // require POS
256  for (int i=0;i<digi.size();++i) // loop over all 10 TS because each digi has 10 entries
257  {
258  if (digi.id().channel()==1){ //here i specify PHAD1
259  meZdcPHAD1fCvsTS->Fill(i,digi.sample(i).nominal_fC()); //filling the plot name with the nominal fC value for each TS
260  if (i==0) meZdcPHAD1fCvsTS->Fill(-1,1); // on first iteration of loop, increment underflow bin
261  }//NEW AVERAGE Thingy
262  if (digi.id().channel()==2){
264  if (i==0) meZdcPHAD2fCvsTS->Fill(-1,1);
265  }
266  if (digi.id().channel()==3){
268  if (i==0) meZdcPHAD3fCvsTS->Fill(-1,1);
269  }
270  if (digi.id().channel()==4){
272  if (i==0) meZdcPHAD4fCvsTS->Fill(-1,1);
273  }
274  totalPHADCharge+=digi.sample(i).nominal_fC(); //here i am looking for the total charge in PHAD so i sum over every TS and channel and add it up
275  } // loop over all (10) TS for the given digi
276  }
277  else {
278  for (int i=0; i<digi.size();++i)
279  {
280  if (digi.id().channel()==1){
282  if (i==0) meZdcNHAD1fCvsTS->Fill(-1,1);
283  }
284  if (digi.id().channel()==2){
286  if (i==0) meZdcNHAD2fCvsTS->Fill(-1,1);
287  }
288  if (digi.id().channel()==3){
290  if (i==0) meZdcNHAD3fCvsTS->Fill(-1,1);
291  }
292  if (digi.id().channel()==4){
294  if (i==0) meZdcNHAD4fCvsTS->Fill(-1,1);
295  }
296  totalNHADCharge+=digi.sample(i).nominal_fC();
297  }
298  }
299  }
301  if (digi.id().section()==1){//require EM....here i do the smae thing that i did above but now for P/N EM sections
302  if (digi.id().zside()==1)
303  {//require pos
304  for (int i=0;i<digi.size();++i)
305  {
306  if (digi.id().channel()==1){
308  if (i==0) meZdcPEM1fCvsTS->Fill(-1,1);
309  }
310  if (digi.id().channel()==2){
312  if (i==0) meZdcPEM2fCvsTS->Fill(-1,1);
313  }
314  if (digi.id().channel()==3){
316  if (i==0) meZdcPEM3fCvsTS->Fill(-1,1);
317  }
318  if (digi.id().channel()==4){
320  if (i==0) meZdcPEM4fCvsTS->Fill(-1,1);
321  }
322  if (digi.id().channel()==5){
324  if (i==0) meZdcPEM5fCvsTS->Fill(-1,1);
325  }
326  totalPEMCharge+=digi.sample(i).nominal_fC();
327  }
328  }
329  else {
330  for (int i=0;i<digi.size();++i)
331  {
332  if (digi.id().channel()==1){
334  if (i==0) meZdcNEM1fCvsTS->Fill(-1,1);
335  }
336  if (digi.id().channel()==2){
338  if (i==0) meZdcNEM2fCvsTS->Fill(-1,1);
339  }
340  if (digi.id().channel()==3){
342  if (i==0) meZdcNEM3fCvsTS->Fill(-1,1);
343  }
344  if (digi.id().channel()==4){
346  if (i==0) meZdcNEM4fCvsTS->Fill(-1,1);
347  }
348  if (digi.id().channel()==5){
350  if (i==0) meZdcNEM5fCvsTS->Fill(-1,1);
351  }
352  totalNEMCharge+=digi.sample(i).nominal_fC();
353  }
354  }
355  }
356 
357  totalPCharge=totalPHADCharge+totalPEMCharge;
358  totalNCharge=totalNHADCharge+totalNEMCharge;
359 
360  /* std::cout <<"CHANNEL = "<<digi.id().channel()<<std::endl;
361  for (int i=0;i<digi.size();++i)
362  std::cout <<"SAMPLE = "<<i<<" ADC = "<<digi.sample(i).adc()<<" fC = "<<digi.sample(i).nominal_fC()<<std::endl;
363  */
364  // digi[i] should be the sample as digi.sample(i), I think
365  } // loop on all (22) ZDC digis
366  }
368 
369 
370 
371 
372  // Now fill total charge histogram
373  meZdcfCPEMvHAD->Fill(totalPHADCharge,totalPEMCharge);
374  meZdcfCNEMvHAD->Fill(totalNHADCharge,totalNEMCharge);
375  meZdcfCPHAD->Fill(totalPHADCharge);
376  meZdcfCNHAD->Fill(totalNHADCharge);
377  meZdcfCNTOT->Fill(totalNCharge);
378  meZdcfCPTOT->Fill(totalPCharge);
379 
380 }
381 
383 
385 {
386  int nevents=(meZdcPHAD1fCvsTS->getTH1F())->GetBinContent(0); //grab the number of digis that were read in and stored in the underflow bin, and call them Nevents
387  (meZdcPHAD1fCvsTS->getTH1F())->Scale(1./nevents); // divide histogram by nevents thereby creating an average..it was done this way so that in DQM when everything is done in parallel and added at the end then the average will add appropriately
388 
389  int nevents1=(meZdcPHAD2fCvsTS->getTH1F())->GetBinContent(0);
390  (meZdcPHAD2fCvsTS->getTH1F())->Scale(1./nevents1);
391 
392  int nevents2=(meZdcPHAD3fCvsTS->getTH1F())->GetBinContent(0);
393  (meZdcPHAD3fCvsTS->getTH1F())->Scale(1./nevents2);
394 
395  int nevents3=(meZdcPHAD4fCvsTS->getTH1F())->GetBinContent(0);
396  (meZdcPHAD4fCvsTS->getTH1F())->Scale(1./nevents3);
397 
398  int nevents4=(meZdcNHAD1fCvsTS->getTH1F())->GetBinContent(0);
399  (meZdcNHAD1fCvsTS->getTH1F())->Scale(1./nevents4);
400 
401  int nevents5=(meZdcNHAD2fCvsTS->getTH1F())->GetBinContent(0);
402  (meZdcNHAD2fCvsTS->getTH1F())->Scale(1./nevents5);
403 
404  int nevents6=(meZdcNHAD3fCvsTS->getTH1F())->GetBinContent(0);
405  (meZdcNHAD3fCvsTS->getTH1F())->Scale(1./nevents6);
406 
407  int nevents7=(meZdcNHAD4fCvsTS->getTH1F())->GetBinContent(0);
408  (meZdcNHAD4fCvsTS->getTH1F())->Scale(1./nevents7);
409 
410  int nevents8=(meZdcPEM1fCvsTS->getTH1F())->GetBinContent(0);
411  (meZdcPEM1fCvsTS->getTH1F())->Scale(1./nevents8);
412 
413  int nevents9=(meZdcPEM2fCvsTS->getTH1F())->GetBinContent(0);
414  (meZdcPEM2fCvsTS->getTH1F())->Scale(1./nevents9);
415 
416  int nevents10=(meZdcPEM3fCvsTS->getTH1F())->GetBinContent(0);
417  (meZdcPEM3fCvsTS->getTH1F())->Scale(1./nevents10);
418 
419  int nevents11=(meZdcPEM4fCvsTS->getTH1F())->GetBinContent(0);
420  (meZdcPEM4fCvsTS->getTH1F())->Scale(1./nevents11);
421 
422  int nevents12=(meZdcPEM5fCvsTS->getTH1F())->GetBinContent(0);
423  (meZdcPEM5fCvsTS->getTH1F())->Scale(1./nevents12);
424 
425  int nevents13=(meZdcNEM1fCvsTS->getTH1F())->GetBinContent(0);
426  (meZdcNEM1fCvsTS->getTH1F())->Scale(1./nevents13);
427 
428  int nevents14=(meZdcNEM2fCvsTS->getTH1F())->GetBinContent(0);
429  (meZdcNEM2fCvsTS->getTH1F())->Scale(1./nevents14);
430 
431  int nevents15=(meZdcNEM3fCvsTS->getTH1F())->GetBinContent(0);
432  (meZdcNEM3fCvsTS->getTH1F())->Scale(1./nevents15);
433 
434  int nevents16=(meZdcNEM4fCvsTS->getTH1F())->GetBinContent(0);
435  (meZdcNEM4fCvsTS->getTH1F())->Scale(1./nevents16);
436 
437  int nevents17=(meZdcNEM5fCvsTS->getTH1F())->GetBinContent(0);
438  (meZdcNEM5fCvsTS->getTH1F())->Scale(1./nevents17);
439 
440 
441 
442 }
443 
444 //define this as a plug-in
446 
447 
448 
449 
450 
451 
452 
453 
454 
455 
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
std::string zdcHits
Definition: ZDCDigiStudy.h:74
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:34
std::vector< ZDCDataFrame >::const_iterator const_iterator
MonitorElement * meZdcfCPTOT
Definition: ZDCDigiStudy.h:85
MonitorElement * meZdcPEM1fCvsTS
Definition: ZDCDigiStudy.h:90
MonitorElement * meZdcfCPEMvHAD
Definition: ZDCDigiStudy.h:88
MonitorElement * meZdcPHAD2fCvsTS
Definition: ZDCDigiStudy.h:96
MonitorElement * meZdcfCNTOT
Definition: ZDCDigiStudy.h:87
MonitorElement * meZdcPHAD3fCvsTS
Definition: ZDCDigiStudy.h:97
MonitorElement * meZdcfCPHAD
Definition: ZDCDigiStudy.h:84
void Fill(long long x)
MonitorElement * meZdcNHAD2fCvsTS
Definition: ZDCDigiStudy.h:105
int iEvent
Definition: GenABIO.cc:230
MonitorElement * meZdcPEM3fCvsTS
Definition: ZDCDigiStudy.h:92
const HcalQIESample & sample(int i) const
access a sample
Definition: ZDCDataFrame.h:39
void endRun(const edm::Run &run, const edm::EventSetup &c)
std::string outFile_
Definition: ZDCDigiStudy.h:74
MonitorElement * meZdcNHAD3fCvsTS
Definition: ZDCDigiStudy.h:106
MonitorElement * meZdcPEM2fCvsTS
Definition: ZDCDigiStudy.h:91
int nevents
MonitorElement * meZdcNEM2fCvsTS
Definition: ZDCDigiStudy.h:100
MonitorElement * meZdcNEM4fCvsTS
Definition: ZDCDigiStudy.h:102
MonitorElement * meZdcNEM3fCvsTS
Definition: ZDCDigiStudy.h:101
void setVerbose(unsigned level)
Definition: DQMStore.cc:631
Section section() const
get the section
Definition: HcalZDCDetId.h:36
MonitorElement * meZdcPHAD1fCvsTS
Definition: ZDCDigiStudy.h:95
void beginJob()
Definition: ZDCDigiStudy.cc:59
MonitorElement * meZdcNHAD4fCvsTS
Definition: ZDCDigiStudy.h:107
const HcalZDCDetId & id() const
Definition: ZDCDataFrame.h:22
double nominal_fC() const
get the nominal FC (no calibrations applied)
TH1F * getTH1F(void) const
DQMStore * dbe_
Definition: ZDCDigiStudy.h:76
int channel() const
get the channel
Definition: HcalZDCDetId.h:40
int size() const
total number of samples in the digi
Definition: ZDCDataFrame.h:26
MonitorElement * meZdcNHAD1fCvsTS
Definition: ZDCDigiStudy.h:104
MonitorElement * meZdcfCNHAD
Definition: ZDCDigiStudy.h:86
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 analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * meZdcfCNEMvHAD
Definition: ZDCDigiStudy.h:89
MonitorElement * meZdcPHAD4fCvsTS
Definition: ZDCDigiStudy.h:98
void showDirStructure(void) const
Definition: DQMStore.cc:3332
ZDCDigiStudy(const edm::ParameterSet &ps)
Definition: ZDCDigiStudy.cc:30
TH2F * getTH2F(void) const
MonitorElement * meZdcPEM4fCvsTS
Definition: ZDCDigiStudy.h:93
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1082
edm::EDGetTokenT< ZDCDigiCollection > tok_zdc_
Definition: ZDCDigiStudy.h:78
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
MonitorElement * meZdcPEM5fCvsTS
Definition: ZDCDigiStudy.h:94
MonitorElement * meZdcNEM1fCvsTS
Definition: ZDCDigiStudy.h:99
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:667
Definition: Run.h:41
MonitorElement * meZdcNEM5fCvsTS
Definition: ZDCDigiStudy.h:103