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