StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StIstFastSimMaker.cxx
1 /* $Id: StIstFastSimMaker.cxx,v 1.38 2015/10/30 19:01:22 perev Exp $ */
2 
3 #include "TGeoManager.h"
4 #include "TDataSet.h"
5 
6 #include "StIstSimMaker/StIstFastSimMaker.h"
7 #include "StEvent/StEvent.h"
9 #include "StMcEvent/StMcEvent.hh"
10 #include "StMcEvent/StMcHit.hh"
11 #include "StMcEvent/StMcIstHit.hh"
12 #include "StIstUtil/StIstConsts.h"
13 #include "StEvent/StIstHit.h"
14 #include "StEvent/StIstHitCollection.h"
15 #include "StIstDbMaker/StIstDb.h"
16 #include "StMcEvent/StMcIstHit.hh"
17 #include "StMcEvent/StMcIstHitCollection.hh"
18 #include "StThreeVectorF.hh"
19 #include "tables/St_HitError_Table.h"
20 
21 ClassImp(StIstFastSimMaker)
22 
23 StIstFastSimMaker::StIstFastSimMaker( const Char_t *name, bool useRandomSeed) : StMaker(name), mIstRot(NULL), mIstDb(NULL), mBuildIdealGeom(kFALSE),
24  mRandom(useRandomSeed ? time(0) : 65539), mSmear(kTRUE)
25 {
26 }
27 
28 //____________________________________________________________
29 Int_t StIstFastSimMaker::Init()
30 {
31  LOG_INFO << "StIstFastSimMaker::Init()" << endm;
32  return kStOk;
33 }
34 
35 
36 
37 //____________________________________________________________
38 Int_t StIstFastSimMaker::InitRun(int runNo)
39 {
40  LOG_INFO << "StIstFastSimMaker::InitRun" << endm;
41 
42  if (mBuildIdealGeom && !gGeoManager) {
43 
44  GetDataBase("VmcGeometry");
45 
46  if (!gGeoManager) {
47  LOG_ERROR << "Init() - "
48  "Cannot initialize StIstFastSimMaker due to missing global object of TGeoManager class. "
49  "Make sure STAR geometry is properly loaded with BFC AgML option" << endm;
50  return kFatal;
51  }
52  }
53 
54 
55  TDataSet *calibDataSet = GetDataBase("Calibrations/tracker");
56  St_HitError *istTableSet = (St_HitError *) calibDataSet->Find("ist1HitError");
57  HitError_st *istHitError = istTableSet->GetTable();
58  mResXIst1 = sqrt(istHitError->coeff[0]);
59  mResZIst1 = sqrt(istHitError->coeff[3]);
60 
61  TObjectSet *istDbDataSet = (TObjectSet *)GetDataSet("ist_db");
62 
63  if (istDbDataSet) {
64  mIstDb = (StIstDb *)istDbDataSet->GetObject();
65  }
66  else {
67  LOG_ERROR << "InitRun : no mIstDb" << endm;
68  return kStErr;
69  }
70 
71  // geometry Db tables
72  mIstRot = mIstDb->getRotations();
73 
74  if (!mIstRot) {
75  LOG_FATAL << "InitRun(): mIstRot is not initialized" << endm;
76  return kStFatal;
77  }
78 
79  if (mBuildIdealGeom) {
80  LOG_DEBUG << " Using ideal geometry" << endm;
81  }
82  else {
83  LOG_DEBUG << " Using geometry tables from the DB." << endm;
84  }
85 
86  return kStOk;
87 }
88 
89 
96 {
97  using namespace StIstConsts;
98 
99  // Get the input data structures from StEvent and StMcEvent
100  StEvent *rcEvent = (StEvent *) GetInputDS("StEvent");
101 
102  if (! rcEvent) {LOG_WARN << "Make() - StEvent not found" << endl; return kStWarn;}
103 
104  StMcEvent *mcEvent = (StMcEvent *) GetInputDS("StMcEvent");
105 
106  if (! mcEvent) {LOG_WARN << "Make() - StMcEvent not found" << endl; return kStWarn;}
107 
108  // Store hits into Ist Hit Collection
109  StIstHitCollection *istHitCollection = rcEvent->istHitCollection();
110 
111  if (!istHitCollection) {
112  istHitCollection = new StIstHitCollection;
113  rcEvent->setIstHitCollection(istHitCollection);
114  LOG_WARN << "Make() - Added new StIstHitCollection to StEvent" << endm;
115  }
116 
117  StThreeVectorF mHitError(0., 0., 0.);
118 
119  //Get MC Ist hit collection. This contains all ist hits.
120  const StMcIstHitCollection *istMcHitCol = mcEvent->istHitCollection();
121 
122  if (!istMcHitCol) {
123  LOG_FATAL << "No Ist MC hits found." << endm;
124  return kStFatal;
125  }
126 
127  //new simulator for new 1-layer design
128 
129  Int_t nIsthits = istMcHitCol->numberOfHits();
130 
131  if (istMcHitCol->layer(0)) {
132  for (UInt_t kk = 0; kk < istMcHitCol->layer(0)->hits().size(); kk++) {
133  StMcHit *mcH = istMcHitCol->layer(0)->hits()[kk];
134  StMcIstHit *mcI = dynamic_cast<StMcIstHit *>(mcH);
135 
136  Int_t matIst = 1000 + (mcI->ladder() - 1) * kIstNumSensorsPerLadder + mcI->wafer();
137 
138  TGeoHMatrix *combI = NULL;
139 
140  //Access VMC geometry once no IST geometry Db tables available or using ideal geoemtry is set
141  if (mBuildIdealGeom) {
142  TString path("HALL_1/CAVE_1/TpcRefSys_1/IDSM_1/IBMO_1");
143  path += Form("/IBAM_%ld/IBLM_%ld/IBSS_1", mcI->ladder(), mcI->wafer());
144  gGeoManager->RestoreMasterVolume();
145  gGeoManager->CdTop();
146  gGeoManager->cd(path);
147  combI = (TGeoHMatrix *)gGeoManager->GetCurrentMatrix();
148  }
149  else { //using mis-aligned gemetry from IST geometry DB tables
150  combI = (TGeoHMatrix *)mIstRot->FindObject(Form("R%04i", matIst));
151  }
152 
153  //YPWANG: McIstHit stored local position
154  Double_t globalIstHitPos[3] = {mcI->position().x(), mcI->position().y(), mcI->position().z()};
155  Double_t localIstHitPos[3] = {mcI->position().x(), mcI->position().y(), mcI->position().z()};
156 
157  LOG_DEBUG << "ladder/wafer = " << mcI->ladder() << " / " << mcI->wafer() << "\n"
158  << "x/y/z before smearing" << localIstHitPos[0] << "/" << localIstHitPos[1] << "/" << localIstHitPos[2] << endm;
159 
160  if (mSmear) { // smearing on
161  localIstHitPos[0] = distortHit(localIstHitPos[0], mResXIst1, kIstSensorActiveSizeRPhi / 2.0);
162  localIstHitPos[2] = distortHit(localIstHitPos[2], mResZIst1, kIstSensorActiveSizeZ / 2.0);
163  }
164  else { //smearing off
165  //discrete hit local position (2D structure of IST sensor pads)
166  Float_t rPhiPos = kIstSensorActiveSizeRPhi / 2.0 - localIstHitPos[0];
167  Float_t zPos = localIstHitPos[2] + kIstSensorActiveSizeZ / 2.0;
168  Short_t meanColumn = (Short_t)floor( zPos / kIstPadPitchColumn ) + 1;
169  Short_t meanRow = (Short_t)floor( rPhiPos / kIstPadPitchRow ) + 1;
170  rPhiPos = (meanRow - 1) * kIstPadPitchRow + 0.5 * kIstPadPitchRow; //unit: cm
171  zPos = (meanColumn - 1) * kIstPadPitchColumn + 0.5 * kIstPadPitchColumn; //unit: cm
172  localIstHitPos[0] = kIstSensorActiveSizeRPhi / 2.0 - rPhiPos;
173  localIstHitPos[2] = zPos - kIstSensorActiveSizeZ / 2.0;
174  }
175 
176  LOG_DEBUG << "x/y/z after smearing" << localIstHitPos[0] << "/" << localIstHitPos[1] << "/" << localIstHitPos[2] << endm;
177 
178  //YPWANG: do local-->global transform with geometry table
179  combI->LocalToMaster(localIstHitPos, globalIstHitPos);
180  StThreeVectorF gistpos(globalIstHitPos);
181 
182  UInt_t hw = ( mcI->ladder() - 1 ) * kIstNumSensorsPerLadder + mcI->wafer();
183  StIstHit *tempHit = new StIstHit(gistpos, mHitError, hw, mcI->dE(), 0);
184  tempHit->setDetectorId(kIstId);
185  tempHit->setId(mcI->key());
186  mcI->parentTrack() ? tempHit->setIdTruth(mcI->parentTrack()->key(), 100) : tempHit->setIdTruth(-999);
187  tempHit->setLocalPosition(localIstHitPos[0], localIstHitPos[1], localIstHitPos[2]);
188  istHitCollection->addHit(tempHit);
189  }//MC hits loop over
190  }//end layer=0 cut
191 
192  LOG_DEBUG << "StIstFastSimMaker::Make() -I- Loaded " << nIsthits << " ist hits. \n";
193 
194  return kStOK;
195 }
196 
197 
204 Double_t StIstFastSimMaker::distortHit(const Double_t x, const Double_t res, const Double_t detLength)
205 {
206  // Do not smear x when it is outside the physical limits. Issue a warning instead
207  if (fabs(x) > detLength) {
208  LOG_WARN << "distortHit() - Generated hit is outside detector sensor plane" << endm;
209  return x;
210  }
211 
212  Double_t smeared_x;
213 
214  do {
215  smeared_x = mRandom.Gaus(x, res);
216  }
217  while ( fabs(smeared_x) > detLength);
218 
219  return smeared_x;
220 }
Definition: Stypes.h:42
Definition: Stypes.h:40
const int kIstNumSensorsPerLadder
6 sensor per one IST Ladder
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:56
Definition: Stypes.h:44
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169
Definition: Stypes.h:41
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362