2#include "include/fun.h"
12 for(
int lay=0; lay<
NLAYER; lay++){
13 m_tbinWid[lay][0] = 5.0;
14 m_tbinWid[lay][1] = 10.0;
15 m_tbinWid[lay][2] = 20.0;
17 m_tbinLim[lay][0] = -10.0;
18 m_tbinLim[lay][1] = 30.0;
19 if(lay < 8) m_tbinLim[lay][2] = 210.0;
20 else m_tbinLim[lay][2] = 350.0;
21 m_tbinLim[lay][3] = 990.0;
23 cout <<
"Calibration type: XtInteCalib" << endl;
32 m_fdPf =
new TFolder(
"mfdProfile",
"fdProfile");
35 m_haxis =
new TH2F(
"axis",
"", 200, -50, 1000, 50, 0, 10);
36 m_haxis -> SetStats(0);
37 m_fdPf -> Add(m_haxis);
40 for(
int lay=0; lay<
NLAYER; lay++){
41 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
42 for(
int lr=0; lr<2; lr++){
43 sprintf(hname,
"mxt%02d_%02d_%d_gr", lay, iEntr, lr);
44 m_grXt[lay][iEntr][lr] =
new TGraph();
45 m_grXt[lay][iEntr][lr]->SetName(hname);
46 m_grXt[lay][iEntr][lr]->SetMarkerColor(2);
47 m_fdPf->Add(m_grXt[lay][iEntr][lr]);
49 int xbinN = (int)((m_tbinLim[lay][1] - m_tbinLim[lay][0])/m_tbinWid[lay][0] + 0.5);
50 sprintf(hname,
"mxt%02d_%02d_%d_near", lay, iEntr, lr);
51 m_pfNear[lay][iEntr][lr] =
new TProfile(hname, hname, xbinN, m_tbinLim[lay][0], m_tbinLim[lay][1]);
52 m_fdPf->Add(m_pfNear[lay][iEntr][lr]);
54 int xbinM = (int)((m_tbinLim[lay][2] - m_tbinLim[lay][1])/m_tbinWid[lay][1] + 0.5);
55 sprintf(hname,
"mxt%02d_%02d_%d_mid", lay, iEntr, lr);
56 m_pfMid[lay][iEntr][lr] =
new TProfile(hname, hname, xbinM, m_tbinLim[lay][1], m_tbinLim[lay][2]);
57 m_fdPf->Add(m_pfMid[lay][iEntr][lr]);
59 int xbinF = (int)((m_tbinLim[lay][3] - m_tbinLim[lay][2])/m_tbinWid[lay][2] + 0.5);
60 sprintf(hname,
"mxt%02d_%02d_%d_far", lay, iEntr, lr);
61 m_pfFar[lay][iEntr][lr] =
new TProfile(hname, hname, xbinF, m_tbinLim[lay][2], m_tbinLim[lay][3]);
62 m_fdPf->Add(m_pfFar[lay][iEntr][lr]);
74 TFolder* fd = (TFolder*)fhist->Get(
"fdProfile");
75 for(
int lay=0; lay<
NLAYER; lay++){
76 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
77 for(
int lr=0; lr<2; lr++){
78 if((m_grXt[lay][iEntr][lr]->GetN()) < m_nMaxGrPoint){
79 sprintf(hname,
"xt%02d_%02d_%d_gr", lay, iEntr, lr);
80 TGraph*
gr = (TGraph*)fd->FindObjectAny(hname);
81 int nPoint =
gr->GetN();
82 for(
int i=0; i<nPoint; i++){
83 gr->GetPoint(i, tdr, doca);
84 int np = m_grXt[lay][iEntr][lr]->GetN();
85 m_grXt[lay][iEntr][lr]->SetPoint(np, tdr, doca);
88 sprintf(hname,
"xt%02d_%02d_%d_near", lay, iEntr, lr);
89 pr = (TProfile*)fd->FindObjectAny(hname);
90 m_pfNear[lay][iEntr][lr]->Add(pr);
92 sprintf(hname,
"xt%02d_%02d_%d_mid", lay, iEntr, lr);
93 pr = (TProfile*)fd->FindObjectAny(hname);
94 m_pfMid[lay][iEntr][lr]->Add(pr);
96 sprintf(hname,
"xt%02d_%02d_%d_far", lay, iEntr, lr);
97 pr = (TProfile*)fd->FindObjectAny(hname);
98 m_pfFar[lay][iEntr][lr]->Add(pr);
106 bool fgOldXt = saveOldXt(newXtList);
111 for(
int lay=0; lay<
NLAYER; lay++){
112 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
113 for(
int lr=0; lr<2; lr++){
117 for(
int iPf=0; iPf<3; iPf++){
119 if(0==iPf) pro = m_pfNear[lay][iEntr][lr];
120 else if(1==iPf) pro = m_pfMid[lay][iEntr][lr];
121 else pro = m_pfFar[lay][iEntr][lr];
123 int nbin = pro->GetNbinsX();
124 for(
int i=0; i<nbin; i++){
125 double tt = pro->GetBinCenter(i+1);
126 double dd = pro->GetBinContent(i+1);
127 double entries = pro->GetBinEntries(i+1);
131 m_entries.push_back(entries);
135 unsigned vsize = m_vt.size();
137 for(
int i=0; i<2; i++){
138 double slope = (m_vd[vsize-1]-m_vd[vsize-2])/(m_vt[vsize-1]-m_vt[vsize-2]);
139 if(fabs(slope)>0.04){
142 m_entries.pop_back();
147 sprintf(hname,
"grXtFit%02d_%02d_%d", lay, iEntr, lr);
148 grXtfit[lay][iEntr][lr] =
new TGraph();
149 grXtfit[lay][iEntr][lr]->SetName(hname);
150 grXtfit[lay][iEntr][lr]->SetMarkerStyle(20);
151 m_fgFit[lay][iEntr][lr] = getXt(lay, iEntr, lr, grXtfit[lay][iEntr][lr]);
157 for(
int lay=0; lay<
NLAYER; lay++){
159 if(lay<8) tCut = 400.0;
160 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
161 for(
int lr=0; lr<2; lr++){
162 if(!m_fgFit[lay][iEntr][lr]){
163 int iEntrNew = findXtEntr(lay, iEntr, lr);
165 int npoint = grXtfit[lay][iEntrNew][lr]->GetN();
166 for(
int i=0; i<npoint; i++){
167 grXtfit[lay][iEntrNew][lr]->GetPoint(i, tdr, doca);
168 grXtfit[lay][iEntr][lr]->SetPoint(i, tdr, doca);
171 cout << grXtfit[lay][iEntr][lr]->GetName() <<
" use old x-t" << endl;
172 int npoint = m_grXtOld[lay][iEntr][lr]->GetN();
173 for(
int i=0; i<npoint; i++){
174 m_grXtOld[lay][iEntr][lr]->GetPoint(i, tdr, doca);
175 grXtfit[lay][iEntr][lr]->SetPoint(i, tdr, doca);
179 int nn = grXtfit[lay][iEntr][lr]->GetN();
181 grXtfit[lay][iEntr][lr]->GetPoint(nn-1, tmax,
dmax);
182 if(tmax > tCut) m_fgEdge[lay][iEntr][lr] =
true;
183 else m_fgEdge[lay][iEntr][lr] =
false;
188 for(
int lay=0; lay<
NLAYER; lay++){
189 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
190 for(
int lr=0; lr<2; lr++){
191 if(!m_fgEdge[lay][iEntr][lr]){
192 int iEntrNew = findXtEntrEdge(lay, iEntr, lr);
195 int n1 = grXtfit[lay][iEntr][lr]->GetN();
196 grXtfit[lay][iEntr][lr]->GetPoint(
n1-1, t1, d1);
198 int n2 = grXtfit[lay][iEntrNew][lr]->GetN();
199 for(
int i=0; i<
n2; i++){
200 grXtfit[lay][iEntrNew][lr]->GetPoint(i, t2, d2);
202 grXtfit[lay][iEntr][lr]->SetPoint(
n1, t2, d2);
213 for(
int lay=0; lay<
NLAYER; lay++){
214 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
215 for(
int lr=0; lr<2; lr++){
216 sprintf(hname,
"trNewXt%02d_%02d_%d", lay, iEntr, lr);
217 xttr[lay][iEntr][lr] =
new TTree(hname, hname);
218 xttr[lay][iEntr][lr]->Branch(
"t", &tdr,
"t/D");
219 xttr[lay][iEntr][lr]->Branch(
"d", &doca,
"d/D");
221 int npoint = m_grXtOld[lay][iEntr][lr]->GetN();
222 for(
int i=0; i<npoint; i++){
223 m_grXtOld[lay][iEntr][lr]->GetPoint(i, tdr, doca);
224 xttr[lay][iEntr][lr]->Fill();
227 int npoint = grXtfit[lay][iEntr][lr]->GetN();
228 for(
int i=0; i<npoint; i++){
229 grXtfit[lay][iEntr][lr]->GetPoint(i, tdr, doca);
230 xttr[lay][iEntr][lr]->Fill();
233 newXtList->Add(xttr[lay][iEntr][lr]);
238 for(
int lay=0; lay<
NLAYER; lay++){
239 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
240 for(
int lr=0; lr<2; lr++){
241 delete grXtfit[lay][iEntr][lr];
250void XtInteCalib::renameHist(){
252 m_fdPf->SetName(
"fdProfile");
253 for(
int lay=0; lay<
NLAYER; lay++){
254 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
255 for(
int lr=0; lr<2; lr++){
256 sprintf(hname,
"xt%02d_%02d_%d_gr", lay, iEntr, lr);
257 m_grXt[lay][iEntr][lr] -> SetName(hname);
258 sprintf(hname,
"xt%02d_%02d_%d_near", lay, iEntr, lr);
259 m_pfNear[lay][iEntr][lr] -> SetName(hname);
260 sprintf(hname,
"xt%02d_%02d_%d_mid", lay, iEntr, lr);
261 m_pfMid[lay][iEntr][lr] -> SetName(hname);
262 sprintf(hname,
"xt%02d_%02d_%d_far", lay, iEntr, lr);
263 m_pfFar[lay][iEntr][lr] -> SetName(hname);
269bool XtInteCalib::saveOldXt(TObjArray* newXtList){
271 Int_t entries = newXtList->GetEntries();
272 cout <<
"entries of newXtList " << entries << endl;
274 cout <<
"can not get old x-t" << endl;
277 for(
int lay=0; lay<
NLAYER; lay++){
278 for(
int iEntr=0; iEntr<
NENTRXT; iEntr++){
279 for(
int lr=0; lr<2; lr++){
280 sprintf(hname,
"grXtOld%02d_%02d_%d", lay, iEntr, lr);
281 m_grXtOld[lay][iEntr][lr] =
new TGraph();
282 m_grXtOld[lay][iEntr][lr]->SetName(hname);
285 sprintf(hname,
"trNewXt%02d_%02d_%d", lay, iEntr, lr);
286 TTree* tr = (TTree*)(newXtList->FindObject(hname));
290 int nPoint = tr -> GetEntries();
292 cout <<
"can not get old x-t: " << hname << endl;
295 for(
int i=0; i<nPoint; i++){
297 m_grXtOld[lay][iEntr][lr]->SetPoint(i,
t, d);
313bool XtInteCalib::getXt(
int lay,
int iEntr,
int lr, TGraph*
gr){
314 unsigned vsize = m_vt.size();
315 if(vsize < 15)
return false;
317 double tmax = m_vt[vsize-1];
327 for(
unsigned i=0; i<vsize; i++){
328 if(m_vt[i] < tm0) n0++;
334 double entries1 = 0.0;
335 double entries2 = 0.0;
336 for(
unsigned i=0; i<vsize; i++){
337 entries1 += m_entries[i];
338 if(m_vt[i] < 150.) entries2 += m_entries[i];
340 if((entries1*0.9) < entries2)
return false;
342 if(n0 < nCut)
return false;
343 if(tmax < tm1)
return funXt0(lay,iEntr,lr,
gr);
344 else return funXt1(lay,iEntr,lr,
gr);
347bool XtInteCalib::funXt0(
int lay,
int iEntr,
int lr, TGraph*
gr){
349 if(lay<8) tCut = 200.0;
353 gr->SetPoint(0, 0, 0);
356 for(
unsigned i=0; i<m_vt.size(); i++){
358 if(i>10) delt = m_vt[i] - m_vt[i-1];
359 if((i>10) && ((delt>100.) || ((delt>60.) && (m_vt[i-1]<tCut))))
break;
361 if(m_vt[i] < 0.0)
gr->SetPoint(npoint, m_vt[i], 0.0);
362 else gr->SetPoint(npoint, m_vt[i], m_vd[i]);
368bool XtInteCalib::funXt1(
int lay,
int iEntr,
int lr, TGraph*
gr){
369 unsigned vsize = m_vt.size();
370 double tmax = m_vt[vsize-1];
373 if(tmax<540) t1 = 300.;
376 if(tmax<700) t1 = 500.;
384 TGraph* grPol1 =
new TGraph();
385 for(
unsigned i=0; i<vsize; i++){
387 grPol1->SetPoint(np, m_vt[i], m_vd[i]);
396 grPol1->GetPoint(0,t2,x2);
397 grPol1->Fit(
"pol1",
"Q",
"",t2, m_vt[vsize-1]);
398 c0 = grPol1->GetFunction(
"pol1")->GetParameter(0);
399 c1 = grPol1->GetFunction(
"pol1")->GetParameter(1);
402 grPol1->Fit(
"pol0",
"Q",
"",t2, m_vt[vsize-1]);
403 c0 = grPol1->GetFunction(
"pol0")->GetParameter(0);
410 if(lay<8) tCut = 200.0;
414 gr->SetPoint(0, 0, 0);
417 for(
unsigned i=0; i<vsize; i++){
419 if(i>10) delt = m_vt[i] - m_vt[i-1];
420 if((i>10) && ((delt>100.) || ((delt>60.) && (m_vt[i-1]<tCut))))
break;
423 if(m_vt[i] < 0.0)
gr->SetPoint(npoint, m_vt[i], 0.0);
424 else gr->SetPoint(npoint, m_vt[i], m_vd[i]);
428 if(!fgfit) dist = m_vd[i];
429 else dist = c1*m_vt[i] + c0;
430 gr->SetPoint(npoint, m_vt[i], dist);
438int XtInteCalib::findXtEntr(
int lay,
int iEntr,
int lr)
const {
445 for(
int i=iEntr; i<=id0; i++){
446 if(m_fgFit[lay][i][lr]){
451 if(-1 !=
id) entrId = id;
453 for(
int i=iEntr; i>=0; i--){
454 if(m_fgFit[lay][i][lr]){
459 if(-1 !=
id) entrId = id;
461 for(
int i=id1; i<=idmax; i++){
462 if(m_fgFit[lay][i][lr]){
472 for(
int i=iEntr; i>=id1; i--){
473 if(m_fgFit[lay][i][lr]){
478 if(-1 !=
id) entrId = id;
480 for(
int i=iEntr; i<idmax; i++){
481 if(m_fgFit[lay][i][lr]){
486 if(-1 !=
id) entrId = id;
488 for(
int i=id1; i>=0; i--){
489 if(m_fgFit[lay][i][lr]){
499 cout <<
"find EntrId error " <<
"layer " << lay <<
" iEntr " << iEntr <<
" lr " << lr << endl;
505int XtInteCalib::findXtEntrEdge(
int lay,
int iEntr,
int lr)
const {
512 for(
int i=iEntr; i<=id0; i++){
513 if(m_fgEdge[lay][i][lr]){
518 if(-1 !=
id) entrId = id;
520 for(
int i=iEntr; i>=0; i--){
521 if(m_fgEdge[lay][i][lr]){
526 if(-1 !=
id) entrId = id;
528 for(
int i=id1; i<=idmax; i++){
529 if(m_fgEdge[lay][i][lr]){
539 for(
int i=iEntr; i>=id1; i--){
540 if(m_fgEdge[lay][i][lr]){
545 if(-1 !=
id) entrId = id;
547 for(
int i=iEntr; i<idmax; i++){
548 if(m_fgEdge[lay][i][lr]){
553 if(-1 !=
id) entrId = id;
555 for(
int i=id1; i>=0; i--){
556 if(m_fgEdge[lay][i][lr]){
566 cout <<
"find EntrId error for cell edge " <<
"layer " << lay <<
" iEntr " << iEntr <<
" lr " << lr << endl;
data SetBranchAddress("time",&time)
virtual void init(TObjArray *hlist, MdcCosGeom *pGeom)=0
virtual void mergeHist(TFile *fhist)=0
virtual void calib(MdcCalibConst *calconst, TObjArray *newXtList, TObjArray *r2tList)=0
void calib(MdcCalibConst *calconst, TObjArray *newXtList, TObjArray *r2tList)
void mergeHist(TFile *fhist)
void init(TObjArray *hlist, MdcCosGeom *pGeom)