ROOTPWA
Fit_Energy_dependence.C
Go to the documentation of this file.
1 // reading BeamPar_70507 in order to retrieve the depencence of the energy on the vertex position
2 // the histograms will be fitted and the fitted values will be filled into 2D histograms
3 // depending on the vertex position
4 //
5 // to do: for each x,y bin set one has produce the energy distribution fit it and
6 // write the mean value and sigma to a TH2(x,y)
7 //
8 // do > root -l fit_Energy_dependence.C+ // to run it
9 // by P. Jasinski Promme@web.de jasinski@kph.uni-mainz.de
10 // BeamPar_70507.root was produced by Hauke Wöhrmann Hauke.Woehrmann@physik.uni-muenchen.de
11 // big thanx for that!
12 
13 
14 #include <iostream>
15 #include "TFile.h"
16 #include "TH2.h"
17 #include "TH1.h"
18 #include "TF1.h"
19 #include "TROOT.h"
20 #include "TStyle.h"
21 #include "TCanvas.h"
22 #include "TTree.h"
23 #include <string>
24 
25 using namespace std;
26 
27 const string filename("BeamPar_70507.root");
28 
30  // set some style options
31  gROOT->SetStyle("Plain");
32  gStyle->SetPalette(1);
33  // try to read the file containing the energy distributions
34  TFile* beampar = new TFile("BeamPar_70507.root");
35  if (beampar->IsZombie()){
36  cout << " Error: could not open file! " << endl;
37  return;
38  }
39  // retrieve the histograms
40  TH2* hEVsDX = (TH2*) gDirectory->Get("hEVsDX");
41  TH2* hEVsDY = (TH2*) gDirectory->Get("hEVsDY");
42  TH2* hEVsX = (TH2*) gDirectory->Get("hEVsX");
43  TH2* hEVsY = (TH2*) gDirectory->Get("hEVsY");
44  TH2* hdxdyB = (TH2*) gDirectory->Get("hdxdyB");
45  TH2* hxdxB = (TH2*) gDirectory->Get("hxdxB");
46  TH2* hxdyB = (TH2*) gDirectory->Get("hxdyB");
47  TH2* hydxB = (TH2*) gDirectory->Get("hydxB");
48  TH2* hydyB = (TH2*) gDirectory->Get("hydyB");
49  TH2* hxyB = (TH2*) gDirectory->Get("hxyB");
50  TTree* BpT = (TTree*) gDirectory->Get("BpT");
51 
52  if (!hEVsDX || !hEVsDY || !hEVsX || !hEVsY || !hdxdyB ||
53  !hxdxB || !hxdyB || !hydxB || !hydyB || !hxyB || !BpT ){
54  cout << " Error: At least one histogram could not be retrieved " << endl;
55  return;
56  }
57  TCanvas* canvas = new TCanvas ("canvas", "loaded histograms", 800, 800);
58  canvas->Divide(3,3);
59  canvas->cd(1);
60  hEVsDX->Draw("COLZ");
61  canvas->cd(2);
62  hEVsDY->Draw("COLZ");
63  canvas->cd(3);
64  hEVsX->Draw("COLZ");
65  canvas->cd(4);
66  hEVsY->Draw("COLZ");
67  canvas->cd(5);
68  hdxdyB->Draw("COLZ");
69  canvas->cd(6);
70  hxdxB->Draw("COLZ");
71  canvas->cd(7);
72  hxdyB->Draw("COLZ");
73  canvas->cd(8);
74  hydxB->Draw("COLZ");
75  canvas->cd(9);
76  hydyB->Draw("COLZ");
77  canvas->Update();
78  canvas->Print("Loaded_histograms.pdf");
79 
80  TFile* outputfile = new TFile("energy_distributions.root", "Recreate");
81 
82  // this part needs to get implemented...
83  // for (int x = 0; x < 21; x++){
84  // for (int y = 0; y < 21; y++){
85  // BpT->Draw("EBeamApprox", " .. < x && x < .. & .. < y && y < .. ");
86  // // get, fit, save
87  // see void UserEvent_basics_root_scripts::Analyze_beam_properties_output()
88  // to get a clue how to do it ...
89 
90  outputfile->Write();
91  outputfile->Close();
92 }
93 
94