CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #include <memory>
9 
10 #include <string>
11 
13 
15  : BaseProtonTransport(iConfig),
16  m_beamline45(nullptr),
17  m_beamline56(nullptr),
18  beamParametersToken_(iC.esConsumes()),
19  beamspotToken_(iC.esConsumes()) {
20  // Create LHC beam line
21 
22  MODE = TransportMode::HECTOR; // defines the MODE for the transport
23  beam1Filename_ = iConfig.getParameter<std::string>("Beam1Filename");
24  beam2Filename_ = iConfig.getParameter<std::string>("Beam2Filename");
25  fCrossingAngleX_45 = iConfig.getParameter<double>("halfCrossingAngleXSector45");
26  fCrossingAngleX_56 = iConfig.getParameter<double>("halfCrossingAngleXSector56");
27  fCrossingAngleY_45 = iConfig.getParameter<double>("halfCrossingAngleYSector45");
28  fCrossingAngleY_56 = iConfig.getParameter<double>("halfCrossingAngleYSector56");
29  m_sigmaSTX = iConfig.getParameter<double>("BeamDivergenceX");
30  m_sigmaSTY = iConfig.getParameter<double>("BeamDivergenceY");
31  m_sigmaSX = iConfig.getParameter<double>("BeamSigmaX");
32  m_sigmaSY = iConfig.getParameter<double>("BeamSigmaY");
33  m_sig_E = iConfig.getParameter<double>("BeamEnergyDispersion");
34 
35  //PPS
36  edm::LogInfo("ProtonTransport") << "=============================================================================\n"
37  << " Bulding LHC Proton transporter based on HECTOR model\n"
38  << "=============================================================================\n";
39  setBeamLine();
40 }
41 //
42 // this method is the same for all propagator, but since transportProton is different for each derived class
43 // it needes to be overriden
44 //
46  const edm::EventSetup& iSetup,
47  CLHEP::HepRandomEngine* _engine) {
48  this->clear();
49 
50  engine_ = _engine; // the engine needs to be updated for each event
51 
52  beamspot_ = &iSetup.getData(beamspotToken_);
54 
55  for (HepMC::GenEvent::particle_const_iterator eventParticle = evt->particles_begin();
56  eventParticle != evt->particles_end();
57  ++eventParticle) {
58  if (!((*eventParticle)->status() == 1 && (*eventParticle)->pdg_id() == 2212))
59  continue;
60 
61  if (!(fabs((*eventParticle)->momentum().eta()) > etaCut_ && fabs((*eventParticle)->momentum().pz()) > momentumCut_))
62  continue; // discard protons outside kinematic acceptance
63 
64  unsigned int line = (*eventParticle)->barcode();
65  HepMC::GenParticle* gpart = (*eventParticle);
66 
67  if (gpart->pdg_id() != 2212)
68  continue; // only transport stable protons
69  if (gpart->status() != 1)
70  continue;
71  if (m_beamPart.find(line) != m_beamPart.end())
72  continue; // assures this protons has not been already propagated
73 
74  transportProton(gpart);
75  }
76 }
78  edm::LogInfo("ProtonTransport") << "Starting proton transport using HECTOR method\n";
79 
80  double px, py, pz, e;
81  unsigned int line = (gpart)->barcode();
82 
83  double mass = gpart->generatedMass();
84  double charge = 1.;
85 
86  // remove the CMS vertex shift
87  double vtxXoffset_;
88  double vtxYoffset_;
89  double vtxZoffset_;
91  vtxXoffset_ = beamParameters_->getVtxOffsetX45() * cm_to_mm;
92  vtxYoffset_ = beamParameters_->getVtxOffsetY45() * cm_to_mm;
93  vtxZoffset_ = beamParameters_->getVtxOffsetZ45() * cm_to_mm;
94  } else {
95  vtxXoffset_ = beamspot_->GetX() * cm_to_mm;
96  vtxYoffset_ = beamspot_->GetY() * cm_to_mm;
97  vtxZoffset_ = beamspot_->GetZ() * cm_to_mm;
98  }
99  vtxZoffset_ *= 1; // to avoid compilation error, should be used in the future
100  // Momentum in LHC ref. frame
101  px = -gpart->momentum().px();
102  py = gpart->momentum().py();
103  pz = -gpart->momentum().pz();
104  e = gpart->momentum().e();
105 
106  int direction = (pz > 0) ? 1 : -1; // in relation to LHC ref frame
107 
108  double XforPosition = -gpart->production_vertex()->position().x(); //mm in the ref. frame of LHC
109  double YforPosition = gpart->production_vertex()->position().y(); //mm
110  double ZforPosition = -gpart->production_vertex()->position().z(); //mm
111  double fCrossingAngleX = (pz < 0) ? fCrossingAngleX_45 : fCrossingAngleX_56;
112  double fCrossingAngleY = (pz < 0) ? fCrossingAngleY_45 : fCrossingAngleY_56;
113  //
114  H_BeamParticle h_p(mass, charge);
115  h_p.set4Momentum(px, py, pz, e);
116  //
117  // shift the starting position of the track to Z=0 if configured so (all the variables below are still in cm)
118  XforPosition = XforPosition - ZforPosition * (px / pz + fCrossingAngleX * urad); // theta ~=tan(theta)
119  YforPosition = YforPosition - ZforPosition * (py / pz + fCrossingAngleY * urad);
120  XforPosition -= (-vtxXoffset_); // X was already in the LHC ref. frame
121  YforPosition -= vtxYoffset_;
122  ZforPosition = 0.;
123 
124  // set position, but do not invert the coordinate for the angles (TX,TY) because it is done by set4Momentum
125  h_p.setPosition(XforPosition * mm_to_um, YforPosition * mm_to_um, h_p.getTX(), h_p.getTY(), 0.);
126 
127  bool is_stop;
128  float x1_ctpps;
129  float y1_ctpps;
130 
131  H_BeamLine* _beamline = nullptr;
132  double _targetZ = 0;
133  switch (direction) {
134  case 1:
135  _beamline = &*m_beamline56; // negative side propagation
136  _targetZ = fPPSRegionStart_56;
137  break;
138  case -1:
139  _beamline = &*m_beamline45;
140  _targetZ = fPPSRegionStart_45;
141  break;
142  }
143  // insert protection for NULL beamlines here
144  h_p.computePath(&*_beamline);
145  is_stop = h_p.stopped(&*_beamline);
146  if (verbosity_)
147  LogDebug("HectorTransportEventProcessing")
148  << "HectorTransport:filterPPS: barcode = " << line << " is_stop= " << is_stop;
149  if (is_stop) {
150  return false;
151  }
152  //
153  //propagating
154  //
155  h_p.propagate(_targetZ);
156  x1_ctpps = h_p.getX();
157  y1_ctpps = h_p.getY();
158 
159  double thx = h_p.getTX();
160  double thy = h_p.getTY();
161 
163  H_BeamParticle p_beam(mass, charge);
164  p_beam.set4Momentum(0., 0., beamMomentum_, beamEnergy_);
165  p_beam.setPosition(0., 0., fCrossingAngleX * urad, fCrossingAngleY * urad, 0.);
166  p_beam.computePath(&*_beamline);
167  thx -= p_beam.getTX();
168  thy -= p_beam.getTY();
169  x1_ctpps -= p_beam.getX();
170  y1_ctpps -= p_beam.getY();
171  edm::LogInfo("HectorTransportEventProcessing")
172  << "Shifting the hit relative to beam : X = " << p_beam.getX() << "(mm) Y = " << p_beam.getY() << "(mm)";
173  }
174 
175  double partP = sqrt(pow(h_p.getE(), 2) - ProtonMassSQ);
176  double theta = sqrt(thx * thx + thy * thy) * urad;
177 
178  // copy the kinematic changing to CMS ref. frame, only the negative Pz needs to be changed
179  TLorentzVector p_out(-tan(thx * urad) * partP * cos(theta),
180  tan(thy * urad) * partP * cos(theta),
181  -direction * partP * cos(theta),
182  h_p.getE());
183 
184  m_beamPart[line] = p_out;
185  m_xAtTrPoint[line] = -x1_ctpps * um_to_mm; // move to CMS ref. frame
186  m_yAtTrPoint[line] = y1_ctpps * um_to_mm;
187  if (verbosity_)
188  LogDebug("HectorTransportEventProcessing")
189  << "HectorTransport:filterPPS: barcode = " << line << " x= " << x1_ctpps << " y= " << y1_ctpps;
190 
191  return true;
192 }
196 
197  // construct beam line for PPS (forward 1 backward 2):
198  if (fPPSBeamLineLength_ > 0.) {
199  m_beamline45 = std::make_unique<H_BeamLine>(-1, fPPSBeamLineLength_ + 0.1);
200  m_beamline45->fill(b2.fullPath(), 1, "IP5");
201  m_beamline56 = std::make_unique<H_BeamLine>(1, fPPSBeamLineLength_ + 0.1);
202  m_beamline56->fill(b1.fullPath(), 1, "IP5");
203  } else {
204  if (verbosity_)
205  LogDebug("HectorTransportSetup") << "HectorTransport: WARNING: lengthctpps= " << fPPSBeamLineLength_;
206  return false;
207  }
208  if (verbosity_) {
209  edm::LogInfo("HectorTransportSetup") << "===================================================================\n"
210  << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n"
211  << " * * \n"
212  << " * --<--<-- A fast simulator --<--<-- * \n"
213  << " * | --<--<-- of particle --<--<-- * \n"
214  << " * ----HECTOR----< * \n"
215  << " * | -->-->-- transport through-->-->-- * \n"
216  << " * -->-->-- generic beamlines -->-->-- * \n"
217  << " * * \n"
218  << " * JINST 2:P09005 (2007) * \n"
219  << " * X Rouby, J de Favereau, K Piotrzkowski (CP3) * \n"
220  << " * http://www.fynu.ucl.ac.be/hector.html * \n"
221  << " * * \n"
222  << " * Center for Cosmology, Particle Physics and Phenomenology * \n"
223  << " * Universite catholique de Louvain * \n"
224  << " * Louvain-la-Neuve, Belgium * \n"
225  << " * * \n"
226  << " * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n"
227  << " HectorTransport configuration: \n"
228  << " Beam line length = " << fPPSBeamLineLength_ << "\n"
229  << " PPS Region Start 44 = " << fPPSRegionStart_45 << "\n"
230  << " PPS Region Start 56 = " << fPPSRegionStart_56 << "\n"
231  << "===================================================================\n";
232  }
233  if (verbosity_) {
234  edm::LogInfo("HectorTransportSetup") << "====================================================================\n"
235  << " Forward beam line elements \n";
236  m_beamline45->showElements();
237  edm::LogInfo("HectorTransportSetup") << "====================================================================\n"
238  << " Backward beam line elements \n";
239  m_beamline56->showElements();
240  }
241  return true;
242 }
double GetY() const
get Y beam position
~HectorTransport() override
Geom::Theta< T > theta() const
static const double urad
double getVtxOffsetX45() const
bool transportProton(const HepMC::GenParticle *)
propagate the particles through a beamline to PPS
bool getData(T &iHolder) const
Definition: EventSetup.h:128
edm::ESGetToken< CTPPSBeamParameters, CTPPSBeamParametersRcd > beamParametersToken_
const CTPPSBeamParameters * beamParameters_
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
double GetZ() const
get Z beam position
const BeamSpotObjects * beamspot_
CLHEP::HepRandomEngine * engine_
static const double um_to_mm
HectorTransport(const edm::ParameterSet &ps, edm::ConsumesCollector iC)
Log< level::Info, false > LogInfo
double GetX() const
get X beam position
void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::map< unsigned int, double > m_xAtTrPoint
double getVtxOffsetZ45() const
static const double mm_to_um
std::map< unsigned int, TLorentzVector > m_beamPart
double getVtxOffsetY45() const
static constexpr double fPPSBeamLineLength_
std::unique_ptr< H_BeamLine > m_beamline56
std::unique_ptr< H_BeamLine > m_beamline45
static constexpr float b2
edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcd > beamspotToken_
static const double ProtonMassSQ
std::map< unsigned int, double > m_yAtTrPoint
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
static constexpr float b1
static const double cm_to_mm
#define LogDebug(id)