CMS 3D CMS Logo

ProtonTransport.cc
Go to the documentation of this file.
3 #include <CLHEP/Random/RandGauss.h>
4 #include <CLHEP/Units/GlobalSystemOfUnits.h>
5 
6 
10 {
11  m_beamPart.clear(); m_xAtTrPoint.clear(); m_yAtTrPoint.clear();
12 };
13 
15 {
16  NEvent++;
17  m_CorrespondenceMap.clear();
18 
19  int direction=0;
20  HepMC::GenParticle * gpart;
21 
22  unsigned int line;
23 
24  for( auto const& it : m_beamPart ) {
25  line = (it ).first;
26  gpart = evt->barcode_to_particle( line );
27 
28  direction=(gpart->momentum().pz()>0)?1:-1;
29 
30  double ddd=(direction>0)?fPPSRegionStart_45:fabs(fPPSRegionStart_56); // Totem uses negative Z for sector 56 while Hector uses always positive distance
31 
32  double time = ( ddd*meter - gpart->production_vertex()->position().z()*mm ); // mm
33 
34 //
35 // ATTENTION: at this point, the vertex at PPS is already in mm
36 //
37  if(ddd == 0.) continue;
38  if(m_verbosity) {
39  LogDebug("ProtonTransportEventProcessing") <<"ProtonTransport:: x= "<< (*(m_xAtTrPoint.find(line))).second<< "\n"
40  <<"ProtonTransport:: y= "<< (*(m_yAtTrPoint.find(line))).second<< "\n"
41  <<"ProtonTransport:: z= "<< ddd * direction*m_to_mm << "\n"
42  <<"ProtonTransport:: t= "<< time;
43  }
44  TLorentzVector const& p_out = (it).second;
45 
46  HepMC::GenVertex * vert = new HepMC::GenVertex(
47  HepMC::FourVector( (*(m_xAtTrPoint.find(line))).second,
48  (*(m_yAtTrPoint.find(line))).second,
49  ddd * direction *m_to_mm, time + time*0.001 ) );
50 
51  gpart->set_status( 2 );
52  vert->add_particle_in( gpart );
53  vert->add_particle_out( new HepMC::GenParticle( HepMC::FourVector(p_out.Px(),p_out.Py(),p_out.Pz(),p_out.E()), gpart->pdg_id(), 1, gpart->flow() )) ;
54  evt->add_vertex( vert );
55 
56  int ingoing = (*vert->particles_in_const_begin())->barcode();
57  int outgoing = (*vert->particles_out_const_begin())->barcode();
58 
59  LHCTransportLink theLink(ingoing,outgoing);
60  if (m_verbosity) LogDebug("ProtonTransportEventProcessing") << "ProtonTransport:addPartToHepMC: LHCTransportLink " << theLink;
61  m_CorrespondenceMap.push_back(theLink);
62  }
63 }
65 {
66  TLorentzVector p_out;
67  p_out.SetPx(p->momentum().px());
68  p_out.SetPy(p->momentum().py());
69  p_out.SetPz(p->momentum().pz());
70  p_out.SetE(p->momentum().e());
71  ApplyBeamCorrection(p_out);
72  p->set_momentum(HepMC::FourVector(p_out.Px(),p_out.Py(),p_out.Pz(),p_out.E()));
73 }
74 void ProtonTransport::ApplyBeamCorrection(TLorentzVector& p_out)
75 {
76  double theta = p_out.Theta();
77  double thetax = atan(p_out.Px()/fabs(p_out.Pz()));
78  double thetay = atan(p_out.Py()/fabs(p_out.Pz()));
79  double energy = p_out.E();
80  double urad = 1e-6;
81 
82  int direction = (p_out.Pz()>0)?1:-1;
83 
84  if (p_out.Pz()<0) theta=TMath::Pi()-theta;
85 
86  if (MODE==TransportMode::TOTEM) thetax+=(p_out.Pz()>0)?fCrossingAngle_45*urad:fCrossingAngle_56*urad;
87 
88  double dtheta_x = (double)CLHEP::RandGauss::shoot(engine,0.,m_sigmaSTX);
89  double dtheta_y = (double)CLHEP::RandGauss::shoot(engine,0.,m_sigmaSTY);
90  double denergy = (double)CLHEP::RandGauss::shoot(engine,0.,m_sig_E);
91 
92  double s_theta = sqrt(pow(thetax+dtheta_x*urad,2)+pow(thetay+dtheta_y*urad,2));
93  double s_phi = atan2(thetay+dtheta_y*urad,thetax+dtheta_x*urad);
94  energy+=denergy;
95  double p = sqrt(pow(energy,2)-ProtonMassSQ);
96 
97  p_out.SetPx((double)p*sin(s_theta)*cos(s_phi));
98  p_out.SetPy((double)p*sin(s_theta)*sin(s_phi));
99  p_out.SetPz((double)p*(cos(s_theta))*direction);
100  p_out.SetE(energy);
101 }
#define LogDebug(id)
const double Pi
double fPPSRegionStart_45
void ApplyBeamCorrection(HepMC::GenParticle *p)
std::map< unsigned int, TLorentzVector > m_beamPart
virtual ~ProtonTransport()
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
TransportMode MODE
std::map< unsigned int, double > m_yAtTrPoint
Geom::Theta< T > theta() const
std::vector< LHCTransportLink > m_CorrespondenceMap
static const double urad
double fCrossingAngle_45
std::map< unsigned int, double > m_xAtTrPoint
double fCrossingAngle_56
U second(std::pair< T, U > const &p)
T sqrt(T t)
Definition: SSEVec.h:18
double fPPSRegionStart_56
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void addPartToHepMC(HepMC::GenEvent *)
static const double m_to_mm
static const double ProtonMassSQ
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
CLHEP::HepRandomEngine * engine