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"
45 if ((phi2[0] - phi2[4]) > M_PI || (phi2[0] - phi2[4]) < -M_PI) {
46 if (phi2[0] > M_PI) {sign_phi[0] = phi2[0] - 2 * M_PI;}
47 else {sign_phi[0] = phi2[0];}
48 if (phi2[4] > M_PI) {sign_phi[1] = phi2[4] - 2 * M_PI;}
49 else {sign_phi[1] = phi2[4];}
51 sign_phi[0] = phi2[0];
52 sign_phi[1] = phi2[4];
54 if ((sign_phi[1] - sign_phi[0]) > 0) {mysign = 0;}
63 cout <<
"Fitter3DUtility::rPhiFit() will be deprecated. Please use Fitter3DUtility::rPhiFitter(). phierror was changed to inv phi error."
65 double invphierror[5];
66 for (
unsigned i = 0; i < 5; i++) {
67 invphierror[i] = 1 / phierror[i];
69 rPhiFitter(rr, phi2, invphierror, rho, myphi0);
76 rPhiFitter(rr, phi2, invphierror, rho, myphi0, chi2);
88 double A, B, C, D,
E, hcx, hcy;
89 double invFiterror[5];
92 for (
unsigned i = 0; i < 5; i++) {
97 invFiterror[i] = invphierror[i] / rr[i];
101 A = 0, B = 0, C = 0, D = 0,
E = 0;
103 for (
unsigned i = 0; i < 5; i++) {
104 A += cos(phi2[i]) * cos(phi2[i]) * (invFiterror[i] * invFiterror[i]);
105 B += sin(phi2[i]) * sin(phi2[i]) * (invFiterror[i] * invFiterror[i]);
106 C += cos(phi2[i]) * sin(phi2[i]) * (invFiterror[i] * invFiterror[i]);
107 D += rr[i] * cos(phi2[i]) * (invFiterror[i] * invFiterror[i]);
108 E += rr[i] * sin(phi2[i]) * (invFiterror[i] * invFiterror[i]);
112 hcx /= 2 * (A * B - C * C);
114 hcy /= 2 * (A * B - C * C);
115 rho = sqrt(hcx * hcx + hcy * hcy);
116 myphi0 = atan2(hcy, hcx);
117 if (myphi0 < 0) myphi0 += 2 * M_PI;
129 for (
unsigned iAx = 0; iAx < 5; iAx++) {
130 if (invphierror[iAx] != 0) nTSHits++;
134 for (
unsigned i = 0; i < 5; i++) {
135 chi2 += (2 * (hcx * cos(phi2[i]) + hcy * sin(phi2[i])) - rr[i]) * (2 * (hcx * cos(phi2[i]) + hcy * sin(phi2[i])) - rr[i]) /
136 (invFiterror[i] * invFiterror[i]);
145 vector<double> tsPhi(5);
146 vector<double> dPhi(5);
147 vector<double> dPhi_c(5);
148 vector<double> charge(5);
149 for (
unsigned iAx = 0; iAx < 5; iAx++) {
152 tsPhi[iAx] = tsIds[iAx] * 2 * M_PI / nTSs[iAx];
153 dPhi[iAx] = tsPhi[iAx] - phi0;
156 if (dPhi[iAx] < -M_PI) dPhi_c[iAx] = dPhi[iAx] + 2 * M_PI;
157 else if (dPhi[iAx] > M_PI) dPhi_c[iAx] = dPhi[iAx] - 2 * M_PI;
158 else dPhi_c[iAx] = dPhi[iAx];
161 if (tsHitmap[iAx] == 0) charge[iAx] = 0;
162 else if (dPhi_c[iAx] == 0) charge[iAx] = 0;
163 else if (dPhi_c[iAx] > 0) charge[iAx] = 1;
164 else charge[iAx] = -1;
168 double sumCharge = charge[0] + charge[1] + charge[2] + charge[3] + charge[4];
171 if (sumCharge == 0) foundCharge = inCharge;
172 else if (sumCharge > 0) foundCharge = 1;
173 else foundCharge = -1;
182 double A, B, C, D,
E, hcx, hcy;
186 for (
int i = 0; i < nTS; i++) {
188 fiterror[i] = 1 + 0 * phierror[i];
192 A = 0, B = 0, C = 0, D = 0,
E = 0;
194 for (
int i = 0; i < nTS; i++) {
195 A += cos(phi2[i]) * cos(phi2[i]) / (fiterror[i] * fiterror[i]);
196 B += sin(phi2[i]) * sin(phi2[i]) / (fiterror[i] * fiterror[i]);
197 C += cos(phi2[i]) * sin(phi2[i]) / (fiterror[i] * fiterror[i]);
198 D += rr[i] * cos(phi2[i]) / (fiterror[i] * fiterror[i]);
199 E += rr[i] * sin(phi2[i]) / (fiterror[i] * fiterror[i]);
203 hcx /= 2 * (A * B - C * C);
205 hcy /= 2 * (A * B - C * C);
206 rho = sqrt(hcx * hcx + hcy * hcy);
207 myphi0 = atan2(hcy, hcx);
208 if (myphi0 < 0) myphi0 += 2 * M_PI;
229 int tdcMax = pow(2, nBits) - 1;
232 if (resultTdc > tdcMax) resultTdc -= (tdcMax + 1);
233 else if (resultTdc < 0) resultTdc += (tdcMax + 1);
236 return (
unsigned) resultTdc;
242 double result = wirePhi;
245 double t_dPhi = driftLength;
249 t_dPhi = atan(t_dPhi / rr);
252 if (lr == 1) result -= t_dPhi;
253 else if (lr == 2) result += t_dPhi;
261 double t_driftLength = (driftTime - eventTime) * 1000 / 1017.774 * 2 * 40 / 1000 / 10;
262 return calPhi(wirePhi, t_driftLength, rr, lr);
267 double wirePhi = (double)localId / nWires * 4 * M_PI;
272 std::map<std::string, std::vector<double> >
const& mConstV, std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage,
273 std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage)
280 if (mSignalStorage.find(
"phiFactor_0") == mSignalStorage.end()) {
281 for (
unsigned iSt = 0; iSt < 4; iSt++) {
282 int nShiftBits = int(log(pow(2, 24) / 2 / mConstD.at(
"M_PI") * mConstV.at(
"nTSs")[2 * iSt + 1] *
283 mSignalStorage[
"phi0"].getToReal()) / log(2));
285 t_name =
"phiFactor_" + to_string(iSt);
286 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(2 * mConstD.at(
"M_PI") / mConstV.at(
"nTSs")[2 * iSt + 1],
287 mSignalStorage[
"phi0"].getToReal() / pow(2, nShiftBits), commonData);
292 for (
unsigned iSt = 0; iSt < 4;
293 iSt++) mSignalStorage[
"wirePhi_" + to_string(iSt)] <= mSignalStorage[
"tsId_" + to_string(iSt)] * mSignalStorage[
"phiFactor_" +
301 for (
unsigned iSt = 0; iSt < 4;
302 iSt++) mSignalStorage[
"driftTimeRaw_" + to_string(iSt)] <= mSignalStorage[
"tdc_" + to_string(iSt)] - mSignalStorage[
"eventTime"];
308 if (mSignalStorage.find(
"maxDriftTimeLow") == mSignalStorage.end()) {
309 int maxDriftTime = 287;
310 mSignalStorage[
"maxDriftTimeLow"] =
Belle2::TRGCDCJSignal(-512 + maxDriftTime + 1, mSignalStorage[
"eventTime"].getToReal(),
312 mSignalStorage[
"maxDriftTimeHigh"] =
Belle2::TRGCDCJSignal(maxDriftTime, mSignalStorage[
"eventTime"].getToReal(), commonData);
313 mSignalStorage[
"maxDriftTimeMax"] =
Belle2::TRGCDCJSignal(512, mSignalStorage[
"eventTime"].getToReal(), commonData);
315 for (
unsigned iSt = 0; iSt < 4; iSt++) {
316 string t_in1Name =
"driftTimeRaw_" + to_string(iSt);
317 string t_valueName =
"driftTime_c_" + to_string(iSt);
319 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
322 mSignalStorage[
"eventTimeValid"].getToReal(), commonData));
324 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
325 make_pair(&mSignalStorage[t_valueName],
Belle2::TRGCDCJSignal(0, mSignalStorage[
"eventTime"].getToReal(), commonData))
328 t_data.push_back(make_pair(t_compare, t_assigns));
333 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] + mSignalStorage[
"maxDriftTimeMax"]).limit(mSignalStorage[
"maxDriftTimeLow"], mSignalStorage[
"maxDriftTimeHigh"]))
336 t_data.push_back(make_pair(t_compare, t_assigns));
341 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[
"maxDriftTimeLow"], mSignalStorage[
"maxDriftTimeHigh"]))
344 t_data.push_back(make_pair(t_compare, t_assigns));
349 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] - mSignalStorage[
"maxDriftTimeMax"]).limit(mSignalStorage[
"maxDriftTimeLow"], mSignalStorage[
"maxDriftTimeHigh"]))
352 t_data.push_back(make_pair(t_compare, t_assigns));
367 if (mSignalStorage.find(
"minDriftTime") == mSignalStorage.end()) {
368 int minDriftTime = -8;
369 mSignalStorage[
"minDriftTime"] =
Belle2::TRGCDCJSignal(minDriftTime, mSignalStorage[
"eventTime"].getToReal(), commonData);
370 mSignalStorage[
"minDriftTimeLow"] =
Belle2::TRGCDCJSignal(0, mSignalStorage[
"eventTime"].getToReal(), commonData);
372 for (
unsigned iSt = 0; iSt < 4; iSt++) {
373 string t_in1Name =
"driftTime_c_" + to_string(iSt);
374 string t_valueName =
"driftTime_" + to_string(iSt);
375 string t_in2Name =
"invErrorRho_" + to_string(iSt);
376 string t_value2Name =
"iZError2_" + to_string(iSt);
377 string t_noneErrorName =
"iZNoneError2_" + to_string(iSt);
379 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
383 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
384 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[
"minDriftTimeLow"], mSignalStorage[
"maxDriftTimeHigh"])),
385 make_pair(&mSignalStorage[t_value2Name], mSignalStorage[t_in2Name])
388 t_data.push_back(make_pair(t_compare, t_assigns));
393 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"minDriftTimeLow"]),
394 make_pair(&mSignalStorage[t_value2Name], mSignalStorage[t_in2Name])
397 t_data.push_back(make_pair(t_compare, t_assigns));
402 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"minDriftTimeLow"]),
403 make_pair(&mSignalStorage[t_value2Name], mSignalStorage[t_noneErrorName])
406 t_data.push_back(make_pair(t_compare, t_assigns));
420 if (!mSignalStorage.count(
"invDriftPhiMin")) {
421 mSignalStorage[
"invDriftPhiMin"] =
Belle2::TRGCDCJSignal(0, mSignalStorage[
"driftTime_0"].getToReal(), commonData);
423 mSignalStorage[
"driftTime_0"].getToReal(), commonData);
428 for (
unsigned iSt = 0; iSt < 4; iSt++) {
429 string t_valueName =
"driftPhi_" + to_string(iSt);
430 string t_inName =
"driftTime_" + to_string(iSt);
431 if (!mLutStorage.count(t_valueName)) {
434 double t_parameter = mConstV.at(
"rr3D")[iSt];
435 mLutStorage[t_valueName]->setFloatFunction(
437 [ = ](
double aValue) ->
double{
return atan(mConstV.at(
"driftLengthTableSL" + to_string(2 * iSt + 1))[aValue] / t_parameter);},
438 mSignalStorage[t_inName],
439 mSignalStorage[
"invDriftPhiMin"], mSignalStorage[
"invDriftPhiMax"], mSignalStorage[
"phi0"].getToReal(),
440 (int)mConstD.at(
"driftPhiLUTInBitSize"), (int)mConstD.at(
"driftPhiLUTOutBitSize"));
446 for (
unsigned iSt = 0; iSt < 4; iSt++) {
449 mLutStorage[
"driftPhi_" + to_string(iSt)]->operate(mSignalStorage[
"driftTime_" + to_string(iSt)],
450 mSignalStorage[
"driftPhi_" + to_string(iSt)]);
456 for (
unsigned iSt = 0; iSt < 4; iSt++) {
457 string t_in1Name =
"lr_" + to_string(iSt);
458 string t_valueName =
"finePhi_" + to_string(iSt);
460 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
463 mSignalStorage[t_in1Name].getToReal(), commonData));
465 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
466 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"wirePhi_" + to_string(iSt)] - mSignalStorage[
"driftPhi_" + to_string(iSt)])
469 t_data.push_back(make_pair(t_compare, t_assigns));
472 mSignalStorage[t_in1Name].getToReal(), commonData));
475 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"wirePhi_" + to_string(iSt)] + mSignalStorage[
"driftPhi_" + to_string(iSt)])
478 t_data.push_back(make_pair(t_compare, t_assigns));
483 make_pair(&mSignalStorage[t_valueName], mSignalStorage[
"wirePhi_" + to_string(iSt)])
486 t_data.push_back(make_pair(t_compare, t_assigns));
493 if (mSignalStorage.find(
"phiMax_0") == mSignalStorage.end()) {
494 for (
unsigned iSt = 0; iSt < 4; iSt++) {
495 string t_valueName =
"finePhi_" + to_string(iSt);
496 string t_maxName =
"phiMax_" + to_string(iSt);
497 string t_minName =
"phiMin_" + to_string(iSt);
498 string t_2PiName =
"phi2Pi_" + to_string(iSt);
499 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
500 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(-mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
501 mSignalStorage[t_2PiName] =
Belle2::TRGCDCJSignal(2 * mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
504 for (
unsigned iSt = 0; iSt < 4; iSt++) {
505 string t_in1Name =
"finePhi_" + to_string(iSt);
506 string t_valueName =
"phi_" + to_string(iSt);
507 string t_maxName =
"phiMax_" + to_string(iSt);
508 string t_minName =
"phiMin_" + to_string(iSt);
509 string t_2PiName =
"phi2Pi_" + to_string(iSt);
511 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
515 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
516 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] - mSignalStorage[t_2PiName]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
519 t_data.push_back(make_pair(t_compare, t_assigns));
524 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
527 t_data.push_back(make_pair(t_compare, t_assigns));
532 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] + mSignalStorage[t_2PiName]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
535 t_data.push_back(make_pair(t_compare, t_assigns));
545 for (
unsigned iSt = 0; iSt < stXts.size(); ++iSt) {
546 string filename = filePrefix +
".st" + to_string(iSt);
548 cout <<
"Fitter3DUtility::saveStereoXt() Saving xt file to " << filename << endl;
549 xtFile.open(filename);
550 for (
unsigned iTick = 0; iTick < stXts[iSt].size(); ++iTick) {
551 xtFile << stXts[iSt][iTick] << endl;
559 stXts = vector<vector<double> > (nFiles);
560 for (
unsigned iSt = 0; iSt < stXts.size(); ++iSt) {
561 string filename = filePrefix +
".st" + to_string(iSt);
563 xtFile.open(filename.c_str());
565 cout <<
"Fitter3DUtility::loadStereoXt() Cannot load " << filename << endl;
569 while (getline(xtFile, line)) {
570 stXts[iSt].push_back(std::stof(line));
578 return (
double)
id / stNWires[iSt] * 4 * M_PI;
584 int eventTime, vector<vector<int> >
const& rawStTSs, vector<double>& stTSs)
586 stTSs = vector<double> (4, 9999);
587 if (eventTimeValid == 0) {
588 for (
unsigned iSt = 0; iSt < 4; iSt++) {
589 stTSs[iSt] =
stereoIdToPhi(stGeometry[
"nWires"], iSt, rawStTSs[iSt][0]);
593 for (
unsigned iSt = 0; iSt < 4; iSt++) {
594 if (rawStTSs[iSt][1] != 0) {
596 int t = rawStTSs[iSt][2] - eventTime;
599 if (t > 511) t = 511;
600 double driftLength = stXts[iSt][t];
602 stGeometry[
"cdcRadius"][iSt], rawStTSs[iSt][1]);
611 double phiMin = -M_PI;
612 double phiMax = M_PI;
613 double result = value - refPhi;
615 while (rangeOK == 0) {
616 if (result > phiMax) result -= 2 * M_PI;
617 else if (result < phiMin) result += 2 * M_PI;
625 double refPhi = (double)refId / nTSs * 2 * M_PI;
631 int result = value - refId;
633 while (rangeOk == 0) {
634 if (result >= nTSs) result -= nTSs;
635 else if (result < 0) result += nTSs;
644 double phiMin = -M_PI;
645 double phiMax = M_PI;
647 while (rangeOK == 0) {
648 if (value > phiMax) value -= 2 * M_PI;
649 else if (value < phiMin) value += 2 * M_PI;
654 if (value > M_PI_2) result = 2;
655 else if (value > 0) result = 1;
656 else if (value > -M_PI_2) result = 4;
657 else if (value > -M_PI) result = 3;
664 std::vector<double>& invZError2)
666 vector<double> driftZError({0.7676, 0.9753, 1.029, 1.372});
667 vector<double> wireZError({0.7676, 0.9753, 1.029, 1.372});
668 vector<double> zError(4, 9999);
669 invZError2 = vector<double> (4, 0);
670 for (
unsigned iSt = 0; iSt < 4; ++iSt) {
671 if (rawStTSs[iSt][1] != 0) {
673 if (rawStTSs[iSt][1] != 3 && eventTimeValid != 0) zError[iSt] = driftZError[iSt];
674 else zError[iSt] = wireZError[iSt];
676 invZError2[iSt] = 1 / pow(zError[iSt], 2);
682 std::map<std::string, std::vector<double> >
const& mConstV, std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage)
686 if (mSignalStorage.find(
"iZWireError2_0") == mSignalStorage.end()) {
687 for (
unsigned iSt = 0; iSt < 4; iSt++) {
689 t_name =
"iZWireError2_" + to_string(iSt);
690 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(mConstD.at(
"iError2BitSize"), 1 / pow(mConstV.at(
"wireZError")[iSt], 2), 0,
691 mConstD.at(
"iError2Max"), -1, commonData);
692 t_name =
"iZDriftError2_" + to_string(iSt);
693 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(mConstD.at(
"iError2BitSize"), 1 / pow(mConstV.at(
"driftZError")[iSt], 2), 0,
694 mConstD.at(
"iError2Max"), -1, commonData);
695 t_name =
"iZNoneError2_" + to_string(iSt);
696 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(mConstD.at(
"iError2BitSize"), 0, 0, mConstD.at(
"iError2Max"), -1, commonData);
705 for (
unsigned iSt = 0; iSt < 4; iSt++) {
706 string t_in1Name =
"lr_" + to_string(iSt);
707 string t_valueName =
"invErrorLR_" + to_string(iSt);
708 string t_noneErrorName =
"iZNoneError2_" + to_string(iSt);
709 string t_driftErrorName =
"iZDriftError2_" + to_string(iSt);
710 string t_wireErrorName =
"iZWireError2_" + to_string(iSt);
712 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
715 mSignalStorage[t_in1Name].getToReal(), commonData));
717 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
718 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_noneErrorName])
721 t_data.push_back(make_pair(t_compare, t_assigns));
724 mSignalStorage[t_in1Name].getToReal(), commonData));
727 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_wireErrorName])
730 t_data.push_back(make_pair(t_compare, t_assigns));
735 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_driftErrorName])
738 t_data.push_back(make_pair(t_compare, t_assigns));
745 if (mSignalStorage.find(
"halfRadius_0") == mSignalStorage.end()) {
746 for (
unsigned iSt = 0; iSt < 4; iSt++) {
748 t_name =
"halfRadius_" + to_string(iSt);
749 mSignalStorage[t_name] =
Belle2::TRGCDCJSignal(mConstV.at(
"rr")[iSt * 2 + 1] / 2, mSignalStorage[
"rho"].getToReal(), commonData);
755 for (
unsigned iSt = 0; iSt < 4; iSt++) {
756 string t_compareName =
"halfRadius_" + to_string(iSt);
758 string t_valueName =
"invErrorRho_" + to_string(iSt);
759 string t_noneErrorName =
"iZNoneError2_" + to_string(iSt);
760 string t_in1Name =
"invErrorLR_" + to_string(iSt);
762 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
766 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
767 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_noneErrorName])
770 t_data.push_back(make_pair(t_compare, t_assigns));
775 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name])
778 t_data.push_back(make_pair(t_compare, t_assigns));
787 if (
false) cout << anglest << ztostraw << endl;
789 double myphiz, acos_real;
792 if (rr > (2 * rho)) t_rho = rr / 2;
793 acos_real = acos(rr / (2 * t_rho));
795 myphiz = +acos_real + myphi0;
797 myphiz = -acos_real + myphi0;
799 if (myphiz > M_PI) myphiz -= 2 * M_PI;
800 if (myphiz < -M_PI) myphiz += 2 * M_PI;
807 if (
false) cout << anglest << ztostraw << endl;
809 double myphiz, acos_real;
812 if (rr > (2 * rho)) t_rho = rr / 2;
813 acos_real = acos(rr / (2 * t_rho));
815 myphiz = -acos_real - myphi0 + phi2;
817 myphiz = +acos_real - myphi0 + phi2;
819 if (myphiz > M_PI) myphiz -= 2 * M_PI;
820 if (myphiz < -M_PI) myphiz += 2 * M_PI;
826 std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage)
830 if (mSignalStorage.find(
"rhoMin_0") == mSignalStorage.end()) {
831 for (
unsigned iSt = 0; iSt < 4; iSt++) {
833 string t_minName =
"rhoMin_" + to_string(iSt);
834 double t_actual = (mConstV.find(
"rr")->second)[2 * iSt + 1] / 2;
835 double t_toReal = mSignalStorage[
"rho"].getToReal();
838 if (mSignalStorage[t_minName].getRealInt() < t_actual) {
839 t_actual += 1 * t_toReal;
845 string t_maxName =
"rhoMax_" + to_string(iSt);
846 t_actual = mSignalStorage[
"rho"].getMaxActual();
855 for (
unsigned iSt = 0; iSt < 4; iSt++) {
856 string t_in1Name =
"rho";
857 string t_valueName =
"rho_c_" + to_string(iSt);
858 string t_maxName =
"rhoMax_" + to_string(iSt);
859 string t_minName =
"rhoMin_" + to_string(iSt);
861 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
865 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
866 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_maxName]),
869 t_data.push_back(make_pair(t_compare, t_assigns));
874 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[t_minName], mSignalStorage[t_maxName]))
877 t_data.push_back(make_pair(t_compare, t_assigns));
882 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_minName])
885 t_data.push_back(make_pair(t_compare, t_assigns));
892double Fitter3DUtility::calZ(
int mysign,
double anglest,
double ztostraw,
double rr,
double phi2,
double rho,
double myphi0)
894 double myphiz = 0, acos_real = 0, dPhiAx = 0;
897 if (rr > (2 * rho)) t_rho = rr / 2;
898 acos_real = acos(rr / (2 * t_rho));
900 dPhiAx = -acos_real - myphi0;
902 dPhiAx = acos_real - myphi0;
904 myphiz = dPhiAx + phi2;
905 if (myphiz > M_PI) myphiz -= 2 * M_PI;
906 if (myphiz < -M_PI) myphiz += 2 * M_PI;
908 return (ztostraw - rr * 2 * sin(myphiz / 2) / anglest);
911void Fitter3DUtility::calZ(std::map<std::string, double>
const& mConstD, std::map<std::string, std::vector<double> >
const& mConstV,
912 std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage, std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage)
916 if (mSignalStorage.find(
"invPhiAxMin_0") == mSignalStorage.end()) {
933 for (
unsigned iSt = 0; iSt < 4; iSt++) {
934 string t_invMinName =
"invPhiAxMin_" + to_string(iSt);
936 double t_actual = mSignalStorage[
"rho_c_" + to_string(iSt)].getMinActual();
937 double t_toReal = mSignalStorage[
"rho_c_" + to_string(iSt)].getToReal();
939 string t_invMaxName =
"invPhiAxMax_" + to_string(iSt);
940 t_actual = mSignalStorage[
"rho_c_" + to_string(iSt)].getMaxActual();
948 for (
unsigned iSt = 0; iSt < 4; iSt++) {
949 string t_valueName =
"phiAx_" + to_string(iSt);
950 string t_minName =
"phiAxMin_" + to_string(iSt);
951 string t_maxName =
"phiAxMax_" + to_string(iSt);
952 string t_invMinName =
"invPhiAxMin_" + to_string(iSt);
953 string t_invMaxName =
"invPhiAxMax_" + to_string(iSt);
954 if (!mLutStorage.count(t_valueName)) {
957 double t_parameter = mConstV.at(
"rr3D")[iSt];
958 mLutStorage[t_valueName]->setFloatFunction(
959 [ = ](
double aValue) ->
double{
return acos(t_parameter / 2 / aValue);},
961 mSignalStorage[
"rho_c_" + to_string(iSt)],
962 mSignalStorage[t_invMinName], mSignalStorage[t_invMaxName], mSignalStorage[
"phi0"].getToReal(),
963 (int)mConstD.at(
"acosLUTInBitSize"), (int)mConstD.at(
"acosLUTOutBitSize"));
969 for (
unsigned iSt = 0; iSt < 4; iSt++) {
971 string t_valueName =
"phiAx_" + to_string(iSt);
973 mLutStorage[t_valueName]->operate(mSignalStorage[
"rho_c_" + to_string(iSt)], mSignalStorage[t_valueName]);
981 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
984 commonData),
"=", mSignalStorage[
"charge"]);
986 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
987 make_pair(&mSignalStorage[
"dPhiAx_0"], -mSignalStorage[
"phiAx_0"] - mSignalStorage[
"phi0"]),
988 make_pair(&mSignalStorage[
"dPhiAx_1"], -mSignalStorage[
"phiAx_1"] - mSignalStorage[
"phi0"]),
989 make_pair(&mSignalStorage[
"dPhiAx_2"], -mSignalStorage[
"phiAx_2"] - mSignalStorage[
"phi0"]),
990 make_pair(&mSignalStorage[
"dPhiAx_3"], -mSignalStorage[
"phiAx_3"] - mSignalStorage[
"phi0"])
993 t_data.push_back(make_pair(t_compare, t_assigns));
998 make_pair(&mSignalStorage[
"dPhiAx_0"], mSignalStorage[
"phiAx_0"] - mSignalStorage[
"phi0"]),
999 make_pair(&mSignalStorage[
"dPhiAx_1"], mSignalStorage[
"phiAx_1"] - mSignalStorage[
"phi0"]),
1000 make_pair(&mSignalStorage[
"dPhiAx_2"], mSignalStorage[
"phiAx_2"] - mSignalStorage[
"phi0"]),
1001 make_pair(&mSignalStorage[
"dPhiAx_3"], mSignalStorage[
"phiAx_3"] - mSignalStorage[
"phi0"])
1004 t_data.push_back(make_pair(t_compare, t_assigns));
1011 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1012 mSignalStorage[
"dPhi_" + to_string(iSt)] <= mSignalStorage[
"dPhiAx_" + to_string(iSt)] + mSignalStorage[
"phi_" + to_string(iSt)];
1017 if (mSignalStorage.find(
"dPhiPiMax_0") == mSignalStorage.end()) {
1018 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1019 string t_valueName =
"dPhi_" + to_string(iSt);
1020 string t_maxName =
"dPhiPiMax_" + to_string(iSt);
1021 string t_minName =
"dPhiPiMin_" + to_string(iSt);
1022 string t_2PiName =
"dPhiPi2Pi_" + to_string(iSt);
1023 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
1024 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(-mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
1025 mSignalStorage[t_2PiName] =
Belle2::TRGCDCJSignal(2 * mConstD.at(
"M_PI"), mSignalStorage[t_valueName].getToReal(), commonData);
1028 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1029 string t_in1Name =
"dPhi_" + to_string(iSt);
1030 string t_valueName =
"dPhiPi_c_" + to_string(iSt);
1031 string t_maxName =
"dPhiPiMax_" + to_string(iSt);
1032 string t_minName =
"dPhiPiMin_" + to_string(iSt);
1033 string t_2PiName =
"dPhiPi2Pi_" + to_string(iSt);
1035 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1039 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1040 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] - mSignalStorage[t_2PiName]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1043 t_data.push_back(make_pair(t_compare, t_assigns));
1048 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1051 t_data.push_back(make_pair(t_compare, t_assigns));
1056 make_pair(&mSignalStorage[t_valueName], (mSignalStorage[t_in1Name] + mSignalStorage[t_2PiName]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1059 t_data.push_back(make_pair(t_compare, t_assigns));
1066 if (mSignalStorage.find(
"dPhiMax_0") == mSignalStorage.end()) {
1067 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1068 string t_maxName =
"dPhiMax_" + to_string(iSt);
1069 string t_minName =
"dPhiMin_" + to_string(iSt);
1070 string t_valueName =
"dPhi_" + to_string(iSt);
1071 double t_value = 2 * mConstD.at(
"M_PI") * fabs(mConstV.at(
"nShift")[iSt]) / (mConstV.at(
"nWires")[2 * iSt + 1]);
1072 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(t_value, mSignalStorage[t_valueName].getToReal(), commonData);
1073 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(0, mSignalStorage[t_valueName].getToReal(), commonData);
1077 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1078 string t_maxName =
"dPhiMax_" + to_string(iSt);
1079 string t_minName =
"dPhiMin_" + to_string(iSt);
1080 string t_valueName =
"dPhi_c_" + to_string(iSt);
1081 string t_in1Name =
"dPhiPi_c_" + to_string(iSt);
1085 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1088 mSignalStorage[t_in1Name].getToReal(), commonData));
1090 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1091 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_minName]),
1094 t_data.push_back(make_pair(t_compare, t_assigns));
1099 make_pair(&mSignalStorage[t_valueName],
Belle2::TRGCDCJSignal::absolute(mSignalStorage[t_in1Name]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1102 t_data.push_back(make_pair(t_compare, t_assigns));
1107 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_maxName]),
1110 t_data.push_back(make_pair(t_compare, t_assigns));
1116 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1120 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1121 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_maxName]),
1124 t_data.push_back(make_pair(t_compare, t_assigns));
1127 mSignalStorage[t_in1Name].getToReal(), commonData));
1130 make_pair(&mSignalStorage[t_valueName],
Belle2::TRGCDCJSignal::absolute(mSignalStorage[t_in1Name]).limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1133 t_data.push_back(make_pair(t_compare, t_assigns));
1138 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_minName]),
1141 t_data.push_back(make_pair(t_compare, t_assigns));
1151 if (mSignalStorage.find(
"invZMin_0") == mSignalStorage.end()) {
1152 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1153 string t_minName =
"invZMin_" + to_string(iSt);
1154 string t_maxName =
"invZMax_" + to_string(iSt);
1155 string t_valueName =
"dPhi_c_" + to_string(iSt);
1156 unsigned long long t_int = mSignalStorage[t_valueName].getMinInt();
1157 double t_toReal = mSignalStorage[t_valueName].getToReal();
1158 double t_actual = mSignalStorage[t_valueName].getMinActual();
1159 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(t_int, t_toReal, t_int, t_int, t_actual, t_actual, t_actual, -1, commonData);
1160 t_int = mSignalStorage[t_valueName].getMaxInt();
1161 t_actual = mSignalStorage[t_valueName].getMaxActual();
1162 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(t_int, t_toReal, t_int, t_int, t_actual, t_actual, t_actual, -1, commonData);
1166 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1167 string t_inputName =
"dPhi_c_" + to_string(iSt);
1168 string t_outputName =
"zz_" + to_string(iSt);
1169 string t_invMinName =
"invZMin_" + to_string(iSt);
1170 string t_invMaxName =
"invZMax_" + to_string(iSt);
1172 if (!mLutStorage.count(t_outputName)) {
1175 double t_zToStraw = mConstV.at(
"zToStraw")[iSt];
1176 double t_rr3D = mConstV.at(
"rr3D")[iSt];
1177 double t_angleSt = mConstV.at(
"angleSt")[iSt];
1180 mLutStorage[t_outputName]->setFloatFunction(
1181 [ = ](
double aValue) ->
double{
return t_zToStraw + t_rr3D * 2 * sin(aValue / 2) / t_angleSt;},
1182 mSignalStorage[t_inputName],
1183 mSignalStorage[t_invMinName], mSignalStorage[t_invMaxName], mSignalStorage[
"rho"].getToReal(),
1184 (int) mConstD.at(
"zLUTInBitSize"), (int) mConstD.at(
"zLUTOutBitSize"));
1186 mLutStorage[t_outputName]->setFloatFunction(
1187 [ = ](
double aValue) ->
double{
return t_zToStraw - t_rr3D * 2 * sin(aValue / 2) / t_angleSt;},
1188 mSignalStorage[t_inputName],
1189 mSignalStorage[t_invMinName], mSignalStorage[t_invMaxName], mSignalStorage[
"rho"].getToReal(),
1190 (int) mConstD.at(
"zLUTInBitSize"), (int) mConstD.at(
"zLUTOutBitSize"));
1197 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1198 string t_outputName =
"zz_" + to_string(iSt);
1199 string t_inputName =
"dPhi_c_" + to_string(iSt);
1200 mLutStorage[t_outputName]->operate(mSignalStorage[t_inputName], mSignalStorage[t_outputName]);
1207 result = rho * 2 * asin(rr / 2 / rho);
1211void Fitter3DUtility::calS(std::map<std::string, double>
const& mConstD, std::map<std::string, std::vector<double> >
const& mConstV,
1212 std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage, std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage)
1216 if (mSignalStorage.find(
"invArcSMin_0") == mSignalStorage.end()) {
1233 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1234 string t_invMinName =
"invArcSMin_" + to_string(iSt);
1236 double t_actual = mSignalStorage[
"rho_c_" + to_string(iSt)].getMaxActual();
1237 double t_toReal = mSignalStorage[
"rho_c_" + to_string(iSt)].getToReal();
1239 string t_invMaxName =
"invArcSMax_" + to_string(iSt);
1240 t_actual = mSignalStorage[
"rho_c_" + to_string(iSt)].getMinActual();
1248 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1249 string t_valueName =
"arcS_" + to_string(iSt);
1250 string t_invMinName =
"invArcSMin_" + to_string(iSt);
1251 string t_invMaxName =
"invArcSMax_" + to_string(iSt);
1252 if (!mLutStorage.count(t_valueName)) {
1255 double t_parameter = mConstV.at(
"rr3D")[iSt];
1256 mLutStorage[t_valueName]->setFloatFunction(
1257 [ = ](
double aValue) ->
double{
return 2 * aValue * asin(t_parameter / 2 / aValue);},
1259 mSignalStorage[
"rho_c_" + to_string(iSt)],
1260 mSignalStorage[t_invMinName], mSignalStorage[t_invMaxName], mSignalStorage[
"rho"].getToReal(),
1261 (int)mConstD.at(
"acosLUTInBitSize"), (int)mConstD.at(
"acosLUTOutBitSize"));
1267 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1269 string t_valueName =
"arcS_" + to_string(iSt);
1271 mLutStorage[t_valueName]->operate(mSignalStorage[
"rho_c_" + to_string(iSt)], mSignalStorage[t_valueName]);
1281 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1282 t_sum1 += pow(1 / zError[iSt], 2);
1283 t_sumSS += pow(arcS[iSt] / zError[iSt], 2);
1284 t_sumS += arcS[iSt] / pow(zError[iSt], 2);
1286 return t_sum1 * t_sumSS - pow(t_sumS, 2);
1294 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1295 t_sum1 += pow(iZError[iSt], 2);
1296 t_sumSS += pow(arcS[iSt] * iZError[iSt], 2);
1297 t_sumS += arcS[iSt] * pow(iZError[iSt], 2);
1299 return t_sum1 * t_sumSS - pow(t_sumS, 2);
1306 double ss = 0, sx = 0, sxx = 0, cotnum = 0, z0num = 0;
1307 double z0nump1[4], z0nump2[4];
1308 double z0den, iz0den;
1310 for (
unsigned i = 0; i < 4; i++) {
1312 sx += arcS[i] * iezz2[i];
1313 sxx += arcS[i] * arcS[i] * iezz2[i];
1316 for (
unsigned i = 0; i < 4; i++) {
1317 cotnum += (ss * arcS[i] - sx) * iezz2[i] * zz[i];
1318 z0nump1[i] = sxx - sx * arcS[i];
1319 z0nump2[i] = z0nump1[i] * iezz2[i] * zz[i];
1320 z0num += z0nump2[i];
1322 z0den = (ss * sxx) - (sx * sx);
1323 iz0den = 1. / z0den;
1331 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1332 if (iezz2[iSt] != 0) nTSHits++;
1336 for (
unsigned i = 0; i < 4; i++) {
1337 zchi2 += (zz[i] - z0 - cot * arcS[i]) * (zz[i] - z0 - cot * arcS[i]) * iezz2[i];
1339 zchi2 /= (nTSHits - 2);
1348 double ss = 0, sx = 0, sxx = 0, cotnum = 0, z0num = 0;
1349 double z0nump1[4], z0nump2[4];
1350 double z0den, iz0den;
1352 for (
unsigned i = 0; i < 4; i++) {
1355 sx += arcS[i] * iezz21[i];
1356 sxx += arcS[i] * arcS[i] * iezz21[i];
1359 sx += arcS[i] * iezz22[i];
1360 sxx += arcS[i] * arcS[i] * iezz22[i];
1364 for (
unsigned i = 0; i < 4; i++) {
1366 cotnum += (ss * arcS[i] - sx) * iezz21[i] * zz[i];
1367 z0nump1[i] = sxx - sx * arcS[i];
1368 z0nump2[i] = z0nump1[i] * iezz21[i] * zz[i];
1369 z0num += z0nump2[i];
1371 cotnum += (ss * arcS[i] - sx) * iezz22[i] * zz[i];
1372 z0nump1[i] = sxx - sx * arcS[i];
1373 z0nump2[i] = z0nump1[i] * iezz22[i] * zz[i];
1374 z0num += z0nump2[i];
1377 z0den = (ss * sxx) - (sx * sx);
1378 iz0den = 1. / z0den;
1386 for (
unsigned i = 0; i < 4; i++) {
1388 zchi2 += (zz[i] - z0 - cot * arcS[i]) * (zz[i] - z0 - cot * arcS[i]) * iezz21[i];
1390 zchi2 += (zz[i] - z0 - cot * arcS[i]) * (zz[i] - z0 - cot * arcS[i]) * iezz22[i];
1397 std::map<std::string, std::vector<double> >
const& mConstV, std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage,
1398 std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage)
1402 mSignalStorage[
"sum1_p1_0"] <= mSignalStorage[
"iZError2_0"] + mSignalStorage[
"iZError2_1"];
1404 mSignalStorage[
"sum1_p1_1"] <= mSignalStorage[
"iZError2_2"] + mSignalStorage[
"iZError2_3"];
1407 mSignalStorage[
"sum1"] <= mSignalStorage[
"sum1_p1_0"] + mSignalStorage[
"sum1_p1_1"];
1410 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1411 mSignalStorage[
"sumS_p1_" + to_string(iSt)] <= mSignalStorage[
"arcS_" + to_string(iSt)] * mSignalStorage[
"iZError2_" + to_string(
1415 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1416 mSignalStorage[
"sumSS_p1_" + to_string(iSt)] <= mSignalStorage[
"arcS_" + to_string(iSt)] * mSignalStorage[
"arcS_" + to_string(iSt)];
1419 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1420 mSignalStorage[
"cotNumS_p1_" + to_string(iSt)] <= mSignalStorage[
"sum1"] * mSignalStorage[
"arcS_" + to_string(iSt)];
1426 mSignalStorage[
"sumS_p2_0"] <= mSignalStorage[
"sumS_p1_0"] + mSignalStorage[
"sumS_p1_1"];
1428 mSignalStorage[
"sumS_p2_1"] <= mSignalStorage[
"sumS_p1_2"] + mSignalStorage[
"sumS_p1_3"];
1430 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1431 mSignalStorage[
"sumSS_p2_" + to_string(iSt)] <= mSignalStorage[
"sumSS_p1_" + to_string(iSt)] * mSignalStorage[
"iZError2_" +
1437 mSignalStorage[
"sumS"] <= mSignalStorage[
"sumS_p2_0"] + mSignalStorage[
"sumS_p2_1"];
1439 mSignalStorage[
"sumSS_p3_0"] <= mSignalStorage[
"sumSS_p2_0"] + mSignalStorage[
"sumSS_p2_1"];
1441 mSignalStorage[
"sumSS_p3_1"] <= mSignalStorage[
"sumSS_p2_2"] + mSignalStorage[
"sumSS_p2_3"];
1446 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1447 mSignalStorage[
"z0NumS_p1_" + to_string(iSt)] <= mSignalStorage[
"arcS_" + to_string(iSt)] * mSignalStorage[
"sumS"];
1450 mSignalStorage[
"den_p1"] <= mSignalStorage[
"sumS"] * mSignalStorage[
"sumS"];
1452 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1453 mSignalStorage[
"cotNumS_" + to_string(iSt)] <= mSignalStorage[
"cotNumS_p1_" + to_string(iSt)] - mSignalStorage[
"sumS"];
1456 mSignalStorage[
"sumSS"] <= mSignalStorage[
"sumSS_p3_0"] + mSignalStorage[
"sumSS_p3_1"];
1458 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1459 mSignalStorage[
"zxiZError_" + to_string(iSt)] <= mSignalStorage[
"zz_" + to_string(iSt)] * mSignalStorage[
"iZError2_" + to_string(
1468 mSignalStorage[
"den_p2"] <= mSignalStorage[
"sum1"] * mSignalStorage[
"sumSS"];
1470 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1471 mSignalStorage[
"z0NumS_" + to_string(iSt)] <= mSignalStorage[
"sumSS"] - mSignalStorage[
"z0NumS_p1_" + to_string(iSt)];
1476 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1477 mSignalStorage[
"cotNumSZ_" + to_string(iSt)] <= mSignalStorage[
"cotNumS_" + to_string(iSt)] * mSignalStorage[
"zxiZError_" +
1481 mSignalStorage[
"den"] <= mSignalStorage[
"den_p2"] - mSignalStorage[
"den_p1"];
1483 if (mSignalStorage.find(
"denMin") == mSignalStorage.end()) {
1485 double t_rr3D[4], t_wireZError[4];
1486 for (
int iSt = 0; iSt < 2; iSt++) {
1487 t_rr3D[iSt] = mConstV.at(
"rr3D")[iSt];
1488 t_wireZError[iSt] = 1 / mConstV.at(
"wireZError")[iSt];
1490 for (
int iSt = 2; iSt < 4; iSt++) {
1491 t_rr3D[iSt] = mConstV.at(
"rr3D")[iSt];
1492 t_wireZError[iSt] = 0;
1495 mSignalStorage[
"denMin"] =
Belle2::TRGCDCJSignal(t_denMin, mSignalStorage[
"den"].getToReal(), commonData);
1496 double t_arcSMax[4], t_driftZError[4];
1497 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1498 t_arcSMax[iSt] = mConstD.at(
"M_PI") * mConstV.at(
"rr3D")[iSt] / 2;
1499 t_driftZError[iSt] = 1 / mConstV.at(
"driftZError")[iSt];
1502 mSignalStorage[
"denMax"] =
Belle2::TRGCDCJSignal(t_denMax, mSignalStorage[
"den"].getToReal(), commonData);
1507 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1511 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1512 make_pair(&mSignalStorage[
"den_c"], mSignalStorage[
"denMax"])
1515 t_data.push_back(make_pair(t_compare, t_assigns));
1520 make_pair(&mSignalStorage[
"den_c"], mSignalStorage[
"den"].limit(mSignalStorage[
"denMin"], mSignalStorage[
"denMax"]))
1523 t_data.push_back(make_pair(t_compare, t_assigns));
1528 make_pair(&mSignalStorage[
"den_c"], mSignalStorage[
"denMin"])
1531 t_data.push_back(make_pair(t_compare, t_assigns));
1535 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1536 mSignalStorage[
"z0NumSZ_" + to_string(iSt)] <= mSignalStorage[
"z0NumS_" + to_string(iSt)] * mSignalStorage[
"zxiZError_" + to_string(
1547 mSignalStorage[
"cot_p1_0"] <= mSignalStorage[
"cotNumSZ_0"] + mSignalStorage[
"cotNumSZ_1"];
1549 mSignalStorage[
"cot_p1_1"] <= mSignalStorage[
"cotNumSZ_2"] + mSignalStorage[
"cotNumSZ_3"];
1551 mSignalStorage[
"z0_p1_0"] <= mSignalStorage[
"z0NumSZ_0"] + mSignalStorage[
"z0NumSZ_1"];
1553 mSignalStorage[
"z0_p1_1"] <= mSignalStorage[
"z0NumSZ_2"] + mSignalStorage[
"z0NumSZ_3"];
1558 if (mSignalStorage.find(
"invIDenMin") == mSignalStorage.end()) {
1559 unsigned long long t_int = mSignalStorage[
"den_c"].getMaxInt();
1560 double t_toReal = mSignalStorage[
"den_c"].getToReal();
1561 double t_actual = mSignalStorage[
"den_c"].getMaxActual();
1562 mSignalStorage[
"invIDenMin"] =
Belle2::TRGCDCJSignal(t_int, t_toReal, t_int, t_int, t_actual, t_actual, t_actual, -1, commonData);
1563 t_int = mSignalStorage[
"den_c"].getMinInt();
1564 t_actual = mSignalStorage[
"den_c"].getMinActual();
1565 mSignalStorage[
"invIDenMax"] =
Belle2::TRGCDCJSignal(t_int, t_toReal, t_int, t_int, t_actual, t_actual, t_actual, -1, commonData);
1570 if (!mLutStorage.count(
"iDen")) {
1572 mLutStorage[
"iDen"]->setFloatFunction(
1573 [ = ](
double aValue) ->
double{
return 1 / aValue;},
1574 mSignalStorage[
"den_c"],
1575 mSignalStorage[
"invIDenMin"], mSignalStorage[
"invIDenMax"],
1576 pow(1 / mSignalStorage[
"rho"].getToReal() / mSignalStorage[
"iZError2_0"].getToReal(), 2),
1577 (int)mConstD.at(
"iDenLUTInBitSize"), (int)mConstD.at(
"iDenLUTOutBitSize"));
1581 mLutStorage[
"iDen"]->operate(mSignalStorage[
"den_c"], mSignalStorage[
"iDen"]);
1589 mSignalStorage[
"cot_p2"] <= mSignalStorage[
"cot_p1_0"] + mSignalStorage[
"cot_p1_1"];
1591 mSignalStorage[
"z0_p2"] <= mSignalStorage[
"z0_p1_0"] + mSignalStorage[
"z0_p1_1"];
1595 mSignalStorage[
"cot"] <= mSignalStorage[
"cot_p2"] * mSignalStorage[
"iDen"];
1597 mSignalStorage[
"z0"] <= mSignalStorage[
"z0_p2"] * mSignalStorage[
"iDen"];
1598 if (mConstD.at(
"JB") == 1) {
1599 cout <<
"<<<cot>>>" << endl; mSignalStorage[
"cot"].dump();
1600 cout <<
"<<<z0>>>" << endl; mSignalStorage[
"z0"].dump();
1609 if (!mSignalStorage.count(
"z0Min")) {
1610 mSignalStorage[
"z0Min"] =
Belle2::TRGCDCJSignal(z0Min, mSignalStorage[
"z0"].getToReal(), commonData);
1611 mSignalStorage[
"z0Max"] =
Belle2::TRGCDCJSignal(z0Max, mSignalStorage[
"z0"].getToReal(), commonData);
1615 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1619 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1620 make_pair(&mSignalStorage[
"z0_c"], mSignalStorage[
"z0Max"])
1623 t_data.push_back(make_pair(t_compare, t_assigns));
1628 make_pair(&mSignalStorage[
"z0_c"], mSignalStorage[
"z0"].limit(mSignalStorage[
"z0Min"], mSignalStorage[
"z0Max"]))
1631 t_data.push_back(make_pair(t_compare, t_assigns));
1636 make_pair(&mSignalStorage[
"z0_c"], mSignalStorage[
"z0Min"])
1639 t_data.push_back(make_pair(t_compare, t_assigns));
1646 double cotMin = cos(127 * mConstD.at(
"M_PI") / 180) / sin(127 * mConstD.at(
"M_PI") / 180);
1647 double cotMax = cos(35 * mConstD.at(
"M_PI") / 180) / sin(35 * mConstD.at(
"M_PI") / 180);
1648 if (!mSignalStorage.count(
"cotMin")) {
1649 mSignalStorage[
"cotMin"] =
Belle2::TRGCDCJSignal(cotMin, mSignalStorage[
"cot"].getToReal(), commonData);
1650 mSignalStorage[
"cotMax"] =
Belle2::TRGCDCJSignal(cotMax, mSignalStorage[
"cot"].getToReal(), commonData);
1654 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1658 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1659 make_pair(&mSignalStorage[
"cot_c"], mSignalStorage[
"cotMax"])
1662 t_data.push_back(make_pair(t_compare, t_assigns));
1667 make_pair(&mSignalStorage[
"cot_c"], mSignalStorage[
"cot"].limit(mSignalStorage[
"cotMin"], mSignalStorage[
"cotMax"]))
1670 t_data.push_back(make_pair(t_compare, t_assigns));
1675 make_pair(&mSignalStorage[
"cot_c"], mSignalStorage[
"cotMin"])
1678 t_data.push_back(make_pair(t_compare, t_assigns));
1690 int z0Shift = mSignalStorage[
"z0_c"].getBitsize() - z0Bits;
1691 mSignalStorage[
"z0_r"] <= mSignalStorage[
"z0_c"].shift(z0Shift, 0);
1692 int cotShift = mSignalStorage[
"cot_c"].getBitsize() - cotBits;
1693 mSignalStorage[
"cot_r"] <= mSignalStorage[
"cot_c"].shift(cotShift, 0);
1702 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1703 mSignalStorage[
"fitDistFromZ0_" + to_string(iSt)] <= mSignalStorage[
"cot"] * mSignalStorage[
"arcS_" + to_string(iSt)];
1706 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1707 mSignalStorage[
"distFromZ0_" + to_string(iSt)] <= mSignalStorage[
"zz_" + to_string(iSt)] - mSignalStorage[
"z0"];
1712 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1713 mSignalStorage[
"chiNum_" + to_string(iSt)] <= mSignalStorage[
"distFromZ0_" + to_string(iSt)] - mSignalStorage[
"fitDistFromZ0_" +
1718 if (mSignalStorage.find(
"chiNumMax_0") == mSignalStorage.end()) {
1719 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1720 string t_maxName =
"chiNumMax_" + to_string(iSt);
1721 string t_minName =
"chiNumMin_" + to_string(iSt);
1722 string t_valueName =
"chiNum_" + to_string(iSt);
1723 double t_maxValue = 2 * mConstV.at(
"zToOppositeStraw")[iSt];
1724 double t_minValue = 2 * mConstV.at(
"zToStraw")[iSt];
1725 mSignalStorage[t_maxName] =
Belle2::TRGCDCJSignal(t_maxValue, mSignalStorage[t_valueName].getToReal(), commonData);
1726 mSignalStorage[t_minName] =
Belle2::TRGCDCJSignal(t_minValue, mSignalStorage[t_valueName].getToReal(), commonData);
1730 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1731 string t_maxName =
"chiNumMax_" + to_string(iSt);
1732 string t_minName =
"chiNumMin_" + to_string(iSt);
1733 string t_valueName =
"chiNum_c_" + to_string(iSt);
1734 string t_in1Name =
"chiNum_" + to_string(iSt);
1736 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1740 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1741 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_maxName]),
1744 t_data.push_back(make_pair(t_compare, t_assigns));
1749 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_in1Name].limit(mSignalStorage[t_minName], mSignalStorage[t_maxName])),
1752 t_data.push_back(make_pair(t_compare, t_assigns));
1757 make_pair(&mSignalStorage[t_valueName], mSignalStorage[t_minName]),
1760 t_data.push_back(make_pair(t_compare, t_assigns));
1768 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1769 mSignalStorage[
"chi2_p1_" + to_string(iSt)] <= mSignalStorage[
"chiNum_c_" + to_string(iSt)] * mSignalStorage[
"chiNum_c_" +
1774 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1775 mSignalStorage[
"chi2_" + to_string(iSt)] <= mSignalStorage[
"chi2_p1_" + to_string(iSt)] * mSignalStorage[
"iZError2_" + to_string(
1780 mSignalStorage[
"chi2Sum_p1_0"] <= mSignalStorage[
"chi2_0"] + mSignalStorage[
"chi2_1"];
1782 mSignalStorage[
"chi2Sum_p1_1"] <= mSignalStorage[
"chi2_2"] + mSignalStorage[
"chi2_3"];
1786 mSignalStorage[
"zChi2"] <= (mSignalStorage[
"chi2Sum_p1_0"] + mSignalStorage[
"chi2Sum_p1_1"]).shift(1);
1787 if (mConstD.at(
"JB") == 1) {cout <<
"<<<zChi2>>>" << endl; mSignalStorage[
"zChi2"].dump();}
1791 double zChi2Min = 0;
1793 double zChi2Max = 100;
1797 if (!mSignalStorage.count(
"zChi2Min")) {
1798 mSignalStorage[
"zChi2Min"] =
Belle2::TRGCDCJSignal(zChi2Min, mSignalStorage[
"zChi2"].getToReal(), commonData);
1799 mSignalStorage[
"zChi2Max"] =
Belle2::TRGCDCJSignal(zChi2Max, mSignalStorage[
"zChi2"].getToReal(), commonData);
1803 vector<pair<Belle2::TRGCDCJSignal, vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > > > t_data;
1807 vector<pair<Belle2::TRGCDCJSignal*, Belle2::TRGCDCJSignal> > t_assigns = {
1808 make_pair(&mSignalStorage[
"zChi2_c"], mSignalStorage[
"zChi2Max"])
1811 t_data.push_back(make_pair(t_compare, t_assigns));
1816 make_pair(&mSignalStorage[
"zChi2_c"], mSignalStorage[
"zChi2"].limit(mSignalStorage[
"zChi2Min"], mSignalStorage[
"zChi2Max"]))
1819 t_data.push_back(make_pair(t_compare, t_assigns));
1824 make_pair(&mSignalStorage[
"zChi2_c"], mSignalStorage[
"zChi2Min"])
1827 t_data.push_back(make_pair(t_compare, t_assigns));
1834 int zChi2Shift = mSignalStorage[
"zChi2_c"].getBitsize() - zChi2Bits;
1835 mSignalStorage[
"zChi2_r"] <= mSignalStorage[
"zChi2_c"].shift(zChi2Shift, 0);
1843 std::vector<std::vector<double> >
const& stXts,
1844 int eventTimeValid,
int eventTime,
1845 std::vector<std::vector<int> >
const& rawStTSs,
1846 int charge,
double radius,
double phi_c,
double& z0,
double& cot,
double& chi2)
1849 vector<double> arcS;
1850 vector<double> invZError2;
1851 fitter3D(stGeometry, stXts, eventTimeValid, eventTime, rawStTSs, charge, radius, phi_c, z0, cot, chi2, arcS, zz, invZError2);
1855 std::vector<std::vector<double> >
const& stXts,
1856 int eventTimeValid,
int eventTime,
1857 std::vector<std::vector<int> >
const& rawStTSs,
1858 int charge,
double radius,
double phi_c,
double& z0,
double& cot,
double& chi2, vector<double>& arcS, vector<double>& zz,
1859 vector<double>& invZError2)
1861 vector<double> stTSs(4);
1864 zz = vector<double> (4, 0);
1865 arcS = vector<double> (4, 0);
1866 for (
unsigned iSt = 0; iSt < 4; iSt++) {
1867 if (rawStTSs[iSt][1] != 0) {
1869 stGeometry[
"cdcRadius"][iSt], stTSs[iSt], radius, phi_c);
1877 const std::map<std::string, std::vector<double> >& mConstV,
1878 int eventTimeValid,
int eventTime,
1879 std::vector<std::vector<int> >
const& rawStTSs,
1880 int charge,
double radius,
double phi_c,
1882 std::map<std::string, Belle2::TRGCDCJLUT*>& mLutStorage)
1886 vector<tuple<string, double, int, double, double, int> > t_values = {
1887 make_tuple(
"phi0", phi_c, mConstD[
"phiBitSize"], mConstD[
"phiMin"], mConstD[
"phiMax"], 0),
1888 make_tuple(
"rho", radius, mConstD[
"rhoBitSize"], mConstD[
"rhoMin"], mConstD[
"rhoMax"], 0),
1889 make_tuple(
"charge", (
int)(charge == 1 ? 1 : 0), 1, 0, 1.5, 0),
1890 make_tuple(
"lr_0", rawStTSs[0][1], 2, 0, 3.5, 0),
1891 make_tuple(
"lr_1", rawStTSs[1][1], 2, 0, 3.5, 0),
1892 make_tuple(
"lr_2", rawStTSs[2][1], 2, 0, 3.5, 0),
1893 make_tuple(
"lr_3", rawStTSs[3][1], 2, 0, 3.5, 0),
1894 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),
1895 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),
1896 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),
1897 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),
1898 make_tuple(
"tdc_0", rawStTSs[0][2], mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1899 make_tuple(
"tdc_1", rawStTSs[1][2], mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1900 make_tuple(
"tdc_2", rawStTSs[2][2], mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1901 make_tuple(
"tdc_3", rawStTSs[3][2], mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1902 make_tuple(
"eventTime", eventTime, mConstD[
"tdcBitSize"], 0, pow(2, mConstD[
"tdcBitSize"]) - 0.5, 0),
1903 make_tuple(
"eventTimeValid", eventTimeValid, 1, 0, 1.5, 0),
1915 if ((*mSignalStorage.begin()).second.getName() ==
"") {
1916 for (
auto it = mSignalStorage.begin(); it != mSignalStorage.end(); ++it) {
1917 (*it).second.setName((*it).first);
1923 ROOT::Math::XYVector& helixCenter,
1924 ROOT::Math::XYZVector& impactPosition)
1934 double rho = sqrt(pow(mcMomentum->X(), 2) + pow(mcMomentum->Y(), 2)) / 0.3 / 1.5 * 100;
1935 double hcx = mcPosition->X() + rho * cos(atan2(mcMomentum->Y(), mcMomentum->X()) - charge * M_PI_2);
1936 double hcy = mcPosition->Y() + rho * sin(atan2(mcMomentum->Y(), mcMomentum->X()) - charge * M_PI_2);
1937 helixCenter.SetXY(hcx, hcy);
1938 double impactX = (helixCenter.R() - rho) / helixCenter.R() * helixCenter.X();
1939 double impactY = (helixCenter.R() - rho) / helixCenter.R() * helixCenter.Y();
1941 if (atan2(impactY, impactX) < atan2(mcPosition->Y(), mcPosition->X())) signdS = -1;
1943 double dS = 2 * rho * asin(sqrt(pow(impactX - mcPosition->X(), 2) + pow(impactY - mcPosition->Y(), 2)) / 2 / rho);
1944 double impactZ = mcMomentum->Pz() / mcMomentum->Pt() * dS * signdS + mcPosition->Z();
1945 impactPosition.SetXYZ(impactX, impactY, impactZ);
1950 TVectorD& helixParameters)
1953 double t_alpha = 1 / 0.3 / 1.5 * 100;
1954 double t_pT = momentum.Rho();
1955 double t_R = t_pT * t_alpha;
1956 helixParameters.Clear();
1957 helixParameters.ResizeTo(5);
1958 helixParameters[2] = t_alpha / t_R;
1959 helixParameters[1] = atan2(position.Y() - t_R * momentum.X() / t_pT * charge, position.X() + t_R * momentum.Y() / t_pT * charge);
1960 helixParameters[0] = (position.X() + t_R * momentum.Y() / t_pT * charge) / cos(helixParameters[1]) - t_R;
1961 double t_phi = atan2(-momentum.X() * charge, momentum.Y() * charge) - helixParameters[1];
1962 if (t_phi > M_PI) t_phi -= 2 * M_PI;
1963 if (t_phi < -M_PI) t_phi += 2 * M_PI;
1964 helixParameters[4] = momentum.Z() / t_pT * charge;
1965 helixParameters[3] = position.Z() + helixParameters[4] * t_R * t_phi;
1968 ROOT::Math::XYZVector& momentum)
1971 double t_alpha = 1 / 0.3 / 1.5 * 100;
1972 double t_R = t_alpha / helixParameters[2];
1973 double t_pT = t_R / t_alpha;
1974 double t_phi = -1 * charge * acos((-pow(cdcRadius, 2) + pow(t_R + helixParameters[0], 2) + pow(t_R,
1975 2)) / (2 * t_R * (t_R + helixParameters[0])));
1976 double t_X = (helixParameters[0] + t_R) * cos(helixParameters[1]) - t_R * cos(helixParameters[1] + t_phi);
1977 double t_Y = (helixParameters[0] + t_R) * sin(helixParameters[1]) - t_R * sin(helixParameters[1] + t_phi);
1978 double t_Z = helixParameters[3] - helixParameters[4] * t_R * t_phi;
1979 double t_Px = -t_pT * sin(helixParameters[1] + t_phi) * charge;
1980 double t_Py = t_pT * cos(helixParameters[1] + t_phi) * charge;
1981 double t_Pz = t_pT * helixParameters[4] * charge;
1982 position.SetXYZ(t_X, t_Y, t_Z);
1983 momentum.SetXYZ(t_Px, t_Py, t_Pz);
1990 for (
int i = 0; i < numberBits - 1; i++) {
1994 }
else if (mode == 0) {
1995 for (
int i = 0; i < numberBits; i++) {
2010 double range = maxValue - minValue;
2011 double convert = (
bitSize - 0.5) / range;
2022 double range = maxValue - minValue;
2023 double convert = (
bitSize - 0.5) / range;
2024 real = (integer / convert) + minValue;
2030 if (value > m_max) m_max = value;
2031 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 calVectorsAtR(const TVectorD &helixParameters, int charge, double radius, ROOT::Math::XYZVector &position, ROOT::Math::XYZVector &momentum)
Calculates position and momentum at a certain radius.
static void loadStereoXt(std::string const &filePrefix, int nFiles, std::vector< std::vector< double > > &stXts)
Load stereo Xt file.
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 void calHelixParameters(ROOT::Math::XYZVector position, ROOT::Math::XYZVector momentum, int charge, TVectorD &helixParameters)
HelixParameters: dR, phi0, keppa, dz, tanLambda Calculates the helix parameters of track.
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 int findSign(double *phi2)
2D fitter functions
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 void findImpactPosition(ROOT::Math::XYZVector *mcPosition, ROOT::Math::PxPyPzEVector *mcMomentum, int charge, ROOT::Math::XYVector &helixCenter, ROOT::Math::XYZVector &impactPosition)
MC calculation functions Calculates the impact position of track.
static double roundInt(double value)
Round double value.
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.