]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONResponseV0.cxx
Registration of screenshots into amore.
[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             AliMpPad pad = seg->PadByPosition(locX,locY,kFALSE);
240             if(pad.IsValid()){
241               Double_t locYCenter = pad.GetPositionY();
242               Double_t locXCenter = pad.GetPositionX();
243               const AliMUONGeometryTransformer* transformer = muon()->GetGeometryTransformer();
244               transformer->Local2Global(detElemId,locXCenter,locYCenter,locZ,globXCenter,globYCenter,globZ);
245               for(Int_t itime = 0; itime<para; itime++)
246                 termA *= 10.0;
247             
248               for(Int_t itime = 0; itime<Int_t((2*para) + 1); itime++)
249                 termB *= (hitY - globYCenter) ; 
250             
251               hitY = hitY + termA*termB;
252             }// if the pad is a valid one
253           }// if bending plane
254         }// cathode loop
255     }// if para > 0 condn
256   }// if tail effect
257
258   // Use that (dx,dy) to specify the area upon which
259   // we will iterate to spread charge into.
260   Double_t x,y,z;
261   Global2Local(detElemId,hitX,hitY,hitZ,x,y,z);
262   x = GetAnod(x);
263   AliMpArea area(x,y,dx,dy);
264   
265   // Get pulse height from energy loss.
266   Float_t qtot = IntPH(hit.Eloss());
267   
268   // Get the charge correlation between cathodes.
269   Float_t currentCorrel = TMath::Exp(gRandom->Gaus(0.0,ChargeCorrel()/2.0));
270
271   for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
272   {
273     Float_t qcath = qtot * ( cath == 0 ? currentCorrel : 1.0/currentCorrel);
274     
275     // Get an iterator to loop over pads, within the given area.
276     const AliMpVSegmentation* seg = 
277         AliMpSegmentation::Instance()
278           ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
279       
280     AliMpVPadIterator* it = seg->CreateIterator(area);
281       
282     if (!it)
283     {
284       AliError(Form("Could not get iterator for detElemId %d",detElemId));
285       return;
286     }
287     
288     // Start loop over pads.
289     it->First();
290     
291     if ( it->IsDone() )
292     {
293       // Exceptional case : iterator is built, but is invalid from the start.
294       AliMpPad pad = seg->PadByPosition(area.GetPositionX(),area.GetPositionY(),
295                                         kFALSE);
296       if ( pad.IsValid() )
297       {
298         AliWarning(Form("Got an invalid iterator bug (area.Position() is within "
299                       " DE but the iterator is void) for detElemId %d cath %d",
300                       detElemId,cath));        
301       }
302       else
303       {
304         AliError(Form("Got an invalid iterator bug for detElemId %d cath %d."
305                       "Might be a bad hit ? area.Position()=(%e,%e) "
306                       "Dimensions()=(%e,%e)",
307                       detElemId,cath,area.GetPositionX(),area.GetPositionY(),
308                       area.GetDimensionX(),area.GetDimensionY()));
309       }
310       delete it;
311       return;
312     }
313     
314     while ( !it->IsDone() )
315     {
316       // For each pad given by the iterator, compute the charge of that
317       // pad, according to the Mathieson distribution.
318       AliMpPad pad = it->CurrentItem();      
319       TVector2 lowerLeft(TVector2(x,y)-TVector2(pad.GetPositionX(),pad.GetPositionY())-
320                          TVector2(pad.GetDimensionX(),pad.GetDimensionY()));
321       TVector2 upperRight(lowerLeft + TVector2(pad.GetDimensionX(),pad.GetDimensionY())*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.GetManuId(),
332                                            pad.GetManuChannel(),cath);
333         d->SetPadXY(pad.GetIx(),pad.GetIy());
334         d->SetCharge(icharge);
335         digits.Add(d);   
336       }       
337       it->Next();
338     }
339     delete it;
340   }
341 }
342
343
344