00001 #include "DQMOffline/Trigger/interface/EgHLTOfflineSource.h"
00002
00003 #include "DQMOffline/Trigger/interface/EgHLTEleHLTFilterMon.h"
00004 #include "DQMOffline/Trigger/interface/EgHLTPhoHLTFilterMon.h"
00005
00006 #include "DQMOffline/Trigger/interface/EgHLTDebugFuncs.h"
00007 #include "DQMOffline/Trigger/interface/EgHLTDQMCut.h"
00008 #include "DQMOffline/Trigger/interface/EgHLTMonElemFuncs.h"
00009 #include "DQMOffline/Trigger/interface/EgHLTTrigTools.h"
00010
00011 #include "DQMServices/Core/interface/MonitorElement.h"
00012
00013 #include "FWCore/Framework/interface/Run.h"
00014 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00015
00016 #include <boost/algorithm/string.hpp>
00017
00018
00019 #include "DataFormats/TrackReco/interface/Track.h"
00020 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00021 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00022 using namespace egHLT;
00023
00024 EgHLTOfflineSource::EgHLTOfflineSource(const edm::ParameterSet& iConfig):
00025 nrEventsProcessed_(0),isSetup_(false)
00026 {
00027 dbe_ = edm::Service<DQMStore>().operator->();
00028 if (!dbe_) {
00029
00030 edm::LogInfo("EgHLTOfflineSource") << "unable to get DQMStore service?";
00031 }
00032 if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00033 dbe_->setVerbose(0);
00034 }
00035
00036
00037 binData_.setup(iConfig.getParameter<edm::ParameterSet>("binData"));
00038 cutMasks_.setup(iConfig.getParameter<edm::ParameterSet>("cutMasks"));
00039 eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
00040 phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
00041 eleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("eleTightLooseTrigNames");
00042 diEleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diEleTightLooseTrigNames");
00043 phoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("phoTightLooseTrigNames");
00044 diPhoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diPhoTightLooseTrigNames");
00045
00046 filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers");
00047 hltTag_ = iConfig.getParameter<std::string>("hltTag");
00048
00049
00050 dirName_=iConfig.getParameter<std::string>("DQMDirName");
00051
00052
00053 offEvtHelper_.setup(iConfig);
00054
00055 }
00056
00057
00058 EgHLTOfflineSource::~EgHLTOfflineSource()
00059 {
00060
00061 for(size_t i=0;i<eleFilterMonHists_.size();i++){
00062 delete eleFilterMonHists_[i];
00063 }
00064 for(size_t i=0;i<phoFilterMonHists_.size();i++){
00065 delete phoFilterMonHists_[i];
00066 }
00067 for(size_t i=0;i<eleMonElems_.size();i++){
00068 delete eleMonElems_[i];
00069 }
00070 for(size_t i=0;i<phoMonElems_.size();i++){
00071 delete phoMonElems_[i];
00072 }
00073 }
00074
00075 void EgHLTOfflineSource::beginJob()
00076 {
00077 if(dbe_) {
00078 dbe_->setCurrentFolder(dirName_);
00079
00080 dqmErrsMonElem_ =dbe_->book1D("dqmErrors","EgHLTOfflineSource Errors",101,-0.5,100.5);
00081 nrEventsProcessedMonElem_ = dbe_->bookInt("nrEventsProcessed");
00082 }
00083 }
00084
00085 void EgHLTOfflineSource::endJob()
00086 {
00087
00088 }
00089
00090
00091
00092
00093
00094 void EgHLTOfflineSource::beginRun(const edm::Run& run, const edm::EventSetup& c)
00095 {
00096 if(dbe_ && !isSetup_){
00097
00098 HLTConfigProvider hltConfig;
00099 bool changed=false;
00100 hltConfig.init(run,c,hltTag_,changed);
00101 if(filterInactiveTriggers_) filterTriggers(hltConfig);
00102
00103 std::vector<std::string> hltFiltersUsed;
00104 getHLTFilterNamesUsed(hltFiltersUsed);
00105 TrigCodes::setCodes(hltFiltersUsed);
00106
00107 offEvtHelper_.setupTriggers(hltConfig,hltFiltersUsed);
00108
00109
00110 dbe_->setCurrentFolder(dirName_);
00111
00112 for(size_t i=0;i<eleHLTFilterNames_.size();i++) addEleTrigPath(eleHLTFilterNames_[i]);
00113 for(size_t i=0;i<phoHLTFilterNames_.size();i++) addPhoTrigPath(phoHLTFilterNames_[i]);
00114
00115
00116 MonElemFuncs::initTightLooseTrigHists(eleMonElems_,eleTightLooseTrigNames_,binData_,"gsfEle");
00118 MonElemFuncs::initTightLooseTrigHistsTrigCuts(eleMonElems_,eleTightLooseTrigNames_,binData_);
00119
00120
00121 MonElemFuncs::initTightLooseTrigHists(phoMonElems_,phoTightLooseTrigNames_,binData_,"pho");
00122
00123 MonElemFuncs::initTightLooseTrigHistsTrigCuts(phoMonElems_,phoTightLooseTrigNames_,binData_);
00124
00125
00126 MonElemFuncs::initTightLooseTrigHists(eleMonElems_,diEleTightLooseTrigNames_,binData_,"gsfEle");
00127
00128 MonElemFuncs::initTightLooseTrigHists(phoMonElems_,diPhoTightLooseTrigNames_,binData_,"pho");
00129
00130
00131 MonElemFuncs::initTightLooseDiObjTrigHistsTrigCuts(eleMonElems_,diEleTightLooseTrigNames_,binData_);
00132 MonElemFuncs::initTightLooseDiObjTrigHistsTrigCuts(phoMonElems_,diPhoTightLooseTrigNames_,binData_);
00133
00134
00135
00136
00137
00138 MonElemFuncs::initTrigTagProbeHists(eleMonElems_,eleHLTFilterNames_,cutMasks_.trigTPEle,binData_);
00139
00140
00141
00142
00143 isSetup_=true;
00144
00145 }
00146 }
00147
00148
00149 void EgHLTOfflineSource::endRun(const edm::Run& run, const edm::EventSetup& c)
00150 {
00151
00152 }
00153
00154
00155 void EgHLTOfflineSource::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00156 {
00157
00158
00159
00160
00161 if(!dbe_) return;
00162
00163
00164
00165
00166
00167 const double weight=1.;
00168 nrEventsProcessed_++;
00169 nrEventsProcessedMonElem_->Fill(nrEventsProcessed_);
00170 int errCode = offEvtHelper_.makeOffEvt(iEvent,iSetup,offEvt_);
00171 if(errCode!=0){
00172 dqmErrsMonElem_->Fill(errCode);
00173 return;
00174 }
00175
00176
00177 for(size_t pathNr=0;pathNr<eleFilterMonHists_.size();pathNr++){
00178 eleFilterMonHists_[pathNr]->fill(offEvt_,weight);
00179 }
00180 for(size_t pathNr=0;pathNr<phoFilterMonHists_.size();pathNr++){
00181 phoFilterMonHists_[pathNr]->fill(offEvt_,weight);
00182 }
00183
00184 for(size_t monElemNr=0;monElemNr<eleMonElems_.size();monElemNr++){
00185 const std::vector<OffEle>& eles = offEvt_.eles();
00186 for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00187 eleMonElems_[monElemNr]->fill(eles[eleNr],offEvt_,weight);
00188 }
00189 }
00190
00191 for(size_t monElemNr=0;monElemNr<phoMonElems_.size();monElemNr++){
00192 const std::vector<OffPho>& phos = offEvt_.phos();
00193 for(size_t phoNr=0;phoNr<phos.size();phoNr++){
00194 phoMonElems_[monElemNr]->fill(phos[phoNr],offEvt_,weight);
00195 }
00196 }
00197 }
00198
00199
00200 void EgHLTOfflineSource::addEleTrigPath(const std::string& name)
00201 {
00202 EleHLTFilterMon* filterMon = new EleHLTFilterMon(name,TrigCodes::getCode(name.c_str()),binData_,cutMasks_);
00203 eleFilterMonHists_.push_back(filterMon);
00204 std::sort(eleFilterMonHists_.begin(),eleFilterMonHists_.end(),EleHLTFilterMon::ptrLess<EleHLTFilterMon>());
00205 }
00206
00207 void EgHLTOfflineSource::addPhoTrigPath(const std::string& name)
00208 {
00209 PhoHLTFilterMon* filterMon = new PhoHLTFilterMon(name,TrigCodes::getCode(name.c_str()),binData_,cutMasks_);
00210 phoFilterMonHists_.push_back(filterMon);
00211 std::sort(phoFilterMonHists_.begin(),phoFilterMonHists_.end(),PhoHLTFilterMon::ptrLess<PhoHLTFilterMon>());
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221 void EgHLTOfflineSource::getHLTFilterNamesUsed(std::vector<std::string>& filterNames)const
00222 {
00223 std::set<std::string> filterNameSet;
00224 for(size_t i=0;i<eleHLTFilterNames_.size();i++) filterNameSet.insert(eleHLTFilterNames_[i]);
00225 for(size_t i=0;i<phoHLTFilterNames_.size();i++) filterNameSet.insert(phoHLTFilterNames_[i]);
00226
00227
00228 for(size_t tightLooseNr=0;tightLooseNr<eleTightLooseTrigNames_.size();tightLooseNr++){
00229 std::vector<std::string> trigNames;
00230 boost::split(trigNames,eleTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00231 if(trigNames.size()!=2) continue;
00232 filterNameSet.insert(trigNames[0]);
00233 filterNameSet.insert(trigNames[1]);
00234 }
00235 for(size_t tightLooseNr=0;tightLooseNr<diEleTightLooseTrigNames_.size();tightLooseNr++){
00236 std::vector<std::string> trigNames;
00237 boost::split(trigNames,diEleTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00238 if(trigNames.size()!=2) continue;
00239 filterNameSet.insert(trigNames[0]);
00240 filterNameSet.insert(trigNames[1]);
00241 }
00242 for(size_t tightLooseNr=0;tightLooseNr<phoTightLooseTrigNames_.size();tightLooseNr++){
00243 std::vector<std::string> trigNames;
00244 boost::split(trigNames,phoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00245 if(trigNames.size()!=2) continue;
00246 filterNameSet.insert(trigNames[0]);
00247 filterNameSet.insert(trigNames[1]);
00248 }
00249 for(size_t tightLooseNr=0;tightLooseNr<diPhoTightLooseTrigNames_.size();tightLooseNr++){
00250 std::vector<std::string> trigNames;
00251 boost::split(trigNames,diPhoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00252 if(trigNames.size()!=2) continue;
00253 filterNameSet.insert(trigNames[0]);
00254 filterNameSet.insert(trigNames[1]);
00255 }
00256
00257
00258 std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
00259 }
00260
00261 void EgHLTOfflineSource::filterTriggers(const HLTConfigProvider& hltConfig)
00262 {
00263
00264 std::vector<std::string> activeFilters;
00265
00266 trigTools::getActiveFilters(hltConfig,activeFilters);
00267
00268 trigTools::filterInactiveTriggers(eleHLTFilterNames_,activeFilters);
00269 trigTools::filterInactiveTriggers(phoHLTFilterNames_,activeFilters);
00270 trigTools::filterInactiveTightLooseTriggers(eleTightLooseTrigNames_,activeFilters);
00271 trigTools::filterInactiveTightLooseTriggers(diEleTightLooseTrigNames_,activeFilters);
00272 trigTools::filterInactiveTightLooseTriggers(phoTightLooseTrigNames_,activeFilters);
00273 trigTools::filterInactiveTightLooseTriggers(diPhoTightLooseTrigNames_,activeFilters);
00274 }