CMS 3D CMS Logo

LHCOpticsApproximator.h
Go to the documentation of this file.
1 #ifndef TotemRPProtonTransportParametrization_LHC_OPTICS_APPROXIMATOR_H
2 #define TotemRPProtonTransportParametrization_LHC_OPTICS_APPROXIMATOR_H
3 
4 #include <string>
5 #include "TNamed.h"
6 #include "TTree.h"
7 #include "TH1D.h"
8 #include "TH2D.h"
9 #include <memory>
10 #include "TMatrixD.h"
11 
13 
15  double x;
16  double theta_x;
17  double y;
18  double theta_y;
19  double ksi;
20 };
21 
23 
29 class LHCOpticsApproximator : public TNamed {
30 public:
35  TMultiDimFet::EMDFPolyType polynom_type,
36  std::string beam_direction,
37  double nominal_beam_momentum);
39  const LHCOpticsApproximator &operator=(const LHCOpticsApproximator &org);
40 
41  enum polynomials_selection { AUTOMATIC, PREDEFINED };
42  enum beam_type { lhcb1, lhcb2 };
43  void Train(TTree *inp_tree,
44  std::string data_prefix = std::string("def"),
45  polynomials_selection mode = PREDEFINED,
46  int max_degree_x = 10,
47  int max_degree_tx = 10,
48  int max_degree_y = 10,
49  int max_degree_ty = 10,
50  bool common_terms = false,
51  double *prec = nullptr);
52  void Test(TTree *inp_tree,
53  TFile *f_out,
54  std::string data_prefix = std::string("def"),
55  std::string base_out_dir = std::string(""));
56  void TestAperture(TTree *in_tree,
57  TTree *out_tree);
58 
59  double ParameterOutOfRangePenalty(double par_m[], bool invert_beam_coord_sytems = true) const;
60 
66  bool Transport(const double *in,
67  double *out,
68  bool check_apertures = false,
69  bool invert_beam_coord_sytems = true) const;
70  bool Transport(const MadKinematicDescriptor *in,
72  bool check_apertures = false,
73  bool invert_beam_coord_sytems = true) const; //return true if transport possible
74 
80  bool Transport2D(const double *in,
81  double *out,
82  bool check_apertures = false,
83  bool invert_beam_coord_sytems = true) const;
84 
85  bool Transport_m_GeV(double in_pos[3],
86  double in_momentum[3],
87  double out_pos[3],
88  double out_momentum[3],
89  bool check_apertures,
90  double z2_z1_dist) const;
91 
92  void PrintInputRange();
93  bool CheckInputRange(const double *in, bool invert_beam_coord_sytems = true) const;
94  void AddRectEllipseAperture(
95  const LHCOpticsApproximator &in, double rect_x, double rect_y, double r_el_x, double r_el_y);
96  void PrintOpticalFunctions();
97  void PrintCoordinateOpticalFunctions(TMultiDimFet &parametrization,
98  const std::string &coord_name,
99  const std::vector<std::string> &input_vars);
100 
108  void GetLineariasedTransportMatrixX(double mad_init_x,
109  double mad_init_thx,
110  double mad_init_y,
111  double mad_init_thy,
112  double mad_init_xi,
113  TMatrixD &tr_matrix,
114  double d_mad_x = 10e-6,
115  double d_mad_thx = 10e-6);
116 
124  void GetLineariasedTransportMatrixY(double mad_init_x,
125  double mad_init_thx,
126  double mad_init_y,
127  double mad_init_thy,
128  double mad_init_xi,
129  TMatrixD &tr_matrix,
130  double d_mad_y = 10e-6,
131  double d_mad_thy = 10e-6);
132 
133  double GetDx(double mad_init_x,
134  double mad_init_thx,
135  double mad_init_y,
136  double mad_init_thy,
137  double mad_init_xi,
138  double d_mad_xi = 0.001);
139  double GetDxds(double mad_init_x,
140  double mad_init_thx,
141  double mad_init_y,
142  double mad_init_thy,
143  double mad_init_xi,
144  double d_mad_xi = 0.001);
145  inline beam_type GetBeamType() const { return beam; }
146 
150  void GetLinearApproximation(double atPoint[],
151  double &Cx,
152  double &Lx,
153  double &vx,
154  double &Cy,
155  double &Ly,
156  double &vy,
157  double &D,
158  double ep = 1E-5);
159 
160 private:
161  void Init();
162  double s_begin_;
163  double s_end_;
167  bool trained_;
168  std::vector<TMultiDimFet *> out_polynomials;
169  std::vector<std::string> coord_names;
170  std::vector<LHCApertureApproximator> apertures_;
171 
172 #ifndef __CINT_
173  friend class ProtonTransportFunctionsESSource;
174 #endif // __CINT__
175 
180 
181  //train_mode mode_; //polynomial selection mode - selection done by fitting function or selection from the list according to the specified order
182  enum class VariableType { X, THETA_X, Y, THETA_Y };
183  //internal methods
184  void InitializeApproximators(polynomials_selection mode,
185  int max_degree_x,
186  int max_degree_tx,
187  int max_degree_y,
188  int max_degree_ty,
189  bool common_terms);
190  void SetDefaultAproximatorSettings(TMultiDimFet &approximator, VariableType var_type, int max_degree);
191  void SetTermsManually(TMultiDimFet &approximator, VariableType variable, int max_degree, bool common_terms);
192 
193  void AllocateErrorHists(TH1D *err_hists[4]);
194  void AllocateErrorInputCorHists(TH2D *err_inp_cor_hists[4][5]);
195  void AllocateErrorOutputCorHists(TH2D *err_out_cor_hists[4][5]);
196 
197  void DeleteErrorHists(TH1D *err_hists[4]);
198  void DeleteErrorCorHistograms(TH2D *err_cor_hists[4][5]);
199 
200  void FillErrorHistograms(double errors[4], TH1D *err_hists[4]);
201  void FillErrorDataCorHistograms(double errors[4], double var[5], TH2D *err_cor_hists[4][5]);
202 
203  void WriteHistograms(TH1D *err_hists[4],
204  TH2D *err_inp_cor_hists[4][5],
205  TH2D *err_out_cor_hists[4][5],
206  TFile *f_out,
207  std::string base_out_dir);
208 
209  ClassDef(LHCOpticsApproximator, 1) // Proton transport approximator
210 };
211 
213 public:
214  enum class ApertureType { NO_APERTURE, RECTELLIPSE };
215 
218  double rect_x,
219  double rect_y,
220  double r_el_x,
221  double r_el_y,
222  ApertureType type = ApertureType::RECTELLIPSE);
223 
224  bool CheckAperture(const double *in, bool invert_beam_coord_sytems = true) const; //x, thx. y, thy, ksi
225  //bool CheckAperture(MadKinematicDescriptor *in); //x, thx. y, thy, ksi
226 private:
227  double rect_x_, rect_y_, r_el_x_, r_el_y_;
229 
230  ClassDef(LHCApertureApproximator, 1) // Aperture approximator
231 };
232 #endif //TotemRPProtonTransportParametrization_LHC_OPTICS_APPROXIMATOR_H
type
Definition: HCALResponse.h:21
std::vector< LHCApertureApproximator > apertures_
apertures on the way
beam_type GetBeamType() const
TMultiDimFet theta_x_parametrisation
polynomial approximation for theta_x
double nominal_beam_momentum_
GeV/c.
#define X(str)
Definition: MuonsGrabber.cc:38
double s_begin_
begin of transport along the reference orbit
TMultiDimFet theta_y_parametrisation
polynomial approximation for theta_y
parametrization
specify parametrization (see SWGuidePATKinematicResolutions for more details)
bool trained_
trained polynomials
std::vector< TMultiDimFet * > out_polynomials
Class finds the parametrisation of MADX proton transport and transports the protons according to it 5...
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
double s_end_
end of transport along the reference orbit
std::vector< std::string > coord_names
pointers to polynomials
TMultiDimFet y_parametrisation
polynomial approximation for y
Definition: errors.py:1
TMultiDimFet x_parametrisation
polynomial approximation for x