FairRoot/PandaRoot
ana_track.C
Go to the documentation of this file.
1 // root macro to analyze the simulation output
2 //void convertMCPoints()
3 
5  {
6  Double_t arg = 0;
7  if (par[2] != 0) arg = (v[0] - par[1])/par[2];
8 
9  Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg);
10  return fitval;
11  }
12 
13 int ana_track(){
14 
15  // ----- Load libraries ------------------------------------------------
16 //``gSystem->Load("fstream.h");
17  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
18 
19  gSystem->Load("libHyp");
20  // ----- Timer --------------------------------------------------------
21  TStopwatch timer;
22  timer.Start();
23  // ------------------------------------------------------------------------
24 
25  gStyle->SetPalette(1);
26 
27  TFile* f = new TFile("HypIdrecdos2.root"); // the sim file you want to analyse
28  TCanvas *c1 = new TCanvas("c1","the fit canvas",700,800);
29  TH1F* h = (TH1F*)f->Get("PndHypDKalman/pH");
30  h->Draw();
31 
32  cout<<" Peak search and gauss fit on the spectrum..."<<endl;
33  //Use TSpectrum to find the peak candidates
34  TSpectrum *s = new TSpectrum(50);
35  Int_t nfound = s->Search(h,0.006,"",0.2);
36  cout<<" **** "<<nfound <<" peaks are found by the peak search."<<endl;
37 
38  Float_t *xpeaks = s->GetPositionX();
39  Float_t xp =xpeaks[0];
40  Int_t bin = h->GetXaxis()->FindBin(xp);
41  Float_t yp = h->GetBinContent(bin);
42 
43 
44  // Creates a Root function based on function fitf above
45 
46  TF1 *func = new TF1("fitf",fitf,0.,0.2,3);
47 
48  // Sets initial values and parameter names
49 
50  func->SetParameter(0,yp);
51 
52  func->SetParName(0,"A");
53 
54  func->SetParameter(1,xp);
55  //func->SetParLimits(1,,limr[1]);
56  func->SetParName(1,"m2");
57 
58  func->SetParameter(2,0.003);
59  //func->SetParLimits(2,0.1,10);//(1,19)
60  func->SetParName(2,"sigma");
61 
62  cout << "Starting the fitting" << endl;
63 
64 
65  h->Fit(func,"r");
66 
67  Float_t Mean =func->GetParameter(1);
68  Float_t sig =func->GetParameter(2);
69 
70 cout<<" fit parameters "<<" Mean "<<Mean<<" "<<" sigma "<<sig<<endl;
71 
72  // ----- Finish -------------------------------------------------------
73  timer.Stop();
74  Double_t rtime = timer.RealTime();
75  Double_t ctime = timer.CpuTime();
76  cout << endl << endl;
77  cout << "Macro finished succesfully." << endl;
78  //cout << "Output file is " << outFile << endl;
79  //cout << "Parameter file is " << parFile << endl;
80  cout << "Real time " << rtime << " s, CPU time " << ctime << " s" << endl;
81  cout << endl;
82  // ------------------------------------------------------------------------
83 
84  return 0;
85 }
int ana_track()
Definition: ana_track.C:13
TF1 * func
TLorentzVector s
Definition: Pnd2DStar.C:50
Double_t par[3]
__m128 v
Definition: P4_F32vec4.h:4
Double_t
TStopwatch timer
Definition: hit_dirc.C:51
TFile * f
Definition: bump_analys.C:12
c1
Definition: plot_dirc.C:35
Double_t ctime
Definition: hit_dirc.C:114
Double_t rtime
Definition: hit_dirc.C:113
Double_t fitf(Double_t *v, Double_t *par)
Definition: ana_track.C:4