]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSt345SlatSegmentationV2.cxx
new digitization and reconstruction corresponded to new data format
[u/mrichter/AliRoot.git] / MUON / AliMUONSt345SlatSegmentationV2.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 #include "AliMUONSt345SlatSegmentationV2.h"
19 #include "AliMUONConstants.h"
20
21 #include "AliMpArea.h"
22 #include "AliMpSlat.h"
23 #include "AliMpSlatSegmentation.h"
24 #include "AliMpPCB.h" 
25 // FIXME: we should not need access to PCB at this level
26 // if the Dpx, Dpy, Sector interface would not be used.
27 // Investigate instead to direct use of AliMpVSegmentation and AliMpPad
28 // from the clusterFinder ? // :aphecetc:20050722 
29 // or, or ... have the AliMpSlat handles the notion of zone, finally
30 // (where "zone" in mapping is equivalent to "sector" here), and thus
31 // let AliMpSlat offer the interface to get information similar to what
32 // Dpx, Dpy, Sector offer now to the clustering. That indeed should be
33 // handled directly at the level of AliMpVSegmentation...
34 #include "AliMpVPadIterator.h"
35
36 #include "AliLog.h"
37
38 #include "Riostream.h"
39 #include "TClass.h"
40
41 ClassImp(AliMUONSt345SlatSegmentationV2)
42
43 namespace
44 {
45   Float_t FMAX(1E9);
46 }
47
48 //_____________________________________________________________________________
49 AliMUONSt345SlatSegmentationV2::AliMUONSt345SlatSegmentationV2()
50 : AliMUONVGeometryDESegmentation(),
51 fDetElemId(-1),
52 fPlaneType(kBendingPlane),
53 fSlat(0),
54 fSlatSegmentation(0),
55 fPadIterator(0),
56 fXhit(FMAX),
57 fYhit(FMAX)
58 {
59         AliDebug(1,Form("this=%p default (empty) ctor",this));
60 }
61
62 //_____________________________________________________________________________
63 AliMUONSt345SlatSegmentationV2::AliMUONSt345SlatSegmentationV2(
64                                    AliMpVSegmentation* segmentation,
65                                    Int_t detElemId, AliMpPlaneType bendingOrNonBending)
66 : AliMUONVGeometryDESegmentation(),
67 fDetElemId(detElemId),
68 fPlaneType(bendingOrNonBending),
69 fSlat(0),
70 fSlatSegmentation(0),
71 fPadIterator(0),
72 fXhit(FMAX),
73 fYhit(FMAX)
74
75   //
76   // Normal ctor.
77   //
78
79   fSlatSegmentation = dynamic_cast<AliMpSlatSegmentation*>(segmentation);
80   if (fSlatSegmentation)
81     fSlat = fSlatSegmentation->Slat();
82   else 
83     AliFatal("Wrong mapping segmentation type");
84                 
85   AliDebug(1,Form("this=%p detElemId=%3d %s fSlatSegmentation=%p",this,detElemId,
86                                                                         ( (bendingOrNonBending==kBendingPlane)?"Bending":"NonBending" ),
87                                                                         fSlatSegmentation));
88 }
89
90 //______________________________________________________________________________
91 AliMUONSt345SlatSegmentationV2::AliMUONSt345SlatSegmentationV2(
92                                    const AliMUONSt345SlatSegmentationV2& right) 
93   : AliMUONVGeometryDESegmentation(right) 
94 {  
95 /// Protected copy constructor (not implemented)
96
97   AliFatal("Copy constructor not provided.");
98 }
99
100 //_____________________________________________________________________________
101 AliMUONSt345SlatSegmentationV2::~AliMUONSt345SlatSegmentationV2()
102 {
103         AliDebug(1,Form("dtor this=%p",this));
104   delete fPadIterator;
105 }
106
107 //______________________________________________________________________________
108 AliMUONSt345SlatSegmentationV2& 
109 AliMUONSt345SlatSegmentationV2::operator=(const AliMUONSt345SlatSegmentationV2& right)
110 {
111 /// Protected assignement operator (not implemented)
112
113   // check assignement to self
114   if (this == &right) return *this;
115
116   AliFatal("Assignement operator not provided.");
117     
118   return *this;  
119 }    
120
121 //_____________________________________________________________________________
122 TF1*
123 AliMUONSt345SlatSegmentationV2::CorrFunc(Int_t) const
124 {
125   AliFatal("Not Implemented");
126   return 0x0;
127 }
128
129 //_____________________________________________________________________________
130 Float_t 
131 AliMUONSt345SlatSegmentationV2::Distance2AndOffset(Int_t,Int_t,
132                                                                                                                                                                                                          Float_t,Float_t,Int_t*)
133 {
134   AliFatal("Not Implemented");
135   return 0.0;
136 }
137
138 //_____________________________________________________________________________
139 void
140 AliMUONSt345SlatSegmentationV2::Draw(Option_t*)
141 {
142   AliFatal("Not Implemented");
143 }
144
145 //_____________________________________________________________________________
146 Float_t
147 AliMUONSt345SlatSegmentationV2::Dpx() const
148 {
149   AliFatal("Not Implemented");
150   return 0.0;
151 }
152
153 //_____________________________________________________________________________
154 Float_t
155 AliMUONSt345SlatSegmentationV2::Dpy() const
156 {
157   AliFatal("Not Implemented");
158   return 0.0;
159 }
160
161 //_____________________________________________________________________________
162 Float_t
163 AliMUONSt345SlatSegmentationV2::Dpx(int ipcb) const
164 {
165         AliMpPCB* pcb = fSlat->GetPCB(ipcb);
166         if (!pcb) 
167   {
168     AliFatal("pcb is null!");
169   }
170         return pcb->PadSizeX();
171 }
172
173 //_____________________________________________________________________________
174 Float_t
175 AliMUONSt345SlatSegmentationV2::Dpy(int ipcb) const
176 {
177         AliMpPCB* pcb = fSlat->GetPCB(ipcb);
178         if (!pcb) 
179   {
180     AliFatal("pcb is null!");
181   }
182         return pcb->PadSizeY();
183 }
184
185 //_____________________________________________________________________________
186 void
187 AliMUONSt345SlatSegmentationV2::FirstPad(Float_t xhit, Float_t yhit, 
188                                                                                                                                                                  Float_t /*zhit*/, 
189                                                                                                                                                                  Float_t dx, Float_t dy)
190 {
191   // OK. We will do it in 2 steps. First get the area over which to
192   // iterate, based on hit coordinates and (dx,dy). This first step
193   // has nothing to do with segmentation in the first place, but with
194   // how we simulate the fact that at some point the charge is shared
195   // amongst several pads.
196   // The second step is the actual pad iteration and is handled by 
197   // a specific class (which has to do only with iteration...)
198   //
199   // FIXME: this method should not be here in the first place, IMHO.
200   //
201         
202   // Find the wire position (center of charge distribution)
203   Float_t xwire = GetAnod(xhit);
204   fXhit = xwire;
205   fYhit = yhit;
206         
207   Double_t x01 = xwire - dx;
208   Double_t x02 = xwire + dx;
209   Double_t y01 = yhit - dy;
210   Double_t y02 = yhit + dy;
211         
212   Double_t xext = x02 - x01;
213   Double_t yext = y02 - y01;
214         
215   // we do not check area here, as we assume the iterator
216   // will do it, and will possibly truncate it if needed.
217   // Note that we convert the area position to a reference frame
218   // located in the lower-left corner of the slat, instead of its
219   // center.
220 //  AliMpArea area(TVector2((x01+x02)/2.0+fSlat->DX(),
221 //                                                                                                      (y01+y02)/2.0+fSlat->DY()),
222 //                                                               TVector2(xext/2.0,yext/2.0));
223   AliMpArea area(TVector2((x01+x02)/2.0,(y01+y02)/2.0),
224                                                                  TVector2(xext/2.0,yext/2.0));
225         
226   delete fPadIterator;
227         
228   fPadIterator = fSlatSegmentation->CreateIterator(area);
229         
230   fPadIterator->First();
231         
232   fCurrentPad = fPadIterator->CurrentItem();
233         
234   if ( !fCurrentPad.IsValid() ) 
235         {
236                 AliError(Form("Cannot get a valid pad for (xhit,yhit,dx,dy)=(%e,%e,%e,%e)",xhit,yhit,dx,dy));
237         }
238         
239   AliDebug(4,Form("xhit,yhit,dx,dy=%e,%e,%e,%e ix,iy=%3d,%3d slat=%s",
240                                                                         xhit,yhit,dx,dy,
241                                                                         fCurrentPad.GetIndices().GetFirst(),
242                                                                         fCurrentPad.GetIndices().GetSecond(),fSlat->GetID()));            
243 }
244
245 //_____________________________________________________________________________
246 Float_t
247 AliMUONSt345SlatSegmentationV2::GetAnod(Float_t xhit) const
248 {
249   // Gets the x-coordinate of the wire which is the closest to xhit.
250         
251   Int_t n = Int_t(xhit/AliMUONConstants::Pitch());
252   Float_t wire = (xhit>0) ? n+0.5 : n-0.5;
253   return AliMUONConstants::Pitch()*wire;
254 }
255
256 //_____________________________________________________________________________
257 AliMUONGeometryDirection
258 AliMUONSt345SlatSegmentationV2::GetDirection()
259 {
260   //AliWarning("Not Implemented");
261   return kDirUndefined;
262 }
263
264 //______________________________________________________________________________
265 const AliMpVSegmentation*  
266 AliMUONSt345SlatSegmentationV2::GetMpSegmentation() const
267 {
268 // Returns the mapping segmentation
269 // (provides access to electronics info)
270
271   return fSlatSegmentation;
272 }  
273
274
275 //_____________________________________________________________________________
276 void 
277 AliMUONSt345SlatSegmentationV2::GetNParallelAndOffset(Int_t,Int_t,Int_t*,Int_t*)
278 {
279   AliFatal("Not Implemented");
280 }
281
282 //_____________________________________________________________________________
283 void
284 AliMUONSt345SlatSegmentationV2::GetPadC(Int_t ix, Int_t iy, 
285                                                                                                                                                                 Float_t& x, Float_t& y, Float_t& z)
286 {
287   z = 0;
288   GetPadC(ix,iy,x,y);
289 }
290
291 //_____________________________________________________________________________
292 void
293 AliMUONSt345SlatSegmentationV2::GetPadC(Int_t ix, Int_t iy, 
294                                                                                                                                                                 Float_t& x, Float_t& y)
295 {
296   AliMpPad pad = 
297   fSlatSegmentation->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
298   x = pad.Position().X();
299   y = pad.Position().Y();
300 }
301
302
303 //_____________________________________________________________________________
304 void
305 AliMUONSt345SlatSegmentationV2::GetPadI(Float_t x, Float_t y, Float_t /*z*/,
306 Int_t& ix, Int_t& iy)
307 {
308   GetPadI(x,y,ix,iy);
309 }
310
311 //_____________________________________________________________________________
312 void
313 AliMUONSt345SlatSegmentationV2::GetPadI(Float_t x, Float_t y,
314                                                                                                                                                                 Int_t& ix, Int_t& iy)
315 {
316   AliMpPad pad = fSlatSegmentation->PadByPosition(TVector2(x,y), kTRUE);
317         
318   if ( pad != AliMpPad::Invalid() )
319         {
320                 ix = pad.GetIndices().GetFirst();
321                 iy = pad.GetIndices().GetSecond();
322         }
323   else
324         {
325                 ix = iy = -1;
326         }
327 }
328
329 //_____________________________________________________________________________
330 void 
331 AliMUONSt345SlatSegmentationV2::GiveTestPoints(Int_t&,Float_t*,Float_t*) const
332 {
333   AliFatal("Not Implemented");
334 }
335
336 //_____________________________________________________________________________
337 Bool_t
338 AliMUONSt345SlatSegmentationV2::HasPad(Float_t x, Float_t y, Float_t z)
339 {
340   Int_t ix, iy;
341   GetPadI(x,y,z,ix,iy);
342   return HasPad(ix,iy);
343 }
344
345 //_____________________________________________________________________________
346 Bool_t
347 AliMUONSt345SlatSegmentationV2::HasPad(Int_t ix, Int_t iy)
348 {
349   return fSlatSegmentation->HasPad(AliMpIntPair(ix,iy));
350 }
351
352 //_____________________________________________________________________________
353 void  
354 AliMUONSt345SlatSegmentationV2::IntegrationLimits(Float_t& x1, Float_t& x2, 
355                                                                                                                                                                                                         Float_t& y1, Float_t& y2)
356 {
357   //
358   //  Returns integration limits for current pad
359   //
360         
361         //   x1 = fXhit - fX - Dpx(fSector)/2.;
362         //   x2 = x1 + Dpx(fSector);
363         //   y1 = fYhit - fY - Dpy(fSector)/2.;
364         //   y2 = y1 + Dpy(fSector);    
365         
366   Float_t x = fCurrentPad.Position().X();
367   Float_t y = fCurrentPad.Position().Y();
368         
369   Float_t padsizex = fCurrentPad.Dimensions().X() * 2.0;
370   Float_t padsizey = fCurrentPad.Dimensions().Y() * 2.0;
371         
372   x1 = fXhit - x - padsizex/2.0;
373   x2 = x1 + padsizex;
374   y1 = fYhit - y - padsizey/2.0;
375   y2 = y1 + padsizey;
376         
377   AliDebug(4,Form("xhit,yhit=%e,%e x,y=%e,%e, x1,x2,y1,y2=%e,%e,%e,%e",fXhit,fYhit,x,y,x1,x2,y1,y2));
378 }
379
380 //_____________________________________________________________________________
381 Int_t
382 AliMUONSt345SlatSegmentationV2::ISector()
383 {
384   // FIXME: remove the usage of ISector from all the code.
385   return -10;
386 }
387
388 //_____________________________________________________________________________
389 Int_t
390 AliMUONSt345SlatSegmentationV2::Ix()
391 {
392   if ( fPadIterator )
393         {
394                 return fPadIterator->CurrentItem().GetIndices().GetFirst();
395         }
396   else
397         {
398                 return -1;
399         }
400 }
401
402 //_____________________________________________________________________________
403 Int_t
404 AliMUONSt345SlatSegmentationV2::Iy()
405 {
406   if ( fPadIterator ) 
407         {
408                 return fPadIterator->CurrentItem().GetIndices().GetSecond();
409         }
410   else
411         {
412                 return -1;
413         }
414 }
415
416 //_____________________________________________________________________________
417 Int_t
418 AliMUONSt345SlatSegmentationV2::MorePads()
419 {
420   return (fPadIterator && !fPadIterator->IsDone());
421 }
422
423 //_____________________________________________________________________________
424 void 
425 AliMUONSt345SlatSegmentationV2::Neighbours(Int_t iX, Int_t iY, Int_t* Nlist, 
426                                                                                                                                                                          Int_t Xlist[10], Int_t Ylist[10])
427 {
428   // Find pad at (ix,iy) for which we'll search neighbours.
429   AliMpPad pad = 
430         fSlatSegmentation->PadByIndices(AliMpIntPair(iX,iY),kTRUE);
431         
432   // Define the region to look into : a region slightly bigger
433   // than the pad itself (5% bigger), in order to catch first neighbours.
434
435   AliMpArea area(pad.Position(),pad.Dimensions()*1.05); 
436                 
437   AliMpVPadIterator* it = fSlatSegmentation->CreateIterator(area);
438   it->First();
439   Int_t n = 0;
440   while ( !it->IsDone() && n < 10 )
441         {
442                 AliMpPad p = it->CurrentItem();
443                 if ( p != pad ) // skip self
444                 {
445                         Xlist[n] = p.GetIndices().GetFirst();
446                         Ylist[n] = p.GetIndices().GetSecond();
447                         ++n;
448                 }
449                 it->Next();
450         }
451         delete it;
452   *Nlist = n;
453 }
454
455 //_____________________________________________________________________________
456 void
457 AliMUONSt345SlatSegmentationV2::NextPad()
458 {
459   if ( fPadIterator )
460         {
461                 fPadIterator->Next();
462                 fCurrentPad = fPadIterator->CurrentItem();
463         }
464   else
465         {
466                 AliError("PadIterator not initialized. Please use First() first ;-)");
467         }
468 }
469
470 //_____________________________________________________________________________
471 Int_t
472 AliMUONSt345SlatSegmentationV2::Npx() const
473 {
474   return fSlatSegmentation->MaxPadIndexX()+1;
475 }
476
477 //_____________________________________________________________________________
478 Int_t
479 AliMUONSt345SlatSegmentationV2::Npy() const
480 {
481   return fSlatSegmentation->MaxPadIndexY()+1;
482 }
483
484 //_____________________________________________________________________________
485 void
486 AliMUONSt345SlatSegmentationV2::Print(Option_t*) const
487 {
488   cout << "DetElemId=" << fDetElemId << " PlaneType=" 
489   << fPlaneType << " Npx,Npy=" << Npx() << "," << Npy() << " fSlat=" << fSlat 
490   << " fSlatSegmentation=" << fSlatSegmentation
491   << " fSlatSegmentation->Slat()=" << fSlatSegmentation->Slat() << endl;
492 }
493
494 //_____________________________________________________________________________
495 Int_t
496 AliMUONSt345SlatSegmentationV2::Sector(Int_t ix, Int_t)
497 {
498   return fSlat->FindPCBIndex(ix);
499 }
500
501 //_____________________________________________________________________________
502 Int_t
503 AliMUONSt345SlatSegmentationV2::Sector(Float_t x, Float_t y)
504 {
505   return fSlat->FindPCBIndex(x,y);
506 }
507
508 //_____________________________________________________________________________
509 void
510 AliMUONSt345SlatSegmentationV2::SetCorrFunc(Int_t,TF1*)
511 {
512   AliFatal("Not Implemented");
513 }
514
515 //_____________________________________________________________________________
516 void
517 AliMUONSt345SlatSegmentationV2::SetDAnod(float)
518 {
519   AliFatal("Not Implemented");
520 }
521
522 //_____________________________________________________________________________
523 void
524 AliMUONSt345SlatSegmentationV2::SetHit(Float_t x, Float_t y, Float_t)
525 {
526   fXhit = x;
527   fYhit = y;
528         
529   //
530   // insure we're within the slat limits. If not, issue a simple
531   // warning, as this might be correct (due to clustering/fitting algorithm
532   // that is allowed to go a little bit outside limits).
533   // That should only be considered an error in case the point is way
534   // outside (but by how much is the question you'll have to determine
535   // by yourself...)
536   //
537   if ( fXhit < -fSlat->DX() || fXhit > fSlat->DX() ||
538        fYhit < -fSlat->DY() || fYhit > fSlat->DY() )
539         {
540     Double_t DX = - fSlat->DX() + TMath::Abs(fXhit);
541     Double_t DY = - fSlat->DY() + TMath::Abs(fYhit);
542     DX = ( DX > 0 ? DX : 0);
543     DY = ( DY > 0 ? DY : 0);
544                 AliWarning(Form("Hit outside slat %s limits (x,y)hit = (%e,%e). "
545                     "Outside by (%e,%e) cm. Might be ok though.",
546                     fSlat->GetID(),fXhit,fYhit,DX,DY));
547         }  
548 }
549
550 //_____________________________________________________________________________
551 void
552 AliMUONSt345SlatSegmentationV2::SetPad(Int_t ix, Int_t iy)
553 {
554   fCurrentPad = 
555         fSlatSegmentation->PadByIndices(AliMpIntPair(ix,iy),kTRUE);
556   if ( !fCurrentPad.IsValid() )
557         {
558                 AliError(Form("Setting current pad to invalid ! (ix,iy)=(%4d,%4d)",ix,iy));
559         }
560 }
561
562 //_____________________________________________________________________________
563 void
564 AliMUONSt345SlatSegmentationV2::SetPadSize(float,float)
565 {
566   AliFatal("Not Implemented");
567 }
568
569 //_____________________________________________________________________________
570 Int_t 
571 AliMUONSt345SlatSegmentationV2::SigGenCond(Float_t,Float_t,Float_t)
572 {
573   AliFatal("Not Implemented");
574   return 0;
575 }
576
577 //_____________________________________________________________________________
578 void 
579 AliMUONSt345SlatSegmentationV2::SigGenInit(Float_t,Float_t,Float_t)
580 {
581   AliFatal("Not Implemented");
582 }