48 #include <boost/algorithm/string.hpp>
71 std::vector<std::string> strs;
74 for (
auto&
str : strs) {
75 if (
str.find(
"HLT_") == 0) {
76 m_usedPaths.insert(
str);
80 m_eventCache = &eventCache;
92 virtual void book(DQMStore::IBooker& booker) = 0;
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) {
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");
170 if (ti == CombinedObjectPlotter) {
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);
234 std::vector<TOutputCandidateType>&
cands,
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;
266 if (
hltConfig.triggerName(
i).find(m_pathPartialName) == std::string::npos)
271 std::vector<std::string> moduleLabels =
hltConfig.moduleLabels(
i);
275 if (
moduleLabel.find(m_filterPartialName) != std::string::npos) {
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;
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;
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);
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 for (
int i = 0;
i < m_combinedObjectDimension; ++
i) {
394 currentCombinationFromCands.push_back(
cands.at(currentCombination.at(
i)));
396 bool isOK = m_combinedObjectSelection(currentCombinationFromCands);
398 float curVal = m_combinedObjectSortFunction(currentCombinationFromCands);
402 <<
"Problem: ranking function returned negative value: " << curVal << std::endl;
403 }
else if (curVal > bestCombinedCandVal) {
405 bestCombinedCandVal = curVal;
406 bestCombination = currentCombination;
412 currentCombination.at(m_combinedObjectDimension - 1) += 1;
414 for (
int i = m_combinedObjectDimension - 1;
i >= 0;
416 currentCombination.at(
i) += carry;
418 if (currentCombination.at(
i) >= columnSize) {
420 currentCombination.at(
i) = 0;
425 std::vector<TOutputCandidateType> bestCombinationFromCands;
426 if (!bestCombination.empty() && bestCombination.at(0) >= 0) {
427 for (
int i = 0;
i < m_combinedObjectDimension; ++
i) {
428 bestCombinationFromCands.push_back(
cands.at(bestCombination.at(
i)));
431 return bestCombinationFromCands;
449 std::vector<reco::Candidate::LorentzVector>&
cands,
456 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
458 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
461 for (
auto const&
i : *hIn) {
464 fillSingleObjectPlots(
i.p4(),
weight);
479 std::vector<int>&
cands,
486 cands.push_back(count<reco::Track>(
iEvent, m_input, m_singleObjectSelection,
weight));
491 std::vector<int>&
cands,
498 cands.push_back(count<reco::GenParticle>(
iEvent, m_input, m_singleObjectSelection,
weight));
521 std::vector<int>&
cands,
529 static const int lMinNDOF = m_pset.getParameter<
int>(
"minNDOF");
530 static const double lMaxZ = m_pset.getParameter<
double>(
"maxZ");
531 static const double lMaxDZ = m_pset.getParameter<
double>(
"maxDZ");
532 static const double lMaxDZ2dzsigma = m_pset.getParameter<
double>(
"maxDZ2dzsigma");
533 static const double lMaxDXY = m_pset.getParameter<
double>(
"maxDXY");
534 static const double lMaxDXY2dxysigma = m_pset.getParameter<
double>(
"maxDXY2dxysigma");
544 double dxy,
dz, dzsigma, dxysigma;
546 double vzErr = 0.0, vxErr = 0.0, vyErr = 0.0;
568 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
570 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
574 for (
auto const&
i : *hIn) {
575 if (!m_singleObjectSelection(
i))
577 dxy = 0.0,
dz = 0.0, dxysigma = 0.0, dzsigma = 0.0;
578 dxy = -1. *
i.dxy(vtxPoint);
580 dxysigma =
sqrt(
i.dxyError() *
i.dxyError() + vxErr * vyErr);
581 dzsigma =
sqrt(
i.dzError() *
i.dzError() + vzErr * vzErr);
583 if (fabs(
dz) > lMaxDZ)
585 if (fabs(
dz / dzsigma) > lMaxDZ2dzsigma)
587 if (fabs(
dxy) > lMaxDXY)
589 if (fabs(
dxy / dxysigma) > lMaxDXY2dxysigma)
613 std::vector<reco::PFJet>&
cands,
622 iEvent.getByToken(m_tokens[jetCorTag.
encode()], pfcorrector);
625 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
628 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
632 for (
auto const&
i : *hIn) {
633 double scale = pfcorrector->correction(
i);
638 fillSingleObjectPlots(newPFJet,
weight);
639 cands.push_back(newPFJet);
657 std::vector<int>&
cands,
667 iEvent.getByToken(m_tokens[m_input.encode()], hIn);
669 edm::LogError(
"FSQDiJetAve") <<
"product not found: " << m_input.encode();
672 for (
auto const&
i : *hIn) {
675 fillSingleObjectPlots(
i.p4(),
weight);
688 std::vector<trigger::TriggerObject>&
cands,
696 if (filterFullName.empty()) {
707 edm::LogInfo(
"FSQDiJetAve") <<
"Cannot determine hlt index for |" << filterFullName <<
"|" <<
process;
714 auto kj = khlt.begin();
716 for (; kj != khlt.end(); ++kj) {
719 fillSingleObjectPlots(toc[*kj],
weight);
720 cands.push_back(toc[*kj]);
745 : m_eventCache(iConfig.
getParameterSet(
"triggerConfiguration"), consumesCollector()) {
761 std::vector<edm::ParameterSet>
todo = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"todo");
764 if (
type ==
"FromHLT") {
766 }
else if (
type ==
"RecoCandidateCounter") {
768 }
else if (
type ==
"RecoTrackCounter") {
770 }
else if (
type ==
"RecoTrackCounterWithVertexConstraint") {
772 }
else if (
type ==
"FromRecoCandidate") {
774 }
else if (
type ==
"RecoPFJet") {
776 }
else if (
type ==
"RecoPFJetWithJEC") {
778 }
else if (
type ==
"RecoTrack") {
780 }
else if (
type ==
"RecoPhoton") {
782 }
else if (
type ==
"RecoMuon") {
784 }
else if (
type ==
"RecoGenParticleCounter") {
786 }
else if (
type ==
"RecoGenParticleHandler") {
793 m_handler->getAndStoreTokens(consumesCollector());
802 edm::LogError(
"FSQDiJetAve") <<
"Could not setup the filter";
810 edm::LogError(
"FSQDiJetAve") <<
"TriggerResults not valid, skippng event";
828 edm::LogInfo(
"FSQDiJetAve") <<
"TriggerEvent not found, ";
851 LogDebug(
"FSQDiJetAve") <<
"HLTConfigProvider failed to initialize.";
856 m_handler->book(booker);