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