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
00050 outputFileName_ = pset.getParameter<string>("OutputFileName");
00051 inputFileName_ = pset.getUntrackedParameter<string>("InputFileName");
00052
00053 histo_index_photons_ = 0;
00054 histo_index_conversions_ = 0;
00055 histo_index_efficiency_ = 0;
00056 histo_index_invMass_ = 0;
00057
00058 types_.push_back("All");
00059 types_.push_back("GoodCandidate");
00060 types_.push_back("Background");
00061
00062 parts_.push_back("AllEcal");
00063 parts_.push_back("Barrel");
00064 parts_.push_back("Endcaps");
00065
00066 }
00067
00068 PhotonOfflineClient::~PhotonOfflineClient()
00069 {}
00070 void PhotonOfflineClient::beginJob()
00071 {}
00072 void PhotonOfflineClient::analyze(const edm::Event& e, const edm::EventSetup& esup)
00073 {}
00074 void PhotonOfflineClient::endLuminosityBlock( const edm::LuminosityBlock& , const edm::EventSetup& setup)
00075 {}
00076
00077
00078
00079 void PhotonOfflineClient::endJob()
00080 {
00081 if(standAlone_) runClient();
00082 }
00083 void PhotonOfflineClient::endRun(const edm::Run& run, const edm::EventSetup& setup)
00084 {
00085 if(!standAlone_) runClient();
00086 }
00087
00088
00089
00090
00091 void PhotonOfflineClient::runClient()
00092 {
00093 if(!dbe_) return;
00094
00095 if(batch_) dbe_->open(inputFileName_);
00096
00097 if(!dbe_->dirExists("Egamma/PhotonAnalyzer")){
00098
00099 return;
00100 }
00101
00102
00103 histo_index_photons_ = dbe_->get("Egamma/PhotonAnalyzer/numberOfHistogramsInPhotonsFolder")->getIntValue();
00104 histo_index_conversions_ = dbe_->get("Egamma/PhotonAnalyzer/numberOfHistogramsInConversionsFolder")->getIntValue();
00105 histo_index_efficiency_ = dbe_->get("Egamma/PhotonAnalyzer/numberOfHistogramsInEfficiencyFolder")->getIntValue();
00106 histo_index_invMass_ = dbe_->get("Egamma/PhotonAnalyzer/numberOfHistogramsInInvMassFolder")->getIntValue();
00107
00108 dbe_->setCurrentFolder("Egamma/PhotonAnalyzer/");
00109 dbe_->removeElement("numberOfHistogramsInPhotonsFolder");
00110 dbe_->removeElement("numberOfHistogramsInConversionsFolder");
00111 dbe_->removeElement("numberOfHistogramsInEfficiencyFolder");
00112 dbe_->removeElement("numberOfHistogramsInInvMassFolder");
00113
00114
00115 string AllPath = "Egamma/PhotonAnalyzer/AllPhotons/";
00116 string IsoPath = "Egamma/PhotonAnalyzer/GoodCandidatePhotons/";
00117 string NonisoPath = "Egamma/PhotonAnalyzer/BackgroundPhotons/";
00118 string EffPath = "Egamma/PhotonAnalyzer/Efficiencies/";
00119
00120
00121
00122 dbe_->setCurrentFolder(EffPath);
00123
00124 p_efficiencyVsEtaLoose_ = bookHisto("EfficiencyVsEtaLoose","Fraction of Photons passing Loose Isolation vs #eta;#eta",etaBin,etaMin, etaMax);
00125 p_efficiencyVsEtLoose_ = bookHisto("EfficiencyVsEtLoose", "Fraction of Photons passing Loose Isolation vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00126 p_efficiencyVsEtaTight_ = bookHisto("EfficiencyVsEtaTight","Fraction of Photons passing Tight Isolation vs #eta;#eta",etaBin,etaMin, etaMax);
00127 p_efficiencyVsEtTight_ = bookHisto("EfficiencyVsEtTight", "Fraction of Photons passing Tight Isolation vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00128
00129
00130 p_efficiencyVsEtaHLT_ = bookHisto("EfficiencyVsEtaHLT","Fraction of Photons firing HLT vs #eta;#eta",etaBin,etaMin, etaMax);
00131 p_efficiencyVsEtHLT_ = bookHisto("EfficiencyVsEtHLT", "Fraction of Photons firing HLT vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00132
00133
00134 p_convFractionVsEtaLoose_ = bookHisto("ConvFractionVsEtaLoose","Fraction of Loosely Isolated Photons which are matched to two tracks vs #eta;#eta",etaBin,etaMin, etaMax);
00135 p_convFractionVsEtLoose_ = bookHisto("ConvFractionVsEtLoose", "Fraction of Loosely Isolated Photons which are matched to two tracks vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00136 p_convFractionVsEtaTight_ = bookHisto("ConvFractionVsEtaTight","Fraction of Tightly Isolated Photons which are matched to two tracks vs #eta;#eta",etaBin,etaMin, etaMax);
00137 p_convFractionVsEtTight_ = bookHisto("ConvFractionVsEtTight", "Fraction of Tightly Isolated Photons which are matched to two tracks vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00138
00139 p_vertexReconstructionEfficiencyVsEta_ = bookHisto("VertexReconstructionEfficiencyVsEta","Fraction of Converted Photons which have a valid vertex vs #eta;#eta",etaBin,etaMin, etaMax);
00140
00141
00142
00143 dbe_->setCurrentFolder(AllPath+"Et above 20 GeV/Conversions");
00144 p_convFractionVsEt_ = book2DHistoVector("1D","convFractionVsEt", "Fraction of Converted Photons vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00145 p_convFractionVsPhi_ = book3DHistoVector("1D","convFractionVsPhi","Fraction of Converted Photons vs #phi;#phi",phiBin,phiMin,phiMax);
00146 p_convFractionVsEta_ = book2DHistoVector("1D","convFractionVsEta","Fraction of Converted Photons vs #eta;#eta",etaBin,etaMin,etaMax);
00147
00148
00149
00150 dbe_->setCurrentFolder(AllPath+"Et above 20 GeV/");
00151 p_badChannelsFractionVsPhi_ = book2DHistoVector("1D","badChannelsFractionVsPhi","Fraction of Photons which have at least one bad channel vs #phi;#phi",phiBin,phiMin,phiMax);
00152 p_badChannelsFractionVsEta_ = book2DHistoVector("1D","badChannelsFractionVsEta","Fraction of Photons which have at least one bad channel vs #eta;#eta",etaBin,etaMin, etaMax);
00153 p_badChannelsFractionVsEt_ = book2DHistoVector("1D","badChannelsFractionVsEt", "Fraction of Photons which have at least one bad channel vs E_{T};E_{T} (GeV)",etBin,etMin,etMax);
00154
00155
00156
00157
00158
00159 MonitorElement * dividend;
00160 MonitorElement * numerator;
00161 MonitorElement * denominator;
00162
00163 currentFolder_.str("");
00164 currentFolder_ << AllPath << "Et above 20 GeV/";
00165
00166
00167 dividend = retrieveHisto(EffPath,"EfficiencyVsEtaHLT");
00168 numerator = retrieveHisto(EffPath,"phoEtaPostHLT");
00169 denominator = retrieveHisto(EffPath,"phoEtaPreHLT");
00170 dividePlots(dividend,numerator,denominator);
00171
00172 dividend = retrieveHisto(EffPath,"EfficiencyVsEtHLT");
00173 numerator = retrieveHisto(EffPath,"phoEtPostHLT");
00174 denominator = retrieveHisto(EffPath,"phoEtPreHLT");
00175 dividePlots(dividend,numerator,denominator);
00176
00177
00178
00179 denominator = retrieveHisto(currentFolder_.str(),"phoEta");
00180
00181 dividend = retrieveHisto(EffPath,"EfficiencyVsEtaLoose");
00182 numerator = retrieveHisto(EffPath,"phoEtaLoose");
00183 dividePlots(dividend,numerator,denominator);
00184
00185 dividend = retrieveHisto(EffPath,"EfficiencyVsEtaTight");
00186 numerator = retrieveHisto(EffPath,"phoEtaTight");
00187 dividePlots(dividend,numerator,denominator);
00188
00189
00190
00191 denominator = retrieveHisto(currentFolder_.str(),"phoEtAllEcal");
00192
00193 dividend = retrieveHisto(EffPath,"EfficiencyVsEtLoose");
00194 numerator = retrieveHisto(EffPath,"phoEtLoose");
00195 dividePlots(dividend,numerator,denominator);
00196
00197 dividend = retrieveHisto(EffPath,"EfficiencyVsEtTight");
00198 numerator = retrieveHisto(EffPath,"phoEtTight");
00199 dividePlots(dividend,numerator,denominator);
00200
00201
00202
00203 dividend = retrieveHisto(EffPath,"ConvFractionVsEtaLoose");
00204 numerator = retrieveHisto(EffPath,"convEtaLoose");
00205 denominator = retrieveHisto(EffPath,"phoEtaLoose");
00206 dividePlots(dividend,numerator,denominator);
00207
00208 dividend = retrieveHisto(EffPath,"ConvFractionVsEtaTight");
00209 numerator = retrieveHisto(EffPath,"convEtaTight");
00210 denominator = retrieveHisto(EffPath,"phoEtaTight");
00211 dividePlots(dividend,numerator,denominator);
00212
00213
00214
00215 dividend = retrieveHisto(EffPath,"ConvFractionVsEtLoose");
00216 numerator = retrieveHisto(EffPath,"convEtLoose");
00217 denominator = retrieveHisto(EffPath,"phoEtLoose");
00218 dividePlots(dividend,numerator,denominator);
00219
00220 dividend = retrieveHisto(EffPath,"ConvFractionVsEtTight");
00221 numerator = retrieveHisto(EffPath,"convEtTight");
00222 denominator = retrieveHisto(EffPath,"phoEtTight");
00223 dividePlots(dividend,numerator,denominator);
00224
00225
00226
00227 dividend = retrieveHisto(EffPath,"VertexReconstructionEfficiencyVsEta");
00228 numerator = retrieveHisto(currentFolder_.str()+"Conversions/","phoConvEta");
00229 denominator = retrieveHisto(EffPath,"phoEtaVertex");
00230 dividePlots(dividend,numerator,denominator);
00231
00232
00233 dbe_->setCurrentFolder(EffPath);
00234
00235
00236 dbe_->removeElement("phoEtaPreHLT");
00237 dbe_->removeElement("phoEtPreHLT");
00238 dbe_->removeElement("phoEtaPostHLT");
00239 dbe_->removeElement("phoEtPostHLT");
00240 dbe_->removeElement("phoEtaLoose");
00241 dbe_->removeElement("phoEtaTight");
00242 dbe_->removeElement("phoEtLoose");
00243 dbe_->removeElement("phoEtTight");
00244 dbe_->removeElement("phoEtaVertex");
00245 dbe_->removeElement("convEtaLoose");
00246 dbe_->removeElement("convEtaTight");
00247 dbe_->removeElement("convEtLoose");
00248 dbe_->removeElement("convEtTight");
00249
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