CMS 3D CMS Logo

SiStripClusterToDigiProducer.cc
Go to the documentation of this file.
6 
9 
13 
15 
17 #include <numeric>
18 
23 
27 
28 public:
29  explicit SiStripClusterToDigiProducer(const edm::ParameterSet& conf);
30  void produce(edm::Event&, const edm::EventSetup&) override;
31 
32 private:
33  void process(const ClusterCollection& input, std::vector<DetDigiCollection>& output_base);
34  void setDetId(const uint32_t id);
35  float gain(const uint16_t& strip) const { return gain_->getStripGain(strip, gainRange); }
36  uint16_t applyGain(const uint16_t& strip, const uint16_t& adc);
37 
43  uint32_t detId;
44 };
45 
47  token = consumes<ClusterCollection>(conf.getParameter<edm::InputTag>("ClusterProducer"));
49 
50  produces<DigiCollection>("ZeroSuppressed");
51  produces<DigiCollection>("VirginRaw");
52  produces<DigiCollection>("ProcessedRaw");
53  produces<DigiCollection>("ScopeMode");
54 }
55 
57  if (gainWatcher_.check(es)) {
58  gain_ = &es.getData(gainToken_);
59  }
60 
61  std::vector<DetDigiCollection> output_base;
63  event.getByToken(token, input);
64 
65  if (input.isValid())
66  process(*input, output_base);
67 
68  auto outputZS = std::make_unique<DigiCollection>(output_base);
69  auto outputVR = std::make_unique<DigiCollection>();
70  auto outputPR = std::make_unique<DigiCollection>();
71  auto outputSM = std::make_unique<DigiCollection>();
72 
73  event.put(std::move(outputZS), "ZeroSuppressed");
74  event.put(std::move(outputVR), "VirginRaw");
75  event.put(std::move(outputPR), "ProcessedRaw");
76  event.put(std::move(outputSM), "ScopeMode");
77 }
78 
80  std::vector<DetDigiCollection>& output_base) {
81  for (ClusterCollection::const_iterator it = input.begin(); it != input.end(); ++it) {
82  uint32_t detid = it->detId();
83 
84  setDetId(detid);
85  DetDigiCollection detDigis(detid);
86 
87  DetClusIter clus(it->begin()), endclus(it->end());
88  for (; clus != endclus; clus++) {
89  size_t istrip = 0;
90  size_t width = clus->amplitudes().size();
91  size_t firstStrip = clus->firstStrip();
92  uint16_t stripPos = firstStrip;
93  for (; istrip < width; ++istrip) {
94  detDigis.data.push_back(SiStripDigi(stripPos, applyGain(stripPos, clus->amplitudes()[istrip])));
95  stripPos++;
96  }
97  }
98 
99  if (!detDigis.empty())
100  output_base.push_back(detDigis);
101  }
102 }
103 
104 inline void SiStripClusterToDigiProducer::setDetId(const uint32_t id) {
105  gainRange = gain_->getRange(id);
106  detId = id;
107 }
108 
109 inline uint16_t SiStripClusterToDigiProducer::applyGain(const uint16_t& strip, const uint16_t& adc) {
110  if (adc > 255)
111  throw cms::Exception("Invalid Charge") << " digi at strip " << strip << " has ADC out of range " << adc;
112  if (adc > 253)
113  return adc; //saturated, do not scale
114  uint16_t charge = static_cast<uint16_t>(
115  adc * gain(strip) +
116  0.5); //NB: here we revert the gain applied at the clusterizer level. for this reason the adc counts are multiplied by gain and not divided
117  return (charge > 1022 ? 255 : (charge > 253 ? 254 : charge));
118 }
119 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::DetSetVector< SiStripDigi > DigiCollection
edmNew::DetSet< SiStripCluster > DetClusterCollection
float gain(const uint16_t &strip) const
uint16_t applyGain(const uint16_t &strip, const uint16_t &adc)
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:75
edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
data_type const * const_iterator
Definition: DetSetNew.h:31
edm::ESWatcher< SiStripGainRcd > gainWatcher_
static std::string const input
Definition: EdmProvDump.cc:50
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:77
std::pair< ContainerIterator, ContainerIterator > Range
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
edm::DetSet< SiStripDigi > DetDigiCollection
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
edm::EDGetTokenT< ClusterCollection > token
edmNew::DetSetVector< SiStripCluster > ClusterCollection
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
void produce(edm::Event &, const edm::EventSetup &) override
void process(const ClusterCollection &input, std::vector< DetDigiCollection > &output_base)
edmNew::DetSet< SiStripCluster >::const_iterator DetClusIter
bool empty() const
Definition: DetSet.h:62
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
SiStripClusterToDigiProducer(const edm::ParameterSet &conf)
collection_type data
Definition: DetSet.h:80
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
edm::DetSet< SiStripDigi >::const_iterator DetDigiIter
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
uint16_t *__restrict__ uint16_t const *__restrict__ adc