X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=TOF%2FAliTOFDigitizer.cxx;h=70d2fb62dc2790081cbcfb6fddfa8e758636f2db;hb=ca10471ab237f6c3a4ba69da0a8ff8c3d8b80d62;hp=340712fcb57cc0be01c6bb2a6c6cf1a684662e71;hpb=68861244d291f007608a46e0d3833153ee26bfd0;p=u%2Fmrichter%2FAliRoot.git diff --git a/TOF/AliTOFDigitizer.cxx b/TOF/AliTOFDigitizer.cxx index 340712fcb57..70d2fb62dc2 100644 --- a/TOF/AliTOFDigitizer.cxx +++ b/TOF/AliTOFDigitizer.cxx @@ -1,5 +1,5 @@ /************************************************************************** - * 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. * @@ -13,371 +13,334 @@ * 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 : Detector size may not be write. -// Warning in : 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 "TRandom.h" +#include +#include +#include +#include +#include +#include -#include -#include "AliRun.h" -#include "AliTOFdigit.h" -#include "AliTOFhit.h" #include "AliTOFDigitizer.h" +#include "AliTOF.h" +#include "AliTOFSDigitizer.h" +#include "AliTOFhit.h" +#include "AliTOFdigit.h" +#include "AliTOFSDigit.h" +#include "AliTOFHitMap.h" +#include "AliDigitizer.h" +#include "AliRunDigitizer.h" +#include "AliLog.h" +#include "AliRun.h" +#include "AliRunLoader.h" +#include "AliLoader.h" +#include "AliPDG.h" + +#include +#include 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() -{ - // 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 - if(!fIsInitialized){ +//--------------------------------------------------------------------- + +void AliTOFDigitizer::Exec(Option_t* /*option*/) +{ + // + // 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(fHeadersFile.IsNull()) - fHeadersFile="galice.root" ; + AliDebug(1, ""); - 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 - TFolder * alice = (TFolder*)gROOT->GetListOfBrowsables()->FindObject("FPAlice") ; - TTask * aliceSD = (TTask*)alice->FindObject("tasks/(S)Digitizer") ; - TTask * tofD = (TTask*)aliceSD->GetListOfTasks()->FindObject("TOF") ; - tofD->Add(this) ; - 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 + // get the ptr to TOF detector + AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ; - TRandom* rnd = new TRandom(); + //Make branches + char branchname[20]; + sprintf (branchname, "%s", tof->GetName ()); - // Collects all hits in the same active volume into digit + fDigits=new TClonesArray("AliTOFdigit",4000); + + AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); + if (outrl == 0x0) + { + AliError("Can not find Run Loader in output folder."); + return; + } + + AliLoader* outgime = outrl->GetLoader("TOFLoader"); + if (outgime == 0x0) + { + AliError("Can not get TOF Loader from Output Run Loader."); + return; + } - if(!fIsInitialized) - Init() ; + TTree* treeD = outgime->TreeD(); + if (treeD == 0x0) + { + outgime->MakeTree("D"); + treeD = outgime->TreeD(); + } + //Make branch for digits (to be created in Init()) + tof->MakeBranchInTree(treeD,branchname,&fDigits,4000); - if(strstr(option,"tim")) - gBenchmark->Start("TOFDigitizer"); + // 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) ; - - if(gAlice->TreeH()==0){ - cout << "AliTOFDigitizer: There is no Hit Tree" << endl; - return ; - } + // Loop over files to digitize + + for (Int_t inputFile=0; inputFileGetNinputs(); + inputFile++) { + ReadSDigit(inputFile); + } + + // create digits + CreateDigits(); + + // free used memory for Hit Map in current event + delete fhitMap; + fSDigitsArray->Delete(); + delete fSDigitsArray; + + treeD->Fill(); + + outgime->WriteDigits("OVERWRITE"); + outgime->UnloadDigits(); + 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=0; // 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++) { - //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 ; - } + Int_t vol[5]; // location for a digit + for (Int_t i=0; i<5; i++) vol[i] = -1; - fDigits->Clear(); - Int_t ndigits = 0 ; + // Get the information for this digit + AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k); - //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 = rnd->Gaus(idealtime, fTimeRes); - digit[0] = tdctime; - // typical Landau Distribution to be inserted here - Float_t idealcharge = hit->GetEdep(); - Float_t adccharge = rnd->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 - - delete rnd; - rnd = 0; + Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots + // for current sdigit - 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 [0-17] + Int_t plate = tofsdigit->GetPlate(); // range [0- 4] + Int_t strip = tofsdigit->GetStrip(); // range [0-19] + Int_t padz = tofsdigit->GetPadz(); // range [0- 1] + Int_t padx = tofsdigit->GetPadx(); // range [0-47] - //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<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47); - for(ibranch = 0;ibranch 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) { + AliFatal("strange sdigit found"); } + //------------------------------------------------------- - //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(kTreeD()->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 - //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; - } + 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); + + // new with placement must be used + // adding a TOF digit for each slot + TClonesArray &aDigits = *fDigits; + Int_t last=fDigits->GetEntriesFast(); + new (aDigits[last]) AliTOFdigit(tracknum, vol, digit); - 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 " <GetInputFolderName(inputFile)); + if (rl == 0x0) + { + AliError(Form("Can not find Run Loader in input %d folder.",inputFile)); + return; + } + + AliLoader* gime = rl->GetLoader("TOFLoader"); + if (gime == 0x0) + { + AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile)); + return; + } + + TTree* currentTreeS=gime->TreeS(); + if (currentTreeS == 0x0) + { + Int_t retval = gime->LoadSDigits(); + if (retval) + { + AliError(Form("Error occured while loading S. Digits for Input %d",inputFile)); + return; + } + currentTreeS=gime->TreeS(); + if (currentTreeS == 0x0) + { + AliError(Form("Can not get S. Digits Tree for Input %d",inputFile)); + return; + } + } + // 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){ + AliFatal(Form("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 = 0; + + 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; kUncheckedAt(k); + + Int_t vol[5]; // location for a sdigit + for (Int_t i=0; i<5; i++) vol[i] = -1; + + // 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(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; kDelete(); + + } // end loop on entries + + delete sdigitsDummyContainer; + +} + + +//_____________________________________________________________________________ +void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit) +{ + // + // Add a TOF sdigit in container + // new with placement must be used + TClonesArray &aSDigitsArray = *fSDigitsArray; + Int_t last=fSDigitsArray->GetEntriesFast(); + // make a copy of the current sdigit and + // put it into tmp array + new (aSDigitsArray[last]) AliTOFSDigit(*sdigit); }