]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSsimulationSPD.cxx
Fixing some problems in the CDB access (Alberto)
[u/mrichter/AliRoot.git] / ITS / AliITSsimulationSPD.cxx
index 7c74648794b6890a4796eb87c010005ad52bf145..35301a979060a709cfb5248bf2913981403e9f5e 100644 (file)
@@ -19,14 +19,9 @@ $Id$
 
 #include <Riostream.h>
 #include <TH1.h>
-#include <TMath.h>
-#include <TParticle.h>
-#include <TRandom.h>
 #include <TString.h>
 #include "AliITS.h"
-#include "AliITSMapA2.h" 
 #include "AliITSdigitSPD.h"
-#include "AliITSgeom.h"
 #include "AliITShit.h"
 #include "AliITSmodule.h"
 #include "AliITSpList.h"
@@ -35,13 +30,16 @@ $Id$
 #include "AliITSsimulationSPD.h"
 #include "AliLog.h"
 #include "AliRun.h"
+#include "AliCDBEntry.h"
+#include "AliCDBLocal.h"
 
 //#define DEBUG
 
 ClassImp(AliITSsimulationSPD)
 ////////////////////////////////////////////////////////////////////////
 //  Version: 1
-//  Modified by Bjorn S. Nilsen, G.E. Bruno, H. Tydesjo
+//  Modified by D. Elia, G.E. Bruno, H. Tydesjo 
+//  Fast diffusion code by Bjorn S. Nilsen
 //  March-April 2006
 //
 //  Version: 0
@@ -193,22 +191,37 @@ AliITSsimulation&  AliITSsimulationSPD::operator=(const
 
 //______________________________________________________________________
 void AliITSsimulationSPD::GetCalibrationObjects(Int_t RunNr) {
+    //    Gets the calibration objects for each module (ladder) 
+    // Inputs:
+    //    RunNr: hard coded to RunNr=0 for now
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
+
   AliCDBManager* man = AliCDBManager::Instance();
-  if(!man->IsDefaultStorageSet()) {
-    man->SetDefaultStorage("local://$ALICE_ROOT");
-  }
-  AliCDBEntry *entrySPD = man->Get("ITS/Calib/CalibSPD", RunNr);
+
+  AliCDBEntry *entrySPD=0;
+  entrySPD = man->Get("ITS/Calib/CalibSPD", RunNr);
+
   if(!entrySPD){
-    AliWarning("Cannot find SPD calibration entry!");
-    return;
+    AliWarning("Cannot find SPD calibration entry in default storage! Using local storage $ALICE_ROOT");
+    AliCDBStorage *localStor = 
+               AliCDBManager::Instance()->GetStorage("local://$ALICE_ROOT");
+    entrySPD = localStor->Get("ITS/Calib/CalibSPD", RunNr);
+    if(!entrySPD){
+      AliFatal("Cannot find SPD calibration entry!");
+      return;
+    }
   }
+  
   TObjArray *respSPD = (TObjArray *)entrySPD->GetObject();
   if ((! respSPD)) {
-    AliWarning("Cannot get data from SPD database entry!");
+    AliFatal("Cannot get data from SPD database entry!");
     return;
   }
   for (Int_t mod=0; mod<240; mod++) {
-    calObj[mod] = (AliITSCalibrationSPD*) respSPD->At(mod);
+    fCalObj[mod] = (AliITSCalibrationSPD*) respSPD->At(mod);
   }
 }
 
@@ -254,6 +267,9 @@ void AliITSsimulationSPD::SDigitiseModule(AliITSmodule *mod,Int_t,
     SetEventNumber(event);
     // HitToSDigit(mod);
     HitToSDigitFast(mod);
+    RemoveDeadPixels(mod);
+//    cout << "After Remove in SDigitiseModule !!!!!" << endl; // dom
+//    cout << "Module " << mod->GetIndex() << " Event " << event << endl; // dom
     WriteSDigits();
     ClearMap();
 }
@@ -270,9 +286,11 @@ void AliITSsimulationSPD::WriteSDigits(){
     static AliITS *aliITS = (AliITS*)gAlice->GetModule("ITS");
 
     AliDebug(1,Form("Writing SDigits for module %d",GetModuleNumber()));
+//    cout << "WriteSDigits for module " << GetModuleNumber() << endl; // dom
     GetMap()->GetMaxMapIndex(niz, nix);
     for(iz=0; iz<niz; iz++)for(ix=0; ix<nix; ix++){
         if(GetMap()->GetSignalOnly(iz,ix)>0.0){
+//            cout << " Signal gt 0  iz ix " << iz << ix << " Module " << GetModuleNumber() << endl; // dom
             aliITS->AddSumDigit(*(GetMap()->GetpListItem(iz,ix)));
            if(AliDebugLevel()>0) {
              AliDebug(1,Form("%d, %d",iz,ix));
@@ -293,7 +311,8 @@ void AliITSsimulationSPD::FinishSDigitiseModule(){
     //    none
 
     AliDebug(1,"()");
-    pListToDigits(); // Charge To Signal both adds noise and
+//    cout << "FinishSDigitiseModule for module " << GetModuleNumber() << endl; // dom
+    FrompListToDigits(); // Charge To Signal both adds noise and
     ClearMap();
     return;
 }
@@ -316,7 +335,8 @@ void AliITSsimulationSPD::DigitiseModule(AliITSmodule *mod,Int_t,
     // HitToSDigit(mod);
     HitToSDigitFast(mod);
     RemoveDeadPixels(mod);
-    pListToDigits();
+//    cout << "After Remove in DigitiseModule in module " << mod->GetIndex() << endl; // dom
+    FrompListToDigits();
     ClearMap();
 }
 //______________________________________________________________________
@@ -388,22 +408,18 @@ void AliITSsimulationSPD::HitToSDigit(AliITSmodule *mod){
         default:
             break;
         case 1: //case 3:
-            // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
             for(i=0;i<GetMap()->GetEntries();i++) 
                 if(GetMap()->GetpListItem(i)==0) continue;
                 else{
-                    GetMap()->GetMapIndex(
-                              GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
                     SetCoupling(iz,ix,idtrack,h);
                 } // end for i
             break;
         case 2: // case 4:
-            // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
             for(i=0;i<GetMap()->GetEntries();i++) 
                 if(GetMap()->GetpListItem(i)==0) continue;
                 else{
-                    GetMap()->GetMapIndex(
-                                GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
                     SetCouplingOld(iz,ix,idtrack,h);
                 } // end for i
             break;
@@ -420,12 +436,12 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
     // Return:
     //    none.
     const Double_t kmictocm = 1.0e-4; // convert microns to cm.
-    const Int_t n10=10;
-    const Double_t ti[n10]={7.443716945e-3,2.166976971e-1,3.397047841e-1,
+    const Int_t kn10=10;
+    const Double_t kti[kn10]={7.443716945e-3,2.166976971e-1,3.397047841e-1,
                             4.325316833e-1,4.869532643e-1,5.130467358e-1,
                             5.674683167e-1,6.602952159e-1,7.833023029e-1,
                             9.255628306e-1};
-    const Double_t wi[n10]={1.477621124e-1,1.346333597e-1,1.095431813e-1,
+    const Double_t kwi[kn10]={1.477621124e-1,1.346333597e-1,1.095431813e-1,
                             7.472567455e-2,3.333567215e-2,3.333567215e-2,
                             7.472567455e-2,1.095431813e-1,1.346333597e-1,
                             1.477621124e-1};
@@ -451,17 +467,17 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
       } // end if GetDebug
         if(!mod->LineSegmentL(h,x0,x1,y0,y1,z0,z1,de,idtrack)) continue;
         st = TMath::Sqrt(x1*x1+y1*y1+z1*z1);
-        if(st>0.0) for(i=0;i<n10;i++){ // Integrate over t
-            t   = ti[i];
+        if(st>0.0) for(i=0;i<kn10;i++){ // Integrate over t
+            t   = kti[i];
             x   = x0+x1*t;
             y   = y0+y1*t;
             z   = z0+z1*t;
                 if(!(seg->LocalToDet(x,z,ix,iz))) continue; // outside
                 // el  = res->GeVToCharge((Double_t)(dt*de));
-                // el  = 1./n10*res->GeVToCharge((Double_t)de);
-                el  = wi[i]*res->GeVToCharge((Double_t)de); 
+                // el  = 1./kn10*res->GeVToCharge((Double_t)de);
+                el  = kwi[i]*res->GeVToCharge((Double_t)de); 
                 if(GetDebug(1)){
-                    if(el<=0.0) cout<<"el="<<el<<" wi["<<i<<"]="<<wi[i]
+                    if(el<=0.0) cout<<"el="<<el<<" kwi["<<i<<"]="<<kwi[i]
                                     <<" de="<<de<<endl;
                 } // end if GetDebug
                 sig = res->SigmaDiffusion1D(TMath::Abs(thick + y));
@@ -488,22 +504,19 @@ void AliITSsimulationSPD::HitToSDigitFast(AliITSmodule *mod){
         default:
             break;
         case 1: // case 3:
-            // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
             for(i=0;i<GetMap()->GetEntries();i++)
                 if(GetMap()->GetpListItem(i)==0) continue;
                 else{
-                    GetMap()->GetMapIndex(
-                              GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
+                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);
                     SetCoupling(iz,ix,idtrack,h);
                 } // end for i
             break;
         case 2: // case 4:
-            // x is column and z is row (see AliITSsegmentationSPD::GetPadIxz)
             for(i=0;i<GetMap()->GetEntries();i++)
                 if(GetMap()->GetpListItem(i)==0) continue;
                 else{
-                    GetMap()->GetMapIndex(
-                                GetMap()->GetpListItem(i)->GetIndex(),iz,ix);                    SetCouplingOld(iz,ix,idtrack,h);
+                    GetMap()->GetMapIndex(GetMap()->GetpListItem(i)->GetIndex(),iz,ix);  
+                    SetCouplingOld(iz,ix,idtrack,h);
                 } // end for i
             break;
         } // end switch
@@ -667,14 +680,22 @@ void AliITSsimulationSPD::SpreadChargeAsym(Double_t x0,Double_t z0,
 }
 //______________________________________________________________________
 void AliITSsimulationSPD::RemoveDeadPixels(AliITSmodule *mod){
-  Int_t module_nr = mod->GetIndex();
-  Int_t nr_dead = calObj[module_nr]->GetNrDead();
-  for (Int_t i=0; i<nr_dead; i++) {
-    GetMap()->DeleteHit(calObj[module_nr]->GetDeadColAt(i),calObj[module_nr]->GetDeadRowAt(i));
+    //    Removes dead pixels on each module (ladder)
+    // Inputs:
+    //    Module Index (0,239)
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
+
+  Int_t moduleNr = mod->GetIndex();
+  Int_t nrDead = fCalObj[moduleNr]->GetNrDead();
+  for (Int_t i=0; i<nrDead; i++) {
+    GetMap()->DeleteHit(fCalObj[moduleNr]->GetDeadColAt(i),fCalObj[moduleNr]->GetDeadRowAt(i));
   }
 }
 //______________________________________________________________________
-void AliITSsimulationSPD::pListToDigits(){
+void AliITSsimulationSPD::FrompListToDigits(){
     // add noise and electronics, perform the zero suppression and add the
     // digit to the list
     // Inputs:
@@ -687,10 +708,10 @@ void AliITSsimulationSPD::pListToDigits(){
     Int_t j,ix,iz;
     Double_t  electronics;
     Double_t sig;
-    const Int_t    nmaxtrk=AliITSdigitSPD::GetNTracks();
+    const Int_t    knmaxtrk=AliITSdigitSPD::GetNTracks();
     static AliITSdigitSPD dig;
     AliITSCalibrationSPD* res = (AliITSCalibrationSPD*)GetCalibrationModel(fDetType->GetITSgeom()->GetStartSPD());
-    if(GetDebug(1)) Info("pListToDigits","()");
+    if(GetDebug(1)) Info("FrompListToDigits","()");
     for(iz=0; iz<GetNPixelsZ(); iz++) for(ix=0; ix<GetNPixelsX(); ix++){
 // NEW (for the moment plugged by hand, in the future possibly read from Data Base)
 // here parametrize the efficiency of the pixel along the row for the test columns (1,9,17,25)
@@ -722,15 +743,18 @@ void AliITSsimulationSPD::pListToDigits(){
         dig.SetCoord1(iz);
         dig.SetCoord2(ix);
         dig.SetSignal(1);
-       Double_t aSignal =  GetMap()->GetSignal(iz,ix);
-       if (TMath::Abs(aSignal)>2147483647.0) { 
-         //PH 2147483647 is the max. integer
-         //PH This apparently is a problem which needs investigation
-         AliWarning(Form("Too big or too small signal value %f",aSignal));
-         aSignal = TMath::Sign((Double_t)2147483647,aSignal);
-       }
-       dig.SetSignalSPD((Int_t)aSignal); 
-        for(j=0;j<nmaxtrk;j++){
+
+//        dig.SetSignalSPD((Int_t) GetMap()->GetSignal(iz,ix));
+        Double_t aSignal =  GetMap()->GetSignal(iz,ix);
+        if (TMath::Abs(aSignal)>2147483647.0) {
+          //PH 2147483647 is the max. integer
+          //PH This apparently is a problem which needs investigation
+          AliWarning(Form("Too big or too small signal value %f",aSignal));
+          aSignal = TMath::Sign((Double_t)2147483647,aSignal);
+        }
+        dig.SetSignalSPD((Int_t)aSignal);
+
+        for(j=0;j<knmaxtrk;j++){
             if (j<GetMap()->GetNEntries()) {
                 dig.SetTrack(j,GetMap()->GetTrack(iz,ix,j));
                 dig.SetHit(j,GetMap()->GetHit(iz,ix,j));
@@ -799,7 +823,7 @@ void AliITSsimulationSPD::ResetHistograms(){
 }
 
 //______________________________________________________________________
-void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
+void AliITSsimulationSPD::SetCoupling(Int_t col, Int_t row, Int_t ntrack,
                                      Int_t idhit) {
     //  Take into account the coupling between adiacent pixels.
     //  The parameters probcol and probrow are the probability of the
@@ -819,8 +843,8 @@ void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
     */
     //End_Html
     // Inputs:
-    //    Int_t row            z cell index
-    //    Int_t col            x cell index
+    //    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:
@@ -833,39 +857,35 @@ void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
     Double_t xr=0.;
 
     GetCouplings(couplC,couplR);
-    if(GetDebug(3)) Info("SetCoupling","(row=%d,col=%d,ntrack=%d,idhit=%d) "
-                         "Calling SetCoupling couplR=%e couplC=%e",
-                         row,col,ntrack,idhit,couplR,couplC);
-    j1 = row;
-    j2 = col;
-    pulse1 = GetMap()->GetSignalOnly(row,col);
+    if(GetDebug(3)) Info("SetCoupling","(col=%d,row=%d,ntrack=%d,idhit=%d) "
+                         "Calling SetCoupling couplC=%e couplR=%e",
+                         col,row,ntrack,idhit,couplC,couplR);
+    j1 = col;
+    j2 = row;
+    pulse1 = GetMap()->GetSignalOnly(col,row);
     pulse2 = pulse1;
-    for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
+    for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
         do{
             j1 += isign;
-            //   pulse1 *= couplR; 
             xr = gRandom->Rndm();
-            //if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold())){
-            if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplR)){
-                j1 = row;
+            if ((j1<0) || (j1>GetNPixelsZ()-1) || (xr>couplC)){
+                j1 = col;
                 flag = 1;
             }else{
-                UpdateMapSignal(col,j1,ntrack,idhit,pulse1);
+                UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
                 //  flag = 0;
                 flag = 1; // only first next!!
             } // end if
         } while(flag == 0);
-        // loop in column direction
+        // loop in row direction
         do{
             j2 += isign;
-            // pulse2 *= couplC; 
             xr = gRandom->Rndm();
-            //if((j2<0)||j2>(GetNPixelsX()-1)||pulse2<GetThreshold()){
-            if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplC)){
-                j2 = col;
+            if ((j2<0) || (j2>GetNPixelsX()-1) || (xr>couplR)){
+                j2 = row;
                 flag = 1;
             }else{
-                UpdateMapSignal(j2,row,ntrack,idhit,pulse2);
+                UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
                 //  flag = 0;
                 flag = 1; // only first next!!
             } // end if
@@ -873,7 +893,7 @@ void AliITSsimulationSPD::SetCoupling(Int_t row, Int_t col, Int_t ntrack,
     } // for isign
 }
 //______________________________________________________________________
-void AliITSsimulationSPD::SetCouplingOld(Int_t row, Int_t col,
+void AliITSsimulationSPD::SetCouplingOld(Int_t col, Int_t row,
                 Int_t ntrack,Int_t idhit) {
     //  Take into account the coupling between adiacent pixels.
     //  The parameters probcol and probrow are the fractions of the
@@ -891,8 +911,8 @@ void AliITSsimulationSPD::SetCouplingOld(Int_t row, Int_t col,
     */
     //End_Html
     // Inputs:
-    //    Int_t row            z cell index
-    //    Int_t col            x cell index
+    //    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
@@ -911,37 +931,37 @@ void AliITSsimulationSPD::SetCouplingOld(Int_t row, Int_t col,
 //    cout << "Couplings --> " << couplC << " " << couplR << endl;  //dom
 
 
-    if(GetDebug(3)) Info("SetCouplingOld","(row=%d,col=%d,ntrack=%d,idhit=%d) "
-                         "Calling SetCoupling couplR=%e couplC=%e",
-                         row,col,ntrack,idhit,couplR,couplC);
-    for (Int_t isign=-1;isign<=1;isign+=2){// loop in row direction
-    pulse1 = GetMap()->GetSignalOnly(row,col);
+    if(GetDebug(3)) Info("SetCouplingOld","(col=%d,row=%d,ntrack=%d,idhit=%d) "
+                         "Calling SetCoupling couplC=%e couplR=%e",
+                         col,row,ntrack,idhit,couplC,couplR);
+    for (Int_t isign=-1;isign<=1;isign+=2){// loop in col direction
+    pulse1 = GetMap()->GetSignalOnly(col,row);
     pulse2 = pulse1;
-    j1 = row;
-    j2 = col;
+    j1 = col;
+    j2 = row;
         do{
             j1 += isign;
-            pulse1 *= couplR;
+            pulse1 *= couplC;
             if ((j1<0)||(j1>GetNPixelsZ()-1)||(pulse1<GetThreshold())){
-                pulse1 = GetMap()->GetSignalOnly(row,col);
-                j1 = row;
+                pulse1 = GetMap()->GetSignalOnly(col,row);
+                j1 = col;
                 flag = 1;
             }else{
-                UpdateMapSignal(col,j1,ntrack,idhit,pulse1);
+                UpdateMapSignal(row,j1,ntrack,idhit,pulse1);
                 // flag = 0;
                 flag = 1;  // only first next !!
             } // end if
         } while(flag == 0);
-        // loop in column direction
+        // loop in row direction
         do{
             j2 += isign;
-            pulse2 *= couplC;
+            pulse2 *= couplR;
             if((j2<0)||(j2>(GetNPixelsX()-1))||(pulse2<GetThreshold())){
-                pulse2 = GetMap()->GetSignalOnly(row,col);
-                j2 = col;
+                pulse2 = GetMap()->GetSignalOnly(col,row);
+                j2 = row;
                 flag = 1;
             }else{
-                UpdateMapSignal(j2,row,ntrack,idhit,pulse2);
+                UpdateMapSignal(j2,col,ntrack,idhit,pulse2);
                 // flag = 0;
                 flag = 1; // only first next!!
             } // end if