00001 #include "TFile.h"
00002 #include "TGraphErrors.h"
00003 #include "TCanvas.h"
00004 #include "TH2.h"
00005 #include "TLine.h"
00006 #include <vector>
00007 #include "TStyle.h"
00008 #include "TText.h"
00009 #include "TGaxis.h"
00010 #include "TROOT.h"
00011 #include <iostream>
00012
00013 using namespace std;
00014
00015
00016 double xshift=0;
00017
00018 void drawSetLimits(double ymin, double ymax)
00019 {
00020 vector<int> runs;
00021
00022 int firstset=55;
00023
00024 runs.push_back(122213);
00025 runs.push_back(122223);
00026 runs.push_back(122466);
00027 runs.push_back(122596);
00028 runs.push_back(122597);
00029 runs.push_back(122732);
00030 runs.push_back(122735);
00031 runs.push_back(122850);
00032 runs.push_back(122851);
00033 runs.push_back(123037);
00034 runs.push_back(123039);
00035 runs.push_back(123224);
00036 runs.push_back(123227);
00037 runs.push_back(123363);
00038 runs.push_back(123367);
00039 runs.push_back(123487);
00040 runs.push_back(123489);
00041 runs.push_back(123564);
00042
00043 char set[80];
00044
00045 for ( size_t i = 0; i < runs.size(); ++i )
00046 {
00047 TLine* l = new TLine(runs[i]+xshift,ymin,runs[i]+xshift,ymax);
00048 l->SetLineStyle(2);
00049 l->SetLineColor(4);
00050 l->Draw();
00051 sprintf(set,"S%d",firstset+i/2);
00052 if ( i % 2 == 0 )
00053 {
00054 TText* t = new TText(runs[i]+xshift,ymax*0.8,set);
00055 t->SetTextAngle(45);
00056 t->SetTextSize(0.03);
00057 t->Draw();
00058 }
00059 }
00060 }
00061
00062 void drawRunLimits(double ymin, double ymax)
00063 {
00064 vector<int> runs;
00065
00066
00067
00068 runs.push_back(106935);
00069 runs.push_back(122223);
00070
00071 runs.push_back(122466);
00072 runs.push_back(123564);
00073
00074
00075
00076
00077
00078 runs.push_back(149539);
00079 runs.push_back(160487);
00080
00081
00082
00083 runs.push_back(161197);
00084 runs.push_back(163627);
00085
00086
00087
00088 for ( size_t i = 0; i < runs.size(); ++i )
00089 {
00090 TLine* l = new TLine(runs[i]+xshift,ymin,runs[i]+xshift,ymax);
00091 l->SetLineStyle(2);
00092 l->SetLineColor(4);
00093 l->Draw();
00094
00095
00096
00097
00098
00099
00100
00101
00102 }
00103 }
00104
00105
00106 void
00107 sectorOnlineToOffline(int sectorOnline, int& arm,
00108 int& offline_sector)
00109 {
00110 if ( sectorOnline < 0 || sectorOnline > 8 )
00111 {
00112 arm=-1;
00113 offline_sector=-1;
00114 }
00115
00116 if ( sectorOnline < 4 )
00117 {
00118 arm = 0;
00119 offline_sector = sectorOnline;
00120 }
00121 else if ( sectorOnline < 6 )
00122 {
00123 arm = 1;
00124 offline_sector = sectorOnline-2;
00125 }
00126 else
00127 {
00128 arm = 1;
00129 offline_sector = sectorOnline-6;
00130 }
00131 }
00132
00133 void shift(TGraphErrors* g, double xshift)
00134 {
00135 for ( int i = 0; i < g->GetN(); ++i )
00136 {
00137 double x,y;
00138 g->GetPoint(i,x,y);
00139 g->SetPoint(i,x+xshift,y);
00140 g->SetPointError(i,0.5,0);
00141 }
00142 }
00143
00144 void draw(const char* sector,
00145 double xmin, double xmax, double ymin, double ymax,
00146 TGraphErrors** g, int n)
00147 {
00148 TH2* h = (TH2*)(gPad->FindObject(sector));
00149 if (!h)
00150 {
00151 cout << "Creating frame histo " << sector << endl;
00152 h = new TH2F(sector,sector,100,xmin+xshift,xmax+xshift,100,ymin,ymax);
00153 h->Draw();
00154
00155 h->SetNdivisions(420);
00156 }
00157
00158 int color[] = { 1,2,4,5,6,7 } ;
00159 int marker[] = { 20,21,22,23,24,25 } ;
00160
00161 for (int i = 0; i < n; ++i )
00162 {
00163 if ( !g[i] ) continue;
00164 TGraphErrors* gc = (TGraphErrors*)g[i]->Clone();
00165 shift(gc,xshift);
00166 gc->SetLineStyle(i+1);
00167 gc->SetLineColor(color[i]);
00168 gc->SetMarkerColor(color[i]);
00169 gc->SetMarkerStyle(marker[i]);
00170 gc->SetMarkerSize(0.7);
00171 cout << "Drawing " << gc->GetName() << endl;
00172 gc->Draw("LP");
00173
00174 }
00175 }
00176
00177 void getGraphLimits(TGraphErrors& g, double& xmin, double& xmax)
00178 {
00179 xmin = g.GetX()[0];
00180 xmax = g.GetX()[g.GetN()-1];
00181 }
00182
00183 void draw_GainEvolution(const char* file="gainEvolution.runlist_63GeV_good_and_or_ppg.root", const char* type = "92446_abs", double ymin=0, double ymax=0, double xmin=0, double xmax=0)
00184
00185
00186
00187 {
00188 TGaxis::SetMaxDigits(7);
00189 gROOT->SetStyle("Plain");
00190
00191 gStyle->SetOptStat(0);
00192
00193 TFile* f = new TFile(file);
00194
00195 const int NG = 4;
00196 const int NS = 6;
00197
00198 TGraphErrors* g[NG];
00199
00200 const char* sectors[] = { "W0","W1","W2","W3","E2","E3" };
00201 const char* gpattern[] =
00202 {
00203 "g%s_0_x_ZS_AVOFRATIO_%s",
00204 "g%s_5_x_ZS_AVOFRATIO_%s",
00205 "g%s_0_x_ZS_AVOFASYM_%s",
00206 "g%s_5_x_ZS_AVOFASYM_%s"
00207 };
00208
00209 TCanvas* c = new TCanvas("c","c",800,600);
00210 c->Divide(2,4,0.001,0.001);
00211 c->Draw();
00212
00213
00214
00215 int ipad[] = { 7,5,3,1,4,2,8,6 };
00216
00217 for ( int i = 0; i < NS; ++i )
00218 {
00219 for ( int ig = 0; ig < NG; ++ig )
00220 {
00221 char gname[80];
00222 sprintf(gname,gpattern[ig],sectors[i],type);
00223 g[ig] = (TGraphErrors*)f->Get(gname);
00224 if ( !g[ig] )
00225 {
00226 printf("Graph %s does not exist in file\n",gname);
00227 continue;
00228 }
00229
00230 if ( xmin==0 && xmax==0 )
00231 {
00232 getGraphLimits(*(g[ig]),xmin,xmax);
00233 printf("%f %f\n",xmin,xmax);
00234 }
00235 }
00236
00237 char cname[80];
00238 sprintf(cname,"%s_%s",sectors[i],type);
00239 int arm,sector;
00240 sectorOnlineToOffline(i,arm,sector);
00241
00242
00243
00244
00245
00246 TVirtualPad* pad = c->cd(ipad[i]);
00247 pad->SetGridy();
00248 pad->SetGridx();
00249 pad->SetTicky();
00250 pad->SetTickx();
00251 pad->SetRightMargin(0.01);
00252 pad->SetTopMargin(0.01);
00253
00254 draw(sectors[i],xmin,xmax,ymin,ymax,g,NG);
00255
00256 drawRunLimits(ymin,ymax);
00257
00258 pad->Update();
00259
00260
00261
00262 }
00263 }