StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSsdBarrel.cc
1 // $Id: StSsdBarrel.cc,v 1.21 2015/08/06 17:46:53 smirnovd Exp $
2 //
3 // $Log: StSsdBarrel.cc,v $
4 // Revision 1.21 2015/08/06 17:46:53 smirnovd
5 // Removed unused local variables
6 //
7 // Revision 1.20 2014/12/05 16:43:01 smirnovd
8 // Deleted pointless print statement
9 //
10 // Revision 1.19 2014/12/05 16:42:54 smirnovd
11 // Removed commented code
12 //
13 // Revision 1.18 2014/10/18 19:31:56 smirnovd
14 // Revert "1st commit" asked by Jonathan
15 //
16 // Revision 1.16 2009/11/09 22:33:03 bouchet
17 // bug 1679 : declaration of size and initialization of arrays
18 //
19 // Revision 1.15 2009/10/29 19:21:14 fine
20 // Add fix me please message
21 //
22 // Revision 1.14 2009/10/29 18:37:21 fine
23 // Fix me: assert(tempo.size() == 5);
24 //
25 // Revision 1.13 2009/10/29 18:34:25 fine
26 // Fix FindMcHit signature
27 //
28 // Revision 1.12 2009/02/23 21:10:40 bouchet
29 // increase NSaturationSignal to reflect the energy increase of the GEANT hit
30 //
31 // Revision 1.11 2008/10/20 19:30:32 bouchet
32 // add methods for the calculation of quality
33 //
34 // Revision 1.10 2008/07/16 21:00:37 bouchet
35 // default writePointToContainer : no quality hits calculation
36 //
37 // Revision 1.9 2008/05/07 22:48:34 bouchet
38 // calculation of quality of hits used embedding
39 //
40 // Revision 1.8 2008/04/12 14:22:36 bouchet
41 // Add a method to fill with constant noise and pedestal
42 //
43 // Revision 1.7 2008/01/11 10:40:37 bouchet
44 // Use of the wafer configuration table
45 //
46 // Revision 1.6 2007/08/02 19:34:13 bouchet
47 // bug fixed for trackReferenceCount
48 //
49 // Revision 1.5 2007/07/14 13:53:45 bouchet
50 // add default pedestal/noise ; noise value is 60/16 = 3.75 adc
51 //
52 // Revision 1.4 2007/07/12 17:08:08 bouchet
53 // add method to decode new ssdNoise Table
54 //
55 // Revision 1.3 2007/03/27 23:11:48 bouchet
56 // Add a method to use the gain calibration for the Charge Matching between pulse of p and n sides
57 //
58 // Revision 1.2 2007/03/21 17:20:40 fisyak
59 // use TGeoHMatrix for coordinate transformation
60 //
61 // Revision 1.1 2006/10/16 16:43:29 bouchet
62 // StSsdUtil regroups now methods for the classes StSsdStrip, StSsdCluster and StSsdPoint
63 //
64 // Revision 1.22 2006/09/15 21:03:14 bouchet
65 // id_mctrack is using for setIdTruth and propagated to the hit
66 //
67 // Revision 1.21 2006/05/06 00:53:06 fisyak
68 // Add local coordinate to StEvent
69 //
70 // Revision 1.20 2006/01/18 22:49:22 jeromel
71 // Removed latest change (no time to check new method)
72 //
73 // Revision 1.18 2005/12/23 21:33:17 perev
74 // Some defence for 1/0 added
75 //
76 // Revision 1.17 2005/12/20 13:47:14 lmartin
77 // better hw position encoding in writePointToContainer (matching the new decoding in StEvent)
78 //
79 // Revision 1.16 2005/12/20 10:53:17 lmartin
80 // ReadNoiseFromTable method modified to ignore rows with id=0
81 //
82 // Revision 1.15 2005/12/07 20:41:54 perev
83 // (int) added. WarnOff
84 //
85 // Revision 1.14 2005/08/11 13:51:38 lmartin
86 // PrintStripDetails, PrintPackageDetails and PrintPointDetails methods added
87 //
88 // Revision 1.13 2005/08/11 08:13:08 lmartin
89 // ssdStripCalib table new format included
90 //
91 // Revision 1.12 2005/06/24 10:19:38 lmartin
92 // preventing crashes if ssdStripCalib is missing
93 //
94 // Revision 1.11 2005/04/25 14:13:23 bouchet
95 // new method makeScfCtrlHistograms and makeScmCtrlHistograms and Clusternoise is coded as a float
96 //
97 // Revision 1.10 2005/04/23 08:56:20 lmartin
98 // physics and pedestal data processing separated
99 //
100 // Revision 1.9 2005/03/22 13:45:02 lmartin
101 // new member mActiveLadders added
102 //
103 // Revision 1.8 2005/03/22 10:57:18 lmartin
104 // hardware position information fully implemented
105 //
106 // Revision 1.7 2005/03/18 14:57:49 lmartin
107 // readNoiseFromTable methods modified to transmit the pedestal
108 //
109 // Revision 1.6 2005/03/18 14:04:06 lmartin
110 // missing CVS header added
111 //
112 
113 #include "StSsdUtil/StSsdBarrel.hh"
114 
115 #include "TFile.h"
116 #include "StEvent.h"
117 #include "StSsdHit.h"
118 #include "StSsdHitCollection.h"
119 #include "StarClassLibrary/StThreeVectorF.hh"
120 
121 #include "tables/St_spa_strip_Table.h"
122 #include "tables/St_ssdPedStrip_Table.h"
123 #include "tables/St_scf_cluster_Table.h"
124 #include "tables/St_scm_spt_Table.h"
125 #include "tables/St_sdm_calib_db_Table.h"
126 #include "tables/St_ssdDimensions_Table.h"
127 #include "tables/St_ssdConfiguration_Table.h"
128 #include "tables/St_ssdWafersPosition_Table.h"
129 #include "tables/St_ssdStripCalib_Table.h"
130 #include "tables/St_slsCtrl_Table.h"
131 #include "tables/St_sls_strip_Table.h"
132 #include "tables/St_spa_strip_Table.h"
133 #include "StSsdUtil/StSsdLadder.hh"
134 #include "StSsdUtil/StSsdWafer.hh"
135 #include "StSsdUtil/StSsdClusterControl.h"
136 #include "StSsdDynamicControl.h"
137 #include "StSsdStripList.hh"
138 #include "StSsdStrip.hh"
139 #include "StSsdUtil/StSsdClusterList.hh"
140 #include "StSsdUtil/StSsdCluster.hh"
141 #include "StSsdUtil/StSsdPointList.hh"
142 #include "StSsdUtil/StSsdPoint.hh"
143 #include "SystemOfUnits.h"
144 #include "StarMagField.h"
145 #include "TMath.h"
146 #include "StMessMgr.h"
147 
148 #include "tables/St_ssdGainCalibWafer_Table.h"
149 #include "tables/St_ssdNoise_Table.h"
150 
151 #include "tables/St_ssdWaferConfiguration_Table.h"
152 #include "StMcEvent/StMcSsdHitCollection.hh"
153 #include "StMcEvent.hh"
154 #include "StEventTypes.h"
155 #include "StMcEventTypes.hh"
156 
157 #include "TDataSetIter.h"
158 
159 StSsdBarrel* StSsdBarrel::fSsdBarrel = 0;
160 //________________________________________________________________________________
164 StSsdBarrel::StSsdBarrel(ssdDimensions_st *dimensions, ssdConfiguration_st *config ) : mDebug(0)
165 {
166  memset (first, 0, last-first);
167  fSsdBarrel = this;
168  setSsdParameters(dimensions);
169  // Set the Lorentz shift for holes and electrons
170  setLorentzShift(dimensions);
171  if (config) {
172  mNLadder = config[0].nMaxLadders;
173  for (Int_t i=0;i<mNLadder;i++) {
174  mActiveLadders[i]=1;
175  if (config && config[0].ladderIsPresent[i]==0)
176  mActiveLadders[i]=0;
177  }
178  }
179  mLadders = new StSsdLadder*[mNLadder];
180  for (Int_t iLad=0; iLad < mNLadder; iLad++){
181  mLadders[iLad] = new StSsdLadder(iLad,mSsdLayer,mNWaferPerLadder,mNStripPerSide);
182  if (Debug()) mLadders[iLad]->SetDebug(Debug());
183  }
184 }
185 //________________________________________________________________________________
186 StSsdBarrel::~StSsdBarrel(){for (Int_t iLad = 0 ; iLad < mNLadder; iLad++) delete mLadders[iLad]; fSsdBarrel = 0;}
187 //________________________________________________________________________________
188 void StSsdBarrel::setSsdParameters(ssdDimensions_st *geom_par){
189  mDimensions = geom_par;
190  mSsdLayer = 7; // all layers : 1->7
191  mDetectorLargeEdge = 2.*geom_par[0].waferHalfActLength;
192  mDetectorSmallEdge = 2.*geom_par[0].waferHalfActWidth;
193  mNLadder = 20;
194  mNWaferPerLadder = geom_par[0].wafersPerLadder;
195  mNStripPerSide = geom_par[0].stripPerSide;
196  mStripPitch = geom_par[0].stripPitch;
197  mTheta = geom_par[0].stereoAngle;
198 }
199 //________________________________________________________________________________
200 void StSsdBarrel::setLorentzShift(ssdDimensions_st *geom_par){
201  Float_t center[3];
202  Float_t B[3];
203  center[0] = 0.0;
204  center[1] = 0.0;
205  center[2] = 0.0;
206  B[0] = 0.0;
207  B[1] = 0.0;
208  B[2] = 0.0;
209  //we take the BField at the point (0,0,0)
210  StarMagField::Instance()->BField(center,B);
211  // 03/06/2007 : test : use the values from CMS
212  Float_t scale = 1.61;
213  Float_t tan_theta_h = scale*TMath::ATan(TMath::Tan(21*2*TMath::Pi()/360)*(B[2]/40.));
214  Float_t tan_theta_e = scale*TMath::ATan(TMath::Tan( 8*2*TMath::Pi()/360)*(B[2]/40.));
215  mShift_hole = geom_par[0].waferHalfThickness*tan_theta_h;
216  mShift_elec = geom_par[0].waferHalfThickness*tan_theta_e;
217 }
218 //________________________________________________________________________________
219 
220 void StSsdBarrel::debugUnPeu (Int_t monladder, Int_t monwafer){
221  for (Int_t i=0;i<this->getNumberOfLadders();i++)
222  {
223  if (this->mLadders[i]->getLadderNumb()==monladder)
224  {
225  cout<<" Ladder "<<monladder<<" found"<<endl;
226  this->mLadders[i]->debugUnPeu(monwafer);
227  }
228  }
229 }
230 //______________________________________________________________
231 void StSsdBarrel::initLadders(St_ssdWafersPosition *wafpos) {for (Int_t iLad = 0; iLad < mNLadder; iLad++) mLadders[iLad]->initWafers(wafpos);}
232 //________________________________________________________________________________
233 void StSsdBarrel::Reset() {for (Int_t iLad = 0; iLad < mNLadder; iLad++) mLadders[iLad]->Reset();}
234 //________________________________________________________________________________
235 Int_t StSsdBarrel::readStripFromTable(St_spa_strip *spa_strip){
236  spa_strip_st *strip = spa_strip->GetTable();
237 
238  Int_t NumberOfStrip = 0;
239  Int_t idWaf = 0;
240  Int_t iWaf = 0;
241  Int_t iLad = 0;
242  Int_t nStrip = 0;
243  Int_t iSide = 0;
244  Float_t sigma = 3.0;
245  Int_t iPedestal = 120;
246  Int_t idMcHit[5] = {0,0,0,0,0};
247  Int_t idMcTrack[5] = {0,0,0,0,0};
248  Int_t e = 0;
249  for (Int_t i = 0 ; i < spa_strip->GetNRows(); i++)
250  {
251  nStrip = (int)(strip[i].id_strip/100000.);
252  idWaf = strip[i].id_strip-10000*((int)(strip[i].id_strip/10000.));
253  iWaf = idWaferToWafer(idWaf);
254  iLad = (int)(idWaf - mSsdLayer*1000 - (iWaf+1)*100 - 1);
255  iSide = (strip[i].id_strip - nStrip*100000 - idWaf)/10000;
256  for (e = 0 ; e < 5;e++) {
257  idMcHit[e] = strip[i].id_mchit[e];
258  idMcTrack[e] = strip[i].id_mctrack[e];
259  }
260  StSsdStrip *newStrip = new StSsdStrip(nStrip, strip[i].adc_count, sigma, iPedestal, idMcHit,idMcTrack);
261  mLadders[iLad]->mWafers[iWaf]->addStrip(newStrip, iSide);
262  }
263  NumberOfStrip = spa_strip->GetNRows();
264  return NumberOfStrip;
265 }
266 //________________________________________________________________________________
267 Int_t StSsdBarrel::writeNoiseToFile(St_spa_strip *spa_strip){
268  spa_strip_st *strip = spa_strip->GetTable();
269  St_ssdStripCalib *stripCal = new St_ssdStripCalib("ssdStripCalib",spa_strip->GetNRows());
270  ssdStripCalib_st noise_strip;
271  for (Int_t i = 0 ; i < spa_strip->GetNRows(); i++)
272  {
273  noise_strip.id=strip[i].id_strip;
274  noise_strip.pedestals=(unsigned char) strip[i].id_mchit[0];
275  noise_strip.rms=(unsigned char) strip[i].adc_count;
276  stripCal->AddAt(&noise_strip);
277  }
278  TFile f1("ssdStripCalib.root","NEW");
279  stripCal->Write();
280  f1.Close();
281  return spa_strip->GetNRows();
282 }
283 //-----------------------------------------------------------------------------------------
284 Int_t StSsdBarrel::writeNewNoiseToFile3(St_ssdPedStrip *spa_ped_strip, char myLabel[]){
285  char *name =new char[100] ;
286  ssdPedStrip_st *strip = spa_ped_strip->GetTable();
287  St_ssdNoise *StripCal = new St_ssdNoise("ssdNoise",spa_ped_strip->GetNRows());
288  ssdNoise_st temp[320];
289  memset(temp, 0, 320*sizeof(ssdNoise_st));
290  Int_t idWaf = 0;
291  Int_t iWaf = 0;
292  Int_t iLad = 0;
293  Int_t nStrip = 0;
294  Int_t iSide = 0;
295  Int_t wafer = 0;
296  Int_t N = spa_ped_strip->GetNRows();
297  for (Int_t i=0; i< N;i++) {
298  if (strip[i].id_strip>0 && strip[i].id_strip<=76818620) {
299  nStrip = (int)(strip[i].id_strip/100000.);
300  idWaf = strip[i].id_strip-10000*((int)(strip[i].id_strip/10000.));
301  iWaf = (int)((idWaf - mSsdLayer*1000)/100 - 1);
302  iLad = (int)(idWaf - mSsdLayer*1000 - (iWaf+1)*100 - 1);
303  iSide = (strip[i].id_strip - nStrip*100000 - idWaf)/10000;
304  wafer = iLad*mNWaferPerLadder +iWaf;
305  if (iSide == 0) temp[wafer].rmsp[nStrip-1] = (unsigned char)strip[i].noise;
306  if (iSide == 1) temp[wafer].rmsn[nStrip-1] = (unsigned char)strip[i].noise;
307  }
308  }
309  for(Int_t i=0;i<320;i++) {
310  temp[i].id = i;
311  StripCal->AddAt(&temp[i]);
312  }
313  sprintf(name,"%s%s%s","ssdNoise.",myLabel,".root");
314  TFile f1(name,"RECREATE","SSD ped and noise file",9);
315  StripCal->Write();
316  f1.Close();
317  return spa_ped_strip->GetNRows();
318 }
319 //________________________________________________________________________________
320 /*
321  Method to read pedestal data and save them into a root file
322 */
323 Int_t StSsdBarrel::writeNoiseToFile(St_ssdPedStrip *spa_ped_strip, char myLabel[]){
324  char *name =new char[100] ;
325  ssdPedStrip_st *strip = spa_ped_strip->GetTable();
326  St_ssdStripCalib *stripCal = new St_ssdStripCalib("ssdStripCalib",spa_ped_strip->GetNRows());
327  ssdStripCalib_st noise_strip;
328  for (Int_t i = 0 ; i < spa_ped_strip->GetNRows(); i++)
329  {
330  noise_strip.id=strip[i].id_strip;
331  noise_strip.pedestals= (unsigned char) strip[i].pedestal;
332  noise_strip.rms=(unsigned char) strip[i].noise;
333  stripCal->AddAt(&noise_strip);
334  }
335  sprintf(name,"%s%s%s","ssdStripCalib.",myLabel,".root");
336  TFile f1(name,"RECREATE","SSD ped and noise file",9);
337  stripCal->Write();
338  f1.Close();
339  return spa_ped_strip->GetNRows();
340 }
341 //________________________________________________________________________________
345 Int_t StSsdBarrel::readNoiseFromTable(St_sdm_calib_db *spa_noise, StSsdDynamicControl *dynamicControl){
346  sdm_calib_db_st *noise = spa_noise->GetTable();
347 
348  Int_t NumberOfNoise = 0;
349  Int_t idWaf = 0;
350  Int_t iWaf = 0;
351  Int_t iLad = 0;
352  Int_t nStrip = 0;
353  Int_t iSide = 0;
354  for (Int_t i = 0 ; i < spa_noise->GetNRows(); i++)
355  {
356  nStrip = (int)(noise[i].id_strip/100000.);
357  idWaf = noise[i].id_strip-10000*((int)(noise[i].id_strip/10000.));
358  iWaf = idWaferToWafer(idWaf);
359  iLad = (int)(idWaf - mSsdLayer*1000 - (iWaf+1)*100 - 1);
360  iSide = (noise[i].id_strip - nStrip*100000 - idWaf)/10000;
361  mLadders[iLad]->mWafers[iWaf]->setPedestalSigmaStrip(nStrip, iSide,0, noise[i].n_sigma, dynamicControl);
362  }
363 
364  NumberOfNoise = spa_noise->GetNRows();
365  return NumberOfNoise;
366 }
367 //________________________________________________________________________________
371 Int_t StSsdBarrel::readNoiseFromTable(St_ssdStripCalib *strip_calib, StSsdDynamicControl *dynamicControl){
372  ssdStripCalib_st *noise = strip_calib->GetTable();
373 
374  Int_t NumberOfNoise = 0;
375  Int_t idWaf = 0;
376  Int_t iWaf = 0;
377  Int_t iLad = 0;
378  Int_t nStrip = 0;
379  Int_t iSide = 0;
380  for (Int_t i = 0 ; i < strip_calib->GetNRows(); i++)
381  {
382  if (noise[i].id>0 && noise[i].id<=76818620) {
383  nStrip = (int)(noise[i].id/100000.);
384  idWaf = noise[i].id-10000*((int)(noise[i].id/10000.));
385  iWaf = idWaferToWafer(idWaf);
386  iLad = (int)(idWaf - mSsdLayer*1000 - (iWaf+1)*100 - 1);
387  iSide = (noise[i].id - nStrip*100000 - idWaf)/10000;
388  mLadders[iLad]->mWafers[iWaf]->setPedestalSigmaStrip(nStrip, iSide, noise[i].pedestals, noise[i].rms, dynamicControl);
389  NumberOfNoise++;
390  }
391  }
392  return NumberOfNoise;
393 }
394 //---------------------------------------------------------------------------------------------
395 Int_t StSsdBarrel::readNoiseDefault(StSsdDynamicControl *dynamicControl){
396  Int_t rms = 48 ;
397  // the noise is coded as 16*rms then for each strip, noise = 60/16 = 3.75 adc
398  Int_t ped = 120 ;
399  Int_t NumberOfNoise = 0;
400  for(Int_t i=0;i<mNLadder;i++)
401  {
402  for(Int_t j=0;j<mNWaferPerLadder;j++)
403  {
404  for(Int_t k=0;k<mNStripPerSide;k++)
405  {
406  for(Int_t iSide=0;iSide<2;iSide++)
407  {
408  mLadders[i]->mWafers[j]->setPedestalSigmaStrip(k+1,iSide,ped,rms,dynamicControl);
409  NumberOfNoise++;
410  }
411  }
412  }
413  }
414  return NumberOfNoise;
415 }
416 //________________________________________________________________________________
420 Int_t StSsdBarrel::readNoiseFromTable(St_ssdNoise *strip_noise, StSsdDynamicControl *dynamicControl){
421  ssdNoise_st *noise = strip_noise->GetTable();
422 
423  Int_t NumberOfNoise = 0;
424  Int_t iWaf = 0;
425  Int_t iLad = 0;
426  Int_t nStrip = 0;
427  Int_t iSide = 0;
428  Int_t pedestal = 120;//constant, not used later
429  printf("size of m_noise3 table = %d\n",(int)strip_noise->GetNRows());
430  for (Int_t i = 0 ; i < strip_noise->GetNRows(); i++)
431  {
432  iWaf = noise[i].id-(noise[i].id/mNWaferPerLadder)*mNWaferPerLadder;
433  iLad = noise[i].id/16;
434  for(nStrip=0;nStrip<mNStripPerSide;nStrip++){
435  iSide=0;
436  mLadders[iLad]->mWafers[iWaf]->setPedestalSigmaStrip(nStrip+1, iSide, pedestal, noise[i].rmsp[nStrip], dynamicControl);
437  NumberOfNoise++;
438  iSide=1;
439  mLadders[iLad]->mWafers[iWaf]->setPedestalSigmaStrip(nStrip+1, iSide, pedestal, noise[i].rmsn[nStrip], dynamicControl);
440  NumberOfNoise++;
441  }
442  }
443  return NumberOfNoise;
444 }
445 //________________________________________________________________________________
446 
447 Int_t StSsdBarrel::readClusterFromTable(St_scf_cluster *scf_cluster){
448  scf_cluster_st *cluster = scf_cluster->GetTable();
449 
450  Int_t NumberOfCluster = 0;
451  Int_t idWaf = 0;
452  Int_t iWaf = 0;
453  Int_t iLad = 0;
454  Int_t nCluster = 0;
455  Int_t nPCluster = 0;
456  Int_t nNCluster = 0;
457  Int_t iSide = 0;
458  Int_t idMcHit[5] = {0,0,0,0,0};
459  Int_t e = 0;
460  Int_t nStrip = 0;
461  Int_t nFirstStrip = 0;
462  Int_t nFirstAdc = 0;
463  Int_t nLastAdc = 0;
464  Int_t nAdcCount = 0;
465  Float_t nNoiseCount = 0;
466  Float_t nStripMean = 0;
467  Int_t nFlag = 0;
468 
469  for (Int_t i = 0 ; i < scf_cluster->GetNRows(); i++)
470  {
471  nCluster = (int)(cluster[i].id_cluster/100000.);
472  idWaf = (cluster[i].id_cluster-10000*((int)(cluster[i].id_cluster/10000.)));
473  iSide = (cluster[i].id_cluster-idWaf-nCluster*100000)/10000;
474  iWaf = idWaferToWafer(idWaf);
475  iLad = (int)(idWaf - mSsdLayer*1000 - (iWaf+1)*100 - 1);
476  nFirstStrip = (int)(cluster[i].first_strip/100000.);
477  nStrip = cluster[i].n_strip;
478  nFirstAdc = cluster[i].first_adc_count;
479  nLastAdc = cluster[i].last_adc_count;
480  nAdcCount = cluster[i].adc_count;
481  nNoiseCount = cluster[i].noise_count;
482  nStripMean = cluster[i].strip_mean;
483  nFlag = cluster[i].flag;
484  for (e = 0 ; e < 5; e++) idMcHit[e] = cluster[i].id_mchit[e];
485  StSsdCluster *newCluster = new StSsdCluster(nCluster, nFirstStrip, nStrip, nAdcCount, nFirstAdc, nLastAdc, nNoiseCount, nStripMean, nFlag, idMcHit);
486  if (iSide == 0)
487  {nPCluster++;}
488  else
489  {nNCluster++;}
490  mLadders[iLad]->mWafers[iWaf]->addCluster(newCluster, iSide);
491  }
492 
493  NumberOfCluster = scf_cluster->GetNRows();
494  return NumberOfCluster;
495 }
496 //________________________________________________________________________________
497 Int_t StSsdBarrel::writeClusterToTable(St_scf_cluster *scf_cluster){
498  scf_cluster_st cluster;
499  Int_t currRecord = 0;
500  Int_t i = 0;
501 
502  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
503  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder ; iWaf++)
504  {
505  Int_t idCurrentWaf = mSsdLayer*1000 + (iWaf+1)*100 + (iLad+1);
506  StSsdClusterList *clusterP = mLadders[iLad]->mWafers[iWaf]->getClusterP();
507  StSsdClusterList *clusterN = mLadders[iLad]->mWafers[iWaf]->getClusterN();
508 
509  StSsdCluster *pClusterP = clusterP->first();
510  while (pClusterP)
511  {
512  cluster.id = currRecord + 1;
513  cluster.id_cluster = 10000*(10*pClusterP->getNCluster() + 0)+idCurrentWaf;
514  cluster.first_strip = 10000*(10*pClusterP->getFirstStrip()+ 0)+idCurrentWaf;
515  cluster.n_strip = pClusterP->getClusterSize();
516  cluster.adc_count = pClusterP->getTotAdc();
517  cluster.first_adc_count = pClusterP->getFirstAdc();
518  cluster.last_adc_count = pClusterP->getLastAdc();
519  cluster.noise_count = (int)pClusterP->getTotNoise();
520  cluster.flag = pClusterP->getFlag();
521  cluster.strip_mean = pClusterP->getStripMean();
522  for (i = 0 ; i < 5 ; i++)
523  cluster.id_mchit[i] = pClusterP->getIdMcHit(i);
524  scf_cluster->AddAt(&cluster);
525  currRecord++;
526  pClusterP = clusterP->next(pClusterP);
527  }
528 
529  StSsdCluster *pClusterN = clusterN->first();
530  while (pClusterN)
531  {
532  cluster.id = currRecord + 1;
533  cluster.id_cluster = 10000*(10*pClusterN->getNCluster() + 1)+idCurrentWaf;
534  cluster.first_strip = 10000*(10*pClusterN->getFirstStrip() + 1)+idCurrentWaf;
535  cluster.n_strip = pClusterN->getClusterSize();
536  cluster.adc_count = pClusterN->getTotAdc();
537  cluster.first_adc_count = pClusterN->getFirstAdc();
538  cluster.last_adc_count = pClusterN->getLastAdc();
539  cluster.noise_count = (int)pClusterN->getTotNoise();
540  cluster.flag = pClusterN->getFlag();
541  cluster.strip_mean = pClusterN->getStripMean();
542  for (i = 0 ; i < 5 ; i++)
543  cluster.id_mchit[i] = pClusterN->getIdMcHit(i);
544  scf_cluster->AddAt(&cluster);
545  currRecord++;
546  pClusterN = clusterN->next(pClusterN);
547  }
548  }
549  return currRecord;
550 }
551 //________________________________________________________________________________
552 Int_t StSsdBarrel::writeClusterToTable(St_scf_cluster *scf_cluster,St_spa_strip *spa_strip){
553  scf_cluster_st cluster;
554  spa_strip_st *on_strip = spa_strip->GetTable();
555  Int_t currRecord = 0;
556  Int_t i = 0;
557  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
558  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder ; iWaf++)
559  {
560  Int_t idCurrentWaf = mSsdLayer*1000 + (iWaf+1)*100 + (iLad+1);
561  StSsdClusterList *clusterP = mLadders[iLad]->mWafers[iWaf]->getClusterP();
562  StSsdClusterList *clusterN = mLadders[iLad]->mWafers[iWaf]->getClusterN();
563 
564  StSsdCluster *pClusterP = clusterP->first();
565  while (pClusterP)
566  {
567  cluster.id = currRecord + 1;
568  cluster.id_cluster = 10000*(10*pClusterP->getNCluster() + 0)+idCurrentWaf;
569  cluster.first_strip = 10000*(10*pClusterP->getFirstStrip()+ 0)+idCurrentWaf;
570  cluster.n_strip = pClusterP->getClusterSize();
571  cluster.adc_count = pClusterP->getTotAdc();
572  cluster.first_adc_count = pClusterP->getFirstAdc();
573  cluster.last_adc_count = pClusterP->getLastAdc();
574  cluster.noise_count = (Int_t) pClusterP->getTotNoise();
575  cluster.flag = pClusterP->getFlag();
576  cluster.strip_mean = pClusterP->getStripMean();
577  for (i = 0 ; i < 5 ; i++)
578  {
579  cluster.id_mchit[i] = pClusterP->getIdMcHit(i);
580  if(cluster.id_mchit[i] == 0){
581  cluster.id_mctrack[i]=0;
582  }
583  else{
584  for(Int_t j = 0 ; j < spa_strip->GetNRows(); j++){
585  if(cluster.id_mchit[i] == on_strip[j].id_mchit[i]){
586  cluster.id_mctrack[i] = on_strip[j].id_mctrack[i];
587  }
588  }
589  }
590  }
591  scf_cluster->AddAt(&cluster);
592  currRecord++;
593  pClusterP = clusterP->next(pClusterP);
594  }
595 
596  StSsdCluster *pClusterN = clusterN->first();
597  while (pClusterN)
598  {
599  cluster.id = currRecord + 1;
600  cluster.id_cluster = 10000*(10*pClusterN->getNCluster() + 1)+idCurrentWaf;
601  cluster.first_strip = 10000*(10*pClusterN->getFirstStrip() + 1)+idCurrentWaf;
602  cluster.n_strip = pClusterN->getClusterSize();
603  cluster.adc_count = pClusterN->getTotAdc();
604  cluster.first_adc_count = pClusterN->getFirstAdc();
605  cluster.last_adc_count = pClusterN->getLastAdc();
606  cluster.noise_count = (Int_t) pClusterN->getTotNoise();
607  cluster.flag = pClusterN->getFlag();
608  cluster.strip_mean = pClusterN->getStripMean();
609  for (i = 0 ; i < 5 ; i++)
610  {
611  cluster.id_mchit[i] = pClusterN->getIdMcHit(i);
612  if(cluster.id_mchit[i] == 0)cluster.id_mctrack[i]=0;
613  else{
614  for(Int_t j = 0 ; j < spa_strip->GetNRows(); j++){
615  if(cluster.id_mchit[i] == on_strip[j].id_mchit[i]){
616  cluster.id_mctrack[i] = on_strip[j].id_mctrack[i];
617  }
618  }
619  }
620  }
621  scf_cluster->AddAt(&cluster);
622  currRecord++;
623  pClusterN = clusterN->next(pClusterN);
624  }
625  }
626  return currRecord;
627 }
628 //________________________________________________________________________________
629 Int_t StSsdBarrel::writePointToContainer(St_scm_spt *scm_spt, StSsdHitCollection* ssdHitColl){
630  scm_spt_st spt;
631  StSsdHit *currentSsdHit;
632  // table size is 148 bytes
633  Int_t i = 0, inContainer = 0, inTable = 0;
634  StThreeVectorF gPos; StThreeVectorF gPosError;
635  Int_t hw; Float_t q ; unsigned char c;
636  c =0;
637 
638  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
639  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
640  {
641  Int_t idCurrentWaf = mSsdLayer*1000 + (iWaf+1)*100 + (iLad+1);
642  StSsdPointList *sptList = mLadders[iLad]->mWafers[iWaf]->getPoint();
643  StSsdPoint *pSpt = sptList->first();
644 
645  while (pSpt){// Start of Point Loop
646  if (ssdHitColl){ // If Available, Fill the StEvent Container
647  for (i = 0 ; i < 3 ; i++){
648  gPos[i] = pSpt->getXg(i);
649  gPosError[i] = 0.0;
650  }
651  hw = idCurrentWaf;
652  q = pSpt->getDe(0);
653  currentSsdHit = new StSsdHit(gPos,gPosError,hw,q,c);
654  currentSsdHit->setIdTruth(pSpt->getNMchit(0));// need to check first = most probable!
655 
656  currentSsdHit->setHardwarePosition(8+16*idWaferToWaferNumb(idCurrentWaf));
657  currentSsdHit->setLocalPosition(pSpt->getXl(0),pSpt->getXl(1));
658  //looking for the correct clusters...
659  Int_t Id_P_Side = pSpt->getIdClusterP();
660  Int_t Id_N_Side = pSpt->getIdClusterN();
661 
662  StSsdClusterList *currentListP_j = mLadders[iLad]->mWafers[iWaf]->getClusterP();
663  StSsdCluster *cluster_P_j = currentListP_j->first();
664  while(cluster_P_j)
665  {
666  if(cluster_P_j->getNCluster()==Id_P_Side)
667  break;
668  cluster_P_j = currentListP_j->next(cluster_P_j);
669  }
670 
671 
672  StSsdClusterList *currentListN_j = mLadders[iLad]->mWafers[iWaf]->getClusterN();
673  StSsdCluster *cluster_N_j = currentListN_j->first();
674  while(cluster_N_j)
675  {
676  if(cluster_N_j->getNCluster()==Id_N_Side)
677  break;
678  cluster_N_j = currentListN_j->next(cluster_N_j);
679  }
680 
681  // encode the hardware position
682  // 2^3 detector ID number (8)
683  // 2^4 4-12 num_wafer (0-319)
684  // 2^13 13-22 cebtral strip of the n-side cluster
685  // 2^23 23-27 strip of the p-side cluster relat. to n-side (-15,+16)
686  // 2^28 28-29 n-side cluster size(1-4)
687  // 2^30 30-31 p-side cluster size(1-4)
688  hw =
689  8
690  + 16 * idWaferToWaferNumb(idCurrentWaf)
691  + 8192 * (int)cluster_N_j->getStripMean()
692  + 8388608 * ((int)cluster_P_j->getStripMean() - (int)cluster_N_j->getStripMean() +15)
693  + 268435456 * (int)((cluster_N_j->getClusterSize() > 3) ? 3 : cluster_N_j->getClusterSize()-1)
694  + 1073741824 * (int)((cluster_P_j->getClusterSize() > 3) ? 3 : cluster_P_j->getClusterSize()-1);
695  currentSsdHit->setHardwarePosition(hw);
696 
697  inContainer += ssdHitColl->addHit(currentSsdHit);
698  }// Container condition
699 
700  if (1) {//Jerome is Happy, Fill the Table
701  spt.flag = pSpt->getFlag();
702  spt.id = 10000*(pSpt->getNPoint())+idCurrentWaf;
703  spt.id_cluster = pSpt->getNCluster();
704  spt.id_globtrk = 0;
705  spt.id_match = pSpt->getNMatched();
706  for (i = 0 ; i < 5 ; i++)
707  {
708  spt.id_mchit[i] = pSpt->getNMchit(i);
709  spt.id_mctrack[i] = 0;
710  spt.id_track[i] = 0;
711  }
712  spt.id_wafer = idCurrentWaf;
713  for (i = 0 ; i < 3 ; i++)
714  {
715  spt.cov[i] = 0;
716  spt.res[i] = 0;
717  spt.x[i] = pSpt->getXg(i);
718  spt.xl[i] = pSpt->getXl(i);
719  }
720  for (i = 0 ; i < 2 ; i++)
721  {
722  spt.mom2[i] = 0;
723  spt.de[i] = pSpt->getDe(i);
724  }
725  scm_spt->AddAt(&spt);
726  }
727  inTable++;
728  pSpt = sptList->next(pSpt);
729  }// End of Point Loop
730  }
731  return inTable;
732 }
733 /***********************************************************/
734 Int_t StSsdBarrel::writePointToContainer(St_scm_spt *scm_spt, StSsdHitCollection* ssdHitColl,St_scf_cluster *scf_cluster){
735  scm_spt_st spt;
736  StSsdHit *currentSsdHit;
737  scf_cluster_st *on_cluster = scf_cluster->GetTable();
738  // table size is 148 bytes
739  Int_t i = 0, inContainer = 0, inTable = 0 ;
740  StThreeVectorF gPos; StThreeVectorF gPosError;
741  Int_t hw; Float_t q ; unsigned char c;
742  c =0;
743  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
744  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
745  {
746  Int_t idCurrentWaf = mSsdLayer*1000 + (iWaf+1)*100 + (iLad+1);
747  StSsdPointList *sptList = mLadders[iLad]->mWafers[iWaf]->getPoint();
748  StSsdPoint *pSpt = sptList->first();
749 
750  while (pSpt){
751  //jb : we fill StEvent after getting the IdMctrack
752  //jb : as it was done too for the strip and clusters --> see StSpaBarrel.cc and StScfBarrel.cc
753  //printf("Now we find the idMcTrack from the cluster\n");
754  for (i = 0 ; i < 5 ; i++)
755  {
756  spt.id_mchit[i] = pSpt->getNMchit(i);
757  spt.id_mctrack[i] = 0;
758  spt.id_track[i] = 0;
759  //we look on the clusters table to get the IdMctrack info
760  if (spt.id_mchit[i] == 0) spt.id_mctrack[i]=0;
761  else {
762  for(Int_t j = 0 ; j < scf_cluster->GetNRows(); j++){
763  if(spt.id_mchit[i] == on_cluster[j].id_mchit[i]){
764  spt.id_mctrack[i] = on_cluster[j].id_mctrack[i];
765  }
766  }
767  }
768  }
769 
770  //now we fill StEvent and get the correct IdTruth
771  if (ssdHitColl){ // If Available, Fill the StEvent Container
772  for (i = 0 ; i < 3 ; i++){
773  gPos[i] = pSpt->getXg(i);
774  gPosError[i] = 0.0;
775  }
776  hw = idCurrentWaf;
777  q = pSpt->getDe(0);
778  currentSsdHit = new StSsdHit(gPos,gPosError,hw,q,c);
779  currentSsdHit->setIdTruth(spt.id_mctrack[0],100);// need to check first = most probable!
780  // Start of Point Loop
781 
782  //looking for the correct clusters...
783  Int_t Id_P_Side = pSpt->getIdClusterP();
784  Int_t Id_N_Side = pSpt->getIdClusterN();
785 
786  StSsdClusterList *currentListP_j = mLadders[iLad]->mWafers[iWaf]->getClusterP();
787  StSsdCluster *cluster_P_j = currentListP_j->first();
788  while(cluster_P_j)
789  {
790  if(cluster_P_j->getNCluster()==Id_P_Side)
791  break;
792  cluster_P_j = currentListP_j->next(cluster_P_j);
793  }
794 
795 
796  StSsdClusterList *currentListN_j = mLadders[iLad]->mWafers[iWaf]->getClusterN();
797  StSsdCluster *cluster_N_j = currentListN_j->first();
798  while(cluster_N_j)
799  {
800  if(cluster_N_j->getNCluster()==Id_N_Side)
801  break;
802  cluster_N_j = currentListN_j->next(cluster_N_j);
803  }
804 
805  // encode the hardware position
806  // 2^3 detector ID number (8)
807  // 2^4 4-12 num_wafer (0-319)
808  // 2^13 13-22 cebtral strip of the n-side cluster
809  // 2^23 23-27 strip of the p-side cluster relat. to n-side (-15,+16)
810  // 2^28 28-29 n-side cluster size(1-4)
811  // 2^30 30-31 p-side cluster size(1-4)
812  hw =
813  8
814  + 16 * idWaferToWaferNumb(idCurrentWaf)
815  + 8192 * (int)cluster_N_j->getStripMean()
816  + 8388608 * ((int)cluster_P_j->getStripMean() - (int)cluster_N_j->getStripMean() +15)
817  + 268435456 * (int)((cluster_N_j->getClusterSize() > 3) ? 3 : cluster_N_j->getClusterSize()-1)
818  + 1073741824 * (int)((cluster_P_j->getClusterSize() > 3) ? 3 : cluster_P_j->getClusterSize()-1);
819  currentSsdHit->setHardwarePosition(hw);
820  currentSsdHit->setLocalPosition(pSpt->getXl(0),pSpt->getXl(1));
821  inContainer += ssdHitColl->addHit(currentSsdHit);
822  }// Container condition
823 
824  if (1) {//Jerome is Happy, Fill the Table
825  spt.flag = pSpt->getFlag();
826  spt.id = 10000*(pSpt->getNPoint())+idCurrentWaf;
827  spt.id_cluster = pSpt->getNCluster();
828  spt.id_globtrk = 0;
829  spt.id_match = pSpt->getNMatched();
830  for (i = 0 ; i < 5 ; i++)
831  {
832  spt.id_mchit[i] = pSpt->getNMchit(i);
833  spt.id_mctrack[i] = 0;
834  spt.id_track[i] = 0;
835  }
836  spt.id_wafer = idCurrentWaf;
837  for (i = 0 ; i < 3 ; i++)
838  {
839  spt.cov[i] = 0;
840  spt.res[i] = 0;
841  spt.x[i] = pSpt->getXg(i);
842  spt.xl[i] = pSpt->getXl(i);
843  }
844  for (i = 0 ; i < 2 ; i++)
845  {
846  spt.mom2[i] = 0;
847  spt.de[i] = pSpt->getDe(i);
848  }
849  scm_spt->AddAt(&spt);
850  }
851  inTable++;
852  pSpt = sptList->next(pSpt);
853  }// End of Point Loop
854  }
855  return inTable;
856 }
857 
858 /***********************************************************/
859 Int_t StSsdBarrel::writePointToContainer(St_scm_spt *scm_spt, StSsdHitCollection* ssdHitColl,St_scf_cluster *scf_cluster,St_spa_strip *spa_strip,StSsdDynamicControl *mDynamicControl,StMcEvent *mcEvent){
860  vector<const StMcSsdHit*> hitCol;
861  StMcSsdHitCollection *myCol;
862  int totRatio, idTruth;
863  if(mcEvent)
864  {
865  if(Debug()){cout << "McEvent exists" << endl;}
866  myCol = mcEvent->ssdHitCollection();
867  if ((myCol))
868  {
869  for (unsigned int iLadder=0; iLadder<myCol->numberOfLadders(); iLadder++) {
870  for (unsigned int iWafer = 0; iWafer < myCol->ladder(iLadder)->numberOfWafers(); iWafer++) {
871  for (StMcSsdHitIterator iter = myCol->ladder(iLadder)->wafer(iWafer)->hits().begin();
872  iter != myCol->ladder(iLadder)->wafer(iWafer)->hits().end();
873  iter++) {
874  const StMcSsdHit *hit = dynamic_cast<const StMcSsdHit *> (*iter);
875  assert(hit);
876  hitCol.push_back(hit);
877  }
878  }
879  }
880  }
881  }
882  else{cout<< "No ssdMcHitCollection" <<endl;
883  }
884  scm_spt_st spt;
885  StSsdHit *currentSsdHit;
886  scf_cluster_st *on_cluster = scf_cluster->GetTable();
887  // table size is 148 bytes
888  Int_t i = 0, inContainer = 0, inTable = 0;
889  StThreeVectorF gPos; StThreeVectorF gPosError;
890  Int_t hw; Float_t q ; unsigned char c;
891  c =0;
892  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
893  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
894  {
895  Int_t idCurrentWaf = mSsdLayer*1000 + (iWaf+1)*100 + (iLad+1);//decode the wafer id
896  StSsdPointList *sptList = mLadders[iLad]->mWafers[iWaf]->getPoint();//loop over StSsdPoint list
897  StSsdPoint *pSpt = sptList->first();
898  totRatio = 0;
899  while (pSpt){
900  if(mcEvent){
901 
902  //we look only idMcTrack for simulation
903  //jb : we fill StEvent after getting the IdMctrack
904  //jb : as it was done too for the strip and clusters --> see StSpaBarrel.cc and StScfBarrel.cc
905  //printf("Now we find the idMcTrack from the cluster\n");
906  int idClusP = 0;
907  int idClusN = 0;
908  for (i = 0 ; i < 5 ; i++)
909  {
910  spt.id_mchit[i] = pSpt->getNMchit(i);
911  spt.id_mctrack[i] = 0;
912  spt.id_track[i] = 0;
913  //we look on the clusters table to get the IdMctrack info
914  if (spt.id_mchit[i] == 0) spt.id_mctrack[i]=0;
915  else {
916  int j =0;
917  for(j = 0 ; j < scf_cluster->GetNRows(); j++){
918  if(spt.id_mchit[i] == on_cluster[j].id_mchit[i]){
919  spt.id_mctrack[i] = on_cluster[j].id_mctrack[i];
920  idClusP = 10000*(10*pSpt->getIdClusterP() + 0)+idCurrentWaf;
921  idClusN = 10000*(10*pSpt->getIdClusterN() + 1)+idCurrentWaf;
922  break;
923  }
924  }
925  Calculation_Ratio(idCurrentWaf,idClusP,idClusN,hitCol,&totRatio,&idTruth);
926  }
927  }
928  }
929  //now we fill StEvent and get the correct IdTruth
930  if (ssdHitColl){ // If Available, Fill the StEvent Container
931  for (i = 0 ; i < 3 ; i++){
932  gPos[i] = pSpt->getXg(i);
933  gPosError[i] = 0.0;
934  }
935  hw = idCurrentWaf;
936  q = pSpt->getDe(0);
937  currentSsdHit = new StSsdHit(gPos,gPosError,hw,q,c);
938  //currentSsdHit->setIdTruth(spt.id_mctrack[0],(int)ratio);// need to check first = most probable! ; new : qATruth is set with the ratio chargeCLUSTER/chargeGEANT
939  currentSsdHit->setIdTruth(idTruth,(int)totRatio);
940  // Start of Point Loop
941 
942  //looking for the correct clusters...
943  Int_t Id_P_Side = pSpt->getIdClusterP();
944  Int_t Id_N_Side = pSpt->getIdClusterN();
945 
946  StSsdClusterList *currentListP_j = mLadders[iLad]->mWafers[iWaf]->getClusterP();
947  StSsdCluster *cluster_P_j = currentListP_j->first();
948  while(cluster_P_j)
949  {
950  if(cluster_P_j->getNCluster()==Id_P_Side)
951  break;
952  cluster_P_j = currentListP_j->next(cluster_P_j);
953  }
954  StSsdClusterList *currentListN_j = mLadders[iLad]->mWafers[iWaf]->getClusterN();
955  StSsdCluster *cluster_N_j = currentListN_j->first();
956  while(cluster_N_j)
957  {
958  if(cluster_N_j->getNCluster()==Id_N_Side)
959  break;
960  cluster_N_j = currentListN_j->next(cluster_N_j);
961  }
962 
963  // encode the hardware position
964  // 2^3 detector ID number (8)
965  // 2^4 4-12 num_wafer (0-319)
966  // 2^13 13-22 cebtral strip of the n-side cluster
967  // 2^23 23-27 strip of the p-side cluster relat. to n-side (-15,+16)
968  // 2^28 28-29 n-side cluster size(1-4)
969  // 2^30 30-31 p-side cluster size(1-4)
970  hw =
971  8
972  + 16 * idWaferToWaferNumb(idCurrentWaf)
973  + 8192 * (int)cluster_N_j->getStripMean()
974  + 8388608 * ((int)cluster_P_j->getStripMean() - (int)cluster_N_j->getStripMean() +15)
975  + 268435456 * (int)((cluster_N_j->getClusterSize() > 3) ? 3 : cluster_N_j->getClusterSize()-1)
976  + 1073741824 * (int)((cluster_P_j->getClusterSize() > 3) ? 3 : cluster_P_j->getClusterSize()-1);
977  currentSsdHit->setHardwarePosition(hw);
978  currentSsdHit->setLocalPosition(pSpt->getXl(0),pSpt->getXl(1));
979  inContainer += ssdHitColl->addHit(currentSsdHit);
980  }// Container condition
981 
982  if (1) {//Jerome is Happy, Fill the Table
983  spt.flag = pSpt->getFlag();
984  spt.id = 10000*(pSpt->getNPoint())+idCurrentWaf;
985  spt.id_cluster = pSpt->getNCluster();
986  spt.id_globtrk = 0;
987  spt.id_match = pSpt->getNMatched();
988  for (i = 0 ; i < 5 ; i++)
989  {
990  spt.id_mchit[i] = pSpt->getNMchit(i);
991  spt.id_mctrack[i] = 0;
992  spt.id_track[i] = 0;
993  }
994  spt.id_wafer = idCurrentWaf;
995  for (i = 0 ; i < 3 ; i++)
996  {
997  spt.cov[i] = 0;
998  spt.res[i] = 0;
999  spt.x[i] = pSpt->getXg(i);
1000  spt.xl[i] = pSpt->getXl(i);
1001  }
1002  for (i = 0 ; i < 2 ; i++)
1003  {
1004  spt.mom2[i] = 0;
1005  spt.de[i] = pSpt->getDe(i);
1006  }
1007  scm_spt->AddAt(&spt);
1008  }
1009  inTable++;
1010  pSpt = sptList->next(pSpt);
1011  }// End of Point Loop
1012  }
1013  if (hitCol.size()>0 )hitCol.clear();
1014  return inTable;
1015 }
1016 //________________________________________________________________________________
1017 void StSsdBarrel::Calculation_Ratio(int idWafer,int idClusterP,int idClusterN,vector<const StMcSsdHit*> hitCol, int *ratio, int *idTruth)
1018 {
1019  Float_t charge[2] = {0,0};
1020  int DominatorP = 0;
1021  int DominatorN = 0;
1022  Float_t adc_DominatorP = 0;
1023  Float_t adc_DominatorN = 0;
1024  vector<StSsdStrip*> ListstripP;
1025  vector<StSsdStrip*> ListstripN;
1026  vector<int> GTrackP(5,0),GTrackN(5,0);
1027  int isSplittedP=0,isSplittedN =0;
1028  Int_t lad = idWaferToLadderNumb(idWafer);
1029  Int_t waf = (int)((idWafer - mSsdLayer*1000)/100)-1;
1030  // now p-side
1031  StSsdCluster *pClusterP = mLadders[lad]->mWafers[waf]->getClusterP()->first();
1032  while (pClusterP){
1033  int idP = 10000*(10*pClusterP->getNCluster() + 0)+idWafer;
1034  if(idP==idClusterP){
1035  charge[0] = pClusterP->getTotAdc();
1036  if(pClusterP->getFlag()==1){
1037  //splitted cluster
1038  isSplittedP = isSplit(pClusterP,0,lad,waf);
1039  }
1040  for(Int_t e =0 ;e<5;e++)GTrackP.push_back(pClusterP->getIdMcHit(e));
1041  //now we loop over the strips of that cluster
1042  StSsdStripList *stripP = StSsdBarrel::Instance()->mLadders[lad]->mWafers[waf]->getStripP();
1043  int lastScan =0;//lastScan : a same strips can be used by 2 adjacents clusters : it must be count twice
1044  for(int kk=pClusterP->getFirstStrip();kk<pClusterP->getFirstStrip()+pClusterP->getClusterSize();kk++)
1045  {
1046  StSsdStrip *pStripP = stripP->first();
1047  while (pStripP)
1048  {
1049  if((pStripP->getNStrip()==kk)&&(pStripP->getNStrip()!=lastScan))
1050  {
1051  lastScan = pStripP->getNStrip();
1052  ListstripP.push_back(pStripP);
1053  }
1054  pStripP = stripP->next(pStripP);
1055  }
1056  }
1057  break;
1058  }
1059  pClusterP = mLadders[lad]->mWafers[waf]->getClusterP()->next(pClusterP);
1060  }
1061  // now n-side
1062  StSsdCluster *pClusterN = mLadders[lad]->mWafers[waf]->getClusterN()->first();
1063  while (pClusterN){
1064  int idN = 10000*(10*pClusterN->getNCluster() + 1)+idWafer;
1065  if(idN==idClusterN){
1066  charge[1] = pClusterN->getTotAdc();
1067  if(pClusterN->getFlag()==1){
1068  //splitted cluster
1069  isSplittedN = isSplit(pClusterN,1,lad,waf);
1070  }
1071  for(Int_t e =0 ;e<5;e++)GTrackN.push_back(pClusterN->getIdMcHit(e));
1072  //now we loop over the strips of that cluster
1073  StSsdStripList *stripN = mLadders[lad]->mWafers[waf]->getStripN();
1074  int lastScan =0;//lastScan : a same strip can be used by 2 adjacents clusters : it must be count twice
1075  for(int kk=pClusterN->getFirstStrip();kk<pClusterN->getFirstStrip()+pClusterN->getClusterSize();kk++)
1076  {
1077  StSsdStrip *pStripN = stripN->first();
1078  while (pStripN)
1079  {
1080  if((pStripN->getNStrip()==kk)&&(pStripN->getNStrip()!=lastScan))
1081  {
1082  lastScan = pStripN->getNStrip();
1083  ListstripN.push_back(pStripN);
1084  }
1085  pStripN = stripN->next(pStripN);
1086  }
1087  }
1088  break;
1089  }
1090  pClusterN = mLadders[lad]->mWafers[waf]->getClusterN()->next(pClusterN);
1091  }
1092 
1093  // find dominator from cluster
1094  DominatorP = FindMcHit(GTrackP,hitCol);
1095  DominatorN = FindMcHit(GTrackN,hitCol);
1096  if(DominatorP!=DominatorN) {
1097  *ratio = 0;
1098  *idTruth = 0;
1099  return;
1100  }
1101  if((ListstripN.size()>0)&&(ListstripP.size()>0))
1102  {
1103  unsigned int min ,max;
1104  // side P
1105  min=0;
1106  max=0;
1107  if(isSplittedP==1){
1108  min = 0;
1109  max = ListstripP.size()-1;}
1110  else
1111  if(isSplittedP==2){
1112  min = 1;
1113  max = ListstripP.size();}
1114  else{
1115  min = 0;
1116  max = ListstripP.size();}
1117  for(unsigned int ee = min;ee<max;ee++){
1118  StSsdStrip* tempoStripP = ListstripP[ee];
1119  if(DominatorP == tempoStripP->getIdMcTrack(0))
1120  {
1121  adc_DominatorP += tempoStripP->getDigitSig();
1122  }
1123  else {
1124  }
1125  }
1126 
1127  //side N
1128  min =0;
1129  max =0;
1130  if(isSplittedN==1){
1131  min = 0;
1132  max = ListstripN.size()-1;
1133  }
1134  else
1135  if(isSplittedN==2){
1136  min = 1;
1137  max = ListstripN.size();
1138  }
1139  else{
1140  min = 0;
1141  max = ListstripN.size();
1142  }
1143  for(unsigned int ee = min;ee<max;ee++){
1144  StSsdStrip *tempoStripN = ListstripN[ee];
1145  if(DominatorN == tempoStripN->getIdMcTrack(0))
1146  {
1147  adc_DominatorN += tempoStripN->getDigitSig();
1148  }
1149  else {
1150  }
1151  }
1152  }
1153  //find the Dominant contributor
1154  float ratioP = 0 ;
1155  float ratioN = 0 ;
1156  if(charge[0]!=0) ratioP = adc_DominatorP/charge[0];
1157  if(charge[1]!=0) ratioN = adc_DominatorN/charge[1];
1158  if(DominatorP == DominatorN){
1159  *ratio = (int)(100*(ratioP*ratioN));
1160  *idTruth = DominatorP;
1161  }
1162  else{
1163  *ratio = 0;
1164  *idTruth = 0;
1165  }
1166  if(ListstripP.size()>0) ListstripP.clear();
1167  if(ListstripN.size()>0) ListstripN.clear();
1168  if(GTrackP.size()>0) GTrackP.clear();
1169  if(GTrackN.size()>0) GTrackN.clear();
1170 }
1171 //__________________________________________________________________
1172 Int_t StSsdBarrel::FindMcHit(const vector<int> &tempo,const vector<const StMcSsdHit*> &hitCol)
1173 {
1174  float ChargeTrack = 0.0;
1175  int idTrack =0;
1176  for(int e=0;e<5;e++){
1177  for (unsigned int hit = 0 ; hit<hitCol.size();hit++){
1178  const StMcSsdHit* currHit = hitCol[hit];
1179  if((tempo[e]>0)&&(currHit->key() == tempo[e])&&(currHit->dE()>ChargeTrack)){
1180  ChargeTrack = currHit->dE();
1181  idTrack = currHit->parentTrack()->key();
1182  }
1183  }
1184  }
1185  return idTrack;
1186 }
1187 //________________________________________________________________________________________
1188 Int_t StSsdBarrel::isSplit(StSsdCluster *currentCluster,int iSide,int lad,int waf){
1189  StSsdCluster *firstClus;
1190  StSsdCluster *lastClus;
1191  StSsdCluster *nextClus;
1192  StSsdCluster *prevClus;
1193  int isSplitted =0 ;
1194  if(iSide ==0){
1195  firstClus = mLadders[lad]->mWafers[waf]->getClusterP()->first();
1196  lastClus = mLadders[lad]->mWafers[waf]->getClusterP()->last();
1197  }
1198  else {
1199  firstClus = mLadders[lad]->mWafers[waf]->getClusterN()->first();
1200  lastClus = mLadders[lad]->mWafers[waf]->getClusterN()->last();
1201  }
1202  if(currentCluster->getNCluster() == firstClus->getNCluster()){
1203  isSplitted=1;
1204  }
1205  else if(currentCluster->getNCluster() == lastClus->getNCluster()){
1206  isSplitted=2;
1207  }
1208  else {
1209  nextClus = currentCluster->getNextCluster();
1210  if(nextClus->getFirstStrip() == ((currentCluster->getFirstStrip()+currentCluster->getClusterSize()-1))) {
1211  isSplitted =1;
1212  prevClus = currentCluster->getPrevCluster();
1213  if(currentCluster->getFirstStrip() == ((prevClus->getFirstStrip()+prevClus->getClusterSize()-1))) {
1214  isSplitted=2;
1215  }
1216  }
1217  }
1218  return isSplitted;
1219 }
1220 //___________________________________________________________________
1221 void StSsdBarrel::doSideClusterisation(Int_t *barrelNumbOfCluster){
1222  Int_t wafNumbOfCluster[2];
1223  wafNumbOfCluster[0] = 0;
1224  wafNumbOfCluster[1] = 0;
1225 
1226  for (Int_t iLad = 0 ; iLad < mNLadder; iLad++)
1227  for (Int_t iWaf = 0 ; iWaf < mNWaferPerLadder; iWaf++)
1228  {
1229  mLadders[iLad]->mWafers[iWaf]->doClusterisation(wafNumbOfCluster, mClusterControl);
1230  barrelNumbOfCluster[0] += wafNumbOfCluster[0];
1231  barrelNumbOfCluster[1] += wafNumbOfCluster[1];
1232  }
1233 }
1234 //________________________________________________________________________________
1235 void StSsdBarrel::doSideClusterisation(Int_t *barrelNumbOfCluster,Int_t WafStatus[20][16]){
1236  Int_t wafNumbOfCluster[2];
1237  wafNumbOfCluster[0] = 0;
1238  wafNumbOfCluster[1] = 0;
1239  for (Int_t iLad = 0 ; iLad < mNLadder; iLad++)
1240  for (Int_t iWaf = 0 ; iWaf < mNWaferPerLadder; iWaf++)
1241  {
1242  if(WafStatus[iLad][iWaf]!=0){
1243  mLadders[iLad]->mWafers[iWaf]->doClusterisation(wafNumbOfCluster, mClusterControl);
1244  barrelNumbOfCluster[0] += wafNumbOfCluster[0];
1245  barrelNumbOfCluster[1] += wafNumbOfCluster[1];
1246  }
1247  }
1248 }
1249 //_______________________________________________________________________________________
1250 Int_t StSsdBarrel::doClusterMatching(Float_t *CalibArray){
1251  Int_t NumberOfPackage = 0;
1252  Int_t nSolved = 0;
1253  Int_t nPerfect = 0;
1254 
1255  for (Int_t iLad = 0; iLad < mNLadder; iLad++){
1256  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
1257  {
1258  mLadders[iLad]->mWafers[iWaf]->doLorentzShift(mDimensions,mShift_hole,mShift_elec);
1259  NumberOfPackage += mLadders[iLad]->mWafers[iWaf]->doFindPackage(mDimensions, mClusterControl);
1260  nPerfect = mLadders[iLad]->mWafers[iWaf]->doSolvePerfect(mDimensions, mClusterControl,CalibArray[(iLad*mNWaferPerLadder)+iWaf]);
1261  if (!nPerfect) continue;
1262  mLadders[iLad]->mWafers[iWaf]->doStatPerfect(nPerfect, mClusterControl);
1263  nSolved += mLadders[iLad]->mWafers[iWaf]->doSolvePackage(mDimensions, mClusterControl,CalibArray[(iLad*mNWaferPerLadder)+iWaf]);
1264  }
1265  }
1266  cout<<"**** Remark: "<<nSolved<<" solved packages ****\n";
1267  return NumberOfPackage;
1268 }
1269 //________________________________________________________________________________
1270 void StSsdBarrel::convertDigitToAnalog(StSsdDynamicControl *dynamicControl){
1271  long nElectronInAMip = dynamicControl->getnElectronInAMip();
1272  long adcDynamic = dynamicControl->getadcDynamic();
1273  Double_t pairCreationEnergy = dynamicControl->getpairCreationEnergy();
1274 
1275  const Int_t NAdcChannel = (int)pow(2.0,dynamicControl->getnbitEncoding());
1276  const Double_t convFactor = (pairCreationEnergy*adcDynamic*nElectronInAMip)/NAdcChannel;
1277  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1278  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
1279  mLadders[iLad]->mWafers[iWaf]->convertDigitToAnalog(convFactor);
1280 }
1281 //________________________________________________________________________________
1282 void StSsdBarrel::convertUFrameToOther(){
1283  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1284  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
1285  {
1286  mLadders[iLad]->mWafers[iWaf]->convertUFrameToLocal(mDimensions);
1287  mLadders[iLad]->mWafers[iWaf]->convertLocalToGlobal();
1288  }
1289 }
1290 //________________________________________________________________________________
1291 void StSsdBarrel::convertGlobalFrameToOther(){
1292  for (Int_t iLad = 0; iLad < mNLadder; iLad++){
1293  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
1294  {
1295  mLadders[iLad]->mWafers[iWaf]->convertGlobalToLocal();
1296  mLadders[iLad]->mWafers[iWaf]->convertLocalToUFrame(mDetectorLargeEdge, mDetectorSmallEdge, mTheta);
1297  }
1298  }
1299 }
1300 //________________________________________________________________________________
1301 void StSsdBarrel::sortListStrip(){
1302  StSsdStripList *currentList = 0;
1303  Int_t isSorted = 0;
1304  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1305  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
1306  {
1307  currentList = mLadders[iLad]->mWafers[iWaf]->getStripP();
1308  isSorted = currentList->isSorted();
1309  if (!isSorted) currentList->sortStrip();
1310 
1311  currentList = mLadders[iLad]->mWafers[iWaf]->getStripN();
1312  isSorted = currentList->isSorted();
1313  if (!isSorted) currentList->sortStrip();
1314  }
1315  return;
1316 }
1317 //________________________________________________________________________________
1318 void StSsdBarrel::sortListCluster(){
1319  StSsdClusterList *currentList = 0;
1320  Int_t isSorted = 0;
1321  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1322  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++)
1323  {
1324  currentList = mLadders[iLad]->mWafers[iWaf]->getClusterP();
1325  isSorted = currentList->isSorted();
1326  if (!isSorted) currentList->sortCluster();
1327 
1328  currentList = mLadders[iLad]->mWafers[iWaf]->getClusterN();
1329  isSorted = currentList->isSorted();
1330  if (!isSorted) currentList->sortCluster();
1331  }
1332 }
1333 
1334 StSsdBarrel::StSsdBarrel(const StSsdBarrel & originalBarrel)
1335 {
1336  mSsdLayer = originalBarrel.mSsdLayer;
1337  mNLadder = originalBarrel.mNLadder;
1338  mNWaferPerLadder = originalBarrel.mNWaferPerLadder;
1339  mNStripPerSide = originalBarrel.mNStripPerSide;
1340 
1341  mLadders = new StSsdLadder*[mNLadder];
1342  for (Int_t iLad=0; iLad < mNLadder; iLad++)
1343  mLadders[iLad] = new StSsdLadder(iLad,mSsdLayer,mNWaferPerLadder,mNStripPerSide);
1344 }
1345 
1346 StSsdBarrel& StSsdBarrel::operator=(const StSsdBarrel originalBarrel)
1347 {
1348  mSsdLayer = originalBarrel.mSsdLayer;
1349  mNLadder = originalBarrel.mNLadder;
1350  mNWaferPerLadder = originalBarrel.mNWaferPerLadder;
1351  mNStripPerSide = originalBarrel.mNStripPerSide;
1352 
1353  mLadders = new StSsdLadder*[mNLadder];
1354  for (Int_t iLad=0; iLad < mNLadder; iLad++)
1355  mLadders[iLad] = new StSsdLadder(iLad,mSsdLayer,mNWaferPerLadder,mNStripPerSide);
1356  return *this;
1357 }
1358 
1359 Int_t StSsdBarrel::idWaferToWaferNumb(Int_t idWafer)
1360 {
1361  Int_t iW = (int)((idWafer - mSsdLayer*1000)/100);
1362  Int_t iL = idWafer - mSsdLayer*1000 - iW*100;
1363  return ((iL-1)*mNWaferPerLadder + iW -1);
1364 }
1365 
1366 Int_t StSsdBarrel::idWaferToLadderNumb(Int_t idWafer)
1367 {
1368  Int_t iW = (int)((idWafer - mSsdLayer*1000)/100);
1369  Int_t iL = idWafer - mSsdLayer*1000 - iW*100;
1370  return iL-1;
1371 }
1372 
1373 Int_t StSsdBarrel::waferNumbToIdWafer(Int_t waferNumb)
1374 {
1375  Int_t iL = 1+(int)((waferNumb)/mNWaferPerLadder);
1376  Int_t iW = waferNumb-((iL-1)*mNWaferPerLadder)+1;
1377  return mSsdLayer*1000 + iW*100 + iL;
1378 }
1379 
1380 Int_t StSsdBarrel::isActiveLadder(Int_t iLadder)
1381 {
1382  return mActiveLadders[iLadder];
1383 }
1384 void StSsdBarrel::renumHitAfterRemove() {
1385  Int_t iLast = 0;
1386  Int_t iNewLast = 0;
1387  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1388  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++) {
1389  iNewLast = mLadders[iLad]->mWafers[iWaf]->getPoint()->renumHits(iLast);
1390  iLast = iNewLast;
1391  }
1392 }
1393 //________________________________________________________________________________
1394 StSsdPointList *StSsdBarrel::getInactiveHitList() {
1395  StSsdPointList *inactiveHits = new StSsdPointList();
1396  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1397  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++) {
1398  //fill the list of hits in inactive wafer areas
1399  StSsdPointList *currDeadList = mLadders[iLad]->mWafers[iWaf]->getDeadHits(mDetectorLargeEdge, mDetectorSmallEdge, mStripPitch);
1400  if(currDeadList->getSize()>0){
1401  }
1402  inactiveHits = inactiveHits->addPointList(currDeadList);
1403  delete currDeadList;
1404  }
1405  inactiveHits->sortPoint();
1406  return inactiveHits;
1407 }
1408 //________________________________________________________________________________
1409 void StSsdBarrel::convertToStrip(Double_t pairCreationEnergy,
1410  Int_t nstripInACluster,
1411  Double_t parDiffP,
1412  Double_t parDiffN,
1413  Double_t parIndRightP,
1414  Double_t parIndRightN,
1415  Double_t parIndLeftP,
1416  Double_t parIndLeftN) {
1417 
1418  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1419  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++) {
1420  mLadders[iLad]->mWafers[iWaf]->convertToStrip(mStripPitch,
1421  mNStripPerSide,
1422  pairCreationEnergy,
1423  nstripInACluster,
1424  parDiffP,
1425  parDiffN,
1426  parIndRightP,
1427  parIndRightN,
1428  parIndLeftP,
1429  parIndLeftN,
1430  mShift_hole,
1431  mShift_elec);
1432  }
1433 }
1434 //________________________________________________________________________________
1435 void StSsdBarrel::addNoiseToStrip(slsCtrl_st *ctrl)
1436 {
1437  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1438  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder; iWaf++) {
1439  StSsdWafer *wafer = mLadders[iLad]->mWafers[iWaf];
1440  wafer->sortNoise();
1441  wafer->sortStrip();
1442  wafer->addNoiseToStripSignal(ctrl[0].nElectronInAMip,ctrl[0].adcDynamic);
1443  }
1444 }
1445 //________________________________________________________________________________
1446 Int_t StSsdBarrel::readStripFromTable(St_sls_strip *sls_strip)
1447 {
1448  sls_strip_st *strip = sls_strip->GetTable();
1449 
1450  Int_t idWaf = 0, iWaf = 0, iLad = 0;
1451  Int_t nStrip = 0;
1452  Int_t iSide = 0;
1453  Int_t i = 0;
1454  Int_t idMcHit[5] = {0,0,0,0,0};
1455  Int_t e = 0;
1456  Int_t my_counterP =0;
1457  Int_t my_counterN =0;
1458  for (i = 0 ; i < sls_strip->GetNRows(); i++)
1459  {
1460  nStrip = (int)(strip[i].id_strip/100000.);
1461  idWaf = strip[i].id_strip-10000*((int)(strip[i].id_strip/10000.));
1462  iWaf = (int)((idWaf - mSsdLayer*1000)/100)-1;
1463  iLad = idWaf - mSsdLayer*1000 - (iWaf+1)*100-1;
1464  iSide = (strip[i].id_strip - nStrip*100000 - idWaf)/10000;
1465  if(iSide==0) my_counterP++;
1466  if(iSide==1) my_counterN++;
1467  for (e = 0 ; e < 5;e++) idMcHit[e] = strip[i].id_mchit[e];
1468  StSsdStrip *newStrip = new StSsdStrip(nStrip, i, strip[i].adc_count, strip[i].de, idMcHit);
1469  mLadders[iLad]->mWafers[iWaf]->addStrip(newStrip, iSide);
1470  }
1471  return sls_strip->GetNRows();
1472 }
1473 //________________________________________________________________________________
1474 Int_t StSsdBarrel::readNoiseFromTable(St_ssdStripCalib *strip_calib)
1475 {
1476  ssdStripCalib_st *noise = strip_calib->GetTable();
1477  Int_t NAdcChannel = (int)pow(2.0,10.0*1.0);
1478  Int_t nElectronInAMip = 22500;
1479  Int_t adcDynamic = 20;
1480  const Float_t AdctoE = (adcDynamic*nElectronInAMip)/(float)(NAdcChannel);
1481  if(Debug()) {printf("AdctoE = %f\n",AdctoE);}
1482 
1483  Int_t idWaf = 0, iWaf = 0, iLad = 0;
1484  Int_t nStrip = 0;
1485  Int_t iSide = 0;
1486  Int_t i = 0;
1487  Int_t ent = 0 ;
1488  for (i = 0 ; i < strip_calib->GetNRows(); i++)
1489  {
1490  if (noise[i].id>0 && noise[i].id<=76818620) {
1491  nStrip = (int)(noise[i].id/100000.);
1492  idWaf = noise[i].id-10000*((int)(noise[i].id/10000.));
1493  iWaf = (int)((idWaf - mSsdLayer*1000)/100)-1;
1494  iLad = idWaf - mSsdLayer*1000 - (iWaf+1)*100-1;
1495  iSide = (noise[i].id - nStrip*100000 - idWaf)/10000;
1496  StSpaNoise *newStrip = new StSpaNoise(nStrip ,(int)(noise[i].pedestals*AdctoE),(int)((noise[i].rms*AdctoE)/16.));
1497  mLadders[iLad]->mWafers[iWaf]->addNoiseToStripSignal(newStrip,iSide);
1498  ent++;
1499  }
1500  }
1501  return ent;
1502 }
1503 //________________________________________________________________________________
1504 Int_t StSsdBarrel::readConditionDbFromTable(St_sdm_condition_db *sdm_condition)
1505 {
1506  sdm_condition_db_st *condition = sdm_condition->GetTable();
1507 
1508  Int_t idWaf = 0, iWaf = 0, iLad = 0;
1509  Int_t nStrip = 0;
1510  Int_t iSide = 0;
1511 
1512  Int_t i = 0;
1513  for (i = 0 ; i < sdm_condition->GetNRows(); i++)
1514  {
1515  if (!(condition[i].is_active))
1516  {
1517  nStrip = (int)(condition[i].id_strip/100000.);
1518  idWaf = condition[i].id_strip-10000*((int)(condition[i].id_strip/10000.));
1519  iWaf = idWaferToWaferNumb(idWaf);
1520  iLad = (int)(idWaf - mSsdLayer*1000 - (iWaf+1)*100 - 1);
1521  iSide = (condition[i].id_strip - nStrip*100000 - idWaf)/10000;
1522  mLadders[iLad]->mWafers[iWaf]->setIsActive(condition[i].is_active, iSide, nStrip);
1523  }
1524  }
1525  return sdm_condition->GetNRows();
1526 }
1527 //________________________________________________________________________________
1528 Int_t StSsdBarrel::writeStripToTable(St_spa_strip *spa_strip)
1529 {
1530  spa_strip_st out_strip;
1531 
1532  Int_t currRecord = 0;
1533  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1534  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder ; iWaf++)
1535  {
1536  Int_t idCurrentWaf = mSsdLayer*1000 +((iWaf+1)*100)+(iLad+1);
1537  StSsdStripList *stripP = mLadders[iLad]->mWafers[iWaf]->getStripP();
1538  StSsdStripList *stripN = mLadders[iLad]->mWafers[iWaf]->getStripN();
1539 
1540  StSsdStrip *pStripP = stripP->first();
1541  while (pStripP)
1542  {
1543 
1544  out_strip.id = currRecord + 1;
1545  out_strip.adc_count = pStripP->getDigitSig();
1546  out_strip.id_strip = 10000*(10*pStripP->getNStrip() + 0)+idCurrentWaf;
1547  for (Int_t i = 0 ; i < 5 ; i++)
1548  {
1549  out_strip.id_mchit[i] = pStripP->getIdMcHit(i);
1550  }
1551  spa_strip->AddAt(&out_strip);
1552  currRecord++;
1553  pStripP = stripP->next(pStripP);
1554  }
1555 
1556  StSsdStrip *pStripN = stripN->first();
1557  while (pStripN)
1558  {
1559 
1560  out_strip.id = currRecord + 1;
1561  out_strip.adc_count = pStripN->getDigitSig();
1562  out_strip.id_strip = 10000*(10*pStripN->getNStrip() + 1)+idCurrentWaf;
1563  for (Int_t i = 0 ; i < 5 ; i++)
1564  {
1565  out_strip.id_mchit[i] = pStripN->getIdMcHit(i);
1566  }
1567  spa_strip->AddAt(&out_strip);
1568  currRecord++;
1569  pStripN = stripN->next(pStripN);
1570  }
1571 
1572  }
1573  return currRecord;
1574 }
1575 //________________________________________________________________________________
1576 Int_t StSsdBarrel::writeStripToTable(St_spa_strip *spa_strip,St_sls_strip *sls_strip )
1577 {
1578  spa_strip_st out_strip;
1579  sls_strip_st *strip = sls_strip->GetTable();
1580  Int_t currRecord = 0;
1581  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1582  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder ; iWaf++)
1583  {
1584  Int_t idCurrentWaf = mSsdLayer*1000 +((iWaf+1)*100)+(iLad+1);
1585  StSsdStripList *stripP = mLadders[iLad]->mWafers[iWaf]->getStripP();
1586  StSsdStripList *stripN = mLadders[iLad]->mWafers[iWaf]->getStripN();
1587  StSsdStrip *pStripP = stripP->first();
1588  while (pStripP)
1589  {
1590  out_strip.id = currRecord + 1;
1591  out_strip.adc_count = pStripP->getDigitSig();
1592  out_strip.id_strip = 10000*(10*pStripP->getNStrip() + 0)+idCurrentWaf;
1593  for (Int_t i = 0 ; i < 5 ; i++)
1594  {
1595  out_strip.id_mchit[i] = pStripP->getIdMcHit(i);
1596  if(out_strip.id_mchit[i]==0) {
1597  out_strip.id_mctrack[i]=0;}
1598  else {
1599  for(Int_t j = 0 ; j < sls_strip->GetNRows(); j++){
1600  if(out_strip.id_mchit[i] == strip[j].id_mchit[i])
1601  out_strip.id_mctrack[i] = strip[j].id_mctrack[i];
1602  }
1603  }
1604  }
1605  spa_strip->AddAt(&out_strip);
1606  currRecord++;
1607  pStripP = stripP->next(pStripP);
1608  }
1609 
1610  StSsdStrip *pStripN = stripN->first();
1611  while (pStripN)
1612  {
1613  out_strip.id = currRecord + 1;
1614  out_strip.adc_count = pStripN->getDigitSig();
1615  out_strip.id_strip = 10000*(10*pStripN->getNStrip() + 1)+idCurrentWaf;
1616  for (Int_t i = 0 ; i < 5 ; i++)
1617  {
1618  out_strip.id_mchit[i] = pStripN->getIdMcHit(i);
1619  if(out_strip.id_mchit[i]==0) {
1620  out_strip.id_mctrack[i]=0;}
1621  else {
1622  for(Int_t j = 0 ; j < sls_strip->GetNRows(); j++){
1623  if(out_strip.id_mchit[i] == strip[j].id_mchit[i])
1624  out_strip.id_mctrack[i] = strip[j].id_mctrack[i];
1625  }
1626  }
1627  }
1628  spa_strip->AddAt(&out_strip);
1629  currRecord++;
1630  pStripN = stripN->next(pStripN);
1631  }
1632  }
1633  return currRecord;
1634 }
1635 //________________________________________________________________________________
1636 void StSsdBarrel::doDaqSimulation(slsCtrl_st *ctrl){
1637  for (Int_t iLad = 0; iLad < mNLadder; iLad++)
1638  for (Int_t iWaf = 0; iWaf < mNWaferPerLadder ; iWaf++) {
1639  mLadders[iLad]->mWafers[iWaf]->convertAnalogToDigit(ctrl[0].nElectronInAMip,
1640  ctrl[0].adcDynamic,
1641  ctrl[0].nbitEncoding,
1642  ctrl[0].daqCutValue);
1643  mLadders[iLad]->mWafers[iWaf]->pedestalSubstraction();
1644  mLadders[iLad]->mWafers[iWaf]->zeroSubstraction();
1645  mLadders[iLad]->mWafers[iWaf]->updateStripList();
1646  }
1647 }
1648 //____________________________________________________________________
1649 Int_t StSsdBarrel::readNoiseDefaultForSimu(){
1650  Int_t rms = 48;
1651  // the noise is coded as 16*rms then for each strip, noise = 60/16 = 3.75 adc
1652  Int_t ped = 120 ;
1653  Int_t NAdcChannel = (int)pow(2.0,10.0*1.0);
1654  Int_t nElectronInAMip = 22500;
1655  Int_t adcDynamic = 20;
1656  const Float_t AdctoE = (adcDynamic*nElectronInAMip)/(float)(NAdcChannel);
1657  Int_t NumberOfNoise = 0;
1658  for(Int_t iLad=0;iLad<mNLadder;iLad++)
1659  {
1660  for(Int_t iWaf=0;iWaf<mNWaferPerLadder;iWaf++)
1661  {
1662  for(Int_t NStrip=0;NStrip<mNStripPerSide;NStrip++)
1663  {
1664  for(Int_t iSide=0;iSide<2;iSide++)
1665  {
1666  StSpaNoise *newStrip = new StSpaNoise(NStrip+1 ,(int)(ped*AdctoE),(int)((rms*AdctoE)/16.));
1667  mLadders[iLad]->mWafers[iWaf]->addNoiseToStripSignal(newStrip,iSide);
1668  NumberOfNoise++;
1669  }
1670  }
1671  }
1672  }
1673  return NumberOfNoise;
1674 }
StSsdPointList * getPoint()
Returns the point list attached to this wafer.
Definition: StSsdWafer.hh:106
void addCluster(StSsdCluster *ptr, Int_t iSide)
Attaches the ptr cluster on the iSide of the wafer.
Definition: StSsdWafer.cc:212
StSsdStripList * getStripP()
Returns the P-side strip list attached to this wafer.
Definition: StSsdWafer.hh:103
void sortStrip()
Definition: StSsdWafer.cc:243
void doLorentzShift(ssdDimensions_st *dimensions, Float_t mShift_hole, Float_t mShift_elec)
Definition: StSsdWafer.cc:446
StSsdStripList * getStripN()
Returns the N-side strip list attached to this wafer.
Definition: StSsdWafer.hh:104
StSsdBarrel(ssdDimensions_st *dimensions, ssdConfiguration_st *config=0)
Definition: StSsdBarrel.cc:164
Int_t doFindPackage(ssdDimensions_st *dimensions, StSsdClusterControl *clusterControl)
Definition: StSsdWafer.cc:492
void addStrip(StSsdStrip *ptr, Int_t iSide)
Definition: StSsdWafer.cc:201
Int_t readNoiseFromTable(St_sdm_calib_db *spa_noise, StSsdDynamicControl *dynamicControl)
Definition: StSsdBarrel.cc:345
void doClusterisation(Int_t *numberOfCluster, StSsdClusterControl *clusterControl)
Definition: StSsdWafer.cc:270
StSsdClusterList * getClusterN()
Returns the N-side cluster list attached to this wafer.
Definition: StSsdWafer.hh:99
StSsdClusterList * getClusterP()
Returns the P-side cluster list attached to this wafer.
Definition: StSsdWafer.hh:98
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169