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 #include <algorithm>
23 
24 // user include files
34 
37 
40 
42 
45 
47 //
48 // class declaration
49 //
50 
52  public:
54  ~L1TriggerResultsConverter() override;
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58  private:
59  void produce(edm::Event&, const edm::EventSetup&) override;
60  void beginRun(edm::Run const&, edm::EventSetup const&) override;
61 
62  // ----------member data ---------------------------
63  const bool legacyL1_;
68  std::vector<std::string> names_;
69  std::vector<unsigned int> mask_;
70  std::vector<unsigned int> indices_;
71 
72  const unsigned int m_triggerRulePrefireVetoBit=255;
73 };
74 
75 
76 
77 //
78 // constructors and destructor
79 //
81  legacyL1_( params.getParameter<bool>("legacyL1") ),
82  store_unprefireable_bit_(!legacyL1_?params.getParameter<bool>("storeUnprefireableBit"):false),
83  tokenLegacy_(legacyL1_?consumes<L1GlobalTriggerReadoutRecord>( params.getParameter<edm::InputTag>("src") ): edm::EDGetTokenT<L1GlobalTriggerReadoutRecord>()),
84  token_(!legacyL1_?consumes<GlobalAlgBlkBxCollection>( params.getParameter<edm::InputTag>("src") ): edm::EDGetTokenT<GlobalAlgBlkBxCollection>()),
85  token_ext_(store_unprefireable_bit_?consumes<GlobalExtBlkBxCollection> (params.getParameter<edm::InputTag>("src_ext") ): edm::EDGetTokenT<GlobalExtBlkBxCollection>())
86 {
87  produces<edm::TriggerResults>();
88 }
89 
90 
92 {
93 
94  // do anything here that needs to be done at destruction time
95  // (e.g. close files, deallocate resources etc.)
96 
97 }
98 
99 
100 //
101 // member functions
102 //
103 
105  mask_.clear();
106  names_.clear();
107  indices_.clear();
108  if(legacyL1_){
110  edm::ESHandle<L1GtTriggerMask> handleAlgoMask;
111  setup.get<L1GtTriggerMenuRcd>().get(handleMenu);
112  auto const & mapping = handleMenu->gtAlgorithmAliasMap();
113  for (auto const & keyval: mapping) {
114  names_.push_back(keyval.first);
115  indices_.push_back(keyval.second.algoBitNumber());
116  }
117  setup.get<L1GtTriggerMaskAlgoTrigRcd>().get(handleAlgoMask);
118  mask_ = handleAlgoMask->gtTriggerMask();
119  } else {
121  setup.get<L1TUtmTriggerMenuRcd>().get(menu);
122  auto const & mapping = menu->getAlgorithmMap();
123  for (auto const & keyval: mapping) {
124  names_.push_back(keyval.first);
125  indices_.push_back(keyval.second.getIndex());
126  }
127  if (store_unprefireable_bit_) names_.push_back("L1_UnprefireableEvent");
128  }
129 
130 }
131 
132 // ------------ method called to produce the data ------------
133 
134 
135 void
137 {
138  using namespace edm;
139  const std::vector<bool> * wordp=nullptr;
140  bool unprefireable_bit = false;
141  if (!legacyL1_){
143  iEvent.getByToken(token_, handleResults);
144  wordp= & handleResults->at(0,0).getAlgoDecisionFinal() ;
146  edm::Handle<GlobalExtBlkBxCollection> handleExtResults;
147  iEvent.getByToken(token_ext_, handleExtResults);
148  unprefireable_bit = handleExtResults->at(0,0).getExternalDecision(std::max(m_triggerRulePrefireVetoBit,GlobalExtBlk::maxExternalConditions-1));
149  }
150  } else {
151 // Legacy access
153  iEvent.getByToken(tokenLegacy_, handleResults);
154  wordp = & handleResults->decisionWord();
155  }
156  auto const &word = *wordp;
157  HLTGlobalStatus l1bitsAsHLTStatus(names_.size());
158  unsigned indices_size = indices_.size();
159  for(size_t nidx=0;nidx<indices_size; nidx++) {
160  unsigned int index = indices_[nidx];
161  bool result =word[index];
162  if(!mask_.empty()) result &= (mask_[index] !=0);
163  l1bitsAsHLTStatus[nidx]=HLTPathStatus(result?edm::hlt::Pass:edm::hlt::Fail);
164  }
165  if (store_unprefireable_bit_) l1bitsAsHLTStatus[indices_size]=HLTPathStatus(unprefireable_bit?edm::hlt::Pass:edm::hlt::Fail);
166  //mimic HLT trigger bits for L1
167  auto out = std::make_unique<edm::TriggerResults>(l1bitsAsHLTStatus,names_);
168  iEvent.put(std::move(out));
169 
170 }
171 
172 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
173 void
176  desc.add<bool>("legacyL1")->setComment("is legacy L1");
177  desc.add<edm::InputTag>("src")->setComment("L1 input (L1GlobalTriggerReadoutRecord if legacy, GlobalAlgBlkBxCollection otherwise)");
178  desc.add<bool>("storeUnprefireableBit",false)->setComment("Activate storage of L1 unprefireable bit (needs L1 external decision input)");
179  desc.add<edm::InputTag>("src_ext",edm::InputTag(""))->setComment("L1 external decision input (GlobalExtBlkBxCollection, only supported if not legacy");
180  descriptions.add("L1TriggerResultsConverter",desc);
181 }
182 
183 //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:125
static const unsigned int maxExternalConditions
Definition: GlobalExtBlk.h:47
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
reject
Definition: HLTenums.h:20
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
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:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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 edm::EDGetTokenT< GlobalExtBlkBxCollection > token_ext_
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:71
const AlgorithmMap & gtAlgorithmAliasMap() const
get / set the algorithm map (by alias)
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
const unsigned int m_triggerRulePrefireVetoBit
const T & at(int bx, unsigned i) const