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