21 m_holeSearchTool(
"InDet::InDetTrackHoleSearchTool/InDetHoleSearchTool", this),
22 m_trackSelTool(
"InDet::InDetTrackSelectionTool/TrackSelectionTool", this),
23 m_trkextrapolator(
"Trk::Extrapolator/InDetExtrapolator", this),
47 std::string partitionLabel(
"Disks");
53 std::unique_ptr<TFile> calibFile(TFile::Open(fullPathToTrainingFile.c_str(),
"READ"));
55 ATH_MSG_ERROR(
"Can not retrieve PixelMonitoring calibration file: " << fullPathToTrainingFile);
56 return StatusCode::FAILURE;
58 std::unique_ptr<TTree> trainingWeights( (TTree*)calibFile->Get(
"lgbm") );
59 m_classBDT.emplace( std::make_pair(partitionLabel, std::make_unique<MVAUtils::BDT>( trainingWeights.get())) );
65 return StatusCode::SUCCESS;
71 ATH_MSG_DEBUG(
"Pixel MVAMon: Filling MVA Monitoring Histograms");
84 std::vector<float>
status(MAXHASH*2);
88 for (; idIt != idItEnd; ++idIt) {
93 if (pixlayer == 99)
continue;
100 for (
int iFE=0; iFE<nFE; iFE++) {
102 if (pixID.is_valid()) {
108 if (is_good)
status[modHash+MAXHASH*iFE] = 0;
109 else status[modHash+MAXHASH*iFE] = 1;
111 else status[modHash+MAXHASH*iFE] = 2;
123 if (is_good)
status[modHash] = 0;
134 if ( !(trackParticles.isValid()) ) {
136 return StatusCode::RECOVERABLE;
138 ATH_MSG_DEBUG(
"Pixel MVAMon: TrackParticle container "<< trackParticles.name() <<
" is found.");
141 bool eventHasPixHits(
false);
142 std::vector<std::pair<Identifier, double> > ClusterIDs;
144 std::vector<float>
holes(MAXHASH*2);
145 std::vector<float> outliers(MAXHASH*2);
146 std::vector<float> measurements(MAXHASH*2);
147 std::vector<float> trkalpha(MAXHASH*2);
148 std::vector<float> trkchi2byndf(MAXHASH*2);
149 std::vector<float> trknpixdead(MAXHASH*2);
150 std::vector<float> trknblayerhits(MAXHASH*2);
154 for (
auto trackPart: *trackParticles) {
159 ATH_MSG_DEBUG(
"Pixel MVAMon: Track either invalid or it does not contain pixel hits, continuing...");
164 bool hasIBLTSOS(
false);
167 if (!passJOTrkCut)
continue;
168 float trkfitndf =
track->fitQuality()->numberDoF();
169 float trkfitchi2byndf =
track->fitQuality()->chiSquared();
170 if (trkfitndf != 0) trkfitchi2byndf /= trkfitndf;
173 float nblayerhits(0);
180 std::unique_ptr<const Trk::Track> trackWithHolesUnique =
nullptr;
182 if ( nPixHoles > 0 ) {
184 trackWithHoles = trackWithHolesUnique.get();
187 for (
auto trackStateOnSurface: *trackStates) {
197 if (mesBase && !RIOOnTrack)
continue;
209 ATH_MSG_DEBUG(
"Pixel MVAMon: can't obtain track parameters for TSOS.");
218 if (pixlayer == 99)
continue;
228 bool goodPixelMeasurement(
false);
235 if ( mesBase && pixClus) {
237 if ( !(locPosID.is_valid()) ) {
238 ATH_MSG_WARNING(
"Pixel MVAMon: got invalid track local position on surface for an outlier.");
242 outliers[indexModule+MAXHASH*iFE] += 1;
247 outliers[indexModule] += 1;
255 if ( !(locPosID.is_valid()) ) {
256 ATH_MSG_WARNING(
"Pixel MVAMon: got invalid track local position on surface for a hole.");
260 holes[indexModule+MAXHASH*iFE] += 1;
264 holes[indexModule] += 1;
271 if (not mesBase)
continue;
274 if (!sde || !pixClus)
continue;
276 if (!rawPixClus)
continue;
279 goodPixelMeasurement =
true;
281 if ( !(locPosID.is_valid()) ) {
286 measurements[indexModule+MAXHASH*iFE] += 1;
293 double trackpnormcomp = trackp.dot(normal);
294 double trackp_mag = trackp.mag();
295 double alpha = 0.5 *
M_PI;
296 if (trackp_mag != 0) alpha = std::acos(std::abs(trackpnormcomp / trackp_mag));
298 trkalpha[indexModule+MAXHASH*iFE] += alpha;
300 if (goodPixelMeasurement) ClusterIDs.emplace_back(locPosID, alpha);
302 trkchi2byndf[indexModule+MAXHASH*iFE] += trkfitchi2byndf;
303 trknpixdead[indexModule+MAXHASH*iFE] += npixdead;
304 trknblayerhits[indexModule+MAXHASH*iFE] += nblayerhits;
306 eventHasPixHits = eventHasPixHits || (
nPixelHits > 0);
309 if (!hasIBLTSOS && expIBLhit==1 && nPixHoles==0 )
313 transSurf.setIdentity();
315 std::vector<std::unique_ptr<Trk::TrackParameters> > iblTrkParameters =
318 double alpha = 0.5 *
M_PI;
319 bool foundIBLElem(
false);
321 for (
auto&
tp: iblTrkParameters) {
323 if (!(sde !=
nullptr && sde->
identify() != 0)) {
328 ATH_MSG_DEBUG(
"Pixel MVAMon: found non-IBL element: "<< sensorPosID);
333 if ( !(chipPosID.is_valid()) ) {
335 ATH_MSG_DEBUG(
"Pixel MVAMon: got invalid track local position on surface for an expected IBL hit.");
337 }
else foundIBLElem=
true;
338 double trackpnormcomp =
tp->momentum().dot(
tp->associatedSurface().normal());
339 double trackp_mag =
tp->momentum().mag();
340 if (trackp_mag != 0) alpha = std::acos(std::abs(trackpnormcomp / trackp_mag));
343 ATH_MSG_DEBUG(
"Pixel MVAMon: couldn't find IBL pos ID: "<< sensorPosID);
348 holes[indexModule+MAXHASH*iFE] += 1;
349 trkalpha[indexModule+MAXHASH*iFE] += alpha;
350 trkchi2byndf[indexModule+MAXHASH*iFE] += trkfitchi2byndf;
351 trknpixdead[indexModule+MAXHASH*iFE] += npixdead;
352 trknblayerhits[indexModule+MAXHASH*iFE] += nblayerhits;
356 if (!eventHasPixHits) {
357 ATH_MSG_DEBUG(
"Pixel MVAMon: event doesn't contain any pixel hits on tracks, skipping evaluation.");
358 return StatusCode::SUCCESS;
362 sort(ClusterIDs.begin(), ClusterIDs.end(), [](
const std::pair<Identifier, double> &left,
const std::pair<Identifier, double> &right) {
363 return left.first < right.first;
366 std::vector<float> misshitsf(MAXHASH*2);
368 for (
int ih=0; ih<MAXHASH; ++ih) {
369 alltrackinfo =
holes[ih] + outliers[ih] + measurements[ih];
371 misshitsf[ih] = (
holes[ih]+outliers[ih])/alltrackinfo;
372 trkalpha[ih] = trkalpha[ih]/alltrackinfo;
373 trkchi2byndf[ih] = trkchi2byndf[ih]/alltrackinfo;
374 trknpixdead[ih] = trknpixdead[ih]/alltrackinfo;
375 trknblayerhits[ih] = trknblayerhits[ih]/alltrackinfo;
378 alltrackinfo =
holes[ih+MAXHASH]+outliers[ih+MAXHASH]+measurements[ih+MAXHASH];
380 misshitsf[ih+MAXHASH] = (
holes[ih+MAXHASH]+outliers[ih+MAXHASH])/alltrackinfo;
381 trkalpha[ih+MAXHASH] = trkalpha[ih+MAXHASH]/alltrackinfo;
382 trkchi2byndf[ih+MAXHASH] = trkchi2byndf[ih+MAXHASH]/alltrackinfo;
383 trknpixdead[ih+MAXHASH] = trknpixdead[ih+MAXHASH]/alltrackinfo;
384 trknblayerhits[ih+MAXHASH] = trknblayerhits[ih+MAXHASH]/alltrackinfo;
393 std::vector<float> clsall(MAXHASH*2);
394 std::vector<float> clsontrkf(MAXHASH*2);
395 std::vector<float> clsontrk(MAXHASH*2);
396 std::vector<float> clsofftrk(MAXHASH*2);
399 std::vector<float> clsontrksize(MAXHASH*2);
400 std::vector<float> clsontrkrowsize(MAXHASH*2);
401 std::vector<float> clsontrkcolsize(MAXHASH*2);
402 std::vector<float> clsofftrksize(MAXHASH*2);
403 std::vector<float> clsofftrkrowsize(MAXHASH*2);
404 std::vector<float> clsofftrkcolsize(MAXHASH*2);
406 std::vector<float> clsontrktot(MAXHASH*2);
407 std::vector<float> clsofftrktot(MAXHASH*2);
411 if ( !(pixel_clcontainer.isValid()) ) {
413 return StatusCode::RECOVERABLE;
415 ATH_MSG_DEBUG(
"Pixel MVAMon: Pixel Cluster container "<< pixel_clcontainer.name() <<
" is found.");
420 for (
auto colNext: *pixel_clcontainer) {
423 if (!ClusterCollection) {
424 ATH_MSG_DEBUG(
"Pixel MVAMon: Pixel Cluster container is empty.");
428 IdentifierHash clusIDHash = ClusterCollection->identifyHash();
429 int indexModule =
static_cast<int>( clusIDHash );
431 for (
auto p_clus: *ClusterCollection) {
433 clusID = p_clus->identify();
436 if (pixlayer == 99)
continue;
442 int idxCluster = indexModule+MAXHASH*iFE;
444 clsall[idxCluster] += 1;
447 double alpha = 0.5 *
M_PI;
449 clsontrk[idxCluster] += 1;
450 clsontrksize[idxCluster] += cluster.
rdoList().size();
451 clsontrkrowsize[idxCluster] += cluster.
width().
colRow().x();
452 clsontrkcolsize[idxCluster] += cluster.
width().
colRow().y();
453 clsontrktot[idxCluster] += cluster.
totalToT();
455 clsofftrk[idxCluster] += 1;
456 clsofftrksize[idxCluster] += cluster.
rdoList().size();
457 clsofftrkrowsize[idxCluster]+= cluster.
width().
colRow().x();
458 clsofftrkcolsize[idxCluster]+= cluster.
width().
colRow().y();
459 clsofftrktot[idxCluster] += cluster.
totalToT();
469 for (
int ih=0; ih<MAXHASH; ++ih) {
471 clsontrksize[ih] /= clsontrk[ih];
472 clsontrkrowsize[ih]/= clsontrk[ih];
473 clsontrkcolsize[ih]/= clsontrk[ih];
474 clsontrktot[ih] /= clsontrk[ih];
477 clsofftrksize[ih] /= clsofftrk[ih];
478 clsofftrkrowsize[ih]/= clsofftrk[ih];
479 clsofftrkcolsize[ih]/= clsofftrk[ih];
480 clsofftrktot[ih] /= clsofftrk[ih];
483 clsontrkf[ih] = clsontrk[ih]/clsall[ih];
487 if (clsontrk[ih+MAXHASH]) {
488 clsontrksize[ih+MAXHASH] /= clsontrk[ih+MAXHASH];
489 clsontrkrowsize[ih+MAXHASH]/= clsontrk[ih+MAXHASH];
490 clsontrkcolsize[ih+MAXHASH]/= clsontrk[ih+MAXHASH];
491 clsontrktot[ih+MAXHASH] /= clsontrk[ih+MAXHASH];
493 if (clsofftrk[ih+MAXHASH]) {
494 clsofftrksize[ih+MAXHASH] /= clsofftrk[ih+MAXHASH];
495 clsofftrkrowsize[ih+MAXHASH]/= clsofftrk[ih+MAXHASH];
496 clsofftrkcolsize[ih+MAXHASH]/= clsofftrk[ih+MAXHASH];
497 clsofftrktot[ih+MAXHASH] /= clsofftrk[ih+MAXHASH];
499 if (clsall[ih+MAXHASH]) {
500 clsontrkf[ih+MAXHASH] = clsontrk[ih+MAXHASH]/clsall[ih+MAXHASH];
508 std::vector<float> bdtweights(MAXHASH*2);
511 for (
int ih=12; ih<MAXHASH-12; ++ih)
518 if ( ih>=156 && ih<=435 )
522 if (module<4 || module>15)
continue;
523 else mod_eta =
module-9.5;
525 else if (ih>=436 && ih<=721 )
530 else if (ih>=722 && ih<=1215)
535 else if (ih>=1216 && ih<=1891)
540 else if ( (ih>=12 && ih<=155) || (ih>=1892 && ih<=2035) )
550 if (pixlayer == 99)
continue;
551 std::string partitionLabel(
"Disks");
554 for (
int iFE=0; iFE<nFE; iFE++) {
558 if (!pixID.is_valid()) {
563 if (mod_eta > 0)
el_eta-=1.0;
567 int idx = ih+MAXHASH*iFE;
568 if (
status[
idx]==2 ) BDT_Weights.
add(pixlayer, pixID, 0);
571 std::vector<float> bdtVars;
573 bdtVars = {
el_eta, misshitsf[
idx], clsontrkf[
idx], clsontrkrowsize[
idx],
574 clsontrkcolsize[
idx], clsofftrkrowsize[
idx], clsofftrkcolsize[
idx],
575 clsontrktot[
idx], clsofftrktot[
idx], trkalpha[
idx],
576 trkchi2byndf[
idx], trknpixdead[
idx], trknblayerhits[
idx] };
578 bdtVars = {
el_eta, misshitsf[
idx], clsontrkf[
idx], clsontrkrowsize[
idx],
579 clsontrkcolsize[
idx], clsofftrkrowsize[
idx], clsofftrkcolsize[
idx],
580 clsontrktot[
idx], clsofftrktot[
idx], trkalpha[
idx],
581 trkchi2byndf[
idx], trknpixdead[
idx] };
583 bdtweights[
idx] =
m_classBDT.at(partitionLabel)->GetClassification(bdtVars);
584 BDT_Weights.
add(pixlayer, pixID, bdtweights[
idx]);
618 fill( mvaGroup, lbval, mon_status_vec, mon_h_vec, mon_o_vec, mon_m_vec,
619 mon_clsontrkf_vec, mon_clsontrk_vec, mon_clsofftrk_vec, mon_clsall_vec,
620 mon_clsontrksize_vec, mon_clsontrkrowsize_vec, mon_clsontrkcolsize_vec,
621 mon_clsofftrksize_vec, mon_clsofftrkrowsize_vec, mon_clsofftrkcolsize_vec,
622 mon_clsontrktot_vec, mon_clsofftrktot_vec, mon_trkalpha_vec, mon_trkchi2byndf_vec,
623 mon_trknpixdead_vec, mon_trknblayerhits_vec, mon_mva_vec );
626 return StatusCode::SUCCESS;