]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTest.cxx
- Volume name attribute replaced with volume path
[u/mrichter/AliRoot.git] / MUON / AliMUONTest.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 // $Id$
17 //
18 // Class AliMUONTest
19 // -----------------
20 // Class with functions for testing
21 //
22 // Author: Ivana Hrivnacova, IPN Orsay
23
24 #include <TStopwatch.h>
25 #include <Riostream.h>
26 #include <TH2F.h>
27 #include <TPave.h>
28 #include <TCanvas.h>
29 #include <TGeoMatrix.h>
30
31 #include "AliRun.h"
32 #include "AliLog.h"
33
34 #include "AliMUONTest.h"
35 #include "AliMUON.h"
36 #include "AliMUONConstants.h"
37 #include "AliMUONGeometryBuilder.h"
38 #include "AliMUONSt1GeometryBuilderV2.h"
39 #include "AliMUONSt2GeometryBuilderV2.h"
40 #include "AliMUONSlatGeometryBuilder.h"
41 #include "AliMUONTriggerGeometryBuilder.h"
42 #include "AliMUONSegFactory.h"
43 #include "AliMUONGeometryTransformer.h"
44 #include "AliMUONGeometryModule.h"
45 #include "AliMUONGeometryStore.h"
46 #include "AliMUONGeometryTransformer.h"
47 #include "AliMUONSegmentation.h"
48 #include "AliMUONGeometrySegmentation.h"
49
50 ClassImp(AliMUONTest)
51
52 //_____________________________________________________________________________
53   AliMUONTest::AliMUONTest(const TString& option)
54   : TObject(),
55     fkTransformer(0),
56     fSegmentation(0),
57     fCanvas(0)
58 {
59 // Standard Constructor
60 //
61
62   if ( option != "default" && 
63        option != "FactoryV2" &&
64        option != "FactoryV3" && 
65        option != "FactoryV4" && 
66        option != "new" )  
67   {
68     BuildWithMUON(option);
69   }
70   else     
71     BuildWithoutMUON(option);
72 }
73
74 //_____________________________________________________________________________
75 AliMUONTest::AliMUONTest()
76   : TObject(),
77     fkTransformer(0),
78     fSegmentation(0),
79     fCanvas(0)
80 {
81 // Default Constructor
82 //
83 }
84
85 //_____________________________________________________________________________
86 AliMUONTest::AliMUONTest(const AliMUONTest& rhs)
87  : TObject(rhs)
88 {
89 // Protected copy constructor
90
91   AliFatal("Not implemented.");
92 }
93
94 //_____________________________________________________________________________
95 AliMUONTest::~AliMUONTest()
96 {
97 // Destructor
98
99   delete fCanvas;
100 }
101
102 //_____________________________________________________________________________
103 AliMUONTest& AliMUONTest::operator = (const AliMUONTest& rhs)
104 {
105 // Protected assignement operator
106
107   if (this == &rhs) return *this;
108
109   AliFatal("Not implemented.");
110     
111   return *this;  
112 }
113
114 //
115 // private methods
116 //
117 //_____________________________________________________________________________
118 void AliMUONTest::BuildWithMUON(const TString& configMacro)
119 {
120 // Build segmentation via AliMUON initialisation
121
122   gAlice->Init(configMacro.Data());
123   AliMUON* muon = (AliMUON*)gAlice->GetModule("MUON");
124   if (!muon) {
125     AliFatal("MUON detector not defined.");
126     return;
127   }  
128   fkTransformer = muon->GetGeometryTransformer();
129   fSegmentation   = muon->GetSegmentation();
130 }    
131
132 //_____________________________________________________________________________
133 void AliMUONTest::BuildWithoutMUON(const TString& option)
134 {
135 // Fill geometry from transform*.dat files and build segmentation via 
136 // SegFactory
137
138   AliMUONSegFactory segFactory("transform.dat");
139   fSegmentation = segFactory.CreateSegmentation(option);
140 }  
141
142
143 //
144 // public methods
145 //
146
147 //_____________________________________________________________________________
148 AliMUONGeometrySegmentation* 
149 AliMUONTest::GetSegmentation(Int_t chamberId, Int_t cath)
150 {
151 // Create geometry segmentation for the specified chamber and cathod
152
153   return fSegmentation->GetModuleSegmentation(chamberId, cath);
154 }               
155
156 #include "AliMUONGeometryDetElement.h"
157 //_____________________________________________________________________________
158 void  AliMUONTest::DetElemTransforms()
159 {
160 // 
161   // Loop over chambers
162   for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
163
164     const AliMUONGeometryModuleTransformer* kModuleTransformer 
165       = fkTransformer->GetModuleTransformer(i);
166       
167     AliMUONGeometryStore* detElements 
168       = kModuleTransformer->GetDetElementStore();
169     
170     // Loop over detection elements
171     for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
172        
173       //Int_t detElemId = kModuleTransformer->GetDetElemId(j);       
174       Int_t detElemId = detElements->GetEntry(j)->GetUniqueID();       
175       cout << "Detection element Id: " << detElemId << endl;
176         
177       Double_t x, y, z;
178       kModuleTransformer->Local2Global(detElemId, 0., 0., 0., x, y, z);
179       cout << "  Global DE position:            " 
180            <<  x << ",  " << y << ",  " << z << endl; 
181
182       Double_t x2, y2, z2;
183       kModuleTransformer->Global2Local(detElemId, 0., 0., 0., x2, y2, z2);
184       cout << "  ALIC center in the local frame: " 
185            <<  x2 << ",  " << y2 << ",  " << z2 << endl; 
186              
187       Double_t x3, y3, z3;
188       kModuleTransformer->Global2Local(detElemId, x, y, z, x3, y3, z3);
189       cout << "  Back in the local frame: " 
190            <<  x3 << ",  " << y3 << ",  " << z3 << endl;        
191       cout << endl;          
192
193       AliMUONGeometryDetElement* detElem =  
194         (AliMUONGeometryDetElement*)detElements->GetEntry(j);
195       detElem->PrintGlobalTransform();  
196     }
197   }
198 }        
199
200 //_____________________________________________________________________________
201 void AliMUONTest::ForWhole(AliMUONTests testCase)
202 {
203 // Perform test for all chambers and first cathod
204
205   TStopwatch timer;
206   timer.Start();  
207
208   // Loop over chambers
209   for (Int_t iChamber=0; iChamber<AliMUONConstants::NCh(); iChamber++) {
210
211     // Loop over cathods
212     //for (Int_t cath=0; cath<2; cath++) {
213     for (Int_t cath=0; cath<1; cath++) {
214
215       AliMUONGeometrySegmentation* segmentation 
216         = GetSegmentation(iChamber, cath);
217         
218       if (!segmentation) continue;
219         
220       cout << setw(6) << "Pads in chamber " << iChamber 
221            << " cathod " << cath << endl;
222       cout << "===================================" << endl;  
223
224       ForSegmentation(testCase, segmentation);
225     }  
226   }     
227   timer.Stop();
228   timer.Print();
229 }    
230
231 //_____________________________________________________________________________
232 void AliMUONTest::ForSegmentation(AliMUONTests testCase,
233                                   AliMUONGeometrySegmentation *segmentation)
234 {
235 // Perform test for a given segmentation
236   
237   TStopwatch timer;
238   timer.Start();  
239
240   Before(testCase);
241
242   // Loop over detection elements
243   //
244   AliMUONGeometryStore* detElements 
245     = segmentation->GetTransformer()->GetDetElementStore();
246     
247   for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
248        
249     Int_t detElemId = detElements->GetEntry(j)->GetUniqueID();       
250     cout << "Detection element id: " << detElemId << endl;
251     
252     ForDetElement(testCase, detElemId, segmentation);
253   }  
254
255   After(testCase);
256
257   timer.Stop();
258   timer.Print();
259
260    
261 //_____________________________________________________________________________
262 void AliMUONTest::ForDetElement(AliMUONTests testCase,
263                                 Int_t detElemId,
264                                 AliMUONGeometrySegmentation *segmentation)
265 {
266 // Prints global pad positions for given detection element
267 // in a given geometry segmentation
268   
269   
270   Int_t counter = 0;
271
272   // Loop over pads in a detection element
273   //
274
275   for(Int_t ix=1; ix<=segmentation->Npx(detElemId); ix++)
276     for(Int_t iy=1; iy<=segmentation->Npy(detElemId); iy++) 
277     {
278        switch (testCase) {
279      
280          case kPrintPads:
281            PrintPad(counter, detElemId, ix, iy, segmentation);
282            break;
283      
284          case kDrawPads:
285            DrawPad(counter, detElemId, ix, iy, segmentation);
286            break;
287       }
288     }    
289
290    
291 //_____________________________________________________________________________
292 void AliMUONTest::Before(AliMUONTests testCase)
293 {
294 // Do some initialization if necessary
295
296   switch (testCase) {
297   
298     case kPrintPads:
299       break;
300
301     case kDrawPads:
302       if (!fCanvas) {
303         fCanvas = new TCanvas("c1","c1", 0, 0, 600, 600);
304         fCanvas->Range(-300,-300, 300, 300);
305         fCanvas->cd();
306       }  
307       break;
308   }        
309 }
310
311 //_____________________________________________________________________________
312 void AliMUONTest::After(AliMUONTests testCase)
313 {
314 // Do some cleanup if necessary
315
316   switch (testCase) {
317   
318     case kPrintPads:
319       break;
320
321     case kDrawPads:
322       fCanvas->Update();
323       cout << "Print any key + enter to continue ..." << endl;
324       char c;
325       cin >> c;
326       fCanvas->Clear();
327       break;
328   }        
329 }
330
331 //_____________________________________________________________________________
332 void AliMUONTest::PrintPad(Int_t& counter,
333                            Int_t detElemId, Int_t ix, Int_t iy,
334                            AliMUONGeometrySegmentation* segmentation)
335 {
336 // Prints global pad positions for the given pad
337   
338   Float_t x, y, z;
339   Bool_t success
340     = segmentation->GetPadC(detElemId, ix, iy, x, y, z);
341   
342   cout << setw(6) << "counter " << counter++ << "   ";
343   cout << "Pad indices:  ( " << detElemId << "; " << ix << ", " << iy << " )  " ;
344
345   if (success) {
346     cout << "Pad position: ( " << x << ", " << y << ", " << z << " );  ";
347     Int_t sector = segmentation->Sector(detElemId, ix, iy);
348     Float_t dpx = segmentation->Dpx(detElemId, sector);
349     Float_t dpy = segmentation->Dpy(detElemId, sector);
350     cout << " dimensions: ( " << dpx << ", " << dpy << " )" << endl;
351   }  
352   else  {
353     counter--; 
354     cout << "... no pad " << endl; 
355   }  
356
357    
358 //_____________________________________________________________________________
359 void AliMUONTest::DrawPad(Int_t& counter,
360                           Int_t detElemId, Int_t ix, Int_t iy,
361                           AliMUONGeometrySegmentation* segmentation)
362 {
363 // Prints global pad positions for the given pad
364   
365   Float_t x, y, z;
366   Bool_t success
367     = segmentation->GetPadC(detElemId, ix, iy, x, y, z);
368
369   if (!success) return;  
370   
371   // PrintPad(counter,detElemId, ix, iy, segmentation); 
372
373   counter++;
374   
375   Int_t sector = segmentation->Sector(detElemId, ix, iy);
376   Float_t dpx = segmentation->Dpx(detElemId, sector);
377   Float_t dpy = segmentation->Dpy(detElemId, sector);
378
379   //printf(" ***** Pad position is ix: %d iy: %d x: %f y: %f sector: %d dpx: %f dpy: %f \n",
380   //       ix, iy, x, y, sector, dpx, dpy);
381
382   if (!fCanvas) Before(kDrawPads);
383
384   fCanvas->cd();
385   TPave* pave = new TPave(x-dpx/2., y-dpy/2., x+dpx/2., y+dpy/2., 1);
386   pave->Draw();
387
388    
389 //_____________________________________________________________________________
390 void AliMUONTest::DrawSegmentation(AliMUONGeometrySegmentation *seg)
391 {
392 // TBR
393
394   // Drawing slat504
395   Int_t ix, iy, deId;
396   Float_t x, y, z;
397   Float_t dpx, dpy;
398 //   TH2F * frame = new TH2F(" "," ",10,-10.,245.,10, -5., 45.);
399 //   TH2F * frame = new TH2F(" "," ",10,-300.,300.,10, -300., 300.);
400   TH2F * frame = new TH2F(" "," ",10,-350.,350.,10, -350., 350.);
401   frame->Draw();
402 //   (new TPave(  0.,  0., 40., 40.,2))->Draw();
403 //   (new TPave( 40.,  0., 80., 40.,2))->Draw();
404 //   (new TPave( 80.,  0.,120., 40.,2))->Draw();
405 //   (new TPave(120.,  0.,160., 40.,2))->Draw();
406 //   (new TPave(160.,  0.,200., 40.,2))->Draw();
407 //   (new TPave(200.,  0.,240., 40.,2))->Draw();
408   
409   // Loop over detection elements
410   //
411   AliMUONGeometryStore* detElements 
412     = seg->GetTransformer()->GetDetElementStore();
413     
414   for (Int_t iDE=0; iDE<detElements->GetNofEntries(); iDE++) {
415     
416     deId = detElements->GetEntry(iDE)->GetUniqueID();       
417         
418     cout << "Detection element id: " << deId << endl;
419     
420     
421     //   for ( seg->FirstPad(detElementId,  0., 0., 0., 100., 100.);
422     //  seg->MorePads(detElementId); 
423     //  seg->NextPad(detElementId) ) {
424     for(ix=1; ix<=seg->Npx(deId); ix++) {
425       for(iy=1; iy<=seg->Npy(deId); iy++) {
426         
427         seg->GetPadC(deId, ix, iy, x, y, z);
428         Int_t sector = seg->Sector(deId, ix, iy);
429         dpx = seg->Dpx(deId,sector);
430         dpy = seg->Dpy(deId,sector);
431         
432         //printf(" ***** Pad position is ix: %d iy: %d x: %f y: %f sector: %d dpx: %f dpy: %f \n",ix, iy, x, y, sector, dpx, dpy);
433         (new TPave(x-dpx/2., y-dpy/2., x+dpx/2., y+dpy/2., 1))->Draw();
434       }
435       
436     }
437   }
438 }
439
440
441