CMS 3D CMS Logo

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 #include <TTree.h>
34 #include <TMath.h>
35 
36 //----------------------------------------------------------------------
37 
38 const unsigned int EcalEBTrigPrimTestAlgo::nrSamples_ = 5;
39 const unsigned int EcalEBTrigPrimTestAlgo::maxNrTowers_ = 2448;
40 const unsigned int EcalEBTrigPrimTestAlgo::maxNrSamplesOut_ = 10;
41 
42 // not BarrelOnly
44  const CaloGeometry *theGeometry,
45  int nSam,
46  int binofmax,
47  bool tcpFormat,
48  bool debug,
49  bool famos)
50  : eTTmap_(eTTmap),
51  theGeometry_(theGeometry),
52  nSamples_(nSam),
53  binOfMaximum_(binofmax),
54  tcpFormat_(tcpFormat),
55  barrelOnly_(false),
56  debug_(debug),
57  famos_(famos) {
58  maxNrSamples_ = 10;
59  this->init();
60 }
61 
62 //barrel only
63 EcalEBTrigPrimTestAlgo::EcalEBTrigPrimTestAlgo(int nSam, int binofmax, bool tcpFormat, bool debug, bool famos)
64  : nSamples_(nSam),
65  binOfMaximum_(binofmax),
66  tcpFormat_(tcpFormat),
67  barrelOnly_(true),
68  debug_(debug),
69  famos_(famos)
70 
71 {
72  maxNrSamples_ = 10;
73  this->init();
74 }
75 
76 //----------------------------------------------------------------------
78  // initialise data structures
81  hitTowers_.resize(maxNrTowers_);
82 
83  linearizer_.resize(nbMaxXtals_);
84  for (int i = 0; i < nbMaxXtals_; i++)
86 
87  //
88  std::vector<int> v;
89  v.resize(maxNrSamples_);
90  lin_out_.resize(nbMaxXtals_);
91  for (int i = 0; i < 5; i++)
92  lin_out_[i] = v;
93  //
95  filt_out_.resize(maxNrSamples_);
96  peak_out_.resize(maxNrSamples_);
97  // these two are dummy
98  fgvb_out_.resize(maxNrSamples_);
100  //
103  format_out_.resize(maxNrSamples_);
104  //
107 }
108 //----------------------------------------------------------------------
109 
111  for (int i = 0; i < nbMaxXtals_; i++)
112  delete linearizer_[i];
113  delete amplitude_filter_;
114  delete peak_finder_;
115  delete fenixFormatterEB_;
116  delete fenixTcpFormat_;
117  delete theMapping_;
118 }
119 
122  EcalEBTrigPrimDigiCollection &resultTcp) {
123  //typedef typename Coll::Digi Digi;
124  if (debug_) {
125  std::cout << " EcalEBTrigPrimTestAlgo: Testing that the algorythm with digis is well plugged " << std::endl;
126  std::cout << " EcalEBTrigPrimTestAlgo: digi size " << digi->size() << std::endl;
127  }
128 
129  uint16_t etInADC;
131  int firstSample = binOfMaximum_ - 1 - nrSamples_ / 2;
132  int lastSample = binOfMaximum_ - 1 + nrSamples_ / 2;
133 
134  if (debug_) {
135  std::cout << " binOfMaximum_ " << binOfMaximum_ << " nrSamples_" << nrSamples_ << std::endl;
136  std::cout << " first sample " << firstSample << " last " << lastSample << std::endl;
137  }
138 
140  fillMap(digi, towerMapEB_);
141 
142  for (int itow = 0; itow < nrTowers_; ++itow) {
143  int index = hitTowers_[itow].first;
144  const EcalTrigTowerDetId &thisTower = hitTowers_[itow].second;
145  if (debug_)
146  std::cout << " Data for TOWER num " << itow << " index " << index << " TowerId " << thisTower << " size "
147  << towerMapEB_[itow].size() << std::endl;
148  // loop over all strips assigned to this trigger tower
149  int nxstals = 0;
150  for (unsigned int iStrip = 0; iStrip < towerMapEB_[itow].size(); ++iStrip) {
151  if (debug_)
152  std::cout << " Data for STRIP num " << iStrip << std::endl;
153  std::vector<EBDataFrame> &dataFrames =
154  (towerMapEB_[index])[iStrip].second; //vector of dataframes for this strip, size; nr of crystals/strip
155 
156  nxstals = (towerMapEB_[index])[iStrip].first;
157  if (nxstals <= 0)
158  continue;
159  if (debug_)
160  std::cout << " Number of xTals " << nxstals << std::endl;
161 
162  const EcalTriggerElectronicsId elId = theMapping_->getTriggerElectronicsId(dataFrames[0].id());
163  uint32_t stripid = elId.rawId() & 0xfffffff8;
164 
165  // loop over the xstals in a strip
166  for (int iXstal = 0; iXstal < nxstals; iXstal++) {
167  const EBDetId &myid = dataFrames[iXstal].id();
169  tp.setSize(nrSamples_);
170 
171  if (debug_) {
172  std::cout << std::endl;
173  std::cout << "iXstal= " << iXstal << " id " << dataFrames[iXstal].id() << " EBDataFrame is: " << std::endl;
174  for (int i = 0; i < dataFrames[iXstal].size(); i++) {
175  std::cout << " " << std::dec << dataFrames[iXstal][i].adc();
176  }
177  std::cout << std::endl;
178  }
179  // Call the linearizer
180  this->getLinearizer(iXstal)->setParameters(
181  dataFrames[iXstal].id().rawId(), ecaltpPed_, ecaltpLin_, ecaltpgBadX_);
182  this->getLinearizer(iXstal)->process(dataFrames[iXstal], lin_out_[iXstal]);
183 
184  for (unsigned int i = 0; i < lin_out_[iXstal].size(); i++) {
185  if ((lin_out_[iXstal])[i] > 0X3FFFF)
186  (lin_out_[iXstal])[i] = 0X3FFFF;
187  }
188 
189  if (debug_) {
190  std::cout << "output of linearizer for channel " << iXstal << std::endl;
191  std::cout << " lin_out[iXstal].size()= " << std::dec << lin_out_[iXstal].size() << std::endl;
192  for (unsigned int i = 0; i < lin_out_[iXstal].size(); i++) {
193  std::cout << " " << std::dec << (lin_out_[iXstal])[i];
194  }
195  std::cout << std::endl;
196  }
197 
198  // Call the amplitude filter
201 
202  if (debug_) {
203  std::cout << "output of filter is a vector of size: " << std::dec << filt_out_.size() << std::endl;
204  for (unsigned int ix = 0; ix < filt_out_.size(); ix++) {
205  std::cout << std::dec << filt_out_[ix] << " ";
206  }
207  std::cout << std::endl;
208  }
209 
210  // call peakfinder
212 
213  if (debug_) {
214  std::cout << "output of peakfinder is a vector of size: " << std::dec << peak_out_.size() << std::endl;
215  for (unsigned int ix = 0; ix < peak_out_.size(); ix++) {
216  std::cout << std::dec << peak_out_[ix] << " ";
217  }
218  std::cout << std::endl;
219  }
220 
221  // call formatter
222  this->getFormatterEB()->setParameters(stripid, ecaltpgSlidW_);
224 
225  if (debug_) {
226  std::cout << "output of formatter is a vector of size: " << format_out_.size() << std::endl;
227  for (unsigned int i = 0; i < format_out_.size(); i++) {
228  std::cout << " " << std::dec << format_out_[i] << " ";
229  }
230  std::cout << std::endl;
231  }
232 
233  // call final tcp formatter
234  this->getFormatter()->setParameters(
237  // loop over the time samples and fill the TP
238  int nSam = 0;
239  for (int iSample = firstSample; iSample <= lastSample; ++iSample) {
240  etInADC = tcpformat_out_[iSample];
241  if (debug_)
242  std::cout << " format_out " << tcpformat_out_[iSample] << " etInADC " << etInADC << std::endl;
243 
244  bool isASpike = false; // no spikes for now
245  int timing = 0; // set to 0 value for now
246  tp.setSample(nSam, EcalEBTriggerPrimitiveSample(etInADC, isASpike, timing));
247 
248  nSam++;
249  if (debug_)
250  std::cout << "in TestAlgo"
251  << " tp size " << tp.size() << std::endl;
252  }
253 
254  if (!tcpFormat_)
255  result.push_back(tp);
256  else
257  resultTcp.push_back(tp);
258 
259  } // Loop over the xStals
260 
261  } //loop over strips in one tower
262  }
263 
264  /*
265  for (unsigned int i=0;i<digi->size();i++) {
266  EBDataFrame myFrame((*digi)[i]);
267  const EBDetId & myid1 = myFrame.id();
268  tp= EcalTriggerPrimitiveDigi( myid1);
269  tp.setSize( myFrame.size());
270  int nSam=0;
271 
272  if (debug_) {
273  std::cout << " data frame size " << myFrame.size() << " Id " << myFrame.id() << std::endl;
274  std::cout << " Sample data ADC: " << std::endl;
275  for (int iSample=0; iSample<myFrame.size(); iSample++) {
276  std::cout << " " << std::dec<< myFrame.sample(iSample).adc() ;
277  }
278  std::cout<<std::endl;
279  }
280 
281 
282  this->getLinearizer(i)->setParameters( myFrame.id().rawId(),ecaltpPed_,ecaltpLin_,ecaltpgBadX_) ;
283  //this->getLinearizer(i)->process( myFrame,lin_out_[i]);
284 
285  if (debug_) {
286  std::cout<< "cryst: "<< i <<" value : "<<std::dec<<std::endl;
287  std::cout<<" lin_out[i].size()= "<<std::dec<<lin_out_[i].size()<<std::endl;
288  for (unsigned int j =0; j<lin_out_[i].size();j++){
289  std::cout <<" "<<std::dec<<(lin_out_[i])[j];
290  }
291  std::cout<<std::endl;
292  }
293 
294 
295  for (int iSample=0; iSample<myFrame.size(); iSample++) {
296  etInADC= myFrame.sample(iSample).adc();
297  EcalEBTriggerPrimitiveSample mysam(etInADC);
298  tp.setSample(nSam, mysam );
299  nSam++;
300  if (debug_) std::cout << "in TestAlgo" <<" tp size "<<tp.size() << std::endl;
301  }
302 
303  if (!tcpFormat_)
304  result.push_back(tp);
305  else
306  resultTcp.push_back(tp);
307 
308 
309  if (debug_) std::cout << " result size " << result.size() << std::endl;
310 
311 
312 
313  }
314  */
315 }
316 
317 //----------------------------------------------------------------------
318 
320  int stripnr;
321  int n = ((id.ic() - 1) % 100) / 20; //20 corresponds to 4 * ecal_barrel_crystals_per_strip FIXME!!
322  if (id.ieta() < 0)
323  stripnr = n + 1;
324  else
325  stripnr = nbMaxStrips_ - n;
326  return stripnr;
327 }
calculates .... for Fenix strip, barrel input: 18 bits output: 18 bits
EcalEBFenixLinearizer * getLinearizer(int i) const
static const unsigned int nrSamples_
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_
Linearisation for Fenix strip input: 16 bits corresponding to input EBDataFrame output: 18 bits...
EcalEBFenixPeakFinder * getPeakFinder() const
Formatting for Fenix strip input: 18 bits + 3x 1bit (fgvb, gapflagbit, output from peakfinder) output...
void push_back(T const &t)
const EcalTPGSlidingWindow * ecaltpgSlidW_
EcalTriggerElectronicsId getTriggerElectronicsId(const DetId &id) const
Get the trigger electronics id for this det id.
const EcalTPGSpike * ecaltpgSpike_
EcalEBFenixTcpFormat * getFormatter() const
const EcalTPGCrystalStatus * ecaltpgBadX_
EcalEBFenixAmplitudeFilter * amplitude_filter_
EcalEBFenixPeakFinder * peak_finder_
U second(std::pair< T, U > const &p)
const EcalTPGLinearizationConst * ecaltpLin_
std::vector< std::pair< int, EcalTrigTowerDetId > > hitTowers_
Formatting for Fenix Tcp input 10 bits from Ettot 1 bit from fgvb 3 bits TriggerTowerFlag output: 16 ...
EcalEBFenixAmplitudeFilter * getFilter() const
std::vector< std::vector< std::pair< int, std::vector< EBDataFrame > > > > towerMapEB_
void initStructures(std::vector< std::vector< std::pair< int, std::vector< T > > > > &towMap)
const EcalTPGWeightGroup * ecaltpgWeightGroup_
const EcalTPGTowerStatus * ecaltpgBadTT_
EcalEBFenixStripFormatEB * fenixFormatterEB_
EcalEBFenixStripFormatEB * getFormatterEB() const
calculates the peak for Fenix strip, barrel input : 18 bits output: boolean
void setParameters(uint32_t towid, const EcalTPGLutGroup *ecaltpgLutGroup, const EcalTPGLutIdMap *ecaltpgLut, const EcalTPGTowerStatus *ecaltpgbadTT, const EcalTPGSpike *ecaltpgSpike)
#define debug
Definition: HDRShower.cc:19
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static const unsigned int maxNrTowers_
std::vector< int > fgvb_out_temp_
std::vector< int > tcpformat_out_
int findStripNr(const EBDetId &id)
const EcalElectronicsMapping * theMapping_
void process(std::vector< int > &, std::vector< int > &)
void run(const EBDigiCollection *col, EcalEBTrigPrimDigiCollection &result, EcalEBTrigPrimDigiCollection &resultTcp)
void setParameters(uint32_t raw, const EcalTPGPedestals *ecaltpPed, const EcalTPGLinearizationConst *ecaltpLin, const EcalTPGCrystalStatus *ecaltpBadX)
EcalEBFenixTcpFormat * fenixTcpFormat_
void clean(std::vector< std::vector< std::pair< int, std::vector< T > > > > &towerMap)
std::vector< EcalEBFenixLinearizer * > linearizer_
EcalEBTrigPrimTestAlgo(const EcalTrigTowerConstituentsMap *eTTmap, const CaloGeometry *theGeometry, int nSamples, int binofmax, bool tcpFormat, bool debug, bool famos)
const EcalTPGPedestals * ecaltpPed_
void setParameters(uint32_t raw, const EcalTPGWeightIdMap *ecaltpgWeightMap, const EcalTPGWeightGroup *ecaltpgWeightGroup)
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_
void setParameters(uint32_t &, const EcalTPGSlidingWindow *&)
std::vector< std::vector< int > > lin_out_
const EcalTPGWeightIdMap * ecaltpgWeightMap_