1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 #include <Riostream.h>
24 #include <TParticle.h>
28 #include "AliITShit.h"
29 #include "AliITSdigitSPD.h"
30 #include "AliITSmodule.h"
31 #include "AliITSMapA2.h"
32 #include "AliITSpList.h"
33 #include "AliITSsimulationSPDdubna.h"
34 #include "AliITSsegmentationSPD.h"
35 #include "AliITSresponseSPD.h"
39 ClassImp(AliITSsimulationSPDdubna)
40 ////////////////////////////////////////////////////////////////////////
42 // Modified by Bjorn S. Nilsen
44 // Written by Boris Batyunya
47 // AliITSsimulationSPDdubna is to do the simulation of SPDs.
48 //______________________________________________________________________
49 AliITSsimulationSPDdubna::AliITSsimulationSPDdubna():
54 // Default constructor.
60 // A default constructed AliITSsimulationSPDdubna class.
62 if(GetDebug(1)) Info("AliITSsimulationSPDdubda()",
63 "Calling degault constructor");
65 //______________________________________________________________________
66 AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(AliITSsegmentation *seg,
67 AliITSresponse *resp,Int_t cup):
68 AliITSsimulation(seg,resp),
72 // standard constructor
74 // AliITSsegmentation *seg A pointer to the segmentation class
75 // to be used for this simulation
76 // AliITSresponse *resp A pointer to the responce class to
77 // be used for this simulation
78 // Int_t cup The type of coupling to be used
79 // =1 uses SetCoupling, =2 uses SetCouplingOld
80 // With diffusion tured off
81 // =3 uses SetCoupling, =4 uses SetCouplingOld
82 // with diffusion on other, no coupling.
86 // A default constructed AliITSsimulationSPDdubna class.
88 if(GetDebug(1)) Info("AliITSsimulationSPDdubda",
89 "Calling degault constructor seg=%p resp=%p cup=%d",
91 if(cup==1||cup==2){ // For the moment, remove defusion if Coupling is
93 resp->SetTemperature(0.0);
94 resp->SetDistanceOverVoltage(0.0);
98 //______________________________________________________________________
99 void AliITSsimulationSPDdubna::Init(){
107 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
111 SetMap(new AliITSpList(GetNPixelsZ(),GetNPixelsX()));
112 GetResp(0,0)->SetDistanceOverVoltage(kmictocm*GetSeg()->Dy(),50.0);
114 //______________________________________________________________________
115 AliITSsimulationSPDdubna::~AliITSsimulationSPDdubna(){
129 //______________________________________________________________________
130 AliITSsimulationSPDdubna::AliITSsimulationSPDdubna(const
131 AliITSsimulationSPDdubna
132 &s) : AliITSsimulation(s){
135 // AliITSsimulationSPDdubna &s The original class for which
136 // this class is a copy of
144 //______________________________________________________________________
145 AliITSsimulationSPDdubna& AliITSsimulationSPDdubna::operator=(const
146 AliITSsimulationSPDdubna &s){
147 // Assignment operator
149 // AliITSsimulationSPDdubna &s The original class for which
150 // this class is a copy of
155 if(&s == this) return *this;
157 fCoupling = s.fCoupling;
158 fSPDname = s.fSPDname;
161 //______________________________________________________________________
162 AliITSsimulationSPDdubna& AliITSsimulationSPDdubna::operator=(const
163 AliITSsimulation &s){
164 // Assignment operator
166 // AliITSsimulationSPDdubna &s The original class for which
167 // this class is a copy of
172 if(&s == this) return *this;
173 Error("AliITSsimulationSPDdubna","Not allowed to make a = with "
174 "AliITSsimulationSPDdubna","Using default creater instead");
178 //______________________________________________________________________
179 void AliITSsimulationSPDdubna::InitSimulationModule(Int_t module, Int_t event){
180 // This function creates maps to build the list of tracks for each
181 // summable digit. Inputs defined by base class.
183 // Int_t module // Module number to be simulated
184 // Int_t event // Event number to be simulated
190 if(GetDebug(1)) Info("InitSimulationModule","(module=%d,event=%d)",
192 SetModuleNumber(module);
193 SetEventNumber(event);
196 //_____________________________________________________________________
197 void AliITSsimulationSPDdubna::SDigitiseModule(AliITSmodule *mod,Int_t,
199 // This function begins the work of creating S-Digits. Inputs defined
202 // AliITSmodule *mod // module
204 // Int_t event // Event number
208 // test // test returns kTRUE if the module contained hits
209 // // test returns kFALSE if it did not contain hits
211 if(GetDebug(1)) Info("SDigitiseModule","(mod=%p, ,event=%d)",mod,event);
212 if(!(mod->GetNhits())){
213 if(GetDebug(1)) Info("SDigitiseModule","In event %d module %d there "
214 "are %d hits returning.",event,
215 mod->GetIndex(),mod->GetNhits());
216 return;// if module has no hits don't create Sdigits
218 SetModuleNumber(mod->GetIndex());
219 SetEventNumber(event);
224 //______________________________________________________________________
225 void AliITSsimulationSPDdubna::WriteSDigits(){
226 // This function adds each S-Digit to pList
233 Int_t ix, nix, iz, niz;
234 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
236 if(GetDebug(1))Info("WriteSDigits","Writing SDigits for module %d",
238 GetMap()->GetMaxMapIndex(niz, nix);
239 for(iz=0; iz<niz; iz++)for(ix=0; ix<nix; ix++){
240 if(GetMap()->GetSignalOnly(iz,ix)>0.0){
241 aliITS->AddSumDigit(*(GetMap()->GetpListItem(iz,ix)));
243 cout <<"AliITSsimulationSPDdubna:WriteSDigits " << iz << ","
244 << ix << "," << *(GetMap()->GetpListItem(iz,ix)) << endl;
246 } // end if GetMap()->GetSignalOnly(iz,ix)>0.0
250 //______________________________________________________________________
251 void AliITSsimulationSPDdubna::FinishSDigitiseModule(){
252 // This function calls SDigitsToDigits which creates Digits from SDigits
260 if(GetDebug(1)) Info("SDigitiseModule","()");
261 pListToDigits(); // Charge To Signal both adds noise and
265 //______________________________________________________________________
266 void AliITSsimulationSPDdubna::DigitiseModule(AliITSmodule *mod,Int_t,
268 // This function creates Digits straight from the hits and then adds
269 // electronic noise to the digits before adding them to pList
270 // Each of the input variables is passed along to HitToSDigit
272 // AliITSmodule *mod module
280 if(GetDebug(1)) Info("DigitiseModule","(mod=%p,,)",mod);
285 //______________________________________________________________________
286 void AliITSsimulationSPDdubna::HitToSDigit(AliITSmodule *mod){
287 // Does the charge distributions using Gaussian diffusion charge charing.
289 // AliITSmodule *mod Pointer to this module
294 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
295 TObjArray *hits = mod->GetHits();
296 Int_t nhits = hits->GetEntriesFast();
299 Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0;
300 Double_t x,y,z,t,tp,st,dt=0.2,el,sig;
301 Double_t thick = kmictocm*GetSeg()->Dy();
303 if(GetDebug(1)) Info("HitsToSDigits","(mod=%p) fCoupling=%d",
306 for(h=0;h<nhits;h++){
308 cout << "Hits=" << h << "," << *(mod->GetHit(h)) << endl;
310 if(!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
311 st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
313 st = (Double_t)((Int_t)(st/kmictocm)); // number of microns
314 if(st<=1.0) st = 1.0;
316 for(t=0.0;t<1.0;t+=dt){ // Integrate over t
321 if(!(GetSeg()->LocalToDet(x,z,ix,iz))) continue; // outside
322 el = GetResp(ix,iz)->GeVToCharge((Double_t)(dt*de));
324 if(el<=0.0) cout<<"el="<<el<<" dt="<<dt
327 sig = GetResp(ix,iz)->SigmaDiffusion1D(thick + y);
328 SpreadCharge(x,z,ix,iz,el,sig,idtrack,h);
330 } else { // st == 0.0 deposit it at this point
334 if(!(GetSeg()->LocalToDet(x,z,ix,iz))) continue; // outside
335 el = GetResp(ix,iz)->GeVToCharge((Double_t)de);
336 sig = GetResp(ix,iz)->SigmaDiffusion1D(thick + y);
337 SpreadCharge(x,z,ix,iz,el,sig,idtrack,h);
344 // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
345 for(i=0;i<GetMap()->GetEntries();i++)
346 if(GetMap()->GetpListItem(i)==0) continue;
348 GetMap()->GetMapIndex(
349 GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
350 SetCoupling(iz,ix,idtrack,h);
354 // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
355 for(i=0;i<GetMap()->GetEntries();i++)
356 if(GetMap()->GetpListItem(i)==0) continue;
358 GetMap()->GetMapIndex(
359 GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
360 SetCouplingOld(iz,ix,idtrack,h);
364 } // Loop over all hits h
365 if(GetDebug(2))Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
367 //______________________________________________________________________
368 void AliITSsimulationSPDdubna::SpreadCharge(Double_t x0,Double_t z0,
370 Double_t el,Double_t sig,Int_t t,
372 // Spreads the charge over neighboring cells. Assume charge is distributed
373 // as charge(x,z) = (el/2*pi*sig*sig)*exp(-arg)
374 // arg=((x-x0)*(x-x0)/2*sig*sig)+((z-z0*z-z0)/2*sig*sig)
375 // Defined this way, the integral over all x and z is el.
377 // Double_t x0 x position of point where charge is liberated
378 // Double_t y0 y position of point where charge is liberated
379 // Double_t z0 z position of point where charge is liberated
380 // Int_t ix0 row of cell corresponding to point x0
381 // Int_t iz0 columb of cell corresponding to point z0
382 // Double_t el number of electrons liberated in this step
383 // Double_t sig Sigma difusion for this step (y0 dependent)
384 // Int_t t track number
385 // Int_t ti hit track index number
386 // Int_t hi hit "hit" index number
391 const Int_t knx = 3,knz = 2;
392 const Double_t kRoot2 = 1.414213562; // Sqrt(2).
393 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
394 Int_t ix,iz,ixs,ixe,izs,ize;
396 Double_t x1,x2,z1,z2,s,sp;
398 if(GetDebug(4)) Info("SpreadCharge","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,"
399 "sig=%e,t=%d,i=%d)",x0,z0,ix0,iz0,el,sig,t,hi);
400 if(sig<=0.0) { // if sig<=0 No diffusion to simulate.
401 GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
403 cout << "sig<=0.0=" << sig << endl;
407 sp = 1.0/(sig*kRoot2);
409 cout << "sig=" << sig << " sp=" << sp << endl;
411 ixs = TMath::Max(-knx+ix0,0);
412 ixe = TMath::Min(knx+ix0,GetSeg()->Npx()-1);
413 izs = TMath::Max(-knz+iz0,0);
414 ize = TMath::Min(knz+iz0,GetSeg()->Npz()-1);
415 for(ix=ixs;ix<=ixe;ix++) for(iz=izs;iz<=ize;iz++){
416 GetSeg()->DetToLocal(ix,iz,x,z); // pixel center
419 x2 = x1 + 0.5*kmictocm*GetSeg()->Dpx(ix); // Upper
420 x1 -= 0.5*kmictocm*GetSeg()->Dpx(ix); // Lower
421 z2 = z1 + 0.5*kmictocm*GetSeg()->Dpz(iz); // Upper
422 z1 -= 0.5*kmictocm*GetSeg()->Dpz(iz); // Lower
423 x1 -= x0; // Distance from where track traveled
424 x2 -= x0; // Distance from where track traveled
425 z1 -= z0; // Distance from where track traveled
426 z2 -= z0; // Distance from where track traveled
427 s = 0.25; // Correction based on definision of Erfc
428 s *= TMath::Erfc(sp*x1) - TMath::Erfc(sp*x2);
430 cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<
431 " iz0="<<iz0<<" iz="<<iz<<" z0="<<z<<
432 " sp*x1="<<sp*x1<<" sp*x2="<<sp*x2<<" s="<<s;
434 s *= TMath::Erfc(sp*z1) - TMath::Erfc(sp*z2);
436 cout<<" sp*z1="<<sp*z1<<" sp*z2="<<sp*z2<<" s="<<s<< endl;
438 GetMap()->AddSignal(iz,ix,t,hi,GetModuleNumber(),s*el);
441 //______________________________________________________________________
442 void AliITSsimulationSPDdubna::pListToDigits(){
443 // add noise and electronics, perform the zero suppression and add the
451 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
453 Double_t electronics;
455 const Int_t nmaxtrk=AliITSdigitSPD::GetNTracks();
456 static AliITSdigitSPD dig;
458 if(GetDebug(1)) Info("pListToDigits","()");
459 for(iz=0; iz<GetNPixelsZ(); iz++) for(ix=0; ix<GetNPixelsX(); ix++){
460 // Apply Noise/Dead channals and the like
461 if(GetResp(ix,iz)->IsPixelDead(GetModuleNumber(),ix,iz)) continue;
462 electronics = GetResp(ix,iz)->ApplyBaselineAndNoise();
463 UpdateMapNoise(ix,iz,electronics);
465 // Apply Threshold and write Digits.
466 sig = GetMap()->GetSignalOnly(iz,ix);
467 FillHistograms(ix,iz,sig+electronics);
469 cout<<sig<<"+"<<electronics<<">threshold("<<ix<<","<<iz
470 <<")="<<GetThreshold(ix,iz) <<endl;
472 if (sig+electronics <= GetThreshold(ix,iz)) continue;
476 dig.SetSignalSPD((Int_t) GetMap()->GetSignal(iz,ix));
477 for(j=0;j<nmaxtrk;j++){
478 if (j<GetMap()->GetNEnteries()) {
479 dig.SetTrack(j,GetMap()->GetTrack(iz,ix,j));
480 dig.SetHit(j,GetMap()->GetHit(iz,ix,j));
481 }else { // Default values
487 cout<<iz<<","<<ix<<","<<*(GetMap()->GetpListItem(iz,ix))<<endl;
489 aliITS->AddSimDigit(0,&dig);
492 //______________________________________________________________________
493 void AliITSsimulationSPDdubna::CreateHistograms(){
494 // create 1D histograms for tests
502 if(GetDebug(1)) Info("CreateHistograms","create histograms");
504 fHis = new TObjArray(GetNPixelsZ());
505 TString fSPDname("spd_");
506 for(Int_t i=0;i<GetNPixelsZ();i++) {
508 sprintf(pixelz,"%d",i);
509 fSPDname.Append(pixelz);
510 fHis->AddAt(new TH1F(fSPDname.Data(),"SPD maps",
511 GetNPixelsX(),0.,(Double_t)GetNPixelsX()),i);
514 //______________________________________________________________________
515 void AliITSsimulationSPDdubna::FillHistograms(Int_t ix,Int_t iz,Double_t v){
516 // Fill the histogram
524 if(!GetHistArray()) return; // Only fill if setup.
525 if(GetDebug(2)) Info("FillHistograms","fill histograms");
526 GetHistogram(iz)->Fill(ix,v);
528 //______________________________________________________________________
529 void AliITSsimulationSPDdubna::ResetHistograms(){
530 // Reset histograms for this detector
538 if(!GetHistArray()) return; // Only fill if setup.
539 if(GetDebug(2)) Info("FillHistograms","fill histograms");
540 for ( int i=0;i<GetNPixelsZ();i++ ) {
541 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
545 //______________________________________________________________________
546 void AliITSsimulationSPDdubna::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
548 // Take into account the coupling between adiacent pixels.
549 // The parameters probcol and probrow are the probability of the
550 // signal in one pixel shared in the two adjacent pixels along
551 // the column and row direction, respectively.
552 // Note pList is goten via GetMap() and module is not need any more.
553 // Otherwise it is identical to that coded by Tiziano Virgili (BSN).
556 <img src="picts/ITS/barimodel_3.gif">
559 <font size=+2 color=red>
560 <a href="mailto:tiziano.virgili@cern.ch"></a>.
566 // Int_t row z cell index
567 // Int_t col x cell index
568 // Int_t ntrack track incex number
569 // Int_t idhit hit index number
575 Double_t pulse1,pulse2;
576 Double_t couplR=0.0,couplC=0.0;
579 GetCouplings(couplR,couplC);
580 if(GetDebug(3)) Info("SetCoupling","(row=%d,col=%d,ntrack=%d,idhit=%d) "
581 "Calling SetCoupling couplR=%e couplC=%e",
582 row,col,ntrack,idhit,couplR,couplC);
585 pulse1 = GetMap()->GetSignalOnly(row,col);
587 for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
591 xr = gRandom->Rndm();
592 //if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold(j1,col))){
593 if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplR)){
597 UpdateMapSignal(col,j1,ntrack,idhit,pulse1);
599 flag = 1; // only first next!!
602 // loop in column direction
606 xr = gRandom->Rndm();
607 //if((j2<0)||j2>(GetNPixelsX()-1)||pulse2<GetThreshold(row,j2)){
608 if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplC)){
612 UpdateMapSignal(j2,row,ntrack,idhit,pulse2);
614 flag = 1; // only first next!!
619 //______________________________________________________________________
620 void AliITSsimulationSPDdubna::SetCouplingOld(Int_t row, Int_t col,
621 Int_t ntrack,Int_t idhit) {
622 // Take into account the coupling between adiacent pixels.
623 // The parameters probcol and probrow are the fractions of the
624 // signal in one pixel shared in the two adjacent pixels along
625 // the column and row direction, respectively.
628 <img src="picts/ITS/barimodel_3.gif">
631 <font size=+2 color=red>
632 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
638 // Int_t row z cell index
639 // Int_t col x cell index
640 // Int_t ntrack track incex number
641 // Int_t idhit hit index number
642 // Int_t module module number
648 Double_t pulse1,pulse2;
649 Double_t couplR=0.0,couplC=0.0;
651 GetCouplings(couplR,couplC);
652 if(GetDebug(3)) Info("SetCouplingOld","(row=%d,col=%d,ntrack=%d,idhit=%d) "
653 "Calling SetCoupling couplR=%e couplC=%e",
654 row,col,ntrack,idhit,couplR,couplC);
657 pulse1 = GetMap()->GetSignalOnly(row,col);
659 for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
663 if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold(j1,col))){
664 pulse1 = GetMap()->GetSignalOnly(row,col);
668 UpdateMapSignal(col,j1,ntrack,idhit,pulse1);
672 // loop in column direction
676 if((j2<0)||(j2>(GetNPixelsX()-1))||(pulse2<GetThreshold(row,j2))){
677 pulse2 = GetMap()->GetSignalOnly(row,col);
681 UpdateMapSignal(j2,row,ntrack,idhit,pulse2);