1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 // Do the Digitization (Digit) from summable Digits (SDigit)
19 // Allow the merging of signal file with background file(s).
21 /////////////////////////////////////////////////////////////////////////////////
23 // AliMUONDigitizerv2 digitizes digits from s-digits.
24 // Merging is allowed from multiple input streams. The first input stream is
25 // assumed to be the signal and all other input streams as assumed to be
27 // Chamber response is applied to the digits identically to AliMUONDigitizerv1.
29 /////////////////////////////////////////////////////////////////////////////////
32 #include "AliMUONData.h"
33 #include "AliMUONLoader.h"
34 #include "AliMUONConstants.h"
35 #include "AliMUONChamber.h"
36 #include "AliMUONDigit.h"
37 #include "AliMUONDigitizerv2.h"
38 #include "AliMUONTransientDigit.h"
41 ClassImp(AliMUONDigitizerv2)
43 //___________________________________________
44 AliMUONDigitizerv2::AliMUONDigitizerv2() : AliMUONDigitizer()
46 /// Default ctor - don't use it
49 //___________________________________________
50 AliMUONDigitizerv2::AliMUONDigitizerv2(AliRunDigitizer* manager) : AliMUONDigitizer(manager)
52 /// ctor which should be used
55 //___________________________________________
56 AliMUONDigitizerv2::~AliMUONDigitizerv2()
61 //-----------------------------------------------------------------------
62 void AliMUONDigitizerv2::GenerateTransientDigits()
64 /// Loop over all chambers and s-digits in the input stream and create
65 /// AliMUONTransientDigit objects from them. These are then added to fTDList.
67 AliDebug(2,"Generating transient digits using treeH = 0x%X");
72 TClonesArray* muonSDigits;
73 for (Int_t ich = 0; ich < AliMUONConstants::NCh(); ich++) // loop over chamber
75 fMUONData->ResetSDigits();
76 fMUONData->GetSDigits();
77 muonSDigits = fMUONData->SDigits(ich);
78 ndig = muonSDigits->GetEntriesFast();
79 for (k = 0; k < ndig; k++)
81 sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k);
82 MakeTransientDigitFromSDigit(ich,sDigit);
84 // fMUONData->ResetSDigits();
85 // fMUONData->GetCathodeS(1);
86 // muonSDigits = fMUONData->SDigits(ich);
87 // ndig=muonSDigits->GetEntriesFast();
88 // for (k = 0; k < ndig; k++)
90 // sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k);
91 // MakeTransientDigitFromSDigit(ich,sDigit);
93 } // SDigits loop, end loop over chamber
96 //------------------------------------------------------------------------
97 void AliMUONDigitizerv2::MakeTransientDigitFromSDigit(Int_t iChamber, AliMUONDigit* sDigit)
99 /// Makes a transient digit from the specified s-digit from the specified chamber.
100 /// Once the digit is created it is added to the fTDList.
102 AliDebug(4,Form("Making transient digit from s-digit for chamber %d.", iChamber));
105 // Creating a new TransientDigits from SDigit
106 digits[0] = sDigit->PadX(); // Padx of the Digit
107 digits[1] = sDigit->PadY(); // Pady of the Digit
108 digits[2] = sDigit->Cathode()+1; // Cathode plane
109 digits[3] = sDigit->Signal(); // Induced charge in the Pad
111 digits[4] = sDigit->Signal();
115 digits[5] = sDigit->Hit(); // Hit number in the list
116 digits[6] = sDigit->DetElemId();
118 AliDebug(5,Form("Made digit from sDigit 0x%X: PadX %d\tPadY %d\tPlane %d\tCharge %d\tHit %d\tidDE %d",
119 (void*)sDigit, digits[0], digits[1], digits[2], digits[3], digits[5], digits[6]));
122 AliMUONTransientDigit* mTD = new AliMUONTransientDigit(iChamber, digits);
123 // Copy list of tracks and trackcharge
124 for(Int_t itrack = 0; itrack < sDigit->Ntracks(); ++itrack)
126 Int_t track = sDigit->Track(itrack);
127 if (track < 0) break; // Check if we reached the end of the track list.
128 mTD->AddToTrackList( track + fMask, sDigit->TrackCharge(itrack) );
131 OnCreateTransientDigit(mTD, sDigit);
132 AddOrUpdateTransientDigit(mTD);
135 //------------------------------------------------------------------------
136 void AliMUONDigitizerv2::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[7])
138 /// Override to add new digits to the digits tree TreeD.
139 fMUONData->AddDigit(chamber, tracks, charges, digits);
142 //------------------------------------------------------------------------
143 Int_t AliMUONDigitizerv2::GetSignalFrom(AliMUONTransientDigit* td)
145 /// Derived to apply the chamber response model to the digit.
146 /// Using AliMUONChamber::ResponseModel() for this.
148 AliDebug(4, "Applying response of chamber to TransientDigit signal.");
150 // Digit Response (noise, threshold, saturation, ...)
151 Int_t q = td->Signal();
152 AliMUONChamber& chamber = fMUON->Chamber(td->Chamber());
153 AliMUONResponse* response = chamber.ResponseModel();
154 q = response->DigitResponse(q, td);
155 if ( q >= response->Saturation() )
157 td->Saturated(kTRUE);
162 //------------------------------------------------------------------------
163 Bool_t AliMUONDigitizerv2::InitInputData(AliMUONLoader* muonloader)
165 /// Overridden to initialize fMUONData to read from the s-digits tree TreeS.
166 /// If the s-digits are not loaded then the muon loader is used to load the
167 /// s-digits into memory.
169 AliDebug(3,"Loading s-digits in READ mode and setting the tree address.");
170 fMUONData->SetLoader(muonloader);
172 if (muonloader->TreeS() == NULL)
174 muonloader->LoadSDigits("READ");
175 if (muonloader->TreeS() == NULL)
177 AliError("Can not load the s-digits tree.");
182 fMUONData->SetTreeAddress("S");
186 //------------------------------------------------------------------------
187 void AliMUONDigitizerv2::CleanupInputData(AliMUONLoader* muonloader)
189 /// Overridden to release and unload s-digits from memory.
191 AliDebug(3,"Releasing loaded s-digits.");
192 fMUONData->ResetSDigits();
193 muonloader->UnloadSDigits();
196 //------------------------------------------------------------------------
197 Bool_t AliMUONDigitizerv2::InitOutputData(AliMUONLoader* muonloader)
199 /// Derived to initialize the output digits tree TreeD, create it if necessary
200 /// and sets the fMUONData tree address to treeD.
202 AliDebug(3, "Creating digits branch and setting the tree address.");
204 fMUONData->SetLoader(muonloader);
206 // New branch per chamber for MUON digit in the tree of digits
207 if (muonloader->TreeD() == NULL)
209 muonloader->MakeDigitsContainer();
210 if (muonloader->TreeD() == NULL)
212 AliError("Could not create TreeD.");
217 fMUONData->MakeBranch("D");
218 fMUONData->SetTreeAddress("D");
223 //------------------------------------------------------------------------
224 void AliMUONDigitizerv2::FillOutputData()
226 /// Derived to fill TreeD and resets the digit array in fMUONData.
228 AliDebug(3, "Filling trees with digits.");
229 fMUONData->Fill("D");
230 fMUONData->ResetDigits();
233 //------------------------------------------------------------------------
234 void AliMUONDigitizerv2::CleanupOutputData(AliMUONLoader* muonloader)
236 /// Derived to write the digits tree and then unload the digits tree once written.
238 AliDebug(3, "Writing digits and releasing pointers.");
239 muonloader->WriteDigits("OVERWRITE");
240 muonloader->UnloadDigits();