00001 #include "Validation/HcalHits/interface/HcalSimHitsClient.h"
00002 #include "FWCore/Framework/interface/MakerMacros.h"
00003
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011
00012 HcalSimHitsClient::HcalSimHitsClient(const edm::ParameterSet& iConfig):conf_(iConfig) {
00013
00014 outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile", "myfile.root");
00015
00016 dbe_ = edm::Service<DQMStore>().operator->();
00017 if (!dbe_) {
00018 edm::LogError("HcalSimHitsClient") << "unable to get DQMStore service, upshot is no client histograms will be made";
00019 }
00020 if (iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00021 if (dbe_) dbe_->setVerbose(0);
00022 }
00023
00024 debug_ = false;
00025 verbose_ = true;
00026
00027 dirName_= iConfig.getParameter<std::string>("DQMDirName");
00028 if (dbe_) dbe_->setCurrentFolder(dirName_);
00029
00030 }
00031
00032
00033 HcalSimHitsClient::~HcalSimHitsClient() { }
00034
00035 void HcalSimHitsClient::beginJob() { }
00036
00037 void HcalSimHitsClient::endJob() {
00038 if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00039 }
00040
00041 void HcalSimHitsClient::beginRun(const edm::Run& run, const edm::EventSetup& c) { }
00042
00043
00044 void HcalSimHitsClient::endRun(const edm::Run& , const edm::EventSetup& ) {
00045 runClient_();
00046 }
00047
00048 void HcalSimHitsClient::analyze(const edm::Event& , const edm::EventSetup&) { }
00049
00050 void HcalSimHitsClient::endLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup& ) { }
00051
00052 void HcalSimHitsClient::runClient_() {
00053
00054 if (!dbe_) return;
00055 dbe_->setCurrentFolder(dirName_);
00056
00057 if (verbose_) std::cout << "\nrunClient" << std::endl;
00058
00059 std::vector<MonitorElement*> hcalMEs;
00060
00061 std::vector<std::string> fullPathHLTFolders = dbe_->getSubdirs();
00062 for (unsigned int i=0;i<fullPathHLTFolders.size();i++) {
00063 if (verbose_) std::cout <<"\nfullPath: "<< fullPathHLTFolders[i] << std::endl;
00064 dbe_->setCurrentFolder(fullPathHLTFolders[i]);
00065
00066 std::vector<std::string> fullSubPathHLTFolders = dbe_->getSubdirs();
00067 for (unsigned int j=0;j<fullSubPathHLTFolders.size();j++) {
00068
00069 if (verbose_) std::cout <<"fullSub: "<<fullSubPathHLTFolders[j] << std::endl;
00070
00071 if (strcmp(fullSubPathHLTFolders[j].c_str(), "HcalHitsV/SimHitsValidationHcal") == 0) {
00072 hcalMEs = dbe_->getContents(fullSubPathHLTFolders[j]);
00073 if (verbose_) std::cout <<"hltMES size : "<<hcalMEs.size()<<std::endl;
00074 if( !SimHitsEndjob(hcalMEs) ) std::cout<<"\nError in SimhitEndjob!"<<std::endl<<std::endl;
00075 }
00076
00077 }
00078
00079 }
00080
00081 }
00082
00083
00084
00085 int HcalSimHitsClient::SimHitsEndjob(const std::vector<MonitorElement*> &hcalMEs) {
00086
00087 MonitorElement *Occupancy_map[nTime][nType];
00088 MonitorElement *Energy[nType1], *Time_weighteden[nType1];
00089 MonitorElement *HitEnergyvsieta[nType], *HitTimevsieta[nType];
00090 std::string divisions[nType]={"HB0","HB1","HE0+z","HE1+z","HE2+z","HE0-z","HE1-z",
00091 "HE2-z","HO0","HFL0+z","HFS0+z","HFL1+z","HFS1+z",
00092 "HFL2+z","HFS2+z","HFL3+z","HFS3+z","HFL0-z","HFS0-z",
00093 "HFL1-z","HFS1-z","HFL2-z","HFS2-z","HFL3-z","HFS3-z"};
00094
00095 std::string time[nTime]={"25","50","100","250"};
00096 std::string detdivision[nType1]={"HB","HE","HF","HO"};
00097 char name[40], name1[40], name2[40], name3[40], name4[40];
00098
00099 for (int k=0; k<nType1;k++) {
00100 Energy[k] = 0;
00101 Time_weighteden[k] = 0;
00102 for (unsigned int ih=0; ih<hcalMEs.size(); ih++) {
00103 sprintf (name1, "Energy_%s", detdivision[k].c_str());
00104 sprintf (name2, "Time_Enweighted_%s", detdivision[k].c_str());
00105 if (strcmp(hcalMEs[ih]->getName().c_str(), name1) == 0) {
00106 Energy[k] = hcalMEs[ih];
00107 }
00108 if (strcmp(hcalMEs[ih]->getName().c_str(), name2) == 0) {
00109 Time_weighteden[k] = hcalMEs[ih];
00110 }
00111 }
00112 }
00113
00114 for (int i=0; i<nTime; i++) {
00115 for (int j=0; j<nType;j++) {
00116 Occupancy_map[i][j]= 0;
00117 for (unsigned int ih=0; ih<hcalMEs.size(); ih++) {
00118 sprintf (name, "HcalHitE%s%s", time[i].c_str(),divisions[j].c_str());
00119 if (strcmp(hcalMEs[ih]->getName().c_str(), name) == 0) {
00120 Occupancy_map[i][j]= hcalMEs[ih];
00121 }
00122 }
00123 }
00124 }
00125
00126 for (int k=0; k<nType;k++) {
00127 HitEnergyvsieta[k]= 0;
00128 HitTimevsieta[k]= 0;
00129 for (unsigned int ih=0; ih<hcalMEs.size(); ih++) {
00130 sprintf (name3, "HcalHitEta%s",divisions[k].c_str());
00131 sprintf (name4, "HcalHitTimeAEta%s",divisions[k].c_str());
00132 if (strcmp(hcalMEs[ih]->getName().c_str(), name3) == 0) {
00133 HitEnergyvsieta[k]= hcalMEs[ih];
00134 }
00135 if (strcmp(hcalMEs[ih]->getName().c_str(), name4) == 0) {
00136 HitTimevsieta[k]= hcalMEs[ih];
00137 }
00138 }
00139 }
00140
00141
00142
00143 double nevent = Energy[0]->getEntries();
00144 if (verbose_) std::cout<<"nevent : "<<nevent<<std::endl;
00145
00146 float cont[nTime][nType];
00147 float en[nType1], tme[nType1];
00148 float hitenergy[nType], hittime[nType];
00149 float fev = float(nevent);
00150
00151 for (int dettype=0; dettype<nType1; dettype++) {
00152 int nx1=Energy[dettype]->getNbinsX();
00153 for (int i=0; i<=nx1; i++) {
00154 en[dettype]= Energy[dettype]->getBinContent(i)/fev;
00155 Energy[dettype]->setBinContent(i,en[dettype]);
00156 }
00157 int nx2= Time_weighteden[dettype]->getNbinsX();
00158 for (int i=0; i<=nx2; i++) {
00159
00160 tme[dettype]= Time_weighteden[dettype]->getBinContent(i)/fev;
00161
00162 Time_weighteden[dettype]->setBinContent(i,tme[dettype]);
00163 }
00164 }
00165
00166 for (int dettype=0; dettype<nType; dettype++) {
00167 if (HitEnergyvsieta[dettype] != 0) {
00168 int nx1=HitEnergyvsieta[dettype]->getNbinsX();
00169 for (int i=0; i<=nx1; i++) {
00170 hitenergy[dettype]= HitEnergyvsieta[dettype]->getBinContent(i)/fev;
00171 HitEnergyvsieta[dettype]->setBinContent(i,hitenergy[dettype]);
00172 }
00173 int nx2= HitTimevsieta[dettype]->getNbinsX();
00174 for (int i=0; i<=nx2; i++) {
00175 hittime[dettype]= HitTimevsieta[dettype]->getBinContent(i)/fev;
00176 HitTimevsieta[dettype]->setBinContent(i,hittime[dettype]);
00177 }
00178 }
00179 }
00180
00181 for (int itime=0; itime<nTime; itime++) {
00182 for (int det=0; det<nType;det++) {
00183 if (Occupancy_map[itime][det] != 0) {
00184 int ny= Occupancy_map[itime][det]->getNbinsY();
00185 int nx= Occupancy_map[itime][det]->getNbinsX();
00186 for (int i=1; i<nx+1; i++) {
00187 for (int j=1; j<ny+1; j++) {
00188 cont[itime][det] = Occupancy_map[itime][det]->getBinContent(i,j)/fev;
00189 Occupancy_map[itime][det]->setBinContent(i,j,cont[itime][det]);
00190 }
00191 }
00192 }
00193 }
00194 }
00195
00196 return 1;
00197 }
00198
00199 DEFINE_FWK_MODULE(HcalSimHitsClient);