CMS 3D CMS Logo

HectorTransport.cc
Go to the documentation of this file.
3 #include <CLHEP/Random/RandGauss.h>
4 #include "TLorentzVector.h"
5 //Hector headers
6 #include "H_BeamLine.h"
7 #include "H_BeamParticle.h"
8 
10 
12  // Create LHC beam line
13  MODE = TransportMode::HECTOR; // defines the MODE for the transport
15  edm::ParameterSet hector_par = param.getParameter<edm::ParameterSet>("PPSHector");
16 
17  m_f_ctpps_f = (float)hector_par.getParameter<double>("PPSf");
18  m_b_ctpps_b = (float)hector_par.getParameter<double>("PPSb");
19  fCrossingAngle_56 = hector_par.getParameter<double>("CrossingAngleBeam1");
20  fCrossingAngle_45 = hector_par.getParameter<double>("CrossingAngleBeam2");
21  fBeamEnergy = hector_par.getParameter<double>("BeamEnergy"); // beam energy in GeV
22  m_fEtacut = hector_par.getParameter<double>("EtaCutForHector");
23  m_fMomentumMin = hector_par.getParameter<double>("MomentumMin");
24  fBeamMomentum = sqrt(fBeamEnergy * fBeamEnergy - PPSTools::ProtonMassSQ);
25 
26  // User definitons
27  m_lengthctpps = hector_par.getParameter<double>("BeamLineLengthPPS");
28 
29  m_beam1filename = hector_par.getParameter<string>("Beam1");
30  m_beam2filename = hector_par.getParameter<string>("Beam2");
31  fVtxMeanX = param.getParameter<double>("VtxMeanX");
32  fVtxMeanY = param.getParameter<double>("VtxMeanY");
33  fVtxMeanZ = param.getParameter<double>("VtxMeanZ");
34  m_sigmaSTX = hector_par.getParameter<double>("sigmaSTX");
35  m_sigmaSTY = hector_par.getParameter<double>("sigmaSTY");
36  m_sigmaSX = hector_par.getParameter<double>("sigmaSX");
37  m_sigmaSY = hector_par.getParameter<double>("sigmaSY");
38  m_sig_E = hector_par.getParameter<double>("sigmaEnergy");
39  fBeamXatIP = hector_par.getUntrackedParameter<double>("BeamXatIP", fVtxMeanX);
40  fBeamYatIP = hector_par.getUntrackedParameter<double>("BeamYatIP", fVtxMeanY);
41  bApplyZShift = hector_par.getParameter<bool>("ApplyZShift");
42  //PPS
43  edm::LogInfo("ProtonTransport") << "=============================================================================\n"
44  << " Bulding LHC Proton transporter based on HECTOR model\n"
45  << "=============================================================================\n";
46  setBeamLine();
49 }
52  const edm::EventSetup& iSetup,
53  CLHEP::HepRandomEngine* _engine) {
54  engine = _engine;
55  iSetup.getData(m_pdt);
56  genProtonsLoop(ev, iSetup);
57  addPartToHepMC(const_cast<HepMC::GenEvent*>(ev));
58 }
60  edm::LogInfo("ProtonTransport") << "Starting proton transport using HECTOR method\n";
61 
62  double px, py, pz, e;
63  unsigned int line = (gpart)->barcode();
64 
65  double mass = gpart->generatedMass();
66  double charge = 1.;
67 
68  px = gpart->momentum().px();
69  py = gpart->momentum().py();
70  pz = gpart->momentum().pz();
71  e = gpart->momentum().e();
72 
73  e = sqrt(pow(mass, 2) + pow(px, 2) + pow(py, 2) + pow(pz, 2));
74 
75  int direction = (pz > 0) ? 1 : -1;
76 
77  // Apply Beam and Crossing Angle Corrections
78  TLorentzVector p_out(px, py, pz, e);
80  "LAB",
81  {fCrossingAngle_56, //Beam1
82  fCrossingAngle_45, //Beam2
84  fBeamEnergy});
85 
86  ApplyBeamCorrection(p_out);
87 
88  // from mm to cm
89  double XforPosition = gpart->production_vertex()->position().x() / cm; //cm
90  double YforPosition = gpart->production_vertex()->position().y() / cm; //cm
91  double ZforPosition = gpart->production_vertex()->position().z() / cm; //cm
92 
93  H_BeamParticle h_p(mass, charge);
94  h_p.set4Momentum(-direction * p_out.Px(), p_out.Py(), fabs(p_out.Pz()), p_out.E());
95  // shift the beam position to the given beam position at IP (in cm)
96  XforPosition = (XforPosition - fVtxMeanX) + fBeamXatIP * mm_to_cm;
97  YforPosition = (YforPosition - fVtxMeanY) + fBeamYatIP * mm_to_cm;
98  //ZforPosition stays the same, move the closed orbit only in the X,Y plane
99  //
100  // shift the starting position of the track to Z=0 if configured so (all the variables below are still in cm)
101  if (bApplyZShift) {
102  double fCrossingAngle = (p_out.Pz() > 0) ? fCrossingAngle_45 : -fCrossingAngle_56;
103  XforPosition = XforPosition +
104  (tan((long double)fCrossingAngle * urad) - ((long double)p_out.Px()) / ((long double)p_out.Pz())) *
105  ZforPosition;
106  YforPosition = YforPosition - ((long double)p_out.Py()) / ((long double)p_out.Pz()) * ZforPosition;
107  ZforPosition = 0.;
108  }
109 
110  //
111  // set position, but do not invert the coordinate for the angles (TX,TY) because it is done by set4Momentum
112  h_p.setPosition(-direction * XforPosition * cm_to_um,
113  YforPosition * cm_to_um,
114  h_p.getTX(),
115  h_p.getTY(),
116  -direction * ZforPosition * cm_to_m);
117  bool is_stop;
118  float x1_ctpps;
119  float y1_ctpps;
120 
121  H_BeamLine* _beamline = nullptr;
122  double _targetZ = 0;
123  switch (direction) {
124  case -1:
125  _beamline = &*m_beamline56; // negative side propagation
126  _targetZ = m_b_ctpps_b;
127  break;
128  case 1:
129  _beamline = &*m_beamline45;
130  _targetZ = m_f_ctpps_f;
131  break;
132  }
133  // insert protection for NULL beamlines here
134  h_p.computePath(&*_beamline);
135  is_stop = h_p.stopped(&*_beamline);
136  if (m_verbosity)
137  LogDebug("HectorTransportEventProcessing")
138  << "HectorTransport:filterPPS: barcode = " << line << " is_stop= " << is_stop;
139  if (is_stop) {
140  return false;
141  }
142  //
143  //propagating
144  //
145  h_p.propagate(_targetZ);
146 
147  p_out = PPSTools::HectorParticle2LorentzVector(h_p, direction);
148 
149  p_out.SetPx(direction * p_out.Px());
150  x1_ctpps = direction * h_p.getX() * um_to_mm;
151  y1_ctpps = h_p.getY() * um_to_mm;
152 
153  if (m_verbosity)
154  LogDebug("HectorTransportEventProcessing")
155  << "HectorTransport:filterPPS: barcode = " << line << " x= " << x1_ctpps << " y= " << y1_ctpps;
156 
157  m_beamPart[line] = p_out;
158  m_xAtTrPoint[line] = x1_ctpps;
159  m_yAtTrPoint[line] = y1_ctpps;
160  return true;
161 }
163  /*
164  Loop over genVertex looking for transportable protons
165 */
166  unsigned int line;
167 
168  for (HepMC::GenEvent::particle_const_iterator eventParticle = evt->particles_begin();
169  eventParticle != evt->particles_end();
170  ++eventParticle) {
171  if (!((*eventParticle)->status() == 1 && (*eventParticle)->pdg_id() == 2212))
172  continue;
173  if (!(fabs((*eventParticle)->momentum().eta()) > m_fEtacut &&
174  fabs((*eventParticle)->momentum().pz()) > m_fMomentumMin))
175  continue;
176  line = (*eventParticle)->barcode();
177 
178  if (m_beamPart.find(line) != m_beamPart.end())
179  continue;
180 
181  HepMC::GenParticle* gpart = (*eventParticle);
182 
183  transportProton(gpart);
184  }
185 }
187  m_beamline45 = nullptr;
188  m_beamline56 = nullptr;
189  edm::FileInPath b1(m_beam1filename.c_str());
190  edm::FileInPath b2(m_beam2filename.c_str());
191  if (m_verbosity) {
192  edm::LogInfo("HectorTransportSetup") << "===================================================================\n"
193  << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n"
194  << " * * \n"
195  << " * --<--<-- A fast simulator --<--<-- * \n"
196  << " * | --<--<-- of particle --<--<-- * \n"
197  << " * ----HECTOR----< * \n"
198  << " * | -->-->-- transport through-->-->-- * \n"
199  << " * -->-->-- generic beamlines -->-->-- * \n"
200  << " * * \n"
201  << " * JINST 2:P09005 (2007) * \n"
202  << " * X Rouby, J de Favereau, K Piotrzkowski (CP3) * \n"
203  << " * http://www.fynu.ucl.ac.be/hector.html * \n"
204  << " * * \n"
205  << " * Center for Cosmology, Particle Physics and Phenomenology * \n"
206  << " * Universite catholique de Louvain * \n"
207  << " * Louvain-la-Neuve, Belgium * \n"
208  << " * * \n"
209  << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n"
210  << " HectorTransport configuration: \n"
211  << " lengthctpps = " << m_lengthctpps << "\n"
212  << " m_f_ctpps_f = " << m_f_ctpps_f << "\n"
213  << " m_b_ctpps_b = " << m_b_ctpps_b << "\n"
214  << "===================================================================\n";
215  }
216 
217  // construct beam line for PPS (forward 1 backward 2):
218  if (m_lengthctpps > 0.) {
219  m_beamline45 = std::unique_ptr<H_BeamLine>(new H_BeamLine(-1, m_lengthctpps + 0.1)); // (direction, length)
220  m_beamline45->fill(b2.fullPath(), 1, "IP5");
221  m_beamline56 = std::unique_ptr<H_BeamLine>(new H_BeamLine(1, m_lengthctpps + 0.1)); //
222  m_beamline56->fill(b1.fullPath(), 1, "IP5");
223  } else {
224  if (m_verbosity)
225  LogDebug("HectorTransportSetup") << "HectorTransport: WARNING: lengthctpps= " << m_lengthctpps;
226  return false;
227  }
228  if (m_verbosity) {
229  edm::LogInfo("HectorTransportSetup") << "====================================================================\n"
230  << " Forward beam line elements \n";
231  m_beamline45->showElements();
232  edm::LogInfo("HectorTransportSetup") << "====================================================================\n"
233  << " Backward beam line elements \n";
234  m_beamline56->showElements();
235  }
236 
237  return true;
238 }
#define LogDebug(id)
void LorentzBoost(H_BeamParticle &h_p, int dir, const std::string &frame, FullBeamInfo const &bi)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
TLorentzVector HectorParticle2LorentzVector(H_BeamParticle hp, int)
Definition: PPSUtilities.cc:6
double fPPSRegionStart_45
~HectorTransport() override
void ApplyBeamCorrection(HepMC::GenParticle *p)
void genProtonsLoop(const HepMC::GenEvent *, const edm::EventSetup &)
Clears BeamParticle, prepares PPSHector for a next Aperture check or/and a next event.
std::map< unsigned int, TLorentzVector > m_beamPart
TransportMode MODE
std::map< unsigned int, double > m_yAtTrPoint
static const double urad
bool ev
static const double cm_to_um
std::string m_beam2filename
double fCrossingAngle_45
bool transportProton(const HepMC::GenParticle *)
propagate the particles through a beamline to PPS
std::map< unsigned int, double > m_xAtTrPoint
double fCrossingAngle_56
bool getData(T &iHolder) const
Definition: EventSetup.h:113
void process(const HepMC::GenEvent *, const edm::EventSetup &, CLHEP::HepRandomEngine *) override
T sqrt(T t)
Definition: SSEVec.h:19
double fPPSRegionStart_56
edm::ESHandle< ParticleDataTable > m_pdt
const double ProtonMassSQ
Definition: PPSUtilities.h:31
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static const double um_to_mm
void addPartToHepMC(HepMC::GenEvent *)
std::string m_beam1filename
static const double mm_to_cm
static const double cm_to_m
std::unique_ptr< H_BeamLine > m_beamline56
std::unique_ptr< H_BeamLine > m_beamline45
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
CLHEP::HepRandomEngine * engine