229 map<string, string> locParameterMap;
230 gPARMS->GetParameters(locParameterMap,
"COMBO_TIMECUT:");
231 for(
auto locParamPair : locParameterMap)
234 cout <<
"param pair: " << locParamPair.first <<
", " << locParamPair.second << endl;
237 auto locUnderscoreIndex = locParamPair.first.find(
'_');
238 auto locParticleString = locParamPair.first.substr(0, locUnderscoreIndex);
239 istringstream locPIDtream(locParticleString);
241 locPIDtream >> locPIDInt;
242 if(locPIDtream.fail())
247 auto locFuncIndex = locParamPair.first.find(
"_FUNC");
248 auto locDetectorString = locParamPair.first.substr(locUnderscoreIndex + 1, locFuncIndex);
249 istringstream locDetectorStream(locDetectorString);
251 locDetectorStream >> locSystemInt;
252 if(locDetectorStream.fail())
257 cout <<
"time cut: pid, detector = " << locPID <<
", " << locSystem << endl;
261 string locFullParamName =
string(
"COMBO_TIMECUT:") + locParamPair.first;
262 gPARMS->SetDefaultParameter(locFullParamName, locKeyValue);
265 if(locFuncIndex != string::npos)
276 locUnderscoreIndex = locKeyValue.find(
'_');
277 auto locValueString = locKeyValue.substr(0, locUnderscoreIndex);
279 istringstream locValuetream(locValueString);
281 locValuetream >> locParameter;
282 if(locValuetream.fail())
285 cout <<
"param: " << locParameter << endl;
289 if(locUnderscoreIndex == string::npos)
291 locKeyValue = locKeyValue.substr(locUnderscoreIndex + 1);
299 japp->RootWriteLock();
303 auto& locSystemMap = locPIDPair.second;
304 for(
auto& locSystemPair : locSystemMap)
306 auto& locParamVector = locSystemPair.second;
307 if(locParamVector.empty())
315 if(locSystemStringMap.find(locSystemPair.first) != locSystemStringMap.end())
316 locCutFuncString = locSystemStringMap[locSystemPair.first];
321 auto locFunc =
new TF1(
"df_TimeCut", locCutFuncString.c_str(), 0.0, 12.0);
323 jout <<
"Time Cut PID, System, func form, params: " <<
ParticleType(locPIDPair.first) <<
", " <<
SystemName(locSystemPair.first) <<
", " << locCutFuncString;
325 for(
size_t loc_i = 0; loc_i < locParamVector.size(); ++loc_i)
327 locFunc->SetParameter(loc_i, locParamVector[loc_i]);
329 jout <<
", " << locParamVector[loc_i];
344 dSourceComboer(locSourceComboer), dSourceComboVertexer(locSourceComboVertexer)
346 gPARMS->SetDefaultParameter(
"COMBO:DEBUG_LEVEL",
dDebugLevel);
347 gPARMS->SetDefaultParameter(
"COMBO:PRINT_CUTS",
dPrintCutFlag);
354 if(locEventLoop ==
nullptr)
365 double locTargetCenterZ = 65.0;
368 double locTargetLength;
376 double locTargetUpstreamZ =
dTargetCenter.Z() - locTargetLength/2.0;
377 double locTargetDownstreamZ =
dTargetCenter.Z() + locTargetLength/2.0;
391 cout <<
"VertexZ Bin Edges: ";
409 vector<double> locBeamPeriodVector;
410 locEventLoop->GetCalib(
"PHOTON_BEAM/RF/beam_period", locBeamPeriodVector);
416 for(
auto& locReaction : locReactions)
418 for(
size_t loc_i = 1; loc_i < locReaction->Get_NumReactionSteps(); ++loc_i)
420 auto locStep = locReaction->Get_ReactionStep(loc_i);
421 auto locPID = locStep->Get_InitialPID();
425 if(std::find(locChainPIDs.begin(), locChainPIDs.end(),
Gamma) == locChainPIDs.end())
436 vector<Particle_t> locPIDs {
Unknown,
Gamma,
Electron,
Positron,
MuonPlus,
MuonMinus,
PiPlus,
PiMinus,
KPlus,
KMinus,
Proton,
AntiProton};
439 japp->RootWriteLock();
442 TDirectory* locCurrentDir = gDirectory;
444 string locDirName =
"Independent";
445 TDirectoryFile* locDirectoryFile =
static_cast<TDirectoryFile*
>(gDirectory->GetDirectory(locDirName.c_str()));
446 if(locDirectoryFile == NULL)
447 locDirectoryFile =
new TDirectoryFile(locDirName.c_str(), locDirName.c_str());
448 locDirectoryFile->cd();
450 locDirName =
"Combo_Construction";
451 locDirectoryFile =
static_cast<TDirectoryFile*
>(gDirectory->GetDirectory(locDirName.c_str()));
452 if(locDirectoryFile == NULL)
453 locDirectoryFile =
new TDirectoryFile(locDirName.c_str(), locDirName.c_str());
454 locDirectoryFile->cd();
457 locDirectoryFile =
static_cast<TDirectoryFile*
>(gDirectory->GetDirectory(locDirName.c_str()));
458 if(locDirectoryFile == NULL)
459 locDirectoryFile =
new TDirectoryFile(locDirName.c_str(), locDirName.c_str());
460 locDirectoryFile->cd();
462 for(
auto locPID : locPIDs)
466 locDirName = locPIDString;
467 locDirectoryFile =
static_cast<TDirectoryFile*
>(gDirectory->GetDirectory(locDirName.c_str()));
468 if(locDirectoryFile == NULL)
469 locDirectoryFile =
new TDirectoryFile(locDirName.c_str(), locDirName.c_str());
470 locDirectoryFile->cd();
472 auto& locTimingSystems = (
ParticleCharge(locPID) == 0) ? locTimingSystems_Neutral : locTimingSystems_Charged;
473 for(
auto locSystem : locTimingSystems)
478 auto locHist = gDirectory->Get(locHistName.c_str());
483 dHistMap_RFDeltaTVsP_AllRFs[locPID][locSystem] =
new TH2I(locHistName.c_str(), locHistTitle.c_str(), 400, 0.0, 12.0, 1400, -7.0, 7.0);
492 auto locHist = gDirectory->Get(locHistName.c_str());
497 dHistMap_RFDeltaTVsP_BestRF[locPID][locSystem] =
new TH2I(locHistName.c_str(), locHistTitle.c_str(), 400, 0.0, 12.0, 1400, -7.0, 7.0);
502 gDirectory->cd(
"..");
505 gDirectory->cd(
"..");
508 string locHistName =
"BeamRFDeltaTVsBeamE";
509 auto locHist = gDirectory->Get(locHistName.c_str());
511 dHist_BeamRFDeltaTVsBeamE =
new TH2I(locHistName.c_str(),
";Beam Energy;#Deltat_{Beam - RF}", 400, 0.0, 12.0, 3600, -18.0, 18.0);
532 vector<const DNeutralShower*> locBCALShowers, locFCALShowers;
534 for(
const auto& locShower : locNeutralShowers)
536 auto& locContainer = (locShower->dDetectorSystem ==
SYS_BCAL) ? locBCALShowers : locFCALShowers;
537 locContainer.push_back(locShower);
543 for(
const auto& locShower : locFCALShowers)
550 for(
const auto& locShower : locBCALShowers)
556 for(
const auto& locShower : locFCALShowers)
564 for(
const auto& locShower : locBCALShowers)
571 for(
auto& locRFShowerPair : locZBinPair.second)
573 auto& locShowerVector = locRFShowerPair.second;
574 std::sort(locShowerVector.begin(), locShowerVector.end());
575 if(locZBinPair.first == locUnknownZBin)
576 locShowerVector.erase(std::unique(locShowerVector.begin(), locShowerVector.end()), locShowerVector.end());
582 cout <<
"SHOWER RF BUNCHES:" << endl;
585 for(
const auto& locShowerPair : locZBinPair.second)
587 cout <<
"z-bin, pointer, system, bunches: " << int(locZBinPair.first) <<
", " << locShowerPair.first <<
", " <<
SystemName(static_cast<const DNeutralShower*>(locShowerPair.first)->dDetectorSystem) <<
", ";
588 for(
const auto& locBunch : locShowerPair.second)
589 cout << locBunch <<
", ";
593 cout <<
"SHOWERS BY BEAM BUNCH BY ZBIN:" << endl;
594 for(
const auto& locZBinPair : dShowersByBeamBunchByZBin)
596 for(
const auto& locBunchPair : locZBinPair.second)
598 cout <<
"z-bin, bunch, showers: " << int(locZBinPair.first) <<
", ";
599 if(locBunchPair.first.empty())
602 cout << locBunchPair.first.front() <<
", ";
603 for(
const auto& locShower : locBunchPair.second)
604 cout << locShower <<
", ";
618 auto locVertexTime = locKinematicData->time();
620 cout <<
"eval time shifts for shower, system, zbin: " << locNeutralShower <<
", " <<
SystemName(locSystem) <<
", " << int(locZBin) << endl;
623 auto locJObject =
static_cast<const JObject*
>(locNeutralShower);
629 locZBinPair.second.emplace(locJObject, locRFShifts);
630 for(
const auto& locNumShifts : locRFShifts)
639 for(
const auto& locNumShifts : locRFShifts)
652 cout <<
"DSourceComboTimeHandler::Calc_BeamBunchShifts(): PID, system, period, orig rf time, particle vertex time, orig prop rf time, delta-t cut, include offset: " << locPID <<
", " <<
SystemName(locSystem) <<
", " <<
dBeamBunchPeriod <<
", " <<
dInitialEventRFBunch->
dTime <<
", " << locVertexTime <<
", " << locOrigRFBunchPropagatedTime <<
", " << locDeltaTCut <<
", " << locIncludeDecayTimeOffset << endl;
653 auto locOrigNumShifts =
Calc_RFBunchShift(locOrigRFBunchPropagatedTime, locVertexTime);
654 vector<int> locRFShifts;
665 auto locMinDeltaT = -1.0*locDeltaTCut;
666 auto locMaxDeltaT = locIncludeDecayTimeOffset ? locDeltaTCut +
dMaxDecayTimeOffset : locDeltaTCut;
669 auto locNumShifts = locOrigNumShifts;
670 auto locDeltaT = locVertexTime - (locOrigRFBunchPropagatedTime + locNumShifts*
dBeamBunchPeriod);
672 cout <<
"num shifts, delta-t = " << locNumShifts <<
", " << locDeltaT << endl;
673 dAllRFDeltaTs[locPID][locSystem].push_back(std::make_pair(locP, locDeltaT));
674 while(((locDeltaT >= locMinDeltaT) && (locDeltaT < locMaxDeltaT)) || (locOrigNumShifts == locNumShifts))
676 if((locDeltaT >= locMinDeltaT) && (locDeltaT < locMaxDeltaT))
679 cout <<
"save shift: " << locNumShifts << endl;
680 locRFShifts.push_back(locNumShifts);
683 locDeltaT = locVertexTime - (locOrigRFBunchPropagatedTime + locNumShifts*
dBeamBunchPeriod);
685 cout <<
"num shifts, delta-t = " << locNumShifts <<
", " << locDeltaT << endl;
686 dAllRFDeltaTs[locPID][locSystem].push_back(std::make_pair(locP, locDeltaT));
690 locNumShifts = locOrigNumShifts - 1;
691 locDeltaT = locVertexTime - (locOrigRFBunchPropagatedTime + locNumShifts*
dBeamBunchPeriod);
693 cout <<
"num shifts, delta-t = " << locNumShifts <<
", " << locDeltaT << endl;
694 dAllRFDeltaTs[locPID][locSystem].push_back(std::make_pair(locP, locDeltaT));
695 while((locDeltaT >= locMinDeltaT) && (locDeltaT < locMaxDeltaT))
698 cout <<
"save shift: " << locNumShifts << endl;
699 locRFShifts.push_back(locNumShifts);
701 locDeltaT = locVertexTime - (locOrigRFBunchPropagatedTime + locNumShifts*
dBeamBunchPeriod);
703 cout <<
"num shifts, delta-t = " << locNumShifts <<
", " << locDeltaT << endl;
704 dAllRFDeltaTs[locPID][locSystem].push_back(std::make_pair(locP, locDeltaT));
707 std::sort(locRFShifts.begin(), locRFShifts.end());
716 auto locPathError = locR*(1.0/
sin(locTheta) -
sqrt(1.0 + pow(1.0/tan(locTheta) - locZError/locR, 2.0))) - locZError;
724 double locPathErrorTerm = 1.0/cos(locTheta) -
sqrt(pow(tan(locTheta), 2.0) + pow(1.0 - locMaxZError/(locDeltaZ - locMaxZError), 2.0));
725 double locPathError = (locDeltaZ - locMaxZError)*locPathErrorTerm - locMaxZError;
732 cout <<
"DSourceComboTimeHandler::Select_RFBunches_Charged()" << endl;
736 locValidRFBunches = locRFIterator->second.second;
738 cout <<
"Previously done, passed flag, # valid bunches = " << locRFIterator->second.first <<
", " << locValidRFBunches.size() << endl;
739 return locRFIterator->second.first;
748 locValidRFBunches.clear();
755 cout <<
"step: " << locStepVertexInfo->Get_StepIndices().front() << endl;
757 auto locIsProductionVertex = locStepVertexInfo->Get_ProductionVertexFlag();
761 cout <<
"PRIMARY VERTEX COMBO:" << endl;
768 auto locIsCombo2ndVertex = locStepVertexInfo->Get_FullConstrainParticles(
false,
d_FinalState,
d_Charged,
false).empty();
777 cout <<
"primary vertex z, targ z, init rf time, time offset, prop time = " << locPrimaryVertexZ <<
", " <<
dTargetCenter.Z() <<
", " <<
dInitialEventRFBunch->
dTime <<
", " << locTimeOffset <<
", " << locPropagatedRFTime << endl;
781 for(
const auto& locParticlePair : locChargedParticles)
783 auto locChargedHypo =
static_cast<const DChargedTrack*
>(locParticlePair.second)->Get_Hypothesis(locParticlePair.first);
784 vector<int> locParticleRFBunches;
785 if(!
Get_RFBunches_ChargedTrack(locChargedHypo, locIsProductionVertex, locVertexPrimaryCombo, locIsCombo2ndVertex, locVertex, locPropagatedRFTime, locOnlyTrackFlag, !locIsProductionVertex, locParticleRFBunches))
788 cout <<
"pid, has no timing info = " << locChargedHypo->PID() << endl;
792 cout <<
"pid, # valid bunches = " << locChargedHypo->PID() <<
", " << locParticleRFBunches.size() << endl;
794 if(locParticleRFBunches.empty())
802 cout <<
"#common bunches = " << locValidRFBunches.size() << endl;
803 if(locValidRFBunches.empty())
813 cout <<
"# valid bunches = " << locValidRFBunches.size() << endl;
820 cout <<
"Select_RFBunches_PhotonVertices()" << endl;
826 locValidRFBunches = locRFIterator->second.second;
827 return locRFIterator->second.first;
836 if(locStepVertexInfo->Get_DanglingVertexFlag())
839 auto locIsProductionVertex = locStepVertexInfo->Get_ProductionVertexFlag();
858 for(
const auto& locParticlePair : locSourceParticles)
860 auto locPID = locParticlePair.first;
861 vector<int> locParticleRFBunches;
866 auto locNeutralShower =
static_cast<const DNeutralShower*
>(locParticlePair.second);
874 locParticleRFBunches =
Calc_BeamBunchShifts(locVertexTime, locPropagatedRFTime, locDeltaTCut,
false,
Gamma, locSystem, locNeutralShower->dEnergy);
876 cout <<
"post-cut: pid, zbin, #bunches, #valid bunches = " << locPID <<
", " << int(locVertexZBin) <<
", " << locParticleRFBunches.size() <<
", " << locValidRFBunches.size() << endl;
880 locParticleRFBunches =
dShowerRFBunches[locVertexZBin][locParticlePair.second];
882 cout <<
"pre-cut: pointer, system, energy, pid, zbin, #bunches, #valid bunches = " << locParticlePair.second <<
", " << locSystem <<
", " << locNeutralShower->dEnergy <<
", " << locPID <<
", " << int(locVertexZBin) <<
", " << locParticleRFBunches.size() <<
", " << locValidRFBunches.size() << endl;
885 auto PhotonCutter = [&](
int locRFBunch) ->
bool {
return !
Cut_PhotonPID(locNeutralShower, locVertex, locPropagatedRFTime + locRFBunch*
dBeamBunchPeriod,
false, !locIsProductionVertex);};
886 locParticleRFBunches.erase(std::remove_if(locParticleRFBunches.begin(), locParticleRFBunches.end(), PhotonCutter), locParticleRFBunches.end());
888 cout <<
"post-cut: pid, zbin, #bunches = " << locPID <<
", " << int(locVertexZBin) <<
", " << locParticleRFBunches.size() << endl;
891 else if(locVertexDeterminableWithCharged)
895 auto locChargedHypo =
static_cast<const DChargedTrack*
>(locParticlePair.second)->Get_Hypothesis(locParticlePair.first);
896 if(!
Get_RFBunches_ChargedTrack(locChargedHypo, locIsProductionVertex, locVertexPrimaryFullCombo,
false, locVertex, locPropagatedRFTime, locOnlyTrackFlag, !locIsProductionVertex, locParticleRFBunches))
899 cout <<
"pid, has no timing info = " << locChargedHypo->PID() << endl;
904 if(locParticleRFBunches.empty())
909 if(locValidRFBunches.empty())
911 locValidRFBunches = locParticleRFBunches;
918 cout <<
"#common bunches = " << locValidRFBunches.size() << endl;
919 if(locValidRFBunches.empty())
934 cout <<
"DSourceComboTimeHandler::Select_RFBunches_AllVerticesUnknown()" << endl;
940 locValidRFBunches = locRFIterator->second.second;
941 return locRFIterator->second.first;
944 locValidRFBunches.clear();
950 for(
const auto& locParticlePair : locSourceParticles)
952 auto locPID = locParticlePair.first;
953 vector<int> locParticleRFBunches;
958 auto locNeutralShower =
static_cast<const DNeutralShower*
>(locParticlePair.second);
959 locParticleRFBunches =
dShowerRFBunches[locVertexZBin][locParticlePair.second];
961 cout <<
"pre-cut: pid, #bunches, #valid bunches = " << locPID <<
", " << locParticleRFBunches.size() <<
", " << locValidRFBunches.size() << endl;
965 locParticleRFBunches.erase(std::remove_if(locParticleRFBunches.begin(), locParticleRFBunches.end(), PhotonCutter), locParticleRFBunches.end());
967 cout <<
"post-cut: pid, #bunches, #valid bunches = " << locPID <<
", " << locParticleRFBunches.size() <<
", " << locValidRFBunches.size() << endl;
971 auto locChargedHypo =
static_cast<const DChargedTrack*
>(locParticlePair.second)->Get_Hypothesis(locParticlePair.first);
972 auto locVertex = locChargedHypo->position();
974 if(!
Get_RFBunches_ChargedTrack(locChargedHypo,
true,
nullptr,
false, locVertex, locPropagatedRFTime, locOnlyTrackFlag,
false, locParticleRFBunches))
977 cout <<
"pid, has no timing info = " << locChargedHypo->PID() << endl;
981 cout <<
"pid, # valid bunches = " << locChargedHypo->PID() <<
", " << locParticleRFBunches.size() << endl;
984 if(locParticleRFBunches.empty())
989 if(locValidRFBunches.empty())
991 locValidRFBunches = locParticleRFBunches;
998 cout <<
"#common bunches = " << locValidRFBunches.size() << endl;
999 if(locValidRFBunches.empty())
1007 cout <<
"# valid bunches = " << locValidRFBunches.size() << endl;
1017 cout <<
"DSourceComboTimeHandler::Select_RFBunch_Full()" << endl;
1023 cout <<
"bunch previously determined: " << locRFIterator->second << endl;
1024 return locRFIterator->second;
1028 if(locRFBunches.empty())
1032 unordered_map<int, double> locChiSqByRFBunch;
1033 for(
const auto& locRFBunch : locRFBunches)
1034 locChiSqByRFBunch.emplace(locRFBunch, 0.0);
1040 bool locVotedFlag =
false;
1046 cout <<
"primary vertex z: " << locPrimaryVertexZ << endl;
1047 map<int, map<Particle_t, map<DetectorSystem_t, vector<pair<float, float>>>>> locRFDeltaTsForHisting;
1051 cout <<
"Step: " << locStepVertexInfo->Get_StepIndices().front() << endl;
1053 if(locStepVertexInfo->Get_DanglingVertexFlag())
1056 auto locIsProductionVertex = locStepVertexInfo->Get_ProductionVertexFlag();
1068 cout <<
"this vertex z, time offset: " << locVertex.Z() <<
", " << locTimeOffset << endl;
1070 for(
const auto& locRFBunch : locRFBunches)
1075 cout <<
"bunch, propagated time: " << locRFBunch <<
", " << locPropagatedRFTime << endl;
1078 for(
const auto& locParticlePair : locParticles)
1080 auto locPID = locParticlePair.first;
1084 locVotedFlag =
true;
1087 auto locNeutralShower =
static_cast<const DNeutralShower*
>(locParticlePair.second);
1088 auto locRFDeltaTPair =
Calc_RFDeltaTChiSq(locNeutralShower, locVertex, locPropagatedRFTime);
1089 locChiSqByRFBunch[locRFBunch] += locRFDeltaTPair.second;
1090 locRFDeltaTsForHisting[locRFBunch][locPID][locNeutralShower->dDetectorSystem].emplace_back(locNeutralShower->dEnergy, locRFDeltaTPair.first);
1094 auto locChargedHypo =
static_cast<const DChargedTrack*
>(locParticlePair.second)->Get_Hypothesis(locParticlePair.first);
1099 auto locRFDeltaTPair =
Calc_RFDeltaTChiSq(locChargedHypo, locVertexTime, locPropagatedRFTime);
1100 locChiSqByRFBunch[locRFBunch] += locRFDeltaTPair.second;
1101 locRFDeltaTsForHisting[locRFBunch][locPID][locChargedHypo->t1_detector()].emplace_back(locChargedHypo->momentum().Mag(), locRFDeltaTPair.first);
1105 cout <<
"bunch, total delta-t chisq = " << locRFBunch <<
", " << locChiSqByRFBunch[locRFBunch] << endl;
1118 auto Compare_RFChiSqs = [](
const pair<int, double>& lhs,
const pair<int, double>& rhs) ->
bool {
return lhs.second < rhs.second;};
1119 auto locRFBunch = std::max_element(locChiSqByRFBunch.begin(), locChiSqByRFBunch.end(), Compare_RFChiSqs)->first;
1122 cout <<
"chosen bunch: " << locRFBunch << endl;
1125 for(
auto& locPIDPair : locRFDeltaTsForHisting[locRFBunch])
1127 for(
auto& locSystemPair : locPIDPair.second)
1130 auto& locMoveFromVector = locSystemPair.second;
1131 std::move(locMoveFromVector.begin(), locMoveFromVector.end(), std::back_inserter(locSaveToVector));
1142 map<int, pair<size_t, double>> locOldMethodVoting;
1146 cout <<
"Vote_OldMethod()" << endl;
1152 for(
const auto& locParticlePair : locParticles)
1154 auto locPID = locParticlePair.first;
1158 vector<int> locParticleRFBunches;
1159 double locVertexTime = 0.0, locPropagatedRFTime = 0.0;
1162 auto locNeutralShower =
static_cast<const DNeutralShower*
>(locParticlePair.second);
1169 auto locHypothesis =
static_cast<const DChargedTrack*
>(locParticlePair.second)->Get_Hypothesis(locParticlePair.first);
1170 auto locP = locHypothesis->momentum().Mag();
1171 if(locHypothesis->t1_detector() ==
SYS_NULL)
1175 locVertexTime = locHypothesis->time();
1177 if((locHypothesis->t1_detector() !=
SYS_TOF) && (locHypothesis->Get_SCHitMatchParams() !=
nullptr))
1180 locVertexTime = locHypothesis->Get_SCHitMatchParams()->dHitTime - locHypothesis->Get_SCHitMatchParams()->dFlightTime;
1187 cout <<
"OldMethod: PID, t1, sc, position, prop-rf-time, vertex-time, #bunches, bunches: " << locHypothesis->PID() <<
", " << locHypothesis->t1_detector() <<
", " << locHypothesis->Get_SCHitMatchParams() <<
", " << locHypothesis->position().Z() <<
", " << locPropagatedRFTime <<
", " << locVertexTime <<
", " << locParticleRFBunches.size();
1188 for(
auto& locBunch : locParticleRFBunches)
1189 cout <<
", " << locBunch;
1194 for(
auto& locRFBunch : locParticleRFBunches)
1196 double locDeltaT = locVertexTime - (locPropagatedRFTime +
dBeamBunchPeriod*locRFBunch);
1197 auto locIterator = locOldMethodVoting.find(locRFBunch);
1198 if(locIterator == locOldMethodVoting.end())
1199 locOldMethodVoting.emplace(locRFBunch, pair<size_t, double>(1, locDeltaT*locDeltaT));
1202 ++(locIterator->second.first);
1203 locIterator->second.second += locDeltaT*locDeltaT;
1208 int locChosenBunch = 0;
1209 size_t locMostVotes = 0;
1210 double locBestDeltaTSq = 9999999.9;
1211 for(
auto& locVotes : locOldMethodVoting)
1214 cout <<
"bunch, #votes: " << locVotes.first <<
", " << locVotes.second.first << endl;
1215 if(locVotes.second.first > locMostVotes)
1217 locChosenBunch = locVotes.first;
1218 locMostVotes = locVotes.second.first;
1219 locBestDeltaTSq = locVotes.second.second;
1221 else if(locVotes.second.first == locMostVotes)
1223 if(locVotes.second.second < locBestDeltaTSq)
1225 locChosenBunch = locVotes.first;
1226 locBestDeltaTSq = locVotes.second.second;
1231 cout <<
"chosen bunch = " << locChosenBunch << endl;
1233 vector<int> locBestVector{locChosenBunch};
1234 if(locValidRFBunches.empty())
1236 locValidRFBunches = locBestVector;
1239 vector<int> locCommonRFBunches = {};
1240 std::set_intersection(locBestVector.begin(), locBestVector.end(), locValidRFBunches.begin(), locValidRFBunches.end(), std::back_inserter(locCommonRFBunches));
1241 locValidRFBunches = locCommonRFBunches;
1248 bool locVotedFlag =
false;
1249 for(
const auto& locRFBunch : locRFBunches)
1252 for(
const auto& locParticlePair : locSourceParticles)
1254 auto locPID = locParticlePair.first;
1258 locVotedFlag =
true;
1261 auto locNeutralShower =
static_cast<const DNeutralShower*
>(locParticlePair.second);
1264 locChiSqByRFBunch[locRFBunch] += locRFDeltaTPair.second;
1265 locRFDeltaTsForHisting[locRFBunch][locPID][locNeutralShower->dDetectorSystem].emplace_back(locNeutralShower->dEnergy, locRFDeltaTPair.first);
1269 auto locChargedHypo =
static_cast<const DChargedTrack*
>(locParticlePair.second)->Get_Hypothesis(locParticlePair.first);
1271 auto locRFDeltaTPair =
Calc_RFDeltaTChiSq(locChargedHypo, locChargedHypo->time(), locPropagatedRFTime);
1272 locChiSqByRFBunch[locRFBunch] += locRFDeltaTPair.second;
1273 locRFDeltaTsForHisting[locRFBunch][locPID][locChargedHypo->t1_detector()].emplace_back(locChargedHypo->momentum().Mag(), locRFDeltaTPair.first);
1277 cout <<
"bunch, total delta-t chisq = " << locRFBunch <<
", " << locChiSqByRFBunch[locRFBunch] << endl;
1279 return locVotedFlag;
1285 cout <<
"DSourceComboTimeHandler::Cut_Timing_MissingMassVertices()" << endl;
1297 cout <<
"Step: " << locStepVertexInfo->Get_StepIndices().front() <<
", dangling-flag = " << locStepVertexInfo->Get_DanglingVertexFlag() << endl;
1307 auto locIsProductionVertex = locStepVertexInfo->Get_ProductionVertexFlag();
1318 for(
const auto& locParticlePair : locSourceParticles)
1320 auto locPID = locParticlePair.first;
1325 auto locNeutralShower =
static_cast<const DNeutralShower*
>(locParticlePair.second);
1328 if(!
Cut_PhotonPID(locNeutralShower, locVertex, locPropagatedRFTime,
false, !locIsProductionVertex))
1333 auto locChargedHypo =
static_cast<const DChargedTrack*
>(locParticlePair.second)->Get_Hypothesis(locParticlePair.first);
1334 if(!
Cut_TrackPID(locChargedHypo, locIsProductionVertex, locReactionFullCombo, locVertexPrimaryFullCombo, locBeamParticle,
false, locVertex, locPropagatedRFTime, !locIsProductionVertex))
1345 japp->WriteLock(
"DSourceComboTimeHandler");
1355 for(
auto& locSystemPair : locPIDPair.second)
1357 auto locSystemIterator = locPIDIterator->second.find(locSystemPair.first);
1358 if(locSystemIterator == locPIDIterator->second.end())
1361 auto& locBestHist = locSystemIterator->second;
1362 for(
auto& locVectorPair : locSystemPair.second)
1363 locBestHist->Fill(locVectorPair.first, locVectorPair.second);
1372 for(
auto& locSystemPair : locPIDPair.second)
1374 auto locSystemIterator = locPIDIterator->second.find(locSystemPair.first);
1375 if(locSystemIterator == locPIDIterator->second.end())
1378 auto& locAllHist = locSystemIterator->second;
1379 for(
auto& locVectorPair : locSystemPair.second)
1380 locAllHist->Fill(locVectorPair.first, locVectorPair.second);
1384 japp->Unlock(
"DSourceComboTimeHandler");
1390 for(
auto& locSystemPair : locPIDPair.second)
1391 decltype(locSystemPair.second)().swap(locSystemPair.second);
1395 for(
auto& locSystemPair : locPIDPair.second)
1396 decltype(locSystemPair.second)().swap(locSystemPair.second);
1402 locRFBunches.clear();
1403 auto locPID = locHypothesis->
PID();
1409 if((locSystem ==
SYS_START) && !locOnlyTrackFlag)
1412 vector<shared_ptr<const DSCHitMatchParams>> locSCMatchParams;
1414 if(locSCMatchParams.size() > 1)
1418 auto locX4 =
Get_ChargedPOCAToVertexX4(locHypothesis, locIsProductionVertex,
nullptr, locVertexPrimaryCombo,
nullptr, locIsCombo2ndVertex, locVertex);
1419 auto locVertexTime = locX4.T();
1421 auto locP = locHypothesis->
momentum().Mag();
1423 auto locDeltaTCut = (locCutFunc !=
nullptr) ? locCutFunc->Eval(locP) : 3.0;
1424 if(locDetachedVertex)
1429 locVertexTime = locHypothesis->
time();
1432 cout <<
"charged track z, new track vert time, new prop rf time: " << locHypothesis->
position().Z() <<
", " << locVertexTime <<
", " << locPropagatedRFTime << endl;
1435 locRFBunches =
Calc_BeamBunchShifts(locVertexTime, locPropagatedRFTime, locDeltaTCut,
false, locPID, locSystem, locP);
1436 return (locCutFunc !=
nullptr);
1442 auto locX4(locHypothesis->
x4());
1443 if(locVertexPrimaryCombo ==
nullptr)
1450 return locPOCAIterator->second;
1464 if(locCutFunc ==
nullptr)
1469 auto locDeltaTCut = locCutFunc->Eval(locNeutralShower->
dEnergy);
1470 if(locDetachedVertex)
1474 auto locDeltaT = locKinematicsPair.second - locPropagatedRFTime;
1476 cout <<
"photon pid cut: pointer, system, vertex-z, photon t, rf t, delta_t, cut-delta-t, result = " << locNeutralShower <<
", " << locSystem <<
", " << locVertex.Z() <<
", " << locKinematicsPair.second <<
", " << locPropagatedRFTime <<
", " << locDeltaT <<
", " << locDeltaTCut <<
", " << (fabs(locDeltaT) <= locDeltaTCut) << endl;
1477 if(locTargetCenterFlag)
1479 return (fabs(locDeltaT) <= locDeltaTCut);
1485 auto locPID = locHypothesis->
PID();
1488 if(locCutFunc ==
nullptr)
1491 auto locP = locHypothesis->
momentum().Mag();
1492 auto locDeltaTCut = locCutFunc->Eval(locP);
1493 if(locDetachedVertex)
1500 vector<shared_ptr<const DSCHitMatchParams>> locSCMatchParams;
1502 if(locSCMatchParams.size() > 1)
1506 auto locX4 =
Get_ChargedPOCAToVertexX4(locHypothesis, locIsProductionVertex, locFullReactionCombo, locVertexPrimaryCombo, locBeamPhoton, locIsCombo2ndVertex, locVertex);
1507 auto locDeltaT = locX4.T() - locPropagatedRFTime;
1511 auto locVertexTime = locHypothesis->
time();
1513 locDeltaT = locVertexTime - locPropagatedRFTime;
1515 cout <<
"charged track z, new track vert time, new prop rf time: " << locHypothesis->
position().Z() <<
", " << locVertexTime <<
", " << locPropagatedRFTime << endl;
1520 cout <<
"track pid cut: pid, pointer, system, vertex-z, track t, rf t, delta_t, cut-delta-t, result = " << locPID <<
", " << locHypothesis <<
", " << locSystem <<
", " << locVertex.Z() <<
", " << locX4.T() <<
", " << locPropagatedRFTime <<
", " << locDeltaT <<
", " << locDeltaTCut <<
", " << (fabs(locDeltaT) <= locDeltaTCut) << endl;
1522 return (fabs(locDeltaT) <= locDeltaTCut);
void Create_CutFunctions(void)
bool Compute_RFChiSqs_UnknownVertices(const DSourceCombo *locReactionFullCombo, Charge_t locCharge, const vector< int > &locRFBunches, unordered_map< int, double > &locChiSqByRFBunch, map< int, map< Particle_t, map< DetectorSystem_t, vector< pair< float, float >>>>> &locRFDeltaTsForHisting)
bool Select_RFBunches_PhotonVertices(const DReactionVertexInfo *locReactionVertexInfo, const DSourceCombo *locReactionFullCombo, vector< int > &locValidRFBunches)
bool Get_VertexDeterminableWithPhotons(const DReactionStepVertexInfo *locStepVertexInfo) const
unordered_map< const DSourceCombo *, pair< bool, vector< int > > > dUnknownVertexRFBunches
signed char Get_VertexZBin_NoBeam(bool locIsProductionVertex, const DSourceCombo *locPrimaryVertexCombo, bool locIsCombo2ndVertex) const
int Select_RFBunch_Full(const DReactionVertexInfo *locReactionVertexInfo, const DSourceCombo *locReactionFullCombo, const vector< int > &locRFBunches)
static char * ParticleName_ROOT(Particle_t p)
double Get_TimeOffset(bool locIsPrimaryProductionVertex, const DSourceCombo *locReactionCombo, const DSourceCombo *locVertexCombo, const DKinematicData *locBeamParticle) const
vector< int > Get_CommonRFBunches(const vector< int > &locRFBunches1, const JObject *locObject, signed char locVertexZBin) const
void Setup(const vector< const DNeutralShower * > &locNeutralShowers, const DEventRFBunch *locInitialEventRFBunch, const DDetectorMatches *locDetectorMatches)
bool Get_RFBunches_ChargedTrack(const DChargedTrackHypothesis *locHypothesis, bool locIsProductionVertex, const DSourceCombo *locVertexPrimaryCombo, bool locIsCombo2ndVertex, DVector3 locVertex, double locPropagatedRFTime, bool locOnlyTrackFlag, bool locDetachedVertex, vector< int > &locRFBunches)
bool Get_SCMatchParams(const DTrackingData *locTrack, vector< shared_ptr< const DSCHitMatchParams > > &locMatchParams) const
DLorentzVector Get_ChargedPOCAToVertexX4(const DChargedTrackHypothesis *locHypothesis, bool locIsProductionVertex, const DSourceCombo *locReactionFullCombo, const DSourceCombo *locVertexPrimaryCombo, const DKinematicData *locBeamPhoton, bool locIsCombo2ndVertex, DVector3 locVertex)
double Calc_MaxDeltaTError(const DNeutralShower *locNeutralShower, double locTheta) const
vector< const DReaction * > Get_Reactions(JEventLoop *locEventLoop)
map< pair< const DKinematicData *, vector< const DKinematicData * > >, DLorentzVector > dChargedParticlePOCAToVertexX4
const DReactionStepVertexInfo * Get_StepVertexInfo(size_t locStepIndex) const
void Define_DefaultCuts(void)
pair< double, double > Calc_RFDeltaTChiSq(const DNeutralShower *locNeutralShower, const TVector3 &locVertex, double locPropagatedRFTime) const
const DVector3 & position(void) const
vector< const DKinematicData * > Get_ConstrainingParticles_NoBeam(bool locIsProductionVertex, const DSourceCombo *locVertexCombo, bool locIsCombo2ndVertex) const
map< Particle_t, map< DetectorSystem_t, vector< pair< float, float > > > > dAllRFDeltaTs
const DTrackTimeBased * Get_TrackTimeBased(void) const
TH2 * dHist_BeamRFDeltaTVsBeamE
bool Get_VertexDeterminableWithCharged(const DReactionStepVertexInfo *locStepVertexInfo) const
static signed char Get_VertexZIndex_OutOfRange(void)
unordered_map< signed char, unordered_map< const JObject *, vector< int > > > dShowerRFBunches
static unsigned short int IsDetachedVertex(Particle_t p)
bool Get_ProductionVertexFlag(void) const
static char * ParticleType(Particle_t p)
shared_ptr< const DKinematicData > Create_KinematicData_Photon(const DNeutralShower *locNeutralShower, const DVector3 &locVertex) const
DVector3 Get_Vertex(bool locIsProductionVertex, const DSourceCombo *locReactionCombo, const DSourceCombo *locVertexCombo, const DKinematicData *locBeamParticle, bool locIsCombo2ndVertex) const
bool Cut_PhotonPID(const DNeutralShower *locNeutralShower, const DVector3 &locVertex, double locPropagatedRFTime, bool locTargetCenterFlag, bool locDetachedVertex)
DLorentzVector x4(void) const
int Calc_RFBunchShift(double locTimeToStepTo) const
void Get_CommandLineCuts(void)
static signed char Get_VertexZIndex_Unknown(void)
TLorentzVector DLorentzVector
DVector3 Get_PrimaryVertex(const DReactionVertexInfo *locReactionVertexInfo, const DSourceCombo *locReactionCombo, const DKinematicData *locBeamParticle) const
double Get_PhotonVertexZBinCenter(signed char locVertexZBin) const
map< Particle_t, map< DetectorSystem_t, TH2 * > > dHistMap_RFDeltaTVsP_AllRFs
static int ParticleCharge(Particle_t p)
static signed char Get_VertexZIndex_ZIndependent(void)
map< Particle_t, map< DetectorSystem_t, vector< pair< float, float > > > > dSelectedRFDeltaTs
map< Particle_t, map< DetectorSystem_t, vector< double > > > dPIDTimingCuts_TF1Params
const DEventRFBunch * dInitialEventRFBunch
vector< Particle_t > Get_ChainPIDs(const DReaction *locReaction, size_t locStepIndex, int locUpToStepIndex, vector< Particle_t > locUpThroughPIDs, bool locExpandDecayingFlag, bool locExcludeMissingFlag)
DetectorSystem_t dDetectorSystem
DLorentzVector dSpacetimeVertex
pair< DVector3, double > Calc_Photon_Kinematics(const DNeutralShower *locNeutralShower, const DVector3 &locVertex) const
vector< pair< Particle_t, const JObject * > > Get_SourceParticles(bool locEntireChainFlag=false, Charge_t locCharge=d_AllCharges) const
float dPhotonVertexZBinWidth
void Vote_OldMethod(const DSourceCombo *locReactionFullCombo, vector< int > &locValidRFBunches)
bool Get_IsTimeOffsetKnown(bool locIsPrimaryProductionVertex, const DSourceCombo *locReactionCombo, const DSourceCombo *locVertexCombo, const DKinematicData *locBeamParticle) const
void Calc_PhotonBeamBunchShifts(const DNeutralShower *locNeutralShower, shared_ptr< const DKinematicData > &locKinematicData, double locRFTime, signed char locZBin)
DGeometry * GetDGeometry(unsigned int run_number)
bool Cut_Timing_MissingMassVertices(const DReactionVertexInfo *locReactionVertexInfo, const DSourceCombo *locReactionFullCombo, const DKinematicData *locBeamParticle, int locRFBunch)
string dDefaultTimeCutFunctionString
bool Cut_TrackPID(const DChargedTrackHypothesis *locHypothesis, bool locIsProductionVertex, const DSourceCombo *locFullReactionCombo, const DSourceCombo *locVertexPrimaryCombo, const DKinematicData *locBeamPhoton, bool locIsCombo2ndVertex, DVector3 locVertex, double locPropagatedRFTime, bool locDetachedVertex)
const DDetectorMatches * dDetectorMatches
double charge(void) const
bool Select_RFBunches_Charged(const DReactionVertexInfo *locReactionVertexInfo, const DSourceCombo *locChargedCombo, vector< int > &locValidRFBunches)
const char * SystemName(DetectorSystem_t sys)
bool Select_RFBunches_AllVerticesUnknown(const DReactionVertexInfo *locReactionVertexInfo, const DSourceCombo *locReactionFullCombo, Charge_t locCharge, vector< int > &locValidRFBunches)
DLorentzVector lorentzMomentum(void) const
map< Particle_t, map< DetectorSystem_t, string > > dPIDTimingCuts_TF1FunctionString
static double ParticleMass(Particle_t p)
vector< const DReactionStepVertexInfo * > Get_StepVertexInfos(void) const
const DSourceCombo * Get_VertexPrimaryCombo(const DSourceCombo *locReactionCombo, const DReactionStepVertexInfo *locStepVertexInfo) const
TF1 * Get_TimeCutFunction(Particle_t locPID, DetectorSystem_t locSystem) const
size_t Get_VertexZBin_TargetCenter(void) const
void Fill_Histograms(void)
double dChargedDecayProductTimeUncertainty
vector< const DKinematicData * > Get_ConstrainingParticles(bool locIsProductionVertex, const DSourceCombo *locReactionCombo, const DSourceCombo *locVertexCombo, const DKinematicData *locBeamParticle, bool locIsCombo2ndVertex) const
const DVector3 & momentum(void) const
double Propagate_Track(int locCharge, const DVector3 &locPropagateToPoint, DLorentzVector &locMeasuredX4, DLorentzVector &locMeasuredP4, TMatrixFSym *locCovarianceMatrix) const
map< Particle_t, map< DetectorSystem_t, TF1 * > > dPIDTimingCuts
unordered_map< signed char, DPhotonShowersByBeamBunch > dShowersByBeamBunchByZBin
unordered_map< const DSourceCombo *, pair< bool, vector< int > > > dPhotonVertexRFBunches
DSourceComboer * dSourceComboer
vector< pair< Particle_t, const JObject * > > Get_SourceParticles_ThisVertex(const DSourceCombo *locSourceCombo, Charge_t locCharge=d_AllCharges)
DVector3 Get_Vertex_NoBeam(bool locIsProductionVertex, const DSourceCombo *locVertexCombo, bool locIsCombo2ndVertex) const
double dMaxDecayTimeOffset
bool Get_IsVertexKnown_NoBeam(bool locIsProductionVertex, const DSourceCombo *locVertexCombo, bool locIsCombo2ndVertex) const
const DSourceComboVertexer * dSourceComboVertexer
unordered_map< const DSourceCombo *, pair< bool, vector< int > > > dChargedComboRFBunches
unordered_map< const DSourceCombo *, int > dFullComboRFBunches
vector< int > Calc_BeamBunchShifts(double locVertexTime, double locOrigRFBunchPropagatedTime, double locDeltaTCut, bool locIncludeDecayTimeOffset, Particle_t locPID, DetectorSystem_t locSystem, double locP)
bool GetTargetLength(double &target_length) const
z-location of center of target
float dPhotonVertexZRangeLow
DPhotonKinematicsByZBin dPhotonKinematics
DetectorSystem_t t1_detector(void) const
bool GetTargetZ(double &z_target) const
z-location of center of target
double Calc_PropagatedRFTime(double locPrimaryVertexZ, int locNumRFBunchShifts, double locDetachedVertexTimeOffset) const
double dDetachedPathLengthUncertainty
Particle_t PID(void) const
const DAnalysisUtilities * dAnalysisUtilities
vector< pair< float, float > > dBeamRFDeltaTs
map< Particle_t, map< DetectorSystem_t, TH2 * > > dHistMap_RFDeltaTVsP_BestRF
DSourceComboTimeHandler(void)=delete
void Print_SourceCombo(const DSourceCombo *locCombo, unsigned char locNumTabs=0)
size_t dNumPhotonVertexZBins