]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTest.cxx
Using common container, as argument, for all classes (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONTest.cxx
CommitLineData
e118b27e 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>
24def874 26#include <TH2F.h>
27#include <TPave.h>
152d6f4e 28#include <TCanvas.h>
8b7981ce 29#include <TGeoMatrix.h>
e118b27e 30
31#include "AliRun.h"
e118b27e 32#include "AliLog.h"
33
34#include "AliMUONTest.h"
35#include "AliMUON.h"
36#include "AliMUONConstants.h"
8b7981ce 37#include "AliMUONGeometryBuilder.h"
38#include "AliMUONSt1GeometryBuilderV2.h"
39#include "AliMUONSt2GeometryBuilderV2.h"
40#include "AliMUONSlatGeometryBuilder.h"
41#include "AliMUONTriggerGeometryBuilder.h"
40afd6cd 42#include "AliMUONSegFactory.h"
8b7981ce 43#include "AliMUONGeometryTransformer.h"
e118b27e 44#include "AliMUONGeometryModule.h"
45#include "AliMUONGeometryStore.h"
8b7981ce 46#include "AliMUONGeometryTransformer.h"
47#include "AliMUONSegmentation.h"
e118b27e 48#include "AliMUONGeometrySegmentation.h"
e118b27e 49
50ClassImp(AliMUONTest)
51
8b7981ce 52//_____________________________________________________________________________
53 AliMUONTest::AliMUONTest(const TString& option)
152d6f4e 54 : TObject(),
8b7981ce 55 fkTransformer(0),
56 fSegmentation(0),
152d6f4e 57 fCanvas(0)
e118b27e 58{
59// Standard Constructor
60//
8b7981ce 61
62 if ( option != "default" &&
40afd6cd 63 option != "FactoryV2" &&
64 option != "FactoryV3" &&
65 option != "FactoryV4" &&
66 option != "new" )
8b7981ce 67 {
68 BuildWithMUON(option);
69 }
70 else
71 BuildWithoutMUON(option);
e118b27e 72}
73
8b7981ce 74//_____________________________________________________________________________
e118b27e 75AliMUONTest::AliMUONTest()
152d6f4e 76 : TObject(),
8b7981ce 77 fkTransformer(0),
78 fSegmentation(0),
152d6f4e 79 fCanvas(0)
e118b27e 80{
81// Default Constructor
82//
83}
84
8b7981ce 85//_____________________________________________________________________________
e118b27e 86AliMUONTest::AliMUONTest(const AliMUONTest& rhs)
87 : TObject(rhs)
88{
89// Protected copy constructor
90
91 AliFatal("Not implemented.");
92}
93
8b7981ce 94//_____________________________________________________________________________
e118b27e 95AliMUONTest::~AliMUONTest()
96{
97// Destructor
152d6f4e 98
99 delete fCanvas;
e118b27e 100}
101
8b7981ce 102//_____________________________________________________________________________
e118b27e 103AliMUONTest& 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//
152d6f4e 115// private methods
e118b27e 116//
24def874 117//_____________________________________________________________________________
8b7981ce 118void AliMUONTest::BuildWithMUON(const TString& configMacro)
24def874 119{
8b7981ce 120// Build segmentation via AliMUON initialisation
24def874 121
8b7981ce 122 gAlice->Init(configMacro.Data());
24def874 123 AliMUON* muon = (AliMUON*)gAlice->GetModule("MUON");
124 if (!muon) {
125 AliFatal("MUON detector not defined.");
8b7981ce 126 return;
24def874 127 }
8b7981ce 128 fkTransformer = muon->GetGeometryTransformer();
129 fSegmentation = muon->GetSegmentation();
130}
24def874 131
58d53b65 132//_____________________________________________________________________________
8b7981ce 133void AliMUONTest::BuildWithoutMUON(const TString& option)
58d53b65 134{
8b7981ce 135// Fill geometry from transform*.dat files and build segmentation via
136// SegFactory
58d53b65 137
40afd6cd 138 AliMUONSegFactory segFactory("transform.dat");
139 fSegmentation = segFactory.CreateSegmentation(option);
8b7981ce 140}
58d53b65 141
58d53b65 142
152d6f4e 143//
144// public methods
145//
146
8b7981ce 147//_____________________________________________________________________________
152d6f4e 148AliMUONGeometrySegmentation*
8b7981ce 149AliMUONTest::GetSegmentation(Int_t chamberId, Int_t cath)
152d6f4e 150{
151// Create geometry segmentation for the specified chamber and cathod
152
8b7981ce 153 return fSegmentation->GetModuleSegmentation(chamberId, cath);
152d6f4e 154}
8b7981ce 155
156#include "AliMUONGeometryDetElement.h"
157//_____________________________________________________________________________
152d6f4e 158void AliMUONTest::DetElemTransforms()
159{
160//
152d6f4e 161 // Loop over chambers
162 for (Int_t i=0; i<AliMUONConstants::NCh(); i++) {
163
8b7981ce 164 const AliMUONGeometryModuleTransformer* kModuleTransformer
165 = fkTransformer->GetModuleTransformer(i);
166
167 AliMUONGeometryStore* detElements
168 = kModuleTransformer->GetDetElementStore();
152d6f4e 169
170 // Loop over detection elements
171 for (Int_t j=0; j<detElements->GetNofEntries(); j++) {
172
8b7981ce 173 //Int_t detElemId = kModuleTransformer->GetDetElemId(j);
152d6f4e 174 Int_t detElemId = detElements->GetEntry(j)->GetUniqueID();
175 cout << "Detection element Id: " << detElemId << endl;
176
177 Double_t x, y, z;
8b7981ce 178 kModuleTransformer->Local2Global(detElemId, 0., 0., 0., x, y, z);
152d6f4e 179 cout << " Global DE position: "
180 << x << ", " << y << ", " << z << endl;
181
182 Double_t x2, y2, z2;
8b7981ce 183 kModuleTransformer->Global2Local(detElemId, 0., 0., 0., x2, y2, z2);
152d6f4e 184 cout << " ALIC center in the local frame: "
185 << x2 << ", " << y2 << ", " << z2 << endl;
186
187 Double_t x3, y3, z3;
8b7981ce 188 kModuleTransformer->Global2Local(detElemId, x, y, z, x3, y3, z3);
152d6f4e 189 cout << " Back in the local frame: "
190 << x3 << ", " << y3 << ", " << z3 << endl;
191 cout << endl;
8b7981ce 192
193 AliMUONGeometryDetElement* detElem =
194 (AliMUONGeometryDetElement*)detElements->GetEntry(j);
195 detElem->PrintGlobalTransform();
152d6f4e 196 }
24def874 197 }
152d6f4e 198}
199
8b7981ce 200//_____________________________________________________________________________
152d6f4e 201void AliMUONTest::ForWhole(AliMUONTests testCase)
202{
203// Perform test for all chambers and first cathod
204
152d6f4e 205 TStopwatch timer;
206 timer.Start();
207
208 // Loop over chambers
580c28fd 209 for (Int_t iChamber=0; iChamber<AliMUONConstants::NCh(); iChamber++) {
152d6f4e 210
211 // Loop over cathods
d640924e 212 //for (Int_t cath=0; cath<2; cath++) {
213 for (Int_t cath=0; cath<1; cath++) {
152d6f4e 214
215 AliMUONGeometrySegmentation* segmentation
8b7981ce 216 = GetSegmentation(iChamber, cath);
152d6f4e 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);
152d6f4e 225 }
226 }
227 timer.Stop();
228 timer.Print();
229}
230
8b7981ce 231//_____________________________________________________________________________
152d6f4e 232void 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
8b7981ce 245 = segmentation->GetTransformer()->GetDetElementStore();
152d6f4e 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();
24def874 259}
152d6f4e 260
8b7981ce 261//_____________________________________________________________________________
152d6f4e 262void 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
8b7981ce 291//_____________________________________________________________________________
152d6f4e 292void 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
8b7981ce 311//_____________________________________________________________________________
152d6f4e 312void 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
8b7981ce 331//_____________________________________________________________________________
152d6f4e 332void 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
152d6f4e 342 cout << setw(6) << "counter " << counter++ << " ";
343 cout << "Pad indices: ( " << detElemId << "; " << ix << ", " << iy << " ) " ;
580c28fd 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 }
152d6f4e 356}
357
8b7981ce 358//_____________________________________________________________________________
152d6f4e 359void 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
6b1e4b22 382 if (!fCanvas) Before(kDrawPads);
383
152d6f4e 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
8b7981ce 389//_____________________________________________________________________________
f48459ab 390void AliMUONTest::DrawSegmentation(AliMUONGeometrySegmentation *seg)
152d6f4e 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.);
f48459ab 399// TH2F * frame = new TH2F(" "," ",10,-300.,300.,10, -300., 300.);
65bcb249 400 TH2F * frame = new TH2F(" "," ",10,-350.,350.,10, -350., 350.);
152d6f4e 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
f48459ab 409 // Loop over detection elements
410 //
411 AliMUONGeometryStore* detElements
8b7981ce 412 = seg->GetTransformer()->GetDetElementStore();
f48459ab 413
414 for (Int_t iDE=0; iDE<detElements->GetNofEntries(); iDE++) {
152d6f4e 415
f48459ab 416 deId = detElements->GetEntry(iDE)->GetUniqueID();
65bcb249 417
f48459ab 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++) {
152d6f4e 426
f48459ab 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);
152d6f4e 431
f48459ab 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();
152d6f4e 434 }
f48459ab 435
152d6f4e 436 }
437 }
438}
439
58d53b65 440
441