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