]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliHits2SDigits.C
Adding RICH and updating PHOS part (Yu.Belikov)
[u/mrichter/AliRoot.git] / STEER / AliHits2SDigits.C
index 58561aaea5848a7d5b47f7c4dd51a945a5f1bf1e..fd52832a684cb5042d1bb565c6a64c021cd98604 100644 (file)
@@ -8,50 +8,45 @@
 //
 // description: 
 //       creates sdigits for several detectors
-//       stores sdigits in separate file (or in the source file
-//       with hits). Stores gAlice object and copies TE to the
-//       file with sdigits
 //
 // input:
-//       TString fileNameSDigits ... output file with sdigits
-//       TString fileNameHits ... input file with hits
+//       TString fileName ... galice input file
 //       Int_t nEvents  ... how many events to proceed
 //       Int_t firstEvent  ... first event number
 //       Int_t ITS, TPC, ...   many flags for diff. detectors
 //
 // History:
 //
+// 21.07.03 - changes for NewIO
+//
 // 04.04.02 - first version
 // 
 ////////////////////////////////////////////////////////////////////////
 
 #if !defined(__CINT__) || defined(__MAKECINT__)
-#include "Riostream.h"
+#include "iostream.h"
 #include "TTree.h"
 #include "TBranch.h"
 #include "TDirectory.h"
 #include "TFile.h"
 #include "AliRun.h"
 #include "TParticle.h"
-#include "AliTPCDigitsArray.h"
+#include "TPC/AliTPCDigitsArray.h"
 #include "AliHeader.h"
 #include "TGeometry.h"
 #include "TObjArray.h"
 #include "TString.h"
-#include "AliITS.h"
-#include "AliTPC.h"
-#include "AliPHOSSDigitizer.h"
-#include "AliTRDdigitizer.h"
+#include "ITS/AliITS.h"
+#include "TPC/AliTPC.h"
+#include "PHOS/AliPHOSSDigitizer.h"
+#include "TRD/AliTRDdigitizer.h"
 #include "TStopwatch.h"
-#include "AliTRDparameter.h"
-#include "AliTOFSDigitizer.h"
+#include "TRD/AliTRDparameter.h"
 #endif
 
-TFile* Init(TString fileNameSDigits, TString fileNameHits);
-TFile* OpenFile(TString fileName);
-Bool_t ImportgAlice(TFile *file);
+AliRunLoader* Init(TString fileName);
+
 AliTRDdigitizer *InitTRDdigitizer();
-void AliCopy(TFile *inputFile, TFile *outputFile);
 
 // global variables
 
@@ -60,38 +55,31 @@ Bool_t gSameFiles = kFALSE;
 Int_t gDEBUG = 1;
 
 
-Int_t AliHits2SDigits(TString fileNameSDigits="sdigits.root", 
-                     TString fileNameHits="rfio:galice.root", 
-                     Int_t nEvents = 1, Int_t firstEvent = 0, Int_t iITS = 0,
-                     Int_t iTPC = 0, Int_t iTRD = 0,Int_t iPHOS = 0, 
-                     Int_t iTOF = 0, Int_t iCopy = 1)
+Int_t AliHits2SDigits(TString fileName="galice.root", 
+                  Int_t nEvents = 1, Int_t firstEvent = 0, Int_t iITS = 0,
+                  Int_t iTPC = 0, Int_t iTRD = 0,Int_t iPHOS = 0)
 {
 //
 // Initialization
 //
-  TFile *fileSDigits;
-  fileSDigits = Init(fileNameSDigits, fileNameHits);
-  if (!fileSDigits) return 1;
-  if (iCopy) {
-    AliCopy(gFileHits,fileSDigits);
-    gFileHits->cd();
-  }  
+  AliRunLoader* rl = Init(fileName);
+  if (!rl) return 1;
 
 // ITS
-  AliITS *ITS;
+  AliITS *ITS = NULL;
   if (iITS) {
     ITS  = (AliITS*) gAlice->GetModule("ITS");
     if (!ITS) {
       iITS = 0;
       cerr<<"AliITS object not found on file." << endl;
     } else if (!ITS->GetITSgeom()) {
-      iITS = 0;
       cerr<<"AliITSgeom not found." << endl;
+      iITS = 0;
     }
   }
 
 // TPC
-  AliTPC *TPC;
+  AliTPC *TPC = NULL;
   if (iTPC) {
     TPC = (AliTPC*)gAlice->GetDetector("TPC");
     if (!TPC) {
@@ -101,23 +89,19 @@ Int_t AliHits2SDigits(TString fileNameSDigits="sdigits.root",
   }
 
 // TRD
-  AliTRDdigitizer *sdTRD;
+  AliTRDdigitizer *sdTRD = NULL;
   if (iTRD) {
     sdTRD = InitTRDdigitizer();
   }
 
 
 // PHOS
-  AliPHOSSDigitizer *sdPHOS;
+  AliPHOSSDigitizer *sdPHOS = NULL;
   if (iPHOS) {
-    sdPHOS = new AliPHOSSDigitizer(fileNameHits.Data());
+    sdPHOS = new AliPHOSSDigitizer(fileName.Data());
   }
 
-// TOF
-  AliTOFSDigitizer *sdTOF;
-  if (iTOF) {
-    sdTOF = new AliTOFSDigitizer(fileNameHits.Data(),firstEvent,nEvents);
-  }
+
 
 //
 // loop over events
@@ -125,52 +109,62 @@ Int_t AliHits2SDigits(TString fileNameSDigits="sdigits.root",
   TStopwatch timer;
   timer.Start();
   for (Int_t iEvent = firstEvent;iEvent<firstEvent+nEvents;iEvent++){
-    gAlice->GetEvent(iEvent);
-    if (!gAlice->TreeS()) gAlice->MakeTree("S",fileSDigits);
+    rl->GetEvent(iEvent);
+//    gAlice->MakeTree("S",fileSDigits);
     
 // ITS
     if (iITS) {
       if (gDEBUG) {cout<<"  Create ITS sdigits: ";}
-      ITS->MakeBranch("S");
-      ITS->SetTreeAddress();
-      ITS->Hits2SDigits();
-      if (gDEBUG) {cout<<"done"<<endl;}
+      AliLoader* loader = rl->GetLoader("ITSLoader");
+      if (loader)
+       { 
+        loader->LoadHits("read");
+        loader->LoadSDigits("recreate");
+       if(!loader->TreeS()) loader->MakeTree("S");
+       ITS->MakeBranch("S");
+        ITS->SetTreeAddress();
+        ITS->Hits2SDigits();
+        loader->UnloadHits();
+        loader->UnloadSDigits();
+        if (gDEBUG) {cout<<"done"<<endl;}
+       }
+      else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
     }
 
 // TPC
     if (iTPC) {
       if (gDEBUG) {cout<<"  Create TPC sdigits: ";}
-      if (iTPC == 1) {
-// process all sectors
-       TPC->SetActiveSectors(1);
-       if (gDEBUG) {cout<<"All TPC sectors set active."<<endl;}
-      } else if (iTPC == 2) {
-// process only sectors with hits
-       TPC->SetActiveSectors(0);
-       if (gDEBUG) {
-         printf("\nActive sectors\n");
-         Int_t iActive = 0;
-         for (Int_t i=0;i<72;i++) {
-           if (TPC->IsSectorActive(i)) {
-             printf("%2d ",i);
-             iActive++;
-             if (iActive%10 == 0) printf("\n");
-           }
-         }
-         printf("\n");
-       }
-      }    
-      TPC->Hits2SDigits2(iEvent);
-      if (gDEBUG) {cout<<"done"<<endl;}
+      AliLoader* loader = rl->GetLoader("TPCLoader");
+      if (loader)
+       { 
+        loader->LoadHits("read");
+        loader->LoadSDigits("recreate");
+      
+       TPC->SetTreeAddress();
+        TPC->SetActiveSectors(1);
+        TPC->Hits2SDigits2(iEvent);
+        loader->UnloadHits();
+        loader->UnloadSDigits();
+        if (gDEBUG) {cout<<"done"<<endl;}
+       }
+      else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
     }
 
 // TRD
     if (iTRD) {
       if (gDEBUG) {cout<<"  Create TRD sdigits: ";}
-      sdTRD->InitOutput(fileSDigits, iEvent);
-      sdTRD->MakeDigits();
-      sdTRD->WriteDigits();
-      if (gDEBUG) {cout<<"done"<<endl;}
+      AliLoader* loader = rl->GetLoader("TRDLoader");
+      if (loader)
+       { 
+        loader->LoadHits("read");
+        loader->LoadSDigits("recreate");
+        sdTRD->MakeDigits();
+        sdTRD->WriteDigits();
+        loader->UnloadHits();
+        loader->UnloadSDigits();
+        if (gDEBUG) {cout<<"done"<<endl;}
+       }
+      else if (gDEBUG) {cout<<"Did not get loader"<<endl;}
     }
     
   } // end of loop over events
@@ -180,125 +174,44 @@ Int_t AliHits2SDigits(TString fileNameSDigits="sdigits.root",
     sdPHOS->ExecuteTask("deb all");
   }
 
-// TOF does its own loop
-  if (iTOF) {
-    sdTOF->Exec("");
-  }
-
-
 //
 // finish 
 //
   timer.Stop(); 
   timer.Print();
 
-  if (iTRD) { 
-    fileSDigits->cd();
-    sdTRD->GetParameter()->Write();
-  }
-
-  gFileHits->cd();
-  delete gAlice;
-  gAlice = 0;
-  if (!gSameFiles) {
-    gFileHits->Close();
-    delete gFileHits;
-  }
-
+  delete rl;
+  return 0;
 }
  
 
 ////////////////////////////////////////////////////////////////////////
-TFile* Init(TString fileNameSDigits, TString fileNameHits) {
+AliRunLoader* Init(TString fileName) 
+ {
 // open input file, read in gAlice, prepare output file
   if (gAlice) delete gAlice;
   gAlice = 0;
-
-  Bool_t gSameFiles = kFALSE;
-  if (fileNameSDigits == fileNameHits || fileNameSDigits == "") gSameFiles = kTRUE;
-
-  TString fileMode = "read";
-  if (gSameFiles) fileMode = "update";
-
-  gFileHits =  TFile::Open(fileNameHits.Data(),fileMode.Data());
-  if (!gFileHits->IsOpen()) {
-    cerr<<"Can't open "<<fileNameHits.Data()<<" !\n";
-    return 0;
-  }
-  if (!ImportgAlice(gFileHits)) return 0;
-  if (!gSameFiles) return gAlice->InitTreeFile("S",fileNameSDigits.Data());
-  return gFileHits;
-
+  AliRunLoader*rl = AliRunLoader::Open(fileName);
+  if (rl == 0x0) return 0x0;
+  rl->LoadgAlice();
+  gAlice = rl->GetAliRun();
+  return rl;
 }
 
-////////////////////////////////////////////////////////////////////////
-TFile* OpenFile(TString fileName) {
-// open file fileName
-  TFile *file = TFile::Open(fileName.Data());
-  if (!file->IsOpen()) {
-    cerr<<"Can't open "<<fileName.Data()<<" !\n";
-    return 0;
-  }
-  return file;
-}
 
 ////////////////////////////////////////////////////////////////////////
-Bool_t ImportgAlice(TFile *file) {
-// read in gAlice object from the file
-  gAlice = (AliRun*)file->Get("gAlice");
-  if (!gAlice)  return kFALSE;
-  return kTRUE;
-}
 ////////////////////////////////////////////////////////////////////////
 AliTRDdigitizer *InitTRDdigitizer() {
 // initialization of TRD digitizer
   AliTRDdigitizer *sdTRD = new AliTRDdigitizer("TRDdigitizer"
-                                              ,"TRD digitizer class");
+                                     ,"TRD digitizer class");
   sdTRD->SetDebug(0);
   sdTRD->SetSDigits(kTRUE);
   AliTRDparameter *TRDparam = new AliTRDparameter("TRDparameter"
-                                                 ,"TRD parameter class");
+                                      ,"TRD parameter class");
 
   sdTRD->SetParameter(TRDparam);
   sdTRD->InitDetector();
-  if (!sdTRD->MakeBranch()) {
-    cerr<<"Problems with TRD digitizer initialization."<<endl;
-  }
   return sdTRD;
 }
-////////////////////////////////////////////////////////////////////////
-void AliCopy(TFile *inputFile, TFile *outputFile) {
-// copy some objects
-
-// copy gAlice
-  if (gDEBUG) cout<<"Copy gAlice: ";
-  outputFile->cd();
-  gAlice->Write();
-  if (gDEBUG) cout<<"done"<<endl;
-
-  TTree *treeE  = gAlice->TreeE();
-  if (!treeE) {
-    cerr<<"No TreeE found "<<endl;
-    return;
-  }      
-
-// copy TreeE
-  if (gDEBUG) cout<<"Copy TreeE: ";
-  AliHeader *header = new AliHeader();
-  treeE->SetBranchAddress("Header", &header);
-  treeE->SetBranchStatus("*",1);
-  TTree *treeENew =  treeE->CloneTree();
-  treeENew->Write();
-  if (gDEBUG) cout<<"done"<<endl;
-
-// copy AliceGeom
-  if (gDEBUG) cout<<"Copy AliceGeom: ";
-  TGeometry *AliceGeom = static_cast<TGeometry*>(inputFile->Get("AliceGeom"));
-  if (!AliceGeom) {
-    cerr<<"AliceGeom was not found in the input file "<<endl;
-    return;
-  }
-  AliceGeom->Write();
-  if (gDEBUG) cout<<"done"<<endl;
-
-}