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