Project

General

Profile

showPlots_withStyle.C

make the canvas plots - Muhammad Elnimr, 02/04/2015 12:32 PM

 
1
void prettyPlots()
2
{
3
  //    gROOT  -> SetStyle("Default");
4
  //    gROOT  -> SetStyle("Plain");
5
  gStyle->SetNdivisions(110,"xyz");
6
  gStyle -> SetStatFont(42);
7
  gStyle -> SetOptStat(0);
8

    
9
  //  gROOT  ->ForceStyle();
10
  gStyle -> SetPalette(1);
11
  gStyle->SetStatX(0.8201149);
12
  gStyle->SetStatY(0.8444915);
13
  //  gStyle->SetStatW(0.8807471);
14
  //  gStyle->SetStatH(0.8644068);
15

    
16
  gStyle -> SetLabelFont(42,"XYZ");
17
  gStyle -> SetTitleFont(42, "XYZ");
18
  gStyle -> SetLabelSize(0.04, "XYZ");
19
  gStyle -> SetTitleSize(0.05, "XYZ");
20
  gStyle -> SetTitleOffset(1.0, "X");
21
  gStyle -> SetTitleOffset(1.0, "Y");
22
  gStyle -> SetTitleOffset(1.0, "Z");
23
}  
24

    
25

    
26
void showPlots_withStyle(char * fileName="display_hist.root",bool log=0)
27
{
28

    
29
  prettyPlots();
30
  TFile * file=new TFile(fileName);
31
   
32
  TString stringArr[]={
33
    "ephi",
34
    "etheta",
35
    "etheta_xz",
36
    "etheta_yz",
37
    "elen",
38
    "emom",
39
    "hetrkspacepoints",
40
    "hetrkhits",
41
    "hetrkclust",
42
    "elenshort"
43
  }
44

    
45
TString axisName[]={
46
    "#phi",
47
    "#theta",
48
    "#theta_xz",
49
    "#theta_yz",
50
    "Length (cm)",
51
    "Momentum (GeV)",
52
    "No. Spacepoints",
53
    "No. all Hits ",
54
    "No. Clusters",
55
    "Length (cm)"
56
  }
57
  
58
  //  TDirectory * dirReco = (TDirectory*)file->Get("display_hist.root");
59
  TCanvas * canvas[20];
60
  
61
  for(int i=0;i<10;i++)
62
    {
63
      TString tmpNameCan="can"; tmpNameCan+=i;canvas[i] = new TCanvas(tmpNameCan, tmpNameCan,11,55,700,500);
64
      TH1F  * tmpHist1;
65
      TH1F  * tmpHist2;
66
      TH1F  * tmpHist3;
67
      TH1F  * tmpHist4;
68
      //      TH1F  * tmpHist5;
69

    
70
      TString tmpString1=stringArr[i]+"_anatreedc";
71
      TString tmpString2=stringArr[i]+"_anatreepandoradc";
72
      TString tmpString3=stringArr[i]+"_anatree";
73
      TString tmpString4=stringArr[i]+"_anatreepandora";
74
      //      TString tmpString5=stringArr[i]+"_anatreecheat";
75
      
76

    
77
      gDirectory->GetObject(tmpString1,tmpHist1);
78
      gDirectory->GetObject(tmpString2,tmpHist2);
79
      gDirectory->GetObject(tmpString3,tmpHist3);
80
      gDirectory->GetObject(tmpString4,tmpHist4);
81
      //      gDirectory->GetObject(tmpString5,tmpHist5);
82
      //      new TCanvas;
83
      tmpHist1->Draw();
84
      //      tmpHist1->SetMaximum(0.6);
85
      tmpHist3->Draw("same");
86
      tmpHist1->SetMarkerStyle(32);
87

    
88
      TCanvas * tmpcan=(TCanvas *)gROOT->FindObject(tmpNameCan);
89
      makeCanvas_withStyle(tmpHist1,tmpcan,"hist",axisName[i],"Efficiency");  
90
      
91
      /////
92
      //      if(!(i==6 || i==8))
93
      {
94
      tmpHist2->Draw("same");
95
      tmpHist2->SetMarkerColor(kRed);
96
      tmpHist2->SetMarkerStyle(32);
97
      tmpHist4->Draw("same");
98
      tmpHist4->SetMarkerColor(kRed);
99
      //      tmpHist5->Draw("same");
100
      //     tmpHist5->SetMarkerColor(kBlue);
101
      }
102

    
103
      TLegend * leg;
104
      if(log)
105
        leg = new TLegend(0.5028736,0.1122881,0.8836207,0.3114407,NULL,"brNDC");
106
      else leg = new TLegend(0.1824713,0.7648305,0.5632184,0.9639831,NULL,"brNDC");//0.1,0.7,0.48,0.9);
107
      leg->SetHeader("Histograms");
108
      leg->AddEntry(tmpHist1,"CosmicTracker_DisambigCheat","lep");
109
      //      if(!(i==6 || i==8)) 
110
        leg->AddEntry(tmpHist2,"Pandora_DisambigCheat","lep");
111
      leg->AddEntry(tmpHist3,"CosmicTracker","lep");
112
      //      if(!(i==6 || i==8))
113
        leg->AddEntry(tmpHist4,"Pandora","lep");
114
        //leg->AddEntry(tmpHist5,"CosmicTracker_allcheat","lep");
115
      leg->Draw();
116
      
117
      if(log){
118
      tmpHist1->SetMinimum(0.0001);
119
      tmpHist2->SetMinimum(0.0001);
120
      tmpHist3->SetMinimum(0.0001);
121
      tmpHist4->SetMinimum(0.0001);
122
      canvas[i]->SetLogy();}
123
      TString tt=tmpcan->GetName();
124
      tt+=".png";
125
      tmpcan->SaveAs(tt);
126
    }
127
  
128
}
129
void makeCanvas_withStyle(TH1F * h,TCanvas * myC,char * canvTitle,char * ch1,char * ch2)
130
{
131
  //  prettyPlots();
132
  //  gStyle->SetOptStat(0);
133
  gStyle->SetOptTitle(0);
134

    
135
   gStyle -> SetLabelSize(0.06, "X");
136
   gStyle -> SetLabelSize(0.06, "Y");
137
   gStyle -> SetLabelOffset(0.017, "X");
138
   gStyle -> SetLabelOffset(0.010, "Y");
139

    
140
  gStyle -> SetTitleSize(0.06, "X");
141
  gStyle -> SetTitleSize(0.06, "Y");
142

    
143

    
144
  gStyle -> SetTitleOffset(1.25, "X");
145
  gStyle -> SetTitleOffset(1.0, "Y");
146

    
147
//--- Define the canvas:
148
 
149
// TCanvas *myC = new TCanvas ("myC",canvTitle,700,500);
150
 myC->SetBorderSize(0);
151

    
152
//--- Primitives in pad p1:
153

    
154
 TString tmpName="Pad";
155
 tmpName+=myC->GetName();
156
 // TPad *p1 = new TPad(tmpName,tmpName,0.06181202,0.3675079,0.5825572,0.6845426);//0.001,0.001,0.99,0.999);
157
 // p1->Draw(); p1->cd(); p1->SetBorderSize(0);
158
 // p1->SetTopMargin   (0.07); p1->SetRightMargin(0.04);
159
 // p1->SetBottomMargin(0.17); p1->SetLeftMargin (0.17);
160
 gStyle->SetOptStat(0);
161

    
162
   myC->Range(-20.82585,-0.2395226,104.1293,1.075066);
163
   myC->SetFillColor(0);
164
   myC->SetBorderMode(0);
165
   myC->SetBorderSize(0);
166
   myC->SetLeftMargin(0.1666667);
167
   myC->SetRightMargin(0.03304598);
168
   myC->SetTopMargin(0.0190678);
169
   myC->SetBottomMargin(0.1822034);
170
   myC->SetFrameBorderMode(0);
171
   myC->SetFrameBorderMode(0);
172
 h->SetXTitle(ch1);
173
 h->SetYTitle(ch2);
174
 // h->Draw("");
175

    
176
 //p1->Modified(); myC->cd();
177
 //  gROOT->ForceStyle();
178

    
179
}
180
Save(char * tcanvTitle)
181
{
182
  TString tmp="";
183
  tmp+=tcanvTitle;
184
  tmp+=".png";
185
  myC->Print(tmp);
186
}
187

    
188

    
189