00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DQMOffline/Trigger/interface/FourVectorHLTClient.h"
00011
00012 #include "DQMServices/Core/interface/QTest.h"
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 #include "DQMServices/Core/interface/QReport.h"
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 #include "DQMServices/Core/interface/MonitorElement.h"
00021 #include "TRandom.h"
00022 #include <TF1.h>
00023 #include <stdio.h>
00024 #include <sstream>
00025 #include <math.h>
00026 #include <TProfile.h>
00027 #include <TProfile2D.h>
00028 #include <memory>
00029 #include <iostream>
00030 #include <iomanip>
00031 #include <map>
00032 #include <vector>
00033 #include <string>
00034 #include <fstream>
00035 #include "TROOT.h"
00036
00037
00038 using namespace edm;
00039 using namespace std;
00040
00041 FourVectorHLTClient::FourVectorHLTClient(const edm::ParameterSet& ps)
00042 {
00043 parameters_=ps;
00044 initialize();
00045
00046 }
00047
00048 FourVectorHLTClient::~FourVectorHLTClient(){
00049 LogDebug("FourVectorHLTClient")<< "FourVectorHLTClient: ending...." ;
00050 }
00051
00052
00053 void FourVectorHLTClient::initialize(){
00054
00055 counterLS_=0;
00056 counterEvt_=0;
00057
00058
00059 dbe_ = Service<DQMStore>().operator->();
00060
00061
00062
00063 sourceDir_ = TString(parameters_.getUntrackedParameter<string>("hltSourceDir",""));
00064 LogDebug("FourVectorHLTClient")<< "Monitor dir = " << sourceDir_ << endl;
00065
00066 clientDir_ = TString(parameters_.getUntrackedParameter<string>("hltClientDir",""));
00067 LogDebug("FourVectorHLTClient")<< "Client dir = " << clientDir_ << endl;
00068
00069 prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00070 LogDebug("FourVectorHLTClient")<< "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00071
00072 prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00073 LogDebug("FourVectorHLTClient")<< "DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00074
00075
00076
00077 }
00078
00079
00080 void FourVectorHLTClient::beginJob(const EventSetup& context){
00081
00082
00083 LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient]: beginJob" << endl;
00084
00085 dbe_ = Service<DQMStore>().operator->();
00086
00087
00088
00089
00090
00091 }
00092
00093
00094 void FourVectorHLTClient::beginRun(const Run& r, const EventSetup& context) {
00095
00096 LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient]: beginRun" << endl;
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 }
00116
00117
00118 void FourVectorHLTClient::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00119
00120 }
00121
00122 void FourVectorHLTClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c){
00123
00124
00125 }
00126
00127
00128
00129
00130 void FourVectorHLTClient::analyze(const Event& e, const EventSetup& context){
00131
00132 counterEvt_++;
00133 if (prescaleEvt_<1) return;
00134 if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00135
00136 LogDebug("FourVectorHLTClient")<<"analyze..." << endl;
00137
00138
00139
00140
00141
00142
00143
00144 }
00145
00146
00147 void FourVectorHLTClient::endRun(const Run& r, const EventSetup& context){
00148 LogDebug("FourVectorHLTClient")<<"FourVectorHLTClient:: endLuminosityBlock " << endl;
00149
00150
00152 Comp2RefKolmogorov * kl_test_ = new Comp2RefKolmogorov("my_kolm");
00153
00154
00155 TObjArray *hltPathNameColl = new TObjArray(100);
00156 hltPathNameColl->SetOwner();
00157
00158 if(! dbe_->containsAnyMonitorable(sourceDir_.Data())) {
00159
00160 LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient] endLuminosityBlock: sourceDir_(" << sourceDir_.Data() << ") has no MEs " << endl;
00161 return;
00162 }
00163
00164 LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient] endLuminosityBlock: Interesting dir has MEs " << endl;
00165
00166 hltMEs = dbe_->getContents(sourceDir_.Data());
00167
00168
00169 for(unsigned int i=0;i<hltMEs.size();i++) {
00170
00171 if(hltMEs[i]->getName().find("HLT") == 0) hltMEName.push_back(TString(hltMEs[i]->getName()));
00172
00173 }
00174
00175
00177 LogDebug("FourVectorHLTClient")<<"[FourVectorHLTClient] HLT DQM MEs are: " << endl;
00178
00179 for(unsigned int i=0;i<hltMEName.size();i++) {
00180
00181 LogDebug("FourVectorHLTClient")<< hltMEName[i] << endl;
00182
00183
00185 TString tempName = hltMEName[i];
00186 tempName.Remove(tempName.Last('_'),tempName.Length());
00187 hltPathName.push_back(tempName);
00188
00189 TObjString *tempHltName = new TObjString(tempName.Data());
00190
00191 if( !hltPathNameColl->Contains(tempHltName)) {
00192
00193 hltPathNameColl->Add(tempHltName);
00194
00195 }
00196
00197 }
00198
00199 LogDebug("FourVectorHLTClient")<< "Number of derived HLT paths from DQM source directory: " << hltPathNameColl->GetEntriesFast() << endl;
00200
00202
00204 for (int j=0;j<hltPathNameColl->GetEntriesFast();j++) {
00205
00206
00207 TObjString *curHltPath = (TObjString*)hltPathNameColl->At(j);
00208 TString pathPrefis = curHltPath->String() + TString("_");
00209 LogDebug("FourVectorHLTClient")<< " path " << curHltPath->String() << endl;
00210
00211 TString pathFolder = clientDir_ + TString("/paths/") + curHltPath->String() + TString("/distributions");
00212
00213 dbe_->setCurrentFolder(pathFolder.Data());
00214
00216
00218 for(unsigned int i=0;i<hltMEName.size();i++) {
00219
00220 TString tempHistName = hltMEName[i];
00221
00222
00223 if( !tempHistName.Contains(curHltPath->String()) ) continue;
00224
00225
00226
00227
00228
00229
00230 TString radical = tempHistName;
00231 radical.ReplaceAll(curHltPath->String()+"_","");
00232 LogDebug("FourVectorHLTClient")<< " tempHistName is " << tempHistName << " radical is: " << radical << endl;
00233
00234 if(radical.CountChar('_')>0) continue;
00235
00236 TString histName = sourceDir_+TString("/")+tempHistName;
00237 TString klmgrvName = tempHistName+TString("_klmgrTest");
00238
00239
00240
00241
00242 MonitorElement *histME = dbe_->get(histName.Data());
00243
00244
00245
00246
00247
00248
00249
00250
00251 LogDebug("FourVectorHLTClient")<< " histME pathName:" << histME->getPathname() << ", kind: " << histME->kind() << " (TH1F=" << MonitorElement::DQM_KIND_TH1F << ")" << endl;
00252
00253 if(histME->kind() == MonitorElement::DQM_KIND_TH1F) {
00254
00255 TH1F *hist = new TH1F();
00256 hist = histME->getTH1F();
00257 dbe_->book1D(hist->GetName(),hist);
00258
00259
00260 if(hist->GetEntries() == 0) continue;
00261 if(hist->Integral() == 0) continue;
00262
00263 LogDebug("FourVectorHLTClient")<< "endRun: histName " << hist->GetName() << endl;
00264 LogDebug("FourVectorHLTClient")<< "endRun: hist entries:" << hist->GetEntries() << endl;
00265
00266 float kl_prob = kl_test_->runTest(histME);
00267
00268 LogDebug("FourVectorHLTClient")<< "endRun: KLMGRV test = " << kl_prob << endl;
00269
00270
00271
00272 }
00273
00274 if(histME->kind() == MonitorElement::DQM_KIND_TH2F) {
00275
00276 TH2F *hist = new TH2F();
00277 hist = histME->getTH2F();
00278 dbe_->book2D(hist->GetName(),hist);
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 }
00296
00297
00298
00299 }
00300
00302
00304 pathFolder = clientDir_ + TString("/paths/") + curHltPath->String() + TString("/efficiencies");
00305
00306 dbe_->setCurrentFolder(pathFolder.Data());
00307
00308 vector<TString> vObj;
00309 vObj.push_back(TString("phi"));
00310 vObj.push_back(TString("eta"));
00311
00312 for (unsigned int k=0; k<vObj.size();k++) {
00313
00314
00315 TString oldHistPathNum = sourceDir_+TString("/")+curHltPath->String()+TString("_")+vObj[k]+TString("On");
00316 TString oldHistPathDen = sourceDir_+TString("/")+curHltPath->String()+TString("_")+vObj[k]+TString("L1");
00317
00318
00319 TString newHistName = curHltPath->String()+TString("_"+vObj[k]+"_Eff-OnToL1");
00320 TString newHistPath = pathFolder+newHistName;
00321
00322 MonitorElement *numME = dbe_->get(oldHistPathNum.Data());
00323 MonitorElement *denME = dbe_->get(oldHistPathDen.Data());
00324
00325
00326 if ( numME && denME ) {
00327
00328
00329 if ( dbe_->get(newHistPath.Data()) ) {
00330 dbe_->removeElement(newHistPath.Data());
00331 }
00332
00333
00334 TH1F* numHist = numME->getTH1F();
00335 TH1F* denHist = denME->getTH1F();
00336
00337 TH1F* effHist = (TH1F*) numHist->Clone(newHistName.Data());
00338 effHist->SetTitle(newHistName.Data());
00339 effHist->Sumw2();
00340 effHist->Divide(denHist);
00341
00342
00343
00344
00345 dbe_->book1D(newHistName.Data(), effHist);
00346
00347 }
00348 else {
00349
00350 LogWarning("FourVectorHLTClient")<< "Cannot find NUM and DEN histograms to derive " << newHistName << "."<< endl;
00351
00352
00353 }
00354 }
00355
00356 }
00357
00358 hltPathNameColl->Delete();
00359 delete kl_test_;
00360
00361
00362 }
00363
00364
00365 void FourVectorHLTClient::endJob(){
00366 }
00367
00368
00369
00370 TH1F * FourVectorHLTClient::get1DHisto(string meName, DQMStore * dbi)
00371 {
00372
00373 MonitorElement * me_ = dbi->get(meName);
00374
00375 if (!me_) {
00376 LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00377 return NULL;
00378 }
00379
00380 return me_->getTH1F();
00381 }
00382
00383 TH2F * FourVectorHLTClient::get2DHisto(string meName, DQMStore * dbi)
00384 {
00385
00386
00387 MonitorElement * me_ = dbi->get(meName);
00388
00389 if (!me_) {
00390 LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00391 return NULL;
00392 }
00393
00394 return me_->getTH2F();
00395 }
00396
00397
00398
00399 TProfile2D * FourVectorHLTClient::get2DProfile(string meName, DQMStore * dbi)
00400 {
00401
00402
00403 MonitorElement * me_ = dbi->get(meName);
00404
00405 if (!me_) {
00406 LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00407 return NULL;
00408 }
00409
00410 return me_->getTProfile2D();
00411 }
00412
00413
00414 TProfile * FourVectorHLTClient::get1DProfile(string meName, DQMStore * dbi)
00415 {
00416
00417
00418 MonitorElement * me_ = dbi->get(meName);
00419
00420 if (!me_) {
00421 LogDebug("FourVectorHLTClient")<< "ME NOT FOUND." << endl;
00422 return NULL;
00423 }
00424
00425 return me_->getTProfile();
00426 }
00427
00428
00429
00430
00431
00432
00433
00434