ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtEvent.h
Go to the documentation of this file.
1 #ifndef AtEVENT_H
2 #define AtEVENT_H
3 // IWYU pragma: no_include <ext/alloc_traits.h>
4 
5 #include "AtBaseEvent.h"
6 #include "AtHit.h"
7 
8 #include <FairLogger.h>
9 
10 #include <Rtypes.h>
11 
12 #include <array>
13 #include <map>
14 #include <memory>
15 #include <type_traits>
16 #include <utility>
17 #include <vector>
18 class TBuffer;
19 class TClass;
20 class TMemberInspector;
21 
22 class AtEvent : public AtBaseEvent {
23 public:
24  using TraceArray = std::array<Float_t, 512>;
25  using HitPtr = std::unique_ptr<AtHit>;
26  using HitVector = std::vector<HitPtr>;
27 
28 private:
29  Double_t fEventCharge = -100;
30  Double_t fRhoVariance = 0;
31 
32  HitVector fHitArray;
33  std::map<Int_t, Int_t> fMultiplicityMap;
34 
35  TraceArray fMeshSig{};
36 
37 public:
38  AtEvent();
39  AtEvent(const AtEvent &copy);
40  AtEvent(const AtBaseEvent &copy) : AtBaseEvent(copy) { SetName("AtEvent"); }
41  AtEvent &operator=(const AtEvent object);
42  virtual ~AtEvent() = default;
43 
44  friend void swap(AtEvent &first, AtEvent &second)
45  {
46  using std::swap;
47  swap(dynamic_cast<AtBaseEvent &>(first), dynamic_cast<AtBaseEvent &>(second));
48 
49  swap(first.fEventCharge, second.fEventCharge);
50  swap(first.fRhoVariance, second.fRhoVariance);
51 
52  swap(first.fHitArray, second.fHitArray);
53  swap(first.fMultiplicityMap, second.fMultiplicityMap);
54  swap(first.fMeshSig, second.fMeshSig);
55  }
56 
57  void Clear(Option_t *opt = nullptr) override;
58 
69  template <typename... Ts>
70  AtHit &AddHit(Ts &&...params)
71  {
72  fHitArray.emplace_back(std::make_unique<AtHit>(std::forward<Ts>(params)...));
73  if (fHitArray.back()->GetHitID() == -1)
74  fHitArray.back()->SetHitID(fHitArray.size() - 1);
75  LOG(debug) << "Adding hit with ID " << fHitArray.back()->GetHitID() << " to event " << fEventID;
76 
77  return *(fHitArray.back());
78  }
79 
90  template <typename T, typename = std::enable_if_t<std::is_base_of<AtHit, std::decay_t<T>>::value>>
91  AtHit &AddHit(std::unique_ptr<T> ptr)
92  {
93  fHitArray.push_back(std::move(ptr));
94  if (fHitArray.back()->GetHitID() == -1)
95  fHitArray.back()->SetHitID(fHitArray.size() - 1);
96  LOG(debug) << "Adding hit with ID " << fHitArray.back()->GetHitID() << " to event " << fEventID;
97 
98  return *(fHitArray.back());
99  }
100 
101  void SetEventCharge(Double_t Qevent) { fEventCharge = Qevent; }
102  void SetRhoVariance(Double_t RhoVariance) { fRhoVariance = RhoVariance; }
103 
104  void SetMultiplicityMap(std::map<Int_t, Int_t> MultiMap) { fMultiplicityMap = std::move(MultiMap); }
105  void SetMeshSignal(TraceArray mesharray) { fMeshSig = std::move(mesharray); }
106  void SetMeshSignal(Int_t idx, Float_t val);
107 
108  Int_t GetNumHits() const { return fHitArray.size(); }
109  Double_t GetEventCharge() const { return fEventCharge; }
110  Double_t GetRhoVariance() const { return fRhoVariance; }
111  const TraceArray &GetMesh() const { return fMeshSig; }
112  Int_t GetHitPadMult(Int_t PadNum); // Returns the multiplicity of the pad where this hit belongs to
113 
114  const AtHit &GetHit(Int_t hitNo) const { return *fHitArray.at(hitNo); }
115  [[deprecated("Use GetHits()")]] std::vector<AtHit> GetHitArray() const;
116  const HitVector &GetHits() const { return fHitArray; }
117  void ClearHits() { fHitArray.clear(); }
118  const std::map<Int_t, Int_t> &GetMultiMap() { return fMultiplicityMap; }
119 
120  void SortHitArray();
121  void SortHitArrayID();
122  void SortHitArrayTime();
123 
125 };
126 
127 #endif
AtBaseEvent::fEventID
ULong_t fEventID
Definition: AtBaseEvent.h:24
AtEvent::GetEventCharge
Double_t GetEventCharge() const
Definition: AtEvent.h:109
AtEvent::SortHitArray
void SortHitArray()
Definition: AtEvent.cxx:52
swap
void swap(AtPad &a, AtPad &b) noexcept
Definition: AtPad.cxx:22
AtEvent::GetHit
const AtHit & GetHit(Int_t hitNo) const
Definition: AtEvent.h:114
AtEvent::GetNumHits
Int_t GetNumHits() const
Definition: AtEvent.h:108
AtBaseEvent.h
AtEvent::SetRhoVariance
void SetRhoVariance(Double_t RhoVariance)
Definition: AtEvent.h:102
AtEvent::Clear
void Clear(Option_t *opt=nullptr) override
Definition: AtEvent.cxx:28
AtEvent::AddHit
AtHit & AddHit(Ts &&...params)
Create a new hit in this event. Adds a new hit, calling a constructor of AtHit using the passed param...
Definition: AtEvent.h:70
AtEvent::AtEvent
AtEvent(const AtBaseEvent &copy)
Definition: AtEvent.h:40
AtEvent::SetMultiplicityMap
void SetMultiplicityMap(std::map< Int_t, Int_t > MultiMap)
Definition: AtEvent.h:104
AtEvent::SortHitArrayTime
void SortHitArrayTime()
Definition: AtEvent.cxx:63
AtEvent::swap
friend void swap(AtEvent &first, AtEvent &second)
Definition: AtEvent.h:44
AtEvent::GetHitPadMult
Int_t GetHitPadMult(Int_t PadNum)
Definition: AtEvent.cxx:43
AtHit::SetHitID
void SetHitID(Int_t hitID)
Definition: AtHit.h:67
AtEvent
Definition: AtEvent.h:22
AtEvent::~AtEvent
virtual ~AtEvent()=default
AtEvent::GetHitArray
std::vector< AtHit > GetHitArray() const
Definition: AtEvent.cxx:69
AtEvent::TraceArray
std::array< Float_t, 512 > TraceArray
Definition: AtEvent.h:24
AtHit.h
AtEvent::GetHits
const HitVector & GetHits() const
Definition: AtEvent.h:116
AtBaseEvent
Base class for all event types in ATTPCROOT.
Definition: AtBaseEvent.h:20
AtEvent::ClassDefOverride
ClassDefOverride(AtEvent, 6)
AtEvent::AddHit
AtHit & AddHit(std::unique_ptr< T > ptr)
Move a hit into this event. Adds a new hit, moving a unique pointer in. Will set the hitID to the nex...
Definition: AtEvent.h:91
AtEvent::GetMesh
const TraceArray & GetMesh() const
Definition: AtEvent.h:111
AtEvent::SetEventCharge
void SetEventCharge(Double_t Qevent)
Definition: AtEvent.h:101
AtEvent::GetMultiMap
const std::map< Int_t, Int_t > & GetMultiMap()
Definition: AtEvent.h:118
AtEvent::operator=
AtEvent & operator=(const AtEvent object)
Definition: AtEvent.cxx:22
AtEvent::HitPtr
std::unique_ptr< AtHit > HitPtr
Definition: AtEvent.h:25
AtEvent::AtEvent
AtEvent()
Definition: AtEvent.cxx:12
AtEvent::SortHitArrayID
void SortHitArrayID()
Definition: AtEvent.cxx:57
AtEvent::GetRhoVariance
Double_t GetRhoVariance() const
Definition: AtEvent.h:110
AtEvent::SetMeshSignal
void SetMeshSignal(TraceArray mesharray)
Definition: AtEvent.h:105
AtEvent::HitVector
std::vector< HitPtr > HitVector
Definition: AtEvent.h:26
AtEvent::ClearHits
void ClearHits()
Definition: AtEvent.h:117
AtHit
Point in space with charge.
Definition: AtHit.h:27