DummyMaterialEffectsUpdator.cxx 10.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

///////////////////////////////////////////////////////////////////
// DummyMaterialEffectsUpdator.cxx, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////

// Trk include
#include "TrkExTools/DummyMaterialEffectsUpdator.h"
#include "TrkExInterfaces/IEnergyLossUpdator.h"
#include "TrkExInterfaces/IMultipleScatteringUpdator.h"
#include "TrkParameters/TrackParameters.h"
#include "TrkEventPrimitives/ParamDefs.h"
#include "TrkSurfaces/Surface.h"
#include "TrkGeometry/Layer.h"
#include "TrkGeometry/MaterialProperties.h"
#include "TrkGeometry/AssociatedMaterial.h"
#include "TrkGeometry/TrackingVolume.h"
#include "TrkDetDescrInterfaces/IMaterialMapper.h"

// constructor
Trk::DummyMaterialEffectsUpdator::DummyMaterialEffectsUpdator(const std::string& t, const std::string& n, const IInterface* p) :
  AthAlgTool(t,n,p),
  m_considerPrePostMapping(true),
  m_validationMode(false),
  m_validationDirectionSwitch(1),
  m_validationDirection(Trk::alongMomentum),
  m_materialMapper("Trk::MaterialMapper"),
  m_etaFinalize(0.),
  m_phiFinalize(0.)

{
      declareInterface<IMaterialEffectsUpdator>(this);
      declareProperty("ValidationMode"                   , m_validationMode);
      declareProperty("ValidationDirection"              , m_validationDirectionSwitch);
      declareProperty("ValidationMaterialMapper"         , m_materialMapper);

}

// destructor
Trk::DummyMaterialEffectsUpdator::~DummyMaterialEffectsUpdator()
{}

// Athena standard methods
// initialize
StatusCode Trk::DummyMaterialEffectsUpdator::initialize()
{

    if ( m_materialMapper.retrieve().isFailure() ) {
      ATH_MSG_FATAL( "Failed to retrieve tool " << m_materialMapper );
      return StatusCode::FAILURE;
    } else 
      ATH_MSG_INFO( "Retrieved tool " << m_materialMapper );
 
    // set the validation switch
    m_validationDirection = (m_validationDirectionSwitch == 1 ) ? Trk::alongMomentum : Trk::oppositeMomentum; 

    ATH_MSG_INFO( "initialize() successful" );
    return StatusCode::SUCCESS;
}

// finalize
StatusCode Trk::DummyMaterialEffectsUpdator::finalize()
{
    ATH_MSG_INFO( "finalize() successful" );
    return StatusCode::SUCCESS;
}



const Trk::TrackParameters*  Trk::DummyMaterialEffectsUpdator::update(const TrackParameters* parm,
                                                                      const Layer& lay,
                                                                      PropDirection,
                                                                      ParticleHypothesis,
                                                                      MaterialUpdateMode) const
{
    if (m_validationMode && parm) {
      // get the numbers according
      const Trk::TrackingVolume* tvol = lay.enclosingTrackingVolume();
      const Trk::MaterialProperties* mprop = lay.fullUpdateMaterialProperties(*parm);

      const Trk::MaterialProperties* updateProperties 
            = dynamic_cast<const Trk::MaterialProperties*>(mprop);

      if (tvol && updateProperties){

88
	   double correctionFactor = fabs(lay.surfaceRepresentation().pathCorrection(parm->position(),parm->momentum()));
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
           // material properties
           double pathInX0         = updateProperties->thicknessInX0();
           double x0               = updateProperties->x0();
           double l0               = updateProperties->l0();
           double A                = updateProperties->averageA();
           double Z                = updateProperties->averageZ();
           double rho              = updateProperties->averageRho();
           // correct
           pathInX0 *= fabs(correctionFactor);
           // record
           m_etaFinalize = parm->eta();
           m_phiFinalize = parm->parameters()[Trk::phi];
           // create the extended material step
           Trk::AssociatedMaterial assMatHit(parm->position(),
                                                pathInX0,
                                                x0, l0, A, Z, rho,
                                                correctionFactor,
                                                lay.enclosingTrackingVolume(),
                                                &lay);

          // record it
          m_materialMapper->recordMaterialHit(assMatHit,parm->momentum());

       }
       else {
           ATH_MSG_WARNING( "update() ... dynamic cast to MaterialProperties failed!" );
       }
   }
   return parm;
}

const Trk::TrackParameters*  Trk::DummyMaterialEffectsUpdator::preUpdate(const TrackParameters* parm,
                                                                         const Layer& lay,
                                                                         PropDirection dir,
                                                                         ParticleHypothesis,
                                                                         MaterialUpdateMode) const
{
   if (m_validationMode && dir == m_validationDirection && parm){
      // get the numbers according 
      const Trk::TrackingVolume* tvol = lay.enclosingTrackingVolume();
      // the preFactor
      double preFactor = lay.preUpdateMaterialFactor(*parm, dir);
      // retrun if the preFactor is too small
      if (preFactor < 0.1) return (parm);

134
      double correctionFactor = fabs(lay.surfaceRepresentation().pathCorrection(parm->position(),parm->momentum()));
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
      bool  surfaceValidaiton = false;
      
      // get the material properties
      const Trk::MaterialProperties* updateProperties = lay.fullUpdateMaterialProperties(*parm);
      
      correctionFactor *= preFactor;

      if (tvol && updateProperties){
           // material properties
           double pathInX0         = updateProperties->thicknessInX0();
           double x0               = updateProperties->x0();
           double l0               = updateProperties->l0();
           double A                = updateProperties->averageA();
           double Z                = updateProperties->averageZ();
           double rho              = updateProperties->averageRho();
           // record
           m_etaFinalize = parm->eta();
           m_phiFinalize = parm->parameters()[Trk::phi];
           // correct
           pathInX0 *= fabs(correctionFactor)*preFactor;
           // create the extended material step
           Trk::AssociatedMaterial assMatHit(parm->position(),
                                                pathInX0,
                                                x0, l0, A, Z, rho,
                                                correctionFactor,
                                                lay.enclosingTrackingVolume(),
                                                &lay);
          // record it
          m_materialMapper->recordMaterialHit(assMatHit,parm->momentum());
          // and if it was a reference material : the SurfaceValidation
          if (surfaceValidaiton)  
              m_materialMapper->recordSurfaceHit(parm->localPosition(),assMatHit);
      }
      else {
          ATH_MSG_WARNING( "preUpdate() ... dynamic cast to MaterialProperties failed!" );
      }
   }
   return parm;
}


const Trk::TrackParameters*  Trk::DummyMaterialEffectsUpdator::postUpdate(const TrackParameters& parm,
                                                                          const Layer& lay,
                                                                          PropDirection dir,
                                                                          ParticleHypothesis,
                                                                          MaterialUpdateMode) const
{
   if (m_validationMode && dir == m_validationDirection){
      const Trk::TrackingVolume* tvol = lay.enclosingTrackingVolume();

      // get the quantities
      double postFactor = lay.postUpdateMaterialFactor( parm, dir);

      if (postFactor < 0.1 ) return 0;

      // the correction Factor to the layer
191
      double correctionFactor = fabs(lay.surfaceRepresentation().pathCorrection(parm.position(),parm.momentum()));
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
      // get the material properties
      const Trk::MaterialProperties* updateProperties = lay.fullUpdateMaterialProperties(parm);
      correctionFactor *= postFactor;

      if (tvol && updateProperties){

           // material properties
           double pathInX0         = updateProperties->thicknessInX0();
           double x0               = updateProperties->x0();
           double l0               = updateProperties->l0();
           double A                = updateProperties->averageA();
           double Z                = updateProperties->averageZ();
           double rho              = updateProperties->averageRho();
           // record
           m_etaFinalize = parm.eta();
           m_phiFinalize = parm.parameters()[Trk::phi];
           // correct
           pathInX0 *= fabs(correctionFactor);
           // create the extended material step
           Trk::AssociatedMaterial assMatHit(parm.position(),
                                                pathInX0,
                                                x0, l0, A, Z, rho,
                                                correctionFactor,
                                                lay.enclosingTrackingVolume(),
                                                &lay);
          // record it
          m_materialMapper->recordMaterialHit(assMatHit,parm.momentum());

      }
      else {
          ATH_MSG_WARNING( "postUpdate() ... dynamic cast to MaterialProperties failed!" );
      }
   }
   return (parm.clone());
}


// actual update method
const Trk::TrackParameters*  Trk::DummyMaterialEffectsUpdator::update(const TrackParameters& parm,
                                                                      const MaterialProperties&,
                                                                      double,
                                                                      PropDirection,
                                                                      ParticleHypothesis,
                                                                      MaterialUpdateMode) const
{
    return (parm.clone());
}


void Trk::DummyMaterialEffectsUpdator::validationAction() const
{
    // first record the values
244
245
  // if (m_validationMode && m_materialMapper)
  //      m_materialMapper->finalizeEvent(m_etaFinalize, m_phiFinalize);
246
}