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