00001 #include <iostream>
00002
00003
00004 #include "DQMOffline/EGamma/plugins/PhotonOfflineClient.h"
00005
00006
00007
00008
00009
00023 using namespace std;
00024 using std::cout;
00025
00026 PhotonOfflineClient::PhotonOfflineClient(const edm::ParameterSet& pset)
00027 {
00028
00029 dbe_ = 0;
00030 dbe_ = edm::Service<DQMStore>().operator->();
00031 dbe_->setVerbose(0);
00032 parameters_ = pset;
00033
00034 cutStep_ = pset.getParameter<double>("cutStep");
00035 numberOfSteps_ = pset.getParameter<int>("numberOfSteps");
00036
00037 etMin = pset.getParameter<double>("etMin");
00038 etMax = pset.getParameter<double>("etMax");
00039 etBin = pset.getParameter<int>("etBin");
00040 etaMin = pset.getParameter<double>("etaMin");
00041 etaMax = pset.getParameter<double>("etaMax");
00042 etaBin = pset.getParameter<int>("etaBin");
00043 phiMin = pset.getParameter<double>("phiMin");
00044 phiMax = pset.getParameter<double>("phiMax");
00045 phiBin = pset.getParameter<int>("phiBin");
00046
00047 standAlone_ = pset.getParameter<bool>("standAlone");
00048 batch_ = pset.getParameter<bool>("batch");
00049 excludeBkgHistos_ = pset.getParameter<bool>("excludeBkgHistos");
00050
00051 outputFileName_ = pset.getParameter<string>("OutputFileName");
00052 inputFileName_ = pset.getUntrackedParameter<string>("InputFileName");
00053
00054 histo_index_photons_ = 0;
00055 histo_index_conversions_ = 0;
00056 histo_index_efficiency_ = 0;
00057 histo_index_invMass_ = 0;
00058
00059 types_.push_back("All");
00060 types_.push_back("GoodCandidate");
00061 if (!excludeBkgHistos_) types_.push_back("Background");
00062
00063 parts_.push_back("AllEcal");
00064 parts_.push_back("Barrel");
00065 parts_.push_back("Endcaps");
00066
00067 }
00068
00069 PhotonOfflineClient::~PhotonOfflineClient()
00070 {}
00071 void PhotonOfflineClient::beginJob()
00072 {}
00073 void PhotonOfflineClient::analyze(const edm::Event& e, const edm::EventSetup& esup)
00074 {}
00075 void PhotonOfflineClient::endLuminosityBlock( const edm::LuminosityBlock& , const edm::EventSetup& setup)
00076 {}
00077
00078
00079
00080 void PhotonOfflineClient::endJob()
00081 {
00082 if(standAlone_) runClient();
00083 }
00084 void PhotonOfflineClient::endRun(const edm::Run& run, const edm::EventSetup& setup)
00085 {
00086 if(!standAlone_) runClient();
00087 }
00088
00089
00090
00091
00092 void PhotonOfflineClient::runClient()
00093 {
00094 if(!dbe_) return;
00095
00096 if(batch_) dbe_->open(inputFileName_);
00097
00098 if(!dbe_->dirExists("Egamma/PhotonAnalyzer")){
00099
00100 return;
00101 }
00102
00103
00104 histo_index_photons_ = dbe_->get("Egamma/PhotonAnalyzer/numberOfHistogramsInPhotonsFolder")->getIntValue();
00105 histo_index_conversions_ = dbe_->get("Egamma/PhotonAnalyzer/numberOfHistogramsInConversionsFolder")->getIntValue();
00106 histo_index_efficiency_ = dbe_->get("Egamma/PhotonAnalyzer/numberOfHistogramsInEfficiencyFolder")->getIntValue();
00107 histo_index_invMass_ = dbe_->get("Egamma/PhotonAnalyzer/numberOfHistogramsInInvMassFolder")->getIntValue();
00108
00109 dbe_->setCurrentFolder("Egamma/PhotonAnalyzer/");
00110 dbe_->removeElement("numberOfHistogramsInPhotonsFolder");
00111 dbe_->removeElement("numberOfHistogramsInConversionsFolder");
00112 dbe_->removeElement("numberOfHistogramsInEfficiencyFolder");
00113 dbe_->removeElement("numberOfHistogramsInInvMassFolder");
00114
00115
00116 string AllPath = "Egamma/PhotonAnalyzer/AllPhotons/";
00117 string IsoPath = "Egamma/PhotonAnalyzer/GoodCandidatePhotons/";
00118 string NonisoPath = "Egamma/PhotonAnalyzer/BackgroundPhotons/";
00119 string EffPath = "Egamma/PhotonAnalyzer/Efficiencies/";
00120
00121
00122
00123 dbe_->setCurrentFolder(EffPath);
00124
00125 p_efficiencyVsEtaLoose_ = bookHisto("EfficiencyVsEtaLoose","Fraction of Photons passing Loose Isolation vs #eta;#eta",etaBin,etaMin, etaMax);
00126 p_efficiencyVsEtLoose_ = bookHisto("EfficiencyVsEtLoose", "Fraction of Photons passing Loose Isolation vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00127 p_efficiencyVsEtaTight_ = bookHisto("EfficiencyVsEtaTight","Fraction of Photons passing Tight Isolation vs #eta;#eta",etaBin,etaMin, etaMax);
00128 p_efficiencyVsEtTight_ = bookHisto("EfficiencyVsEtTight", "Fraction of Photons passing Tight Isolation vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00129
00130
00131 p_efficiencyVsEtaHLT_ = bookHisto("EfficiencyVsEtaHLT","Fraction of Photons firing HLT vs #eta;#eta",etaBin,etaMin, etaMax);
00132 p_efficiencyVsEtHLT_ = bookHisto("EfficiencyVsEtHLT", "Fraction of Photons firing HLT vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00133
00134
00135 p_convFractionVsEtaLoose_ = bookHisto("ConvFractionVsEtaLoose","Fraction of Loosely Isolated Photons which are matched to two tracks vs #eta;#eta",etaBin,etaMin, etaMax);
00136 p_convFractionVsEtLoose_ = bookHisto("ConvFractionVsEtLoose", "Fraction of Loosely Isolated Photons which are matched to two tracks vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00137 p_convFractionVsEtaTight_ = bookHisto("ConvFractionVsEtaTight","Fraction of Tightly Isolated Photons which are matched to two tracks vs #eta;#eta",etaBin,etaMin, etaMax);
00138 p_convFractionVsEtTight_ = bookHisto("ConvFractionVsEtTight", "Fraction of Tightly Isolated Photons which are matched to two tracks vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00139
00140 p_vertexReconstructionEfficiencyVsEta_ = bookHisto("VertexReconstructionEfficiencyVsEta","Fraction of Converted Photons which have a valid vertex vs #eta;#eta",etaBin,etaMin, etaMax);
00141
00142
00143
00144 dbe_->setCurrentFolder(AllPath+"Et above 20 GeV/Conversions");
00145 p_convFractionVsEt_ = book2DHistoVector("1D","convFractionVsEt", "Fraction of Converted Photons vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00146 p_convFractionVsPhi_ = book3DHistoVector("1D","convFractionVsPhi","Fraction of Converted Photons vs #phi;#phi",phiBin,phiMin,phiMax);
00147 p_convFractionVsEta_ = book2DHistoVector("1D","convFractionVsEta","Fraction of Converted Photons vs #eta;#eta",etaBin,etaMin,etaMax);
00148
00149
00150
00151 dbe_->setCurrentFolder(AllPath+"Et above 20 GeV/");
00152 p_badChannelsFractionVsPhi_ = book2DHistoVector("1D","badChannelsFractionVsPhi","Fraction of Photons which have at least one bad channel vs #phi;#phi",phiBin,phiMin,phiMax);
00153 p_badChannelsFractionVsEta_ = book2DHistoVector("1D","badChannelsFractionVsEta","Fraction of Photons which have at least one bad channel vs #eta;#eta",etaBin,etaMin, etaMax);
00154 p_badChannelsFractionVsEt_ = book2DHistoVector("1D","badChannelsFractionVsEt", "Fraction of Photons which have at least one bad channel vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00155
00156
00157
00158
00159
00160 MonitorElement * dividend;
00161 MonitorElement * numerator;
00162 MonitorElement * denominator;
00163
00164 currentFolder_.str("");
00165 currentFolder_ << AllPath << "Et above 20 GeV/";
00166
00167
00168 dividend = retrieveHisto(EffPath,"EfficiencyVsEtaHLT");
00169 numerator = retrieveHisto(EffPath,"phoEtaPostHLT");
00170 denominator = retrieveHisto(EffPath,"phoEtaPreHLT");
00171 dividePlots(dividend,numerator,denominator);
00172
00173 dividend = retrieveHisto(EffPath,"EfficiencyVsEtHLT");
00174 numerator = retrieveHisto(EffPath,"phoEtPostHLT");
00175 denominator = retrieveHisto(EffPath,"phoEtPreHLT");
00176 dividePlots(dividend,numerator,denominator);
00177
00178
00179
00180 denominator = retrieveHisto(currentFolder_.str(),"phoEta");
00181
00182 dividend = retrieveHisto(EffPath,"EfficiencyVsEtaLoose");
00183 numerator = retrieveHisto(EffPath,"phoEtaLoose");
00184 dividePlots(dividend,numerator,denominator);
00185
00186 dividend = retrieveHisto(EffPath,"EfficiencyVsEtaTight");
00187 numerator = retrieveHisto(EffPath,"phoEtaTight");
00188 dividePlots(dividend,numerator,denominator);
00189
00190
00191
00192 denominator = retrieveHisto(currentFolder_.str(),"phoEtAllEcal");
00193
00194 dividend = retrieveHisto(EffPath,"EfficiencyVsEtLoose");
00195 numerator = retrieveHisto(EffPath,"phoEtLoose");
00196 dividePlots(dividend,numerator,denominator);
00197
00198 dividend = retrieveHisto(EffPath,"EfficiencyVsEtTight");
00199 numerator = retrieveHisto(EffPath,"phoEtTight");
00200 dividePlots(dividend,numerator,denominator);
00201
00202
00203
00204 dividend = retrieveHisto(EffPath,"ConvFractionVsEtaLoose");
00205 numerator = retrieveHisto(EffPath,"convEtaLoose");
00206 denominator = retrieveHisto(EffPath,"phoEtaLoose");
00207 dividePlots(dividend,numerator,denominator);
00208
00209 dividend = retrieveHisto(EffPath,"ConvFractionVsEtaTight");
00210 numerator = retrieveHisto(EffPath,"convEtaTight");
00211 denominator = retrieveHisto(EffPath,"phoEtaTight");
00212 dividePlots(dividend,numerator,denominator);
00213
00214
00215
00216 dividend = retrieveHisto(EffPath,"ConvFractionVsEtLoose");
00217 numerator = retrieveHisto(EffPath,"convEtLoose");
00218 denominator = retrieveHisto(EffPath,"phoEtLoose");
00219 dividePlots(dividend,numerator,denominator);
00220
00221 dividend = retrieveHisto(EffPath,"ConvFractionVsEtTight");
00222 numerator = retrieveHisto(EffPath,"convEtTight");
00223 denominator = retrieveHisto(EffPath,"phoEtTight");
00224 dividePlots(dividend,numerator,denominator);
00225
00226
00227
00228 dividend = retrieveHisto(EffPath,"VertexReconstructionEfficiencyVsEta");
00229 numerator = retrieveHisto(currentFolder_.str()+"Conversions/","phoConvEta");
00230 denominator = retrieveHisto(EffPath,"phoEtaVertex");
00231 dividePlots(dividend,numerator,denominator);
00232
00233
00234 dbe_->setCurrentFolder(EffPath);
00235
00236
00237 dbe_->removeElement("phoEtaPreHLT");
00238 dbe_->removeElement("phoEtPreHLT");
00239 dbe_->removeElement("phoEtaPostHLT");
00240 dbe_->removeElement("phoEtPostHLT");
00241 dbe_->removeElement("phoEtaLoose");
00242 dbe_->removeElement("phoEtaTight");
00243 dbe_->removeElement("phoEtLoose");
00244 dbe_->removeElement("phoEtTight");
00245 dbe_->removeElement("phoEtaVertex");
00246 dbe_->removeElement("convEtaLoose");
00247 dbe_->removeElement("convEtaTight");
00248 dbe_->removeElement("convEtLoose");
00249 dbe_->removeElement("convEtTight");
00250
00251
00252 for(uint type=0;type!=types_.size();++type){
00253
00254 for (int cut = 0; cut !=numberOfSteps_; ++cut) {
00255
00256 currentFolder_.str("");
00257 currentFolder_ << "Egamma/PhotonAnalyzer/" << types_[type] << "Photons/Et above " << (cut+1)*cutStep_ << " GeV/";
00258
00259
00260
00261
00262 dividend = retrieveHisto(currentFolder_.str(),"badChannelsFractionVsEt");
00263 numerator = retrieveHisto(currentFolder_.str(),"phoEtBadChannels");
00264 denominator = retrieveHisto(currentFolder_.str(),"phoEtAllEcal");
00265 dividePlots(dividend,numerator,denominator);
00266
00267
00268 dividend = retrieveHisto(currentFolder_.str(),"badChannelsFractionVsEta");
00269 numerator = retrieveHisto(currentFolder_.str(),"phoEtaBadChannels");
00270 denominator = retrieveHisto(currentFolder_.str(),"phoEta");
00271 dividePlots(dividend,numerator,denominator);
00272
00273
00274 dividend = retrieveHisto(currentFolder_.str(),"badChannelsFractionVsPhi");
00275 numerator = retrieveHisto(currentFolder_.str(),"phoPhiBadChannels");
00276 denominator = retrieveHisto(currentFolder_.str(),"phoPhiAllEcal");
00277 dividePlots(dividend,numerator,denominator);
00278
00279
00280
00281
00282 dividend = retrieveHisto(currentFolder_.str()+"Conversions/","convFractionVsEt");
00283 numerator = retrieveHisto(currentFolder_.str()+"Conversions/","phoConvEtAllEcal");
00284 denominator = retrieveHisto(currentFolder_.str(),"phoEtAllEcal");
00285 dividePlots(dividend,numerator,denominator);
00286
00287
00288 dividend = retrieveHisto(currentFolder_.str()+"Conversions/","convFractionVsEta");
00289 numerator = retrieveHisto(currentFolder_.str()+"Conversions/","phoConvEtaForEfficiency");
00290 denominator = retrieveHisto(currentFolder_.str(),"phoEta");
00291 dividePlots(dividend,numerator,denominator);
00292
00293
00294 dividend = retrieveHisto(currentFolder_.str()+"Conversions/","convFractionVsPhiAllEcal");
00295 numerator = retrieveHisto(currentFolder_.str()+"Conversions/","phoConvPhiForEfficiencyAllEcal");
00296 denominator = retrieveHisto(currentFolder_.str(),"phoPhiAllEcal");
00297 dividePlots(dividend,numerator,denominator);
00298 dividend = retrieveHisto(currentFolder_.str()+"Conversions/","convFractionVsPhiBarrel");
00299 numerator = retrieveHisto(currentFolder_.str()+"Conversions/","phoConvPhiForEfficiencyBarrel");
00300 denominator = retrieveHisto(currentFolder_.str(),"phoPhiBarrel");
00301 dividePlots(dividend,numerator,denominator);
00302 dividend = retrieveHisto(currentFolder_.str()+"Conversions/","convFractionVsPhiEndcaps");
00303 numerator = retrieveHisto(currentFolder_.str()+"Conversions/","phoConvPhiForEfficiencyEndcaps");
00304 denominator = retrieveHisto(currentFolder_.str(),"phoPhiEndcaps");
00305 dividePlots(dividend,numerator,denominator);
00306
00307
00308 dbe_->setCurrentFolder(currentFolder_.str()+"Conversions/");
00309 dbe_->removeElement("phoConvEtaForEfficiency");
00310 dbe_->removeElement("phoConvPhiForEfficiencyAllEcal");
00311 dbe_->removeElement("phoConvPhiForEfficiencyBarrel");
00312 dbe_->removeElement("phoConvPhiForEfficiencyEndcaps");
00313
00314 }
00315
00316
00317 }
00318
00319
00320 if(standAlone_) dbe_->save(outputFileName_);
00321 else if(batch_) dbe_->save(inputFileName_);
00322
00323
00324 }
00325
00326
00327
00328
00329 void PhotonOfflineClient::dividePlots(MonitorElement* dividend, MonitorElement* numerator, MonitorElement* denominator){
00330 double value,err;
00331
00332 if(denominator->getEntries()==0) return;
00333
00334 for (int j=1; j<=numerator->getNbinsX(); j++){
00335 if (denominator->getBinContent(j)!=0){
00336 value = ((double) numerator->getBinContent(j))/((double) denominator->getBinContent(j));
00337 err = sqrt( value*(1-value) / ((double) denominator->getBinContent(j)) );
00338 dividend->setBinContent(j, value);
00339 dividend->setBinError(j,err);
00340 }
00341 else {
00342 dividend->setBinContent(j, 0);
00343 dividend->setBinError(j,0);
00344 }
00345 dividend->setEntries(numerator->getEntries());
00346 }
00347 }
00348
00349
00350 void PhotonOfflineClient::dividePlots(MonitorElement* dividend, MonitorElement* numerator, double denominator){
00351 double value,err;
00352
00353 for (int j=1; j<=numerator->getNbinsX(); j++){
00354 if (denominator!=0){
00355 value = ((double) numerator->getBinContent(j))/denominator;
00356 err = sqrt( value*(1-value) / denominator);
00357 dividend->setBinContent(j, value);
00358 dividend->setBinError(j,err);
00359 }
00360 else {
00361 dividend->setBinContent(j, 0);
00362 }
00363 }
00364
00365 }
00366
00367 MonitorElement* PhotonOfflineClient::bookHisto(string histoName, string title, int bin, double min, double max)
00368 {
00369
00370 int histo_index = 0;
00371 stringstream histo_number_stream;
00372
00373
00374
00375 if(dbe_->pwd().find( "InvMass" ) != string::npos){
00376 histo_index_invMass_++;
00377 histo_index = histo_index_invMass_;
00378 }
00379 if(dbe_->pwd().find( "Efficiencies" ) != string::npos){
00380 histo_index_efficiency_++;
00381 histo_index = histo_index_efficiency_;
00382 }
00383 histo_number_stream << "h_";
00384 if(histo_index<10) histo_number_stream << "0";
00385 histo_number_stream << histo_index;
00386
00387 return dbe_->book1D(histo_number_stream.str()+"_"+histoName,title,bin,min,max);
00388
00389 }
00390
00391 vector<vector<MonitorElement*> > PhotonOfflineClient::book2DHistoVector(string histoType, string histoName, string title,
00392 int xbin, double xmin,double xmax,
00393 int ybin, double ymin, double ymax)
00394 {
00395 int histo_index = 0;
00396
00397 vector<MonitorElement*> temp1DVector;
00398 vector<vector<MonitorElement*> > temp2DVector;
00399
00400
00401 bool conversionPlot = false;
00402 if(dbe_->pwd().find( "Conversions" ) != string::npos) conversionPlot = true;
00403
00404
00405 if(conversionPlot){
00406 histo_index_conversions_++;
00407 histo_index = histo_index_conversions_;
00408 }
00409 else{
00410 histo_index_photons_++;
00411 histo_index = histo_index_photons_;
00412 }
00413
00414
00415 stringstream histo_number_stream;
00416 histo_number_stream << "h_";
00417 if(histo_index<10) histo_number_stream << "0";
00418 histo_number_stream << histo_index << "_";
00419
00420
00421 for(int cut = 0; cut != numberOfSteps_; ++cut){
00422
00423 for(uint type=0;type!=types_.size();++type){
00424
00425 currentFolder_.str("");
00426 currentFolder_ << "Egamma/PhotonAnalyzer/" << types_[type] << "Photons/Et above " << (cut+1)*cutStep_ << " GeV";
00427 if(conversionPlot) currentFolder_ << "/Conversions";
00428
00429 dbe_->setCurrentFolder(currentFolder_.str());
00430
00431 string kind;
00432 if(conversionPlot) kind = " Conversions: ";
00433 else kind = " Photons: ";
00434
00435 if(histoType=="1D") temp1DVector.push_back(dbe_->book1D(histo_number_stream.str()+histoName,types_[type]+kind+title,xbin,xmin,xmax));
00436 else if(histoType=="2D") temp1DVector.push_back(dbe_->book2D(histo_number_stream.str()+histoName,types_[type]+kind+title,xbin,xmin,xmax,ybin,ymin,ymax));
00437 else if(histoType=="Profile") temp1DVector.push_back(dbe_->bookProfile(histo_number_stream.str()+histoName,types_[type]+kind+title,xbin,xmin,xmax,ybin,ymin,ymax,""));
00438
00439 }
00440
00441 temp2DVector.push_back(temp1DVector);
00442 temp1DVector.clear();
00443 }
00444
00445 return temp2DVector;
00446
00447 }
00448
00449
00450
00451 vector<vector<vector<MonitorElement*> > > PhotonOfflineClient::book3DHistoVector(string histoType, string histoName, string title,
00452 int xbin, double xmin,double xmax,
00453 int ybin, double ymin, double ymax)
00454 {
00455 int histo_index = 0;
00456
00457 vector<MonitorElement*> temp1DVector;
00458 vector<vector<MonitorElement*> > temp2DVector;
00459 vector<vector<vector<MonitorElement*> > > temp3DVector;
00460
00461
00462
00463 bool conversionPlot = false;
00464 if(dbe_->pwd().find( "Conversions" ) != string::npos) conversionPlot = true;
00465
00466
00467 if(conversionPlot){
00468 histo_index_conversions_++;
00469 histo_index = histo_index_conversions_;
00470 }
00471 else{
00472 histo_index_photons_++;
00473 histo_index = histo_index_photons_;
00474 }
00475
00476 stringstream histo_number_stream;
00477 histo_number_stream << "h_";
00478 if(histo_index<10) histo_number_stream << "0";
00479 histo_number_stream << histo_index << "_";
00480
00481
00482 for(int cut = 0; cut != numberOfSteps_; ++cut){
00483
00484 for(uint type=0;type!=types_.size();++type){
00485
00486 for(uint part=0;part!=parts_.size();++part){
00487
00488 currentFolder_.str("");
00489 currentFolder_ << "Egamma/PhotonAnalyzer/" << types_[type] << "Photons/Et above " << (cut+1)*cutStep_ << " GeV";
00490 if(conversionPlot) currentFolder_ << "/Conversions";
00491
00492 dbe_->setCurrentFolder(currentFolder_.str());
00493
00494 string kind;
00495 if(conversionPlot) kind = " Conversions: ";
00496 else kind = " Photons: ";
00497
00498 if(histoType=="1D") temp1DVector.push_back(dbe_->book1D( histo_number_stream.str()+histoName+parts_[part],types_[type]+kind+parts_[part]+": "+title,xbin,xmin,xmax));
00499 else if(histoType=="2D") temp1DVector.push_back(dbe_->book2D( histo_number_stream.str()+histoName+parts_[part],types_[type]+kind+parts_[part]+": "+title,xbin,xmin,xmax,ybin,ymin,ymax));
00500 else if(histoType=="Profile") temp1DVector.push_back(dbe_->bookProfile( histo_number_stream.str()+histoName+parts_[part],types_[type]+kind+parts_[part]+": "+title,xbin,xmin,xmax,ybin,ymin,ymax,""));
00501
00502
00503
00504 }
00505
00506 temp2DVector.push_back(temp1DVector);
00507 temp1DVector.clear();
00508 }
00509
00510 temp3DVector.push_back(temp2DVector);
00511 temp2DVector.clear();
00512 }
00513
00514 return temp3DVector;
00515 }
00516
00517
00518 MonitorElement* PhotonOfflineClient::retrieveHisto(string dir, string name){
00519
00520
00521 vector<MonitorElement*> histoVector;
00522 uint indexOfRelevantHistogram=0;
00523 string fullMEName = "";
00524 histoVector = dbe_->getContents(dir);
00525 for(uint index=0;index!=histoVector.size();index++){
00526 string MEName = histoVector[index]->getName();
00527 if(MEName.find( name ) != string::npos){
00528 indexOfRelevantHistogram = index;
00529 break;
00530 }
00531 }
00532 return histoVector[indexOfRelevantHistogram];
00533 }
00534