]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometrySegmentation.cxx
In GetPadC - update the coordinates with big values
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometrySegmentation.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 // Class AliMUONGeometrySegmentation
18 // -------------------------------
19 // New class for the module segmentation 
20 // composed of the segmentations of detection elements.
21 // Applies transformations defined in geometry.
22 //
23 // Author:Ivana Hrivnacova, IPN Orsay
24
25 /* $Id$ */
26
27 #include <Riostream.h>
28 #include "TClass.h"
29
30 #include "AliLog.h"
31
32 #include "AliMUONGeometrySegmentation.h"
33 #include "AliMUONVGeometryDESegmentation.h"
34 #include "AliMUONGeometryModule.h"
35 #include "AliMUONGeometryDetElement.h"
36 #include "AliMUONGeometryStore.h"
37
38 ClassImp(AliMUONGeometrySegmentation)
39
40 const Float_t  AliMUONGeometrySegmentation::fgkMaxDistance = 1.0e11;
41
42 //______________________________________________________________________________
43 AliMUONGeometrySegmentation::AliMUONGeometrySegmentation(
44                                   AliMUONGeometryModule* geometry) 
45 : TObject(),
46   fCurrentDetElemId(0),
47   fCurrentDetElement(0),
48   fCurrentSegmentation(0),
49   fGeometryModule(geometry),
50   fDESegmentations(0)
51   
52 {
53 /// Standard constructor
54
55   fDESegmentations 
56     = new AliMUONGeometryStore(geometry->GetDEIndexing(), false);
57 }
58
59 //______________________________________________________________________________
60 AliMUONGeometrySegmentation::AliMUONGeometrySegmentation() 
61 : TObject(),
62   fCurrentDetElemId(0),
63   fCurrentDetElement(0),
64   fCurrentSegmentation(0),
65   fGeometryModule(0),
66   fDESegmentations(0)
67 {
68 /// Default Constructor
69 }
70
71 //______________________________________________________________________________
72 AliMUONGeometrySegmentation::AliMUONGeometrySegmentation(
73                                   const AliMUONGeometrySegmentation& rhs) 
74   : TObject(rhs)
75 {
76 /// Protected copy constructor
77
78   AliFatal("Copy constructor is not implemented.");
79 }
80
81 //______________________________________________________________________________
82 AliMUONGeometrySegmentation::~AliMUONGeometrySegmentation() 
83 {
84 /// Destructor
85
86   delete fDESegmentations;
87
88
89 //
90 // operators
91 //
92
93 //______________________________________________________________________________
94 AliMUONGeometrySegmentation& 
95 AliMUONGeometrySegmentation::operator=(const AliMUONGeometrySegmentation& rhs)
96 {
97 /// Protected assignment operator 
98
99   // check assignement to self
100   if (this == &rhs) return *this;
101
102   AliFatal("Assignment operator is not implemented.");
103     
104   return *this;  
105 }
106
107 //
108 // private methods
109 //
110
111 //______________________________________________________________________________
112 Bool_t AliMUONGeometrySegmentation::OwnNotify(Int_t detElemId) const
113 {
114 /// Update current detection element and segmentation,
115 /// and checks if they exist.
116 /// Return true if success.
117
118   if (detElemId != fCurrentDetElemId) {
119
120     // Find detection element and its segmentation
121     AliMUONGeometryDetElement* detElement
122       = fGeometryModule->GetDetElement(detElemId);
123     if (!detElement) {
124       AliError(Form("Detection element %d not defined", detElemId));
125       return false;
126     }     
127
128     AliMUONVGeometryDESegmentation* segmentation 
129       = (AliMUONVGeometryDESegmentation*) fDESegmentations->Get(detElemId);
130     if (!segmentation) {
131       AliError(Form("Segmentation for detection element %d not defined",
132                      detElemId));
133       return false;                  
134     }
135   
136     fCurrentDetElemId = detElemId;
137     fCurrentDetElement = detElement;
138     fCurrentSegmentation = segmentation;
139   }  
140  
141   return true;
142 }         
143
144 //
145 // public methods
146 //
147
148 //______________________________________________________________________________
149 void AliMUONGeometrySegmentation::Add(Int_t detElemId, 
150                                       AliMUONVGeometryDESegmentation* segmentation)
151 {
152 /// Add detection element segmentation
153
154   fDESegmentations->Add(detElemId, segmentation); 
155 }  
156
157
158 //______________________________________________________________________________
159 const AliMUONVGeometryDESegmentation* 
160 AliMUONGeometrySegmentation::GetDESegmentation(Int_t detElemId) const
161 {
162 /// Return the DE segmentation 
163
164   if (!OwnNotify(detElemId)) return 0;
165
166   return fCurrentSegmentation;
167 }
168
169 //______________________________________________________________________________
170 AliMUONGeometryDirection 
171 AliMUONGeometrySegmentation::GetDirection(Int_t detElemId) const
172 {
173 /// Return direction with a constant pad size 
174 /// (Direction or coordinate where the resolution is the best)
175
176   if (!OwnNotify(detElemId)) return kDirUndefined;
177
178   return fCurrentSegmentation->GetDirection();
179 }
180
181 //______________________________________________________________________________
182 void AliMUONGeometrySegmentation::Print(Option_t* opt) const
183 {
184 // Print DE segmentations
185
186   std::cout << "fDESegmentations (class " 
187             << fDESegmentations->Class()->GetName() << ") entries=" 
188             << fDESegmentations->GetNofEntries() 
189             << std::endl;
190   fDESegmentations->Print(opt); 
191 }
192
193 //______________________________________________________________________________
194 void AliMUONGeometrySegmentation::SetPadSize(Float_t p1, Float_t p2)
195 {
196 /// Set pad size Dx*Dy to all detection element segmentations 
197
198   for (Int_t i=0; i<fDESegmentations->GetNofEntries(); i++) {
199      AliMUONVGeometryDESegmentation* segmentation
200        = (AliMUONVGeometryDESegmentation*)fDESegmentations->GetEntry(i);
201      segmentation->SetPadSize(p1, p2);
202   }   
203 }
204
205 //______________________________________________________________________________
206 void AliMUONGeometrySegmentation::SetDAnod(Float_t d)
207 {
208 /// Set anod pitch to all detection element segmentations
209
210   for (Int_t i=0; i<fDESegmentations->GetNofEntries(); i++) {
211      AliMUONVGeometryDESegmentation* segmentation
212        = (AliMUONVGeometryDESegmentation*)fDESegmentations->GetEntry(i);
213      segmentation->SetDAnod(d);
214   }   
215 }
216
217 //______________________________________________________________________________
218 Float_t AliMUONGeometrySegmentation::GetAnod(Int_t detElemId, Float_t xhit) const
219 {
220 /// Anod wire coordinate closest to xhit
221 /// Returns for a hit position xhit the position of the nearest anode wire
222 /// !!! xhit is understand a a distance, not as a position in the space
223 /// CHECK
224
225   if (!OwnNotify(detElemId)) return 0;
226
227   return fCurrentSegmentation->GetAnod(xhit);
228 }
229
230 //______________________________________________________________________________
231 Bool_t  AliMUONGeometrySegmentation::GetPadI(Int_t detElemId,
232                                         Float_t xg, Float_t yg, Float_t zg, 
233                                         Int_t& ix, Int_t& iy)
234 {                                       
235 /// Return pad coordinates (ix,iy) for given real coordinates (x,y)
236
237   if (!OwnNotify(detElemId)) return false;
238   
239   Float_t xl, yl, zl;
240   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
241
242   if (!fCurrentSegmentation->HasPad(xl, yl, zl)) return false;
243
244   fCurrentSegmentation->GetPadI(xl, yl, zl, ix, iy);
245   return true;
246 }
247
248 //______________________________________________________________________________
249 Bool_t
250 AliMUONGeometrySegmentation::HasPad(Int_t detElemId, Int_t ix, Int_t iy)
251 {
252 // Tells if a given pad exists in a given detector element
253
254   if (!OwnNotify(detElemId)) return false;
255         
256   return fCurrentSegmentation->HasPad(ix,iy);
257 }
258                                     
259 //______________________________________________________________________________
260 Bool_t  
261 AliMUONGeometrySegmentation::GetPadC(Int_t detElemId,
262                                      Int_t ix, Int_t iy, 
263                                      Float_t& xg, Float_t& yg, Float_t& zg)
264 {                                       
265 /// Transform from pad to real coordinates
266
267   if (!OwnNotify(detElemId)) return false;
268  
269   if (!fCurrentSegmentation->HasPad(ix, iy)) {
270     xg = yg = zg = fgkMaxDistance;
271     return false;
272   }
273   
274   Float_t xl, yl, zl;
275   fCurrentSegmentation->GetPadC(ix, iy, xl , yl, zl);
276
277   fGeometryModule->Local2Global(detElemId, xl, yl, zl, xg, yg, zg); 
278   return true;
279 }
280
281 //______________________________________________________________________________
282 void AliMUONGeometrySegmentation::Init(Int_t chamber)
283 {
284 /// Initialize segmentation.
285 /// Check that all detection elements have segmanetation set
286
287   // Loop over detection elements
288   AliMUONGeometryStore* detElements = fGeometryModule->GetDetElementStore();
289
290   for (Int_t i=0; i<detElements->GetNofEntries(); i++) {
291
292     // Get detction element Id
293     Int_t detElemId = detElements->GetEntry(i)->GetUniqueID();
294
295     // Check segmentation
296     if (! fDESegmentations->Get(detElemId) ) {
297       AliError(Form("Detection element %d has not a segmentation set.",
298                detElements->GetEntry(i)->GetUniqueID()));
299     }
300     else {              
301       // Initialize DE Segmentation
302       ((AliSegmentation*)fDESegmentations->Get(detElemId))->Init(chamber);
303     }          
304   }                
305 }
306  
307 //______________________________________________________________________________
308 Float_t AliMUONGeometrySegmentation::Dpx(Int_t detElemId) const
309 {
310 /// Get pad size in x
311
312   if (!OwnNotify(detElemId)) return 0.;
313   
314   return fCurrentSegmentation->Dpx();
315 }
316
317 //______________________________________________________________________________
318 Float_t AliMUONGeometrySegmentation::Dpy(Int_t detElemId) const
319 {
320 /// Get pad size in y
321
322   if (!OwnNotify(detElemId)) return 0.;
323
324   return fCurrentSegmentation->Dpy();
325 }
326  
327 //______________________________________________________________________________
328 Float_t AliMUONGeometrySegmentation::Dpx(Int_t detElemId, Int_t isector) const
329 {
330 /// Pad size in x by sector
331
332   if (!OwnNotify(detElemId)) return 0.;
333
334   return fCurrentSegmentation->Dpx(isector);
335
336
337 //______________________________________________________________________________
338 Float_t AliMUONGeometrySegmentation::Dpy(Int_t detElemId, Int_t isector) const
339 {
340 /// Pad size in x, y by Sector 
341
342   if (!OwnNotify(detElemId)) return 0.;
343
344   return fCurrentSegmentation->Dpy(isector);
345 }
346
347 //______________________________________________________________________________
348 Int_t AliMUONGeometrySegmentation::Npx(Int_t detElemId) const
349 {
350 /// Maximum number of Pads in x
351
352   if (!OwnNotify(detElemId)) return 0;
353
354   return fCurrentSegmentation->Npx();
355 }
356
357 //______________________________________________________________________________
358 Int_t AliMUONGeometrySegmentation::Npy(Int_t detElemId) const
359 {
360 /// Maximum number of Pads in y
361
362   if (!OwnNotify(detElemId)) return 0;
363
364   return fCurrentSegmentation->Npy();
365 }
366
367 //______________________________________________________________________________
368 void  AliMUONGeometrySegmentation::SetPad(Int_t detElemId, Int_t ix, Int_t iy)
369 {
370 /// Set pad position.
371 /// Sets virtual pad coordinates, needed for evaluating pad response 
372 /// outside the tracking program.
373 /// From AliMUONGeometrySegmentationV01.
374
375   if (!OwnNotify(detElemId)) return;
376
377   fCurrentSegmentation->SetPad(ix, iy);
378 }
379
380 //______________________________________________________________________________
381 void  AliMUONGeometrySegmentation::SetHit(Int_t detElemId, 
382                                         Float_t xghit, Float_t yghit, Float_t zghit)
383 {
384 /// Set hit position
385 /// Sets virtual hit position, needed for evaluating pad response 
386 /// outside the tracking program 
387 /// From AliMUONGeometrySegmentationV01.
388
389   if (!OwnNotify(detElemId)) return;
390
391   Float_t xl, yl, zl;
392   fCurrentDetElement->Global2Local(xghit, yghit, zghit, xl, yl, zl); 
393
394   fCurrentSegmentation->SetHit(xl, yl, zl);
395 }
396     
397 //______________________________________________________________________________
398 void  AliMUONGeometrySegmentation::FirstPad(Int_t detElemId,
399                                         Float_t xghit, Float_t yghit, Float_t zghit, 
400                                         Float_t dx, Float_t dy) 
401 {                                        
402 /// Iterate over pads - initialiser
403
404   if (!OwnNotify(detElemId)) return;
405
406   Float_t xl, yl, zl;
407   fCurrentDetElement->Global2Local(xghit, yghit, zghit, xl, yl, zl); 
408
409   fCurrentSegmentation->FirstPad(xl, yl, zl, dx, dy);
410 }
411  
412 //______________________________________________________________________________
413 void  AliMUONGeometrySegmentation::NextPad(Int_t detElemId)
414 {
415 /// Iterate over pads - stepper
416
417   if (!OwnNotify(detElemId)) return;
418   
419   fCurrentSegmentation->NextPad();
420 }
421
422 //______________________________________________________________________________
423 Int_t AliMUONGeometrySegmentation::MorePads(Int_t detElemId)
424 {
425 /// Iterate over pads - condition
426
427   if (!OwnNotify(detElemId)) return 0;
428   
429   return fCurrentSegmentation->MorePads();
430 }
431
432 //______________________________________________________________________________
433 Float_t AliMUONGeometrySegmentation::Distance2AndOffset(Int_t detElemId,
434                                            Int_t ix, Int_t iy, 
435                                            Float_t xg, Float_t yg,  Float_t zg,
436                                            Int_t* dummy)
437 {                                          
438 /// Return the square of the distance between 1 pad
439 /// labelled by its channel numbers and a coordinate
440
441   if (!OwnNotify(detElemId)) return 0.;
442
443   Float_t xl, yl, zl;
444   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
445
446   return fCurrentSegmentation->Distance2AndOffset(ix, iy, xl, yl, dummy);
447 }
448
449 //______________________________________________________________________________
450 void AliMUONGeometrySegmentation::GetNParallelAndOffset(Int_t detElemId,
451                                             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 /// CHECK
457
458   if (!OwnNotify(detElemId)) return;
459
460   fCurrentSegmentation->GetNParallelAndOffset(ix, iy, nparallel, offset);  
461 }
462
463
464 //______________________________________________________________________________
465 void AliMUONGeometrySegmentation::Neighbours(Int_t detElemId,
466                                            Int_t ix, Int_t iy, 
467                                            Int_t* nlist, 
468                                            Int_t xlist[10], Int_t ylist[10])
469 {                                         
470 /// Get next neighbours 
471
472   if (!OwnNotify(detElemId)) return;
473
474   fCurrentSegmentation->Neighbours(ix, iy, nlist, xlist, ylist);
475 }
476
477 //______________________________________________________________________________
478 Int_t  AliMUONGeometrySegmentation::Ix()
479 {
480 /// Current pad cursor during disintegration
481 /// x, y-coordinate
482
483   return fCurrentSegmentation->Ix();
484 }
485
486 //______________________________________________________________________________
487 Int_t  AliMUONGeometrySegmentation::Iy()
488 {
489 /// Current pad cursor during disintegration
490 /// x, y-coordinate
491
492   return fCurrentSegmentation->Iy();
493 }
494
495 //______________________________________________________________________________
496 Int_t  AliMUONGeometrySegmentation::DetElemId()
497 {
498 /// Current pad cursor during disintegration
499 /// x, y-coordinate
500
501   return fCurrentDetElemId;
502 }
503
504 //______________________________________________________________________________
505 Int_t  AliMUONGeometrySegmentation::ISector()
506 {
507 /// Current sector
508
509   return fCurrentSegmentation->ISector();
510 }
511
512 //______________________________________________________________________________
513 Int_t AliMUONGeometrySegmentation::Sector(Int_t detElemId, Int_t ix, Int_t iy)
514 {
515 /// Calculate sector from pad coordinates
516
517   if (!OwnNotify(detElemId)) return 0;
518
519   return fCurrentSegmentation->Sector(ix, iy);
520 }
521
522 //______________________________________________________________________________
523 Int_t AliMUONGeometrySegmentation::Sector(Int_t detElemId,
524                                         Float_t xg, Float_t yg, Float_t zg)
525 {
526 /// Calculate sector from pad coordinates
527
528   if (!OwnNotify(detElemId)) return 0;
529
530   Float_t xl, yl, zl;
531   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
532
533   return fCurrentSegmentation->Sector(xl, yl);
534 }
535
536 //______________________________________________________________________________
537 void  AliMUONGeometrySegmentation::IntegrationLimits(Int_t detElemId,
538                                         Float_t& x1, Float_t& x2,
539                                         Float_t& y1, Float_t& y2)
540 {                                                 
541 /// Current integration limits 
542  
543   if (!OwnNotify(detElemId)) return;
544
545   fCurrentSegmentation->IntegrationLimits(x1, x2, y1, y2);
546 }
547
548 //______________________________________________________________________________
549 Int_t AliMUONGeometrySegmentation::SigGenCond(Int_t detElemId,
550                                         Float_t xg, Float_t yg, Float_t zg)
551 {
552 /// Signal Generation Condition during Stepping
553 ///  0: don't generate signal                                                 \n
554 ///  1: generate signal                                                       \n
555 ///  Comments:                                                                \n
556 ///                                                                           \n
557 ///  Crossing of pad boundary and mid plane between neighbouring wires is checked.
558 ///  To correctly simulate the dependence of the spatial resolution on the angle 
559 ///  of incidence signal must be generated for constant steps on 
560 ///  the projection of the trajectory along the anode wire.
561 ///                                                                           \n
562 ///  Signal will be generated if particle crosses pad boundary or
563 ///  boundary between two wires. 
564
565   if (!OwnNotify(detElemId)) return 0;
566
567   Float_t xl, yl, zl;
568   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
569
570   return fCurrentSegmentation->SigGenCond(xl, yl, zl);
571  }
572
573 //______________________________________________________________________________
574 void  AliMUONGeometrySegmentation::SigGenInit(Int_t detElemId,
575                                        Float_t xg, Float_t yg, Float_t zg)
576 {
577 /// Initialise signal generation at coord (x,y,z)
578 /// Initialise pad and wire position during stepping.
579 /// From AliMUONGeometrySegmentationV01
580
581   if (!OwnNotify(detElemId)) return;
582
583   Float_t xl, yl, zl;
584   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
585
586   if (!fCurrentSegmentation->HasPad(xl, yl, zl)) {
587     AliWarningStream()
588          << "No pad at " << detElemId 
589          << " global position: " << xg << "  " << yg << "  " << zg
590          << " local position: " << xl << "  " << yl << "  " << zl << endl;
591     return ;
592   }  
593
594   fCurrentSegmentation->SigGenInit(xl, yl, zl);
595 }                   
596     
597 //______________________________________________________________________________
598 void AliMUONGeometrySegmentation::GiveTestPoints(Int_t /*detElemId*/,
599                                        Int_t& /*n*/, 
600                                        Float_t* /*xg*/, Float_t* /*yg*/) const
601 {                                             
602 /// Test points for auto calibration
603 /// Return test point on the pad plane.
604 /// Used during determination of the segmoid correction of the COG-method
605 /// From AliMUONGeometrySegmentationV01
606
607   // Requires change of interface
608   // to convert points from local to global we need z coordinate
609   AliError("Not implemented.");
610 }
611
612 //______________________________________________________________________________
613 void AliMUONGeometrySegmentation::Draw(const char* opt)
614 {
615 /// Draw the segmentation zones for all detElemId 
616
617   for (Int_t i=0; i<fDESegmentations->GetNofEntries(); i++) {
618      AliMUONVGeometryDESegmentation* segmentation
619        = (AliMUONVGeometryDESegmentation*)fDESegmentations->GetEntry(i);
620      segmentation->Draw(opt);
621   }   
622 }
623
624 //______________________________________________________________________________
625 void AliMUONGeometrySegmentation::Draw(Int_t detElemId, const char* opt)
626 {
627 /// Draw the segmentation zones for a given detElemId.
628
629   if (!OwnNotify(detElemId)) return;
630
631   fCurrentSegmentation->Draw(opt);
632 }
633
634 //______________________________________________________________________________
635 void AliMUONGeometrySegmentation::SetCorrFunc(Int_t detElemId, 
636                                               Int_t isec, TF1* func)
637 {
638 /// Set the correction function.
639 /// From AliMUONGeometrySegmentationV01
640
641   if (!OwnNotify(detElemId)) return;
642
643   fCurrentSegmentation->SetCorrFunc(isec, func);
644 }
645
646 //______________________________________________________________________________
647 TF1* AliMUONGeometrySegmentation::CorrFunc(Int_t detElemId, Int_t isec) const
648 {
649 /// Get the correction Function.
650 /// From AliMUONGeometrySegmentationV01
651
652   if (!OwnNotify(detElemId)) return 0;
653
654   return  fCurrentSegmentation->CorrFunc(isec);
655
656