13#include "Acts/Definitions/Units.hpp"
14#include "Acts/MagneticField/MagneticFieldContext.hpp"
50 ATH_MSG_DEBUG(
"Filling Histograms for " << name() <<
" ... " );
56 auto beamSpotData = beamSpotHandle.
cptr();
65 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
67 Acts::Vector2 beamPos( beamSpotData->beamPos()[
Amg::x ] * Acts::UnitConstants::mm,
68 beamSpotData->beamPos()[
Amg::y ] * Acts::UnitConstants::mm );
72 Acts::MagneticFieldProvider::Cache magFieldCache = magneticField.
makeCache( magFieldContext );
73 Acts::Vector3 bField = *magneticField.
getField( Acts::Vector3(beamPos.x(), beamPos.y(), 0),
90 [] (
const auto& seed) ->
double
91 {
return seed.sp()[0]->x(); });
94 [] (
const auto& seed) ->
double
95 {
return seed.sp()[0]->y(); });
98 [] (
const auto& seed) ->
double
99 {
return seed.sp()[0]->z(); });
102 [] (
const auto& seed) ->
double
104 const auto*
sp = seed.sp()[0];
105 return std::sqrt(
sp->x()*
sp->x() +
sp->y()*
sp->y());
111 [] (
const auto& seed) ->
double
112 {
return seed.sp()[1]->x(); });
115 [] (
const auto& seed) ->
double
116 {
return seed.sp()[1]->y(); });
119 [] (
const auto& seed) ->
double
120 {
return seed.sp()[1]->z(); });
123 [] (
const auto& seed) ->
double
125 const auto*
sp = seed.sp()[1];
126 return std::sqrt(
sp->x()*
sp->x() +
sp->y()*
sp->y());
132 [] (
const auto& seed) ->
double
133 {
return seed.sp()[2]->x(); });
136 [] (
const auto& seed) ->
double
137 {
return seed.sp()[2]->y(); });
140 [] (
const auto& seed) ->
double
141 {
return seed.sp()[2]->z(); });
144 [] (
const auto& seed) ->
double
146 const auto*
sp = seed.sp()[2];
147 return std::sqrt(
sp->x()*
sp->x() +
sp->y()*
sp->y());
150 std::vector< std::array<float, 7> > parametersCollection;
151 parametersCollection.reserve(seed_collection->size());
153 for (
auto seed : *seed_collection) {
158 [] (
const auto& params) ->
float
159 {
return params[0]; });
161 [] (
const auto& params) ->
float
162 {
return params[1]; });
164 [] (
const auto& params) ->
float
165 {
return params[2]; });
167 [] (
const auto& params) ->
float
168 {
return params[3]; });
171 [] (
const auto& params) ->
float
172 {
return params[4]; });
174 [] (
const auto& params) ->
float
175 {
return params[5]; });
179 [] (
const auto& params) ->
float
180 {
return params[6]; });
186 auto monitor_event_number =
Monitored::Scalar<long>(
"event_number",
static_cast<long>(eventInfo->eventNumber()));
189 std::vector<int> vec_truthBarcode;
190 std::vector<double> vec_truthProb;
197 monitor_x1, monitor_y1, monitor_z1, monitor_r1,
198 monitor_x2, monitor_y2, monitor_z2, monitor_r2,
199 monitor_x3, monitor_y3, monitor_z3, monitor_r3,
200 monitor_param_pt, monitor_param_theta, monitor_param_eta, monitor_param_d0,
201 monitor_param_dzdr_b, monitor_param_dzdr_t,
202 monitor_param_penalty,
203 monitor_event_number, monitor_actual_mu,
204 monitor_truth_barcode, monitor_truth_prob);
206 return StatusCode::SUCCESS;
211 std::vector<int>& truthBarCodeVec,
212 std::vector<double>& truthProbVec)
const
214 ATH_MSG_DEBUG(
"Filling Truth Histograms for " << name() <<
" ... " );
231 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
237 auto retrieveSurfaceFunction =
238 [
this, &detElements] (
const ActsTrk::Seed& seed,
bool useTopSp) ->
const Acts::Surface&
242 useTopSp ?
sp->elementIdList().back() :
sp->elementIdList().front());
249 std::vector<bool> vec_pass;
250 vec_pass.reserve(seed_container.size());
252 std::vector<double> estimated_pt;
253 std::vector<double> estimated_eta;
254 estimated_pt.reserve(seed_container.size());
255 estimated_eta.reserve(seed_container.size());
257 for (
auto seed : seed_container) {
258 std::optional<Acts::BoundTrackParameters> optTrackParams =
262 geo_context.context(),
264 retrieveSurfaceFunction);
266 if ( not optTrackParams.has_value() )
continue;
268 const auto param = optTrackParams.value();
269 estimated_pt.push_back( param.transverseMomentum() );
270 estimated_eta.push_back( -std::log( std::tan(0.5 * param.parameters()[Acts::eBoundTheta]) ) );
272 std::map<int, int> truthHits;
274 const auto& sps = seed.sp();
275 for (
const auto*
sp : sps) {
277 for (
int cluster_number(0); cluster_number < number_of_clusters; cluster_number++) {
278 const auto& els =
sp->measurements();
279 const auto* cluster = els[cluster_number];
289 truthBarCodeVec.push_back(barcode);
290 truthProbVec.push_back(prob);
291 vec_pass.push_back( barcode != 0 and prob > 0.5 );
300 monitor_estimated_pt, monitor_estimated_eta);
302 return StatusCode::SUCCESS;
315 return (*pixelLink)->identify();
328 return (*stripLink)->identify();
334 std::map<int, int>& countMap)
const {
335 auto n1 = prdTruth->count(
id);
338 auto nBC = countMap.count(bc);
345 using iprdt = PRD_MultiTruthCollection::const_iterator;
346 std::pair<iprdt, iprdt> range = prdTruth->equal_range(
id);
347 for (iprdt itr = range.first; itr != range.second; ++itr) {
348 auto bc = itr->second.barcode();
349 auto nBC = countMap.count(bc);
363 int bestBarcode = std::numeric_limits<int>::min();
365 for (
auto const& [barcode,
count] : countMap) {
366 if (
count > bestCount) {
368 bestBarcode = barcode;
374 double prob = bestCount / nTotal;
376 return std::make_pair(bestBarcode, prob);
381 float pTPerHelixRadius)
const
383 auto extractCoordinates =
386 std::array<float, 4> coordinates {
static_cast<float>(
sp->x()),
387 static_cast<float>(
sp->y()),
388 static_cast<float>(
sp->z()),
389 static_cast<float>(std::sqrt(
sp->x()*
sp->x() +
sp->y()*
sp->y()))};
393 auto extractQuantities =
394 [] (
const std::array<float, 4>&
sp,
395 const std::array<float, 4>& spM,
396 bool isBottom) -> std::array<float, 5>
398 auto& [xM, yM, zM, rM] = spM;
399 auto& [xO, yO, zO, rO] =
sp;
401 float cosPhiM = xM / rM;
402 float sinPhiM = yM / rM;
403 float deltaX = xO - xM;
404 float deltaY = yO - yM;
405 float deltaZ = zO - zM;
406 float x = deltaX * cosPhiM + deltaY * sinPhiM;
407 float y = deltaY * cosPhiM - deltaX * sinPhiM;
408 float iDeltaR2 = 1.f / (deltaX * deltaX + deltaY * deltaY);
409 float iDeltaR = std::sqrt(iDeltaR2);
411 float cot_theta = deltaZ * iDeltaR * bottomFactor;
414 std::array<float, 5> params =
426 const auto& sps = seed.sp();
427 const auto* bottom = sps[0];
428 const auto* medium = sps[1];
429 const auto*
top = sps[2];
431 auto coo_b = extractCoordinates(bottom);
432 auto coo_m = extractCoordinates(medium);
433 auto coo_t = extractCoordinates(
top);
436 auto [cotThetaB, Zob, iDeltaRB, Ub, Vb] = extractQuantities(coo_b, coo_m,
true);
437 auto [cotThetaT, Zot, iDeltaRT, Ut, Vt] = extractQuantities(coo_t, coo_m,
false);
439 float squarediDeltaR2B = iDeltaRB*iDeltaRB;
440 float squarediDeltaR2T = iDeltaRB*iDeltaRT;
441 float squarediDeltaR = std::min(squarediDeltaR2B, squarediDeltaR2T);
443 auto& [xB, yB, zB, rB] = coo_b;
444 auto& [xM, yM, zM, rM] = coo_m;
445 auto& [xT, yT, zT, rT] = coo_t;
453 float xb = dxb * ax + dyb *ay;
454 float yb = dyb * ax - dxb * ay;
455 float dxyb = xb * xb + yb * yb;
459 float xt = dxt * ax + dyt *ay;
460 float yt = dyt * ax - dxt * ay;
463 float tzb = dzb * std::sqrt( 1.f/dxyb );
464 float tzt = dzt * std::sqrt( 1.f/dxyt );
466 float sTzb2 = std::sqrt(1.f + tzb*tzb);
470 return {-1, -1, -1, -1, -1, -1, -1};
473 float A = (Vt - Vb) / dU;
474 float S2 = 1.f +
A *
A;
475 float B = Vb -
A * Ub;
477 if (B2 == 0) B2 = 1e-8;
480 float dzdr_b = (zM - zB) / (rM - rB);
481 float dzdr_t = (zT - zM) / (rT - rM);
484 float cotThetaAvg2 = cotThetaB * cotThetaT;
485 if (cotThetaAvg2 <= 0) {
486 return {-1, -1, -1, -1, -1, -1, -1};
488 float theta = std::atan(1.f / std::sqrt(cotThetaAvg2));
489 float eta = -std::log(std::tan(0.5f *
theta));
492 float pt = pTPerHelixRadius * std::sqrt(
S2 / B2) / 2.f;
495 float d0 = std::abs((
A - B * rM) * rM);
500 float penalty = std::abs((tzb - tzt) / (squarediDeltaR * sTzb2));
502 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::IActsToTrkConverterTool > m_ATLASConverterTool
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
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