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