]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitizerv1.cxx
Added customised streamer to AliMUONSt12QuadrantSegmentation (Ivana)
[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                           if (GetSegmentation() == 1) // old segmentation
115                             chamber.SigGenInit(mHit->X(), mHit->Y(), mHit->Z());
116                           else 
117                             chamber.SigGenInit(mHit);
118
119                         } // else do nothing for Trigger Chambers
120                         
121                         MakeTransientDigitsFromHit(itrack, ihit, mHit);
122                 } // hit loop
123         } // track loop      
124 }
125
126 //--------------------------------------------------------------------------
127 void AliMUONDigitizerv1::MakeTransientDigitsFromHit(Int_t track, Int_t iHit, AliMUONHit * mHit)
128 {  
129 // This method is called for every hit in an event to generate AliMUONTransientDigits 
130 // from the hit and add these to fTDList.
131 // The AliMUONChamber::DisIntegration method us used to figure out which pads are 
132 // fired for a given hit. We then loop over the fired pads and add an AliMUONTransientDigit
133 // for each pad.
134
135         AliDebug(4,Form("Making transient digit for hit number %d.", iHit));
136                 
137         //
138         // Calls the charge disintegration method of the current chamber 
139         AliDebug(5,"Calling AliMUONChamber::DisIngtegration...");
140
141         Float_t newdigit[6][500];  // Pad information
142         Int_t nnew=0;              // Number of touched Pads per hit
143         Int_t ichamber = mHit->Chamber()-1;
144         AliMUONChamber& chamber = fMUON->Chamber(ichamber);
145         if (GetSegmentation() == 1)
146           chamber.DisIntegration(mHit->Eloss(), mHit->Age(), mHit->X(), mHit->Y(), mHit->Z(), nnew, newdigit);
147         else
148           chamber.DisIntegration(mHit, 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[7];
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                 if (GetSegmentation() == 1)
172                   digits[6] = 0;
173                 else
174                   digits[6] =  mHit->DetElemId();
175
176                 AliDebug(5,Form("MakeTransientDigitsFromHit", 
177                                 "DisIntegration result %d: PadX %d\tPadY %d\tPlane %d\tCharge %d\tHit %d\tidDE %d",
178                                 iTD, digits[0], digits[1], digits[2], digits[3], digits[5], digits[6]));
179
180                 AliMUONTransientDigit* mTD = new AliMUONTransientDigit(ichamber, digits);
181                 mTD->AddToTrackList(track + fMask, charge);
182
183                 OnCreateTransientDigit(mTD, mHit);
184                 AddOrUpdateTransientDigit(mTD);
185         }
186 }
187
188 //------------------------------------------------------------------------
189 void AliMUONDigitizerv1::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[7])
190 {
191 // Derived to add digits to TreeD.
192   fMUONData->AddDigit(chamber, tracks, charges, digits);  
193 }
194
195 //------------------------------------------------------------------------
196 void AliMUONDigitizerv1::AddDigitTrigger(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[7])
197 {
198 // Derived to add digits to TreeD for trigger.
199   fTrigDec->AddDigit(chamber, tracks, charges, digits); 
200 }
201
202 //------------------------------------------------------------------------
203 void AliMUONDigitizerv1::FillTriggerOutput()
204 {
205 // Derived to fill TreeD and resets the trigger array in fMUONData.
206
207         AliDebug(3,"Filling trees with trigger.");
208         fMUONData->Fill("GLT");
209         fMUONData->ResetTrigger();
210 }
211
212 //------------------------------------------------------------------------
213 void AliMUONDigitizerv1::CreateTrigger()
214 {
215   fMUONData->MakeBranch("GLT");
216   fMUONData->SetTreeAddress("GLT");
217   fTrigDec->Digits2Trigger(); 
218   FillTriggerOutput();  
219
220 }
221
222 //------------------------------------------------------------------------
223 Int_t AliMUONDigitizerv1::GetSignalFrom(AliMUONTransientDigit* td)
224 {
225 // Derived to apply the chamber response model to the digit. 
226 // Using AliMUONChamber::ResponseModel() for this.
227
228         AliDebug(4, "Applying response of chamber to TransientDigit signal.");
229         //
230         //  Digit Response (noise, threshold, saturation, ...)
231         Int_t q = td->Signal(); 
232         AliMUONChamber& chamber = fMUON->Chamber(td->Chamber());
233         AliMUONResponse* response = chamber.ResponseModel();
234         q = response->DigitResponse(q, td);
235         return q;
236 }
237
238 //------------------------------------------------------------------------
239 Bool_t AliMUONDigitizerv1::InitOutputData(AliMUONLoader* muonloader)
240 {
241 // Derived to initialize the output digits tree TreeD, create it if necessary
242 // and sets the fMUONData tree address to treeD.
243
244         AliDebug(3, "Creating digits branch and setting the tree address.");
245
246         fMUONData->SetLoader(muonloader);
247
248         // New branch per chamber for MUON digit in the tree of digits
249         if (muonloader->TreeD() == NULL)
250         {
251                 muonloader->MakeDigitsContainer();
252                 if (muonloader->TreeD() == NULL)
253                 {
254                         AliError("Could not create TreeD.");
255                         return kFALSE;
256                 }
257         }
258
259         fMUONData->MakeBranch("D");
260         fMUONData->SetTreeAddress("D");
261         
262         return kTRUE;
263 }
264
265 //------------------------------------------------------------------------
266 void AliMUONDigitizerv1::FillOutputData()
267 {
268 // Derived to fill TreeD and resets the digit array in fMUONData.
269
270         AliDebug(3, "Filling trees with digits.");
271         fMUONData->Fill("D");
272         fMUONData->ResetDigits();
273 }
274
275 //------------------------------------------------------------------------
276 void AliMUONDigitizerv1::CleanupOutputData(AliMUONLoader* muonloader)
277 {
278 // Derived to write the digits tree and then unload the digits tree once written.
279
280         AliDebug(3, "Writing digits and releasing pointers.");
281         muonloader->WriteDigits("OVERWRITE");
282         muonloader->UnloadDigits();
283 }
284
285
286 //------------------------------------------------------------------------
287 Bool_t AliMUONDigitizerv1::InitInputData(AliMUONLoader* muonloader)
288 {
289 // Derived to initialise the input to read from TreeH the hits tree. 
290 // If the hits are not loaded then we load the hits using the muon loader.
291
292         AliDebug(3, "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                         AliError("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         AliDebug(3, "Releasing loaded hits.");
316         fMUONData->ResetHits();
317         muonloader->UnloadHits();
318 }
319