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);
176  if (st_oh.isBad()) {
177  LogDebug("GEMRawToDigiModule") << st_oh;
178  if (keepDAQStatus_) {
179  outOHStatus.get()->insertDigi(cId, st_oh);
180  }
181  }
182 
183  //Read vfat data
184  for (auto vfat : *optoHybrid.vFATs()) {
185  // set vfat fw version
186  if (chamberType < 10)
187  vfat.setVersion(2);
188  else
189  vfat.setVersion(3);
190  uint16_t vfatId = vfat.vfatId();
191 
192  if (!gemChMap->isValidVFAT(chamberType, vfatId)) {
193  st_oh.inValidVFAT();
194  continue;
195  }
196 
197  GEMVFATStatus st_vfat(amc, vfat, vfat.phi(), readMultiBX_);
198  if (st_vfat.isBad()) {
199  LogDebug("GEMRawToDigiModule") << st_vfat;
200  if (keepDAQStatus_) {
201  outVFATStatus.get()->insertDigi(cId, st_vfat);
202  }
203  continue;
204  }
205 
206  int bx(vfat.bc() - amcBx);
207 
208  for (int chan = 0; chan < GEMVFAT::nChannels; ++chan) {
209  uint8_t chan0xf = 0;
210  if (chan < 64)
211  chan0xf = ((vfat.lsData() >> chan) & 0x1);
212  else
213  chan0xf = ((vfat.msData() >> (chan - 64)) & 0x1);
214 
215  // no hits
216  if (chan0xf == 0)
217  continue;
218 
219  auto stMap = gemChMap->getStrip(chamberType, vfatId, chan);
220 
221  int stripId = stMap.stNum;
222  int ieta = stMap.iEta;
223 
224  GEMDetId gemId(cId.region(), cId.ring(), cId.station(), cId.layer(), cId.chamber(), ieta);
225 
226  GEMDigi digi(stripId, bx);
227 
228  LogDebug("GEMRawToDigiModule") << "fed: " << fedId << " amc:" << int(amcNum) << " geb:" << int(gebId)
229  << " vfat id:" << int(vfatId) << ",type:" << chamberType << " id:" << gemId
230  << " ch:" << chan << " st:" << digi.strip() << " bx:" << digi.bx();
231 
232  outGEMDigis.get()->insertDigi(gemId, digi);
233 
234  } // end of channel loop
235 
236  if (keepDAQStatus_) {
237  outVFATStatus.get()->insertDigi(cId, st_vfat);
238  }
239 
240  } // end of vfat loop
241 
242  if (keepDAQStatus_) {
243  outOHStatus.get()->insertDigi(cId, st_oh);
244  }
245 
246  } // end of optohybrid loop
247 
248  if (keepDAQStatus_) {
249  outAMCStatus.get()->insertDigi(fedId, st_amc);
250  }
251 
252  } // end of amc loop
253 
254  if (keepDAQStatus_) {
255  outAMC13Status.get()->insertDigi(fedId, st_amc13);
256  }
257 
258  } // end of amc13
259 
260  iEvent.put(std::move(outGEMDigis));
261 
262  if (keepDAQStatus_) {
263  iEvent.put(std::move(outAMC13Status), "AMC13Status");
264  iEvent.put(std::move(outAMCStatus), "AMCStatus");
265  iEvent.put(std::move(outOHStatus), "OHStatus");
266  iEvent.put(std::move(outVFATStatus), "VFATStatus");
267  }
268 }
constexpr int station() const
Definition: GEMDetId.h:179
constexpr int region() const
Definition: GEMDetId.h:171
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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:61
constexpr int chamber() const
Definition: GEMDetId.h:183
static const int nChannels
Definition: GEMVFAT.h:116
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
bool getData(T &iHolder) const
Definition: EventSetup.h:122
GEMRawToDigiModule(const edm::ParameterSet &pset)
Constructor.
unsigned long long uint64_t
Definition: Time.h:13
bool isBad() const
Definition: GEMOHStatus.h:67
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)