@@ -5,16 +5,17 @@ C.Brown & C.Savard 07/2020
5
5
*/
6
6
7
7
#include " L1Trigger/TrackTrigger/interface/TrackQuality.h"
8
+ #include " PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h"
8
9
9
10
// Constructors
10
11
11
12
TrackQuality::TrackQuality () {}
12
13
13
- TrackQuality::TrackQuality (edm::ParameterSet& qualityParams) {
14
- std::string qualityAlgorithm = qualityParams.getParameter <std::string>(" qualityAlgorithm" );
14
+ TrackQuality::TrackQuality (const edm::ParameterSet& qualityParams) {
15
+ std::string AlgorithmString = qualityParams.getParameter <std::string>(" qualityAlgorithm" );
15
16
// Unpacks EDM parameter set itself to save unecessary processing within TrackProducers
16
- if (qualityAlgorithm == " Cut" ) {
17
- setCutParameters (qualityAlgorithm ,
17
+ if (AlgorithmString == " Cut" ) {
18
+ setCutParameters (AlgorithmString ,
18
19
(float )qualityParams.getParameter <double >(" maxZ0" ),
19
20
(float )qualityParams.getParameter <double >(" maxEta" ),
20
21
(float )qualityParams.getParameter <double >(" chi2dofMax" ),
@@ -24,10 +25,11 @@ TrackQuality::TrackQuality(edm::ParameterSet& qualityParams) {
24
25
}
25
26
26
27
else {
27
- setONNXModel (qualityAlgorithm ,
28
- edm::FileInPath ( qualityParams.getParameter <std::string >(" ONNXmodel" ) ),
28
+ setONNXModel (AlgorithmString ,
29
+ qualityParams.getParameter <edm::FileInPath >(" ONNXmodel" ),
29
30
qualityParams.getParameter <std::string>(" ONNXInputName" ),
30
31
qualityParams.getParameter <std::vector<std::string>>(" featureNames" ));
32
+ ONNXInvRScaling_ = qualityParams.getParameter <double >(" ONNXInvRScale" );
31
33
}
32
34
}
33
35
@@ -41,6 +43,9 @@ std::vector<float> TrackQuality::featureTransform(TTTrack<Ref_Phase2TrackerDigi_
41
43
42
44
std::vector<float > transformedFeatures;
43
45
46
+ // Define feature map, filled as features are generated
47
+ std::map<std::string, float > feature_map;
48
+
44
49
// The following converts the 7 bit hitmask in the TTTrackword to an expected
45
50
// 11 bit hitmask based on the eta of the track
46
51
std::vector<int > hitpattern_binary = {0 , 0 , 0 , 0 , 0 , 0 , 0 };
@@ -109,7 +114,7 @@ std::vector<float> TrackQuality::featureTransform(TTTrack<Ref_Phase2TrackerDigi_
109
114
110
115
// bin bendchi2 variable (bins from https://twiki.cern.ch/twiki/bin/viewauth/CMS/HybridDataFormat#Fitted_Tracks_written_by_KalmanF)
111
116
float tmp_trk_bendchi2 = aTrack.stubPtConsistency ();
112
- std::vector <float > bendchi2_bins = { 0 , 0.5 , 1.25 , 2 , 3 , 5 , 10 , 50 };
117
+ std::array <float , 8 > bendchi2_bins{{ 0 , 0.5 , 1.25 , 2 , 3 , 5 , 10 , 50 } };
113
118
int n_bendchi2 = static_cast <int >(bendchi2_bins.size ());
114
119
float tmp_trk_bendchi2_bin = -1 ;
115
120
for (int i = 0 ; i < n_bendchi2; i++) {
@@ -123,7 +128,7 @@ std::vector<float> TrackQuality::featureTransform(TTTrack<Ref_Phase2TrackerDigi_
123
128
124
129
// bin chi2rphi variable (bins from https://twiki.cern.ch/twiki/bin/viewauth/CMS/HybridDataFormat#Fitted_Tracks_written_by_KalmanF)
125
130
float tmp_trk_chi2rphi = aTrack.chi2XY ();
126
- std::vector <float > chi2rphi_bins = { 0 , 0.25 , 0.5 , 1 , 2 , 3 , 5 , 7 , 10 , 20 , 40 , 100 , 200 , 500 , 1000 , 3000 };
131
+ std::array <float , 16 > chi2rphi_bins{{ 0 , 0.25 , 0.5 , 1 , 2 , 3 , 5 , 7 , 10 , 20 , 40 , 100 , 200 , 500 , 1000 , 3000 } };
127
132
int n_chi2rphi = static_cast <int >(chi2rphi_bins.size ());
128
133
float tmp_trk_chi2rphi_bin = -1 ;
129
134
for (int i = 0 ; i < n_chi2rphi; i++) {
@@ -137,7 +142,7 @@ std::vector<float> TrackQuality::featureTransform(TTTrack<Ref_Phase2TrackerDigi_
137
142
138
143
// bin chi2rz variable (bins from https://twiki.cern.ch/twiki/bin/viewauth/CMS/HybridDataFormat#Fitted_Tracks_written_by_KalmanF)
139
144
float tmp_trk_chi2rz = aTrack.chi2Z ();
140
- std::vector <float > chi2rz_bins = { 0 , 0.25 , 0.5 , 1 , 2 , 3 , 5 , 7 , 10 , 20 , 40 , 100 , 200 , 500 , 1000 , 3000 };
145
+ std::array <float , 16 > chi2rz_bins{{ 0 , 0.25 , 0.5 , 1 , 2 , 3 , 5 , 7 , 10 , 20 , 40 , 100 , 200 , 500 , 1000 , 3000 } };
141
146
int n_chi2rz = static_cast <int >(chi2rz_bins.size ());
142
147
float tmp_trk_chi2rz_bin = -1 ;
143
148
for (int i = 0 ; i < n_chi2rz; i++) {
@@ -152,33 +157,32 @@ std::vector<float> TrackQuality::featureTransform(TTTrack<Ref_Phase2TrackerDigi_
152
157
// get the nstub
153
158
std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>> stubRefs =
154
159
aTrack.getStubRefs ();
155
- float tmp_trk_nstub = stubRefs.size ();
156
-
157
- // While not strictly necessary to define these parameters,
158
- // it is included so each variable is named to avoid confusion
159
- float tmp_trk_big_invr = 500 * abs (aTrack.rInv ());
160
- float tmp_trk_tanl = abs (aTrack.tanL ());
161
- float tmp_trk_z0 = aTrack.z0 ();
162
- float tmp_trk_phi = aTrack.phi ();
163
- float tmp_trk_pt = aTrack.momentum ().perp ();
164
- float tmp_trk_eta = aTrack.eta ();
165
- float tmp_trk_chi2 = aTrack.chi2 ();
166
- float tmp_trk_log_chi2 = log (tmp_trk_chi2);
167
- float tmp_trk_log_chi2rphi = log (tmp_trk_chi2rphi);
168
- float tmp_trk_log_chi2rz = log (tmp_trk_chi2rz);
169
- float tmp_trk_log_bendchi2 = log (tmp_trk_bendchi2);
170
160
171
- // fill feature map
172
- std::map<std::string, float > feature_map;
173
- feature_map[" log_chi2" ] = tmp_trk_log_chi2;
174
- feature_map[" log_chi2rphi" ] = tmp_trk_log_chi2rphi;
175
- feature_map[" log_chi2rz" ] = tmp_trk_log_chi2rz;
176
- feature_map[" log_bendchi2" ] = tmp_trk_log_bendchi2;
161
+ // fill the feature map
162
+ feature_map[" nstub" ] = stubRefs.size ();
163
+ feature_map[" rinv" ] = ONNXInvRScaling_ * abs (aTrack.rInv ());
164
+ feature_map[" tanl" ] = abs (aTrack.tanL ());
165
+ feature_map[" z0" ] = aTrack.z0 ();
166
+ feature_map[" phi" ] = aTrack.phi ();
167
+ feature_map[" pt" ] = aTrack.momentum ().perp ();
168
+ feature_map[" eta" ] = aTrack.eta ();
169
+
170
+ float tmp_trk_chi2 = aTrack.chi2 ();
177
171
feature_map[" chi2" ] = tmp_trk_chi2;
172
+ feature_map[" log_chi2" ] = log (tmp_trk_chi2);
173
+
178
174
feature_map[" chi2rphi" ] = tmp_trk_chi2rphi;
175
+ feature_map[" log_chi2rphi" ] = log (tmp_trk_chi2rphi);
176
+
179
177
feature_map[" chi2rz" ] = tmp_trk_chi2rz;
178
+ feature_map[" log_chi2rz" ] = log (tmp_trk_chi2rz);
179
+
180
+ feature_map[" chi2rz" ] = tmp_trk_chi2rz;
181
+ feature_map[" log_chi2rz" ] = log (tmp_trk_chi2rz);
182
+
180
183
feature_map[" bendchi2" ] = tmp_trk_bendchi2;
181
- feature_map[" nstub" ] = tmp_trk_nstub;
184
+ feature_map[" log_bendchi2" ] = log (tmp_trk_bendchi2);
185
+
182
186
feature_map[" lay1_hits" ] = float (hitpattern_expanded_binary[0 ]);
183
187
feature_map[" lay2_hits" ] = float (hitpattern_expanded_binary[1 ]);
184
188
feature_map[" lay3_hits" ] = float (hitpattern_expanded_binary[2 ]);
@@ -190,14 +194,10 @@ std::vector<float> TrackQuality::featureTransform(TTTrack<Ref_Phase2TrackerDigi_
190
194
feature_map[" disk3_hits" ] = float (hitpattern_expanded_binary[8 ]);
191
195
feature_map[" disk4_hits" ] = float (hitpattern_expanded_binary[9 ]);
192
196
feature_map[" disk5_hits" ] = float (hitpattern_expanded_binary[10 ]);
193
- feature_map[" rinv" ] = tmp_trk_big_invr;
194
- feature_map[" tanl" ] = tmp_trk_tanl;
195
- feature_map[" z0" ] = tmp_trk_z0;
196
- feature_map[" phi" ] = tmp_trk_phi;
197
+
197
198
feature_map[" dtot" ] = float (tmp_trk_dtot);
198
199
feature_map[" ltot" ] = float (tmp_trk_ltot);
199
- feature_map[" pt" ] = tmp_trk_pt;
200
- feature_map[" eta" ] = tmp_trk_eta;
200
+
201
201
feature_map[" nlaymiss_interior" ] = float (tmp_trk_nlaymiss_interior);
202
202
feature_map[" bendchi2_bin" ] = tmp_trk_bendchi2_bin;
203
203
feature_map[" chi2rphi_bin" ] = tmp_trk_chi2rphi_bin;
@@ -212,7 +212,7 @@ std::vector<float> TrackQuality::featureTransform(TTTrack<Ref_Phase2TrackerDigi_
212
212
}
213
213
214
214
void TrackQuality::setTrackQuality (TTTrack<Ref_Phase2TrackerDigi_>& aTrack) {
215
- if (this ->qualityAlgorithm_ == " Cut" ) {
215
+ if (this ->qualityAlgorithm_ == QualityAlgorithm:: Cut) {
216
216
// Get Track parameters
217
217
float trk_pt = aTrack.momentum ().perp ();
218
218
float trk_bend_chi2 = aTrack.stubPtConsistency ();
@@ -232,7 +232,7 @@ void TrackQuality::setTrackQuality(TTTrack<Ref_Phase2TrackerDigi_>& aTrack) {
232
232
aTrack.settrkMVA1 (classification);
233
233
}
234
234
235
- if ((this ->qualityAlgorithm_ == " NN " ) || (this ->qualityAlgorithm_ == " GBDT" )) {
235
+ if ((this ->qualityAlgorithm_ == QualityAlgorithm::NN ) || (this ->qualityAlgorithm_ == QualityAlgorithm:: GBDT)) {
236
236
// Setup ONNX input and output names and arrays
237
237
std::vector<std::string> ortinput_names;
238
238
std::vector<std::string> ortoutput_names;
@@ -255,11 +255,11 @@ void TrackQuality::setTrackQuality(TTTrack<Ref_Phase2TrackerDigi_>& aTrack) {
255
255
// Run classification
256
256
ortoutputs = Runtime.run (ortinput_names, ortinput, {}, ortoutput_names, batch_size);
257
257
258
- if (this ->qualityAlgorithm_ == " NN " ) {
258
+ if (this ->qualityAlgorithm_ == QualityAlgorithm::NN ) {
259
259
aTrack.settrkMVA1 (ortoutputs[0 ][0 ]);
260
260
}
261
261
262
- if (this ->qualityAlgorithm_ == " GBDT" ) {
262
+ else if (this ->qualityAlgorithm_ == QualityAlgorithm:: GBDT) {
263
263
aTrack.settrkMVA1 (ortoutputs[1 ][1 ]);
264
264
}
265
265
// Slight differences in the ONNX models of the GBDTs and NNs mean different
@@ -271,14 +271,14 @@ void TrackQuality::setTrackQuality(TTTrack<Ref_Phase2TrackerDigi_>& aTrack) {
271
271
}
272
272
}
273
273
274
- void TrackQuality::setCutParameters (std::string const & qualityAlgorithm ,
274
+ void TrackQuality::setCutParameters (std::string const & AlgorithmString ,
275
275
float maxZ0,
276
276
float maxEta,
277
277
float chi2dofMax,
278
278
float bendchi2Max,
279
279
float minPt,
280
280
int nStubmin) {
281
- qualityAlgorithm_ = qualityAlgorithm ;
281
+ qualityAlgorithm_ = QualityAlgorithm::Cut ;
282
282
maxZ0_ = maxZ0;
283
283
maxEta_ = maxEta;
284
284
chi2dofMax_ = chi2dofMax;
@@ -287,11 +287,18 @@ void TrackQuality::setCutParameters(std::string const& qualityAlgorithm,
287
287
nStubsmin_ = nStubmin;
288
288
}
289
289
290
- void TrackQuality::setONNXModel (std::string const & qualityAlgorithm ,
290
+ void TrackQuality::setONNXModel (std::string const & AlgorithmString ,
291
291
edm::FileInPath const & ONNXmodel,
292
292
std::string const & ONNXInputName,
293
293
std::vector<std::string> const & featureNames) {
294
- qualityAlgorithm_ = qualityAlgorithm;
294
+ // Convert algorithm string to Enum class for track by track comparison
295
+ if (AlgorithmString == " NN" ) {
296
+ qualityAlgorithm_ = QualityAlgorithm::NN;
297
+ } else if (AlgorithmString == " GBDT" ) {
298
+ qualityAlgorithm_ = QualityAlgorithm::GBDT;
299
+ } else {
300
+ qualityAlgorithm_ = QualityAlgorithm::None;
301
+ }
295
302
ONNXmodel_ = ONNXmodel;
296
303
ONNXInputName_ = ONNXInputName;
297
304
featureNames_ = featureNames;
0 commit comments