/************************************************************************** * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * * * * Author: The ALICE Off-line Project. * * Contributors are mentioned in the code where appropriate. * * * * Permission to use, copy, modify and distribute this software and its * * documentation strictly for non-commercial purposes is hereby granted * * without fee, provided that the above copyright notice appears in all * * copies and that both the copyright notice and this permission notice * * appear in the supporting documentation. The authors make no claims * * about the suitability of this software for any purpose. It is * * provided "as is" without express or implied warranty. * **************************************************************************/ /* $Id$ */ //_________________________________________________________________________ // This is a TTask that makes SDigits out of Hits // A Summable Digits is the sum of all hits originating // from one primary in one active cell // A threshold for assignment of the primary to SDigit is applied // SDigits are written to TreeS, branch "PHOS" // AliPHOSSDigitizer with all current parameters is written // to TreeS branch "AliPHOSSDigitizer". // Both branches have the same title. If necessary one can produce // another set of SDigits with different parameters. Two versions // can be distunguished using titles of the branches. // User case: // root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root") // Warning in : object already instantiated // root [1] s->ExecuteTask() // // Makes SDigitis for all events stored in galice.root // root [2] s->SetPedestalParameter(0.001) // // One can change parameters of digitization // root [3] s->SetSDigitsBranch("Pedestal 0.001") // // and write them into the new branch // root [4] s->ExecuteTask("deb all tim") // // available parameters: // deb - print # of produced SDigitis // deb all - print # and list of produced SDigits // tim - print benchmarking information // //*-- Author : Dmitri Peressounko (SUBATECH & KI) ////////////////////////////////////////////////////////////////////////////// // --- ROOT system --- #include "TFile.h" #include "TTask.h" #include "TTree.h" #include "TSystem.h" #include "TROOT.h" #include "TFolder.h" #include "TBenchmark.h" // --- Standard library --- #include // --- AliRoot header files --- #include "AliRun.h" #include "AliPHOSDigit.h" #include "AliPHOSHit.h" #include "AliPHOSSDigitizer.h" ClassImp(AliPHOSSDigitizer) //____________________________________________________________________________ AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("AliPHOSSDigitizer","") { // ctor fA = 0; fB = 10000000.; fPrimThreshold = 0.01 ; fNevents = 0 ; fSDigits = 0 ; fHits = 0 ; fIsInitialized = kFALSE ; } //____________________________________________________________________________ AliPHOSSDigitizer::AliPHOSSDigitizer(const char* headerFile, const char *sDigitsTitle):TTask("AliPHOSSDigitizer","") { // ctor fA = 0; fB = 10000000.; fPrimThreshold = 0.01 ; fNevents = 0 ; fSDigitsTitle = sDigitsTitle ; fHeadersFile = headerFile ; fIsInitialized = kFALSE ; Init(); } //____________________________________________________________________________ AliPHOSSDigitizer::~AliPHOSSDigitizer() { // dtor if(fSDigits) delete fSDigits ; if(fHits) delete fHits ; } //____________________________________________________________________________ void AliPHOSSDigitizer::Init() { // Initialization: open root-file, allocate arrays for hits and sdigits, // attach task SDigitizer to the list of PHOS tasks // // Initialization can not be done in the default constructor if(!fIsInitialized){ if(fHeadersFile.IsNull()) fHeadersFile="galice.root" ; TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ; //if file was not opened yet, read gAlice if(file == 0){ if(fHeadersFile.Contains("rfio")) file = TFile::Open(fHeadersFile,"update") ; else file = new TFile(fHeadersFile.Data(),"update") ; gAlice = (AliRun *) file->Get("gAlice") ; } fHits = new TClonesArray("AliPHOSHit",1000); fSDigits = new TClonesArray("AliPHOSDigit",1000); //add Task to //YSAlice/tasks/(S)Diditizer/PHOS TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("YSAlice") ; TTask * aliceSD = (TTask*)alice->FindObject("tasks/(S)Digitizer") ; TTask * phosSD = (TTask*)aliceSD->GetListOfTasks()->FindObject("PHOS") ; phosSD->Add(this) ; fIsInitialized = kTRUE ; } } //____________________________________________________________________________ void AliPHOSSDigitizer::Exec(Option_t *option) { // Collects all hits in the same active volume into digit if(!fIsInitialized) Init() ; if(strstr(option,"tim")) gBenchmark->Start("PHOSSDigitizer"); fNevents = (Int_t) gAlice->TreeE()->GetEntries() ; Int_t ievent ; for(ievent = 0; ievent < fNevents; ievent++){ gAlice->GetEvent(ievent) ; gAlice->SetEvent(ievent) ; if(gAlice->TreeH()==0){ cout << "AliPHOSSDigitizer: There is no Hit Tree" << endl; return ; } //set address of the hits TBranch * branch = gAlice->TreeH()->GetBranch("PHOS"); if (branch) branch->SetAddress(&fHits); else{ cout << "ERROR in AliPHOSSDigitizer: "<< endl ; cout << " no branch PHOS in TreeH"<< endl ; cout << " do nothing " << endl ; return ; } fSDigits->Clear(); Int_t nSdigits = 0 ; //Now made SDigits from hits, for PHOS it is the same, so just copy Int_t itrack ; for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){ //=========== Get the PHOS branch from Hits Tree for the Primary track itrack branch->GetEntry(itrack,0); Int_t i; for ( i = 0 ; i < fHits->GetEntries() ; i++ ) { AliPHOSHit * hit = (AliPHOSHit*)fHits->At(i) ; // Assign primary number only if contribution is significant if( hit->GetEnergy() > fPrimThreshold) new((*fSDigits)[nSdigits]) AliPHOSDigit( hit->GetPrimary(), hit->GetId(), Digitize( hit->GetEnergy() ) ) ; else new((*fSDigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(), Digitize( hit->GetEnergy() ) ) ; nSdigits++ ; } } // loop over tracks fSDigits->Sort() ; nSdigits = fSDigits->GetEntriesFast() ; fSDigits->Expand(nSdigits) ; Int_t i ; for (i = 0 ; i < nSdigits ; i++) { AliPHOSDigit * digit = (AliPHOSDigit *) fSDigits->At(i) ; digit->SetIndexInList(i) ; } if(gAlice->TreeS() == 0) gAlice->MakeTree("S") ; //check, if this branch already exits? TBranch * sdigitsBranch = 0; TBranch * sdigitizerBranch = 0; TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ; Int_t ibranch; Bool_t phosNotFound = kTRUE ; Bool_t sdigitizerNotFound = kTRUE ; for(ibranch = 0;ibranch GetEntries();ibranch++){ if(phosNotFound){ sdigitsBranch=(TBranch *) branches->At(ibranch) ; if( (strcmp("PHOS",sdigitsBranch->GetName())==0 ) && (fSDigitsTitle.CompareTo(sdigitsBranch->GetTitle()) == 0) ) phosNotFound = kFALSE ; } if(sdigitizerNotFound){ sdigitizerBranch = (TBranch *) branches->At(ibranch) ; if( (strcmp(sdigitizerBranch->GetName(),"AliPHOSSDigitizer") == 0)&& (fSDigitsTitle.CompareTo(sdigitizerBranch->GetTitle()) == 0) ) sdigitizerNotFound = kFALSE ; } } if(!(sdigitizerNotFound && phosNotFound)){ cout << "AliPHOSSdigitizer error:" << endl ; cout << "Can not overwrite existing branches: do not write" << endl ; return ; } //Make (if necessary) branches char * file =0; if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name file = new char[strlen(gAlice->GetBaseFile())+20] ; sprintf(file,"%s/PHOS.SDigits.root",gAlice->GetBaseFile()) ; } TDirectory *cwd = gDirectory; //First list of sdigits Int_t bufferSize = 32000 ; sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&fSDigits,bufferSize); sdigitsBranch->SetTitle(fSDigitsTitle.Data()); if (file) { sdigitsBranch->SetFile(file); TIter next( sdigitsBranch->GetListOfBranches()); TBranch * subbr; while ((subbr=(TBranch*)next())) { subbr->SetFile(file); } cwd->cd(); } //second - SDigitizer Int_t splitlevel = 0 ; AliPHOSSDigitizer * sd = this ; sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer", &sd,bufferSize,splitlevel); sdigitizerBranch->SetTitle(fSDigitsTitle.Data()); if (file) { sdigitizerBranch->SetFile(file); TIter next( sdigitizerBranch->GetListOfBranches()); TBranch * subbr ; while ((subbr=(TBranch*)next())) { subbr->SetFile(file); } cwd->cd(); delete file; } sdigitsBranch->Fill() ; sdigitizerBranch->Fill() ; gAlice->TreeS()->Write(0,TObject::kOverwrite) ; if(strstr(option,"deb")) PrintSDigits(option) ; } if(strstr(option,"tim")){ gBenchmark->Stop("PHOSSDigitizer"); cout << "AliPHOSSDigitizer:" << endl ; cout << " took " << gBenchmark->GetCpuTime("PHOSSDigitizer") << " seconds for SDigitizing " << gBenchmark->GetCpuTime("PHOSSDigitizer")/fNevents << " seconds per event " << endl ; cout << endl ; } } //__________________________________________________________________ void AliPHOSSDigitizer::SetSDigitsBranch(const char * title ) { // Setting title to branch SDigits if(!fSDigitsTitle.IsNull()) cout << "AliPHOSSdigitizer: changing SDigits file from " <GetEntriesFast() << endl ; cout << endl ; if(strstr(option,"all")){// print all digits //loop over digits AliPHOSDigit * digit; cout << "SDigit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl; Int_t index ; for (index = 0 ; index < fSDigits->GetEntries() ; index++) { digit = (AliPHOSDigit * ) fSDigits->At(index) ; cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " " << setw(6) << digit->GetIndexInList() << " " << setw(5) << digit->GetNprimary() <<" "; Int_t iprimary; for (iprimary=0; iprimaryGetNprimary(); iprimary++) cout << setw(5) << digit->GetPrimary(iprimary+1) << " "; cout << endl; } } }