ATLAS Offline Software
RtCalibrationCurved.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MuonCalib_RtCalibrationCurvedH
6 #define MuonCalib_RtCalibrationCurvedH
7 
14 
15 #include <list>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 // CLHEP //
21 #include "CLHEP/Matrix/SymMatrix.h"
22 #include "CLHEP/Matrix/Vector.h"
23 
24 // ROOT //
25 #include "TFile.h"
26 #include "TH1F.h"
27 #include "TH2F.h"
28 
29 // MuonCalib //
32 
33 namespace MuonCalib {
34 
35  class IMdtCalibrationOutput;
36  class IRtRelation;
37  class RtRelationLookUp;
38  class RtCalibrationOutput;
39  class CurvedPatRec;
40  class MuonCalibSegment;
41  class BaseFunction;
42  class CurvedLine;
43  class MultilayerRtDifference;
44 
46  public:
47  // Constructors //
48  RtCalibrationCurved(const std::string &name);
59 
60  RtCalibrationCurved(const std::string &name, const double rt_accuracy, const unsigned int &func_type, const unsigned int &ord,
61  const bool &fix_min, const bool &fix_max, const int &max_it, bool do_parabolic_extrapolation = false,
62  bool do_smoothing = false, bool do_multilayer_rt_scale = false);
79 
80  // Destructor //
83 
84  // Methods //
85  // get-methods //
86  double reliability() const;
92  double estimatedRtAccuracy() const;
100  int numberOfSegments() const;
103  int numberOfSegmentsUsed() const;
106  int iteration() const;
109  bool smoothing() const;
115 
116  // set-method //
117  void setEstimateRtAccuracy(const double acc);
119  void fullMatrix(const bool &yes_or_no);
128  void switch_on_control_histograms(const std::string &file_name);
137  void forceMonotony();
140  void doNotForceMonotony();
148  void doSmoothing();
153  void noSmoothing();
156 
157  // methods required by the base class "IMdtCalibration" //
158  MdtCalibOutputPtr analyseSegments(const MuonSegVec &seg) override;
163  bool handleSegment(MuonCalibSegment &seg);
167  void setInput(const IMdtCalibrationOutput *rt_input) override;
171  bool analyse(const MuonSegVec &seg);
174  bool converged() const;
177  virtual MdtCalibOutputPtr getResults() const override;
179 
180  private:
181  // options //
182  bool m_control_histograms = false; // = true, if control histograms should be
183  // produces
184  bool m_fix_min = false; // = true: fix r(t_min)
185  bool m_fix_max = false; // = true: fix r(t_max)
186  int m_max_it = 0; // maximum number of iterations
187  bool m_force_monotony = false; // = true if r(t) is forced to monotonically
188  // increasing, false otherwise
189  bool m_do_multilayer_rt_scale = false; // determine multilayer rt scaling
190 
191  // bookkeeping //
192  int m_nb_segments = 0; // number of segments passed to the algorithm
193  int m_nb_segments_used = 0; // number of segments used by the algorithm
194  int m_iteration = 0; // current iteration
195  std::array<bool, 2> m_multilayer{}; // m_multilayer[k] = true, if there was a segment
196  // extending to multilayer k+1
197 
198  // r-t quality //
199  int m_status = 0; // m_status: 0: no covergence yet,
200  // 1: convergence, r-t is reliable,
201  // 2: convergence, r-t is unreliable
202  double m_rt_accuracy = 0.0; // r-t accuracy (CLHEP::mm) of the input r-t
203  double m_rt_accuracy_previous; // r-t accuracy of the previous iteration
204  // (used in the convergence criterion)
205  double m_chi2_previous = 0.0;
206  // average chi^2 per degrees of freedom from the
207  // previous iteration (set to a large initial value
208  // to force at least two iterations);
209  // if an iteration gives a larger average than the
210  // pervious iteration, the algorithm has converged
211  double m_chi2 = 0.0; // average chi^2 per degrees of freedom,
212  // if an iteration gives a larger average than the
213  // pervious iteration, the algorithm has converged
214 
215  // r-t relationship //
216  std::shared_ptr<const IRtRelation> m_rt; // pointer to the input r-t relationship
217  double m_t_length = 0.0; // size of the drift time interval
218  double m_t_mean = 0.0; // mean value of the drift time interval
219 
220  // r-t output //
221  std::shared_ptr<IRtRelation> m_rt_new; // r-t as determined by the autocalibration
222  std::shared_ptr<RtCalibrationOutput> m_output; // class holding the results of the
223  // autocalibration
224  std::unique_ptr<MultilayerRtDifference> m_multilayer_rt_difference;
225  // curved-segment fitting //
226  double m_r_max = 0.0; // maximum value for accepted drift radii
227  std::unique_ptr<CurvedPatRec> m_tracker; // curved segment finder (used for track fitting)
228  // The following three objects are needed for autocalibration formulae.
229 
230  CLHEP::HepSymMatrix m_M_track; // segment parameters = m_M_track^-1*m_b_track
231  CLHEP::HepSymMatrix m_M_track_inverse; // inverse of m_M_track
232 
233  // autocalibration objects //
234  bool m_do_parabolic_extrapolation = false; // = true: parabolic extrapolation is
235  // done for small and large radii
236  // = false: no parabolic extrapolation is
237  // done
238  bool m_do_smoothing = false; // = true: the r-t relationship is smoothened after
239  // convergence, no smoothing is done
240  // otherwise
241  unsigned int m_order = 0U; // order of the polynomial describing the
242  // correction to the r-t relationship
243  std::vector<CLHEP::HepVector> m_U; // vector of base correction function values
244  std::vector<CLHEP::HepVector> m_U_weighted; // vector of base correction function
245  // values weighted by the inverse
246  // standard deviation of the radius
247  // measurements
248  CLHEP::HepSymMatrix m_A; // coefficient matrix of the final autocalibration
249  // equation
250  CLHEP::HepVector m_alpha; // vector of fit parameters, i.e. the coefficients
251  // of the correction polynomial
252  CLHEP::HepVector m_b; // m_A*m_alpha = m_b (final autocalibration equation)
253 
254  // correction functions //
255  std::unique_ptr<BaseFunction> m_base_function; // pointer to the base function u
256 
257  // control histograms //
258  std::unique_ptr<TFile> m_tfile{}; // ROOT file
259  std::unique_ptr<TH1F> m_cut_evolution{}; // cut evolution histogram
260  std::unique_ptr<TH1F> m_nb_segment_hits{}; // number of hits on the segments
261  std::unique_ptr<TH1F> m_pull_initial{}; // initial pull distribution
262  std::unique_ptr<TH1F> m_pull_final{}; // final pull distribution after convergence
263  std::unique_ptr<TH2F> m_residuals_initial{}; // initial residual distribution
264  std::unique_ptr<TH2F> m_residuals_initial_all{}; // initial residual distribution before convergence
265  std::unique_ptr<TH2F> m_residuals_final{}; // final residual distribution after convergence
266  std::unique_ptr<TH2F> m_driftTime_initial{}; // final residual distribution after convergence
267  std::unique_ptr<TH2F> m_driftTime_final{}; // final residual distribution after convergence
268  std::unique_ptr<TH2F> m_adc_vs_residual_final{}; // final residual distribution after convergence
269 
270  // private methods //
271  void init(const double rt_accuracy, const unsigned int &func_type, const unsigned int &ord, const bool &fix_min,
272  const bool &fix_max, const int &max_it, bool do_parabolic_extrapolation, bool do_smoothing, bool do_multilayer_rt_scale);
273  // initialization method:
274  // rt_accuracy = estimated r-t accuracy,
275  // func_type: type of function to be used for
276  // the r-t correction;
277  // = 1: Legendre polynomial,
278  // = 2: Chebyshev polynomial,
279  // = 3: polygon
280  // ord = "order" ot the r-t correction function
281  // split = true forces the algorithm to restrict
282  // segments to multilayers;
283  // fix_min, fix_max=true: fix r(t_min), r(t_max)
284  // max_it: maximum number of iterations
285  // do_parabolic_extrapolation: do or do not use
286  // parabolic extrapolations for small and large
287  // radii;
288  // do_smoothing: smoothen the r-t relationship
289  // after convergence if do_smoothing = true
290  double t_from_r(const double r);
291  // get t(r) for the input r-t relationship,
292  // the method is auxiliary and not optimized;
293  // it will disappear when the t(r) will be
294  // available in the MuonCalib framework
295  void display_segment(MuonCalibSegment *segment, std::ofstream &outfile, const CurvedLine *curved_segment);
296  // write out a simple PAW macro displaying the
297  // segment; if the pointer "curved_segment" equals
298  // 0, a straight line as stored in segment is drawn;
299  // the curved line is used otherwise
300  std::shared_ptr<RtRelationLookUp> performParabolicExtrapolation(const bool &min, const bool &max, const IRtRelation &in_rt);
301  // use parabolic extrapolations on the given r-t
302  // relationship in_rt;
303  // min: if true, use parabolic extrapolation towards
304  // r=0;
305  // max: if true, use parabolic extrapolation towards
306  // r=r_max;
307  };
308 
309 } // namespace MuonCalib
310 
311 #endif
MuonCalib::RtCalibrationCurved::m_driftTime_initial
std::unique_ptr< TH2F > m_driftTime_initial
Definition: RtCalibrationCurved.h:266
MuonCalib::RtCalibrationCurved::noSmoothing
void noSmoothing()
do not smoothen the r-t relationship after convergence
Definition: RtCalibrationCurved.cxx:100
MuonCalib::RtCalibrationCurved::m_base_function
std::unique_ptr< BaseFunction > m_base_function
Definition: RtCalibrationCurved.h:255
MuonCalib::RtCalibrationCurved::m_fix_max
bool m_fix_max
Definition: RtCalibrationCurved.h:185
beamspotman.r
def r
Definition: beamspotman.py:676
MuonCalib::RtCalibrationCurved::m_rt_new
std::shared_ptr< IRtRelation > m_rt_new
Definition: RtCalibrationCurved.h:221
MuonCalib::IMdtCalibration::MdtCalibOutputPtr
std::shared_ptr< IMdtCalibrationOutput > MdtCalibOutputPtr
Definition: IMdtCalibration.h:30
MuonCalib::RtCalibrationCurved::m_residuals_initial
std::unique_ptr< TH2F > m_residuals_initial
Definition: RtCalibrationCurved.h:263
MuonCalib::RtCalibrationCurved
Definition: RtCalibrationCurved.h:45
MuonCalib::RtCalibrationCurved::m_tfile
std::unique_ptr< TFile > m_tfile
Definition: RtCalibrationCurved.h:258
MuonCalib::RtCalibrationCurved::m_order
unsigned int m_order
Definition: RtCalibrationCurved.h:241
MuonCalib::RtCalibrationCurved::init
void init(const double rt_accuracy, const unsigned int &func_type, const unsigned int &ord, const bool &fix_min, const bool &fix_max, const int &max_it, bool do_parabolic_extrapolation, bool do_smoothing, bool do_multilayer_rt_scale)
Definition: RtCalibrationCurved.cxx:725
MuonCalib::RtCalibrationCurved::iteration
int iteration() const
get the number of the current iteration
Definition: RtCalibrationCurved.cxx:57
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
MuonCalib::RtCalibrationCurved::forceMonotony
void forceMonotony()
force r(t) to be monotonically increasing (this is default)
Definition: RtCalibrationCurved.cxx:96
MuonCalib::RtCalibrationCurved::m_do_smoothing
bool m_do_smoothing
Definition: RtCalibrationCurved.h:238
MuonCalib::RtCalibrationCurved::m_multilayer
std::array< bool, 2 > m_multilayer
Definition: RtCalibrationCurved.h:195
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
MuonCalib::RtCalibrationCurved::m_nb_segments
int m_nb_segments
Definition: RtCalibrationCurved.h:192
MuonCalib::CurvedLine
Definition: CurvedLine.h:30
MuonCalib::RtCalibrationCurved::m_pull_initial
std::unique_ptr< TH1F > m_pull_initial
Definition: RtCalibrationCurved.h:261
MuonCalib::IMdtCalibration
Definition: IMdtCalibration.h:25
MuonCalib::RtCalibrationCurved::RtCalibrationCurved
RtCalibrationCurved(const std::string &name)
Default constructor: r-t accuracy is set to 0.5 mm.
Definition: RtCalibrationCurved.cxx:35
MuonCalib::MuonCalibSegment
Definition: MuonCalibSegment.h:39
MuonCalib::RtCalibrationCurved::m_nb_segments_used
int m_nb_segments_used
Definition: RtCalibrationCurved.h:193
MuonCalib::RtCalibrationCurved::m_chi2
double m_chi2
Definition: RtCalibrationCurved.h:211
MuonCalib::RtCalibrationCurved::m_rt
std::shared_ptr< const IRtRelation > m_rt
Definition: RtCalibrationCurved.h:216
MuonCalib::RtCalibrationCurved::smoothing
bool smoothing() const
returns true, if the r-t relationship will be smoothened using the conventional autocalibration after...
Definition: RtCalibrationCurved.cxx:59
MuonCalib::RtCalibrationCurved::fullMatrix
void fullMatrix(const bool &yes_or_no)
yes_or_no=true: the full matrix relating the errors in the r-t relationship to the residuals is used ...
MuonCalib::RtCalibrationCurved::display_segment
void display_segment(MuonCalibSegment *segment, std::ofstream &outfile, const CurvedLine *curved_segment)
Definition: RtCalibrationCurved.cxx:824
MuonCalib::RtCalibrationCurved::doSmoothing
void doSmoothing()
requires that the r-t relationship will be smoothened using the conventional autocalibration after co...
Definition: RtCalibrationCurved.cxx:99
MuonCalib::RtCalibrationCurved::reliability
double reliability() const
get the reliability of the final r-t relationship: 0: no convergence yet 1: convergence,...
Definition: RtCalibrationCurved.cxx:49
MuonCalib::RtCalibrationCurved::m_fix_min
bool m_fix_min
Definition: RtCalibrationCurved.h:184
MuonCalib::RtCalibrationCurved::noParabolicExtrapolation
void noParabolicExtrapolation()
no parabolic extrapolation is done
MuonCalib::RtCalibrationCurved::m_do_parabolic_extrapolation
bool m_do_parabolic_extrapolation
Definition: RtCalibrationCurved.h:234
MuonCalib::RtCalibrationCurved::m_residuals_final
std::unique_ptr< TH2F > m_residuals_final
Definition: RtCalibrationCurved.h:265
physics_parameters.file_name
string file_name
Definition: physics_parameters.py:32
GeoPrimitives.h
MuonCalib::RtCalibrationCurved::m_r_max
double m_r_max
Definition: RtCalibrationCurved.h:226
CurvedLine
MuonCalib::RtCalibrationCurved::m_rt_accuracy
double m_rt_accuracy
Definition: RtCalibrationCurved.h:202
MuonCalib::RtCalibrationCurved::m_driftTime_final
std::unique_ptr< TH2F > m_driftTime_final
Definition: RtCalibrationCurved.h:267
MuonCalib::RtCalibrationCurved::m_status
int m_status
Definition: RtCalibrationCurved.h:199
MuonCalib::RtCalibrationCurved::m_control_histograms
bool m_control_histograms
Definition: RtCalibrationCurved.h:182
MuonCalib::RtCalibrationCurved::performParabolicExtrapolation
std::shared_ptr< RtRelationLookUp > performParabolicExtrapolation(const bool &min, const bool &max, const IRtRelation &in_rt)
Definition: RtCalibrationCurved.cxx:910
MuonCalib::RtCalibrationCurved::numberOfSegments
int numberOfSegments() const
get the number of segments which were passed to the algorithm
Definition: RtCalibrationCurved.cxx:53
MuonCalib::RtCalibrationCurved::switch_on_control_histograms
void switch_on_control_histograms(const std::string &file_name)
this methods requests control histograms from the algorithms; the algorithm will write them to ROOT f...
Definition: RtCalibrationCurved.cxx:63
MuonCalib::RtCalibrationCurved::m_residuals_initial_all
std::unique_ptr< TH2F > m_residuals_initial_all
Definition: RtCalibrationCurved.h:264
MuonCalib::RtCalibrationCurved::estimatedRtAccuracy
double estimatedRtAccuracy() const
get the estimated r-t quality (CLHEP::mm), the accuracy of the input r-t is computed at the end of th...
Definition: RtCalibrationCurved.cxx:51
MuonCalib::RtCalibrationCurved::m_t_mean
double m_t_mean
Definition: RtCalibrationCurved.h:218
MuonCalib::RtCalibrationCurved::m_force_monotony
bool m_force_monotony
Definition: RtCalibrationCurved.h:187
MuonCalib::RtCalibrationCurved::m_chi2_previous
double m_chi2_previous
Definition: RtCalibrationCurved.h:205
MuonCalib::RtCalibrationCurved::m_multilayer_rt_difference
std::unique_ptr< MultilayerRtDifference > m_multilayer_rt_difference
Definition: RtCalibrationCurved.h:224
MuonCalib::RtCalibrationCurved::setEstimateRtAccuracy
void setEstimateRtAccuracy(const double acc)
set the estimated r-t accuracy =acc
Definition: RtCalibrationCurved.cxx:61
MuonCalib::RtCalibrationCurved::m_M_track
CLHEP::HepSymMatrix m_M_track
Definition: RtCalibrationCurved.h:230
MuonCalib::RtCalibrationCurved::m_M_track_inverse
CLHEP::HepSymMatrix m_M_track_inverse
Definition: RtCalibrationCurved.h:231
MuonCalib::RtCalibrationCurved::m_cut_evolution
std::unique_ptr< TH1F > m_cut_evolution
Definition: RtCalibrationCurved.h:259
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
MuonCalib::RtCalibrationCurved::m_output
std::shared_ptr< RtCalibrationOutput > m_output
Definition: RtCalibrationCurved.h:222
MuonCalib::RtCalibrationCurved::m_pull_final
std::unique_ptr< TH1F > m_pull_final
Definition: RtCalibrationCurved.h:262
MuonCalib::RtCalibrationCurved::m_nb_segment_hits
std::unique_ptr< TH1F > m_nb_segment_hits
Definition: RtCalibrationCurved.h:260
MuonCalib::RtCalibrationCurved::m_do_multilayer_rt_scale
bool m_do_multilayer_rt_scale
Definition: RtCalibrationCurved.h:189
MuonCalib::RtCalibrationCurved::m_t_length
double m_t_length
Definition: RtCalibrationCurved.h:217
MuonCalib::RtCalibrationCurved::m_max_it
int m_max_it
Definition: RtCalibrationCurved.h:186
CurvedPatRec
MuonCalib::IMdtCalibration::name
virtual std::string name() const
returns name (region) of instance
Definition: IMdtCalibration.h:49
MuonCalib::RtCalibrationCurved::m_iteration
int m_iteration
Definition: RtCalibrationCurved.h:194
MuonCalib::RtCalibrationCurved::m_adc_vs_residual_final
std::unique_ptr< TH2F > m_adc_vs_residual_final
Definition: RtCalibrationCurved.h:268
IMdtCalibration.h
MuonCalib::IMdtCalibrationOutput
Definition: IMdtCalibrationOutput.h:28
MuonCalib::RtCalibrationCurved::setInput
void setInput(const IMdtCalibrationOutput *rt_input) override
set the r-t relationship, the internal autocalibration objects are reset
Definition: RtCalibrationCurved.cxx:506
MuonCalib::RtCalibrationCurved::analyseSegments
MdtCalibOutputPtr analyseSegments(const MuonSegVec &seg) override
perform the full autocalibration including iterations (required since MdtCalibInterfaces-00-01-06)
Definition: RtCalibrationCurved.cxx:101
MuonCalib::RtCalibrationCurved::converged
bool converged() const
returns true, if the autocalibration has converged
Definition: RtCalibrationCurved.cxx:717
MuonCalib::RtCalibrationCurved::analyse
bool analyse(const MuonSegVec &seg)
perform the autocalibration with the segments acquired so far
Definition: RtCalibrationCurved.cxx:563
MuonCalib::RtCalibrationCurved::numberOfSegmentsUsed
int numberOfSegmentsUsed() const
get the number of segments which are used in the autocalibration
Definition: RtCalibrationCurved.cxx:55
MuonCalib::RtCalibrationCurved::m_rt_accuracy_previous
double m_rt_accuracy_previous
Definition: RtCalibrationCurved.h:203
MuonCalib::RtCalibrationCurved::switch_off_control_histograms
void switch_off_control_histograms()
the algorithm does not produce controll histograms (this is the default)
Definition: RtCalibrationCurved.cxx:88
MuonCalib::RtCalibrationCurved::doNotForceMonotony
void doNotForceMonotony()
do not force r(t) to be monotonically increasing
Definition: RtCalibrationCurved.cxx:97
MuonCalib::RtCalibrationCurved::t_from_r
double t_from_r(const double r)
Definition: RtCalibrationCurved.cxx:803
MuonCalib::RtCalibrationCurved::getResults
virtual MdtCalibOutputPtr getResults() const override
returns the final r-t relationship
Definition: RtCalibrationCurved.cxx:718
MuonCalib::RtCalibrationCurved::m_b
CLHEP::HepVector m_b
Definition: RtCalibrationCurved.h:252
MuonCalib::RtCalibrationCurved::m_A
CLHEP::HepSymMatrix m_A
Definition: RtCalibrationCurved.h:248
MuonCalib::RtCalibrationCurved::handleSegment
bool handleSegment(MuonCalibSegment &seg)
analyse the segment "seg" (this method was required before MdtCalibInterfaces-00-01-06)
Definition: RtCalibrationCurved.cxx:267
MuonCalib::RtCalibrationCurved::m_alpha
CLHEP::HepVector m_alpha
Definition: RtCalibrationCurved.h:250
MuonCalib::IMdtCalibration::MuonSegVec
std::vector< std::shared_ptr< MuonCalibSegment > > MuonSegVec
Definition: IMdtCalibration.h:27
MuonCalib::RtCalibrationCurved::~RtCalibrationCurved
~RtCalibrationCurved()
Destructor.
Definition: RtCalibrationCurved.cxx:46
MuonCalib::RtCalibrationCurved::m_U_weighted
std::vector< CLHEP::HepVector > m_U_weighted
Definition: RtCalibrationCurved.h:244
MuonCalib::RtCalibrationCurved::m_U
std::vector< CLHEP::HepVector > m_U
Definition: RtCalibrationCurved.h:243
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
MuonCalib::RtCalibrationCurved::m_tracker
std::unique_ptr< CurvedPatRec > m_tracker
Definition: RtCalibrationCurved.h:227
MuonCalib::RtCalibrationCurved::doParabolicExtrapolation
void doParabolicExtrapolation()
requires that parabolic extrapolation will be used for small and large radii
Definition: RtCalibrationCurved.cxx:98
MuonCalib::IRtRelation
generic interface for a rt-relation
Definition: IRtRelation.h:15
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5