43 #include <boost/algorithm/string.hpp> 66 std::vector<std::string> strs;
69 for (
auto&
str : strs) {
70 if (
str.find(
"HLT_") == 0) {
71 m_usedPaths.insert(
str);
75 m_eventCache = &eventCache;
93 std::map<std::string, MonitorElement*>
m_histos;
103 template <
class TInputCand
idateType,
class TOutputCand
idateType, SpecialFilters filter = None>
115 std::map<std::string, std::shared_ptr<StringObjectFunction<std::vector<TOutputCandidateType> > > >
119 static const int SingleObjectPlotter = 0;
120 static const int CombinedObjectPlotter = 1;
131 m_singleObjectSelection(iConfig.getParameter<
std::
string>(
"singleObjectsPreselection")),
132 m_combinedObjectSelection(iConfig.getParameter<
std::
string>(
"combinedObjectSelection")),
133 m_combinedObjectSortFunction(iConfig.getParameter<
std::
string>(
"combinedObjectSortCriteria")) {
135 if (
type !=
"FromHLT") {
140 m_filterPartialName =
143 m_combinedObjectDimension = iConfig.
getParameter<
int>(
"combinedObjectDimension");
144 m_combinedObjectDrawables = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"combinedObjectDrawables");
145 m_singleObjectDrawables = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"singleObjectDrawables");
153 std::vector<std::vector<edm::ParameterSet>*>
todo(2, (std::vector<edm::ParameterSet>*)
nullptr);
154 todo[CombinedObjectPlotter] = &m_combinedObjectDrawables;
155 todo[SingleObjectPlotter] = &m_singleObjectDrawables;
156 for (
size_t ti = 0; ti <
todo.size(); ++ti) {
157 for (
size_t i = 0;
i <
todo[ti]->size(); ++
i) {
160 int bins =
todo[ti]->at(
i).template getParameter<int>(
"bins");
161 double rangeLow =
todo[ti]->at(
i).template getParameter<double>(
"min");
162 double rangeHigh =
todo[ti]->at(
i).template getParameter<double>(
"max");
165 if (ti == CombinedObjectPlotter) {
168 std::shared_ptr<StringObjectFunction<std::vector<TOutputCandidateType> > >(
func);
171 m_plottersSingleObject[
histoName] = std::shared_ptr<StringObjectFunction<TInputCandidateType> >(
func);
196 for (
size_t i = 0;
i < hIn->size(); ++
i) {
199 fillSingleObjectPlots(hIn->at(
i),
weight);
208 std::map<std::string, MonitorElement*>::iterator it, itE;
209 it = m_histos.begin();
210 itE = m_histos.end();
211 for (; it != itE; ++it) {
212 if (m_plotterType[it->first] != SingleObjectPlotter)
214 float val = (*m_plottersSingleObject[it->first])(
cand);
229 std::vector<TOutputCandidateType>&
cands,
243 for (
size_t i = 0;
i < hIn->size(); ++
i) {
246 fillSingleObjectPlots(hIn->at(
i),
weight);
247 cands.push_back(hIn->at(
i));
253 std::vector<std::string>
ret(2,
"");
256 std::vector<std::string> filtersForThisPath;
258 int numPathMatches = 0;
259 int numFilterMatches = 0;
261 if (
hltConfig.triggerName(
i).find(m_pathPartialName) == std::string::npos)
266 std::vector<std::string> moduleLabels =
hltConfig.moduleLabels(
i);
270 if (
moduleLabel.find(m_filterPartialName) != std::string::npos) {
279 if (numPathMatches != 1) {
280 edm::LogInfo(
"FSQDiJetAve") <<
"Problem: found " << numPathMatches <<
" paths matching " << m_pathPartialName
284 ret[0] = pathFullName;
285 if (numFilterMatches != 1) {
286 edm::LogError(
"FSQDiJetAve") <<
"Problem: found " << numFilterMatches <<
" filter matching " 287 << m_filterPartialName <<
" in path " << m_pathPartialName << std::endl;
290 ret[1] = filterFullName;
303 auto itUsedPaths = m_usedPaths.begin();
304 for (; itUsedPaths != m_usedPaths.end(); ++itUsedPaths) {
305 if (
triggerNames.triggerName(
i).find(*itUsedPaths) != std::string::npos) {
311 if (
found == m_usedPaths.size())
314 if (
found != m_usedPaths.size()) {
315 edm::LogInfo(
"FSQDiJetAve") <<
"One of requested paths not found, skipping event";
318 if (m_eventCache->configurationUpdated()) {
319 m_expression->init(*m_eventCache);
321 if (not(*m_expression)(*m_eventCache))
337 std::vector<TOutputCandidateType>
cands;
343 std::vector<TOutputCandidateType> bestCombinationFromCands = getBestCombination(
cands);
344 if (bestCombinationFromCands.empty())
348 std::map<std::string, MonitorElement*>::iterator it, itE;
349 it = m_histos.begin();
350 itE = m_histos.end();
351 for (; it != itE; ++it) {
352 if (m_plotterType[it->first] != CombinedObjectPlotter)
354 float val = (*m_plottersCombinedObject[it->first])(bestCombinationFromCands);
360 int columnSize =
cands.size();
361 std::vector<int> currentCombination(m_combinedObjectDimension, 0);
362 std::vector<int> bestCombination(m_combinedObjectDimension, -1);
364 int maxCombinations = 1;
366 while (cnt < m_combinedObjectDimension) {
368 maxCombinations *= columnSize;
372 float bestCombinedCandVal = -1;
373 while (cnt < maxCombinations) {
377 std::vector<int> currentCombinationCopy(currentCombination);
378 std::vector<int>::iterator it;
379 std::sort(currentCombinationCopy.begin(), currentCombinationCopy.end());
380 it =
std::unique(currentCombinationCopy.begin(), currentCombinationCopy.end());
381 currentCombinationCopy.resize(
std::distance(currentCombinationCopy.begin(), it));
382 bool duplicatesPresent = currentCombination.size() != currentCombinationCopy.size();
386 if (!duplicatesPresent) {
387 std::vector<TOutputCandidateType> currentCombinationFromCands;
388 currentCombinationFromCands.reserve(m_combinedObjectDimension);
389 for (
int i = 0;
i < m_combinedObjectDimension; ++
i) {
390 currentCombinationFromCands.push_back(
cands.at(currentCombination.at(
i)));
392 bool isOK = m_combinedObjectSelection(currentCombinationFromCands);
394 float curVal = m_combinedObjectSortFunction(currentCombinationFromCands);
398 <<
"Problem: ranking function returned negative value: " << curVal << std::endl;
399 }
else if (curVal > bestCombinedCandVal) {
401 bestCombinedCandVal = curVal;
402 bestCombination = currentCombination;
408 currentCombination.at(m_combinedObjectDimension - 1) += 1;
410 for (
int i = m_combinedObjectDimension - 1;
i >= 0;
412 currentCombination.at(
i) += carry;
414 if (currentCombination.at(
i) >= columnSize) {
416 currentCombination.at(
i) = 0;
421 std::vector<TOutputCandidateType> bestCombinationFromCands;
422 if (!bestCombination.empty() && bestCombination.at(0) >= 0) {
423 for (
int i = 0;
i < m_combinedObjectDimension; ++
i) {
424 bestCombinationFromCands.push_back(
cands.at(bestCombination.at(
i)));
427 return bestCombinationFromCands;
445 std::vector<reco::Candidate::LorentzVector>&
cands,
452 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
454 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
457 for (
auto const&
i : *hIn) {
460 fillSingleObjectPlots(
i.p4(),
weight);
475 std::vector<int>&
cands,
482 cands.push_back(count<reco::Track>(
iEvent, m_input, m_singleObjectSelection,
weight));
487 std::vector<int>&
cands,
494 cands.push_back(count<reco::GenParticle>(
iEvent, m_input, m_singleObjectSelection,
weight));
517 std::vector<int>&
cands,
525 static const int lMinNDOF = m_pset.getParameter<
int>(
"minNDOF");
526 static const double lMaxZ = m_pset.getParameter<
double>(
"maxZ");
527 static const double lMaxDZ = m_pset.getParameter<
double>(
"maxDZ");
528 static const double lMaxDZ2dzsigma = m_pset.getParameter<
double>(
"maxDZ2dzsigma");
529 static const double lMaxDXY = m_pset.getParameter<
double>(
"maxDXY");
530 static const double lMaxDXY2dxysigma = m_pset.getParameter<
double>(
"maxDXY2dxysigma");
539 double vzErr = 0.0, vxErr = 0.0, vyErr = 0.0;
542 bool vtxfound =
false;
544 if (
vertex.ndof() < lMinNDOF)
546 if (fabs(
vertex.z()) > lMaxZ)
549 vtxPoint =
vertex.position();
560 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
562 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
566 for (
auto const&
i : *hIn) {
567 if (!m_singleObjectSelection(
i))
570 double absdz = fabs(
i.dz(vtxPoint));
575 double absdxy = fabs(
i.dxy(vtxPoint));
576 if (absdxy > lMaxDXY)
579 double dzsigma2 =
i.dzError() *
i.dzError() + vzErr * vzErr;
580 if (absdz * absdz > lMaxDZ2dzsigma * lMaxDZ2dzsigma * dzsigma2)
583 double dxysigma2 =
i.dxyError() *
i.dxyError() + vxErr * vyErr;
584 if (absdxy * absdxy > lMaxDXY2dxysigma * lMaxDXY2dxysigma * dxysigma2)
608 std::vector<reco::PFJet>&
cands,
617 iEvent.getByToken(m_tokens[jetCorTag.
encode()], pfcorrector);
620 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
623 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
627 for (
auto const&
i : *hIn) {
628 double scale = pfcorrector->correction(
i);
633 fillSingleObjectPlots(newPFJet,
weight);
634 cands.push_back(newPFJet);
652 std::vector<int>&
cands,
662 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
664 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
667 for (
auto const&
i : *hIn) {
670 fillSingleObjectPlots(
i.p4(),
weight);
683 std::vector<trigger::TriggerObject>&
cands,
691 if (filterFullName.empty()) {
702 edm::LogInfo(
"FSQDiJetAve") <<
"Cannot determine hlt index for |" << filterFullName <<
"|" <<
process;
709 auto kj = khlt.begin();
711 for (; kj != khlt.end(); ++kj) {
714 fillSingleObjectPlots(toc[*kj],
weight);
715 cands.push_back(toc[*kj]);
740 : m_eventCache(iConfig.
getParameterSet(
"triggerConfiguration"), consumesCollector()) {
756 std::vector<edm::ParameterSet>
todo = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"todo");
759 if (
type ==
"FromHLT") {
761 }
else if (
type ==
"RecoCandidateCounter") {
763 }
else if (
type ==
"RecoTrackCounter") {
765 }
else if (
type ==
"RecoTrackCounterWithVertexConstraint") {
767 }
else if (
type ==
"FromRecoCandidate") {
769 }
else if (
type ==
"RecoPFJet") {
771 }
else if (
type ==
"RecoPFJetWithJEC") {
773 }
else if (
type ==
"RecoTrack") {
775 }
else if (
type ==
"RecoPhoton") {
777 }
else if (
type ==
"RecoMuon") {
779 }
else if (
type ==
"RecoGenParticleCounter") {
781 }
else if (
type ==
"RecoGenParticleHandler") {
788 m_handler->getAndStoreTokens(consumesCollector());
797 edm::LogError(
"FSQDiJetAve") <<
"Could not setup the filter";
805 edm::LogError(
"FSQDiJetAve") <<
"TriggerResults not valid, skippng event";
823 edm::LogInfo(
"FSQDiJetAve") <<
"TriggerEvent not found, ";
846 LogDebug(
"FSQDiJetAve") <<
"HLTConfigProvider failed to initialize.";
851 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
#define DEFINE_FWK_MODULE(type)
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