CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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);
40 
42  enum beam_type { lhcb1, lhcb2 };
43  void Train(TTree *inp_tree,
44  std::string data_prefix = std::string("def"),
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;
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;
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_
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
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:
215 
218  double rect_x,
219  double rect_y,
220  double r_el_x,
221  double r_el_y,
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:
229 
230  ClassDef(LHCApertureApproximator, 1) // Aperture approximator
231 };
232 #endif //TotemRPProtonTransportParametrization_LHC_OPTICS_APPROXIMATOR_H
void InitializeApproximators(polynomials_selection mode, int max_degree_x, int max_degree_tx, int max_degree_y, int max_degree_ty, bool common_terms)
void FillErrorDataCorHistograms(double errors[4], double var[5], TH2D *err_cor_hists[4][5])
void DeleteErrorHists(TH1D *err_hists[4])
void TestAperture(TTree *in_tree, TTree *out_tree)
x, theta_x, y, theta_y, ksi, mad_accepted, parametriz_accepted
bool Transport2D(const double *in, double *out, bool check_apertures=false, bool invert_beam_coord_sytems=true) const
bool Transport(const double *in, double *out, bool check_apertures=false, bool invert_beam_coord_sytems=true) const
std::vector< LHCApertureApproximator > apertures_
apertures on the way
beam_type GetBeamType() const
TMultiDimFet theta_x_parametrisation
polynomial approximation for theta_x
friend class ProtonTransportFunctionsESSource
double nominal_beam_momentum_
GeV/c.
void AllocateErrorOutputCorHists(TH2D *err_out_cor_hists[4][5])
bool Transport_m_GeV(double in_pos[3], double in_momentum[3], double out_pos[3], double out_momentum[3], bool check_apertures, double z2_z1_dist) const
pos, momentum: x,y,z; pos in m, momentum in GeV/c
bool CheckInputRange(const double *in, bool invert_beam_coord_sytems=true) const
void SetTermsManually(TMultiDimFet &approximator, VariableType variable, int max_degree, bool common_terms)
void GetLineariasedTransportMatrixY(double mad_init_x, double mad_init_thx, double mad_init_y, double mad_init_thy, double mad_init_xi, TMatrixD &tr_matrix, double d_mad_y=10e-6, double d_mad_thy=10e-6)
returns linearised transport matrix for y projection | dy_out/dy_in dy_out/dthy_in | | dthy_out/dy_in...
void AddRectEllipseAperture(const LHCOpticsApproximator &in, double rect_x, double rect_y, double r_el_x, double r_el_y)
double ParameterOutOfRangePenalty(double par_m[], bool invert_beam_coord_sytems=true) const
double s_begin_
begin of transport along the reference orbit
TMultiDimFet theta_y_parametrisation
polynomial approximation for theta_y
void AllocateErrorHists(TH1D *err_hists[4])
void GetLinearApproximation(double atPoint[], double &Cx, double &Lx, double &vx, double &Cy, double &Ly, double &vy, double &D, double ep=1E-5)
bool trained_
trained polynomials
void PrintCoordinateOpticalFunctions(TMultiDimFet &parametrization, const std::string &coord_name, const std::vector< std::string > &input_vars)
std::vector< TMultiDimFet * > out_polynomials
list var
if using global norm cols_to_minmax = [&#39;t_delta&#39;, &#39;t_hmaxNearP&#39;,&#39;t_emaxNearP&#39;, &#39;t_hAnnular&#39;, &#39;t_eAnnular&#39;,&#39;t_pt&#39;,&#39;t_nVtx&#39;,&#39;t_ieta&#39;,&#39;t_eHcal10&#39;, &#39;t_eHcal30&#39;,&#39;t_rhoh&#39;,&#39;t_eHcal&#39;] df[cols_to_minmax] = df[cols_to_minmax].apply(lambda x: (x - x.min()) / (x.max() - x.min()) if (x.max() - x.min() &gt; 0) else 1.0/200.0)
double GetDxds(double mad_init_x, double mad_init_thx, double mad_init_y, double mad_init_thy, double mad_init_xi, double d_mad_xi=0.001)
void Test(TTree *inp_tree, TFile *f_out, std::string data_prefix=std::string("def"), std::string base_out_dir=std::string(""))
Class finds the parametrisation of MADX proton transport and transports the protons according to it 5...
void GetLineariasedTransportMatrixX(double mad_init_x, double mad_init_thx, double mad_init_y, double mad_init_thy, double mad_init_xi, TMatrixD &tr_matrix, double d_mad_x=10e-6, double d_mad_thx=10e-6)
returns linearised transport matrix for x projection | dx_out/dx_in dx_out/dthx_in | | dthx_out/dx_in...
void DeleteErrorCorHistograms(TH2D *err_cor_hists[4][5])
void SetDefaultAproximatorSettings(TMultiDimFet &approximator, VariableType var_type, int max_degree)
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
double s_end_
end of transport along the reference orbit
void FillErrorHistograms(double errors[4], TH1D *err_hists[4])
double GetDx(double mad_init_x, double mad_init_thx, double mad_init_y, double mad_init_thy, double mad_init_xi, double d_mad_xi=0.001)
void AllocateErrorInputCorHists(TH2D *err_inp_cor_hists[4][5])
std::vector< std::string > coord_names
pointers to polynomials
TMultiDimFet y_parametrisation
polynomial approximation for y
TMultiDimFet x_parametrisation
polynomial approximation for x
void Train(TTree *inp_tree, std::string data_prefix=std::string("def"), polynomials_selection mode=PREDEFINED, int max_degree_x=10, int max_degree_tx=10, int max_degree_y=10, int max_degree_ty=10, bool common_terms=false, double *prec=nullptr)
void WriteHistograms(TH1D *err_hists[4], TH2D *err_inp_cor_hists[4][5], TH2D *err_out_cor_hists[4][5], TFile *f_out, std::string base_out_dir)
bool CheckAperture(const double *in, bool invert_beam_coord_sytems=true) const
const LHCOpticsApproximator & operator=(const LHCOpticsApproximator &org)