CMS 3D CMS Logo

SiStripFEDEmulator.cc
Go to the documentation of this file.
4 
5 #include <functional>
6 
7 using edm::LogError;
8 using edm::LogInfo;
9 using edm::LogWarning;
10 
11 namespace sistrip {
12 
13  const char* const FEDEmulator::messageLabel_ = "SiStripFEDEmulator";
14 
16  byModule_ = false;
17  minStrip_ = 0;
18  maxStrip_ = 0;
19  pedestals_.clear();
20  noises_.clear();
21  medians_.clear();
22 
23  detId_ = 0;
24  nPairs_ = 0;
25  pair_ = 0;
26  }
27 
29 
30  void FEDEmulator::initialise(const bool byModule) {
31  byModule_ = byModule;
32  pedestals_.clear();
33  noises_.clear();
34  medians_.clear();
35  }
36 
37  void FEDEmulator::initialiseModule(const uint32_t aDetId, const uint32_t aNPairs, const uint32_t aPair) {
38  detId_ = aDetId;
39  nPairs_ = aNPairs;
40  pair_ = aPair;
41 
42  minStrip_ = 0;
44  if (!byModule_) {
47  }
48 
49  //need resize because it will not be filled by push_back...
50  pedestals_.clear();
52 
53  noises_.clear();
55 
56  medians_.clear();
57  medians_.reserve(nPairs_ * 2);
58  }
59 
61  try {
62  SiStripPedestals::Range pedestalsRange = aHandle->getRange(detId_);
63  aHandle->allPeds(pedestals_, pedestalsRange);
64  } catch (const cms::Exception& e) {
65  LogError(messageLabel_) << " Something wrong whilst getting pedestals: size = " << pedestals_.size()
66  << " detId = " << detId_ << std::endl
67  << e.what();
68  //throw cms::Exception("ProductNotFound") << "Problem with pedestals..." ;
69  }
70  } //end of retrievePedestals method.
71 
73  try {
74  SiStripNoises::Range noisesRange = aHandle->getRange(detId_);
75  aHandle->allNoises(noises_, noisesRange);
76  } catch (const cms::Exception& e) {
77  LogError(messageLabel_) << " Something wrong whilst getting noises: size = " << noises_.size()
78  << " detId = " << detId_ << std::endl
79  << e.what();
80  //throw cms::Exception("ProductNotFound") << "Problem with noises..." ;
81  }
82  } //end of retrieveNoises method.
83 
85  std::vector<SiStripRawDigi>& pedsDetSetData,
86  std::vector<SiStripProcessedRawDigi>& noiseDetSetData,
87  std::vector<SiStripRawDigi>& pedSubtrDetSetData,
88  std::vector<uint32_t>& medsDetSetData,
89  const bool fillApvsForCM) {
90  edm::DetSet<SiStripRawDigi>::const_iterator digi_it = inputChannel->begin();
92  uint32_t lCount = 0;
93  std::vector<std::vector<uint16_t> > apvs;
94  apvs.reserve(nPairs_ * 2);
95 
96  //subtract pedestals and fill apv vector
97  //for median calculation
98  //in a module, 256*nPairs, but here we are dealing
99  //channel by channel, so 256 values at a time in the pedestal object.
100  //reordered = 0-127 APV0 128-255 APV1
101 
102  std::vector<uint16_t> apvVec;
103  ;
104  apvVec.reserve(sistrip::STRIPS_PER_APV);
105 
106  for (uint32_t st = minStrip_; st < maxStrip_; st++) {
107  uint16_t ped = static_cast<uint16_t>(pedestals_[st]);
108  pedsDetSetData.push_back(SiStripRawDigi(ped));
109 
110  float noise = noises_[st];
111  noiseDetSetData.push_back(SiStripProcessedRawDigi(noise));
112 
113  if (digi_it == inputChannel->end()) {
114  LogError(messageLabel_) << " Error, end of inputchannel reached for detid " << detId_ << "! Processed "
115  << lCount << " strips." << std::endl;
116  break;
117  }
118 
119  int lVal = digi_it->adc() - ped;
120  if (lVal < 0) {
121  if (digi_it->adc() > 0)
122  LogDebug(messageLabel_) << " Negative value after pedestal subtraction ! Detid = " << detId_ << ", strip "
123  << st << ", digi = " << digi_it->adc() << ", ped = " << ped << std::endl;
124  lVal = 0;
125  }
126  pedSubtrDetSetData.push_back(SiStripRawDigi(static_cast<uint16_t>(lVal)));
127 
128  if (fillApvsForCM) {
129  apvVec.push_back(static_cast<uint16_t>(lVal));
130  }
131 
132  lCount++;
133  ++digi_it;
134 
135  if (lCount % sistrip::STRIPS_PER_APV == 0 && fillApvsForCM) {
136  if (!apvVec.empty())
137  apvs.push_back(apvVec);
138  apvVec.clear();
139  apvVec.reserve(sistrip::STRIPS_PER_APV);
140  }
141 
142  } //end of loop over strips
143 
144  if (fillApvsForCM) {
145  if (apvs.size() != nPairs_ * 2) {
146  LogError(messageLabel_) << " Error, wrong output size for median calculation for detid " << detId_
147  << "! Processed " << apvs.size() << " APVs." << std::endl;
148  }
149 
150  //calculate common mode values
151  for (uint32_t iapv(0); iapv < apvs.size(); iapv++) {
152  std::vector<uint16_t> lVec = apvs[iapv];
153 
154  std::vector<uint16_t>::iterator mid = lVec.begin() + (lVec.size() / 2 - 1);
155  std::nth_element(lVec.begin(), mid, lVec.end());
156 
157  //std::sort(lVec.begin(),lVec.end());
158  //get the 64th element
159  //if (*mid != lVec.at(63)) exit(0);
160  //medians_.push_back(lVec.at(63));
161  //medsDetSetData.push_back(lVec.at(63));
162  medians_.push_back(*mid);
163  medsDetSetData.push_back(*mid);
164  }
165  }
166 
167  } //end of FEDEmulator::subtractPedestals method.
168 
169  void FEDEmulator::subtractCM(const std::vector<SiStripRawDigi>& pedSubtrDetSetData,
170  std::vector<SiStripRawDigi>& cmSubtrDetSetData) {
171  //subtract Medians
172  std::vector<SiStripRawDigi>::const_iterator lDigi = pedSubtrDetSetData.begin();
173  uint32_t lCount = 0;
174 
175  for (uint32_t st = minStrip_; st < maxStrip_; st++) {
176  uint32_t lApvNum = static_cast<uint32_t>(lCount * 1. / sistrip::STRIPS_PER_APV);
177 
178  int value = lDigi->adc() - medians_.at(lApvNum);
179  if (value < 0) {
180  //FED doesn't handle negative values
181  value = 0;
182  }
183  cmSubtrDetSetData.push_back(SiStripRawDigi(static_cast<uint16_t>(value)));
184 
185  ++lDigi;
186  lCount++;
187  }
188  }
189 
190  void FEDEmulator::zeroSuppress(const std::vector<SiStripRawDigi>& cmSubtrDetSetData,
191  edm::DetSet<SiStripDigi>& zsDetSetData,
192  const std::unique_ptr<SiStripRawProcessingAlgorithms>& algorithms) {
193  //transform the input digis to a vector of integers
194  std::vector<int16_t> cmSubtrRawDigis;
195  transform(cmSubtrDetSetData.begin(),
196  cmSubtrDetSetData.end(),
197  back_inserter(cmSubtrRawDigis),
198  std::bind(&SiStripRawDigi::adc, std::placeholders::_1));
199  algorithms->suppressor->suppress(cmSubtrRawDigis, 0, zsDetSetData);
200 
201  } //end of FEDEmulator::zeroSuppress method.
202 
204  for (edm::DetSet<SiStripRawDigi>::const_iterator iApv = peds->begin(); iApv != peds->end(); ++iApv) {
205  pedestals_.push_back(iApv->adc());
206  }
207  }
208 
210  for (edm::DetSet<SiStripProcessedRawDigi>::const_iterator iApv = noises->begin(); iApv != noises->end(); ++iApv) {
211  noises_.push_back(iApv->adc());
212  }
213  }
214 
215  void FEDEmulator::fillMedians(const std::map<uint32_t, std::vector<uint32_t> >::const_iterator& meds) {
216  std::vector<uint32_t>::const_iterator iApv = (meds->second).begin();
217  for (; iApv != (meds->second).end(); ++iApv) {
218  medians_.push_back(*iApv);
219  }
220  }
221 
222  void FEDEmulator::print(std::ostream& aOs) {
223  aOs << "===============================" << std::endl
224  << " ===== FEDEmulator::print =====" << std::endl
225  << " === byModule = " << byModule_ << std::endl
226  << " === minStrip = " << minStrip_ << std::endl
227  << " === maxStrip = " << maxStrip_ << std::endl
228  << " === size of pedestals = " << pedestals_.size() << std::endl
229  << " === size of noises = " << noises_.size() << std::endl
230  << " === size of medians = " << medians_.size() << std::endl
231  << " === detId = " << detId_ << std::endl
232  << " === nPairs = " << nPairs_ << std::endl
233  << " === pair = " << pair_ << std::endl
234  << "===============================" << std::endl;
235  }
236 
237  void FEDEmulator::printPeds(std::ostream& aOs) {
238  aOs << "=========================================" << std::endl
239  << " ===== FEDEmulator::printPedestals =====" << std::endl;
240  for (unsigned int i(0); i < pedestals_.size(); i++) {
241  if (i % 32 == 0)
242  aOs << std::endl;
243  aOs << pedestals_[i] << " ";
244  }
245  aOs << "=========================================" << std::endl;
246  }
247 
248  void FEDEmulator::printNoises(std::ostream& aOs) {
249  aOs << "=========================================" << std::endl
250  << " ===== FEDEmulator::printNoises =====" << std::endl;
251  for (unsigned int i(0); i < noises_.size(); i++) {
252  if (i % 32 == 0)
253  aOs << std::endl;
254  aOs << noises_[i] << " ";
255  }
256  aOs << "=========================================" << std::endl;
257  }
258 
259  void FEDEmulator::printMeds(std::ostream& aOs) {
260  aOs << "=========================================" << std::endl
261  << " ===== FEDEmulator::printMedians =====" << std::endl;
262  for (unsigned int i(0); i < medians_.size(); i++) {
263  if (i % 32 == 0)
264  aOs << std::endl;
265  aOs << medians_[i] << " ";
266  }
267  aOs << "=========================================" << std::endl;
268  }
269 
270 } //namespace sistrip
const Range getRange(const uint32_t &detID) const
void push_back(const T &t)
Definition: DetSet.h:66
void allNoises(std::vector< float > &noises, const Range &range) const
void subtractPedestals(const edm::DetSetVector< SiStripRawDigi >::const_iterator &inputChannel, std::vector< SiStripRawDigi > &pedsDetSetData, std::vector< SiStripProcessedRawDigi > &noiseDetSetData, std::vector< SiStripRawDigi > &pedSubtrDetSetData, std::vector< uint32_t > &medsDetSetData, const bool fillApvsForCM)
void printPeds(std::ostream &aOs)
A signed Digi for the silicon strip detector, containing only adc information, and suitable for stori...
static const char *const messageLabel_
void fillPeds(const edm::DetSetVector< SiStripRawDigi >::const_iterator &peds)
void allPeds(std::vector< int > &pefs, const Range &range) const
std::pair< ContainerIterator, ContainerIterator > Range
Log< level::Error, false > LogError
uint16_t adc() const
sistrip classes
void retrieveNoises(const edm::ESHandle< SiStripNoises > &aHandle)
std::vector< float > noises_
void fillMedians(const std::map< uint32_t, std::vector< uint32_t > >::const_iterator &meds)
void initialiseModule(const uint32_t aDetId, const uint32_t aNPairs, const uint32_t aPair)
Definition: value.py:1
std::vector< int > pedestals_
void subtractCM(const std::vector< SiStripRawDigi > &pedSubtrDetSetData, std::vector< SiStripRawDigi > &cmSubtrDetSetData)
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:316
Log< level::Info, false > LogInfo
static const uint16_t STRIPS_PER_FEDCH
void initialise(const bool byModule)
void zeroSuppress(const std::vector< SiStripRawDigi > &cmSubtrDetSetData, edm::DetSet< SiStripDigi > &zsDetSetData, const std::unique_ptr< SiStripRawProcessingAlgorithms > &algorithms)
void printNoises(std::ostream &aOs)
void print(std::ostream &aOs)
void printMeds(std::ostream &aOs)
const Range getRange(const uint32_t detID) const
std::vector< uint32_t > medians_
static const uint16_t STRIPS_PER_APV
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:305
void retrievePedestals(const edm::ESHandle< SiStripPedestals > &aHandle)
Log< level::Warning, false > LogWarning
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
void fillNoises(const edm::DetSetVector< SiStripProcessedRawDigi >::const_iterator &noise)
#define LogDebug(id)
unsigned transform(const HcalDetId &id, unsigned transformCode)