]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSHits2Digits.C
renaming function to avoid library conflict (discovered in test/generators/TUHKMgen)
[u/mrichter/AliRoot.git] / ITS / AliITSHits2Digits.C
index 3961f98e17e0d5624958cbc5b903d3694517b3d0..ecfbaf7910a63d809fbb0d5726f8cf022f672bf0 100644 (file)
-Int_t AliITSHits2Digits()
-{
+#if !defined(__CINT__) || defined(__MAKECINT__)
 
-  // Connect the Root Galice file containing Geometry, Kine and Hits
+#include "TROOT.h"
+#include "Riostream.h"
+#include "TDatime.h"
+#include "TClassTable.h"
+#include "AliRun.h"
+#include "AliRunDigitizer.h"
+#include "AliITS.h"
+#include "AliITSDetTypeSim.h"
+#include "AliITSLoader.h"
+#include "AliITSresponseSDD.h"
+#include "TStopwatch.h"
 
-  const char * inFile = "galice.root";  
-  TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile);
-  if (file) {file->Close(); delete file;}
-  printf("Hits2Digits\n");
-  file = new TFile(inFile,"UPDATE");
-  if (!file->IsOpen()) {
-    cerr<<"Can't open "<<inFile<<" !\n";
-    return 1;
-  }
-  file->ls();
+#endif
 
-  // Get AliRun object from file or return if not on file
-  if (gAlice) delete gAlice;
-  gAlice = (AliRun*)file->Get("gAlice");
-  if (!gAlice) {
-    cerr<<"ITSHits2Digits.C : AliRun object not found on file\n";
-    return 2;
-  }
+//#define DEBUG
+Int_t AliITSHits2Digits(TString inFile = "galice.root"){
+    // Standard ITS Hits to Digits, excluding creation of SDigits.
 
-  gAlice->GetEvent(0);
-  AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");      
-  if (!ITS) {
-    cerr<<"ITSHits2Digits.C : AliITS object not found on file\n";
-    return 3;
-  }
+    // 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;
+     } 
 
-// Set the simulation models for the three detector types
-  AliITSgeom *geom = ITS->GetITSgeom();
+   AliRunLoader* rl = AliRunLoader::Open(inFile.Data());
+    if (rl == 0x0)
+     {
+      cerr<<"AliITSHits2Digits.C : Can not open session RL=NULL"
+           << endl;
+       return 3;
+     }
+     
+    Int_t retval = rl->LoadgAlice();
+    if (retval)
+     {
+      cerr<<"AliITSHits2Digits.C : LoadgAlice returned error"
+           << endl;
+       return 3;
+     }
+    gAlice=rl->GetAliRun();
+    AliITSLoader* gime = (AliITSLoader*)rl->GetLoader("ITSLoader");
+    if (gime == 0x0)
+     {
+      cerr<<"AliITSHits2Digits.C : can not get ITS loader"
+           << endl;
+     }
+    AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");      
+    if (!ITS) {
+       cerr<<"AliITSHits2Digit.C : AliITS object not found on file"
+           << endl;
+       return 3;
+    }  // end if !ITS
 
-  // SPD
-  AliITSDetType *iDetType=ITS->DetType(0);
-  AliITSsegmentationSPD *seg0=(AliITSsegmentationSPD*)iDetType->GetSegmentationModel();
-  AliITSresponseSPD *res0 = (AliITSresponseSPD*)iDetType->GetResponseModel();
-  AliITSsimulationSPD *sim0=new AliITSsimulationSPD(seg0,res0);
-  ITS->SetSimulationModel(0,sim0);
-  // test
-  printf("SPD dimensions %f %f \n",seg0->Dx(),seg0->Dz());
-  printf("SPD npixels %d %d \n",seg0->Npz(),seg0->Npx());
-  printf("SPD pitches %d %d \n",seg0->Dpz(0),seg0->Dpx(0));
-  // end test
+    if(!(ITS->GetITSgeom())){
+       cerr << " AliITSgeom not found. Can't digitize without it." << endl;
+       return 4;
+    } // end if
 
-  // SDD
-  // Set response parameters
-  // SDD compression param: 2 fDecrease, 2fTmin, 2fTmax or disable, 2 fTolerance
-  AliITSDetType *iDetType=ITS->DetType(1);
-  AliITSresponseSDD *res1 = (AliITSresponseSDD*)iDetType->GetResponseModel();
-  if (!res1) {
-    res1=new AliITSresponseSDD();
-    ITS->SetResponseModel(1,res1);
-  }
-   Float_t baseline;
-   Float_t noise;
-   res1->GetNoiseParam(noise,baseline);
-   Float_t noise_after_el = res1->GetNoiseAfterElectronics();
-   cout << "noise_after_el: " << noise_after_el << endl; 
-   Float_t fCutAmp;
-   fCutAmp = baseline;
-   fCutAmp += (2.*noise_after_el);  // noise
-   cout << "Cut amplitude: " << fCutAmp << endl;
-   Int_t cp[8]={0,0,fCutAmp,fCutAmp,0,0,0,0};
-   res1->SetCompressParam(cp);
+    
 
-   res1->Print();
-  AliITSsegmentationSDD *seg1=(AliITSsegmentationSDD*)iDetType->GetSegmentationModel();
-  if (!seg1) {
-    seg1 = new AliITSsegmentationSDD(geom,res1);
-    ITS->SetSegmentationModel(1,seg1);
-  }
-  AliITSsimulationSDD *sim1=new AliITSsimulationSDD(seg1,res1);
-  ITS->SetSimulationModel(1,sim1);
+    TStopwatch timer;
+    Int_t evNumber1 = 0;
+    Int_t evNumber2 = rl->GetNumberOfEvents();
+    timer.Start();
+    retval = gime->LoadHits();
+    if (retval)
+     {
+      cerr<<"AliITSHits2Digits.C : ITSLoader::LoadHits returned error"
+           << endl;
+       return 3;
+     }
 
-  // SSD
-  AliITSDetType *iDetType=ITS->DetType(2);
-  AliITSsegmentationSSD *seg2=(AliITSsegmentationSSD*)iDetType->GetSegmentationModel();
-  AliITSresponseSSD *res2 = (AliITSresponseSSD*)iDetType->GetResponseModel();
-  res2->SetSigmaSpread(3.,2.);
-  AliITSsimulationSSD *sim2=new AliITSsimulationSSD(seg2,res2);
-  ITS->SetSimulationModel(2,sim2);
+    retval = gime->LoadDigits("recreate");
+    if (retval)
+     {
+      cerr<<"AliITSHits2Digits.C : ITSLoader::LoadDigits returned error"
+           << endl;
+       return 3;
+     }
+    for(Int_t nevent = evNumber1; nevent < evNumber2; nevent++){
+       // cout<<"Producing Digits for event n."<<nevent<<endl;
 
-  cerr<<"Digitizing ITS...\n";
-
-   if(!gAlice->TreeD()) gAlice->MakeTree("D");
-   printf("TreeD %p\n",gAlice->TreeD());
-   //make branch
-   ITS->MakeBranch("D");
-  
-  TStopwatch timer;
-  timer.Start();
-  ITS->HitsToDigits(0,0,-1," ","All"," ");
-  timer.Stop(); timer.Print();
-
-  delete sim0;
-  delete sim1;
-  delete sim2;
-
-
-  delete gAlice;   gAlice=0;
-  file->Close(); 
-  delete file;
-  return 0;
-};
+       rl->GetEvent(nevent);
+       if(!gime->TreeD()){ 
+           cout << "Having to create the Digits Tree." << endl;
+           gime->MakeTree("D");
+       } // end if creating digits tree
+       ITS->MakeBranch("D");
+       ITS->SetTreeAddress();   
+       ITS->Hits2Digits();
+    } // end for nevent
+    timer.Stop();
+    timer.Print();
 
+    delete rl;
+    return 0;
+}