]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTest.cxx
Minor fixes in the event tag to take into account the new way of storing the trigger...
[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 // Author: Ivana Hrivnacova, IPN Orsay
23
24 #include "AliMUONTest.h"
25 #include "AliMUON.h"
26 #include "AliMUONConstants.h"
27 #include "AliMUONSegFactory.h"
28 #include "AliMUONGeometryTransformer.h"
29 #include "AliMUONGeometryModuleTransformer.h"
30 #include "AliMUONGeometryDetElement.h"
31 #include "AliMUONSegmentation.h"
32 #include "AliMUONGeometrySegmentation.h"
33
34 #include "AliMpDEIterator.h"
35 #include "AliMpDEManager.h"
36 #include "AliMpVSegmentation.h"
37 #include "AliMpPad.h"
38
39 #include "AliRun.h"
40 #include "AliLog.h"
41
42 #include <TStopwatch.h>
43 #include <Riostream.h>
44 #include <TH2F.h>
45 #include <TPave.h>
46 #include <TCanvas.h>
47 #include <TGeoMatrix.h>
48
49 ClassImp(AliMUONTest)
50
51 //_____________________________________________________________________________
52   AliMUONTest::AliMUONTest(const TString& option)
53   : TObject(),
54     fkTransformer(0),
55     fSegmentation(0),
56     fCanvas(0)
57 {
58 /// Standard Constructor
59
60   if ( option != "default" && 
61        option != "FactoryV2" &&
62        option != "FactoryV3" && 
63        option != "FactoryV4" && 
64        option != "new" )  
65   {
66     BuildWithMUON(option);
67   }
68   else     
69     BuildWithoutMUON(option);
70
71   // Create canvas
72   fCanvas = new TCanvas("c1","c1", 0, 0, 800, 800);
73   fCanvas->Range(-400,-400, 400, 400);
74   fCanvas->cd();
75 }
76
77 //_____________________________________________________________________________
78 AliMUONTest::AliMUONTest()
79   : TObject(),
80     fkTransformer(0),
81     fSegmentation(0),
82     fCanvas(0)
83 {
84 /// Default Constructor
85 }
86
87 //_____________________________________________________________________________
88 AliMUONTest::AliMUONTest(const AliMUONTest& rhs)
89  : TObject(rhs)
90 {
91 /// Protected copy constructor
92
93   AliFatal("Not implemented.");
94 }
95
96 //_____________________________________________________________________________
97 AliMUONTest::~AliMUONTest()
98 {
99 /// Destructor
100
101   delete fCanvas;
102 }
103
104 //_____________________________________________________________________________
105 AliMUONTest& AliMUONTest::operator = (const AliMUONTest& rhs)
106 {
107 /// Protected assignement operator
108
109   if (this == &rhs) return *this;
110
111   AliFatal("Not implemented.");
112     
113   return *this;  
114 }
115
116 //
117 // private methods
118 //
119 //_____________________________________________________________________________
120 void AliMUONTest::BuildWithMUON(const TString& configMacro)
121 {
122 /// Build segmentation via AliMUON initialisation
123
124   gAlice->Init(configMacro.Data());
125   AliMUON* muon = (AliMUON*)gAlice->GetModule("MUON");
126   if (!muon) {
127     AliFatal("MUON detector not defined.");
128     return;
129   }  
130   fkTransformer = muon->GetGeometryTransformer();
131   fSegmentation   = muon->GetSegmentation();
132 }    
133
134 //_____________________________________________________________________________
135 void AliMUONTest::BuildWithoutMUON(const TString& option)
136 {
137 /// Fill geometry from transform*.dat files and build segmentation via 
138 /// SegFactory
139
140   AliMUONSegFactory segFactory("volpaths.dat", "transform.dat");
141   fSegmentation = segFactory.CreateSegmentation(option);
142 }  
143
144
145 //
146 // public methods
147 //
148
149 //_____________________________________________________________________________
150 void AliMUONTest::PrintPadsForAll() const
151 {
152 /// Print pads for all chambers and first cathod
153
154   TStopwatch timer;
155   timer.Start();  
156
157   // Loop over chambers
158   for (Int_t iChamber=0; iChamber<AliMUONConstants::NCh(); iChamber++) {
159
160     // Loop over cathods
161     //for (Int_t cath=0; cath<2; cath++) {
162     for (Int_t cath=0; cath<1; cath++) {
163
164       cout << setw(6) << "Pads in chamber " << iChamber 
165            << " cathod " << cath << endl;
166       cout << "===================================" << endl;  
167
168       PrintPadsForSegmentation(iChamber, cath);
169     }  
170   }     
171   timer.Stop();
172   timer.Print();
173 }    
174
175 //_____________________________________________________________________________
176 void AliMUONTest::PrintPadsForSegmentation(Int_t moduleId, Int_t cath) const
177 {
178 /// Print pads for the given segmentation
179   
180   TStopwatch timer;
181   timer.Start();  
182
183   // Loop over detection elements
184   //
185   AliMpDEIterator it;
186   for ( it.First(moduleId); ! it.IsDone(); it.Next()) {
187        
188     Int_t detElemId = it.CurrentDE();       
189     cout << "Detection element id: " << detElemId << endl;
190     
191     PrintPadsForDetElement(detElemId, cath);
192   }  
193
194   timer.Stop();
195   timer.Print();
196
197    
198 //_____________________________________________________________________________
199 void AliMUONTest::PrintPadsForDetElement(Int_t detElemId, Int_t cath) const
200 {
201 /// Print global pad positions for the given detection element
202   
203   
204   // Get geometry segmentation
205   //
206   AliMUONGeometrySegmentation* segmentation 
207     = fSegmentation->GetModuleSegmentationByDEId(detElemId, cath);
208   if (!segmentation) {
209     AliErrorStream()
210       << "Segmentation for detElemId = " << detElemId << ", cath = " << cath
211       << " not defined." << endl;
212     return;
213   }  
214         
215   Int_t counter = 0;
216
217   // Loop over pads in a detection element
218   //
219   for(Int_t ix=0; ix<=segmentation->Npx(detElemId); ix++)
220     for(Int_t iy=0; iy<=segmentation->Npy(detElemId); iy++) 
221        PrintPad(counter, detElemId, ix, iy, segmentation);
222
223    
224 //_____________________________________________________________________________
225 void AliMUONTest::PrintPad(Int_t& counter,
226                            Int_t detElemId, Int_t ix, Int_t iy,
227                            AliMUONGeometrySegmentation* segmentation) const
228 {
229 /// Print global pad position for the given pad
230   
231   Float_t x, y, z;
232   Bool_t success
233     = segmentation->GetPadC(detElemId, ix, iy, x, y, z);
234   
235   cout << setw(6) << "counter " << counter++ << "   ";
236   cout << "Pad indices:  ( " << detElemId << "; " << ix << ", " << iy << " )  " ;
237
238   if (success) {
239     cout << "Pad position: ( " << x << ", " << y << ", " << z << " );  ";
240     Int_t sector = segmentation->Sector(detElemId, ix, iy);
241     Float_t dpx = segmentation->Dpx(detElemId, sector);
242     Float_t dpy = segmentation->Dpy(detElemId, sector);
243     cout << " dimensions: ( " << dpx << ", " << dpy << " )" << endl;
244   }  
245   else  {
246     counter--; 
247     cout << "... no pad " << endl; 
248   }  
249
250    
251 //_____________________________________________________________________________
252 void AliMUONTest::DrawPadsForAll() const
253 {
254 /// Draw pad for all chambers and first cathod
255
256   TStopwatch timer;
257   timer.Start();  
258
259   // Loop over chambers
260   for (Int_t iChamber=0; iChamber<AliMUONConstants::NCh(); iChamber++) {
261
262     // Loop over cathods
263     //for (Int_t cath=0; cath<2; cath++) {
264     for (Int_t cath=0; cath<1; cath++) {
265
266       cout << setw(6) << "Pads in chamber " << iChamber 
267            << " cathod " << cath << endl;
268       cout << "===================================" << endl;  
269
270       DrawPadsForSegmentation(iChamber, cath);
271     }  
272   }     
273   timer.Stop();
274   timer.Print();
275 }    
276
277 //_____________________________________________________________________________
278 void AliMUONTest::DrawPadsForSegmentation(Int_t moduleId, Int_t cath) const
279 {
280 /// Draw pads for the given segmentation
281   
282   TStopwatch timer;
283   timer.Start();  
284
285   // Loop over detection elements
286   //
287   AliMpDEIterator it;
288   for ( it.First(moduleId); ! it.IsDone(); it.Next()) {
289        
290     Int_t detElemId = it.CurrentDE();       
291     cout << "Detection element id: " << detElemId << endl;
292     
293     DrawPadsForDetElement(detElemId, cath);
294   }  
295
296   fCanvas->Update();
297   cout << "Print any key + enter to continue ..." << endl;
298   char c;
299   cin >> c;
300   fCanvas->Clear();
301
302   timer.Stop();
303   timer.Print();
304
305    
306 //_____________________________________________________________________________
307 void AliMUONTest::DrawPadsForDetElement(Int_t detElemId, Int_t cath) const
308 {
309 /// Draw pads for the given detection element
310   
311   // Get geometry segmentation
312   //
313   AliMUONGeometrySegmentation* segmentation 
314     = fSegmentation->GetModuleSegmentationByDEId(detElemId, cath);
315   if (!segmentation) {
316     AliErrorStream()
317       << "Segmentation for detElemId = " << detElemId << ", cath = " << cath
318       << " not defined." << endl;
319     return;
320   }  
321         
322   Int_t counter = 0;
323
324   // Loop over pads in a detection element
325   //
326   for(Int_t ix=0; ix<=segmentation->Npx(detElemId); ix++)
327     for(Int_t iy=0; iy<=segmentation->Npy(detElemId); iy++) 
328       DrawPad(counter, detElemId, ix, iy, segmentation);
329
330    
331 //_____________________________________________________________________________
332 void AliMUONTest::DrawPad(Int_t& counter,
333                           Int_t detElemId, Int_t ix, Int_t iy,
334                           AliMUONGeometrySegmentation* segmentation) const
335 {
336 /// Draw 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   if (!success) return;  
343   
344   // PrintPad(counter,detElemId, ix, iy, segmentation); 
345
346   counter++;
347   
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
352   //printf(" ***** Pad position is ix: %d iy: %d x: %f y: %f sector: %d dpx: %f dpy: %f \n",
353   //       ix, iy, x, y, sector, dpx, dpy);
354
355   fCanvas->cd();
356   TPave* pave = new TPave(x-dpx/2., y-dpy/2., x+dpx/2., y+dpy/2., 1);
357   pave->Draw();
358
359
360 //_____________________________________________________________________________
361 void  AliMUONTest::DetElemTransforms() const
362 {
363 /// Print detection elements transformations 
364
365   // Loop over chambers
366   for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
367
368     const AliMUONGeometryModuleTransformer* kModuleTransformer 
369       = fkTransformer->GetModuleTransformer(i);
370       
371     // Loop over detection elements
372     AliMpDEIterator it;
373     for ( it.First(i); ! it.IsDone(); it.Next()) {
374        
375       Int_t detElemId = it.CurrentDE();       
376       cout << "Detection element id: " << detElemId << endl;
377         
378       Double_t x, y, z;
379       kModuleTransformer->Local2Global(detElemId, 0., 0., 0., x, y, z);
380       cout << "  Global DE position:            " 
381            <<  x << ",  " << y << ",  " << z << endl; 
382
383       Double_t x2, y2, z2;
384       kModuleTransformer->Global2Local(detElemId, 0., 0., 0., x2, y2, z2);
385       cout << "  ALIC center in the local frame: " 
386            <<  x2 << ",  " << y2 << ",  " << z2 << endl; 
387              
388       Double_t x3, y3, z3;
389       kModuleTransformer->Global2Local(detElemId, x, y, z, x3, y3, z3);
390       cout << "  Back in the local frame: " 
391            <<  x3 << ",  " << y3 << ",  " << z3 << endl;        
392       cout << endl;          
393
394       AliMUONGeometryDetElement* detElem =  
395         kModuleTransformer->GetDetElement(detElemId);
396       detElem->PrintGlobalTransform();  
397     }
398   }
399 }        
400