]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONManuContourMaker.cxx
Macro to be attached to the analysis train
[u/mrichter/AliRoot.git] / MUON / AliMUONManuContourMaker.cxx
CommitLineData
0b936dc0 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 AliMUONManuContourMaker
19///
20/// Maker of manu contours.
21///
22/// Make use of the AliMUONContourMaker class, but this one contains
23/// specific things for MUON (as the mapping, for instance), hence its
24/// separation from AliMUONContourMaker.
25///
26/// This class requires that the mapping is loaded before anything can be done.
27///
28/// \author Laurent Aphecetche, Subatech
29
30#include "AliMUONManuContourMaker.h"
31
32#include "AliCodeTimer.h"
33#include "AliLog.h"
34#include "AliMUONContour.h"
35#include "AliMUONContourMaker.h"
36#include "AliMUONPolygon.h"
37#include "AliMpCathodType.h"
38#include "AliMpConnection.h"
39#include "AliMpConstants.h"
40#include "AliMpDDLStore.h"
41#include "AliMpDEManager.h"
42#include "AliMpIntPair.h"
43#include "AliMpMotifPosition.h"
44#include "AliMpMotifType.h"
45#include "AliMpManuIterator.h"
46#include "AliMpPlaneType.h"
47#include "AliMpSegmentation.h"
48#include "AliMpUID.h"
49#include "AliMpVMotif.h"
50#include "AliMpVSegmentation.h"
51#include "TGeoMatrix.h"
52#include "TObjArray.h"
53#include "TObjString.h"
54#include "TString.h"
55#include "TVector2.h"
56
57///\cond CLASSIMP
58ClassImp(AliMUONManuContourMaker)
59///\endcond
60
61//_____________________________________________________________________________
62AliMUONManuContourMaker::AliMUONManuContourMaker(AliMpExMap* deTransformations)
63: TObject(), fDETransformations(deTransformations), fLocalManuContours(222,1)
64{
65 fLocalManuContours.SetOwnerKeyValue(kTRUE,kTRUE);
66}
67
68//_____________________________________________________________________________
69AliMUONManuContourMaker::~AliMUONManuContourMaker()
70{
71}
72
73//_____________________________________________________________________________
74AliMUONContour*
75AliMUONManuContourMaker::CreateManuContour(Int_t detElemId, Int_t manuId, const char* name) const
76{
77 /// Create the contour of a given manu (global coordinates)
78
79 AliCodeTimerAuto("");
80
81 TString sname(name);
82
83 if ( sname.Length()==0 )
84 {
85 sname = ManuPathName(detElemId,manuId);
86 }
87
88 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
89 const AliMpMotifPosition* motifPos = seg->MotifPosition(manuId);
90
91 AliMUONContour* contour = CreateMotifContour(*motifPos);
92
93 if (!contour)
94 {
95 AliError(Form("Could not build contour %s",sname.Data()));
96 return 0x0;
97 }
98
99 contour->SetName(sname.Data());
100
101 contour->Offset(motifPos->GetPositionX()-seg->GetPositionX(),
102 motifPos->GetPositionY()-seg->GetPositionY());
103
104 TGeoHMatrix* matrix = 0x0;
105
106 if ( fDETransformations )
107 {
108 matrix = static_cast<TGeoHMatrix*>(fDETransformations->GetValue(detElemId));
109 if ( matrix ) contour->Transform(*matrix);
110 }
111
112 return contour;
113}
114
115
116//_____________________________________________________________________________
117AliMUONContour*
118AliMUONManuContourMaker::CreateMotifContour(const AliMpMotifPosition& motifPosition) const
119{
120 /// Create the contour of a given MOTIF (i.e. local coordinates only).
121
122 AliCodeTimerAuto("");
123
124 TString mpName(NameIt(motifPosition));
125
126 AliMUONContour* contour = static_cast<AliMUONContour*>(fLocalManuContours.GetValue(mpName.Data()));
127
128 if ( contour )
129 {
130 // if we have already done the job, just have to clone it and we are done
131 return static_cast<AliMUONContour*>(contour->Clone());
132 }
133
134 TObjArray polygons(AliMpConstants::ManuNofChannels()); // array of AliMUONPolygon objects
135 polygons.SetOwner(kTRUE);
136
137 AliMpVMotif* motif = motifPosition.GetMotif();
138
139 AliMpMotifType* motifType = motif->GetMotifType();
140
141 if ( motifType->IsFull() )
142 {
143 // motif is a simple rectangle. No need to loop over pads, we can
144 // compute the contour right here and now.
145 polygons.Add(new AliMUONPolygon(0.0,0.0,motif->DimensionX(),motif->DimensionY()));
146 }
147 else
148 {
149 for ( Int_t i = 0; i <= AliMpConstants::ManuNofChannels(); ++i )
150 {
151 AliMpConnection* connection = motifType->FindConnectionByGassiNum(i);
152
153 if ( connection )
154 {
155 Int_t ix = connection->GetLocalIx();
156 Int_t iy = connection->GetLocalIy();
157
158 Double_t x,y,dx,dy;
159
160 motif->GetPadDimensionsByIndices(ix,iy,dx,dy);
161 motif->PadPositionLocal(ix,iy,x,y);
162
163 AliMUONPolygon* pol = new AliMUONPolygon(x,y,dx,dy);
164 polygons.Add(pol);
165 }
166 }
167 }
168
169 AliMUONContourMaker maker;
170
171 contour = maker.CreateContour(polygons);
172
173 if (!contour || !contour->IsValid() )
174 {
175 AliError(Form("Failed to properly create contour %s contour = %p",mpName.Data(),contour));
176 if ( contour )
177 {
178 AliError(Form("nofVertices=%d area.isvalid=%d",contour->NumberOfVertices(),contour->Area().IsValid()));
179 StdoutToAliError(contour->Area().Print(););
180 }
181 delete contour;
182 return 0x0;
183 }
184
185 {
186 AliCodeTimerAuto("localmanucontour.add");
187 fLocalManuContours.Add(new TObjString(mpName),contour);
188 }
189
190 return static_cast<AliMUONContour*>(contour->Clone());
191}
192
193//_____________________________________________________________________________
194TObjArray*
195AliMUONManuContourMaker::GenerateManuContours(Bool_t stopAtError)
196{
197 /// Generate the contours for all the manus, taking into account the given transformation
198 /// (to go from local to global). That transformation need not be the real one (i.e.
199 /// it can be an "exploded" one to ease visualization).
200
201 AliCodeTimerAuto("");
202
203 TObjArray* manuContours = new TObjArray;
204
205 manuContours->SetOwner(kTRUE);
206
207 AliMpManuIterator it;
208 Int_t detElemId, manuId;
209 Int_t nmanus(0);
210 Int_t nok(0);
211
212 while ( it.Next(detElemId,manuId) )
213 {
214 ++nmanus;
215 AliMUONContour* contour = CreateManuContour(detElemId,manuId);
216 if (contour)
217 {
218 manuContours->Add(contour);
219 }
220 else
221 {
222 if ( stopAtError )
223 {
224 break;
225 }
226 }
227 ++nok;
228 }
229
230 AliInfo(Form("%d manus. %d contours successfully created",nmanus,nok));
231
232 return manuContours;
233}
234
235//_____________________________________________________________________________
236TString
237AliMUONManuContourMaker::NameIt(const AliMpMotifPosition& motifPosition) const
238{
239 /// Get the name of an AliMpMotifPosition
240
241 AliMpVMotif* motif = motifPosition.GetMotif();
242 TString name(Form("%s",motif->GetID().Data()));
243
244 for ( Int_t i = 0; i < motif->GetNofPadDimensions(); ++i )
245 {
246 name += Form("/%7.3f-%7.3f:",motif->GetPadDimensionX(i),motif->GetPadDimensionY(i));
247 }
248
249 return name;
250}
251
252//_____________________________________________________________________________
253TString
254AliMUONManuContourMaker::ManuPathName(Int_t detElemId, Int_t manuId, Bool_t withCathodeName)
255{
256 /// Get the name of a manu
257
258 AliMp::PlaneType planeType;
259 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) )
260 {
261 planeType = AliMp::kNonBendingPlane;
262 }
263 else
264 {
265 planeType = AliMp::kBendingPlane;
266 }
267 AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
268
269 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
270 Int_t stationId = chamberId/2;
271
272 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId, manuId);
273
274 AliMpUID id(cathodeType,stationId,chamberId,detElemId,busPatchId,manuId);
275
276 if ( withCathodeName ) return id.PathName();
277
278 TString name(id.PathName());
279
280 name.ReplaceAll("Cathode0/","");
281 name.ReplaceAll("Cathode1/","");
282
283 return name;
284}
285
286
287
288