CMS 3D CMS Logo

GEMRawToDigiModule.cc
Go to the documentation of this file.
1 
12 
14 
15 using namespace gem;
16 
18  : fed_token(consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("InputLabel"))),
19  useDBEMap_(pset.getParameter<bool>("useDBEMap")),
20  unPackStatusDigis_(pset.getParameter<bool>("unPackStatusDigis")) {
21  if (useDBEMap_) {
22  gemEMapToken_ = esConsumes<GEMeMap, GEMeMapRcd, edm::Transition::BeginRun>();
23  }
24  produces<GEMDigiCollection>();
25  if (unPackStatusDigis_) {
26  produces<GEMVfatStatusDigiCollection>("vfatStatus");
27  produces<GEMGEBdataCollection>("gebStatus");
28  produces<GEMAMCdataCollection>("AMCdata");
29  produces<GEMAMC13EventCollection>("AMC13Event");
30  }
31 }
32 
35  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
36  desc.add<bool>("useDBEMap", false);
37  desc.add<bool>("unPackStatusDigis", false);
38  descriptions.add("muonGEMDigisDefault", desc);
39 }
40 
41 std::shared_ptr<GEMROMapping> GEMRawToDigiModule::globalBeginRun(edm::Run const&, edm::EventSetup const& iSetup) const {
42  auto gemROmap = std::make_shared<GEMROMapping>();
43  if (useDBEMap_) {
44  GEMeMap const& eMap = iSetup.getData(gemEMapToken_);
45  auto gemEMap = std::make_unique<GEMeMap>(eMap);
46  gemEMap->convert(*gemROmap);
47  gemEMap.reset();
48  } else {
49  // no EMap in DB, using dummy
50  auto gemEMap = std::make_unique<GEMeMap>();
51  gemEMap->convertDummy(*gemROmap);
52  gemEMap.reset();
53  }
54  return gemROmap;
55 }
56 
58  auto outGEMDigis = std::make_unique<GEMDigiCollection>();
59  auto outVFATStatus = std::make_unique<GEMVfatStatusDigiCollection>();
60  auto outGEBStatus = std::make_unique<GEMGEBdataCollection>();
61  auto outAMCdata = std::make_unique<GEMAMCdataCollection>();
62  auto outAMC13Event = std::make_unique<GEMAMC13EventCollection>();
63 
64  // Take raw from the event
66  iEvent.getByToken(fed_token, fed_buffers);
67 
68  auto gemROMap = runCache(iEvent.getRun().index());
69 
71  const FEDRawData& fedData = fed_buffers->FEDData(fedId);
72 
73  int nWords = fedData.size() / sizeof(uint64_t);
74  LogDebug("GEMRawToDigiModule") << " words " << nWords;
75 
76  if (nWords < 5)
77  continue;
78  const unsigned char* data = fedData.data();
79 
80  auto amc13Event = std::make_unique<AMC13Event>();
81 
82  const uint64_t* word = reinterpret_cast<const uint64_t*>(data);
83 
84  amc13Event->setCDFHeader(*word);
85  amc13Event->setAMC13Header(*(++word));
86 
87  bool unknownChamber = false, unknownVFat = false, badVfat = false;
88 
89  // Readout out AMC headers
90  for (uint8_t i = 0; i < amc13Event->nAMC(); ++i)
91  amc13Event->addAMCheader(*(++word));
92 
93  // Readout out AMC payloads
94  for (uint8_t i = 0; i < amc13Event->nAMC(); ++i) {
95  auto amcData = std::make_unique<AMCdata>();
96  amcData->setAMCheader1(*(++word));
97  amcData->setAMCheader2(*(++word));
98  amcData->setGEMeventHeader(*(++word));
99  uint16_t amcBx = amcData->bx();
100  uint8_t amcNum = amcData->amcNum();
101 
102  // Fill GEB
103  for (uint8_t j = 0; j < amcData->davCnt(); ++j) {
104  auto gebData = std::make_unique<GEBdata>();
105  gebData->setChamberHeader(*(++word));
106 
107  uint8_t gebId = gebData->inputID();
108  GEMROMapping::chamEC geb_ec = {fedId, amcNum, gebId};
109 
110  // check if Chamber exists.
111  if (!gemROMap->isValidChamber(geb_ec)) {
112  unknownChamber = true;
113  LogDebug("GEMRawToDigiModule") << "InValid: amcNum " << int(amcNum) << " gebId " << int(gebId);
114  continue;
115  }
116 
117  GEMROMapping::chamDC geb_dc = gemROMap->chamberPos(geb_ec);
118  GEMDetId gemChId = geb_dc.detId;
119 
120  for (uint16_t k = 0; k < gebData->vfatWordCnt() / 3; k++) {
121  auto vfatData = std::make_unique<VFATdata>();
122  vfatData->read_fw(*(++word));
123  vfatData->read_sw(*(++word));
124  vfatData->read_tw(*(++word));
125 
126  vfatData->setVersion(geb_dc.vfatVer);
127  uint16_t vfatId = vfatData->vfatId();
128  GEMROMapping::vfatEC vfat_ec = {vfatId, gemChId};
129 
130  // check if ChipID exists.
131  if (!gemROMap->isValidChipID(vfat_ec)) {
132  unknownVFat = true;
133  LogDebug("GEMRawToDigiModule") << "InValid: amcNum " << int(amcNum) << " gebId " << int(gebId) << " vfatId "
134  << int(vfatId) << " vfat Pos " << int(vfatData->position());
135  continue;
136  }
137 
138  // check vfat data
139  if (vfatData->quality()) {
140  badVfat = true;
141  LogDebug("GEMRawToDigiModule")
142  << "Quality " << int(vfatData->quality()) << " b1010 " << int(vfatData->b1010()) << " b1100 "
143  << int(vfatData->b1100()) << " b1110 " << int(vfatData->b1110());
144  if (vfatData->crc() != vfatData->checkCRC()) {
145  LogDebug("GEMRawToDigiModule") << "DIFFERENT CRC :" << vfatData->crc() << " " << vfatData->checkCRC();
146  }
147  }
148 
149  GEMROMapping::vfatDC vfat_dc = gemROMap->vfatPos(vfat_ec);
150 
151  vfatData->setPhi(vfat_dc.localPhi);
152  GEMDetId gemId = vfat_dc.detId;
153  uint16_t bc = vfatData->bc();
154  // strip bx = vfat bx - amc bx
155  int bx = bc - amcBx;
156 
157  for (int chan = 0; chan < VFATdata::nChannels; ++chan) {
158  uint8_t chan0xf = 0;
159  if (chan < 64)
160  chan0xf = ((vfatData->lsData() >> chan) & 0x1);
161  else
162  chan0xf = ((vfatData->msData() >> (chan - 64)) & 0x1);
163 
164  // no hits
165  if (chan0xf == 0)
166  continue;
167 
168  GEMROMapping::channelNum chMap = {vfat_dc.vfatType, chan};
169  GEMROMapping::stripNum stMap = gemROMap->hitPos(chMap);
170 
171  int stripId = stMap.stNum + vfatData->phi() * GEMeMap::maxChan_;
172 
173  GEMDigi digi(stripId, bx);
174 
175  LogDebug("GEMRawToDigiModule")
176  << " fed: " << fedId << " amc:" << int(amcNum) << " geb:" << int(gebId) << " vfat:" << vfat_dc.localPhi
177  << ",type: " << vfat_dc.vfatType << " id:" << gemId << " ch:" << chMap.chNum << " st:" << digi.strip()
178  << " bx:" << digi.bx();
179 
180  outGEMDigis.get()->insertDigi(gemId, digi);
181 
182  } // end of channel loop
183 
184  if (unPackStatusDigis_) {
185  outVFATStatus.get()->insertDigi(gemId, GEMVfatStatusDigi(*vfatData));
186  }
187 
188  } // end of vfat loop
189 
190  gebData->setChamberTrailer(*(++word));
191 
192  if (unPackStatusDigis_) {
193  outGEBStatus.get()->insertDigi(gemChId.chamberId(), (*gebData));
194  }
195 
196  } // end of geb loop
197 
198  amcData->setGEMeventTrailer(*(++word));
199  amcData->setAMCTrailer(*(++word));
200 
201  if (unPackStatusDigis_) {
202  outAMCdata.get()->insertDigi(amcData->boardId(), (*amcData));
203  }
204 
205  } // end of amc loop
206 
207  amc13Event->setAMC13Trailer(*(++word));
208  amc13Event->setCDFTrailer(*(++word));
209 
210  if (unPackStatusDigis_) {
211  outAMC13Event.get()->insertDigi(amc13Event->bxId(), AMC13Event(*amc13Event));
212  }
213 
214  if (unknownChamber || unknownVFat || badVfat) {
215  edm::LogWarning("GEMRawToDigiModule") << "unpacking error: unknown Chamber " << unknownChamber << " unknown VFat "
216  << unknownVFat << " bad VFat " << badVfat;
217  }
218 
219  } // end of amc13Event
220 
221  iEvent.put(std::move(outGEMDigis));
222 
223  if (unPackStatusDigis_) {
224  iEvent.put(std::move(outVFATStatus), "vfatStatus");
225  iEvent.put(std::move(outGEBStatus), "gebStatus");
226  iEvent.put(std::move(outAMCdata), "AMCdata");
227  iEvent.put(std::move(outAMC13Event), "AMC13Event");
228  }
229 }
FEDNumbering.h
edm::StreamID
Definition: StreamID.h:30
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
GEMRawToDigiModule::GEMRawToDigiModule
GEMRawToDigiModule(const edm::ParameterSet &pset)
Constructor.
Definition: GEMRawToDigiModule.cc:17
mps_fire.i
i
Definition: mps_fire.py:355
GEMROMapping::vfatDC::vfatType
int vfatType
Definition: GEMROMapping.h:45
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
GEMRawToDigiModule::unPackStatusDigis_
bool unPackStatusDigis_
Definition: GEMRawToDigiModule.h:45
edm::Run
Definition: Run.h:45
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
GEMROMapping::chamDC
Definition: GEMROMapping.h:26
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
ecaldqm::nChannels
Definition: EcalDQMCommonUtils.h:114
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
GEMROMapping::stripNum
Definition: GEMROMapping.h:72
edm::Handle
Definition: AssociativeIterator.h:50
gem::AMC13Event
Definition: AMC13Event.h:51
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
GEMeMap
Definition: GEMeMap.h:10
FEDNumbering::MINGEMFEDID
Definition: FEDNumbering.h:123
GEMROMapping::chamDC::vfatVer
int vfatVer
Definition: GEMROMapping.h:28
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
GEMDigi::bx
int bx() const
Definition: GEMDigi.h:27
GEMROMapping::vfatDC::detId
GEMDetId detId
Definition: GEMROMapping.h:46
GEMROMapping::vfatDC::localPhi
int localPhi
Definition: GEMROMapping.h:47
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
GEMRawToDigiModule::fed_token
edm::EDGetTokenT< FEDRawDataCollection > fed_token
Definition: GEMRawToDigiModule.h:42
GEMDigi::strip
int strip() const
Definition: GEMDigi.h:26
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
GEMVfatStatusDigi
Definition: GEMVfatStatusDigi.h:6
GEMRawToDigiModule::gemEMapToken_
edm::ESGetToken< GEMeMap, GEMeMapRcd > gemEMapToken_
Definition: GEMRawToDigiModule.h:43
Run.h
GEMRawToDigiModule::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: GEMRawToDigiModule.cc:33
Transition.h
dqmdumpme.k
k
Definition: dqmdumpme.py:60
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
GEMROMapping::vfatDC
Definition: GEMROMapping.h:44
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
GEMROMapping::channelNum::chNum
int chNum
Definition: GEMROMapping.h:63
edm::LogWarning
Definition: MessageLogger.h:141
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
GEMDetId
Definition: GEMDetId.h:17
GEMROMapping::chamEC
Definition: GEMROMapping.h:9
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
GEMDigi
Definition: GEMDigi.h:15
edm::EventSetup
Definition: EventSetup.h:57
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:88
gem
Definition: AMC13Event.h:6
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
InputTag.h
GEMROMapping::stripNum::stNum
int stNum
Definition: GEMROMapping.h:74
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:113
eostools.move
def move(src, dest)
Definition: eostools.py:511
GEMROMapping::channelNum
Definition: GEMROMapping.h:61
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
GEMDetId::chamberId
constexpr GEMDetId chamberId() const
Definition: GEMDetId.h:193
GEMRawToDigiModule::globalBeginRun
std::shared_ptr< GEMROMapping > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
Definition: GEMRawToDigiModule.cc:41
FEDNumbering::MAXGEMFEDID
Definition: FEDNumbering.h:124
EventSetup.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
GEMRawToDigiModule.h
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
ParameterSet.h
GEMROMapping::chamDC::detId
GEMDetId detId
Definition: GEMROMapping.h:27
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
GEMRawToDigiModule::useDBEMap_
bool useDBEMap_
Definition: GEMRawToDigiModule.h:44
GEMROMapping::vfatEC
Definition: GEMROMapping.h:32
edm::InputTag
Definition: InputTag.h:15
GEMeMap::maxChan_
static const int maxChan_
Definition: GEMeMap.h:69
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
GEMRawToDigiModule::produce
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: GEMRawToDigiModule.cc:57