00001 #include "DQM/L1TMonitorClient/interface/L1THcalClient.h"
00002 #include "FWCore/Framework/interface/ESHandle.h"
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include <FWCore/Framework/interface/ESHandle.h>
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "DQMServices/Core/interface/DQMStore.h"
00008 #include "DQMServices/Core/interface/MonitorElement.h"
00009 #include <iostream>
00010 #include <stdio.h>
00011 #include <string>
00012 #include <sstream>
00013 #include <math.h>
00014 #include <TROOT.h>
00015 #include <TStyle.h>
00016 #include <TH1F.h>
00017 #include <TH2F.h>
00018 #include <TF1.h>
00019 using namespace edm;
00020 using namespace std;
00021
00022
00023 const unsigned int RTPBINS = 101;
00024 const float RTPMIN = -0.5;
00025 const float RTPMAX = 100.5;
00026
00027 const unsigned int TPPHIBINS = 72;
00028 const float TPPHIMIN = 0.5;
00029 const float TPPHIMAX = 72.5;
00030
00031 const unsigned int TPETABINS = 65;
00032 const float TPETAMIN = -32.5;
00033 const float TPETAMAX = 32.5;
00034
00035 const unsigned int effBins = 50;
00036 const float effMinHBHE = -0.5;
00037 const float effMaxHBHE = 5.5;
00038 const float effMinHF = -0.5;
00039 const float effMaxHF = 2.5;
00040
00041 const unsigned int ratiobins = 100;
00042 const float ratiomin = 0.0;
00043 const float ratiomax = 1.0;
00044
00045 const unsigned int tvsrecbins = 100;
00046 const float tvsrecmin = 0.0;
00047 const float tvsrecmax = 100.0;
00048
00049 const unsigned int effcombo = 6472;
00050 const float effcombomin = -3272;
00051 const float effcombomax = 3272;
00052
00053 L1THcalClient::L1THcalClient(const edm::ParameterSet& iConfig)
00054 {
00055 minEventsforFit = iConfig.getUntrackedParameter<int>("minEventsforFit",1000);
00056 input_dir = "L1T/L1THCALTPGXAna/";
00057 output_dir = "L1T/L1THCALTPGXAna/Tests/";
00058
00059 dbe = edm::Service<DQMStore>().operator->();
00060
00061
00062
00063 LogInfo( "TriggerDQM");
00064 }
00065
00066
00067
00068 L1THcalClient::~L1THcalClient()
00069 {
00070
00071 LogInfo("TriggerDQM")<<"[TriggerDQM]: ending... ";
00072
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082 void L1THcalClient::beginJob(void)
00083 {
00084 LogInfo("TriggerDQM")<<"[TriggerDQM]: Begin Job";
00085
00086 nevents = 0;
00087 dbe->setCurrentFolder(output_dir);
00088
00089 hcalPlateau_ =
00090 dbe->book2D("FitPlateau","HCAL Fit Plateau",TPETABINS,TPETAMIN,TPETAMAX,
00091 TPPHIBINS,TPPHIMIN,TPPHIMAX);
00092 hcalThreshold_ =
00093 dbe->book2D("FitThreshold","HCAL Fit Threshold",TPETABINS,TPETAMIN,TPETAMAX,
00094 TPPHIBINS,TPPHIMIN,TPPHIMAX);
00095 hcalWidth_ =
00096 dbe->book2D("FitWidth","HCAL Fit Width",TPETABINS,TPETAMIN,TPETAMAX,
00097 TPPHIBINS,TPPHIMIN,TPPHIMAX);
00098 hcalEff_1_ =
00099 dbe->book1D("HcalEff1","HCAL Efficiency - 1",effBins,effMinHBHE,effMaxHBHE);
00100 hcalEff_2_ =
00101 dbe->book1D("HcalEff2","HCAL Efficiency - 2",effBins,effMinHBHE,effMaxHBHE);
00102 hcalEff_3_ =
00103 dbe->book1D("HcalEff3","HCAL Efficiency - 3",effBins,effMinHBHE,effMaxHBHE);
00104 hcalEff_4_ =
00105 dbe->book1D("HcalEff4","HCAL Efficiency - 4",effBins,effMinHF,effMaxHF);
00106
00107
00108
00109
00110 if (0){
00111
00112 for (int i=0; i < 56; i++)
00113 {
00114 char hname[20],htitle[20];
00115 char dirname[80];
00116 int ieta, iphi;
00117 if (i<28) ieta = i-28;
00118 else ieta = i-27;
00119 sprintf(dirname,"%sEffByChannel/EtaTower%d",output_dir.c_str(),ieta);
00120 dbe->setCurrentFolder(dirname);
00121 for (int j=0; j < 72; j++)
00122 {
00123 iphi = j+1;
00124 if (i<28) ieta = i-28;
00125 else ieta = i-27;
00126 sprintf(hname,"eff_%d_%d",ieta,iphi);
00127 sprintf(htitle,"Eff <%d,%d>",ieta,iphi);
00128 hcalEff_HBHE[i][j] = dbe->book1D(hname, htitle, effBins,effMinHBHE,effMaxHBHE);
00129 }
00130 }
00131
00132 for (int i=0; i < 8; i++)
00133 {
00134 char hname[20],htitle[20];
00135 char dirname[80];
00136 int ieta, iphi;
00137 if (i<4) ieta = i-32;
00138 else ieta = i+25;
00139 sprintf(dirname,"%sEffByChannel/EtaTower%d",output_dir.c_str(),ieta);
00140 dbe->setCurrentFolder(dirname);
00141 for (int j=0; j < 18; j++)
00142 {
00143 iphi = j*4+1;
00144 if (i<4) ieta = i-32;
00145 else ieta = i+25;
00146 sprintf(hname,"eff_%d_%d",ieta,iphi);
00147 sprintf(htitle,"Eff <%d,%d>",ieta,iphi);
00148 hcalEff_HF[i][j] = dbe->book1D(hname, htitle, effBins,effMinHF,effMaxHF);
00149 }
00150 }
00151 }
00152
00153 }
00154
00155
00156 void L1THcalClient::endJob() {
00157
00158 LogInfo("TriggerDQM")<<"[TriggerDQM]: endJob";
00159
00160 }
00161
00162 void
00163 L1THcalClient::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00164 {
00165 using namespace edm;
00166 nevents++;
00167 if (nevents%10 == 0) LogInfo("TriggerDQM")<<"[TriggerDQM]: event analyzed "<<nevents;
00168
00169
00170
00171
00172
00173 TF1 *turnon = new TF1("turnon","[0]*0.5*(TMath::Erf((x -[1])*0.5/[2])+1.)",0,30);
00174 TH1F *eff_histo;
00175
00176
00177
00178 TH1F *hcalEff_num = this->get1DHisto(input_dir+"HcalTP1",dbe);
00179 if (!hcalEff_num) std::cout << "numerator not found\n";
00180 TH1F *hcalEff_den = this->get1DHisto(input_dir+"HcalAll1",dbe);
00181 if (!hcalEff_den) std::cout << "denominator not found\n";
00182
00183
00184 calcEff(hcalEff_num, hcalEff_den, hcalEff_1_);
00185 if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
00186 {
00187 eff_histo = this->get1DHisto(output_dir+"HcalEff1",dbe);
00188 turnon->SetParameter(0,1);
00189 turnon->SetParameter(1,2);
00190 turnon->SetParameter(2,6);
00191 eff_histo->Fit("turnon","LL,E");
00192 }
00193 hcalEff_num = this->get1DHisto(input_dir+"HcalTP2",dbe);
00194 if (!hcalEff_num) std::cout << "numerator not found\n";
00195 hcalEff_den = this->get1DHisto(input_dir+"HcalAll2",dbe);
00196 if (!hcalEff_den) std::cout << "denominator not found\n";
00197
00198
00199 calcEff(hcalEff_num, hcalEff_den, hcalEff_2_);
00200 if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
00201 {
00202 eff_histo = this->get1DHisto(output_dir+"HcalEff2",dbe);
00203 turnon->SetParameter(0,1);
00204 turnon->SetParameter(1,2);
00205 turnon->SetParameter(2,6);
00206 eff_histo->Fit("turnon","LL,E");
00207 }
00208 hcalEff_num = this->get1DHisto(input_dir+"HcalTP3",dbe);
00209 if (!hcalEff_num) std::cout << "numerator not found\n";
00210 hcalEff_den = this->get1DHisto(input_dir+"HcalAll3",dbe);
00211 if (!hcalEff_den) std::cout << "denominator not found\n";
00212
00213
00214 calcEff(hcalEff_num, hcalEff_den, hcalEff_3_);
00215 if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
00216 {
00217 eff_histo = this->get1DHisto(output_dir+"HcalEff3",dbe);
00218 turnon->SetParameter(0,1);
00219 turnon->SetParameter(1,3);
00220 turnon->SetParameter(2,6);
00221 eff_histo->Fit("turnon","LL,E");
00222 }
00223 hcalEff_num = this->get1DHisto(input_dir+"HcalTP4",dbe);
00224 if (!hcalEff_num) std::cout << "numerator not found\n";
00225 hcalEff_den = this->get1DHisto(input_dir+"HcalAll4",dbe);
00226 if (!hcalEff_den) std::cout << "denominator not found\n";
00227
00228
00229 calcEff(hcalEff_num, hcalEff_den, hcalEff_4_);
00230 if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
00231 {
00232 eff_histo = this->get1DHisto(output_dir+"HcalEff4",dbe);
00233 turnon->SetParameter(0,1);
00234 turnon->SetParameter(1,1);
00235 turnon->SetParameter(2,6);
00236 eff_histo->Fit("turnon","LL,E");
00237 }
00238 double plateau, threshold, width;
00239
00240
00241 if (0){
00242
00243 for (int i=0; i < 56; i++)
00244 {
00245 char hname[20],htitle[30];
00246 int ieta, iphi;
00247 char subdirname[80];
00248 for (int j=0; j < 72; j++)
00249 {
00250 iphi = j+1;
00251 if (i<28) ieta = i-28;
00252 else ieta = i-27;
00253 sprintf(hname,"eff_%d_%d",ieta,iphi);
00254 sprintf(htitle,"Eff <%d,%d>",ieta,iphi);
00255
00256 sprintf(subdirname,"%sEffByChannel/EtaTower%d/",input_dir.c_str(),ieta);
00257 hcalEff_num = this->get1DHisto((string)subdirname+(string)hname+"_num",dbe);
00258 hcalEff_den = this->get1DHisto((string)subdirname+(string)hname+"_den",dbe);
00259 if (!hcalEff_num) std::cout <<(string)subdirname+(string)hname+"_num" << "numerator not found\n";
00260 if (!hcalEff_num) std::cout << "numerator not found\n";
00261 if (!hcalEff_den) std::cout << "denominator not found\n";
00262 calcEff(hcalEff_num, hcalEff_den, hcalEff_HBHE[i][j]);
00263
00264 if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
00265 {
00266 sprintf(subdirname,"%sEffByChannel/EtaTower%d/",output_dir.c_str(),ieta);
00267 eff_histo = this->get1DHisto((string)subdirname+(string)hname,dbe);
00268 turnon->SetParameter(0,1);
00269 turnon->SetParameter(1,3);
00270 turnon->SetParameter(2,6);
00271 eff_histo->Fit("turnon","LL,E");
00272 plateau = turnon->GetParameter(0);
00273 threshold = turnon->GetParameter(1);
00274 width = turnon->GetParameter(2);
00275 hcalPlateau_->Fill(ieta,iphi,plateau);
00276 hcalThreshold_->Fill(ieta,iphi,threshold);
00277 hcalWidth_->Fill(ieta,iphi,width);
00278 }
00279 }
00280 }
00281
00282 for (int i=0; i < 8; i++)
00283 {
00284 char hname[20],htitle[30];
00285 int ieta, iphi;
00286 char subdirname[80];
00287 for (int j=0; j < 18; j++)
00288 {
00289 iphi = j*4+1;
00290 if (i<4) ieta = i-32;
00291 else ieta = i+25;
00292 sprintf(hname,"eff_%d_%d",ieta,iphi);
00293 sprintf(htitle,"Eff <%d,%d>",ieta,iphi);
00294
00295 sprintf(subdirname,"%sEffByChannel/EtaTower%d/",input_dir.c_str(),ieta);
00296 hcalEff_num = this->get1DHisto((string)subdirname+(string)hname+"_num",dbe);
00297 hcalEff_den = this->get1DHisto((string)subdirname+(string)hname+"_den",dbe);
00298 if (!hcalEff_num) std::cout <<(string)subdirname+(string)hname+"_num" << "numerator not found\n";
00299 if (!hcalEff_den) std::cout << "denominator not found\n";
00300 calcEff(hcalEff_num, hcalEff_den, hcalEff_HF[i][j]);
00301 if (hcalEff_num->GetEntries() > minEventsforFit && nevents%1000 == 0)
00302 {
00303 sprintf(subdirname,"%sEffByChannel/EtaTower%d/",output_dir.c_str(),ieta);
00304 eff_histo = this->get1DHisto((string)subdirname+(string)hname,dbe);
00305 turnon->SetParameter(0,1);
00306 turnon->SetParameter(1,1);
00307 turnon->SetParameter(2,6);
00308 eff_histo->Fit("turnon","LL,E");
00309 plateau = turnon->GetParameter(0);
00310 threshold = turnon->GetParameter(1);
00311 width = turnon->GetParameter(2);
00312 hcalPlateau_->Fill(ieta,iphi,plateau);
00313 hcalThreshold_->Fill(ieta,iphi,threshold);
00314 hcalWidth_->Fill(ieta,iphi,width);
00315 }
00316 }
00317 }
00318 }
00319 }
00320
00321 void L1THcalClient::calcEff(TH1F *num, TH1F *den, MonitorElement* me)
00322 {
00323 if (num->GetNbinsX() != den->GetNbinsX())
00324 {
00325 std::cout << "numerator and denominator do not have the same number of bins!\n";
00326 return;
00327 }
00328 double eff;
00329 for (int bin = 0; bin <= num->GetNbinsX(); bin++)
00330 {
00331 if (den->GetBinContent(bin) != 0) eff = num->GetBinContent(bin)/den->GetBinContent(bin);
00332 else eff = 0;
00333 me->setBinContent(bin,eff);
00334 }
00335 }
00336
00337 TH1F * L1THcalClient::get1DHisto(string meName, DQMStore * dbi)
00338 {
00339
00340
00341
00342
00343 MonitorElement * me_ = dbi->get(meName);
00344
00345 TH1F * meHisto = NULL;
00346
00347 if (me_) {
00348
00349 meHisto = me_->getTH1F();
00350 }
00351 else {
00352
00353 LogInfo("TriggerDQM") << "ME " << meName << " NOT FOUND!";
00354
00355 }
00356
00357 return meHisto;
00358 }
00359
00360 TH2F * L1THcalClient::get2DHisto(string meName, DQMStore * dbi)
00361 {
00362
00363
00364
00365 MonitorElement * me_ = dbi->get(meName);
00366
00367 TH2F * meHisto = NULL;
00368
00369 if (me_) {
00370
00371 meHisto = me_->getTH2F();
00372 }
00373 else {
00374
00375 LogInfo("TriggerDQM") << "ME NOT FOUND.";
00376
00377 }
00378
00379 return meHisto;
00380 }
00381