ATLAS Offline Software
Loading...
Searching...
No Matches
IDAlignMonGenericTracksAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// **********************************************************************
6// AlignmentMonAlg.cxx
7// AUTHORS: Beate Heinemann, Tobias Golling
8// Adapted to AthenaMT by Per Johansson 2021
9// **********************************************************************
10
11//main header
13
18
22
25
28
29#include "CLHEP/GenericFunctions/CumulativeChiSquare.hh"
30
32
33#include <cmath>
34
35// *********************************************************************
36// Public Methods
37// *********************************************************************
38
39IDAlignMonGenericTracksAlg::IDAlignMonGenericTracksAlg( const std::string & name, ISvcLocator* pSvcLocator ) :
40 AthMonitorAlgorithm(name, pSvcLocator),
41 m_idHelper(nullptr),
42 m_pixelID(nullptr),
43 m_sctID(nullptr),
44 m_trtID(nullptr),
45 m_d0Range(2.0),
46 m_d0BsRange(0.5),
47 m_z0Range(250.0),
48 m_etaRange(3.0),
49 m_NTracksRange(200),
50 m_barrelEta(0.8), //Tracks between -0.8 & 0.8 are considered as Barrel Tracks, otherwise are End-Caps
51 m_trackSelection( "InDet::InDetTrackSelectionTool/TrackSelectionTool", this),
53{
54 declareProperty("Pixel_Manager" , m_Pixel_Manager);
55 declareProperty("SCT_Manager" , m_SCT_Manager);
56 declareProperty("TRT_Manager" , m_TRT_Manager);
57 declareProperty("TrackSelectionTool" , m_trackSelection);
58 declareProperty("HitQualityTool" , m_hitQualityTool);
59 declareProperty("useExtendedPlots" , m_extendedPlots = false);
60 declareProperty("d0Range" , m_d0Range);
61 declareProperty("d0BsRange" , m_d0BsRange);
62 declareProperty("z0Range" , m_z0Range);
63 declareProperty("etaRange" , m_etaRange);
64 declareProperty("pTRange" , m_pTRange);
65 declareProperty("NTracksRange" , m_NTracksRange);
66 declareProperty("doIP" , m_doIP = false);
67 declareProperty("ApplyTrackSelection" , m_applyTrkSel = true);
68}
69
70
72
73
75{
76 StatusCode sc;
77
78 ATH_MSG_DEBUG("Initialize -- START --");
79 //ID Helper
80 ATH_CHECK(detStore()->retrieve(m_idHelper, "AtlasID"));
81
82 m_pixelID = nullptr;
83 ATH_CHECK(detStore()->retrieve(m_pixelID, "PixelID"));
84 ATH_MSG_DEBUG("Initialized PixelIDHelper");
85
86 m_sctID = nullptr;
87 ATH_CHECK(detStore()->retrieve(m_sctID, "SCT_ID"));
88 ATH_MSG_DEBUG("Initialized SCTIDHelper");
89
90 m_trtID = nullptr;
91 ATH_CHECK(detStore()->retrieve(m_trtID, "TRT_ID"));
92 ATH_MSG_DEBUG("Initialized TRTIDHelper");
93
94 ATH_CHECK(m_trackSelection.retrieve());
95 ATH_MSG_DEBUG("Retrieved tool " << m_trackSelection);
96
97 if (m_hitQualityTool.empty()) {
98 ATH_MSG_DEBUG("No hit quality tool configured - not hit quality cuts will be imposed");
99 m_doHitQuality = false;
100 } else if (m_hitQualityTool.retrieve().isFailure()) {
101 ATH_MSG_WARNING("Could not retrieve " << m_hitQualityTool << " (to apply hit quality cuts to Si hits) ");
102 m_doHitQuality = false;
103 } else {
104 ATH_MSG_DEBUG("Hit quality tool setup - hit quality cuts will be applied to Si hits");
105 m_doHitQuality = true;
106 }
107
108 if (m_doIP) {
110 }else {
112 }
113
114 if ( m_beamSpotKey.initialize().isFailure() ) {
115 ATH_MSG_WARNING("Failed to retrieve beamspot service " << m_beamSpotKey << " - will use nominal beamspot at (0,0,0)");
116 m_hasBeamCondSvc = false;
117 }
118 else {
119 m_hasBeamCondSvc = true;
120 ATH_MSG_DEBUG("Retrieved service " << m_beamSpotKey);
121 }
122
123 ATH_CHECK(m_VxPrimContainerName.initialize(not m_VxPrimContainerName.key().empty()));
124 ATH_CHECK(m_tracksName.initialize());
125 ATH_CHECK(m_tracksKey.initialize());
126
127 // Building Tool Maps for the Hit Maps
129 m_measurements_vs_Eta_Phi_pix_ec = Monitored::buildToolMap<int>(m_tools, "measurements_vs_Eta_Phi_pix_ec", 2);
136
137 ATH_MSG_DEBUG("Initialize -- completed --");
139}
140
141StatusCode IDAlignMonGenericTracksAlg::fillHistograms( const EventContext& ctx ) const {
142 using namespace Monitored;
143
144 // For histogram naming
145 auto genericTrackGroup = getGroup("IDA_Tracks");
146
147 //counters
148 int ntrkMax=0;
149 float xv=-999;
150 float yv=-999;
151 float zv=-999;
152 int nTracks=0;
153 int ngTracks=0;
154
155 ATH_MSG_DEBUG ("IDAlignMonGenericTracksAlg::fillHistograms ** START ** call for track collection: " << m_tracksName.key());
156
157 //get tracks
158 auto trks = SG::makeHandle(m_tracksName, ctx);
159 // check for tracks
160 if (not trks.isValid()) {
161 ATH_MSG_DEBUG ("IDAlignMonGenericTracksAlg::fillHistograms() --" << m_tracksName.key() << " could not be retrieved");
162 return StatusCode::RECOVERABLE;
163 }else {
164 ATH_MSG_DEBUG("IDAlignMonGenericTracksAlg: Track container " << trks.name() <<" is found.");
165 }
166
167 //retrieving vertices
168 auto handle_vxContainer = SG::makeHandle(m_VxPrimContainerName, ctx);
169 // if m_doIP
170 const xAOD::Vertex* pvtx = nullptr;
171
172 if (!handle_vxContainer.isPresent()) {
173 ATH_MSG_DEBUG ("InDetGlobalPrimaryVertexMonAlg: StoreGate doesn't contain primary vertex container with key "+m_VxPrimContainerName.key());
174 return StatusCode::SUCCESS;
175 }
176 if (!handle_vxContainer.isValid()) {
177 ATH_MSG_ERROR ("InDetGlobalPrimaryVertexMonAlg: Could not retrieve primary vertex container with key "+m_VxPrimContainerName.key());
178 return StatusCode::RECOVERABLE;
179 }
180
181 const auto *vertexContainer = handle_vxContainer.cptr();
182 for(const auto vtx : *vertexContainer) {
183 if ( !vtx ) continue;
184 if ( !vtx->vxTrackAtVertexAvailable() ) continue;
185
186 const std::vector< Trk::VxTrackAtVertex >& theTrackAtVertex = vtx->vxTrackAtVertex();
187 int numTracksPerVertex = theTrackAtVertex.size();
188 ATH_MSG_DEBUG("Size of TrackAtVertex: " << numTracksPerVertex);
189 if (numTracksPerVertex>ntrkMax) {
190 ntrkMax=numTracksPerVertex;
191 xv=vtx->position()[0];
192 yv=vtx->position()[1];
193 zv=vtx->position()[2];
194 }
195 }
196
197 if (xv==-999 || yv==-999 || zv==-999) {
198 ATH_MSG_DEBUG("No vertex found => setting it to 0");
199 xv=0;yv=0;zv=0;
200 }
201
202
203 std::map<const xAOD::TrackParticle*, const xAOD::Vertex*> trackVertexMapTP;
204 if (m_doIP) fillVertexInformation(trackVertexMapTP, ctx);
205
206 float beamSpotX = 0.;
207 float beamSpotY = 0.;
208 float beamSpotZ = 0.;
209 float beamTiltX = 0.;
210 float beamTiltY = 0.;
211
212 if (m_hasBeamCondSvc) {
213 auto beamSpotHandle = SG::ReadCondHandle(m_beamSpotKey, ctx);
214 Amg::Vector3D bpos = beamSpotHandle->beamPos();
215 beamSpotX = bpos.x();
216 beamSpotY = bpos.y();
217 beamSpotZ = bpos.z();
218 beamTiltX = beamSpotHandle->beamTilt(0);
219 beamTiltY = beamSpotHandle->beamTilt(1);
220 ATH_MSG_DEBUG ("Beamspot: x0 = " << beamSpotX << ", y0 = " << beamSpotY << ", z0 = " << beamSpotZ << ", tiltX = " << beamTiltX << ", tiltY = " << beamTiltY);
221 }
222
223 // Get EventInfo
224 int lb = GetEventInfo(ctx)->lumiBlock();
225 auto lb_m = Monitored::Scalar<int>( "m_lb", lb );
226 int run = GetEventInfo(ctx)->runNumber();
227 auto run_m = Monitored::Scalar<int>( "m_run", run );
228 int event = GetEventInfo(ctx)->eventNumber();
229 auto event_m = Monitored::Scalar<int>( "m_event", event );
230 float mu = lbAverageInteractionsPerCrossing(ctx);
231 auto mu_m = Monitored::Scalar<float>("m_mu", mu);
232
233 if (m_extendedPlots) {
234 //Fill BeamSpot Position histos
235 auto beamSpotX_m = Monitored::Scalar<float>( "m_beamSpotX", beamSpotX );
236 auto beamSpotY_m = Monitored::Scalar<float>( "m_beamSpotY", beamSpotY );
237 auto beamSpotZ_m = Monitored::Scalar<float>( "m_beamSpotZ", beamSpotZ );
238 auto beamTiltX_m = Monitored::Scalar<float>( "m_beamTiltX", beamTiltX );
239 auto beamTiltY_m = Monitored::Scalar<float>( "m_beamTiltY", beamTiltY );
240 fill(genericTrackGroup, beamSpotX_m, beamSpotY_m, beamSpotZ_m, lb_m);
241
242 // interactions per beam crossing
243 fill(genericTrackGroup, mu_m);
244 }
245
246 if (m_doIP) {
247 auto handle_vxContainer = SG::makeHandle(m_VxPrimContainerName, ctx);
248
249 if (!handle_vxContainer.isPresent()) {
250 ATH_MSG_DEBUG ("InDetGlobalPrimaryVertexMonAlg: StoreGate doesn't contain primary vertex container with key "+m_VxPrimContainerName.key());
251 return StatusCode::SUCCESS;
252 }
253 if (!handle_vxContainer.isValid()) {
254 ATH_MSG_ERROR ("InDetGlobalPrimaryVertexMonAlg: Could not retrieve primary vertex container with key "+m_VxPrimContainerName.key());
255 return StatusCode::FAILURE;
256 }
257
258 const auto *vertexContainer = handle_vxContainer.cptr();
259
260 xAOD::VertexContainer::const_iterator vxI = vertexContainer->begin();
261 xAOD::VertexContainer::const_iterator vxE = vertexContainer->end();
262 for (; vxI != vxE; ++vxI) {
263 if ((*vxI)->type() == 1) {
264 pvtx = (*vxI);
265 }
266 }
267 }
268
269 //
270 // Start loop on tracks
271 //
272
273 ATH_MSG_DEBUG ("Start loop on tracks. Number of tracks " << trks->size());
274 for (const Trk::Track* trksItr: *trks) {
275
276 // Found track?!
277 if ( !trksItr || trksItr->perigeeParameters() == nullptr )
278 {
279 ATH_MSG_DEBUG( "InDetAlignmentMonitoringRun3: NULL track pointer in collection" );
280 continue;
281 }
282
283 // Select tracks
284 if ( m_applyTrkSel and !m_trackSelection->accept( *trksItr) )
285 continue; // track selection applied and failed
286
287 nTracks++;
288
289 float chisquared = 0.;
290 int DoF = 0;
291 float chi2oDoF = -999;
292 float trkd0 = -999;
293 float Err_d0 = -999;
294 float trkz0 = -999;
295 float Err_z0 = -999;
296 float trkphi = -999;
297 float Err_phi = -999;
298 float trktheta = -999;
299 float Err_theta = -999;
300 float Err_eta = -999;
301 float trketa = -999;
302 float qOverP = -999;
303 float Err_qOverP = -999;
304 float Err_Pt = -999;
305 float trkpt = -999;
306 float trkP = -999;
307 float charge = 0;
308 float trkd0c = -999;
309 float beamX = 0;
310 float beamY = 0;
311 float d0bscorr = -999;
312 int layerDisk = 99;
313 int sctSide = 99;
314 int modEta = 9999;
315 int modPhi = 9999;
316
317 // get fit quality and chi2 probability of track
318 const Trk::FitQuality* fitQual = trksItr->fitQuality();
319
320 const Trk::Perigee* measPer = trksItr->perigeeParameters();
321 const AmgSymMatrix(5)* covariance = measPer ? measPer->covariance() : nullptr;
322
323 std::unique_ptr<Trk::ImpactParametersAndSigma> myIPandSigma=nullptr;
324
325
326 if (m_doIP){
327
328 //Get unbiased impact parameter
329 if (pvtx) myIPandSigma = m_trackToVertexIPEstimator->estimate(trksItr->perigeeParameters(), pvtx, true);
330 }
331
332 if (covariance == nullptr) {
333 ATH_MSG_WARNING("No measured perigee parameters assigned to the track");
334 }
335 else{
336 AmgVector(5) perigeeParams = measPer->parameters();
337 trkd0 = perigeeParams[Trk::d0];
338 trkz0 = perigeeParams[Trk::z0];
339 trkphi = perigeeParams[Trk::phi0];
340 trktheta = perigeeParams[Trk::theta];
341 trketa = measPer->eta();
342 qOverP = perigeeParams[Trk::qOverP]*1000.;
343 if(qOverP) trkP = 1/qOverP;
344 trkpt = measPer->pT()/1000.;
345 Err_d0 = Amg::error(*measPer->covariance(), Trk::d0);
346 Err_z0 = Amg::error(*measPer->covariance(), Trk::z0);
347 Err_phi = Amg::error(*measPer->covariance(), Trk::phi0);
348 Err_theta = Amg::error(*measPer->covariance(), Trk::theta);
349 Err_eta = Err_theta / sin(trktheta);
350 Err_qOverP = Amg::error(*measPer->covariance(), Trk::qOverP) * 1000;
351 Err_Pt = sin(trktheta) * Err_qOverP / pow(qOverP, 2);
352 if (qOverP < 0) charge = -1;
353 else charge=+1;
354
355 // correct the track d0 for the vertex position
356 // would rather corrected for the beamline but could not find beamline
357 trkd0c=trkd0-(yv*cos(trkphi)-xv*sin(trkphi));
358 ATH_MSG_DEBUG("trkd0, trkd0c: " << trkd0 << ", " << trkd0c);
359
360 // correct the track parameters for the beamspot position
361 beamX = beamSpotX + tan(beamTiltX) * (trkz0-beamSpotZ);
362 beamY = beamSpotY + tan(beamTiltY) * (trkz0-beamSpotZ);
363 d0bscorr = trkd0 - ( -sin(trkphi)*beamX + cos(trkphi)*beamY );
364 }
365
366 if (fitQual==nullptr) {
367 ATH_MSG_WARNING("No fit quality assigned to the track");
368 }
369
370 chisquared = (fitQual) ? fitQual->chiSquared() : -1.;
371 DoF = (fitQual) ? fitQual->numberDoF() : -1;
372 if(DoF>0) chi2oDoF = chisquared/(float)DoF;
373
374 if (trkphi<0) trkphi+=2*M_PI;
375
376 ngTracks++;
377 ATH_MSG_DEBUG(nTracks << " is a good track!");
378
379 // fill lb histogram for each accepted track
380 auto lb_track_m = Monitored::Scalar<int>( "m_lb_track", lb );
381 fill(genericTrackGroup, lb_track_m);
382
383 int nhpixB=0, nhpixECA=0, nhpixECC=0, nhsctB=0, nhsctECA=0, nhsctECC=0, nhtrtB=0, nhtrtECA=0, nhtrtECC=0;
384
385 // loop over all hits on track
386 ATH_MSG_VERBOSE (" starting to loop over TSOS: " << trksItr->trackStateOnSurfaces()->size());
387 for (const Trk::TrackStateOnSurface* tsos : *trksItr->trackStateOnSurfaces()) {
388 //check that we have track parameters defined for the surface (pointer is not null)
389 if(!(tsos->trackParameters())) {
390 ATH_MSG_DEBUG(" hit skipped because no associated track parameters");
391 continue;
392 }
393
394 Identifier surfaceID;
395 const Trk::MeasurementBase* mesb=tsos->measurementOnTrack();
396 // hits, outliers
397 if (mesb != nullptr && mesb->associatedSurface().associatedDetectorElement()!=nullptr) surfaceID = mesb->associatedSurface().associatedDetectorElement()->identify();
398
399 // holes, perigee
400 else continue;
401
402 if ( tsos->type(Trk::TrackStateOnSurface::Measurement) ){
403 //hit quality cuts for Si hits if tool is configured - default is NO CUTS
404 if (m_idHelper->is_pixel(surfaceID) || m_idHelper->is_sct(surfaceID)) {
405 if (m_doHitQuality) {
406 ATH_MSG_DEBUG("applying hit quality cuts to Silicon hit...");
407
408 const Trk::RIO_OnTrack* hit = m_hitQualityTool->getGoodHit(tsos);
409 if (hit == nullptr) {
410 ATH_MSG_DEBUG("hit failed quality cuts and is rejected.");
411 continue;
412 } else {
413 ATH_MSG_DEBUG("hit passed quality cuts");
414 }
415 } else {
416 ATH_MSG_VERBOSE("hit quality cuts NOT APPLIED to Silicon hit.");
417 }
418 } // hit is Pixel or SCT
419
420 // --- pixel hit count
421 if (m_idHelper->is_pixel(surfaceID)){
422 if(m_pixelID->barrel_ec(surfaceID) == 0){
423 nhpixB++;
424 }
425 else if(m_pixelID->barrel_ec(surfaceID) == 2) nhpixECA++;
426 else if(m_pixelID->barrel_ec(surfaceID) == -2) nhpixECC++;
427 }
428 // --- sct hit count
429 else if (m_idHelper->is_sct(surfaceID)){
430 if(m_sctID->barrel_ec(surfaceID) == 0){
431 nhsctB++;
432 }
433 else if(m_sctID->barrel_ec(surfaceID) == 2) nhsctECA++;
434 else if(m_sctID->barrel_ec(surfaceID) == -2) nhsctECC++;
435 }
436 // --- trt hit count
437 if (m_idHelper->is_trt(surfaceID)){
438 int barrel_ec = m_trtID->barrel_ec(surfaceID);
439 if(barrel_ec == 1 || barrel_ec == -1 ) {
440 nhtrtB++;
441 }
442 else if(barrel_ec == 2){
443 nhtrtECA++;
444 }else if(barrel_ec == -2){
445 nhtrtECC++;
446 }
447 }
448 // filling hit maps
449 if (m_idHelper->is_pixel(surfaceID)){
450 layerDisk = m_pixelID -> layer_disk(surfaceID);
451 modEta = m_pixelID->eta_module(surfaceID);
452 modPhi = m_pixelID->phi_module(surfaceID);
453 auto modEta_m = Monitored::Scalar<int>( "m_modEta", modEta );
454 auto modPhi_m = Monitored::Scalar<int>( "m_modPhi", modPhi );
455 auto layerDisk_m = Monitored::Scalar<float>("m_layerDisk", layerDisk);
456
457 if(m_pixelID->barrel_ec(surfaceID) == 0){ //pixel barrel hit
458 fill(m_tools[m_measurements_vs_Eta_Phi_pix_b[layerDisk]], modEta_m, modPhi_m);
459 }
460 else if(m_pixelID->barrel_ec(surfaceID) == 2){ //pixel endcap A hit
461 fill(m_tools[m_measurements_vs_Eta_Phi_pix_ec[0]], layerDisk_m, modPhi_m);
462 }
463 else if(m_sctID->barrel_ec(surfaceID) == -2){ //pixel endcap C hit
464 fill(m_tools[m_measurements_vs_Eta_Phi_pix_ec[1]], layerDisk_m, modPhi_m);
465 }
466 }
467 else if (m_idHelper->is_sct(surfaceID)){
468 layerDisk = m_sctID->layer_disk(surfaceID);
469 modEta = m_sctID->eta_module(surfaceID);
470 modPhi = m_sctID->phi_module(surfaceID);
471 sctSide = m_sctID->side(surfaceID);
472 auto modEta_m = Monitored::Scalar<int>( "m_modEta", modEta );
473 auto modPhi_m = Monitored::Scalar<int>( "m_modPhi", modPhi );
474 auto layerDisk_m = Monitored::Scalar<float>("m_layerDisk", layerDisk);
475
476 if(m_sctID->barrel_ec(surfaceID) == 0){ //SCT barrel hit
477 if (sctSide == 0) {
478 fill(m_tools[m_measurements_vs_Eta_Phi_sct_b_s0[layerDisk]], modEta_m, modPhi_m);
479 } else {
480 fill(m_tools[m_measurements_vs_Eta_Phi_sct_b_s1[layerDisk]], modEta_m, modPhi_m);
481 }
482 }
483 else if(m_sctID->barrel_ec(surfaceID) == 2){ //SCT endcap A hit
484 if (sctSide == 0) {
485 fill(m_tools[m_measurements_vs_Eta_Phi_sct_eca_s0[layerDisk]], modEta_m, modPhi_m);
486 } else {
487 fill(m_tools[m_measurements_vs_Eta_Phi_sct_eca_s1[layerDisk]], modEta_m, modPhi_m);
488 }
489 }
490 else if(m_sctID->barrel_ec(surfaceID) == -2){ //SCT endcap C hit
491 if (sctSide == 0) {
492 fill(m_tools[m_measurements_vs_Eta_Phi_sct_ecc_s0[layerDisk]], modEta_m, modPhi_m);
493 } else {
494 fill(m_tools[m_measurements_vs_Eta_Phi_sct_ecc_s1[layerDisk]], modEta_m, modPhi_m);
495 }
496 }
497 }
498
499 }
500 }
501
502 int nhpix= nhpixB +nhpixECA + nhpixECC;
503 int nhsct= nhsctB +nhsctECA + nhsctECC;
504 int nhtrt= nhtrtB +nhtrtECA + nhtrtECC;
505 int nhits= nhpix+ nhsct+ nhtrt;
506
507 auto nhits_per_track_m = Monitored::Scalar<float>( "m_nhits_per_track", nhits );
508 fill(genericTrackGroup, nhits_per_track_m);
509 //Pixel hits
510 auto npixelhits_per_track_m = Monitored::Scalar<float>( "m_npixelhits_per_track", nhpix );
511 auto npixelhits_per_track_barrel_m = Monitored::Scalar<float>( "m_npixelhits_per_track_barrel", nhpixB );
512 fill(genericTrackGroup, npixelhits_per_track_barrel_m);
513 auto npixelhits_per_track_eca_m = Monitored::Scalar<float>( "m_npixelhits_per_track_eca", nhpixECA );
514 fill(genericTrackGroup, npixelhits_per_track_eca_m);
515 auto npixelhits_per_track_ecc_m = Monitored::Scalar<float>( "m_npixelhits_per_track_ecc", nhpixECC );
516 fill(genericTrackGroup, npixelhits_per_track_ecc_m);
517 //SCT hits
518 auto nscthits_per_track_m = Monitored::Scalar<float>( "m_nscthits_per_track", nhsct );
519 auto nscthits_per_track_barrel_m = Monitored::Scalar<float>( "m_nscthits_per_track_barrel", nhsctB );
520 fill(genericTrackGroup, nscthits_per_track_barrel_m);
521 auto nscthits_per_track_eca_m = Monitored::Scalar<float>( "m_nscthits_per_track_eca", nhsctECA );
522 fill(genericTrackGroup, nscthits_per_track_eca_m);
523 auto nscthits_per_track_ecc_m = Monitored::Scalar<float>( "m_nscthits_per_track_ecc", nhsctECC );
524 fill(genericTrackGroup, nscthits_per_track_ecc_m);
525 //TRT hits
526 auto ntrthits_per_track_m = Monitored::Scalar<float>( "m_ntrthits_per_track", nhtrt );
527 auto ntrthits_per_track_barrel_m = Monitored::Scalar<float>( "m_ntrthits_per_track_barrel", nhtrtB );
528 fill(genericTrackGroup, ntrthits_per_track_barrel_m);
529 auto ntrthits_per_track_eca_m = Monitored::Scalar<float>( "m_ntrthits_per_track_eca", nhtrtECA );
530 fill(genericTrackGroup, ntrthits_per_track_eca_m);
531 auto ntrthits_per_track_ecc_m = Monitored::Scalar<float>( "m_ntrthits_per_track_ecc", nhtrtECC );
532 fill(genericTrackGroup, ntrthits_per_track_ecc_m);
533
534 auto chi2oDoF_m = Monitored::Scalar<float>( "m_chi2oDoF", chi2oDoF );
535 fill(genericTrackGroup, chi2oDoF_m);
536 auto eta_m = Monitored::Scalar<float>( "m_eta", trketa );
537 auto errEta_m = Monitored::Scalar<float>( "m_errEta", Err_eta );
538 fill(genericTrackGroup, errEta_m);
539
540 // Eta for positive and negative tracks
541 auto isTrkPositive = Monitored::Scalar<float>( "isTrkPositive", charge > 0 ? 1 : 0 );
542 auto isTrkNegative = Monitored::Scalar<float>( "isTrkNegative", charge > 0 ? 0 : 1 );
543
544 // z0
545 auto z0_m = Monitored::Scalar<float>( "m_z0", trkz0 );
546 auto errZ0_m = Monitored::Scalar<float>( "m_errZ0", Err_z0 );
547 auto z0_bscorr_m = Monitored::Scalar<float>( "m_z0_bscorr", trkz0-beamSpotZ );
548 float z0sintheta = trkz0*(sin(trktheta));
549 auto z0sintheta_m = Monitored::Scalar<float>( "m_z0sintheta", z0sintheta );
550 fill(genericTrackGroup, z0_m, errZ0_m, z0_bscorr_m, z0sintheta_m);
551
552 //d0
553 auto d0_m = Monitored::Scalar<float>( "m_d0", trkd0 );
554 fill(genericTrackGroup, d0_m);
555 auto errD0_m = Monitored::Scalar<float>( "m_errD0", Err_d0 );
556 fill(genericTrackGroup, errD0_m);
557 auto d0_bscorr_m = Monitored::Scalar<float>( "m_d0_bscorr", d0bscorr );
558
559 // Phi
560 auto phi_m = Monitored::Scalar<float>( "m_phi", trkphi );
561 auto errPhi_m = Monitored::Scalar<float>( "m_errPhi", Err_phi );
562
563 //d0 vs phi in barrel, End-Cap A, End-cap C
564 auto isTrackBarrel = Monitored::Scalar<float>( "isTrackBarrel", fabs(trketa) < m_barrelEta ? 1 : 0 );
565 auto isTrackECA = Monitored::Scalar<float>( "isTrackECA", trketa > m_barrelEta ? 1 : 0 );
566 auto isTrackECC = Monitored::Scalar<float>( "isTrackECC", trketa < - m_barrelEta ? 1 : 0 );
567
568 //pT and p
569 float pT = charge*trkpt;
570 auto pT_m = Monitored::Scalar<float>( "m_pT", pT );
571 auto errPt_m = Monitored::Scalar<float>( "m_errPt", Err_Pt );
572 auto pTRes_m = Monitored::Scalar<float>( "m_pTRes", std::fabs(Err_qOverP / qOverP) );
573
574 //d0 (BS) vs Eta, vs Phi (Phi, Barrel, EndCap A, EndCap C), vs pT // Eta vs Npixhits_per_track, SCT, TRT // Eta for positive and negative tracks
575 fill(genericTrackGroup, npixelhits_per_track_m, nscthits_per_track_m, ntrthits_per_track_m, eta_m, isTrkPositive, isTrkNegative, d0_bscorr_m, phi_m, isTrackBarrel, isTrackECA, isTrackECC, errPhi_m, pT_m, errPt_m, pTRes_m);
576
577 auto p_m = Monitored::Scalar<float>( "m_p", trkP );
578 fill(genericTrackGroup, p_m);
579 } //
580 // end of loop on trks
581 //
582
583 // histo with the count of used(good) tracks
584 auto ngTracks_m = Monitored::Scalar<float>( "m_ngTracks", ngTracks );
585 fill(genericTrackGroup, ngTracks_m);
586
587 ATH_MSG_DEBUG("Histogram filling completed for #good_tracks: " << ngTracks);
588
589 return StatusCode::SUCCESS;
590}
591
592const xAOD::Vertex* IDAlignMonGenericTracksAlg::findAssociatedVertexTP(const std::map<const xAOD::TrackParticle*, const xAOD::Vertex*>& trackVertexMapTP, const xAOD::TrackParticle *track) const
593{
594
595 std::map<const xAOD::TrackParticle*, const xAOD::Vertex* >::const_iterator tpVx = trackVertexMapTP.find( track);
596
597 if (tpVx == trackVertexMapTP.end() ){
598 ATH_MSG_VERBOSE("Did not find the vertex. Returning 0");
599 return nullptr;
600 }
601 return (*tpVx).second;
602
603}
604
605
607{
608
609 //find the link to the TrackParticleBase
610 const Trk::ITrackLink* trkLink = trkAtVx->trackOrParticleLink();
611 const Trk::TrackParticleBase* trkPB(nullptr);
612 if(nullptr!= trkLink){
613 const Trk::LinkToTrackParticleBase* linktrkPB = dynamic_cast<const Trk::LinkToTrackParticleBase *>(trkLink);
614 if(nullptr!= linktrkPB){
615 if(linktrkPB->isValid()) trkPB = linktrkPB->cachedElement();
616 }//end of dynamic_cast check
617 }//end of ITrackLink existance check
618
619 //cast to TrackParticle
620 if(trkPB){
621 if ( trkPB->trackElementLink()->isValid() ) {
622 // retrieve and refit original track
623 const Trk::Track* trktrk = trkPB->originalTrack();
624 return trktrk;
625 }
626 }
627 return nullptr;
628}
629
630
631
632bool IDAlignMonGenericTracksAlg::fillVertexInformation(std::map<const xAOD::TrackParticle*, const xAOD::Vertex*>& trackVertexMapTP, const EventContext& ctx ) const
633{
634 ATH_MSG_DEBUG("Generic Tracks: fillVertexInformation(): Checking ");
635 trackVertexMapTP.clear();
636
637 // retrieving vertices
638 auto handle_vxContainer = SG::makeHandle(m_VxPrimContainerName, ctx);
639
640 if (!handle_vxContainer.isPresent()) {
641 ATH_MSG_DEBUG ("InDetGlobalPrimaryVertexMonAlg: StoreGate doesn't contain primary vertex container with key "+m_VxPrimContainerName.key());
642 return false;
643 }
644 if (!handle_vxContainer.isValid()) {
645 ATH_MSG_ERROR ("InDetGlobalPrimaryVertexMonAlg: Could not retrieve primary vertex container with key "+m_VxPrimContainerName.key());
646 return false;
647 }
648
649 const auto *vertexContainer = handle_vxContainer.cptr();
650
651 for(const auto vtx : *vertexContainer) {
652 auto tpLinks = vtx->trackParticleLinks();
653 ATH_MSG_DEBUG("tpLinks size " << tpLinks.size());
654
655 if (tpLinks.size() > 4 ) {
656 for(const auto& link: tpLinks) {
657 const xAOD::TrackParticle *TP = *link;
658 if(TP) {
659 trackVertexMapTP.insert( std::make_pair( TP, vtx ) );
660 }
661 }
662 }
663 }
664
665 return true;
666}
#define M_PI
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
double charge(const T &p)
Definition AtlasPID.h:997
#define AmgSymMatrix(dim)
#define AmgVector(rows)
static Double_t sc
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
This is an Identifier helper class for the TRT subdetector.
constexpr int pow(int base, int exp) noexcept
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
virtual StatusCode initialize() override
initialize
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
std::vector< int > m_measurements_vs_Eta_Phi_sct_ecc_s1
std::vector< int > m_measurements_vs_Eta_Phi_pix_b
SG::ReadHandleKey< xAOD::VertexContainer > m_VxPrimContainerName
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
ToolHandle< Trk::ITrackToVertexIPEstimator > m_trackToVertexIPEstimator
const xAOD::Vertex * findAssociatedVertexTP(const std::map< const xAOD::TrackParticle *, const xAOD::Vertex * > &trackVertexMapTP, const xAOD::TrackParticle *) const
virtual StatusCode initialize() override
initialize
static const Trk::Track * getTrkTrack(const Trk::VxTrackAtVertex *)
std::vector< int > m_measurements_vs_Eta_Phi_sct_b_s0
std::vector< int > m_measurements_vs_Eta_Phi_sct_b_s1
ToolHandle< InDet::IInDetTrackSelectionTool > m_trackSelection
SG::ReadHandleKey< TrackCollection > m_tracksKey
std::vector< int > m_measurements_vs_Eta_Phi_sct_eca_s0
SG::ReadHandleKey< TrackCollection > m_tracksName
ToolHandle< IInDetAlignHitQualSelTool > m_hitQualityTool
std::vector< int > m_measurements_vs_Eta_Phi_sct_ecc_s0
IDAlignMonGenericTracksAlg(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< int > m_measurements_vs_Eta_Phi_sct_eca_s1
bool fillVertexInformation(std::map< const xAOD::TrackParticle *, const xAOD::Vertex * > &trackVertexMapTP, const EventContext &ctx) const
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
std::vector< int > m_measurements_vs_Eta_Phi_pix_ec
Declare a monitored scalar variable.
Class to represent and store fit qualities from track reconstruction in terms of and number of degre...
Definition FitQuality.h:97
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition FitQuality.h:60
double chiSquared() const
returns the of the overall track fit
Definition FitQuality.h:56
This class is the pure abstract base class for all fittable tracking measurements.
virtual const Surface & associatedSurface() const =0
Interface method to get the associated Surface.
double eta() const
Access method for pseudorapidity - from momentum.
double pT() const
Access method for transverse momentum.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
const TrkDetElementBase * associatedDetectorElement() const
return associated Detector Element
const ElementLink< TrackCollection > * trackElementLink() const
Return the ElementLink to the Track.
const Track * originalTrack() const
Return pointer to associated track.
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
virtual Identifier identify() const =0
Identifier.
The VxTrackAtVertex is a common class for all present TrkVertexFitters The VxTrackAtVertex is designe...
const ITrackLink * trackOrParticleLink(void) const
int lb
Definition globals.cxx:23
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable > > &&variables) const
Fills a vector of variables to a group by reference.
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx=Gaudi::Hive::currentContext()) const
Calculate the average mu, i.e.
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Eigen::Matrix< double, 3, 1 > Vector3D
Generic monitoring tool for athena components.
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ phi0
Definition ParamDefs.h:65
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ d0
Definition ParamDefs.h:63
@ z0
Definition ParamDefs.h:64
Definition run.py:1
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.