KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVGroup.cpp
Go to the documentation of this file.
1 #include "Riostream.h"
2 #include "KVGroup.h"
3 #include "KVNucleus.h"
4 #include "KVList.h"
5 #include "KVDetector.h"
6 #include "KVLayer.h"
7 #include "TROOT.h"
8 #include "KVNameValueList.h"
9 
10 using namespace std;
11 
13 
14 
15 
16 
19 {
20  init();
21 }
22 
23 
24 
25 
29 
31 {
32  // Default initialisation
33  // KVGroup does not own the structures which it groups together
34 
35  fReconstructedNuclei = 0;
36  SetType("GROUP");
37  SetOwnsDaughters(kFALSE);
38  fReconTraj.SetOwner();
39 }
40 
41 
42 
43 
45 
46 KVGroup::~KVGroup()
47 {
48  if (fReconstructedNuclei && fReconstructedNuclei->TestBit(kNotDeleted)) {
49  fReconstructedNuclei->Clear();
50  delete fReconstructedNuclei;
51  fReconstructedNuclei = 0;
52  }
53  fReconstructedNuclei = 0;
54  fTrajectories.Clear();
55 }
56 
57 
58 
63 
65 {
66  // The number of detector layers is the maximum number of detectors in the
67  // group which are placed one in front of the other, i.e. we interrogate
68  // each detector as to how many detectors there are in front of it
69 
70  UInt_t max = 0;
71  TIter next(GetDetectors());
72  KVDetector* d;
73  while ((d = (KVDetector*)next())) {
74  UInt_t e = d->GetAlignedDetectors()->GetEntries();
75  if (e > max) max = e;
76  }
77  return max;
78 }
79 
80 
81 
87 
89 {
90  // lay=1 : create and fill list with detectors closest to target
91  // lay=GetNumberOfDetectorLayers() : detectors furthest from target
92  //
93  // Delete TList after use!
94 
95  TList* dets = new TList;
96  TIter next(GetDetectors());
97  KVDetector* d;
98 
99  while ((d = (KVDetector*)next())) {
100  if (lay == (UInt_t)d->GetAlignedDetectors()->GetEntries()) dets->Add(d);
101  }
102  return dets;
103 }
104 
105 
106 
107 
113 
115 {
116  //Reset the group, i.e. wipe the list of reconstructed nuclei and call "Reset" method of
117  //each and every detector in the group.
118  // The option 'opt' is passed to KVDetector::Reset
119 
120  //Info("Reset","Call %s",GetName());
121  if (fReconstructedNuclei && fReconstructedNuclei->GetSize()) {
122  fReconstructedNuclei->Clear();
123  }
124  //reset energy loss and KVDetector::IsAnalysed() state
125  //plus ACQParams set to zero if opt!="N" (for No Reset)
126  const_cast<KVSeqCollection*>(GetDetectors())->R__FOR_EACH(KVDetector, Reset)(opt);
127 }
128 
129 
130 
131 
133 
135 {
136  if (!fReconstructedNuclei) {
137  fReconstructedNuclei = new KVList(kFALSE);
138  fReconstructedNuclei->SetCleanup();
139  }
140  fReconstructedNuclei->Add(kvd);
141 }
142 
143 
144 
145 
149 
151 {
152  //Remove reconstructed nucleus from group's list of reconstructed
153  //particles.
154  if (fReconstructedNuclei) {
155  fReconstructedNuclei->Remove(kvd);
156  if (fReconstructedNuclei->GetSize() == 0) {
157  delete fReconstructedNuclei;
158  fReconstructedNuclei = 0;
159  }
160  }
161  else {
162  Warning("RemoveHit", "No reconstructed nuclei in this group");
163  }
164 }
165 
166 
167 
176 
178 {
179  //Fill TList with all detectors aligned with "det" which are closer to the target.
180  //These are the detectors through which any particle stopping in "det" will have
181  //to pass. By default (dir=KVGroup::kBackwards) the list starts with "det" and
182  //goes towards the target. Use dir=KVGroup::kForwards to have the list in the
183  //order seen by an impinging particle.
184  //
185  //Delete TList after use.
186 
187  TList* tmp = new TList;
188 
189  while (det) {
190  tmp->Add(det);
191  KVGeoDetectorNode* node = det->GetNode();
192  KVSeqCollection* infront = node->GetDetectorsInFront();
193  if (!infront) break;
194  if (infront->GetEntries() > 1) {
195  Warning("GetAlignedDetectors",
196  "No unique solution. There are %d detectors in front of %s.",
197  infront->GetEntries(), det->GetName());
198  infront->ls();
199  }
200  det = (KVDetector*)infront->First();
201  }
202 
203  if (dir == kForwards) {
204  TIter next(tmp, kIterBackward);
205  TList* tmp2 = new TList;
206  while ((det = (KVDetector*)next())) tmp2->Add(det);
207  delete tmp;
208  tmp = tmp2;
209  }
210  return tmp;
211 }
212 
213 
214 
215 
216 
217 
221 
223 {
224  // Loop over all detectors in group and clear their list of 'hits'
225  // i.e. the lists of particles which hit each detector
226  const_cast<KVSeqCollection*>(GetDetectors())->R__FOR_EACH(KVDetector, ClearHits)();
227 }
228 
229 
230 
236 
238 {
239  // Calculate all possible (sub-)trajectories
240  // for particle reconstruction (GetReconTrajectories())
241  //
242  // Returns number of (unique) trajectories in group
243 
244  fReconTraj.Clear();
245  TIter next_traj(GetTrajectories());
246  KVGeoDNTrajectory* traj;
247  while ((traj = (KVGeoDNTrajectory*)next_traj())) { // loop over all trajectories
248 
249  traj->IterateFrom(); // from furthest-out to closest-in detector
250 
252  while ((N = traj->GetNextNode())) {
253  fReconTraj.Add(KVGeoDNTrajectory::Factory("KVReconNucTrajectory", traj, N));
254  }
255  }
256 
257  // There may be trajectories with different names but identical titles
258  // (=physically same trajectories)
259  // We find the duplicates, delete them, and set up a map between the names of the
260  // duplicates and the name of the one remaining trajectory in the list
261  TList toRemove;
262  KVUniqueNameList unique_trajectories(kFALSE);//no replace
263  unique_trajectories.SetOwner();
264  fReconTrajMap.Clear();
265  TIter nxtRT(GetReconTrajectories());
266  KVGeoDNTrajectory* rnt;
267  while ((rnt = (KVGeoDNTrajectory*)nxtRT())) {
268 
269  TNamed* n = new TNamed(rnt->GetTitle(), rnt->GetName());
270  unique_trajectories.Add(n);
271  TNamed* orig = n;
272  if (!unique_trajectories.ObjectAdded()) {
273  orig = (TNamed*)unique_trajectories.FindObject(rnt->GetTitle());
274  toRemove.Add(rnt);
275  delete n;
276  }
277  // set up mapping from duplicate trajectory name to orginal trajectory name
278  fReconTrajMap.SetValue(rnt->GetName(), orig->GetTitle());
279 
280  }
281 
282  // now remove & delete the duplicates
283  TIter nxtDel(&toRemove);
284  while ((rnt = (KVGeoDNTrajectory*)nxtDel())) {
285  fReconTraj.Remove(rnt);
286  }
287  toRemove.Delete();
288 
289  return fReconTraj.GetEntries();
290 }
291 
292 
293 
296 
297 void KVGroup::PrintData() const
298 {
299  // list detectors of group with any data they contain
300  KVDetector* det;
301  TIter it(GetDetectors());
302  while ((det = (KVDetector*)it())) det->Print("data");
303 }
304 
305 
306 
int Int_t
unsigned int UInt_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define d(i)
#define e(i)
unsigned char UChar_t
const Bool_t kFALSE
const char Option_t
const Bool_t kIterBackward
#define R__FOR_EACH(type, proc)
#define N
Base class for detector geometry description.
Definition: KVDetector.h:159
KVGeoDetectorNode * GetNode()
Definition: KVDetector.h:325
virtual void Print(Option_t *option="") const
Definition: KVDetector.cpp:364
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.
KVSeqCollection * GetDetectorsInFront() const
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:114
virtual TList * GetAlignedDetectors(KVDetector *, UChar_t dir=kBackwards)
Definition: KVGroup.cpp:177
void init()
Definition: KVGroup.cpp:30
virtual TList * GetDetectorsInLayer(UInt_t lay)
Definition: KVGroup.cpp:88
virtual UInt_t GetNumberOfDetectorLayers()
Definition: KVGroup.cpp:64
void ClearHitDetectors()
Definition: KVGroup.cpp:222
void AddHit(KVNucleus *kvd)
Definition: KVGroup.cpp:134
void RemoveHit(KVNucleus *kvd)
Definition: KVGroup.cpp:150
void PrintData() const
list detectors of group with any data they contain
Definition: KVGroup.cpp:297
Int_t CalculateReconstructionTrajectories()
Definition: KVGroup.cpp:237
Extended TList class which owns its objects by default.
Definition: KVList.h:27
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:125
KaliVeda extensions to ROOT collection classes.
virtual void SetOwner(Bool_t enable=kTRUE)
virtual TObject * First() const
virtual TObject * FindObject(const char *name) const
Optimised list in which named objects can only be placed once.
Bool_t ObjectAdded() const
virtual void Add(TObject *obj)
virtual void ls(Option_t *option="") const
virtual Int_t GetEntries() const
virtual void Add(TObject *obj)
virtual void Delete(Option_t *option="")
virtual const char * GetName() const
virtual const char * GetTitle() const
const Int_t n
void Warning(const char *location, const char *va_(fmt),...)