コード例 #1
0
ParameterSet* VectoredFeldmanCousins::getParameterSet( ParameterSet* inputSet, ResultParameterSet* inputResult )
{
	// Model 1 nuisence parameters are not changed
	if( nuisenceModel == 0 )
	{
		return new ParameterSet( *inputSet );
	}
	// Model 2 nuisence parameters are varied within 1 sigma of their true value
	else if( nuisenceModel == 1 )
	{
		ParameterSet* tempSet = new ParameterSet( *inputSet );
		vector<string> all_params = tempSet->GetAllNames();
		for( vector<string>::iterator param_i = all_params.begin(); param_i != all_params.end(); ++param_i )
		{
			PhysicsParameter* thisParameter = tempSet->GetPhysicsParameter( *param_i );
			ResultParameter* thisResult = inputResult->GetResultParameter( *param_i );
			if( thisParameter->GetType() != "Fixed" && !thisResult->GetScanStatus() )
			{
				TRandom3* rand_gen = RapidFitRandom::GetRandomFunction();
				double new_value = rand_gen->Gaus( thisResult->GetValue(), thisResult->GetError() );
				thisParameter->SetBlindedValue( new_value );
				thisParameter->SetStepSize( thisResult->GetError() );
			}
		}
		return tempSet;
	}
	else
	{
		cout << endl << "\t\tUNKNOWN NUICENCE MODEL, NOT DOING ANTYTHING!!!!" << endl << endl;
		nuisenceModel = 0;
		return this->getParameterSet( inputSet, inputResult );
	}
}
コード例 #2
0
ファイル: ResultFormatter.cpp プロジェクト: kgizdov/RapidFit
//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;
}