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"
38 ClassImp(AliITSsimulationSPD)
39 ////////////////////////////////////////////////////////////////////////
41 // Modified by D. Elia, G.E. Bruno, H. Tydesjo
42 // Fast diffusion code by Bjorn S. Nilsen
44 // October 2007: GetCalibrationObjects() removed
47 // Written by Boris Batyunya
51 // AliITSsimulationSPD is to do the simulation of SPDs.
53 ////////////////////////////////////////////////////////////////////////
55 //______________________________________________________________________
56 AliITSsimulationSPD::AliITSsimulationSPD():
65 fStrobePhase(-12.5e-9){
66 // Default constructor.
72 // A default constructed AliITSsimulationSPD class.
74 AliDebug(1,Form("Calling default constructor"));
77 //______________________________________________________________________
78 AliITSsimulationSPD::AliITSsimulationSPD(AliITSDetTypeSim *dettyp):
79 AliITSsimulation(dettyp),
87 fStrobePhase(-12.5e-9){
88 // standard constructor
90 // AliITSsegmentation *seg A pointer to the segmentation class
91 // to be used for this simulation
92 // AliITSCalibration *resp A pointer to the responce class to
93 // be used for this simulation
97 // A default constructed AliITSsimulationSPD class.
99 AliDebug(1,Form("Calling standard constructor "));
102 //______________________________________________________________________
103 void AliITSsimulationSPD::Init(){
111 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
115 SetMap(new AliITSpList(GetNPixelsZ(),GetNPixelsX()));
116 AliITSSimuParam* simpar = fDetType->GetSimuParam();
117 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
118 Double_t bias = simpar->GetSPDBiasVoltage();
119 // cout << "Bias Voltage --> " << bias << endl; // dom
120 simpar->SetDistanceOverVoltage(kmictocm*seg->Dy(),bias);
121 // set kind of coupling ("old" or "new")
123 simpar->GetSPDCouplingOption(opt);
124 char *old = strstr(opt,"old");
130 //SetLorentzDrift(kTRUE);
131 if (fLorentz) SetTanLorAngle();
132 //SetStrobeGeneration(kFALSE);
133 if (fStrobe) GenerateStrobePhase();
135 //______________________________________________________________________
136 Bool_t AliITSsimulationSPD::SetTanLorAngle(Double_t WeightHole) {
137 // This function set the Tangent of the Lorentz angle.
138 // A weighted average is used for electrons and holes
139 // Input: Double_t WeightHole: wheight for hole: it should be in the range [0,1]
140 // output: Bool_t : kTRUE in case of success
143 AliError("AliITSsimulationSPD::SetTanLorAngle: AliITSDetTypeSim* fDetType not set ");
147 AliWarning("AliITSsimulationSPD::SetTanLorAngle: You have asked for negative Hole weight");
148 AliWarning("AliITSsimulationSPD::SetTanLorAngle: I'm going to use only electrons");
152 AliWarning("AliITSsimulationSPD::SetTanLorAngle: You have asked for weight > 1");
153 AliWarning("AliITSsimulationSPD::SetTanLorAngle: I'm going to use only holes");
155 Double_t WeightEle=1.-WeightHole;
156 AliITSSimuParam* simpar = fDetType->GetSimuParam();
157 Double_t pos[3]={0.,0.,0.};
158 Double_t B[3]={0.,0.,0.};
159 TGeoGlobalMagField::Instance()->Field(pos,B);
160 fTanLorAng = TMath::Tan(WeightHole*simpar->LorentzAngleHole(B[2]) +
161 WeightEle*simpar->LorentzAngleElectron(B[2]));
162 fTanLorAng*=-1.; // this only for the old geometry
163 // comment the upper line for the new geometry
166 //______________________________________________________________________
167 AliITSsimulationSPD::~AliITSsimulationSPD(){
181 //______________________________________________________________________
182 AliITSsimulationSPD::AliITSsimulationSPD(const
184 &s) : AliITSsimulation(s),
186 fSPDname(s.fSPDname),
187 fCoupling(s.fCoupling),
188 fLorentz(s.fLorentz),
189 fTanLorAng(s.fTanLorAng),
191 fStrobeLenght(s.fStrobeLenght),
192 fStrobePhase(s.fStrobePhase){
195 // AliITSsimulationSPD &s The original class for which
196 // this class is a copy of
202 //______________________________________________________________________
203 AliITSsimulationSPD& AliITSsimulationSPD::operator=(const
204 AliITSsimulationSPD &s){
205 // Assignment operator
207 // AliITSsimulationSPD &s The original class for which
208 // this class is a copy of
213 if(&s == this) return *this;
215 fCoupling = s.fCoupling;
216 fSPDname = s.fSPDname;
217 fLorentz = s.fLorentz;
218 fTanLorAng = s.fTanLorAng;
220 fStrobeLenght = s.fStrobeLenght;
221 fStrobePhase = s.fStrobePhase;
225 //______________________________________________________________________
226 AliITSsimulation& AliITSsimulationSPD::operator=(const
227 AliITSsimulation &s){
228 // Assignment operator
230 // AliITSsimulationSPD &s The original class for which
231 // this class is a copy of
236 if(&s == this) return *this;
237 Error("AliITSsimulationSPD","Not allowed to make a = with "
238 "AliITSsimulationSPD","Using default creater instead");
243 //______________________________________________________________________
244 void AliITSsimulationSPD::InitSimulationModule(Int_t module, Int_t event){
245 // This function creates maps to build the list of tracks for each
246 // summable digit. Inputs defined by base class.
248 // Int_t module // Module number to be simulated
249 // Int_t event // Event number to be simulated
255 AliDebug(1,Form("(module=%d,event=%d)",module,event));
256 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
257 AliITSSimuParam* simpar = fDetType->GetSimuParam();
258 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
259 SetModuleNumber(module);
260 SetEventNumber(event);
261 simpar->SetDistanceOverVoltage(kmictocm*seg->Dy(),simpar->GetSPDBiasVoltage(module));
264 //_____________________________________________________________________
265 void AliITSsimulationSPD::SDigitiseModule(AliITSmodule *mod,Int_t,
267 // This function begins the work of creating S-Digits. Inputs defined
270 // AliITSmodule *mod // module
272 // Int_t event // Event number
276 // test // test returns kTRUE if the module contained hits
277 // // test returns kFALSE if it did not contain hits
279 AliDebug(1,Form("(mod=%p, ,event=%d)",mod,event));
280 if(!(mod->GetNhits())){
281 AliDebug(1,Form("In event %d module %d there are %d hits returning.",
282 event, mod->GetIndex(),mod->GetNhits()));
283 return;// if module has no hits don't create Sdigits
285 SetModuleNumber(mod->GetIndex());
286 if (fStrobe) if(event != GetEventNumber()) GenerateStrobePhase();
287 SetEventNumber(event);
288 InitSimulationModule( GetModuleNumber() , event );
290 HitToSDigitFast(mod);
291 RemoveDeadPixels(mod);
292 // cout << "After Remove in SDigitiseModule !!!!!" << endl; // dom
293 // cout << "Module " << mod->GetIndex() << " Event " << event << endl; // dom
297 //______________________________________________________________________
298 void AliITSsimulationSPD::WriteSDigits(){
299 // This function adds each S-Digit to pList
306 Int_t ix, nix, iz, niz;
307 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
309 AliDebug(1,Form("Writing SDigits for module %d",GetModuleNumber()));
310 // cout << "WriteSDigits for module " << GetModuleNumber() << endl; // dom
311 GetMap()->GetMaxMapIndex(niz, nix);
312 for(iz=0; iz<niz; iz++)for(ix=0; ix<nix; ix++){
313 if(GetMap()->GetSignalOnly(iz,ix)>0.0){
314 // cout << " Signal gt 0 iz ix " << iz << ix << " Module " << GetModuleNumber() << endl; // dom
315 aliITS->AddSumDigit(*(GetMap()->GetpListItem(iz,ix)));
316 if(AliDebugLevel()>0) {
317 AliDebug(1,Form("%d, %d",iz,ix));
318 cout << *(GetMap()->GetpListItem(iz,ix)) << endl;
320 } // end if GetMap()->GetSignalOnly(iz,ix)>0.0
324 //______________________________________________________________________
325 void AliITSsimulationSPD::FinishSDigitiseModule(){
326 // This function calls SDigitsToDigits which creates Digits from SDigits
335 // cout << "FinishSDigitiseModule for module " << GetModuleNumber() << endl; // dom
336 FrompListToDigits(); // Charge To Signal both adds noise and
340 //______________________________________________________________________
341 void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod,Int_t,
343 // This function creates Digits straight from the hits and then adds
344 // electronic noise to the digits before adding them to pList
345 // Each of the input variables is passed along to HitToSDigit
347 // AliITSmodule *mod module
355 if (fStrobe) if(event != GetEventNumber()) GenerateStrobePhase();
356 AliDebug(1,Form("(mod=%p,,)",mod));
358 InitSimulationModule( mod->GetIndex(), event );
359 HitToSDigitFast(mod);
360 RemoveDeadPixels(mod);
361 // cout << "After Remove in DigitiseModule in module " << mod->GetIndex() << endl; // dom
365 //______________________________________________________________________
366 void AliITSsimulationSPD::HitToSDigit(AliITSmodule *mod){
367 // Does the charge distributions using Gaussian diffusion charge charing.
369 // AliITSmodule *mod Pointer to this module
374 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
375 const Double_t kBunchLenght = 25e-9; // LHC clock
376 TObjArray *hits = mod->GetHits();
377 Int_t nhits = hits->GetEntriesFast();
380 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;
381 Double_t x,y,z,t,tp,st,dt=0.2,el,sig,sigx,sigz,fda;
382 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
383 AliITSSimuParam *simpar = fDetType->GetSimuParam();
384 Double_t thick = 0.5*kmictocm*seg->Dy(); // Half Thickness
385 simpar->GetSPDSigmaDiffusionAsymmetry(fda); //
387 AliDebug(1,Form("(mod=%p) fCoupling=%d",mod,fCoupling));
389 for(h=0;h<nhits;h++){
390 if(AliDebugLevel()>0) {
391 AliDebug(1,Form("Hits, %d", h));
392 cout << *(mod->GetHit(h)) << endl;
394 // Check if the hit is inside readout window
396 if ((mod->GetHit(h)->GetTOF() < fStrobePhase) ||
397 (mod->GetHit(h)->GetTOF() > (fStrobePhase+(Double_t)fStrobeLenght*kBunchLenght))) continue;
398 if(!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
399 st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
401 st = (Double_t)((Int_t)(st/kmictocm)); // number of microns
402 if(st<=1.0) st = 1.0;
404 for(t=0.0;t<1.0;t+=dt){ // Integrate over t
409 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
410 //el = res->GeVToCharge((Double_t)(dt*de));
411 el = dt * de / simpar->GetGeVToCharge();
413 if(el<=0.0) cout<<"el="<<el<<" dt="<<dt
416 sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
419 if (fLorentz) ld=(y+thick)*fTanLorAng;
420 SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
422 } else { // st == 0.0 deposit it at this point
426 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
427 //el = res->GeVToCharge((Double_t)de);
428 el = de / simpar->GetGeVToCharge();
429 sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
432 if (fLorentz) ld=(y+thick)*fTanLorAng;
433 SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
436 } // Loop over all hits h
443 for(i=0;i<GetMap()->GetEntries();i++)
444 if(GetMap()->GetpListItem(i)==0) continue;
446 GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
447 SetCoupling(iz,ix,idtrack,h);
451 for(i=0;i<GetMap()->GetEntries();i++)
452 if(GetMap()->GetpListItem(i)==0) continue;
454 GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
455 SetCouplingOld(iz,ix,idtrack,h);
459 if(GetDebug(2))Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
461 //______________________________________________________________________
462 void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
463 // Does the charge distributions using Gaussian diffusion charge charing. // Inputs:
464 // AliITSmodule *mod Pointer to this module
469 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
471 const Double_t kti[kn10]={7.443716945e-3,2.166976971e-1,3.397047841e-1,
472 4.325316833e-1,4.869532643e-1,5.130467358e-1,
473 5.674683167e-1,6.602952159e-1,7.833023029e-1,
475 const Double_t kwi[kn10]={1.477621124e-1,1.346333597e-1,1.095431813e-1,
476 7.472567455e-2,3.333567215e-2,3.333567215e-2,
477 7.472567455e-2,1.095431813e-1,1.346333597e-1,
479 const Double_t kBunchLenght = 25e-9; // LHC clock
480 TObjArray *hits = mod->GetHits();
481 Int_t nhits = hits->GetEntriesFast();
484 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;
485 Double_t x,y,z,t,st,el,sig,sigx,sigz,fda;
486 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
487 AliITSSimuParam* simpar = fDetType->GetSimuParam();
488 Double_t thick = 0.5*kmictocm*seg->Dy(); // Half thickness
489 simpar->GetSPDSigmaDiffusionAsymmetry(fda);
490 // cout << "Half Thickness " << thick << endl; // dom
491 // cout << "Diffusion asymm " << fda << endl; // dom
493 AliDebug(1,Form("(mod=%p) fCoupling=%d",mod,fCoupling));
495 for(h=0;h<nhits;h++){
496 if(AliDebugLevel()>0) {
497 AliDebug(1,Form("Hits, %d", h));
498 cout << *(mod->GetHit(h)) << endl;
500 // Check if the hit is inside readout window
502 if ((mod->GetHit(h)->GetTOF() < fStrobePhase) ||
503 (mod->GetHit(h)->GetTOF() > (fStrobePhase+(Double_t)fStrobeLenght*kBunchLenght))) continue;
504 if(!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
505 st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
506 if(st>0.0) for(i=0;i<kn10;i++){ // Integrate over t
511 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
512 el = kwi[i]*de/simpar->GetGeVToCharge();
514 if(el<=0.0) cout<<"el="<<el<<" kwi["<<i<<"]="<<kwi[i]
517 sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
520 if (fLorentz) ld=(y+thick)*fTanLorAng;
521 SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
522 // cout << "sigx sigz " << sigx << " " << sigz << endl; // dom
523 } // end for i // End Integrate over t
524 else { // st == 0.0 deposit it at this point
528 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
529 el = de / simpar->GetGeVToCharge();
530 sig = simpar->SigmaDiffusion1D(TMath::Abs(thick + y));
533 if (fLorentz) ld=(y+thick)*fTanLorAng;
534 SpreadChargeAsym(x,z,ix,iz,el,sigx,sigz,ld,idtrack,h);
537 } // Loop over all hits h
544 for(i=0;i<GetMap()->GetEntries();i++)
545 if(GetMap()->GetpListItem(i)==0) continue;
547 GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
548 SetCoupling(iz,ix,idtrack,h);
552 for(i=0;i<GetMap()->GetEntries();i++)
553 if(GetMap()->GetpListItem(i)==0) continue;
555 GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
556 SetCouplingOld(iz,ix,idtrack,h);
560 if(GetDebug(2))Info("HitToSDigit","Finished fCoupling=%d",fCoupling);
562 //______________________________________________________________________
563 void AliITSsimulationSPD::SpreadCharge(Double_t x0,Double_t z0,
565 Double_t el,Double_t sig,Double_t ld,
567 // Spreads the charge over neighboring cells. Assume charge is distributed
568 // as charge(x,z) = (el/2*pi*sig*sig)*exp(-arg)
569 // arg=((x-x0)*(x-x0)/2*sig*sig)+((z-z0*z-z0)/2*sig*sig)
570 // if fLorentz=kTRUE, then x0=x0+ld (Lorentz drift taken into account)
571 // Defined this way, the integral over all x and z is el.
573 // Double_t x0 x position of point where charge is liberated
574 // Double_t z0 z position of point where charge is liberated
575 // Int_t ix0 row of cell corresponding to point x0
576 // Int_t iz0 columb of cell corresponding to point z0
577 // Double_t el number of electrons liberated in this step
578 // Double_t sig Sigma difusion for this step (y0 dependent)
579 // Double_t ld lorentz drift in x for this step (y0 dependent)
580 // Int_t t track number
581 // Int_t ti hit track index number
582 // Int_t hi hit "hit" index number
587 const Int_t knx = 3,knz = 2;
588 const Double_t kRoot2 = 1.414213562; // Sqrt(2).
589 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
590 Int_t ix,iz,ixs,ixe,izs,ize;
592 Double_t x1,x2,z1,z2,s,sp;
593 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
596 if(GetDebug(4)) Info("SpreadCharge","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,"
597 "sig=%e,t=%d,i=%d)",x0,z0,ix0,iz0,el,sig,t,hi);
598 if(sig<=0.0) { // if sig<=0 No diffusion to simulate.
599 GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
601 cout << "sig<=0.0=" << sig << endl;
605 sp = 1.0/(sig*kRoot2);
607 cout << "sig=" << sig << " sp=" << sp << endl;
609 ixs = TMath::Max(-knx+ix0,0);
610 ixe = TMath::Min(knx+ix0,seg->Npx()-1);
611 izs = TMath::Max(-knz+iz0,0);
612 ize = TMath::Min(knz+iz0,seg->Npz()-1);
613 for(ix=ixs;ix<=ixe;ix++) for(iz=izs;iz<=ize;iz++){
614 seg->DetToLocal(ix,iz,x,z); // pixel center
617 x2 = x1 + 0.5*kmictocm*seg->Dpx(ix); // Upper
618 x1 -= 0.5*kmictocm*seg->Dpx(ix); // Lower
619 z2 = z1 + 0.5*kmictocm*seg->Dpz(iz); // Upper
620 z1 -= 0.5*kmictocm*seg->Dpz(iz); // Lower
621 x1 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
622 x2 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
623 z1 -= z0; // Distance from where track traveled
624 z2 -= z0; // Distance from where track traveled
625 s = 0.25; // Correction based on definision of Erfc
626 s *= TMath::Erfc(sp*x1) - TMath::Erfc(sp*x2);
628 cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<
629 " iz0="<<iz0<<" iz="<<iz<<" z0="<<z<<
630 " sp*x1="<<sp*x1<<" sp*x2="<<sp*x2<<" s="<<s;
632 s *= TMath::Erfc(sp*z1) - TMath::Erfc(sp*z2);
634 cout<<" sp*z1="<<sp*z1<<" sp*z2="<<sp*z2<<" s="<<s<< endl;
636 GetMap()->AddSignal(iz,ix,t,hi,GetModuleNumber(),s*el);
639 //______________________________________________________________________
640 void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
642 Double_t el,Double_t sigx,Double_t sigz,
643 Double_t ld,Int_t t,Int_t hi){
644 // Spreads the charge over neighboring cells. Assume charge is distributed
645 // as charge(x,z) = (el/2*pi*sigx*sigz)*exp(-arg)
646 // arg=((x-x0)*(x-x0)/2*sigx*sigx)+((z-z0*z-z0)/2*sigz*sigz)
647 // if fLorentz=kTRUE, then x0=x0+ld (Lorentz drift taken into account)
648 // Defined this way, the integral over all x and z is el.
650 // Double_t x0 x position of point where charge is liberated
651 // Double_t z0 z position of point where charge is liberated
652 // Int_t ix0 row of cell corresponding to point x0
653 // Int_t iz0 columb of cell corresponding to point z0
654 // Double_t el number of electrons liberated in this step
655 // Double_t sigx Sigma difusion along x for this step (y0 dependent)
656 // Double_t sigz Sigma difusion along z for this step (y0 dependent)
657 // Double_t ld lorentz drift in x for this stip (y0 dependent)
658 // Int_t t track number
659 // Int_t ti hit track index number
660 // Int_t hi hit "hit" index number
665 const Int_t knx = 3,knz = 2;
666 const Double_t kRoot2 = 1.414213562; // Sqrt(2).
667 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
668 Int_t ix,iz,ixs,ixe,izs,ize;
670 Double_t x1,x2,z1,z2,s,spx,spz;
671 AliITSsegmentationSPD* seg = (AliITSsegmentationSPD*)GetSegmentationModel(0);
674 if(GetDebug(4)) Info("SpreadChargeAsym","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,"
675 "sig=%e,t=%d,i=%d)",x0,z0,ix0,iz0,el,sigx,sigz,t,hi);
676 if(sigx<=0.0 || sigz<=0.0) { // if sig<=0 No diffusion to simulate.
677 GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
679 cout << "sigx<=0.0=" << sigx << endl;
680 cout << "sigz<=0.0=" << sigz << endl;
684 spx = 1.0/(sigx*kRoot2); spz = 1.0/(sigz*kRoot2);
686 cout << "sigx=" << sigx << " spx=" << spx << endl;
687 cout << "sigz=" << sigz << " spz=" << spz << endl;
689 ixs = TMath::Max(-knx+ix0,0);
690 ixe = TMath::Min(knx+ix0,seg->Npx()-1);
691 izs = TMath::Max(-knz+iz0,0);
692 ize = TMath::Min(knz+iz0,seg->Npz()-1);
693 for(ix=ixs;ix<=ixe;ix++) for(iz=izs;iz<=ize;iz++){
694 seg->DetToLocal(ix,iz,x,z); // pixel center
697 x2 = x1 + 0.5*kmictocm*seg->Dpx(ix); // Upper
698 x1 -= 0.5*kmictocm*seg->Dpx(ix); // Lower
699 z2 = z1 + 0.5*kmictocm*seg->Dpz(iz); // Upper
700 z1 -= 0.5*kmictocm*seg->Dpz(iz); // Lower
701 x1 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
702 x2 -= x0+ld; // Distance from where track traveled (taking into account the Lorentz drift)
703 z1 -= z0; // Distance from where track traveled
704 z2 -= z0; // Distance from where track traveled
705 s = 0.25; // Correction based on definision of Erfc
706 s *= TMath::Erfc(spx*x1) - TMath::Erfc(spx*x2);
708 cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<
709 " iz0="<<iz0<<" iz="<<iz<<" z0="<<z<<
710 " spx*x1="<<spx*x1<<" spx*x2="<<spx*x2<<" s="<<s;
712 s *= TMath::Erfc(spz*z1) - TMath::Erfc(spz*z2);
714 cout<<" spz*z1="<<spz*z1<<" spz*z2="<<spz*z2<<" s="<<s<< endl;
716 GetMap()->AddSignal(iz,ix,t,hi,GetModuleNumber(),s*el);
719 //______________________________________________________________________
720 void AliITSsimulationSPD::RemoveDeadPixels(AliITSmodule *mod){
721 // Removes dead pixels on each module (ladder)
723 // Module Index (0,239)
729 Int_t moduleNr = mod->GetIndex();
730 AliITSCalibrationSPD* calObj = (AliITSCalibrationSPD*) GetCalibrationModel(moduleNr);
732 Int_t nrDead = calObj->GetNrBad();
733 // cout << "Module --> " << moduleNr << endl; // dom
734 // cout << "nr of dead " << nrDead << endl; // dom
735 for (Int_t i=0; i<nrDead; i++) {
736 GetMap()->DeleteHit(calObj->GetBadColAt(i),calObj->GetBadRowAt(i));
737 // cout << "dead index " << i << endl; // dom
738 // cout << "col row --> " << calObj->GetDeadColAt(i) << " " << calObj->GetDeadRowAt(i) << endl; // dom
741 //______________________________________________________________________
742 void AliITSsimulationSPD::FrompListToDigits(){
743 // add noise and electronics, perform the zero suppression and add the
751 static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
753 Double_t electronics;
755 const Int_t knmaxtrk=AliITSdigit::GetNTracks();
756 static AliITSdigitSPD dig;
757 AliITSSimuParam *simpar = fDetType->GetSimuParam();
758 if(GetDebug(1)) Info("FrompListToDigits","()");
759 for(iz=0; iz<GetNPixelsZ(); iz++) for(ix=0; ix<GetNPixelsX(); ix++){
760 // NEW (for the moment plugged by hand, in the future possibly read from Data Base)
761 // here parametrize the efficiency of the pixel along the row for the test columns (1,9,17,25)
762 // if(iz==1 || iz == 9 || iz == 17 || iz == 25) {
763 // Double_t eff,p1=0.,p2=0.;
766 // case 1: p1=0.63460;p2=0.42438E-01;break;
767 // case 9: p1=0.41090;p2=0.75914E-01;break;
768 // case 17: p1=0.31883;p2=0.91502E-01;break;
769 // case 25: p1=0.48828;p2=0.57975E-01;break;
771 // eff=1.-p1*exp(-p2*x);
772 // if (gRandom->Rndm() >= eff) continue;
774 // END parametrize the efficiency
776 electronics = simpar->ApplySPDBaselineAndNoise();
777 UpdateMapNoise(ix,iz,electronics);
779 // Apply Threshold and write Digits.
780 sig = GetMap()->GetSignalOnly(iz,ix);
781 FillHistograms(ix,iz,sig+electronics);
783 cout<<sig<<"+"<<electronics<<">threshold("<<ix<<","<<iz
784 <<")="<<GetThreshold() <<endl;
786 if (sig+electronics <= GetThreshold()) continue;
791 // dig.SetSignalSPD((Int_t) GetMap()->GetSignal(iz,ix));
792 Double_t aSignal = GetMap()->GetSignal(iz,ix);
793 if (TMath::Abs(aSignal)>2147483647.0) {
794 //PH 2147483647 is the max. integer
795 //PH This apparently is a problem which needs investigation
796 AliWarning(Form("Too big or too small signal value %f",aSignal));
797 aSignal = TMath::Sign((Double_t)2147483647,aSignal);
799 dig.SetSignalSPD((Int_t)aSignal);
801 for(j=0;j<knmaxtrk;j++){
802 if (j<GetMap()->GetNEntries()) {
803 dig.SetTrack(j,GetMap()->GetTrack(iz,ix,j));
804 dig.SetHit(j,GetMap()->GetHit(iz,ix,j));
805 }else { // Default values
811 cout<<iz<<","<<ix<<","<<*(GetMap()->GetpListItem(iz,ix))<<endl;
813 aliITS->AddSimDigit(0,&dig);
816 //______________________________________________________________________
817 void AliITSsimulationSPD::CreateHistograms(){
818 // create 1D histograms for tests
826 if(GetDebug(1)) Info("CreateHistograms","create histograms");
828 fHis = new TObjArray(GetNPixelsZ());
830 for(Int_t i=0;i<GetNPixelsZ();i++) {
832 sprintf(pixelz,"%d",i);
833 fSPDname.Append(pixelz);
834 fHis->AddAt(new TH1F(fSPDname.Data(),"SPD maps",
835 GetNPixelsX(),0.,(Double_t)GetNPixelsX()),i);
838 //______________________________________________________________________
839 void AliITSsimulationSPD::FillHistograms(Int_t ix,Int_t iz,Double_t v){
840 // Fill the histogram
848 if(!GetHistArray()) return; // Only fill if setup.
849 if(GetDebug(2)) Info("FillHistograms","fill histograms");
850 GetHistogram(iz)->Fill(ix,v);
852 //______________________________________________________________________
853 void AliITSsimulationSPD::ResetHistograms(){
854 // Reset histograms for this detector
862 if(!GetHistArray()) return; // Only fill if setup.
863 if(GetDebug(2)) Info("FillHistograms","fill histograms");
864 for ( int i=0;i<GetNPixelsZ();i++ ) {
865 if (fHis->At(i)) ((TH1F*)fHis->At(i))->Reset();
869 //______________________________________________________________________
870 void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
872 // Take into account the coupling between adiacent pixels.
873 // The parameters probcol and probrow are the probability of the
874 // signal in one pixel shared in the two adjacent pixels along
875 // the column and row direction, respectively.
876 // Note pList is goten via GetMap() and module is not need any more.
877 // Otherwise it is identical to that coded by Tiziano Virgili (BSN).
880 <img src="picts/ITS/barimodel_3.gif">
883 <font size=+2 color=red>
884 <a href="mailto:tiziano.virgili@cern.ch"></a>.
890 // Int_t col z cell index
891 // Int_t row x cell index
892 // Int_t ntrack track incex number
893 // Int_t idhit hit index number
899 Double_t pulse1,pulse2;
900 Double_t couplR=0.0,couplC=0.0;
903 GetCouplings(couplC,couplR);
904 if(GetDebug(3)) Info("SetCoupling","(col=%d,row=%d,ntrack=%d,idhit=%d) "
905 "Calling SetCoupling couplC=%e couplR=%e",
906 col,row,ntrack,idhit,couplC,couplR);
909 pulse1 = GetMap()->GetSignalOnly(col,row);
911 for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
914 xr = gRandom->Rndm();
915 if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplC)){
919 UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
921 flag = 1; // only first next!!
924 // loop in row direction
927 xr = gRandom->Rndm();
928 if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplR)){
932 UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
934 flag = 1; // only first next!!
939 //______________________________________________________________________
940 void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
941 Int_t ntrack,Int_t idhit) {
942 // Take into account the coupling between adiacent pixels.
943 // The parameters probcol and probrow are the fractions of the
944 // signal in one pixel shared in the two adjacent pixels along
945 // the column and row direction, respectively.
948 <img src="picts/ITS/barimodel_3.gif">
951 <font size=+2 color=red>
952 <a href="mailto:Rocco.Caliandro@ba.infn.it"></a>.
958 // Int_t col z cell index
959 // Int_t row x cell index
960 // Int_t ntrack track incex number
961 // Int_t idhit hit index number
962 // Int_t module module number
968 Double_t pulse1,pulse2;
969 Double_t couplR=0.0,couplC=0.0;
971 GetCouplings(couplC,couplR);
974 // cout << "Threshold --> " << GetThreshold() << endl; // dom
975 // cout << "Couplings --> " << couplC << " " << couplR << endl; // dom
977 if(GetDebug(3)) Info("SetCouplingOld","(col=%d,row=%d,ntrack=%d,idhit=%d) "
978 "Calling SetCoupling couplC=%e couplR=%e",
979 col,row,ntrack,idhit,couplC,couplR);
980 for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
981 pulse1 = GetMap()->GetSignalOnly(col,row);
988 if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold())){
989 pulse1 = GetMap()->GetSignalOnly(col,row);
993 UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
995 flag = 1; // only first next !!
998 // loop in row direction
1002 if((j2<0)||(j2>(GetNPixelsX()-1))||(pulse2<GetThreshold())){
1003 pulse2 = GetMap()->GetSignalOnly(col,row);
1007 UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
1009 flag = 1; // only first next!!
1014 //______________________________________________________________________
1015 void AliITSsimulationSPD::GenerateStrobePhase()
1017 // Generate randomly the strobe
1018 // phase w.r.t to the LHC clock
1019 // Done once per event
1020 const Double_t kBunchLenght = 25e-9; // LHC clock
1021 fStrobePhase = ((Double_t)gRandom->Integer(fStrobeLenght))*kBunchLenght-
1022 (Double_t)fStrobeLenght*kBunchLenght+