]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSt12QuadrantSegmentation.cxx
Using TGeo as default transport package
[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 "AliMpNeighboursPadIterator.h"
44 #include <TSystem.h>
45
46 ClassImp(AliMUONSt12QuadrantSegmentation)
47
48 const Float_t  AliMUONSt12QuadrantSegmentation::fgkWireD = 0.20; 
49 const Float_t  AliMUONSt12QuadrantSegmentation::fgkLengthUnit = 0.1; 
50
51 //______________________________________________________________________________
52 AliMUONSt12QuadrantSegmentation::AliMUONSt12QuadrantSegmentation(
53                                        AliMpStationType stationType,
54                                        AliMpPlaneType planeType) 
55 : AliMUONVGeometryDESegmentation(),
56   fStationType(stationType),
57   fPlaneType(planeType),
58   fSector(0),
59   fSectorSegmentation(0),
60   fSectorIterator(0),
61   fWireD(fgkWireD),
62   fChamber(0),
63   fId(0),
64   fRmin(0.),
65   fRmax(0.),
66   fZ(0.),
67   fIx(0),
68   fIy(0),
69   fX(0.),
70   fY(0.),
71   fZone(0),
72   fXhit(0.),
73   fYhit(0.),
74   fIxt(0),
75   fIyt(0),
76   fIwt(0),
77   fXt(0.),
78   fYt(0.),
79   fCorrA(0)
80 {
81 // Normal constructor
82
83   ReadMappingData();
84
85   fCorrA = new TObjArray(3);
86   fCorrA->AddAt(0,0);
87   fCorrA->AddAt(0,1);
88   fCorrA->AddAt(0,2);
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
121 //______________________________________________________________________________
122 AliMUONSt12QuadrantSegmentation::AliMUONSt12QuadrantSegmentation(const AliMUONSt12QuadrantSegmentation& rhs) 
123   : AliMUONVGeometryDESegmentation(rhs)
124 {
125 // Copy constructor
126   AliFatal("Copy constructor is not implemented.");
127 }
128
129 //______________________________________________________________________________
130 AliMUONSt12QuadrantSegmentation::~AliMUONSt12QuadrantSegmentation() {
131 // Destructor
132
133   delete fSector;
134   delete fSectorSegmentation;  
135   delete fSectorIterator;  
136
137
138 //
139 // operators
140 //
141
142 //______________________________________________________________________________
143 AliMUONSt12QuadrantSegmentation& 
144 AliMUONSt12QuadrantSegmentation::operator=(const AliMUONSt12QuadrantSegmentation& rhs)
145 {
146 // Copy operator 
147
148   // check assignement to self
149   if (this == &rhs) return *this;
150
151   AliFatal("Assignment operator is not implemented.");
152     
153   return *this;  
154 }
155
156 //
157 // private methods
158 //
159
160 //______________________________________________________________________________
161 void AliMUONSt12QuadrantSegmentation::UpdateCurrentPadValues(const AliMpPad& pad)
162 {
163 // Updates current pad values.
164 // ---
165
166   fIx = pad.GetIndices().GetFirst();
167   fIy = pad.GetIndices().GetSecond();
168   fX = pad.Position().X() * fgkLengthUnit;
169   fY = pad.Position().Y() * fgkLengthUnit;
170   fZone = fSectorSegmentation->Zone(pad);
171 }  
172
173
174 //______________________________________________________________________________
175 void AliMUONSt12QuadrantSegmentation::ReadMappingData()
176 {
177 // Reads mapping data
178 // ---
179
180   // set path to mapping data files
181    if (!gSystem->Getenv("MINSTALL")) {    
182      TString dirPath = gSystem->Getenv("ALICE_ROOT");
183      dirPath += "/MUON/mapping"; 
184      AliMpFiles::Instance()->SetTopPath(dirPath);
185      gSystem->Setenv("MINSTALL", dirPath.Data());
186      //cout << "AliMpFiles top path set to " << dirPath << endl;          
187    }
188   
189   AliMpReader r(fStationType, fPlaneType);
190   fSector = r.BuildSector();
191   fSectorSegmentation = new AliMpSectorSegmentation(fSector);
192 }
193
194 //
195 // public methods
196 //
197
198 //______________________________________________________________________________
199 void AliMUONSt12QuadrantSegmentation::SetPadSize(Float_t /*p1*/, Float_t /*p2*/)
200 {
201 // Set pad size Dx*Dy 
202 // ---
203
204   AliFatal("Not uniform pad size.");
205 }
206
207 //______________________________________________________________________________
208 void AliMUONSt12QuadrantSegmentation::SetDAnod(Float_t d)
209 {
210 // Set anod pitch
211 // ---
212
213   fWireD = d;
214 }
215
216 #include "AliMpMotifMap.h"
217 //______________________________________________________________________________
218 Bool_t  AliMUONSt12QuadrantSegmentation::HasPad(Float_t x, Float_t y, Float_t /*z*/)
219
220 // Returns true if a pad exists in the given position
221
222   // fSector->GetMotifMap()->Print();
223
224   AliMpPad pad = fSectorSegmentation
225                ->PadByPosition(TVector2(x/fgkLengthUnit, y/fgkLengthUnit), false);
226
227   return pad.IsValid();
228 }  
229
230
231 //______________________________________________________________________________
232 Bool_t  AliMUONSt12QuadrantSegmentation::HasPad(Int_t ix, Int_t iy)
233 {
234 // Returns true if a pad with given indices exists
235
236   AliMpPad pad = fSectorSegmentation->PadByIndices(AliMpIntPair(ix,iy), false);
237
238   return pad.IsValid();
239 }  
240
241
242 //______________________________________________________________________________
243 AliMUONGeometryDirection  AliMUONSt12QuadrantSegmentation::GetDirection()
244 {
245 // Returns the direction with a constant pad size  
246 // (Direction or coordinate where the resolution is the best)
247
248   switch ( fSector->GetDirection() ) {
249     case kX: return kDirX;
250     case kY: return kDirY;
251     default: return kDirUndefined;
252   }  
253 }  
254
255 //______________________________________________________________________________
256 Float_t AliMUONSt12QuadrantSegmentation::GetAnod(Float_t xhit) const
257 {
258 // Anod wire coordinate closest to xhit
259 // Returns for a hit position xhit the position of the nearest anode wire    
260 // From AliMUONSegmentationV01.
261 // ---
262
263   Float_t wire= (xhit>0) ? Int_t(xhit/fWireD) + 0.5
264                          : Int_t(xhit/fWireD) - 0.5;
265   return fWireD*wire;
266
267 }
268
269 //______________________________________________________________________________
270 void  AliMUONSt12QuadrantSegmentation::GetPadI(Float_t x, Float_t y, Float_t /*z*/, 
271                                       Int_t& ix, Int_t& iy)
272 {                                       
273 //  Returns pad coordinates (ix,iy) for given real coordinates (x,y)
274 // ---
275
276   GetPadI(x, y, ix, iy);
277 }
278                        
279 //______________________________________________________________________________
280 void  AliMUONSt12QuadrantSegmentation::GetPadI(Float_t x, Float_t y,
281                                       Int_t& ix, Int_t& iy)
282 {                                       
283 // Returns pad coordinates (ix,iy) for given real coordinates (x,y)
284 // If there is no pad, ix = 0, iy = 0 are returned.
285 // ---
286
287   AliMpPad pad = fSectorSegmentation
288                ->PadByPosition(TVector2(x/fgkLengthUnit, y/fgkLengthUnit), true);
289
290   ix = pad.GetIndices().GetFirst();
291   iy = pad.GetIndices().GetSecond();
292 }
293                        
294 //______________________________________________________________________________
295 void  AliMUONSt12QuadrantSegmentation::GetPadC(Int_t ix, Int_t iy, 
296                                       Float_t& x, Float_t& y, Float_t& z)
297 {                                       
298 // Transform from pad to real coordinates
299 // ---
300
301   z = fZ;
302   GetPadC(ix, iy, x , y);
303 }
304
305 //______________________________________________________________________________
306 void  AliMUONSt12QuadrantSegmentation::GetPadC(Int_t ix, Int_t iy, 
307                                       Float_t& x, Float_t& y)
308 {                                       
309 // Transform from pad to real coordinates
310 // If there is no pad, x = 0., y = 0. are returned.
311 // ---
312
313   AliMpPad pad = fSectorSegmentation->PadByIndices(AliMpIntPair(ix,iy), true);
314
315   x = pad.Position().X() * fgkLengthUnit;
316   y = pad.Position().Y() * fgkLengthUnit;
317 }
318
319
320 //______________________________________________________________________________
321 void AliMUONSt12QuadrantSegmentation::Init(Int_t chamber)
322 {
323 // Initialize segmentation
324 // ---
325
326  // find Npx, Npy and save this info
327   
328   // reference to chamber
329  AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
330  fChamber = &(pMUON->Chamber(chamber));
331  fRmin=fChamber->RInner();
332  fRmax=fChamber->ROuter();  
333  fZ = 0;
334  fId=chamber;
335 }
336  
337 //______________________________________________________________________________
338 Float_t AliMUONSt12QuadrantSegmentation::Dpx() const
339 {
340 // Get pad size in x
341 // ---
342
343   AliFatal( "Not uniform pad size.");
344   return 0.;
345 }
346
347 //______________________________________________________________________________
348 Float_t AliMUONSt12QuadrantSegmentation::Dpy() const
349 {
350 // Get pad size in y
351 // ---
352
353   AliFatal("Not uniform pad size.");
354   return 0.;
355 }
356  
357 //______________________________________________________________________________
358 Float_t AliMUONSt12QuadrantSegmentation::Dpx(Int_t isector) const
359 {
360 // Pad size in x by sector
361 // ---
362
363   return fSectorSegmentation->PadDimensions(isector).X()*2.*fgkLengthUnit;
364
365
366 //______________________________________________________________________________
367 Float_t AliMUONSt12QuadrantSegmentation::Dpy(Int_t isector) const
368 {
369 // Pad size in x, y by Sector 
370 // ---
371
372   return fSectorSegmentation->PadDimensions(isector).Y()*2.*fgkLengthUnit;
373 }
374
375 //______________________________________________________________________________
376 Int_t AliMUONSt12QuadrantSegmentation::Npx() const
377 {
378 // Maximum number of Pads in x
379 // hard coded for the time being
380 // ---
381
382   return fSectorSegmentation->MaxPadIndexX();
383 }
384
385 //______________________________________________________________________________
386 Int_t AliMUONSt12QuadrantSegmentation::Npy() const
387 {
388 // Maximum number of Pads in y
389 // hard coded for the time being
390 // ---
391
392   return fSectorSegmentation->MaxPadIndexY();
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   AliMpNeighboursPadIterator iter
510     = AliMpNeighboursPadIterator(fSectorSegmentation, pad, kFALSE);
511
512   for( iter.First(); !iter.IsDone() && i<10; iter.Next()) {
513     Xlist[i] = iter.CurrentItem().GetIndices().GetFirst();
514     Ylist[i] = iter.CurrentItem().GetIndices().GetSecond();
515     i++;
516   }
517 }
518  
519 //______________________________________________________________________________
520 Int_t  AliMUONSt12QuadrantSegmentation::Ix()
521 {
522 // Current pad cursor during disintegration
523 // x, y-coordinate
524 // ---
525
526   return fSectorIterator->CurrentItem().GetIndices().GetFirst();
527 }
528
529 //______________________________________________________________________________
530 Int_t  AliMUONSt12QuadrantSegmentation::Iy()
531 {
532 // Current pad cursor during disintegration
533 // x, y-coordinate
534 // ---
535
536   return fSectorIterator->CurrentItem().GetIndices().GetSecond();
537 }
538
539 //______________________________________________________________________________
540 Int_t  AliMUONSt12QuadrantSegmentation::ISector()
541 {
542 // Current sector
543 // ---
544
545   return fZone;
546 }
547
548 //______________________________________________________________________________
549 Int_t AliMUONSt12QuadrantSegmentation::Sector(Int_t ix, Int_t iy)
550 {
551 // Calculate sector from pad coordinates
552 // ---
553
554   return fSectorSegmentation
555            ->Zone(fSectorSegmentation->PadByIndices(AliMpIntPair(ix, iy)));
556 }
557
558 //______________________________________________________________________________
559 Int_t AliMUONSt12QuadrantSegmentation::Sector(Float_t x, Float_t y)
560 {
561 // Calculate sector from pad coordinates
562 // ---
563
564   return fSectorSegmentation
565            ->Zone(fSectorSegmentation
566                     ->PadByPosition(TVector2(x/fgkLengthUnit, y/fgkLengthUnit)));
567 }
568
569 //______________________________________________________________________________
570 void  AliMUONSt12QuadrantSegmentation::IntegrationLimits(Float_t& x1, Float_t& x2,
571                                                 Float_t& y1, Float_t& y2)
572 {                                                 
573 // Current integration limits 
574 // ---
575  
576   x1 = fXhit - fX - Dpx(fZone)/2.;
577   x2 = x1 + Dpx(fZone);
578
579   y1 = fYhit - fY - Dpy(fZone)/2.;
580   y2 = y1 + Dpy(fZone);    
581 }
582
583 //______________________________________________________________________________
584 Int_t AliMUONSt12QuadrantSegmentation::SigGenCond(Float_t x, Float_t y, Float_t /*z*/)
585 {
586 // Signal Generation Condition during Stepping
587 //  0: don't generate signal
588 //  1: generate signal 
589 //  Comments: 
590 //
591 //  Crossing of pad boundary and mid plane between neighbouring wires is checked.
592 //  To correctly simulate the dependence of the spatial resolution on the angle 
593 //  of incidence signal must be generated for constant steps on 
594 //  the projection of the trajectory along the anode wire.
595 //
596 //  Signal will be generated if particle crosses pad boundary or
597 //  boundary between two wires. 
598 //
599 // From AliMUONSegmentationV01
600 // ---
601
602   Int_t ixt, iyt;
603   GetPadI(x, y, ixt, iyt);
604   Int_t iwt=(x>0) ? Int_t(x/fWireD)+1 : Int_t(x/fWireD)-1;
605   
606   if ((ixt != fIxt) || (iyt !=fIyt) || (iwt != fIwt)) {
607     return 1;
608   } 
609   else {
610     return 0;
611   }
612 }
613
614 //______________________________________________________________________________
615 void  AliMUONSt12QuadrantSegmentation::SigGenInit(Float_t x, Float_t y, Float_t /*z*/)
616 {
617 // Initialise signal generation at coord (x,y,z)
618 // Initialises pad and wire position during stepping.
619 // From AliMUONSegmentationV01
620 // ---
621
622   fXt = x;
623   fYt = y;
624   GetPadI(x, y, fIxt, fIyt);
625   fIwt = (x>0) ? Int_t(x/fWireD)+1 : Int_t(x/fWireD)-1 ;
626 }                   
627     
628 //______________________________________________________________________________
629 void AliMUONSt12QuadrantSegmentation::GiveTestPoints(Int_t& n, Float_t* x, Float_t* y) const
630 {                                             
631 // Test points for auto calibration
632 // Returns test point on the pad plane.
633 // Used during determination of the segmoid correction of the COG-method
634 // From AliMUONSegmentationV01
635 // ---
636
637   n=1;
638   x[0] = (fRmax+fRmin)/2/TMath::Sqrt(2.);
639   y[0] = x[0];
640 }
641
642 //______________________________________________________________________________
643 void AliMUONSt12QuadrantSegmentation::Draw(const char * /*opt*/)
644 {
645 // Draw the segmentation zones.
646 // (Called from AliMUON::BuildGeometry)
647 // ---
648
649   AliWarning("Not yet implemented.");
650 }
651
652 //______________________________________________________________________________
653 void AliMUONSt12QuadrantSegmentation::SetCorrFunc(Int_t isec, TF1* func)
654 {
655 // Set the correction function.
656 // From AliMUONSegmentationV01
657 // ---
658
659   fCorrA->AddAt(func, isec);
660 }
661
662 //______________________________________________________________________________
663 TF1* AliMUONSt12QuadrantSegmentation::CorrFunc(Int_t isec) const
664 {
665 // Get the correction Function.
666 // From AliMUONSegmentationV01
667 // ---
668
669   return (TF1*) fCorrA->At(isec);
670
671
672 //______________________________________________________________________________
673 void AliMUONSt12QuadrantSegmentation::Streamer(TBuffer &R__b)
674 {
675 // Stream an object of class AliMUONSt12QuadrantSegmentation.
676
677   if (R__b.IsReading()) {
678     AliMUONSt12QuadrantSegmentation::Class()->ReadBuffer(R__b, this);
679     ReadMappingData();
680   } 
681   else {
682     AliMUONSt12QuadrantSegmentation::Class()->WriteBuffer(R__b, this);
683   }
684 }
685
686