CMS 3D CMS Logo

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