CMS 3D CMS Logo

EcalTrigPrimFunctionalAlgo.h
Go to the documentation of this file.
1 #ifndef SIMCALORIMETRY_ECALTRIGPRIMALGOS_ECALTRIGPRIMFUNCTIONALALGO_h
2 #define SIMCALORIMETRY_ECALTRIGPRIMALGOS_ECALTRIGPRIMFUNCTIONALALGO_h
3 
18 #include <iostream>
19 #include <sys/time.h>
20 #include <vector>
21 
23 
26 
29 
31 
32 #include <map>
33 #include <utility>
34 #include <string>
35 
38 class EcalTrigTowerDetId;
39 class ETPCoherenceTest;
42 class EBDataFrame;
43 class EEDataFrame;
45 
47 public:
48  //Not barrelOnly
50  const CaloSubdetectorGeometry *endcapGeometry,
51  const EcalElectronicsMapping *theMapping,
52  int binofmax,
53  bool tcpFormat,
54  bool debug,
55  bool famos,
56  bool TPinfoPrintout);
57 
58  //barrel only
59  explicit EcalTrigPrimFunctionalAlgo(const EcalElectronicsMapping *theMapping,
60  int binofmax,
61  bool tcpFormat,
62  bool debug,
63  bool famos,
64  bool TPinfoPrintout);
65 
67 
70  void run_part1_EB(EBDigiCollection const *col);
71  void run_part1_EE(EEDigiCollection const *col);
72  template <class Coll>
73  void run_part2(Coll const *col,
74  std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi>>>> &towerMap,
76  EcalTrigPrimDigiCollection &resultTcp);
77 
78  void setPointers(const EcalTPGLinearizationConst *ecaltpLin,
79  const EcalTPGPedestals *ecaltpPed,
80  const EcalTPGSlidingWindow *ecaltpgSlidW,
81  const EcalTPGWeightIdMap *ecaltpgWeightMap,
82  const EcalTPGWeightGroup *ecaltpgWeightGroup,
83  const EcalTPGOddWeightIdMap *ecaltpgOddWeightMap,
84  const EcalTPGOddWeightGroup *ecaltpgOddWeightGroup,
85  const EcalTPGFineGrainStripEE *ecaltpgFgStripEE,
86  const EcalTPGCrystalStatus *ecaltpgBadX,
87  const EcalTPGStripStatus *ecaltpgStripStatus,
88  const EcalTPGTPMode *ecaltpgTPMode) {
89  estrip_->setPointers(ecaltpPed,
90  ecaltpLin,
91  ecaltpgWeightMap,
92  ecaltpgWeightGroup,
93  ecaltpgOddWeightMap,
94  ecaltpgOddWeightGroup,
95  ecaltpgSlidW,
96  ecaltpgFgStripEE,
97  ecaltpgBadX,
98  ecaltpgStripStatus,
99  ecaltpgTPMode);
100  }
101  void setPointers2(const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup,
102  const EcalTPGLutGroup *ecaltpgLutGroup,
103  const EcalTPGLutIdMap *ecaltpgLut,
104  const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB,
105  const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE,
106  const EcalTPGTowerStatus *ecaltpgBadTT,
107  const EcalTPGSpike *ecaltpgSpike,
108  const EcalTPGTPMode *ecaltpgTPMode) {
109  etcp_->setPointers(ecaltpgFgEBGroup,
110  ecaltpgLutGroup,
111  ecaltpgLut,
112  ecaltpgFineGrainEB,
113  ecaltpgFineGrainTowerEE,
114  ecaltpgBadTT,
115  ecaltpgSpike,
116  ecaltpgTPMode);
117  }
118 
119 private:
120  void init();
121  template <class T>
122  void initStructures(std::vector<std::vector<std::pair<int, std::vector<T>>>> &towMap);
123  template <class T>
124  void clean(std::vector<std::vector<std::pair<int, std::vector<T>>>> &towerMap);
125  template <class Coll>
126  void fillMap(Coll const *col, std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi>>>> &towerMap);
127  int findStripNr(const EBDetId &id);
128  int findStripNr(const EEDetId &id);
129 
130  // FIXME: temporary until hashedIndex works alsom for endcap
131  int getIndex(const EBDigiCollection *, EcalTrigTowerDetId &id) { return id.hashedIndex(); }
132  // mind that eta is continuous between barrel+endcap
134  int ind = (id.ietaAbs() - 18) * 72 + id.iphi();
135  if (id.zside() < 0)
136  ind += 792;
137  return ind;
138  }
139 
140  std::unique_ptr<EcalFenixStrip> estrip_;
141  std::unique_ptr<EcalFenixTcp> etcp_;
142 
146 
147  float threshold;
148 
151 
154  bool debug_;
155  bool famos_;
157 
158  static const unsigned int nrSamples_; // nr samples to write, should not be changed since by
159  // convention the size means that it is coming from simulation
160  static const unsigned int maxNrSamplesOut_; // to be placed in the intermediate samples
161  static const unsigned int maxNrTowers_; // would be better to get from somewhere..
162  static const unsigned int maxNrTPs_; // would be better to get from
163  // somewhere..
164 
165  int nrTowers_; // nr of towers found by fillmap method
166 
167  // data structures kept during the whole run
168  std::vector<std::vector<int>> striptp_;
169  std::vector<std::vector<std::pair<int, std::vector<EBDataFrame>>>> towerMapEB_;
170  std::vector<std::vector<std::pair<int, std::vector<EEDataFrame>>>> towerMapEE_;
171  std::vector<std::pair<int, EcalTrigTowerDetId>> hitTowers_;
172  std::vector<EcalTriggerPrimitiveSample> towtp_;
173  std::vector<EcalTriggerPrimitiveSample> towtp2_;
174 
175  enum { nbMaxStrips_ = 5 };
176  enum { nbMaxXtals_ = 5 };
177 };
178 
179 //=================================== implementations
180 //=============================================
181 
182 template <class Coll>
184  Coll const *col,
185  std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi>>>> &towerMap,
187  EcalTrigPrimDigiCollection &resultTcp) {
188  typedef typename Coll::Digi Digi;
189 
190  // prepare writing of TP-s
191 
192  int firstSample = binOfMaximum_ - 1 - nrSamples_ / 2;
193  int lastSample = binOfMaximum_ - 1 + nrSamples_ / 2;
194  int nrTP = 0;
195  std::vector<typename Coll::Digi> dummy;
196  EcalTriggerPrimitiveDigi tptow[2];
197  EcalTriggerPrimitiveDigi tptowTcp[2];
198 
199  estrip_->getFGVB()->setbadStripMissing(false);
200 
201  for (int itow = 0; itow < nrTowers_; ++itow) {
202  int index = hitTowers_[itow].first;
203  const EcalTrigTowerDetId &thisTower = hitTowers_[itow].second;
204 
205  if (tpInfoPrintout_) {
206  edm::LogVerbatim("EcalTPG") << "+++++++++++++++++++++++++++++++++++++++++++++++++";
207  edm::LogVerbatim("EcalTPG") << "on Tower " << itow << " of " << nrTowers_;
208  edm::LogVerbatim("EcalTPG") << "Tower ieta, iphi: " << thisTower.ieta() << ", " << thisTower.iphi();
209  }
210 
211  // loop over all strips assigned to this trigger tower
212  int nstr = 0;
213  for (unsigned int i = 0; i < towerMap[itow].size(); ++i) {
214  std::vector<Digi> &df = (towerMap[index])[i].second; // vector of dataframes for this strip,
215  // size; nr of crystals/strip
216 
217  if ((towerMap[index])[i].first > 0) {
218  if (tpInfoPrintout_) {
219  edm::LogVerbatim("EcalTPG") << "-------------------------------------------------";
220  edm::LogVerbatim("EcalTPG") << "on Strip index " << i;
221  }
222  estrip_->process(df, (towerMap[index])[i].first, striptp_[nstr++]);
223  }
224  } // loop over strips in one tower
225 
226  bool isInInnerRings = false;
227  if (thisTower.subDet() == EcalEndcap && (thisTower.ietaAbs() == 27 || thisTower.ietaAbs() == 28))
228  isInInnerRings = true;
229  etcp_->process(dummy, striptp_, nstr, towtp_, towtp2_, isInInnerRings, thisTower);
230 
231  // prepare TP-s
232  // special treatment for 2 inner endcap rings
233  int nrTowers;
234  if (isInInnerRings) {
235  nrTowers = 2;
236  int phi = 2 * ((thisTower.iphi() - 1) / 2);
237  tptow[0] = EcalTriggerPrimitiveDigi(
238  EcalTrigTowerDetId(thisTower.zside(), thisTower.subDet(), thisTower.ietaAbs(), phi + 1));
239  tptow[1] = EcalTriggerPrimitiveDigi(
240  EcalTrigTowerDetId(thisTower.zside(), thisTower.subDet(), thisTower.ietaAbs(), phi + 2));
241 
242  if (tcpFormat_) {
243  tptowTcp[0] = EcalTriggerPrimitiveDigi(
244  EcalTrigTowerDetId(thisTower.zside(), thisTower.subDet(), thisTower.ietaAbs(), phi + 1));
245  tptowTcp[1] = EcalTriggerPrimitiveDigi(
246  EcalTrigTowerDetId(thisTower.zside(), thisTower.subDet(), thisTower.ietaAbs(), phi + 2));
247  }
248  } else {
249  nrTowers = 1;
250  tptow[0] = EcalTriggerPrimitiveDigi(thisTower);
251  if (tcpFormat_)
252  tptowTcp[0] = EcalTriggerPrimitiveDigi(thisTower);
253  }
254 
255  // now fill in
256  for (int nrt = 0; nrt < nrTowers; nrt++) {
257  (tptow[nrt]).setSize(nrSamples_);
258  if (towtp_.size() < nrSamples_) { // FIXME: only once
259  edm::LogWarning("") << "Too few samples produced, nr is " << towtp_.size();
260  break;
261  }
262  int isam = 0;
263  for (int i = firstSample; i <= lastSample; ++i) {
264  tptow[nrt].setSample(isam++, EcalTriggerPrimitiveSample(towtp_[i]));
265  }
266  nrTP++;
267  LogDebug("EcalTPG") << " For tower " << itow << " created TP nr " << nrTP << " with Et "
268  << tptow[nrt].compressedEt();
269  result.push_back(tptow[nrt]);
270  }
271 
272  if (tcpFormat_) {
273  for (int nrt = 0; nrt < nrTowers; nrt++) {
274  tptowTcp[nrt].setSize(nrSamples_);
275  if (towtp2_.size() < nrSamples_) { // FIXME: only once
276  edm::LogWarning("") << "Too few samples produced, nr is " << towtp2_.size();
277  break;
278  }
279  int isam = 0;
280  for (int i = firstSample; i <= lastSample; ++i) {
281  if (nrTowers <= 1)
282  tptowTcp[nrt].setSample(isam++, EcalTriggerPrimitiveSample(towtp2_[i]));
283  else {
284  int et = towtp2_[i].compressedEt() / 2;
285  tptowTcp[nrt].setSample(isam++,
286  EcalTriggerPrimitiveSample(et, towtp2_[i].fineGrain(), towtp2_[i].ttFlag()));
287  }
288  }
289  resultTcp.push_back(tptowTcp[nrt]);
290  }
291  }
292  }
293  return;
294 }
295 
296 template <class Coll>
298  Coll const *col, std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi>>>> &towerMap) {
299  typedef typename Coll::Digi Digi;
300 
301  // implementation for Barrel and Endcap
302 
303  if (col) {
304  nrTowers_ = 0;
305  LogDebug("EcalTPG") << "Fill mapping, Collection size = " << col->size();
306  for (unsigned int i = 0; i < col->size(); ++i) {
307  Digi samples((*col)[i]);
308  EcalTrigTowerDetId coarser = (*eTTmap_).towerOf(samples.id());
309  int index = getIndex(col, coarser);
310  int stripnr = findStripNr(samples.id());
311 
312  int filled = 0;
313  for (unsigned int ij = 0; ij < towerMap[index].size(); ++ij)
314  filled += towerMap[index][ij].first;
315  if (!filled) {
316  hitTowers_[nrTowers_++] = std::pair<int, EcalTrigTowerDetId>(index, coarser);
317  }
318 
319  // FIXME: temporary protection
320  int ncryst = towerMap[index][stripnr - 1].first;
321  if (ncryst >= nbMaxXtals_) {
322  edm::LogError("EcalTrigPrimFunctionAlgo")
323  << "! Too many xtals for TT " << coarser << " stripnr " << stripnr << " xtalid " << samples.id();
324  continue;
325  }
326  ((towerMap[index])[stripnr - 1].second)[ncryst] = samples;
327  (towerMap[index])[stripnr - 1].first++;
328  }
329 
330  LogDebug("EcalTPG") << "fillMap"
331  << "[EcalTrigPrimFunctionalAlgo] (found " << col->size() << " frames in " << towerMap.size()
332  << " towers) ";
333  } else {
334  LogDebug("EcalTPG") << "FillMap - FillMap Collection size=0 !!!!";
335  }
336 }
337 
338 template <class T>
339 void EcalTrigPrimFunctionalAlgo::clean(std::vector<std::vector<std::pair<int, std::vector<T>>>> &towMap) {
340  // clean internal data structures
341  for (unsigned int i = 0; i < maxNrTowers_; ++i)
342  for (int j = 0; j < nbMaxStrips_; ++j)
343  (towMap[i])[j].first = 0;
344  return;
345 }
346 
347 template <class T>
348 void EcalTrigPrimFunctionalAlgo::initStructures(std::vector<std::vector<std::pair<int, std::vector<T>>>> &towMap) {
349  // initialise internal data structures
350 
351  std::vector<T> vec0(nbMaxXtals_);
352  std::vector<std::pair<int, std::vector<T>>> vec1(nbMaxStrips_);
353  for (int i = 0; i < nbMaxStrips_; ++i)
354  vec1[i] = std::pair<int, std::vector<T>>(0, vec0);
355  towMap.resize(maxNrTowers_);
356  for (unsigned int i = 0; i < maxNrTowers_; ++i)
357  towMap[i] = vec1;
358 
359  std::vector<int> vecint(maxNrSamples_);
360  striptp_.resize(nbMaxStrips_);
361  for (int i = 0; i < nbMaxStrips_; ++i)
362  striptp_[i] = vecint;
363 }
364 
365 #endif
Log< level::Info, true > LogVerbatim
const EcalElectronicsMapping * theMapping_
void setPointers2(const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup, const EcalTPGLutGroup *ecaltpgLutGroup, const EcalTPGLutIdMap *ecaltpgLut, const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB, const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE, const EcalTPGTowerStatus *ecaltpgBadTT, const EcalTPGSpike *ecaltpgSpike, const EcalTPGTPMode *ecaltpgTPMode)
int ieta() const
get the tower ieta
EcalTrigPrimFunctionalAlgo(const EcalTrigTowerConstituentsMap *eTTmap, const CaloSubdetectorGeometry *endcapGeometry, const EcalElectronicsMapping *theMapping, int binofmax, bool tcpFormat, bool debug, bool famos, bool TPinfoPrintout)
std::vector< std::vector< int > > striptp_
EcalSubdetector subDet() const
get the subDetector associated to the Trigger Tower
void fillMap(Coll const *col, std::vector< std::vector< std::pair< int, std::vector< typename Coll::Digi >>>> &towerMap)
std::unique_ptr< EcalFenixTcp > etcp_
const CaloSubdetectorGeometry * theEndcapGeometry_
void push_back(T const &t)
void run_part2(Coll const *col, std::vector< std::vector< std::pair< int, std::vector< typename Coll::Digi >>>> &towerMap, EcalTrigPrimDigiCollection &result, EcalTrigPrimDigiCollection &resultTcp)
std::vector< std::pair< int, EcalTrigTowerDetId > > hitTowers_
static const unsigned int maxNrSamplesOut_
int zside(DetId const &)
Log< level::Error, false > LogError
std::vector< EcalTriggerPrimitiveSample > towtp_
U second(std::pair< T, U > const &p)
static const unsigned int maxNrTowers_
void initStructures(std::vector< std::vector< std::pair< int, std::vector< T >>>> &towMap)
int zside() const
get the z-side of the tower (1/-1)
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
std::vector< double > vec1
Definition: HCALResponse.h:15
std::vector< std::vector< std::pair< int, std::vector< EBDataFrame > > > > towerMapEB_
void setPointers(const EcalTPGLinearizationConst *ecaltpLin, const EcalTPGPedestals *ecaltpPed, const EcalTPGSlidingWindow *ecaltpgSlidW, const EcalTPGWeightIdMap *ecaltpgWeightMap, const EcalTPGWeightGroup *ecaltpgWeightGroup, const EcalTPGOddWeightIdMap *ecaltpgOddWeightMap, const EcalTPGOddWeightGroup *ecaltpgOddWeightGroup, const EcalTPGFineGrainStripEE *ecaltpgFgStripEE, const EcalTPGCrystalStatus *ecaltpgBadX, const EcalTPGStripStatus *ecaltpgStripStatus, const EcalTPGTPMode *ecaltpgTPMode)
void clean(std::vector< std::vector< std::pair< int, std::vector< T >>>> &towerMap)
int getIndex(const EBDigiCollection *, EcalTrigTowerDetId &id)
int getIndex(const EEDigiCollection *, EcalTrigTowerDetId &id)
int compressedEt() const
get the encoded/compressed Et of interesting sample
int ietaAbs() const
get the absolute value of the tower ieta
#define debug
Definition: HDRShower.cc:19
static const unsigned int maxNrTPs_
std::vector< std::vector< std::pair< int, std::vector< EEDataFrame > > > > towerMapEE_
std::unique_ptr< EcalFenixStrip > estrip_
std::vector< EcalTriggerPrimitiveSample > towtp2_
void run_part1_EB(EBDigiCollection const *col)
col
Definition: cuy.py:1009
const EcalTrigTowerConstituentsMap * eTTmap_
Log< level::Warning, false > LogWarning
static const unsigned int nrSamples_
void run_part1_EE(EEDigiCollection const *col)
int iphi() const
get the tower iphi
void run(const EBDigiCollection *col, EcalTrigPrimDigiCollection &result, EcalTrigPrimDigiCollection &resultTcp)
#define LogDebug(id)