]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONResponseV0.cxx
Possibility to vary the cos(PA) cut
[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 #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
49 ClassImp(AliMUONResponseV0)
50 /// \endcond
51         
52 AliMUON* muon()
53 {
54     return static_cast<AliMUON*>(gAlice->GetModule("MUON"));
55 }
56
57 void 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 //__________________________________________________________________________
71 AliMUONResponseV0::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 //__________________________________________________________________________
90 AliMUONResponseV0::AliMUONResponseV0(const AliMUONResponseV0& other)
91 : AliMUONResponse(),
92 fChargeSlope(0.0),
93 fChargeSpreadX(0.0),
94 fChargeSpreadY(0.0),
95 fSigmaIntegration(0.0),
96 fMaxAdc(0),
97 fSaturation(0),
98 fZeroSuppression(0),
99 fChargeCorrel(0.0),
100 fMathieson(0),
101 fChargeThreshold(1e-4),
102 fIsTailEffect(kFALSE)
103 {
104   /// copy ctor
105   other.CopyTo(*this);
106 }
107
108 //__________________________________________________________________________
109 AliMUONResponseV0& 
110 AliMUONResponseV0::operator=(const AliMUONResponseV0& other)
111 {
112   /// Assignment operator
113   other.CopyTo(*this);
114   return *this;
115 }
116
117 //__________________________________________________________________________
118 AliMUONResponseV0::~AliMUONResponseV0()
119 {
120 /// Destructor
121
122   AliDebug(1,"");
123   delete fMathieson;
124 }
125
126 //______________________________________________________________________________
127 void
128 AliMUONResponseV0::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 //______________________________________________________________________________
145 void
146 AliMUONResponseV0::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   //__________________________________________________________________________
158 void 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   //__________________________________________________________________________
168 void 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   //__________________________________________________________________________
177 Float_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 //_____________________________________________________________________________
193 Float_t
194 AliMUONResponseV0::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 //______________________________________________________________________________
204 void 
205 AliMUONResponseV0::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   // Scale the charge to it'll (roughly) be in fC
275   qtot *= AliMUONConstants::DefaultADC2MV()*AliMUONConstants::DefaultA0()*AliMUONConstants::DefaultCapa();
276   
277   // Get the charge correlation between cathodes.
278   Float_t currentCorrel = TMath::Exp(gRandom->Gaus(0.0,ChargeCorrel()/2.0));
279
280   for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
281   {
282     Float_t qcath = qtot * ( cath == 0 ? currentCorrel : 1.0/currentCorrel);
283     
284     // Get an iterator to loop over pads, within the given area.
285     const AliMpVSegmentation* seg = 
286         AliMpSegmentation::Instance()
287           ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
288       
289     AliMpVPadIterator* it = seg->CreateIterator(area);
290       
291     if (!it)
292     {
293       AliError(Form("Could not get iterator for detElemId %d",detElemId));
294       return;
295     }
296     
297     // Start loop over pads.
298     it->First();
299     
300     if ( it->IsDone() )
301     {
302       // Exceptional case : iterator is built, but is invalid from the start.
303       AliMpPad pad = seg->PadByPosition(area.GetPositionX(),area.GetPositionY(),
304                                         kFALSE);
305       if ( pad.IsValid() )
306       {
307         AliDebug(1, Form("Got an invalid iterator bug (area.Position() is within "
308                       " DE but the iterator is void) for detElemId %d cath %d",
309                       detElemId,cath));        
310       }
311       else
312       {
313         AliDebug(1, Form("Got an invalid iterator bug for detElemId %d cath %d."
314                       "Might be a bad hit ? area.Position()=(%e,%e) "
315                       "Dimensions()=(%e,%e)",
316                       detElemId,cath,area.GetPositionX(),area.GetPositionY(),
317                       area.GetDimensionX(),area.GetDimensionY()));
318       }
319       delete it;
320       return;
321     }
322     
323     while ( !it->IsDone() )
324     {
325       // For each pad given by the iterator, compute the charge of that
326       // pad, according to the Mathieson distribution.
327       AliMpPad pad = it->CurrentItem();      
328       TVector2 lowerLeft(TVector2(x,y)-TVector2(pad.GetPositionX(),pad.GetPositionY())-
329                          TVector2(pad.GetDimensionX(),pad.GetDimensionY()));
330       TVector2 upperRight(lowerLeft + TVector2(pad.GetDimensionX(),pad.GetDimensionY())*2.0);
331       Float_t qp = TMath::Abs(fMathieson->IntXY(lowerLeft.X(),lowerLeft.Y(),
332                                                 upperRight.X(),upperRight.Y()));
333             
334       if ( qp > fChargeThreshold && 
335            qp*qcath > AliMUONConstants::DefaultADC2MV()*AliMUONConstants::DefaultA0()*AliMUONConstants::DefaultCapa() )
336       {
337         // If we're above threshold, then we create a digit,
338         // and fill it with relevant information, including electronics.
339         
340         // note that the second condition above is to be backward compatible (when 
341         // the sdigitizer was making a cut on Int_t(qp*qcath) > 0 and qcath was in ADC, not in fC)
342         
343         AliMUONDigit* d = new AliMUONDigit(detElemId,pad.GetManuId(),
344                                            pad.GetManuChannel(),cath);
345         d->SetPadXY(pad.GetIx(),pad.GetIy());
346         d->SetCharge(qp*qcath);
347         digits.Add(d);   
348       }       
349       it->Next();
350     }
351     delete it;
352   }
353 }
354
355
356