StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StVpdAnalysisMaker.cxx
1 /*******************************************************************
2  *
3  * $Id: StVpdAnalysisMaker.cxx,v 1.4 2018/02/26 23:26:51 smirnovd Exp $
4  *
5  * Author: Xin Dong
6  *****************************************************************
7  *
8  * Description: Vpd analysis Maker to do the calibration for pVPD
9  * hit pattern, VzVpd, Tdiff, Tstart
10  *
11  *******************************************************************/
12 #include <iostream>
13 #include "TFile.h"
14 #include "TProfile.h"
15 #include "TNtuple.h"
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TF1.h"
19 
20 #include "StEvent.h"
21 #include "StEventTypes.h"
22 #include "Stypes.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"
30 
31 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
32 #include "StMuDSTMaker/COMMON/StMuDst.h"
33 #include "StMuDSTMaker/COMMON/StMuEvent.h"
34 
35 #include "StVpdAnalysisMaker.h"
36 
37 #include "StMessMgr.h"
38 #include "StMemoryInfo.hh"
39 #include "StTimer.hh"
40 
41 
42 //_____________________________________________________________________________
44 {
47  mTofINLCorr = 0;
48  mDaqMap = 0;
49  mVertexZ = -9999.;
50 
51  mEvent = 0;
52  mMuDst = 0;
53 
54  setVPDHitsCut(1,1);
55  mSlewingCorr = kTRUE;
56  mValidCalibPar = kFALSE;
57 
59  resetVpdPars();
60 }
61 
62 //_____________________________________________________________________________
64 { /* noop */ }
65 
66 //_____________________________________________________________________________
68 {
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;
73  }
74  mVPDTZero[i] = 0.0;
75  mVPDLeTime[i] = 0.0;
76  mVPDTot[i] = 0.0;
77  }
78  mPhaseOffset8 = 0.;
79 }
80 
81 //_____________________________________________________________________________
82 void StVpdAnalysisMaker::resetVpdPars()
83 {
84  mTSumEast = 0.;
85  mTSumWest = 0.;
86  mVPDHitPatternEast = 0;
87  mVPDHitPatternWest = 0;
88  mNEast = 0;
89  mNWest = 0;
90  mVPDVtxZ = -9999.;
91  mTDiff = -9999.;
92  mTStart = -9999.;
93  mVertexZ = -9999.;
94 }
95 
96 //____________________________________________________________________________
97 Int_t StVpdAnalysisMaker::Init()
98 {
99  return kStOK;
100 }
101 
102 //____________________________________________________________________________
103 Int_t StVpdAnalysisMaker::InitRun(int runnumber)
104 {
105  // tof run configurations
106  mYear8 = (runnumber>9000000&&runnumber<10000000);
107 
108  mTofINLCorr = new StTofINLCorr();
109  mDaqMap = new StTofrDaqMap();
110  if(mYear8) {
111  mTofINLCorr->setNValidTrays(mNValidTrays_Run8);
112  mTofINLCorr->initFromDbase(this);
113  gMessMgr->Info("","OS") << " Initialize INL table for run 8 ... " << endm;
114 
115  mDaqMap->setNValidTrays(mNValidTrays_Run8);
116  mDaqMap->initFromDbaseGeneral(this);
117  gMessMgr->Info("","OS") << " Initialize Daq map for run 8 ... " << endm;
118  }
119 
120 
121  Int_t val = kStOK;
122  val = initParameters(runnumber);
123  if(val==kStOK) {
124  mValidCalibPar = kTRUE;
125  } else {
126  mValidCalibPar = kFALSE;
127  }
128 
129  if(mValidCalibPar) {
130  gMessMgr->Info(" ==> Good! Valid cali parameters! ","OS");
131  } else {
132  gMessMgr->Info(" ==> No valid cali parameters! ","OS");
133  }
134 
135  return kStOK;
136 
137 }
138 
139 //_____________________________________________________________________________
141 {
144  LOG_INFO << " -- retrieving run parameters from Calibrations_tof" << endm;
145  TDataSet *mDbDataSet = GetDataBase("Calibrations/tof/tofTotCorr");
146  if (!mDbDataSet){
147  gMessMgr->Error("unable to get TOF run parameters","OS");
148  return kStErr;
149  }
150 
151  if(mYear8) {
152  gMessMgr->Info("","OS") << " loading parameters for Run VIII" << endm;
153 
154  // read tofTotCorr table
155  St_tofTotCorr* tofTotCorr = static_cast<St_tofTotCorr*>(mDbDataSet->Find("tofTotCorr"));
156  if(!tofTotCorr) {
157  gMessMgr->Error("unable to get tof TotCorr table parameters","OS");
158  // assert(tofTotCorr);
159  return kStErr;
160  }
161  tofTotCorr_st* totCorr = static_cast<tofTotCorr_st*>(tofTotCorr->GetArray());
162  Int_t numRows = tofTotCorr->GetNRows();
163 
164  if(numRows!=mNTray8*mNTDIG+mNVPD*2) {
165  gMessMgr->Warning("","OS") << " Mis-matched number of rows in tofTotCorr table! " << endm;
166  // return kStErr;
167  }
168 
169  if(Debug()) gMessMgr->Info("","OS") << " Number of rows read in: " << numRows << " for ToT correction" << endm;
170 
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; // used for trays
175  short cellId = totCorr[i].cellId; // used for vpds
176 
177  int index = (trayId-120-1)*mNVPD+(cellId-1); // used for vpd index
178 
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) { // upVPD east west
183  mVPDTotEdge[index][j] = totCorr[i].tot[j];
184  mVPDTotCorr[index][j] = totCorr[i].corr[j];
185  }
186  } // end j 0->mNBinMax
187  } // end i 0->numRows
188 
189  // read tofPhaseOffset table
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");
193  // assert(tofPhaseOffset);
194  return kStErr;
195  }
196  tofPhaseOffset_st* tPhaseDiff = static_cast<tofPhaseOffset_st*>(tofPhaseOffset->GetArray());
197 
198  mPhaseOffset8 = tPhaseDiff[0].T0[0] + tPhaseDiff[0].T0[1]; // run 8, only e/w difference, to double precision
199  if(Debug()) gMessMgr->Info("","OS") << " PhaseOffset = " << mPhaseOffset8 << endm;
200  }
201 
202  return kStOK;
203 }
204 //____________________________________________________________________________
205 Int_t StVpdAnalysisMaker::FinishRun(int runnumber)
206 {
207  LOG_INFO << "StVpdAnalysisMaker -- cleaning up (FinishRun)" << endm;
208 
209  if(mDaqMap) delete mDaqMap;
210  mDaqMap = 0;
211 
212  if(mTofINLCorr) delete mTofINLCorr;
213  mTofINLCorr = 0;
214 
215  return kStOK;
216 }
217 
218 //_____________________________________________________________________________
220 {
221  return kStOK;
222 }
223 
224 //_____________________________________________________________________________
226 {
227  gMessMgr->Info(" StVpdAnalysisMaker::Maker: starting ...","OS");
228 
229  resetVpdPars();
230 
231  Int_t iret = kStOK;
232  if(mYear8) {
233  iret = processEventYear8();
234  }
235  return kStOK;
236 }
237 
238 //____________________________________________________________________________
240 {
241  mMuDstMaker = (StMuDstMaker *)GetMaker("MuDst");
242  if(!mMuDstMaker) {
243  LOG_INFO << " StVpdAnalysisMaker -- No MuDstMaker ... bye-bye" << endm;
244  return kStOK;
245  }
246 
247  mMuDst = mMuDstMaker->muDst();
248  if(!mMuDst) {
249  LOG_INFO << " StVpdAnalysisMaker -- No MuDst ... bye-bye" << endm;
250  return kStOK;
251  }
252 
253  mMuEvent = mMuDst->event();
254  if(mMuEvent) {
255  mVertexZ = mMuEvent->primaryVertexPosition().z();
256  if( fabs(mMuEvent->primaryVertexPosition().x())<1.e-4 &&
257  fabs(mMuEvent->primaryVertexPosition().y())<1.e-4 &&
258  fabs(mMuEvent->primaryVertexPosition().z())<1.e-4 )
259  mVertexZ = -9999;
260  }
264  mEvent = new StEvent();
265  mTofCollection = new StTofCollection();
266  mEvent->setTofCollection(mTofCollection);
267  int nTofRawData = mMuDst->numberOfTofRawData();
268  for(int i=0;i<nTofRawData;i++) {
269  StTofRawData *aRawData;
270  StTofRawData *aMuRawData = (StTofRawData *)mMuDst->tofRawData(i);
271  if(aMuRawData) {
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);
280  }
281  mTofCollection->addRawData(aRawData);
282  }
283 
284  mSortTofRawData = new StSortTofRawData(mTofCollection, mDaqMap);
285 
286  //-------------------------------------------------
287  // upVPD calibration and calculate the start timing
288  //-------------------------------------------------
289  for(int i=0;i<2*mNVPD;i++) {
290  mVPDLeTime[i] = -999.;
291  mVPDTot[i] = -999.;
292  }
293  for(int ivpd=0;ivpd<2;ivpd++) { // west and east sides
294  int trayId = (ivpd==0) ? mWestVpdTrayId : mEastVpdTrayId;
295  int ewId = trayId - 120;
296 
297  IntVec validtube = mSortTofRawData->GetValidChannel(trayId);
298  if(Debug()) gMessMgr->Info("","OS") << " Number of fired hits on tray(vpd) " << trayId << " = " << validtube.size() << endm;
299 
300  if(!validtube.size()) continue;
301  for(int i=0;i<mNVPD;i++) {
302  int tubeId = i+1;
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);
307 
308  if(!leTdc.size() || !teTdc.size()) continue;
309 
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.;
314 
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.;
319 
320  mVPDLeTime[(trayId-121)*mNVPD+(tubeId-1)] = letime;
321  mVPDTot[(trayId-121)*mNVPD+(tubeId-1)] = tetime - letime;
322  }
323  }
324  tsum(mVPDTot, mVPDLeTime);
325 
326  gMessMgr->Info("","OS") << " NWest = " << mNWest << " NEast = " << mNEast << " TdcSum West = " << mTSumWest << " East = " << mTSumEast << endm;
327 
329  mTofCollection->setVpdEast(mVPDHitPatternEast);
330  mTofCollection->setVpdWest(mVPDHitPatternWest);
331  mTofCollection->setTdiff(mTDiff);
332  mTofCollection->setVzVpd(mVPDVtxZ);
333  mTofCollection->setTstart(mTStart);
334 
335  mNWest = mTofCollection->numberOfVpdWest();
336  mNEast = mTofCollection->numberOfVpdEast();
337 
338  gMessMgr->Info("","OS") << " TofCollection: NWest = " << mVPDHitPatternWest << " NEast = " << mVPDHitPatternEast << endm;
339  gMessMgr->Info("","OS") << "Tdiff = " << mTDiff <<" vpd vz = " << mVPDVtxZ << " tstart = " << mTStart << endm;
340 
341  return kStOK;
342 }
343 
344 //_____________________________________________________________________________
345 void StVpdAnalysisMaker::tsum(const Double_t *tot, const Double_t *time)
346 {
348  mTSumEast = 0.;
349  mTSumWest = 0.;
350  mNEast = 0;
351  mNWest = 0;
352  mVPDHitPatternWest = 0;
353  mVPDHitPatternEast = 0;
354 
355  // West
356  for(int i=0;i<mNVPD;i++) {
357  if( time[i]>0. && tot[i]>0. ) {
358  // west no offset
359  if(mSlewingCorr) { // a switch
360  int ibin = -1;
361  for(int j=0;j<mNBinMax-1;j++) {
362  if(tot[i]>=mVPDTotEdge[i][j] && tot[i]<mVPDTotEdge[i][j+1]) {
363  ibin = j;
364  break;
365  }
366  }
367  if(ibin>=0&&ibin<mNBinMax) {
368  mNWest++;
369 
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);
375 
376  mVPDLeTime[i] = time[i] - dcorr;
377  mTSumWest += mVPDLeTime[i];
378 
379  mVPDHitPatternWest |= 1<<i;
380  }
381  } else {
382  gMessMgr->Info("","OS") << " Vpd West tube " << i+1 << " TOT out of range!" << endm;
383  // out of range, remove this hit
384  }
385  }
386 
387  // East
388  if( time[i+mNVPD]>0. && tot[i+mNVPD]>0. ) {
389  double tmp = time[i+mNVPD] - mPhaseOffset8;
390  while(tmp>TMAX) tmp -= TMAX;
391  if(mSlewingCorr) { // a switch
392  int ibin = -1;
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]) {
395  ibin = j;
396  break;
397  }
398  }
399  if(ibin>=0&&ibin<mNBinMax) {
400  mNEast++;
401 
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);
407 
408  mVPDLeTime[i+mNVPD] = tmp - dcorr;
409  mTSumEast += mVPDLeTime[i+mNVPD];
410 
411  mVPDHitPatternEast |= 1<<i;
412 
413  }
414  } else {
415  gMessMgr->Info("","OS") << " Vpd East tube " << i+1 << " TOT out of range!" << endm;
416  // out of range, remove this hit
417  }
418  }
419  }
420 
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);;
426  } else {
427  LOG_INFO << " StVpdAnalysisMaker -- vtx z " << mVertexZ << " is out of range! " << endm;
428  mTDiff = -9999.;
429  mTStart = -9999.;
430  }
431  }
432 
433  return;
434 }
435 
436 /*****************************************************************
437  *
438  * $Log: StVpdAnalysisMaker.cxx,v $
439  * Revision 1.4 2018/02/26 23:26:51 smirnovd
440  * StTof: Remove outdated ClassImp macro
441  *
442  * Revision 1.3 2018/02/26 23:13:21 smirnovd
443  * Move embedded CVS log messages to the end of file
444  *
445  * Revision 1.2 2012/12/14 06:35:56 geurts
446  * Changed global database calls to direct table access and/or removed deprecated database access code.
447  *
448  * Revision 1.1 2008/09/02 18:27:21 dongx
449  * first release.
450  * - Vpd analysis maker from MuDst to extract vz, Tstart, Tdiff etc.
451  * - TPC primary vertex used for Tstart and Tdiff calculation
452  *
453  */
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
void tsum(const Double_t *tot, const Double_t *time)
Run 8++ -&gt;
StMuDst * muDst()
Definition: StMuDstMaker.h:425
static StTofRawData * tofRawData(int i)
returns pointer to the i-th tofRawData
Definition: StMuDst.h:417
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)
Definition: StMuDst.h:320
~StVpdAnalysisMaker()
Destructor.
Definition: Stypes.h:40
Int_t initParameters(int)
Initialize the calibration parameters from dbase.
Definition: Stypes.h:44
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362