CMS 3D CMS Logo

L1UpgradeTfMuonTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1Ntuples
4 // Class: L1UpgradeTfMuonTreeProducer
5 //
11 //
12 // Original Author:
13 // Created:
14 // $Id: L1UpgradeTfMuonTreeProducer.cc,v 1.8 2012/08/29 12:44:03 jbrooke Exp $
15 //
16 //
17 
18 // system include files
19 #include <memory>
20 
21 // framework
28 
29 // data formats
32 
33 // Needed to get BMTF firmware version
37 
38 // ROOT output stuff
41 #include "TTree.h"
42 
45 
46 //
47 // class declaration
48 //
49 
50 class L1UpgradeTfMuonTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
51 public:
53  ~L1UpgradeTfMuonTreeProducer() override = default;
54 
55 private:
56  void beginJob(void) override;
57  void analyze(const edm::Event&, const edm::EventSetup&) override;
58  void endJob() override;
59 
60 public:
71 
72 private:
74  bool isEMU_;
75 
76  // output file
78 
79  // tree
80  TTree* tree_;
81 
82  // EDM input tags
88 
91 
92  // EDM handles
94 
95  unsigned getAlgoFwVersion();
96 };
97 
99  : fedToken_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("feds"))),
100  bmtfMuonToken_(
101  consumes<l1t::RegionalMuonCandBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("bmtfMuonToken"))),
102  bmtf2MuonToken_(
103  consumes<l1t::RegionalMuonCandBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("bmtf2MuonToken"))),
104  omtfMuonToken_(
105  consumes<l1t::RegionalMuonCandBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("omtfMuonToken"))),
106  emtfMuonToken_(
107  consumes<l1t::RegionalMuonCandBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("emtfMuonToken"))),
108  bmtfPhInputToken_(
109  consumes<L1MuDTChambPhContainer>(iConfig.getUntrackedParameter<edm::InputTag>("bmtfInputPhMuonToken"))),
110  bmtfThInputToken_(
111  consumes<L1MuDTChambThContainer>(iConfig.getUntrackedParameter<edm::InputTag>("bmtfInputThMuonToken"))) {
112  isEMU_ = iConfig.getParameter<bool>("isEMU");
113  maxL1UpgradeTfMuon_ = iConfig.getParameter<unsigned int>("maxL1UpgradeTfMuon");
114 
120 
121  usesResource(TFileService::kSharedResource);
122 
123  // set up output
124  tree_ = fs_->make<TTree>("L1UpgradeTfMuonTree", "L1UpgradeTfMuonTree");
125  tree_->Branch("L1UpgradeBmtfMuon", "L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat", &l1UpgradeBmtfData, 32000, 3);
126  tree_->Branch("L1UpgradeKBmtfMuon", "L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat", &l1UpgradeKBmtfData, 32000, 3);
127  tree_->Branch("L1UpgradeOmtfMuon", "L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat", &l1UpgradeOmtfData, 32000, 3);
128  tree_->Branch("L1UpgradeEmtfMuon", "L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat", &l1UpgradeEmtfData, 32000, 3);
129 
130  tree_->Branch(
131  "L1UpgradeBmtfInputs", "L1Analysis::L1AnalysisBMTFInputsDataFormat", &l1UpgradeBmtfInputsData, 32000, 3);
132 }
133 
134 //
135 // member functions
136 //
137 
138 // ------------ method called to for each event ------------
142  if (isEMU_) {
143  legacybmtfMuonToken = bmtfMuonToken_;
144  kbmtfMuonToken = bmtf2MuonToken_;
145  } else {
146  iEvent.getByToken(fedToken_, feds_);
147  // Get fw version
148  unsigned algoFwVersion{getAlgoFwVersion()};
149  if (algoFwVersion < 2499805536) { //95000160(hex)
150  // Legacy was triggering (and therefore in the main collection)
151  legacybmtfMuonToken = bmtfMuonToken_;
152  kbmtfMuonToken = bmtf2MuonToken_;
153  } else {
154  // kBMTF was triggering
155  legacybmtfMuonToken = bmtf2MuonToken_;
156  kbmtfMuonToken = bmtfMuonToken_;
157  }
158  }
159 
167 
174 
175  iEvent.getByToken(legacybmtfMuonToken, bmtfMuon);
176  iEvent.getByToken(kbmtfMuonToken, kbmtfMuon);
177  iEvent.getByToken(omtfMuonToken_, omtfMuon);
178  iEvent.getByToken(emtfMuonToken_, emtfMuon);
179  iEvent.getByToken(bmtfPhInputToken_, bmtfPhInputs);
180  iEvent.getByToken(bmtfThInputToken_, bmtfThInputs);
181 
182  if (bmtfMuon.isValid()) {
184  } else {
185  edm::LogWarning("MissingProduct") << "L1Upgrade BMTF muons not found. Branch will not be filled" << std::endl;
186  }
187 
188  if (kbmtfMuon.isValid()) {
190  } else {
191  edm::LogWarning("MissingProduct") << "L1Upgrade kBMTF muons not found. Branch will not be filled" << std::endl;
192  }
193 
194  if (omtfMuon.isValid()) {
196  } else {
197  edm::LogWarning("MissingProduct") << "L1Upgrade OMTF muons not found. Branch will not be filled" << std::endl;
198  }
199 
200  if (emtfMuon.isValid()) {
202  } else {
203  edm::LogWarning("MissingProduct") << "L1Upgrade EMTF muons not found. Branch will not be filled" << std::endl;
204  }
205 
206  int max_inputs = maxL1UpgradeTfMuon_ * 4;
207 
208  if (!bmtfPhInputs.isValid()) {
209  edm::LogWarning("MissingProduct") << "L1Upgrade BMTF Ph Inputs not found. Branch will not be filled" << std::endl;
210  } else
211  l1UpgradeBmtfInputs.SetBMPH(bmtfPhInputs, max_inputs);
212 
213  if (!bmtfThInputs.isValid()) {
214  edm::LogWarning("MissingProduct") << "L1Upgrade BMTF Th Inputs not found. Branch will not be filled" << std::endl;
215  } else
216  l1UpgradeBmtfInputs.SetBMTH(bmtfThInputs, max_inputs);
217 
218  tree_->Fill();
219 }
220 
221 // ------------ method called once each job just before starting event loop ------------
223 
224 // ------------ method called once each job just after ending the event loop ------------
226 
228  int nonEmptyFed = 0;
229  if (feds_->FEDData(1376).size() > 0)
230  nonEmptyFed = 1376;
231  else if (feds_->FEDData(1377).size() > 0)
232  nonEmptyFed = 1377;
233  else {
234  edm::LogError("L1UpgradeTfMuonTreeProducer")
235  << "Both BMTF feds (1376, 1377) seem empty, will lead to unexpected results in tree from data.";
236  return 0;
237  }
238 
239  const FEDRawData& l1tRcd = feds_->FEDData(nonEmptyFed);
240  edm::LogInfo("L1UpgradeTfMuonTreeProducer") << "L1T Rcd taken from the FEDData.";
241  edm::LogInfo("L1UpgradeTfMuonTreeProducer") << "l1tRcd.size=" << l1tRcd.size() << " for fed:" << nonEmptyFed;
242 
243  const unsigned char* data = l1tRcd.data();
245 
246  amc13::Packet packet;
247  if (!packet.parse((const uint64_t*)data,
248  (const uint64_t*)(data + 8),
249  (l1tRcd.size()) / 8,
250  header.lvl1ID(),
251  header.bxID(),
252  false,
253  false)) {
254  edm::LogError("L1UpgradeTfMuonTreeProducer") << "Could not extract AMC13 Packet.";
255  return 0;
256  }
257 
258  if (!packet.payload().empty()) {
259  auto payload64 = (packet.payload().at(0)).data();
260  const uint32_t* start = (const uint32_t*)payload64.get();
261  const uint32_t* end = start + (packet.payload().at(0).size() * 2);
262 
263  l1t::MP7Payload payload(start, end, false);
264  return payload.getAlgorithmFWVersion();
265 
266  } else {
267  edm::LogError("L1UpgradeTfMuonTreeProducer") << "AMC13 payload is empty, cannot extract AMC13 Packet.";
268  return 0;
269  }
270 }
271 
272 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
Definition: start.py:1
L1Analysis::L1AnalysisL1UpgradeTfMuon l1UpgradeEmtf
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
~L1UpgradeTfMuonTreeProducer() override=default
L1UpgradeTfMuonTreeProducer(const edm::ParameterSet &)
BXVector< RegionalMuonCand > RegionalMuonCandBxCollection
L1AnalysisBMTFInputsDataFormat * getData()
L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat * l1UpgradeEmtfData
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
const edm::EDGetTokenT< l1t::RegionalMuonCandBxCollection > emtfMuonToken_
delete x;
Definition: CaloConfig.h:22
const edm::EDGetTokenT< l1t::RegionalMuonCandBxCollection > bmtfMuonToken_
const edm::EDGetTokenT< L1MuDTChambThContainer > bmtfThInputToken_
L1Analysis::L1AnalysisL1UpgradeTfMuon l1UpgradeOmtf
Log< level::Error, false > LogError
L1Analysis::L1AnalysisBMTFInputs l1UpgradeBmtfInputs
void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< FEDRawDataCollection > fedToken_
edm::Handle< FEDRawDataCollection > feds_
const edm::EDGetTokenT< l1t::RegionalMuonCandBxCollection > omtfMuonToken_
void SetBMPH(const edm::Handle< L1MuDTChambPhContainer > L1MuDTChambPhContainer, unsigned int maxDTPH)
const edm::EDGetTokenT< l1t::RegionalMuonCandBxCollection > bmtf2MuonToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1Analysis::L1AnalysisL1UpgradeTfMuon l1UpgradeBmtf
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat * l1UpgradeBmtfData
Log< level::Info, false > LogInfo
unsigned long long uint64_t
Definition: Time.h:13
bool parse(const uint64_t *start, const uint64_t *data, unsigned int size, unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
Definition: AMC13Spec.cc:60
L1Analysis::L1AnalysisBMTFInputsDataFormat * l1UpgradeBmtfInputsData
bool isValid() const
Definition: HandleBase.h:70
const edm::EDGetTokenT< L1MuDTChambPhContainer > bmtfPhInputToken_
void SetBMTH(const edm::Handle< L1MuDTChambThContainer > L1MuDTChambThContainer, unsigned int maxDTTH)
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
std::vector< amc::Packet > payload() const
Definition: AMC13Spec.h:92
L1AnalysisL1UpgradeTfMuonDataFormat * getData()
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
L1Analysis::L1AnalysisL1UpgradeTfMuon l1UpgradeKBmtf
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat * l1UpgradeOmtfData
Log< level::Warning, false > LogWarning
edm::Service< TFileService > fs_
void SetTfMuon(const l1t::RegionalMuonCandBxCollection &muon, unsigned maxL1UpgradeTfMuon)
L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat * l1UpgradeKBmtfData