CMS 3D CMS Logo

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