Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:42

0001 #include <iostream>
0002 #include <sstream>
0003 #include "TFile.h"
0004 #include "TH2F.h"
0005 #include "TDirectory.h"
0006 #include "TROOT.h"
0007 #include "FitWithRooFit.cc"
0008 
0009 /**
0010  * Fit the mass distribution with the given function using RooFit.
0011  */
0012 
0013 class FitMass
0014 {
0015 public:
0016   FitMass() : rebinX(1)
0017   {
0018     fitter_.initMean( 3.1, 2.9, 3.3 );
0019     fitter_.initSigma(  0.03, 0., 0.1 );
0020     fitter_.initSigma2( 0.1,  0., 1. );
0021 
0022     fitter_.initGamma( 2.4952, 0., 10.);
0023     fitter_.gamma()->setConstant(kTRUE);
0024 
0025     fitter_.initGaussFrac( 0.5, 0., 1. );
0026     fitter_.initExpCoeffa1( -1., -10., 0. );
0027     fitter_.initFsig(0.5, 0., 1.);
0028   };
0029 
0030   void fit(const double & xMin, const double & xMax, const TString & fileNum = "0",
0031        const TString & signalType = "doubleGaussian", const TString & backgroundType = "exponential")
0032   {
0033     TFile * inputFile1 = new TFile(fileNum+"_MuScleFit.root", "READ");
0034     TH1F * histo1 = (TH1F*)inputFile1->Get("hRecBestResAllEvents_Mass");
0035     histo1->Rebin(rebinX);
0036 
0037     TFile * outputFile = new TFile("MassFit_"+fileNum+".root", "RECREATE");
0038     outputFile->cd();
0039 
0040     fitter_.fit(histo1, signalType, backgroundType, xMin, xMax);
0041     // fitter_.fit(histo1, "doubleGaussian", "exponential", xMin, xMax);
0042     // fitter_.fit(it->second, "gaussian", "exponential", xMin, xMax);
0043 
0044     outputFile->Write();
0045     outputFile->Close();
0046   }
0047 
0048   FitWithRooFit * fitter()
0049   {
0050     return( &fitter_ );
0051   }
0052 protected:
0053   int rebinX;
0054   FitWithRooFit fitter_;
0055 };