CMS 3D CMS Logo

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