// @(#)root/roostats:$Id$ // Author: Kyle Cranmer, George Lewis /************************************************************************* * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ //////////////////////////////////////////////////////////////////////////////// /* BEGIN_HTML
END_HTML */ // #include "TH1.h" #include "RooStats/HistFactory/Sample.h" #include "RooStats/HistFactory/HistFactoryException.h" //#include "TClass.h" RooStats::HistFactory::Sample::Sample() : fNormalizeByTheory(false), fStatErrorActivate(false), fhNominal(), fhCountingHist(0) { ; } // copy constructor (important for python) RooStats::HistFactory::Sample::Sample(const Sample& other) : fName(other.fName), fInputFile(other.fInputFile), fHistoName(other.fHistoName), fHistoPath(other.fHistoPath), fChannelName(other.fChannelName), fOverallSysList(other.fOverallSysList), fNormFactorList(other.fNormFactorList), fHistoSysList(other.fHistoSysList), fHistoFactorList(other.fHistoFactorList), fShapeSysList(other.fShapeSysList), fShapeFactorList(other.fShapeFactorList), fStatError(other.fStatError), fNormalizeByTheory(other.fNormalizeByTheory), fStatErrorActivate(other.fStatErrorActivate), fhNominal(other.fhNominal), fhCountingHist(0) { if( other.fhCountingHist ) { SetValue( other.fhCountingHist->GetBinContent(1) ); }else{ fhCountingHist = NULL; } } RooStats::HistFactory::Sample::Sample(std::string SampName, std::string SampHistoName, std::string SampInputFile, std::string SampHistoPath) : fName( SampName ), fInputFile( SampInputFile), fHistoName( SampHistoName ), fHistoPath( SampHistoPath ), fNormalizeByTheory(true), fStatErrorActivate(false), fhNominal(), fhCountingHist(0) { ; } RooStats::HistFactory::Sample::Sample(std::string SampName) : fName( SampName ), fInputFile( "" ), fHistoName( "" ), fHistoPath( "" ), fNormalizeByTheory(true), fStatErrorActivate(false),fhNominal(), fhCountingHist(0) { ; } RooStats::HistFactory::Sample::~Sample() { if(fhCountingHist) delete fhCountingHist; } TH1* RooStats::HistFactory::Sample::GetHisto() { TH1* histo = (TH1*) fhNominal.GetObject(); return histo; } void RooStats::HistFactory::Sample::writeToFile( std::string OutputFileName, std::string DirName ) { TH1* histNominal = GetHisto(); histNominal->Write(); // Set the location of the data // in the output measurement fInputFile = OutputFileName; fHistoName = histNominal->GetName(); fHistoPath = DirName; // Write this sample's StatError GetStatError().writeToFile( OutputFileName, DirName ); // Must write all systematics that contain internal histograms // (This is not all systematics) for( unsigned int i = 0; i < GetHistoSysList().size(); ++i ) { GetHistoSysList().at(i).writeToFile( OutputFileName, DirName ); } for( unsigned int i = 0; i < GetHistoFactorList().size(); ++i ) { GetHistoFactorList().at(i).writeToFile( OutputFileName, DirName ); } for( unsigned int i = 0; i < GetShapeSysList().size(); ++i ) { GetShapeSysList().at(i).writeToFile( OutputFileName, DirName ); } for( unsigned int i = 0; i < GetShapeFactorList().size(); ++i ) { GetShapeFactorList().at(i).writeToFile( OutputFileName, DirName ); } return; } void RooStats::HistFactory::Sample::SetValue( Double_t val ) { // For use in a number counting measurement // Create a 1-bin histogram, // fill it with this input value, // and set this Sample's histogram to that hist std::string SampleHistName = fName + "_hist"; // Histogram has 1-bin (hard-coded) if(fhCountingHist) delete fhCountingHist; fhCountingHist = new TH1F( SampleHistName.c_str(), SampleHistName.c_str(), 1, 0, 1 ); fhCountingHist->SetBinContent( 1, val ); // Set the histogram of the internally held data // node of this channel to this newly created histogram SetHisto( fhCountingHist ); } void RooStats::HistFactory::Sample::Print( std::ostream& stream ) { stream << "\t \t Name: " << fName << "\t \t Channel: " << fChannelName << "\t NormalizeByTheory: " << (fNormalizeByTheory ? "True" : "False") << "\t StatErrorActivate: " << (fStatErrorActivate ? "True" : "False") << std::endl; stream << "\t \t \t \t " << "\t InputFile: " << fInputFile << "\t HistName: " << fHistoName << "\t HistoPath: " << fHistoPath << "\t HistoAddress: " << GetHisto() // << "\t Type: " << GetHisto()->ClassName() << std::endl; if( fStatError.GetActivate() ) { stream << "\t \t \t StatError Activate: " << fStatError.GetActivate() << "\t InputFile: " << fInputFile << "\t HistName: " << fStatError.GetHistoName() << "\t HistoPath: " << fStatError.GetHistoPath() << "\t HistoAddress: " << fStatError.GetErrorHist() << std::endl; } /* stream<< " NormalizeByTheory: "; if(NormalizeByTheory) stream << "True"; else stream << "False"; stream<< " StatErrorActivate: "; if(StatErrorActivate) stream << "True"; else stream << "False"; */ } void RooStats::HistFactory::Sample::PrintXML( std::ofstream& xml ) { // Create the sample tag xml << "