get_fit.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <TMath.h>
  2. #include <TSystem.h>
  3. #include <TFile.h>
  4. #include <TTree.h>
  5. #include <TString.h>
  6. #include "TROOT.h"
  7. #include <TH1.h>
  8. #include <TF1.h>
  9. #include <iostream>
  10. const float ptBins[] = {0.,0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.};
  11. const int NptBins = 12;
  12. const float etaBins[] = {-1.5,-1.2,-1.,-0.8,-0.6,-0.4,-0.2,0.,0.2,0.4,0.6,0.8,1.,1.2,1.5};
  13. const int NetaBins = 14;
  14. const int Ndim = 3;
  15. void get_fit(TString inFileName , TString outFileName)
  16. {
  17. TH1F* h_dca[Ndim][NptBins][NetaBins];
  18. TF1 *dca_fit[Ndim][NptBins][NetaBins];
  19. char name[200];
  20. char title[200];
  21. TFile *inFile = new TFile(inFileName.Data(),"READ");
  22. TFile *outFile = new TFile(outFileName.Data(),"RECREATE");
  23. for (int dim = 0; dim < Ndim; ++dim)
  24. {
  25. for (int ptbin = 0; ptbin < NptBins; ++ptbin)
  26. {
  27. for (int etabin = 0; etabin < NetaBins; ++etabin)
  28. {
  29. sprintf(name,"h_dca_%i_%i_%i",dim,ptbin,etabin);
  30. h_dca[dim][ptbin][etabin] = (TH1F*)inFile->Get(name);
  31. sprintf(name,"dca_fit_%i_%i_%i",dim,ptbin,etabin);
  32. dca_fit[dim][ptbin][etabin] = new TF1(name,"gaus",-0.2,0.2);
  33. h_dca[dim][ptbin][etabin]->Fit(name,"R");
  34. h_dca[dim][ptbin][etabin]->Write();
  35. dca_fit[dim][ptbin][etabin]->Write();
  36. }
  37. }
  38. }
  39. }