RawDigitMixer.cxx
Go to the documentation of this file.
1 #ifndef OVERLAY_DATAOVERLAY_RAWDIGITMIXER_CXX
2 #define OVERLAY_DATAOVERLAY_RAWDIGITMIXER_CXX
3 
4 #include "RawDigitMixer.h"
5 #include <limits>
6 #include <iostream>
7 #include <stdexcept>
8 #include <algorithm>
9 
10 void mix::RawDigitMixer::DeclareData(std::vector<raw::RawDigit> const& dataVector){
11 
12  fChannelIndexMap.clear();
13  fOutputWaveforms.clear();
14  fOutputWaveforms.resize(dataVector.size());
15 
16  for(size_t i_rd=0; i_rd<dataVector.size(); i_rd++){
17 
18  std::vector<short> waveform;
19  if(dataVector[i_rd].Compression()!=raw::kNone)
20  {
21  raw::Uncompress(dataVector[i_rd].ADCs(),
22  waveform,
23  dataVector[i_rd].GetPedestal(),
24  dataVector[i_rd].Compression());
25  }
26  else
27  {
28  waveform = dataVector[i_rd].ADCs();
29  }
30 
31  if (_datastart > waveform.size() || _dataend > waveform.size())
32  throw std::runtime_error("RawDigitMixer::DeclareData : Input data RawDigit shape does not match what is expected.");
33 
34  fChannelIndexMap[dataVector[i_rd].Channel()] = i_rd;
35 
36  //initialize adc vector for output
37  fOutputWaveforms[i_rd].waveform.resize(dataVector[i_rd].Samples(),0);
38  fOutputWaveforms[i_rd].channel = dataVector[i_rd].Channel();
39  fOutputWaveforms[i_rd].ped = dataVector[i_rd].GetPedestal();
40  fOutputWaveforms[i_rd].sigma = dataVector[i_rd].GetSigma();
41 
42 
43  //do the steps for filling that output vector
44  //This is data, so set scales to one.
45  fRDAdderAlg.SetScaleInputs(1.0,1.0);
47  fRDAdderAlg.AddRawDigits(waveform,fOutputWaveforms[i_rd].waveform);
48  }
49 
50 }
51 
52 void mix::RawDigitMixer::Mix(std::vector<raw::RawDigit> const& mcVector,
53  std::unordered_map<raw::ChannelID_t,float> const& scale_map){
54 
55  for( auto const& rd : mcVector){
56 
57  if(rd.Compression()!=raw::kNone)
58  throw std::runtime_error("Error in RawDigitMixer::Mix : Compressed MC waveforms not supported. Turn it off and try again.");
59 
60  if (_mcstart > rd.Samples() || _mcend > rd.Samples())
61  throw std::runtime_error("RawDigitMixer::Mix : Input MC RawDigit shape does not match what is expected.");
62 
63  auto it_ch = fChannelIndexMap.find(rd.Channel());
64 
65  //if this channel is not in the data, skip this channel!
66  if(it_ch==fChannelIndexMap.end())
67  continue;
68 
69  size_t i_output = it_ch->second;
70 
71  fRDAdderAlg.SetPedestalInputs(rd.GetPedestal(),0.0);
72  fRDAdderAlg.SetScaleInputs(scale_map.at(rd.Channel()),1.0);
74 
75  std::vector<short> const data_trimmed(fOutputWaveforms[i_output].waveform.begin()+_datastart,
76  fOutputWaveforms[i_output].waveform.begin()+_dataend);
77  std::vector<short> const mc_trimmed(rd.ADCs().begin()+_mcstart,
78  rd.ADCs().begin()+_mcend);
79  fRDAdderAlg.AddRawDigits(mc_trimmed,data_trimmed,fOutputWaveforms[i_output].waveform);
80  }
81 
82 }
83 
84 void mix::RawDigitMixer::FillRawDigitOutput(std::vector<raw::RawDigit> & output){
85 
86  for(auto const& rd_i : fOutputWaveforms){
87 
88  //now emplace back onto output collection...
89  output.emplace_back(rd_i.channel,
90  rd_i.waveform.size(),
91  rd_i.waveform);
92 
93  //set pedestal and rms to be same as data
94  output.back().SetPedestal(rd_i.ped,rd_i.sigma);
95  }
96 
97 }
98 
99 
100 #endif
void FillRawDigitOutput(std::vector< raw::RawDigit > &output)
Mixer function for putting together two raw digit collections.
RawDigitAdder_35t fRDAdderAlg
Definition: RawDigitMixer.h:83
no compression
Definition: RawTypes.h:9
void SetStuckBitRetentionMethod(bool s)
void SetScaleInputs(float f1, float f2)
void AddRawDigits(std::vector< short > const &, std::vector< short > const &, std::vector< short > &)
void SetPedestalInputs(float f1, float f2)
Definition: RawDigitAdder.h:52
void Mix(std::vector< raw::RawDigit > const &mcVector, std::unordered_map< raw::ChannelID_t, float > const &map)
std::unordered_map< raw::ChannelID_t, size_t > fChannelIndexMap
Definition: RawDigitMixer.h:81
void DeclareData(std::vector< raw::RawDigit > const &dataVector)
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:755
std::vector< RD_Info > fOutputWaveforms
Definition: RawDigitMixer.h:79