CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalEBTrigPrimTestAlgo.cc
Go to the documentation of this file.
1 
9 #include <string>
10 #include <algorithm>
11 #include <numeric>
12 #include <functional>
13 
15 
16 //#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
17 //#include "Geometry/Records/interface/CaloGeometryRecord.h"
20 
22 
29 
32 
33 
34 
35 #include <TTree.h>
36 #include <TMath.h>
37 
38 
39 //----------------------------------------------------------------------
40 
41 const unsigned int EcalEBTrigPrimTestAlgo::nrSamples_=5;
42 const unsigned int EcalEBTrigPrimTestAlgo::maxNrTowers_=2448;
43 const unsigned int EcalEBTrigPrimTestAlgo::maxNrSamplesOut_=10;
44 
45 
46 EcalEBTrigPrimTestAlgo::EcalEBTrigPrimTestAlgo(const edm::EventSetup & setup,int nSam, int binofmax,bool tcpFormat, bool barrelOnly,bool debug, bool famos):
47  nSamples_(nSam),binOfMaximum_(binofmax), tcpFormat_(tcpFormat), barrelOnly_(barrelOnly), debug_(debug), famos_(famos)
48 
49 {
50 
51  maxNrSamples_=10;
52  this->init(setup);
53 }
54 
55 //----------------------------------------------------------------------
57  if (!barrelOnly_) {
58  //edm::ESHandle<CaloGeometry> theGeometry;
59  // edm::ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle;
60  setup.get<CaloGeometryRecord>().get( theGeometry );
61  setup.get<IdealGeometryRecord>().get(eTTmap_);
62  }
63 
64  // initialise data structures
66  hitTowers_.resize(maxNrTowers_);
67 
68 
69  linearizer_.resize(nbMaxXtals_);
70  for (int i=0;i<nbMaxXtals_;i++) linearizer_[i] = new EcalFenixLinearizer(famos_);
71 
72  //
73  std::vector <int> v;
74  v.resize(maxNrSamples_);
75  lin_out_.resize(nbMaxXtals_);
76  for (int i=0;i<5;i++) lin_out_[i]=v;
77  //
79  filt_out_.resize(maxNrSamples_);
80  peak_out_.resize(maxNrSamples_);
81  // these two are dummy
82  fgvb_out_.resize(maxNrSamples_);
84  //
87  format_out_.resize(maxNrSamples_);
88  //
91 
92 }
93 //----------------------------------------------------------------------
94 
96 {
97  for (int i=0;i<nbMaxXtals_;i++) delete linearizer_[i];
98  delete amplitude_filter_;
99  delete peak_finder_;
100  delete fenixFormatterEB_;
101  delete fenixTcpFormat_;
102 }
103 
104 /*
105 void EcalEBTrigPrimTestAlgo::run(const edm::EventSetup & setup, EcalRecHitCollection const * rh,
106  EcalEBTrigPrimDigiCollection & result,
107  EcalEBTrigPrimDigiCollection & resultTcp)
108 {
109 
110 
111 
112  //std::cout << " EcalEBTrigPrimTestAlgo: Testing that the algorythm is well plugged " << std::endl;
113  //std::cout << " EcalEBTrigPrimTestAlgo: recHit size " << rh->size() << std::endl;
114 
115  edm::ESHandle<CaloSubdetectorGeometry> theBarrelGeometry_handle;
116  setup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
117  const CaloSubdetectorGeometry *theBarrelGeometry;
118  theBarrelGeometry = &(*theBarrelGeometry_handle);
119 
120 
121  EcalEBTriggerPrimitiveDigi tp;
122  std::vector<EcalTriggerPrimitiveSample> tpSam[10];
123 
124 
125  uint16_t fEt;
126  double EtSat=128.;
127 
128  for (unsigned int i=0;i<rh->size();i++) {
129  const EBDetId & myid1=(*rh)[i].id();
130  if ( (*rh)[i].energy() < 0.2 ) continue;
131  tp= EcalEBTriggerPrimitiveDigi( myid1);
132  tp.setSize(nSamples_);
133  int nSam=0;
134 
135  for (int iSample=0; iSample<nSamples_; iSample++) {
136  if (debug_) std::cout << " DetId " << myid1 << "Subdetector " << myid1.subdet() << " ieta " << myid1.ieta() << " iphi " << myid1.iphi() << std::endl;
137 
138  float theta = theBarrelGeometry->getGeometry(myid1)->getPosition().theta();
139  //uint16_t et=((*rh)[i].energy())*sin(theta);
140  double et=((*rh)[i].energy())*sin(theta);
141 
142  double lsb10bits = 0. ;
143  int tpgADC10b = 0.;
144  lsb10bits = EtSat/1024. ;
145  if (lsb10bits>0)
146  tpgADC10b = int(et/lsb10bits+0.5) ;
147 
148  if (debug_) std::cout << " Et in GeV " << et << " tpgADC10b " << tpgADC10b << std::endl;
149  fEt=et;
150 
151 
152  // if (fEt >0xfff)
153  // fEt=0xfff;
154  //fEt >>=2;
155  //if (fEt>0x3ff) fEt=0x3ff;
156 
157  //std::cout << " Et after formatting " << fEt << std::endl;
158  EcalTriggerPrimitiveSample mysam(fEt);
159  tp.setSample(nSam, mysam );
160  nSam++;
161  if (debug_) std::cout << "in TestAlgo" <<" tp size "<<tp.size() << std::endl;
162  }
163 
164 
165 
166  if (!tcpFormat_)
167  result.push_back(tp);
168  else
169  resultTcp.push_back(tp);
170 
171 
172  if (debug_) std::cout << " result size " << result.size() << std::endl;
173 
174  }
175 
176 }
177 */
178 
179 
181  EBDigiCollection const * digi,
183  EcalEBTrigPrimDigiCollection & resultTcp)
184 {
185 
186  //typedef typename Coll::Digi Digi;
187  if (debug_) {
188  std::cout << " EcalEBTrigPrimTestAlgo: Testing that the algorythm with digis is well plugged " << std::endl;
189  std::cout << " EcalEBTrigPrimTestAlgo: digi size " << digi->size() << std::endl;
190  }
191 
192  uint16_t etInADC;
196 
197  if (debug_) {
198  std::cout << " binOfMaximum_ " << binOfMaximum_ << " nrSamples_" << nrSamples_ << std::endl;
199  std::cout << " first sample " << firstSample << " last " << lastSample <<std::endl;
200  }
201 
203  fillMap(digi,towerMapEB_);
204 
205  for(int itow=0;itow<nrTowers_;++itow) {
206 
207  int index=hitTowers_[itow].first;
208  const EcalTrigTowerDetId &thisTower=hitTowers_[itow].second;
209  if (debug_) std::cout << " Data for TOWER num " << itow << " index " << index << " TowerId " << thisTower << " size " << towerMapEB_[itow].size() << std::endl;
210  // loop over all strips assigned to this trigger tower
211  int nxstals=0;
212  for(unsigned int iStrip = 0; iStrip < towerMapEB_[itow].size();++iStrip)
213  {
214  if (debug_) std::cout << " Data for STRIP num " << iStrip << std::endl;
215  std::vector<EBDataFrame> &dataFrames = (towerMapEB_[index])[iStrip].second;//vector of dataframes for this strip, size; nr of crystals/strip
216 
217  nxstals = (towerMapEB_[index])[iStrip].first;
218  if (nxstals <= 0) continue;
219  if (debug_) std::cout << " Number of xTals " << nxstals << std::endl;
220 
221  const EcalTriggerElectronicsId elId = theMapping_->getTriggerElectronicsId(dataFrames[0].id());
222  uint32_t stripid=elId.rawId() & 0xfffffff8;
223 
224 
225  // loop over the xstals in a strip
226  for (int iXstal=0;iXstal<nxstals;iXstal++) {
227  const EBDetId & myid = dataFrames[iXstal].id();
228  tp= EcalEBTriggerPrimitiveDigi( myid );
229  tp.setSize( nrSamples_);
230 
231 
232  if(debug_){
233  std::cout<<std::endl;
234  std::cout <<"iXstal= "<<iXstal<< " id " << dataFrames[iXstal].id() << " EBDataFrame is: "<<std::endl;
235  for ( int i = 0; i<dataFrames[iXstal].size();i++){
236  std::cout <<" "<<std::dec<<dataFrames[iXstal][i].adc();
237  }
238  std::cout<<std::endl;
239  }
240  // Call the linearizer
241  this->getLinearizer(iXstal)->setParameters( dataFrames[iXstal].id().rawId(),ecaltpPed_,ecaltpLin_,ecaltpgBadX_) ;
242  this->getLinearizer(iXstal)->process( dataFrames[iXstal],lin_out_[iXstal]);
243 
244  for (unsigned int i =0; i<lin_out_[iXstal].size();i++){
245  if( (lin_out_[iXstal])[i]>0X3FFFF) (lin_out_[iXstal])[i]=0X3FFFF;
246  }
247 
248 
249  if ( debug_ ) {
250  std::cout<< "output of linearizer for channel " << iXstal << std::endl;
251  std::cout<<" lin_out[iXstal].size()= "<<std::dec<<lin_out_[iXstal].size()<<std::endl;
252  for (unsigned int i =0; i<lin_out_[iXstal].size();i++){
253  std::cout <<" "<<std::dec<<(lin_out_[iXstal])[i];
254  }
255  std::cout<<std::endl;
256  }
257 
258 
259 
260  // Call the amplitude filter
263 
264  if(debug_){
265  std::cout<< "output of filter is a vector of size: "<<std::dec<<filt_out_.size()<<std::endl;
266  for (unsigned int ix=0;ix<filt_out_.size();ix++){
267  std::cout<<std::dec<<filt_out_[ix] << " " ;
268  }
269  std::cout<<std::endl;
270  }
271 
272  // call peakfinder
274 
275  if(debug_){
276  std::cout<< "output of peakfinder is a vector of size: "<<std::dec<<peak_out_.size()<<std::endl;
277  for (unsigned int ix=0;ix<peak_out_.size();ix++){
278  std::cout<<std::dec<<peak_out_[ix] << " " ;
279  }
280  std::cout<<std::endl;
281  }
282 
283  // call formatter
284  this->getFormatterEB()->setParameters(stripid,ecaltpgSlidW_) ;
286 
287  if (debug_) {
288  std::cout<< "output of formatter is a vector of size: "<<format_out_.size()<<std::endl;
289  for (unsigned int i =0; i<format_out_.size();i++){
290  std::cout <<" "<<std::dec<<format_out_[i] << " " ;
291  }
292  std::cout<<std::endl;
293  }
294 
295 
296  // call final tcp formatter
299 
300  // loop over the time samples and fill the TP
301  int nSam=0;
302  for (int iSample=firstSample;iSample<=lastSample;++iSample) {
303  etInADC= tcpformat_out_[iSample];
304  if (debug_) std::cout << " format_out " << tcpformat_out_[iSample] << " etInADC " << etInADC << std::endl;
305  // EcalTriggerPrimitiveSample mysam(etInADC);
306  //tp.setSample(nSam, mysam );
307 
308  tp.setSample(nSam, EcalTriggerPrimitiveSample(etInADC, false, 0) );
309 
310  nSam++;
311  if (debug_) std::cout << "in TestAlgo" <<" tp size "<<tp.size() << std::endl;
312  }
313 
314 
315 
316  if (!tcpFormat_)
317  result.push_back(tp);
318  else
319  resultTcp.push_back(tp);
320 
321 
322 
323  } // Loop over the xStals
324 
325 
326 
327 
328  }//loop over strips in one tower
329 
330 
331 
332 
333  }
334 
335 
336 
337 
338  /*
339  for (unsigned int i=0;i<digi->size();i++) {
340  EBDataFrame myFrame((*digi)[i]);
341  const EBDetId & myid1 = myFrame.id();
342  tp= EcalTriggerPrimitiveDigi( myid1);
343  tp.setSize( myFrame.size());
344  int nSam=0;
345 
346  if (debug_) {
347  std::cout << " data frame size " << myFrame.size() << " Id " << myFrame.id() << std::endl;
348  std::cout << " Sample data ADC: " << std::endl;
349  for (int iSample=0; iSample<myFrame.size(); iSample++) {
350  std::cout << " " << std::dec<< myFrame.sample(iSample).adc() ;
351  }
352  std::cout<<std::endl;
353  }
354 
355 
356  this->getLinearizer(i)->setParameters( myFrame.id().rawId(),ecaltpPed_,ecaltpLin_,ecaltpgBadX_) ;
357  //this->getLinearizer(i)->process( myFrame,lin_out_[i]);
358 
359  if (debug_) {
360  std::cout<< "cryst: "<< i <<" value : "<<std::dec<<std::endl;
361  std::cout<<" lin_out[i].size()= "<<std::dec<<lin_out_[i].size()<<std::endl;
362  for (unsigned int j =0; j<lin_out_[i].size();j++){
363  std::cout <<" "<<std::dec<<(lin_out_[i])[j];
364  }
365  std::cout<<std::endl;
366  }
367 
368 
369  for (int iSample=0; iSample<myFrame.size(); iSample++) {
370  etInADC= myFrame.sample(iSample).adc();
371  EcalTriggerPrimitiveSample mysam(etInADC);
372  tp.setSample(nSam, mysam );
373  nSam++;
374  if (debug_) std::cout << "in TestAlgo" <<" tp size "<<tp.size() << std::endl;
375  }
376 
377  if (!tcpFormat_)
378  result.push_back(tp);
379  else
380  resultTcp.push_back(tp);
381 
382 
383  if (debug_) std::cout << " result size " << result.size() << std::endl;
384 
385 
386 
387  }
388  */
389 
390 }
391 
392 
393 
394 
395 
396 
397 //----------------------------------------------------------------------
398 
400  int stripnr;
401  int n=((id.ic()-1)%100)/20; //20 corresponds to 4 * ecal_barrel_crystals_per_strip FIXME!!
402  if (id.ieta()<0) stripnr = n+1;
403  else stripnr =nbMaxStrips_ - n;
404  return stripnr;
405 }
406 
int i
Definition: DBlmapReader.cc:9
void setParameters(uint32_t raw, const EcalTPGPedestals *ecaltpPed, const EcalTPGLinearizationConst *ecaltpLin, const EcalTPGCrystalStatus *ecaltpBadX)
void process(std::vector< int > &, std::vector< int > &)
std::vector< std::vector< std::pair< int, std::vector< EBDataFrame > > > > towerMapEB_
EcalFenixStripFormatEB * fenixFormatterEB_
static const unsigned int nrSamples_
EcalFenixPeakFinder * getPeakFinder() const
void fillMap(Coll const *col, std::vector< std::vector< std::pair< int, std::vector< typename Coll::Digi > > > > &towerMap)
std::vector< int > format_out_
static const unsigned int maxNrSamplesOut_
void push_back(T const &t)
const EcalTPGSlidingWindow * ecaltpgSlidW_
calculates the peak for Fenix strip, barrel input : 18 bits output: boolean
EcalFenixTcpFormat * getFormatter() const
EcalFenixLinearizer * getLinearizer(int i) const
EcalEBTrigPrimTestAlgo(const edm::EventSetup &setup, int nSamples, int binofmax, bool tcpFormat, bool barrelOnly, bool debug, bool famos)
const EcalTPGSpike * ecaltpgSpike_
const EcalTPGCrystalStatus * ecaltpgBadX_
tuple result
Definition: mps_fire.py:84
EcalFenixStripFormatEB * getFormatterEB() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
const EcalTPGLinearizationConst * ecaltpLin_
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
Linearisation for Fenix strip input: 16 bits corresponding to input EBDataFrame output: 18 bits...
EcalTriggerElectronicsId getTriggerElectronicsId(const DetId &id) const
Get the trigger electronics id for this det id.
std::vector< std::pair< int, EcalTrigTowerDetId > > hitTowers_
EcalFenixAmplitudeFilter * getFilter() const
void initStructures(std::vector< std::vector< std::pair< int, std::vector< T > > > > &towMap)
calculates .... for Fenix strip, barrel input: 18 bits output: 18 bits
const EcalTPGWeightGroup * ecaltpgWeightGroup_
const EcalTPGTowerStatus * ecaltpgBadTT_
void run(const edm::EventSetup &, const EBDigiCollection *col, EcalEBTrigPrimDigiCollection &result, EcalEBTrigPrimDigiCollection &resultTcp)
#define debug
Definition: HDRShower.cc:19
Formatting for Fenix strip input: 18 bits + 3x 1bit (fgvb, gapflagbit, output from peakfinder) output...
std::vector< EcalFenixLinearizer * > linearizer_
void setParameters(uint32_t towid, const EcalTPGLutGroup *ecaltpgLutGroup, const EcalTPGLutIdMap *ecaltpgLut, const EcalTPGTowerStatus *ecaltpgbadTT, const EcalTPGSpike *ecaltpgSpike)
edm::ESHandle< CaloGeometry > theGeometry
const T & get() const
Definition: EventSetup.h:56
static const unsigned int maxNrTowers_
std::vector< int > fgvb_out_temp_
edm::ESHandle< EcalTrigTowerConstituentsMap > eTTmap_
std::vector< int > tcpformat_out_
void setParameters(uint32_t &, const EcalTPGSlidingWindow *&)
int findStripNr(const EBDetId &id)
const EcalElectronicsMapping * theMapping_
void setParameters(uint32_t raw, const EcalTPGWeightIdMap *ecaltpgWeightMap, const EcalTPGWeightGroup *ecaltpgWeightGroup)
tuple cout
Definition: gather_cfg.py:145
EcalFenixAmplitudeFilter * amplitude_filter_
void clean(std::vector< std::vector< std::pair< int, std::vector< T > > > > &towerMap)
void init(const edm::EventSetup &)
const EcalTPGPedestals * ecaltpPed_
EcalFenixPeakFinder * peak_finder_
const EcalTPGLutIdMap * ecaltpgLut_
Ecal trigger electronics identification [32:20] Unused (so far) [19:13] TCC id [12:6] TT id [5:3] pse...
const EcalTPGLutGroup * ecaltpgLutGroup_
std::vector< std::vector< int > > lin_out_
EcalFenixTcpFormat * fenixTcpFormat_
const EcalTPGWeightIdMap * ecaltpgWeightMap_