CMS 3D CMS Logo

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