Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CDC_dedx.C
Go to the documentation of this file.
1 
2 // The following are special comments used by RootSpy to know
3 // which histograms to fetch for the macro.
4 //
5 // hnamepath: /CDC_dedx/dedx_p_pos
6 // hnamepath: /CDC_dedx/dedx_p_neg
7 // hnamepath: /CDC_dedx/dedx_i_p_pos
8 // hnamepath: /CDC_dedx/dedx_i_p_neg
9 
10 
11 // By default, use the dE/dx from amplitude histos
12 // Set integral=1 to switch to integral instead
13 
14 
15 void CDC_dedx(int integral=0) {
16 
17  gStyle->SetCanvasDefW(1000);
18  gStyle->SetCanvasDefH(1000);
19  gStyle->SetOptStat(0);
20  gStyle->SetOptFit(0);
21  gStyle->SetFuncWidth(1);
22  gStyle->SetFuncColor(6);
23 
24 
25  TDirectory *CDCdir = (TDirectory*)gDirectory->FindObjectAny("CDC_dedx");
26  if (!CDCdir) printf("Cannot find directory CDC_dedx\n");
27  if (!CDCdir) return;
28  CDCdir->cd();
29 
30  char whichdedx[20];
31  char hname_pos[20];
32  char hname_neg[20];
33 
34  if (integral == 0) {
35  sprintf(whichdedx,"");
36  sprintf(hname_pos,"dedx_p_pos");
37  sprintf(hname_neg,"dedx_p_neg");
38  } else {
39  sprintf(whichdedx," (integ)");
40  sprintf(hname_pos,"intdedx_p_pos");
41  sprintf(hname_neg,"intdedx_p_neg");
42  }
43 
44  TH2I *h = (TH2I*)CDCdir->Get(hname_pos);
45  if (!h) printf("Cannot find histogram %s\n",hname_pos);
46  if (!h) return;
47 
48  TH2I *hn = (TH2I*)CDCdir->Get(hname_neg);
49  if (!hn) printf("Cannot find histogram %s\n",hname_neg);
50  if (!hn) return;
51 
52  if(gPad == NULL){
53  TCanvas *c1 = new TCanvas("c1");
54  c1->cd(0);
55  c1->Draw();
56  c1->Update();
57  }
58 
59  if(!gPad) return;
60 
61  TCanvas *c1 = gPad->GetCanvas();
62  c1->Divide(2,2);
63 
64  const float ymin=0;
65  const float ymax=12;
66 
67 
68  c1->cd(1);
69 
70  gPad->SetLogz();
71  h->Draw("colz");
72 
73  c1->cd(2);
74 
75  gPad->SetLogz();
76  hn->Draw("colz");
77 
78  c1->cd(4);
79 
80  TF1 *g = new TF1("gaus","gaus",0,ymax);
81 
82  double pars[3];
83  double res;
84  double resp = 0;
85  double respi = 0;
86 
87 
88  // draw cut through histo at p=1.5 GeV/c
89 
90  float pcut = 1.5;
91  int pbin = h->GetXaxis()->FindBin(pcut);
92 
93  TH1D *p = h->ProjectionY("p1",pbin,pbin);
94 
95  p->SetTitle(Form("CDC q+ dE/dx%s at %.2f GeV/c",whichdedx,pcut));
96  p->GetXaxis()->SetRangeUser(ymin,ymax);
97  p->DrawCopy("");
98 
99  double fitstat = p->Fit(g,"Q0WE"); // fitstat=0 is good
100  double mean = 0;
101 
102  if (fitstat == 0) {
103  g->GetParameters(&pars[0]);
104  res = 2.0*pars[2]/pars[1];
105  scale = pars[1]/2.5; // dE/dx band is usually at ~2.5 keV/cm after calibration
106  mean = pars[1];
107 
108  g->DrawCopy("same");
109 
110  TPaveText *txt1 = new TPaveText(0.4,0.75,0.8,0.85,"NDC");
111  txt1->AddText(Form("Mean %.2f width %.2f res %.2f",pars[1],2*pars[2],res));
112  txt1->SetBorderSize(0);
113  txt1->SetFillStyle(0);
114  txt1->Draw();
115 
116  }
117 
118 
119  c1->cd(3);
120 
121  // draw cut through histo at p=0.5 GeV/c
122 
123  pcut = 0.5;
124  pbin = h->GetXaxis()->FindBin(pcut);
125  p = h->ProjectionY("p1",pbin,pbin);
126 
127  p->SetTitle(Form("CDC q+ dE/dx%s at %.2f GeV/c",whichdedx,pcut));
128  p->GetXaxis()->SetRangeUser(ymin,ymax);
129  p->DrawCopy("");
130 
131  if (mean ==0) return; // don't try to fit these if the earlier fit failed
132 
133  TPaveText *txt2 = new TPaveText(0.4,0.75,0.8,0.85,"NDC");
134  txt2->SetBorderSize(0);
135  txt2->SetFillStyle(0);
136 
137 
138  fitstat = p->Fit(g,"Q0WE","",0,2*mean);
139 
140  if (fitstat == 0) {
141  g->GetParameters(&pars[0]);
142  respi = 2.0*pars[2]/pars[1];
143 
144  g->DrawCopy("same");
145 
146  txt2->AddText(Form("Mean %.2f width %.2f res %.2f",pars[1],2*pars[2],respi));
147 
148  }
149 
150 
151  fitstat = p->Fit(g,"Q0WE","",2*mean,ymax);
152 
153  if (fitstat == 0) {
154  g->GetParameters(&pars[0]);
155  resp = 2.0*pars[2]/pars[1];
156 
157  g->DrawCopy("same");
158 
159  txt2->AddText("");
160  txt2->AddText(Form("Mean %.2f width %.2f res %.2f",pars[1],2*pars[2],resp));
161 
162  }
163 
164 
165  txt2->Draw();
166 
167 
168 }
169 
170 
171 
TDirectory * CDCdir
sprintf(text,"Post KinFit Cut")
static TLatex * txt2
Double_t c1[2][NMODULES]
Definition: tw_corr.C:68
void CDC_dedx(int integral=0)
Definition: CDC_dedx.C:15
Double_t ymin
Definition: bcal_hist_eff.C:89
static TLatex * txt1
Double_t ymax
Definition: bcal_hist_eff.C:91
printf("string=%s", string)