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