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