AliMpSegFactory replaced with AliMpSegmentation
[u/mrichter/AliRoot.git] / MUON / AliMUONResponseV0.cxx
CommitLineData
a9e2aefa 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
88cb7938 16/* $Id$ */
a9e2aefa 17
d19b6003 18// --------------------------
19// Class AliMUONResponseV0
20// --------------------------
21// Implementation of Mathieson response
22// ...
a9e2aefa 23
30178c30 24#include "AliMUONResponseV0.h"
885d501b 25
f29ba3e1 26#include "AliLog.h"
885d501b 27#include "AliMUON.h"
28#include "AliMUONConstants.h"
29#include "AliMUONDigit.h"
30#include "AliMUONGeometrySegmentation.h"
31#include "AliMUONGeometryTransformer.h"
32#include "AliMUONHit.h"
33#include "AliMUONSegmentation.h"
34#include "AliMpArea.h"
35#include "AliMpDEManager.h"
885d501b 36#include "AliMpVPadIterator.h"
37#include "AliMpVSegmentation.h"
38#include "AliRun.h"
39#include "Riostream.h"
40#include "TVector2.h"
41#include <TMath.h>
42#include <TRandom.h>
8c343c7c 43
d5bfadcc 44ClassImp(AliMUONResponseV0)
45
885d501b 46AliMUON* muon()
47{
48 return static_cast<AliMUON*>(gAlice->GetModule("MUON"));
49}
50
51void Global2Local(Int_t detElemId, Double_t xg, Double_t yg, Double_t zg,
52 Double_t& xl, Double_t& yl, Double_t& zl)
53{
54 // ideally should be :
55 // Double_t x,y,z;
56 // AliMUONGeometry::Global2Local(detElemId,xg,yg,zg,x,y,z);
57 // but while waiting for this geometry singleton, let's go through
58 // AliMUON still.
59
60 const AliMUONGeometryTransformer* transformer = muon()->GetGeometryTransformer();
61 transformer->Global2Local(detElemId,xg,yg,zg,xl,yl,zl);
62}
63
64AliMUONSegmentation* Segmentation()
65{
66 static AliMUONSegmentation* segmentation = muon()->GetSegmentation();
67 return segmentation;
68}
69
30178c30 70//__________________________________________________________________________
71AliMUONResponseV0::AliMUONResponseV0()
885d501b 72 : AliMUONResponse(),
73 fChargeSlope(0.0),
74 fChargeSpreadX(0.0),
75 fChargeSpreadY(0.0),
76 fSigmaIntegration(0.0),
77 fMaxAdc(0),
ccea41d4 78 fSaturation(0),
885d501b 79 fZeroSuppression(0),
80 fChargeCorrel(0.0),
81 fMathieson(new AliMUONMathieson),
82 fChargeThreshold(1e-4)
30178c30 83{
885d501b 84 // Normal constructor
85 AliDebug(1,Form("Default ctor"));
30178c30 86}
f29ba3e1 87
ccea41d4 88//__________________________________________________________________________
a713db22 89AliMUONResponseV0::~AliMUONResponseV0()
90{
885d501b 91 AliDebug(1,"");
a713db22 92 delete fMathieson;
93}
f29ba3e1 94
885d501b 95//______________________________________________________________________________
96void
97AliMUONResponseV0::Print(Option_t*) const
98{
d19b6003 99// Printing
100
885d501b 101 cout << " ChargeSlope=" << fChargeSlope
102 << " ChargeSpreadX,Y=" << fChargeSpreadX
103 << fChargeSpreadY
104 << " ChargeCorrelation=" << fChargeCorrel
105 << endl;
885d501b 106}
107
d5bfadcc 108 //__________________________________________________________________________
109void AliMUONResponseV0::SetSqrtKx3AndDeriveKx2Kx4(Float_t SqrtKx3)
110{
111 // Set to "SqrtKx3" the Mathieson parameter K3 ("fSqrtKx3")
112 // in the X direction, perpendicular to the wires,
113 // and derive the Mathieson parameters K2 ("fKx2") and K4 ("fKx4")
114 // in the same direction
a713db22 115 fMathieson->SetSqrtKx3AndDeriveKx2Kx4(SqrtKx3);
d5bfadcc 116}
117
118 //__________________________________________________________________________
119void AliMUONResponseV0::SetSqrtKy3AndDeriveKy2Ky4(Float_t SqrtKy3)
120{
121 // Set to "SqrtKy3" the Mathieson parameter K3 ("fSqrtKy3")
122 // in the Y direction, along the wires,
123 // and derive the Mathieson parameters K2 ("fKy2") and K4 ("fKy4")
124 // in the same direction
a713db22 125 fMathieson->SetSqrtKy3AndDeriveKy2Ky4(SqrtKy3);
d5bfadcc 126}
a713db22 127 //__________________________________________________________________________
85fec35d 128Float_t AliMUONResponseV0::IntPH(Float_t eloss) const
a9e2aefa 129{
130 // Calculate charge from given ionization energy loss
131 Int_t nel;
4ac9d21e 132 nel= Int_t(eloss*1.e9/27.4);
a9e2aefa 133 Float_t charge=0;
134 if (nel == 0) nel=1;
135 for (Int_t i=1;i<=nel;i++) {
01997fa2 136 Float_t arg=0.;
137 while(!arg) arg = gRandom->Rndm();
138 charge -= fChargeSlope*TMath::Log(arg);
a9e2aefa 139 }
140 return charge;
141}
a713db22 142
a713db22 143 //-------------------------------------------
85fec35d 144Float_t AliMUONResponseV0::IntXY(Int_t idDE,
145 AliMUONGeometrySegmentation* segmentation)
146const
a713db22 147{
148 // Calculate charge on current pad according to Mathieson distribution
a9e2aefa 149
a713db22 150 return fMathieson->IntXY(idDE, segmentation);
151}
885d501b 152
153
885d501b 154//_____________________________________________________________________________
155Float_t
156AliMUONResponseV0::GetAnod(Float_t x) const
157{
158 //
159 // Return wire coordinate closest to x.
160 //
161 Int_t n = Int_t(x/Pitch());
162 Float_t wire = (x>0) ? n+0.5 : n-0.5;
163 return Pitch()*wire;
164}
a9e2aefa 165
885d501b 166//______________________________________________________________________________
167void
168AliMUONResponseV0::DisIntegrate(const AliMUONHit& hit, TList& digits)
169{
170 //
32c9ead9 171 // Go from 1 hit to a list of digits.
172 // The energy deposition of that hit is first converted into charge
173 // (in IntPH() method), and then this charge is dispatched on several
174 // pads, according to the Mathieson distribution.
885d501b 175 //
176
177 digits.Clear();
178
179 Int_t detElemId = hit.DetElemId();
180
885d501b 181 // Width of the integration area
885d501b 182 Double_t dx = SigmaIntegration()*ChargeSpreadX();
183 Double_t dy = SigmaIntegration()*ChargeSpreadY();
184
185 // Use that (dx,dy) to specify the area upon which
186 // we will iterate to spread charge into.
187 Double_t x,y,z;
188 Global2Local(detElemId,hit.X(),hit.Y(),hit.Z(),x,y,z);
189 x = GetAnod(x);
190 TVector2 hitPosition(x,y);
191 AliMpArea area(hitPosition,TVector2(dx,dy));
192
32c9ead9 193 // Get pulse height from energy loss.
885d501b 194 Float_t qtot = IntPH(hit.Eloss());
195
32c9ead9 196 // Get the charge correlation between cathodes.
885d501b 197 Float_t currentCorrel = TMath::Exp(gRandom->Gaus(0.0,ChargeCorrel()/2.0));
a9e2aefa 198
885d501b 199 for ( Int_t cath = 0; cath < 2; ++cath )
200 {
201 Float_t qcath = qtot * ( cath == 0 ? currentCorrel : 1.0/currentCorrel);
202
885d501b 203 // Get an iterator to loop over pads, within the given area.
32c9ead9 204 const AliMpVSegmentation* seg =
885d501b 205 Segmentation()->GetMpSegmentation(detElemId,cath);
885d501b 206
32c9ead9 207 AliMpVPadIterator* it = seg->CreateIterator(area);
208
209 if (!it)
210 {
211 AliError(Form("Could not get iterator for detElemId %d",detElemId));
212 return;
213 }
214
215 // Start loop over pads.
216 it->First();
217
218 if ( it->IsDone() )
219 {
220 // Exceptional case : iterator is built, but is invalid from the start.
221 AliMpPad pad = seg->PadByPosition(area.Position(),kFALSE);
222 if ( pad.IsValid() )
885d501b 223 {
32c9ead9 224 AliWarning(Form("Got an invalid iterator bug (area.Position() is within "
225 " DE but the iterator is void) for detElemId %d cath %d",
226 detElemId,cath));
885d501b 227 }
32c9ead9 228 else
885d501b 229 {
32c9ead9 230 AliError(Form("Got an invalid iterator bug for detElemId %d cath %d."
231 "Might be a bad hit ? area.Position()=(%e,%e) "
232 "Dimensions()=(%e,%e)",
233 detElemId,cath,area.Position().X(),area.Position().Y(),
234 area.Dimensions().X(),area.Dimensions().Y()));
885d501b 235 }
236 delete it;
32c9ead9 237 return;
238 }
239
240 while ( !it->IsDone() )
241 {
242 // For each pad given by the iterator, compute the charge of that
243 // pad, according to the Mathieson distribution.
244 AliMpPad pad = it->CurrentItem();
245 TVector2 lowerLeft(hitPosition-pad.Position()-pad.Dimensions());
246 TVector2 upperRight(lowerLeft + pad.Dimensions()*2.0);
247 Float_t qp = TMath::Abs(fMathieson->IntXY(lowerLeft.X(),lowerLeft.Y(),
248 upperRight.X(),upperRight.Y()));
249
250 Int_t icharge = Int_t(qp*qcath);
251
252 if ( qp > fChargeThreshold )
253 {
254 // If we're above threshold, then we create a digit,
255 // and fill it with relevant information, including electronics.
256 AliMUONDigit* d = new AliMUONDigit;
257 d->SetDetElemId(detElemId);
258 d->SetPadX(pad.GetIndices().GetFirst());
259 d->SetPadY(pad.GetIndices().GetSecond());
260 d->SetSignal(icharge);
261 d->AddPhysicsSignal(d->Signal());
262 d->SetCathode(cath);
263 d->SetElectronics(pad.GetLocation().GetFirst(),
264 pad.GetLocation().GetSecond());
265 digits.Add(d);
266 }
267 it->Next();
268 }
269 delete it;
885d501b 270 }
271}
a9e2aefa 272
273
274