148 #include "St_DataSetIter.h"
149 #include "St_ObjectSet.h"
150 #include "StMessMgr.h"
156 #include "TDirectory.h"
159 #include "StSequence.hh"
160 #include "StDbUtilities/StSvtCoordinateTransform.hh"
161 #include "StDbUtilities/StGlobalCoordinate.hh"
162 #include "StDbUtilities/StSvtLocalCoordinate.hh"
163 #include "StDbUtilities/StSvtWaferCoordinate.hh"
165 #include "StSvtClassLibrary/StSvtHybridData.hh"
166 #include "StSvtClassLibrary/StSvtData.hh"
167 #include "StSvtClassLibrary/StSvtHybridPixelsD.hh"
168 #include "StSvtClassLibrary/StSvtHybridPixelsC.hh"
169 #include "StSvtClassLibrary/StSvtConfig.hh"
170 #include "StSvtClassLibrary/StSvtGeometry.hh"
171 #include "StSvtClassLibrary/StSvtWaferGeometry.hh"
172 #include "StSvtClassLibrary/StSvtT0.hh"
173 #include "StSvtClassLibrary/StSvtHybridDriftVelocity.hh"
174 #include "StSvtClassLibrary/StSvtHybridPed.hh"
175 #include "StSvtClassLibrary/StSvtDaq.hh"
176 #include "StSvtDaqMaker/StSvtHybridDaqPed.hh"
177 #include "StSvtCalibMaker/StSvtPedMaker.h"
178 #include "StSvtAngles.hh"
179 #include "StSvtElectronCloud.hh"
180 #include "StSvtSignal.hh"
181 #include "StSvtSimulation.hh"
182 #include "StSvtGeantHits.hh"
184 #include "StThreeVectorD.hh"
185 #include "StPhysicalHelixD.hh"
186 #include "SystemOfUnits.h"
188 #include "tables/St_g2t_svt_hit_Table.h"
189 #include "tables/St_g2t_track_Table.h"
192 #include "StSvtSimulationMaker.h"
193 #include "StDbUtilities/St_svtCorrectionC.h"
194 #include "StDbUtilities/St_svtHybridDriftVelocityC.h"
195 #include "StMcEvent/StMcSvtHitCollection.hh"
196 #include "StParticleDefinition.hh"
197 #include "StMcEvent.hh"
198 #include "StMcTrack.hh"
199 #include "StMcSvtHit.hh"
200 #include "StarMagField.h"
212 #define cTimeBinSize 0.04
213 #define cDefaultDriftVelocity 1.E-5*675000
214 #define cDiffusionConst 0.0035
215 #define cLifeTime 1000000.0
217 #define cTrapConst 5.0e-5 // Stephens tuning to real data
221 , mLifeTime(cLifeTime)
222 , mTrapConst(cTrapConst)
223 , mDiffusionConst(cDiffusionConst)
224 , mTimeBinSize(cTimeBinSize)
228 , mDefaultDriftVelocity(-1956)
231 , mDoEmbedding(kFALSE)
239 , mSvtSimPixelColl(0)
240 , mSvt8bitPixelColl(0)
241 , mSvtGeantHitColl(0)
246 LOG_DEBUG <<
"StSvtSimulationMaker::constructor"<<endm;
250 LOG_DEBUG <<
"StSvtSimulationMaker::constructor...END"<<endm;
254 StSvtSimulationMaker::~StSvtSimulationMaker()
256 LOG_DEBUG <<
"StSvtSimulationMaker::destructor"<<endm;
258 SafeDelete(mSvtAngles);
259 SafeDelete(mSvtSimulation);
260 SafeDelete(mElectronCloud);
261 SafeDelete(mCoordTransform);
263 LOG_DEBUG <<
"StSvtSimulationMaker::destructor...END"<<endm;
268 Int_t StSvtSimulationMaker::setConst(
double timBinSize,
double anodeSize)
270 mTimeBinSize = timBinSize ;
271 mAnodeSize = anodeSize;
284 void StSvtSimulationMaker::setTrappingConst(
double trapConst)
286 mTrapConst = trapConst;
290 void StSvtSimulationMaker::setDiffusionConst(
double diffConst)
292 mDiffusionConst = diffConst;
299 mSigOption = SigOption;
309 LOG_DEBUG <<
"In StSvtSimulationMaker::Init() ..."<<endm;
312 LOG_DEBUG <<
"In StSvtSimulationMaker::Init() -End"<<endm;
314 return StMaker::Init();
321 LOG_DEBUG <<
"StSvtSimulationMaker::InitRun()"<<endm;
326 if ((res=getSvtGeometry())!=
kStOk)
return res;
328 if ((res=getSvtDriftSpeeds())!=
kStOk)
return res;
330 if ((res=getSvtT0())!=
kStOk)
return res;
331 if ((res=getPedestalOffset())!=
kStOk)
return res;
337 mCoordTransform->setParamPointers(mSvtGeom, mConfig,mDriftSpeedColl,mT0);
342 mTimeBinSize = cTimeBinSize;
343 mAnodeSize = mSvtGeom->getAnodePitch()*10;
344 mDefaultDriftVelocity = cDefaultDriftVelocity;
347 mElectronCloud->setDriftVelocity(mDefaultDriftVelocity);
348 mElectronCloud->setElectronLifeTime(mLifeTime);
349 mElectronCloud->setDiffusionConst(mDiffusionConst);
350 mElectronCloud->setTrappingConst(mTrapConst);
352 mSvtSimulation->setOptions(mSigOption);
353 mSvtSimulation->setAnodeTimeBinSizes(mTimeBinSize , mAnodeSize);
354 mSvtSimulation->setDriftVelocity(mDefaultDriftVelocity);
355 mSvtSimulation->setElCloud(mElectronCloud);
357 LOG_INFO <<
"StSvtSimulationMaker::InitRun info:"<<endm;
358 LOG_INFO <<
" Anode size="<<mAnodeSize<<
" ,time bin size="<<mTimeBinSize<<endm;
359 LOG_INFO <<
" default drift velocity="<<mDefaultDriftVelocity<<endm;
360 LOG_INFO <<
" pedestal offset(from database)="<<mPedOffset<<endm;
361 LOG_INFO <<
" T0(from database)= "<<mT0->getT0(1)<<endm;
364 Float_t x[3] = {0,0,0};
366 StarMagField::Instance()->BField(x,b);
367 mBField = b[2]*tesla;
369 LOG_DEBUG <<
"StSvtSimulationMaker::InitRun()-END"<<endm;
371 return StMaker::InitRun(runumber);
376 Int_t StSvtSimulationMaker:: FinishRun(
int oldrunumber){
377 LOG_INFO <<
"StSvtSimulationMaker::FinishRun()"<<endm;
380 if ((set=GetDataSet(
"StSvtPixelData")))
delete set;
381 if ((set=GetDataSet(
"StSvt8bitPixelData")))
delete set;
383 LOG_INFO <<
"StSvtSimulationMaker::FinishRun() - END"<<endm;
384 return StMaker::FinishRun(oldrunumber);
390 void StSvtSimulationMaker::resetPixelData(){
395 if (mSvtSimPixelColl) {
396 for(
int Barrel = 1;Barrel <= mSvtSimPixelColl->getNumberOfBarrels();Barrel++) {
397 for (
int Ladder = 1;Ladder <= mSvtSimPixelColl->getNumberOfLadders(Barrel);Ladder++) {
398 for (
int Wafer = 1;Wafer <= mSvtSimPixelColl->getNumberOfWafers(Barrel);Wafer++) {
399 for(
int Hybrid = 1;Hybrid <= mSvtSimPixelColl->getNumberOfHybrids();Hybrid++){
401 int index = mSvtSimPixelColl->getHybridIndex(Barrel,Ladder,Wafer,Hybrid);
402 if( index < 0)
continue;
409 mSvtSimPixelColl->put_at(tmpPixels,index);
413 mSvt8bitPixelColl->put_at(tmp8bitPixels,index);
416 tmpPixels->setPedOffset(mPedOffset);
431 if (GetDataSet(
"StSvtPixelData"))
432 LOG_ERROR <<
"Error: Found StSvtSimPIxels in the chain - should have been deleted"<<endm;
436 mSvtSimPixelColl =
new StSvtData(mConfig->getConfiguration());
437 set->
SetObject((TObject*)mSvtSimPixelColl);
441 mSvt8bitPixelColl =
new StSvtData(mConfig->getConfiguration());
442 set->
SetObject((TObject*)mSvt8bitPixelColl);
444 mNumOfHybrids = mSvtSimPixelColl->getTotalNumberOfHybrids();
449 void StSvtSimulationMaker::setGeantData()
454 LOG_DEBUG <<
"Found StSvtGeantHits in the chain- replacing"<<endm;
462 if (mSvtGeantHitColl) {
463 LOG_ERROR <<
"!!!!!!m SvtGeantHitColl already exists in SvtSimulationMaker.cxx:setEval"<<endm;
466 mSvtGeantHitColl =
new StSvtData(mConfig->getConfiguration());
467 set->
SetObject((TObject*)mSvtGeantHitColl);
473 counter =
new int[mNumOfHybrids];
474 for(
int ii=0; ii<mNumOfHybrids; ii++){
481 Int_t StSvtSimulationMaker::getSvtGeometry()
485 dataSet = GetDataSet(
"StSvtGeometry");
487 LOG_ERROR <<
"BIG TROUBLE:No SVT geometry -impossible to run!!!!"<<endm;
494 LOG_ERROR <<
"BIG TROUBLE:No SVT geometry -impossible to run!!!!"<<endm;
503 Int_t StSvtSimulationMaker::getPedestalOffset()
507 dataSet = GetDataSet(
"StSvtDaq");
509 LOG_ERROR <<
"BIG TROUBLE:No DAQ parameters for SVT!!!!"<<endm;
516 LOG_ERROR <<
"BIG TROUBLE:No DAQ parameters are empty!!!!"<<endm;
521 mPedOffset=daq->getPedOffset();
527 Int_t StSvtSimulationMaker::getSvtDriftSpeeds()
529 mDriftSpeedColl =NULL;
531 dataSet = GetDataSet(
"StSvtDriftVelocity");
533 cout<<
"Warning: no SVT drift velocity data available - using default drift speed:"<<mDefaultDriftVelocity<<endl;
538 if (! mDriftSpeedColl) cout<<
"Warning: SVT drift velocity data empty - using default drift speed:"<<mDefaultDriftVelocity<<endl;
545 Int_t StSvtSimulationMaker::getSvtT0()
549 dataSet = GetDataSet(
"StSvtT0");
551 LOG_WARN <<
"no SVT T0 data available -using defalt T0 = 0"<<endm;
556 if (! mT0) LOG_WARN <<
" SVT T0 data empty - using default T0 = 0"<<endm;
562 Int_t StSvtSimulationMaker::getConfig()
566 dataSet = GetDataSet(
"StSvtConfig");
570 LOG_WARN <<
" No SvtConfig data set" << endm;
579 LOG_WARN <<
"SvtConfig data set is empty- seting default full configuration" << endm;
581 mConfig->setConfiguration(
"FULL");
593 int index = mSvtGeom->getWaferIndex(*wafId);
595 LOG_DEBUG <<
"StSvtSimulationMaker::ideal2RealTranslation: illegal wafId = " << *wafId << endl;
602 if (! waferGeom)
return kStSkip;
603 StThreeVectorD wafCent(waferGeom->x(0),waferGeom->x(1),waferGeom->x(2));
604 StThreeVectorD norm(waferGeom->n(0),waferGeom->n(1),waferGeom->n(2));
609 double s = tHelix.pathLength(wafCent, norm);
614 globalCor.setPosition(*pos);
617 if( mCoordTransform->IsOnWaferZ(*pos,*wafId) && mCoordTransform->IsOnWaferR(*pos,*wafId)){
619 x = tHelix.momentumAt(s,mBField);
630 int ladder = *wafId%100;
631 int layer = *wafId/1000;
632 int barrel = (layer-1)/2 +1;
634 for( iladder = ladder-1; iladder <= ladder+1; iladder++){
635 if( iladder==0)
continue;
636 if( iladder > mConfig->getNumberOfLadders(barrel))
break;
637 for(
int iwaf = 1; iwaf <= mConfig->getNumberOfWafers(barrel); iwaf++){
639 index = mSvtGeom->getWaferIndex(barrel, iladder, iwaf);
643 if (! waferGeom)
continue;
644 wafCent.setX(waferGeom->x(0));
645 wafCent.setY(waferGeom->x(1));
646 wafCent.setZ(waferGeom->x(2));
647 norm.setX(waferGeom->n(0));
648 norm.setY(waferGeom->n(1));
649 norm.setZ(waferGeom->n(2));
652 s = tHelix.pathLength(wafCent, norm);
657 globalCor.setPosition(*pos);
658 *wafId = 1000*mConfig->getLayer(index) + 100*iwaf + iladder;
659 if( mCoordTransform->IsOnWaferZ(*pos,*wafId) && mCoordTransform->IsOnWaferR(*pos,*wafId)){
661 x = tHelix.momentumAt(s,mBField);
671 iladder = mConfig->getNumberOfLadders(barrel);
672 for(
int iwaf = 1; iwaf <= mConfig->getNumberOfWafers(barrel); iwaf++){
674 index = mSvtGeom->getWaferIndex(barrel, iladder, iwaf);
678 if (! waferGeom)
continue;
679 wafCent.setX(waferGeom->x(0));
680 wafCent.setY(waferGeom->x(1));
681 wafCent.setZ(waferGeom->x(2));
682 norm.setX(waferGeom->n(0));
683 norm.setY(waferGeom->n(1));
684 norm.setZ(waferGeom->n(2));
687 s = tHelix.pathLength(wafCent, norm);
692 globalCor.setPosition(*pos);
693 *wafId = 1000*mConfig->getLayer(index) + 100*iwaf + iladder;
694 if( mCoordTransform->IsOnWaferZ(*pos,*wafId) &&
695 mCoordTransform->IsOnWaferR(*pos,*wafId)){
697 x = tHelix.momentumAt(s,mBField);
711 LOG_DEBUG <<
"In StSvtSimulationMaker::Make()" << endm;
713 int volId ,barrel, layer, ladder, wafer, hybrid;
736 mcEvent = (
StMcEvent*) GetDataSet(
"StMcEvent");
741 mcCol = mcEvent->svtHitCollection();
742 LOG_INFO <<
"mNumOfGeantHits = "<<mcCol->numberOfHits()<<endm;
743 for (
unsigned int iBarrel=0; iBarrel< mcCol->numberOfBarrels(); iBarrel++) {
744 for (
unsigned int iLadder=0; iLadder<mcCol->barrel(iBarrel)->numberOfLadders(); iLadder++) {
745 for (
unsigned int iWafer = 0; iWafer < mcCol->barrel(iBarrel)->ladder(iLadder)->numberOfWafers(); iWafer++) {
746 for (StMcSvtHitIterator iter = mcCol->barrel(iBarrel)->ladder(iLadder)->wafer(iWafer)->hits().begin();
747 iter != mcCol->barrel(iBarrel)->ladder(iLadder)->wafer(iWafer)->hits().end();
751 VecG.setX( mchit->position().x());
752 VecG.setY( mchit->position().y());
753 VecG.setZ( mchit->position().z());
754 mtm.setX(mchit->localMomentum().x());
755 mtm.setY(mchit->localMomentum().y());
756 mtm.setZ(mchit->localMomentum().z());
757 volId = 1000*mchit->layer()+100*mchit->wafer()+mchit->ladder();
764 Int_t iok = ideal2RealTranslation(&VecG, &mtm, (
double)mchit->parentTrack()->particleDefinition()->charge(), &volId);
765 if (iok !=
kStOK)
continue;
766 mchit->setPosition(VecG);
767 mchit->setLocalMomentum(mtm);
769 globalCor.setPosition(VecG);
770 mCoordTransform->operator()(globalCor,localCoord,volId);
773 if (! driftVel->p(localCoord.barrel(),localCoord.ladder(),localCoord.wafer(),localCoord.hybrid()))
continue;
777 mCoordTransform->operator()(localCoord,waferCoord);
778 mCoordTransform->operator()(waferCoord,localCoordb);
782 double diffx = localCoordb.position().x()- localCoord.position().x();
783 while( fabs(diffx) > 0.002){
785 told = waferCoord.timebucket();
786 tnew =waferCoord.timebucket()+ scale*waferCoord.timebucket()*(localCoordb.position().x()- localCoord.position().x())/localCoord.position().x();
787 if( told-tnew > 4) tnew = told-0.5;
788 else if( told-tnew < -4) tnew = told+0.5;
789 waferCoord.setTimeBucket(tnew);
790 mCoordTransform->operator()(waferCoord,localCoordb);
791 if( fabs(diffx) < fabs(localCoordb.position().x()- localCoord.position().x())){
792 waferCoord.setTimeBucket(told);
796 diffx = localCoordb.position().x()- localCoord.position().x();
800 if( mtry > 10000) diffx = 0;
805 VecL.setX(localCoord.position().x());
806 VecL.setY(localCoord.position().y());
807 VecL.setZ(localCoord.position().z());
811 barrel = waferCoord.barrel();
812 layer = waferCoord.layer(); ladder = waferCoord.ladder();
813 wafer = waferCoord.wafer(); hybrid = waferCoord.hybrid();
814 time = waferCoord.timebucket();
815 double driftTime=time - mT0->getT0();
816 anode = waferCoord.anode();
818 if(driftTime < 0.0 || time > 128.0 || anode < 0.0 || anode > 240.0)
819 { tmpBadCount++;
continue;}
825 static const int barrels[]={3,1,1,2,2};
827 if (layer<=4) barrel = barrels[layer];
829 if ( !strncmp(mConfig->getConfiguration(),
"Y1L", strlen(
"Y1L")) ) {
830 if ((wafer == 1) || (wafer == 2) || (wafer == 3))
836 if( 1000*layer+100*wafer+ladder != volId){
837 LOG_INFO <<
"trouble - skipping hit" << volId <<
"\t"<< mchit->position().x() <<
"\t"
838 << mchit->position().y() <<
"\t and our calc"<<
"\t" << layer <<
" "
839 << wafer <<
"\t" << ladder <<endm;
843 int index = mSvtSimPixelColl->getHybridIndex(barrel,ladder,wafer,hybrid);
844 if( index < 0)
continue;
847 mSvtAngles->calcAngles(mSvtGeom,mtm.x(),mtm.y(),mtm.z(),layer,ladder,wafer);
848 double theta = mSvtAngles->getTheta();
849 double phi = mSvtAngles->getPhi();
853 if (mDriftSpeedColl && mDriftSpeedColl->at(index)){
855 if (vd<=0) vd=mDefaultDriftVelocity;
860 vd = driftVel->DriftVelocity(barrel,ladder,wafer,hybrid)*1e-5;
862 if (vd <= 0)
continue;
864 double PasaShift=0.22/vd*25.;
866 mSvtSimulation->setDriftVelocity(vd);
867 double energy = mchit->dE()*1e9;
868 mSvtSimulation->doCloud(driftTime,energy,theta,phi,mchit->parentTrack()->key());
869 mSvtSimulation->fillBuffer(anode,time-PasaShift,svtSimDataPixels);
872 FillGeantHit(barrel,ladder,wafer,hybrid,&waferCoord,&VecG,&VecL,mSvtSimulation->getPeak(),mchit->parentTrack()->key());
882 LOG_INFO <<
"There's a problem no MC event" << endm;
884 int nSimDataPixels = mSvtSimPixelColl->size();
885 for (
int index=0;index<nSimDataPixels;index++) {
887 if (!svtSimDataPixels)
continue;
888 svtSimDataPixels->updateTruth();
890 LOG_DEBUG <<
"bad hits:"<<tmpBadCount<<endm;
891 LOG_DEBUG <<
"In StSvtSimulationMaker::Make()...END" << endm;
897 void StSvtSimulationMaker::FillGeantHit(
int barrel,
int ladder,
int wafer,
int hybrid,
903 int index = mSvtGeantHitColl->getHybridIndex(barrel,ladder,wafer,hybrid);
904 if (index < 0)
return;
909 mSvtGeantHitColl->put_at(geantHit,index);
912 geantHit->setGeantHit(counter[index],waferCoord);
913 geantHit->setLocalCoord(counter[index],VecL);
914 geantHit->setGlobalCoord(counter[index],VecG);
915 geantHit->setPeak(counter[index],peak);
916 geantHit->setTrackId(counter[index],idtrk);
918 geantHit->setNumOfHits(counter[index]);
923 void StSvtSimulationMaker::Clear(
const char*)
926 LOG_DEBUG <<
"In StSvtSimulationMaker::Clear" << endm;
930 mSvtGeantHitColl = NULL;
932 if (counter)
delete counter; counter=NULL;
936 LOG_DEBUG <<
"In StSvtSimulationMaker::Clear..END" << endm;
944 LOG_DEBUG <<
"In StSvtSimulationMaker::Finish()"<< endm;
955 LOG_DEBUG <<
"In StSvtSimulationMaker::Finish() ...END"<< endm;
virtual Int_t Init()
inherited maker routines
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
virtual void Clear(Option_t *option="")
User defined functions.
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
void setSvtPixelData()
create output data and put them into the chain
virtual Int_t InitRun(int runumber)
all database dependent data are read here
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
SVT Slow Simulator Simulates hits in SVT based on geant data and database information.
StSvtSimulationMaker(const char *name="SvtSimulator")
the only place where electron cloud expansioin constants are set
void setElectronLifeTime(double tLife)
only these three constants influence the physics of electron cloud expansion
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Int_t setOptions(int SigOption)
seting different options and configurations - for testing purposes
SVT electron cloud expansion routines Simulates electron cloud expansion inside of the silicon wafer...