]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSHits2SDigits.C
Made Track Hypothesis container to derive from AliKalmanTrack for ESD update
[u/mrichter/AliRoot.git] / ITS / AliITSHits2SDigits.C
index d7fef4dce1a763c65b1316e5dcfba35b9365efc8..2f53e133a5a6a947642a2c244e825ac73ea61902 100644 (file)
-Int_t AliITSHits2SDigits(const char *inFile = "galice.root"){
+#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->LoadMacro("loadlibs.C");
-       loadlibs();
-    } // end if
+      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
-  
-    TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile);
-    if (file) {file->Close(); delete file;}
-    cout << "AliITSHits2SDigitsDefault" << endl;
-    file = new TFile(inFile,"UPDATE");
-    if (!file->IsOpen()) {
-       cerr<<"Can't open "<<inFile<<" !" << endl;
-       return 1;
-    } // end if !file
-    file->ls();
-    if(!file) file = new TFile(fileNameSDigitsSig.Data());
-    TDatime *ct0 = new TDatime(2002,04,26,00,00,00), ct = file->GetCreationDate();
-
-    // Get AliRun object from file or return if not on file
-    if (gAlice) delete gAlice;
-    gAlice = (AliRun*)file->Get("gAlice");
-    if (!gAlice) {
-       cerr << "AliITSITSHits2Digits.C : AliRun object not found on file"
-           << endl;
-       return 2;
-    } // end if !gAlice
 
-    gAlice->GetEvent(0);
+    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<<"AliITSHits2DigitsDefault.C : AliITS object not found on file"
+       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;
+       cerr << " AliITSgeom not found. Can't digitize without it." << endl;
+       return 4;
     } // end if
 
-    if(ct0->GetDate()>ct.GetDate()){
-       // For old files, must change SDD noise.
-       AliITS *ITS = (AliITS*) gAlice->GetDetector("ITS");
-       AliITSresponseSDD *resp1 = ITS->DetType(1)->GetResponseModel();
-       resp1->SetNoiseParam();
-       resp1->SetNoiseAfterElectronics();
-       Float_t n,b;
-       Int_t cPar[8];
-       resp1->GetNoiseParam(n,b);
-       n = resp1->GetNoiseAfterElectronics();
-       cPar[0]=0;
-       cPar[1]=0;
-       cPar[2]=(Int_t)(b + 2.*n + 0.5);
-       cPar[3]=(Int_t)(b + 2.*n + 0.5);
-       cPar[4]=0;
-       cPar[5]=0;
-       cPar[6]=0;
-       cPar[7]=0;
-       resp1->SetCompressParam(cPar);
-    } // end if
-
-    if(!gAlice->TreeS()){ 
-       cout << "Having to create the SDigits Tree." << endl;
-       gAlice->MakeTree("S");
-    } // end if !gAlice->TreeS()
-    //make branch
-    ITS->MakeBranch("S");
-    ITS->SetTreeAddress();
-    cout << "Digitizing ITS..." << endl;
-
     TStopwatch timer;
-    Long_t size0 = file->GetSize();
+    Int_t evNumber1 = 0;
+    Int_t evNumber2 = AliRunLoader::GetNumberOfEvents();
     timer.Start();
-    ITS->Hits2SDigits();
-    timer.Stop(); timer.Print();
+    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 
 
-    delete gAlice;   gAlice=0;
-    file->Close();
-    Long_t size1 = file->GetSize();
-    cout << "File size before = " << size0 << " file size after = " << size1;
-    cout << "Increase in file size is " << size1-size0 << " Bytes" << endl;
-    delete file;
-    return 0;
-};
+       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;
+}