46 #include <boost/algorithm/string.hpp> 69 std::vector<std::string> strs;
72 for (
auto&
str : strs) {
73 if (
str.find(
"HLT_") == 0) {
74 m_usedPaths.insert(
str);
78 m_eventCache = &eventCache;
96 std::map<std::string, MonitorElement*>
m_histos;
106 template <
class TInputCand
idateType,
class TOutputCand
idateType, SpecialFilters filter = None>
118 std::map<std::string, std::shared_ptr<StringObjectFunction<std::vector<TOutputCandidateType> > > >
122 static const int SingleObjectPlotter = 0;
123 static const int CombinedObjectPlotter = 1;
134 m_singleObjectSelection(iConfig.getParameter<
std::
string>(
"singleObjectsPreselection")),
135 m_combinedObjectSelection(iConfig.getParameter<
std::
string>(
"combinedObjectSelection")),
136 m_combinedObjectSortFunction(iConfig.getParameter<
std::
string>(
"combinedObjectSortCriteria")) {
138 if (
type !=
"FromHLT") {
143 m_filterPartialName =
146 m_combinedObjectDimension = iConfig.
getParameter<
int>(
"combinedObjectDimension");
147 m_combinedObjectDrawables = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"combinedObjectDrawables");
148 m_singleObjectDrawables = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"singleObjectDrawables");
156 std::vector<std::vector<edm::ParameterSet>*>
todo(2, (std::vector<edm::ParameterSet>*)
nullptr);
157 todo[CombinedObjectPlotter] = &m_combinedObjectDrawables;
158 todo[SingleObjectPlotter] = &m_singleObjectDrawables;
159 for (
size_t ti = 0; ti <
todo.size(); ++ti) {
160 for (
size_t i = 0;
i <
todo[ti]->size(); ++
i) {
162 std::string expression =
todo[ti]->at(
i).template getParameter<std::string>(
"expression");
163 int bins =
todo[ti]->at(
i).template getParameter<int>(
"bins");
164 double rangeLow =
todo[ti]->at(
i).template getParameter<double>(
"min");
165 double rangeHigh =
todo[ti]->at(
i).template getParameter<double>(
"max");
168 if (ti == CombinedObjectPlotter) {
171 std::shared_ptr<StringObjectFunction<std::vector<TOutputCandidateType> > >(
func);
174 m_plottersSingleObject[
histoName] = std::shared_ptr<StringObjectFunction<TInputCandidateType> >(
func);
199 for (
size_t i = 0;
i < hIn->size(); ++
i) {
202 fillSingleObjectPlots(hIn->at(
i),
weight);
211 std::map<std::string, MonitorElement*>::iterator it, itE;
212 it = m_histos.begin();
213 itE = m_histos.end();
214 for (; it != itE; ++it) {
215 if (m_plotterType[it->first] != SingleObjectPlotter)
217 float val = (*m_plottersSingleObject[it->first])(
cand);
232 std::vector<TOutputCandidateType>&
cands,
246 for (
size_t i = 0;
i < hIn->size(); ++
i) {
249 fillSingleObjectPlots(hIn->at(
i),
weight);
250 cands.push_back(hIn->at(
i));
256 std::vector<std::string>
ret(2,
"");
259 std::vector<std::string> filtersForThisPath;
261 int numPathMatches = 0;
262 int numFilterMatches = 0;
264 if (
hltConfig.triggerName(
i).find(m_pathPartialName) == std::string::npos)
269 std::vector<std::string> moduleLabels =
hltConfig.moduleLabels(
i);
273 if (
moduleLabel.find(m_filterPartialName) != std::string::npos) {
282 if (numPathMatches != 1) {
283 edm::LogInfo(
"FSQDiJetAve") <<
"Problem: found " << numPathMatches <<
" paths matching " << m_pathPartialName
287 ret[0] = pathFullName;
288 if (numFilterMatches != 1) {
289 edm::LogError(
"FSQDiJetAve") <<
"Problem: found " << numFilterMatches <<
" filter matching " 290 << m_filterPartialName <<
" in path " << m_pathPartialName << std::endl;
293 ret[1] = filterFullName;
306 auto itUsedPaths = m_usedPaths.begin();
307 for (; itUsedPaths != m_usedPaths.end(); ++itUsedPaths) {
308 if (
triggerNames.triggerName(
i).find(*itUsedPaths) != std::string::npos) {
314 if (
found == m_usedPaths.size())
317 if (
found != m_usedPaths.size()) {
318 edm::LogInfo(
"FSQDiJetAve") <<
"One of requested paths not found, skipping event";
321 if (m_eventCache->configurationUpdated()) {
322 m_expression->init(*m_eventCache);
324 if (not(*m_expression)(*m_eventCache))
340 std::vector<TOutputCandidateType>
cands;
346 std::vector<TOutputCandidateType> bestCombinationFromCands = getBestCombination(
cands);
347 if (bestCombinationFromCands.empty())
351 std::map<std::string, MonitorElement*>::iterator it, itE;
352 it = m_histos.begin();
353 itE = m_histos.end();
354 for (; it != itE; ++it) {
355 if (m_plotterType[it->first] != CombinedObjectPlotter)
357 float val = (*m_plottersCombinedObject[it->first])(bestCombinationFromCands);
363 int columnSize =
cands.size();
364 std::vector<int> currentCombination(m_combinedObjectDimension, 0);
365 std::vector<int> bestCombination(m_combinedObjectDimension, -1);
367 int maxCombinations = 1;
369 while (cnt < m_combinedObjectDimension) {
371 maxCombinations *= columnSize;
375 float bestCombinedCandVal = -1;
376 while (cnt < maxCombinations) {
380 std::vector<int> currentCombinationCopy(currentCombination);
381 std::vector<int>::iterator it;
382 std::sort(currentCombinationCopy.begin(), currentCombinationCopy.end());
383 it =
std::unique(currentCombinationCopy.begin(), currentCombinationCopy.end());
384 currentCombinationCopy.resize(
std::distance(currentCombinationCopy.begin(), it));
385 bool duplicatesPresent = currentCombination.size() != currentCombinationCopy.size();
389 if (!duplicatesPresent) {
390 std::vector<TOutputCandidateType> currentCombinationFromCands;
391 currentCombinationFromCands.reserve(m_combinedObjectDimension);
392 for (
int i = 0;
i < m_combinedObjectDimension; ++
i) {
393 currentCombinationFromCands.push_back(
cands.at(currentCombination.at(
i)));
395 bool isOK = m_combinedObjectSelection(currentCombinationFromCands);
397 float curVal = m_combinedObjectSortFunction(currentCombinationFromCands);
401 <<
"Problem: ranking function returned negative value: " << curVal << std::endl;
402 }
else if (curVal > bestCombinedCandVal) {
404 bestCombinedCandVal = curVal;
405 bestCombination = currentCombination;
411 currentCombination.at(m_combinedObjectDimension - 1) += 1;
413 for (
int i = m_combinedObjectDimension - 1;
i >= 0;
415 currentCombination.at(
i) += carry;
417 if (currentCombination.at(
i) >= columnSize) {
419 currentCombination.at(
i) = 0;
424 std::vector<TOutputCandidateType> bestCombinationFromCands;
425 if (!bestCombination.empty() && bestCombination.at(0) >= 0) {
426 for (
int i = 0;
i < m_combinedObjectDimension; ++
i) {
427 bestCombinationFromCands.push_back(
cands.at(bestCombination.at(
i)));
430 return bestCombinationFromCands;
448 std::vector<reco::Candidate::LorentzVector>&
cands,
455 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
457 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
460 for (
auto const&
i : *hIn) {
463 fillSingleObjectPlots(
i.p4(),
weight);
478 std::vector<int>&
cands,
485 cands.push_back(count<reco::Track>(
iEvent, m_input, m_singleObjectSelection,
weight));
490 std::vector<int>&
cands,
497 cands.push_back(count<reco::GenParticle>(
iEvent, m_input, m_singleObjectSelection,
weight));
520 std::vector<int>&
cands,
528 static const int lMinNDOF = m_pset.getParameter<
int>(
"minNDOF");
529 static const double lMaxZ = m_pset.getParameter<
double>(
"maxZ");
530 static const double lMaxDZ = m_pset.getParameter<
double>(
"maxDZ");
531 static const double lMaxDZ2dzsigma = m_pset.getParameter<
double>(
"maxDZ2dzsigma");
532 static const double lMaxDXY = m_pset.getParameter<
double>(
"maxDXY");
533 static const double lMaxDXY2dxysigma = m_pset.getParameter<
double>(
"maxDXY2dxysigma");
543 double dxy,
dz, dzsigma, dxysigma;
545 double vzErr = 0.0, vxErr = 0.0, vyErr = 0.0;
567 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
569 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
573 for (
auto const&
i : *hIn) {
574 if (!m_singleObjectSelection(
i))
576 dxy = 0.0,
dz = 0.0, dxysigma = 0.0, dzsigma = 0.0;
577 dxy = -1. *
i.dxy(vtxPoint);
579 dxysigma =
sqrt(
i.dxyError() *
i.dxyError() + vxErr * vyErr);
580 dzsigma =
sqrt(
i.dzError() *
i.dzError() + vzErr * vzErr);
582 if (fabs(
dz) > lMaxDZ)
584 if (fabs(
dz / dzsigma) > lMaxDZ2dzsigma)
586 if (fabs(
dxy) > lMaxDXY)
588 if (fabs(
dxy / dxysigma) > lMaxDXY2dxysigma)
612 std::vector<reco::PFJet>&
cands,
621 iEvent.getByToken(m_tokens[jetCorTag.
encode()], pfcorrector);
624 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
627 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
631 for (
auto const&
i : *hIn) {
632 double scale = pfcorrector->correction(
i);
637 fillSingleObjectPlots(newPFJet,
weight);
638 cands.push_back(newPFJet);
656 std::vector<int>&
cands,
666 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
668 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
671 for (
auto const&
i : *hIn) {
674 fillSingleObjectPlots(
i.p4(),
weight);
687 std::vector<trigger::TriggerObject>&
cands,
695 if (filterFullName.empty()) {
706 edm::LogInfo(
"FSQDiJetAve") <<
"Cannot determine hlt index for |" << filterFullName <<
"|" <<
process;
713 auto kj = khlt.begin();
715 for (; kj != khlt.end(); ++kj) {
718 fillSingleObjectPlots(toc[*kj],
weight);
719 cands.push_back(toc[*kj]);
744 : m_eventCache(iConfig.
getParameterSet(
"triggerConfiguration"), consumesCollector()) {
760 std::vector<edm::ParameterSet>
todo = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"todo");
763 if (
type ==
"FromHLT") {
765 }
else if (
type ==
"RecoCandidateCounter") {
767 }
else if (
type ==
"RecoTrackCounter") {
769 }
else if (
type ==
"RecoTrackCounterWithVertexConstraint") {
771 }
else if (
type ==
"FromRecoCandidate") {
773 }
else if (
type ==
"RecoPFJet") {
775 }
else if (
type ==
"RecoPFJetWithJEC") {
777 }
else if (
type ==
"RecoTrack") {
779 }
else if (
type ==
"RecoPhoton") {
781 }
else if (
type ==
"RecoMuon") {
783 }
else if (
type ==
"RecoGenParticleCounter") {
785 }
else if (
type ==
"RecoGenParticleHandler") {
792 m_handler->getAndStoreTokens(consumesCollector());
801 edm::LogError(
"FSQDiJetAve") <<
"Could not setup the filter";
809 edm::LogError(
"FSQDiJetAve") <<
"TriggerResults not valid, skippng event";
827 edm::LogInfo(
"FSQDiJetAve") <<
"TriggerEvent not found, ";
850 LogDebug(
"FSQDiJetAve") <<
"HLTConfigProvider failed to initialize.";
855 m_handler->book(booker);
int count(const edm::Event &iEvent, InputTag &input, StringCutObjectSelector< T > &sel, float weight)
const Keys & filterKeys(trigger::size_type index) const
edm::Handle< edm::TriggerResults > m_triggerResults
std::vector< edm::ParameterSet > m_combinedObjectDrawables
std::string m_filterPartialName
vector< string > parse(string line, const string &delimiter)
T getParameter(std::string const &) const
triggerExpression::Data m_eventCache
HandlerTemplate< reco::Photon, reco::Photon > RecoPhotonHandler
The single EDProduct to be saved for each event (AOD case)
std::vector< std::shared_ptr< FSQ::BaseHandler > > m_handlers
std::vector< edm::ParameterSet > m_singleObjectDrawables
dqm::legacy::MonitorElement MonitorElement
edm::Handle< trigger::TriggerEvent > m_trgEvent
virtual void setCurrentFolder(std::string const &fullpath)
ret
prodAgent to be discontinued
edm::EDGetTokenT< GenEventInfoProduct > m_genEvInfoToken
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken
trigger::size_type sizeFilters() const
T const * product() const
std::vector< std::string > findPathAndFilter(const HLTConfigProvider &hltConfig)
StringObjectFunction< std::vector< TOutputCandidateType > > m_combinedObjectSortFunction
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::EDGetTokenT< edm::TriggerResults > triggerResultsFUToken
T getUntrackedParameter(std::string const &, T const &) const
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
std::set< std::string > m_usedPaths
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryFUToken
def unique(seq, keepstr=True)
const TriggerObjectCollection & getObjects() const
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
BaseHandler(const edm::ParameterSet &iConfig, triggerExpression::Data &eventCache)
def split(sequence, size)
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
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
HandlerTemplate< reco::Track, int > RecoTrackCounter
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
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_
ParameterSet const & getParameterSet(ParameterSetID const &id)
void book(DQMStore::IBooker &booker) override
const std::string & usedProcessName() const
getters
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_
preselection
PRESELECTION
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