Classes | Public Member Functions | Private Types | Private Attributes | List of all members
CRT::OnlinePlotter< TFS > Class Template Reference

Classes

struct  ForeverPlots
 
struct  PerRunPlots
 

Public Member Functions

 OnlinePlotter (TFS &tfs, const double tickLength=16)
 
virtual ~OnlinePlotter ()
 
void ReactEndRun (const std::string &)
 
void ReactBeginRun (const std::string &)
 
void AnalyzeEvent (const std::vector< CRT::Trigger > &triggers)
 

Private Types

using DIRECTORY = decltype(fFileService->mkdir("test"))
 

Private Attributes

size_t fRunNum
 
TFS fFileService
 
std::unique_ptr< PerRunPlotsfCurrentRunPlots
 
PerRunPlots fWholeJobPlots
 
uint64_t fRunStartTime
 
uint64_t fRunStopTime
 
uint64_t fStartTotalTime
 
size_t fRunCounter
 
std::unordered_map< unsigned int, ForeverPlotsfUSBToForeverPlots
 
std::unordered_map< unsigned int, unsigned int > fModuleToUSB
 
const double fClockTicksToNs
 

Detailed Description

template<class TFS>
class CRT::OnlinePlotter< TFS >

Definition at line 31 of file OnlinePlotter.cpp.

Member Typedef Documentation

template<class TFS>
using CRT::OnlinePlotter< TFS >::DIRECTORY = decltype(fFileService->mkdir("test"))
private

Definition at line 201 of file OnlinePlotter.cpp.

Constructor & Destructor Documentation

template<class TFS>
CRT::OnlinePlotter< TFS >::OnlinePlotter ( TFS &  tfs,
const double  tickLength = 16 
)
inline

Definition at line 35 of file OnlinePlotter.cpp.

35  : fFileService(tfs), fWholeJobPlots(tfs->mkdir("PerJob")),
38  fRunCounter(0),
39  fModuleToUSB ({{0, 13},
40  {1, 13},
41  {2, 13},
42  {3, 13},
43  {4, 13},
44  {5, 13},
45  {6, 13},
46  {7, 13},
47  {8, 14},
48  {9, 14},
49  {10, 14},
50  {11, 14},
51  {12, 14},
52  {13, 14},
53  {14, 14},
54  {15, 14},
55  {16, 3},
56  {17, 3},
57  {18, 3},
58  {19, 3},
59  {20, 22},
60  {21, 22},
61  {22, 22},
62  {23, 22},
63  {24, 22},
64  {25, 22},
65  {26, 22},
66  {27, 22},
67  {28, 3},
68  {29, 3},
69  {30, 3},
70  {31, 3}}), fClockTicksToNs(tickLength)
71  {
72  //TODO: Get unordered_mapping from module to USB from some parameter passed to constructor
73  //TODO: Get tick length from parameter passed to constructor
74  }
const double fClockTicksToNs
static int max(int a, int b)
std::unordered_map< unsigned int, unsigned int > fModuleToUSB
PerRunPlots fWholeJobPlots
template<class TFS>
virtual CRT::OnlinePlotter< TFS >::~OnlinePlotter ( )
inlinevirtual

Definition at line 76 of file OnlinePlotter.cpp.

77  {
78  const auto deltaT = (fRunStopTime - fStartTotalTime)*fClockTicksToNs*1.e-9;
79  if(deltaT > 0)
80  {
81  fWholeJobPlots.fMeanRate->Scale(1./deltaT);
82  fWholeJobPlots.fMeanRatePerBoard->Scale(1./deltaT);
83  }
84  }
const double fClockTicksToNs
const double e
PerRunPlots fWholeJobPlots

Member Function Documentation

template<class TFS>
void CRT::OnlinePlotter< TFS >::AnalyzeEvent ( const std::vector< CRT::Trigger > &  triggers)
inline

Definition at line 153 of file OnlinePlotter.cpp.

154  {
155  for(const auto& trigger: triggers)
156  {
157  const auto timestamp = trigger.Timestamp();
158  if(timestamp > 1e16)
159  {
160  //Update time bounds based on this timestamp
161  if(timestamp < fRunStartTime)
162  {
163  //std::cout << "fRunStartTime=" << fRunStartTime << " is >= " << timestamp << ", so setting fRunStartTime.\n";
164  fRunStartTime = timestamp;
165  }
166  if(timestamp > fRunStopTime)
167  {
168  //std::cout << "fRunStopTime=" << fRunStopTime << " is <= " << timestamp << ", so setting fRunStopTime.\n";
169  fRunStopTime = timestamp;
170  }
171  if(timestamp < fStartTotalTime)
172  {
173  //std::cout << "fStartTotalTime=" << fStartTotalTime << " is >= " << timestamp << ", so setting fStartTotalTime.\n";
174  fStartTotalTime = timestamp;
175  }
176 
177  const auto module = trigger.Channel();
178  const auto& hits = trigger.Hits();
179  for(const auto& hit: hits)
180  {
181  const auto channel = hit.Channel();
182  fCurrentRunPlots->fMeanRate->Fill(channel, module);
183  fCurrentRunPlots->fMeanADC->Fill(channel, module, hit.ADC());
184  fCurrentRunPlots->fMeanADCPerBoard->Fill(module, hit.ADC());
185 
186  fWholeJobPlots.fMeanRate->Fill(channel, module);
187  fWholeJobPlots.fMeanADC->Fill(channel, module, hit.ADC());
188  fWholeJobPlots.fMeanADCPerBoard->Fill(module, hit.ADC());
189  }
190  fCurrentRunPlots->fMeanRatePerBoard->Fill(module);
191  fWholeJobPlots.fMeanRatePerBoard->Fill(module);
192  } //If UNIX timestamp is not 0
193  }
194  }
uint8_t channel
Definition: CRTFragment.hh:201
Detector simulation of raw signals on wires.
std::unique_ptr< PerRunPlots > fCurrentRunPlots
PerRunPlots fWholeJobPlots
template<class TFS>
void CRT::OnlinePlotter< TFS >::ReactBeginRun ( const std::string )
inline

Definition at line 140 of file OnlinePlotter.cpp.

141  {
142  //const uint64_t totalDeltaTInSeconds = (fRunStopTime - fStartTotalTime)*fClockTicksToNs*1.e-9; //TODO: replace with tick length from constructor
143  fCurrentRunPlots.reset(new PerRunPlots(fFileService->mkdir("Run"+std::to_string(++fRunCounter))));
144  //TODO: The above directory name is not guaranteed to be unique, and art::TFileDirectory's only mechanism for
145  // reacting to that situation seems to be catching a cet::exception from whenver the internal cd() method is
146  // called. I need to either find a way to deal with this problem or stop making plots per-file.
147  // One way to deal with this is by going back to "run number" directory labels.
148 
150  fRunStopTime = 0;
151  }
static int max(int a, int b)
std::unique_ptr< PerRunPlots > fCurrentRunPlots
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
template<class TFS>
void CRT::OnlinePlotter< TFS >::ReactEndRun ( const std::string )
inline

Definition at line 86 of file OnlinePlotter.cpp.

87  {
88  //Scale all rate histograms here with total elapsed time in run
89  const auto deltaT = (fRunStopTime-fRunStartTime)*1e-9*fClockTicksToNs; //Convert ticks from timestamp into seconds
90  //TODO: Use tick length from constructor
91  const auto totalDeltaTInSeconds = (fRunStopTime - fStartTotalTime)*fClockTicksToNs*1.e-9; //TODO: replace with tick length from constructor
92  if(deltaT > 0)
93  {
94  //TODO: Remove cout for LArSoft compatibility
95  std::cout << "Elapsed time for this run is " << deltaT << " seconds. Total elapsed time is " << totalDeltaTInSeconds << " seconds.\n";
96  std::cout << "Beginning of all time was " << (uint64_t)(fStartTotalTime*fClockTicksToNs*1.e-9) << ", beginning of run was "
97  << (uint64_t)(fRunStartTime*fClockTicksToNs*1.e-9) << ", and end of run was " << (uint64_t)(fRunStopTime*fClockTicksToNs*1.e-9) << "\n";
98  const auto timeInv = 1./deltaT;
99  fCurrentRunPlots->fMeanRate->Scale(timeInv);
100  fCurrentRunPlots->fMeanRatePerBoard->Scale(timeInv);
101  }
102 
103  //Fill histograms that profile over board or USB number
104  const auto nChannels = fCurrentRunPlots->fMeanRate->GetXaxis()->GetNbins();
105  const auto nModules = fCurrentRunPlots->fMeanRate->GetYaxis()->GetNbins();
106  std::unordered_map<unsigned int, size_t> usbToHits; //USB bins of number of hits
107  for(auto channel = 0; channel < nChannels; ++channel)
108  {
109  for(auto module = 0; module < nModules; ++module)
110  {
111  const auto count = fCurrentRunPlots->fMeanRate->GetBinContent(fCurrentRunPlots->fMeanRate->GetBin(channel, module));
112 
113  const auto foundUSB = fModuleToUSB.find(module);
114  if(foundUSB != fModuleToUSB.end())
115  {
116  const auto usb = foundUSB->second;
117  auto found = fUSBToForeverPlots.find(usb);
118  if(found == fUSBToForeverPlots.end())
119  {
120  found = fUSBToForeverPlots.emplace(usb, fFileService->mkdir("USB"+std::to_string(usb))).first;
121  }
122 
123  auto& forever = found->second;
124  usbToHits[usb] += count;
125  forever.fMeanADC->Fill(totalDeltaTInSeconds,
126  fCurrentRunPlots->fMeanADC->GetBinContent(fCurrentRunPlots->fMeanADC->GetBin(channel, module)));
127  } //If found a USB for this module
128  } //For each module in mean rate/ADC plots
129  } //For each channel in mean rate/ADC plots
130  if(deltaT > 0)
131  {
132  for(const auto bin: usbToHits)
133  {
134  const auto found = fUSBToForeverPlots.find(bin.first);
135  if(found != fUSBToForeverPlots.end()) found->second.fMeanRate->Fill(totalDeltaTInSeconds, bin.second);
136  }
137  }
138  }
std::unordered_map< unsigned int, ForeverPlots > fUSBToForeverPlots
const double fClockTicksToNs
uint8_t channel
Definition: CRTFragment.hh:201
const double e
std::unordered_map< unsigned int, unsigned int > fModuleToUSB
std::unique_ptr< PerRunPlots > fCurrentRunPlots
QTextStream & bin(QTextStream &s)
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34

Member Data Documentation

template<class TFS>
const double CRT::OnlinePlotter< TFS >::fClockTicksToNs
private

Definition at line 262 of file OnlinePlotter.cpp.

template<class TFS>
std::unique_ptr<PerRunPlots> CRT::OnlinePlotter< TFS >::fCurrentRunPlots
private

Definition at line 234 of file OnlinePlotter.cpp.

template<class TFS>
TFS CRT::OnlinePlotter< TFS >::fFileService
private

Definition at line 200 of file OnlinePlotter.cpp.

template<class TFS>
std::unordered_map<unsigned int, unsigned int> CRT::OnlinePlotter< TFS >::fModuleToUSB
private

Definition at line 261 of file OnlinePlotter.cpp.

template<class TFS>
size_t CRT::OnlinePlotter< TFS >::fRunCounter
private

Definition at line 239 of file OnlinePlotter.cpp.

template<class TFS>
size_t CRT::OnlinePlotter< TFS >::fRunNum
private

Definition at line 198 of file OnlinePlotter.cpp.

template<class TFS>
uint64_t CRT::OnlinePlotter< TFS >::fRunStartTime
private

Definition at line 236 of file OnlinePlotter.cpp.

template<class TFS>
uint64_t CRT::OnlinePlotter< TFS >::fRunStopTime
private

Definition at line 237 of file OnlinePlotter.cpp.

template<class TFS>
uint64_t CRT::OnlinePlotter< TFS >::fStartTotalTime
private

Definition at line 238 of file OnlinePlotter.cpp.

template<class TFS>
std::unordered_map<unsigned int, ForeverPlots> CRT::OnlinePlotter< TFS >::fUSBToForeverPlots
private

Definition at line 258 of file OnlinePlotter.cpp.

template<class TFS>
PerRunPlots CRT::OnlinePlotter< TFS >::fWholeJobPlots
private

Definition at line 235 of file OnlinePlotter.cpp.


The documentation for this class was generated from the following file: