@@ -52,10 +52,13 @@ using std::ios_base;
5252using std::ifstream;
5353using namespace o2 ::TPC ;
5454
55+ // #define NEWHIT 1
56+
5557Detector::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
275308void Detector::EndOfEvent ()
276309{
277-
310+ mHitGroupCollection -> Clear ();
278311 mPointCollection ->Clear ();
279312 ++mEventNr ;
280313}
281314
282-
283-
284315void 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-
298331TClonesArray* 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
304341void Detector::Reset ()
305342{
343+ #ifdef NEWHIT
344+ mHitGroupCollection ->Clear ();
345+ #else
306346 mPointCollection ->Clear ();
347+ #endif
307348}
308349
309350void Detector::ConstructGeometry ()
0 commit comments