Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12_5_X] Fix try/catch in Vx3DHLTAnalyzer #39340

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
143 changes: 80 additions & 63 deletions DQM/BeamMonitor/plugins/Vx3DHLTAnalyzer.cc
Expand Up @@ -265,16 +265,17 @@ double Vx3DHLTAnalyzer::Gauss3DFunc(const double* par) {
}

int Vx3DHLTAnalyzer::MyFit(vector<double>* vals) {
// ############################################
// # RETURN CODE: #
// # >0 == NO OK - fit status (MINUIT manual) #
// # 0 == OK #
// # -1 == NO OK - not finite edm #
// # -2 == NO OK - not enough "minNentries" #
// # -3 == NO OK - not finite errors #
// # -4 == NO OK - negative determinant #
// # -5 == NO OK - maxLumiIntegration reached #
// ############################################
// ###############################################
// # RETURN CODE: #
// # >0 == NOT OK - fit status (MINUIT manual) #
// # 0 == OK #
// # -1 == NOT OK - not finite edm #
// # -2 == NOT OK - not enough "minNentries" #
// # -3 == NOT OK - not finite errors #
// # -4 == NOT OK - negative determinant #
// # -5 == NOT OK - maxLumiIntegration reached #
// # -6 == NOT OK - FatalRootError: @SUB=Minuit2 #
// ###############################################

if ((vals != nullptr) && (vals->size() == nParams * 2)) {
double nSigmaXY = 10.;
Expand Down Expand Up @@ -332,29 +333,32 @@ int Vx3DHLTAnalyzer::MyFit(vector<double>* vals) {
Gauss3D->SetVariable(8, "mean z", *(it + 8), parDistanceZ);

// Set the central positions of the centroid for vertex rejection
xPos = (*vals)[6];
yPos = (*vals)[7];
zPos = (*vals)[8];
xPos = *(it + 6) + deltaMean;
yPos = *(it + 7);
zPos = *(it + 8);

// Set dimensions of the centroid for vertex rejection
maxTransRadius = nSigmaXY * std::sqrt(std::fabs((*vals)[0]) + std::fabs((*vals)[1])) / 2.;
maxLongLength = nSigmaZ * std::sqrt(std::fabs((*vals)[2]));
maxTransRadius = nSigmaXY * std::sqrt(std::fabs(*(it + 0)) + std::fabs(*(it + 1)) / 2.);
maxLongLength = nSigmaZ * std::sqrt(std::fabs(*(it + 2)));

try {
Gauss3D->Minimize();
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();
} catch (cms::Exception& er) {
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception: " << er.what();
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception @ Fit at X: \n" << er.what();
goodData = -6;
edm = 1.;
continue;
}
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();

if (counterVx < minNentries)
goodData = -2;
else if (isNotFinite(edm) == true) {
goodData = -1;
if (internalDebug == true)
edm::LogInfo("Vx3DHLTAnalyzer") << "\tNot finite edm !";
} else
} else if (goodData != -6)
for (unsigned int j = 0; j < nParams; j++)
if (isNotFinite(Gauss3D->Errors()[j]) == true) {
goodData = -3;
Expand Down Expand Up @@ -408,29 +412,32 @@ int Vx3DHLTAnalyzer::MyFit(vector<double>* vals) {
Gauss3D->SetVariable(8, "mean z", *(it + 8), parDistanceZ);

// Set the central positions of the centroid for vertex rejection
xPos = Gauss3D->X()[6];
yPos = Gauss3D->X()[7];
zPos = Gauss3D->X()[8];
xPos = *(it + 6) + (double(bestMovementX) - 1.) * std::sqrt(*(it + 0));
yPos = *(it + 7) + deltaMean;
zPos = *(it + 8);

// Set dimensions of the centroid for vertex rejection
maxTransRadius = nSigmaXY * std::sqrt(std::fabs(Gauss3D->X()[0]) + std::fabs(Gauss3D->X()[1])) / 2.;
maxLongLength = nSigmaZ * std::sqrt(std::fabs(Gauss3D->X()[2]));
maxTransRadius = nSigmaXY * std::sqrt(std::fabs(*(it + 0)) + std::fabs(*(it + 1)) / 2.);
maxLongLength = nSigmaZ * std::sqrt(std::fabs(*(it + 2)));

try {
Gauss3D->Minimize();
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();
} catch (cms::Exception& er) {
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception: " << er.what();
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception @ Fit at Y: \n" << er.what();
goodData = -6;
edm = 1.;
continue;
}
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();

if (counterVx < minNentries)
goodData = -2;
else if (isNotFinite(edm) == true) {
goodData = -1;
if (internalDebug == true)
edm::LogInfo("Vx3DHLTAnalyzer") << "\tNot finite edm !";
} else
} else if (goodData != -6)
for (unsigned int j = 0; j < nParams; j++)
if (isNotFinite(Gauss3D->Errors()[j]) == true) {
goodData = -3;
Expand Down Expand Up @@ -485,29 +492,32 @@ int Vx3DHLTAnalyzer::MyFit(vector<double>* vals) {
Gauss3D->SetVariable(8, "mean z", *(it + 8) + deltaMean, parDistanceZ);

// Set the central positions of the centroid for vertex rejection
xPos = Gauss3D->X()[6];
yPos = Gauss3D->X()[7];
zPos = Gauss3D->X()[8];
xPos = *(it + 6) + (double(bestMovementX) - 1.) * std::sqrt(*(it + 0));
yPos = *(it + 7) + (double(bestMovementY) - 1.) * std::sqrt(*(it + 1));
zPos = *(it + 8) + deltaMean;

// Set dimensions of the centroid for vertex rejection
maxTransRadius = nSigmaXY * std::sqrt(std::fabs(Gauss3D->X()[0]) + std::fabs(Gauss3D->X()[1])) / 2.;
maxLongLength = nSigmaZ * std::sqrt(std::fabs(Gauss3D->X()[2]));
maxTransRadius = nSigmaXY * std::sqrt(std::fabs(*(it + 0)) + std::fabs(*(it + 1)) / 2.);
maxLongLength = nSigmaZ * std::sqrt(std::fabs(*(it + 2)));

try {
Gauss3D->Minimize();
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();
} catch (cms::Exception& er) {
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception: " << er.what();
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception @ Fit at Z: \n" << er.what();
goodData = -6;
edm = 1.;
continue;
}
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();

if (counterVx < minNentries)
goodData = -2;
else if (isNotFinite(edm) == true) {
goodData = -1;
if (internalDebug == true)
edm::LogInfo("Vx3DHLTAnalyzer") << "\tNot finite edm !";
} else
} else if (goodData != -6)
for (unsigned int j = 0; j < nParams; j++)
if (isNotFinite(Gauss3D->Errors()[j]) == true) {
goodData = -3;
Expand Down Expand Up @@ -553,29 +563,31 @@ int Vx3DHLTAnalyzer::MyFit(vector<double>* vals) {
Gauss3D->SetVariable(8, "mean z", *(it + 8) + (double(bestMovementZ) - 1.) * std::sqrt(*(it + 2)), parDistanceZ);

// Set the central positions of the centroid for vertex rejection
xPos = (*vals)[6];
yPos = (*vals)[7];
zPos = (*vals)[8];
xPos = *(it + 6) + (double(bestMovementX) - 1.) * std::sqrt(*(it + 0));
yPos = *(it + 7) + (double(bestMovementY) - 1.) * std::sqrt(*(it + 1));
zPos = *(it + 8) + (double(bestMovementZ) - 1.) * std::sqrt(*(it + 2));

// Set dimensions of the centroid for vertex rejection
maxTransRadius = nSigmaXY * std::sqrt(std::fabs((*vals)[0]) + std::fabs((*vals)[1])) / 2.;
maxLongLength = nSigmaZ * std::sqrt(std::fabs((*vals)[2]));
maxTransRadius = nSigmaXY * std::sqrt(std::fabs(*(it + 0)) + std::fabs(*(it + 1)) / 2.);
maxLongLength = nSigmaZ * std::sqrt(std::fabs(*(it + 2)));

try {
Gauss3D->Minimize();
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();
} catch (cms::Exception& er) {
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception: " << er.what();
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception @ Final fit: \n" << er.what();
goodData = -6;
edm = 1.;
}
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();

if (counterVx < minNentries)
goodData = -2;
else if (isNotFinite(edm) == true) {
goodData = -1;
if (internalDebug == true)
edm::LogInfo("Vx3DHLTAnalyzer") << "\tNot finite edm !";
} else
} else if (goodData != -6)
for (unsigned int j = 0; j < nParams; j++)
if (isNotFinite(Gauss3D->Errors()[j]) == true) {
goodData = -3;
Expand Down Expand Up @@ -625,29 +637,33 @@ int Vx3DHLTAnalyzer::MyFit(vector<double>* vals) {
8, "mean z", *(it + 8) + (double(bestMovementZ) - 1.) * std::sqrt(*(it + 2)), parDistanceZ * largerDist[i]);

// Set the central positions of the centroid for vertex rejection
xPos = Gauss3D->X()[6];
yPos = Gauss3D->X()[7];
zPos = Gauss3D->X()[8];
xPos = *(it + 6) + (double(bestMovementX) - 1.) * std::sqrt(*(it + 0));
yPos = *(it + 7) + (double(bestMovementY) - 1.) * std::sqrt(*(it + 1));
zPos = *(it + 8) + (double(bestMovementZ) - 1.) * std::sqrt(*(it + 2));

// Set dimensions of the centroid for vertex rejection
maxTransRadius = nSigmaXY * std::sqrt(std::fabs(Gauss3D->X()[0]) + std::fabs(Gauss3D->X()[1])) / 2.;
maxLongLength = nSigmaZ * std::sqrt(std::fabs(Gauss3D->X()[2]));
maxTransRadius = nSigmaXY * std::sqrt(std::fabs(*(it + 0)) + std::fabs(*(it + 1)) / 2.);
maxLongLength = nSigmaZ * std::sqrt(std::fabs(*(it + 2)));

try {
Gauss3D->Minimize();
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();
} catch (cms::Exception& er) {
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception: " << er.what();
edm::LogError("Vx3DHLTAnalyzer") << "\tCaught Minuit2 exception @ Fit with different distances: \n"
<< er.what();
goodData = -6;
edm = 1.;
continue;
}
goodData = Gauss3D->Status();
edm = Gauss3D->Edm();

if (counterVx < minNentries)
goodData = -2;
else if (isNotFinite(edm) == true) {
goodData = -1;
if (internalDebug == true)
edm::LogInfo("Vx3DHLTAnalyzer") << "\tNot finite edm !";
} else
} else if (goodData != -6)
for (unsigned int j = 0; j < nParams; j++)
if (isNotFinite(Gauss3D->Errors()[j]) == true) {
goodData = -3;
Expand Down Expand Up @@ -1525,18 +1541,19 @@ void Vx3DHLTAnalyzer::bookHistograms(DQMStore::IBooker& ibooker, Run const& iRun
"L - status vs lumi", "App. Status vs. Lumisection", nLumiXaxisRange, 0.5, ((double)nLumiXaxisRange) + 0.5);
statusCounter->setAxisTitle("Lumisection [#]", 1);
statusCounter->getTH1()->SetOption("E1");
statusCounter->getTH1()->GetYaxis()->Set(11, -5.5, 5.5);
statusCounter->getTH1()->GetYaxis()->SetBinLabel(1, "Max Lumi.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(2, "Neg. det.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(3, "Infinite err.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(4, "No vtx.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(5, "Infinite EDM");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(6, "OK");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(7, "MINUIT stat.");
statusCounter->getTH1()->GetYaxis()->Set(12, -6.5, 5.5);
statusCounter->getTH1()->GetYaxis()->SetBinLabel(1, "FatalRootError");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(2, "Max Lumi.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(3, "Neg. det.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(4, "Infinite err.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(5, "No vtx.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(6, "Infinite EDM");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(7, "OK");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(8, "MINUIT stat.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(9, "MINUIT stat.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(10, "MINUIT stat.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(11, "MINUIT stat.");
statusCounter->getTH1()->GetYaxis()->SetBinLabel(12, "MINUIT stat.");

fitResults = ibooker.book2D("A - fit results", "Results of Beam Spot Fit", 2, 0., 2., 9, 0., 9.);
fitResults->setAxisTitle("Ongoing: bootstrapping", 1);
Expand Down