]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSt12QuadrantSegmentation.cxx
- Detection elements segmentations now derived from the
[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 Float_t AliMUONSt12QuadrantSegmentation::GetAnod(Float_t xhit) const
215 {
216 // Anod wire coordinate closest to xhit
217 // Returns for a hit position xhit the position of the nearest anode wire    
218 // From AliMUONSegmentationV01.
219 // ---
220
221   Float_t wire= (xhit>0) ? Int_t(xhit/fWireD) + 0.5
222                          : Int_t(xhit/fWireD) - 0.5;
223   return fWireD*wire;
224
225 }
226
227 //______________________________________________________________________________
228 void  AliMUONSt12QuadrantSegmentation::GetPadI(Float_t x, Float_t y, Float_t /*z*/, 
229                                       Int_t& ix, Int_t& iy)
230 {                                       
231 //  Returns pad coordinates (ix,iy) for given real coordinates (x,y)
232 // ---
233
234   GetPadI(x, y, ix, iy);
235 }
236                        
237 //______________________________________________________________________________
238 void  AliMUONSt12QuadrantSegmentation::GetPadI(Float_t x, Float_t y,
239                                       Int_t& ix, Int_t& iy)
240 {                                       
241 // Returns pad coordinates (ix,iy) for given real coordinates (x,y)
242 // If there is no pad, ix = 0, iy = 0 are returned.
243 // ---
244
245   AliMpPad pad = fSectorSegmentation
246                ->PadByPosition(TVector2(x/fgkLengthUnit, y/fgkLengthUnit), true);
247
248   ix = pad.GetIndices().GetFirst();
249   iy = pad.GetIndices().GetSecond();
250 }
251                        
252 //______________________________________________________________________________
253 void  AliMUONSt12QuadrantSegmentation::GetPadC(Int_t ix, Int_t iy, 
254                                       Float_t& x, Float_t& y, Float_t& z)
255 {                                       
256 // Transform from pad to real coordinates
257 // ---
258
259   z = fZ;
260   GetPadC(ix, iy, x , y);
261 }
262
263 //______________________________________________________________________________
264 void  AliMUONSt12QuadrantSegmentation::GetPadC(Int_t ix, Int_t iy, 
265                                       Float_t& x, Float_t& y)
266 {                                       
267 // Transform from pad to real coordinates
268 // If there is no pad, x = 0., y = 0. are returned.
269 // ---
270
271   AliMpPad pad = fSectorSegmentation->PadByIndices(AliMpIntPair(ix,iy), true);
272
273   x = pad.Position().X() * fgkLengthUnit;
274   y = pad.Position().Y() * fgkLengthUnit;
275 }
276
277
278 //______________________________________________________________________________
279 void AliMUONSt12QuadrantSegmentation::Init(Int_t chamber)
280 {
281 // Initialize segmentation
282 // ---
283
284   // find Npx, Npy and save this info
285   
286   // reference to chamber
287  AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
288  fChamber = &(pMUON->Chamber(chamber));
289  fRmin=fChamber->RInner();
290  fRmax=fChamber->ROuter();  
291  fZ = 0;
292  fId=chamber;
293 }
294  
295 //______________________________________________________________________________
296 Float_t AliMUONSt12QuadrantSegmentation::Dpx() const
297 {
298 // Get pad size in x
299 // ---
300
301   AliFatal( "Not uniform pad size.");
302   return 0.;
303 }
304
305 //______________________________________________________________________________
306 Float_t AliMUONSt12QuadrantSegmentation::Dpy() const
307 {
308 // Get pad size in y
309 // ---
310
311   AliFatal("Not uniform pad size.");
312   return 0.;
313 }
314  
315 //______________________________________________________________________________
316 Float_t AliMUONSt12QuadrantSegmentation::Dpx(Int_t isector) const
317 {
318 // Pad size in x by sector
319 // ---
320
321   return fSectorSegmentation->PadDimensions(isector).X()*2.*fgkLengthUnit;
322
323
324 //______________________________________________________________________________
325 Float_t AliMUONSt12QuadrantSegmentation::Dpy(Int_t isector) const
326 {
327 // Pad size in x, y by Sector 
328 // ---
329
330   return fSectorSegmentation->PadDimensions(isector).Y()*2.*fgkLengthUnit;
331 }
332
333 //______________________________________________________________________________
334 Int_t AliMUONSt12QuadrantSegmentation::Npx() const
335 {
336 // Maximum number of Pads in x
337 // hard coded for the time being
338 // ---
339
340   //Fatal("Npx", "Not yet implemented.");
341   switch (fSector->GetDirection()) {
342     case kX:
343       return 142;
344     case kY:
345       return 108;
346     default:
347       AliError("Unknown sector direction");
348       return 0;  
349   }      
350 }
351
352 //______________________________________________________________________________
353 Int_t AliMUONSt12QuadrantSegmentation::Npy() const
354 {
355 // Maximum number of Pads in y
356 // hard coded for the time being
357 // ---
358
359   //Fatal("Npy", "Not yet implemented.");
360   switch (fSector->GetDirection()) {
361     case kX:
362       return 160;
363     case kY:
364       return 213;
365     default:
366       AliError("Unknown sector direction");
367       return 0;  
368   }    
369 }
370
371 //______________________________________________________________________________
372 void  AliMUONSt12QuadrantSegmentation::SetPad(Int_t ix, Int_t iy)
373 {
374 // Set pad position.
375 // Sets virtual pad coordinates, needed for evaluating pad response 
376 // outside the tracking program.
377 // From AliMUONSegmentationV01.
378 // ---
379
380   GetPadC(ix, iy, fX, fY);
381   fZone = Sector(ix, iy);
382 }
383
384 //______________________________________________________________________________
385 void  AliMUONSt12QuadrantSegmentation::SetHit(Float_t xhit, Float_t yhit, Float_t /*zhit*/)
386 {
387 // Set hit position
388 // Sets virtual hit position, needed for evaluating pad response 
389 // outside the tracking program 
390 // From AliMUONSegmentationV01.
391
392   fXhit = xhit;
393   fYhit = yhit;
394 }
395     
396 //______________________________________________________________________________
397 void  AliMUONSt12QuadrantSegmentation::FirstPad(Float_t xhit, Float_t yhit, Float_t /*zhit*/, 
398                                        Float_t dx, Float_t dy) 
399 {                                        
400 // Iterate over pads - initialiser
401 // ---
402
403   // Sets the current pad to that located in the hit position
404  
405   SetHit(GetAnod(xhit), yhit, 0.); 
406   
407   // Enable iterating in one dimension
408   if (dx == 0.)  dx = 0.01;
409   if (dy == 0.)  dy = 0.01;
410   
411   fSectorIterator 
412     = fSectorSegmentation
413         ->CreateIterator(AliMpArea(TVector2(fXhit/fgkLengthUnit, fYhit/fgkLengthUnit), 
414                                    TVector2(dx/fgkLengthUnit, dy/fgkLengthUnit)));
415
416   fSectorIterator->First();             
417
418   if (! fSectorIterator->IsDone())
419     UpdateCurrentPadValues(fSectorIterator->CurrentItem());
420 }
421  
422 //______________________________________________________________________________
423 void  AliMUONSt12QuadrantSegmentation::NextPad()
424 {
425 // Iterate over pads - stepper
426 // ---
427
428   fSectorIterator->Next();                              
429
430   if (! fSectorIterator->IsDone())
431     UpdateCurrentPadValues(fSectorIterator->CurrentItem());
432 }
433
434 //______________________________________________________________________________
435 Int_t AliMUONSt12QuadrantSegmentation::MorePads()
436 {
437 // Iterate over pads - condition
438 // ---
439
440   if (fSectorIterator->IsDone())
441     return 0;
442   else
443     return 1;  
444 }
445
446 //______________________________________________________________________________
447 Float_t AliMUONSt12QuadrantSegmentation::Distance2AndOffset(Int_t iX, Int_t iY, 
448                                                    Float_t x, Float_t y, Int_t* /*dummy*/)
449 {                                          
450 // Returns the square of the distance between 1 pad
451 // labelled by its channel numbers and a coordinate
452 // ---
453
454   AliMpPad pad = fSectorSegmentation->PadByIndices(AliMpIntPair(iX, iY));
455   
456   if (!pad.IsValid())
457     AliFatal("Cannot locate pad.");
458
459   return (pad.Position()*fgkLengthUnit - TVector2(x, y)).Mod2();
460 }
461
462 //______________________________________________________________________________
463 void AliMUONSt12QuadrantSegmentation::GetNParallelAndOffset(Int_t /*iX*/, Int_t /*iY*/,
464                                                    Int_t* /*Nparallel*/, Int_t* /*Offset*/)
465 {                                          
466 // Number of pads read in parallel and offset to add to x 
467 // (specific to LYON, but mandatory for display)
468 // ---
469
470   AliFatal( "Not yet implemented.");
471 }
472
473
474 //______________________________________________________________________________
475 void AliMUONSt12QuadrantSegmentation::Neighbours(Int_t iX, Int_t iY, 
476                                         Int_t* Nlist, 
477                                         Int_t Xlist[10], Int_t Ylist[10])
478 {                                         
479 // Get next neighbours 
480 // ---
481
482   AliMpPad pad = fSectorSegmentation->PadByIndices(AliMpIntPair(iX,iY));
483   Int_t &i = *Nlist;
484   i=0;
485   AliMpVPadIterator* iter
486     = fSectorSegmentation
487       ->CreateIterator(AliMpArea(pad.Position(),2.*pad.Dimensions()*1.1));
488
489   for( iter->First(); !iter->IsDone() && i<10; iter->Next()) {
490     Xlist[i] = iter->CurrentItem().GetIndices().GetFirst();
491     Ylist[i] = iter->CurrentItem().GetIndices().GetSecond();
492     i++;
493   }
494   
495   delete iter;
496 }
497
498 //______________________________________________________________________________
499 Int_t  AliMUONSt12QuadrantSegmentation::Ix()
500 {
501 // Current pad cursor during disintegration
502 // x, y-coordinate
503 // ---
504
505   return fSectorIterator->CurrentItem().GetIndices().GetFirst();
506 }
507
508 //______________________________________________________________________________
509 Int_t  AliMUONSt12QuadrantSegmentation::Iy()
510 {
511 // Current pad cursor during disintegration
512 // x, y-coordinate
513 // ---
514
515   return fSectorIterator->CurrentItem().GetIndices().GetSecond();
516 }
517
518 //______________________________________________________________________________
519 Int_t  AliMUONSt12QuadrantSegmentation::ISector()
520 {
521 // Current sector
522 // ---
523
524   return fZone;
525 }
526
527 //______________________________________________________________________________
528 Int_t AliMUONSt12QuadrantSegmentation::Sector(Int_t ix, Int_t iy)
529 {
530 // Calculate sector from pad coordinates
531 // ---
532
533   return fSectorSegmentation
534            ->Zone(fSectorSegmentation->PadByIndices(AliMpIntPair(ix, iy)));
535 }
536
537 //______________________________________________________________________________
538 Int_t AliMUONSt12QuadrantSegmentation::Sector(Float_t x, Float_t y)
539 {
540 // Calculate sector from pad coordinates
541 // ---
542
543   return fSectorSegmentation
544            ->Zone(fSectorSegmentation
545                     ->PadByPosition(TVector2(x/fgkLengthUnit, y/fgkLengthUnit)));
546 }
547
548 //______________________________________________________________________________
549 void  AliMUONSt12QuadrantSegmentation::IntegrationLimits(Float_t& x1, Float_t& x2,
550                                                 Float_t& y1, Float_t& y2)
551 {                                                 
552 // Current integration limits 
553 // ---
554  
555   x1 = fXhit - fX - Dpx(fZone)/2.;
556   x2 = x1 + Dpx(fZone);
557
558   y1 = fYhit - fY - Dpy(fZone)/2.;
559   y2 = y1 + Dpy(fZone);    
560 }
561
562 //______________________________________________________________________________
563 Int_t AliMUONSt12QuadrantSegmentation::SigGenCond(Float_t x, Float_t y, Float_t /*z*/)
564 {
565 // Signal Generation Condition during Stepping
566 //  0: don't generate signal
567 //  1: generate signal 
568 //  Comments: 
569 //
570 //  Crossing of pad boundary and mid plane between neighbouring wires is checked.
571 //  To correctly simulate the dependence of the spatial resolution on the angle 
572 //  of incidence signal must be generated for constant steps on 
573 //  the projection of the trajectory along the anode wire.
574 //
575 //  Signal will be generated if particle crosses pad boundary or
576 //  boundary between two wires. 
577 //
578 // From AliMUONSegmentationV01
579 // ---
580
581   Int_t ixt, iyt;
582   GetPadI(x, y, ixt, iyt);
583   Int_t iwt=(x>0) ? Int_t(x/fWireD)+1 : Int_t(x/fWireD)-1;
584   
585   if ((ixt != fIxt) || (iyt !=fIyt) || (iwt != fIwt)) {
586     return 1;
587   } 
588   else {
589     return 0;
590   }
591 }
592
593
594 //______________________________________________________________________________
595 void  AliMUONSt12QuadrantSegmentation::SigGenInit(Float_t x, Float_t y, Float_t /*z*/)
596 {
597 // Initialise signal generation at coord (x,y,z)
598 // Initialises pad and wire position during stepping.
599 // From AliMUONSegmentationV01
600 // ---
601
602   fXt = x;
603   fYt = y;
604   GetPadI(x, y, fIxt, fIyt);
605   fIwt = (x>0) ? Int_t(x/fWireD)+1 : Int_t(x/fWireD)-1 ;
606 }                   
607     
608 //______________________________________________________________________________
609 void AliMUONSt12QuadrantSegmentation::GiveTestPoints(Int_t& n, Float_t* x, Float_t* y) const
610 {                                             
611 // Test points for auto calibration
612 // Returns test point on the pad plane.
613 // Used during determination of the segmoid correction of the COG-method
614 // From AliMUONSegmentationV01
615 // ---
616
617   n=1;
618   x[0] = (fRmax+fRmin)/2/TMath::Sqrt(2.);
619   y[0] = x[0];
620 }
621
622 //______________________________________________________________________________
623 void AliMUONSt12QuadrantSegmentation::Draw(const char * /*opt*/)
624 {
625 // Draw the segmentation zones.
626 // (Called from AliMUON::BuildGeometry)
627 // ---
628
629   AliWarning("Not yet implemented.");
630 }
631
632 //______________________________________________________________________________
633 void AliMUONSt12QuadrantSegmentation::SetCorrFunc(Int_t isec, TF1* func)
634 {
635 // Set the correction function.
636 // From AliMUONSegmentationV01
637 // ---
638
639   fCorrA->AddAt(func, isec);
640 }
641
642 //______________________________________________________________________________
643 TF1* AliMUONSt12QuadrantSegmentation::CorrFunc(Int_t isec) const
644 {
645 // Get the correction Function.
646 // From AliMUONSegmentationV01
647 // ---
648
649   return (TF1*) fCorrA->At(isec);
650
651