StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTofMuDstEval.cxx
1 #include "StTofMuDstEval.h"
2 
3 #include "StChain.h"
4 #include "TF1.h"
5 #include "TRandom.h"
6 
7 #include <iostream>
8 #include <fstream>
9 #include <stdlib.h>
10 #include <string>
11 #include <vector>
12 #include <math.h>
13 #include <cmath>
14 
15 #include "PhysicalConstants.h"
16 #include "SystemOfUnits.h"
17 #include "StThreeVector.hh"
18 #include "StThreeVectorF.hh"
19 #include "StThreeVectorD.hh"
20 #include "StLorentzVectorD.hh"
21 
22 #include "StEvent.h"
23 #include "StTofCollection.h"
24 #include "StTofRawData.h"
25 #include "StTofUtil/StSortTofRawData.h"
26 #include "StTofUtil/StTofrGeometry.h"
27 #include "StTriggerIdCollection.h"
28 #include "StTriggerId.h"
29 
30 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
31 #include "StMuDSTMaker/COMMON/StMuEvent.h"
32 #include "StMuDSTMaker/COMMON/StMuDst.h"
33 #include "StMuDSTMaker/COMMON/StMuTrack.h"
34 #include "StMuDSTMaker/COMMON/StMuTofHit.h"
35 
36 #include "StTofMuDstEval.h"
37 
38 
39 //_________________________________________________
40 StTofMuDstEval::StTofMuDstEval(const char *name, StMuDstMaker *maker):StMaker(name)
41 {
42  // StTofMuDstEval Constructor
43  // - zero all pointers defined in the header file
44  mEvent = 0;
45  mSortTofRawData = 0;
46  mTofrGeom = 0;
47  mTofCollection = 0;
48  mMuDstMaker = maker;
49  Clear("C");
50 }
51 
52 //_________________________________________________
53 StTofMuDstEval::~StTofMuDstEval()
54 {
55  Clear("C");
56 }
57 
58 //_____________________________________________________________________________
59 
60 void StTofMuDstEval::Clear(const char*)
61 {
62  if(mEvent) delete mEvent;
63  mEvent = 0;
64  if(mSortTofRawData) delete mSortTofRawData;
65  mSortTofRawData = 0;
67 }
68 
69 //_________________________________________________
71 {
72  if(mTofrGeom) delete mTofrGeom;
73 
74  return StMaker::Finish();
75 }
76 
77 
78 //_________________________________________________
79 Int_t StTofMuDstEval::Init()
80 {
81  Clear("C");
82 
83  mTofrGeom = new StTofrGeometry("tofrGeom","tofrGeom in MuDstEval");
84  if(!mTofrGeom->IsInitDone()) {
85  gMessMgr->Info("TofrGemetry initialization..." ,"OS");
86  TVolume *starHall = (TVolume *)GetDataSet("HALL");
87  mTofrGeom->Init(starHall);
88  }
89 
90  return kStOK;
91 }
92 //_________________________________________________
94 {
95  cout << " StTofMuDstEval::Make()" << endl;
96 
97  if( mMuDstMaker != NULL ) {
98  mMuDst = mMuDstMaker->muDst();
99  }
100 
101  if(!mMuDst) return kStOK;
102 
103  mEvent = new StEvent();
104  mTofCollection = new StTofCollection();
105  mEvent->setTofCollection(mTofCollection);
106  int nTofRawData = mMuDst->numberOfTofRawData();
107  for(int i=0;i<nTofRawData;i++) {
108  StTofRawData *aRawData;
109  StTofRawData *aMuRawData = (StTofRawData *)mMuDst->tofRawData(i);
110  if(aMuRawData) {
111  unsigned short leteFlag = aMuRawData->leteFlag();
112  unsigned short channel = aMuRawData->channel();
113  unsigned int tdc = aMuRawData->tdc();
114  unsigned short quality = aMuRawData->quality();
115  aRawData = new StTofRawData(leteFlag,channel,tdc,quality);
116  } else {
117  aRawData = new StTofRawData(0, 0, 0, 0);
118  }
119  mTofCollection->addRawData(aRawData);
120  }
121  mSortTofRawData = new StSortTofRawData(mTofCollection);
122 
123  return kStOK;
124 }
125 //_________________________________________________
126 void StTofMuDstEval::GetPvpdNHits(int &neast, int &nwest)
127 {
128  IntVec validchannel = mSortTofRawData->GetValidChannel();
129 
130  int used[mNPVPD] = {0,0,0,0,0,0};
131  int channum[mNPVPD] ={-1,-1,-1,-1,-1,-1};
132  float mPVPDLeTime[mNPVPD] = {0.,0.,0.,0.,0.,0.};
133  float mPVPDTot[mNPVPD] = {0.,0.,0.,0.,0.,0.};
134 
135  const Float_t mPVPDTotMin = 2.0;
136  const Float_t mPVPDTotMax = 8.0;
137 
138  for(unsigned int ich=0;ich<validchannel.size();ich++){
139  int chan = validchannel[ich];
140  if(chan<mNTOFr5) continue; // need only pvpd
141  int ichan = chan - mNTOFr5;
142  if(ichan<0||ichan>=mNPVPD) continue;
143  if(used[ichan]>0) continue; // skip multi hits
144  used[ichan]++;
145  // leading edge
146  int tmptdc = (mSortTofRawData->GetLeadingTdc(chan))[0];
147  float pvpdletdc = tmptdc;
148  mPVPDLeTime[ichan] = pvpdletdc * VHRBIN2PS/1000.;
149  // Trailing edge
150  tmptdc = (mSortTofRawData->GetTrailingTdc(chan))[0];
151  float pvpdtetdc = tmptdc;
152  float tetime = pvpdtetdc * HRBIN2PS/1000.;
153  mPVPDTot[ichan] = tetime - mPVPDLeTime[ichan];
154  channum[ichan]=ichan;
155  }
156 
157  // sort out the piled-up hit - remove those hits not from this event
158  int nPVPDFired = 0;
159  for(int i=0;i<mNPVPD;i++) {
160  if(channum[i]!=i) {
161  mPVPDLeTime[i] = 0.;
162  mPVPDTot[i] = 0.;
163  } else {
164  nPVPDFired++;
165  }
166  }
167  for(int i=0;i<mNPVPD;i++) {
168  if(channum[i]!=i) continue;
169  int n0 = 0;
170  for(int j=0;j<mNPVPD;j++) {
171  if(channum[j]!=j) continue;
172  float dt = mPVPDLeTime[j] - mPVPDLeTime[i];
173  if(fabs(dt)<200.) n0++;
174  }
175 
176  if(n0>=nPVPDFired/2) { // OK
177  } else { // not from this event
178  mPVPDLeTime[i] = 0.;
179  mPVPDTot[i] = 0.;
180  }
181  }
182 
183 
184  for(int i=0;i<mNPVPD/2;i++) {
185  if(mPVPDLeTime[i]>0.&&mPVPDTot[i]>mPVPDTotMin&&mPVPDTot[i]<mPVPDTotMax) neast++;
186  int j=i+mNPVPD/2;
187  if(mPVPDLeTime[j]>0.&&mPVPDTot[j]>mPVPDTotMin&&mPVPDTot[j]<mPVPDTotMax) nwest++;
188  }
189 
190  return;
191 }
192 //_________________________________________________
193 Float_t StTofMuDstEval::GetUncorrectedTot(StMuTofHit *tofHit)
194 {
195  Float_t tot = -999.;
196 
197  int daqIndex = tofHit->daqIndex();
198  IntVec validchannel = mSortTofRawData->GetValidChannel();
199  for(unsigned int ich=0;ich<validchannel.size();ich++){
200  int chan = validchannel[ich];
201  if(chan==daqIndex) {
202  int tmptdc = (mSortTofRawData->GetLeadingTdc(chan))[0];
203  float letime = tmptdc * VHRBIN2PS/1000.;
204  tmptdc = (mSortTofRawData->GetTrailingTdc(chan))[0];
205  float tetime = tmptdc * HRBIN2PS/1000.;
206  tot = tetime - letime;
207  break;
208  }
209  }
210 
211  return tot;
212 }
213 //_________________________________________________
214 void StTofMuDstEval::GetLocalHitPosition(StMuTofHit *tofHit, Double_t* local)
215 {
216  if(!tofHit) return;
217  int itray = tofHit->trayIndex();
218  int imodule = tofHit->moduleIndex();
219  StTofrGeomSensor* sensor = mTofrGeom->GetGeomSensor(imodule,itray);
220  if(!sensor) {
221  gMessMgr->Warning("","OS") << " No sensitive module in the projection??? -- Something weird!!! " << endm;
222  return;
223  }
224 
225  Double_t global[3] = {0.,0.,0.};
226  global[0] = tofHit->projectedPoint().x();
227  global[1] = tofHit->projectedPoint().y();
228  global[2] = tofHit->projectedPoint().z();
229 
230  sensor->Master2Local(&global[0],local);
231  delete sensor;
232  return;
233 }
StMuDst * muDst()
Definition: StMuDstMaker.h:425
static StTofRawData * tofRawData(int i)
returns pointer to the i-th tofRawData
Definition: StMuDst.h:417
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Definition: Stypes.h:40
virtual Int_t Finish()
Definition: StMaker.cxx:776