CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalSimHitsClient.cc
Go to the documentation of this file.
3 
8 
11 
13 
14  outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root");
15 
17  if (!dbe_) {
18  edm::LogError("HcalSimHitsClient") << "unable to get DQMStore service, upshot is no client histograms will be made";
19  }
20  if (iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
21  if (dbe_) dbe_->setVerbose(0);
22  }
23 
24  debug_ = false;
25  verbose_ = true;
26 
27  dirName_= iConfig.getParameter<std::string>("DQMDirName");
28  if (dbe_) dbe_->setCurrentFolder(dirName_);
29 
30 }
31 
32 
34 
36 
38  if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
39 }
40 
42 
43 
45  runClient_();
46 }
47 
49 
51 
53 
54  if (!dbe_) return; //we dont have the DQMStore so we cant do anything
56 
57  if (verbose_) std::cout << "\nrunClient" << std::endl;
58 
59  std::vector<MonitorElement*> hcalMEs;
60 
61  std::vector<std::string> fullPathHLTFolders = dbe_->getSubdirs();
62  for (unsigned int i=0;i<fullPathHLTFolders.size();i++) {
63  if (verbose_) std::cout <<"\nfullPath: "<< fullPathHLTFolders[i] << std::endl;
64  dbe_->setCurrentFolder(fullPathHLTFolders[i]);
65 
66  std::vector<std::string> fullSubPathHLTFolders = dbe_->getSubdirs();
67  for (unsigned int j=0;j<fullSubPathHLTFolders.size();j++) {
68 
69  if (verbose_) std::cout <<"fullSub: "<<fullSubPathHLTFolders[j] << std::endl;
70 
71  if (strcmp(fullSubPathHLTFolders[j].c_str(), "HcalHitsV/SimHitsValidationHcal") == 0) {
72  hcalMEs = dbe_->getContents(fullSubPathHLTFolders[j]);
73  if (verbose_) std::cout <<"hltMES size : "<<hcalMEs.size()<<std::endl;
74  if( !SimHitsEndjob(hcalMEs) ) std::cout<<"\nError in SimhitEndjob!"<<std::endl<<std::endl;
75  }
76 
77  }
78 
79  }
80 
81 }
82 
83 // called after entering the directory
84 // hcalMEs are within that directory
85 int HcalSimHitsClient::SimHitsEndjob(const std::vector<MonitorElement*> &hcalMEs) {
86 
87  MonitorElement *Occupancy_map[nTime][nType];
88  MonitorElement *Energy[nType1], *Time_weighteden[nType1];
89  MonitorElement *HitEnergyvsieta[nType], *HitTimevsieta[nType];
90  std::string divisions[nType]={"HB0","HB1","HE0+z","HE1+z","HE2+z","HE0-z","HE1-z",
91  "HE2-z","HO0","HFL0+z","HFS0+z","HFL1+z","HFS1+z",
92  "HFL2+z","HFS2+z","HFL3+z","HFS3+z","HFL0-z","HFS0-z",
93  "HFL1-z","HFS1-z","HFL2-z","HFS2-z","HFL3-z","HFS3-z"};
94 
95  std::string time[nTime]={"25","50","100","250"};
96  std::string detdivision[nType1]={"HB","HE","HF","HO"};
97  char name[40], name1[40], name2[40], name3[40], name4[40];
98 
99  for (int k=0; k<nType1;k++) {
100  Energy[k] = 0;
101  Time_weighteden[k] = 0;
102  for (unsigned int ih=0; ih<hcalMEs.size(); ih++) {
103  sprintf (name1, "Energy_%s", detdivision[k].c_str());
104  sprintf (name2, "Time_Enweighted_%s", detdivision[k].c_str());
105  if (strcmp(hcalMEs[ih]->getName().c_str(), name1) == 0) {
106  Energy[k] = hcalMEs[ih];
107  }
108  if (strcmp(hcalMEs[ih]->getName().c_str(), name2) == 0) {
109  Time_weighteden[k] = hcalMEs[ih];
110  }
111  }
112  }
113 
114  for (int i=0; i<nTime; i++) {
115  for (int j=0; j<nType;j++) {
116  Occupancy_map[i][j]= 0;
117  for (unsigned int ih=0; ih<hcalMEs.size(); ih++) {
118  sprintf (name, "HcalHitE%s%s", time[i].c_str(),divisions[j].c_str());
119  if (strcmp(hcalMEs[ih]->getName().c_str(), name) == 0) {
120  Occupancy_map[i][j]= hcalMEs[ih];
121  }
122  }
123  }
124  }
125 
126  for (int k=0; k<nType;k++) {
127  HitEnergyvsieta[k]= 0;
128  HitTimevsieta[k]= 0;
129  for (unsigned int ih=0; ih<hcalMEs.size(); ih++) {
130  sprintf (name3, "HcalHitEta%s",divisions[k].c_str());
131  sprintf (name4, "HcalHitTimeAEta%s",divisions[k].c_str());
132  if (strcmp(hcalMEs[ih]->getName().c_str(), name3) == 0) {
133  HitEnergyvsieta[k]= hcalMEs[ih];
134  }
135  if (strcmp(hcalMEs[ih]->getName().c_str(), name4) == 0) {
136  HitTimevsieta[k]= hcalMEs[ih];
137  }
138  }
139  }
140 
141  //mean energy
142 
143  double nevent = Energy[0]->getEntries();
144  if (verbose_) std::cout<<"nevent : "<<nevent<<std::endl;
145 
146  float cont[nTime][nType];
147  float en[nType1], tme[nType1];
148  float hitenergy[nType], hittime[nType];
149  float fev = float(nevent);
150 
151  for (int dettype=0; dettype<nType1; dettype++) {
152  int nx1=Energy[dettype]->getNbinsX();
153  for (int i=0; i<=nx1; i++) {
154  en[dettype]= Energy[dettype]->getBinContent(i)/fev;
155  Energy[dettype]->setBinContent(i,en[dettype]);
156  }
157  int nx2= Time_weighteden[dettype]->getNbinsX();
158  for (int i=0; i<=nx2; i++) {
159  //std::cout<<" time_eneweighted for bin: "<< i<<"is:"<<Time_weighteden[dettype]->getBinContent(i)<<std::endl;
160  tme[dettype]= Time_weighteden[dettype]->getBinContent(i)/fev;
161  //std::cout<<" averagetime for bin : "<<i<<"is:"<<tme[dettype]<<std::endl;
162  Time_weighteden[dettype]->setBinContent(i,tme[dettype]);
163  }
164  }
165 
166  for (int dettype=0; dettype<nType; dettype++) {
167  if (HitEnergyvsieta[dettype] != 0) {
168  int nx1=HitEnergyvsieta[dettype]->getNbinsX();
169  for (int i=0; i<=nx1; i++) {
170  hitenergy[dettype]= HitEnergyvsieta[dettype]->getBinContent(i)/fev;
171  HitEnergyvsieta[dettype]->setBinContent(i,hitenergy[dettype]);
172  }
173  int nx2= HitTimevsieta[dettype]->getNbinsX();
174  for (int i=0; i<=nx2; i++) {
175  hittime[dettype]= HitTimevsieta[dettype]->getBinContent(i)/fev;
176  HitTimevsieta[dettype]->setBinContent(i,hittime[dettype]);
177  }
178  }
179  }
180 
181  for (int itime=0; itime<nTime; itime++) {
182  for (int det=0; det<nType;det++) {
183  if (Occupancy_map[itime][det] != 0) {
184  int ny= Occupancy_map[itime][det]->getNbinsY();
185  int nx= Occupancy_map[itime][det]->getNbinsX();
186  for (int i=1; i<nx+1; i++) {
187  for (int j=1; j<ny+1; j++) {
188  cont[itime][det] = Occupancy_map[itime][det]->getBinContent(i,j)/fev;
189  Occupancy_map[itime][det]->setBinContent(i,j,cont[itime][det]);
190  }
191  }
192  }
193  }
194  }
195 
196  return 1;
197 }
198 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
virtual void runClient_()
static const int nType1
std::vector< std::string > getSubdirs(void) const
Definition: DQMStore.cc:1575
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &, const edm::EventSetup &)
int SimHitsEndjob(const std::vector< MonitorElement * > &hcalMEs)
virtual void beginRun(const edm::Run &run, const edm::EventSetup &c)
double getEntries(void) const
get # of entries
virtual void endRun(const edm::Run &run, const edm::EventSetup &c)
int getNbinsY(void) const
get # of bins in Y-axis
int nevent
Definition: AMPTWrapper.h:74
static const int nType
std::string outputFile_
int j
Definition: DBlmapReader.cc:9
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2297
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1653
virtual void beginJob(void)
int k[5][pyjets_maxn]
virtual ~HcalSimHitsClient()
static const int nTime
int cont
virtual void endJob()
double getBinContent(int binx) const
get content of bin (1-D)
virtual void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
HcalSimHitsClient(const edm::ParameterSet &)
int getNbinsX(void) const
get # of bins in X-axis
tuple cout
Definition: gather_cfg.py:121
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:585
Definition: Run.h:41