StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_sls_Maker.cxx
1  /**************************************************************************
2  * Class : St_sls_maker.cxx
3  **************************************************************************
4  * $Id: St_sls_Maker.cxx,v 1.24 2017/04/26 20:15:49 perev Exp $
5  *
6  * $Log: St_sls_Maker.cxx,v $
7  * Revision 1.24 2017/04/26 20:15:49 perev
8  * Hide m_DataSet
9  *
10  * Revision 1.23 2015/08/06 17:46:53 smirnovd
11  * Removed unused local variables
12  *
13  * Revision 1.22 2013/11/19 14:48:55 jeromel
14  * Corrections for %d format use for long int
15  *
16  * Revision 1.21 2009/01/26 15:00:34 fisyak
17  * Take care about sector number packed in volume Id
18  *
19  * Revision 1.20 2008/08/12 22:48:38 bouchet
20  * retrieve positions and dimensions tables using Get methods
21  *
22  * Revision 1.19 2008/07/17 02:51:15 bouchet
23  * initialize StMcSsd hits collections
24  *
25  * Revision 1.18 2008/07/15 23:08:13 bouchet
26  * fix bug (1232) related to a segmentation fault to the SsdHitCollection
27  *
28  * Revision 1.17 2008/05/29 03:07:27 bouchet
29  * remove inactive variables;fix a potential memory leak
30  *
31  * Revision 1.16 2008/05/07 22:59:11 bouchet
32  * EmbeddingMaker:initial version ; modified reading of GEANT hits
33  *
34  * Revision 1.15 2008/01/15 14:42:51 bouchet
35  * Set a default value for uninitialized variables
36  *
37  * Revision 1.14 2007/04/28 17:56:59 perev
38  * Redundant StChain.h removed
39  *
40  * Revision 1.13 2007/03/21 17:19:56 fisyak
41  * use new StSsdBarrel
42  *
43  * Revision 1.12 2007/01/17 18:14:37 bouchet
44  * replace printf, cout statements with LOG statements
45  *
46  * Revision 1.11 2006/10/16 16:36:08 bouchet
47  * Unify classes : Remove StSlsStrip, StSlsPoint, StSpaStrip, StSpaNoise by the same classes used in StSsdPointMaker (StSsdStrip,StSsdPoint) ; The methods for these classes are in StSsdUtil
48  *
49  * Revision 1.10 2006/09/15 21:09:52 bouchet
50  * read the noise and pedestal from ssdStripCalib
51  *
52  * Revision 1.9 2005/05/13 15:08:58 bouchet
53  * reading svt/ssd tables
54  *
55  * Revision 1.8 2005/05/13 09:28:24 lmartin
56  * geant information read from g2t_ssd_hit table
57  *
58  * Revision 1.7 2005/05/13 08:39:33 lmartin
59  * CVS tags added
60  *
61  * Revision 1.6 2003/10/08 03:46:34 suire
62  * *** empty log message ***
63  *
64  * Revision 1.4 2002/03/25 20:06:43 suire
65  * Doxygen documentation, cleaning
66  *
67  *
68  **************************************************************************/
69 #include <Stiostream.h>
70 #include <stdlib.h>
71 #include "St_sls_Maker.h"
72 #include "TDataSetIter.h"
73 #include "TFile.h"
74 #include "StMessMgr.h"
75 
76 #include "StSsdUtil/StSsdBarrel.hh"
77 #include "StSsdUtil/StSsdPoint.hh"
78 #include "StSsdUtil/StSsdPointList.hh"
79 #include "StSsdUtil/StSsdStrip.hh"
80 #include "StSsdUtil/StSsdStripList.hh"
81 #include "tables/St_sls_strip_Table.h"
82 #include "tables/St_g2t_svt_hit_Table.h"
83 #include "tables/St_g2t_ssd_hit_Table.h"
84 #include "tables/St_ssdDimensions_Table.h"
85 //#include "tables/St_ssdWafersPosition_Table.h"
86 #include "tables/St_slsCtrl_Table.h"
87 #include "StSsdUtil/StSsdBarrel.hh"
88 
89 #include "StBFChain.h"
90 #include "StChain.h"
91 #include "StMaker.h"
92 
93 #include "tables/St_g2t_track_Table.h"
94 #include "StThreeVectorD.hh"
95 #include "StPhysicalHelixD.hh"
96 #include "SystemOfUnits.h"
97 #include "StarMagField.h"
98 #include "StMcEvent/StMcSsdHitCollection.hh"
99 #include "StMcEvent.hh"
100 #include "StEventTypes.h"
101 #include "StMcEventTypes.hh"
102 #include "StDAQMaker/StDAQReader.h"
103 #include "St_ObjectSet.h"
104 #include "StThreeVectorF.hh"
105 #include "StSsdDbMaker/StSsdDbMaker.h"
106 
107 ClassImp(St_sls_Maker)
108 St_sls_Maker::St_sls_Maker(const char *name):StMaker(name){
109  mHit = 0;
110  m_ctrl = 0;
111 };
112 //____________________________________________________________________________
113 St_sls_Maker::~St_sls_Maker(){ }
114 //_____________________________________________________________________________
115 Int_t St_sls_Maker::Init(){
116  if (IAttr(".histos")) {
117  hRejected = new TH1F("hRejected","hits after removal / hits GEANT",110,0,1.1);
118  }
119  return kStOk;
120 }
121 //_____________________________________________________________________________
122 Int_t St_sls_Maker::InitRun(Int_t runNumber) {
123  assert(StSsdBarrel::Instance());
124  LOG_DEBUG << " instance of barrel ... done " << endm;
125 
126  m_ctrl = gStSsdDbMaker->GetSlsCtrl();
127  m_dimensions = 0;
128  m_dimensions = gStSsdDbMaker->GetssdDimensions();
129  m_positions = 0;
130  m_positions = gStSsdDbMaker->GetssdWafersPos();
131 
132  if (!m_ctrl) {
133  LOG_ERROR << "No access to control parameters" << endm;
134  return kStFatal;
135  }
136  if ((!m_dimensions)||(!m_positions)) {
137  LOG_ERROR << "No access to geometry parameters" << endm;
138  return kStFatal;
139  }
140  if(m_positions){
141  LOG_DEBUG << " m_positions found " << endl;
142  positions = m_positions->GetTable();
143  N = m_positions->GetNRows();
144  LOG_DEBUG << " size is : " <<N << endl;
145  }
146 
147  Float_t center[3]={0,0,0};
148  Float_t B[3]={0,0,0};
149  StarMagField::Instance()->BField(center,B);
150  mBField = B[2]*kilogauss;
151  return kStOk;
152 }
153 //_____________________________________________________________________________
155 {
156  if (Debug()==true) {LOG_DEBUG << "Make() ..." << endm;}
157  // Create output tables
158 
159  ssdDimensions_st *dimensions = m_dimensions->GetTable();
160 
161  setSsdParameters(dimensions);
162  if(Debug()){
163  printSsdParameters();}
164 
165  Int_t res = 0;
166  St_sls_strip *sls_strip = new St_sls_strip("sls_strip",40000);
167  AddData(sls_strip);
168 
169  TDataSetIter geant(GetInputDS("geant"));
170  St_g2t_svt_hit *g2t_svt_hit = (St_g2t_svt_hit *) geant("g2t_svt_hit");
171  St_g2t_ssd_hit *g2t_ssd_hit = (St_g2t_ssd_hit *) geant("g2t_ssd_hit");
172 
173  //table is retrieved directly, not the structure
174  //slsCtrl_st *ctrl = m_ctrl->GetTable();
175 
176  LOG_INFO<<"#################################################"<<endm;
177  LOG_INFO<<"#### START OF SSD LAZY SIMULATOR ####"<<endm;
178  LOG_INFO<<"#### SSD BARREL INITIALIZATION ####"<<endm;
179  LOG_INFO<<"#### SSD WAFERS INITIALIZATION ####"<<endm;
180  Int_t nSsdHits = 0;
181  if (g2t_ssd_hit)
182  {
183  //nSsdHits = readPointFromTable(g2t_ssd_hit);
184  // Get g2t tracks
185  St_DataSet *g2t_tracks = GetDataSet("g2t_track");
186  St_DataSetIter g2t_track_it(g2t_tracks);
187  St_g2t_track *g2t_track = (St_g2t_track *) g2t_track_it.Find("g2t_track");
188  if(!g2t_track){
189  LOG_WARN <<" no track table , abort event because we cannot procede IdealTorealMethod()" << endm;
190  return kStErr;
191  }
192  LOG_INFO<<Form("Num of SSD geant hits =%ld",g2t_ssd_hit->GetNRows());
193  //nSsdHits = readPointFromTable(g2t_ssd_hit);
194  nSsdHits = readPointFromTableWithEmbedding(g2t_ssd_hit,g2t_track,N,positions);
195  if(g2t_ssd_hit->GetNRows())hRejected->Fill((float)nSsdHits/g2t_ssd_hit->GetNRows());
196  }
197  if (nSsdHits == 0)
198  {
199  if (g2t_svt_hit)
200  {
201  nSsdHits = readPointFromTable( g2t_svt_hit);
202  }
203  }
204  LOG_INFO <<"#### -> "<<nSsdHits<<" HITS READ FROM TABLE ####"<<endm;
205  StSsdBarrel::Instance()->convertGlobalFrameToOther();
206  Int_t inactiveHit = 0;
207  if (g2t_ssd_hit)
208  {
209  inactiveHit = removeInactiveHitInTable(g2t_ssd_hit);
210  }
211  else
212  {
213  if (g2t_svt_hit)
214  {
215  inactiveHit = removeInactiveHitInTable(g2t_svt_hit);
216  }
217  }
218  LOG_INFO<<"#### -> "<<inactiveHit<<" DEAD ZONE HITS REMOVED ####"<<endm;
219  //chargeSharingOverStrip(ctrl);
220  chargeSharingOverStrip(m_ctrl);
221  Int_t nSsdStrips = writeStripToTable(sls_strip);
222  sls_strip->Purge();
223  LOG_INFO<<"#### -> "<<nSsdStrips<<" FIRED STRIPS INTO TABLE ####"<<endm;
224  LOG_INFO<<"#### END OF SSD LAZY SIMULATOR ####"<<endm;
225  LOG_INFO<<"#################################################"<<endm;
226  StSsdBarrel::Instance()->Reset();// delete mySsd;
227  if (nSsdStrips) res = kStOK;
228 
229  if(res!=kStOK){
230  LOG_WARN<<"no output"<<endm;
231  return kStWarn;
232  }
233  if(Debug()==true){ LOG_DEBUG << "Make():end ... "<< endm;}
234  return kStOK;
235 }
236 //_____________________________________________________________________________
237 void St_sls_Maker::PrintInfo() {
238  if (Debug()==true){ StMaker::PrintInfo();}
239 }
240 //_____________________________________________________________________________
242  if (Debug()==true){LOG_DEBUG << "Finish() ... " << endm;}
243  return kStOK;
244 }
245 //________________________________________________________________________________
246 Int_t St_sls_Maker::readPointFromTable(St_g2t_ssd_hit *g2t_ssd_hit) {
247  g2t_ssd_hit_st *g2t = g2t_ssd_hit->GetTable();
248 
249  // LOG_INFO<< "NumberOfRows = " << g2t_ssd_hit->GetNRows() << " size " << g2t_ssd_hit->GetTableSize() << endm ;
250  // g2t_ssd_hit->Print(0,g2t_ssd_hit->GetNRows());
251 
252  Int_t minWaf = StSsdBarrel::Instance()->getSsdLayer()*1000;
253  Int_t currWafId = 0;
254  Int_t currWafNumb = 0;
255  Int_t currLadder = 0;
256  Int_t counter = 0;
257  Int_t i = 0 ;
258  Int_t j = 0 ;
259  // Float_t *p = new float[3];
260  Float_t p[3] = {0,0,0};
261  for (i = 0; i < g2t_ssd_hit->GetNRows() ; i++) {
262  currWafId=g2t[i].volume_id%10000;
263  if (currWafId > minWaf) {
264  counter++;
265  currLadder=StSsdBarrel::Instance()->idWaferToLadderNumb(currWafId);
266  currWafNumb=StSsdBarrel::Instance()->idWaferToWafer(currWafId);
267  for (j = 0; j<3; j++) {p[j] = g2t[i].p[j];}
268  StSsdBarrel::Instance()->mLadders[currLadder]->mWafers[currWafNumb]->
269  addHit(g2t[i].id, g2t[i].id, g2t[i].track_p, g2t[i].x, g2t[i].de, p);
270  }
271  }
272  return counter;
273 }
274 //________________________________________________________________________________
275 Int_t St_sls_Maker::removeInactiveHitInTable(St_g2t_ssd_hit *g2t_ssd_hit) {
276  g2t_ssd_hit_st *g2t = g2t_ssd_hit->GetTable();
277  StSsdPointList *inactiveHits = StSsdBarrel::Instance()->getInactiveHitList();
278  Int_t localSize = 0;
279  localSize=inactiveHits->getSize();
280  if (localSize)
281  {
282  Int_t firstSsdPoint=0;
283  Int_t iP1 = 0;
284  for (iP1 = 0; ((iP1 < g2t_ssd_hit->GetNRows())&&(g2t[iP1].volume_id%10000 < StSsdBarrel::Instance()->getSsdLayer()*1000)) ; iP1++)
285  firstSsdPoint=iP1;
286  firstSsdPoint++;
287  Int_t isG2tSorted = 1;
288  Int_t iP2 = 0;
289  for (iP2 = firstSsdPoint+1 ; (iP2 < g2t_ssd_hit->GetNRows())&&(isG2tSorted) ;iP2++)
290  {
291  if (g2t[iP2].id < g2t[iP2 - 1].id) isG2tSorted = 0;
292  }
293  StSsdPoint *currToDele = inactiveHits->first();
294  Int_t nDeleted = 0;
295  Int_t isAllRemove = 0;
296  if (isG2tSorted)
297  {
298  Int_t ipScan = 0;
299  Int_t ipKeep = firstSsdPoint;
300  for (ipScan = firstSsdPoint; (ipScan<g2t_ssd_hit->GetNRows()); ipScan++)
301  {
302  if ((!isAllRemove)&&(g2t[ipScan].id == currToDele->getNId()))
303  {
304  currToDele=inactiveHits->next(currToDele);
305  if (currToDele == 0) isAllRemove = 1;
306  nDeleted++;
307  }
308  else
309  {
310  g2t[ipKeep]=g2t[ipScan];
311  ipKeep++;
312  }
313  }
314  g2t_ssd_hit->SetNRows( g2t_ssd_hit->GetNRows() - nDeleted );
315  }
316  else
317  {
318  Int_t iLoop = 0;
319  for (iLoop = 0 ; (iLoop < localSize)&&(!isAllRemove); iLoop++)
320  {
321  Int_t ipScan = 0;
322  Int_t nLoopDeleted = 0;
323  for (ipScan = firstSsdPoint; ipScan < g2t_ssd_hit->GetNRows() ; ipScan++)
324  {
325  if (!isAllRemove)
326  {
327  if (g2t[ipScan].id == currToDele->getNId())
328  {
329  currToDele=inactiveHits->next(currToDele);
330  if (currToDele == 0)
331  {
332  isAllRemove = 1;
333  }
334  else
335  {
336  nDeleted++;
337  nLoopDeleted++;
338  }
339  }
340  }
341  g2t[ipScan]=g2t[ipScan + nLoopDeleted];
342  }
343  g2t_ssd_hit->SetNRows( g2t_ssd_hit->GetNRows() - nDeleted );
344  }
345  }
346  }
347  StSsdBarrel::Instance()->renumHitAfterRemove();
348  delete inactiveHits;
349  return localSize;
350 }
351 //________________________________________________________________________________
352 void St_sls_Maker::chargeSharingOverStrip(slsCtrl_st *ctrl)
353 {
354  StSsdBarrel::Instance()->convertToStrip(ctrl[0].pairCreationEnergy,
355  ctrl[0].nstripInACluster,
356  ctrl[0].parDiffP,
357  ctrl[0].parDiffN,
358  ctrl[0].parIndRightP,
359  ctrl[0].parIndRightN,
360  ctrl[0].parIndLeftP,
361  ctrl[0].parIndLeftN);
362 }
363 //________________________________________________________________________________
364 Int_t St_sls_Maker::writeStripToTable(St_sls_strip *sls_strip) {
365  sls_strip_st strip;
366 
367  Int_t currRecord = 0;
368 
369  for (Int_t iLad = 0; iLad < StSsdBarrel::Instance()->getNumberOfLadders(); iLad++)
370  for (Int_t iWaf = 0; iWaf < StSsdBarrel::Instance()->getNWaferPerLadder(); iWaf++) {
371  StSsdWafer *wafer = StSsdBarrel::Instance()->getLadder(iLad)->getWafer(iWaf);
372  //Int_t idCurrentWaf = StSsdBarrel::Instance()->waferNumbToIdWafer(iWaf);
373  Int_t idCurrentWaf = StSsdBarrel::Instance()->getSsdLayer()*1000 +((iWaf+1)*100)+(iLad+1);
374  StSsdStripList *stripP = wafer->getStripP();
375  StSsdStripList *stripN = wafer->getStripN();
376  StSsdStrip *pStripP = stripP->first();
377  Int_t iP = 0;
378  for (iP = 0; iP < stripP->getSize() ; iP++) {
379  strip.id = currRecord + 1;
380  strip.adc_count = pStripP->getDigitSig();
381  strip.noise_count = 0;
382  strip.id_strip = 10000*(10*pStripP->getNStrip() + 0)+idCurrentWaf;
383  strip.id_cluster = 0;
384  strip.N_hits = pStripP->getNHits();
385  strip.de = pStripP->getAnalogSig();
386  for (Int_t i = 0 ; i < 5 ; i++) {
387  strip.id_hit[i] = pStripP->getIdHit(i);
388  strip.id_mchit[i] = pStripP->getIdMcHit(i);
389  strip.id_mctrack[i] = pStripP->getIdMcTrack(i);
390  LOG_DEBUG<<Form("idwafer=%d strip_id=%d side P i=%d IdMcHit=%d IdMcTrack=%d signal(adc)=%d signal(GeV)=%f",
391  idCurrentWaf,pStripP->getNStrip(),i,pStripP->getIdMcHit(i),pStripP->getIdMcTrack(i),pStripP->getDigitSig(),pStripP->getAnalogSig())
392  <<endm;
393  }
394  sls_strip->AddAt(&strip);
395  currRecord++;
396  pStripP = stripP->next(pStripP);
397  }
398 
399  StSsdStrip *pStripN = stripN->first();
400  Int_t iN = 0;
401  for (iN = 0 ; iN < stripN->getSize() ; iN++) {
402  strip.id = currRecord + 1;
403  strip.adc_count = pStripN->getDigitSig();
404  strip.noise_count = 0;
405  strip.id_strip = 10000*(10*pStripN->getNStrip() + 1)+idCurrentWaf;
406  strip.id_cluster = 0;
407  strip.N_hits = pStripN->getNHits() ;
408  strip.de = pStripN->getAnalogSig();
409  for (Int_t i = 0 ; i < 5 ; i++) {
410  strip.id_hit[i] = pStripN->getIdHit(i);
411  strip.id_mchit[i] = pStripN->getIdMcHit(i);
412  strip.id_mctrack[i] = pStripN->getIdMcTrack(i);
413  LOG_DEBUG <<Form("idwafer=%d strip_id=%d side N i=%d IdMcHit=%d IdMcTrack=%d signal(adc)=%d signal(GeV)=%f",
414  idCurrentWaf,pStripN->getNStrip(),i,pStripN->getIdMcHit(i),pStripN->getIdMcTrack(i),pStripN->getDigitSig(),pStripN->getAnalogSig())
415  <<endm;
416  }
417  sls_strip->AddAt(&strip);
418  currRecord++;
419  pStripN = stripN->next(pStripN);
420  }
421  }
422  return currRecord;
423 }
424 //_______________________________________________________________
425 
426 Int_t St_sls_Maker::readPointFromTableWithEmbedding(St_g2t_ssd_hit *g2t_ssd_hit, St_g2t_track *g2t_track,Int_t N,ssdWafersPosition_st *positions){
427  StMcEvent* mcEvent = 0;
428  mcEvent = (StMcEvent*) GetDataSet("StMcEvent");
429 
430  StMcSsdHitCollection *mcCol = 0;
431  StMcSsdHitCollection *mcCol1 = 0;
432  if(mcEvent)
433  {
434  mcCol = mcEvent->ssdHitCollection();
435  if (!mcCol)
436  {
437  LOG_WARN <<"StSsdEmbeddingMaker -E- no SsdHitCollection!" << endm;
438  mcCol = new StMcSsdHitCollection;
439  mcEvent->setSsdHitCollection(mcCol);
440  LOG_WARN <<"Make() has added a non existing StSsdHitCollection" <<endm;
441  }
442  else {
443  //SafeDelete(mcCol);
444  //assert(mcEvent);
445  mcCol1 = new StMcSsdHitCollection;
446  mcEvent->setSsdHitCollection(mcCol1);
447  }
448  }
449 
450  g2t_ssd_hit_st *g2t = g2t_ssd_hit->GetTable();
451  g2t_track_st *g2tTrack = 0;
452  g2tTrack = g2t_track->GetTable();
453  LOG_DEBUG << "Size of track Table=" << g2t_track->GetNRows() << endm;
454  LOG_DEBUG << "Size of SSD Table=" << g2t_ssd_hit->GetNRows() << endm;
455  //ssdWafersPosition_st *positions = m_positions->GetTable();
456  if(Debug()){
457  for(Int_t i =0;i<N;i++)
458  {
459  for(Int_t ii=0;ii<3;ii++){
460  LOG_INFO <<"Id " << positions[i].id <<" drift["<<ii<<"] ="<< positions[i].driftDirection[ii]<< endm;
461  LOG_INFO <<" Transverse["<<ii<<"] ="<< positions[i].transverseDirection[ii]<< endm;
462  LOG_INFO <<" Id " << positions[i].id <<" normal["<<ii<<"] ="<< positions[i].normalDirection[ii]<< endm;
463  LOG_INFO <<" center["<<ii<<"] ="<< positions[i].centerPosition[ii]<< endm;
464  }
465  }
466  }
467  StThreeVector<double> VecG(0,0,0);
468  StThreeVector<double> VecL(0,0,0);
469  StThreeVector<double> mtm(0,0,0);
470  Double_t myVectG[3] = {0,0,0};
471  Double_t myVectL[3] = {0,0,0};
472  Int_t NumOfHits = 0;
473  Int_t foundGoodHits = 0;
474  Int_t currWafId = 0;
475  Int_t currLadder = 0;
476  Int_t currWafNumb = 0;
477  Int_t trackId = 0;
478  Int_t FinalLadder = 0;
479  Int_t FinalWafer = 0;
480  Int_t idWafer = 0;
481  Float_t Flag_Energy = 1.0;
482  N = m_positions->GetNRows();
483  NumOfHits = g2t_ssd_hit->GetNRows();
484  if (NumOfHits>0){
485  for (int j=0;j<NumOfHits ;j++)
486  {
487  Flag_Energy =1.0;
488  currWafId = g2t[j].volume_id%10000;
489  trackId = g2t[j].track_p;
490  if( currWafId < mSsdLayer*1000) continue; // ssd hit
491  currLadder = StSsdBarrel::Instance()->idWaferToLadderNumb(currWafId);
492  currWafNumb = StSsdBarrel::Instance()->idWaferToWafer(currWafId);
493  LOG_DEBUG <<"geant hit #"<<j<<" volumeID="<< currWafId << " x=" << g2t[j].x[0] << " y=" << g2t[j].x[1] << " z=" << g2t[j].x[2]<<endm;
494  VecG.setX(g2t[j].x[0]);
495  VecG.setY(g2t[j].x[1]);
496  VecG.setZ(g2t[j].x[2]);
497  mtm.setX(g2t[j].p[0]);
498  mtm.setY(g2t[j].p[1]);
499  mtm.setZ(g2t[j].p[2]);
500  for (Int_t i = 0; i < N; i++) // loop over the full wafer table now.
501  {
502  idWafer = positions[i].id;
503  if ((idWafer > mSsdLayer*1000)&&
504  (idWafer == currWafId)){ // find the good wafer
505  if(Debug()){
506  for(Int_t ii=0;ii<3;ii++){
507  LOG_INFO <<"Id " << idWafer <<" drift["<<ii<<"] ="<< positions[i].driftDirection[ii]<< endm;
508  LOG_INFO <<" Transverse["<<ii<<"] ="<< positions[i].transverseDirection[ii]<< endm;
509  LOG_INFO <<" Id " << idWafer <<" normal["<<ii<<"] ="<< positions[i].normalDirection[ii]<< endm;
510  LOG_INFO <<" center["<<ii<<"] ="<< positions[i].centerPosition[ii]<< endm;
511  }
512  }
513  LOG_DEBUG << " idWafer =" << idWafer << " TrackId="<<trackId <<" hit id="<<g2t[j].id <<endm;
514  Int_t iok = ideal2RealTranslation(&VecG,&mtm,(double)g2tTrack[trackId-1].charge,currWafId,i,positions,&FinalLadder,&FinalWafer);
515  if(iok==kStSkip){
516  LOG_DEBUG << "Not found correct wafer "<<endm;
517  Flag_Energy =-1.0;// we mark the energy as -1*energy for this hit : do not use hit
518  }
519  // fill stMcEvent
520  g2t[j].de = Flag_Energy*g2t[j].de;
521  //StMcSsdHit *mHit =0;
522  //mHit = new StMcSsdHit(&g2t[j]);
523  Int_t finalVolumeId = 7000+(FinalLadder+1)+(FinalWafer+1)*100;
524  LOG_DEBUG<<Form("New ladder=%d New Wafer=%d New volume id =%d",FinalLadder,FinalWafer,finalVolumeId) << endm;
525  g2t[j].volume_id = 10000*(g2t[j].volume_id/10000) + (long)finalVolumeId; // miss sector
526  StMcTrack *t = 0;
527  t = new StMcTrack(&(g2tTrack[trackId-1]));
528  //mHit = new StMcSsdHit(g2t[j].x,g2t[j].p,g2t[j].de,0,0,0,finalVolumeId,t);
529  mHit = new StMcSsdHit(&g2t[j]);
530  LOG_DEBUG<<Form("from mHit:ladder=%ld wafer=%ld energy =%f x=%f y=%f z=%f",mHit->ladder(),mHit->wafer(),mHit->dE(),mHit->position().x(),mHit->position().y(),mHit->position().z())<<endm;
531  mHit->setParentTrack(t);
532  //mHit->setVolumeId(finalVolumeId);
533  t->addSsdHit(mHit);
534  mcEvent->ssdHitCollection()->addHit(mHit);
535  LOG_DEBUG<<Form("check :finalVolumeid =%d fromhit ladder=%ld wafer=%ld ParentTrack=%ld",finalVolumeId,mHit->ladder(),mHit->wafer(),mHit->parentTrack()->key())<<endm;
536  if (iok != kStOK) continue;
537  foundGoodHits++;
538  //dump the 3-vector to Double_t[3] for MasterToLocal
539  myVectG[0] = VecG.x();
540  myVectG[1] = VecG.y();
541  myVectG[2] = VecG.z();
542  StSsdBarrel::Instance()->mLadders[currLadder]->mWafers[currWafNumb]->MasterToLocal(myVectG,myVectL);
543  //dump the local Double_t[3] to a 3-vector for the FillGeantHits method
544  VecL.setX(myVectL[0]);
545  VecL.setY(myVectL[1]);
546  VecL.setZ(myVectL[2]);
547  //########### fill the barrel with proper hits ##########
548  Float_t p[3],tempo[3];
549  for (Int_t jj = 0; jj<3; jj++) {p[jj] = g2t[j].p[jj];tempo[jj] = myVectG[jj];}
550  trackId = g2t[j].track_p;
551  LOG_DEBUG<<Form("Final Ladder=%d FinalWafer=%d geantId=%d xg=%f yg=%f zg=%f energy=%f trackId=%d",FinalLadder,FinalWafer,g2t[j].id,myVectG[0],myVectG[1],myVectG[2],g2t[j].de,trackId)<<endm;
552  StSsdBarrel::Instance()->mLadders[FinalLadder]->mWafers[FinalWafer]->addHit(g2t[j].id, g2t[j].id, trackId, tempo, g2t[j].de, p);
553  }
554  }
555  }
556  }
557  if(mcEvent){
558  LOG_DEBUG << Form("Size of collection =%ld",mcEvent->ssdHitCollection()->numberOfHits())<<endm;
559 }
560  return foundGoodHits;
561 }
562 
563 //_______________________________________________________________________
564 Int_t St_sls_Maker::idWaferToWaferNumb(Int_t idWafer)
565 {
566  // idwafer = layer*1000+waf*100+ladder
567  Int_t iW = (int)((idWafer - mSsdLayer*1000)/100);
568  Int_t iL = idWafer - mSsdLayer*1000 - iW*100;
569  return ((iL-1)*mNWaferPerLadder + iW -1);
570 }
571 //________________________________________________________________________
572 Int_t St_sls_Maker::idWaferToLadderNumb(Int_t idWafer)
573 {
574  // idwafer = layer*1000+waf*100+ladder
575  Int_t iW = (int)((idWafer - mSsdLayer*1000)/100);
576  Int_t iL = idWafer - mSsdLayer*1000 - iW*100;
577  return iL-1;
578 }
579 //_________________________________________________________________________
580 Int_t St_sls_Maker::waferNumbToIdWafer(Int_t waferNumb)
581 {
582  Int_t iL = 1+(int)((waferNumb)/mNLadder);
583  Int_t iW = waferNumb-((iL-1)*mNLadder)+1;
584  return mSsdLayer*1000 + iW*100 + iL;
585 }
586 //__________________________________________________________________________
587 void St_sls_Maker::setSsdParameters(ssdDimensions_st *geom_par){
588  mDimensions = geom_par;
589  mSsdLayer = 7;
590  mDetectorLargeEdge = 2.*geom_par[0].waferHalfActLength;
591  mDetectorSmallEdge = 2.*geom_par[0].waferHalfActWidth;
592  mNLadder = 20;
593  mNWaferPerLadder = geom_par[0].wafersPerLadder;
594  mNStripPerSide = geom_par[0].stripPerSide;
595  mStripPitch = geom_par[0].stripPitch;
596  mTheta = geom_par[0].stereoAngle;
597 }
598 //___________________________________________________________________________
599 void St_sls_Maker::printSsdParameters(){
600  LOG_INFO << "###Ladders = " <<mNLadder<<"###"<< endm;
601  LOG_INFO << "###Wafers per Ladder = " <<mNWaferPerLadder<<"###"<< endm;
602  LOG_INFO << "###half Active LargeEdge = " << mDetectorLargeEdge << "###" << endm;
603  LOG_INFO << "###half Active SmallEdge = " << mDetectorSmallEdge << "###" << endm;
604 }
605 //_____________________________________________________________________________
606 void St_sls_Maker::debugUnPeu() {
607  Int_t monladder,monwafer;
608  for(monladder=0;monladder<mNLadder;monladder++)
609  for(monwafer=0;monwafer<mNWaferPerLadder;monwafer++)
610  StSsdBarrel::Instance()->debugUnPeu(monladder,monwafer);
611 }
612 //_____________________________________________________________________________
613  int St_sls_Maker::IsOnWafer(const StThreeVector<double>& LocalPosition){
614  //Find out for a given z coord and Hardware pos is it on the wafer
615  if((LocalPosition[0] >(mDetectorLargeEdge/2.)) || (LocalPosition[0] < (-mDetectorLargeEdge/2.)) ||
616  ( LocalPosition[1]>(mDetectorSmallEdge/2.)) || (LocalPosition[1] < (-mDetectorSmallEdge/2.)))
617  return 0;
618  else return 1;
619  /*
620  if((LocalPosition[0] <(mDetectorLargeEdge/2.)) || (LocalPosition[0] > (-mDetectorLargeEdge/2.)) ||
621  (LocalPosition[1] <(mDetectorSmallEdge/2.)) || (LocalPosition[1] > (-mDetectorSmallEdge/2.)))
622  return 1;
623  return 0;
624  */
625  }
626 //____________________________________________________________________________
627 Int_t St_sls_Maker::ideal2RealTranslation(StThreeVector<double> *pos, StThreeVector<double> *mtm, double charge, int wafId, int index, ssdWafersPosition_st *positions,Int_t *IL,Int_t *IW){
628  StThreeVector<double> x(0,0,0);
629  // Get normal and center position of the wafer geom
630  StThreeVector<double> wafCent(0,0,0);
631  StThreeVector<double> wafNorm(0,0,0);
632  wafCent.setX(positions[index].centerPosition[0]);
633  wafCent.setY(positions[index].centerPosition[1]);
634  wafCent.setZ(positions[index].centerPosition[2]);
635  wafNorm.setX(positions[index].normalDirection[0]);
636  wafNorm.setY(positions[index].normalDirection[1]);
637  wafNorm.setZ(positions[index].normalDirection[2]);
638  Int_t Ladder = idWaferToLadderNumb(wafId);
639  Int_t Wafer = idWaferToWafer(wafId);
640  // Move helix of track from IDEAL geom to find where it hit REAL wafer geom
641  StPhysicalHelixD tHelix( *mtm, *pos, mBField, charge);
642  LOG_DEBUG << "pos going in : "<< *pos << endm;
643  double s = tHelix.pathLength(wafCent,wafNorm);
644  x = tHelix.at(s);
645  LOG_DEBUG << "Helix pathLength="<< s <<" x="<<x.x()<<" y="<<x.y()<<" z="<<x.z()<<endm;
646  pos->setX(x.x());
647  pos->setY(x.y());
648  pos->setZ(x.z());
649  LOG_DEBUG << "Track projection on Global x =" << pos->x() <<" y =" << pos->y() <<" z =" << pos->z() <<endm;
650  Double_t xg[3] = {0,0,0};
651  xg[0] = pos->x();
652  xg[1] = pos->y();
653  xg[2] = pos->z();
654  Double_t xl[3] = {0,0,0};
655  // get the local coordinate of the track projection to the real wafer
656  StSsdBarrel::Instance()->mLadders[Ladder]->mWafers[Wafer]->MasterToLocal(xg,xl);
657  if (Debug()){
658  for(Int_t i=0;i<3;i++){
659  LOG_DEBUG << "xg["<<i<<"] = "<<xg[i] << "--> to local --> xl["<<i<<"] = "<<xl[i] <<endm;}
660  }
661  if(IsOnWafer(xl))
662  {
663  LOG_DEBUG << " First Pass Coming out " << *pos << endm;
664  x = tHelix.momentumAt(s,mBField);
665  mtm->setX(x.x());
666  mtm->setY(x.y());
667  mtm->setZ(x.z());
668  *IL = Ladder;
669  *IW = Wafer;
670  return kStOK;
671  }
672  LOG_DEBUG <<"not found at the first pass, continue "<<endm;
673  // If the hit is now on a different wafer look for it by looping
674  // over one ladder before and one after
675  Int_t iladder,theLadder = 0;
676  StThreeVector<double> newx(0,0,0);
677  for( iladder = -1; iladder <= 1; iladder++){
678  theLadder = Ladder + iladder;
679  if( theLadder==20) theLadder=0;
680  else
681  if( theLadder==-1) theLadder=19;
682  for( Int_t iwaf = 0; iwaf < mNWaferPerLadder; iwaf++){
683  LOG_DEBUG << "Wafer ="<< iwaf << " Ladder="<<theLadder << endm;
684  wafId = 1000*mSsdLayer + 100*(iwaf+1) + (theLadder+1);
685  Int_t NewLadder = idWaferToLadderNumb(wafId);
686  Int_t NewWafer = idWaferToWafer(wafId);
687  index = idWaferToWaferNumb(wafId);
688  wafCent.setX(positions[index].centerPosition[0]);
689  wafCent.setY(positions[index].centerPosition[1]);
690  wafCent.setZ(positions[index].centerPosition[2]);
691  wafNorm.setX(positions[index].normalDirection[0]);
692  wafNorm.setY(positions[index].normalDirection[1]);
693  wafNorm.setZ(positions[index].normalDirection[2]);
694  double news = tHelix.pathLength(wafCent,wafNorm);
695  if(TMath::Abs(news)>5) continue;
696  newx = tHelix.at(news);
697  pos->setX(newx.x());
698  pos->setY(newx.y());
699  pos->setZ(newx.z());
700  Double_t XG[3]={0,0,0};
701  XG[0] = newx.x();
702  XG[1] = newx.y();
703  XG[2] = newx.z();
704  Double_t XL[3]={0,0,0};
705  StSsdBarrel::Instance()->mLadders[NewLadder]->mWafers[NewWafer]->MasterToLocal(XG,XL);
706  if(IsOnWafer(XL))
707  {
708  LOG_DEBUG << " after search, found it Coming out " << *pos << endm;
709  newx = tHelix.momentumAt(news,mBField);
710  mtm->setX(newx.x());
711  mtm->setY(newx.y());
712  mtm->setZ(newx.z());
713  *IL = NewLadder;
714  *IW = NewWafer;
715  return kStOk;
716  }
717  else{LOG_DEBUG <<" Not found wafer for this hit/track projection, will reject the hit"<<endm;}
718  }
719  }
720  return kStSkip;
721 }
722 //____________________________________________________________________________
723 void St_sls_Maker::Clear(Option_t *option)
724 {
725  LOG_DEBUG << "Clear()" <<endm;
726  StMaker::Clear();
727 }
728 //________________________________________________________________________________
StSsdStripList * getStripP()
Returns the P-side strip list attached to this wafer.
Definition: StSsdWafer.hh:103
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
StSsdStripList * getStripN()
Returns the N-side strip list attached to this wafer.
Definition: StSsdWafer.hh:104
virtual Int_t Make()
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
Definition: StMcTrack.hh:144
Definition: Stypes.h:49
Definition: Stypes.h:42
Definition: Stypes.h:40
virtual Int_t Finish()
virtual TDataSet * Find(const Char_t *path, TDataSet *rootset=0, Bool_t mkdir=kFALSE, Bool_t titleFlag=kFALSE)
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