From cc2535cd11694b214d08613a69ebde5d3627813f Mon Sep 17 00:00:00 2001 From: barbera Date: Tue, 11 Jun 2002 15:58:49 +0000 Subject: [PATCH] new macros compliant with multiple events/files for TreeS,D,R --- ITS/AliITSDigits2RecPoints.C | 68 +++++++++--- ITS/AliITSHits2Digits.C | 128 ++++++++++++++++++++++ ITS/AliITSHits2FastRecPoints.C | 188 +++++++++++++++++---------------- ITS/AliITSHits2SDR.C | 16 ++- ITS/AliITSHits2SDigits.C | 177 +++++++++++++++++++------------ ITS/AliITSSDigits2Digits.C | 64 +++++++++-- 6 files changed, 451 insertions(+), 190 deletions(-) create mode 100644 ITS/AliITSHits2Digits.C diff --git a/ITS/AliITSDigits2RecPoints.C b/ITS/AliITSDigits2RecPoints.C index 962cccc7162..e0dc51d2acd 100644 --- a/ITS/AliITSDigits2RecPoints.C +++ b/ITS/AliITSDigits2RecPoints.C @@ -1,15 +1,55 @@ -void AliITSDigits2RecPoints(Int_t evNumber1=0,Int_t evNumber2=0, const char *filename="galice.root"){ - TStopwatch timer; - - if(gAlice){ - delete gAlice; - gAlice = 0; - } // end if gAlice - cout << "Creating reconstructed points from digits for the ITS..." << endl; - AliITSreconstruction *itsr = new AliITSreconstruction(filename); - timer.Start(); - itsr->Init(); - itsr->Exec(); - timer.Stop(); timer.Print(); - delete itsr; +TFile* AccessFile(TString inFile="galice.root", TString acctype="R"); + +void AliITSDigits2RecPoints(TString inFile="galice.root", TString outFile="galice.root"){ + + TFile *file; + if(outFile.Data() == inFile.Data()){ + file = AccessFile(inFile,"U"); + } + else { + file = AccessFile(inFile); + } + + TStopwatch timer; + + cout << "Creating reconstructed points from digits for the ITS..." << endl; + const char *nulptr=0; + AliITSreconstruction *itsr = new AliITSreconstruction(nulptr); + if(outFile.Data() != inFile.Data())itsr->SetOutputFile(outFile); + timer.Start(); + itsr->Init(); + itsr->Exec(); + timer.Stop(); + timer.Print(); + delete itsr; +} + +//------------------------------------------------------------------- +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 "<Get("gAlice"); + if (!gAlice) { + cerr << "AliRun object not found on file"<< endl; + return retfil; + } + return file; } diff --git a/ITS/AliITSHits2Digits.C b/ITS/AliITSHits2Digits.C new file mode 100644 index 00000000000..0c3675c34b1 --- /dev/null +++ b/ITS/AliITSHits2Digits.C @@ -0,0 +1,128 @@ +TFile* AccessFile(TString inFile="galice.root", TString acctype="R"); +void writeAR(TFile * fin, TFile *fou); + +Int_t AliITSHits2Digits(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 TreeD + + if(!(outFile.Data() == inFile.Data())){ + // open output file and create TreeR on it + file2 = gAlice->InitTreeFile("D",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())){ + cerr << " AliITSgeom not found. Can't digitize with out 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++){ + cout<<"Producing Digits for event n."<GetEvent(nevent); + if(!gAlice->TreeD() && file2 == 0){ + cout << "Having to create the Digits Tree." << endl; + gAlice->MakeTree("D"); + } + if(file2)gAlice->MakeTree("D",file2); + ITS->MakeBranch("D"); + ITS->SetTreeAddress(); + ITS->Hits2Digits(); + } + 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 "<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"; +} + + + + + diff --git a/ITS/AliITSHits2FastRecPoints.C b/ITS/AliITSHits2FastRecPoints.C index 7ea5eba75c9..d5d3eec6c54 100644 --- a/ITS/AliITSHits2FastRecPoints.C +++ b/ITS/AliITSHits2FastRecPoints.C @@ -1,101 +1,107 @@ -#include "iostream.h" +TFile* AccessFile(TString inFile="galice.root", TString acctype="R"); -void AliITSHits2FastRecPoints (Int_t evNumber1=0,Int_t evNumber2=0,Int_t nsignal=25, Int_t size=-1) +void AliITSHits2FastRecPoints (Int_t evNumber1=0,Int_t evNumber2=0, TString inFile = "galice.root", TString outFile="galice.root", Int_t nsignal=25, Int_t size=-1) { -///////////////////////////////////////////////////////////////////////// -// This macro is a small example of a ROOT macro -// illustrating how to read the output of GALICE -// and do some analysis. -// -///////////////////////////////////////////////////////////////////////// - -// Dynamically link some shared libs - - if (gClassTable->GetID("AliRun") < 0) { - gROOT->LoadMacro("loadlibs.C"); - loadlibs(); - } else { - delete gAlice; - gAlice=0; - } - -// Connect the Root Galice file containing Geometry, Kine and Hits - - TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject("galice.root"); - if (file) file->Close(); - file = new TFile("galice.root","UPDATE"); - file->ls(); - - printf ("I'm after Map \n"); - -// Get AliRun object from file or create it if not on file - - if (!gAlice) { - gAlice = (AliRun*)file->Get("gAlice"); - if (gAlice) printf("AliRun object found on file\n"); - if (!gAlice) gAlice = new AliRun("gAlice","Alice test program"); - } - printf ("I'm after gAlice \n"); - - AliITS *ITS = (AliITS*) gAlice->GetModule("ITS"); - if (!ITS) return; + ///////////////////////////////////////////////////////////////////////// + // + // This macro creates fast recpoints, optionally on a separate file + // + ///////////////////////////////////////////////////////////////////////// + + // Dynamically link some shared libs + + if (gClassTable->GetID("AliRun") < 0) { + gROOT->LoadMacro("loadlibs.C"); + loadlibs(); + } else { + delete gAlice; + gAlice=0; + } + + // 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 TreeR + if(!(outFile.Data() == inFile.Data())){ + // open output file and create TreeR on it + file2 = gAlice->InitTreeFile("R",outFile); + } + + AliITS *ITS = (AliITS*) gAlice->GetModule("ITS"); + if (!ITS) return; // Set the simulation model - /* Bug !!! (I.Belikov) - AliITSsimulationFastPoints *sim = new AliITSsimulationFastPoints(); - - for (Int_t i=0;i<3;i++) { - ITS->SetSimulationModel(i,sim); - } - */ - - for (Int_t i=0;i<3;i++) { - ITS->SetSimulationModel(i,new AliITSsimulationFastPoints()); - } + for (Int_t i=0;i<3;i++) { + ITS->SetSimulationModel(i,new AliITSsimulationFastPoints()); + } -// -// Event Loop -// - - Int_t nbgr_ev=0; - TStopwatch timer; - - cout << "Creating fast reconstructed points from hits for the ITS..." << endl; - - for (int ev=evNumber1; ev<= evNumber2; ev++) { - cout << "...working on event "<< ev << " ..." << endl; - Int_t nparticles = gAlice->GetEvent(ev); - cout << "event " <SetEvent(ev); - if(!gAlice->TreeR()) gAlice-> MakeTree("R"); - ITS->MakeBranch("R"); - if (ev < evNumber1) continue; - if (nparticles <= 0) return; - - Int_t bgr_ev=Int_t(ev/nsignal); - //printf("bgr_ev %d\n",bgr_ev); - timer.Start(); - ITS->HitsToFastRecPoints(ev,bgr_ev,size," ","All"," "); - timer.Stop(); timer.Print(); - } // event loop - - delete gAlice; gAlice=0; - file->Close(); + // + // Event Loop + // + + Int_t nbgr_ev=0; + TStopwatch timer; + + cout << "Creating fast reconstructed points from hits for the ITS..." << endl; + + for (int ev=evNumber1; ev<= evNumber2; ev++) { + cout << "...working on event "<< ev << " ..." << endl; + Int_t nparticles = gAlice->GetEvent(ev); + cout << "event " <SetEvent(ev); + if(!gAlice->TreeR() && file2 == 0) gAlice-> MakeTree("R"); + if(!gAlice->TreeR() && file2 != 0) gAlice->MakeTree("R",file2); + ITS->MakeBranch("RF"); + if (ev < evNumber1) continue; + if (nparticles <= 0) return; + + Int_t bgr_ev=Int_t(ev/nsignal); + //printf("bgr_ev %d\n",bgr_ev); + timer.Start(); + ITS->HitsToFastRecPoints(ev,bgr_ev,size," ","All"," "); + timer.Stop(); timer.Print(); + } // event loop + + 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 "<Get("gAlice"); + if (!gAlice) { + cerr << "AliRun object not found on file"<< endl; + return retfil; + } + return file; +} diff --git a/ITS/AliITSHits2SDR.C b/ITS/AliITSHits2SDR.C index 2782c1b5ab7..bd687afa8c0 100644 --- a/ITS/AliITSHits2SDR.C +++ b/ITS/AliITSHits2SDR.C @@ -107,16 +107,14 @@ void AliITSH2SD2Files(TFile *file2){ return ; } - // for old files + // these re-instantiations are necessary if the input file was created + // with aliroot version V3.07 or older AliITSresponseSDD *resp1 = (AliITSresponseSDD*)ITS->DetType(1)->GetResponseModel(); - TDatime *ct0= new TDatime(2002,04,26,00,00,00),ct=file2->GetCreationDate(); - if(ct0->GetDate()SetResponseModel(1,resp1); - cout << "Changed response class for SDD: \n"; - resp1->Print(); - } // end if - // end mods for old files (<26/4/2002) + resp1 = new AliITSresponseSDD(); + ITS->SetResponseModel(1,resp1); + cout << "Changed response class for SDD: \n"; + resp1->Print(); + for (Int_t nevent=0; neventTreeE()->GetEntries(); nevent++) { gAlice->GetEvent(nevent); gAlice->MakeTree("S",file2); diff --git a/ITS/AliITSHits2SDigits.C b/ITS/AliITSHits2SDigits.C index d7fef4dce1a..c0bd7bad944 100644 --- a/ITS/AliITSHits2SDigits.C +++ b/ITS/AliITSHits2SDigits.C @@ -1,88 +1,129 @@ -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 "<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 "<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 "<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"; +} + + + + diff --git a/ITS/AliITSSDigits2Digits.C b/ITS/AliITSSDigits2Digits.C index 8675dbbaf8b..081006d4930 100644 --- a/ITS/AliITSSDigits2Digits.C +++ b/ITS/AliITSSDigits2Digits.C @@ -1,4 +1,7 @@ -void AliITSSDigits2Digits(const char *filename = "galice.root"){ +void writeAR(TFile * fin, TFile *fou); +void AliITSSD2D(TString inFile, TString outFile); + +void AliITSSDigits2Digits(TString inFile= "galice.root", TString outFile = ""){ // This macro takes SDigits and produces Digits. No merging is done // and only one galice.root file is used. // Dynamically link some shared libs @@ -9,11 +12,56 @@ void AliITSSDigits2Digits(const char *filename = "galice.root"){ gAlice = 0; } // end if gAlice cout << "Creating digits from summable digits for the ITS..." << endl; - AliRunDigitizer * manager = new AliRunDigitizer(1,1); - manager->SetInputStream(0,filename); - AliITSDigitizer *dITS = new AliITSDigitizer(manager); - timer.Start(); - manager->Exec(""); - timer.Stop(); timer.Print(); - delete dITS; + AliITSSD2D(inFile,outFile); + timer.Stop(); + timer.Print(); +} + +void AliITSSD2D(TString inFile, TString outFile){ + AliRunDigitizer * manager = new AliRunDigitizer(1,1); + char ftmp[50]; + sprintf(ftmp,"%s",inFile.Data()); + manager->SetInputStream(0,ftmp); + if(outFile != "")manager->SetOutputFile(outFile); + AliITSDigitizer *dITS = new AliITSDigitizer(manager); + manager->Exec(""); + TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(inFile); + TFile *file2 = 0; + if(outFile != ""){ + file2 = new TFile(outFile,"UPDATE"); + writeAR(file,file2); + } + delete dITS; + delete manager; + if(file){ + file->Close(); + delete file; + } + if(file2){ + file2->Close(); + delete file2; + } } + +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"; +} + + + + + + -- 2.31.1