Skip to content

Commit

Permalink
Update to Vertex Reconstruction (#226)
Browse files Browse the repository at this point in the history
* Update to Vertex Reconstruction, including new FineGrid search and mean time selection

* False Commit to enable checkout; please ignore.

* Edited recent vertex reconstruction updates for better mesh with TA code
Removed redundant GenerateFineGrid function in VtxSeedGenerator
Removed experimental penalty term calculation in FoMCalculator

* Fixed small typo in VtxSeedGenerator.cpp

* Fixes to VtxSeedFineGrid.  Added new PDF charge fitter to FoMCalculator, and handling in VtxExtendedVertexFinder and MinuitOptimizer.  This change is experimental, but should only trigger with appropriate config variables.

* bug fixes to recent update

* Fixes to VtxExtendedVertexFinder, and further progress in experimental charge fit.

* Incremental update on pdf charge fit.  Updated to chi2 definition.

* Charge fit update for LikelihoodCheck tool, along with a debug ability to vary 2D angle instead of position

* Further debug update of charge fit addition to FoMCalculator

* Bringing up to date with new charge fitter fixes.  Added VGCheck-pdfcharge.root, which is the file containing pdf plot for use within new charge fitter.
  • Loading branch information
flemmons authored Feb 16, 2024
1 parent 426b7cb commit b2c650b
Show file tree
Hide file tree
Showing 25 changed files with 1,767 additions and 559 deletions.
1,181 changes: 652 additions & 529 deletions DataModel/FoMCalculator.cpp
100644 → 100755

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion DataModel/FoMCalculator.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************
> File Name: MinuitOptimizer.hh
> File Name: FoMCalculator.hh
> Author: Jingbo Wang, Teal Pershing
> mail: [email protected], [email protected]
> Created Time: MAY 07, 2019
Expand Down Expand Up @@ -50,6 +50,7 @@ class FoMCalculator {
double FindSimpleTimeProperties(double myConeEdge);
void TimePropertiesLnL(double vtxTime, double& vtxFom);
void ConePropertiesFoM(double coneEdge, double& chi2);
void ConePropertiesLnL(double vtxX, double vtxY, double VtxZ, double dirX, double dirY, double dirZ, double coneEdge, double& chi2, TH1D angularDist, double& phimax, double& phimin);
void PointPositionChi2(double vtxX, double vtxY, double vtxZ, double vtxTime, double& fom);
void PointDirectionChi2(double vtxX, double vtxY, double vtxZ, double dirX, double dirY, double dirZ, double coneAngle, double& fom);
void PointVertexChi2(double vtxX, double vtxY, double vtxZ,
Expand All @@ -58,6 +59,9 @@ class FoMCalculator {
void ExtendedVertexChi2(double vtxX, double vtxY, double vtxZ,
double dirX, double dirY, double dirZ,
double coneAngle, double vtxTime, double& fom);
void ExtendedVertexChi2(double vtxX, double vtxY, double vtxZ,
double dirX, double dirY, double dirZ,
double coneAngle, double vtxTime, double& fom, TH1D pdf);
// void ConePropertiesLnL(double coneParam0, double coneParam1, double coneParam2, double& coneAngle, double& coneFOM);
// void CorrectedVertexChi2(double vtxX, double vtxY, double vtxZ,
// double dirX, double dirY, double dirZ,
Expand Down
149 changes: 149 additions & 0 deletions DataModel/MinuitOptimizer.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,155 @@ void MinuitOptimizer::FitExtendedVertexWithMinuit() {
return;
}

void MinuitOptimizer::FitExtendedVertexWithMinuit(TH1D pdf) {
// seed vertex
// ===========
bool foundSeed = (fSeedVtx->FoundVertex()
&& fSeedVtx->FoundDirection());


double seedTime = fSeedVtx->GetTime();
double seedX = fSeedVtx->GetPosition().X();
double seedY = fSeedVtx->GetPosition().Y();
double seedZ = fSeedVtx->GetPosition().Z();

double seedDirX = fSeedVtx->GetDirection().X();
double seedDirY = fSeedVtx->GetDirection().Y();
double seedDirZ = fSeedVtx->GetDirection().Z();

double seedTheta = acos(seedDirZ);
double seedPhi = 0.0;

//modified by JW
if (seedDirX > 0.0) {
seedPhi = atan(seedDirY / seedDirX);
}
if (seedDirX < 0.0) {
seedPhi = atan(seedDirY / seedDirX);
if (seedDirY > 0.0) seedPhi += TMath::Pi();
if (seedDirY <= 0.0) seedPhi -= TMath::Pi();
}
if (seedDirX == 0.0) {
if (seedDirY > 0.0) seedPhi = 0.5 * TMath::Pi();
else if (seedDirY < 0.0) seedPhi = -0.5 * TMath::Pi();
else seedPhi = 0.0;
}
// current status
// ==============
int status = fSeedVtx->GetStatus();

// reset counter
// =============
extended_vertex_reset_itr();

// abort if necessary
// ==================
if (foundSeed == 0) {
if (fPrintLevel >= 0) {
std::cout << " <warning> extended vertex fit failed to find input vertex " << std::endl;
}
status |= RecoVertex::kFailExtendedVertex;
fFittedVtx->SetStatus(status);
return;
}

// run Minuit
// ==========
// six-parameter fit to vertex position, time and direction

int err = 0;
int flag = 0;

double fitXpos = 0.0;
double fitYpos = 0.0;
double fitZpos = 0.0;
double fitTheta = 0.0;
double fitPhi = 0.0;
double fitTime = 0.0;

double fitTimeErr = 0.0;
double fitXposErr = 0.0;
double fitYposErr = 0.0;
double fitZposErr = 0.0;
double fitThetaErr = 0.0;
double fitPhiErr = 0.0;

double* arglist = new double[10];
arglist[0] = 2; // 1: standard minimization
// 2: try to improve minimum

// re-initialize everything...
fMinuitExtendedVertex->mncler();
fMinuitExtendedVertex->SetFCN(extended_vertex_chi2);
fMinuitExtendedVertex->mnset();
fMinuitExtendedVertex->mnexcm("SET STR", arglist, 1, err);
fMinuitExtendedVertex->mnparm(0, "x", seedX, 1.0, fXmin, fXmax, err);
fMinuitExtendedVertex->mnparm(1, "y", seedY, 1.0, fYmin, fYmax, err);
fMinuitExtendedVertex->mnparm(2, "z", seedZ, 5.0, fZmin, fZmax, err);
fMinuitExtendedVertex->mnparm(3, "theta", seedTheta, 0.125 * TMath::Pi(), -1.0 * TMath::Pi(), 2.0 * TMath::Pi(), err);
fMinuitExtendedVertex->mnparm(4, "phi", seedPhi, 0.125 * TMath::Pi(), -2.0 * TMath::Pi(), 2.0 * TMath::Pi(), err);
fMinuitExtendedVertex->mnparm(5, "vtxTime", seedTime, 1.0, fTmin, fTmax, err); //....TX

flag = fMinuitExtendedVertex->Migrad();

fMinuitExtendedVertex->GetParameter(0, fitXpos, fitXposErr);
fMinuitExtendedVertex->GetParameter(1, fitYpos, fitYposErr);
fMinuitExtendedVertex->GetParameter(2, fitZpos, fitZposErr);
fMinuitExtendedVertex->GetParameter(3, fitTheta, fitThetaErr);
fMinuitExtendedVertex->GetParameter(4, fitPhi, fitPhiErr);
fMinuitExtendedVertex->GetParameter(5, fitTime, fitTimeErr);

delete[] arglist;

//correct angles, JW
if (fitTheta < 0.0) fitTheta = -1.0 * fitTheta;
if (fitTheta > TMath::Pi()) fitTheta = 2.0 * TMath::Pi() - fitTheta;
if (fitPhi < -1.0 * TMath::Pi()) fitPhi += 2.0 * TMath::Pi();
if (fitPhi > TMath::Pi()) fitPhi -= 2.0 * TMath::Pi();

// sort results
// ============
fVtxX = fitXpos;
fVtxY = fitYpos;
fVtxZ = fitZpos;
fVtxTime = fitTime;
fDirX = sin(fitTheta) * cos(fitPhi);
fDirY = sin(fitTheta) * sin(fitPhi);
fDirZ = cos(fitTheta);

fVtxFOM = -9999.0;

fPass = 0; // flag = 0: normal termination
if (flag == 0) fPass = 1; // anything else: abnormal termination

fItr = extended_vertex_iterations();

// fit complete; calculate fit results
// ================
fgFoMCalculator->ExtendedVertexChi2(fVtxX, fVtxY, fVtxZ,
fDirX, fDirY, fDirZ,
fConeAngle, fVtxTime, fVtxFOM, pdf);

// set vertex and direction
// ========================
fFittedVtx->SetVertex(fVtxX, fVtxY, fVtxZ, fVtxTime);
fFittedVtx->SetDirection(fDirX, fDirY, fDirZ);
fFittedVtx->SetConeAngle(fConeAngle);
fFittedVtx->SetFOM(fVtxFOM, fItr, fPass);

// set status
// ==========
bool inside_det = ANNIEGeometry::Instance()->InsideDetector(fVtxX, fVtxY, fVtxZ);
if (!fPass || !inside_det) status |= RecoVertex::kFailExtendedVertex;
fFittedVtx->SetStatus(status);
if (fPrintLevel >= 0) {
if (!fPass) std::cout << " <warning> extended vertex fit failed to converge! Error code: " << flag << std::endl;
}
// return vertex
// =============
return;
}


//KEPT FOR HISTORY, BUT FITTER IS CURRENTLY NOT WORKING
//THESE SHOULD BE MOVED TO BEFORE THE CONSTRUCTOR
Expand Down
1 change: 1 addition & 0 deletions DataModel/MinuitOptimizer.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class MinuitOptimizer {
void FitPointDirectionWithMinuit();
void FitPointVertexWithMinuit();
void FitExtendedVertexWithMinuit();
void FitExtendedVertexWithMinuit(TH1D pdf);

double GetTime() {return fVtxTime;}
double GetFOM() {return fVtxFOM;}
Expand Down
2 changes: 2 additions & 0 deletions UserTools/Factory/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ if (tool=="checkLAPPDStatus") ret=new checkLAPPDStatus;
if (tool=="GetLAPPDEvents") ret=new GetLAPPDEvents;
if (tool=="LAPPDDataDecoder") ret=new LAPPDDataDecoder;
if (tool=="PythonScript") ret=new PythonScript;
if (tool=="MeanTimeCheck") ret=new MeanTimeCheck;
if (tool=="ReweightEventsGenie") ret=new ReweightEventsGenie;
if (tool=="FilterLAPPDEvents") ret=new FilterLAPPDEvents;
if (tool=="VtxSeedFineGrid") ret=new VtxSeedFineGrid;
if (tool=="FilterEvents") ret=new FilterEvents;
if (tool=="Stage1DataBuilder") ret=new Stage1DataBuilder;
if (tool=="BeamFetcherV2") ret=new BeamFetcherV2;
Expand Down
Loading

0 comments on commit b2c650b

Please sign in to comment.