48 #include <boost/algorithm/string.hpp>
69 : m_expression(triggerExpression::
parse(iConfig.getParameter<std::
string>(
"triggerSelection"))) {
71 std::vector<std::string> strs;
73 boost::split(strs, triggerSelection, boost::is_any_of(
"\t ,`!@#$%^&*()~/\\"));
74 for (
auto&
str : strs) {
75 if (
str.find(
"HLT_") == 0) {
76 m_usedPaths.insert(
str);
80 m_eventCache = &eventCache;
98 std::map<std::string, MonitorElement*>
m_histos;
108 template <
class TInputCand
idateType,
class TOutputCand
idateType, SpecialFilters filter = None>
120 std::map<std::string, std::shared_ptr<StringObjectFunction<std::vector<TOutputCandidateType> > > >
124 static const int SingleObjectPlotter = 0;
125 static const int CombinedObjectPlotter = 1;
136 m_singleObjectSelection(iConfig.getParameter<std::
string>(
"singleObjectsPreselection")),
137 m_combinedObjectSelection(iConfig.getParameter<std::
string>(
"combinedObjectSelection")),
138 m_combinedObjectSortFunction(iConfig.getParameter<std::
string>(
"combinedObjectSortCriteria")) {
140 if (type !=
"FromHLT") {
145 m_filterPartialName =
148 m_combinedObjectDimension = iConfig.
getParameter<
int>(
"combinedObjectDimension");
149 m_combinedObjectDrawables = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"combinedObjectDrawables");
150 m_singleObjectDrawables = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"singleObjectDrawables");
158 std::vector<std::vector<edm::ParameterSet>*> todo(2, (std::vector<edm::ParameterSet>*)
nullptr);
159 todo[CombinedObjectPlotter] = &m_combinedObjectDrawables;
160 todo[SingleObjectPlotter] = &m_singleObjectDrawables;
161 for (
size_t ti = 0; ti < todo.size(); ++ti) {
162 for (
size_t i = 0;
i < todo[ti]->size(); ++
i) {
163 std::string histoName = m_dqmhistolabel +
"_" + todo[ti]->at(
i).template getParameter<std::string>(
"name");
164 std::string expression = todo[ti]->at(
i).template getParameter<std::string>(
"expression");
165 int bins = todo[ti]->at(
i).template getParameter<int>(
"bins");
166 double rangeLow = todo[ti]->at(
i).template getParameter<double>(
"min");
167 double rangeHigh = todo[ti]->at(
i).template getParameter<double>(
"max");
168 m_histos[histoName] = booker.
book1D(histoName, histoName, bins, rangeLow, rangeHigh);
169 m_plotterType[histoName] = ti;
170 if (ti == CombinedObjectPlotter) {
172 m_plottersCombinedObject[histoName] =
173 std::shared_ptr<StringObjectFunction<std::vector<TOutputCandidateType> > >(
func);
176 m_plottersSingleObject[histoName] = std::shared_ptr<StringObjectFunction<TInputCandidateType> >(
func);
201 for (
size_t i = 0;
i < hIn->size(); ++
i) {
204 fillSingleObjectPlots(hIn->at(
i),
weight);
213 std::map<std::string, MonitorElement*>::iterator it, itE;
214 it = m_histos.begin();
215 itE = m_histos.end();
216 for (; it != itE; ++it) {
217 if (m_plotterType[it->first] != SingleObjectPlotter)
219 float val = (*m_plottersSingleObject[it->first])(cand);
220 it->second->Fill(val, weight);
234 std::vector<TOutputCandidateType>&
cands,
241 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
244 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
248 for (
size_t i = 0;
i < hIn->size(); ++
i) {
251 fillSingleObjectPlots(hIn->at(
i),
weight);
252 cands.push_back(hIn->at(
i));
258 std::vector<std::string>
ret(2,
"");
261 std::vector<std::string> filtersForThisPath;
263 int numPathMatches = 0;
264 int numFilterMatches = 0;
265 for (
size_t i = 0;
i < hltConfig.
size(); ++
i) {
266 if (hltConfig.
triggerName(
i).find(m_pathPartialName) == std::string::npos)
271 std::vector<std::string> moduleLabels = hltConfig.
moduleLabels(
i);
272 for (
auto& moduleLabel : moduleLabels) {
274 filtersForThisPath.push_back(moduleLabel);
275 if (moduleLabel.find(m_filterPartialName) != std::string::npos) {
276 filterFullName = moduleLabel;
284 if (numPathMatches != 1) {
285 edm::LogInfo(
"FSQDiJetAve") <<
"Problem: found " << numPathMatches <<
" paths matching " << m_pathPartialName
289 ret[0] = pathFullName;
290 if (numFilterMatches != 1) {
291 edm::LogError(
"FSQDiJetAve") <<
"Problem: found " << numFilterMatches <<
" filter matching "
292 << m_filterPartialName <<
" in path " << m_pathPartialName << std::endl;
295 ret[1] = filterFullName;
307 for (
size_t i = 0;
i < triggerNames.
size(); ++
i) {
308 auto itUsedPaths = m_usedPaths.begin();
309 for (; itUsedPaths != m_usedPaths.end(); ++itUsedPaths) {
310 if (triggerNames.
triggerName(
i).find(*itUsedPaths) != std::string::npos) {
316 if (found == m_usedPaths.size())
319 if (found != m_usedPaths.size()) {
320 edm::LogInfo(
"FSQDiJetAve") <<
"One of requested paths not found, skipping event";
323 if (m_eventCache->configurationUpdated()) {
324 m_expression->init(*m_eventCache);
326 if (not(*m_expression)(*m_eventCache))
342 std::vector<TOutputCandidateType>
cands;
343 getFilteredCands((TInputCandidateType*)
nullptr, cands, iEvent, iSetup, hltConfig, trgEvent, weight);
348 std::vector<TOutputCandidateType> bestCombinationFromCands = getBestCombination(cands);
349 if (bestCombinationFromCands.empty())
353 std::map<std::string, MonitorElement*>::iterator it, itE;
354 it = m_histos.begin();
355 itE = m_histos.end();
356 for (; it != itE; ++it) {
357 if (m_plotterType[it->first] != CombinedObjectPlotter)
359 float val = (*m_plottersCombinedObject[it->first])(bestCombinationFromCands);
360 it->second->Fill(val, weight);
365 int columnSize = cands.size();
366 std::vector<int> currentCombination(m_combinedObjectDimension, 0);
367 std::vector<int> bestCombination(m_combinedObjectDimension, -1);
369 int maxCombinations = 1;
371 while (cnt < m_combinedObjectDimension) {
373 maxCombinations *= columnSize;
377 float bestCombinedCandVal = -1;
378 while (cnt < maxCombinations) {
382 std::vector<int> currentCombinationCopy(currentCombination);
383 std::vector<int>::iterator it;
384 std::sort(currentCombinationCopy.begin(), currentCombinationCopy.end());
385 it =
std::unique(currentCombinationCopy.begin(), currentCombinationCopy.end());
386 currentCombinationCopy.resize(
std::distance(currentCombinationCopy.begin(), it));
387 bool duplicatesPresent = currentCombination.size() != currentCombinationCopy.size();
391 if (!duplicatesPresent) {
392 std::vector<TOutputCandidateType> currentCombinationFromCands;
393 currentCombinationFromCands.reserve(m_combinedObjectDimension);
394 for (
int i = 0;
i < m_combinedObjectDimension; ++
i) {
395 currentCombinationFromCands.push_back(cands.at(currentCombination.at(
i)));
397 bool isOK = m_combinedObjectSelection(currentCombinationFromCands);
399 float curVal = m_combinedObjectSortFunction(currentCombinationFromCands);
403 <<
"Problem: ranking function returned negative value: " << curVal << std::endl;
404 }
else if (curVal > bestCombinedCandVal) {
406 bestCombinedCandVal = curVal;
407 bestCombination = currentCombination;
413 currentCombination.at(m_combinedObjectDimension - 1) += 1;
415 for (
int i = m_combinedObjectDimension - 1;
i >= 0;
417 currentCombination.at(
i) += carry;
419 if (currentCombination.at(
i) >= columnSize) {
421 currentCombination.at(
i) = 0;
426 std::vector<TOutputCandidateType> bestCombinationFromCands;
427 if (!bestCombination.empty() && bestCombination.at(0) >= 0) {
428 for (
int i = 0;
i < m_combinedObjectDimension; ++
i) {
429 bestCombinationFromCands.push_back(cands.at(bestCombination.at(
i)));
432 return bestCombinationFromCands;
450 std::vector<reco::Candidate::LorentzVector>&
cands,
457 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
459 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
462 for (
auto const&
i : *hIn) {
465 fillSingleObjectPlots(
i.p4(),
weight);
466 cands.push_back(
i.p4());
480 std::vector<int>&
cands,
487 cands.push_back(count<reco::Track>(iEvent, m_input, m_singleObjectSelection, weight));
492 std::vector<int>&
cands,
499 cands.push_back(count<reco::GenParticle>(iEvent, m_input, m_singleObjectSelection, weight));
522 std::vector<int>&
cands,
530 static const int lMinNDOF = m_pset.getParameter<
int>(
"minNDOF");
531 static const double lMaxZ = m_pset.getParameter<
double>(
"maxZ");
532 static const double lMaxDZ = m_pset.getParameter<
double>(
"maxDZ");
533 static const double lMaxDZ2dzsigma = m_pset.getParameter<
double>(
"maxDZ2dzsigma");
534 static const double lMaxDXY = m_pset.getParameter<
double>(
"maxDXY");
535 static const double lMaxDXY2dxysigma = m_pset.getParameter<
double>(
"maxDXY2dxysigma");
545 double dxy,
dz, dzsigma, dxysigma;
547 double vzErr = 0.0, vxErr = 0.0, vyErr = 0.0;
551 for (
size_t i = 0;
i < vertices->size(); ++
i) {
552 if (vertices->at(
i).ndof() < lMinNDOF)
554 if (fabs(vertices->at(
i).z()) > lMaxZ)
557 vtxPoint = vertices->at(
i).position();
558 vzErr = vertices->at(
i).zError();
559 vxErr = vertices->at(
i).xError();
560 vyErr = vertices->at(
i).yError();
569 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
571 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
575 for (
auto const&
i : *hIn) {
576 if (!m_singleObjectSelection(
i))
578 dxy = 0.0, dz = 0.0, dxysigma = 0.0, dzsigma = 0.0;
579 dxy = -1. *
i.dxy(vtxPoint);
581 dxysigma =
sqrt(
i.dxyError() *
i.dxyError() + vxErr * vyErr);
582 dzsigma =
sqrt(
i.dzError() *
i.dzError() + vzErr * vzErr);
584 if (fabs(dz) > lMaxDZ)
586 if (fabs(dz / dzsigma) > lMaxDZ2dzsigma)
588 if (fabs(dxy) > lMaxDXY)
590 if (fabs(dxy / dxysigma) > lMaxDXY2dxysigma)
614 std::vector<reco::PFJet>&
cands,
626 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
629 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
633 for (
auto const&
i : *hIn) {
634 double scale = pfcorrector->correction(
i);
635 reco::PFJet newPFJet(scale *
i.p4(),
i.vertex(),
i.getSpecific(),
i.getJetConstituents());
639 fillSingleObjectPlots(newPFJet, weight);
640 cands.push_back(newPFJet);
658 std::vector<int>&
cands,
668 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
670 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
673 for (
auto const&
i : *hIn) {
676 fillSingleObjectPlots(
i.p4(),
weight);
689 std::vector<trigger::TriggerObject>&
cands,
696 std::string filterFullName = findPathAndFilter(hltConfig)[1];
697 if (filterFullName.empty()) {
708 edm::LogInfo(
"FSQDiJetAve") <<
"Cannot determine hlt index for |" << filterFullName <<
"|" <<
process;
715 auto kj = khlt.begin();
717 for (; kj != khlt.end(); ++kj) {
720 fillSingleObjectPlots(toc[*kj], weight);
721 cands.push_back(toc[*kj]);
746 : m_eventCache(iConfig.
getParameterSet(
"triggerConfiguration"), consumesCollector()) {
762 std::vector<edm::ParameterSet> todo = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"todo");
763 for (
const auto&
pset : todo) {
765 if (type ==
"FromHLT") {
767 }
else if (type ==
"RecoCandidateCounter") {
769 }
else if (type ==
"RecoTrackCounter") {
771 }
else if (type ==
"RecoTrackCounterWithVertexConstraint") {
773 }
else if (type ==
"FromRecoCandidate") {
775 }
else if (type ==
"RecoPFJet") {
777 }
else if (type ==
"RecoPFJetWithJEC") {
779 }
else if (type ==
"RecoTrack") {
781 }
else if (type ==
"RecoPhoton") {
783 }
else if (type ==
"RecoMuon") {
785 }
else if (type ==
"RecoGenParticleCounter") {
787 }
else if (type ==
"RecoGenParticleHandler") {
794 m_handler->getAndStoreTokens(consumesCollector());
803 edm::LogError(
"FSQDiJetAve") <<
"Could not setup the filter";
811 edm::LogError(
"FSQDiJetAve") <<
"TriggerResults not valid, skippng event";
829 edm::LogInfo(
"FSQDiJetAve") <<
"TriggerEvent not found, ";
852 LogDebug(
"FSQDiJetAve") <<
"HLTConfigProvider failed to initialize.";
857 m_handler->book(booker);
unsigned int size() const
number of trigger paths in trigger table
int count(const edm::Event &iEvent, InputTag &input, StringCutObjectSelector< T > &sel, float weight)
edm::Handle< edm::TriggerResults > m_triggerResults
T getUntrackedParameter(std::string const &, T const &) const
std::vector< edm::ParameterSet > m_combinedObjectDrawables
tuple ret
prodAgent to be discontinued
std::string m_filterPartialName
triggerExpression::Data m_eventCache
const edm::EventSetup & c
HandlerTemplate< reco::Photon, reco::Photon > RecoPhotonHandler
The single EDProduct to be saved for each event (AOD case)
trigger::size_type sizeFilters() const
std::vector< std::shared_ptr< FSQ::BaseHandler > > m_handlers
const std::string & triggerName(unsigned int triggerIndex) const
std::vector< edm::ParameterSet > m_singleObjectDrawables
dqm::legacy::MonitorElement MonitorElement
edm::Handle< trigger::TriggerEvent > m_trgEvent
virtual void setCurrentFolder(std::string const &fullpath)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< GenEventInfoProduct > m_genEvInfoToken
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterSet const & getParameterSet(ParameterSetID const &id)
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken
const Keys & filterKeys(trigger::size_type index) const
std::vector< std::string > findPathAndFilter(const HLTConfigProvider &hltConfig)
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
StringObjectFunction< std::vector< TOutputCandidateType > > m_combinedObjectSortFunction
const std::string moduleEDMType(const std::string &module) const
C++ base class name of module.
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
std::vector< Vertex > VertexCollection
collection of Vertex objects
FSQDiJetAve(const edm::ParameterSet &)
HandlerTemplate< trigger::TriggerObject, trigger::TriggerObject > HLTHandler
Log< level::Error, false > LogError
void bookHistograms(DQMStore::IBooker &, edm::Run const &run, edm::EventSetup const &c) override
Jets made from PFObjects.
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
std::map< std::string, MonitorElement * > m_histos
static std::string const input
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
edm::EDGetTokenT< edm::TriggerResults > triggerResultsFUToken
Single trigger physics object (e.g., an isolated muon)
std::vector< TOutputCandidateType > getBestCombination(std::vector< TOutputCandidateType > &cands)
HandlerTemplate< reco::GenParticle, reco::GenParticle > RecoGenParticleHandler
std::string m_pathPartialName
void addDefault(ParameterSetDescription const &psetDescription)
std::string m_dqmhistolabel
void fillSingleObjectPlots(const TInputCandidateType &cand, float weight)
std::map< std::string, int > m_plotterType
StringCutObjectSelector< std::vector< TOutputCandidateType > > m_combinedObjectSelection
const TriggerObjectCollection & getObjects() const
std::set< std::string > m_usedPaths
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryFUToken
const std::string & usedProcessName() const
getters
tuple preselection
string added as general entry for modeul definition here and use in tauTools.py
void getFilteredCands(TInputCandidateType *, std::vector< TOutputCandidateType > &cands, const edm::Event &iEvent, const edm::EventSetup &iSetup, const HLTConfigProvider &hltConfig, const trigger::TriggerEvent &trgEvent, float weight)
HandlerTemplate< reco::Candidate::LorentzVector, int > RecoCandidateCounter
HandlerTemplate< reco::Track, int, BestVertexMatching > RecoTrackCounterWithVertexConstraint
int m_combinedObjectDimension
HandlerTemplate< reco::PFJet, reco::PFJet, ApplyJEC > RecoPFJetWithJECHandler
bool setEvent(const edm::Event &event, const edm::EventSetup &setup)
HandlerTemplate(const edm::ParameterSet &iConfig, triggerExpression::Data &eventCache)
std::map< std::string, edm::EDGetToken > m_tokens
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
BaseHandler(const edm::ParameterSet &iConfig, triggerExpression::Data &eventCache)
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Log< level::Info, false > LogInfo
std::unique_ptr< triggerExpression::Evaluator > m_expression
HandlerTemplate< reco::Candidate::LorentzVector, reco::Candidate::LorentzVector > RecoCandidateHandler
HandlerTemplate< reco::Track, int > RecoTrackCounter
T const * product() const
std::string const & triggerName(unsigned int index) const
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< size_type > Keys
static std::string const triggerResults("TriggerResults")
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d'tor
T getParameter(std::string const &) const
StringCutObjectSelector< TInputCandidateType > m_singleObjectSelection
std::map< std::string, std::shared_ptr< StringObjectFunction< TInputCandidateType > > > m_plottersSingleObject
HandlerTemplate< reco::Track, reco::Track > RecoTrackHandler
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup, const HLTConfigProvider &hltConfig, const trigger::TriggerEvent &trgEvent, const edm::TriggerResults &triggerResults, const edm::TriggerNames &triggerNames, float weight) override
dqm::legacy::DQMStore DQMStore
HLTConfigProvider m_hltConfig
math::XYZTLorentzVector LorentzVector
Lorentz vector.
edm::InputTag triggerSummaryLabel_
void book(DQMStore::IBooker &booker) override
HandlerTemplate< reco::GenParticle, int > RecoGenParticleCounter
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryToken
void analyze(const edm::Event &, const edm::EventSetup &) override
HandlerTemplate< reco::Muon, reco::Muon > RecoMuonHandler
edm::InputTag triggerResultsLabel_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
edm::TriggerNames m_triggerNames
HandlerTemplate< reco::PFJet, reco::PFJet > RecoPFJetHandler
void dqmBeginRun(edm::Run const &run, edm::EventSetup const &c) override
triggerExpression::Data * m_eventCache
void getAndStoreTokens(edm::ConsumesCollector &&iC) override
std::map< std::string, std::shared_ptr< StringObjectFunction< std::vector< TOutputCandidateType > > > > m_plottersCombinedObject