]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitizerv2.cxx
Using TGeo as default transport package
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerv2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 //  Do the Digitization (Digit) from summable Digits (SDigit)
19 //  Allow the merging of signal file with background file(s).
20
21 /////////////////////////////////////////////////////////////////////////////////
22 //
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 
26 // background.
27 // Chamber response is applied to the digits identically to AliMUONDigitizerv1.
28 //
29 /////////////////////////////////////////////////////////////////////////////////
30
31 #include "AliMUON.h"
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"
39 #include "AliMUONTriggerDecision.h"
40 #include "AliLog.h"
41
42 ClassImp(AliMUONDigitizerv2)
43
44 //___________________________________________
45 AliMUONDigitizerv2::AliMUONDigitizerv2() : AliMUONDigitizer()
46 {
47         // Default ctor - don't use it
48 }
49
50 //___________________________________________
51 AliMUONDigitizerv2::AliMUONDigitizerv2(AliRunDigitizer* manager) : AliMUONDigitizer(manager)
52 {
53         // ctor which should be used
54 }
55
56 //___________________________________________
57 AliMUONDigitizerv2::~AliMUONDigitizerv2()
58 {
59         // Destructor
60 }
61
62 //-----------------------------------------------------------------------
63 void AliMUONDigitizerv2::GenerateTransientDigits()
64 {
65 // Loop over all chambers and s-digits in the input stream and create 
66 // AliMUONTransientDigit objects from them. These are then added to fTDList.
67
68         AliDebug(2,"Generating transient digits using treeH = 0x%X");
69         //
70         // Loop over SDigits
71         Int_t ndig, k;
72         AliMUONDigit* sDigit;
73         TClonesArray* muonSDigits;
74         for (Int_t ich = 0; ich < AliMUONConstants::NCh(); ich++)  // loop over chamber
75         {
76                 fMUONData->ResetSDigits();
77                 fMUONData->GetCathodeS(0);
78                 muonSDigits = fMUONData->SDigits(ich); 
79                 ndig = muonSDigits->GetEntriesFast();
80                 for (k = 0; k < ndig; k++)
81                 {
82                         sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k);
83                         MakeTransientDigitFromSDigit(ich,sDigit);
84                 }
85                 fMUONData->ResetSDigits();
86                 fMUONData->GetCathodeS(1);
87                 muonSDigits = fMUONData->SDigits(ich); 
88                 ndig=muonSDigits->GetEntriesFast();
89                 for (k = 0; k < ndig; k++)
90                 {
91                         sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k);
92                         MakeTransientDigitFromSDigit(ich,sDigit);
93                 }
94         } // SDigits loop, end loop over chamber
95 }
96
97 //------------------------------------------------------------------------
98 void AliMUONDigitizerv2::MakeTransientDigitFromSDigit(Int_t iChamber, AliMUONDigit* sDigit)
99 {
100 // Makes a transient digit from the specified s-digit from the specified chamber. 
101 // Once the digit is created it is added to the fTDList.
102
103         AliDebug(4,Form("Making transient digit from s-digit for chamber %d.", iChamber));
104         Int_t digits[7];
105         //
106         // Creating a new TransientDigits from SDigit
107         digits[0] = sDigit->PadX();  // Padx of the Digit
108         digits[1] = sDigit->PadY();  // Pady of the Digit
109         digits[2] = sDigit->Cathode()+1;  // Cathode plane
110         digits[3] = sDigit->Signal();  // Induced charge in the Pad
111         if (fSignal)
112                 digits[4] = sDigit->Signal();
113         else
114                 digits[4] = 0;
115                 
116         digits[5] = sDigit->Hit();    // Hit number in the list
117         if (GetSegmentation() == 1)
118           digits[6] = 0;
119         else
120           digits[6] = sDigit->DetElemId();
121
122         AliDebug(5,Form("Made digit from sDigit 0x%X: PadX %d\tPadY %d\tPlane %d\tCharge %d\tHit %d\tidDE %d",
123                         (void*)sDigit, digits[0], digits[1], digits[2], digits[3], digits[5], digits[6]));
124
125         
126         AliMUONTransientDigit* mTD = new AliMUONTransientDigit(iChamber, digits);
127         // Copy list of tracks and trackcharge
128         for(Int_t itrack = 0; itrack < kMAXTRACKS; itrack++)
129         {
130                 Int_t track = sDigit->Track(itrack);
131                 if (track < 0) break;  // Check if we reached the end of the track list.
132                 mTD->AddToTrackList( track + fMask, sDigit->TrackCharge(itrack) );
133         }
134
135         OnCreateTransientDigit(mTD, sDigit);
136         AddOrUpdateTransientDigit(mTD);
137 }
138
139 //------------------------------------------------------------------------
140 void AliMUONDigitizerv2::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[7])
141 {
142 // Override to add new digits to the digits tree TreeD.
143         fMUONData->AddDigit(chamber, tracks, charges, digits);   
144 }
145
146 //------------------------------------------------------------------------
147 Int_t AliMUONDigitizerv2::GetSignalFrom(AliMUONTransientDigit* td)
148 {
149 // Derived to apply the chamber response model to the digit. 
150 // Using AliMUONChamber::ResponseModel() for this.
151
152         AliDebug(4, "Applying response of chamber to TransientDigit signal.");
153         //
154         //  Digit Response (noise, threshold, saturation, ...)
155         Int_t q = td->Signal(); 
156         AliMUONChamber& chamber = fMUON->Chamber(td->Chamber());
157         AliMUONResponse* response = chamber.ResponseModel();
158         q = response->DigitResponse(q, td);
159         return q;
160 }
161
162 //------------------------------------------------------------------------
163 Bool_t AliMUONDigitizerv2::InitInputData(AliMUONLoader* muonloader)
164 {
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.
168
169         AliDebug(3,"Loading s-digits in READ mode and setting the tree address.");
170         fMUONData->SetLoader(muonloader);
171
172         if (muonloader->TreeS() == NULL)
173         {
174                 muonloader->LoadSDigits("READ");
175                 if (muonloader->TreeS() == NULL)
176                 {
177                         AliError("Can not load the s-digits tree.");
178                         return kFALSE;
179                 }
180         }
181
182         fMUONData->SetTreeAddress("S");
183         return kTRUE;
184 }
185
186 //------------------------------------------------------------------------
187 void AliMUONDigitizerv2::CleanupInputData(AliMUONLoader* muonloader)
188 {
189 // Overridden to release and unload s-digits from memory.
190
191         AliDebug(3,"Releasing loaded s-digits.");
192         fMUONData->ResetSDigits();
193         muonloader->UnloadSDigits();
194 }
195
196 //------------------------------------------------------------------------
197 Bool_t AliMUONDigitizerv2::InitOutputData(AliMUONLoader* muonloader)
198 {
199 // Derived to initialize the output digits tree TreeD, create it if necessary
200 // and sets the fMUONData tree address to treeD.
201
202         AliDebug(3, "Creating digits branch and setting the tree address.");
203
204         fMUONData->SetLoader(muonloader);
205
206         // New branch per chamber for MUON digit in the tree of digits
207         if (muonloader->TreeD() == NULL)
208         {
209                 muonloader->MakeDigitsContainer();
210                 if (muonloader->TreeD() == NULL)
211                 {
212                         AliError("Could not create TreeD.");
213                         return kFALSE;
214                 }
215         }
216
217         fMUONData->MakeBranch("D");
218         fMUONData->SetTreeAddress("D");
219         
220         return kTRUE;
221 }
222
223 //------------------------------------------------------------------------
224 void AliMUONDigitizerv2::FillOutputData()
225 {
226 // Derived to fill TreeD and resets the digit array in fMUONData.
227
228         AliDebug(3, "Filling trees with digits.");
229         fMUONData->Fill("D");
230         fMUONData->ResetDigits();
231 }
232
233 //------------------------------------------------------------------------
234 void AliMUONDigitizerv2::CleanupOutputData(AliMUONLoader* muonloader)
235 {
236 // Derived to write the digits tree and then unload the digits tree once written.
237
238         AliDebug(3, "Writing digits and releasing pointers.");
239         muonloader->WriteDigits("OVERWRITE");
240         muonloader->UnloadDigits();
241 }
242
243 //-----------------------------------------------------------------------
244
245 void AliMUONDigitizerv2::CleanupTriggerArrays()
246 {
247   fTrigDec->ClearDigits();
248 }
249
250 //------------------------------------------------------------------------
251 void AliMUONDigitizerv2::AddDigitTrigger(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[7])
252 {
253 // Derived to add digits to TreeD for trigger.
254   fTrigDec->AddDigit(chamber, tracks, charges, digits); 
255 }
256
257 //------------------------------------------------------------------------
258 void AliMUONDigitizerv2::FillTriggerOutput()
259 {
260 // Derived to fill TreeD and resets the trigger array in fMUONData.
261
262         AliDebug(3,"Filling trees with trigger.");
263         fMUONData->Fill("GLT");
264         fMUONData->ResetTrigger();
265 }
266
267 //------------------------------------------------------------------------
268 void AliMUONDigitizerv2::CreateTrigger()
269 {
270   fMUONData->MakeBranch("GLT");
271   fMUONData->SetTreeAddress("GLT");
272   fTrigDec->Digits2Trigger(); 
273   FillTriggerOutput();  
274
275 }