]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSDigitizerv1.cxx
Using the recommended way of forward declarations for TVector and TMatrix (see v5...
[u/mrichter/AliRoot.git] / MUON / AliMUONSDigitizerv1.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 // AliMUONSDigitizerv1 digitizes hits from the input stream into s-digits. 
21 // The s-digits are written to the s-digit tree TreeS.
22 // The same algorithm is implemented as for AliMUONDigitizerv1 however the
23 // chamber response is not applied to the s-digits and we write to TreeS and 
24 // not TreeD.
25 //
26 /////////////////////////////////////////////////////////////////////////////////
27
28 #include "AliMUONSDigitizerv1.h"
29 #include "AliMUON.h"
30 #include "AliMUONLoader.h"
31 #include "AliMUONConstants.h"
32 #include "AliMUONChamber.h"
33 #include "AliMUONData.h"
34 #include "AliMUONDigit.h"
35 #include "AliMUONHit.h"
36 #include "AliMUONTransientDigit.h"
37 #include "AliLog.h"
38
39 ClassImp(AliMUONSDigitizerv1)
40
41 //___________________________________________
42 AliMUONSDigitizerv1::AliMUONSDigitizerv1() 
43   : AliMUONDigitizer()
44 {
45         // Default ctor - don't use it
46 }
47
48 //___________________________________________
49 AliMUONSDigitizerv1::AliMUONSDigitizerv1(AliRunDigitizer* manager) 
50   : AliMUONDigitizer(manager)
51 {
52         // ctor which should be used
53 }
54
55 //___________________________________________
56 AliMUONSDigitizerv1::~AliMUONSDigitizerv1()
57 {
58         // Destructor
59 }
60
61 //-----------------------------------------------------------------------
62 void AliMUONSDigitizerv1::GenerateTransientDigits()
63 {
64 // Loops over all tracks and hits in the current selected event and calls 
65 // MakeTransientDigitsFromHit for each hit. 
66 // Note: Charge correlation is applied to the tracking chambers. 
67
68         TTree* treeH = fGime->TreeH();
69         AliDebug(2, Form("Generating transient digits using treeH = 0x%X"
70                         , (void*)treeH));
71         //
72         // Loop over tracks
73         Int_t ntracks = (Int_t) treeH->GetEntries();
74         for (Int_t itrack = 0; itrack < ntracks; itrack++) 
75         {
76                 AliDebug(3, Form("Processing track %d...", itrack));
77                 fMUONData->ResetHits();
78                 treeH->GetEvent(itrack);
79                 //
80                 //  Loop over hits
81                 TClonesArray* hits = fMUONData->Hits();
82                 for (Int_t ihit = 0; ihit < hits->GetEntriesFast(); ihit++) 
83                 {
84                         AliMUONHit* mHit = static_cast<AliMUONHit*>( hits->At(ihit) );
85                         Int_t ichamber = mHit->Chamber()-1;  // chamber number
86                         if (ichamber > AliMUONConstants::NCh()-1) 
87                         {
88                                 AliError(Form("Hit 0x%X has a invalid chamber number: %d", ichamber));
89                                 continue;
90                         }
91                         //
92                         //Dumping Hit content:
93                         AliDebug(3,Form("Hit %d: chamber = %d\tX = %f\tY = %f\tZ = %f\teloss = %f",
94                                         ihit, mHit->Chamber(), mHit->X(), mHit->Y(), mHit->Z(), mHit->Eloss()
95                                     ));
96                         // 
97                         // Inititializing Correlation
98                         AliMUONChamber& chamber = fMUON->Chamber(ichamber);
99                         chamber.ChargeCorrelationInit();
100 //                      if (ichamber < AliMUONConstants::NTrackingCh()) 
101 //                      {
102 //                              // Tracking Chamber
103 //                              // Initialize hit position (cursor) in the segmentation model 
104                           
105 //                        chamber.SigGenInit(mHit);
106
107 //                      } // else do nothing for Trigger Chambers
108                         
109                         MakeTransientDigitsFromHit(itrack, ihit, mHit);
110                 } // hit loop
111         } // track loop      
112 }
113
114 //--------------------------------------------------------------------------
115 void AliMUONSDigitizerv1::MakeTransientDigitsFromHit(Int_t track, Int_t iHit, AliMUONHit * mHit)
116 {  
117 // This method is called for every hit in an event to generate AliMUONTransientDigits 
118 // from the hit and add these to fTDList.
119 // The AliMUONChamber::DisIntegration method us used to figure out which pads are 
120 // fired for a given hit. We then loop over the fired pads and add an AliMUONTransientDigit
121 // for each pad.
122
123         AliDebug(4,Form("Making transient digit for hit number %d.", iHit));
124                 
125         //
126         // Calls the charge disintegration method of the current chamber 
127         AliDebug(5,"Calling AliMUONChamber::DisIngtegration...");
128
129         Float_t newdigit[6][500];  // Pad information
130         Int_t nnew=0;              // Number of touched Pads per hit
131         Int_t ichamber = mHit->Chamber()-1;
132         AliMUONChamber& chamber = fMUON->Chamber(ichamber);
133
134         chamber.DisIntegration(mHit, nnew, newdigit);
135
136         // Creating new TransientDigits from hit
137         for(Int_t iTD = 0; iTD < nnew; iTD++) 
138         {
139                 Int_t charge;   
140                 Int_t digits[7];
141                 
142                 digits[0] = Int_t(newdigit[1][iTD]);  // Padx of the Digit
143                 digits[1] = Int_t(newdigit[2][iTD]);  // Pady of the Digit
144                 digits[2] = Int_t(newdigit[5][iTD]);  // Cathode plane
145                 digits[3] = Int_t(newdigit[3][iTD]);  // Induced charge in the Pad
146                 if (fSignal)
147                 { 
148                         charge = digits[3];
149                         digits[4] = Int_t(newdigit[3][iTD]);  // Signal due to physics
150                 }
151                 else
152                 {
153                         charge = digits[3] + fMask;
154                         digits[4] = 0;    // No signal due to physics since this is now background.
155                 }
156                 digits[5] = iHit+fMask;    // Hit number in the list
157                 digits[6] =  mHit->DetElemId();
158
159                 AliDebug(5,Form("MakeTransientDigitsFromHit", 
160                                 "DisIntegration result %d: PadX %d\tPadY %d\tPlane %d\tCharge %d\tHit %d\tidDE %d",
161                                 iTD, digits[0], digits[1], digits[2], digits[3], digits[5], digits[6]));
162
163                 AliMUONTransientDigit* mTD = new AliMUONTransientDigit(ichamber, digits);
164                 mTD->AddToTrackList(track + fMask, charge);
165
166                 OnCreateTransientDigit(mTD, mHit);
167                 AddOrUpdateTransientDigit(mTD);
168         }
169 }
170
171 //------------------------------------------------------------------------
172 void AliMUONSDigitizerv1::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[7])
173 {
174 // Derived to write to the s-digit tree TreeS.
175
176         fMUONData->AddSDigit(chamber, tracks, charges, digits);   
177 }
178
179 //------------------------------------------------------------------------
180 Int_t AliMUONSDigitizerv1::GetSignalFrom(AliMUONTransientDigit* td)
181 {
182 // Returns the transient digit signal as is without applying the chamber response.
183         AliDebug(4,"Returning TransientDigit signal.");
184         return td->Signal(); 
185 }
186
187 //------------------------------------------------------------------------
188 Bool_t AliMUONSDigitizerv1::InitOutputData(AliMUONLoader* muonloader)
189 {
190 // Overridden to initialise the output tree to be TreeS rather than TreeD.
191         AliDebug(3,"Creating s-digits branch and setting the tree address.");
192
193         fMUONData->SetLoader(muonloader);
194
195         // New branch per chamber for MUON digit in the tree of digits
196         if (muonloader->TreeS() == NULL)
197         {
198                 muonloader->MakeSDigitsContainer();
199                 if (muonloader->TreeS() == NULL)
200                 {
201                         AliError("Could not create TreeS.");
202                         return kFALSE;
203                 }
204         }
205
206         fMUONData->MakeBranch("S");
207         fMUONData->SetTreeAddress("S");
208         
209         return kTRUE;
210 }
211
212 //------------------------------------------------------------------------
213 void AliMUONSDigitizerv1::FillOutputData()
214 {
215 // Overridden to fill TreeS rather than TreeD.
216
217         AliDebug(3,"Filling trees with s-digits.");
218         fMUONData->Fill("S");
219         fMUONData->ResetSDigits();
220 }
221
222 //------------------------------------------------------------------------
223 void AliMUONSDigitizerv1::CleanupOutputData(AliMUONLoader* muonloader)
224 {
225 // Overridden to write and then cleanup TreeS that was initialised in InitOutputData.
226         AliDebug(3,"Writing s-digits and releasing pointers.");
227         muonloader->WriteSDigits("OVERWRITE");
228         fMUONData->ResetSDigits();
229         muonloader->UnloadSDigits();
230 }
231
232 //------------------------------------------------------------------------
233 Bool_t AliMUONSDigitizerv1::InitInputData(AliMUONLoader* muonloader)
234 {
235 // Derived to initialise the input to read from TreeH the hits tree. 
236 // If the hits are not loaded then we load the hits using the muon loader.
237
238         AliDebug(3, "Loading hits in READ mode and setting the tree address.");
239
240         fMUONData->SetLoader(muonloader);
241
242         if (muonloader->TreeH() == NULL)
243         {
244                 muonloader->LoadHits("READ");
245                 if (muonloader->TreeH() == NULL)
246                 {
247                         AliError("Can not load the hits tree.");
248                         return kFALSE;
249                 }
250         }
251
252         fMUONData->SetTreeAddress("H");
253         return kTRUE;
254 }
255
256 //------------------------------------------------------------------------
257 void AliMUONSDigitizerv1::CleanupInputData(AliMUONLoader* muonloader)
258 {
259 // Derived to release the loaded hits and unload them.
260
261         AliDebug(3, "Releasing loaded hits.");
262         fMUONData->ResetHits();
263         muonloader->UnloadHits();
264 }
265