void ResultFormatter::LatexMinimumFitResultTable( FitResult * OutputData, stringstream& latex ) { ResultFormatter::TableHeader( latex, 2 ); latex << "Parameter & Fit result and error \\\\ \\hline \\hline\n" << endl; ResultParameterSet * outputParameters = OutputData->GetResultParameterSet(); vector<string> allNames = outputParameters->GetAllNames(); for( vector<string>::iterator nameIterator = allNames.begin(); nameIterator != allNames.end(); ++nameIterator ) { ResultParameter * outputParameter = outputParameters->GetResultParameter( *nameIterator ); double fitValue = outputParameter->GetValue(); double fitError = outputParameter->GetError(); string unit = outputParameter->GetUnit(); string name = *nameIterator; latex << setw(20) << EdStyle::GetParamLatexName(name) << " & " << setw(12) << setprecision(3) << fitValue; if( outputParameter->GetAssym() ) { latex << " + " << outputParameter->GetErrHi() << " - " << outputParameter->GetErrLow() << " "; } else { latex << " \\pm " << setw(10) << fitError << " "; } latex << setw(15) << EdStyle::GetParamLatexUnit(unit) << "\\\\" << endl; } ResultFormatter::TableFooter( latex ); }
//Display the results of a fit in a LaTeX table using cout void ResultFormatter::ReviewOutput( FitResult * OutputData ) { ResultParameterSet * outputParameters = OutputData->GetResultParameterSet(); vector<string> allNames = outputParameters->GetAllNames(); vector<string>::iterator nameIterator; cout << endl << endl; cout << "--------------------------------------------------" <<endl; cout << "\nFit Review:\t\tStatus:\t" <<OutputData->GetFitStatus()<<"\t\tNLL:\t"<<setprecision(10)<<OutputData->GetMinimumValue()<<endl<<endl; //Ouput each parameter for( nameIterator = allNames.begin(); nameIterator != allNames.end(); ++nameIterator ) { ResultParameter * outputParameter = outputParameters->GetResultParameter( *nameIterator ); double fitValue = outputParameter->GetValue(); double fitError = outputParameter->GetError(); string unit = outputParameter->GetUnit(); string name = *nameIterator; cout << setw(25) << name << " : " << setw(13) << setprecision(5) << fitValue; if( outputParameter->GetAssym() ) { cout << " + " << setprecision(5) << setw(8) << outputParameter->GetErrHi() << " - " << setw(6) << outputParameter->GetErrLow() << endl; } else { cout << " ± " << setw(13) << setprecision(5) << fitError << endl; } } cout << endl; cout << "--------------------------------------------------" <<endl; cout << endl <<endl; }
//Make pull plots from the output of a toy study void ResultFormatter::WriteFlatNtuple( const string FileName, const FitResultVector* ToyResult, const vector<string> inputXML, const vector<string> runtimeArgs, const string XMLForProjections, const string XMLForToys ) { TFile * rootFile = TFile::Open( FileName.c_str(), "RECREATE" ); rootFile->SetCompressionLevel( 9 ); //cout << "Storing Fit Result Vector" << endl; // Important! // The output from this is typically run through the RapidPlot file // For sake of backwards compatibility the RapidPlot tool makes use of the ability to look for the 'first' TTree in a ROOT file for some of it's internal logic // KEEP THIS TREE AS THE FIRST TREE CREATED AND WRITTEN TO THE FILE TO BE ABLE TO KEEP USING THIS TOOL!!! TTree* outputTree = new TTree( "RapidFitResult", "RapidFitResult" ); ResultParameterSet* resultSet = ToyResult->GetFitResult( 0 )->GetResultParameterSet(); vector<string> allNames = resultSet->GetAllNames(); for( unsigned int param_i=0; param_i< allNames.size(); ++param_i ) { string thisParamName( allNames[param_i] ); vector<double> ParameterValues, ParameterErrors, ParameterOriginalValues; vector<double> ParameterPulls, ParameterStepSizes; vector<double> ParameterErrorsHigh, ParameterErrorsLow; vector<double> ParameterMinimums, ParameterMaximums; vector<int> ParameterScanStatus, ParameterFixedStatus; for( unsigned int resultNum=0; resultNum< (unsigned)ToyResult->NumberResults(); ++resultNum ) { ResultParameter* thisParam = ToyResult->GetFitResult( (unsigned)resultNum )->GetResultParameterSet()->GetResultParameter( thisParamName ); ParameterValues.push_back( thisParam->GetValue() ); ParameterErrors.push_back( thisParam->GetError() ); ParameterPulls.push_back( thisParam->GetPull() ); ParameterMinimums.push_back( thisParam->GetMinimum() ); ParameterMaximums.push_back( thisParam->GetMaximum() ); ParameterOriginalValues.push_back( thisParam->GetOriginalValue() ); if( thisParam->GetType() == "Fixed" ) { ParameterFixedStatus.push_back( 1 ); } else { ParameterFixedStatus.push_back( 0 ); } //if( thisParam->GetScanStatus() ) cout << "Scanned: " << string(thisParamName) << endl; if( thisParam->GetScanStatus() ) { ParameterScanStatus.push_back( 1 ); } else { ParameterScanStatus.push_back( 0 ); } if( thisParam->GetAssym() ) { ParameterErrorsHigh.push_back( thisParam->GetErrHi() ); ParameterErrorsLow.push_back( thisParam->GetErrLow() ); } else { ParameterErrorsHigh.push_back( 0. ); ParameterErrorsLow.push_back( 0. ); } ParameterStepSizes.push_back( thisParam->GetStepSize() ); } string BranchName=allNames[param_i]; ResultFormatter::AddBranch( outputTree, BranchName+"_value", ParameterValues ); bool fixed_param = ToyResult->GetFitResult(0)->GetResultParameterSet()->GetResultParameter(thisParamName)->GetType() == "Fixed"; bool scanned_param = ToyResult->GetFitResult(0)->GetResultParameterSet()->GetResultParameter(thisParamName)->GetScanStatus(); if( (!fixed_param) || (scanned_param) ) { ResultFormatter::AddBranch( outputTree, BranchName+"_error", ParameterErrors ); ResultFormatter::AddBranch( outputTree, BranchName+"_gen", ParameterOriginalValues ); ResultFormatter::AddBranch( outputTree, BranchName+"_pull", ParameterPulls ); ResultFormatter::AddBranch( outputTree, BranchName+"_max", ParameterMaximums ); ResultFormatter::AddBranch( outputTree, BranchName+"_min", ParameterMinimums ); ResultFormatter::AddBranch( outputTree, BranchName+"_step", ParameterStepSizes ); ResultFormatter::AddBranch( outputTree, BranchName+"_errHi", ParameterErrorsHigh ); ResultFormatter::AddBranch( outputTree, BranchName+"_errLo", ParameterErrorsLow ); } ResultFormatter::AddBranch( outputTree, BranchName+"_scan", ParameterScanStatus ); ResultFormatter::AddBranch( outputTree, BranchName+"_fix", ParameterFixedStatus ); } //cout << "Stored Parameters" << endl; ResultFormatter::AddBranch( outputTree, "Fit_RealTime", ToyResult->GetAllRealTimes() ); ResultFormatter::AddBranch( outputTree, "Fit_CPUTime", ToyResult->GetAllCPUTimes() ); ResultFormatter::AddBranch( outputTree, "Fit_GLTime", ToyResult->GetAllGLTimes() ); vector<int> fitStatus; vector<double> NLL_Values, RealTimes, CPUTimes; for( unsigned int i=0; i< (unsigned) ToyResult->NumberResults(); ++i ) { fitStatus.push_back( ToyResult->GetFitResult( (int)i )->GetFitStatus() ); NLL_Values.push_back( ToyResult->GetFitResult( (int)i )->GetMinimumValue() ); } ResultFormatter::AddBranch( outputTree, "Fit_Status", fitStatus ); ResultFormatter::AddBranch( outputTree, "NLL", NLL_Values ); outputTree->Write("",TObject::kOverwrite); //ResultFormatter::AddBranch( outputTree, "Fit_RealTime", RealTimes ); //ResultFormatter::AddBranch( outputTree, "Fit_CPUTime", CPUTimes ); // Ntuples are 'stupid' objects in ROOT and the basic one can only handle float type objects /*TNtuple * parameterNTuple; parameterNTuple = new TNtuple("RapidFitResult", "RapidFitResult", ToyResult->GetFlatResultHeader()); Float_t * resultArr; for( int resultIndex = 0; resultIndex < ToyResult->NumberResults(); ++resultIndex ) { vector<double> result = ToyResult->GetFlatResult(resultIndex); resultArr = new Float_t [result.size()]; copy( result.begin(), result.end(), resultArr); parameterNTuple->Fill( resultArr ); delete [] resultArr; }*/ //cout << "Storing Correlation Matrix" << endl; if( ToyResult->GetFitResult(0)->GetResultParameterSet() != NULL ) { if( !ToyResult->GetFitResult(0)->GetResultParameterSet()->GetAllFloatNames().empty() ) { vector<double> MatrixElements; vector<string> MatrixNames; TTree * tree = new TTree("corr_matrix", "Elements from Correlation Matricies"); tree->Branch("MartrixElements", "std::vector<double>", &MatrixElements ); tree->Branch("MartrixNames", "std::vector<string>", &MatrixNames ); for( int resultIndex = 0; resultIndex < ToyResult->NumberResults(); ++resultIndex ) { TMatrixDSym* thisMatrix = ToyResult->GetFitResult(resultIndex)->GetCovarianceMatrix()->thisMatrix; if( thisMatrix == NULL ) continue; MatrixNames = ToyResult->GetFitResult(resultIndex)->GetCovarianceMatrix()->theseParameters; if( MatrixNames.empty() ) continue; double* MatrixArray = thisMatrix->GetMatrixArray(); if( MatrixArray == NULL ) continue; MatrixElements.clear(); for( unsigned int i=0; i< (unsigned) thisMatrix->GetNoElements(); ++i ) { MatrixElements.push_back( MatrixArray[i] ); } if( thisMatrix->GetNoElements() > 0 ) tree->Fill(); } tree->Write("",TObject::kOverwrite); } } //cout << "Saving XML and runtime" << endl; if( !inputXML.empty() ) { TTree* XMLTree = new TTree( "FittingXML", "FittingXML" ); vector<string> thisXML = inputXML; XMLTree->Branch( "FittingXML", "std::vector<string>", &thisXML ); XMLTree->Fill(); XMLTree->Write("",TObject::kOverwrite); } if( !runtimeArgs.empty() ) { TTree* RuntimeTree = new TTree( "RuntimeArgs", "RuntimeArgs" ); vector<string> thisRuntime = runtimeArgs; RuntimeTree->Branch( "RuntimeArgs", "std::vector<string>", &thisRuntime ); RuntimeTree->Fill(); RuntimeTree->Write("",TObject::kOverwrite); } if( !XMLForProjections.empty() ) { TTree* ProjectionXML = new TTree( "XMLForProjections", "XMLForProjections" ); string thisXML = XMLForProjections; ProjectionXML->Branch( "ProjectionXML", "std::string", &thisXML ); ProjectionXML->Fill(); ProjectionXML->Write("",TObject::kOverwrite); } if( !XMLForToys.empty() ) { TTree* ToyXML = new TTree( "XMLForToys", "XMLForToys" ); string thisXML = XMLForToys; ToyXML->Branch( "ToyXML", "std::string", &thisXML ); ToyXML->Fill(); ToyXML->Write("",TObject::kOverwrite); } rootFile->Write("",TObject::kOverwrite); rootFile->Close(); // THIS SHOULD BE SAFE... BUT THIS IS ROOT so 'of course' it isn't... //delete parameterNTuple; //delete rootFile; }