CMS 3D CMS Logo

TotemTransport.cc
Go to the documentation of this file.
3 #include <CLHEP/Units/GlobalSystemOfUnits.h>
4 #include <CLHEP/Random/RandGauss.h>
5 #include "TLorentzVector.h"
6 #include "TFile.h"
7 
8 #include <cmath>
9 
12 {
13  this->clear();
14 }
16  m_parameters(iConfig.getParameter<edm::ParameterSet>("BeamProtTransportSetup")),
17  m_verbosity(iConfig.getParameter<bool>("Verbosity")),
18  m_model_root_file_r(m_parameters.getParameter<std::string>("ModelRootFile_R")),
19  m_model_root_file_l(m_parameters.getParameter<std::string>("ModelRootFile_L")),
20  m_model_ip_150_r_name(m_parameters.getParameter<std::string>("Model_IP_150_R_Name")),
21  m_model_ip_150_l_name(m_parameters.getParameter<std::string>("Model_IP_150_L_Name")),
22  m_model_ip_150_r_zmin(m_parameters.getParameter<double>("Model_IP_150_R_Zmin")),
23  m_model_ip_150_r_zmax(m_parameters.getParameter<double>("Model_IP_150_R_Zmax")),
24  m_model_ip_150_l_zmin(m_parameters.getParameter<double>("Model_IP_150_L_Zmin")),
25  m_model_ip_150_l_zmax(m_parameters.getParameter<double>("Model_IP_150_L_Zmax")),
26  m_beampipe_aperture_radius(m_parameters.getParameter<double>("BeampipeApertureRadius"))
27 {
28  fBeamEnergy= m_parameters.getParameter<double>("sqrtS");
29  m_sigmaSTX = m_parameters.getParameter<double>("beamDivergenceX");
30  m_sigmaSTY = m_parameters.getParameter<double>("beamDivergenceY");
31  m_sig_E = m_parameters.getParameter<double>("beamEnergyDispersion");
32  fCrossingAngle_45 = m_parameters.getParameter<double>("halfCrossingAngleSector45");
33  fCrossingAngle_56 = m_parameters.getParameter<double>("halfCrossingAngleSector56");
34  fVtxMeanX = iConfig.getParameter<double>("VtxMeanX");
35  fVtxMeanY = iConfig.getParameter<double>("VtxMeanY");
36  fVtxMeanZ = iConfig.getParameter<double>("VtxMeanZ");
39  bApplyZShift = m_parameters.getParameter<bool>("ApplyZShift");
40 
42  edm::LogInfo("ProtonTransport")
43  <<"=============================================================================\n"
44  <<" Bulding LHC Proton transporter based on TOTEM model\n"
45  <<"=============================================================================\n";
46 
48 
51 
54 
55  if (m_aprox_ip_150_r == nullptr || m_aprox_ip_150_l == nullptr) {
56  edm::LogError("ProtonTransport") << "Parameterisation "
57  << m_model_ip_150_r_name << " or " << m_model_ip_150_l_name << " missing in file. Cannot proceed. ";
58  exit(1);
59  }
60  edm::LogInfo("TotemRPProtonTransportSetup") <<
61  "Parameterizations read from file, pointers:" << m_aprox_ip_150_r << " " << m_aprox_ip_150_l << " ";
62 }
63 void TotemTransport::process(const HepMC::GenEvent * evt , const edm::EventSetup& iSetup, CLHEP::HepRandomEngine * _engine )
64 {
65  engine=_engine;
66 
67  for (HepMC::GenEvent::particle_const_iterator eventParticle =evt->particles_begin(); eventParticle != evt->particles_end(); ++eventParticle ) {
68  if (!((*eventParticle)->status() == 1 && (*eventParticle)->pdg_id()==2212 )) continue;
69  unsigned int line = (*eventParticle)->barcode();
70  HepMC::GenParticle * gpart = (*eventParticle);
71  if ( gpart->pdg_id()!=2212 ) continue; // only transport stable protons
72  if ( gpart->status()!=1 /*&& gpart->status()<83 */) continue;
73  if ( m_beamPart.find(line) != m_beamPart.end() ) continue;
74 
75 
76  transportProton(gpart);
77 
78  }
79  addPartToHepMC(const_cast<HepMC::GenEvent*>(evt));
80 }
82 {
83  edm::LogInfo("ProtonTransport")<<"Starting proton transport using TOTEM method\n";
84  ApplyBeamCorrection(const_cast<HepMC::GenParticle*>(in_trk));
85 
86  const HepMC::GenVertex* in_pos = in_trk->production_vertex();
87  const HepMC::FourVector in_mom = in_trk->momentum();
88 //
89 // ATTENTION: HepMC uses mm, vertex config of CMS uses cm and SimTransport uses mm
90 //
91  double in_position[3] = {(in_pos->position().x()-fVtxMeanX*cm) / meter+fBeamXatIP*mm/meter,
92  (in_pos->position().y()-fVtxMeanY*cm) / meter+fBeamYatIP*mm/meter,
93  (in_pos->position().z()-fVtxMeanZ*cm) / meter}; // move to z=0 if configured below
94 
95 // (bApplyZShift) -- The TOTEM parameterization requires the shift to z=0
96  double fCrossingAngle = (in_mom.z()>0)?fCrossingAngle_45:-fCrossingAngle_56;
97  in_position[0] = in_position[0]+(tan((long double)fCrossingAngle*urad)-((long double)in_mom.x())/((long double)in_mom.z()))*in_position[2];
98  in_position[1] = in_position[1]-((long double)in_mom.y())/((long double)in_mom.z())*in_position[2];
99  in_position[2] = 0.;
100 //
101  double in_momentum[3] = {in_mom.x(), in_mom.y() , in_mom.z()};
102  double out_position[3];
103  double out_momentum[3];
104  edm::LogInfo("ProtonTransport") << "before transport ->" <<
105  " position: " << in_position[0] << ", " << in_position[1] << ", " << in_position[2] <<
106  " momentum: " << in_momentum[0] << ", " << in_momentum[1] << ", " << in_momentum[2];
107 
108  LHCOpticsApproximator* approximator_= nullptr;
109  if (in_mom.z()>0) {approximator_ = m_aprox_ip_150_l; m_Zin_ = m_model_ip_150_l_zmin; m_Zout_ = m_model_ip_150_l_zmax;}
111 
112  bool invert_beam_coord_system=true; // it doesn't matter the option here, it is hard coded as TRUE inside LHCOpticsApproximator!
113 
114  bool tracked = approximator_->Transport_m_GeV(in_position, in_momentum, out_position, out_momentum, invert_beam_coord_system, m_Zout_ - m_Zin_);
115 
116  if (!tracked) return false;
117 
118  edm::LogInfo("ProtonTransport") << "after transport -> " <<
119  "position: " << out_position[0] << ", " << out_position[1] << ", " << out_position[2] <<
120  "momentum: " << out_momentum[0] << ", " << out_momentum[1] << ", " << out_momentum[2];
121 
122  if (out_position[0] * out_position[0] + out_position[1] * out_position[1] >
124  edm::LogInfo("ProtonTransport") << "Proton ouside beampipe";
125  edm::LogInfo("ProtonTransport") << "===== END Transport " << "====================";
126  return false;
127  }
128 
129  TVector3 out_pos(out_position[0] * meter, out_position[1] * meter, out_position[2] * meter);
130  TVector3 out_mom(out_momentum[0], out_momentum[1], out_momentum[2]);
131  edm::LogInfo("TotemRPProtonTransportModel") << "output -> " << "position: ";out_pos.Print();
132  edm::LogInfo("TotemRPProtonTransportModel") << " momentum: ";out_mom.Print();
133  double px = -out_momentum[0];
134  double py = out_momentum[1]; // this need to be checked again, since it seems an invertion is occuring in the prop.
135  double pz = out_momentum[2];
136  double e = sqrt(px*px+py*py+pz*pz+ProtonMassSQ);
137  TLorentzVector p_out(px,py,pz,e);
138  double x1_ctpps = -out_position[0]*meter; // Totem parameterization uses meter, one need it in millimeter
139  double y1_ctpps = -out_position[1]*meter;
140 
141  unsigned int line = in_trk->barcode();
142 
143  if(m_verbosity) LogDebug("ProtonTransportEventProcessing") <<
144  "ProtonTransport:filterPPS: barcode = " << line << " x= "<< x1_ctpps <<" y= " << y1_ctpps;
145 
146  m_beamPart[line] = p_out;
147  m_xAtTrPoint[line] = x1_ctpps;
148  m_yAtTrPoint[line] = y1_ctpps;
149  return true;
150 }
152 {
153  edm::FileInPath fileName(rootfile.c_str());
154  TFile *f = TFile::Open(fileName.fullPath().c_str(), "read");
155  if (!f) {
156  edm::LogError("TotemRPProtonTransportSetup") << "File " << fileName << " not found. Exiting.";
157  return nullptr;
158  }
159  edm::LogInfo("TotemRPProtonTransportSetup") << "Root file opened, pointer:" << f;
160 
161  // read parametrization
162  LHCOpticsApproximator* aprox = (LHCOpticsApproximator *) f->Get(m_model_name.c_str());
163  f->Close();
164  return aprox;
165 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
double fPPSRegionStart_45
void ApplyBeamCorrection(HepMC::GenParticle *p)
edm::ParameterSet m_parameters
double m_model_ip_150_l_zmax
double m_model_ip_150_l_zmin
std::map< unsigned int, TLorentzVector > m_beamPart
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
TransportMode MODE
std::map< unsigned int, double > m_yAtTrPoint
static const double urad
~TotemTransport() override
std::string m_model_ip_150_r_name
double fCrossingAngle_45
LHCOpticsApproximator * m_aprox_ip_150_l
std::map< unsigned int, double > m_xAtTrPoint
double fCrossingAngle_56
std::string m_model_ip_150_l_name
T sqrt(T t)
Definition: SSEVec.h:18
double fPPSRegionStart_56
std::string m_model_root_file_l
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double m_model_ip_150_r_zmin
double f[11][100]
Class finds the parametrisation of MADX proton transport and transports the protons according to it 5...
bool transportProton(const HepMC::GenParticle *)
void addPartToHepMC(HepMC::GenEvent *)
std::string m_model_root_file_r
double m_beampipe_aperture_radius
LHCOpticsApproximator * ReadParameterization(const std::string &, const std::string &)
HLT enums.
LHCOpticsApproximator * m_aprox_ip_150_r
void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine) override
static const double ProtonMassSQ
double m_model_ip_150_r_zmax
CLHEP::HepRandomEngine * engine