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