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);
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();
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
LHCApertureApproximator::ApertureType
ApertureType
Definition: LHCOpticsApproximator.h:214
MadKinematicDescriptor::theta_x
double theta_x
rad
Definition: LHCOpticsApproximator.h:16
LHCApertureApproximator::ApertureType::RECTELLIPSE
LHCOpticsApproximator::lhcb2
Definition: LHCOpticsApproximator.h:42
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
MadKinematicDescriptor::y
double y
m
Definition: LHCOpticsApproximator.h:17
LHCOpticsApproximator::coord_names
std::vector< std::string > coord_names
pointers to polynomials
Definition: LHCOpticsApproximator.h:169
LHCOpticsApproximator::operator=
const LHCOpticsApproximator & operator=(const LHCOpticsApproximator &org)
Definition: LHCOpticsApproximator.cc:261
TMultiDimFet::EMDFPolyType
EMDFPolyType
Definition: TMultiDimFet.h:46
LHCOpticsApproximator::FillErrorDataCorHistograms
void FillErrorDataCorHistograms(double errors[4], double var[5], TH2D *err_cor_hists[4][5])
Definition: LHCOpticsApproximator.cc:843
LHCOpticsApproximator::FillErrorHistograms
void FillErrorHistograms(double errors[4], TH1D *err_hists[4])
Definition: LHCOpticsApproximator.cc:837
LHCOpticsApproximator::apertures_
std::vector< LHCApertureApproximator > apertures_
apertures on the way
Definition: LHCOpticsApproximator.h:170
LHCApertureApproximator
Definition: LHCOpticsApproximator.h:212
LHCOpticsApproximator::VariableType
VariableType
Definition: LHCOpticsApproximator.h:182
LHCOpticsApproximator::LHCOpticsApproximator
LHCOpticsApproximator()
Definition: LHCOpticsApproximator.cc:59
LHCOpticsApproximator::out_polynomials
std::vector< TMultiDimFet * > out_polynomials
Definition: LHCOpticsApproximator.h:168
LHCOpticsApproximator::DeleteErrorHists
void DeleteErrorHists(TH1D *err_hists[4])
Definition: LHCOpticsApproximator.cc:851
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
LHCOpticsApproximator::VariableType::X
LHCOpticsApproximator::GetDx
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)
Definition: LHCOpticsApproximator.cc:1153
LHCOpticsApproximator::PrintCoordinateOpticalFunctions
void PrintCoordinateOpticalFunctions(TMultiDimFet &parametrization, const std::string &coord_name, const std::vector< std::string > &input_vars)
Definition: LHCOpticsApproximator.cc:1002
LHCOpticsApproximator::nominal_beam_energy_
double nominal_beam_energy_
GeV.
Definition: LHCOpticsApproximator.h:165
LHCOpticsApproximator::AllocateErrorInputCorHists
void AllocateErrorInputCorHists(TH2D *err_inp_cor_hists[4][5])
Definition: LHCOpticsApproximator.cc:779
LHCOpticsApproximator::WriteHistograms
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)
Definition: LHCOpticsApproximator.cc:865
LHCOpticsApproximator::x_parametrisation
TMultiDimFet x_parametrisation
polynomial approximation for x
Definition: LHCOpticsApproximator.h:176
LHCOpticsApproximator::Test
void Test(TTree *inp_tree, TFile *f_out, std::string data_prefix=std::string("def"), std::string base_out_dir=std::string(""))
Definition: LHCOpticsApproximator.cc:629
LHCApertureApproximator::r_el_x_
double r_el_x_
Definition: LHCOpticsApproximator.h:227
LHCOpticsApproximator::Train
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)
Definition: LHCOpticsApproximator.cc:282
trigObjTnPSource_cfi.var
var
Definition: trigObjTnPSource_cfi.py:21
LHCApertureApproximator::rect_x_
double rect_x_
Definition: LHCOpticsApproximator.h:227
LHCOpticsApproximator::GetLineariasedTransportMatrixX
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...
Definition: LHCOpticsApproximator.cc:1065
LHCOpticsApproximator::y_parametrisation
TMultiDimFet y_parametrisation
polynomial approximation for y
Definition: LHCOpticsApproximator.h:178
errors
Definition: errors.py:1
LHCOpticsApproximator::theta_x_parametrisation
TMultiDimFet theta_x_parametrisation
polynomial approximation for theta_x
Definition: LHCOpticsApproximator.h:177
LHCOpticsApproximator::PrintInputRange
void PrintInputRange()
Definition: LHCOpticsApproximator.cc:919
LHCOpticsApproximator::trained_
bool trained_
trained polynomials
Definition: LHCOpticsApproximator.h:167
stringResolutionProvider_cfi.parametrization
parametrization
specify parametrization (see SWGuidePATKinematicResolutions for more details)
Definition: stringResolutionProvider_cfi.py:6
LHCOpticsApproximator::beam_type
beam_type
Definition: LHCOpticsApproximator.h:42
LHCOpticsApproximator::ProtonTransportFunctionsESSource
friend class ProtonTransportFunctionsESSource
Definition: LHCOpticsApproximator.h:173
LHCOpticsApproximator::AllocateErrorHists
void AllocateErrorHists(TH1D *err_hists[4])
Definition: LHCOpticsApproximator.cc:720
LHCApertureApproximator::r_el_y_
double r_el_y_
Definition: LHCOpticsApproximator.h:227
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LHCOpticsApproximator::s_begin_
double s_begin_
begin of transport along the reference orbit
Definition: LHCOpticsApproximator.h:162
LHCOpticsApproximator::PrintOpticalFunctions
void PrintOpticalFunctions()
Definition: LHCOpticsApproximator.cc:993
LHCOpticsApproximator::Transport2D
bool Transport2D(const double *in, double *out, bool check_apertures=false, bool invert_beam_coord_sytems=true) const
Definition: LHCOpticsApproximator.cc:144
MadKinematicDescriptor::ksi
double ksi
1
Definition: LHCOpticsApproximator.h:19
LHCApertureApproximator::ap_type_
ApertureType ap_type_
Definition: LHCOpticsApproximator.h:228
LHCOpticsApproximator::PREDEFINED
Definition: LHCOpticsApproximator.h:41
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
recoMuon::in
Definition: RecoMuonEnumerators.h:6
LHCApertureApproximator::LHCApertureApproximator
LHCApertureApproximator()
Definition: LHCOpticsApproximator.cc:965
LHCOpticsApproximator::Transport
bool Transport(const double *in, double *out, bool check_apertures=false, bool invert_beam_coord_sytems=true) const
Definition: LHCOpticsApproximator.cc:102
TMultiDimFet
Definition: TMultiDimFet.h:35
LHCOpticsApproximator::lhcb1
Definition: LHCOpticsApproximator.h:42
LHCOpticsApproximator::polynomials_selection
polynomials_selection
Definition: LHCOpticsApproximator.h:41
LHCOpticsApproximator::AUTOMATIC
Definition: LHCOpticsApproximator.h:41
LHCOpticsApproximator::nominal_beam_momentum_
double nominal_beam_momentum_
GeV/c.
Definition: LHCOpticsApproximator.h:166
LHCOpticsApproximator::s_end_
double s_end_
end of transport along the reference orbit
Definition: LHCOpticsApproximator.h:163
LHCOpticsApproximator::TestAperture
void TestAperture(TTree *in_tree, TTree *out_tree)
x, theta_x, y, theta_y, ksi, mad_accepted, parametriz_accepted
Definition: LHCOpticsApproximator.cc:736
LHCOpticsApproximator::ParameterOutOfRangePenalty
double ParameterOutOfRangePenalty(double par_m[], bool invert_beam_coord_sytems=true) const
Definition: LHCOpticsApproximator.cc:68
LHCOpticsApproximator::GetDxds
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)
Definition: LHCOpticsApproximator.cc:1181
LHCOpticsApproximator
Class finds the parametrisation of MADX proton transport and transports the protons according to it 5...
Definition: LHCOpticsApproximator.h:29
LHCApertureApproximator::CheckAperture
bool CheckAperture(const double *in, bool invert_beam_coord_sytems=true) const
Definition: LHCOpticsApproximator.cc:980
MadKinematicDescriptor
Definition: LHCOpticsApproximator.h:14
LHCOpticsApproximator::theta_y_parametrisation
TMultiDimFet theta_y_parametrisation
polynomial approximation for theta_y
Definition: LHCOpticsApproximator.h:179
funct::D
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
taus_updatedMVAIds_cff.variable
variable
Definition: taus_updatedMVAIds_cff.py:33
LHCOpticsApproximator::VariableType::THETA_Y
TMultiDimFet.h
MadKinematicDescriptor::x
double x
m
Definition: LHCOpticsApproximator.h:15
LHCApertureApproximator::ApertureType::NO_APERTURE
LHCOpticsApproximator::AddRectEllipseAperture
void AddRectEllipseAperture(const LHCOpticsApproximator &in, double rect_x, double rect_y, double r_el_x, double r_el_y)
Definition: LHCOpticsApproximator.cc:959
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
LHCOpticsApproximator::InitializeApproximators
void InitializeApproximators(polynomials_selection mode, int max_degree_x, int max_degree_tx, int max_degree_y, int max_degree_ty, bool common_terms)
Definition: LHCOpticsApproximator.cc:391
LHCApertureApproximator::rect_y_
double rect_y_
Definition: LHCOpticsApproximator.h:227
MadKinematicDescriptor::theta_y
double theta_y
rad
Definition: LHCOpticsApproximator.h:18
LHCOpticsApproximator::GetLineariasedTransportMatrixY
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...
Definition: LHCOpticsApproximator.cc:1109
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
LHCOpticsApproximator::VariableType::Y
LHCOpticsApproximator::GetBeamType
beam_type GetBeamType() const
Definition: LHCOpticsApproximator.h:145
LHCOpticsApproximator::Init
void Init()
Definition: LHCOpticsApproximator.cc:15
LHCOpticsApproximator::VariableType::THETA_X
LHCOpticsApproximator::beam
beam_type beam
Definition: LHCOpticsApproximator.h:164
SiStripBadComponentsDQMServiceTemplate_cfg.ep
ep
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:86
LHCOpticsApproximator::AllocateErrorOutputCorHists
void AllocateErrorOutputCorHists(TH2D *err_out_cor_hists[4][5])
Definition: LHCOpticsApproximator.cc:808
LHCOpticsApproximator::Transport_m_GeV
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
Definition: LHCOpticsApproximator.cc:182
LHCOpticsApproximator::GetLinearApproximation
void GetLinearApproximation(double atPoint[], double &Cx, double &Lx, double &vx, double &Cy, double &Ly, double &vy, double &D, double ep=1E-5)
Definition: LHCOpticsApproximator.cc:1033
LHCOpticsApproximator::SetDefaultAproximatorSettings
void SetDefaultAproximatorSettings(TMultiDimFet &approximator, VariableType var_type, int max_degree)
Definition: LHCOpticsApproximator.cc:410
LHCOpticsApproximator::CheckInputRange
bool CheckInputRange(const double *in, bool invert_beam_coord_sytems=true) const
Definition: LHCOpticsApproximator.cc:931
LHCOpticsApproximator::DeleteErrorCorHistograms
void DeleteErrorCorHistograms(TH2D *err_cor_hists[4][5])
Definition: LHCOpticsApproximator.cc:857
LHCOpticsApproximator::SetTermsManually
void SetTermsManually(TMultiDimFet &approximator, VariableType variable, int max_degree, bool common_terms)
Definition: LHCOpticsApproximator.cc:441
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37