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