OpDetWaveformMixer.cxx
Go to the documentation of this file.
1 #ifndef OVERLAY_DATAOVERLAY_OPDETWAVEFORMMIXER_CXX
2 #define OVERLAY_DATAOVERLAY_OPDETWAVEFORMMIXER_CXX
3 
4 #include "OpDetWaveformMixer.h"
5 #include <limits>
6 #include <iostream>
7 #include <stdexcept>
8 #include <algorithm>
9 
10 
11 void mix::OpDetWaveformMixer::DeclareData(std::vector<raw::OpDetWaveform> const& dataVector,
12  std::vector<raw::OpDetWaveform> & outputVector){
13 
14  fChannelIndexMap.clear();
15  outputVector.reserve(dataVector.size());
16 
17  for(auto const& od : dataVector){
18 
19 
20  outputVector.emplace_back(od);
21 
22  if(od.size() < fMinSampleSize) continue;
23 
24  //we're going to keep the longest one ... JUST handling beam gate stuff for now
25  auto my_channel = fChannelIndexMap.find(od.ChannelNumber());
26  if( my_channel != fChannelIndexMap.end() && outputVector[my_channel->second].size() > od.size())
27  continue;
28 
29  fChannelIndexMap[od.ChannelNumber()] = outputVector.size()-1;
30 
31  }
32 
33 }
34 
35 void mix::OpDetWaveformMixer::Mix(std::vector<raw::OpDetWaveform> const& mcVector,
36  std::unordered_map<raw::Channel_t,float> const& scale_map,
37  std::vector<raw::OpDetWaveform> & outputVector){
38 
39 
40  for( auto const& od : mcVector){
41 
42  if(od.size() < fMinSampleSize) continue;
43 
44  auto it_ch = fChannelIndexMap.find(od.ChannelNumber());
45 
46  //if this channel is not in the data, skip this channel!
47  if(it_ch==fChannelIndexMap.end())
48  continue;
49 
50  size_t i_output = it_ch->second;
51 
52  fRDAdderAlg.SetPedestalInputs(2048,0.0); //HARDCODED PEDESTAL AT 2048!!!!!!!
53  fRDAdderAlg.SetScaleInputs(scale_map.at(od.ChannelNumber()),1.0);
54 
55  //If the sizes are not the same...
56  if(od.size() != outputVector[i_output].size()){
57 
58  if(_printWarnings)
59  std::cout << "WARNING! Two collections don't have same number of samples:\t"
60  << outputVector[i_output].size() << " " << od.size() << std::endl;
61 
62  //if the samples is larger, we make a new vector of the right size, trimmed down appropriately
63  if(od.size() > outputVector[i_output].size()){
64  std::vector<short> const& mc_trimmed = std::vector<short>(od.begin(),
65  od.begin()+outputVector[i_output].size());
66  fRDAdderAlg.AddRawDigits(mc_trimmed,outputVector[i_output]);
67  }
68  //if the samples is shorter, pad it out with the pedestal
69  else if(od.size() < outputVector[i_output].size()){
70  std::vector<short> mc_trimmed(outputVector[i_output].size(),0.0);
71  std::copy(od.begin(),od.end(),mc_trimmed.begin());
72  fRDAdderAlg.AddRawDigits(mc_trimmed,outputVector[i_output]);
73  }
74  }
75  //Sizes are the same? Easy!
76  else{
77  fRDAdderAlg.AddRawDigits(od,outputVector[i_output]);
78  }
79  }
80 
81 }
82 
83 #endif
Mixer function for putting together two raw digit collections.
std::unordered_map< raw::Channel_t, size_t > fChannelIndexMap
void DeclareData(std::vector< raw::OpDetWaveform > const &dataVector, std::vector< raw::OpDetWaveform > &outputVector)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
void AddRawDigits(std::vector< short > const &, std::vector< short > const &, std::vector< short > &)
void SetPedestalInputs(float f1, float f2)
Definition: RawDigitAdder.h:52
RawDigitAdder_HardSaturate fRDAdderAlg
T copy(T const &v)
void Mix(std::vector< raw::OpDetWaveform > const &mcVector, std::unordered_map< raw::Channel_t, float > const &map, std::vector< raw::OpDetWaveform > &outputVector)
QTextStream & endl(QTextStream &s)