69 #include "PhysicalConstants.h"
71 #include "StFtpcSlowSimulator.hh"
72 #include "StFtpcSlowSimField.hh"
73 #include "StFtpcSlowSimCluster.hh"
74 #include "StFtpcSlowSimReadout.hh"
75 #include "StFtpcRawWriter.hh"
76 #include "StFtpcClusterMaker/StFtpcGeantReader.hh"
77 #include "StFtpcClusterMaker/StFtpcParamReader.hh"
78 #include "StFtpcClusterMaker/StFtpcDbReader.hh"
81 #include "StFtpcTrackMaker/StFtpcTrackingParams.hh"
101 int StFtpcSlowSimulator::simulate()
105 if(DEBUG) {LOG_DEBUG <<
"Begin Initialization..." << endm;}
109 if(DEBUG) field->Output();
112 float *ADC =
new float[mDb->numberOfPadrows()
113 *mDb->numberOfSectors()
115 *mDb->numberOfTimebins()];
119 if(DEBUG) rdout->Print();
124 if (DEBUG) {LOG_DEBUG <<
"Looping over points..." << endm;}
134 float aip = mDb->gasIonizationPotential()*eV;
135 float px, py, pz, pp;
138 float r_min = mDb->sensitiveVolumeInnerRadius();
139 float r_max = mDb->sensitiveVolumeOuterRadius();
140 float dip_ang, cross_ang;
142 int number_hits = mGeant->numberOfHits();
145 int n_cross_ang_max = 0;
158 for ( i=0; i<number_hits; ++i )
170 px = mGeant->pVertexX(i);
171 py = mGeant->pVertexY(i);
172 pz = mGeant->pVertexZ(i);
173 pp = sqrt ( px*px + py*py );
189 int irow = mGeant->geantPlane(mGeant->geantVolume(i)) -1 ;
196 StThreeVectorD transform = StFtpcTrackingParams::Instance()->GlobalToTpcRotation() * (org - StFtpcTrackingParams::Instance()->TpcPositionInGlobal());
199 Int_t whichFtpc = (transform.z() < 0) ? 0 : 1;
202 transform.setY(transform.y() - StFtpcTrackingParams::Instance()->InstallationPointY(whichFtpc));
203 transform.setZ(transform.z() - StFtpcTrackingParams::Instance()->InstallationPointZ(whichFtpc));
206 transform = StFtpcTrackingParams::Instance()->FtpcRotationInverse(whichFtpc) * transform;
209 transform.setY(transform.y() + StFtpcTrackingParams::Instance()->InstallationPointY(whichFtpc));
210 transform.setZ(transform.z() + StFtpcTrackingParams::Instance()->InstallationPointZ(whichFtpc));
220 rad = sqrt ( xx*xx + yy*yy );
221 if(rad < r_min || rad > r_max) {
226 de = mGeant->energyLoss(i);
232 LOG_DEBUG <<
"Now processing hit " << i <<
" with xx;yy;zz;px;py;pz :"<< xx <<
"; " <<yy <<
"; "<< zz <<
"; "<< px <<
"; "<< py <<
"; "<< pz << endm;
237 float fpp=0;
if (pp>0) fpp=atan2(py,px);
238 float alpha = fpp - atan2(yy,xx);
242 float p_perp = pp * sin(alpha);
243 float p_rad = pp * cos(alpha);
245 LOG_DEBUG <<
"alpha=" << alpha
246 <<
" pperp=" << p_perp
253 <<
" pz=" << pz << endm;
257 dip_ang = atan(p_perp / pz);
259 cross_ang = atan(p_rad / pz);
260 if(cross_ang>halfpi) cross_ang = cross_ang - pi;
265 if ( fabs( cross_ang) > ang_max ) {
266 cross_ang = ang_max*cross_ang/fabs(cross_ang) ;
269 if ( fabs( dip_ang) > ang_max ) {
270 dip_ang = ang_max*dip_ang/fabs(dip_ang) ;
278 phi = twopi + atan(yy/xx);
281 phi = pi + atan(yy/xx);
291 LOG_DEBUG << i <<
" " << xx <<
" " << yy <<
" " << zz <<
" " << rad <<
" " << phi << endm;
296 drift_time = -mDb->tZero();
299 rad_off = rdout->GetPadLength() * tan(dip_ang);
300 pad_off = rdout->GetPadLength() * tan(cross_ang);
304 LOG_DEBUG <<
" ##### Point i= " << i
305 <<
" counter=" << counter
306 <<
" nel=" << electron
310 LOG_DEBUG <<
" ##### "
311 <<
" rad_off=" << rad_off
312 <<
" pad_off=" << pad_off
314 LOG_DEBUG <<
" x = " << xx
316 <<
" z = " << zz << endm;
317 LOG_DEBUG <<
" px = " << px
321 <<
" de = " << de << endm;
322 LOG_DEBUG <<
" dip_angle = " << dip_ang
323 <<
" cross_angle = " << cross_ang
324 <<
" row_id = " << mGeant->geantPlane(mGeant->geantVolume(i))-1
325 <<
" track_id = " << mGeant->track(i)+1
326 <<
" ge_pid = " << mGeant->trackPid(i)
331 rad, phi, drift_time, irow);
333 clus->DriftDiffuse(field);
335 rdout->Avalanche(clus);
337 rdout->PadResponse(clus);
339 rdout->ShaperResponse(clus);
341 rdout->Digitize(clus, irow);
348 LOG_DEBUG <<
"Total number of hit points tested = " << number_hits << endm;
349 LOG_DEBUG <<
"Number of hit points accepted = " << counter << endm;
350 LOG_DEBUG <<
"Number of hit points rejected (radius test) = " << rad_rej << endm;
351 LOG_DEBUG <<
"Number of hit points rejected (de=0 test) = " << de_zero << endm;
352 LOG_DEBUG <<
"Number of hit points with cross_ang > cross_ang_max = " << n_cross_ang_max << endm;
353 LOG_DEBUG <<
"Writing out ADC array in raw data structure." << endm;
358 mWriter->writeArray(ADC,
359 mDb->numberOfPadrows(),
360 mDb->numberOfSectors(),
362 mDb->numberOfTimebins(),
363 mParam->zeroSuppressThreshold());
375 StFtpcSlowSimulator::~StFtpcSlowSimulator()