CMS 3D CMS Logo

EcalEBPhase2TrigPrimAlgo.cc
Go to the documentation of this file.
1 #include <string>
2 #include <algorithm>
3 #include <numeric>
4 #include <functional>
5 
10 
12 
18 
21 
23 
24 #include <TTree.h>
25 #include <TMath.h>
26 
27 //----------------------------------------------------------------------
28 
29 const unsigned int EcalEBPhase2TrigPrimAlgo::nrSamples_ =
30  ecalPh2::sampleSize; // set to 16 samples, might change (less than 16) in the future
31 const unsigned int EcalEBPhase2TrigPrimAlgo::maxNrTowers_ = 2448; // number of towers in EB
32 
34  const CaloGeometry *theGeometry,
35  int binofmax,
36  bool debug)
37  : eTTmap_(eTTmap),
38  theGeometry_(theGeometry),
39  binOfMaximum_(binofmax),
40  debug_(debug)
41 
42 {
44  this->init();
45 }
46 
49  // initialise data structures
51  hitTowers_.resize(maxNrTowers_);
52 
54  lin_out_.resize(maxNrSamples_);
55 
57  filt_out_.resize(maxNrSamples_);
58 
60  outEt_.resize(maxNrSamples_);
61  outTime_.resize(maxNrSamples_);
62 
63  //
64 
66  time_out_.resize(maxNrSamples_);
68 }
69 //----------------------------------------------------------------------
70 
72  delete linearizer_;
74  delete time_reconstructor_;
75  delete spike_tagger_;
76  delete tpFormatter_;
77  delete theMapping_;
78 }
79 
81  if (debug_)
82  LogDebug("") << " EcalEBPhase2TrigPrimAlgo: digi size " << digi->size() << std::endl;
83 
85  int firstSample = binOfMaximum_ - 1 - nrSamples_ / 2;
86  int lastSample = binOfMaximum_ - 1 + nrSamples_ / 2;
87 
88  if (debug_) {
89  LogDebug("") << " binOfMaximum_ " << binOfMaximum_ << " nrSamples_" << nrSamples_ << std::endl;
90  LogDebug("") << " first sample " << firstSample << " last " << lastSample << std::endl;
91  }
92 
94  fillMap(digi, towerMapEB_);
95 
96  int iChannel = 0;
97  int nXinBCP = 0;
98  for (int itow = 0; itow < nrTowers_; ++itow) {
99  int index = hitTowers_[itow].first;
100  const EcalTrigTowerDetId &thisTower = hitTowers_[itow].second;
101  if (debug_)
102  LogDebug("") << " Data for TOWER num " << itow << " index " << index << " TowerId " << thisTower << " zside "
103  << thisTower.zside() << " ieta " << thisTower.ieta() << " iphi " << thisTower.iphi() << " size "
104  << towerMapEB_[itow].size() << std::endl;
105 
106  // loop over all strips assigned to this trigger tower
107  int nxstals = 0;
108  for (unsigned int iStrip = 0; iStrip < towerMapEB_[itow].size(); ++iStrip) {
109  if (debug_)
110  LogDebug("") << " Data for STRIP num " << iStrip << std::endl;
111  std::vector<EBDataFrame_Ph2> &dataFrames =
112  (towerMapEB_[index])[iStrip].second; //vector of dataframes for this strip, size; nr of crystals/strip
113 
114  nxstals = (towerMapEB_[index])[iStrip].first;
115  if (nxstals <= 0)
116  continue;
117  if (debug_)
118  LogDebug("") << " Number of xTals " << nxstals << std::endl;
119 
120  //const EcalTriggerElectronicsId elId = theMapping_->getTriggerElectronicsId(dataFrames[0].id());
121 
122  // loop over the xstals in a strip
123 
124  for (int iXstal = 0; iXstal < nxstals; iXstal++) {
125  const EBDetId &myid = dataFrames[iXstal].id();
126 
127  nXinBCP++;
128  if (debug_) {
129  LogDebug("") << " Data for TOWER num " << itow << " index " << index << " TowerId " << thisTower << " size "
130  << towerMapEB_[itow].size() << std::endl;
131  LogDebug("") << "nXinBCP " << nXinBCP << " myid rawId " << myid.rawId() << " xTal iEta " << myid.ieta()
132  << " iPhi " << myid.iphi() << std::endl;
133  }
134 
136  tp.setSize(nrSamples_);
137 
138  iChannel++;
139  if (debug_) {
140  LogDebug("") << " " << std::endl;
141  LogDebug("") << " ****** iChannel " << iChannel << std::endl;
142  for (int i = 0; i < dataFrames[iXstal].size(); i++) {
143  LogDebug("") << " " << dataFrames[iXstal][i].adc();
144  }
145  LogDebug("") << " " << std::endl;
146  }
147 
148  if (debug_) {
149  LogDebug("") << std::endl;
150  EBDetId id = dataFrames[iXstal].id();
151  LogDebug("") << "iXstal= " << iXstal << std::endl;
152  LogDebug("") << "iXstal= " << iXstal << " id " << id << " EcalDataFrame_Ph2 is: " << std::endl;
153  for (int i = 0; i < dataFrames[iXstal].size(); i++) {
154  LogDebug("") << " " << std::dec << dataFrames[iXstal][i].adc();
155  }
156  LogDebug("") << std::endl;
157  }
158 
159  // Call the linearizer
160  this->getLinearizer()->setParameters(dataFrames[iXstal].id(), ecaltpPed_, ecaltpLin_, ecaltpgBadX_);
161  this->getLinearizer()->process(dataFrames[iXstal], lin_out_);
162 
163  for (unsigned int i = 0; i < lin_out_.size(); i++) {
164  if (lin_out_[i] > 0X3FFF)
165  lin_out_[i] = 0X3FFF;
166  }
167 
168  if (debug_) {
169  LogDebug("") << "EcalEBPhase2TrigPrimAlgo output of linearize for channel " << iXstal << std::endl;
170  for (unsigned int i = 0; i < lin_out_.size(); i++) {
171  LogDebug("") << " " << std::dec << lin_out_[i];
172  }
173  LogDebug("") << std::endl;
174  }
175 
176  // call spike finder right after the linearizer
177  this->getSpikeTagger()->setParameters(dataFrames[iXstal].id(), ecaltpPed_, ecaltpLin_, ecaltpgBadX_);
178  bool isASpike = this->getSpikeTagger()->process(lin_out_);
179 
180  //if (!isASpike) {
181 
182  // Call the amplitude reconstructor
185 
186  if (debug_) {
187  LogDebug("") << "EcalEBPhase2TrigPrimAlgo output of amp finder is a vector of size: " << std::dec
188  << time_out_.size() << std::endl;
189  for (unsigned int ix = 0; ix < filt_out_.size(); ix++) {
190  LogDebug("") << std::dec << filt_out_[ix] << " ";
191  }
192  LogDebug("") << std::endl;
193  }
194 
195  if (debug_) {
196  LogDebug("") << " Ampl "
197  << " ";
198  for (unsigned int ix = 0; ix < filt_out_.size(); ix++) {
199  LogDebug("") << std::dec << filt_out_[ix] << " ";
200  }
201  LogDebug("") << std::endl;
202  }
203 
204  // call time finder
207 
208  if (debug_) {
209  LogDebug("") << " Time "
210  << " ";
211  for (unsigned int ix = 0; ix < time_out_.size(); ix++) {
212  LogDebug("") << std::dec << time_out_[ix] << " ";
213  }
214  LogDebug("") << std::endl;
215  }
216 
217  if (debug_) {
218  LogDebug("") << "EcalEBPhase2TrigPrimAlgo output of timefinder is a vector of size: " << std::dec
219  << time_out_.size() << std::endl;
220  for (unsigned int ix = 0; ix < time_out_.size(); ix++) {
221  LogDebug("") << std::dec << time_out_[ix] << " ";
222  }
223  LogDebug("") << std::endl;
224  }
225 
227 
228  if (debug_) {
229  LogDebug("") << " compressed Et "
230  << " ";
231  for (unsigned int iSample = 0; iSample < outEt_.size(); ++iSample) {
232  LogDebug("") << outEt_[iSample] << " ";
233  }
234  LogDebug("") << std::endl;
235 
236  LogDebug("") << " compressed time "
237  << " ";
238  for (unsigned int iSample = 0; iSample < outEt_.size(); ++iSample) {
239  LogDebug("") << outTime_[iSample] << " ";
240  }
241  LogDebug("") << std::endl;
242  }
243 
244  if (debug_) {
245  LogDebug("") << " EcalEBPhase2TrigPrimAlgo after getting the formatter " << std::endl;
246  for (unsigned int iSample = 0; iSample < outEt_.size(); ++iSample) {
247  LogDebug("") << " outEt " << outEt_[iSample] << " outTime " << outTime_[iSample] << " ";
248  }
249  LogDebug("") << std::endl;
250  }
251 
252  // } not a spike
253 
254  // create the final TP samples
255  int etInADC = 0;
256  ;
257  int64_t time = -999;
258  int nSam = 0;
259  for (int iSample = 0; iSample < 16; ++iSample) {
260  etInADC = outEt_[iSample];
261  time = outTime_[iSample];
262  if (debug_) {
263  LogDebug("") << "TrigPrimAlgo outEt " << outEt_[iSample] << " outTime " << outTime_[iSample] << std::endl;
264  LogDebug("") << "TrigPrimAlgo etInADCt " << outEt_[iSample] << " outTime " << time << std::endl;
265  }
266 
267  tp.setSample(nSam, EcalEBPhase2TriggerPrimitiveSample(etInADC, isASpike, time));
268  nSam++;
269  }
270 
271  result.push_back(tp);
272 
273  } // Loop over the xStals
274 
275  } //loop over strips in one tower
276 
277  if (debug_) {
278  if (nXinBCP > 0)
279  LogDebug("") << " Accepted xTals " << nXinBCP << std::endl;
280  }
281  }
282 }
283 
284 //----------------------------------------------------------------------
285 
287  int stripnr;
288  int n = ((id.ic() - 1) % 100) / 20; //20 corresponds to 4 * ecal_barrel_crystals_per_strip FIXME!!
289  if (id.ieta() < 0)
290  stripnr = n + 1;
291  else
292  stripnr = nbMaxStrips_ - n;
293  return stripnr;
294 }
EcalEBPhase2AmplitudeReconstructor * amplitude_reconstructor_
const EcalEBPhase2TPGTimeWeightIdMap * ecaltpgTimeWeightMap_
int ieta() const
get the tower ieta
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
int findStripNr(const EBDetId &id)
void process(const EBDigiCollectionPh2::Digi &df, std::vector< int > &output_percry)
bool process(const std::vector< int > &linInput)
virtual void process(std::vector< int > &ampl, std::vector< int64_t > &time, std::vector< int > &outampl, std::vector< int64_t > &outtime)
std::vector< std::pair< int, EcalTrigTowerDetId > > hitTowers_
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
static const unsigned int nrSamples_
U second(std::pair< T, U > const &p)
EcalEBPhase2TimeReconstructor * getTimeFinder() const
static constexpr unsigned int sampleSize
Definition: EcalConstants.h:36
int zside() const
get the z-side of the tower (1/-1)
void run(const EBDigiCollectionPh2 *col, EcalEBPhase2TrigPrimDigiCollection &result)
const EcalTPGWeightGroup * ecaltpgWeightGroup_
static const unsigned int maxNrTowers_
EcalEBPhase2TimeReconstructor * time_reconstructor_
std::vector< int64_t > outTime_
EcalEBPhase2Linearizer * linearizer_
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
#define debug
Definition: HDRShower.cc:19
const EcalTPGCrystalStatus * ecaltpgBadX_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
EcalEBPhase2Linearizer * getLinearizer() const
std::vector< std::vector< std::pair< int, std::vector< EBDataFrame_Ph2 > > > > towerMapEB_
EcalEBPhase2SpikeTagger * spike_tagger_
void setParameters(EBDetId id, const EcalLiteDTUPedestalsMap *peds, const EcalEBPhase2TPGLinearizationConstMap *ecaltplin, const EcalTPGCrystalStatus *ecaltpBadX)
const EcalEBPhase2TPGLinearizationConstMap * ecaltpLin_
void setParameters(uint32_t raw, const EcalEBPhase2TPGAmplWeightIdMap *ecaltpgWeightMap, const EcalTPGWeightGroup *ecaltpgWeightGroup)
std::vector< int64_t > time_out_
const EcalLiteDTUPedestalsMap * ecaltpPed_
EcalEBPhase2TrigPrimAlgo(const EcalTrigTowerConstituentsMap *eTTmap, const CaloGeometry *theGeometry, int binofmax, bool debug)
const EcalElectronicsMapping * theMapping_
void initStructures(std::vector< std::vector< std::pair< int, std::vector< T > > > > &towMap)
EcalEBPhase2AmplitudeReconstructor * getAmplitudeFinder() const
void clean(std::vector< std::vector< std::pair< int, std::vector< T > > > > &towerMap)
EcalEBPhase2TPFormatter * tpFormatter_
void setParameters(EBDetId id, const EcalLiteDTUPedestalsMap *peds, const EcalEBPhase2TPGLinearizationConstMap *ecaltplin, const EcalTPGCrystalStatus *ecaltpBadX)
void setParameters(uint32_t raw, const EcalEBPhase2TPGTimeWeightIdMap *ecaltpgTimeWeightMap, const EcalTPGWeightGroup *ecaltpgWeightGroup)
int iphi() const
get the tower iphi
EcalEBPhase2SpikeTagger * getSpikeTagger() const
const EcalEBPhase2TPGAmplWeightIdMap * ecaltpgAmplWeightMap_
EcalEBPhase2TPFormatter * getTPFormatter() const
void fillMap(EBDigiCollectionPh2 const *col, std::vector< std::vector< std::pair< int, std::vector< EBDataFrame_Ph2 > > > > &towerMap)
#define LogDebug(id)