StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtSimulationMaker.cxx
1  /***************************************************************************
2  *
3  * $Id: StSvtSimulationMaker.cxx,v 1.49 2013/03/26 15:56:00 genevb Exp $
4  *
5  * Author: Selemon Bekele
6  ***************************************************************************
7  *
8  * Description: Svt Slow Simulator Maker class
9  *
10  ***************************************************************************
11  * Revision 1.23 2004/04/08 15:11:27 caines
12  * Ensure array is initialised to zeros
13  *
14  * Revision 1.22 2004/04/06 20:18:19 caines
15  * Initialise variable counter in the constructor to NULL to avoid crash
16  *
17  * Revision 1.21 2004/03/30 21:27:12 caines
18  * Remove asserts from code so doesnt crash if doesnt get parameters it just quits with kStErr
19  *
20  * $Log: StSvtSimulationMaker.cxx,v $
21  * Revision 1.49 2013/03/26 15:56:00 genevb
22  * Replace agufld(x,b) with direct call to StarMagField::Instance()->BField(x,b)
23  *
24  * Revision 1.48 2013/02/18 16:30:42 fisyak
25  * gufld => agufld
26  *
27  * Revision 1.47 2010/09/25 16:17:50 caines
28  * Add iteration to transformation routines so local -> wafer followed by wafer->local come to same point, needed because of dirft velocity assumptions
29  *
30  * Revision 1.46 2010/09/22 13:44:25 caines
31  * Record is StMcHit the shifted hit position after caling ideal2real routines
32  *
33  * Revision 1.45 2010/08/27 17:46:28 perev
34  * WarnOff
35  *
36  * Revision 1.44 2009/06/28 04:04:06 baumgart
37  * Increase of trapping constant to compensate for changes in electron cloud shape
38  *
39  * Revision 1.43 2009/06/11 23:22:07 baumgart
40  * Decrease of cTrapConst to reflect proper time evolution of hits
41  *
42  * Revision 1.42 2009/02/21 14:18:45 caines
43  * change trapping const to better reproduce data
44  *
45  * Revision 1.41 2009/01/28 23:03:42 fisyak
46  * Fix wafId
47  *
48  * Revision 1.40 2009/01/22 23:19:21 fine
49  * Prptection against fo the crash
50  *
51  * Revision 1.39 2008/12/13 01:12:57 caines
52  * Check that ladder index not out of range in translation routine
53  *
54  * Revision 1.38 2008/11/07 20:42:06 caines
55  * Fix some mistakes in new way of initializing variables. lifetime was missing
56  *
57  * Revision 1.37 2008/10/21 21:13:30 fine
58  * Initialize the class data-members see bug #1294
59  *
60  * Revision 1.36 2008/10/21 21:05:51 fine
61  * Initialize the class data-members see bug #1294
62  *
63  * Revision 1.35 2007/12/24 17:37:19 fisyak
64  * Add protection from missing geometry
65  *
66  * Revision 1.34 2007/11/01 19:56:12 caines
67  * Added routines to move SVT hits from GEANT geometry to real geometry
68  *
69  * Revision 1.33 2007/07/12 20:18:18 fisyak
70  * read Db by deman
71  *
72  * Revision 1.32 2007/03/21 17:25:51 fisyak
73  * Ivan Kotov's drift velocities, TGeoHMatrix
74  *
75  * Revision 1.31 2005/10/21 02:46:07 caines
76  * Improve PASA shift to 220 microns to place hit residuals in MC closer to zero
77 
78  * Revision 1.30 2005/10/19 21:22:30 caines
79  * Make PASA shift 200 microns
80  *
81  * Revision 1.29 2005/10/18 18:59:24 caines
82  * Addtional code change for improving PASA shift
83  *
84  * Revision 1.28 2005/07/23 03:37:34 perev
85  * IdTruth + Cleanup
86  *
87  * Revision 1.26 2005/02/09 14:33:35 caines
88  * New electron expansion routine
89  *
90  * Revision 1.20 2004/02/24 15:53:22 caines
91  * Read all params from database
92  *
93  * Revision 1.19 2004/01/27 02:45:42 perev
94  * LeakOff
95  *
96  * Revision 1.18 2004/01/22 16:30:47 caines
97  * Getting closer to a final simulation
98  *
99  * Revision 1.17 2003/11/30 20:51:48 caines
100  * New version of embedding maker and make OnlSeqAdj a stand alone maker
101  *
102  * Revision 1.16 2003/11/15 20:24:29 caines
103  * fixes to remove warnings at compilation
104  *
105  * Revision 1.15 2003/11/14 17:33:19 caines
106  * DOnt read from pedmaker for now
107  *
108  * Revision 1.14 2003/11/13 16:24:59 caines
109  * Further improvements to get simulator looking like reality
110  *
111  * Revision 1.12 2003/07/31 19:18:10 caines
112  * Petrs improved simulation code
113  *
114  * Revision 1.10 2001/11/06 20:12:06 caines
115  * Add include for new compiler
116  *
117  * Revision 1.9 2001/08/13 15:34:18 bekele
118  * Debugging tools added
119  *
120  * Revision 1.7 2001/04/12 20:34:54 caines
121  * Add check for if nosvt hits present
122  *
123  * Revision 1.6 2001/04/03 15:24:24 caines
124  * Increase hit space size again
125  *
126  * Revision 1.5 2001/03/19 22:25:53 caines
127  * Catch wrong wafer ids more elegantly
128  *
129  * Revision 1.4 2001/03/15 15:12:09 bekele
130  * added a method to fill the whole SVT hybrid with background
131  *
132  * Revision 1.3 2001/02/18 00:10:42 caines
133  * Improve and use StSvtConfig
134  *
135  * Revision 1.2 2001/02/07 19:13:51 caines
136  * Small fixes to allow to run without setup from command line
137  *
138  * Revision 1.1 2000/11/30 20:47:49 caines
139  * First version of Slow Simulator - S. Bekele
140  *
141  **************************************************************************/
142 
143 
144 #include <string>
145 #include <cmath>
146 using namespace std;
147 
148 #include "St_DataSetIter.h"
149 #include "St_ObjectSet.h"
150 #include "StMessMgr.h"
151 #include "TH1.h"
152 #include "TH2.h"
153 #include "TString.h"
154 
155 #include "TFile.h"
156 #include "TDirectory.h"
157 #include "TNtuple.h"
158 
159 #include "StSequence.hh"
160 #include "StDbUtilities/StSvtCoordinateTransform.hh"
161 #include "StDbUtilities/StGlobalCoordinate.hh"
162 #include "StDbUtilities/StSvtLocalCoordinate.hh"
163 #include "StDbUtilities/StSvtWaferCoordinate.hh"
164 //#include "StSvtClassLibrary/StSvtHybridCollection.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"
183 
184 #include "StThreeVectorD.hh"
185 #include "StPhysicalHelixD.hh"
186 #include "SystemOfUnits.h"
187 
188 #include "tables/St_g2t_svt_hit_Table.h"
189 #include "tables/St_g2t_track_Table.h"
190 //#include "StSvtConversionTable.h"
191 
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"
201 
202 ClassImp(StSvtSimulationMaker)
203 
204 
212 #define cTimeBinSize 0.04
213 #define cDefaultDriftVelocity 1.E-5*675000
214 #define cDiffusionConst 0.0035
215 #define cLifeTime 1000000.0
216 //#define cTrapConst 4.0e-5
217 #define cTrapConst 5.0e-5 // Stephens tuning to real data
218 //___________________________________________________________________________
221  , mLifeTime(cLifeTime) // [us] //default =1000000.0
222  , mTrapConst(cTrapConst) // [us] //default =0
223  , mDiffusionConst(cDiffusionConst) // [mm**2/micro seconds] default=0.0035 (for silicon)
224  , mTimeBinSize(cTimeBinSize) // [us] //default =0.04
225  , mAnodeSize(-1956)
226  , mPedOffset(-1956) // not absolutely necesary to be already here - could be added in EmbeddingMaker, but it works
227  , mSigOption(0) // use both PASA codes, mNumOfHybrids(-1956) //!could be used to override number of simulated hybrids
228  , mDefaultDriftVelocity(-1956) // obsolete? - used if no database, error might be better
229  , mBField(-1956) // z component of BField;
230  , mConfig(0) // created in constructor (desctructor kills)
231  , mDoEmbedding(kFALSE) // embedding or plain simulation?
232  , mSvtAngles(0) // created in Init (desctructor kills)
233  , mElectronCloud(0)
234  , mSvtSimulation(0)
235  , mCoordTransform(0) // created in Init (desctructor kills)
236  , mSvtGeom(0) // read for each run in InitRun(owned by SvtDbMaker - don't kill)
237  , mDriftSpeedColl(0)
238  , mT0(0)
239  , mSvtSimPixelColl(0) // the simulated data - created for each run InitRun{in beginAnalyses}
240  , mSvt8bitPixelColl(0) // simulated final result written to 8 bits - would be cleaner if owned by OnlSeqAdj
241  , mSvtGeantHitColl(0) //
242  , counter(0)
243  , mNtFile(0)
244  , mNTuple(0)
245 {
246  LOG_DEBUG << "StSvtSimulationMaker::constructor"<<endm;
247 
248  //initial cleanup
249  mNumOfHybrids = 0;
250  LOG_DEBUG << "StSvtSimulationMaker::constructor...END"<<endm;
251 }
252 
253 //____________________________________________________________________________
254 StSvtSimulationMaker::~StSvtSimulationMaker()
255 {
256  LOG_DEBUG << "StSvtSimulationMaker::destructor"<<endm;
257 
258  SafeDelete(mSvtAngles);
259  SafeDelete(mSvtSimulation);
260  SafeDelete(mElectronCloud);
261  SafeDelete(mCoordTransform);
262 
263  LOG_DEBUG << "StSvtSimulationMaker::destructor...END"<<endm;
264 }
265 
266 //____________________________________________________________________________
267 
268 Int_t StSvtSimulationMaker::setConst(double timBinSize, double anodeSize)
269 {
270  mTimeBinSize = timBinSize ;
271  mAnodeSize = anodeSize;
272  return kStOK;
273 }
274 
275 
276 //____________________________________________________________________________
277 
279 {
280  mLifeTime = tLife; // [micro seconds]
281 
282 }
283 //____________________________________________________________________________
284 void StSvtSimulationMaker::setTrappingConst(double trapConst)
285 {
286  mTrapConst = trapConst; // [micro seconds]
287 }
288 
289 //____________________________________________________________________________
290 void StSvtSimulationMaker::setDiffusionConst(double diffConst)
291 {
292  mDiffusionConst = diffConst;
293 }
294 
295 //____________________________________________________________________________
296 //mainly for debugging
298 {
299  mSigOption = SigOption;
300 
301  return kStOK;
302 }
303 
304 
305 //____________________________________________________________________________
307 {
308 
309  LOG_DEBUG << "In StSvtSimulationMaker::Init() ..."<<endm;
310 
311 
312  LOG_DEBUG << "In StSvtSimulationMaker::Init() -End"<<endm;
313 
314  return StMaker::Init();
315 }
316 
317 //__________________________________________________________________________
319 Int_t StSvtSimulationMaker::InitRun(int runumber)
320 { //when the run changes
321  LOG_DEBUG << "StSvtSimulationMaker::InitRun()"<<endm;
322 
323  //read from database
324  Int_t res;
325  getConfig();
326  if ((res=getSvtGeometry())!=kStOk) return res;
327 #if 0
328  if ((res=getSvtDriftSpeeds())!=kStOk) return res;
329 #endif
330  if ((res=getSvtT0())!=kStOk) return res;
331  if ((res=getPedestalOffset())!=kStOk) return res;
332 
333  setSvtPixelData();
334  //Set up coordinate transformation
335  if (! mCoordTransform) mCoordTransform=new StSvtCoordinateTransform();
336 
337  mCoordTransform->setParamPointers(mSvtGeom, mConfig,mDriftSpeedColl,mT0);
338 
339  //mTimeBinSize = 1.E6/mSvtSrsPar->fsca; // Micro Secs
340  //mAnodeSize = mSvtSrsPar->pitch*10; // mm
341  // *****values hard wired for the time being - should be in database
342  mTimeBinSize = cTimeBinSize; // Micro Secs - Petr: this is quite accurate according to Dave
343  mAnodeSize = mSvtGeom->getAnodePitch()*10; // mm
344  mDefaultDriftVelocity = cDefaultDriftVelocity; // used only if there is no database
345  //set default drift speeds - if drift speed data exist it will be overriden later
346  if (! mElectronCloud) mElectronCloud = new StSvtElectronCloud();
347  mElectronCloud->setDriftVelocity(mDefaultDriftVelocity);
348  mElectronCloud->setElectronLifeTime(mLifeTime);
349  mElectronCloud->setDiffusionConst(mDiffusionConst);
350  mElectronCloud->setTrappingConst(mTrapConst);
351  if (! mSvtSimulation) mSvtSimulation = new StSvtSimulation();
352  mSvtSimulation->setOptions(mSigOption);
353  mSvtSimulation->setAnodeTimeBinSizes(mTimeBinSize , mAnodeSize);
354  mSvtSimulation->setDriftVelocity(mDefaultDriftVelocity);
355  mSvtSimulation->setElCloud(mElectronCloud);
356 
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;
362 
363  // Get BField;
364  Float_t x[3] = {0,0,0};
365  Float_t b[3];
366  StarMagField::Instance()->BField(x,b);
367  mBField = b[2]*tesla;
368 
369  LOG_DEBUG << "StSvtSimulationMaker::InitRun()-END"<<endm;
370 
371  return StMaker::InitRun(runumber);
372 }
373 
374 //____________________________________________________________________________
375 
376 Int_t StSvtSimulationMaker:: FinishRun(int oldrunumber){
377  LOG_INFO <<"StSvtSimulationMaker::FinishRun()"<<endm;
378 
379  TDataSet *set;
380  if ((set=GetDataSet("StSvtPixelData"))) delete set;
381  if ((set=GetDataSet("StSvt8bitPixelData"))) delete set;
382 
383  LOG_INFO <<"StSvtSimulationMaker::FinishRun() - END"<<endm;
384  return StMaker::FinishRun(oldrunumber);
385 }
386 
387 
388 //____________________________________________________________________________
389 
390 void StSvtSimulationMaker::resetPixelData(){
391  //this resets mSvtSimPixelColl and mSvt8bitPixelColl
392 
393  StSvtHybridPixelsD* tmpPixels;
394  StSvtHybridPixelsC* tmp8bitPixels;
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++){
400 
401  int index = mSvtSimPixelColl->getHybridIndex(Barrel,Ladder,Wafer,Hybrid);
402  if( index < 0) continue;
403 
404  tmpPixels = (StSvtHybridPixelsD*)mSvtSimPixelColl->at(index);
405  tmp8bitPixels = (StSvtHybridPixelsC*)mSvt8bitPixelColl->at(index);
406 
407  if(!tmpPixels) {
408  tmpPixels = new StSvtHybridPixelsD(Barrel, Ladder, Wafer, Hybrid);
409  mSvtSimPixelColl->put_at(tmpPixels,index);
410  }
411  if(!tmp8bitPixels) {
412  tmp8bitPixels = new StSvtHybridPixelsC(Barrel, Ladder, Wafer, Hybrid);
413  mSvt8bitPixelColl->put_at(tmp8bitPixels,index);
414  }
415 
416  tmpPixels->setPedOffset(mPedOffset);
417  tmpPixels->reset();
418 
419  }
420  }
421  }
422  }
423  }
424 }
425 
426 
427 //____________________________________________________________________________
430 { //add pixeldata to chain->.data
431  if (GetDataSet("StSvtPixelData"))
432  LOG_ERROR <<"Error: Found StSvtSimPIxels in the chain - should have been deleted"<<endm;
433 
434  St_ObjectSet *set = new St_ObjectSet("StSvtPixelData");
435  AddConst(set);
436  mSvtSimPixelColl = new StSvtData(mConfig->getConfiguration());
437  set->SetObject((TObject*)mSvtSimPixelColl);
438 
439  set = new St_ObjectSet("StSvt8bitPixelData");
440  AddConst(set);
441  mSvt8bitPixelColl = new StSvtData(mConfig->getConfiguration());
442  set->SetObject((TObject*)mSvt8bitPixelColl);
443 
444  mNumOfHybrids = mSvtSimPixelColl->getTotalNumberOfHybrids();
445 }
446 
447 
448 //__________________________________________________________________________________________________
449 void StSvtSimulationMaker::setGeantData()
450 {
451  St_ObjectSet* set=(St_ObjectSet*)GetDataSet("StSvtGeantHits");
452 
453  if (set) {
454  LOG_DEBUG <<"Found StSvtGeantHits in the chain- replacing"<<endm;
455  set->SetObject(0);
456  }
457  else{
458  set = new St_ObjectSet("StSvtGeantHits");
459  AddData(set);
460  }
461 
462  if (mSvtGeantHitColl) {
463  LOG_ERROR <<"!!!!!!m SvtGeantHitColl already exists in SvtSimulationMaker.cxx:setEval"<<endm;
464  } else{
465  //owned by the SvtData
466  mSvtGeantHitColl = new StSvtData(mConfig->getConfiguration());
467  set->SetObject((TObject*)mSvtGeantHitColl);
468  }
469 
470 //+++++++++++++++++
471 //for debugging purposes
472  if(!counter){
473  counter = new int[mNumOfHybrids];
474  for( int ii=0; ii<mNumOfHybrids; ii++){
475  counter[ii] = 0;
476  }
477  }
478 }
479 
480 //__________________________________________________________________________________________________
481 Int_t StSvtSimulationMaker::getSvtGeometry()
482 {
483 
484  St_DataSet* dataSet;
485  dataSet = GetDataSet("StSvtGeometry");
486  if (!dataSet){
487  LOG_ERROR <<"BIG TROUBLE:No SVT geometry -impossible to run!!!!"<<endm;
488  return kStFatal;
489  }
490 
491 
492  mSvtGeom = (StSvtGeometry*)dataSet->GetObject();
493  if (!mSvtGeom){
494  LOG_ERROR << "BIG TROUBLE:No SVT geometry -impossible to run!!!!"<<endm;
495  return kStFatal;
496  }
497 
498 
499  return kStOk;
500 }
501 
502 //__________________________________________________________________________________________________
503 Int_t StSvtSimulationMaker::getPedestalOffset()
504 {
505 
506  St_DataSet* dataSet;
507  dataSet = GetDataSet("StSvtDaq");
508  if (!dataSet){
509  LOG_ERROR <<"BIG TROUBLE:No DAQ parameters for SVT!!!!"<<endm;
510  return kStFatal;
511  }
512 
513 
514  StSvtDaq *daq = (StSvtDaq*)dataSet->GetObject();
515  if (daq==NULL){
516  LOG_ERROR << "BIG TROUBLE:No DAQ parameters are empty!!!!"<<endm;
517  return kStFatal;
518  }
519 
520 
521  mPedOffset=daq->getPedOffset();
522 
523  return kStOk;
524 }
525 #if 0
526 //____________________________________________________________________________
527 Int_t StSvtSimulationMaker::getSvtDriftSpeeds()
528 {
529  mDriftSpeedColl =NULL;
530  St_DataSet* dataSet;
531  dataSet = GetDataSet("StSvtDriftVelocity");
532  if (!dataSet){
533  cout<<"Warning: no SVT drift velocity data available - using default drift speed:"<<mDefaultDriftVelocity<<endl;
534  return kStErr;
535  } //this might be obsolete, maybe it's better to give an error instead of running on
536 
537  mDriftSpeedColl = (StSvtHybridCollection*)dataSet->GetObject();
538  if (! mDriftSpeedColl) cout<<"Warning: SVT drift velocity data empty - using default drift speed:"<<mDefaultDriftVelocity<<endl;
539 
540  return kStOk;
541 }
542 #endif
543 
544 //____________________________________________________________________________
545 Int_t StSvtSimulationMaker::getSvtT0()
546 {
547  mT0=NULL;
548  St_DataSet* dataSet;
549  dataSet = GetDataSet("StSvtT0");
550  if (!dataSet){
551  LOG_WARN <<"no SVT T0 data available -using defalt T0 = 0"<<endm;
552  return kStErr;
553  } //this might be obsolete, maybe it's better to give an error instead of running on
554 
555  mT0 = (StSvtT0*)dataSet->GetObject();
556  if (! mT0) LOG_WARN <<" SVT T0 data empty - using default T0 = 0"<<endm;
557 
558  return kStOk;
559 }
560 
561 //____________________________________________________________________________
562 Int_t StSvtSimulationMaker::getConfig()
563 {
564  mConfig=NULL;
565  St_DataSet *dataSet = NULL;
566  dataSet = GetDataSet("StSvtConfig");
567 
568  if (!dataSet)
569  {
570  LOG_WARN <<" No SvtConfig data set" << endm;
571  dataSet = new St_ObjectSet("StSvtConfig");
572  AddConst(dataSet);
573  mConfig=NULL;
574  }
575 
576  mConfig=((StSvtConfig*)(dataSet->GetObject()));
577 
578  if (!mConfig) {
579  LOG_WARN <<"SvtConfig data set is empty- seting default full configuration" << endm;
580  mConfig=new StSvtConfig();
581  mConfig->setConfiguration("FULL");
582  dataSet->SetObject(mConfig);
583  }
584 
585  return kStOk;
586 }
587 
588 //____________________________________________________________________________
589 Int_t StSvtSimulationMaker::ideal2RealTranslation( StThreeVector<double> *pos, StThreeVector<double> *mtm, double charge, int *wafId){
590  StGlobalCoordinate globalCor(0,0,0);
592  // Find wafer geometry of wafer track passed through in Ideal Geom
593  int index = mSvtGeom->getWaferIndex(*wafId);
594  if (index < 0) {
595  LOG_DEBUG << "StSvtSimulationMaker::ideal2RealTranslation: illegal wafId = " << *wafId << endl;
596  return kStSkip;
597  }
598  //cout << "pos going in : " << *pos << endl;
599 
600  // Get normal and center position of the REAL wafer geom
601  StSvtWaferGeometry* waferGeom = (StSvtWaferGeometry*)mSvtGeom->at(index);
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));
605 
606  // Move helix of track from IDEAL geom to find where it hit REAL wafer geom
607 
608  StPhysicalHelixD tHelix( *mtm, *pos, mBField, charge);
609  double s = tHelix.pathLength(wafCent, norm);
610  x = tHelix.at(s);
611  pos->setX(x.x());
612  pos->setY(x.y());
613  pos->setZ(x.z());
614  globalCor.setPosition(*pos);
615 
616 
617  if( mCoordTransform->IsOnWaferZ(*pos,*wafId) && mCoordTransform->IsOnWaferR(*pos,*wafId)){
618  //cout << " Coming out " << *pos << endl;
619  x = tHelix.momentumAt(s,mBField);
620  mtm->setX(x.x());
621  mtm->setY(x.y());
622  mtm->setZ(x.z());
623  return kStOk;
624  }
625 
626 
627  // If the hit is now on a different wafer look for it by looping
628  // over one ladder before and one after
629 
630  int ladder = *wafId%100;
631  int layer = *wafId/1000;
632  int barrel = (layer-1)/2 +1;
633  int iladder;
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++){
638  //wafId = 1000*layer+ 100*iwaf + iladder;
639  index = mSvtGeom->getWaferIndex(barrel, iladder, iwaf);
640 
641  // Get normal and center position of the REAL wafer geom
642  waferGeom = (StSvtWaferGeometry*)mSvtGeom->at(index);
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));
650 
651  // Move helix of track from IDEAL geom to find where it hit REAL wafer geom
652  s = tHelix.pathLength(wafCent, norm);
653  x = tHelix.at(s);
654  pos->setX(x.x());
655  pos->setY(x.y());
656  pos->setZ(x.z());
657  globalCor.setPosition(*pos);
658  *wafId = 1000*mConfig->getLayer(index) + 100*iwaf + iladder;
659  if( mCoordTransform->IsOnWaferZ(*pos,*wafId) && mCoordTransform->IsOnWaferR(*pos,*wafId)){
660  //cout << " Coming out " << *pos << endl;
661  x = tHelix.momentumAt(s,mBField);
662  mtm->setX(x.x());
663  mtm->setY(x.y());
664  mtm->setZ(x.z());
665  return kStOk;
666  }
667  }
668  }
669 
670  if( ladder ==1){
671  iladder = mConfig->getNumberOfLadders(barrel);
672  for( int iwaf = 1; iwaf <= mConfig->getNumberOfWafers(barrel); iwaf++){
673  //wafId = 1000*layer+ 100*iwaf + iladder;
674  index = mSvtGeom->getWaferIndex(barrel, iladder, iwaf);
675 
676  // Get normal and center position of the REAL wafer geom
677  waferGeom = (StSvtWaferGeometry*)mSvtGeom->at(index);
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));
685 
686  // Move helix of track from IDEAL geom to find where it hit REAL wafer geom
687  s = tHelix.pathLength(wafCent, norm);
688  x = tHelix.at(s);
689  pos->setX(x.x());
690  pos->setY(x.y());
691  pos->setZ(x.z());
692  globalCor.setPosition(*pos);
693  *wafId = 1000*mConfig->getLayer(index) + 100*iwaf + iladder;
694  if( mCoordTransform->IsOnWaferZ(*pos,*wafId) &&
695  mCoordTransform->IsOnWaferR(*pos,*wafId)){
696  //cout << " Coming out " << *pos << endl;
697  x = tHelix.momentumAt(s,mBField);
698  mtm->setX(x.x());
699  mtm->setY(x.y());
700  mtm->setZ(x.z());
701  return kStOk;
702  }
703  }
704  }
705  //cout << " Coming out " << *pos << endl;
706  return kStSkip;
707 }
708 //____________________________________________________________________________
710 {
711  LOG_DEBUG << "In StSvtSimulationMaker::Make()" << endm;
712 
713  int volId ,barrel, layer, ladder, wafer, hybrid;
714  // Int_t NumOfHitsPerHyb=0;
715  StThreeVector<double> VecG(0,0,0);
716  StThreeVector<double> VecL(0,0,0);
717  StThreeVector<double> mtm(0,0,0);
718 
719 
720  StSvtHybridPixelsD *svtSimDataPixels;
721 
722  //########## initiating data structures ##########################
723  resetPixelData();
724  setGeantData(); //if this removed geant data need to be dealocated in Clear()
725 
726  StSvtWaferCoordinate waferCoord (0,0,0,0,0,0);
727  StSvtLocalCoordinate localCoord (0,0,0), localCoordb(0,0,0);
728  StGlobalCoordinate globalCor(0,0,0);
729 
730  St_svtHybridDriftVelocityC *driftVel = St_svtHybridDriftVelocityC::instance();
731  assert(driftVel);
732 
733  int tmpBadCount=0;
734 
735  StMcEvent* mcEvent = 0;
736  mcEvent = (StMcEvent*) GetDataSet("StMcEvent");
737  StMcSvtHitCollection *mcCol = 0;
738  // StMcSvtHitCollection *mcCol1 = 0;
739  if(mcEvent)
740  {
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();
748  iter++) {
749  StMcSvtHit *mchit = dynamic_cast<StMcSvtHit *> (*iter);
750 
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();
758 
759  // Translate hit position from IDEAL geom coords to REAL geom coords in
760  // global coordinates
761  // cout << "Going in : " << VecG << endl;
762 
763 
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);
768 
769  globalCor.setPosition(VecG);
770  mCoordTransform->operator()(globalCor,localCoord,volId);
771 
772 
773  if (! driftVel->p(localCoord.barrel(),localCoord.ladder(),localCoord.wafer(),localCoord.hybrid())) continue;
774 
775  // need to djust drift time because the drift velocity assumptions are different in the conversion routines
776  // to and from the wafer coordinate.
777  mCoordTransform->operator()(localCoord,waferCoord);
778  mCoordTransform->operator()(waferCoord,localCoordb);
779  double tnew, told;
780  int mtry=0;
781  double scale = 1;
782  double diffx = localCoordb.position().x()- localCoord.position().x();
783  while( fabs(diffx) > 0.002){
784 
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);
793  scale *= 0.5;
794  }
795  else{
796  diffx = localCoordb.position().x()- localCoord.position().x();
797  }
798  // cout << "try "<< mtry << " " << scale << " " << diffx << " " << localCoord.position() << " " << localCoordb.position() << " " << told << " " << tnew << endl;
799  mtry++;
800  if( mtry > 10000) diffx = 0;
801 
802  }
803  // cout << "Final best guess " << "try "<< mtry << " " << diffx << " " << scale << " " << told << " " << tnew << endl;
804 
805  VecL.setX(localCoord.position().x());
806  VecL.setY(localCoord.position().y());
807  VecL.setZ(localCoord.position().z());
808 
809  //mCoordTransform->operator()(localCoord,waferCoord);
810  double anode,time;
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();
817 
818  if(driftTime < 0.0 || time > 128.0 || anode < 0.0 || anode > 240.0)
819  { tmpBadCount++; continue;}
820 #if 0
821 
822 
823  //########### get barrel and ladder numbers correctly #################
824 
825  static const int barrels[]={3,1,1,2,2};
826  barrel = 3;
827  if (layer<=4) barrel = barrels[layer];
828 
829  if ( !strncmp(mConfig->getConfiguration(), "Y1L", strlen("Y1L")) ) {
830  if ((wafer == 1) || (wafer == 2) || (wafer == 3))
831  ladder = 2;
832  }
833 
834  //if(Debug()) mNTuple->Fill(time,anode,trk_st[j].x[0],trk_st[j].x[1],trk_st[j].x[2],0 ,0,0,0,0,0);
835 #endif
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;
840  continue;
841  }
842 
843  int index = mSvtSimPixelColl->getHybridIndex(barrel,ladder,wafer,hybrid);
844  if( index < 0) continue;
845  svtSimDataPixels = (StSvtHybridPixelsD*)mSvtSimPixelColl->at(index);
846  if (! mSvtAngles) mSvtAngles = new StSvtAngles();
847  mSvtAngles->calcAngles(mSvtGeom,mtm.x(),mtm.y(),mtm.z(),layer,ladder,wafer);
848  double theta = mSvtAngles->getTheta();
849  double phi = mSvtAngles->getPhi();
850  //seting drift speed for simulation
851  double vd=-1;
852 #if 0
853  if (mDriftSpeedColl && mDriftSpeedColl->at(index)){
854  vd = ((StSvtHybridDriftVelocity*)mDriftSpeedColl->at(index))->getV3(1);
855  if (vd<=0) vd=mDefaultDriftVelocity;
856  else vd=vd*1e-5;
857  }
858  //cout<<"drift velocity used: = "<<vd<<" (default would be "<<mDefaultDriftVelocity<<")"<<endl;
859 #else
860  vd = driftVel->DriftVelocity(barrel,ladder,wafer,hybrid)*1e-5;
861 #endif
862  if (vd <= 0) continue;
863  // double PasaShift=0.1/vd*25.; //100 um shift from pasa
864  double PasaShift=0.22/vd*25.; //220 um shift from pasa
865 
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);
870 
871  if (Debug()) {
872  FillGeantHit(barrel,ladder,wafer,hybrid,&waferCoord,&VecG,&VecL,mSvtSimulation->getPeak(),mchit->parentTrack()->key());
873  }
874 
875 
876  }
877  }
878  }
879  }
880  }
881  else
882  LOG_INFO << "There's a problem no MC event" << endm;
883 
884  int nSimDataPixels = mSvtSimPixelColl->size();
885  for (int index=0;index<nSimDataPixels;index++) {
886  svtSimDataPixels = (StSvtHybridPixelsD*)mSvtSimPixelColl->at(index);
887  if (!svtSimDataPixels) continue;
888  svtSimDataPixels->updateTruth();
889  }
890  LOG_DEBUG <<"bad hits:"<<tmpBadCount<<endm;
891  LOG_DEBUG << "In StSvtSimulationMaker::Make()...END" << endm;
892  return kStOK;
893 }
894 
895 
896 //____________________________________________________________________________
897 void StSvtSimulationMaker::FillGeantHit(int barrel, int ladder, int wafer, int hybrid,
899  StThreeVector<double>* VecL, double peak,int idtrk)
900 {
901  StSvtGeantHits* geantHit;
902 
903  int index = mSvtGeantHitColl->getHybridIndex(barrel,ladder,wafer,hybrid);
904  if (index < 0) return;
905 
906  geantHit = (StSvtGeantHits*)mSvtGeantHitColl->at(index);
907  if(!geantHit) { //actually, it should be empty
908  geantHit = new StSvtGeantHits(barrel,ladder,wafer,hybrid);
909  mSvtGeantHitColl->put_at(geantHit,index);
910  }
911 
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);
917  ++counter[index];
918  geantHit->setNumOfHits(counter[index]);
919 }
920 
921 
922 //_____________________________________________________________________________
923 void StSvtSimulationMaker::Clear(const char*)
924 {
925 
926  LOG_DEBUG << "In StSvtSimulationMaker::Clear" << endm;
927 
928 
929  //all will be deleted by StMaker::Clear()
930  mSvtGeantHitColl = NULL;
931 
932  if (counter) delete counter; counter=NULL;
933 
934  StMaker::Clear();
935 
936  LOG_DEBUG << "In StSvtSimulationMaker::Clear..END" << endm;
937 }
938 
939 
940 //____________________________________________________________________________
941 
943 {
944  LOG_DEBUG << "In StSvtSimulationMaker::Finish()"<< endm;
945 
946  /*
947  if (Debug()&&(mNtFile)) {
948  mNtFile->Write();
949  mNtFile->Close();
950  }
951  */
952  //mSvtSimulation->closeFiles();
953  //mElectronCloud->closeFiles();
954 
955  LOG_DEBUG << "In StSvtSimulationMaker::Finish() ...END"<< endm;
956  return kStOK;
957 }
958 
959 //____________________________________________________________________________
960 
961 
962 
virtual Int_t Init()
inherited maker routines
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:480
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)
Definition: TObjectSet.h:59
Definition: Stypes.h:49
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Definition: Stypes.h:40
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
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
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...