Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef FitMassSlices_cc
0002 #define FitMassSlices_cc
0003 
0004 #include "FitSlices.cc"
0005 #include "TFile.h"
0006 #include "TH1F.h"
0007 #include "TROOT.h"
0008 
0009 /**
0010  * This class can be used to fit the X slices of a TH1 histogram using RooFit.
0011  * It uses the FitXslices class to do the fitting.
0012  */
0013 class FitMassSlices : public FitSlices
0014 {
0015 public:
0016 
0017   FitMassSlices(
0018     double xMean_ = 3.1,
0019     double xMin_ = 3.,
0020     double xMax_ = 3.2,
0021     double sigma_ = 0.03,
0022     double sigmaMin_ = 0.,
0023     double sigmaMax_ = 0.1,
0024     TString signalType_ = "gaussian",
0025     TString backgroundType_ = "exponential"
0026     ) :
0027     FitSlices(xMean_, xMin_, xMax_, sigma_, sigmaMin_, sigmaMax_, signalType_, backgroundType_)
0028   {}
0029 
0030   void fit(
0031     const TString & inputFileName = "0_MuScleFit.root", const TString & outputFileName = "BiasCheck_0.root",
0032     
0033     // change 0 if you want to rebin phi distributions
0034     const int rebinXphi = 4, const int rebinXetadiff = 2, const int rebinXeta = 2, const int rebinXpt = 8,//(ORIGINAL 64 bin in eta, 64 bin in phi, 32 bin in deltaEta, 200 bin in pt)
0035 
0036     TDirectory * externalDir = 0,
0037     const TString & histoBaseName = "hRecBestResVSMu", const TString & histoBaseTitle = "MassVs"
0038     ){
0039     gROOT->SetBatch(kTRUE);
0040 
0041     TFile* inputFile = TFile::Open(inputFileName, "READ");
0042     TFile* outputFile = 0;
0043     TDirectory * dir = externalDir;
0044     if (dir == 0) {
0045       outputFile = new TFile(outputFileName, "RECREATE");
0046       dir = outputFile->GetDirectory("");
0047     }
0048 
0049     fitSlice(histoBaseName+"_MassVSPt", histoBaseTitle+"Pt",
0050       inputFile, dir);
0051 
0052     //     fitSlice(histoBaseName+"_MassVSEta", histoBaseTitle+"Eta",
0053     //       inputFile, dir);
0054 
0055     if (rebinXeta != 0) rebinX = rebinXeta;
0056     fitSlice(histoBaseName+"_MassVSEtaPlus", histoBaseTitle+"EtaPlus",
0057       inputFile, dir);
0058 
0059     fitSlice(histoBaseName+"_MassVSEtaMinus", histoBaseTitle+"EtaMinus",
0060       inputFile, dir);
0061 
0062 
0063     fitSlice(histoBaseName+"_MassVSEtaPhiPlus", histoBaseTitle+"EtaPhiPlus",
0064       inputFile, dir);
0065 
0066     fitSlice(histoBaseName+"_MassVSEtaPhiMinus", histoBaseTitle+"EtaPhiMinus",
0067       inputFile, dir);
0068 
0069     //    //    New entries...        
0070     fitSlice(histoBaseName+"_MassVSCosThetaCS", histoBaseTitle+"CosThetaCS",
0071       inputFile, dir);
0072 
0073     fitSlice(histoBaseName+"_MassVSPhiCS", histoBaseTitle+"PhiCS",
0074       inputFile, dir);
0075 
0076     if (rebinXphi != 0) rebinX = rebinXphi;
0077     fitSlice(histoBaseName+"_MassVSPhiPlus", histoBaseTitle+"PhiPlus",
0078       inputFile, dir);
0079 
0080     fitSlice(histoBaseName+"_MassVSPhiMinus", histoBaseTitle+"PhiMinus",
0081       inputFile, dir);
0082 
0083 
0084     //     fitSlice(histoBaseName+"_MassVSPhiPlusMinusDiff", histoBaseTitle+"PhiPlusMinusDiff",
0085     //              inputFile, dir);
0086 
0087 
0088     //     fitSlice(histoBaseName+"_MassVSPhiPlusPhiMinus", histoBaseTitle+"PhiPlusPhiMinus",
0089     //              inputFile, dir);
0090 
0091     //     fitSlice(histoBaseName+"_MassVSEtaPlusEtaMinus", histoBaseTitle+"EtaPlusEtaMinus",
0092     //              inputFile, dir);
0093 
0094     if (rebinXetadiff != 0) rebinX = rebinXetadiff;
0095     fitSlice(histoBaseName+"_MassVSEtaPlusMinusDiff", histoBaseTitle+"EtaPlusMinusDiff",
0096       inputFile, dir);
0097 
0098     // Close the output file
0099     if (outputFile != 0) {
0100       outputFile->Write();
0101       outputFile->Close();
0102     }
0103   }
0104 };
0105 
0106 #endif