FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
runPull.C
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 int runPull(std::string propName = "rk", bool drawHist = false)
9 {
10  if (propName != "geane" && propName != "rk") {
11  cout << "Choose either \"geane\" or \"rk\"." << endl;
12  return 1;
13  }
14 
15  gROOT->Reset();
16  gStyle->SetOptFit(1);
17 
18  TFile *f = new TFile(Form("prop.%s.cal.root", propName.data()));
19  TTree *simtree = (TTree *)f->Get("cbmsim");
20 
21  TClonesArray *fTrackParProp = new TClonesArray("FairTrackParP");
22  TClonesArray *fTrackParIni = new TClonesArray("FairTrackParP");
23  TClonesArray *fTrackParFinal = new TClonesArray("FairTrackParP");
24 
25  Double_t maxDist = 0.1;
26  TH1F *hQP = new TH1F("hQP", "charge over momentum", 200, -maxDist, maxDist);
27  TH1F *hX = new TH1F("hX", "position X", 200, -maxDist, maxDist);
28  TH1F *hY = new TH1F("hY", "position Y", 200, -maxDist, maxDist);
29  TH1F *hPx = new TH1F("hPx", "momentum X", 200, -maxDist, maxDist);
30  TH1F *hPy = new TH1F("hPy", "momentum Y", 200, -maxDist, maxDist);
31  TH1F *hPz = new TH1F("hPz", "momentum Z", 200, -maxDist, maxDist);
32 
33  simtree->SetBranchAddress("PropTrackFinal", &fTrackParFinal);
34  simtree->SetBranchAddress("PropTrackPar", &fTrackParProp);
35  FairTrackParP *fTrkF;
36  FairTrackParP *fTrkG;
37  Int_t Nevents = simtree->GetEntriesFast();
38  cout << Nevents << endl;
39  for (Int_t i = 0; i < Nevents; i++) {
40  simtree->GetEntry(i);
41  for (Int_t k = 0; k < fTrackParProp->GetEntriesFast(); k++) {
42  fTrkF = (FairTrackParP *)fTrackParFinal->At(k);
43  fTrkG = (FairTrackParP *)fTrackParProp->At(k);
44  if (fTrkF && fTrkG) {
45  hQP->Fill(fTrkF->GetQp() - fTrkG->GetQp());
46  hX->Fill(fTrkF->GetX() - fTrkG->GetX());
47  hY->Fill(fTrkF->GetY() - fTrkG->GetY());
48  hPx->Fill(fTrkF->GetPx() - fTrkG->GetPx());
49  hPy->Fill(fTrkF->GetPy() - fTrkG->GetPy());
50  hPz->Fill(fTrkF->GetPz() - fTrkG->GetPz());
51  // if(fTrkG->GetDQp()) hQP->Fill((fTrkF->GetQp()-fTrkG->GetQp())/fTrkG->GetDQp());
52  // if(fTrkG->GetDX() ) hX ->Fill((fTrkF->GetX() -fTrkG->GetX()) /fTrkG->GetDX());
53  // if(fTrkG->GetDY() ) hY ->Fill((fTrkF->GetY() -fTrkG->GetY()) /fTrkG->GetDY());
54  // if(fTrkG->GetDPx()) hPx->Fill((fTrkF->GetPx()-fTrkG->GetPx())/fTrkG->GetDPx());
55  // if(fTrkG->GetDPy()) hPy->Fill((fTrkF->GetPy()-fTrkG->GetPy())/fTrkG->GetDPy());
56  // if(fTrkG->GetDPz()) hPz->Fill((fTrkF->GetPz()-fTrkG->GetPz())/fTrkG->GetDPz());
57  }
58  }
59  }
60  if (drawHist) {
61  TCanvas *c = new TCanvas("c", "c", 900, 600);
62  c->Divide(3, 2);
63  c->cd(1);
64  hQP->Draw();
65  hQP->Fit("gaus");
66  c->cd(2);
67  hX->Draw();
68  hX->Fit("gaus");
69  c->cd(3);
70  hY->Draw();
71  hY->Fit("gaus");
72  c->cd(4);
73  hPx->Draw();
74  hPx->Fit("gaus");
75  c->cd(5);
76  hPy->Draw();
77  hPy->Fit("gaus");
78  c->cd(6);
79  hPz->Draw();
80  hPz->Fit("gaus");
81 
82  c->cd();
83  }
84 
85  TF1 *fitX = new TF1("fitX", "gaus", -5., 5.);
86  hX->Fit("fitX", "QN");
87 
88  if (fitX->GetParameter(1) > -1.e-3 && fitX->GetParameter(1) < 1.e-3 && fitX->GetParameter(2) > 0.
89  && fitX->GetParameter(2) < 1.e-2)
90  cout << "Macro finished successfully. Mean (" << fitX->GetParameter(1) << ") and sigma ("
91  << fitX->GetParameter(2) << ") inside limits." << endl;
92  else
93  cout << "Macro failed. Mean (" << fitX->GetParameter(1) << ") or sigma (" << fitX->GetParameter(2)
94  << ") too far off." << endl;
95 
96  return 0;
97 }
virtual Double_t GetPz() const
Definition: FairTrackPar.h:62
virtual Double_t GetQp() const
Definition: FairTrackPar.h:63
virtual Double_t GetPx() const
Definition: FairTrackPar.h:60
int runPull(std::string propName="rk", bool drawHist=false)
Definition: runPull.C:8
virtual Double_t GetPy() const
Definition: FairTrackPar.h:61
virtual Double_t GetY()
Definition: FairTrackPar.h:50
virtual Double_t GetX()
Definition: FairTrackPar.h:49