Global constants moved to the class scope. (I. Hrivnacova)
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerv2.cxx
CommitLineData
d1775029 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
cf286af7 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
d1775029 37ClassImp(AliMUONDigitizerv2)
38
39//___________________________________________
cf286af7 40AliMUONDigitizerv2::AliMUONDigitizerv2() : AliMUONDigitizerv1()
d1775029 41{
cf286af7 42 // Default ctor - don't use it
d1775029 43}
44
45//___________________________________________
cf286af7 46AliMUONDigitizerv2::AliMUONDigitizerv2(AliRunDigitizer* manager) : AliMUONDigitizerv1(manager)
d1775029 47{
cf286af7 48 // ctor which should be used
d1775029 49}
50
cf286af7 51//-----------------------------------------------------------------------
52void AliMUONDigitizerv2::GenerateTransientDigits()
d1775029 53{
cf286af7 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.
d1775029 56
cf286af7 57 if (GetDebug() > 1)
58 Info("GenerateTransientDigits", "Generating transient digits using treeH = 0x%X");
d1775029 59
cf286af7 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};
d1775029 87
88//------------------------------------------------------------------------
cf286af7 89void AliMUONDigitizerv2::MakeTransientDigitFromSDigit(Int_t iChamber, AliMUONDigit* sDigit)
d1775029 90{
cf286af7 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.
d1775029 93
cf286af7 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};
d1775029 129
130//------------------------------------------------------------------------
cf286af7 131void AliMUONDigitizerv2::AddDigit(Int_t chamber, Int_t tracks[kMAXTRACKS], Int_t charges[kMAXTRACKS], Int_t digits[6])
d1775029 132{
cf286af7 133// Override to add new digits to the digits tree TreeD.
134 muondata->AddDigit(chamber, tracks, charges, digits);
135};
d1775029 136
cf286af7 137//------------------------------------------------------------------------
138Bool_t AliMUONDigitizerv2::InitInputData(AliMUONLoader* muonloader)
d1775029 139{
cf286af7 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.
d1775029 143
cf286af7 144 if (GetDebug() > 2)
145 Info("InitInputData", "Loading s-digits in READ mode and setting the tree address.");
d1775029 146
cf286af7 147 muondata->SetLoader(muonloader);
d1775029 148
cf286af7 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 };
be42eafc 158
be42eafc 159 muondata->SetTreeAddress("S");
cf286af7 160 return kTRUE;
161};
162
d1775029 163//------------------------------------------------------------------------
cf286af7 164void AliMUONDigitizerv2::CleanupInputData(AliMUONLoader* muonloader)
d1775029 165{
cf286af7 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};