CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BaseProtonTransport.cc
Go to the documentation of this file.
4 #include <CLHEP/Random/RandGauss.h>
5 #include <CLHEP/Units/GlobalSystemOfUnits.h>
6 #include <cctype>
7 
9  : verbosity_(iConfig.getParameter<bool>("Verbosity")),
10  bApplyZShift(iConfig.getParameter<bool>("ApplyZShift")),
11  useBeamPositionFromLHCInfo_(iConfig.getParameter<bool>("useBeamPositionFromLHCInfo")),
12  produceHitsRelativeToBeam_(iConfig.getParameter<bool>("produceHitsRelativeToBeam")),
13  fPPSRegionStart_45(iConfig.getParameter<double>("PPSRegionStart_45")),
14  fPPSRegionStart_56(iConfig.getParameter<double>("PPSRegionStart_56")),
15  beamEnergy_(iConfig.getParameter<double>("BeamEnergy")),
16  etaCut_(iConfig.getParameter<double>("EtaCut")),
17  momentumCut_(iConfig.getParameter<double>("MomentumCut")) {
19 }
21  TLorentzVector p_out;
22  p_out.SetPx(p->momentum().px());
23  p_out.SetPy(p->momentum().py());
24  p_out.SetPz(p->momentum().pz());
25  p_out.SetE(p->momentum().e());
26  ApplyBeamCorrection(p_out);
27  p->set_momentum(HepMC::FourVector(p_out.Px(), p_out.Py(), p_out.Pz(), p_out.E()));
28 }
29 void BaseProtonTransport::ApplyBeamCorrection(TLorentzVector& p_out) {
30  double theta = p_out.Theta();
31  double thetax = atan(p_out.Px() / fabs(p_out.Pz()));
32  double thetay = atan(p_out.Py() / fabs(p_out.Pz()));
33  double energy = p_out.E();
34  double urad = 1e-6;
35 
36  int direction = (p_out.Pz() > 0) ? 1 : -1;
37 
38  if (p_out.Pz() < 0)
39  theta = TMath::Pi() - theta;
40 
42  thetax += (p_out.Pz() > 0) ? fCrossingAngleX_45 * urad : fCrossingAngleX_56 * urad;
43 
44  double dtheta_x = (double)CLHEP::RandGauss::shoot(engine_, 0., m_sigmaSTX);
45  double dtheta_y = (double)CLHEP::RandGauss::shoot(engine_, 0., m_sigmaSTY);
46  double denergy = (double)CLHEP::RandGauss::shoot(engine_, 0., m_sig_E);
47 
48  double s_theta = sqrt(pow(thetax + dtheta_x * urad, 2) + pow(thetay + dtheta_y * urad, 2));
49  double s_phi = atan2(thetay + dtheta_y * urad, thetax + dtheta_x * urad);
50  energy += denergy;
51  double p = sqrt(pow(energy, 2) - ProtonMassSQ);
52 
53  p_out.SetPx((double)p * sin(s_theta) * cos(s_phi));
54  p_out.SetPy((double)p * sin(s_theta) * sin(s_phi));
55  p_out.SetPz((double)p * (cos(s_theta)) * direction);
56  p_out.SetE(energy);
57 }
59  NEvent++;
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 }
const double Pi
BaseProtonTransport(const edm::ParameterSet &iConfig)
void setBeamEnergy(double e)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
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
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
void addPartToHepMC(const HepMC::GenEvent *, HepMC::GenEvent *)
#define LogDebug(id)