-Int_t AliITSHits2SDigits(const char *inFile = "galice.root"){
+TFile* AccessFile(TString inFile="galice.root", TString acctype="R");
+void writeAR(TFile * fin, TFile *fou);
- // Dynamically link some shared libs
- if (gClassTable->GetID("AliRun") < 0) {
+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
+ } // end if
+
+ // Connect the Root Galice file containing Geometry, Kine and Hits
- // 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 *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
+ TFile *file2 = 0; // possible output file for TreeS
- gAlice->GetEvent(0);
- AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
- if (!ITS) {
+ 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"
<< endl;
return 3;
- } // end if !ITS
- if(!(ITS->GetITSgeom())){
+ } // end if !ITS
+ if(!(ITS->GetITSgeom())){
cerr << " AliITSgeom not found. Can't digitize with out it." << endl;
return 4;
- } // end if
+ } // end if
+
+ TDatime *ct0 = new TDatime(2002,04,26,00,00,00);
+ TDatime ct = file->GetCreationDate();
- if(ct0->GetDate()>ct.GetDate()){
+ 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");
+ 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()
- //make branch
+ if(file2)gAlice->MakeTree("S",file2);
+ // make branch
ITS->MakeBranch("S");
ITS->SetTreeAddress();
- cout << "Digitizing ITS..." << endl;
-
+ cout<<"Making ITS SDigits for event "<<nevent<<endl;
TStopwatch timer;
Long_t size0 = file->GetSize();
- timer.Start();
ITS->Hits2SDigits();
- timer.Stop(); timer.Print();
-
- 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;
-};
+ }
+ timer.Stop();
+ timer.Print();
+
+ // write the AliRun object to the output file
+ if(file2)writeAR(file,file2);
+
+ delete gAlice; gAlice=0;
+ file->Close();
+}
+
+//-------------------------------------------------------------------
+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";
+}
+
+
+
+