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