CMS 3D CMS Logo

SiStripZeroSuppression.cc
Go to the documentation of this file.
2 
12 #include <memory>
13 
15  : algorithms(SiStripRawProcessingFactory::create(conf.getParameter<edm::ParameterSet>("Algorithms"))),
16  produceRawDigis(conf.getParameter<bool>("produceRawDigis")),
17  storeCM(conf.getParameter<bool>("storeCM")),
18  fixCM(conf.getParameter<bool>("fixCM")),
19  produceCalculatedBaseline(conf.getParameter<bool>("produceCalculatedBaseline")),
20  produceBaselinePoints(conf.getParameter<bool>("produceBaselinePoints")),
21  storeInZScollBadAPV(conf.getParameter<bool>("storeInZScollBadAPV")),
22  produceHybridFormat(conf.getParameter<bool>("produceHybridFormat")) {
23  for (const auto& inputTag : conf.getParameter<std::vector<edm::InputTag>>("RawDigiProducersList")) {
24  const auto& tagName = inputTag.instance();
25  produces<edm::DetSetVector<SiStripDigi>>(tagName);
26  if (produceRawDigis)
27  produces<edm::DetSetVector<SiStripRawDigi>>(tagName);
28  if (storeCM)
29  produces<edm::DetSetVector<SiStripProcessedRawDigi>>("APVCM" + tagName);
31  produces<edm::DetSetVector<SiStripProcessedRawDigi>>("BADAPVBASELINE" + tagName);
33  produces<edm::DetSetVector<SiStripDigi>>("BADAPVBASELINEPOINTS" + tagName);
34 
35  RawType inputType = RawType::Unknown;
36  if (tagName == "ProcessedRaw") {
37  inputType = RawType::ProcessedRaw;
39  throw cms::Exception("Processed Raw Cannot be converted in hybrid Format");
40  } else if (tagName == "VirginRaw") {
41  inputType = RawType::VirginRaw;
42  } else if (tagName == "ScopeMode") {
43  inputType = RawType::ScopeMode;
45  throw cms::Exception("Scope Mode cannot be converted in hybrid Format");
46  }
47  if (RawType::Unknown != inputType) {
48  rawInputs.emplace_back(tagName, inputType, consumes<edm::DetSetVector<SiStripRawDigi>>(inputTag));
49  } else if (tagName == "ZeroSuppressed") {
51  } else {
52  throw cms::Exception("Unknown input type")
53  << tagName << " unknown. "
54  << "SiStripZeroZuppression can only process types \"VirginRaw\", \"ProcessedRaw\" and \"ZeroSuppressed\"";
55  }
56  }
57 
58  if (produceHybridFormat &&
59  ("HybridEmulation" !=
60  conf.getParameter<edm::ParameterSet>("Algorithms").getParameter<std::string>("APVInspectMode")))
61  throw cms::Exception("Invalid option") << "When producing data in the hybrid format, the APV restorer must be "
62  "configured with APVInspectMode='HybridEmulation'";
63 
64  if ((!hybridInputs.empty()) && produceRawDigis) {
65  edm::LogInfo("SiStripZeroSuppression") << "Raw digis will not be saved for hybrid inputs";
66  }
67 
68  if (!(rawInputs.empty() && hybridInputs.empty())) {
69  output_base.reserve(16000);
70  if (produceRawDigis && !rawInputs.empty())
71  output_base_raw.reserve(16000);
72  if (storeCM)
73  output_apvcm.reserve(16000);
75  output_baseline.reserve(16000);
77  output_baseline_points.reserve(16000);
78  }
79 }
80 
82  algorithms->initialize(es, e);
83 
84  for (const auto& input : rawInputs) {
85  clearOutputs();
87  e.getByToken(std::get<rawtoken_t>(input), inDigis);
88  if (!inDigis->empty())
89  processRaw(*inDigis, std::get<RawType>(input));
90  putOutputs(e, std::get<std::string>(input));
91  }
92  for (const auto& input : hybridInputs) {
93  clearOutputs();
95  e.getByToken(std::get<zstoken_t>(input), inDigis);
96  if (!inDigis->empty()) {
97  processHybrid(*inDigis);
98  }
99  putOutputs(e, std::get<std::string>(input));
100  }
101 }
102 
104  output_base.clear();
105  output_base_raw.clear();
106  output_baseline.clear();
107  output_baseline_points.clear();
108  output_apvcm.clear();
109 }
111  evt.put(std::make_unique<edm::DetSetVector<SiStripDigi>>(output_base), tagName);
112  if (produceRawDigis && !rawInputs.empty())
115  evt.put(std::make_unique<edm::DetSetVector<SiStripProcessedRawDigi>>(output_baseline), "BADAPVBASELINE" + tagName);
117  evt.put(std::make_unique<edm::DetSetVector<SiStripDigi>>(output_baseline_points), "BADAPVBASELINEPOINTS" + tagName);
118  if (storeCM)
119  evt.put(std::make_unique<edm::DetSetVector<SiStripProcessedRawDigi>>(output_apvcm), "APVCM" + tagName);
120 }
121 
123  for (const auto& rawDigis : input) {
124  edm::DetSet<SiStripDigi> suppressedDigis(rawDigis.id);
125 
126  int16_t nAPVflagged = 0;
127  if (RawType::ProcessedRaw == inType) {
128  nAPVflagged = algorithms->suppressProcessedRawData(rawDigis, suppressedDigis);
129  } else if (RawType::ScopeMode == inType) {
130  nAPVflagged = algorithms->suppressVirginRawData(rawDigis, suppressedDigis);
131  } else if (RawType::VirginRaw == inType) {
132  if (produceHybridFormat) {
133  nAPVflagged = algorithms->convertVirginRawToHybrid(rawDigis, suppressedDigis);
134  } else {
135  nAPVflagged = algorithms->suppressVirginRawData(rawDigis, suppressedDigis);
136  }
137  }
138 
139  storeExtraOutput(rawDigis.id, nAPVflagged);
140  if (!suppressedDigis.empty() && (storeInZScollBadAPV || nAPVflagged == 0))
141  output_base.push_back(std::move(suppressedDigis));
142 
143  if (produceRawDigis && nAPVflagged > 0) {
144  output_base_raw.push_back(formatRawDigis(rawDigis));
145  }
146  }
147 }
148 
150  for (const auto& inDigis : input) {
151  edm::DetSet<SiStripDigi> suppressedDigis(inDigis.id);
152 
153  uint16_t nAPVflagged = 0;
154  nAPVflagged = algorithms->suppressHybridData(inDigis, suppressedDigis);
155 
156  storeExtraOutput(inDigis.id, nAPVflagged);
157  if (!suppressedDigis.empty())
158  output_base.push_back(std::move(suppressedDigis));
159  }
160 }
161 
163  edm::DetSet<SiStripRawDigi> outRawDigis(rawDigis.id);
164  outRawDigis.reserve(rawDigis.size());
165  const std::vector<bool>& apvf = algorithms->getAPVFlags();
166  uint32_t strip = 0;
167  for (const auto rawDigi : rawDigis) {
168  int16_t apvN = strip / 128;
169  if (apvf[apvN])
170  outRawDigis.push_back(rawDigi);
171  else
172  outRawDigis.push_back(SiStripRawDigi(0));
173  ++strip;
174  }
175  return outRawDigis;
176 }
177 
179  const std::vector<int16_t>& rawDigis) {
180  edm::DetSet<SiStripRawDigi> outRawDigis(detId);
181  outRawDigis.reserve(rawDigis.size());
182  const std::vector<bool>& apvf = algorithms->getAPVFlags();
183  uint32_t strip = 0;
184  for (const auto rawDigi : rawDigis) {
185  int16_t apvN = strip / 128;
186  if (apvf[apvN])
187  outRawDigis.push_back(SiStripRawDigi(rawDigi));
188  else
189  outRawDigis.push_back(SiStripRawDigi(0));
190  ++strip;
191  }
192  return outRawDigis;
193 }
194 
195 inline void SiStripZeroSuppression::storeExtraOutput(uint32_t id, int16_t nAPVflagged) {
196  const auto& vmedians = algorithms->getAPVsCM();
197  if (storeCM)
198  storeCMN(id, vmedians);
199  if (nAPVflagged > 0) {
201  storeBaseline(id, vmedians);
204  }
205 }
206 
207 inline void SiStripZeroSuppression::storeBaseline(uint32_t id, const medians_t& vmedians) {
208  const auto& baselinemap = algorithms->getBaselineMap();
209 
210  edm::DetSet<SiStripProcessedRawDigi> baselineDetSet(id);
211  baselineDetSet.reserve(vmedians.size() * 128);
212  for (const auto& vmed : vmedians) {
213  const uint16_t apvN = vmed.first;
214  const float median = vmed.second;
215  auto itBaselineMap = baselinemap.find(apvN);
216  if (baselinemap.end() == itBaselineMap) {
217  for (size_t strip = 0; strip < 128; ++strip)
218  baselineDetSet.push_back(SiStripProcessedRawDigi(median));
219  } else {
220  for (size_t strip = 0; strip < 128; ++strip)
221  baselineDetSet.push_back(SiStripProcessedRawDigi((itBaselineMap->second)[strip]));
222  }
223  }
224 
225  if (!baselineDetSet.empty())
226  output_baseline.push_back(baselineDetSet);
227 }
228 
230  edm::DetSet<SiStripDigi> baspointDetSet(id);
231  for (const auto& itBaselinePointVect : algorithms->getSmoothedPoints()) {
232  const uint16_t apvN = itBaselinePointVect.first;
233  for (const auto& itBaselinePointMap : itBaselinePointVect.second) {
234  const uint16_t bpstrip = itBaselinePointMap.first + apvN * 128;
235  const int16_t bp = itBaselinePointMap.second;
236  baspointDetSet.push_back(SiStripDigi(bpstrip, bp + 128));
237  }
238  }
239 
240  if (!baspointDetSet.empty())
241  output_baseline_points.push_back(std::move(baspointDetSet));
242 }
243 
244 inline void SiStripZeroSuppression::storeCMN(uint32_t id, const medians_t& vmedians) {
245  std::vector<bool> apvf(6, false);
246  if (fixCM) {
247  const auto& apvFlagged = algorithms->getAPVFlags();
248  std::copy(std::begin(apvFlagged), std::end(apvFlagged), std::begin(apvf));
249  }
250 
252  short apvNb = 0;
253  for (const auto& vmed : vmedians) {
254  if (vmed.first > apvNb) {
255  for (int i{0}; i < vmed.first - apvNb; ++i) {
256  apvDetSet.push_back(SiStripProcessedRawDigi(-999.));
257  apvNb++;
258  }
259  }
260 
261  if (fixCM && apvf[vmed.first]) {
262  apvDetSet.push_back(SiStripProcessedRawDigi(-999.));
263  } else {
264  apvDetSet.push_back(SiStripProcessedRawDigi(vmed.second));
265  }
266  apvNb++;
267  }
268 
269  if (!apvDetSet.empty())
270  output_apvcm.push_back(std::move(apvDetSet));
271 }
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:372
mps_fire.i
i
Definition: mps_fire.py:355
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:207
edm::DetSet< SiStripDigi >
SiStripRawProcessingFactory
Definition: SiStripRawProcessingFactory.h:14
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:244
SiStripRawDigi.h
SiStripZeroSuppression.h
edm::LogInfo
Definition: MessageLogger.h:254
SiStripZeroSuppression::formatRawDigis
edm::DetSet< SiStripRawDigi > formatRawDigis(const edm::DetSet< SiStripRawDigi > &rawDigis)
Definition: SiStripZeroSuppression.cc:162
SiStripZeroSuppression::output_base_raw
std::vector< edm::DetSet< SiStripRawDigi > > output_base_raw
Definition: SiStripZeroSuppression.h:53
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
edm::Handle
Definition: AssociativeIterator.h:50
end
#define end
Definition: vmac.h:39
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:149
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:97559
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:110
HLT_FULL_cff.storeCM
storeCM
Definition: HLT_FULL_cff.py:97599
SiStripZeroSuppression::fixCM
bool fixCM
Definition: SiStripZeroSuppression.h:41
SiStripDigi.h
HLT_FULL_cff.produceCalculatedBaseline
produceCalculatedBaseline
Definition: HLT_FULL_cff.py:97558
SiStripZeroSuppression::RawType::ScopeMode
HLT_FULL_cff.produceHybridFormat
produceHybridFormat
Definition: HLT_FULL_cff.py:97556
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:229
SiStripZeroSuppression::RawType::ProcessedRaw
edm::ParameterSet
Definition: ParameterSet.h:36
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:97557
SiStripZeroSuppression::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: SiStripZeroSuppression.cc:81
pfParticleNetPreprocessParams_cfi.median
median
Definition: pfParticleNetPreprocessParams_cfi.py:16
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:132
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:103
DetSetVector.h
HLT_FULL_cff.fixCM
fixCM
Definition: HLT_FULL_cff.py:97555
SiStripZeroSuppression::hybridInputs
std::vector< std::tuple< std::string, zstoken_t > > hybridInputs
Definition: SiStripZeroSuppression.h:50
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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:97600
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:122
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
SiStripZeroSuppression::storeExtraOutput
void storeExtraOutput(uint32_t, int16_t)
Definition: SiStripZeroSuppression.cc:195
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
begin
#define begin
Definition: vmac.h:32
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