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)
73 fTransformations = GenerateTransformations(explodedView);
74 AliMUONManuContourMaker manuMaker(fTransformations);
75 TObjArray* manus = manuMaker.GenerateManuContours(kTRUE);
78 manus->SetOwner(kFALSE);
79 GenerateAllContours(*manus);
84 //_____________________________________________________________________________
85 AliMUONContourHandler::~AliMUONContourHandler()
88 delete fAllContourMap;
89 delete fAllContourArray;
92 //______________________________________________________________________________
94 AliMUONContourHandler::Adopt(AliMUONContour* contour)
96 /// Adopt the given contour
97 if ( GetContour(contour->GetName()) )
99 // contour already exists
102 fAllContourMap->Add(new TObjString(contour->GetName()),contour);
106 //______________________________________________________________________________
108 AliMUONContourHandler::CreateContourList(const TObjArray& manuContours)
110 /// Create an array of maps of contour names
112 /// Assyming that key is something like station#/chamber#/de#/buspatch#/manu#
113 /// the idea here is to put one TMap for each level in mapArray :
115 /// mapArray[0].key = station0
116 /// mapArray[0].value = map of strings { station0/chamber0, station0/chamber1 }
118 /// Then each entry in mapArray will be converted into a contour by
119 /// merging its children (e.g. station0 contour will be made from the merging
120 /// of station0/chamber0 and station0/chamber1 in the example above).
123 AliCodeTimerAuto("",0);
125 TIter next(&manuContours);
126 AliMUONContour* contour;
127 TObjArray* mapArray = new TObjArray;
129 while ( ( contour = static_cast<AliMUONContour*>(next()) ) )
131 // Key is something like station#/chamber#/de#/buspatch#/manu#
133 TString key(contour->GetName());
134 TObjArray* s = key.Tokenize("/");
135 for ( Int_t i = 0; i < s->GetLast(); ++i )
137 TMap* m = static_cast<TMap*>(mapArray->At(i));
141 if ( i > mapArray->GetSize() ) mapArray->Expand(i);
142 mapArray->AddAt(m,i);
145 for ( Int_t k = 0; k <= i; ++k )
147 TObjString* str = static_cast<TObjString*>(s->At(k));
148 parent += str->String();
149 if ( k < i ) parent += "/";
151 TString child(parent);
153 child += static_cast<TObjString*>(s->At(i+1))->String();
155 TObjArray* ma = static_cast<TObjArray*>(m->GetValue(parent.Data()));
159 m->Add(new TObjString(parent.Data()),ma);
161 TPair* p = static_cast<TPair*>(ma->FindObject(child.Data()));
164 ma->Add(new TObjString(child.Data()));
173 //______________________________________________________________________________
175 AliMUONContourHandler::GenerateAllContours(const TObjArray& manuContours)
177 /// From a map of manu contours, generate the compound contours (bp, de, etc...)
179 /// Note that manuContours should NOT be the owner of its contours,
180 /// as they are adopted by the array returned by this method.
182 AliCodeTimerAuto("",0);
184 // Get the list of contours to create
185 TObjArray* mapArray = CreateContourList(manuContours);
187 // Now loop over the mapArray to actually create the contours
188 TIter next2(mapArray,kIterBackward);
190 fAllContourMap = new TMap(20000,1);
191 fAllContourMap->SetOwnerKeyValue(kTRUE,kTRUE);
193 fAllContourArray = new TObjArray;
194 fAllContourArray->SetOwner(kFALSE); // the map is the real owner of the contours
196 TIter nextContour(&manuContours);
197 AliMUONContour* contour(0x0);
199 // start by adding the manu contours we begin with
200 while ( ( contour = static_cast<AliMUONContour*>(nextContour()) ) )
202 fAllContourMap->Add(new TObjString(contour->GetName()),contour);
205 AliMUONContourMaker maker;
207 for ( Int_t i = mapArray->GetLast(); i >= 1; --i )
208 // end at 1 to avoid merging different cathodes together, which
211 TMap* a = static_cast<TMap*>(mapArray->At(i));
214 while ( ( str = static_cast<TObjString*>(next3()) ) )
216 TObjArray* m = static_cast<TObjArray*>(a->GetValue(str->String().Data()));
219 TObjArray subcontours;
220 subcontours.SetOwner(kFALSE);
221 while ( ( k = static_cast<TObjString*>(next4()) ) )
223 contour = static_cast<AliMUONContour*>(fAllContourMap->GetValue(k->String().Data()));
226 subcontours.Add(contour);
230 AliError(Form("Did not find contour %s",k->String().Data()))
235 contour = maker.MergeContour(subcontours,str->String().Data());
242 AliError(Form("ERROR : could not merge into %s",str->String().Data()));
246 if ( contour->Area().IsValid() == kFALSE )
249 AliError(Form("ERROR : area of contour %s is invalid",str->String().Data()));
255 fAllContourMap->Add(new TObjString(str->String().Data()),contour);
256 fAllContourArray->Add(contour);
262 //_____________________________________________________________________________
264 AliMUONContourHandler::GenerateTransformations(Bool_t exploded)
266 /// Generate geometric transformations to be used to compute the contours
267 /// If exploded=kFALSE then we generate real transformations, otherwise
268 /// we generate tweaked ones that look fine on screen.
270 AliCodeTimerAuto("",0);
272 AliMUONGeometryTransformer transformer;
273 Bool_t ok = transformer.LoadGeometryData("transform.dat");
274 // transformer.LoadGeometryData("geometry.root"); //FIXME: add a protection if geometry.root file does not exist
277 cout << "ERROR : cannot get geometry !" << endl;
280 AliMpExMap* transformations = new AliMpExMap;
281 AliMpDEIterator deIt;
283 while ( !deIt.IsDone() )
285 Int_t detElemId = deIt.CurrentDEId();
286 const AliMUONGeometryDetElement* de = transformer.GetDetElement(detElemId);
288 TGeoHMatrix* matrix = static_cast<TGeoHMatrix*>(de->GetGlobalTransformation()->Clone());
292 Double_t* translation = matrix->GetTranslation();
293 Double_t xscale = 1.0;
294 Double_t yscale = 1.5;
295 Double_t shift = 5.0; // cm
297 if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStation345 )
299 translation[0] *= xscale;
300 translation[1] *= yscale;
304 Double_t xshift[] = { shift, -shift, -shift, shift };
305 Double_t yshift[] = { shift, shift, -shift, -shift };
306 Int_t ishift = detElemId % 100;
308 translation[0] += xshift[ishift];
309 translation[1] += yshift[ishift];
311 matrix->SetTranslation(translation);
313 transformations->Add(detElemId,matrix);
316 return transformations;
319 //_____________________________________________________________________________
321 AliMUONContourHandler::GetContour(const char* contourname) const
323 /// Get a given contour
324 return static_cast<AliMUONContour*>(fAllContourMap->GetValue(contourname));
327 //_____________________________________________________________________________
329 AliMUONContourHandler::Print(Option_t* /*opt*/) const
333 if ( fAllContourMap )
335 cout << Form("Contour map : collisions = %5.3f size = %d capacity = %d",
336 fAllContourMap->AverageCollisions(),
337 fAllContourMap->GetSize(),
338 fAllContourMap->Capacity()) << endl;