ROOT logo
/**
 * @file 
 * 
 * Scripts to draw energy loss fits from correction object file 
 *
 * @ingroup pwglf_forward_scripts_corr
 */
/** 
 * Clear canvas 
 * 
 * @param c Canvas to clear 
 *
 * @ingroup pwglf_forward_scripts_corr
 */
void
ClearCanvas(TCanvas* c)
{
  c->SetLeftMargin(.1);
  c->SetRightMargin(.05);
  c->SetBottomMargin(.1);
  c->SetTopMargin(.05);
  c->Clear();
}

/** 
 * Load the needed libraries
 * 
 */
void
LoadLibraries()
{
  const char* test = gSystem->GetLibraries("PWGLFforward2","D",false);
  if (test && test[0] != '\0') return;
  gROOT->Macro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C");
}

/** 
 * Draw energy loss fits to a multi-page PDF. 
 *
 * @par Input: 
 * The input file is expected to contain a AliFMDCorrELossFit object
 * named @c elossfits in the top level directory.
 * 
 * @par Output: 
 * A multi-page PDF.  Note, that the PDF generated by ROOT in this way
 * is broken (cannot be read by Acrobat Reader on Windows and MacOSX)
 * and one should pass it through a filter to correct these problems.
 * 
 * @param fname     File name 
 * @param option    Drawing options 
 * @param tracklets Tracklets flag
 *
 * @ingroup pwglf_forward_scripts_corr
 */
void
DrawCorrCentralSecMap2(const char* fname, const char* option="colz", bool tracklets=true)
{
  //__________________________________________________________________
  // Load libraries and object 
  LoadLibraries();

  TFile* file = TFile::Open(fname, "READ");
  if (!file) { 
    Error("DrawCorrSecMap", "Failed to open %s", fname);
    return;
  }
  TString pname(fname);
  pname.ReplaceAll(".root", ".png");
  pname = gSystem->BaseName(pname);

  AliCentralMultiplicityTask::Manager* mgr = 
    new AliCentralMultiplicityTask::Manager;
  const char* objName = mgr->GetObjectName(0);
  AliCentralCorrSecondaryMap* corr = 
    static_cast<AliCentralCorrSecondaryMap*>(file->Get(objName));
  if (!corr) { 
    Error("DrawCorrCentralSecMap", "Object '%s' not found in %s", 
	  objName, fname);
    file->ls();
    return;
  }

  //__________________________________________________________________
  // Create a canvas
  Int_t w = 1200;
  TCanvas* c = new TCanvas("c", "c", w, w / TMath::Sqrt(2));
  c->SetFillColor(0);
  c->SetBorderSize(0);
  c->SetBorderMode(0);
  // c->Print(Form("%s[", pname.Data()));
  
  gStyle->SetOptStat(0);
  gStyle->SetTitleColor(0);
  gStyle->SetTitleStyle(0);
  gStyle->SetTitleBorderSize(0);
  gStyle->SetTitleX(.1);
  gStyle->SetTitleY(1);
  gStyle->SetTitleW(.8);
  gStyle->SetTitleH(.09);
  gStyle->SetFrameFillColor(kWhite);
  gStyle->SetFrameBorderSize(1);
  gStyle->SetFrameBorderMode(1);
  gStyle->SetPalette(1);

  TString opt(option);
  opt.ToLower();
  Bool_t h2d = (opt.Contains("lego") || 
		opt.Contains("surf") || 
		opt.Contains("col"));
  ClearCanvas(c);
  //__________________________________________________________________
  // Draw all corrections
  const TAxis& vtxAxis = corr->GetVertexAxis();
  Int_t        nVtx    = vtxAxis.GetNbins();
  c->Divide((nVtx+2)/3, 3, 0, 0);
  Int_t ipad = 0;
  for (UShort_t v=1; v <= nVtx+1; v++) { 
    ipad++;
    if (ipad == 1) {
      c->cd(ipad);
      TLatex* l = new TLatex(.5, .5, 
			     "#frac{#sum N_{ch,SPD0}}{#sum N_{ch,primary}}");
      if (!tracklets) 
	l->SetText(.5,.5,"#frac{dN_{ch}/d#eta}{#sum N_{ch,primary}}");
      l->SetNDC();
      l->SetTextAlign(22);
      l->SetTextSize(.1);
      l->Draw();
      ipad++;
    }
    if (ipad == 12) {
      if (!tracklets) 
	continue;
      c->cd(ipad);
      TFile* f = TFile::Open("forward_mccorr.root", "READ");
      if (!f) {
	Warning("DrawCorrCentralSecMap2", "File forward_mccorr.root not found");
	continue;
      }
      TList* l3 = static_cast<TList*>(f->Get("CentralSums"));
      if (!l3) { 
	Warning("DrawCorrCentralSecMap2", "No CentralSums list found");
	f->Close();
	continue;
      }
      TH1* xyz = static_cast<TH1*>(l3->FindObject("xyz"));
      if (!xyz) {
	Warning("DrawCorrCentralSecMap2", "no xyz histogram found");
	f->Close();
	continue;
      }
      xyz = static_cast<TH1*>(xyz->Clone());
      xyz->SetDirectory(0);
      xyz->Draw("ISO");
      f->Close();
      continue;
    }
    TVirtualPad* p = c->cd(ipad);
    p->SetFillColor(kWhite);
    p->SetGridx();
    p->SetGridy();

    TH2*   h1 = corr->GetCorrection(v);
    if (h2d) { 
      p->SetRightMargin(0.13);
      h1->SetMaximum(1.9);
      h1->Draw(option);
      continue;
    }

    TH1D*  pr = h1->ProjectionX(Form("vtxbin%02d", v), -1, -1, "e");
    TH1D*  nr = static_cast<TH1D*>(pr->Clone("norm"));
    nr->SetDirectory(0);
    pr->SetDirectory(0);
    pr->SetTitle(Form("%+5.1f<v_{z}<%+5.1f", 
		      vtxAxis.GetBinLowEdge(v),
		      vtxAxis.GetBinUpEdge(v)));
    pr->SetMarkerColor(kRed+1);
    pr->SetFillColor(kRed+1);
    pr->SetFillStyle(3001);
    pr->SetMaximum(1.65);
    pr->GetXaxis()->SetRangeUser(-3.1,3.1);
    
    Int_t nX = h1->GetNbinsX();
    Int_t nY = h1->GetNbinsY();
    nr->Reset();
    for (Int_t i = 1; i <= nX; i++) { 
      Int_t nonZero = 0;
      for (Int_t j = 1; j <= nY; j++) 
	if (h1->GetBinContent(i,j) > 0.001) nonZero++;
      nr->SetBinContent(i, nonZero);
    }
    // pr->Scale(1. / nY);
    pr->Divide(nr);
    pr->Draw("hist"); 
    pr->Draw("same");
   
  }
  
  //__________________________________________________________________
  // Close output file 
  c->SaveAs(pname.Data());
  
}
//
// EOF
//
 DrawCorrCentralSecMap2.C:1
 DrawCorrCentralSecMap2.C:2
 DrawCorrCentralSecMap2.C:3
 DrawCorrCentralSecMap2.C:4
 DrawCorrCentralSecMap2.C:5
 DrawCorrCentralSecMap2.C:6
 DrawCorrCentralSecMap2.C:7
 DrawCorrCentralSecMap2.C:8
 DrawCorrCentralSecMap2.C:9
 DrawCorrCentralSecMap2.C:10
 DrawCorrCentralSecMap2.C:11
 DrawCorrCentralSecMap2.C:12
 DrawCorrCentralSecMap2.C:13
 DrawCorrCentralSecMap2.C:14
 DrawCorrCentralSecMap2.C:15
 DrawCorrCentralSecMap2.C:16
 DrawCorrCentralSecMap2.C:17
 DrawCorrCentralSecMap2.C:18
 DrawCorrCentralSecMap2.C:19
 DrawCorrCentralSecMap2.C:20
 DrawCorrCentralSecMap2.C:21
 DrawCorrCentralSecMap2.C:22
 DrawCorrCentralSecMap2.C:23
 DrawCorrCentralSecMap2.C:24
 DrawCorrCentralSecMap2.C:25
 DrawCorrCentralSecMap2.C:26
 DrawCorrCentralSecMap2.C:27
 DrawCorrCentralSecMap2.C:28
 DrawCorrCentralSecMap2.C:29
 DrawCorrCentralSecMap2.C:30
 DrawCorrCentralSecMap2.C:31
 DrawCorrCentralSecMap2.C:32
 DrawCorrCentralSecMap2.C:33
 DrawCorrCentralSecMap2.C:34
 DrawCorrCentralSecMap2.C:35
 DrawCorrCentralSecMap2.C:36
 DrawCorrCentralSecMap2.C:37
 DrawCorrCentralSecMap2.C:38
 DrawCorrCentralSecMap2.C:39
 DrawCorrCentralSecMap2.C:40
 DrawCorrCentralSecMap2.C:41
 DrawCorrCentralSecMap2.C:42
 DrawCorrCentralSecMap2.C:43
 DrawCorrCentralSecMap2.C:44
 DrawCorrCentralSecMap2.C:45
 DrawCorrCentralSecMap2.C:46
 DrawCorrCentralSecMap2.C:47
 DrawCorrCentralSecMap2.C:48
 DrawCorrCentralSecMap2.C:49
 DrawCorrCentralSecMap2.C:50
 DrawCorrCentralSecMap2.C:51
 DrawCorrCentralSecMap2.C:52
 DrawCorrCentralSecMap2.C:53
 DrawCorrCentralSecMap2.C:54
 DrawCorrCentralSecMap2.C:55
 DrawCorrCentralSecMap2.C:56
 DrawCorrCentralSecMap2.C:57
 DrawCorrCentralSecMap2.C:58
 DrawCorrCentralSecMap2.C:59
 DrawCorrCentralSecMap2.C:60
 DrawCorrCentralSecMap2.C:61
 DrawCorrCentralSecMap2.C:62
 DrawCorrCentralSecMap2.C:63
 DrawCorrCentralSecMap2.C:64
 DrawCorrCentralSecMap2.C:65
 DrawCorrCentralSecMap2.C:66
 DrawCorrCentralSecMap2.C:67
 DrawCorrCentralSecMap2.C:68
 DrawCorrCentralSecMap2.C:69
 DrawCorrCentralSecMap2.C:70
 DrawCorrCentralSecMap2.C:71
 DrawCorrCentralSecMap2.C:72
 DrawCorrCentralSecMap2.C:73
 DrawCorrCentralSecMap2.C:74
 DrawCorrCentralSecMap2.C:75
 DrawCorrCentralSecMap2.C:76
 DrawCorrCentralSecMap2.C:77
 DrawCorrCentralSecMap2.C:78
 DrawCorrCentralSecMap2.C:79
 DrawCorrCentralSecMap2.C:80
 DrawCorrCentralSecMap2.C:81
 DrawCorrCentralSecMap2.C:82
 DrawCorrCentralSecMap2.C:83
 DrawCorrCentralSecMap2.C:84
 DrawCorrCentralSecMap2.C:85
 DrawCorrCentralSecMap2.C:86
 DrawCorrCentralSecMap2.C:87
 DrawCorrCentralSecMap2.C:88
 DrawCorrCentralSecMap2.C:89
 DrawCorrCentralSecMap2.C:90
 DrawCorrCentralSecMap2.C:91
 DrawCorrCentralSecMap2.C:92
 DrawCorrCentralSecMap2.C:93
 DrawCorrCentralSecMap2.C:94
 DrawCorrCentralSecMap2.C:95
 DrawCorrCentralSecMap2.C:96
 DrawCorrCentralSecMap2.C:97
 DrawCorrCentralSecMap2.C:98
 DrawCorrCentralSecMap2.C:99
 DrawCorrCentralSecMap2.C:100
 DrawCorrCentralSecMap2.C:101
 DrawCorrCentralSecMap2.C:102
 DrawCorrCentralSecMap2.C:103
 DrawCorrCentralSecMap2.C:104
 DrawCorrCentralSecMap2.C:105
 DrawCorrCentralSecMap2.C:106
 DrawCorrCentralSecMap2.C:107
 DrawCorrCentralSecMap2.C:108
 DrawCorrCentralSecMap2.C:109
 DrawCorrCentralSecMap2.C:110
 DrawCorrCentralSecMap2.C:111
 DrawCorrCentralSecMap2.C:112
 DrawCorrCentralSecMap2.C:113
 DrawCorrCentralSecMap2.C:114
 DrawCorrCentralSecMap2.C:115
 DrawCorrCentralSecMap2.C:116
 DrawCorrCentralSecMap2.C:117
 DrawCorrCentralSecMap2.C:118
 DrawCorrCentralSecMap2.C:119
 DrawCorrCentralSecMap2.C:120
 DrawCorrCentralSecMap2.C:121
 DrawCorrCentralSecMap2.C:122
 DrawCorrCentralSecMap2.C:123
 DrawCorrCentralSecMap2.C:124
 DrawCorrCentralSecMap2.C:125
 DrawCorrCentralSecMap2.C:126
 DrawCorrCentralSecMap2.C:127
 DrawCorrCentralSecMap2.C:128
 DrawCorrCentralSecMap2.C:129
 DrawCorrCentralSecMap2.C:130
 DrawCorrCentralSecMap2.C:131
 DrawCorrCentralSecMap2.C:132
 DrawCorrCentralSecMap2.C:133
 DrawCorrCentralSecMap2.C:134
 DrawCorrCentralSecMap2.C:135
 DrawCorrCentralSecMap2.C:136
 DrawCorrCentralSecMap2.C:137
 DrawCorrCentralSecMap2.C:138
 DrawCorrCentralSecMap2.C:139
 DrawCorrCentralSecMap2.C:140
 DrawCorrCentralSecMap2.C:141
 DrawCorrCentralSecMap2.C:142
 DrawCorrCentralSecMap2.C:143
 DrawCorrCentralSecMap2.C:144
 DrawCorrCentralSecMap2.C:145
 DrawCorrCentralSecMap2.C:146
 DrawCorrCentralSecMap2.C:147
 DrawCorrCentralSecMap2.C:148
 DrawCorrCentralSecMap2.C:149
 DrawCorrCentralSecMap2.C:150
 DrawCorrCentralSecMap2.C:151
 DrawCorrCentralSecMap2.C:152
 DrawCorrCentralSecMap2.C:153
 DrawCorrCentralSecMap2.C:154
 DrawCorrCentralSecMap2.C:155
 DrawCorrCentralSecMap2.C:156
 DrawCorrCentralSecMap2.C:157
 DrawCorrCentralSecMap2.C:158
 DrawCorrCentralSecMap2.C:159
 DrawCorrCentralSecMap2.C:160
 DrawCorrCentralSecMap2.C:161
 DrawCorrCentralSecMap2.C:162
 DrawCorrCentralSecMap2.C:163
 DrawCorrCentralSecMap2.C:164
 DrawCorrCentralSecMap2.C:165
 DrawCorrCentralSecMap2.C:166
 DrawCorrCentralSecMap2.C:167
 DrawCorrCentralSecMap2.C:168
 DrawCorrCentralSecMap2.C:169
 DrawCorrCentralSecMap2.C:170
 DrawCorrCentralSecMap2.C:171
 DrawCorrCentralSecMap2.C:172
 DrawCorrCentralSecMap2.C:173
 DrawCorrCentralSecMap2.C:174
 DrawCorrCentralSecMap2.C:175
 DrawCorrCentralSecMap2.C:176
 DrawCorrCentralSecMap2.C:177
 DrawCorrCentralSecMap2.C:178
 DrawCorrCentralSecMap2.C:179
 DrawCorrCentralSecMap2.C:180
 DrawCorrCentralSecMap2.C:181
 DrawCorrCentralSecMap2.C:182
 DrawCorrCentralSecMap2.C:183
 DrawCorrCentralSecMap2.C:184
 DrawCorrCentralSecMap2.C:185
 DrawCorrCentralSecMap2.C:186
 DrawCorrCentralSecMap2.C:187
 DrawCorrCentralSecMap2.C:188
 DrawCorrCentralSecMap2.C:189
 DrawCorrCentralSecMap2.C:190
 DrawCorrCentralSecMap2.C:191
 DrawCorrCentralSecMap2.C:192
 DrawCorrCentralSecMap2.C:193
 DrawCorrCentralSecMap2.C:194
 DrawCorrCentralSecMap2.C:195
 DrawCorrCentralSecMap2.C:196
 DrawCorrCentralSecMap2.C:197
 DrawCorrCentralSecMap2.C:198
 DrawCorrCentralSecMap2.C:199
 DrawCorrCentralSecMap2.C:200
 DrawCorrCentralSecMap2.C:201
 DrawCorrCentralSecMap2.C:202
 DrawCorrCentralSecMap2.C:203
 DrawCorrCentralSecMap2.C:204
 DrawCorrCentralSecMap2.C:205
 DrawCorrCentralSecMap2.C:206
 DrawCorrCentralSecMap2.C:207
 DrawCorrCentralSecMap2.C:208