19#include "GaudiKernel/SmartDataPtr.h"
20#include "CLHEP/Units/SystemOfUnits.h"
71static const char *
const s_linestr =
"----------------------------------------------------------------------------------------------------------------------------------------------";
72static const char *
const s_linestr2 =
"..............................................................................................................................................";
118 "Measurement updator to calculate unbiased track states");
120 "Tool to calculate residuals and pulls");
162 if (sc1.isFailure()) {
164 return StatusCode::FAILURE;
168 ATH_MSG_ERROR(
"No reco track collection specified! Aborting.");
169 return StatusCode::FAILURE;
176 <<
" TrackTruthCollection keys."
177 <<
" You have to specify one TrackTruthCollection for each"
178 <<
" TrackCollection! Exiting."
180 return StatusCode::FAILURE;
187 ATH_MSG_FATAL(
"Could not retrieve measurement updator tool: "
189 return StatusCode::FAILURE;
194 "No Updator for unbiased track states given, use normal states!");
202 "No residual/pull calculator for general hit residuals configured."
205 "It is recommended to give R/P calculators to the det-specific tool"
206 <<
" handle lists then.");
209 <<
" (to calculate residuals and pulls) ");
212 ATH_MSG_INFO(
"Generic hit residuals&pulls will be calculated in one or both "
213 <<
"available local coordinates");
237 unsigned int nCollections = 0;
238 for (SG::ReadHandleKeyArray<TrackCollection>::const_iterator
249 if (sc3.isFailure()) {
251 return StatusCode::FAILURE;
258 return StatusCode :: SUCCESS;
278 return StatusCode::SUCCESS;
291 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > GenSignal;
293 unsigned int inTimeStart = 0;
294 unsigned int inTimeEnd = 0;
301 ATH_MSG_ERROR(
"No reco track collection specified! Aborting.");
302 return StatusCode::FAILURE;
306 std::vector< SG::ReadHandle<TrackTruthCollection> > truth_track_collections;
309 if (truth_track_collections.size() != rec_track_collections.size()) {
310 ATH_MSG_ERROR(
"Different number of reco and truth track collections (" << rec_track_collections.size() <<
"!=" << truth_track_collections.size() <<
")" );
314 ATH_MSG_ERROR(
"Number expected reco track collections does not match the actual number of such collections ("
315 <<
m_SignalCounters.size() <<
"!=" << rec_track_collections.size() <<
")" );
318 std::vector< SG::ReadHandle<TrackCollection> >
::iterator rec_track_collections_iter = rec_track_collections.begin();
319 std::vector< SG::ReadHandle<TrackTruthCollection> >
::iterator truth_track_collections_iter = truth_track_collections.begin();
320 for (std::vector <class TrackStatHelper *>::const_iterator statHelper
323 ++statHelper, ++rec_track_collections_iter) {
324 assert( rec_track_collections_iter != rec_track_collections.end());
327 const TrackCollection * RecCollection = &(**rec_track_collections_iter);
330 if (RecCollection)
ATH_MSG_DEBUG(
"Retrieved " << RecCollection->
size() <<
" reconstructed tracks from storegate");
334 assert( truth_track_collections_iter != truth_track_collections.end());
335 TruthMap = &(**truth_track_collections_iter);
336 if (TruthMap)
ATH_MSG_DEBUG(
"Retrieved " << TruthMap->size() <<
" TrackTruth elements from storegate");
337 ++truth_track_collections_iter;
342 std::vector <const Trk::Track *> RecTracks, RecSignal;
346 " RecTracks.size()=" << RecTracks.size()
347 <<
", GenSignal.size()=" << GenSignal.size());
350 (*statHelper)->addEvent (RecCollection,
365 it < RecCollection->end(); ++ it){
366 std::vector<const Trk::RIO_OnTrack*> rioOnTracks;
368 (*it)->measurementsOnTrack()->stdcont() );
373 m_counter += counter;
376 return StatusCode::SUCCESS;
382StatusCode InDet :: InDetRecStatisticsAlg :: finalize() {
389 for (std::vector <class TrackStatHelper *>::const_iterator collection =
393 delete (*collection);
396 return StatusCode::SUCCESS;
400StatusCode InDet :: InDetRecStatisticsAlg :: getServices ()
406 StatusCode
sc =
detStore()->retrieve(idDictMgr,
"IdDict");
407 if (
sc.isFailure()) {
409 return StatusCode::FAILURE;
414 if (
sc.isFailure()) {
416 return StatusCode::FAILURE;
422 msg(MSG::FATAL) <<
"Could not get Pixel ID helper" <<
endmsg;
423 return StatusCode::FAILURE;
426 msg(MSG::FATAL) <<
"Could not get SCT ID helper" <<
endmsg;
427 return StatusCode::FAILURE;
432 if (
sc.isFailure()) {
434 return StatusCode::FAILURE;
439 return StatusCode::FAILURE;
443 if (dict->file_name().find(
"SLHC")!=std::string::npos) isSLHC=
true;
447 msg(MSG::FATAL) <<
"Could not get TRT ID helper" <<
endmsg;
448 return StatusCode::FAILURE;
457 return StatusCode::FAILURE;
469 return StatusCode::FAILURE;
481 return StatusCode::FAILURE;
488 return StatusCode :: SUCCESS;
491StatusCode InDet :: InDetRecStatisticsAlg :: resetStatistics() {
495 for (std::vector<InDet::TrackStatHelper *>::const_iterator counter =
500 return StatusCode :: SUCCESS;
504 std::vector <const Trk::Track *> & RecTracks ,
505 std::vector <const Trk::Track *> & RecSignal,
509 it != RecCollection->
end(); ++ it){
510 RecTracks.push_back(*it);
512 (*it)->trackParameters();
514 if(!trackpara->
empty()){
518 RecSignal.push_back(*it);
529void InDet :: InDetRecStatisticsAlg ::
531 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > & GenSignal,
532 unsigned int ,
unsigned int ,
535 if (! SimTracks)
return;
537 unsigned int nb_mc_event = SimTracks->size();
538 std::unique_ptr<PileUpType> put = std::make_unique<PileUpType>(SimTracks);
545 inTimeMBbegin = put->in_time_minimum_bias_event_begin();
546 inTimeMBend = put->in_time_minimum_bias_event_end();
549 for(
unsigned int ievt=0; ievt<nb_mc_event; ++ievt)
551 const HepMC::GenEvent* genEvent = SimTracks->at(ievt);
553 for (
const auto& particle: *genEvent){
556 int pdgCode = particle->pdg_id();
559 if (std::abs(
charge)<0.5)
continue;
560 if (std::abs(particle->momentum().perp()) >
m_minPt &&
561 std::abs(particle->momentum().pseudoRapidity()) <
m_maxEta ) {
562 std::pair<HepMC::ConstGenParticlePtr,int> thisPair(particle,ievt);
563 GenSignal.push_back(thisPair);
571 template <
class T_Stream>
575 RestoreStream(T_Stream &out) : m_stream(&out),m_precision(out.precision()) { }
576 ~RestoreStream() { (*m_stream).precision(m_precision); }
583void InDet :: InDetRecStatisticsAlg :: printStatistics() {
584 if (!
msgLvl(MSG::INFO))
return;
586 ATH_MSG_INFO(
" ********** Beginning InDetRecStatistics Statistics Table ***********");
587 ATH_MSG_INFO(
"For documentation see https://twiki.cern.ch/twiki/bin/view/Atlas/InDetRecStatistics");
588 ATH_MSG_INFO(
"(or for guaranteed latest version: http://atlas-sw.cern.ch/cgi-bin/viewcvs-atlas.cgi/offline/InnerDetector/InDetValidation/InDetRecStatistics/doc/mainpage.h?&view=markup )");
589 ATH_MSG_INFO(
" ********************************************************************");
591 std::stringstream outstr;
592 int def_precision(outstr.precision());
595 << std::setiosflags(std::ios::fixed | std::ios::showpoint)
596 << std::setw(7) << std::setprecision(2)
603 <<
" truth particles" <<
"\n"
605 <<
" tracks without perigee, "
607 <<
"\t" <<
"Reco TrackCollections : ";
609 for (std::vector <class TrackStatHelper *>::const_iterator collection =
619 outstr <<
"\"" << (*collection)->key() <<
"\"";
628 <<
"\t" <<
"TrackTruthCollections : ";
630 for (std::vector <class TrackStatHelper *>::const_iterator collection =
m_SignalCounters.begin();
639 outstr <<
"\"" << (*collection)->Truthkey() <<
"\"";
647 <<
"Cuts and Settings for Statistics Table" <<
"\n"
648 <<
"\t" <<
"TrackSummary Statistics" <<
"\t"
650 <<
"\t" <<
"Signal \t" <<
"pT > "
652 <<
"\t" <<
"Primary track start \t" <<
"R < "
655 <<
"\t" <<
"Barrel \t" << 0.0
657 <<
"\t" <<
"Primary track end \t" <<
"R > "
662 <<
"\t" <<
"Secondary (non-Primary) start \t"
667 <<
"\t" <<
"Secondary (non-primary) end \t"
670 <<
"\t" <<
"Forward \t"
672 <<
"\t" <<
"Low prob tracks #1 \t" <<
"< "
675 <<
"\t" <<
"Low prob tracks #2 \t" <<
"< "
678 <<
"\t" <<
"No link tracks \t Track has no link associated to an HepMC Particle" <<
"\n"
679 <<
"\t" <<
"Good reco tracks \t" <<
"> "
684 MsgStream &out =
msg(MSG::INFO);
686 RestoreStream<MsgStream> restore(out);
694 <<
"Detailed Statistics for Hits on Reconstructed tracks, using TrackSummary: (Preselection of tracks as described above.)" <<
"\n"
696 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
697 <<
" Reco Tracks .........................................hits/track....................................................... " <<
"\n"
698 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
699 <<
" in BARREL tracks/event " << track_stummary_type_header <<
"\n"
700 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
704 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
705 <<
" in TRANSITION region tracks/event " << track_stummary_type_header <<
"\n"
706 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------"
711 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
712 <<
" in ENDCAP tracks/event " << track_stummary_type_header <<
"\n"
713 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
717 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
718 <<
" in FORWARD region tracks/event " << track_stummary_type_header <<
"\n"
719 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
725 outstr <<
"\n" << std::setprecision(def_precision)
727 <<
"Statistics for Secondaries (non-Primaries)"<<
"\n"
728 <<
"\t" <<
"Secondary track start \t"
731 <<
"\t" <<
"Secondary track end \t"
743 ATH_MSG_INFO(
" ********** Ending InDetRecStatistics Statistics Table ***********");
749void InDet :: InDetRecStatisticsAlg ::printTrackSummary (MsgStream &out,
enum eta_region eta_reg)
751 bool printed =
m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_ALL, eta_reg);
755 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
758 printed =
m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_LOWTRUTHPROB, eta_reg);
761 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
764 m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_LOWTRUTHPROB2, eta_reg);
771float InDet :: InDetRecStatisticsAlg :: calculatePull(
const float residual,
775 ErrorSum = sqrt(
pow(trkErr, 2) +
pow(hitErr, 2));
776 if (ErrorSum != 0) {
return residual/ErrorSum; }
793 if ( trkParameters->covariance() ) {
796 unbiasedTrkParameters =
797 m_updator->removeFromState( *trkParameters,
801 if (!unbiasedTrkParameters) {
803 <<
"use normal parameters");
809 <<
"Unbiased track states can not be calculated "
810 <<
"(ie. pulls and residuals will be too small)");
817 return unbiasedTrkParameters;
837 <<
" can not determine detector type");
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
double charge(const T &p)
ATLAS-specific HepMC functions.
Extrapolation for HepMC particles.
static const char *const s_linestr
static const char *const s_linestr2
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.
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
constexpr int pow(int base, int exp) noexcept
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
An algorithm that can be simultaneously executed in multiple threads.
DataModel_detail::const_iterator< DataVector > const_iterator
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const T * front() const
Access the first element in the collection as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
IdDictManager is the interface to identifier dictionaries.
const TRT_ID * m_trtID
get trt layer from hit ID
float m_minZEndSecondary
If track has end vertex, this is min Z of end vertex to be considered secondary.
void selectGenSignal(const McEventCollection *, std::vector< std::pair< HepMC::ConstGenParticlePtr, int > > &, unsigned int, unsigned int, CounterLocal &counter) const
Select charged,stable particles which pass pt and eta cuts for analysis.
ToolHandle< Trk::ITruthToTrack > m_truthToTrack
tool to create track parameters from a gen particle
std::atomic< long > m_events_processed
number of events processed
Trk::IUpdator * m_updator
updator for unbiased states
std::atomic< int > m_isUnbiased
if can get unbiased residuals
float m_maxEta
Maximum Eta cut for tracks used by the algorithm.
SG::ReadHandleKey< McEventCollection > m_McTrackCollection_key
StatusCode getServices()
Get various services such as StoreGate, dictionaries, detector managers etc.
float m_minREndSecondary
If track has end vertex, this is min R of end vertex to be considered secondary.
float m_maxRStartSecondary
Maximum R of start vertex to be considered secondary.
StatusCode resetStatistics()
Clear statistics counters, called before each track collection is processed.
const AtlasDetectorID * m_idHelper
Used to find out the sub-det from PRD->identify().
SG::ReadHandleKeyArray< TrackTruthCollection > m_TrackTruthCollection_keys
std::atomic< bool > m_pullWarning
warn only once, if pull cannot be calculated
float m_minZEndPrimary
If track has end vertex, this is min Z of end vertex to be considered primary.
const IdDictManager * m_idDictMgr
void printStatistics()
Print tracking statistics calculated with TrackStatHelper.
float m_maxZStartPrimary
Maximum Z of start vertex to be considered primary.
bool m_printSecondary
Flag to print hit information for secondary tracks.
const PixelID * m_pixelID
get pixel layer from hit ID
float m_minREndPrimary
If track has end vertex, this is min R of end vertex to be considered primary.
InDetRecStatisticsAlg(const std::string &name, ISvcLocator *pSvcLocator)
Default Constructor.
float m_fakeTrackCut2
Second definition of maximum probability for which a track will be considered a fake.
StatusCode execute(const EventContext &ctx) const
Calculation of statistics.
float m_maxRStartPrimary
Maximum R of start vertex to be considered primary.
float m_maxEtaEndcap
define max eta of eta region
bool m_doTruth
Use truth information.
ToolHandle< Trk::IResidualPullCalculator > m_residualPullCalculator
The residual and pull calculator tool handle.
std::vector< class TrackStatHelper * > m_SignalCounters
Vector of TrackStatHelper objects, one for each track collection.
float m_maxEtaTransition
define max eta of transition region
std::atomic< bool > m_UpdatorWarning
warn only once, if unbiased track states can not be calculated
ToolHandle< Trk::IUpdator > m_updatorHandle
Tool handle of updator for unbiased states.
void selectRecSignal(const TrackCollection *, std::vector< const Trk::Track * > &, std::vector< const Trk::Track * > &, CounterLocal &counter) const
Select for analysis reconstructed tracks passing Pt and eta cuts.
const SCT_ID * m_sctID
get sct layer from hit ID
Identifier getIdentifier(const Trk::MeasurementBase *measurement)
ToolHandle< Trk::IExtendedTrackSummaryTool > m_trkSummaryTool
tool to get track summary information from track
const Trk::TrackParameters * getUnbiasedTrackParameters(const Trk::TrackParameters *, const Trk::MeasurementBase *)
Get Unbiased Track Parameters.
SG::ReadHandleKeyArray< TrackCollection > m_RecTrackCollection_keys
ToolHandle< Trk::ITrackSelectorTool > m_trackSelectorTool
float m_minPt
Minimum Pt cut for tracks used by the algorithm.
bool m_UseTrackSummary
Flag to print detailed statistics for each track collection.
float m_fakeTrackCut
Maximum probability for which a track will be considered a fake.
@ kN_gen_tracks_processed
number of generated tracks processed
@ kN_rec_tracks_processed
number of reconstructed tracks processed
@ kN_rec_tracks_without_perigee
number of tracks w/o perigee
@ kN_spacepoints_processed
number of space points processed
@ kN_unknown_hits
number of hits without track
Counter< int > CounterLocal
void printTrackSummary(MsgStream &out, enum eta_region)
Print track statistics for all and low proability tracks.
float m_maxEtaBarrel
define max eta of barrel region
StatusCode initialize()
Initialization of services, track collections, creates TrackStatHelper for each Track Collection.
bool m_useTrackSelection
Use track selector tool.
float m_maxZStartSecondary
Maximum Z of start vertex to be considered secondary.
float m_matchTrackCut
Minimum number of hits from a truth track to be considered a matched reco track.
static std::string getSummaryTypeHeader()
void SetCuts(const struct cuts &)
Sets the cuts such as the eta regions (barrel, transition,endcap) and the hit fraction fake cuts and ...
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
unsigned int indexOfMaxAssignProb() const
Index of the ROT with the highest assignment probability.
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
const Amg::MatrixX & localCovariance() const
Interface method to get the localError.
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.
Identifier identify() const
return the identifier -extends MeasurementBase
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
double charge(const T &p)
bool isNucleus(const T &p)
PDG rule 16 Nuclear codes are given as 10-digit numbers ±10LZZZAAAI.
ParametersBase< TrackParametersDim, Charged > TrackParameters