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;
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 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);
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;
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,
623 iEvent.getByToken(m_tokens[jetCorTag.
encode()], pfcorrector);
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);
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,
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");
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);