Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "TFile.h"
0002 #include "TString.h"
0003 #include "TCanvas.h"
0004 #include "RooPlot.h"
0005 #include "RooHist.h"
0006 #include "RooCurve.h"
0007 #include "TPaveText.h"
0008 #include "FitMass.cc"
0009 
0010 void CompareMass()
0011 {
0012   gROOT->SetStyle("Plain");
0013 
0014   TString fileNum1 = "0";
0015   TString fileNum2 = "3";
0016 
0017   TString fitType1("gaussianPlusCrystalBall");
0018   TString fitType2("gaussianPlusCrystalBall");
0019   TString backgroundType("exponential");
0020 
0021   FitMass fitMass1;
0022   fitMass1.rebinX = 2;
0023   fitMass1.fitter()->initMean(3.1, 3., 3.2);
0024   fitMass1.fitter()->initSigma(0.03, 0., 10.);
0025   fitMass1.fitter()->initSigma2(1., 0., 10.);
0026   fitMass1.fitter()->initAlpha(1.9, 0., 10.);
0027   fitMass1.fitter()->initN(0.4, 0., 10.);
0028   fitMass1.fitter()->initFGCB(0.4, 0., 1.);
0029   fitMass1.fit(2.95, 3.25, fileNum1, fitType1, backgroundType);
0030   FitMass fitMass2;
0031   fitMass2.rebinX = 2;
0032   fitMass2.fitter()->initMean(3.1, 3., 3.2);
0033   fitMass2.fitter()->initSigma(0.03, 0., 10.);
0034   fitMass2.fitter()->initSigma2(1., 0., 10.);
0035   fitMass2.fitter()->initAlpha(1.9, 0., 10.);
0036   fitMass2.fitter()->initN(0.4, 0., 10.);
0037   fitMass2.fitter()->initFGCB(0.4, 0., 1.);
0038   fitMass2.fit(2.95, 3.25, fileNum2, fitType2, backgroundType);
0039 
0040   TString fileName1("MassFit_"+fileNum1+".root");
0041   TString fileName2("MassFit_"+fileNum2+".root");  
0042 
0043   TFile * file1 = new TFile(fileName1, "READ");
0044   RooPlot * rooPlot1 = (RooPlot*)file1->Get("hRecBestResAllEvents_Mass_frame");
0045 
0046   TFile * file2 = new TFile(fileName2, "READ");
0047   RooPlot * rooPlot2 = (RooPlot*)file2->Get("hRecBestResAllEvents_Mass_frame");
0048 
0049   TFile * outputFile = new TFile("CompareMass.root", "RECREATE");
0050   outputFile->cd();
0051   TCanvas * canvas = new TCanvas("canvas", "canvas", 1000, 800);
0052   canvas->Draw();
0053   rooPlot1->Draw();
0054   rooPlot1->GetXaxis()->SetTitle("");
0055   rooPlot1->SetTitle("");
0056   rooPlot2->Draw("same");
0057   rooPlot2->getHist("h_dh")->SetLineColor(kRed);
0058   rooPlot2->getHist("h_dh")->SetMarkerColor(kRed);
0059   rooPlot2->GetXaxis()->SetTitle("Mass (GeV)");
0060   rooPlot2->GetYaxis()->SetTitle("");
0061   rooPlot2->SetTitle("");
0062   RooCurve * curve = 0;
0063   TPaveText * paveText = 0;
0064   if( backgroundType != "" ) {
0065     curve = (RooCurve*)rooPlot2->findObject("model_Norm[x]");
0066     paveText = (TPaveText*)rooPlot2->findObject("model_paramBox");
0067   }
0068   else if( fitType2 == "gaussian" ) {
0069     curve = (RooCurve*)rooPlot2->findObject("gaussian_Norm[x]");
0070     paveText = (TPaveText*)rooPlot2->findObject("gaussian_paramBox");
0071   }
0072   else if( fitType2 == "doubleGaussian" ) {
0073     paveText = (TPaveText*)rooPlot2->findObject("doubleGaussian_paramBox");
0074     curve = (RooCurve*)rooPlot2->findObject("doubleGaussian_Norm[x]");
0075   }
0076   else if( fitType2 == "voigtian" ) {
0077     paveText = (TPaveText*)rooPlot2->findObject("voigt_paramBox");
0078     curve = (RooCurve*)rooPlot2->findObject("voigt_Norm[x]");
0079   }
0080   if( curve != 0 ) curve->SetLineColor(kRed);
0081   if( paveText != 0 ) paveText->SetTextColor(kRed);
0082   canvas->Write();
0083   outputFile->Write();
0084   outputFile->Close();
0085 }