CMS 3D CMS Logo

BaseProtonTransport.cc
Go to the documentation of this file.
4 #include <CLHEP/Random/RandGauss.h>
5 #include <CLHEP/Units/GlobalSystemOfUnits.h>
6 
8  : verbosity_(iConfig.getParameter<bool>("Verbosity")),
9  bApplyZShift_(iConfig.getParameter<bool>("ApplyZShift")),
10  useBeamPositionFromLHCInfo_(iConfig.getParameter<bool>("useBeamPositionFromLHCInfo")),
11  produceHitsRelativeToBeam_(iConfig.getParameter<bool>("produceHitsRelativeToBeam")),
12  fPPSRegionStart_45_(iConfig.getParameter<double>("PPSRegionStart_45")),
13  fPPSRegionStart_56_(iConfig.getParameter<double>("PPSRegionStart_56")),
14  etaCut_(iConfig.getParameter<double>("EtaCut")),
15  momentumCut_(iConfig.getParameter<double>("MomentumCut")),
16  beamEnergy_(iConfig.getParameter<double>("BeamEnergy")) {
18 }
19 
21 
23  TLorentzVector p_out;
24  p_out.SetPx(p->momentum().px());
25  p_out.SetPy(p->momentum().py());
26  p_out.SetPz(p->momentum().pz());
27  p_out.SetE(p->momentum().e());
28  ApplyBeamCorrection(p_out);
29  p->set_momentum(HepMC::FourVector(p_out.Px(), p_out.Py(), p_out.Pz(), p_out.E()));
30 }
31 
32 void BaseProtonTransport::ApplyBeamCorrection(TLorentzVector& p_out) {
33  double thetax = atan(p_out.Px() / fabs(p_out.Pz()));
34  double thetay = atan(p_out.Py() / fabs(p_out.Pz()));
35  double energy = p_out.E();
36  double urad = 1e-6;
37 
38  int direction = (p_out.Pz() > 0) ? 1 : -1;
39 
41  thetax += (p_out.Pz() > 0) ? fCrossingAngleX_45_ * urad : fCrossingAngleX_56_ * urad;
42 
43  double dtheta_x = (m_sigmaSTX <= 0.0) ? 0.0 : CLHEP::RandGauss::shoot(engine_, 0., m_sigmaSTX);
44  double dtheta_y = (m_sigmaSTY <= 0.0) ? 0.0 : CLHEP::RandGauss::shoot(engine_, 0., m_sigmaSTY);
45  double denergy = (m_sig_E <= 0.0) ? 0.0 : CLHEP::RandGauss::shoot(engine_, 0., m_sig_E);
46 
47  double s_theta = std::sqrt(pow(thetax + dtheta_x * urad, 2) + std::pow(thetay + dtheta_y * urad, 2));
48  double s_phi = std::atan2(thetay + dtheta_y * urad, thetax + dtheta_x * urad);
49  energy += denergy;
50  double p = std::sqrt(std::pow(energy, 2) - ProtonMassSQ);
51  double sint = std::sin(s_theta);
52 
53  p_out.SetPx(p * sint * std::cos(s_phi));
54  p_out.SetPy(p * sint * std::sin(s_phi));
55  p_out.SetPz(p * std::cos(s_theta) * direction);
56  p_out.SetE(energy);
57 }
58 
60  m_CorrespondenceMap.clear();
61 
62  int direction = 0;
63  HepMC::GenParticle* gpart;
64 
65  unsigned int line;
66 
67  for (auto const& it : m_beamPart) {
68  line = (it).first;
69  gpart = in_evt->barcode_to_particle(line);
70 
71  direction = (gpart->momentum().pz() > 0) ? 1 : -1;
72 
73  // Totem uses negative Z for sector 56 while Hector uses always positive distance
74  double ddd = (direction > 0) ? fPPSRegionStart_45_ : fabs(fPPSRegionStart_56_);
75 
76  double time = (ddd * meter - gpart->production_vertex()->position().z() * mm); // mm
77 
78  //
79  // ATTENTION: at this point, the vertex at PPS is already in mm
80  //
81  if (ddd == 0.)
82  continue;
83 
84  if (verbosity_) {
85  LogDebug("BaseProtonTransportEventProcessing")
86  << "BaseProtonTransport:: x= " << (*(m_xAtTrPoint.find(line))).second << "\n"
87  << "BaseProtonTransport:: y= " << (*(m_yAtTrPoint.find(line))).second << "\n"
88  << "BaseProtonTransport:: z= " << ddd * direction * m_to_mm << "\n"
89  << "BaseProtonTransport:: t= " << time;
90  }
91  TLorentzVector const& p_out = (it).second;
92 
93  HepMC::GenVertex* vert = new HepMC::GenVertex(HepMC::FourVector((*(m_xAtTrPoint.find(line))).second,
94  (*(m_yAtTrPoint.find(line))).second,
95  ddd * direction * m_to_mm,
96  time + time * 0.001));
97 
98  vert->add_particle_out(new HepMC::GenParticle(
99  HepMC::FourVector(p_out.Px(), p_out.Py(), p_out.Pz(), p_out.E()), gpart->pdg_id(), 1, gpart->flow()));
100  evt->add_vertex(vert);
101 
102  int ingoing = 0; //do not attach the incoming proton to this vertex to avoid duplicating data
103  int outgoing = (*vert->particles_out_const_begin())->barcode();
104 
105  LHCTransportLink theLink(ingoing, outgoing);
106  if (verbosity_)
107  LogDebug("BaseProtonTransportEventProcessing")
108  << "BaseProtonTransport:addPartToHepMC: LHCTransportLink " << theLink;
109  m_CorrespondenceMap.push_back(theLink);
110  }
111 }
113  m_beamPart.clear();
114  m_xAtTrPoint.clear();
115  m_yAtTrPoint.clear();
116  m_CorrespondenceMap.clear();
117 }
BaseProtonTransport(const edm::ParameterSet &iConfig)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
constexpr int pow(int x)
Definition: conifer.h:24
static const double urad
U second(std::pair< T, U > const &p)
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
CLHEP::HepRandomEngine * engine_
std::map< unsigned int, double > m_xAtTrPoint
void ApplyBeamCorrection(HepMC::GenParticle *p)
static const double m_to_mm
std::map< unsigned int, TLorentzVector > m_beamPart
static const double ProtonMassSQ
std::map< unsigned int, double > m_yAtTrPoint
std::vector< LHCTransportLink > m_CorrespondenceMap
void addPartToHepMC(const HepMC::GenEvent *, HepMC::GenEvent *)
#define LogDebug(id)