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  const edm::EventSetup &setup, int binofmax, bool tcpFormat, bool barrelOnly, bool debug, bool famos);
51 
53 
54  void run(const edm::EventSetup &,
55  const EBDigiCollection *col,
57  EcalTrigPrimDigiCollection &resultTcp);
58  void run(const edm::EventSetup &,
59  const EEDigiCollection *col,
61  EcalTrigPrimDigiCollection &resultTcp);
62  void run_part1_EB(EBDigiCollection const *col);
63  void run_part1_EE(EEDigiCollection const *col);
64  template <class Coll>
65  void run_part2(const edm::EventSetup &,
66  Coll const *col,
67  std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi>>>> &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,
80  ecaltpLin,
81  ecaltpgWeightMap,
82  ecaltpgWeightGroup,
83  ecaltpgSlidW,
84  ecaltpgFgStripEE,
85  ecaltpgBadX,
86  ecaltpgStripStatus);
87  }
88  void setPointers2(const EcalTPGFineGrainEBGroup *ecaltpgFgEBGroup,
89  const EcalTPGLutGroup *ecaltpgLutGroup,
90  const EcalTPGLutIdMap *ecaltpgLut,
91  const EcalTPGFineGrainEBIdMap *ecaltpgFineGrainEB,
92  const EcalTPGFineGrainTowerEE *ecaltpgFineGrainTowerEE,
93  const EcalTPGTowerStatus *ecaltpgBadTT,
94  const EcalTPGSpike *ecaltpgSpike) {
95  etcp_->setPointers(ecaltpgFgEBGroup,
96  ecaltpgLutGroup,
97  ecaltpgLut,
98  ecaltpgFineGrainEB,
99  ecaltpgFineGrainTowerEE,
100  ecaltpgBadTT,
101  ecaltpgSpike);
102  }
103 
104 private:
105  void init(const edm::EventSetup &);
106  template <class T>
107  void initStructures(std::vector<std::vector<std::pair<int, std::vector<T>>>> &towMap);
108  template <class T>
109  void clean(std::vector<std::vector<std::pair<int, std::vector<T>>>> &towerMap);
110  template <class Coll>
111  void fillMap(Coll const *col, std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi>>>> &towerMap);
112  int findStripNr(const EBDetId &id);
113  int findStripNr(const EEDetId &id);
114 
115  // FIXME: temporary until hashedIndex works alsom for endcap
116  int getIndex(const EBDigiCollection *, EcalTrigTowerDetId &id) { return id.hashedIndex(); }
117  // mind that eta is continuous between barrel+endcap
119  int ind = (id.ietaAbs() - 18) * 72 + id.iphi();
120  if (id.zside() < 0)
121  ind += 792;
122  return ind;
123  }
124 
127 
131 
132  float threshold;
133 
136 
139  bool debug_;
140  bool famos_;
141 
142  static const unsigned int 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 maxNrSamplesOut_; // to be placed in the intermediate samples
145  static const unsigned int maxNrTowers_; // would be better to get from somewhere..
146  static const unsigned int maxNrTPs_; // would be better to get from
147  // somewhere..
148 
149  int nrTowers_; // nr of towers found by fillmap method
150 
151  // data structures kept during the whole run
152  std::vector<std::vector<int>> striptp_;
153  std::vector<std::vector<std::pair<int, std::vector<EBDataFrame>>>> towerMapEB_;
154  std::vector<std::vector<std::pair<int, std::vector<EEDataFrame>>>> towerMapEE_;
155  std::vector<std::pair<int, EcalTrigTowerDetId>> hitTowers_;
156  std::vector<EcalTriggerPrimitiveSample> towtp_;
157  std::vector<EcalTriggerPrimitiveSample> towtp2_;
158 
159  enum { nbMaxStrips_ = 5 };
160  enum { nbMaxXtals_ = 5 };
161 };
162 
163 //=================================== implementations
164 //=============================================
165 
166 template <class Coll>
168  const edm::EventSetup &setup,
169  Coll const *col,
170  std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi>>>> &towerMap,
172  EcalTrigPrimDigiCollection &resultTcp) {
173  typedef typename Coll::Digi Digi;
174 
175  // prepare writing of TP-s
176 
177  int firstSample = binOfMaximum_ - 1 - nrSamples_ / 2;
178  int lastSample = binOfMaximum_ - 1 + nrSamples_ / 2;
179  int nrTP = 0;
180  std::vector<typename Coll::Digi> dummy;
181  EcalTriggerPrimitiveDigi tptow[2];
182  EcalTriggerPrimitiveDigi tptowTcp[2];
183 
185 
186  for (int itow = 0; itow < nrTowers_; ++itow) {
187  int index = hitTowers_[itow].first;
188  const EcalTrigTowerDetId &thisTower = hitTowers_[itow].second;
189 
190  // loop over all strips assigned to this trigger tower
191  int nstr = 0;
192  for (unsigned int i = 0; i < towerMap[itow].size(); ++i) {
193  std::vector<Digi> &df = (towerMap[index])[i].second; // vector of dataframes for this strip,
194  // size; nr of crystals/strip
195 
196  if ((towerMap[index])[i].first > 0) {
197  estrip_->process(setup, df, (towerMap[index])[i].first, striptp_[nstr++]);
198  }
199  } // loop over strips in one tower
200 
201  bool isInInnerRings = false;
202  if (thisTower.subDet() == EcalEndcap && (thisTower.ietaAbs() == 27 || thisTower.ietaAbs() == 28))
203  isInInnerRings = true;
204  etcp_->process(setup, dummy, striptp_, nstr, towtp_, towtp2_, isInInnerRings, thisTower);
205 
206  // prepare TP-s
207  // special treatment for 2 inner endcap rings
208  int nrTowers;
209  if (isInInnerRings) {
210  nrTowers = 2;
211  int phi = 2 * ((thisTower.iphi() - 1) / 2);
212  tptow[0] = EcalTriggerPrimitiveDigi(
213  EcalTrigTowerDetId(thisTower.zside(), thisTower.subDet(), thisTower.ietaAbs(), phi + 1));
214  tptow[1] = EcalTriggerPrimitiveDigi(
215  EcalTrigTowerDetId(thisTower.zside(), thisTower.subDet(), thisTower.ietaAbs(), phi + 2));
216 
217  if (tcpFormat_) {
218  tptowTcp[0] = EcalTriggerPrimitiveDigi(
219  EcalTrigTowerDetId(thisTower.zside(), thisTower.subDet(), thisTower.ietaAbs(), phi + 1));
220  tptowTcp[1] = EcalTriggerPrimitiveDigi(
221  EcalTrigTowerDetId(thisTower.zside(), thisTower.subDet(), thisTower.ietaAbs(), phi + 2));
222  }
223  } else {
224  nrTowers = 1;
225  tptow[0] = EcalTriggerPrimitiveDigi(thisTower);
226  if (tcpFormat_)
227  tptowTcp[0] = EcalTriggerPrimitiveDigi(thisTower);
228  }
229 
230  // now fill in
231  for (int nrt = 0; nrt < nrTowers; nrt++) {
232  (tptow[nrt]).setSize(nrSamples_);
233  if (towtp_.size() < nrSamples_) { // FIXME: only once
234  edm::LogWarning("") << "Too few samples produced, nr is " << towtp_.size();
235  break;
236  }
237  int isam = 0;
238  for (int i = firstSample; i <= lastSample; ++i) {
239  tptow[nrt].setSample(isam++, EcalTriggerPrimitiveSample(towtp_[i]));
240  }
241  nrTP++;
242  LogDebug("EcalTPG") << " For tower " << itow << " created TP nr " << nrTP << " with Et "
243  << tptow[nrt].compressedEt();
244  result.push_back(tptow[nrt]);
245  }
246 
247  if (tcpFormat_) {
248  for (int nrt = 0; nrt < nrTowers; nrt++) {
249  tptowTcp[nrt].setSize(nrSamples_);
250  if (towtp2_.size() < nrSamples_) { // FIXME: only once
251  edm::LogWarning("") << "Too few samples produced, nr is " << towtp2_.size();
252  break;
253  }
254  int isam = 0;
255  for (int i = firstSample; i <= lastSample; ++i) {
256  if (nrTowers <= 1)
257  tptowTcp[nrt].setSample(isam++, EcalTriggerPrimitiveSample(towtp2_[i]));
258  else {
259  int et = towtp2_[i].compressedEt() / 2;
260  tptowTcp[nrt].setSample(isam++,
261  EcalTriggerPrimitiveSample(et, towtp2_[i].fineGrain(), towtp2_[i].ttFlag()));
262  }
263  }
264  resultTcp.push_back(tptowTcp[nrt]);
265  }
266  }
267  }
268  return;
269 }
270 
271 template <class Coll>
273  Coll const *col, std::vector<std::vector<std::pair<int, std::vector<typename Coll::Digi>>>> &towerMap) {
274  typedef typename Coll::Digi Digi;
275 
276  // implementation for Barrel and Endcap
277 
278  if (col) {
279  nrTowers_ = 0;
280  LogDebug("EcalTPG") << "Fill mapping, Collection size = " << col->size();
281  for (unsigned int i = 0; i < col->size(); ++i) {
282  Digi samples((*col)[i]);
283  EcalTrigTowerDetId coarser = (*eTTmap_).towerOf(samples.id());
284  int index = getIndex(col, coarser);
285  int stripnr = findStripNr(samples.id());
286 
287  int filled = 0;
288  for (unsigned int ij = 0; ij < towerMap[index].size(); ++ij)
289  filled += towerMap[index][ij].first;
290  if (!filled) {
291  hitTowers_[nrTowers_++] = std::pair<int, EcalTrigTowerDetId>(index, coarser);
292  }
293 
294  // FIXME: temporary protection
295  int ncryst = towerMap[index][stripnr - 1].first;
296  if (ncryst >= nbMaxXtals_) {
297  edm::LogError("EcalTrigPrimFunctionAlgo")
298  << "! Too many xtals for TT " << coarser << " stripnr " << stripnr << " xtalid " << samples.id();
299  continue;
300  }
301  ((towerMap[index])[stripnr - 1].second)[ncryst] = samples;
302  (towerMap[index])[stripnr - 1].first++;
303  }
304 
305  LogDebug("EcalTPG") << "fillMap"
306  << "[EcalTrigPrimFunctionalAlgo] (found " << col->size() << " frames in " << towerMap.size()
307  << " towers) ";
308  } else {
309  LogDebug("EcalTPG") << "FillMap - FillMap Collection size=0 !!!!";
310  }
311 }
312 
313 template <class T>
314 void EcalTrigPrimFunctionalAlgo::clean(std::vector<std::vector<std::pair<int, std::vector<T>>>> &towMap) {
315  // clean internal data structures
316  for (unsigned int i = 0; i < maxNrTowers_; ++i)
317  for (int j = 0; j < nbMaxStrips_; ++j)
318  (towMap[i])[j].first = 0;
319  return;
320 }
321 
322 template <class T>
323 void EcalTrigPrimFunctionalAlgo::initStructures(std::vector<std::vector<std::pair<int, std::vector<T>>>> &towMap) {
324  // initialise internal data structures
325 
326  std::vector<T> vec0(nbMaxXtals_);
327  std::vector<std::pair<int, std::vector<T>>> vec1(nbMaxStrips_);
328  for (int i = 0; i < nbMaxStrips_; ++i)
329  vec1[i] = std::pair<int, std::vector<T>>(0, vec0);
330  towMap.resize(maxNrTowers_);
331  for (unsigned int i = 0; i < maxNrTowers_; ++i)
332  towMap[i] = vec1;
333 
334  std::vector<int> vecint(maxNrSamples_);
335  striptp_.resize(nbMaxStrips_);
336  for (int i = 0; i < nbMaxStrips_; ++i)
337  striptp_[i] = vecint;
338 }
339 
340 #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:54
void push_back(T const &t)
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:57
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)
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)