CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
51 public:
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  isEMU_ = iConfig.getParameter<bool>("isEMU");
100  fedToken_ = consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("feds"));
102  consumes<l1t::RegionalMuonCandBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("bmtfMuonToken"));
104  consumes<l1t::RegionalMuonCandBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("bmtf2MuonToken"));
106  consumes<l1t::RegionalMuonCandBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("omtfMuonToken"));
108  consumes<l1t::RegionalMuonCandBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("emtfMuonToken"));
110  consumes<L1MuDTChambPhContainer>(iConfig.getUntrackedParameter<edm::InputTag>("bmtfInputPhMuonToken"));
112  consumes<L1MuDTChambThContainer>(iConfig.getUntrackedParameter<edm::InputTag>("bmtfInputThMuonToken"));
113 
114  maxL1UpgradeTfMuon_ = iConfig.getParameter<unsigned int>("maxL1UpgradeTfMuon");
115 
121 
122  // set up output
123  tree_ = fs_->make<TTree>("L1UpgradeTfMuonTree", "L1UpgradeTfMuonTree");
124  tree_->Branch("L1UpgradeBmtfMuon", "L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat", &l1UpgradeBmtfData, 32000, 3);
125  tree_->Branch("L1UpgradeKBmtfMuon", "L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat", &l1UpgradeKBmtfData, 32000, 3);
126  tree_->Branch("L1UpgradeOmtfMuon", "L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat", &l1UpgradeOmtfData, 32000, 3);
127  tree_->Branch("L1UpgradeEmtfMuon", "L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat", &l1UpgradeEmtfData, 32000, 3);
128 
129  tree_->Branch(
130  "L1UpgradeBmtfInputs", "L1Analysis::L1AnalysisBMTFInputsDataFormat", &l1UpgradeBmtfInputsData, 32000, 3);
131 }
132 
134 
135 //
136 // member functions
137 //
138 
139 // ------------ method called to for each event ------------
143  if (isEMU_) {
144  legacybmtfMuonToken = bmtfMuonToken_;
145  kbmtfMuonToken = bmtf2MuonToken_;
146  } else {
147  iEvent.getByToken(fedToken_, feds_);
148  // Get fw version
149  unsigned algoFwVersion{getAlgoFwVersion()};
150  if (algoFwVersion < 2499805536) { //95000160(hex)
151  // Legacy was triggering (and therefore in the main collection)
152  legacybmtfMuonToken = bmtfMuonToken_;
153  kbmtfMuonToken = bmtf2MuonToken_;
154  } else {
155  // kBMTF was triggering
156  legacybmtfMuonToken = bmtf2MuonToken_;
157  kbmtfMuonToken = bmtfMuonToken_;
158  }
159  }
160 
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();
244  FEDHeader header(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
std::vector< amc::Packet > payload() const
Definition: AMC13Spec.h:92
T getUntrackedParameter(std::string const &, T const &) const
L1Analysis::L1AnalysisL1UpgradeTfMuon l1UpgradeEmtf
edm::EDGetTokenT< l1t::RegionalMuonCandBxCollection > bmtf2MuonToken_
L1UpgradeTfMuonTreeProducer(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
L1AnalysisBMTFInputsDataFormat * getData()
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat * l1UpgradeEmtfData
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
L1Analysis::L1AnalysisL1UpgradeTfMuon l1UpgradeOmtf
Log< level::Error, false > LogError
L1Analysis::L1AnalysisBMTFInputs l1UpgradeBmtfInputs
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< FEDRawDataCollection > fedToken_
edm::Handle< FEDRawDataCollection > feds_
edm::EDGetTokenT< L1MuDTChambThContainer > bmtfThInputToken_
edm::EDGetTokenT< l1t::RegionalMuonCandBxCollection > bmtfMuonToken_
edm::EDGetTokenT< l1t::RegionalMuonCandBxCollection > omtfMuonToken_
void SetBMPH(const edm::Handle< L1MuDTChambPhContainer > L1MuDTChambPhContainer, unsigned int maxDTPH)
bool isValid() const
Definition: HandleBase.h:70
L1Analysis::L1AnalysisL1UpgradeTfMuon l1UpgradeBmtf
edm::EDGetTokenT< L1MuDTChambPhContainer > bmtfPhInputToken_
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
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1Analysis::L1AnalysisBMTFInputsDataFormat * l1UpgradeBmtfInputsData
uint16_t bxID() const
The bunch crossing number.
Definition: FEDHeader.cc:17
void SetBMTH(const edm::Handle< L1MuDTChambThContainer > L1MuDTChambThContainer, unsigned int maxDTTH)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
L1AnalysisL1UpgradeTfMuonDataFormat * getData()
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
edm::EDGetTokenT< l1t::RegionalMuonCandBxCollection > emtfMuonToken_
string end
Definition: dataset.py:937
L1Analysis::L1AnalysisL1UpgradeTfMuon l1UpgradeKBmtf
uint32_t lvl1ID() const
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:15
L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat * l1UpgradeOmtfData
Log< level::Warning, false > LogWarning
edm::Service< TFileService > fs_
void SetTfMuon(const l1t::RegionalMuonCandBxCollection &muon, unsigned maxL1UpgradeTfMuon)
L1Analysis::L1AnalysisL1UpgradeTfMuonDataFormat * l1UpgradeKBmtfData