X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUONDigitizerv2.cxx;h=b0af4057458ddd93e8d8e020c769597bdaaef757;hb=b1318453c443076bc2608bb6411574b9655972d5;hp=4775e343dbb2a278bddca72dbf5428c931c35ca4;hpb=94e6f326506f78c61e4a132bba4194578158112d;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUONDigitizerv2.cxx b/MUON/AliMUONDigitizerv2.cxx index 4775e343dbb..b0af4057458 100644 --- a/MUON/AliMUONDigitizerv2.cxx +++ b/MUON/AliMUONDigitizerv2.cxx @@ -1,463 +1,276 @@ +/************************************************************************** + * 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$ */ // Do the Digitization (Digit) from summable Digits (SDigit) // Allow the merging of signal file with background file(s). -#include -#include -#include -#include -#include -#include -#include +///////////////////////////////////////////////////////////////////////////////// +// +// AliMUONDigitizerv2 digitizes digits from s-digits. +// Merging is allowed from multiple input streams. The first input stream is +// assumed to be the signal and all other input streams as assumed to be +// background. +// Chamber response is applied to the digits identically to AliMUONDigitizerv1. +// +///////////////////////////////////////////////////////////////////////////////// #include "AliMUON.h" -#include "AliMUONChamber.h" +#include "AliMUONData.h" +#include "AliMUONLoader.h" #include "AliMUONConstants.h" +#include "AliMUONChamber.h" #include "AliMUONDigit.h" #include "AliMUONDigitizerv2.h" -#include "AliMUONHit.h" -#include "AliMUONHitMapA1.h" -#include "AliMUONPadHit.h" #include "AliMUONTransientDigit.h" -#include "AliRun.h" -#include "AliRunDigitizer.h" -#include "AliRunLoader.h" -#include "AliLoader.h" +#include "AliMUONTriggerDecision.h" +#include "AliLog.h" ClassImp(AliMUONDigitizerv2) //___________________________________________ -AliMUONDigitizerv2::AliMUONDigitizerv2() : - AliDigitizer(), - fHitMap(0), - fTDList(0), - fTDCounter(0), - fDebug(0), - fMask(0), - fSignal(0) +AliMUONDigitizerv2::AliMUONDigitizerv2() : AliMUONDigitizer() { -// Default ctor - don't use it - if (GetDebug()>2) - cerr<<"AliMUONDigitizerv2::AliMUONDigitizerv2" - <<"(AliRunDigitizer* manager) was processed"<2) - cerr<<"AliMUONDigitizerv2::AliMUONDigitizerv2" - <<"(AliRunDigitizer* manager) was processed"<ResetSDigits(); + fMUONData->GetSDigits(); + muonSDigits = fMUONData->SDigits(ich); + ndig = muonSDigits->GetEntriesFast(); + for (k = 0; k < ndig; k++) + { + sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k); + MakeTransientDigitFromSDigit(ich,sDigit); + } +// fMUONData->ResetSDigits(); +// fMUONData->GetCathodeS(1); +// muonSDigits = fMUONData->SDigits(ich); +// ndig=muonSDigits->GetEntriesFast(); +// for (k = 0; k < ndig; k++) +// { +// sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k); +// MakeTransientDigitFromSDigit(ich,sDigit); +// } + } // SDigits loop, end loop over chamber } //------------------------------------------------------------------------ -void AliMUONDigitizerv2::AddTransientDigit(AliMUONTransientDigit * mTD) +void AliMUONDigitizerv2::MakeTransientDigitFromSDigit(Int_t iChamber, AliMUONDigit* sDigit) { - // Choosing the maping of the cathode plane of the chamber: - Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh(); - fTDList->AddAtAndExpand(mTD, fTDCounter); - fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter); - fTDCounter++; +// Makes a transient digit from the specified s-digit from the specified chamber. +// Once the digit is created it is added to the fTDList. + + AliDebug(4,Form("Making transient digit from s-digit for chamber %d.", iChamber)); + Int_t digits[7]; + // + // Creating a new TransientDigits from SDigit + digits[0] = sDigit->PadX(); // Padx of the Digit + digits[1] = sDigit->PadY(); // Pady of the Digit + digits[2] = sDigit->Cathode()+1; // Cathode plane + digits[3] = sDigit->Signal(); // Induced charge in the Pad + if (fSignal) + digits[4] = sDigit->Signal(); + else + digits[4] = 0; + + digits[5] = sDigit->Hit(); // Hit number in the list + digits[6] = sDigit->DetElemId(); + + AliDebug(5,Form("Made digit from sDigit 0x%X: PadX %d\tPadY %d\tPlane %d\tCharge %d\tHit %d\tidDE %d", + (void*)sDigit, digits[0], digits[1], digits[2], digits[3], digits[5], digits[6])); + + + AliMUONTransientDigit* mTD = new AliMUONTransientDigit(iChamber, digits); + // Copy list of tracks and trackcharge + for(Int_t itrack = 0; itrack < kMAXTRACKS; itrack++) + { + Int_t track = sDigit->Track(itrack); + if (track < 0) break; // Check if we reached the end of the track list. + mTD->AddToTrackList( track + fMask, sDigit->TrackCharge(itrack) ); + } + + OnCreateTransientDigit(mTD, sDigit); + AddOrUpdateTransientDigit(mTD); } //------------------------------------------------------------------------ -Bool_t AliMUONDigitizerv2::ExistTransientDigit(AliMUONTransientDigit * mTD) +void AliMUONDigitizerv2::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[7]) { - // Choosing the maping of the cathode plane of the chamber: - Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh(); - return( fHitMap[iNchCpl]->TestHit(mTD->PadX(), mTD->PadY()) ); +// Override to add new digits to the digits tree TreeD. + fMUONData->AddDigit(chamber, tracks, charges, digits); } //------------------------------------------------------------------------ -Bool_t AliMUONDigitizerv2::Init() +Int_t AliMUONDigitizerv2::GetSignalFrom(AliMUONTransientDigit* td) { +// Derived to apply the chamber response model to the digit. +// Using AliMUONChamber::ResponseModel() for this. -// Initialization - if (GetDebug()>2) Info("Init","AliMUONDigitizerv2::Init() starts"); - - //Loaders (We assume input0 to be the output too) - AliRunLoader * runloader; // Input loader - AliLoader * gime; - - // Getting runloader - runloader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0)); - if (runloader == 0x0) { - Error("Init","RunLoader is not in input file 0"); - return kFALSE; // RunDigitizer is not working. - } - // Getting MUONloader - gime = runloader->GetLoader("MUONLoader"); - gime->LoadSDigits("READ"); - gime->LoadDigits("RECREATE"); - - return kTRUE; + AliDebug(4, "Applying response of chamber to TransientDigit signal."); + // + // Digit Response (noise, threshold, saturation, ...) + Int_t q = td->Signal(); + AliMUONChamber& chamber = fMUON->Chamber(td->Chamber()); + AliMUONResponse* response = chamber.ResponseModel(); + q = response->DigitResponse(q, td); + return q; } //------------------------------------------------------------------------ -void AliMUONDigitizerv2::UpdateTransientDigit(Int_t /*track*/, AliMUONTransientDigit * mTD) +Bool_t AliMUONDigitizerv2::InitInputData(AliMUONLoader* muonloader) { - // Choosing the maping of the cathode plane of the chamber: - Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh(); - AliMUONTransientDigit *pdigit = - static_cast(fHitMap[iNchCpl]->GetHit(mTD->PadX(),mTD->PadY())); - // update charge - // - Int_t iqpad = mTD->Signal(); // charge per pad - pdigit->AddSignal(iqpad); - pdigit->AddPhysicsSignal(iqpad); - // update list of tracks - // - // List of tracks and trackcharge - Int_t itrack; - for(itrack=0;itrackUpdateTrackList(mTD->Track(itrack), mTD->TrackCharge(itrack)); - } +// Overridden to initialize fMUONData to read from the s-digits tree TreeS. +// If the s-digits are not loaded then the muon loader is used to load the +// s-digits into memory. + + AliDebug(3,"Loading s-digits in READ mode and setting the tree address."); + fMUONData->SetLoader(muonloader); + + if (muonloader->TreeS() == NULL) + { + muonloader->LoadSDigits("READ"); + if (muonloader->TreeS() == NULL) + { + AliError("Can not load the s-digits tree."); + return kFALSE; + } + } + + fMUONData->SetTreeAddress("S"); + return kTRUE; } -//-------------------------------------------------------------------------- -void AliMUONDigitizerv2::MakeTransientDigitFromSDigit(Int_t iChamber, AliMUONDigit * sDigit) +//------------------------------------------------------------------------ +void AliMUONDigitizerv2::CleanupInputData(AliMUONLoader* muonloader) { - Int_t digits[6]; - - - // - // Creating a new TransientDigits from SDigit - digits[0] = sDigit->PadX(); // Padx of the Digit - digits[1] = sDigit->PadY(); // Pady of the Digit - digits[2] = sDigit->Cathode()+1; // Cathode plane - digits[3] = sDigit->Signal(); // Induced charge in the Pad - if (fSignal) digits[4] = sDigit->Signal(); - else digits[4] = 0; - digits[5] = sDigit->Hit(); // Hit number in the list - if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::MakeTransientDigitFromSDigit " << - "PadX "<< digits[0] << " " << - "PadY "<< digits[1] << " " << - "Plane " << digits[2] << " " << - "Charge " << digits[3] <<" " << - "Hit " << digits[5] << endl; - - if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::MakeTransientDigitFromSDigit Creating AliMUONTransientDigit"<AddToTrackList(fMask+sDigit->Track(itrack), sDigit->TrackCharge(itrack)); - } - - if (!ExistTransientDigit(mTD)) { - AddTransientDigit(mTD); - if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::MakeTransientDigitFromSDigit Adding TransientDigit"<2) cerr<<"AliMUONDigitizerv2::MakeTransientDigitFromSDigit updating TransientDigit"<ResetSDigits(); + muonloader->UnloadSDigits(); } -//----------------------------------------------------------------------- -void AliMUONDigitizerv2::Exec(Option_t* option) +//------------------------------------------------------------------------ +Bool_t AliMUONDigitizerv2::InitOutputData(AliMUONLoader* muonloader) { - TString optionString = option; - if (optionString.Data() == "deb") { - Info("Digitize","Called with option deb "); - fDebug = 3; - } - - AliRun *aliRun; - AliMUONChamber* chamber; - AliSegmentation* c1Segmentation; //Cathode plane c1 of the chamber - AliSegmentation* c2Segmentation; //Cathode place c2 of the chamber - - if (GetDebug()>2) Info("Exec","AliMUONDigitizerv2::Exec() starts"); - fTDList = new TObjArray; - - //Loaders (We assume input0 to be the output too) - AliRunLoader *runloader, *runloaderOut; // Input / Output loaders - AliLoader *gime, *gimeOut; - - // Getting runloader - runloader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0)); - if (runloader == 0x0) { - Error("Exec","RunLoader is not in input file 0"); - return; // RunDigitizer is not working. - } - // Getting MUONloader - gime = runloader->GetLoader("MUONLoader"); - if (gime->TreeS()==0x0) { - if (GetDebug()>2) Info("Exec","TreeS is not loaded yet. Loading..."); - gime->LoadSDigits("READ"); - if (GetDebug()>2) Info("Exec","Now treeS is %#x. MUONLoader is %#x",gime->TreeS(),gime); - } - - if (GetDebug()>2) Info("Exec","Loaders ready"); - - if (runloader->GetAliRun() == 0x0) runloader->LoadgAlice(); - aliRun = runloader->GetAliRun(); - - // Getting Module MUON - AliMUON *pMUON = (AliMUON *) aliRun->GetDetector("MUON"); - if (!pMUON) { - Error("Digitize","Module MUON not found in the input file"); - return; - } - // Getting Muon data - AliMUONData * muondata = pMUON->GetMUONData(); - - // Loading Event - Int_t currentevent = fManager->GetOutputEventNr(); - - if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::Exec() Event Number is "<GetOutputFolderName()); - gimeOut = runloaderOut->GetLoader("MUONLoader"); - - - if (gimeOut->TreeD() == 0x0) { - gimeOut->MakeDigitsContainer(); - } - TTree* treeD = gimeOut->TreeD(); - muondata->SetLoader(gimeOut); - muondata->MakeBranch("D"); - muondata->SetTreeAddress("D"); - - // Array of pointer of the AliMUONHitMapA1: - // two HitMaps per chamber, or one HitMap per cahtode plane - fHitMap= new AliMUONHitMapA1* [2*AliMUONConstants::NCh()]; - - //Loop over chambers for the definition AliMUONHitMap - for (Int_t i=0; iChamber(i)); - c1Segmentation = chamber->SegmentationModel(1); // Cathode plane 1 - fHitMap[i] = new AliMUONHitMapA1(c1Segmentation, fTDList); - c2Segmentation = chamber->SegmentationModel(2); // Cathode plane 2 - fHitMap[i+AliMUONConstants::NCh()] = new AliMUONHitMapA1(c2Segmentation, fTDList); - } - -// Loop over files to merge and to digitize - fSignal = kTRUE; - for (Int_t inputFile=0; inputFileGetNinputs(); inputFile++) { - if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::Exec() Input File is "<SetLoader(gime); - muondata->SetTreeAddress("S"); - } else { - // Connect MUON Hit branch - fSignal = kFALSE; - runloader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile)); - if (runloader == 0x0) { - cerr<<"AliMUONDigitizerv2::Digitize() RunLoader for inputFile "<GetLoader("MUONLoader"); - if (gime->TreeS() == 0x0) gime->LoadSDigits("READ"); - muondata->SetLoader(gime); - muondata->SetTreeAddress("S"); - } - - // Setting the address - TTree *treeS = gime->TreeS(); - if (treeS == 0x0) { - Error("Digitize","Can not get TreeS from input %d",inputFile); - Info("Digitize","Now treeS is %#x. MUONLoader is %#x",gime->TreeS(),gime); - return; - } - if (GetDebug()>2) { - cerr<<"AliMUONDigitizerv2::Exec inputFile is "<2) cerr<<"AliMUONDigitizerv2::Exec Setting tree addresses"<GetMask(inputFile); - // - // Loop over SDigits - Int_t ndig,k; - AliMUONDigit *sDigit; - TClonesArray * muonSDigits; - for (Int_t ich = 0; ich < AliMUONConstants::NCh(); ich++) { // loop over chamber - muondata->ResetSDigits(); - muondata->GetCathodeS(0); - //TClonesArray * - muonSDigits = muondata->SDigits(ich); - ndig = muonSDigits->GetEntriesFast(); - // printf("\n 1 Found %d Sdigits in %p chamber %d", ndig, muonSDigits,ich); - Int_t n = 0; - for (k = 0; k < ndig; k++) { - sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k); - MakeTransientDigitFromSDigit(ich,sDigit); - } - muondata->ResetSDigits(); - muondata->GetCathodeS(1); - //TClonesArray * - muonSDigits = muondata->SDigits(ich); - ndig=muonSDigits->GetEntriesFast(); - // printf("\n 2 Found %d Sdigits in %p chamber %d", ndig, muonSDigits,ich); - n = 0; - for (k = 0; k < ndig; k++) { - sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k); - MakeTransientDigitFromSDigit(ich,sDigit); - } - - } // SDigits loop end loop over chamber - } // end file loop - if (GetDebug()>2) cerr<<"AliMUONDigitizerv2::Exec End of Sdigits, file loops"<GetEntriesFast(); - Int_t digits[6]; - for (Int_t nent = 0; nent < nentries; nent++) { - AliMUONTransientDigit *address = (AliMUONTransientDigit*)fTDList->At(nent); - if (address == 0) continue; - Int_t ich = address->Chamber(); - Int_t q = address->Signal(); - chamber = &(pMUON->Chamber(ich)); - // - // Digit Response (noise, threshold, saturation, ...) - AliMUONResponse * response = chamber->ResponseModel(); - q = response->DigitResponse(q,address); - - if (!q) continue; - - digits[0] = address->PadX(); - digits[1] = address->PadY(); - digits[2] = address->Cathode()-1; - digits[3] = q; - digits[4] = address->Physics(); - digits[5] = address->Hit(); - - Int_t nptracks = address->GetNTracks(); - - if (nptracks > kMAXTRACKS) { - if (GetDebug() >0) { - cerr<<"AliMUONDigitizer:Exec nptracks > 10 "< 2 && GetDebug() >2) { - cerr<<"AliMUONDigitizer::Exec nptracks > 2 "<GetTrack(tr); - charges[tr] = address->GetCharge(tr); - } //end loop over list of tracks for one pad - // Sort list of tracks according to charge - if (nptracks > 1) { - SortTracks(tracks,charges,nptracks); - } - if (nptracks < kMAXTRACKS ) { - for (Int_t i = nptracks; i < kMAXTRACKS; i++) { - tracks[i] = -1; - charges[i] = 0; - } +// Derived to initialize the output digits tree TreeD, create it if necessary +// and sets the fMUONData tree address to treeD. + + AliDebug(3, "Creating digits branch and setting the tree address."); + + fMUONData->SetLoader(muonloader); + + // New branch per chamber for MUON digit in the tree of digits + if (muonloader->TreeD() == NULL) + { + muonloader->MakeDigitsContainer(); + if (muonloader->TreeD() == NULL) + { + AliError("Could not create TreeD."); + return kFALSE; + } } + + fMUONData->MakeBranch("D"); + fMUONData->SetTreeAddress("D"); - // Add digits - if (GetDebug()>3) cerr<<"AliMUONDigitzerv2::Exec TransientDigit to Digit"<AddDigit(ich,tracks,charges,digits); -// printf("test rm ich %d padX %d padY %d \n",ich, digits[0], digits[1]); - } - muondata->SetLoader(gimeOut); - muondata->Fill("D"); - muondata->ResetDigits(); - } // end loop cathode - fTDList->Delete(); - - for(Int_t ii = 0; ii < 2*AliMUONConstants::NCh(); ++ii) { - if (fHitMap[ii]) { - delete fHitMap[ii]; - fHitMap[ii] = 0; - } - } - - if (GetDebug()>2) - cerr<<"AliMUONDigitizer::Exec: writing the TreeD: " - <GetName()<WriteDigits("OVERWRITE"); - delete [] fHitMap; - delete fTDList; - muondata->ResetSDigits(); - gime->UnloadSDigits(); - gimeOut->UnloadDigits(); + return kTRUE; } + //------------------------------------------------------------------------ -void AliMUONDigitizerv2::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr) +void AliMUONDigitizerv2::FillOutputData() { - // - // Sort the list of tracks contributing to a given digit - // Only the 3 most significant tracks are acctually sorted - // - - // - // Loop over signals, only 3 times - // - - Int_t qmax; - Int_t jmax; - Int_t idx[3] = {-2,-2,-2}; - Int_t jch[3] = {-2,-2,-2}; - Int_t jtr[3] = {-2,-2,-2}; - Int_t i,j,imax; - - if (ntr<3) imax=ntr; - else imax=3; - for(i=0;i qmax) { - qmax = charges[j]; - jmax=j; - } - } - - if(qmax > 0) { - idx[i]=jmax; - jch[i]=charges[jmax]; - jtr[i]=tracks[jmax]; - } - - } - - for(i=0;i<3;i++){ - if (jtr[i] == -2) { - charges[i]=0; - tracks[i]=0; - } else { - charges[i]=jch[i]; - tracks[i]=jtr[i]; - } - } +// Derived to fill TreeD and resets the digit array in fMUONData. + + AliDebug(3, "Filling trees with digits."); + fMUONData->Fill("D"); + fMUONData->ResetDigits(); +} + +//------------------------------------------------------------------------ +void AliMUONDigitizerv2::CleanupOutputData(AliMUONLoader* muonloader) +{ +// Derived to write the digits tree and then unload the digits tree once written. + + AliDebug(3, "Writing digits and releasing pointers."); + muonloader->WriteDigits("OVERWRITE"); + muonloader->UnloadDigits(); +} + +//----------------------------------------------------------------------- + +void AliMUONDigitizerv2::CleanupTriggerArrays() +{ + fTrigDec->ClearDigits(); +} + +//------------------------------------------------------------------------ +void AliMUONDigitizerv2::AddDigitTrigger( + Int_t chamber, Int_t tracks[kMAXTRACKS], + Int_t charges[kMAXTRACKS], Int_t digits[7], + Int_t digitindex + ) +{ +// Derived to add digits to TreeD for trigger. + fTrigDec->AddDigit(chamber, tracks, charges, digits, digitindex); +} + +//------------------------------------------------------------------------ +void AliMUONDigitizerv2::FillTriggerOutput() +{ +// Derived to fill TreeD and resets the trigger array in fMUONData. + + AliDebug(3,"Filling trees with trigger."); + fMUONData->Fill("GLT"); + fMUONData->ResetTrigger(); +} + +//------------------------------------------------------------------------ +void AliMUONDigitizerv2::CreateTrigger() +{ + fMUONData->MakeBranch("GLT"); + fMUONData->SetTreeAddress("GLT"); + fTrigDec->Digits2Trigger(); + FillTriggerOutput(); + }