X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUONDigitizerv1.cxx;h=b5e01b07a25d98eb173003cdbb37327f2f960653;hb=e81ffe364e20fd9dffe19b73193988f054a2529e;hp=317d97ccbc9b11d2931db854a0bdd77a5dac10a1;hpb=69e452ffe3a776a8c8285034e7faa834bdd6349d;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUONDigitizerv1.cxx b/MUON/AliMUONDigitizerv1.cxx index 317d97ccbc9..b5e01b07a25 100644 --- a/MUON/AliMUONDigitizerv1.cxx +++ b/MUON/AliMUONDigitizerv1.cxx @@ -1,5 +1,4 @@ - #include #include #include @@ -8,6 +7,11 @@ #include #include +#include "AliRun.h" +#include "AliRunDigitizer.h" +#include "AliRunLoader.h" +#include "AliLoader.h" + #include "AliMUON.h" #include "AliMUONChamber.h" #include "AliMUONConstants.h" @@ -17,488 +21,260 @@ #include "AliMUONHitMapA1.h" #include "AliMUONPadHit.h" #include "AliMUONTransientDigit.h" -#include "AliRun.h" -#include "AliRunDigitizer.h" -#include "AliRunLoader.h" -#include "AliLoader.h" + +///////////////////////////////////////////////////////////////////////////////// +// +// AliMUONDigitizerv1 implements a full digitizer to digitize digits directly +// from hits. It also performs merging over several input streams. +// The first input stream is assumed to be the signal and all other input +// streams are assumed to be background. SDigits are never generated by this +// digitizer and one should use the AliMUONSDigitizerv1 for that task. +// +// NOTE: This digitizer will become depricated in the future in favour of +// AliMUONSDigitizerv1 and AliMUONDigitizerv2. +// +///////////////////////////////////////////////////////////////////////////////// ClassImp(AliMUONDigitizerv1) //___________________________________________ -AliMUONDigitizerv1::AliMUONDigitizerv1() : - AliDigitizer(), - fHitMap(0), - fTDList(0), - fTDCounter(0), - fDebug(0), - fMask(0), - fSignal(0) +AliMUONDigitizerv1::AliMUONDigitizerv1() : AliMUONDigitizer() { -// Default ctor - don't use it - if (GetDebug()>2) - cerr<<"AliMUONDigitizerv1::AliMUONDigitizerv1" - <<"(AliRunDigitizer* manager) was processed"<2) - cerr<<"AliMUONDigitizerv1::AliMUONDigitizerv1" - <<"(AliRunDigitizer* manager) was processed"<Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh(); - fTDList->AddAtAndExpand(mTD, fTDCounter); - fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter); - fTDCounter++; -} +// Loops over all tracks and hits in the current selected event and calls +// MakeTransientDigitsFromHit for each hit. +// Note: Charge correlation is applied to the tracking chambers. + + TTree* treeH = gime->TreeH(); + if (GetDebug() > 1) + Info("GenerateTransientDigits", "Generating transient digits using treeH = 0x%X" + , (void*)treeH); + // + // Loop over tracks + Int_t ntracks = (Int_t) treeH->GetEntries(); + for (Int_t itrack = 0; itrack < ntracks; itrack++) + { + if (GetDebug() > 2) Info("GenerateTransientDigits", "Processing track %d...", itrack); + muondata->ResetHits(); + treeH->GetEvent(itrack); + // + // Loop over hits + TClonesArray* hits = muondata->Hits(); + for (Int_t ihit = 0; ihit < hits->GetEntriesFast(); ihit++) + { + AliMUONHit* mHit = static_cast( hits->At(ihit) ); + Int_t ichamber = mHit->Chamber()-1; // chamber number + if (ichamber > AliMUONConstants::NCh()-1) + { + Error("GenerateTransientDigits", + "Hit 0x%X has a invalid chamber number: %d", ichamber); + continue; + } + // + //Dumping Hit content: + if (GetDebug() > 2) + { + Info("GenerateTransientDigits", + "Hit %d: chamber = %d\tX = %f\tY = %f\tZ = %f\teloss = %f", + ihit, mHit->Chamber(), mHit->X(), mHit->Y(), mHit->Z(), mHit->Eloss() + ); + } + // + // Inititializing Correlation + AliMUONChamber& chamber = pMUON->Chamber(ichamber); + chamber.ChargeCorrelationInit(); + if (ichamber < AliMUONConstants::NTrackingCh()) + { + // Tracking Chamber + // Initialize hit position (cursor) in the segmentation model + chamber.SigGenInit(mHit->X(), mHit->Y(), mHit->Z()); + }; // else do nothing for Trigger Chambers + + MakeTransientDigitsFromHit(itrack, ihit, mHit); + } // hit loop + } // track loop +}; + +//-------------------------------------------------------------------------- +void AliMUONDigitizerv1::MakeTransientDigitsFromHit(Int_t track, Int_t iHit, AliMUONHit * mHit) +{ +// This method is called for every hit in an event to generate AliMUONTransientDigits +// from the hit and add these to fTDList. +// The AliMUONChamber::DisIntegration method us used to figure out which pads are +// fired for a given hit. We then loop over the fired pads and add an AliMUONTransientDigit +// for each pad. + + if (GetDebug() > 3) + Info("MakeTransientDigitsFromHit", "Making transient digit for hit number %d.", iHit); + + // + // Calls the charge disintegration method of the current chamber + if (GetDebug() > 4) + Info("MakeTransientDigitsFromHit", "Calling AliMUONChamber::DisIngtegration..."); + + Float_t newdigit[6][500]; // Pad information + Int_t nnew=0; // Number of touched Pads per hit + Int_t ichamber = mHit->Chamber()-1; + AliMUONChamber& chamber = pMUON->Chamber(ichamber); + chamber.DisIntegration(mHit->Eloss(), mHit->Age(), mHit->X(), mHit->Y(), mHit->Z(), nnew, newdigit); + + // Creating new TransientDigits from hit + for(Int_t iTD = 0; iTD < nnew; iTD++) + { + Int_t charge; + Int_t digits[6]; + + digits[0] = Int_t(newdigit[1][iTD]); // Padx of the Digit + digits[1] = Int_t(newdigit[2][iTD]); // Pady of the Digit + digits[2] = Int_t(newdigit[5][iTD]); // Cathode plane + digits[3] = Int_t(newdigit[3][iTD]); // Induced charge in the Pad + if (fSignal) + { + charge = digits[3]; + digits[4] = Int_t(newdigit[3][iTD]); // Signal due to physics + } + else + { + charge = digits[3] + fMask; + digits[4] = 0; // No signal due to physics since this is now background. + }; + digits[5] = iHit+fMask; // Hit number in the list + + if (GetDebug() > 4) + Info("MakeTransientDigitsFromHit", + "DisIntegration result %d: PadX %d\tPadY %d\tPlane %d\tCharge %d\tHit %d", + iTD, digits[0], digits[1], digits[2], digits[3], digits[5]); + + AliMUONTransientDigit* mTD = new AliMUONTransientDigit(ichamber, digits); + mTD->AddToTrackList(track + fMask, charge); + + OnCreateTransientDigit(mTD, mHit); + AddOrUpdateTransientDigit(mTD); + }; +}; //------------------------------------------------------------------------ -Bool_t AliMUONDigitizerv1::ExistTransientDigit(AliMUONTransientDigit * mTD) +void AliMUONDigitizerv1::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[6]) { - // 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()) ); -} +// Derived to add digits to TreeD. + muondata->AddDigit(chamber, tracks, charges, digits); +}; //------------------------------------------------------------------------ -Bool_t AliMUONDigitizerv1::Init() +Int_t AliMUONDigitizerv1::GetSignalFrom(AliMUONTransientDigit* td) { +// Derived to apply the chamber response model to the digit. +// Using AliMUONChamber::ResponseModel() for this. -// Initialization - if (GetDebug()>2) Info("Init","AliMUONDigitizerv1::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->LoadHits("READ"); - gime->LoadDigits("RECREATE"); - - return kTRUE; -} + if (GetDebug() > 3) + Info("GetSignalFrom", "Applying response of chamber to TransientDigit signal."); + // + // Digit Response (noise, threshold, saturation, ...) + Int_t q = td->Signal(); + AliMUONChamber& chamber = pMUON->Chamber(td->Chamber()); + AliMUONResponse* response = chamber.ResponseModel(); + q = response->DigitResponse(q, td); + return q; +}; //------------------------------------------------------------------------ -void AliMUONDigitizerv1::UpdateTransientDigit(Int_t track, AliMUONTransientDigit * mTD) +Bool_t AliMUONDigitizerv1::InitOutputData(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 - // - Int_t charge; - track=+ fMask; - if (fSignal) charge = iqpad; - //else charge = kBgTag; - else charge = iqpad + fMask; - - pdigit->UpdateTrackList(track,charge); -} +// Derived to initialize the output digits tree TreeD, create it if necessary +// and sets the muondata tree address to treeD. + + if (GetDebug() > 2) + Info("InitOutputData", "Creating digits branch and setting the tree address."); + + muondata->SetLoader(muonloader); + + // New branch per chamber for MUON digit in the tree of digits + if (muonloader->TreeD() == NULL) + { + muonloader->MakeDigitsContainer(); + if (muonloader->TreeD() == NULL) + { + Error("InitOutputData", "Could not create TreeD."); + return kFALSE; + }; + }; + + muondata->MakeBranch("D"); + muondata->SetTreeAddress("D"); + + return kTRUE; +}; +//------------------------------------------------------------------------ +void AliMUONDigitizerv1::FillOutputData() +{ +// Derived to fill TreeD and resets the digit array in muondata. -//-------------------------------------------------------------------------- -void AliMUONDigitizerv1::MakeTransientDigit(Int_t track, Int_t iHit, AliMUONHit * mHit) + if (GetDebug() > 2) Info("FillOutputData", "Filling trees with digits."); + muondata->Fill("D"); + muondata->ResetDigits(); +}; + +//------------------------------------------------------------------------ +void AliMUONDigitizerv1::CleanupOutputData(AliMUONLoader* muonloader) { - AliMUON *pMUON = (AliMUON *) gAlice->GetModule("MUON"); - if (!pMUON) { - cerr<<"AliMUONDigitizerv1::Digitize Error:" - <<" module MUON not found in the input file"<2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit starts"<Chamber()-1; - AliMUONChamber & chamber = pMUON->Chamber(ichamber); - Float_t xhit = mHit->X(); - Float_t yhit = mHit->Y(); - Float_t zhit = mHit->Z(); - Float_t eloss= mHit->Eloss(); - Float_t tof = mHit->Age(); - // Variables for chamber response from AliMUONChamber::DisIntegration - Float_t newdigit[6][500]; // Pad information - Int_t nnew=0; // Number of touched Pads per hit - Int_t digits[6]; - - // - // Calls the charge disintegration method of the current chamber - if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit calling AliMUONChamber::DisIngtegration starts"<2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit " << - "PadX "<< digits[0] << " " << - "PadY "<< digits[1] << " " << - "Plane " << digits[2] << " " << - "Charge " << digits[3] <<" " << - "Hit " << digits[5] << endl; - // list of tracks - Int_t charge; - track += fMask; - if (fSignal) charge = digits[3]; - //else charge = kBgTag; - else charge = digits[3] + fMask; - - if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit Creating AliMUONTransientDigit"<AddToTrackList(track,charge); - if (!ExistTransientDigit(mTD)) { - AddTransientDigit(mTD); - if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit Adding TransientDigit"<2) cerr<<"AliMUONDigitizerv1::MakeTransientDigit updating TransientDigit"< 2) Info("CleanupOutputData", "Writing digits and releasing pointers."); + muonloader->WriteDigits("OVERWRITE"); + muonloader->UnloadDigits(); +}; + + +//------------------------------------------------------------------------ +Bool_t AliMUONDigitizerv1::InitInputData(AliMUONLoader* muonloader) { - TString optionString = option; - if (optionString.Data() == "deb") { - Info("Digitize","Called with option deb "); - fDebug = 3; - } - - AliMUONChamber* chamber; - AliSegmentation* c1Segmentation; //Cathode plane c1 of the chamber - AliSegmentation* c2Segmentation; //Cathode place c2 of the chamber - - if (GetDebug()>2) Info("Digitize","AliMUONDigitizerv1::Digitize() starts"); - fTDList = new TObjArray; - - //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("Digitize","RunLoader is not in input file 0"); - return; // RunDigitizer is not working. - } - // Getting MUONloader - gime = runloader->GetLoader("MUONLoader"); - if (gime->TreeH()==0x0) { - if (GetDebug()>2) Info("Digitize","TreeH is not loaded yet. Loading..."); - gime->LoadHits("READ"); - if (GetDebug()>2) Info("Digitize","Now treeH is %#x. MUONLoader is %#x",gime->TreeH(),gime); - } - - if (GetDebug()>2) Info("Digitize","Loaders ready"); - - if (runloader->GetAliRun() == 0x0) runloader->LoadgAlice(); - gAlice = runloader->GetAliRun(); - - // Getting Module MUON - AliMUON *pMUON = (AliMUON *) gAlice->GetDetector("MUON"); - if (!pMUON) { - Error("Digitize","Module MUON not found in the input file"); - return; - } - // Getting Muon data - AliMUONData * muondata = pMUON->GetMUONData(); - muondata->SetLoader(gime); - muondata->SetTreeAddress("H"); - - // Loading Event - Int_t currentevent = fManager->GetOutputEventNr(); - - if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Digitize() Event Number is "<GetOutputFolderName()); - //AliLoader * gimeout = runloaderout->GetLoader("MUONLoader"); - // New branch per chamber for MUON digit in the tree of digits - if (gime->TreeD() == 0x0) { - gime->MakeDigitsContainer(); - } - TTree* treeD = gime->TreeD(); - 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<<"AliMUONDigitizerv1::Digitize() Input File is "< 0 ) { - fSignal = kFALSE; - runloader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile)); - if (runloader == 0x0) { - cerr<<"AliMUONDigitizerv1::Digitize() RunLoader for inputFile "<GetLoader("MUONLoader"); - if (gime->TreeH() == 0x0) gime->LoadHits("READ"); - muondata->SetLoader(gime); - muondata->SetTreeAddress("H"); - } - - // Setting the address - TTree *treeH = gime->TreeH(); - if (treeH == 0x0) { - Error("Digitize","Can not get TreeH from input %d",inputFile); - Info("Digitize","Now treeH is %#x. MUONLoader is %#x",gime->TreeH(),gime); - return; - } - if (GetDebug()>2) { - cerr<<"AliMUONDigitizerv1::Exec inputFile is "<2) cerr<<"AliMUONDigitizerv1::Exec Setting tree addresses"<GetMask(inputFile); - // - // Loop over tracks - Int_t itrack; - Int_t ntracks = (Int_t) treeH->GetEntries(); - for (itrack = 0; itrack < ntracks; itrack++) { - if (GetDebug()>2) cerr<<"AliMUONDigitizerv1::Exec itrack = "<ResetHits(); - treeH->GetEvent(itrack); - // - // Loop over hits - Int_t ihit, ichamber; - AliMUONHit* mHit; - TClonesArray* hits = muondata->Hits(); - for(ihit = 0; ihit < hits->GetEntriesFast(); ihit++) { - mHit = static_cast(hits->At(ihit)); - ichamber = mHit->Chamber()-1; // chamber number - if (ichamber > AliMUONConstants::NCh()-1) { - cerr<<"AliMUONDigitizer: ERROR: " - <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): " - <Chamber(ichamber)); - // - //Dumping Hit content: - if (GetDebug()>2) { - cerr<<"AliMuonDigitizerv1::Exec ihit, ichamber, x, y, z, eloss " << - ihit << " " << - mHit->Chamber() << " " << - mHit->X() << " " << - mHit->Y() << " " << - mHit->Z() << " " << - mHit->Eloss() << " " << endl; - } - // - // Inititializing Correlation - chamber->ChargeCorrelationInit(); - if (ichamber < AliMUONConstants::NTrackingCh()) { - // Tracking Chamber - // Initialize hit position (cursor) in the segmentation model - chamber->SigGenInit(mHit->X(), mHit->Y(), mHit->Z()); - } else { - // Trigger Chamber - } - MakeTransientDigit(itrack, ihit, mHit); - } // hit loop - } // track loop - } // end file loop - if (GetDebug()>2) cerr<<"AliMUONDigitizer::Exec End of hits, track and file loops"<GetOutputFolderName()); - gime = runloader->GetLoader("MUONLoader"); - muondata->SetLoader(gime); - - // Loop on cathodes - Int_t icat; - for(icat=0; icat<2; icat++) { - // - // Filling Digit List - Int_t tracks[kMAXTRACKS]; - Int_t charges[kMAXTRACKS]; - Int_t nentries = fTDList->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; - } - } - - // Add digits - if (GetDebug()>3) cerr<<"AliMUONDigitzerv1::Exex TransientDigit to Digit"<AddDigit(ich,tracks,charges,digits); -// printf("test rm ich %d padX %d padY %d \n",ich, digits[0], digits[1]); - } - // Filling list of digits per chamber for a given cathode. - 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()<GetOutputFolderName()); - gime = runloader->GetLoader("MUONLoader"); - gime->WriteDigits("OVERWRITE"); - delete [] fHitMap; - delete fTDList; - muondata->ResetHits(); - gime->UnloadHits(); - gime->UnloadDigits(); -} +// Derived to initialise the input to read from TreeH the hits tree. +// If the hits are not loaded then we load the hits using the muon loader. + + if (GetDebug() > 2) + Info("InitInputData", "Loading hits in READ mode and setting the tree address."); + + muondata->SetLoader(muonloader); + + if (muonloader->TreeH() == NULL) + { + muonloader->LoadHits("READ"); + if (muonloader->TreeH() == NULL) + { + Error("InitInputData", "Can not load the hits tree."); + return kFALSE; + }; + }; + + muondata->SetTreeAddress("H"); + return kTRUE; +}; + //------------------------------------------------------------------------ -void AliMUONDigitizerv1::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr) +void AliMUONDigitizerv1::CleanupInputData(AliMUONLoader* muonloader) { - // - // 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 release the loaded hits and unload them. + + if (GetDebug() > 2) Info("CleanupInputData", "Releasing loaded hits."); + muondata->ResetHits(); + muonloader->UnloadHits(); +}; +