]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSt1Segmentation.cxx
New parametrization of the geometry and new geometry interface (Working week effort)
[u/mrichter/AliRoot.git] / MUON / AliMUONSt1Segmentation.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 // Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
19 //
20 // Class AliMUONSt1Segmentation
21 // ------------------------------
22 // Segmentation for MUON station 1 using the external 
23 // mapping package
24 // Included in AliRoot 2003/01/28
25
26 #include <TError.h>
27 #include <TF1.h>
28 #include <TObjArray.h>
29 #include <TVector2.h>
30
31 #include "AliMpPad.h"
32 #include "AliMpPlane.h"
33 #include "AliMpPlaneAreaPadIterator.h"
34 #include "AliMpPlaneSegmentation.h"
35
36 #include "AliMUONSt1Segmentation.h"
37 #include "AliRun.h"
38 #include "AliMUON.h"
39 #include "AliMUONChamber.h"
40
41 ClassImp(AliMUONSt1Segmentation)
42
43 const Float_t  AliMUONSt1Segmentation::fgkWireD = 0.20; 
44 const Float_t  AliMUONSt1Segmentation::fgkLengthUnit = 0.1; 
45
46 //______________________________________________________________________________
47 AliMUONSt1Segmentation::AliMUONSt1Segmentation(const AliMpPlaneType planeType) 
48 : AliSegmentation(),
49   fPlane(0),
50   fPlaneSegmentation(0),
51   fPlaneIterator(0),
52   fWireD(fgkWireD),
53   fChamber(0),
54   fId(0),
55   fRmin(0.),
56   fRmax(0.),
57   fZ(0.),
58   fIx(0),
59   fIy(0),
60   fX(0.),
61   fY(0.),
62   fSector(0),
63   fXhit(0.),
64   fYhit(0.),
65   fIxt(0),
66   fIyt(0),
67   fIwt(0),
68   fXt(0.),
69   fYt(0.),
70   fCorrA(0)
71 {
72 // Normal constructor
73   fPlane = AliMpPlane::Create(kStation1, planeType);
74   fPlaneSegmentation = new AliMpPlaneSegmentation(fPlane);
75
76   fCorrA = new TObjArray(3);
77   fCorrA->AddAt(0,0);
78   fCorrA->AddAt(0,1);
79   fCorrA->AddAt(0,2);
80 }
81
82 //______________________________________________________________________________
83 AliMUONSt1Segmentation::AliMUONSt1Segmentation() 
84 : AliSegmentation(),
85   fPlane(0),
86   fPlaneSegmentation(0),
87   fPlaneIterator(0),
88   fWireD(fgkWireD),
89   fChamber(0),
90   fId(0),
91   fRmin(0.),
92   fRmax(0.),
93   fZ(0.),
94   fIx(0),
95   fIy(0),
96   fX(0.),
97   fY(0.),
98   fSector(0),
99   fXhit(0.),
100   fYhit(0.),
101   fIxt(0),
102   fIyt(0),
103   fIwt(0),
104   fXt(0.),
105   fYt(0.),
106   fCorrA(0) {
107 // Default Constructor
108 }
109
110 //______________________________________________________________________________
111 AliMUONSt1Segmentation::AliMUONSt1Segmentation(const AliMUONSt1Segmentation& rhs) 
112   : AliSegmentation(rhs)
113 {
114 // Copy constructor
115   Fatal("Copy constructor", 
116         "Copy constructor is not implemented.");
117 }
118
119 //______________________________________________________________________________
120 AliMUONSt1Segmentation::~AliMUONSt1Segmentation() {
121 // Destructor
122
123   delete fPlane;
124   delete fPlaneSegmentation;  
125   delete fPlaneIterator;  
126
127
128 //
129 // operators
130 //
131
132 //______________________________________________________________________________
133 AliMUONSt1Segmentation& 
134 AliMUONSt1Segmentation::operator=(const AliMUONSt1Segmentation& rhs)
135 {
136 // Copy operator 
137
138   // check assignement to self
139   if (this == &rhs) return *this;
140
141   Fatal("operator=", 
142         "Assignment operator is not implemented.");
143     
144   return *this;  
145 }
146
147 //
148 // private methods
149 //
150
151 //______________________________________________________________________________
152 void AliMUONSt1Segmentation::UpdateCurrentPadValues(const AliMpPad& pad)
153 {
154 // Updates current pad values.
155 // ---
156
157   fIx = pad.GetIndices().GetFirst();
158   fIy = pad.GetIndices().GetSecond();
159   fX = pad.Position().X() * fgkLengthUnit;
160   fY = pad.Position().Y() * fgkLengthUnit;
161   fSector = fPlaneSegmentation->Zone(pad);
162 }  
163
164 //
165 // public methods
166 //
167
168 //______________________________________________________________________________
169 void AliMUONSt1Segmentation::SetPadSize(Float_t /*p1*/, Float_t /*p2*/)
170 {
171 // Set pad size Dx*Dy 
172 // ---
173
174   Fatal("SetPadSize", "Not uniform pad size.");
175 }
176
177 //______________________________________________________________________________
178 void AliMUONSt1Segmentation::SetDAnod(Float_t d)
179 {
180 // Set anod pitch
181 // ---
182
183   fWireD = d;
184 }
185
186 //______________________________________________________________________________
187 Float_t AliMUONSt1Segmentation::GetAnod(Float_t xhit) const
188 {
189 // Anod wire coordinate closest to xhit
190 // Returns for a hit position xhit the position of the nearest anode wire    
191 // From AliMUONSegmentationV01.
192 // ---
193
194   Float_t wire= (xhit>0) ? Int_t(xhit/fWireD) + 0.5
195                          : Int_t(xhit/fWireD) - 0.5;
196   return fWireD*wire;
197
198 }
199
200 //______________________________________________________________________________
201 void  AliMUONSt1Segmentation::GetPadI(Float_t x, Float_t y, Float_t /*z*/, 
202                                       Int_t& ix, Int_t& iy)
203 {                                       
204 //  Returns pad coordinates (ix,iy) for given real coordinates (x,y)
205 // ---
206
207   GetPadI(x, y, ix, iy);
208 }
209                        
210 //______________________________________________________________________________
211 void  AliMUONSt1Segmentation::GetPadI(Float_t x, Float_t y,
212                                       Int_t& ix, Int_t& iy)
213 {                                       
214 // Returns pad coordinates (ix,iy) for given real coordinates (x,y)
215 // If there is no pad, ix = 0, iy = 0 are returned.
216 // ---
217
218   AliMpPad pad = fPlaneSegmentation
219                ->PadByPosition(TVector2(x/fgkLengthUnit, y/fgkLengthUnit), false);
220
221   ix = pad.GetIndices().GetFirst();
222   iy = pad.GetIndices().GetSecond();
223 }
224                        
225 //______________________________________________________________________________
226 void  AliMUONSt1Segmentation::GetPadC(Int_t ix, Int_t iy, 
227                                       Float_t& x, Float_t& y, Float_t& z)
228 {                                       
229 // Transform from pad to real coordinates
230 // ---
231
232   z = fZ;
233   GetPadC(ix, iy, x , y);
234 }
235
236 //______________________________________________________________________________
237 void  AliMUONSt1Segmentation::GetPadC(Int_t ix, Int_t iy, 
238                                       Float_t& x, Float_t& y)
239 {                                       
240 // Transform from pad to real coordinates
241 // If there is no pad, x = 0., y = 0. are returned.
242 // ---
243
244   AliMpPad pad = fPlaneSegmentation->PadByIndices(AliMpIntPair(ix,iy));
245
246   x = pad.Position().X() * fgkLengthUnit;
247   y = pad.Position().Y() * fgkLengthUnit;
248 }
249
250
251 //______________________________________________________________________________
252 void AliMUONSt1Segmentation::Init(Int_t chamber)
253 {
254 // Initialize segmentation
255 // ---
256
257   // find Npx, Npy and save this info
258   
259   // reference to chamber
260  AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
261  fChamber = &(pMUON->Chamber(chamber));
262  fRmin=fChamber->RInner();
263  fRmax=fChamber->ROuter();  
264  fZ = fChamber->Z();
265  fId=chamber;
266 }
267  
268 //______________________________________________________________________________
269 Float_t AliMUONSt1Segmentation::Dpx() const
270 {
271 // Get pad size in x
272 // ---
273
274   Fatal("Dpx", "Not uniform pad size.");
275   return 0.;
276 }
277
278 //______________________________________________________________________________
279 Float_t AliMUONSt1Segmentation::Dpy() const
280 {
281 // Get pad size in y
282 // ---
283
284   Fatal("Dpy", "Not uniform pad size.");
285   return 0.;
286 }
287  
288 //______________________________________________________________________________
289 Float_t AliMUONSt1Segmentation::Dpx(Int_t isector) const
290 {
291 // Pad size in x by sector
292 // ---
293
294   return fPlaneSegmentation->PadDimensions(isector).X()*2.*fgkLengthUnit;
295
296
297 //______________________________________________________________________________
298 Float_t AliMUONSt1Segmentation::Dpy(Int_t isector) const
299 {
300 // Pad size in x, y by Sector 
301 // ---
302
303   return fPlaneSegmentation->PadDimensions(isector).Y()*2.*fgkLengthUnit;
304 }
305
306 //______________________________________________________________________________
307 Int_t AliMUONSt1Segmentation::Npx() const
308 {
309 // Maximum number of Pads in x
310 // ---
311
312   //Fatal("Npx", "Not yet implemented.");
313   return 142; //hard coded for the time being
314 }
315
316 //______________________________________________________________________________
317 Int_t AliMUONSt1Segmentation::Npy() const
318 {
319 // Maximum number of Pads in y
320 // ---
321
322   //Fatal("Npy", "Not yet implemented.");
323   return 213; //hard coded for the time being
324 }
325
326 //______________________________________________________________________________
327 void  AliMUONSt1Segmentation::SetPad(Int_t ix, Int_t iy)
328 {
329 // Set pad position.
330 // Sets virtual pad coordinates, needed for evaluating pad response 
331 // outside the tracking program.
332 // From AliMUONSegmentationV01.
333 // ---
334
335   GetPadC(ix, iy, fX, fY);
336   fSector = Sector(ix, iy);
337 }
338
339 //______________________________________________________________________________
340 void  AliMUONSt1Segmentation::SetHit(Float_t xhit, Float_t yhit, Float_t /*zhit*/)
341 {
342 // Set hit position
343 // Sets virtual hit position, needed for evaluating pad response 
344 // outside the tracking program 
345 // From AliMUONSegmentationV01.
346
347   fXhit = xhit;
348   fYhit = yhit;
349 }
350     
351 //______________________________________________________________________________
352 void  AliMUONSt1Segmentation::FirstPad(Float_t xhit, Float_t yhit, Float_t /*zhit*/, 
353                                        Float_t dx, Float_t dy) 
354 {                                        
355 // Iterate over pads - initialiser
356 // ---
357
358   // Sets the current pad to that located in the hit position
359  
360   SetHit(GetAnod(xhit), yhit, 0.); 
361   
362   // Enable iterating in one dimension
363   if (dx == 0.)  dx = 0.01;
364   if (dy == 0.)  dy = 0.01;
365   
366   fPlaneIterator 
367     = fPlaneSegmentation
368         ->CreateIterator(AliMpArea(TVector2(fXhit/fgkLengthUnit, fYhit/fgkLengthUnit), 
369                                    TVector2(dx/fgkLengthUnit, dy/fgkLengthUnit)));
370
371   fPlaneIterator->First();              
372
373   if (! fPlaneIterator->IsDone())
374     UpdateCurrentPadValues(fPlaneIterator->CurrentItem());
375 }
376  
377 //______________________________________________________________________________
378 void  AliMUONSt1Segmentation::NextPad()
379 {
380 // Iterate over pads - stepper
381 // ---
382
383   fPlaneIterator->Next();                               
384
385   if (! fPlaneIterator->IsDone())
386     UpdateCurrentPadValues(fPlaneIterator->CurrentItem());
387 }
388
389 //______________________________________________________________________________
390 Int_t AliMUONSt1Segmentation::MorePads()
391 {
392 // Iterate over pads - condition
393 // ---
394
395   if (fPlaneIterator->IsDone())
396     return 0;
397   else
398     return 1;  
399 }
400
401 //______________________________________________________________________________
402 Float_t AliMUONSt1Segmentation::Distance2AndOffset(Int_t iX, Int_t iY, 
403                                                    Float_t x, Float_t y, Int_t* /*dummy*/)
404 {                                          
405 // Returns the square of the distance between 1 pad
406 // labelled by its channel numbers and a coordinate
407 // ---
408
409   AliMpPad pad = fPlaneSegmentation->PadByIndices(AliMpIntPair(iX, iY));
410   
411   if (!pad.IsValid())
412     Fatal("Distance2AndOffset", "Cannot locate pad.");
413
414   return (pad.Position()*fgkLengthUnit - TVector2(x, y)).Mod2();
415 }
416
417 //______________________________________________________________________________
418 void AliMUONSt1Segmentation::GetNParallelAndOffset(Int_t /*iX*/, Int_t /*iY*/,
419                                                    Int_t* /*Nparallel*/, Int_t* /*Offset*/)
420 {                                          
421 // Number of pads read in parallel and offset to add to x 
422 // (specific to LYON, but mandatory for display)
423 // ---
424
425   Fatal("GetNParallelAndOffset", "Not yet implemented.");
426 }
427
428
429 //______________________________________________________________________________
430 void AliMUONSt1Segmentation::Neighbours(Int_t iX, Int_t iY, 
431                                         Int_t* Nlist, 
432                                         Int_t Xlist[10], Int_t Ylist[10])
433 {                                         
434 // Get next neighbours 
435 // ---
436
437   AliMpPad pad = fPlaneSegmentation->PadByIndices(AliMpIntPair(iX,iY));
438   Int_t &i = *Nlist;
439   i=0;
440   AliMpVPadIterator* iter
441     = fPlaneSegmentation
442       ->CreateIterator(AliMpArea(pad.Position(),2.*pad.Dimensions()*1.1));
443
444   for( iter->First(); !iter->IsDone() && i<10; iter->Next()) {
445     Xlist[i] = iter->CurrentItem().GetIndices().GetFirst();
446     Ylist[i] = iter->CurrentItem().GetIndices().GetSecond();
447     i++;
448   }
449   
450   delete iter;
451 }
452
453 //______________________________________________________________________________
454 Int_t  AliMUONSt1Segmentation::Ix()
455 {
456 // Current pad cursor during disintegration
457 // x, y-coordinate
458 // ---
459
460   return fPlaneIterator->CurrentItem().GetIndices().GetFirst();
461 }
462
463 //______________________________________________________________________________
464 Int_t  AliMUONSt1Segmentation::Iy()
465 {
466 // Current pad cursor during disintegration
467 // x, y-coordinate
468 // ---
469
470   return fPlaneIterator->CurrentItem().GetIndices().GetSecond();
471 }
472
473 //______________________________________________________________________________
474 Int_t  AliMUONSt1Segmentation::ISector()
475 {
476 // Current sector
477 // ---
478
479   return fSector;
480 }
481
482 //______________________________________________________________________________
483 Int_t AliMUONSt1Segmentation::Sector(Int_t ix, Int_t iy)
484 {
485 // Calculate sector from pad coordinates
486 // ---
487
488   return fPlaneSegmentation
489            ->Zone(fPlaneSegmentation->PadByIndices(AliMpIntPair(ix, iy)));
490 }
491
492 //______________________________________________________________________________
493 Int_t AliMUONSt1Segmentation::Sector(Float_t x, Float_t y)
494 {
495 // Calculate sector from pad coordinates
496 // ---
497
498   return fPlaneSegmentation
499            ->Zone(fPlaneSegmentation
500                     ->PadByPosition(TVector2(x/fgkLengthUnit, y/fgkLengthUnit)));
501 }
502
503 //______________________________________________________________________________
504 void  AliMUONSt1Segmentation::IntegrationLimits(Float_t& x1, Float_t& x2,
505                                                 Float_t& y1, Float_t& y2)
506 {                                                 
507 // Current integration limits 
508 // ---
509  
510   x1 = fXhit - fX - Dpx(fSector)/2.;
511   x2 = x1 + Dpx(fSector);
512
513   y1 = fYhit - fY - Dpy(fSector)/2.;
514   y2 = y1 + Dpy(fSector);    
515 }
516
517 //______________________________________________________________________________
518 Int_t AliMUONSt1Segmentation::SigGenCond(Float_t x, Float_t y, Float_t /*z*/)
519 {
520 // Signal Generation Condition during Stepping
521 //  0: don't generate signal
522 //  1: generate signal 
523 //  Comments: 
524 //
525 //  Crossing of pad boundary and mid plane between neighbouring wires is checked.
526 //  To correctly simulate the dependence of the spatial resolution on the angle 
527 //  of incidence signal must be generated for constant steps on 
528 //  the projection of the trajectory along the anode wire.
529 //
530 //  Signal will be generated if particle crosses pad boundary or
531 //  boundary between two wires. 
532 //
533 // From AliMUONSegmentationV01
534 // ---
535
536   Int_t ixt, iyt;
537   GetPadI(x, y, ixt, iyt);
538   Int_t iwt=(x>0) ? Int_t(x/fWireD)+1 : Int_t(x/fWireD)-1;
539   
540   if ((ixt != fIxt) || (iyt !=fIyt) || (iwt != fIwt)) {
541     return 1;
542   } 
543   else {
544     return 0;
545   }
546 }
547
548
549 //______________________________________________________________________________
550 void  AliMUONSt1Segmentation::SigGenInit(Float_t x, Float_t y, Float_t /*z*/)
551 {
552 // Initialise signal generation at coord (x,y,z)
553 // Initialises pad and wire position during stepping.
554 // From AliMUONSegmentationV01
555 // ---
556
557   fXt = x;
558   fYt = y;
559   GetPadI(x, y, fIxt, fIyt);
560   fIwt = (x>0) ? Int_t(x/fWireD)+1 : Int_t(x/fWireD)-1 ;
561 }                   
562     
563 //______________________________________________________________________________
564 void AliMUONSt1Segmentation::GiveTestPoints(Int_t& n, Float_t* x, Float_t* y) const
565 {                                             
566 // Test points for auto calibration
567 // Returns test point on the pad plane.
568 // Used during determination of the segmoid correction of the COG-method
569 // From AliMUONSegmentationV01
570 // ---
571
572   n=1;
573   x[0] = (fRmax+fRmin)/2/TMath::Sqrt(2.);
574   y[0] = x[0];
575 }
576
577 //______________________________________________________________________________
578 void AliMUONSt1Segmentation::Draw(const char * /*opt*/) const
579 {
580 // Draw the segmentation zones.
581 // (Called from AliMUON::BuildGeometry)
582 // ---
583
584   Warning("Draw", "Not yet implemented.");
585 }
586
587 //______________________________________________________________________________
588 void AliMUONSt1Segmentation::SetCorrFunc(Int_t isec, TF1* func)
589 {
590 // Set the correction function.
591 // From AliMUONSegmentationV01
592 // ---
593
594   fCorrA->AddAt(func, isec);
595 }
596
597 //______________________________________________________________________________
598 TF1* AliMUONSt1Segmentation::CorrFunc(Int_t isec) const
599 {
600 // Get the correction Function.
601 // From AliMUONSegmentationV01
602 // ---
603
604   return (TF1*) fCorrA->At(isec);
605
606