CMS 3D CMS Logo

EcalFenixLinearizer.cc
Go to the documentation of this file.
2 
6 
8 
10  : famos_(famos), init_(false),
11  linConsts_(nullptr),
12  peds_(nullptr),
13  badXStatus_(nullptr)
14 {
15 }
16 
18  if (init_) {
19  for (int i=0;i<(int)vectorbadXStatus_.size();i++){
20  delete vectorbadXStatus_[i];
21  }
22  }
23 }
24 
25 void EcalFenixLinearizer::setParameters(uint32_t raw, const EcalTPGPedestals * ecaltpPed, const EcalTPGLinearizationConst * ecaltpLin, const EcalTPGCrystalStatus * ecaltpBadX)
26 {
27 
28 
29  const EcalTPGLinearizationConstMap & linMap = ecaltpLin->getMap() ;
31 
32  if (it!=linMap.end()) {
33  linConsts_=&(*it);
34  }
35  else std::cout <<" could not find EcalTPGLinearizationConstMap entry for "<<raw << std::endl;
36 
37  EcalTPGPedestalsMapIterator itped=ecaltpPed->find(raw);
38  if (itped!=ecaltpPed->end()) peds_=&(*itped);
39  else std::cout <<" could not find EcalTPGPedestalsMap entry for "<<raw << std::endl;
40 
41  const EcalTPGCrystalStatusMap & badXMap = ecaltpBadX->getMap();
42  EcalTPGCrystalStatusMapIterator itbadX=badXMap.find(raw);
43 
44  if (itbadX!=badXMap.end()) {
45  badXStatus_=&(*itbadX);
46  }
47  else
48  {
49  edm::LogWarning("EcalTPG")<<" could not find EcalTPGCrystalStatusMap entry for "<<raw;
51  vectorbadXStatus_.push_back(&(*badXStatus_));
52  init_ = true;
53  }
54 
55 
56 
57 }
58 
60 {
61 
62 
63  int output=(uncorrectedSample_-base_); //Substract base
64  //std::cout << " EcalFenixLinearizer::process() output non bit shifted " << output << std::endl;
65  if(famos_ || output<0) return 0;
66 
67  if(output<0) return shift_ << 12; // FENIX bug(!)
68  output=(output*mult_)>>(shift_+2); //Apply multiplicative factor
69  //std::cout << " EcalFenixLinearizer::process() output 2nd step " << output << std::endl;
70  if(output>0X3FFFF)output=0X3FFFF; //Saturation if too high
71  //std::cout << " EcalFenixLinearizer::process() output 3rd step " << output << std::endl;
72  return output;
73 }
74 
76 {
77 
78  //std::cout << " EcalFenixLinearizer::setInput RawSam.raw() " << RawSam.raw() << std::endl;
79  if(RawSam.raw()>0X3FFF)
80  {
81  LogDebug("EcalTPG")<<"ERROR IN INPUT SAMPLE OF FENIX LINEARIZER";
82  return -1;
83  }
84 
85  uncorrectedSample_=RawSam.adc(); //uncorrectedSample_ is coded in the 12 LSB
86  gainID_=RawSam.gainId(); //uncorrectedSample_ is coded in the 2 next bits!
87 
88  if ( gainID_>1) {
89  //std::cout << " EcalFenixLinearizer::setInput gain " << gainID_ << std::endl;
90  return -999;
91  }
92  //if (gainID_==0) gainID_=3;
93 
94  if(gainID_ == 0)
95  {
96  base_ = 0;
97  shift_ = 0;
98  mult_ = 0xFF;
99  if((linConsts_->mult_x12 == 0) && (linConsts_->mult_x6 == 0) && (linConsts_->mult_x1 == 0))
100  {
101 
102  mult_ = 0; // Implemented in CCSSupervisor to
103  // reject overflow cases in rejected channels
104  }
105  }
106  else if (gainID_==1) {
107  base_ = peds_ -> mean_x12;
108  shift_ = linConsts_ -> shift_x12;
109 
110  // take into account the badX
111  // badXStatus_ == 0 if the crystal works
112  // badXStatus_ !=0 some problem with the crystal
113  if (badXStatus_->getStatusCode()!=0){
114  mult_ = 0;
115  }
116  else{
117  mult_ = linConsts_ -> mult_x12;
118  }
119  }
120  else if (gainID_==2) {
121  base_ = peds_ -> mean_x6;
122  shift_ = linConsts_ -> shift_x6;
123 
124  // take into account the badX
125  // check if the badX has a status code=0 or 1
126  if (badXStatus_->getStatusCode()!=0){
127  mult_ = 0;
128  }
129  else{
130  mult_ = linConsts_ -> mult_x6;
131  }
132  }
133  else if (gainID_==3){
134  base_ = peds_-> mean_x1;
135  shift_ = linConsts_ -> shift_x1;
136 
137  // take into account the badX
138  // check if the badX has a status code=0 or 1
139  if (badXStatus_->getStatusCode()!=0){
140  mult_ = 0;
141  }
142  else{
143  mult_ = linConsts_ -> mult_x1;
144  }
145  }
146 
147  //std::cout << " EcalFenixLinearizer::setInput uncorrectedSample_ " << RawSam.adc() << " gainID " << gainID_ << " baseline " << base_ << std::endl;
148 
149  if (famos_) base_=200; //FIXME by preparing a correct TPG.txt for Famos
150 
151  return 1;
152 }
153 
#define LogDebug(id)
void setParameters(uint32_t raw, const EcalTPGPedestals *ecaltpPed, const EcalTPGLinearizationConst *ecaltpLin, const EcalTPGCrystalStatus *ecaltpBadX)
EcalTPGPedestalsMap::const_iterator EcalTPGPedestalsMapIterator
const self & getMap() const
EcalFenixLinearizer(bool famos)
uint16_t raw() const
get the raw word
#define nullptr
int gainId() const
get the gainId (2 bits)
EcalCondObjectContainer< EcalTPGLinearizationConstant >::const_iterator EcalTPGLinearizationConstMapIterator
EcalTPGCrystalStatusMap::const_iterator EcalTPGCrystalStatusMapIterator
int setInput(const EcalMGPASample &RawSam)
const EcalTPGLinearizationConstant * linConsts_
const EcalTPGCrystalStatusCode * badXStatus_
std::vector< const EcalTPGCrystalStatusCode * > vectorbadXStatus_
const_iterator find(uint32_t rawId) const
const EcalTPGPedestal * peds_
const_iterator end() const
int adc() const
get the ADC sample (12 bits)