ROOT logo
//____________________________________________________________________
//
// Script to plot the lego information 
// 
#ifndef __CINT__
# include <TFile.h>
# include <TCanvas.h>
# include <TPad.h>
# include <TH1D.h>
# include <TString.h>
# include <TLatex.h>
# include <TLegend.h>
# include <THStack.h>
# include <TStyle.h>
# include <iostream>
using namespace std;
#endif
/** @defgroup lego_script LEGO script
    @ingroup FMD_script 
*/
//____________________________________________________________________
/** @ingroup lego_script
    @param ang 
    @return  */
Float_t 
deg2eta(Float_t ang) 
{
  if (ang == 180) ang -= .001;
  if (ang == 0)   ang += .001;
  Float_t theta = ang * TMath::Pi() / 180;
  Float_t eta   = - TMath::Log(TMath::Tan(theta / 2));
  return eta;
}


//____________________________________________________________________
/** @ingroup lego_script
    @param which 
    @param what 
    @param back 
    @return  */
TH1* 
getHisto(const Char_t* which, const Char_t* what, TH1* back=0) 
{
  TFile* file = TFile::Open(Form("Lego_%s.root", which), "READ");
  if (!file) {
    cerr << "Couldn't open the file 'Lego_" << which << ".root" 
	 << endl;
    return 0;
  }
  TH1D*  h1d  = static_cast<TH1D*>(file->Get(Form("h%s_py", what)));
  if (!h1d) {
    cerr << "Couldn't find h" << what << "_py in " 
	 <<  "Lego_" << which << ".root" << endl;
    return 0;
  }

  TAxis* xaxis = h1d->GetXaxis();
  Int_t n = xaxis->GetNbins();
  TArrayF bins(n-1);
  for (Int_t i = n-1; i > 1; i--) {
    Float_t ang = xaxis->GetBinUpEdge(i);
    Float_t eta = deg2eta(ang);
    bins[n-i-1] = deg2eta(xaxis->GetBinUpEdge(i));
  }
  bins[n-2] = deg2eta(xaxis->GetBinLowEdge(2));
  
  TH1F* heta = new TH1F(Form("%s_eta", what), h1d->GetTitle(),
			n-2, bins.fArray);
  heta->SetXTitle("#eta");
  heta->GetXaxis()->SetTitleSize(0);
  heta->GetXaxis()->SetTitleOffset(1.5);
  heta->GetXaxis()->SetTitleFont(132);
  heta->GetXaxis()->SetLabelFont(132);
  heta->SetYTitle(Form("%s per degree", h1d->GetTitle()));
  heta->GetYaxis()->SetTitleOffset(1.5);
  heta->GetYaxis()->SetTitleFont(132);
  heta->GetYaxis()->SetLabelFont(132);
  heta->GetYaxis()->SetTitleSize(0);
  heta->GetZaxis()->SetTitle(heta->GetTitle());
  heta->GetZaxis()->SetTitleOffset(1.5);
  heta->GetZaxis()->SetTitleFont(132);
  heta->GetZaxis()->SetLabelFont(132);
  heta->GetYaxis()->SetTitleOffset(1.5);
  for (Int_t i = 2; i < n; i++) {
    Float_t ang = xaxis->GetBinUpEdge(i);
    Float_t eta = deg2eta(ang);
    Float_t y   = h1d->GetBinContent(i);
    Float_t j   = heta->FindBin(eta);
    if (back) {
      Float_t b = back->GetBinContent(j);
      if (y - b <= 0) y = .000001;
      else            y = y - b;
    }
    // cout << i << ": " << ang << " -> " << eta << " = " << y << endl;    
    heta->SetBinContent(j, y);
  }
  return heta;
}

//____________________________________________________________________
/** @ingroup lego_script
    @param what 
*/
void
drawLego(const char* what="abso") 
{
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetPadRightMargin(0.05);
  gStyle->SetPadTopMargin(0.05);
  gStyle->SetPadBottomMargin(0.15);
  gStyle->SetLabelFont(132, "xyz");
  gStyle->SetTitleFont(132, "xyz");
  gStyle->SetTitleOffset(1.5, "y");

  TH1* nothing = getHisto("Nothing", what);
  TH1* its     = getHisto("ITS",     what, nothing);
  TH1* fmd     = getHisto("FMD",     what, nothing);
  TH1* pipe    = getHisto("PIPE",    what, nothing);
  TH1* inner   = getHisto("Inner",   what);

  if (!inner || !pipe || !fmd || !its || !nothing) {
    cerr << "Failed to get a histogram!" << endl;
    return;
  }
  TCanvas* c = new TCanvas(Form("single_%s", what), 
			   Form("Single %s", what), 800, 800);
  c->SetFillColor(0);
  c->SetBorderMode(0);
  c->SetBorderSize(0);
  TPad* p1 = new TPad("p1", "p1", 0.0, 0.5, 0.5, 1.0, 0, 0, 0);
  TPad* p2 = new TPad("p2", "p2", 0.5, 0.5, 1.0, 1.0, 0, 0, 0);
  TPad* p3 = new TPad("p3", "p3", 0.0, 0.0, 0.5, 0.5, 0, 0, 0);
  TPad* p4 = new TPad("p4", "p4", 0.5, 0.0, 1.0, 0.5, 0, 0, 0);
  
  TLatex* latex = new TLatex(0,0,"");
  latex->SetTextFont(132);

  float logmax = inner->GetMaximum();
  float logmin = .001 * logmax;
  float latexy = 6 * logmin;
  
  c->cd();
  p1->SetLogy();
  p1->SetGridy();
  p1->SetTopMargin(0.15);
  p1->SetBottomMargin(0);
  p1->SetRightMargin(0);
  p1->Draw();
  p1->cd();
  fmd->SetFillColor(4);
  fmd->GetYaxis()->SetRangeUser(logmin, logmax);
  fmd->GetYaxis()->SetTitleSize(.04);
  fmd->Draw();
  latex->DrawLatex(-1, latexy, "FMD only");
  
  c->cd();
  p2->SetLogy();
  p2->SetGridy();
  p2->SetTopMargin(0.15);
  p2->SetBottomMargin(0);
  p2->SetLeftMargin(0);
  p2->SetRightMargin(0.15);
  p2->Draw();
  p2->cd();
  its->SetFillColor(2);
  its->GetYaxis()->SetRangeUser(logmin, logmax);
  its->Draw();
  latex->DrawLatex(-1, latexy, "ITS only");

  c->cd();
  p3->SetLogy();
  p3->SetGridy();
  p3->SetTopMargin(0);
  p3->SetLeftMargin(0.15);
  p3->SetRightMargin(0);
  p3->Draw();
  p3->cd();
  pipe->SetFillColor(3);
  pipe->GetYaxis()->SetRangeUser(logmin, logmax);
  pipe->Draw();
  latex->DrawLatex(-1, latexy, "PIPE only");
  
  c->cd();
  p4->SetLogy();
  p4->SetGridy();
  p4->SetTopMargin(0);
  p4->SetLeftMargin(0.);
  p4->SetRightMargin(0.15);
  p4->Draw();
  p4->cd();
  inner->GetYaxis()->SetRangeUser(logmin, logmax);
  inner->GetXaxis()->SetTitleSize(.04);
  inner->SetFillColor(5);
  inner->Draw();
  latex->DrawLatex(-1, latexy, "PIPE, ITS, FMD and Air");
  
  c->Modified();
  c->cd();
  c->Print(Form("%s_single.png", what));

  TCanvas* accum = new TCanvas(Form("accum_%s", what), 
			       Form("Accumalted %s",what), 
			       800, 500);
  accum->SetLogy();
  accum->SetFillColor(0);
  accum->SetBorderMode(0);
  accum->SetBorderSize(0);

  THStack* stack = new THStack("stack", "Stack");
  nothing->SetFillColor(6);
  stack->Add(nothing);
  stack->Add(pipe);
  stack->Add(fmd);
  stack->Add(its);

  TLegend* legend = new TLegend(.15, .65, .27, .95);
  legend->SetFillColor(0);
  legend->SetBorderSize(1);
  legend->AddEntry(its, "ITS", "f");
  legend->AddEntry(fmd, "FMD", "f");
  legend->AddEntry(pipe, "PIPE", "f");
  legend->AddEntry(nothing, "Air", "f");
  
  stack->SetMinimum(nothing->GetMinimum());
  stack->SetMaximum(logmax);
  stack->Draw();
  stack->GetXaxis()->SetTitle("#eta");
  // stack->GetYaxis()->SetRangeUser(, );
  stack->GetYaxis()->SetTitle(fmd->GetTitle());
  legend->Draw();
  accum->Modified();
  
  accum->Modified(); 
  accum->cd();
  // accum->Print(Form("%s_accum.eps", what));
  accum->Print(Form("%s_accum.png", what));
  
}

  
  
//____________________________________________________________________
/** @ingroup lego_script
 */
void 
DrawLego() 
{
  drawLego("abso");
  drawLego("radl");
  drawLego("gcm2");
}

//____________________________________________________________________
//
// EOF
//

  
 DrawLego.C:1
 DrawLego.C:2
 DrawLego.C:3
 DrawLego.C:4
 DrawLego.C:5
 DrawLego.C:6
 DrawLego.C:7
 DrawLego.C:8
 DrawLego.C:9
 DrawLego.C:10
 DrawLego.C:11
 DrawLego.C:12
 DrawLego.C:13
 DrawLego.C:14
 DrawLego.C:15
 DrawLego.C:16
 DrawLego.C:17
 DrawLego.C:18
 DrawLego.C:19
 DrawLego.C:20
 DrawLego.C:21
 DrawLego.C:22
 DrawLego.C:23
 DrawLego.C:24
 DrawLego.C:25
 DrawLego.C:26
 DrawLego.C:27
 DrawLego.C:28
 DrawLego.C:29
 DrawLego.C:30
 DrawLego.C:31
 DrawLego.C:32
 DrawLego.C:33
 DrawLego.C:34
 DrawLego.C:35
 DrawLego.C:36
 DrawLego.C:37
 DrawLego.C:38
 DrawLego.C:39
 DrawLego.C:40
 DrawLego.C:41
 DrawLego.C:42
 DrawLego.C:43
 DrawLego.C:44
 DrawLego.C:45
 DrawLego.C:46
 DrawLego.C:47
 DrawLego.C:48
 DrawLego.C:49
 DrawLego.C:50
 DrawLego.C:51
 DrawLego.C:52
 DrawLego.C:53
 DrawLego.C:54
 DrawLego.C:55
 DrawLego.C:56
 DrawLego.C:57
 DrawLego.C:58
 DrawLego.C:59
 DrawLego.C:60
 DrawLego.C:61
 DrawLego.C:62
 DrawLego.C:63
 DrawLego.C:64
 DrawLego.C:65
 DrawLego.C:66
 DrawLego.C:67
 DrawLego.C:68
 DrawLego.C:69
 DrawLego.C:70
 DrawLego.C:71
 DrawLego.C:72
 DrawLego.C:73
 DrawLego.C:74
 DrawLego.C:75
 DrawLego.C:76
 DrawLego.C:77
 DrawLego.C:78
 DrawLego.C:79
 DrawLego.C:80
 DrawLego.C:81
 DrawLego.C:82
 DrawLego.C:83
 DrawLego.C:84
 DrawLego.C:85
 DrawLego.C:86
 DrawLego.C:87
 DrawLego.C:88
 DrawLego.C:89
 DrawLego.C:90
 DrawLego.C:91
 DrawLego.C:92
 DrawLego.C:93
 DrawLego.C:94
 DrawLego.C:95
 DrawLego.C:96
 DrawLego.C:97
 DrawLego.C:98
 DrawLego.C:99
 DrawLego.C:100
 DrawLego.C:101
 DrawLego.C:102
 DrawLego.C:103
 DrawLego.C:104
 DrawLego.C:105
 DrawLego.C:106
 DrawLego.C:107
 DrawLego.C:108
 DrawLego.C:109
 DrawLego.C:110
 DrawLego.C:111
 DrawLego.C:112
 DrawLego.C:113
 DrawLego.C:114
 DrawLego.C:115
 DrawLego.C:116
 DrawLego.C:117
 DrawLego.C:118
 DrawLego.C:119
 DrawLego.C:120
 DrawLego.C:121
 DrawLego.C:122
 DrawLego.C:123
 DrawLego.C:124
 DrawLego.C:125
 DrawLego.C:126
 DrawLego.C:127
 DrawLego.C:128
 DrawLego.C:129
 DrawLego.C:130
 DrawLego.C:131
 DrawLego.C:132
 DrawLego.C:133
 DrawLego.C:134
 DrawLego.C:135
 DrawLego.C:136
 DrawLego.C:137
 DrawLego.C:138
 DrawLego.C:139
 DrawLego.C:140
 DrawLego.C:141
 DrawLego.C:142
 DrawLego.C:143
 DrawLego.C:144
 DrawLego.C:145
 DrawLego.C:146
 DrawLego.C:147
 DrawLego.C:148
 DrawLego.C:149
 DrawLego.C:150
 DrawLego.C:151
 DrawLego.C:152
 DrawLego.C:153
 DrawLego.C:154
 DrawLego.C:155
 DrawLego.C:156
 DrawLego.C:157
 DrawLego.C:158
 DrawLego.C:159
 DrawLego.C:160
 DrawLego.C:161
 DrawLego.C:162
 DrawLego.C:163
 DrawLego.C:164
 DrawLego.C:165
 DrawLego.C:166
 DrawLego.C:167
 DrawLego.C:168
 DrawLego.C:169
 DrawLego.C:170
 DrawLego.C:171
 DrawLego.C:172
 DrawLego.C:173
 DrawLego.C:174
 DrawLego.C:175
 DrawLego.C:176
 DrawLego.C:177
 DrawLego.C:178
 DrawLego.C:179
 DrawLego.C:180
 DrawLego.C:181
 DrawLego.C:182
 DrawLego.C:183
 DrawLego.C:184
 DrawLego.C:185
 DrawLego.C:186
 DrawLego.C:187
 DrawLego.C:188
 DrawLego.C:189
 DrawLego.C:190
 DrawLego.C:191
 DrawLego.C:192
 DrawLego.C:193
 DrawLego.C:194
 DrawLego.C:195
 DrawLego.C:196
 DrawLego.C:197
 DrawLego.C:198
 DrawLego.C:199
 DrawLego.C:200
 DrawLego.C:201
 DrawLego.C:202
 DrawLego.C:203
 DrawLego.C:204
 DrawLego.C:205
 DrawLego.C:206
 DrawLego.C:207
 DrawLego.C:208
 DrawLego.C:209
 DrawLego.C:210
 DrawLego.C:211
 DrawLego.C:212
 DrawLego.C:213
 DrawLego.C:214
 DrawLego.C:215
 DrawLego.C:216
 DrawLego.C:217
 DrawLego.C:218
 DrawLego.C:219
 DrawLego.C:220
 DrawLego.C:221
 DrawLego.C:222
 DrawLego.C:223
 DrawLego.C:224
 DrawLego.C:225
 DrawLego.C:226
 DrawLego.C:227
 DrawLego.C:228
 DrawLego.C:229
 DrawLego.C:230
 DrawLego.C:231
 DrawLego.C:232
 DrawLego.C:233
 DrawLego.C:234
 DrawLego.C:235
 DrawLego.C:236
 DrawLego.C:237
 DrawLego.C:238
 DrawLego.C:239
 DrawLego.C:240
 DrawLego.C:241
 DrawLego.C:242
 DrawLego.C:243
 DrawLego.C:244
 DrawLego.C:245
 DrawLego.C:246
 DrawLego.C:247
 DrawLego.C:248
 DrawLego.C:249
 DrawLego.C:250
 DrawLego.C:251
 DrawLego.C:252
 DrawLego.C:253
 DrawLego.C:254
 DrawLego.C:255
 DrawLego.C:256
 DrawLego.C:257
 DrawLego.C:258
 DrawLego.C:259
 DrawLego.C:260
 DrawLego.C:261
 DrawLego.C:262