StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
reCalSmd.C
1 //recalibrate SMD strips
2 reCalSmd() {
3  float goalMipEne=1.3; // MeV
4 
5  // const int nSec=8; char *secL[nSec]={"01V","02U","04V","05U","07V","08U","10V","11U"}; TString tit="smd-Layer-1"; char *fncN="pol4";
6  // const int nSec=8; char *secL[nSec]={"02V","03U","05V","06U","08V","09U","11V","12U"}; TString tit="smd-Layer-2"; char *fncN="pol4";
7  const int nSec=8; char *secL[nSec]={"03V","04U","06V","07U","09V","10U","12V","01U"}; TString tit="smd-Layer-3"; char *fncN="pol4";
8 
9  // const int nSec=2; char *secL[nSec]={"01U","01V"}; TString tit="sectXX"; char *fncN="pol3"; //test case
10 
11  TFile *fdA[nSec];
12  TString iPath="/star/u/wissink/cal2006/"; //location of .hist.root files
13 
14  //.......... open files
15  int j;
16  for(j=0;j<nSec;j++) {
17  TString fname=iPath+"smd"+secL[j]+".hist.root";
18  fdA[j]=new TFile(fname);
19  assert(fdA[j]->IsOpen());
20  }
21 
22  // fdG=new TFile("R5112018.hist.root");
23  fdG=new TFile("/star/u/wissink/cal2006/iter5-pp/R7089008.hist.root");
24  assert(fdG->IsOpen());
25 
26  // ...... draw .........
27 
28  h=new TH1F(tit,tit+" Average recon MIP energy from pair of strips; strip ID; MIP energy [MeV]",290,.5,290.5);
29 
30  c=new TCanvas(tit,tit,600,400);
31 
32  h->Draw();
33  h->SetMinimum(0.7);
34  h->SetMaximum(1.8);
35  gStyle->SetOptFit(0);
36  gStyle->SetOptStat(0);
37 
38  lg=new TLegend(.2,.11,.35,.41);
39 
40  TGraphErrors *grS=new TGraphErrors;
41  grS->SetMarkerStyle(3);
42 
43  for(j=0;j<nSec;j++) {
44  // if(j>1) break;
45  TString grN="mpvN"; grN+=secL[j];
46  TGraphErrors *gr=(TGraphErrors *)fdA[j]->Get(grN);
47  assert(gr);
48  int n=gr->GetN();
49  Double_t* eyA=gr->GetEY();
50  Double_t* yA=gr->GetY();
51  Double_t* xA=gr->GetX();
52  int i;
53  for(i=0;i<n;i++){
54  if(fabs(yA[i]-1.3)>0.5) continue;
55  if(fabs(eyA[i])>0.5) continue;
56  int nS=grS->GetN();
57  grS->SetPoint(nS,xA[i],yA[i]);
58  grS->SetPointError(nS,0.,eyA[i]);
59  }
60  // gr->Print();
61  gr->Draw("P");
62  gr->SetMarkerStyle(24+j);
63  lg->AddEntry(gr,secL[j],"lpe");
64  }
65 
66  lg->Draw();
67 
68  c2=new TCanvas();
69 
70  h->Draw();
71  grS->Draw("P");
72  //grS->Print();
73  int col=kBlue;
74 
75  grS->Fit(fncN);
76  TF1* f=grS->GetFunction(fncN); assert(f);
77  f->SetLineColor(col);
78  f->SetLineWidth(2);
79  f->SetRange(0.5,288.);
80 
81  c->cd();
82  f->Draw("same");
83 
84  //................calc new gains
85  // c->Print();
86  c3=new TCanvas();
87  c3->Divide(3,3);
88  for(j=0;j<nSec;j++) {
89  TString gnN="ug"; gnN+=secL[j];
90  TH1F * hg=( TH1F *)fdG->Get(gnN);
91  assert(hg);
92  c3->cd(j+1); hg->Draw();
93  int i;
94  int ns=hg->GetNbinsX();
95 
96  TString ogN="gains"; ogN+=secL[j]; ogN+="smd.dat";
97  FILE *fog=fopen(ogN.Data(),"w"); assert(fog);
98  fprintf(fog,"# absolute gains for SMD plain %s,\n# stripName, gain[ch/GeV], erGain=dumm, correction, old gain\n",secL[j]);
99  // return;
100  for(i=1;i<=ns;i++) {
101  if(i>288) break;
102  float g1=hg->GetBinContent(i);
103  float gc=goalMipEne/f->Eval(i);
104  float g2=g1/gc;
105 
106  //printf("str=%d %8.1f %.3f -->%.1f \n",i,g1,gc,g2);
107  fprintf(fog,"%s%03d %8.1f 0.1 (corr= %.3f) old=%.1f \n",secL[j],i,g2,gc,g1);
108  }
109  fclose(fog);
110  }
111 
112 
113 }
114 
115 
116 
117 
118 
119 
120 //................................................
121 //................................................
122 //................................................
123 // plot average MIP response of SMD plains on the same depth
124 avr2() {
125 
126  // const int nSec=3; char *secL[nSec]={"05U","07V","08U"}; int symA[nSec]={24,28,29}; TString tit="SMD-L1";
127  // const int nSec=3; char *secL[nSec]={"06U","05V","08V"}; int symA[nSec]={26,24,29}; TString tit="SMD-L2";
128  const int nSec=2; char *secL[nSec]={"01U","01V"}; int symA[nSec]={26,28}; TString tit="SMD-L3";
129 
130  TFile *fdA[nSec];
131  TString iPath="/star/u/wissink/cal2006/"; // location for output files
132 
133  //.......... open files
134  int j;
135  for(j=0;j<nSec;j++) {
136  TString fname=iPath+"smd"+secL[j]+".hist.root";
137  fdA[j]=new TFile(fname);
138  assert(fdA[j]->IsOpen());
139  }
140 
141  // ...... draw .........
142 
143  h=new TH1F(tit,tit+" Average recon MIP energy from pair of strips; strip ID; MIP energy [MeV]",290,.5,290.5);
144 
145  c=new TCanvas(tit,tit,600,400);
146  // c->Divide(2,2); c->cd(1);
147 
148  h->Draw();
149  h->SetMinimum(0.6);
150  h->SetMaximum(1.6);
151  gStyle->SetOptFit(0);
152  gStyle->SetOptStat(0);
153 
154  lg=new TLegend(.2,.15,.4,.45);
155 
156  for(j=0;j<nSec;j++) {
157  int col=kBlack+j+1;
158  TString grN="mpvN"; grN+=secL[j];
159  TGraphErrors *gr=(TGraphErrors *)fdA[j]->Get(grN);
160  assert(gr);
161  gr->Draw("P");
162  gr->SetMarkerStyle(symA[j]);
163  gr->SetLineColor(col);
164  gr->SetMarkerColor(col);
165 
166  // change pol4 -> pol2 3/30/2007 - sww
167  char *fncN="pol4";
168  gr->Fit(fncN);
169  TF1* f=gr->GetFunction(fncN); assert(f);
170  f->SetLineColor(col);
171  f->SetLineWidth(2);
172 
173  lg->AddEntry(gr,secL[j],"lpe");
174  }
175 
176  lg->Draw();
177 
178  // c->Print();
179 
180 
181 }