21 #include "StEventTypes.h"
23 #include "StMessMgr.h"
24 #include "StThreeVectorD.hh"
25 #include "phys_constants.h"
26 #include "tables/St_tofTotCorr_Table.h"
27 #include "tables/St_tofZCorr_Table.h"
28 #include "tables/St_tofTOffset_Table.h"
29 #include "tables/St_tofPhaseOffset_Table.h"
31 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
32 #include "StMuDSTMaker/COMMON/StMuDst.h"
33 #include "StMuDSTMaker/COMMON/StMuEvent.h"
35 #include "StVpdAnalysisMaker.h"
37 #include "StMessMgr.h"
38 #include "StMemoryInfo.hh"
56 mValidCalibPar = kFALSE;
69 for(
int i=0;i<2*mNVPD;i++) {
70 for(
int j=0;j<mNBinMax;j++) {
71 mVPDTotEdge[i][j] = 0.0;
72 mVPDTotCorr[i][j] = 0.0;
82 void StVpdAnalysisMaker::resetVpdPars()
86 mVPDHitPatternEast = 0;
87 mVPDHitPatternWest = 0;
97 Int_t StVpdAnalysisMaker::Init()
103 Int_t StVpdAnalysisMaker::InitRun(
int runnumber)
106 mYear8 = (runnumber>9000000&&runnumber<10000000);
111 mTofINLCorr->setNValidTrays(mNValidTrays_Run8);
112 mTofINLCorr->initFromDbase(
this);
113 gMessMgr->Info(
"",
"OS") <<
" Initialize INL table for run 8 ... " << endm;
115 mDaqMap->setNValidTrays(mNValidTrays_Run8);
116 mDaqMap->initFromDbaseGeneral(
this);
117 gMessMgr->Info(
"",
"OS") <<
" Initialize Daq map for run 8 ... " << endm;
124 mValidCalibPar = kTRUE;
126 mValidCalibPar = kFALSE;
130 gMessMgr->Info(
" ==> Good! Valid cali parameters! ",
"OS");
132 gMessMgr->Info(
" ==> No valid cali parameters! ",
"OS");
144 LOG_INFO <<
" -- retrieving run parameters from Calibrations_tof" << endm;
145 TDataSet *mDbDataSet = GetDataBase(
"Calibrations/tof/tofTotCorr");
147 gMessMgr->Error(
"unable to get TOF run parameters",
"OS");
152 gMessMgr->Info(
"",
"OS") <<
" loading parameters for Run VIII" << endm;
155 St_tofTotCorr* tofTotCorr =
static_cast<St_tofTotCorr*
>(mDbDataSet->
Find(
"tofTotCorr"));
157 gMessMgr->Error(
"unable to get tof TotCorr table parameters",
"OS");
161 tofTotCorr_st* totCorr =
static_cast<tofTotCorr_st*
>(tofTotCorr->GetArray());
162 Int_t numRows = tofTotCorr->GetNRows();
164 if(numRows!=mNTray8*mNTDIG+mNVPD*2) {
165 gMessMgr->Warning(
"",
"OS") <<
" Mis-matched number of rows in tofTotCorr table! " << endm;
169 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" Number of rows read in: " << numRows <<
" for ToT correction" << endm;
171 for (Int_t i=0;i<mNTray8*mNTDIG+mNVPD*2;i++) {
172 short trayId = totCorr[i].trayId;
173 short moduleId = totCorr[i].moduleId;
174 short boardId = (moduleId-1)/4+1;
175 short cellId = totCorr[i].cellId;
177 int index = (trayId-120-1)*mNVPD+(cellId-1);
179 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" tray " << trayId <<
" board " << boardId <<
" cell " << cellId << endm;
180 if(trayId!=mWestVpdTrayId&&trayId!=mEastVpdTrayId)
continue;
181 for(Int_t j=0;j<mNBinMax;j++) {
182 if(trayId==mWestVpdTrayId||trayId==mEastVpdTrayId) {
183 mVPDTotEdge[index][j] = totCorr[i].tot[j];
184 mVPDTotCorr[index][j] = totCorr[i].corr[j];
190 St_tofPhaseOffset* tofPhaseOffset =
static_cast<St_tofPhaseOffset*
>(mDbDataSet->
Find(
"tofPhaseOffset"));
191 if(!tofPhaseOffset) {
192 gMessMgr->Error(
"unable to get tof PhaseOffset table parameters",
"OS");
196 tofPhaseOffset_st* tPhaseDiff =
static_cast<tofPhaseOffset_st*
>(tofPhaseOffset->GetArray());
198 mPhaseOffset8 = tPhaseDiff[0].T0[0] + tPhaseDiff[0].T0[1];
199 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" PhaseOffset = " << mPhaseOffset8 << endm;
205 Int_t StVpdAnalysisMaker::FinishRun(
int runnumber)
207 LOG_INFO <<
"StVpdAnalysisMaker -- cleaning up (FinishRun)" << endm;
209 if(mDaqMap)
delete mDaqMap;
212 if(mTofINLCorr)
delete mTofINLCorr;
227 gMessMgr->Info(
" StVpdAnalysisMaker::Maker: starting ...",
"OS");
243 LOG_INFO <<
" StVpdAnalysisMaker -- No MuDstMaker ... bye-bye" << endm;
247 mMuDst = mMuDstMaker->
muDst();
249 LOG_INFO <<
" StVpdAnalysisMaker -- No MuDst ... bye-bye" << endm;
253 mMuEvent = mMuDst->
event();
266 mEvent->setTofCollection(mTofCollection);
267 int nTofRawData = mMuDst->numberOfTofRawData();
268 for(
int i=0;i<nTofRawData;i++) {
272 unsigned short tray = aMuRawData->tray();
273 if(tray!=mWestVpdTrayId&&tray!=mEastVpdTrayId)
continue;
274 unsigned short leteFlag = aMuRawData->leteFlag();
275 unsigned short channel = aMuRawData->channel();
276 unsigned int tdc = aMuRawData->tdc();
277 unsigned int triggertime = aMuRawData->triggertime();
278 unsigned short quality = aMuRawData->quality();
279 aRawData =
new StTofRawData(leteFlag,tray,channel,tdc,triggertime,quality);
281 mTofCollection->addRawData(aRawData);
289 for(
int i=0;i<2*mNVPD;i++) {
290 mVPDLeTime[i] = -999.;
293 for(
int ivpd=0;ivpd<2;ivpd++) {
294 int trayId = (ivpd==0) ? mWestVpdTrayId : mEastVpdTrayId;
295 int ewId = trayId - 120;
297 IntVec validtube = mSortTofRawData->GetValidChannel(trayId);
298 if(Debug()) gMessMgr->Info(
"",
"OS") <<
" Number of fired hits on tray(vpd) " << trayId <<
" = " << validtube.size() << endm;
300 if(!validtube.size())
continue;
301 for(
int i=0;i<mNVPD;i++) {
303 int lechan = (ewId==1) ? mDaqMap->WestPMT2TDIGLeChan(tubeId) : mDaqMap->EastPMT2TDIGLeChan(tubeId);
304 int techan = (ewId==1) ? mDaqMap->WestPMT2TDIGTeChan(tubeId) : mDaqMap->EastPMT2TDIGTeChan(tubeId);
305 IntVec leTdc = mSortTofRawData->GetLeadingTdc(trayId, lechan, kTRUE);
306 IntVec teTdc = mSortTofRawData->GetTrailingTdc(trayId, lechan, kTRUE);
308 if(!leTdc.size() || !teTdc.size())
continue;
310 int letdc = leTdc[0];
311 int bin = (int)letdc&0x3ff;
312 double letdc_f = letdc + mTofINLCorr->getVpdINLCorr(ewId, lechan, bin);
313 double letime = letdc_f*VHRBIN2PS / 1000.;
315 int tetdc = teTdc[0];
316 bin = (int)tetdc&0x3ff;
317 double tetdc_f = tetdc + mTofINLCorr->getVpdINLCorr(ewId, techan, bin);
318 double tetime = tetdc_f*VHRBIN2PS / 1000.;
320 mVPDLeTime[(trayId-121)*mNVPD+(tubeId-1)] = letime;
321 mVPDTot[(trayId-121)*mNVPD+(tubeId-1)] = tetime - letime;
324 tsum(mVPDTot, mVPDLeTime);
326 gMessMgr->Info(
"",
"OS") <<
" NWest = " << mNWest <<
" NEast = " << mNEast <<
" TdcSum West = " << mTSumWest <<
" East = " << mTSumEast << endm;
329 mTofCollection->setVpdEast(mVPDHitPatternEast);
330 mTofCollection->setVpdWest(mVPDHitPatternWest);
331 mTofCollection->setTdiff(mTDiff);
332 mTofCollection->setVzVpd(mVPDVtxZ);
333 mTofCollection->setTstart(mTStart);
335 mNWest = mTofCollection->numberOfVpdWest();
336 mNEast = mTofCollection->numberOfVpdEast();
338 gMessMgr->Info(
"",
"OS") <<
" TofCollection: NWest = " << mVPDHitPatternWest <<
" NEast = " << mVPDHitPatternEast << endm;
339 gMessMgr->Info(
"",
"OS") <<
"Tdiff = " << mTDiff <<
" vpd vz = " << mVPDVtxZ <<
" tstart = " << mTStart << endm;
352 mVPDHitPatternWest = 0;
353 mVPDHitPatternEast = 0;
356 for(
int i=0;i<mNVPD;i++) {
357 if( time[i]>0. && tot[i]>0. ) {
361 for(
int j=0;j<mNBinMax-1;j++) {
362 if(tot[i]>=mVPDTotEdge[i][j] && tot[i]<mVPDTotEdge[i][j+1]) {
367 if(ibin>=0&&ibin<mNBinMax) {
370 double x1 = mVPDTotEdge[i][ibin];
371 double x2 = mVPDTotEdge[i][ibin+1];
372 double y1 = mVPDTotCorr[i][ibin];
373 double y2 = mVPDTotCorr[i][ibin+1];
374 double dcorr = y1 + (tot[i]-x1)*(y2-y1)/(x2-x1);
376 mVPDLeTime[i] = time[i] - dcorr;
377 mTSumWest += mVPDLeTime[i];
379 mVPDHitPatternWest |= 1<<i;
382 gMessMgr->Info(
"",
"OS") <<
" Vpd West tube " << i+1 <<
" TOT out of range!" << endm;
388 if( time[i+mNVPD]>0. && tot[i+mNVPD]>0. ) {
389 double tmp = time[i+mNVPD] - mPhaseOffset8;
390 while(tmp>TMAX) tmp -= TMAX;
393 for(
int j=0;j<mNBinMax-1;j++) {
394 if(tot[i+mNVPD]>=mVPDTotEdge[i+mNVPD][j] && tot[i+mNVPD]<mVPDTotEdge[i+mNVPD][j+1]) {
399 if(ibin>=0&&ibin<mNBinMax) {
402 double x1 = mVPDTotEdge[i+mNVPD][ibin];
403 double x2 = mVPDTotEdge[i+mNVPD][ibin+1];
404 double y1 = mVPDTotCorr[i+mNVPD][ibin];
405 double y2 = mVPDTotCorr[i+mNVPD][ibin+1];
406 double dcorr = y1 + (tot[i+mNVPD]-x1)*(y2-y1)/(x2-x1);
408 mVPDLeTime[i+mNVPD] = tmp - dcorr;
409 mTSumEast += mVPDLeTime[i+mNVPD];
411 mVPDHitPatternEast |= 1<<i;
415 gMessMgr->Info(
"",
"OS") <<
" Vpd East tube " << i+1 <<
" TOT out of range!" << endm;
421 if ( mNEast>=mVPDEastHitsCut && mNWest>=mVPDWestHitsCut ) {
422 mVPDVtxZ = (mTSumEast/mNEast - mTSumWest/mNWest)/2.*(C_C_LIGHT/1.e9);
423 if(fabs(mVertexZ)<200.) {
424 mTDiff = (mTSumEast/mNEast - mTSumWest/mNWest)/2. - mVertexZ/(C_C_LIGHT/1.e9);
425 mTStart = (mTSumEast+mTSumWest-(mNEast-mNWest)*mVertexZ/(C_C_LIGHT/1.e9))/(mNEast+mNWest);;
427 LOG_INFO <<
" StVpdAnalysisMaker -- vtx z " << mVertexZ <<
" is out of range! " << endm;
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in 'physical events'. Therefore there is only 1 primary vert...
void tsum(const Double_t *tot, const Double_t *time)
Run 8++ ->
static StTofRawData * tofRawData(int i)
returns pointer to the i-th tofRawData
StVpdAnalysisMaker(const char *name="vpdAna")
Default constructor.
void resetCalibPars()
Reset the calibration parameters.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
~StVpdAnalysisMaker()
Destructor.
Int_t processEventYear8()
Int_t initParameters(int)
Initialize the calibration parameters from dbase.
virtual TDataSet * Find(const char *path) const