CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OpticalFunctionsTransport.cc
Go to the documentation of this file.
3 
5  : BaseProtonTransport(iConfig),
6  lhcInfoToken_(iC.esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoLabel")))),
7  beamParametersToken_(iC.esConsumes()),
8  opticsToken_(iC.esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("opticsLabel")))),
9  beamspotToken_(iC.esConsumes()),
10  useEmpiricalApertures_(iConfig.getParameter<bool>("useEmpiricalApertures")),
11  empiricalAperture45_xi0_int_(iConfig.getParameter<double>("empiricalAperture45_xi0_int")),
12  empiricalAperture45_xi0_slp_(iConfig.getParameter<double>("empiricalAperture45_xi0_slp")),
13  empiricalAperture45_a_int_(iConfig.getParameter<double>("empiricalAperture45_a_int")),
14  empiricalAperture45_a_slp_(iConfig.getParameter<double>("empiricalAperture45_a_slp")),
15  empiricalAperture56_xi0_int_(iConfig.getParameter<double>("empiricalAperture56_xi0_int")),
16  empiricalAperture56_xi0_slp_(iConfig.getParameter<double>("empiricalAperture56_xi0_slp")),
17  empiricalAperture56_a_int_(iConfig.getParameter<double>("empiricalAperture56_a_int")),
18  empiricalAperture56_a_slp_(iConfig.getParameter<double>("empiricalAperture56_a_slp")) {
20 }
22  const edm::EventSetup& iSetup,
23  CLHEP::HepRandomEngine* _engine) {
24  this->clear();
25 
26  lhcInfo_ = &iSetup.getData(lhcInfoToken_);
29  beamspot_ = &iSetup.getData(beamspotToken_);
30 
31  // Choose the optical function corresponding to the first station ono each side (it is in lhc ref. frame)
32  optFunctionId45_ = 0;
33  optFunctionId56_ = 0;
34  for (const auto& ofp : (*opticalFunctions_)) {
35  if (ofp.second.getScoringPlaneZ() < 0) {
36  if (optFunctionId45_ == 0)
37  optFunctionId45_ = ofp.first;
38  if (opticalFunctions_->at(optFunctionId45_).getScoringPlaneZ() < ofp.second.getScoringPlaneZ())
39  optFunctionId45_ = ofp.first;
40  }
41  if (ofp.second.getScoringPlaneZ() > 0) {
42  if (optFunctionId56_ == 0)
43  optFunctionId56_ = ofp.first;
44  if (opticalFunctions_->at(optFunctionId56_).getScoringPlaneZ() > ofp.second.getScoringPlaneZ())
45  optFunctionId56_ = ofp.first;
46  }
47  }
48  //
49  engine_ = _engine; // the engine needs to be updated for each event
50 
51  for (HepMC::GenEvent::particle_const_iterator eventParticle = evt->particles_begin();
52  eventParticle != evt->particles_end();
53  ++eventParticle) {
54  if (!((*eventParticle)->status() == 1 && (*eventParticle)->pdg_id() == 2212))
55  continue;
56 
57  if (!(fabs((*eventParticle)->momentum().eta()) > etaCut_ && fabs((*eventParticle)->momentum().pz()) > momentumCut_))
58  continue; // discard protons outside kinematic acceptance
59 
60  unsigned int line = (*eventParticle)->barcode();
61  HepMC::GenParticle* gpart = (*eventParticle);
62  if (gpart->pdg_id() != 2212)
63  continue; // only transport stable protons
64  if (gpart->status() != 1)
65  continue;
66  if (m_beamPart.find(line) != m_beamPart.end()) // assures this protons has not been already propagated
67  continue;
68 
69  transportProton(gpart);
70  }
71 }
72 
74  const HepMC::FourVector& vtx_cms = in_trk->production_vertex()->position(); // in mm
75  const HepMC::FourVector& mom_cms = in_trk->momentum();
76 
77  // transformation to LHC/TOTEM convention
78  HepMC::FourVector vtx_lhc(-vtx_cms.x(), vtx_cms.y(), -vtx_cms.z(), vtx_cms.t());
79  HepMC::FourVector mom_lhc(-mom_cms.x(), mom_cms.y(), -mom_cms.z(), mom_cms.t());
80 
81  // determine the LHC arm and related parameters
82  double urad = 1.e-6;
83  double beamMomentum = 0.;
84  double xangle = 0.;
85  double empiricalAperture_xi0_int, empiricalAperture_xi0_slp;
86  double empiricalAperture_a_int, empiricalAperture_a_slp;
87  unsigned int optFunctionId_;
88  // get the beam position at the IP in mm and in the LHC ref. frame
89  double vtxXoffset_;
90  double vtxYoffset_;
91  double vtxZoffset_;
93  vtxXoffset_ = -beamParameters_->getVtxOffsetX45() * cm_to_mm;
94  vtxYoffset_ = beamParameters_->getVtxOffsetY45() * cm_to_mm;
95  vtxZoffset_ = -beamParameters_->getVtxOffsetZ45() * cm_to_mm;
96  } else {
97  vtxXoffset_ = -beamspot_->GetX() * cm_to_mm;
98  vtxYoffset_ = beamspot_->GetY() * cm_to_mm;
99  vtxZoffset_ = -beamspot_->GetZ() * cm_to_mm;
100  }
101  vtxZoffset_ *= 1.0; // just to avoid compilation error, should be used in the future
102  //
103  if (mom_lhc.z() < 0) // sector 45
104  {
105  optFunctionId_ = optFunctionId45_;
106  beamMomentum = beamParameters_->getBeamMom45();
107  xangle = beamParameters_->getHalfXangleX45();
108  empiricalAperture_xi0_int = empiricalAperture45_xi0_int_;
109  empiricalAperture_xi0_slp = empiricalAperture45_xi0_slp_;
110  empiricalAperture_a_int = empiricalAperture45_a_int_;
111  empiricalAperture_a_slp = empiricalAperture45_a_slp_;
112  } else { // sector 56
113  optFunctionId_ = optFunctionId56_;
114  beamMomentum = beamParameters_->getBeamMom56();
115  xangle = beamParameters_->getHalfXangleX56();
116  empiricalAperture_xi0_int = empiricalAperture56_xi0_int_;
117  empiricalAperture_xi0_slp = empiricalAperture56_xi0_slp_;
118  empiricalAperture_a_int = empiricalAperture56_a_int_;
119  empiricalAperture_a_slp = empiricalAperture56_a_slp_;
120  }
121  if (xangle > 1.0)
122  xangle *= urad;
123  // calculate kinematics for optics parametrisation, avoid the aproximation for small angles xangle -> tan(xangle)
124  const double p = mom_lhc.rho();
125  const double xi = 1. - p / beamMomentum;
126  const double th_x_phys = mom_lhc.x() / abs(mom_lhc.z()) - tan(xangle); //"-" in the LHC ref. frame
127  const double th_y_phys = mom_lhc.y() / abs(mom_lhc.z());
128  const double vtx_lhc_eff_x = vtx_lhc.x() - vtx_lhc.z() * (mom_lhc.x() / mom_lhc.z() + tan(xangle)) - (vtxXoffset_);
129  const double vtx_lhc_eff_y = vtx_lhc.y() - vtx_lhc.z() * (mom_lhc.y() / mom_lhc.z()) - (vtxYoffset_);
130 
131  if (verbosity_) {
132  LogDebug("OpticalFunctionsTransport")
133  << "simu: xi = " << xi << ", th_x_phys = " << th_x_phys << ", th_y_phys = " << th_y_phys
134  << ", vtx_lhc_eff_x = " << vtx_lhc_eff_x << ", vtx_lhc_eff_y = " << vtx_lhc_eff_y << std::endl;
135  }
136 
137  // check empirical aperture
139  const auto& xangle =
141  const double xi_th = (empiricalAperture_xi0_int + xangle * empiricalAperture_xi0_slp) +
142  (empiricalAperture_a_int + xangle * empiricalAperture_a_slp) * th_x_phys;
143 
144  if (xi > xi_th) {
145  if (verbosity_) {
146  LogDebug("OpticalFunctionsTransport") << "stop because of empirical appertures";
147  }
148  return false;
149  }
150  }
151 
152  // transport the proton into pot/scoring plane
153  auto ofp = opticalFunctions_->at(optFunctionId_);
154  CTPPSDetId rpId(optFunctionId_);
155  const unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
156 
157  if (verbosity_)
158  LogDebug("OpticalFunctionsTransport") << " RP " << rpDecId << std::endl;
159 
160  // transport proton
162  vtx_lhc_eff_x * 1E-1, th_x_phys, vtx_lhc_eff_y * 1E-1, th_y_phys, xi}; // conversions: mm -> cm
163 
165  ofp.transport(k_in, k_out, true);
166 
167  // Original code uses mm, but CMS uses cm, so keep it in cm
168  double b_x = k_out.x * 1E1, b_y = k_out.y * 1E1; // conversions: cm -> mm
169  double a_x = k_out.th_x, a_y = k_out.th_y;
170 
171  // if needed, subtract beam position and angle
173  // determine beam position
174  LHCInterpolatedOpticalFunctionsSet::Kinematics k_be_in = {0., -tan(xangle), 0., 0., 0.};
176  ofp.transport(k_be_in, k_be_out, true);
177 
178  a_x -= k_be_out.th_x;
179  a_y -= k_be_out.th_y;
180  b_x -= k_be_out.x * 1E1;
181  b_y -= k_be_out.y * 1E1; // conversions: cm -> mm
182  }
183 
184  const double z_scoringPlane = ofp.getScoringPlaneZ() * 1E1; // conversion: cm --> mm
185 
186  if (verbosity_) {
187  LogDebug("OpticalFunctionsTransport")
188  << " proton transported: a_x = " << a_x << " rad, a_y = " << a_y << " rad, b_x = " << b_x
189  << " mm, b_y = " << b_y << " mm, z = " << z_scoringPlane << " mm" << std::endl;
190  }
191  //
192  // Project the track back to the starting of PPS region
193  b_x -= (abs(z_scoringPlane) - (double)((z_scoringPlane < 0) ? fPPSRegionStart_45 : fPPSRegionStart_56) * 1e3) *
194  a_x; // z_scoringPlane is in mm
195  b_y -= (abs(z_scoringPlane) - (double)((z_scoringPlane < 0) ? fPPSRegionStart_45 : fPPSRegionStart_56) * 1e3) * a_y;
196 
197  unsigned int line = in_trk->barcode();
198  double px = -p * a_x;
199  double py = p * a_y;
200  double pz = std::copysign(sqrt(p * p - px * px - py * py), mom_cms.z());
201  double e = sqrt(px * px + py * py + pz * pz + ProtonMassSQ);
202  TLorentzVector p_out(px, py, pz, e);
203  m_beamPart[line] = p_out;
204  m_xAtTrPoint[line] = -b_x;
205  m_yAtTrPoint[line] = b_y;
206  return true;
207 }
uint32_t station() const
Definition: CTPPSDetId.h:58
double GetY() const
get Y beam position
edm::ESGetToken< LHCInfo, LHCInfoRcd > lhcInfoToken_
OpticalFunctionsTransport(const edm::ParameterSet &ps, edm::ConsumesCollector iC)
edm::ESGetToken< LHCInterpolatedOpticalFunctionsSetCollection, CTPPSInterpolatedOpticsRcd > opticsToken_
static const double urad
double getVtxOffsetX45() const
void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine) override
bool getData(T &iHolder) const
Definition: EventSetup.h:128
float const crossingAngle() const
Definition: LHCInfo.cc:182
T sqrt(T t)
Definition: SSEVec.h:19
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double getBeamMom56() const
double GetZ() const
get Z beam position
edm::ESGetToken< CTPPSBeamParameters, CTPPSBeamParametersRcd > beamParametersToken_
double getHalfXangleX56() const
const LHCInterpolatedOpticalFunctionsSetCollection * opticalFunctions_
uint32_t arm() const
Definition: CTPPSDetId.h:51
const BeamSpotObjects * beamspot_
CLHEP::HepRandomEngine * engine_
double GetX() const
get X beam position
std::map< unsigned int, double > m_xAtTrPoint
edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcd > beamspotToken_
double getVtxOffsetZ45() const
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
std::map< unsigned int, TLorentzVector > m_beamPart
double getVtxOffsetY45() const
double getBeamMom45() const
const CTPPSBeamParameters * beamParameters_
bool transportProton(const HepMC::GenParticle *)
static const double ProtonMassSQ
std::map< unsigned int, double > m_yAtTrPoint
double getHalfXangleX45() const
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static const double cm_to_mm
uint32_t rp() const
Definition: CTPPSDetId.h:65
#define LogDebug(id)