CMS 3D CMS Logo

L1TriggerResultsConverter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: L1TriggerResultsConverter
5 //
13 //
14 // Original Author: Andrea Rizzi
15 // Created: Mon, 11 Aug 2017 11:20:30 GMT
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
33 
35 
38 
41 
44 
46 //
47 // class declaration
48 //
49 
51  public:
53  ~L1TriggerResultsConverter() override;
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57  private:
58  void produce(edm::Event&, const edm::EventSetup&) override;
59  void beginRun(edm::Run const&, edm::EventSetup const&) override;
60 
61  // ----------member data ---------------------------
62  const bool legacyL1_;
65  std::vector<std::string> names_;
66  std::vector<unsigned int> mask_;
67  std::vector<unsigned int> indices_;
68 };
69 
70 
71 
72 //
73 // constructors and destructor
74 //
76  legacyL1_( params.getParameter<bool>("legacyL1") ),
77  tokenLegacy_(legacyL1_?consumes<L1GlobalTriggerReadoutRecord>( params.getParameter<edm::InputTag>("src") ): edm::EDGetTokenT<L1GlobalTriggerReadoutRecord>()),
78  token_(!legacyL1_?consumes<GlobalAlgBlkBxCollection>( params.getParameter<edm::InputTag>("src") ): edm::EDGetTokenT<GlobalAlgBlkBxCollection>())
79 {
80  produces<edm::TriggerResults>();
81 }
82 
83 
85 {
86 
87  // do anything here that needs to be done at destruction time
88  // (e.g. close files, deallocate resources etc.)
89 
90 }
91 
92 
93 //
94 // member functions
95 //
96 
98  mask_.clear();
99  names_.clear();
100  indices_.clear();
101  if(legacyL1_){
103  edm::ESHandle<L1GtTriggerMask> handleAlgoMask;
104  setup.get<L1GtTriggerMenuRcd>().get(handleMenu);
105  auto const & mapping = handleMenu->gtAlgorithmAliasMap();
106  for (auto const & keyval: mapping) {
107  names_.push_back(keyval.first);
108  indices_.push_back(keyval.second.algoBitNumber());
109  }
110  setup.get<L1GtTriggerMaskAlgoTrigRcd>().get(handleAlgoMask);
111  mask_ = handleAlgoMask->gtTriggerMask();
112  } else {
114  setup.get<L1TUtmTriggerMenuRcd>().get(menu);
115  auto const & mapping = menu->getAlgorithmMap();
116  for (auto const & keyval: mapping) {
117  names_.push_back(keyval.first);
118  indices_.push_back(keyval.second.getIndex());
119  }
120 
121  }
122 }
123 
124 // ------------ method called to produce the data ------------
125 
126 
127 void
129 {
130  using namespace edm;
131  const std::vector<bool> * wordp=nullptr;
132  if (!legacyL1_){
134  iEvent.getByToken(token_, handleResults);
135  wordp= & handleResults->at(0,0).getAlgoDecisionFinal() ;
136  } else {
137 // Legacy access
139  iEvent.getByToken(tokenLegacy_, handleResults);
140  wordp = & handleResults->decisionWord();
141  }
142  auto const &word = *wordp;
143  HLTGlobalStatus l1bitsAsHLTStatus(names_.size());
144 // std::cout << word.size() << " " << names_.size() << " " << mask_.size() << std::endl;
145  unsigned indices_size = indices_.size();
146  for(size_t nidx=0;nidx<indices_size; nidx++) {
147  unsigned int index = indices_[nidx];
148  bool result =word[index];
149  if(!mask_.empty()) result &= (mask_[index] !=0);
150  l1bitsAsHLTStatus[nidx]=HLTPathStatus(result?edm::hlt::Pass:edm::hlt::Fail);
151  }
152  //mimic HLT trigger bits for L1
153  auto out = std::make_unique<edm::TriggerResults>(l1bitsAsHLTStatus,names_);
154  iEvent.put(std::move(out));
155 
156 }
157 
158 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
159 void
162  desc.add<bool>("legacyL1")->setComment("is legacy L1");
163  desc.add<edm::InputTag>("src")->setComment("L1 input (L1GlobalTriggerReadoutRecord if legacy, GlobalAlgBlkBxCollection otherwise)");
164  descriptions.add("L1TriggerResultsConverter",desc);
165 }
166 
167 //define this as a plug-in
std::vector< unsigned int > indices_
std::vector< std::string > names_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
std::vector< bool > const & getAlgoDecisionFinal() const
Definition: GlobalAlgBlk.h:90
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
reject
Definition: HLTenums.h:20
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginRun(edm::Run const &, edm::EventSetup const &) override
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
accept
Definition: HLTenums.h:19
const std::vector< unsigned int > & gtTriggerMask() const
get the trigger mask
const edm::EDGetTokenT< GlobalAlgBlkBxCollection > token_
L1TriggerResultsConverter(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const DecisionWord & decisionWord(int bxInEventValue) const
const edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > tokenLegacy_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< unsigned int > mask_
const std::map< std::string, L1TUtmAlgorithm > & getAlgorithmMap() const
HLT enums.
T get() const
Definition: EventSetup.h:63
const AlgorithmMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:44
const T & at(int bx, unsigned i) const