]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtest.C
Stand-alone library for ESD. Possibility to use only root and lidESD.so for analysis...
[u/mrichter/AliRoot.git] / TRD / AliTRDtest.C
index 42fb096920677133b32526190640af5b31b4c67d..27c9282c656a032d98b3c2a3eb087887ad894722 100644 (file)
@@ -16,9 +16,9 @@ Int_t AliTRDtest()
   gAlice->SetDebug(2);
   gAlice->Run(1);
 
-  if (gAlice) delete gAlice;
-  file   = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
-  gAlice = (AliRun *) file->Get("gAlice");
+  //if (gAlice) delete gAlice;
+  //file   = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
+  //gAlice = (AliRun *) file->Get("gAlice");
 
   // Analyze the TRD hits
   if (rc = AliTRDanalyzeHits()) return rc;
@@ -26,22 +26,22 @@ Int_t AliTRDtest()
   // Run the digitization
   if (rc = AliTRDcreateDigits()) return rc;
 
-  if (gAlice) delete gAlice;
-  file   = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
-  gAlice = (AliRun *) file->Get("gAlice");
+//    if (gAlice) delete gAlice;
+//    file   = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
+//    gAlice = (AliRun *) file->Get("gAlice");
 
   // Analyze the digits
   if (rc = AliTRDanalyzeDigits()) return rc;
 
-  // Create the cluster
-  if (rc = AliTRDcreateCluster()) return rc;
+//    // Create the cluster
+//    if (rc = AliTRDcreateCluster()) return rc;
 
-  if (gAlice) delete gAlice;
-  file   = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
-  gAlice = (AliRun *) file->Get("gAlice");
+//    if (gAlice) delete gAlice;
+//    file   = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
+//    gAlice = (AliRun *) file->Get("gAlice");
 
-  // Analyze the cluster
-  if (rc = AliTRDanalyzeCluster()) return rc;
+//    // Analyze the cluster
+//    if (rc = AliTRDanalyzeCluster()) return rc;
 
   //file   = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
   //file->Close();
@@ -62,12 +62,22 @@ Int_t AliTRDanalyzeHits()
 
   Int_t rc = 0;
 
-  if (!gAlice) {
-    cout << "<AliTRDanalyzeHits> No AliRun object found" << endl;
+  AliRunLoader *rl = gAlice->GetRunLoader();
+  if (!rl) {
+    cout << "<AliTRDanalyzeHits> No RunLoader found" << endl;
     rc = 1;
     return rc;
   }
-  gAlice->GetEvent(0);
+
+  // Import the Trees for the event nEvent in the file
+  rl->GetEvent(0);
+  
+  AliLoader* loader = rl->GetLoader("TRDLoader");
+  if (!loader) {
+    cout << "<AliTRDanalyzeHits> No TRDLoader found" << endl;
+    rc = 2;
+    return rc;
+  }
 
   // Get the pointer to the TRD detector 
   AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
@@ -107,17 +117,8 @@ Int_t AliTRDanalyzeHits()
   TH2F *hXZ     = new TH2F("hXZ"   ,"Z vs X (plane 0)"  , ncol, -width/2., width/2.
                                                         , nrow,-length/2.,length/2.);
 
-  TH1F *hNprimP = new TH1F("hNprimP","Number of primary electrons per cm (MIP pion)"
-                                    ,50,0.0,100.0);
-  TH1F *hNprimE = new TH1F("hNprimE","Number of primary electrons per cm (3GeV electron)"
-                                    ,50,0.0,100.0);
-  TH1F *hNtotP  = new TH1F("hNtotP" ,"Number of electrons per cm (MIP pion)"
-                                    ,50,0.0,1000.0);
-  TH1F *hNtotE  = new TH1F("hNtotE" ,"Number of electrons per cm (3GeV electron)"
-                                    ,50,0.0,1000.0);
-
   // Get the pointer hit tree
-  TTree *hitTree = gAlice->TreeH();  
+  TTree *hitTree = loader->TreeH();  
   if (!hitTree) {
     cout << "<AliTRDanalyzeHits> No hit tree found" << endl;
     rc = 4;
@@ -139,11 +140,6 @@ Int_t AliTRDanalyzeHits()
     gAlice->ResetHits();
     nBytes += hitTree->GetEvent(iTrack);
 
-    Int_t nPrimE = 0;
-    Int_t nPrimP = 0;
-    Int_t nTotE  = 0;
-    Int_t nTotP  = 0;    
-
     // Loop through the TRD hits  
     Int_t iHit = 0;
     AliTRDhit *hit = (AliTRDhit *) trd->FirstHit(-1);
@@ -171,35 +167,10 @@ Int_t AliTRDanalyzeHits()
         hQtr->Fill(TMath::Abs(q));
       }
 
-      TParticle *part = gAlice->Particle(track);
-
-      if ((plane == 0) && (q > 0)) {
-
-        // 3 GeV electrons
-        if ((part->GetPdgCode() ==   11) && 
-            (part->P()          >   2.9)) {
-          nPrimE++;
-          nTotE += ((Int_t) q);
-        }
-
-        // MIP pions
-        if ((part->GetPdgCode() == -211) &&
-            (part->P()          >   0.5)) {
-          nPrimP++;
-          nTotP += ((Int_t) q);
-        }
-
-      }
-
       hit = (AliTRDhit *) trd->NextHit();         
 
     }
 
-    if (nPrimE > 0) hNprimE->Fill(((Double_t) nPrimE)/3.7);
-    if (nPrimP > 0) hNprimP->Fill(((Double_t) nPrimP)/3.7);
-    if (nTotE  > 0) hNtotE->Fill(((Double_t) nTotE)/3.7);
-    if (nTotP  > 0) hNtotP->Fill(((Double_t) nTotP)/3.7);
-
   }
 
   cout << "<AliTRDanalyzeHits> Found " << countHits << " hits in total" << endl;
@@ -217,28 +188,6 @@ Int_t AliTRDanalyzeHits()
   gPad->SetLogy();
   hQtr->Draw();
 
-  TCanvas *cNel = new TCanvas("cNel","Ionization",50,50,600,600);
-  cNel->Divide(2,2);
-  cNel->cd(1);
-  hNprimE->SetStats();
-  hNprimE->Draw();
-  cNel->cd(2);
-  hNprimP->SetStats();
-  hNprimP->Draw();
-  cNel->cd(3);
-  hNtotE->SetStats();
-  hNtotE->Draw();
-  cNel->cd(4);
-  hNtotP->SetStats();
-  hNtotP->Draw();
-
-  TFile *fout = new TFile("TRD_ionization.root","RECREATE");
-  hNprimE->Write();
-  hNprimP->Write();
-  hNtotE->Write();
-  hNtotP->Write();
-  fout->Close(); 
-
   return rc;
 
 }
@@ -262,7 +211,9 @@ Int_t AliTRDcreateDigits()
   // Create the TRD digitzer 
   AliTRDdigitizer *digitizer = new AliTRDdigitizer("TRDdigitizer"
                                                   ,"TRD digitizer class");
+  digitizer->Open("TRD_test.root");
   digitizer->InitDetector();
+  digitizer->InitOutput(0);
 
   // Set the parameter
   digitizer->SetDebug(1);
@@ -281,10 +232,10 @@ Int_t AliTRDcreateDigits()
   }
 
   // Write the digits into the input file
-  if (!(digitizer->MakeBranch())) {
-    rc = 3;
-    return rc;
-  }
+  //if (!(digitizer->MakeBranch())) {
+  //  rc = 3;
+  //  return rc;
+  //}
 
   // Write the digits into the input file
   if (!(digitizer->WriteDigits())) {
@@ -318,25 +269,38 @@ Int_t AliTRDanalyzeDigits()
     rc = 1;
     return rc;
   }
-  Int_t nPart = gAlice->GetEvent(0);
 
-  // Get the pointer to the TRD detector 
-  AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
-  if (!trd) {
-    cout << "<AliTRDanalyzeDigits> No TRD detector found" << endl;
+  AliRunLoader *rl = gAlice->GetRunLoader();
+  if (!rl) {
+    cout << "<AliTRDanalyzeHits> No RunLoader found" << endl;
     rc = 2;
     return rc;
   }
 
-  // Get the digitizer object
-  TFile *file = (TFile *) gROOT->GetListOfFiles()->FindObject("TRD_test.root");
-  AliTRDparameter *parameter = (AliTRDparameter *) file->Get("TRDparameter");
-  if (!parameter) {
-    cout << "<AliTRDanalyzeDigits> No parameter object found" << endl;
+  // Import the Trees for the event nEvent in the file
+  rl->LoadKinematics();
+  rl->GetEvent(0);
+  rl->GetHeader();
+  
+  AliLoader* loader = rl->GetLoader("TRDLoader");
+  if (!loader) {
+    cout << "<AliTRDanalyzeHits> No TRDLoader found" << endl;
     rc = 3;
     return rc;
   }
 
+  // Get the pointer to the TRD detector 
+  AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
+  if (!trd) {
+    cout << "<AliTRDanalyzeDigits> No TRD detector found" << endl;
+    rc = 4;
+    return rc;
+  }
+
+  // Get the parameter object
+  AliTRDparameter *parameter = new AliTRDparameter("TRDparameter"
+                                                 ,"TRD parameter class");
+
   // Define the histograms
   Int_t adcRange = ((Int_t) parameter->GetADCoutRange());
   TH1F *hAmpAll   = new TH1F("hAmpAll"  ,"Amplitude of the digits (all)"
@@ -355,7 +319,7 @@ Int_t AliTRDanalyzeDigits()
   }
   else {
     cout << "<AliTRDanalyzeDigits> No TRD geometry found" << endl;
-    rc = 4;
+    rc = 5;
     return rc;
   }
 
@@ -363,12 +327,18 @@ Int_t AliTRDanalyzeDigits()
   AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
   digitsManager->SetDebug(1);
 
-  digitsManager->Open("TRD_test.root");
-
   // Read the digits from the file
-  if (!(digitsManager->ReadDigits())) {
+  if (!(digitsManager->ReadDigits(loader->TreeD()))) {
     cout << "<AliTRDanalyzeDigits> Cannot read the digits" << endl;
-    rc = 5;
+    rc = 6;
+    return rc;
+  }
+
+  // Get the particle stack
+  AliStack *kineStack = rl->Stack();
+  if (!kineStack) {
+    cout << "<AliTRDanalyzeDigits> Cannot find the KINE stack" << endl;
+    rc = 7;
     return rc;
   }
 
@@ -377,7 +347,7 @@ Int_t AliTRDanalyzeDigits()
   Int_t countDigits = 0;
   Int_t iSec        = trd->GetSensSector();
   Int_t iCha        = trd->GetSensChamber();
-  Int_t timeMax     = geo->GetTimeTotal();
+  Int_t timeMax     = parameter->GetTimeTotal();
 
   TProfile *hAmpTimeEl = new TProfile("hAmpTimeEl","Amplitude of the digits (electrons)"
                                      ,timeMax,-0.5,((Double_t) timeMax)-0.5);
@@ -406,7 +376,7 @@ Int_t AliTRDanalyzeDigits()
           Int_t        track1   = digitsManager->GetTrack(1,row,col,time,iDet);
           TParticle   *particle = 0;
           if (track0 > -1) {
-            particle = gAlice->Particle(track0);
+            particle = (TParticle *) kineStack->Particle(track0);
          }
 
           if (amp > 0) {
@@ -480,15 +450,6 @@ Int_t AliTRDanalyzeDigits()
   hAmpTimePi->SetYTitle("Mean amplitude");
   hAmpTimePi->Draw("HIST");
 
-  TFile *fileOut = new TFile("digits_test.root","RECREATE");
-  hAmpAll->Write();
-  hAmpNoise->Write();
-  hAmpEl->Write();
-  hAmpPi->Write();
-  hAmpTimeEl->Write();
-  hAmpTimePi->Write();
-  fileOut->Close();
-
   return rc;
 
 }
@@ -578,7 +539,7 @@ Int_t AliTRDanalyzeCluster()
   TH1F *hClusAll   = new TH1F("hClusAll"  ,"Amplitude of the cluster (all)"     
                                           ,501,-0.5,500.5);
   TH1F *hClusNoise = new TH1F("hClusNoise","Amplitude of the cluster (noise)"   
-                                          ,  5,-0.5,  4.5);
+                                          , 11,-0.5, 10.5);
   TH1F *hClusEl    = new TH1F("hClusEl"   ,"Amplitude of the cluster (electron)"
                                           ,501,-0.5,500.5);
   TH1F *hClusPi    = new TH1F("hClusPi"   ,"Amplitude of the cluster (pion)"    
@@ -642,9 +603,9 @@ Int_t AliTRDanalyzeCluster()
       Int_t    plane    = geo->GetPlane(detector);
       Int_t    chamber  = geo->GetChamber(detector);
       Float_t  energy   = cluster->GetQ();
-      Int_t    track0   = cluster->GetTrackIndex(0);
-      Int_t    track1   = cluster->GetTrackIndex(1);
-      Int_t    track2   = cluster->GetTrackIndex(2);
+      Int_t    track0   = cluster->GetLabel(0);
+      Int_t    track1   = cluster->GetLabel(1);
+      Int_t    track2   = cluster->GetLabel(2);
       TParticle *particle = 0;
       if (track0 > -1) {
         particle = gAlice->Particle(track0);
@@ -696,10 +657,10 @@ Int_t AliTRDanalyzeCluster()
   fun->SetLineColor(2);
   fun->Draw("SAME");
   
-  //cCluster->cd(2);
-  //gPad->SetLogy();
+  cCluster->cd(2);
+  gPad->SetLogy();
   Float_t meanNoise = hClusNoise->GetMean();
-  //hClusNoise->Draw();
+  hClusNoise->Draw();
 
   cCluster->cd(3);
   gPad->SetLogy();