48 #include <boost/algorithm/string.hpp> 69 std::vector<std::string> strs;
71 boost::split(strs, triggerSelection, boost::is_any_of(
"\t ,`!@#$%^&*()~/\\"));
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>
121 static const int SingleObjectPlotter = 0;
122 static const int CombinedObjectPlotter = 1;
133 m_singleObjectSelection(iConfig.getParameter<
std::
string>(
"singleObjectsPreselection")),
134 m_combinedObjectSelection(iConfig.getParameter<
std::
string>(
"combinedObjectSelection")),
135 m_combinedObjectSortFunction(iConfig.getParameter<
std::
string>(
"combinedObjectSortCriteria"))
138 if (type !=
"FromHLT") {
145 m_combinedObjectDimension = iConfig.
getParameter<
int>(
"combinedObjectDimension");
146 m_combinedObjectDrawables = iConfig.
getParameter< std::vector< edm::ParameterSet > >(
"combinedObjectDrawables");
147 m_singleObjectDrawables = iConfig.
getParameter< std::vector< edm::ParameterSet > >(
"singleObjectDrawables");
155 std::vector< std::vector< edm::ParameterSet > * > todo(2, (std::vector< edm::ParameterSet > * )
nullptr);
156 todo[CombinedObjectPlotter]=&m_combinedObjectDrawables;
157 todo[SingleObjectPlotter]=&m_singleObjectDrawables;
158 for (
size_t ti =0; ti<todo.size();++ti){
159 for (
size_t i = 0;
i < todo[ti]->size(); ++
i){
160 std::string histoName = m_dqmhistolabel +
"_" + todo[ti]->at(
i).template getParameter<std::string>(
"name");
161 std::string expression = todo[ti]->at(
i).template getParameter<std::string>(
"expression");
162 int bins = todo[ti]->at(
i).template getParameter<int>(
"bins");
163 double rangeLow = todo[ti]->at(
i).template getParameter<double>(
"min");
164 double rangeHigh = todo[ti]->at(
i).template getParameter<double>(
"max");
165 m_histos[histoName] = booker.
book1D(histoName, histoName, bins, rangeLow, rangeHigh);
166 m_plotterType[histoName] = ti;
167 if (ti == CombinedObjectPlotter){
170 m_plottersCombinedObject[histoName] = 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();
215 if (m_plotterType[it->first]!=SingleObjectPlotter)
continue;
216 float val = (*m_plottersSingleObject[it->first])(cand);
217 it->second->Fill(val, weight);
245 for (
size_t i = 0;
i<hIn->size(); ++
i) {
248 fillSingleObjectPlots(hIn->at(
i),
weight);
249 cands.push_back(hIn->at(
i));
255 std::vector<std::string> ret(2,
"");
258 std::vector<std::string> filtersForThisPath;
260 int numPathMatches = 0;
261 int numFilterMatches = 0;
262 for (
size_t i = 0;
i < hltConfig.
size(); ++
i) {
263 if (hltConfig.
triggerName(
i).find(m_pathPartialName) == std::string::npos)
continue;
267 std::vector<std::string > moduleLabels = hltConfig.
moduleLabels(
i);
268 for (
auto & moduleLabel : moduleLabels){
270 filtersForThisPath.push_back(moduleLabel);
271 if ( moduleLabel.find(m_filterPartialName)!= std::string::npos ){
272 filterFullName = moduleLabel;
280 if (numPathMatches != 1) {
281 edm::LogInfo(
"FSQDiJetAve") <<
"Problem: found " << numPathMatches
282 <<
" paths matching " << m_pathPartialName << std::endl;
285 ret[0] = pathFullName;
286 if (numFilterMatches != 1) {
287 edm::LogError(
"FSQDiJetAve") <<
"Problem: found " << numFilterMatches
288 <<
" filter matching " << m_filterPartialName
289 <<
" in path "<< m_pathPartialName << std::endl;
292 ret[1] = filterFullName;
304 for (
size_t i = 0;
i<triggerNames.
size(); ++
i){
305 auto itUsedPaths = m_usedPaths.begin();
306 for(; itUsedPaths != m_usedPaths.end(); ++itUsedPaths){
307 if (triggerNames.
triggerName(
i).find(*itUsedPaths)!= std::string::npos ){
313 if (found == m_usedPaths.size())
break;
315 if (found != m_usedPaths.size()){
316 edm::LogInfo(
"FSQDiJetAve") <<
"One of requested paths not found, skipping event";
319 if (m_eventCache->configurationUpdated()) {
320 m_expression->init(*m_eventCache);
322 if (not (*m_expression)(*m_eventCache))
return;
337 std::vector<TOutputCandidateType> cands;
338 getFilteredCands((TInputCandidateType *)
nullptr, cands, iEvent, iSetup, hltConfig, trgEvent, weight);
340 if (cands.size()==0)
return;
342 std::vector<TOutputCandidateType> bestCombinationFromCands = getBestCombination(cands);
343 if (bestCombinationFromCands.size()==0)
return;
346 std::map<std::string, MonitorElement*>::iterator it, itE;
347 it = m_histos.begin();
348 itE = m_histos.end();
350 if (m_plotterType[it->first]!=CombinedObjectPlotter)
continue;
351 float val = (*m_plottersCombinedObject[it->first])(bestCombinationFromCands);
352 it->second->Fill(val, weight);
357 int columnSize = cands.size();
358 std::vector<int> currentCombination(m_combinedObjectDimension, 0);
359 std::vector<int> bestCombination(m_combinedObjectDimension, -1);
361 int maxCombinations = 1;
363 while (cnt < m_combinedObjectDimension){
365 maxCombinations *= columnSize;
369 float bestCombinedCandVal = -1;
370 while ( cnt < maxCombinations){
374 std::vector<int> currentCombinationCopy(currentCombination);
375 std::vector<int>::iterator it;
376 std::sort(currentCombinationCopy.begin(), currentCombinationCopy.end());
377 it =
std::unique(currentCombinationCopy.begin(), currentCombinationCopy.end());
378 currentCombinationCopy.resize(
std::distance(currentCombinationCopy.begin(),it) );
379 bool duplicatesPresent = currentCombination.size() != currentCombinationCopy.size();
383 if (!duplicatesPresent) {
384 std::vector<TOutputCandidateType > currentCombinationFromCands;
385 for (
int i = 0;
i<m_combinedObjectDimension;++
i){
386 currentCombinationFromCands.push_back( cands.at(currentCombination.at(
i)));
388 bool isOK = m_combinedObjectSelection(currentCombinationFromCands);
390 float curVal = m_combinedObjectSortFunction(currentCombinationFromCands);
393 edm::LogError(
"FSQDiJetAve") <<
"Problem: ranking function returned negative value: " << curVal << std::endl;
394 }
else if (curVal > bestCombinedCandVal){
396 bestCombinedCandVal = curVal;
397 bestCombination = currentCombination;
403 currentCombination.at(m_combinedObjectDimension-1)+=1;
405 for (
int i = m_combinedObjectDimension-1;
i>=0; --
i){
406 currentCombination.at(
i)+= carry;
408 if (currentCombination.at(
i)>=columnSize){
410 currentCombination.at(
i) = 0;
415 std::vector<TOutputCandidateType > bestCombinationFromCands;
416 if (bestCombination.size()!=0 && bestCombination.at(0)>=0){
417 for (
int i = 0;
i<m_combinedObjectDimension;++
i){
418 bestCombinationFromCands.push_back( cands.at(bestCombination.at(
i)));
421 return bestCombinationFromCands;
440 std::vector<reco::Candidate::LorentzVector> & cands,
448 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
450 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
453 for (
auto const &
i : *hIn) {
456 fillSingleObjectPlots(
i.p4(),
weight);
457 cands.push_back(
i.p4());
471 std::vector<int > & cands,
479 cands.push_back(count<reco::Track>(iEvent, m_input, m_singleObjectSelection, weight) );
484 std::vector<int > & cands,
489 cands.push_back(count<reco::GenParticle>(iEvent, m_input, m_singleObjectSelection, weight) );
514 std::vector<int > & cands,
522 static const int lMinNDOF = m_pset.getParameter<
int>(
"minNDOF");
523 static const double lMaxZ = m_pset.getParameter<
double>(
"maxZ");
524 static const double lMaxDZ = m_pset.getParameter<
double>(
"maxDZ");
525 static const double lMaxDZ2dzsigma = m_pset.getParameter<
double>(
"maxDZ2dzsigma");
526 static const double lMaxDXY = m_pset.getParameter<
double>(
"maxDXY");
527 static const double lMaxDXY2dxysigma = m_pset.getParameter<
double>(
"maxDXY2dxysigma");
537 double dxy,
dz, dzsigma, dxysigma;
539 double vzErr =0.0, vxErr=0.0, vyErr=0.0;
543 for (
size_t i = 0;
i < vertices->size(); ++
i){
544 if (vertices->at(
i).ndof()<lMinNDOF)
continue;
545 if (fabs(vertices->at(
i).z())> lMaxZ)
continue;
547 vtxPoint=vertices->at(
i).position();
548 vzErr=vertices->at(
i).zError();
549 vxErr=vertices->at(
i).xError();
550 vyErr=vertices->at(
i).yError();
554 if (bestVtx < 0)
return;
558 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
560 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
564 for (
auto const &
i : *hIn) {
565 if (!m_singleObjectSelection(
i))
continue;
566 dxy=0.0, dz=0.0, dxysigma=0.0, dzsigma=0.0;
567 dxy = -1.*
i.dxy(vtxPoint);
569 dxysigma =
sqrt(
i.dxyError()*
i.dxyError()+vxErr*vyErr);
570 dzsigma =
sqrt(
i.dzError()*
i.dzError()+vzErr*vzErr);
572 if(fabs(dz)>lMaxDZ)
continue;
573 if(fabs(dz/dzsigma)>lMaxDZ2dzsigma)
continue;
574 if(fabs(dxy)>lMaxDXY)
continue;
575 if(fabs(dxy/dxysigma)>lMaxDXY2dxysigma)
continue;
601 std::vector<reco::PFJet > & cands,
613 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
616 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
620 for (
auto const &
i : *hIn) {
621 double scale = pfcorrector->correction(
i);
623 i.getSpecific(),
i.getJetConstituents());
627 fillSingleObjectPlots(newPFJet, weight);
628 cands.push_back(newPFJet);
648 std::vector<int > & cands,
659 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
661 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
664 for (
auto const &
i : *hIn) {
667 fillSingleObjectPlots(
i.p4(),
weight);
680 std::vector<trigger::TriggerObject> &cands,
688 std::string filterFullName = findPathAndFilter(hltConfig)[1];
689 if (filterFullName ==
"") {
700 edm::LogInfo(
"FSQDiJetAve") <<
"Cannot determine hlt index for |" << filterFullName <<
"|" <<
process;
707 auto kj = khlt.begin();
709 for(;kj != khlt.end(); ++kj){
712 fillSingleObjectPlots(toc[*kj], weight);
713 cands.push_back( toc[*kj]);
738 m_eventCache(iConfig.
getParameterSet(
"triggerConfiguration") , consumesCollector())
753 std::vector< edm::ParameterSet > todo = iConfig.
getParameter< std::vector< edm::ParameterSet > >(
"todo");
754 for (
auto pset : todo) {
756 if (type ==
"FromHLT") {
759 else if (type ==
"RecoCandidateCounter") {
762 else if (type ==
"RecoTrackCounter") {
765 else if (type ==
"RecoTrackCounterWithVertexConstraint") {
766 m_handlers.push_back(std::make_shared<FSQ::RecoTrackCounterWithVertexConstraint>
769 else if (type ==
"FromRecoCandidate") {
772 else if (type ==
"RecoPFJet") {
775 else if (type ==
"RecoPFJetWithJEC") {
778 else if (type ==
"RecoTrack") {
781 else if (type ==
"RecoPhoton") {
784 else if (type ==
"RecoMuon") {
787 else if (type ==
"RecoGenParticleCounter") {
790 else if (type ==
"RecoGenParticleHandler") {
810 edm::LogError(
"FSQDiJetAve") <<
"Could not setup the filter";
818 edm::LogError(
"FSQDiJetAve") <<
"TriggerResults not valid, skippng event";
836 edm::LogInfo(
"FSQDiJetAve") <<
"TriggerEvent not found, ";
861 LogDebug(
"FSQDiJetAve") <<
"HLTConfigProvider failed to initialize.";
867 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)
T getParameter(std::string const &) const
edm::Handle< edm::TriggerResults > m_triggerResults
T getUntrackedParameter(std::string const &, T const &) const
std::string m_filterPartialName
triggerExpression::Data m_eventCache
HandlerTemplate< reco::Photon, reco::Photon > RecoPhotonHandler
std::map< std::string, int > m_plotterType
The single EDProduct to be saved for each event (AOD case)
trigger::size_type sizeFilters() const
const std::string & triggerName(unsigned int triggerIndex) const
edm::Handle< trigger::TriggerEvent > m_trgEvent
bool getByToken(EDGetToken token, Handle< PROD > &result) const
def analyze(function, filename, filter=None)
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
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.
std::vector< Vertex > VertexCollection
collection of Vertex objects
FSQDiJetAve(const edm::ParameterSet &)
edm::EDGetTokenT< GenEventInfoProduct > m_genEvInfoToken
HandlerTemplate< trigger::TriggerObject, trigger::TriggerObject > HLTHandler
Strings::size_type size() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &run, edm::EventSetup const &c) override
Jets made from PFObjects.
std::vector< edm::ParameterSet > m_singleObjectDrawables
std::map< std::string, MonitorElement * > m_histos
static std::string const input
edm::EDGetTokenT< edm::TriggerResults > triggerResultsFUToken
Single trigger physics object (e.g., an isolated muon)
HandlerTemplate< reco::Track, int > RecoTrackCounter
std::vector< TOutputCandidateType > getBestCombination(std::vector< TOutputCandidateType > &cands)
std::string m_pathPartialName
void addDefault(ParameterSetDescription const &psetDescription)
std::string m_dqmhistolabel
HandlerTemplate< reco::GenParticle, reco::GenParticle > RecoGenParticleHandler
void fillSingleObjectPlots(const TInputCandidateType &cand, float weight)
StringCutObjectSelector< std::vector< TOutputCandidateType > > m_combinedObjectSelection
const TriggerObjectCollection & getObjects() const
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::set< std::string > m_usedPaths
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryFUToken
def unique(seq, keepstr=True)
const std::string & usedProcessName() const
getters
MonitorElement * book1D(Args &&...args)
std::vector< std::string > findPathAndFilter(const HLTConfigProvider &hltConfig)
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::Track, int, BestVertexMatching > RecoTrackCounterWithVertexConstraint
int m_combinedObjectDimension
HandlerTemplate< reco::PFJet, reco::PFJet, ApplyJEC > RecoPFJetWithJECHandler
HandlerTemplate< reco::GenParticle, int > RecoGenParticleCounter
bool setEvent(const edm::Event &event, const edm::EventSetup &setup)
std::map< std::string, std::shared_ptr< StringObjectFunction< TInputCandidateType > > > m_plottersSingleObject
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)
std::unique_ptr< triggerExpression::Evaluator > m_expression
HandlerTemplate< reco::Candidate::LorentzVector, reco::Candidate::LorentzVector > RecoCandidateHandler
void setCurrentFolder(const std::string &fullpath)
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
HandlerTemplate< reco::Candidate::LorentzVector, int > RecoCandidateCounter
StringCutObjectSelector< TInputCandidateType > m_singleObjectSelection
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
HLTConfigProvider m_hltConfig
math::XYZTLorentzVector LorentzVector
Lorentz vector.
edm::InputTag triggerSummaryLabel_
void book(DQMStore::IBooker &booker) override
std::vector< std::shared_ptr< FSQ::BaseHandler > > m_handlers
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryToken
void analyze(const edm::Event &, const edm::EventSetup &) override
HandlerTemplate< reco::Muon, reco::Muon > RecoMuonHandler
edm::InputTag triggerResultsLabel_
edm::TriggerNames m_triggerNames
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
HandlerTemplate< reco::PFJet, reco::PFJet > RecoPFJetHandler
void dqmBeginRun(edm::Run const &run, edm::EventSetup const &c) override
triggerExpression::Data * m_eventCache
std::vector< edm::ParameterSet > m_combinedObjectDrawables
void getAndStoreTokens(edm::ConsumesCollector &&iC) override
std::map< std::string, std::shared_ptr< StringObjectFunction< std::vector< TOutputCandidateType > > > > m_plottersCombinedObject