]>
Commit | Line | Data |
---|---|---|
b0f5e3fc | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
5c5273c2 | 15 | |
88cb7938 | 16 | /* $Id$ */ |
b0f5e3fc | 17 | |
4ae5bbc4 | 18 | #include <Riostream.h> |
b0f5e3fc | 19 | #include <stdlib.h> |
20 | #include <stdio.h> | |
1ca7869b | 21 | #include <string.h> |
22 | ||
ece86d9a | 23 | #include <TCanvas.h> |
24 | #include <TF1.h> | |
1ca7869b | 25 | #include <TH1.h> |
26 | #include <TFile.h> | |
ece86d9a | 27 | |
e8189707 | 28 | #include "AliITS.h" |
e8189707 | 29 | #include "AliITSMapA2.h" |
e8189707 | 30 | #include "AliITSRawData.h" |
f77f13c8 | 31 | #include "AliITSdigitSPD.h" |
32 | #include "AliITSetfSDD.h" | |
50d05d7b | 33 | #include "AliITSgeom.h" |
f77f13c8 | 34 | #include "AliITSmodule.h" |
35 | #include "AliITSpList.h" | |
c7a4dac0 | 36 | #include "AliITSresponseSDD.h" |
fcf95fc7 | 37 | #include "AliITSCalibrationSDD.h" |
f77f13c8 | 38 | #include "AliITSsegmentationSDD.h" |
1ca7869b | 39 | #include "AliITSsimulationSDD.h" |
f77f13c8 | 40 | #include "AliLog.h" |
41 | #include "AliRun.h" | |
b0f5e3fc | 42 | |
b0f5e3fc | 43 | ClassImp(AliITSsimulationSDD) |
44 | //////////////////////////////////////////////////////////////////////// | |
8ba39da9 | 45 | // Version: 0 // |
46 | // Written by Piergiorgio Cerello // | |
47 | // November 23 1999 // | |
48 | // // | |
49 | // AliITSsimulationSDD is the simulation of SDDs. // | |
50 | //////////////////////////////////////////////////////////////////////// | |
51 | ||
52 | //______________________________________________________________________ | |
aacedc3e | 53 | Int_t power(Int_t b, Int_t e) { |
54 | // compute b to the e power, where both b and e are Int_ts. | |
55 | Int_t power = 1,i; | |
3d2c9d72 | 56 | |
aacedc3e | 57 | for(i=0; i<e; i++) power *= b; |
58 | return power; | |
8a33ae9e | 59 | } |
60 | //______________________________________________________________________ | |
b0f5e3fc | 61 | void FastFourierTransform(AliITSetfSDD *alisddetf,Double_t *real, |
62 | Double_t *imag,Int_t direction) { | |
aacedc3e | 63 | // Do a Fast Fourier Transform |
64 | ||
65 | Int_t samples = alisddetf->GetSamples(); | |
66 | Int_t l = (Int_t) ((log((Float_t) samples)/log(2.))+0.5); | |
67 | Int_t m1 = samples; | |
68 | Int_t m = samples/2; | |
69 | Int_t m2 = samples/m1; | |
70 | Int_t i,j,k; | |
71 | for(i=1; i<=l; i++) { | |
72 | for(j=0; j<samples; j += m1) { | |
73 | Int_t p = 0; | |
74 | for(k=j; k<= j+m-1; k++) { | |
75 | Double_t wsr = alisddetf->GetWeightReal(p); | |
76 | Double_t wsi = alisddetf->GetWeightImag(p); | |
77 | if(direction == -1) wsi = -wsi; | |
78 | Double_t xr = *(real+k+m); | |
79 | Double_t xi = *(imag+k+m); | |
80 | *(real+k+m) = wsr*(*(real+k)-xr) - wsi*(*(imag+k)-xi); | |
81 | *(imag+k+m) = wsr*(*(imag+k)-xi) + wsi*(*(real+k)-xr); | |
82 | *(real+k) += xr; | |
83 | *(imag+k) += xi; | |
84 | p += m2; | |
85 | } // end for k | |
86 | } // end for j | |
87 | m1 = m; | |
88 | m /= 2; | |
89 | m2 += m2; | |
3d2c9d72 | 90 | } // end for i |
aacedc3e | 91 | |
92 | for(j=0; j<samples; j++) { | |
93 | Int_t j1 = j; | |
94 | Int_t p = 0; | |
95 | Int_t i1; | |
96 | for(i1=1; i1<=l; i1++) { | |
97 | Int_t j2 = j1; | |
98 | j1 /= 2; | |
99 | p = p + p + j2 - j1 - j1; | |
100 | } // end for i1 | |
101 | if(p >= j) { | |
102 | Double_t xr = *(real+j); | |
103 | Double_t xi = *(imag+j); | |
104 | *(real+j) = *(real+p); | |
105 | *(imag+j) = *(imag+p); | |
106 | *(real+p) = xr; | |
107 | *(imag+p) = xi; | |
108 | } // end if p>=j | |
109 | } // end for j | |
110 | if(direction == -1) { | |
111 | for(i=0; i<samples; i++) { | |
112 | *(real+i) /= samples; | |
113 | *(imag+i) /= samples; | |
114 | } // end for i | |
115 | } // end if direction == -1 | |
116 | return; | |
b0f5e3fc | 117 | } |
8a33ae9e | 118 | //______________________________________________________________________ |
aacedc3e | 119 | AliITSsimulationSDD::AliITSsimulationSDD(): |
120 | AliITSsimulation(), | |
121 | fITS(0), | |
122 | fHitMap2(0), | |
123 | fHitSigMap2(0), | |
124 | fHitNoiMap2(0), | |
125 | fStream(0), | |
126 | fElectronics(0), | |
127 | fInZR(0), | |
128 | fInZI(0), | |
129 | fOutZR(0), | |
130 | fOutZI(0), | |
131 | fAnodeFire(0), | |
132 | fHis(0), | |
133 | fD(), | |
134 | fT1(), | |
135 | fTol(), | |
136 | fBaseline(), | |
137 | fNoise(), | |
138 | fTreeB(0), | |
139 | fFileName(), | |
140 | fFlag(kFALSE), | |
141 | fCheckNoise(kFALSE), | |
142 | fCrosstalkFlag(kFALSE), | |
143 | fDoFFT(1), | |
144 | fNofMaps(0), | |
145 | fMaxNofSamples(0), | |
146 | fScaleSize(0){ | |
147 | // Default constructor | |
148 | SetScaleFourier(); | |
149 | SetPerpendTracksFlag(); | |
150 | SetCrosstalkFlag(); | |
151 | SetDoFFT(); | |
152 | SetCheckNoise(); | |
b0f5e3fc | 153 | } |
8a33ae9e | 154 | //______________________________________________________________________ |
ac74f489 | 155 | AliITSsimulationSDD::AliITSsimulationSDD(AliITSsimulationSDD &source) : |
aacedc3e | 156 | AliITSsimulation(source){ |
157 | // Copy constructor to satify Coding roules only. | |
8a33ae9e | 158 | |
aacedc3e | 159 | if(this==&source) return; |
d2f55a22 | 160 | Error("AliITSsimulationSDD","Not allowed to make a copy of " |
aacedc3e | 161 | "AliITSsimulationSDD Using default creater instead"); |
162 | AliITSsimulationSDD(); | |
b0f5e3fc | 163 | } |
8a33ae9e | 164 | //______________________________________________________________________ |
d2f55a22 | 165 | AliITSsimulationSDD& AliITSsimulationSDD::operator=(const AliITSsimulationSDD &src){ |
166 | // Assignment operator to satify Coding roules only. | |
167 | ||
168 | if(this==&src) return *this; | |
169 | Error("AliITSsimulationSDD","Not allowed to make a = with " | |
170 | "AliITSsimulationSDD Using default creater instead"); | |
171 | return *this ; | |
172 | } | |
173 | //______________________________________________________________________ | |
5402d9ca | 174 | AliITSsimulation& AliITSsimulationSDD::operator=(const AliITSsimulation &src){ |
aacedc3e | 175 | // Assignment operator to satify Coding roules only. |
8a33ae9e | 176 | |
aacedc3e | 177 | if(this==&src) return *this; |
178 | Error("AliITSsimulationSSD","Not allowed to make a = with " | |
179 | "AliITSsimulationSDD Using default creater instead"); | |
180 | return *this ; | |
b0f5e3fc | 181 | } |
d2f55a22 | 182 | |
8a33ae9e | 183 | //______________________________________________________________________ |
8ba39da9 | 184 | AliITSsimulationSDD::AliITSsimulationSDD(AliITSDetTypeSim* dettyp): |
185 | AliITSsimulation(dettyp), | |
aacedc3e | 186 | fITS(0), |
187 | fHitMap2(0), | |
188 | fHitSigMap2(0), | |
189 | fHitNoiMap2(0), | |
190 | fStream(0), | |
191 | fElectronics(0), | |
192 | fInZR(0), | |
193 | fInZI(0), | |
194 | fOutZR(0), | |
195 | fOutZI(0), | |
196 | fAnodeFire(0), | |
197 | fHis(0), | |
198 | fD(), | |
199 | fT1(), | |
200 | fTol(), | |
201 | fBaseline(), | |
202 | fNoise(), | |
203 | fTreeB(0), | |
204 | fFileName(), | |
205 | fFlag(kFALSE), | |
206 | fCheckNoise(kFALSE), | |
207 | fCrosstalkFlag(kFALSE), | |
208 | fDoFFT(1), | |
209 | fNofMaps(0), | |
210 | fMaxNofSamples(0), | |
211 | fScaleSize(0){ | |
212 | // Standard Constructor | |
213 | ||
214 | Init(); | |
c7a4dac0 | 215 | } |
216 | //______________________________________________________________________ | |
aacedc3e | 217 | void AliITSsimulationSDD::Init(){ |
218 | // Standard Constructor | |
219 | ||
220 | SetScaleFourier(); | |
221 | SetPerpendTracksFlag(); | |
222 | SetCrosstalkFlag(); | |
223 | SetDoFFT(); | |
224 | SetCheckNoise(); | |
225 | ||
8ba39da9 | 226 | AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1); |
227 | ||
fcf95fc7 | 228 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 229 | fpList = new AliITSpList( seg->Npz(), |
230 | fScaleSize*seg->Npx() ); | |
231 | fHitSigMap2 = new AliITSMapA2(seg,fScaleSize,1); | |
232 | fHitNoiMap2 = new AliITSMapA2(seg,fScaleSize,1); | |
aacedc3e | 233 | fHitMap2 = fHitSigMap2; |
234 | ||
8ba39da9 | 235 | fNofMaps = seg->Npz(); |
236 | fMaxNofSamples = seg->Npx(); | |
aacedc3e | 237 | fAnodeFire = new Bool_t [fNofMaps]; |
43217ad9 | 238 | |
8ba39da9 | 239 | Float_t sddLength = seg->Dx(); |
240 | Float_t sddWidth = seg->Dz(); | |
aacedc3e | 241 | |
242 | Int_t dummy = 0; | |
8ba39da9 | 243 | Float_t anodePitch = seg->Dpz(dummy); |
244 | Double_t timeStep = (Double_t)seg->Dpx(dummy); | |
fcf95fc7 | 245 | Float_t driftSpeed = res->GetDriftSpeed(); |
aacedc3e | 246 | |
247 | if(anodePitch*(fNofMaps/2) > sddWidth) { | |
248 | Warning("AliITSsimulationSDD", | |
249 | "Too many anodes %d or too big pitch %f \n", | |
250 | fNofMaps/2,anodePitch); | |
251 | } // end if | |
b0f5e3fc | 252 | |
aacedc3e | 253 | if(timeStep*fMaxNofSamples < sddLength/driftSpeed) { |
254 | Error("AliITSsimulationSDD", | |
255 | "Time Interval > Allowed Time Interval: exit\n"); | |
256 | return; | |
257 | } // end if | |
b0f5e3fc | 258 | |
aacedc3e | 259 | fElectronics = new AliITSetfSDD(timeStep/fScaleSize, |
fcf95fc7 | 260 | res->GetElectronics()); |
b0f5e3fc | 261 | |
aacedc3e | 262 | char opt1[20], opt2[20]; |
fcf95fc7 | 263 | res->GetParamOptions(opt1,opt2); |
aacedc3e | 264 | fParam = opt2; |
265 | char *same = strstr(opt1,"same"); | |
266 | if (same) { | |
267 | fNoise.Set(0); | |
268 | fBaseline.Set(0); | |
269 | } else { | |
270 | fNoise.Set(fNofMaps); | |
271 | fBaseline.Set(fNofMaps); | |
272 | } // end if | |
5d18fa90 | 273 | |
fcf95fc7 | 274 | const char *kopt=res->GetZeroSuppOption(); |
aacedc3e | 275 | if (strstr(fParam.Data(),"file") ) { |
276 | fD.Set(fNofMaps); | |
277 | fT1.Set(fNofMaps); | |
278 | if (strstr(kopt,"2D")) { | |
279 | fT2.Set(fNofMaps); | |
280 | fTol.Set(0); | |
281 | Init2D(); // desactivate if param change module by module | |
282 | } else if(strstr(kopt,"1D")) { | |
283 | fT2.Set(2); | |
284 | fTol.Set(2); | |
285 | Init1D(); // desactivate if param change module by module | |
286 | } // end if strstr | |
287 | } else { | |
288 | fD.Set(2); | |
289 | fTol.Set(2); | |
290 | fT1.Set(2); | |
291 | fT2.Set(2); | |
292 | SetCompressParam(); | |
293 | } // end if else strstr | |
294 | ||
8ba39da9 | 295 | Bool_t write = res->OutputOption(); |
aacedc3e | 296 | if(write && strstr(kopt,"2D")) MakeTreeB(); |
297 | ||
298 | // call here if baseline does not change by module | |
299 | // ReadBaseline(); | |
300 | ||
301 | fITS = (AliITS*)gAlice->GetModule("ITS"); | |
302 | Int_t size = fNofMaps*fMaxNofSamples; | |
303 | fStream = new AliITSInStream(size); | |
304 | ||
305 | fInZR = new Double_t [fScaleSize*fMaxNofSamples]; | |
306 | fInZI = new Double_t [fScaleSize*fMaxNofSamples]; | |
307 | fOutZR = new Double_t [fScaleSize*fMaxNofSamples]; | |
308 | fOutZI = new Double_t [fScaleSize*fMaxNofSamples]; | |
b0f5e3fc | 309 | } |
8a33ae9e | 310 | //______________________________________________________________________ |
b0f5e3fc | 311 | AliITSsimulationSDD::~AliITSsimulationSDD() { |
aacedc3e | 312 | // destructor |
313 | ||
314 | // delete fpList; | |
315 | delete fHitSigMap2; | |
316 | delete fHitNoiMap2; | |
317 | delete fStream; | |
318 | delete fElectronics; | |
319 | ||
320 | fITS = 0; | |
321 | ||
322 | if (fHis) { | |
323 | fHis->Delete(); | |
324 | delete fHis; | |
325 | } // end if fHis | |
326 | if(fTreeB) delete fTreeB; | |
327 | if(fInZR) delete [] fInZR; | |
328 | if(fInZI) delete [] fInZI; | |
329 | if(fOutZR) delete [] fOutZR; | |
330 | if(fOutZI) delete [] fOutZI; | |
331 | if(fAnodeFire) delete [] fAnodeFire; | |
b0f5e3fc | 332 | } |
8a33ae9e | 333 | //______________________________________________________________________ |
50d05d7b | 334 | void AliITSsimulationSDD::InitSimulationModule( Int_t module, Int_t event ) { |
aacedc3e | 335 | // create maps to build the lists of tracks for each summable digit |
336 | fModule = module; | |
337 | fEvent = event; | |
338 | ClearMaps(); | |
339 | memset(fAnodeFire,0,sizeof(Bool_t)*fNofMaps); | |
50d05d7b | 340 | } |
341 | //______________________________________________________________________ | |
342 | void AliITSsimulationSDD::ClearMaps() { | |
aacedc3e | 343 | // clear maps |
344 | fpList->ClearMap(); | |
345 | fHitSigMap2->ClearMap(); | |
346 | fHitNoiMap2->ClearMap(); | |
50d05d7b | 347 | } |
348 | //______________________________________________________________________ | |
aacedc3e | 349 | void AliITSsimulationSDD::SDigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){ |
350 | // digitize module using the "slow" detector simulator creating | |
351 | // summable digits. | |
352 | ||
353 | TObjArray *fHits = mod->GetHits(); | |
354 | Int_t nhits = fHits->GetEntriesFast(); | |
355 | if( !nhits ) return; | |
356 | ||
357 | InitSimulationModule( md, ev ); | |
358 | HitsToAnalogDigits( mod ); | |
8ba39da9 | 359 | ChargeToSignal( fModule,kFALSE ); // - Process signal without add noise |
aacedc3e | 360 | fHitMap2 = fHitNoiMap2; // - Swap to noise map |
8ba39da9 | 361 | ChargeToSignal( fModule,kTRUE ); // - Process only noise |
aacedc3e | 362 | fHitMap2 = fHitSigMap2; // - Return to signal map |
363 | WriteSDigits(); | |
364 | ClearMaps(); | |
50d05d7b | 365 | } |
366 | //______________________________________________________________________ | |
aacedc3e | 367 | Bool_t AliITSsimulationSDD::AddSDigitsToModule(TClonesArray *pItemArray, |
368 | Int_t mask ) { | |
369 | // Add Summable digits to module maps. | |
fcf95fc7 | 370 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
aacedc3e | 371 | Int_t nItems = pItemArray->GetEntries(); |
fcf95fc7 | 372 | Double_t maxadc = res->GetMaxAdc(); |
aacedc3e | 373 | Bool_t sig = kFALSE; |
48058160 | 374 | |
aacedc3e | 375 | // cout << "Adding "<< nItems <<" SDigits to module " << fModule << endl; |
376 | for( Int_t i=0; i<nItems; i++ ) { | |
377 | AliITSpListItem * pItem = (AliITSpListItem *)(pItemArray->At( i )); | |
378 | if( pItem->GetModule() != fModule ) { | |
379 | Error( "AliITSsimulationSDD","Error reading, SDigits module " | |
380 | "%d != current module %d: exit", | |
381 | pItem->GetModule(), fModule ); | |
382 | return sig; | |
383 | } // end if | |
384 | ||
385 | if(pItem->GetSignal()>0.0 ) sig = kTRUE; | |
43217ad9 | 386 | |
aacedc3e | 387 | fpList->AddItemTo( mask, pItem ); // Add SignalAfterElect + noise |
388 | AliITSpListItem * pItem2 = fpList->GetpListItem( pItem->GetIndex() ); | |
389 | Double_t sigAE = pItem2->GetSignalAfterElect(); | |
390 | if( sigAE >= maxadc ) sigAE = maxadc-1; // avoid overflow signal | |
391 | Int_t ia; | |
392 | Int_t it; | |
393 | fpList->GetMapIndex( pItem->GetIndex(), ia, it ); | |
394 | fHitMap2->SetHit( ia, it, sigAE ); | |
395 | fAnodeFire[ia] = kTRUE; | |
396 | } | |
397 | return sig; | |
48058160 | 398 | } |
50d05d7b | 399 | //______________________________________________________________________ |
400 | void AliITSsimulationSDD::FinishSDigitiseModule() { | |
aacedc3e | 401 | // digitize module using the "slow" detector simulator from |
402 | // the sum of summable digits. | |
403 | FinishDigits() ; | |
404 | ClearMaps(); | |
c7a4dac0 | 405 | } |
406 | //______________________________________________________________________ | |
b0f5e3fc | 407 | void AliITSsimulationSDD::DigitiseModule(AliITSmodule *mod,Int_t md,Int_t ev){ |
aacedc3e | 408 | // create maps to build the lists of tracks for each digit |
b0f5e3fc | 409 | |
aacedc3e | 410 | TObjArray *fHits = mod->GetHits(); |
411 | Int_t nhits = fHits->GetEntriesFast(); | |
8a33ae9e | 412 | |
aacedc3e | 413 | InitSimulationModule( md, ev ); |
50d05d7b | 414 | |
aacedc3e | 415 | if( !nhits && fCheckNoise ) { |
8ba39da9 | 416 | ChargeToSignal( fModule,kTRUE ); // process noise |
aacedc3e | 417 | GetNoise(); |
418 | ClearMaps(); | |
419 | return; | |
420 | } else | |
421 | if( !nhits ) return; | |
48058160 | 422 | |
aacedc3e | 423 | HitsToAnalogDigits( mod ); |
8ba39da9 | 424 | ChargeToSignal( fModule,kTRUE ); // process signal + noise |
aacedc3e | 425 | |
426 | for( Int_t i=0; i<fNofMaps; i++ ) { | |
427 | for( Int_t j=0; j<fMaxNofSamples; j++ ) { | |
428 | Int_t jdx = j*fScaleSize; | |
429 | Int_t index = fpList->GetHitIndex( i, j ); | |
430 | AliITSpListItem pItemTmp2( fModule, index, 0. ); | |
431 | // put the fScaleSize analog digits in only one | |
432 | for( Int_t ik=0; ik<fScaleSize; ik++ ) { | |
433 | AliITSpListItem *pItemTmp = fpList->GetpListItem( i, jdx+ik ); | |
434 | if( pItemTmp == 0 ) continue; | |
435 | pItemTmp2.Add( pItemTmp ); | |
436 | } | |
437 | fpList->DeleteHit( i, j ); | |
438 | fpList->AddItemTo( 0, &pItemTmp2 ); | |
439 | } | |
48058160 | 440 | } |
aacedc3e | 441 | FinishDigits(); |
442 | ClearMaps(); | |
c7a4dac0 | 443 | } |
444 | //______________________________________________________________________ | |
50d05d7b | 445 | void AliITSsimulationSDD::FinishDigits() { |
aacedc3e | 446 | // introduce the electronics effects and do zero-suppression if required |
8a33ae9e | 447 | |
8ba39da9 | 448 | ApplyDeadChannels(fModule); |
449 | if( fCrosstalkFlag ) ApplyCrosstalk(fModule); | |
50d05d7b | 450 | |
fcf95fc7 | 451 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
452 | const char *kopt = res->GetZeroSuppOption(); | |
aacedc3e | 453 | ZeroSuppression( kopt ); |
c7a4dac0 | 454 | } |
455 | //______________________________________________________________________ | |
50d05d7b | 456 | void AliITSsimulationSDD::HitsToAnalogDigits( AliITSmodule *mod ) { |
aacedc3e | 457 | // create maps to build the lists of tracks for each digit |
458 | ||
8ba39da9 | 459 | AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1); |
fcf95fc7 | 460 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 461 | TObjArray *hits = mod->GetHits(); |
aacedc3e | 462 | Int_t nhits = hits->GetEntriesFast(); |
8ba39da9 | 463 | |
aacedc3e | 464 | // Int_t arg[6] = {0,0,0,0,0,0}; |
465 | Int_t dummy = 0; | |
466 | Int_t nofAnodes = fNofMaps/2; | |
8ba39da9 | 467 | Float_t sddLength = seg->Dx(); |
468 | Float_t sddWidth = seg->Dz(); | |
469 | Float_t anodePitch = seg->Dpz(dummy); | |
470 | Float_t timeStep = seg->Dpx(dummy); | |
fcf95fc7 | 471 | Float_t driftSpeed = res->GetDriftSpeed(); |
472 | Float_t maxadc = res->GetMaxAdc(); | |
473 | Float_t topValue = res->GetDynamicRange(); | |
474 | Float_t cHloss = res->GetChargeLoss(); | |
aacedc3e | 475 | Float_t norm = maxadc/topValue; |
fcf95fc7 | 476 | Float_t dfCoeff, s1; res->DiffCoeff(dfCoeff,s1); // Signal 2d Shape |
8ba39da9 | 477 | Double_t eVpairs = res->GetGeVToCharge()*1.0E9; // 3.6 eV by def. |
fcf95fc7 | 478 | Float_t nsigma = res->GetNSigmaIntegration(); // |
479 | Int_t nlookups = res->GetGausNLookUp(); // | |
480 | Float_t jitter = res->GetJitterError(); // | |
aacedc3e | 481 | |
482 | // Piergiorgio's part (apart for few variables which I made float | |
483 | // when i thought that can be done | |
484 | // Fill detector maps with GEANT hits | |
485 | // loop over hits in the module | |
486 | ||
487 | const Float_t kconv = 1.0e+6; // GeV->KeV | |
488 | Int_t itrack = 0; | |
489 | Int_t hitDetector; // detector number (lay,lad,hitDetector) | |
490 | Int_t iWing; // which detector wing/side. | |
491 | Int_t detector; // 2*(detector-1)+iWing | |
492 | Int_t ii,kk,ka,kt; // loop indexs | |
493 | Int_t ia,it,index; // sub-pixel integration indexies | |
494 | Int_t iAnode; // anode number. | |
495 | Int_t timeSample; // time buckett. | |
496 | Int_t anodeWindow; // anode direction charge integration width | |
497 | Int_t timeWindow; // time direction charge integration width | |
498 | Int_t jamin,jamax; // anode charge integration window | |
499 | Int_t jtmin,jtmax; // time charge integration window | |
500 | Int_t ndiv; // Anode window division factor. | |
501 | Int_t nsplit; // the number of splits in anode and time windows==1. | |
502 | Int_t nOfSplits; // number of times track length is split into | |
503 | Float_t nOfSplitsF; // Floating point version of nOfSplits. | |
504 | Float_t kkF; // Floating point version of loop index kk. | |
505 | Float_t pathInSDD; // Track length in SDD. | |
506 | Float_t drPath; // average position of track in detector. in microns | |
507 | Float_t drTime; // Drift time | |
508 | Float_t nmul; // drift time window multiplication factor. | |
509 | Float_t avDrft; // x position of path length segment in cm. | |
510 | Float_t avAnode; // Anode for path length segment in Anode number (float) | |
511 | Float_t xAnode; // Floating point anode number. | |
512 | Float_t driftPath; // avDrft in microns. | |
513 | Float_t width; // width of signal at anodes. | |
514 | Double_t depEnergy; // Energy deposited in this GEANT step. | |
515 | Double_t xL[3],dxL[3]; // local hit coordinates and diff. | |
516 | Double_t sigA; // sigma of signal at anode. | |
517 | Double_t sigT; // sigma in time/drift direction for track segment | |
518 | Double_t aStep,aConst; // sub-pixel size and offset anode | |
519 | Double_t tStep,tConst; // sub-pixel size and offset time | |
520 | Double_t amplitude; // signal amplitude for track segment in nanoAmpere | |
521 | Double_t chargeloss; // charge loss for track segment. | |
522 | Double_t anodeAmplitude; // signal amplitude in anode direction | |
523 | Double_t aExpo; // exponent of Gaussian anode direction | |
524 | Double_t timeAmplitude; // signal amplitude in time direction | |
525 | Double_t tExpo; // exponent of Gaussian time direction | |
526 | // Double_t tof; // Time of flight in ns of this step. | |
527 | ||
528 | for(ii=0; ii<nhits; ii++) { | |
529 | if(!mod->LineSegmentL(ii,xL[0],dxL[0],xL[1],dxL[1],xL[2],dxL[2], | |
530 | depEnergy,itrack)) continue; | |
531 | xL[0] += 0.0001*gRandom->Gaus( 0, jitter ); // | |
532 | depEnergy *= kconv; | |
533 | hitDetector = mod->GetDet(); | |
534 | //tof = 1.E+09*(mod->GetHit(ii)->GetTOF()); // tof in ns. | |
535 | //if(tof>sddLength/driftSpeed) continue; // hit happed too late. | |
536 | ||
537 | // scale path to simulate a perpendicular track | |
538 | // continue if the particle did not lose energy | |
539 | // passing through detector | |
540 | if (!depEnergy) { | |
f77f13c8 | 541 | AliDebug(1, |
542 | Form("fTrack = %d hit=%d module=%d This particle has passed without losing energy!", | |
543 | itrack,ii,mod->GetIndex())); | |
aacedc3e | 544 | continue; |
545 | } // end if !depEnergy | |
546 | ||
547 | pathInSDD = TMath::Sqrt(dxL[0]*dxL[0]+dxL[1]*dxL[1]+dxL[2]*dxL[2]); | |
548 | ||
549 | if (fFlag && pathInSDD) { depEnergy *= (0.03/pathInSDD); } | |
550 | drPath = 10000.*(dxL[0]+2.*xL[0])*0.5; | |
551 | if(drPath < 0) drPath = -drPath; | |
552 | drPath = sddLength-drPath; | |
553 | if(drPath < 0) { | |
f77f13c8 | 554 | AliDebug(1, // this should be fixed at geometry level |
555 | Form("negative drift path drPath=%e sddLength=%e dxL[0]=%e xL[0]=%e", | |
556 | drPath,sddLength,dxL[0],xL[0])); | |
aacedc3e | 557 | continue; |
558 | } // end if drPath < 0 | |
559 | ||
560 | // Compute number of segments to brake step path into | |
561 | drTime = drPath/driftSpeed; // Drift Time | |
562 | sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1);// Sigma along the anodes | |
563 | // calcuate the number of time the path length should be split into. | |
564 | nOfSplits = (Int_t) (1. + 10000.*pathInSDD/sigA); | |
565 | if(fFlag) nOfSplits = 1; | |
566 | ||
567 | // loop over path segments, init. some variables. | |
568 | depEnergy /= nOfSplits; | |
569 | nOfSplitsF = (Float_t) nOfSplits; | |
570 | for(kk=0;kk<nOfSplits;kk++) { // loop over path segments | |
571 | kkF = (Float_t) kk + 0.5; | |
572 | avDrft = xL[0]+dxL[0]*kkF/nOfSplitsF; | |
573 | avAnode = xL[2]+dxL[2]*kkF/nOfSplitsF; | |
574 | driftPath = 10000.*avDrft; | |
575 | ||
576 | iWing = 2; // Assume wing is 2 | |
577 | if(driftPath < 0) { // if wing is not 2 it is 1. | |
578 | iWing = 1; | |
579 | driftPath = -driftPath; | |
580 | } // end if driftPath < 0 | |
581 | driftPath = sddLength-driftPath; | |
582 | detector = 2*(hitDetector-1) + iWing; | |
583 | if(driftPath < 0) { | |
f77f13c8 | 584 | AliDebug(1, // this should be fixed at geometry level |
585 | Form("negative drift path driftPath=%e sddLength=%e avDrft=%e dxL[0]=%e xL[0]=%e", | |
586 | driftPath,sddLength,avDrft,dxL[0],xL[0])); | |
aacedc3e | 587 | continue; |
588 | } // end if driftPath < 0 | |
589 | ||
590 | // Drift Time | |
591 | drTime = driftPath/driftSpeed; // drift time for segment. | |
592 | timeSample = (Int_t) (fScaleSize*drTime/timeStep + 1); | |
593 | // compute time Sample including tof information. The tof only | |
594 | // effects the time of the signal is recoreded and not the | |
595 | // the defusion. | |
596 | // timeSample = (Int_t) (fScaleSize*(drTime+tof)/timeStep + 1); | |
597 | if(timeSample > fScaleSize*fMaxNofSamples) { | |
598 | Warning("HitsToAnalogDigits","Wrong Time Sample: %e", | |
599 | timeSample); | |
600 | continue; | |
601 | } // end if timeSample > fScaleSize*fMaxNoofSamples | |
602 | ||
603 | // Anode | |
604 | xAnode = 10000.*(avAnode)/anodePitch + nofAnodes/2; // +1? | |
605 | if(xAnode*anodePitch > sddWidth || xAnode*anodePitch < 0.) | |
606 | Warning("HitsToAnalogDigits", | |
607 | "Exceedubg sddWidth=%e Z = %e", | |
608 | sddWidth,xAnode*anodePitch); | |
609 | iAnode = (Int_t) (1.+xAnode); // xAnode? | |
610 | if(iAnode < 1 || iAnode > nofAnodes) { | |
611 | Warning("HitToAnalogDigits","Wrong iAnode: 1<%d>%d", | |
612 | iAnode,nofAnodes); | |
613 | continue; | |
614 | } // end if iAnode < 1 || iAnode > nofAnodes | |
615 | ||
616 | // store straight away the particle position in the array | |
617 | // of particles and take idhit=ii only when part is entering (this | |
618 | // requires FillModules() in the macro for analysis) : | |
b0f5e3fc | 619 | |
aacedc3e | 620 | // Sigma along the anodes for track segment. |
621 | sigA = TMath::Sqrt(2.*dfCoeff*drTime+s1*s1); | |
622 | sigT = sigA/driftSpeed; | |
623 | // Peak amplitude in nanoAmpere | |
624 | amplitude = fScaleSize*160.*depEnergy/ | |
625 | (timeStep*eVpairs*2.*acos(-1.)*sigT*sigA); | |
626 | amplitude *= timeStep/25.; // WARNING!!!!! Amplitude scaling to | |
627 | // account for clock variations | |
628 | // (reference value: 40 MHz) | |
629 | chargeloss = 1.-cHloss*driftPath/1000; | |
630 | amplitude *= chargeloss; | |
631 | width = 2.*nsigma/(nlookups-1); | |
632 | // Spread the charge | |
633 | // Pixel index | |
634 | ndiv = 2; | |
635 | nmul = 3.; | |
636 | if(drTime > 1200.) { | |
637 | ndiv = 4; | |
638 | nmul = 1.5; | |
639 | } // end if drTime > 1200. | |
640 | // Sub-pixel index | |
641 | nsplit = 4; // hard-wired //nsplit=4;nsplit = (nsplit+1)/2*2; | |
642 | // Sub-pixel size see computation of aExpo and tExpo. | |
643 | aStep = anodePitch/(nsplit*fScaleSize*sigA); | |
644 | aConst = xAnode*anodePitch/sigA; | |
645 | tStep = timeStep/(nsplit*fScaleSize*sigT); | |
646 | tConst = drTime/sigT; | |
647 | // Define SDD window corresponding to the hit | |
648 | anodeWindow = (Int_t)(fScaleSize*nsigma*sigA/anodePitch+1); | |
649 | timeWindow = (Int_t) (fScaleSize*nsigma*sigT/timeStep+1.); | |
650 | jamin = (iAnode - anodeWindow/ndiv - 1)*fScaleSize*nsplit +1; | |
651 | jamax = (iAnode + anodeWindow/ndiv)*fScaleSize*nsplit; | |
652 | if(jamin <= 0) jamin = 1; | |
653 | if(jamax > fScaleSize*nofAnodes*nsplit) | |
654 | jamax = fScaleSize*nofAnodes*nsplit; | |
655 | // jtmin and jtmax are Hard-wired | |
656 | jtmin = (Int_t)(timeSample-timeWindow*nmul-1)*nsplit+1; | |
657 | jtmax = (Int_t)(timeSample+timeWindow*nmul)*nsplit; | |
658 | if(jtmin <= 0) jtmin = 1; | |
659 | if(jtmax > fScaleSize*fMaxNofSamples*nsplit) | |
660 | jtmax = fScaleSize*fMaxNofSamples*nsplit; | |
661 | // Spread the charge in the anode-time window | |
662 | for(ka=jamin; ka <=jamax; ka++) { | |
663 | ia = (ka-1)/(fScaleSize*nsplit) + 1; | |
664 | if(ia <= 0) { | |
665 | Warning("HitsToAnalogDigits","ia < 1: "); | |
666 | continue; | |
667 | } // end if | |
668 | if(ia > nofAnodes) ia = nofAnodes; | |
669 | aExpo = (aStep*(ka-0.5)-aConst); | |
670 | if(TMath::Abs(aExpo) > nsigma) anodeAmplitude = 0.; | |
671 | else { | |
672 | dummy = (Int_t) ((aExpo+nsigma)/width); | |
fcf95fc7 | 673 | anodeAmplitude = amplitude*res->GetGausLookUp(dummy); |
aacedc3e | 674 | } // end if TMath::Abs(aEspo) > nsigma |
675 | // index starts from 0 | |
676 | index = ((detector+1)%2)*nofAnodes+ia-1; | |
677 | if(anodeAmplitude) for(kt=jtmin; kt<=jtmax; kt++) { | |
678 | it = (kt-1)/nsplit+1; // it starts from 1 | |
679 | if(it<=0){ | |
680 | Warning("HitsToAnalogDigits","it < 1:"); | |
681 | continue; | |
682 | } // end if | |
683 | if(it>fScaleSize*fMaxNofSamples) | |
684 | it = fScaleSize*fMaxNofSamples; | |
685 | tExpo = (tStep*(kt-0.5)-tConst); | |
686 | if(TMath::Abs(tExpo) > nsigma) timeAmplitude = 0.; | |
687 | else { | |
688 | dummy = (Int_t) ((tExpo+nsigma)/width); | |
689 | timeAmplitude = anodeAmplitude* | |
fcf95fc7 | 690 | res->GetGausLookUp(dummy); |
aacedc3e | 691 | } // end if TMath::Abs(tExpo) > nsigma |
692 | // build the list of Sdigits for this module | |
693 | // arg[0] = index; | |
694 | // arg[1] = it; | |
695 | // arg[2] = itrack; // track number | |
696 | // arg[3] = ii-1; // hit number. | |
697 | timeAmplitude *= norm; | |
698 | timeAmplitude *= 10; | |
699 | // ListOfFiredCells(arg,timeAmplitude,alst,padr); | |
700 | Double_t charge = timeAmplitude; | |
701 | charge += fHitMap2->GetSignal(index,it-1); | |
702 | fHitMap2->SetHit(index, it-1, charge); | |
703 | fpList->AddSignal(index,it-1,itrack,ii-1, | |
704 | mod->GetIndex(),timeAmplitude); | |
705 | fAnodeFire[index] = kTRUE; | |
706 | } // end if anodeAmplitude and loop over time in window | |
707 | } // loop over anodes in window | |
708 | } // end loop over "sub-hits" | |
709 | } // end loop over hits | |
b0f5e3fc | 710 | } |
50d05d7b | 711 | /* |
8a33ae9e | 712 | //______________________________________________________________________ |
b0f5e3fc | 713 | void AliITSsimulationSDD::ListOfFiredCells(Int_t *arg,Double_t timeAmplitude, |
3d2c9d72 | 714 | TObjArray *alist,TClonesArray *padr){ |
aacedc3e | 715 | // Returns the list of "fired" cells. |
716 | ||
717 | Int_t index = arg[0]; | |
718 | Int_t ik = arg[1]; | |
719 | Int_t idtrack = arg[2]; | |
720 | Int_t idhit = arg[3]; | |
721 | Int_t counter = arg[4]; | |
722 | Int_t countadr = arg[5]; | |
723 | Double_t charge = timeAmplitude; | |
724 | charge += fHitMap2->GetSignal(index,ik-1); | |
725 | fHitMap2->SetHit(index, ik-1, charge); | |
726 | ||
727 | Int_t digits[3]; | |
728 | Int_t it = (Int_t)((ik-1)/fScaleSize); | |
729 | digits[0] = index; | |
730 | digits[1] = it; | |
731 | digits[2] = (Int_t)timeAmplitude; | |
732 | Float_t phys; | |
733 | if (idtrack >= 0) phys = (Float_t)timeAmplitude; | |
734 | else phys = 0; | |
735 | ||
736 | Double_t cellcharge = 0.; | |
737 | AliITSTransientDigit* pdigit; | |
738 | // build the list of fired cells and update the info | |
739 | if (!fHitMap1->TestHit(index, it)) { | |
740 | new((*padr)[countadr++]) TVector(3); | |
741 | TVector &trinfo=*((TVector*) (*padr)[countadr-1]); | |
742 | trinfo(0) = (Float_t)idtrack; | |
743 | trinfo(1) = (Float_t)idhit; | |
744 | trinfo(2) = (Float_t)timeAmplitude; | |
745 | ||
746 | alist->AddAtAndExpand(new AliITSTransientDigit(phys,digits),counter); | |
747 | fHitMap1->SetHit(index, it, counter); | |
748 | counter++; | |
749 | pdigit=(AliITSTransientDigit*)alist->At(alist->GetLast()); | |
750 | // list of tracks | |
751 | TObjArray *trlist=(TObjArray*)pdigit->TrackList(); | |
752 | trlist->Add(&trinfo); | |
753 | } else { | |
754 | pdigit = (AliITSTransientDigit*) fHitMap1->GetHit(index, it); | |
755 | for(Int_t kk=0;kk<fScaleSize;kk++) { | |
756 | cellcharge += fHitMap2->GetSignal(index,fScaleSize*it+kk); | |
757 | } // end for kk | |
758 | // update charge | |
759 | (*pdigit).fSignal = (Int_t)cellcharge; | |
760 | (*pdigit).fPhysics += phys; | |
761 | // update list of tracks | |
762 | TObjArray* trlist = (TObjArray*)pdigit->TrackList(); | |
763 | Int_t lastentry = trlist->GetLast(); | |
764 | TVector *ptrkp = (TVector*)trlist->At(lastentry); | |
765 | TVector &trinfo = *ptrkp; | |
766 | Int_t lasttrack = Int_t(trinfo(0)); | |
767 | Float_t lastcharge=(trinfo(2)); | |
768 | if (lasttrack==idtrack ) { | |
769 | lastcharge += (Float_t)timeAmplitude; | |
770 | trlist->RemoveAt(lastentry); | |
771 | trinfo(0) = lasttrack; | |
772 | trinfo(1) = idhit; | |
773 | trinfo(2) = lastcharge; | |
774 | trlist->AddAt(&trinfo,lastentry); | |
775 | } else { | |
776 | new((*padr)[countadr++]) TVector(3); | |
777 | TVector &trinfo=*((TVector*) (*padr)[countadr-1]); | |
778 | trinfo(0) = (Float_t)idtrack; | |
779 | trinfo(1) = (Float_t)idhit; | |
780 | trinfo(2) = (Float_t)timeAmplitude; | |
781 | trlist->Add(&trinfo); | |
782 | } // end if lasttrack==idtrack | |
783 | ||
f77f13c8 | 784 | if(AliDebugLevel()){ |
aacedc3e | 785 | // check the track list - debugging |
786 | Int_t trk[20], htrk[20]; | |
787 | Float_t chtrk[20]; | |
788 | Int_t nptracks = trlist->GetEntriesFast(); | |
789 | if (nptracks > 2) { | |
790 | Int_t tr; | |
791 | for (tr=0;tr<nptracks;tr++) { | |
792 | TVector *pptrkp = (TVector*)trlist->At(tr); | |
793 | TVector &pptrk = *pptrkp; | |
794 | trk[tr] = Int_t(pptrk(0)); | |
795 | htrk[tr] = Int_t(pptrk(1)); | |
796 | chtrk[tr] = (pptrk(2)); | |
797 | cout << "nptracks "<<nptracks << endl; | |
798 | } // end for tr | |
799 | } // end if nptracks | |
f77f13c8 | 800 | } // end if AliDebugLevel() |
aacedc3e | 801 | } // end if pdigit |
802 | ||
803 | // update counter and countadr for next call. | |
804 | arg[4] = counter; | |
805 | arg[5] = countadr; | |
b0f5e3fc | 806 | } |
50d05d7b | 807 | */ |
b0f5e3fc | 808 | //____________________________________________ |
50d05d7b | 809 | void AliITSsimulationSDD::AddDigit( Int_t i, Int_t j, Int_t signal ) { |
aacedc3e | 810 | // Adds a Digit. |
811 | Int_t size = AliITSdigitSPD::GetNTracks(); | |
812 | Int_t digits[3]; | |
813 | Int_t * tracks = new Int_t[size]; | |
814 | Int_t * hits = new Int_t[size]; | |
815 | Float_t phys; | |
816 | Float_t * charges = new Float_t[size]; | |
817 | ||
818 | digits[0] = i; | |
819 | digits[1] = j; | |
820 | digits[2] = signal; | |
821 | ||
822 | AliITSpListItem *pItem = fpList->GetpListItem( i, j ); | |
823 | if( pItem == 0 ) { | |
824 | phys = 0.0; | |
825 | for( Int_t l=0; l<size; l++ ) { | |
826 | tracks[l] = 0; | |
827 | hits[l] = 0; | |
828 | charges[l] = 0.0; | |
829 | } | |
830 | } else { | |
831 | Int_t idtrack = pItem->GetTrack( 0 ); | |
832 | if( idtrack >= 0 ) phys = pItem->GetSignal(); | |
833 | else phys = 0.0; | |
834 | ||
835 | for( Int_t l=0; l<size; l++ ) if(l<pItem->GetMaxKept()) { | |
836 | tracks[l] = pItem->GetTrack( l ); | |
837 | hits[l] = pItem->GetHit( l ); | |
838 | charges[l] = pItem->GetSignal( l ); | |
839 | }else{ | |
840 | tracks[l] = -3; | |
841 | hits[l] = -1; | |
842 | charges[l] = 0.0; | |
843 | }// end for if | |
50d05d7b | 844 | } |
50d05d7b | 845 | |
aacedc3e | 846 | fITS->AddSimDigit( 1, phys, digits, tracks, hits, charges ); |
847 | delete [] tracks; | |
848 | delete [] hits; | |
849 | delete [] charges; | |
850 | } | |
8a33ae9e | 851 | //______________________________________________________________________ |
8ba39da9 | 852 | void AliITSsimulationSDD::ChargeToSignal(Int_t mod,Bool_t bAddNoise) { |
aacedc3e | 853 | // add baseline, noise, electronics and ADC saturation effects |
854 | ||
855 | char opt1[20], opt2[20]; | |
fcf95fc7 | 856 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(mod); |
8ba39da9 | 857 | |
fcf95fc7 | 858 | res->GetParamOptions(opt1,opt2); |
aacedc3e | 859 | char *read = strstr(opt1,"file"); |
860 | Double_t baseline, noise; | |
861 | ||
862 | if (read) { | |
863 | static Bool_t readfile=kTRUE; | |
864 | //read baseline and noise from file | |
865 | if (readfile) ReadBaseline(); | |
866 | readfile=kFALSE; | |
8ba39da9 | 867 | } else res->GetNoiseParam(noise,baseline); |
aacedc3e | 868 | |
869 | Float_t contrib=0; | |
870 | Int_t i,k,kk; | |
fcf95fc7 | 871 | Float_t maxadc = res->GetMaxAdc(); |
aacedc3e | 872 | if(!fDoFFT) { |
873 | for (i=0;i<fNofMaps;i++) { | |
874 | if( !fAnodeFire[i] ) continue; | |
875 | if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise); | |
876 | for(k=0; k<fScaleSize*fMaxNofSamples; k++) { | |
877 | fInZR[k] = fHitMap2->GetSignal(i,k); | |
878 | if( bAddNoise ) { | |
879 | contrib = (baseline + noise*gRandom->Gaus()); | |
880 | fInZR[k] += contrib; | |
881 | } | |
882 | } // end for k | |
883 | for(k=0; k<fMaxNofSamples; k++) { | |
884 | Double_t newcont = 0.; | |
885 | Double_t maxcont = 0.; | |
886 | for(kk=0;kk<fScaleSize;kk++) { | |
887 | newcont = fInZR[fScaleSize*k+kk]; | |
888 | if(newcont > maxcont) maxcont = newcont; | |
889 | } // end for kk | |
890 | newcont = maxcont; | |
891 | if (newcont >= maxadc) newcont = maxadc -1; | |
892 | if(newcont >= baseline){ | |
893 | Warning("","newcont=%d>=baseline=%d",newcont,baseline); | |
894 | } // end if | |
895 | // back to analog: ? | |
896 | fHitMap2->SetHit(i,k,newcont); | |
897 | } // end for k | |
898 | } // end for i loop over anodes | |
899 | return; | |
900 | } // end if DoFFT | |
901 | ||
ece86d9a | 902 | for (i=0;i<fNofMaps;i++) { |
aacedc3e | 903 | if( !fAnodeFire[i] ) continue; |
904 | if (read && i<fNofMaps) GetAnodeBaseline(i,baseline,noise); | |
905 | for(k=0; k<fScaleSize*fMaxNofSamples; k++) { | |
906 | fInZR[k] = fHitMap2->GetSignal(i,k); | |
907 | if( bAddNoise ) { | |
908 | contrib = (baseline + noise*gRandom->Gaus()); | |
909 | fInZR[k] += contrib; | |
910 | } | |
911 | fInZI[k] = 0.; | |
912 | } // end for k | |
913 | FastFourierTransform(fElectronics,&fInZR[0],&fInZI[0],1); | |
914 | for(k=0; k<fScaleSize*fMaxNofSamples; k++) { | |
915 | Double_t rw = fElectronics->GetTraFunReal(k); | |
916 | Double_t iw = fElectronics->GetTraFunImag(k); | |
917 | fOutZR[k] = fInZR[k]*rw - fInZI[k]*iw; | |
918 | fOutZI[k] = fInZR[k]*iw + fInZI[k]*rw; | |
919 | } // end for k | |
920 | FastFourierTransform(fElectronics,&fOutZR[0],&fOutZI[0],-1); | |
921 | for(k=0; k<fMaxNofSamples; k++) { | |
922 | Double_t newcont1 = 0.; | |
923 | Double_t maxcont1 = 0.; | |
924 | for(kk=0;kk<fScaleSize;kk++) { | |
925 | newcont1 = fOutZR[fScaleSize*k+kk]; | |
926 | if(newcont1 > maxcont1) maxcont1 = newcont1; | |
927 | } // end for kk | |
928 | newcont1 = maxcont1; | |
929 | if (newcont1 >= maxadc) newcont1 = maxadc -1; | |
930 | fHitMap2->SetHit(i,k,newcont1); | |
931 | } // end for k | |
8a33ae9e | 932 | } // end for i loop over anodes |
3d2c9d72 | 933 | return; |
b0f5e3fc | 934 | } |
50d05d7b | 935 | //____________________________________________________________________ |
8ba39da9 | 936 | void AliITSsimulationSDD::ApplyDeadChannels(Int_t mod) { |
aacedc3e | 937 | // Set dead channel signal to zero |
fcf95fc7 | 938 | AliITSCalibrationSDD * response = (AliITSCalibrationSDD *)GetCalibrationModel(mod); |
8ba39da9 | 939 | AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1); |
aacedc3e | 940 | // nothing to do |
8ba39da9 | 941 | if( response->IsDead() || |
942 | ( response->GetDeadChips() == 0 && | |
943 | response->GetDeadChannels() == 0 ) ) return; | |
50d05d7b | 944 | |
8ba39da9 | 945 | // static AliITS *iTS = (AliITS*)gAlice->GetModule( "ITS" ); |
aacedc3e | 946 | |
8ba39da9 | 947 | Int_t fMaxNofSamples = seg->Npx(); |
948 | // AliITSgeom *geom = iTS->GetITSgeom(); | |
949 | // Int_t firstSDDMod = geom->GetStartDet( 1 ); | |
aacedc3e | 950 | // loop over wings |
951 | for( Int_t j=0; j<2; j++ ) { | |
8ba39da9 | 952 | // Int_t mod = (fModule-firstSDDMod)*2 + j; |
953 | for( Int_t u=0; u<response->Chips(); u++ ) | |
954 | for( Int_t v=0; v<response->Channels(); v++ ) { | |
955 | Float_t gain = response->Gain(j, u, v ); | |
956 | for( Int_t k=0; k<fMaxNofSamples; k++ ) { | |
957 | Int_t i = j*response->Chips()*response->Channels() + | |
958 | u*response->Channels() + | |
959 | v; | |
960 | Double_t signal = gain * fHitMap2->GetSignal( i, k ); | |
961 | fHitMap2->SetHit( i, k, signal ); /// | |
962 | } | |
963 | } | |
964 | } | |
50d05d7b | 965 | } |
966 | //______________________________________________________________________ | |
8ba39da9 | 967 | void AliITSsimulationSDD::ApplyCrosstalk(Int_t mod) { |
aacedc3e | 968 | // function add the crosstalk effect to signal |
969 | // temporal function, should be checked...!!! | |
8ba39da9 | 970 | AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1); |
971 | ||
972 | Int_t fNofMaps = seg->Npz(); | |
973 | Int_t fMaxNofSamples = seg->Npx(); | |
aacedc3e | 974 | |
975 | // create and inizialice crosstalk map | |
976 | Float_t* ctk = new Float_t[fNofMaps*fMaxNofSamples+1]; | |
977 | if( ctk == NULL ) { | |
978 | Error( "ApplyCrosstalk", "no memory for temporal map: exit \n" ); | |
979 | return; | |
980 | } | |
981 | memset( ctk, 0, sizeof(Float_t)*(fNofMaps*fMaxNofSamples+1) ); | |
fcf95fc7 | 982 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(mod); |
aacedc3e | 983 | |
984 | Double_t noise, baseline; | |
8ba39da9 | 985 | res->GetNoiseParam( noise, baseline ); |
aacedc3e | 986 | for( Int_t z=0; z<fNofMaps; z++ ) { |
987 | Bool_t on = kFALSE; | |
988 | Int_t tstart = 0; | |
989 | Int_t tstop = 0; | |
990 | Int_t nTsteps = 0; | |
50d05d7b | 991 | |
aacedc3e | 992 | for( Int_t l=0; l<fMaxNofSamples; l++ ) { |
993 | Float_t fadc = (Float_t)fHitMap2->GetSignal( z, l ); | |
994 | if( fadc > baseline ) { | |
995 | if( on == kFALSE && l<fMaxNofSamples-4 ) { | |
996 | Float_t fadc1 = (Float_t)fHitMap2->GetSignal( z, l+1 ); | |
997 | if( fadc1 < fadc ) continue; | |
998 | on = kTRUE; | |
999 | nTsteps = 0; | |
1000 | tstart = l; | |
1001 | } | |
1002 | nTsteps++; | |
1003 | } | |
1004 | else { // end fadc > baseline | |
1005 | if( on == kTRUE ) { | |
1006 | if( nTsteps > 2 ) { | |
1007 | tstop = l; | |
1008 | // make smooth derivative | |
1009 | Float_t* dev = new Float_t[fMaxNofSamples+1]; | |
1010 | memset( dev, 0, sizeof(Float_t)*(fMaxNofSamples+1) ); | |
1011 | if( ctk == NULL ) { | |
1012 | Error( "ApplyCrosstalk", | |
1013 | "no memory for temporal array: exit \n" ); | |
1014 | return; | |
1015 | } | |
1016 | for( Int_t i=tstart; i<tstop; i++ ) { | |
1017 | if( i > 2 && i < fMaxNofSamples-2 ) | |
1018 | dev[i] = -0.2*fHitMap2->GetSignal( z,i-2 ) | |
1019 | -0.1*fHitMap2->GetSignal( z,i-1 ) | |
1020 | +0.1*fHitMap2->GetSignal( z,i+1 ) | |
1021 | +0.2*fHitMap2->GetSignal( z,i+2 ); | |
1022 | } | |
50d05d7b | 1023 | |
aacedc3e | 1024 | // add crosstalk contribution to neibourg anodes |
1025 | for( Int_t i=tstart; i<tstop; i++ ) { | |
1026 | Int_t anode = z - 1; | |
1027 | Int_t i1 = (Int_t)((i-tstart)*.61+tstart+0.5); // | |
1028 | Float_t ctktmp = -dev[i1] * 0.25; | |
1029 | if( anode > 0 ) { | |
1030 | ctk[anode*fMaxNofSamples+i] += ctktmp; | |
1031 | } | |
1032 | anode = z + 1; | |
1033 | if( anode < fNofMaps ) { | |
1034 | ctk[anode*fMaxNofSamples+i] += ctktmp; | |
1035 | } | |
1036 | } | |
1037 | delete [] dev; | |
50d05d7b | 1038 | |
aacedc3e | 1039 | } // if( nTsteps > 2 ) |
1040 | on = kFALSE; | |
1041 | } // if( on == kTRUE ) | |
1042 | } // else | |
1043 | } | |
3d2c9d72 | 1044 | } |
50d05d7b | 1045 | |
aacedc3e | 1046 | for( Int_t a=0; a<fNofMaps; a++ ) |
1047 | for( Int_t t=0; t<fMaxNofSamples; t++ ) { | |
1048 | Float_t signal = fHitMap2->GetSignal(a,t)+ctk[a*fMaxNofSamples+t]; | |
1049 | fHitMap2->SetHit( a, t, signal ); | |
1050 | } | |
1051 | ||
1052 | delete [] ctk; | |
50d05d7b | 1053 | } |
8a33ae9e | 1054 | //______________________________________________________________________ |
aacedc3e | 1055 | void AliITSsimulationSDD::GetAnodeBaseline(Int_t i,Double_t &baseline, |
8ba39da9 | 1056 | Double_t &noise) const{ |
aacedc3e | 1057 | // Returns the Baseline for a particular anode. |
1058 | baseline = fBaseline[i]; | |
1059 | noise = fNoise[i]; | |
b0f5e3fc | 1060 | } |
8a33ae9e | 1061 | //______________________________________________________________________ |
b0f5e3fc | 1062 | void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl, |
1063 | Int_t &th){ | |
aacedc3e | 1064 | // Returns the compression alogirthm parameters |
1065 | Int_t size = fD.GetSize(); | |
1066 | if (size > 2 ) { | |
1067 | db=fD[i]; tl=fT1[i]; th=fT2[i]; | |
8a33ae9e | 1068 | } else { |
aacedc3e | 1069 | if (size <= 2 && i>=fNofMaps/2) { |
1070 | db=fD[1]; tl=fT1[1]; th=fT2[1]; | |
1071 | } else { | |
1072 | db=fD[0]; tl=fT1[0]; th=fT2[0]; | |
1073 | } // end if size <=2 && i>=fNofMaps/2 | |
1074 | } // end if size >2 | |
b0f5e3fc | 1075 | } |
8a33ae9e | 1076 | //______________________________________________________________________ |
b0f5e3fc | 1077 | void AliITSsimulationSDD::CompressionParam(Int_t i,Int_t &db,Int_t &tl){ |
aacedc3e | 1078 | // returns the compression alogirthm parameters |
1079 | Int_t size = fD.GetSize(); | |
1080 | ||
1081 | if (size > 2 ) { | |
1082 | db=fD[i]; tl=fT1[i]; | |
8a33ae9e | 1083 | } else { |
aacedc3e | 1084 | if (size <= 2 && i>=fNofMaps/2) { |
1085 | db=fD[1]; tl=fT1[1]; | |
1086 | } else { | |
1087 | db=fD[0]; tl=fT1[0]; | |
1088 | } // end if size <=2 && i>=fNofMaps/2 | |
1089 | // Warning("CompressionParam", | |
1090 | // "Size= %d . Values i=%d ; db= %d ; tl= %d", | |
1091 | // size,i,db,tl); | |
1092 | } // end if size > 2 | |
b0f5e3fc | 1093 | } |
8a33ae9e | 1094 | //______________________________________________________________________ |
b0f5e3fc | 1095 | void AliITSsimulationSDD::SetCompressParam(){ |
aacedc3e | 1096 | // Sets the compression alogirthm parameters |
1097 | Int_t cp[8],i; | |
fcf95fc7 | 1098 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
aacedc3e | 1099 | |
8ba39da9 | 1100 | res->GiveCompressParam(cp); |
aacedc3e | 1101 | for (i=0; i<2; i++) { |
1102 | fD[i] = cp[i]; | |
1103 | fT1[i] = cp[i+2]; | |
1104 | fT2[i] = cp[i+4]; | |
1105 | fTol[i] = cp[i+6]; | |
1106 | } // end for i | |
b0f5e3fc | 1107 | } |
8a33ae9e | 1108 | //______________________________________________________________________ |
b0f5e3fc | 1109 | void AliITSsimulationSDD::ReadBaseline(){ |
aacedc3e | 1110 | // read baseline and noise from file - either a .root file and in this |
1111 | // case data should be organised in a tree with one entry for each | |
1112 | // module => reading should be done accordingly | |
1113 | // or a classic file and do smth. like this: | |
1114 | // Read baselines and noise for SDD | |
1115 | ||
1116 | Int_t na,pos; | |
1117 | Float_t bl,n; | |
1118 | char input[100], base[100], param[100]; | |
1119 | char *filtmp; | |
fcf95fc7 | 1120 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 1121 | res->Filenames(input,base,param); |
aacedc3e | 1122 | fFileName=base; |
1123 | // | |
1124 | filtmp = gSystem->ExpandPathName(fFileName.Data()); | |
1125 | FILE *bline = fopen(filtmp,"r"); | |
1126 | na = 0; | |
1127 | ||
1128 | if(bline) { | |
1129 | while(fscanf(bline,"%d %f %f",&pos, &bl, &n) != EOF) { | |
1130 | if (pos != na+1) { | |
1131 | Error("ReadBaseline","Anode number not in increasing order!", | |
1132 | filtmp); | |
1133 | exit(1); | |
1134 | } // end if pos != na+1 | |
1135 | fBaseline[na]=bl; | |
1136 | fNoise[na]=n; | |
1137 | na++; | |
1138 | } // end while | |
1139 | } else { | |
1140 | Error("ReadBaseline"," THE BASELINE FILE %s DOES NOT EXIST !",filtmp); | |
1141 | exit(1); | |
1142 | } // end if(bline) | |
1143 | ||
1144 | fclose(bline); | |
1145 | delete [] filtmp; | |
b0f5e3fc | 1146 | } |
8a33ae9e | 1147 | //______________________________________________________________________ |
1148 | Int_t AliITSsimulationSDD::Convert10to8(Int_t signal) const { | |
aacedc3e | 1149 | // To the 10 to 8 bit lossive compression. |
1150 | // code from Davide C. and Albert W. | |
1151 | ||
1152 | if (signal < 128) return signal; | |
1153 | if (signal < 256) return (128+((signal-128)>>1)); | |
1154 | if (signal < 512) return (192+((signal-256)>>3)); | |
1155 | if (signal < 1024) return (224+((signal-512)>>4)); | |
1156 | return 0; | |
b0f5e3fc | 1157 | } |
50d05d7b | 1158 | /* |
8a33ae9e | 1159 | //______________________________________________________________________ |
b0f5e3fc | 1160 | AliITSMap* AliITSsimulationSDD::HitMap(Int_t i){ |
aacedc3e | 1161 | //Return the correct map. |
8a33ae9e | 1162 | |
aacedc3e | 1163 | return ((i==0)? fHitMap1 : fHitMap2); |
3d2c9d72 | 1164 | } |
1165 | */ | |
8a33ae9e | 1166 | //______________________________________________________________________ |
e8189707 | 1167 | void AliITSsimulationSDD::ZeroSuppression(const char *option) { |
aacedc3e | 1168 | // perform the zero suppresion |
1169 | ||
1170 | if (strstr(option,"2D")) { | |
1171 | //Init2D(); // activate if param change module by module | |
1172 | Compress2D(); | |
1173 | } else if (strstr(option,"1D")) { | |
1174 | //Init1D(); // activate if param change module by module | |
1175 | Compress1D(); | |
1176 | } else StoreAllDigits(); | |
b0f5e3fc | 1177 | } |
8a33ae9e | 1178 | //______________________________________________________________________ |
b0f5e3fc | 1179 | void AliITSsimulationSDD::Init2D(){ |
aacedc3e | 1180 | // read in and prepare arrays: fD, fT1, fT2 |
1181 | // savemu[nanodes], savesigma[nanodes] | |
1182 | // read baseline and noise from file - either a .root file and in this | |
1183 | // case data should be organised in a tree with one entry for each | |
1184 | // module => reading should be done accordingly | |
1185 | // or a classic file and do smth. like this ( code from Davide C. and | |
1186 | // Albert W.) : | |
1187 | // Read 2D zero-suppression parameters for SDD | |
1188 | ||
1189 | if (!strstr(fParam.Data(),"file")) return; | |
1190 | ||
1191 | Int_t na,pos,tempTh; | |
1192 | Float_t mu,sigma; | |
1193 | Float_t *savemu = new Float_t [fNofMaps]; | |
1194 | Float_t *savesigma = new Float_t [fNofMaps]; | |
1195 | char input[100],basel[100],par[100]; | |
1196 | char *filtmp; | |
1197 | Double_t tmp1,tmp2; | |
fcf95fc7 | 1198 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 1199 | |
1200 | res->Thresholds(tmp1,tmp2); | |
aacedc3e | 1201 | Int_t minval = static_cast<Int_t>(tmp1); |
1202 | ||
8ba39da9 | 1203 | res->Filenames(input,basel,par); |
aacedc3e | 1204 | fFileName = par; |
1205 | // | |
1206 | filtmp = gSystem->ExpandPathName(fFileName.Data()); | |
1207 | FILE *param = fopen(filtmp,"r"); | |
1208 | na = 0; | |
1209 | ||
1210 | if(param) { | |
1211 | while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) { | |
1212 | if (pos != na+1) { | |
1213 | Error("Init2D","Anode number not in increasing order!",filtmp); | |
1214 | exit(1); | |
1215 | } // end if pos != na+1 | |
1216 | savemu[na] = mu; | |
1217 | savesigma[na] = sigma; | |
1218 | if ((2.*sigma) < mu) { | |
1219 | fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5); | |
1220 | mu = 2.0 * sigma; | |
1221 | } else fD[na] = 0; | |
1222 | tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval; | |
1223 | if (tempTh < 0) tempTh=0; | |
1224 | fT1[na] = tempTh; | |
1225 | tempTh = (Int_t)floor(mu+3.0*sigma+0.5) - minval; | |
1226 | if (tempTh < 0) tempTh=0; | |
1227 | fT2[na] = tempTh; | |
1228 | na++; | |
1229 | } // end while | |
1230 | } else { | |
1231 | Error("Init2D","THE FILE %s DOES NOT EXIST !",filtmp); | |
1232 | exit(1); | |
1233 | } // end if(param) | |
1234 | ||
1235 | fclose(param); | |
1236 | delete [] filtmp; | |
1237 | delete [] savemu; | |
1238 | delete [] savesigma; | |
8a33ae9e | 1239 | } |
1240 | //______________________________________________________________________ | |
b0f5e3fc | 1241 | void AliITSsimulationSDD::Compress2D(){ |
aacedc3e | 1242 | // simple ITS cluster finder -- online zero-suppression conditions |
1243 | ||
1244 | Int_t db,tl,th; | |
1245 | Double_t tmp1,tmp2; | |
fcf95fc7 | 1246 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 1247 | |
1248 | res->Thresholds(tmp1,tmp2); | |
aacedc3e | 1249 | Int_t minval = static_cast<Int_t>(tmp1); |
8ba39da9 | 1250 | Bool_t write = res->OutputOption(); |
1251 | Bool_t do10to8 = res->Do10to8(); | |
aacedc3e | 1252 | Int_t nz, nl, nh, low, i, j; |
1253 | ||
1254 | for (i=0; i<fNofMaps; i++) { | |
1255 | CompressionParam(i,db,tl,th); | |
1256 | nz = 0; | |
1257 | nl = 0; | |
1258 | nh = 0; | |
1259 | low = 0; | |
1260 | for (j=0; j<fMaxNofSamples; j++) { | |
1261 | Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j)); | |
1262 | signal -= db; // if baseline eq. is done here | |
1263 | if (signal <= 0) {nz++; continue;} | |
1264 | if ((signal - tl) < minval) low++; | |
1265 | if ((signal - th) >= minval) { | |
1266 | nh++; | |
1267 | Bool_t cond=kTRUE; | |
1268 | FindCluster(i,j,signal,minval,cond); | |
1269 | if(cond && j && | |
1270 | ((TMath::Abs(fHitMap2->GetSignal(i,j-1))-th)>=minval)){ | |
1271 | if(do10to8) signal = Convert10to8(signal); | |
1272 | AddDigit(i,j,signal); | |
1273 | } // end if cond&&j&&() | |
1274 | } else if ((signal - tl) >= minval) nl++; | |
1275 | } // end for j loop time samples | |
1276 | if (write) TreeB()->Fill(nz,nl,nh,low,i+1); | |
1277 | } //end for i loop anodes | |
1278 | ||
1279 | char hname[30]; | |
1280 | if (write) { | |
1281 | sprintf(hname,"TNtuple%d_%d",fModule,fEvent); | |
1282 | TreeB()->Write(hname); | |
1283 | // reset tree | |
1284 | TreeB()->Reset(); | |
1285 | } // end if write | |
8a33ae9e | 1286 | } |
1287 | //______________________________________________________________________ | |
b0f5e3fc | 1288 | void AliITSsimulationSDD::FindCluster(Int_t i,Int_t j,Int_t signal, |
ece86d9a | 1289 | Int_t minval,Bool_t &cond){ |
aacedc3e | 1290 | // Find clusters according to the online 2D zero-suppression algorithm |
fcf95fc7 | 1291 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 1292 | AliITSsegmentationSDD* seg = (AliITSsegmentationSDD*)GetSegmentationModel(1); |
1293 | ||
1294 | Bool_t do10to8 = res->Do10to8(); | |
aacedc3e | 1295 | Bool_t high = kFALSE; |
1296 | ||
1297 | fHitMap2->FlagHit(i,j); | |
1298 | // | |
1299 | // check the online zero-suppression conditions | |
1300 | // | |
1301 | const Int_t kMaxNeighbours = 4; | |
1302 | Int_t nn; | |
1303 | Int_t dbx,tlx,thx; | |
1304 | Int_t xList[kMaxNeighbours], yList[kMaxNeighbours]; | |
8ba39da9 | 1305 | seg->Neighbours(i,j,&nn,xList,yList); |
aacedc3e | 1306 | Int_t in,ix,iy,qns; |
1307 | for (in=0; in<nn; in++) { | |
1308 | ix=xList[in]; | |
1309 | iy=yList[in]; | |
1310 | if (fHitMap2->TestHit(ix,iy)==kUnused) { | |
1311 | CompressionParam(ix,dbx,tlx,thx); | |
1312 | Int_t qn = (Int_t)(fHitMap2->GetSignal(ix,iy)); | |
1313 | qn -= dbx; // if baseline eq. is done here | |
1314 | if ((qn-tlx) < minval) { | |
1315 | fHitMap2->FlagHit(ix,iy); | |
1316 | continue; | |
1317 | } else { | |
1318 | if ((qn - thx) >= minval) high=kTRUE; | |
1319 | if (cond) { | |
1320 | if(do10to8) signal = Convert10to8(signal); | |
1321 | AddDigit(i,j,signal); | |
1322 | } // end if cond | |
1323 | if(do10to8) qns = Convert10to8(qn); | |
1324 | else qns=qn; | |
1325 | if (!high) AddDigit(ix,iy,qns); | |
1326 | cond=kFALSE; | |
1327 | if(!high) fHitMap2->FlagHit(ix,iy); | |
1328 | } // end if qn-tlx < minval | |
1329 | } // end if TestHit | |
1330 | } // end for in loop over neighbours | |
b0f5e3fc | 1331 | } |
8a33ae9e | 1332 | //______________________________________________________________________ |
b0f5e3fc | 1333 | void AliITSsimulationSDD::Init1D(){ |
aacedc3e | 1334 | // this is just a copy-paste of input taken from 2D algo |
1335 | // Torino people should give input | |
1336 | // Read 1D zero-suppression parameters for SDD | |
1337 | ||
1338 | if (!strstr(fParam.Data(),"file")) return; | |
1339 | ||
1340 | Int_t na,pos,tempTh; | |
1341 | Float_t mu,sigma; | |
1342 | Float_t *savemu = new Float_t [fNofMaps]; | |
1343 | Float_t *savesigma = new Float_t [fNofMaps]; | |
1344 | char input[100],basel[100],par[100]; | |
1345 | char *filtmp; | |
1346 | Double_t tmp1,tmp2; | |
fcf95fc7 | 1347 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 1348 | |
1349 | res->Thresholds(tmp1,tmp2); | |
aacedc3e | 1350 | Int_t minval = static_cast<Int_t>(tmp1); |
1351 | ||
8ba39da9 | 1352 | res->Filenames(input,basel,par); |
aacedc3e | 1353 | fFileName=par; |
1354 | ||
1355 | // set first the disable and tol param | |
1356 | SetCompressParam(); | |
1357 | // | |
1358 | filtmp = gSystem->ExpandPathName(fFileName.Data()); | |
1359 | FILE *param = fopen(filtmp,"r"); | |
1360 | na = 0; | |
1361 | ||
1362 | if (param) { | |
1363 | fscanf(param,"%d %d %d %d ", &fT2[0], &fT2[1], &fTol[0], &fTol[1]); | |
1364 | while(fscanf(param,"%d %f %f",&pos, &mu, &sigma) != EOF) { | |
1365 | if (pos != na+1) { | |
1366 | Error("Init1D","Anode number not in increasing order!",filtmp); | |
1367 | exit(1); | |
1368 | } // end if pos != na+1 | |
1369 | savemu[na]=mu; | |
1370 | savesigma[na]=sigma; | |
1371 | if ((2.*sigma) < mu) { | |
1372 | fD[na] = (Int_t)floor(mu - 2.0*sigma + 0.5); | |
1373 | mu = 2.0 * sigma; | |
1374 | } else fD[na] = 0; | |
1375 | tempTh = (Int_t)floor(mu+2.25*sigma+0.5) - minval; | |
1376 | if (tempTh < 0) tempTh=0; | |
1377 | fT1[na] = tempTh; | |
1378 | na++; | |
1379 | } // end while | |
1380 | } else { | |
1381 | Error("Init1D","THE FILE %s DOES NOT EXIST !",filtmp); | |
1382 | exit(1); | |
1383 | } // end if(param) | |
1384 | ||
1385 | fclose(param); | |
1386 | delete [] filtmp; | |
1387 | delete [] savemu; | |
1388 | delete [] savesigma; | |
8a33ae9e | 1389 | } |
1390 | //______________________________________________________________________ | |
b0f5e3fc | 1391 | void AliITSsimulationSDD::Compress1D(){ |
aacedc3e | 1392 | // 1D zero-suppression algorithm (from Gianluca A.) |
1393 | Int_t dis,tol,thres,decr,diff; | |
1394 | UChar_t *str=fStream->Stream(); | |
1395 | Int_t counter=0; | |
fcf95fc7 | 1396 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 1397 | |
1398 | Bool_t do10to8=res->Do10to8(); | |
aacedc3e | 1399 | Int_t last=0; |
1400 | Int_t k,i,j; | |
1401 | ||
1402 | for (k=0; k<2; k++) { | |
1403 | tol = Tolerance(k); | |
1404 | dis = Disable(k); | |
1405 | for (i=0; i<fNofMaps/2; i++) { | |
1406 | Bool_t firstSignal=kTRUE; | |
1407 | Int_t idx=i+k*fNofMaps/2; | |
1408 | if( !fAnodeFire[idx] ) continue; | |
1409 | CompressionParam(idx,decr,thres); | |
1410 | ||
1411 | for (j=0; j<fMaxNofSamples; j++) { | |
1412 | Int_t signal=(Int_t)(fHitMap2->GetSignal(idx,j)); | |
1413 | signal -= decr; // if baseline eq. | |
1414 | if(do10to8) signal = Convert10to8(signal); | |
1415 | if (signal <= thres) { | |
1416 | signal=0; | |
1417 | diff=128; | |
1418 | last=0; | |
1419 | // write diff in the buffer for HuffT | |
1420 | str[counter]=(UChar_t)diff; | |
1421 | counter++; | |
1422 | continue; | |
1423 | } // end if signal <= thres | |
1424 | diff=signal-last; | |
1425 | if (diff > 127) diff=127; | |
1426 | if (diff < -128) diff=-128; | |
1427 | if (signal < dis) { | |
1428 | // tol has changed to 8 possible cases ? - one can write | |
1429 | // this if(TMath::Abs(diff)<tol) ... else ... | |
1430 | if(TMath::Abs(diff)<tol) diff=0; | |
1431 | // or keep it as it was before | |
1432 | AddDigit(idx,j,last+diff); | |
1433 | } else { | |
1434 | AddDigit(idx,j,signal); | |
1435 | } // end if singal < dis | |
1436 | diff += 128; | |
1437 | // write diff in the buffer used to compute Huffman tables | |
1438 | if (firstSignal) str[counter]=(UChar_t)signal; | |
1439 | else str[counter]=(UChar_t)diff; | |
1440 | counter++; | |
1441 | last=signal; | |
1442 | firstSignal=kFALSE; | |
1443 | } // end for j loop time samples | |
1444 | } // end for i loop anodes one half of detector | |
1445 | } // end for k | |
b0f5e3fc | 1446 | |
1447 | // check | |
aacedc3e | 1448 | fStream->CheckCount(counter); |
b0f5e3fc | 1449 | |
aacedc3e | 1450 | // open file and write out the stream of diff's |
1451 | static Bool_t open=kTRUE; | |
1452 | static TFile *outFile; | |
8ba39da9 | 1453 | Bool_t write = res->OutputOption(); |
aacedc3e | 1454 | TDirectory *savedir = gDirectory; |
b0f5e3fc | 1455 | |
aacedc3e | 1456 | if (write ) { |
1457 | if(open) { | |
1458 | SetFileName("stream.root"); | |
1459 | cout<<"filename "<<fFileName<<endl; | |
1460 | outFile=new TFile(fFileName,"recreate"); | |
1461 | cout<<"I have opened "<<fFileName<<" file "<<endl; | |
1462 | } // end if open | |
1463 | open = kFALSE; | |
1464 | outFile->cd(); | |
1465 | fStream->Write(); | |
1466 | } // endif write | |
1467 | ||
1468 | fStream->ClearStream(); | |
1469 | ||
1470 | // back to galice.root file | |
1471 | if(savedir) savedir->cd(); | |
8a33ae9e | 1472 | } |
1473 | //______________________________________________________________________ | |
b0f5e3fc | 1474 | void AliITSsimulationSDD::StoreAllDigits(){ |
aacedc3e | 1475 | // if non-zero-suppressed data |
fcf95fc7 | 1476 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
8ba39da9 | 1477 | |
1478 | Bool_t do10to8 = res->Do10to8(); | |
aacedc3e | 1479 | Int_t i, j, digits[3]; |
1480 | ||
1481 | for (i=0; i<fNofMaps; i++) { | |
1482 | for (j=0; j<fMaxNofSamples; j++) { | |
1483 | Int_t signal=(Int_t)(fHitMap2->GetSignal(i,j)); | |
1484 | if(do10to8) signal = Convert10to8(signal); | |
1485 | digits[0] = i; | |
1486 | digits[1] = j; | |
1487 | digits[2] = signal; | |
1488 | fITS->AddRealDigit(1,digits); | |
1489 | } // end for j | |
1490 | } // end for i | |
b0f5e3fc | 1491 | } |
8a33ae9e | 1492 | //______________________________________________________________________ |
ece86d9a | 1493 | void AliITSsimulationSDD::CreateHistograms(Int_t scale){ |
aacedc3e | 1494 | // Creates histograms of maps for debugging |
1495 | Int_t i; | |
1496 | ||
1497 | fHis=new TObjArray(fNofMaps); | |
1498 | for (i=0;i<fNofMaps;i++) { | |
1499 | TString sddName("sdd_"); | |
1500 | Char_t candNum[4]; | |
1501 | sprintf(candNum,"%d",i+1); | |
1502 | sddName.Append(candNum); | |
1503 | fHis->AddAt(new TH1F(sddName.Data(),"SDD maps",scale*fMaxNofSamples, | |
1504 | 0.,(Float_t) scale*fMaxNofSamples), i); | |
1505 | } // end for i | |
b0f5e3fc | 1506 | } |
8a33ae9e | 1507 | //______________________________________________________________________ |
ece86d9a | 1508 | void AliITSsimulationSDD::FillHistograms(){ |
aacedc3e | 1509 | // fill 1D histograms from map |
8a33ae9e | 1510 | |
aacedc3e | 1511 | if (!fHis) return; |
8a33ae9e | 1512 | |
aacedc3e | 1513 | for( Int_t i=0; i<fNofMaps; i++) { |
1514 | TH1F *hist =(TH1F *)fHis->UncheckedAt(i); | |
1515 | Int_t nsamples = hist->GetNbinsX(); | |
1516 | for( Int_t j=0; j<nsamples; j++) { | |
1517 | Double_t signal=fHitMap2->GetSignal(i,j); | |
1518 | hist->Fill((Float_t)j,signal); | |
1519 | } // end for j | |
1520 | } // end for i | |
ece86d9a | 1521 | } |
8a33ae9e | 1522 | //______________________________________________________________________ |
b0f5e3fc | 1523 | void AliITSsimulationSDD::ResetHistograms(){ |
aacedc3e | 1524 | // Reset histograms for this detector |
1525 | Int_t i; | |
8a33ae9e | 1526 | |
aacedc3e | 1527 | for (i=0;i<fNofMaps;i++ ) { |
1528 | if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset(); | |
1529 | } // end for i | |
b0f5e3fc | 1530 | } |
8a33ae9e | 1531 | //______________________________________________________________________ |
b0f5e3fc | 1532 | TH1F *AliITSsimulationSDD::GetAnode(Int_t wing, Int_t anode) { |
aacedc3e | 1533 | // Fills a histogram from a give anode. |
8a33ae9e | 1534 | |
aacedc3e | 1535 | if (!fHis) return 0; |
8a33ae9e | 1536 | |
aacedc3e | 1537 | if(wing <=0 || wing > 2) { |
1538 | Warning("GetAnode","Wrong wing number: %d",wing); | |
1539 | return NULL; | |
1540 | } // end if wing <=0 || wing >2 | |
1541 | if(anode <=0 || anode > fNofMaps/2) { | |
1542 | Warning("GetAnode","Wrong anode number: %d",anode); | |
1543 | return NULL; | |
1544 | } // end if ampde <=0 || andoe > fNofMaps/2 | |
8a33ae9e | 1545 | |
aacedc3e | 1546 | Int_t index = (wing-1)*fNofMaps/2 + anode-1; |
1547 | return (TH1F*)(fHis->At(index)); | |
b0f5e3fc | 1548 | } |
8a33ae9e | 1549 | //______________________________________________________________________ |
b0f5e3fc | 1550 | void AliITSsimulationSDD::WriteToFile(TFile *hfile) { |
aacedc3e | 1551 | // Writes the histograms to a file |
b0f5e3fc | 1552 | |
aacedc3e | 1553 | if (!fHis) return; |
8a33ae9e | 1554 | |
aacedc3e | 1555 | hfile->cd(); |
1556 | Int_t i; | |
1557 | for(i=0; i<fNofMaps; i++) fHis->At(i)->Write(); //fAdcs[i]->Write(); | |
1558 | return; | |
b0f5e3fc | 1559 | } |
8a33ae9e | 1560 | //______________________________________________________________________ |
ece86d9a | 1561 | Float_t AliITSsimulationSDD::GetNoise() { |
aacedc3e | 1562 | // Returns the noise value |
1563 | //Bool_t do10to8=GetResp()->Do10to8(); | |
1564 | //noise will always be in the liniar part of the signal | |
1565 | Int_t decr; | |
1566 | Int_t threshold = fT1[0]; | |
1567 | char opt1[20], opt2[20]; | |
fcf95fc7 | 1568 | AliITSCalibrationSDD* res = (AliITSCalibrationSDD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSDD()); |
aacedc3e | 1569 | |
fcf95fc7 | 1570 | res->GetParamOptions(opt1,opt2); |
aacedc3e | 1571 | fParam=opt2; |
1572 | char *same = strstr(opt1,"same"); | |
1573 | Double_t noise,baseline; | |
1574 | if (same) { | |
8ba39da9 | 1575 | res->GetNoiseParam(noise,baseline); |
aacedc3e | 1576 | } else { |
1577 | static Bool_t readfile=kTRUE; | |
1578 | //read baseline and noise from file | |
1579 | if (readfile) ReadBaseline(); | |
1580 | readfile=kFALSE; | |
1581 | } // end if same | |
1582 | ||
1583 | TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2"); | |
1584 | if(c2) delete c2->GetPrimitive("noisehist"); | |
1585 | if(c2) delete c2->GetPrimitive("anode"); | |
1586 | else c2=new TCanvas("c2"); | |
1587 | c2->cd(); | |
1588 | c2->SetFillColor(0); | |
1589 | ||
1590 | TH1F *noisehist = new TH1F("noisehist","noise",100,0.,(float)2*threshold); | |
1591 | TH1F *anode = new TH1F("anode","Anode Projection",fMaxNofSamples,0., | |
1592 | (float)fMaxNofSamples); | |
1593 | Int_t i,k; | |
1594 | for (i=0;i<fNofMaps;i++) { | |
1595 | CompressionParam(i,decr,threshold); | |
1596 | if (!same) GetAnodeBaseline(i,baseline,noise); | |
1597 | anode->Reset(); | |
1598 | for (k=0;k<fMaxNofSamples;k++) { | |
1599 | Float_t signal=(Float_t)fHitMap2->GetSignal(i,k); | |
1600 | //if (signal <= (float)threshold) noisehist->Fill(signal-baseline); | |
1601 | if (signal <= (float)(threshold+decr)) noisehist->Fill(signal); | |
1602 | anode->Fill((float)k,signal); | |
1603 | } // end for k | |
1604 | anode->Draw(); | |
1605 | c2->Update(); | |
1606 | } // end for i | |
1607 | TF1 *gnoise = new TF1("gnoise","gaus",0.,threshold); | |
1608 | noisehist->Fit("gnoise","RQ"); | |
1609 | noisehist->Draw(); | |
ece86d9a | 1610 | c2->Update(); |
aacedc3e | 1611 | Float_t mnoise = gnoise->GetParameter(1); |
1612 | cout << "mnoise : " << mnoise << endl; | |
1613 | Float_t rnoise = gnoise->GetParameter(2); | |
1614 | cout << "rnoise : " << rnoise << endl; | |
1615 | delete noisehist; | |
1616 | return rnoise; | |
50d05d7b | 1617 | } |
1618 | //______________________________________________________________________ | |
1619 | void AliITSsimulationSDD::WriteSDigits(){ | |
aacedc3e | 1620 | // Fills the Summable digits Tree |
1621 | static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS"); | |
1622 | ||
1623 | for( Int_t i=0; i<fNofMaps; i++ ) { | |
1624 | if( !fAnodeFire[i] ) continue; | |
1625 | for( Int_t j=0; j<fMaxNofSamples; j++ ) { | |
1626 | Double_t sig = fHitMap2->GetSignal( i, j ); | |
1627 | if( sig > 0.2 ) { | |
1628 | Int_t jdx = j*fScaleSize; | |
1629 | Int_t index = fpList->GetHitIndex( i, j ); | |
1630 | AliITSpListItem pItemTmp2( fModule, index, 0. ); | |
1631 | // put the fScaleSize analog digits in only one | |
1632 | for( Int_t ik=0; ik<fScaleSize; ik++ ) { | |
1633 | AliITSpListItem *pItemTmp = fpList->GetpListItem(i,jdx+ik); | |
1634 | if( pItemTmp == 0 ) continue; | |
1635 | pItemTmp2.Add( pItemTmp ); | |
1636 | } | |
1637 | pItemTmp2.AddSignalAfterElect( fModule, index, sig ); | |
1638 | pItemTmp2.AddNoise(fModule,index,fHitNoiMap2->GetSignal(i,j)); | |
1639 | aliITS->AddSumDigit( pItemTmp2 ); | |
1640 | } // end if (sig > 0.2) | |
1641 | } | |
48058160 | 1642 | } |
aacedc3e | 1643 | return; |
b0f5e3fc | 1644 | } |
8a33ae9e | 1645 | //______________________________________________________________________ |
d2f55a22 | 1646 | void AliITSsimulationSDD::PrintStatus() const { |
aacedc3e | 1647 | // Print SDD simulation Parameters |
1648 | ||
1649 | cout << "**************************************************" << endl; | |
1650 | cout << " Silicon Drift Detector Simulation Parameters " << endl; | |
1651 | cout << "**************************************************" << endl; | |
1652 | cout << "Flag for Perpendicular tracks: " << (Int_t) fFlag << endl; | |
1653 | cout << "Flag for noise checking: " << (Int_t) fCheckNoise << endl; | |
1654 | cout << "Flag to switch off electronics: " << (Int_t) fDoFFT << endl; | |
1655 | cout << "Number pf Anodes used: " << fNofMaps << endl; | |
1656 | cout << "Number of Time Samples: " << fMaxNofSamples << endl; | |
1657 | cout << "Scale size factor: " << fScaleSize << endl; | |
1658 | cout << "**************************************************" << endl; | |
44a312c3 | 1659 | } |