CMS 3D CMS Logo

TotemTransport.cc
Go to the documentation of this file.
3 #include <CLHEP/Units/GlobalSystemOfUnits.h>
4 #include <CLHEP/Random/RandGauss.h>
5 #include "TLorentzVector.h"
6 #include "TFile.h"
7 
8 #include <cmath>
9 
11  : BaseProtonTransport(iConfig),
12  m_model_ip_150_r_name(iConfig.getParameter<std::string>("Model_IP_150_R_Name")),
13  m_model_ip_150_l_name(iConfig.getParameter<std::string>("Model_IP_150_L_Name")),
14  m_beampipe_aperture_radius(iConfig.getParameter<double>("BeampipeApertureRadius")) {
16  beam1Filename_ = iConfig.getParameter<std::string>("Beam1Filename");
17  beam2Filename_ = iConfig.getParameter<std::string>("Beam2Filename");
18  fCrossingAngleX_45 = iConfig.getParameter<double>("halfCrossingAngleSector45");
19  fCrossingAngleX_56 = iConfig.getParameter<double>("halfCrossingAngleSector56");
20  beamEnergy_ = iConfig.getParameter<double>("BeamEnergy");
21  m_sigmaSTX = iConfig.getParameter<double>("BeamDivergenceX");
22  m_sigmaSTY = iConfig.getParameter<double>("BeamDivergenceY");
23  m_sigmaSX = iConfig.getParameter<double>("BeamSigmaX");
24  m_sigmaSY = iConfig.getParameter<double>("BeamSigmaY");
25  m_sig_E = iConfig.getParameter<double>("BeamEnergyDispersion");
26  fBeamXatIP = iConfig.getUntrackedParameter<double>("BeamXatIP", 0.);
27  fBeamYatIP = iConfig.getUntrackedParameter<double>("BeamYatIP", 0.);
28 
29  if (fPPSRegionStart_56 > 0)
30  fPPSRegionStart_56 *= -1; // make sure sector 56 has negative position, as TOTEM convention
31 
32  edm::LogInfo("TotemTransport") << "=============================================================================\n"
33  << " Bulding LHC Proton transporter based on TOTEM model\n"
34  << "=============================================================================\n";
35 
38 
39  if (m_aprox_ip_150_r == nullptr || m_aprox_ip_150_l == nullptr) {
40  edm::LogError("TotemTransport") << "Parameterisation " << m_model_ip_150_r_name << " or " << m_model_ip_150_l_name
41  << " missing in file. Cannot proceed. ";
42  exit(1);
43  }
44  edm::LogInfo("TotemTransport") << "Parameterizations read from file, pointers:" << m_aprox_ip_150_r << " "
45  << m_aprox_ip_150_l << " ";
46 }
47 //
48 // this method is the same for all propagator, but since transportProton is different for each derived class
49 // it needes to be overriden
50 //
52  const edm::EventSetup& iSetup,
53  CLHEP::HepRandomEngine* _engine) {
54  this->clear();
55 
56  engine_ = _engine; // the engine needs to be updated for each event
57 
58  for (HepMC::GenEvent::particle_const_iterator eventParticle = evt->particles_begin();
59  eventParticle != evt->particles_end();
60  ++eventParticle) {
61  if (!((*eventParticle)->status() == 1 && (*eventParticle)->pdg_id() == 2212))
62  continue;
63 
64  if (!(fabs((*eventParticle)->momentum().eta()) > etaCut_ && fabs((*eventParticle)->momentum().pz()) > momentumCut_))
65  continue; // discard protons outside kinematic acceptance
66 
67  unsigned int line = (*eventParticle)->barcode();
68  HepMC::GenParticle* gpart = (*eventParticle);
69  if (gpart->pdg_id() != 2212)
70  continue; // only transport stable protons
71  if (gpart->status() != 1)
72  continue;
73  if (m_beamPart.find(line) != m_beamPart.end()) // assures this protons has not been already propagated
74  continue;
75 
76  transportProton(gpart);
77  }
78 }
79 //
80 //
81 // here comes the real thing
82 //
83 //
85  //
86  //
87  edm::LogInfo("TotemTransport") << "Starting proton transport using TOTEM method\n";
88  //
89  ApplyBeamCorrection(const_cast<HepMC::GenParticle*>(in_trk));
90 
91  const HepMC::GenVertex* in_pos = in_trk->production_vertex();
92  const HepMC::FourVector in_mom = in_trk->momentum();
93  //
94  // ATTENTION: HepMC uses mm, vertex config of CMS uses cm and SimTransport uses mm
95  //
96  double in_position[3] = {in_pos->position().x(), in_pos->position().y(), in_pos->position().z()}; //in LHC ref. frame
97 
98  double fCrossingAngleX = (in_mom.z() > 0) ? fCrossingAngleX_45 : fCrossingAngleX_56;
99 
100  // Move the position to z=0. Do it in the CMS ref frame. Totem parameterization does the rotation internatlly
101  in_position[0] =
102  in_position[0] - in_position[2] * (in_mom.x() / in_mom.z() - fCrossingAngleX * urad); // in CMS ref. frame
103  in_position[1] = in_position[1] - in_position[2] * (in_mom.y() / (in_mom.z()));
104  in_position[2] = 0.;
105  double in_momentum[3] = {in_mom.x(), in_mom.y(), in_mom.z()};
106  double out_position[3];
107  double out_momentum[3];
108  edm::LogInfo("TotemTransport") << "before transport ->"
109  << " position: " << in_position[0] << ", " << in_position[1] << ", " << in_position[2]
110  << " momentum: " << in_momentum[0] << ", " << in_momentum[1] << ", " << in_momentum[2];
111 
112  LHCOpticsApproximator* approximator_ = nullptr;
113  double m_Zin_;
114  double m_Zout_;
115  if (in_mom.z() > 0) {
116  approximator_ = m_aprox_ip_150_l;
117  m_Zin_ = 0.0; // Totem propagations assumes the starting point at 0 (zero)
118  m_Zout_ = fPPSRegionStart_45;
119  } else {
120  approximator_ = m_aprox_ip_150_r;
121  m_Zin_ = 0.0; // Totem propagations assumes the starting point at 0 (zero)
122  m_Zout_ = fPPSRegionStart_56;
123  }
124 
125  bool invert_beam_coord_system =
126  true; // it doesn't matter the option here, it is hard coded as TRUE inside LHCOpticsApproximator!
127 
128  bool tracked = approximator_->Transport_m_GeV(
129  in_position, in_momentum, out_position, out_momentum, invert_beam_coord_system, m_Zout_ - m_Zin_);
130 
131  if (!tracked)
132  return false;
133 
134  edm::LogInfo("TotemTransport") << "after transport -> "
135  << "position: " << out_position[0] << ", " << out_position[1] << ", "
136  << out_position[2] << "momentum: " << out_momentum[0] << ", " << out_momentum[1]
137  << ", " << out_momentum[2];
138 
139  if (out_position[0] * out_position[0] + out_position[1] * out_position[1] >
141  edm::LogInfo("TotemTransport") << "Proton ouside beampipe";
142  edm::LogInfo("TotemTransport") << "===== END Transport "
143  << "====================";
144  return false;
145  }
146 
147  TVector3 out_pos(out_position[0] * meter, out_position[1] * meter, out_position[2] * meter);
148  TVector3 out_mom(out_momentum[0], out_momentum[1], out_momentum[2]);
149 
150  if (verbosity_) {
151  LogDebug("TotemTransport") << "output -> position: ";
152  out_pos.Print();
153  LogDebug("TotemTransport") << " momentum: ";
154  out_mom.Print();
155  }
156 
157  double px = -out_momentum[0]; // tote calculates px by means of TH_X, which is in the LHC ref. frame.
158  double py = out_momentum[1]; // this need to be checked again, since it seems an invertion is occuring in the prop.
159  double pz =
160  out_momentum[2]; // totem calculates output pz already in the CMS ref. frame, it doesn't need to be converted
161  double e = sqrt(px * px + py * py + pz * pz + ProtonMassSQ);
162  TLorentzVector p_out(px, py, pz, e);
163  double x1_ctpps = -out_position[0] * meter; // Totem parameterization uses meter, one need it in millimeter
164  double y1_ctpps = out_position[1] * meter;
165 
166  unsigned int line = in_trk->barcode();
167 
168  if (verbosity_)
169  LogDebug("TotemTransport") << "TotemTransport:filterPPS: barcode = " << line << " x= " << x1_ctpps
170  << " y= " << y1_ctpps;
171 
172  m_beamPart[line] = p_out;
173  m_xAtTrPoint[line] = x1_ctpps;
174  m_yAtTrPoint[line] = y1_ctpps;
175  return true;
176 }
177 //
179  const std::string& rootfile) {
181  TFile* f = TFile::Open(fileName.fullPath().c_str(), "read");
182  if (!f) {
183  edm::LogError("TotemTransport") << "File " << fileName << " not found. Exiting.";
184  return nullptr;
185  }
186  edm::LogInfo("TotemTransport") << "Root file opened, pointer:" << f;
187 
188  // read parametrization
189  LHCOpticsApproximator* aprox = (LHCOpticsApproximator*)f->Get(m_model_name.c_str());
190  f->Close();
191  return aprox;
192 }
BaseProtonTransport::beam2Filename_
std::string beam2Filename_
Definition: BaseProtonTransport.h:55
TotemTransport.h
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
BaseProtonTransport::m_sigmaSTY
double m_sigmaSTY
Definition: BaseProtonTransport.h:70
BaseProtonTransport::clear
void clear()
Definition: BaseProtonTransport.cc:109
BaseProtonTransport::MODE
TransportMode MODE
Definition: BaseProtonTransport.h:42
BaseProtonTransport::ApplyBeamCorrection
void ApplyBeamCorrection(HepMC::GenParticle *p)
Definition: BaseProtonTransport.cc:17
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
TotemTransport::m_model_ip_150_r_name
std::string m_model_ip_150_r_name
Definition: TotemTransport.h:37
BaseProtonTransport::verbosity_
bool verbosity_
Definition: BaseProtonTransport.h:51
TotemTransport::m_aprox_ip_150_l
LHCOpticsApproximator * m_aprox_ip_150_l
Definition: TotemTransport.h:35
BaseProtonTransport::fPPSRegionStart_45
double fPPSRegionStart_45
Definition: BaseProtonTransport.h:57
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
BaseProtonTransport::momentumCut_
double momentumCut_
Definition: BaseProtonTransport.h:67
BaseProtonTransport::m_sig_E
double m_sig_E
Definition: BaseProtonTransport.h:73
BaseProtonTransport::m_sigmaSY
double m_sigmaSY
Definition: BaseProtonTransport.h:72
BaseProtonTransport::fPPSRegionStart_56
double fPPSRegionStart_56
Definition: BaseProtonTransport.h:58
BaseProtonTransport::beam1Filename_
std::string beam1Filename_
Definition: BaseProtonTransport.h:54
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
edm::FileInPath
Definition: FileInPath.h:61
BaseProtonTransport::m_sigmaSX
double m_sigmaSX
Definition: BaseProtonTransport.h:71
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
FileInPath.h
BaseProtonTransport::fCrossingAngleX_45
double fCrossingAngleX_45
Definition: BaseProtonTransport.h:59
ProtonMassSQ
static const double ProtonMassSQ
Definition: PPSUnitConversion.h:6
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
BaseProtonTransport::etaCut_
double etaCut_
Definition: BaseProtonTransport.h:66
BaseProtonTransport::fBeamXatIP
double fBeamXatIP
Definition: BaseProtonTransport.h:74
TotemTransport::m_model_ip_150_l_name
std::string m_model_ip_150_l_name
Definition: TotemTransport.h:38
TotemTransport::TotemTransport
TotemTransport(const edm::ParameterSet &ps)
Definition: TotemTransport.cc:10
BaseProtonTransport::m_beamPart
std::map< unsigned int, TLorentzVector > m_beamPart
Definition: BaseProtonTransport.h:47
urad
static const double urad
Definition: PPSUnitConversion.h:10
TotemTransport::transportProton
bool transportProton(const HepMC::GenParticle *)
Definition: TotemTransport.cc:84
BaseProtonTransport
Definition: BaseProtonTransport.h:17
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
BaseProtonTransport::engine_
CLHEP::HepRandomEngine * engine_
Definition: BaseProtonTransport.h:45
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LHCOpticsApproximator
Class finds the parametrisation of MADX proton transport and transports the protons according to it 5...
Definition: LHCOpticsApproximator.h:29
TotemTransport::m_aprox_ip_150_r
LHCOpticsApproximator * m_aprox_ip_150_r
Definition: TotemTransport.h:34
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
BaseProtonTransport::TransportMode::TOTEM
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
std
Definition: JetResolutionObject.h:76
BaseProtonTransport::m_yAtTrPoint
std::map< unsigned int, double > m_yAtTrPoint
Definition: BaseProtonTransport.h:49
BaseProtonTransport::m_sigmaSTX
double m_sigmaSTX
Definition: BaseProtonTransport.h:69
BaseProtonTransport::beamEnergy_
double beamEnergy_
Definition: BaseProtonTransport.h:65
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
BaseProtonTransport::m_xAtTrPoint
std::map< unsigned int, double > m_xAtTrPoint
Definition: BaseProtonTransport.h:48
BaseProtonTransport::fCrossingAngleX_56
double fCrossingAngleX_56
Definition: BaseProtonTransport.h:60
TotemTransport::process
void process(const HepMC::GenEvent *ev, const edm::EventSetup &es, CLHEP::HepRandomEngine *engine) override
Definition: TotemTransport.cc:51
BaseProtonTransport::fBeamYatIP
double fBeamYatIP
Definition: BaseProtonTransport.h:75
TotemTransport::m_beampipe_aperture_radius
double m_beampipe_aperture_radius
Definition: TotemTransport.h:40
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:52
TotemTransport::ReadParameterization
LHCOpticsApproximator * ReadParameterization(const std::string &, const std::string &)
Definition: TotemTransport.cc:178
doHarvest.rootfile
rootfile
Definition: doHarvest.py:122
mps_splice.line
line
Definition: mps_splice.py:76
LHCOpticsApproximator::Transport_m_GeV
bool Transport_m_GeV(double in_pos[3], double in_momentum[3], double out_pos[3], double out_momentum[3], bool check_apertures, double z2_z1_dist) const
pos, momentum: x,y,z; pos in m, momentum in GeV/c
Definition: LHCOpticsApproximator.cc:182
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37