]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/scripts/DrawXsection.C
0. General code clean-up, including messages, and the like.
[u/mrichter/AliRoot.git] / FMD / scripts / DrawXsection.C
1 //____________________________________________________________________
2 //
3 // Script to draw a X-section, LOSS, or range made with MakeXsection
4 //
5 void
6 DrawXsection(Bool_t scale=kFALSE, 
7              const char* filename="xsec.root", 
8              const char* var="LOSS", 
9              const char* medName="FMD_Si$", 
10              Double_t thick=.03,
11              const char* pdgName="pi+")
12 {
13   TFile*   file = TFile::Open(filename, "READ");
14   TTree*   tree = static_cast<TTree*>(file->Get(Form("%s_%s",medName,
15                                                      pdgName)));
16   TLeaf* tb   = tree->GetLeaf("T");
17   TLeaf* vb   = tree->GetLeaf(var);
18   if (!vb) {
19     std::cerr << "Leaf " << var << " not found" << std::endl;
20     return;
21   }
22   Float_t tkine, value;
23   tb->SetAddress(&tkine);
24   vb->SetAddress(&value);
25   Int_t n = tree->GetEntries();
26
27   Float_t xscale = 1;
28   Float_t yscale = 1;
29   if (scale) {
30     TDatabasePDG* pdgDb = TDatabasePDG::Instance();
31     TParticlePDG* pdgP  = pdgDb->GetParticle(pdgName);
32     if (!pdgP) {
33       std::cerr << "Couldn't find particle " << pdgName << std::endl;
34       return;
35     }
36     Double_t m = pdgP->Mass();
37     Double_t q = pdgP->Charge() / 3;
38     if (m == 0 || q == 0) {
39       std::cerr  << "Mass is 0" << std::endl;
40       return;
41     }
42     xscale = 1 / m;
43     yscale = 1 / (q * q);
44   }
45   
46   TGraphErrors* graph = new TGraphErrors(n);
47   for (Int_t i = 0; i < n; i++) {
48     tree->GetEntry(i);
49     Double_t x = tkine*xscale;
50     Double_t y = value*yscale;
51     graph->SetPoint(i, x, y); 
52     // 5 sigma
53     graph->SetPointError(i, 0, 5 * .1 * y);
54   }
55   graph->SetLineWidth(2);
56   graph->SetFillStyle(3001);
57   graph->SetFillColor(6);
58   graph->Draw("L3 same");
59 }
60
61 //____________________________________________________________________
62 //
63 // EOF
64 //