22 double dphimin = dmin / cell.caloDDE()->r();
26 double dphi = cell.caloDDE()->dphi();
27 if (dphi < dphimin) dphi = dphimin;
28 double CellPhimin = cell.caloDDE()->phi() - dphi * 0.5;
29 double CellPhimax = cell.caloDDE()->phi() + dphi * 0.5;
34 if (cell.caloDDE()->z() < 0) isign = -1;
35 double dr = cell.caloDDE()->dr();
40 if (dr == 0) dr = drFix;
42 if (dr < dmin) dr = dmin;
43 double dz = cell.caloDDE()->dz();
44 if (dz == 0) dz = dzFix;
46 if (dz < dmin) dz = dmin;
48 double CellZmin = cell.caloDDE()->z() - isign * dz * 0.5;
49 double CellZmax = cell.caloDDE()->z() + isign * dz * 0.5;
50 double CellRmin = cell.caloDDE()->r() - dr * 0.5;
51 double CellRmax = cell.caloDDE()->r() + dr * 0.5;
58 if (dir.mag() == 0)
return 0.;
59 dir = dir / dir.mag();
63 double r0 = (entrance.x() - cell.caloDDE()->x()) * sin(dir.phi()) - (entrance.y() - cell.caloDDE()->y()) * cos(dir.phi());
65 if (fabs(r0) > sqrt(cell.caloDDE()->r() * cell.caloDDE()->r() * dphi * dphi + dr * dr)) crossing =
false;
69 double rz0 = (entrance.perp() - cell.caloDDE()->r()) * cos(dir.theta()) - (entrance.z() - cell.caloDDE()->z()) * sin(dir.theta());
70 if (fabs(rz0) > sqrt(dr * dr + dz * dz)) crossing =
false;
73 if (!crossing)
return 0.;
77 Amg::Vector3D Corner0(CellRmin * cos(CellPhimin), CellRmin * sin(CellPhimin), CellZmin);
78 Amg::Vector3D Corner1(CellRmin * cos(CellPhimax), CellRmin * sin(CellPhimax), CellZmin);
79 Amg::Vector3D Corner2(CellRmin * cos(CellPhimin), CellRmin * sin(CellPhimin), CellZmax);
80 Amg::Vector3D Corner3(CellRmin * cos(CellPhimax), CellRmin * sin(CellPhimax), CellZmax);
82 Amg::Vector3D Corner4(CellRmax * cos(CellPhimin), CellRmax * sin(CellPhimin), CellZmin);
83 Amg::Vector3D Corner5(CellRmax * cos(CellPhimax), CellRmax * sin(CellPhimax), CellZmin);
84 Amg::Vector3D Corner6(CellRmax * cos(CellPhimin), CellRmax * sin(CellPhimin), CellZmax);
85 Amg::Vector3D Corner7(CellRmax * cos(CellPhimax), CellRmax * sin(CellPhimax), CellZmax);
110 double dotp1 = fabs(dirT.dot(dir01) / dir01.mag() / dirT.mag());
111 double dotp2 = fabs(dirT.dot(dir02) / dir02.mag() / dirT.mag());
112 double dotp4 = fabs(dirT.dot(dir04) / dir04.mag() / dirT.mag());
128 mEntry.col(2) = dirT;
132 if (dotp1 <= dotp2 && dotp2 <= dotp4) {
134 mEntry.col(0) = dir01;
135 mEntry.col(1) = dir02;
136 mExit.col(0) = dir67;
137 mExit.col(1) = dir64;
138 }
else if (dotp1 <= dotp4 && dotp4 <= dotp2) {
140 mEntry.col(0) = dir01;
141 mEntry.col(1) = dir04;
142 mExit.col(0) = dir67;
143 mExit.col(1) = dir62;
144 }
else if (dotp2 <= dotp1 && dotp1 <= dotp4) {
146 mEntry.col(0) = dir02;
147 mEntry.col(1) = dir01;
148 mExit.col(0) = dir64;
149 mExit.col(1) = dir67;
150 }
else if (dotp2 <= dotp4 && dotp4 <= dotp1) {
152 mEntry.col(0) = dir02;
153 mEntry.col(1) = dir04;
154 mExit.col(0) = dir64;
155 mExit.col(1) = dir62;
156 }
else if (dotp4 <= dotp2 && dotp2 <= dotp1) {
158 mEntry.col(0) = dir04;
159 mEntry.col(1) = dir02;
160 mExit.col(0) = dir62;
161 mExit.col(1) = dir64;
162 }
else if (dotp4 <= dotp1 && dotp1 <= dotp2) {
164 mEntry.col(0) = dir04;
165 mEntry.col(1) = dir01;
166 mExit.col(0) = dir62;
167 mExit.col(1) = dir67;
172 Amg::Vector3D posEn = entrance - (Corner1 + Corner2 + Corner4) / 2.;
173 Amg::Vector3D posEx = entrance - (Corner2 + Corner4 + Corner7) / 2.;
182 int type0 =
type - 10 * int(
type / 10);
185 posEn += Corner1 / 2.;
186 posEx += Corner7 / 2.;
190 posEn += Corner2 / 2.;
191 posEx += Corner4 / 2.;
195 posEn += Corner4 / 2.;
196 posEx += Corner2 / 2.;
201 int typeCheck = type0;
207 int type1 = int((
type - 100 *
int(
type / 100)) / 10);
208 int type2 = int(
type / 100);
209 if (type1 == 1) posEn += Corner1 / 2.;
210 if (type1 == 2) posEn += Corner2 / 2.;
211 if (type1 == 4) posEn += Corner4 / 2.;
213 mEntry.col(1) = dir01;
214 posEn -= Corner1 / 2.;
217 mEntry.col(1) = dir02;
218 posEn -= Corner2 / 2.;
221 mEntry.col(1) = dir04;
222 posEn -= Corner4 / 2.;
227 if (type2 == 1) posEn += Corner1 / 2.;
228 if (type2 == 2) posEn += Corner2 / 2.;
229 if (type2 == 4) posEn += Corner4 / 2.;
231 mEntry.col(0) = dir01;
232 posEn -= Corner1 / 2.;
235 mEntry.col(0) = dir02;
236 posEn -= Corner2 / 2.;
239 mEntry.col(0) = dir04;
240 posEn -= Corner4 / 2.;
249 posXEn = entrance - dirT * pathEn.z();
250 if (typeCheck == 1) {
252 acos(cos(posXEn.phi()) * cos((CellPhimax + CellPhimin) / 2.) + sin(posXEn.phi()) * sin((CellPhimax + CellPhimin) / 2.));
253 if (dphiCheck > fabs(CellPhimax - CellPhimin)) { crossingEn =
false; }
255 if (typeCheck == 2) {
256 if (posXEn.perp() < CellRmin) crossingEn =
false;
257 if (posXEn.perp() > CellRmax) crossingEn =
false;
259 if (typeCheck == 4) {
260 if (isign * posXEn.z() < isign * CellZmin) crossingEn =
false;
261 if (isign * posXEn.z() > isign * CellZmax) crossingEn =
false;
265 if (!crossingEn)
return 0.;
273 int type1 = int((
type - 100 *
int(
type / 100)) / 10);
274 int type2 = int(
type / 100);
275 if (type1 == 1) posEx += Corner7 / 2.;
276 if (type1 == 2) posEx += Corner4 / 2.;
277 if (type1 == 4) posEx += Corner2 / 2.;
279 mExit.col(1) = dir67;
280 posEx -= Corner7 / 2.;
283 mExit.col(1) = dir64;
284 posEx -= Corner4 / 2.;
287 mExit.col(1) = dir62;
288 posEx -= Corner2 / 2.;
293 if (type2 == 1) posEx += Corner7 / 2.;
294 if (type2 == 2) posEx += Corner4 / 2.;
295 if (type2 == 4) posEx += Corner2 / 2.;
297 mExit.col(0) = dir67;
298 posEx -= Corner7 / 2.;
301 mExit.col(0) = dir64;
302 posEx -= Corner4 / 2.;
305 mExit.col(0) = dir62;
306 posEx -= Corner2 / 2.;
315 posXEx = entrance - dirT * pathEx.z();
316 if (typeCheck == 1) {
318 acos(cos(posXEx.phi()) * cos((CellPhimax + CellPhimin) / 2.) + sin(posXEx.phi()) * sin((CellPhimax + CellPhimin) / 2.));
319 if (dphiCheck > fabs(CellPhimax - CellPhimin)) { crossingEx =
false; }
321 if (typeCheck == 2) {
322 if (posXEx.perp() < CellRmin) crossingEx =
false;
323 if (posXEx.perp() > CellRmax) crossingEx =
false;
325 if (typeCheck == 4) {
326 if (isign * posXEx.z() < isign * CellZmin) crossingEx =
false;
327 if (isign * posXEx.z() > isign * CellZmax) crossingEx =
false;
331 if (crossingEn && crossingEx) {
332 path = (posXEx - posXEn).
mag();
358 unsigned int SampleID = cell.caloDDE()->getSampling();
360 constexpr double CellZB[9] = {141.495, 424.49, 707.485, 999.605, 1300.855, 1615.8, 1949., 2300.46, 2651.52};
361 constexpr double CellDZB[9] = {282.99, 283., 282.99, 301.25, 301.25, 328.64, 337.76, 365.16, 336.96};
362 constexpr double CellZC[9] = {159.755, 483.83, 812.465, 1150.23, 1497.125, 1857.71, 2241.12, 2628.695, 0};
363 constexpr double CellDZC[9] = {319.51, 328.64, 328.63, 346.9, 346.89, 374.28, 392.54, 382.61, 0};
367 if (SampleID == 13 && (fabs(cell.caloDDE()->eta() - 0.85) < 0.001 || fabs(cell.caloDDE()->eta() + 0.85) < 0.001)) isBC9 =
true;
372 double Layer1X(exit.x()), Layer1Y(exit.y()), Layer1Z(exit.z());
373 double Layer2X(entrance.x()), Layer2Y(entrance.y()), Layer2Z(entrance.z());
375 double CellPhimin = cell.caloDDE()->phi() - cell.caloDDE()->dphi() * 0.5;
376 double CellPhimax = cell.caloDDE()->phi() + cell.caloDDE()->dphi() * 0.5;
377 double CellZmin = cell.caloDDE()->z() - cell.caloDDE()->dz() * 0.5;
378 double CellZmax = cell.caloDDE()->z() + cell.caloDDE()->dz() * 0.5;
379 double CellRmin = cell.caloDDE()->r() - cell.caloDDE()->dr() * 0.5;
380 double CellRmax = cell.caloDDE()->r() + cell.caloDDE()->dr() * 0.5;
383 if (cell.caloDDE()->dr() == 0) {
385 double CellVolume = cell.caloDDE()->volume();
386 double product = cell.caloDDE()->dphi() * cell.caloDDE()->r() * cell.caloDDE()->dz();
387 double drFormula = 0;
388 if (product != 0) { drFormula = CellVolume / product; }
389 CellRmin = cell.caloDDE()->r() - drFormula * 0.5;
390 CellRmax = cell.caloDDE()->r() + drFormula * 0.5;
395 double CellXimp[2], CellYimp[2], CellZimp[2];
396 double X(0), Y(0), Z(0),
Phi(0);
404 if (lBC == 1 && isBC9)
break;
406 if (sqrt((Layer1X - Layer2X) * (Layer1X - Layer2X) + (Layer1Y - Layer2Y) * (Layer1Y - Layer2Y)) < 3818.5) {
407 if (SampleID == 13 && lBC == 0) {
408 int cpos = fabs(cell.caloDDE()->eta()) / 0.1;
412 CellZmin = CellZB[cpos] - 0.5 * CellDZB[cpos];
413 CellZmax = CellZB[cpos] + 0.5 * CellDZB[cpos];
415 else if (SampleID == 13 && lBC == 1) {
416 int cpos = fabs(cell.caloDDE()->eta()) / 0.1;
420 CellZmin = CellZC[cpos] - 0.5 * CellDZC[cpos];
421 CellZmax = CellZC[cpos] + 0.5 * CellDZC[cpos];
425 double Sxy = (Layer2X - Layer1X) / (Layer2Y - Layer1Y);
426 double Sxz = (Layer2X - Layer1X) / (Layer2Z - Layer1Z);
427 double Syz = (Layer2Y - Layer1Y) / (Layer2Z - Layer1Z);
431 double Radius(CellRmin);
433 double x0int(exit.x()), x1int(entrance.x()), y0int(exit.y()), y1int(entrance.y()), z0int(exit.z()), z1int(entrance.z());
434 double S((y1int - y0int) / (x1int - x0int));
435 double a(1 + S * S), b(2 * S * y0int - 2 * S * S * x0int),
436 c(y0int * y0int - Radius * Radius + S * S * x0int * x0int - 2 * y0int * S * x0int);
437 double x1((-b + sqrt(b * b - 4 *
a * c)) / (2 *
a)), x2((-b - sqrt(b * b - 4 *
a * c)) / (2 *
a));
438 double y1(y0int + S * (x1 - x0int)), y2(y0int + S * (x2 - x0int));
439 double S1 = ((z1int - z0int) / (x1int - x0int));
440 double z1(z0int +
S1 * (x1 - x0int)), z2(z0int +
S1 * (x2 - x0int));
446 if (((x1 - x0int) * (x1 - x0int) + (y1 - y0int) * (y1 - y0int) + (z1 - z0int) * (z1 - z0int)) >
447 ((x2 - x0int) * (x2 - x0int) + (y2 - y0int) * (y2 - y0int) + (z2 - z0int) * (z2 - z0int))) {
453 if (CellRmin != CellRmax) {
454 Phi = acos(X / sqrt(X * X + Y * Y));
455 if (Y <= 0) Phi = -Phi;
458 if (Z >= CellZmin && Z <= CellZmax && Phi >= CellPhimin && Phi <= CellPhimax) {
468 c = y0int * y0int - Radius * Radius + S * S * x0int * x0int - 2 * y0int * S * x0int;
469 x1 = ((-b + sqrt(b * b - 4 *
a * c)) / (2 *
a));
470 x2 = ((-b - sqrt(b * b - 4 *
a * c)) / (2 *
a));
471 y1 = (y0int + S * (x1 - x0int));
472 y2 = (y0int + S * (x2 - x0int));
473 z1 = (z0int +
S1 * (x1 - x0int));
474 z2 = (z0int +
S1 * (x2 - x0int));
475 S1 = ((z1int - z0int) / (x1int - x0int));
481 if (((x1 - x0int) * (x1 - x0int) + (y1 - y0int) * (y1 - y0int) + (z1 - z0int) * (z1 - z0int)) >
482 ((x2 - x0int) * (x2 - x0int) + (y2 - y0int) * (y2 - y0int) + (z2 - z0int) * (z2 - z0int))) {
488 Phi = std::acos(X / sqrt(X * X + Y * Y));
489 if (Y <= 0) Phi = -Phi;
492 if (Z >= CellZmin && Z <= CellZmax && Phi >= CellPhimin && Phi <= CellPhimax) {
501 if (CellZmin != CellZmax) {
504 X = Layer1X + Sxz * (Z - Layer1Z);
505 Y = Layer1Y + Syz * (Z - Layer1Z);
506 const double R = sqrt(X * X + Y * Y);
507 Phi = std::acos(X / R);
508 if (Y <= 0) Phi = -Phi;
509 if (R >= CellRmin && R <= CellRmax && Phi >= CellPhimin && Phi <= CellPhimax) {
519 X = Layer1X + Sxz * (Z - Layer1Z);
520 Y = Layer1Y + Syz * (Z - Layer1Z);
521 const double R = sqrt(X * X + Y * Y);
522 Phi = std::acos(X / R);
523 if (Y <= 0) Phi = -Phi;
524 if (R >= CellRmin && R <= CellRmax && Phi >= CellPhimin && Phi <= CellPhimax) {
534 if (CellPhimin != CellPhimax) {
536 X = (Layer1X - Sxy * Layer1Y) / (1 - Sxy * tan(CellPhimin));
537 Y = X * std::tan(CellPhimin);
538 Z = Layer1Z + (1 / Sxz) * (X - Layer1X);
539 const double R = sqrt(X * X + Y * Y);
540 Phi = std::acos(X / R);
541 if (Y <= 0) Phi = -Phi;
542 DeltaPhi = fabs(Phi - CellPhimin);
543 if (DeltaPhi > 3.141593) DeltaPhi = fabs(Phi + CellPhimin);
544 if (R >= CellRmin && R <= CellRmax && Z >= CellZmin && Z <= CellZmax && DeltaPhi < 0.0001) {
553 X = (Layer1X - Sxy * Layer1Y) / (1 - Sxy * tan(CellPhimax));
554 Y = X * std::tan(CellPhimax);
555 Z = Layer1Z + (1 / Sxz) * (X - Layer1X);
556 const double R = sqrt(X * X + Y * Y);
558 if (Y <= 0) Phi = -Phi;
559 DeltaPhi = fabs(Phi - CellPhimax);
560 if (DeltaPhi > 3.141593) DeltaPhi = fabs(Phi + CellPhimax);
561 if (R >= CellRmin && R <= CellRmax && Z >= CellZmin && Z <= CellZmax && DeltaPhi < 0.0001) {
572 pathl += sqrt((CellXimp[0] - CellXimp[1]) * (CellXimp[0] - CellXimp[1]) +
573 (CellYimp[0] - CellYimp[1]) * (CellYimp[0] - CellYimp[1]) +
574 (CellZimp[0] - CellZimp[1]) * (CellZimp[0] - CellZimp[1]));
577 if (SampleID == 13 && lBC == 0)