]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitizerv2.cxx
e8eb27438a25201e93f1e6b4f191c8c239049d37
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerv2.cxx
1
2 //  Do the Digitization (Digit) from summable Digits (SDigit)
3 //  Allow the merging of signal file with background file(s).
4
5 #include <Riostream.h>
6 #include <TDirectory.h>
7 #include <TFile.h>
8 #include <TObjArray.h>
9 #include <TPDGCode.h>
10 #include <TTree.h> 
11 #include <TMath.h>
12
13 #include "AliMUON.h"
14 #include "AliMUONChamber.h"
15 #include "AliMUONConstants.h"
16 #include "AliMUONDigit.h"
17 #include "AliMUONDigitizerv2.h"
18 #include "AliMUONHit.h"
19 #include "AliMUONHitMapA1.h"
20 #include "AliMUONPadHit.h"
21 #include "AliMUONTransientDigit.h"
22 #include "AliRun.h"
23 #include "AliRunDigitizer.h"
24 #include "AliRunLoader.h"
25 #include "AliLoader.h"
26
27 /////////////////////////////////////////////////////////////////////////////////
28 //
29 // AliMUONDigitizerv2 digitizes digits from s-digits. 
30 // Merging is allowed from multiple input streams. The first input stream is 
31 // assumed to be the signal and all other input streams as assumed to be 
32 // background.
33 // Chamber response is applied to the digits identically to AliMUONDigitizerv1.
34 //
35 /////////////////////////////////////////////////////////////////////////////////
36
37 ClassImp(AliMUONDigitizerv2)
38
39 //___________________________________________
40 AliMUONDigitizerv2::AliMUONDigitizerv2() : AliMUONDigitizerv1()
41 {
42         // Default ctor - don't use it
43 }
44
45 //___________________________________________
46 AliMUONDigitizerv2::AliMUONDigitizerv2(AliRunDigitizer* manager) : AliMUONDigitizerv1(manager)
47 {
48         // ctor which should be used
49 }
50
51 //-----------------------------------------------------------------------
52 void AliMUONDigitizerv2::GenerateTransientDigits()
53 {
54 // Loop over all chambers and s-digits in the input stream and create 
55 // AliMUONTransientDigit objects from them. These are then added to fTDList.
56
57         if (GetDebug() > 1) 
58                 Info("GenerateTransientDigits", "Generating transient digits using treeH = 0x%X");
59
60         //
61         // Loop over SDigits
62         Int_t ndig, k;
63         AliMUONDigit* sDigit;
64         TClonesArray* muonSDigits;
65         for (Int_t ich = 0; ich < AliMUONConstants::NCh(); ich++)  // loop over chamber
66         {
67                 muondata->ResetSDigits();
68                 muondata->GetCathodeS(0);
69                 muonSDigits = muondata->SDigits(ich); 
70                 ndig = muonSDigits->GetEntriesFast();
71                 for (k = 0; k < ndig; k++)
72                 {
73                         sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k);
74                         MakeTransientDigitFromSDigit(ich,sDigit);
75                 }
76                 muondata->ResetSDigits();
77                 muondata->GetCathodeS(1);
78                 muonSDigits = muondata->SDigits(ich); 
79                 ndig=muonSDigits->GetEntriesFast();
80                 for (k = 0; k < ndig; k++)
81                 {
82                         sDigit = (AliMUONDigit*) muonSDigits->UncheckedAt(k);
83                         MakeTransientDigitFromSDigit(ich,sDigit);
84                 };
85         } // SDigits loop, end loop over chamber
86 };
87
88 //------------------------------------------------------------------------
89 void AliMUONDigitizerv2::MakeTransientDigitFromSDigit(Int_t iChamber, AliMUONDigit* sDigit)
90 {
91 // Makes a transient digit from the specified s-digit from the specified chamber. 
92 // Once the digit is created it is added to the fTDList.
93
94         if (GetDebug() > 3)
95                 Info("MakeTransientDigitFromSDigit", 
96                         "Making transient digit from s-digit for chamber %d.", iChamber);
97         
98         Int_t digits[6];
99         //
100         // Creating a new TransientDigits from SDigit
101         digits[0] = sDigit->PadX();  // Padx of the Digit
102         digits[1] = sDigit->PadY();  // Pady of the Digit
103         digits[2] = sDigit->Cathode()+1;  // Cathode plane
104         digits[3] = sDigit->Signal();  // Induced charge in the Pad
105         if (fSignal)
106                 digits[4] = sDigit->Signal();
107         else
108                 digits[4] = 0;
109                 
110         digits[5] = sDigit->Hit();    // Hit number in the list
111
112         if (GetDebug() > 4)
113                 Info("MakeTransientDigitFromSDigit", 
114                         "Made digit from sDigit 0x%X: PadX %d\tPadY %d\tPlane %d\tCharge %d\tHit %d",
115                         (void*)sDigit, digits[0], digits[1], digits[2], digits[3], digits[5]);
116         
117         AliMUONTransientDigit* mTD = new AliMUONTransientDigit(iChamber, digits);
118         // Copy list of tracks and trackcharge
119         for(Int_t itrack = 0; itrack < kMAXTRACKS; itrack++)
120         {
121                 Int_t track = sDigit->Track(itrack);
122                 if (track < 0) break;  // Check if we reached the end of the track list.
123                 mTD->AddToTrackList( track + fMask, sDigit->TrackCharge(itrack) );
124         };
125
126         OnCreateTransientDigit(mTD, sDigit);
127         AddOrUpdateTransientDigit(mTD);
128 };
129
130 //------------------------------------------------------------------------
131 void AliMUONDigitizerv2::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[6])
132 {
133 // Override to add new digits to the digits tree TreeD.
134         muondata->AddDigit(chamber, tracks, charges, digits);   
135 };
136
137 //------------------------------------------------------------------------
138 Bool_t AliMUONDigitizerv2::InitInputData(AliMUONLoader* muonloader)
139 {
140 // Overridden to initialize muondata to read from the s-digits tree TreeS. 
141 // If the s-digits are not loaded then the muon loader is used to load the
142 // s-digits into memory.
143
144         if (GetDebug() > 2)
145                 Info("InitInputData", "Loading s-digits in READ mode and setting the tree address.");
146
147         muondata->SetLoader(muonloader);
148
149         if (muonloader->TreeS() == NULL)
150         {
151                 muonloader->LoadSDigits("READ");
152                 if (muonloader->TreeS() == NULL)
153                 {
154                         Error("InitInputData", "Can not load the s-digits tree.");
155                         return kFALSE;
156                 };
157         };
158
159         muondata->SetTreeAddress("S");
160         return kTRUE;
161 };
162
163 //------------------------------------------------------------------------
164 void AliMUONDigitizerv2::CleanupInputData(AliMUONLoader* muonloader)
165 {
166 // Overridden to release and unload s-digits from memory.
167
168         if (GetDebug() > 2) Info("CleanupInputData", "Releasing loaded s-digits.");
169         muondata->ResetSDigits();
170         muonloader->UnloadSDigits();
171 };