CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTTauDQMOfflineSource.cc
Go to the documentation of this file.
2 
4 
6 
7 using namespace std;
8 using namespace edm;
9 using namespace reco;
10 using namespace l1extra;
11 using namespace trigger;
12 
13 //
14 // constructors and destructor
15 //
17  hltProcessName_(ps.getUntrackedParameter<std::string>("HLTProcessName","HLT")),
18  triggerResultsSrc_(ps.getUntrackedParameter<edm::InputTag>("TriggerResultsSrc")),
19  triggerResultsToken_(consumes<edm::TriggerResults>(triggerResultsSrc_)),
20  triggerEventSrc_(ps.getUntrackedParameter<edm::InputTag>("TriggerEventSrc")),
21  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventSrc_)),
22  pathRegex_(ps.getUntrackedParameter<std::string>("Paths")),
23  nPtBins_(ps.getUntrackedParameter<int>("PtHistoBins", 20)),
24  nEtaBins_(ps.getUntrackedParameter<int>("EtaHistoBins",12)),
25  nPhiBins_(ps.getUntrackedParameter<int>("PhiHistoBins",18)),
26  ptMax_(ps.getUntrackedParameter<double>("PtHistoMax",200)),
27  highPtMax_(ps.getUntrackedParameter<double>("HighPtHistoMax",1000)),
28  l1MatchDr_(ps.getUntrackedParameter<double>("L1MatchDeltaR", 0.5)),
29  hltMatchDr_(ps.getUntrackedParameter<double>("HLTMatchDeltaR", 0.2)),
30  dqmBaseFolder_(ps.getUntrackedParameter<std::string>("DQMBaseFolder")),
31  counterEvt_(0),
32  prescaleEvt_(ps.getUntrackedParameter<int>("prescaleEvt", -1))
33 {
34  edm::ParameterSet matching = ps.getParameter<edm::ParameterSet>("Matching");
35  doRefAnalysis_ = matching.getUntrackedParameter<bool>("doMatching");
36 
37  if(ps.exists("L1Plotter")) {
39  nPhiBins_, ptMax_, highPtMax_, doRefAnalysis_, l1MatchDr_, dqmBaseFolder_));
40  }
41  if(ps.exists("PathSummaryPlotter")) {
43  doRefAnalysis_, dqmBaseFolder_, hltMatchDr_));
44  }
45 
46  if(doRefAnalysis_) {
47  using VPSet = std::vector<edm::ParameterSet>;
48  VPSet matchObjects = matching.getUntrackedParameter<VPSet>("matchFilters");
49  for(const edm::ParameterSet& pset: matchObjects) {
50  refObjects_.push_back(RefObject{pset.getUntrackedParameter<int>("matchObjectID"),
51  consumes<LVColl>(pset.getUntrackedParameter<edm::InputTag>("FilterName"))});
52  }
53  }
54 }
55 
57 }
58 
59 //--------------------------------------------------------
61  //Evaluate configuration for every new trigger menu
62  bool hltMenuChanged = false;
63  if(HLTCP_.init(iRun, iSetup, hltProcessName_, hltMenuChanged)) {
64  LogDebug("HLTTauDQMOffline") << "dqmBeginRun(), hltMenuChanged " << hltMenuChanged;
65  if(hltMenuChanged) {
66  // Find all paths to monitor
67  std::vector<std::string> foundPaths;
68  boost::smatch what;
69  LogDebug("HLTTauDQMOffline") << "Looking for paths with regex " << pathRegex_;
70  for(const std::string& pathName: HLTCP_.triggerNames()) {
71  if(boost::regex_search(pathName, what, pathRegex_)) {
72  LogDebug("HLTTauDQMOffline") << "Found path " << pathName;
73  foundPaths.emplace_back(pathName);
74  }
75  }
76  std::sort(foundPaths.begin(), foundPaths.end());
77 
78  // Construct path plotters
79  std::vector<const HLTTauDQMPath *> pathObjects;
80  pathPlotters_.reserve(foundPaths.size());
81  pathObjects.reserve(foundPaths.size());
82  for(const std::string& pathName: foundPaths) {
84  if(pathPlotters_.back().isValid()) {
85  pathObjects.push_back(pathPlotters_.back().getPathObject());
86  }
87  }
88 
89  // Update paths to the summary plotter
91  pathSummaryPlotter_->setPathObjects(pathObjects);
92  }
93  }
94  } else {
95  edm::LogWarning("HLTTauDQMOffline") << "HLT config extraction failure with process name '" << hltProcessName_ << "'";
96  }
97 }
98 
99 //--------------------------------------------------------
101  if(l1Plotter_) {
102  l1Plotter_->bookHistograms(iBooker);
103  }
104  for(auto& pathPlotter: pathPlotters_) {
105  pathPlotter.bookHistograms(iBooker);
106  }
107  if(pathSummaryPlotter_) {
108  pathSummaryPlotter_->bookHistograms(iBooker);
109  }
110 }
111 
112 // ----------------------------------------------------------
114  //Apply the prescaler
115  if (counterEvt_ > prescaleEvt_) {
116  //Do Analysis here
117  counterEvt_ = 0;
118 
119  edm::Handle<edm::TriggerResults> triggerResultsHandle;
120  iEvent.getByToken(triggerResultsToken_, triggerResultsHandle);
121  if(!triggerResultsHandle.isValid()) {
122  edm::LogWarning("HLTTauDQMOffline") << "Unable to read edm::TriggerResults with label " << triggerResultsSrc_;
123  return;
124  }
125 
126  edm::Handle<trigger::TriggerEvent> triggerEventHandle;
127  iEvent.getByToken(triggerEventToken_, triggerEventHandle);
128  if(!triggerEventHandle.isValid()) {
129  edm::LogWarning("HLTTauDQMOffline") << "Unable to read trigger::TriggerEvent with label " << triggerEventSrc_;
130  return;
131  }
132 
133  //Create match collections
135  if (doRefAnalysis_) {
136  for(RefObject& refObj: refObjects_) {
137  edm::Handle<LVColl> collHandle;
138  iEvent.getByToken(refObj.token, collHandle);
139  if(!collHandle.isValid())
140  continue;
141 
142  if(refObj.objID == 11) {
143  refC.electrons.insert(refC.electrons.end(), collHandle->begin(), collHandle->end());
144  }
145  else if(refObj.objID == 13) {
146  refC.muons.insert(refC.muons.end(), collHandle->begin(), collHandle->end());
147  }
148  else if(refObj.objID == 15) {
149  refC.taus.insert(refC.taus.end(), collHandle->begin(), collHandle->end());
150  }
151  }
152  }
153 
154  //Path Plotters
155  for(auto& pathPlotter: pathPlotters_) {
156  if(pathPlotter.isValid())
157  pathPlotter.analyze(*triggerResultsHandle, *triggerEventHandle, refC);
158  }
159 
160  if(pathSummaryPlotter_ && pathSummaryPlotter_->isValid()) {
161  pathSummaryPlotter_->analyze(*triggerResultsHandle, *triggerEventHandle, refC);
162  }
163 
164  //L1 Plotter
165  if(l1Plotter_ && l1Plotter_->isValid()) {
166  l1Plotter_->analyze(iEvent, iSetup, refC);
167  }
168  } else {
169  counterEvt_++;
170  }
171 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string dqmBaseFolder_
void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c) override
std::vector< LV > electrons
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
std::vector< LV > taus
edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< RefObject > refObjects_
void bookHistograms(DQMStore::IBooker &iBooker, const edm::Run &r, const edm::EventSetup &c) override
const std::vector< std::string > & triggerNames() const
names of trigger paths
bool exists(std::string const &parameterName) const
checks if a parameter exists
triggerResultsToken_(consumes< edm::TriggerResults >(edm::InputTag("TriggerResults")))
int iEvent
Definition: GenABIO.cc:230
HLTTauDQMOfflineSource(const edm::ParameterSet &)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< HLTTauDQMPathPlotter > pathPlotters_
bool isValid() const
Definition: HandleBase.h:76
std::unique_ptr< HLTTauDQMPathSummaryPlotter > pathSummaryPlotter_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const boost::regex pathRegex_
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
Definition: Run.h:41
std::vector< LV > muons
std::unique_ptr< HLTTauDQML1Plotter > l1Plotter_
void analyze(const edm::Event &e, const edm::EventSetup &c) override