Pottu
RawHistogrammer.hpp
Go to the documentation of this file.
1 
6 #ifndef H_POTTU_RAWHISTOGRAMMER
7 #define H_POTTU_RAWHISTOGRAMMER
8 
9 
10 
12 
13 #include "DetectorEvent.hpp"
14 #include "ContextBase.hpp"
15 #include "DAQChannels.hpp"
16 #include "StageDetectorEvent.hpp"
17 
18 #include <vector>
19 
20 
21 namespace pottu {
22 
25  template <class EventOp = EventOpEnergy>
27  public:
28 
29  RawHistogrammer( EventOp eventOp )
30  : _ctxh( ContextBase::getActive().createHandle("RawHistogrammer") ),
31  _eventOp(eventOp),
32  _histos(4096)
33  {}
34 
44  void setHistogram( uint16_t ch, _histogram_1d_type *h ) {
45  _histos[ch] = h;
46  }
47 
48  _histogram_1d_type *getHistogram( uint16_t ch ) noexcept {
49  if( ch >= 4096 )
50  return nullptr;
51  return _histos[ch];
52  }
53 
54  void createAndSetHistogramsChannelInterval( _result_tree_type tree, const std::string &prefix,
55  uint16_t chFirst, uint16_t chLast,
56  double low, double high, unsigned int binc ) {
57  for( uint16_t ch = chFirst; ch < chLast; ++ch ) {
58  std::string name = fmt::format( "{}{:04d}", prefix, ch );
59  auto h1 = createHistogram1D( tree, name.c_str(), low, high, binc );
60  setHistogram( ch, h1 );
61  }
62  }
63 
73  template <class DAQCH>
74  void setGroup( DetectorEvent::group_type group, double low, double high, unsigned int binc,
75  const DAQCH &daqchannels, _result_tree_type tree ) {
76 
77  auto &g = daqchannels.getGroup( group );
78 
79  std::string hname = fmt::format("Raw histogram of group {}", g.getName() );
80  //auto h1 = tree->createHistogram1D( hname, low, high, binc );
81  auto h1 = createHistogram1D( tree, hname.c_str(), low, high, binc );
82 
83  const auto &chs = g.getChannels();
84  for( const auto &ch : chs )
85  setHistogram( ch, h1 );
86 
87  _ctxh->logInfo( fmt::format( "Assigned {} channels to raw group histogram for group \'{}\'.",
88  chs.size(), g.getName() ) );
89  }
90 
91  //template <class Cont>
92  virtual void process( std::vector<DetectorEvent> &data ) noexcept {
93  /*
94  static_assert( std::is_same<typename Cont::value_type,DetectorEvent>::value,
95  "RawHistogrammer requires DetectorEvent as a datapacket value_type" );
96  */
97  auto proci = _ctxh->processInstance();
98 
99  for( const auto &event : data ) {
100  if( _histos[event.ch] ) {
101  fill( _histos[event.ch], _eventOp(event) );
102  }
103  }
104  }
105 
106 
107  ContextHandle *_ctxh;
108 
109  EventOp _eventOp;
110  std::vector<_histogram_1d_type *> _histos;
111  };
112 
113 
114 
115 }
116 
117 
118 #endif
119 
Handle to context used by specific class.
Definition: ContextBase.hpp:188
Simple 1D histogram.
Definition: Histogram1D.hpp:26
Class holding tree of histograms and subtrees.
Definition: ObjectTree.hpp:44
Definition: RawHistogrammer.hpp:26
void setHistogram(uint16_t ch, _histogram_1d_type *h)
Sets individual histogram to a channel.
Definition: RawHistogrammer.hpp:44
virtual void process(std::vector< DetectorEvent > &data) noexcept
Uses or modifies detector events in a container.
Definition: RawHistogrammer.hpp:92
void setGroup(DetectorEvent::group_type group, double low, double high, unsigned int binc, const DAQCH &daqchannels, _result_tree_type tree)
Definition: RawHistogrammer.hpp:74
Abstract baseclass for all stages which uses or modifies detector events.
Definition: StageDetectorEvent.hpp:20
Definition: mainpage.dox:6
static ContextBase & getActive() noexcept
Returns active Context.
Definition: ContextBase.hpp:80