45 #include "CLHEP/Random/RandGauss.h"
46 #include "CLHEP/Units/GlobalPhysicalConstants.h"
48 #include <unordered_map>
74 CLHEP::HepRandomEngine *rndEngine,
76 std::vector<CTPPSLocalTrackLite> &out_tracks,
130 : lhcInfoLabel_(iConfig.getParameter<
std::
string>(
"lhcInfoLabel")),
131 opticsLabel_(iConfig.getParameter<
std::
string>(
"opticsLabel")),
134 produceScoringPlaneHits_(iConfig.getParameter<
bool>(
"produceScoringPlaneHits")),
135 produceRecHits_(iConfig.getParameter<
bool>(
"produceRecHits")),
137 useEmpiricalApertures_(iConfig.getParameter<
bool>(
"useEmpiricalApertures")),
138 empiricalAperture45_(
139 new
TF2(
"empiricalAperture45", iConfig.getParameter<
std::
string>(
"empiricalAperture45").c_str())),
140 empiricalAperture56_(
141 new
TF2(
"empiricalAperture56", iConfig.getParameter<
std::
string>(
"empiricalAperture56").c_str())),
143 produceHitsRelativeToBeam_(iConfig.getParameter<
bool>(
"produceHitsRelativeToBeam")),
144 roundToPitch_(iConfig.getParameter<
bool>(
"roundToPitch")),
145 checkIsHit_(iConfig.getParameter<
bool>(
"checkIsHit")),
147 pitchStrips_(iConfig.getParameter<double>(
"pitchStrips")),
148 insensitiveMarginStrips_(iConfig.getParameter<double>(
"insensitiveMarginStrips")),
150 pitchPixelsHor_(iConfig.getParameter<double>(
"pitchPixelsHor")),
151 pitchPixelsVer_(iConfig.getParameter<double>(
"pitchPixelsVer")),
153 timeResolutionDiamonds45_(
154 new
TF1(
"timeResolutionDiamonds45", iConfig.getParameter<
std::
string>(
"timeResolutionDiamonds45").c_str())),
155 timeResolutionDiamonds56_(
156 new
TF1(
"timeResolutionDiamonds56", iConfig.getParameter<
std::
string>(
"timeResolutionDiamonds56").c_str())),
158 verbosity_(iConfig.getUntrackedParameter<unsigned
int>(
"verbosity", 0)) {
160 produces<std::vector<CTPPSLocalTrackLite>>();
163 produces<edm::DetSetVector<TotemRPRecHit>>();
164 produces<edm::DetSetVector<CTPPSDiamondRecHit>>();
165 produces<edm::DetSetVector<CTPPSPixelRecHit>>();
167 produces<std::map<int, edm::DetSetVector<TotemRPRecHit>>>();
168 produces<std::map<int, edm::DetSetVector<CTPPSDiamondRecHit>>>();
169 produces<std::map<int, edm::DetSetVector<CTPPSPixelRecHit>>>();
181 desc.addUntracked<
unsigned int>(
"verbosity", 0);
183 desc.add<
std::string>(
"lhcInfoLabel",
"")->setComment(
"label of the LHCInfo record");
184 desc.add<
std::string>(
"opticsLabel",
"")->setComment(
"label of the optics records");
187 desc.add<
bool>(
"produceScoringPlaneHits",
true);
188 desc.add<
bool>(
"produceRecHits",
true);
190 desc.add<
bool>(
"useEmpiricalApertures",
false);
191 desc.add<
std::string>(
"empiricalAperture45",
"0")->setComment(
"2D function of xi and xangle for cutoff on sec 45");
192 desc.add<
std::string>(
"empiricalAperture56",
"0")->setComment(
"2D function of xi and xangle for cutoff on sec 56");
194 desc.add<
bool>(
"produceHitsRelativeToBeam",
false);
195 desc.add<
bool>(
"roundToPitch",
true);
196 desc.add<
bool>(
"checkIsHit",
true);
197 desc.add<
double>(
"pitchStrips", 66.e-3);
198 desc.add<
double>(
"insensitiveMarginStrips", 34.e-3);
200 desc.add<
double>(
"pitchPixelsHor", 100.e-3);
201 desc.add<
double>(
"pitchPixelsVer", 150.e-3);
204 ->setComment(
"time resolution of single diamond sensor in sector 45, in ns");
206 ->setComment(
"time resolution of single diamond sensor in sector 56, in ns");
208 descriptions.
add(
"ctppsDirectProtonSimulation",
desc);
236 auto pStripRecHitsPerParticle = std::make_unique<std::map<int, edm::DetSetVector<TotemRPRecHit>>>();
237 auto pDiamondRecHitsPerParticle = std::make_unique<std::map<int, edm::DetSetVector<CTPPSDiamondRecHit>>>();
238 auto pPixelRecHitsPerParticle = std::make_unique<std::map<int, edm::DetSetVector<CTPPSPixelRecHit>>>();
240 std::unique_ptr<std::vector<CTPPSLocalTrackLite>> pTracks(
new std::vector<CTPPSLocalTrackLite>());
248 for (
auto it_vtx = evt->vertices_begin(); it_vtx != evt->vertices_end(); ++it_vtx) {
249 auto vtx = *(it_vtx);
252 for (
auto it_part =
vtx->particles_out_const_begin(); it_part !=
vtx->particles_out_const_end(); ++it_part) {
253 auto part = *(it_part);
256 if (
part->pdg_id() != 2212)
259 if (
part->status() != 1 &&
part->status() < 83)
273 *pStripRecHitsPerParticle,
274 *pPixelRecHitsPerParticle,
275 *pDiamondRecHitsPerParticle);
296 const HepMC::GenVertex *in_vtx,
302 CLHEP::HepRandomEngine *rndEngine,
303 std::vector<CTPPSLocalTrackLite> &out_tracks,
313 std::stringstream ssLog;
316 const HepMC::FourVector &vtx_cms = in_vtx->position();
317 const HepMC::FourVector &mom_cms = in_trk->momentum();
320 HepMC::FourVector vtx_lhc(-vtx_cms.x(), vtx_cms.y(), -vtx_cms.z(), vtx_cms.t());
321 HepMC::FourVector mom_lhc(-mom_cms.x(), mom_cms.y(), -mom_cms.z(), mom_cms.t());
324 unsigned int arm = 3;
326 double beamMomentum = 0.;
328 const std::unique_ptr<TF2> *empiricalAperture;
350 const double time_eff = (vtx_lhc.t() - z_sign * vtx_lhc.z()) / CLHEP::c_light;
353 const double p = mom_lhc.rho();
354 const double xi = 1. -
p / beamMomentum;
355 const double th_x_phys = mom_lhc.x() /
p;
356 const double th_y_phys = mom_lhc.y() /
p;
357 const double vtx_lhc_eff_x = vtx_lhc.x() - vtx_lhc.z() * (mom_lhc.x() / mom_lhc.z() +
xangle);
358 const double vtx_lhc_eff_y = vtx_lhc.y() - vtx_lhc.z() * (mom_lhc.y() / mom_lhc.z());
361 ssLog <<
"simu: xi = " <<
xi <<
", th_x_phys = " << th_x_phys <<
", th_y_phys = " << th_y_phys
362 <<
", vtx_lhc_eff_x = " << vtx_lhc_eff_x <<
", vtx_lhc_eff_y = " << vtx_lhc_eff_y << std::endl;
368 (*empiricalAperture)->SetParameter(
"xi",
xi);
369 (*empiricalAperture)->SetParameter(
"xangle",
xangle);
370 const double th_x_th = (*empiricalAperture)->EvalPar(
nullptr);
372 if (th_x_th > th_x_phys) {
374 ssLog <<
"stop because of empirical appertures";
375 edm::LogInfo(
"CTPPSDirectProtonSimulation") << ssLog.str();
385 const unsigned int rpDecId =
rpId.arm() * 100 +
rpId.station() * 10 +
rpId.rp();
388 if (
rpId.arm() != arm)
392 ssLog <<
" RP " << rpDecId << std::endl;
396 vtx_lhc_eff_x * 1E-1, th_x_phys, vtx_lhc_eff_y * 1E-1, th_y_phys,
xi};
398 ofp.second.transport(k_in, k_out,
true);
400 double b_x = k_out.
x * 1E1, b_y = k_out.
y * 1E1;
401 double a_x = k_out.
th_x, a_y = k_out.
th_y;
408 ofp.second.transport(k_be_in, k_be_out,
true);
410 a_x -= k_be_out.
th_x;
411 a_y -= k_be_out.
th_y;
412 b_x -= k_be_out.
x * 1E1;
413 b_y -= k_be_out.
y * 1E1;
416 const double z_scoringPlane = ofp.second.getScoringPlaneZ() * 1E1;
419 ssLog <<
" proton transported: a_x = " << a_x <<
" rad, a_y = " << a_y <<
" rad, b_x = " << b_x
420 <<
" mm, b_y = " << b_y <<
" mm, z = " << z_scoringPlane <<
" mm" << std::endl;
425 out_tracks.emplace_back(
426 rpId.rawId(), b_x, 0., b_y, 0., 0., 0., 0., 0., 0.,
CTPPSpixelLocalTrackReconstructionInfo::invalid, 0, 0., 0.);
433 for (
const auto &detIdInt :
geometry.sensorsInRP(
rpId)) {
442 double gl_o_z = gl_o.z();
449 A(0, 1) = -gl_a1.x();
450 A(0, 2) = -gl_a2.x();
451 B(0) = gl_o.x() - b_x;
453 A(1, 1) = -gl_a1.y();
454 A(1, 2) = -gl_a2.y();
455 B(1) = gl_o.y() - b_y;
457 A(2, 1) = -gl_a1.z();
458 A(2, 2) = -gl_a2.z();
459 B(2) = gl_o_z - z_scoringPlane;
469 auto h_loc =
geometry.globalToLocal(detId, h_glo);
473 <<
" de z = " <<
P(0) <<
" mm, p1 = " <<
P(1) <<
" mm, p2 = " <<
P(2) <<
" mm" << std::endl
474 <<
" h_glo: x = " << h_glo.x() <<
" mm, y = " << h_glo.y() <<
" mm, z = " << h_glo.z() <<
" mm"
476 <<
" h_loc: c1 = " << h_loc.x() <<
" mm, c2 = " << h_loc.y() <<
" mm, c3 = " << h_loc.z() <<
" mm"
482 double u = h_loc.x();
483 double v = h_loc.y();
486 ssLog <<
" u=" << u <<
", v=" <<
v;
491 ssLog <<
" | no hit" << std::endl;
503 ssLog <<
" | strip=" <<
strip;
509 ssLog <<
" | m=" <<
v <<
", sigma=" << sigma << std::endl;
515 out_strip_hits_per_particle[in_trk->barcode()].find_or_insert(detId);
523 const auto *dg =
geometry.sensor(detIdInt);
525 const auto &diamondDimensions = dg->getDiamondDimensions();
526 const auto x_half_width = diamondDimensions.xHalfWidth;
527 const auto y_half_width = diamondDimensions.yHalfWidth;
528 const auto z_half_width = diamondDimensions.zHalfWidth;
534 if (h_loc.x() < -x_half_width || h_loc.x() > +x_half_width || h_loc.y() < -y_half_width ||
535 h_loc.y() > +y_half_width)
539 const double t0 = time_eff + CLHEP::RandGauss::shoot(rndEngine, 0., time_resolution);
540 const double tot = 1.23456;
541 const double ch_t_precis = time_resolution;
542 const int time_slice = 0;
545 const bool multiHit =
false;
564 out_diamond_hits_per_particle[in_trk->barcode()].find_or_insert(detId);
572 ssLog <<
" pixel plane " << pixelDetId.
plane() <<
": local hit x = " << h_loc.x()
573 <<
" mm, y = " << h_loc.y() <<
" mm, z = " << h_loc.z() <<
" mm" << std::endl;
586 ssLog <<
" hit accepted: m1 = " << h_loc.x() <<
" mm, m2 = " << h_loc.y() <<
" mm" << std::endl;
591 const LocalPoint lp(h_loc.x(), h_loc.y(), h_loc.z());
598 out_pixel_hits_per_particle[in_trk->barcode()].find_or_insert(detId);
605 edm::LogInfo(
"CTPPSDirectProtonSimulation") << ssLog.str();