Skip to content

Commit 44a30e4

Browse files
Sandro Wenzelsawenzel
authored andcommitted
Introduction of group of hits container for TPC
* a plain elemental hit class for the TPC * a container holding groups of hits This makes it possible to reduce the memory usage, because we do no longer have to derive from FairRoot bases classes for each individual hit.
1 parent 09cd77e commit 44a30e4

5 files changed

Lines changed: 104 additions & 9 deletions

File tree

Detectors/TPC/simulation/include/TPCSimulation/Detector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class Detector: public o2::Base::Detector {
121121

122122
/** container for data points */
123123
TClonesArray* mPointCollection;
124+
TClonesArray* mHitGroupCollection; //! container that keeps track-grouped hits
124125

125126
TString mGeoFileName; ///< Name of the file containing the TPC geometry
126127
size_t mEventNr; //!< current event number

Detectors/TPC/simulation/include/TPCSimulation/Point.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,59 @@
44
#define ALICEO2_TPC_POINT_H
55

66
#include "SimulationDataFormat/BaseHits.h"
7+
#include <vector>
78

89
namespace o2 {
910
namespace TPC {
1011

12+
// a minimal and plain TPC hit class
13+
class ElementalHit {
14+
public:
15+
Point3D<float> mPos; // cartesian position of Hit
16+
float mTime = -1; // time of flight
17+
float mELoss = -2; // energy loss
18+
19+
public:
20+
ElementalHit() = default; // for ROOT IO
21+
~ElementalHit() = default;
22+
23+
// constructor
24+
ElementalHit(float x, float y, float z, float time, float e)
25+
: mPos(x, y, z), mTime(time), mELoss(e) {}
26+
27+
ClassDefNV(ElementalHit,1);
28+
};
29+
30+
// a higher order hit class encapsulating
31+
// a set of elemental hits belonging to the same trackid (and sector)
32+
// construct used to do less MC truth linking and to save memory
33+
// this hitcontainer is linkable with FairLinks,
34+
// and can be stored as element of a TClonesArray into a branch
35+
class LinkableHitGroup : public o2::BaseHit {
36+
public:
37+
LinkableHitGroup() : mHits() {}
38+
39+
LinkableHitGroup(int trackID) : mHits() {
40+
SetTrackID(trackID);
41+
}
42+
43+
~LinkableHitGroup() override = default;
44+
45+
void addHit(float x, float y, float z, float time, float e) {
46+
mHits.emplace_back(x,y,z,time,e);
47+
}
48+
49+
size_t getSize() const {return mHits.size();}
50+
std::vector<o2::TPC::ElementalHit> const & getHitGroup() const { return mHits; }
51+
52+
public:
53+
std::vector<o2::TPC::ElementalHit> mHits; // the hits for this group
54+
// could think about AOS/SOA storage
55+
ClassDefOverride(LinkableHitGroup, 1);
56+
};
57+
1158
class Point : public o2::BasicXYZEHit<float>
1259
{
13-
1460
public:
1561

1662
/// Default constructor

Detectors/TPC/simulation/src/Detector.cxx

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ using std::ios_base;
5252
using std::ifstream;
5353
using namespace o2::TPC;
5454

55+
//#define NEWHIT 1
56+
5557
Detector::Detector()
5658
: o2::Base::Detector("TPC", kTRUE, kAliTpc),
5759
mSimulationType(SimulationType::Other),
5860
mPointCollection(new TClonesArray("o2::TPC::Point")),
61+
mHitGroupCollection(new TClonesArray("o2::TPC::LinkableHitGroup")),
5962
mGeoFileName(),
6063
mEventNr(0)
6164
{
@@ -65,6 +68,7 @@ Detector::Detector(const char* name, Bool_t active)
6568
: o2::Base::Detector(name, active, kAliTpc),
6669
mSimulationType(SimulationType::Other),
6770
mPointCollection(new TClonesArray("o2::TPC::Point")),
71+
mHitGroupCollection(new TClonesArray("o2::TPC::LinkableHitGroup")),
6872
mGeoFileName(),
6973
mEventNr(0)
7074
{
@@ -254,7 +258,36 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
254258
float time = refMC->TrackTime() * 1.0e09;
255259
int trackID = refMC->GetStack()->GetCurrentTrackNumber();
256260
int detID = vol->getMCid();
261+
262+
#ifdef NEWHIT
263+
static int oldTrackId = trackID;
264+
static int oldDetId = detID;
265+
static int groupCounter = 0;
266+
267+
// a new group is starting -> put it into the container
268+
static LinkableHitGroup *currentgroup = nullptr;
269+
if (groupCounter == 0) {
270+
TClonesArray& clref = *mHitGroupCollection;
271+
272+
// push-back in place
273+
Int_t size = clref.GetEntriesFast();
274+
currentgroup = new(clref[size]) LinkableHitGroup(trackID);
275+
276+
// set the MC truth link for this group
277+
currentgroup->SetLink(FairLink(-1, mEventNr, mMCTrackBranchId, trackID));
278+
}
279+
if ( trackID == oldTrackId && oldDetId == detID ){
280+
groupCounter++;
281+
currentgroup->addHit(position.X(), position.Y(), position.Z(), time, nel);
282+
}
283+
// finish group
284+
else {
285+
oldTrackId = trackID;
286+
groupCounter = 0;
287+
}
288+
#else
257289
addHit(position.X(), position.Y(), position.Z(), time, nel, trackID, detID);
290+
#endif
258291

259292
//LOG(INFO) << "TPC::AddHit" << FairLogger::endl
260293
//<< " -- " << trackNumberID <<"," << volumeID << " " << vol->GetName()
@@ -274,36 +307,44 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
274307

275308
void Detector::EndOfEvent()
276309
{
277-
310+
mHitGroupCollection->Clear();
278311
mPointCollection->Clear();
279312
++mEventNr;
280313
}
281314

282-
283-
284315
void Detector::Register()
285316
{
286-
287317
/** This will create a branch in the output tree called
288318
DetectorPoint, setting the last parameter to kFALSE means:
289319
this collection will not be written to the file, it will exist
290320
only during the simulation.
291321
*/
292-
293-
FairRootManager::Instance()->Register("TPCPoint", "TPC",mPointCollection, kTRUE);
294-
322+
auto *mgr=FairRootManager::Instance();
323+
#ifdef NEWHIT
324+
mgr->Register("TPCGroupedHits", "TPC", mHitGroupCollection, kTRUE);
325+
#else
326+
mgr->Register("TPCPoint", "TPC", mPointCollection, kTRUE);
327+
#endif
328+
mMCTrackBranchId=mgr->GetBranchId("MCTrack");
295329
}
296330

297-
298331
TClonesArray* Detector::GetCollection(Int_t iColl) const
299332
{
333+
#ifdef NEWHIT
334+
if (iColl == 0) { return mHitGroupCollection; }
335+
#else
300336
if (iColl == 0) { return mPointCollection; }
337+
#endif
301338
else { return nullptr; }
302339
}
303340

304341
void Detector::Reset()
305342
{
343+
#ifdef NEWHIT
344+
mHitGroupCollection->Clear();
345+
#else
306346
mPointCollection->Clear();
347+
#endif
307348
}
308349

309350
void Detector::ConstructGeometry()

Detectors/TPC/simulation/src/Point.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
12
#include "TPCSimulation/Point.h"
3+
#include <iostream>
24

35
using std::cout;
46
using std::endl;
@@ -15,3 +17,5 @@ void Point::Print(const Option_t* opt) const
1517
}
1618

1719
ClassImp(Point)
20+
ClassImp(LinkableHitGroup)
21+
ClassImp(ElementalHit)

Detectors/TPC/simulation/src/TPCSimulationLinkDef.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#pragma link C++ class o2::TPC::HwFixedPoint+;
3333
#pragma link C++ class o2::TPC::PadResponse+;
3434
#pragma link C++ class o2::TPC::Point+;
35+
#pragma link C++ class o2::TPC::ElementalHit+;
36+
#pragma link C++ class std::vector<o2::TPC::ElementalHit>+;
37+
#pragma link C++ class o2::TPC::LinkableHitGroup+;
3538
#pragma link C++ class o2::TPC::SAMPAProcessing+;
3639

3740
#endif

0 commit comments

Comments
 (0)