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