|
16 | 16 | #include "DetectorsBase/Detector.h" |
17 | 17 | #include "DetectorsCommonDataFormats/DetID.h" |
18 | 18 | #include "SimulationDataFormat/MCTrack.h" |
| 19 | +#include "SimConfig/SimCutParams.h" |
19 | 20 |
|
20 | 21 | #include "FairDetector.h" // for FairDetector |
21 | 22 | #include "FairLogger.h" // for FairLogger |
@@ -245,6 +246,28 @@ void Stack::notifyFinishPrimary() |
245 | 246 | } |
246 | 247 | } |
247 | 248 |
|
| 249 | +// calculates a hash based on particle properties |
| 250 | +// hash may serve as seed for this track |
| 251 | +ULong_t getHash(TParticle const& p) |
| 252 | +{ |
| 253 | + auto asLong = [](double x) { |
| 254 | + return (ULong_t) * (reinterpret_cast<ULong_t*>(&x)); |
| 255 | + }; |
| 256 | + |
| 257 | + ULong_t hash; |
| 258 | + o2::MCTrackT<double> track(p); |
| 259 | + |
| 260 | + hash = asLong(track.GetStartVertexCoordinatesX()); |
| 261 | + hash ^= asLong(track.GetStartVertexCoordinatesY()); |
| 262 | + hash ^= asLong(track.GetStartVertexCoordinatesZ()); |
| 263 | + hash ^= asLong(track.GetStartVertexCoordinatesT()); |
| 264 | + hash ^= asLong(track.GetStartVertexMomentumX()); |
| 265 | + hash ^= asLong(track.GetStartVertexMomentumY()); |
| 266 | + hash ^= asLong(track.GetStartVertexMomentumZ()); |
| 267 | + hash += (ULong_t)track.GetPdgCode(); |
| 268 | + return hash; |
| 269 | +} |
| 270 | + |
248 | 271 | TParticle* Stack::PopNextTrack(Int_t& iTrack) |
249 | 272 | { |
250 | 273 | // This functions is mainly used by Geant3? |
@@ -276,6 +299,16 @@ TParticle* Stack::PopNextTrack(Int_t& iTrack) |
276 | 299 | mIndexOfCurrentTrack = mCurrentParticle.GetStatusCode(); |
277 | 300 | iTrack = mIndexOfCurrentTrack; |
278 | 301 |
|
| 302 | + if (o2::conf::SimCutParams::Instance().trackSeed) { |
| 303 | + auto hash = getHash(mCurrentParticle); |
| 304 | + // LOG(INFO) << "SEEDING NEW TRACK USING HASH" << hash; |
| 305 | + // init seed per track |
| 306 | + gRandom->SetSeed(hash); |
| 307 | + |
| 308 | + // NOTE: THE BETTER PLACE WOULD BE IN PRETRACK HOOK BUT THIS DOES NOT SEEM TO WORK |
| 309 | + // WORKS ONLY WITH G3 SINCE G4 DOES NOT CALL THIS FUNCTION |
| 310 | + } |
| 311 | + |
279 | 312 | // LOG(INFO) << "transporting ID " << mIndexOfCurrentTrack << "\n"; |
280 | 313 | return &mCurrentParticle; |
281 | 314 | } |
|
0 commit comments