CMS 3D CMS Logo

Functions
write_lst_ntuple.cc File Reference
#include "write_lst_ntuple.h"

Go to the source code of this file.

Functions

void createGnnNtupleBranches ()
 
void createOptionalOutputBranches ()
 
void createOutputBranches ()
 
void createRequiredOutputBranches ()
 
void fillOutputBranches (LSTEvent *event)
 
std::tuple< float, float, float, std::vector< unsigned int >, std::vector< unsigned int > > parsepLS (LSTEvent *event, unsigned int idx)
 
std::tuple< float, float, float, std::vector< unsigned int >, std::vector< unsigned int > > parsepT3 (LSTEvent *event, unsigned int idx)
 
std::tuple< float, float, float, std::vector< unsigned int >, std::vector< unsigned int > > parsepT5 (LSTEvent *event, unsigned int idx)
 
std::tuple< float, float, float, std::vector< unsigned int >, std::vector< unsigned int > > parseT5 (LSTEvent *event, unsigned int idx)
 
std::tuple< int, float, float, float, int, std::vector< int > > parseTrackCandidate (LSTEvent *event, unsigned int idx)
 
void printAllObjects (LSTEvent *event)
 
void printHitMultiplicities (LSTEvent *event)
 
void printLSs (LSTEvent *event)
 
void printMDs (LSTEvent *event)
 
void printMiniDoubletMultiplicities (LSTEvent *event)
 
void printpLSs (LSTEvent *event)
 
void printT3s (LSTEvent *event)
 
void setGnnNtupleBranches (LSTEvent *event)
 
void setGnnNtupleMiniDoublet (LSTEvent *event, unsigned int MD)
 
void setOptionalOutputBranches (LSTEvent *event)
 
void setOutputBranches (LSTEvent *event)
 
void setPixelQuintupletOutputBranches (LSTEvent *event)
 
void setPixelTripletOutputBranches (LSTEvent *event)
 
void setQuintupletOutputBranches (LSTEvent *event)
 

Function Documentation

◆ createGnnNtupleBranches()

void createGnnNtupleBranches ( )

Definition at line 141 of file write_lst_ntuple.cc.

References ana, RooUtil::TTreeX::createBranch(), and AnalysisConfig::tx.

Referenced by run_lst().

141  {
142  // Mini Doublets
143  ana.tx->createBranch<std::vector<float>>("MD_pt");
144  ana.tx->createBranch<std::vector<float>>("MD_eta");
145  ana.tx->createBranch<std::vector<float>>("MD_phi");
146  ana.tx->createBranch<std::vector<float>>("MD_dphichange");
147  ana.tx->createBranch<std::vector<int>>("MD_isFake");
148  ana.tx->createBranch<std::vector<int>>("MD_tpType");
149  ana.tx->createBranch<std::vector<int>>("MD_detId");
150  ana.tx->createBranch<std::vector<int>>("MD_layer");
151  ana.tx->createBranch<std::vector<float>>("MD_0_r");
152  ana.tx->createBranch<std::vector<float>>("MD_0_x");
153  ana.tx->createBranch<std::vector<float>>("MD_0_y");
154  ana.tx->createBranch<std::vector<float>>("MD_0_z");
155  ana.tx->createBranch<std::vector<float>>("MD_1_r");
156  ana.tx->createBranch<std::vector<float>>("MD_1_x");
157  ana.tx->createBranch<std::vector<float>>("MD_1_y");
158  ana.tx->createBranch<std::vector<float>>("MD_1_z");
159 
160  // Line Segments
161  ana.tx->createBranch<std::vector<float>>("LS_pt");
162  ana.tx->createBranch<std::vector<float>>("LS_eta");
163  ana.tx->createBranch<std::vector<float>>("LS_phi");
164  ana.tx->createBranch<std::vector<int>>("LS_isFake");
165  ana.tx->createBranch<std::vector<int>>("LS_MD_idx0");
166  ana.tx->createBranch<std::vector<int>>("LS_MD_idx1");
167  ana.tx->createBranch<std::vector<float>>("LS_sim_pt");
168  ana.tx->createBranch<std::vector<float>>("LS_sim_eta");
169  ana.tx->createBranch<std::vector<float>>("LS_sim_phi");
170  ana.tx->createBranch<std::vector<float>>("LS_sim_pca_dxy");
171  ana.tx->createBranch<std::vector<float>>("LS_sim_pca_dz");
172  ana.tx->createBranch<std::vector<int>>("LS_sim_q");
173  ana.tx->createBranch<std::vector<int>>("LS_sim_pdgId");
174  ana.tx->createBranch<std::vector<int>>("LS_sim_event");
175  ana.tx->createBranch<std::vector<int>>("LS_sim_bx");
176  ana.tx->createBranch<std::vector<float>>("LS_sim_vx");
177  ana.tx->createBranch<std::vector<float>>("LS_sim_vy");
178  ana.tx->createBranch<std::vector<float>>("LS_sim_vz");
179  ana.tx->createBranch<std::vector<int>>("LS_isInTrueTC");
180 
181  // TC's LS
182  ana.tx->createBranch<std::vector<std::vector<int>>>("tc_lsIdx");
183 }
RooUtil::TTreeX * tx
AnalysisConfig ana
void createBranch(TString, bool=true)

◆ createOptionalOutputBranches()

void createOptionalOutputBranches ( )

Definition at line 54 of file write_lst_ntuple.cc.

References ana, RooUtil::TTreeX::createBranch(), and AnalysisConfig::tx.

Referenced by createOutputBranches().

54  {
55 #ifdef CUT_VALUE_DEBUG
56  // Event-wide branches
57  // ana.tx->createBranch<float>("evt_dummy");
58 
59  // Sim Track branches
60  // NOTE: Must sync with main tc branch in length!!
61  ana.tx->createBranch<std::vector<float>>("sim_dummy");
62 
63  // Track Candidate branches
64  // NOTE: Must sync with main tc branch in length!!
65  ana.tx->createBranch<std::vector<float>>("tc_dummy");
66 
67  // pT5 branches
68  ana.tx->createBranch<std::vector<std::vector<int>>>("pT5_matched_simIdx");
69  ana.tx->createBranch<std::vector<std::vector<int>>>("pT5_hitIdxs");
70  ana.tx->createBranch<std::vector<int>>("sim_pT5_matched");
71  ana.tx->createBranch<std::vector<float>>("pT5_pt");
72  ana.tx->createBranch<std::vector<float>>("pT5_eta");
73  ana.tx->createBranch<std::vector<float>>("pT5_phi");
74  ana.tx->createBranch<std::vector<int>>("pT5_isFake");
75  ana.tx->createBranch<std::vector<int>>("pT5_isDuplicate");
76  ana.tx->createBranch<std::vector<int>>("pT5_score");
77  ana.tx->createBranch<std::vector<int>>("pT5_layer_binary");
78  ana.tx->createBranch<std::vector<int>>("pT5_moduleType_binary");
79  ana.tx->createBranch<std::vector<float>>("pT5_matched_pt");
80  ana.tx->createBranch<std::vector<float>>("pT5_rzChiSquared");
81  ana.tx->createBranch<std::vector<float>>("pT5_rPhiChiSquared");
82  ana.tx->createBranch<std::vector<float>>("pT5_rPhiChiSquaredInwards");
83 
84  // pT3 branches
85  ana.tx->createBranch<std::vector<int>>("sim_pT3_matched");
86  ana.tx->createBranch<std::vector<float>>("pT3_pt");
87  ana.tx->createBranch<std::vector<int>>("pT3_isFake");
88  ana.tx->createBranch<std::vector<int>>("pT3_isDuplicate");
89  ana.tx->createBranch<std::vector<float>>("pT3_eta");
90  ana.tx->createBranch<std::vector<float>>("pT3_phi");
91  ana.tx->createBranch<std::vector<float>>("pT3_score");
92  ana.tx->createBranch<std::vector<int>>("pT3_foundDuplicate");
93  ana.tx->createBranch<std::vector<std::vector<int>>>("pT3_matched_simIdx");
94  ana.tx->createBranch<std::vector<std::vector<int>>>("pT3_hitIdxs");
95  ana.tx->createBranch<std::vector<float>>("pT3_pixelRadius");
96  ana.tx->createBranch<std::vector<float>>("pT3_pixelRadiusError");
97  ana.tx->createBranch<std::vector<std::vector<float>>>("pT3_matched_pt");
98  ana.tx->createBranch<std::vector<float>>("pT3_tripletRadius");
99  ana.tx->createBranch<std::vector<float>>("pT3_rPhiChiSquared");
100  ana.tx->createBranch<std::vector<float>>("pT3_rPhiChiSquaredInwards");
101  ana.tx->createBranch<std::vector<float>>("pT3_rzChiSquared");
102  ana.tx->createBranch<std::vector<int>>("pT3_layer_binary");
103  ana.tx->createBranch<std::vector<int>>("pT3_moduleType_binary");
104 
105  // pLS branches
106  ana.tx->createBranch<std::vector<int>>("sim_pLS_matched");
107  ana.tx->createBranch<std::vector<std::vector<int>>>("sim_pLS_types");
108  ana.tx->createBranch<std::vector<int>>("pLS_isFake");
109  ana.tx->createBranch<std::vector<int>>("pLS_isDuplicate");
110  ana.tx->createBranch<std::vector<float>>("pLS_pt");
111  ana.tx->createBranch<std::vector<float>>("pLS_eta");
112  ana.tx->createBranch<std::vector<float>>("pLS_phi");
113  ana.tx->createBranch<std::vector<float>>("pLS_score");
114 
115  // T5 branches
116  ana.tx->createBranch<std::vector<int>>("sim_T5_matched");
117  ana.tx->createBranch<std::vector<int>>("t5_isFake");
118  ana.tx->createBranch<std::vector<int>>("t5_isDuplicate");
119  ana.tx->createBranch<std::vector<int>>("t5_foundDuplicate");
120  ana.tx->createBranch<std::vector<float>>("t5_pt");
121  ana.tx->createBranch<std::vector<float>>("t5_eta");
122  ana.tx->createBranch<std::vector<float>>("t5_phi");
123  ana.tx->createBranch<std::vector<float>>("t5_score_rphisum");
124  ana.tx->createBranch<std::vector<std::vector<int>>>("t5_hitIdxs");
125  ana.tx->createBranch<std::vector<std::vector<int>>>("t5_matched_simIdx");
126  ana.tx->createBranch<std::vector<int>>("t5_moduleType_binary");
127  ana.tx->createBranch<std::vector<int>>("t5_layer_binary");
128  ana.tx->createBranch<std::vector<float>>("t5_matched_pt");
129  ana.tx->createBranch<std::vector<int>>("t5_partOfTC");
130  ana.tx->createBranch<std::vector<float>>("t5_innerRadius");
131  ana.tx->createBranch<std::vector<float>>("t5_outerRadius");
132  ana.tx->createBranch<std::vector<float>>("t5_bridgeRadius");
133  ana.tx->createBranch<std::vector<float>>("t5_chiSquared");
134  ana.tx->createBranch<std::vector<float>>("t5_rzChiSquared");
135  ana.tx->createBranch<std::vector<float>>("t5_nonAnchorChiSquared");
136 
137 #endif
138 }
RooUtil::TTreeX * tx
AnalysisConfig ana
void createBranch(TString, bool=true)

◆ createOutputBranches()

void createOutputBranches ( )

Definition at line 6 of file write_lst_ntuple.cc.

References createOptionalOutputBranches(), and createRequiredOutputBranches().

Referenced by run_lst().

6  {
9 }
void createOptionalOutputBranches()
void createRequiredOutputBranches()

◆ createRequiredOutputBranches()

void createRequiredOutputBranches ( )

Definition at line 26 of file write_lst_ntuple.cc.

References ana, RooUtil::TTreeX::createBranch(), and AnalysisConfig::tx.

Referenced by createOutputBranches().

26  {
27  // Setup output TTree
28  ana.tx->createBranch<std::vector<float>>("sim_pt");
29  ana.tx->createBranch<std::vector<float>>("sim_eta");
30  ana.tx->createBranch<std::vector<float>>("sim_phi");
31  ana.tx->createBranch<std::vector<float>>("sim_pca_dxy");
32  ana.tx->createBranch<std::vector<float>>("sim_pca_dz");
33  ana.tx->createBranch<std::vector<int>>("sim_q");
34  ana.tx->createBranch<std::vector<int>>("sim_event");
35  ana.tx->createBranch<std::vector<int>>("sim_pdgId");
36  ana.tx->createBranch<std::vector<float>>("sim_vx");
37  ana.tx->createBranch<std::vector<float>>("sim_vy");
38  ana.tx->createBranch<std::vector<float>>("sim_vz");
39  ana.tx->createBranch<std::vector<float>>("sim_trkNtupIdx");
40  ana.tx->createBranch<std::vector<int>>("sim_TC_matched");
41  ana.tx->createBranch<std::vector<int>>("sim_TC_matched_mask");
42 
43  // Track candidates
44  ana.tx->createBranch<std::vector<float>>("tc_pt");
45  ana.tx->createBranch<std::vector<float>>("tc_eta");
46  ana.tx->createBranch<std::vector<float>>("tc_phi");
47  ana.tx->createBranch<std::vector<int>>("tc_type");
48  ana.tx->createBranch<std::vector<int>>("tc_isFake");
49  ana.tx->createBranch<std::vector<int>>("tc_isDuplicate");
50  ana.tx->createBranch<std::vector<std::vector<int>>>("tc_matched_simIdx");
51 }
RooUtil::TTreeX * tx
AnalysisConfig ana
void createBranch(TString, bool=true)

◆ fillOutputBranches()

void fillOutputBranches ( LSTEvent event)

Definition at line 12 of file write_lst_ntuple.cc.

References ana, RooUtil::TTreeX::clear(), RooUtil::TTreeX::fill(), AnalysisConfig::gnn_ntuple, setGnnNtupleBranches(), setOptionalOutputBranches(), setOutputBranches(), and AnalysisConfig::tx.

Referenced by run_lst().

12  {
15  if (ana.gnn_ntuple)
17 
18  // Now actually fill the ttree
19  ana.tx->fill();
20 
21  // Then clear the branches to default values (e.g. -999, or clear the vectors to empty vectors)
22  ana.tx->clear();
23 }
void setGnnNtupleBranches(LSTEvent *event)
RooUtil::TTreeX * tx
AnalysisConfig ana
void setOutputBranches(LSTEvent *event)
void setOptionalOutputBranches(LSTEvent *event)
Definition: event.py:1
void fill()
Definition: ttreex.h:122
void clear()
Definition: ttreex.cc:40

◆ parsepLS()

std::tuple<float, float, float, std::vector<unsigned int>, std::vector<unsigned int> > parsepLS ( LSTEvent event,
unsigned int  idx 
)

Definition at line 923 of file write_lst_ntuple.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), getPixelHitIdxsFrompLS(), getPixelHitTypesFrompLS(), heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), pLS, and DiDispStaMuonMonitor_cfi::pt.

Referenced by parseTrackCandidate().

924  {
925  auto const& trackCandidates = event->getTrackCandidates();
926  SegmentsPixelConst segmentsPixel = event->getSegments<SegmentsPixelSoA>();
927 
928  // Getting pLS index
929  unsigned int pLS = trackCandidates.directObjectIndices()[idx];
930 
931  // Getting pt eta and phi
932  float pt = segmentsPixel.ptIn()[pLS];
933  float eta = segmentsPixel.eta()[pLS];
934  float phi = segmentsPixel.phi()[pLS];
935 
936  // Getting hit indices and types
937  std::vector<unsigned int> hit_idx = getPixelHitIdxsFrompLS(event, pLS);
938  std::vector<unsigned int> hit_type = getPixelHitTypesFrompLS(event, pLS);
939 
940  return {pt, eta, phi, hit_idx, hit_type};
941 }
std::vector< unsigned int > getPixelHitIdxsFrompLS(LSTEvent *event, unsigned int pLS)
Definition: AccessHelper.cc:49
std::vector< unsigned int > getPixelHitTypesFrompLS(LSTEvent *event, unsigned int pLS)
Definition: AccessHelper.cc:59
SegmentsPixelSoALayout<> SegmentsPixelSoA
Definition: SegmentsSoA.h:46
SegmentsPixelSoA::ConstView SegmentsPixelConst
Definition: SegmentsSoA.h:53
Definition: event.py:1

◆ parsepT3()

std::tuple<float, float, float, std::vector<unsigned int>, std::vector<unsigned int> > parsepT3 ( LSTEvent event,
unsigned int  idx 
)

Definition at line 854 of file write_lst_ntuple.cc.

References getHitIdxsFrompT3(), getHitTypesFrompT3(), getPixelLSFrompT3(), getT3FrompT3(), heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::lst::k2Rinv1GeVf, pLS, DiDispStaMuonMonitor_cfi::pt, and pT3.

Referenced by parseTrackCandidate().

855  {
856  // Get relevant information
857  auto const trackCandidates = event->getTrackCandidates();
858  auto const triplets = event->getTriplets<TripletsSoA>();
859  auto const segmentsPixel = event->getSegments<SegmentsPixelSoA>();
860 
861  //
862  // pictorial representation of a pT3
863  //
864  // inner tracker outer tracker
865  // ------------- --------------------------
866  // pLS 01 23 45 (anchor hit of a minidoublet is always the first of the pair)
867  // **** oo -- oo -- oo pT3
868  unsigned int pT3 = trackCandidates.directObjectIndices()[idx];
869  unsigned int pLS = getPixelLSFrompT3(event, pT3);
870  unsigned int T3 = getT3FrompT3(event, pT3);
871 
872  // pixel pt
873  const float pt_pLS = segmentsPixel.ptIn()[pLS];
874  const float eta_pLS = segmentsPixel.eta()[pLS];
875  const float phi_pLS = segmentsPixel.phi()[pLS];
876  float pt_T3 = triplets.radius()[T3] * 2 * k2Rinv1GeVf;
877 
878  // average pt
879  const float pt = (pt_pLS + pt_T3) / 2;
880 
881  // Form the hit idx/type std::vector
882  std::vector<unsigned int> hit_idx = getHitIdxsFrompT3(event, pT3);
883  std::vector<unsigned int> hit_type = getHitTypesFrompT3(event, pT3);
884 
885  return {pt, eta_pLS, phi_pLS, hit_idx, hit_type};
886 }
std::vector< unsigned int > getHitTypesFrompT3(LSTEvent *event, unsigned int pT3)
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float k2Rinv1GeVf
Definition: Common.h:49
std::vector< unsigned int > getHitIdxsFrompT3(LSTEvent *event, unsigned int pT3)
unsigned int getPixelLSFrompT3(LSTEvent *event, unsigned int pT3)
SegmentsPixelSoALayout<> SegmentsPixelSoA
Definition: SegmentsSoA.h:46
unsigned int getT3FrompT3(LSTEvent *event, unsigned int pT3)
TripletsSoALayout<> TripletsSoA
Definition: TripletsSoA.h:29
Definition: event.py:1

◆ parsepT5()

std::tuple<float, float, float, std::vector<unsigned int>, std::vector<unsigned int> > parsepT5 ( LSTEvent event,
unsigned int  idx 
)

Definition at line 742 of file write_lst_ntuple.cc.

References __H2F, getHitIdxsFrompT5(), getHitTypesFrompT5(), getPixelLSFrompT5(), getT5FrompT5(), heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::lst::k2Rinv1GeVf, pLS, DiDispStaMuonMonitor_cfi::pt, and pT5.

Referenced by parseTrackCandidate().

743  {
744  // Get relevant information
745  auto const trackCandidates = event->getTrackCandidates();
746  auto const quintuplets = event->getQuintuplets<QuintupletsSoA>();
747  auto const segmentsPixel = event->getSegments<SegmentsPixelSoA>();
748 
749  //
750  // pictorial representation of a pT5
751  //
752  // inner tracker outer tracker
753  // ------------- --------------------------
754  // pLS 01 23 45 67 89 (anchor hit of a minidoublet is always the first of the pair)
755  // **** oo -- oo -- oo -- oo -- oo pT5
756  // oo -- oo -- oo first T3 of the T5
757  // oo -- oo -- oo second T3 of the T5
758  unsigned int pT5 = trackCandidates.directObjectIndices()[idx];
759  unsigned int pLS = getPixelLSFrompT5(event, pT5);
760  unsigned int T5Index = getT5FrompT5(event, pT5);
761 
762  //=================================================================================
763  // Some history and geometry lesson...
764  // For a given T3, we compute two angles. (NOTE: This is a bit weird!)
765  // Historically, T3 were created out of T4, which we used to build a long time ago.
766  // So for the sake of argument let's discuss T4 first.
767  // For a T4, we have 4 mini-doublets.
768  // Therefore we have 4 "anchor hits".
769  // Therefore we have 4 xyz points.
770  //
771  //
772  // *
773  // |\
774  // | \
775  // |1 \
776  // | \
777  // | * \
778  // |
779  // |
780  // |
781  // |
782  // |
783  // | * /
784  // | /
785  // |2 /
786  // | /
787  // |/
788  // *
789  //
790  //
791  // Then from these 4 points, one can approximate a some sort of "best" fitted circle trajectory,
792  // and obtain "tangential" angles from 1st and 4th hits.
793  // See the carton below.
794  // The "*" are the 4 physical hit points
795  // angle 1 and 2 are the "tangential" angle for a "circle" from 4 * points.
796  // Please note, that a straight line from first two * and the latter two * are NOT the
797  // angle 1 and angle 2. (they were called "beta" angles)
798  // But rather, a slightly larger angle.
799  // Because 4 * points would be on a circle, and a tangential line on the circles
800  // would deviate from the points on circles.
801  //
802  // In the early days of LST, there was an iterative algorithm (devised by Slava) to
803  // obtain the angle beta1 and 2 _without_ actually performing a 4 point circle fit.
804  // Hence, the beta1 and beta2 were quickly estimated without too many math operations
805  // and afterwards (beta1-beta2) was computed to obtain what we call a "delta-beta" values.
806  //
807  // For a real track, the deltabeta ~ 0, for fakes, it'd have a flat distribution.
808  //
809  // However, after some time we abandonded the T4s, and moved to T3s.
810  // In T3, however, now we have the following cartoon:
811  //
812  // *
813  // |\
814  // | \
815  // |1 \
816  // | \
817  // | * X (* here are "two" MDs but really just one)
818  // | /
819  // |2 /
820  // | /
821  // |/
822  // *
823  //
824  // With the "four" *'s (really just "three") you can still run the iterative beta calculation,
825  // which is what we still currently do, we still get two beta1 and beta2
826  // But! high school geometry tells us that 3 points = ONLY 1 possible CIRCLE!
827  // There is really nothing to "fit" here.
828  // YET we still compute these in T3, out of legacy method of how we used to treat T4s.
829  //
830  // Hence, in the below code, "betaIn_in" and "betaOut_in" if we performed
831  // a circle fit they would come out by definition identical values.
832  // But due to our approximate iterative beta calculation method, they come out different values.
833  // So if we are "cutting on" abs(deltaBeta) = abs(betaIn_in - betaOut_in) < threshold,
834  // what does that even mean?
835  //
836  // Anyhow, as of now, we compute 2 beta's for T3s, and T5 has two T3s.
837  // And from there we estimate the pt's and we compute pt_T5.
838 
839  // pixel pt
840  const float pt_pLS = segmentsPixel.ptIn()[pLS];
841  const float eta_pLS = segmentsPixel.eta()[pLS];
842  const float phi_pLS = segmentsPixel.phi()[pLS];
843  float pt_T5 = __H2F(quintuplets.innerRadius()[T5Index]) * 2 * k2Rinv1GeVf;
844  const float pt = (pt_T5 + pt_pLS) / 2;
845 
846  // Form the hit idx/type std::vector
847  std::vector<unsigned int> hit_idx = getHitIdxsFrompT5(event, pT5);
848  std::vector<unsigned int> hit_type = getHitTypesFrompT5(event, pT5);
849 
850  return {pt, eta_pLS, phi_pLS, hit_idx, hit_type};
851 }
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float k2Rinv1GeVf
Definition: Common.h:49
std::vector< unsigned int > getHitIdxsFrompT5(LSTEvent *event, unsigned int pT5)
unsigned int getT5FrompT5(LSTEvent *event, unsigned int pT5)
#define __H2F
Definition: Common.h:50
QuintupletsSoALayout<> QuintupletsSoA
unsigned int getPixelLSFrompT5(LSTEvent *event, unsigned int pT5)
SegmentsPixelSoALayout<> SegmentsPixelSoA
Definition: SegmentsSoA.h:46
std::vector< unsigned int > getHitTypesFrompT5(LSTEvent *event, unsigned int pT5)
Definition: event.py:1

◆ parseT5()

std::tuple<float, float, float, std::vector<unsigned int>, std::vector<unsigned int> > parseT5 ( LSTEvent event,
unsigned int  idx 
)

Definition at line 889 of file write_lst_ntuple.cc.

References __H2F, ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), getHitIdxsFromT5(), getHitsFromT5(), getHitTypesFromT5(), hfClusterShapes_cfi::hits, heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::lst::k2Rinv1GeVf, Trktree::ph2_x(), Trktree::ph2_y(), Trktree::ph2_z(), ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), DiDispStaMuonMonitor_cfi::pt, T5, and trk.

Referenced by parseTrackCandidate().

890  {
891  auto const trackCandidates = event->getTrackCandidates();
892  auto const quintuplets = event->getQuintuplets<QuintupletsSoA>();
893  unsigned int T5 = trackCandidates.directObjectIndices()[idx];
894  std::vector<unsigned int> hits = getHitsFromT5(event, T5);
895 
896  //
897  // pictorial representation of a T5
898  //
899  // inner tracker outer tracker
900  // ------------- --------------------------
901  // 01 23 45 67 89 (anchor hit of a minidoublet is always the first of the pair)
902  // (none) oo -- oo -- oo -- oo -- oo T5
903  unsigned int Hit_0 = hits[0];
904  unsigned int Hit_4 = hits[4];
905  unsigned int Hit_8 = hits[8];
906 
907  // T5 radius is average of the inner and outer radius
908  const float pt = __H2F(quintuplets.innerRadius()[T5]) * k2Rinv1GeVf * 2;
909 
910  // T5 eta and phi are computed using outer and innermost hits
911  lst_math::Hit hitA(trk.ph2_x()[Hit_0], trk.ph2_y()[Hit_0], trk.ph2_z()[Hit_0]);
912  lst_math::Hit hitB(trk.ph2_x()[Hit_8], trk.ph2_y()[Hit_8], trk.ph2_z()[Hit_8]);
913  const float phi = hitA.phi();
914  const float eta = hitB.eta();
915 
916  std::vector<unsigned int> hit_idx = getHitIdxsFromT5(event, T5);
917  std::vector<unsigned int> hit_type = getHitTypesFromT5(event, T5);
918 
919  return {pt, eta, phi, hit_idx, hit_type};
920 }
Definition: performance.cc:3
const std::vector< float > & ph2_z()
Definition: Trktree.cc:4905
std::vector< unsigned int > getHitsFromT5(LSTEvent *event, unsigned int T5)
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float k2Rinv1GeVf
Definition: Common.h:49
const std::vector< float > & ph2_y()
Definition: Trktree.cc:4929
std::vector< unsigned int > getHitTypesFromT5(LSTEvent *event, unsigned int T5)
Trktree trk
Definition: Trktree.cc:2
#define __H2F
Definition: Common.h:50
const std::vector< float > & ph2_x()
Definition: Trktree.cc:4917
std::vector< unsigned int > getHitIdxsFromT5(LSTEvent *event, unsigned int T5)
QuintupletsSoALayout<> QuintupletsSoA
Definition: event.py:1

◆ parseTrackCandidate()

std::tuple<int, float, float, float, int, std::vector<int> > parseTrackCandidate ( LSTEvent event,
unsigned int  idx 
)

Definition at line 711 of file write_lst_ntuple.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), heavyIonCSV_trainingSettings::idx, matchedSimTrkIdxs(), parsepLS(), parsepT3(), parsepT5(), parseT5(), ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), pLS, DiDispStaMuonMonitor_cfi::pt, pT3, pT5, and T5.

Referenced by setOutputBranches().

711  {
712  // Get the type of the track candidate
713  auto const& trackCandidates = event->getTrackCandidates();
714  short type = trackCandidates.trackCandidateType()[idx];
715 
716  // Compute pt eta phi and hit indices that will be used to figure out whether the TC matched
717  float pt, eta, phi;
718  std::vector<unsigned int> hit_idx, hit_type;
719  switch (type) {
721  std::tie(pt, eta, phi, hit_idx, hit_type) = parsepT5(event, idx);
722  break;
724  std::tie(pt, eta, phi, hit_idx, hit_type) = parsepT3(event, idx);
725  break;
726  case lst::LSTObjType::T5:
727  std::tie(pt, eta, phi, hit_idx, hit_type) = parseT5(event, idx);
728  break;
730  std::tie(pt, eta, phi, hit_idx, hit_type) = parsepLS(event, idx);
731  break;
732  }
733 
734  // Perform matching
735  std::vector<int> simidx = matchedSimTrkIdxs(hit_idx, hit_type);
736  int isFake = simidx.size() == 0;
737 
738  return {type, pt, eta, phi, isFake, simidx};
739 }
Definition: performance.cc:3
std::vector< int > matchedSimTrkIdxs(std::vector< int > hitidxs, std::vector< int > hittypes, bool verbose)
Definition: trkCore.cc:285
std::tuple< float, float, float, std::vector< unsigned int >, std::vector< unsigned int > > parsepT3(LSTEvent *event, unsigned int idx)
std::tuple< float, float, float, std::vector< unsigned int >, std::vector< unsigned int > > parsepLS(LSTEvent *event, unsigned int idx)
std::tuple< float, float, float, std::vector< unsigned int >, std::vector< unsigned int > > parseT5(LSTEvent *event, unsigned int idx)
Definition: event.py:1
std::tuple< float, float, float, std::vector< unsigned int >, std::vector< unsigned int > > parsepT5(LSTEvent *event, unsigned int idx)

◆ printAllObjects()

void printAllObjects ( LSTEvent event)

Definition at line 978 of file write_lst_ntuple.cc.

References printLSs(), printMDs(), printpLSs(), and printT3s().

978  {
979  printMDs(event);
980  printLSs(event);
981  printpLSs(event);
982  printT3s(event);
983 }
void printMDs(LSTEvent *event)
void printpLSs(LSTEvent *event)
Definition: event.py:1
void printLSs(LSTEvent *event)
void printT3s(LSTEvent *event)

◆ printHitMultiplicities()

void printHitMultiplicities ( LSTEvent event)

Definition at line 944 of file write_lst_ntuple.cc.

References gather_cfg::cout, heavyIonCSV_trainingSettings::idx, and nHits.

944  {
945  auto modules = event->getModules<ModulesSoA>();
946  auto hitRanges = event->getHits<HitsRangesSoA>();
947 
948  int nHits = 0;
949  for (unsigned int idx = 0; idx <= modules.nLowerModules();
950  idx++) // "<=" because cheating to include pixel track candidate lower module
951  {
952  nHits += hitRanges.hitRanges()[2 * idx][1] - hitRanges.hitRanges()[2 * idx][0] + 1;
953  nHits += hitRanges.hitRanges()[2 * idx + 1][1] - hitRanges.hitRanges()[2 * idx + 1][0] + 1;
954  }
955  std::cout << " nHits: " << nHits << std::endl;
956 }
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
HitsRangesSoALayout<> HitsRangesSoA
Definition: HitsSoA.h:30
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits

◆ printLSs()

void printLSs ( LSTEvent event)

Definition at line 1009 of file write_lst_ntuple.cc.

References gather_cfg::cout, mps_fire::i, heavyIonCSV_trainingSettings::idx, and diffTwoXMLs::ranges.

Referenced by printAllObjects().

1009  {
1010  SegmentsConst segments = event->getSegments<SegmentsSoA>();
1011  SegmentsOccupancyConst segmentsOccupancy = event->getSegments<SegmentsOccupancySoA>();
1012  MiniDoubletsConst miniDoublets = event->getMiniDoublets<MiniDoubletsSoA>();
1013  auto hitsEvt = event->getHits<HitsSoA>();
1014  auto modules = event->getModules<ModulesSoA>();
1015  auto ranges = event->getRanges();
1016 
1017  int nSegments = 0;
1018  for (unsigned int i = 0; i < modules.nLowerModules(); ++i) {
1019  unsigned int idx = i; //modules->lowerModuleIndices[i];
1020  nSegments += segmentsOccupancy.nSegments()[idx];
1021  for (unsigned int jdx = 0; jdx < segmentsOccupancy.nSegments()[idx]; jdx++) {
1022  unsigned int sgIdx = ranges.segmentModuleIndices()[idx] + jdx;
1023  unsigned int InnerMiniDoubletIndex = segments.mdIndices()[sgIdx][0];
1024  unsigned int OuterMiniDoubletIndex = segments.mdIndices()[sgIdx][1];
1025  unsigned int InnerMiniDoubletLowerHitIndex = miniDoublets.anchorHitIndices()[InnerMiniDoubletIndex];
1026  unsigned int InnerMiniDoubletUpperHitIndex = miniDoublets.outerHitIndices()[InnerMiniDoubletIndex];
1027  unsigned int OuterMiniDoubletLowerHitIndex = miniDoublets.anchorHitIndices()[OuterMiniDoubletIndex];
1028  unsigned int OuterMiniDoubletUpperHitIndex = miniDoublets.outerHitIndices()[OuterMiniDoubletIndex];
1029  unsigned int hit0 = hitsEvt.idxs()[InnerMiniDoubletLowerHitIndex];
1030  unsigned int hit1 = hitsEvt.idxs()[InnerMiniDoubletUpperHitIndex];
1031  unsigned int hit2 = hitsEvt.idxs()[OuterMiniDoubletLowerHitIndex];
1032  unsigned int hit3 = hitsEvt.idxs()[OuterMiniDoubletUpperHitIndex];
1033  std::cout << "VALIDATION 'LS': "
1034  << "LS"
1035  << " hit0: " << hit0 << " hit1: " << hit1 << " hit2: " << hit2 << " hit3: " << hit3 << std::endl;
1036  }
1037  }
1038  std::cout << "VALIDATION nSegments: " << nSegments << std::endl;
1039 }
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
SegmentsOccupancySoALayout<> SegmentsOccupancySoA
Definition: SegmentsSoA.h:45
SegmentsSoALayout<> SegmentsSoA
Definition: SegmentsSoA.h:44
MiniDoubletsSoA::ConstView MiniDoubletsConst
HitsSoALayout<> HitsSoA
Definition: HitsSoA.h:29
MiniDoubletsSoALayout<> MiniDoubletsSoA
string ranges
Definition: diffTwoXMLs.py:79
SegmentsOccupancySoA::ConstView SegmentsOccupancyConst
Definition: SegmentsSoA.h:51
SegmentsSoA::ConstView SegmentsConst
Definition: SegmentsSoA.h:49

◆ printMDs()

void printMDs ( LSTEvent event)

Definition at line 986 of file write_lst_ntuple.cc.

References gather_cfg::cout, heavyIonCSV_trainingSettings::idx, and diffTwoXMLs::ranges.

Referenced by printAllObjects().

986  {
987  MiniDoubletsConst miniDoublets = event->getMiniDoublets<MiniDoubletsSoA>();
988  MiniDoubletsOccupancyConst miniDoubletsOccupancy = event->getMiniDoublets<MiniDoubletsOccupancySoA>();
989  auto hitsEvt = event->getHits<HitsSoA>();
990  auto modules = event->getModules<ModulesSoA>();
991  auto ranges = event->getRanges();
992 
993  // Then obtain the lower module index
994  for (unsigned int idx = 0; idx <= modules.nLowerModules(); ++idx) {
995  for (unsigned int iMD = 0; iMD < miniDoubletsOccupancy.nMDs()[idx]; iMD++) {
996  unsigned int mdIdx = ranges.miniDoubletModuleIndices()[idx] + iMD;
997  unsigned int LowerHitIndex = miniDoublets.anchorHitIndices()[mdIdx];
998  unsigned int UpperHitIndex = miniDoublets.outerHitIndices()[mdIdx];
999  unsigned int hit0 = hitsEvt.idxs()[LowerHitIndex];
1000  unsigned int hit1 = hitsEvt.idxs()[UpperHitIndex];
1001  std::cout << "VALIDATION 'MD': "
1002  << "MD"
1003  << " hit0: " << hit0 << " hit1: " << hit1 << std::endl;
1004  }
1005  }
1006 }
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
MiniDoubletsOccupancySoALayout<> MiniDoubletsOccupancySoA
MiniDoubletsSoA::ConstView MiniDoubletsConst
HitsSoALayout<> HitsSoA
Definition: HitsSoA.h:29
MiniDoubletsSoALayout<> MiniDoubletsSoA
string ranges
Definition: diffTwoXMLs.py:79
MiniDoubletsOccupancySoA::ConstView MiniDoubletsOccupancyConst

◆ printMiniDoubletMultiplicities()

void printMiniDoubletMultiplicities ( LSTEvent event)

Definition at line 959 of file write_lst_ntuple.cc.

References gather_cfg::cout, and heavyIonCSV_trainingSettings::idx.

959  {
960  MiniDoubletsOccupancyConst miniDoublets = event->getMiniDoublets<MiniDoubletsOccupancySoA>();
961  auto modules = event->getModules<ModulesSoA>();
962 
963  int nMiniDoublets = 0;
964  int totOccupancyMiniDoublets = 0;
965  for (unsigned int idx = 0; idx <= modules.nModules();
966  idx++) // "<=" because cheating to include pixel track candidate lower module
967  {
968  if (modules.isLower()[idx]) {
969  nMiniDoublets += miniDoublets.nMDs()[idx];
970  totOccupancyMiniDoublets += miniDoublets.totOccupancyMDs()[idx];
971  }
972  }
973  std::cout << " nMiniDoublets: " << nMiniDoublets << std::endl;
974  std::cout << " totOccupancyMiniDoublets (including trucated ones): " << totOccupancyMiniDoublets << std::endl;
975 }
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
MiniDoubletsOccupancySoALayout<> MiniDoubletsOccupancySoA
MiniDoubletsOccupancySoA::ConstView MiniDoubletsOccupancyConst

◆ printpLSs()

void printpLSs ( LSTEvent event)

Definition at line 1042 of file write_lst_ntuple.cc.

References gather_cfg::cout, mps_fire::i, heavyIonCSV_trainingSettings::idx, and diffTwoXMLs::ranges.

Referenced by printAllObjects().

1042  {
1043  SegmentsConst segments = event->getSegments<SegmentsSoA>();
1044  SegmentsOccupancyConst segmentsOccupancy = event->getSegments<SegmentsOccupancySoA>();
1045  MiniDoubletsConst miniDoublets = event->getMiniDoublets<MiniDoubletsSoA>();
1046  auto hitsEvt = event->getHits<HitsSoA>();
1047  auto modules = event->getModules<ModulesSoA>();
1048  auto ranges = event->getRanges();
1049 
1050  unsigned int i = modules.nLowerModules();
1051  unsigned int idx = i; //modules->lowerModuleIndices[i];
1052  int npLS = segmentsOccupancy.nSegments()[idx];
1053  for (unsigned int jdx = 0; jdx < segmentsOccupancy.nSegments()[idx]; jdx++) {
1054  unsigned int sgIdx = ranges.segmentModuleIndices()[idx] + jdx;
1055  unsigned int InnerMiniDoubletIndex = segments.mdIndices()[sgIdx][0];
1056  unsigned int OuterMiniDoubletIndex = segments.mdIndices()[sgIdx][1];
1057  unsigned int InnerMiniDoubletLowerHitIndex = miniDoublets.anchorHitIndices()[InnerMiniDoubletIndex];
1058  unsigned int InnerMiniDoubletUpperHitIndex = miniDoublets.outerHitIndices()[InnerMiniDoubletIndex];
1059  unsigned int OuterMiniDoubletLowerHitIndex = miniDoublets.anchorHitIndices()[OuterMiniDoubletIndex];
1060  unsigned int OuterMiniDoubletUpperHitIndex = miniDoublets.outerHitIndices()[OuterMiniDoubletIndex];
1061  unsigned int hit0 = hitsEvt.idxs()[InnerMiniDoubletLowerHitIndex];
1062  unsigned int hit1 = hitsEvt.idxs()[InnerMiniDoubletUpperHitIndex];
1063  unsigned int hit2 = hitsEvt.idxs()[OuterMiniDoubletLowerHitIndex];
1064  unsigned int hit3 = hitsEvt.idxs()[OuterMiniDoubletUpperHitIndex];
1065  std::cout << "VALIDATION 'pLS': "
1066  << "pLS"
1067  << " hit0: " << hit0 << " hit1: " << hit1 << " hit2: " << hit2 << " hit3: " << hit3 << std::endl;
1068  }
1069  std::cout << "VALIDATION npLS: " << npLS << std::endl;
1070 }
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
SegmentsOccupancySoALayout<> SegmentsOccupancySoA
Definition: SegmentsSoA.h:45
SegmentsSoALayout<> SegmentsSoA
Definition: SegmentsSoA.h:44
MiniDoubletsSoA::ConstView MiniDoubletsConst
HitsSoALayout<> HitsSoA
Definition: HitsSoA.h:29
MiniDoubletsSoALayout<> MiniDoubletsSoA
string ranges
Definition: diffTwoXMLs.py:79
SegmentsOccupancySoA::ConstView SegmentsOccupancyConst
Definition: SegmentsSoA.h:51
SegmentsSoA::ConstView SegmentsConst
Definition: SegmentsSoA.h:49

◆ printT3s()

void printT3s ( LSTEvent event)

Definition at line 1073 of file write_lst_ntuple.cc.

References gather_cfg::cout, mps_fire::i, and heavyIonCSV_trainingSettings::idx.

Referenced by printAllObjects().

1073  {
1074  auto const triplets = event->getTriplets<TripletsSoA>();
1075  auto const tripletsOccupancy = event->getTriplets<TripletsOccupancySoA>();
1076  SegmentsConst segments = event->getSegments<SegmentsSoA>();
1077  MiniDoubletsConst miniDoublets = event->getMiniDoublets<MiniDoubletsSoA>();
1078  auto hitsEvt = event->getHits<HitsSoA>();
1079  auto modules = event->getModules<ModulesSoA>();
1080  int nTriplets = 0;
1081  for (unsigned int i = 0; i < modules.nLowerModules(); ++i) {
1082  // unsigned int idx = modules->lowerModuleIndices[i];
1083  nTriplets += tripletsOccupancy.nTriplets()[i];
1084  unsigned int idx = i;
1085  for (unsigned int jdx = 0; jdx < tripletsOccupancy.nTriplets()[idx]; jdx++) {
1086  unsigned int tpIdx = idx * 5000 + jdx;
1087  unsigned int InnerSegmentIndex = triplets.segmentIndices()[tpIdx][0];
1088  unsigned int OuterSegmentIndex = triplets.segmentIndices()[tpIdx][1];
1089  unsigned int InnerSegmentInnerMiniDoubletIndex = segments.mdIndices()[InnerSegmentIndex][0];
1090  unsigned int InnerSegmentOuterMiniDoubletIndex = segments.mdIndices()[InnerSegmentIndex][1];
1091  unsigned int OuterSegmentOuterMiniDoubletIndex = segments.mdIndices()[OuterSegmentIndex][1];
1092 
1093  unsigned int hit_idx0 = miniDoublets.anchorHitIndices()[InnerSegmentInnerMiniDoubletIndex];
1094  unsigned int hit_idx1 = miniDoublets.outerHitIndices()[InnerSegmentInnerMiniDoubletIndex];
1095  unsigned int hit_idx2 = miniDoublets.anchorHitIndices()[InnerSegmentOuterMiniDoubletIndex];
1096  unsigned int hit_idx3 = miniDoublets.outerHitIndices()[InnerSegmentOuterMiniDoubletIndex];
1097  unsigned int hit_idx4 = miniDoublets.anchorHitIndices()[OuterSegmentOuterMiniDoubletIndex];
1098  unsigned int hit_idx5 = miniDoublets.outerHitIndices()[OuterSegmentOuterMiniDoubletIndex];
1099 
1100  unsigned int hit0 = hitsEvt.idxs()[hit_idx0];
1101  unsigned int hit1 = hitsEvt.idxs()[hit_idx1];
1102  unsigned int hit2 = hitsEvt.idxs()[hit_idx2];
1103  unsigned int hit3 = hitsEvt.idxs()[hit_idx3];
1104  unsigned int hit4 = hitsEvt.idxs()[hit_idx4];
1105  unsigned int hit5 = hitsEvt.idxs()[hit_idx5];
1106  std::cout << "VALIDATION 'T3': "
1107  << "T3"
1108  << " hit0: " << hit0 << " hit1: " << hit1 << " hit2: " << hit2 << " hit3: " << hit3 << " hit4: " << hit4
1109  << " hit5: " << hit5 << std::endl;
1110  }
1111  }
1112  std::cout << "VALIDATION nTriplets: " << nTriplets << std::endl;
1113 }
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
TripletsOccupancySoALayout<> TripletsOccupancySoA
Definition: TripletsSoA.h:37
SegmentsSoALayout<> SegmentsSoA
Definition: SegmentsSoA.h:44
MiniDoubletsSoA::ConstView MiniDoubletsConst
HitsSoALayout<> HitsSoA
Definition: HitsSoA.h:29
MiniDoubletsSoALayout<> MiniDoubletsSoA
SegmentsSoA::ConstView SegmentsConst
Definition: SegmentsSoA.h:49
TripletsSoALayout<> TripletsSoA
Definition: TripletsSoA.h:29

◆ setGnnNtupleBranches()

void setGnnNtupleBranches ( LSTEvent event)

Definition at line 502 of file write_lst_ntuple.cc.

References ana, gather_cfg::cout, ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), RooUtil::TTreeX::getBranch(), lst_math::getCenterFromThreePoints(), getHitIdxsAndHitTypesFromLS(), getHitIdxsAndHitTypesFromTC(), getHitsFromLS(), getLSsFromTC(), getMDsFromLS(), hfClusterShapes_cfi::hits, heavyIonCSV_trainingSettings::idx, matchedSimTrkIdxs(), ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), DiDispStaMuonMonitor_cfi::pt, lst_math::ptEstimateFromRadius(), RooUtil::TTreeX::pushbackToBranch(), diffTwoXMLs::ranges, setGnnNtupleMiniDoublet(), Trktree::sim_bunchCrossing(), Trktree::sim_eta(), Trktree::sim_event(), Trktree::sim_parentVtxIdx(), Trktree::sim_pca_dxy(), Trktree::sim_pca_dz(), Trktree::sim_pdgId(), Trktree::sim_phi(), Trktree::sim_pt(), Trktree::sim_q(), Trktree::simvtx_x(), Trktree::simvtx_y(), Trktree::simvtx_z(), trk, and AnalysisConfig::tx.

Referenced by fillOutputBranches().

502  {
503  // Get relevant information
504  SegmentsOccupancyConst segmentsOccupancy = event->getSegments<SegmentsOccupancySoA>();
505  MiniDoubletsOccupancyConst miniDoublets = event->getMiniDoublets<MiniDoubletsOccupancySoA>();
506  auto hitsEvt = event->getHits<HitsSoA>();
507  auto modules = event->getModules<ModulesSoA>();
508  auto ranges = event->getRanges();
509  auto const& trackCandidates = event->getTrackCandidates();
510 
511  std::set<unsigned int> mds_used_in_sg;
512  std::map<unsigned int, unsigned int> md_index_map;
513  std::map<unsigned int, unsigned int> sg_index_map;
514 
515  // Loop over modules (lower ones where the MDs are saved)
516  unsigned int nTotalMD = 0;
517  unsigned int nTotalLS = 0;
518  for (unsigned int idx = 0; idx < modules.nLowerModules(); ++idx) {
519  nTotalMD += miniDoublets.nMDs()[idx];
520  nTotalLS += segmentsOccupancy.nSegments()[idx];
521  }
522 
523  std::set<unsigned int> lss_used_in_true_tc;
524  unsigned int nTrackCandidates = trackCandidates.nTrackCandidates();
525  for (unsigned int idx = 0; idx < nTrackCandidates; idx++) {
526  // Only consider true track candidates
527  std::vector<unsigned int> hitidxs;
528  std::vector<unsigned int> hittypes;
529  std::tie(hitidxs, hittypes) = getHitIdxsAndHitTypesFromTC(event, idx);
530  std::vector<int> simidxs = matchedSimTrkIdxs(hitidxs, hittypes);
531  if (simidxs.size() == 0)
532  continue;
533 
534  std::vector<unsigned int> LSs = getLSsFromTC(event, idx);
535  for (auto& LS : LSs) {
536  if (lss_used_in_true_tc.find(LS) == lss_used_in_true_tc.end()) {
537  lss_used_in_true_tc.insert(LS);
538  }
539  }
540  }
541 
542  std::cout << " lss_used_in_true_tc.size(): " << lss_used_in_true_tc.size() << std::endl;
543 
544  // std::cout << " nTotalMD: " << nTotalMD << std::endl;
545  // std::cout << " nTotalLS: " << nTotalLS << std::endl;
546 
547  // Loop over modules (lower ones where the MDs are saved)
548  for (unsigned int idx = 0; idx < modules.nLowerModules(); ++idx) {
549  // // Loop over minidoublets
550  // for (unsigned int jdx = 0; jdx < miniDoublets->nMDs[idx]; jdx++)
551  // {
552  // // Get the actual index to the mini-doublet using ranges
553  // unsigned int mdIdx = ranges->miniDoubletModuleIndices[idx] + jdx;
554 
555  // setGnnNtupleMiniDoublet(event, mdIdx);
556  // }
557 
558  // Loop over segments
559  for (unsigned int jdx = 0; jdx < segmentsOccupancy.nSegments()[idx]; jdx++) {
560  // Get the actual index to the segments using ranges
561  unsigned int sgIdx = ranges.segmentModuleIndices()[idx] + jdx;
562 
563  // Get the hit indices
564  std::vector<unsigned int> MDs = getMDsFromLS(event, sgIdx);
565 
566  if (mds_used_in_sg.find(MDs[0]) == mds_used_in_sg.end()) {
567  mds_used_in_sg.insert(MDs[0]);
568  md_index_map[MDs[0]] = mds_used_in_sg.size() - 1;
570  }
571 
572  if (mds_used_in_sg.find(MDs[1]) == mds_used_in_sg.end()) {
573  mds_used_in_sg.insert(MDs[1]);
574  md_index_map[MDs[1]] = mds_used_in_sg.size() - 1;
576  }
577 
578  ana.tx->pushbackToBranch<int>("LS_MD_idx0", md_index_map[MDs[0]]);
579  ana.tx->pushbackToBranch<int>("LS_MD_idx1", md_index_map[MDs[1]]);
580 
581  std::vector<unsigned int> hits = getHitsFromLS(event, sgIdx);
582 
583  // Computing line segment pt estimate (assuming beam spot is at zero)
584  lst_math::Hit hitA(0, 0, 0);
585  lst_math::Hit hitB(hitsEvt.xs()[hits[0]], hitsEvt.ys()[hits[0]], hitsEvt.zs()[hits[0]]);
586  lst_math::Hit hitC(hitsEvt.xs()[hits[2]], hitsEvt.ys()[hits[2]], hitsEvt.zs()[hits[2]]);
587  lst_math::Hit center = lst_math::getCenterFromThreePoints(hitA, hitB, hitC);
588  float pt = lst_math::ptEstimateFromRadius(center.rt());
589  float eta = hitC.eta();
590  float phi = hitB.phi();
591 
592  ana.tx->pushbackToBranch<float>("LS_pt", pt);
593  ana.tx->pushbackToBranch<float>("LS_eta", eta);
594  ana.tx->pushbackToBranch<float>("LS_phi", phi);
595  // ana.tx->pushbackToBranch<int>("LS_layer0", layer0);
596  // ana.tx->pushbackToBranch<int>("LS_layer1", layer1);
597 
598  std::vector<unsigned int> hitidxs;
599  std::vector<unsigned int> hittypes;
600  std::tie(hitidxs, hittypes) = getHitIdxsAndHitTypesFromLS(event, sgIdx);
601  std::vector<int> simidxs = matchedSimTrkIdxs(hitidxs, hittypes);
602 
603  ana.tx->pushbackToBranch<int>("LS_isFake", simidxs.size() == 0);
604  ana.tx->pushbackToBranch<float>("LS_sim_pt", simidxs.size() > 0 ? trk.sim_pt()[simidxs[0]] : -999);
605  ana.tx->pushbackToBranch<float>("LS_sim_eta", simidxs.size() > 0 ? trk.sim_eta()[simidxs[0]] : -999);
606  ana.tx->pushbackToBranch<float>("LS_sim_phi", simidxs.size() > 0 ? trk.sim_phi()[simidxs[0]] : -999);
607  ana.tx->pushbackToBranch<float>("LS_sim_pca_dxy", simidxs.size() > 0 ? trk.sim_pca_dxy()[simidxs[0]] : -999);
608  ana.tx->pushbackToBranch<float>("LS_sim_pca_dz", simidxs.size() > 0 ? trk.sim_pca_dz()[simidxs[0]] : -999);
609  ana.tx->pushbackToBranch<int>("LS_sim_q", simidxs.size() > 0 ? trk.sim_q()[simidxs[0]] : -999);
610  ana.tx->pushbackToBranch<int>("LS_sim_event", simidxs.size() > 0 ? trk.sim_event()[simidxs[0]] : -999);
611  ana.tx->pushbackToBranch<int>("LS_sim_bx", simidxs.size() > 0 ? trk.sim_bunchCrossing()[simidxs[0]] : -999);
612  ana.tx->pushbackToBranch<int>("LS_sim_pdgId", simidxs.size() > 0 ? trk.sim_pdgId()[simidxs[0]] : -999);
613  ana.tx->pushbackToBranch<float>("LS_sim_vx",
614  simidxs.size() > 0 ? trk.simvtx_x()[trk.sim_parentVtxIdx()[simidxs[0]]] : -999);
615  ana.tx->pushbackToBranch<float>("LS_sim_vy",
616  simidxs.size() > 0 ? trk.simvtx_y()[trk.sim_parentVtxIdx()[simidxs[0]]] : -999);
617  ana.tx->pushbackToBranch<float>("LS_sim_vz",
618  simidxs.size() > 0 ? trk.simvtx_z()[trk.sim_parentVtxIdx()[simidxs[0]]] : -999);
619  ana.tx->pushbackToBranch<int>("LS_isInTrueTC", lss_used_in_true_tc.find(sgIdx) != lss_used_in_true_tc.end());
620 
621  sg_index_map[sgIdx] = ana.tx->getBranch<std::vector<int>>("LS_isFake").size() - 1;
622 
623  // // T5 eta and phi are computed using outer and innermost hits
624  // lst_math::Hit hitA(trk.ph2_x()[anchitidx], trk.ph2_y()[anchitidx], trk.ph2_z()[anchitidx]);
625  // const float phi = hitA.phi();
626  // const float eta = hitA.eta();
627  }
628  }
629 
630  for (unsigned int idx = 0; idx < nTrackCandidates; idx++) {
631  std::vector<unsigned int> LSs = getLSsFromTC(event, idx);
632  std::vector<int> lsIdx;
633  for (auto& LS : LSs) {
634  lsIdx.push_back(sg_index_map[LS]);
635  }
636  ana.tx->pushbackToBranch<std::vector<int>>("tc_lsIdx", lsIdx);
637  }
638 
639  std::cout << " mds_used_in_sg.size(): " << mds_used_in_sg.size() << std::endl;
640 }
size
Write out results.
const std::vector< float > & simvtx_z()
Definition: Trktree.cc:6489
const std::vector< int > & sim_pdgId()
Definition: Trktree.cc:3993
RooUtil::TTreeX * tx
const std::vector< float > & simvtx_x()
Definition: Trktree.cc:5229
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
const std::vector< int > & sim_bunchCrossing()
Definition: Trktree.cc:5661
const std::vector< float > & sim_phi()
Definition: Trktree.cc:5721
const std::vector< int > & sim_event()
Definition: Trktree.cc:3141
std::tuple< std::vector< unsigned int >, std::vector< unsigned int > > getHitIdxsAndHitTypesFromTC(LSTEvent *event, unsigned iTC)
const std::vector< int > & sim_parentVtxIdx()
Definition: Trktree.cc:5817
void pushbackToBranch(TString, T)
AnalysisConfig ana
const T & getBranch(TString, bool=true)
Trktree trk
Definition: Trktree.cc:2
SegmentsOccupancySoALayout<> SegmentsOccupancySoA
Definition: SegmentsSoA.h:45
const std::vector< float > & sim_pca_dz()
Definition: Trktree.cc:5433
std::vector< unsigned int > getMDsFromLS(LSTEvent *event, unsigned int LS)
Definition: AccessHelper.cc:94
const std::vector< float > & sim_pca_dxy()
Definition: Trktree.cc:4833
std::vector< int > matchedSimTrkIdxs(std::vector< int > hitidxs, std::vector< int > hittypes, bool verbose)
Definition: trkCore.cc:285
MiniDoubletsOccupancySoALayout<> MiniDoubletsOccupancySoA
HitsSoALayout<> HitsSoA
Definition: HitsSoA.h:29
const std::vector< float > & sim_pt()
Definition: Trktree.cc:3873
string ranges
Definition: diffTwoXMLs.py:79
std::vector< unsigned int > getLSsFromTC(LSTEvent *event, unsigned int iTC)
SegmentsOccupancySoA::ConstView SegmentsOccupancyConst
Definition: SegmentsSoA.h:51
void setGnnNtupleMiniDoublet(LSTEvent *event, unsigned int MD)
const std::vector< int > & sim_q()
Definition: Trktree.cc:3645
float ptEstimateFromRadius(float radius)
Definition: lst_math.h:34
const std::vector< float > & simvtx_y()
Definition: Trktree.cc:5445
const std::vector< float > & sim_eta()
Definition: Trktree.cc:3189
Hit getCenterFromThreePoints(Hit &hitA, Hit &hitB, Hit &hitC)
Definition: lst_math.h:154
std::vector< unsigned int > getHitsFromLS(LSTEvent *event, unsigned int LS)
MiniDoubletsOccupancySoA::ConstView MiniDoubletsOccupancyConst
std::tuple< std::vector< unsigned int >, std::vector< unsigned int > > getHitIdxsAndHitTypesFromLS(LSTEvent *event, unsigned LS)
Definition: event.py:1

◆ setGnnNtupleMiniDoublet()

void setGnnNtupleMiniDoublet ( LSTEvent event,
unsigned int  MD 
)

Definition at line 643 of file write_lst_ntuple.cc.

References ana, hcalRecHitTable_cff::detId, ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), getDenomSimTrkType(), ALPAKA_ACCELERATOR_NAMESPACE::lst::k2Rinv1GeVf, matchedSimTrkIdxs(), Trktree::ph2_detId(), Trktree::ph2_layer(), Trktree::ph2_subdet(), Trktree::ph2_x(), Trktree::ph2_y(), Trktree::ph2_z(), ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), DiDispStaMuonMonitor_cfi::pt, RooUtil::TTreeX::pushbackToBranch(), funct::sin(), mathSSE::sqrt(), trk, and AnalysisConfig::tx.

Referenced by setGnnNtupleBranches().

643  {
644  // Get relevant information
645  MiniDoubletsConst miniDoublets = event->getMiniDoublets<MiniDoubletsSoA>();
646  auto hitsEvt = event->getHits<HitsSoA>();
647 
648  // Get the hit indices
649  unsigned int hit0 = miniDoublets.anchorHitIndices()[MD];
650  unsigned int hit1 = miniDoublets.outerHitIndices()[MD];
651 
652  // Get the hit infos
653  const float hit0_x = hitsEvt.xs()[hit0];
654  const float hit0_y = hitsEvt.ys()[hit0];
655  const float hit0_z = hitsEvt.zs()[hit0];
656  const float hit0_r = sqrt(hit0_x * hit0_x + hit0_y * hit0_y);
657  const float hit1_x = hitsEvt.xs()[hit1];
658  const float hit1_y = hitsEvt.ys()[hit1];
659  const float hit1_z = hitsEvt.zs()[hit1];
660  const float hit1_r = sqrt(hit1_x * hit1_x + hit1_y * hit1_y);
661 
662  // Do sim matching
663  std::vector<unsigned int> hit_idx = {hitsEvt.idxs()[hit0], hitsEvt.idxs()[hit1]};
664  std::vector<unsigned int> hit_type = {4, 4};
665  std::vector<int> simidxs = matchedSimTrkIdxs(hit_idx, hit_type);
666 
667  bool isFake = simidxs.size() == 0;
668  int tp_type = getDenomSimTrkType(simidxs);
669 
670  // Obtain where the actual hit is located in terms of their layer, module, rod, and ring number
671  unsigned int anchitidx = hitsEvt.idxs()[hit0];
672  int subdet = trk.ph2_subdet()[hitsEvt.idxs()[anchitidx]];
673  int is_endcap = subdet == 4;
674  int layer =
675  trk.ph2_layer()[anchitidx] +
676  6 * (is_endcap); // this accounting makes it so that you have layer 1 2 3 4 5 6 in the barrel, and 7 8 9 10 11 in the endcap. (becuase endcap is ph2_subdet == 4)
677  int detId = trk.ph2_detId()[anchitidx];
678 
679  // Obtaining dPhiChange
680  float dphichange = miniDoublets.dphichanges()[MD];
681 
682  // Computing pt
683  float pt = hit0_r * k2Rinv1GeVf / sin(dphichange);
684 
685  // T5 eta and phi are computed using outer and innermost hits
686  lst_math::Hit hitA(trk.ph2_x()[anchitidx], trk.ph2_y()[anchitidx], trk.ph2_z()[anchitidx]);
687  const float phi = hitA.phi();
688  const float eta = hitA.eta();
689 
690  // Mini Doublets
691  ana.tx->pushbackToBranch<float>("MD_pt", pt);
692  ana.tx->pushbackToBranch<float>("MD_eta", eta);
693  ana.tx->pushbackToBranch<float>("MD_phi", phi);
694  ana.tx->pushbackToBranch<float>("MD_dphichange", dphichange);
695  ana.tx->pushbackToBranch<int>("MD_isFake", isFake);
696  ana.tx->pushbackToBranch<int>("MD_tpType", tp_type);
697  ana.tx->pushbackToBranch<int>("MD_detId", detId);
698  ana.tx->pushbackToBranch<int>("MD_layer", layer);
699  ana.tx->pushbackToBranch<float>("MD_0_r", hit0_r);
700  ana.tx->pushbackToBranch<float>("MD_0_x", hit0_x);
701  ana.tx->pushbackToBranch<float>("MD_0_y", hit0_y);
702  ana.tx->pushbackToBranch<float>("MD_0_z", hit0_z);
703  ana.tx->pushbackToBranch<float>("MD_1_r", hit1_r);
704  ana.tx->pushbackToBranch<float>("MD_1_x", hit1_x);
705  ana.tx->pushbackToBranch<float>("MD_1_y", hit1_y);
706  ana.tx->pushbackToBranch<float>("MD_1_z", hit1_z);
707  // ana.tx->pushbackToBranch<int>("MD_sim_idx", simidxs.size() > 0 ? simidxs[0] : -999);
708 }
RooUtil::TTreeX * tx
const std::vector< unsigned short > & ph2_layer()
Definition: Trktree.cc:6561
const std::vector< float > & ph2_z()
Definition: Trktree.cc:4905
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float k2Rinv1GeVf
Definition: Common.h:49
const std::vector< float > & ph2_y()
Definition: Trktree.cc:4929
void pushbackToBranch(TString, T)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
AnalysisConfig ana
int getDenomSimTrkType(int isimtrk)
Definition: trkCore.cc:452
Trktree trk
Definition: Trktree.cc:2
const std::vector< float > & ph2_x()
Definition: Trktree.cc:4917
T sqrt(T t)
Definition: SSEVec.h:23
std::vector< int > matchedSimTrkIdxs(std::vector< int > hitidxs, std::vector< int > hittypes, bool verbose)
Definition: trkCore.cc:285
MiniDoubletsSoA::ConstView MiniDoubletsConst
HitsSoALayout<> HitsSoA
Definition: HitsSoA.h:29
MiniDoubletsSoALayout<> MiniDoubletsSoA
const std::vector< unsigned int > & ph2_detId()
Definition: Trktree.cc:3441
const std::vector< unsigned short > & ph2_subdet()
Definition: Trktree.cc:6513

◆ setOptionalOutputBranches()

void setOptionalOutputBranches ( LSTEvent event)

Definition at line 281 of file write_lst_ntuple.cc.

References setPixelQuintupletOutputBranches(), setPixelTripletOutputBranches(), and setQuintupletOutputBranches().

Referenced by fillOutputBranches().

281  {
282 #ifdef CUT_VALUE_DEBUG
283 
287 
288 #endif
289 }
void setQuintupletOutputBranches(LSTEvent *event)
void setPixelTripletOutputBranches(LSTEvent *event)
void setPixelQuintupletOutputBranches(LSTEvent *event)
Definition: event.py:1

◆ setOutputBranches()

void setOutputBranches ( LSTEvent event)

Definition at line 186 of file write_lst_ntuple.cc.

References ana, ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), mps_fire::i, heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::isDuplicate(), parseTrackCandidate(), ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), DiDispStaMuonMonitor_cfi::pt, RooUtil::TTreeX::pushbackToBranch(), RooUtil::TTreeX::setBranch(), Trktree::sim_bunchCrossing(), Trktree::sim_eta(), Trktree::sim_event(), Trktree::sim_parentVtxIdx(), Trktree::sim_pca_dxy(), Trktree::sim_pca_dz(), Trktree::sim_pdgId(), Trktree::sim_phi(), Trktree::sim_pt(), Trktree::sim_q(), tas::sim_TC_matched(), tas::sim_TC_matched_mask(), Trktree::simvtx_x(), Trktree::simvtx_y(), Trktree::simvtx_z(), tas::tc_isDuplicate(), tas::tc_matched_simIdx(), trk, and AnalysisConfig::tx.

Referenced by fillOutputBranches().

186  {
187  // ============ Sim tracks =============
188  int n_accepted_simtrk = 0;
189  for (unsigned int isimtrk = 0; isimtrk < trk.sim_pt().size(); ++isimtrk) {
190  // Skip out-of-time pileup
191  if (trk.sim_bunchCrossing()[isimtrk] != 0)
192  continue;
193 
194  // Skip non-hard-scatter
195  if (trk.sim_event()[isimtrk] != 0)
196  continue;
197 
198  ana.tx->pushbackToBranch<float>("sim_pt", trk.sim_pt()[isimtrk]);
199  ana.tx->pushbackToBranch<float>("sim_eta", trk.sim_eta()[isimtrk]);
200  ana.tx->pushbackToBranch<float>("sim_phi", trk.sim_phi()[isimtrk]);
201  ana.tx->pushbackToBranch<float>("sim_pca_dxy", trk.sim_pca_dxy()[isimtrk]);
202  ana.tx->pushbackToBranch<float>("sim_pca_dz", trk.sim_pca_dz()[isimtrk]);
203  ana.tx->pushbackToBranch<int>("sim_q", trk.sim_q()[isimtrk]);
204  ana.tx->pushbackToBranch<int>("sim_event", trk.sim_event()[isimtrk]);
205  ana.tx->pushbackToBranch<int>("sim_pdgId", trk.sim_pdgId()[isimtrk]);
206 
207  // For vertex we need to look it up from simvtx info
208  int vtxidx = trk.sim_parentVtxIdx()[isimtrk];
209  ana.tx->pushbackToBranch<float>("sim_vx", trk.simvtx_x()[vtxidx]);
210  ana.tx->pushbackToBranch<float>("sim_vy", trk.simvtx_y()[vtxidx]);
211  ana.tx->pushbackToBranch<float>("sim_vz", trk.simvtx_z()[vtxidx]);
212 
213  // The trkNtupIdx is the idx in the trackingNtuple
214  ana.tx->pushbackToBranch<float>("sim_trkNtupIdx", isimtrk);
215 
216  // Increase the counter for accepted simtrk
217  n_accepted_simtrk++;
218  }
219 
220  // Intermediate variables to keep track of matched track candidates for a given sim track
221  std::vector<int> sim_TC_matched(n_accepted_simtrk);
222  std::vector<int> sim_TC_matched_mask(n_accepted_simtrk);
223  std::vector<int> sim_TC_matched_for_duplicate(trk.sim_pt().size());
224 
225  // Intermediate variables to keep track of matched sim tracks for a given track candidate
226  std::vector<std::vector<int>> tc_matched_simIdx;
227 
228  // ============ Track candidates =============
229  auto const& trackCandidates = event->getTrackCandidates();
230  unsigned int nTrackCandidates = trackCandidates.nTrackCandidates();
231  for (unsigned int idx = 0; idx < nTrackCandidates; idx++) {
232  // Compute reco quantities of track candidate based on final object
233  int type, isFake;
234  float pt, eta, phi;
235  std::vector<int> simidx;
236  std::tie(type, pt, eta, phi, isFake, simidx) = parseTrackCandidate(event, idx);
237  ana.tx->pushbackToBranch<float>("tc_pt", pt);
238  ana.tx->pushbackToBranch<float>("tc_eta", eta);
239  ana.tx->pushbackToBranch<float>("tc_phi", phi);
240  ana.tx->pushbackToBranch<int>("tc_type", type);
241  ana.tx->pushbackToBranch<int>("tc_isFake", isFake);
242  tc_matched_simIdx.push_back(simidx);
243 
244  // Loop over matched sim idx and increase counter of TC_matched
245  for (auto& idx : simidx) {
246  // NOTE Important to note that the idx of the std::vector<> is same
247  // as the tracking-ntuple's sim track idx ONLY because event==0 and bunchCrossing==0 condition is applied!!
248  // Also do not try to access beyond the event and bunchCrossing
249  if (idx < n_accepted_simtrk) {
250  sim_TC_matched.at(idx) += 1;
251  sim_TC_matched_mask.at(idx) |= (1 << type);
252  }
253  sim_TC_matched_for_duplicate.at(idx) += 1;
254  }
255  }
256 
257  // Using the intermedaite variables to compute whether a given track candidate is a duplicate
258  std::vector<int> tc_isDuplicate(tc_matched_simIdx.size());
259  // Loop over the track candidates
260  for (unsigned int i = 0; i < tc_matched_simIdx.size(); ++i) {
261  bool isDuplicate = false;
262  // Loop over the sim idx matched to this track candidate
263  for (unsigned int isim = 0; isim < tc_matched_simIdx[i].size(); ++isim) {
264  // Using the sim_TC_matched to see whether this track candidate is matched to a sim track that is matched to more than one
265  int simidx = tc_matched_simIdx[i][isim];
266  if (sim_TC_matched_for_duplicate[simidx] > 1) {
267  isDuplicate = true;
268  }
269  }
271  }
272 
273  // Now set the last remaining branches
274  ana.tx->setBranch<std::vector<int>>("sim_TC_matched", sim_TC_matched);
275  ana.tx->setBranch<std::vector<int>>("sim_TC_matched_mask", sim_TC_matched_mask);
276  ana.tx->setBranch<std::vector<std::vector<int>>>("tc_matched_simIdx", tc_matched_simIdx);
277  ana.tx->setBranch<std::vector<int>>("tc_isDuplicate", tc_isDuplicate);
278 }
const std::vector< float > & simvtx_z()
Definition: Trktree.cc:6489
const std::vector< int > & sim_pdgId()
Definition: Trktree.cc:3993
RooUtil::TTreeX * tx
const std::vector< float > & simvtx_x()
Definition: Trktree.cc:5229
const std::vector< int > & sim_bunchCrossing()
Definition: Trktree.cc:5661
const std::vector< float > & sim_phi()
Definition: Trktree.cc:5721
const std::vector< int > & sim_event()
Definition: Trktree.cc:3141
const std::vector< int > & sim_parentVtxIdx()
Definition: Trktree.cc:5817
void pushbackToBranch(TString, T)
AnalysisConfig ana
Trktree trk
Definition: Trktree.cc:2
const std::vector< float > & sim_pca_dz()
Definition: Trktree.cc:5433
std::tuple< int, float, float, float, int, std::vector< int > > parseTrackCandidate(LSTEvent *event, unsigned int idx)
const std::vector< int > & sim_TC_matched_mask()
Definition: LSTEff.cc:3364
const std::vector< float > & sim_pca_dxy()
Definition: Trktree.cc:4833
const std::vector< std::vector< int > > & tc_matched_simIdx()
Definition: LSTEff.cc:3338
void setBranch(TString, T, bool=false, bool=false)
const std::vector< int > & tc_isDuplicate()
Definition: LSTEff.cc:3264
const std::vector< float > & sim_pt()
Definition: Trktree.cc:3873
const std::vector< int > & sim_TC_matched()
Definition: LSTEff.cc:3363
const std::vector< int > & sim_q()
Definition: Trktree.cc:3645
const std::vector< float > & simvtx_y()
Definition: Trktree.cc:5445
const std::vector< float > & sim_eta()
Definition: Trktree.cc:3189
ALPAKA_FN_ACC ALPAKA_FN_INLINE constexpr bool isDuplicate(uint32_t const *__restrict__ status, uint16_t x, uint16_t y)
Definition: event.py:1

◆ setPixelQuintupletOutputBranches()

void setPixelQuintupletOutputBranches ( LSTEvent event)

Definition at line 292 of file write_lst_ntuple.cc.

References __H2F, ana, ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), RooUtil::TTreeX::getBranch(), getHitIdxsFrompT5(), getHitTypesFrompT5(), getModuleIdxsFrompT5(), getPixelLSFrompT5(), getT5FrompT5(), mps_fire::i, heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::isDuplicate(), ALPAKA_ACCELERATOR_NAMESPACE::lst::k2Rinv1GeVf, matchedSimTrkIdxs(), ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), DiDispStaMuonMonitor_cfi::pt, pT5, tas::pT5_isDuplicate(), tas::pT5_matched_simIdx(), RooUtil::TTreeX::pushbackToBranch(), RooUtil::TTreeX::setBranch(), tas::sim_pT5_matched(), and AnalysisConfig::tx.

Referenced by setOptionalOutputBranches().

292  {
293  // ============ pT5 =============
294  auto const pixelQuintuplets = event->getPixelQuintuplets();
295  auto const quintuplets = event->getQuintuplets<QuintupletsSoA>();
296  auto const segmentsPixel = event->getSegments<SegmentsPixelSoA>();
297  auto modules = event->getModules<ModulesSoA>();
298  int n_accepted_simtrk = ana.tx->getBranch<std::vector<int>>("sim_TC_matched").size();
299 
300  unsigned int nPixelQuintuplets = pixelQuintuplets.nPixelQuintuplets();
301  std::vector<int> sim_pT5_matched(n_accepted_simtrk);
302  std::vector<std::vector<int>> pT5_matched_simIdx;
303 
304  for (unsigned int pT5 = 0; pT5 < nPixelQuintuplets; pT5++) {
305  unsigned int T5Index = getT5FrompT5(event, pT5);
306  unsigned int pLSIndex = getPixelLSFrompT5(event, pT5);
307  float pt = (__H2F(quintuplets.innerRadius()[T5Index]) * k2Rinv1GeVf * 2 + segmentsPixel.ptIn()[pLSIndex]) / 2;
308  float eta = segmentsPixel.eta()[pLSIndex];
309  float phi = segmentsPixel.phi()[pLSIndex];
310 
311  std::vector<unsigned int> hit_idx = getHitIdxsFrompT5(event, pT5);
312  std::vector<unsigned int> module_idx = getModuleIdxsFrompT5(event, pT5);
313  std::vector<unsigned int> hit_type = getHitTypesFrompT5(event, pT5);
314 
315  int layer_binary = 1;
316  int moduleType_binary = 0;
317  for (size_t i = 0; i < module_idx.size(); i += 2) {
318  layer_binary |= (1 << (modules.layers()[module_idx[i]] + 6 * (modules.subdets()[module_idx[i]] == 4)));
319  moduleType_binary |= (modules.moduleType()[module_idx[i]] << i);
320  }
321  std::vector<int> simidx = matchedSimTrkIdxs(hit_idx, hit_type);
322  ana.tx->pushbackToBranch<int>("pT5_isFake", static_cast<int>(simidx.size() == 0));
323  ana.tx->pushbackToBranch<float>("pT5_pt", pt);
324  ana.tx->pushbackToBranch<float>("pT5_eta", eta);
325  ana.tx->pushbackToBranch<float>("pT5_phi", phi);
326  ana.tx->pushbackToBranch<int>("pT5_layer_binary", layer_binary);
327  ana.tx->pushbackToBranch<int>("pT5_moduleType_binary", moduleType_binary);
328 
329  pT5_matched_simIdx.push_back(simidx);
330 
331  // Loop over matched sim idx and increase counter of pT5_matched
332  for (auto& idx : simidx) {
333  // NOTE Important to note that the idx of the std::vector<> is same
334  // as the tracking-ntuple's sim track idx ONLY because event==0 and bunchCrossing==0 condition is applied!!
335  // Also do not try to access beyond the event and bunchCrossing
336  if (idx < n_accepted_simtrk) {
337  sim_pT5_matched.at(idx) += 1;
338  }
339  }
340  }
341 
342  // Using the intermedaite variables to compute whether a given track candidate is a duplicate
343  std::vector<int> pT5_isDuplicate(pT5_matched_simIdx.size());
344  // Loop over the track candidates
345  for (unsigned int i = 0; i < pT5_matched_simIdx.size(); ++i) {
346  bool isDuplicate = false;
347  // Loop over the sim idx matched to this track candidate
348  for (unsigned int isim = 0; isim < pT5_matched_simIdx[i].size(); ++isim) {
349  // Using the sim_pT5_matched to see whether this track candidate is matched to a sim track that is matched to more than one
350  int simidx = pT5_matched_simIdx[i][isim];
351  if (simidx < n_accepted_simtrk) {
352  if (sim_pT5_matched[simidx] > 1) {
353  isDuplicate = true;
354  }
355  }
356  }
358  }
359 
360  // Now set the last remaining branches
361  ana.tx->setBranch<std::vector<int>>("sim_pT5_matched", sim_pT5_matched);
362  ana.tx->setBranch<std::vector<std::vector<int>>>("pT5_matched_simIdx", pT5_matched_simIdx);
363  ana.tx->setBranch<std::vector<int>>("pT5_isDuplicate", pT5_isDuplicate);
364 }
size
Write out results.
std::vector< unsigned int > getModuleIdxsFrompT5(LSTEvent *event, unsigned int pT5)
const std::vector< int > & pT5_isDuplicate()
Definition: LSTEff.cc:3261
RooUtil::TTreeX * tx
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float k2Rinv1GeVf
Definition: Common.h:49
void pushbackToBranch(TString, T)
AnalysisConfig ana
const T & getBranch(TString, bool=true)
std::vector< unsigned int > getHitIdxsFrompT5(LSTEvent *event, unsigned int pT5)
unsigned int getT5FrompT5(LSTEvent *event, unsigned int pT5)
#define __H2F
Definition: Common.h:50
QuintupletsSoALayout<> QuintupletsSoA
unsigned int getPixelLSFrompT5(LSTEvent *event, unsigned int pT5)
std::vector< int > matchedSimTrkIdxs(std::vector< int > hitidxs, std::vector< int > hittypes, bool verbose)
Definition: trkCore.cc:285
void setBranch(TString, T, bool=false, bool=false)
const std::vector< std::vector< int > > & pT5_matched_simIdx()
Definition: LSTEff.cc:3283
SegmentsPixelSoALayout<> SegmentsPixelSoA
Definition: SegmentsSoA.h:46
std::vector< unsigned int > getHitTypesFrompT5(LSTEvent *event, unsigned int pT5)
ALPAKA_FN_ACC ALPAKA_FN_INLINE constexpr bool isDuplicate(uint32_t const *__restrict__ status, uint16_t x, uint16_t y)
const std::vector< int > & sim_pT5_matched()
Definition: LSTEff.cc:3387
Definition: event.py:1

◆ setPixelTripletOutputBranches()

void setPixelTripletOutputBranches ( LSTEvent event)

Definition at line 439 of file write_lst_ntuple.cc.

References ana, ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), RooUtil::TTreeX::getBranch(), getHitIdxsFrompT3(), getHitTypesFrompT3(), getModuleIdxsFrompT3(), getPixelLSFrompT3(), getT3FrompT3(), mps_fire::i, heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::isDuplicate(), matchedSimTrkIdxs(), ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), DiDispStaMuonMonitor_cfi::pt, pT3, tas::pT3_isDuplicate(), tas::pT3_matched_simIdx(), RooUtil::TTreeX::pushbackToBranch(), RooUtil::TTreeX::setBranch(), tas::sim_pT3_matched(), and AnalysisConfig::tx.

Referenced by setOptionalOutputBranches().

439  {
440  auto const pixelTriplets = event->getPixelTriplets();
441  auto modules = event->getModules<ModulesSoA>();
442  SegmentsPixelConst segmentsPixel = event->getSegments<SegmentsPixelSoA>();
443  int n_accepted_simtrk = ana.tx->getBranch<std::vector<int>>("sim_TC_matched").size();
444 
445  unsigned int nPixelTriplets = pixelTriplets.nPixelTriplets();
446  std::vector<int> sim_pT3_matched(n_accepted_simtrk);
447  std::vector<std::vector<int>> pT3_matched_simIdx;
448 
449  for (unsigned int pT3 = 0; pT3 < nPixelTriplets; pT3++) {
450  unsigned int T3Index = getT3FrompT3(event, pT3);
451  unsigned int pLSIndex = getPixelLSFrompT3(event, pT3);
452  const float pt = segmentsPixel.ptIn()[pLSIndex];
453 
454  float eta = segmentsPixel.eta()[pLSIndex];
455  float phi = segmentsPixel.phi()[pLSIndex];
456  std::vector<unsigned int> hit_idx = getHitIdxsFrompT3(event, pT3);
457  std::vector<unsigned int> hit_type = getHitTypesFrompT3(event, pT3);
458 
459  std::vector<int> simidx = matchedSimTrkIdxs(hit_idx, hit_type);
460  std::vector<unsigned int> module_idx = getModuleIdxsFrompT3(event, pT3);
461  int layer_binary = 1;
462  int moduleType_binary = 0;
463  for (size_t i = 0; i < module_idx.size(); i += 2) {
464  layer_binary |= (1 << (modules.layers()[module_idx[i]] + 6 * (modules.subdets()[module_idx[i]] == 4)));
465  moduleType_binary |= (modules.moduleType()[module_idx[i]] << i);
466  }
467  ana.tx->pushbackToBranch<int>("pT3_isFake", static_cast<int>(simidx.size() == 0));
468  ana.tx->pushbackToBranch<float>("pT3_pt", pt);
469  ana.tx->pushbackToBranch<float>("pT3_eta", eta);
470  ana.tx->pushbackToBranch<float>("pT3_phi", phi);
471  ana.tx->pushbackToBranch<int>("pT3_layer_binary", layer_binary);
472  ana.tx->pushbackToBranch<int>("pT3_moduleType_binary", moduleType_binary);
473 
474  pT3_matched_simIdx.push_back(simidx);
475 
476  for (auto& idx : simidx) {
477  if (idx < n_accepted_simtrk) {
478  sim_pT3_matched.at(idx) += 1;
479  }
480  }
481  }
482 
483  std::vector<int> pT3_isDuplicate(pT3_matched_simIdx.size());
484  for (unsigned int i = 0; i < pT3_matched_simIdx.size(); i++) {
485  bool isDuplicate = true;
486  for (unsigned int isim = 0; isim < pT3_matched_simIdx[i].size(); isim++) {
487  int simidx = pT3_matched_simIdx[i][isim];
488  if (simidx < n_accepted_simtrk) {
489  if (sim_pT3_matched[simidx] > 1) {
490  isDuplicate = true;
491  }
492  }
493  }
495  }
496  ana.tx->setBranch<std::vector<int>>("sim_pT3_matched", sim_pT3_matched);
497  ana.tx->setBranch<std::vector<std::vector<int>>>("pT3_matched_simIdx", pT3_matched_simIdx);
498  ana.tx->setBranch<std::vector<int>>("pT3_isDuplicate", pT3_isDuplicate);
499 }
size
Write out results.
RooUtil::TTreeX * tx
std::vector< unsigned int > getHitTypesFrompT3(LSTEvent *event, unsigned int pT3)
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
void pushbackToBranch(TString, T)
AnalysisConfig ana
const T & getBranch(TString, bool=true)
const std::vector< std::vector< int > > & pT3_matched_simIdx()
Definition: LSTEff.cc:3392
std::vector< unsigned int > getHitIdxsFrompT3(LSTEvent *event, unsigned int pT3)
const std::vector< int > & pT3_isDuplicate()
Definition: LSTEff.cc:3263
std::vector< int > matchedSimTrkIdxs(std::vector< int > hitidxs, std::vector< int > hittypes, bool verbose)
Definition: trkCore.cc:285
unsigned int getPixelLSFrompT3(LSTEvent *event, unsigned int pT3)
void setBranch(TString, T, bool=false, bool=false)
std::vector< unsigned int > getModuleIdxsFrompT3(LSTEvent *event, unsigned int pT3)
SegmentsPixelSoALayout<> SegmentsPixelSoA
Definition: SegmentsSoA.h:46
SegmentsPixelSoA::ConstView SegmentsPixelConst
Definition: SegmentsSoA.h:53
unsigned int getT3FrompT3(LSTEvent *event, unsigned int pT3)
ALPAKA_FN_ACC ALPAKA_FN_INLINE constexpr bool isDuplicate(uint32_t const *__restrict__ status, uint16_t x, uint16_t y)
const std::vector< int > & sim_pT3_matched()
Definition: LSTEff.cc:3266
Definition: event.py:1

◆ setQuintupletOutputBranches()

void setQuintupletOutputBranches ( LSTEvent event)

Definition at line 367 of file write_lst_ntuple.cc.

References __H2F, ana, ALPAKA_ACCELERATOR_NAMESPACE::lst::eta(), RooUtil::TTreeX::getBranch(), getHitIdxsFromT5(), getHitTypesFromT5(), getModuleIdxsFromT5(), mps_fire::i, heavyIonCSV_trainingSettings::idx, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::isDuplicate(), ALPAKA_ACCELERATOR_NAMESPACE::lst::k2Rinv1GeVf, matchedSimTrkIdxs(), ALPAKA_ACCELERATOR_NAMESPACE::lst::phi(), DiDispStaMuonMonitor_cfi::pt, RooUtil::TTreeX::pushbackToBranch(), diffTwoXMLs::ranges, RooUtil::TTreeX::setBranch(), tas::t5_isDuplicate(), tas::t5_matched_simIdx(), and AnalysisConfig::tx.

Referenced by setOptionalOutputBranches().

367  {
368  auto const quintuplets = event->getQuintuplets<QuintupletsSoA>();
369  auto const quintupletsOccupancy = event->getQuintuplets<QuintupletsOccupancySoA>();
370  auto ranges = event->getRanges();
371  auto modules = event->getModules<ModulesSoA>();
372  int n_accepted_simtrk = ana.tx->getBranch<std::vector<int>>("sim_TC_matched").size();
373 
374  std::vector<int> sim_t5_matched(n_accepted_simtrk);
375  std::vector<std::vector<int>> t5_matched_simIdx;
376 
377  for (unsigned int lowerModuleIdx = 0; lowerModuleIdx < modules.nLowerModules(); ++lowerModuleIdx) {
378  int nQuintuplets = quintupletsOccupancy.nQuintuplets()[lowerModuleIdx];
379  for (unsigned int idx = 0; idx < nQuintuplets; idx++) {
380  unsigned int quintupletIndex = ranges.quintupletModuleIndices()[lowerModuleIdx] + idx;
381  float pt = __H2F(quintuplets.innerRadius()[quintupletIndex]) * k2Rinv1GeVf * 2;
382  float eta = __H2F(quintuplets.eta()[quintupletIndex]);
383  float phi = __H2F(quintuplets.phi()[quintupletIndex]);
384 
385  std::vector<unsigned int> hit_idx = getHitIdxsFromT5(event, quintupletIndex);
386  std::vector<unsigned int> hit_type = getHitTypesFromT5(event, quintupletIndex);
387  std::vector<unsigned int> module_idx = getModuleIdxsFromT5(event, quintupletIndex);
388 
389  int layer_binary = 0;
390  int moduleType_binary = 0;
391  for (size_t i = 0; i < module_idx.size(); i += 2) {
392  layer_binary |= (1 << (modules.layers()[module_idx[i]] + 6 * (modules.subdets()[module_idx[i]] == 4)));
393  moduleType_binary |= (modules.moduleType()[module_idx[i]] << i);
394  }
395 
396  std::vector<int> simidx = matchedSimTrkIdxs(hit_idx, hit_type);
397 
398  ana.tx->pushbackToBranch<int>("t5_isFake", static_cast<int>(simidx.size() == 0));
399  ana.tx->pushbackToBranch<float>("t5_pt", pt);
400  ana.tx->pushbackToBranch<float>("t5_eta", eta);
401  ana.tx->pushbackToBranch<float>("t5_phi", phi);
402  ana.tx->pushbackToBranch<float>("t5_innerRadius", __H2F(quintuplets.innerRadius()[quintupletIndex]));
403  ana.tx->pushbackToBranch<float>("t5_bridgeRadius", __H2F(quintuplets.bridgeRadius()[quintupletIndex]));
404  ana.tx->pushbackToBranch<float>("t5_outerRadius", __H2F(quintuplets.outerRadius()[quintupletIndex]));
405  ana.tx->pushbackToBranch<float>("t5_chiSquared", quintuplets.chiSquared()[quintupletIndex]);
406  ana.tx->pushbackToBranch<float>("t5_rzChiSquared", quintuplets.rzChiSquared()[quintupletIndex]);
407  ana.tx->pushbackToBranch<int>("t5_layer_binary", layer_binary);
408  ana.tx->pushbackToBranch<int>("t5_moduleType_binary", moduleType_binary);
409 
410  t5_matched_simIdx.push_back(simidx);
411 
412  for (auto& simtrk : simidx) {
413  if (simtrk < n_accepted_simtrk) {
414  sim_t5_matched.at(simtrk) += 1;
415  }
416  }
417  }
418  }
419 
420  std::vector<int> t5_isDuplicate(t5_matched_simIdx.size());
421  for (unsigned int i = 0; i < t5_matched_simIdx.size(); i++) {
422  bool isDuplicate = false;
423  for (unsigned int isim = 0; isim < t5_matched_simIdx[i].size(); isim++) {
424  int simidx = t5_matched_simIdx[i][isim];
425  if (simidx < n_accepted_simtrk) {
426  if (sim_t5_matched[simidx] > 1) {
427  isDuplicate = true;
428  }
429  }
430  }
432  }
433  ana.tx->setBranch<std::vector<int>>("sim_T5_matched", sim_t5_matched);
434  ana.tx->setBranch<std::vector<std::vector<int>>>("t5_matched_simIdx", t5_matched_simIdx);
435  ana.tx->setBranch<std::vector<int>>("t5_isDuplicate", t5_isDuplicate);
436 }
size
Write out results.
std::vector< unsigned int > getModuleIdxsFromT5(LSTEvent *event, unsigned int T5)
RooUtil::TTreeX * tx
ModulesSoALayout<> ModulesSoA
Definition: ModulesSoA.h:43
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float k2Rinv1GeVf
Definition: Common.h:49
void pushbackToBranch(TString, T)
std::vector< unsigned int > getHitTypesFromT5(LSTEvent *event, unsigned int T5)
AnalysisConfig ana
const T & getBranch(TString, bool=true)
const std::vector< int > & t5_isDuplicate()
Definition: LSTEff.cc:3358
#define __H2F
Definition: Common.h:50
std::vector< unsigned int > getHitIdxsFromT5(LSTEvent *event, unsigned int T5)
QuintupletsSoALayout<> QuintupletsSoA
const std::vector< std::vector< int > > & t5_matched_simIdx()
Definition: LSTEff.cc:3287
std::vector< int > matchedSimTrkIdxs(std::vector< int > hitidxs, std::vector< int > hittypes, bool verbose)
Definition: trkCore.cc:285
void setBranch(TString, T, bool=false, bool=false)
string ranges
Definition: diffTwoXMLs.py:79
ALPAKA_FN_ACC ALPAKA_FN_INLINE constexpr bool isDuplicate(uint32_t const *__restrict__ status, uint16_t x, uint16_t y)
QuintupletsOccupancySoALayout<> QuintupletsOccupancySoA
Definition: event.py:1