]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSsimulationSPDdubna.cxx
New methods and data member added by M. Horner.
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSPDdubna.cxx
CommitLineData
f74211b0 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 **************************************************************************/
15
16/*
17$Log$
99df08fd 18Revision 1.9 2002/10/22 14:45:45 alibrary
19Introducing Riostream.h
20
4ae5bbc4 21Revision 1.8 2002/10/14 14:57:08 hristov
22Merging the VirtualMC branch to the main development branch (HEAD)
23
b9d0a01d 24Revision 1.3.8.2 2002/10/14 13:14:08 hristov
25Updating VirtualMC to v3-09-02
26
27Revision 1.7 2002/09/09 17:23:28 nilsen
28Minor changes in support of changes to AliITSdigitS?D class'.
29
ee86d557 30Revision 1.6 2002/08/21 22:09:58 nilsen
31Updated SPD simulation with difusion effects. ReWritten Hit to SDigits
32code.
33
f74211b0 34*/
4ae5bbc4 35#include <Riostream.h>
409f8c84 36#include <TRandom.h>
37#include <TH1.h>
38#include <TMath.h>
39#include <TString.h>
40#include <TParticle.h>
41
409f8c84 42#include "AliRun.h"
43#include "AliITS.h"
44#include "AliITShit.h"
45#include "AliITSdigit.h"
46#include "AliITSmodule.h"
47#include "AliITSMapA2.h"
2cc6b29a 48#include "AliITSpList.h"
409f8c84 49#include "AliITSsimulationSPDdubna.h"
f74211b0 50#include "AliITSsegmentationSPD.h"
51#include "AliITSresponseSPDdubna.h"
409f8c84 52
f74211b0 53//#define DEBUG
409f8c84 54
55ClassImp(AliITSsimulationSPDdubna)
56////////////////////////////////////////////////////////////////////////
57// Version: 0
58// Written by Boris Batyunya
59// December 20 1999
60//
61// AliITSsimulationSPDdubna is the simulation of SPDs
2cc6b29a 62//______________________________________________________________________
63
64
65AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(){
66 // constructor
67
68 fResponse = 0;
69 fSegmentation = 0;
70 fMapA2 = 0;
71 fpList = 0;
72 fModule = 0;
73 fEvent = 0;
74 fHis = 0;
75 fNoise = 0.;
76 fBaseline = 0.;
77 fNPixelsZ = 0;
78 fNPixelsX = 0;
409f8c84 79}
2cc6b29a 80//______________________________________________________________________
81AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(AliITSsegmentation *seg,
82 AliITSresponse *resp){
83 // standard constructor
f74211b0 84 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
409f8c84 85
2cc6b29a 86 fHis = 0;
87 fResponse = resp;
88 fSegmentation = seg;
89 fModule = 0;
90 fEvent = 0;
409f8c84 91
99df08fd 92 fNPixelsZ=GetSeg()->Npz();
93 fNPixelsX=GetSeg()->Npx();
409f8c84 94
99df08fd 95 GetResp()->GetNoiseParam(fNoise,fBaseline);
96 GetResp()->SetDistanceOverVoltage(kmictocm*GetSeg()->Dy(),50.0);
409f8c84 97
99df08fd 98// fMapA2 = new AliITSMapA2(GetSeg());
f74211b0 99 fMapA2 = 0;
409f8c84 100
2cc6b29a 101 fpList = new AliITSpList(fNPixelsZ+1,fNPixelsX+1);
409f8c84 102
2cc6b29a 103}
104//______________________________________________________________________
105AliITSsimulationSPDdubna::~AliITSsimulationSPDdubna(){
106 // destructor
409f8c84 107
f74211b0 108 if(fMapA2) delete fMapA2;
409f8c84 109
2cc6b29a 110 if (fHis) {
111 fHis->Delete();
112 delete fHis;
113 } // end if fHis
409f8c84 114}
2cc6b29a 115//______________________________________________________________________
116AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(const
117 AliITSsimulationSPDdubna
118 &source){
119 // Copy Constructor
120 if(&source == this) return;
121 this->fMapA2 = source.fMapA2;
122 this->fNoise = source.fNoise;
123 this->fBaseline = source.fBaseline;
124 this->fNPixelsX = source.fNPixelsX;
125 this->fNPixelsZ = source.fNPixelsZ;
126 this->fHis = source.fHis;
127 return;
128}
129//______________________________________________________________________
130AliITSsimulationSPDdubna& AliITSsimulationSPDdubna::operator=(const
131 AliITSsimulationSPDdubna &source){
132 // Assignment operator
133 if(&source == this) return *this;
134 this->fMapA2 = source.fMapA2;
135 this->fNoise = source.fNoise;
136 this->fBaseline = source.fBaseline;
137 this->fNPixelsX = source.fNPixelsX;
138 this->fNPixelsZ = source.fNPixelsZ;
139 this->fHis = source.fHis;
140 return *this;
141}
142//______________________________________________________________________
143void AliITSsimulationSPDdubna::InitSimulationModule(Int_t module, Int_t event){
144 // This function creates maps to build the list of tracks for each
145 // summable digit.
146 //
147 // Inputs:
148 // Int_t module // Module number to be simulated
149 // Int_t event // Event number to be simulated
150 //
151 // Outputs:
152 // none
153 //
154 // Returns:
155 // none
409f8c84 156
2cc6b29a 157 fModule = module;
158 fEvent = event;
f74211b0 159// fMapA2->ClearMap();
2cc6b29a 160 fpList->ClearMap();
161}
162//_____________________________________________________________________
163void AliITSsimulationSPDdubna::SDigitiseModule(AliITSmodule *mod, Int_t mask,
164 Int_t event){
165 // This function begins the work of creating S-Digits
166 //
167 // Inputs:
168 // AliITSmodule *mod // module
169 // Int_t mask // mask to be applied to the module
170 //
171 // Outputs:
172 // none
173 //
174 // Return:
175 // test // test returns kTRUE if the module contained hits
176 // // test returns kFALSE if it did not contain hits
409f8c84 177
2cc6b29a 178 Int_t module = 0;
409f8c84 179
2cc6b29a 180 if(!(mod->GetNhits())) return;// if module has no hits don't create Sdigits
181 fModule = mod->GetIndex();
182 HitToSDigit(mod, module, mask, fpList);
183 WriteSDigits(fpList);
f74211b0 184// fMapA2->ClearMap();
2cc6b29a 185 fpList->ClearMap();
409f8c84 186}
2cc6b29a 187//______________________________________________________________________
188void AliITSsimulationSPDdubna::WriteSDigits(AliITSpList *pList){
189 // This function adds each S-Digit to pList
190 //
191 // Inputs:
192 // AliITSpList *pList
193 //
194 // Outputs:
195 // none
196 //
197 // Return:
198 // none
7d50ea21 199 Int_t ix, nix, iz, niz;
2cc6b29a 200 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
201
7d50ea21 202 pList->GetMaxMapIndex(niz, nix);
99df08fd 203 for(iz=0; iz<niz-1; iz++)for(ix=0; ix<nix-1; ix++){
204 if(pList->GetSignalOnly(iz+1,ix+1)>0.0){
205 aliITS->AddSumDigit(*(pList->GetpListItem(iz+1,ix+1)));
f74211b0 206#ifdef DEBUG
207 cout <<"SDigits " << iz << "," << ix << "," <<
99df08fd 208 *(pList->GetpListItem(iz+1,ix+1)) << endl;
f74211b0 209#endif
2cc6b29a 210 } // end if pList
7d50ea21 211 } // end for iz,ix
2cc6b29a 212 return;
213}
214//______________________________________________________________________
215void AliITSsimulationSPDdubna::FinishSDigitiseModule(){
216 // This function calls SDigitsToDigits which creates Digits from SDigits
217 //
218 // Inputs:
219 // none
220 //
221 // Outputs:
222 // none
223 // Return
224 // none
409f8c84 225
2cc6b29a 226 SDigitsToDigits(fModule, fpList);
227 return;
228}
229//______________________________________________________________________
230void AliITSsimulationSPDdubna::SDigitsToDigits(Int_t module,
231 AliITSpList *pList){
232 // This function adds electronic noise to the S-Digits and then adds them
233 // to a new pList
234 //
235 // Inputs:
236 // Int_t module // module number
237 // AliITSpList *pList // pList
238 //
239 // Outputs:
240 // pList is passed along to the functions ChargeToSignal and GetList
241 //
242 // Return:
243 // none
409f8c84 244
2cc6b29a 245 fModule = module;
246 ChargeToSignal(pList); // Charge To Signal both adds noise and
f74211b0 247// fMapA2->ClearMap();
2cc6b29a 248 pList->ClearMap();
409f8c84 249}
2cc6b29a 250//______________________________________________________________________
251void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod, Int_t module,
252 Int_t dummy){
253 // This function creates Digits straight from the hits and then adds
254 // electronic noise to the digits before adding them to pList
255 //
256 // Inputs:
257 // AliITSmodule *mod // module
258 // Int_t module // module number Dummy.
259 // Int_t dummy
260 //
261 // Outputs:
262 // Each of the input variables is passed along to HitToSDigit
263 //
264 // Return:
265 // none
409f8c84 266
2cc6b29a 267 fModule = mod->GetIndex(); //This calls the module for HitToSDigit
268 HitToSDigit(mod,fModule, dummy, fpList);
269 ChargeToSignal(fpList);
f74211b0 270// fMapA2->ClearMap();
2cc6b29a 271 fpList->ClearMap();
272}
273//______________________________________________________________________
7d50ea21 274void AliITSsimulationSPDdubna::UpdateMapSignal(Int_t iz, Int_t ix, Int_t trk,
2cc6b29a 275 Int_t ht, Int_t module,
276 Double_t signal,
277 AliITSpList *pList){
278 // This function adds a signal to the pList from the pList class
279 //
280 // Inputs:
7d50ea21 281 // Int_t iz // row number
282 // Int_t ix // column number
2cc6b29a 283 // Int_t trk // track number
284 // Int_t ht // hit number
285 // Double_t signal // signal strength
286 // AliITSpList *pList // pList
287 //
288 // Outputs:
289 // All of the inputs are passed to AliITSpList::AddSignal
290 // Int_t ix // row number
291 // Int_t iz // column number
292 // Double_t sig // signal strength
293 // // These three variables are defined to preserve the
294 // // assignments used in the function AliITSMapA2::AddSignal
295 //
296 // Return:
297 // none
2cc6b29a 298
f74211b0 299// fMapA2->AddSignal(iz, ix, signal);
99df08fd 300 pList->AddSignal(iz+1,ix+1, trk, ht, fModule, signal);
2cc6b29a 301}
302//______________________________________________________________________
7d50ea21 303void AliITSsimulationSPDdubna::UpdateMapNoise(Int_t iz,
304 Int_t ix, Int_t fModule,
2cc6b29a 305 Double_t sig, Float_t noise,
306 AliITSpList *pList){
307 // This function adds noise to data in the MapA2 as well as the pList
308 //
309 // Inputs:
7d50ea21 310 // Int_t iz // row number
311 // Int_t ix // column number
2cc6b29a 312 // Int_t mod // module number
313 // Double_t sig // signal strength
314 // Double_t noise // electronic noise generated by ChargeToSignal
315 // AliITSpList *pList // pList
316 //
317 // Outputs:
318 // All of the inputs are passed to AliITSMapA2::AddSignal or
319 // AliITSpList::AddNoise
320 //
321 // Return:
322 // none
409f8c84 323
f74211b0 324// fMapA2->AddSignal(iz, ix, noise);
99df08fd 325 pList->AddNoise(iz+1,ix+1, fModule, noise);
2cc6b29a 326}
327//______________________________________________________________________
328void AliITSsimulationSPDdubna::HitToDigit(AliITSmodule *mod, Int_t module,
329 Int_t dummy){
330 DigitiseModule(mod, module, dummy);
331}
332//______________________________________________________________________
333void AliITSsimulationSPDdubna::HitToSDigit(AliITSmodule *mod, Int_t module,
f74211b0 334 Int_t dummy,AliITSpList *pList){
335 // Does the charge distributions using Gaussian diffusion charge charing.
336 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
337 TObjArray *hits = mod->GetHits();
338 Int_t nhits = hits->GetEntriesFast();
339 Int_t h,ix,iz;
340 Int_t idtrack;
341 Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0;
342 Double_t x,y,z,t,tp,st,dt=0.2,el,sig;
343 Double_t thick = kmictocm*GetSeg()->Dy();
344
345 if(nhits<=0) return;
346 for(h=0;h<nhits;h++){
347#ifdef DEBUG
348 cout << "Hits=" << h << "," << *(mod->GetHit(h)) << endl;
349#endif
350 if(mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)){
351 st =TMath::Sqrt(x1*x1+y1*y1+z1*z1);
99df08fd 352 if(st>0.0){
353 st = (Double_t)((Int_t)(1.0E+04*st)); // number of microns
354 if(st<=0.0) st = 1.0;
355 dt = 1.0/st;
356 for(t=0;t<1.0;t+=dt){ // Integrate over t
357 tp = t+0.5*dt;
358 el = GetResp()->GeVToCharge((Float_t)(dt*de));
f74211b0 359#ifdef DEBUG
99df08fd 360 if(el<=0.0) cout << "el="<<el<<" dt="<<dt<<" de="<<de<<endl;
f74211b0 361#endif
99df08fd 362 x = x0+x1*tp;
363 y = y0+y1*tp;
364 z = z0+z1*tp;
365 GetSeg()->LocalToDet(x,z,ix,iz);
366 sig = GetResp()->SigmaDiffusion1D(thick + y);
367 SpreadCharge(x,y,z,ix,iz,el,sig,idtrack,
368 mod->GetHitTrackIndex(h),h,mod->GetIndex());
369 } // end for t
370 } else { // st == 0.0 deposit it at this point
371 el = GetResp()->GeVToCharge((Float_t)de);
372 x = x0;
373 y = y0;
374 z = z0;
f74211b0 375 GetSeg()->LocalToDet(x,z,ix,iz);
376 sig = GetResp()->SigmaDiffusion1D(thick + y);
377 SpreadCharge(x,y,z,ix,iz,el,sig,
378 idtrack,mod->GetHitTrackIndex(h),h,mod->GetIndex());
99df08fd 379 } // end if st>0.0
380 }} // Loop over all hits h
381}/*
382//______________________________________________________________________
383void AliITSsimulationSPDdubna::HitToSDigit(AliITSmodule *mod, Int_t module,
384 Int_t dummy,AliITSpList *pList){
385 // Does the charge distributions using Gaussian diffusion charge charing.
386 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
387 TObjArray *hits = mod->GetHits();
388 Int_t nhits = hits->GetEntriesFast();
389 Int_t h,ix,iz,i,n;
390 Int_t idtrack;
391 Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0;
392 Double_t x,y,z,*ta,t,tp,st,dt=0.2,el,sig;
393 Double_t thick = kmictocm*GetSeg()->Dy();
394
395 if(nhits<=0) return;
396 for(h=0;h<nhits;h++){
397#ifdef DEBUG
398 cout << "Hits=" << h << "," << *(mod->GetHit(h)) << endl;
399#endif
400 if(mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)){
401 st =TMath::Sqrt(x1*x1+y1*y1+z1*z1);
402 if(st>0.0){
403 st =TMath::Sqrt(x1*x1+y1*y1+z1*z1)*(ta[i+1]-ta[i]);
404 ta = CreateFindCellEdges(x0,x1,z0,z1,n);
405 for(i=0;i<n-1;i++){
406 dt = TMath::Min((1.0E-4)/st,);
407 for(t=ta[i];t<ta[i+1];t+=dt){ // Integrate over t
408 tp = t+0.5*dt;
409 el = GetResp()->GeVToCharge((Float_t)(dt*de));
410#ifdef DEBUG
411 if(el<=0.0) cout << "el="<<el<<" dt="<<dt<<" de="<<de<<endl;
412#endif
413 x = x0+x1*tp;
414 y = y0+y1*tp;
415 z = z0+z1*tp;
416 GetSeg()->LocalToDet(x,z,ix,iz);
417 sig = GetResp()->SigmaDiffusion1D(thick + y);
418 SpreadCharge(x,y,z,ix,iz,el,sig,idtrack,
419 mod->GetHitTrackIndex(h),h,mod->GetIndex());
420 } // end for t[i]
421 delete[] t;
f74211b0 422 } else { // st == 0.0 deposit it at this point
423 el = GetResp()->GeVToCharge((Float_t)de);
424 x = x0;
425 y = y0;
426 z = z0;
427 GetSeg()->LocalToDet(x,z,ix,iz);
428 sig = GetResp()->SigmaDiffusion1D(thick + y);
429 SpreadCharge(x,y,z,ix,iz,el,sig,
430 idtrack,mod->GetHitTrackIndex(h),h,mod->GetIndex());
431 } // end if st>0.0
432 }} // Loop over all hits h
99df08fd 433 }*/
f74211b0 434//______________________________________________________________________
435void AliITSsimulationSPDdubna::SpreadCharge(Double_t x0,Double_t y0,
436 Double_t z0,Int_t ix0,Int_t iz0,
437 Double_t el,Double_t sig,Int_t t,
438 Int_t ti,Int_t hi,Int_t mod){
439 // Spreads the charge over neighboring cells. Assume charge is distributed
440 // as charge(x,z) = (el/2*pi*sig*sig)*exp(-arg)
441 // arg=((x-x0)*(x-x0)/2*sig*sig)+((z-z0*z-z0)/2*sig*sig)
442 // Defined this way, the integral over all x and z is el.
443 const Int_t knx = 3,knz = 2;
444 const Double_t kRoot2 = 1.414213562; // Sqrt(2).
445 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
446 Int_t ix,iz,ixs,ixe,izs,ize;
447 Float_t x,z;
448 Double_t x1,x2,z1,z2,s,sp;
449
450 if(sig<=0.0) {
99df08fd 451 fpList->AddSignal(iz0+1,ix0+1,t,hi,mod,el);
f74211b0 452 return;
453 } // end if
454 sp = 1.0/(sig*kRoot2);
455#ifdef DEBUG
456 cout << "sig=" << sig << " sp=" << sp << endl;
457#endif
458 ixs = TMath::Max(-knx+ix0,0);
459 ixe = TMath::Min(knx+ix0,GetSeg()->Npx()-1);
460 izs = TMath::Max(-knz+iz0,0);
461 ize = TMath::Min(knz+iz0,GetSeg()->Npz()-1);
462 for(ix=ixs;ix<=ixe;ix++) for(iz=izs;iz<=ize;iz++){
463 GetSeg()->DetToLocal(ix,iz,x,z); // pixel center
464 x1 = x;
465 z1 = z;
466 x2 = x1 + 0.5*kmictocm*GetSeg()->Dpx(ix); // Upper
467 x1 -= 0.5*kmictocm*GetSeg()->Dpx(ix); // Lower
468 z2 = z1 + 0.5*kmictocm*GetSeg()->Dpz(iz); // Upper
469 z1 -= 0.5*kmictocm*GetSeg()->Dpz(iz); // Lower
470 x1 -= x0; // Distance from where track traveled
471 x2 -= x0; // Distance from where track traveled
472 z1 -= z0; // Distance from where track traveled
473 z2 -= z0; // Distance from where track traveled
474 s = 0.25; // Correction based on definision of Erfc
475 s *= TMath::Erfc(sp*x1) - TMath::Erfc(sp*x2);
476#ifdef DEBUG
477 cout << "el=" << el << " ix0=" << ix0 << " ix=" << ix << " x0="<< x <<
478 " iz0=" << iz0 << " iz=" << iz << " z0=" << z <<
479 " sp*x1=" << sp*x1 <<" sp*x2=" << sp*x2 << " s=" << s;
480#endif
481 s *= TMath::Erfc(sp*z1) - TMath::Erfc(sp*z2);
482#ifdef DEBUG
483 cout << " sp*z1=" << sp*z1 <<" sp*z2=" << sp*z2 << " s=" << s << endl;
484#endif
99df08fd 485 fpList->AddSignal(iz+1,ix+1,t,hi,mod,s*el);
f74211b0 486 } // end for ix, iz
487}
488//______________________________________________________________________
99df08fd 489Double_t *AliITSsimulationSPDdubna::CreateFindCellEdges(Double_t x0,Double_t x1,
490 Double_t z0,Double_t z1,Int_t &n){
491 // Note: This function is a potensial source for a memory leak. The memory
492 // pointed to in its return, must be deleted.
493 // Inputs:
494 // Double_t x0 The starting location of the track step in x
495 // Double_t x1 The distance allong x for the track step
496 // Double_t z0 The starting location of the track step in z
497 // Double_t z1 The distance allong z for the track step
498 // Output:
499 // Int)t &n The size of the array returned. Minimal n=2.
500 // Return:
501 // The pointer to the array of track steps.
502 Int_t ix0,ix1,ix,iz0,iz1,iz,i;
503 Double_t x,z,lx,ux,lz,uz,a,b,c,d;
504 Double_t *t;
505
506 GetSeg()->LocalToDet(x0,z0,ix0,iz0);
507 GetSeg()->LocalToDet(x1,z1,ix1,iz1);
508 n = 2 + TMath::Abs(ix1-ix0) + TMath::Abs(iz1-iz0);
509 t = new Double_t[n];
510 t[0] = 0.0;
511 t[n-1] = 1.0;
512 x = x0;
513 z = z0;
514 for(i=1;i<n-1;i++){
515 GetSeg()->LocalToDet(x,z,ix,iz);
516 GetSeg()->CellBoundries(ix,iz,lx,ux,lz,uz);
517 a = (lx-x0)/x1;
518 if(a<=t[i-1]) a = 1.0;
519 b = (ux-x0)/x1;
520 if(b<=t[i-1]) b = 1.0;
521 c = (lz-z0)/z1;
522 if(c<=t[i-1]) c = 1.0;
523 d = (uz-z0)/z1;
524 if(d<=t[i-1]) d = 1.0;
525 t[i] = TMath::Min(TMath::Min(TMath::Min(a,b),c),d);
526 x = x0+x1*(t[i]*1.00000001);
527 z = z0+z1*(t[i]*1.00000001);
528 i++;
529 } // end for i
530 return t;
531}
532//______________________________________________________________________
f74211b0 533void AliITSsimulationSPDdubna::HitToSDigitOld(AliITSmodule *mod, Int_t module,
2cc6b29a 534 Int_t dummy, AliITSpList *pList){
535 // digitize module
409f8c84 536 const Float_t kEnToEl = 2.778e+8; // GeV->charge in electrons
537 // for 3.6 eV/pair
538 const Float_t kconv = 10000.; // cm -> microns
539
99df08fd 540 Float_t spdLength = GetSeg()->Dz();
541 Float_t spdWidth = GetSeg()->Dx();
542 Float_t spdThickness = GetSeg()->Dy();
409f8c84 543 Float_t difCoef, dum;
99df08fd 544 GetResp()->DiffCoeff(difCoef,dum);
338e4f06 545 if(spdThickness > 290) difCoef = 0.00613;
409f8c84 546
547 Float_t zPix0 = 1e+6;
548 Float_t xPix0 = 1e+6;
549 Float_t yPrev = 1e+6;
550
99df08fd 551 Float_t zPitch = GetSeg()->Dpz(0);
552 Float_t xPitch = GetSeg()->Dpx(0);
409f8c84 553
554 TObjArray *fHits = mod->GetHits();
2cc6b29a 555 module = mod->GetIndex();
409f8c84 556 Int_t nhits = fHits->GetEntriesFast();
557 if (!nhits) return;
f74211b0 558#ifdef DEBUG
2cc6b29a 559 cout<<"len,wid,thickness,nx,nz,pitchx,pitchz,difcoef ="<<spdLength<<","
560 <<spdWidth<<","<<spdThickness<<","<<fNPixelsX<<","<<fNPixelsZ<<","
561 <<xPitch<<","<<zPitch<<","<<difCoef<<endl;
f74211b0 562#endif
2cc6b29a 563 // Array of pointers to the label-signal list
409f8c84 564 Int_t indexRange[4] = {0,0,0,0};
565
566 // Fill detector maps with GEANT hits
567 // loop over hits in the module
568 static Bool_t first;
569 Int_t lasttrack=-2;
570 Int_t hit, iZi, jz, jx;
338e4f06 571 Int_t idhit=-1; //!
f74211b0 572#ifdef DEBUG
338e4f06 573 cout<<"SPDdubna: module,nhits ="<<module<<","<<nhits<<endl;
f74211b0 574#endif
409f8c84 575 for (hit=0;hit<nhits;hit++) {
576 AliITShit *iHit = (AliITShit*) fHits->At(hit);
f74211b0 577#ifdef DEBUG
578 cout << "Hits=" << hit << "," << *iHit << endl;
579#endif
338e4f06 580 //Int_t layer = iHit->GetLayer();
581 Float_t yPix0 = -spdThickness/2;
582
583 // work with the idtrack=entry number in the TreeH
584 //Int_t idhit,idtrack; //!
585 //mod->GetHitTrackAndHitIndex(hit,idtrack,idhit); //!
586 //Int_t idtrack=mod->GetHitTrackIndex(hit);
587 // or store straight away the particle position in the array
588 // of particles :
409f8c84 589 if(iHit->StatusEntering()) idhit=hit;
590 Int_t itrack = iHit->GetTrack();
591 Int_t dray = 0;
592
593 if (lasttrack != itrack || hit==(nhits-1)) first = kTRUE;
594
338e4f06 595 //Int_t parent = iHit->GetParticle()->GetFirstMother();
409f8c84 596 Int_t partcode = iHit->GetParticle()->GetPdgCode();
597
2cc6b29a 598 // partcode (pdgCode): 11 - e-, 13 - mu-, 22 - gamma, 111 - pi0,
599 // 211 - pi+, 310 - K0s, 321 - K+, 2112 - n, 2212 - p, 3122 - lambda
409f8c84 600
601 Float_t pmod = iHit->GetParticle()->P(); // total momentum at the
602 // vertex
603 pmod *= 1000;
604
409f8c84 605 if(partcode == 11 && pmod < 6) dray = 1; // delta ray is e-
606 // at p < 6 MeV/c
607
409f8c84 608 // Get hit z and x(r*phi) cordinates for each module (detector)
609 // in local system.
610
611 Float_t zPix = kconv*iHit->GetZL();
612 Float_t xPix = kconv*iHit->GetXL();
613 Float_t yPix = kconv*iHit->GetYL();
614
615 // Get track status
616 Int_t status = iHit->GetTrackStatus();
409f8c84 617
618 // Check boundaries
619 if(zPix > spdLength/2) {
f74211b0 620#ifdef DEBUG
621 cout<<"!!! SPD: z outside ="<<zPix<<endl;
622#endif
2cc6b29a 623 zPix = spdLength/2 - 10;
409f8c84 624 }
625 if(zPix < 0 && zPix < -spdLength/2) {
f74211b0 626#ifdef DEBUG
627 cout<<"!!! SPD: z outside ="<<zPix<<endl;
628#endif
2cc6b29a 629 zPix = -spdLength/2 + 10;
409f8c84 630 }
631 if(xPix > spdWidth/2) {
f74211b0 632#ifdef DEBUG
633 cout<<"!!! SPD: x outside ="<<xPix<<endl;
634#endif
2cc6b29a 635 xPix = spdWidth/2 - 10;
409f8c84 636 }
637 if(xPix < 0 && xPix < -spdWidth/2) {
f74211b0 638#ifdef DEBUG
639 cout<<"!!! SPD: x outside ="<<xPix<<endl;
640#endif
2cc6b29a 641 xPix = -spdWidth/2 + 10;
409f8c84 642 }
643 Int_t trdown = 0;
644
645 // enter Si or after event in Si
646 if (status == 66 ) {
2cc6b29a 647 zPix0 = zPix;
648 xPix0 = xPix;
649 yPrev = yPix;
650 } // end if status == 66
409f8c84 651
652 Float_t depEnergy = iHit->GetIonization();
653 // skip if the input point to Si
654
655 if(depEnergy <= 0.) continue;
656
657 // if track returns to the opposite direction:
658 if (yPix < yPrev) {
659 trdown = 1;
2cc6b29a 660 } // end if yPix < yPrev
409f8c84 661
662 // take into account the holes diffusion inside the Silicon
663 // the straight line between the entrance and exit points in Si is
664 // divided into the several steps; the diffusion is considered
665 // for each end point of step and charge
666 // is distributed between the pixels through the diffusion.
409f8c84 667
668 // ---------- the diffusion in Z (beam) direction -------
409f8c84 669 Float_t charge = depEnergy*kEnToEl; // charge in e-
670 Float_t drPath = 0.;
671 Float_t tang = 0.;
672 Float_t sigmaDif = 0.;
673 Float_t zdif = zPix - zPix0;
674 Float_t xdif = xPix - xPix0;
675 Float_t ydif = TMath::Abs(yPix - yPrev);
676 Float_t ydif0 = TMath::Abs(yPrev - yPix0);
677
678 if(ydif < 1) continue; // ydif is not zero
679
680 Float_t projDif = sqrt(xdif*xdif + zdif*zdif);
681
682 Int_t ndZ = (Int_t)TMath::Abs(zdif/zPitch) + 1;
683 Int_t ndX = (Int_t)TMath::Abs(xdif/xPitch) + 1;
684
685 // number of the steps along the track:
686 Int_t nsteps = ndZ;
687 if(ndX > ndZ) nsteps = ndX;
338e4f06 688 if(nsteps < 20) nsteps = 20; // minimum number of the steps
409f8c84 689
690 if (projDif < 5 ) {
2cc6b29a 691 drPath = (yPix-yPix0)*1.e-4;
692 drPath = TMath::Abs(drPath); // drift path in cm
693 sigmaDif = difCoef*sqrt(drPath); // sigma diffusion in cm
694 sigmaDif = sigmaDif*kconv; // sigma diffusion in microns
695 nsteps = 1;
696 } // end if projDif < 5
409f8c84 697
698 if(projDif > 5) tang = ydif/projDif;
699 Float_t dCharge = charge/nsteps; // charge in e- for one step
700 Float_t dZ = zdif/nsteps;
701 Float_t dX = xdif/nsteps;
702
2cc6b29a 703 for (iZi = 1; iZi <= nsteps;iZi++) {
704 Float_t dZn = iZi*dZ;
409f8c84 705 Float_t dXn = iZi*dX;
706 Float_t zPixn = zPix0 + dZn;
707 Float_t xPixn = xPix0 + dXn;
708
709 if(projDif >= 5) {
2cc6b29a 710 Float_t dProjn = sqrt(dZn*dZn+dXn*dXn);
711 drPath = dProjn*tang*1.e-4; // drift path for iZi+1 step in cm
712 if(trdown == 0) {
713 drPath = TMath::Abs(drPath) + ydif0*1.e-4;
714 }// end if trdow ==0
715 if(trdown == 1) {
716 drPath = ydif0*1.e-4 - TMath::Abs(drPath);
717 drPath = TMath::Abs(drPath);
718 } // end if trdown == 1
719 sigmaDif = difCoef*sqrt(drPath);
720 sigmaDif = sigmaDif*kconv; // sigma diffusion in microns
721 } // end if projdif >= 5
409f8c84 722
723 zPixn = (zPixn + spdLength/2.);
724 xPixn = (xPixn + spdWidth/2.);
725 Int_t nZpix, nXpix;
99df08fd 726 GetSeg()->GetPadIxz(xPixn,zPixn,nXpix,nZpix);
727 zPitch = GetSeg()->Dpz(nZpix);
728 GetSeg()->GetPadTxz(xPixn,zPixn);
409f8c84 729 // set the window for the integration
730 Int_t jzmin = 1;
731 Int_t jzmax = 3;
732 if(nZpix == 1) jzmin =2;
733 if(nZpix == fNPixelsZ) jzmax = 2;
734
735 Int_t jxmin = 1;
736 Int_t jxmax = 3;
737 if(nXpix == 1) jxmin =2;
738 if(nXpix == fNPixelsX) jxmax = 2;
739
740 Float_t zpix = nZpix;
741 Float_t dZright = zPitch*(zpix - zPixn);
742 Float_t dZleft = zPitch - dZright;
743
744 Float_t xpix = nXpix;
745 Float_t dXright = xPitch*(xpix - xPixn);
746 Float_t dXleft = xPitch - dXright;
747
748 Float_t dZprev = 0.;
749 Float_t dZnext = 0.;
750 Float_t dXprev = 0.;
751 Float_t dXnext = 0.;
752
753 for(jz=jzmin; jz <=jzmax; jz++) {
754 if(jz == 1) {
2cc6b29a 755 dZprev = -zPitch - dZleft;
756 dZnext = -dZleft;
757 } else if(jz == 2) {
758 dZprev = -dZleft;
759 dZnext = dZright;
760 } else if(jz == 3) {
761 dZprev = dZright;
762 dZnext = dZright + zPitch;
763 } // end if jz
409f8c84 764 // kz changes from 1 to the fNofPixels(270)
765 Int_t kz = nZpix + jz -2;
766
767 Float_t zArg1 = dZprev/sigmaDif;
768 Float_t zArg2 = dZnext/sigmaDif;
769 Float_t zProb1 = TMath::Erfc(zArg1);
770 Float_t zProb2 = TMath::Erfc(zArg2);
771 Float_t dZCharge =0.5*(zProb1-zProb2)*dCharge;
772
773
774 // ----------- holes diffusion in X(r*phi) direction --------
775
776 if(dZCharge > 1.) {
2cc6b29a 777 for(jx=jxmin; jx <=jxmax; jx++) {
778 if(jx == 1) {
779 dXprev = -xPitch - dXleft;
780 dXnext = -dXleft;
781 } else if(jx == 2) {
782 dXprev = -dXleft;
783 dXnext = dXright;
784 } else if(jx == 3) {
785 dXprev = dXright;
786 dXnext = dXright + xPitch;
787 } // end if jx
788 Int_t kx = nXpix + jx -2;
789 Float_t xArg1 = dXprev/sigmaDif;
790 Float_t xArg2 = dXnext/sigmaDif;
791 Float_t xProb1 = TMath::Erfc(xArg1);
792 Float_t xProb2 = TMath::Erfc(xArg2);
793 Float_t dXCharge =0.5*(xProb1-xProb2)*dZCharge;
794
795 if(dXCharge > 1.) {
2cc6b29a 796 if (first) {
f74211b0 797 indexRange[0]=indexRange[1]=kz-1;
2cc6b29a 798 indexRange[2]=indexRange[3]=kx-1;
799 first=kFALSE;
800 } // end if first
801 indexRange[0]=TMath::Min(indexRange[0],kz-1);
802 indexRange[1]=TMath::Max(indexRange[1],kz-1);
803 indexRange[2]=TMath::Min(indexRange[2],kx-1);
804 indexRange[3]=TMath::Max(indexRange[3],kx-1);
f74211b0 805/*
2cc6b29a 806 // build the list of digits for this module
f74211b0 807 Double_t signal = fMapA2->GetSignal(kz-1,kx-1);
2cc6b29a 808 signal+=dXCharge;
f74211b0 809 fMapA2->SetHit(kz-1,kx-1,(double)signal);
810*/
2cc6b29a 811 // The calling sequence for UpdateMapSignal was
812 // moved into the (dx > 1 e-) loop because it
813 // needs to call signal which is defined inside
814 // this loop
2cc6b29a 815 fModule = module;//Defined because functions
816 // called by UpdateMapSignal
817 // expect module to be an
818 // integer
7d50ea21 819 UpdateMapSignal(kz-1,kx-1,
ee86d557 820// mod->GetHitTrackIndex(hit),
821 ((AliITShit*)(mod->GetHit(hit)))->GetTrack(),
f74211b0 822 hit,fModule,dXCharge,pList);
2cc6b29a 823 } // dXCharge > 1 e-
824 } // jx loop
409f8c84 825 } // dZCharge > 1 e-
826 } // jz loop
827 } // iZi loop
409f8c84 828 if (status == 65) { // the step is inside of Si
2cc6b29a 829 zPix0 = zPix;
830 xPix0 = xPix;
831 } // end if status == 65
832 yPrev = yPix;
409f8c84 833 } // hit loop inside the module
409f8c84 834}
2cc6b29a 835//______________________________________________________________________
836void AliITSsimulationSPDdubna::ChargeToSignal(AliITSpList *pList){
837 // add noise and electronics, perform the zero suppression and add the
838 // digit to the list
f74211b0 839 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
99df08fd 840 Float_t threshold = (float)GetResp()->MinVal();
f74211b0 841 Int_t j;
842// Int_t digits[3], tracks[3], hits[3];
843// Float_t charges[3];
2cc6b29a 844 Float_t electronics;
f74211b0 845// Float_t phys;
2cc6b29a 846 Double_t sig;
ee86d557 847 const Int_t nmaxtrk=AliITSdigitSPD::GetNTracks();
f74211b0 848 static AliITSdigitSPD dig;
849
2cc6b29a 850 for(Int_t iz=0; iz<fNPixelsZ; iz++){
851 for(Int_t ix=0; ix<fNPixelsX; ix++){
852 electronics = fBaseline + fNoise*gRandom->Gaus();
99df08fd 853 sig = pList->GetSignalOnly(iz+1,ix+1);
f74211b0 854 UpdateMapNoise(iz,ix,fModule,sig,electronics,pList);
855#ifdef DEBUG
856// cout << sig << "+" << electronics <<">threshold=" << threshold
857// << endl;
858#endif
859 if (sig+electronics > threshold) {
860 dig.fCoord1 = iz;
861 dig.fCoord2 = ix;
862 dig.fSignal = 1;
99df08fd 863 dig.fSignalSPD = (Int_t) pList->GetSignal(iz+1,ix+1);
f74211b0 864 /*
865 digits[0] = iz;
866 digits[1] = ix;
867 digits[2] = 1; */
868 for(j=0;j<nmaxtrk;j++){
869// charges[j] = 0.0;
ee86d557 870 if (j<pList->GetNEnteries()) {
99df08fd 871 dig.fTracks[j] = pList->GetTrack(iz+1,ix+1,j);
872 dig.fHits[j] = pList->GetHit(iz+1,ix+1,j);
f74211b0 873 /*
99df08fd 874 tracks[j] = pList->GetTrack(iz+1,ix+1,j);
875 hits[j] = pList->GetHit(iz+1,ix+1,j);
f74211b0 876 */
877 }else { // Default values
ee86d557 878 dig.fTracks[j] = -3;
879 dig.fHits[j] = -1;
f74211b0 880/* tracks[j] = -2; //noise
881 hits[j] = -1; */
2cc6b29a 882 } // end if pList
f74211b0 883 } // end for j
99df08fd 884// charges[0] = (Float_t) pList->GetSumSignal(iz+1,ix+1);
f74211b0 885/*
2cc6b29a 886 if(tracks[0] == tracks[1] && tracks[0] == tracks[2]) {
887 tracks[1] = -3;
888 hits[1] = -1;
889 tracks[2] = -3;
890 hits[2] = -1;
891 } else if(tracks[0] == tracks[1] && tracks[0] != tracks[2]) {
892 tracks[1] = -3;
893 hits[1] = -1;
894 } else if(tracks[0] == tracks[2] && tracks[0] != tracks[1]) {
895 tracks[2] = -3;
896 hits[2] = -1;
897 } else if(tracks[1] == tracks[2] && tracks[0] != tracks[1]) {
898 tracks[2] = -3;
899 hits[2] = -1;
900 } // end if
f74211b0 901*/
902// phys = 0.0;
903#ifdef DEBUG
904 cout << iz << "," << ix << "," <<
99df08fd 905 *(pList->GetpListItem(iz+1,ix+1)) << endl;
f74211b0 906#endif
907// aliITS->AddSimDigit(0, phys, digits, tracks, hits, charges);
908 aliITS->AddSimDigit(0,&dig);
2cc6b29a 909 } //
910 } //
911 } //
409f8c84 912}
2cc6b29a 913//______________________________________________________________________
914void AliITSsimulationSPDdubna::CreateHistograms(){
915 // create 1D histograms for tests
916
917 printf("SPD - create histograms\n");
918
919 fHis=new TObjArray(fNPixelsZ);
920 TString spdName("spd_");
921 for (Int_t i=0;i<fNPixelsZ;i++) {
922 Char_t pixelz[4];
923 sprintf(pixelz,"%d",i+1);
924 spdName.Append(pixelz);
925 //PH (*fHis)[i] = new TH1F(spdName.Data(),"SPD maps",
926 //PH fNPixelsX,0.,(Float_t) fNPixelsX);
927 fHis->AddAt(new TH1F(spdName.Data(),"SPD maps",
928 fNPixelsX,0.,(Float_t) fNPixelsX), i);
929 } // end for i
409f8c84 930}
2cc6b29a 931//______________________________________________________________________
932void AliITSsimulationSPDdubna::ResetHistograms(){
409f8c84 933 //
934 // Reset histograms for this detector
935 //
936
937 for ( int i=0;i<fNPixelsZ;i++ ) {
2cc6b29a 938 //PH if ((*fHis)[i]) ((TH1F*)(*fHis)[i])->Reset();
2682e810 939 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
2cc6b29a 940 } // end for i
409f8c84 941}