KaliVeda
Toolkit for HIC analysis
KVGroup.cpp
1 #include "KVGroup.h"
2 #include "KVNucleus.h"
3 #include "KVList.h"
4 #include "KVDetector.h"
5 #include "KVNameValueList.h"
6 
7 using namespace std;
8 
10 
11 
12 
13 
16 {
17  init();
18 }
19 
20 
21 
22 
26 
28 {
29  // Default initialisation
30  // KVGroup does not own the structures which it groups together
31 
32  fReconstructedNuclei = 0;
33  SetType("GROUP");
34  SetOwnsDaughters(kFALSE);
35  fReconTraj.SetOwner();
36 }
37 
38 
39 
40 
42 
43 KVGroup::~KVGroup()
44 {
45  if (fReconstructedNuclei && fReconstructedNuclei->TestBit(kNotDeleted)) {
46  fReconstructedNuclei->Clear();
47  delete fReconstructedNuclei;
48  fReconstructedNuclei = 0;
49  }
50  fReconstructedNuclei = 0;
51  fTrajectories.Clear();
52 }
53 
54 
55 
56 
62 
64 {
65  //Reset the group, i.e. wipe the list of reconstructed nuclei and call "Reset" method of
66  //each and every detector in the group.
67  // The option 'opt' is passed to KVDetector::Reset
68 
69  //Info("Reset","Call %s",GetName());
70  if (fReconstructedNuclei && fReconstructedNuclei->GetSize()) {
71  fReconstructedNuclei->Clear();
72  }
73  //reset energy loss and KVDetector::IsAnalysed() state
74  //plus ACQParams set to zero if opt!="N" (for No Reset)
75  const_cast<KVSeqCollection*>(GetDetectors())->R__FOR_EACH(KVDetector, Reset)(opt);
76 }
77 
78 
79 
80 
82 
84 {
85  if (!fReconstructedNuclei) {
86  fReconstructedNuclei = new KVList(kFALSE);
87  fReconstructedNuclei->SetCleanup();
88  }
89  fReconstructedNuclei->Add(kvd);
90 }
91 
92 
93 
94 
98 
100 {
101  //Remove reconstructed nucleus from group's list of reconstructed
102  //particles.
103  if (fReconstructedNuclei) {
104  fReconstructedNuclei->Remove(kvd);
105  if (fReconstructedNuclei->GetSize() == 0) {
106  delete fReconstructedNuclei;
107  fReconstructedNuclei = 0;
108  }
109  }
110  else {
111  Warning("RemoveHit", "No reconstructed nuclei in this group");
112  }
113 }
114 
115 
116 
120 
122 {
123  // Loop over all detectors in group and clear their list of 'hits'
124  // i.e. the lists of particles which hit each detector
125  const_cast<KVSeqCollection*>(GetDetectors())->R__FOR_EACH(KVDetector, ClearHits)();
126 }
127 
128 
129 
135 
137 {
138  // Calculate all possible (sub-)trajectories
139  // for particle reconstruction (GetReconTrajectories())
140  //
141  // Returns number of (unique) trajectories in group
142 
143  fReconTraj.Clear();
144  TIter next_traj(GetTrajectories());
145  KVGeoDNTrajectory* traj;
146  while ((traj = (KVGeoDNTrajectory*)next_traj())) { // loop over all trajectories
147 
148  traj->IterateFrom(); // from furthest-out to closest-in detector
149 
151  while ((N = traj->GetNextNode())) {
152  fReconTraj.Add(KVGeoDNTrajectory::Factory("KVReconNucTrajectory", traj, N));
153  }
154  }
155 
156  // There may be trajectories with different names but identical titles
157  // (=physically same trajectories)
158  // We find the duplicates, delete them, and set up a map between the names of the
159  // duplicates and the name of the one remaining trajectory in the list
160  TList toRemove;
161  KVUniqueNameList unique_trajectories(kFALSE);//no replace
162  unique_trajectories.SetOwner();
163  fReconTrajMap.Clear();
164  TIter nxtRT(GetReconTrajectories());
165  KVGeoDNTrajectory* rnt;
166  while ((rnt = (KVGeoDNTrajectory*)nxtRT())) {
167 
168  TNamed* n = new TNamed(rnt->GetTitle(), rnt->GetName());
169  unique_trajectories.Add(n);
170  TNamed* orig = n;
171  if (!unique_trajectories.ObjectAdded()) {
172  orig = (TNamed*)unique_trajectories.FindObject(rnt->GetTitle());
173  toRemove.Add(rnt);
174  delete n;
175  }
176  // set up mapping from duplicate trajectory name to orginal trajectory name
177  fReconTrajMap.SetValue(rnt->GetName(), orig->GetTitle());
178 
179  }
180 
181  // now remove & delete the duplicates
182  TIter nxtDel(&toRemove);
183  while ((rnt = (KVGeoDNTrajectory*)nxtDel())) {
184  fReconTraj.Remove(rnt);
185  }
186  toRemove.Delete();
187 
188  return fReconTraj.GetEntries();
189 }
190 
191 
192 
195 
196 void KVGroup::PrintData() const
197 {
198  // list detectors of group with any data they contain
199  KVDetector* det;
200  TIter it(GetDetectors());
201  while ((det = (KVDetector*)it())) det->Print("data");
202 }
203 
204 
205 
int Int_t
constexpr Bool_t kFALSE
const char Option_t
#define R__FOR_EACH(type, proc)
#define N
Path taken by particles through multidetector geometry.
KVGeoDetectorNode * GetNextNode() const
static KVGeoDNTrajectory * Factory(const char *plugin, const KVGeoDNTrajectory *, const KVGeoDetectorNode *)
Instantiate & return object of class corresponding to plugin.
void IterateFrom(const KVGeoDetectorNode *node0=nullptr) const
Information on relative positions of detectors & particle trajectories.
Group of detectors which can be treated independently of all others in array.
Definition: KVGroup.h:19
void Reset(Option_t *opt="")
Definition: KVGroup.cpp:63
void init()
Definition: KVGroup.cpp:27
void ClearHitDetectors()
Definition: KVGroup.cpp:121
void AddHit(KVNucleus *kvd)
Definition: KVGroup.cpp:83
void RemoveHit(KVNucleus *kvd)
Definition: KVGroup.cpp:99
void PrintData() const
list detectors of group with any data they contain
Definition: KVGroup.cpp:196
Int_t CalculateReconstructionTrajectories()
Definition: KVGroup.cpp:136
Extended TList class which owns its objects by default.
Definition: KVList.h:28
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:123
KaliVeda extensions to ROOT collection classes.
TObject * FindObject(const char *name) const override
void SetOwner(Bool_t enable=kTRUE) override
Optimised list in which named objects can only be placed once.
Bool_t ObjectAdded() const
void Add(TObject *obj) override
void Add(TObject *obj) override
void Delete(Option_t *option="") override
const char * GetName() const override
const char * GetTitle() const override
const Int_t n
void Warning(const char *location, const char *fmt,...)
void init()
ClassImp(TPyArg)