CMS 3D CMS Logo

EcalFEtoDigi.cc
Go to the documentation of this file.
2 
4  : tpgLutGroupToken_(esConsumes()),
5  tpgLutIdMapToken_(esConsumes()),
6  basename_(iConfig.getUntrackedParameter<std::string>("FlatBaseName", "ecal_tcc_")),
7  useIdentityLUT_(iConfig.getUntrackedParameter<bool>("UseIdentityLUT", false)),
8  sm_(iConfig.getUntrackedParameter<int>("SuperModuleId", -1)),
9  fileEventOffset_(iConfig.getUntrackedParameter<int>("FileEventOffset", 0)),
10  debug_(iConfig.getUntrackedParameter<bool>("debugPrintFlag", false)) {
11  singlefile = (sm_ == -1) ? false : true;
12 
13  produces<EcalTrigPrimDigiCollection>();
14  produces<EcalTrigPrimDigiCollection>("formatTCP");
15 }
16 
20  static int current_bx = -1;
21  current_bx++;
22 
24  // readInput();
25 
26  if (debug_)
27  std::cout << "[EcalFEtoDigi::produce] producing event " << current_bx << std::endl;
28 
29  std::unique_ptr<EcalTrigPrimDigiCollection> e_tpdigis(new EcalTrigPrimDigiCollection);
30  std::unique_ptr<EcalTrigPrimDigiCollection> e_tpdigisTcp(new EcalTrigPrimDigiCollection);
31 
32  std::vector<TCCinput>::const_iterator it;
33 
34  for (int i = 0; i < N_SM; i++) {
35  if (!singlefile)
36  sm_ = i + 1;
37 
38  for (it = inputdata_[i].begin(); it != inputdata_[i].end(); it++) {
39  if (!(*it).is_current(current_bx + fileEventOffset_))
40  continue;
41  else if (debug_ && (*it).input != 0)
42  std::cout << "[EcalFEtoDigi] "
43  << "\tsupermodule:" << sm_ << "\tevent: " << current_bx << "\tbx: " << (*it).bunchCrossing
44  << "\tvalue:0x" << std::setfill('0') << std::setw(4) << std::hex << (*it).input << std::setfill(' ')
45  << std::dec << std::endl;
46 
48  const EcalTrigTowerDetId e_id = create_TTDetId(*it);
49 
50  // EcalElectronicsMapping theMapping;
51  // const EcalTrigTowerDetId e_id
52  //= theMapping.getTrigTowerDetId(SMidToTCCid(sm_),(*it).tower);
53  // EcalElectronicsMapping::getTrigTowerDetId(int TCCid, int iTT)
54 
58 
60  EcalTriggerPrimitiveSample e_sample = create_TPSample(*it, iSetup);
61  EcalTriggerPrimitiveSample e_sampleTcp = create_TPSampleTcp(*it, iSetup);
62 
64  e_digi->setSize(1); // set sampleOfInterest to 0
65  e_digi->setSample(0, e_sample);
66 
68  e_tpdigis->push_back(*e_digi);
69 
71  e_digiTcp->setSize(1); // set sampleOfInterest to 0
72  e_digiTcp->setSample(0, e_sampleTcp);
73 
75  e_tpdigisTcp->push_back(*e_digiTcp);
76 
77  if (debug_)
78  outfile << (*it).tower << '\t' << (*it).bunchCrossing << '\t' << std::setfill('0') << std::hex << "0x"
79  << std::setw(4) << (*it).input << '\t' << "0" << std::dec << std::setfill(' ') << std::endl;
80 
82  if (debug_ && (*it).input != 0)
83  std::cout << "[EcalFEtoDigi] debug id: " << e_digi->id() << "\n\t" << std::dec
84  << "\tieta: " << e_digi->id().ieta() << "\tiphi: " << e_digi->id().iphi()
85  << "\tsize: " << e_digi->size() << "\tfg: " << (e_digi->fineGrain() ? 1 : 0) << std::hex << "\tEt: 0x"
86  << e_digi->compressedEt() << " (0x" << (*it).get_energy() << ")"
87  << "\tttflag: 0x" << e_digi->ttFlag() << std::dec << std::endl;
88 
89  delete e_digi;
90  delete e_digiTcp;
91  }
92 
93  if (singlefile)
94  break;
95  }
96 
98  if (e_tpdigis->empty()) {
99  std::cout << "[EcalFEtoDigi] creating empty collection for the event!\n";
101  e_tpdigis->push_back(*e_digi);
102  }
103 
104  iEvent.put(std::move(e_tpdigis));
105  iEvent.put(std::move(e_tpdigisTcp), "formatTCP");
106 }
107 
110  if (debug_)
111  std::cout << "\n[EcalFEtoDigi::readInput] Reading input data\n";
112 
113  if (!singlefile)
114  sm_ = -1;
115  for (int i = 0; i < N_SM; i++)
116  inputdata_[i].clear();
117 
118  std::stringstream s;
119  int tcc;
120 
121  for (int i = 0; i < N_SM; i++) {
122  tcc = (sm_ == -1) ? SMidToTCCid(i + 1) : SMidToTCCid(sm_);
123 
124  s.str("");
125  s << basename_ << tcc << ".txt";
126 
127  std::ifstream f(s.str().c_str());
128 
129  if (debug_) {
130  std::cout << " opening " << s.str().c_str() << "..." << std::endl;
131  if (!f.good())
132  std::cout << " skipped!";
133  std::cout << std::endl;
134  }
135  // if (!f.good() || f.eof())
136  // throw cms::Exception("BadInputFile")
137  // << "EcalFEtoDigi: cannot open file " << s.str().c_str() << std::endl;
138 
139  int n_bx = 0;
140  int tt;
141  int bx;
142  unsigned val;
143  int dummy;
144 
145  while (f.good()) {
146  if (f.eof())
147  break;
148  tt = 0;
149  bx = -1;
150  val = 0x0;
151  dummy = 0;
152  f >> tt >> bx >> std::hex >> val >> std::dec >> dummy;
153  if (bx == -1 || bx < fileEventOffset_)
154  continue;
155  if (!n_bx || (bx != (inputdata_[i].back()).bunchCrossing))
156  n_bx++;
157  TCCinput ttdata(tt, bx, val);
158  inputdata_[i].push_back(ttdata);
159 
160  if (debug_ && val != 0)
161  printf("\treading tower:%d bx:%d input:0x%x dummy:%2d\n", tt, bx, val, dummy);
162  }
163 
164  f.close();
165 
166  if (sm_ != -1)
167  break;
168  }
169 
170  if (debug_)
171  std::cout << "[EcalFEtoDigi::readInput] Done reading." << std::endl;
172 
173  return;
174 }
175 
178  // (EcalBarrel only)
179  static const int kTowersInPhi = 4;
180 
181  int iTT = data.tower;
182  int zside = (sm_ > 18) ? -1 : +1;
183  int SMid = sm_;
184 
185  int jtower = iTT - 1;
186  int etaTT = jtower / kTowersInPhi + 1;
187  int phiTT;
188  if (zside < 0)
189  phiTT = (SMid - 19) * kTowersInPhi + jtower % kTowersInPhi;
190  else
191  phiTT = (SMid - 1) * kTowersInPhi + kTowersInPhi - (jtower % kTowersInPhi) - 1;
192 
193  phiTT++;
194  // needed as phi=0 (iphi=1) is at middle of lower SMs (1 and 19), need shift
195  // by 2
196  phiTT = phiTT - 2;
197  if (phiTT <= 0)
198  phiTT = 72 + phiTT;
199 
201  if (debug_ && data.get_energy() != 0)
202  printf(
203  "[EcalFEtoDigi] Creating EcalTrigTowerDetId "
204  "(SMid,itt)=(%d,%d)->(eta,phi)=(%d,%d) \n",
205  SMid,
206  iTT,
207  etaTT,
208  phiTT);
209 
210  EcalTrigTowerDetId e_id(zside, EcalBarrel, etaTT, phiTT, 0);
211 
212  return e_id;
213 }
214 
217  int tower = create_TTDetId(data).rawId();
218  int Et = data.get_energy();
219  bool tt_fg = data.get_fg();
220  // unsigned input = data.input;
221  // int Et = input & 0x3ff; //get bits 0-9
222  // bool tt_fg = input & 0x400; //get bit number 10
223 
225  unsigned int lut_[1024];
226  if (!useIdentityLUT_)
227  getLUT(lut_, tower, evtSetup);
228  else
229  for (int i = 0; i < 1024; i++)
230  lut_[i] = i; // identity lut!
231 
233  int lut_out = lut_[Et];
234  int ttFlag = (lut_out & 0x700) >> 8;
235  int cEt = (lut_out & 0xff);
236 
238  if (debug_ && data.get_energy() != 0)
239  printf(
240  "[EcalFEtoDigi] Creating sample; input:0x%X (Et:0x%x) cEt:0x%x "
241  "fg:%d ttflag:0x%x \n",
242  data.input,
243  Et,
244  cEt,
245  tt_fg,
246  ttFlag);
247 
248  EcalTriggerPrimitiveSample e_sample(cEt, tt_fg, ttFlag);
249 
250  return e_sample;
251 }
252 
255  int tower = create_TTDetId(data).rawId();
256  int Et = data.get_energy();
257  bool tt_fg = data.get_fg();
258 
260  unsigned int lut_[1024];
261  if (!useIdentityLUT_)
262  getLUT(lut_, tower, evtSetup);
263  else
264  for (int i = 0; i < 1024; i++)
265  lut_[i] = i; // identity lut!
266 
267  int lut_out = lut_[Et];
268  int ttFlag = (lut_out & 0x700) >> 8;
269  int tcpdata = ((ttFlag & 0x7) << 11) | ((tt_fg & 0x1) << 10) | (Et & 0x3ff);
270 
271  EcalTriggerPrimitiveSample e_sample(tcpdata);
272 
273  return e_sample;
274 }
275 
280  if (sm_ != -1 && (sm_ < 1 || sm_ > 36))
281  throw cms::Exception("EcalFEtoDigiInvalidDetId") << "EcalFEtoDigi: Adapt SM numbering convention.\n";
282 
284  if (debug_)
285  outfile.open("inputcopy.txt");
286 
287  readInput();
288 }
289 
292  if (outfile.is_open())
293  outfile.close();
294 }
295 
297 int EcalFEtoDigi::SMidToTCCid(const int smid) const { return (smid <= 18) ? smid + 55 - 1 : smid + 37 - 19; }
298 
300 void EcalFEtoDigi::getLUT(unsigned int *lut, const int towerId, const edm::EventSetup &evtSetup) const {
301  const EcalTPGGroups::EcalTPGGroupsMap &lutGrpMap = evtSetup.getData(tpgLutGroupToken_).getMap();
302  EcalTPGGroups::EcalTPGGroupsMapItr itgrp = lutGrpMap.find(towerId);
303  uint32_t lutGrp = 999;
304  if (itgrp != lutGrpMap.end())
305  lutGrp = itgrp->second;
306 
307  const EcalTPGLutIdMap::EcalTPGLutMap &lutMap = evtSetup.getData(tpgLutIdMapToken_).getMap();
308  EcalTPGLutIdMap::EcalTPGLutMapItr itLut = lutMap.find(lutGrp);
309  if (itLut != lutMap.end()) {
310  const unsigned int *theLut = (itLut->second).getLut();
311  for (unsigned int i = 0; i < 1024; i++)
312  lut[i] = theLut[i];
313  }
314 }
bool fineGrain() const
get the fine-grain bit of interesting sample
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
int ieta() const
get the tower ieta
const edm::ESGetToken< EcalTPGLutGroup, EcalTPGLutGroupRcd > tpgLutGroupToken_
Definition: EcalFEtoDigi.h:55
EcalFEtoDigi(const edm::ParameterSet &)
Definition: EcalFEtoDigi.cc:3
std::map< uint32_t, uint32_t >::const_iterator EcalTPGGroupsMapItr
Definition: EcalTPGGroups.h:20
const EcalTrigTowerDetId & id() const
void readInput()
open and read in input (flat) data file
TCCInputData inputdata_[N_SM]
Definition: EcalFEtoDigi.h:58
void produce(edm::Event &, const edm::EventSetup &) override
method called to produce the data
Definition: EcalFEtoDigi.cc:18
int SMidToTCCid(const int) const
translate input supermodule id into TCC id (barrel)
int zside(DetId const &)
int iEvent
Definition: GenABIO.cc:224
Definition: TTTypes.h:54
void endJob() override
method called once each job just after ending the event loop
unsigned towerId(DetId const &, EcalElectronicsMapping const *)
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
const bool useIdentityLUT_
Definition: EcalFEtoDigi.h:61
static const int N_SM
Definition: EcalFEtoDigi.h:36
double f[11][100]
int compressedEt() const
get the encoded/compressed Et of interesting sample
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
EcalTriggerPrimitiveSample create_TPSampleTcp(TCCinput, const edm::EventSetup &)
create EcalTriggerPrimitiveSample in tcp format (uncomrpessed energy)
const int fileEventOffset_
Definition: EcalFEtoDigi.h:65
const std::string basename_
Definition: EcalFEtoDigi.h:60
std::map< uint32_t, EcalTPGLut > EcalTPGLutMap
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
int ttFlag() const
get the Trigger tower Flag of interesting sample
void getLUT(unsigned int *lut, const int towerId, const edm::EventSetup &) const
return the LUT from eventSetup
const edm::ESGetToken< EcalTPGLutIdMap, EcalTPGLutIdMapRcd > tpgLutIdMapToken_
Definition: EcalFEtoDigi.h:56
void clear(EGIsoObj &c)
Definition: egamma.h:82
void beginJob() override
method called once each job just before starting event loop
int iphi() const
get the tower iphi
EcalTriggerPrimitiveSample create_TPSample(TCCinput, const edm::EventSetup &)
create EcalTriggerPrimitiveSample from input data (line)
const bool debug_
Definition: EcalFEtoDigi.h:66
std::map< uint32_t, uint32_t > EcalTPGGroupsMap
Definition: EcalTPGGroups.h:19
std::map< uint32_t, EcalTPGLut >::const_iterator EcalTPGLutMapItr
def move(src, dest)
Definition: eostools.py:511
std::ofstream outfile
Definition: EcalFEtoDigi.h:67
EcalTrigTowerDetId create_TTDetId(TCCinput)
create EcalTrigTowerDetId from input data (line)