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