CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CandidateTriggerObjectProducer.cc
Go to the documentation of this file.
7 
8 #include "TString.h"
9 #include "TRegexp.h"
10 
11 #include <cassert>
12 
14 
15 
16 //
17 // constructors and destructor
18 //
20  triggerResultsToken_(consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("triggerResults"))),
21  triggerEventTag_(ps.getParameter<edm::InputTag>("triggerEvent")),
22  triggerEventToken_(consumes<trigger::TriggerEvent>(triggerEventTag_)),
23  triggerName_(ps.getParameter<std::string>("triggerName"))
24 {
25 
26 // cout << "Trigger Object Producer:" << endl
27 // << " TriggerResultsTag = " << triggerResultsTag_.encode() << endl
28 // << " TriggerEventTag = " << triggerEventTag_.encode() << endl;
29 
30  produces<reco::CandidateCollection>();
31 
32 }
33 
35 {
36 }
37 
38 //
39 // member functions
40 //
41 void
43 {
44  using namespace edm;
45 
46  bool changed(false);
47  if(!hltConfig_.init(iRun,iSetup,triggerEventTag_.process(),changed) ){
48  edm::LogError( "CandidateTriggerObjectProducer" ) <<
49  "Error! Can't initialize HLTConfigProvider";
50  throw cms::Exception("HLTConfigProvider::init() returned non 0");
51  }
52 
53  return;
54 
55 }
56 
57 // ------------ method called to produce the data ------------
58 void
60 {
61  using namespace edm;
62  using namespace reco;
63  using namespace trigger;
64 
65  std::auto_ptr<reco::CandidateCollection> coll( new reco::CandidateCollection );
66 
67  // get event products
70  edm::LogError( "CandidateTriggerObjectProducer" ) << "CandidateTriggerObjectProducer::analyze: Error in getting TriggerResults product from Event!" ;
71  return;
72  }
75  edm::LogError( "CandidateTriggerObjectProducer" ) << "CandidateTriggerObjectProducer::analyze: Error in getting TriggerEvent product from Event!" ;
76  return;
77  }
78  // sanity check
79  // std::cout << hltConfig_.size() << std::endl;
80  // std::cout << triggerResultsHandle_->size() << std::endl;
82 
83  const unsigned int n(hltConfig_.size());
84  std::vector<std::string> activeHLTPathsInThisEvent = hltConfig_.triggerNames();
85  std::map<std::string, bool> triggerInMenu;
86  std::map<std::string, bool> triggerUnprescaled;
87 
88  for (std::vector<std::string>::const_iterator iHLT = activeHLTPathsInThisEvent.begin();
89  iHLT != activeHLTPathsInThisEvent.end(); ++iHLT)
90  {
91  //matching with regexp filter name. More than 1 matching filter is allowed
92  if (TString(*iHLT).Contains(TRegexp(TString(triggerName_))))
93  {
94  triggerInMenu[*iHLT] = true;
95  const std::pair<int,int> prescales(hltConfig_.prescaleValues(iEvent,iSetup,*iHLT));
96  if (prescales.first * prescales.second == 1)
97  triggerUnprescaled[*iHLT] = true;
98  }
99  }
100 
101  for (std::map<std::string, bool>::const_iterator iMyHLT = triggerInMenu.begin();
102  iMyHLT != triggerInMenu.end(); ++iMyHLT)
103  {
104  //using only unprescaled triggers
105  if (!(iMyHLT->second && triggerUnprescaled[iMyHLT->first]))
106  continue;
107  const unsigned int triggerIndex(hltConfig_.triggerIndex(iMyHLT->first));
108 
109  assert(triggerIndex==iEvent.triggerNames(*triggerResultsHandle_).triggerIndex(iMyHLT->first));
110 
111  // abort on invalid trigger name
112  if (triggerIndex>=n) {
113  edm::LogError( "CandidateTriggerObjectProducer" ) << "CandidateTriggerObjectProducer::analyzeTrigger: path "
114  << triggerName_ << " - not found!" ;
115  return;
116  }
117 
118  // modules on this trigger path
119  // const unsigned int m(hltConfig_.size(triggerIndex));
120  const std::vector<std::string>& moduleLabels(hltConfig_.saveTagsModules(triggerIndex));
121 
122  // Results from TriggerResults product
123  if (!(triggerResultsHandle_->wasrun(triggerIndex)) ||
124  !(triggerResultsHandle_->accept(triggerIndex)) ||
125  (triggerResultsHandle_->error(triggerIndex)))
126  {
127  continue;
128  }
129 
130 // const unsigned int moduleIndex(triggerResultsHandle_->index(triggerIndex));
131 
132 // assert (moduleIndex<m);
133 
134  // Results from TriggerEvent product - Looking only on last filter since trigger is accepted
135  for (unsigned int imodule=0;imodule<moduleLabels.size();++imodule)
136  {
137  const std::string& moduleLabel(moduleLabels[imodule]);
138  const std::string moduleType(hltConfig_.moduleType(moduleLabel));
139  //Avoiding L1 seeds
140  if (moduleType.find("Level1GTSeed") != std::string::npos)
141  continue;
142  // check whether the module is packed up in TriggerEvent product
143  const unsigned int filterIndex(triggerEventHandle_->filterIndex(InputTag(moduleLabel,"",triggerEventTag_.process())));
144  if (filterIndex<triggerEventHandle_->sizeFilters()) {
145  // std::cout << " 'L3' filter in slot " << imodule << " - label/type " << moduleLabel << "/" << moduleType << std::endl;
146  const Vids& VIDS (triggerEventHandle_->filterIds(filterIndex));
147  const Keys& KEYS(triggerEventHandle_->filterKeys(filterIndex));
148  const size_type nI(VIDS.size());
149  const size_type nK(KEYS.size());
150  assert(nI==nK);
151  const size_type n(std::max(nI,nK));
152  // std::cout << " " << n << " accepted 'L3' objects found: " << std::endl;
153  const TriggerObjectCollection& TOC(triggerEventHandle_->getObjects());
154  for (size_type i=0; i!=n; ++i) {
155  const TriggerObject& TO(TOC[KEYS[i]]);
156  coll->push_back(reco::LeafCandidate( 0, TO.particle().p4(), reco::Particle::Point( 0., 0., 0. ), TO.id() ));
157 // std::cout << " " << i << " " << VIDS[i] << "/" << KEYS[i] << ": "
158 // << TO.id() << " " << TO.pt() << " " << TO.eta() << " " << TO.phi() << " " << TO.mass()
159 // << std::endl;
160  }
161  }
162  }
163  }
164 
165 
166  iEvent.put(coll);
167  return;
168 }
169 
171 
173 
174 
unsigned int size() const
number of trigger paths in trigger table
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:208
const std::string moduleType(const std::string &module) const
C++ class name of module.
int id() const
getters
Definition: TriggerObject.h:55
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
const std::vector< std::string > & triggerNames() const
names of trigger paths
reco::Particle particle(reco::Particle::Charge q=0, const reco::Particle::Point &vertex=reco::Particle::Point(0, 0, 0), int status=0, bool integerCharge=true) const
Definition: TriggerObject.h:69
edm::Handle< edm::TriggerResults > triggerResultsHandle_
additional class data memebers
CandidateTriggerObjectProducer(const edm::ParameterSet &)
edm::EDGetTokenT< edm::TriggerResults > triggerResultsToken_
const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: Particle.h:72
uint16_t size_type
edm::Handle< trigger::TriggerEvent > triggerEventHandle_
triggerResultsToken_(consumes< edm::TriggerResults >(edm::InputTag("TriggerResults")))
const std::vector< std::string > & saveTagsModules(unsigned int trigger) const
unsigned int triggerIndex(const std::string &triggerName) const
slot position of trigger path in trigger table (0 to size-1)
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
tuple TriggerResults
Definition: old-fu_pass.py:28
int iEvent
Definition: GenABIO.cc:230
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
virtual void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< trigger::TriggerEvent > triggerEventToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
math::XYZPoint Point
point in the space
Definition: Particle.h:25
bool isValid() const
Definition: HandleBase.h:75
virtual void beginRun(const edm::Run &iRun, edm::EventSetup const &iSetup) override
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
JetCorrectorParametersCollection coll
Definition: classes.h:10
std::vector< size_type > Keys
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::pair< int, int > prescaleValues(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger) const
Combined L1T (pair.first) and HLT (pair.second) prescales per HLT path.
std::string const & process() const
Definition: InputTag.h:46
std::vector< int > Vids
Definition: Run.h:41