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