]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCDigitizer.cxx
Add a task to a train
[u/mrichter/AliRoot.git] / TPC / AliTPCDigitizer.cxx
index ed62f3033bc403eb67d424ea2ab9cb82a797606e..0bee1a63e1220323577af7844a6a0be697d2faa3 100644 (file)
@@ -46,8 +46,9 @@
 #include "AliTPCParam.h"
 #include "AliTPCParamSR.h" 
 #include "AliRun.h"
+#include "AliLoader.h"
 #include "AliPDG.h"
-#include "AliRunDigitizer.h"
+#include "AliDigitizationInput.h"
 #include "AliSimDigits.h"
 #include "AliLog.h"
 
@@ -67,13 +68,13 @@ ClassImp(AliTPCDigitizer)
 }
 
 //___________________________________________
-AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager
-  :AliDigitizer(manager),fDebug(0)
+AliTPCDigitizer::AliTPCDigitizer(AliDigitizationInput* digInput
+  :AliDigitizer(digInput),fDebug(0)
 {
   //
 // ctor which should be used
 //  
-  AliDebug(2,"(AliRunDigitizer* manager) was processed");
+  AliDebug(2,"(AliDigitizationInput* digInput) was processed");
 }
 
 //------------------------------------------------------------------------
@@ -94,12 +95,12 @@ Bool_t AliTPCDigitizer::Init()
 
 
 //------------------------------------------------------------------------
-void AliTPCDigitizer::Exec(Option_t* option)
+void AliTPCDigitizer::Digitize(Option_t* option)
 {
-  ExecFast(option);  
+  DigitizeFast(option);  
 }
 //------------------------------------------------------------------------
-void AliTPCDigitizer::ExecFast(Option_t* option)
+void AliTPCDigitizer::DigitizeFast(Option_t* option)
 {
   
   // merge input tree's with summable digits
@@ -108,7 +109,7 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
   char ss[100];
   TString optionString = option;
   if (!strcmp(optionString.Data(),"deb")) {
-    cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
+    cout<<"AliTPCDigitizer:::DigitizeFast called with option deb "<<endl;
     fDebug = 3;
   }
   //get detector and geometry
@@ -119,11 +120,11 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
   
   if (gAlice == 0x0)
    {
-     Warning("ExecFast","gAlice is NULL. Loading from input 0");
-     rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
+     Warning("DigitizeFast","gAlice is NULL. Loading from input 0");
+     rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(0));
      if (rl == 0x0)
       {
-        Error("ExecFast","Can not find Run Loader for input 0. Can not proceed.");
+        Error("DigitizeFast","Can not find Run Loader for input 0. Can not proceed.");
         return;
       }
      rl->LoadgAlice();
@@ -132,15 +133,18 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
   AliTPC *pTPC  = (AliTPC *) gAlice->GetModule("TPC");
   AliTPCParam * param = pTPC->GetParam();
   
-  sprintf(s,param->GetTitle());
-  sprintf(ss,"75x40_100x60");
+  //sprintf(s,param->GetTitle());
+  snprintf(s,100,"%s",param->GetTitle());
+  //sprintf(ss,"75x40_100x60");
+  snprintf(ss,100,"75x40_100x60");
   if(strcmp(s,ss)==0){
     printf("2 pad-length geom hits with 3 pad-lenght geom digits...\n");
     delete param;
     param=new AliTPCParamSR();
   }
   else{
-   sprintf(ss,"75x40_100x60_150x60");
+    //sprintf(ss,"75x40_100x60_150x60");
+    snprintf(ss,100,"75x40_100x60_150x60");
    if(strcmp(s,ss)!=0) {
      printf("No TPC parameters found...\n");
      exit(2); 
@@ -149,10 +153,10 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
   
   pTPC->GenerNoise(500000); //create table with noise
   //
-  Int_t nInputs = fManager->GetNinputs();
+  Int_t nInputs = fDigInput->GetNinputs();
   Int_t * masks = new Int_t[nInputs];
   for (Int_t i=0; i<nInputs;i++)
-    masks[i]= fManager->GetMask(i);
+    masks[i]= fDigInput->GetMask(i);
   Short_t **pdig= new Short_t*[nInputs];   //pointers to the expanded digits 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
@@ -162,7 +166,7 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
   // make indexes
   //
   //create branch's in TPC treeD
-  orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
+  orl = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
   ogime = orl->GetLoader("TPCLoader");
   TTree * tree  = ogime->TreeD();
   AliSimDigits * digrow = new AliSimDigits;  
@@ -179,7 +183,7 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
     {
       digarr[i1]=0;
      //    intree[i1]
-      rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
+      rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(i1));
       gime = rl->GetLoader("TPCLoader");
       gime->LoadSDigits("read");
       TTree * treear =  gime->TreeS();
@@ -188,15 +192,33 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
        {
         cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
             <<" input "<< i1<<endl;
+        for (Int_t i2=0;i2<i1+1; i2++){ 
+          
+          if(digarr[i2])  delete digarr[i2];
+       }
+        delete [] digarr;
+        delete [] active;
+        delete []masks;
+        delete []pdig;
+        delete []ptr;
         return;
        }
 
-      sprintf(phname,"lhcphase%d",i1);
+      //sprintf(phname,"lhcphase%d",i1);
+      snprintf(phname,100,"lhcphase%d",i1);
       TParameter<float> *ph = (TParameter<float>*)treear->GetUserInfo()
                               ->FindObject("lhcphase0");
       if(!ph){
         cerr<<"AliTPCDigitizer: LHC phase  not found in"
             <<" input "<< i1<<endl;
+        for (Int_t i2=0;i2<i1+1; i2++){ 
+          if(digarr[i2])  delete digarr[i2];
+       }
+        delete [] digarr;
+        delete [] active;
+        delete []masks;
+        delete []pdig;
+        delete []ptr;
         return;
       }
       tree->GetUserInfo()->Add(new TParameter<float>(phname,ph->GetVal()));
@@ -238,7 +260,7 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
     for (Int_t i=0;i<nInputs; i++) 
      { 
 
-      rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
+      rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(i));
       gime = rl->GetLoader("TPCLoader");
       
       if (gime->TreeS()->GetEntryWithIndex(segmentID,segmentID) >= 0) {
@@ -247,11 +269,11 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
         nrows = digarr[i]->GetNRows();
         ncols = digarr[i]->GetNCols();
        active[i] = kTRUE;
-       if (!fRegionOfInterest || (i == 0)) digitize = kTRUE;
+       if (!GetRegionOfInterest() || (i == 0)) digitize = kTRUE;
       } else {
        active[i] = kFALSE;
       }
-      if (fRegionOfInterest && !digitize) break;
+      if (GetRegionOfInterest() && !digitize) break;
      }   
     if (!digitize) continue;
 
@@ -336,11 +358,11 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
    } //for (Int_t n=0; n<param->GetNRowsTotal(); n++) 
   
 
-  orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
+  orl = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
   ogime = orl->GetLoader("TPCLoader");
   ogime->WriteDigits("OVERWRITE");
   
-  //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
+  //fDigInput->GetTreeDTPC()->Write(0,TObject::kOverwrite);
   
   delete digrow;     
   for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
@@ -354,7 +376,7 @@ void AliTPCDigitizer::ExecFast(Option_t* option)
 
 
 //------------------------------------------------------------------------
-void AliTPCDigitizer::ExecSave(Option_t* option)
+void AliTPCDigitizer::DigitizeSave(Option_t* option)
 {
   
   // merge input tree's with summable digits
@@ -362,7 +384,7 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
 
   TString optionString = option;
   if (!strcmp(optionString.Data(),"deb")) {
-    cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
+    cout<<"AliTPCDigitizer::Digitize: called with option deb "<<endl;
     fDebug = 3;
   }
   //get detector and geometry 
@@ -370,12 +392,12 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
   AliLoader *gime, *ogime;
 
   
-  orl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
+  orl = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
   ogime = orl->GetLoader("TPCLoader");
   
-  rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
-  gime = rl->GetLoader("TPCLoader");
-  
+  rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(0));
+  //gime = rl->GetLoader("TPCLoader");
+  rl->GetLoader("TPCLoader");
   rl->LoadgAlice();
   AliRun* alirun = rl->GetAliRun();
   
@@ -384,29 +406,40 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
   pTPC->GenerNoise(500000); //create teble with noise
   printf("noise %f \n",  param->GetNoise()*param->GetNoiseNormFac());
   //
-  Int_t nInputs = fManager->GetNinputs();
+  Int_t nInputs = fDigInput->GetNinputs();
+  // stupid protection...
+  if (nInputs <= 0) return;
+  //
   Int_t * masks = new Int_t[nInputs];
   for (Int_t i=0; i<nInputs;i++)
-    masks[i]= fManager->GetMask(i);
+    masks[i]= fDigInput->GetMask(i);
 
   AliSimDigits ** digarr = new AliSimDigits*[nInputs]; 
+  for(Int_t ii=0;ii<nInputs;ii++) digarr[ii]=0;
+
   for (Int_t i1=0;i1<nInputs; i1++)
    {
-    digarr[i1]=0;
+     //digarr[i1]=0;
     //    intree[i1]
-    rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i1));
+    rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(i1));
     gime = rl->GetLoader("TPCLoader");
 
     TTree * treear =  gime->TreeS();
-    TBranch * br = treear->GetBranch("fSegmentID");
-    if (br) br->GetFile()->cd();
+    //
     if (!treear) {      
-      cerr<<" TPC -  not existing input = \n"<<i1<<" ";      
+      cerr<<" TPC -  not existing input = \n"<<i1<<" "; 
+      delete [] masks;  
+      for(Int_t i=0; i<nInputs; i++) delete digarr[i];
+      delete [] digarr;
+      return;   
     } 
+    //
+    TBranch * br = treear->GetBranch("fSegmentID");
+    if (br) br->GetFile()->cd();
     treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
-  }
+   }
   
-  rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
+  rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(0));
   gime = rl->GetLoader("TPCLoader");
   Stat_t nentries = gime->TreeS()->GetEntries();
   
@@ -424,7 +457,7 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
   AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetDedxGainFactor();
   AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
   for (Int_t n=0; n<nentries; n++) {
-    rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0));
+    rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(0));
     gime = rl->GetLoader("TPCLoader");
     gime->TreeS()->GetEvent(n);
 
@@ -433,8 +466,8 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
 
 
     for (Int_t i=1;i<nInputs; i++){ 
-//      fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());      
-      rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
+//      fDigInput->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());      
+      rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(i));
       gime = rl->GetLoader("TPCLoader");
       gime->TreeS()->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());  
       digarr[i]->ExpandBuffer();
@@ -521,13 +554,13 @@ void AliTPCDigitizer::ExecSave(Option_t* option)
     tree->Fill();
     if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";  
   } 
-//  printf("end TPC merging - end -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
-  //fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
+//  printf("end TPC merging - end -Tree %s\t%p\n",fDigInput->GetInputTreeH(0)->GetName(),fDigInput->GetInputTreeH(0)->GetListOfBranches()->At(3));
+  //fDigInput->GetTreeDTPC()->Write(0,TObject::kOverwrite);
     ogime->WriteDigits("OVERWRITE");
 
     for (Int_t i=1;i<nInputs; i++) 
      { 
-      rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(i));
+      rl = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(i));
       gime = rl->GetLoader("TPCLoader");
       gime->UnloadSDigits();
      }