]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSsimulationSPD.cxx
minor fix
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSPD.cxx
index cbf1c2728c5f14eb30fb42be3b4c18e4e6c30dd1..ac65a13e6345d7eded82390dbd4553d5ab3e9b6e 100644 (file)
@@ -32,9 +32,12 @@ $Id$
 #include "AliLog.h"
 #include "AliRun.h"
 #include "AliMagF.h"
+#include "AliMathBase.h"
 
 //#define DEBUG
 
+using std::endl;
+using std::cout;
 ClassImp(AliITSsimulationSPD)
 ////////////////////////////////////////////////////////////////////////
 //  Version: 1
@@ -127,8 +130,8 @@ void AliITSsimulationSPD::Init(){
    } else {
        fCoupling=1;
    } // end if
-   //SetLorentzDrift(kTRUE);
-   if (fLorentz) SetTanLorAngle();
+   SetLorentzDrift(simpar->GetSPDLorentzDrift());
+   if (fLorentz) SetTanLorAngle(simpar->GetSPDLorentzHoleWeight());
    //SetStrobeGeneration(kFALSE);
    if (fStrobe) GenerateStrobePhase();
 }
@@ -154,13 +157,11 @@ Bool_t AliITSsimulationSPD::SetTanLorAngle(Double_t WeightHole) {
     }
     Double_t WeightEle=1.-WeightHole;
     AliITSSimuParam* simpar = fDetType->GetSimuParam();
-    Double_t pos[3]={0.,0.,0.};
-    Double_t B[3]={0.,0.,0.};
-    TGeoGlobalMagField::Instance()->Field(pos,B);
-    fTanLorAng = TMath::Tan(WeightHole*simpar->LorentzAngleHole(B[2]) +
-                             WeightEle*simpar->LorentzAngleElectron(B[2]));
-    fTanLorAng*=-1.; // this only for the old geometry
-                      // comment the upper line for the new geometry
+    AliMagF* fld = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
+    if (!fld) AliFatal("The field is not initialized");
+    Double_t bz = fld->SolenoidField();
+    fTanLorAng = TMath::Tan(WeightHole*simpar->LorentzAngleHole(bz) +
+                             WeightEle*simpar->LorentzAngleElectron(bz));
     return kTRUE;
 }
 //______________________________________________________________________
@@ -288,7 +289,9 @@ void AliITSsimulationSPD::SDigitiseModule(AliITSmodule *mod,Int_t,
    InitSimulationModule( GetModuleNumber() , event );
    // HitToSDigit(mod);
    HitToSDigitFast(mod);
-   RemoveDeadPixels(mod);
+  if (fDetType->GetSimuParam()->GetSPDAddNoisyFlag())   AddNoisyPixels();
+  if (fDetType->GetSimuParam()->GetSPDRemoveDeadFlag()) RemoveDeadPixels();
+
 //    cout << "After Remove in SDigitiseModule !!!!!" << endl; // dom
 //    cout << "Module " << mod->GetIndex() << " Event " << event << endl; // dom
    WriteSDigits();
@@ -353,11 +356,13 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod,Int_t,
    //    none.
 
    if (fStrobe) if(event != GetEventNumber()) GenerateStrobePhase();
-   AliDebug(1,Form("(mod=%p,,)",mod));
+   AliDebug(1,Form("(mod=%p,,0)",mod));
    // HitToSDigit(mod);
    InitSimulationModule( mod->GetIndex(), event );
    HitToSDigitFast(mod);
-   RemoveDeadPixels(mod);
+   
+  if (fDetType->GetSimuParam()->GetSPDAddNoisyFlag())   AddNoisyPixels();
+  if (fDetType->GetSimuParam()->GetSPDRemoveDeadFlag()) RemoveDeadPixels();
 //    cout << "After Remove in DigitiseModule in module " << mod->GetIndex() << endl; // dom
    FrompListToDigits();
    ClearMap();
@@ -444,7 +449,7 @@ void AliITSsimulationSPD::HitToSDigit(AliITSmodule *mod){
                if(GetMap()->GetpListItem(i)==0) continue;
                else{
                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
-                   SetCoupling(iz,ix,idtrack,h);
+                   SetCoupling(iz,ix);
                } // end for i
            break;
        case 2: // case 4:
@@ -452,7 +457,7 @@ void AliITSsimulationSPD::HitToSDigit(AliITSmodule *mod){
                if(GetMap()->GetpListItem(i)==0) continue;
                else{
                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
-                   SetCouplingOld(iz,ix,idtrack,h);
+                   SetCouplingOld(iz,ix);
                } // end for i
            break;
        } // end switch
@@ -545,7 +550,7 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
                if(GetMap()->GetpListItem(i)==0) continue;
                else{
                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
-                   SetCoupling(iz,ix,idtrack,h);
+                   SetCoupling(iz,ix);
                } // end for i
            break;
        case 2: // case 4:
@@ -553,7 +558,7 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
                if(GetMap()->GetpListItem(i)==0) continue;
                else{
                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);  
-                   SetCouplingOld(iz,ix,idtrack,h);
+                   SetCouplingOld(iz,ix);
                } // end for i
            break;
        } // end switch
@@ -623,13 +628,13 @@ void AliITSsimulationSPD::SpreadCharge(Double_t x0,Double_t z0,
        z1 -= z0; // Distance from where track traveled
        z2 -= z0; // Distance from where track traveled
        s   = 0.25; // Correction based on definision of Erfc
-       s  *= TMath::Erfc(sp*x1) - TMath::Erfc(sp*x2);
+       s  *= AliMathBase::ErfcFast(sp*x1) - AliMathBase::ErfcFast(sp*x2);
        if(GetDebug(3)){
            cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<
                " iz0="<<iz0<<" iz="<<iz<<" z0="<<z<< 
                " sp*x1="<<sp*x1<<" sp*x2="<<sp*x2<<" s="<<s;
        } // end if GetDebug
-       s  *= TMath::Erfc(sp*z1) - TMath::Erfc(sp*z2);
+       s  *= AliMathBase::ErfcFast(sp*z1) - AliMathBase::ErfcFast(sp*z2);
        if(GetDebug(3)){
            cout<<" sp*z1="<<sp*z1<<" sp*z2="<<sp*z2<<" s="<<s<< endl;
        } // end if GetDebug
@@ -672,7 +677,7 @@ void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
 
 
    if(GetDebug(4)) Info("SpreadChargeAsym","(x0=%e,z0=%e,ix0=%d,iz0=%d,el=%e,"
-                        "sig=%e,t=%d,i=%d)",x0,z0,ix0,iz0,el,sigx,sigz,t,hi);
+                        "sigx=%e, sigz=%e, t=%d,i=%d)",x0,z0,ix0,iz0,el,sigx,sigz,t,hi);
    if(sigx<=0.0 || sigz<=0.0) { // if sig<=0 No diffusion to simulate.
        GetMap()->AddSignal(iz0,ix0,t,hi,GetModuleNumber(),el);
        if(GetDebug(2)){
@@ -703,13 +708,13 @@ void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
        z1 -= z0; // Distance from where track traveled
        z2 -= z0; // Distance from where track traveled
        s   = 0.25; // Correction based on definision of Erfc
-       s  *= TMath::Erfc(spx*x1) - TMath::Erfc(spx*x2);
+       s  *= AliMathBase::ErfcFast(spx*x1) - AliMathBase::ErfcFast(spx*x2);
        if(GetDebug(3)){
            cout <<"el="<<el<<" ix0="<<ix0<<" ix="<<ix<<" x0="<<x<<
                " iz0="<<iz0<<" iz="<<iz<<" z0="<<z<< 
                " spx*x1="<<spx*x1<<" spx*x2="<<spx*x2<<" s="<<s;
        } // end if GetDebug
-       s  *= TMath::Erfc(spz*z1) - TMath::Erfc(spz*z2);
+       s  *= AliMathBase::ErfcFast(spz*z1) - AliMathBase::ErfcFast(spz*z2);
        if(GetDebug(3)){
            cout<<" spz*z1="<<spz*z1<<" spz*z2="<<spz*z2<<" s="<<s<< endl;
        } // end if GetDebug
@@ -717,26 +722,29 @@ void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
    } // end for ix, iz
 }
 //______________________________________________________________________
-void AliITSsimulationSPD::RemoveDeadPixels(AliITSmodule *mod){
-   //    Removes dead pixels on each module (ladder)
-   // Inputs:
-   //    Module Index (0,239)
-   // Outputs:
-   //    none.
-   // Return:
-   //    none.
+void AliITSsimulationSPD::RemoveDeadPixels(){
+  // Removes dead pixels on each module (ladder)
+  // This should be called before going from sdigits to digits (FrompListToDigits)
+  Int_t mod = GetModuleNumber();
+  AliITSCalibrationSPD* calObj = (AliITSCalibrationSPD*) fDetType->GetCalibrationModel(mod);
 
- Int_t moduleNr = mod->GetIndex();
- AliITSCalibrationSPD* calObj = (AliITSCalibrationSPD*) GetCalibrationModel(moduleNr);
+  Int_t nrDead = calObj->GetNrBad();
+  for (Int_t i=0; i<nrDead; i++) {
+    GetMap()->DeleteHit(calObj->GetBadColAt(i), calObj->GetBadRowAt(i));
+  }
+}
+//______________________________________________________________________
+void AliITSsimulationSPD::AddNoisyPixels() {
+  // Adds noisy pixels on each module (ladder)
+  // This should be called before going from sdigits to digits (FrompListToDigits)
+  Int_t mod = GetModuleNumber();
+  AliITSCalibrationSPD* calObj = (AliITSCalibrationSPD*) fDetType->GetSPDNoisyModel(mod);
 
- Int_t nrDead = calObj->GetNrBad();
-//  cout << "Module --> " << moduleNr << endl; // dom
-//  cout << "nr of dead " << nrDead << endl; // dom
- for (Int_t i=0; i<nrDead; i++) {
-   GetMap()->DeleteHit(calObj->GetBadColAt(i),calObj->GetBadRowAt(i));
-//    cout << "dead index " << i << endl; // dom
-//    cout << "col row --> " << calObj->GetDeadColAt(i) << " " << calObj->GetDeadRowAt(i) << endl; // dom
- }
+  Int_t nrNoisy = calObj->GetNrBad();
+  for (Int_t i=0; i<nrNoisy; i++) {
+    // adding 10 times the threshold will for sure make this pixel fire...
+    GetMap()->AddNoise(calObj->GetBadColAt(i), calObj->GetBadRowAt(i), mod, 10*GetThreshold());
+  }
 }
 //______________________________________________________________________
 void AliITSsimulationSPD::FrompListToDigits(){
@@ -783,7 +791,8 @@ void AliITSsimulationSPD::FrompListToDigits(){
            cout<<sig<<"+"<<electronics<<">threshold("<<ix<<","<<iz
                <<")="<<GetThreshold() <<endl;
        } // end if GetDebug
-       if (sig+electronics <= GetThreshold()) continue;
+      // if (sig+electronics <= GetThreshold()) continue;
+       if (GetMap()->GetSignal(iz,ix) <= GetThreshold()) continue;
        dig.SetCoord1(iz);
        dig.SetCoord2(ix);
        dig.SetSignal(1);
@@ -811,6 +820,8 @@ void AliITSsimulationSPD::FrompListToDigits(){
            cout<<iz<<","<<ix<<","<<*(GetMap()->GetpListItem(iz,ix))<<endl;
        } // end if GetDebug
        aliITS->AddSimDigit(0,&dig);
+       // simulate fo signal response for this pixel hit:
+       fDetType->ProcessSPDDigitForFastOr(fModule, dig.GetCoord1(), dig.GetCoord2());
    } //  for ix/iz
 }
 //______________________________________________________________________
@@ -829,7 +840,7 @@ void AliITSsimulationSPD::CreateHistograms(){
    fSPDname="spd_";
    for(Int_t i=0;i<GetNPixelsZ();i++) {
        Char_t pixelz[4];
-       sprintf(pixelz,"%d",i);
+       snprintf(pixelz,3,"%d",i);
        fSPDname.Append(pixelz);
        fHis->AddAt(new TH1F(fSPDname.Data(),"SPD maps",
                             GetNPixelsX(),0.,(Double_t)GetNPixelsX()),i);
@@ -867,8 +878,7 @@ void AliITSsimulationSPD::ResetHistograms(){
 }
 
 //______________________________________________________________________
-void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
-                                     Int_t idhit) {
+void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row) {
    //  Take into account the coupling between adiacent pixels.
    //  The parameters probcol and probrow are the probability of the
    //  signal in one pixel shared in the two adjacent pixels along
@@ -889,8 +899,6 @@ void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
    // Inputs:
    //    Int_t col            z cell index
    //    Int_t row            x cell index
-   //    Int_t ntrack         track incex number
-   //    Int_t idhit          hit index number
    // Outputs:
    //    none.
    // Return:
@@ -901,9 +909,9 @@ void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
    Double_t xr=0.;
 
    GetCouplings(couplC,couplR);
-   if(GetDebug(3)) Info("SetCoupling","(col=%d,row=%d,ntrack=%d,idhit=%d) "
+   if(GetDebug(3)) Info("SetCoupling","(col=%d,row=%d) "
                         "Calling SetCoupling couplC=%e couplR=%e",
-                        col,row,ntrack,idhit,couplC,couplR);
+                        col,row,couplC,couplR);
    j1 = col;
    j2 = row;
    pulse1 = GetMap()->GetSignalOnly(col,row);
@@ -916,7 +924,7 @@ void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
                j1 = col;
                flag = 1;
            }else{
-               UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
+               UpdateMapNoise(row,j1,pulse1);
                //  flag = 0;
                flag = 1; // only first next!!
            } // end if
@@ -929,7 +937,7 @@ void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
                j2 = row;
                flag = 1;
            }else{
-               UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
+               UpdateMapNoise(j2,col,pulse2);
                //  flag = 0;
                flag = 1; // only first next!!
            } // end if
@@ -937,8 +945,7 @@ void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
    } // for isign
 }
 //______________________________________________________________________
-void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
-               Int_t ntrack,Int_t idhit) {
+void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row) {
    //  Take into account the coupling between adiacent pixels.
    //  The parameters probcol and probrow are the fractions of the
    //  signal in one pixel shared in the two adjacent pixels along
@@ -957,8 +964,6 @@ void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
    // Inputs:
    //    Int_t col            z cell index
    //    Int_t row            x cell index
-   //    Int_t ntrack         track incex number
-   //    Int_t idhit          hit index number
    //    Int_t module         module number
    // Outputs:
    //    none.
@@ -974,9 +979,9 @@ void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
 //    cout << "Threshold --> " << GetThreshold() << endl;  // dom
 //    cout << "Couplings --> " << couplC << " " << couplR << endl;  // dom
 
-   if(GetDebug(3)) Info("SetCouplingOld","(col=%d,row=%d,ntrack=%d,idhit=%d) "
+   if(GetDebug(3)) Info("SetCouplingOld","(col=%d,row=%d) "
                         "Calling SetCoupling couplC=%e couplR=%e",
-                        col,row,ntrack,idhit,couplC,couplR);
+                        col,row,couplC,couplR);
    for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
    pulse1 = GetMap()->GetSignalOnly(col,row);
    pulse2 = pulse1;
@@ -990,7 +995,7 @@ void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
                j1 = col;
                flag = 1;
            }else{
-               UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
+               UpdateMapNoise(row,j1,pulse1);
                // flag = 0;
                flag = 1;  // only first next !!
            } // end if
@@ -1004,7 +1009,7 @@ void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
                j2 = row;
                flag = 1;
            }else{
-               UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
+               UpdateMapNoise(j2,col,pulse2);
                // flag = 0;
                flag = 1; // only first next!!
            } // end if