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