48 #include <boost/algorithm/string.hpp> 69 std::vector<std::string> strs;
71 boost::split(strs, triggerSelection, boost::is_any_of(
"\t ,`!@#$%^&*()~/\\"));
72 for (
size_t iToken = 0; iToken < strs.size();++iToken ){
73 if (strs.at(iToken).find(
"HLT_")==0){
74 m_usedPaths.insert(strs.at(iToken));
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 > * )0);
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 (
size_t iMod = 0; iMod <moduleLabels.size(); ++iMod){
269 if (
"EDFilter" == hltConfig.
moduleEDMType(moduleLabels.at(iMod))) {
270 filtersForThisPath.push_back(moduleLabels.at(iMod));
271 if ( moduleLabels.at(iMod).find(m_filterPartialName)!= std::string::npos ){
272 filterFullName = moduleLabels.at(iMod);
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 std::set<std::string>::iterator 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 *)0, 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 (
size_t i = 0;
i<hIn->size(); ++
i) {
454 bool preselection = m_singleObjectSelection(hIn->at(
i).p4());
456 fillSingleObjectPlots(hIn->at(
i).p4(),
weight);
457 cands.push_back(hIn->at(
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 (
size_t i = 0;
i<hIn->size(); ++
i) {
565 if (!m_singleObjectSelection(hIn->at(
i)))
continue;
566 dxy=0.0, dz=0.0, dxysigma=0.0, dzsigma=0.0;
567 dxy = -1.*hIn->at(
i).dxy(vtxPoint);
568 dz = hIn->at(
i).dz(vtxPoint);
569 dxysigma =
sqrt(hIn->at(
i).dxyError()*hIn->at(
i).dxyError()+vxErr*vyErr);
570 dzsigma =
sqrt(hIn->at(
i).dzError()*hIn->at(
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 (
size_t i = 0;
i<hIn->size(); ++
i) {
621 double scale = pfcorrector->correction(hIn->at(
i));
622 reco::PFJet newPFJet(scale*hIn->at(
i).p4(), hIn->at(
i).vertex(),
623 hIn->at(
i).getSpecific(), hIn->at(
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 (
size_t i = 0;
i<hIn->size(); ++
i) {
665 bool preselection = m_singleObjectSelection(hIn->at(
i).p4());
667 fillSingleObjectPlots(hIn->at(
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 trigger::Keys::const_iterator 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 (
size_t i = 0;
i < todo.size(); ++
i) {
757 if (type ==
"FromHLT") {
760 else if (type ==
"RecoCandidateCounter") {
763 else if (type ==
"RecoTrackCounter") {
766 else if (type ==
"RecoTrackCounterWithVertexConstraint") {
767 m_handlers.push_back(std::shared_ptr<FSQ::RecoTrackCounterWithVertexConstraint>
770 else if (type ==
"FromRecoCandidate") {
773 else if (type ==
"RecoPFJet") {
776 else if (type ==
"RecoPFJetWithJEC") {
779 else if (type ==
"RecoTrack") {
782 else if (type ==
"RecoPhoton") {
785 else if (type ==
"RecoMuon") {
788 else if (type ==
"RecoGenParticleCounter") {
791 else if (type ==
"RecoGenParticleHandler") {
812 edm::LogError(
"FSQDiJetAve") <<
"Could not setup the filter";
820 edm::LogError(
"FSQDiJetAve") <<
"TriggerResults not valid, skippng event";
838 edm::LogInfo(
"FSQDiJetAve") <<
"TriggerEvent not found, ";
863 LogDebug(
"FSQDiJetAve") <<
"HLTConfigProvider failed to initialize.";
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)
void book(DQMStore::IBooker &booker)
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
virtual 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)
void getAndStoreTokens(edm::ConsumesCollector &&iC)
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)
HLTConfigProvider m_hltConfig
math::XYZTLorentzVector LorentzVector
Lorentz vector.
edm::InputTag triggerSummaryLabel_
std::vector< std::shared_ptr< FSQ::BaseHandler > > m_handlers
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryToken
virtual 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
virtual void dqmBeginRun(edm::Run const &run, edm::EventSetup const &c) override
triggerExpression::Data * m_eventCache
std::vector< edm::ParameterSet > m_combinedObjectDrawables
std::map< std::string, std::shared_ptr< StringObjectFunction< std::vector< TOutputCandidateType > > > > m_plottersCombinedObject