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