11 #include "StSsdFastSimMaker.h"
13 #include "StEventTypes.h"
16 #include "Sti/StiVMCToolKit.h"
17 #include "StarClassLibrary/StRandom.hh"
18 #include "tables/St_HitError_Table.h"
24 #include "tables/St_g2t_ssd_hit_Table.h"
25 #include "StSsdDbMaker/StSsdDbMaker.h"
26 #include "StSsdDbMaker/StSstDbMaker.h"
27 #include "StSsdUtil/StSsdBarrel.hh"
28 #include "StSsdHitCollection.h"
30 #include "StMcEvent.hh"
44 StSsdFastSimMaker::~StSsdFastSimMaker(){
55 int StSsdFastSimMaker::Init()
59 myRandom->setSeed(seed);
66 LOG_DEBUG <<
"Init() : Defining the histograms" << endm;
68 WaferNumb =
new TH1S(
"WaferNumb",
"Hits from geant per Wafer Id",1620,7000,8620);
69 WaferNumb->SetXTitle(
"from 7000 to 7000*(iW*100)+16");
70 WaferNumb->SetLabelSize(0.03,
"X");
71 WaferNumb->SetLabelSize(0.03,
"Y");
72 HitsMap =
new TH2S(
"HitsMap",
"Map of hits in ssd wafers",20,1,21,16,1,17);
73 HitsMap->SetXTitle(
"Ladder");
74 HitsMap->SetYTitle(
"Wafer");
75 HitsMap->SetLabelSize(0.03,
"X");
76 HitsMap->SetLabelSize(0.03,
"Y");
77 dX =
new TH1F(
"dX",
"difference in X after smearing the hit",200,-0.02,0.02);
78 dX->SetXTitle(
"x_{G} - x_{G}^{smear} [cm]");
79 dX->SetLabelSize(0.03,
"X");
80 dX->SetLabelSize(0.03,
"Y");
81 dY =
new TH1F(
"dY",
"difference in Y after smearing the hit",200,-0.02,0.02);
82 dY->SetXTitle(
"y_{G} - y_{G}^{smear} [cm]");
83 dY->SetLabelSize(0.03,
"X");
84 dY->SetLabelSize(0.03,
"Y");
85 dZ =
new TH1F(
"dZ",
"difference in Z after smearing the hit",800,-2,2);
86 dZ->SetXTitle(
"z_{G} - z_{G}^{smear} [cm]");
87 dZ->SetLabelSize(0.03,
"X");
88 dZ->SetLabelSize(0.03,
"Y");
89 Local =
new TH2F(
"Local",
"Local x vs local y : hits ",800,-4,4,250,-2.25,2.25);
90 Local->SetXTitle(
"x_{l}[cm]");
91 Local->SetYTitle(
"y_{l}[cm]");
92 Local->SetLabelSize(0.03,
"X");
93 Local->SetLabelSize(0.03,
"Y");
94 Ratio =
new TH1F(
"Ratio",
"Ratio between initial geant hits and after removal of the dead areas",120,0,1.2);
95 Ratio->SetLabelSize(0.03,
"X");
96 Ratio->SetLabelSize(0.03,
"Y");
101 int StSsdFastSimMaker::InitRun(
int RunNo)
104 TDataSet *set = GetDataBase(
"Calibrations/tracker");
105 St_HitError *tableSet = (St_HitError *)set->
Find(
"ssdHitError");
106 HitError_st* hitError = tableSet->GetTable();
107 mResXSsd = sqrt(hitError->coeff[0]);
108 mResZSsd = sqrt(hitError->coeff[3]);
109 LOG_DEBUG <<
"Smearing SSD hits by " << mResXSsd <<
" " << mResZSsd <<
" cm in the SSD " << endm;
112 TDataSet *ssdparams = GetInputDB(
"Geometry/ssd");
114 LOG_ERROR <<
"No access to Geometry/ssd parameters" << endm;
118 m_ctrl = (St_slsCtrl *)local(
"slsCtrl");
119 m_dimensions = (St_ssdDimensions *)local(
"ssdDimensions");
120 m_positions = (St_ssdWafersPosition *)local(
"ssdWafersPosition");
123 LOG_ERROR <<
"No access to control parameters" << endm;
126 if ((!m_dimensions)||(!m_positions)) {
127 LOG_ERROR <<
"No access to geometry parameters" << endm;
130 St_ssdConfiguration* configTable = (St_ssdConfiguration*) local(
"ssdConfiguration");
132 LOG_ERROR <<
"InitRun : No access to ssdConfiguration database" << endm;
135 m_config = (ssdConfiguration_st*) configTable->GetTable() ;
145 mEvent = (
StEvent*) GetInputDS(
"StEvent");
148 mCol = mEvent->ssdHitCollection();
151 LOG_WARN <<
"StSsdFastSimulatorMaker -E- no SsdHitCollection!" << endm;
153 mEvent->setSsdHitCollection(mCol);
154 LOG_WARN <<
"Make() has added a non existing StSsdHitCollection" <<endm;
158 LOG_WARN <<
"No StEvent on input, bye bye" << endm;
return kStWarn;
162 if (! gGeoManager) GetDataBase(
"VmcGeometry");
163 LOG_DEBUG <<
"Geometry Loaded" << endm;
164 St_g2t_ssd_hit *g2t_ssd_hit = (St_g2t_ssd_hit *) geant(
"g2t_ssd_hit");
166 LOG_WARN <<
"No g2t_ssd_hit on input, bye bye" << endm;
return kStWarn;
169 g2t_ssd_hit_st *g2t = g2t_ssd_hit->GetTable();
171 LOG_INFO<<
"#### START OF SSD FAST SIM MAKER ####"<<endm;
172 mySsd = StSsdBarrel::Instance();
173 ssdDimensions_st *dimensions = m_dimensions->GetTable();
174 setSsdParameters(dimensions);
175 if(Debug()>1) printSsdParameters();
176 Int_t inContainer = 0;
179 LOG_INFO<<Form(
"NumberOfRows = %d Size of g2t_ssd table=%d",(
int)g2t_ssd_hit->GetNRows(),(int)g2t_ssd_hit->GetTableSize())<<endm;
180 Int_t minWaf = mSsdLayer*1000;
182 Int_t currWafNumb = 0;
183 Int_t currLadder = 0;
188 for (i = 0; i < g2t_ssd_hit->GetNRows() ; i++) {
189 currWafId=g2t[i].volume_id%10000;
190 if (currWafId > minWaf) {
191 currLadder = StSsdBarrel::Instance()->idWaferToLadderNumb(currWafId);
192 currWafNumb = StSsdBarrel::Instance()->idWaferToWafer(currWafId);
194 mHit =
new StSsdHit(g2t[i].x,error,currWafId,g2t[i].de,c);
195 LOG_DEBUG<<Form(
"currWafId=%d currWafNum=%d currLadder=%d",currWafId,currWafNumb,currLadder)<<endm;
198 Double_t xl[3] = {mHit->position().x(),mHit->position().y(),mHit->position().z()};
199 LOG_DEBUG <<Form(
"local position x=%f y=%f z=%f",xl[0],xl[1],xl[2])<<endm;
200 LOG_DEBUG <<
"will smear X"<<endm;
201 Double_t xlSmear[3]={0.,0.,0.};
202 xlSmear[0] = (distortHit(xl[0], mResXSsd));
203 LOG_DEBUG <<
"will smear Z"<<endm;
204 xlSmear[2] = (distortHit(xl[2], mResZSsd));
206 LOG_DEBUG <<Form(
"smeared local position x=%f y=%f z=%f",xlSmear[0],xlSmear[1],xlSmear[2])<<endm;
207 Double_t xgSmear[3]={0.,0.,0.};
208 mySsd->mLadders[currLadder]->mWafers[currWafNumb]->LocalToMaster(xlSmear,xgSmear);
209 LOG_DEBUG<<
"After : global position are :"<<endm;
210 LOG_DEBUG <<Form(
"x=%f y=%f z=%f",xgSmear[0],xgSmear[1],xgSmear[2])<<endm;
211 LOG_DEBUG <<Form(
"Smearing done...")<< endm;
212 in = IsOnWafer(xlSmear[0],xlSmear[2]);
214 LOG_DEBUG <<
"good hit in wafer active area " << endm;
215 iok = RemoveTriangle(xlSmear[0],xlSmear[2]);
218 LOG_DEBUG <<
"good hit after triangle rejection" << endm;
219 Local->Fill(xlSmear[0],xlSmear[2]);
222 if(IAttr(
".histos")){
223 HitsMap->Fill(currLadder+1,currWafNumb+1,1);
224 WaferNumb->Fill(currWafId);
225 dX->Fill(mHit->position().x()-xgSmear[0]);
226 dY->Fill(mHit->position().y()-xgSmear[1]);
227 dZ->Fill(mHit->position().z()-xgSmear[2]);
234 + 16 * idWaferToWaferNumb(currWafId);
235 mSmearedhit->setHardwarePosition(hw);
236 mSmearedhit->setLocalPosition(xlSmear[0],xlSmear[2]);
237 mSmearedhit->setIdTruth(g2t[i].track_p,100);
238 inContainer+=mCol->addHit(mSmearedhit);
243 LOG_INFO<<
"#### -> "<<inContainer<<
" HITS WRITTEN INTO CONTAINER ####"<<endm;
244 Ratio->Fill(inContainer/(
float)g2t_ssd_hit->GetNRows());
247 LOG_INFO<<
"######### NO SSD HITS WRITTEN INTO CONTAINER ####"<<endm;
249 LOG_DEBUG <<
"ssd col= "<<mCol->numberOfHits()<<
" inContainer=" << inContainer <<
" good hits = " << goodHits <<
" initial # hits="<<g2t_ssd_hit->GetNRows()<<endm;
254 Bool_t StSsdFastSimMaker::accept(
StEvent* event){
255 return event ?
true :
false;
258 Float_t StSsdFastSimMaker::distortHit(Float_t x,
double res){
260 LOG_DEBUG <<
"In distortHit " << endm;
261 LOG_DEBUG << Form(
"smear me by %f",res)<<endm;
263 test = x + myRandom->gauss(0,res);
265 LOG_DEBUG<<
" x was " <<x<<
" and is now " << test << endm;
271 Int_t StSsdFastSimMaker::idWaferToWaferNumb(Int_t idWafer)
274 Int_t iW = (int)((idWafer - mSsdLayer*1000)/100);
275 Int_t iL = idWafer - mSsdLayer*1000 - iW*100;
276 return ((iL-1)*mNWaferPerLadder + iW -1);
279 Int_t StSsdFastSimMaker::idWaferToLadderNumb(Int_t idWafer)
282 Int_t iW = (int)((idWafer - mSsdLayer*1000)/100);
283 Int_t iL = idWafer - mSsdLayer*1000 - iW*100;
287 Int_t StSsdFastSimMaker::waferNumbToIdWafer(Int_t waferNumb)
289 Int_t iL = 1+(int)((waferNumb)/mNLadder);
290 Int_t iW = waferNumb-((iL-1)*mNLadder)+1;
291 return mSsdLayer*1000 + iW*100 + iL;
294 void StSsdFastSimMaker::setSsdParameters(ssdDimensions_st *geom_par){
295 mDimensions = geom_par;
297 mDetectorLargeEdge = 2.*geom_par[0].waferHalfActLength;
298 mDetectorSmallEdge = 2.*geom_par[0].waferHalfActWidth;
300 mNWaferPerLadder = geom_par[0].wafersPerLadder;
301 mNStripPerSide = geom_par[0].stripPerSide;
302 mStripPitch = geom_par[0].stripPitch;
303 mTheta = geom_par[0].stereoAngle;
306 void StSsdFastSimMaker::printSsdParameters(){
307 LOG_INFO <<
"###Ladders = " <<mNLadder<<
"###"<< endm;
308 LOG_INFO <<
"###Wafers per Ladder = " <<mNWaferPerLadder<<
"###"<< endm;
315 Int_t StSsdFastSimMaker::RemoveTriangle(Float_t x, Float_t y)
318 Float_t beta = (TMath::Pi()/2.) - (mTheta/2.);
319 Float_t X = (mDetectorSmallEdge/2.)*TMath::Tan(mTheta/2.);
320 Float_t l = (mDetectorLargeEdge/2.) -X ;
321 LOG_DEBUG <<Form(
"beta=%f arctan(beta)=%f X=%f l=%f mdetectorsmallEdge=%f mDetectorLargeEdge=%f\n",beta,TMath::ATan(beta),X,l,mDetectorSmallEdge,mDetectorLargeEdge)<<endm;
322 if(x>(mDetectorLargeEdge/2.) -X){
323 if(y < TMath::ATan(beta)*(x-l)){
324 LOG_DEBUG<<
"upper right corner , hit rejected at x=" << x <<
" y=" <<y << endm;
328 if(y>-1*TMath::ATan(beta)*(x-l)){
329 LOG_DEBUG<<
"bottom right corner , hit rejected at x=" << x <<
" y=" <<y << endm;
333 if(x<((-1*mDetectorLargeEdge/2.)+X)){
334 if(y<-1*TMath::ATan(beta)*(x+l)){
335 LOG_DEBUG<<
"upper left corner , hit rejected at x=" << x <<
" y=" <<y << endm;
339 if(y>1*TMath::ATan(beta)*(x+l)){
340 LOG_DEBUG<<
"bottom left corner , hit rejected at x=" << x <<
" y=" <<y << endm;
349 int StSsdFastSimMaker::IsOnWafer(Float_t x , Float_t y){
351 if((x <(mDetectorLargeEdge/2.)) && (x > (-mDetectorLargeEdge/2.)) &&
352 (y <(mDetectorSmallEdge/2.)) && (y > (-mDetectorSmallEdge/2.)))
virtual void Clear(Option_t *option="")
User defined functions.
virtual TDataSet * Find(const char *path) const