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

fix compilation errors in MomentumScaleCalibration macros #39065

Merged
merged 2 commits into from Aug 16, 2022
Merged
Show file tree
Hide file tree
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
113 changes: 55 additions & 58 deletions MuonAnalysis/MomentumScaleCalibration/test/Macros/RooFit/FitSlices.cc
Expand Up @@ -12,10 +12,8 @@
* This class can be used to fit the X slices of a TH1 histogram using RooFit.
* It uses the FitXslices class to do the fitting.
*/
class FitSlices
{
class FitSlices {
public:

double xMean;
double xMin;
double xMax;
Expand All @@ -33,26 +31,29 @@ class FitSlices

FitXslices fitXslices;

FitSlices(
double xMean_,
double xMin_,
double xMax_,
double sigma_,
double sigmaMin_,
double sigmaMax_,
TString signalType_,
TString backgroundType_
) :
xMean(xMean_),
xMin(xMin_),
xMax(xMax_),
sigma(sigma_),
sigmaMin(sigmaMin_),
sigmaMax(sigmaMax_),
signalType(signalType_),
backgroundType(backgroundType_),
rebinX(2), rebinY(2), rebinZ(2), sigma2(0.1), sigma2Min(0.), sigma2Max(10.), useChi2(false)
{
FitSlices(double xMean_,
double xMin_,
double xMax_,
double sigma_,
double sigmaMin_,
double sigmaMax_,
TString signalType_,
TString backgroundType_)
: xMean(xMean_),
xMin(xMin_),
xMax(xMax_),
sigma(sigma_),
sigmaMin(sigmaMin_),
sigmaMax(sigmaMax_),
signalType(signalType_),
backgroundType(backgroundType_),
rebinX(2),
rebinY(2),
rebinZ(2),
sigma2(0.1),
sigma2Min(0.),
sigma2Max(10.),
useChi2(false) {
// Initialize fitXslices to some defaults, nothing un-overridable
fitXslices.fitter()->useChi2_ = useChi2;
fitXslices.fitter()->initMean(xMean, xMin, xMax);
Expand All @@ -69,15 +70,10 @@ class FitSlices
// const double & sigma = 0.03, const double & sigmaMin = 0., const double & sigmaMax = 0.1,
// const TString & histoBaseName = "hRecBestResVSMu", const TString & histoBaseTitle = "MassVs") = 0;

void fitSlice(
const TString & histoName, const TString & dirName,
TFile * inputFile, TDirectory * outputFile
){
void fitSlice(const TString& histoName, const TString& dirName, TFile* inputFile, TDirectory* outputFile) {
//r.c. patch --------------
if (
histoName=="hRecBestResVSMu_MassVSEtaPhiPlus" || histoName=="hRecBestResVSMu_MassVSEtaPhiMinus" ||
histoName=="hRecBestResVSMu_MassVSPhiPlusPhiMinus" || histoName=="hRecBestResVSMu_MassVSEtaPlusEtaMinus"
){
if (histoName == "hRecBestResVSMu_MassVSEtaPhiPlus" || histoName == "hRecBestResVSMu_MassVSEtaPhiMinus" ||
histoName == "hRecBestResVSMu_MassVSPhiPlusPhiMinus" || histoName == "hRecBestResVSMu_MassVSEtaPlusEtaMinus") {
TH3* histoPt3 = (TH3*)inputFile->FindObjectAny(histoName);
outputFile->mkdir(dirName);
outputFile->cd(dirName);
Expand All @@ -90,8 +86,7 @@ class FitSlices
// histoPt3->RebinY(rebinY);
// (histoPt3->DoProject2D())->RebinX(rebinX);
// (histoPt3->DoProject2D())->RebinY(rebinY);
}
else{
} else {
TH2* histoPt2 = (TH2*)inputFile->FindObjectAny(histoName);
histoPt2->RebinX(rebinX);
histoPt2->RebinY(rebinY);
Expand All @@ -103,45 +98,47 @@ class FitSlices
}
}

TH3* rebin3D(const TH3* histo3D){
unsigned int zbins=histo3D->GetNbinsZ();
TH3* rebin3D(const TH3* histo3D) {
unsigned int zbins = histo3D->GetNbinsZ();
// std::cout<< "number of bins in z (and tempHisto) --> "<<zbins<<std::endl;
std::map<unsigned int, TH2*> twoDprojection;
for (unsigned int z=1; z<zbins; ++z) {
TAxis* ax_tmp = const_cast<TAxis*>(histo3D->GetZaxis()); ax_tmp->SetRange(z, z);
TH2* tempHisto= (TH2*)histo3D->Project3D("xy");
for (unsigned int z = 1; z < zbins; ++z) {
TAxis* ax_tmp = const_cast<TAxis*>(histo3D->GetZaxis());
ax_tmp->SetRange(z, z);
TH2* tempHisto = (TH2*)histo3D->Project3D("xy");
std::stringstream ss;
ss << z;
tempHisto->SetName(TString(tempHisto->GetName())+ss.str());
tempHisto->SetName((std::string{tempHisto->GetName()} + ss.str()).c_str());
tempHisto->RebinX(rebinX);
tempHisto->RebinY(rebinY);
twoDprojection.insert(std::make_pair(z, tempHisto));
}
unsigned int xbins, ybins;
TH3* rebinned3D = (TH3*) new TH3F(TString(histo3D->GetName())+"_rebinned", histo3D->GetTitle(),
xbins, histo3D->GetXaxis()->GetXmin(), histo3D->GetXaxis()->GetXmax(),
ybins, histo3D->GetYaxis()->GetXmin(), histo3D->GetYaxis()->GetXmax(),
zbins, histo3D->GetZaxis()->GetXmin(), histo3D->GetZaxis()->GetXmax());
if (twoDprojection.size()!=0)
{
xbins=twoDprojection[1]->GetNbinsX();
ybins=twoDprojection[1]->GetNbinsY();
TH3* rebinned3D = (TH3*)new TH3F(TString(histo3D->GetName()) + "_rebinned",
histo3D->GetTitle(),
xbins,
histo3D->GetXaxis()->GetXmin(),
histo3D->GetXaxis()->GetXmax(),
ybins,
histo3D->GetYaxis()->GetXmin(),
histo3D->GetYaxis()->GetXmax(),
zbins,
histo3D->GetZaxis()->GetXmin(),
histo3D->GetZaxis()->GetXmax());
if (twoDprojection.size() != 0) {
xbins = twoDprojection[1]->GetNbinsX();
ybins = twoDprojection[1]->GetNbinsY();
//std::cout<< "number of bins in x --> "<<xbins<<std::endl;
//std::cout<< "number of bins in y --> "<<ybins<<std::endl;
for (unsigned int z=1; z<zbins; ++z)
{
for (unsigned int y=1; y<ybins; ++y)
{
for (unsigned int x=1; x<xbins; ++x)
{
std::cout<< "x/y/z= "<<x<<"/"<<y<<"/"<<z <<std::endl;
std::cout<< "number of bins in x --> "<<xbins<<std::endl;
std::cout<< "number of bins in y --> "<<ybins<<std::endl;
for (unsigned int z = 1; z < zbins; ++z) {
for (unsigned int y = 1; y < ybins; ++y) {
for (unsigned int x = 1; x < xbins; ++x) {
std::cout << "x/y/z= " << x << "/" << y << "/" << z << std::endl;
std::cout << "number of bins in x --> " << xbins << std::endl;
std::cout << "number of bins in y --> " << ybins << std::endl;
rebinned3D->Fill(x, y, twoDprojection[z]->GetBinContent(x, y));
}

}

}
}
return rebinned3D;
Expand Down