]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSsimulationSPD.cxx
Using AliLog in Config.C
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSPD.cxx
CommitLineData
c7a4dac0 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
88cb7938 16/* $Id$ */
f8d9a5b8 17
4ae5bbc4 18#include <Riostream.h>
b0f5e3fc 19#include <TRandom.h>
20#include <TH1.h>
e8189707 21#include <TMath.h>
9f033001 22#include <TString.h>
23#include <TParticle.h>
e8189707 24
b0f5e3fc 25#include "AliRun.h"
e8189707 26#include "AliITS.h"
9f033001 27#include "AliITShit.h"
e869281d 28#include "AliITSdigitSPD.h"
9f033001 29#include "AliITSmodule.h"
21b825a4 30#include "AliITSMapA2.h"
c7a4dac0 31#include "AliITSpList.h"
b0f5e3fc 32#include "AliITSsimulationSPD.h"
9f033001 33#include "AliITSsegmentation.h"
34#include "AliITSresponse.h"
c7a4dac0 35#include "AliITSsegmentationSPD.h"
36#include "AliITSresponseSPD.h"
f77f13c8 37#include "AliLog.h"
9f033001 38
bb6b39bf 39//#define DEBUG
e8189707 40
b0f5e3fc 41ClassImp(AliITSsimulationSPD)
42////////////////////////////////////////////////////////////////////////
43// Version: 0
21b825a4 44// Written by Rocco Caliandro
45// from a model developed with T. Virgili and R.A. Fini
46// June 15 2000
b0f5e3fc 47//
48// AliITSsimulationSPD is the simulation of SPDs
21b825a4 49//
c7a4dac0 50//______________________________________________________________________
aacedc3e 51AliITSsimulationSPD::AliITSsimulationSPD() : AliITSsimulation(),
52fMapA2(0),
53fHis(0){
c7a4dac0 54 // Default constructor
aacedc3e 55 // Inputs:
56 // none.
57 // Outputs:
58 // none.
59 // Return:
60 // A default constructed AliITSsimulationSPD class.
b0f5e3fc 61}
c7a4dac0 62//______________________________________________________________________
63AliITSsimulationSPD::AliITSsimulationSPD(AliITSsegmentation *seg,
aacedc3e 64 AliITSresponse *res):
65AliITSsimulation(seg,res),
66fMapA2(0),
67fHis(0){
c7a4dac0 68 // Standard constructor
aacedc3e 69 // Inputs:
70 // AliITSsegmentation *seg Segmentation class to be used
71 // AliITSresonse *res Response class to be used
72 // Outputs:
73 // none.
74 // Return:
75 // A standard constructed AliITSsimulationSPD class.
76
77 Init();
78}
79//______________________________________________________________________
80void AliITSsimulationSPD::Init() {
81 // Initilizes the variables of AliITSsimulation SPD.
82 // Inputs:
83 // none.
84 // Outputs:
85 // none.
86 // Return:
87 // none.
c7a4dac0 88
aacedc3e 89 fHis = 0;
90 if(fMapA2) delete fMapA2;
91 fMapA2 = new AliITSMapA2(fSegmentation);
92 if(fpList) delete fpList;
93 fpList = new AliITSpList(GetNPixelsZ()+1,GetNPixelsX()+1);
b0f5e3fc 94}
c7a4dac0 95//______________________________________________________________________
96void AliITSsimulationSPD::Init(AliITSsegmentationSPD *seg,
aacedc3e 97 AliITSresponseSPD *resp) {
c7a4dac0 98 // Initilizes the variables of AliITSsimulation SPD.
aacedc3e 99 // Inputs:
100 // AliITSsegmentationSPD replacement segmentation class to be used
101 // aliITSresponseSPD replacement response class to be used
102 // Outputs:
103 // none.
104 // Return:
105 // none.
c7a4dac0 106
aacedc3e 107 if(fHis){
108 fHis->Delete();
109 delete fHis;
110 } // end if fHis
c7a4dac0 111 fHis = 0;
aacedc3e 112 if(fResponse) delete fResponse;
c7a4dac0 113 fResponse = resp;
aacedc3e 114 if(fSegmentation) delete fSegmentation;
c7a4dac0 115 fSegmentation = seg;
aacedc3e 116 if(fMapA2) delete fMapA2;
3a97c582 117 fMapA2 = new AliITSMapA2(fSegmentation);
aacedc3e 118 if(fpList) delete fpList;
3a97c582 119 fpList = new AliITSpList(GetNPixelsZ()+1,GetNPixelsX()+1);
c7a4dac0 120}
121//______________________________________________________________________
b0f5e3fc 122AliITSsimulationSPD::~AliITSsimulationSPD() {
c7a4dac0 123 // destructor
aacedc3e 124 // Inputs:
125 // none.
126 // Outputs:
127 // none.
128 // Return:
129 // none.
b0f5e3fc 130
aacedc3e 131 if(fMapA2) delete fMapA2;
b0f5e3fc 132
c7a4dac0 133 if (fHis) {
aacedc3e 134 fHis->Delete();
135 delete fHis;
c7a4dac0 136 } // end if
b0f5e3fc 137}
c7a4dac0 138//______________________________________________________________________
ac74f489 139AliITSsimulationSPD::AliITSsimulationSPD(const AliITSsimulationSPD &source) :
140 AliITSsimulation(source){
c7a4dac0 141 // Copy Constructor
aacedc3e 142 // Inputs:
143 // none.
144 // Outputs:
145 // none.
146 // Return:
147 // A new AliITSsimulationSPD class with the same parameters as source.
c7a4dac0 148
149 if(&source == this) return;
150
151 this->fMapA2 = source.fMapA2;
152 this->fHis = source.fHis;
c7a4dac0 153 return;
b0f5e3fc 154}
c7a4dac0 155//______________________________________________________________________
156AliITSsimulationSPD& AliITSsimulationSPD::operator=(const AliITSsimulationSPD
157 &source) {
158 // Assignment operator
aacedc3e 159 // Inputs:
160 // none.
161 // Outputs:
162 // none.
163 // Return:
164 // A new AliITSsimulationSPD class with the same parameters as source.
c7a4dac0 165
166 if(&source == this) return *this;
167
168 this->fMapA2 = source.fMapA2;
169 this->fHis = source.fHis;
c7a4dac0 170 return *this;
3a97c582 171}
d2f55a22 172//______________________________________________________________________
173AliITSsimulationSPD& AliITSsimulationSPD::operator=(const AliITSsimulation
174 &source) {
175 // Assignment operator
176 // Inputs:
177 // none.
178 // Outputs:
179 // none.
180 // Return:
181 // A new AliITSsimulationSPD class with the same parameters as source.
182
183 if(&source == this) return *this;
184 Error("AliITSsimulationSPD","Not allowed to make a = with "
185 "AliITSsimulationSPD Using default creater instead");
186
187 return *this;
188}
189
3a97c582 190//______________________________________________________________________
191void AliITSsimulationSPD::InitSimulationModule(Int_t module,Int_t event){
192 // Creates maps to build the list of tracks for each sumable digit
193 // Inputs:
194 // Int_t module // Module number to be simulated
195 // Int_t event // Event number to be simulated
196 // Outputs:
197 // none.
198 // Return
199 // none.
200
201 fModule = module;
202 fEvent = event;
203 fMapA2->ClearMap();
204 fpList->ClearMap();
205}
206//______________________________________________________________________
207void AliITSsimulationSPD::FinishSDigitiseModule(){
208 // Does the Sdigits to Digits work
209 // Inputs:
210 // none.
211 // Outputs:
212 // none.
213 // Return:
214 // none.
215
216 SDigitsToDigits(fModule,fpList);
c7a4dac0 217}
218//______________________________________________________________________
219void AliITSsimulationSPD::SDigitiseModule(AliITSmodule *mod, Int_t dummy0,
220 Int_t dummy1) {
221 // Sum digitize module
aacedc3e 222 // Inputs:
223 // AliITSmodule *mod The module to be SDgitized
224 // Int_t dummy0 Not used kept for general compatibility
225 // Int_t dummy1 Not used kept for general compatibility
226 // Outputs:
227 // none.
228 // Return:
229 // none.
c7a4dac0 230 if (!(mod->GetNhits())) return; // if module has no hits then no Sdigits.
231 Int_t number = 10000;
232 Int_t *frowpixel = new Int_t[number];
233 Int_t *fcolpixel = new Int_t[number];
234 Double_t *fenepixel = new Double_t[number];
235
ac74f489 236 dummy0 = dummy1; // remove unsued variable warning.
3a97c582 237 fModule = mod->GetIndex();
238
c7a4dac0 239 // Array of pointers to store the track index of the digits
240 // leave +1, otherwise pList crashes when col=256, row=192
c7a4dac0 241
3a97c582 242 HitsToAnalogDigits(mod,frowpixel,fcolpixel,fenepixel,fpList);
c7a4dac0 243
3a97c582 244 WriteSDigits(fpList);
c7a4dac0 245
246 // clean memory
247 delete[] frowpixel;
248 delete[] fcolpixel;
249 delete[] fenepixel;
250 fMapA2->ClearMap();
3a97c582 251 fpList->ClearMap();
c7a4dac0 252}
253//______________________________________________________________________
aacedc3e 254void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod, Int_t,Int_t) {
c7a4dac0 255 // digitize module. Also need to digitize modules with only noise.
aacedc3e 256 // Inputs:
257 // AliITSmodule *mod The module to be SDgitized
258 // Outputs:
259 // none.
260 // Return:
261 // none.
b0f5e3fc 262
c7a4dac0 263 Int_t number = 10000;
264 Int_t *frowpixel = new Int_t[number];
265 Int_t *fcolpixel = new Int_t[number];
266 Double_t *fenepixel = new Double_t[number];
b0f5e3fc 267
c7a4dac0 268 // Array of pointers to store the track index of the digits
3a97c582 269 // leave +1, otherwise pList crashes when col=256, row=192
270 fModule = mod->GetIndex();
c7a4dac0 271 // noise setting
3a97c582 272 SetFluctuations(fpList,fModule);
b0f5e3fc 273
3a97c582 274 HitsToAnalogDigits(mod,frowpixel,fcolpixel,fenepixel,fpList);
21b825a4 275
c7a4dac0 276 // apply mask to SPD module
277 SetMask();
21b825a4 278
3a97c582 279 CreateDigit(fModule,fpList);
b0f5e3fc 280
c7a4dac0 281 // clean memory
282 delete[] frowpixel;
283 delete[] fcolpixel;
284 delete[] fenepixel;
285 fMapA2->ClearMap();
3a97c582 286 fpList->ClearMap();
21b825a4 287}
c7a4dac0 288//______________________________________________________________________
289void AliITSsimulationSPD::SDigitsToDigits(Int_t module,AliITSpList *pList) {
290 // sum digits to Digits.
aacedc3e 291 // Inputs:
292 // AliITSmodule *mod The module to be SDgitized
293 // AliITSpList *pList the array of SDigits
294 // Outputs:
295 // AliITSpList *pList the array of SDigits
296 // Return:
297 // none.
bb6b39bf 298
f77f13c8 299 AliDebug(1,Form("Entering AliITSsimulatinSPD::SDigitsToDigits for module=%d",
300 module));
3a97c582 301 fModule = module;
b0f5e3fc 302
c7a4dac0 303 // noise setting
304 SetFluctuations(pList,module);
b0f5e3fc 305
3a97c582 306 fMapA2->ClearMap(); // since noise is in pList aready. Zero Map so that
307 // noise is not doubled when calling FillMapFrompList.
308
309 FillMapFrompList(pList);
310
c7a4dac0 311 // apply mask to SPD module
312 SetMask();
21b825a4 313
c7a4dac0 314 CreateDigit(module,pList);
3a97c582 315
316 fMapA2->ClearMap();
317 pList->ClearMap();
c7a4dac0 318}
319//______________________________________________________________________
320void AliITSsimulationSPD::UpdateMapSignal(Int_t row,Int_t col,Int_t trk,
321 Int_t hit,Int_t mod,Double_t ene,
322 AliITSpList *pList) {
323 // updates the Map of signal, adding the energy (ene) released by
324 // the current track
aacedc3e 325 // Inputs:
326 // Int_t row pixel row number
327 // Int_t col pixel column number
328 // Int_t trk track number which contributed
329 // Int_t hit hit number which contributed
330 // Int_t mod module number
331 // Double_t ene the energy associated with this contribution
332 // AliITSpList *pList the array of SDigits
333 // Outputs:
334 // AliITSpList *pList the array of SDigits
335 // Return:
336 // none.
c7a4dac0 337
338 fMapA2->AddSignal(row,col,ene);
339 pList->AddSignal(row,col,trk,hit,mod,ene);
340}
341//______________________________________________________________________
342void AliITSsimulationSPD::UpdateMapNoise(Int_t row,Int_t col,Int_t mod,
343 Double_t ene,AliITSpList *pList) {
344 // updates the Map of noise, adding the energy (ene) give my noise
aacedc3e 345 // Inputs:
346 // Int_t row pixel row number
347 // Int_t col pixel column number
348 // Int_t mod module number
349 // Double_t ene the energy associated with this contribution
350 // AliITSpList *pList the array of SDigits
351 // Outputs:
352 // AliITSpList *pList the array of SDigits
353 // Return:
354 // none.
21b825a4 355
c7a4dac0 356 fMapA2->AddSignal(row,col,ene);
357 pList->AddNoise(row,col,mod,ene);
358}
359//______________________________________________________________________
360void AliITSsimulationSPD::HitsToAnalogDigits(AliITSmodule *mod,
361 Int_t *frowpixel,Int_t *fcolpixel,
362 Double_t *fenepixel,
363 AliITSpList *pList) {
364 // Loops over all hits to produce Analog/floting point digits. This
365 // is also the first task in producing standard digits.
aacedc3e 366 // Inputs:
367 // AliITSmodule *mod module class
368 // Int_t *frowpixel array of pixel rows
369 // Int_t *fcolpixel array of pixel columns
370 // Double_t *fenepiexel array of pixel energies
371 // AliITSpList *pList the array of SDigits
372 // Outputs:
373 // AliITSpList *pList the array of SDigits
374 // Return:
375 // none.
21b825a4 376
c7a4dac0 377 // loop over hits in the module
378 Int_t hitpos,nhits = mod->GetNhits();
379 for (hitpos=0;hitpos<nhits;hitpos++) {
aacedc3e 380 HitToDigit(mod,hitpos,frowpixel,fcolpixel,fenepixel,pList);
c7a4dac0 381 }// end loop over digits
382}
383//______________________________________________________________________
384void AliITSsimulationSPD::HitToDigit(AliITSmodule *mod,Int_t hitpos,
385 Int_t *frowpixel,Int_t *fcolpixel,
386 Double_t *fenepixel,AliITSpList *pList) {
387 // Steering function to determine the digits associated to a given
388 // hit (hitpos)
389 // The digits are created by charge sharing (ChargeSharing) and by
390 // capacitive coupling (SetCoupling). At all the created digits is
391 // associated the track number of the hit (ntrack)
aacedc3e 392 // Inputs:
393 // AliITSmodule *mod module class
394 // Int_t hitpos hit index value
395 // Int_t *frowpixel array of pixel rows
396 // Int_t *fcolpixel array of pixel columns
397 // Double_t *fenepiexel array of pixel energies
398 // AliITSpList *pList the array of SDigits
399 // Outputs:
400 // AliITSpList *pList the array of SDigits
401 // Return:
402 // none.
c7a4dac0 403 Double_t x1l=0.0,y1l=0.0,z1l=0.0,x2l=0.0,y2l=0.0,z2l=0.0;
404 Int_t r1,r2,c1,c2,row,col,npixel = 0;
405 Int_t ntrack;
406 Double_t ene=0.0,etot=0.0;
407 const Float_t kconv = 10000.; // cm -> microns
408 const Float_t kconv1= 0.277e9; // GeV -> electrons equivalent
409
410 if(!(mod->LineSegmentL(hitpos,x1l,x2l,y1l,y2l,z1l,z2l,etot,ntrack)))return;
411
412 x2l += x1l; y2l += y1l; z2l += z1l; // Convert to ending coordinate.
413 // positions shifted and converted in microns
414 x1l = x1l*kconv + fSegmentation->Dx()/2.;
415 z1l = z1l*kconv + fSegmentation->Dz()/2.;
416 // positions shifted and converted in microns
417 x2l = x2l*kconv + fSegmentation->Dx()/2.;
418 z2l = z2l*kconv + fSegmentation->Dz()/2.;
419 etot *= kconv1; // convert from GeV to electrons equivalent.
420 Int_t module = mod->GetIndex();
421
422 // to account for the effective sensitive area
423 // introduced in geometry
424 if (z1l<0 || z1l>fSegmentation->Dz()) return;
425 if (z2l<0 || z2l>fSegmentation->Dz()) return;
426 if (x1l<0 || x1l>fSegmentation->Dx()) return;
427 if (x2l<0 || x2l>fSegmentation->Dx()) return;
428
429 //Get the col and row number starting from 1
430 // the x direction is not inverted for the second layer!!!
431 fSegmentation->GetPadIxz(x1l, z1l, c1, r1);
432 fSegmentation->GetPadIxz(x2l, z2l, c2, r2);
433
434 // to account for unexpected equal entrance and
435 // exit coordinates
0fee5d51 436 if (x1l==x2l) x2l=x2l+x2l*0.1;
437 if (z1l==z2l) z2l=z2l+z2l*0.1;
c7a4dac0 438
439 if ((r1==r2) && (c1==c2)){
aacedc3e 440 // no charge sharing
441 npixel = 1;
442 frowpixel[npixel-1] = r1;
443 fcolpixel[npixel-1] = c1;
444 fenepixel[npixel-1] = etot;
c7a4dac0 445 } else {
aacedc3e 446 // charge sharing
447 ChargeSharing(x1l,z1l,x2l,z2l,c1,r1,c2,r2,etot,
448 npixel,frowpixel,fcolpixel,fenepixel);
c7a4dac0 449 } // end if r1==r2 && c1==c2.
450
451 for (Int_t npix=0;npix<npixel;npix++){
aacedc3e 452 row = frowpixel[npix];
453 col = fcolpixel[npix];
454 ene = fenepixel[npix];
455 UpdateMapSignal(row,col,ntrack,hitpos,module,ene,pList);
456 // Starting capacitive coupling effect
457 SetCoupling(row,col,ntrack,hitpos,module,pList);
c7a4dac0 458 } // end for npix
459}
460//______________________________________________________________________
461void AliITSsimulationSPD::ChargeSharing(Float_t x1l,Float_t z1l,Float_t x2l,
462 Float_t z2l,Int_t c1,Int_t r1,Int_t c2,
463 Int_t r2,Float_t etot,
464 Int_t &npixel,Int_t *frowpixel,
465 Int_t *fcolpixel,Double_t *fenepixel){
466 // Take into account the geometrical charge sharing when the track
467 // crosses more than one pixel.
aacedc3e 468 // Inputs:
469 // Float_t x1l
470 // Float_t z1l
471 // Float_t x2l
472 // Float_t z2l
473 // Int_t c1
474 // Int_t r1
475 // Int_t c2
476 // Int_t r2
477 // Float_t etot
478 // Int_t &npixel
479 // Int_t *frowpixel array of pixel rows
480 // Int_t *fcolpixel array of pixel columns
481 // Double_t *fenepiexel array of pixel energies
482 // Outputs:
483 // Int_t &npixel
484 // Return:
485 // none.
c7a4dac0 486 //
487 //Begin_Html
21b825a4 488 /*
c7a4dac0 489 <img src="picts/ITS/barimodel_2.gif">
490 </pre>
491 <br clear=left>
492 <font size=+2 color=red>
493 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
494 </font>
495 <pre>
21b825a4 496 */
c7a4dac0 497 //End_Html
ee86d557 498 //Float_t dm;
499 Float_t xa,za,xb,zb,dx,dz,dtot,refr,refm,refc;
c7a4dac0 500 Float_t refn=0.;
501 Float_t arefm, arefr, arefn, arefc, azb, az2l, axb, ax2l;
502 Int_t dirx,dirz,rb,cb;
503 Int_t flag,flagrow,flagcol;
504 Double_t epar;
505
506 npixel = 0;
507 xa = x1l;
508 za = z1l;
cf6105a4 509// dx = x1l-x2l;
510// dz = z1l-z2l;
511 dx = x2l-x1l;
512 dz = z2l-z1l;
c7a4dac0 513 dtot = TMath::Sqrt((dx*dx)+(dz*dz));
d709f420 514 if (dtot==0.0) dtot = 0.01;
515 dirx = (Int_t) TMath::Sign((Float_t)1,dx);
516 dirz = (Int_t) TMath::Sign((Float_t)1,dz);
c7a4dac0 517
518 // calculate the x coordinate of the pixel in the next column
519 // and the z coordinate of the pixel in the next row
520 Float_t xpos, zpos;
521
522 fSegmentation->GetPadCxz(c1, r1-1, xpos, zpos);
523
524 Float_t xsize = fSegmentation->Dpx(0);
525 Float_t zsize = fSegmentation->Dpz(r1-1);
21b825a4 526
c7a4dac0 527 if (dirx == 1) refr = xpos+xsize/2.;
528 else refr = xpos-xsize/2.;
529
530 if (dirz == 1) refn = zpos+zsize/2.;
531 else refn = zpos-zsize/2.;
532
533 flag = 0;
534 flagrow = 0;
535 flagcol = 0;
536 do{
aacedc3e 537 // calculate the x coordinate of the intersection with the pixel
538 // in the next cell in row direction
539 if(dz!=0)
540 refm = dx*((refn - z1l)/dz) + x1l;
541 else
542 refm = refr+dirx*xsize;
543
544 // calculate the z coordinate of the intersection with the pixel
545 // in the next cell in column direction
546 if (dx!=0)
547 refc = dz*((refr - x1l)/dx) + z1l;
548 else
549 refc = refn+dirz*zsize;
550
551 arefm = refm * dirx;
552 arefr = refr * dirx;
553 arefn = refn * dirz;
554 arefc = refc * dirz;
555
556 if ((arefm < arefr) && (arefn < arefc)){
557 // the track goes in the pixel in the next cell in row direction
558 xb = refm;
559 zb = refn;
560 cb = c1;
561 rb = r1 + dirz;
562 azb = zb * dirz;
563 az2l = z2l * dirz;
564 if (rb == r2) flagrow=1;
565 if (azb > az2l) {
566 zb = z2l;
567 xb = x2l;
568 } // end if
569 // shift to the pixel in the next cell in row direction
570 Float_t zsizeNext = fSegmentation->Dpz(rb-1);
571 //to account for cell at the borders of the detector
572 if(zsizeNext==0) zsizeNext = zsize;
573 refn += zsizeNext*dirz;
574 }else {
575 // the track goes in the pixel in the next cell in column direction
576 xb = refr;
577 zb = refc;
578 cb = c1 + dirx;
579 rb = r1;
580 axb = xb * dirx;
581 ax2l = x2l * dirx;
582 if (cb == c2) flagcol=1;
583 if (axb > ax2l) {
584 zb = z2l;
585 xb = x2l;
586 } // end ifaxb > ax2l
587
588 // shift to the pixel in the next cell in column direction
589 Float_t xsizeNext = fSegmentation->Dpx(cb-1);
590 //to account for cell at the borders of the detector
591 if(xsizeNext==0) xsizeNext = xsize;
592 refr += xsizeNext*dirx;
593 } // end if (arefm < arefr) && (arefn < arefc)
594
595 //calculate the energy lost in the crossed pixel
596 epar = TMath::Sqrt((xb-xa)*(xb-xa)+(zb-za)*(zb-za));
597 epar = etot*(epar/dtot);
598
599 //store row, column and energy lost in the crossed pixel
600 frowpixel[npixel] = r1;
601 fcolpixel[npixel] = c1;
602 fenepixel[npixel] = epar;
603 npixel++;
604
605 // the exit point of the track is reached
606 if (epar == 0) flag = 1;
607 if ((r1 == r2) && (c1 == c2)) flag = 1;
608 if (flag!=1) {
609 r1 = rb;
610 c1 = cb;
611 xa = xb;
612 za = zb;
613 } // end if flag!=1
c7a4dac0 614 } while (flag==0);
21b825a4 615}
c7a4dac0 616//______________________________________________________________________
21b825a4 617void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
c7a4dac0 618 Int_t idhit,Int_t module,
619 AliITSpList *pList) {
620 // Take into account the coupling between adiacent pixels.
f8d9a5b8 621 // The parameters probcol and probrow are the probability of the
622 // signal in one pixel shared in the two adjacent pixels along
623 // the column and row direction, respectively.
aacedc3e 624 // Inputs:
625 // Int_t row pixel row number
626 // Int_t col pixel column number
627 // Int_t ntrack track number of track contributing to this signal
628 // Int_t idhit hit number of hit contributing to this signal
629 // Int_t module module number
630 // AliITSpList *pList the array of SDigits
631 // Outputs:
632 // AliITSpList *pList the array of SDigits
633 // Return:
634 // none.
f8d9a5b8 635 //
636 //Begin_Html
637 /*
638 <img src="picts/ITS/barimodel_3.gif">
639 </pre>
640 <br clear=left>
641 <font size=+2 color=red>
642 <a href="mailto:tiziano.virgili@cern.ch"></a>.
643 </font>
644 <pre>
645 */
646 //End_Html
647 Int_t j1,j2,flag=0;
648 Double_t pulse1,pulse2;
aacedc3e 649 Double_t couplR=0.0,couplC=0.0;
f8d9a5b8 650 Double_t xr=0.;
651
652 GetCouplings(couplR,couplC);
653 j1 = row;
654 j2 = col;
655 pulse1 = fMapA2->GetSignal(row,col);
656 pulse2 = pulse1;
657 for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
aacedc3e 658 do{
659 j1 += isign;
660 // pulse1 *= couplR;
661 xr = gRandom->Rndm();
662 //if ((j1<0) || (j1>GetNPixelsZ()-1) || (pulse1<GetThreshold())){
663 if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplR)){
664 j1 = row;
665 flag = 1;
666 }else{
667 UpdateMapSignal(j1,col,ntrack,idhit,module,pulse1,pList);
668 // flag = 0;
669 flag = 1; // only first next!!
670 } // end if
671 } while(flag == 0);
672 // loop in column direction
673 do{
674 j2 += isign;
675 // pulse2 *= couplC;
676 xr = gRandom->Rndm();
677 //if ((j2<0) || (j2>(GetNPixelsX()-1)) || (pulse2<GetThreshold())){
678 if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplC)){
679 j2 = col;
680 flag = 1;
681 }else{
682 UpdateMapSignal(row,j2,ntrack,idhit,module,pulse2,pList);
683 // flag = 0;
684 flag = 1; // only first next!!
685 } // end if
686 } while(flag == 0);
f8d9a5b8 687 } // for isign
688}
689//______________________________________________________________________
690void AliITSsimulationSPD::SetCouplingOld(Int_t row, Int_t col, Int_t ntrack,
691 Int_t idhit,Int_t module,
692 AliITSpList *pList) {
693 // Take into account the coupling between adiacent pixels.
c7a4dac0 694 // The parameters probcol and probrow are the fractions of the
695 // signal in one pixel shared in the two adjacent pixels along
696 // the column and row direction, respectively.
aacedc3e 697 // Inputs:
698 // Int_t row pixel row number
699 // Int_t col pixel column number
700 // Int_t ntrack track number of track contributing to this pixel
701 // Int_t idhit hit index number of hit contributing to this pixel
702 // Int_t module module number
703 // AliITSpList *pList the array of SDigits
704 // Outputs:
705 // AliITSpList *pList the array of SDigits
706 // Return:
707 // none.
c7a4dac0 708 //
709 //Begin_Html
710 /*
711 <img src="picts/ITS/barimodel_3.gif">
712 </pre>
713 <br clear=left>
714 <font size=+2 color=red>
715 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
716 </font>
717 <pre>
718 */
719 //End_Html
720 Int_t j1,j2,flag=0;
721 Double_t pulse1,pulse2;
aacedc3e 722 Double_t couplR=0.0,couplC=0.0;
c7a4dac0 723
724 GetCouplings(couplR,couplC);
725 j1 = row;
726 j2 = col;
727 pulse1 = fMapA2->GetSignal(row,col);
728 pulse2 = pulse1;
729 for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
aacedc3e 730 do{
731 j1 += isign;
732 pulse1 *= couplR;
733 if ((j1<0) || (j1>GetNPixelsZ()-1) || (pulse1<GetThreshold())){
734 pulse1 = fMapA2->GetSignal(row,col);
735 j1 = row;
736 flag = 1;
737 }else{
738 UpdateMapSignal(j1,col,ntrack,idhit,module,pulse1,pList);
739 flag = 0;
740 } // end if
741 } while(flag == 0);
742 // loop in column direction
743 do{
744 j2 += isign;
745 pulse2 *= couplC;
746 if ((j2<0) || (j2>(GetNPixelsX()-1)) || (pulse2<GetThreshold())){
747 pulse2 = fMapA2->GetSignal(row,col);
748 j2 = col;
749 flag = 1;
750 }else{
751 UpdateMapSignal(row,j2,ntrack,idhit,module,pulse2,pList);
752 flag = 0;
753 } // end if
754 } while(flag == 0);
c7a4dac0 755 } // for isign
21b825a4 756}
c7a4dac0 757//______________________________________________________________________
758void AliITSsimulationSPD::CreateDigit(Int_t module,AliITSpList *pList) {
759 // The pixels are fired if the energy deposited inside them is above
760 // the threshold parameter ethr. Fired pixed are interpreted as digits
761 // and stored in the file digitfilename. One also needs to write out
762 // cases when there is only noise (nhits==0).
aacedc3e 763 // Inputs:
764 // Int_t module
765 // AliITSpList *pList the array of SDigits
766 // Outputs:
767 // AliITSpList *pList the array of SDigits
768 // Return:
769 // none.
c7a4dac0 770
771 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
772
ee86d557 773 Int_t size = AliITSdigitSPD::GetNTracks();
5c5273c2 774 Int_t * digits = new Int_t[size];
775 Int_t * tracks = new Int_t[size];
776 Int_t * hits = new Int_t[size];
777 Float_t * charges = new Float_t[size];
c7a4dac0 778 Int_t j1;
779
ac74f489 780 module=0; // remove unused variable warning.
f8d9a5b8 781 for(j1=0;j1<size;j1++){tracks[j1]=-3;hits[j1]=-1;charges[j1]=0.0;}
c7a4dac0 782 for (Int_t r=1;r<=GetNPixelsZ();r++) {
aacedc3e 783 for (Int_t c=1;c<=GetNPixelsX();c++) {
784 // check if the deposited energy in a pixel is above the
785 // threshold
786 Float_t signal = (Float_t) fMapA2->GetSignal(r,c);
787 if ( signal > GetThreshold()) {
788 digits[0] = r-1; // digits starts from 0
789 digits[1] = c-1; // digits starts from 0
790 //digits[2] = 1;
791 digits[2] = (Int_t) signal; // the signal is stored in
c7a4dac0 792 // electrons
aacedc3e 793 for(j1=0;j1<size;j1++){
794 if(j1<pList->GetNEnteries()){
795 tracks[j1] = pList->GetTrack(r,c,j1);
796 hits[j1] = pList->GetHit(r,c,j1);
797 //}else{
798 //tracks[j1] = -3;
799 //hits[j1] = -1;
800 } // end if
801 //charges[j1] = 0;
802 } // end for j1
803 Float_t phys = 0;
804 aliITS->AddSimDigit(0,phys,digits,tracks,hits,charges);
f77f13c8 805 AliDebug(1,Form("mod=%d r,c=%d,%d sig=%f noise=%f Msig=%d Thres=%f",
806 fModule,r,c,fpList->GetSignalOnly(r,c),fpList->GetNoise(r,c),
807 signal,GetThreshold()));
aacedc3e 808 } // end if of threshold condition
809 } // for c
c7a4dac0 810 }// end do on pixels
5c5273c2 811 delete [] digits;
812 delete [] tracks;
813 delete [] hits;
814 delete [] charges;
21b825a4 815}
c7a4dac0 816//______________________________________________________________________
817void AliITSsimulationSPD::SetFluctuations(AliITSpList *pList,Int_t module) {
818 // Set the electronic noise and threshold non-uniformities to all the
819 // pixels in a detector.
820 // The parameter fSigma is the squared sum of the sigma due to noise
821 // and the sigma of the threshold distribution among pixels.
aacedc3e 822 // Inputs:
823 // Int_t module modulel number
824 // AliITSpList *pList the array of SDigits
825 // Outputs:
826 // AliITSpList *pList the array of SDigits
827 // Return:
828 // none.
c7a4dac0 829 //
830 //Begin_Html
831 /*
832 <img src="picts/ITS/barimodel_1.gif">
833 </pre>
834 <br clear=left>
835 <font size=+2 color=red>
836 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
837 </font>
838 <pre>
839 */
840 //End_Html
aacedc3e 841 Double_t thr=0.0,sigm=0.0;
c7a4dac0 842 Double_t signal,sigma;
843 Int_t iz,ix;
844
845 GetThresholds(thr,sigm);
846 sigma = (Double_t) sigm;
847 for(iz=1;iz<=GetNPixelsZ();iz++){
aacedc3e 848 for(ix=1;ix<=GetNPixelsX();ix++){
849 signal = sigma*gRandom->Gaus();
850 fMapA2->SetHit(iz,ix,signal);
851 // insert in the label-signal-hit list the pixels fired
852 // only by noise
853 pList->AddNoise(iz,ix,module,signal);
854 } // end of loop on pixels
21b825a4 855 } // end of loop on pixels
c7a4dac0 856}
857//______________________________________________________________________
858void AliITSsimulationSPD::SetMask() {
859 // Apply a mask to the SPD module. 1% of the pixel channels are
860 // masked. When the database will be ready, the masked pixels
861 // should be read from it.
aacedc3e 862 // Inputs:
863 // none.
864 // Outputs:
865 // none.
866 // Return:
867 // none.
c7a4dac0 868 Double_t signal;
869 Int_t iz,ix,im;
870 Float_t totMask;
871 Float_t perc = ((AliITSresponseSPD*)fResponse)->GetFractionDead();
872 // in this way we get the same set of random numbers for all runs.
873 // This is a cluge for now.
874 static TRandom *rnd = new TRandom();
875
876 totMask= perc*GetNPixelsZ()*GetNPixelsX();
877 for(im=1;im<totMask;im++){
aacedc3e 878 do{
879 ix=(Int_t)(rnd->Rndm()*(GetNPixelsX()-1.) + 1.);
880 } while(ix<=0 || ix>GetNPixelsX());
881 do{
882 iz=(Int_t)(rnd->Rndm()*(GetNPixelsZ()-1.) + 1.);
883 } while(iz<=0 || iz>GetNPixelsZ());
884 signal = -1.;
885 fMapA2->SetHit(iz,ix,signal);
c7a4dac0 886 } // end loop on masked pixels
887}
888//______________________________________________________________________
21b825a4 889void AliITSsimulationSPD::CreateHistograms() {
c7a4dac0 890 // Create Histograms
aacedc3e 891 // Inputs:
892 // none.
893 // Outputs:
894 // none.
895 // Return:
896 // none.
c7a4dac0 897 Int_t i;
21b825a4 898
c7a4dac0 899 fHis=new TObjArray(GetNPixelsZ());
900 for(i=0;i<GetNPixelsZ();i++) {
aacedc3e 901 TString spdname("spd_");
902 Char_t candnum[4];
903 sprintf(candnum,"%d",i+1);
904 spdname.Append(candnum);
905 (*fHis)[i] = new TH1F(spdname.Data(),"SPD maps",
906 GetNPixelsX(),0.,(Float_t) GetNPixelsX());
c7a4dac0 907 } // end for i
b0f5e3fc 908}
c7a4dac0 909//______________________________________________________________________
21b825a4 910void AliITSsimulationSPD::ResetHistograms() {
b0f5e3fc 911 // Reset histograms for this detector
aacedc3e 912 // Inputs:
913 // none.
914 // Outputs:
915 // none.
916 // Return:
917 // none.
21b825a4 918 Int_t i;
b0f5e3fc 919
c7a4dac0 920 for(i=0;i<GetNPixelsZ();i++ ) {
aacedc3e 921 if ((*fHis)[i]) ((TH1F*)(*fHis)[i])->Reset();
c7a4dac0 922 } // end for i
923}
924//______________________________________________________________________
925void AliITSsimulationSPD::WriteSDigits(AliITSpList *pList){
926 // Fills the Summable digits Tree
aacedc3e 927 // Inputs:
928 // AliITSpList *pList the array of SDigits
929 // Outputs:
930 // AliITSpList *pList the array of SDigits
931 // Return:
932 // none.
c7a4dac0 933 Int_t i,ni,j,nj;
934 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
935
936 pList->GetMaxMapIndex(ni,nj);
937 for(i=0;i<ni;i++)for(j=0;j<nj;j++){
aacedc3e 938 if(pList->GetSignalOnly(i,j)>0.0){
939 aliITS->AddSumDigit(*(pList->GetpListItem(i,j)));
f77f13c8 940 if(AliDebugLevel()){
aacedc3e 941 cout << "pListSPD: " << *(pList->GetpListItem(i,j)) << endl;
f77f13c8 942 AliDebug(1,Form("mod=%s r,c=%d %d sig=%f noise=%f",
943 fModule,i,j,fpList->GetSignalOnly(i,j),fpList->GetNoise(i,j)))
aacedc3e 944 } // end if GetDebug
945 } // end if
c7a4dac0 946 } // end for i,j
947 return;
948}
949//______________________________________________________________________
950void AliITSsimulationSPD::FillMapFrompList(AliITSpList *pList){
951 // Fills fMap2A from the pList of Summable digits
aacedc3e 952 // Inputs:
953 // AliITSpList *pList the array of SDigits
954 // Outputs:
955 // AliITSpList *pList the array of SDigits
956 // Return:
957 // none.
3a97c582 958 Int_t ix,iz;
c7a4dac0 959
3a97c582 960 for(iz=0;iz<GetNPixelsZ();iz++)for(ix=0;ix<GetNPixelsX();ix++)
961 fMapA2->AddSignal(iz,ix,pList->GetSignal(iz,ix));
c7a4dac0 962 return;
b0f5e3fc 963}