CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Private Member Functions | Private Attributes
ProtonReconstructionAlgorithm Class Reference

#include <ProtonReconstructionAlgorithm.h>

Classes

class  ChiSquareCalculator
 class for calculation of chi^2 More...
 
struct  RPOpticsData
 optics data associated with 1 RP More...
 

Public Member Functions

void init (const LHCInterpolatedOpticalFunctionsSetCollection &opticalFunctions)
 
 ProtonReconstructionAlgorithm (bool fit_vtx_y, bool improved_estimate, unsigned int verbosity)
 
reco::ForwardProton reconstructFromMultiRP (const CTPPSLocalTrackLiteRefVector &tracks, const LHCInfo &lhcInfo, std::ostream &os) const
 run proton reconstruction using multiple-RP strategy More...
 
reco::ForwardProton reconstructFromSingleRP (const CTPPSLocalTrackLiteRef &track, const LHCInfo &lhcInfo, std::ostream &os) const
 run proton reconstruction using single-RP strategy More...
 
void release ()
 
 ~ProtonReconstructionAlgorithm ()=default
 

Static Private Member Functions

static void doLinearFit (const std::vector< double > &vx, const std::vector< double > &vy, double &b, double &a)
 

Private Attributes

std::unique_ptr< ChiSquareCalculatorchiSquareCalculator_
 object to calculate chi^2 More...
 
std::unique_ptr< ROOT::Fit::Fitter > fitter_
 fitter object More...
 
bool fitVtxY_
 
bool initialized_
 
std::map< unsigned int, RPOpticsDatam_rp_optics_
 map: RP id –> optics data More...
 
bool useImprovedInitialEstimate_
 
unsigned int verbosity_
 

Detailed Description

Definition at line 26 of file ProtonReconstructionAlgorithm.h.

Constructor & Destructor Documentation

ProtonReconstructionAlgorithm::ProtonReconstructionAlgorithm ( bool  fit_vtx_y,
bool  improved_estimate,
unsigned int  verbosity 
)

Definition at line 22 of file ProtonReconstructionAlgorithm.cc.

References chiSquareCalculator_, and fitter_.

26  fitVtxY_(fit_vtx_y),
27  useImprovedInitialEstimate_(improved_estimate),
28  initialized_(false),
30  chiSquareCalculator_(new ChiSquareCalculator) {
31  // needed for thread safety
32  TMinuitMinimizer::UseStaticMinuit(false);
33 
34  // initialise fitter
35  double pStart[] = {0, 0, 0, 0};
36  fitter_->SetFCN(4, *chiSquareCalculator_, pStart, 0, true);
37 }
std::unique_ptr< ROOT::Fit::Fitter > fitter_
fitter object
std::unique_ptr< ChiSquareCalculator > chiSquareCalculator_
object to calculate chi^2
ProtonReconstructionAlgorithm::~ProtonReconstructionAlgorithm ( )
default

Member Function Documentation

void ProtonReconstructionAlgorithm::doLinearFit ( const std::vector< double > &  vx,
const std::vector< double > &  vy,
double &  b,
double &  a 
)
staticprivate

Definition at line 84 of file ProtonReconstructionAlgorithm.cc.

References ztail::d, and mps_fire::i.

Referenced by init().

87  {
88  double s_1 = 0., s_x = 0., s_xx = 0., s_y = 0., s_xy = 0.;
89  for (unsigned int i = 0; i < vx.size(); ++i) {
90  s_1 += 1.;
91  s_x += vx[i];
92  s_xx += vx[i] * vx[i];
93  s_y += vy[i];
94  s_xy += vx[i] * vy[i];
95  }
96 
97  const double d = s_xx * s_1 - s_x * s_x;
98  a = (s_1 * s_xy - s_x * s_y) / d;
99  b = (-s_x * s_xy + s_xx * s_y) / d;
100 }
d
Definition: ztail.py:151
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
void ProtonReconstructionAlgorithm::init ( const LHCInterpolatedOpticalFunctionsSetCollection opticalFunctions)

Definition at line 41 of file ProtonReconstructionAlgorithm.cc.

References ProtonReconstructionAlgorithm::RPOpticsData::ch0, ProtonReconstructionAlgorithm::RPOpticsData::ch1, doLinearFit(), LHCOpticalFunctionsSet::eLx, LHCOpticalFunctionsSet::eLy, LHCOpticalFunctionsSet::evy, LHCOpticalFunctionsSet::exd, LHCOpticalFunctionsSet::eyd, LHCOpticalFunctionsSet::getFcnValues(), LHCOpticalFunctionsSet::getXiValues(), initialized_, ProtonReconstructionAlgorithm::RPOpticsData::la0, ProtonReconstructionAlgorithm::RPOpticsData::la1, m_rp_optics_, eostools::move(), ProtonReconstructionAlgorithm::RPOpticsData::optics, AlCaHLTBitMon_ParallelJobs::p, release(), ProtonReconstructionAlgorithm::RPOpticsData::s_L_y_vs_xi, ProtonReconstructionAlgorithm::RPOpticsData::s_v_y_vs_xi, ProtonReconstructionAlgorithm::RPOpticsData::s_xi_vs_x_d, ProtonReconstructionAlgorithm::RPOpticsData::s_y_d_vs_xi, LHCInterpolatedOpticalFunctionsSet::splines(), LHCInterpolatedOpticalFunctionsSet::transport(), LHCInterpolatedOpticalFunctionsSet::Kinematics::x, ProtonReconstructionAlgorithm::RPOpticsData::x0, LHCInterpolatedOpticalFunctionsSet::Kinematics::y, and ProtonReconstructionAlgorithm::RPOpticsData::y0.

Referenced by CTPPSProtonProducer::produce().

41  {
42  // reset cache
43  release();
44 
45  // build optics data for each object
46  for (const auto &p : opticalFunctions) {
47  const LHCInterpolatedOpticalFunctionsSet &ofs = p.second;
48 
49  // make record
50  RPOpticsData rpod;
51  rpod.optics = &p.second;
52  rpod.s_y_d_vs_xi = ofs.splines()[LHCOpticalFunctionsSet::eyd];
53  rpod.s_v_y_vs_xi = ofs.splines()[LHCOpticalFunctionsSet::evy];
54  rpod.s_L_y_vs_xi = ofs.splines()[LHCOpticalFunctionsSet::eLy];
55 
56  vector<double> xiValues =
57  ofs.getXiValues(); // local copy made since the TSpline constructor needs non-const parameters
58  vector<double> xDValues = ofs.getFcnValues()[LHCOpticalFunctionsSet::exd];
59  rpod.s_xi_vs_x_d = make_shared<TSpline3>("", xDValues.data(), xiValues.data(), xiValues.size());
60 
61  // calculate auxiliary data
62  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in = {0., 0., 0., 0., 0.};
64  rpod.optics->transport(k_in, k_out);
65  rpod.x0 = k_out.x;
66  rpod.y0 = k_out.y;
67 
68  doLinearFit(ofs.getXiValues(), ofs.getFcnValues()[LHCOpticalFunctionsSet::exd], rpod.ch0, rpod.ch1);
69  rpod.ch0 -= rpod.x0;
70 
71  doLinearFit(ofs.getXiValues(), ofs.getFcnValues()[LHCOpticalFunctionsSet::eLx], rpod.la0, rpod.la1);
72 
73  // insert record
74  const CTPPSDetId rpId(p.first);
75  m_rp_optics_.emplace(rpId, std::move(rpod));
76  }
77 
78  // update settings
79  initialized_ = true;
80 }
const std::vector< double > & getXiValues() const
std::map< unsigned int, RPOpticsData > m_rp_optics_
map: RP id –> optics data
const std::vector< std::shared_ptr< const TSpline3 > > & splines() const
static void doLinearFit(const std::vector< double > &vx, const std::vector< double > &vy, double &b, double &a)
Set of optical functions corresponding to one scoring plane along LHC, including splines for interpol...
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
const std::vector< std::vector< double > > & getFcnValues() const
def move(src, dest)
Definition: eostools.py:511
reco::ForwardProton ProtonReconstructionAlgorithm::reconstructFromMultiRP ( const CTPPSLocalTrackLiteRefVector tracks,
const LHCInfo lhcInfo,
std::ostream &  os 
) const

run proton reconstruction using multiple-RP strategy

Definition at line 145 of file ProtonReconstructionAlgorithm.cc.

References a, b, HltBtagPostValidation_cff::c, ProtonReconstructionAlgorithm::RPOpticsData::ch0, ProtonReconstructionAlgorithm::RPOpticsData::ch1, chiSquareCalculator_, LHCInfo::energy(), fitter_, fitVtxY_, mps_fire::i, createfilelist::int, dqmiolumiharvest::j, ProtonReconstructionAlgorithm::RPOpticsData::la0, ProtonReconstructionAlgorithm::RPOpticsData::la1, m_rp_optics_, AlCaHLTBitMon_ParallelJobs::p, CalibrationSummaryClient_cfi::params, mps_fire::result, mathSSE::sqrt(), HLT_2018_cff::track, PDWG_EXOHSCP_cff::tracks, useImprovedInitialEstimate_, verbosity_, bphysicsOniaDQM_cfi::vertex, hybridSuperClusters_cfi::xi, and y.

Referenced by CTPPSProtonProducer::produce().

147  {
148  // make sure optics is available for all tracks
149  for (const auto &it : tracks) {
150  auto oit = m_rp_optics_.find(it->rpId());
151  if (oit == m_rp_optics_.end())
152  throw cms::Exception("ProtonReconstructionAlgorithm")
153  << "Optics data not available for RP " << it->rpId() << ", i.e. " << CTPPSDetId(it->rpId()) << ".";
154  }
155 
156  // initial estimate of xi and th_x
157  double xi_init = 0., th_x_init = 0.;
158 
160  double x_N = tracks[0]->x() * 1E-1, // conversion: mm --> cm
161  x_F = tracks[1]->x() * 1E-1;
162 
163  const RPOpticsData &i_N = m_rp_optics_.find(tracks[0]->rpId())->second,
164  &i_F = m_rp_optics_.find(tracks[1]->rpId())->second;
165 
166  const double a = i_F.ch1 * i_N.la1 - i_N.ch1 * i_F.la1;
167  const double b =
168  i_F.ch0 * i_N.la1 - i_N.ch0 * i_F.la1 + i_F.ch1 * i_N.la0 - i_N.ch1 * i_F.la0 + x_N * i_F.la1 - x_F * i_N.la1;
169  const double c = x_N * i_F.la0 - x_F * i_N.la0 + i_F.ch0 * i_N.la0 - i_N.ch0 * i_F.la0;
170  const double D = b * b - 4. * a * c;
171  const double sqrt_D = (D >= 0.) ? sqrt(D) : 0.;
172 
173  xi_init = (-b + sqrt_D) / 2. / a;
174  th_x_init = (x_N - i_N.ch0 - i_N.ch1 * xi_init) / (i_N.la0 + i_N.la1 * xi_init);
175  } else {
176  double s_xi0 = 0., s_1 = 0.;
177  for (const auto &track : tracks) {
178  auto oit = m_rp_optics_.find(track->rpId());
179  double xi = oit->second.s_xi_vs_x_d->Eval(track->x() * 1E-1 + oit->second.x0); // conversion: mm --> cm
180 
181  s_1 += 1.;
182  s_xi0 += xi;
183  }
184 
185  xi_init = s_xi0 / s_1;
186  }
187 
188  if (!std::isfinite(xi_init))
189  xi_init = 0.;
190  if (!std::isfinite(th_x_init))
191  th_x_init = 0.;
192 
193  // initial estimate of th_y and vtx_y
194  double y[2] = {0}, v_y[2] = {0}, L_y[2] = {0};
195  unsigned int y_idx = 0;
196  for (const auto &track : tracks) {
197  if (y_idx >= 2)
198  break;
199 
200  auto oit = m_rp_optics_.find(track->rpId());
201 
202  y[y_idx] = track->y() * 1E-1 - oit->second.s_y_d_vs_xi->Eval(xi_init); // track y: mm --> cm
203  v_y[y_idx] = oit->second.s_v_y_vs_xi->Eval(xi_init);
204  L_y[y_idx] = oit->second.s_L_y_vs_xi->Eval(xi_init);
205 
206  y_idx++;
207  }
208 
209  double vtx_y_init = 0.;
210  double th_y_init = 0.;
211 
212  if (fitVtxY_) {
213  const double det_y = v_y[0] * L_y[1] - L_y[0] * v_y[1];
214  vtx_y_init = (det_y != 0.) ? (L_y[1] * y[0] - L_y[0] * y[1]) / det_y : 0.;
215  th_y_init = (det_y != 0.) ? (v_y[0] * y[1] - v_y[1] * y[0]) / det_y : 0.;
216  } else {
217  vtx_y_init = 0.;
218  th_y_init = (y[1] / L_y[1] + y[0] / L_y[0]) / 2.;
219  }
220 
221  if (!std::isfinite(vtx_y_init))
222  vtx_y_init = 0.;
223  if (!std::isfinite(th_y_init))
224  th_y_init = 0.;
225 
226  unsigned int armId = CTPPSDetId((*tracks.begin())->rpId()).arm();
227 
228  if (verbosity_)
229  os << "ProtonReconstructionAlgorithm::reconstructFromMultiRP(" << armId << ")" << std::endl
230  << " initial estimate: xi_init = " << xi_init << ", th_x_init = " << th_x_init
231  << ", th_y_init = " << th_y_init << ", vtx_y_init = " << vtx_y_init << "." << std::endl;
232 
233  // minimisation
234  fitter_->Config().ParSettings(0).Set("xi", xi_init, 0.005);
235  fitter_->Config().ParSettings(1).Set("th_x", th_x_init, 2E-6);
236  fitter_->Config().ParSettings(2).Set("th_y", th_y_init, 2E-6);
237  fitter_->Config().ParSettings(3).Set("vtx_y", vtx_y_init, 10E-6);
238 
239  if (!fitVtxY_)
240  fitter_->Config().ParSettings(3).Fix();
241 
242  chiSquareCalculator_->tracks = &tracks;
243  chiSquareCalculator_->m_rp_optics = &m_rp_optics_;
244 
245  fitter_->FitFCN();
246  fitter_->FitFCN(); // second minimisation in case the first one had troubles
247 
248  // extract proton parameters
249  const ROOT::Fit::FitResult &result = fitter_->Result();
250  const double *params = result.GetParams();
251 
252  if (verbosity_)
253  os << " xi=" << params[0] << " +- " << result.Error(0) << ", th_x=" << params[1] << " +-" << result.Error(1)
254  << ", th_y=" << params[2] << " +-" << result.Error(2) << ", vtx_y=" << params[3] << " +-" << result.Error(3)
255  << ", chiSq = " << result.Chi2() << std::endl;
256 
257  // save reco candidate
258  using FP = reco::ForwardProton;
259 
260  const double sign_z = (armId == 0) ? +1. : -1.; // CMS convention
261  const FP::Point vertex(0., params[3], 0.);
262  const double xi = params[0];
263  const double th_x = params[1];
264  const double th_y = params[2];
265  const double cos_th = sqrt(1. - th_x * th_x - th_y * th_y);
266  const double p = lhcInfo.energy() * (1. - xi);
267  const FP::Vector momentum(-p * th_x, // the signs reflect change LHC --> CMS convention
268  +p * th_y,
269  sign_z * p * cos_th);
270  signed int ndf = 2. * tracks.size() - ((fitVtxY_) ? 4. : 3.);
271 
272  map<unsigned int, signed int> index_map = {
273  {(unsigned int)FP::Index::xi, 0},
274  {(unsigned int)FP::Index::th_x, 1},
275  {(unsigned int)FP::Index::th_y, 2},
276  {(unsigned int)FP::Index::vtx_y, ((fitVtxY_) ? 3 : -1)},
277  {(unsigned int)FP::Index::vtx_x, -1},
278  };
279 
281  for (unsigned int i = 0; i < (unsigned int)FP::Index::num_indices; ++i) {
282  signed int fit_i = index_map[i];
283 
284  for (unsigned int j = 0; j < (unsigned int)FP::Index::num_indices; ++j) {
285  signed int fit_j = index_map[j];
286 
287  cm(i, j) = (fit_i >= 0 && fit_j >= 0) ? result.CovMatrix(fit_i, fit_j) : 0.;
288  }
289  }
290 
291  return reco::ForwardProton(
292  result.Chi2(), ndf, vertex, momentum, xi, cm, FP::ReconstructionMethod::multiRP, tracks, result.IsValid());
293 }
std::unique_ptr< ROOT::Fit::Fitter > fitter_
fitter object
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
math::Error< 5 >::type CovarianceMatrix
std::map< unsigned int, RPOpticsData > m_rp_optics_
map: RP id –> optics data
std::unique_ptr< ChiSquareCalculator > chiSquareCalculator_
object to calculate chi^2
T sqrt(T t)
Definition: SSEVec.h:19
math::XYZPoint Point
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
double b
Definition: hdecay.h:118
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
double a
Definition: hdecay.h:119
float const energy() const
Definition: LHCInfo.cc:190
reco::ForwardProton ProtonReconstructionAlgorithm::reconstructFromSingleRP ( const CTPPSLocalTrackLiteRef track,
const LHCInfo lhcInfo,
std::ostream &  os 
) const

run proton reconstruction using single-RP strategy

Definition at line 297 of file ProtonReconstructionAlgorithm.cc.

References funct::abs(), CTPPSDetId::arm(), LHCInfo::energy(), m_rp_optics_, AlCaHLTBitMon_ParallelJobs::p, funct::pow(), edm::RefVector< C, T, F >::push_back(), mathSSE::sqrt(), verbosity_, bphysicsOniaDQM_cfi::vertex, and hybridSuperClusters_cfi::xi.

Referenced by CTPPSProtonProducer::produce().

299  {
300  CTPPSDetId rpId(track->rpId());
301 
302  if (verbosity_)
303  os << "reconstructFromSingleRP(" << rpId.arm() * 100 + rpId.station() * 10 + rpId.rp() << ")" << std::endl;
304 
305  // make sure optics is available for the track
306  auto oit = m_rp_optics_.find(track->rpId());
307  if (oit == m_rp_optics_.end())
308  throw cms::Exception("ProtonReconstructionAlgorithm")
309  << "Optics data not available for RP " << track->rpId() << ", i.e. " << rpId << ".";
310 
311  // rough estimate of xi and th_y from each track
312  const double x_full = track->x() * 1E-1 + oit->second.x0; // conversion mm --> cm
313  const double xi = oit->second.s_xi_vs_x_d->Eval(x_full);
314  const double L_y = oit->second.s_L_y_vs_xi->Eval(xi);
315  const double th_y = track->y() * 1E-1 / L_y; // conversion mm --> cm
316 
317  const double ep_x = 1E-6;
318  const double dxi_dx = (oit->second.s_xi_vs_x_d->Eval(x_full + ep_x) - xi) / ep_x;
319  const double xi_unc = abs(dxi_dx) * track->xUnc() * 1E-1; // conversion mm --> cm
320 
321  const double ep_xi = 1E-4;
322  const double dL_y_dxi = (oit->second.s_L_y_vs_xi->Eval(xi + ep_xi) - L_y) / ep_xi;
323  const double th_y_unc = th_y * sqrt(pow(track->yUnc() / track->y(), 2.) + pow(dL_y_dxi * xi_unc / L_y, 2.));
324 
325  if (verbosity_)
326  os << " xi = " << xi << " +- " << xi_unc << ", th_y = " << th_y << " +- " << th_y_unc << "." << std::endl;
327 
328  using FP = reco::ForwardProton;
329 
330  // save proton candidate
331  const double sign_z = (CTPPSDetId(track->rpId()).arm() == 0) ? +1. : -1.; // CMS convention
332  const FP::Point vertex(0., 0., 0.);
333  const double cos_th = sqrt(1. - th_y * th_y);
334  const double p = lhcInfo.energy() * (1. - xi);
335  const FP::Vector momentum(0., p * th_y, sign_z * p * cos_th);
336 
338  cm((int)FP::Index::xi, (int)FP::Index::xi) = xi_unc * xi_unc;
339  cm((int)FP::Index::th_y, (int)FP::Index::th_y) = th_y_unc * th_y_unc;
340 
342  trk.push_back(track);
343 
344  return reco::ForwardProton(0., 0, vertex, momentum, xi, cm, FP::ReconstructionMethod::singleRP, trk, true);
345 }
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
math::Error< 5 >::type CovarianceMatrix
std::map< unsigned int, RPOpticsData > m_rp_optics_
map: RP id –> optics data
T sqrt(T t)
Definition: SSEVec.h:19
math::XYZPoint Point
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
uint32_t arm() const
Definition: CTPPSDetId.h:51
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
float const energy() const
Definition: LHCInfo.cc:190
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
void ProtonReconstructionAlgorithm::release ( )

Definition at line 104 of file ProtonReconstructionAlgorithm.cc.

References initialized_, and m_rp_optics_.

Referenced by init(), and CTPPSProtonProducer::produce().

104  {
105  initialized_ = false;
106 
107  m_rp_optics_.clear();
108 }
std::map< unsigned int, RPOpticsData > m_rp_optics_
map: RP id –> optics data

Member Data Documentation

std::unique_ptr<ChiSquareCalculator> ProtonReconstructionAlgorithm::chiSquareCalculator_
private

object to calculate chi^2

Definition at line 80 of file ProtonReconstructionAlgorithm.h.

Referenced by ProtonReconstructionAlgorithm(), and reconstructFromMultiRP().

std::unique_ptr<ROOT::Fit::Fitter> ProtonReconstructionAlgorithm::fitter_
private

fitter object

Definition at line 77 of file ProtonReconstructionAlgorithm.h.

Referenced by ProtonReconstructionAlgorithm(), and reconstructFromMultiRP().

bool ProtonReconstructionAlgorithm::fitVtxY_
private

Definition at line 46 of file ProtonReconstructionAlgorithm.h.

Referenced by reconstructFromMultiRP().

bool ProtonReconstructionAlgorithm::initialized_
private

Definition at line 48 of file ProtonReconstructionAlgorithm.h.

Referenced by init(), and release().

std::map<unsigned int, RPOpticsData> ProtonReconstructionAlgorithm::m_rp_optics_
private

map: RP id –> optics data

Definition at line 63 of file ProtonReconstructionAlgorithm.h.

Referenced by init(), reconstructFromMultiRP(), reconstructFromSingleRP(), and release().

bool ProtonReconstructionAlgorithm::useImprovedInitialEstimate_
private

Definition at line 47 of file ProtonReconstructionAlgorithm.h.

Referenced by reconstructFromMultiRP().

unsigned int ProtonReconstructionAlgorithm::verbosity_
private