21 #include "GaudiKernel/SystemOfUnits.h"
29 m_extrapolator(
"Trk::Extrapolator/AtlasExtrapolator"),
30 m_extraprec(
"Trk::Extrapolator/MuonExtrapolator"),
46 m_checkStepWise(false),
47 m_printMaterial(false),
49 m_matTotFile(
"material.txt"),
50 m_matScanFile(
"material_scan.txt"),
51 m_matActiveFile(
"mat_active.txt"),
52 m_matCompFile(
"material_comp.txt"),
62 m_outerBoundary(nullptr),
63 m_trackingGeometry(nullptr),
66 m_chronoStatSvc(
"ChronoStatSvc",
name )
117 if (m_extrapolator.retrieve().isFailure()) {
118 ATH_MSG_FATAL(
"Could not retrieve Tool " << m_extrapolator <<
". Exiting." );
119 return StatusCode::FAILURE;
121 if (m_extraprec.retrieve().isFailure()) {
122 ATH_MSG_FATAL(
"Could not retrieve Tool " << m_extraprec <<
". Exiting." );
123 return StatusCode::FAILURE;
130 m_gaussDist =
new Rndm::Numbers(randSvc(), Rndm::Gauss(0.,1.));
131 m_flatDist =
new Rndm::Numbers(randSvc(), Rndm::Flat(0.,1.));
134 return StatusCode::SUCCESS;
143 if (m_chronoStatSvc) m_chronoStatSvc->chronoPrint(
"MS::scan");
145 return StatusCode::SUCCESS;
153 const EventContext& ctx = Gaudi::Hive::currentContext();
155 if (!m_outerBoundary) {
156 m_trackingGeometry = m_extrapolator->trackingGeometry();
157 m_outerBoundary = &(m_trackingGeometry->highestTrackingVolume()->boundarySurfaces()[2]->surfaceRepresentation());
158 if (!m_outerBoundary) {
159 ATH_MSG_FATAL(
"Could not retrieve cylinder boundary from " << m_extrapolator <<
". Exiting." );
160 return StatusCode::FAILURE;
176 if (m_chronoStatSvc) m_chronoStatSvc->chronoStart(
"MS::scan");
179 std::vector<const TrackStateOnSurface*> material;
180 std::vector<const TrackStateOnSurface*> matPrec;
182 for (
unsigned int it = 0;
it < m_numScan+1;
it++) {
184 double z0 = m_minZ0 + (m_maxZ0-m_minZ0)/m_numScan *
it;
187 double theta = m_minTheta + (m_maxTheta-m_minTheta)/m_numScan*
it;
188 double p = m_minP + (m_maxP-m_minP)/m_numScan *
it;
194 material.clear(); matPrec.clear();
199 m_msentry = m_trackingGeometry->trackingVolume(
"Calo::Containers::Calorimeter");
203 m_extrapolator->extrapolateToVolume(
217 const std::vector<const Trk::TrackStateOnSurface*>* mmsentry = m_extrapolator->extrapolateM(ctx,
224 for (
unsigned int i=0;
i< mmsentry->size();
i++)
226 ATH_MSG_DEBUG(
"position:eloss:" <<
i <<
"," << (*mmsentry)[
i]->trackParameters()->position() <<
":"
228 currPar = (mmsentry->back()) ? mmsentry->back()->trackParameters() : msEntry;
230 const std::vector<const Trk::TrackStateOnSurface*>* peri = m_extrapolator->extrapolateM(ctx,
240 ATH_MSG_ERROR (
"Perigee pointer is null in CETmaterial.cxx");
242 return StatusCode::FAILURE;
244 for (
unsigned int i=0;
i< peri->size();
i++)
245 if ((*peri)[
i] && (*peri)[
i]->trackParameters())
246 ATH_MSG_DEBUG(
"position:eloss:" <<
i <<
"," << (*peri)[
i]->trackParameters()->position() <<
":"
249 if (peri->back() && peri->back()->trackParameters()) {
251 << initialPerigee.parameters()[0] <<
","
252 << initialPerigee.parameters()[1] <<
","
253 << initialPerigee.parameters()[2] <<
","
254 << initialPerigee.parameters()[3] <<
","
255 << initialPerigee.momentum().mag() );
257 << peri->back()->trackParameters()->parameters()[0] <<
","
258 << peri->back()->trackParameters()->parameters()[1] <<
","
259 << peri->back()->trackParameters()->parameters()[2] <<
","
260 << peri->back()->trackParameters()->parameters()[3] <<
","
261 << peri->back()->trackParameters()->momentum().mag() );
263 ATH_MSG_ERROR(
"extrapolation to perigee failed for input parameters: " << msEntry->parameters() );
268 ATH_MSG_ERROR(
"extrapolation to MSentry failed for input parameters: " << currPar->parameters() );
276 if (m_checkStepWise) {
279 std::pair<std::unique_ptr<Trk::TrackParameters>,
const Trk::Layer*>
next = m_extrapolator->extrapolateToNextActiveLayerM(
292 if (m_doprecision && precPar && currPar ) {
294 const std::vector<const Trk::TrackStateOnSurface*>* nextPrec = m_extraprec->extrapolateM(
303 for (
const auto *
i : *nextPrec) {
312 if (!lay || !nextPrec || nextPrec->empty() || !nextPrec->back() )
break;
313 precPar = nextPrec->back()->trackParameters();
315 if (!material.empty())
for (
auto &
i : material) {
316 if (
i->materialEffectsOnTrack())
mat +=
i->materialEffectsOnTrack()->thicknessInX0();
319 currPar->parameters()[1]-precPar->parameters()[1]);
325 if (nextPar && m_printActive) {
329 if (!material.empty())
for (
auto &
i : material) {
330 if (
i->materialEffectsOnTrack()) matc +=
i->materialEffectsOnTrack()->thicknessInX0();
336 printMatPrec(
theta,
phi,nextPar,nextPar,matc,
id,
"unknown");
340 if (m_printMaterial) {
342 if (!material.empty())
for (
auto &
i : material) {
343 if (
i->materialEffectsOnTrack()) {
344 mat +=
i->materialEffectsOnTrack()->thicknessInX0();
350 const std::vector<const Trk::TrackStateOnSurface*>* destParameters = m_extrapolator->extrapolateM(
358 if (m_printMaterial) {
360 if (destParameters)
for (
const auto *destParameter : *destParameters) {
371 std::vector<const Trk::DetachedTrackingVolume*> detVols = m_extrapolator->trackingGeometry()->lowestDetachedTrackingVolumes(trPar->
position());
376 if (destParameters) {
384 if (!destParameters || destParameters->empty() ) {
385 ATH_MSG_ERROR(
"extrapolation to outer boundary failed for input parameters: " << initialPerigee.parameters() );
386 }
else if (destParameters->back()->trackParameters()) {
392 const std::vector<const Trk::TrackStateOnSurface*>* peri = m_extrapolator->extrapolateM(
393 ctx, *(destParameters->back()->trackParameters()),
401 for (
unsigned int i=0;
i< peri->size();
i++)
402 ATH_MSG_INFO(
"position:" <<
i <<
"," << (*peri)[
i]->trackParameters()->position() );
403 ATH_MSG_INFO(
"extrapolation to perigee:input: " << initialPerigee.parameters() );
404 ATH_MSG_INFO(
"extrapolation to perigee:output: " << peri->back()->trackParameters()->parameters() );
406 ATH_MSG_ERROR(
"extrapolation to perigee failed for input parameters: " << destParameters->back()->trackParameters()->parameters() );
412 delete destParameters;
416 if (m_chronoStatSvc) m_chronoStatSvc->chronoStop(
"MS::scan");
418 return StatusCode::SUCCESS;
425 std::ofstream myfilemat;
426 myfilemat.open (m_matTotFile,std::ios::app);
427 myfilemat<<
theta<<
" "<<
phi<<
" "<<
mat<<
" "<<dtheta<<
" "<<dphi<<std::endl;
433 std::ofstream myfilemat;
434 myfilemat.open(m_matScanFile,std::ios::app);
435 myfilemat <<
theta <<
" " <<
phi <<
" " <<
r <<
" " <<
z <<
" " <<
mat <<
" " <<
name << std::endl;
440 if (
name.empty()) {};
441 std::ofstream myfilemat;
442 myfilemat.open(m_matActiveFile,std::ios::app);
444 if (!m_th && !m_ph) {
449 delete m_next; m_next=nextPar->
clone();
454 *m_err = mdest->covariance()->inverse().eval();
461 if (m_err && m_id>0) {
462 myfilemat << m_th <<
" " << m_ph <<
" " << 1 <<
" " << m_id <<
" " << m_matSaved << std::endl;
463 myfilemat << m_next->parameters()[
Trk::locX] <<
" " << m_next->parameters()[
Trk::locY] <<
" " << m_next->parameters()[
Trk::phi]
469 myfilemat << m_th <<
" " << m_ph <<
" " << 0 <<
" " << m_id << std::endl;
470 myfilemat << m_next->parameters()[
Trk::locX] <<
" " << m_next->parameters()[
Trk::locY] <<
" " << m_next->parameters()[
Trk::phi]
477 delete m_next; m_next=nextPar->
clone();
483 *m_err = mdest->covariance()->inverse().eval();
494 delete m_next; m_next=nextPar->
clone();
499 *m_err = mdest->covariance()->inverse().eval();
506 std::ofstream myfilemat;
507 myfilemat.open(m_matCompFile,std::ios::app);
509 <<
" " <<
mat <<
" " << matApp <<
" " <<
dx <<
" " <<
dy << std::endl;