CMS 3D CMS Logo

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") {
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 }
112  evt.put(std::make_unique<edm::DetSetVector<SiStripDigi>>(output_base), tagName);
113  if (produceRawDigis && !rawInputs.empty())
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 }
SiStripZeroSuppression::storeCM
bool storeCM
Definition: SiStripZeroSuppression.h:40
edm::DetSet::push_back
void push_back(const T &t)
Definition: DetSet.h:66
SiStripZeroSuppression::RawType
RawType
Definition: SiStripZeroSuppression.h:22
edm::DetSetVector< SiStripRawDigi >
SiStripRawProcessingFactory.h
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
SiStripZeroSuppression::rawInputs
std::vector< std::tuple< std::string, RawType, rawtoken_t > > rawInputs
Definition: SiStripZeroSuppression.h:49
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm::DetSet::size
size_type size() const
Definition: DetSet.h:61
SiStripZeroSuppression::storeBaseline
void storeBaseline(uint32_t, const medians_t &)
Definition: SiStripZeroSuppression.cc:208
edm::DetSet< SiStripDigi >
SiStripRawProcessingFactory
Definition: SiStripRawProcessingFactory.h:15
edm
HLT enums.
Definition: AlignableModifier.h:19
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
edm::DetSet::id
det_id_type id
Definition: DetSet.h:79
SiStripZeroSuppression::storeCMN
void storeCMN(uint32_t, const medians_t &)
Definition: SiStripZeroSuppression.cc:245
SiStripRawDigi.h
SiStripZeroSuppression.h
pfDeepBoostedJetPreprocessParams_cfi.median
median
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:12
SiStripZeroSuppression::formatRawDigis
edm::DetSet< SiStripRawDigi > formatRawDigis(const edm::DetSet< SiStripRawDigi > &rawDigis)
Definition: SiStripZeroSuppression.cc:163
SiStripZeroSuppression::output_base_raw
std::vector< edm::DetSet< SiStripRawDigi > > output_base_raw
Definition: SiStripZeroSuppression.h:53
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
edm::Handle
Definition: AssociativeIterator.h:50
SiStripZeroSuppression::medians_t
std::vector< std::pair< short, float > > medians_t
Definition: SiStripZeroSuppression.h:32
SiStripZeroSuppression::processHybrid
void processHybrid(const edm::DetSetVector< SiStripDigi > &input)
Definition: SiStripZeroSuppression.cc:150
edm::DetSet::empty
bool empty() const
Definition: DetSet.h:62
SiStripZeroSuppression::SiStripZeroSuppression
SiStripZeroSuppression(const edm::ParameterSet &)
Definition: SiStripZeroSuppression.cc:14
HLT_FULL_cff.storeInZScollBadAPV
storeInZScollBadAPV
Definition: HLT_FULL_cff.py:101443
SiStripRawDigi
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
Definition: SiStripRawDigi.h:15
SiStripZeroSuppression::putOutputs
void putOutputs(edm::Event &evt, const std::string &tagName)
Definition: SiStripZeroSuppression.cc:111
HLT_FULL_cff.storeCM
storeCM
Definition: HLT_FULL_cff.py:101483
SiStripZeroSuppression::fixCM
bool fixCM
Definition: SiStripZeroSuppression.h:41
SiStripDigi.h
HLT_FULL_cff.produceCalculatedBaseline
produceCalculatedBaseline
Definition: HLT_FULL_cff.py:101442
mps_fire.end
end
Definition: mps_fire.py:242
SiStripZeroSuppression::RawType::ScopeMode
HLT_FULL_cff.produceHybridFormat
produceHybridFormat
Definition: HLT_FULL_cff.py:101440
SiStripZeroSuppression::storeInZScollBadAPV
bool storeInZScollBadAPV
Definition: SiStripZeroSuppression.h:44
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripZeroSuppression::storeBaselinePoints
void storeBaselinePoints(uint32_t)
Definition: SiStripZeroSuppression.cc:230
SiStripZeroSuppression::RawType::ProcessedRaw
edm::ParameterSet
Definition: ParameterSet.h:47
SiStripZeroSuppression::output_baseline
std::vector< edm::DetSet< SiStripProcessedRawDigi > > output_baseline
Definition: SiStripZeroSuppression.h:55
Event.h
ParameterSet
Definition: Functions.h:16
HLT_FULL_cff.produceBaselinePoints
produceBaselinePoints
Definition: HLT_FULL_cff.py:101441
SiStripZeroSuppression::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: SiStripZeroSuppression.cc:82
SiStripZeroSuppression::produceCalculatedBaseline
bool produceCalculatedBaseline
Definition: SiStripZeroSuppression.h:42
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
SiStripZeroSuppression::output_base
std::vector< edm::DetSet< SiStripDigi > > output_base
Definition: SiStripZeroSuppression.h:52
edm::EventSetup
Definition: EventSetup.h:57
analysisFilters_cff.algorithms
algorithms
Definition: analysisFilters_cff.py:30
SiStripZeroSuppression::clearOutputs
void clearOutputs()
Definition: SiStripZeroSuppression.cc:104
DetSetVector.h
HLT_FULL_cff.fixCM
fixCM
Definition: HLT_FULL_cff.py:101439
SiStripZeroSuppression::hybridInputs
std::vector< std::tuple< std::string, zstoken_t > > hybridInputs
Definition: SiStripZeroSuppression.h:50
edm::DetSet::reserve
void reserve(size_t s)
Definition: DetSet.h:65
SiStripZeroSuppression::produceRawDigis
bool produceRawDigis
Definition: SiStripZeroSuppression.h:39
eostools.move
def move(src, dest)
Definition: eostools.py:511
HLT_FULL_cff.produceRawDigis
produceRawDigis
Definition: HLT_FULL_cff.py:101484
SiStripZeroSuppression::produceBaselinePoints
bool produceBaselinePoints
Definition: SiStripZeroSuppression.h:43
SiStripZeroSuppression::RawType::Unknown
SiStripZeroSuppression::processRaw
void processRaw(const edm::DetSetVector< SiStripRawDigi > &input, RawType inType)
Definition: SiStripZeroSuppression.cc:123
SiStripZeroSuppression::output_apvcm
std::vector< edm::DetSet< SiStripProcessedRawDigi > > output_apvcm
Definition: SiStripZeroSuppression.h:54
transform.h
Exception
Definition: hltDiff.cc:246
SiStripZeroSuppression::RawType::VirginRaw
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SiStripZeroSuppression::storeExtraOutput
void storeExtraOutput(uint32_t, int16_t)
Definition: SiStripZeroSuppression.cc:196
SiStripProcessedRawDigi
A signed Digi for the silicon strip detector, containing only adc information, and suitable for stori...
Definition: SiStripProcessedRawDigi.h:16
SiStripDigi
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
ParameterSet.h
SiStripZeroSuppression::algorithms
std::unique_ptr< SiStripRawProcessingAlgorithms > algorithms
Definition: SiStripZeroSuppression.h:37
SimL1EmulatorRepack_Full_cff.inputTag
inputTag
Definition: SimL1EmulatorRepack_Full_cff.py:56
edm::Event
Definition: Event.h:73
JetPartonCorrections_cff.tagName
tagName
Definition: JetPartonCorrections_cff.py:12
SiStripZeroSuppression::produceHybridFormat
bool produceHybridFormat
Definition: SiStripZeroSuppression.h:45
SiStripZeroSuppression::output_baseline_points
std::vector< edm::DetSet< SiStripDigi > > output_baseline_points
Definition: SiStripZeroSuppression.h:56
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37