CMS 3D CMS Logo

SiStripClusterToDigiProducer.cc
Go to the documentation of this file.
6 
9 
13 
15 
17 #include "boost/foreach.hpp"
18 #include <numeric>
19 
21 
25 
26 
30 
31 
32 public:
33 
34  explicit SiStripClusterToDigiProducer(const edm::ParameterSet& conf);
35  void produce(edm::Event&, const edm::EventSetup&) override;
36 
37 private:
38 
39  void process(const ClusterCollection& input, std::vector<DetDigiCollection>& output_base);
40  void initialize(const edm::EventSetup& es);
41  void setDetId(const uint32_t id);
42  float gain(const uint16_t& strip) const { return gainHandle->getStripGain( strip, gainRange ); }
43  uint16_t applyGain(const uint16_t& strip,const uint16_t& adc );
44 
48  uint32_t gain_cache_id, detId;
49 
50 };
51 
52 
55 {
56 
57  token = consumes<ClusterCollection>(conf.getParameter<edm::InputTag>("ClusterProducer"));
58 
59  produces< DigiCollection > ("ZeroSuppressed");
60  produces< DigiCollection > ("VirginRaw" );
61  produces< DigiCollection > ("ProcessedRaw" );
62  produces< DigiCollection > ("ScopeMode" );
63 
64 }
65 
68 
69  initialize(es);
70 
71  std::vector<DetDigiCollection> output_base;
73  event.getByToken(token,input);
74 
75  if(input.isValid())
76  process(*input, output_base);
77 
78 
79  auto outputZS = std::make_unique<DigiCollection>(output_base);
80  auto outputVR = std::make_unique<DigiCollection>();
81  auto outputPR = std::make_unique<DigiCollection>();
82  auto outputSM = std::make_unique<DigiCollection>();
83 
84  event.put(std::move(outputZS), "ZeroSuppressed");
85  event.put(std::move(outputVR), "VirginRaw" );
86  event.put(std::move(outputPR), "ProcessedRaw" );
87  event.put(std::move(outputSM), "ScopeMode" );
88 }
89 
91 process(const ClusterCollection& input, std::vector<DetDigiCollection>& output_base) {
92 
93  for(ClusterCollection::const_iterator it = input.begin(); it!=input.end(); ++it) {
94 
95  uint32_t detid=it->detId();
96 
97  setDetId(detid);
98  DetDigiCollection detDigis(detid);
99 
100  DetClusIter clus(it->begin()), endclus(it->end());
101  for(;clus!=endclus;clus++){
102  size_t istrip = 0;
103  size_t width = clus->amplitudes().size();
104  size_t firstStrip = clus->firstStrip();
105  uint16_t stripPos=firstStrip;
106  for(;istrip<width;++istrip){
107  detDigis.data.push_back( SiStripDigi( stripPos, applyGain(stripPos,clus->amplitudes()[istrip]) ) );
108  stripPos++;
109  }
110  }
111 
112  if (!detDigis.empty())
113  output_base.push_back(detDigis);
114  }
115 }
116 
119  uint32_t g_cache_id = es.get<SiStripGainRcd>().cacheIdentifier();
120 
121  if(g_cache_id != gain_cache_id) {
122  es.get<SiStripGainRcd>().get( gainHandle );
123  gain_cache_id = g_cache_id;
124  }
125 }
126 
127 
128 inline
130 setDetId(const uint32_t id) {
131  gainRange = gainHandle->getRange(id);
132  detId = id;
133 }
134 
135 inline
137 applyGain(const uint16_t& strip,const uint16_t& adc ) {
138 
139  if(adc > 255) throw cms::Exception("Invalid Charge") << " digi at strip " << strip << " has ADC out of range " << adc;
140  if(adc > 253) return adc; //saturated, do not scale
141  uint16_t charge = static_cast<uint16_t>( adc*gain(strip) + 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
142  return ( charge > 1022 ? 255 :
143  ( charge > 253 ? 254 : charge ));
144 }
145 
146 
147 
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
edm::DetSetVector< SiStripDigi > DigiCollection
const_iterator end(bool update=false) const
edmNew::DetSet< SiStripCluster > DetClusterCollection
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
uint16_t applyGain(const uint16_t &strip, const uint16_t &adc)
data_type const * const_iterator
Definition: DetSetNew.h:30
edm::ESHandle< SiStripGain > gainHandle
float gain(const uint16_t &strip) const
static std::string const input
Definition: EdmProvDump.cc:44
void initialize(const edm::EventSetup &es)
static float getStripGain(const uint16_t &strip, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:72
std::pair< ContainerIterator, ContainerIterator > Range
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
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< ClusterCollection > token
edmNew::DetSetVector< SiStripCluster > ClusterCollection
void produce(edm::Event &, const edm::EventSetup &) override
void process(const ClusterCollection &input, std::vector< DetDigiCollection > &output_base)
edmNew::DetSet< SiStripCluster >::const_iterator DetClusIter
const T & get() const
Definition: EventSetup.h:59
SiStripClusterToDigiProducer(const edm::ParameterSet &conf)
collection_type data
Definition: DetSet.h:78
bool empty() const
Definition: DetSet.h:64
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
edm::DetSet< SiStripDigi >::const_iterator DetDigiIter
def move(src, dest)
Definition: eostools.py:510
const_iterator begin(bool update=false) const
Definition: event.py:1
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:70