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* 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
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
sistrip::FEDEmulator::retrievePedestals
void retrievePedestals(const edm::ESHandle< SiStripPedestals > &aHandle)
Definition: SiStripFEDEmulator.cc:60
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
sistrip::FEDEmulator::subtractPedestals
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)
Definition: SiStripFEDEmulator.cc:84
edm::DetSetVector::end
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:325
sistrip::FEDEmulator::fillPeds
void fillPeds(const edm::DetSetVector< SiStripRawDigi >::const_iterator &peds)
Definition: SiStripFEDEmulator.cc:203
SiStripPedestals::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripPedestals.h:51
edm::DetSet< SiStripDigi >
edm::DetSetVector::begin
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:314
sistrip::FEDEmulator::printNoises
void printNoises(std::ostream &aOs)
Definition: SiStripFEDEmulator.cc:248
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
SiStripNoises::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripNoises.cc:34
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
sistrip::FEDEmulator::initialiseModule
void initialiseModule(const uint32_t aDetId, const uint32_t aNPairs, const uint32_t aPair)
Definition: SiStripFEDEmulator.cc:37
sistrip::FEDEmulator::subtractCM
void subtractCM(const std::vector< SiStripRawDigi > &pedSubtrDetSetData, std::vector< SiStripRawDigi > &cmSubtrDetSetData)
Definition: SiStripFEDEmulator.cc:169
SiStripRawDigi
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
Definition: SiStripRawDigi.h:15
sistrip::FEDEmulator::printMeds
void printMeds(std::ostream &aOs)
Definition: SiStripFEDEmulator.cc:259
SiStripFEDEmulator.h
SiStripNoises::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
SiStripRawDigi::adc
uint16_t adc() const
Definition: SiStripRawDigi.h:22
mps_fire.end
end
Definition: mps_fire.py:242
edm::ESHandle
Definition: DTSurvey.h:22
sistrip::FEDEmulator::print
void print(std::ostream &aOs)
Definition: SiStripFEDEmulator.cc:222
sistrip::FEDEmulator::zeroSuppress
void zeroSuppress(const std::vector< SiStripRawDigi > &cmSubtrDetSetData, edm::DetSet< SiStripDigi > &zsDetSetData, const std::unique_ptr< SiStripRawProcessingAlgorithms > &algorithms)
Definition: SiStripFEDEmulator.cc:190
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
sistrip::FEDEmulator::noises_
std::vector< float > noises_
Definition: SiStripFEDEmulator.h:86
sistrip::FEDEmulator::messageLabel_
static const char * messageLabel_
Definition: SiStripFEDEmulator.h:74
SiStripPedestals::allPeds
void allPeds(std::vector< int > &pefs, const Range &range) const
Definition: SiStripPedestals.cc:143
sistrip::FEDEmulator::minStrip_
uint32_t minStrip_
Definition: SiStripFEDEmulator.h:82
SiStripPedestals::getRange
const Range getRange(const uint32_t &detID) const
Definition: SiStripPedestals.cc:28
sistrip::FEDEmulator::initialise
void initialise(const bool byModule)
Definition: SiStripFEDEmulator.cc:30
sistrip::FEDEmulator::pedestals_
std::vector< int > pedestals_
Definition: SiStripFEDEmulator.h:85
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::DetSetVector::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
sistrip::STRIPS_PER_FEDCH
static const uint16_t STRIPS_PER_FEDCH
Definition: ConstantsForHardwareSystems.h:44
sistrip::FEDEmulator::retrieveNoises
void retrieveNoises(const edm::ESHandle< SiStripNoises > &aHandle)
Definition: SiStripFEDEmulator.cc:72
value
Definition: value.py:1
sistrip::FEDEmulator::FEDEmulator
FEDEmulator()
Definition: SiStripFEDEmulator.cc:15
analysisFilters_cff.algorithms
algorithms
Definition: analysisFilters_cff.py:30
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
gpuVertexFinder::noise
__shared__ int noise
Definition: gpuFitVertices.h:50
SiStripSpyEventMatcher.h
sistrip::FEDEmulator::detId_
uint32_t detId_
Definition: SiStripFEDEmulator.h:78
sistrip::FEDEmulator::maxStrip_
uint32_t maxStrip_
Definition: SiStripFEDEmulator.h:83
sistrip::FEDEmulator::fillNoises
void fillNoises(const edm::DetSetVector< SiStripProcessedRawDigi >::const_iterator &noise)
Definition: SiStripFEDEmulator.cc:209
sistrip::STRIPS_PER_APV
static const uint16_t STRIPS_PER_APV
Definition: ConstantsForHardwareSystems.h:43
SiStripNoises::allNoises
void allNoises(std::vector< float > &noises, const Range &range) const
Definition: SiStripNoises.cc:122
sistrip::FEDEmulator::printPeds
void printPeds(std::ostream &aOs)
Definition: SiStripFEDEmulator.cc:237
sistrip::FEDEmulator::fillMedians
void fillMedians(const std::map< uint32_t, std::vector< uint32_t > >::const_iterator &meds)
Definition: SiStripFEDEmulator.cc:215
sistrip::FEDEmulator::byModule_
bool byModule_
Definition: SiStripFEDEmulator.h:76
sistrip::FEDEmulator::nPairs_
uint32_t nPairs_
Definition: SiStripFEDEmulator.h:79
SiStripProcessedRawDigi
A signed Digi for the silicon strip detector, containing only adc information, and suitable for stori...
Definition: SiStripProcessedRawDigi.h:16
cms::Exception
Definition: Exception.h:70
genParticles_cff.map
map
Definition: genParticles_cff.py:11
sistrip
sistrip classes
Definition: EnsembleCalibrationLA.cc:10
sistrip::FEDEmulator::pair_
uint32_t pair_
Definition: SiStripFEDEmulator.h:80
sistrip::FEDEmulator::medians_
std::vector< uint32_t > medians_
Definition: SiStripFEDEmulator.h:87
HLTEgPhaseIITestSequence_cff.noises
noises
Definition: HLTEgPhaseIITestSequence_cff.py:1348
sistrip::FEDEmulator::~FEDEmulator
~FEDEmulator()
Definition: SiStripFEDEmulator.cc:28
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31