CMS 3D CMS Logo

EcalTrigPrimFunctionalAlgo.h
Go to the documentation of this file.
1 #ifndef EcalTrigPrimFunctionalAlgo_h
2 #define EcalTrigPrimFunctionalAlgo_h
3 
18 #include <sys/time.h>
19 #include <iostream>
20 #include <vector>
21 
23 
26 
29 
33 
34 #include <map>
35 #include <utility>
36 
40 class EcalTrigTowerDetId;
41 class ETPCoherenceTest;
44 class EBDataFrame;
45 class EEDataFrame;
47 
48 
50 {
51  public:
52 
53  explicit EcalTrigPrimFunctionalAlgo(const edm::EventSetup & setup, int binofmax, bool tcpFormat, bool barrelOnly, bool debug, bool famos);
54 
56 
58  void run(const edm::EventSetup&, const EEDigiCollection *col, EcalTrigPrimDigiCollection & result, EcalTrigPrimDigiCollection & resultTcp);
59  void run_part1_EB(EBDigiCollection const * col);
60  void run_part1_EE(EEDigiCollection const * col);
61  template <class Coll>
62  void run_part2(const edm::EventSetup &, Coll const * col,
63  std::vector<std::vector<std::pair<int,std::vector<typename Coll::Digi> > > > &towerMap,
65  EcalTrigPrimDigiCollection & resultTcp);
66 
67  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) {
68  estrip_->setPointers(ecaltpPed,ecaltpLin,ecaltpgWeightMap,ecaltpgWeightGroup,ecaltpgSlidW,ecaltpgFgStripEE,ecaltpgBadX,ecaltpgStripStatus);
69 
70  }
71  void setPointers2( const EcalTPGFineGrainEBGroup * ecaltpgFgEBGroup,
72  const EcalTPGLutGroup * ecaltpgLutGroup,
73  const EcalTPGLutIdMap * ecaltpgLut,
74  const EcalTPGFineGrainEBIdMap * ecaltpgFineGrainEB,
75  const EcalTPGFineGrainTowerEE * ecaltpgFineGrainTowerEE,
76  const EcalTPGTowerStatus * ecaltpgBadTT,
77  const EcalTPGSpike * ecaltpgSpike){
78 
79  etcp_->setPointers(ecaltpgFgEBGroup,ecaltpgLutGroup,ecaltpgLut,ecaltpgFineGrainEB,ecaltpgFineGrainTowerEE,ecaltpgBadTT,ecaltpgSpike);
80  }
81 
82  private:
83 
84  void init(const edm::EventSetup&);
85  template <class T>
86  void initStructures(std::vector<std::vector<std::pair<int,std::vector<T> > > > & towMap);
87  template <class T>
88  void clean(std::vector<std::vector<std::pair<int,std::vector<T> > > > &towerMap);
89  template <class Coll>
90  void fillMap(Coll const * col, std::vector<std::vector<std::pair<int,std::vector<typename Coll::Digi> > > > &towerMap);
91  int findStripNr(const EBDetId &id);
92  int findStripNr(const EEDetId &id);
93 
94  // FIXME: temporary until hashedIndex works alsom for endcap
95  int getIndex(const EBDigiCollection *, EcalTrigTowerDetId& id) {return id.hashedIndex();}
96  // mind that eta is continuous between barrel+endcap
98  int ind=(id.ietaAbs()-18)*72 + id.iphi();
99  if (id.zside()<0) ind+=792;
100  return ind;
101  }
102 
105 
109 
110  float threshold;
111 
114 
117  bool debug_;
118  bool famos_;
119 
120  static const unsigned int nrSamples_; //nr samples to write, should not be changed since by convention the size means that it is coming from simulation
121  static const unsigned int maxNrSamplesOut_; //to be placed in the intermediate samples
122  static const unsigned int maxNrTowers_; //would be better to get from somewhere..
123  static const unsigned int maxNrTPs_; //would be better to get from somewhere..
124 
125  int nrTowers_; // nr of towers found by fillmap method
126 
127  // data structures kept during the whole run
128  std::vector<std::vector<int> > striptp_;
129  std::vector<std::vector<std::pair<int,std::vector<EBDataFrame> > > > towerMapEB_;
130  std::vector<std::vector<std::pair<int,std::vector<EEDataFrame> > > > towerMapEE_;
131  std::vector<std::pair<int,EcalTrigTowerDetId> > hitTowers_;
132  std::vector<EcalTriggerPrimitiveSample> towtp_;
133  std::vector<EcalTriggerPrimitiveSample> towtp2_;
134 
135  enum {nbMaxStrips_=5};
136  enum {nbMaxXtals_=5};
137 };
138 
139 //=================================== implementations =============================================
140 
141 template <class Coll>
142 void EcalTrigPrimFunctionalAlgo::run_part2(const edm::EventSetup &setup,Coll const * col, std::vector<std::vector<std::pair<int,std::vector<typename Coll::Digi> > > > &towerMap,
144  EcalTrigPrimDigiCollection & resultTcp)
145 {
146  typedef typename Coll::Digi Digi;
147 
148  // prepare writing of TP-s
149 
151  int lastSample = binOfMaximum_-1 +nrSamples_/2;
152  int nrTP=0;
153  std::vector<typename Coll::Digi> dummy;
154  EcalTriggerPrimitiveDigi tptow[2];
155  EcalTriggerPrimitiveDigi tptowTcp[2];
156 
158 
159  for(int itow=0;itow<nrTowers_;++itow)
160  {
161 
162  int index=hitTowers_[itow].first;
163  const EcalTrigTowerDetId &thisTower=hitTowers_[itow].second;
164 
165  // loop over all strips assigned to this trigger tower
166  int nstr=0;
167  for(unsigned int i = 0; i < towerMap[itow].size();++i)
168  {
169  std::vector<Digi> &df = (towerMap[index])[i].second;//vector of dataframes for this strip, size; nr of crystals/strip
170 
171  if ((towerMap[index])[i].first > 0) {
172  estrip_->process(setup,df,(towerMap[index])[i].first,striptp_[nstr++]);
173  }
174  }//loop over strips in one tower
175 
176  bool isInInnerRings=false;
177  if (thisTower.subDet()==EcalEndcap && (thisTower.ietaAbs()==27 || thisTower.ietaAbs()==28 )) isInInnerRings=true;
178  etcp_->process(setup,dummy,striptp_,nstr,towtp_,towtp2_,isInInnerRings,thisTower);
179 
180  // prepare TP-s
181  // special treatment for 2 inner endcap rings
182  int nrTowers;
183  if (isInInnerRings)
184  {
185  nrTowers=2;
186  int phi=2*((thisTower.iphi()-1)/2);
187  tptow[0]=EcalTriggerPrimitiveDigi(EcalTrigTowerDetId(thisTower.zside(),thisTower.subDet(),thisTower.ietaAbs(),phi+1));
188  tptow[1]=EcalTriggerPrimitiveDigi(EcalTrigTowerDetId(thisTower.zside(),thisTower.subDet(),thisTower.ietaAbs(),phi+2));
189 
190  if (tcpFormat_){
191  tptowTcp[0]=EcalTriggerPrimitiveDigi(EcalTrigTowerDetId(thisTower.zside(),thisTower.subDet(),thisTower.ietaAbs(),phi+1));
192  tptowTcp[1]=EcalTriggerPrimitiveDigi(EcalTrigTowerDetId(thisTower.zside(),thisTower.subDet(),thisTower.ietaAbs(),phi+2));
193  }
194  }else {
195  nrTowers=1;
196  tptow[0]=EcalTriggerPrimitiveDigi(thisTower);
197  if (tcpFormat_) tptowTcp[0]=EcalTriggerPrimitiveDigi(thisTower);
198  }
199 
200  // now fill in
201  for (int nrt=0;nrt<nrTowers;nrt++) {
202  (tptow[nrt]).setSize(nrSamples_);
203  if (towtp_.size()<nrSamples_) { //FIXME: only once
204  edm::LogWarning("") <<"Too few samples produced, nr is "<<towtp_.size();
205  break;
206  }
207  int isam=0;
208  for (int i=firstSample;i<=lastSample;++i) {
209  tptow[nrt].setSample(isam++,EcalTriggerPrimitiveSample(towtp_[i]));
210  }
211  nrTP++;
212  LogDebug("EcalTPG") <<" For tower "<<itow<<" created TP nr "<<nrTP<<" with Et "<<tptow[nrt].compressedEt();
213  result.push_back(tptow[nrt]);
214  }
215 
216  if (tcpFormat_) {
217 
218  for (int nrt=0;nrt<nrTowers;nrt++) {
219  tptowTcp[nrt].setSize(nrSamples_);
220  if (towtp2_.size()<nrSamples_) { //FIXME: only once
221  edm::LogWarning("") <<"Too few samples produced, nr is "<<towtp2_.size();
222  break;
223  }
224  int isam=0;
225  for (int i=firstSample;i<=lastSample;++i) {
226  if (nrTowers<=1) tptowTcp[nrt].setSample(isam++,EcalTriggerPrimitiveSample(towtp2_[i]));
227  else {
228  int et=towtp2_[i].compressedEt()/2;
229  tptowTcp[nrt].setSample(isam++,EcalTriggerPrimitiveSample(et,towtp2_[i].fineGrain(),towtp2_[i].ttFlag()));
230  }
231  }
232  resultTcp.push_back(tptowTcp[nrt]);
233  }
234  }
235  }
236  return;
237 }
238 
239 template <class Coll>
241  std::vector<std::vector<std::pair<int,std::vector<typename Coll::Digi> > > > &towerMap)
242 {
243  typedef typename Coll::Digi Digi;
244 
245  // implementation for Barrel and Endcap
246 
247  if (col) {
248  nrTowers_=0;
249  LogDebug("EcalTPG") <<"Fill mapping, Collection size = "<<col->size();
250  for(unsigned int i = 0; i < col->size() ; ++i) {
251  Digi samples((*col)[i]);
252  EcalTrigTowerDetId coarser=(*eTTmap_).towerOf(samples.id());
253  int index=getIndex(col,coarser);
254  int stripnr=findStripNr(samples.id());
255 
256  int filled=0;
257  for (unsigned int ij=0;ij<towerMap[index].size();++ij) filled+=towerMap[index][ij].first;
258  if (!filled) {
259  hitTowers_[nrTowers_++]=std::pair <int,EcalTrigTowerDetId>(index,coarser);
260  }
261 
262  //FIXME: temporary protection
263  int ncryst=towerMap[index][stripnr-1].first;
264  if (ncryst>=nbMaxXtals_ ) {
265  edm::LogError("EcalTrigPrimFunctionAlgo")<<"! Too many xtals for TT "<<coarser<<" stripnr "<<stripnr<<" xtalid "<<samples.id() ;
266  continue;
267  }
268  ((towerMap[index])[stripnr-1].second)[ncryst]=samples;
269  (towerMap[index])[stripnr-1].first++;
270  }
271 
272  LogDebug("EcalTPG")<<"fillMap"<<"[EcalTrigPrimFunctionalAlgo] (found "
273  << col->size() << " frames in "<< towerMap.size() << " towers) ";
274  }
275  else {
276  LogDebug("EcalTPG")<<"FillMap - FillMap Collection size=0 !!!!";
277  }
278 }
279 
280 template <class T>
281 void EcalTrigPrimFunctionalAlgo::clean( std::vector<std::vector<std::pair<int,std::vector<T> > > > & towMap) {
282  // clean internal data structures
283  for (unsigned int i=0;i<maxNrTowers_;++i)
284  for (int j=0;j<nbMaxStrips_ ;++j) (towMap[i])[j].first=0;
285  return;
286 }
287 
288 template <class T>
289 void EcalTrigPrimFunctionalAlgo::initStructures( std::vector<std::vector<std::pair<int,std::vector<T> > > > & towMap) {
290  //initialise internal data structures
291 
292  std::vector <T> vec0(nbMaxXtals_ );
293  std::vector<std::pair<int,std::vector<T> > > vec1(nbMaxStrips_);
294  for (int i=0;i<nbMaxStrips_ ;++i) vec1[i]=std::pair<int,std::vector<T> >(0,vec0);
295  towMap.resize(maxNrTowers_);
296  for (unsigned int i=0;i<maxNrTowers_;++i) towMap[i]=vec1;
297 
298  std::vector<int> vecint(maxNrSamples_);
299  striptp_.resize(nbMaxStrips_);
300  for (int i=0;i<nbMaxStrips_;++i) striptp_[i]=vecint;
301 
302 }
303 
304 #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)
std::vector< std::vector< std::pair< int, std::vector< EBDataFrame > > > > towerMapEB_
const EcalElectronicsMapping * theMapping_
void setbadStripMissing(bool flag)
const CaloSubdetectorGeometry * theEndcapGeometry
std::vector< std::vector< int > > striptp_
std::vector< std::pair< int, EcalTrigTowerDetId > > hitTowers_
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 push_back(T const &t)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
static const unsigned int maxNrSamplesOut_
int zside(DetId const &)
std::tuple< unsigned int, int, int, DigiType, int, int, int, float > Digi
Definition: GenericDigi.h:30
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 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:59
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 fillMap(Coll const *col, std::vector< std::vector< std::pair< int, std::vector< typename Coll::Digi > > > > &towerMap)
void run(const edm::EventSetup &, const EBDigiCollection *col, EcalTrigPrimDigiCollection &result, EcalTrigPrimDigiCollection &resultTcp)
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)
EcalFenixStripFgvbEE * getFGVB() const
std::vector< std::vector< std::pair< int, std::vector< EEDataFrame > > > > towerMapEE_
int getIndex(const EBDigiCollection *, EcalTrigTowerDetId &id)
int getIndex(const EEDigiCollection *, EcalTrigTowerDetId &id)
int iphi() const
get the tower iphi
#define debug
Definition: HDRShower.cc:19
void init(const edm::EventSetup &)
void initStructures(std::vector< std::vector< std::pair< int, std::vector< T > > > > &towMap)
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
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:34
void clean(std::vector< std::vector< std::pair< int, std::vector< T > > > > &towerMap)
static const unsigned int nrSamples_
void run_part1_EE(EEDigiCollection const *col)
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:46