RawDigitAdderAna.cxx
Go to the documentation of this file.
1 #ifndef MIX_RAWDIGITADDERANA_CXX
2 #define MIX_RAWDIGITADDERANA_CXX
3 
4 #include "RawDigitAdderAna.hh"
5 
6 #include <iostream>
7 #include <stdexcept>
8 #include <algorithm>
9 #include <sstream>
10 
12  std::vector<raw::ChannelID_t> special_channels,
13  bool print_bad,
14  std::string in1label,
15  std::string in2label,
16  std::string sumlabel)
17  : fChannelSampleInterval(sample),
18  fChannelsSpecial(special_channels),
19  fPrintBadOverlays(print_bad),
20  fInput1Label(in1label),
21  fInput2Label(in2label),
22  fSumLabel(sumlabel)
23 {
24 }
25 
27  fChannelsToPrint.clear();
28  fChannelsBadOverlay.clear();
29 }
30 
31 size_t mix::RawDigitAdderAna::CheckOverlay(std::vector<raw::RawDigit> const& in1,
32  std::vector<raw::RawDigit> const& in2,
33  std::vector<raw::RawDigit> const& sum)
34 {
35 
36  ResetOutput();
37 
38  //check size of all the rawdigit vectors
39  if(in1.size()!=in2.size() ||
40  in1.size()!=sum.size() )
41  throw std::runtime_error("Error in RawDigitAdderAna::CheckOverlay : Input vector lists not equal size.");
42 
43  for(size_t i_ch=0; i_ch<sum.size(); i_ch++){
44 
45  //check to make sure channels are same
46  if(in1[i_ch].Channel()!=in2[i_ch].Channel() ||
47  in1[i_ch].Channel()!=sum[i_ch].Channel())
48  throw std::runtime_error("Error in RawDigitAdderAna::CheckOverlay : Input vector lists out of order.");
49 
50  //check to make sure channels have same ADC vector
51  if(in1[i_ch].ADCs().size()!=in2[i_ch].ADCs().size() ||
52  in1[i_ch].ADCs().size()!=sum[i_ch].ADCs().size())
53  throw std::runtime_error("Error in RawDigitAdderAna::CheckOverlay : Input channels have different sizes.");
54 
55  bool print= ( (in1[i_ch].Channel()%fChannelSampleInterval==0) ||
56  (std::find(fChannelsSpecial.begin(),fChannelsSpecial.end(),in1[i_ch].Channel())!=fChannelsSpecial.end()) );
57 
58  for(size_t i_t=0; i_t<sum[i_ch].ADCs().size(); i_t++){
59  if( (in1[i_ch].ADCs()[i_t]+in2[i_ch].ADCs()[i_t])==sum[i_ch].ADCs()[i_t] )
60  continue;
61 
62  fChannelsBadOverlay.emplace_back(in1[i_ch].Channel());
63  if(fPrintBadOverlays) print=true;
64  break;
65  }
66 
67  if(print) fChannelsToPrint.emplace_back(in1[i_ch].Channel());
68 
69  }
70 
71  return fChannelsToPrint.size()*3;
72 
73 }
74 
76  raw::RawDigit const& waveform,
77  unsigned int run,
78  unsigned int event,
79  unsigned int channel,
81 {
82  std::stringstream hname,htitle;
83  hname << "h_" << label
84  << "_run" << run
85  << "_ev" << event
86  << "_ch" << channel;
87  htitle << "Waveform, Channel " << channel
88  << ", Event " << event
89  << ", Run " << run
90  << ", Input " << label;
91  histo->SetName(hname.str().c_str());
92  histo->SetTitle(htitle.str().c_str());
93  histo->SetBins(waveform.ADCs().size(),0,waveform.ADCs().size());
94 
95  for(size_t i_t=0; i_t<waveform.ADCs().size(); i_t++)
96  histo->SetBinContent(i_t,waveform.ADCs()[i_t]);
97 
98 }
99 
100 
101 void mix::RawDigitAdderAna::CreateOutputHistograms(std::vector<TH1S*> const histoPtrVector,
102  std::vector<raw::RawDigit> const& in1,
103  std::vector<raw::RawDigit> const& in2,
104  std::vector<raw::RawDigit> const& sum,
105  unsigned int run, unsigned int event)
106 {
107 
108  if(histoPtrVector.size()!=fChannelsToPrint.size())
109  throw std::runtime_error("Error in RawDigitAdderAna::CreateOutputHistograms : Histogram output vector not equal to channels to print.");
110 
111 
112  //check size of all the rawdigit vectors
113  if(in1.size()!=in2.size() ||
114  in1.size()!=sum.size() )
115  throw std::runtime_error("Error in RawDigitAdderAna::CheckOverlay : Input vector lists not equal size.");
116 
117  size_t histo_count=0;
118 
119  for(size_t i_ch=0; i_ch<sum.size(); i_ch++){
120 
121  //check to make sure channels are same
122  if(in1[i_ch].Channel()!=in2[i_ch].Channel() ||
123  in1[i_ch].Channel()!=sum[i_ch].Channel())
124  throw std::runtime_error("Error in RawDigitAdderAna::CheckOverlay : Input vector lists out of order.");
125 
126  if(std::find(fChannelsToPrint.begin(),fChannelsToPrint.end(),in1[i_ch].Channel())==fChannelsToPrint.end())
127  continue;
128 
129  //check to make sure channels have same ADC vector
130  if(in1[i_ch].ADCs().size()!=in2[i_ch].ADCs().size() ||
131  in1[i_ch].ADCs().size()!=sum[i_ch].ADCs().size())
132  throw std::runtime_error("Error in RawDigitAdderAna::CheckOverlay : Input channels have different sizes.");
133 
134  CreateHistogram(histoPtrVector.at(histo_count),
135  in1[i_ch],
136  run,event,in1[i_ch].Channel(),
137  fInput1Label);
138  histo_count++;
139  CreateHistogram(histoPtrVector.at(histo_count),
140  in2[i_ch],
141  run,event,in2[i_ch].Channel(),
142  fInput2Label);
143  histo_count++;
144  CreateHistogram(histoPtrVector.at(histo_count),
145  sum[i_ch],
146  run,event,sum[i_ch].Channel(),
147  fSumLabel);
148  histo_count++;
149 
150  }
151 
152 }
153 
154 #endif
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:210
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
std::string string
Definition: nybbler.cc:12
void CreateOutputHistograms(std::vector< TH1S * > const histoPtrVector, std::vector< raw::RawDigit > const &in1, std::vector< raw::RawDigit > const &in2, std::vector< raw::RawDigit > const &sum, unsigned int run, unsigned int event)
void CreateHistogram(TH1S *histo, raw::RawDigit const &waveform, unsigned int run, unsigned int event, unsigned int channel, std::string label)
std::vector< raw::ChannelID_t > fChannelsToPrint
std::vector< raw::ChannelID_t > fChannelsBadOverlay
RawDigitAdderAna(size_t sample=100, std::vector< raw::ChannelID_t > special_channels=std::vector< raw::ChannelID_t >(0), bool print_bad=true, std::string in1label="in1", std::string in2label="in2", std::string sumlabel="sum")
Default constructor.
std::vector< raw::ChannelID_t > fChannelsSpecial
ChannelMappingService::Channel Channel
size_t CheckOverlay(std::vector< raw::RawDigit > const &in1, std::vector< raw::RawDigit > const &in2, std::vector< raw::RawDigit > const &sum)
Event finding and building.
unsigned int run