StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mip_ring_draw.C
1 #include <iostream>
2 #include <fstream>
3 using namespace std;
4 
5 #include "TFile.h"
6 #include "TMath.h"
7 #include "TH1.h"
8 #include "TF1.h"
9 #include "TPostScript.h"
10 #include "TCanvas.h"
11 #include "TStyle.h"
12 #include "TLatex.h"
13 #include "TString.h"
14 #include "TLine.h"
15 
16 void drawTower(TH1* h, TF1* f, int id);
17 
18 void mip_ring_draw(const char* infile="mipskimfile.root", const char* postscript="mipring.ps", const char* outname="2008mipring.root")
19 {
20  const int nrings = 40;
21  TFile input(infile);
22  char name[100];
23  TH1* ring_histo[nrings];
24  TH1F* ringMIP = new TH1F("ringMIP","",nrings,-1.0,1.0);
25  ringMIP->SetXTitle("#eta");
26  ringMIP->SetYTitle("MIP peak (ADC)");
27  for(int i = 0; i < nrings; i++)
28  {
29  sprintf(name,"ring_histo_%i",i+1);
30  ring_histo[i] = (TH1F*)input.Get(name);
31  }
32 
33 
34  TPostScript* ps = new TPostScript(postscript);
35  TCanvas* c = new TCanvas("c","",100,100,600.,800.);
36  //TH1F* ringprec = new TH1F("ringprec","",40,-1.0,1.0);
37  //ringprec->SetYTitle("Gain (fit)/ Target Gain");
38  //ringprec->SetXTitle("#eta");
39  //double ew[nrings];
40  int pad = 16;
41  TF1 *gaussian_fit[nrings], *landau_fit[nrings];
42  for(int i=0; i<nrings; i++){
43  if(pad%15 == 1){
44  c->Update();
45  ps->NewPage();
46  c->Clear();
47  c->Divide(3,5);
48  pad = 1;
49  }
50  c->cd(pad);
51 
52  cout<<"fitting ring "<<i+1<<" of "<<nrings<<endl;
53 
54  sprintf(name,"fit_%i",i+1);
55 
56  gaussian_fit[i] = new TF1(name,"gaus",7.,45.);
57  landau_fit[i] = new TF1(name,"landau",7.,200.);
58 
59  gaussian_fit[i]->SetParameter(1,20.);
60  gaussian_fit[i]->SetParameter(2,5.);
61 
62  landau_fit[i]->SetParameter(1,17.);
63  landau_fit[i]->SetParameter(2,3.);
64 
65  gaussian_fit[i]->SetLineColor(kGreen);
66  gaussian_fit[i]->SetLineWidth(0.6);
67 
68  landau_fit[i]->SetLineColor(kYellow);
69  landau_fit[i]->SetLineWidth(0.6);
70 
71  ring_histo[i]->Fit(gaussian_fit[i],"rq");
72  ring_histo[i]->GetXaxis()->SetRangeUser(3.0,50.0);
73 
74  drawTower(ring_histo[i],gaussian_fit[i],i);
75 
76  double histogram_top = ring_histo[i]->GetBinContent(ring_histo[i]->GetMaximumBin());
77 
78  double gaussian_mean = gaussian_fit[i]->GetParameter(1);
79  TLine *gaussian_peak = new TLine(gaussian_mean,0.,gaussian_mean,histogram_top+15);
80  gaussian_peak->SetLineColor(kGreen);
81  gaussian_peak->SetLineWidth(2.0);
82  gaussian_peak->Draw("same");
83 
84  pad++;
85  float eta = (float)((i - 20) * 2 + 1)/40;
86  float theta = 2*TMath::ATan(TMath::Exp(-eta));
87  float mipenergy = 0.264 * (1+0.056*eta*eta)/TMath::Sin(theta);
88  cout<<mipenergy/gaussian_mean<<", ";
89  ringMIP->Fill(eta,gaussian_mean);
90  ringMIP->SetBinError(i+1,gaussian_fit[i]->GetParError(1));
91 
92  }
93  cout<<endl;
94  c->Update();
95  ps->NewPage();
96  c->Clear();
97  c->Divide(1,2);
98  c->cd(1);
99  ringMIP->SetMarkerStyle(20);
100  ringMIP->GetYaxis()->SetRangeUser(0,35);
101  gStyle->SetOptStat(0);
102  ringMIP->Draw("ep");
103 
104  ps->Close();
105 
106  TFile outfile(outname,"RECREATE");
107  for(int i = 0; i < nrings; i++)
108  {
109  ring_histo[i]->Write();
110  }
111  ringMIP->Write();
112  outfile.Close();
113 }
114 
115 void drawTower(TH1* h, TF1* f, int id){
116  //calculate a few quantities
117  //double peak = f->GetParameter(1);
118  //double mean = f->Mean(5.,200.);
119  //double histo_height = h->GetBinContent(h->GetMaximumBin());
120  //if(histo_height == 0) histo_height = 1.;
121 
122  int xLatexBin = 20;
123 
124  //histogram options
125  h->SetXTitle("ADC");
126  h->Draw();
127 
128  //draw a line through the location of the MIP peak
129  char line_name[50];
130  sprintf(line_name,"mip_peak_%i",id);
131  //TH1* line = new TH1F(line_name,line_name,h->GetNbinsX(),h->GetBinLowEdge(1),h->GetBinLowEdge(h->GetNbinsX()+1));
132  // line->SetLineColor(kRed);
133  //line->Fill(peak,1.e8);
134 // line->Draw("same");
135 
136  //write the tower number on the plot
137  char tower_title[100];
138  float eta = (float)((id - 20) * 2 + 1)/40;
139  sprintf(tower_title,"eta = %f",eta);
140  TLatex title_latex;
141  title_latex.SetTextSize(0.15);
142  //if(isBadTower2006(id)) title_latex.SetTextColor(kRed);
143 // title_latex.DrawLatex(xLatexBin,0.94*histo_height,tower_title);
144  title_latex.DrawTextNDC(0.13,0.78,tower_title);
145 
146 
147 }