3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/IMessageSvc.h"
5#include "GaudiKernel/StatusCode.h"
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/Bootstrap.h"
9#include "GaudiKernel/SmartDataPtr.h"
10#include "GaudiKernel/IDataProviderSvc.h"
11#include "GaudiKernel/PropertyMgr.h"
44 delete m_hTrec[lay][lr];
46 delete m_hTrecZ[lay][lr][
bin];
62 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
63 MsgStream log(
msgSvc,
"PreT0MdcCalib");
64 log << MSG::INFO <<
"PreT0MdcCalib::initialize()" << endreq;
67 m_mdcGeomSvc = mdcGeomSvc;
68 m_mdcFunSvc = mdcFunSvc;
69 m_mdcUtilitySvc = mdcUtilitySvc;
78 m_fdTrec =
new TFolder(
"Trec",
"Trec");
79 m_hlist->Add(m_fdTrec);
81 m_fdTrecZ =
new TFolder(
"TrecZ",
"TrecZ");
82 m_hlist->Add(m_fdTrecZ);
86 if(0 == lr)
sprintf(hname,
"Trec%02d_L", lay);
87 else if(1 == lr)
sprintf(hname,
"Trec%02d_R", lay);
88 else sprintf(hname,
"Trec%02d_C", lay);
90 if(lay < 8) m_hTrec[lay][lr] =
new TH1F(hname,
"", 100, 0, 400);
91 else m_hTrec[lay][lr] =
new TH1F(hname,
"", 125, 0, 500);
92 m_fdTrec ->
Add(m_hTrec[lay][lr]);
97 for(
int iud=0; iud<2; iud++){
98 if(0 == iud)
sprintf(hname,
"TrecCosm%02d_Up", lay);
99 else sprintf(hname,
"TrecCosm%02d_Dw", lay);
100 if(lay < 8) m_hTrecCosm[lay][iud] =
new TH1F(hname,
"", 100, 0, 400);
101 else m_hTrecCosm[lay][iud] =
new TH1F(hname,
"", 125, 0, 500);
102 m_fdTrec ->
Add(m_hTrecCosm[lay][iud]);
109 if(0 == lr)
sprintf(hname,
"Trec%02d_z%02d_L", lay,
bin);
110 else if(1 == lr)
sprintf(hname,
"Trec%02d_z%02d_R", lay,
bin);
111 else sprintf(hname,
"Trec%02d_z%02d_C", lay,
bin);
113 if(lay < 8) m_hTrecZ[lay][lr][
bin] =
new TH1F(hname,
"", 100, 0, 400);
114 else m_hTrecZ[lay][lr][
bin] =
new TH1F(hname,
"", 125, 0, 500);
115 m_fdTrecZ ->
Add(m_hTrecZ[lay][lr][
bin]);
125 m_zwid[lay] = (zeast - zwest) / (
double)m_nzbin;
127 if(lay < 8) m_vp[lay] = 220.0;
128 else m_vp[lay] = 240.0;
130 if( 0 == (lay % 2) ){
140 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
141 MsgStream log(
msgSvc,
"PreT0MdcCalib");
142 log << MSG::DEBUG <<
"PreT0MdcCalib::fillHist()" << endreq;
166 IDataProviderSvc* eventSvc = NULL;
167 Gaudi::svcLocator()->service(
"EventDataSvc", eventSvc);
170 double tes =
event->getTes();
172 bool esCutFg =
event->getEsCutFlag();
173 if( ! esCutFg )
return -1;
176 int ntrk =
event -> getNTrk();
177 for(i=0; i<ntrk; i++){
178 rectrk =
event->getRecTrk(i);
179 nhit = rectrk -> getNHits();
180 for(k=0; k<nhit; k++){
181 rechit = rectrk -> getRecHit(k);
182 lay = rechit -> getLayid();
183 cel = rechit -> getCellid();
184 lr = rechit -> getLR();
185 zhit = rechit -> getZhit();
186 tdc = rechit -> getTdc();
187 tdr = rechit -> getTdrift();
192 zprop = fabs(zhit - m_zst[lay]);
193 bin = (int)(zprop / m_zwid[lay]);
194 tp = zprop / m_vp[lay];
195 t0 = m_mdcFunSvc -> getT0(lay, cel);
196 tof = rechit -> getTof();
198 double adc = rechit -> getQhit();
202 const MdcGeoWire* pWire = m_mdcGeomSvc -> Wire(lay, cel);
203 double y1 = pWire -> Backward().y();
204 double y2 = pWire -> Forward().y();
205 double ymid = (y1+y2)*0.5;
212 trec = traw - tp - tof - tes + m_param.
timeShift - tw;
214 m_hTrec[lay][lr] ->
Fill(trec);
215 m_hTrec[lay][2] ->
Fill(trec);
216 if(ymid > 0) m_hTrecCosm[lay][0] ->
Fill(trec);
217 else m_hTrecCosm[lay][1] ->
Fill(trec);
220 m_hTrecZ[lay][lr][
bin] ->
Fill(trec);
221 m_hTrecZ[lay][2][
bin] ->
Fill(trec);
230 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
231 MsgStream log(
msgSvc,
"PreT0MdcCalib");
232 log << MSG::DEBUG <<
"PreT0MdcCalib::updateConst()" << endreq;
243 double initT0 = m_param.
initT0;
262 fitTminFg[lay][lr] = 0;
263 chindfTmin[lay][lr] = -1;
264 sprintf(funname,
"ftmin%02d_%d", lay, lr);
265 ftmin[lay][lr] =
new TF1(funname, funTmin, 0, 150, 6);
268 Stat_t nEntryTot = 0;
269 for(
int ibin=1; ibin<=25; ibin++){
270 Stat_t entry = m_hTrec[lay][lr]->GetBinContent(ibin);
273 double c0Ini = (double)nEntryTot / 25.0;
274 double c1Ini = (m_hTrec[lay][lr]->GetMaximum()) - c0Ini;
276 ftmin[lay][lr] -> SetParameter(0, c0Ini);
277 ftmin[lay][lr] -> SetParameter(1, c1Ini);
278 ftmin[lay][lr] -> SetParameter(2, 0);
279 ftmin[lay][lr] -> SetParameter(4, initT0);
280 ftmin[lay][lr] -> SetParameter(5, 2);
282 m_hTrec[lay][lr] ->
Fit(funname,
"Q",
"",
285 gStyle -> SetOptFit(11);
288 chisq = ftmin[lay][lr]->GetChisquare();
289 ndf = ftmin[lay][lr]->GetNDF();
290 chindfTmin[lay][lr] = chisq / ndf;
293 fitTminFg[lay][lr] = 1;
294 t0Fit[lay][lr] = ftmin[lay][lr]->GetParameter(4);
296 t0Fit[lay][lr] += m_param.
t0Shift;
297 t0Cal[lay][lr] = t0Fit[lay][lr] - m_param.
timeShift;
301 if(0 == fitTminFg[lay][lr]){
302 wir = m_mdcGeomSvc->
Wire(lay, 0)->
Id();
303 t0Cal[lay][lr] = calconst->
getT0(wir);
304 t0Fit[lay][lr] = t0Cal[lay][lr] + m_param.
timeShift;
308 for(
int iud=0; iud<2; iud++){
309 sprintf(funname,
"ftminCosm_%02d_%d", lay, iud);
310 ftminCosm[lay][iud] =
new TF1(funname, funTmin, 0, 150, 6);
311 ftminCosm[lay][iud] -> SetParameter(0, 0);
312 ftminCosm[lay][iud] -> SetParameter(4, initT0);
313 ftminCosm[lay][iud] -> SetParameter(5, 1);
314 m_hTrecCosm[lay][iud] ->
Fit(funname,
"Q",
"",
317 gStyle -> SetOptFit(11);
318 t0FitCosm[lay][iud] += m_param.
t0Shift;
319 t0FitCosm[lay][iud] = ftminCosm[lay][iud]->GetParameter(4);
327 fitTmaxFg[lay][lr] = 0;
328 chindfTmax[lay][lr] = -1;
329 sprintf(funname,
"ftmax%02d_%d", lay, lr);
330 ftmax[lay][lr] =
new TF1(funname, funTmax, 250, 500, 4);
333 ftmax[lay][lr] -> SetParameter(2, m_param.
initTm[lay]);
334 ftmax[lay][lr] -> SetParameter(3, 10);
335 m_hTrec[lay][lr] ->
Fit(funname,
"Q+",
"",
338 gStyle -> SetOptFit(11);
339 chisq = ftmax[lay][lr]->GetChisquare();
340 ndf = ftmax[lay][lr]->GetNDF();
341 chindfTmax[lay][lr] = chisq / ndf;
343 fitTmaxFg[lay][lr] = 1;
344 tmax[lay][lr] = ftmax[lay][lr]->GetParameter(2);
348 if(0 == fitTmaxFg[lay][lr]){
349 tmax[lay][lr] = (calconst->
getXtpar(lay, 0, lr, 6)) + t0Fit[lay][2];
355 ofstream ft0(
"preT0.dat");
357 ft0 << setw(5) << lay << setw(3) << fitTminFg[lay][2]
358 << setw(15) << t0Cal[lay][2] << setw(15) << t0Fit[lay][2]
359 << setw(15) << chindfTmin[lay][2] << endl;
363 ft0 << setw(5) << lay
364 << setw(3) << fitTmaxFg[lay][0] << setw(10) << tmax[lay][0]
365 << setw(10) << chindfTmax[lay][0]
366 << setw(3) << fitTmaxFg[lay][1] << setw(10) << tmax[lay][1]
367 << setw(10) << chindfTmax[lay][1]
368 << setw(3) << fitTmaxFg[lay][2] << setw(10) << tmax[lay][2]
369 << setw(10) << chindfTmax[lay][2]
370 << setw(10) << tmax[lay][0] - t0Fit[lay][2]
371 << setw(10) << tmax[lay][1] - t0Fit[lay][2]
372 << setw(10) << tmax[lay][2] - t0Fit[lay][2]
376 cout <<
"preT0.dat was written." << endl;
379 ofstream ft0cosm(
"cosmicT0.dat");
381 ft0cosm << setw(5) << lay << setw(15) << t0Fit[lay][2]
382 << setw(15) << t0FitCosm[lay][0] << setw(15) << t0FitCosm[lay][1] << endl;
388 int nwire = m_mdcGeomSvc -> getWireSize();
389 for(i=0; i<nwire; i++){
390 lay = m_mdcGeomSvc -> Wire(i) -> Layer();
392 calconst -> resetT0(i, t0Cal[lay][2]);
393 calconst -> resetDelT0(i, 0.0);
402 if(1 != m_param.
fgCalib[lay])
continue;
406 tm = tmax[lay][lr] - t0Fit[lay][2];
409 calconst -> resetXtpar(lay, iEntr, lr, 6, tm);
421 for(lr=0; lr<2; lr++){
423 calconst -> resetSdpar(lay, iEntr, lr,
bin, sdpar);
432 delete ftmin[lay][lr];
433 delete ftmax[lay][lr];
438Double_t PreT0MdcCalib::funTmin(Double_t* x, Double_t* par){
440 fitval = par[0] + par[1]*
exp( -par[2]*(x[0]-par[3]) ) /
441 ( 1 +
exp( -(x[0]-par[4])/par[5] ));
445Double_t PreT0MdcCalib::funTmax(Double_t* x, Double_t* par){
447 fitval = par[0] + par[1] / (1 +
exp((x[0]-par[2])/par[3]));
EvtComplex exp(const EvtComplex &c)
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
const double MdcCalTdcCnv
virtual double getTimeWalk(int layid, double Q) const =0
virtual const MdcGeoWire *const Wire(unsigned id)=0
double initTm[MdcCalNLayer]
int fgCalib[MdcCalNLayer]
double tminFitRange[MdcCalNLayer][2]
double tmaxFitRange[MdcCalNLayer][2]
double getT0(int wireid) const
double getXtpar(int lay, int entr, int lr, int order)
HepPoint3D Forward(void) const
HepPoint3D Backward(void) const
int updateConst(MdcCalibConst *calconst)
int fillHist(MdcCalEvent *event)
void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)