Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:36

0001 #ifndef FitMass1D_cc
0002 #define FitMass1D_cc
0003 
0004 #include <iostream>
0005 #include <sstream>
0006 #include "TFile.h"
0007 #include "TH2F.h"
0008 #include "TDirectory.h"
0009 #include "TROOT.h"
0010 #include "FitWithRooFit.cc"
0011 
0012 /**
0013  * Fit the mass distribution with the given function using RooFit.
0014  */
0015 
0016 class FitMass1D
0017 {
0018 public:
0019   FitMass1D() : rebinX(1)
0020   {
0021   };
0022 
0023   void fit(const TString & inputFileName, const TString & outputFileName, const TString & outputFileOption, 
0024        const double & xMin, const double & xMax, 
0025        const TString & signalType = "doubleGaussian", const TString & backgroundType = "exponential")
0026   {
0027     //    TFile * inputFile1 = new TFile(fileNum+"_MuScleFit.root", "READ");
0028     TFile* inputFile = TFile::Open(inputFileName, "READ" );
0029     TH1F * histo = (TH1F*)inputFile->Get("hRecBestResAllEvents_Mass");
0030     histo->Rebin(rebinX);
0031 
0032     TFile * outputFile = new TFile(outputFileName,outputFileOption);
0033     outputFile->cd();
0034 
0035     fitter_.fit(histo, signalType, backgroundType, xMin, xMax);
0036 
0037     outputFile->Write();
0038     outputFile->Close();
0039   }
0040 
0041   FitWithRooFit * fitter()
0042   {
0043     return( &fitter_ );
0044   }
0045 protected:
0046   int rebinX;
0047   FitWithRooFit fitter_;
0048 };
0049 
0050 #endif