00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 #include <iostream>
00088 #include "TFile.h"
00089 #include "TProfile.h"
00090 #include "TNtuple.h"
00091 #include "TH1.h"
00092 #include "TH2.h"
00093 #include "TF1.h"
00094
00095 #include "StEvent.h"
00096 #include "StTofHit.h"
00097 #include "StTofCell.h"
00098 #include "StTofSlat.h"
00099 #include "StTofData.h"
00100 #include "StTofPidTraits.h"
00101 #include "StEventTypes.h"
00102 #include "Stypes.h"
00103 #include "StMessMgr.h"
00104 #include "StThreeVectorD.hh"
00105 #include "StHelix.hh"
00106 #include "StTrackGeometry.h"
00107 #include "StEventUtilities/StuRefMult.hh"
00108 #include "PhysicalConstants.h"
00109 #include "phys_constants.h"
00110 #include "StPhysicalHelixD.hh"
00111 #include "tables/St_tofTzero_Table.h"
00112 #include "tables/St_tofTACorr_Table.h"
00113 #include "tables/St_tofCorrection_Table.h"
00114 #include "tables/St_tofAdcRange_Table.h"
00115 #include "tables/St_tofResolution_Table.h"
00116
00117 #include "tables/St_tofr5INLtable_Table.h"
00118 #include "tables/St_tofTotCorr_Table.h"
00119 #include "tables/St_tofZCorr_Table.h"
00120
00121 #include "tables/St_vertexSeed_Table.h"
00122
00123 #include "tables/St_tofTOffset_Table.h"
00124 #include "tables/St_tofPhaseOffset_Table.h"
00125
00126 #include "StTofUtil/tofPathLength.hh"
00127 #include "StTofUtil/StTofDataCollection.h"
00128 #include "StTofUtil/StTofSlatCollection.h"
00129 #include "StTofUtil/StTofCellCollection.h"
00130 #include "StTofUtil/StTofHitCollection.h"
00131 #include "StTofUtil/StTofGeometry.h"
00132 #include "StTofCalibMaker.h"
00133
00134 #include "StMessMgr.h"
00135 #include "StMemoryInfo.hh"
00136 #include "StTimer.hh"
00137
00138 #ifdef __ROOT__
00139 ClassImp(StTofCalibMaker)
00140 #endif
00141
00142
00143 StTofCalibMaker::StTofCalibMaker(const char *name) : StMaker(name)
00144 {
00148 setTDCLimits(20, 1500);
00149 setADCCut(300);
00150 setTDCWidth(0.05);
00151
00152 setPVPDADCLimits(30,1100);
00153 setPVPDTDCLimits(1,2000);
00154 setPVPDHitsCut(1,1);
00155 setOuterGeometry(true);
00156
00157 mValidStartTime = kTRUE;
00158 mEastPVPDValid = kTRUE;
00159 mSlewingCorr = kTRUE;
00160
00161 StThreeVectorD MomFstPt(0.,0.,9999.);
00162 StThreeVectorD origin(0.,0.,0.);
00163 mBeamHelix = new StPhysicalHelixD(MomFstPt,origin,0.5*tesla,1.);
00164
00165 resetPars();
00166 }
00167
00168
00169 StTofCalibMaker::~StTofCalibMaker()
00170 {
00171 resetPars();
00172 }
00173
00174
00175 void StTofCalibMaker::resetPars()
00176 {
00177 for(int i=0;i<mNPar;i++) {
00178 mTofrZPar[i] = 0.;
00179 mTofpZPar[i] = 0.;
00180 }
00181 for(int i=0;i<mNTOFr;i++) {
00182 mTofrT0[i] = 0.;
00183 }
00184 for(int i=0;i<mNTOFr*mNPar;i++) {
00185 mTofrTAPar[i] = 0.0;
00186 }
00187 for(int i=0;i<mNTOFp;i++) {
00188 mTofpT0[i] = 0.;
00189 }
00190 for(int i=0;i<mNTOFp*mNPar;i++) {
00191 mTofpTAPar[i] = 0.0;
00192 }
00193 for(int i=0;i<mNPVPD*mNPar;i++) {
00194 mPVPDTAPar[i] = 0.0;
00195 }
00196
00197 mValidCalibPar = kFALSE;
00198
00200 for(int i=0;i<mNTOFr;i++) {
00201 mTofrADCMin[i] = 0.;
00202 mTofrADCMax[i] = 1024.;
00203 mTofrRes[i] = 999.;
00204 }
00205 for(int i=0;i<mNTOFp;i++) {
00206 mTofpADCMin[i] = 0.;
00207 mTofpADCMax[i] = 1024.;
00208 mTofpRes[i] = 999.;
00209 }
00210 for(int i=0;i<mNPVPD;i++) {
00211 mPVPDRes[i] = 999.;
00212 }
00213
00214
00215 for(int i=0;i<mTdigBoard;i++) {
00216 for(int j=0;j<mTdcOnBoard;j++) {
00217 for(int k=0;k<mTdcChannel;k++) {
00218 mINLtable[i][j][k] = 0.0;
00219 }
00220 }
00221 }
00222
00223 for(int i=0;i<mNTOFr5;i++) {
00224 for(int j=0;j<mNBinMax;j++) {
00225 mTofr5TotEdge[i][j] = 0.0;
00226 mTofr5TotCorr[i][j] = 0.0;
00227 mTofr5ZEdge[i][j] = 0.0;
00228 mTofr5ZCorr[i][j] = 0.0;
00229 }
00230 }
00231
00232 for(int i=0;i<mNPVPD;i++) {
00233 for(int j=0;j<mNBinMax;j++) {
00234 mPVPDTotEdge[i][j] = 0.0;
00235 mPVPDTotCorr[i][j] = 0.0;
00236 }
00237 }
00238
00239
00240 for(int i=0;i<mNTray;i++) {
00241 for(int j=0;j<mNTDIG;j++) {
00242 for(int k=0;k<mNBinMax;k++) {
00243 mTofTotEdge[i][j][k] = 0.0;
00244 mTofTotCorr[i][j][k] = 0.0;
00245 mTofZEdge[i][j][k] = 0.0;
00246 mTofZCorr[i][j][k] = 0.0;
00247 }
00248 }
00249 for(int j=0;j<mNModule;j++) {
00250 for(int k=0;k<mNCell;k++) {
00251 mTofTZero[i][j][k] = 0.0;
00252 }
00253 }
00254 }
00255 for(int i=0;i<2*mNVPD;i++) {
00256 for(int j=0;j<mNBinMax;j++) {
00257 mVPDTotEdge[i][j] = 0.0;
00258 mVPDTotCorr[i][j] = 0.0;
00259 }
00260 mVPDTZero[i] = 0.0;
00261 mVPDLeTime[i] = 0.0;
00262 mVPDTot[i] = 0.0;
00263 }
00264
00265 mTStart = -9999.;
00266 mTDiff = -9999.;
00267 mVPDVtxZ = -9999.;
00268 mProjVtxZ = -9999.;
00269 mVPDHitPatternEast = 0;
00270 mVPDHitPatternWest = 0;
00271 }
00272
00273
00274 Int_t StTofCalibMaker::Init()
00275 {
00276 initFormulas();
00277 return kStOK;
00278 }
00279
00280
00281 void StTofCalibMaker::initFormulas()
00282 {
00284 mTofrSlewing = new TF1("TofrSlewing", "[0]+[1]/sqrt(x)+[2]/x+[3]/sqrt(x)/x+[4]/x/x");
00285
00286 mTofpSlewing = new TF1("TofpSlewing", "[0]+[1]/sqrt(x)+[2]/x+[3]/sqrt(x)/x+[4]/x/x");
00287
00288
00289 mTofrZCorr = new TF1("TofrZCorr", "pol7");
00290
00291
00292 mTofpZCorr = new TF1("TofpZCorr", "[0]+[1]*sqrt(x)+[2]*x+[3]*x*sqrt(x)");
00293 mPVPDSlewing = new TF1("pVPDSlewing","[0]+[1]/sqrt(x)+[2]/x+[3]*x");
00294 }
00295
00296
00297 Int_t StTofCalibMaker::InitRun(int runnumber)
00298 {
00299
00300
00301 mTofpGeom = new StTofGeometry();
00302 mTofpGeom->init(this);
00303
00304 Int_t val = kStOK;
00305 val = initParameters(runnumber);
00306 if(val==kStOK) {
00307 mValidCalibPar = kTRUE;
00308 } else {
00309 mValidCalibPar = kFALSE;
00310 }
00311
00312 if(mValidCalibPar) {
00313 gMessMgr->Info(" ==> Good! Valid cali parameters! ","OS");
00314 } else {
00315 gMessMgr->Info(" ==> No valid cali parameters! ","OS");
00316 }
00317
00318
00319 if(runnumber>5023000&&runnumber<5035000) {
00320 mEastPVPDValid = kFALSE;
00321 } else {
00322 mEastPVPDValid = kTRUE;
00323 }
00324
00325 return kStOK;
00326
00327 }
00328
00329
00330 Int_t StTofCalibMaker::initParameters(int runnumber)
00331 {
00332 mYear2 = (runnumber<4000000);
00333 mYear3 = (runnumber>4000000&&runnumber<5000000);
00334 mYear4 = (runnumber>5000000&&runnumber<6000000);
00335 mYear5 = (runnumber>6000000&&runnumber<7000000);
00336 mYear8 = (runnumber>9000000&&runnumber<10000000);
00339 gMessMgr->Info("","OS") << " -- retrieving run parameters from Calibrations_tof" << endm;
00340 TDataSet *mDbDataSet = GetDataBase("Calibrations/tof");
00341 if (!mDbDataSet){
00342 gMessMgr->Error("unable to get TOF run parameters","OS");
00343 return kStErr;
00344 }
00345
00349 if(mYear2||mYear3||mYear4) {
00350 gMessMgr->Info(" loading parameters for Run II/III/IV", "OS");
00351
00352 St_tofTzero* tofT0 = static_cast<St_tofTzero*>(mDbDataSet->Find("tofTzero"));
00353 if(!tofT0) {
00354 gMessMgr->Error("unable to get Tzero table","OS");
00355 return kStErr;
00356 } else {
00357 tofTzero_st* t0 = static_cast<tofTzero_st*>(tofT0->GetArray());
00358 Int_t nRows = t0[0].entries;
00359 if(nRows<0||nRows>mNMax) {
00360 gMessMgr->Error("# of Tzero out of range","OS");
00361 return kStErr;
00362 }
00363 for(Int_t i=0;i<nRows;i++) {
00364 int daqId = t0[0].daqChannel[i];
00365 int tdcChan = t0[0].tdcChan[i];
00366
00367 if(daqId<0) continue;
00368 if(tdcChan<42) {
00369 mTofpT0[daqId] = (Double_t)(t0[0].Tzero[i]);
00370 if(Debug()) {
00371 gMessMgr->Info("","OS") << " -TOFp- daqId=" << daqId << " tdcChan=" << tdcChan << " T0=" << mTofpT0[daqId] << endm;
00372 }
00373 } else {
00374 mTofrT0[daqId] = (Double_t)(t0[0].Tzero[i]);
00375 if(Debug()) {
00376 gMessMgr->Info("","OS") << " -TOFr- daqId=" << daqId << " tdcChan=" << tdcChan << " T0=" << mTofrT0[daqId] << endm;
00377 }
00378 }
00379 }
00380 }
00381
00382 St_tofTACorr *tofTA = static_cast<St_tofTACorr*>(mDbDataSet->Find("tofTACorr"));
00383 if(!tofTA) {
00384 gMessMgr->Error("unable to find TA slewing parameters","OS");
00385 return kStErr;
00386 }
00387 tofTACorr_st *tofta = static_cast<tofTACorr_st*>(tofTA->GetArray());
00388 for(Int_t i=0;i<mNMax;i++) {
00389 int daqId = tofta[0].daqChannel[i];
00390 int tdcChan = tofta[0].tdcChan[i];
00391
00392 if(daqId<0) continue;
00393 for(int j=0;j<mNPar;j++) {
00394 int ijdaq = daqId*mNPar+j;
00395 int ij = i*mNPar+j;
00396 if(tdcChan<42) {
00397 if(daqId>=mNTOFp) {
00398 gMessMgr->Warning("More than expected TOFp channels read in","OS");
00399 } else {
00400 mTofpTAPar[ijdaq] = (Double_t)(tofta[0].a[ij]);
00401 if(Debug()) {
00402 gMessMgr->Info("","OS") << " -TOFp- daqId=" << daqId << " tdcChan=" << tdcChan << " TA Corr[" << j << "]=" << mTofpTAPar[ijdaq] << endm;
00403 }
00404 }
00405 } else if(tdcChan<48) {
00406 if(daqId>=mNPVPD) {
00407 gMessMgr->Warning("More than expected pVPD channels read in","OS");
00408 } else {
00409 mPVPDTAPar[ijdaq] = (Double_t)(tofta[0].a[ij]);
00410 if(Debug()) {
00411 gMessMgr->Info("","OS") << " -pVPD- daqId=" << daqId << " tdcChan=" << tdcChan << " TA Corr[" << j << "]=" << mPVPDTAPar[ijdaq] << endm;
00412 }
00413 }
00414 } else {
00415 if(daqId>=mNTOFr) {
00416 gMessMgr->Warning("More than expected TOFr channels read in","OS");
00417 } else {
00418 mTofrTAPar[ijdaq] = (Double_t)(tofta[0].a[ij]);
00419 if(Debug()) {
00420 gMessMgr->Info("","OS") << " -TOFr- daqId=" << daqId << " tdcChan=" << tdcChan << " TA Corr[" << j << "]=" << mTofrTAPar[ij] << endm;
00421 }
00422 }
00423 }
00424 }
00425 }
00426
00427
00428 St_tofCorrection *tofrZCorr = static_cast<St_tofCorrection*>(mDbDataSet->Find("tofrZhitCorr"));
00429 St_tofCorrection *tofpZCorr = static_cast<St_tofCorrection*>(mDbDataSet->Find("tofpZhitCorr"));
00430 if(!tofrZCorr && !tofpZCorr) {
00431 gMessMgr->Error("unable to find Zhit corr parameters","OS");
00432 return kStErr;
00433 }
00434 if(tofrZCorr) {
00435 tofCorrection_st *tofrZ = static_cast<tofCorrection_st*>(tofrZCorr->GetArray());
00436 for(int i=0;i<mNPar;i++) {
00437 mTofrZPar[i] = tofrZ[0].a[i];
00438 if(Debug()) {
00439 gMessMgr->Info("","OS") << " -TOFr- Zcorr[" << i << "]=" << mTofrZPar[i] << endm;
00440 }
00441 }
00442 }
00443 if(tofpZCorr) {
00444 tofCorrection_st *tofpZ = static_cast<tofCorrection_st*>(tofpZCorr->GetArray());
00445 for(int i=0;i<mNPar;i++) {
00446 mTofpZPar[i] = tofpZ[0].a[i];
00447 if(Debug()) {
00448 gMessMgr->Info("","OS") << " -TOFp- Zcorr[" << i << "]=" << mTofpZPar[i] << endm;
00449 }
00450 }
00451 }
00452
00453
00454 St_tofAdcRange *tofAdc = static_cast<St_tofAdcRange*>(mDbDataSet->Find("tofAdcRange"));
00455 if(!tofAdc) {
00456 gMessMgr->Warning("unable to find ADC range parameters, use default values!","OS");
00457 }
00458 tofAdcRange_st *tofadc = static_cast<tofAdcRange_st*>(tofAdc->GetArray());
00459 for(Int_t i=0;i<mNMax;i++) {
00460 int daqId = tofadc[0].daqChannel[i];
00461 int adcChan = tofadc[0].adcChan[i];
00462 if(daqId<0) continue;
00463 if(adcChan<42) {
00464 if(daqId>=mNTOFp) {
00465 gMessMgr->Warning("More than expected TOFp channels read in","OS");
00466 } else {
00467 mTofpADCMin[daqId] = tofadc[0].adcMin[i];
00468 mTofpADCMax[daqId] = tofadc[0].adcMax[i];
00469 if(Debug()) {
00470 gMessMgr->Info("","OS") << " -TOFp- daqId=" << daqId << " adcChan=" << adcChan << " min=" << mTofpADCMin[daqId] << " max=" << mTofpADCMax[daqId] << endm;
00471 }
00472 }
00473 }
00474 if(adcChan>=60) {
00475 if(daqId>=mNTOFr) {
00476 gMessMgr->Warning("More than expected TOFr channels read in","OS");
00477 } else {
00478 mTofrADCMin[daqId] = tofadc[0].adcMin[i];
00479 mTofrADCMax[daqId] = tofadc[0].adcMax[i];
00480 if(Debug()) {
00481 gMessMgr->Info("","OS") << " -TOFr- daqId=" << daqId << " adcChan=" << adcChan << " min=" << mTofrADCMin[daqId] << " max=" << mTofrADCMax[daqId] << endm;
00482 }
00483 }
00484 }
00485 }
00486
00487
00488 St_tofResolution *tofRes = static_cast<St_tofResolution*>(mDbDataSet->Find("tofResolution"));
00489 if(!tofRes) {
00490 gMessMgr->Warning("unable to find resolution parameters, nSimgaTof UNAVAILABLE!","OS");
00491 }
00492 tofResolution_st *tofres = static_cast<tofResolution_st*>(tofRes->GetArray());
00493 for(Int_t i=0;i<mNMax;i++) {
00494 int daqId = tofres[0].daqChannel[i];
00495 int tdcChan = tofres[0].tdcChan[i];
00496 if(daqId<0) continue;
00497 if(tdcChan<42) {
00498 if(daqId>=mNTOFp) {
00499 gMessMgr->Warning("More than expected TOFp channels read in","OS");
00500 } else {
00501 mTofpRes[daqId] = tofres[0].resolution[i];
00502 if(Debug()) {
00503 gMessMgr->Info("","OS") << " -TOFp- daqId=" << daqId << " tdcChan=" << tdcChan << " resolution=" << mTofpRes[daqId] << endm;
00504 }
00505 }
00506 } else if(tdcChan<48) {
00507 if(daqId>=mNPVPD) {
00508 gMessMgr->Warning("More than expected PVPD channels read in","OS");
00509 } else {
00510 mPVPDRes[daqId] = tofres[0].resolution[i];
00511 if(Debug()) {
00512 gMessMgr->Info("","OS") << " -PVPD- daqId=" << daqId << " tdcChan=" << tdcChan << " resolution=" << mPVPDRes[daqId] << endm;
00513 }
00514 }
00515 } else {
00516 if(daqId>=mNTOFr) {
00517 gMessMgr->Warning("More than expected TOFr channels read in","OS");
00518 } else {
00519 mTofrRes[daqId] = tofres[0].resolution[i];
00520 if(Debug()) {
00521 gMessMgr->Info("","OS") << " -TOFr- daqId=" << daqId << " tdcChan=" << tdcChan << " resolution=" << mTofrRes[daqId] << endm;
00522 }
00523 }
00524 }
00525 }
00529 } else if(mYear5) {
00530 gMessMgr->Info(" loading parameters for Run V","OS");
00531
00532
00533 St_tofr5INLtable* tofr5INLtable = static_cast<St_tofr5INLtable*>(mDbDataSet->Find("tofr5INLtable"));
00534 if(!tofr5INLtable) {
00535 gMessMgr->Error("unable to get tofr5 INL table parameters","OS");
00536
00537 return kStErr;
00538 }
00539 tofr5INLtable_st* inltable = static_cast<tofr5INLtable_st*>(tofr5INLtable->GetArray());
00540 Int_t numRows = tofr5INLtable->GetNRows();
00541
00542 if(Debug()) gMessMgr->Info("","OS") << " Number of rows read in: " << numRows << " for INL tables" << endm;
00543
00544 Char_t *boardName;
00545 Short_t boardId;
00546 Short_t tdcId;
00547 Float_t INLcorr[1024];
00548
00549 for (Int_t i=0;i<numRows;i++) {
00550 boardName = "";
00551 boardId = -1;
00552 tdcId = -1;
00553 for(int j=0;j<mTdcChannel;j++) {
00554 INLcorr[j] = 0.0;
00555 }
00556
00557 boardName = (Char_t *)(inltable[i].boardID);
00558 boardId = inltable[i].boardNumber;
00559 tdcId = inltable[i].TDCID;
00560 if(Debug())
00561 gMessMgr->Info("","OS") << " name = " << boardName << " bId = " << boardId << " tdcId = " << tdcId << endm;
00562 for(int j=0;j<mTdcChannel;j++) {
00563 INLcorr[j] = inltable[i].INLcorrection[j];
00564 if(Debug()&&j%100==0) gMessMgr->Info("","OS") << " j=" << j << " inlcorr=" << INLcorr[j] << endm;
00565 mINLtable[boardId][tdcId][j] = INLcorr[j];
00566 }
00567
00568 }
00569
00570
00571 St_tofTotCorr* tofTotCorr = static_cast<St_tofTotCorr*>(mDbDataSet->Find("tofTotCorr"));
00572 if(!tofTotCorr) {
00573 gMessMgr->Error("unable to get tofr5 TotCorr table parameters","OS");
00574
00575 return kStErr;
00576 }
00577 tofTotCorr_st* totCorr = static_cast<tofTotCorr_st*>(tofTotCorr->GetArray());
00578 numRows = tofTotCorr->GetNRows();
00579
00580 if(Debug()) gMessMgr->Info("","OS") << " Number of rows read in: " << numRows << " for ToT correction" << endm;
00581
00582 if(numRows!=mNTOFr5+mNPVPD) {
00583 gMessMgr->Warning("","OS") << " Mis-matched number of rows in tofTotCorr table! Return! " << endm;
00584
00585 }
00586
00587
00588 for(Int_t i=0;i<mNTOFr5+mNPVPD;i++) {
00589 short trayId = totCorr[i].trayId;
00590 short moduleId = totCorr[i].moduleId;
00591 short cellId = totCorr[i].cellId;
00592 short tdcId = totCorr[i].tdcId;
00593
00594 if(Debug()) gMessMgr->Info("","OS") << " module " << moduleId << " cell " << cellId << " tdcId " << tdcId << endm;
00595 for(Int_t j=0;j<mNBinMax;j++) {
00596 if(trayId==-1||trayId==-2) {
00597 mPVPDTotEdge[cellId-1][j] = totCorr[i].tot[j];
00598 mPVPDTotCorr[cellId-1][j] = totCorr[i].corr[j];
00599 } else if(trayId==93) {
00600 mTofr5TotEdge[(moduleId-1)*6+cellId-1][j] = totCorr[i].tot[j];
00601 mTofr5TotCorr[(moduleId-1)*6+cellId-1][j] = totCorr[i].corr[j];
00602 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;
00603 } else {
00604 }
00605 }
00606 }
00607
00608
00609
00610 St_tofZCorr* tofZCorr = static_cast<St_tofZCorr*>(mDbDataSet->Find("tofZCorr"));
00611 if(!tofZCorr) {
00612 gMessMgr->Error("unable to get tofr5 ZCorr table parameters","OS");
00613
00614 return kStErr;
00615 }
00616 tofZCorr_st* zCorr = static_cast<tofZCorr_st*>(tofZCorr->GetArray());
00617 numRows = tofZCorr->GetNRows();
00618
00619 if(Debug()) gMessMgr->Info("","OS") << " Number of rows read in: " << numRows << " for Z correction" << endm;
00620
00621 if(numRows!=mNTOFr5) {
00622 gMessMgr->Warning("","OS") << " Mis-matched number of rows in tofZCorr table! Return! " << endm;
00623
00624 }
00625
00626
00627 for (Int_t i=0;i<mNTOFr5;i++) {
00628 short trayId = zCorr[i].trayId;
00629 short moduleId = zCorr[i].moduleId;
00630 short cellId = zCorr[i].cellId;
00631
00632
00633 if(Debug()) gMessMgr->Info("","OS") << " module " << moduleId << " cell " << cellId << endm;
00634 for(Int_t j=0;j<mNBinMax;j++) {
00635 if(trayId==93) {
00636 mTofr5ZEdge[(moduleId-1)*6+cellId-1][j] = zCorr[i].z[j];
00637 mTofr5ZCorr[(moduleId-1)*6+cellId-1][j] = zCorr[i].corr[j];
00638 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;
00639 } else {
00640 }
00641 }
00642 }
00643
00647 } else if(mYear8) {
00648 gMessMgr->Info("","OS") << " loading parameters for Run VIII" << endm;
00649
00650
00651 St_tofTotCorr* tofTotCorr = static_cast<St_tofTotCorr*>(mDbDataSet->Find("tofTotCorr"));
00652 if(!tofTotCorr) {
00653 gMessMgr->Error("unable to get tof TotCorr table parameters","OS");
00654
00655 return kStErr;
00656 }
00657 tofTotCorr_st* totCorr = static_cast<tofTotCorr_st*>(tofTotCorr->GetArray());
00658 Int_t numRows = tofTotCorr->GetNRows();
00659
00660 if(numRows!=mNTray8*mNTDIG+mNVPD*2) {
00661 gMessMgr->Warning("","OS") << " Mis-matched number of rows in tofTotCorr table! " << endm;
00662
00663 }
00664
00665 if(Debug()) gMessMgr->Info("","OS") << " Number of rows read in: " << numRows << " for ToT correction" << endm;
00666
00667 for (Int_t i=0;i<mNTray8*mNTDIG+mNVPD*2;i++) {
00668 short trayId = totCorr[i].trayId;
00669 short moduleId = totCorr[i].moduleId;
00670 short boardId = (moduleId-1)/4+1;
00671 short cellId = totCorr[i].cellId;
00672
00673 int index = (trayId-mNTray-1)*mNVPD+(cellId-1);
00674
00675 if(Debug()) gMessMgr->Info("","OS") << " tray " << trayId << " board " << boardId << " cell " << cellId << endm;
00676 for(Int_t j=0;j<mNBinMax;j++) {
00677 if(trayId==mWestVpdTrayId||trayId==mEastVpdTrayId) {
00678 mVPDTotEdge[index][j] = totCorr[i].tot[j];
00679 mVPDTotCorr[index][j] = totCorr[i].corr[j];
00680 } else if(trayId>0&&trayId<=mNTray){
00681 mTofTotEdge[trayId-1][boardId-1][j] = totCorr[i].tot[j];
00682 mTofTotCorr[trayId-1][boardId-1][j] = totCorr[i].corr[j];
00683 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;
00684 }
00685 }
00686 }
00687
00688
00689
00690 St_tofZCorr* tofZCorr = static_cast<St_tofZCorr*>(mDbDataSet->Find("tofZCorr"));
00691 if(!tofZCorr) {
00692 gMessMgr->Error("unable to get tof ZCorr table parameters","OS");
00693
00694 return kStErr;
00695 }
00696 tofZCorr_st* zCorr = static_cast<tofZCorr_st*>(tofZCorr->GetArray());
00697 numRows = tofZCorr->GetNRows();
00698
00699 if(numRows!=mNTray8*mNTDIG) {
00700 gMessMgr->Warning("","OS") << " Mis-matched number of rows in tofZCorr table! " << endm;
00701
00702 }
00703 if(Debug()) gMessMgr->Info("","OS") << " Number of rows read in: " << numRows << " for Z correction" << endm;
00704
00705 for (Int_t i=0;i<mNTray8*mNTDIG;i++) {
00706 short trayId = totCorr[i].trayId;
00707 short moduleId = totCorr[i].moduleId;
00708 short boardId = (moduleId-1)/4+1;
00709 short cellId = totCorr[i].cellId;
00710
00711 if(Debug()) gMessMgr->Info("","OS") << " tray " << trayId << " board " << boardId << " cell " << cellId << endm;
00712 for(Int_t j=0;j<mNBinMax;j++) {
00713 if(trayId>0&&trayId<=120) {
00714 mTofZEdge[trayId-1][boardId-1][j] = zCorr[i].z[j];
00715 mTofZCorr[trayId-1][boardId-1][j] = zCorr[i].corr[j];
00716 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;
00717 }
00718 }
00719 }
00720
00721
00722 St_tofTOffset* tofTOffset = static_cast<St_tofTOffset*>(mDbDataSet->Find("tofTOffset"));
00723 if(!tofTOffset) {
00724 gMessMgr->Error("unable to get tof TOffset table parameters","OS");
00725
00726 return kStErr;
00727 }
00728 tofTOffset_st* tZero = static_cast<tofTOffset_st*>(tofTOffset->GetArray());
00729 numRows = tofTOffset->GetNRows();
00730
00731 if(Debug()) gMessMgr->Info("","OS") << " Number of rows read in: " << numRows << " for TOffset correction" << endm;
00732
00733 if(numRows!=mNTray8) {
00734 gMessMgr->Warning("","OS") << " Mis-matched number of rows in tofTOffset table! " << endm;
00735
00736 }
00737 for (Int_t i=0;i<mNTray8;i++) {
00738 short trayId = tZero[i].trayId;
00739 if(Debug()) gMessMgr->Info("","OS") << " tray " << trayId << endm;
00740
00741 if(trayId>0&&trayId<=mNTray) {
00742 for(int j=0;j<mNTOF;j++) {
00743 mTofTZero[trayId-1][j/6][j%6] = tZero[i].T0[j];
00744 if(Debug()&&j%10==0) gMessMgr->Info("","OS") << " j=" << j << " T0 " << mTofTZero[trayId-1][j/6][j%6] << endm;
00745 }
00746 }
00747 }
00748
00749
00750 St_tofPhaseOffset* tofPhaseOffset = static_cast<St_tofPhaseOffset*>(mDbDataSet->Find("tofPhaseOffset"));
00751 if(!tofPhaseOffset) {
00752 gMessMgr->Error("unable to get tof PhaseOffset table parameters","OS");
00753
00754 return kStErr;
00755 }
00756 tofPhaseOffset_st* tPhaseDiff = static_cast<tofPhaseOffset_st*>(tofPhaseOffset->GetArray());
00757
00758 mPhaseOffset8 = tPhaseDiff[0].T0[0] + tPhaseDiff[0].T0[1];
00759 if(Debug()) gMessMgr->Info("","OS") << " PhaseOffset = " << mPhaseOffset8 << endm;
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871 double x0 = 0.;
00872 double y0 = 0.;
00873 double dxdz = 0.;
00874 double dydz = 0.;
00875
00876
00877 TDataSet* dbDataSet = this->GetDataBase("Calibrations/rhic");
00878
00879 if (dbDataSet) {
00880 vertexSeed_st* vSeed = ((St_vertexSeed*) (dbDataSet->FindObject("vertexSeed")))->GetTable();
00881
00882 x0 = vSeed->x0;
00883 y0 = vSeed->y0;
00884 dxdz = vSeed->dxdz;
00885 dydz = vSeed->dydz;
00886 }
00887 else {
00888 LOG_INFO << "StTofCalibMaker -- No Database for beamline" << endm;
00889 }
00890
00891 LOG_INFO << "BeamLine Constraint: " << endm;
00892 LOG_INFO << "x(z) = " << x0 << " + " << dxdz << " * z" << endm;
00893 LOG_INFO << "y(z) = " << y0 << " + " << dydz << " * z" << endm;
00894
00895
00896
00897
00898
00899
00900 StThreeVectorD origin(x0,y0,0.0);
00901 double pt = 88889999;
00902 double nxy=::sqrt(dxdz*dxdz + dydz*dydz);
00903 if(nxy<1.e-5){
00904 LOG_WARN << "StTofCalibMaker:: Beam line must be tilted!" << endm;
00905 nxy=dxdz=1.e-5;
00906 }
00907 double p0=pt/nxy;
00908 double px = p0*dxdz;
00909 double py = p0*dydz;
00910 double pz = p0;
00911 StThreeVectorD MomFstPt(px*GeV, py*GeV, pz*GeV);
00912 if(mBeamHelix) delete mBeamHelix;
00913 mBeamHelix = new StPhysicalHelixD(MomFstPt,origin,0.5*tesla,1.);
00914
00915 }
00916
00917 return kStOK;
00918 }
00919
00920
00921 Int_t StTofCalibMaker::FinishRun(int runnumber)
00922 {
00923
00924 if(mTofpGeom) delete mTofpGeom;
00925 mTofpGeom = 0;
00926
00927 if(mBeamHelix) delete mBeamHelix;
00928 mBeamHelix = 0;
00929
00930 return kStOK;
00931 }
00932
00933
00934 Int_t StTofCalibMaker::Finish()
00935 {
00936 clearFormulars();
00937 return kStOK;
00938 }
00939
00940
00941 void StTofCalibMaker::clearFormulars()
00942 {
00943 if (mTofrSlewing) delete mTofrSlewing;
00944 if (mTofpSlewing) delete mTofpSlewing;
00945 if (mTofrZCorr) delete mTofrZCorr;
00946 if (mTofpZCorr) delete mTofpZCorr;
00947 if (mPVPDSlewing) delete mPVPDSlewing;
00948 }
00949
00950
00951 Int_t StTofCalibMaker::Make()
00952 {
00953 gMessMgr->Info(" StTofCalibMaker::Maker: starting ...","OS");
00954
00955 mTStart = -9999.;
00956 mTDiff = -9999.;
00957 mVPDVtxZ = -9999.;
00958 mProjVtxZ = -9999.;
00959 mVPDHitPatternEast = 0;
00960 mVPDHitPatternWest = 0;
00961
00962 Int_t iret = kStOK;
00963 if(mYear2||mYear3||mYear4){
00964 iret = processEventYear2to4();
00965 } else if(mYear5) {
00966 iret = processEventYear5();
00967 } else if(mYear8) {
00968 iret = processEventYear8();
00969 }
00970 return kStOK;
00971 }
00972
00973
00974 Int_t StTofCalibMaker::processEventYear2to4(){
00975 mEvent = (StEvent *) GetInputDS("StEvent");
00976
00977
00978 if( !mEvent || !mEvent->primaryVertex() ||
00979 !mEvent->tofCollection() ||
00980 !mEvent->tofCollection()->dataPresent() ||
00981 (!mEvent->tofCollection()->cellsPresent() &&
00982 !mEvent->tofCollection()->slatsPresent()) ) {
00983 gMessMgr->Info("","OS") << "StTofCalibMaker -- nothing to do ... bye-bye" << endm;
00984 return kStOK;
00985 }
00986
00987 StThreeVectorD vtx = mEvent->primaryVertex()->position();
00988 Double_t vz = vtx.z();
00989
00990
00991
00992
00993 StTofCollection *theTof = mEvent->tofCollection();
00994 StSPtrVecTofData &tofData = theTof->tofData();
00995 for(int i=0;i<mNPVPD;i++) {
00996 mPVPDAdc[i] = tofData[42+i]->adc();
00997 mPVPDTdc[i] = tofData[42+i]->tdc();
00998 if(mYear3||mYear4) {
00999 mPVPDAdc[i] = tofData[54+i]->adc();
01000 }
01001 }
01002
01003 mValidStartTime = kTRUE;
01004 Double_t T0 = tstart(mPVPDAdc, mPVPDTdc, vz);
01005 if(T0>1000.) {
01006 gMessMgr->Info(" Not a good PVPD-required event!","OS");
01007 mValidStartTime = kFALSE;
01008
01009 }
01010 gMessMgr->Info("","OS") << " pVPD start timing T0 = " << T0 << endm;
01011
01012 StTofHitCollection *tofHit = new StTofHitCollection();
01013
01014
01015
01016
01017 StSPtrVecTofCell &tofCell = theTof->tofCells();
01018 Int_t ncells = tofCell.size();
01019 gMessMgr->Info("","OS") << " TOFr matched cells : " << ncells << endm;
01020 for(int i=0;i<ncells;i++) {
01021 StTofHit *aHit = new StTofHit;
01022 StTofCell *aCell = dynamic_cast<StTofCell*>(tofCell[i]);
01023 aHit->setTrayIndex(aCell->trayIndex());
01024 aHit->setModuleIndex(aCell->moduleIndex());
01025 aHit->setCellIndex(aCell->cellIndex());
01026 aHit->setCellCollIndex(i);
01027
01028 int daqId = aCell->daqIndex();
01029 aHit->setDaqIndex(daqId);
01030 Double_t tof = (Double_t)aCell->tdc()*mTDCWidth;
01031 Double_t adc = (Double_t)aCell->adc();
01032 Double_t zhit = (Double_t)aCell->zHit();
01033
01034 StTrack *thisTrack = aCell->associatedTrack();
01035 aHit->setAssociatedTrack(thisTrack);
01036 StTrackGeometry *theTrackGeometry =
01037 (mOuterGeometry)?thisTrack->outerGeometry():thisTrack->geometry();
01038 Double_t L = tofPathLength(&vtx, &aCell->position(), theTrackGeometry->helix().curvature());
01039 aHit->setPathLength((Float_t)L);
01040
01041 if(adc<mTofrADCMin[daqId]||adc>=mTofrADCMax[daqId]) {
01042 delete aHit;
01043 continue;
01044 }
01045 if(mValidCalibPar&&mValidStartTime) {
01046 Double_t tofcorr = tofrAllCorr(tof, T0, adc, zhit, daqId);
01047 aHit->setTimeOfFlight((Float_t)tofcorr);
01048
01049 Double_t beta = L/(tofcorr*(C_C_LIGHT/1.e9));
01050 aHit->setBeta((Float_t)beta);
01051
01052 const StThreeVectorF momentum = thisTrack->geometry()->momentum();
01053 Double_t ptot = momentum.mag();
01054 Double_t tofe = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_ELECTRON*M_ELECTRON)/ptot;
01055 Double_t tofpi = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PION_PLUS*M_PION_PLUS)/ptot;
01056 Double_t tofk = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_KAON_PLUS*M_KAON_PLUS)/ptot;
01057 Double_t tofp = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PROTON*M_PROTON)/ptot;
01058
01059 aHit->setTofExpectedAsElectron((Float_t)tofe);
01060 aHit->setTofExpectedAsPion((Float_t)tofpi);
01061 aHit->setTofExpectedAsKaon((Float_t)tofk);
01062 aHit->setTofExpectedAsProton((Float_t)tofp);
01063
01064 float sigmae = 999.;
01065 float sigmapi = 999.;
01066 float sigmak = 999.;
01067 float sigmap = 999.;
01068 float res = mTofrRes[daqId];
01069 if(fabs(res)>1.e-5) {
01070 sigmae = (Float_t)((tofcorr-tofe)/res);
01071 sigmapi = (Float_t)((tofcorr-tofpi)/res);
01072 sigmak = (Float_t)((tofcorr-tofk)/res);
01073 sigmap = (Float_t)((tofcorr-tofp)/res);
01074 }
01075 aHit->setSigmaElectron(sigmae);
01076 aHit->setSigmaPion(sigmapi);
01077 aHit->setSigmaKaon(sigmak);
01078 aHit->setSigmaProton(sigmap);
01079
01080 } else {
01081 aHit->setTimeOfFlight(9999.);
01082 aHit->setBeta(9999.);
01083 }
01084
01085 tofHit->push_back(aHit);
01086 }
01087
01088
01089
01090
01091 StSPtrVecTofSlat &tofSlat = theTof->tofSlats();
01092 Int_t nslats = tofSlat.size();
01093 for(int i=0;i<nslats;i++) {
01094 StTofHit *aHit = new StTofHit;
01095 StTofSlat *aSlat = tofSlat[i];
01096 aHit->setTrayIndex(0);
01097 aHit->setModuleIndex(0);
01098
01099
01100
01101 int daqId = aSlat->slatIndex()-1;
01102 int slatId = mTofpGeom->daqToSlatId(daqId);
01103
01104 aHit->setCellIndex(slatId);
01105 aHit->setCellCollIndex(i);
01106 aHit->setDaqIndex(daqId);
01107
01108 Double_t tof = (Double_t)aSlat->tdc()*mTDCWidth;
01109 Double_t adc = (Double_t)aSlat->adc();
01110 Double_t zhit = (Double_t)aSlat->zHit();
01111
01112 StTrack *thisTrack = aSlat->associatedTrack();
01113 aHit->setAssociatedTrack(thisTrack);
01114 StTrackGeometry *theTrackGeometry =
01115 (mOuterGeometry)?thisTrack->outerGeometry():thisTrack->geometry();
01116 Double_t L = tofPathLength(&vtx, &aSlat->position(), theTrackGeometry->helix().curvature());
01117 aHit->setPathLength((Float_t)L);
01118
01119
01120 if(adc<mTofpADCMin[daqId]) {
01121 delete aHit;
01122 continue;
01123 }
01124 if(mValidCalibPar&&mValidStartTime) {
01125 Double_t tofcorr = tofpAllCorr(tof, T0, adc, zhit, daqId);
01126 aHit->setTimeOfFlight((Float_t)tofcorr);
01127
01128 Double_t beta = L/(tofcorr*(C_C_LIGHT/1.e9));
01129 aHit->setBeta((Float_t)beta);
01130
01131 const StThreeVectorF momentum = thisTrack->geometry()->momentum();
01132 Double_t ptot = momentum.mag();
01133 Double_t tofe = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_ELECTRON*M_ELECTRON)/ptot;
01134 Double_t tofpi = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PION_PLUS*M_PION_PLUS)/ptot;
01135 Double_t tofk = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_KAON_PLUS*M_KAON_PLUS)/ptot;
01136 Double_t tofp = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PROTON*M_PROTON)/ptot;
01137 aHit->setTofExpectedAsElectron((Float_t)tofe);
01138 aHit->setTofExpectedAsPion((Float_t)tofpi);
01139 aHit->setTofExpectedAsKaon((Float_t)tofk);
01140 aHit->setTofExpectedAsProton((Float_t)tofp);
01141
01142 float sigmae = 999.;
01143 float sigmapi = 999.;
01144 float sigmak = 999.;
01145 float sigmap = 999.;
01146 float res = mTofpRes[daqId];
01147 if(fabs(res)>1.e-5) {
01148 sigmae = (Float_t)((tofcorr-tofe)/res);
01149 sigmapi = (Float_t)((tofcorr-tofpi)/res);
01150 sigmak = (Float_t)((tofcorr-tofk)/res);
01151 sigmap = (Float_t)((tofcorr-tofp)/res);
01152 }
01153 aHit->setSigmaElectron(sigmae);
01154 aHit->setSigmaPion(sigmapi);
01155 aHit->setSigmaKaon(sigmak);
01156 aHit->setSigmaProton(sigmap);
01157
01158 } else {
01159 aHit->setTimeOfFlight(9999.);
01160 aHit->setBeta(9999.);
01161 }
01162 tofHit->push_back(aHit);
01163 }
01164
01165
01166
01167 for (size_t j=0;j<tofHit->size();j++){
01168 theTof->addHit(tofHit->getHit(j));
01169 if (Debug())
01170 gMessMgr->Info("","OS") << "storing " << j << " " << " tray:"
01171 << tofHit->getHit(j)->trayIndex() << " module:"
01172 << tofHit->getHit(j)->moduleIndex() << " cell "
01173 << tofHit->getHit(j)->cellIndex() << endm;
01174 }
01175
01176
01177 StSPtrVecTofHit& tofHitVec = theTof->tofHits();
01178 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
01179 for (unsigned int iNode=0; iNode<nodes.size(); iNode++){
01180 StTrack *theTrack = nodes[iNode]->track(primary);
01181 if(!theTrack) continue;
01182 Int_t trkId = theTrack->key();
01183 for (size_t j=0;j<tofHitVec.size();j++){
01184 StTrack *aTrack = tofHitVec[j]->associatedTrack();
01185 if(!aTrack) continue;
01186 if(aTrack->key()!=trkId) continue;
01187 StTofPidTraits* pidTof = new StTofPidTraits(tofHitVec[j]->trayIndex(), tofHitVec[j]->moduleIndex(), tofHitVec[j]->cellIndex(), tofHitVec[j]->timeOfFlight(), tofHitVec[j]->pathLength(), tofHitVec[j]->beta());
01188 pidTof->setSigmaElectron(tofHitVec[j]->sigmaElectron());
01189 pidTof->setSigmaPion(tofHitVec[j]->sigmaPion());
01190 pidTof->setSigmaKaon(tofHitVec[j]->sigmaKaon());
01191 pidTof->setSigmaProton(tofHitVec[j]->sigmaProton());
01192
01193 theTrack->addPidTraits(pidTof);
01194 }
01195 }
01196
01197 delete tofHit;
01198
01199 return kStOK;
01200 }
01201
01202
01203 Int_t StTofCalibMaker::processEventYear5(){
01204
01205 mEvent = (StEvent *) GetInputDS("StEvent");
01206
01207
01208 if( !mEvent || !mEvent->primaryVertex() ||
01209 !mEvent->tofCollection() ||
01210 (!mEvent->tofCollection()->dataPresent() &&
01211 !mEvent->tofCollection()->rawdataPresent()) ||
01212 (!mEvent->tofCollection()->cellsPresent()) ) {
01213 gMessMgr->Info("","OS") << "StTofCalibMaker -- nothing to do ... bye-bye" << endm;
01214 return kStOK;
01215 }
01216
01217 StThreeVectorD vtx = mEvent->primaryVertex()->position();
01218 Double_t vz = vtx.z();
01219
01220
01221
01222
01223 StTofCollection *theTof = mEvent->tofCollection();
01224 mSortTofRawData = new StSortTofRawData(theTof);
01225 IntVec validchannel = mSortTofRawData->GetValidChannel();
01226
01227 int used[mNPVPD] = {0,0,0,0,0,0};
01228 int channum[mNPVPD] ={-1,-1,-1,-1,-1,-1};
01229
01230 for(unsigned int ich=0;ich<validchannel.size();ich++){
01231 int chan = validchannel[ich];
01232 if(chan<mNTOFr5) continue;
01233 int ichan = chan - mNTOFr5;
01234 if(ichan<0||ichan>=mNPVPD) continue;
01235 if(used[ichan]>0) continue;
01236 used[ichan]++;
01237
01238 int tmptdc = (mSortTofRawData->GetLeadingTdc(chan))[0];
01239
01240 int bin = int(tmptdc)&0x03ff;
01241 float pvpdletdc = tmptdc + GetINLcorr(4,chan,bin);
01242 mPVPDLeTime[ichan] = pvpdletdc * VHRBIN2PS/1000.;
01243
01244 tmptdc = (mSortTofRawData->GetTrailingTdc(chan))[0];
01245
01246 bin = int(tmptdc)&0x0ff;
01247 float pvpdtetdc = tmptdc + GetINLcorr(5,chan,bin);
01248 float tetime = pvpdtetdc * HRBIN2PS/1000.;
01249 mPVPDTot[ichan] = tetime - mPVPDLeTime[ichan];
01250 channum[ichan]=ichan;
01251 }
01252
01253
01254 int nPVPDFired = 0;
01255 for(int i=0;i<mNPVPD;i++) {
01256 if(channum[i]!=i) {
01257 mPVPDLeTime[i] = 0.;
01258 mPVPDTot[i] = 0.;
01259 } else {
01260 nPVPDFired++;
01261 }
01262 }
01263 for(int i=0;i<mNPVPD;i++) {
01264 if(channum[i]!=i) continue;
01265 int n0 = 0;
01266 for(int j=0;j<mNPVPD;j++) {
01267 if(channum[j]!=j) continue;
01268 float dt = mPVPDLeTime[j] - mPVPDLeTime[i];
01269 if(fabs(dt)<200.) n0++;
01270 }
01271
01272 if(n0>=nPVPDFired/2) {
01273 } else {
01274 mPVPDLeTime[i] = 0.;
01275 mPVPDTot[i] = 0.;
01276 }
01277 }
01278
01279 mValidStartTime = kTRUE;
01280 Double_t T0 = tstart5(mPVPDTot, mPVPDLeTime, vz);
01281 if(T0<0.) {
01282 gMessMgr->Info(" Not a good PVPD-required event!","OS");
01283 mValidStartTime = kFALSE;
01284
01285 }
01286 gMessMgr->Info("","OS") << " pVPD start timing T0 = " << T0 << endm;
01287
01288 StTofHitCollection *tofHit = new StTofHitCollection();
01289
01290
01291
01292
01293 StSPtrVecTofCell &tofCell = theTof->tofCells();
01294 Int_t ncells = tofCell.size();
01295 gMessMgr->Info("","OS") << " TOFr matched cells : " << ncells << endm;
01296 for(int i=0;i<ncells;i++) {
01297 StTofHit *aHit = new StTofHit;
01298 StTofCell *aCell = dynamic_cast<StTofCell*>(tofCell[i]);
01299 aHit->setTrayIndex(aCell->trayIndex());
01300 aHit->setModuleIndex(aCell->moduleIndex());
01301 aHit->setCellIndex(aCell->cellIndex());
01302 aHit->setCellCollIndex(i);
01303
01304 int daqId = aCell->daqIndex();
01305 aHit->setDaqIndex(daqId);
01306
01307
01308
01309 Int_t letdc = (Int_t)aCell->tdc();
01310 int bin = int(letdc)&0x03ff;
01311 double tmptdc_f = letdc + GetINLcorr(4, daqId, bin);
01312 double letime = tmptdc_f * VHRBIN2PS / 1000.;
01313
01314 Int_t tetdc = (Int_t)aCell->adc();
01315 bin = int(tetdc)&0x0ff;
01316 tmptdc_f = tetdc + GetINLcorr(5, daqId, bin);
01317 double tetime = tmptdc_f * HRBIN2PS / 1000.;
01318
01319 double tot = tetime - letime;
01320 double tof = letime - T0;
01321 Double_t zhit = (Double_t)aCell->zHit();
01322
01323 StTrack *thisTrack = aCell->associatedTrack();
01324 aHit->setAssociatedTrack(thisTrack);
01325 StTrackGeometry *theTrackGeometry =
01326 (mOuterGeometry)?thisTrack->outerGeometry():thisTrack->geometry();
01327 Double_t L = tofPathLength(&vtx, &aCell->position(), theTrackGeometry->helix().curvature());
01328 aHit->setPathLength((Float_t)L);
01329
01330 if(fabs(tof)>200.) {
01331 gMessMgr->Info("","OS") << " the hit is not from this event!" << endm;
01332 delete aHit;
01333 continue;
01334 }
01335 if(mValidCalibPar&&mValidStartTime) {
01336 int moduleChan = (aCell->moduleIndex()-1)*6 + (aCell->cellIndex()-1);
01337 Double_t tofcorr = tofr5AllCorr(tof, tot, zhit, moduleChan);
01338 aHit->setTimeOfFlight((Float_t)tofcorr);
01339
01340 Double_t beta = L/(tofcorr*(C_C_LIGHT/1.e9));
01341 aHit->setBeta((Float_t)beta);
01342
01343 const StThreeVectorF momentum = thisTrack->geometry()->momentum();
01344 Double_t ptot = momentum.mag();
01345 Double_t tofe = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_ELECTRON*M_ELECTRON)/ptot;
01346 Double_t tofpi = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PION_PLUS*M_PION_PLUS)/ptot;
01347 Double_t tofk = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_KAON_PLUS*M_KAON_PLUS)/ptot;
01348 Double_t tofp = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PROTON*M_PROTON)/ptot;
01349
01350 aHit->setTofExpectedAsElectron((Float_t)tofe);
01351 aHit->setTofExpectedAsPion((Float_t)tofpi);
01352 aHit->setTofExpectedAsKaon((Float_t)tofk);
01353 aHit->setTofExpectedAsProton((Float_t)tofp);
01354
01355 float sigmae = 999.;
01356 float sigmapi = 999.;
01357 float sigmak = 999.;
01358 float sigmap = 999.;
01359 float res = 0.095;
01360 if(fabs(res)>1.e-5) {
01361 sigmae = (Float_t)((tofcorr-tofe)/res);
01362 sigmapi = (Float_t)((tofcorr-tofpi)/res);
01363 sigmak = (Float_t)((tofcorr-tofk)/res);
01364 sigmap = (Float_t)((tofcorr-tofp)/res);
01365 }
01366 aHit->setSigmaElectron(sigmae);
01367 aHit->setSigmaPion(sigmapi);
01368 aHit->setSigmaKaon(sigmak);
01369 aHit->setSigmaProton(sigmap);
01370
01371 } else {
01372 aHit->setTimeOfFlight(9999.);
01373 aHit->setBeta(9999.);
01374 }
01375
01376 tofHit->push_back(aHit);
01377 }
01378
01379
01380
01381 for (size_t j=0;j<tofHit->size();j++){
01382 theTof->addHit(tofHit->getHit(j));
01383 if (Debug())
01384 gMessMgr->Info("","OS") << "storing " << j << " " << " tray:"
01385 << tofHit->getHit(j)->trayIndex() << " module:"
01386 << tofHit->getHit(j)->moduleIndex() << " cell:"
01387 << tofHit->getHit(j)->cellIndex() << endm;
01388 }
01389
01390
01391 StSPtrVecTofHit& tofHitVec = theTof->tofHits();
01392 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
01393 for (unsigned int iNode=0; iNode<nodes.size(); iNode++){
01394 StTrack *theTrack = nodes[iNode]->track(primary);
01395 if(!theTrack) continue;
01396 Int_t trkId = theTrack->key();
01397 for (size_t j=0;j<tofHitVec.size();j++){
01398 StTrack *aTrack = tofHitVec[j]->associatedTrack();
01399 if(!aTrack) continue;
01400 if(aTrack->key()!=trkId) continue;
01401 StTofPidTraits* pidTof = new StTofPidTraits(tofHitVec[j]->trayIndex(), tofHitVec[j]->moduleIndex(), tofHitVec[j]->cellIndex(), tofHitVec[j]->timeOfFlight(), tofHitVec[j]->pathLength(), tofHitVec[j]->beta());
01402 pidTof->setSigmaElectron(tofHitVec[j]->sigmaElectron());
01403 pidTof->setSigmaPion(tofHitVec[j]->sigmaPion());
01404 pidTof->setSigmaKaon(tofHitVec[j]->sigmaKaon());
01405 pidTof->setSigmaProton(tofHitVec[j]->sigmaProton());
01406
01407 theTrack->addPidTraits(pidTof);
01408 }
01409 }
01410
01411 delete tofHit;
01412
01413 return kStOK;
01414 }
01415
01416
01417 Int_t StTofCalibMaker::processEventYear8(){
01418
01419 mEvent = (StEvent *) GetInputDS("StEvent");
01420
01421
01422 if( !mEvent ||
01423 !mEvent->tofCollection() ||
01424 (!mEvent->tofCollection()->dataPresent() &&
01425 !mEvent->tofCollection()->rawdataPresent()) ||
01426 (!mEvent->tofCollection()->cellsPresent()) ) {
01427 gMessMgr->Info("","OS") << "StTofCalibMaker -- nothing to do ... bye-bye" << endm;
01428 return kStOK;
01429 }
01430
01431 StTofCollection *theTof = mEvent->tofCollection();
01432 StSPtrVecTofCell &tofCell = theTof->tofCells();
01433 Int_t ncells = tofCell.size();
01434 gMessMgr->Info("","OS") << " TOFr matched cells + upVPD fired tubes : " << ncells << endm;
01435
01436
01437
01438 float dcaRmin = 9999;
01439 for(int i=0;i<ncells;i++) {
01440 StTofHit *aHit = new StTofHit;
01441 StTofCell *aCell = dynamic_cast<StTofCell*>(tofCell[i]);
01442 int trayId = aCell->trayIndex();
01443 if(trayId<=0 || trayId>120) continue;
01444 StTrack *thisTrack = aCell->associatedTrack();
01445 aHit->setAssociatedTrack(thisTrack);
01446 StTrackGeometry *theTrackGeometry = thisTrack->geometry();
01447
01448 StThreeVectorD tofPos = theTrackGeometry->helix().at(theTrackGeometry->helix().pathLengths(*mBeamHelix).first);
01449 LOG_INFO<<"tofPos(x,y,z)= "<<tofPos.x()<<" "<<tofPos.y()<<" "<<tofPos.z()<<endm;
01450 StThreeVectorD dcatof = tofPos - mBeamHelix->at(theTrackGeometry->helix().pathLengths(*mBeamHelix).second);
01451 LOG_INFO<<"dcatof(x,y)= "<<dcatof.x()<<" "<<dcatof.y()<<endm;
01452
01453 if(dcaRmin>dcatof.perp()) {
01454 mProjVtxZ = tofPos.z();
01455 dcaRmin = dcatof.perp();
01456 }
01457 delete aHit;
01458 }
01459
01460
01461
01462
01463
01464 for(int i=0;i<2*mNVPD;i++) {
01465 mVPDLeTime[i] = -999.;
01466 mVPDTot[i] = -999.;
01467 }
01468 for(int i=0;i<ncells;i++) {
01469 StTofCell *aCell = dynamic_cast<StTofCell*>(tofCell[i]);
01470 if(!aCell) continue;
01471 int trayId = aCell->trayIndex();
01472
01473 if(trayId!=mWestVpdTrayId && trayId!=mEastVpdTrayId) continue;
01474
01475 int tubeId = aCell->cellIndex();
01476 mVPDLeTime[(trayId-121)*mNVPD+(tubeId-1)] = aCell->leadingEdgeTime();
01477 mVPDTot[(trayId-121)*mNVPD+(tubeId-1)] = aCell->tot();
01478
01479
01480
01481
01482
01483
01484
01485
01486 }
01487 tsum8(mVPDTot, mVPDLeTime);
01488 mTStart = tstart8(mProjVtxZ);
01489
01490 gMessMgr->Info("","OS") << " NWest = " << mNWest << " NEast = " << mNEast << " TdcSum West = " << mTSumWest << " East = " << mTSumEast << endm;
01491 if(mTStart<-1000.) {
01492 gMessMgr->Info("","OS") << " mTStart not available!" << endm;
01493 mValidStartTime = kFALSE;
01494 } else {
01495 mValidStartTime = kTRUE;
01496 }
01497 gMessMgr->Info("","OS") << " mValidCalibPar = " << mValidCalibPar << " mValidStartTime = " << mValidStartTime << endm;
01498
01500 theTof->setVpdEast(mVPDHitPatternEast);
01501 theTof->setVpdWest(mVPDHitPatternWest);
01502 theTof->setTdiff(mTDiff);
01503 theTof->setVzVpd(mVPDVtxZ);
01504 theTof->setTstart(mTStart);
01505
01506 gMessMgr->Info("","OS") << " TofCollection: NWest = " << theTof->numberOfVpdWest() << " NEast = " << theTof->numberOfVpdEast() << endm;
01507 gMessMgr->Info("","OS") << "Tdiff = " << mTDiff <<" vpd vz = " << mVPDVtxZ << " proj vz = " << mProjVtxZ<<endm;
01508
01509 StTofHitCollection *tofHit = new StTofHitCollection();
01510
01511
01512
01513
01514
01515 for(int i=0;i<ncells;i++) {
01516 StTofHit *aHit = new StTofHit;
01517 StTofCell *aCell = dynamic_cast<StTofCell*>(tofCell[i]);
01518 int trayId = aCell->trayIndex();
01519 if(trayId<=0 || trayId>120) continue;
01520
01521 aHit->setTrayIndex(aCell->trayIndex());
01522 aHit->setModuleIndex(aCell->moduleIndex());
01523 aHit->setCellIndex(aCell->cellIndex());
01524 aHit->setCellCollIndex(i);
01525
01526 int daqId = aCell->daqIndex();
01527 aHit->setDaqIndex(daqId);
01528
01529 StTrack *thisTrack = aCell->associatedTrack();
01530 aHit->setAssociatedTrack(thisTrack);
01531 StTrackGeometry *theTrackGeometry = thisTrack->geometry();
01532
01533 StThreeVectorD tofPos = theTrackGeometry->helix().at(theTrackGeometry->helix().pathLengths(*mBeamHelix).first);
01534 StThreeVectorD dcatof = tofPos - mBeamHelix->at(theTrackGeometry->helix().pathLengths(*mBeamHelix).second);
01535
01536 Double_t L = tofPathLength(&tofPos, &aCell->position(), theTrackGeometry->helix().curvature());
01537 aHit->setPathLength((Float_t)L);
01538
01539
01540 gMessMgr->Info("","OS") << " p(x,y,z) = "<<theTrackGeometry->momentum().x()<<" "<<theTrackGeometry->momentum().y()<<" "<<theTrackGeometry->momentum().z()<<endm;
01541 gMessMgr->Info("","OS") << " Project Z = " << tofPos.z() << " mTStart = " << mTStart << endm;
01542
01543 double tot = aCell->tot();
01544 double tdc = aCell->leadingEdgeTime();
01545 tdc -= mPhaseOffset8;
01546 while(tdc>TMAX) tdc -= TMAX;
01547 double tof = tdc - mTStart;
01548 Double_t zhit = (Double_t)aCell->zHit();
01549
01550
01551 if(mValidCalibPar&&mValidStartTime) {
01552 int moduleChan = (aCell->moduleIndex()-1)*6 + (aCell->cellIndex()-1);
01553 Double_t tofcorr = tofr8AllCorr(tof, tot, zhit, trayId, moduleChan);
01554 aHit->setTimeOfFlight((Float_t)tofcorr);
01555
01556 Double_t beta = L/(tofcorr*(C_C_LIGHT/1.e9));
01557 aHit->setBeta((Float_t)beta);
01558
01559 const StThreeVectorF momentum = thisTrack->geometry()->momentum();
01560 Double_t ptot = momentum.mag();
01561 Double_t tofe = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_ELECTRON*M_ELECTRON)/ptot;
01562 Double_t tofpi = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PION_PLUS*M_PION_PLUS)/ptot;
01563 Double_t tofk = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_KAON_PLUS*M_KAON_PLUS)/ptot;
01564 Double_t tofp = L/(C_C_LIGHT/1.e9)*sqrt(ptot*ptot+M_PROTON*M_PROTON)/ptot;
01565
01566 aHit->setTofExpectedAsElectron((Float_t)tofe);
01567 aHit->setTofExpectedAsPion((Float_t)tofpi);
01568 aHit->setTofExpectedAsKaon((Float_t)tofk);
01569 aHit->setTofExpectedAsProton((Float_t)tofp);
01570
01571 float sigmae = 999.;
01572 float sigmapi = 999.;
01573 float sigmak = 999.;
01574 float sigmap = 999.;
01575 float res = 0.085;
01576 if(fabs(res)>1.e-5) {
01577 sigmae = (Float_t)((tofcorr-tofe)/res);
01578 sigmapi = (Float_t)((tofcorr-tofpi)/res);
01579 sigmak = (Float_t)((tofcorr-tofk)/res);
01580 sigmap = (Float_t)((tofcorr-tofp)/res);
01581 }
01582 aHit->setSigmaElectron(sigmae);
01583 aHit->setSigmaPion(sigmapi);
01584 aHit->setSigmaKaon(sigmak);
01585 aHit->setSigmaProton(sigmap);
01586
01587 } else {
01588 aHit->setTimeOfFlight(9999.);
01589 aHit->setBeta(9999.);
01590 }
01591
01592 tofHit->push_back(aHit);
01593 }
01594
01595
01596
01597 for (size_t j=0;j<tofHit->size();j++){
01598 theTof->addHit(tofHit->getHit(j));
01599 if (Debug())
01600 gMessMgr->Info("","OS") << "storing " << j << " " << " tray:"
01601 << tofHit->getHit(j)->trayIndex() << " module:"
01602 << tofHit->getHit(j)->moduleIndex() << " cell:"
01603 << tofHit->getHit(j)->cellIndex() << " TOF:"
01604 << tofHit->getHit(j)->timeOfFlight() << " beta:"
01605 << tofHit->getHit(j)->beta() << endm;
01606 }
01607
01608
01609 StSPtrVecTofHit& tofHitVec = theTof->tofHits();
01610 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
01611 for (unsigned int iNode=0; iNode<nodes.size(); iNode++){
01612 StTrack *theTrack = nodes[iNode]->track(primary);
01613 if(!theTrack) continue;
01614 Int_t trkId = theTrack->key();
01615 for (size_t j=0;j<tofHitVec.size();j++){
01616 StTrack *aTrack = tofHitVec[j]->associatedTrack();
01617 if(!aTrack) continue;
01618 if(aTrack->key()!=trkId) continue;
01619 StTofPidTraits* pidTof = new StTofPidTraits(tofHitVec[j]->trayIndex(), tofHitVec[j]->moduleIndex(), tofHitVec[j]->cellIndex(), tofHitVec[j]->timeOfFlight(), tofHitVec[j]->pathLength(), tofHitVec[j]->beta());
01620 pidTof->setSigmaElectron(tofHitVec[j]->sigmaElectron());
01621 pidTof->setSigmaPion(tofHitVec[j]->sigmaPion());
01622 pidTof->setSigmaKaon(tofHitVec[j]->sigmaKaon());
01623 pidTof->setSigmaProton(tofHitVec[j]->sigmaProton());
01624
01625 theTrack->addPidTraits(pidTof);
01626 }
01627 }
01628
01629 delete tofHit;
01630
01631 return kStOK;
01632 }
01633
01634
01635 Double_t StTofCalibMaker::tofrT0Corr(const Double_t tof, const Double_t Tstart, const Int_t iDaqChan)
01636 {
01637 return tof - Tstart - mTofrT0[iDaqChan];
01638 }
01639
01640
01641 Double_t StTofCalibMaker::tofrSlewingCorr(const Double_t tof, const Double_t adc, const Int_t iDaqChan)
01642 {
01643 Double_t par[mNPar];
01644 for(int i=0;i<mNPar;i++) {
01645 par[i] = mTofrTAPar[iDaqChan*mNPar+i];
01646 }
01647
01648 mTofrSlewing->SetParameters(par);
01649 return tof - mTofrSlewing->Eval(adc);
01650
01651 }
01652
01653
01654 Double_t StTofCalibMaker::tofrZCorr(const Double_t tof, const Double_t zhit)
01655 {
01656 mTofrZCorr->SetParameters(mTofrZPar);
01657 return tof - mTofrZCorr->Eval(zhit);
01658 }
01659
01660
01661 Double_t StTofCalibMaker::tofrAllCorr(const Double_t tof, const Double_t T0, const Double_t adc, const Double_t z, const Int_t iDaqChan)
01662 {
01663 gMessMgr->Info("","OS") << "\nStTofCalibMaker::tofrAllCorr: Tofr calibrating...\n"
01664 << "\tDoing Calibration in TOFr Channel " << iDaqChan
01665 << "\n\tinput tof = " << tof << " Tstart = "
01666 << T0 << " ADC = " << adc << " Zlocal = " << z
01667 << "\n" << endm;
01668
01669 Double_t tofcorr = tofrT0Corr( tof, T0, iDaqChan );
01670 gMessMgr->Info("","OS") << " T0 corr: tofcorr = " << tofcorr << endm;
01671 Double_t tofcorr2 = tofrSlewingCorr( tofcorr, adc, iDaqChan );
01672 gMessMgr->Info("","OS") << " Slewing corr: tofcorr2 = " << tofcorr2 << endm;
01673 Double_t tofcorr3 = tofrZCorr( tofcorr2, z);
01674 gMessMgr->Info("","OS") << " Z position corr: tofcorr3 = " << tofcorr3 << endm;
01675 return tofcorr3;
01676 }
01677
01678
01679 Double_t StTofCalibMaker::tofpT0Corr(const Double_t tof, const Double_t Tstart, const Int_t iDaqChan)
01680 {
01681 return tof - Tstart - mTofpT0[iDaqChan];
01682 }
01683
01684
01685 Double_t StTofCalibMaker::tofpSlewingCorr(const Double_t tof, const Double_t adc, const Int_t iDaqChan)
01686 {
01687 Double_t par[mNPar];
01688 for(int i=0;i<mNPar;i++) {
01689 par[i] = mTofpTAPar[iDaqChan*mNPar+i];
01690 }
01691
01692 mTofpSlewing->SetParameters(par);
01693 return tof - mTofpSlewing->Eval(adc);
01694
01695 }
01696
01697
01698 Double_t StTofCalibMaker::tofpZCorr(const Double_t tof, const Double_t zhit)
01699 {
01700 mTofpZCorr->SetParameters(mTofpZPar);
01701 return tof - mTofpZCorr->Eval(zhit);
01702 }
01703
01704
01705 Double_t StTofCalibMaker::tofpAllCorr(const Double_t tof, const Double_t T0, const Double_t adc, const Double_t z, const Int_t iDaqChan)
01706 {
01707 gMessMgr->Info("","OS") << "\nStTofCalibMaker::tofpAllCorr: Tofp calibrating...\n"
01708 << "\tDoing Calibration in TOFp Channel " << iDaqChan
01709 << "\n\tinput tof = " << tof << " Tstart = "
01710 << T0 << " ADC = " << adc << " Zlocal = " << z
01711 << "\n" << endm;
01712
01713 Double_t tofcorr = tofpT0Corr( tof, T0, iDaqChan );
01714 gMessMgr->Info("","OS") << " T0 corr: tofcorr = " << tofcorr << endm;
01715 Double_t tofcorr2 = tofpSlewingCorr( tofcorr, adc, iDaqChan );
01716 gMessMgr->Info("","OS") << " Slewing corr: tofcorr2 = " << tofcorr2 << endm;
01717 Double_t tofcorr3 = tofpZCorr( tofcorr2, z);
01718 gMessMgr->Info("","OS") << " Z position corr: tofcorr3 = " << tofcorr3 << endm;
01719 return tofcorr3;
01720 }
01721
01722
01723 Double_t StTofCalibMaker::tofr5AllCorr(const Double_t tof, const Double_t tot, const Double_t z, const Int_t iModuleChan)
01724 {
01725 int module = iModuleChan/6 + 1;
01726 int cell = iModuleChan%6 + 1;
01727 gMessMgr->Info("","OS") << "\nStTofCalibMaker::tofr5AllCorr: Tofr5 calibrating...\n"
01728 << "\tDoing Calibration in TOFr5 Module " << module << " Cell " << cell
01729 << "\n\tinput tof = " << tof
01730 << " TOT = " << tot << " Zlocal = " << z
01731 << "\n" << endm;
01732
01733 Double_t tofcorr = tof;
01734
01735 int iTotBin = -1;
01736 for(int i=0;i<mNBinMax-1;i++) {
01737 if(tot>=mTofr5TotEdge[iModuleChan][i] && tot<mTofr5TotEdge[iModuleChan][i+1]) {
01738 iTotBin = i;
01739 break;
01740 }
01741 }
01742 if(iTotBin>=0&&iTotBin<mNBinMax) {
01743 tofcorr -= mTofr5TotCorr[iModuleChan][iTotBin];
01744 } else {
01745 tofcorr = -9999.;
01746 }
01747
01748 int iZBin = -1;
01749 for(int i=0;i<mNBinMax-1;i++) {
01750 if(z>=mTofr5ZEdge[iModuleChan][i] && z<mTofr5ZEdge[iModuleChan][i+1]) {
01751 iZBin = i;
01752 break;
01753 }
01754 }
01755 if(iZBin>=0&&iZBin<mNBinMax) {
01756 tofcorr -= mTofr5ZCorr[iModuleChan][iZBin];
01757 } else {
01758 tofcorr = -9999.;
01759 }
01760
01761 gMessMgr->Info("","OS") << " Corrected tof: tofcorr = " << tofcorr << endm;
01762 return tofcorr;
01763 }
01764
01765
01766 Double_t StTofCalibMaker::tofr8AllCorr(const Double_t tof, const Double_t tot, const Double_t z, const Int_t iTray, const Int_t iModuleChan)
01767 {
01768 int tray = iTray;
01769 int module = iModuleChan/6 + 1;
01770 int cell = iModuleChan%6 + 1;
01771 int board = iModuleChan/24 + 1;
01772 gMessMgr->Info("","OS") << "\nStTofCalibMaker::tofr8AllCorr: Tofr8 calibrating...\n"
01773 << "\tDoing Calibration in TOFr8 Tray " << tray << " Module " << module << " Cell " << cell
01774 << "\n\tinput tof = " << tof
01775 << " TOT = " << tot << " Zlocal = " << z
01776 << "\n" << endm;
01777
01778 Double_t tofcorr = tof;
01779
01780 tofcorr -= mTofTZero[tray-1][module-1][cell-1];
01781
01782 if(Debug()) gMessMgr->Info("","OS") << "T0 correction: "<<mTofTZero[tray-1][module-1][cell-1]<<endm;
01783
01784 if(mSlewingCorr) {
01785 int iTotBin = -1;
01786 for(int i=0;i<mNBinMax-1;i++) {
01787 if(tot>=mTofTotEdge[tray-1][board-1][i] && tot<mTofTotEdge[tray-1][board-1][i+1]) {
01788 iTotBin = i;
01789 break;
01790 }
01791 }
01792 if(iTotBin>=0&&iTotBin<mNBinMax) {
01793 double x1 = mTofTotEdge[tray-1][board-1][iTotBin];
01794 double x2 = mTofTotEdge[tray-1][board-1][iTotBin+1];
01795 double y1 = mTofTotCorr[tray-1][board-1][iTotBin];
01796 double y2 = mTofTotCorr[tray-1][board-1][iTotBin+1];
01797 double dcorr = y1 + (tot-x1)*(y2-y1)/(x2-x1);
01798 if(Debug()) gMessMgr->Info("","OS") << "TOT correction: "<<dcorr<<endm;
01799
01800 tofcorr -= dcorr;
01801 } else {
01802 gMessMgr->Info("","OS") << " TOT out of range! EXIT! " << endm;
01803 return -9999.;
01804 }
01805
01806 int iZBin = -1;
01807 for(int i=0;i<mNBinMax-1;i++) {
01808 if(z>=mTofZEdge[tray-1][board-1][i] && z<mTofZEdge[tray-1][board-1][i+1]) {
01809 iZBin = i;
01810 break;
01811 }
01812 }
01813 if(iZBin>=0&&iZBin<mNBinMax) {
01814 double x1 = mTofZEdge[tray-1][board-1][iZBin];
01815 double x2 = mTofZEdge[tray-1][board-1][iZBin+1];
01816 double y1 = mTofZCorr[tray-1][board-1][iZBin];
01817 double y2 = mTofZCorr[tray-1][board-1][iZBin+1];
01818
01819 double dcorr = y1 + (z-x1)*(y2-y1)/(x2-x1);
01820
01821 tofcorr -= dcorr;
01822 if(Debug()) gMessMgr->Info("","OS") << "zHit correction: "<<dcorr<<endm;
01823
01824 } else {
01825 gMessMgr->Info("","OS") << " Z our of range! EXIT! " << endm;
01826 return -9999.;
01827 }
01828
01829 }
01830
01831 gMessMgr->Info("","OS") << " Corrected tof: tofcorr = " << tofcorr << endm;
01832 return tofcorr;
01833 }
01834
01835
01836 Double_t StTofCalibMaker::tstart(const Double_t *adc, const Double_t *tdc, const Double_t vz)
01837 {
01840 Double_t Tstart = 9999.;
01841
01842 Int_t Ieast = 0, Iwest = 0;
01843 Double_t TdcSumEast = 0., TdcSumWest = 0.;
01844 Double_t ped = 0.0;
01845 for(int i=0;i<3;i++) {
01846 if( validPVPDADC(adc[i]) && validPVPDTDC(tdc[i]) ) {
01847 Ieast++;
01848 Double_t par[mNPar];
01849 for(int j=0;j<mNPar;j++) {
01850 par[j] = mPVPDTAPar[i*mNPar+j];
01851 }
01852 mPVPDSlewing->SetParameters(par);
01853 mPVPDTdc[i] = tdc[i] - mPVPDSlewing->Eval(adc[i]-ped);
01854 TdcSumEast += mPVPDTdc[i];
01855 }
01856
01857 if( validPVPDADC(adc[i+3]) && validPVPDTDC(tdc[i+3]) ) {
01858 Iwest++;
01859 Double_t par[mNPar];
01860 for(int j=0;j<mNPar;j++) {
01861 par[j] = mPVPDTAPar[(i+3)*mNPar+j];
01862 }
01863 mPVPDSlewing->SetParameters(par);
01864 mPVPDTdc[i+3] = tdc[i+3] - mPVPDSlewing->Eval(adc[i+3]-ped);
01865 TdcSumWest += mPVPDTdc[i+3];
01866 }
01867 }
01868
01869 Double_t TdcSum = TdcSumEast + TdcSumWest;
01870
01871
01873 if ( (Ieast>=mPVPDEastHitsCut || !mEastPVPDValid) && Iwest>=mPVPDWestHitsCut ) {
01874 Tstart = (TdcSum*mTDCWidth-(Ieast-Iwest)*vz/(C_C_LIGHT/1.e9))/(Ieast+Iwest);
01875 }
01876
01877 return Tstart;
01878 }
01879
01880 Double_t StTofCalibMaker::tstart5(const Double_t *tot, const Double_t *time, const Double_t vz)
01881 {
01884 Double_t Tstart = -999999.;
01885
01886 Int_t Ieast = 0, Iwest = 0;
01887 Double_t TSumEast = 0., TSumWest = 0.;
01888 for(int i=0;i<3;i++) {
01889 if(Debug()) gMessMgr->Info("","OS") << " East pVPD tot = " << tot[i] << " time = " << time[i] << endm;
01890 if(Debug()) gMessMgr->Info("","OS") << " West pVPD tot = " << tot[i+3] << " time = " << time[i+3] << endm;
01891
01892 if( time[i]>0. ) {
01893 int ibin = -1;
01894 for(int j=0;j<mNBinMax-1;j++) {
01895 if(tot[i]>=mPVPDTotEdge[i][j] && tot[i]<mPVPDTotEdge[i][j+1]) {
01896 ibin = j;
01897 break;
01898 }
01899 }
01900 if(ibin>=0&&ibin<mNBinMax) {
01901 Ieast++;
01902 mPVPDLeTime[i] = time[i] - mPVPDTotCorr[i][ibin];
01903 TSumEast += mPVPDLeTime[i];
01904 }
01905 }
01906
01907 if( time[i+3]>0. ) {
01908 int ibin = -1;
01909 for(int j=0;j<mNBinMax-1;j++) {
01910 if(tot[i+3]>=mPVPDTotEdge[i+3][j] && tot[i+3]<mPVPDTotEdge[i+3][j+1]) {
01911 ibin = j;
01912 break;
01913 }
01914 }
01915 if(ibin>=0&&ibin<mNBinMax) {
01916 Iwest++;
01917 mPVPDLeTime[i+3] = time[i+3] - mPVPDTotCorr[i+3][ibin];
01918 TSumWest += mPVPDLeTime[i+3];
01919 }
01920 }
01921 }
01922
01923 Double_t TSum = TSumEast + TSumWest;
01924
01925 if ( Ieast>=mPVPDEastHitsCut && Iwest>=mPVPDWestHitsCut ) {
01926 Tstart = (TSum-(Ieast-Iwest)*vz/(C_C_LIGHT/1.e9))/(Ieast+Iwest);
01927 }
01928
01929 return Tstart;
01930 }
01931
01932
01933 void StTofCalibMaker::tsum8(const Double_t *tot, const Double_t *time)
01934 {
01936 mTSumEast = 0.;
01937 mTSumWest = 0.;
01938 mNEast = 0;
01939 mNWest = 0;
01940 mVPDHitPatternWest = 0;
01941 mVPDHitPatternEast = 0;
01942
01943
01944 for(int i=0;i<mNVPD;i++) {
01945 if( time[i]>0. && tot[i]>0. ) {
01946
01947 if(mSlewingCorr) {
01948 int ibin = -1;
01949 for(int j=0;j<mNBinMax-1;j++) {
01950 if(tot[i]>=mVPDTotEdge[i][j] && tot[i]<mVPDTotEdge[i][j+1]) {
01951 ibin = j;
01952 break;
01953 }
01954 }
01955 if(ibin>=0&&ibin<mNBinMax) {
01956 mNWest++;
01957
01958 double x1 = mVPDTotEdge[i][ibin];
01959 double x2 = mVPDTotEdge[i][ibin+1];
01960 double y1 = mVPDTotCorr[i][ibin];
01961 double y2 = mVPDTotCorr[i][ibin+1];
01962 double dcorr = y1 + (tot[i]-x1)*(y2-y1)/(x2-x1);
01963
01964 mVPDLeTime[i] = time[i] - dcorr;
01965 mTSumWest += mVPDLeTime[i];
01966
01967 mVPDHitPatternWest |= 1<<i;
01968 }
01969 } else {
01970 gMessMgr->Info("","OS") << " Vpd West tube " << i+1 << " TOT out of range!" << endm;
01971
01972 }
01973 }
01974
01975
01976 if( time[i+mNVPD]>0. && tot[i+mNVPD]>0. ) {
01977 double tmp = time[i+mNVPD] - mPhaseOffset8;
01978 while(tmp>TMAX) tmp -= TMAX;
01979 if(mSlewingCorr) {
01980 int ibin = -1;
01981 for(int j=0;j<mNBinMax-1;j++) {
01982 if(tot[i+mNVPD]>=mVPDTotEdge[i+mNVPD][j] && tot[i+mNVPD]<mVPDTotEdge[i+mNVPD][j+1]) {
01983 ibin = j;
01984 break;
01985 }
01986 }
01987 if(ibin>=0&&ibin<mNBinMax) {
01988 mNEast++;
01989
01990 double x1 = mVPDTotEdge[i+mNVPD][ibin];
01991 double x2 = mVPDTotEdge[i+mNVPD][ibin+1];
01992 double y1 = mVPDTotCorr[i+mNVPD][ibin];
01993 double y2 = mVPDTotCorr[i+mNVPD][ibin+1];
01994 double dcorr = y1 + (tot[i+mNVPD]-x1)*(y2-y1)/(x2-x1);
01995
01996 mVPDLeTime[i+mNVPD] = tmp - dcorr;
01997 mTSumEast += mVPDLeTime[i+mNVPD];
01998
01999 mVPDHitPatternEast |= 1<<i;
02000
02001 }
02002 } else {
02003 gMessMgr->Info("","OS") << " Vpd East tube " << i+1 << " TOT out of range!" << endm;
02004
02005 }
02006 }
02007 }
02008
02009 if ( mNEast>=mPVPDEastHitsCut && mNWest>=mPVPDWestHitsCut ) {
02010 mTDiff = (mTSumEast/mNEast - mTSumWest/mNWest)/2. - mProjVtxZ/(C_C_LIGHT/1.e9);
02011 mVPDVtxZ = (mTSumEast/mNEast - mTSumWest/mNWest)/2.*(C_C_LIGHT/1.e9);
02012 }
02013
02014 return;
02015 }
02016
02017 Double_t StTofCalibMaker::tstart8(const Double_t vz)
02018 {
02019 Double_t Tstart = -9999.;
02020
02021 Double_t TSum = mTSumEast + mTSumWest;
02022
02023 if ( mNEast>=mPVPDEastHitsCut && mNWest>=mPVPDWestHitsCut ) {
02024 Tstart = (TSum-(mNEast-mNWest)*vz/(C_C_LIGHT/1.e9))/(mNEast+mNWest);
02025 }
02026
02027 return Tstart;
02028 }
02029
02030
02031 Double_t StTofCalibMaker::GetINLcorr(const int edgeflag,const int tdcchan,const int bin)
02032 {
02033 int iboard=tdcchan/24;
02034 int chan = (tdcchan%24);
02035 int itdc=0;
02036 if(edgeflag==4) itdc = chan/8;
02037 if(edgeflag==5) itdc = 3;
02038 if(tdcchan==192&&edgeflag==4) itdc=0;
02039 if(tdcchan==193&&edgeflag==4) itdc=1;
02040 if(tdcchan==194&&edgeflag==4) itdc=1;
02041 if(tdcchan==195&&edgeflag==4) itdc=0;
02042 if(tdcchan==196&&edgeflag==4) itdc=1;
02043 if(tdcchan==197&&edgeflag==4) itdc=1;
02044
02045 return mINLtable[iboard][itdc][bin];
02046 }
02047