CMS 3D CMS Logo

TotemTransport.cc
Go to the documentation of this file.
3 #include <CLHEP/Units/GlobalSystemOfUnits.h>
4 #include "TLorentzVector.h"
5 #include "TFile.h"
6 
7 #include <cmath>
8 
10  : BaseProtonTransport(iConfig),
11  m_model_ip_150_r_name_(iConfig.getParameter<std::string>("Model_IP_150_R_Name")),
12  m_model_ip_150_l_name_(iConfig.getParameter<std::string>("Model_IP_150_L_Name")),
13  m_beampipe_aperture_radius_(iConfig.getParameter<double>("BeampipeApertureRadius")) {
15  std::string s1 = iConfig.getParameter<std::string>("Beam1Filename");
16  std::string s2 = iConfig.getParameter<std::string>("Beam2Filename");
17  setBeamFileNames(s1, s2);
18  double cax45 = iConfig.getParameter<double>("halfCrossingAngleXSector45");
19  double cax56 = iConfig.getParameter<double>("halfCrossingAngleXSector56");
20  setCrossingAngles(cax45, cax56, 0.0, 0.0);
21  double stx = iConfig.getParameter<double>("BeamDivergenceX");
22  double sty = iConfig.getParameter<double>("BeamDivergenceY");
23  double sx = iConfig.getParameter<double>("BeamSigmaX");
24  double sy = iConfig.getParameter<double>("BeamSigmaY");
25  double se = iConfig.getParameter<double>("BeamEnergyDispersion");
26  setBeamParameters(stx, sty, sx, sy, se);
27 
28  if (fPPSRegionStart_56_ > 0)
29  fPPSRegionStart_56_ *= -1; // make sure sector 56 has negative position, as TOTEM convention
30 
31  edm::LogVerbatim("TotemTransport")
32  << "=============================================================================\n"
33  << " Bulding LHC Proton transporter based on TOTEM model\n"
34  << "=============================================================================\n";
35 
38 
39  if (m_aprox_ip_150_r_ == nullptr || m_aprox_ip_150_l_ == nullptr) {
40  edm::LogError("TotemTransport") << "Parameterisation " << m_model_ip_150_r_name_ << " or " << m_model_ip_150_l_name_
41  << " missing in file. Cannot proceed. ";
42  throw edm::Exception(edm::errors::Configuration) << "TotemTransport is not properly initialized";
43  }
44  edm::LogVerbatim("TotemTransport") << "Parameterizations read from file, pointers:" << m_aprox_ip_150_r_ << " "
45  << m_aprox_ip_150_l_ << " ";
46 }
48 //
49 // this method is the same for all propagator, but since transportProton is different for each derived class
50 // it needes to be overriden
51 //
53  const edm::EventSetup& iSetup,
54  CLHEP::HepRandomEngine* engine) {
55  clear();
56  engine_ = engine; // the engine needs to be updated for each event
57 
58  HepMC::GenEvent evt(*ievt);
59 
60  for (HepMC::GenEvent::particle_const_iterator eventParticle = evt.particles_begin();
61  eventParticle != evt.particles_end();
62  ++eventParticle) {
63  if (!((*eventParticle)->status() == 1 && (*eventParticle)->pdg_id() == 2212))
64  continue;
65 
66  if (!(fabs((*eventParticle)->momentum().eta()) > etaCut_ && fabs((*eventParticle)->momentum().pz()) > momentumCut_))
67  continue; // discard protons outside kinematic acceptance
68 
69  unsigned int line = (*eventParticle)->barcode();
70  HepMC::GenParticle* gpart = (*eventParticle);
71  if (gpart->pdg_id() != 2212)
72  continue; // only transport stable protons
73  if (gpart->status() != 1)
74  continue;
75  if (m_beamPart.find(line) != m_beamPart.end()) // assures this protons has not been already propagated
76  continue;
77 
78  transportProton(gpart);
79  }
80 }
81 //
82 //
83 // here comes the real thing
84 //
85 //
87  //
88  edm::LogVerbatim("TotemTransport") << "Starting proton transport using TOTEM method\n";
89  //
90  ApplyBeamCorrection(in_trk);
91 
92  const HepMC::GenVertex* in_pos = in_trk->production_vertex();
93  const HepMC::FourVector in_mom = in_trk->momentum();
94  //
95  // ATTENTION: HepMC uses mm, vertex config of CMS uses cm and SimTransport uses mm
96  //
97  double in_position[3] = {in_pos->position().x(), in_pos->position().y(), in_pos->position().z()}; //in LHC ref. frame
98 
99  double crossingAngleX = (in_mom.z() > 0) ? fCrossingAngleX_45_ : fCrossingAngleX_56_;
100 
101  // Move the position to z=0. Do it in the CMS ref frame. Totem parameterization does the rotation internatlly
102  in_position[0] =
103  in_position[0] - in_position[2] * (in_mom.x() / in_mom.z() - crossingAngleX * urad); // in CMS ref. frame
104  in_position[1] = in_position[1] - in_position[2] * (in_mom.y() / (in_mom.z()));
105  in_position[2] = 0.;
106  double in_momentum[3] = {in_mom.x(), in_mom.y(), in_mom.z()};
107  double out_position[3];
108  double out_momentum[3];
109  edm::LogVerbatim("TotemTransport") << "before transport ->"
110  << " position: " << in_position[0] << ", " << in_position[1] << ", "
111  << in_position[2] << " momentum: " << in_momentum[0] << ", " << in_momentum[1]
112  << ", " << in_momentum[2];
113 
114  LHCOpticsApproximator* approximator = nullptr;
115  double zin;
116  double zout;
117  if (in_mom.z() > 0) {
118  approximator = m_aprox_ip_150_l_;
119  zin = 0.0; // Totem propagations assumes the starting point at 0 (zero)
120  zout = fPPSRegionStart_45_;
121  } else {
122  approximator = m_aprox_ip_150_r_;
123  zin = 0.0; // Totem propagations assumes the starting point at 0 (zero)
124  zout = fPPSRegionStart_56_;
125  }
126 
127  bool invert_beam_coord_system =
128  true; // it doesn't matter the option here, it is hard coded as TRUE inside LHCOpticsApproximator!
129 
130  bool tracked = approximator->Transport_m_GeV(
131  in_position, in_momentum, out_position, out_momentum, invert_beam_coord_system, zout - zin);
132 
133  if (!tracked)
134  return false;
135 
136  edm::LogVerbatim("TotemTransport") << "after transport -> "
137  << "position: " << out_position[0] << ", " << out_position[1] << ", "
138  << out_position[2] << "momentum: " << out_momentum[0] << ", " << out_momentum[1]
139  << ", " << out_momentum[2];
140 
141  if (out_position[0] * out_position[0] + out_position[1] * out_position[1] >
143  edm::LogVerbatim("TotemTransport") << "Proton ouside beampipe\n"
144  << "===== END Transport "
145  << "====================";
146  return false;
147  }
148 
149  TVector3 out_pos(out_position[0] * meter, out_position[1] * meter, out_position[2] * meter);
150  TVector3 out_mom(out_momentum[0], out_momentum[1], out_momentum[2]);
151 
152  if (verbosity_) {
153  LogDebug("TotemTransport") << "output -> position: ";
154  out_pos.Print();
155  LogDebug("TotemTransport") << " momentum: ";
156  out_mom.Print();
157  }
158 
159  double px = -out_momentum[0]; // calculates px by means of TH_X, which is in the LHC ref. frame.
160  double py = out_momentum[1]; // this need to be checked again, since it seems an invertion is occuring in the prop.
161  double pz =
162  out_momentum[2]; // totem calculates output pz already in the CMS ref. frame, it doesn't need to be converted
163  double e = sqrt(px * px + py * py + pz * pz + ProtonMassSQ);
164  TLorentzVector p_out(px, py, pz, e);
165  double x1_ctpps = -out_position[0] * meter; // Totem parameterization uses meter, one need it in millimeter
166  double y1_ctpps = out_position[1] * meter;
167 
168  unsigned int line = in_trk->barcode();
169 
170  if (verbosity_)
171  LogDebug("TotemTransport") << "TotemTransport:filterPPS: barcode = " << line << " x= " << x1_ctpps
172  << " y= " << y1_ctpps;
173 
174  m_beamPart[line] = p_out;
175  m_xAtTrPoint[line] = x1_ctpps;
176  m_yAtTrPoint[line] = y1_ctpps;
177  return true;
178 }
179 //
181  const std::string& rootfile) {
183  TFile* f = TFile::Open(fileName.fullPath().c_str(), "read");
184  if (!f) {
185  edm::LogError("TotemTransport") << "File " << fileName << " not found. Exiting.";
186  return nullptr;
187  }
188  edm::LogVerbatim("TotemTransport") << "Root file opened, pointer:" << f;
189 
190  // read parametrization
191  LHCOpticsApproximator* aprox = (LHCOpticsApproximator*)f->Get(m_model_name.c_str());
192  f->Close();
193  return aprox;
194 }
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string m_model_ip_150_l_name_
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
static const double urad
~TotemTransport() override
Log< level::Error, false > LogError
void setBeamParameters(double stx, double sty, double sx, double sy, double se)
LHCOpticsApproximator * m_aprox_ip_150_r_
TotemTransport(const edm::ParameterSet &ps)
T sqrt(T t)
Definition: SSEVec.h:19
std::string m_model_ip_150_r_name_
double m_beampipe_aperture_radius_
double f[11][100]
Class finds the parametrisation of MADX proton transport and transports the protons according to it 5...
LHCOpticsApproximator * m_aprox_ip_150_l_
CLHEP::HepRandomEngine * engine_
void setCrossingAngles(double cx45, double cx56, double cy45, double cy56)
void setBeamFileNames(const std::string &nam1, const std::string &nam2)
bool transportProton(HepMC::GenParticle *)
std::map< unsigned int, double > m_xAtTrPoint
void ApplyBeamCorrection(HepMC::GenParticle *p)
std::map< unsigned int, TLorentzVector > m_beamPart
LHCOpticsApproximator * ReadParameterization(const std::string &, const std::string &)
void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine) override
static const double ProtonMassSQ
std::map< unsigned int, double > m_yAtTrPoint
#define LogDebug(id)