ROOT logo
#if !defined(__CINT__) || defined(__MAKECINT__)
#include <TCanvas.h>
#include <TFile.h>
#include <TStyle.h>
#include <TProfile.h>
#include <TH1F.h>
#include <TH1D.h>
#include <TH2F.h>
#include <TPaveStats.h>
#include <TGraphErrors.h>
#include <TLatex.h>
#include <TString.h>
#endif


// Macro to plot the output of the ITS aligment task for SDD detector
// For the moment just plot quantities summed over modules
// Orgin: F. Prino


void PlotTrackToPointResidualsSDD(){
  TFile *fil=new TFile("AnalysisResults.root");
  TDirectoryFile* df=(TDirectoryFile*)fil->Get("ITSAlignQA");
  TList* l=(TList*)df->Get("clistITSAlignQA");
  TH2F* hSDDResidXvsX=0x0;
  TH2F* hSDDResidX=0x0;
  for(Int_t iMod=240; iMod<500; iMod++){
    TString hname=Form("hSDDResidXvsX%d",iMod);
    TH2F* h=(TH2F*)l->FindObject(hname);
    if(h){
      if(hSDDResidXvsX==0x0){
	hSDDResidXvsX=(TH2F*)h->Clone("hSDDResidXvsXAll");
      }else{
	hSDDResidXvsX->Add(h);
      }
    }
    TString hname2=Form("hSDDResidX%d",iMod);
    TH2F* h2=(TH2F*)l->FindObject(hname2);
    if(h2){
      if(hSDDResidX==0x0){
	hSDDResidX=(TH2F*)h2->Clone("hSDDResidXvsPtAll");
      }else{
	hSDDResidX->Add(h2);
      }
    }
  }

  gStyle->SetPalette(1);
  gStyle->SetOptTitle(0);
  TCanvas* c1=new TCanvas("c1","",700,1000);
  c1->Divide(1,2);
  c1->cd(1);
  hSDDResidXvsX->Draw("colz");
  hSDDResidXvsX->GetYaxis()->SetTitle("Track-to-point residual (cm)");
  hSDDResidXvsX->GetXaxis()->SetTitle("X local (cm)");
  TProfile* hpfx=hSDDResidXvsX->ProfileX();
  hpfx->SetLineWidth(2);
  hpfx->Draw("same");
  c1->cd(2);
  Int_t midbin=hSDDResidXvsX->GetXaxis()->FindBin(0.);
  TH1D* hleft=hSDDResidXvsX->ProjectionY("hleft",1,midbin-2);
  TH1D* hright=hSDDResidXvsX->ProjectionY("hright",midbin+2,hSDDResidXvsX->GetNbinsX());
  hleft->Draw();
  hleft->GetYaxis()->SetTitle("Track-to-point residual (cm)");
  c1->Update();
  TPaveStats *st1=(TPaveStats*)hleft->GetListOfFunctions()->FindObject("stats");
  st1->SetY1NDC(0.71);
  st1->SetY2NDC(0.9);
  hright->SetLineColor(2);
  hright->Draw("sames");
  c1->Update();
  TPaveStats *st2=(TPaveStats*)hright->GetListOfFunctions()->FindObject("stats");
  st2->SetY1NDC(0.51);
  st2->SetY2NDC(0.7);
  st2->SetTextColor(2);
  c1->Modified();
  c1->Update();
  TLatex *t2=new TLatex(0.14,0.7,"Left sides");
  t2->SetTextSize(0.048);
  t2->SetNDC();
  TLatex *t3=new TLatex(0.14,0.5,"Right sides");
  t3->SetNDC();
  t3->SetTextSize(0.048);
  t3->SetTextColor(2);
  t2->Draw();
  t3->Draw();

  TCanvas* c2=new TCanvas("c2","",700,1000);
  c2->Divide(1,2);
  c2->cd(1);
  hSDDResidX->GetXaxis()->SetRangeUser(0.,10.);
  hSDDResidX->Draw("colz");
  hSDDResidX->GetXaxis()->SetTitle("p_{t} (GeV/c)");
  hSDDResidX->GetYaxis()->SetTitle("Track-to-point residual (cm)");
  c2->cd(2);
  TGraphErrors* grms=new TGraphErrors(0);
  for(Int_t iBin=1; iBin<=hSDDResidX->GetNbinsX(); iBin++){
    TH1D* htmp=hSDDResidX->ProjectionY("htmp",iBin,iBin);
    if(htmp->GetEntries()>10.){
      Int_t npt=grms->GetN();
      grms->SetPoint(npt,hSDDResidX->GetXaxis()->GetBinCenter(iBin),htmp->GetRMS());
      grms->SetPointError(npt,0.5*hSDDResidX->GetXaxis()->GetBinWidth(iBin),htmp->GetRMSError());
    }
  }
  grms->SetMarkerStyle(20);
  grms->GetXaxis()->SetLimits(0.,10.);
  grms->Draw("AP");
  grms->GetXaxis()->SetTitle("p_{t} (GeV/c)");
  grms->GetYaxis()->SetTitle("RMS of Track-to-point residual (cm)");
}
 PlotTrackToPointResidualsSDD.C:1
 PlotTrackToPointResidualsSDD.C:2
 PlotTrackToPointResidualsSDD.C:3
 PlotTrackToPointResidualsSDD.C:4
 PlotTrackToPointResidualsSDD.C:5
 PlotTrackToPointResidualsSDD.C:6
 PlotTrackToPointResidualsSDD.C:7
 PlotTrackToPointResidualsSDD.C:8
 PlotTrackToPointResidualsSDD.C:9
 PlotTrackToPointResidualsSDD.C:10
 PlotTrackToPointResidualsSDD.C:11
 PlotTrackToPointResidualsSDD.C:12
 PlotTrackToPointResidualsSDD.C:13
 PlotTrackToPointResidualsSDD.C:14
 PlotTrackToPointResidualsSDD.C:15
 PlotTrackToPointResidualsSDD.C:16
 PlotTrackToPointResidualsSDD.C:17
 PlotTrackToPointResidualsSDD.C:18
 PlotTrackToPointResidualsSDD.C:19
 PlotTrackToPointResidualsSDD.C:20
 PlotTrackToPointResidualsSDD.C:21
 PlotTrackToPointResidualsSDD.C:22
 PlotTrackToPointResidualsSDD.C:23
 PlotTrackToPointResidualsSDD.C:24
 PlotTrackToPointResidualsSDD.C:25
 PlotTrackToPointResidualsSDD.C:26
 PlotTrackToPointResidualsSDD.C:27
 PlotTrackToPointResidualsSDD.C:28
 PlotTrackToPointResidualsSDD.C:29
 PlotTrackToPointResidualsSDD.C:30
 PlotTrackToPointResidualsSDD.C:31
 PlotTrackToPointResidualsSDD.C:32
 PlotTrackToPointResidualsSDD.C:33
 PlotTrackToPointResidualsSDD.C:34
 PlotTrackToPointResidualsSDD.C:35
 PlotTrackToPointResidualsSDD.C:36
 PlotTrackToPointResidualsSDD.C:37
 PlotTrackToPointResidualsSDD.C:38
 PlotTrackToPointResidualsSDD.C:39
 PlotTrackToPointResidualsSDD.C:40
 PlotTrackToPointResidualsSDD.C:41
 PlotTrackToPointResidualsSDD.C:42
 PlotTrackToPointResidualsSDD.C:43
 PlotTrackToPointResidualsSDD.C:44
 PlotTrackToPointResidualsSDD.C:45
 PlotTrackToPointResidualsSDD.C:46
 PlotTrackToPointResidualsSDD.C:47
 PlotTrackToPointResidualsSDD.C:48
 PlotTrackToPointResidualsSDD.C:49
 PlotTrackToPointResidualsSDD.C:50
 PlotTrackToPointResidualsSDD.C:51
 PlotTrackToPointResidualsSDD.C:52
 PlotTrackToPointResidualsSDD.C:53
 PlotTrackToPointResidualsSDD.C:54
 PlotTrackToPointResidualsSDD.C:55
 PlotTrackToPointResidualsSDD.C:56
 PlotTrackToPointResidualsSDD.C:57
 PlotTrackToPointResidualsSDD.C:58
 PlotTrackToPointResidualsSDD.C:59
 PlotTrackToPointResidualsSDD.C:60
 PlotTrackToPointResidualsSDD.C:61
 PlotTrackToPointResidualsSDD.C:62
 PlotTrackToPointResidualsSDD.C:63
 PlotTrackToPointResidualsSDD.C:64
 PlotTrackToPointResidualsSDD.C:65
 PlotTrackToPointResidualsSDD.C:66
 PlotTrackToPointResidualsSDD.C:67
 PlotTrackToPointResidualsSDD.C:68
 PlotTrackToPointResidualsSDD.C:69
 PlotTrackToPointResidualsSDD.C:70
 PlotTrackToPointResidualsSDD.C:71
 PlotTrackToPointResidualsSDD.C:72
 PlotTrackToPointResidualsSDD.C:73
 PlotTrackToPointResidualsSDD.C:74
 PlotTrackToPointResidualsSDD.C:75
 PlotTrackToPointResidualsSDD.C:76
 PlotTrackToPointResidualsSDD.C:77
 PlotTrackToPointResidualsSDD.C:78
 PlotTrackToPointResidualsSDD.C:79
 PlotTrackToPointResidualsSDD.C:80
 PlotTrackToPointResidualsSDD.C:81
 PlotTrackToPointResidualsSDD.C:82
 PlotTrackToPointResidualsSDD.C:83
 PlotTrackToPointResidualsSDD.C:84
 PlotTrackToPointResidualsSDD.C:85
 PlotTrackToPointResidualsSDD.C:86
 PlotTrackToPointResidualsSDD.C:87
 PlotTrackToPointResidualsSDD.C:88
 PlotTrackToPointResidualsSDD.C:89
 PlotTrackToPointResidualsSDD.C:90
 PlotTrackToPointResidualsSDD.C:91
 PlotTrackToPointResidualsSDD.C:92
 PlotTrackToPointResidualsSDD.C:93
 PlotTrackToPointResidualsSDD.C:94
 PlotTrackToPointResidualsSDD.C:95
 PlotTrackToPointResidualsSDD.C:96
 PlotTrackToPointResidualsSDD.C:97
 PlotTrackToPointResidualsSDD.C:98
 PlotTrackToPointResidualsSDD.C:99
 PlotTrackToPointResidualsSDD.C:100
 PlotTrackToPointResidualsSDD.C:101
 PlotTrackToPointResidualsSDD.C:102
 PlotTrackToPointResidualsSDD.C:103
 PlotTrackToPointResidualsSDD.C:104
 PlotTrackToPointResidualsSDD.C:105
 PlotTrackToPointResidualsSDD.C:106
 PlotTrackToPointResidualsSDD.C:107
 PlotTrackToPointResidualsSDD.C:108
 PlotTrackToPointResidualsSDD.C:109
 PlotTrackToPointResidualsSDD.C:110
 PlotTrackToPointResidualsSDD.C:111