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