19#include "GaudiKernel/SmartDataPtr.h"
20#include "CLHEP/Units/SystemOfUnits.h"
73static const char *
const s_linestr =
"----------------------------------------------------------------------------------------------------------------------------------------------";
74static const char *
const s_linestr2 =
"..............................................................................................................................................";
120 "Measurement updator to calculate unbiased track states");
122 "Tool to calculate residuals and pulls");
164 if (sc1.isFailure()) {
166 return StatusCode::FAILURE;
170 ATH_MSG_ERROR(
"No reco track collection specified! Aborting.");
171 return StatusCode::FAILURE;
178 <<
" TrackTruthCollection keys."
179 <<
" You have to specify one TrackTruthCollection for each"
180 <<
" TrackCollection! Exiting."
182 return StatusCode::FAILURE;
189 ATH_MSG_FATAL(
"Could not retrieve measurement updator tool: "
191 return StatusCode::FAILURE;
196 "No Updator for unbiased track states given, use normal states!");
204 "No residual/pull calculator for general hit residuals configured."
207 "It is recommended to give R/P calculators to the det-specific tool"
208 <<
" handle lists then.");
211 <<
" (to calculate residuals and pulls) ");
214 ATH_MSG_INFO(
"Generic hit residuals&pulls will be calculated in one or both "
215 <<
"available local coordinates");
239 unsigned int nCollections = 0;
240 for (SG::ReadHandleKeyArray<TrackCollection>::const_iterator
251 if (sc3.isFailure()) {
253 return StatusCode::FAILURE;
260 return StatusCode :: SUCCESS;
280 return StatusCode::SUCCESS;
293 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > GenSignal;
295 unsigned int inTimeStart = 0;
296 unsigned int inTimeEnd = 0;
303 ATH_MSG_ERROR(
"No reco track collection specified! Aborting.");
304 return StatusCode::FAILURE;
308 std::vector< SG::ReadHandle<TrackTruthCollection> > truth_track_collections;
311 if (truth_track_collections.size() != rec_track_collections.size()) {
312 ATH_MSG_ERROR(
"Different number of reco and truth track collections (" << rec_track_collections.size() <<
"!=" << truth_track_collections.size() <<
")" );
316 ATH_MSG_ERROR(
"Number expected reco track collections does not match the actual number of such collections ("
317 <<
m_SignalCounters.size() <<
"!=" << rec_track_collections.size() <<
")" );
320 std::vector< SG::ReadHandle<TrackCollection> >
::iterator rec_track_collections_iter = rec_track_collections.begin();
321 std::vector< SG::ReadHandle<TrackTruthCollection> >
::iterator truth_track_collections_iter = truth_track_collections.begin();
322 for (std::vector <class TrackStatHelper *>::const_iterator statHelper
325 ++statHelper, ++rec_track_collections_iter) {
326 assert( rec_track_collections_iter != rec_track_collections.end());
329 const TrackCollection * RecCollection = &(**rec_track_collections_iter);
332 if (RecCollection)
ATH_MSG_DEBUG(
"Retrieved " << RecCollection->
size() <<
" reconstructed tracks from storegate");
336 assert( truth_track_collections_iter != truth_track_collections.end());
337 TruthMap = &(**truth_track_collections_iter);
338 if (TruthMap)
ATH_MSG_DEBUG(
"Retrieved " << TruthMap->size() <<
" TrackTruth elements from storegate");
339 ++truth_track_collections_iter;
344 std::vector <const Trk::Track *> RecTracks, RecSignal;
348 " RecTracks.size()=" << RecTracks.size()
349 <<
", GenSignal.size()=" << GenSignal.size());
352 (*statHelper)->addEvent (ctx,
368 it < RecCollection->end(); ++ it){
369 std::vector<const Trk::RIO_OnTrack*> rioOnTracks;
371 (*it)->measurementsOnTrack()->stdcont() );
376 m_counter += counter;
379 return StatusCode::SUCCESS;
385StatusCode InDet :: InDetRecStatisticsAlg :: finalize() {
392 for (std::vector <class TrackStatHelper *>::const_iterator collection =
396 delete (*collection);
399 return StatusCode::SUCCESS;
403StatusCode InDet :: InDetRecStatisticsAlg :: getServices ()
409 StatusCode
sc =
detStore()->retrieve(idDictMgr,
"IdDict");
410 if (
sc.isFailure()) {
412 return StatusCode::FAILURE;
417 if (
sc.isFailure()) {
419 return StatusCode::FAILURE;
425 msg(MSG::FATAL) <<
"Could not get Pixel ID helper" <<
endmsg;
426 return StatusCode::FAILURE;
429 msg(MSG::FATAL) <<
"Could not get SCT ID helper" <<
endmsg;
430 return StatusCode::FAILURE;
435 if (
sc.isFailure()) {
437 return StatusCode::FAILURE;
442 return StatusCode::FAILURE;
446 if (dict->file_name().find(
"SLHC")!=std::string::npos) isSLHC=
true;
450 msg(MSG::FATAL) <<
"Could not get TRT ID helper" <<
endmsg;
451 return StatusCode::FAILURE;
460 return StatusCode::FAILURE;
472 return StatusCode::FAILURE;
484 return StatusCode::FAILURE;
491 return StatusCode :: SUCCESS;
494StatusCode InDet :: InDetRecStatisticsAlg :: resetStatistics() {
498 for (std::vector<InDet::TrackStatHelper *>::const_iterator counter =
503 return StatusCode :: SUCCESS;
507 std::vector <const Trk::Track *> & RecTracks ,
508 std::vector <const Trk::Track *> & RecSignal,
512 it != RecCollection->
end(); ++ it){
513 RecTracks.push_back(*it);
515 (*it)->trackParameters();
517 if(!trackpara->
empty()){
521 RecSignal.push_back(*it);
532void InDet :: InDetRecStatisticsAlg ::
534 std::vector <std::pair<HepMC::ConstGenParticlePtr,int> > & GenSignal,
535 unsigned int ,
unsigned int ,
538 if (! SimTracks)
return;
540 unsigned int nb_mc_event = SimTracks->size();
541 std::unique_ptr<PileUpType> put = std::make_unique<PileUpType>(SimTracks);
548 inTimeMBbegin = put->in_time_minimum_bias_event_begin();
549 inTimeMBend = put->in_time_minimum_bias_event_end();
552 for(
unsigned int ievt=0; ievt<nb_mc_event; ++ievt)
556 for (
const auto& particle: *genEvent){
559 int pdgCode = particle->pdg_id();
562 if (std::abs(
charge)<0.5)
continue;
563 if (std::abs(particle->momentum().perp()) >
m_minPt &&
564 std::abs(particle->momentum().pseudoRapidity()) <
m_maxEta ) {
565 GenSignal.emplace_back(particle,ievt);
573 template <
class T_Stream>
577 RestoreStream(T_Stream &out) : m_stream(&out),m_precision(out.precision()) { }
578 ~RestoreStream() { (*m_stream).precision(m_precision); }
585void InDet :: InDetRecStatisticsAlg :: printStatistics() {
586 if (!
msgLvl(MSG::INFO))
return;
588 ATH_MSG_INFO(
" ********** Beginning InDetRecStatistics Statistics Table ***********");
589 ATH_MSG_INFO(
"For documentation see https://twiki.cern.ch/twiki/bin/view/Atlas/InDetRecStatistics");
590 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 )");
591 ATH_MSG_INFO(
" ********************************************************************");
593 std::stringstream outstr;
594 int def_precision(outstr.precision());
597 << std::setiosflags(std::ios::fixed | std::ios::showpoint)
598 << std::setw(7) << std::setprecision(2)
605 <<
" truth particles" <<
"\n"
607 <<
" tracks without perigee, "
609 <<
"\t" <<
"Reco TrackCollections : ";
611 for (std::vector <class TrackStatHelper *>::const_iterator collection =
621 outstr <<
"\"" << (*collection)->key() <<
"\"";
630 <<
"\t" <<
"TrackTruthCollections : ";
632 for (std::vector <class TrackStatHelper *>::const_iterator collection =
m_SignalCounters.begin();
641 outstr <<
"\"" << (*collection)->Truthkey() <<
"\"";
649 <<
"Cuts and Settings for Statistics Table" <<
"\n"
650 <<
"\t" <<
"TrackSummary Statistics" <<
"\t"
652 <<
"\t" <<
"Signal \t" <<
"pT > "
654 <<
"\t" <<
"Primary track start \t" <<
"R < "
657 <<
"\t" <<
"Barrel \t" << 0.0
659 <<
"\t" <<
"Primary track end \t" <<
"R > "
664 <<
"\t" <<
"Secondary (non-Primary) start \t"
669 <<
"\t" <<
"Secondary (non-primary) end \t"
672 <<
"\t" <<
"Forward \t"
674 <<
"\t" <<
"Low prob tracks #1 \t" <<
"< "
677 <<
"\t" <<
"Low prob tracks #2 \t" <<
"< "
680 <<
"\t" <<
"No link tracks \t Track has no link associated to an HepMC Particle" <<
"\n"
681 <<
"\t" <<
"Good reco tracks \t" <<
"> "
686 MsgStream &out =
msg(MSG::INFO);
688 RestoreStream<MsgStream> restore(out);
696 <<
"Detailed Statistics for Hits on Reconstructed tracks, using TrackSummary: (Preselection of tracks as described above.)" <<
"\n"
698 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
699 <<
" Reco Tracks .........................................hits/track....................................................... " <<
"\n"
700 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
701 <<
" in BARREL tracks/event " << track_stummary_type_header <<
"\n"
702 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
706 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
707 <<
" in TRANSITION region tracks/event " << track_stummary_type_header <<
"\n"
708 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------"
713 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
714 <<
" in ENDCAP tracks/event " << track_stummary_type_header <<
"\n"
715 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
719 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n"
720 <<
" in FORWARD region tracks/event " << track_stummary_type_header <<
"\n"
721 <<
"----------------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
727 outstr <<
"\n" << std::setprecision(def_precision)
729 <<
"Statistics for Secondaries (non-Primaries)"<<
"\n"
730 <<
"\t" <<
"Secondary track start \t"
733 <<
"\t" <<
"Secondary track end \t"
745 ATH_MSG_INFO(
" ********** Ending InDetRecStatistics Statistics Table ***********");
751void InDet :: InDetRecStatisticsAlg ::printTrackSummary (MsgStream &out,
enum eta_region eta_reg)
753 bool printed =
m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_ALL, eta_reg);
757 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
760 printed =
m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_LOWTRUTHPROB, eta_reg);
763 <<
"----------------------------------------------------------------------------------------------------------------------------------------------" <<
"\n";
766 m_SignalCounters.back()->printTrackSummaryRegion(out, TRACK_LOWTRUTHPROB2, eta_reg);
773float InDet :: InDetRecStatisticsAlg :: calculatePull(
const float residual,
777 ErrorSum = sqrt(pow(trkErr, 2) + pow(hitErr, 2));
778 if (ErrorSum != 0) {
return residual/ErrorSum; }
795 if ( trkParameters->covariance() ) {
798 unbiasedTrkParameters =
799 m_updator->removeFromState( *trkParameters,
803 if (!unbiasedTrkParameters) {
805 <<
"use normal parameters");
811 <<
"Unbiased track states can not be calculated "
812 <<
"(ie. pulls and residuals will be too small)");
819 return unbiasedTrkParameters;
839 <<
" 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.
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
HepMC3::GenEvent GenEvent
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