Skip to content

Commit 862c400

Browse files
committed
save vector of tracks in TICLDumper
1 parent ab28ccf commit 862c400

File tree

1 file changed

+123
-97
lines changed

1 file changed

+123
-97
lines changed

RecoHGCal/TICL/plugins/TICLDumper.cc

Lines changed: 123 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ class TracksterDumperHelper {
159159
if (tracksterType_ != TracksterType::Trackster) {
160160
trackster_tree_->Branch("regressed_pt", &simtrackster_regressed_pt);
161161
trackster_tree_->Branch("pdgID", &simtrackster_pdgID);
162-
trackster_tree_->Branch("trackIdx", &simtrackster_trackIdx);
163-
trackster_tree_->Branch("trackTime", &simtrackster_trackTime);
162+
trackster_tree_->Branch("trackIdx", &simtrackster_trackIdxs);
164163
trackster_tree_->Branch("timeBoundary", &simtrackster_timeBoundary);
165164
trackster_tree_->Branch("boundaryX", &simtrackster_boundaryX);
166165
trackster_tree_->Branch("boundaryY", &simtrackster_boundaryY);
@@ -217,8 +216,7 @@ class TracksterDumperHelper {
217216

218217
simtrackster_regressed_pt.clear();
219218
simtrackster_pdgID.clear();
220-
simtrackster_trackIdx.clear();
221-
simtrackster_trackTime.clear();
219+
simtrackster_trackIdxs.clear();
222220
simtrackster_timeBoundary.clear();
223221
simtrackster_boundaryX.clear();
224222
simtrackster_boundaryY.clear();
@@ -291,11 +289,11 @@ class TracksterDumperHelper {
291289

292290
simtrackster_timeBoundary.push_back(trackster_iterator->boundaryTime());
293291

294-
/* SimTracksters can be built from either a CaloParticle or a SimCluster
292+
/* SimTracksters can be built from either a CaloParticle or a SimCluster
295293
The SimTrackster "fromCP" collection is built solely from CaloParticle (all CPs that have association to reco in HGCAL)
296294
SimTrackster "from SC" is built from either :
297295
- a CaloParticle (when the CaloParticle first SimTrack has crossedBoundary=True)
298-
- a SimCluster (other cases)
296+
- a SimCluster (other cases)
299297
Thus trackster.seedIndex() can point to either CaloParticle or SimCluster collection (check seedID to differentiate)
300298
*/
301299
using CaloObjectVariant = std::variant<CaloParticle, SimCluster>;
@@ -330,47 +328,62 @@ class TracksterDumperHelper {
330328
simtrackster_boundaryPz.push_back(-999);
331329
}
332330

333-
auto const trackIdx = trackster_iterator->trackIdx();
334-
simtrackster_trackIdx.push_back(trackIdx);
335-
if (trackIdx != -1) {
336-
const auto& track = tracks[trackIdx];
337-
338-
int iSide = int(track.eta() > 0);
339-
340-
const auto& fts = trajectoryStateTransform::outerFreeState((track), &detectorTools.bfield);
341-
// to the HGCal front
342-
const auto& tsos = detectorTools.propagator.propagate(fts, detectorTools.firstDisk_[iSide]->surface());
343-
if (tsos.isValid()) {
344-
const auto& globalPos = tsos.globalPosition();
345-
const auto& globalMom = tsos.globalMomentum();
346-
simtrackster_track_boundaryX.push_back(globalPos.x());
347-
simtrackster_track_boundaryY.push_back(globalPos.y());
348-
simtrackster_track_boundaryZ.push_back(globalPos.z());
349-
simtrackster_track_boundaryEta.push_back(globalPos.eta());
350-
simtrackster_track_boundaryPhi.push_back(globalPos.phi());
351-
simtrackster_track_boundaryPx.push_back(globalMom.x());
352-
simtrackster_track_boundaryPy.push_back(globalMom.y());
353-
simtrackster_track_boundaryPz.push_back(globalMom.z());
354-
simtrackster_trackTime.push_back(track.t0());
355-
} else {
356-
simtrackster_track_boundaryX.push_back(-999);
357-
simtrackster_track_boundaryY.push_back(-999);
358-
simtrackster_track_boundaryZ.push_back(-999);
359-
simtrackster_track_boundaryEta.push_back(-999);
360-
simtrackster_track_boundaryPhi.push_back(-999);
361-
simtrackster_track_boundaryPx.push_back(-999);
362-
simtrackster_track_boundaryPy.push_back(-999);
363-
simtrackster_track_boundaryPz.push_back(-999);
331+
auto const trackIdxs = trackster_iterator->trackIdxs();
332+
simtrackster_trackIdxs.push_back(trackIdxs);
333+
if (!trackIdxs.empty()) {
334+
std::vector<float> track_boundaryX;
335+
std::vector<float> track_boundaryY;
336+
std::vector<float> track_boundaryZ;
337+
std::vector<float> track_boundaryEta;
338+
std::vector<float> track_boundaryPhi;
339+
std::vector<float> track_boundaryPx;
340+
std::vector<float> track_boundaryPy;
341+
std::vector<float> track_boundaryPz;
342+
for (const auto trackIdx : trackIdxs) {
343+
const auto& track = tracks[trackIdx];
344+
int iSide = int(track.eta() > 0);
345+
const auto& fts = trajectoryStateTransform::outerFreeState((track), &detectorTools.bfield);
346+
// to the HGCal front
347+
const auto& tsos = detectorTools.propagator.propagate(fts, detectorTools.firstDisk_[iSide]->surface());
348+
if (tsos.isValid()) {
349+
const auto& globalPos = tsos.globalPosition();
350+
const auto& globalMom = tsos.globalMomentum();
351+
track_boundaryX.push_back(globalPos.x());
352+
track_boundaryY.push_back(globalPos.y());
353+
track_boundaryZ.push_back(globalPos.z());
354+
track_boundaryEta.push_back(globalPos.eta());
355+
track_boundaryPhi.push_back(globalPos.phi());
356+
track_boundaryPx.push_back(globalMom.x());
357+
track_boundaryPy.push_back(globalMom.y());
358+
track_boundaryPz.push_back(globalMom.z());
359+
} else {
360+
track_boundaryX.push_back(-999);
361+
track_boundaryY.push_back(-999);
362+
track_boundaryZ.push_back(-999);
363+
track_boundaryEta.push_back(-999);
364+
track_boundaryPhi.push_back(-999);
365+
track_boundaryPx.push_back(-999);
366+
track_boundaryPy.push_back(-999);
367+
track_boundaryPz.push_back(-999);
368+
}
364369
}
370+
simtrackster_track_boundaryX.push_back(track_boundaryX);
371+
simtrackster_track_boundaryY.push_back(track_boundaryY);
372+
simtrackster_track_boundaryZ.push_back(track_boundaryZ);
373+
simtrackster_track_boundaryEta.push_back(track_boundaryEta);
374+
simtrackster_track_boundaryPhi.push_back(track_boundaryPhi);
375+
simtrackster_track_boundaryPx.push_back(track_boundaryPx);
376+
simtrackster_track_boundaryPy.push_back(track_boundaryPy);
377+
simtrackster_track_boundaryPz.push_back(track_boundaryPz);
365378
} else {
366-
simtrackster_track_boundaryX.push_back(-999);
367-
simtrackster_track_boundaryY.push_back(-999);
368-
simtrackster_track_boundaryZ.push_back(-999);
369-
simtrackster_track_boundaryEta.push_back(-999);
370-
simtrackster_track_boundaryPhi.push_back(-999);
371-
simtrackster_track_boundaryPx.push_back(-999);
372-
simtrackster_track_boundaryPy.push_back(-999);
373-
simtrackster_track_boundaryPz.push_back(-999);
379+
simtrackster_track_boundaryX.push_back({-999});
380+
simtrackster_track_boundaryY.push_back({-999});
381+
simtrackster_track_boundaryZ.push_back({-999});
382+
simtrackster_track_boundaryEta.push_back({-999});
383+
simtrackster_track_boundaryPhi.push_back({-999});
384+
simtrackster_track_boundaryPx.push_back({-999});
385+
simtrackster_track_boundaryPy.push_back({-999});
386+
simtrackster_track_boundaryPz.push_back({-999});
374387
}
375388
}
376389

@@ -450,8 +463,7 @@ class TracksterDumperHelper {
450463
// for simtrackster
451464
std::vector<float> simtrackster_regressed_pt;
452465
std::vector<int> simtrackster_pdgID;
453-
std::vector<int> simtrackster_trackIdx;
454-
std::vector<float> simtrackster_trackTime;
466+
std::vector<std::vector<int>> simtrackster_trackIdxs;
455467
std::vector<float> simtrackster_timeBoundary;
456468
std::vector<float> simtrackster_boundaryX;
457469
std::vector<float> simtrackster_boundaryY;
@@ -461,14 +473,14 @@ class TracksterDumperHelper {
461473
std::vector<float> simtrackster_boundaryPx;
462474
std::vector<float> simtrackster_boundaryPy;
463475
std::vector<float> simtrackster_boundaryPz;
464-
std::vector<float> simtrackster_track_boundaryX;
465-
std::vector<float> simtrackster_track_boundaryY;
466-
std::vector<float> simtrackster_track_boundaryZ;
467-
std::vector<float> simtrackster_track_boundaryEta;
468-
std::vector<float> simtrackster_track_boundaryPhi;
469-
std::vector<float> simtrackster_track_boundaryPx;
470-
std::vector<float> simtrackster_track_boundaryPy;
471-
std::vector<float> simtrackster_track_boundaryPz;
476+
std::vector<std::vector<float>> simtrackster_track_boundaryX;
477+
std::vector<std::vector<float>> simtrackster_track_boundaryY;
478+
std::vector<std::vector<float>> simtrackster_track_boundaryZ;
479+
std::vector<std::vector<float>> simtrackster_track_boundaryEta;
480+
std::vector<std::vector<float>> simtrackster_track_boundaryPhi;
481+
std::vector<std::vector<float>> simtrackster_track_boundaryPx;
482+
std::vector<std::vector<float>> simtrackster_track_boundaryPy;
483+
std::vector<std::vector<float>> simtrackster_track_boundaryPz;
472484

473485
std::vector<std::vector<float>> trackster_id_probabilities;
474486
std::vector<std::vector<uint32_t>> trackster_vertices_indexes;
@@ -663,20 +675,20 @@ class TICLDumper : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::Sh
663675
std::vector<float> simTICLCandidate_raw_energy;
664676
std::vector<float> simTICLCandidate_regressed_energy;
665677
std::vector<std::vector<int>> simTICLCandidate_simTracksterCPIndex;
666-
std::vector<float> simTICLCandidate_boundaryX;
667-
std::vector<float> simTICLCandidate_boundaryY;
668-
std::vector<float> simTICLCandidate_boundaryZ;
669-
std::vector<float> simTICLCandidate_boundaryPx;
670-
std::vector<float> simTICLCandidate_boundaryPy;
671-
std::vector<float> simTICLCandidate_boundaryPz;
678+
std::vector<std::vector<int>> simTICLCandidate_tracks_in_candidate;
679+
std::vector<std::vector<float>> simTICLCandidate_boundaryX;
680+
std::vector<std::vector<float>> simTICLCandidate_boundaryY;
681+
std::vector<std::vector<float>> simTICLCandidate_boundaryZ;
682+
std::vector<std::vector<float>> simTICLCandidate_boundaryPx;
683+
std::vector<std::vector<float>> simTICLCandidate_boundaryPy;
684+
std::vector<std::vector<float>> simTICLCandidate_boundaryPz;
672685
std::vector<float> simTICLCandidate_pt;
673686
std::vector<float> simTICLCandidate_phi;
674687
std::vector<float> simTICLCandidate_eta;
675688
std::vector<float> simTICLCandidate_caloParticleMass;
676689
std::vector<float> simTICLCandidate_time;
677690
std::vector<int> simTICLCandidate_pdgId;
678691
std::vector<int> simTICLCandidate_charge;
679-
std::vector<int> simTICLCandidate_track_in_candidate;
680692

681693
// from TICLCandidate, product of linking
682694
size_t nCandidates;
@@ -784,7 +796,7 @@ void TICLDumper::clearVariables() {
784796
simTICLCandidate_caloParticleMass.clear();
785797
simTICLCandidate_pdgId.clear();
786798
simTICLCandidate_charge.clear();
787-
simTICLCandidate_track_in_candidate.clear();
799+
simTICLCandidate_tracks_in_candidate.clear();
788800

789801
nCandidates = 0;
790802
candidate_charge.clear();
@@ -1069,7 +1081,7 @@ void TICLDumper::beginJob() {
10691081
simTICLCandidate_tree->Branch("simTICLCandidate_caloParticleMass", &simTICLCandidate_caloParticleMass);
10701082
simTICLCandidate_tree->Branch("simTICLCandidate_pdgId", &simTICLCandidate_pdgId);
10711083
simTICLCandidate_tree->Branch("simTICLCandidate_charge", &simTICLCandidate_charge);
1072-
simTICLCandidate_tree->Branch("simTICLCandidate_track_in_candidate", &simTICLCandidate_track_in_candidate);
1084+
simTICLCandidate_tree->Branch("simTICLCandidate_tracks_in_candidate", &simTICLCandidate_tracks_in_candidate);
10731085
}
10741086
}
10751087

@@ -1200,7 +1212,7 @@ void TICLDumper::analyze(const edm::Event& event, const edm::EventSetup& setup)
12001212
}
12011213

12021214
const auto& simTrackstersSC_h = event.getHandle(simTracksters_SC_token_);
1203-
simTICLCandidate_track_in_candidate.resize(simTICLCandidates.size(), -1);
1215+
simTICLCandidate_tracks_in_candidate.resize(simTICLCandidates.size());
12041216
for (size_t i = 0; i < simTICLCandidates.size(); ++i) {
12051217
auto const& cand = simTICLCandidates[i];
12061218

@@ -1219,40 +1231,54 @@ void TICLDumper::analyze(const edm::Event& event, const edm::EventSetup& setup)
12191231
}
12201232
simTICLCandidate_simTracksterCPIndex.push_back(tmpIdxVec);
12211233
tmpIdxVec.clear();
1222-
auto const& trackPtr = cand.trackPtr();
1223-
if (!trackPtr.isNull()) {
1224-
auto const& track = *trackPtr;
1225-
int iSide = int(track.eta() > 0);
1226-
int tk_idx = trackPtr.get() - (edm::Ptr<reco::Track>(tracks_h, 0)).get();
1227-
simTICLCandidate_track_in_candidate[i] = tk_idx;
1228-
1229-
const auto& fts = trajectoryStateTransform::outerFreeState((track), &detectorTools_->bfield);
1230-
// to the HGCal front
1231-
const auto& tsos = detectorTools_->propagator.propagate(fts, detectorTools_->firstDisk_[iSide]->surface());
1232-
if (tsos.isValid()) {
1233-
const auto& globalPos = tsos.globalPosition();
1234-
const auto& globalMom = tsos.globalMomentum();
1235-
simTICLCandidate_boundaryX.push_back(globalPos.x());
1236-
simTICLCandidate_boundaryY.push_back(globalPos.y());
1237-
simTICLCandidate_boundaryZ.push_back(globalPos.z());
1238-
simTICLCandidate_boundaryPx.push_back(globalMom.x());
1239-
simTICLCandidate_boundaryPy.push_back(globalMom.y());
1240-
simTICLCandidate_boundaryPz.push_back(globalMom.z());
1241-
} else {
1242-
simTICLCandidate_boundaryX.push_back(-999);
1243-
simTICLCandidate_boundaryY.push_back(-999);
1244-
simTICLCandidate_boundaryZ.push_back(-999);
1245-
simTICLCandidate_boundaryPx.push_back(-999);
1246-
simTICLCandidate_boundaryPy.push_back(-999);
1247-
simTICLCandidate_boundaryPz.push_back(-999);
1234+
auto const& trackPtrs = cand.trackPtrs();
1235+
if (!trackPtrs.empty()) {
1236+
std::vector<float> boundaryX;
1237+
std::vector<float> boundaryY;
1238+
std::vector<float> boundaryZ;
1239+
std::vector<float> boundaryPx;
1240+
std::vector<float> boundaryPy;
1241+
std::vector<float> boundaryPz;
1242+
for (const auto& trackPtr : trackPtrs) {
1243+
auto const& track = *trackPtr;
1244+
int iSide = int(track.eta() > 0);
1245+
int tk_idx = trackPtr.get() - (edm::Ptr<reco::Track>(tracks_h, 0)).get();
1246+
simTICLCandidate_tracks_in_candidate[i].push_back(tk_idx);
1247+
1248+
const auto& fts = trajectoryStateTransform::outerFreeState((track), &detectorTools_->bfield);
1249+
// to the HGCal front
1250+
const auto& tsos = detectorTools_->propagator.propagate(fts, detectorTools_->firstDisk_[iSide]->surface());
1251+
if (tsos.isValid()) {
1252+
const auto& globalPos = tsos.globalPosition();
1253+
const auto& globalMom = tsos.globalMomentum();
1254+
boundaryX.push_back(globalPos.x());
1255+
boundaryY.push_back(globalPos.y());
1256+
boundaryZ.push_back(globalPos.z());
1257+
boundaryPx.push_back(globalMom.x());
1258+
boundaryPy.push_back(globalMom.y());
1259+
boundaryPz.push_back(globalMom.z());
1260+
} else {
1261+
boundaryX.push_back(-999);
1262+
boundaryY.push_back(-999);
1263+
boundaryZ.push_back(-999);
1264+
boundaryPx.push_back(-999);
1265+
boundaryPy.push_back(-999);
1266+
boundaryPz.push_back(-999);
1267+
}
12481268
}
1269+
simTICLCandidate_boundaryX.push_back(boundaryX);
1270+
simTICLCandidate_boundaryY.push_back(boundaryY);
1271+
simTICLCandidate_boundaryZ.push_back(boundaryZ);
1272+
simTICLCandidate_boundaryPx.push_back(boundaryPx);
1273+
simTICLCandidate_boundaryPy.push_back(boundaryPy);
1274+
simTICLCandidate_boundaryPz.push_back(boundaryPz);
12491275
} else {
1250-
simTICLCandidate_boundaryX.push_back(-999);
1251-
simTICLCandidate_boundaryY.push_back(-999);
1252-
simTICLCandidate_boundaryZ.push_back(-999);
1253-
simTICLCandidate_boundaryPx.push_back(-999);
1254-
simTICLCandidate_boundaryPy.push_back(-999);
1255-
simTICLCandidate_boundaryPz.push_back(-999);
1276+
simTICLCandidate_boundaryX.push_back({-999});
1277+
simTICLCandidate_boundaryY.push_back({-999});
1278+
simTICLCandidate_boundaryZ.push_back({-999});
1279+
simTICLCandidate_boundaryPx.push_back({-999});
1280+
simTICLCandidate_boundaryPy.push_back({-999});
1281+
simTICLCandidate_boundaryPz.push_back({-999});
12561282
}
12571283
}
12581284

0 commit comments

Comments
 (0)