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