11 using namespace TrTrack;
13 static std::array<unsigned long int, numSpans>
patterns = {3, 5, 6, 7, 0, 0, 3};
20 return trackPtr->TestHitLayerJHasXY(1);
22 return trackPtr->TestHitLayerJHasXY(9);
24 return (trackPtr->TestHitLayerJHasXY(1) && trackPtr->TestHitLayerJHasXY(9));
30 throw std::runtime_error(
"Span not supported");
34 static constexpr std::array<double, 9>
powersOfTen = {1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8};
39 for (
int il = 2; il < 9; il++) {
40 if (!trackPtr->TestHitLayerJ(il))
53 bool TrTrackBaseData::_FitIDExists(
Fit fit,
Span span)
const {
54 auto itr = _fit_ID.find(fit);
55 if (itr ==
end(_fit_ID)) {
59 auto fit_ID_itr = itr->second.find(span);
60 if (fit_ID_itr ==
end(itr->second)) {
64 return (fit_ID_itr->second > 0);
67 Span TrTrackBaseData::_GetBestSpan(
Fit fit)
const {
85 pars.
charge =
static_cast<int>(inner_charge + 0.5f);
88 pars.mass = TrFit::Mproton;
90 pars.mass = TrFit::Mhelium / 2.0f * pars.charge;
93 if (pars.charge == static_cast<int>(production_charge + 0.5f))
103 bool TrTrackBaseData::Fill(TrTrackR *trackPtr, TrTrackFillType type) {
107 if (type == TrTrackFillType::Standalone) {
113 float tmp_inner_charge = trackPtr->GetQ_all(_beta, temp_fit_ID).Mean;
114 if (tmp_inner_charge > 1.5) {
115 if (trackPtr->GetQYJ_all(2, _beta, temp_fit_ID).InnerQ > 8.5)
116 tmp_inner_charge = trackPtr->GetQYJ_all(2, _beta, temp_fit_ID).InnerQ;
119 FitCharge = tmp_inner_charge;
121 auto fitPars =
InitTrkReFit(tmp_inner_charge, _isMC, FitCharge);
122 _tmpCharge = fitPars.charge;
133 if (type == TrTrackFillType::Standalone) {
149 _fit_ID[fit][span] = trackPtr->iTrTrackPar(
fitAlgoCode[fit], static_cast<int>(
patterns[span]),
150 30 + fitPars.refit, fitPars.mass, _tmpCharge);
152 if (_fit_ID[fit][span] > 0) {
154 AMSPlane pl(TVector3(0, 0, 0), TVector3(1, 0, 0), TVector3(0, 1, 0));
155 trackPtr->Interpolate(pl, rigidity, _fit_ID[fit][span]);
156 Rigidity[fit][span] =
static_cast<float>(rigidity);
158 static_cast<float>(trackPtr->GetChisqX(_fit_ID[fit][span]) / trackPtr->GetNdofX(_fit_ID[fit][span]));
160 static_cast<float>(trackPtr->GetChisqY(_fit_ID[fit][span]) / trackPtr->GetNdofY(_fit_ID[fit][span]));
165 trackPtr->RecalcHitCoordinates(0,
false,
false, _tmpCharge);
169 if (type == TrTrackFillType::Standalone) {
182 InnerCharge[
ChargeRecoType::HL] = trackPtr->GetInnerQH_all(2, _beta, base_fit_ID).Mean;
185 InnerChargeRMS[
ChargeRecoType::HL] = trackPtr->GetInnerQH_all(2, _beta, base_fit_ID).RMS;
186 InnerChargeRMS[
ChargeRecoType::YJ] = trackPtr->GetQYJ_all(2, _beta, base_fit_ID).InnerQRMS;
189 for (
int ijl = 0; ijl < 9; ijl++) {
190 if (!trackPtr->GetHitLJ(ijl + 1))
192 AMSPlaneM plm = trackPtr->GetHitCooLJN(ijl + 1);
193 TVector3 mglob = plm.getMGlobal();
194 if (trackPtr->GetHitLJ(ijl + 1)->GetXCluster())
195 TrTrackHitPos[ijl][0] = static_cast<float>(mglob.x());
196 if (trackPtr->GetHitLJ(ijl + 1)->GetYCluster())
197 TrTrackHitPos[ijl][1] = static_cast<float>(mglob.y());
198 if (trackPtr->GetHitLJ(ijl + 1))
199 TrTrackHitPos[ijl][2] = static_cast<float>(mglob.z());
202 if (type == TrTrackFillType::SecondTrack) {
207 for (
int ijl = 0; ijl < 9; ijl++) {
211 if (trackPtr->GetHitLJ(ijl + 1)) {
212 LayerChargeStatus[ijl] = trackPtr->GetHitLJ(ijl + 1)->GetQStatus();
214 LayerChargeXY[ijl][
ChargeRecoType::STD] = trackPtr->GetHitLJ(ijl + 1)->GetQ(2, _beta, Rigidity[fit][span]);
215 LayerChargeXY[ijl][
ChargeRecoType::HL] = trackPtr->GetLayerJQH(ijl + 1, 2, _beta, _fit_ID[fit][span]);
216 LayerChargeXY[ijl][
ChargeRecoType::YJ] = trackPtr->GetLayerQYJ(ijl + 1, 2, _beta, _fit_ID[fit][span]);
225 plm_res = trackPtr->GetHitCooLJN(fitPos + 1);
226 mglob = plm_res.getMGlobal();
228 for (
auto fit : fitTypes) {
229 for (
auto span : spanTypes) {
230 if (type == TrTrackFillType::Standalone) {
244 if (FitIDExists(fit, span)) {
245 int fit_ID = _fit_ID.at(fit).at(span);
252 AMSPlane plm_fitpos(TVector3(0, 0,
fitPositionHeightZ[fitPos]), TVector3(1, 0, 0), TVector3(0, 1, 0));
253 trackPtr->Interpolate(plm_fitpos, rigidity, fit_ID);
254 TVector3 pglob_fitpos = plm_fitpos.getP();
255 TrTrackFitPos[fitPos][fit][span][
Side::X] =
static_cast<float>(pglob_fitpos.x());
256 TrTrackFitPos[fitPos][fit][span][
Side::Y] =
static_cast<float>(pglob_fitpos.y());
265 bool TrTrackPlusData::Fill(TrTrackR *trackPtr) {
266 const auto &_beta = trkBase->_beta;
267 const auto &_tmpCharge = trkBase->_tmpCharge;
269 if (trkBase->InnerCharge.empty())
272 auto *pev = AMSEventR::Head();
274 int refit = ((trkBase->_isMC) || (_tmpCharge != trackPtr->GetAdvancedFitCharge())) ? 3 : 1;
275 float fitMass = (_tmpCharge >= 2) ? TrFit::Mhelium / 2 * _tmpCharge : TrFit::Mproton;
277 auto getPartialPattern = [](TrTrackR *track,
unsigned int jLayer) {
278 unsigned int pattern = 0;
279 for (
unsigned int ijl = 1; ijl < 10; ijl++) {
280 if (track->TestHitLayerJ(ijl) && ijl != jLayer)
286 for (
unsigned int ijl = 2; ijl < 9; ijl++) {
287 TrackFeetDistance[ijl - 1] = pev->GetTkFeetDist(ijl, trackPtr);
291 for (
auto fit : fitTypes) {
297 for (
auto span : spanTypes) {
298 if (trkBase->FitIDExists(fit, span)) {
300 trackPtr->iTrTrackPar(
fitAlgoCode[fit], static_cast<int>(
patterns[span]), 30 + refit, fitMass, _tmpCharge);
301 if (_fit_ID[fit][span] < 0)
307 float zpl = (_beta > 0) ? 195 : -195;
308 AMSPlane pl_TOI(TVector3(0, 0, zpl), TVector3(1, 0, 0), TVector3(0, 1, 0));
309 trackPtr->Interpolate(pl_TOI, rigidity, _fit_ID[fit][span], fitMass, _tmpCharge, 1, (_beta > 0) ? 1 : -1);
310 RigidityTOI[fit][span] =
static_cast<float>(rigidity);
312 AMSPlane pl_RICH(TVector3(0, 0, -70), TVector3(1, 0, 0), TVector3(0, 1, 0));
313 trackPtr->Interpolate(pl_RICH, rigidity, _fit_ID[fit][span], fitMass, _tmpCharge, 1);
314 RigidityRICH[fit][span] =
static_cast<float>(rigidity);
317 AMSPlane pl(TVector3(0, 0, 0), TVector3(1, 0, 0), TVector3(0, 1, 0));
318 trackPtr->Interpolate(pl, rigidity, _fit_ID[fit][span]);
319 Theta[fit][span] =
static_cast<float>(pl.getD().Theta());
320 Phi[fit][span] =
static_cast<float>(pl.getD().Phi());
322 const TrTrackPar &trackPar = trackPtr->gTrTrackPar(_fit_ID[fit][span]);
323 InvRigErr[fit][span] =
static_cast<float>(trackPar.ErrRinv);
327 trackPtr->RecalcHitCoordinates(0, 0, 0, _tmpCharge);
331 for (
unsigned int ijl = 1; ijl < 10; ijl++) {
332 if (!trackPtr->TestHitLayerJ(ijl))
334 auto partialPattern = getPartialPattern(trackPtr, ijl);
336 int pfit_ID = trackPtr->iTrTrackPar(
fitAlgoCode[fit], partialPattern, 30 + refit, fitMass, _tmpCharge);
340 const TrTrackPar &partialTrackPar = trackPtr->gTrTrackPar(pfit_ID);
341 PartialRigidity[ijl - 1][fit] = partialTrackPar.Rigidity;
342 PartialInvRigErr[ijl - 1][fit] = partialTrackPar.ErrRinv;
343 PartialTrChiSq[ijl - 1][fit][
Side::X] =
static_cast<float>(partialTrackPar.ChisqX / partialTrackPar.NdofX);
344 PartialTrChiSq[ijl - 1][fit][
Side::Y] =
static_cast<float>(partialTrackPar.ChisqY / partialTrackPar.NdofY);
348 AMSPlane plm_fitpos(TVector3(0, 0,
fitPositionHeightZ[ijl - 1]), TVector3(1, 0, 0), TVector3(0, 1, 0));
349 trackPtr->Interpolate(plm_fitpos, rigidity, pfit_ID);
350 TVector3 pglob_fitpos = plm_fitpos.getP();
351 PartialTrTrackFitPos[ijl - 1][fit][
Side::X] =
static_cast<float>(pglob_fitpos.x());
352 PartialTrTrackFitPos[ijl - 1][fit][
Side::Y] =
static_cast<float>(pglob_fitpos.y());
356 AMSPlaneM plm_res = trackPtr->GetHitCooLJN(ijl + 1);
357 TVector3 mglob = plm_res.getMGlobal();
358 trackPtr->Interpolate(plm_res, rigidity, pfit_ID);
359 TVector3 pglob_res = plm_res.getP();
360 PartialTrTrackResidual[ijl - 1][fit][
Side::X] =
static_cast<float>(mglob.x() - pglob_res.x());
361 PartialTrTrackResidual[ijl - 1][fit][
Side::Y] =
static_cast<float>(mglob.y() - pglob_res.y());
365 trackPtr->RecalcHitCoordinates(0, 0, 0, _tmpCharge);
369 auto dir_span = trkBase->GetBestSpan(dir_fit);
370 if (trkBase->FitIDExists(dir_fit, dir_span)) {
371 AMSDir trk_dir{Theta[dir_fit][dir_span], Phi[dir_fit][dir_span]};
375 AMSEventR::Head()->GetStoermerCutoff(tmp, -1, trk_dir);
376 DirectionalStoermerCutoff[0] = tmp;
377 AMSEventR::Head()->GetStoermerCutoff(tmp, 1, trk_dir);
378 DirectionalStoermerCutoff[1] = tmp;
384 if (trkBase->FitIDExists(base_fit, base_span)) {
385 int base_fit_ID = _fit_ID.at(base_fit).at(base_span);
387 for (
int ijl = 0; ijl < 9; ijl++) {
388 if (trackPtr->GetHitLJ(ijl + 1)) {
389 float rigidity = (base_fit_ID > 0) ? trkBase->Rigidity.at(base_fit).at(base_span) : 0;
395 if (trackPtr->GetHitLJ(ijl + 1)->GetXCluster())
396 LayerEdep[ijl][
Side::X] = trackPtr->GetHitLJ(ijl + 1)->GetXCluster()->GetEdep();
397 if (trackPtr->GetHitLJ(ijl + 1)->GetYCluster())
398 LayerEdep[ijl][
Side::Y] = trackPtr->GetHitLJ(ijl + 1)->GetYCluster()->GetEdep();
407 for (
const auto fitPos : fitPositionHeights) {
412 plm_res = trackPtr->GetHitCooLJN(fitPos + 1);
413 mglob = plm_res.getMGlobal();
415 for (
auto fit : fitTypes) {
416 for (
auto span : spanTypes) {
417 if (trkBase->FitIDExists(fit, span)) {
418 int fit_ID = _fit_ID.at(fit).at(span);
424 AMSPlane plm_fitpos(TVector3(0, 0,
fitPositionHeightZ[fitPos]), TVector3(1, 0, 0), TVector3(0, 1, 0));
425 trackPtr->Interpolate(plm_fitpos, rigidity, fit_ID);
426 TVector3 pglob_fitpos = plm_fitpos.getP();
431 if (!trackPtr->TestHitLayerJ(fitPos + 1))
433 trackPtr->Interpolate(plm_res, rigidity, fit_ID);
434 TVector3 pglob_res = plm_res.getP();
435 TrTrackResidual[fitPos][fit][span][
Side::X] =
static_cast<float>(mglob.x() - pglob_res.x());
436 TrTrackResidual[fitPos][fit][span][
Side::Y] =
static_cast<float>(mglob.y() - pglob_res.y());
443 static constexpr std::array<float, 5> window = {0.1, 1., 2., 5., 10.};
446 for (
int jLayer = 1; jLayer <= 9; jLayer++) {
448 ClusterSignalRatio[jLayer - 1] = pev->GetTrackerRawSignalRatio(jLayer, 10);
451 TrClusterR *trackClusterPtrX = trackPtr->GetHitLJ(jLayer) ? trackPtr->GetHitLJ(jLayer)->GetXCluster() :
nullptr;
452 TrClusterR *trackClusterPtrY = trackPtr->GetHitLJ(jLayer) ? trackPtr->GetHitLJ(jLayer)->GetYCluster() :
nullptr;
456 AMSPlane plm(TVector3(0, 0,
fitPositionHeightZ[jLayer - 1]), TVector3(1, 0, 0), TVector3(0, 1, 0));
458 TVector3 pglob = plm.getP();
459 AMSPoint fitcoo = AMSPoint(pglob.x(), pglob.y(), pglob.z());
462 static constexpr
float noiseThreshold = 0;
464 for (
int icl = 0; icl < pev->nTrCluster(); icl++) {
465 auto *cluster = pev->pTrCluster(icl);
467 if (!cluster || cluster->GetLayerJ() != jLayer)
470 float edep = 1000 * cluster->GetEdep();
471 if (cluster == trackClusterPtrX) {
476 if (cluster == trackClusterPtrY) {
482 if (edep < noiseThreshold)
486 float clusterDistanceToTrack = std::numeric_limits<float>::max();
487 for (
int im = 0; im < cluster->GetMultiplicity(); im++) {
488 AMSPlaneM pl_mult = cluster->GetGCoordN(im);
489 TVector3 mglob_mult = pl_mult.getMGlobal();
491 clusterDistanceToTrack =
492 std::min(clusterDistanceToTrack,
493 fabs(static_cast<float>(fitcoo[cluster->GetSide()] - mglob_mult[cluster->GetSide()])));
500 if (edep > MaxClusterEdep[jLayer - 1][side]) {
501 MaxClusterEdep[jLayer - 1][side] = edep;
502 MaxClusterDistance[jLayer - 1][side] = clusterDistanceToTrack;
506 for (
unsigned int iw = 0; iw < window.size(); iw++) {
507 if (std::fabs(clusterDistanceToTrack) < window[iw]) {
517 bool TrTrackBaseData::FillElectronVars(TrTrackR *trackPtr,
float zEcalCOG,
bool refitKalman) {
524 _fit_ID[fit][span] = trackPtr->iTrTrackPar(
fitAlgoCode[fit], static_cast<int>(
patterns[span]), 32,
525 static_cast<float>(TrFit::Melectron), 1);
527 if (_fit_ID[fit][span] > 0) {
529 AMSPlane pl(TVector3(0, 0, 0), TVector3(1, 0, 0), TVector3(0, 1, 0));
530 trackPtr->Interpolate(pl, rigidity, _fit_ID[fit][span], TrFit::Melectron, 1);
531 Rigidity[fit][span] =
static_cast<float>(rigidity);
533 static_cast<float>(trackPtr->GetChisqX(_fit_ID[fit][span]) / trackPtr->GetNdofX(_fit_ID[fit][span]));
535 static_cast<float>(trackPtr->GetChisqY(_fit_ID[fit][span]) / trackPtr->GetNdofY(_fit_ID[fit][span]));
541 if (zEcalCOG < std::numeric_limits<float>::max()) {
542 for (
auto fit : fitTypes) {
543 for (
auto span : spanTypes) {
544 if (FitIDExists(fit, span)) {
545 int fit_ID = _fit_ID.at(fit).at(span);
547 AMSPlane plm(TVector3(0, 0, zEcalCOG), TVector3(1, 0, 0), TVector3(0, 1, 0));
548 trackPtr->Interpolate(plm, rigidity, fit_ID);
549 TVector3 pglob = plm.getP();
560 bool TrTrackPlusData::FillElectronVars(TrTrackR *trackPtr,
bool refitKalman) {
561 const auto &base_fit_ID = trkBase->_fit_ID;
562 const auto &_beta = trkBase->_beta;
567 if (trkBase->FitIDExists(fit, span) && refitKalman) {
568 int fit_ID = base_fit_ID.at(fit).at(span);
571 float zpl = (_beta > 0) ? 195 : -195;
572 AMSPlane pl_TOI(TVector3(0, 0, zpl), TVector3(1, 0, 0), TVector3(0, 1, 0));
573 trackPtr->Interpolate(pl_TOI, rigidity, fit_ID, TrFit::Melectron, 1, 1, (_beta > 0) ? 1 : -1);
574 RigidityTOI[fit][span] =
static_cast<float>(rigidity);
576 AMSPlane pl_RICH(TVector3(0, 0, -70), TVector3(1, 0, 0), TVector3(0, 1, 0));
577 trackPtr->Interpolate(pl_RICH, rigidity, fit_ID, TrFit::Melectron, 1, 1);
578 RigidityRICH[fit][span] =
static_cast<float>(rigidity);
580 AMSPlane pl(TVector3(0, 0, 0), TVector3(1, 0, 0), TVector3(0, 1, 0));
581 trackPtr->Interpolate(pl, rigidity, fit_ID, TrFit::Melectron, 1);
582 Theta[fit][span] =
static_cast<float>(pl.getD().Theta());
583 Phi[fit][span] =
static_cast<float>(pl.getD().Phi());
585 const TrTrackPar &trackPar = trackPtr->gTrTrackPar(fit_ID);
586 InvRigErr[fit][span] =
static_cast<float>(trackPar.ErrRinv);
Track constructed with the upper part of the inner tracker (layers 2 to 6)
static bool TrackHasExtHits(TrTrackR *trackPtr, Span span)
Track constructed with the upper part of the inner tracker (layers 3 to 8)
constexpr std::array< Span, numSpans > spanTypes
constexpr std::array< float, numFitPositionHeights > fitPositionHeightZ
void ComputePatterns(TrTrackR *trackPtr)
constexpr std::array< Fit, numFits > fitTypes
Track constructed with inner tracker + layer9 hits.
GenFit kalman filter track fit.
TrTrack container class description.
std::array< int, numFits > fitAlgoCode
ReFitParameters InitTrkReFit(float inner_charge, bool _isMC, float production_charge)
Track constructed without correcting for multiple scattering.
GenFit kalman filter track fit assuming electron mass.
static constexpr std::array< double, 9 > powersOfTen
NAIAChain::EventItr end(NAIAChain &chain)
static std::array< unsigned long int, numSpans > patterns
Standard tracker charge reconstruction.
constexpr std::array< FitPositionHeight, numFitPositionHeights > fitPositionHeights