/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
* *
* Author: The ALICE Off-line Project. *
* Contributors are mentioned in the code where appropriate. *
* provided "as is" without express or implied warranty. *
**************************************************************************/
-
//_________________________________________________________________________
-// This is a TTask that makes TOF-Digits out of TOF-Hits.
-// A TOF Digit is essentially a TOF hit with the smearing for strip
-// time resolution and simulation of the ADC correlation signal.
+// This is a TTask that makes TOF-Digits out of TOF-SDigits.
+// The simulation of the detector is performed at sdigits level:
+// during digitization the unique task is the sum of all sdigits in the
+// same pad.
// Digits are written to TreeD in branch "TOF".
-// AliTOFDigitizer with all current parameters used for digitization
-// (time resolution and ADC parameter) is written
-// to TreeD branch "AliTOFDigitizer".
-// Both branches have the same title. If necessary one can produce
-// another set of Digits with different parameters. Two versions
-// can be distunguished using titles of the branches.
-// User case:
-// root [0] AliTOFDigitizer * s = new AliTOFDigitizer("galice.root")
-// Warning in <AliITSgeomSPD425Long::Default Creator>: Detector size may not be write.
-// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
-// root [1] s->ExecuteTask()
-// // Makes Digits for all events stored in galice.root
-// root [2] s->SetTimeRes(100.)
-// // One can change parameters of digitization
-// root [3] s->SetDigitsBranch("Time Resolution 100. ps")
-// // and write them into the new branch
-// root [4] s->ExecuteTask("deb all tim")
-// // available parameters:
-// deb - print number of produced Digits
-// deb all - print number and list of produced Digits
-// tim - print benchmarking information
//
// -- Author : F. Pierella (Bologna University) pierella@bo.infn.it
//////////////////////////////////////////////////////////////////////////////
-#include "TFile.h"
-#include "TTask.h"
-#include "TTree.h"
-#include "TSystem.h"
-#include "TROOT.h"
-#include "TFolder.h"
-#include "TBenchmark.h"
-#include "TObjString.h"
+#include <TTree.h>
+#include <TVector.h>
+#include <TObjArray.h>
+#include <TFile.h>
+#include <TDirectory.h>
+#include <TRandom.h>
-#include <iomanip.h>
-#include "AliRun.h"
+#include "AliTOFDigitizer.h"
#include "AliTOF.h"
-#include "AliTOFdigit.h"
+#include "AliTOFSDigitizer.h"
#include "AliTOFhit.h"
-#include "AliTOFDigitizer.h"
+#include "AliTOFdigit.h"
+#include "AliTOFSDigit.h"
+#include "AliTOFHitMap.h"
+#include "AliDigitizer.h"
+#include "AliRunDigitizer.h"
+#include "AliRun.h"
+#include "AliPDG.h"
+
+#include <stdlib.h>
+#include <iostream.h>
+#include <fstream.h>
ClassImp(AliTOFDigitizer)
-
-//____________________________________________________________________________
- AliTOFDigitizer::AliTOFDigitizer():TTask("AliTOFDigitizer","")
+//___________________________________________
+ AliTOFDigitizer::AliTOFDigitizer() :AliDigitizer()
{
- // ctor
- fTimeRes = 100; // ps
- fChrgRes = 100.; // pC
- fNevents = 0 ;
- fDigits = 0 ;
- fHits = 0 ;
- fIsInitialized = kFALSE ;
-
+ // Default ctor - don't use it
+ fDigits=0;
+ fSDigitsArray=0;
+ fhitMap=0;
}
-//____________________________________________________________________________
-AliTOFDigitizer::AliTOFDigitizer(const char* headerFile, const char *digitsTitle):TTask("AliTOFDigitizer","")
+//___________________________________________
+AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager)
+ :AliDigitizer(manager)
{
- // ctor
- fTimeRes = 100; // ps
- fChrgRes = 100.; // pC
- fNevents = 0 ;
- fDigitsTitle = digitsTitle ;
- fHeadersFile = headerFile ;
- fIsInitialized = kFALSE ;
- Init();
+ fDigits=0;
+ fSDigitsArray=0;
+ fhitMap=0;
}
-//____________________________________________________________________________
+//------------------------------------------------------------------------
AliTOFDigitizer::~AliTOFDigitizer()
{
- // dtor
- if(fDigits)
- delete fDigits ;
- if(fHits)
- delete fHits ;
+ // Destructor
}
-//____________________________________________________________________________
-void AliTOFDigitizer::Init()
+
+//---------------------------------------------------------------------
+
+void AliTOFDigitizer::Exec(Option_t* option)
{
- // Initialization: open root-file, allocate arrays for hits and digits,
- // attach task Digitizer to the list of TOF tasks
- //
- // Initialization can not be done in the default constructor
+ //
+ // Perform digitization and merging.
+ // The algorithm is the following:
+ // - a hitmap is created to check if a pad is already activated;
+ // - an sdigits container is created to collect all sdigits from
+ // different files;
+ // - sdigits are summed using the hitmap;
+ // - the sdigits container is used to create the array of AliTOFdigit.
+ //
- if(!fIsInitialized){
+ if(strstr(option,"deb")) cout<<"AliTOFDigitizer::Exec\n";
- 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("AliTOFhit" , 405);
- fDigits = new TClonesArray("AliTOFdigit", 405);
-
- //add Task to //FPAlice/tasks/(S)Digitizer/TOF
- TList * aList = gROOT->GetListOfBrowsables();
- if (aList) {
- TFolder * alice = (TFolder*)aList->FindObject("FPAlice") ;
- if (alice) {
- TTask * aliceSD = (TTask*)alice->FindObject("tasks/(S)Digitizer") ;
- if (aliceSD) {
- TTask * tofD = (TTask*)aliceSD->GetListOfTasks()->FindObject("TOF") ;
- tofD->Add(this) ;
- }
- }
- }
+ // get the ptr to TOF detector
+ AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
- fIsInitialized = kTRUE ;
- }
-}
-//____________________________________________________________________________
-void AliTOFDigitizer::Exec(Option_t *option)
-{
- Int_t tracks[3]; // track info
- Int_t vol[5]; // dummy location for digit
- Float_t digit[2]; // TOF digit variables
-
- // Collects all hits in the same active volume into digit
-
- if(!fIsInitialized)
- Init() ;
+ //Make branches
+ char branchname[20];
+ sprintf (branchname, "%s", tof->GetName ());
+
+ fDigits=new TClonesArray("AliTOFdigit",4000);
- if(strstr(option,"tim"))
- gBenchmark->Start("TOFDigitizer");
+ TTree* treeD = fManager->GetTreeD();
+ //Make branch for digits (to be created in Init())
+ tof->MakeBranchInTree(treeD,branchname,&fDigits,4000);
+
+ // container for all summed sdigits (to be created in Init())
+ fSDigitsArray=new TClonesArray("AliTOFSDigit",1000);
- fNevents = (Int_t) gAlice->TreeE()->GetEntries() ;
+ // create hit map (to be created in Init())
+ fhitMap = new AliTOFHitMap(fSDigitsArray);
- Int_t ievent ;
- // start loop on events
- for(ievent = 0; ievent < fNevents; ievent++){
- gAlice->GetEvent(ievent) ;
- gAlice->SetEvent(ievent) ;
+ // Loop over files to digitize
+
+ for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
+ inputFile++) {
+ ReadSDigit(inputFile);
+ }
+
+ // create digits
+ CreateDigits();
+
+ // free used memory for Hit Map in current event
+ delete fhitMap;
+ fSDigitsArray->Delete();
+ treeD->Fill();
+
+ fManager->GetTreeD()->AutoSave(); // to fit with the framework
+ fDigits->Delete();
+ delete fDigits;
+
+}
+
+//---------------------------------------------------------------------
+
+void AliTOFDigitizer::CreateDigits()
+{
+ // loop on sdigits container to fill the AliTOFdigit TClonesArray
+ // start digitizing all the collected sdigits
+
+ Int_t ndump=15; // dump the first ndump created digits for each event
+
+ // get the total number of collected sdigits
+ Int_t ndig = fSDigitsArray->GetEntriesFast();
+
+ for (Int_t k = 0; k < ndig; k++) {
- if(gAlice->TreeH()==0){
- cout << "AliTOFDigitizer: There is no Hit Tree" << endl;
- return ;
- }
+ Int_t vol[5]; // location for a digit
- //set address of the hits
- TBranch * branch = gAlice->TreeH()->GetBranch("TOF");
- if (branch)
- branch->SetAddress(&fHits);
- else{
- cout << "ERROR in AliTOFDigitizer: "<< endl ;
- cout << " no branch TOF in TreeH"<< endl ;
- cout << " do nothing " << endl ;
- return ;
- }
+ // Get the information for this digit
+ AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k);
- fDigits->Clear();
- Int_t ndigits = 0 ;
+ Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
+ // for current sdigit
- //Now made Digits from hits, for TOF it is the same a part for the tof smearing
- // and some missing MC variables
- Int_t itrack ;
- for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
-
- //=========== Get the TOF branch from Hits Tree for the Primary track itrack
- branch->GetEntry(itrack,0);
-
- Int_t i;
- for ( i = 0 ; i < fHits->GetEntries() ; i++ ) {
-
- AliTOFhit * hit = (AliTOFhit*)fHits->At(i) ;
-
- vol[0] = hit->GetSector();
- vol[1] = hit->GetPlate();
- vol[2] = hit->GetPadx();
- vol[3] = hit->GetPadz();
- vol[4] = hit->GetStrip();
- // 95% of efficiency to be inserted here
- // edge effect to be inserted here
- // cross talk to be inserted here
- // simulation of the detector response
- Float_t idealtime = hit->GetTof(); // unit s
- idealtime *= 1.E+12; // conversion from s to ps
- // fTimeRes is given usually in ps
- Float_t tdctime = gRandom->Gaus(idealtime, fTimeRes);
- digit[0] = tdctime;
- // typical Landau Distribution to be inserted here
- Float_t idealcharge = hit->GetEdep();
- Float_t adccharge = gRandom->Gaus(idealcharge, fChrgRes);
- digit[1] = adccharge;
- // to be added a check for overlaps
- new((*fDigits)[ndigits]) AliTOFdigit(tracks, vol, digit);
- ndigits++ ;
- }
-
- } // end loop over tracks
-
- ndigits = fDigits->GetEntriesFast() ;
- printf("AliTOFDigitizer: Total number of digits %d\n",ndigits);
-
- if(gAlice->TreeD() == 0)
- gAlice->MakeTree("D") ;
+ // TOF sdigit volumes (always the same for all slots)
+ Int_t sector = tofsdigit->GetSector(); // range [1-18]
+ Int_t plate = tofsdigit->GetPlate(); // range [1- 5]
+ Int_t strip = tofsdigit->GetStrip(); // range [1-20]
+ Int_t padz = tofsdigit->GetPadz(); // range [1- 2]
+ Int_t padx = tofsdigit->GetPadx(); // range [1-48]
- //check, if this branch already exits
- TBranch * digitsBranch = 0;
- TBranch * digitizerBranch = 0;
+ vol[0] = sector;
+ vol[1] = plate;
+ vol[2] = strip;
+ vol[3] = padx;
+ vol[4] = padz;
- TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
- Int_t ibranch;
- Bool_t tofNotFound = kTRUE ;
- Bool_t digitizerNotFound = kTRUE ;
+ //--------------------- QA section ----------------------
+ // in the while, I perform QA
+ Bool_t isSDigitBad = (sector<1 || sector>18 || plate<1 || plate >5 || padz<1 || padz>2 || padx<1 || padx>48);
- for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
-
- if(tofNotFound){
- digitsBranch=(TBranch *) branches->At(ibranch) ;
- if( (strcmp("TOF",digitsBranch->GetName())==0 ) &&
- (fDigitsTitle.CompareTo(digitsBranch->GetTitle()) == 0) )
- tofNotFound = kFALSE ;
- }
- if(digitizerNotFound){
- digitizerBranch = (TBranch *) branches->At(ibranch) ;
- if( (strcmp(digitizerBranch->GetName(),"AliTOFDigitizer") == 0)&&
- (fDigitsTitle.CompareTo(digitizerBranch->GetTitle()) == 0) )
- digitizerNotFound = kFALSE ;
- }
- }
-
- if(!(digitizerNotFound && tofNotFound)){
- cout << "AliTOFdigitizer error:" << endl ;
- cout << "Can not overwrite existing branches: do not write" << endl ;
- return ;
+ if (isSDigitBad) {
+ cout << "<AliTOFSDigits2Digits> strange sdigit found" << endl;
+ abort();
}
+ //-------------------------------------------------------
- //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/TOF.Digits.root",gAlice->GetBaseFile()) ;
+ //------------------- Dump section ----------------------
+ if(k<ndump){
+ cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
+ cout << k << "-th sdigit" << endl;
+ cout << "----------------------------------------------------"<< endl;
}
+ // ------------------------------------------------------
- TDirectory *cwd = gDirectory;
-
- //First list of digits
- Int_t bufferSize = 32000 ;
- digitsBranch = gAlice->TreeD()->Branch("TOF",&fDigits,bufferSize);
- digitsBranch->SetTitle(fDigitsTitle.Data());
- if (file) {
- digitsBranch->SetFile(file);
- TIter next( digitsBranch->GetListOfBranches());
- TBranch * subbr;
- while ((subbr=(TBranch*)next())) {
- subbr->SetFile(file);
- }
- cwd->cd();
- }
+ // start loop on number of slots for current sdigit
+ for (Int_t islot = 0; islot < nslot; islot++) {
+ Float_t digit[2]; // TOF digit variables
+ Int_t tracknum[kMAXDIGITS]; // contributing tracks for the current slot
+
+ Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
+ Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
+
+ tracknum[0]=tofsdigit->GetTrack(islot,0);
+ tracknum[1]=tofsdigit->GetTrack(islot,1);
+ tracknum[2]=tofsdigit->GetTrack(islot,2);
- //second - Digitizer
- Int_t splitlevel = 0 ;
- AliTOFDigitizer * digtz = this ;
- digitizerBranch = gAlice->TreeD()->Branch("AliTOFDigitizer","AliTOFDigitizer",
- &digtz,bufferSize,splitlevel);
- digitizerBranch->SetTitle(fDigitsTitle.Data());
- if (file) {
- digitizerBranch->SetFile(file);
- TIter next( digitizerBranch->GetListOfBranches());
- TBranch * subbr ;
- while ((subbr=(TBranch*)next())) {
- subbr->SetFile(file);
- }
- cwd->cd();
- delete file;
+
+ // adding a TOF digit for each slot
+ AliTOFdigit* newDigit=new AliTOFdigit(tracknum, vol, digit);
+ fDigits->Add(newDigit);
}
-
- digitsBranch->Fill();
- digitizerBranch->Fill();
- gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
-
- if(strstr(option,"deb"))
- PrintDigits(option) ;
- }
-
- if(strstr(option,"tim")){
- gBenchmark->Stop("TOFDigitizer");
- cout << "AliTOFDigitizer:" << endl ;
- cout << " took " << gBenchmark->GetCpuTime("TOFDigitizer") << " seconds for Digitizing "
- << gBenchmark->GetCpuTime("TOFDigitizer")/fNevents << " seconds per event " << endl ;
- cout << endl ;
- }
-
-
-}
-//__________________________________________________________________
-void AliTOFDigitizer::SetDigitsBranch(const char* title )
-{
- // Setting title to branch Digits
- if(!fDigitsTitle.IsNull())
- cout << "AliTOFdigitizer: changing Digits file from " <<fDigitsTitle.Data() << " to " << title << endl ;
- fDigitsTitle=title ;
+ } // end loop on sdigits - end digitizing all collected sdigits
+
}
-//__________________________________________________________________
-void AliTOFDigitizer::Print(Option_t* option)const
+
+//---------------------------------------------------------------------
+
+void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
{
- // Prints parameters of Digitizer
- cout << "------------------- "<< GetName() << " -------------" << endl ;
- cout << " Writing Digits to branch with title " << fDigitsTitle.Data() << endl ;
- cout << " with digitization parameters Time resolution = " << fTimeRes << endl ;
- cout << " Adc smearing parameter = " << fChrgRes << endl ;
- cout << "---------------------------------------------------"<<endl ;
+ // Read sdigits for current event and inputFile;
+ // store them into the sdigits container
+ // and update the hit map
+ // SDigits from different files are assumed to
+ // be created with the same simulation parameters.
-}
-//__________________________________________________________________
-Bool_t AliTOFDigitizer::operator==( AliTOFDigitizer const &digtz )const
-{
- // Equal operator.
- // Dititizers are equal if their time resolution and Adc
- // smearing parameter are equal
-
- if( (fTimeRes==digtz.fTimeRes)&&(fChrgRes==digtz.fChrgRes))
- return kTRUE ;
- else
- return kFALSE ;
-}
-//__________________________________________________________________
-void AliTOFDigitizer::PrintDigits(Option_t * option)
-{
- // Prints list of digits produced in the current pass of AliTOFDigitizer
+ // get the treeS from manager
+ TTree* currentTreeS=fManager->GetInputTreeS(inputFile);
+
+ // get the branch TOF inside the treeS
+ TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit", 1000);
+
+ // check if the branch exist
+ TBranch* tofBranch=currentTreeS->GetBranch("TOF");
+
+ if(!tofBranch){
+ Fatal("ReadSDigit","TOF branch not found for input %d",inputFile);
+ }
- cout << "AliTOFDigitizer: " << endl ;
- cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ;
- cout << endl ;
+ tofBranch->SetAddress(&sdigitsDummyContainer);
- if(strstr(option,"all")){// print all digits
+ Int_t nEntries = (Int_t)tofBranch->GetEntries();
+
+ // Loop through all entries in the tree
+ Int_t nbytes;
+
+ for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
- //loop over digits
- AliTOFdigit * digit;
- cout << "Digit # " << " Time of flight(ps) " <<
- " ADC(pC)" << " Sector #" << " Plate #" <<
- " Strip #" << " Pad # (x) " << " Pad # (z) " << endl;
- Int_t index ;
- for (index = 0 ; index < fDigits->GetEntries() ; index++) {
- digit = (AliTOFdigit * ) fDigits->At(index) ;
-
- // set the width of the output with the setw(int width) manipulator
-
- cout << setw(7) << index << " "
- << setw(13) << digit->GetTdc() << " "
- << setw(13) << digit->GetAdc() << " "
- << setw(6) << digit->GetSector() << " "
- << setw(6) << digit->GetPlate() << " "
- << setw(6) << digit->GetStrip() << " "
- << setw(7) << digit->GetPadx() << " "
- << setw(7) << digit->GetPadz() << " " << endl;
-
- } // end loop on digits
+ // Import the tree
+ nbytes += tofBranch->GetEvent(iEntry);
- } // close if "all" option selected
+ // Get the number of sdigits
+ Int_t ndig = sdigitsDummyContainer->GetEntriesFast();
+
+ for (Int_t k=0; k<ndig; k++) {
+ AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k);
+
+ Int_t vol[5]; // location for a sdigit
+
+ // check the sdigit volume
+ vol[0] = tofSdigit->GetSector();
+ vol[1] = tofSdigit->GetPlate();
+ vol[2] = tofSdigit->GetStrip();
+ vol[3] = tofSdigit->GetPadx();
+ vol[4] = tofSdigit->GetPadz();
+
+ if (fhitMap->TestHit(vol) != kEmpty) {
+ AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol));
+ sdig->Update(tofSdigit);
+
+ } else {
+
+ CollectSDigit(tofSdigit); // collect the current sdigit
+ fhitMap->SetHit(vol); // update the hitmap for location vol
+
+ } // if (hitMap->TestHit(vol) != kEmpty)
+
+ } // for (Int_t k=0; k<ndig; k++)
+
+ } // end loop on entries
+
+ sdigitsDummyContainer->Delete();
+ sdigitsDummyContainer=0;
+
+}
+
+
+//_____________________________________________________________________________
+void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit)
+{
+ //
+ // Add a TOF digit
+ // new with placement used
+ AliTOFSDigit sdigitCopy=AliTOFSDigit(*sdigit); // make a copy of the current sdigit
+ fSDigitsArray->Add(&sdigitCopy); // put it into tmp array
}