]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCDigitizer.cxx
Update TPCCEda to write output file in parts (to avoid too big files produced in...
[u/mrichter/AliRoot.git] / TPC / AliTPCDigitizer.cxx
index 252cfdbb7eed1897a5d0f7c2f34ddb4a7b65bf58..ed62f3033bc403eb67d424ea2ab9cb82a797606e 100644 (file)
 
 /* $Id$ */
 
+/*
+  Class for creating of the sumable digits and digits from MC data
+  //
+  The input :  ideal signals (Hits->Diffusion->Attachment -Ideal signal)
+  The output:  raw digits
+
+  Effect implemented:
+  1. Pad by pad gain map
+  2. Noise map
+  3. The dead channels identified  - zerro noise for corresponding pads
+     In this case the outpu equal zerro
+*/
+
+
+
+
 #include <stdlib.h>
 #include <TTree.h> 
 #include <TObjArray.h>
 #include <TFile.h>
 #include <TDirectory.h>
 #include <Riostream.h>
+#include <TParameter.h>
 
 #include "AliTPCDigitizer.h"
 
 #include "AliPDG.h"
 #include "AliRunDigitizer.h"
 #include "AliSimDigits.h"
+#include "AliLog.h"
 
+#include "AliTPCcalibDB.h"
+#include "AliTPCCalPad.h"
+#include "AliTPCCalROC.h"
 
 ClassImp(AliTPCDigitizer)
 
 //___________________________________________
-AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer()
+  AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer(),fDebug(0)
 {
+  //
 // Default ctor - don't use it
-  fDebug =0;
+//
+  
 }
 
 //___________________________________________
 AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager) 
-    :AliDigitizer(manager)
+  :AliDigitizer(manager),fDebug(0)
 {
+  //
 // ctor which should be used
-  fDebug =0;
-  if (GetDebug()>2) 
-    cerr<<"AliTPCDigitizer::AliTPCDigitizer"
-       <<"(AliRunDigitizer* manager) was processed"<<endl;
+//  
+  AliDebug(2,"(AliRunDigitizer* manager) was processed");
 }
 
 //------------------------------------------------------------------------
@@ -84,7 +107,7 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
   char s[100]; 
   char ss[100];
   TString optionString = option;
-  if (optionString.Data() == "deb") {
+  if (!strcmp(optionString.Data(),"deb")) {
     cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
     fDebug = 3;
   }
@@ -124,20 +147,33 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
    }
   }
   
-  pTPC->GenerNoise(500000); //create teble with noise
+  pTPC->GenerNoise(500000); //create table with noise
   //
   Int_t nInputs = fManager->GetNinputs();
   Int_t * masks = new Int_t[nInputs];
   for (Int_t i=0; i<nInputs;i++)
     masks[i]= fManager->GetMask(i);
   Short_t **pdig= new Short_t*[nInputs];   //pointers to the expanded digits array
-  Int_t **ptr=  new Int_t*[nInputs];       //pointers to teh expanded tracks array
+  Int_t **ptr=  new Int_t*[nInputs];       //pointers to the expanded tracks array
   Bool_t *active=  new Bool_t[nInputs];    //flag for active input segments
-
+  Char_t phname[100];
   
   //create digits array for given sectors
   // make indexes
-  
+  //
+  //create branch's in TPC treeD
+  orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
+  ogime = orl->GetLoader("TPCLoader");
+  TTree * tree  = ogime->TreeD();
+  AliSimDigits * digrow = new AliSimDigits;  
+
+  if (tree == 0x0)
+   {
+     ogime->MakeTree("D");
+     tree  = ogime->TreeD();
+   }
+  tree->Branch("Segment","AliSimDigits",&digrow);
+  //  
   AliSimDigits ** digarr = new AliSimDigits*[nInputs]; 
   for (Int_t i1=0;i1<nInputs; i1++)
     {
@@ -154,31 +190,32 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
             <<" input "<< i1<<endl;
         return;
        }
-    
+
+      sprintf(phname,"lhcphase%d",i1);
+      TParameter<float> *ph = (TParameter<float>*)treear->GetUserInfo()
+                              ->FindObject("lhcphase0");
+      if(!ph){
+        cerr<<"AliTPCDigitizer: LHC phase  not found in"
+            <<" input "<< i1<<endl;
+        return;
+      }
+      tree->GetUserInfo()->Add(new TParameter<float>(phname,ph->GetVal()));
+             //
       if (treear->GetIndex()==0)  
        treear->BuildIndex("fSegmentID","fSegmentID");
       treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
     }
 
 
-  //create branch's in TPC treeD
-  AliSimDigits * digrow = new AliSimDigits;
 
-  orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
-  ogime = orl->GetLoader("TPCLoader");
-  
-  TTree * tree  = ogime->TreeD();
-  if (tree == 0x0)
-   {
-     ogime->MakeTree("D");
-     tree  = ogime->TreeD();
-   }
-  TBranch* branch = tree->Branch("Segment","AliSimDigits",&digrow);
+
   //
 
   param->SetZeroSup(2);
 
   Int_t zerosup = param->GetZeroSup(); 
+  AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor(); 
+  AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise(); 
   //
   //Loop over segments of the TPC
     
@@ -190,7 +227,8 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
       cerr<<"AliTPC warning: invalid segment ID ! "<<segmentID<<endl;
       continue;
      }
-
+    AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec);  // pad gains per given sector
+    AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(sec);  // noise per given sector
     digrow->SetID(segmentID);
 
     Int_t nrows = 0;
@@ -262,13 +300,19 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
            ptr[i]++;
          }
         q/=16.;  //conversion factor
+       Float_t gain = gainROC->GetValue(row,elem/nrows);  // get gain for given - pad-row pad
+       //if (gain<0.5){
+         //printf("problem\n");
+       //}
+       q*= gain;
+       Float_t noisePad = noiseROC->GetValue(row,elem/nrows);
         //       Float_t noise  = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());  
         Float_t noise  = pTPC->GetNoise();
-        q+=noise;
+        q+=noise*noisePad;
         q=TMath::Nint(q);
         if (q > zerosup)
          { 
-          if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
+          if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1);
           //digrow->SetDigitFast((Short_t)q,rows,col);  
           *pdig1 =Short_t(q);
           for (Int_t tr=0;tr<3;tr++)
@@ -280,10 +324,13 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
         pdig1++;
         ptr1++;
      }
-    
+    //
+    //  glitch filter
+    //
+    digrow->GlitchFilter();
+    //
     digrow->CompresBuffer(1,zerosup);
     digrow->CompresTrackBuffer(1);
-    branch->SetAddress(&digrow);
     tree->Fill();
     if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";  
    } //for (Int_t n=0; n<param->GetNRowsTotal(); n++) 
@@ -314,7 +361,7 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
   //output stored in TreeTPCD
 
   TString optionString = option;
-  if (optionString.Data() == "deb") {
+  if (!strcmp(optionString.Data(),"deb")) {
     cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
     fDebug = 3;
   }
@@ -374,6 +421,8 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
   Int_t zerosup = param->GetZeroSup();
   //Loop over segments of the TPC
     
+  AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
+  AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
   for (Int_t n=0; n<nentries; n++) {
     rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
     gime = rl->GetLoader("TPCLoader");
@@ -381,7 +430,8 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
 
     digarr[0]->ExpandBuffer();
     digarr[0]->ExpandTrackBuffer();
-           
+
+
     for (Int_t i=1;i<nInputs; i++){ 
 //      fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());      
       rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
@@ -400,6 +450,8 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
       continue;
     }
 
+    AliTPCCalROC * gainROC = gainTPC->GetCalROC(sec);  // pad gains per given sector
+    AliTPCCalROC * noiseROC = noiseTPC->GetCalROC(sec);  // noise per given sector
     digrow->SetID(digarr[0]->GetID());
 
     Int_t nrows = digarr[0]->GetNRows();
@@ -437,12 +489,17 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
         }
        q/=16.;  //conversion factor
        //       Float_t noise  = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());  
+       Float_t gain = gainROC->GetValue(row,col);
+       q*= gain;
+       Float_t noisePad = noiseROC->GetValue(row, col);
+
        Float_t noise  = pTPC->GetNoise();
-       q+=noise;
+       q+=noise*noisePad;
+
         q=TMath::Nint(q);
         if (q > zerosup){ 
          
-         if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
+         if(q >= param->GetADCSat()) q = (Short_t)(param->GetADCSat() - 1);
          digrow->SetDigitFast((Short_t)q,rows,col);  
          // *pdig1 =Short_t(q);
          for (Int_t tr=0;tr<3;tr++){
@@ -478,6 +535,6 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
     
   delete digrow;     
   for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
-  delete []masks;
-  delete digarr;  
+  delete [] masks;
+  delete [] digarr;  
 }