StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St_sdm_Maker.cxx
1 // //
3 // St_sdm_Maker class for Makers //
4 // //
6 
7 #include <Stiostream.h>
8 #include <stdlib.h>
9 #include "St_sdm_Maker.h"
10 #include "St_DataSetIter.h"
11 
12 #include "tables/St_sdm_condition_par_Table.h"
13 #include "tables/St_sdm_geom_par_Table.h"
14 #include "tables/St_sdm_calib_par_Table.h"
15 #include "tables/St_sdm_calib_db_Table.h"
16 #include "tables/St_sdm_condition_db_Table.h"
17 
18 #include "TFile.h"
19 #include "TString.h"
20 #include "TRandom.h"
21 
22 ClassImp(St_sdm_Maker)
23 
24 //_____________________________________________________________________________
25 St_sdm_Maker::St_sdm_Maker(const char *name):
26 StMaker(name),
27 m_cond_par(0),
28 m_geom_par(0),
29 m_cal_par(0),
30 m_DBPath(0),
31 m_ParPath(0),
32 m_DBRandom(0)
33 {
34  //m_CondDBFile(0),
35  //m_CalibDBFile(0)
36 //m_noise(0),
37 //m_condition(0),
38 }
39 //_____________________________________________________________________________
40 St_sdm_Maker::~St_sdm_Maker()
41 {
42 }
43 //_____________________________________________________________________________
44 Int_t St_sdm_Maker::Init(){
45  m_DBRandom = new TRandom();
46  if(!m_ParPath)
47  {
48  cout<<" **** Path for Parameter Tables not set : Take default Parameter Tables "<<endl;
49  InitConditionPar();
50  InitCalibPar();
51  InitGeomPar();
52  }
53  else
54  {
55  cout<<"Parameter Tables Path : "<<m_ParPath->Data()<<endl;
56  cout<<"DB Tables Path : "<<m_DBPath->Data()<<endl;
57 
58  if (!(LoadConditionPar()))
59  {
60  cout<<" *** Condition Parameter Table not found : Take default parameters ***"<<endl;
61  InitConditionPar();
62  }
63 
64  if (!(LoadCalibPar()))
65  {
66  cout<<" *** Calibration Parameter Table not found : Take default parameters ***"<<endl;
67  InitCalibPar();
68  }
69 
70  if (!(LoadGeomPar()))
71  {
72  cout<<" *** Geometry Parameter Table not found : Take default parameters ***"<<endl;
73  InitGeomPar();
74  }
75  }
76 
77  sdm_geom_par_st *m_geom_par_t = m_geom_par->GetTable();
78 
79  mSsdLayer = m_geom_par_t[0].N_layer;
80  mSsdTotLadder = m_geom_par_t[0].N_ladder;
81  mSsdTotWafer = mSsdTotLadder*m_geom_par_t[0].N_waf_per_ladder;
82  mSsdTotPlane = 2*mSsdTotWafer;
83  mSsdTotA128 = m_geom_par_t[0].N_alice_per_side*mSsdTotPlane;
84  mSsdTotStrip = mSsdTotPlane*m_geom_par_t[0].N_strip_per_side;
85 
86  if(!m_DBPath)
87  {
88  cout<<" **** Path for DataBase Tables not set : Write in Local Directory "<<endl;
89  m_DBPath = new TString(".");
90  }
91 
92  TString *fCalibDBName = new TString("sdm_calib_db.root");
93  TFile m_CalibDBFile(((*m_DBPath)+(*fCalibDBName)).Data(),"RECREATE");
94  m_CalibDBFile.Close();
95 
96  TString *fCondDBName = new TString("sdm_condition_db.root");
97  TFile m_CondDBFile(((*m_DBPath)+(*fCondDBName)).Data(),"RECREATE");
98  m_CondDBFile.Close();
99 
100  delete fCalibDBName;
101  delete fCondDBName;
102  return StMaker::Init();
103 }
104 //_____________________________________________________________________________
106 {
107  BuildCalibDB();
108  BuildConditionDB();
109  return kStOK;
110 }
111 //_____________________________________________________________________________
112 void St_sdm_Maker::PrintInfo()
113 {
114  printf("**************************************************************\n");
115  printf("* $Id: St_sdm_Maker.cxx,v 1.3 2007/04/28 17:56:53 perev Exp $\n");
116  printf("**************************************************************\n");
117  if (Debug()) StMaker::PrintInfo();
118 }
119 //_____________________________________________________________________________
120 void St_sdm_Maker::SetParamPath(Char_t *ParPath)
121 {
122  if (ParPath) m_ParPath = new TString(ParPath);
123 }
124 //_____________________________________________________________________________
125 void St_sdm_Maker::SetDBPath(Char_t *DBPath)
126 {
127  if (DBPath) m_DBPath = new TString(DBPath);
128 }
129 //_____________________________________________________________________________
130 Bool_t St_sdm_Maker::LoadConditionPar()
131 {
132  TString *fCondName = new TString("sdm_condition_par.root");
133  TFile *fCond = new TFile(((*m_ParPath)+(*fCondName)).Data());
134 
135  if (!fCond->IsOpen()) return kFALSE;
136  St_sdm_condition_par *file_cond_par = ((St_sdm_condition_par*)fCond->Get("sdm_condition_par"));
137 
138  m_cond_par = new St_sdm_condition_par("sdm_condition_par",1);
139 // m_cond_par->SetNRow(0);
140  sdm_condition_par_st *m_cond_par_t = m_cond_par->GetTable();
141  sdm_condition_par_st *file_cond_par_t = file_cond_par->GetTable();
142 
143  m_cond_par->SetNRows(file_cond_par->GetNRows());
144 
145  m_cond_par_t[0].i_seed = file_cond_par_t[0].i_seed;
146  m_cond_par_t[0].N_active_ladder[0] = file_cond_par_t[0].N_active_ladder[0] ;
147  m_cond_par_t[0].N_active_ladder[1] = file_cond_par_t[0].N_active_ladder[1] ;
148  m_cond_par_t[0].N_active_ladder[2] = file_cond_par_t[0].N_active_ladder[2] ;
149  m_cond_par_t[0].N_active_ladder[3] = file_cond_par_t[0].N_active_ladder[3] ;
150  m_cond_par_t[0].N_active_ladder[4] = file_cond_par_t[0].N_active_ladder[4] ;
151  m_cond_par_t[0].N_active_ladder[5] = file_cond_par_t[0].N_active_ladder[5] ;
152  m_cond_par_t[0].N_active_ladder[6] = file_cond_par_t[0].N_active_ladder[6] ;
153  m_cond_par_t[0].N_active_ladder[7] = file_cond_par_t[0].N_active_ladder[7] ;
154  m_cond_par_t[0].N_active_ladder[8] = file_cond_par_t[0].N_active_ladder[8] ;
155  m_cond_par_t[0].N_active_ladder[9] = file_cond_par_t[0].N_active_ladder[9] ;
156  m_cond_par_t[0].N_active_ladder[10] = file_cond_par_t[0].N_active_ladder[10] ;
157  m_cond_par_t[0].N_active_ladder[11] = file_cond_par_t[0].N_active_ladder[11] ;
158  m_cond_par_t[0].N_active_ladder[12] = file_cond_par_t[0].N_active_ladder[12] ;
159  m_cond_par_t[0].N_active_ladder[13] = file_cond_par_t[0].N_active_ladder[13] ;
160  m_cond_par_t[0].N_active_ladder[14] = file_cond_par_t[0].N_active_ladder[14] ;
161  m_cond_par_t[0].N_active_ladder[15] = file_cond_par_t[0].N_active_ladder[15] ;
162  m_cond_par_t[0].N_active_ladder[16] = file_cond_par_t[0].N_active_ladder[16] ;
163  m_cond_par_t[0].N_active_ladder[17] = file_cond_par_t[0].N_active_ladder[17] ;
164  m_cond_par_t[0].N_active_ladder[18] = file_cond_par_t[0].N_active_ladder[18] ;
165  m_cond_par_t[0].N_active_ladder[19] = file_cond_par_t[0].N_active_ladder[19] ;
166  m_cond_par_t[0].p_bad_wafer = file_cond_par_t[0].p_bad_wafer ;
167  m_cond_par_t[0].p_bad_alice = file_cond_par_t[0].p_bad_alice ;
168  m_cond_par_t[0].p_bad_strip = file_cond_par_t[0].p_bad_strip ;
169 
170  fCond->Close();
171  delete fCond;
172  delete fCondName;
173  if (!m_cond_par) return kFALSE;
174  return kTRUE;
175 
176 }
177 //_____________________________________________________________________________
178 Bool_t St_sdm_Maker::LoadGeomPar()
179 {
180  TString *fGeomName = new TString("sdm_geom_par.root");
181  TFile *fGeom = new TFile(((*m_ParPath)+(*fGeomName)).Data());
182 
183  if (!fGeom->IsOpen()) return kFALSE;
184 
185  St_sdm_geom_par *file_geom_par = ((St_sdm_geom_par*)fGeom->Get("sdm_geom_par"));
186 
187  m_geom_par = new St_sdm_geom_par("sdm_geom_par",1);
188 // m_geom_par->SetNRow(0);
189  sdm_geom_par_st *m_geom_par_t = m_geom_par->GetTable();
190 
191  sdm_geom_par_st *file_geom_par_t = file_geom_par->GetTable();
192 
193  m_geom_par->SetNRows(file_geom_par->GetNRows());
194 
195  m_geom_par_t[0].N_layer = file_geom_par_t[0].N_layer ;
196  m_geom_par_t[0].N_ladder = file_geom_par_t[0].N_ladder ;
197  m_geom_par_t[0].N_waf_per_ladder = file_geom_par_t[0].N_waf_per_ladder ;
198  m_geom_par_t[0].N_alice_per_side = file_geom_par_t[0].N_alice_per_side ;
199  m_geom_par_t[0].N_strip_per_side = file_geom_par_t[0].N_strip_per_side ;
200  m_geom_par_t[0].L_strip_pitch = file_geom_par_t[0].L_strip_pitch ;
201  m_geom_par_t[0].L_stereo_angle = file_geom_par_t[0].L_stereo_angle ;
202  m_geom_par_t[0].L_wafer_tot_l = file_geom_par_t[0].L_wafer_tot_l ;
203  m_geom_par_t[0].L_wafer_tot_w = file_geom_par_t[0].L_wafer_tot_w ;
204  m_geom_par_t[0].L_wafer_tot_t = file_geom_par_t[0].L_wafer_tot_t ;
205  m_geom_par_t[0].L_wafer_act_l = file_geom_par_t[0].L_wafer_act_l ;
206  m_geom_par_t[0].L_wafer_act_w = file_geom_par_t[0].L_wafer_act_w ;
207 
208  fGeom->Close();
209  delete fGeom;
210  delete fGeomName;
211  if (!m_geom_par) return kFALSE;
212  return kTRUE;
213 
214  }
215 //_____________________________________________________________________________
216 Bool_t St_sdm_Maker::LoadCalibPar()
217 {
218  TString *fCalibName = new TString("sdm_calib_par.root");
219  TFile *fCalib = new TFile(((*m_ParPath)+(*fCalibName)).Data());
220 
221  if (!fCalib->IsOpen()) return kFALSE;
222 
223  St_sdm_calib_par *file_cal_par = ((St_sdm_calib_par*)fCalib->Get("sdm_calib_par"));
224 
225  m_cal_par = new St_sdm_calib_par("sdm_calib_par",1);
226 // m_cal_par->SetNRow(0);
227  sdm_calib_par_st *m_cal_par_t = m_cal_par->GetTable();
228 
229  sdm_calib_par_st *file_cal_par_t = file_cal_par->GetTable();
230 
231  m_cal_par->SetNRows(file_cal_par->GetNRows());
232 
233  m_cal_par_t[0].i_seed = file_cal_par_t[0].i_seed ;
234  m_cal_par_t[0].barrel_ped = file_cal_par_t[0].barrel_ped ;
235  m_cal_par_t[0].wafer_sig = file_cal_par_t[0].wafer_sig ;
236  m_cal_par_t[0].alice_sig = file_cal_par_t[0].alice_sig ;
237  m_cal_par_t[0].strip_P_sig = file_cal_par_t[0].strip_P_sig ;
238  m_cal_par_t[0].strip_N_sig = file_cal_par_t[0].strip_N_sig ;
239  m_cal_par_t[0].strip_P_noise = file_cal_par_t[0].strip_P_noise ;
240  m_cal_par_t[0].strip_N_noise = file_cal_par_t[0].strip_N_noise ;
241  m_cal_par_t[0].strip_P_noise_sig = file_cal_par_t[0].strip_P_noise_sig ;
242  m_cal_par_t[0].strip_N_noise_sig = file_cal_par_t[0].strip_N_noise_sig ;
243  m_cal_par_t[0].n_strip_P_factor = file_cal_par_t[0].n_strip_P_factor ;
244  m_cal_par_t[0].n_strip_N_factor = file_cal_par_t[0].n_strip_N_factor ;
245  m_cal_par_t[0].n_noisy_strip = file_cal_par_t[0].n_noisy_strip ;
246 
247  fCalib->Close();
248  delete fCalib;
249  delete fCalibName;
250  if (!m_cal_par) return kFALSE;
251  return kTRUE;
252 }
253 //_____________________________________________________________________________
254 void St_sdm_Maker::InitConditionPar()
255 {
256  m_cond_par = new St_sdm_condition_par("sdm_condition_par",1);
257  m_cond_par->SetNRows(1);
258  sdm_condition_par_st *m_cond_par_t = m_cond_par->GetTable();
259 
260  m_cond_par_t[0].i_seed = 111111;// random initialisation seed
261  m_cond_par_t[0].N_active_ladder[0] = 1 ;// array of active(1) and dead(0) ladders
262  m_cond_par_t[0].N_active_ladder[1] = 1 ;
263  m_cond_par_t[0].N_active_ladder[2] = 1 ;
264  m_cond_par_t[0].N_active_ladder[3] = 1 ;
265  m_cond_par_t[0].N_active_ladder[4] = 1 ;
266  m_cond_par_t[0].N_active_ladder[5] = 1 ;
267  m_cond_par_t[0].N_active_ladder[6] = 1 ;
268  m_cond_par_t[0].N_active_ladder[7] = 1 ;
269  m_cond_par_t[0].N_active_ladder[8] = 1 ;
270  m_cond_par_t[0].N_active_ladder[9] = 1 ;
271  m_cond_par_t[0].N_active_ladder[10] = 1 ;
272  m_cond_par_t[0].N_active_ladder[11] = 1 ;
273  m_cond_par_t[0].N_active_ladder[12] = 1 ;
274  m_cond_par_t[0].N_active_ladder[13] = 1 ;
275  m_cond_par_t[0].N_active_ladder[14] = 1 ;
276  m_cond_par_t[0].N_active_ladder[15] = 1 ;
277  m_cond_par_t[0].N_active_ladder[16] = 1 ;
278  m_cond_par_t[0].N_active_ladder[17] = 1 ;
279  m_cond_par_t[0].N_active_ladder[18] = 1 ;
280  m_cond_par_t[0].N_active_ladder[19] = 1 ;
281  m_cond_par_t[0].p_bad_wafer = 0.0;//percentage of dead wafers
282  m_cond_par_t[0].p_bad_alice = 0.0;//percentage of dead A128C
283  m_cond_par_t[0].p_bad_strip = 0.00;//percentage of dead strips
284 }
285 //_____________________________________________________________________________
286 void St_sdm_Maker::InitGeomPar()
287 {
288  m_geom_par = new St_sdm_geom_par("sdm_geom_par",1);
289  m_geom_par->SetNRows(1);
290  sdm_geom_par_st *m_geom_par_t = m_geom_par->GetTable();
291 
292  m_geom_par_t[0].N_layer = 7 ;// SSD layer number
293  m_geom_par_t[0].N_ladder = 20 ;// Nbr ladder per layer
294  m_geom_par_t[0].N_waf_per_ladder = 16 ;// Nbr wafer per ladder
295  m_geom_par_t[0].N_alice_per_side = 6 ;// Nbr A128C per wafer side
296  m_geom_par_t[0].N_strip_per_side = 768 ;// Nbr Strip per wafer side
297  m_geom_par_t[0].L_strip_pitch = 0.0095;// strip pitch
298  m_geom_par_t[0].L_stereo_angle = 0.0175;// half stereo angle
299  m_geom_par_t[0].L_wafer_tot_l = 3.75 ;// half wafer total length
300  m_geom_par_t[0].L_wafer_tot_w = 2.1 ;// half wafer total width
301  m_geom_par_t[0].L_wafer_tot_t = 0.015 ;// half wafer total thickness
302  m_geom_par_t[0].L_wafer_act_l = 3.65 ;// half wafer active length
303  m_geom_par_t[0].L_wafer_act_w = 2.0 ;// half wafer active width
304 }
305 //_____________________________________________________________________________
306 void St_sdm_Maker::InitCalibPar()
307 {
308  m_cal_par = new St_sdm_calib_par("sdm_calib_par",1);
309  m_cal_par->SetNRows(1);
310  sdm_calib_par_st *m_cal_par_t = m_cal_par->GetTable();
311 
312  m_cal_par_t[0].i_seed = 111111;// random initialisation seed
313  m_cal_par_t[0].barrel_ped = 100000;// offset
314  m_cal_par_t[0].wafer_sig = 10000 ;// dispersion around the offset
315  m_cal_par_t[0].alice_sig = 5000 ;// dispersion of alice pedestal
316  m_cal_par_t[0].strip_P_sig = 50 ;// dispersion of strip P pedestal
317  m_cal_par_t[0].strip_N_sig = 50 ;// dispersion of strip N pedestal
318  m_cal_par_t[0].strip_P_noise = 1400 ;//(700) mean value of strip P noise
319  m_cal_par_t[0].strip_N_noise = 2200 ;//(1100) mean value of strip N noise
320  m_cal_par_t[0].strip_P_noise_sig = 50 ;//(50) dispersion of strip P noise around mean value
321  m_cal_par_t[0].strip_N_noise_sig = 70 ;//(70) dispersion of strip N noise around mean value
322  m_cal_par_t[0].n_strip_P_factor = 10. ;// max noise multiplication factor for a noisy P strip
323  m_cal_par_t[0].n_strip_N_factor = 10. ;// max noise multiplication factor for a noisy N strip
324  m_cal_par_t[0].n_noisy_strip = 0. ;// percentage of noisy strip
325 }
326 //_____________________________________________________________________________
327 void St_sdm_Maker::BuildCalibDB()
328 {
329  Int_t iSide = 0 ;
330  Int_t lSsdPedestal = 0 ;
331  Int_t lWaferPedestal = 0 ;
332  Int_t lStripNoise = 0 ;
333  Int_t lStripPedestal = 0 ;
334  Int_t iBin = 0 ;
335 
336  const Int_t nA128PerSide = mSsdTotA128/mSsdTotPlane;
337  const Int_t nStripPerA128 = mSsdTotStrip/mSsdTotA128;
338  const Int_t nStripPerSide = mSsdTotStrip/mSsdTotPlane;
339 
340  sdm_calib_par_st *m_cal_par_t = m_cal_par->GetTable();
341 
342  Int_t *mSignalPar = new Int_t[9]; // allocation...
343  Float_t *mNoisyPar = new Float_t[3]; // allocation...
344  Int_t *mPedestalArray = new Int_t[mSsdTotStrip]; // allocation...
345  Int_t *mNoiseArray = new Int_t[mSsdTotStrip]; // allocation...
346 
347  mSignalPar[0] = m_cal_par_t[0].barrel_ped;
348  mSignalPar[1] = m_cal_par_t[0].wafer_sig;
349  mSignalPar[2] = m_cal_par_t[0].alice_sig;
350  mSignalPar[3] = m_cal_par_t[0].strip_P_sig;
351  mSignalPar[4] = m_cal_par_t[0].strip_N_sig;
352  mSignalPar[5] = m_cal_par_t[0].strip_P_noise;
353  mSignalPar[6] = m_cal_par_t[0].strip_N_noise;
354  mSignalPar[7] = m_cal_par_t[0].strip_P_noise_sig;
355  mSignalPar[8] = m_cal_par_t[0].strip_N_noise_sig;
356 
357  mNoisyPar[0] = m_cal_par_t[0].n_strip_P_factor;
358  mNoisyPar[1] = m_cal_par_t[0].n_strip_N_factor;
359  mNoisyPar[2] = m_cal_par_t[0].n_noisy_strip;
360 
361  Int_t i = 0;
362  Int_t j = 0;
363  Int_t k = 0;
364 
365 
366  for(i = 0 ; i < mSsdTotPlane ; i++)
367  {
368  iSide = (i%2 == 0) ? 0 : 1 ;
369  lSsdPedestal = Int_t((mSignalPar[0])+m_DBRandom->Gaus(0.,Double_t(mSignalPar[1])));
370 
371  for(j = 0 ; j < nA128PerSide ; j++)
372  {
373  lWaferPedestal = lSsdPedestal + Int_t(m_DBRandom->Gaus(0.,mSignalPar[2]));
374  for(k = 0 ; k < nStripPerA128 ; k++ )
375  {
376  switch(iSide)
377  {
378  case 0 :
379  lStripNoise = Int_t(mSignalPar[5]+(m_DBRandom->Gaus(0.,mSignalPar[7])));
380  lStripPedestal = lWaferPedestal + Int_t(m_DBRandom->Gaus(0.,mSignalPar[3]));
381  break;
382  case 1 :
383  lStripNoise = Int_t(mSignalPar[6]+(m_DBRandom->Gaus(0.,mSignalPar[8])));
384  lStripPedestal = lWaferPedestal + Int_t(m_DBRandom->Gaus(0.,mSignalPar[4]));
385  break;
386  }
387  iBin = i*nStripPerSide + j*nStripPerA128 + k ;
388  mPedestalArray[iBin] = lStripPedestal;
389  mNoiseArray[iBin] = lStripNoise;
390  }
391  }
392  }
393 
394  Int_t nNoisyStrip = Int_t(mSsdTotStrip*m_cal_par_t[0].n_noisy_strip);
395  Float_t factorP = (m_cal_par_t[0].n_strip_P_factor)-1.;
396  Float_t factorN = (m_cal_par_t[0].n_strip_N_factor)-1.;
397  Int_t *noisyTmp = new Int_t[mSsdTotStrip]; // allocation...
398 
399  for ( i = 0 ; i < mSsdTotStrip ; i++)
400  {
401  noisyTmp[i] = i ;
402  }
403  Int_t localSize = mSsdTotStrip;
404  Int_t st = 0;
405  Float_t fact = 0.;
406 
407  i = 0;
408  while (i < nNoisyStrip)
409  {
410  st = Int_t(m_DBRandom->Rndm()*localSize);
411  iSide = (Int_t(st/768))%2;
412  switch (iSide)
413  {
414  case 0:
415  fact = 1.+Float_t(m_DBRandom->Rndm()*factorP);
416  mNoiseArray[noisyTmp[st]] = Int_t(mNoiseArray[noisyTmp[st]]*fact);
417  break;
418  case 1:
419  fact = 1+Float_t(m_DBRandom->Rndm()*factorN);
420  mNoiseArray[noisyTmp[st]] = Int_t(mNoiseArray[noisyTmp[st]]*fact);
421  break;
422  }
423  noisyTmp[st] = noisyTmp[localSize-1];
424  localSize--;
425  i++;
426  }
427 
428  Int_t iStrip = 0;
429 
430  St_sdm_calib_db *m_noise = new St_sdm_calib_db("sdm_calib_db",500000); // allocation...
431  m_noise->SetNRows(0);
432  sdm_calib_db_st *m_noise_t = m_noise->GetTable();
433  cout<<" noise Used Rows = "<<m_noise->GetNRows()<<endl;
434  cout<<" noise Allocated Rows = "<<m_noise->GetTableSize()<<endl;
435 
436  for(i = 0 ; i < mSsdTotStrip ; i++ ){
437 
438  iStrip = ConvertStripId(i+1);
439 
440  m_noise_t[i].id_strip = iStrip;
441  m_noise_t[i].n_pedestal = mPedestalArray[i];
442  m_noise_t[i].n_sigma = mNoiseArray[i];
443  m_noise->SetNRows(i+1);
444  }
445 
446  TString *fCalibDBName = new TString("sdm_calib_db.root");
447  TFile *m_CalibDBFile = new TFile(((*m_DBPath)+(*fCalibDBName)).Data(),"RECREATE");
448  m_noise->Write();
449  m_CalibDBFile->Close();
450 
451  delete[] noisyTmp;
452  delete[] mSignalPar;
453  delete[] mNoisyPar;
454  delete[] mPedestalArray;
455  delete[] mNoiseArray;
456  delete fCalibDBName;
457  delete m_noise;
458  delete m_CalibDBFile;
459 }
460 //_____________________________________________________________________________
461 void St_sdm_Maker::BuildConditionDB()
462 {
463  sdm_condition_par_st *m_cond_par_t = m_cond_par->GetTable();
464 
465  Int_t *mSsdActiveLadder = new Int_t[mSsdTotLadder];
466  Int_t *mSsdActivePlane = new Int_t[mSsdTotPlane];
467  Int_t *mSsdActiveA128 = new Int_t[mSsdTotA128];
468  Int_t *mSsdActiveStrip = new Int_t[mSsdTotStrip];
469 
470  Int_t i = 0 ;
471  Int_t j = 0 ;
472  for (i = 0 ; i < mSsdTotLadder ; i++)
473  {
474 
475  mSsdActiveLadder[i] = Int_t(m_cond_par_t[0].N_active_ladder[i]);
476 
477  }
478  for (i = 0 ; i < mSsdTotLadder ; i++ )
479  {
480  Int_t tmp_loc = 0;
481  if (mSsdActiveLadder[i])
482  {
483  tmp_loc = mSsdTotPlane/mSsdTotLadder;
484  for (j = 0 ; j < tmp_loc ; j++) mSsdActivePlane[j+tmp_loc*i] = 1;
485  tmp_loc = mSsdTotA128/mSsdTotLadder;
486  for (j = 0 ; j < tmp_loc ; j++) mSsdActiveA128[j+tmp_loc*i] = 1;
487  tmp_loc = mSsdTotStrip/mSsdTotLadder;
488  for (j = 0 ; j < tmp_loc ; j++) mSsdActiveStrip[j+tmp_loc*i] = 1;
489  }
490  else
491  {
492  tmp_loc = mSsdTotPlane/mSsdTotLadder;
493  for (j = 0 ; j < tmp_loc ; j++) mSsdActivePlane[j+tmp_loc*i] = 0;
494  tmp_loc = mSsdTotA128/mSsdTotLadder;
495  for (j = 0 ; j < tmp_loc ; j++) mSsdActiveA128[j+tmp_loc*i] = 0;
496  tmp_loc = mSsdTotStrip/mSsdTotLadder;
497  for (j = 0 ; j < tmp_loc ; j++) mSsdActiveStrip[j+tmp_loc*i] = 0;
498  }
499  }
500 
501  Int_t nDeadWafer = Int_t(mSsdTotWafer*m_cond_par_t[0].p_bad_wafer);
502  Int_t nDeadA128 = Int_t(mSsdTotA128*m_cond_par_t[0].p_bad_alice);
503  Int_t nDeadStrip = Int_t(mSsdTotStrip*m_cond_par_t[0].p_bad_strip);
504  Int_t iBin = 0 ;
505  Int_t *nTmpDeadStrip = new Int_t[mSsdTotStrip];
506  Int_t LocalSize = 0;
507 
508  Int_t nStripPerA128 = mSsdTotStrip/mSsdTotA128;
509  Int_t nStripPerWafer = mSsdTotStrip/mSsdTotWafer;
510 
511  Int_t ii = 0;
512  Int_t st = 0;
513  Int_t jj = 0;
514  Int_t ch = 0;
515  Int_t ss = 0;
516  for (ii =0 ; ii < mSsdTotStrip ; ii++)
517  {
518  if (mSsdActiveStrip[ii])
519  {
520  nTmpDeadStrip[LocalSize] = ii;
521  LocalSize++;
522  }
523  }
524  ii = 0;
525  while (ii < nDeadStrip)
526  {
527  st = Int_t (m_DBRandom->Rndm()*LocalSize);
528  mSsdActiveStrip[nTmpDeadStrip[st]] = 0 ;
529  nTmpDeadStrip[st] = nTmpDeadStrip[LocalSize - 1];
530  nTmpDeadStrip[LocalSize - 1] = 0;
531  LocalSize--;
532  ii++;
533  }
534  ii = 0;
535  while (ii < nDeadA128)
536  {
537  ch = Int_t(m_DBRandom->Rndm()*mSsdTotA128);
538  if ( mSsdActiveA128[ch])
539  {
540  for(jj = 0 ; jj <nStripPerA128 ; jj++)
541  {
542  iBin = jj + ch*nStripPerA128;
543  mSsdActiveStrip[iBin] = 0 ;
544  }
545  mSsdActiveA128[ch] = 0 ;
546  ii++;
547  }
548  }
549 
550  ii = 0;
551  while (ii < nDeadWafer)
552  {
553  ss = Int_t(m_DBRandom->Rndm()*mSsdTotWafer);
554  if ((mSsdActivePlane[2*ss])||(mSsdActivePlane[2*ss+1]))
555  {
556  for(jj = 0 ; jj < nStripPerWafer ; jj++)
557  {
558  iBin = jj + ss*nStripPerWafer ;
559  mSsdActiveStrip[iBin] = 0 ;
560 
561  }
562  mSsdActivePlane[2*ss] = 0 ; // p-side plane
563  mSsdActivePlane[2*ss+1] = 0 ; // n-side plane
564  }
565  ii++;
566  }
567 
568  Int_t iStrip = 0;
569 
570  St_sdm_condition_db *m_condition = new St_sdm_condition_db("sdm_condition_db",500000);
571  m_condition->SetNRows(0);
572  sdm_condition_db_st *m_condition_t = m_condition->GetTable();
573 
574  for(jj = 0 ; jj < mSsdTotStrip ; jj++ ){
575 
576  iStrip = ConvertStripId(jj+1);
577 
578  m_condition_t[jj].id_strip = iStrip;
579  m_condition_t[jj].is_active = mSsdActiveStrip[jj];
580  m_condition->SetNRows(jj+1);
581  }
582 
583  TString *fCondDBName = new TString("sdm_condition_db.root");
584  TFile *m_CondDBFile = new TFile (((*m_DBPath)+(*fCondDBName)).Data(),"RECREATE");
585  m_condition->Write();
586  m_CondDBFile->Close();
587 
588  delete[] nTmpDeadStrip;
589  delete[] mSsdActiveLadder;
590  delete[] mSsdActivePlane;
591  delete[] mSsdActiveA128;
592  delete[] mSsdActiveStrip;
593  delete fCondDBName;
594  delete m_condition;
595  delete m_CondDBFile;
596 }
597 //__________________________________________________________
598 Int_t St_sdm_Maker::WaferNumbToIdWafer(Int_t wafer_numb)
599 {
600  Int_t nWaferPerLadder = mSsdTotWafer/mSsdTotLadder;
601  Int_t iLadder = 1+Int_t(wafer_numb/nWaferPerLadder);
602  Int_t iWafer = wafer_numb-((iLadder-1)*nWaferPerLadder)+1;
603  return mSsdLayer*1000 + iWafer*100 + iLadder;
604 }
605 //__________________________________________________________
606 Int_t St_sdm_Maker::ConvertStripId(Int_t st)
607 {
608  Int_t iWafer = 0;
609  Int_t iSide = 0 ;
610  Int_t idStrip = 0;
611  Int_t nStripPerWafer = Int_t(mSsdTotStrip/mSsdTotWafer);
612 
613  iWafer = Int_t((st-1)/nStripPerWafer);
614  idStrip = st - iWafer*nStripPerWafer;
615  iWafer = WaferNumbToIdWafer(iWafer);
616  iSide = (idStrip <= (nStripPerWafer/2)) ? 0 : 1 ;
617 
618  if(iSide) idStrip -= (nStripPerWafer/2);
619  idStrip = 10000*(10*idStrip+iSide)+iWafer ;
620  return idStrip;
621 }
Definition: Stypes.h:40
virtual Int_t Make()