35 #include "G4SDManager.hh"
38 #include "G4VProcess.hh"
40 #include "G4PhysicalConstants.hh"
41 #include "G4SystemOfUnits.hh"
61 preStepPoint(nullptr),
62 postStepPoint(nullptr) {
67 SetVerboseLevel(verbn);
71 if (
name ==
"TotemHitsT1") {
73 }
else if (
name ==
"TotemHitsT2Si") {
75 }
else if (
name ==
"TotemHitsT2Gem") {
77 }
else if (
name ==
"TotemHitsRP") {
80 edm::LogWarning(
"ForwardSim") <<
"TotemSD: ReadoutName not supported\n";
107 edm::LogVerbatim(
"ForwardSim") <<
"TotemSD : Initialize called for " << GetName();
121 int thehc_entries =
theHC->entries();
122 for (
int j = 0;
j < thehc_entries &&
j < 15000;
j++) {
126 <<
"\n enrty z " << aHit->
getEntry().z() <<
"\n theta "
148 theHC->PrintAllHits();
159 edm::LogVerbatim(
"ForwardSim") <<
" Dispatched BeginOfEvent for " << GetName() <<
" !";
167 G4ThreeVector localPoint;
168 const G4VTouchable* touch =
preStepPoint->GetTouchable();
169 localPoint = touch->GetHistory()->GetTopTransform().TransformPoint(global);
184 edeposit = aStep->GetTotalEnergyDeposit();
195 Pabs = aStep->GetPreStepPoint()->GetMomentum().mag() /
CLHEP::GeV;
196 Tof = aStep->GetPostStepPoint()->GetGlobalTime() / CLHEP::nanosecond;
201 ThetaAtEntry = aStep->GetPreStepPoint()->GetPosition().theta() / CLHEP::deg;
202 PhiAtEntry = aStep->GetPreStepPoint()->GetPosition().phi() / CLHEP::deg;
212 edm::LogWarning(
"ForwardSim") <<
"***** TotemSD error: primaryID = " <<
primaryID <<
" maybe detector name changed";
230 int thehc_entries =
theHC->entries();
231 for (
int j = 0;
j < thehc_entries && !
found;
j++) {
252 <<
" PVid = " <<
currentPV->GetCopyNo() <<
" Unit " <<
unitID <<
"\n primary "
254 <<
" which is a " <<
theTrack->GetDefinition()->GetParticleName();
262 if (
theTrack->GetCreatorProcess() !=
nullptr)
316 G4ThreeVector _PosizioEvo;
331 const G4ThreeVector& Pos,
double vx,
double vy,
double vz,
double pabs,
int& accettanza) {
334 G4ThreeVector PosEvo;
335 double ThetaX = std::atan((Pos.x() - vx) / (Pos.z() - vz));
336 double ThetaY = std::atan((Pos.y() - vy) / (Pos.z() - vz));
337 double X_at_0 = (vx - ((Pos.x() - vx) / (Pos.z() - vz)) * vz) / 1000.;
338 double Y_at_0 = (vy - ((Pos.y() - vy) / (Pos.z() - vz)) * vz) / 1000.;
346 double csi =
std::abs((7000. - pabs) / 7000.);
350 double x_par[no_rp + 1];
351 double y_par[no_rp + 1];
353 double rp[no_rp] = {141., 149., 198., 220.};
355 double leffx[][2] = {{122.5429, -46.9312}, {125.4194, -49.1849}, {152.6, -81.157}, {98.8914, -131.8390}};
357 double leffy[][2] = {{124.2314, -55.4852}, {127.7825, -57.4503}, {179.455, -76.274}, {273.0931, -40.4626}};
359 double avx[][2] = {{0.515483, -1.0123}, {0.494122, -1.0534}, {0.2217, -1.483}, {0.004633, -1.0719}};
361 double avy[][2] = {{0.371418, -1.6327}, {0.349035, -1.6955}, {0.0815, -2.59}, {0.007592, -4.0841}};
363 double ddx[][4] = {{-0.082336, -0.092513, 112.3436, -82.5029},
364 {-0.086927, -0.097670, 114.9513, -82.9835},
365 {-0.092117, -0.0915, 180.6236, -82.443},
366 {-0.050470, 0.058837, 208.1106, 20.8198}};
368 double detlim[][2] = {{0, 0}, {0.0028, 0.0021}, {0, 0}, {0.0008, 0.0013}};
370 double pipelim[][2] = {{0.026, 0.026}, {0.04, 0.04}, {0.0226, 0.0177}, {0.04, 0.04}};
372 for (
int j = 0;
j < no_rp;
j++) {
375 y_par[
j] = ThetaY * (leffy[
j][0] + leffy[
j][1] * csi) + (avy[
j][0] + avy[
j][1] * csi) * Y_at_0;
376 x_par[
j] = ThetaX * (leffx[
j][0] + leffx[
j][1] * csi) + (avx[
j][0] + avx[
j][1] * csi) * X_at_0 -
377 csi * (ddx[
j][0] + (ddx[
j][1] + ddx[
j][2] * ThetaX) * csi + ddx[
j][3] * ThetaX);
381 if (
std::abs(y_par[0]) < pipelim[0][1] &&
sqrt((y_par[0] * y_par[0]) + (x_par[0] * x_par[0])) < pipelim[0][0]) {
383 if ((
sqrt((y_par[1] * y_par[1]) + (x_par[1] * x_par[1])) < pipelim[1][0]) &&
384 (
std::abs(y_par[1]) > detlim[1][1] || x_par[1] > detlim[1][0])) {
390 if (
std::abs(y_par[0]) < pipelim[0][1] &&
sqrt((y_par[0]) * (y_par[0]) + (x_par[0]) * (x_par[0])) < pipelim[0][0]) {
392 if (
std::abs(y_par[2]) < pipelim[2][1] &&
sqrt((y_par[2] * y_par[2]) + (x_par[2] * x_par[2])) < pipelim[2][0]) {
394 if ((
sqrt((y_par[3] * y_par[3]) + (x_par[3] * x_par[3])) < pipelim[3][0]) &&
395 (
std::abs(y_par[3]) > detlim[3][1] || x_par[3] > detlim[3][0])) {
398 PosEvo.setX(1000 * x_par[3]);
399 PosEvo.setY(1000 * y_par[3]);
400 PosEvo.setZ(1000 * rp[3]);
402 PosEvo.setZ(-1000 * rp[3]);
444 if (
hit ==
nullptr) {
445 edm::LogWarning(
"ForwardSim") <<
"TotemSD: hit to be stored is NULL !!";