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 
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 
106  EBDigiCollection const * digi,
108  EcalEBTrigPrimDigiCollection & resultTcp)
109 {
110 
111  //typedef typename Coll::Digi Digi;
112  if (debug_) {
113  std::cout << " EcalEBTrigPrimTestAlgo: Testing that the algorythm with digis is well plugged " << std::endl;
114  std::cout << " EcalEBTrigPrimTestAlgo: digi size " << digi->size() << std::endl;
115  }
116 
117  uint16_t etInADC;
120  int lastSample = binOfMaximum_-1 +nrSamples_/2;
121 
122  if (debug_) {
123  std::cout << " binOfMaximum_ " << binOfMaximum_ << " nrSamples_" << nrSamples_ << std::endl;
124  std::cout << " first sample " << firstSample << " last " << lastSample <<std::endl;
125  }
126 
128  fillMap(digi,towerMapEB_);
129 
130  for(int itow=0;itow<nrTowers_;++itow) {
131 
132  int index=hitTowers_[itow].first;
133  const EcalTrigTowerDetId &thisTower=hitTowers_[itow].second;
134  if (debug_) std::cout << " Data for TOWER num " << itow << " index " << index << " TowerId " << thisTower << " size " << towerMapEB_[itow].size() << std::endl;
135  // loop over all strips assigned to this trigger tower
136  int nxstals=0;
137  for(unsigned int iStrip = 0; iStrip < towerMapEB_[itow].size();++iStrip)
138  {
139  if (debug_) std::cout << " Data for STRIP num " << iStrip << std::endl;
140  std::vector<EBDataFrame> &dataFrames = (towerMapEB_[index])[iStrip].second;//vector of dataframes for this strip, size; nr of crystals/strip
141 
142  nxstals = (towerMapEB_[index])[iStrip].first;
143  if (nxstals <= 0) continue;
144  if (debug_) std::cout << " Number of xTals " << nxstals << std::endl;
145 
146  const EcalTriggerElectronicsId elId = theMapping_->getTriggerElectronicsId(dataFrames[0].id());
147  uint32_t stripid=elId.rawId() & 0xfffffff8;
148 
149 
150  // loop over the xstals in a strip
151  for (int iXstal=0;iXstal<nxstals;iXstal++) {
152  const EBDetId & myid = dataFrames[iXstal].id();
153  tp= EcalEBTriggerPrimitiveDigi( myid );
154  tp.setSize( nrSamples_);
155 
156 
157  if(debug_){
158  std::cout<<std::endl;
159  std::cout <<"iXstal= "<<iXstal<< " id " << dataFrames[iXstal].id() << " EBDataFrame is: "<<std::endl;
160  for ( int i = 0; i<dataFrames[iXstal].size();i++){
161  std::cout <<" "<<std::dec<<dataFrames[iXstal][i].adc();
162  }
163  std::cout<<std::endl;
164  }
165  // Call the linearizer
166  this->getLinearizer(iXstal)->setParameters( dataFrames[iXstal].id().rawId(),ecaltpPed_,ecaltpLin_,ecaltpgBadX_) ;
167  this->getLinearizer(iXstal)->process( dataFrames[iXstal],lin_out_[iXstal]);
168 
169  for (unsigned int i =0; i<lin_out_[iXstal].size();i++){
170  if( (lin_out_[iXstal])[i]>0X3FFFF) (lin_out_[iXstal])[i]=0X3FFFF;
171  }
172 
173 
174  if ( debug_ ) {
175  std::cout<< "output of linearizer for channel " << iXstal << std::endl;
176  std::cout<<" lin_out[iXstal].size()= "<<std::dec<<lin_out_[iXstal].size()<<std::endl;
177  for (unsigned int i =0; i<lin_out_[iXstal].size();i++){
178  std::cout <<" "<<std::dec<<(lin_out_[iXstal])[i];
179  }
180  std::cout<<std::endl;
181  }
182 
183 
184 
185  // Call the amplitude filter
188 
189  if(debug_){
190  std::cout<< "output of filter is a vector of size: "<<std::dec<<filt_out_.size()<<std::endl;
191  for (unsigned int ix=0;ix<filt_out_.size();ix++){
192  std::cout<<std::dec<<filt_out_[ix] << " " ;
193  }
194  std::cout<<std::endl;
195  }
196 
197  // call peakfinder
199 
200  if(debug_){
201  std::cout<< "output of peakfinder is a vector of size: "<<std::dec<<peak_out_.size()<<std::endl;
202  for (unsigned int ix=0;ix<peak_out_.size();ix++){
203  std::cout<<std::dec<<peak_out_[ix] << " " ;
204  }
205  std::cout<<std::endl;
206  }
207 
208  // call formatter
209  this->getFormatterEB()->setParameters(stripid,ecaltpgSlidW_) ;
211 
212  if (debug_) {
213  std::cout<< "output of formatter is a vector of size: "<<format_out_.size()<<std::endl;
214  for (unsigned int i =0; i<format_out_.size();i++){
215  std::cout <<" "<<std::dec<<format_out_[i] << " " ;
216  }
217  std::cout<<std::endl;
218  }
219 
220 
221  // call final tcp formatter
224  // loop over the time samples and fill the TP
225  int nSam=0;
226  for (int iSample=firstSample;iSample<=lastSample;++iSample) {
227  etInADC= tcpformat_out_[iSample];
228  if (debug_) std::cout << " format_out " << tcpformat_out_[iSample] << " etInADC " << etInADC << std::endl;
229 
230  bool isASpike=false; // no spikes for now
231  int timing=0; // set to 0 value for now
232  tp.setSample(nSam, EcalEBTriggerPrimitiveSample(etInADC,isASpike,timing) );
233 
234  nSam++;
235  if (debug_) std::cout << "in TestAlgo" <<" tp size "<<tp.size() << std::endl;
236  }
237 
238 
239 
240  if (!tcpFormat_)
241  result.push_back(tp);
242  else
243  resultTcp.push_back(tp);
244 
245 
246 
247  } // Loop over the xStals
248 
249 
250 
251 
252  }//loop over strips in one tower
253 
254 
255 
256 
257  }
258 
259 
260 
261 
262  /*
263  for (unsigned int i=0;i<digi->size();i++) {
264  EBDataFrame myFrame((*digi)[i]);
265  const EBDetId & myid1 = myFrame.id();
266  tp= EcalTriggerPrimitiveDigi( myid1);
267  tp.setSize( myFrame.size());
268  int nSam=0;
269 
270  if (debug_) {
271  std::cout << " data frame size " << myFrame.size() << " Id " << myFrame.id() << std::endl;
272  std::cout << " Sample data ADC: " << std::endl;
273  for (int iSample=0; iSample<myFrame.size(); iSample++) {
274  std::cout << " " << std::dec<< myFrame.sample(iSample).adc() ;
275  }
276  std::cout<<std::endl;
277  }
278 
279 
280  this->getLinearizer(i)->setParameters( myFrame.id().rawId(),ecaltpPed_,ecaltpLin_,ecaltpgBadX_) ;
281  //this->getLinearizer(i)->process( myFrame,lin_out_[i]);
282 
283  if (debug_) {
284  std::cout<< "cryst: "<< i <<" value : "<<std::dec<<std::endl;
285  std::cout<<" lin_out[i].size()= "<<std::dec<<lin_out_[i].size()<<std::endl;
286  for (unsigned int j =0; j<lin_out_[i].size();j++){
287  std::cout <<" "<<std::dec<<(lin_out_[i])[j];
288  }
289  std::cout<<std::endl;
290  }
291 
292 
293  for (int iSample=0; iSample<myFrame.size(); iSample++) {
294  etInADC= myFrame.sample(iSample).adc();
295  EcalEBTriggerPrimitiveSample mysam(etInADC);
296  tp.setSample(nSam, mysam );
297  nSam++;
298  if (debug_) std::cout << "in TestAlgo" <<" tp size "<<tp.size() << std::endl;
299  }
300 
301  if (!tcpFormat_)
302  result.push_back(tp);
303  else
304  resultTcp.push_back(tp);
305 
306 
307  if (debug_) std::cout << " result size " << result.size() << std::endl;
308 
309 
310 
311  }
312  */
313 
314 }
315 
316 
317 
318 
319 
320 
321 //----------------------------------------------------------------------
322 
324  int stripnr;
325  int n=((id.ic()-1)%100)/20; //20 corresponds to 4 * ecal_barrel_crystals_per_strip FIXME!!
326  if (id.ieta()<0) stripnr = n+1;
327  else stripnr =nbMaxStrips_ - n;
328  return stripnr;
329 }
330 
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)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
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_
void setSample(int i, const EcalEBTriggerPrimitiveSample &sam)
const EcalTPGCrystalStatus * ecaltpgBadX_
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_
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:55
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)
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_