9#include <framework/gearbox/Gearbox.h>
10#include <framework/gearbox/GearDir.h>
11#include <framework/logging/Logger.h>
12#include <framework/utilities/FileSystem.h>
14#include <cdc/geometry/CDCGeometryPar.h>
15#include <cdc/geometry/CDCGeoControlPar.h>
16#include <cdc/simulation/CDCSimControlPar.h>
17#include <cdc/utilities/OpenFile.h>
22#include <boost/iostreams/filtering_stream.hpp>
24#include <Math/ChebyshevPol.h>
45 if ((*m_t0FromDB).isValid()) {
52 if ((*m_badWireFromDB).isValid()) {
59 if ((*m_propSpeedFromDB).isValid()) {
66 if ((*m_timeWalkFromDB).isValid()) {
73 if ((*m_xtRelFromDB).isValid()) {
80 if ((*m_sResolFromDB).isValid()) {
87 if ((*m_fFactorFromDB).isValid()) {
94 if ((*m_chMapFromDB).isValid()) {
101 if ((*m_displacementFromDB).isValid()) {
108 if ((*m_alignmentFromDB).isValid()) {
116 if ((*m_misalignmentFromDB).isValid()) {
125 if ((*m_eDepToADCConversionsFromDB).isValid()) {
138 B2WARNING(
"CDCGeometryPar: Strange that readFromDB is not called! Please make sure that CDC is included in Geometry.");
177 for (
unsigned i = 0; i < 4; ++i) {
179 for (
unsigned j = 0; j < 2; ++j)
182 for (
unsigned i = 0; i < c_maxNSenseLayers; ++i) {
194 for (
unsigned i = 0; i < c_maxNFieldLayers; ++i) {
200 for (
unsigned L = 0; L < c_maxNSenseLayers; ++L) {
201 for (
unsigned C = 0; C < c_maxNDriftCells; ++C) {
202 for (
unsigned i = 0; i < 3; ++i) {
210 for (
unsigned i = 0; i < 7; ++i) {
220 for (
unsigned L = 0; L < c_maxNSenseLayers; ++L) {
221 for (
unsigned i = 0; i < 2; ++i) {
222 for (
unsigned alpha = 0; alpha < c_maxNAlphaPoints; ++alpha) {
223 for (
unsigned theta = 0; theta < c_maxNThetaPoints; ++theta) {
224 for (
unsigned xtparam = 0; xtparam < c_nXTParams; ++xtparam) {
225 m_XT[L][i][alpha][theta][xtparam] = 0.;
228 for (
unsigned sigmaparam = 0; sigmaparam < c_nSigmaParams; ++sigmaparam) {
229 m_Sigma[L][i][alpha][theta][sigmaparam] = 0.;
236 for (
unsigned board = 0; board < c_nBoards; ++board) {
237 for (
unsigned i = 0; i < 2; ++i) {
240 for (
unsigned channel = 0; channel < 48; ++channel) {
245 for (
unsigned superLayer = 0; superLayer < c_nSuperLayers; ++superLayer) {
246 for (
unsigned layer = 0; layer < 8; ++layer) {
259 m_rWall[0] = geom.getInnerWall(2).getRmin();
260 m_zWall[0][0] = geom.getInnerWall(0).getZbwd();
261 m_zWall[0][1] = geom.getInnerWall(0).getZfwd();
263 m_rWall[1] = geom.getInnerWall(0).getRmax();
264 m_zWall[1][0] = geom.getInnerWall(0).getZbwd();
265 m_zWall[1][1] = geom.getInnerWall(0).getZbwd();
268 m_rWall[2] = geom.getOuterWall(0).getRmin();
269 m_zWall[2][0] = geom.getOuterWall(0).getZbwd();
270 m_zWall[2][1] = geom.getOuterWall(0).getZfwd();
272 m_rWall[3] = geom.getOuterWall(1).getRmax();
273 m_zWall[3][0] = geom.getOuterWall(0).getZbwd();
274 m_zWall[3][1] = geom.getOuterWall(0).getZfwd();
283 B2DEBUG(100,
"CDCGeometryPar: Define a mixture of gases and wires in the tracking volume.");
286 B2FATAL(
"CDCGeometryPar: Materialdefinition=2 is disabled for now.");
288 B2FATAL(
"CDCGeometryPar: Materialdefinition mode you specify is invalid.");
299 GearDir content =
GearDir(
"/Detector/DetectorComponent[@name=\"CDC\"]/Content/");
307 for (
const auto& sense : geom.getSenseLayers()) {
308 uint layerId = sense.getId();
313 m_nWires[layerId] = sense.getNWires();
315 m_offSet[layerId] = sense.getOffset();
328 B2FATAL(
"CDCGeometryPar: invalid wire z definition mode specified");
332 const int nWires =
m_nWires[layerId];
333 for (
int iCell = 0; iCell < nWires; ++iCell) {
340 for (
const auto& field : geom.getFieldLayers()) {
341 uint layerId = field.getId();
373 B2FATAL(
"HardwareClockSettings payloads are not valid.");
374 const double officialClockFreq4TDC = 2 *
m_clockSettings->getAcceleratorRF();
376 B2WARNING(
"ClockFreq4TDC changed from cdclocal " << scientific << setprecision(6) <<
m_clockFreq4TDC <<
" to official " <<
377 officialClockFreq4TDC <<
" (GHz) (difference larger than 0.01%)");
380 B2DEBUG(100,
"CDCGeometryPar: Clock freq. for TDC= " <<
m_clockFreq4TDC <<
" (GHz).");
382 B2DEBUG(100,
"CDCGeometryPar: TDC bin width= " <<
m_tdcBinWidth <<
" (ns).");
393 B2DEBUG(100,
"CDCGeometryPar: Load displacement params. (=1); not load (=0):" <<
m_displacement);
396 B2DEBUG(100,
"CDCGeometryPar: Read displacement from DB");
405 B2DEBUG(100,
"CDCGeometryPar: Load alignment params. (=1); not load (=0):" <<
409 B2DEBUG(100,
"CDCGeometryPar: Read alignment from DB");
418 B2DEBUG(100,
"CDCGeometryPar: Load misalignment params. (=1); not load (=0):" <<
422 B2DEBUG(100,
"CDCGeometryPar: Read misalignment from DB");
435 B2FATAL(
"ModifiedLeftRightFlag = true is disabled for now; need to update a G4-related code in framework...");
444 B2DEBUG(100,
"CDCGeometryPar: Read xt from DB");
451 B2DEBUG(100,
"CDCGeometryPar: Read sigma from DB");
458 B2DEBUG(100,
"CDCGeometryPar: Read fudge factors from DB");
465 B2DEBUG(100,
"CDCGeometryPar: Read prop-speed from DB");
472 B2DEBUG(100,
"CDCGeometryPar: Read t0 from DB");
479 B2DEBUG(100,
"CDCGeometryPar: Read badwire from DB");
483 B2FATAL(
"Text file input mode for bdwires is disabled now!");
487 B2DEBUG(100,
"CDCGeometryPar: Read ch-map from DB");
494 B2DEBUG(100,
"CDCGeometryPar: Read time-walk from DB");
499 B2DEBUG(100,
"CDCGeometryPar: Time-walk param. mode= " <<
m_twParamMode);
502 B2DEBUG(29,
"CDCGeometryPar: Read EDepToADC from DB");
503 if ((*m_eDepToADCConversionsFromDB).isValid()) {
575 std::string fileName0;
580 }
else if (set == c_Misaligned) {
582 }
else if (set == c_Aligned) {
588 }
else if (set == c_Misaligned) {
590 }
else if (set == c_Aligned) {
597 boost::iostreams::filtering_istream ifs;
602 double back[np], fwrd[np], tension;
607 for (
int i = 0; i < np; ++i) {
610 for (
int i = 0; i < np; ++i) {
616 if (ifs.eof())
break;
624 for (
int i = 0; i < np; ++i) {
628 }
else if (set == c_Misaligned) {
631 }
else if (set == c_Aligned) {
643 }
else if (set == c_Misaligned) {
648 }
else if (set == c_Aligned) {
667 if (nRead !=
m_nSenseWires) B2FATAL(
"CDCGeometryPar::readWirePositionParams: #lines read-in (=" << nRead <<
668 ") is inconsistent with total #sense wires (=" <<
m_nSenseWires <<
") !");
671 boost::iostreams::close(ifs);
679 for (
unsigned iL = 0; iL < c_maxNSenseLayers; ++iL) {
686 auto layerID =
WireID(iL, 511);
697 for (
unsigned iC = 0; iC <
m_nWires[iL]; ++iC) {
709 m_BWirPosAlign[iL][iC][0] = d_layerXbwd + cos(d_layerPhiBwd) * wireXbwd + sin(d_layerPhiBwd) * wireYbwd;
710 m_BWirPosAlign[iL][iC][1] = d_layerYbwd - sin(d_layerPhiBwd) * wireXbwd + cos(d_layerPhiBwd) * wireYbwd;
713 m_FWirPosAlign[iL][iC][0] = d_layerXfwd + cos(d_layerPhiFwd) * wireXfwd + sin(d_layerPhiFwd) * wireYfwd;
714 m_FWirPosAlign[iL][iC][1] = d_layerYfwd - sin(d_layerPhiFwd) * wireXfwd + cos(d_layerPhiFwd) * wireYfwd;
720 double back[np], fwrd[np];
722 for (
unsigned iL = 0; iL < c_maxNSenseLayers; ++iL) {
728 for (
unsigned iC = 0; iC <
m_nWires[iL]; ++iC) {
739 for (
int i = 0; i < np; ++i) {
763 double back[np], fwrd[np];
765 for (
unsigned iL = 0; iL < c_maxNSenseLayers; ++iL) {
771 for (
unsigned iC = 0; iC <
m_nWires[iL]; ++iC) {
782 for (
int i = 0; i < np; ++i) {
817 fileName0 = gbxParams.
getString(
"xt4ReconFileName");
820 boost::iostreams::filtering_istream ifs;
844 unsigned short nAlphaBins = 0;
845 if (ifs >> nAlphaBins) {
846 if (nAlphaBins == 0 || nAlphaBins > c_maxNAlphaPoints) B2FATAL(
"Fail to read alpha bins !");
848 B2FATAL(
"Fail to read alpha bins !");
851 double alpha0, alpha1, alpha2;
852 for (
unsigned short i = 0; i < nAlphaBins; ++i) {
853 ifs >> alpha0 >> alpha1 >> alpha2;
858 unsigned short nThetaBins = 0;
859 if (ifs >> nThetaBins) {
860 if (nThetaBins == 0 || nThetaBins > c_maxNThetaPoints) B2FATAL(
"CDCGeometryPar: fail to read theta bins !");
862 B2FATAL(
"CDCGeometryPar: fail to read theta bins !");
865 double theta0, theta1, theta2;
867 for (
unsigned short i = 0; i < nThetaBins; ++i) {
868 ifs >> theta0 >> theta1 >> theta2;
873 unsigned short iCL, iLR;
874 const unsigned short npx = c_nXTParams - 1;
876 double theta, alpha, dummy1;
879 if (m_xtParamMode < 0 || m_xtParamMode > 3) B2FATAL(
"CDCGeometryPar: invalid xt-parameterization mode read !");
881 if (np <= 0 || np > npx) B2FATAL(
"CDCGeometryPar: no. of xt-params. outside limits !");
883 const double epsi = 0.1;
891 ifs >> theta >> alpha >> dummy1 >> iLR;
892 for (
int i = 0; i < np; ++i) {
897 for (
unsigned short i = 0; i < nThetaBins; ++i) {
903 if (itheta < 0) B2FATAL(
"CDCGeometryPar: thetas in xt.dat are inconsistent !");
906 for (
unsigned short i = 0; i < nAlphaBins; ++i) {
912 if (ialpha < 0) B2FATAL(
"CDCGeometryPar: alphas in xt.dat are inconsistent !");
914 for (
int i = 0; i < np; ++i) {
915 m_XT[iCL][iLR][ialpha][itheta][i] = xtc[i];
918 double boundT = xtc[6];
920 m_XT[iCL][iLR][ialpha][itheta][np] = ROOT::Math::Chebyshev5(boundT, xtc[0], xtc[1], xtc[2], xtc[3], xtc[4], xtc[5]);
922 m_XT[iCL][iLR][ialpha][itheta][np] =
933 boost::iostreams::close(ifs);
936 const double degrad = M_PI / 180.;
937 for (
unsigned i = 0; i < nAlphaBins; ++i) {
940 for (
unsigned i = 0; i < nThetaBins; ++i) {
963 fileName0 = gbxParams.
getString(
"sigma4ReconFileName");
971 unsigned short nAlphaBins = 0;
972 if (ifs >> nAlphaBins) {
973 if (nAlphaBins == 0 || nAlphaBins > c_maxNAlphaPoints) B2FATAL(
"Fail to read alpha bins !");
975 B2FATAL(
"Fail to read alpha bins !");
979 double alpha0, alpha1, alpha2;
980 for (
unsigned short i = 0; i < nAlphaBins; ++i) {
981 ifs >> alpha0 >> alpha1 >> alpha2;
987 unsigned short nThetaBins = 0;
988 if (ifs >> nThetaBins) {
989 if (nThetaBins == 0 || nThetaBins > c_maxNThetaPoints) B2FATAL(
"CDCGeometryPar: fail to read theta bins !");
991 B2FATAL(
"CDCGeometryPar: fail to read theta bins !");
995 double theta0, theta1, theta2;
997 for (
unsigned short i = 0; i < nThetaBins; ++i) {
998 ifs >> theta0 >> theta1 >> theta2;
1003 unsigned short np = 0;
1004 unsigned short iCL, iLR;
1005 double sigma[c_nSigmaParams];
1006 double theta, alpha;
1010 if (m_sigmaParamMode < 0 || m_sigmaParamMode > 4) B2FATAL(
"CDCGeometryPar: invalid sigma-parameterization mode read !");
1012 if (np > c_nSigmaParams) B2FATAL(
"CDCGeometryPar: no. of sigma-params. outside limits !");
1016 const double epsi = 0.1;
1018 while (ifs >> iCL) {
1024 ifs >> theta >> alpha >> iLR;
1026 for (
int i = 0; i < np; ++i) {
1031 for (
unsigned short i = 0; i < nThetaBins; ++i) {
1037 if (itheta < 0) B2FATAL(
"CDCGeometryPar: thetas in sigma.dat are inconsistent !");
1040 for (
unsigned short i = 0; i < nAlphaBins; ++i) {
1046 if (ialpha < 0) B2FATAL(
"CDCGeometryPar: alphas in sigma.dat are inconsistent !");
1048 for (
int i = 0; i < np; ++i) {
1049 m_Sigma[iCL][iLR][ialpha][itheta][i] = sigma[i];
1056 const double degrad = M_PI / 180.;
1057 for (
unsigned i = 0; i < nAlphaBins; ++i) {
1060 for (
unsigned i = 0; i < nThetaBins; ++i) {
1073 fileName0 = gbxParams.
getString(
"fudgeFactorFileName");
1075 B2WARNING(
"readFFactor is not ready! " << fileName0);
1085 fileName0 = gbxParams.
getString(
"propSpeed4ReconFileName");
1098 if (ifs.eof())
break;
1104 if (
m_debug) B2DEBUG(150, iL <<
" " << speed);
1107 if (nRead != c_maxNSenseLayers) B2FATAL(
"CDCGeometryPar::readPropSpeed: #lines read-in (=" << nRead <<
1108 ") is inconsistent with total #layers (=" << c_maxNSenseLayers <<
") !");
1153 fileName0 = gbxParams.
getString(
"t04ReconFileName");
1165 ifs >> iL >> iC >> t0;
1171 if (ifs.eof())
break;
1178 B2DEBUG(150, iL <<
" " << iC <<
" " << t0);
1182 if (nRead !=
m_nSenseWires) B2FATAL(
"CDCGeometryPar::readT0: #lines read-in (=" << nRead <<
1183 ") is inconsistent with total #sense wires (=" <<
m_nSenseWires <<
") !");
1234 fileName0 = gbxParams.
getString(
"tw4ReconFileName");
1241 unsigned short nPars(0);
1244 B2FATAL(
"CDCGeometryPar::readTW: invalid mode specified!");
1247 B2FATAL(
"CDCGeometryPar::readTW: invalid #params specified!");
1250 unsigned iBoard = 0;
1253 while (ifs >> iBoard) {
1254 for (
unsigned short i = 0; i < nPars; ++i) {
1260 if (nRead != c_nBoards) B2FATAL(
"CDCGeometryPar::readTW: #lines read-in (=" << nRead <<
") is inconsistent with #boards (=" <<
1278 unsigned short iSL, iL, iW, iB, iC;
1283 ifs >> iSL >> iL >> iW >> iB >> iC;
1284 if (ifs.eof())
break;
1289 m_wireToBoard.insert(pair<WireID, unsigned short>(wID, iB));
1292 if (nRead !=
m_nSenseWires) B2FATAL(
"CDCGeometryPar::readChMap: #lines read-in (=" << nRead <<
1293 ") is inconsistent with #sense-wires (="
1306 fileName0 = gbxParams.
getString(
"fudgeFactorFileName");
1311 std::string fileName1 =
"/data/cdc/" + fileName0;
1314 if (fileName ==
"") {
1318 if (fileName ==
"") {
1319 B2FATAL(
"CDC::openFile: " << fileName0 <<
" not exist!");
1322 B2DEBUG(29,
"CDC::openFile: open " << fileName);
1323 ifs.open(fileName.c_str());
1324 if (!ifs) B2FATAL(
"CDC::openFile: cannot open " << fileName <<
" !");
1327 unsigned short paramMode(0), nParams(0);
1328 ifs >> paramMode >> nParams;
1329 if (paramMode > 1) B2FATAL(
"Param mode > 1!");
1330 if (nParams > 7) B2FATAL(
"No. of params. > 7!");
1331 unsigned short groupId(0);
1333 B2DEBUG(29, paramMode <<
" " << nParams <<
" " << groupId);
1334 if (groupId > 0) B2FATAL(
"GgroupId > 0!");
1337 unsigned short cLMin[c_nSuperLayers], cLMax[c_nSuperLayers];
1340 for (
unsigned int sl = 1; sl < c_nSuperLayers; ++sl) {
1341 cLMin[sl] = cLMax[0] + 6 * sl - 5;
1342 cLMax[sl] = cLMax[0] + 6 * sl;
1345 unsigned short id = 0;
1347 unsigned short nRead = 0;
1349 for (
unsigned short i = 0; i < nParams; ++i) {
1351 for (
unsigned short cL = cLMin[
id]; cL <= cLMax[id]; ++cL) {
1352 for (
unsigned short cell = 0; cell <
m_nWires[cL]; ++cell) {
1359 if (nRead > c_nSuperLayers) B2FATAL(
"No. of read in lines > " << c_nSuperLayers <<
" !");
1369 for (
unsigned short iCL = 0; iCL < c_maxNSenseLayers; ++iCL) {
1370 for (
unsigned short iW = 0; iW < c_maxNDriftCells; ++iW) {
1375 for (
auto const& ent : (*m_t0FromDB)->getT0s()) {
1378 const unsigned short iW = wid.
getIWire();
1389 double oldMeanT0 = 0;
1390 unsigned short it1 = 0;
1391 for (
unsigned short it = 0; it < maxIt; ++it) {
1393 double effiSum = 0.;
1396 for (
unsigned short iCL = 0; iCL < c_maxNSenseLayers; ++iCL) {
1397 for (
unsigned short iW = 0; iW <
m_nWires[iCL]; ++iW) {
1398 if (
m_t0[iCL][iW] < minT0 ||
m_t0[iCL][iW] > maxT0)
continue;
1413 B2DEBUG(29, it <<
" " << effiSum <<
" " <<
m_meanT0 <<
" " << stdvT0);
1414 if (fabs(
m_meanT0 - oldMeanT0) < epsi)
break;
1419 B2FATAL(
"Wire efficiency sum <= 0!");
1422 if (it1 == maxIt - 1) B2WARNING(
"Max. iterations(=" << maxIt <<
") needed to calculate the mean t0. Strange.");
1437 for (
unsigned short iCL = 0; iCL < (*m_propSpeedFromDB)->getEntries(); ++iCL) {
1449 for (
unsigned short iBd = 0; iBd < (*m_timeWalkFromDB)->getEntries(); ++iBd) {
1450 int np = ((*m_timeWalkFromDB)->getTimeWalkParams(iBd)).size();
1451 for (
int i = 0; i < np; ++i) {
1452 m_timeWalkCoef[iBd][i] = ((*m_timeWalkFromDB)->getTimeWalkParams(iBd))[i];
1478 for (
unsigned short iCL = 0; iCL < c_maxNSenseLayers; ++iCL) {
1485 for (
unsigned short iLR = 0; iLR < 2; ++iLR) {
1488 const std::vector<float> params = (*m_xtRelFromDB)->getXtParams(iCL, iLR, iA, iT);
1489 unsigned short np = params.size();
1491 for (
unsigned short i = 0; i < np; ++i) {
1492 m_XT[iCL][iLR][iA][iT][i] = params[i];
1495 double boundT =
m_XT[iCL][iLR][iA][iT][6];
1497 m_XT[iCL][iLR][iA][iT][np] = ROOT::Math::Chebyshev5(boundT,
m_XT[iCL][iLR][iA][iT][0],
m_XT[iCL][iLR][iA][iT][1],
1498 m_XT[iCL][iLR][iA][iT][2],
m_XT[iCL][iLR][iA][iT][3],
m_XT[iCL][iLR][iA][iT][4],
m_XT[iCL][iLR][iA][iT][5]);
1500 m_XT[iCL][iLR][iA][iT][np] =
1501 m_XT[iCL][iLR][iA][iT][0] + boundT
1502 * (
m_XT[iCL][iLR][iA][iT][1] + boundT
1503 * (
m_XT[iCL][iLR][iA][iT][2] + boundT
1504 * (
m_XT[iCL][iLR][iA][iT][3] + boundT
1505 * (
m_XT[iCL][iLR][iA][iT][4] + boundT
1506 * (
m_XT[iCL][iLR][iA][iT][5])))));
1541 for (
unsigned short iCL = 0; iCL < c_maxNSenseLayers; ++iCL) {
1542 for (
unsigned short iLR = 0; iLR < 2; ++iLR) {
1545 const std::vector<float> params = (*m_sResolFromDB)->getSigmaParams(iCL, iLR, iA, iT);
1546 unsigned short np = params.size();
1548 for (
unsigned short i = 0; i < np; ++i) {
1562 unsigned short groupId = (*m_fFactorFromDB)->getGroupID();
1563 unsigned short nEnt = (*m_fFactorFromDB)->getEntries();
1564 B2DEBUG(29,
"setFFactor called: groupId,nEnt= " << groupId <<
" " << nEnt);
1568 B2FATAL(
"CDCGeometryPar:: Invalid group-id " << groupId <<
" specified!");
1571 for (
unsigned short id = 0;
id < nEnt; ++id) {
1572 unsigned short np = ((*m_fFactorFromDB)->getFactors(
id)).size();
1573 if (np != 3) B2FATAL(
"CDCGeometryPar:: No. of fudge factors != 3!");
1574 for (
unsigned short i = 0; i < np; ++i) {
1591 const unsigned short isl = cm.getISuperLayer();
1593 const uint il = cm.getILayer();
1594 const int iw = cm.getIWire();
1595 const int iBd = cm.getBoardID();
1596 const WireID wID(isl, il, iw);
1597 m_wireToBoard.insert(pair<WireID, unsigned short>(wID, iBd));
1598 const int iCh = cm.getBoardChannel();
1607 unsigned short groupId = (*m_eDepToADCConversionsFromDB)->getGroupID();
1608 unsigned short nEnt = (*m_eDepToADCConversionsFromDB)->getEntries();
1610 if (nEnt > c_nSuperLayers) B2FATAL(
"CDCGeometryPar:: group-id " << groupId <<
" and #entries " << nEnt <<
" are inconsistent!");
1611 }
else if (groupId == 1) {
1612 if (nEnt > c_maxNSenseLayers) B2FATAL(
"CDCGeometryPar:: group-id " << groupId <<
" and #entries " << nEnt <<
" are inconsistent!");
1614 B2FATAL(
"CDCGeometryPar:: Invalid group-id " << groupId <<
" specified !");
1617 unsigned short cLMin[c_nSuperLayers], cLMax[c_nSuperLayers];
1620 for (
unsigned int sl = 1; sl < c_nSuperLayers; ++sl) {
1621 cLMin[sl] = cLMax[0] + 6 * sl - 5;
1622 cLMax[sl] = cLMax[0] + 6 * sl;
1625 for (
unsigned short id = 0;
id < nEnt; ++id) {
1626 unsigned short np = ((*m_eDepToADCConversionsFromDB)->getParams(
id)).size();
1627 if (np > 7) B2FATAL(
"CDCGeometryPar:: No. of edep-to-ADC conversion params. > 7");
1629 for (
unsigned short cL = cLMin[
id]; cL <= cLMax[id]; ++cL) {
1630 for (
unsigned short cell = 0; cell <
m_nWires[cL]; ++cell) {
1631 for (
unsigned short i = 0; i < np; ++i) {
1636 }
else if (groupId == 1) {
1637 for (
unsigned short cell = 0; cell <
m_nWires[id]; ++cell) {
1638 for (
unsigned short i = 0; i < np; ++i) {
1642 }
else if (groupId == 2) {
1644 B2FATAL(
"CDCGeometryPar::setEDepToADCConversions(): groupId=2 not ready!");
1663 const double cth = fabs(costh) + dlt;
1664 const double iGen = edep / dx;
1665 const double tmp = cth - gam * iGen;
1666 const double disc = tmp * tmp + 4.*alf * cth * iGen;
1670 iMea = cth * iGen / tmp;
1671 }
else if (disc >= 0.) {
1672 iMea = (-tmp +
sqrt(disc)) / (2.*alf);
1680 double convF = mainF;
1682 convF = mainF * std::min(iMea / iGen, 1.);
1691 convF *= 1. + a * (costh - b);
1711 if (set == c_Misaligned) {
1715 }
else if (set == c_Base) {
1737 if (set == c_Misaligned) {
1740 }
else if (set == c_Base) {
1759 if (set == c_Misaligned) {
1763 }
else if (set == c_Base) {
1785 if (set == c_Misaligned) {
1788 }
else if (set == c_Base) {
1799 if (set == c_Misaligned) {
1801 }
else if (set == c_Aligned) {
1809 static double IRWL[c_maxNSenseLayers] = {0};
1821 static double ORWL[c_maxNSenseLayers] = {0};
1837 const unsigned nWires =
m_nWires[layerId];
1841 const double phiSize = 2 * M_PI / double(nWires);
1858 for (
unsigned i = 0; i < 1; ++i) {
1859 const double phiF = phiSize * (double(i) +
offset)
1866 const double beta = (position.
Z() - b.Z()) / u.Z();
1868 double dPhi = std::atan2(position.
Y(), position.
X())
1869 - std::atan2(p.Y(), p.X())
1871 while (dPhi < 0) dPhi += (2. * M_PI);
1872 j = int(dPhi / phiSize);
1873 while (j >= nWires) j -= nWires;
1882 std::ofstream ofs(of.c_str(), std::ios::out);
1884 B2ERROR(
"CDCGeometryPar::read !!! can not open file : "
1887 ofs <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
1889 <<
"<Subdetector type=\"CDC\">"
1891 <<
" <Name>CDC BelleII </Name>"
1893 <<
" <Description>CDC geometry parameters</Description>"
1895 <<
" <Version>0</Version>"
1897 <<
" <GeoCreator>CDCBelleII</GeoCreator>"
1901 <<
" <Rotation desc=\"Rotation of the whole cdc detector (should be the same as beampipe)\" unit=\"mrad\">0.0</Rotation>"
1903 <<
" <OffsetZ desc=\"The offset of the whole cdc in z with respect to the IP (should be the same as beampipe)\" unit=\"mm\">0.0</OffsetZ>"
1905 <<
" <Material>CDCGas</Material>"
1909 ofs <<
" <SLayers>" << endl;
1912 ofs <<
" <SLayer id=\"" << i <<
"\">" << endl;
1913 ofs <<
" <Radius desc=\"Radius of wires in this layer\" unit=\"mm\">" <<
senseWireR(i) <<
"</Radius>" << endl;
1914 ofs <<
" <BackwardZ desc=\"z position of this wire layer at backward endplate\" unit=\"mm\">" <<
senseWireBZ(
1915 i) <<
"</BackwardZ>" << endl;
1916 ofs <<
" <ForwardZ desc=\"z position of this wire layer at forward endplate\" unit=\"mm\">" <<
senseWireFZ(
1917 i) <<
"</ForwardZ>" << endl;
1920 ofs <<
" <NHoles desc=\"the number of holes in this layer, 2*(cell number)\">" <<
nWiresInLayer(
1921 i) * 2 <<
"</NHoles>" << endl;
1922 ofs <<
" <NShift desc=\"the shifted hole number of each wire in this layer\">" <<
nShifts(i) <<
"</NShift>" << endl;
1923 ofs <<
" <Offset desc=\"wire offset in phi direction at endplate\">" <<
m_offSet[i] <<
"</Offset>" << endl;
1924 ofs <<
" </SLayer>" << endl;
1927 ofs <<
" </SLayers>" << endl;
1928 ofs <<
" <FLayers>" << endl;
1931 ofs <<
" <FLayer id=\"" << i <<
"\">" << endl;
1932 ofs <<
" <Radius desc=\"Radius of field wires in this layer\" unit=\"mm\">" <<
fieldWireR(i) <<
"</Radius>" << endl;
1933 ofs <<
" <BackwardZ desc=\"z position of this field wire layer at backward endplate\" unit=\"mm\">" <<
fieldWireBZ(
1934 i) <<
"</BackwardZ>" << endl;
1935 ofs <<
" <ForwardZ desc=\"z position of this field wire layer at forward endplate\" unit=\"mm\">" <<
fieldWireFZ(
1936 i) <<
"</ForwardZ>" << endl;
1937 ofs <<
" </FLayer>" << endl;
1940 ofs <<
" </FLayers>" << endl;
1942 ofs <<
" <InnerWall name=\"InnerWall\">" << endl;
1943 ofs <<
" <InnerR desc=\"Inner radius\" unit=\"mm\">" <<
innerRadiusInnerWall() <<
"</InnerR>" << endl;
1944 ofs <<
" <OuterR desc=\"Outer radius\" unit=\"mm\">" <<
outerRadiusInnerWall() <<
"</OuterR>" << endl;
1945 ofs <<
" <BackwardZ desc=\"z position at backward endplate\" unit=\"mm\">" <<
m_zWall[0][0] <<
"</BackwardZ>" << endl;
1946 ofs <<
" <ForwardZ desc=\"z position at forward endplate\" unit=\"mm\">" <<
m_zWall[0][1] <<
"</ForwardZ>" << endl;
1947 ofs <<
" </InnerWall>" << endl;
1949 ofs <<
" <OuterWall name=\"OuterWall\">" << endl;
1950 ofs <<
" <InnerR desc=\"Inner radius\" unit=\"mm\">" <<
innerRadiusOuterWall() <<
"</InnerR>" << endl;
1951 ofs <<
" <OuterR desc=\"Outer radius\" unit=\"mm\">" <<
outerRadiusOuterWall() <<
"</OuterR>" << endl;
1952 ofs <<
" <BackwardZ desc=\"z position at backward endplate\" unit=\"mm\">" <<
m_zWall[2][0] <<
"</BackwardZ>" << endl;
1953 ofs <<
" <ForwardZ desc=\"z position at forward endplate\" unit=\"mm\">" <<
m_zWall[2][1] <<
"</ForwardZ>" << endl;
1954 ofs <<
" </OuterWall>" << endl;
1956 ofs <<
" </Content>" << endl
1957 <<
"</Subdetector>" << endl;
1961 double& Yb_sag,
double& Yf_sag)
const
1992 if (set == c_Aligned) {
2006 }
else if (set == c_Misaligned) {
2020 }
else if (set == c_Base) {
2035 B2FATAL(
"CDCGeometryPar::getWireSagEffect: called with an invalid set: " <<
" " << set);
2038 const double dx = Xf - Xb;
2039 const double dy = Yf - Yb;
2040 const double dz = Zf - Zb;
2042 const double Zfp =
sqrt(dz * dz + dx * dx);
2043 const double Zp = (Z - Zb) * Zfp / dz;
2045 const double Y_sag = (Coef * (Zp - Zfp) + dy / Zfp) * Zp + Yb;
2046 const double dydz = (Coef * (2.*Zp - Zfp) * Zfp + dy) / dz;
2048 Yb_sag = Y_sag + dydz * (Zb - Z);
2049 Yf_sag = Y_sag + dydz * (Zf - Z);
2055 const unsigned L = layerID;
2056 const unsigned C = cellID;
2060 const double phiSize = 2 * M_PI / double(
m_nWires[L]);
2062 const double phiF = phiSize * (double(C) +
offset)
2075 for (
int i = 0; i < 3; ++i) {
2093 const unsigned L = layerID;
2094 const unsigned C = cellID;
2096 static bool first =
true;
2097 static ofstream ofs;
2100 ofs.open(
"alignment.dat");
2103 ofs << L <<
" " << C;
2105 ofs << setiosflags(ios::showpoint | ios::uppercase);
2107 for (
int i = 0; i < 3; ++i) ofs <<
" " << setw(15) << setprecision(8) <<
m_BWirPos[L][C][i];
2109 for (
int i = 0; i < 3; ++i) ofs <<
" " << setw(15) << setprecision(8) <<
m_FWirPos[L][C][i];
2110 ofs << setiosflags(ios::fixed);
2117 const double theta)
const
2119 if (iCLayer < m_firstLayerOffset || iCLayer >= c_maxNSenseLayers) {
2127 double delta = time - minTime;
2133 B2FATAL(
"linearInterpolationOfXT = false is not allowed now !");
2136 unsigned short ial[2] = {0};
2137 unsigned short ilr[2] = {lro, lro};
2140 unsigned short ith[2] = {0};
2143 unsigned short jal(0), jlr(0), jth(0);
2147 double timep = delta < 0. ? minTime - delta : time;
2150 for (
unsigned k = 0; k < 4; ++k) {
2155 w = (1. - wal) * (1. - wth);
2156 }
else if (k == 1) {
2160 w = (1. - wal) * wth;
2161 }
else if (k == 2) {
2165 w = wal * (1. - wth);
2166 }
else if (k == 3) {
2173 double boundary =
m_XT[iCLayer][jlr][jal][jth][6];
2175 if (timep < boundary) {
2177 const double& c1 =
m_XT[iCLayer][jlr][jal][jth][1];
2178 const double& c2 =
m_XT[iCLayer][jlr][jal][jth][2];
2179 const double& c3 =
m_XT[iCLayer][jlr][jal][jth][3];
2180 const double& c4 =
m_XT[iCLayer][jlr][jal][jth][4];
2181 const double& c5 =
m_XT[iCLayer][jlr][jal][jth][5];
2182 dDdt += w * ROOT::Math::Chebyshev4(timep, c1 + 3.*c3 + 5.*c5, 4.*c2 + 8.*c4, 6.*c3 + 10.*c5, 8.*c4, 10.*c5);
2184 dDdt += w * (
m_XT[iCLayer][jlr][jal][jth][1] + timep
2185 * (2.*
m_XT[iCLayer][jlr][jal][jth][2] + timep
2186 * (3.*
m_XT[iCLayer][jlr][jal][jth][3] + timep
2187 * (4.*
m_XT[iCLayer][jlr][jal][jth][4] + timep
2188 * (5.*
m_XT[iCLayer][jlr][jal][jth][5])))));
2191 dDdt += w *
m_XT[iCLayer][jlr][jal][jth][7];
2205 const double theta)
const
2207 if (iCLayer < m_firstLayerOffset || iCLayer >= c_maxNSenseLayers) {
2219 B2FATAL(
"linearInterpolationOfXT = false is not allowed now !");
2222 unsigned short ial[2] = {0};
2223 unsigned short ilr[2] = {lro, lro};
2226 unsigned short ith[2] = {0};
2229 unsigned short jal(0), jlr(0), jth(0);
2233 double timep = time;
2237 for (
unsigned k = 0; k < 4; ++k) {
2242 w = (1. - wal) * (1. - wth);
2243 }
else if (k == 1) {
2247 w = (1. - wal) * wth;
2248 }
else if (k == 2) {
2252 w = wal * (1. - wth);
2253 }
else if (k == 3) {
2260 double boundary =
m_XT[iCLayer][jlr][jal][jth][6];
2262 if (timep < boundary) {
2264 dist += w * ROOT::Math::Chebyshev5(timep,
m_XT[iCLayer][jlr][jal][jth][0],
m_XT[iCLayer][jlr][jal][jth][1],
2265 m_XT[iCLayer][jlr][jal][jth][2],
m_XT[iCLayer][jlr][jal][jth][3],
m_XT[iCLayer][jlr][jal][jth][4],
m_XT[iCLayer][jlr][jal][jth][5]);
2267 dist += w * (
m_XT[iCLayer][jlr][jal][jth][0] + timep
2268 * (
m_XT[iCLayer][jlr][jal][jth][1] + timep
2269 * (
m_XT[iCLayer][jlr][jal][jth][2] + timep
2270 * (
m_XT[iCLayer][jlr][jal][jth][3] + timep
2271 * (
m_XT[iCLayer][jlr][jal][jth][4] + timep
2272 * (
m_XT[iCLayer][jlr][jal][jth][5]))))));
2275 dist += w * (
m_XT[iCLayer][jlr][jal][jth][7] * (timep - boundary) +
m_XT[iCLayer][jlr][jal][jth][8]);
2288 const bool calculateMinTime,
2289 const double inputMinTime)
const
2291 if (iCLayer < m_firstLayerOffset || iCLayer >= c_maxNSenseLayers) {
2298 double minTime = calculateMinTime ?
getMinDriftTime(iCLayer, lr, alpha, theta) : inputMinTime;
2299 double delta = time - minTime;
2307 B2FATAL(
"linearInterpolationOfXT = false is not allowed now !");
2310 unsigned short ial[2] = {0};
2311 unsigned short ilr[2] = {lro, lro};
2314 unsigned short ith[2] = {0};
2317 unsigned short jal(0), jlr(0), jth(0);
2321 double timep = delta < 0. ? minTime - delta : time;
2326 for (
unsigned k = 0; k < 4; ++k) {
2331 w = (1. - wal) * (1. - wth);
2332 }
else if (k == 1) {
2336 w = (1. - wal) * wth;
2337 }
else if (k == 2) {
2341 w = wal * (1. - wth);
2342 }
else if (k == 3) {
2362 double boundary =
m_XT[iCLayer][jlr][jal][jth][6];
2364 if (timep < boundary) {
2366 dist += w * ROOT::Math::Chebyshev5(timep,
m_XT[iCLayer][jlr][jal][jth][0],
m_XT[iCLayer][jlr][jal][jth][1],
2367 m_XT[iCLayer][jlr][jal][jth][2],
m_XT[iCLayer][jlr][jal][jth][3],
m_XT[iCLayer][jlr][jal][jth][4],
m_XT[iCLayer][jlr][jal][jth][5]);
2369 dist += w * (
m_XT[iCLayer][jlr][jal][jth][0] + timep
2370 * (
m_XT[iCLayer][jlr][jal][jth][1] + timep
2371 * (
m_XT[iCLayer][jlr][jal][jth][2] + timep
2372 * (
m_XT[iCLayer][jlr][jal][jth][3] + timep
2373 * (
m_XT[iCLayer][jlr][jal][jth][4] + timep
2374 * (
m_XT[iCLayer][jlr][jal][jth][5]))))));
2377 dist += w * (
m_XT[iCLayer][jlr][jal][jth][7] * (timep - boundary) +
m_XT[iCLayer][jlr][jal][jth][8]);
2384 if (delta < 0.) dist *= -1.;
2390 const double theta)
const
2392 if (iCLayer < m_firstLayerOffset || iCLayer >= c_maxNSenseLayers) {
2396 double minTime = 0.;
2402 B2FATAL(
"linearInterpolationOfXT = false is not allowed now !");
2405 unsigned short ial[2] = {0};
2406 unsigned short ilr[2] = {lro, lro};
2409 unsigned short ith[2] = {0};
2412 unsigned short jal(0), jlr(0), jth(0);
2415 double c[6] = {0.}, a[6] = {0.};
2416 for (
unsigned k = 0; k < 4; ++k) {
2421 w = (1. - wal) * (1. - wth);
2422 }
else if (k == 1) {
2426 w = (1. - wal) * wth;
2427 }
else if (k == 2) {
2431 w = wal * (1. - wth);
2432 }
else if (k == 3) {
2439 for (
int i = 0; i < 5; ++i) {
2440 c[i] += w *
m_XT[iCLayer][jlr][jal][jth][i];
2445 a[0] = c[0] - c[2] + c[4];
2446 a[1] = c[1] - 3.*c[3] + 5.*c[5];
2447 a[2] = 2.*c[2] - 8.*c[4];
2448 a[3] = 4.*c[3] - 20.*c[5];
2452 for (
int i = 0; i < 5; ++i) a[i] = c[i];
2459 const double det = a[1] * a[1] - 4.*a[2] * a[0];
2462 minTime = (-a[1] +
sqrt(det)) / (2.*a[2]);
2466 minTime = -a[1] / (2.*a[2]);
2469 }
else if (a[1] != 0.) {
2470 minTime = -a[0] / a[1];
2472 B2WARNING(
"CDCGeometryPar::getMinDriftTime: minDriftTime not determined; assume zero.\n" <<
"layer(#0-55),lr,alpha(rad),theta= " <<
2473 iCLayer <<
" " << lr <<
" " << alpha <<
" " << theta);
2482 const double epsi4x = 5.e-6;
2484 const unsigned short maxIter = 8;
2485 const double maxDt = 20.;
2486 unsigned short nIter = 0;
2487 double minXsq = 1.e10;
2488 double minMinTime = minTime;
2491 for (nIter = 0; nIter <= maxIter; ++nIter) {
2494 double x = a[0] + t * (a[1] + t * (a[2] + t * (a[3] + t * (a[4] + t * a[5]))));
2500 double xp = a[1] + t * (2 * a[2] + t * (3 * a[3] + t * (4 * a[4] + t * 5 * a[5])));
2501 double xpp = 2 * a[2] + t * (6 * a[3] + t * (12 * a[4] + t * 20 * a[5]));
2502 double den = xp * xp + x * xpp;
2509 edm = fabs(x * xp) /
sqrt(den);
2510 if (edm < epsi4x)
break;
2517 dt = std::min(dt, maxDt);
2519 dt = std::max(dt, -maxDt);
2522 B2WARNING(
"CDCGeometryPar::getMinDriftTime: den = 0\n" <<
"layer(#0-55),lr,alpha(rad),theta= " <<
2525 " " << alpha <<
" " << theta);
2531 if (nIter == (maxIter + 1)) minTime = minMinTime;
2584 const double theta)
const
2586 if (iCLayer < m_firstLayerOffset || iCLayer >= c_maxNSenseLayers) {
2592 const double eps = 2.5e-1;
2593 const double maxTrials = 100;
2601 double maxTime = 2000.;
2607 double t0 = minTime;
2609 const bool calMinTime =
false;
2614 double t1 = maxTime;
2616 while (((t1 - t0) > eps) && (i < maxTrials)) {
2617 time = 0.5 * (t0 + t1);
2618 double d1 =
getDriftLength(time, iCLayer, lr, alpha, theta, calMinTime, minTime) - dist;
2628 if (i >= maxTrials - 1 || time > maxTime) {
2629 B2WARNING(
"CDCGeometryPar::getDriftTime " << dist <<
" " << iCLayer <<
" " << alpha <<
" " << lr <<
" " << t0 <<
" " << t1 <<
" " <<
2640 const double theta)
const
2642 if (iCLayer < m_firstLayerOffset || iCLayer >= c_maxNSenseLayers) {
2649 const double driftL = fabs(DriftL0);
2655 B2FATAL(
"linearInterpolationOfSgm = false is not allowed now !");
2659 unsigned short ial[2] = {0};
2660 unsigned short ilr[2] = {lro, lro};
2663 unsigned short ith[2] = {0};
2667 unsigned short jal(0), jlr(0), jth(0);
2669 for (
unsigned k = 0; k < 4; ++k) {
2674 w = (1. - wal) * (1. - wth);
2675 }
else if (k == 1) {
2679 w = (1. - wal) * wth;
2680 }
else if (k == 2) {
2684 w = wal * (1. - wth);
2685 }
else if (k == 3) {
2703 const double& P0 =
m_Sigma[iCLayer][jlr][jal][jth][0];
2704 const double& P1 =
m_Sigma[iCLayer][jlr][jal][jth][1];
2705 const double& P2 =
m_Sigma[iCLayer][jlr][jal][jth][2];
2706 const double& P3 =
m_Sigma[iCLayer][jlr][jal][jth][3];
2707 const double& P4 =
m_Sigma[iCLayer][jlr][jal][jth][4];
2708 const double& P5 =
m_Sigma[iCLayer][jlr][jal][jth][5];
2709 const double& P6 =
m_Sigma[iCLayer][jlr][jal][jth][6];
2711#if defined(CDC_DEBUG)
2712 cout <<
"driftL= " << driftL << endl;
2713 cout <<
"iCLayer= " << iCLayer <<
" " << jlr <<
" " << jal <<
" " << jth << endl;
2714 cout <<
"P0= " << P0 << endl;
2715 cout <<
"P1= " << P1 << endl;
2716 cout <<
"P2= " << P2 << endl;
2717 cout <<
"P3= " << P3 << endl;
2718 cout <<
"P4= " << P4 << endl;
2719 cout <<
"P5= " << P5 << endl;
2720 cout <<
"P6= " << P6 << endl;
2725 sigma += w *
sqrt(P0 / (driftL * driftL + P1) + P2 * driftL + P3 +
2726 P4 * exp(P5 * (driftL - P6) * (driftL - P6)));
2728 double forthTermAtP7 = P4 * exp(P5 * (P7 - P6) * (P7 - P6));
2729 const double& P8 =
m_Sigma[iCLayer][jlr][jal][jth][8];
2731 double sigmaAtP7 =
sqrt(P0 / (P7 * P7 + P1) + P2 * P7 + P3 + forthTermAtP7);
2732 sigma += w * (P8 * (driftL - P7) + sigmaAtP7);
2734 double onePls4AtP7 =
sqrt(P0 / (P7 * P7 + P1) + forthTermAtP7);
2735 const double onePls4 = P8 * (driftL - P7) + onePls4AtP7;
2736 sigma += w *
sqrt(P2 * driftL + P3 + onePls4 * onePls4);
2738 forthTermAtP7 =
sqrt(forthTermAtP7);
2739 const double forthTerm = P8 * (driftL - P7) + forthTermAtP7;
2740 sigma += w *
sqrt(P0 / (driftL * driftL + P1) + P2 * driftL + P3 +
2741 forthTerm * forthTerm);
2754 unsigned short lr = 0;
2755 double wCrossT = (posOnWire.
Cross(posOnTrack)).Z();
2759 }
else if (wCrossT > 0.) {
2762 if ((posOnTrack - posOnWire).Perp() != 0.) {
2763 double wCrossP = (posOnWire.
Cross(momentum)).Z();
2765 if (posOnTrack.
Perp() > posOnWire.
Perp()) {
2770 }
else if (wCrossP < 0.) {
2771 if (posOnTrack.
Perp() < posOnWire.
Perp()) {
2789 const double distanceCrossP = ((posOnWire - posOnTrack).Cross(momentum)).Z();
2790 unsigned short int lr = (distanceCrossP > 0.) ? 1 : 0;
2797 const double wx = posOnWire.
X();
2798 const double wy = posOnWire.
Y();
2799 const double px = momentum.X();
2800 const double py = momentum.Y();
2802 const double cross = wx * py - wy * px;
2803 const double dot = wx * px + wy * py;
2805 return atan2(cross,
dot);
2810 return atan2(momentum.Perp(), momentum.Z());
2816 unsigned short lro = (fabs(alpha) <= 0.5 * M_PI) ? lr : abs(lr - 1);
2824 double alphao = alpha;
2825 if (alpha > 0.5 * M_PI) {
2827 }
else if (alpha < -0.5 * M_PI) {
2837 double thetao = fabs(alpha) > 0.5 * M_PI ? M_PI - theta : theta;
2843 unsigned short lrs[2])
const
2852 lrs[0] = abs(lrs[0] - 1);
2859 lrs[1] = abs(lrs[1] - 1);
2866 points[0] = points[1] - 1;
2873 unsigned short lrs[2])
const
2882 lrs[0] = abs(lrs[0] - 1);
2889 lrs[1] = abs(lrs[1] - 1);
2896 points[0] = points[1] - 1;
2922 points[0] = points[1] - 1;
2929 unsigned short points[2])
const
2945 points[0] = points[1] - 1;
2977 const unsigned short nLayers[c_nSuperLayers] = {8, 6, 6, 6, 6, 6, 6, 6, 6};
2979 for (
unsigned short SLayer = 0; SLayer < c_nSuperLayers; ++SLayer) {
2980 unsigned short firstCLayer = 0;
2981 for (
unsigned short i = 0; i < SLayer; ++i) {
2982 firstCLayer += nLayers[i];
2987 for (
unsigned short Layer = 0; Layer < nLayers[SLayer]; ++Layer) {
2988 unsigned short CLayer = firstCLayer + Layer;
2990 if (CLayer == firstCLayer) {
2993 }
else if (CLayer == firstCLayer + 1) {
2999 if (Layer % 2 == 0) {
DataType Z() const
access variable Z (= .at(2) without boundary check)
void SetX(DataType x)
set X/1st-coordinate
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
void SetZ(DataType z)
set Z/3rd-coordinate
void SetY(DataType y)
set Y/2nd-coordinate
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
B2Vector3< DataType > Unit() const
Unit vector parallel to this.
static const baseType layerDPhi
Layer rotation in global X-Y plane (gamma) dPhi = forward - backward endplate.
static const baseType layerDy
Layer shift in global Y dY = forward - backward endplate.
static const baseType wireBwdZ
Wire Z position w.r.t. nominal on backward endplate.
static const baseType layerDx
Layer shift in global X dX = forward - backward endplate.
static const baseType wireBwdY
Wire Y position w.r.t. nominal on backward endplate.
static const baseType wireFwdZ
Wire Z position w.r.t. nominal on forward endplate.
static const baseType wireFwdY
Wire Y position w.r.t. nominal on forward endplate.
static const baseType wireFwdX
Wire X position w.r.t. nominal on forward endplate.
static const baseType wireBwdX
Wire X position w.r.t. nominal on backward endplate.
static const baseType layerY
Layer shift in global Y at backward endplate.
static const baseType layerX
Layer shift in global X at backward endplate.
static const baseType layerPhi
Layer rotation in global X-Y plane (gamma) at backward endplate.
static const baseType wireTension
Wire tension w.r.t. nominal (=50. ?)
The Class for CDC geometry.
static const baseType wireBwdZ
Wire Z position w.r.t. nominal on backward endplate.
static const baseType wireBwdY
Wire Y position w.r.t. nominal on backward endplate.
static const baseType wireFwdZ
Wire Z position w.r.t. nominal on forward endplate.
static const baseType wireFwdY
Wire Y position w.r.t. nominal on forward endplate.
static const baseType wireFwdX
Wire X position w.r.t. nominal on forward endplate.
static const baseType wireBwdX
Wire X position w.r.t. nominal on backward endplate.
static const baseType wireTension
Wire tension w.r.t. nominal (=50. ?)
The Class for CDC Geometry Control Parameters.
bool getDebug() const
Get debug flag.
bool getSigmaInputType()
Get input type for sigma.
bool getMisalignmentInputType()
Get input type for wire misalignment.
std::string getT0File() const
Get input file name for t0.
bool getDisplacementInputType()
Get input type for wire displacement.
double getAddFudgeFactorForSigmaForMC() const
Get additional fudge factor for space resol for MC.
std::string getEDepToADCFile() const
Get input file name for edeptoadc.
std::string getDisplacementFile() const
Get input file name for wire displacement.
std::string getMisalignmentFile() const
Get input file name for wire misalignment.
std::string getAlignmentFile() const
Get input file name for wire alignment.
bool getAlignmentInputType()
Get input type for wire alignment.
double getMaterialDefinitionMode() const
Get material definition mode.
std::string getPropSpeedFile() const
Get input file name for prop-speed.
bool getT0InputType()
Get input type for t0.
bool getEDepToADCInputType()
Get input type for edeptoadc.
std::string getSigmaFile() const
Get input file name for sigma.
bool getAlignment() const
Get alignment switch.
bool getMisalignment() const
Get misalignment switch.
bool getDisplacement() const
Get displacement switch.
int getSenseWireZposMode() const
Get sense wire z position mode.
double getAddFudgeFactorForSigmaForData() const
Get additional fudge factor for space resol for data.
std::string getXtFile() const
Get input file name for xt-relation.
bool getTwInputType()
Get input type for time-walk.
std::string getFFactorFile() const
Get input file name for fudge factor.
bool getChMapInputType()
Get input type for channel map.
std::string getTwFile() const
Get input file name for time-walk.
bool getFFactorInputType()
Get input type for fuge factor.
bool getXtInputType()
Get input type for xt.
bool getBwInputType()
Get input type for bad wire.
bool getPropSpeedInputType()
Get input type for prop.
static CDCGeoControlPar & getInstance()
Static method to get a reference to the CDCGeoControlPar instance.
std::string getChMapFile() const
Get input file name for channel map.
The Class for CDC Geometry Parameters.
void outputDesignWirParam(unsigned layerID, unsigned cellID) const
Write the designed wire parameters to the alignment.dat (default).
std::map< WireID, unsigned short > m_wireToChannel
map relating wire-id and channel-id.
void setWirPosAlignParams()
Set wire alignment params.
int m_materialDefinitionMode
Control switch for gas and wire material definition.
unsigned short m_nAlphaPoints4Sgm
No.
void readSigma(const GearDir &gbxParams, int mode=0)
Read spatial resolution table.
void readTW(const GearDir &gbxParams, int mode=0)
Read time-walk parameter.
void setXtRel()
Set XT-relation table (from DB) (new).
float m_BWirPosMisalign[c_maxNSenseLayers][c_maxNDriftCells][3]
Wire position incl.
DBObjPtr< CDCBadWires > * m_badWireFromDB
bad-wires retrieved from DB.
double getTheta(const B2Vector3D &momentum) const
Returns track incident angle (theta in rad.).
void readT0(const GearDir &gbxParams, int mode=0)
Read t0 parameters (from a file).
void setT0()
Set t0 parameters (from DB)
float m_alphaPoints4Sgm[c_maxNAlphaPoints]
alpha sampling points for sigma (rad)
virtual ~CDCGeometryPar()
Destructor.
ushort m_maxNSuperLayers
Maximum number of Super Layers.
double m_fudgeFactorForSigma[3]
Fuge factor for space resol.
double outerRadiusInnerWall() const
Returns the outer radius of the inner wall.
int m_sigmaParamMode
Mode for sigma parameterization.
bool m_alignment
Switch for alignment.
float m_alphaPoints[c_maxNAlphaPoints]
alpha sampling points for xt (rad)
void getClosestAlphaPoints(const double alpha, double &wal, unsigned short points[2], unsigned short lrs[2]) const
Returns the two closest alpha points for the input track incident angle (alpha).
void readEDepToADC(const GearDir &gbxParams, int mode=0)
Read spatial edep-to-adc conv.
double m_globalPhiRotation
Global ratation in phi (rad.); only for sense wires now.
EWirePosition
Wire position set.
double innerRadiusOuterWall() const
Returns the inner radius of the outer wall.
unsigned cellId(unsigned layerId, const B2Vector3D &position) const
The method to get cell id based on given layer id and the position.
void newReadSigma(const GearDir &gbxParams, int mode=0)
Read spatial resolution table in new format.
void setEDepToADCConversions()
Set edep-to-ADC conversion params.
double m_nominalPropSpeed
Nominal propagation speed of the sense wire (27.25 cm/nsec).
int nShifts(int layerId) const
Returns number shift.
float m_thetaPoints[c_maxNThetaPoints]
theta sampling points for xt (rad)
void setDesignWirParam(unsigned layerID, unsigned cellID)
Set the desizend wire parameters.
void getWireSagEffect(EWirePosition set, unsigned layerID, unsigned cellID, double zw, double &ywb_sag, double &ywf_sag) const
Compute effects of the sense wire sag.
DBArray< CDCDisplacement > * m_displacementFromDB
displacement params.
bool m_XTetc
Switch for reading x-t etc.
void setShiftInSuperLayer()
Calculates and saves shifts in super-layers (to be used in searching hits in neighboring cells)
int m_nShifts[c_maxNSenseLayers]
The array to store shifted cell number in each sense wire layer.
bool m_wireSag
Switch for sense wire sag.
bool m_XTetc4Recon
Switch for selecting xt etc.
double getDriftLength0(double dt, unsigned short layer, unsigned short lr, double alpha=0., double theta=0.5 *M_PI) const
Return the drift dength to the sense wire; tentative ver.
unsigned short m_boardAndChannelToWire[c_nBoards][48]
array relating board-channel-id and wire-id.
unsigned short m_nThetaPoints4Sgm
No.
float m_WireSagCoef[c_maxNSenseLayers][c_maxNDriftCells]
Wire sag coefficient for each cell; ibid.
void generateXML(const std::string &of)
Generate an xml file used in gearbox.
void getClosestAlphaPoints4Sgm(const double alpha, double &wal, unsigned short points[2], unsigned short lrs[2]) const
Returns the two closest alpha points for sigma for the input track incident angle (alpha).
DBObjPtr< HardwareClockSettings > m_clockSettings
hardware clock settings
float m_eDepToADCParams[c_maxNSenseLayers][c_maxNDriftCells][7]
edep-to-ADC conv.
double m_minTrackLength
Minimum track length for G4 step.
double getAlpha(const B2Vector3D &posOnWire, const B2Vector3D &momentum) const
Returns track incident angle in rphi plane (alpha in rad.).
double fieldWireR(int layerId) const
Returns radius of field wire in each layer.
float m_FWirPosMisalign[c_maxNSenseLayers][c_maxNDriftCells][3]
Wire position incl.
const B2Vector3D wireForwardPosition(uint layerId, int cellId, EWirePosition set=c_Base) const
Returns the forward position of the input sense wire.
bool isDeadWire(const WireID &wid, double &eff)
Inquire if the wire is dead.
unsigned m_nWires[c_maxNSenseLayers]
The array to store the wire number in each sense wire layre.
double getDriftV(double dt, unsigned short layer, unsigned short lr, double alpha=0., double theta=0.5 *M_PI) const
Get the realistic drift velocity.
double m_clockFreq4TDC
Clock frequency used for TDC (GHz).
int m_nFLayer
The number of field wire layer.
static CDCGeometryPar * m_B4CDCGeometryParDB
Pointer that saves the instance of this class.
DBObjPtr< CDCMisalignment > * m_misalignmentFromDB
misalignment params.
float m_XT[c_maxNSenseLayers][2][c_maxNAlphaPoints][c_maxNThetaPoints][c_nXTParams]
XT-relation coefficients for each layer, Left/Right, entrance angle and polar angle.
signed short m_shiftInSuperLayer[c_nSuperLayers][8]
shift in phi-direction wrt the 1st layer in each super layer
std::string m_version
The version of geometry parameters.
const B2Vector3D wireBackwardPosition(uint layerId, int cellId, EWirePosition set=c_Base) const
Returns the backward position of the input sense wire.
bool m_linearInterpolationOfXT
Switch for linear interpolation of xt.
DBObjPtr< CDCSpaceResols > * m_sResolFromDB
sigma params.
void setDisplacement()
Set displacement of sense wire.
double getOutgoingAlpha(const double alpha) const
Converts incoming- to outgoing-alpha.
bool isHotWire(const WireID &wid)
Inquire if the wire is hot.
double m_meanT0
mean t0 over all wires; should be double.
bool m_debug
Switch for debug printing.
DBObjPtr< CDCTimeWalks > * m_timeWalkFromDB
time-walk coeffs.
ushort m_nSenseWires
Maximum number of Sense Wires.
unsigned short m_tdcOffset
Not used; to be removed later.
double getSigma(double dist, unsigned short layer, unsigned short lr, double alpha=0., double theta=0.5 *M_PI) const
Return the basic resolution of drift length (cm).
CDCGeometryPar(const CDCGeometry *=nullptr)
Singleton class.
unsigned short getOutgoingLR(const unsigned short lr, const double alpha) const
Converts incoming-lr to outgoing-lr.
ushort m_maxNSenseLayers
Maximum number of Sense Wire Layers.
void readWirePositionParams(EWirePosition set, const CDCGeometry *geom)
Read displacement or (mis)alignment params from text file.
float m_thetaPoints4Sgm[c_maxNThetaPoints]
theta sampling points for sigma (rad)
std::map< WireID, unsigned short > m_wireToBoard
map relating wire-id and board-id.
double getOutgoingTheta(const double alpha, const double theta) const
Converts incoming- to outgoing-theta.
double m_senseWireDiameter
The diameter of sense wires.
double offset(int layerID) const
Return wire offset in phi direction at endplate.
bool m_displacement
Switch for displacement.
int m_twParamMode
Mode for tw parameterization.
double senseWireBZ(int layerId) const
Returns backward z position of sense wire in each layer.
double m_dzSBackwardLayer[c_maxNSenseLayers]
Corrections for backward z position of sense wire layers.
double getMinDriftTime(unsigned short layer, unsigned short lr, double alpha=0., double theta=0.5 *M_PI) const
Return the min.
unsigned nWiresInLayer(int layerId) const
Returns wire numbers in a layer.
double fieldWireBZ(int layerId) const
Returns backward z position of field wire in each layer.
void getClosestThetaPoints(const double alpha, const double theta, double &wth, unsigned short points[2]) const
Returns the two closest theta points for the input track incident angle (theta).
double senseWireFZ(int layerId) const
Returns forward z position of sense wire in each layer.
void readPropSpeed(const GearDir &gbxParams, int mode=0)
Read the propagation speed along the sense wire.
double innerRadiusInnerWall() const
Returns the inner radius of the inner wall.
DBObjPtr< CDCTimeZeros > * m_t0FromDB
t0s retrieved from DB.
int m_xtFileFormat
Format of xt input file.
int m_sigmaFileFormat
Format of sigma input file.
ushort m_firstSuperLayerOffset
Offset of the first super layer (for reduced CDC studies)
void setChMap()
Set channel map (from DB)
DBObjPtr< CDCFudgeFactorsForSigma > * m_fFactorFromDB
fudge factors retrieved from DB.
int m_nSLayer
The number of sense wire layer.
DBArray< CDCChannelMap > * m_chMapFromDB
channel map retrieved from DB.
void calcMeanT0(double minT0=3800, double maxT0=5800, int maxIt=10, double nStdv=3, double epsi=0.1)
Calculate mean t0 in ns (over all good wires)
void readFromDB(const CDCGeometry &)
Gets geometry parameters from database.
DBObjPtr< CDCXtRelations > * m_xtRelFromDB
xt params.
double m_nominalDriftV
Nominal drift velocity (4.0x10^-3 cm/nsec).
float m_FWirPos[c_maxNSenseLayers][c_maxNDriftCells][3]
Wire position incl.
float m_WireSagCoefAlign[c_maxNSenseLayers][c_maxNDriftCells]
Wire sag coefficient incl.
double m_zSForwardLayer[c_maxNSenseLayers]
The array to store forward z position of sense wire layers.
bool m_linearInterpolationOfSgm
Switch for linear interpolation of sigma.
DBObjPtr< CDCPropSpeeds > * m_propSpeedFromDB
prop.
void setBadWire()
Set bad-wires (from DB)
int m_xtParamMode
Mode for xt parameterization.
float m_FWirPosAlign[c_maxNSenseLayers][c_maxNDriftCells][3]
Wire position incl.
double fieldWireFZ(int layerId) const
Returns forward z position of field wire in each layer.
double m_dzSForwardLayer[c_maxNSenseLayers]
Corrections for forward z position of sense wire layers.
double getEDepToADCConvFactor(unsigned short layer, unsigned short cell, double edep, double dx, double costh)
Return edep-to-ADC conversion factor.
double m_nominalDriftVInv
Inverse of the nominal drift velocity.
const double * innerRadiusWireLayer() const
Returns an array of inner radius of wire layers.
double getDriftTime(double dist, unsigned short layer, unsigned short lr, double alpha, double theta) const
Return the drift time to the sense wire.
void setPropSpeed()
Set prop.
signed short getShiftInSuperLayer(unsigned short iSuperLayer, unsigned short iLayer) const
Returns shift in the super-layer.
double getWireSagCoef(EWirePosition set, uint layerId, int cellId) const
Returns coefficient for the sense wire sag.
void readChMap()
Read channel map between wire-id and electronics-id.
double m_zFForwardLayer[c_maxNFieldLayers]
The array to store forward z position of field wire layers.
double m_rSLayer[c_maxNSenseLayers]
The array to store radius of sense wire layers.
double m_fieldWireDiameter
The diameter of field wires.
double m_zFBackwardLayer[c_maxNFieldLayers]
The array to store backward z position of field wire layers.
ushort m_nFieldWires
Maximum number of Field Wires.
float m_WireSagCoefMisalign[c_maxNSenseLayers][c_maxNDriftCells]
Wire sag coefficient incl.
double getDriftLength(double dt, unsigned short layer, unsigned short lr, double alpha=0., double theta=0.5 *M_PI, bool calculateMinTime=true, double minTime=0.) const
Return the drift dength to the sense wire.
double m_cellSize[c_maxNSenseLayers]
The array to store cell size in each sense wire layer.
float m_BWirPosAlign[c_maxNSenseLayers][c_maxNDriftCells][3]
Wire position incl.
double outerRadiusOuterWall() const
Returns the outer radius of the outer wall.
float m_t0[c_maxNSenseLayers][c_maxNDriftCells]
t0 for each sense-wire (in nsec).
void setWirPosMisalignParams()
Set wire misalignment params.
double m_offSet[c_maxNSenseLayers]
The array to store z offset of sense wire layers.
void setTW()
Set time-walk parameters.
void setSResol()
Set spatial resolution (from DB).
double m_zSBackwardLayer[c_maxNSenseLayers]
The array to store backward z position of sense wire layers.
unsigned short getOldLeftRight(const B2Vector3D &posOnWire, const B2Vector3D &posOnTrack, const B2Vector3D &momentum) const
Returns old left/right.
float m_propSpeedInv[c_maxNSenseLayers]
Inverse of propagation speed of the sense wire.
ushort m_maxNCellsPerLayer
Maximum number wires within a layer.
double m_zWall[4][2]
The array to store z position of inner wall and outer wall.
bool isBadWire(const WireID &wid)
Inquire if the wire is totally-dead.
DBObjPtr< CDCAlignment > * m_alignmentFromDB
alignment params.
ushort m_maxNFieldLayers
Maximum number of Field Wire Layers.
bool m_misalignment
Switch for misalignment.
double m_senseWireDensity
The density of sense wires.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
ushort m_firstLayerOffset
Offset of the first layer (for reduced CDC studies)
void Print() const
Print some debug information.
float m_timeWalkCoef[c_nBoards][2]
coefficients for time walk.
void readFFactor(const GearDir &gbxParams, int mode=0)
Read fudge factors.
unsigned short m_nThetaPoints
No.
double m_maxSpaceResol
max space resolution allowed (cm).
double m_thresholdEnergyDeposit
Energy thresh.
float m_BWirPos[c_maxNSenseLayers][c_maxNDriftCells][3]
Wire position incl.
float m_Sigma[c_maxNSenseLayers][2][c_maxNAlphaPoints][c_maxNThetaPoints][c_nSigmaParams]
position resolution for each layer.
void readXT(const GearDir &gbxParams, int mode=0)
Read XT-relation table.
double m_rFLayer[c_maxNFieldLayers]
The array to store radius of field wire layers.
void newReadXT(const GearDir &gbxParams, int mode=0)
Read XT-relation table in new format.
double m_nominalSpaceResol
Nominal spatial resolution (0.0130 cm).
unsigned nWireLayers() const
Returns a number of wire layers.
unsigned short m_nAlphaPoints
No.
unsigned short getNewLeftRightRaw(const B2Vector3D &posOnWire, const B2Vector3D &posOnTrack, const B2Vector3D &momentum) const
Returns new left/right_raw.
int m_senseWireZposMode
Mode for sense wire z position corr.
double m_rWall[4]
The array to store radius of inner wall and outer wall.
double m_tdcBinWidth
TDC bin width (nsec/bin).
bool m_modLeftRightFlag
Switch for modified left/right flag.
void getClosestThetaPoints4Sgm(const double alpha, const double theta, double &wth, unsigned short points[2]) const
Returns the two closest theta points for sigma for the input track incident angle (theta).
DBObjPtr< CDCEDepToADCConversions > * m_eDepToADCConversionsFromDB
Pointer to edep-to-ADC conv.
const double * outerRadiusWireLayer() const
Returns an array of outer radius of wire layers.
double senseWireR(int layerId) const
Returns radius of sense wire in each layer.
double m_senseWireTension
The tension of sense wires.
void setFFactor()
Set fudge factors (from DB).
bool getModLeftRightFlag() const
Get modified left/right flag.
double getMinTrackLength() const
Get minimum track length.
double getThresholdEnergyDeposit() const
Get threshold for Energy Deposit;.
static CDCSimControlPar & getInstance()
Static method to get a reference to the CDCSimControlPar instance.
bool getWireSag() const
Get wiresag flag.
void addCallback(std::function< void(const std::string &)> callback, bool onDestruction=false)
Add a callback method.
Class for accessing arrays of objects in the database.
Class for accessing objects in the database.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
GearDir is the basic class used for accessing the parameter store.
virtual std::string getString(const std::string &path="") const noexcept(false) override
Get the parameter path as a string.
Optional DBObjPtr: This class behaves the same as the DBObjPtr except that it will not raise errors w...
Class to identify a wire inside the CDC.
unsigned short getICLayer() const
Getter for continuous layer numbering.
unsigned short getIWire() const
Getter for wire within the layer.
unsigned short getEWire() const
Getter for encoded wire number.
B2Vector3< double > B2Vector3D
typedef for common usage with double
double sqrt(double a)
sqrt for double
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors
void openFileB(boost::iostreams::filtering_istream &ifs, const std::string &fileName0)
Open a file using boost (to be able to read a gzipped file)
void openFileA(std::ifstream &ifs, const std::string &fileName0)
Open a file.
Abstract base class for different kinds of events.