~maddevelopers/mg5amcnlo/WWW5_caching

« back to all changes in this revision

Viewing changes to users/mardelcourt/PROC_141512/PROC_141512/bin/internal/plot_tree.C

  • Committer: John Doe
  • Date: 2013-03-25 20:27:02 UTC
  • Revision ID: john.doe@gmail.com-20130325202702-5sk3t1r8h33ca4p4
first clean version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <string>
 
2
 
 
3
bool plot_tree(char* quantity,char* plotdim="(100,0.,3.)",bool log=true)
 
4
{
 
5
  char tmp1[250];
 
6
  char tmp2[300];
 
7
  char tmp3[100];
 
8
  sprintf(tmp2,"pythia.root");
 
9
 
 
10
  TFile* file;
 
11
  file=new TFile(tmp2);
 
12
  if(!file->IsOpen()) {
 
13
    cout << "No file "<<tmp2<<endl;
 
14
    return false;
 
15
  }
 
16
  file->cd();
 
17
 
 
18
  gROOT->SetStyle("Plain");
 
19
  const int maxjets=1+4;
 
20
  TH1F* hists[maxjets];
 
21
  sprintf(tmp3,"%s",quantity);
 
22
  TCanvas* c1=new TCanvas(tmp3,tmp3);
 
23
  c1->SetLogy();
 
24
  TLegend* leg=new TLegend(0.99,0.7,0.7,0.95);
 
25
  sprintf(tmp3,"l%s",quantity);
 
26
  leg->SetName(tmp3);
 
27
  int color[5]={2,4,3,5,6};
 
28
  int style[5]={2,3,4,3,4};
 
29
 
 
30
  //  bool ptw=false;
 
31
  TLeaf *leaf_Xsec = xsecs->FindLeaf("Xsecfact");
 
32
  Float_t Xsecfact;
 
33
  leaf_Xsec->SetAddress(&Xsecfact);
 
34
  xsecs->GetEntry(0);
 
35
 
 
36
  for(int i=0;i<maxjets && events->GetEntries()>0;i++){
 
37
    events->SetLineWidth(2);
 
38
    events->SetLineColor(color[i]);
 
39
    events->SetLineStyle(style[i]);
 
40
    
 
41
    if(log) 
 
42
      sprintf(tmp1,"log10(%s)>>%s%i%s",quantity,quantity,i,plotdim);
 
43
    else 
 
44
      sprintf(tmp1,"%s>>%s%i%s",quantity,quantity,i,plotdim);
 
45
    sprintf(tmp2,"%e*(Npart==%i)",Xsecfact,i);
 
46
 
 
47
    cout << "events->Draw("<<tmp1<<","<<tmp2<<");"<<endl;
 
48
    events->Draw(tmp1,tmp2);
 
49
 
 
50
    sprintf(tmp3,"%s%i",quantity,i);
 
51
    hists[i]=(TH1F*)gROOT->FindObject(tmp3);
 
52
    if(!hists[i]){
 
53
      cout << "Failed to get object "<<tmp3<<endl;
 
54
      return false;
 
55
    }
 
56
  }
 
57
 
 
58
 
 
59
  TH1F *hsum = (TH1F*)hists[0]->Clone();
 
60
  sprintf(tmp3,"%ssum",quantity);
 
61
  hsum->SetName(tmp3);
 
62
  for(int i=1;i<maxjets;i++)
 
63
    hsum->Add(hists[i]);
 
64
  cout << "Integral of "<<quantity<<": "<<hsum->Integral()<<endl;
 
65
  hsum->SetLineWidth(2);
 
66
  hsum->SetLineColor(1);
 
67
  hsum->SetLineStyle(1);
 
68
  //  hsum->SetMinimum(hsum->GetMaximum()*1e-3);
 
69
  hsum->SetStats(kFALSE);
 
70
  sprintf(tmp3,"%s",quantity);
 
71
  hsum->SetTitle(tmp3);
 
72
  sprintf(tmp3,"log10(%s)",quantity);
 
73
  hsum->GetXaxis()->SetTitle(tmp3);
 
74
  hsum->GetYaxis()->SetTitle("Cross section (pb/bin)");
 
75
  hsum->Draw();
 
76
  leg->AddEntry(hsum->GetName(),"Sum of contributions");
 
77
 
 
78
  for(int i=0;i<maxjets;i++){
 
79
    hists[i]->Draw("same");
 
80
    sprintf(tmp3,"%i-jet sample",i);
 
81
    leg->AddEntry(hists[i]->GetName(),tmp3);
 
82
  }
 
83
 
 
84
  leg->Draw();
 
85
 
 
86
  sprintf(tmp2,"%s.eps",quantity);
 
87
  cout << "Saving plot as " << tmp2 << endl;
 
88
  c1->SaveAs(tmp2);
 
89
  return true;
 
90
}
 
91