9 #include "trg/cdc/Fitter3DUtility.h"
10 #include "trg/cdc/FpgaUtility.h"
11 #include "trg/cdc/JLUT.h"
12 #include "trg/cdc/JSignal.h"
13 #include "trg/cdc/JSignalData.h"
16 #include "Fitter3DUtility.h"
19 #include "JSignalData.h"
40 using std::make_tuple;
47 if ((phi2[0] - phi2[4]) > M_PI || (phi2[0] - phi2[4]) < -M_PI) {
48 if (phi2[0] > M_PI) {sign_phi[0] = phi2[0] - 2 * M_PI;}
49 else {sign_phi[0] = phi2[0];}
50 if (phi2[4] > M_PI) {sign_phi[1] = phi2[4] - 2 * M_PI;}
51 else {sign_phi[1] = phi2[4];}
53 sign_phi[0] = phi2[0];
54 sign_phi[1] = phi2[4];
56 if ((sign_phi[1] - sign_phi[0]) > 0) {mysign = 0;}
65 cout <<
"Fitter3DUtility::rPhiFit() will be deprecated. Please use Fitter3DUtility::rPhiFitter(). phierror was changed to inv phi error."
67 double invphierror[5];
68 for (
unsigned i = 0; i < 5; i++) {
69 invphierror[i] = 1 / phierror[i];
71 rPhiFitter(rr, phi2, invphierror, rho, myphi0);
78 rPhiFitter(rr, phi2, invphierror, rho, myphi0, chi2);
90 double A, B, C, D,
E, hcx, hcy;
91 double invFiterror[5];
94 for (
unsigned i = 0; i < 5; i++) {
99 invFiterror[i] = invphierror[i] / rr[i];
103 A = 0, B = 0, C = 0, D = 0,
E = 0;
105 for (
unsigned i = 0; i < 5; i++) {
106 A += cos(phi2[i]) * cos(phi2[i]) * (invFiterror[i] * invFiterror[i]);
107 B += sin(phi2[i]) * sin(phi2[i]) * (invFiterror[i] * invFiterror[i]);
108 C += cos(phi2[i]) * sin(phi2[i]) * (invFiterror[i] * invFiterror[i]);
109 D += rr[i] * cos(phi2[i]) * (invFiterror[i] * invFiterror[i]);
110 E += rr[i] * sin(phi2[i]) * (invFiterror[i] * invFiterror[i]);
114 hcx /= 2 * (A * B - C * C);
116 hcy /= 2 * (A * B - C * C);
117 rho =
sqrt(hcx * hcx + hcy * hcy);
118 myphi0 = atan2(hcy, hcx);
119 if (myphi0 < 0) myphi0 += 2 * M_PI;
131 for (
unsigned iAx = 0; iAx < 5; iAx++) {
132 if (invphierror[iAx] != 0) nTSHits++;
136 for (
unsigned i = 0; i < 5; i++) {
137 chi2 += (2 * (hcx * cos(phi2[i]) + hcy * sin(phi2[i])) - rr[i]) * (2 * (hcx * cos(phi2[i]) + hcy * sin(phi2[i])) - rr[i]) /
138 (invFiterror[i] * invFiterror[i]);
147 vector<double> tsPhi(5);
148 vector<double> dPhi(5);
149 vector<double> dPhi_c(5);
150 vector<double> charge(5);
151 for (
unsigned iAx = 0; iAx < 5; iAx++) {
154 tsPhi[iAx] = tsIds[iAx] * 2 * M_PI / nTSs[iAx];
155 dPhi[iAx] = tsPhi[iAx] - phi0;
158 if (dPhi[iAx] < -M_PI) dPhi_c[iAx] = dPhi[iAx] + 2 * M_PI;
159 else if (dPhi[iAx] > M_PI) dPhi_c[iAx] = dPhi[iAx] - 2 * M_PI;
160 else dPhi_c[iAx] = dPhi[iAx];
163 if (tsHitmap[iAx] == 0) charge[iAx] = 0;
164 else if (dPhi_c[iAx] == 0) charge[iAx] = 0;
165 else if (dPhi_c[iAx] > 0) charge[iAx] = 1;
166 else charge[iAx] = -1;
170 double sumCharge = charge[0] + charge[1] + charge[2] + charge[3] + charge[4];
173 if (sumCharge == 0) foundCharge = inCharge;
174 else if (sumCharge > 0) foundCharge = 1;
175 else foundCharge = -1;
184 double A, B, C, D,
E, hcx, hcy;
188 for (
int i = 0; i < nTS; i++) {
190 fiterror[i] = 1 + 0 * phierror[i];
194 A = 0, B = 0, C = 0, D = 0,
E = 0;
196 for (
int i = 0; i < nTS; i++) {
197 A += cos(phi2[i]) * cos(phi2[i]) / (fiterror[i] * fiterror[i]);
198 B += sin(phi2[i]) * sin(phi2[i]) / (fiterror[i] * fiterror[i]);
199 C += cos(phi2[i]) * sin(phi2[i]) / (fiterror[i] * fiterror[i]);
200 D += rr[i] * cos(phi2[i]) / (fiterror[i] * fiterror[i]);
201 E += rr[i] * sin(phi2[i]) / (fiterror[i] * fiterror[i]);
205 hcx /= 2 * (A * B - C * C);
207 hcy /= 2 * (A * B - C * C);
208 rho =
sqrt(hcx * hcx + hcy * hcy);
209 myphi0 = atan2(hcy, hcx);
210 if (myphi0 < 0) myphi0 += 2 * M_PI;
231 int tdcMax = pow(2, nBits) - 1;
234 if (resultTdc > tdcMax) resultTdc -= (tdcMax + 1);
235 else if (resultTdc < 0) resultTdc += (tdcMax + 1);
238 return (
unsigned) resultTdc;
244 double result = wirePhi;
247 double t_dPhi = driftLength;
251 t_dPhi =
atan(t_dPhi / rr);
254 if (lr == 1) result -= t_dPhi;
255 else if (lr == 2) result += t_dPhi;
263 double t_driftLength = (driftTime - eventTime) * 1000 / 1017.774 * 2 * 40 / 1000 / 10;
264 return calPhi(wirePhi, t_driftLength, rr, lr);
269 double wirePhi = (double)localId / nWires * 4 * M_PI;
274 std::map<std::string, std::vector<double> >
const& mConstV, std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage,
275 std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage)
282 if (mSignalStorage.find(
"phiFactor_0") == mSignalStorage.end()) {
283 for (
unsigned iSt = 0; iSt < 4; iSt++) {
284 int nShiftBits = int(log(pow(2, 24) / 2 / mConstD.at(
"M_PI") * mConstV.at(
"nTSs")[2 * iSt + 1] *
285 mSignalStorage[
"phi0"].getToReal()) / log(2));
287 t_name =
"phiFactor_" + to_string(iSt);
288 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(2 * mConstD.at(
"M_PI") / mConstV.at(
"nTSs")[2 * iSt + 1],
289 mSignalStorage[
"phi0"].getToReal() / pow(2, nShiftBits), commonData);
294 for (
unsigned iSt = 0; iSt < 4;
295 iSt++) mSignalStorage[
"wirePhi_" + to_string(iSt)] <= mSignalStorage[
"tsId_" + to_string(iSt)] * mSignalStorage[
"phiFactor_" +
303 for (
unsigned iSt = 0; iSt < 4;
304 iSt++) mSignalStorage[
"driftTimeRaw_" + to_string(iSt)] <= mSignalStorage[
"tdc_" + to_string(iSt)] - mSignalStorage[
"eventTime"];
310 if (mSignalStorage.find(
"maxDriftTimeLow") == mSignalStorage.end()) {
311 int maxDriftTime = 287;
312 mSignalStorage[
"maxDriftTimeLow"] =
Belle2::TRGCDCJSignal(-512 + maxDriftTime + 1, mSignalStorage[
"eventTime"].getToReal(),
314 mSignalStorage[
"maxDriftTimeHigh"] =
Belle2::TRGCDCJSignal(maxDriftTime, mSignalStorage[
"eventTime"].getToReal(), commonData);
315 mSignalStorage[
"maxDriftTimeMax"] =
Belle2::TRGCDCJSignal(512, mSignalStorage[
"eventTime"].getToReal(), commonData);
317 for (
unsigned iSt = 0; iSt < 4; iSt++) {
318 string t_in1Name =
"driftTimeRaw_" + to_string(iSt);
319 string t_valueName =
"driftTime_c_" + to_string(iSt);
321 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
324 mSignalStorage[
"eventTimeValid"].getToReal(), commonData));
326 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
327 make_pair(&mSignalStorage[t_valueName],
Belle2::TRGCDCJSignal(0, mSignalStorage[
"eventTime"].getToReal(), commonData))
330 t_data.push_back(make_pair(t_compare, t_assigns));
335 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] + mSignalStorage[
"maxDriftTimeMax"]).limit(mSignalStorage[
"maxDriftTimeLow"], mSignalStorage[
"maxDriftTimeHigh"]))
338 t_data.push_back(make_pair(t_compare, t_assigns));
343 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[
"maxDriftTimeLow"], mSignalStorage[
"maxDriftTimeHigh"]))
346 t_data.push_back(make_pair(t_compare, t_assigns));
351 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] - mSignalStorage[
"maxDriftTimeMax"]).limit(mSignalStorage[
"maxDriftTimeLow"], mSignalStorage[
"maxDriftTimeHigh"]))
354 t_data.push_back(make_pair(t_compare, t_assigns));
369 if (mSignalStorage.find(
"minDriftTime") == mSignalStorage.end()) {
370 int minDriftTime = -8;
371 mSignalStorage[
"minDriftTime"] =
Belle2::TRGCDCJSignal(minDriftTime, mSignalStorage[
"eventTime"].getToReal(), commonData);
372 mSignalStorage[
"minDriftTimeLow"] =
Belle2::TRGCDCJSignal(0, mSignalStorage[
"eventTime"].getToReal(), commonData);
374 for (
unsigned iSt = 0; iSt < 4; iSt++) {
375 string t_in1Name =
"driftTime_c_" + to_string(iSt);
376 string t_valueName =
"driftTime_" + to_string(iSt);
377 string t_in2Name =
"invErrorRho_" + to_string(iSt);
378 string t_value2Name =
"iZError2_" + to_string(iSt);
379 string t_noneErrorName =
"iZNoneError2_" + to_string(iSt);
381 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
385 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
386 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[
"minDriftTimeLow"], mSignalStorage[
"maxDriftTimeHigh"])),
387 make_pair(&mSignalStorage[t_value2Name], mSignalStorage[t_in2Name])
390 t_data.push_back(make_pair(t_compare, t_assigns));
395 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"minDriftTimeLow"]),
396 make_pair(&mSignalStorage[t_value2Name], mSignalStorage[t_in2Name])
399 t_data.push_back(make_pair(t_compare, t_assigns));
404 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"minDriftTimeLow"]),
405 make_pair(&mSignalStorage[t_value2Name], mSignalStorage[t_noneErrorName])
408 t_data.push_back(make_pair(t_compare, t_assigns));
422 if (!mSignalStorage.count(
"invDriftPhiMin")) {
423 mSignalStorage[
"invDriftPhiMin"] =
Belle2::TRGCDCJSignal(0, mSignalStorage[
"driftTime_0"].getToReal(), commonData);
425 mSignalStorage[
"driftTime_0"].getToReal(), commonData);
430 for (
unsigned iSt = 0; iSt < 4; iSt++) {
431 string t_valueName =
"driftPhi_" + to_string(iSt);
432 string t_inName =
"driftTime_" + to_string(iSt);
433 if (!mLutStorage.count(t_valueName)) {
436 double t_parameter = mConstV.at(
"rr3D")[iSt];
437 mLutStorage[t_valueName]->setFloatFunction(
439 [ = ](
double aValue) ->
double{
return atan(mConstV.at(
"driftLengthTableSL" + to_string(2 * iSt + 1))[aValue] / t_parameter);},
440 mSignalStorage[t_inName],
441 mSignalStorage[
"invDriftPhiMin"], mSignalStorage[
"invDriftPhiMax"], mSignalStorage[
"phi0"].getToReal(),
442 (int)mConstD.at(
"driftPhiLUTInBitSize"), (int)mConstD.at(
"driftPhiLUTOutBitSize"));
448 for (
unsigned iSt = 0; iSt < 4; iSt++) {
451 mLutStorage[
"driftPhi_" + to_string(iSt)]->operate(mSignalStorage[
"driftTime_" + to_string(iSt)],
452 mSignalStorage[
"driftPhi_" + to_string(iSt)]);
458 for (
unsigned iSt = 0; iSt < 4; iSt++) {
459 string t_in1Name =
"lr_" + to_string(iSt);
460 string t_valueName =
"finePhi_" + to_string(iSt);
462 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
465 mSignalStorage[t_in1Name].getToReal(), commonData));
467 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
468 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"wirePhi_" + to_string(iSt)] - mSignalStorage[
"driftPhi_" + to_string(iSt)])
471 t_data.push_back(make_pair(t_compare, t_assigns));
474 mSignalStorage[t_in1Name].getToReal(), commonData));
477 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"wirePhi_" + to_string(iSt)] + mSignalStorage[
"driftPhi_" + to_string(iSt)])
480 t_data.push_back(make_pair(t_compare, t_assigns));
485 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"wirePhi_" + to_string(iSt)])
488 t_data.push_back(make_pair(t_compare, t_assigns));
495 if (mSignalStorage.find(
"phiMax_0") == mSignalStorage.end()) {
496 for (
unsigned iSt = 0; iSt < 4; iSt++) {
497 string t_valueName =
"finePhi_" + to_string(iSt);
498 string t_maxName =
"phiMax_" + to_string(iSt);
499 string t_minName =
"phiMin_" + to_string(iSt);
500 string t_2PiName =
"phi2Pi_" + to_string(iSt);
501 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
502 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(-mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
503 mSignalStorage[t_2PiName] =
Belle2::TRGCDCJSignal(2 * mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
506 for (
unsigned iSt = 0; iSt < 4; iSt++) {
507 string t_in1Name =
"finePhi_" + to_string(iSt);
508 string t_valueName =
"phi_" + to_string(iSt);
509 string t_maxName =
"phiMax_" + to_string(iSt);
510 string t_minName =
"phiMin_" + to_string(iSt);
511 string t_2PiName =
"phi2Pi_" + to_string(iSt);
513 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
517 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
518 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] - mSignalStorage[t_2PiName]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
521 t_data.push_back(make_pair(t_compare, t_assigns));
526 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
529 t_data.push_back(make_pair(t_compare, t_assigns));
534 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] + mSignalStorage[t_2PiName]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
537 t_data.push_back(make_pair(t_compare, t_assigns));
547 for (
unsigned iSt = 0; iSt < stXts.size(); ++iSt) {
548 string filename = filePrefix +
".st" + to_string(iSt);
550 cout <<
"Fitter3DUtility::saveStereoXt() Saving xt file to " << filename << endl;
551 xtFile.open(filename);
552 for (
unsigned iTick = 0; iTick < stXts[iSt].size(); ++iTick) {
553 xtFile << stXts[iSt][iTick] << endl;
561 stXts = vector<vector<double> > (nFiles);
562 for (
unsigned iSt = 0; iSt < stXts.size(); ++iSt) {
563 string filename = filePrefix +
".st" + to_string(iSt);
565 xtFile.open(filename.c_str());
567 cout <<
"Fitter3DUtility::loadStereoXt() Cannot load " << filename << endl;
571 while (getline(xtFile, line)) {
572 stXts[iSt].push_back(std::stof(line));
580 return (
double)
id / stNWires[iSt] * 4 * M_PI;
586 int eventTime, vector<vector<int> >
const& rawStTSs, vector<double>& stTSs)
588 stTSs = vector<double> (4, 9999);
589 if (eventTimeValid == 0) {
590 for (
unsigned iSt = 0; iSt < 4; iSt++) {
591 stTSs[iSt] =
stereoIdToPhi(stGeometry[
"nWires"], iSt, rawStTSs[iSt][0]);
595 for (
unsigned iSt = 0; iSt < 4; iSt++) {
596 if (rawStTSs[iSt][1] != 0) {
598 int t = rawStTSs[iSt][2] - eventTime;
601 if (t > 511) t = 511;
602 double driftLength = stXts[iSt][t];
604 stGeometry[
"cdcRadius"][iSt], rawStTSs[iSt][1]);
613 double phiMin = -M_PI;
614 double phiMax = M_PI;
615 double result = value - refPhi;
617 while (rangeOK == 0) {
618 if (result > phiMax) result -= 2 * M_PI;
619 else if (result < phiMin) result += 2 * M_PI;
627 double refPhi = (double)refId / nTSs * 2 * M_PI;
633 int result = value - refId;
635 while (rangeOk == 0) {
636 if (result >= nTSs) result -= nTSs;
637 else if (result < 0) result += nTSs;
646 double phiMin = -M_PI;
647 double phiMax = M_PI;
649 while (rangeOK == 0) {
650 if (value > phiMax) value -= 2 * M_PI;
651 else if (value < phiMin) value += 2 * M_PI;
656 if (value > M_PI_2) result = 2;
657 else if (value > 0) result = 1;
658 else if (value > -M_PI_2) result = 4;
659 else if (value > -M_PI) result = 3;
666 std::vector<double>& invZError2)
668 vector<double> driftZError({0.7676, 0.9753, 1.029, 1.372});
669 vector<double> wireZError({0.7676, 0.9753, 1.029, 1.372});
670 vector<double> zError(4, 9999);
671 invZError2 = vector<double> (4, 0);
672 for (
unsigned iSt = 0; iSt < 4; ++iSt) {
673 if (rawStTSs[iSt][1] != 0) {
675 if (rawStTSs[iSt][1] != 3 && eventTimeValid != 0) zError[iSt] = driftZError[iSt];
676 else zError[iSt] = wireZError[iSt];
678 invZError2[iSt] = 1 / pow(zError[iSt], 2);
684 std::map<std::string, std::vector<double> >
const& mConstV, std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage)
688 if (mSignalStorage.find(
"iZWireError2_0") == mSignalStorage.end()) {
689 for (
unsigned iSt = 0; iSt < 4; iSt++) {
691 t_name =
"iZWireError2_" + to_string(iSt);
692 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(mConstD.at(
"iError2BitSize"), 1 / pow(mConstV.at(
"wireZError")[iSt], 2), 0,
693 mConstD.at(
"iError2Max"), -1, commonData);
694 t_name =
"iZDriftError2_" + to_string(iSt);
695 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(mConstD.at(
"iError2BitSize"), 1 / pow(mConstV.at(
"driftZError")[iSt], 2), 0,
696 mConstD.at(
"iError2Max"), -1, commonData);
697 t_name =
"iZNoneError2_" + to_string(iSt);
698 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(mConstD.at(
"iError2BitSize"), 0, 0, mConstD.at(
"iError2Max"), -1, commonData);
707 for (
unsigned iSt = 0; iSt < 4; iSt++) {
708 string t_in1Name =
"lr_" + to_string(iSt);
709 string t_valueName =
"invErrorLR_" + to_string(iSt);
710 string t_noneErrorName =
"iZNoneError2_" + to_string(iSt);
711 string t_driftErrorName =
"iZDriftError2_" + to_string(iSt);
712 string t_wireErrorName =
"iZWireError2_" + to_string(iSt);
714 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
717 mSignalStorage[t_in1Name].getToReal(), commonData));
719 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
720 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_noneErrorName])
723 t_data.push_back(make_pair(t_compare, t_assigns));
726 mSignalStorage[t_in1Name].getToReal(), commonData));
729 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_wireErrorName])
732 t_data.push_back(make_pair(t_compare, t_assigns));
737 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_driftErrorName])
740 t_data.push_back(make_pair(t_compare, t_assigns));
747 if (mSignalStorage.find(
"halfRadius_0") == mSignalStorage.end()) {
748 for (
unsigned iSt = 0; iSt < 4; iSt++) {
750 t_name =
"halfRadius_" + to_string(iSt);
751 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(mConstV.at(
"rr")[iSt * 2 + 1] / 2, mSignalStorage[
"rho"].getToReal(), commonData);
757 for (
unsigned iSt = 0; iSt < 4; iSt++) {
758 string t_compareName =
"halfRadius_" + to_string(iSt);
760 string t_valueName =
"invErrorRho_" + to_string(iSt);
761 string t_noneErrorName =
"iZNoneError2_" + to_string(iSt);
762 string t_in1Name =
"invErrorLR_" + to_string(iSt);
764 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
768 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
769 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_noneErrorName])
772 t_data.push_back(make_pair(t_compare, t_assigns));
777 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name])
780 t_data.push_back(make_pair(t_compare, t_assigns));
789 if (
false) cout << anglest << ztostraw << endl;
791 double myphiz, acos_real;
794 if (rr > (2 * rho)) t_rho = rr / 2;
795 acos_real = acos(rr / (2 * t_rho));
797 myphiz = +acos_real + myphi0;
799 myphiz = -acos_real + myphi0;
801 if (myphiz > M_PI) myphiz -= 2 * M_PI;
802 if (myphiz < -M_PI) myphiz += 2 * M_PI;
809 if (
false) cout << anglest << ztostraw << endl;
811 double myphiz, acos_real;
814 if (rr > (2 * rho)) t_rho = rr / 2;
815 acos_real = acos(rr / (2 * t_rho));
817 myphiz = -acos_real - myphi0 + phi2;
819 myphiz = +acos_real - myphi0 + phi2;
821 if (myphiz > M_PI) myphiz -= 2 * M_PI;
822 if (myphiz < -M_PI) myphiz += 2 * M_PI;
828 std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage)
832 if (mSignalStorage.find(
"rhoMin_0") == mSignalStorage.end()) {
833 for (
unsigned iSt = 0; iSt < 4; iSt++) {
835 string t_minName =
"rhoMin_" + to_string(iSt);
836 double t_actual = (mConstV.find(
"rr")->second)[2 * iSt + 1] / 2;
837 double t_toReal = mSignalStorage[
"rho"].getToReal();
840 if (mSignalStorage[t_minName].getRealInt() < t_actual) {
841 t_actual += 1 * t_toReal;
847 string t_maxName =
"rhoMax_" + to_string(iSt);
848 t_actual = mSignalStorage[
"rho"].getMaxActual();
857 for (
unsigned iSt = 0; iSt < 4; iSt++) {
858 string t_in1Name =
"rho";
859 string t_valueName =
"rho_c_" + to_string(iSt);
860 string t_maxName =
"rhoMax_" + to_string(iSt);
861 string t_minName =
"rhoMin_" + to_string(iSt);
863 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
867 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
868 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_maxName]),
871 t_data.push_back(make_pair(t_compare, t_assigns));
876 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[t_minName], mSignalStorage[t_maxName]))
879 t_data.push_back(make_pair(t_compare, t_assigns));
884 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_minName])
887 t_data.push_back(make_pair(t_compare, t_assigns));
894 double Fitter3DUtility::calZ(
int mysign,
double anglest,
double ztostraw,
double rr,
double phi2,
double rho,
double myphi0)
896 double myphiz = 0, acos_real = 0, dPhiAx = 0;
899 if (rr > (2 * rho)) t_rho = rr / 2;
900 acos_real = acos(rr / (2 * t_rho));
902 dPhiAx = -acos_real - myphi0;
904 dPhiAx = acos_real - myphi0;
906 myphiz = dPhiAx + phi2;
907 if (myphiz > M_PI) myphiz -= 2 * M_PI;
908 if (myphiz < -M_PI) myphiz += 2 * M_PI;
910 return (ztostraw - rr * 2 * sin(myphiz / 2) / anglest);
913 void Fitter3DUtility::calZ(std::map<std::string, double>
const& mConstD, std::map<std::string, std::vector<double> >
const& mConstV,
914 std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage, std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage)
918 if (mSignalStorage.find(
"invPhiAxMin_0") == mSignalStorage.end()) {
935 for (
unsigned iSt = 0; iSt < 4; iSt++) {
936 string t_invMinName =
"invPhiAxMin_" + to_string(iSt);
938 double t_actual = mSignalStorage[
"rho_c_" + to_string(iSt)].getMinActual();
939 double t_toReal = mSignalStorage[
"rho_c_" + to_string(iSt)].getToReal();
941 string t_invMaxName =
"invPhiAxMax_" + to_string(iSt);
942 t_actual = mSignalStorage[
"rho_c_" + to_string(iSt)].getMaxActual();
950 for (
unsigned iSt = 0; iSt < 4; iSt++) {
951 string t_valueName =
"phiAx_" + to_string(iSt);
952 string t_minName =
"phiAxMin_" + to_string(iSt);
953 string t_maxName =
"phiAxMax_" + to_string(iSt);
954 string t_invMinName =
"invPhiAxMin_" + to_string(iSt);
955 string t_invMaxName =
"invPhiAxMax_" + to_string(iSt);
956 if (!mLutStorage.count(t_valueName)) {
959 double t_parameter = mConstV.at(
"rr3D")[iSt];
960 mLutStorage[t_valueName]->setFloatFunction(
961 [ = ](
double aValue) ->
double{
return acos(t_parameter / 2 / aValue);},
963 mSignalStorage[
"rho_c_" + to_string(iSt)],
964 mSignalStorage[t_invMinName], mSignalStorage[t_invMaxName], mSignalStorage[
"phi0"].getToReal(),
965 (int)mConstD.at(
"acosLUTInBitSize"), (int)mConstD.at(
"acosLUTOutBitSize"));
971 for (
unsigned iSt = 0; iSt < 4; iSt++) {
973 string t_valueName =
"phiAx_" + to_string(iSt);
975 mLutStorage[t_valueName]->operate(mSignalStorage[
"rho_c_" + to_string(iSt)], mSignalStorage[t_valueName]);
983 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
986 commonData),
"=", mSignalStorage[
"charge"]);
988 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
989 make_pair(&mSignalStorage[
"dPhiAx_0"], -mSignalStorage[
"phiAx_0"] - mSignalStorage[
"phi0"]),
990 make_pair(&mSignalStorage[
"dPhiAx_1"], -mSignalStorage[
"phiAx_1"] - mSignalStorage[
"phi0"]),
991 make_pair(&mSignalStorage[
"dPhiAx_2"], -mSignalStorage[
"phiAx_2"] - mSignalStorage[
"phi0"]),
992 make_pair(&mSignalStorage[
"dPhiAx_3"], -mSignalStorage[
"phiAx_3"] - mSignalStorage[
"phi0"])
995 t_data.push_back(make_pair(t_compare, t_assigns));
1000 make_pair(&mSignalStorage[
"dPhiAx_0"], mSignalStorage[
"phiAx_0"] - mSignalStorage[
"phi0"]),
1001 make_pair(&mSignalStorage[
"dPhiAx_1"], mSignalStorage[
"phiAx_1"] - mSignalStorage[
"phi0"]),
1002 make_pair(&mSignalStorage[
"dPhiAx_2"], mSignalStorage[
"phiAx_2"] - mSignalStorage[
"phi0"]),
1003 make_pair(&mSignalStorage[
"dPhiAx_3"], mSignalStorage[
"phiAx_3"] - mSignalStorage[
"phi0"])
1006 t_data.push_back(make_pair(t_compare, t_assigns));
1013 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1014 mSignalStorage[
"dPhi_" + to_string(iSt)] <= mSignalStorage[
"dPhiAx_" + to_string(iSt)] + mSignalStorage[
"phi_" + to_string(iSt)];
1019 if (mSignalStorage.find(
"dPhiPiMax_0") == mSignalStorage.end()) {
1020 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1021 string t_valueName =
"dPhi_" + to_string(iSt);
1022 string t_maxName =
"dPhiPiMax_" + to_string(iSt);
1023 string t_minName =
"dPhiPiMin_" + to_string(iSt);
1024 string t_2PiName =
"dPhiPi2Pi_" + to_string(iSt);
1025 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
1026 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(-mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
1027 mSignalStorage[t_2PiName] =
Belle2::TRGCDCJSignal(2 * mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
1030 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1031 string t_in1Name =
"dPhi_" + to_string(iSt);
1032 string t_valueName =
"dPhiPi_c_" + to_string(iSt);
1033 string t_maxName =
"dPhiPiMax_" + to_string(iSt);
1034 string t_minName =
"dPhiPiMin_" + to_string(iSt);
1035 string t_2PiName =
"dPhiPi2Pi_" + to_string(iSt);
1037 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1041 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1042 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] - mSignalStorage[t_2PiName]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1045 t_data.push_back(make_pair(t_compare, t_assigns));
1050 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1053 t_data.push_back(make_pair(t_compare, t_assigns));
1058 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] + mSignalStorage[t_2PiName]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1061 t_data.push_back(make_pair(t_compare, t_assigns));
1068 if (mSignalStorage.find(
"dPhiMax_0") == mSignalStorage.end()) {
1069 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1070 string t_maxName =
"dPhiMax_" + to_string(iSt);
1071 string t_minName =
"dPhiMin_" + to_string(iSt);
1072 string t_valueName =
"dPhi_" + to_string(iSt);
1073 double t_value = 2 * mConstD.at(
"M_PI") * fabs(mConstV.at(
"nShift")[iSt]) / (mConstV.at(
"nWires")[2 * iSt + 1]);
1074 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(t_value, mSignalStorage[t_valueName].getToReal(), commonData);
1075 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(0, mSignalStorage[t_valueName].getToReal(), commonData);
1079 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1080 string t_maxName =
"dPhiMax_" + to_string(iSt);
1081 string t_minName =
"dPhiMin_" + to_string(iSt);
1082 string t_valueName =
"dPhi_c_" + to_string(iSt);
1083 string t_in1Name =
"dPhiPi_c_" + to_string(iSt);
1087 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1090 mSignalStorage[t_in1Name].getToReal(), commonData));
1092 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1093 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_minName]),
1096 t_data.push_back(make_pair(t_compare, t_assigns));
1101 make_pair(&mSignalStorage[t_valueName],
Belle2::TRGCDCJSignal::absolute(mSignalStorage[t_in1Name]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1104 t_data.push_back(make_pair(t_compare, t_assigns));
1109 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_maxName]),
1112 t_data.push_back(make_pair(t_compare, t_assigns));
1118 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1122 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1123 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_maxName]),
1126 t_data.push_back(make_pair(t_compare, t_assigns));
1129 mSignalStorage[t_in1Name].getToReal(), commonData));
1132 make_pair(&mSignalStorage[t_valueName],
Belle2::TRGCDCJSignal::absolute(mSignalStorage[t_in1Name]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1135 t_data.push_back(make_pair(t_compare, t_assigns));
1140 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_minName]),
1143 t_data.push_back(make_pair(t_compare, t_assigns));
1153 if (mSignalStorage.find(
"invZMin_0") == mSignalStorage.end()) {
1154 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1155 string t_minName =
"invZMin_" + to_string(iSt);
1156 string t_maxName =
"invZMax_" + to_string(iSt);
1157 string t_valueName =
"dPhi_c_" + to_string(iSt);
1158 unsigned long long t_int = mSignalStorage[t_valueName].getMinInt();
1159 double t_toReal = mSignalStorage[t_valueName].getToReal();
1160 double t_actual = mSignalStorage[t_valueName].getMinActual();
1161 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(t_int, t_toReal, t_int, t_int, t_actual, t_actual, t_actual, -1, commonData);
1162 t_int = mSignalStorage[t_valueName].getMaxInt();
1163 t_actual = mSignalStorage[t_valueName].getMaxActual();
1164 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(t_int, t_toReal, t_int, t_int, t_actual, t_actual, t_actual, -1, commonData);
1168 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1169 string t_inputName =
"dPhi_c_" + to_string(iSt);
1170 string t_outputName =
"zz_" + to_string(iSt);
1171 string t_invMinName =
"invZMin_" + to_string(iSt);
1172 string t_invMaxName =
"invZMax_" + to_string(iSt);
1174 if (!mLutStorage.count(t_outputName)) {
1177 double t_zToStraw = mConstV.at(
"zToStraw")[iSt];
1178 double t_rr3D = mConstV.at(
"rr3D")[iSt];
1179 double t_angleSt = mConstV.at(
"angleSt")[iSt];
1182 mLutStorage[t_outputName]->setFloatFunction(
1183 [ = ](
double aValue) ->
double{
return t_zToStraw + t_rr3D * 2 * sin(aValue / 2) / t_angleSt;},
1184 mSignalStorage[t_inputName],
1185 mSignalStorage[t_invMinName], mSignalStorage[t_invMaxName], mSignalStorage[
"rho"].getToReal(),
1186 (int) mConstD.at(
"zLUTInBitSize"), (int) mConstD.at(
"zLUTOutBitSize"));
1188 mLutStorage[t_outputName]->setFloatFunction(
1189 [ = ](
double aValue) ->
double{
return t_zToStraw - t_rr3D * 2 * sin(aValue / 2) / t_angleSt;},
1190 mSignalStorage[t_inputName],
1191 mSignalStorage[t_invMinName], mSignalStorage[t_invMaxName], mSignalStorage[
"rho"].getToReal(),
1192 (int) mConstD.at(
"zLUTInBitSize"), (int) mConstD.at(
"zLUTOutBitSize"));
1199 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1200 string t_outputName =
"zz_" + to_string(iSt);
1201 string t_inputName =
"dPhi_c_" + to_string(iSt);
1202 mLutStorage[t_outputName]->operate(mSignalStorage[t_inputName], mSignalStorage[t_outputName]);
1209 result = rho * 2 * asin(rr / 2 / rho);
1213 void Fitter3DUtility::calS(std::map<std::string, double>
const& mConstD, std::map<std::string, std::vector<double> >
const& mConstV,
1214 std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage, std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage)
1218 if (mSignalStorage.find(
"invArcSMin_0") == mSignalStorage.end()) {
1235 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1236 string t_invMinName =
"invArcSMin_" + to_string(iSt);
1238 double t_actual = mSignalStorage[
"rho_c_" + to_string(iSt)].getMaxActual();
1239 double t_toReal = mSignalStorage[
"rho_c_" + to_string(iSt)].getToReal();
1241 string t_invMaxName =
"invArcSMax_" + to_string(iSt);
1242 t_actual = mSignalStorage[
"rho_c_" + to_string(iSt)].getMinActual();
1250 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1251 string t_valueName =
"arcS_" + to_string(iSt);
1252 string t_invMinName =
"invArcSMin_" + to_string(iSt);
1253 string t_invMaxName =
"invArcSMax_" + to_string(iSt);
1254 if (!mLutStorage.count(t_valueName)) {
1257 double t_parameter = mConstV.at(
"rr3D")[iSt];
1258 mLutStorage[t_valueName]->setFloatFunction(
1259 [ = ](
double aValue) ->
double{
return 2 * aValue * asin(t_parameter / 2 / aValue);},
1261 mSignalStorage[
"rho_c_" + to_string(iSt)],
1262 mSignalStorage[t_invMinName], mSignalStorage[t_invMaxName], mSignalStorage[
"rho"].getToReal(),
1263 (int)mConstD.at(
"acosLUTInBitSize"), (int)mConstD.at(
"acosLUTOutBitSize"));
1269 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1271 string t_valueName =
"arcS_" + to_string(iSt);
1273 mLutStorage[t_valueName]->operate(mSignalStorage[
"rho_c_" + to_string(iSt)], mSignalStorage[t_valueName]);
1283 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1284 t_sum1 += pow(1 / zError[iSt], 2);
1285 t_sumSS += pow(arcS[iSt] / zError[iSt], 2);
1286 t_sumS += arcS[iSt] / pow(zError[iSt], 2);
1288 return t_sum1 * t_sumSS - pow(t_sumS, 2);
1296 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1297 t_sum1 += pow(iZError[iSt], 2);
1298 t_sumSS += pow(arcS[iSt] * iZError[iSt], 2);
1299 t_sumS += arcS[iSt] * pow(iZError[iSt], 2);
1301 return t_sum1 * t_sumSS - pow(t_sumS, 2);
1308 double ss = 0, sx = 0, sxx = 0, cotnum = 0, z0num = 0;
1309 double z0nump1[4], z0nump2[4];
1310 double z0den, iz0den;
1312 for (
unsigned i = 0; i < 4; i++) {
1314 sx += arcS[i] * iezz2[i];
1315 sxx += arcS[i] * arcS[i] * iezz2[i];
1318 for (
unsigned i = 0; i < 4; i++) {
1319 cotnum += (ss * arcS[i] - sx) * iezz2[i] * zz[i];
1320 z0nump1[i] = sxx - sx * arcS[i];
1321 z0nump2[i] = z0nump1[i] * iezz2[i] * zz[i];
1322 z0num += z0nump2[i];
1324 z0den = (ss * sxx) - (sx * sx);
1325 iz0den = 1. / z0den;
1333 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1334 if (iezz2[iSt] != 0) nTSHits++;
1338 for (
unsigned i = 0; i < 4; i++) {
1339 zchi2 += (zz[i] - z0 - cot * arcS[i]) * (zz[i] - z0 - cot * arcS[i]) * iezz2[i];
1341 zchi2 /= (nTSHits - 2);
1350 double ss = 0, sx = 0, sxx = 0, cotnum = 0, z0num = 0;
1351 double z0nump1[4], z0nump2[4];
1352 double z0den, iz0den;
1354 for (
unsigned i = 0; i < 4; i++) {
1357 sx += arcS[i] * iezz21[i];
1358 sxx += arcS[i] * arcS[i] * iezz21[i];
1361 sx += arcS[i] * iezz22[i];
1362 sxx += arcS[i] * arcS[i] * iezz22[i];
1366 for (
unsigned i = 0; i < 4; i++) {
1368 cotnum += (ss * arcS[i] - sx) * iezz21[i] * zz[i];
1369 z0nump1[i] = sxx - sx * arcS[i];
1370 z0nump2[i] = z0nump1[i] * iezz21[i] * zz[i];
1371 z0num += z0nump2[i];
1373 cotnum += (ss * arcS[i] - sx) * iezz22[i] * zz[i];
1374 z0nump1[i] = sxx - sx * arcS[i];
1375 z0nump2[i] = z0nump1[i] * iezz22[i] * zz[i];
1376 z0num += z0nump2[i];
1379 z0den = (ss * sxx) - (sx * sx);
1380 iz0den = 1. / z0den;
1388 for (
unsigned i = 0; i < 4; i++) {
1390 zchi2 += (zz[i] - z0 - cot * arcS[i]) * (zz[i] - z0 - cot * arcS[i]) * iezz21[i];
1392 zchi2 += (zz[i] - z0 - cot * arcS[i]) * (zz[i] - z0 - cot * arcS[i]) * iezz22[i];
1399 std::map<std::string, std::vector<double> >
const& mConstV, std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage,
1400 std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage)
1404 mSignalStorage[
"sum1_p1_0"] <= mSignalStorage[
"iZError2_0"] + mSignalStorage[
"iZError2_1"];
1406 mSignalStorage[
"sum1_p1_1"] <= mSignalStorage[
"iZError2_2"] + mSignalStorage[
"iZError2_3"];
1409 mSignalStorage[
"sum1"] <= mSignalStorage[
"sum1_p1_0"] + mSignalStorage[
"sum1_p1_1"];
1412 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1413 mSignalStorage[
"sumS_p1_" + to_string(iSt)] <= mSignalStorage[
"arcS_" + to_string(iSt)] * mSignalStorage[
"iZError2_" + to_string(
1417 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1418 mSignalStorage[
"sumSS_p1_" + to_string(iSt)] <= mSignalStorage[
"arcS_" + to_string(iSt)] * mSignalStorage[
"arcS_" + to_string(iSt)];
1421 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1422 mSignalStorage[
"cotNumS_p1_" + to_string(iSt)] <= mSignalStorage[
"sum1"] * mSignalStorage[
"arcS_" + to_string(iSt)];
1428 mSignalStorage[
"sumS_p2_0"] <= mSignalStorage[
"sumS_p1_0"] + mSignalStorage[
"sumS_p1_1"];
1430 mSignalStorage[
"sumS_p2_1"] <= mSignalStorage[
"sumS_p1_2"] + mSignalStorage[
"sumS_p1_3"];
1432 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1433 mSignalStorage[
"sumSS_p2_" + to_string(iSt)] <= mSignalStorage[
"sumSS_p1_" + to_string(iSt)] * mSignalStorage[
"iZError2_" +
1439 mSignalStorage[
"sumS"] <= mSignalStorage[
"sumS_p2_0"] + mSignalStorage[
"sumS_p2_1"];
1441 mSignalStorage[
"sumSS_p3_0"] <= mSignalStorage[
"sumSS_p2_0"] + mSignalStorage[
"sumSS_p2_1"];
1443 mSignalStorage[
"sumSS_p3_1"] <= mSignalStorage[
"sumSS_p2_2"] + mSignalStorage[
"sumSS_p2_3"];
1448 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1449 mSignalStorage[
"z0NumS_p1_" + to_string(iSt)] <= mSignalStorage[
"arcS_" + to_string(iSt)] * mSignalStorage[
"sumS"];
1452 mSignalStorage[
"den_p1"] <= mSignalStorage[
"sumS"] * mSignalStorage[
"sumS"];
1454 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1455 mSignalStorage[
"cotNumS_" + to_string(iSt)] <= mSignalStorage[
"cotNumS_p1_" + to_string(iSt)] - mSignalStorage[
"sumS"];
1458 mSignalStorage[
"sumSS"] <= mSignalStorage[
"sumSS_p3_0"] + mSignalStorage[
"sumSS_p3_1"];
1460 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1461 mSignalStorage[
"zxiZError_" + to_string(iSt)] <= mSignalStorage[
"zz_" + to_string(iSt)] * mSignalStorage[
"iZError2_" + to_string(
1470 mSignalStorage[
"den_p2"] <= mSignalStorage[
"sum1"] * mSignalStorage[
"sumSS"];
1472 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1473 mSignalStorage[
"z0NumS_" + to_string(iSt)] <= mSignalStorage[
"sumSS"] - mSignalStorage[
"z0NumS_p1_" + to_string(iSt)];
1478 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1479 mSignalStorage[
"cotNumSZ_" + to_string(iSt)] <= mSignalStorage[
"cotNumS_" + to_string(iSt)] * mSignalStorage[
"zxiZError_" +
1483 mSignalStorage[
"den"] <= mSignalStorage[
"den_p2"] - mSignalStorage[
"den_p1"];
1485 if (mSignalStorage.find(
"denMin") == mSignalStorage.end()) {
1487 double t_rr3D[4], t_wireZError[4];
1488 for (
int iSt = 0; iSt < 2; iSt++) {
1489 t_rr3D[iSt] = mConstV.at(
"rr3D")[iSt];
1490 t_wireZError[iSt] = 1 / mConstV.at(
"wireZError")[iSt];
1492 for (
int iSt = 2; iSt < 4; iSt++) {
1493 t_rr3D[iSt] = mConstV.at(
"rr3D")[iSt];
1494 t_wireZError[iSt] = 0;
1497 mSignalStorage[
"denMin"] =
Belle2::TRGCDCJSignal(t_denMin, mSignalStorage[
"den"].getToReal(), commonData);
1498 double t_arcSMax[4], t_driftZError[4];
1499 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1500 t_arcSMax[iSt] = mConstD.at(
"M_PI") * mConstV.at(
"rr3D")[iSt] / 2;
1501 t_driftZError[iSt] = 1 / mConstV.at(
"driftZError")[iSt];
1504 mSignalStorage[
"denMax"] =
Belle2::TRGCDCJSignal(t_denMax, mSignalStorage[
"den"].getToReal(), commonData);
1509 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1513 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1514 make_pair(&mSignalStorage[
"den_c"], mSignalStorage[
"denMax"])
1517 t_data.push_back(make_pair(t_compare, t_assigns));
1522 make_pair(&mSignalStorage[
"den_c"], mSignalStorage[
"den"].limit(mSignalStorage[
"denMin"], mSignalStorage[
"denMax"]))
1525 t_data.push_back(make_pair(t_compare, t_assigns));
1530 make_pair(&mSignalStorage[
"den_c"], mSignalStorage[
"denMin"])
1533 t_data.push_back(make_pair(t_compare, t_assigns));
1537 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1538 mSignalStorage[
"z0NumSZ_" + to_string(iSt)] <= mSignalStorage[
"z0NumS_" + to_string(iSt)] * mSignalStorage[
"zxiZError_" + to_string(
1549 mSignalStorage[
"cot_p1_0"] <= mSignalStorage[
"cotNumSZ_0"] + mSignalStorage[
"cotNumSZ_1"];
1551 mSignalStorage[
"cot_p1_1"] <= mSignalStorage[
"cotNumSZ_2"] + mSignalStorage[
"cotNumSZ_3"];
1553 mSignalStorage[
"z0_p1_0"] <= mSignalStorage[
"z0NumSZ_0"] + mSignalStorage[
"z0NumSZ_1"];
1555 mSignalStorage[
"z0_p1_1"] <= mSignalStorage[
"z0NumSZ_2"] + mSignalStorage[
"z0NumSZ_3"];
1560 if (mSignalStorage.find(
"invIDenMin") == mSignalStorage.end()) {
1561 unsigned long long t_int = mSignalStorage[
"den_c"].getMaxInt();
1562 double t_toReal = mSignalStorage[
"den_c"].getToReal();
1563 double t_actual = mSignalStorage[
"den_c"].getMaxActual();
1564 mSignalStorage[
"invIDenMin"] =
Belle2::TRGCDCJSignal(t_int, t_toReal, t_int, t_int, t_actual, t_actual, t_actual, -1, commonData);
1565 t_int = mSignalStorage[
"den_c"].getMinInt();
1566 t_actual = mSignalStorage[
"den_c"].getMinActual();
1567 mSignalStorage[
"invIDenMax"] =
Belle2::TRGCDCJSignal(t_int, t_toReal, t_int, t_int, t_actual, t_actual, t_actual, -1, commonData);
1572 if (!mLutStorage.count(
"iDen")) {
1574 mLutStorage[
"iDen"]->setFloatFunction(
1575 [ = ](
double aValue) ->
double{
return 1 / aValue;},
1576 mSignalStorage[
"den_c"],
1577 mSignalStorage[
"invIDenMin"], mSignalStorage[
"invIDenMax"],
1578 pow(1 / mSignalStorage[
"rho"].getToReal() / mSignalStorage[
"iZError2_0"].getToReal(), 2),
1579 (int)mConstD.at(
"iDenLUTInBitSize"), (int)mConstD.at(
"iDenLUTOutBitSize"));
1583 mLutStorage[
"iDen"]->operate(mSignalStorage[
"den_c"], mSignalStorage[
"iDen"]);
1591 mSignalStorage[
"cot_p2"] <= mSignalStorage[
"cot_p1_0"] + mSignalStorage[
"cot_p1_1"];
1593 mSignalStorage[
"z0_p2"] <= mSignalStorage[
"z0_p1_0"] + mSignalStorage[
"z0_p1_1"];
1597 mSignalStorage[
"cot"] <= mSignalStorage[
"cot_p2"] * mSignalStorage[
"iDen"];
1599 mSignalStorage[
"z0"] <= mSignalStorage[
"z0_p2"] * mSignalStorage[
"iDen"];
1600 if (mConstD.at(
"JB") == 1) {
1601 cout <<
"<<<cot>>>" << endl; mSignalStorage[
"cot"].dump();
1602 cout <<
"<<<z0>>>" << endl; mSignalStorage[
"z0"].dump();
1611 if (!mSignalStorage.count(
"z0Min")) {
1612 mSignalStorage[
"z0Min"] =
Belle2::TRGCDCJSignal(z0Min, mSignalStorage[
"z0"].getToReal(), commonData);
1613 mSignalStorage[
"z0Max"] =
Belle2::TRGCDCJSignal(z0Max, mSignalStorage[
"z0"].getToReal(), commonData);
1617 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1621 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1622 make_pair(&mSignalStorage[
"z0_c"], mSignalStorage[
"z0Max"])
1625 t_data.push_back(make_pair(t_compare, t_assigns));
1630 make_pair(&mSignalStorage[
"z0_c"], mSignalStorage[
"z0"].limit(mSignalStorage[
"z0Min"], mSignalStorage[
"z0Max"]))
1633 t_data.push_back(make_pair(t_compare, t_assigns));
1638 make_pair(&mSignalStorage[
"z0_c"], mSignalStorage[
"z0Min"])
1641 t_data.push_back(make_pair(t_compare, t_assigns));
1648 double cotMin = cos(127 * mConstD.at(
"M_PI") / 180) / sin(127 * mConstD.at(
"M_PI") / 180);
1649 double cotMax = cos(35 * mConstD.at(
"M_PI") / 180) / sin(35 * mConstD.at(
"M_PI") / 180);
1650 if (!mSignalStorage.count(
"cotMin")) {
1651 mSignalStorage[
"cotMin"] =
Belle2::TRGCDCJSignal(cotMin, mSignalStorage[
"cot"].getToReal(), commonData);
1652 mSignalStorage[
"cotMax"] =
Belle2::TRGCDCJSignal(cotMax, mSignalStorage[
"cot"].getToReal(), commonData);
1656 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1660 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1661 make_pair(&mSignalStorage[
"cot_c"], mSignalStorage[
"cotMax"])
1664 t_data.push_back(make_pair(t_compare, t_assigns));
1669 make_pair(&mSignalStorage[
"cot_c"], mSignalStorage[
"cot"].limit(mSignalStorage[
"cotMin"], mSignalStorage[
"cotMax"]))
1672 t_data.push_back(make_pair(t_compare, t_assigns));
1677 make_pair(&mSignalStorage[
"cot_c"], mSignalStorage[
"cotMin"])
1680 t_data.push_back(make_pair(t_compare, t_assigns));
1692 int z0Shift = mSignalStorage[
"z0_c"].getBitsize() - z0Bits;
1693 mSignalStorage[
"z0_r"] <= mSignalStorage[
"z0_c"].shift(z0Shift, 0);
1694 int cotShift = mSignalStorage[
"cot_c"].getBitsize() - cotBits;
1695 mSignalStorage[
"cot_r"] <= mSignalStorage[
"cot_c"].shift(cotShift, 0);
1704 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1705 mSignalStorage[
"fitDistFromZ0_" + to_string(iSt)] <= mSignalStorage[
"cot"] * mSignalStorage[
"arcS_" + to_string(iSt)];
1708 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1709 mSignalStorage[
"distFromZ0_" + to_string(iSt)] <= mSignalStorage[
"zz_" + to_string(iSt)] - mSignalStorage[
"z0"];
1714 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1715 mSignalStorage[
"chiNum_" + to_string(iSt)] <= mSignalStorage[
"distFromZ0_" + to_string(iSt)] - mSignalStorage[
"fitDistFromZ0_" +
1720 if (mSignalStorage.find(
"chiNumMax_0") == mSignalStorage.end()) {
1721 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1722 string t_maxName =
"chiNumMax_" + to_string(iSt);
1723 string t_minName =
"chiNumMin_" + to_string(iSt);
1724 string t_valueName =
"chiNum_" + to_string(iSt);
1725 double t_maxValue = 2 * mConstV.at(
"zToOppositeStraw")[iSt];
1726 double t_minValue = 2 * mConstV.at(
"zToStraw")[iSt];
1727 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(t_maxValue, mSignalStorage[t_valueName].getToReal(), commonData);
1728 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(t_minValue, mSignalStorage[t_valueName].getToReal(), commonData);
1732 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1733 string t_maxName =
"chiNumMax_" + to_string(iSt);
1734 string t_minName =
"chiNumMin_" + to_string(iSt);
1735 string t_valueName =
"chiNum_c_" + to_string(iSt);
1736 string t_in1Name =
"chiNum_" + to_string(iSt);
1738 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1742 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1743 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_maxName]),
1746 t_data.push_back(make_pair(t_compare, t_assigns));
1751 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1754 t_data.push_back(make_pair(t_compare, t_assigns));
1759 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_minName]),
1762 t_data.push_back(make_pair(t_compare, t_assigns));
1770 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1771 mSignalStorage[
"chi2_p1_" + to_string(iSt)] <= mSignalStorage[
"chiNum_c_" + to_string(iSt)] * mSignalStorage[
"chiNum_c_" +
1776 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1777 mSignalStorage[
"chi2_" + to_string(iSt)] <= mSignalStorage[
"chi2_p1_" + to_string(iSt)] * mSignalStorage[
"iZError2_" + to_string(
1782 mSignalStorage[
"chi2Sum_p1_0"] <= mSignalStorage[
"chi2_0"] + mSignalStorage[
"chi2_1"];
1784 mSignalStorage[
"chi2Sum_p1_1"] <= mSignalStorage[
"chi2_2"] + mSignalStorage[
"chi2_3"];
1788 mSignalStorage[
"zChi2"] <= (mSignalStorage[
"chi2Sum_p1_0"] + mSignalStorage[
"chi2Sum_p1_1"]).shift(1);
1789 if (mConstD.at(
"JB") == 1) {cout <<
"<<<zChi2>>>" << endl; mSignalStorage[
"zChi2"].dump();}
1793 double zChi2Min = 0;
1795 double zChi2Max = 100;
1799 if (!mSignalStorage.count(
"zChi2Min")) {
1800 mSignalStorage[
"zChi2Min"] =
Belle2::TRGCDCJSignal(zChi2Min, mSignalStorage[
"zChi2"].getToReal(), commonData);
1801 mSignalStorage[
"zChi2Max"] =
Belle2::TRGCDCJSignal(zChi2Max, mSignalStorage[
"zChi2"].getToReal(), commonData);
1805 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1809 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1810 make_pair(&mSignalStorage[
"zChi2_c"], mSignalStorage[
"zChi2Max"])
1813 t_data.push_back(make_pair(t_compare, t_assigns));
1818 make_pair(&mSignalStorage[
"zChi2_c"], mSignalStorage[
"zChi2"].limit(mSignalStorage[
"zChi2Min"], mSignalStorage[
"zChi2Max"]))
1821 t_data.push_back(make_pair(t_compare, t_assigns));
1826 make_pair(&mSignalStorage[
"zChi2_c"], mSignalStorage[
"zChi2Min"])
1829 t_data.push_back(make_pair(t_compare, t_assigns));
1836 int zChi2Shift = mSignalStorage[
"zChi2_c"].getBitsize() - zChi2Bits;
1837 mSignalStorage[
"zChi2_r"] <= mSignalStorage[
"zChi2_c"].shift(zChi2Shift, 0);
1845 std::vector<std::vector<double> >
const& stXts,
1846 int eventTimeValid,
int eventTime,
1847 std::vector<std::vector<int> >
const& rawStTSs,
1848 int charge,
double radius,
double phi_c,
double& z0,
double& cot,
double& chi2)
1851 vector<double> arcS;
1852 vector<double> invZError2;
1853 fitter3D(stGeometry, stXts, eventTimeValid, eventTime, rawStTSs, charge, radius, phi_c, z0, cot, chi2, arcS, zz, invZError2);
1857 std::vector<std::vector<double> >
const& stXts,
1858 int eventTimeValid,
int eventTime,
1859 std::vector<std::vector<int> >
const& rawStTSs,
1860 int charge,
double radius,
double phi_c,
double& z0,
double& cot,
double& chi2, vector<double>& arcS, vector<double>& zz,
1861 vector<double>& invZError2)
1863 vector<double> stTSs(4);
1866 zz = vector<double> (4, 0);
1867 arcS = vector<double> (4, 0);
1868 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1869 if (rawStTSs[iSt][1] != 0) {
1871 stGeometry[
"cdcRadius"][iSt], stTSs[iSt], radius, phi_c);
1879 const std::map<std::string, std::vector<double> >& mConstV,
1880 int eventTimeValid,
int eventTime,
1881 std::vector<std::vector<int> >
const& rawStTSs,
1882 int charge,
double radius,
double phi_c,
1884 std::map<std::string, Belle2::TRGCDCJLUT*>& mLutStorage)
1888 vector<tuple<string, double, int, double, double, int> > t_values = {
1889 make_tuple(
"phi0", phi_c, mConstD[
"phiBitSize"], mConstD[
"phiMin"], mConstD[
"phiMax"], 0),
1890 make_tuple(
"rho", radius, mConstD[
"rhoBitSize"], mConstD[
"rhoMin"], mConstD[
"rhoMax"], 0),
1891 make_tuple(
"charge", (
int)(charge == 1 ? 1 : 0), 1, 0, 1.5, 0),
1892 make_tuple(
"lr_0", rawStTSs[0][1], 2, 0, 3.5, 0),
1893 make_tuple(
"lr_1", rawStTSs[1][1], 2, 0, 3.5, 0),
1894 make_tuple(
"lr_2", rawStTSs[2][1], 2, 0, 3.5, 0),
1895 make_tuple(
"lr_3", rawStTSs[3][1], 2, 0, 3.5, 0),
1896 make_tuple(
"tsId_0", rawStTSs[0][0], ceil(log(mConstV.at(
"nTSs")[1]) / log(2)), 0, pow(2, ceil(log(mConstV.at(
"nTSs")[1]) / log(2))) - 0.5, 0),
1897 make_tuple(
"tsId_1", rawStTSs[1][0], ceil(log(mConstV.at(
"nTSs")[3]) / log(2)), 0, pow(2, ceil(log(mConstV.at(
"nTSs")[3]) / log(2))) - 0.5, 0),
1898 make_tuple(
"tsId_2", rawStTSs[2][0], ceil(log(mConstV.at(
"nTSs")[5]) / log(2)), 0, pow(2, ceil(log(mConstV.at(
"nTSs")[5]) / log(2))) - 0.5, 0),
1899 make_tuple(
"tsId_3", rawStTSs[3][0], ceil(log(mConstV.at(
"nTSs")[7]) / log(2)), 0, pow(2, ceil(log(mConstV.at(
"nTSs")[7]) / log(2))) - 0.5, 0),
1900 make_tuple(
"tdc_0", rawStTSs[0][2], mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1901 make_tuple(
"tdc_1", rawStTSs[1][2], mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1902 make_tuple(
"tdc_2", rawStTSs[2][2], mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1903 make_tuple(
"tdc_3", rawStTSs[3][2], mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1904 make_tuple(
"eventTime", eventTime, mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1905 make_tuple(
"eventTimeValid", eventTimeValid, 1, 0, 1.5, 0),
1917 if ((*mSignalStorage.begin()).second.getName() ==
"") {
1918 for (
auto it = mSignalStorage.begin(); it != mSignalStorage.end(); ++it) {
1919 (*it).second.setName((*it).first);
1925 TVector2& helixCenter,
1926 TVector3& impactPosition)
1936 double rho =
sqrt(pow(mcMomentum->Px(), 2) + pow(mcMomentum->Py(), 2)) / 0.3 / 1.5 * 100;
1937 double hcx = mcPosition->X() + rho * cos(atan2(mcMomentum->Py(), mcMomentum->Px()) - charge * TMath::Pi() / 2);
1938 double hcy = mcPosition->Y() + rho * sin(atan2(mcMomentum->Py(), mcMomentum->Px()) - charge * TMath::Pi() / 2);
1939 helixCenter.Set(hcx, hcy);
1940 double impactX = (helixCenter.Mod() - rho) / helixCenter.Mod() * helixCenter.X();
1941 double impactY = (helixCenter.Mod() - rho) / helixCenter.Mod() * helixCenter.Y();
1943 if (atan2(impactY, impactX) < atan2(mcPosition->Y(), mcPosition->X())) signdS = -1;
1945 double dS = 2 * rho * asin(
sqrt(pow(impactX - mcPosition->X(), 2) + pow(impactY - mcPosition->Y(), 2)) / 2 / rho);
1946 double impactZ = mcMomentum->Pz() / mcMomentum->Pt() * dS * signdS + mcPosition->Z();
1947 impactPosition.SetXYZ(impactX, impactY, impactZ);
1954 double t_alpha = 1 / 0.3 / 1.5 * 100;
1955 double t_pT = momentum.Perp();
1956 double t_R = t_pT * t_alpha;
1957 helixParameters.Clear();
1958 helixParameters.ResizeTo(5);
1959 helixParameters[2] = t_alpha / t_R;
1960 helixParameters[1] = atan2(position.Y() - t_R * momentum.X() / t_pT * charge, position.X() + t_R * momentum.Y() / t_pT * charge);
1961 helixParameters[0] = (position.X() + t_R * momentum.Y() / t_pT * charge) / cos(helixParameters[1]) - t_R;
1962 double t_phi = atan2(-momentum.X() * charge, momentum.Y() * charge) - helixParameters[1];
1963 if (t_phi > M_PI) t_phi -= 2 * M_PI;
1964 if (t_phi < -M_PI) t_phi += 2 * M_PI;
1965 helixParameters[4] = momentum.Z() / t_pT * charge;
1966 helixParameters[3] = position.Z() + helixParameters[4] * t_R * t_phi;
1972 double t_alpha = 1 / 0.3 / 1.5 * 100;
1973 double t_R = t_alpha / helixParameters[2];
1974 double t_pT = t_R / t_alpha;
1975 double t_phi = -1 * charge * acos((-pow(cdcRadius, 2) + pow(t_R + helixParameters[0], 2) + pow(t_R,
1976 2)) / (2 * t_R * (t_R + helixParameters[0])));
1977 double t_X = (helixParameters[0] + t_R) * cos(helixParameters[1]) - t_R * cos(helixParameters[1] + t_phi);
1978 double t_Y = (helixParameters[0] + t_R) * sin(helixParameters[1]) - t_R * sin(helixParameters[1] + t_phi);
1979 double t_Z = helixParameters[3] - helixParameters[4] * t_R * t_phi;
1980 double t_Px = -t_pT * sin(helixParameters[1] + t_phi) * charge;
1981 double t_Py = t_pT * cos(helixParameters[1] + t_phi) * charge;
1982 double t_Pz = t_pT * helixParameters[4] * charge;
1983 position.SetXYZ(t_X, t_Y, t_Z);
1984 momentum.SetXYZ(t_Px, t_Py, t_Pz);
1991 for (
int i = 0; i < numberBits - 1; i++) {
1995 }
else if (mode == 0) {
1996 for (
int i = 0; i < numberBits; i++) {
2011 double range = maxValue - minValue;
2012 double convert = (
bitSize - 0.5) / range;
2023 double range = maxValue - minValue;
2024 double convert = (
bitSize - 0.5) / range;
2025 real = (integer / convert) + minValue;
2031 if (value > m_max) m_max = value;
2032 if (value < m_min) m_min = value;
A class to use LUTs for TRGCDC.
A class to hold common data for JSignals.
A class to use Signals for TRGCDC 3D tracker.
static void loadStereoXt(std::string const &filePrefix, int nFiles, std::vector< std::vector< double > > &stXts)
Load stereo Xt file.
static void findImpactPosition(TVector3 *mcPosition, ROOT::Math::PxPyPzEVector *mcMomentum, int charge, TVector2 &helixCenter, TVector3 &impactPosition)
MC calculation functions Calculates the impact position of track.
static double rotatePhi(double value, double refPhi)
Rotates to range [-pi, pi].
static double calStAxPhi(int charge, double anglest, double ztostraw, double rr, double rho, double phi0)
Calculates the fitted axial phi for the stereo super layer.
static void changeReal(double &real, int integer, double minValue, double maxValue, int bitSize)
Changes integer to float value.
static int findQuadrant(double value)
Finds quadrant of angle. Angle is in rad.
static int bitSize(int numberBits, int mode)
Firmware convert functions.
static void fitter3DFirm(std::map< std::string, double > &mConstD, const std::map< std::string, std::vector< double > > &mConstV, int eventTimeValid, int eventTime, std::vector< std::vector< int > > const &rawStTSs, int charge, double radius, double phi_c, Belle2::TRGCDCJSignalData *commonData, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage, std::map< std::string, Belle2::TRGCDCJLUT * > &mLutStorage)
Combines several functions for fitter3D firmware.
static void rPhiFitter(double *rr, double *phi2, double *invphierror, double &rho, double &myphi0)
A circle fitter with invPhiError without fit chi2 output.
static void changeInteger(int &integer, double real, double minValue, double maxValue, int bitSize)
Changes float to integer value.
static double calZ(int charge, double anglest, double ztostraw, double rr, double phi, double rho, double phi0)
Calculates z.
static double calDenWithIZError(double *arcS, double *iZError)
Calculates the denominator for fitting z and arc s.
static void setError(std::map< std::string, double > const &mConstD, std::map< std::string, std::vector< double > > const &mConstV, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage)
Sets error using JSignal class.
static void setErrorFast(std::vector< std::vector< int > > const &rawStTSs, int eventTimeValid, std::vector< double > &invZError2)
Sets error for fitting.
static void calPhiFast(std::map< std::string, std::vector< double > > &stGeometry, std::vector< std::vector< double > > const &stXts, int eventTimeValid, int eventTime, std::vector< std::vector< int > > const &rawStTSs, std::vector< double > &stTSs)
Calculates phi with fast simulation.
static double calDeltaPhi(int charge, double anglest, double ztostraw, double rr, double phi, double rho, double phi0)
Calculates the phi difference between fitted axial phi and stereo phi.
static double calS(double rho, double rr)
Calculates arc length.
static double stereoIdToPhi(std::vector< double > &stNWires, int iSt, int id)
Converts stereo ts id to phi.
static void fitter3D(std::map< std::string, std::vector< double > > &stGeometry, std::vector< std::vector< double > > const &stXts, int eventTimeValid, int eventTime, std::vector< std::vector< int > > const &rawStTSs, int charge, double radius, double phi_c, double &z0, double &cot, double &chi2)
Combines several functions for fitter3D.
static void calVectorsAtR(const TVectorD &helixParameters, int charge, double radius, TVector3 &position, TVector3 &momentum)
Calculates position and momentum at a certain radius.
static int findSign(double *phi2)
2D fitter functions
static void calHelixParameters(TVector3 position, TVector3 momentum, int charge, TVectorD &helixParameters)
HelixParameters: dR, phi0, keppa, dz, tanLambda Calculates the helix parameters of track.
static double calPhi(double wirePhi, double driftLength, double rr, int lr)
Pre 3D fitter functions. rr is in cm scale. driftLength is in cm scale.
static void chargeFinder(double *nTSs, double *tsIds, double *tsHitmap, double phi0, double inCharge, double &outCharge)
Charge finder using circle fitter output and axial TSs.
static int rotateTsId(int value, int refId, int nTSs)
Rotates to range [0, nTSs-1].
static void saveStereoXt(std::vector< std::vector< double > > &stXts, std::string const &filePrefix)
Saves stereo Xt to file.
static void rPhiFit(double *rr, double *phi2, double *phierror, double &rho, double &myphi0)
A circle fitter.
static void rSFit2(double *iezz21, double *iezz22, double *arcS, double *zz, int *lutv, double &z0, double &cot, double &zchi2)
Fits z and arc S. (Will be deprecated.)
static unsigned toUnsignedTdc(int tdc, int nBits)
Changes tdc and event time to unsigned value that has # bits.
static void rSFit(double *iezz2, double *arcS, double *zz, double &z0, double &cot, double &zchi2)
3D fitter functions Fits z and arc S.
static double calDen(double *arcS, double *zError)
Calculates the denominator for fitting z and arc s.
static void rPhiFit2(double *rr, double *phi2, double *phierror, double &rho, double &myphi0, int nTS)
A circle fitter.
static void findExtreme(double &m_max, double &m_min, double value)
Finds maximum and minium values.
static void constrainRPerStSl(std::map< std::string, std::vector< double > > const &mConstV, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage)
Constrains R for each SL differently using JSignal and multiple constants.
static double roundInt(double value)
Round double value.
double sqrt(double a)
sqrt for double
double atan(double a)
atan for double
static void valuesToMapSignals(std::vector< std::tuple< std::string, double, int, double, double, int > > const &inValues, Belle2::TRGCDCJSignalData *inCommonData, std::map< std::string, Belle2::TRGCDCJSignal > &outMap)
Values => [name, value, bitwidth, min, max, clock] Changes values to signals.
static void ifElse(std::vector< std::pair< TRGCDCJSignal, std::vector< std::pair< TRGCDCJSignal *, TRGCDCJSignal > > > > &data, int targetClock)
If else implementation with target clock.
static TRGCDCJSignal const absolute(TRGCDCJSignal const &first)
Absolute TRGCDCJSignal. Removes 1 bit if signed or minus unsigned.
static TRGCDCJSignal comp(TRGCDCJSignal const &lhs, const std::string &operate, TRGCDCJSignal const &rhs)
Compare two signals.