//_________________________________________________________________________
// This is a TTask that makes SDigits out of Hits
+// The name of the TTask is also the title of the branch that will contain
+// the created SDigits
+// The title of the TTAsk is the name of the file that contains the hits from
+// which the SDigits are created
// 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
// 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 <TDatabasePDG::TDatabasePDG>: object already instantiated
-// root [1] s->ExecuteTask()
+// root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root")
+// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
+// root [1] s->ExecuteTask()
// // Makes SDigitis for all events stored in galice.root
-// root [2] s->SetPedestalParameter(0.001)
+// root [2] s->SetPedestalParameter(0.001)
// // One can change parameters of digitization
-// root [3] s->SetSDigitsBranch("Redestal 0.001")
+// root [3] s->SetSDigitsBranch("Pedestal 0.001")
// // and write them into the new branch
-// root [4] s->ExeciteTask("deb all tim")
+// root [4] s->ExecuteTask("deb all tim")
// // available parameters:
// deb - print # of produced SDigitis
// deb all - print # and list of produced SDigits
// --- AliRoot header files ---
#include "AliRun.h"
#include "AliPHOSDigit.h"
+#include "AliPHOSGetter.h"
#include "AliPHOSHit.h"
#include "AliPHOSSDigitizer.h"
//____________________________________________________________________________
- AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("AliPHOSSDigitizer","")
+ AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","")
{
// ctor
- fA = 0;
- fB = 10000000. ;
+ fA = 0;
+ fB = 10000000.;
fPrimThreshold = 0.01 ;
- fNevents = 0 ;
- fSDigits = 0 ;
- fHits = 0 ;
- fIsInitialized = kFALSE ;
-
+ fSDigitsInRun = 0 ;
}
//____________________________________________________________________________
-AliPHOSSDigitizer::AliPHOSSDigitizer(const char* headerFile, const char *sDigitsTitle):TTask("AliPHOSSDigitizer","")
+AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigitsTitle):TTask(sDigitsTitle, headerFile)
{
// ctor
- fA = 0;
- fB = 10000000.;
+ fA = 0;
+ fB = 10000000.;
fPrimThreshold = 0.01 ;
- fNevents = 0 ;
- fSDigitsTitle = sDigitsTitle ;
- fHeadersFile = headerFile ;
- fSDigits = new TClonesArray("AliPHOSDigit",1000);
- fHits = new TClonesArray("AliPHOSHit",1000);
-
- TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
-
- //File was not opened yet
- if(file == 0){
- if(fHeadersFile.Contains("rfio"))
- file = TFile::Open(fHeadersFile,"update") ;
- else
- file = new TFile(fHeadersFile.Data(),"update") ;
- gAlice = (AliRun *) file->Get("gAlice") ;
- }
-
- //add Task to //root/Tasks folder
- TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ;
- roottasks->Add(this) ;
-
- fIsInitialized = kTRUE ;
+ fSDigitsInRun = 0 ;
+ Init();
}
+
//____________________________________________________________________________
-AliPHOSSDigitizer::~AliPHOSSDigitizer()
+void AliPHOSSDigitizer::Init()
{
- // dtor
- if(fSDigits)
- delete fSDigits ;
- if(fHits)
- delete fHits ;
-}
-//____________________________________________________________________________
-void AliPHOSSDigitizer::Init(){
- //Initialization can not be done in the default constructor
-
- if(!fIsInitialized){
+ // 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
+ //============================================================= YS
+ // The initialisation is now done by AliPHOSGetter
+
+ if( strcmp(GetTitle(), "") == 0 )
+ SetTitle("galice.root") ;
+
+ AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ;
+ if ( gime == 0 ) {
+ cerr << "ERROR: AliPHOSSDigitizer::Init -> Could not obtain the Getter object !" << endl ;
+ return ;
+ }
+
+ // //add Task to //YSAlice/tasks/SDiditizer/PHOS
+ // TTask * aliceSD = (TTask*)gROOT->FindObjectAny("YSAlice/tasks/SDigitizer") ;
+ // TTask * phosSD = (TTask*)aliceSD->GetListOfTasks()->FindObject("PHOS") ;
+ // if ( ! phosSD->GetListOfTasks()->FindObject(GetName()) )
+ // phosSD->Add(this) ;
- if(fHeadersFile.IsNull())
- fHeadersFile="galice.root" ;
+ gime->PostSDigits( GetName(), GetTitle() ) ;
- TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
+ TString sdname(GetName() );
+ sdname.Append(":") ;
+ sdname.Append(GetTitle() ) ;
+ SetName(sdname) ;
+ gime->PostSDigitizer(this) ;
+
+ // create a folder on the white board //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/sdigitsTitle
- //if file was not opened yet, read gAlice
- if(file == 0){
- file = new TFile(fHeadersFile.Data(),"update") ;
- gAlice = (AliRun *) file->Get("gAlice") ;
- }
-
- fHits = new TClonesArray("AliPHOSHit",1000);
- fSDigits = new TClonesArray("AliPHOSDigit",1000);
-
- // add Task to //root/Tasks folder
- TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ;
- roottasks->Add(this) ;
-
- fIsInitialized = kTRUE ;
- }
}
+
//____________________________________________________________________________
-void AliPHOSSDigitizer::Exec(Option_t *option) {
- //Collects all hits in the same active volume into digit
-
- if(!fIsInitialized)
+void AliPHOSSDigitizer::Exec(Option_t *option)
+{
+ // Collects all hits in the same active volume into digit
+ if( strcmp(GetName(), "") == 0 )
Init() ;
+
+ if (strstr(option, "print") ) {
+ Print("") ;
+ return ;
+ }
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) ;
+
+ //Check, if this branch already exits
+ gAlice->GetEvent(0) ;
+ if(gAlice->TreeS() ) {
+ TObjArray * lob = (TObjArray*)gAlice->TreeS()->GetListOfBranches() ;
+ TIter next(lob) ;
+ TBranch * branch = 0 ;
+ Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ;
- if(gAlice->TreeH()==0){
- cout << "AliPHOSSDigitizer: There is no Hit Tree" << endl;
- return ;
+ while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
+ if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
+ phosfound = kTRUE ;
+
+ else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
+ sdigitizerfound = kTRUE ;
}
- //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 ;
- }
+ if ( phosfound || sdigitizerfound ) {
+ cerr << "WARNING: AliPHOSSDigitizer::Exec -> SDigits and/or SDigitizer branch with name " << GetName()
+ << " already exits" << endl ;
+ return ;
+ }
+ }
+
+ TString sdname(GetName()) ;
+ sdname.Remove(sdname.Index(GetTitle())-1) ;
- fSDigits->Clear();
+ AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
+
+ Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
+
+ Int_t ievent ;
+ for(ievent = 0; ievent < nevents; ievent++){
+ gime->Event(ievent,"H") ;
+
+ TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
+ sdigits->Clear();
Int_t nSdigits = 0 ;
- //Now made SDigits from hits, for PHOS it is the same, so just copy
+ //Now make SDigits from hits, for PHOS it is the same, so just copy
Int_t itrack ;
- for (itrack=0; itrack<gAlice->GetNtrack(); itrack++){
-
- //=========== Get the Hits Tree for the Primary track itrack
- gAlice->ResetHits();
- gAlice->TreeH()->GetEvent(itrack);
-
+ for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
+
+ //=========== Get the PHOS branch from Hits Tree for the Primary track itrack
+ gime->Track(itrack) ;
+ TClonesArray * hits = gime->Hits() ;
Int_t i;
- for ( i = 0 ; i < fHits->GetEntries() ; i++ ) {
- AliPHOSHit * hit = (AliPHOSHit*)fHits->At(i) ;
- AliPHOSDigit * newdigit ;
-
+ for ( i = 0 ; i < hits->GetEntries() ; i++ ) {
+ AliPHOSHit * hit = (AliPHOSHit *) hits->At(i) ;
// Assign primary number only if contribution is significant
+
if( hit->GetEnergy() > fPrimThreshold)
- newdigit = new AliPHOSDigit( hit->GetPrimary(), hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
+ new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(),
+ Digitize(hit->GetEnergy()), hit->GetTime()) ;
else
- newdigit = new AliPHOSDigit( -1 , hit->GetId(), Digitize( hit->GetEnergy() ) ) ;
+ new((*sdigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(),
+ Digitize(hit->GetEnergy()), hit->GetTime()) ;
+ nSdigits++ ;
- new((*fSDigits)[nSdigits]) AliPHOSDigit(* newdigit) ;
- nSdigits++ ;
-
- delete newdigit ;
- }
-
+ }
} // loop over tracks
- fSDigits->Sort() ;
+ sdigits->Sort() ;
- nSdigits = fSDigits->GetEntriesFast() ;
- fSDigits->Expand(nSdigits) ;
+ nSdigits = sdigits->GetEntriesFast() ;
+ sdigits->Expand(nSdigits) ;
Int_t i ;
for (i = 0 ; i < nSdigits ; i++) {
- AliPHOSDigit * digit = (AliPHOSDigit *) fSDigits->At(i) ;
+ AliPHOSDigit * digit = (AliPHOSDigit *) sdigits->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 <branches->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
//First list of sdigits
Int_t bufferSize = 32000 ;
- sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&fSDigits,bufferSize);
- sdigitsBranch->SetTitle(fSDigitsTitle.Data());
+ TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
+ sdigitsBranch->SetTitle(sdname);
if (file) {
sdigitsBranch->SetFile(file);
TIter next( sdigitsBranch->GetListOfBranches());
- while ((sdigitsBranch=(TBranch*)next())) {
- sdigitsBranch->SetFile(file);
+ TBranch * subbr;
+ while ((subbr=(TBranch*)next())) {
+ subbr->SetFile(file);
}
cwd->cd();
}
- //second - SDigitizer
+ //Next - SDigitizer
Int_t splitlevel = 0 ;
AliPHOSSDigitizer * sd = this ;
- sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
+ TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
&sd,bufferSize,splitlevel);
- sdigitizerBranch->SetTitle(fSDigitsTitle.Data());
+ sdigitizerBranch->SetTitle(sdname);
if (file) {
sdigitizerBranch->SetFile(file);
TIter next( sdigitizerBranch->GetListOfBranches());
- while ((sdigitizerBranch=(TBranch*)next())) {
- sdigitizerBranch->SetFile(file);
+ TBranch * subbr ;
+ while ((subbr=(TBranch*)next())) {
+ subbr->SetFile(file);
}
cwd->cd();
delete file;
}
- gAlice->TreeS()->Fill() ;
+ sdigitsBranch->Fill() ;
+ sdigitizerBranch->Fill() ;
gAlice->TreeS()->Write(0,TObject::kOverwrite) ;
if(strstr(option,"deb"))
gBenchmark->Stop("PHOSSDigitizer");
cout << "AliPHOSSDigitizer:" << endl ;
cout << " took " << gBenchmark->GetCpuTime("PHOSSDigitizer") << " seconds for SDigitizing "
- << gBenchmark->GetCpuTime("PHOSSDigitizer")/fNevents << " seconds per event " << endl ;
+ << gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents << " seconds per event " << endl ;
cout << endl ;
}
}
//__________________________________________________________________
-void AliPHOSSDigitizer::SetSDigitsBranch(const char * title ){
- //Seting title to branch SDigits
- if(!fSDigitsTitle.IsNull())
- cout << "AliPHOSSdigitizer: changing SDigits file from " <<fSDigitsTitle.Data() << " to " << title << endl ;
- fSDigitsTitle=title ;
+void AliPHOSSDigitizer::SetSDigitsBranch(const char * title )
+{
+ // Setting title to branch SDigits
+
+ TString stitle(title) ;
+
+ // check if branch with title already exists
+ TBranch * sdigitsBranch = (TBranch*)gAlice->TreeS()->GetListOfBranches()->FindObject("PHOS") ;
+ TBranch * sdigitizerBranch = (TBranch*)gAlice->TreeS()->GetListOfBranches()->FindObject("AliPHOSSDigitizer") ;
+ const char * sdigitsTitle = sdigitsBranch ->GetTitle() ;
+ const char * sdigitizerTitle = sdigitizerBranch ->GetTitle() ;
+ if ( stitle.CompareTo(sdigitsTitle)==0 || stitle.CompareTo(sdigitizerTitle)==0 ){
+ cerr << "ERROR: AliPHOSSdigitizer::SetSDigitsBranch -> Cannot overwrite existing branch with title " << title << endl ;
+ return ;
+ }
+
+ cout << "AliPHOSSdigitizer::SetSDigitsBranch -> Changing SDigits file from " << GetName() << " to " << title << endl ;
+
+ SetName(title) ;
+
+ // Post to the WhiteBoard
+ AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
+ gime->PostSDigits( title, GetTitle()) ;
}
+
//__________________________________________________________________
-void AliPHOSSDigitizer::Print(Option_t* option)const{
+void AliPHOSSDigitizer::Print(Option_t* option)const
+{
+ // Prints parameters of SDigitizer
cout << "------------------- "<< GetName() << " -------------" << endl ;
- cout << " Writing SDigitis to branch with title " << fSDigitsTitle.Data() << endl ;
+ cout << " Writing SDigitis to branch with title " << GetName() << endl ;
cout << " with digitization parameters A = " << fA << endl ;
cout << " B = " << fB << endl ;
cout << " Threshold for Primary assignment= " << fPrimThreshold << endl ;
}
//__________________________________________________________________
-Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const{
+Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const
+{
+ // Equal operator.
+ // SDititizers are equal if their pedestal, slope and threshold are equal
+
if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold))
return kTRUE ;
else
return kFALSE ;
}
//__________________________________________________________________
-void AliPHOSSDigitizer::PrintSDigits(Option_t * option){
- //Prints list of digits produced at the current pass of AliPHOSDigitizer
-
- cout << "AliPHOSSDigitizer: " << endl ;
- cout << " Number of entries in SDigits list " << fSDigits->GetEntriesFast() << endl ;
+void AliPHOSSDigitizer::PrintSDigits(Option_t * option)
+{
+ // Prints list of digits produced in the current pass of AliPHOSDigitizer
+
+ AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
+ TString sdname(GetName()) ;
+ sdname.Remove(sdname.Index(GetTitle())-1) ;
+ TClonesArray * sdigits = gime->SDigits(sdname.Data()) ;
+
+ cout << "AliPHOSSDigitizer: event "<<gAlice->GetEvNumber() << endl ;
+ cout << " Number of entries in SDigits list " << sdigits->GetEntriesFast() << endl ;
cout << endl ;
+
+ fSDigitsInRun += sdigits->GetEntriesFast() ;
if(strstr(option,"all")){// print all 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) ;
+ for (index = 0 ; index < sdigits->GetEntries() ; index++) {
+ digit = (AliPHOSDigit * ) sdigits->At(index) ;
cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
<< setw(6) << digit->GetIndexInList() << " "
<< setw(5) << digit->GetNprimary() <<" ";
}
}
+
+//____________________________________________________________________________
+void AliPHOSSDigitizer::UseHitsFrom(const char * filename)
+{
+ SetTitle(filename) ;
+ Init() ;
+}