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