]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSHits2SDigits.C
1) Added classes for digitization
[u/mrichter/AliRoot.git] / ITS / AliITSHits2SDigits.C
index c0bd7bad944e13b8f8d27de07aa5f18e54d886f2..2f53e133a5a6a947642a2c244e825ac73ea61902 100644 (file)
-TFile* AccessFile(TString inFile="galice.root", TString acctype="R");
-void writeAR(TFile * fin, TFile *fou);
-
-Int_t AliITSHits2SDigits(Int_t evNumber1=0,Int_t evNumber2=0, TString inFile = "galice.root", TString outFile="galice.root"){
-
-  // Dynamically link some shared libs
-  if (gClassTable->GetID("AliRun") < 0) {
-       gROOT->LoadMacro("loadlibs.C");
-       loadlibs();
-  } // end if
-
-  // Connect the Root Galice file containing Geometry, Kine and Hits
-
-  TFile *file;
-  if(outFile.Data() == inFile.Data()){
-    file = AccessFile(inFile,"U");
-  }
-  else {
-    file = AccessFile(inFile);
-  }
-  
-  TFile *file2 = 0;  // possible output file for TreeS
-
-  if(!(outFile.Data() == inFile.Data())){
-    // open output file and create TreeS on it
-    file2 = gAlice->InitTreeFile("S",outFile);
-  }
-
-  AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");      
-  if (!ITS) {
-       cerr<<"AliITSHits2DigitsDefault.C : AliITS object not found on file"
+#if !defined(__CINT__) || defined(__MAKECINT__)
+
+#include "Riostream.h"
+#include "TDatime.h"
+#include "TClassTable.h"
+#include "AliRun.h"
+#include "AliRunDigitizer.h"
+#include "AliITSDigitizer.h"
+#include "AliITS.h"
+#include "AliITSDetType.h"
+#include "AliITSLoader.h"
+#include "AliITSresponseSDD.h"
+#include "TStopwatch.h"
+
+#endif
+
+Int_t AliITSHits2SDigits(TString  filename = "galice.root")
+ {
+    // Standard ITS Hits to SDigits.
+
+    // Dynamically link some shared libs
+    if (gClassTable->GetID("AliRun") < 0) {
+      gROOT->ProcessLine(".x $(ALICE_ROOT)/macros/loadlibs.C");
+    }else if (gAlice){
+      delete AliRunLoader::Instance();
+      delete gAlice;
+      gAlice=0;
+     } 
+
+    // Connect the Root Galice file containing Geometry, Kine and Hits
+
+    AliRunLoader* rl = AliRunLoader::Open(filename);
+    if (rl == 0x0)
+     {
+      cerr<<"AliITSHits2SDigits.C : Can not open session RL=NULL"
+           << endl;
+       return 3;
+     }
+     
+    Int_t retval = rl->LoadgAlice();
+    if (retval)
+     {
+      cerr<<"AliITSHits2SDigits.C : LoadgAlice returned error"
+           << endl;
+       return 3;
+     }
+    gAlice=rl->GetAliRun();
+    AliITSLoader* gime = (AliITSLoader*) rl->GetLoader("ITSLoader");
+    if (gime == 0x0)
+     {
+      cerr<<"AliITSHits2SDigits.C : can not get ITS loader"
+           << endl;
+     }
+    AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");      
+    if (!ITS) {
+       cerr<<"AliITSHits2SDigits.C : AliITS object not found on file"
            << endl;
        return 3;
-  }  // end if !ITS
-  if(!(ITS->GetITSgeom())){
-       cerr << " AliITSgeom not found. Can't digitize with out it." << endl;
-       return 4;
-  } // end if
+    }  // end if !ITS
+    if(!(ITS->GetITSgeom())){
+       cerr << " AliITSgeom not found. Can't digitize without it." << endl;
+       return 4;
+    } // end if
 
-  TDatime *ct0 = new TDatime(2002,04,26,00,00,00);
-  TDatime ct = file->GetCreationDate();
-
-  if(ct0->GetDate()>ct.GetDate()){
-       // For old files, must change SDD noise.
-    AliITSresponseSDD *resp1 = (AliITSresponseSDD*)ITS->DetType(1)->GetResponseModel();
-    resp1 = new AliITSresponseSDD();
-    ITS->SetResponseModel(1,resp1);
-    cout << "Changed response class for SDD: \n";
-    resp1->Print();
-  } // end if
-  TStopwatch timer;
-  timer.Start();
-  for(Int_t nevent = evNumber1; nevent <= evNumber2; nevent++){
-    gAlice->GetEvent(nevent);
-    if(!gAlice->TreeS() && file2 == 0){ 
-      cout << "Having to create the SDigits Tree." << endl;
-      gAlice->MakeTree("S");
-    } // end if !gAlice->TreeS()
-    if(file2)gAlice->MakeTree("S",file2);
-    //    make branch
-    ITS->MakeBranch("S");
-    ITS->SetTreeAddress();
-    cout<<"Making ITS SDigits for event "<<nevent<<endl;
     TStopwatch timer;
-    Long_t size0 = file->GetSize();
-    ITS->Hits2SDigits();
-  }
-  timer.Stop();
-  timer.Print();
-
-  // write the AliRun object to the output file
-  if(file2)writeAR(file,file2);
-
-  delete gAlice;   gAlice=0;
-  file->Close();
+    Int_t evNumber1 = 0;
+    Int_t evNumber2 = AliRunLoader::GetNumberOfEvents();
+    timer.Start();
+    retval = gime->LoadHits();
+    if (retval)
+     {
+      cerr<<"AliITSHits2SDigits.C : ITSLoader::LoadHits returned error"
+           << endl;
+       return 3;
+     }
+    retval = gime->LoadSDigits("recreate");
+    if (retval)
+     {
+      cerr<<"AliITSHits2SDigits.C : ITSLoader::LoadSDigits returned error"
+           << endl;
+       return 3;
+     }
+    for(Int_t event = evNumber1; event < evNumber2; event++){
+       rl->GetEvent(event);
+       if(!gime->TreeS()){ 
+           cout << "Having to create the SDigits Tree." << endl;
+           gime->MakeTree("S");
+       } // end 
+
+       ITS->MakeBranch("S");
+       ITS->SetTreeAddress();
+       cout<<"Making ITS SDigits for event "<<event<<endl;
+       ITS->Hits2SDigits();
+    } // end for event
+    timer.Stop();
+    timer.Print();
+
+    delete rl; // sdigfile is closed by deleting gAlice if != hitfile.
+    return 0;
 }
-
-//-------------------------------------------------------------------
-TFile * AccessFile(TString FileName, TString acctype){
-
-  // Function used to open the input file and fetch the AliRun object
-
-  TFile *retfil = 0;
-  TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName);
-  if (file) {file->Close(); delete file; file = 0;}
-  if(acctype.Contains("U")){
-    file = new TFile(FileName,"update");
-  }
-  if(acctype.Contains("N") && !file){
-    file = new TFile(FileName,"recreate");
-  }
-  if(!file) file = new TFile(FileName);   // default readonly
-  if (!file->IsOpen()) {
-       cerr<<"Can't open "<<FileName<<" !" << endl;
-       return retfil;
-  } 
-
-  // Get AliRun object from file or return if not on file
-  if (gAlice) {delete gAlice; gAlice = 0;}
-  gAlice = (AliRun*)file->Get("gAlice");
-  if (!gAlice) {
-       cerr << "AliRun object not found on file"<< endl;
-       return retfil;
-  } 
-  return file;
-}
-
-//-------------------------------------------------------------------
-void writeAR(TFile * fin, TFile *fou) {
-  TDirectory *current = gDirectory;
-  TTree *Te;
-  TTree *TeNew;
-  AliHeader *alhe = new AliHeader();
-  Te = (TTree*)fin->Get("TE");
-  Te->SetBranchAddress("Header",&alhe);
-  Te->SetBranchStatus("*",1);
-  fou->cd();
-  TeNew = Te->CloneTree();
-  TeNew->Write(0,TObject::kOverwrite);
-  gAlice->Write(0,TObject::kOverwrite);
-  current->cd();
-  delete alhe;
-  cout<<"AliRun object written to file\n";
-}
-
-
-
-
-