CMS 3D CMS Logo

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 
45 }
46 
48 
50 {
51  ib.setCurrentFolder("ZDCDigiValidation");
52  //Histograms for Hits
54  //# Below we are filling the histograms made in the .h file. The syntax is as follows: #
55  //# plot_code_name = dbe_->TypeofPlot[(1,2,3)-D,(F,I,D)]("Name as it will appear","Title",axis options); #
56  //# They will be stored in the TFile subdirectory set by : dbe_->setCurrentFolder("FolderIwant") #
57  //# axis options are like (#ofbins,min,max) #
59 
60 
61  if (checkHit_) {
62 
63 
65 
67  ib.setCurrentFolder("ZDCDigiValidation/ZDC_Digis/1D_fC");
68  meZdcfCPHAD = ib.book1D("PHAD_TotalfC","PZDC_HAD_TotalfC",1000,-50,10000);
69  meZdcfCPHAD->setAxisTitle("Counts",2);
70  meZdcfCPHAD->setAxisTitle("fC",1);
72  meZdcfCPTOT = ib.book1D("PZDC_TotalfC","PZDC_TotalfC",1000,-50,20000);
73  meZdcfCPTOT->setAxisTitle("Counts",2);
74  meZdcfCPTOT->setAxisTitle("fC",1);
76  meZdcfCNHAD = ib.book1D("NHAD_TotalfC","NZDC_HAD_TotalfC",1000,-50,10000);
77  meZdcfCNHAD->setAxisTitle("Counts",2);
78  meZdcfCNHAD->setAxisTitle("fC",1);
80  meZdcfCNTOT = ib.book1D("NZDC_TotalfC","NZDC_TotalfC",1000,-50,20000);
81  meZdcfCNTOT->setAxisTitle("Counts",2);
82  meZdcfCNTOT->setAxisTitle("fC",1);
84 
86  ib.setCurrentFolder("ZDCDigiValidation/ZDC_Digis/fCvsTS/PZDC");
87 
89  meZdcPEM1fCvsTS = ib.book1D("PEM1_fCvsTS","P-EM1_AveragefC_vsTS",10,0,9);
94  meZdcPEM2fCvsTS = ib.book1D("PEM2_fCvsTS","P-EM2_AveragefC_vsTS",10,0,9);
99  meZdcPEM3fCvsTS = ib.book1D("PEM3_fCvsTS","P-EM3_AveragefC_vsTS",10,0,9);
100  meZdcPEM3fCvsTS->setAxisTitle("fC",2);
101  meZdcPEM3fCvsTS->setAxisTitle("TS",1);
104  meZdcPEM4fCvsTS = ib.book1D("PEM4_fCvsTS","P-EM4_AveragefC_vsTS",10,0,9);
105  meZdcPEM4fCvsTS->setAxisTitle("fC",2);
106  meZdcPEM4fCvsTS->setAxisTitle("TS",1);
109  meZdcPEM5fCvsTS = ib.book1D("PEM5_fCvsTS","P-EM5_AveragefC_vsTS",10,0,9);
110  meZdcPEM5fCvsTS->setAxisTitle("fC",2);
111  meZdcPEM5fCvsTS->setAxisTitle("TS",1);
114  meZdcPHAD1fCvsTS = ib.book1D("PHAD1_fCvsTS","P-HAD1_AveragefC_vsTS",10,0,9);
119  meZdcPHAD2fCvsTS = ib.book1D("PHAD2_fCvsTS","P-HAD2_AveragefC_vsTS",10,0,9);
124  meZdcPHAD3fCvsTS = ib.book1D("PHAD3_fCvsTS","P-HAD3_AveragefC_vsTS",10,0,9);
129  meZdcPHAD4fCvsTS = ib.book1D("PHAD4_fCvsTS","P-HAD4_AveragefC_vsTS",10,0,9);
133  ib.setCurrentFolder("ZDCDigiValidation/ZDC_Digis/fCvsTS/NZDC");
134 
136  meZdcNEM1fCvsTS = ib.book1D("NEM1_fCvsTS","N-EM1_AveragefC_vsTS",10,0,9);
137  meZdcNEM1fCvsTS->setAxisTitle("fC",2);
138  meZdcNEM1fCvsTS->setAxisTitle("TS",1);
141  meZdcNEM2fCvsTS = ib.book1D("NEM2_fCvsTS","N-EM2_AveragefC_vsTS",10,0,9);
142  meZdcNEM2fCvsTS->setAxisTitle("fC",2);
143  meZdcNEM2fCvsTS->setAxisTitle("TS",1);
146  meZdcNEM3fCvsTS = ib.book1D("NEM3_fCvsTS","N-EM3_AveragefC_vsTS",10,0,9);
147  meZdcNEM3fCvsTS->setAxisTitle("fC",2);
148  meZdcNEM3fCvsTS->setAxisTitle("TS",1);
151  meZdcNEM4fCvsTS = ib.book1D("NEM4_fCvsTS","N-EM4_AveragefC_vsTS",10,0,9);
152  meZdcNEM4fCvsTS->setAxisTitle("fC",2);
153  meZdcNEM4fCvsTS->setAxisTitle("TS",1);
156  meZdcNEM5fCvsTS = ib.book1D("NEM5_fCvsTS","N-EM5_AveragefC_vsTS",10,0,9);
157  meZdcNEM5fCvsTS->setAxisTitle("fC",2);
158  meZdcNEM5fCvsTS->setAxisTitle("TS",1);
161  meZdcNHAD1fCvsTS = ib.book1D("NHAD1_fCvsTS","N-HAD1_AveragefC_vsTS",10,0,9);
166  meZdcNHAD2fCvsTS = ib.book1D("NHAD2_fCvsTS","N-HAD2_AveragefC_vsTS",10,0,9);
171  meZdcNHAD3fCvsTS = ib.book1D("NHAD3_fCvsTS","N-HAD3_AveragefC_vsTS",10,0,9);
176  meZdcNHAD4fCvsTS = ib.book1D("NHAD4_fCvsTS","N-HAD4_AveragefC_vsTS",10,0,9);
180 
182  ib.setCurrentFolder("ZDCDigiValidation/ZDC_Digis/2D_EMvHAD");
185  meZdcfCPEMvHAD = ib.book2D("PEMvPHAD","PZDC_EMvHAD",200,-25,12000,200,-25,15000);
186  meZdcfCPEMvHAD->setAxisTitle("SumEM_fC",2);
187  meZdcfCPEMvHAD->setAxisTitle("SumHAD_fC",1);
188  meZdcfCPEMvHAD->getTH2F()->SetOption("colz");
190  meZdcfCNEMvHAD = ib.book2D("NEMvNHAD","NZDC_EMvHAD",1000,-25,12000,1000,-25,15000);
191  meZdcfCNEMvHAD->setAxisTitle("SumEM_fC",2);
192  meZdcfCNEMvHAD->setAxisTitle("SumHAD_fC",1);
193  meZdcfCNEMvHAD->getTH2F()->SetOption("colz");
195 
196  }
197 
198 }
199 
200 
201 /*void ZDCDigiStudy::endJob() {
202  if (dbe_ && outFile_.size() > 0) dbe_->save(outFile_);
203  }*/
204 
205 //void ZDCDigiStudy::analyze(const edm::Event& e, const edm::EventSetup& ) {
208 
209  using namespace edm;
210  bool gotZDCDigis=true;
211 
212 
213  Handle<ZDCDigiCollection> zdchandle;
214  if (!(iEvent.getByToken(tok_zdc_,zdchandle)))
215  {
216  gotZDCDigis=false; //this is a boolean set up to check if there are ZDCDigis in the input root file
217  }
218  if (!(zdchandle.isValid()))
219  {
220  gotZDCDigis=false; //if it is not there, leave it false
221  }
222 
223  double totalPHADCharge=0;
224  double totalNHADCharge=0;
225  double totalPEMCharge=0;
226  double totalNEMCharge=0;
227  double totalPCharge=0;
228  double totalNCharge=0;
229 
230 
232  if (gotZDCDigis==true){
233  for (ZDCDigiCollection::const_iterator zdc = zdchandle->begin();
234  zdc!=zdchandle->end();
235  ++zdc)
236  {
237  const ZDCDataFrame digi = (const ZDCDataFrame)(*zdc);
238  //std::cout <<"CHANNEL = "<<zdc->id().channel()<<std::endl;
239 
240 
241 
243 
244  if (digi.id().section()==2){ // require HAD
245  if (digi.id().zside()==1)
246  { // require POS
247  for (int i=0;i<digi.size();++i) // loop over all 10 TS because each digi has 10 entries
248  {
249  if (digi.id().channel()==1){ //here i specify PHAD1
250  meZdcPHAD1fCvsTS->Fill(i,digi.sample(i).nominal_fC()); //filling the plot name with the nominal fC value for each TS
251  if (i==0) meZdcPHAD1fCvsTS->Fill(-1,1); // on first iteration of loop, increment underflow bin
252  }//NEW AVERAGE Thingy
253  if (digi.id().channel()==2){
255  if (i==0) meZdcPHAD2fCvsTS->Fill(-1,1);
256  }
257  if (digi.id().channel()==3){
259  if (i==0) meZdcPHAD3fCvsTS->Fill(-1,1);
260  }
261  if (digi.id().channel()==4){
263  if (i==0) meZdcPHAD4fCvsTS->Fill(-1,1);
264  }
265  if(i==4 || i==5 || i==6) totalPHADCharge+=digi.sample(i).nominal_fC();
266  } // loop over all (10) TS for the given digi
267  }
268  else {
269  for (int i=0; i<digi.size();++i)
270  {
271  if (digi.id().channel()==1){
273  if (i==0) meZdcNHAD1fCvsTS->Fill(-1,1);
274  }
275  if (digi.id().channel()==2){
277  if (i==0) meZdcNHAD2fCvsTS->Fill(-1,1);
278  }
279  if (digi.id().channel()==3){
281  if (i==0) meZdcNHAD3fCvsTS->Fill(-1,1);
282  }
283  if (digi.id().channel()==4){
285  if (i==0) meZdcNHAD4fCvsTS->Fill(-1,1);
286  }
287  if(i==4 || i==5 || i==6) totalNHADCharge+=digi.sample(i).nominal_fC();
288  }//loop over all 10 TS
289  }//Requires NHAd
290  }//Requires HAD sections
292  if (digi.id().section()==1){//require EM....here i do the smae thing that i did above but now for P/N EM sections
293  if (digi.id().zside()==1)
294  {//require pos
295  for (int i=0;i<digi.size();++i)
296  {
297  if (digi.id().channel()==1){
299  if (i==0) meZdcPEM1fCvsTS->Fill(-1,1);
300  }
301  if (digi.id().channel()==2){
303  if (i==0) meZdcPEM2fCvsTS->Fill(-1,1);
304  }
305  if (digi.id().channel()==3){
307  if (i==0) meZdcPEM3fCvsTS->Fill(-1,1);
308  }
309  if (digi.id().channel()==4){
311  if (i==0) meZdcPEM4fCvsTS->Fill(-1,1);
312  }
313  if (digi.id().channel()==5){
315  if (i==0) meZdcPEM5fCvsTS->Fill(-1,1);
316  }
317  if (i==4 || i==5 || i==6) totalPEMCharge+=digi.sample(i).nominal_fC();
318  }
319  }
320  else {
321  for (int i=0;i<digi.size();++i)
322  {
323  if (digi.id().channel()==1){
325  if (i==0) meZdcNEM1fCvsTS->Fill(-1,1);
326  }
327  if (digi.id().channel()==2){
329  if (i==0) meZdcNEM2fCvsTS->Fill(-1,1);
330  }
331  if (digi.id().channel()==3){
333  if (i==0) meZdcNEM3fCvsTS->Fill(-1,1);
334  }
335  if (digi.id().channel()==4){
337  if (i==0) meZdcNEM4fCvsTS->Fill(-1,1);
338  }
339  if (digi.id().channel()==5){
341  if (i==0) meZdcNEM5fCvsTS->Fill(-1,1);
342  }
343  if (i==4 || i==5 || i==6) totalNEMCharge+=digi.sample(i).nominal_fC();
344  }
345  }
346  }
347 
348  totalPCharge=totalPHADCharge+(0.1)*totalPEMCharge;
349  totalNCharge=totalNHADCharge+(0.1)*totalNEMCharge;
350 
351 
352  /* std::cout <<"CHANNEL = "<<digi.id().channel()<<std::endl;
353  for (int i=0;i<digi.size();++i)
354  std::cout <<"SAMPLE = "<<i<<" ADC = "<<digi.sample(i).adc()<<" fC = "<<digi.sample(i).nominal_fC()<<std::endl;
355  */
356  // digi[i] should be the sample as digi.sample(i), I think
357  } // loop on all (22) ZDC digis
358  }
360 
361 
362 
363 
364  // Now fill total charge histogram
365  meZdcfCPEMvHAD->Fill(totalPCharge,totalPEMCharge);
366  meZdcfCNEMvHAD->Fill(totalNCharge,totalNEMCharge);
367  meZdcfCPHAD->Fill(totalPHADCharge);
368  meZdcfCNHAD->Fill(totalNHADCharge);
369  meZdcfCNTOT->Fill(totalNCharge);
370  meZdcfCPTOT->Fill(totalPCharge);
371 }
372 
374 
376 {
377  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
378  (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
379 
380  int nevents1=(meZdcPHAD2fCvsTS->getTH1F())->GetBinContent(0);
381  (meZdcPHAD2fCvsTS->getTH1F())->Scale(1./nevents1);
382 
383  int nevents2=(meZdcPHAD3fCvsTS->getTH1F())->GetBinContent(0);
384  (meZdcPHAD3fCvsTS->getTH1F())->Scale(1./nevents2);
385 
386  int nevents3=(meZdcPHAD4fCvsTS->getTH1F())->GetBinContent(0);
387  (meZdcPHAD4fCvsTS->getTH1F())->Scale(1./nevents3);
388 
389  int nevents4=(meZdcNHAD1fCvsTS->getTH1F())->GetBinContent(0);
390  (meZdcNHAD1fCvsTS->getTH1F())->Scale(1./nevents4);
391 
392  int nevents5=(meZdcNHAD2fCvsTS->getTH1F())->GetBinContent(0);
393  (meZdcNHAD2fCvsTS->getTH1F())->Scale(1./nevents5);
394 
395  int nevents6=(meZdcNHAD3fCvsTS->getTH1F())->GetBinContent(0);
396  (meZdcNHAD3fCvsTS->getTH1F())->Scale(1./nevents6);
397 
398  int nevents7=(meZdcNHAD4fCvsTS->getTH1F())->GetBinContent(0);
399  (meZdcNHAD4fCvsTS->getTH1F())->Scale(1./nevents7);
400 
401  int nevents8=(meZdcPEM1fCvsTS->getTH1F())->GetBinContent(0);
402  (meZdcPEM1fCvsTS->getTH1F())->Scale(1./nevents8);
403 
404  int nevents9=(meZdcPEM2fCvsTS->getTH1F())->GetBinContent(0);
405  (meZdcPEM2fCvsTS->getTH1F())->Scale(1./nevents9);
406 
407  int nevents10=(meZdcPEM3fCvsTS->getTH1F())->GetBinContent(0);
408  (meZdcPEM3fCvsTS->getTH1F())->Scale(1./nevents10);
409 
410  int nevents11=(meZdcPEM4fCvsTS->getTH1F())->GetBinContent(0);
411  (meZdcPEM4fCvsTS->getTH1F())->Scale(1./nevents11);
412 
413  int nevents12=(meZdcPEM5fCvsTS->getTH1F())->GetBinContent(0);
414  (meZdcPEM5fCvsTS->getTH1F())->Scale(1./nevents12);
415 
416  int nevents13=(meZdcNEM1fCvsTS->getTH1F())->GetBinContent(0);
417  (meZdcNEM1fCvsTS->getTH1F())->Scale(1./nevents13);
418 
419  int nevents14=(meZdcNEM2fCvsTS->getTH1F())->GetBinContent(0);
420  (meZdcNEM2fCvsTS->getTH1F())->Scale(1./nevents14);
421 
422  int nevents15=(meZdcNEM3fCvsTS->getTH1F())->GetBinContent(0);
423  (meZdcNEM3fCvsTS->getTH1F())->Scale(1./nevents15);
424 
425  int nevents16=(meZdcNEM4fCvsTS->getTH1F())->GetBinContent(0);
426  (meZdcNEM4fCvsTS->getTH1F())->Scale(1./nevents16);
427 
428  int nevents17=(meZdcNEM5fCvsTS->getTH1F())->GetBinContent(0);
429  (meZdcNEM5fCvsTS->getTH1F())->Scale(1./nevents17);
430 
431 
432 
433 }
434 
435 //define this as a plug-in
437 
438 
439 
440 
441 
442 
443 
444 
445 
446 
T getUntrackedParameter(std::string const &, T const &) const
std::string zdcHits
Definition: ZDCDigiStudy.h:74
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
TH1F * getTH1F() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: ZDCDigiStudy.cc:49
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:39
std::vector< ZDCDataFrame >::const_iterator const_iterator
MonitorElement * meZdcfCPTOT
Definition: ZDCDigiStudy.h:84
MonitorElement * meZdcPEM1fCvsTS
Definition: ZDCDigiStudy.h:89
MonitorElement * meZdcfCPEMvHAD
Definition: ZDCDigiStudy.h:87
MonitorElement * meZdcPHAD2fCvsTS
Definition: ZDCDigiStudy.h:95
MonitorElement * meZdcfCNTOT
Definition: ZDCDigiStudy.h:86
MonitorElement * meZdcPHAD3fCvsTS
Definition: ZDCDigiStudy.h:96
MonitorElement * meZdcfCPHAD
Definition: ZDCDigiStudy.h:83
void Fill(long long x)
~ZDCDigiStudy() override
Definition: ZDCDigiStudy.cc:47
MonitorElement * meZdcNHAD2fCvsTS
Definition: ZDCDigiStudy.h:104
void analyze(const edm::Event &e, const edm::EventSetup &c) override
int iEvent
Definition: GenABIO.cc:230
MonitorElement * meZdcPEM3fCvsTS
Definition: ZDCDigiStudy.h:91
const HcalQIESample & sample(int i) const
access a sample
Definition: ZDCDataFrame.h:39
std::string outFile_
Definition: ZDCDigiStudy.h:74
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
MonitorElement * meZdcNHAD3fCvsTS
Definition: ZDCDigiStudy.h:105
MonitorElement * meZdcPEM2fCvsTS
Definition: ZDCDigiStudy.h:90
MonitorElement * meZdcNEM2fCvsTS
Definition: ZDCDigiStudy.h:99
MonitorElement * meZdcNEM4fCvsTS
Definition: ZDCDigiStudy.h:101
MonitorElement * meZdcNEM3fCvsTS
Definition: ZDCDigiStudy.h:100
bool isValid() const
Definition: HandleBase.h:74
constexpr double nominal_fC() const
get the nominal FC (no calibrations applied)
Definition: HcalQIESample.h:61
MonitorElement * meZdcPHAD1fCvsTS
Definition: ZDCDigiStudy.h:94
TH2F * getTH2F() const
const_iterator end() const
MonitorElement * meZdcNHAD4fCvsTS
Definition: ZDCDigiStudy.h:106
const HcalZDCDetId & id() const
Definition: ZDCDataFrame.h:22
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
void endRun(const edm::Run &run, const edm::EventSetup &c) override
int channel() const
get the channel
Definition: HcalZDCDetId.cc:62
int size() const
total number of samples in the digi
Definition: ZDCDataFrame.h:26
MonitorElement * meZdcNHAD1fCvsTS
Definition: ZDCDigiStudy.h:103
Section section() const
get the section
Definition: HcalZDCDetId.cc:47
MonitorElement * meZdcfCNHAD
Definition: ZDCDigiStudy.h:85
HLT enums.
MonitorElement * meZdcfCNEMvHAD
Definition: ZDCDigiStudy.h:88
MonitorElement * meZdcPHAD4fCvsTS
Definition: ZDCDigiStudy.h:97
ZDCDigiStudy(const edm::ParameterSet &ps)
Definition: ZDCDigiStudy.cc:30
MonitorElement * meZdcPEM4fCvsTS
Definition: ZDCDigiStudy.h:92
edm::EDGetTokenT< ZDCDigiCollection > tok_zdc_
Definition: ZDCDigiStudy.h:77
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:93
MonitorElement * meZdcNEM1fCvsTS
Definition: ZDCDigiStudy.h:98
const_iterator begin() const
Definition: Run.h:44
MonitorElement * meZdcNEM5fCvsTS
Definition: ZDCDigiStudy.h:102
ib
Definition: cuy.py:661