CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GEMRawToDigiModule.cc
Go to the documentation of this file.
1 
14 
16 
17 using namespace gem;
18 
20  : fed_token(consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("InputLabel"))),
21  useDBEMap_(pset.getParameter<bool>("useDBEMap")),
22  unPackStatusDigis_(pset.getParameter<bool>("unPackStatusDigis")) {
23  produces<GEMDigiCollection>();
24  if (unPackStatusDigis_) {
25  produces<GEMVfatStatusDigiCollection>("vfatStatus");
26  produces<GEMGEBdataCollection>("gebStatus");
27  produces<GEMAMCdataCollection>("AMCdata");
28  produces<GEMAMC13EventCollection>("AMC13Event");
29  }
30 }
31 
34  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
35  desc.add<bool>("useDBEMap", false);
36  desc.add<bool>("unPackStatusDigis", false);
37  descriptions.add("muonGEMDigisDefault", desc);
38 }
39 
40 std::shared_ptr<GEMROMapping> GEMRawToDigiModule::globalBeginRun(edm::Run const&, edm::EventSetup const& iSetup) const {
41  auto gemROmap = std::make_shared<GEMROMapping>();
42  if (useDBEMap_) {
43  edm::ESHandle<GEMeMap> gemEMapRcd;
44  iSetup.get<GEMeMapRcd>().get(gemEMapRcd);
45  auto gemEMap = std::make_unique<GEMeMap>(*(gemEMapRcd.product()));
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  // Readout out AMC headers
88  for (uint8_t i = 0; i < amc13Event->nAMC(); ++i)
89  amc13Event->addAMCheader(*(++word));
90 
91  // Readout out AMC payloads
92  for (uint8_t i = 0; i < amc13Event->nAMC(); ++i) {
93  auto amcData = std::make_unique<AMCdata>();
94  amcData->setAMCheader1(*(++word));
95  amcData->setAMCheader2(*(++word));
96  amcData->setGEMeventHeader(*(++word));
97  uint16_t amcBx = amcData->bx();
98  uint8_t amcNum = amcData->amcNum();
99 
100  // Fill GEB
101  for (uint8_t j = 0; j < amcData->davCnt(); ++j) {
102  auto gebData = std::make_unique<GEBdata>();
103  gebData->setChamberHeader(*(++word));
104 
105  uint8_t gebId = gebData->inputID();
106  GEMROMapping::chamEC geb_ec = {fedId, amcNum, gebId};
107  GEMROMapping::chamDC geb_dc = gemROMap->chamberPos(geb_ec);
108  GEMDetId gemChId = geb_dc.detId;
109 
110  for (uint16_t k = 0; k < gebData->vfatWordCnt() / 3; k++) {
111  auto vfatData = std::make_unique<VFATdata>();
112  vfatData->read_fw(*(++word));
113  vfatData->read_sw(*(++word));
114  vfatData->read_tw(*(++word));
115 
116  vfatData->setVersion(geb_dc.vfatVer);
117  uint16_t vfatId = vfatData->vfatId();
118  GEMROMapping::vfatEC vfat_ec = {vfatId, gemChId};
119 
120  // check if ChipID exists.
121  if (!gemROMap->isValidChipID(vfat_ec)) {
122  edm::LogWarning("GEMRawToDigiModule")
123  << "InValid: amcNum " << int(amcNum) << " gebId " << int(gebId) << " vfatId " << int(vfatId)
124  << " vfat Pos " << int(vfatData->position());
125  continue;
126  }
127  // check vfat data
128  if (vfatData->quality()) {
129  edm::LogWarning("GEMRawToDigiModule")
130  << "Quality " << int(vfatData->quality()) << " b1010 " << int(vfatData->b1010()) << " b1100 "
131  << int(vfatData->b1100()) << " b1110 " << int(vfatData->b1110());
132  if (vfatData->crc() != vfatData->checkCRC()) {
133  edm::LogWarning("GEMRawToDigiModule")
134  << "DIFFERENT CRC :" << vfatData->crc() << " " << vfatData->checkCRC();
135  }
136  }
137 
138  GEMROMapping::vfatDC vfat_dc = gemROMap->vfatPos(vfat_ec);
139 
140  vfatData->setPhi(vfat_dc.localPhi);
141  GEMDetId gemId = vfat_dc.detId;
142  uint16_t bc = vfatData->bc();
143  // strip bx = vfat bx - amc bx
144  int bx = bc - amcBx;
145 
146  for (int chan = 0; chan < VFATdata::nChannels; ++chan) {
147  uint8_t chan0xf = 0;
148  if (chan < 64)
149  chan0xf = ((vfatData->lsData() >> chan) & 0x1);
150  else
151  chan0xf = ((vfatData->msData() >> (chan - 64)) & 0x1);
152 
153  // no hits
154  if (chan0xf == 0)
155  continue;
156 
157  GEMROMapping::channelNum chMap = {vfat_dc.vfatType, chan};
158  GEMROMapping::stripNum stMap = gemROMap->hitPos(chMap);
159 
160  int stripId = stMap.stNum + vfatData->phi() * GEMeMap::maxChan_;
161 
162  GEMDigi digi(stripId, bx);
163 
164  LogDebug("GEMRawToDigiModule")
165  << " fed: " << fedId << " amc:" << int(amcNum) << " geb:" << int(gebId) << " vfat:" << vfat_dc.localPhi
166  << ",type: " << vfat_dc.vfatType << " id:" << gemId << " ch:" << chMap.chNum << " st:" << digi.strip()
167  << " bx:" << digi.bx();
168 
169  outGEMDigis.get()->insertDigi(gemId, digi);
170 
171  } // end of channel loop
172 
173  if (unPackStatusDigis_) {
174  outVFATStatus.get()->insertDigi(gemId, GEMVfatStatusDigi(*vfatData));
175  }
176 
177  } // end of vfat loop
178 
179  gebData->setChamberTrailer(*(++word));
180 
181  if (unPackStatusDigis_) {
182  outGEBStatus.get()->insertDigi(gemChId.chamberId(), (*gebData));
183  }
184 
185  } // end of geb loop
186 
187  amcData->setGEMeventTrailer(*(++word));
188  amcData->setAMCTrailer(*(++word));
189 
190  if (unPackStatusDigis_) {
191  outAMCdata.get()->insertDigi(amcData->boardId(), (*amcData));
192  }
193 
194  } // end of amc loop
195 
196  amc13Event->setAMC13Trailer(*(++word));
197  amc13Event->setCDFTrailer(*(++word));
198 
199  if (unPackStatusDigis_) {
200  outAMC13Event.get()->insertDigi(amc13Event->bxId(), AMC13Event(*amc13Event));
201  }
202 
203  } // end of amc13Event
204 
205  iEvent.put(std::move(outGEMDigis));
206 
207  if (unPackStatusDigis_) {
208  iEvent.put(std::move(outVFATStatus), "vfatStatus");
209  iEvent.put(std::move(outGEBStatus), "gebStatus");
210  iEvent.put(std::move(outAMCdata), "AMCdata");
211  iEvent.put(std::move(outAMC13Event), "AMC13Event");
212  }
213 }
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
Run const & getRun() const
Definition: Event.cc:108
static const int maxChan_
Definition: GEMeMap.h:69
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
Definition: AMC13Event.h:6
edm::EDGetTokenT< FEDRawDataCollection > fed_token
GEMDetId chamberId() const
Definition: GEMDetId.h:193
uint64_t word
int iEvent
Definition: GenABIO.cc:224
std::shared_ptr< GEMROMapping > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
RunIndex index() const
Definition: Run.cc:21
ParameterDescriptionBase * add(U const &iLabel, T const &value)
GEMRawToDigiModule(const edm::ParameterSet &pset)
Constructor.
int bx() const
Definition: GEMDigi.h:27
unsigned long long uint64_t
Definition: Time.h:13
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...
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
T get() const
Definition: EventSetup.h:73
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
int strip() const
Definition: GEMDigi.h:26
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45