]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPC.cxx
Merging the VirtualMC branch to the main development branch (HEAD)
[u/mrichter/AliRoot.git] / TPC / AliTPC.cxx
index 9c5d75c535ceff01bfa261638ac69e531f5fd177..c1eef630b3046c0de76809ebc1aea26ab639c120 100644 (file)
 
 /*
 $Log$
+Revision 1.54.4.3  2002/10/11 08:34:48  hristov
+Updating VirtualMC to v3-09-02
+
+Revision 1.62  2002/09/23 09:22:56  hristov
+The address of the TrackReferences is set (M.Ivanov)
+
+Revision 1.61  2002/09/10 07:06:42  kowal2
+Corrected for the memory leak. Thanks to J. Chudoba and M. Ivanov
+
+Revision 1.60  2002/06/12 14:56:56  kowal2
+Added track length to the reference hits
+
+Revision 1.59  2002/06/05 15:37:31  kowal2
+Added cross-talk from the wires beyond the first and the last rows
+
+Revision 1.58  2002/05/27 14:33:14  hristov
+The new class AliTrackReference used (M.Ivanov)
+
+Revision 1.57  2002/05/07 17:23:11  kowal2
+Linear gain inefficiency instead of the step one at the wire edges.
+
+Revision 1.56  2002/04/04 16:26:33  kowal2
+Digits (Sdigits) go to separate files now.
+
+Revision 1.55  2002/03/29 06:57:45  kowal2
+Restored backward compatibility to use the hits from Dec. 2000 production.
+
+Revision 1.54  2002/03/18 17:59:13  kowal2
+Chnges in the pad geometry - 3 pad lengths introduced.
+
 Revision 1.53  2002/02/25 11:02:56  kowal2
 Changes towards speeding up the code. Thanks to Marian Ivanov.
 
@@ -196,6 +226,7 @@ Introduction of the Copyright and cvs Log
 #include <fstream.h>
 #include "AliMC.h"
 #include "AliMagF.h"
+#include "AliTrackReference.h"
 
 
 #include "AliTPCParamSR.h"
@@ -245,7 +276,9 @@ AliTPCFastMatrix::AliTPCFastMatrix(Int_t row_lwb, Int_t row_upb, Int_t col_lwb,
 class AliTPCFastVector : public TVector {
 public :
   AliTPCFastVector(Int_t size);
+  virtual ~AliTPCFastVector(){;}
   inline Float_t & UncheckedAt(Int_t index) const  {return  fElements[index];} //fast acces  
+  
 };
 
 AliTPCFastVector::AliTPCFastVector(Int_t size):TVector(size){
@@ -266,7 +299,7 @@ AliTPC::AliTPC()
   fDefaults = 0;
   fTrackHits = 0; 
   fTrackHitsOld = 0;   
-  fHitType = 4; //default CONTAINERS - based on ROOT structure 
+  fHitType = 2; //default CONTAINERS - based on ROOT structure 
   fTPCParam = 0;    
   fNoiseTable = 0;
   fActiveSectors =0;
@@ -301,7 +334,7 @@ AliTPC::AliTPC(const char *name, const char *title)
 
   fNoiseTable =0;
 
-  fHitType = 4;
+  fHitType = 2;
   fActiveSectors = 0;
   //
   // Initialise counters
@@ -359,6 +392,22 @@ void AliTPC::AddHit(Int_t track, Int_t *vol, Float_t *hits)
   if (fHitType>1)
    AddHit2(track,vol,hits);
 }
+
+void  AliTPC::AddTrackReference(Int_t lab, TLorentzVector p, TLorentzVector x, Float_t length){
+  //
+  // add a trackrefernce to the list
+  if (!fTrackReferences) {
+    cerr<<"Container trackrefernce not active\n";
+    return;
+  }
+  Int_t nref = fTrackReferences->GetEntriesFast();
+  TClonesArray &lref = *fTrackReferences;
+  AliTrackReference * ref =  new(lref[nref]) AliTrackReference;
+  ref->SetMomentum(p[0],p[1],p[2]);
+  ref->SetPosition(x[0],x[1],x[2]);
+  ref->SetTrack(lab);
+  ref->SetLength(length);
+}
  
 //_____________________________________________________________________________
 void AliTPC::BuildGeometry()
@@ -920,7 +969,7 @@ void    AliTPC::SetActiveSectors(Int_t * sectors, Int_t n)
     
 }
 
-void    AliTPC::SetActiveSectors()
+void    AliTPC::SetActiveSectors(Int_t flag)
 {
   //
   // activate sectors which were hitted by tracks 
@@ -928,6 +977,10 @@ void    AliTPC::SetActiveSectors()
   if (fHitType==0) return;  // if Clones hit - not short volume ID information
   if (fActiveSectors) delete [] fActiveSectors;
   fActiveSectors = new Bool_t[fTPCParam->GetNSector()];
+  if (flag) {
+    for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kTRUE;
+    return;
+  }
   for (Int_t i=0;i<fTPCParam->GetNSector();i++) fActiveSectors[i]=kFALSE;
   TBranch * branch=0;
   if (fHitType>1) branch = gAlice->TreeH()->GetBranch("TPC2");
@@ -1301,6 +1354,11 @@ void AliTPC::Hits2ExactClustersSector(Int_t isec)
          Float_t detbz=currentIndex*(sumxz*sumx4-sumx2z*sumx3)-sumz*(sumx*sumx4-sumx2*sumx3)+
            sumx2*(sumx*sumx2z-sumx2*sumxz);
          
+         if (TMath::Abs(det)<0.00001){
+            tpcHit = (AliTPChit*)NextHit();
+           continue;
+         }
+       
          Float_t y=detay/det+centralPad;
          Float_t z=detaz/det;  
          Float_t by=detby/det; //y angle
@@ -1349,7 +1407,16 @@ void AliTPC::SDigits2Digits2(Int_t eventnumber)
   sprintf(dname,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
 
   //conect tree with sSDigits
-  TTree *t = (TTree *)gDirectory->Get(sname); 
+  TTree *t;
+  if (gAlice->GetTreeDFile()) {
+    t = (TTree *)gAlice->GetTreeDFile()->Get(sname); 
+  } else {
+    t = (TTree *)gDirectory->Get(sname); 
+  }
+  if (!t) {
+    cerr<<"TPC tree with sdigits not found"<<endl;
+    return;
+  }
   AliSimDigits digarr, *dummy=&digarr;
   t->GetBranch("Segment")->SetAddress(&dummy);
   Stat_t nentries = t->GetEntries();
@@ -1367,7 +1434,12 @@ void AliTPC::SDigits2Digits2(Int_t eventnumber)
   AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
   arr->SetClass("AliSimDigits");
   arr->Setup(fTPCParam);
-  arr->MakeTree(fDigitsFile);
+// Note that methods arr->MakeTree have different signatures
+  if (gAlice->GetTreeDFile()) {
+    arr->MakeTree(gAlice->GetTreeDFile());
+  } else {
+    arr->MakeTree(fDigitsFile);
+  }
   
   AliTPCParam * par =fTPCParam;
 
@@ -1433,7 +1505,7 @@ void AliTPC::SDigits2Digits2(Int_t eventnumber)
 
   
   arr->GetTree()->SetName(dname);  
-  arr->GetTree()->Write();  
+  arr->GetTree()->AutoSave();  
   delete arr;
 }
 //_________________________________________
@@ -1574,6 +1646,20 @@ void AliTPC::SetDefaults(){
   // Set response functions
 
   AliTPCParamSR *param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60");
+  if(param){
+    printf("You are using 2 pad-length geom hits with 3 pad-lenght geom digits...\n");
+    delete param;
+    param = new AliTPCParamSR();
+  }
+  else {
+    param=(AliTPCParamSR*)gDirectory->Get("75x40_100x60_150x60");
+  }
+  if(!param){
+    printf("No TPC parameters found\n");
+    exit(4);
+  }
+
+
   AliTPCPRF2D    * prfinner   = new AliTPCPRF2D;
   AliTPCPRF2D    * prfouter1   = new AliTPCPRF2D;
   AliTPCPRF2D    * prfouter2   = new AliTPCPRF2D;  
@@ -1625,7 +1711,12 @@ void AliTPC::Hits2Digits(Int_t eventnumber)
   AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
   arr->SetClass("AliSimDigits");
   arr->Setup(fTPCParam);
-  arr->MakeTree(fDigitsFile);
+// Note that methods arr->MakeTree have different signatures
+  if (gAlice->GetTreeDFile()) {
+    arr->MakeTree(gAlice->GetTreeDFile());
+  } else {
+    arr->MakeTree(fDigitsFile);
+  }
   SetDigitsArray(arr);
 
   fDigitsSwitch=0; // standard digits
@@ -1641,7 +1732,7 @@ void AliTPC::Hits2Digits(Int_t eventnumber)
   sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
   
   GetDigitsArray()->GetTree()->SetName(treeName);  
-  GetDigitsArray()->GetTree()->Write();  
+  GetDigitsArray()->GetTree()->AutoSave();  
 
 
 }
@@ -1670,7 +1761,12 @@ void AliTPC::Hits2SDigits2(Int_t eventnumber)
   AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
   arr->SetClass("AliSimDigits");
   arr->Setup(fTPCParam);
-  arr->MakeTree(fDigitsFile);
+// Note that methods arr->MakeTree have different signatures
+  if (gAlice->GetTreeSFile()) {
+    arr->MakeTree(gAlice->GetTreeSFile());
+  } else {
+    arr->MakeTree(fDigitsFile);
+  }
   SetDigitsArray(arr);
 
   cerr<<"Digitizing TPC -- summable digits...\n"; 
@@ -1691,7 +1787,7 @@ void AliTPC::Hits2SDigits2(Int_t eventnumber)
   sprintf(treeName,"TreeS_%s_%d",fTPCParam->GetTitle(),eventnumber);
   
   GetDigitsArray()->GetTree()->SetName(treeName); 
-  GetDigitsArray()->GetTree()->Write(); 
+  GetDigitsArray()->GetTree()->AutoSave(); 
 
 }
 
@@ -1721,7 +1817,12 @@ void AliTPC::Hits2SDigits()
   AliTPCDigitsArray *arr = new AliTPCDigitsArray; 
   arr->SetClass("AliSimDigits");
   arr->Setup(fTPCParam);
-  arr->MakeTree(fDigitsFile);
+// Note that methods arr->MakeTree have different signatures
+  if (gAlice->GetTreeSFile()) {
+    arr->MakeTree(gAlice->GetTreeSFile());
+  } else {
+    arr->MakeTree(fDigitsFile);
+  }
   SetDigitsArray(arr);
 
   cerr<<"Digitizing TPC -- summable digits...\n"; 
@@ -1737,7 +1838,7 @@ void AliTPC::Hits2SDigits()
   sprintf(treeName,"TreeD_%s_%d",fTPCParam->GetTitle(),eventnumber);
   
   GetDigitsArray()->GetTree()->SetName(treeName); 
-  GetDigitsArray()->GetTree()->Write(); 
+  GetDigitsArray()->GetTree()->AutoSave(); 
 
 }
 
@@ -1777,7 +1878,7 @@ void AliTPC::Hits2DigitsSector(Int_t isec)
 
       Int_t nrows =fTPCParam->GetNRow(isec);
 
-      row= new TObjArray* [nrows];
+      row= new TObjArray* [nrows+2]; // 2 extra rows for cross talk
     
       MakeSector(isec,nrows,tH,ntracks,row);
 
@@ -1808,7 +1909,7 @@ void AliTPC::Hits2DigitsSector(Int_t isec)
    
        } // end of the sector digitization
 
-      for(i=0;i<nrows;i++){
+      for(i=0;i<nrows+2;i++){
         row[i]->Delete();  
         delete row[i];   
       }
@@ -1835,7 +1936,7 @@ void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
  
 
   Float_t zerosup = fTPCParam->GetZeroSup();
-  Int_t nrows =fTPCParam->GetNRow(isec);
+  //  Int_t nrows =fTPCParam->GetNRow(isec);
   fCurrentIndex[1]= isec;
   
 
@@ -1863,14 +1964,16 @@ void AliTPC::DigitizeRow(Int_t irow,Int_t isec,TObjArray **rows)
   //
   //calculate signal 
   //
-  Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
-  Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
+  //Int_t row1 = TMath::Max(irow-fTPCParam->GetNCrossRows(),0);
+  //Int_t row2 = TMath::Min(irow+fTPCParam->GetNCrossRows(),nrows-1);
+  Int_t row1=irow;
+  Int_t row2=irow+2; 
   for (Int_t row= row1;row<=row2;row++){
     Int_t nTracks= rows[row]->GetEntries();
     for (i1=0;i1<nTracks;i1++){
       fCurrentIndex[2]= row;
-      fCurrentIndex[3]=irow;
-      if (row==irow){
+      fCurrentIndex[3]=irow+1;
+      if (row==irow+1){
        m2->Zero();  // clear single track signal matrix
        Float_t trackLabel = GetSignal(rows[row],i1,m2,m1,indexRange); 
        GetList(trackLabel,nofPads,m2,indexRange,pList);
@@ -1970,7 +2073,7 @@ Float_t AliTPC::GetSignal(TObjArray *p1, Int_t ntr,
   AliTPCFastVector &v = *tv;
   
   Float_t label = v(0);
-  Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3])-1)/2;
+  Int_t centralPad = (fTPCParam->GetNPads(fCurrentIndex[1],fCurrentIndex[3]-1)-1)/2;
 
   Int_t nElectrons = (tv->GetNrows()-1)/4;
   indexRange[0]=9999; // min pad
@@ -2141,10 +2244,10 @@ void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
   // of electrons, one AliTPCFastVectors per each track.
   //---------------------------------------------- 
     
-  Int_t *nofElectrons = new Int_t [nrows]; // electron counter for each row
-  AliTPCFastVector **tracks = new AliTPCFastVector* [nrows]; //pointers to the track vectors
+  Int_t *nofElectrons = new Int_t [nrows+2]; // electron counter for each row
+  AliTPCFastVector **tracks = new AliTPCFastVector* [nrows+2]; //pointers to the track vectors
 
-  for(i=0; i<nrows; i++){
+  for(i=0; i<nrows+2; i++){
     row[i] = new TObjArray;
     nofElectrons[i]=0;
     tracks[i]=0;
@@ -2191,7 +2294,7 @@ void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
                           
            // store already filled fTrack
               
-          for(i=0;i<nrows;i++){
+          for(i=0;i<nrows+2;i++){
              if(previousTrack != -1){
               if(nofElectrons[i]>0){
                  AliTPCFastVector &v = *tracks[i];
@@ -2244,14 +2347,16 @@ void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
          xyz[3]= (Float_t) (-gasgain*TMath::Log(rn)); 
          index[0]=1;
          
-         TransportElectron(xyz,index); //MI change -august       
+         TransportElectron(xyz,index);    
          Int_t rowNumber;
-         fTPCParam->GetPadRow(xyz,index); //MI change august
-         rowNumber = index[2];
+         fTPCParam->GetPadRow(xyz,index); 
+         // row 0 - cross talk from the innermost row
+         // row fNRow+1 cross talk from the outermost row
+         rowNumber = index[2]+1; 
          //transform position to local digit coordinates
          //relative to nearest pad row 
-         if ((rowNumber<0)||rowNumber>=fTPCParam->GetNRow(isec)) continue;
-  Float_t x1,y1;
+         if ((rowNumber<0)||rowNumber>fTPCParam->GetNRow(isec)+1) continue;
+          Float_t x1,y1;
          if (isec <fTPCParam->GetNInnerSector()) {
            x1 = xyz[1]*fTPCParam->GetInnerPadPitchWidth();
            y1 = fTPCParam->GetYInner(rowNumber);
@@ -2260,14 +2365,11 @@ void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
            x1=xyz[1]*fTPCParam->GetOuterPadPitchWidth();
            y1 = fTPCParam->GetYOuter(rowNumber);
          }
-
+         // gain inefficiency at the wires edges - linear
          x1=TMath::Abs(x1);
-         if (y1-0.5 <x1) {
-           xyz[3]=0.;}
-         else{ 
-           if (y1 -1.<x1){
-             xyz[3]*=0.5;}
-         }                    
+         y1-=1.;
+          if(x1>y1) xyz[3]*=TMath::Max(1.e-6,(y1-x1+1.));      
+       
          nofElectrons[rowNumber]++;      
          //----------------------------------
          // Expand vector if necessary
@@ -2296,7 +2398,7 @@ void AliTPC::MakeSector(Int_t isec,Int_t nrows,TTree *TH,
     //   store remaining track (the last one) if not empty
     //
 
-     for(i=0;i<nrows;i++){
+     for(i=0;i<nrows+2;i++){
        if(nofElectrons[i]>0){
           AliTPCFastVector &v = *tracks[i];
          v(0) = previousTrack;
@@ -2513,13 +2615,10 @@ void AliTPC::TransportElectron(Float_t *xyz, Int_t *index)
   // ExB
   
   if (fTPCParam->GetMWPCReadout()==kTRUE){
-    Float_t x1=xyz[0];
-    fTPCParam->Transform2to2NearestWire(xyz,index);
-    Float_t dx=xyz[0]-x1;
+    Float_t dx = fTPCParam->Transform2to2NearestWire(xyz,index);
     xyz[1]+=dx*(fTPCParam->GetOmegaTau());
   }
-  //add nonisochronity (not implemented yet)
-  
+  //add nonisochronity (not implemented yet)  
 }
   
 ClassImp(AliTPCdigit)
@@ -2654,6 +2753,13 @@ void AliTPC::SetTreeAddress2()
     branch = treeH->GetBranch(branchname);
     if (branch) branch->SetAddress(&fTrackHitsOld);
   }
+  //set address to TREETR
+  TTree *treeTR = gAlice->TreeTR();
+  if (treeTR && fTrackReferences) {
+    branch = treeTR->GetBranch(GetName());
+    if (branch) branch->SetAddress(&fTrackReferences);
+  }
+
 
 }
 
@@ -3125,7 +3231,21 @@ void AliTPC::Digits2Reco(Int_t firstevent,Int_t lastevent)
   TDirectory *cwd = gDirectory;
 
 
-  AliTPCParam *dig=(AliTPCParam *)gDirectory->Get("75x40_100x60");
+  AliTPCParamSR *dig=(AliTPCParamSR *)gDirectory->Get("75x40_100x60");
+  if(dig){
+    printf("You are running 2 pad-length geom hits with 3 pad-length geom digits\n");
+    delete dig;
+    dig = new AliTPCParamSR();
+  }
+  else
+  {
+   dig=(AliTPCParamSR *)gDirectory->Get("75x40_100x60_150x60"); 
+  }
+  if(!dig){
+   printf("No TPC parameters found\n");
+   exit(3);
+  }
+   
   SetParam(dig);
   cout<<"AliTPC::Digits2Reco: TPC parameteres have been set"<<endl; 
   TFile *out;