]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCDigitizer.cxx
Class for fixed point operations.
[u/mrichter/AliRoot.git] / TPC / AliTPCDigitizer.cxx
index 618c6e8e7050ea6b696bb56c251570bf20c0aa80..2cc2d1c2fa504e1d395f2a89fbe26ef8a346ffb4 100644 (file)
 $Log$
 */
 
+
+
+
+#include <stdlib.h>
 #include <TTree.h> 
 #include <TObjArray.h>
 #include <TFile.h>
@@ -27,6 +31,7 @@ $Log$
 
 #include "AliTPC.h"
 #include "AliTPCParam.h"
+#include "AliTPCParamSR.h" 
 #include "AliRun.h"
 #include "AliPDG.h"
 #include "AliRunDigitizer.h"
@@ -39,6 +44,7 @@ ClassImp(AliTPCDigitizer)
 AliTPCDigitizer::AliTPCDigitizer() :AliDigitizer()
 {
 // Default ctor - don't use it
+  fDebug =0;
 }
 
 //___________________________________________
@@ -46,6 +52,7 @@ AliTPCDigitizer::AliTPCDigitizer(AliRunDigitizer* manager)
     :AliDigitizer(manager)
 {
 // ctor which should be used
+  fDebug =0;
   if (GetDebug()>2) 
     cerr<<"AliTPCDigitizer::AliTPCDigitizer"
        <<"(AliRunDigitizer* manager) was processed"<<endl;
@@ -70,11 +77,17 @@ Bool_t AliTPCDigitizer::Init()
 
 //------------------------------------------------------------------------
 void AliTPCDigitizer::Exec(Option_t* option)
+{
+  ExecFast(option);  
+}
+//------------------------------------------------------------------------
+void AliTPCDigitizer::ExecFast(Option_t* option)
 {
   
   // merge input tree's with summable digits
   //output stored in TreeTPCD
-
+  char s[100]; 
+  char ss[100];
   TString optionString = option;
   if (optionString.Data() == "deb") {
     cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
@@ -83,14 +96,45 @@ void AliTPCDigitizer::Exec(Option_t* option)
   //get detector and geometry
   AliTPC *pTPC  = (AliTPC *) gAlice->GetModule("TPC");
   AliTPCParam * param = pTPC->GetParam();
+  
+  sprintf(s,param->GetTitle());
+  sprintf(ss,"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");
+   if(strcmp(s,ss)!=0) {
+     printf("No TPC parameters found...\n");
+     exit(2); 
+   }
+  }
+  
+  pTPC->GenerNoise(500000); //create teble 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
 
-  printf("noise %f \n",  param->GetNoise()*param->GetNoiseNormFac());
   //create digits array for given sectors
-  AliSimDigits ** digarr = new AliSimDigits*[fManager->GetNinputs()]; 
-  for (Int_t i1=0;i1<fManager->GetNinputs(); i1++){
+  // make indexes
+  AliSimDigits ** digarr = new AliSimDigits*[nInputs]; 
+  for (Int_t i1=0;i1<nInputs; i1++){
     digarr[i1]=0;
     //    intree[i1]
     TTree * treear =  fManager->GetInputTreeTPCS(i1);
+    if (!treear) {
+      cerr<<"AliTPCDigitizer: Input tree with SDigits not found in"
+         <<" input "<< i1<<endl;
+      return;
+    }
+    if (treear->GetIndex()==0) 
+      treear->BuildIndex("fSegmentID","fSegmentID");
     if (!treear) {      
       cerr<<" TPC -  not existing input = \n"<<i1<<" ";      
     }
@@ -102,23 +146,196 @@ void AliTPCDigitizer::Exec(Option_t* option)
   //create branch's in TPC treeD
   AliSimDigits * digrow = new AliSimDigits;
   TTree * tree  = fManager->GetTreeDTPC();
-  if (tree->GetBranch("Segment") ) tree->GetBranch("Segment")->SetAddress(&digrow);
-  else
-    tree->Branch("Segment","AliSimDigits",&digrow);
+  tree->Branch("Segment","AliSimDigits",&digrow);
   //
 
-  Int_t zerosup = param->GetZeroSup();
+  param->SetZeroSup(2);
+
+  Int_t zerosup = param->GetZeroSup(); 
+  //
   //Loop over segments of the TPC
     
   for (Int_t n=0; n<nentries; n++) {
+  //    for (Int_t n=0; n<300; n++) {
+    fManager->GetInputTreeTPCS(0)->GetEvent(n);      
+    digarr[0]->ExpandBuffer();
+    digarr[0]->ExpandTrackBuffer();
+           
+    for (Int_t i=1;i<nInputs; i++){ 
+      fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());
+      if ((digarr[0]->GetID()-digarr[i]->GetID())>0) 
+       printf("problem - not corresponding segment in background event\n");
+      
+      digarr[i]->ExpandBuffer();
+      digarr[i]->ExpandTrackBuffer();
+    }   
+    Int_t sec, row;
+    if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
+      cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
+      continue;
+    }
+
+    digrow->SetID(digarr[0]->GetID());
+
+    Int_t nrows = digarr[0]->GetNRows();
+    Int_t ncols = digarr[0]->GetNCols();
+    digrow->Allocate(nrows,ncols);
+    digrow->AllocateTrack(3);
+
+    Float_t q=0;
+    Int_t label[1000]; //stack for 300 events 
+    Int_t labptr = 0;
+
+    Int_t nElems = nrows*ncols;     
+    for (Int_t i=0;i<nInputs; i++){ 
+      pdig[i] = digarr[i]->GetDigits();
+      ptr[i]  = digarr[i]->GetTracks();
+    }
+    Short_t *pdig1= digrow->GetDigits();
+    Int_t   *ptr1= digrow->GetTracks() ;
+
+    
+
+    //    for (Int_t rows=0;rows<nrows; rows++){
+    //  for (Int_t col=0;col<ncols; col++){
+    for (Int_t elem=0;elem<nElems; elem++){    
+      //for (Int_t elem=nElems;elem<nElems; elem++){
+
+       q=0;
+       labptr=0;
+       // looop over digits 
+        for (Int_t i=0;i<nInputs; i++){ 
+         //          q  += digarr[i]->GetDigitFast(rows,col);
+          q  += *(pdig[i]);
+         
+          for (Int_t tr=0;tr<3;tr++) {
+           //             Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
+           Int_t lab = ptr[i][tr*nElems];
+            if ( (lab > 1) && *(pdig[i])>zerosup) {
+              label[labptr]=lab+masks[i];
+              labptr++;
+            }     
+          }
+         pdig[i]++;
+         ptr[i]++;
+         
+        }
+       q/=16.;  //conversion factor
+       //      Float_t noise  = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());  
+       Float_t noise  = pTPC->GetNoise();
+       q+=noise;
+        q=TMath::Nint(q);
+        if (q > zerosup){ 
+         
+         if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
+         //digrow->SetDigitFast((Short_t)q,rows,col);  
+         *pdig1 =Short_t(q);
+         for (Int_t tr=0;tr<3;tr++){
+           if (tr<labptr) 
+             // ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
+             ptr1[tr*nElems] = label[tr];
+           //else
+             //            ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);          
+           //  ptr1[tr*nElems] = 1;
+         }
+       }
+       pdig1++;
+       ptr1++;
+    }
+    
+    digrow->CompresBuffer(1,zerosup);
+    digrow->CompresTrackBuffer(1);
+    tree->Fill();
+    if (fDebug>0) cerr<<sec<<"\t"<<row<<"\n";  
+  } 
+  fManager->GetTreeDTPC()->Write(0,TObject::kOverwrite);
+  delete digrow;     
+  for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
+  delete []masks;
+  delete digarr;  
+}
+
+
+
+//------------------------------------------------------------------------
+void AliTPCDigitizer::ExecSave(Option_t* option)
+{
+  
+  // merge input tree's with summable digits
+  //output stored in TreeTPCD
+
+  TString optionString = option;
+  if (optionString.Data() == "deb") {
+    cout<<"AliTPCDigitizer::Exec: called with option deb "<<endl;
+    fDebug = 3;
+  }
+  //get detector and geometry 
+  printf("TPC merging -1  -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
+  AliTPC *pTPC  = (AliTPC *) gAlice->GetModule("TPC");
+  AliTPCParam * param = pTPC->GetParam();
+  pTPC->GenerNoise(500000); //create teble with noise
+  printf("noise %f \n",  param->GetNoise()*param->GetNoiseNormFac());
+  //
+  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
+
+  //create digits array for given sectors
+  // make indexes
+   printf("TPC merging -2  -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
+  AliSimDigits ** digarr = new AliSimDigits*[nInputs]; 
+  for (Int_t i1=0;i1<nInputs; i1++){
+    digarr[i1]=0;
+    //    intree[i1]
+    TTree * treear =  fManager->GetInputTreeTPCS(i1);
+    printf("TPC merging -2.7  -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
+    TBranch * br = treear->GetBranch("fSegmentID");
+    if (br) br->GetFile()->cd();
+    printf("TPC merging -2.75  -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
+    //treear->BuildIndex("fSegmentID","fSegmentID");
+    if (!treear) {      
+      cerr<<" TPC -  not existing input = \n"<<i1<<" ";      
+    } 
+    printf("TPC merging -2.8  -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
+    treear->GetBranch("Segment")->SetAddress(&digarr[i1]);
+     printf("TPC merging -2.9  -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
+  }
+  Stat_t nentries = fManager->GetInputTreeTPCS(0)->GetEntries();
+  
+
+  //create branch's in TPC treeD
+  AliSimDigits * digrow = new AliSimDigits;
+  TTree * tree  = fManager->GetTreeDTPC();
+  //if (tree->GetBranch("Segment") ) tree->GetBranch("Segment")->SetAddress(&digrow);
+  //else
+  tree->Branch("Segment","AliSimDigits",&digrow);
+  //
+ printf("TPC merging -3  -Tree %s\t%p\n",fManager->GetInputTreeH(0)->GetName(),fManager->GetInputTreeH(0)->GetListOfBranches()->At(3));
+  param->SetZeroSup(2);
+
+  Int_t zerosup = param->GetZeroSup();
+  //Loop over segments of the TPC
     
-    for (Int_t i=0;i<fManager->GetNinputs(); i++){ 
-      fManager->GetInputTreeTPCS(i)->GetEvent(n);      
+  for (Int_t n=0; n<nentries; n++) {
+  //    for (Int_t n=0; n<300; n++) {
+    fManager->GetInputTreeTPCS(0)->GetEvent(n);      
+    digarr[0]->ExpandBuffer();
+    digarr[0]->ExpandTrackBuffer();
+           
+    for (Int_t i=1;i<nInputs; i++){ 
+      fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),digarr[0]->GetID());      
+      //fManager->GetInputTreeTPCS(i)->GetEntryWithIndex(digarr[0]->GetID(),1);      
       digarr[i]->ExpandBuffer();
       digarr[i]->ExpandTrackBuffer();
+      if ((digarr[0]->GetID()-digarr[i]->GetID())>0) 
+       printf("problem\n");
+    
     }   
-    if ((digarr[0]->GetID()-digarr[1]->GetID())>0) 
-      printf("problem\n");
+    
     Int_t sec, row;
     if (!param->AdjustSectorRow(digarr[0]->GetID(),sec,row)) {
       cerr<<"AliTPC warning: invalid segment ID ! "<<digarr[0]->GetID()<<endl;
@@ -132,50 +349,67 @@ void AliTPCDigitizer::Exec(Option_t* option)
     digrow->Allocate(nrows,ncols);
     digrow->AllocateTrack(3);
 
+    Float_t q=0;
+    Int_t label[1000]; //stack for 300 events 
+    Int_t labptr = 0;
+
+    
+
     for (Int_t rows=0;rows<nrows; rows++){
       for (Int_t col=0;col<ncols; col++){
-        Float_t q=0;
-        Int_t label[1000]; //stack for 300 events 
-        Int_t labptr = 0;
-        // looop over digits
-        for (Int_t i=0;i<fManager->GetNinputs(); i++){ 
-          q  += digarr[i]->GetDigitFast(rows,col);
+    
+       q=0;
+       labptr=0;
+       // looop over digits 
+        for (Int_t i=0;i<nInputs; i++){ 
+         q  += digarr[i]->GetDigitFast(rows,col);
+          //q  += *(pdig[i]);
+         
           for (Int_t tr=0;tr<3;tr++) {
-            Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
-            if ( lab > 1) {
-              label[labptr]=lab+fManager->GetMask(i)-2;
+           Int_t lab = digarr[i]->GetTrackIDFast(rows,col,tr);
+           //Int_t lab = ptr[i][tr*nElems];
+            if ( (lab > 1) ) {
+              label[labptr]=lab+masks[i];
               labptr++;
-            }
+            }     
           }
+         // pdig[i]++;
+         //ptr[i]++;
+         
         }
-        //add noise
        q/=16.;  //conversion factor
-       Float_t noise  = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());     
-       //printf("%f\n",noise);
+       //      Float_t noise  = gRandom->Gaus(0,param->GetNoise()*param->GetNoiseNormFac());  
+       Float_t noise  = pTPC->GetNoise();
        q+=noise;
         q=TMath::Nint(q);
-       printf("%f\n",q);
-
-        if (q <= zerosup)continue;
+        if (q > zerosup){ 
          
-       if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
-       digrow->SetDigitFast((Short_t)q,rows,col);  
-       
-       for (Int_t tr=0;tr<3;tr++){
-         if (tr<labptr)
-           ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
-         else
-           ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);          
-        }
-      } 
+         if(q > param->GetADCSat()) q = (Short_t)(param->GetADCSat());
+         digrow->SetDigitFast((Short_t)q,rows,col);  
+         // *pdig1 =Short_t(q);
+         for (Int_t tr=0;tr<3;tr++){
+           if (tr<labptr) 
+             ((AliSimDigits*)digrow)->SetTrackIDFast(label[tr],rows,col,tr);
+           //ptr1[tr*nElems] = label[tr];
+           //else
+             //            ((AliSimDigits*)digrow)->SetTrackIDFast(-1,rows,col,tr);          
+           //  ptr1[tr*nElems] = 1;
+         }
+       }
+       //pdig1++;
+       //ptr1++;
+    }
     }
+    
     digrow->CompresBuffer(1,zerosup);
     digrow->CompresTrackBuffer(1);
     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);
   delete digrow;     
-  for (Int_t ii1=0;ii1<fManager->GetNinputs(); ii1++) delete digarr[ii1];
+  for (Int_t i1=0;i1<nInputs; i1++) delete digarr[i1];
+  delete []masks;
   delete digarr;  
 }
-