CMS 3D CMS Logo

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