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