00001
00002
00003
00004
00006
00007 #include <Stiostream.h>
00008 #include <stdlib.h>
00009 #include "St_sdm_Maker.h"
00010 #include "St_DataSetIter.h"
00011
00012 #include "tables/St_sdm_condition_par_Table.h"
00013 #include "tables/St_sdm_geom_par_Table.h"
00014 #include "tables/St_sdm_calib_par_Table.h"
00015 #include "tables/St_sdm_calib_db_Table.h"
00016 #include "tables/St_sdm_condition_db_Table.h"
00017
00018 #include "TFile.h"
00019 #include "TString.h"
00020 #include "TRandom.h"
00021
00022 ClassImp(St_sdm_Maker)
00023
00024
00025 St_sdm_Maker::St_sdm_Maker(const char *name):
00026 StMaker(name),
00027 m_cond_par(0),
00028 m_geom_par(0),
00029 m_cal_par(0),
00030 m_DBPath(0),
00031 m_ParPath(0),
00032 m_DBRandom(0)
00033 {
00034
00035
00036
00037
00038 }
00039
00040 St_sdm_Maker::~St_sdm_Maker()
00041 {
00042 }
00043
00044 Int_t St_sdm_Maker::Init(){
00045 m_DBRandom = new TRandom();
00046 if(!m_ParPath)
00047 {
00048 cout<<" **** Path for Parameter Tables not set : Take default Parameter Tables "<<endl;
00049 InitConditionPar();
00050 InitCalibPar();
00051 InitGeomPar();
00052 }
00053 else
00054 {
00055 cout<<"Parameter Tables Path : "<<m_ParPath->Data()<<endl;
00056 cout<<"DB Tables Path : "<<m_DBPath->Data()<<endl;
00057
00058 if (!(LoadConditionPar()))
00059 {
00060 cout<<" *** Condition Parameter Table not found : Take default parameters ***"<<endl;
00061 InitConditionPar();
00062 }
00063
00064 if (!(LoadCalibPar()))
00065 {
00066 cout<<" *** Calibration Parameter Table not found : Take default parameters ***"<<endl;
00067 InitCalibPar();
00068 }
00069
00070 if (!(LoadGeomPar()))
00071 {
00072 cout<<" *** Geometry Parameter Table not found : Take default parameters ***"<<endl;
00073 InitGeomPar();
00074 }
00075 }
00076
00077 sdm_geom_par_st *m_geom_par_t = m_geom_par->GetTable();
00078
00079 mSsdLayer = m_geom_par_t[0].N_layer;
00080 mSsdTotLadder = m_geom_par_t[0].N_ladder;
00081 mSsdTotWafer = mSsdTotLadder*m_geom_par_t[0].N_waf_per_ladder;
00082 mSsdTotPlane = 2*mSsdTotWafer;
00083 mSsdTotA128 = m_geom_par_t[0].N_alice_per_side*mSsdTotPlane;
00084 mSsdTotStrip = mSsdTotPlane*m_geom_par_t[0].N_strip_per_side;
00085
00086 if(!m_DBPath)
00087 {
00088 cout<<" **** Path for DataBase Tables not set : Write in Local Directory "<<endl;
00089 m_DBPath = new TString(".");
00090 }
00091
00092 TString *fCalibDBName = new TString("sdm_calib_db.root");
00093 TFile m_CalibDBFile(((*m_DBPath)+(*fCalibDBName)).Data(),"RECREATE");
00094 m_CalibDBFile.Close();
00095
00096 TString *fCondDBName = new TString("sdm_condition_db.root");
00097 TFile m_CondDBFile(((*m_DBPath)+(*fCondDBName)).Data(),"RECREATE");
00098 m_CondDBFile.Close();
00099
00100 delete fCalibDBName;
00101 delete fCondDBName;
00102 return StMaker::Init();
00103 }
00104
00105 Int_t St_sdm_Maker::Make()
00106 {
00107 BuildCalibDB();
00108 BuildConditionDB();
00109 return kStOK;
00110 }
00111
00112 void St_sdm_Maker::PrintInfo()
00113 {
00114 printf("**************************************************************\n");
00115 printf("* $Id: St_sdm_Maker.cxx,v 1.3 2007/04/28 17:56:53 perev Exp $\n");
00116 printf("**************************************************************\n");
00117 if (Debug()) StMaker::PrintInfo();
00118 }
00119
00120 void St_sdm_Maker::SetParamPath(Char_t *ParPath)
00121 {
00122 if (ParPath) m_ParPath = new TString(ParPath);
00123 }
00124
00125 void St_sdm_Maker::SetDBPath(Char_t *DBPath)
00126 {
00127 if (DBPath) m_DBPath = new TString(DBPath);
00128 }
00129
00130 Bool_t St_sdm_Maker::LoadConditionPar()
00131 {
00132 TString *fCondName = new TString("sdm_condition_par.root");
00133 TFile *fCond = new TFile(((*m_ParPath)+(*fCondName)).Data());
00134
00135 if (!fCond->IsOpen()) return kFALSE;
00136 St_sdm_condition_par *file_cond_par = ((St_sdm_condition_par*)fCond->Get("sdm_condition_par"));
00137
00138 m_cond_par = new St_sdm_condition_par("sdm_condition_par",1);
00139
00140 sdm_condition_par_st *m_cond_par_t = m_cond_par->GetTable();
00141 sdm_condition_par_st *file_cond_par_t = file_cond_par->GetTable();
00142
00143 m_cond_par->SetNRows(file_cond_par->GetNRows());
00144
00145 m_cond_par_t[0].i_seed = file_cond_par_t[0].i_seed;
00146 m_cond_par_t[0].N_active_ladder[0] = file_cond_par_t[0].N_active_ladder[0] ;
00147 m_cond_par_t[0].N_active_ladder[1] = file_cond_par_t[0].N_active_ladder[1] ;
00148 m_cond_par_t[0].N_active_ladder[2] = file_cond_par_t[0].N_active_ladder[2] ;
00149 m_cond_par_t[0].N_active_ladder[3] = file_cond_par_t[0].N_active_ladder[3] ;
00150 m_cond_par_t[0].N_active_ladder[4] = file_cond_par_t[0].N_active_ladder[4] ;
00151 m_cond_par_t[0].N_active_ladder[5] = file_cond_par_t[0].N_active_ladder[5] ;
00152 m_cond_par_t[0].N_active_ladder[6] = file_cond_par_t[0].N_active_ladder[6] ;
00153 m_cond_par_t[0].N_active_ladder[7] = file_cond_par_t[0].N_active_ladder[7] ;
00154 m_cond_par_t[0].N_active_ladder[8] = file_cond_par_t[0].N_active_ladder[8] ;
00155 m_cond_par_t[0].N_active_ladder[9] = file_cond_par_t[0].N_active_ladder[9] ;
00156 m_cond_par_t[0].N_active_ladder[10] = file_cond_par_t[0].N_active_ladder[10] ;
00157 m_cond_par_t[0].N_active_ladder[11] = file_cond_par_t[0].N_active_ladder[11] ;
00158 m_cond_par_t[0].N_active_ladder[12] = file_cond_par_t[0].N_active_ladder[12] ;
00159 m_cond_par_t[0].N_active_ladder[13] = file_cond_par_t[0].N_active_ladder[13] ;
00160 m_cond_par_t[0].N_active_ladder[14] = file_cond_par_t[0].N_active_ladder[14] ;
00161 m_cond_par_t[0].N_active_ladder[15] = file_cond_par_t[0].N_active_ladder[15] ;
00162 m_cond_par_t[0].N_active_ladder[16] = file_cond_par_t[0].N_active_ladder[16] ;
00163 m_cond_par_t[0].N_active_ladder[17] = file_cond_par_t[0].N_active_ladder[17] ;
00164 m_cond_par_t[0].N_active_ladder[18] = file_cond_par_t[0].N_active_ladder[18] ;
00165 m_cond_par_t[0].N_active_ladder[19] = file_cond_par_t[0].N_active_ladder[19] ;
00166 m_cond_par_t[0].p_bad_wafer = file_cond_par_t[0].p_bad_wafer ;
00167 m_cond_par_t[0].p_bad_alice = file_cond_par_t[0].p_bad_alice ;
00168 m_cond_par_t[0].p_bad_strip = file_cond_par_t[0].p_bad_strip ;
00169
00170 fCond->Close();
00171 delete fCond;
00172 delete fCondName;
00173 if (!m_cond_par) return kFALSE;
00174 return kTRUE;
00175
00176 }
00177
00178 Bool_t St_sdm_Maker::LoadGeomPar()
00179 {
00180 TString *fGeomName = new TString("sdm_geom_par.root");
00181 TFile *fGeom = new TFile(((*m_ParPath)+(*fGeomName)).Data());
00182
00183 if (!fGeom->IsOpen()) return kFALSE;
00184
00185 St_sdm_geom_par *file_geom_par = ((St_sdm_geom_par*)fGeom->Get("sdm_geom_par"));
00186
00187 m_geom_par = new St_sdm_geom_par("sdm_geom_par",1);
00188
00189 sdm_geom_par_st *m_geom_par_t = m_geom_par->GetTable();
00190
00191 sdm_geom_par_st *file_geom_par_t = file_geom_par->GetTable();
00192
00193 m_geom_par->SetNRows(file_geom_par->GetNRows());
00194
00195 m_geom_par_t[0].N_layer = file_geom_par_t[0].N_layer ;
00196 m_geom_par_t[0].N_ladder = file_geom_par_t[0].N_ladder ;
00197 m_geom_par_t[0].N_waf_per_ladder = file_geom_par_t[0].N_waf_per_ladder ;
00198 m_geom_par_t[0].N_alice_per_side = file_geom_par_t[0].N_alice_per_side ;
00199 m_geom_par_t[0].N_strip_per_side = file_geom_par_t[0].N_strip_per_side ;
00200 m_geom_par_t[0].L_strip_pitch = file_geom_par_t[0].L_strip_pitch ;
00201 m_geom_par_t[0].L_stereo_angle = file_geom_par_t[0].L_stereo_angle ;
00202 m_geom_par_t[0].L_wafer_tot_l = file_geom_par_t[0].L_wafer_tot_l ;
00203 m_geom_par_t[0].L_wafer_tot_w = file_geom_par_t[0].L_wafer_tot_w ;
00204 m_geom_par_t[0].L_wafer_tot_t = file_geom_par_t[0].L_wafer_tot_t ;
00205 m_geom_par_t[0].L_wafer_act_l = file_geom_par_t[0].L_wafer_act_l ;
00206 m_geom_par_t[0].L_wafer_act_w = file_geom_par_t[0].L_wafer_act_w ;
00207
00208 fGeom->Close();
00209 delete fGeom;
00210 delete fGeomName;
00211 if (!m_geom_par) return kFALSE;
00212 return kTRUE;
00213
00214 }
00215
00216 Bool_t St_sdm_Maker::LoadCalibPar()
00217 {
00218 TString *fCalibName = new TString("sdm_calib_par.root");
00219 TFile *fCalib = new TFile(((*m_ParPath)+(*fCalibName)).Data());
00220
00221 if (!fCalib->IsOpen()) return kFALSE;
00222
00223 St_sdm_calib_par *file_cal_par = ((St_sdm_calib_par*)fCalib->Get("sdm_calib_par"));
00224
00225 m_cal_par = new St_sdm_calib_par("sdm_calib_par",1);
00226
00227 sdm_calib_par_st *m_cal_par_t = m_cal_par->GetTable();
00228
00229 sdm_calib_par_st *file_cal_par_t = file_cal_par->GetTable();
00230
00231 m_cal_par->SetNRows(file_cal_par->GetNRows());
00232
00233 m_cal_par_t[0].i_seed = file_cal_par_t[0].i_seed ;
00234 m_cal_par_t[0].barrel_ped = file_cal_par_t[0].barrel_ped ;
00235 m_cal_par_t[0].wafer_sig = file_cal_par_t[0].wafer_sig ;
00236 m_cal_par_t[0].alice_sig = file_cal_par_t[0].alice_sig ;
00237 m_cal_par_t[0].strip_P_sig = file_cal_par_t[0].strip_P_sig ;
00238 m_cal_par_t[0].strip_N_sig = file_cal_par_t[0].strip_N_sig ;
00239 m_cal_par_t[0].strip_P_noise = file_cal_par_t[0].strip_P_noise ;
00240 m_cal_par_t[0].strip_N_noise = file_cal_par_t[0].strip_N_noise ;
00241 m_cal_par_t[0].strip_P_noise_sig = file_cal_par_t[0].strip_P_noise_sig ;
00242 m_cal_par_t[0].strip_N_noise_sig = file_cal_par_t[0].strip_N_noise_sig ;
00243 m_cal_par_t[0].n_strip_P_factor = file_cal_par_t[0].n_strip_P_factor ;
00244 m_cal_par_t[0].n_strip_N_factor = file_cal_par_t[0].n_strip_N_factor ;
00245 m_cal_par_t[0].n_noisy_strip = file_cal_par_t[0].n_noisy_strip ;
00246
00247 fCalib->Close();
00248 delete fCalib;
00249 delete fCalibName;
00250 if (!m_cal_par) return kFALSE;
00251 return kTRUE;
00252 }
00253
00254 void St_sdm_Maker::InitConditionPar()
00255 {
00256 m_cond_par = new St_sdm_condition_par("sdm_condition_par",1);
00257 m_cond_par->SetNRows(1);
00258 sdm_condition_par_st *m_cond_par_t = m_cond_par->GetTable();
00259
00260 m_cond_par_t[0].i_seed = 111111;
00261 m_cond_par_t[0].N_active_ladder[0] = 1 ;
00262 m_cond_par_t[0].N_active_ladder[1] = 1 ;
00263 m_cond_par_t[0].N_active_ladder[2] = 1 ;
00264 m_cond_par_t[0].N_active_ladder[3] = 1 ;
00265 m_cond_par_t[0].N_active_ladder[4] = 1 ;
00266 m_cond_par_t[0].N_active_ladder[5] = 1 ;
00267 m_cond_par_t[0].N_active_ladder[6] = 1 ;
00268 m_cond_par_t[0].N_active_ladder[7] = 1 ;
00269 m_cond_par_t[0].N_active_ladder[8] = 1 ;
00270 m_cond_par_t[0].N_active_ladder[9] = 1 ;
00271 m_cond_par_t[0].N_active_ladder[10] = 1 ;
00272 m_cond_par_t[0].N_active_ladder[11] = 1 ;
00273 m_cond_par_t[0].N_active_ladder[12] = 1 ;
00274 m_cond_par_t[0].N_active_ladder[13] = 1 ;
00275 m_cond_par_t[0].N_active_ladder[14] = 1 ;
00276 m_cond_par_t[0].N_active_ladder[15] = 1 ;
00277 m_cond_par_t[0].N_active_ladder[16] = 1 ;
00278 m_cond_par_t[0].N_active_ladder[17] = 1 ;
00279 m_cond_par_t[0].N_active_ladder[18] = 1 ;
00280 m_cond_par_t[0].N_active_ladder[19] = 1 ;
00281 m_cond_par_t[0].p_bad_wafer = 0.0;
00282 m_cond_par_t[0].p_bad_alice = 0.0;
00283 m_cond_par_t[0].p_bad_strip = 0.00;
00284 }
00285
00286 void St_sdm_Maker::InitGeomPar()
00287 {
00288 m_geom_par = new St_sdm_geom_par("sdm_geom_par",1);
00289 m_geom_par->SetNRows(1);
00290 sdm_geom_par_st *m_geom_par_t = m_geom_par->GetTable();
00291
00292 m_geom_par_t[0].N_layer = 7 ;
00293 m_geom_par_t[0].N_ladder = 20 ;
00294 m_geom_par_t[0].N_waf_per_ladder = 16 ;
00295 m_geom_par_t[0].N_alice_per_side = 6 ;
00296 m_geom_par_t[0].N_strip_per_side = 768 ;
00297 m_geom_par_t[0].L_strip_pitch = 0.0095;
00298 m_geom_par_t[0].L_stereo_angle = 0.0175;
00299 m_geom_par_t[0].L_wafer_tot_l = 3.75 ;
00300 m_geom_par_t[0].L_wafer_tot_w = 2.1 ;
00301 m_geom_par_t[0].L_wafer_tot_t = 0.015 ;
00302 m_geom_par_t[0].L_wafer_act_l = 3.65 ;
00303 m_geom_par_t[0].L_wafer_act_w = 2.0 ;
00304 }
00305
00306 void St_sdm_Maker::InitCalibPar()
00307 {
00308 m_cal_par = new St_sdm_calib_par("sdm_calib_par",1);
00309 m_cal_par->SetNRows(1);
00310 sdm_calib_par_st *m_cal_par_t = m_cal_par->GetTable();
00311
00312 m_cal_par_t[0].i_seed = 111111;
00313 m_cal_par_t[0].barrel_ped = 100000;
00314 m_cal_par_t[0].wafer_sig = 10000 ;
00315 m_cal_par_t[0].alice_sig = 5000 ;
00316 m_cal_par_t[0].strip_P_sig = 50 ;
00317 m_cal_par_t[0].strip_N_sig = 50 ;
00318 m_cal_par_t[0].strip_P_noise = 1400 ;
00319 m_cal_par_t[0].strip_N_noise = 2200 ;
00320 m_cal_par_t[0].strip_P_noise_sig = 50 ;
00321 m_cal_par_t[0].strip_N_noise_sig = 70 ;
00322 m_cal_par_t[0].n_strip_P_factor = 10. ;
00323 m_cal_par_t[0].n_strip_N_factor = 10. ;
00324 m_cal_par_t[0].n_noisy_strip = 0. ;
00325 }
00326
00327 void St_sdm_Maker::BuildCalibDB()
00328 {
00329 Int_t iSide = 0 ;
00330 Int_t lSsdPedestal = 0 ;
00331 Int_t lWaferPedestal = 0 ;
00332 Int_t lStripNoise = 0 ;
00333 Int_t lStripPedestal = 0 ;
00334 Int_t iBin = 0 ;
00335
00336 const Int_t nA128PerSide = mSsdTotA128/mSsdTotPlane;
00337 const Int_t nStripPerA128 = mSsdTotStrip/mSsdTotA128;
00338 const Int_t nStripPerSide = mSsdTotStrip/mSsdTotPlane;
00339
00340 sdm_calib_par_st *m_cal_par_t = m_cal_par->GetTable();
00341
00342 Int_t *mSignalPar = new Int_t[9];
00343 Float_t *mNoisyPar = new Float_t[3];
00344 Int_t *mPedestalArray = new Int_t[mSsdTotStrip];
00345 Int_t *mNoiseArray = new Int_t[mSsdTotStrip];
00346
00347 mSignalPar[0] = m_cal_par_t[0].barrel_ped;
00348 mSignalPar[1] = m_cal_par_t[0].wafer_sig;
00349 mSignalPar[2] = m_cal_par_t[0].alice_sig;
00350 mSignalPar[3] = m_cal_par_t[0].strip_P_sig;
00351 mSignalPar[4] = m_cal_par_t[0].strip_N_sig;
00352 mSignalPar[5] = m_cal_par_t[0].strip_P_noise;
00353 mSignalPar[6] = m_cal_par_t[0].strip_N_noise;
00354 mSignalPar[7] = m_cal_par_t[0].strip_P_noise_sig;
00355 mSignalPar[8] = m_cal_par_t[0].strip_N_noise_sig;
00356
00357 mNoisyPar[0] = m_cal_par_t[0].n_strip_P_factor;
00358 mNoisyPar[1] = m_cal_par_t[0].n_strip_N_factor;
00359 mNoisyPar[2] = m_cal_par_t[0].n_noisy_strip;
00360
00361 Int_t i = 0;
00362 Int_t j = 0;
00363 Int_t k = 0;
00364
00365
00366 for(i = 0 ; i < mSsdTotPlane ; i++)
00367 {
00368 iSide = (i%2 == 0) ? 0 : 1 ;
00369 lSsdPedestal = Int_t((mSignalPar[0])+m_DBRandom->Gaus(0.,Double_t(mSignalPar[1])));
00370
00371 for(j = 0 ; j < nA128PerSide ; j++)
00372 {
00373 lWaferPedestal = lSsdPedestal + Int_t(m_DBRandom->Gaus(0.,mSignalPar[2]));
00374 for(k = 0 ; k < nStripPerA128 ; k++ )
00375 {
00376 switch(iSide)
00377 {
00378 case 0 :
00379 lStripNoise = Int_t(mSignalPar[5]+(m_DBRandom->Gaus(0.,mSignalPar[7])));
00380 lStripPedestal = lWaferPedestal + Int_t(m_DBRandom->Gaus(0.,mSignalPar[3]));
00381 break;
00382 case 1 :
00383 lStripNoise = Int_t(mSignalPar[6]+(m_DBRandom->Gaus(0.,mSignalPar[8])));
00384 lStripPedestal = lWaferPedestal + Int_t(m_DBRandom->Gaus(0.,mSignalPar[4]));
00385 break;
00386 }
00387 iBin = i*nStripPerSide + j*nStripPerA128 + k ;
00388 mPedestalArray[iBin] = lStripPedestal;
00389 mNoiseArray[iBin] = lStripNoise;
00390 }
00391 }
00392 }
00393
00394 Int_t nNoisyStrip = Int_t(mSsdTotStrip*m_cal_par_t[0].n_noisy_strip);
00395 Float_t factorP = (m_cal_par_t[0].n_strip_P_factor)-1.;
00396 Float_t factorN = (m_cal_par_t[0].n_strip_N_factor)-1.;
00397 Int_t *noisyTmp = new Int_t[mSsdTotStrip];
00398
00399 for ( i = 0 ; i < mSsdTotStrip ; i++)
00400 {
00401 noisyTmp[i] = i ;
00402 }
00403 Int_t localSize = mSsdTotStrip;
00404 Int_t st = 0;
00405 Float_t fact = 0.;
00406
00407 i = 0;
00408 while (i < nNoisyStrip)
00409 {
00410 st = Int_t(m_DBRandom->Rndm()*localSize);
00411 iSide = (Int_t(st/768))%2;
00412 switch (iSide)
00413 {
00414 case 0:
00415 fact = 1.+Float_t(m_DBRandom->Rndm()*factorP);
00416 mNoiseArray[noisyTmp[st]] = Int_t(mNoiseArray[noisyTmp[st]]*fact);
00417 break;
00418 case 1:
00419 fact = 1+Float_t(m_DBRandom->Rndm()*factorN);
00420 mNoiseArray[noisyTmp[st]] = Int_t(mNoiseArray[noisyTmp[st]]*fact);
00421 break;
00422 }
00423 noisyTmp[st] = noisyTmp[localSize-1];
00424 localSize--;
00425 i++;
00426 }
00427
00428 Int_t iStrip = 0;
00429
00430 St_sdm_calib_db *m_noise = new St_sdm_calib_db("sdm_calib_db",500000);
00431 m_noise->SetNRows(0);
00432 sdm_calib_db_st *m_noise_t = m_noise->GetTable();
00433 cout<<" noise Used Rows = "<<m_noise->GetNRows()<<endl;
00434 cout<<" noise Allocated Rows = "<<m_noise->GetTableSize()<<endl;
00435
00436 for(i = 0 ; i < mSsdTotStrip ; i++ ){
00437
00438 iStrip = ConvertStripId(i+1);
00439
00440 m_noise_t[i].id_strip = iStrip;
00441 m_noise_t[i].n_pedestal = mPedestalArray[i];
00442 m_noise_t[i].n_sigma = mNoiseArray[i];
00443 m_noise->SetNRows(i+1);
00444 }
00445
00446 TString *fCalibDBName = new TString("sdm_calib_db.root");
00447 TFile *m_CalibDBFile = new TFile(((*m_DBPath)+(*fCalibDBName)).Data(),"RECREATE");
00448 m_noise->Write();
00449 m_CalibDBFile->Close();
00450
00451 delete[] noisyTmp;
00452 delete[] mSignalPar;
00453 delete[] mNoisyPar;
00454 delete[] mPedestalArray;
00455 delete[] mNoiseArray;
00456 delete fCalibDBName;
00457 delete m_noise;
00458 delete m_CalibDBFile;
00459 }
00460
00461 void St_sdm_Maker::BuildConditionDB()
00462 {
00463 sdm_condition_par_st *m_cond_par_t = m_cond_par->GetTable();
00464
00465 Int_t *mSsdActiveLadder = new Int_t[mSsdTotLadder];
00466 Int_t *mSsdActivePlane = new Int_t[mSsdTotPlane];
00467 Int_t *mSsdActiveA128 = new Int_t[mSsdTotA128];
00468 Int_t *mSsdActiveStrip = new Int_t[mSsdTotStrip];
00469
00470 Int_t i = 0 ;
00471 Int_t j = 0 ;
00472 for (i = 0 ; i < mSsdTotLadder ; i++)
00473 {
00474
00475 mSsdActiveLadder[i] = Int_t(m_cond_par_t[0].N_active_ladder[i]);
00476
00477 }
00478 for (i = 0 ; i < mSsdTotLadder ; i++ )
00479 {
00480 Int_t tmp_loc = 0;
00481 if (mSsdActiveLadder[i])
00482 {
00483 tmp_loc = mSsdTotPlane/mSsdTotLadder;
00484 for (j = 0 ; j < tmp_loc ; j++) mSsdActivePlane[j+tmp_loc*i] = 1;
00485 tmp_loc = mSsdTotA128/mSsdTotLadder;
00486 for (j = 0 ; j < tmp_loc ; j++) mSsdActiveA128[j+tmp_loc*i] = 1;
00487 tmp_loc = mSsdTotStrip/mSsdTotLadder;
00488 for (j = 0 ; j < tmp_loc ; j++) mSsdActiveStrip[j+tmp_loc*i] = 1;
00489 }
00490 else
00491 {
00492 tmp_loc = mSsdTotPlane/mSsdTotLadder;
00493 for (j = 0 ; j < tmp_loc ; j++) mSsdActivePlane[j+tmp_loc*i] = 0;
00494 tmp_loc = mSsdTotA128/mSsdTotLadder;
00495 for (j = 0 ; j < tmp_loc ; j++) mSsdActiveA128[j+tmp_loc*i] = 0;
00496 tmp_loc = mSsdTotStrip/mSsdTotLadder;
00497 for (j = 0 ; j < tmp_loc ; j++) mSsdActiveStrip[j+tmp_loc*i] = 0;
00498 }
00499 }
00500
00501 Int_t nDeadWafer = Int_t(mSsdTotWafer*m_cond_par_t[0].p_bad_wafer);
00502 Int_t nDeadA128 = Int_t(mSsdTotA128*m_cond_par_t[0].p_bad_alice);
00503 Int_t nDeadStrip = Int_t(mSsdTotStrip*m_cond_par_t[0].p_bad_strip);
00504 Int_t iBin = 0 ;
00505 Int_t *nTmpDeadStrip = new Int_t[mSsdTotStrip];
00506 Int_t LocalSize = 0;
00507
00508 Int_t nStripPerA128 = mSsdTotStrip/mSsdTotA128;
00509 Int_t nStripPerWafer = mSsdTotStrip/mSsdTotWafer;
00510
00511 Int_t ii = 0;
00512 Int_t st = 0;
00513 Int_t jj = 0;
00514 Int_t ch = 0;
00515 Int_t ss = 0;
00516 for (ii =0 ; ii < mSsdTotStrip ; ii++)
00517 {
00518 if (mSsdActiveStrip[ii])
00519 {
00520 nTmpDeadStrip[LocalSize] = ii;
00521 LocalSize++;
00522 }
00523 }
00524 ii = 0;
00525 while (ii < nDeadStrip)
00526 {
00527 st = Int_t (m_DBRandom->Rndm()*LocalSize);
00528 mSsdActiveStrip[nTmpDeadStrip[st]] = 0 ;
00529 nTmpDeadStrip[st] = nTmpDeadStrip[LocalSize - 1];
00530 nTmpDeadStrip[LocalSize - 1] = 0;
00531 LocalSize--;
00532 ii++;
00533 }
00534 ii = 0;
00535 while (ii < nDeadA128)
00536 {
00537 ch = Int_t(m_DBRandom->Rndm()*mSsdTotA128);
00538 if ( mSsdActiveA128[ch])
00539 {
00540 for(jj = 0 ; jj <nStripPerA128 ; jj++)
00541 {
00542 iBin = jj + ch*nStripPerA128;
00543 mSsdActiveStrip[iBin] = 0 ;
00544 }
00545 mSsdActiveA128[ch] = 0 ;
00546 ii++;
00547 }
00548 }
00549
00550 ii = 0;
00551 while (ii < nDeadWafer)
00552 {
00553 ss = Int_t(m_DBRandom->Rndm()*mSsdTotWafer);
00554 if ((mSsdActivePlane[2*ss])||(mSsdActivePlane[2*ss+1]))
00555 {
00556 for(jj = 0 ; jj < nStripPerWafer ; jj++)
00557 {
00558 iBin = jj + ss*nStripPerWafer ;
00559 mSsdActiveStrip[iBin] = 0 ;
00560
00561 }
00562 mSsdActivePlane[2*ss] = 0 ;
00563 mSsdActivePlane[2*ss+1] = 0 ;
00564 }
00565 ii++;
00566 }
00567
00568 Int_t iStrip = 0;
00569
00570 St_sdm_condition_db *m_condition = new St_sdm_condition_db("sdm_condition_db",500000);
00571 m_condition->SetNRows(0);
00572 sdm_condition_db_st *m_condition_t = m_condition->GetTable();
00573
00574 for(jj = 0 ; jj < mSsdTotStrip ; jj++ ){
00575
00576 iStrip = ConvertStripId(jj+1);
00577
00578 m_condition_t[jj].id_strip = iStrip;
00579 m_condition_t[jj].is_active = mSsdActiveStrip[jj];
00580 m_condition->SetNRows(jj+1);
00581 }
00582
00583 TString *fCondDBName = new TString("sdm_condition_db.root");
00584 TFile *m_CondDBFile = new TFile (((*m_DBPath)+(*fCondDBName)).Data(),"RECREATE");
00585 m_condition->Write();
00586 m_CondDBFile->Close();
00587
00588 delete[] nTmpDeadStrip;
00589 delete[] mSsdActiveLadder;
00590 delete[] mSsdActivePlane;
00591 delete[] mSsdActiveA128;
00592 delete[] mSsdActiveStrip;
00593 delete fCondDBName;
00594 delete m_condition;
00595 delete m_CondDBFile;
00596 }
00597
00598 Int_t St_sdm_Maker::WaferNumbToIdWafer(Int_t wafer_numb)
00599 {
00600 Int_t nWaferPerLadder = mSsdTotWafer/mSsdTotLadder;
00601 Int_t iLadder = 1+Int_t(wafer_numb/nWaferPerLadder);
00602 Int_t iWafer = wafer_numb-((iLadder-1)*nWaferPerLadder)+1;
00603 return mSsdLayer*1000 + iWafer*100 + iLadder;
00604 }
00605
00606 Int_t St_sdm_Maker::ConvertStripId(Int_t st)
00607 {
00608 Int_t iWafer = 0;
00609 Int_t iSide = 0 ;
00610 Int_t idStrip = 0;
00611 Int_t nStripPerWafer = Int_t(mSsdTotStrip/mSsdTotWafer);
00612
00613 iWafer = Int_t((st-1)/nStripPerWafer);
00614 idStrip = st - iWafer*nStripPerWafer;
00615 iWafer = WaferNumbToIdWafer(iWafer);
00616 iSide = (idStrip <= (nStripPerWafer/2)) ? 0 : 1 ;
00617
00618 if(iSide) idStrip -= (nStripPerWafer/2);
00619 idStrip = 10000*(10*idStrip+iSide)+iWafer ;
00620 return idStrip;
00621 }