-Int_t AliITSHits2Digits(const char *inFile = "galice.root"){
+#if !defined(__CINT__) || defined(__MAKECINT__)
+
+#include "iostream.h"
+#include "TDatetime.h"
+#include "STEER/AliRun.h"
+#include "STEER/AliRunDigitizer.h"
+#include "ITS/AliITSDigitizer.h"
+#include "ITS/AliITS.h"
+#include "ITS/AliITSDetType.h"
+#include "ITS/AliITSresponseSDD.h"
+#include "TStopwatch.h"
+
+#endif
+
+TFile* AccessFile(TString inFile="galice.root", TString acctype="R");
+void writeAR(TFile * fin, TFile *fou);
+Int_t ChangeITSDefaults(TFile *hitfile,AliITS *ITS,TString opt="");
+//#define DEBUG
+Int_t AliITSHits2Digits(TString hitFile = "galice.root",
+ TString digFile = "galiceD.root",TString opt=""){
+ // Standeard ITS Hits to Digits, excluding creation of SDigits.
// Dynamically link some shared libs
if (gClassTable->GetID("AliRun") < 0) {
} // end if
// Connect the Root Galice file containing Geometry, Kine and Hits
-
- TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile);
- if (file) {file->Close(); delete file;}
- cout << "AliITSHits2Digits" << endl;
- file = new TFile(inFile,"UPDATE");
- if (!file->IsOpen()) {
- cerr<<"Can't open "<<inFile<<" !" << endl;
- return 1;
- } // end if !file
- file->ls();
- // 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 *hitfile = 0; // pointer to input file.
+ TFile *digfile = 0; // possible output file for TreeD
+ if(digFile.CompareTo(hitFile) == 0){// write output to same file as input.
+ hitfile = AccessFile(hitFile,"U"); // input file open for update.
+ }else{ // different output file then input file.
+ hitfile = AccessFile(hitFile,"R"); // input file open as read only
+ // open output file and create TreeR on it
+ digfile = gAlice->InitTreeFile("D",digFile);
+ } // end if digFile == hitFile.
AliITS *ITS = (AliITS*)gAlice->GetDetector("ITS");
if (!ITS) {
- cerr<<"AliITSHits2Digits.C : AliITS object not found on file"
+ cerr<<"AliITSHits2DigitsDefault.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
- // Set the simulation models for the three detector types
- AliITSgeom *geom = ITS->GetITSgeom();
-
- // SPD
- cout << "Changing from Default SPD simulation, and responce." << endl;
- 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
- cout << "SPD dimensions " << seg0->Dx() << " " << seg0->Dz() << endl;
- cout << "SPD npixels " << seg0->Npz() << " " << seg0->Npx() << endl;
- cout << "SPD pitches " << seg0->Dpz(0) << " " << seg0->Dpx(0) << endl;
- // end test
+ ChangeITSDefaults(hitfile,ITS,opt);
+ // write the AliRun object to the output file if different from input file.
+ if(digfile) writeAR(hitfile,digfile);
- // SDD
- cout << "Changing from Default SDD simulation, and responce." << endl;
- //Set response functions
- Float_t baseline = 10.;
- Float_t noise = 1.75;
- // 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);
- } // end if !res1
- Float_t fCutAmp = baseline + 2.*noise;
- Int_t cp[8]={0,0,fCutAmp,fCutAmp,0,0,0,0}; //1D
+ TStopwatch timer;
+ Int_t evNumber1 = 0;
+ Int_t evNumber2 = gAlice->GetEventsPerRun();
+ timer.Start();
+ for(Int_t nevent = evNumber1; nevent < evNumber2; nevent++){
+ // cout<<"Producing Digits for event n."<<nevent<<endl;
+ gAlice->GetEvent(nevent);
+ if(!gAlice->TreeD() && digfile == 0){
+ cout << "Having to create the Digits Tree." << endl;
+ gAlice->MakeTree("D");
+ } // end if creating digits tree
+ if(digfile) gAlice->MakeTree("D",digfile);
+ ITS->MakeBranch("D");
+ ITS->SetTreeAddress();
+ ITS->Hits2Digits();
+ } // end for nevent
+ timer.Stop();
+ timer.Print();
+ if(digfile!=0){
+ cout << digFile << " size =" << digfile->GetSize() << endl;
+ }else{
+ cout << hitFile << " size =" << hitfile->GetSize() << endl;
+ } // end if sdigfile!=0
- //res1->SetZeroSupp("2D");
- res1->SetZeroSupp("1D");
- res1->SetNoiseParam(noise,baseline);
- res1->SetDo10to8(kTRUE);
- res1->SetCompressParam(cp);
- res1->SetMinVal(4);
- res1->SetDiffCoeff(3.6,40.);
- AliITSsegmentationSDD *seg1=(AliITSsegmentationSDD*)iDetType->
- GetSegmentationModel();
- if (!seg1) {
- seg1 = new AliITSsegmentationSDD(geom,res1);
- ITS->SetSegmentationModel(1,seg1);
- } // end if !seg1
- AliITSsimulationSDD *sim1 = new AliITSsimulationSDD(seg1,res1);
- sim1->SetDoFFT(1);
- sim1->SetCheckNoise(kFALSE);
- ITS->SetSimulationModel(1,sim1);
+ delete gAlice; // digfile is closed by deleting gAlice if != hitfile.
+ gAlice = 0;
+ hitfile->Close(); hitfile = 0;
+}
+//______________________________________________________________________
+TFile * AccessFile(TString FileName, TString acctype){
+ // Function used to open the input file and fetch the AliRun object
- // SSD
- cout << "Changing from Default SSD simulation, and responce." << endl;
- 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);
+ TFile *retfil = 0;
+ TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(FileName);
+ if(file) {
+ file->Close();
+ delete file;
+ file = 0;
+ } // end if file
+ if(acctype.Contains("U")){
+ file = new TFile(FileName,"UPDATE");
+ } // end if open for update
+ if(acctype.Contains("N") && !file){
+ file = new TFile(FileName,"RECREATE");
+ } // end if open a new file
+ if(!file) file = new TFile(FileName,"READ"); // default readonly
+ if (!file->IsOpen()) {
+ cerr << "Can't open " << FileName << " !" << endl;
+ return retfil;
+ } // end if error opeing file
- if(!gAlice->TreeD()){
- cout << "Having to create the Digits Tree." << endl;
- gAlice->MakeTree("D");
- } // end if !gAlice->TreeD()
- //make branch
- ITS->MakeBranch("D");
- ITS->SetTreeAddress();
- gAlice->GetEvent(0);
- cout << "Digitizing ITS..." << endl;
+ // 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 "<< FileName << "!" << endl;
+ file->Close(); // close file and return error.
+ return retfil;
+ } // end if !gAlice
+ return file;
+}
+//______________________________________________________________________
+void writeAR(TFile * fin, TFile *fou) {
+ TDirectory *current = gDirectory;
+ TTree *TeOld;
+ TTree *TeNew;
+ AliHeader *alhe = new AliHeader();
+ TeOld = (TTree*)fin->Get("TE");
+ TeOld->SetBranchAddress("Header",&alhe);
+ TeOld->SetBranchStatus("*",1);
+ fou->cd();
+ TeNew = TeOld->CloneTree();
+ TeNew->Write(0,TObject::kOverwrite);
+ gAlice->Write(0,TObject::kOverwrite);
+ current->cd();
+ delete alhe;
+#ifdef DEBUG
+ cout << "AliRun object written to file" << endl;
+#endif
+}
+//______________________________________________________________________
+Int_t ChangeITSDefaults(TFile *hitfile,AliITS *ITS,TString opt){
- TStopwatch timer;
- Long_t size0 = file->GetSize();
- timer.Start();
- ITS->Hits2Digits();
- timer.Stop(); timer.Print();
+ TDatime *ct0 = new TDatime(2002,04,26,00,00,00);
+ TDatime ct = hitfile->GetCreationDate();
- 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;
-};
+ 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:" << endl;
+ resp1->Print();
+ } // end if
+ if(opt.Contains("Dubna")){
+ AliITSresponseSPDdubna *resp0 = new AliITSresponseSPDdubna();
+ if(ITS->DetType(0)->GetResponseModel() !=0){
+ delete ((AliITSresponse*)ITS->DetType(0)->GetResponseModel());
+ ITS->DetType(0)->ResponseModel(0);
+ } // end if
+ ITS->DetType(0)->ResponseModel(resp0);
+ AliITSsegmentationSPD *seg0 = (AliITSsegmentationSPD*)ITS->
+ DetType(0)->GetSegmentationModel();
+ AliITSsimulationSPDdubna *sim0 = new AliITSsimulationSPDdubna(seg0,
+ resp0);
+ if(ITS->DetType(0)->GetSimulationModel() !=0){
+ delete ((AliITSsimulation*)ITS->DetType(0)->GetSimulationModel());
+ ITS->DetType(0)->SimulationModel(0);
+ } // end if
+ ITS->DetType(0)->SimulationModel(sim0);
+ } // end if Dubna
+}