StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPxlHitMaker.cxx
1 
6 /***************************************************************************
7  *
8  * $Id: StPxlHitMaker.cxx,v 1.20 2015/05/14 18:57:52 smirnovd Exp $
9  *
10  * Author: Qiu Hao, Jan 2013
11  **************************************************************************/
12 
13 #include "StPxlHitMaker.h"
14 #include "StMessMgr.h"
15 #include "StEventTypes.h"
16 #include "TGeoMatrix.h"
17 #include "StPxlUtil/StThinPlateSpline.h"
18 #include "StPxlClusterMaker/StPxlCluster.h"
19 #include "StPxlClusterMaker/StPxlClusterCollection.h"
20 #include "StPxlUtil/StPxlConstants.h"
21 #include "StPxlUtil/StPxlDigiHit.h"
22 #include "tables/St_pxlControl_Table.h"
23 #include "StPxlDbMaker/StPxlDb.h"
24 
25 ClassImp(StPxlHitMaker)
26 
27 
28 StPxlHitMaker::StPxlHitMaker(const Char_t *name) : StMaker(name),
29  mPxlDb(0)
30 {
31 }
32 
33 
34 Int_t StPxlHitMaker::InitRun(Int_t runnumber)
35 {
36  TObjectSet *pxlDbDataSet = (TObjectSet*) GetDataSet("pxl_db");
37 
38  if (pxlDbDataSet) {
39  mPxlDb = (StPxlDb*) pxlDbDataSet->GetObject();
40  assert(mPxlDb);
41  }
42  else {
43  LOG_ERROR << "InitRun : not pxlDb" << endm;
44  return kStErr;
45  }
46 
47  return kStOk;
48 }
49 
50 
60 {
61  Bool_t embeddingShortCut = IAttr("EmbeddingShortCut"); // 1 for embedding, use ideal geometry with no corrections
62 
63  StEvent *pEvent = (StEvent*) GetInputDS("StEvent");
64 
65  if (!pEvent) {
66  LOG_WARN << "StPxlHitMaker::Make(): There is no StEvent " << endm;
67  return kStWarn;
68  }
69 
70  if (!mPxlDb) {
71  LOG_WARN << "StPxlHitMaker::Make(): StPxlDb mPxlDb is not initialized" << endm;
72  return kStWarn;
73  }
74 
75  // input pxl cluster collection
76  TObjectSet *pxlClusterDataSet = (TObjectSet*) GetDataSet("pxlCluster");
77  StPxlClusterCollection *pxlClusterCollection = 0;
78 
79  if (pxlClusterDataSet)
80  pxlClusterCollection = (StPxlClusterCollection*) pxlClusterDataSet->GetObject();
81 
82  // input pxl hit collection
83  StPxlHitCollection *pxlHitCollection = pEvent->pxlHitCollection();
84 
85  // if no pxl hit collection nor pxl cluster collection, nothing to work on
86  if (!pxlClusterCollection && !pxlHitCollection) {
87  LOG_WARN << "StPxlHitMaker::Make() no pxlClusterCollection or pxlHitCollection to work on" << endm;
88  return kStWarn;
89  }
90 
91  // if no pxl hit collection, create one for output
92  if (!pxlHitCollection) {
93  pxlHitCollection = new StPxlHitCollection();
94  pEvent->setPxlHitCollection(pxlHitCollection);
95  }
96 
97  // loop over the detector
98  for (int i = 0; i < kNumberOfPxlSectors; i++)
99  for (int j = 0; j < kNumberOfPxlLaddersPerSector; j++)
100  for (int k = 0; k < kNumberOfPxlSensorsPerLadder; k++) {
101  // add in new hits from clusters
102  if (pxlClusterCollection) {
103  int vecSize = pxlClusterCollection->numberOfClusters(i + 1, j + 1, k + 1);
104  for (int l = 0; l < vecSize; l++) {
105  const StPxlCluster *cluster = pxlClusterCollection->cluster(i + 1, j + 1, k + 1, l);
106 
107  pxlHitCollection->addHit(new StPxlDigiHit(*cluster, i+1, j+1, k+1));
108  }
109  }
110 
111  // Update global coordinates of all hits from sector i, ladder j, and sensor k
112  // Also, in case of real data (i.e. not MC or embedding) update the Y coordinate using
113  // the thin plane spline correction
114  const TGeoHMatrix *geoMSensorOnGlobal = mPxlDb->geoHMatrixSensorOnGlobal(i + 1, j + 1, k + 1);
115  int nHitsInSensor = pxlHitCollection->sector(i)->ladder(j)->sensor(k)->hits().size();
116  for (int l = 0; l < nHitsInSensor; l++) {
117  StPxlHit *pxlHit = pxlHitCollection->sector(i)->ladder(j)->sensor(k)->hits()[l];
118 
119  double local[3] = {pxlHit->localPosition()[0], pxlHit->localPosition()[1], pxlHit->localPosition()[2]};
120 
121  // apply Tps correction if not embedding
122  if (!embeddingShortCut || !pxlHit->idTruth()) {
123  local[1] = mPxlDb->thinPlateSpline(i + 1, j + 1, k + 1)->z(local[2], local[0]); // the Tps x, y, z are sensor local z, x, y respectively
124  pxlHit->setLocalY(local[1]);
125  }
126 
127  double global[3];
128  geoMSensorOnGlobal->LocalToMaster(local, global); // rotation and shift from sensor local to STAR global coordinate
129  pxlHit->setPosition(StThreeVectorF(global));
130  }
131  }
132 
133  return kStOK;
134 }
135 
136 
137 /***************************************************************************
138  *
139  * $Log: StPxlHitMaker.cxx,v $
140  * Revision 1.20 2015/05/14 18:57:52 smirnovd
141  * Squashed commit of the following:
142  *
143  * StPxlFastSim: Streamlined creation of PXL hits by making use of StPxlUtil/StPxlDigiHit
144  *
145  * StPxlHitMaker: Updated comments
146  *
147  * StPxlHitMaker: Streamlined creation of PXL hits by making use of StPxlUtil/StPxlDigiHit
148  *
149  * StPxlDigiHit: A helper to manipulate local hit position in StPxlHit
150  *
151  * StPxlConsts: Define constants in namespace
152  *
153  * For safety reasons, the intentions is to move the constants into the namespace
154  * and get rid of those defined in the global space.
155  *
156  * Revision 1.19 2015/05/14 18:53:50 smirnovd
157  * StPxlHitMaker: Removed unused members and local variables
158  *
159  * These values are set now internaly in the new version of StEvent/StPxlHit
160  *
161  * Revision 1.18 2015/05/14 18:53:43 smirnovd
162  * StPxlHitMaker: Minor stylistic touches to the code
163  *
164  * Revision 1.17 2015/05/14 18:53:35 smirnovd
165  * StPxlHitMaker: Update hit's Y coordinate only when hit is identified as coming from real data otherwise do nothing
166  *
167  * Do not set the Y coordinate to zero as before. Let the simulation makers decide
168  * and set the correct position
169  *
170  * Revision 1.16 2015/05/14 18:53:28 smirnovd
171  * StPxlHitMaker: Only hit's Y coordinate gets updated. The other two are just used as is
172  *
173  * Revision 1.15 2015/05/14 18:53:18 smirnovd
174  * Revert "Bug #3083 fixed. It happened when StPxlHits created in StPxlSimu"
175  *
176  * This reverts commit 26325ed704a000bd2ff32e237725b3cbbf4f7142.
177  *
178  * Revision 1.13 2014/05/08 15:10:49 smirnovd
179  * PXL DB dataset has been renamed to avoid conflict with StPxlDbMaker's name
180  *
181  * Revision 1.12 2014/02/07 22:58:30 smirnovd
182  * Cosmetic style changes
183  *
184  * Revision 1.11 2014/02/07 22:58:17 smirnovd
185  * Initialize member variables through initialization list
186  *
187  * Revision 1.10 2014/02/07 22:58:08 smirnovd
188  * Added check to validate mPxlDb pointer
189  *
190  * Revision 1.9 2014/02/07 22:56:39 smirnovd
191  * Moved CVS log list to the bottom of file
192  *
193  * Revision 1.8 2014/02/07 22:38:12 smirnovd
194  * Doxygen comments reshuffled
195  *
196  * Revision 1.7 2014/02/07 14:56:00 smirnovd
197  * When a new StPxlHitCollection is created put it in the event right away
198  *
199  * Revision 1.6 2014/01/28 19:29:40 qiuh
200  * *** empty log message ***
201  *
202  *
203  **************************************************************************/
Int_t numberOfClusters(Int_t sector, Int_t ladder, Int_t sensor) const
number of clusters in a sensor
const StPxlCluster * cluster(Int_t sector, Int_t ladder, Int_t sensor, Int_t clusterIndex) const
pointer to a cluster in the collection
Double_t z(Double_t x, Double_t y) const
calculate z on the profile at (x,y)
Definition: Stypes.h:42
Definition: Stypes.h:40
const StThinPlateSpline * thinPlateSpline(Int_t sector, Int_t ladder, Int_t sensor) const
&lt; thin plate spline function to describe the sensor surface
Definition: StPxlDb.h:126
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