CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripZeroSuppression.cc
Go to the documentation of this file.
2 
12 #include <memory>
13 
15  : algorithms(
16  SiStripRawProcessingFactory::create(conf.getParameter<edm::ParameterSet>("Algorithms"), consumesCollector())),
17  produceRawDigis(conf.getParameter<bool>("produceRawDigis")),
18  storeCM(conf.getParameter<bool>("storeCM")),
19  fixCM(conf.getParameter<bool>("fixCM")),
20  produceCalculatedBaseline(conf.getParameter<bool>("produceCalculatedBaseline")),
21  produceBaselinePoints(conf.getParameter<bool>("produceBaselinePoints")),
22  storeInZScollBadAPV(conf.getParameter<bool>("storeInZScollBadAPV")),
23  produceHybridFormat(conf.getParameter<bool>("produceHybridFormat")) {
24  for (const auto& inputTag : conf.getParameter<std::vector<edm::InputTag>>("RawDigiProducersList")) {
25  const auto& tagName = inputTag.instance();
26  produces<edm::DetSetVector<SiStripDigi>>(tagName);
27  if (produceRawDigis)
28  produces<edm::DetSetVector<SiStripRawDigi>>(tagName);
29  if (storeCM)
30  produces<edm::DetSetVector<SiStripProcessedRawDigi>>("APVCM" + tagName);
32  produces<edm::DetSetVector<SiStripProcessedRawDigi>>("BADAPVBASELINE" + tagName);
34  produces<edm::DetSetVector<SiStripDigi>>("BADAPVBASELINEPOINTS" + tagName);
35 
36  RawType inputType = RawType::Unknown;
37  if (tagName == "ProcessedRaw") {
38  inputType = RawType::ProcessedRaw;
40  throw cms::Exception("Processed Raw Cannot be converted in hybrid Format");
41  } else if (tagName == "VirginRaw") {
42  inputType = RawType::VirginRaw;
43  } else if (tagName == "ScopeMode") {
44  inputType = RawType::ScopeMode;
46  throw cms::Exception("Scope Mode cannot be converted in hybrid Format");
47  }
48  if (RawType::Unknown != inputType) {
49  rawInputs.emplace_back(tagName, inputType, consumes<edm::DetSetVector<SiStripRawDigi>>(inputTag));
50  } else if (tagName == "ZeroSuppressed") {
51  hybridInputs.emplace_back(tagName, consumes<edm::DetSetVector<SiStripDigi>>(inputTag));
52  } else {
53  throw cms::Exception("Unknown input type")
54  << tagName << " unknown. "
55  << "SiStripZeroZuppression can only process types \"VirginRaw\", \"ProcessedRaw\" and \"ZeroSuppressed\"";
56  }
57  }
58 
59  if (produceHybridFormat &&
60  ("HybridEmulation" !=
61  conf.getParameter<edm::ParameterSet>("Algorithms").getParameter<std::string>("APVInspectMode")))
62  throw cms::Exception("Invalid option") << "When producing data in the hybrid format, the APV restorer must be "
63  "configured with APVInspectMode='HybridEmulation'";
64 
65  if ((!hybridInputs.empty()) && produceRawDigis) {
66  edm::LogInfo("SiStripZeroSuppression") << "Raw digis will not be saved for hybrid inputs";
67  }
68 
69  if (!(rawInputs.empty() && hybridInputs.empty())) {
70  output_base.reserve(16000);
71  if (produceRawDigis && !rawInputs.empty())
72  output_base_raw.reserve(16000);
73  if (storeCM)
74  output_apvcm.reserve(16000);
76  output_baseline.reserve(16000);
78  output_baseline_points.reserve(16000);
79  }
80 }
81 
83  algorithms->initialize(es, e);
84 
85  for (const auto& input : rawInputs) {
86  clearOutputs();
88  e.getByToken(std::get<rawtoken_t>(input), inDigis);
89  if (!inDigis->empty())
90  processRaw(*inDigis, std::get<RawType>(input));
91  putOutputs(e, std::get<std::string>(input));
92  }
93  for (const auto& input : hybridInputs) {
94  clearOutputs();
96  e.getByToken(std::get<zstoken_t>(input), inDigis);
97  if (!inDigis->empty()) {
98  processHybrid(*inDigis);
99  }
100  putOutputs(e, std::get<std::string>(input));
101  }
102 }
103 
105  output_base.clear();
106  output_base_raw.clear();
107  output_baseline.clear();
108  output_baseline_points.clear();
109  output_apvcm.clear();
110 }
111 inline void SiStripZeroSuppression::putOutputs(edm::Event& evt, const std::string& tagName) {
112  evt.put(std::make_unique<edm::DetSetVector<SiStripDigi>>(output_base), tagName);
113  if (produceRawDigis && !rawInputs.empty())
114  evt.put(std::make_unique<edm::DetSetVector<SiStripRawDigi>>(output_base_raw), tagName);
116  evt.put(std::make_unique<edm::DetSetVector<SiStripProcessedRawDigi>>(output_baseline), "BADAPVBASELINE" + tagName);
118  evt.put(std::make_unique<edm::DetSetVector<SiStripDigi>>(output_baseline_points), "BADAPVBASELINEPOINTS" + tagName);
119  if (storeCM)
120  evt.put(std::make_unique<edm::DetSetVector<SiStripProcessedRawDigi>>(output_apvcm), "APVCM" + tagName);
121 }
122 
124  for (const auto& rawDigis : input) {
125  edm::DetSet<SiStripDigi> suppressedDigis(rawDigis.id);
126 
127  int16_t nAPVflagged = 0;
128  if (RawType::ProcessedRaw == inType) {
129  nAPVflagged = algorithms->suppressProcessedRawData(rawDigis, suppressedDigis);
130  } else if (RawType::ScopeMode == inType) {
131  nAPVflagged = algorithms->suppressVirginRawData(rawDigis, suppressedDigis);
132  } else if (RawType::VirginRaw == inType) {
133  if (produceHybridFormat) {
134  nAPVflagged = algorithms->convertVirginRawToHybrid(rawDigis, suppressedDigis);
135  } else {
136  nAPVflagged = algorithms->suppressVirginRawData(rawDigis, suppressedDigis);
137  }
138  }
139 
140  storeExtraOutput(rawDigis.id, nAPVflagged);
141  if (!suppressedDigis.empty() && (storeInZScollBadAPV || nAPVflagged == 0))
142  output_base.push_back(std::move(suppressedDigis));
143 
144  if (produceRawDigis && nAPVflagged > 0) {
145  output_base_raw.push_back(formatRawDigis(rawDigis));
146  }
147  }
148 }
149 
151  for (const auto& inDigis : input) {
152  edm::DetSet<SiStripDigi> suppressedDigis(inDigis.id);
153 
154  uint16_t nAPVflagged = 0;
155  nAPVflagged = algorithms->suppressHybridData(inDigis, suppressedDigis);
156 
157  storeExtraOutput(inDigis.id, nAPVflagged);
158  if (!suppressedDigis.empty())
159  output_base.push_back(std::move(suppressedDigis));
160  }
161 }
162 
164  edm::DetSet<SiStripRawDigi> outRawDigis(rawDigis.id);
165  outRawDigis.reserve(rawDigis.size());
166  const std::vector<bool>& apvf = algorithms->getAPVFlags();
167  uint32_t strip = 0;
168  for (const auto rawDigi : rawDigis) {
169  int16_t apvN = strip / 128;
170  if (apvf[apvN])
171  outRawDigis.push_back(rawDigi);
172  else
173  outRawDigis.push_back(SiStripRawDigi(0));
174  ++strip;
175  }
176  return outRawDigis;
177 }
178 
180  const std::vector<int16_t>& rawDigis) {
181  edm::DetSet<SiStripRawDigi> outRawDigis(detId);
182  outRawDigis.reserve(rawDigis.size());
183  const std::vector<bool>& apvf = algorithms->getAPVFlags();
184  uint32_t strip = 0;
185  for (const auto rawDigi : rawDigis) {
186  int16_t apvN = strip / 128;
187  if (apvf[apvN])
188  outRawDigis.push_back(SiStripRawDigi(rawDigi));
189  else
190  outRawDigis.push_back(SiStripRawDigi(0));
191  ++strip;
192  }
193  return outRawDigis;
194 }
195 
196 inline void SiStripZeroSuppression::storeExtraOutput(uint32_t id, int16_t nAPVflagged) {
197  const auto& vmedians = algorithms->getAPVsCM();
198  if (storeCM)
199  storeCMN(id, vmedians);
200  if (nAPVflagged > 0) {
202  storeBaseline(id, vmedians);
205  }
206 }
207 
208 inline void SiStripZeroSuppression::storeBaseline(uint32_t id, const medians_t& vmedians) {
209  const auto& baselinemap = algorithms->getBaselineMap();
210 
211  edm::DetSet<SiStripProcessedRawDigi> baselineDetSet(id);
212  baselineDetSet.reserve(vmedians.size() * 128);
213  for (const auto& vmed : vmedians) {
214  const uint16_t apvN = vmed.first;
215  const float median = vmed.second;
216  auto itBaselineMap = baselinemap.find(apvN);
217  if (baselinemap.end() == itBaselineMap) {
218  for (size_t strip = 0; strip < 128; ++strip)
219  baselineDetSet.push_back(SiStripProcessedRawDigi(median));
220  } else {
221  for (size_t strip = 0; strip < 128; ++strip)
222  baselineDetSet.push_back(SiStripProcessedRawDigi((itBaselineMap->second)[strip]));
223  }
224  }
225 
226  if (!baselineDetSet.empty())
227  output_baseline.push_back(baselineDetSet);
228 }
229 
231  edm::DetSet<SiStripDigi> baspointDetSet(id);
232  for (const auto& itBaselinePointVect : algorithms->getSmoothedPoints()) {
233  const uint16_t apvN = itBaselinePointVect.first;
234  for (const auto& itBaselinePointMap : itBaselinePointVect.second) {
235  const uint16_t bpstrip = itBaselinePointMap.first + apvN * 128;
236  const int16_t bp = itBaselinePointMap.second;
237  baspointDetSet.push_back(SiStripDigi(bpstrip, bp + 128));
238  }
239  }
240 
241  if (!baspointDetSet.empty())
242  output_baseline_points.push_back(std::move(baspointDetSet));
243 }
244 
245 inline void SiStripZeroSuppression::storeCMN(uint32_t id, const medians_t& vmedians) {
246  std::vector<bool> apvf(6, false);
247  if (fixCM) {
248  const auto& apvFlagged = algorithms->getAPVFlags();
249  std::copy(std::begin(apvFlagged), std::end(apvFlagged), std::begin(apvf));
250  }
251 
253  short apvNb = 0;
254  for (const auto& vmed : vmedians) {
255  if (vmed.first > apvNb) {
256  for (int i{0}; i < vmed.first - apvNb; ++i) {
257  apvDetSet.push_back(SiStripProcessedRawDigi(-999.));
258  apvNb++;
259  }
260  }
261 
262  if (fixCM && apvf[vmed.first]) {
263  apvDetSet.push_back(SiStripProcessedRawDigi(-999.));
264  } else {
265  apvDetSet.push_back(SiStripProcessedRawDigi(vmed.second));
266  }
267  apvNb++;
268  }
269 
270  if (!apvDetSet.empty())
271  output_apvcm.push_back(std::move(apvDetSet));
272 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void push_back(const T &t)
Definition: DetSet.h:66
tuple produceHybridFormat
std::vector< edm::DetSet< SiStripDigi > > output_base
std::vector< edm::DetSet< SiStripProcessedRawDigi > > output_baseline
tuple produceBaselinePoints
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< std::tuple< std::string, zstoken_t > > hybridInputs
A signed Digi for the silicon strip detector, containing only adc information, and suitable for stori...
tuple produceCalculatedBaseline
void processRaw(const edm::DetSetVector< SiStripRawDigi > &input, RawType inType)
std::vector< edm::DetSet< SiStripProcessedRawDigi > > output_apvcm
static std::string const input
Definition: EdmProvDump.cc:47
size_type size() const
Definition: DetSet.h:61
void reserve(size_t s)
Definition: DetSet.h:65
void storeExtraOutput(uint32_t, int16_t)
std::unique_ptr< SiStripRawProcessingAlgorithms > algorithms
tuple storeInZScollBadAPV
def move
Definition: eostools.py:511
std::vector< edm::DetSet< SiStripDigi > > output_baseline_points
std::vector< std::tuple< std::string, RawType, rawtoken_t > > rawInputs
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
tuple produceRawDigis
Log< level::Info, false > LogInfo
void storeBaseline(uint32_t, const medians_t &)
std::vector< edm::DetSet< SiStripRawDigi > > output_base_raw
void storeCMN(uint32_t, const medians_t &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::pair< short, float >> medians_t
void processHybrid(const edm::DetSetVector< SiStripDigi > &input)
SiStripZeroSuppression(const edm::ParameterSet &)
T median(std::vector< T > values)
Definition: median.h:16
bool empty() const
Definition: DetSet.h:62
edm::DetSet< SiStripRawDigi > formatRawDigis(const edm::DetSet< SiStripRawDigi > &rawDigis)
det_id_type id
Definition: DetSet.h:79
string end
Definition: dataset.py:937
void putOutputs(edm::Event &evt, const std::string &tagName)
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...