CMS 3D CMS Logo

HGCalSimHitsClient.cc
Go to the documentation of this file.
9 
16 
18  nameDetector_ = iConfig.getParameter<std::string>("DetectorName");
19  nTimes_ = iConfig.getParameter<int>("TimeSlices");
20  verbosity_ = iConfig.getUntrackedParameter<int>("Verbosity",0);
21 }
22 
24 
26 
27  if (nameDetector_ == "HCal") {
29  iSetup.get<HcalRecNumberingRecord>().get( pHRNDC );
30  const HcalDDDRecConstants *hcons = &(*pHRNDC);
31  layers_ = hcons->getMaxDepth(1);
32  } else {
34  iSetup.get<IdealGeometryRecord>().get(nameDetector_, pHGDC);
35  const HGCalDDDConstants & hgcons = (*pHGDC);
36  layers_ = hgcons.layers(false);
37  }
38  if (verbosity_>0)
39  edm::LogInfo("HGCalValidation") << "Initialize HGCalSimHitsClient for "
40  << nameDetector_ << " : " << layers_ <<"\n";
41 }
42 
44  runClient_(ib, ig);
45 }
46 
48 
49  ig.setCurrentFolder("/");
50  if (verbosity_>0) edm::LogInfo("HGCalValidation") << " runClient\n";
51  std::vector<MonitorElement*> hgcalMEs;
52  std::vector<std::string> fullDirPath = ig.getSubdirs();
53 
54  for (unsigned int i=0; i<fullDirPath.size(); i++) {
55  if (verbosity_>0)
56  edm::LogInfo("HGCalValidation") << "fullPath: " << fullDirPath.at(i) << "\n";
57  ig.setCurrentFolder(fullDirPath.at(i));
58  std::vector<std::string> fullSubDirPath = ig.getSubdirs();
59 
60  for (unsigned int j=0; j<fullSubDirPath.size(); j++) {
61  if (verbosity_>0)
62  edm::LogInfo("HGCalValidation") << "fullSubPath: " << fullSubDirPath.at(j) << "\n";
63  std::string nameDirectory = "HGCalSimHitsV/"+nameDetector_;
64 
65  if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
66  hgcalMEs = ig.getContents(fullSubDirPath.at(j));
67  if (verbosity_>0)
68  edm::LogInfo("HGCalValidation") << "hgcalMES size : " << hgcalMEs.size() << "\n";
69  if (!simHitsEndjob(hgcalMEs))
70  edm::LogWarning("HGCalValidation") << "\nError in SimhitsEndjob!";
71  }
72  }
73  }
74 }
75 
76 int HGCalSimHitsClient::simHitsEndjob(const std::vector<MonitorElement*>& hgcalMEs) {
77 
78  std::vector<MonitorElement*> energy_[6];
79  std::vector<MonitorElement*> EtaPhi_Plus_, EtaPhi_Minus_;
80  std::vector<MonitorElement*> HitOccupancy_Plus_, HitOccupancy_Minus_;
81  MonitorElement *MeanHitOccupancy_Plus_, *MeanHitOccupancy_Minus_;
82 
83  std::ostringstream name;
84  double nevent;
85  int nbinsx, nbinsy;
86  for (unsigned int ilayer = 0; ilayer < layers_; ilayer++ ){
87  for (int itimeslice = 0; itimeslice < nTimes_; itimeslice++ ) {
88  //Energy
89  name.str(""); name << "energy_time_" << itimeslice << "_layer_" << ilayer;
90  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
91  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0){
92  energy_[itimeslice].push_back(hgcalMEs[ih]);
93  }
94  }
95  //normalization
96  nevent = energy_[itimeslice].at(ilayer)->getEntries();
97  nbinsx = energy_[itimeslice].at(ilayer)->getNbinsX();
98  for(int i=1; i <= nbinsx; i++) {
99  double binValue = energy_[itimeslice].at(ilayer)->getBinContent(i)/nevent;
100  energy_[itimeslice].at(ilayer)->setBinContent(i,binValue);
101  }
102  }
103 
104  //EtaPhi 2d plots
105  name.str(""); name << "EtaPhi_Plus_" << "layer_" << ilayer;
106  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
107  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0){
108  EtaPhi_Plus_.push_back(hgcalMEs[ih]);
109  }
110  }
111 
112  name.str(""); name << "EtaPhi_Minus_" << "layer_" << ilayer;
113  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
114  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0){
115  EtaPhi_Minus_.push_back(hgcalMEs[ih]);
116  }
117  }
118  //normalization EtaPhi
119  nevent = EtaPhi_Plus_.at(ilayer)->getEntries();
120  nbinsx = EtaPhi_Plus_.at(ilayer)->getNbinsX();
121  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
122  for(int i=1; i<= nbinsx; ++i) {
123  for(int j=1; j<= nbinsy; ++j) {
124  double binValue = EtaPhi_Plus_.at(ilayer)->getBinContent(i, j)/nevent;
125  EtaPhi_Plus_.at(ilayer)->setBinContent(i, j, binValue);
126  }
127  }
128 
129  nevent = EtaPhi_Minus_.at(ilayer)->getEntries();
130  nbinsx = EtaPhi_Minus_.at(ilayer)->getNbinsX();
131  nbinsy = EtaPhi_Plus_.at(ilayer)->getNbinsY();
132  for(int i=1; i<= nbinsx; ++i) {
133  for(int j=1; j<= nbinsy; ++j) {
134  double binValue = EtaPhi_Minus_.at(ilayer)->getBinContent(i, j)/nevent;
135  EtaPhi_Minus_.at(ilayer)->setBinContent(i, j, binValue);
136  }
137  }
138 
139  //HitOccupancy
140  name.str(""); name << "HitOccupancy_Plus_layer_" << ilayer;
141  for (unsigned int ih=0; ih<hgcalMEs.size(); ih++) {
142  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
143  HitOccupancy_Plus_.push_back(hgcalMEs[ih]);
144  }
145  }
146  name.str(""); name << "HitOccupancy_Minus_layer_" << ilayer;
147  for (unsigned int ih=0; ih<hgcalMEs.size(); ih++) {
148  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
149  HitOccupancy_Minus_.push_back(hgcalMEs[ih]);
150  }
151  }
152 
153  nevent = HitOccupancy_Plus_.at(ilayer)->getEntries();
154  nbinsx = HitOccupancy_Plus_.at(ilayer)->getNbinsX();
155  for (int i=1; i<= nbinsx; ++i) {
156  double binValue = HitOccupancy_Plus_.at(ilayer)->getBinContent(i)/nevent;
157  HitOccupancy_Plus_.at(ilayer)->setBinContent(i, binValue);
158  }
159 
160  nevent = HitOccupancy_Minus_.at(ilayer)->getEntries();
161  nbinsx = HitOccupancy_Minus_.at(ilayer)->getNbinsX();
162  for (int i=1; i<= nbinsx; ++i) {
163  double binValue = HitOccupancy_Minus_.at(ilayer)->getBinContent(i)/nevent;
164  HitOccupancy_Minus_.at(ilayer)->setBinContent(i, binValue);
165  }
166 
167  }//loop over layers
168 
169  name.str(""); name << "MeanHitOccupancy_Plus";
170  for (unsigned int ih=0; ih<hgcalMEs.size(); ih++) {
171  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
172  MeanHitOccupancy_Plus_ = hgcalMEs[ih];
173  for (int ilayer=0; ilayer < (int)layers_; ++ilayer) {
174  double meanVal = HitOccupancy_Plus_.at(ilayer)->getMean();
175  MeanHitOccupancy_Plus_->setBinContent(ilayer+1, meanVal);
176  }
177  break;
178  }
179  }
180 
181  name.str(""); name << "MeanHitOccupancy_Minus";
182  for(unsigned int ih=0; ih<hgcalMEs.size(); ih++){
183  if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
184  MeanHitOccupancy_Minus_ = hgcalMEs[ih];
185  for (int ilayer=0; ilayer < (int)layers_; ++ilayer) {
186  double meanVal = HitOccupancy_Minus_.at(ilayer)->getMean();
187  MeanHitOccupancy_Minus_->setBinContent(ilayer+1, meanVal);
188  }
189  break;
190  }
191  }
192 
193  return 1;
194 }
195 
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:197
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
virtual void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
virtual void beginRun(const edm::Run &run, const edm::EventSetup &c)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
int nevent
Definition: AMPTWrapper.h:74
unsigned int layers(bool reco) const
HGCalSimHitsClient(const edm::ParameterSet &)
int getMaxDepth(const int &type) const
const T & get() const
Definition: EventSetup.h:55
std::vector< std::string > getSubdirs(void)
Definition: DQMStore.cc:323
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:347
int simHitsEndjob(const std::vector< MonitorElement * > &hcalMEs)
void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig)
Definition: Run.h:42
ib
Definition: cuy.py:660