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