]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTest.cxx
adapted to new trigger output
[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()
89 {
90 /// Destructor
91
92   delete fCanvas;
93 }
94
95 //
96 // private methods
97 //
98 //_____________________________________________________________________________
99 void AliMUONTest::BuildWithMUON(const TString& configMacro)
100 {
101 /// Build segmentation via AliMUON initialisation
102
103   gAlice->Init(configMacro.Data());
104   AliMUON* muon = (AliMUON*)gAlice->GetModule("MUON");
105   if (!muon) {
106     AliFatal("MUON detector not defined.");
107     return;
108   }  
109   fkTransformer = muon->GetGeometryTransformer();
110   fSegmentation   = muon->GetSegmentation();
111 }    
112
113 //_____________________________________________________________________________
114 void AliMUONTest::BuildWithoutMUON(const TString& option)
115 {
116 /// Fill geometry from transform*.dat files and build segmentation via 
117 /// SegFactory
118
119   AliMUONSegFactory segFactory("volpaths.dat", "transform.dat");
120   fSegmentation = segFactory.CreateSegmentation(option);
121 }  
122
123
124 //
125 // public methods
126 //
127
128 //_____________________________________________________________________________
129 void AliMUONTest::PrintPadsForAll() const
130 {
131 /// Print pads for all chambers and first cathod
132
133   TStopwatch timer;
134   timer.Start();  
135
136   // Loop over chambers
137   for (Int_t iChamber=0; iChamber<AliMUONConstants::NCh(); iChamber++) {
138
139     // Loop over cathods
140     //for (Int_t cath=0; cath<2; cath++) {
141     for (Int_t cath=0; cath<1; cath++) {
142
143       cout << setw(6) << "Pads in chamber " << iChamber 
144            << " cathod " << cath << endl;
145       cout << "===================================" << endl;  
146
147       PrintPadsForSegmentation(iChamber, cath);
148     }  
149   }     
150   timer.Stop();
151   timer.Print();
152 }    
153
154 //_____________________________________________________________________________
155 void AliMUONTest::PrintPadsForSegmentation(Int_t moduleId, Int_t cath) const
156 {
157 /// Print pads for the given segmentation
158   
159   TStopwatch timer;
160   timer.Start();  
161
162   // Loop over detection elements
163   //
164   AliMpDEIterator it;
165   for ( it.First(moduleId); ! it.IsDone(); it.Next()) {
166        
167     Int_t detElemId = it.CurrentDE();       
168     cout << "Detection element id: " << detElemId << endl;
169     
170     PrintPadsForDetElement(detElemId, cath);
171   }  
172
173   timer.Stop();
174   timer.Print();
175
176    
177 //_____________________________________________________________________________
178 void AliMUONTest::PrintPadsForDetElement(Int_t detElemId, Int_t cath) const
179 {
180 /// Print global pad positions for the given detection element
181   
182   
183   // Get geometry segmentation
184   //
185   AliMUONGeometrySegmentation* segmentation 
186     = fSegmentation->GetModuleSegmentationByDEId(detElemId, cath);
187   if (!segmentation) {
188     AliErrorStream()
189       << "Segmentation for detElemId = " << detElemId << ", cath = " << cath
190       << " not defined." << endl;
191     return;
192   }  
193         
194   Int_t counter = 0;
195
196   // Loop over pads in a detection element
197   //
198   for(Int_t ix=0; ix<=segmentation->Npx(detElemId); ix++)
199     for(Int_t iy=0; iy<=segmentation->Npy(detElemId); iy++) 
200        PrintPad(counter, detElemId, ix, iy, segmentation);
201
202    
203 //_____________________________________________________________________________
204 void AliMUONTest::PrintPad(Int_t& counter,
205                            Int_t detElemId, Int_t ix, Int_t iy,
206                            AliMUONGeometrySegmentation* segmentation) const
207 {
208 /// Print global pad position for the given pad
209   
210   Float_t x, y, z;
211   Bool_t success
212     = segmentation->GetPadC(detElemId, ix, iy, x, y, z);
213   
214   cout << setw(6) << "counter " << counter++ << "   ";
215   cout << "Pad indices:  ( " << detElemId << "; " << ix << ", " << iy << " )  " ;
216
217   if (success) {
218     cout << "Pad position: ( " << x << ", " << y << ", " << z << " );  ";
219     Int_t sector = segmentation->Sector(detElemId, ix, iy);
220     Float_t dpx = segmentation->Dpx(detElemId, sector);
221     Float_t dpy = segmentation->Dpy(detElemId, sector);
222     cout << " dimensions: ( " << dpx << ", " << dpy << " )" << endl;
223   }  
224   else  {
225     counter--; 
226     cout << "... no pad " << endl; 
227   }  
228
229    
230 //_____________________________________________________________________________
231 void AliMUONTest::DrawPadsForAll() const
232 {
233 /// Draw pad for all chambers and first cathod
234
235   TStopwatch timer;
236   timer.Start();  
237
238   // Loop over chambers
239   for (Int_t iChamber=0; iChamber<AliMUONConstants::NCh(); iChamber++) {
240
241     // Loop over cathods
242     //for (Int_t cath=0; cath<2; cath++) {
243     for (Int_t cath=0; cath<1; cath++) {
244
245       cout << setw(6) << "Pads in chamber " << iChamber 
246            << " cathod " << cath << endl;
247       cout << "===================================" << endl;  
248
249       DrawPadsForSegmentation(iChamber, cath);
250     }  
251   }     
252   timer.Stop();
253   timer.Print();
254 }    
255
256 //_____________________________________________________________________________
257 void AliMUONTest::DrawPadsForSegmentation(Int_t moduleId, Int_t cath) const
258 {
259 /// Draw pads for the given segmentation
260   
261   TStopwatch timer;
262   timer.Start();  
263
264   // Loop over detection elements
265   //
266   AliMpDEIterator it;
267   for ( it.First(moduleId); ! it.IsDone(); it.Next()) {
268        
269     Int_t detElemId = it.CurrentDE();       
270     cout << "Detection element id: " << detElemId << endl;
271     
272     DrawPadsForDetElement(detElemId, cath);
273   }  
274
275   fCanvas->Update();
276   cout << "Print any key + enter to continue ..." << endl;
277   char c;
278   cin >> c;
279   fCanvas->Clear();
280
281   timer.Stop();
282   timer.Print();
283
284    
285 //_____________________________________________________________________________
286 void AliMUONTest::DrawPadsForDetElement(Int_t detElemId, Int_t cath) const
287 {
288 /// Draw pads for the given detection element
289   
290   // Get geometry segmentation
291   //
292   AliMUONGeometrySegmentation* segmentation 
293     = fSegmentation->GetModuleSegmentationByDEId(detElemId, cath);
294   if (!segmentation) {
295     AliErrorStream()
296       << "Segmentation for detElemId = " << detElemId << ", cath = " << cath
297       << " not defined." << endl;
298     return;
299   }  
300         
301   Int_t counter = 0;
302
303   // Loop over pads in a detection element
304   //
305   for(Int_t ix=0; ix<=segmentation->Npx(detElemId); ix++)
306     for(Int_t iy=0; iy<=segmentation->Npy(detElemId); iy++) 
307       DrawPad(counter, detElemId, ix, iy, segmentation);
308
309    
310 //_____________________________________________________________________________
311 void AliMUONTest::DrawPad(Int_t& counter,
312                           Int_t detElemId, Int_t ix, Int_t iy,
313                           AliMUONGeometrySegmentation* segmentation) const
314 {
315 /// Draw the given pad
316   
317   Float_t x, y, z;
318   Bool_t success
319     = segmentation->GetPadC(detElemId, ix, iy, x, y, z);
320
321   if (!success) return;  
322   
323   // PrintPad(counter,detElemId, ix, iy, segmentation); 
324
325   counter++;
326   
327   Int_t sector = segmentation->Sector(detElemId, ix, iy);
328   Float_t dpx = segmentation->Dpx(detElemId, sector);
329   Float_t dpy = segmentation->Dpy(detElemId, sector);
330
331   //printf(" ***** Pad position is ix: %d iy: %d x: %f y: %f sector: %d dpx: %f dpy: %f \n",
332   //       ix, iy, x, y, sector, dpx, dpy);
333
334   fCanvas->cd();
335   TPave* pave = new TPave(x-dpx/2., y-dpy/2., x+dpx/2., y+dpy/2., 1);
336   pave->Draw();
337
338
339 //_____________________________________________________________________________
340 void  AliMUONTest::DetElemTransforms() const
341 {
342 /// Print detection elements transformations 
343
344   // Loop over chambers
345   for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
346
347     const AliMUONGeometryModuleTransformer* kModuleTransformer 
348       = fkTransformer->GetModuleTransformer(i);
349       
350     // Loop over detection elements
351     AliMpDEIterator it;
352     for ( it.First(i); ! it.IsDone(); it.Next()) {
353        
354       Int_t detElemId = it.CurrentDE();       
355       cout << "Detection element id: " << detElemId << endl;
356         
357       Double_t x, y, z;
358       kModuleTransformer->Local2Global(detElemId, 0., 0., 0., x, y, z);
359       cout << "  Global DE position:            " 
360            <<  x << ",  " << y << ",  " << z << endl; 
361
362       Double_t x2, y2, z2;
363       kModuleTransformer->Global2Local(detElemId, 0., 0., 0., x2, y2, z2);
364       cout << "  ALIC center in the local frame: " 
365            <<  x2 << ",  " << y2 << ",  " << z2 << endl; 
366              
367       Double_t x3, y3, z3;
368       kModuleTransformer->Global2Local(detElemId, x, y, z, x3, y3, z3);
369       cout << "  Back in the local frame: " 
370            <<  x3 << ",  " << y3 << ",  " << z3 << endl;        
371       cout << endl;          
372
373       AliMUONGeometryDetElement* detElem =  
374         kModuleTransformer->GetDetElement(detElemId);
375       detElem->PrintGlobalTransform();  
376     }
377   }
378 }        
379