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 **************************************************************************/
20 #include <Riostream.h>
21 #include <TGeoGlobalMagField.h>
25 #include "AliITSdigitSPD.h"
26 #include "AliITShit.h"
27 #include "AliITSmodule.h"
28 #include "AliITSpList.h"
29 #include "AliITSCalibrationSPD.h"
30 #include "AliITSsegmentationSPD.h"
31 #include "AliITSsimulationSPD.h"
35 #include "AliMathBase.h"
41 ClassImp(AliITSsimulationSPD)
42 ////////////////////////////////////////////////////////////////////////
44 // Modified by D. Elia, G.E. Bruno, H. Tydesjo
45 // Fast diffusion code by Bjorn S. Nilsen
47 // October 2007: GetCalibrationObjects() removed
50 // Written by Boris Batyunya
54 // AliITSsimulationSPD is to do the simulation of SPDs.
56 ////////////////////////////////////////////////////////////////////////
58 //______________________________________________________________________
59 AliITSsimulationSPD::AliITSsimulationSPD():
68 fStrobePhase(-12.5e-9){
69 // Default constructor.
75 // A default constructed AliITSsimulationSPD class.
77 AliDebug(1,Form("Calling default constructor"));
80 //______________________________________________________________________
81 AliITSsimulationSPD::AliITSsimulationSPD(AliITSDetTypeSim *dettyp):
82 AliITSsimulation(dettyp),
90 fStrobePhase(-12.5e-9){
91 // standard constructor
93 // AliITSsegmentation *seg A pointer to the segmentation class
94 // to be used for this simulation
95 // AliITSCalibration *resp A pointer to the responce class to
96 // be used for this simulation
100 // A default constructed AliITSsimulationSPD class.
102 AliDebug(1,Form("Calling standard constructor "));
105 //______________________________________________________________________
106 void AliITSsimulationSPD::Init(){
114 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
118 SetMap(new AliITSpList(GetNPixelsZ(),GetNPixelsX()));
119 AliITSSimuParam* simpar = fDetType->GetSimuParam();
120 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
121 Double_t bias = simpar->GetSPDBiasVoltage();
122 // cout << "Bias Voltage --> " << bias << endl; // dom
123 simpar->SetDistanceOverVoltage(kmictocm*seg->Dy(),bias);
124 // set kind of coupling ("old" or "new")
126 simpar->GetSPDCouplingOption(opt);
127 char *old = strstr(opt,"old");
133 SetLorentzDrift(simpar->GetSPDLorentzDrift());
134 if (fLorentz) SetTanLorAngle(simpar->GetSPDLorentzHoleWeight());
135 //SetStrobeGeneration(kFALSE);
136 if (fStrobe) GenerateStrobePhase();
138 //______________________________________________________________________
139 Bool_t AliITSsimulationSPD::SetTanLorAngle(Double_t WeightHole) {
140 // This function set the Tangent of the Lorentz angle.
141 // A weighted average is used for electrons and holes
142 // Input: Double_t WeightHole: wheight for hole: it should be in the range [0,1]
143 // output: Bool_t : kTRUE in case of success
146 AliError("AliITSsimulationSPD::SetTanLorAngle: AliITSDetTypeSim* fDetType not set ");
150 AliWarning("AliITSsimulationSPD::SetTanLorAngle: You have asked for negative Hole weight");
151 AliWarning("AliITSsimulationSPD::SetTanLorAngle: I'm going to use only electrons");
155 AliWarning("AliITSsimulationSPD::SetTanLorAngle: You have asked for weight > 1");
156 AliWarning("AliITSsimulationSPD::SetTanLorAngle: I'm going to use only holes");
158 Double_t WeightEle=1.-WeightHole;
159 AliITSSimuParam* simpar = fDetType->GetSimuParam();
160 AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
161 if (!fld) AliFatal("The field is not initialized");
162 Double_t bz = fld->SolenoidField();
163 fTanLorAng = TMath::Tan(WeightHole*simpar->LorentzAngleHole(bz) +
164 WeightEle*simpar->LorentzAngleElectron(bz));
167 //______________________________________________________________________
168 AliITSsimulationSPD::~AliITSsimulationSPD(){
182 //______________________________________________________________________
183 AliITSsimulationSPD::AliITSsimulationSPD(const
185 &s) : AliITSsimulation(s),
187 fSPDname(s.fSPDname),
188 fCoupling(s.fCoupling),
189 fLorentz(s.fLorentz),
190 fTanLorAng(s.fTanLorAng),
192 fStrobeLenght(s.fStrobeLenght),
193 fStrobePhase(s.fStrobePhase){
196 // AliITSsimulationSPD &s The original class for which
197 // this class is a copy of
203 //______________________________________________________________________
204 AliITSsimulationSPD& AliITSsimulationSPD::operator=(const
205 AliITSsimulationSPD &s){
206 // Assignment operator
208 // AliITSsimulationSPD &s The original class for which
209 // this class is a copy of
214 if(&s == this) return *this;
216 fCoupling = s.fCoupling;
217 fSPDname = s.fSPDname;
218 fLorentz = s.fLorentz;
219 fTanLorAng = s.fTanLorAng;
221 fStrobeLenght = s.fStrobeLenght;
222 fStrobePhase = s.fStrobePhase;
226 //______________________________________________________________________
227 AliITSsimulation& AliITSsimulationSPD::operator=(const
228 AliITSsimulation &s){
229 // Assignment operator
231 // AliITSsimulationSPD &s The original class for which
232 // this class is a copy of
237 if(&s == this) return *this;
238 Error("AliITSsimulationSPD","Not allowed to make a = with "
239 "AliITSsimulationSPD","Using default creater instead");
244 //______________________________________________________________________
245 void AliITSsimulationSPD::InitSimulationModule(Int_t module, Int_t event){
246 // This function creates maps to build the list of tracks for each
247 // summable digit. Inputs defined by base class.
249 // Int_t module // Module number to be simulated
250 // Int_t event // Event number to be simulated
256 AliDebug(1,Form("(module=%d,event=%d)",module,event));
257 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
258 AliITSSimuParam* simpar = fDetType->GetSimuParam();
259 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
260 SetModuleNumber(module);
261 SetEventNumber(event);
262 simpar->SetDistanceOverVoltage(kmictocm*seg->Dy(),simpar->GetSPDBiasVoltage(module));
265 //_____________________________________________________________________
266 void AliITSsimulationSPD::SDigitiseModule(AliITSmodule *mod,Int_t,
268 // This function begins the work of creating S-Digits. Inputs defined
271 // AliITSmodule *mod // module
273 // Int_t event // Event number
277 // test // test returns kTRUE if the module contained hits
278 // // test returns kFALSE if it did not contain hits
280 AliDebug(1,Form("(mod=%p, ,event=%d)",mod,event));
281 if(!(mod->GetNhits())){
282 AliDebug(1,Form("In event %d module %d there are %d hits returning.",
283 event, mod->GetIndex(),mod->GetNhits()));
284 return;// if module has no hits don't create Sdigits
286 SetModuleNumber(mod->GetIndex());
287 if (fStrobe) if(event != GetEventNumber()) GenerateStrobePhase();
288 SetEventNumber(event);
289 InitSimulationModule( GetModuleNumber() , event );
291 HitToSDigitFast(mod);
292 if (fDetType->GetSimuParam()->GetSPDAddNoisyFlag()) AddNoisyPixels();
293 if (fDetType->GetSimuParam()->GetSPDRemoveDeadFlag()) RemoveDeadPixels();
295 // cout << "After Remove in SDigitiseModule !!!!!" << endl; // dom
296 // cout << "Module " << mod->GetIndex() << " Event " << event << endl; // dom
300 //______________________________________________________________________
301 void AliITSsimulationSPD::WriteSDigits(){
302 // This function adds each S-Digit to pList
309 Int_t ix, nix, iz, niz;
310 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
312 AliDebug(1,Form("Writing SDigits for module %d",GetModuleNumber()));
313 // cout << "WriteSDigits for module " << GetModuleNumber() << endl; // dom
314 GetMap()->GetMaxMapIndex(niz, nix);
315 for(iz=0; iz<niz; iz++)for(ix=0; ix<nix; ix++){
316 if(GetMap()->GetSignalOnly(iz,ix)>0.0){
317 // cout << " Signal gt 0 iz ix " << iz << ix << " Module " << GetModuleNumber() << endl; // dom
318 aliITS->AddSumDigit(*(GetMap()->GetpListItem(iz,ix)));
319 if(AliDebugLevel()>0) {
320 AliDebug(1,Form("%d, %d",iz,ix));
321 cout << *(GetMap()->GetpListItem(iz,ix)) << endl;
323 } // end if GetMap()->GetSignalOnly(iz,ix)>0.0
327 //______________________________________________________________________
328 void AliITSsimulationSPD::FinishSDigitiseModule(){
329 // This function calls SDigitsToDigits which creates Digits from SDigits
338 // cout << "FinishSDigitiseModule for module " << GetModuleNumber() << endl; // dom
339 FrompListToDigits(); // Charge To Signal both adds noise and
343 //______________________________________________________________________
344 void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod,Int_t,
346 // This function creates Digits straight from the hits and then adds
347 // electronic noise to the digits before adding them to pList
348 // Each of the input variables is passed along to HitToSDigit
350 // AliITSmodule *mod module
358 if (fStrobe) if(event != GetEventNumber()) GenerateStrobePhase();
359 AliDebug(1,Form("(mod=%p,,0)",mod));
361 InitSimulationModule( mod->GetIndex(), event );
362 HitToSDigitFast(mod);
364 if (fDetType->GetSimuParam()->GetSPDAddNoisyFlag()) AddNoisyPixels();
365 if (fDetType->GetSimuParam()->GetSPDRemoveDeadFlag()) RemoveDeadPixels();
366 // cout << "After Remove in DigitiseModule in module " << mod->GetIndex() << endl; // dom
370 //______________________________________________________________________
371 void AliITSsimulationSPD::HitToSDigit(AliITSmodule *mod){
372 // Does the charge distributions using Gaussian diffusion charge charing.
374 // AliITSmodule *mod Pointer to this module
379 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
380 const Double_t kBunchLenght = 25e-9; // LHC clock
381 TObjArray *hits = mod->GetHits();
382 Int_t nhits = hits->GetEntriesFast();
385 Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0,ld=0.0;
386 Double_t x,y,z,t,tp,st,dt=0.2,el,sig,sigx,sigz,fda;
387 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
388 AliITSSimuParam *simpar = fDetType->GetSimuParam();
389 Double_t thick = 0.5*kmictocm*seg->Dy(); // Half Thickness
390 simpar->GetSPDSigmaDiffusionAsymmetry(fda); //
392 AliDebug(1,Form("(mod=%p) fCoupling=%d",mod,fCoupling));
394 for(h=0;h<nhits;h++){
395 if(AliDebugLevel()>0) {
396 AliDebug(1,Form("Hits, %d", h));
397 cout << *(mod->GetHit(h)) << endl;
399 // Check if the hit is inside readout window
401 if ((mod->GetHit(h)->GetTOF() < fStrobePhase) ||
402 (mod->GetHit(h)->GetTOF() > (fStrobePhase+(Double_t)fStrobeLenght*kBunchLenght))) continue;
403 if(!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
404 st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
406 st = (Double_t)((Int_t)(st/kmictocm)); // number of microns
407 if(st<=1.0) st = 1.0;
409 for(t=0.0;t<1.0;t+=dt){ // Integrate over t
414 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
415 //el = res->GeVToCharge((Double_t)(dt*de));
416 el = dt * de / simpar->GetGeVToCharge();
418 if(el<=0.0) cout<<"el="<<el<<" dt="<<dt
421 sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
424 if (fLorentz) ld=(y+thick)*fTanLorAng;
425 SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
427 } else { // st == 0.0 deposit it at this point
431 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
432 //el = res->GeVToCharge((Double_t)de);
433 el = de / simpar->GetGeVToCharge();
434 sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
437 if (fLorentz) ld=(y+thick)*fTanLorAng;
438 SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
441 } // Loop over all hits h
448 for(i=0;i<GetMap()->GetEntries();i++)
449 if(GetMap()->GetpListItem(i)==0) continue;
451 GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
452 SetCoupling(iz,ix,idtrack,h);
456 for(i=0;i<GetMap()->GetEntries();i++)
457 if(GetMap()->GetpListItem(i)==0) continue;
459 GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
460 SetCouplingOld(iz,ix,idtrack,h);
464 if(GetDebug(2))Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
466 //______________________________________________________________________
467 void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
468 // Does the charge distributions using Gaussian diffusion charge charing. // Inputs:
469 // AliITSmodule *mod Pointer to this module
474 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
476 const Double_t kti[kn10]={7.443716945e-3,2.166976971e-1,3.397047841e-1,
477 4.325316833e-1,4.869532643e-1,5.130467358e-1,
478 5.674683167e-1,6.602952159e-1,7.833023029e-1,
480 const Double_t kwi[kn10]={1.477621124e-1,1.346333597e-1,1.095431813e-1,
481 7.472567455e-2,3.333567215e-2,3.333567215e-2,
482 7.472567455e-2,1.095431813e-1,1.346333597e-1,
484 const Double_t kBunchLenght = 25e-9; // LHC clock
485 TObjArray *hits = mod->GetHits();
486 Int_t nhits = hits->GetEntriesFast();
489 Double_t x0=0.0,x1=0.0,y0=0.0,y1=0.0,z0=0.0,z1=0.0,de=0.0,ld=0.0;
490 Double_t x,y,z,t,st,el,sig,sigx,sigz,fda;
491 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
492 AliITSSimuParam* simpar = fDetType->GetSimuParam();
493 Double_t thick = 0.5*kmictocm*seg->Dy(); // Half thickness
494 simpar->GetSPDSigmaDiffusionAsymmetry(fda);
495 // cout << "Half Thickness " << thick << endl; // dom
496 // cout << "Diffusion asymm " << fda << endl; // dom
498 AliDebug(1,Form("(mod=%p) fCoupling=%d",mod,fCoupling));
500 for(h=0;h<nhits;h++){
501 if(AliDebugLevel()>0) {
502 AliDebug(1,Form("Hits, %d", h));
503 cout << *(mod->GetHit(h)) << endl;
505 // Check if the hit is inside readout window
507 if ((mod->GetHit(h)->GetTOF() < fStrobePhase) ||
508 (mod->GetHit(h)->GetTOF() > (fStrobePhase+(Double_t)fStrobeLenght*kBunchLenght))) continue;
509 if(!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
510 st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
511 if(st>0.0) for(i=0;i<kn10;i++){ // Integrate over t
516 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
517 el = kwi[i]*de/simpar->GetGeVToCharge();
519 if(el<=0.0) cout<<"el="<<el<<" kwi["<<i<<"]="<<kwi[i]
522 sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
525 if (fLorentz) ld=(y+thick)*fTanLorAng;
526 SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
527 // cout << "sigx sigz " << sigx << " " << sigz << endl; // dom
528 } // end for i // End Integrate over t
529 else { // st == 0.0 deposit it at this point
533 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
534 el = de / simpar->GetGeVToCharge();
535 sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
538 if (fLorentz) ld=(y+thick)*fTanLorAng;
539 SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
542 } // Loop over all hits h
549 for(i=0;i<GetMap()->GetEntries();i++)
550 if(GetMap()->GetpListItem(i)==0) continue;
552 GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
553 SetCoupling(iz,ix,idtrack,h);
557 for(i=0;i<GetMap()->GetEntries();i++)
558 if(GetMap()->GetpListItem(i)==0) continue;
560 GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
561 SetCouplingOld(iz,ix,idtrack,h);
565 if(GetDebug(2))Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
567 //______________________________________________________________________
568 void AliITSsimulationSPD::SpreadCharge(Double_t x0,Double_t z0,
570 Double_t el,Double_t sig,Double_t ld,
572 // Spreads the charge over neighboring cells. Assume charge is distributed
573 // as charge(x,z) = (el/2*pi*sig*sig)*exp(-arg)
574 // arg=((x-x0)*(x-x0)/2*sig*sig)+((z-z0*z-z0)/2*sig*sig)
575 // if fLorentz=kTRUE, then x0=x0+ld (Lorentz drift taken into account)
576 // Defined this way, the integral over all x and z is el.
578 // Double_t x0 x position of point where charge is liberated
579 // Double_t z0 z position of point where charge is liberated
580 // Int_t ix0 row of cell corresponding to point x0
581 // Int_t iz0 columb of cell corresponding to point z0
582 // Double_t el number of electrons liberated in this step
583 // Double_t sig Sigma difusion for this step (y0 dependent)
584 // Double_t ld lorentz drift in x for this step (y0 dependent)
585 // Int_t t track number
586 // Int_t ti hit track index number
587 // Int_t hi hit "hit" index number
592 const Int_t knx = 3,knz = 2;
593 const Double_t kRoot2 = 1.414213562; // Sqrt(2).
594 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
595 Int_t ix,iz,ixs,ixe,izs,ize;
597 Double_t x1,x2,z1,z2,s,sp;
598 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
601 if(GetDebug(4)) Info("SpreadCharge","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,"
602 "sig=%e,t=%d,i=%d)",x0,z0,ix0,iz0,el,sig,t,hi);
603 if(sig<=0.0) { // if sig<=0 No diffusion to simulate.
604 GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
606 cout << "sig<=0.0=" << sig << endl;
610 sp = 1.0/(sig*kRoot2);
612 cout << "sig=" << sig << " sp=" << sp << endl;
614 ixs = TMath::Max(-knx+ix0,0);
615 ixe = TMath::Min(knx+ix0,seg->Npx()-1);
616 izs = TMath::Max(-knz+iz0,0);
617 ize = TMath::Min(knz+iz0,seg->Npz()-1);
618 for(ix=ixs;ix<=ixe;ix++) for(iz=izs;iz<=ize;iz++){
619 seg->DetToLocal(ix,iz,x,z); // pixel center
622 x2 = x1 + 0.5*kmictocm*seg->Dpx(ix); // Upper
623 x1 -= 0.5*kmictocm*seg->Dpx(ix); // Lower
624 z2 = z1 + 0.5*kmictocm*seg->Dpz(iz); // Upper
625 z1 -= 0.5*kmictocm*seg->Dpz(iz); // Lower
626 x1 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
627 x2 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
628 z1 -= z0; // Distance from where track traveled
629 z2 -= z0; // Distance from where track traveled
630 s = 0.25; // Correction based on definision of Erfc
631 s *= AliMathBase::ErfcFast(sp*x1) - AliMathBase::ErfcFast(sp*x2);
633 cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<
634 " iz0="<<iz0<<" iz="<<iz<<" z0="<<z<<
635 " sp*x1="<<sp*x1<<" sp*x2="<<sp*x2<<" s="<<s;
637 s *= AliMathBase::ErfcFast(sp*z1) - AliMathBase::ErfcFast(sp*z2);
639 cout<<" sp*z1="<<sp*z1<<" sp*z2="<<sp*z2<<" s="<<s<< endl;
641 GetMap()->AddSignal(iz,ix,t,hi,GetModuleNumber(),s*el);
644 //______________________________________________________________________
645 void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
647 Double_t el,Double_t sigx,Double_t sigz,
648 Double_t ld,Int_t t,Int_t hi){
649 // Spreads the charge over neighboring cells. Assume charge is distributed
650 // as charge(x,z) = (el/2*pi*sigx*sigz)*exp(-arg)
651 // arg=((x-x0)*(x-x0)/2*sigx*sigx)+((z-z0*z-z0)/2*sigz*sigz)
652 // if fLorentz=kTRUE, then x0=x0+ld (Lorentz drift taken into account)
653 // Defined this way, the integral over all x and z is el.
655 // Double_t x0 x position of point where charge is liberated
656 // Double_t z0 z position of point where charge is liberated
657 // Int_t ix0 row of cell corresponding to point x0
658 // Int_t iz0 columb of cell corresponding to point z0
659 // Double_t el number of electrons liberated in this step
660 // Double_t sigx Sigma difusion along x for this step (y0 dependent)
661 // Double_t sigz Sigma difusion along z for this step (y0 dependent)
662 // Double_t ld lorentz drift in x for this stip (y0 dependent)
663 // Int_t t track number
664 // Int_t ti hit track index number
665 // Int_t hi hit "hit" index number
670 const Int_t knx = 3,knz = 2;
671 const Double_t kRoot2 = 1.414213562; // Sqrt(2).
672 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
673 Int_t ix,iz,ixs,ixe,izs,ize;
675 Double_t x1,x2,z1,z2,s,spx,spz;
676 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
679 if(GetDebug(4)) Info("SpreadChargeAsym","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,"
680 "sigx=%e, sigz=%e, t=%d,i=%d)",x0,z0,ix0,iz0,el,sigx,sigz,t,hi);
681 if(sigx<=0.0 || sigz<=0.0) { // if sig<=0 No diffusion to simulate.
682 GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
684 cout << "sigx<=0.0=" << sigx << endl;
685 cout << "sigz<=0.0=" << sigz << endl;
689 spx = 1.0/(sigx*kRoot2); spz = 1.0/(sigz*kRoot2);
691 cout << "sigx=" << sigx << " spx=" << spx << endl;
692 cout << "sigz=" << sigz << " spz=" << spz << endl;
694 ixs = TMath::Max(-knx+ix0,0);
695 ixe = TMath::Min(knx+ix0,seg->Npx()-1);
696 izs = TMath::Max(-knz+iz0,0);
697 ize = TMath::Min(knz+iz0,seg->Npz()-1);
698 for(ix=ixs;ix<=ixe;ix++) for(iz=izs;iz<=ize;iz++){
699 seg->DetToLocal(ix,iz,x,z); // pixel center
702 x2 = x1 + 0.5*kmictocm*seg->Dpx(ix); // Upper
703 x1 -= 0.5*kmictocm*seg->Dpx(ix); // Lower
704 z2 = z1 + 0.5*kmictocm*seg->Dpz(iz); // Upper
705 z1 -= 0.5*kmictocm*seg->Dpz(iz); // Lower
706 x1 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
707 x2 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
708 z1 -= z0; // Distance from where track traveled
709 z2 -= z0; // Distance from where track traveled
710 s = 0.25; // Correction based on definision of Erfc
711 s *= AliMathBase::ErfcFast(spx*x1) - AliMathBase::ErfcFast(spx*x2);
713 cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<
714 " iz0="<<iz0<<" iz="<<iz<<" z0="<<z<<
715 " spx*x1="<<spx*x1<<" spx*x2="<<spx*x2<<" s="<<s;
717 s *= AliMathBase::ErfcFast(spz*z1) - AliMathBase::ErfcFast(spz*z2);
719 cout<<" spz*z1="<<spz*z1<<" spz*z2="<<spz*z2<<" s="<<s<< endl;
721 GetMap()->AddSignal(iz,ix,t,hi,GetModuleNumber(),s*el);
724 //______________________________________________________________________
725 void AliITSsimulationSPD::RemoveDeadPixels(){
726 // Removes dead pixels on each module (ladder)
727 // This should be called before going from sdigits to digits (FrompListToDigits)
728 Int_t mod = GetModuleNumber();
729 AliITSCalibrationSPD* calObj = (AliITSCalibrationSPD*) fDetType->GetCalibrationModel(mod);
731 Int_t nrDead = calObj->GetNrBad();
732 for (Int_t i=0; i<nrDead; i++) {
733 GetMap()->DeleteHit(calObj->GetBadColAt(i), calObj->GetBadRowAt(i));
736 //______________________________________________________________________
737 void AliITSsimulationSPD::AddNoisyPixels() {
738 // Adds noisy pixels on each module (ladder)
739 // This should be called before going from sdigits to digits (FrompListToDigits)
740 Int_t mod = GetModuleNumber();
741 AliITSCalibrationSPD* calObj = (AliITSCalibrationSPD*) fDetType->GetSPDNoisyModel(mod);
743 Int_t nrNoisy = calObj->GetNrBad();
744 for (Int_t i=0; i<nrNoisy; i++) {
745 // adding 10 times the threshold will for sure make this pixel fire...
746 GetMap()->AddNoise(calObj->GetBadColAt(i), calObj->GetBadRowAt(i), mod, 10*GetThreshold());
749 //______________________________________________________________________
750 void AliITSsimulationSPD::FrompListToDigits(){
751 // add noise and electronics, perform the zero suppression and add the
759 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
761 Double_t electronics;
763 const Int_t knmaxtrk=AliITSdigit::GetNTracks();
764 static AliITSdigitSPD dig;
765 AliITSSimuParam *simpar = fDetType->GetSimuParam();
766 if(GetDebug(1)) Info("FrompListToDigits","()");
767 for(iz=0; iz<GetNPixelsZ(); iz++) for(ix=0; ix<GetNPixelsX(); ix++){
768 // NEW (for the moment plugged by hand, in the future possibly read from Data Base)
769 // here parametrize the efficiency of the pixel along the row for the test columns (1,9,17,25)
770 // if(iz==1 || iz == 9 || iz == 17 || iz == 25) {
771 // Double_t eff,p1=0.,p2=0.;
774 // case 1: p1=0.63460;p2=0.42438E-01;break;
775 // case 9: p1=0.41090;p2=0.75914E-01;break;
776 // case 17: p1=0.31883;p2=0.91502E-01;break;
777 // case 25: p1=0.48828;p2=0.57975E-01;break;
779 // eff=1.-p1*exp(-p2*x);
780 // if (gRandom->Rndm() >= eff) continue;
782 // END parametrize the efficiency
784 electronics = simpar->ApplySPDBaselineAndNoise();
785 UpdateMapNoise(ix,iz,electronics);
787 // Apply Threshold and write Digits.
788 sig = GetMap()->GetSignalOnly(iz,ix);
789 FillHistograms(ix,iz,sig+electronics);
791 cout<<sig<<"+"<<electronics<<">threshold("<<ix<<","<<iz
792 <<")="<<GetThreshold() <<endl;
794 // if (sig+electronics <= GetThreshold()) continue;
795 if (GetMap()->GetSignal(iz,ix) <= GetThreshold()) continue;
800 // dig.SetSignalSPD((Int_t) GetMap()->GetSignal(iz,ix));
801 Double_t aSignal = GetMap()->GetSignal(iz,ix);
802 if (TMath::Abs(aSignal)>2147483647.0) {
803 //PH 2147483647 is the max. integer
804 //PH This apparently is a problem which needs investigation
805 AliWarning(Form("Too big or too small signal value %f",aSignal));
806 aSignal = TMath::Sign((Double_t)2147483647,aSignal);
808 dig.SetSignalSPD((Int_t)aSignal);
810 for(j=0;j<knmaxtrk;j++){
811 if (j<GetMap()->GetNEntries()) {
812 dig.SetTrack(j,GetMap()->GetTrack(iz,ix,j));
813 dig.SetHit(j,GetMap()->GetHit(iz,ix,j));
814 }else { // Default values
820 cout<<iz<<","<<ix<<","<<*(GetMap()->GetpListItem(iz,ix))<<endl;
822 aliITS->AddSimDigit(0,&dig);
823 // simulate fo signal response for this pixel hit:
824 fDetType->ProcessSPDDigitForFastOr(fModule, dig.GetCoord1(), dig.GetCoord2());
827 //______________________________________________________________________
828 void AliITSsimulationSPD::CreateHistograms(){
829 // create 1D histograms for tests
837 if(GetDebug(1)) Info("CreateHistograms","create histograms");
839 fHis = new TObjArray(GetNPixelsZ());
841 for(Int_t i=0;i<GetNPixelsZ();i++) {
843 snprintf(pixelz,3,"%d",i);
844 fSPDname.Append(pixelz);
845 fHis->AddAt(new TH1F(fSPDname.Data(),"SPD maps",
846 GetNPixelsX(),0.,(Double_t)GetNPixelsX()),i);
849 //______________________________________________________________________
850 void AliITSsimulationSPD::FillHistograms(Int_t ix,Int_t iz,Double_t v){
851 // Fill the histogram
859 if(!GetHistArray()) return; // Only fill if setup.
860 if(GetDebug(2)) Info("FillHistograms","fill histograms");
861 GetHistogram(iz)->Fill(ix,v);
863 //______________________________________________________________________
864 void AliITSsimulationSPD::ResetHistograms(){
865 // Reset histograms for this detector
873 if(!GetHistArray()) return; // Only fill if setup.
874 if(GetDebug(2)) Info("FillHistograms","fill histograms");
875 for ( int i=0;i<GetNPixelsZ();i++ ) {
876 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
880 //______________________________________________________________________
881 void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
883 // Take into account the coupling between adiacent pixels.
884 // The parameters probcol and probrow are the probability of the
885 // signal in one pixel shared in the two adjacent pixels along
886 // the column and row direction, respectively.
887 // Note pList is goten via GetMap() and module is not need any more.
888 // Otherwise it is identical to that coded by Tiziano Virgili (BSN).
891 <img src="picts/ITS/barimodel_3.gif">
894 <font size=+2 color=red>
895 <a href="mailto:tiziano.virgili@cern.ch"></a>.
901 // Int_t col z cell index
902 // Int_t row x cell index
903 // Int_t ntrack track incex number
904 // Int_t idhit hit index number
910 Double_t pulse1,pulse2;
911 Double_t couplR=0.0,couplC=0.0;
914 GetCouplings(couplC,couplR);
915 if(GetDebug(3)) Info("SetCoupling","(col=%d,row=%d,ntrack=%d,idhit=%d) "
916 "Calling SetCoupling couplC=%e couplR=%e",
917 col,row,ntrack,idhit,couplC,couplR);
920 pulse1 = GetMap()->GetSignalOnly(col,row);
922 for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
925 xr = gRandom->Rndm();
926 if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplC)){
930 UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
932 flag = 1; // only first next!!
935 // loop in row direction
938 xr = gRandom->Rndm();
939 if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplR)){
943 UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
945 flag = 1; // only first next!!
950 //______________________________________________________________________
951 void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
952 Int_t ntrack,Int_t idhit) {
953 // Take into account the coupling between adiacent pixels.
954 // The parameters probcol and probrow are the fractions of the
955 // signal in one pixel shared in the two adjacent pixels along
956 // the column and row direction, respectively.
959 <img src="picts/ITS/barimodel_3.gif">
962 <font size=+2 color=red>
963 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
969 // Int_t col z cell index
970 // Int_t row x cell index
971 // Int_t ntrack track incex number
972 // Int_t idhit hit index number
973 // Int_t module module number
979 Double_t pulse1,pulse2;
980 Double_t couplR=0.0,couplC=0.0;
982 GetCouplings(couplC,couplR);
985 // cout << "Threshold --> " << GetThreshold() << endl; // dom
986 // cout << "Couplings --> " << couplC << " " << couplR << endl; // dom
988 if(GetDebug(3)) Info("SetCouplingOld","(col=%d,row=%d,ntrack=%d,idhit=%d) "
989 "Calling SetCoupling couplC=%e couplR=%e",
990 col,row,ntrack,idhit,couplC,couplR);
991 for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
992 pulse1 = GetMap()->GetSignalOnly(col,row);
999 if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold())){
1000 pulse1 = GetMap()->GetSignalOnly(col,row);
1004 UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
1006 flag = 1; // only first next !!
1009 // loop in row direction
1013 if((j2<0)||(j2>(GetNPixelsX()-1))||(pulse2<GetThreshold())){
1014 pulse2 = GetMap()->GetSignalOnly(col,row);
1018 UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
1020 flag = 1; // only first next!!
1025 //______________________________________________________________________
1026 void AliITSsimulationSPD::GenerateStrobePhase()
1028 // Generate randomly the strobe
1029 // phase w.r.t to the LHC clock
1030 // Done once per event
1031 const Double_t kBunchLenght = 25e-9; // LHC clock
1032 fStrobePhase = ((Double_t)gRandom->Integer(fStrobeLenght))*kBunchLenght-
1033 (Double_t)fStrobeLenght*kBunchLenght+