1#include "MdcCalibAlg/XtMdcCalib.h"
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"
39 for(
int lay=0; lay<43; lay++){
40 if(lay < 15) m_nEntr[lay] = 1;
41 else m_nEntr[lay] = 2;
52 cout <<
"~XtMdcCalib" << endl;
55 for(i=0; i<m_hxt.size(); i++){
57 if(0 == (i % 1000)) cout <<
"delete hxt[" << i <<
"]" << endl;
70 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
71 MsgStream log(
msgSvc,
"XtMdcCalib");
72 log << MSG::INFO <<
"XtMdcCalib::initialize()" << endreq;
75 m_mdcGeomSvc = mdcGeomSvc;
76 m_mdcFunSvc = mdcFunSvc;
77 m_mdcUtilitySvc = mdcUtilitySvc;
90 m_fdXt =
new TFolder(
"fdXt",
"fdXt");
91 m_hlist ->
Add(m_fdXt);
93 m_nlayer = m_mdcGeomSvc -> getLayerSize();
96 for(lay=0; lay<m_nlayer; lay++){
97 for(iEntr=0; iEntr<m_nEntr[lay]; iEntr++){
98 for(iLR=0; iLR<m_nLR; iLR++){
100 sprintf(hname,
"Hxt%02d_E%02d_LR%01d_B%02d", lay, iEntr, iLR,
bin);
101 hist =
new TH1D(hname,
"", 300, -1.5, 1.5);
102 m_hxt.push_back( hist );
103 m_fdXt ->
Add( hist );
116 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
117 MsgStream log(
msgSvc,
"XtMdcCalib");
118 log << MSG::DEBUG <<
"XtMdcCalib::fillHist()" << endreq;
123 bool esCutFg =
event->getEsCutFlag();
124 if( ! esCutFg )
return -1;
154 for(iEntr=0; iEntr<m_nEntr[lay]; iEntr++){
157 if(0 == iEntr) m_mdcFunSvc -> getXtpar(lay, 8, iLR, xtpar);
158 else if(1 == iEntr) m_mdcFunSvc -> getXtpar(lay, 9, iLR, xtpar);
159 m_tm[lay][iEntr][iLR] = xtpar[6];
170 int ntrk =
event -> getNTrk();
171 if((ntrk < m_param.
nTrkCut[0]) || (ntrk > m_param.
nTrkCut[1]))
return -1;
172 for(i=0; i<ntrk; i++){
173 rectrk =
event->getRecTrk(i);
174 nhit = rectrk -> getNHits();
177 dr = rectrk->
getDr();
178 if(fabs(dr) > m_param.
drCut)
continue;
181 dz = rectrk->
getDz();
182 if(fabs(dz) > m_param.
dzCut)
continue;
185 fgHitLay[lay] =
false;
188 for(k=0; k<nhit; k++){
189 rechit = rectrk -> getRecHit(k);
190 lay = rechit -> getLayid();
191 fgHitLay[lay] =
true;
196 if(fgHitLay[lay]) nhitlay++;
203 for(k=0; k<nhit; k++){
204 rechit = rectrk -> getRecHit(k);
205 lay = rechit -> getLayid();
206 doca = rechit -> getDocaInc();
207 iLR = rechit -> getLR();
208 entrance = rechit -> getEntra();
209 resi = rechit -> getResiInc();
210 tdr = rechit -> getTdrift();
211 stat = rechit -> getStat();
213 if(1 != stat)
continue;
215 if( (fabs(doca) > m_docaMax[lay]) ||
216 (fabs(resi) > m_param.
resiCut[lay]) ){
221 if( ! fgHitLay[1] )
continue;
222 }
else if(42 == lay){
223 if( ! fgHitLay[41] )
continue;
225 if( (!fgHitLay[lay-1]) && (!fgHitLay[lay+1]) )
continue;
228 iEntr = m_mdcFunSvc -> getXtEntrIndex(entrance);
229 if(1 == m_nEntr[lay]){
231 }
else if(2 == m_nEntr[lay]){
232 if(entrance > 0.0) iEntr = 1;
236 bin = (int)(tdr / m_tbinw);
240 if((
bin < m_nbin) && (1 == m_hxtmap.count(
key))){
242 m_hxt[hid] -> Fill( resi );
247 if((
bin < m_nbin) && (1 == m_hxtmap.count(
key))){
249 m_hxt[hid] -> Fill( resi );
252 if(fabs(tdr - m_tm[lay][iEntr][iLR]) < 5){
254 if( 1 == m_hxtmap.count(
key) ){
256 m_hxt[hid] -> Fill( resi );
260 if( 1 == m_hxtmap.count(
key) ){
262 m_hxt[hid] -> Fill( resi );
273 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
274 MsgStream log(
msgSvc,
"XtMdcCalib");
275 log << MSG::INFO <<
"XtMdcCalib::updateConst()" << endreq;
305 Double_t arglist[10];
307 TMinuit* gmxt =
new TMinuit(6);
308 gmxt -> SetPrintLevel(-1);
309 gmxt -> SetFCN(
fcnXT);
310 gmxt -> SetErrorDef(1.0);
311 gmxt -> mnparm(0,
"xtpar0", 0, 0.1, 0, 0, ierflg);
312 gmxt -> mnparm(1,
"xtpar1", 0, 0.1, 0, 0, ierflg);
313 gmxt -> mnparm(2,
"xtpar2", 0, 0.1, 0, 0, ierflg);
314 gmxt -> mnparm(3,
"xtpar3", 0, 0.1, 0, 0, ierflg);
315 gmxt -> mnparm(4,
"xtpar4", 0, 0.1, 0, 0, ierflg);
316 gmxt -> mnparm(5,
"xtpar5", 0, 0.1, 0, 0, ierflg);
318 gmxt -> mnexcm(
"SET NOW", arglist, 0, ierflg);
320 TMinuit* gmxtEd =
new TMinuit(1);
321 gmxtEd -> SetPrintLevel(-1);
323 gmxtEd -> SetErrorDef(1.0);
324 gmxtEd -> mnparm(0,
"xtpar0", 0, 0.1, 0, 0, ierflg);
326 gmxtEd -> mnexcm(
"SET NOW", arglist, 0, ierflg);
328 ofstream fxtlog(
"xtlog");
329 for(lay=0; lay<m_nlayer; lay++){
330 if(0 == m_param.
fgCalib[lay])
continue;
332 for(iEntr=0; iEntr<m_nEntr[lay]; iEntr++){
333 for(iLR=0; iLR<m_nLR; iLR++){
335 fxtlog <<
"Layer " << setw(3) << lay << setw(3) << iEntr
336 << setw(3) << iLR << endl;
338 for(ord=0; ord<m_nxtpar; ord++){
340 if(0 == iEntr) xtpar = calconst -> getXtpar(lay, 8, iLR, ord);
341 else if(1 == iEntr) xtpar = calconst -> getXtpar(lay, 9, iLR, ord);
353 entry = m_hxt[hid] -> GetEntries();
355 deltx = m_hxt[hid] -> GetMean();
356 xerr = m_hxt[hid]->GetRMS();
362 tbcen = ( (double)
bin + 0.5 ) * m_tbinw;
363 else tbcen = m_tm[lay][iEntr][iLR];
364 xcor =
xtFun(tbcen, xtini) - deltx;
366 if((tbcen <=
Tmax) || (
bin == m_nbin)){
368 XMEAS.push_back( xcor );
369 ERR.push_back( xerr );
373 ERRED.push_back( xerr );
375 fxtlog << setw(3) <<
bin
383 if(
XMEAS.size() < 12 ){
395 for(ord=0; ord<=5; ord++){
396 arglist[0] = ord + 1;
397 arglist[1] = xtini[ord];
398 gmxt -> mnexcm(
"SET PARameter", arglist, 2, ierflg);
405 gmxt -> mnexcm(
"SET PARameter", arglist, 2, ierflg);
406 gmxt -> mnexcm(
"FIX", arglist, 1, ierflg);
411 gmxt -> mnexcm(
"MIGRAD", arglist, 2, ierflg);
412 gmxt -> mnstat(fmin, edm, errdef, nvpar, nparx, istat);
414 fxtlog <<
"Xtpar: " << endl;
415 if( (0 == ierflg) && (istat >= 2) ){
416 for(ord=0; ord<=5; ord++){
417 gmxt -> GetParameter(ord, xtpar, xterr);
421 if(1 == m_nEntr[lay]){
423 calconst -> resetXtpar(lay, i, iLR, ord, xtpar);
424 }
else if(2 == m_nEntr[lay]){
427 calconst->
resetXtpar(lay, i, iLR, ord, xtpar);
430 calconst->
resetXtpar(lay, i, iLR, ord, xtpar);
433 fxtlog << setw(15) << xtpar << setw(15) << xterr << endl;
436 for(ord=0; ord<=5; ord++){
437 fxtlog << setw(15) << xtini[ord] << setw(15) <<
"0" << endl;
440 fxtlog << setw(15) <<
Tmax << setw(15) <<
"0" << endl;
445 gmxt -> mnexcm(
"REL", arglist, 1, ierflg);
453 arglist[1] = xtini[7];
454 gmxtEd -> mnexcm(
"SET PARameter", arglist, 2, ierflg);
458 gmxtEd -> mnexcm(
"MIGRAD", arglist, 2, ierflg);
459 gmxtEd -> mnstat(fmin, edm, errdef, nvpar, nparx, istat);
461 if( (0 == ierflg) && (istat >=2) ){
462 gmxtEd -> GetParameter(0, xtpar, xterr);
463 if(xtpar < 0.0) xtpar = 0.0;
467 if(1 == m_nEntr[lay]){
469 calconst -> resetXtpar(lay, i, iLR, 7, xtpar);
470 }
else if(2 == m_nEntr[lay]){
479 fxtlog << setw(15) << xtpar << setw(15) << xterr << endl;
481 fxtlog << setw(15) << xtini[7] << setw(15) <<
"0" << endl;
484 fxtlog << setw(15) << xtini[7] << setw(15) <<
"0" << endl;
486 fxtlog <<
"Tm " << setw(15) <<
Tmax
487 <<
" Dmax " << setw(15) <<
Dmax << endl;
502 cout <<
"Xt update finished" << endl;
509 key = ( (lay << HXTLAYER_INDEX) & HXTLAYER_MASK ) |
510 ( (entr << HXTENTRA_INDEX) & HXTENTRA_MASK ) |
511 ( (lr << HXTLR_INDEX) & HXTLR_MASK ) |
512 ( (
bin << HXTBIN_INDEX) & HXTBIN_MASK );
518 Double_t *par, Int_t iflag){
522 Double_t chisq = 0.0;
525 for(i=0; i<
TBINCEN.size(); i++){
527 for(ord=0; ord<=5; ord++){
528 dfit += par[ord] * pow(
TBINCEN[i], ord);
531 chisq += deta * deta;
540 double tmax = xtpar[6];
543 for(ord=0; ord<=5; ord++){
544 dist += xtpar[ord] * pow(
t, ord);
547 for(ord=0; ord<=5; ord++){
548 dist += xtpar[ord] * pow(tmax, ord);
550 dist += xtpar[7] * (
t - tmax);
556 Double_t *par, Int_t iflag){
559 Double_t chisq = 0.0;
565 chisq += deta * deta;
*******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
*************DOUBLE PRECISION m_pi *DOUBLE PRECISION m_HvecTau2 DOUBLE PRECISION m_HvClone2 DOUBLE PRECISION m_gamma1 DOUBLE PRECISION m_gamma2 DOUBLE PRECISION m_thet1 DOUBLE PRECISION m_thet2 INTEGER m_IFPHOT *COMMON c_Taupair $ !Spin Polarimeter vector first Tau $ !Spin Polarimeter vector second Tau $ !Clone Spin Polarimeter vector first Tau $ !Clone Spin Polarimeter vector second Tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning st tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !Random Euler angle for cloning nd tau $ !phi of HvecTau1 $ !theta of HvecTau1 $ !phi of HvecTau2 $ !theta of HvecTau2 $ !super key
map< int, int >::value_type valType2
double resiCut[MdcCalNLayer]
int fgCalib[MdcCalNLayer]
void resetXtpar(int lay, int entr, int lr, int order, double val)
virtual void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)=0
virtual int updateConst(MdcCalibConst *calconst)=0
virtual int fillHist(MdcCalEvent *event)=0
int getHxtKey(int lay, int entr, int lr, int bin) const
int updateConst(MdcCalibConst *calconst)
static double xtFun(double t, double xtpar[])
static std::vector< double > ERR
static void fcnXT(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
int fillHist(MdcCalEvent *event)
static std::vector< double > ERRED
static std::vector< double > XMEAS
void initialize(TObjArray *hlist, IMdcGeomSvc *mdcGeomSvc, IMdcCalibFunSvc *mdcFunSvc, IMdcUtilitySvc *mdcUtilitySvc)
static void fcnXtEdge(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
static std::vector< double > XMEASED
static std::vector< double > TBINCEN
static std::vector< double > TBINCENED
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)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")