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  edm::LogInfo("ZDCDigiStudy")
38  //std::cout
39  << " Hits: "
40  << zdcHits << " / "<< checkHit_
41  << " Output: " << outFile_;
42 
44  if (dbe_) {
45  if (verbose_) {
46  dbe_->setVerbose(1);
47  sleep (3);
49  } else {
50  dbe_->setVerbose(0);
51  }
52  }
53 }
54 
56 
58  if (dbe_) {
59  dbe_->setCurrentFolder("ZDCDigiValidation");
60  //Histograms for Hits
62 //# Below we are filling the histograms made in the .h file. The syntax is as follows: #
63 //# plot_code_name = dbe_->TypeofPlot[(1,2,3)-D,(F,I,D)]("Name as it will appear","Title",axis options); #
64 //# They will be stored in the TFile subdirectory set by : dbe_->setCurrentFolder("FolderIwant") #
65 //# axis options are like (#ofbins,min,max) #
67 
68 
69  if (checkHit_) {
70 
71 
73 
75  dbe_->setCurrentFolder("ZDCDigiValidation/ZDC_Digis/1D_fC");
76  meZdcfCPHAD = dbe_->book1D("PHAD_TotalfC","PZDC_HAD_TotalfC",1000,-50,950);
77  meZdcfCPHAD->setAxisTitle("Counts",2);
78  meZdcfCPHAD->setAxisTitle("fC",1);
80  meZdcfCPTOT = dbe_->book1D("PZDC_TotalfC","PZDC_TotalfC",1000,-50,950);
81  meZdcfCPTOT->setAxisTitle("Counts",2);
82  meZdcfCPTOT->setAxisTitle("fC",1);
84  meZdcfCNHAD = dbe_->book1D("NHAD_TotalfC","NZDC_HAD_TotalfC",1000,-50,950);
85  meZdcfCNHAD->setAxisTitle("Counts",2);
86  meZdcfCNHAD->setAxisTitle("fC",1);
88  meZdcfCNTOT = dbe_->book1D("NZDC_TotalfC","NZDC_TotalfC",1000,-50,950);
89  meZdcfCNTOT->setAxisTitle("Counts",2);
90  meZdcfCNTOT->setAxisTitle("fC",1);
92 
94  dbe_->setCurrentFolder("ZDCDigiValidation/ZDC_Digis/fCvsTS/PZDC");
95 
97  meZdcPEM1fCvsTS = dbe_->book1D("PEM1_fCvsTS","P-EM1_AveragefC_vsTS",10,0,9);
102  meZdcPEM2fCvsTS = dbe_->book1D("PEM2_fCvsTS","P-EM2_AveragefC_vsTS",10,0,9);
103  meZdcPEM2fCvsTS->setAxisTitle("fC",2);
104  meZdcPEM2fCvsTS->setAxisTitle("TS",1);
107  meZdcPEM3fCvsTS = dbe_->book1D("PEM3_fCvsTS","P-EM3_AveragefC_vsTS",10,0,9);
108  meZdcPEM3fCvsTS->setAxisTitle("fC",2);
109  meZdcPEM3fCvsTS->setAxisTitle("TS",1);
112  meZdcPEM4fCvsTS = dbe_->book1D("PEM4_fCvsTS","P-EM4_AveragefC_vsTS",10,0,9);
113  meZdcPEM4fCvsTS->setAxisTitle("fC",2);
114  meZdcPEM4fCvsTS->setAxisTitle("TS",1);
117  meZdcPEM5fCvsTS = dbe_->book1D("PEM5_fCvsTS","P-EM5_AveragefC_vsTS",10,0,9);
118  meZdcPEM5fCvsTS->setAxisTitle("fC",2);
119  meZdcPEM5fCvsTS->setAxisTitle("TS",1);
122  meZdcPHAD1fCvsTS = dbe_->book1D("PHAD1_fCvsTS","P-HAD1_AveragefC_vsTS",10,0,9);
127  meZdcPHAD2fCvsTS = dbe_->book1D("PHAD2_fCvsTS","P-HAD2_AveragefC_vsTS",10,0,9);
132  meZdcPHAD3fCvsTS = dbe_->book1D("PHAD3_fCvsTS","P-HAD3_AveragefC_vsTS",10,0,9);
137  meZdcPHAD4fCvsTS = dbe_->book1D("PHAD4_fCvsTS","P-HAD4_AveragefC_vsTS",10,0,9);
141  dbe_->setCurrentFolder("ZDCDigiValidation/ZDC_Digis/fCvsTS/NZDC");
142 
144  meZdcNEM1fCvsTS = dbe_->book1D("NEM1_fCvsTS","N-EM1_AveragefC_vsTS",10,0,9);
145  meZdcNEM1fCvsTS->setAxisTitle("fC",2);
146  meZdcNEM1fCvsTS->setAxisTitle("TS",1);
149  meZdcNEM2fCvsTS = dbe_->book1D("NEM2_fCvsTS","N-EM2_AveragefC_vsTS",10,0,9);
150  meZdcNEM2fCvsTS->setAxisTitle("fC",2);
151  meZdcNEM2fCvsTS->setAxisTitle("TS",1);
154  meZdcNEM3fCvsTS = dbe_->book1D("NEM3_fCvsTS","N-EM3_AveragefC_vsTS",10,0,9);
155  meZdcNEM3fCvsTS->setAxisTitle("fC",2);
156  meZdcNEM3fCvsTS->setAxisTitle("TS",1);
159  meZdcNEM4fCvsTS = dbe_->book1D("NEM4_fCvsTS","N-EM4_AveragefC_vsTS",10,0,9);
160  meZdcNEM4fCvsTS->setAxisTitle("fC",2);
161  meZdcNEM4fCvsTS->setAxisTitle("TS",1);
164  meZdcNEM5fCvsTS = dbe_->book1D("NEM5_fCvsTS","N-EM5_AveragefC_vsTS",10,0,9);
165  meZdcNEM5fCvsTS->setAxisTitle("fC",2);
166  meZdcNEM5fCvsTS->setAxisTitle("TS",1);
169  meZdcNHAD1fCvsTS = dbe_->book1D("NHAD1_fCvsTS","N-HAD1_AveragefC_vsTS",10,0,9);
174  meZdcNHAD2fCvsTS = dbe_->book1D("NHAD2_fCvsTS","N-HAD2_AveragefC_vsTS",10,0,9);
179  meZdcNHAD3fCvsTS = dbe_->book1D("NHAD3_fCvsTS","N-HAD3_AveragefC_vsTS",10,0,9);
184  meZdcNHAD4fCvsTS = dbe_->book1D("NHAD4_fCvsTS","N-HAD4_AveragefC_vsTS",10,0,9);
188 
190  dbe_->setCurrentFolder("ZDCDigiValidation/ZDC_Digis/2D_EMvHAD");
193  meZdcfCPEMvHAD = dbe_->book2D("PEMvPHAD","PZDC_EMvHAD",1000,-25,1000,1000,-25,1000);
194  meZdcfCPEMvHAD->setAxisTitle("SumEM_fC",2);
195  meZdcfCPEMvHAD->setAxisTitle("SumHAD_fC",1);
196  meZdcfCPEMvHAD->getTH2F()->SetOption("colz");
198  meZdcfCNEMvHAD = dbe_->book2D("NEMvNHAD","NZDC_EMvHAD",1000,-25,1000,1000,-25,1000);
199  meZdcfCNEMvHAD->setAxisTitle("SumEM_fC",2);
200  meZdcfCNEMvHAD->setAxisTitle("SumHAD_fC",1);
201  meZdcfCNEMvHAD->getTH2F()->SetOption("colz");
203 
204  }
205  }
206 }
207 
209  if (dbe_ && outFile_.size() > 0) dbe_->save(outFile_);
210 }
211 
212 //void ZDCDigiStudy::analyze(const edm::Event& e, const edm::EventSetup& ) {
215 
216  using namespace edm;
217  bool gotZDCDigis=true;
218 
219 
220  Handle<ZDCDigiCollection> zdchandle;
221  if (!(iEvent.getByLabel("simHcalUnsuppressedDigis",zdchandle)))
222  {
223  gotZDCDigis=false; //this is a boolean set up to check if there are ZDCDigis in the input root file
224  }
225  if (!(zdchandle.isValid()))
226  {
227  gotZDCDigis=false; //if it is not there, leave it false
228  }
229 
230  double totalPHADCharge=0;
231  double totalNHADCharge=0;
232  double totalPEMCharge=0;
233  double totalNEMCharge=0;
234  double totalPCharge=0;
235  double totalNCharge=0;
236 
237 
239  if (gotZDCDigis==true){
240  for (ZDCDigiCollection::const_iterator zdc = zdchandle->begin();
241  zdc!=zdchandle->end();
242  ++zdc)
243  {
244  const ZDCDataFrame digi = (const ZDCDataFrame)(*zdc);
245  //std::cout <<"CHANNEL = "<<zdc->id().channel()<<std::endl;
246 
247 
248 
250 
251  if (digi.id().section()==2){ // require HAD
252  if (digi.id().zside()==1)
253  { // require POS
254  for (int i=0;i<digi.size();++i) // loop over all 10 TS because each digi has 10 entries
255  {
256  if (digi.id().channel()==1){ //here i specify PHAD1
257  meZdcPHAD1fCvsTS->Fill(i,digi.sample(i).nominal_fC()); //filling the plot name with the nominal fC value for each TS
258  if (i==0) meZdcPHAD1fCvsTS->Fill(-1,1); // on first iteration of loop, increment underflow bin
259  }//NEW AVERAGE Thingy
260  if (digi.id().channel()==2){
262  if (i==0) meZdcPHAD2fCvsTS->Fill(-1,1);
263  }
264  if (digi.id().channel()==3){
266  if (i==0) meZdcPHAD3fCvsTS->Fill(-1,1);
267  }
268  if (digi.id().channel()==4){
270  if (i==0) meZdcPHAD4fCvsTS->Fill(-1,1);
271  }
272  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
273  } // loop over all (10) TS for the given digi
274  }
275  else {
276  for (int i=0; i<digi.size();++i)
277  {
278  if (digi.id().channel()==1){
280  if (i==0) meZdcNHAD1fCvsTS->Fill(-1,1);
281  }
282  if (digi.id().channel()==2){
284  if (i==0) meZdcNHAD2fCvsTS->Fill(-1,1);
285  }
286  if (digi.id().channel()==3){
288  if (i==0) meZdcNHAD3fCvsTS->Fill(-1,1);
289  }
290  if (digi.id().channel()==4){
292  if (i==0) meZdcNHAD4fCvsTS->Fill(-1,1);
293  }
294  totalNHADCharge+=digi.sample(i).nominal_fC();
295  }
296  }
297  }
299  if (digi.id().section()==1){//require EM....here i do the smae thing that i did above but now for P/N EM sections
300  if (digi.id().zside()==1)
301  {//require pos
302  for (int i=0;i<digi.size();++i)
303  {
304  if (digi.id().channel()==1){
306  if (i==0) meZdcPEM1fCvsTS->Fill(-1,1);
307  }
308  if (digi.id().channel()==2){
310  if (i==0) meZdcPEM2fCvsTS->Fill(-1,1);
311  }
312  if (digi.id().channel()==3){
314  if (i==0) meZdcPEM3fCvsTS->Fill(-1,1);
315  }
316  if (digi.id().channel()==4){
318  if (i==0) meZdcPEM4fCvsTS->Fill(-1,1);
319  }
320  if (digi.id().channel()==5){
322  if (i==0) meZdcPEM5fCvsTS->Fill(-1,1);
323  }
324  totalPEMCharge+=digi.sample(i).nominal_fC();
325  }
326  }
327  else {
328  for (int i=0;i<digi.size();++i)
329  {
330  if (digi.id().channel()==1){
332  if (i==0) meZdcNEM1fCvsTS->Fill(-1,1);
333  }
334  if (digi.id().channel()==2){
336  if (i==0) meZdcNEM2fCvsTS->Fill(-1,1);
337  }
338  if (digi.id().channel()==3){
340  if (i==0) meZdcNEM3fCvsTS->Fill(-1,1);
341  }
342  if (digi.id().channel()==4){
344  if (i==0) meZdcNEM4fCvsTS->Fill(-1,1);
345  }
346  if (digi.id().channel()==5){
348  if (i==0) meZdcNEM5fCvsTS->Fill(-1,1);
349  }
350  totalNEMCharge+=digi.sample(i).nominal_fC();
351  }
352  }
353  }
354 
355  totalPCharge=totalPHADCharge+totalPEMCharge;
356  totalNCharge=totalNHADCharge+totalNEMCharge;
357 
358  /* std::cout <<"CHANNEL = "<<digi.id().channel()<<std::endl;
359  for (int i=0;i<digi.size();++i)
360  std::cout <<"SAMPLE = "<<i<<" ADC = "<<digi.sample(i).adc()<<" fC = "<<digi.sample(i).nominal_fC()<<std::endl;
361  */
362  // digi[i] should be the sample as digi.sample(i), I think
363  } // loop on all (22) ZDC digis
364  }
366 
367 
368 
369 
370  // Now fill total charge histogram
371  meZdcfCPEMvHAD->Fill(totalPHADCharge,totalPEMCharge);
372  meZdcfCNEMvHAD->Fill(totalNHADCharge,totalNEMCharge);
373  meZdcfCPHAD->Fill(totalPHADCharge);
374  meZdcfCNHAD->Fill(totalNHADCharge);
375  meZdcfCNTOT->Fill(totalNCharge);
376  meZdcfCPTOT->Fill(totalPCharge);
377 
378 }
379 
381 
383 {
384  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
385  (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
386 
387  int nevents1=(meZdcPHAD2fCvsTS->getTH1F())->GetBinContent(0);
388  (meZdcPHAD2fCvsTS->getTH1F())->Scale(1./nevents1);
389 
390  int nevents2=(meZdcPHAD3fCvsTS->getTH1F())->GetBinContent(0);
391  (meZdcPHAD3fCvsTS->getTH1F())->Scale(1./nevents2);
392 
393  int nevents3=(meZdcPHAD4fCvsTS->getTH1F())->GetBinContent(0);
394  (meZdcPHAD4fCvsTS->getTH1F())->Scale(1./nevents3);
395 
396  int nevents4=(meZdcNHAD1fCvsTS->getTH1F())->GetBinContent(0);
397  (meZdcNHAD1fCvsTS->getTH1F())->Scale(1./nevents4);
398 
399  int nevents5=(meZdcNHAD2fCvsTS->getTH1F())->GetBinContent(0);
400  (meZdcNHAD2fCvsTS->getTH1F())->Scale(1./nevents5);
401 
402  int nevents6=(meZdcNHAD3fCvsTS->getTH1F())->GetBinContent(0);
403  (meZdcNHAD3fCvsTS->getTH1F())->Scale(1./nevents6);
404 
405  int nevents7=(meZdcNHAD4fCvsTS->getTH1F())->GetBinContent(0);
406  (meZdcNHAD4fCvsTS->getTH1F())->Scale(1./nevents7);
407 
408  int nevents8=(meZdcPEM1fCvsTS->getTH1F())->GetBinContent(0);
409  (meZdcPEM1fCvsTS->getTH1F())->Scale(1./nevents8);
410 
411  int nevents9=(meZdcPEM2fCvsTS->getTH1F())->GetBinContent(0);
412  (meZdcPEM2fCvsTS->getTH1F())->Scale(1./nevents9);
413 
414  int nevents10=(meZdcPEM3fCvsTS->getTH1F())->GetBinContent(0);
415  (meZdcPEM3fCvsTS->getTH1F())->Scale(1./nevents10);
416 
417  int nevents11=(meZdcPEM4fCvsTS->getTH1F())->GetBinContent(0);
418  (meZdcPEM4fCvsTS->getTH1F())->Scale(1./nevents11);
419 
420  int nevents12=(meZdcPEM5fCvsTS->getTH1F())->GetBinContent(0);
421  (meZdcPEM5fCvsTS->getTH1F())->Scale(1./nevents12);
422 
423  int nevents13=(meZdcNEM1fCvsTS->getTH1F())->GetBinContent(0);
424  (meZdcNEM1fCvsTS->getTH1F())->Scale(1./nevents13);
425 
426  int nevents14=(meZdcNEM2fCvsTS->getTH1F())->GetBinContent(0);
427  (meZdcNEM2fCvsTS->getTH1F())->Scale(1./nevents14);
428 
429  int nevents15=(meZdcNEM3fCvsTS->getTH1F())->GetBinContent(0);
430  (meZdcNEM3fCvsTS->getTH1F())->Scale(1./nevents15);
431 
432  int nevents16=(meZdcNEM4fCvsTS->getTH1F())->GetBinContent(0);
433  (meZdcNEM4fCvsTS->getTH1F())->Scale(1./nevents16);
434 
435  int nevents17=(meZdcNEM5fCvsTS->getTH1F())->GetBinContent(0);
436  (meZdcNEM5fCvsTS->getTH1F())->Scale(1./nevents17);
437 
438 
439 
440 }
441 
442 //define this as a plug-in
444 
445 
446 
447 
448 
449 
450 
451 
452 
453 
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:722
std::string zdcHits
Definition: ZDCDigiStudy.h:74
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2118
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:36
std::vector< T >::const_iterator const_iterator
MonitorElement * meZdcfCPTOT
Definition: ZDCDigiStudy.h:83
MonitorElement * meZdcPEM1fCvsTS
Definition: ZDCDigiStudy.h:88
MonitorElement * meZdcfCPEMvHAD
Definition: ZDCDigiStudy.h:86
MonitorElement * meZdcPHAD2fCvsTS
Definition: ZDCDigiStudy.h:94
MonitorElement * meZdcfCNTOT
Definition: ZDCDigiStudy.h:85
MonitorElement * meZdcPHAD3fCvsTS
Definition: ZDCDigiStudy.h:95
void sleep(Duration_t)
Definition: Utils.h:163
MonitorElement * meZdcfCPHAD
Definition: ZDCDigiStudy.h:82
void Fill(long long x)
MonitorElement * meZdcNHAD2fCvsTS
Definition: ZDCDigiStudy.h:103
int iEvent
Definition: GenABIO.cc:243
MonitorElement * meZdcPEM3fCvsTS
Definition: ZDCDigiStudy.h:90
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:104
MonitorElement * meZdcPEM2fCvsTS
Definition: ZDCDigiStudy.h:89
int nevents
MonitorElement * meZdcNEM2fCvsTS
Definition: ZDCDigiStudy.h:98
MonitorElement * meZdcNEM4fCvsTS
Definition: ZDCDigiStudy.h:100
MonitorElement * meZdcNEM3fCvsTS
Definition: ZDCDigiStudy.h:99
void setVerbose(unsigned level)
Definition: DQMStore.cc:398
Section section() const
get the section
Definition: HcalZDCDetId.h:38
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
MonitorElement * meZdcPHAD1fCvsTS
Definition: ZDCDigiStudy.h:93
void beginJob()
Definition: ZDCDigiStudy.cc:57
MonitorElement * meZdcNHAD4fCvsTS
Definition: ZDCDigiStudy.h:105
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:42
int size() const
total number of samples in the digi
Definition: ZDCDataFrame.h:26
MonitorElement * meZdcNHAD1fCvsTS
Definition: ZDCDigiStudy.h:102
MonitorElement * meZdcfCNHAD
Definition: ZDCDigiStudy.h:84
void analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * meZdcfCNEMvHAD
Definition: ZDCDigiStudy.h:87
MonitorElement * meZdcPHAD4fCvsTS
Definition: ZDCDigiStudy.h:96
void showDirStructure(void) const
Definition: DQMStore.cc:2766
ZDCDigiStudy(const edm::ParameterSet &ps)
Definition: ZDCDigiStudy.cc:30
TH2F * getTH2F(void) const
MonitorElement * meZdcPEM4fCvsTS
Definition: ZDCDigiStudy.h:91
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:850
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:92
MonitorElement * meZdcNEM1fCvsTS
Definition: ZDCDigiStudy.h:97
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
Definition: Run.h:36
MonitorElement * meZdcNEM5fCvsTS
Definition: ZDCDigiStudy.h:101