CMS 3D CMS Logo

CTPPSFastTrackingProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FastSimulation/CTPPSFastTrackingProducer
4 // Class: CTPPSFastTrackingProducer
5 //
13 //
14 // Original Author: Sandro Fonseca De Souza
15 // Created: Thu, 29 Sep 2016 16:13:41 GMT
16 //
17 //
18 
19 #include <memory>
20 
41 
42 #include "TLorentzVector.h"
43 
44 // hector includes
45 #include "H_Parameters.h"
46 #include "H_BeamLine.h"
47 #include "H_RecRPObject.h"
48 #include "H_BeamParticle.h"
49 
51 public:
53 
54 private:
55  void produce(edm::Event&, const edm::EventSetup&) override;
56 
57  // ----------member data ---------------------------
58 
59  typedef std::vector<CTPPSFastRecHit> CTPPSFastRecHitContainer;
62  void FastReco(int Direction, H_RecRPObject* station);
63  void Reconstruction();
64  void ReconstructArm(
65  H_RecRPObject* pps_station, double x1, double y1, double x2, double y2, double& tx, double& ty, double& eloss);
66  void MatchCellId(int cellId, std::vector<int> vrecCellId, std::vector<double> vrecTof, bool& match, double& recTof);
67  bool SearchTrack(int,
68  int,
69  int Direction,
70  double& xi,
71  double& t,
72  double& partP,
73  double& pt,
74  double& thx,
75  double& thy,
76  double& x0,
77  double& y0,
78  double& xt,
79  double& yt,
80  double& X1d,
81  double& Y1d,
82  double& X2d,
83  double& Y2d);
84  void TrackerStationClear();
86  void ProjectToToF(const double x1, const double y1, const double x2, const double y2, double& xt, double& yt) {
87  xt = ((fz_timing - fz_tracker2) * (x2 - x1) / (fz_tracker2 - fz_tracker1)) + x2;
88  yt = ((fz_timing - fz_tracker2) * (y2 - y1) / (fz_tracker2 - fz_tracker1)) + y2;
89  };
90  // Hector objects
91  bool SetBeamLine();
92 
93  std::unique_ptr<H_BeamLine> m_beamlineCTPPS1;
94  std::unique_ptr<H_BeamLine> m_beamlineCTPPS2;
95  std::unique_ptr<H_RecRPObject> pps_stationF;
96  std::unique_ptr<H_RecRPObject> pps_stationB;
97 
100 
101  // Defaults
102  double lengthctpps;
104  double fBeamEnergy;
110  std::unique_ptr<CTPPSTrkStation> TrkStation_F; // auxiliary object with the tracker geometry
111  std::unique_ptr<CTPPSTrkStation> TrkStation_B;
112  std::unique_ptr<CTPPSTrkDetector> det1F;
113  std::unique_ptr<CTPPSTrkDetector> det1B;
114  std::unique_ptr<CTPPSTrkDetector> det2F;
115  std::unique_ptr<CTPPSTrkDetector> det2B;
116  std::unique_ptr<CTPPSToFDetector> detToF_F;
117  std::unique_ptr<CTPPSToFDetector> detToF_B;
118 
119  std::vector<CTPPSFastTrack> theCTPPSFastTrack;
120 
122 
123  std::vector<int> recCellId_F, recCellId_B;
124  std::vector<double> recTof_F, recTof_B;
125 
128  std::vector<double> fToFCellWidth;
132 };
134 // constructors and destructor
135 //
137  : m_verbosity(false), fBeamMomentum(0.), fCrossAngleCorr(false), fCrossingAngleBeam1(0.), fCrossingAngleBeam2(0.) {
138  //register your products
139  produces<edm::CTPPSFastTrackContainer>("CTPPSFastTrack");
140  using namespace edm;
141  _recHitToken = consumes<CTPPSFastRecHitContainer>(iConfig.getParameter<edm::InputTag>("recHitTag"));
142  m_verbosity = iConfig.getParameter<bool>("Verbosity");
143  // User definitons
144 
145  // Read beam parameters needed for Hector reconstruction
146  lengthctpps = iConfig.getParameter<double>("BeamLineLengthCTPPS");
147  beam1filename = iConfig.getParameter<string>("Beam1");
148  beam2filename = iConfig.getParameter<string>("Beam2");
149  fBeamEnergy = iConfig.getParameter<double>("BeamEnergy"); // beam energy in GeV
151  fCrossingAngleBeam1 = iConfig.getParameter<double>("CrossingAngleBeam1");
152  fCrossingAngleBeam2 = iConfig.getParameter<double>("CrossingAngleBeam2");
153 
154  if (fCrossingAngleBeam1 != 0 || fCrossingAngleBeam2 != 0)
155  fCrossAngleCorr = true;
156  //Read detectors positions and parameters
157 
158  fz_tracker1 = iConfig.getParameter<double>("Z_Tracker1");
159  fz_tracker2 = iConfig.getParameter<double>("Z_Tracker2");
160  fz_timing = iConfig.getParameter<double>("Z_Timing");
161  //
162  fTrackerWidth = iConfig.getParameter<double>("TrackerWidth");
163  fTrackerHeight = iConfig.getParameter<double>("TrackerHeight");
164  fTrackerInsertion = iConfig.getParameter<double>("TrackerInsertion");
165  fBeamXRMS_Trk1 = iConfig.getParameter<double>("BeamXRMS_Trk1");
166  fBeamXRMS_Trk2 = iConfig.getParameter<double>("BeamXRMS_Trk2");
167  fTrk1XOffset = iConfig.getParameter<double>("Trk1XOffset");
168  fTrk2XOffset = iConfig.getParameter<double>("Trk2XOffset");
169  fToFCellWidth = iConfig.getUntrackedParameter<std::vector<double> >("ToFCellWidth");
170  fToFCellHeight = iConfig.getParameter<double>("ToFCellHeight");
171  fToFPitchX = iConfig.getParameter<double>("ToFPitchX");
172  fToFPitchY = iConfig.getParameter<double>("ToFPitchY");
173  fToFNCellX = iConfig.getParameter<int>("ToFNCellX");
174  fToFNCellY = iConfig.getParameter<int>("ToFNCellY");
175  fToFInsertion = iConfig.getParameter<double>("ToFInsertion");
176  fBeamXRMS_ToF = iConfig.getParameter<double>("BeamXRMS_ToF");
177  fToFXOffset = iConfig.getParameter<double>("ToFXOffset");
178  fTimeSigma = iConfig.getParameter<double>("TimeSigma");
179  fImpParcut = iConfig.getParameter<double>("ImpParcut");
180 
181  if (!SetBeamLine()) {
182  if (m_verbosity)
183  LogDebug("CTPPSFastTrackingProducer") << "CTPPSFastTrackingProducer: WARNING: lengthctpps= " << lengthctpps;
184  return;
185  }
186 
187  // Create a particle to get the beam energy from the beam file
188  // Take care: the z inside the station is in meters
189  //
190  //Tracker Detector Description
191  det1F = std::make_unique<CTPPSTrkDetector>(
193  det2F = std::make_unique<CTPPSTrkDetector>(
195  det1B = std::make_unique<CTPPSTrkDetector>(
197  det2B = std::make_unique<CTPPSTrkDetector>(
199 
200  //Timing Detector Description
201  std::vector<double> vToFCellWidth;
202  vToFCellWidth.reserve(8);
203  for (int i = 0; i < 8; i++) {
204  vToFCellWidth.push_back(fToFCellWidth[i]);
205  }
206  double pos_tof = fToFInsertion * fBeamXRMS_ToF + fToFXOffset;
207  detToF_F = std::make_unique<CTPPSToFDetector>(
208  fToFNCellX, fToFNCellY, vToFCellWidth, fToFCellHeight, fToFPitchX, fToFPitchY, pos_tof, fTimeSigma);
209  detToF_B = std::make_unique<CTPPSToFDetector>(
210  fToFNCellX, fToFNCellY, vToFCellWidth, fToFCellHeight, fToFPitchX, fToFPitchY, pos_tof, fTimeSigma);
211  //
212 }
213 
214 // ------------ method called to produce the data ------------
216  using namespace edm;
219  iEvent.getByToken(_recHitToken, recHits);
220  recCellId_F.clear();
221  recCellId_B.clear();
222  recTof_F.clear();
223  recTof_B.clear();
225  Reconstruction();
227 
228  std::unique_ptr<CTPPSFastTrackContainer> output_tracks(new CTPPSFastTrackContainer);
229  for (std::vector<CTPPSFastTrack>::const_iterator i = theCTPPSFastTrack.begin(); i != theCTPPSFastTrack.end(); i++) {
230  output_tracks->push_back(*i);
231  }
232 
233  iEvent.put(std::move(output_tracks), "CTPPSFastTrack");
234 } //end
235 
238  TrkStation_F->first.clear();
239  TrkStation_F->second.clear();
240  TrkStation_B->first.clear();
241  TrkStation_B->second.clear();
242 }
245  det1F->clear();
246  det1B->clear();
247  det2F->clear();
248  det2B->clear();
249  detToF_F->clear();
250  detToF_B->clear();
251 }
252 
255  // DetId codification for PSimHit taken from CTPPSPixel- It will be replaced by CTPPSDetId
256  // 2014314496 -> Tracker1 zPositive
257  // 2014838784 -> Tracker2 zPositive
258  // 2046820352 -> Timing zPositive
259  // 2031091712 -> Tracker1 zNegative
260  // 2031616000 -> Tracker2 zNegative
261  // 2063597568 -> Timing zNegative
262 
263  for (unsigned int irecHits = 0; irecHits < recHits->size(); ++irecHits) {
264  const CTPPSFastRecHit* recHitDet = &(*recHits)[irecHits];
265  unsigned int detlayerId = recHitDet->detUnitId();
266  double x = recHitDet->entryPoint().x();
267  double y = recHitDet->entryPoint().y();
268  double z = recHitDet->entryPoint().z();
269  float tof = recHitDet->tof();
270  if (detlayerId == 2014314496)
271  det1F->AddHit(detlayerId, x, y, z);
272  else if (detlayerId == 2014838784)
273  det2F->AddHit(detlayerId, x, y, z);
274  else if (detlayerId == 2031091712)
275  det1B->AddHit(detlayerId, x, y, z);
276  else if (detlayerId == 2031616000)
277  det2B->AddHit(detlayerId, x, y, z);
278  else if (detlayerId == 2046820352) {
279  detToF_F->AddHit(x, y, tof);
280  recCellId_F.push_back(detToF_F->findCellId(x, y));
281  recTof_F.push_back(tof);
282  } else if (detlayerId == 2063597568) {
283  detToF_B->AddHit(x, y, tof);
284  recCellId_B.push_back(detToF_B->findCellId(x, y));
285  recTof_B.push_back(tof);
286  }
287 
288  } //LOOP TRK
289  //creating Stations
290  TrkStation_F = std::make_unique<CTPPSTrkStation>(*det1F, *det2F);
291  TrkStation_B = std::make_unique<CTPPSTrkStation>(*det1B, *det2B);
292 } // end function
293 
295  theCTPPSFastTrack.clear();
296  int Direction;
297  Direction = 1; //cms positive Z / forward
298  FastReco(Direction, &*pps_stationF);
299  Direction = -1; //cms negative Z / backward
300  FastReco(Direction, &*pps_stationB);
301 } //end Reconstruction
302 
304  int j,
305  int Direction,
306  double& xi,
307  double& t,
308  double& partP,
309  double& pt,
310  double& thx,
311  double& thy,
312  double& x0,
313  double& y0,
314  double& xt,
315  double& yt,
316  double& X1d,
317  double& Y1d,
318  double& X2d,
319  double& Y2d) {
320  // Given 1 hit in Tracker1 and 1 hit in Tracker2 try to make a track with Hector
321  xi = 0;
322  t = 0;
323  partP = 0;
324  pt = 0;
325  x0 = 0.;
326  y0 = 0.;
327  xt = 0.;
328  yt = 0.;
329  X1d = 0.;
330  Y1d = 0.;
331  X2d = 0.;
332  Y2d = 0.;
333  CTPPSTrkDetector* det1 = nullptr;
334  CTPPSTrkDetector* det2 = nullptr;
335  H_RecRPObject* station = nullptr;
336  // Separate in forward and backward stations according to direction
337  if (Direction > 0) {
338  det1 = &(TrkStation_F->first);
339  det2 = &(TrkStation_F->second);
340  station = &*pps_stationF;
341  } else {
342  det1 = &(TrkStation_B->first);
343  det2 = &(TrkStation_B->second);
344  station = &*pps_stationB;
345  }
346  if (det1->ppsNHits_ <= i || det2->ppsNHits_ <= j)
347  return false;
348  //
349  double x1 = det1->ppsX_.at(i);
350  double y1 = det1->ppsY_.at(i);
351  double x2 = det2->ppsX_.at(j);
352  double y2 = det2->ppsY_.at(j);
353  double eloss;
354 
355  //thx and thy are returned in microrad
357  station, Direction * x1, y1, Direction * x2, y2, thx, thy, eloss); // Pass the hits in the LHC ref. frame
358  thx *= -Direction; // invert to the CMS ref frame
359 
360  // Protect for unphysical results
361  if (edm::isNotFinite(eloss) || edm::isNotFinite(thx) || edm::isNotFinite(thy))
362  return false;
363  //
364 
365  if (m_verbosity)
366  LogDebug("CTPPSFastTrackingProducer::SearchTrack:") << "thx " << thx << " thy " << thy << " eloss " << eloss;
367 
368  // Get the start point of the reconstructed track near the origin made by Hector in the CMS ref. frame
369  x0 = -Direction * station->getX0() * um_to_cm;
370  y0 = station->getY0() * um_to_cm;
371  double ImpPar = sqrt(x0 * x0 + y0 * y0);
372  if (ImpPar > fImpParcut)
373  return false;
374  if (eloss < 0. || eloss > fBeamEnergy)
375  return false;
376  //
377  // Calculate the reconstructed track parameters
378  double theta = sqrt(thx * thx + thy * thy) * urad;
379  xi = eloss / fBeamEnergy;
380  double energy = fBeamEnergy * (1. - xi);
382  t = -2. * (PPSTools::ProtonMassSQ - fBeamEnergy * energy + fBeamMomentum * partP * cos(theta));
383  pt = partP * theta;
384  if (xi < 0. || xi > 1. || t < 0. || t > 10. || pt <= 0.) {
385  xi = 0.;
386  t = 0.;
387  partP = 0.;
388  pt = 0.;
389  x0 = 0.;
390  y0 = 0.;
391  return false; // unphysical values
392  }
393  //Try to include the timing detector in the track
394  ProjectToToF(x1, y1, x2, y2, xt, yt); // the projections is done in the CMS ref frame
395  X1d = x1;
396  Y1d = y1;
397  X2d = x2;
398  Y2d = y2;
399  return true;
400 } //end SearchTrack
401 
403  H_RecRPObject* pps_station, double x1, double y1, double x2, double y2, double& tx, double& ty, double& eloss) {
404  tx = 0.;
405  ty = 0.;
406  eloss = 0.;
407  if (!pps_station)
408  return;
409  x1 *= mm_to_um;
410  x2 *= mm_to_um;
411  y1 *= mm_to_um;
412  y2 *= mm_to_um;
413  pps_station->setPositions(x1, y1, x2, y2);
414  double energy = pps_station->getE(AM); // dummy call needed to calculate some Hector internal parameter
416  return;
417  tx = pps_station->getTXIP(); // change orientation to CMS
418  ty = pps_station->getTYIP();
419  eloss = pps_station->getE();
420 }
421 
423  int cellId, std::vector<int> vrecCellId, std::vector<double> vrecTof, bool& match, double& recTof) {
424  for (unsigned int i = 0; i < vrecCellId.size(); i++) {
425  if (cellId == vrecCellId.at(i)) {
426  match = true;
427  recTof = vrecTof.at(i);
428  continue;
429  }
430  }
431 }
432 
433 void CTPPSFastTrackingProducer::FastReco(int Direction, H_RecRPObject* station) {
434  double theta = 0.;
435  double xi, t, partP, pt, phi, x0, y0, thx, thy, xt, yt, X1d, Y1d, X2d, Y2d;
436  CTPPSTrkDetector* Trk1 = nullptr;
437  CTPPSTrkDetector* Trk2 = nullptr;
438  double pos_tof = fToFInsertion * fBeamXRMS_ToF + fToFXOffset;
439  int cellId = 0;
440  std::vector<double> vToFCellWidth;
441  vToFCellWidth.reserve(8);
442  for (int i = 0; i < 8; i++) {
443  vToFCellWidth.push_back(fToFCellWidth[i]);
444  }
446  fToFNCellX, fToFNCellY, vToFCellWidth, fToFCellHeight, fToFPitchX, fToFPitchY, pos_tof, fTimeSigma);
447  if (Direction > 0) {
448  Trk1 = &(TrkStation_F->first);
449  Trk2 = &(TrkStation_F->second);
450  } else {
451  Trk1 = &(TrkStation_B->first);
452  Trk2 = &(TrkStation_B->second);
453  }
454  // Make a track from EVERY pair of hits combining Tracker1 and Tracker2.
455  // The tracks may not be independent as 1 hit may belong to more than 1 track.
456  for (int i = 0; i < (int)Trk1->ppsNHits_; i++) {
457  for (int j = 0; j < (int)Trk2->ppsNHits_; j++) {
458  if (SearchTrack(i, j, Direction, xi, t, partP, pt, thx, thy, x0, y0, xt, yt, X1d, Y1d, X2d, Y2d)) {
459  // Check if the hitted timing cell matches the reconstructed track
460  cellId = ToF->findCellId(xt, yt);
461  double recTof = 0.;
462  bool matchCellId = false;
463  if (Direction > 0) {
464  theta = sqrt(thx * thx + thy * thy) * urad;
465  MatchCellId(cellId, recCellId_F, recTof_F, matchCellId, recTof);
466  } else if (Direction < 0) {
467  theta = TMath::Pi() - sqrt(thx * thx + thy * thy) * urad;
468  MatchCellId(cellId, recCellId_B, recTof_B, matchCellId, recTof);
469  }
470  phi = atan2(thy, thx); // at this point, thx is already in the cms ref. frame
471 
472  double px = partP * sin(theta) * cos(phi);
473  double py = partP * sin(theta) * sin(phi);
474  double pz = partP * cos(theta);
475  double e = sqrt(partP * partP + PPSTools::ProtonMassSQ);
476  TLorentzVector p(px, py, pz, e);
477  // Invert the Lorentz boost made to take into account the crossing angle during simulation
478  if (fCrossAngleCorr) {
480  }
481  //Getting the Xi and t (squared four momentum transferred) of the reconstructed track
482  PPSTools::Get_t_and_xi(const_cast<TLorentzVector*>(&p), t, xi, {fBeamMomentum, fBeamEnergy});
483  double pxx = p.Px();
484  double pyy = p.Py();
485  double pzz = p.Pz();
486  math::XYZVector momentum(pxx, pyy, pzz);
487  math::XYZPoint vertex(x0, y0, 0);
488 
489  track.setp(momentum);
491  track.sett(t);
492  track.setxi(xi);
493  track.setx1(X1d);
494  track.sety1(Y1d);
495  track.setx2(X2d);
496  track.sety2(Y2d);
497  if (matchCellId) {
498  track.setcellid(cellId);
499  track.settof(recTof);
500  } else {
501  track.setcellid(0);
502  track.settof(0.);
503  }
504  theCTPPSFastTrack.push_back(track);
505  }
506  }
507  }
508 } //end FastReco
509 
513  if (lengthctpps <= 0)
514  return false;
515  m_beamlineCTPPS1 = std::make_unique<H_BeamLine>(-1, lengthctpps + 0.1); // (direction, length)
516  m_beamlineCTPPS1->fill(b2.fullPath(), 1, "IP5");
517  m_beamlineCTPPS2 = std::make_unique<H_BeamLine>(1, lengthctpps + 0.1); //
518  m_beamlineCTPPS2->fill(b1.fullPath(), 1, "IP5");
519  m_beamlineCTPPS1->offsetElements(120, 0.097);
520  m_beamlineCTPPS2->offsetElements(120, -0.097);
521  pps_stationF = std::make_unique<H_RecRPObject>(fz_tracker1, fz_tracker2, *m_beamlineCTPPS1);
522  pps_stationB = std::make_unique<H_RecRPObject>(fz_tracker1, fz_tracker2, *m_beamlineCTPPS2);
523  return true;
524 }
525 //define this as a plug-in
void LorentzBoost(H_BeamParticle &h_p, int dir, const std::string &frame, FullBeamInfo const &bi)
void sett(float t)
const double Pi
weight_default_t b1[25]
Definition: b1.h:9
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< double > ppsX_
std::unique_ptr< CTPPSTrkDetector > det2B
int findCellId(double x, double y)
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
std::unique_ptr< H_BeamLine > m_beamlineCTPPS1
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void FastReco(int Direction, H_RecRPObject *station)
void setvertex(const Point &vertex)
static const double urad
void sety1(float y1)
void setx2(float x2)
void ReconstructArm(H_RecRPObject *pps_station, double x1, double y1, double x2, double y2, double &tx, double &ty, double &eloss)
std::unique_ptr< H_RecRPObject > pps_stationB
std::unique_ptr< CTPPSToFDetector > detToF_F
std::unique_ptr< CTPPSTrkDetector > det2F
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< H_RecRPObject > pps_stationF
void setp(const Vector &momentum)
int iEvent
Definition: GenABIO.cc:224
void setx1(float x1)
CTPPSFastTrackingProducer(const edm::ParameterSet &)
std::unique_ptr< CTPPSTrkDetector > det1B
T sqrt(T t)
Definition: SSEVec.h:19
std::unique_ptr< CTPPSTrkStation > TrkStation_B
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void setxi(float xi)
const double ProtonMassSQ
Definition: PPSUtilities.h:31
std::unique_ptr< CTPPSToFDetector > detToF_B
std::vector< CTPPSFastRecHit > CTPPSFastRecHitContainer
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
weight_default_t b2[10]
Definition: b2.h:9
std::unique_ptr< H_BeamLine > m_beamlineCTPPS2
void ProjectToToF(const double x1, const double y1, const double x2, const double y2, double &xt, double &yt)
std::vector< double > ppsY_
void MatchCellId(int cellId, std::vector< int > vrecCellId, std::vector< double > vrecTof, bool &match, double &recTof)
std::unique_ptr< CTPPSTrkStation > TrkStation_F
std::vector< CTPPSFastTrack > theCTPPSFastTrack
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
static const double um_to_cm
std::unique_ptr< CTPPSTrkDetector > det1F
void settof(float tof)
void sety2(float y2)
static const double mm_to_um
HLT enums.
edm::EDGetTokenT< CTPPSFastRecHitContainer > _recHitToken
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
void Get_t_and_xi(const TLorentzVector *proton, double &t, double &xi, LimitedBeamInfo const &bi)
Definition: PPSUtilities.cc:72
const GeomDet * recHitDet(const TrackingRecHit &hit, const TrackingGeometry *geom)
Geom::Theta< T > theta() const
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< CTPPSFastTrack > CTPPSFastTrackContainer
void setcellid(unsigned int cellid)
void ReadRecHits(edm::Handle< CTPPSFastRecHitContainer > &)
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)
bool SearchTrack(int, int, int Direction, double &xi, double &t, double &partP, double &pt, double &thx, double &thy, double &x0, double &y0, double &xt, double &yt, double &X1d, double &Y1d, double &X2d, double &Y2d)