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