]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometrySegmentation.cxx
cleanup
[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
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::Notify(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 (!Notify(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 (!Notify(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 (!Notify(detElemId)) return false;
216   
217   if (!fCurrentSegmentation->HasPad(xg, yg, zg)) return false;
218
219   Float_t xl, yl, zl;
220   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
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 (!Notify(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 //______________________________________________________________________________
247 void AliMUONGeometrySegmentation::Init(Int_t chamber)
248 {
249 // Initialize segmentation.
250 // Check that all detection elements have segmanetation set
251 // ---
252
253   // Loop over detection elements
254   AliMUONGeometryStore* detElements = fGeometryModule->GetDetElementStore();
255
256   for (Int_t i=0; i<detElements->GetNofEntries(); i++) {
257
258     // Get detction element Id
259     Int_t detElemId = detElements->GetEntry(i)->GetUniqueID();
260
261     // Check segmentation
262     if (! fDESegmentations->Get(detElemId) ) {
263       AliError(Form("Detection element %d has not a segmentation set.",
264                detElements->GetEntry(i)->GetUniqueID()));
265     }
266     else {              
267       // Initialize DE Segmentation
268       ((AliSegmentation*)fDESegmentations->Get(detElemId))->Init(chamber);
269     }          
270   }                
271 }
272  
273 //______________________________________________________________________________
274 Float_t AliMUONGeometrySegmentation::Dpx(Int_t detElemId) const
275 {
276 // Get pad size in x
277 // ---
278
279   if (!Notify(detElemId)) return 0.;
280   
281   return fCurrentSegmentation->Dpx();
282 }
283
284 //______________________________________________________________________________
285 Float_t AliMUONGeometrySegmentation::Dpy(Int_t detElemId) const
286 {
287 // Get pad size in y
288 // ---
289
290   if (!Notify(detElemId)) return 0.;
291
292   return fCurrentSegmentation->Dpy();
293 }
294  
295 //______________________________________________________________________________
296 Float_t AliMUONGeometrySegmentation::Dpx(Int_t detElemId, Int_t isector) const
297 {
298 // Pad size in x by sector
299 // ---
300
301   if (!Notify(detElemId)) return 0.;
302
303   return fCurrentSegmentation->Dpx(isector);
304
305
306 //______________________________________________________________________________
307 Float_t AliMUONGeometrySegmentation::Dpy(Int_t detElemId, Int_t isector) const
308 {
309 // Pad size in x, y by Sector 
310 // ---
311
312   if (!Notify(detElemId)) return 0.;
313
314   return fCurrentSegmentation->Dpy(isector);
315 }
316
317 //______________________________________________________________________________
318 Int_t AliMUONGeometrySegmentation::Npx(Int_t detElemId) const
319 {
320 // Maximum number of Pads in x
321 // ---
322
323   if (!Notify(detElemId)) return 0;
324
325   return fCurrentSegmentation->Npx();
326 }
327
328 //______________________________________________________________________________
329 Int_t AliMUONGeometrySegmentation::Npy(Int_t detElemId) const
330 {
331 // Maximum number of Pads in y
332 // ---
333
334   if (!Notify(detElemId)) return 0;
335
336   return fCurrentSegmentation->Npy();
337 }
338
339 //______________________________________________________________________________
340 void  AliMUONGeometrySegmentation::SetPad(Int_t detElemId, Int_t ix, Int_t iy)
341 {
342 // Set pad position.
343 // Sets virtual pad coordinates, needed for evaluating pad response 
344 // outside the tracking program.
345 // From AliMUONGeometrySegmentationV01.
346 // ---
347
348   if (!Notify(detElemId)) return;
349
350   fCurrentSegmentation->SetPad(ix, iy);
351 }
352
353 //______________________________________________________________________________
354 void  AliMUONGeometrySegmentation::SetHit(Int_t detElemId, 
355                                         Float_t xghit, Float_t yghit, Float_t zghit)
356 {
357 // Set hit position
358 // Sets virtual hit position, needed for evaluating pad response 
359 // outside the tracking program 
360 // From AliMUONGeometrySegmentationV01.
361
362   if (!Notify(detElemId)) return;
363
364   Float_t xl, yl, zl;
365   fCurrentDetElement->Global2Local(xghit, yghit, zghit, xl, yl, zl); 
366
367   fCurrentSegmentation->SetHit(xl, yl, zl);
368 }
369     
370 //______________________________________________________________________________
371 void  AliMUONGeometrySegmentation::FirstPad(Int_t detElemId,
372                                         Float_t xghit, Float_t yghit, Float_t zghit, 
373                                         Float_t dx, Float_t dy) 
374 {                                        
375 // Iterate over pads - initialiser
376 // ---
377
378   if (!Notify(detElemId)) return;
379
380   Float_t xl, yl, zl;
381   fCurrentDetElement->Global2Local(xghit, yghit, zghit, xl, yl, zl); 
382
383   fCurrentSegmentation->FirstPad(xl, yl, zl, dx, dy);
384 }
385  
386 //______________________________________________________________________________
387 void  AliMUONGeometrySegmentation::NextPad(Int_t detElemId)
388 {
389 // Iterate over pads - stepper
390 // ---
391
392   if (!Notify(detElemId)) return;
393   
394   fCurrentSegmentation->NextPad();
395 }
396
397 //______________________________________________________________________________
398 Int_t AliMUONGeometrySegmentation::MorePads(Int_t detElemId)
399 {
400 // Iterate over pads - condition
401 // ---
402
403   if (!Notify(detElemId)) return 0;
404   
405   return fCurrentSegmentation->MorePads();
406 }
407
408 //______________________________________________________________________________
409 Float_t AliMUONGeometrySegmentation::Distance2AndOffset(Int_t detElemId,
410                                            Int_t ix, Int_t iy, 
411                                            Float_t xg, Float_t yg,  Float_t zg,
412                                            Int_t* dummy)
413 {                                          
414 // Returns the square of the distance between 1 pad
415 // labelled by its channel numbers and a coordinate
416 // ---
417
418   if (!Notify(detElemId)) return 0.;
419
420   Float_t xl, yl, zl;
421   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
422
423   return fCurrentSegmentation->Distance2AndOffset(ix, iy, xl, yl, dummy);
424 }
425
426 //______________________________________________________________________________
427 void AliMUONGeometrySegmentation::GetNParallelAndOffset(Int_t detElemId,
428                                             Int_t ix, Int_t iy,
429                                             Int_t* nparallel, Int_t* offset)
430 {                                          
431 // Number of pads read in parallel and offset to add to x 
432 // (specific to LYON, but mandatory for display)
433 // CHECK
434 // ---
435
436   if (!Notify(detElemId)) return;
437
438   fCurrentSegmentation->GetNParallelAndOffset(ix, iy, nparallel, offset);  
439 }
440
441
442 //______________________________________________________________________________
443 void AliMUONGeometrySegmentation::Neighbours(Int_t detElemId,
444                                            Int_t ix, Int_t iy, 
445                                            Int_t* nlist, 
446                                            Int_t xlist[10], Int_t ylist[10])
447 {                                         
448 // Get next neighbours 
449 // ---
450
451   if (!Notify(detElemId)) return;
452
453   fCurrentSegmentation->Neighbours(ix, iy, nlist, xlist, ylist);
454 }
455
456 //______________________________________________________________________________
457 Int_t  AliMUONGeometrySegmentation::Ix()
458 {
459 // Current pad cursor during disintegration
460 // x, y-coordinate
461 // ---
462
463   return fCurrentSegmentation->Ix();
464 }
465
466 //______________________________________________________________________________
467 Int_t  AliMUONGeometrySegmentation::Iy()
468 {
469 // Current pad cursor during disintegration
470 // x, y-coordinate
471 // ---
472
473   return fCurrentSegmentation->Iy();
474 }
475
476 //______________________________________________________________________________
477 Int_t  AliMUONGeometrySegmentation::DetElemId()
478 {
479 // Current pad cursor during disintegration
480 // x, y-coordinate
481 // ---
482
483   return fCurrentDetElemId;
484 }
485
486 //______________________________________________________________________________
487 Int_t  AliMUONGeometrySegmentation::ISector()
488 {
489 // Current sector
490 // ---
491
492   return fCurrentSegmentation->ISector();
493 }
494
495 //______________________________________________________________________________
496 Int_t AliMUONGeometrySegmentation::Sector(Int_t detElemId, Int_t ix, Int_t iy)
497 {
498 // Calculate sector from pad coordinates
499 // ---
500
501   if (!Notify(detElemId)) return 0;
502
503   return fCurrentSegmentation->Sector(ix, iy);
504 }
505
506 //______________________________________________________________________________
507 Int_t AliMUONGeometrySegmentation::Sector(Int_t detElemId,
508                                         Float_t xg, Float_t yg, Float_t zg)
509 {
510 // Calculate sector from pad coordinates
511 // ---
512
513   if (!Notify(detElemId)) return 0;
514
515   Float_t xl, yl, zl;
516   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
517
518   return fCurrentSegmentation->Sector(xl, yl);
519 }
520
521 //______________________________________________________________________________
522 void  AliMUONGeometrySegmentation::IntegrationLimits(Int_t detElemId,
523                                         Float_t& x1, Float_t& x2,
524                                         Float_t& y1, Float_t& y2)
525 {                                                 
526 // Current integration limits 
527 // ---
528  
529   if (!Notify(detElemId)) return;
530
531   fCurrentSegmentation->IntegrationLimits(x1, x2, y1, y2);
532 }
533
534 //______________________________________________________________________________
535 Int_t AliMUONGeometrySegmentation::SigGenCond(Int_t detElemId,
536                                         Float_t xg, Float_t yg, Float_t zg)
537 {
538 // Signal Generation Condition during Stepping
539 //  0: don't generate signal
540 //  1: generate signal 
541 //  Comments: 
542 //
543 //  Crossing of pad boundary and mid plane between neighbouring wires is checked.
544 //  To correctly simulate the dependence of the spatial resolution on the angle 
545 //  of incidence signal must be generated for constant steps on 
546 //  the projection of the trajectory along the anode wire.
547 //
548 //  Signal will be generated if particle crosses pad boundary or
549 //  boundary between two wires. 
550 // ---
551
552   if (!Notify(detElemId)) return 0;
553
554   Float_t xl, yl, zl;
555   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
556
557   return fCurrentSegmentation->SigGenCond(xl, yl, zl);
558  }
559
560 //______________________________________________________________________________
561 void  AliMUONGeometrySegmentation::SigGenInit(Int_t detElemId,
562                                        Float_t xg, Float_t yg, Float_t zg)
563 {
564 // Initialise signal generation at coord (x,y,z)
565 // Initialises pad and wire position during stepping.
566 // From AliMUONGeometrySegmentationV01
567 // ---
568
569   if (!Notify(detElemId)) return;
570
571   Float_t xl, yl, zl;
572   fCurrentDetElement->Global2Local(xg, yg, zg, xl, yl, zl); 
573
574   if (!fCurrentSegmentation->HasPad(xl, yl, zl)) {
575     AliWarningStream()
576          << "No pad at " << detElemId 
577          << " global position: " << xg << "  " << yg << "  " << zg
578          << " local position: " << xl << "  " << yl << "  " << zl << endl;
579     return ;
580   }  
581
582   fCurrentSegmentation->SigGenInit(xl, yl, zl);
583 }                   
584     
585 //______________________________________________________________________________
586 void AliMUONGeometrySegmentation::GiveTestPoints(Int_t /*detElemId*/,
587                                        Int_t& /*n*/, 
588                                        Float_t* /*xg*/, Float_t* /*yg*/) const
589 {                                             
590 // Test points for auto calibration
591 // Returns test point on the pad plane.
592 // Used during determination of the segmoid correction of the COG-method
593 // From AliMUONGeometrySegmentationV01
594 // ---
595
596   // Requires change of interface
597   // to convert points from local to global we need z coordinate
598   AliError("Not implemented.");
599 }
600
601 //______________________________________________________________________________
602 void AliMUONGeometrySegmentation::Draw(Int_t detElemId, const char* opt) const
603 {
604 // Draw the segmentation zones.
605 // (Called from AliMUON::BuildGeometry)
606 // ---
607
608   if (!Notify(detElemId)) return;
609
610   fCurrentSegmentation->Draw(opt);
611 }
612
613 //______________________________________________________________________________
614 void AliMUONGeometrySegmentation::SetCorrFunc(Int_t detElemId, 
615                                               Int_t isec, TF1* func)
616 {
617 // Set the correction function.
618 // From AliMUONGeometrySegmentationV01
619 // ---
620
621   if (!Notify(detElemId)) return;
622
623   fCurrentSegmentation->SetCorrFunc(isec, func);
624 }
625
626 //______________________________________________________________________________
627 TF1* AliMUONGeometrySegmentation::CorrFunc(Int_t detElemId, Int_t isec) const
628 {
629 // Get the correction Function.
630 // From AliMUONGeometrySegmentationV01
631 // ---
632
633   if (!Notify(detElemId)) return 0;
634
635   return  fCurrentSegmentation->CorrFunc(isec);
636
637