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