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