1 /**************************************************************************
2 * Copyright(c) 2004, 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 **************************************************************************/
16 /** @file AliFMDDetector.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:36:27 2006
19 @brief Sub-detector base class implementation
23 //____________________________________________________________________
27 // Base class for concrete FMD detectors, like AliFMD1, AliFMD2,
29 // Utility class to help implement the FMD geometry. This provides
30 // the interface for the concrete geometry implementations of the FMD
33 // The AliFMDGeometry object owns the AliFMDDetector objects
35 // Latest changes by Christian Holm Christensen
38 #include <TGeoManager.h> // ROOT_TGeoManager
39 #include <TGeoMatrix.h> // ROOT_TGeoMatrix
40 #include <TMath.h> // ROOT_TMath
42 #include "AliFMDDetector.h" // ALIFMDSUBDETECTOR_H
43 #include "AliFMDRing.h" // ALIFMDRING_H
44 #include "AliLog.h" // ALILOG_H
46 //====================================================================
47 ClassImp(AliFMDDetector)
49 ; // This is here to keep Emacs for indenting the next line
52 //____________________________________________________________________
53 AliFMDDetector::AliFMDDetector(Int_t id, AliFMDRing* inner, AliFMDRing* outer)
54 : TNamed(Form("FMD%d", id), "Forward multiplicity ring"),
58 fHoneycombThickness(0.),
71 // ID Id of detector (1,2, or 3)
72 // INNER Inner ring geometry
73 // OUTER Outer ring geometry (if any)
75 SetHoneycombThickness();
78 SetInnerHoneyHighR(0);
82 SetOuterHoneyHighR(0);
85 //____________________________________________________________________
86 AliFMDDetector::AliFMDDetector(const AliFMDDetector& other)
91 fHoneycombThickness(0.),
99 fInnerTransforms(other.fInnerTransforms),
100 fOuterTransforms(other.fOuterTransforms)
103 SetHoneycombThickness(other.GetHoneycombThickness());
104 SetAlThickness(other.GetAlThickness());
105 SetInnerHoneyLowR(other.GetInnerHoneyLowR());
106 SetInnerHoneyHighR(other.GetInnerHoneyHighR());
107 SetInnerZ(other.GetInnerZ());
108 SetOuterZ(other.GetOuterZ());
109 SetOuterHoneyLowR(other.GetOuterHoneyLowR());
110 SetOuterHoneyHighR(other.GetOuterHoneyHighR());
113 //____________________________________________________________________
115 AliFMDDetector::operator=(const AliFMDDetector& other)
117 // Assignment operator
118 SetName(other.GetName());
119 SetTitle(other.GetTitle());
121 fInner = other.fInner;
122 fOuter = other.fOuter;
123 fInnerTransforms = other.fInnerTransforms;
124 fOuterTransforms = other.fOuterTransforms;
125 SetHoneycombThickness(other.GetHoneycombThickness());
126 SetAlThickness(other.GetAlThickness());
127 SetInnerHoneyLowR(other.GetInnerHoneyLowR());
128 SetInnerHoneyHighR(other.GetInnerHoneyHighR());
129 SetInnerZ(other.GetInnerZ());
130 SetOuterZ(other.GetOuterZ());
131 SetOuterHoneyLowR(other.GetOuterHoneyLowR());
132 SetOuterHoneyHighR(other.GetOuterHoneyHighR());
136 //____________________________________________________________________
138 AliFMDDetector::Init()
142 SetInnerHoneyLowR(fInner->GetLowR() + 1.);
143 SetInnerHoneyHighR(fInner->GetHighR() + 1.);
146 SetOuterHoneyLowR(fOuter->GetLowR() + 1.);
147 SetOuterHoneyHighR(fOuter->GetHighR() + 1.);
151 //____________________________________________________________________
153 AliFMDDetector::HasAllTransforms(Char_t ring) const
155 // Check if we got all transformations for a given ring. Return
156 // true in that case.
157 AliFMDRing* r = GetRing(ring);
158 if (!r) return kTRUE;
159 TObjArray* matricies = (r == fInner ? fInnerTransforms : fOuterTransforms);
160 if (!matricies) return kTRUE;
161 if (matricies->GetEntries() == r->GetNModules()) return kTRUE;
165 #define IS_NODE_THIS(name) \
166 (name[0] == 'F' && name[2] == 'M' && name[1] == Char_t(48+fId) && \
167 (name[3] == 'T' || name[3] == 'B'))
168 #define IS_NODE_SENSOR(name) \
169 (name[0] == 'F' && name[2] == 'S' && name[3] == 'E')
170 #define IS_NODE_HALF(name) \
171 (name[0] == 'F' && name[2] == 'M' && (name[3] == 'B' || name[3] == 'T'))
173 //____________________________________________________________________
175 AliFMDDetector::InitTransformations()
177 // Find all local<->global transformations for this detector.
178 if ((!fInner || (fInner && fInnerTransforms)) &&
179 (!fOuter || (fOuter && fOuterTransforms))) {
180 AliDebug(5, Form("Transforms for FMD%d already registered", fId));
183 AliDebug(5, Form("Initializing transforms for FMD%d", fId));
185 AliFatal("No TGeoManager defined");
188 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
190 AliFatal("No top-level volume defined");
193 // Make container of transforms
194 if (fInner && !fInnerTransforms)
195 fInnerTransforms = new TObjArray(fInner->GetNModules());
196 if (fOuter && !fOuterTransforms)
197 fOuterTransforms = new TObjArray(fOuter->GetNModules());
200 TGeoIterator next(topVolume);
203 // Find the node corresponding to this detector, and then find the
205 Bool_t thisNodeFound = kFALSE;
206 Bool_t allInners = HasAllTransforms('I');
207 Bool_t allOuters = HasAllTransforms('O');
209 while ((node = static_cast<TGeoNode*>(next()))
210 && !(allInners && allOuters)) {
212 const Char_t* name = node->GetName();
214 AliDebug(50, Form("Got volume %s", name));
215 // Check if this node is this detector
216 // The base offset for numbers in the ASCII table is 48
217 if (IS_NODE_THIS(name)) {
218 AliDebug(20, Form("Found detector node '%s' for FMD%d", name, fId));
219 thisNodeFound = kTRUE;
221 // if the detector was found, then we're on that branch, and we
222 // check if this node represents a module in that branch.
223 if (thisNodeFound && IS_NODE_SENSOR(name)) {
224 AliDebug(20, Form("Found sensor node '%s' for FMD%d", name, fId));
226 Char_t ringid = name[1];
228 // Get the approprate ring
229 AliFMDRing* ring = GetRing(ringid);
232 // Check whether we have all the modules we need for this ring,
233 // and if so, go on to the next node.
234 Bool_t& done = (ring == fInner ? allInners : allOuters);
235 if ((done = HasAllTransforms(ringid))) {
236 AliDebug(20, Form("Already has all module transforms for ring %c",
241 // Get the approprate container
242 TObjArray* matricies = (ringid == 'i' || ringid == 'I'
243 ? fInnerTransforms : fOuterTransforms);
245 // Get the copy (module) number, and check that it hasn't
246 // already been added to the container.
247 Int_t copy = node->GetNumber();
248 if (matricies->At(copy)) {
249 AliWarning(Form("Have a transformation for module %d in ring %c",
254 // Get the global transformation matrix, and store it.
255 TGeoMatrix* trans = new TGeoHMatrix(*(next.GetCurrentMatrix()));
256 matricies->AddAt(trans, copy);
262 //____________________________________________________________________
264 AliFMDDetector::SetAlignableVolumes() const
266 AliDebug(10, Form("Making alignable volumes for FMD%d", fId));
268 AliFatal("No TGeoManager defined");
271 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
273 AliFatal("No top-level volume defined");
278 TGeoIterator next(topVolume);
279 next.Reset(topVolume);
280 next.SetTopName(Form("/%s_1", topVolume->GetName()));
283 Int_t nInnerSensor = (fInner ? fInner->GetNModules() : 0);
284 Int_t nOuterSensor = (fOuter ? fOuter->GetNModules() : 0);
285 // Find the node corresponding to this detector, and then find the
287 Bool_t thisNodeFound = kFALSE;
288 Char_t thisHalf = '\0';
289 Int_t iInnerSensor = 0;
290 Int_t iOuterSensor = 0;
291 Bool_t hasTop = false;
292 Bool_t hasBottom = false;
295 while ((node = static_cast<TGeoNode*>(next()))
296 && (iInnerSensor < nInnerSensor || iOuterSensor < nOuterSensor
297 || !hasBottom || !hasTop)) {
299 const Char_t* name = node->GetName();
301 AliDebug((name[0] == 'F' ? 40 : 50), Form("Got volume %s", name));
302 // Check if this node is this detector
303 // The base offset for numbers in the ASCII table is 48
304 if (IS_NODE_THIS(name)) {
305 AliDebug(20, Form("Found detector node '%s' for FMD%d", name, fId));
306 thisNodeFound = kTRUE;
309 // if a half ring is found, then we're on that branch, and we
310 // check if this node represents a half ring on that branch
311 if (thisNodeFound && IS_NODE_HALF(name)) {
312 AliDebug(30, Form("Found half node '%s' for FMD%d", name, fId));
316 // Check if we're done
317 Bool_t done = (thisHalf == 'T' ? hasTop : hasBottom);
319 AliDebug(20,Form("Already has all halves for detector %c",name[1]));
324 case 'T': hasTop = true; break;
325 case 'B': hasBottom = true; break;
327 AliWarning(Form("Unknown part '%c' of FMD%d", fId));
328 continue; // because the node is unknown.
333 align = Form("FMD/FMD%d_%c", fId, thisHalf);
336 // if the detector was found, then we're on that branch, and we
337 // check if this node represents a module in that branch.
338 if (thisNodeFound && thisHalf && IS_NODE_SENSOR(name)) {
339 AliDebug(30, Form("Found sensor node '%s' for FMD%d", name, fId));
341 Char_t ringid = name[1];
343 // check that the ring is valid
344 if (!GetRing(ringid)) {
345 AliWarning(Form("Invalid ring %c for FMD%d", ringid, fId));
349 // Check if we're done
352 case 'I': done = iInnerSensor >= nInnerSensor; break;
353 case 'O': done = iOuterSensor >= nOuterSensor; break;
357 AliDebug(20,Form("Already has all sensor volumes for ring %c",ringid));
360 // Get the copy (module) number, and check that it hasn't
361 // already been added to the container.
362 Int_t copy = node->GetNumber();
364 // path.Replace("ALIC", "/ALIC_1");
365 align = Form("FMD/FMD%d_%c/FMD%c_%02d", fId, thisHalf, ringid, copy);
368 case 'I': iInnerSensor++; break;
369 case 'O': iOuterSensor++; break;
372 if (!align.IsNull() && !path.IsNull()) {
373 AliDebug(20, Form("Got %s -> %s", path.Data(), align.Data()));
375 gGeoManager->SetAlignableEntry(align.Data(),path.Data());
377 AliFatal(Form("Alignable entry %s not created. "
378 "Volume path %s not valid",
379 align.Data(),path.Data()));
380 #ifdef MAKE_ALIGNABLE_PHYSICAL
381 TGeoPhysicalNode* phys = gGeoManager->MakeAlignablePN(entry);
383 AliWarning(Form("Physical node entry %s not created. "
384 "Volume path %s not valid",
385 align.Data(),path.Data()));
389 AliDebug(20, Form("FMD%d: top: %d bottom: %d Inner: %d/%d Outer %d/%d",
390 fId, hasTop, hasBottom, iInnerSensor, nInnerSensor,
391 iOuterSensor, nOuterSensor));
397 //____________________________________________________________________
399 AliFMDDetector::GetRing(Char_t id) const
401 // Get the specified ring
403 // ID Id of ring ('I' or 'O')
407 case 'I': return GetInner();
409 case 'O': return GetOuter();
414 //____________________________________________________________________
416 AliFMDDetector::GetRingZ(Char_t id) const
418 // Get the z-coordinate specified ring
420 // ID Id of ring ('I' or 'O')
424 case 'I': return GetInnerZ();
426 case 'O': return GetOuterZ();
431 //____________________________________________________________________
433 AliFMDDetector::FindTransform(Char_t ring, UShort_t sector) const
435 // Find the transformation that corresponds to sector sector in ring
437 TObjArray* matricies = 0;
439 case 'i': case 'I': matricies = fInnerTransforms; break;
440 case 'o': case 'O': matricies = fOuterTransforms; break;
443 AliWarning(Form("Unknown ring %c of FMD%d", ring, fId));
446 UInt_t module = sector / 2;
447 TGeoMatrix* m = static_cast<TGeoMatrix*>(matricies->At(module));
449 AliWarning(Form("No matrix found for sector %d in FMD%d%c",
457 //____________________________________________________________________
459 AliFMDDetector::Detector2XYZ(Char_t ring,
466 // Translate detector coordinates (this,ring,sector,strip) into
467 // (x,y,z) coordinates (in global reference frame)
468 AliFMDRing* r = GetRing(ring);
470 TGeoMatrix* m = FindTransform(ring, sector);
472 Double_t rho = r->GetStripRadius(strip);
473 Double_t phi = ((sector % 2) - .5) * r->GetTheta();
474 Double_t siThick = r->GetSiThickness();
475 Double_t modThick = (siThick
476 + r->GetPrintboardThickness()
477 + r->GetCopperThickness()
478 + r->GetChipThickness()
480 AliDebug(30,Form("Rho %7.3f, angle %7.3f", rho, phi));
481 # define DEGRAD TMath::Pi() / 180.
482 Double_t local[] = { rho * TMath::Cos(phi * DEGRAD),
483 rho * TMath::Sin(phi * DEGRAD),
484 -modThick + siThick / 2 };
486 AliDebug(30, Form("Local (%7.3f,%7.3f,%7.3f)",local[0], local[1], local[2]));
487 m->LocalToMaster(local, master);
488 AliDebug(30, Form("Master (%7.3f,%7.3f,%7.3f)",
489 master[0],master[1],master[2]));
495 //____________________________________________________________________
497 AliFMDDetector::XYZ2Detector(Double_t x,
502 UShort_t& strip) const
504 // Translate (x,y,z) coordinates (in global reference frame) into
505 // detector coordinates (this,ring,sector,strip).
508 for (int j = 0; j < 2; j++) {
509 rng = GetRing(j == 0 ? 'I' : 'O');
511 Double_t ringZ = GetRingZ(j == 0 ? 'I' : 'O');
512 Double_t modSpace = TMath::Sign(rng->GetModuleSpacing(), ringZ);
513 if (TMath::Abs(z - ringZ) < 0.01 ||
514 TMath::Abs(z - ringZ + modSpace) < 0.01) break;
517 if (rng && rng->XYZ2Detector(x, y, z - GetRingZ(rng->GetId()),
527 //____________________________________________________________________