]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRD.cxx
Bugfix for calculation of cluster widths.
[u/mrichter/AliRoot.git] / TRD / AliTRD.cxx
index b9d0ec8cce874ecb1d111a6c88d5a6cb8dd89dd3..736a417d3d64bf058ff56057a2022eae86158059 100644 (file)
@@ -43,8 +43,6 @@
 #include "AliMagF.h"
 #include "AliRun.h"
 #include "AliTRD.h"
-#include "AliTRDcluster.h"
-#include "AliTRDclusterizer.h"
 #include "AliTRDdigit.h"
 #include "AliTRDdigitizer.h"
 #include "AliTRDdigitsManager.h"
 #include "AliTRDgeometryHole.h"
 #include "AliTRDhit.h"
 #include "AliTRDpoints.h"
-#include "AliTRDrecPoint.h"
 #include "AliTRDtrackHits.h"  
+#include "AliTRDrawData.h"
 #include "AliTrackReference.h"
+#include "AliMC.h"
 
 ClassImp(AliTRD)
  
@@ -70,9 +69,6 @@ AliTRD::AliTRD()
   fHits          = 0;
   fDigits        = 0;
 
-  fRecPoints     = 0;
-  fNRecPoints    = 0;
-
   fGeometry      = 0;
 
   fGasDensity    = 0;
@@ -102,13 +98,9 @@ AliTRD::AliTRD(const char *name, const char *title)
     exit(1);
   } 
 
-  // Define the TRD geometry according to the FRAME geometry
-  if      (frame->IsVersion() == 0) {
-    // Geometry with hole
-    fGeometry = new AliTRDgeometryHole();
-  }
-  else if (frame->IsVersion() == 1) {
-    // Geometry without hole
+  // Define the TRD geometry
+  if ((frame->IsVersion() == 0) ||
+      (frame->IsVersion() == 1)) {
     fGeometry = new AliTRDgeometryFull();
   }
   else {
@@ -116,17 +108,19 @@ AliTRD::AliTRD(const char *name, const char *title)
     exit(1);
   }
 
+  // Save the geometry
+  TDirectory* saveDir = gDirectory;
+  gAlice->GetRunLoader()->CdGAFile();
+  fGeometry->Write("TRDgeometry");
+  saveDir->cd();
+
   // Allocate the hit array
   fHits           = new TClonesArray("AliTRDhit"     ,405);
-  gAlice->AddHitList(fHits);
+  gAlice->GetMCApp()->AddHitList(fHits);
 
   // Allocate the digits array
   fDigits         = 0;
 
-  // Allocate the rec point array
-  fRecPoints     = new TObjArray(400);
-  fNRecPoints    = 0;
-   
   fIshunt        = 0;
   fGasMix        = 1;
 
@@ -144,7 +138,7 @@ AliTRD::AliTRD(const char *name, const char *title)
 }
 
 //_____________________________________________________________________________
-AliTRD::AliTRD(const AliTRD &trd)
+AliTRD::AliTRD(const AliTRD &trd):AliDetector(trd)
 {
   //
   // Copy constructor
@@ -171,10 +165,10 @@ AliTRD::~AliTRD()
     delete fHits;
     fHits      = 0;
   }
-  if (fRecPoints) {
-    delete fRecPoints;
-    fRecPoints = 0;
-  }
+//  if (fRecPoints) {
+//    delete fRecPoints;
+//    fRecPoints = 0;
+//  }
   if (fTrackHits) {
     delete fTrackHits;
     fTrackHits = 0;
@@ -182,79 +176,30 @@ AliTRD::~AliTRD()
 
 }
 
-//_____________________________________________________________________________
-void AliTRD::AddCluster(Float_t *pos, Int_t det, Float_t amp
-                      , Int_t *tracks, Float_t *sig, Int_t iType)
-{
-  //
-  // Add a cluster for the TRD
-  //
-
-  AliTRDcluster *c = new AliTRDcluster();
-
-  c->SetDetector(det);
-  c->AddTrackIndex(tracks);
-  c->SetQ(amp);
-  c->SetY(pos[0]);
-  c->SetZ(pos[1]);
-  c->SetSigmaY2(sig[0]);   
-  c->SetSigmaZ2(sig[1]);
-  c->SetLocalTimeBin(((Int_t) pos[2]));
-
-  switch (iType) {
-  case 0:
-    c->Set2pad();
-    break;
-  case 1:
-    c->Set3pad();
-    break;
-  case 2:
-    c->Set4pad();
-    break;
-  case 3:
-    c->Set5pad();
-    break;
-  case 4:
-    c->SetLarge();
-    break;
-  };
-
-  fRecPoints->Add(c);
-
-}
-
 //_____________________________________________________________________________
 void AliTRD::Hits2Digits()
 {
   //
   // Create digits
   //
-  if (!fLoader->TreeH()) fLoader->LoadHits("read");
-  SetTreeAddress();
-  
-  AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
-                                                  ,"TRD digitizer class");
-  digitizer->SetDebug(GetDebug());
-  digitizer->SetEvent(gAlice->GetEvNumber());
+  AliTRDdigitizer digitizer("TRDdigitizer","TRD digitizer class");
+  digitizer.SetDebug(GetDebug());
   
   // Initialization
-  digitizer->InitDetector();
+  digitizer.InitDetector();
     
-  // Create the digits
-  digitizer->MakeDigits();
-  
-  // Write the digits into the input file
-
-  if (!fLoader->TreeD()) fLoader->MakeTree("D");
-  if (digitizer->MakeBranch(fLoader->TreeD())) {
-
-    digitizer->WriteDigits();
-
-    // Save the digitizer class in the AliROOT 
-    digitizer->Write();
+  if (!fLoader->TreeH()) fLoader->LoadHits("read");
+  fLoader->LoadDigits("recreate");
+  AliRunLoader* runLoader = fLoader->GetRunLoader(); 
 
+  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
+    digitizer.Open(runLoader->GetFileName().Data(), iEvent);
+    digitizer.MakeDigits();
+    digitizer.WriteDigits();
   }
 
+  fLoader->UnloadHits();
+  fLoader->UnloadDigits();
 }
 
 //_____________________________________________________________________________
@@ -263,35 +208,32 @@ void AliTRD::Hits2SDigits()
   //
   // Create summable digits
   //
-  if (!fLoader->TreeH()) fLoader->LoadHits("read");
-  SetTreeAddress();
-
-  AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
-                                                  ,"TRD digitizer class");
-  digitizer->SetDebug(GetDebug());
-
+  AliTRDdigitizer digitizer("TRDdigitizer","TRD digitizer class");
   // For the summable digits
-  digitizer->SetSDigits(kTRUE);
-  digitizer->SetEvent(gAlice->GetEvNumber());
+  digitizer.SetSDigits(kTRUE);
+  digitizer.SetDebug(GetDebug());
 
   // Initialization
-  digitizer->InitDetector();
+  digitizer.InitDetector();
     
-  // Create the TRD s-digits branch
-  digitizer->MakeDigits();
-  
-  // Write the digits into the input file
-  if (!fLoader->TreeS()) fLoader->MakeTree("S");
-  
-  if (digitizer->MakeBranch(fLoader->TreeS())) {
-
-    digitizer->WriteDigits();
+  if (!fLoader->TreeH()) fLoader->LoadHits("read");
+  fLoader->LoadSDigits("recreate");
+  AliRunLoader* runLoader = fLoader->GetRunLoader(); 
 
-    // Save the digitizer class in the AliROOT 
-    digitizer->Write();
+  for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
+    digitizer.Open(runLoader->GetFileName().Data(), iEvent);
+    digitizer.MakeDigits();
+    digitizer.WriteDigits();
+  }
 
+  fLoader->UnloadHits();
+  fLoader->UnloadSDigits();
   }
 
+//_____________________________________________________________________________
+AliDigitizer* AliTRD::CreateDigitizer(AliRunDigitizer* manager) const
+{
+  return new AliTRDdigitizer(manager);
 }
 
 //_____________________________________________________________________________
@@ -302,22 +244,21 @@ void AliTRD::SDigits2Digits()
   //
 
    // Create the TRD digitizer
-  AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
-                                                  ,"TRD digitizer class");  
-  digitizer->SetDebug(GetDebug());
+  AliTRDdigitizer digitizer("TRDdigitizer","TRD digitizer class");  
+  digitizer.SetDebug(GetDebug());
 
   // Set the parameter
-  digitizer->SetEvent(gAlice->GetEvNumber());
+  digitizer.SetEvent(gAlice->GetEvNumber());
 
   // Initialization
-  digitizer->InitDetector();
+  digitizer.InitDetector();
 
   // Read the s-digits via digits manager
-  AliTRDdigitsManager *sdigitsManager = new AliTRDdigitsManager();
+  AliTRDdigitsManager sdigitsManager;
  
-  sdigitsManager->SetDebug(GetDebug());
-  sdigitsManager->SetSDigits(kTRUE);
-  sdigitsManager->CreateArrays();
+  sdigitsManager.SetDebug(GetDebug());
+  sdigitsManager.SetSDigits(kTRUE);
+  sdigitsManager.CreateArrays();
   
   if (!fLoader->TreeS()) 
     if (fLoader->LoadSDigits("read"))
@@ -327,22 +268,46 @@ void AliTRD::SDigits2Digits()
      }
   if (!fLoader->TreeS()) return;
   
-  sdigitsManager->ReadDigits(fLoader->TreeS());
+  sdigitsManager.ReadDigits(fLoader->TreeS());
 
   // Add the s-digits to the input list 
-  digitizer->AddSDigitsManager(sdigitsManager);
+  digitizer.AddSDigitsManager(&sdigitsManager);
 
   // Convert the s-digits to normal digits
-  digitizer->SDigits2Digits();
+  digitizer.SDigits2Digits();
 
   // Store the digits
   if (!fLoader->TreeD()) fLoader->MakeTree("D");
-  if (digitizer->MakeBranch(fLoader->TreeD())){
-    digitizer->WriteDigits();
+  if (digitizer.MakeBranch(fLoader->TreeD())){
+    digitizer.WriteDigits();
   }
 
 }
 
+//_____________________________________________________________________________
+void AliTRD::Digits2Raw() 
+{
+  //
+  // convert digits of the current event to raw data
+  //
+
+  fLoader->LoadDigits();
+  TTree* digits = fLoader->TreeD();
+  if (!digits) {
+    Error("Digits2Raw", "no digits tree");
+    return;
+  }
+
+  AliTRDrawData rawWriter;
+//  rawWriter.SetDebug(2);
+  if (!rawWriter.Digits2Raw(digits)) {
+    Error("AliTRD::Digits2Raw","The raw writer could not load the digits tree");
+  }
+
+  fLoader->UnloadDigits();
+
+}
+
 //_____________________________________________________________________________
 void AliTRD::AddHit(Int_t track, Int_t det, Float_t *hits, Int_t q
                   , Bool_t inDrift)
@@ -476,8 +441,6 @@ void AliTRD::Copy(TObject &trd)
 
   ((AliTRD &) trd).fGasMix      = fGasMix;
   ((AliTRD &) trd).fGeometry    = fGeometry;       
-  ((AliTRD &) trd).fRecPoints   = fRecPoints;
-  ((AliTRD &) trd).fNRecPoints  = fNRecPoints;
   ((AliTRD &) trd).fGasDensity  = fGasDensity;
   ((AliTRD &) trd).fFoilDensity = fFoilDensity;
   ((AliTRD &) trd).fDrawTR      = fDrawTR;
@@ -700,6 +663,9 @@ void AliTRD::CreateMaterials()
   // Al of cooling pipes
   AliMedium(24, "Cooling" ,   1, 0, isxfld, sxmgmx
                 , tmaxfd, stemax, deemax, epsil, stmin);
+  // Cu in services
+  AliMedium(25, "Serv-Cu" ,   5, 0, isxfld, sxmgmx
+                , tmaxfd, stemax, deemax, epsil, stmin);
 
   // Save the density values for the TRD absorbtion
   fFoilDensity = dmy;
@@ -797,16 +763,16 @@ void AliTRD::Init()
     printf("\n");
   }
 
-  if      (fGeometry->IsVersion() == 0) {
-    printf("%s: Geometry for spaceframe with holes initialized\n",ClassName());
-  }
-  else if (fGeometry->IsVersion() == 1) {
-    printf("%s: Geometry for spaceframe without holes initialized\n",ClassName());
+  if (fGeometry->IsVersion() == 1) {
+    printf("%s: Full geometry version initialized\n",ClassName());
     if (fGeometry->GetPHOShole())
       printf("%s: Leave space in front of PHOS free\n",ClassName());
     if (fGeometry->GetRICHhole())
       printf("%s: Leave space in front of RICH free\n",ClassName());
   }
+  else {
+    printf("%s: Not a valid geometry\n",ClassName());
+  }
   
   if (fGasMix == 1) {
     printf("%s: Gas Mixture: 85%% Xe + 15%% CO2\n",ClassName());
@@ -818,7 +784,7 @@ void AliTRD::Init()
 }
 
 //_____________________________________________________________________________
-void AliTRD::LoadPoints(Int_t track)
+void AliTRD::LoadPoints(Int_t )
 {
   //
   // Store x, y, z of all hits in memory.
@@ -841,7 +807,7 @@ void AliTRD::LoadPoints(Int_t track)
   } 
   if (nhits == 0) return;
 
-  Int_t tracks = gAlice->GetNtrack();
+  Int_t tracks = gAlice->GetMCApp()->GetNtrack();
   if (fPoints == 0) fPoints = new TObjArray(tracks);
 
   AliTRDhit *ahit;
@@ -997,21 +963,6 @@ void AliTRD::ResetDigits()
 
 }
 
-//_____________________________________________________________________________
-void AliTRD::ResetRecPoints()
-{
-  //
-  // Reset number of reconstructed points and the point array
-  //
-
-  if (fRecPoints) {
-    fNRecPoints = 0;
-    Int_t nentr = fRecPoints->GetEntriesFast();
-    for (Int_t i = 0; i < nentr; i++) delete fRecPoints->RemoveAt(i);
-  }
-
-}
-
 //_____________________________________________________________________________
 void AliTRD::SetTreeAddress()
 {
@@ -1019,25 +970,9 @@ void AliTRD::SetTreeAddress()
   // Set the branch addresses for the trees.
   //
 
-  Char_t branchname[15];
-
   if ( fLoader->TreeH() && (fHits == 0x0))  fHits = new TClonesArray("AliTRDhit",405);
   AliDetector::SetTreeAddress();
 
-  TBranch *branch;
-  TTree   *treeR = fLoader->TreeR();
-
-  if (treeR) {
-    sprintf(branchname,"%scluster",GetName());
-    if (fRecPoints == 0x0) fRecPoints  = new TObjArray(400);
-    if (fRecPoints) {
-      branch = treeR->GetBranch(branchname);
-      if (branch) {
-        branch->SetAddress(&fRecPoints);
-      }
-    }
-  }
-
   if (fHitType > 0) {
     SetTreeAddress2();    
   }
@@ -1218,7 +1153,7 @@ AliHit* AliTRD::NextHit2()
 }
 
 //_____________________________________________________________________________
-void AliTRD::MakeBranch2(Option_t *option, const char *file)
+void AliTRD::MakeBranch2(Option_t *option, const char)
 {
   //
   // Create a new branch in the current Root tree.
@@ -1289,13 +1224,13 @@ void AliTRD::AddHit2(Int_t track, Int_t det, Float_t *hits, Int_t q
   Int_t rtrack;
 
   if (fIshunt) {
-    Int_t primary = gAlice->GetPrimary(track);
-    gAlice->Particle(primary)->SetBit(kKeepBit);
+    Int_t primary = gAlice->GetMCApp()->GetPrimary(track);
+    gAlice->GetMCApp()->Particle(primary)->SetBit(kKeepBit);
     rtrack = primary;
   } 
   else {
     rtrack = track;
-    gAlice->FlagTrack(track);
+    gAlice->GetMCApp()->FlagTrack(track);
   }
 
   if ((fTrackHits) && (fHitType > 0)) {
@@ -1637,8 +1572,6 @@ void AliTRD::AddHit2(Int_t track, Int_t det, Float_t *hits, Int_t q
 
 
 
-
-