22 m_incidentSvc(
"IncidentSvc",
n),
23 m_histSvc(
"THistSvc",
n),
24 m_materialAssociationType(1),
25 m_maxMappingEvents(100000),
27 m_totalMaterialTree(
"TotalMaterial"),
28 m_validationTree(nullptr),
29 m_validationTreeName(
"MaterialMapper"),
30 m_validationTreeDescription(
"Material Effects Updator information"),
31 m_validationTreeFolder(
"/val/MaterialMapper"),
33 m_averageEta{}, m_averagePhi{}, m_mappedPath{}, m_mappedPathInX0{},
34 m_mappedPathInL0{}, m_mappedPathRho{}, m_mappedPathZARho{},
36 m_volumeValidation(
true),
37 m_volumeTreePrefix(
"VolumeMaterial"),
38 m_layerValidation(
true),
39 m_layerTreePrefix(
"LayerMaterial_"),
40 m_surfaceValidation(
true),
41 m_surfaceTreePrefix(
"SurfaceMaterial_")
43 declareInterface<IMaterialMapper>(
this);
46 declareProperty(
"MaximumMappingEvents", m_maxMappingEvents);
48 declareProperty(
"ValidationTreeName", m_validationTreeName);
49 declareProperty(
"ValidationTreeDescription", m_validationTreeDescription);
50 declareProperty(
"ValidationTreeFolder", m_validationTreeFolder);
52 declareProperty(
"TotalMaterialTreeName", m_totalMaterialTree);
54 declareProperty(
"MaterialAssociationType", m_materialAssociationType);
56 declareProperty(
"TrackingVolumeValidation", m_volumeValidation);
57 declareProperty(
"TrackingVolumeTreePrefix", m_volumeTreePrefix);
59 declareProperty(
"DetailedLayerValidation", m_layerValidation);
60 declareProperty(
"DetailedLayerTreePrefix", m_layerTreePrefix);
62 declareProperty(
"DetailedSurfaceValidation", m_surfaceValidation);
63 declareProperty(
"DetailedSurfaceTreePrefix", m_surfaceTreePrefix);
71 if (m_volumeValidation) {
72 auto volTreeIter = m_volumeTrees.begin();
73 auto endVolTreeIter = m_volumeTrees.end();
74 for ( ; volTreeIter != endVolTreeIter;
delete (volTreeIter->second), ++volTreeIter) {}
77 if (m_layerValidation) {
79 auto layTreeIter = m_layerTrees.begin();
80 auto endLayTreeIter = m_layerTrees.end();
81 for ( ; layTreeIter != endLayTreeIter;
delete (layTreeIter->second), ++layTreeIter) {}
83 layTreeIter = m_layerFullTrees.begin();
84 endLayTreeIter = m_layerFullTrees.end();
85 for ( ; layTreeIter != endLayTreeIter;
delete (layTreeIter->second), ++layTreeIter) {}
88 if (m_surfaceValidation) {
90 auto surfTreeIter = m_surfaceTrees.begin();
91 auto endSurfTreeIter = m_surfaceTrees.end();
92 for ( ; surfTreeIter != endSurfTreeIter;
delete (surfTreeIter->second), ++surfTreeIter) {}
106 m_incidentSvc->addListener(
this, IncidentType::EndEvent);
109 bookValidationTree();
110 return StatusCode::SUCCESS;
117 return StatusCode::SUCCESS;
123 if (m_processedEvents >= m_maxMappingEvents)
return;
133 ATH_MSG_WARNING(
"Could not associate TrackingVolume to material step!");
148 if(amhit.
A() != 0.0) {
149 (*volTreeObj).pathZARho += (amhit.
Z()/amhit.
A())*amhit.
rho()*amhit.
steplength();
159 m_averageEta += position.eta();
160 m_averagePhi += position.phi();
165 m_mappedPath += steplength;
168 m_mappedPathRho += amhit.
rho()*steplength;
169 if(amhit.
A() != 0.0) {
170 m_mappedPathZARho += (amhit.
Z()/amhit.
A())*amhit.
rho()*steplength;
172 ATH_MSG_VERBOSE(
"[ MaterialMapper ] Accumulated Path in Rho (*Z/A) = " << m_mappedPathRho <<
" ( " << m_mappedPathZARho <<
" )");
179 m_materialAccumPathInX0[m_materialSteps] = m_mappedPathInX0;
180 m_materialAccumPathZARho[m_materialSteps] = m_mappedPathZARho;
181 m_materialStepPath[m_materialSteps] = steplength;
182 m_materialStepX0[m_materialSteps] = amhit.
x0();
183 m_materialStepL0[m_materialSteps] = amhit.
l0();
184 m_materialStepA[m_materialSteps] = amhit.
A();
185 m_materialStepZ[m_materialSteps] = amhit.
Z();
186 m_materialStepRho[m_materialSteps] = amhit.
rho();
187 m_materialStepPositionX[m_materialSteps] = position.x();
188 m_materialStepPositionY[m_materialSteps] = position.y();
189 m_materialStepPositionZ[m_materialSteps] = position.z();
190 m_materialStepPositionR[m_materialSteps] = position.perp();
192 m_materialProjPositionX[m_materialSteps] = projectedPosition.x();
193 m_materialProjPositionY[m_materialSteps] = projectedPosition.y();
194 m_materialProjPositionZ[m_materialSteps] = projectedPosition.z();
195 m_materialProjPositionR[m_materialSteps] = projectedPosition.perp();
196 m_materialProjDistance[m_materialSteps] = (position-projectedPosition).
mag();
202 if (m_layerValidation) recordLayerHit(amhit);
210 auto volTreeIter =
mapped ? m_volumeTrees.begin() : m_volumeTreesUnmapped.begin();
211 auto endVolTreeIter =
mapped ? m_volumeTrees.end() : m_volumeTreesUnmapped.end();
214 for ( ; volTreeIter != endVolTreeIter; ++volTreeIter ) {
218 if (!volTreeObj)
continue;
220 if ((*volTreeObj).path > 0.) {
222 (*volTreeObj).
eta = m_averageEta;
223 (*volTreeObj).phi = m_averagePhi;
225 (*volTreeObj).tree->Fill();
228 (*volTreeObj).eta = 0.;
229 (*volTreeObj).phi = 0.;
230 (*volTreeObj).path = 0.;
231 (*volTreeObj).pathInX0 = 0.;
232 (*volTreeObj).pathInL0 = 0.;
233 (*volTreeObj).pathZARho = 0.;
242 if (m_processedEvents >= m_maxMappingEvents)
return;
245 if (m_layerValidation && lay) {
259 double posR =
pos.perp();
260 double posEta =
pos.eta();
263 (*layTreeObj).hitPositionX[(*layTreeObj).layerHits] =
posX;
264 (*layTreeObj).hitPositionY[(*layTreeObj).layerHits] =
posY;
265 (*layTreeObj).hitPositionZ[(*layTreeObj).layerHits] =
posZ;
266 (*layTreeObj).hitPositionR[(*layTreeObj).layerHits] = posR;
267 (*layTreeObj).hitPositionEta[(*layTreeObj).layerHits] = posEta;
270 ++(*layTreeObj).layerHits;
271 ++(*layTreeObj).densedHits;
274 (*layTreeObj).densedHitX +=
posX;
275 (*layTreeObj).densedHitY +=
posY;
276 (*layTreeObj).densedHitZ +=
posZ;
277 (*layTreeObj).densedHitR += posR;
278 (*layTreeObj).densedHitPhi +=
pos.phi();
279 (*layTreeObj).densedHitTheta +=
pos.theta();
299 for (
size_t iltm = 0; iltm < 2; ++iltm) {
301 auto layObjIter = iltm ? m_layerFullTrees.begin() : m_layerTrees.begin();
302 auto endIter = iltm ? m_layerFullTrees.end() : m_layerTrees.end();
304 for ( ; layObjIter != endIter; ++layObjIter ) {
308 if (!layTreeObj)
continue;
311 int hits = (*layTreeObj).densedHits;
313 if ((*layTreeObj).pathInX0 > 0.) {
315 (*layTreeObj).densedHitX /=
hits;
316 (*layTreeObj).densedHitY /=
hits;
317 (*layTreeObj).densedHitZ /=
hits;
318 (*layTreeObj).densedHitR /=
hits;
319 (*layTreeObj).densedHitPhi /=
hits;
320 (*layTreeObj).densedHitTheta /=
hits;
321 (*layTreeObj).correctionFactor /=
hits;
322 (*layTreeObj).A /= (*layTreeObj).rho;
323 (*layTreeObj).Z /= (*layTreeObj).rho;
324 (*layTreeObj).rho /= (*layTreeObj).path;
327 (*layTreeObj).tree->Fill();
330 (*layTreeObj).layerHits = 0;
331 (*layTreeObj).path = 0.;
332 (*layTreeObj).pathInX0 = 0.;
333 (*layTreeObj).pathInL0 = 0.;
334 (*layTreeObj).densedHits = 0;
335 (*layTreeObj).densedHitX = 0.;
336 (*layTreeObj).densedHitY = 0.;
337 (*layTreeObj).densedHitZ = 0.;
338 (*layTreeObj).densedHitR = 0.;
339 (*layTreeObj).densedHitPhi = 0.;
340 (*layTreeObj).densedHitTheta = 0.;
341 (*layTreeObj).correctionFactor = 0.;
342 (*layTreeObj).A = 0.;
343 (*layTreeObj).Z = 0.;
344 (*layTreeObj).rho = 0.;
354 if (m_processedEvents >= m_maxMappingEvents)
return;
357 if (m_surfaceValidation && lay) {
363 (*surfTreeObj).loc1 += locpos[0];
364 (*surfTreeObj).loc2 += locpos[1];
374 ++(*surfTreeObj).surfaceHits;
387 auto surfObjIter = m_surfaceTrees.begin();
388 auto endIter = m_surfaceTrees.end();
390 for ( ; surfObjIter != endIter; ++surfObjIter ) {
393 int hits = (*surfTreeObj).surfaceHits;
395 if ((*surfTreeObj).pathInX0 > 0.) {
397 (*surfTreeObj).loc1 /=
hits;
398 (*surfTreeObj).loc2 /=
hits;
399 (*surfTreeObj).eta /=
hits;
400 (*surfTreeObj).correctionFactor /=
hits;
401 (*surfTreeObj).A /=
hits;
402 (*surfTreeObj).Z /=
hits;
403 (*surfTreeObj).rho /=
hits;
406 (*surfTreeObj).tree->Fill();
409 (*surfTreeObj).loc1 = 0.;
410 (*surfTreeObj).loc2 = 0.;
411 (*surfTreeObj).eta = 0.;
413 (*surfTreeObj).correctionFactor = 0.;
414 (*surfTreeObj).path = 0.;
415 (*surfTreeObj).pathInX0 = 0.;
416 (*surfTreeObj).pathInL0 = 0.;
417 (*surfTreeObj).rho = 0.;
419 (*surfTreeObj).surfaceHits = 0;
428 auto endIter = lay ? m_volumeTrees.end() : m_volumeTreesUnmapped.end();
429 auto findIter = lay ? m_volumeTrees.end() : m_volumeTreesUnmapped.end();
433 findIter = lay ? m_volumeTrees.find(tvol) : m_volumeTreesUnmapped.find(tvol);
435 if (findIter == endIter) {
438 tvolName.ReplaceAll(
"::",
"_");
445 TString treeTitle =
"TrackingVolume : ";
446 treeTitle += tvolName;
447 if (!lay) treeTitle +=
" - UNMAPPED";
449 TString treeRegName =
"/val/";
453 ATH_MSG_INFO(
" -> Booking it now with register name : " << treeRegName.Data() );
457 m_volumeTrees.insert(std::make_pair(tvol,tvolTreeObj));
459 m_volumeTreesUnmapped.insert(std::make_pair(tvol,tvolTreeObj));
462 if (m_histSvc->regTree(treeRegName.Data(), (*tvolTreeObj).tree).isFailure()) {
463 ATH_MSG_ERROR(
"initialize() Could not register the validation Tree -> Switching Tree output for this volume off !" );
464 delete tvolTreeObj; tvolTreeObj =
nullptr;
468 tvolTreeObj = findIter->second;
483 auto it = m_layerFullTrees.find(&lay);
484 if (
it != m_layerFullTrees.end()) {
489 auto it = m_layerTrees.find(&lay);
490 if (
it != m_layerTrees.end()) {
499 ATH_MSG_INFO(
"MaterialLayer from BoundarySurface detected.");
502 TString tvolName = (enclosingVolume) ? enclosingVolume->
volumeName() :
"BoundaryLayers";
503 tvolName.ReplaceAll(
"::",
"_");
510 "CylinderLayer_" :
"DiscLayer_";
513 if (mLayer)
treeName +=
"boundary_";
516 TString treeTitle =
"TrackingVolume :";
517 treeTitle += tvolName;
519 TString treeRegName =
"/val/";
523 ATH_MSG_INFO(
" -> Booking it now with register name : " << treeRegName.Data() );
526 if (
full) m_layerFullTrees.insert(std::make_pair(&lay,layTreeObj));
527 else m_layerTrees.insert(std::make_pair(&lay,layTreeObj));
530 if (m_histSvc->regTree(treeRegName.Data(), (*layTreeObj).tree).isFailure()) {
531 ATH_MSG_ERROR(
"initialize() Could not register the validation Tree -> Switching Tree output for this layer off !" );
532 delete layTreeObj; layTreeObj =
nullptr;
544 auto endIter = m_surfaceTrees.end();
545 auto findIter = m_surfaceTrees.end();
549 findIter = m_surfaceTrees.find(&lay);
550 if (findIter == endIter) {
553 TString volumeName = (enclosingVolume) ? enclosingVolume->
volumeName() :
"Unknown";
555 TString
treeName = m_surfaceTreePrefix;
558 TString treeTitle =
"TrackingVolume :";
559 treeTitle += volumeName;
561 TString treeRegName =
"/val/";
565 <<
" in Volume '" << volumeName <<
"'." );
566 ATH_MSG_INFO(
" -> Booking it now with register name : " << treeRegName.Data() );
569 m_surfaceTrees.insert(std::make_pair(&lay,surfTreeObj));
572 if (m_histSvc->regTree(treeRegName.Data(), (*surfTreeObj).tree).isFailure()) {
573 ATH_MSG_INFO(
"initialize() Could not register the validation Tree -> Switching Tree output for this surface off !" );
574 delete surfTreeObj; surfTreeObj =
nullptr;
578 surfTreeObj = findIter->second;
585 if ( inc.type() == IncidentType::EndEvent && m_materialSteps){
589 m_averageEta /= m_materialSteps;
590 m_averagePhi /= m_materialSteps;
592 finalizeVolumeHits(
true);
593 finalizeVolumeHits(
false);
597 finalizeSurfaceHits();
599 m_validationTree->Fill();
606 m_mappedPathInX0 = 0.;
607 m_mappedPathInL0 = 0.;
608 m_mappedPathRho = 0.;
609 m_mappedPathZARho = 0.;
623 m_validationTree =
new TTree(m_validationTreeName.c_str(), m_validationTreeDescription.c_str());
626 m_validationTree->Branch(
"Eta", &m_averageEta,
"averageEta/F");
627 m_validationTree->Branch(
"Phi", &m_averagePhi,
"averagePhiF");
628 m_validationTree->Branch(
"Path", &m_mappedPath,
"path/F");
629 m_validationTree->Branch(
"PathInX0", &m_mappedPathInX0,
"pathInX0/F");
630 m_validationTree->Branch(
"PathInL0", &m_mappedPathInL0,
"pathInL0/F");
631 m_validationTree->Branch(
"PathRho", &m_mappedPathRho,
"pathRho/F");
632 m_validationTree->Branch(
"PathZARho", &m_mappedPathZARho,
"pathZARho/F");
633 m_validationTree->Branch(
"UnmappedPathInX0", &m_unmappedPathInX0,
"unmappedPathInX0/F");
634 m_validationTree->Branch(
"MaterialSteps", &m_materialSteps,
"steps/I");
635 m_validationTree->Branch(
"Mapped", m_mapped,
"mapped[steps]/I");
636 m_validationTree->Branch(
"MaterialAccumPathInX0", m_materialAccumPathInX0,
"materialAccumPinX0[steps]/F");
637 m_validationTree->Branch(
"MaterialAccumPathZARho", m_materialAccumPathZARho,
"materialAccumPZARho[steps]/F");
638 m_validationTree->Branch(
"MaterialStepPath", m_materialStepPath,
"materialStepPath[steps]/F");
639 m_validationTree->Branch(
"MaterialStepX0", m_materialStepX0,
"materialStepX0[steps]/F");
640 m_validationTree->Branch(
"MaterialStepL0", m_materialStepL0,
"materialStepL0[steps]/F");
641 m_validationTree->Branch(
"MaterialStepZ", m_materialStepZ,
"materialStepZ[steps]/F");
642 m_validationTree->Branch(
"MaterialStepA", m_materialStepA,
"materialStepA[steps]/F");
643 m_validationTree->Branch(
"MaterialStepRho", m_materialStepRho,
"materialStepRho[steps]/F");
644 m_validationTree->Branch(
"MaterialStepPositionX", m_materialStepPositionX ,
"materialStepX[steps]/F");
645 m_validationTree->Branch(
"MaterialStepPositionY", m_materialStepPositionY ,
"materialStepY[steps]/F");
646 m_validationTree->Branch(
"MaterialStepPositionZ", m_materialStepPositionZ ,
"materialStepZ[steps]/F");
647 m_validationTree->Branch(
"MaterialStepPositionR", m_materialStepPositionR ,
"materialStepR[steps]/F");
648 m_validationTree->Branch(
"MaterialProjPositionX", m_materialProjPositionX ,
"materialProjX[steps]/F");
649 m_validationTree->Branch(
"MaterialProjPositionY", m_materialProjPositionY ,
"materialProjY[steps]/F");
650 m_validationTree->Branch(
"MaterialProjPositionZ", m_materialProjPositionZ ,
"materialProjZ[steps]/F");
651 m_validationTree->Branch(
"MaterialProjPositionR", m_materialProjPositionR ,
"materialProjR[steps]/F");
652 m_validationTree->Branch(
"MaterialProjDistance", m_materialProjDistance ,
"materialProjD[steps]/F");
655 if (m_histSvc->regTree(m_validationTreeFolder.c_str(), m_validationTree).isFailure()) {
656 ATH_MSG_ERROR(
"initialize() Could not register the validation Tree -> Switching ValidationMode Off !" );
657 delete m_validationTree; m_validationTree =
nullptr;