Skip to content

Commit 07abc80

Browse files
committed
first version of training data output
1 parent 7a87e70 commit 07abc80

1 file changed

Lines changed: 55 additions & 41 deletions

File tree

MyTasks/W/wMuonFwdEfficiency.cxx

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ struct wMuonFwdEfficiency {
1414
HistogramRegistry histos{"histos", {},
1515
OutputObjHandlingPolicy::AnalysisObject};
1616

17-
// definition of reconstructed info to be saved
17+
// definition of reconstructed info to be saved for processing
1818
struct RecoTrackInfo {
1919
int64_t trackID;
20+
uint8_t trackType;
2021
float chi2;
2122
float chi2MatchMCHMID;
23+
float chi2MatchMCHMFT;
24+
float matchScoreMCHMFT;
25+
int32_t matchMFTTrackId;
2226
float pDca;
2327
float pt;
2428
float eta;
29+
float ptResolution;
2530
};
31+
2632
// Map to group reconstructed tracks by their associated simulated track ID
2733
std::unordered_map<int64_t, std::vector<RecoTrackInfo>> trackGroups;
2834

@@ -36,7 +42,7 @@ struct wMuonFwdEfficiency {
3642
if (!muonTracksOut.is_open()) {
3743
LOGF(fatal, "Failed to open muonTracks.csv for writing");
3844
}
39-
muonTracksOut << "trackID,chi2,chi2MatchMCHMID,pDCA,pt,eta" << std::endl;
45+
muonTracksOut << "trackID,trackType,phi,tgl,signed1Pt,nClusters,pDCA,rAtAbsorberEnd,sign,chi2,chi2MatchMCHMID,chi2MatchMCHMFT,trackTime,eta,pt,p" << std::endl;
4046

4147
// define axes you want to use
4248
const AxisSpec axisCounter{1, 0, +1, ""};
@@ -53,7 +59,7 @@ struct wMuonFwdEfficiency {
5359
histos.add("yPtTruthHist", "yPtTruthHist", kTH2F, {axisPt, axisEta});
5460
histos.add("PtRecoHist", "PtRecoHist", kTH1F, {axisPt});
5561
histos.add("PtTruthHist", "PtTruthHist", kTH1F, {axisPt});
56-
//histos.add("PtResolution", "PtResolution", kTH1F, {axisDeltaPt});
62+
histos.add("PtResolution", "PtResolution", kTH1F, {axisDeltaPt});
5763
histos.add("chi2", "chi2", kTH1F, {axisChi2});
5864
histos.add("chi2MatchMCHMID", "chi2MatchMCHMID", kTH1F, {axisChi2});
5965
histos.add("pDCA", "pDCA", kTH1F, {axisDCA});
@@ -67,7 +73,7 @@ struct wMuonFwdEfficiency {
6773
histos.fill(HIST("eventCounterReco"), 0.5);
6874

6975
for (auto& track : tracks) {
70-
if(track.has_mcParticle() && track.chi2MatchMCHMID() > 0) { // check if track has associated MC particle and has a valid chi2 match
76+
if(track.has_mcParticle()) { // check if track has associated MC particle and has a valid chi2 match
7177
auto mcParticle = track.mcParticle();
7278
int64_t recoTrackID = track.globalIndex(); // Reconstructed track ID
7379

@@ -103,61 +109,69 @@ struct wMuonFwdEfficiency {
103109
// std::cout << std::endl;
104110

105111
if (hasWmother) {
112+
auto muTrackType = static_cast<int64_t>(track.trackType());
106113
auto muChi2 = track.chi2();
107114
auto muChi2MatchMCHMID = track.chi2MatchMCHMID();
108-
auto pDca = track.pDca();
109-
auto pt = track.pt();
110-
auto eta = track.eta();
115+
auto muChi2MatchMCHMFT = track.chi2MatchMCHMFT();
116+
auto muMatchScoreMCHMFT = track.matchScoreMCHMFT();
117+
auto muMatchMFTTrackId = track.matchMFTTrackId();
118+
auto muDca = track.pDca();
119+
auto muPt = track.pt();
120+
auto muEta = track.eta();
121+
auto ptResolution = abs(mcParticle.pt() - track.pt());
111122

112-
// Store the reconstructed track information in the map
113-
RecoTrackInfo trackInfo = {recoTrackID, muChi2, muChi2MatchMCHMID, pDca, pt, eta};
123+
// Store the reconstructed track information in the map for additional processing, associated with the simulated track ID
124+
RecoTrackInfo trackInfo = {recoTrackID, muTrackType, muChi2, muChi2MatchMCHMID, muChi2MatchMCHMFT, muMatchScoreMCHMFT, muMatchMFTTrackId,
125+
muDca, muPt, muEta, ptResolution};
114126
trackGroups[mcTrackID].push_back(trackInfo);
127+
128+
// save all muon tracks to the output file
129+
muonTracksOut << recoTrackID << "," << muTrackType << "," << track.phi() << "," << track.tgl() << "," << track.signed1Pt() << ","
130+
<< static_cast<int64_t>(track.nClusters()) << "," << muDca << "," << track.rAtAbsorberEnd() << ","
131+
<< static_cast<int64_t>(track.sign()) << "," << muChi2 << "," << muChi2MatchMCHMID << "," << muChi2MatchMCHMFT << ","
132+
<< track.trackTime() << "," << muEta << "," << muPt << "," << track.p() << std::endl;
133+
134+
// basic cuts before plotting
135+
if (muTrackType == 3 && muChi2MatchMCHMID > 0) { // only look at standalone tracks for now
136+
// write to histograms
137+
histos.fill(HIST("PtRecoHist"), muPt);
138+
histos.fill(HIST("yPtRecoHist"), muPt, muEta);
139+
histos.fill(HIST("PtResolution"), ptResolution);
140+
histos.fill(HIST("chi2"), muChi2);
141+
histos.fill(HIST("chi2MatchMCHMID"), muChi2MatchMCHMID);
142+
histos.fill(HIST("pDCA"), muDca);
143+
}
115144
}
116145
}
117146
}
118147
}
119148

149+
// additional track processing to check the multiple reconstructed tracks associated with the same simulated track
120150
for (auto& [mcTrackID, recoTracks] : trackGroups) {
121-
// prcess tracks to choose track with lowest chi2
122-
int trackIndex = 0;
123-
int chosenIndex = trackIndex;
124-
float minChi2 = 100000.0;
125-
for (const auto& trackInfo : recoTracks) {
126-
if (trackInfo.chi2 < minChi2) {
127-
minChi2 = trackInfo.chi2;
128-
chosenIndex = trackIndex; // remember the index of the track with the lowest chi2
129-
}
130-
trackIndex++;
131-
}
151+
// prcess tracks to choose track with lowest chi2 (this is now pointless?)
152+
// int trackIndex = 0;
153+
// int chosenIndex = trackIndex;
154+
// float minChi2 = 100000.0;
155+
// for (const auto& trackInfo : recoTracks) {
156+
// if (trackInfo.chi2 < minChi2) {
157+
// minChi2 = trackInfo.chi2;
158+
// chosenIndex = trackIndex; // remember the index of the track with the lowest chi2
159+
// }
160+
// trackIndex++;
161+
// }
132162

133-
// write to histograms
134-
histos.fill(HIST("PtRecoHist"), recoTracks[chosenIndex].pt);
135-
histos.fill(HIST("yPtRecoHist"), recoTracks[chosenIndex].pt, recoTracks[chosenIndex].eta);
136-
//histos.fill(HIST("PtResolution"), abs(mcParticle.pt-track.pt));
137-
histos.fill(HIST("chi2"), recoTracks[chosenIndex].chi2);
138-
histos.fill(HIST("chi2MatchMCHMID"), recoTracks[chosenIndex].chi2MatchMCHMID);
139-
histos.fill(HIST("pDCA"), recoTracks[chosenIndex].pDca);
140-
141-
// output to textfile
142-
muonTracksOut << recoTracks[chosenIndex].trackID << ","
143-
<< recoTracks[chosenIndex].chi2 << ","
144-
<< recoTracks[chosenIndex].chi2MatchMCHMID << ","
145-
<< recoTracks[chosenIndex].pDca << ","
146-
<< recoTracks[chosenIndex].pt << ","
147-
<< recoTracks[chosenIndex].eta << std::endl;
148-
149-
// only print if the first track isn't the best track
150-
if (chosenIndex > 0) {
163+
// choose when to print the information
164+
bool printRecoTracks = false;
165+
if (printRecoTracks) {
151166
// printing
152167
if (recoTracks.size() > 1) {
153168
// Output a heading for the simulated track
154169
LOGF(info, "Simulated track ID %ld has multiple associated reconstructed tracks:", mcTrackID);
155170

156171
// List the associated reconstructed tracks
157172
for (const auto& trackInfo : recoTracks) {
158-
// Option 1: Using RecoTrackInfo struct
159-
LOGF(info, "RecoTrack: ID = %ld, chi2 = %.2f, chi2MatchMCHMID = %.2f, pDCA = %.2f",
160-
trackInfo.trackID, trackInfo.chi2, trackInfo.chi2MatchMCHMID, trackInfo.pDca);
173+
LOGF(info, "RecoTrack ID = %ld, Track Type = %d, chi2 = %.2f, chi2MatchMCHMID = %.2f, chi2MatchMCHMFT = %.2f, matchScoreMCHMFT = %.2f, MFT Track ID = %d",
174+
trackInfo.trackID, trackInfo.trackType, trackInfo.chi2, trackInfo.chi2MatchMCHMID, trackInfo.chi2MatchMCHMFT, trackInfo.matchScoreMCHMFT, trackInfo.matchMFTTrackId);
161175
}
162176
}
163177
LOGF(info, "Chosen track has index %d with track ID %ld", chosenIndex, recoTracks[chosenIndex].trackID);

0 commit comments

Comments
 (0)