48 #include <boost/algorithm/string.hpp>
67 m_expression(triggerExpression::
parse( iConfig.getParameter<std::
string>(
"triggerSelection")))
70 std::vector<std::string> strs;
72 boost::split(strs, triggerSelection, boost::is_any_of(
"\t ,`!@#$%^&*()~/\\"));
73 for (
size_t iToken = 0; iToken < strs.size();++iToken ){
74 if (strs.at(iToken).find(
"HLT_")==0){
75 m_usedPaths.insert(strs.at(iToken));
79 m_eventCache = &eventCache;
97 std::map<std::string, MonitorElement*>
m_histos;
107 template <
class TInputCand
idateType,
class TOutputCand
idateType, SpecialFilters filter = None>
122 static const int SingleObjectPlotter = 0;
123 static const int CombinedObjectPlotter = 1;
134 m_singleObjectSelection(iConfig.getParameter<std::
string>(
"singleObjectsPreselection")),
135 m_combinedObjectSelection(iConfig.getParameter<std::
string>(
"combinedObjectSelection")),
136 m_combinedObjectSortFunction(iConfig.getParameter<std::
string>(
"combinedObjectSortCriteria"))
139 if (type !=
"FromHLT") {
146 m_combinedObjectDimension = iConfig.
getParameter<
int>(
"combinedObjectDimension");
147 m_combinedObjectDrawables = iConfig.
getParameter< std::vector< edm::ParameterSet > >(
"combinedObjectDrawables");
148 m_singleObjectDrawables = iConfig.
getParameter< std::vector< edm::ParameterSet > >(
"singleObjectDrawables");
156 std::vector< std::vector< edm::ParameterSet > * > todo(2, (std::vector< edm::ParameterSet > * )0);
157 todo[CombinedObjectPlotter]=&m_combinedObjectDrawables;
158 todo[SingleObjectPlotter]=&m_singleObjectDrawables;
159 for (
size_t ti =0; ti<todo.size();++ti){
160 for (
size_t i = 0;
i < todo[ti]->size(); ++
i){
161 std::string histoName = m_dqmhistolabel +
"_" + todo[ti]->at(
i).template getParameter<std::string>(
"name");
162 std::string expression = todo[ti]->at(
i).template getParameter<std::string>(
"expression");
163 int bins = todo[ti]->at(
i).template getParameter<int>(
"bins");
164 double rangeLow = todo[ti]->at(
i).template getParameter<double>(
"min");
165 double rangeHigh = todo[ti]->at(
i).template getParameter<double>(
"max");
166 m_histos[
histoName] = booker.
book1D(histoName, histoName, bins, rangeLow, rangeHigh);
168 if (ti == CombinedObjectPlotter){
171 m_plottersCombinedObject[
histoName] = std::shared_ptr<StringObjectFunction<std::vector<TOutputCandidateType> > >(func);
175 m_plottersSingleObject[
histoName] = std::shared_ptr<StringObjectFunction<TInputCandidateType> > (func);
200 for (
size_t i = 0;
i<hIn->size(); ++
i) {
203 fillSingleObjectPlots(hIn->at(
i),
weight);
212 std::map<std::string, MonitorElement*>::iterator it, itE;
213 it = m_histos.begin();
214 itE = m_histos.end();
216 if (m_plotterType[it->first]!=SingleObjectPlotter)
continue;
217 float val = (*m_plottersSingleObject[it->first])(cand);
218 it->second->Fill(val, weight);
239 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
242 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
246 for (
size_t i = 0;
i<hIn->size(); ++
i) {
249 fillSingleObjectPlots(hIn->at(
i),
weight);
250 cands.push_back(hIn->at(
i));
256 std::vector<std::string>
ret(2,
"");
259 std::vector<std::string> filtersForThisPath;
261 int numPathMatches = 0;
262 int numFilterMatches = 0;
263 for (
size_t i = 0;
i < hltConfig.
size(); ++
i) {
264 if (hltConfig.
triggerName(
i).find(m_pathPartialName) == std::string::npos)
continue;
268 std::vector<std::string > moduleLabels = hltConfig.
moduleLabels(
i);
269 for (
size_t iMod = 0; iMod <moduleLabels.size(); ++iMod){
270 if (
"EDFilter" == hltConfig.
moduleEDMType(moduleLabels.at(iMod))) {
271 filtersForThisPath.push_back(moduleLabels.at(iMod));
272 if ( moduleLabels.at(iMod).find(m_filterPartialName)!= std::string::npos ){
273 filterFullName = moduleLabels.at(iMod);
281 if (numPathMatches != 1) {
282 edm::LogInfo(
"FSQDiJetAve") <<
"Problem: found " << numPathMatches
283 <<
" paths matching " << m_pathPartialName << std::endl;
286 ret[0] = pathFullName;
287 if (numFilterMatches != 1) {
288 edm::LogError(
"FSQDiJetAve") <<
"Problem: found " << numFilterMatches
289 <<
" filter matching " << m_filterPartialName
290 <<
" in path "<< m_pathPartialName << std::endl;
293 ret[1] = filterFullName;
305 for (
size_t i = 0;
i<triggerNames.
size(); ++
i){
306 std::set<std::string>::iterator itUsedPaths = m_usedPaths.begin();
307 for(; itUsedPaths != m_usedPaths.end(); ++itUsedPaths){
308 if (triggerNames.
triggerName(
i).find(*itUsedPaths)!= std::string::npos ){
314 if (found == m_usedPaths.size())
break;
316 if (found != m_usedPaths.size()){
317 edm::LogInfo(
"FSQDiJetAve") <<
"One of requested paths not found, skipping event";
320 if (m_eventCache->configurationUpdated()) {
321 m_expression->init(*m_eventCache);
323 if (not (*m_expression)(*m_eventCache))
return;
338 std::vector<TOutputCandidateType> cands;
339 getFilteredCands((TInputCandidateType *)0, cands, iEvent, iSetup, hltConfig, trgEvent, weight);
341 if (cands.size()==0)
return;
343 std::vector<TOutputCandidateType> bestCombinationFromCands = getBestCombination(cands);
344 if (bestCombinationFromCands.size()==0)
return;
347 std::map<std::string, MonitorElement*>::iterator it, itE;
348 it = m_histos.begin();
349 itE = m_histos.end();
351 if (m_plotterType[it->first]!=CombinedObjectPlotter)
continue;
352 float val = (*m_plottersCombinedObject[it->first])(bestCombinationFromCands);
353 it->second->Fill(val, weight);
358 int columnSize = cands.size();
359 std::vector<int> currentCombination(m_combinedObjectDimension, 0);
360 std::vector<int> bestCombination(m_combinedObjectDimension, -1);
362 int maxCombinations = 1;
364 while (cnt < m_combinedObjectDimension){
366 maxCombinations *= columnSize;
370 float bestCombinedCandVal = -1;
371 while ( cnt < maxCombinations){
375 std::vector<int> currentCombinationCopy(currentCombination);
376 std::vector<int>::iterator it;
377 std::sort(currentCombinationCopy.begin(), currentCombinationCopy.end());
378 it = std::unique(currentCombinationCopy.begin(), currentCombinationCopy.end());
379 currentCombinationCopy.resize(
std::distance(currentCombinationCopy.begin(),it) );
380 bool duplicatesPresent = currentCombination.size() != currentCombinationCopy.size();
384 if (!duplicatesPresent) {
385 std::vector<TOutputCandidateType > currentCombinationFromCands;
386 for (
int i = 0;
i<m_combinedObjectDimension;++
i){
387 currentCombinationFromCands.push_back( cands.at(currentCombination.at(
i)));
389 bool isOK = m_combinedObjectSelection(currentCombinationFromCands);
391 float curVal = m_combinedObjectSortFunction(currentCombinationFromCands);
394 edm::LogError(
"FSQDiJetAve") <<
"Problem: ranking function returned negative value: " << curVal << std::endl;
395 }
else if (curVal > bestCombinedCandVal){
397 bestCombinedCandVal = curVal;
398 bestCombination = currentCombination;
404 currentCombination.at(m_combinedObjectDimension-1)+=1;
406 for (
int i = m_combinedObjectDimension-1;
i>=0; --
i){
407 currentCombination.at(
i)+= carry;
409 if (currentCombination.at(
i)>=columnSize){
411 currentCombination.at(
i) = 0;
416 std::vector<TOutputCandidateType > bestCombinationFromCands;
417 if (bestCombination.size()!=0 && bestCombination.at(0)>=0){
418 for (
int i = 0;
i<m_combinedObjectDimension;++
i){
419 bestCombinationFromCands.push_back( cands.at(bestCombination.at(
i)));
422 return bestCombinationFromCands;
441 std::vector<reco::Candidate::LorentzVector> & cands,
449 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
451 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
454 for (
size_t i = 0;
i<hIn->size(); ++
i) {
455 bool preselection = m_singleObjectSelection(hIn->at(
i).p4());
457 fillSingleObjectPlots(hIn->at(
i).p4(),
weight);
458 cands.push_back(hIn->at(
i).p4());
472 std::vector<int > & cands,
480 cands.push_back(count<reco::Track>(iEvent, m_input, m_singleObjectSelection, weight) );
485 std::vector<int > & cands,
490 cands.push_back(count<reco::GenParticle>(iEvent, m_input, m_singleObjectSelection, weight) );
515 std::vector<int > & cands,
523 static const int lMinNDOF = m_pset.getParameter<
int>(
"minNDOF");
524 static const double lMaxZ = m_pset.getParameter<
double>(
"maxZ");
525 static const double lMaxDZ = m_pset.getParameter<
double>(
"maxDZ");
526 static const double lMaxDZ2dzsigma = m_pset.getParameter<
double>(
"maxDZ2dzsigma");
527 static const double lMaxDXY = m_pset.getParameter<
double>(
"maxDXY");
528 static const double lMaxDXY2dxysigma = m_pset.getParameter<
double>(
"maxDXY2dxysigma");
538 double dxy, dz, dzsigma, dxysigma;
540 double vzErr =0.0, vxErr=0.0, vyErr=0.0;
544 for (
size_t i = 0;
i < vertices->size(); ++
i){
545 if (vertices->at(
i).ndof()<lMinNDOF)
continue;
546 if (fabs(vertices->at(
i).z())> lMaxZ)
continue;
548 vtxPoint=vertices->at(
i).position();
549 vzErr=vertices->at(
i).zError();
550 vxErr=vertices->at(
i).xError();
551 vyErr=vertices->at(
i).yError();
555 if (bestVtx < 0)
return;
559 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
561 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
565 for (
size_t i = 0;
i<hIn->size(); ++
i) {
566 if (!m_singleObjectSelection(hIn->at(
i)))
continue;
567 dxy=0.0, dz=0.0, dxysigma=0.0, dzsigma=0.0;
568 dxy = -1.*hIn->at(
i).dxy(vtxPoint);
569 dz = hIn->at(
i).dz(vtxPoint);
570 dxysigma =
sqrt(hIn->at(
i).dxyError()*hIn->at(
i).dxyError()+vxErr*vyErr);
571 dzsigma =
sqrt(hIn->at(
i).dzError()*hIn->at(
i).dzError()+vzErr*vzErr);
573 if(fabs(dz)>lMaxDZ)
continue;
574 if(fabs(dz/dzsigma)>lMaxDZ2dzsigma)
continue;
575 if(fabs(dxy)>lMaxDXY)
continue;
576 if(fabs(dxy/dxysigma)>lMaxDXY2dxysigma)
continue;
602 std::vector<reco::PFJet > & cands,
614 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
617 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
621 for (
size_t i = 0;
i<hIn->size(); ++
i) {
622 double scale = pfcorrector->correction(hIn->at(
i));
623 reco::PFJet newPFJet(scale*hIn->at(
i).p4(), hIn->at(
i).vertex(),
624 hIn->at(
i).getSpecific(), hIn->at(
i).getJetConstituents());
628 fillSingleObjectPlots(newPFJet, weight);
629 cands.push_back(newPFJet);
649 std::vector<int > & cands,
660 iEvent.
getByToken(m_tokens[m_input.encode()], hIn);
662 edm::LogError(
"FSQDiJetAve") <<
"product not found: "<< m_input.encode();
665 for (
size_t i = 0;
i<hIn->size(); ++
i) {
666 bool preselection = m_singleObjectSelection(hIn->at(
i).p4());
668 fillSingleObjectPlots(hIn->at(
i).p4(),
weight);
681 std::vector<trigger::TriggerObject> &cands,
689 std::string filterFullName = findPathAndFilter(hltConfig)[1];
690 if (filterFullName ==
"") {
701 edm::LogInfo(
"FSQDiJetAve") <<
"Cannot determine hlt index for |" << filterFullName <<
"|" <<
process;
708 trigger::Keys::const_iterator kj = khlt.begin();
710 for(;kj != khlt.end(); ++kj){
713 fillSingleObjectPlots(toc[*kj], weight);
714 cands.push_back( toc[*kj]);
739 m_eventCache(iConfig.
getParameterSet(
"triggerConfiguration") , consumesCollector())
754 std::vector< edm::ParameterSet > todo = iConfig.
getParameter< std::vector< edm::ParameterSet > >(
"todo");
755 for (
size_t i = 0;
i < todo.size(); ++
i) {
758 if (type ==
"FromHLT") {
761 else if (type ==
"RecoCandidateCounter") {
764 else if (type ==
"RecoTrackCounter") {
767 else if (type ==
"RecoTrackCounterWithVertexConstraint") {
768 m_handlers.push_back(std::shared_ptr<FSQ::RecoTrackCounterWithVertexConstraint>
771 else if (type ==
"FromRecoCandidate") {
774 else if (type ==
"RecoPFJet") {
777 else if (type ==
"RecoPFJetWithJEC") {
780 else if (type ==
"RecoTrack") {
783 else if (type ==
"RecoPhoton") {
786 else if (type ==
"RecoMuon") {
789 else if (type ==
"RecoGenParticleCounter") {
792 else if (type ==
"RecoGenParticleHandler") {
813 edm::LogError(
"FSQDiJetAve") <<
"Could not setup the filter";
821 edm::LogError(
"FSQDiJetAve") <<
"TriggerResults not valid, skippng event";
839 edm::LogInfo(
"FSQDiJetAve") <<
"TriggerEvent not found, ";
864 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
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
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
Evaluator * parse(const T &text)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
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
const std::string & usedProcessName() const
getters
MonitorElement * book1D(Args &&...args)
tuple preselection
PRESELECTION
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
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)
bool setEvent(const edm::Event &event, const edm::EventSetup &setup)
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
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