CMS 3D CMS Logo

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 {
24  produces<GEMDigiCollection>();
25  if (unPackStatusDigis_){
26  produces<GEMVfatStatusDigiCollection>("vfatStatus");
27  produces<GEMGEBStatusDigiCollection>("GEBStatus");
28  produces<GEMAMCStatusDigiCollection>("AMCStatus");
29  }
30 }
31 
33 {
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<GEMROmap> GEMRawToDigiModule::globalBeginRun(edm::Run const&, edm::EventSetup const& iSetup) const
42 {
43  auto gemORmap = std::make_shared<GEMROmap>();
44  if (useDBEMap_){
45  edm::ESHandle<GEMELMap> gemEMapRcd;
46  iSetup.get<GEMELMapRcd>().get(gemEMapRcd);
47  auto gemEMap = std::make_unique<GEMELMap>(*(gemEMapRcd.product()));
48  gemEMap->convert(*gemORmap);
49  gemEMap.reset();
50  }
51  else {
52  // no EMap in DB, using dummy
53  auto gemEMap = std::make_unique<GEMELMap>();
54  gemEMap->convertDummy(*gemORmap);
55  gemEMap.reset();
56  }
57  return gemORmap;
58 }
59 
61 {
62  auto outGEMDigis = std::make_unique<GEMDigiCollection>();
63  auto outVfatStatus = std::make_unique<GEMVfatStatusDigiCollection>();
64  auto outGEBStatus = std::make_unique<GEMGEBStatusDigiCollection>();
65  auto outAMCStatus = std::make_unique<GEMAMCStatusDigiCollection>();
66 
67  // Take raw from the event
69  iEvent.getByToken( fed_token, fed_buffers );
70 
71  auto gemROMap = runCache(iEvent.getRun().index());
72 
73  for (unsigned int id=FEDNumbering::MINGEMFEDID; id<=FEDNumbering::MAXGEMFEDID; ++id){
74  const FEDRawData& fedData = fed_buffers->FEDData(id);
75 
76  int nWords = fedData.size()/sizeof(uint64_t);
77  LogDebug("GEMRawToDigiModule") <<" words " << nWords;
78  if (nWords<5) continue;
79  const unsigned char * data = fedData.data();
80 
81  auto amc13Event = std::make_unique<AMC13Event>();
82 
83  const uint64_t* word = reinterpret_cast<const uint64_t* >(data);
84 
85  amc13Event->setCDFHeader(*word);
86  amc13Event->setAMC13header(*(++word));
87 
88  // Readout out AMC headers
89  for (unsigned short i = 0; i < amc13Event->nAMC(); ++i)
90  amc13Event->addAMCheader(*(++word));
91 
92  // Readout out AMC payloads
93  for (unsigned short i = 0; i < amc13Event->nAMC(); ++i){
94  auto amcData = std::make_unique<AMCdata>();
95  amcData->setAMCheader1(*(++word));
96  amcData->setAMCheader2(*(++word));
97  amcData->setGEMeventHeader(*(++word));
98  uint16_t amcId = amcData->boardId();
99  uint16_t amcBx = amcData->bx();
100 
101  // Fill GEB
102  for (unsigned short j = 0; j < amcData->gdCount(); ++j){
103  auto gebData = std::make_unique<GEBdata>();
104  gebData->setChamberHeader(*(++word));
105 
106  unsigned int m_nvb = gebData->vwh() / 3; // number of VFAT2 blocks
107  uint16_t gebId = gebData->inputID();
108  GEMDetId gemId(-1,1,1,1,1,0); // temp ID
109  for (unsigned short k = 0; k < m_nvb; k++){
110  auto vfatData = std::make_unique<VFATdata>();
111  vfatData->read_fw(*(++word));
112  vfatData->read_sw(*(++word));
113  vfatData->read_tw(*(++word));
114  gebData->addVFAT(*vfatData);
115 
116  uint16_t bc=vfatData->bc();
117  uint8_t b1010=vfatData->b1010();
118  uint8_t b1100=vfatData->b1100();
119  uint8_t b1110=vfatData->b1110();
120  uint16_t vfatId=vfatData->chipID();
121  uint16_t crc = vfatData->crc();
122  uint16_t crc_check = vfatData->checkCRC();
123  bool Quality = (b1010==10) && (b1100==12) && (b1110==14) && (crc==crc_check);
124 
125  if (crc!=crc_check) edm::LogWarning("GEMRawToDigiModule") << "DIFFERENT CRC :"<<crc<<" "<<crc_check;
126  if (!Quality) edm::LogWarning("GEMRawToDigiModule") << "Quality "<< Quality
127  << " b1010 "<< int(b1010)
128  << " b1100 "<< int(b1100)
129  << " b1110 "<< int(b1110);
130 
131  //check if ChipID exists.
132  GEMROmap::eCoord ec = {amcId, gebId, vfatId};
133 
134  if (!gemROMap->isValidChipID(ec)){
135  edm::LogWarning("GEMRawToDigiModule") << "InValid ChipID :"<<ec.vfatId;
136  continue;
137  }
138 
139  for (int chan = 0; chan < VFATdata::nChannels; ++chan) {
140  uint8_t chan0xf = 0;
141  if (chan < 64) chan0xf = ((vfatData->lsData() >> chan) & 0x1);
142  else chan0xf = ((vfatData->msData() >> (chan-64)) & 0x1);
143 
144  // no hits
145  if(chan0xf==0) continue;
146  GEMROmap::dCoord dc = gemROMap->hitPosition(ec);
147  // strip bx = vfat bx - amc bx
148  int bx = bc-amcBx;
149  gemId = dc.gemDetId;
150 
151  GEMROmap::channelNum chMap = {dc.vfatType, chan};
152  GEMROmap::stripNum stMap = gemROMap->hitPosition(chMap);
153 
154  int maxVFat = GEMELMap::maxVFatGE11_;
155  if (gemId.station() == 2) maxVFat = GEMELMap::maxVFatGE21_;
156  int stripId = stMap.stNum + (dc.iPhi-1)%maxVFat*GEMELMap::maxChan_;
157 
158  GEMDigi digi(stripId,bx);
159  LogDebug("GEMRawToDigiModule") <<" vfatId "<<ec.vfatId
160  <<" gemDetId "<< gemId
161  <<" chan "<< chMap.chNum
162  <<" strip "<< stripId
163  <<" bx "<< digi.bx();
164 
165  outGEMDigis.get()->insertDigi(gemId,digi);
166  }
167 
168  if (unPackStatusDigis_){
169  GEMVfatStatusDigi vfatStatus(vfatData->lsData(), vfatData->msData(),
170  crc, vfatData->crc_calc(),
171  b1010, b1100, b1110, vfatData->flag(),
172  vfatData->isBlockGood());
173  outVfatStatus.get()->insertDigi(gebData->inputID(),vfatStatus);
174  }
175 
176  }
177 
178  gebData->setChamberTrailer(*(++word));
179  if (unPackStatusDigis_){
180  GEMGEBStatusDigi gebStatus(gebData->zeroSupWordsCnt(),
181  gebData->vwh(),
182  gebData->errorC(),
183  gebData->ohCRC(),
184  gebData->vwt(),
185  gebData->inFu(),
186  gebData->inputID(),
187  gebData->stuckd(),
188  gebData->getGEBflag());
189  outGEBStatus.get()->insertDigi(gebData->inputID(),gebStatus);
190  }
191 
192  amcData->addGEB(*gebData);
193  }
194 
195  amcData->setGEMeventTrailer(*(++word));
196  amcData->setAMCTrailer(*(++word));
197 
198  if (unPackStatusDigis_){
199  GEMAMCStatusDigi amcStatus(amcData->amcNum(),
200  amcData->l1A(),
201  amcData->bx(),
202  amcData->dlength(),
203  amcData->fv(),
204  amcData->runType(),
205  amcData->param1(),
206  amcData->param2(),
207  amcData->param3(),
208  amcData->orbitNum(),
209  amcData->boardId(),
210  amcData->gemDAV(),
211  amcData->bStatus(),
212  amcData->gdCount(),
213  amcData->ttsState(),
214  amcData->chamberTimeOut(),
215  amcData->oosGLIB());
216  outAMCStatus.get()->insertDigi(amcData->boardId(), amcStatus);
217  }
218 
219  amc13Event->addAMCpayload(*amcData);
220  }
221 
222  amc13Event->setAMC13trailer(*(++word));
223  amc13Event->setCDFTrailer(*(++word));
224  }
225 
226  iEvent.put(std::move(outGEMDigis));
227  if (unPackStatusDigis_){
228  iEvent.put(std::move(outVfatStatus), "vfatStatus");
229  iEvent.put(std::move(outGEBStatus), "GEBStatus");
230  iEvent.put(std::move(outAMCStatus), "AMCStatus");
231  }
232 }
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
Run const & getRun() const
Definition: Event.cc:114
std::shared_ptr< GEMROmap > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
static const int maxVFatGE21_
Definition: GEMELMap.h:60
A class for AMC data.
Definition: AMC13Event.h:6
edm::EDGetTokenT< FEDRawDataCollection > fed_token
static const int maxChan_
Definition: GEMELMap.h:61
int iEvent
Definition: GenABIO.cc:230
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
GEMDetId gemDetId
Definition: GEMROmap.h:30
int station() const
Station id : the station is the pair of chambers at same disk.
Definition: GEMDetId.h:64
RunIndex index() const
Definition: Run.cc:24
ParameterDescriptionBase * add(U const &iLabel, T const &value)
int k[5][pyjets_maxn]
GEMRawToDigiModule(const edm::ParameterSet &pset)
Constructor.
int bx() const
Definition: GEMDigi.h:27
unsigned long long uint64_t
Definition: Time.h:15
static const int maxVFatGE11_
Definition: GEMELMap.h:59
uint16_t vfatId
Definition: GEMROmap.h:12
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:82
T get() const
Definition: EventSetup.h:62
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
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:44