CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalSimHitStudy.cc
Go to the documentation of this file.
3 
5 
7 
8  g4Label = ps.getUntrackedParameter<std::string>("moduleLabel","g4SimHits");
9  hcalHits = ps.getUntrackedParameter<std::string>("HitCollection","HcalHits");
10  outFile_ = ps.getUntrackedParameter<std::string>("outputFile", "hcHit.root");
11  verbose_ = ps.getUntrackedParameter<bool>("Verbose", false);
12  checkHit_= true;
13 
14  tok_hits_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label,hcalHits));
15 
16  edm::LogInfo("HcalSim") << "Module Label: " << g4Label << " Hits: "
17  << hcalHits << " / "<< checkHit_
18  << " Output: " << outFile_;
19 
21  if (dbe_) {
22  if (verbose_) {
23  dbe_->setVerbose(1);
24  sleep (3);
26  } else {
27  dbe_->setVerbose(0);
28  }
29  }
30 }
31 
33 
35 
36  if (dbe_) {
37  dbe_->setCurrentFolder("HcalHitsV/HcalSimHitsTask");
38 
39  //Histograms for Hits
40  if (checkHit_) {
41  meAllNHit_ = dbe_->book1D("Hit01","Number of Hits in HCal",1000,0.,1000.);
42  meBadDetHit_= dbe_->book1D("Hit02","Hits with wrong Det", 100,0.,100.);
43  meBadSubHit_= dbe_->book1D("Hit03","Hits with wrong Subdet",100,0.,100.);
44  meBadIdHit_ = dbe_->book1D("Hit04","Hits with wrong ID", 100,0.,100.);
45  meHBNHit_ = dbe_->book1D("Hit05","Number of Hits in HB",1000,0.,1000.);
46  meHENHit_ = dbe_->book1D("Hit06","Number of Hits in HE",1000,0.,1000.);
47  meHONHit_ = dbe_->book1D("Hit07","Number of Hits in HO",1000,0.,1000.);
48  meHFNHit_ = dbe_->book1D("Hit08","Number of Hits in HF",1000,0.,1000.);
49  meDetectHit_= dbe_->book1D("Hit09","Detector ID", 50,0.,50.);
50  meSubdetHit_= dbe_->book1D("Hit10","Subdetectors in HCal", 50,0.,50.);
51  meDepthHit_ = dbe_->book1D("Hit11","Depths in HCal", 20,0.,20.);
52  meEtaHit_ = dbe_->book1D("Hit12","Eta in HCal", 100,-50.,50.);
53  mePhiHit_ = dbe_->book1D("Hit13","Phi in HCal", 100,0.,100.);
54  meEnergyHit_= dbe_->book1D("Hit14","Energy in HCal", 100,0.,1.);
55  meTimeHit_ = dbe_->book1D("Hit15","Time in HCal", 100,0.,400.);
56  meTimeWHit_ = dbe_->book1D("Hit16","Time in HCal (E wtd)", 100,0.,400.);
57  meHBDepHit_ = dbe_->book1D("Hit17","Depths in HB", 20,0.,20.);
58  meHEDepHit_ = dbe_->book1D("Hit18","Depths in HE", 20,0.,20.);
59  meHODepHit_ = dbe_->book1D("Hit19","Depths in HO", 20,0.,20.);
60  meHFDepHit_ = dbe_->book1D("Hit20","Depths in HF", 20,0.,20.);
61  meHBEtaHit_ = dbe_->book1D("Hit21","Eta in HB", 100,-50.,50.);
62  meHEEtaHit_ = dbe_->book1D("Hit22","Eta in HE", 100,-50.,50.);
63  meHOEtaHit_ = dbe_->book1D("Hit23","Eta in HO", 100,-50.,50.);
64  meHFEtaHit_ = dbe_->book1D("Hit24","Eta in HF", 100,-50.,50.);
65  meHBPhiHit_ = dbe_->book1D("Hit25","Phi in HB", 100,0.,100.);
66  meHEPhiHit_ = dbe_->book1D("Hit26","Phi in HE", 100,0.,100.);
67  meHOPhiHit_ = dbe_->book1D("Hit27","Phi in HO", 100,0.,100.);
68  meHFPhiHit_ = dbe_->book1D("Hit28","Phi in HF", 100,0.,100.);
69  meHBEneHit_ = dbe_->book1D("Hit29","Energy in HB", 100,0.,1.);
70  meHEEneHit_ = dbe_->book1D("Hit30","Energy in HE", 100,0.,1.);
71  meHOEneHit_ = dbe_->book1D("Hit31","Energy in HO", 100,0.,1.);
72  meHFEneHit_ = dbe_->book1D("Hit32","Energy in HF", 100,0.,100.);
73  meHBTimHit_ = dbe_->book1D("Hit33","Time in HB", 100,0.,400.);
74  meHETimHit_ = dbe_->book1D("Hit34","Time in HE", 100,0.,400.);
75  meHOTimHit_ = dbe_->book1D("Hit35","Time in HO", 100,0.,400.);
76  meHFTimHit_ = dbe_->book1D("Hit36","Time in HF", 100,0.,400.);
77  meHBEneHit2_ = dbe_->book1D("Hit37","Energy in HB 2", 100,0.,0.0001);
78  meHEEneHit2_ = dbe_->book1D("Hit38","Energy in HE 2", 100,0.,0.0001);
79  meHOEneHit2_ = dbe_->book1D("Hit39","Energy in HO 2", 100,0.,0.0001);
80  meHFEneHit2_ = dbe_->book1D("Hit40","Energy in HF 2", 100,0.,0.0001);
81  meHBL10Ene_ = dbe_->book1D("Hit41","Log10Energy in HB", 140, -10., 4. );
82  meHEL10Ene_ = dbe_->book1D("Hit42","Log10Energy in HE", 140, -10., 4. );
83  meHFL10Ene_ = dbe_->book1D("Hit43","Log10Energy in HF", 140, -10., 4. );
84  meHOL10Ene_ = dbe_->book1D("Hit44","Log10Energy in HO", 140, -10., 4. );
85  meHBL10EneP_ = dbe_->bookProfile("Hit45","Log10Energy in HB vs Hit contribution", 140, -10., 4., 100, 0., 1. );
86  meHEL10EneP_ = dbe_->bookProfile("Hit46","Log10Energy in HE vs Hit contribution", 140, -10., 4., 100, 0., 1. );
87  meHFL10EneP_ = dbe_->bookProfile("Hit47","Log10Energy in HF vs Hit contribution", 140, -10., 4., 100, 0., 1. );
88  meHOL10EneP_ = dbe_->bookProfile("Hit48","Log10Energy in HO vs Hit contribution", 140, -10., 4., 100, 0., 1. );
89  }
90  }
91 }
92 
94  if (dbe_ && outFile_.size() > 0) dbe_->save(outFile_);
95 }
96 
98 
99  LogDebug("HcalSim") << "Run = " << e.id().run() << " Event = "
100  << e.id().event();
101 
102  std::vector<PCaloHit> caloHits;
104 
105  bool getHits = false;
106  if (checkHit_) {
107  e.getByToken(tok_hits_,hitsHcal);
108  if (hitsHcal.isValid()) getHits = true;
109  }
110 
111  LogDebug("HcalSim") << "HcalValidation: Input flags Hits " << getHits;
112 
113  if (getHits) {
114  caloHits.insert(caloHits.end(),hitsHcal->begin(),hitsHcal->end());
115  LogDebug("HcalSim") << "HcalValidation: Hit buffer "
116  << caloHits.size();
117  analyzeHits (caloHits);
118  }
119 }
120 
121 void HcalSimHitStudy::analyzeHits (std::vector<PCaloHit>& hits) {
122 
123  int nHit = hits.size();
124  int nHB=0, nHE=0, nHO=0, nHF=0, nBad1=0, nBad2=0, nBad=0;
125  std::vector<double> encontHB(140, 0.);
126  std::vector<double> encontHE(140, 0.);
127  std::vector<double> encontHF(140, 0.);
128  std::vector<double> encontHO(140, 0.);
129  double entotHB = 0, entotHE = 0, entotHF = 0, entotHO = 0;
130 
131  for (int i=0; i<nHit; i++) {
132  double energy = hits[i].energy();
133  double log10en = log10(energy);
134  int log10i = int( (log10en+10.)*10. );
135  double time = hits[i].time();
136  unsigned int id_ = hits[i].id();
137  HcalDetId id = HcalDetId(id_);
138  int det = id.det();
139  int subdet = id.subdet();
140  int depth = id.depth();
141  int eta = id.ieta();
142  int phi = id.iphi();
143  LogDebug("HcalSim") << "Hit[" << i << "] ID " << std::hex << id_
144  << std::dec << " Det " << det << " Sub "
145  << subdet << " depth " << depth << " Eta " << eta
146  << " Phi " << phi << " E " << energy << " time "
147  << time;
148  if (det == 4) { // Check DetId.h
149  if (subdet == static_cast<int>(HcalBarrel)) nHB++;
150  else if (subdet == static_cast<int>(HcalEndcap)) nHE++;
151  else if (subdet == static_cast<int>(HcalOuter)) nHO++;
152  else if (subdet == static_cast<int>(HcalForward)) nHF++;
153  else { nBad++; nBad2++;}
154  } else { nBad++; nBad1++;}
155  if (dbe_) {
156  meDetectHit_->Fill(double(det));
157  if (det == 4) {
158  meSubdetHit_->Fill(double(subdet));
159  meDepthHit_->Fill(double(depth));
160  meEtaHit_->Fill(double(eta));
161  mePhiHit_->Fill(double(phi));
162  meEnergyHit_->Fill(energy);
163  meTimeHit_->Fill(time);
164  meTimeWHit_->Fill(double(time),energy);
165  if (subdet == static_cast<int>(HcalBarrel)) {
166  meHBDepHit_->Fill(double(depth));
167  meHBEtaHit_->Fill(double(eta));
168  meHBPhiHit_->Fill(double(phi));
169  meHBEneHit_->Fill(energy);
170  meHBEneHit2_->Fill(energy);
171  meHBTimHit_->Fill(time);
172  meHBL10Ene_->Fill(log10en);
173  if( log10i >=0 && log10i < 140 ) encontHB[log10i] += energy;
174  entotHB += energy;
175  } else if (subdet == static_cast<int>(HcalEndcap)) {
176  meHEDepHit_->Fill(double(depth));
177  meHEEtaHit_->Fill(double(eta));
178  meHEPhiHit_->Fill(double(phi));
179  meHEEneHit_->Fill(energy);
180  meHEEneHit2_->Fill(energy);
181  meHETimHit_->Fill(time);
182  meHEL10Ene_->Fill(log10en);
183  if( log10i >=0 && log10i < 140 ) encontHE[log10i] += energy;
184  entotHE += energy;
185  } else if (subdet == static_cast<int>(HcalOuter)) {
186  meHODepHit_->Fill(double(depth));
187  meHOEtaHit_->Fill(double(eta));
188  meHOPhiHit_->Fill(double(phi));
189  meHOEneHit_->Fill(energy);
190  meHOEneHit2_->Fill(energy);
191  meHOTimHit_->Fill(time);
192  meHOL10Ene_->Fill(log10en);
193  if( log10i >=0 && log10i < 140 ) encontHO[log10i] += energy;
194  entotHO += energy;
195  } else if (subdet == static_cast<int>(HcalForward)) {
196  meHFDepHit_->Fill(double(depth));
197  meHFEtaHit_->Fill(double(eta));
198  meHFPhiHit_->Fill(double(phi));
199  meHFEneHit_->Fill(energy);
200  meHFEneHit2_->Fill(energy);
201  meHFTimHit_->Fill(time);
202  meHFL10Ene_->Fill(log10en);
203  if( log10i >=0 && log10i < 140 ) encontHF[log10i] += energy;
204  entotHF += energy;
205  }
206  }
207  }
208  }
209  if( entotHB != 0 ) for( int i=0; i<140; i++ ) meHBL10EneP_->Fill( -10.+(float(i)+0.5)/10., encontHB[i]/entotHB );
210  if( entotHE != 0 ) for( int i=0; i<140; i++ ) meHEL10EneP_->Fill( -10.+(float(i)+0.5)/10., encontHE[i]/entotHE );
211  if( entotHF != 0 ) for( int i=0; i<140; i++ ) meHFL10EneP_->Fill( -10.+(float(i)+0.5)/10., encontHF[i]/entotHF );
212  if( entotHO != 0 ) for( int i=0; i<140; i++ ) meHOL10EneP_->Fill( -10.+(float(i)+0.5)/10., encontHO[i]/entotHO );
213 
214  if (dbe_) {
215  meAllNHit_->Fill(double(nHit));
216  meBadDetHit_->Fill(double(nBad1));
217  meBadSubHit_->Fill(double(nBad2));
218  meBadIdHit_->Fill(double(nBad));
219  meHBNHit_->Fill(double(nHB));
220  meHENHit_->Fill(double(nHE));
221  meHONHit_->Fill(double(nHO));
222  meHFNHit_->Fill(double(nHF));
223  }
224  LogDebug("HcalSim") << "HcalSimHitStudy::analyzeHits: HB " << nHB
225  << " HE " << nHE << " HO " << nHO << " HF " << nHF
226  << " Bad " << nBad << " All " << nHit;
227 
228 }
229 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
MonitorElement * mePhiHit_
edm::EDGetTokenT< edm::PCaloHitContainer > tok_hits_
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
MonitorElement * meHEDepHit_
MonitorElement * meHOL10Ene_
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:942
MonitorElement * meHOPhiHit_
MonitorElement * meDetectHit_
MonitorElement * meHFNHit_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
MonitorElement * meHFEtaHit_
MonitorElement * meHFL10EneP_
MonitorElement * meHFEneHit2_
MonitorElement * meHOL10EneP_
MonitorElement * meHBNHit_
MonitorElement * meHFTimHit_
T eta() const
MonitorElement * meHBEneHit2_
MonitorElement * meHONHit_
void Fill(long long x)
MonitorElement * meAllNHit_
MonitorElement * meHBL10Ene_
MonitorElement * meBadDetHit_
MonitorElement * meHFL10Ene_
MonitorElement * meHETimHit_
MonitorElement * meTimeHit_
void analyzeHits(std::vector< PCaloHit > &)
MonitorElement * meHFDepHit_
MonitorElement * meHBTimHit_
MonitorElement * meTimeWHit_
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1256
void setVerbose(unsigned level)
Definition: DQMStore.cc:619
bool isValid() const
Definition: HandleBase.h:76
MonitorElement * meHBDepHit_
void analyze(const edm::Event &e, const edm::EventSetup &c)
MonitorElement * meBadSubHit_
MonitorElement * meHENHit_
MonitorElement * meBadIdHit_
MonitorElement * meHEL10EneP_
MonitorElement * meEnergyHit_
std::string hcalHits
MonitorElement * meHOEtaHit_
MonitorElement * meEtaHit_
MonitorElement * meHBEneHit_
MonitorElement * meHOTimHit_
MonitorElement * meHBL10EneP_
edm::EventID id() const
Definition: EventBase.h:56
MonitorElement * meHEEneHit2_
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:2490
MonitorElement * meHFPhiHit_
std::string outFile_
MonitorElement * meDepthHit_
MonitorElement * meHBEtaHit_
MonitorElement * meHODepHit_
MonitorElement * meHEL10Ene_
void showDirStructure(void) const
Definition: DQMStore.cc:3282
MonitorElement * meHEEneHit_
std::string g4Label
MonitorElement * meHEPhiHit_
HcalSimHitStudy(const edm::ParameterSet &ps)
MonitorElement * meSubdetHit_
MonitorElement * meHBPhiHit_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:655
MonitorElement * meHFEneHit_
MonitorElement * meHEEtaHit_
MonitorElement * meHOEneHit_
MonitorElement * meHOEneHit2_
Definition: DDAxes.h:10