1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 /// \class AliMUONContourHandler
21 /// Class used to create contours of the muon tracker parts :
22 /// manu, bus patches, detection elements, chambers.
24 /// \author Laurent Aphecetche, Subatech
27 #include "AliMUONContourHandler.h"
29 #include "AliCodeTimer.h"
31 #include "AliMUONContour.h"
32 #include "AliMUONContourMaker.h"
33 #include "AliMUONGeometryDetElement.h"
34 #include "AliMUONGeometryTransformer.h"
35 #include "AliMUONManuContourMaker.h"
36 #include "AliMUONPolygon.h"
37 #include "AliMUONSegment.h"
38 #include "AliMpArea.h"
40 #include "AliMpDDLStore.h"
41 #include "AliMpDEManager.h"
42 #include "AliMpExMap.h"
44 #include "Riostream.h"
48 #include "TGeoMatrix.h"
50 #include "TObjArray.h"
51 #include "TPolyLine.h"
55 ClassImp(AliMUONContourHandler)
58 //_____________________________________________________________________________
59 AliMUONContourHandler::AliMUONContourHandler(Bool_t explodedView)
61 fTransformations(0x0),
65 /// ctor. If explodedView=kTRUE, we generate views that will look
66 /// fine in 2D (i.e. won't show overlaps of DE as in reality)
67 /// Use kFALSE if you want realistic geometry, though.
69 /// IMPORTANT : as we many MUON classes, this one cannot work
70 /// before you've loaded the mapping in memory (see e.g. AliMpCDB::LoadDDLStore)
75 fTransformations = GenerateTransformations(explodedView);
78 AliMUONManuContourMaker manuMaker(fTransformations);
80 TObjArray* manus = manuMaker.GenerateManuContours(kTRUE);
84 manus->SetOwner(kFALSE);
85 GenerateAllContours(*manus);
90 //_____________________________________________________________________________
91 AliMUONContourHandler::~AliMUONContourHandler()
94 delete fTransformations;
95 delete fAllContourMap;
96 delete fAllContourArray;
99 //______________________________________________________________________________
101 AliMUONContourHandler::Adopt(AliMUONContour* contour)
103 /// Adopt the given contour
104 if ( GetContour(contour->GetName()) )
106 // contour already exists
109 fAllContourMap->Add(new TObjString(contour->GetName()),contour);
113 //______________________________________________________________________________
115 AliMUONContourHandler::CreateContourList(const TObjArray& manuContours)
117 /// Create an array of maps of contour names
119 /// Assyming that key is something like station#/chamber#/de#/buspatch#/manu#
120 /// the idea here is to put one TMap for each level in mapArray :
122 /// mapArray[0].key = station0
123 /// mapArray[0].value = map of strings { station0/chamber0, station0/chamber1 }
125 /// Then each entry in mapArray will be converted into a contour by
126 /// merging its children (e.g. station0 contour will be made from the merging
127 /// of station0/chamber0 and station0/chamber1 in the example above).
130 AliCodeTimerAuto("",0);
134 if ( !fTransformations )
136 start = 2; // skip chamber and station contours, as we seem to be in 3D
139 TIter next(&manuContours);
140 AliMUONContour* contour;
141 TObjArray* mapArray = new TObjArray;
143 while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
145 // Key is something like station#/chamber#/de#/buspatch#/manu#
147 TString key(contour->GetName());
148 TObjArray* s = key.Tokenize("/");
149 for ( Int_t i = start; i < s->GetLast(); ++i )
151 TMap* m = static_cast<TMap*>(mapArray->At(i));
155 if ( i > mapArray->GetSize() ) mapArray->Expand(i);
156 mapArray->AddAt(m,i);
159 for ( Int_t k = 0; k <= i; ++k )
161 TObjString* str = static_cast<TObjString*>(s->At(k));
162 parent += str->String();
163 if ( k < i ) parent += "/";
165 TString child(parent);
167 child += static_cast<TObjString*>(s->At(i+1))->String();
169 TObjArray* ma = static_cast<TObjArray*>(m->GetValue(parent.Data()));
173 m->Add(new TObjString(parent.Data()),ma);
175 TPair* p = static_cast<TPair*>(ma->FindObject(child.Data()));
178 ma->Add(new TObjString(child.Data()));
187 //______________________________________________________________________________
189 AliMUONContourHandler::GenerateAllContours(const TObjArray& manuContours)
191 /// From a map of manu contours, generate the compound contours (bp, de, etc...)
193 /// Note that manuContours should NOT be the owner of its contours,
194 /// as they are adopted by the array returned by this method.
196 AliCodeTimerAuto("",0);
198 // Get the list of contours to create
199 TObjArray* mapArray = CreateContourList(manuContours);
201 fAllContourMap = new TMap(20000,1);
202 fAllContourMap->SetOwnerKeyValue(kTRUE,kTRUE);
204 fAllContourArray = new TObjArray;
205 fAllContourArray->SetOwner(kFALSE); // the map is the real owner of the contours
207 TIter nextContour(&manuContours);
208 AliMUONContour* contour(0x0);
210 // start by adding the manu contours we begin with
211 while ( ( contour = static_cast<AliMUONContour*>(nextContour()) ) )
213 fAllContourMap->Add(new TObjString(contour->GetName()),contour);
216 AliMUONContourMaker maker;
218 for ( Int_t i = mapArray->GetLast(); i >= 1; --i )
219 // end at 1 to avoid merging different cathodes together, which
222 TMap* a = static_cast<TMap*>(mapArray->At(i));
225 while ( ( str = static_cast<TObjString*>(next3()) ) )
227 TObjArray* m = static_cast<TObjArray*>(a->GetValue(str->String().Data()));
230 TObjArray subcontours;
231 subcontours.SetOwner(kFALSE);
232 while ( ( k = static_cast<TObjString*>(next4()) ) )
234 contour = static_cast<AliMUONContour*>(fAllContourMap->GetValue(k->String().Data()));
237 subcontours.Add(contour);
241 AliError(Form("Did not find contour %s",k->String().Data()))
246 contour = maker.MergeContour(subcontours,str->String().Data());
253 AliError(Form("ERROR : could not merge into %s",str->String().Data()));
257 if ( contour->Area().IsValid() == kFALSE )
260 AliError(Form("ERROR : area of contour %s is invalid",str->String().Data()));
266 fAllContourMap->Add(new TObjString(str->String().Data()),contour);
267 fAllContourArray->Add(contour);
273 //_____________________________________________________________________________
275 AliMUONContourHandler::GenerateTransformations(Bool_t exploded)
277 /// Generate geometric transformations to be used to compute the contours
278 /// If exploded=kFALSE then we generate real transformations, otherwise
279 /// we generate tweaked ones that look fine on screen.
281 AliCodeTimerAuto("",0);
283 AliMUONGeometryTransformer transformer;
284 Bool_t ok = transformer.LoadGeometryData("transform.dat");
285 // transformer.LoadGeometryData("geometry.root"); //FIXME: add a protection if geometry.root file does not exist
288 cout << "ERROR : cannot get geometry !" << endl;
291 AliMpExMap* transformations = new AliMpExMap;
292 AliMpDEIterator deIt;
294 while ( !deIt.IsDone() )
296 Int_t detElemId = deIt.CurrentDEId();
297 const AliMUONGeometryDetElement* de = transformer.GetDetElement(detElemId);
299 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(de->GetGlobalTransformation()->Clone());
303 Double_t* translation = matrix->GetTranslation();
304 Double_t xscale = 1.0;
305 Double_t yscale = 1.5;
306 Double_t shift = 5.0; // cm
308 if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345 )
310 translation[0] *= xscale;
311 translation[1] *= yscale;
315 Double_t xshift[] = { shift, -shift, -shift, shift };
316 Double_t yshift[] = { shift, shift, -shift, -shift };
317 Int_t ishift = detElemId % 100;
319 translation[0] += xshift[ishift];
320 translation[1] += yshift[ishift];
322 matrix->SetTranslation(translation);
324 transformations->Add(detElemId,matrix);
327 return transformations;
330 //_____________________________________________________________________________
332 AliMUONContourHandler::GetContour(const char* contourname) const
334 /// Get a given contour
335 return static_cast<AliMUONContour*>(fAllContourMap->GetValue(contourname));
338 //_____________________________________________________________________________
340 AliMUONContourHandler::Print(Option_t* opt) const
344 if ( fAllContourMap )
346 cout << Form("Contour map : collisions = %5.3f size = %d capacity = %d",
347 fAllContourMap->AverageCollisions(),
348 fAllContourMap->GetSize(),
349 fAllContourMap->Capacity()) << endl;
354 if ( sopt.Contains("ALL") || sopt.Contains("FULL") )
356 fAllContourMap->Print();