CMS 3D CMS Logo

SiStripProcessedRawDigiProducer.cc
Go to the documentation of this file.
1 // system includes
2 #include <functional>
3 #include <memory>
4 #include <string>
5 
6 // user includes
24 
26 public:
28 
29 private:
30  void produce(edm::Event& e, const edm::EventSetup& es) override;
31  template <class T>
33 
36  const SiStripGain&);
39  const SiStripGain&);
42  const SiStripGain&);
43  void common_process(const uint32_t,
44  std::vector<float>&,
46  const SiStripGain&);
47 
48  const std::vector<edm::InputTag> inputTags_;
49  const std::vector<edm::EDGetTokenT<edm::DetSetVector<SiStripDigi> > > inputTokensDigi_;
50  const std::vector<edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> > > inputTokensRawDigi_;
52 
53  std::unique_ptr<SiStripPedestalsSubtractor> subtractorPed_;
54  std::unique_ptr<SiStripCommonModeNoiseSubtractor> subtractorCMN_;
55 };
56 
58  : inputTags_(conf.getParameter<std::vector<edm::InputTag> >("DigiProducersList")),
59  inputTokensDigi_(edm::vector_transform(
60  inputTags_, [this](edm::InputTag const& tag) { return consumes<edm::DetSetVector<SiStripDigi> >(tag); })),
61  inputTokensRawDigi_(edm::vector_transform(
62  inputTags_, [this](edm::InputTag const& tag) { return consumes<edm::DetSetVector<SiStripRawDigi> >(tag); })),
63  gainToken_(esConsumes()),
64  subtractorPed_(SiStripRawProcessingFactory::create_SubtractorPed(conf, consumesCollector())),
65  subtractorCMN_(SiStripRawProcessingFactory::create_SubtractorCMN(conf, consumesCollector())) {
66  produces<edm::DetSetVector<SiStripProcessedRawDigi> >("");
67 }
68 
70  std::unique_ptr<edm::DetSetVector<SiStripProcessedRawDigi> > output(new edm::DetSetVector<SiStripProcessedRawDigi>());
73 
74  const auto& gain = es.getData(gainToken_);
75  subtractorPed_->init(es);
76  subtractorCMN_->init(es);
77 
78  std::string label = findInput(inputRawdigis, inputTokensRawDigi_, e);
79  if ("VirginRaw" == label)
80  vr_process(*inputRawdigis, *output, gain);
81  else if ("ProcessedRaw" == label)
82  pr_process(*inputRawdigis, *output, gain);
83  else if ("ZeroSuppressed" == findInput(inputDigis, inputTokensDigi_, e))
85  else
86  edm::LogError("Input Not Found");
87 
88  e.put(std::move(output));
89 }
90 
91 template <class T>
93  const std::vector<edm::EDGetTokenT<T> >& tokens,
94  const edm::Event& e) {
95  for (typename std::vector<edm::EDGetTokenT<T> >::const_iterator token = tokens.begin(); token != tokens.end();
96  ++token) {
97  unsigned index(token - tokens.begin());
98  e.getByToken(*token, handle);
99  if (handle.isValid() && !handle->empty()) {
100  edm::LogInfo("Input") << inputTags_.at(index);
101  return inputTags_.at(index).instance();
102  }
103  }
104  return "Input Not Found";
105 }
106 
109  const SiStripGain& gain) {
110  std::vector<float> digis;
111  for (const auto& detset : input) {
112  digis.clear();
113  for (const auto& digi : detset) {
114  digis.resize(digi.strip(), 0);
115  digis.push_back(digi.adc());
116  }
117  common_process(detset.id, digis, output, gain);
118  }
119 }
120 
123  const SiStripGain& gain) {
124  for (const auto& detset : input) {
125  std::vector<float> digis;
126  transform(
127  detset.begin(), detset.end(), back_inserter(digis), std::bind(&SiStripRawDigi::adc, std::placeholders::_1));
128  subtractorCMN_->subtract(detset.id, 0, digis);
129  common_process(detset.id, digis, output, gain);
130  }
131 }
132 
135  const SiStripGain& gain) {
136  for (const auto& detset : input) {
137  std::vector<int16_t> int_digis(detset.size());
138  subtractorPed_->subtract(detset, int_digis);
139  std::vector<float> digis(int_digis.begin(), int_digis.end());
140  subtractorCMN_->subtract(detset.id, 0, digis);
141  common_process(detset.id, digis, output, gain);
142  }
143 }
144 
146  std::vector<float>& digis,
148  const SiStripGain& gain) {
149  //Apply Gains
150  SiStripApvGain::Range detGainRange = gain.getRange(detId);
151  for (auto& it : digis)
152  it /= (gain.getStripGain(it - *digis.begin(), detGainRange));
153 
154  //Insert as DetSet
156  copy(digis.begin(), digis.end(), back_inserter(ds.data));
157  output.insert(ds);
158 }
159 
162 
const edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void zs_process(const edm::DetSetVector< SiStripDigi > &, edm::DetSetVector< SiStripProcessedRawDigi > &, const SiStripGain &)
const std::vector< edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > > inputTokensRawDigi_
void common_process(const uint32_t, std::vector< float > &, edm::DetSetVector< SiStripProcessedRawDigi > &, const SiStripGain &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< SiStripCommonModeNoiseSubtractor > subtractorCMN_
const std::vector< edm::InputTag > inputTags_
Log< level::Error, false > LogError
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
uint16_t adc() const
std::string findInput(edm::Handle< T > &handle, const std::vector< edm::EDGetTokenT< T > > &tokens, const edm::Event &e)
static std::string const input
Definition: EdmProvDump.cc:47
static std::unique_ptr< SiStripCommonModeNoiseSubtractor > create_SubtractorCMN(const edm::ParameterSet &, edm::ConsumesCollector)
char const * label
const std::vector< edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > > inputTokensDigi_
SiStripProcessedRawDigiProducer(edm::ParameterSet const &)
std::pair< ContainerIterator, ContainerIterator > Range
void pr_process(const edm::DetSetVector< SiStripRawDigi > &, edm::DetSetVector< SiStripProcessedRawDigi > &, const SiStripGain &)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
static std::unique_ptr< SiStripPedestalsSubtractor > create_SubtractorPed(const edm::ParameterSet &, edm::ConsumesCollector)
void produce(edm::Event &e, const edm::EventSetup &es) override
Log< level::Info, false > LogInfo
collection_type data
Definition: DetSet.h:80
HLT enums.
std::unique_ptr< SiStripPedestalsSubtractor > subtractorPed_
void vr_process(const edm::DetSetVector< SiStripRawDigi > &, edm::DetSetVector< SiStripProcessedRawDigi > &, const SiStripGain &)
def move(src, dest)
Definition: eostools.py:511
unsigned transform(const HcalDetId &id, unsigned transformCode)