]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitizerv1.cxx
17c2965f647e0e741b302c16667250baf0e72a1c
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerv1.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 /////////////////////////////////////////////////////////////////////////////////
19 //
20 // AliMUONDigitizerv1 implements a full digitizer to digitize digits directly
21 // from hits. It also performs merging over several input streams. 
22 // The first input stream is assumed to be the signal and all other input
23 // streams are assumed to be background. SDigits are never generated by this
24 // digitizer and one should use the AliMUONSDigitizerv1 for that task. 
25 //
26 // NOTE: This digitizer will become depricated in the future in favour of
27 //       AliMUONSDigitizerv1 and AliMUONDigitizerv2.
28 //
29 /////////////////////////////////////////////////////////////////////////////////
30
31 #include <TTree.h> 
32
33 #include "AliMUON.h"
34 #include "AliMUONData.h"
35 #include "AliMUONLoader.h"
36 #include "AliMUONChamber.h"
37 #include "AliMUONConstants.h"
38 #include "AliMUONDigitizerv1.h"
39 #include "AliMUONHit.h"
40 #include "AliMUONTransientDigit.h"
41 #include "AliMUONTriggerDecision.h"
42
43 ClassImp(AliMUONDigitizerv1)
44
45 //___________________________________________
46 AliMUONDigitizerv1::AliMUONDigitizerv1() : AliMUONDigitizer()
47 {
48         // Default ctor - don't use it
49 }
50
51 //___________________________________________
52 AliMUONDigitizerv1::AliMUONDigitizerv1(AliRunDigitizer* manager) : AliMUONDigitizer(manager)
53 {
54         // ctor which should be used
55
56 }
57
58 //___________________________________________
59 AliMUONDigitizerv1::~AliMUONDigitizerv1()
60 {
61         // dtor
62 }
63 //-----------------------------------------------------------------------
64
65 void AliMUONDigitizerv1::CleanupTriggerArrays()
66 {
67   fTrigDec->ClearDigits();
68 }
69
70 //-----------------------------------------------------------------------
71 void AliMUONDigitizerv1::GenerateTransientDigits()
72 {
73 // Loops over all tracks and hits in the current selected event and calls 
74 // MakeTransientDigitsFromHit for each hit. 
75 // Note: Charge correlation is applied to the tracking chambers. 
76
77         TTree* treeH = fGime->TreeH();
78         if (GetDebug() > 1)
79                 Info("GenerateTransientDigits", "Generating transient digits using treeH = 0x%X"
80                         , (void*)treeH);
81         //
82         // Loop over tracks
83         Int_t ntracks = (Int_t) treeH->GetEntries();
84         for (Int_t itrack = 0; itrack < ntracks; itrack++) 
85         {
86                 if (GetDebug() > 2) Info("GenerateTransientDigits", "Processing track %d...", itrack);
87                 fMUONData->ResetHits();
88                 treeH->GetEvent(itrack);
89                 //
90                 //  Loop over hits
91                 TClonesArray* hits = fMUONData->Hits();
92                 for (Int_t ihit = 0; ihit < hits->GetEntriesFast(); ihit++) 
93                 {
94                         AliMUONHit* mHit = static_cast<AliMUONHit*>( hits->At(ihit) );
95                         Int_t ichamber = mHit->Chamber()-1;  // chamber number
96                         if (ichamber > AliMUONConstants::NCh()-1) 
97                         {
98                                 Error("GenerateTransientDigits", 
99                                         "Hit 0x%X has a invalid chamber number: %d", ichamber);
100                                 continue;
101                         }
102                         //
103                         //Dumping Hit content:
104                         if (GetDebug() > 2) 
105                         {
106                                 Info("GenerateTransientDigits", 
107                                         "Hit %d: chamber = %d\tX = %f\tY = %f\tZ = %f\teloss = %f",
108                                         ihit, mHit->Chamber(), mHit->X(), mHit->Y(), mHit->Z(), mHit->Eloss()
109                                     );
110                         }
111                         // 
112                         // Inititializing Correlation
113                         AliMUONChamber& chamber = fMUON->Chamber(ichamber);
114                         chamber.ChargeCorrelationInit();
115                         if (ichamber < AliMUONConstants::NTrackingCh()) 
116                         {
117                                 // Tracking Chamber
118                                 // Initialize hit position (cursor) in the segmentation model 
119                                 chamber.SigGenInit(mHit->X(), mHit->Y(), mHit->Z());
120                         }; // else do nothing for Trigger Chambers
121                         
122                         MakeTransientDigitsFromHit(itrack, ihit, mHit);
123                 } // hit loop
124         } // track loop      
125 };
126
127 //--------------------------------------------------------------------------
128 void AliMUONDigitizerv1::MakeTransientDigitsFromHit(Int_t track, Int_t iHit, AliMUONHit * mHit)
129 {  
130 // This method is called for every hit in an event to generate AliMUONTransientDigits 
131 // from the hit and add these to fTDList.
132 // The AliMUONChamber::DisIntegration method us used to figure out which pads are 
133 // fired for a given hit. We then loop over the fired pads and add an AliMUONTransientDigit
134 // for each pad.
135
136         if (GetDebug() > 3)
137                 Info("MakeTransientDigitsFromHit", "Making transient digit for hit number %d.", iHit);
138                 
139         //
140         // Calls the charge disintegration method of the current chamber 
141         if (GetDebug() > 4)
142                 Info("MakeTransientDigitsFromHit", "Calling AliMUONChamber::DisIngtegration...");
143
144         Float_t newdigit[6][500];  // Pad information
145         Int_t nnew=0;              // Number of touched Pads per hit
146         Int_t ichamber = mHit->Chamber()-1;
147         AliMUONChamber& chamber = fMUON->Chamber(ichamber);
148         chamber.DisIntegration(mHit->Eloss(), mHit->Age(), mHit->X(), mHit->Y(), mHit->Z(), nnew, newdigit);
149
150         // Creating new TransientDigits from hit
151         for(Int_t iTD = 0; iTD < nnew; iTD++) 
152         {
153                 Int_t charge;   
154                 Int_t digits[6];
155                 
156                 digits[0] = Int_t(newdigit[1][iTD]);  // Padx of the Digit
157                 digits[1] = Int_t(newdigit[2][iTD]);  // Pady of the Digit
158                 digits[2] = Int_t(newdigit[5][iTD]);  // Cathode plane
159                 digits[3] = Int_t(newdigit[3][iTD]);  // Induced charge in the Pad
160                 if (fSignal)
161                 { 
162                         charge = digits[3];
163                         digits[4] = Int_t(newdigit[3][iTD]);  // Signal due to physics
164                 }
165                 else
166                 {
167                         charge = digits[3] + fMask;
168                         digits[4] = 0;    // No signal due to physics since this is now background.
169                 };
170                 digits[5] = iHit+fMask;    // Hit number in the list
171
172                 if (GetDebug() > 4)
173                         Info("MakeTransientDigitsFromHit", 
174                                 "DisIntegration result %d: PadX %d\tPadY %d\tPlane %d\tCharge %d\tHit %d",
175                                 iTD, digits[0], digits[1], digits[2], digits[3], digits[5]);
176
177                 AliMUONTransientDigit* mTD = new AliMUONTransientDigit(ichamber, digits);
178                 mTD->AddToTrackList(track + fMask, charge);
179
180                 OnCreateTransientDigit(mTD, mHit);
181                 AddOrUpdateTransientDigit(mTD);
182         };
183 };
184
185 //------------------------------------------------------------------------
186 void AliMUONDigitizerv1::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[6])
187 {
188 // Derived to add digits to TreeD.
189   fMUONData->AddDigit(chamber, tracks, charges, digits);  
190 };
191
192 //------------------------------------------------------------------------
193 void AliMUONDigitizerv1::AddDigitTrigger(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[6])
194 {
195 // Derived to add digits to TreeD for trigger.
196   fTrigDec->AddDigit(chamber, tracks, charges, digits); 
197 };
198
199 //------------------------------------------------------------------------
200 void AliMUONDigitizerv1::FillTriggerOutput()
201 {
202 // Derived to fill TreeD and resets the trigger array in fMUONData.
203
204         if (GetDebug() > 2) Info("FillTriggerOutput", "Filling trees with trigger.");
205         fMUONData->Fill("GLT");
206         fMUONData->ResetTrigger();
207 };
208
209 //------------------------------------------------------------------------
210 void AliMUONDigitizerv1::CreateTrigger()
211 {
212   fMUONData->MakeBranch("GLT");
213   fMUONData->SetTreeAddress("GLT");
214   fTrigDec->Digits2Trigger(); 
215   FillTriggerOutput();  
216
217 };
218
219 //------------------------------------------------------------------------
220 Int_t AliMUONDigitizerv1::GetSignalFrom(AliMUONTransientDigit* td)
221 {
222 // Derived to apply the chamber response model to the digit. 
223 // Using AliMUONChamber::ResponseModel() for this.
224
225         if (GetDebug() > 3)
226                 Info("GetSignalFrom", "Applying response of chamber to TransientDigit signal.");
227         //
228         //  Digit Response (noise, threshold, saturation, ...)
229         Int_t q = td->Signal(); 
230         AliMUONChamber& chamber = fMUON->Chamber(td->Chamber());
231         AliMUONResponse* response = chamber.ResponseModel();
232         q = response->DigitResponse(q, td);
233         return q;
234 };
235
236 //------------------------------------------------------------------------
237 Bool_t AliMUONDigitizerv1::InitOutputData(AliMUONLoader* muonloader)
238 {
239 // Derived to initialize the output digits tree TreeD, create it if necessary
240 // and sets the fMUONData tree address to treeD.
241
242         if (GetDebug() > 2)
243                 Info("InitOutputData", "Creating digits branch and setting the tree address.");
244
245         fMUONData->SetLoader(muonloader);
246
247         // New branch per chamber for MUON digit in the tree of digits
248         if (muonloader->TreeD() == NULL)
249         {
250                 muonloader->MakeDigitsContainer();
251                 if (muonloader->TreeD() == NULL)
252                 {
253                         Error("InitOutputData", "Could not create TreeD.");
254                         return kFALSE;
255                 };
256         };
257
258         fMUONData->MakeBranch("D");
259         fMUONData->SetTreeAddress("D");
260         
261         return kTRUE;
262 };
263
264 //------------------------------------------------------------------------
265 void AliMUONDigitizerv1::FillOutputData()
266 {
267 // Derived to fill TreeD and resets the digit array in fMUONData.
268
269         if (GetDebug() > 2) Info("FillOutputData", "Filling trees with digits.");
270         fMUONData->Fill("D");
271         fMUONData->ResetDigits();
272 };
273
274 //------------------------------------------------------------------------
275 void AliMUONDigitizerv1::CleanupOutputData(AliMUONLoader* muonloader)
276 {
277 // Derived to write the digits tree and then unload the digits tree once written.
278
279         if (GetDebug() > 2) Info("CleanupOutputData", "Writing digits and releasing pointers.");
280         muonloader->WriteDigits("OVERWRITE");
281         muonloader->UnloadDigits();
282 };
283
284
285 //------------------------------------------------------------------------
286 Bool_t AliMUONDigitizerv1::InitInputData(AliMUONLoader* muonloader)
287 {
288 // Derived to initialise the input to read from TreeH the hits tree. 
289 // If the hits are not loaded then we load the hits using the muon loader.
290
291         if (GetDebug() > 2)
292                 Info("InitInputData", "Loading hits in READ mode and setting the tree address.");
293
294         fMUONData->SetLoader(muonloader);
295
296         if (muonloader->TreeH() == NULL)
297         {
298                 muonloader->LoadHits("READ");
299                 if (muonloader->TreeH() == NULL)
300                 {
301                         Error("InitInputData", "Can not load the hits tree.");
302                         return kFALSE;
303                 };
304         };
305
306         fMUONData->SetTreeAddress("H");
307         return kTRUE;
308 };
309
310 //------------------------------------------------------------------------
311 void AliMUONDigitizerv1::CleanupInputData(AliMUONLoader* muonloader)
312 {
313 // Derived to release the loaded hits and unload them.
314
315         if (GetDebug() > 2) Info("CleanupInputData", "Releasing loaded hits.");
316         fMUONData->ResetHits();
317         muonloader->UnloadHits();
318 };
319