]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - MUON/AliMUONResponseV0.cxx
bug fixed
[u/mrichter/AliRoot.git] / MUON / AliMUONResponseV0.cxx
... / ...
CommitLineData
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
16/* $Id$ */
17
18//-----------------------------------------------------------------------------
19// Class AliMUONResponseV0
20// --------------------------
21// Implementation of
22// Mathieson response
23//-----------------------------------------------------------------------------
24
25#include "AliMUONResponseV0.h"
26#include "AliMUON.h"
27#include "AliMUONConstants.h"
28#include "AliMUONDigit.h"
29#include "AliMUONGeometryTransformer.h"
30#include "AliMUONHit.h"
31#include "AliMUONConstants.h"
32
33#include "AliMpArea.h"
34#include "AliMpDEManager.h"
35#include "AliMpVPadIterator.h"
36#include "AliMpSegmentation.h"
37#include "AliMpVSegmentation.h"
38#include "AliMpCathodType.h"
39
40#include "AliRun.h"
41#include "AliLog.h"
42
43#include "Riostream.h"
44#include "TVector2.h"
45#include <TMath.h>
46#include <TRandom.h>
47
48/// \cond CLASSIMP
49ClassImp(AliMUONResponseV0)
50/// \endcond
51
52AliMUON* muon()
53{
54 return static_cast<AliMUON*>(gAlice->GetModule("MUON"));
55}
56
57void Global2Local(Int_t detElemId, Double_t xg, Double_t yg, Double_t zg,
58 Double_t& xl, Double_t& yl, Double_t& zl)
59{
60 /// ideally should be :
61 /// Double_t x,y,z;
62 /// AliMUONGeometry::Global2Local(detElemId,xg,yg,zg,x,y,z);
63 /// but while waiting for this geometry singleton, let's go through
64 /// AliMUON still.
65
66 const AliMUONGeometryTransformer* transformer = muon()->GetGeometryTransformer();
67 transformer->Global2Local(detElemId,xg,yg,zg,xl,yl,zl);
68}
69
70//__________________________________________________________________________
71AliMUONResponseV0::AliMUONResponseV0()
72 : AliMUONResponse(),
73 fChargeSlope(0.0),
74 fChargeSpreadX(0.0),
75 fChargeSpreadY(0.0),
76 fSigmaIntegration(0.0),
77 fMaxAdc(0),
78 fSaturation(0),
79 fZeroSuppression(0),
80 fChargeCorrel(0.0),
81 fMathieson(new AliMUONMathieson),
82 fChargeThreshold(1e-4),
83 fIsTailEffect(kFALSE)
84{
85 /// Normal constructor
86 AliDebug(1,Form("Default ctor"));
87}
88
89//__________________________________________________________________________
90AliMUONResponseV0::AliMUONResponseV0(const AliMUONResponseV0& other)
91: AliMUONResponse(),
92fChargeSlope(0.0),
93fChargeSpreadX(0.0),
94fChargeSpreadY(0.0),
95fSigmaIntegration(0.0),
96fMaxAdc(0),
97fSaturation(0),
98fZeroSuppression(0),
99fChargeCorrel(0.0),
100fMathieson(0),
101fChargeThreshold(1e-4),
102fIsTailEffect(kFALSE)
103{
104 /// copy ctor
105 other.CopyTo(*this);
106}
107
108//__________________________________________________________________________
109AliMUONResponseV0&
110AliMUONResponseV0::operator=(const AliMUONResponseV0& other)
111{
112 /// Assignment operator
113 other.CopyTo(*this);
114 return *this;
115}
116
117//__________________________________________________________________________
118AliMUONResponseV0::~AliMUONResponseV0()
119{
120/// Destructor
121
122 AliDebug(1,"");
123 delete fMathieson;
124}
125
126//______________________________________________________________________________
127void
128AliMUONResponseV0::CopyTo(AliMUONResponseV0& other) const
129{
130 /// Copy *this to other
131 other.fChargeSlope=fChargeSlope;
132 other.fChargeSpreadX=fChargeSpreadX;
133 other.fChargeSpreadY=fChargeSpreadY;
134 other.fSigmaIntegration=fSigmaIntegration;
135 other.fMaxAdc=fMaxAdc;
136 other.fSaturation=fSaturation;
137 other.fZeroSuppression=fZeroSuppression;
138 other.fChargeCorrel=fChargeCorrel;
139 delete other.fMathieson;
140 other.fMathieson = new AliMUONMathieson(*fMathieson);
141 other.fChargeThreshold=fChargeThreshold;
142}
143
144//______________________________________________________________________________
145void
146AliMUONResponseV0::Print(Option_t*) const
147{
148/// Printing
149
150 cout << " ChargeSlope=" << fChargeSlope
151 << " ChargeSpreadX,Y=" << fChargeSpreadX
152 << fChargeSpreadY
153 << " ChargeCorrelation=" << fChargeCorrel
154 << endl;
155}
156
157 //__________________________________________________________________________
158void AliMUONResponseV0::SetSqrtKx3AndDeriveKx2Kx4(Float_t SqrtKx3)
159{
160 /// Set to "SqrtKx3" the Mathieson parameter K3 ("fSqrtKx3")
161 /// in the X direction, perpendicular to the wires,
162 /// and derive the Mathieson parameters K2 ("fKx2") and K4 ("fKx4")
163 /// in the same direction
164 fMathieson->SetSqrtKx3AndDeriveKx2Kx4(SqrtKx3);
165}
166
167 //__________________________________________________________________________
168void AliMUONResponseV0::SetSqrtKy3AndDeriveKy2Ky4(Float_t SqrtKy3)
169{
170 /// Set to "SqrtKy3" the Mathieson parameter K3 ("fSqrtKy3")
171 /// in the Y direction, along the wires,
172 /// and derive the Mathieson parameters K2 ("fKy2") and K4 ("fKy4")
173 /// in the same direction
174 fMathieson->SetSqrtKy3AndDeriveKy2Ky4(SqrtKy3);
175}
176 //__________________________________________________________________________
177Float_t AliMUONResponseV0::IntPH(Float_t eloss) const
178{
179 /// Calculate charge from given ionization energy loss
180 Int_t nel;
181 nel= Int_t(eloss*1.e9/27.4);
182 Float_t charge=0;
183 if (nel == 0) nel=1;
184 for (Int_t i=1;i<=nel;i++) {
185 Float_t arg=0.;
186 while(!arg) arg = gRandom->Rndm();
187 charge -= fChargeSlope*TMath::Log(arg);
188 }
189 return charge;
190}
191
192//_____________________________________________________________________________
193Float_t
194AliMUONResponseV0::GetAnod(Float_t x) const
195{
196 /// Return wire coordinate closest to x.
197
198 Int_t n = Int_t(x/Pitch());
199 Float_t wire = (x>0) ? n+0.5 : n-0.5;
200 return Pitch()*wire;
201}
202
203//______________________________________________________________________________
204void
205AliMUONResponseV0::DisIntegrate(const AliMUONHit& hit, TList& digits, Float_t timeDif)
206{
207 /// Go from 1 hit to a list of digits.
208 /// The energy deposition of that hit is first converted into charge
209 /// (in IntPH() method), and then this charge is dispatched on several
210 /// pads, according to the Mathieson distribution.
211
212 digits.Clear();
213
214 Int_t detElemId = hit.DetElemId();
215 Double_t hitX = hit.X() ;
216 Double_t hitY = hit.Y() ;
217 Double_t hitZ = hit.Z() ;
218
219 // Width of the integration area
220 Double_t dx = SigmaIntegration()*ChargeSpreadX();
221 Double_t dy = SigmaIntegration()*ChargeSpreadY();
222
223 //Modify to take the tailing effect.
224 if(fIsTailEffect){
225 Double_t locX,locY,locZ,globXCenter,globYCenter,globZ;
226 Int_t para = 5; // This parameter is a natural number(excluding zero), higher the value less is the tailing effect
227 Double_t termA = 1.0;
228 Double_t termB = 1.0;
229 if(para>0){
230 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
231 {
232 // Get an iterator to loop over pads, within the given area.
233 const AliMpVSegmentation* seg =
234 AliMpSegmentation::Instance()
235 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
236 AliMp::PlaneType plane = seg->PlaneType();
237
238 if(plane == AliMp::kBendingPlane) {
239 Global2Local(detElemId,hitX,hitY,hitZ,locX,locY,locZ);
240 AliMpPad pad = seg->PadByPosition(locX,locY,kFALSE);
241 if(pad.IsValid()){
242 Double_t locYCenter = pad.GetPositionY();
243 Double_t locXCenter = pad.GetPositionX();
244 const AliMUONGeometryTransformer* transformer = muon()->GetGeometryTransformer();
245 transformer->Local2Global(detElemId,locXCenter,locYCenter,locZ,globXCenter,globYCenter,globZ);
246 for(Int_t itime = 0; itime<para; itime++)
247 termA *= 10.0;
248
249 for(Int_t itime = 0; itime<Int_t((2*para) + 1); itime++)
250 termB *= (hitY - globYCenter) ;
251
252 hitY = hitY + termA*termB;
253 }// if the pad is a valid one
254 }// if bending plane
255 }// cathode loop
256 }// if para > 0 condn
257 }// if tail effect
258
259 // Use that (dx,dy) to specify the area upon which
260 // we will iterate to spread charge into.
261 Double_t x,y,z;
262 Global2Local(detElemId,hitX,hitY,hitZ,x,y,z);
263 x = GetAnod(x);
264 AliMpArea area(x,y,dx,dy);
265
266 // Get pulse height from energy loss.
267 Float_t qtot = IntPH(hit.Eloss());
268
269 // If from a pileup event we apply a reduction factor to the charge
270 if (timeDif!=0){
271 qtot = AliMUONConstants::ReducedQTot(qtot,timeDif);
272 }
273
274 // Get the charge correlation between cathodes.
275 Float_t currentCorrel = TMath::Exp(gRandom->Gaus(0.0,ChargeCorrel()/2.0));
276
277 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
278 {
279 Float_t qcath = qtot * ( cath == 0 ? currentCorrel : 1.0/currentCorrel);
280
281 // Get an iterator to loop over pads, within the given area.
282 const AliMpVSegmentation* seg =
283 AliMpSegmentation::Instance()
284 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
285
286 AliMpVPadIterator* it = seg->CreateIterator(area);
287
288 if (!it)
289 {
290 AliError(Form("Could not get iterator for detElemId %d",detElemId));
291 return;
292 }
293
294 // Start loop over pads.
295 it->First();
296
297 if ( it->IsDone() )
298 {
299 // Exceptional case : iterator is built, but is invalid from the start.
300 AliMpPad pad = seg->PadByPosition(area.GetPositionX(),area.GetPositionY(),
301 kFALSE);
302 if ( pad.IsValid() )
303 {
304 AliWarning(Form("Got an invalid iterator bug (area.Position() is within "
305 " DE but the iterator is void) for detElemId %d cath %d",
306 detElemId,cath));
307 }
308 else
309 {
310 AliError(Form("Got an invalid iterator bug for detElemId %d cath %d."
311 "Might be a bad hit ? area.Position()=(%e,%e) "
312 "Dimensions()=(%e,%e)",
313 detElemId,cath,area.GetPositionX(),area.GetPositionY(),
314 area.GetDimensionX(),area.GetDimensionY()));
315 }
316 delete it;
317 return;
318 }
319
320 while ( !it->IsDone() )
321 {
322 // For each pad given by the iterator, compute the charge of that
323 // pad, according to the Mathieson distribution.
324 AliMpPad pad = it->CurrentItem();
325 TVector2 lowerLeft(TVector2(x,y)-TVector2(pad.GetPositionX(),pad.GetPositionY())-
326 TVector2(pad.GetDimensionX(),pad.GetDimensionY()));
327 TVector2 upperRight(lowerLeft + TVector2(pad.GetDimensionX(),pad.GetDimensionY())*2.0);
328 Float_t qp = TMath::Abs(fMathieson->IntXY(lowerLeft.X(),lowerLeft.Y(),
329 upperRight.X(),upperRight.Y()));
330
331 Int_t icharge = Int_t(qp*qcath);
332
333 if ( qp > fChargeThreshold )
334 {
335 // If we're above threshold, then we create a digit,
336 // and fill it with relevant information, including electronics.
337 AliMUONDigit* d = new AliMUONDigit(detElemId,pad.GetManuId(),
338 pad.GetManuChannel(),cath);
339 d->SetPadXY(pad.GetIx(),pad.GetIy());
340 d->SetCharge(icharge);
341 digits.Add(d);
342 }
343 it->Next();
344 }
345 delete it;
346 }
347}
348
349
350