Skip to content

Commit aa893c9

Browse files
committed
GPU QA: Add option to dump / read also O2 MC track information
1 parent c2fb406 commit aa893c9

File tree

5 files changed

+196
-103
lines changed

5 files changed

+196
-103
lines changed

GPU/GPUTracking/Global/GPUChainTracking.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ int GPUChainTracking::PrepareEvent()
405405

406406
int GPUChainTracking::ForceInitQA()
407407
{
408+
if (!mQA) {
409+
mQA.reset(new GPUQA(this));
410+
}
408411
return mQA->InitQA();
409412
}
410413

GPU/GPUTracking/Interface/GPUO2Interface.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ int GPUO2Interface::RunTracking(GPUTrackingInOutPointers* data, GPUInterfaceOutp
9898
mChain->DumpData(fname);
9999
if (nEvent == 0) {
100100
mRec->DumpSettings();
101+
#ifdef GPUCA_BUILD_QA
102+
if (mConfig->configProcessing.runMC) {
103+
mChain->ForceInitQA();
104+
sprintf(fname, "mc.%d.dump", nEvent);
105+
mChain->GetQA()->DumpO2MCData(fname);
106+
}
107+
#endif
101108
}
102109
nEvent++;
103110
if (mConfig->configInterface.dumpEvents >= 2) {

GPU/GPUTracking/Standalone/Benchmark/standalone.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,18 @@ int ReadEvent(int n)
492492
if (r) {
493493
return r;
494494
}
495+
#if defined(GPUCA_TPC_GEOMETRY_O2) && defined(GPUCA_BUILD_QA) && !defined(GPUCA_O2_LIB)
496+
if (configStandalone.proc.runQA && !configStandalone.QA.noMC) {
497+
chainTracking->ForceInitQA();
498+
snprintf(filename, 256, "events/%s/mc.%d.dump", configStandalone.EventsDir, n);
499+
if (chainTracking->GetQA()->ReadO2MCData(filename)) {
500+
snprintf(filename, 256, "events/%s/mc.%d.dump", configStandalone.EventsDir, 0);
501+
if (chainTracking->GetQA()->ReadO2MCData(filename)) {
502+
throw std::runtime_error("Error reading O2 MC dump");
503+
}
504+
}
505+
}
506+
#endif
495507
if (chainTracking->mIOPtrs.clustersNative && (configStandalone.TF.bunchSim || configStandalone.TF.nMerge || !configStandalone.runTransformation)) {
496508
if (configStandalone.proc.debugLevel >= 2) {
497509
printf("Converting Native to Legacy ClusterData for overlaying - WARNING: No raw clusters produced - Compression etc will not run!!!\n");

GPU/GPUTracking/qa/GPUQA.cxx

Lines changed: 164 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ static constexpr Color_t defaultColorNUms[COLORCOUNT] = {kRed, kBlue, kGreen, kM
204204

205205
#define TRACK_EXPECTED_REFERENCE_X_DEFAULT 81
206206
#ifdef GPUCA_TPC_GEOMETRY_O2
207-
inline unsigned int GPUQA::GetNMCCollissions()
207+
inline unsigned int GPUQA::GetNMCCollissions() const
208208
{
209209
return mNColTracks.size();
210210
}
211-
inline unsigned int GPUQA::GetNMCTracks(int iCol) { return mNColTracks[iCol]; }
212-
inline unsigned int GPUQA::GetNMCLabels() { return mClNative->clustersMCTruth ? mClNative->clustersMCTruth->getIndexedSize() : 0; }
211+
inline unsigned int GPUQA::GetNMCTracks(int iCol) const { return mNColTracks[iCol]; }
212+
inline unsigned int GPUQA::GetNMCLabels() const { return mClNative->clustersMCTruth ? mClNative->clustersMCTruth->getIndexedSize() : 0; }
213213
inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(unsigned int iTrk, unsigned int iCol) { return mMCInfos[iCol][iTrk]; }
214214
inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(const mcLabel_t& label) { return mMCInfos[label.getEventID()][label.getTrackID()]; }
215215
inline GPUQA::mcLabels_t GPUQA::GetMCLabel(unsigned int i) { return mClNative->clustersMCTruth->getLabels(i); }
@@ -231,9 +231,9 @@ inline GPUQA::mcLabelI_t::mcLabelI_t(const GPUQA::mcLabel_t& l) : track(l.fMCID)
231231
{
232232
}
233233
inline bool GPUQA::mcLabelI_t::operator==(const GPUQA::mcLabel_t& l) { return AbsLabelID(track) == l.fMCID; }
234-
inline unsigned int GPUQA::GetNMCCollissions() { return 1; }
235-
inline unsigned int GPUQA::GetNMCTracks(int iCol) { return mTracking->mIOPtrs.nMCInfosTPC; }
236-
inline unsigned int GPUQA::GetNMCLabels() { return mTracking->mIOPtrs.nMCLabelsTPC; }
234+
inline unsigned int GPUQA::GetNMCCollissions() const { return 1; }
235+
inline unsigned int GPUQA::GetNMCTracks(int iCol) const { return mTracking->mIOPtrs.nMCInfosTPC; }
236+
inline unsigned int GPUQA::GetNMCLabels() const { return mTracking->mIOPtrs.nMCLabelsTPC; }
237237
inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(unsigned int iTrk, unsigned int iCol) { return mTracking->mIOPtrs.mcInfosTPC[AbsLabelID(iTrk)]; }
238238
inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(const mcLabel_t& label) { return GetMCTrack(label.fMCID, 0); }
239239
inline const GPUQA::mcInfo_t& GPUQA::GetMCTrack(const mcLabelI_t& label) { return GetMCTrack(label.track, 0); }
@@ -555,6 +555,147 @@ int GPUQA::loadHistograms(std::vector<TH1F>& i1, std::vector<TH2F>& i2, std::vec
555555
return 0;
556556
}
557557

558+
void GPUQA::DumpO2MCData(const char* filename) const
559+
{
560+
FILE* fp = fopen(filename, "w+b");
561+
if (fp == nullptr) {
562+
return;
563+
}
564+
unsigned int n = GetNMCCollissions();
565+
fwrite(&n, sizeof(n), 1, fp);
566+
for (unsigned int i = 0; i < n; i++) {
567+
unsigned int nn = GetNMCTracks(i);
568+
fwrite(&nn, sizeof(nn), 1, fp);
569+
fwrite(mMCInfos[i].data(), sizeof(mMCInfos[i][0]), nn, fp);
570+
}
571+
fclose(fp);
572+
}
573+
574+
int GPUQA::ReadO2MCData(const char* filename)
575+
{
576+
FILE* fp = fopen(filename, "rb");
577+
if (fp == nullptr) {
578+
return 1;
579+
}
580+
unsigned int n;
581+
unsigned int x;
582+
if ((x = fread(&n, sizeof(n), 1, fp)) != 1) {
583+
fclose(fp);
584+
return 1;
585+
}
586+
mNColTracks.resize(n);
587+
mMCInfos.resize(GetNMCCollissions());
588+
for (unsigned int i = 0; i < n; i++) {
589+
unsigned int nn = GetNMCTracks(i);
590+
if (fread(&nn, sizeof(nn), 1, fp) != 1) {
591+
fclose(fp);
592+
return 1;
593+
}
594+
mNColTracks[i] = nn;
595+
mMCInfos[i].resize(nn);
596+
if (fread(mMCInfos[i].data(), sizeof(mMCInfos[i][0]), nn, fp) != nn) {
597+
fclose(fp);
598+
return 1;
599+
}
600+
}
601+
fclose(fp);
602+
return 0;
603+
}
604+
605+
void GPUQA::InitO2MCData()
606+
{
607+
#ifdef GPUCA_O2_LIB
608+
HighResTimer timer;
609+
if (mTracking && mTracking->GetProcessingSettings().debugLevel) {
610+
GPUInfo("Start reading O2 Track MC information");
611+
timer.Start();
612+
}
613+
static constexpr float PRIM_MAX_T = 0.01f;
614+
615+
o2::steer::MCKinematicsReader mcReader("collisioncontext.root");
616+
int nSimEvents = mcReader.getNEvents(0);
617+
mNColTracks.resize(nSimEvents);
618+
mMCInfos.resize(GetNMCCollissions());
619+
std::vector<int> refId;
620+
621+
auto dc = o2::steer::DigitizationContext::loadFromFile("collisioncontext.root");
622+
auto evrec = dc->getEventRecords();
623+
624+
for (int i = 0; i < nSimEvents; i++) {
625+
auto ir = evrec[i];
626+
auto ir0 = o2::raw::HBFUtils::Instance().getFirstIRofTF(ir);
627+
float timebin = (float)ir.differenceInBC(ir0) / o2::tpc::constants::LHCBCPERTIMEBIN;
628+
629+
const std::vector<o2::MCTrack>& tracks = mcReader.getTracks(0, i);
630+
const std::vector<o2::TrackReference>& trackRefs = mcReader.getTrackRefsByEvent(0, i);
631+
632+
refId.resize(tracks.size());
633+
std::fill(refId.begin(), refId.end(), -1);
634+
for (unsigned int j = 0; j < trackRefs.size(); j++) {
635+
if (trackRefs[j].getDetectorId() == o2::detectors::DetID::TPC) {
636+
int trkId = trackRefs[j].getTrackID();
637+
if (refId[trkId] == -1) {
638+
refId[trkId] = j;
639+
}
640+
}
641+
}
642+
mNColTracks[i] = tracks.size();
643+
mMCInfos[i].resize(mNColTracks[i]);
644+
for (unsigned int j = 0; j < tracks.size(); j++) {
645+
auto& info = mMCInfos[i][j];
646+
const auto& trk = tracks[j];
647+
TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(trk.GetPdgCode());
648+
Int_t pid = -1;
649+
if (abs(trk.GetPdgCode()) == kElectron) {
650+
pid = 0;
651+
}
652+
if (abs(trk.GetPdgCode()) == kMuonMinus) {
653+
pid = 1;
654+
}
655+
if (abs(trk.GetPdgCode()) == kPiPlus) {
656+
pid = 2;
657+
}
658+
if (abs(trk.GetPdgCode()) == kKPlus) {
659+
pid = 3;
660+
}
661+
if (abs(trk.GetPdgCode()) == kProton) {
662+
pid = 4;
663+
}
664+
665+
info.charge = particle ? particle->Charge() : 0;
666+
info.prim = trk.T() < PRIM_MAX_T;
667+
info.primDaughters = 0;
668+
if (trk.getFirstDaughterTrackId() != -1) {
669+
for (int k = trk.getFirstDaughterTrackId(); k <= trk.getLastDaughterTrackId(); k++) {
670+
if (tracks[k].T() < PRIM_MAX_T) {
671+
info.primDaughters = 1;
672+
break;
673+
}
674+
}
675+
}
676+
info.pid = pid;
677+
info.t0 = timebin;
678+
if (refId[j] >= 0) {
679+
const auto& trkRef = trackRefs[refId[j]];
680+
info.x = trkRef.X();
681+
info.y = trkRef.Y();
682+
info.z = trkRef.Z();
683+
info.pX = trkRef.Px();
684+
info.pY = trkRef.Py();
685+
info.pZ = trkRef.Pz();
686+
info.genRadius = std::sqrt(trk.GetStartVertexCoordinatesX() * trk.GetStartVertexCoordinatesX() + trk.GetStartVertexCoordinatesY() * trk.GetStartVertexCoordinatesY() + trk.GetStartVertexCoordinatesZ() * trk.GetStartVertexCoordinatesZ());
687+
} else {
688+
info.x = info.y = info.z = info.pX = info.pY = info.pZ = 0;
689+
info.genRadius = 0;
690+
}
691+
}
692+
}
693+
if (mTracking && mTracking->GetProcessingSettings().debugLevel) {
694+
GPUInfo("Finished reading O2 Track MC information (%f seconds)", timer.GetCurrentElapsedTime());
695+
}
696+
#endif
697+
}
698+
558699
int GPUQA::InitQA(int tasks)
559700
{
560701
if (mQAInitialized) {
@@ -583,98 +724,7 @@ int GPUQA::InitQA(int tasks)
583724

584725
#ifdef GPUCA_O2_LIB
585726
if (!mConfig.noMC) {
586-
HighResTimer timer;
587-
if (mTracking && mTracking->GetProcessingSettings().debugLevel) {
588-
GPUInfo("Start reading O2 Track MC information");
589-
timer.Start();
590-
}
591-
static constexpr float PRIM_MAX_T = 0.01f;
592-
593-
o2::steer::MCKinematicsReader mcReader("collisioncontext.root");
594-
int nSimEvents = mcReader.getNEvents(0);
595-
mTrackMCLabelsReverse.resize(nSimEvents);
596-
mRecTracks.resize(nSimEvents);
597-
mFakeTracks.resize(nSimEvents);
598-
mMCParam.resize(nSimEvents);
599-
mMCInfos.resize(nSimEvents);
600-
mNColTracks.resize(nSimEvents);
601-
std::vector<int> refId;
602-
603-
auto dc = o2::steer::DigitizationContext::loadFromFile("collisioncontext.root");
604-
auto evrec = dc->getEventRecords();
605-
606-
for (int i = 0; i < nSimEvents; i++) {
607-
auto ir = evrec[i];
608-
auto ir0 = o2::raw::HBFUtils::Instance().getFirstIRofTF(ir);
609-
float timebin = (float)ir.differenceInBC(ir0) / o2::tpc::constants::LHCBCPERTIMEBIN;
610-
611-
const std::vector<o2::MCTrack>& tracks = mcReader.getTracks(0, i);
612-
const std::vector<o2::TrackReference>& trackRefs = mcReader.getTrackRefsByEvent(0, i);
613-
614-
refId.resize(tracks.size());
615-
std::fill(refId.begin(), refId.end(), -1);
616-
for (unsigned int j = 0; j < trackRefs.size(); j++) {
617-
if (trackRefs[j].getDetectorId() == o2::detectors::DetID::TPC) {
618-
int trkId = trackRefs[j].getTrackID();
619-
if (refId[trkId] == -1) {
620-
refId[trkId] = j;
621-
}
622-
}
623-
}
624-
mNColTracks[i] = tracks.size();
625-
mMCInfos[i].resize(tracks.size());
626-
for (unsigned int j = 0; j < tracks.size(); j++) {
627-
auto& info = mMCInfos[i][j];
628-
const auto& trk = tracks[j];
629-
TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(trk.GetPdgCode());
630-
Int_t pid = -1;
631-
if (abs(trk.GetPdgCode()) == kElectron) {
632-
pid = 0;
633-
}
634-
if (abs(trk.GetPdgCode()) == kMuonMinus) {
635-
pid = 1;
636-
}
637-
if (abs(trk.GetPdgCode()) == kPiPlus) {
638-
pid = 2;
639-
}
640-
if (abs(trk.GetPdgCode()) == kKPlus) {
641-
pid = 3;
642-
}
643-
if (abs(trk.GetPdgCode()) == kProton) {
644-
pid = 4;
645-
}
646-
647-
info.charge = particle ? particle->Charge() : 0;
648-
info.prim = trk.T() < PRIM_MAX_T;
649-
info.primDaughters = 0;
650-
if (trk.getFirstDaughterTrackId() != -1) {
651-
for (int k = trk.getFirstDaughterTrackId(); k <= trk.getLastDaughterTrackId(); k++) {
652-
if (tracks[k].T() < PRIM_MAX_T) {
653-
info.primDaughters = 1;
654-
break;
655-
}
656-
}
657-
}
658-
info.pid = pid;
659-
info.t0 = timebin;
660-
if (refId[j] >= 0) {
661-
const auto& trkRef = trackRefs[refId[j]];
662-
info.x = trkRef.X();
663-
info.y = trkRef.Y();
664-
info.z = trkRef.Z();
665-
info.pX = trkRef.Px();
666-
info.pY = trkRef.Py();
667-
info.pZ = trkRef.Pz();
668-
info.genRadius = std::sqrt(trk.GetStartVertexCoordinatesX() * trk.GetStartVertexCoordinatesX() + trk.GetStartVertexCoordinatesY() * trk.GetStartVertexCoordinatesY() + trk.GetStartVertexCoordinatesZ() * trk.GetStartVertexCoordinatesZ());
669-
} else {
670-
info.x = info.y = info.z = info.pX = info.pY = info.pZ = 0;
671-
info.genRadius = 0;
672-
}
673-
}
674-
}
675-
if (mTracking && mTracking->GetProcessingSettings().debugLevel) {
676-
GPUInfo("Finished reading O2 Track MC information (%f seconds)", timer.GetCurrentElapsedTime());
677-
}
727+
InitO2MCData();
678728
}
679729
#endif
680730

@@ -729,6 +779,22 @@ void GPUQA::RunQA(bool matchOnly, const std::vector<o2::tpc::TrackTPC>* tracksEx
729779
}
730780
mClNative = clNative;
731781

782+
#ifdef GPUCA_TPC_GEOMETRY_O2
783+
unsigned int nSimEvents = GetNMCCollissions();
784+
if (mTrackMCLabelsReverse.size() < nSimEvents) {
785+
mTrackMCLabelsReverse.resize(nSimEvents);
786+
}
787+
if (mRecTracks.size() < nSimEvents) {
788+
mRecTracks.resize(nSimEvents);
789+
}
790+
if (mFakeTracks.size() < nSimEvents) {
791+
mFakeTracks.resize(nSimEvents);
792+
}
793+
if (mMCParam.size() < nSimEvents) {
794+
mMCParam.resize(nSimEvents);
795+
}
796+
#endif
797+
732798
// Initialize Arrays
733799
unsigned int nReconstructedTracks = 0;
734800
if (tracksExternal) {

GPU/GPUTracking/qa/GPUQA.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class GPUQA
5252
int HitAttachStatus(int iHit) const { return false; }
5353
int GetMCTrackLabel(unsigned int trackId) const { return -1; }
5454
bool clusterRemovable(int attach, bool prot) const { return false; }
55+
void DumpO2MCData(const char* filename) const {}
56+
int ReadO2MCData(const char* filename) { return 1; }
5557
static bool QAAvailable() { return false; }
5658
static bool IsInitialized() { return false; }
5759
};
@@ -104,6 +106,8 @@ class GPUQA
104106
int HitAttachStatus(int iHit) const;
105107
int GetMCTrackLabel(unsigned int trackId) const;
106108
bool clusterRemovable(int attach, bool prot) const;
109+
void DumpO2MCData(const char* filename) const;
110+
int ReadO2MCData(const char* filename);
107111
static bool QAAvailable() { return true; }
108112
bool IsInitialized() { return mQAInitialized; }
109113

@@ -140,6 +144,7 @@ class GPUQA
140144
};
141145

142146
int InitQACreateHistograms();
147+
void InitO2MCData();
143148
int DoClusterCounts(unsigned long long int* attachClusterCounts, int mode = 0);
144149
void PrintClusterCount(int mode, int& num, const char* name, unsigned long long int n, unsigned long long int normalization);
145150

@@ -188,9 +193,9 @@ class GPUQA
188193
template <class T>
189194
static auto& GetMCTrackObj(T& obj, const mcLabelI_t& l);
190195

191-
unsigned int GetNMCCollissions();
192-
unsigned int GetNMCTracks(int iCol);
193-
unsigned int GetNMCLabels();
196+
unsigned int GetNMCCollissions() const;
197+
unsigned int GetNMCTracks(int iCol) const;
198+
unsigned int GetNMCLabels() const;
194199
const mcInfo_t& GetMCTrack(unsigned int iTrk, unsigned int iCol);
195200
const mcInfo_t& GetMCTrack(const mcLabel_t& label);
196201
int GetMCLabelNID(const mcLabels_t& label);
@@ -222,14 +227,14 @@ class GPUQA
222227
std::vector<std::vector<int>> mRecTracks;
223228
std::vector<std::vector<int>> mFakeTracks;
224229
std::vector<std::vector<additionalMCParameters>> mMCParam;
225-
std::vector<std::vector<mcInfo_t>> mMCInfos;
226-
std::vector<int> mNColTracks;
227230
#else
228231
std::vector<int> mTrackMCLabelsReverse[1];
229232
std::vector<int> mRecTracks[1];
230233
std::vector<int> mFakeTracks[1];
231234
std::vector<additionalMCParameters> mMCParam[1];
232235
#endif
236+
std::vector<int> mNColTracks;
237+
std::vector<std::vector<mcInfo_t>> mMCInfos;
233238
std::vector<additionalClusterParameters> mClusterParam;
234239
int mNTotalFakes = 0;
235240

0 commit comments

Comments
 (0)