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 eleHLTFilterNames2Leg_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames2Leg");
00041 phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
00042 eleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("eleTightLooseTrigNames");
00043 diEleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diEleTightLooseTrigNames");
00044 phoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("phoTightLooseTrigNames");
00045 diPhoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diPhoTightLooseTrigNames");
00046
00047 filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers");
00048 hltTag_ = iConfig.getParameter<std::string>("hltTag");
00049
00050
00051 dirName_=iConfig.getParameter<std::string>("DQMDirName");
00052
00053
00054 offEvtHelper_.setup(iConfig);
00055
00056 }
00057
00058
00059 EgHLTOfflineSource::~EgHLTOfflineSource()
00060 {
00061
00062 for(size_t i=0;i<eleFilterMonHists_.size();i++){
00063 delete eleFilterMonHists_[i];
00064 }
00065 for(size_t i=0;i<phoFilterMonHists_.size();i++){
00066 delete phoFilterMonHists_[i];
00067 }
00068 for(size_t i=0;i<eleMonElems_.size();i++){
00069 delete eleMonElems_[i];
00070 }
00071 for(size_t i=0;i<phoMonElems_.size();i++){
00072 delete phoMonElems_[i];
00073 }
00074 }
00075
00076 void EgHLTOfflineSource::beginJob()
00077 {
00078 if(dbe_) {
00079 dbe_->setCurrentFolder(dirName_);
00080
00081 dqmErrsMonElem_ =dbe_->book1D("dqmErrors","EgHLTOfflineSource Errors",101,-0.5,100.5);
00082 nrEventsProcessedMonElem_ = dbe_->bookInt("nrEventsProcessed");
00083 }
00084 }
00085
00086 void EgHLTOfflineSource::endJob()
00087 {
00088
00089 }
00090
00091
00092
00093
00094
00095 void EgHLTOfflineSource::beginRun(const edm::Run& run, const edm::EventSetup& c)
00096 {
00097 if(dbe_ && !isSetup_){
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_+"/Source_Histos");
00111
00112 for(size_t i=0;i<eleHLTFilterNames_.size();i++){dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames_[i]); addEleTrigPath(eleHLTFilterNames_[i]);}
00113 for(size_t i=0;i<phoHLTFilterNames_.size();i++){dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+phoHLTFilterNames_[i]); addPhoTrigPath(phoHLTFilterNames_[i]);}
00114
00115 MonElemFuncs::initTightLooseTrigHists(eleMonElems_,eleTightLooseTrigNames_,binData_,"gsfEle");
00116
00117
00118
00119
00120 MonElemFuncs::initTightLooseTrigHists(phoMonElems_,phoTightLooseTrigNames_,binData_,"pho");
00121
00122
00123
00124
00125 MonElemFuncs::initTightLooseTrigHists(eleMonElems_,diEleTightLooseTrigNames_,binData_,"gsfEle");
00126
00127 MonElemFuncs::initTightLooseTrigHists(phoMonElems_,diPhoTightLooseTrigNames_,binData_,"pho");
00128
00129
00130 MonElemFuncs::initTightLooseDiObjTrigHistsTrigCuts(eleMonElems_,diEleTightLooseTrigNames_,binData_);
00131 MonElemFuncs::initTightLooseDiObjTrigHistsTrigCuts(phoMonElems_,diPhoTightLooseTrigNames_,binData_);
00132
00133
00134
00135
00136
00137 bool doTrigTagProbeEff=false;
00138 if(doTrigTagProbeEff){
00139 for(size_t i=0;i<eleHLTFilterNames_.size();i++){
00140 dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames_[i]);
00141 MonElemFuncs::initTrigTagProbeHist(eleMonElems_,eleHLTFilterNames_[i],cutMasks_.trigTPEle,binData_);
00142 }
00143 for(size_t i=0;i<phoHLTFilterNames_.size();i++){
00144 dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+phoHLTFilterNames_[i]);
00145 MonElemFuncs::initTrigTagProbeHist(phoMonElems_,phoHLTFilterNames_[i],cutMasks_.trigTPPho,binData_);
00146 }
00147 for(size_t i=0;i<eleHLTFilterNames2Leg_.size();i++){
00148 dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames2Leg_[i].substr(eleHLTFilterNames2Leg_[i].find("::")+2));
00149
00150
00151 MonElemFuncs::initTrigTagProbeHist_2Leg(eleMonElems_,eleHLTFilterNames2Leg_[i],cutMasks_.trigTPEle,binData_);
00152 }
00153
00154
00155 }
00156 isSetup_=true;
00157
00158 dbe_->setCurrentFolder(dirName_);
00159 }
00160 }
00161
00162
00163 void EgHLTOfflineSource::endRun(const edm::Run& run, const edm::EventSetup& c)
00164 {
00165
00166 }
00167
00168
00169 void EgHLTOfflineSource::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00170 {
00171
00172
00173
00174
00175 if(!dbe_) return;
00176
00177
00178
00179
00180
00181 const double weight=1.;
00182 nrEventsProcessed_++;
00183 nrEventsProcessedMonElem_->Fill(nrEventsProcessed_);
00184 int errCode = offEvtHelper_.makeOffEvt(iEvent,iSetup,offEvt_);
00185 if(errCode!=0){
00186 dqmErrsMonElem_->Fill(errCode);
00187 return;
00188 }
00189
00190
00191 for(size_t pathNr=0;pathNr<eleFilterMonHists_.size();pathNr++){
00192 eleFilterMonHists_[pathNr]->fill(offEvt_,weight);
00193 }
00194 for(size_t pathNr=0;pathNr<phoFilterMonHists_.size();pathNr++){
00195 phoFilterMonHists_[pathNr]->fill(offEvt_,weight);
00196 }
00197
00198 for(size_t monElemNr=0;monElemNr<eleMonElems_.size();monElemNr++){
00199 const std::vector<OffEle>& eles = offEvt_.eles();
00200 for(size_t eleNr=0;eleNr<eles.size();eleNr++){
00201 eleMonElems_[monElemNr]->fill(eles[eleNr],offEvt_,weight);
00202 }
00203 }
00204
00205 for(size_t monElemNr=0;monElemNr<phoMonElems_.size();monElemNr++){
00206 const std::vector<OffPho>& phos = offEvt_.phos();
00207 for(size_t phoNr=0;phoNr<phos.size();phoNr++){
00208 phoMonElems_[monElemNr]->fill(phos[phoNr],offEvt_,weight);
00209 }
00210 }
00211 }
00212
00213
00214 void EgHLTOfflineSource::addEleTrigPath(const std::string& name)
00215 {
00216 EleHLTFilterMon* filterMon = new EleHLTFilterMon(name,TrigCodes::getCode(name.c_str()),binData_,cutMasks_);
00217 eleFilterMonHists_.push_back(filterMon);
00218 std::sort(eleFilterMonHists_.begin(),eleFilterMonHists_.end(),EleHLTFilterMon::ptrLess<EleHLTFilterMon>());
00219 }
00220
00221 void EgHLTOfflineSource::addPhoTrigPath(const std::string& name)
00222 {
00223 PhoHLTFilterMon* filterMon = new PhoHLTFilterMon(name,TrigCodes::getCode(name.c_str()),binData_,cutMasks_);
00224 phoFilterMonHists_.push_back(filterMon);
00225 std::sort(phoFilterMonHists_.begin(),phoFilterMonHists_.end(),PhoHLTFilterMon::ptrLess<PhoHLTFilterMon>());
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235 void EgHLTOfflineSource::getHLTFilterNamesUsed(std::vector<std::string>& filterNames)const
00236 {
00237 std::set<std::string> filterNameSet;
00238 for(size_t i=0;i<eleHLTFilterNames_.size();i++) filterNameSet.insert(eleHLTFilterNames_[i]);
00239 for(size_t i=0;i<phoHLTFilterNames_.size();i++) filterNameSet.insert(phoHLTFilterNames_[i]);
00240
00241
00242 for(size_t tightLooseNr=0;tightLooseNr<eleTightLooseTrigNames_.size();tightLooseNr++){
00243 std::vector<std::string> trigNames;
00244 boost::split(trigNames,eleTightLooseTrigNames_[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<diEleTightLooseTrigNames_.size();tightLooseNr++){
00250 std::vector<std::string> trigNames;
00251 boost::split(trigNames,diEleTightLooseTrigNames_[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 for(size_t tightLooseNr=0;tightLooseNr<phoTightLooseTrigNames_.size();tightLooseNr++){
00257 std::vector<std::string> trigNames;
00258 boost::split(trigNames,phoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00259 if(trigNames.size()!=2) continue;
00260 filterNameSet.insert(trigNames[0]);
00261 filterNameSet.insert(trigNames[1]);
00262 }
00263 for(size_t tightLooseNr=0;tightLooseNr<diPhoTightLooseTrigNames_.size();tightLooseNr++){
00264 std::vector<std::string> trigNames;
00265 boost::split(trigNames,diPhoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
00266 if(trigNames.size()!=2) continue;
00267 filterNameSet.insert(trigNames[0]);
00268 filterNameSet.insert(trigNames[1]);
00269 }
00270
00271
00272 std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
00273 }
00274
00275 void EgHLTOfflineSource::filterTriggers(const HLTConfigProvider& hltConfig)
00276 {
00277
00278 std::vector<std::string> activeFilters;
00279 std::vector<std::string> activeEleFilters;
00280 std::vector<std::string> activeEle2LegFilters;
00281 std::vector<std::string> activePhoFilters;
00282 std::vector<std::string> activePho2LegFilters;
00283
00284 trigTools::getActiveFilters(hltConfig,activeFilters,activeEleFilters,activeEle2LegFilters,activePhoFilters,activePho2LegFilters);
00285
00286 trigTools::filterInactiveTriggers(eleHLTFilterNames_,activeEleFilters);
00287 trigTools::filterInactiveTriggers(phoHLTFilterNames_,activePhoFilters);
00288 trigTools::filterInactiveTriggers(eleHLTFilterNames2Leg_,activeEle2LegFilters);
00289 trigTools::filterInactiveTightLooseTriggers(eleTightLooseTrigNames_,activeEleFilters);
00290 trigTools::filterInactiveTightLooseTriggers(diEleTightLooseTrigNames_,activeEleFilters);
00291 trigTools::filterInactiveTightLooseTriggers(phoTightLooseTrigNames_,activePhoFilters);
00292 trigTools::filterInactiveTightLooseTriggers(diPhoTightLooseTrigNames_,activePhoFilters);
00293 }