CMS 3D CMS Logo

GEMRawToDigiModule.cc
Go to the documentation of this file.
1 
30 
31 class GEMRawToDigiModule : public edm::global::EDProducer<edm::RunCache<GEMChMap>> {
32 public:
35 
36  // global::EDProducer
37  std::shared_ptr<GEMChMap> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
38  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
39  void globalEndRun(edm::Run const&, edm::EventSetup const&) const override{};
40 
41  // Fill parameters descriptions
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44 private:
48  unsigned int fedIdStart_, fedIdEnd_;
49  std::unique_ptr<GEMRawToDigi> gemRawToDigi_;
50 };
51 
54 
56  : fed_token(consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("InputLabel"))),
57  useDBEMap_(pset.getParameter<bool>("useDBEMap")),
58  keepDAQStatus_(pset.getParameter<bool>("keepDAQStatus")),
59  readMultiBX_(pset.getParameter<bool>("readMultiBX")),
60  ge21Off_(pset.getParameter<bool>("ge21Off")),
61  fedIdStart_(pset.getParameter<unsigned int>("fedIdStart")),
62  fedIdEnd_(pset.getParameter<unsigned int>("fedIdEnd")),
63  gemRawToDigi_(std::make_unique<GEMRawToDigi>()) {
64  produces<GEMDigiCollection>();
65  if (keepDAQStatus_) {
66  produces<GEMAMC13StatusCollection>("AMC13Status");
67  produces<GEMAMCStatusCollection>("AMCStatus");
68  produces<GEMOHStatusCollection>("OHStatus");
69  produces<GEMVFATStatusCollection>("VFATStatus");
70  }
71  if (useDBEMap_) {
72  gemChMapToken_ = esConsumes<GEMChMap, GEMChMapRcd, edm::Transition::BeginRun>();
73  }
76  } else if (ge21Off_) {
77  edm::LogError("InvalidSettings") << "Turning GE2/1 off requires changing the FEDIDs the GEM unpacker looks at. If "
78  "you wish to set the FEDIDs yourself, don't use the ge21Off switch.";
79  }
80 }
81 
84  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
85  desc.add<bool>("useDBEMap", false);
86  desc.add<bool>("keepDAQStatus", true);
87  desc.add<bool>("readMultiBX", false);
88  desc.add<bool>("ge21Off", false);
89  desc.add<unsigned int>("fedIdStart", FEDNumbering::MINGEMFEDID);
90  desc.add<unsigned int>("fedIdEnd", FEDNumbering::MAXGEMFEDID);
91  descriptions.add("muonGEMDigisDefault", desc);
92 }
93 
94 std::shared_ptr<GEMChMap> GEMRawToDigiModule::globalBeginRun(edm::Run const&, edm::EventSetup const& iSetup) const {
95  if (useDBEMap_) {
96  const auto& eMap = iSetup.getData(gemChMapToken_);
97  auto gemChMap = std::make_shared<GEMChMap>(eMap);
98  return gemChMap;
99  } else {
100  // no EMap in DB, using dummy
101  auto gemChMap = std::make_shared<GEMChMap>();
102  gemChMap->setDummy();
103  return gemChMap;
104  }
105 }
106 
108  auto outGEMDigis = std::make_unique<GEMDigiCollection>();
109  auto outAMC13Status = std::make_unique<GEMAMC13StatusCollection>();
110  auto outAMCStatus = std::make_unique<GEMAMCStatusCollection>();
111  auto outOHStatus = std::make_unique<GEMOHStatusCollection>();
112  auto outVFATStatus = std::make_unique<GEMVFATStatusCollection>();
113 
114  // Take raw from the event
116  iEvent.getByToken(fed_token, fed_buffers);
117 
118  auto gemChMap = runCache(iEvent.getRun().index());
119 
120  for (unsigned int fedId = fedIdStart_; fedId <= fedIdEnd_; ++fedId) {
121  const FEDRawData& fedData = fed_buffers->FEDData(fedId);
122 
123  int nWords = fedData.size() / sizeof(uint64_t);
124  LogDebug("GEMRawToDigiModule") << "fedId:" << fedId << " words: " << nWords;
125  GEMAMC13Status st_amc13(fedData);
126  if (st_amc13.isBad()) {
127  LogDebug("GEMRawToDigiModule") << st_amc13;
128  if (keepDAQStatus_) {
129  outAMC13Status.get()->insertDigi(fedId, st_amc13);
130  }
131  continue;
132  }
133 
134  const uint64_t* word = reinterpret_cast<const uint64_t*>(fedData.data());
135  auto amc13 = gemRawToDigi_->convertWordToGEMAMC13(word);
136  LogDebug("GEMRawToDigiModule") << "Event bx:" << iEvent.bunchCrossing() << " lv1Id:" << iEvent.id().event()
137  << " orbitNumber:" << iEvent.orbitNumber();
138  LogDebug("GEMRawToDigiModule") << "AMC13 bx:" << amc13->bunchCrossing() << " lv1Id:" << int(amc13->lv1Id())
139  << " orbitNumber:" << amc13->orbitNumber();
140 
141  // Read AMC data
142  for (const auto& amc : *(amc13->getAMCpayloads())) {
143  uint8_t amcNum = amc.amcNum();
144  if (!gemChMap->isValidAMC(fedId, amcNum)) {
145  st_amc13.inValidAMC();
146  continue;
147  }
148 
149  GEMAMCStatus st_amc(amc13.get(), amc);
150  if (st_amc.isBad()) {
151  LogDebug("GEMRawToDigiModule") << st_amc;
152  if (keepDAQStatus_) {
153  outAMCStatus.get()->insertDigi(fedId, st_amc);
154  }
155  continue;
156  }
157 
158  uint16_t amcBx = amc.bunchCrossing();
159  LogDebug("GEMRawToDigiModule") << "AMC no.:" << int(amc.amcNum()) << " bx:" << int(amc.bunchCrossing())
160  << " lv1Id:" << int(amc.lv1Id()) << " orbitNumber:" << int(amc.orbitNumber());
161 
162  // Read GEB data
163  for (const auto& optoHybrid : *amc.gebs()) {
164  uint8_t gebId = optoHybrid.inputID();
165 
166  bool isValidChamber = gemChMap->isValidChamber(fedId, amcNum, gebId);
167  if (!isValidChamber) {
168  st_amc.inValidOH();
169  continue;
170  }
171  auto geb_dc = gemChMap->chamberPos(fedId, amcNum, gebId);
172  GEMDetId cId(geb_dc.detId);
173  int chamberType = geb_dc.chamberType;
174 
175  GEMOHStatus st_oh(optoHybrid, chamberType);
176  if (st_oh.isBad()) {
177  LogDebug("GEMRawToDigiModule") << st_oh;
178  if (keepDAQStatus_) {
179  outOHStatus.get()->insertDigi(cId, st_oh);
180  }
181  continue;
182  }
183 
184  //Read vfat data
185  for (auto vfat : *optoHybrid.vFATs()) {
186  // set vfat fw version
187  if (chamberType < 10)
188  vfat.setVersion(2);
189  else
190  vfat.setVersion(3);
191  uint16_t vfatId = vfat.vfatId();
192 
193  if (!gemChMap->isValidVFAT(chamberType, vfatId)) {
194  st_oh.inValidVFAT();
195  continue;
196  }
197 
198  GEMVFATStatus st_vfat(amc, optoHybrid, vfat, chamberType, readMultiBX_);
199  if (st_vfat.isBad()) {
200  LogDebug("GEMRawToDigiModule") << st_vfat;
201  if (keepDAQStatus_) {
202  outVFATStatus.get()->insertDigi(cId, st_vfat);
203  }
204  continue;
205  }
206 
207  int bx(vfat.bc() - amcBx);
208 
209  for (int chan = 0; chan < GEMVFAT::nChannels; ++chan) {
210  uint8_t chan0xf = 0;
211  if (chan < 64)
212  chan0xf = ((vfat.lsData() >> chan) & 0x1);
213  else
214  chan0xf = ((vfat.msData() >> (chan - 64)) & 0x1);
215 
216  // no hits
217  if (chan0xf == 0)
218  continue;
219 
220  auto stMap = gemChMap->getStrip(chamberType, vfatId, chan);
221 
222  int stripId = stMap.stNum;
223  int ieta = stMap.iEta;
224 
225  GEMDetId gemId(cId.region(), cId.ring(), cId.station(), cId.layer(), cId.chamber(), ieta);
226 
227  GEMDigi digi(stripId, bx);
228 
229  LogDebug("GEMRawToDigiModule") << "fed: " << fedId << " amc:" << int(amcNum) << " geb:" << int(gebId)
230  << " vfat id:" << int(vfatId) << ",type:" << chamberType << " id:" << gemId
231  << " ch:" << chan << " st:" << digi.strip() << " bx:" << digi.bx();
232 
233  outGEMDigis.get()->insertDigi(gemId, digi);
234 
235  } // end of channel loop
236 
237  if (keepDAQStatus_) {
238  outVFATStatus.get()->insertDigi(cId, st_vfat);
239  }
240 
241  } // end of vfat loop
242 
243  if (keepDAQStatus_) {
244  outOHStatus.get()->insertDigi(cId, st_oh);
245  }
246 
247  } // end of optohybrid loop
248 
249  if (keepDAQStatus_) {
250  outAMCStatus.get()->insertDigi(fedId, st_amc);
251  }
252 
253  } // end of amc loop
254 
255  if (keepDAQStatus_) {
256  outAMC13Status.get()->insertDigi(fedId, st_amc13);
257  }
258 
259  } // end of amc13
260 
261  iEvent.put(std::move(outGEMDigis));
262 
263  if (keepDAQStatus_) {
264  iEvent.put(std::move(outAMC13Status), "AMC13Status");
265  iEvent.put(std::move(outAMCStatus), "AMCStatus");
266  iEvent.put(std::move(outOHStatus), "OHStatus");
267  iEvent.put(std::move(outVFATStatus), "VFATStatus");
268  }
269 }
constexpr int station() const
Definition: GEMDetId.h:179
constexpr int region() const
Definition: GEMDetId.h:171
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
Log< level::Error, false > LogError
constexpr int layer() const
Definition: GEMDetId.h:190
std::shared_ptr< GEMChMap > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
void inValidVFAT()
Definition: GEMOHStatus.h:67
constexpr int chamber() const
Definition: GEMDetId.h:183
static const int nChannels
Definition: GEMVFAT.h:117
bool isBad() const
Definition: GEMVFATStatus.h:65
edm::EDGetTokenT< FEDRawDataCollection > fed_token
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
uint64_t word
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< GEMChMap, GEMChMapRcd > gemChMapToken_
double amc
Definition: hdecay.h:20
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isBad() const
constexpr int ring() const
Definition: GEMDetId.h:176
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GEMRawToDigiModule(const edm::ParameterSet &pset)
Constructor.
unsigned long long uint64_t
Definition: Time.h:13
bool isBad() const
Definition: GEMOHStatus.h:73
void add(std::string const &label, ParameterSetDescription const &psetDescription)
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
std::unique_ptr< GEMRawToDigi > gemRawToDigi_
HLT enums.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
Definition: AMCSpec.h:8
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
#define LogDebug(id)