DriftResponse.cxx
Go to the documentation of this file.
1 // \file PCHit.h
2 // \brief A DriftResponse contains the basic information from cosmic track data needed for calibration.
3 // \version $Id: DriftResponse.cxx,v 1.0 2013/01/13 22:06:10 rtoner Exp $
4 // \author $Author: rtoner $
5 // \date $Date: 2013/01/13 22:06:10 $
6 
8 #include <iostream>
9 #include <iomanip>
10 
11 namespace caldp
12 {
13 
14  //------------------------------------------------------------
15  void MeanStruct::SetResponse( double fMean, double fMeanErr, double fRMS, int fNHits ){
16  mean = fMean;
17  meanerr = fMeanErr;
18  rms = fRMS;
19  nhits = fNHits;
20  }
21 
22 
23  //------------------------------------------------------------
25  run (-1),
26  startTime(0),
27  endTime (0)
28  { }
29 
30 
31  //------------------------------------------------------------
32  DriftResponse::DriftResponse(int fRun, uint32_t fStartTime, uint32_t fEndTime):
33  run (fRun),
34  startTime(fStartTime),
35  endTime (fEndTime)
36  { }
37 
38 
39  //------------------------------------------------------------
41 
42 
43  //------------------------------------------------------------
44  void DriftResponse::AddChannelResponse ( int fOffChan, double fMean, double fMeanErr, double fRMS, int fNHits ){
45 
46  if ( meanMap.find(fOffChan) == meanMap.end() ) {
47 
48  MeanStruct meanResp;
49 
50  meanResp.SetResponse(fMean,fMeanErr,fRMS,fNHits);
51 
52  //Insert a new entry into the map.
53  meanMap.insert(std::make_pair(fOffChan,meanResp));
54  } else {
55  std::cout << "Print an error message here about the entry already existing." << std::endl;
56  }
57  } //End AddChannelResponse
58 
59 
60  //------------------------------------------------------------
61  bool DriftResponse::GetChannelResponse ( int fOffChan, double &fMean, double &fMeanErr, double &fRMS, int &fNHits ) const {
62 
63  fMean = -1;
64  fMeanErr = -1;
65  fRMS = -1;
66  fNHits = -1;
67 
68  if ( meanMap.find(fOffChan) == meanMap.end() ) {
69  return false;
70  }
71 
72  const MeanStruct meanResp = meanMap.at(fOffChan);
73 
74  fMean = meanResp.Mean();
75  fMeanErr = meanResp.MeanErr();
76  fRMS = meanResp.RMS();
77  fNHits = meanResp.NHits();
78 
79  return true;
80 
81 
82  } //End AddChannelResp
83 
84  //------------------------------------------------------------
85  double DriftResponse::Mean (int fOffChan) const {
86 
87  double fMean = -1;
88 
89  if ( meanMap.find(fOffChan) != meanMap.end() ) {
90  const MeanStruct meanAtChan = meanMap.at(fOffChan);
91  fMean = meanAtChan.Mean();
92  }
93 
94  return fMean;
95 
96  }
97 
98  //------------------------------------------------------------
99  double DriftResponse::MeanErr (int fOffChan) const {
100 
101  double fMeanErr = -1;
102 
103  if ( meanMap.find(fOffChan) != meanMap.end() ) {
104  const MeanStruct meanAtChan = meanMap.at(fOffChan);
105  fMeanErr = meanAtChan.MeanErr();
106  }
107 
108  return fMeanErr;
109 
110  }
111 
112  //------------------------------------------------------------
113  double DriftResponse::RMS (int fOffChan) const {
114 
115  double fRMS = -1;
116 
117  if ( meanMap.find(fOffChan) != meanMap.end() ) {
118  const MeanStruct meanAtChan = meanMap.at(fOffChan);
119  fRMS = meanAtChan.RMS();
120  }
121 
122  return fRMS;
123 
124  }
125 
126  //------------------------------------------------------------
127  double DriftResponse::NHits (int fOffChan) const {
128 
129  double fNHits = -1;
130 
131  if ( meanMap.find(fOffChan) != meanMap.end() ) {
132  const MeanStruct meanAtChan = meanMap.at(fOffChan);
133  fNHits = meanAtChan.NHits();
134  }
135 
136  return fNHits;
137 
138  }
139 
140 
141  //------------------------------------------------------------
142  bool DriftResponse::CheckForChannel ( int fOffChan ) const {
143 
144  if ( meanMap.find(fOffChan) == meanMap.end() ) return false;
145 
146  return true;
147 
148  }
149 
150 
151  //------------------------------------------------------------
152  std::ostream& operator<< (std::ostream& o, const DriftResponse& dr)
153  {
154  o << std::setiosflags(std::ios::fixed) << std::setprecision(2);
155  o << "Run = " << std::setw(1) << std::right << dr.Run()
156  << " StartTime = " << std::setw(1) << std::right << dr.StartTime()
157  << " EndTime = " << std::setw(3) << std::right << dr.EndTime();
158 
159  MeanStruct firstChan = dr.ReturnMap().begin()->second;
160 
161  o << "\nResponse for channel " << dr.ReturnMap().begin()->first << " is"
162  << "\n\tMean: " << firstChan.Mean()
163  << "\n\tMeanErr: " << firstChan.MeanErr()
164  << "\n\tRMS: " << firstChan.RMS()
165  << "\n\tNHits: " << firstChan.NHits()
166  << std::endl;
167 
168  return o;
169  }
170 
171 
172 } // end namespace caldp
Structure to hold drift response in a single channel at a single time.
Definition: DriftResponse.h:36
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
void AddChannelResponse(int fOffChan, double fMean, double fMeanErr, double fRMS, int fNHits)
Return subrun end time.
int NHits() const
Return rms of distribution.
Definition: DriftResponse.h:29
std::map< int, MeanStruct > meanMap
End time of the run period.
Definition: DriftResponse.h:73
uint32_t startTime
Run number.
Definition: DriftResponse.h:70
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
double MeanErr(int fOffChan) const
Return mean for given offline channel.
bool GetChannelResponse(int fOffChan, double &fMean, double &fMeanErr, double &fRMS, int &fNHits) const
Check for existence of channel in DriftResponse.
double meanerr
Mean response.
Definition: DriftResponse.h:22
double RMS() const
Return error on mean.
Definition: DriftResponse.h:28
double Mean() const
Number of hits in mean calculation.
Definition: DriftResponse.h:26
double rms
Error on mean response.
Definition: DriftResponse.h:23
uint32_t endTime
Start time of the run period.
Definition: DriftResponse.h:71
void SetResponse(double fMean, double fMeanErr, double fRMS, int fNHits)
Return number of hits in distribution.
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
Histograms used by attenuation calibration.
uint32_t EndTime() const
Return subrun start time.
Definition: DriftResponse.h:48
uint32_t StartTime() const
Return run number.
Definition: DriftResponse.h:47
std::map< int, MeanStruct > const & ReturnMap() const
Definition: DriftResponse.h:61
bool CheckForChannel(int fOffChan) const
Return number of hits for given offline channel.
double NHits(int fOffChan) const
Return rms for given offline channel.
double Mean(int fOffChan) const
Function to add response value for single channel;.
double MeanErr() const
Return mean.
Definition: DriftResponse.h:27
int nhits
Error on mean response.
Definition: DriftResponse.h:24
double RMS(int fOffChan) const
Return mean error for given offline channel.
friend std::ostream & operator<<(std::ostream &o, const DriftResponse &dr)