StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBTofMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StBTofMaker.cxx,v 1.4 2018/02/26 23:26:50 smirnovd Exp $
4  *
5  * Author: Valeri Fine, BNL Feb 2008
6  ***************************************************************************
7  *
8  * Description: Convert StBTofRawHitCollection to StBTofHitCollection
9  *
10  * Input: BTofRawHitCollection
11  * Output: BTofHitCollection
12  *
13  ***************************************************************************
14  *
15  **************************************************************************/
16 #include "StBTofMaker.h"
17 
18 #include "StEventTypes.h"
19 #include "StEvent/StBTofCollection.h"
20 #include "StEvent/StBTofHeader.h"
21 #include "StEvent/StBTofRawHit.h"
22 #include "StBTofUtil/StBTofRawHitCollection.h"
23 #include "StBTofUtil/StBTofHitCollection.h"
24 #include "StBTofUtil/StBTofDaqMap.h"
25 #include "StBTofUtil/StBTofINLCorr.h"
26 #include "StEvent/StEvent.h"
27 
28 
29 //_____________________________________________________________
30 StBTofMaker::StBTofMaker(const char *name):StMaker("tof",name)
31 , mStEvent(0)
32 {
33  mDoINLCorr = kTRUE; // default
34  mDoTriggerCut = kTRUE; // default
35 
36  mBTofDaqMap = 0;
37  mBTofSortRawHit = 0;
38  mBTofINLCorr = 0;
39 
40  LOG_INFO << "StBTofMaker::ctor" << endm;
41 }
42 
43 //_____________________________________________________________
44 StBTofMaker::~StBTofMaker()
45 { }
46 
47 //_____________________________________________________________
48 void StBTofMaker::Clear(Option_t* option)
49 {
50  for(int i=0;i<4;i++) mTriggerTimeStamp[i] = 0;
51 }
52 
53 //_____________________________________________________________
54 Int_t StBTofMaker::Init()
55 {
56  Clear("");
57  return kStOK;
58 }
59 
60 //_____________________________________________________________
61 Int_t StBTofMaker::InitRun(Int_t runnumber)
62 {
64  // TOF Daq map and INL initialization -- load from StBTofUtil
66  LOG_INFO << " Initialize Daq map ... " << endm;
67  mBTofDaqMap = new StBTofDaqMap();
68  mBTofDaqMap->Init(this);
69 
70  mNValidTrays = mBTofDaqMap->numberOfValidTrays();
71 
72  LOG_INFO << " Initialize StBTofSortRawHit() ... " << endm;
73  mBTofSortRawHit = new StBTofSortRawHit();
74  mBTofSortRawHit->Init(this, mBTofDaqMap);
75 
76  if(mDoINLCorr) {
77  LOG_INFO << " Initialize INL table ... " << endm;
78  mBTofINLCorr = new StBTofINLCorr();
79  mBTofINLCorr->initFromDbase(this);
80  }
81 
82 
83  return kStOK;
84 }
85 
86 //_____________________________________________________________
87 Int_t StBTofMaker::FinishRun(Int_t runnumber)
88 {
89  if(mBTofDaqMap) delete mBTofDaqMap;
90  mBTofDaqMap = 0;
91 
92  if(mDoINLCorr) {
93  if(mBTofINLCorr) delete mBTofINLCorr;
94  mBTofINLCorr = 0;
95  }
96 
97  if(mBTofSortRawHit) delete mBTofSortRawHit;
98  mBTofSortRawHit = 0;
99 
100  return kStOK;
101 }
102 
103 //-------------------------------------------------------------
105 {
106  Clear("");
107  return kStOK;
108 }
109 
110 //_____________________________________________________________
117 {
119  StBTofCollection *btofCollection = 0;
120  mStEvent = dynamic_cast<StEvent *> (GetInputDS("StEvent"));
121 // LOG_INFO << "StBTofMaker::Make : StEvent has been retrieved "
122 // <<mStEvent<< endm;
123 
124  if (mStEvent) {
125  btofCollection = mStEvent->btofCollection();
126 
128  if ( !btofCollection ) {
130  btofCollection = new StBTofCollection();
131  mStEvent->setBTofCollection(btofCollection);
132  }
133  }
134  return btofCollection;
135 }
136 
137 //_____________________________________________________________
139 {
140  mBTofCollection = GetBTofCollection();
141 // LOG_INFO << " getting the tof collection " << mBTofCollection << endm;
142  if (mBTofCollection) {
143  fillBTofHitCollection();
144  }
145  return kStOk;
146 }
147 //____________________________________________
151 void StBTofMaker::fillBTofHitCollection()
152 {
153  mBTofSortRawHit->setBTofCollection(mBTofCollection);
154 
155  // multi-tray system
156  IntVec validtray = mBTofDaqMap->ValidTrays();
157  for(size_t i=0;i<validtray.size();i++) {
158  int trayId = validtray[i];
159  IntVec validchannel = mBTofSortRawHit->GetValidChannel(trayId);
160  if(Debug()) {
161  LOG_INFO << " Number of fired hits on tray " << trayId << " = " << validchannel.size() << endm;
162  }
163 
164  for(size_t iv=0;iv<validchannel.size();iv++) {
165  UIntVec leTdc = mBTofSortRawHit->GetLeadingTdc(trayId, validchannel[iv], mDoTriggerCut);
166  UIntVec teTdc = mBTofSortRawHit->GetTrailingTdc(trayId, validchannel[iv], mDoTriggerCut);
167 
168  if(Debug()) {
169  LOG_INFO << " Number of fired hits on channel " << validchannel[iv] << " = " << leTdc.size() << " / " << teTdc.size() << endm;
170  }
171 
172  if(!leTdc.size() || !teTdc.size()) continue;
173 
174  int chan = validchannel[iv];
175  IntVec map = mBTofDaqMap->TDIGChan2Cell(chan);
176  int moduleId = map[0];
177  int cellId = map[1];
178 
179  // store raw hit from trays and vpds into StBTofHit
180  //
181  // correct for INL
182  unsigned int tmptdc = leTdc[0]; // select the first hit
183  int bin = tmptdc&0x3ff;
184  double corr = mDoINLCorr ? mBTofINLCorr->getTrayINLCorr(trayId, chan, bin) : 0.0;
185  double tmptdc_f = tmptdc + corr;
186  double letime = tmptdc_f*VHRBIN2PS / 1000.;
187 
188  tmptdc = teTdc[0];
189  bin = tmptdc&0x3ff;
190  corr = mDoINLCorr ? mBTofINLCorr->getTrayINLCorr(trayId, chan, bin) : 0.0;
191  tmptdc_f = tmptdc + corr;
192  double tetime = tmptdc_f*VHRBIN2PS / 1000.;
193 
194  StBTofHit *aHit = new StBTofHit();
195  aHit->setTray((UChar_t)trayId);
196  aHit->setModule((UChar_t)moduleId);
197  aHit->setCell((UChar_t)cellId);
198  aHit->setLeadingEdgeTime(letime);
199  aHit->setTrailingEdgeTime(tetime);
200  mBTofCollection->addHit(aHit);
201 
202  } // end channel
203  } // end tray
204 
205  // vpd -> StBTofHit
206  for(int ivpd=0;ivpd<2;ivpd++) { // west and east sides
207  StBeamDirection eastwest = (ivpd==0) ? west : east;
208  int trayId = (ivpd==0) ? mWestVpdTrayId : mEastVpdTrayId;
209  IntVec validtube = mBTofSortRawHit->GetValidChannel(trayId);
210  if(Debug()) {
211  LOG_INFO << " Number of fired hits on tray(vpd) " << trayId << " = " << validtube.size() << endm;
212  }
213 
214  if(!validtube.size()) continue;
215  for(int i=0;i<mNVPD;i++) {
216  int tubeId = i+1;
217  int lechan = (ivpd==0) ? mBTofDaqMap->WestPMT2TDIGLeChan(tubeId) : mBTofDaqMap->EastPMT2TDIGLeChan(tubeId);
218  int techan = (ivpd==0) ? mBTofDaqMap->WestPMT2TDIGTeChan(tubeId) : mBTofDaqMap->EastPMT2TDIGTeChan(tubeId);
219  UIntVec leTdc = mBTofSortRawHit->GetLeadingTdc(trayId, lechan, mDoTriggerCut);
220  UIntVec teTdc = mBTofSortRawHit->GetTrailingTdc(trayId, lechan, mDoTriggerCut); // channel number should be le, sorted in StBTofSortRawHit
221 
222  if(Debug()) {
223  LOG_INFO << " Number of fired hits on tube " << tubeId << " = " << leTdc.size() << " / " << teTdc.size() << endm;
224  }
225 
226  if(leTdc.size() && teTdc.size()) {
227 
228  // correct for INL
229  unsigned int tmptdc = leTdc[0]; // select the first hit
230  int bin = tmptdc&0x3ff;
231  double corr = mDoINLCorr ? mBTofINLCorr->getVpdINLCorr(eastwest, lechan, bin) : 0.0;
232  double tmptdc_f = tmptdc + corr;
233  double letime = tmptdc_f*VHRBIN2PS / 1000.;
234 
235  tmptdc = teTdc[0];
236  bin = tmptdc&0x3ff;
237  corr = mDoINLCorr ? mBTofINLCorr->getVpdINLCorr(eastwest, techan, bin) : 0.0;
238  tmptdc_f = tmptdc + corr;
239  double tetime = tmptdc_f*VHRBIN2PS / 1000.;
240 
241  StBTofHit *aHit = new StBTofHit();
242  aHit->setTray((UChar_t)trayId);
243  aHit->setModule(0);
244  aHit->setCell((UChar_t)tubeId);
245  aHit->setLeadingEdgeTime(letime);
246  aHit->setTrailingEdgeTime(tetime);
247  mBTofCollection->addHit(aHit);
248  }
249  }
250  }
251  //
252 
253 }
void Init(StMaker *maker)
Initial function, need a maker to access the data base.
Int_t Make()
Int_t numberOfValidTrays()
Returns the number of valid trays.
Definition: StBTofDaqMap.h:116
Int_t WestPMT2TDIGTeChan(const Int_t iTube)
To convert west VPD PMT number to TDIG trailing channel number.
Int_t WestPMT2TDIGLeChan(const Int_t iTube)
To convert west VPD PMT number to TDIG leading channel number.
IntVec ValidTrays()
Returns the list of valid tray Ids.
void setBTofCollection(StBTofCollection *tofColl)
set to use the VPD delays
Int_t EastPMT2TDIGTeChan(const Int_t iTube)
To convert east VPD PMT number to TDIG trailing channel number.
IntVec GetValidChannel(int tray)
Returns the valid channel Ids for a tray.
UIntVec GetLeadingTdc(int tray, int channel, bool triggerevent=true)
Returns the leading Tdcs for one channel. triggerevent used as a switch for physical hits selection...
float getTrayINLCorr(int trayId, int globalTdcChan, int bin)
To get the INL correction tables for trays.
UIntVec GetTrailingTdc(int tray, int channel, bool triggerevent=true)
Returns the trailing Tdcs for one channel. triggerevent used as a switch for physical hits selection...
StBTofCollection * GetBTofCollection()
Switch to turn on trigger cut.
void initFromDbase(StMaker *maker)
Initial function to access the data base and retrieve INL tables.
IntVec TDIGChan2Cell(const Int_t iTdc)
To convert TDIG channel number to module/cell number.
Definition: Stypes.h:40
Int_t Finish()
Int_t EastPMT2TDIGLeChan(const Int_t iTube)
void Clear(Option_t *option="")
User defined functions.
Definition: StBTofMaker.cxx:48
StBTofMaker(const char *name="tof_raw")
Default constructor.
Definition: StBTofMaker.cxx:30
float getVpdINLCorr(StBeamDirection eastwest, int globalTdcChan, int bin)
To get the INL correction tables for vpds.
Definition: Stypes.h:41