Added new library libFMDutil. This library contains utility classes that
[u/mrichter/AliRoot.git] / FMD / scripts / DrawXsection.C
1 void
2 DrawXsection(const char* file="xsec.root", 
3              const char* var="LOSS", 
4              const char* medName="FMD_Si$", 
5              Double_t thick=.03,
6              const char* pdgName="pi+")
7 {
8   TFile*   file = TFile::Open("xsec.root", "READ");
9   TTree*   tree = static_cast<TTree*>(file->Get(Form("%s_%s",medName,
10                                                      pdgName)));
11   TLeaf* tb   = tree->GetLeaf("T");
12   TLeaf* vb   = tree->GetLeaf(var);
13   if (!vb) {
14     std::cerr << "Leaf " << var << " not found" << std::endl;
15     return;
16   }
17   Float_t tkine, value;
18   tb->SetAddress(&tkine);
19   vb->SetAddress(&value);
20   Int_t n = tree->GetEntries();
21
22   TDatabasePDG* pdgDb = TDatabasePDG::Instance();
23   TParticlePDG* pdgP  = pdgDb->GetParticle(pdgName);
24   if (!pdgP) {
25     std::cerr << "Couldn't find particle " << pdgName << std::endl;
26     return;
27   }
28   Double_t m = pdgP->Mass();
29   Double_t q = pdgP->Charge() / 3;
30   if (m == 0) {
31     std::cerr  << "Mass is 0" << std::endl;
32     return;
33   }
34   
35   TGraph* graph = new TGraph(n);
36   for (Int_t i = 0; i < n; i++) {
37     tree->GetEntry(i);
38     graph->SetPoint(i, tkine/m/q/q, value*thick);
39   }
40   graph->Draw("ALP");
41 }
42
43 //____________________________________________________________________
44 //
45 // EOF
46 //