StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFstHitMaker.cxx
1 #include "Stypes.h"
2 #include "TNamed.h"
3 #include "TGeoMatrix.h"
4 
5 #include "StFstHitMaker.h"
6 #include "StFstUtil/StFstCollection.h"
7 #include "StFstUtil/StFstCluster.h"
8 #include "StFstUtil/StFstClusterCollection.h"
9 #include "StFstHit.h"
10 #include "StFstHitCollection.h"
11 
12 #include "St_base/StMessMgr.h"
13 #include "StEvent.h"
14 #include "StEventTypes.h"
15 #include "StContainers.h"
16 #include "StEvent/StEnumerations.h"
17 #include "StEvent/StFstConsts.h"
18 
19 #include "StFstDbMaker/StFstDb.h"
20 #include "tables/St_fstControl_Table.h"
21 
22 ClassImp(StFstHitMaker);
23 
24 
25 StFstHitMaker::StFstHitMaker( const char *name ) : StMaker(name), mSensorTransforms(0)
26 {}
27 
28 
29 Int_t StFstHitMaker::InitRun(Int_t runnumber)
30 {
31  TObjectSet *fstDbDataSet = (TObjectSet *) GetDataSet("fst_db");
32  StFstDb *fstDb = 0;
33 
34  if (fstDbDataSet) {
35  fstDb = (StFstDb *) fstDbDataSet->GetObject();
36  assert(fstDb);
37  }
38  else {
39  LOG_ERROR << "InitRun : no fstDb" << endm;
40  return kStErr;
41  }
42 
43  // geometry Db tables
44  mSensorTransforms = fstDb->getRotations();
45 
46  return kStOk;
47 }
48 
49 
56 {
57  // Obtain hit collection
58  StEvent *eventPtr = (StEvent *) GetDataSet("StEvent");
59 
60  if (!eventPtr) {
61  LOG_ERROR << "Make() - No StEvent found in the chain. Cannot proceed" << endm;
62  return kStErr;
63  }
64 
65  //input clusters info.
66  TObjectSet *fstDataSet = (TObjectSet *) GetDataSet("fstRawHitAndCluster");
67 
68  if (!fstDataSet) {
69  LOG_WARN << "Make() - fstRawHitAndCluster dataset not found. No FST hits will be available for tracking" << endm;
70  return kStWarn;
71  }
72 
73  StFstCollection *fstCollectionPtr = (StFstCollection *) fstDataSet->GetObject();
74 
75  if ( !fstCollectionPtr ) {
76  LOG_WARN << "Make() - StFstCollection not found. No FST hits will be available for tracking" << endm;
77  return kStWarn;
78  }
79 
80  // Get pointer to an existing StFstHitCollection if any
81  StFstHitCollection *fstHitCollection = eventPtr->fstHitCollection();
82 
83  // If no fst hit collection, create one
84  if (!fstHitCollection) {
85  fstHitCollection = new StFstHitCollection();
86  eventPtr->setFstHitCollection(fstHitCollection);
87  LOG_DEBUG << "Make() - Added new StFstHitCollection to this StEvent" << endm;
88  }
89 
90  unsigned char nClusteringType = -1;
91 
92  for (unsigned char wedgeIdx = 0; wedgeIdx < kFstNumWedges; ++wedgeIdx) {
93  //add new hits from clusters
94 
95  StFstClusterCollection *clusterCollectionPtr = fstCollectionPtr->getClusterCollection(wedgeIdx );
96 
97  if ( clusterCollectionPtr ) {
98  unsigned int numClusters = clusterCollectionPtr->getNumClusters();
99  LOG_DEBUG << "Make() - Number of clusters found in wedge " << (int)(wedgeIdx + 1) << ": " << numClusters << endm;
100 
101  unsigned short idTruth = 0;
102  unsigned char nRawHits = -1, nRawHitsR = -1, nRawHitsPhi = -1;
103  unsigned char disk = -1, wedge = -1, sensor = -1, apv = -1;
104  int meanRStrip = -1, meanPhiStrip = -1;
105  float charge = 0., chargeErr = 0.;
106  unsigned char maxTb = -1;
107  int key = -1;
108  float phiInner = -999.9, phiOuter = -999.9;
109 
110  for (std::vector< StFstCluster * >::iterator clusterIter = clusterCollectionPtr->getClusterVec().begin(); clusterIter != clusterCollectionPtr->getClusterVec().end(); ++clusterIter) {
111  idTruth = (*clusterIter)->getIdTruth();
112  key = (*clusterIter)->getKey();
113  disk = (*clusterIter)->getDisk();
114  wedge = (*clusterIter)->getWedge();
115  sensor = (*clusterIter)->getSensor();
116  apv = (*clusterIter)->getApv();
117  meanRStrip = (*clusterIter)->getMeanRStrip();
118  meanPhiStrip = (*clusterIter)->getMeanPhiStrip();
119  maxTb = (*clusterIter)->getMaxTimeBin();
120  charge = (*clusterIter)->getTotCharge();
121  chargeErr = (*clusterIter)->getTotChargeErr();
122  nRawHits = (*clusterIter)->getNRawHits();
123  nRawHitsR = (*clusterIter)->getNRawHitsR();
124  nRawHitsPhi = (*clusterIter)->getNRawHitsPhi();
125  nClusteringType = (*clusterIter)->getClusteringType();
126 
127  StFstHit *newHit = new StFstHit(disk, wedge, sensor, apv, charge, chargeErr, maxTb, meanRStrip, meanPhiStrip, nRawHits, nRawHitsR, nRawHitsPhi);
128  newHit->setId(key);
129  newHit->setIdTruth(idTruth);
130 
131  int moduleIdx;
132  if(disk == 1) // Disk 1
133  moduleIdx = wedge;
134  else if(disk == 2)// Disk 2
135  moduleIdx = wedge-12;
136  else if(disk == 3)// Disk 3
137  moduleIdx = wedge-24;
138  // The simple transformation will be updated with the geomtry table in database later
139  if(disk == 1 || disk == 3)
140  {// Disk 1 & 3
141  phiInner = kFstphiStart[moduleIdx-1]*TMath::Pi()/6.0 + 0.5*kFstzDirct[moduleIdx-1]*kFstStripPitchPhi;
142  phiOuter = kFstphiStop[moduleIdx-1]*TMath::Pi()/6.0 - 0.5*kFstzDirct[moduleIdx-1]*kFstStripPitchPhi;
143  }
144  else if(disk == 2)
145  { // Disk 2
146  phiInner = kFstphiStop[moduleIdx-1]*TMath::Pi()/6.0 - 0.5*kFstzDirct[moduleIdx-1]*kFstStripPitchPhi;
147  phiOuter = kFstphiStart[moduleIdx-1]*TMath::Pi()/6.0 + 0.5*kFstzDirct[moduleIdx-1]*kFstStripPitchPhi;
148  }
149  double local[3] = {0};
150  if(meanRStrip < kFstNumRStripsPerWedge/2)
151  { // inner
152  local[0] = kFstrStart[meanRStrip] + 0.5*kFstStripPitchR;
153  local[1] = phiInner + kFstzFilp[disk-1]*kFstzDirct[moduleIdx-1]*meanPhiStrip*kFstStripPitchPhi;
154  }
155  else
156  {// outer
157  if(sensor == 1){
158  local[0] = kFstrStart[meanRStrip] + 0.5*kFstStripPitchR;
159  local[1] = phiOuter - kFstzFilp[disk-1]*kFstzDirct[moduleIdx-1]*meanPhiStrip*kFstStripPitchPhi - kFstzFilp[disk-1]*kFstzDirct[moduleIdx-1]*0.5*kFstStripGapPhi;
160  }
161  if(sensor == 2){
162  local[0] = kFstrStart[meanRStrip] + 0.5*kFstStripPitchR;
163  local[1] = phiOuter - kFstzFilp[disk-1]*kFstzDirct[moduleIdx-1]*meanPhiStrip*kFstStripPitchPhi + kFstzFilp[disk-1]*kFstzDirct[moduleIdx-1]*0.5*kFstStripGapPhi;
164  }
165  }
166 
167  if(disk == 1) local[2] = 151.750; //unit: cm
168  else if(disk == 2) local[2] = 165.248; //unit: cm
169  else if(disk == 3) local[2] = 178.781; //unit: cm
170  newHit->setLocalPosition(local[0], local[1], local[2]); //set local position on sensor
171 
172  fstHitCollection->addHit(newHit);
173  } //cluster loop over
174  }//end clusterCollectionPtr
175 
176  //set global position
177  StFstWedgeHitCollection *wedgeHitCollection = fstHitCollection->wedge(wedgeIdx);
178  for (int sensorIdx = 0; sensorIdx < kFstNumSensorsPerWedge; sensorIdx++) {
179  StFstSensorHitCollection *sensorHitCollection = wedgeHitCollection->sensor(sensorIdx);
180 
181  for (int idx = 0; idx < (int) sensorHitCollection->hits().size(); idx++ ) {
182  StFstHit *newHit = sensorHitCollection->hits()[idx];
183  double local[3];
184  double global[3];
185  local[0] = newHit->localPosition(0);
186  local[1] = newHit->localPosition(1);
187  local[2] = newHit->localPosition(2);
188 
189  //Ye: simple transformation. Need to revisit
190  // The simple transformation will be updated with the geomtry table in database later
191  int sensorId = 1000 + ((int)newHit->getWedge() - 1) * kFstNumSensorsPerWedge + (int)newHit->getSensor();
192  TGeoHMatrix *geoMSensorOnGlobal = (TGeoHMatrix *) mSensorTransforms->FindObject(Form("R%04i", sensorId));
193  geoMSensorOnGlobal->LocalToMaster(local, global);
194 
195  global[0] = local[0]*cos(local[1]);
196  global[1] = local[0]*sin(local[1]);
197  global[2] = local[2];
198 
199  StThreeVectorF vecGlobal(global);
200  newHit->setPosition(vecGlobal); //set global position
201  }//end sensor hit collection
202  }//end wedge hit collection
203  } //wedge loop over
204 
205  fstHitCollection->setClusteringType(nClusteringType);
206 
207  return kStOk;
208 }
THashList * mSensorTransforms
A list of TGeo transformations for each FST sensor.
Definition: StFstHitMaker.h:25
Definition: Stypes.h:42
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:56
Definition: Stypes.h:44
Definition: Stypes.h:41