25 #include "StTofCell.h"
26 #include "StTofSlat.h"
27 #include "StTofData.h"
28 #include "StTofPidTraits.h"
29 #include "StEventTypes.h"
31 #include "StMessMgr.h"
32 #include "StThreeVectorD.hh"
34 #include "StTrackGeometry.h"
35 #include "StEventUtilities/StuRefMult.hh"
36 #include "PhysicalConstants.h"
37 #include "phys_constants.h"
38 #include "StPhysicalHelixD.hh"
39 #include "tables/St_tofTzero_Table.h"
40 #include "tables/St_tofTACorr_Table.h"
41 #include "tables/St_tofCorrection_Table.h"
42 #include "tables/St_tofAdcRange_Table.h"
43 #include "tables/St_tofResolution_Table.h"
45 #include "tables/St_tofr5INLtable_Table.h"
46 #include "tables/St_tofTotCorr_Table.h"
47 #include "tables/St_tofZCorr_Table.h"
49 #include "tables/St_vertexSeed_Table.h"
51 #include "tables/St_tofTOffset_Table.h"
52 #include "tables/St_tofPhaseOffset_Table.h"
54 #include "StTofUtil/tofPathLength.hh"
55 #include "StTofUtil/StTofDataCollection.h"
56 #include "StTofUtil/StTofSlatCollection.h"
57 #include "StTofUtil/StTofCellCollection.h"
58 #include "StTofUtil/StTofHitCollection.h"
59 #include "StTofUtil/StTofGeometry.h"
60 #include "StTofCalibMaker.h"
62 #include "StMessMgr.h"
63 #include "StMemoryInfo.hh"
73 setTDCLimits(20, 1500);
77 setPVPDADCLimits(30,1100);
78 setPVPDTDCLimits(1,2000);
82 mValidStartTime = kTRUE;
83 mEastPVPDValid = kTRUE;
102 for(
int i=0;i<mNPar;i++) {
106 for(
int i=0;i<mNTOFr;i++) {
109 for(
int i=0;i<mNTOFr*mNPar;i++) {
112 for(
int i=0;i<mNTOFp;i++) {
115 for(
int i=0;i<mNTOFp*mNPar;i++) {
118 for(
int i=0;i<mNPVPD*mNPar;i++) {
122 mValidCalibPar = kFALSE;
125 for(
int i=0;i<mNTOFr;i++) {
127 mTofrADCMax[i] = 1024.;
130 for(
int i=0;i<mNTOFp;i++) {
132 mTofpADCMax[i] = 1024.;
135 for(
int i=0;i<mNPVPD;i++) {
140 for(
int i=0;i<mTdigBoard;i++) {
141 for(
int j=0;j<mTdcOnBoard;j++) {
142 for(
int k=0;k<mTdcChannel;k++) {
143 mINLtable[i][j][k] = 0.0;
148 for(
int i=0;i<mNTOFr5;i++) {
149 for(
int j=0;j<mNBinMax;j++) {
150 mTofr5TotEdge[i][j] = 0.0;
151 mTofr5TotCorr[i][j] = 0.0;
152 mTofr5ZEdge[i][j] = 0.0;
153 mTofr5ZCorr[i][j] = 0.0;
157 for(
int i=0;i<mNPVPD;i++) {
158 for(
int j=0;j<mNBinMax;j++) {
159 mPVPDTotEdge[i][j] = 0.0;
160 mPVPDTotCorr[i][j] = 0.0;
165 for(
int i=0;i<mNTray;i++) {
166 for(
int j=0;j<mNTDIG;j++) {
167 for(
int k=0;k<mNBinMax;k++) {
168 mTofTotEdge[i][j][k] = 0.0;
169 mTofTotCorr[i][j][k] = 0.0;
170 mTofZEdge[i][j][k] = 0.0;
171 mTofZCorr[i][j][k] = 0.0;
174 for(
int j=0;j<mNModule;j++) {
175 for(
int k=0;k<mNCell;k++) {
176 mTofTZero[i][j][k] = 0.0;
180 for(
int i=0;i<2*mNVPD;i++) {
181 for(
int j=0;j<mNBinMax;j++) {
182 mVPDTotEdge[i][j] = 0.0;
183 mVPDTotCorr[i][j] = 0.0;
194 mVPDHitPatternEast = 0;
195 mVPDHitPatternWest = 0;
199 Int_t StTofCalibMaker::Init()
209 mTofrSlewing =
new TF1(
"TofrSlewing",
"[0]+[1]/sqrt(x)+[2]/x+[3]/sqrt(x)/x+[4]/x/x");
211 mTofpSlewing =
new TF1(
"TofpSlewing",
"[0]+[1]/sqrt(x)+[2]/x+[3]/sqrt(x)/x+[4]/x/x");
214 mTofrZCorr =
new TF1(
"TofrZCorr",
"pol7");
217 mTofpZCorr =
new TF1(
"TofpZCorr",
"[0]+[1]*sqrt(x)+[2]*x+[3]*x*sqrt(x)");
218 mPVPDSlewing =
new TF1(
"pVPDSlewing",
"[0]+[1]/sqrt(x)+[2]/x+[3]*x");
222 Int_t StTofCalibMaker::InitRun(
int runnumber)
227 mTofpGeom->
init(
this);
232 mValidCalibPar = kTRUE;
234 mValidCalibPar = kFALSE;
238 gMessMgr->Info(
" ==> Good! Valid cali parameters! ",
"OS");
240 gMessMgr->Info(
" ==> No valid cali parameters! ",
"OS");
244 if(runnumber>5023000&&runnumber<5035000) {
245 mEastPVPDValid = kFALSE;
247 mEastPVPDValid = kTRUE;
257 mYear2 = (runnumber<4000000);
258 mYear3 = (runnumber>4000000&&runnumber<5000000);
259 mYear4 = (runnumber>5000000&&runnumber<6000000);
260 mYear5 = (runnumber>6000000&&runnumber<7000000);
261 mYear8 = (runnumber>9000000&&runnumber<10000000);
264 gMessMgr->Info(
"",
"OS") <<
" -- retrieving run parameters from Calibrations_tof" << endm;
265 TDataSet *mDbDataSet = GetDataBase(
"Calibrations/tof/tofTzero");
267 gMessMgr->Error(
"unable to get TOF run parameters",
"OS");
274 if(mYear2||mYear3||mYear4) {
275 gMessMgr->Info(
" loading parameters for Run II/III/IV",
"OS");
277 St_tofTzero* tofT0 =
static_cast<St_tofTzero*
>(mDbDataSet->
Find(
"tofTzero"));
279 gMessMgr->Error(
"unable to get Tzero table",
"OS");
282 tofTzero_st* t0 =
static_cast<tofTzero_st*
>(tofT0->GetArray());
283 Int_t nRows = t0[0].entries;
284 if(nRows<0||nRows>mNMax) {
285 gMessMgr->Error(
"# of Tzero out of range",
"OS");
288 for(Int_t i=0;i<nRows;i++) {
289 int daqId = t0[0].daqChannel[i];
290 int tdcChan = t0[0].tdcChan[i];
292 if(daqId<0)
continue;
294 mTofpT0[daqId] = (Double_t)(t0[0].Tzero[i]);
296 gMessMgr->Info(
"",
"OS") <<
" -TOFp- daqId=" << daqId <<
" tdcChan=" << tdcChan <<
" T0=" << mTofpT0[daqId] << endm;
299 mTofrT0[daqId] = (Double_t)(t0[0].Tzero[i]);
301 gMessMgr->Info(
"",
"OS") <<
" -TOFr- daqId=" << daqId <<
" tdcChan=" << tdcChan <<
" T0=" << mTofrT0[daqId] << endm;
307 St_tofTACorr *tofTA =
static_cast<St_tofTACorr*
>(mDbDataSet->
Find(
"tofTACorr"));
309 gMessMgr->Error(
"unable to find TA slewing parameters",
"OS");
312 tofTACorr_st *tofta =
static_cast<tofTACorr_st*
>(tofTA->GetArray());
313 for(Int_t i=0;i<mNMax;i++) {
314 int daqId = tofta[0].daqChannel[i];
315 int tdcChan = tofta[0].tdcChan[i];
317 if(daqId<0)
continue;
318 for(
int j=0;j<mNPar;j++) {
319 int ijdaq = daqId*mNPar+j;
323 gMessMgr->Warning(
"More than expected TOFp channels read in",
"OS");
325 mTofpTAPar[ijdaq] = (Double_t)(tofta[0].a[ij]);
327 gMessMgr->Info(
"",
"OS") <<
" -TOFp- daqId=" << daqId <<
" tdcChan=" << tdcChan <<
" TA Corr[" << j <<
"]=" << mTofpTAPar[ijdaq] << endm;
330 }
else if(tdcChan<48) {
332 gMessMgr->Warning(
"More than expected pVPD channels read in",
"OS");
334 mPVPDTAPar[ijdaq] = (Double_t)(tofta[0].a[ij]);
336 gMessMgr->Info(
"",
"OS") <<
" -pVPD- daqId=" << daqId <<
" tdcChan=" << tdcChan <<
" TA Corr[" << j <<
"]=" << mPVPDTAPar[ijdaq] << endm;
341 gMessMgr->Warning(
"More than expected TOFr channels read in",
"OS");
343 mTofrTAPar[ijdaq] = (Double_t)(tofta[0].a[ij]);
345 gMessMgr->Info(
"",
"OS") <<
" -TOFr- daqId=" << daqId <<
" tdcChan=" << tdcChan <<
" TA Corr[" << j <<
"]=" << mTofrTAPar[ij] << endm;
353 St_tofCorrection *
tofrZCorr =
static_cast<St_tofCorrection*
>(mDbDataSet->
Find(
"tofrZhitCorr"));
354 St_tofCorrection *
tofpZCorr =
static_cast<St_tofCorrection*
>(mDbDataSet->
Find(
"tofpZhitCorr"));
355 if(!tofrZCorr && !tofpZCorr) {
356 gMessMgr->Error(
"unable to find Zhit corr parameters",
"OS");
360 tofCorrection_st *tofrZ =
static_cast<tofCorrection_st*
>(tofrZCorr->GetArray());
361 for(
int i=0;i<mNPar;i++) {
362 mTofrZPar[i] = tofrZ[0].a[i];
364 gMessMgr->Info(
"",
"OS") <<
" -TOFr- Zcorr[" << i <<
"]=" << mTofrZPar[i] << endm;
369 tofCorrection_st *tofpZ =
static_cast<tofCorrection_st*
>(tofpZCorr->GetArray());
370 for(
int i=0;i<mNPar;i++) {
371 mTofpZPar[i] = tofpZ[0].a[i];
373 gMessMgr->Info(
"",
"OS") <<
" -TOFp- Zcorr[" << i <<
"]=" << mTofpZPar[i] << endm;
379 St_tofAdcRange *tofAdc =
static_cast<St_tofAdcRange*
>(mDbDataSet->
Find(
"tofAdcRange"));
381 gMessMgr->Warning(
"unable to find ADC range parameters, use default values!",
"OS");
383 tofAdcRange_st *
tofadc =
static_cast<tofAdcRange_st*
>(tofAdc->GetArray());
384 for(Int_t i=0;i<mNMax;i++) {
385 int daqId = tofadc[0].daqChannel[i];
386 int adcChan = tofadc[0].adcChan[i];
387 if(daqId<0)
continue;
390 gMessMgr->Warning(
"More than expected TOFp channels read in",
"OS");
392 mTofpADCMin[daqId] = tofadc[0].adcMin[i];
393 mTofpADCMax[daqId] = tofadc[0].adcMax[i];
395 gMessMgr->Info(
"",
"OS") <<
" -TOFp- daqId=" << daqId <<
" adcChan=" << adcChan <<
" min=" << mTofpADCMin[daqId] <<
" max=" << mTofpADCMax[daqId] << endm;
401 gMessMgr->Warning(
"More than expected TOFr channels read in",
"OS");
403 mTofrADCMin[daqId] = tofadc[0].adcMin[i];
404 mTofrADCMax[daqId] = tofadc[0].adcMax[i];
406 gMessMgr->Info(
"",
"OS") <<
" -TOFr- daqId=" << daqId <<
" adcChan=" << adcChan <<
" min=" << mTofrADCMin[daqId] <<
" max=" << mTofrADCMax[daqId] << endm;
413 St_tofResolution *tofRes =
static_cast<St_tofResolution*
>(mDbDataSet->
Find(
"tofResolution"));
415 gMessMgr->Warning(
"unable to find resolution parameters, nSimgaTof UNAVAILABLE!",
"OS");
417 tofResolution_st *tofres =
static_cast<tofResolution_st*
>(tofRes->GetArray());
418 for(Int_t i=0;i<mNMax;i++) {
419 int daqId = tofres[0].daqChannel[i];
420 int tdcChan = tofres[0].tdcChan[i];
421 if(daqId<0)
continue;
424 gMessMgr->Warning(
"More than expected TOFp channels read in",
"OS");
426 mTofpRes[daqId] = tofres[0].resolution[i];
428 gMessMgr->Info(
"",
"OS") <<
" -TOFp- daqId=" << daqId <<
" tdcChan=" << tdcChan <<
" resolution=" << mTofpRes[daqId] << endm;
431 }
else if(tdcChan<48) {
433 gMessMgr->Warning(
"More than expected PVPD channels read in",
"OS");
435 mPVPDRes[daqId] = tofres[0].resolution[i];
437 gMessMgr->Info(
"",
"OS") <<
" -PVPD- daqId=" << daqId <<
" tdcChan=" << tdcChan <<
" resolution=" << mPVPDRes[daqId] << endm;
442 gMessMgr->Warning(
"More than expected TOFr channels read in",
"OS");
444 mTofrRes[daqId] = tofres[0].resolution[i];
446 gMessMgr->Info(
"",
"OS") <<
" -TOFr- daqId=" << daqId <<
" tdcChan=" << tdcChan <<
" resolution=" << mTofrRes[daqId] << endm;
455 gMessMgr->Info(
" loading parameters for Run V",
"OS");
458 St_tofr5INLtable* tofr5INLtable =
static_cast<St_tofr5INLtable*
>(mDbDataSet->
Find(
"tofr5INLtable"));
460 gMessMgr->Error(
"unable to get tofr5 INL table parameters",
"OS");
464 tofr5INLtable_st* inltable =
static_cast<tofr5INLtable_st*
>(tofr5INLtable->GetArray());
465 Int_t numRows = tofr5INLtable->GetNRows();
467 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" Number of rows read in: " << numRows <<
" for INL tables" << endm;
469 const Char_t *boardName;
472 Float_t INLcorr[1024];
474 for (Int_t i=0;i<numRows;i++) {
478 for(
int j=0;j<mTdcChannel;j++) {
482 boardName = (Char_t *)(inltable[i].boardID);
483 boardId = inltable[i].boardNumber;
484 tdcId = inltable[i].TDCID;
486 gMessMgr->Info(
"",
"OS") <<
" name = " << boardName <<
" bId = " << boardId <<
" tdcId = " << tdcId << endm;
487 for(
int j=0;j<mTdcChannel;j++) {
488 INLcorr[j] = inltable[i].INLcorrection[j];
489 if(Debug()&&j%100==0) gMessMgr->Info(
"",
"OS") <<
" j=" << j <<
" inlcorr=" << INLcorr[j] << endm;
490 mINLtable[boardId][tdcId][j] = INLcorr[j];
496 St_tofTotCorr* tofTotCorr =
static_cast<St_tofTotCorr*
>(mDbDataSet->
Find(
"tofTotCorr"));
498 gMessMgr->Error(
"unable to get tofr5 TotCorr table parameters",
"OS");
502 tofTotCorr_st* totCorr =
static_cast<tofTotCorr_st*
>(tofTotCorr->GetArray());
503 numRows = tofTotCorr->GetNRows();
505 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" Number of rows read in: " << numRows <<
" for ToT correction" << endm;
507 if(numRows!=mNTOFr5+mNPVPD) {
508 gMessMgr->Warning(
"",
"OS") <<
" Mis-matched number of rows in tofTotCorr table! Return! " << endm;
513 for(Int_t i=0;i<mNTOFr5+mNPVPD;i++) {
514 short trayId = totCorr[i].trayId;
515 short moduleId = totCorr[i].moduleId;
516 short cellId = totCorr[i].cellId;
517 short tdcId = totCorr[i].tdcId;
519 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" module " << moduleId <<
" cell " << cellId <<
" tdcId " << tdcId << endm;
520 for(Int_t j=0;j<mNBinMax;j++) {
521 if(trayId==-1||trayId==-2) {
522 mPVPDTotEdge[cellId-1][j] = totCorr[i].tot[j];
523 mPVPDTotCorr[cellId-1][j] = totCorr[i].corr[j];
524 }
else if(trayId==93) {
525 mTofr5TotEdge[(moduleId-1)*6+cellId-1][j] = totCorr[i].tot[j];
526 mTofr5TotCorr[(moduleId-1)*6+cellId-1][j] = totCorr[i].corr[j];
527 if(Debug()&&j%10==0) gMessMgr->Info(
"",
"OS") <<
" j=" << j <<
" tot " << mTofr5TotEdge[(moduleId-1)*6+cellId-1][j] <<
" corr " << mTofr5TotCorr[(moduleId-1)*6+cellId-1][j] << endm;
535 St_tofZCorr* tofZCorr =
static_cast<St_tofZCorr*
>(mDbDataSet->
Find(
"tofZCorr"));
537 gMessMgr->Error(
"unable to get tofr5 ZCorr table parameters",
"OS");
541 tofZCorr_st* zCorr =
static_cast<tofZCorr_st*
>(tofZCorr->GetArray());
542 numRows = tofZCorr->GetNRows();
544 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" Number of rows read in: " << numRows <<
" for Z correction" << endm;
546 if(numRows!=mNTOFr5) {
547 gMessMgr->Warning(
"",
"OS") <<
" Mis-matched number of rows in tofZCorr table! Return! " << endm;
552 for (Int_t i=0;i<mNTOFr5;i++) {
553 short trayId = zCorr[i].trayId;
554 short moduleId = zCorr[i].moduleId;
555 short cellId = zCorr[i].cellId;
558 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" module " << moduleId <<
" cell " << cellId << endm;
559 for(Int_t j=0;j<mNBinMax;j++) {
561 mTofr5ZEdge[(moduleId-1)*6+cellId-1][j] = zCorr[i].z[j];
562 mTofr5ZCorr[(moduleId-1)*6+cellId-1][j] = zCorr[i].corr[j];
563 if(Debug()&&j%10==0) gMessMgr->Info(
"",
"OS") <<
" j=" << j <<
" z " << mTofr5ZEdge[(moduleId-1)*6+cellId-1][j] <<
" corr " << mTofr5ZCorr[(moduleId-1)*6+cellId-1][j] << endm;
573 gMessMgr->Info(
"",
"OS") <<
" loading parameters for Run VIII" << endm;
576 St_tofTotCorr* tofTotCorr =
static_cast<St_tofTotCorr*
>(mDbDataSet->
Find(
"tofTotCorr"));
578 gMessMgr->Error(
"unable to get tof TotCorr table parameters",
"OS");
582 tofTotCorr_st* totCorr =
static_cast<tofTotCorr_st*
>(tofTotCorr->GetArray());
583 Int_t numRows = tofTotCorr->GetNRows();
585 if(numRows!=mNTray8*mNTDIG+mNVPD*2) {
586 gMessMgr->Warning(
"",
"OS") <<
" Mis-matched number of rows in tofTotCorr table! " << endm;
590 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" Number of rows read in: " << numRows <<
" for ToT correction" << endm;
592 for (Int_t i=0;i<mNTray8*mNTDIG+mNVPD*2;i++) {
593 short trayId = totCorr[i].trayId;
594 short moduleId = totCorr[i].moduleId;
595 short boardId = (moduleId-1)/4+1;
596 short cellId = totCorr[i].cellId;
598 int index = (trayId-mNTray-1)*mNVPD+(cellId-1);
600 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" tray " << trayId <<
" board " << boardId <<
" cell " << cellId << endm;
601 for(Int_t j=0;j<mNBinMax;j++) {
602 if(trayId==mWestVpdTrayId||trayId==mEastVpdTrayId) {
603 mVPDTotEdge[index][j] = totCorr[i].tot[j];
604 mVPDTotCorr[index][j] = totCorr[i].corr[j];
605 }
else if(trayId>0&&trayId<=mNTray){
606 mTofTotEdge[trayId-1][boardId-1][j] = totCorr[i].tot[j];
607 mTofTotCorr[trayId-1][boardId-1][j] = totCorr[i].corr[j];
608 if(Debug()&&j%10==0) gMessMgr->Info(
"",
"OS") <<
" j=" << j <<
" tot " << mTofTotEdge[trayId-1][boardId-1][j] <<
" corr " << mTofTotCorr[trayId-1][boardId-1][j] << endm;
615 St_tofZCorr* tofZCorr =
static_cast<St_tofZCorr*
>(mDbDataSet->
Find(
"tofZCorr"));
617 gMessMgr->Error(
"unable to get tof ZCorr table parameters",
"OS");
621 tofZCorr_st* zCorr =
static_cast<tofZCorr_st*
>(tofZCorr->GetArray());
622 numRows = tofZCorr->GetNRows();
624 if(numRows!=mNTray8*mNTDIG) {
625 gMessMgr->Warning(
"",
"OS") <<
" Mis-matched number of rows in tofZCorr table! " << endm;
628 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" Number of rows read in: " << numRows <<
" for Z correction" << endm;
630 for (Int_t i=0;i<mNTray8*mNTDIG;i++) {
631 short trayId = totCorr[i].trayId;
632 short moduleId = totCorr[i].moduleId;
633 short boardId = (moduleId-1)/4+1;
634 short cellId = totCorr[i].cellId;
636 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" tray " << trayId <<
" board " << boardId <<
" cell " << cellId << endm;
637 for(Int_t j=0;j<mNBinMax;j++) {
638 if(trayId>0&&trayId<=120) {
639 mTofZEdge[trayId-1][boardId-1][j] = zCorr[i].z[j];
640 mTofZCorr[trayId-1][boardId-1][j] = zCorr[i].corr[j];
641 if(Debug()&&j%10==0) gMessMgr->Info(
"",
"OS") <<
" j=" << j <<
" tot " << mTofZEdge[trayId-1][boardId-1][j] <<
" corr " << mTofZCorr[trayId-1][boardId-1][j] << endm;
647 St_tofTOffset* tofTOffset =
static_cast<St_tofTOffset*
>(mDbDataSet->
Find(
"tofTOffset"));
649 gMessMgr->Error(
"unable to get tof TOffset table parameters",
"OS");
653 tofTOffset_st* tZero =
static_cast<tofTOffset_st*
>(tofTOffset->GetArray());
654 numRows = tofTOffset->GetNRows();
656 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" Number of rows read in: " << numRows <<
" for TOffset correction" << endm;
658 if(numRows!=mNTray8) {
659 gMessMgr->Warning(
"",
"OS") <<
" Mis-matched number of rows in tofTOffset table! " << endm;
662 for (Int_t i=0;i<mNTray8;i++) {
663 short trayId = tZero[i].trayId;
664 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" tray " << trayId << endm;
666 if(trayId>0&&trayId<=mNTray) {
667 for(
int j=0;j<mNTOF;j++) {
668 mTofTZero[trayId-1][j/6][j%6] = tZero[i].T0[j];
669 if(Debug()&&j%10==0) gMessMgr->Info(
"",
"OS") <<
" j=" << j <<
" T0 " << mTofTZero[trayId-1][j/6][j%6] << endm;
675 St_tofPhaseOffset* tofPhaseOffset =
static_cast<St_tofPhaseOffset*
>(mDbDataSet->
Find(
"tofPhaseOffset"));
676 if(!tofPhaseOffset) {
677 gMessMgr->Error(
"unable to get tof PhaseOffset table parameters",
"OS");
681 tofPhaseOffset_st* tPhaseDiff =
static_cast<tofPhaseOffset_st*
>(tofPhaseOffset->GetArray());
683 mPhaseOffset8 = tPhaseDiff[0].T0[0] + tPhaseDiff[0].T0[1];
684 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" PhaseOffset = " << mPhaseOffset8 << endm;
802 TDataSet* dbDataSet = this->GetDataBase(
"Calibrations/rhic/vertexSeed");
805 vertexSeed_st* vSeed = ((St_vertexSeed*) (dbDataSet->FindObject(
"vertexSeed")))->GetTable();
813 LOG_INFO <<
"StTofCalibMaker -- No Database for beamline" << endm;
816 LOG_INFO <<
"BeamLine Constraint: " << endm;
817 LOG_INFO <<
"x(z) = " << x0 <<
" + " << dxdz <<
" * z" << endm;
818 LOG_INFO <<
"y(z) = " << y0 <<
" + " << dydz <<
" * z" << endm;
826 double pt = 88889999;
827 double nxy=::sqrt(dxdz*dxdz + dydz*dydz);
829 LOG_WARN <<
"StTofCalibMaker:: Beam line must be tilted!" << endm;
837 if(mBeamHelix)
delete mBeamHelix;
846 Int_t StTofCalibMaker::FinishRun(
int runnumber)
849 if(mTofpGeom)
delete mTofpGeom;
852 if(mBeamHelix)
delete mBeamHelix;
868 if (mTofrSlewing)
delete mTofrSlewing;
869 if (mTofpSlewing)
delete mTofpSlewing;
870 if (mTofrZCorr)
delete mTofrZCorr;
871 if (mTofpZCorr)
delete mTofpZCorr;
872 if (mPVPDSlewing)
delete mPVPDSlewing;
878 gMessMgr->Info(
" StTofCalibMaker::Maker: starting ...",
"OS");
884 mVPDHitPatternEast = 0;
885 mVPDHitPatternWest = 0;
888 if(mYear2||mYear3||mYear4){
889 iret = processEventYear2to4();
891 iret = processEventYear5();
899 Int_t StTofCalibMaker::processEventYear2to4(){
900 mEvent = (
StEvent *) GetInputDS(
"StEvent");
903 if( !mEvent || !mEvent->primaryVertex() ||
904 !mEvent->tofCollection() ||
905 !mEvent->tofCollection()->dataPresent() ||
906 (!mEvent->tofCollection()->cellsPresent() &&
907 !mEvent->tofCollection()->slatsPresent()) ) {
908 gMessMgr->Info(
"",
"OS") <<
"StTofCalibMaker -- nothing to do ... bye-bye" << endm;
913 Double_t vz = vtx.z();
919 StSPtrVecTofData &tofData = theTof->tofData();
920 for(
int i=0;i<mNPVPD;i++) {
921 mPVPDAdc[i] = tofData[42+i]->adc();
922 mPVPDTdc[i] = tofData[42+i]->tdc();
924 mPVPDAdc[i] = tofData[54+i]->adc();
928 mValidStartTime = kTRUE;
929 Double_t T0 =
tstart(mPVPDAdc, mPVPDTdc, vz);
931 gMessMgr->Info(
" Not a good PVPD-required event!",
"OS");
932 mValidStartTime = kFALSE;
935 gMessMgr->Info(
"",
"OS") <<
" pVPD start timing T0 = " << T0 << endm;
942 StSPtrVecTofCell &tofCell = theTof->tofCells();
943 Int_t ncells = tofCell.size();
944 gMessMgr->Info(
"",
"OS") <<
" TOFr matched cells : " << ncells << endm;
945 for(
int i=0;i<ncells;i++) {
948 aHit->setTrayIndex(aCell->trayIndex());
949 aHit->setModuleIndex(aCell->moduleIndex());
950 aHit->setCellIndex(aCell->cellIndex());
951 aHit->setCellCollIndex(i);
953 int daqId = aCell->daqIndex();
954 aHit->setDaqIndex(daqId);
955 Double_t
tof = (Double_t)aCell->tdc()*mTDCWidth;
956 Double_t adc = (Double_t)aCell->adc();
957 Double_t zhit = (Double_t)aCell->zHit();
959 StTrack *thisTrack = aCell->associatedTrack();
960 aHit->setAssociatedTrack(thisTrack);
962 (mOuterGeometry)?thisTrack->outerGeometry():thisTrack->geometry();
963 Double_t L = tofPathLength(&vtx, &aCell->position(), theTrackGeometry->helix().curvature());
964 aHit->setPathLength((Float_t)L);
966 if(adc<mTofrADCMin[daqId]||adc>=mTofrADCMax[daqId]) {
970 if(mValidCalibPar&&mValidStartTime) {
971 Double_t tofcorr =
tofrAllCorr(tof, T0, adc, zhit, daqId);
972 aHit->setTimeOfFlight((Float_t)tofcorr);
974 Double_t beta = L/(tofcorr*(C_C_LIGHT/1.e9));
975 aHit->setBeta((Float_t)beta);
977 const StThreeVectorF momentum = thisTrack->geometry()->momentum();
978 Double_t ptot = momentum.mag();
979 Double_t tofe = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_ELECTRON*M_ELECTRON)/ptot;
980 Double_t tofpi = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PION_PLUS*M_PION_PLUS)/ptot;
981 Double_t tofk = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_KAON_PLUS*M_KAON_PLUS)/ptot;
982 Double_t tofp = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PROTON*M_PROTON)/ptot;
984 aHit->setTofExpectedAsElectron((Float_t)tofe);
985 aHit->setTofExpectedAsPion((Float_t)tofpi);
986 aHit->setTofExpectedAsKaon((Float_t)tofk);
987 aHit->setTofExpectedAsProton((Float_t)tofp);
990 float sigmapi = 999.;
993 float res = mTofrRes[daqId];
994 if(fabs(res)>1.e-5) {
995 sigmae = (Float_t)((tofcorr-tofe)/res);
996 sigmapi = (Float_t)((tofcorr-tofpi)/res);
997 sigmak = (Float_t)((tofcorr-tofk)/res);
998 sigmap = (Float_t)((tofcorr-tofp)/res);
1000 aHit->setSigmaElectron(sigmae);
1001 aHit->setSigmaPion(sigmapi);
1002 aHit->setSigmaKaon(sigmak);
1003 aHit->setSigmaProton(sigmap);
1006 aHit->setTimeOfFlight(9999.);
1007 aHit->setBeta(9999.);
1010 tofHit->push_back(aHit);
1016 StSPtrVecTofSlat &tofSlat = theTof->tofSlats();
1017 Int_t nslats = tofSlat.size();
1018 for(
int i=0;i<nslats;i++) {
1021 aHit->setTrayIndex(0);
1022 aHit->setModuleIndex(0);
1026 int daqId = aSlat->slatIndex()-1;
1027 int slatId = mTofpGeom->daqToSlatId(daqId);
1029 aHit->setCellIndex(slatId);
1030 aHit->setCellCollIndex(i);
1031 aHit->setDaqIndex(daqId);
1033 Double_t tof = (Double_t)aSlat->tdc()*mTDCWidth;
1034 Double_t adc = (Double_t)aSlat->adc();
1035 Double_t zhit = (Double_t)aSlat->zHit();
1037 StTrack *thisTrack = aSlat->associatedTrack();
1038 aHit->setAssociatedTrack(thisTrack);
1040 (mOuterGeometry)?thisTrack->outerGeometry():thisTrack->geometry();
1041 Double_t L = tofPathLength(&vtx, &aSlat->position(), theTrackGeometry->helix().curvature());
1042 aHit->setPathLength((Float_t)L);
1045 if(adc<mTofpADCMin[daqId]) {
1049 if(mValidCalibPar&&mValidStartTime) {
1050 Double_t tofcorr =
tofpAllCorr(tof, T0, adc, zhit, daqId);
1051 aHit->setTimeOfFlight((Float_t)tofcorr);
1053 Double_t beta = L/(tofcorr*(C_C_LIGHT/1.e9));
1054 aHit->setBeta((Float_t)beta);
1056 const StThreeVectorF momentum = thisTrack->geometry()->momentum();
1057 Double_t ptot = momentum.mag();
1058 Double_t tofe = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_ELECTRON*M_ELECTRON)/ptot;
1059 Double_t tofpi = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PION_PLUS*M_PION_PLUS)/ptot;
1060 Double_t tofk = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_KAON_PLUS*M_KAON_PLUS)/ptot;
1061 Double_t tofp = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PROTON*M_PROTON)/ptot;
1062 aHit->setTofExpectedAsElectron((Float_t)tofe);
1063 aHit->setTofExpectedAsPion((Float_t)tofpi);
1064 aHit->setTofExpectedAsKaon((Float_t)tofk);
1065 aHit->setTofExpectedAsProton((Float_t)tofp);
1067 float sigmae = 999.;
1068 float sigmapi = 999.;
1069 float sigmak = 999.;
1070 float sigmap = 999.;
1071 float res = mTofpRes[daqId];
1072 if(fabs(res)>1.e-5) {
1073 sigmae = (Float_t)((tofcorr-tofe)/res);
1074 sigmapi = (Float_t)((tofcorr-tofpi)/res);
1075 sigmak = (Float_t)((tofcorr-tofk)/res);
1076 sigmap = (Float_t)((tofcorr-tofp)/res);
1078 aHit->setSigmaElectron(sigmae);
1079 aHit->setSigmaPion(sigmapi);
1080 aHit->setSigmaKaon(sigmak);
1081 aHit->setSigmaProton(sigmap);
1084 aHit->setTimeOfFlight(9999.);
1085 aHit->setBeta(9999.);
1087 tofHit->push_back(aHit);
1092 for (
size_t j=0;j<tofHit->size();j++){
1093 theTof->addHit(tofHit->getHit(j));
1095 gMessMgr->Info(
"",
"OS") <<
"storing " << j <<
" " <<
" tray:"
1096 << tofHit->getHit(j)->trayIndex() <<
" module:"
1097 << tofHit->getHit(j)->moduleIndex() <<
" cell "
1098 << tofHit->getHit(j)->cellIndex() << endm;
1102 StSPtrVecTofHit& tofHitVec = theTof->tofHits();
1103 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1104 for (
unsigned int iNode=0; iNode<nodes.size(); iNode++){
1105 StTrack *theTrack = nodes[iNode]->track(primary);
1106 if(!theTrack)
continue;
1107 Int_t trkId = theTrack->key();
1108 for (
size_t j=0;j<tofHitVec.size();j++){
1109 StTrack *aTrack = tofHitVec[j]->associatedTrack();
1110 if(!aTrack)
continue;
1111 if(aTrack->key()!=trkId)
continue;
1112 StTofPidTraits* pidTof =
new StTofPidTraits(tofHitVec[j]->trayIndex(), tofHitVec[j]->moduleIndex(), tofHitVec[j]->cellIndex(), tofHitVec[j]->timeOfFlight(), tofHitVec[j]->pathLength(), tofHitVec[j]->beta());
1113 pidTof->setSigmaElectron(tofHitVec[j]->sigmaElectron());
1114 pidTof->setSigmaPion(tofHitVec[j]->sigmaPion());
1115 pidTof->setSigmaKaon(tofHitVec[j]->sigmaKaon());
1116 pidTof->setSigmaProton(tofHitVec[j]->sigmaProton());
1118 theTrack->addPidTraits(pidTof);
1128 Int_t StTofCalibMaker::processEventYear5(){
1130 mEvent = (
StEvent *) GetInputDS(
"StEvent");
1133 if( !mEvent || !mEvent->primaryVertex() ||
1134 !mEvent->tofCollection() ||
1135 (!mEvent->tofCollection()->dataPresent() &&
1136 !mEvent->tofCollection()->rawdataPresent()) ||
1137 (!mEvent->tofCollection()->cellsPresent()) ) {
1138 gMessMgr->Info(
"",
"OS") <<
"StTofCalibMaker -- nothing to do ... bye-bye" << endm;
1143 Double_t vz = vtx.z();
1150 IntVec validchannel = mSortTofRawData->GetValidChannel();
1152 int used[mNPVPD] = {0,0,0,0,0,0};
1153 int channum[mNPVPD] ={-1,-1,-1,-1,-1,-1};
1155 for(
unsigned int ich=0;ich<validchannel.size();ich++){
1156 int chan = validchannel[ich];
1157 if(chan<mNTOFr5)
continue;
1158 int ichan = chan - mNTOFr5;
1159 if(ichan<0||ichan>=mNPVPD)
continue;
1160 if(used[ichan]>0)
continue;
1163 int tmptdc = (mSortTofRawData->GetLeadingTdc(chan))[0];
1165 int bin = int(tmptdc)&0x03ff;
1166 float pvpdletdc = tmptdc +
GetINLcorr(4,chan,bin);
1167 mPVPDLeTime[ichan] = pvpdletdc * VHRBIN2PS/1000.;
1169 tmptdc = (mSortTofRawData->GetTrailingTdc(chan))[0];
1171 bin = int(tmptdc)&0x0ff;
1172 float pvpdtetdc = tmptdc +
GetINLcorr(5,chan,bin);
1173 float tetime = pvpdtetdc * HRBIN2PS/1000.;
1174 mPVPDTot[ichan] = tetime - mPVPDLeTime[ichan];
1175 channum[ichan]=ichan;
1180 for(
int i=0;i<mNPVPD;i++) {
1182 mPVPDLeTime[i] = 0.;
1188 for(
int i=0;i<mNPVPD;i++) {
1189 if(channum[i]!=i)
continue;
1191 for(
int j=0;j<mNPVPD;j++) {
1192 if(channum[j]!=j)
continue;
1193 float dt = mPVPDLeTime[j] - mPVPDLeTime[i];
1194 if(fabs(dt)<200.) n0++;
1197 if(n0>=nPVPDFired/2) {
1199 mPVPDLeTime[i] = 0.;
1204 mValidStartTime = kTRUE;
1205 Double_t T0 =
tstart5(mPVPDTot, mPVPDLeTime, vz);
1207 gMessMgr->Info(
" Not a good PVPD-required event!",
"OS");
1208 mValidStartTime = kFALSE;
1211 gMessMgr->Info(
"",
"OS") <<
" pVPD start timing T0 = " << T0 << endm;
1218 StSPtrVecTofCell &tofCell = theTof->tofCells();
1219 Int_t ncells = tofCell.size();
1220 gMessMgr->Info(
"",
"OS") <<
" TOFr matched cells : " << ncells << endm;
1221 for(
int i=0;i<ncells;i++) {
1224 aHit->setTrayIndex(aCell->trayIndex());
1225 aHit->setModuleIndex(aCell->moduleIndex());
1226 aHit->setCellIndex(aCell->cellIndex());
1227 aHit->setCellCollIndex(i);
1229 int daqId = aCell->daqIndex();
1230 aHit->setDaqIndex(daqId);
1234 Int_t letdc = (Int_t)aCell->tdc();
1235 int bin = int(letdc)&0x03ff;
1236 double tmptdc_f = letdc +
GetINLcorr(4, daqId, bin);
1237 double letime = tmptdc_f * VHRBIN2PS / 1000.;
1239 Int_t tetdc = (Int_t)aCell->adc();
1240 bin = int(tetdc)&0x0ff;
1241 tmptdc_f = tetdc +
GetINLcorr(5, daqId, bin);
1242 double tetime = tmptdc_f * HRBIN2PS / 1000.;
1244 double tot = tetime - letime;
1245 double tof = letime - T0;
1246 Double_t zhit = (Double_t)aCell->zHit();
1248 StTrack *thisTrack = aCell->associatedTrack();
1249 aHit->setAssociatedTrack(thisTrack);
1251 (mOuterGeometry)?thisTrack->outerGeometry():thisTrack->geometry();
1252 Double_t L = tofPathLength(&vtx, &aCell->position(), theTrackGeometry->helix().curvature());
1253 aHit->setPathLength((Float_t)L);
1255 if(fabs(tof)>200.) {
1256 gMessMgr->Info(
"",
"OS") <<
" the hit is not from this event!" << endm;
1260 if(mValidCalibPar&&mValidStartTime) {
1261 int moduleChan = (aCell->moduleIndex()-1)*6 + (aCell->cellIndex()-1);
1262 Double_t tofcorr = tofr5AllCorr(tof, tot, zhit, moduleChan);
1263 aHit->setTimeOfFlight((Float_t)tofcorr);
1265 Double_t beta = L/(tofcorr*(C_C_LIGHT/1.e9));
1266 aHit->setBeta((Float_t)beta);
1268 const StThreeVectorF momentum = thisTrack->geometry()->momentum();
1269 Double_t ptot = momentum.mag();
1270 Double_t tofe = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_ELECTRON*M_ELECTRON)/ptot;
1271 Double_t tofpi = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PION_PLUS*M_PION_PLUS)/ptot;
1272 Double_t tofk = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_KAON_PLUS*M_KAON_PLUS)/ptot;
1273 Double_t tofp = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PROTON*M_PROTON)/ptot;
1275 aHit->setTofExpectedAsElectron((Float_t)tofe);
1276 aHit->setTofExpectedAsPion((Float_t)tofpi);
1277 aHit->setTofExpectedAsKaon((Float_t)tofk);
1278 aHit->setTofExpectedAsProton((Float_t)tofp);
1280 float sigmae = 999.;
1281 float sigmapi = 999.;
1282 float sigmak = 999.;
1283 float sigmap = 999.;
1285 if(fabs(res)>1.e-5) {
1286 sigmae = (Float_t)((tofcorr-tofe)/res);
1287 sigmapi = (Float_t)((tofcorr-tofpi)/res);
1288 sigmak = (Float_t)((tofcorr-tofk)/res);
1289 sigmap = (Float_t)((tofcorr-tofp)/res);
1291 aHit->setSigmaElectron(sigmae);
1292 aHit->setSigmaPion(sigmapi);
1293 aHit->setSigmaKaon(sigmak);
1294 aHit->setSigmaProton(sigmap);
1297 aHit->setTimeOfFlight(9999.);
1298 aHit->setBeta(9999.);
1301 tofHit->push_back(aHit);
1306 for (
size_t j=0;j<tofHit->size();j++){
1307 theTof->addHit(tofHit->getHit(j));
1309 gMessMgr->Info(
"",
"OS") <<
"storing " << j <<
" " <<
" tray:"
1310 << tofHit->getHit(j)->trayIndex() <<
" module:"
1311 << tofHit->getHit(j)->moduleIndex() <<
" cell:"
1312 << tofHit->getHit(j)->cellIndex() << endm;
1316 StSPtrVecTofHit& tofHitVec = theTof->tofHits();
1317 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1318 for (
unsigned int iNode=0; iNode<nodes.size(); iNode++){
1319 StTrack *theTrack = nodes[iNode]->track(primary);
1320 if(!theTrack)
continue;
1321 Int_t trkId = theTrack->key();
1322 for (
size_t j=0;j<tofHitVec.size();j++){
1323 StTrack *aTrack = tofHitVec[j]->associatedTrack();
1324 if(!aTrack)
continue;
1325 if(aTrack->key()!=trkId)
continue;
1326 StTofPidTraits* pidTof =
new StTofPidTraits(tofHitVec[j]->trayIndex(), tofHitVec[j]->moduleIndex(), tofHitVec[j]->cellIndex(), tofHitVec[j]->timeOfFlight(), tofHitVec[j]->pathLength(), tofHitVec[j]->beta());
1327 pidTof->setSigmaElectron(tofHitVec[j]->sigmaElectron());
1328 pidTof->setSigmaPion(tofHitVec[j]->sigmaPion());
1329 pidTof->setSigmaKaon(tofHitVec[j]->sigmaKaon());
1330 pidTof->setSigmaProton(tofHitVec[j]->sigmaProton());
1332 theTrack->addPidTraits(pidTof);
1344 mEvent = (
StEvent *) GetInputDS(
"StEvent");
1348 !mEvent->tofCollection() ||
1349 (!mEvent->tofCollection()->dataPresent() &&
1350 !mEvent->tofCollection()->rawdataPresent()) ||
1351 (!mEvent->tofCollection()->cellsPresent()) ) {
1352 gMessMgr->Info(
"",
"OS") <<
"StTofCalibMaker -- nothing to do ... bye-bye" << endm;
1357 StSPtrVecTofCell &tofCell = theTof->tofCells();
1358 Int_t ncells = tofCell.size();
1359 gMessMgr->Info(
"",
"OS") <<
" TOFr matched cells + upVPD fired tubes : " << ncells << endm;
1363 float dcaRmin = 9999;
1364 for(
int i=0;i<ncells;i++) {
1367 int trayId = aCell->trayIndex();
1368 if(trayId<=0 || trayId>120)
continue;
1369 StTrack *thisTrack = aCell->associatedTrack();
1370 aHit->setAssociatedTrack(thisTrack);
1374 LOG_INFO<<
"tofPos(x,y,z)= "<<tofPos.x()<<
" "<<tofPos.y()<<
" "<<tofPos.z()<<endm;
1376 LOG_INFO<<
"dcatof(x,y)= "<<dcatof.x()<<
" "<<dcatof.y()<<endm;
1378 if(dcaRmin>dcatof.perp()) {
1379 mProjVtxZ = tofPos.z();
1380 dcaRmin = dcatof.perp();
1389 for(
int i=0;i<2*mNVPD;i++) {
1390 mVPDLeTime[i] = -999.;
1393 for(
int i=0;i<ncells;i++) {
1395 if(!aCell)
continue;
1396 int trayId = aCell->trayIndex();
1398 if(trayId!=mWestVpdTrayId && trayId!=mEastVpdTrayId)
continue;
1400 int tubeId = aCell->cellIndex();
1401 mVPDLeTime[(trayId-121)*mNVPD+(tubeId-1)] = aCell->leadingEdgeTime();
1402 mVPDTot[(trayId-121)*mNVPD+(tubeId-1)] = aCell->tot();
1412 tsum8(mVPDTot, mVPDLeTime);
1413 mTStart = tstart8(mProjVtxZ);
1415 gMessMgr->Info(
"",
"OS") <<
" NWest = " << mNWest <<
" NEast = " << mNEast <<
" TdcSum West = " << mTSumWest <<
" East = " << mTSumEast << endm;
1416 if(mTStart<-1000.) {
1417 gMessMgr->Info(
"",
"OS") <<
" mTStart not available!" << endm;
1418 mValidStartTime = kFALSE;
1420 mValidStartTime = kTRUE;
1422 gMessMgr->Info(
"",
"OS") <<
" mValidCalibPar = " << mValidCalibPar <<
" mValidStartTime = " << mValidStartTime << endm;
1425 theTof->setVpdEast(mVPDHitPatternEast);
1426 theTof->setVpdWest(mVPDHitPatternWest);
1427 theTof->setTdiff(mTDiff);
1428 theTof->setVzVpd(mVPDVtxZ);
1429 theTof->setTstart(mTStart);
1431 gMessMgr->Info(
"",
"OS") <<
" TofCollection: NWest = " << theTof->numberOfVpdWest() <<
" NEast = " << theTof->numberOfVpdEast() << endm;
1432 gMessMgr->Info(
"",
"OS") <<
"Tdiff = " << mTDiff <<
" vpd vz = " << mVPDVtxZ <<
" proj vz = " << mProjVtxZ<<endm;
1440 for(
int i=0;i<ncells;i++) {
1443 int trayId = aCell->trayIndex();
1444 if(trayId<=0 || trayId>120)
continue;
1446 aHit->setTrayIndex(aCell->trayIndex());
1447 aHit->setModuleIndex(aCell->moduleIndex());
1448 aHit->setCellIndex(aCell->cellIndex());
1449 aHit->setCellCollIndex(i);
1451 int daqId = aCell->daqIndex();
1452 aHit->setDaqIndex(daqId);
1454 StTrack *thisTrack = aCell->associatedTrack();
1455 aHit->setAssociatedTrack(thisTrack);
1461 Double_t L = tofPathLength(&tofPos, &aCell->position(), theTrackGeometry->helix().curvature());
1462 aHit->setPathLength((Float_t)L);
1465 gMessMgr->Info(
"",
"OS") <<
" p(x,y,z) = "<<theTrackGeometry->momentum().x()<<
" "<<theTrackGeometry->momentum().y()<<
" "<<theTrackGeometry->momentum().z()<<endm;
1466 gMessMgr->Info(
"",
"OS") <<
" Project Z = " << tofPos.z() <<
" mTStart = " << mTStart << endm;
1468 double tot = aCell->tot();
1469 double tdc = aCell->leadingEdgeTime();
1470 tdc -= mPhaseOffset8;
1471 while(tdc>TMAX) tdc -= TMAX;
1472 double tof = tdc - mTStart;
1473 Double_t zhit = (Double_t)aCell->zHit();
1476 if(mValidCalibPar&&mValidStartTime) {
1477 int moduleChan = (aCell->moduleIndex()-1)*6 + (aCell->cellIndex()-1);
1478 Double_t tofcorr =
tofr8AllCorr(tof, tot, zhit, trayId, moduleChan);
1479 aHit->setTimeOfFlight((Float_t)tofcorr);
1481 Double_t beta = L/(tofcorr*(C_C_LIGHT/1.e9));
1482 aHit->setBeta((Float_t)beta);
1484 const StThreeVectorF momentum = thisTrack->geometry()->momentum();
1485 Double_t ptot = momentum.mag();
1486 Double_t tofe = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_ELECTRON*M_ELECTRON)/ptot;
1487 Double_t tofpi = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PION_PLUS*M_PION_PLUS)/ptot;
1488 Double_t tofk = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_KAON_PLUS*M_KAON_PLUS)/ptot;
1489 Double_t tofp = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PROTON*M_PROTON)/ptot;
1491 aHit->setTofExpectedAsElectron((Float_t)tofe);
1492 aHit->setTofExpectedAsPion((Float_t)tofpi);
1493 aHit->setTofExpectedAsKaon((Float_t)tofk);
1494 aHit->setTofExpectedAsProton((Float_t)tofp);
1496 float sigmae = 999.;
1497 float sigmapi = 999.;
1498 float sigmak = 999.;
1499 float sigmap = 999.;
1501 if(fabs(res)>1.e-5) {
1502 sigmae = (Float_t)((tofcorr-tofe)/res);
1503 sigmapi = (Float_t)((tofcorr-tofpi)/res);
1504 sigmak = (Float_t)((tofcorr-tofk)/res);
1505 sigmap = (Float_t)((tofcorr-tofp)/res);
1507 aHit->setSigmaElectron(sigmae);
1508 aHit->setSigmaPion(sigmapi);
1509 aHit->setSigmaKaon(sigmak);
1510 aHit->setSigmaProton(sigmap);
1513 aHit->setTimeOfFlight(9999.);
1514 aHit->setBeta(9999.);
1517 tofHit->push_back(aHit);
1522 for (
size_t j=0;j<tofHit->size();j++){
1523 theTof->addHit(tofHit->getHit(j));
1525 gMessMgr->Info(
"",
"OS") <<
"storing " << j <<
" " <<
" tray:"
1526 << tofHit->getHit(j)->trayIndex() <<
" module:"
1527 << tofHit->getHit(j)->moduleIndex() <<
" cell:"
1528 << tofHit->getHit(j)->cellIndex() <<
" TOF:"
1529 << tofHit->getHit(j)->timeOfFlight() <<
" beta:"
1530 << tofHit->getHit(j)->beta() << endm;
1534 StSPtrVecTofHit& tofHitVec = theTof->tofHits();
1535 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1536 for (
unsigned int iNode=0; iNode<nodes.size(); iNode++){
1537 StTrack *theTrack = nodes[iNode]->track(primary);
1538 if(!theTrack)
continue;
1539 Int_t trkId = theTrack->key();
1540 for (
size_t j=0;j<tofHitVec.size();j++){
1541 StTrack *aTrack = tofHitVec[j]->associatedTrack();
1542 if(!aTrack)
continue;
1543 if(aTrack->key()!=trkId)
continue;
1544 StTofPidTraits* pidTof =
new StTofPidTraits(tofHitVec[j]->trayIndex(), tofHitVec[j]->moduleIndex(), tofHitVec[j]->cellIndex(), tofHitVec[j]->timeOfFlight(), tofHitVec[j]->pathLength(), tofHitVec[j]->beta());
1545 pidTof->setSigmaElectron(tofHitVec[j]->sigmaElectron());
1546 pidTof->setSigmaPion(tofHitVec[j]->sigmaPion());
1547 pidTof->setSigmaKaon(tofHitVec[j]->sigmaKaon());
1548 pidTof->setSigmaProton(tofHitVec[j]->sigmaProton());
1550 theTrack->addPidTraits(pidTof);
1562 return tof - Tstart - mTofrT0[iDaqChan];
1568 Double_t par[mNPar];
1569 for(
int i=0;i<mNPar;i++) {
1570 par[i] = mTofrTAPar[iDaqChan*mNPar+i];
1573 mTofrSlewing->SetParameters(par);
1574 return tof - mTofrSlewing->Eval(adc);
1581 mTofrZCorr->SetParameters(mTofrZPar);
1582 return tof - mTofrZCorr->Eval(zhit);
1588 gMessMgr->Info(
"",
"OS") <<
"\nStTofCalibMaker::tofrAllCorr: Tofr calibrating...\n"
1589 <<
"\tDoing Calibration in TOFr Channel " << iDaqChan
1590 <<
"\n\tinput tof = " << tof <<
" Tstart = "
1591 << T0 <<
" ADC = " << adc <<
" Zlocal = " << z
1594 Double_t tofcorr =
tofrT0Corr( tof, T0, iDaqChan );
1595 gMessMgr->Info(
"",
"OS") <<
" T0 corr: tofcorr = " << tofcorr << endm;
1597 gMessMgr->Info(
"",
"OS") <<
" Slewing corr: tofcorr2 = " << tofcorr2 << endm;
1598 Double_t tofcorr3 =
tofrZCorr( tofcorr2, z);
1599 gMessMgr->Info(
"",
"OS") <<
" Z position corr: tofcorr3 = " << tofcorr3 << endm;
1606 return tof - Tstart - mTofpT0[iDaqChan];
1612 Double_t par[mNPar];
1613 for(
int i=0;i<mNPar;i++) {
1614 par[i] = mTofpTAPar[iDaqChan*mNPar+i];
1617 mTofpSlewing->SetParameters(par);
1618 return tof - mTofpSlewing->Eval(adc);
1625 mTofpZCorr->SetParameters(mTofpZPar);
1626 return tof - mTofpZCorr->Eval(zhit);
1632 gMessMgr->Info(
"",
"OS") <<
"\nStTofCalibMaker::tofpAllCorr: Tofp calibrating...\n"
1633 <<
"\tDoing Calibration in TOFp Channel " << iDaqChan
1634 <<
"\n\tinput tof = " << tof <<
" Tstart = "
1635 << T0 <<
" ADC = " << adc <<
" Zlocal = " << z
1638 Double_t tofcorr =
tofpT0Corr( tof, T0, iDaqChan );
1639 gMessMgr->Info(
"",
"OS") <<
" T0 corr: tofcorr = " << tofcorr << endm;
1641 gMessMgr->Info(
"",
"OS") <<
" Slewing corr: tofcorr2 = " << tofcorr2 << endm;
1642 Double_t tofcorr3 =
tofpZCorr( tofcorr2, z);
1643 gMessMgr->Info(
"",
"OS") <<
" Z position corr: tofcorr3 = " << tofcorr3 << endm;
1648 Double_t StTofCalibMaker::tofr5AllCorr(
const Double_t tof,
const Double_t tot,
const Double_t z,
const Int_t iModuleChan)
1650 int module = iModuleChan/6 + 1;
1651 int cell = iModuleChan%6 + 1;
1652 gMessMgr->Info(
"",
"OS") <<
"\nStTofCalibMaker::tofr5AllCorr: Tofr5 calibrating...\n"
1653 <<
"\tDoing Calibration in TOFr5 Module " << module <<
" Cell " << cell
1654 <<
"\n\tinput tof = " << tof
1655 <<
" TOT = " << tot <<
" Zlocal = " << z
1658 Double_t tofcorr = tof;
1661 for(
int i=0;i<mNBinMax-1;i++) {
1662 if(tot>=mTofr5TotEdge[iModuleChan][i] && tot<mTofr5TotEdge[iModuleChan][i+1]) {
1667 if(iTotBin>=0&&iTotBin<mNBinMax) {
1668 tofcorr -= mTofr5TotCorr[iModuleChan][iTotBin];
1674 for(
int i=0;i<mNBinMax-1;i++) {
1675 if(z>=mTofr5ZEdge[iModuleChan][i] && z<mTofr5ZEdge[iModuleChan][i+1]) {
1680 if(iZBin>=0&&iZBin<mNBinMax) {
1681 tofcorr -= mTofr5ZCorr[iModuleChan][iZBin];
1686 gMessMgr->Info(
"",
"OS") <<
" Corrected tof: tofcorr = " << tofcorr << endm;
1694 int module = iModuleChan/6 + 1;
1695 int cell = iModuleChan%6 + 1;
1696 int board = iModuleChan/24 + 1;
1697 gMessMgr->Info(
"",
"OS") <<
"\nStTofCalibMaker::tofr8AllCorr: Tofr8 calibrating...\n"
1698 <<
"\tDoing Calibration in TOFr8 Tray " << tray <<
" Module " << module <<
" Cell " << cell
1699 <<
"\n\tinput tof = " << tof
1700 <<
" TOT = " << tot <<
" Zlocal = " << z
1703 Double_t tofcorr = tof;
1705 tofcorr -= mTofTZero[tray-1][module-1][cell-1];
1707 if(Debug()) gMessMgr->Info(
"",
"OS") <<
"T0 correction: "<<mTofTZero[tray-1][module-1][cell-1]<<endm;
1711 for(
int i=0;i<mNBinMax-1;i++) {
1712 if(tot>=mTofTotEdge[tray-1][board-1][i] && tot<mTofTotEdge[tray-1][board-1][i+1]) {
1717 if(iTotBin>=0&&iTotBin<mNBinMax) {
1718 double x1 = mTofTotEdge[tray-1][board-1][iTotBin];
1719 double x2 = mTofTotEdge[tray-1][board-1][iTotBin+1];
1720 double y1 = mTofTotCorr[tray-1][board-1][iTotBin];
1721 double y2 = mTofTotCorr[tray-1][board-1][iTotBin+1];
1722 double dcorr = y1 + (tot-x1)*(y2-y1)/(x2-x1);
1723 if(Debug()) gMessMgr->Info(
"",
"OS") <<
"TOT correction: "<<dcorr<<endm;
1727 gMessMgr->Info(
"",
"OS") <<
" TOT out of range! EXIT! " << endm;
1732 for(
int i=0;i<mNBinMax-1;i++) {
1733 if(z>=mTofZEdge[tray-1][board-1][i] && z<mTofZEdge[tray-1][board-1][i+1]) {
1738 if(iZBin>=0&&iZBin<mNBinMax) {
1739 double x1 = mTofZEdge[tray-1][board-1][iZBin];
1740 double x2 = mTofZEdge[tray-1][board-1][iZBin+1];
1741 double y1 = mTofZCorr[tray-1][board-1][iZBin];
1742 double y2 = mTofZCorr[tray-1][board-1][iZBin+1];
1744 double dcorr = y1 + (z-x1)*(y2-y1)/(x2-x1);
1747 if(Debug()) gMessMgr->Info(
"",
"OS") <<
"zHit correction: "<<dcorr<<endm;
1750 gMessMgr->Info(
"",
"OS") <<
" Z our of range! EXIT! " << endm;
1756 gMessMgr->Info(
"",
"OS") <<
" Corrected tof: tofcorr = " << tofcorr << endm;
1765 Double_t Tstart = 9999.;
1767 Int_t Ieast = 0, Iwest = 0;
1768 Double_t TdcSumEast = 0., TdcSumWest = 0.;
1770 for(
int i=0;i<3;i++) {
1771 if( validPVPDADC(adc[i]) && validPVPDTDC(tdc[i]) ) {
1773 Double_t par[mNPar];
1774 for(
int j=0;j<mNPar;j++) {
1775 par[j] = mPVPDTAPar[i*mNPar+j];
1777 mPVPDSlewing->SetParameters(par);
1778 mPVPDTdc[i] = tdc[i] - mPVPDSlewing->Eval(adc[i]-ped);
1779 TdcSumEast += mPVPDTdc[i];
1782 if( validPVPDADC(adc[i+3]) && validPVPDTDC(tdc[i+3]) ) {
1784 Double_t par[mNPar];
1785 for(
int j=0;j<mNPar;j++) {
1786 par[j] = mPVPDTAPar[(i+3)*mNPar+j];
1788 mPVPDSlewing->SetParameters(par);
1789 mPVPDTdc[i+3] = tdc[i+3] - mPVPDSlewing->Eval(adc[i+3]-ped);
1790 TdcSumWest += mPVPDTdc[i+3];
1794 Double_t TdcSum = TdcSumEast + TdcSumWest;
1798 if ( (Ieast>=mPVPDEastHitsCut || !mEastPVPDValid) && Iwest>=mPVPDWestHitsCut ) {
1799 Tstart = (TdcSum*mTDCWidth-(Ieast-Iwest)*vz/(C_C_LIGHT/1.e9))/(Ieast+Iwest);
1809 Double_t Tstart = -999999.;
1811 Int_t Ieast = 0, Iwest = 0;
1812 Double_t TSumEast = 0., TSumWest = 0.;
1813 for(
int i=0;i<3;i++) {
1814 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" East pVPD tot = " << tot[i] <<
" time = " << time[i] << endm;
1815 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" West pVPD tot = " << tot[i+3] <<
" time = " << time[i+3] << endm;
1819 for(
int j=0;j<mNBinMax-1;j++) {
1820 if(tot[i]>=mPVPDTotEdge[i][j] && tot[i]<mPVPDTotEdge[i][j+1]) {
1825 if(ibin>=0&&ibin<mNBinMax) {
1827 mPVPDLeTime[i] = time[i] - mPVPDTotCorr[i][ibin];
1828 TSumEast += mPVPDLeTime[i];
1832 if( time[i+3]>0. ) {
1834 for(
int j=0;j<mNBinMax-1;j++) {
1835 if(tot[i+3]>=mPVPDTotEdge[i+3][j] && tot[i+3]<mPVPDTotEdge[i+3][j+1]) {
1840 if(ibin>=0&&ibin<mNBinMax) {
1842 mPVPDLeTime[i+3] = time[i+3] - mPVPDTotCorr[i+3][ibin];
1843 TSumWest += mPVPDLeTime[i+3];
1848 Double_t TSum = TSumEast + TSumWest;
1850 if ( Ieast>=mPVPDEastHitsCut && Iwest>=mPVPDWestHitsCut ) {
1851 Tstart = (TSum-(Ieast-Iwest)*vz/(C_C_LIGHT/1.e9))/(Ieast+Iwest);
1865 mVPDHitPatternWest = 0;
1866 mVPDHitPatternEast = 0;
1869 for(
int i=0;i<mNVPD;i++) {
1870 if( time[i]>0. && tot[i]>0. ) {
1874 for(
int j=0;j<mNBinMax-1;j++) {
1875 if(tot[i]>=mVPDTotEdge[i][j] && tot[i]<mVPDTotEdge[i][j+1]) {
1880 if(ibin>=0&&ibin<mNBinMax) {
1883 double x1 = mVPDTotEdge[i][ibin];
1884 double x2 = mVPDTotEdge[i][ibin+1];
1885 double y1 = mVPDTotCorr[i][ibin];
1886 double y2 = mVPDTotCorr[i][ibin+1];
1887 double dcorr = y1 + (tot[i]-x1)*(y2-y1)/(x2-x1);
1889 mVPDLeTime[i] = time[i] - dcorr;
1890 mTSumWest += mVPDLeTime[i];
1892 mVPDHitPatternWest |= 1<<i;
1895 gMessMgr->Info(
"",
"OS") <<
" Vpd West tube " << i+1 <<
" TOT out of range!" << endm;
1901 if( time[i+mNVPD]>0. && tot[i+mNVPD]>0. ) {
1902 double tmp = time[i+mNVPD] - mPhaseOffset8;
1903 while(tmp>TMAX) tmp -= TMAX;
1906 for(
int j=0;j<mNBinMax-1;j++) {
1907 if(tot[i+mNVPD]>=mVPDTotEdge[i+mNVPD][j] && tot[i+mNVPD]<mVPDTotEdge[i+mNVPD][j+1]) {
1912 if(ibin>=0&&ibin<mNBinMax) {
1915 double x1 = mVPDTotEdge[i+mNVPD][ibin];
1916 double x2 = mVPDTotEdge[i+mNVPD][ibin+1];
1917 double y1 = mVPDTotCorr[i+mNVPD][ibin];
1918 double y2 = mVPDTotCorr[i+mNVPD][ibin+1];
1919 double dcorr = y1 + (tot[i+mNVPD]-x1)*(y2-y1)/(x2-x1);
1921 mVPDLeTime[i+mNVPD] = tmp - dcorr;
1922 mTSumEast += mVPDLeTime[i+mNVPD];
1924 mVPDHitPatternEast |= 1<<i;
1928 gMessMgr->Info(
"",
"OS") <<
" Vpd East tube " << i+1 <<
" TOT out of range!" << endm;
1934 if ( mNEast>=mPVPDEastHitsCut && mNWest>=mPVPDWestHitsCut ) {
1935 mTDiff = (mTSumEast/mNEast - mTSumWest/mNWest)/2. - mProjVtxZ/(C_C_LIGHT/1.e9);
1936 mVPDVtxZ = (mTSumEast/mNEast - mTSumWest/mNWest)/2.*(C_C_LIGHT/1.e9);
1942 Double_t StTofCalibMaker::tstart8(
const Double_t vz)
1944 Double_t Tstart = -9999.;
1946 Double_t TSum = mTSumEast + mTSumWest;
1948 if ( mNEast>=mPVPDEastHitsCut && mNWest>=mPVPDWestHitsCut ) {
1949 Tstart = (TSum-(mNEast-mNWest)*vz/(C_C_LIGHT/1.e9))/(mNEast+mNWest);
1958 int iboard=tdcchan/24;
1959 int chan = (tdcchan%24);
1961 if(edgeflag==4) itdc = chan/8;
1962 if(edgeflag==5) itdc = 3;
1963 if(tdcchan==192&&edgeflag==4) itdc=0;
1964 if(tdcchan==193&&edgeflag==4) itdc=1;
1965 if(tdcchan==194&&edgeflag==4) itdc=1;
1966 if(tdcchan==195&&edgeflag==4) itdc=0;
1967 if(tdcchan==196&&edgeflag==4) itdc=1;
1968 if(tdcchan==197&&edgeflag==4) itdc=1;
1970 return mINLtable[iboard][itdc][bin];
Double_t tofpSlewingCorr(const Double_t tof, const Double_t adc, const Int_t iDaqChan)
tofp TA slewing correction function
Int_t processEventYear8()
void resetPars()
Reset the calibration parameters.
Int_t initParameters(int)
Initialize the calibration parameters from dbase.
void setOuterGeometry(const bool)
switch to select the Helix Geometry
pair< double, double > pathLengths(const StHelix &, double minStepSize=10 *micrometer, double minRange=10 *centimeter) const
path lengths at dca between two helices
Double_t tofrAllCorr(const Double_t tof, const Double_t Tstart, const Double_t adc, const Double_t zlocal, const Int_t iDaqChan)
tofr overall correction function
Double_t GetINLcorr(const int edgeid, const int tempchan, const int bin)
Run 5 ->
Double_t tstart(const Double_t *adc, const Double_t *tdc, const Double_t Vz)
Start timing calculation function.
void tsum8(const Double_t *tot, const Double_t *time)
Run 8 ->
void initFormulas()
Initialize the formulas of calibration functions.
Double_t tofrSlewingCorr(const Double_t tof, const Double_t adc, const Int_t iDaqChan)
tofr TA slewing correction function
StTofCalibMaker(const char *name="tofCalib")
Default constructor.
Time-of-Flight Geometry Utilities.
Double_t tofpZCorr(const Double_t tof, const Double_t zlocal)
tofp loca Zhit correction function
Double_t tofpT0Corr(const Double_t tof, const Double_t Tstart, const Int_t iDaqChan)
tofp T0 calibration function
void clearFormulars()
Delete the calibration functions.
Double_t tofrZCorr(const Double_t tof, const Double_t zlocal)
tofr local Zhit correction function
Double_t tstart5(const Double_t *tot, const Double_t *time, const Double_t Vz)
~StTofCalibMaker()
Destructor.
Double_t tofrT0Corr(const Double_t tof, const Double_t Tstart, const Int_t iDaqChan)
tofr T0 calibration function
Double_t tofr8AllCorr(const Double_t tof, const Double_t tot, const Double_t zlocal, const Int_t iTray, const Int_t iModuleChan)
tstart calculation splitted into 2 steps in Run 8 since no primary vertex in the event ...
Double_t tofpAllCorr(const Double_t tof, const Double_t Tstart, const Double_t adc, const Double_t zlocal, const Int_t iDaqChan)
tofp overall correction function
virtual TDataSet * Find(const char *path) const
void init()
initialize geometry class from XDF file and set-up DAQ/Slat mappings