13#include "Acts/Definitions/Units.hpp"
14#include "Acts/MagneticField/MagneticFieldContext.hpp"
48 ATH_MSG_DEBUG(
"Filling Histograms for " << name() <<
" ... " );
54 auto beamSpotData = beamSpotHandle.
cptr();
63 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
65 Acts::Vector2 beamPos( beamSpotData->beamPos()[
Amg::x ] * Acts::UnitConstants::mm,
66 beamSpotData->beamPos()[
Amg::y ] * Acts::UnitConstants::mm );
70 Acts::MagneticFieldProvider::Cache magFieldCache = magneticField.
makeCache( magFieldContext );
71 Acts::Vector3 bField = *magneticField.
getField( Acts::Vector3(beamPos.x(), beamPos.y(), 0),
88 [] (
const auto& seed) ->
double
89 {
return seed.sp()[0]->x(); });
92 [] (
const auto& seed) ->
double
93 {
return seed.sp()[0]->y(); });
96 [] (
const auto& seed) ->
double
97 {
return seed.sp()[0]->z(); });
100 [] (
const auto& seed) ->
double
102 const auto*
sp = seed.sp()[0];
103 return std::sqrt(
sp->x()*
sp->x() +
sp->y()*
sp->y());
109 [] (
const auto& seed) ->
double
110 {
return seed.sp()[1]->x(); });
113 [] (
const auto& seed) ->
double
114 {
return seed.sp()[1]->y(); });
117 [] (
const auto& seed) ->
double
118 {
return seed.sp()[1]->z(); });
121 [] (
const auto& seed) ->
double
123 const auto*
sp = seed.sp()[1];
124 return std::sqrt(
sp->x()*
sp->x() +
sp->y()*
sp->y());
130 [] (
const auto& seed) ->
double
131 {
return seed.sp()[2]->x(); });
134 [] (
const auto& seed) ->
double
135 {
return seed.sp()[2]->y(); });
138 [] (
const auto& seed) ->
double
139 {
return seed.sp()[2]->z(); });
142 [] (
const auto& seed) ->
double
144 const auto*
sp = seed.sp()[2];
145 return std::sqrt(
sp->x()*
sp->x() +
sp->y()*
sp->y());
148 std::vector< std::array<float, 7> > parametersCollection;
149 parametersCollection.reserve(seed_collection->
size());
151 for (
auto seed : *seed_collection) {
156 [] (
const auto& params) ->
float
157 {
return params[0]; });
159 [] (
const auto& params) ->
float
160 {
return params[1]; });
162 [] (
const auto& params) ->
float
163 {
return params[2]; });
165 [] (
const auto& params) ->
float
166 {
return params[3]; });
169 [] (
const auto& params) ->
float
170 {
return params[4]; });
172 [] (
const auto& params) ->
float
173 {
return params[5]; });
177 [] (
const auto& params) ->
float
178 {
return params[6]; });
184 auto monitor_event_number =
Monitored::Scalar<long>(
"event_number",
static_cast<long>(eventInfo->eventNumber()));
187 std::vector<int> vec_truthBarcode;
188 std::vector<double> vec_truthProb;
195 monitor_x1, monitor_y1, monitor_z1, monitor_r1,
196 monitor_x2, monitor_y2, monitor_z2, monitor_r2,
197 monitor_x3, monitor_y3, monitor_z3, monitor_r3,
198 monitor_param_pt, monitor_param_theta, monitor_param_eta, monitor_param_d0,
199 monitor_param_dzdr_b, monitor_param_dzdr_t,
200 monitor_param_penalty,
201 monitor_event_number, monitor_actual_mu,
202 monitor_truth_barcode, monitor_truth_prob);
204 return StatusCode::SUCCESS;
209 std::vector<int>& truthBarCodeVec,
210 std::vector<double>& truthProbVec)
const
212 ATH_MSG_DEBUG(
"Filling Truth Histograms for " << name() <<
" ... " );
229 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
235 auto retrieveSurfaceFunction =
236 [
this, &detElements] (
const ActsTrk::Seed& seed,
bool useTopSp) ->
const Acts::Surface&
240 useTopSp ?
sp->elementIdList().back() :
sp->elementIdList().front());
247 std::vector<bool> vec_pass;
248 vec_pass.reserve(seed_container.
size());
250 std::vector<double> estimated_pt;
251 std::vector<double> estimated_eta;
252 estimated_pt.reserve(seed_container.
size());
253 estimated_eta.reserve(seed_container.
size());
255 for (
auto seed : seed_container) {
256 std::optional<Acts::BoundTrackParameters> optTrackParams =
260 geo_context.context(),
262 retrieveSurfaceFunction);
264 if ( not optTrackParams.has_value() )
continue;
266 const auto param = optTrackParams.value();
267 estimated_pt.push_back( param.transverseMomentum() );
268 estimated_eta.push_back( -std::log( std::tan(0.5 * param.parameters()[Acts::eBoundTheta]) ) );
270 std::map<int, int> truthHits;
272 const auto& sps = seed.sp();
273 for (
const auto*
sp : sps) {
275 for (
int cluster_number(0); cluster_number < number_of_clusters; cluster_number++) {
276 const auto& els =
sp->measurements();
277 const auto* cluster = els[cluster_number];
287 truthBarCodeVec.push_back(barcode);
288 truthProbVec.push_back(prob);
289 vec_pass.push_back( barcode != 0 and prob > 0.5 );
298 monitor_estimated_pt, monitor_estimated_eta);
300 return StatusCode::SUCCESS;
313 return (*pixelLink)->identify();
326 return (*stripLink)->identify();
332 std::map<int, int>& countMap)
const {
333 auto n1 = prdTruth->count(
id);
336 auto nBC = countMap.count(bc);
343 using iprdt = PRD_MultiTruthCollection::const_iterator;
344 std::pair<iprdt, iprdt> range = prdTruth->equal_range(
id);
345 for (iprdt itr = range.first; itr != range.second; ++itr) {
346 auto bc = itr->second.barcode();
347 auto nBC = countMap.count(bc);
361 int bestBarcode = std::numeric_limits<int>::min();
363 for (
auto const& [barcode,
count] : countMap) {
364 if (
count > bestCount) {
366 bestBarcode = barcode;
372 double prob = bestCount / nTotal;
374 return std::make_pair(bestBarcode, prob);
378 float pTPerHelixRadius)
const
380 auto extractCoordinates =
383 std::array<float, 4> coordinates {
static_cast<float>(
sp->x()),
384 static_cast<float>(
sp->y()),
385 static_cast<float>(
sp->z()),
386 static_cast<float>(std::sqrt(
sp->x()*
sp->x() +
sp->y()*
sp->y()))};
390 auto extractQuantities =
391 [] (
const std::array<float, 4>&
sp,
392 const std::array<float, 4>& spM,
393 bool isBottom) -> std::array<float, 5>
395 auto& [xM, yM, zM, rM] = spM;
396 auto& [xO, yO, zO, rO] =
sp;
398 float cosPhiM = xM / rM;
399 float sinPhiM = yM / rM;
400 float deltaX = xO - xM;
401 float deltaY = yO - yM;
402 float deltaZ = zO - zM;
403 float x = deltaX * cosPhiM + deltaY * sinPhiM;
404 float y = deltaY * cosPhiM - deltaX * sinPhiM;
405 float iDeltaR2 = 1.f / (deltaX * deltaX + deltaY * deltaY);
406 float iDeltaR = std::sqrt(iDeltaR2);
408 float cot_theta = deltaZ * iDeltaR * bottomFactor;
411 std::array<float, 5> params =
423 const auto& sps = seed.sp();
424 const auto* bottom = sps[0];
425 const auto* medium = sps[1];
426 const auto*
top = sps[2];
428 auto coo_b = extractCoordinates(bottom);
429 auto coo_m = extractCoordinates(medium);
430 auto coo_t = extractCoordinates(
top);
433 auto [cotThetaB, Zob, iDeltaRB, Ub, Vb] = extractQuantities(coo_b, coo_m,
true);
434 auto [cotThetaT, Zot, iDeltaRT, Ut, Vt] = extractQuantities(coo_t, coo_m,
false);
436 float squarediDeltaR2B = iDeltaRB*iDeltaRB;
437 float squarediDeltaR2T = iDeltaRB*iDeltaRT;
438 float squarediDeltaR = std::min(squarediDeltaR2B, squarediDeltaR2T);
440 auto& [xB, yB, zB, rB] = coo_b;
441 auto& [xM, yM, zM, rM] = coo_m;
442 auto& [xT, yT, zT, rT] = coo_t;
450 float xb = dxb * ax + dyb *ay;
451 float yb = dyb * ax - dxb * ay;
452 float dxyb = xb * xb + yb * yb;
456 float xt = dxt * ax + dyt *ay;
457 float yt = dyt * ax - dxt * ay;
460 float tzb = dzb * std::sqrt( 1.f/dxyb );
461 float tzt = dzt * std::sqrt( 1.f/dxyt );
463 float sTzb2 = std::sqrt(1.f + tzb*tzb);
467 return {-1, -1, -1, -1, -1, -1, -1};
470 float A = (Vt - Vb) / dU;
471 float S2 = 1.f +
A *
A;
472 float B = Vb -
A * Ub;
474 if (B2 == 0) B2 = 1e-8;
477 float dzdr_b = (zM - zB) / (rM - rB);
478 float dzdr_t = (zT - zM) / (rT - rM);
481 float cotThetaAvg2 = cotThetaB * cotThetaT;
482 if (cotThetaAvg2 <= 0) {
483 return {-1, -1, -1, -1, -1, -1, -1};
485 float theta = std::atan(1.f / std::sqrt(cotThetaAvg2));
486 float eta = -std::log(std::tan(0.5f *
theta));
489 float pt = pTPerHelixRadius * std::sqrt(
S2 / B2) / 2.f;
492 float d0 = std::abs((
A - B * rM) * rM);
497 float penalty = std::abs((tzb - tzt) / (squarediDeltaR * sTzb2));
499 return {pt,
theta,
eta, d0, dzdr_b, dzdr_t, penalty};
Scalar eta() const
pseudorapidity method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
bool isBottom(const T &p)
Helper class to provide constant type-safe access to aux data.
This is an Identifier helper class for the Pixel subdetector.
struct TBPatternUnitContext S2
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Acts::MagneticFieldProvider::Cache &gcache) const override
MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
std::pair< int, double > findSeedMajorityTruthParticle(const std::map< int, int > &countMap) const
SeedAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< bool > m_usePixel
StatusCode fillTruthHistograms(const EventContext &ctx, const ActsTrk::SeedContainer &seed_container, std::vector< int > &, std::vector< double > &) const
ToolHandle< ActsTrk::ITrackParamsEstimationTool > m_paramEstimationTool
const Identifier identify(const xAOD::PixelCluster &) const
void matchParticleToSeedClusters(const PRD_MultiTruthCollection *prdTruth, const Identifier &id, std::map< int, int > &countMap) const
std::array< float, 7 > estimateParameters(const ActsTrk::Seed &seed, float pTPerHelixRadius) const
SG::ReadHandleKey< PRD_MultiTruthCollection > m_prdTruth
virtual StatusCode initialize() override
initialize
Gaudi::Property< std::string > m_monGroupName
PublicToolHandle< IGeometryRealmConvTool > m_geometryConvTool
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
SG::ReadHandleKey< ActsTrk::SeedContainer > m_inputSeedColletionKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_detEleCollKey
Gaudi::Property< bool > m_useTopSp
virtual StatusCode initialize() override
initialize
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Key for retrieving EventInfo from StoreGate.
ElementLink implementation for ROOT usage.
Class to hold the SiDetectorElement objects to be put in the detector store.
const SiDetectorElement * getDetectorElement(const IdentifierHash &hash) const
Class to hold geometrical description of a silicon detector element.
Trk::Surface & surface()
Element Surface.
Declare a monitored scalar variable.
A PRD is mapped onto all contributing particles.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
const_pointer_type retrieve()
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
Abstract Base Class for tracking surfaces.
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.
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
StripCluster_v1 StripCluster
Define the version of the strip cluster class.
PixelCluster_v1 PixelCluster
Define the version of the pixel cluster class.
UncalibMeasType
Define the type of the uncalibrated measurement.
hold the test vectors and ease the comparison
std::size_t size() const noexcept