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 <TGeoPhysicalNode.h> // ROOT_TGeoPhysicalNode
40 #include <TGeoMatrix.h> // ROOT_TGeoMatrix
41 #include <TMath.h> // ROOT_TMath
43 #include "AliFMDDetector.h" // ALIFMDSUBDETECTOR_H
44 #include "AliFMDRing.h" // ALIFMDRING_H
45 #include "AliFMDDebug.h" // ALIFMDDEBUG_H ALILOG_H
47 //====================================================================
48 ClassImp(AliFMDDetector)
50 ; // This is here to keep Emacs for indenting the next line
53 //____________________________________________________________________
54 AliFMDDetector::AliFMDDetector(Int_t id, AliFMDRing* inner, AliFMDRing* outer)
55 : TNamed(Form("FMD%d", id), "Forward multiplicity ring"),
59 fHoneycombThickness(0.),
72 // ID Id of detector (1,2, or 3)
73 // INNER Inner ring geometry
74 // OUTER Outer ring geometry (if any)
76 SetHoneycombThickness();
79 SetInnerHoneyHighR(0);
83 SetOuterHoneyHighR(0);
86 //____________________________________________________________________
87 AliFMDDetector::AliFMDDetector(const AliFMDDetector& other)
92 fHoneycombThickness(0.),
100 fInnerTransforms(other.fInnerTransforms),
101 fOuterTransforms(other.fOuterTransforms)
104 SetHoneycombThickness(other.GetHoneycombThickness());
105 SetAlThickness(other.GetAlThickness());
106 SetInnerHoneyLowR(other.GetInnerHoneyLowR());
107 SetInnerHoneyHighR(other.GetInnerHoneyHighR());
108 SetInnerZ(other.GetInnerZ());
109 SetOuterZ(other.GetOuterZ());
110 SetOuterHoneyLowR(other.GetOuterHoneyLowR());
111 SetOuterHoneyHighR(other.GetOuterHoneyHighR());
114 //____________________________________________________________________
116 AliFMDDetector::operator=(const AliFMDDetector& other)
118 // Assignment operator
119 SetName(other.GetName());
120 SetTitle(other.GetTitle());
122 fInner = other.fInner;
123 fOuter = other.fOuter;
124 fInnerTransforms = other.fInnerTransforms;
125 fOuterTransforms = other.fOuterTransforms;
126 SetHoneycombThickness(other.GetHoneycombThickness());
127 SetAlThickness(other.GetAlThickness());
128 SetInnerHoneyLowR(other.GetInnerHoneyLowR());
129 SetInnerHoneyHighR(other.GetInnerHoneyHighR());
130 SetInnerZ(other.GetInnerZ());
131 SetOuterZ(other.GetOuterZ());
132 SetOuterHoneyLowR(other.GetOuterHoneyLowR());
133 SetOuterHoneyHighR(other.GetOuterHoneyHighR());
137 //____________________________________________________________________
139 AliFMDDetector::Init()
143 SetInnerHoneyLowR(fInner->GetLowR() + 1.);
144 SetInnerHoneyHighR(fInner->GetHighR() + 1.);
147 SetOuterHoneyLowR(fOuter->GetLowR() + 1.);
148 SetOuterHoneyHighR(fOuter->GetHighR() + 1.);
152 //____________________________________________________________________
154 AliFMDDetector::HasAllTransforms(Char_t ring) const
156 // Check if we got all transformations for a given ring. Return
157 // true in that case.
158 AliFMDRing* r = GetRing(ring);
159 if (!r) return kTRUE;
160 TObjArray* matricies = (r == fInner ? fInnerTransforms : fOuterTransforms);
161 if (!matricies) return kTRUE;
162 if (matricies->GetEntries() == r->GetNModules()) return kTRUE;
166 #define IS_NODE_THIS(name) \
167 (name[0] == 'F' && name[2] == 'M' && name[1] == Char_t(48+fId) && \
168 (name[3] == 'T' || name[3] == 'B'))
169 #define IS_NODE_SENSOR(name) \
170 (name[0] == 'F' && name[2] == 'S' && name[3] == 'E')
171 #define IS_NODE_HALF(name) \
172 (name[0] == 'F' && name[2] == 'M' && (name[3] == 'B' || name[3] == 'T'))
173 #define HALF_FORMAT "FMD/FMD%d_%c"
174 #define SENSOR_FORMAT "FMD/FMD%d_%c/FMD%c_%02d"
176 //____________________________________________________________________
178 AliFMDDetector::InitTransformations()
180 // Find all local<->global transformations for this detector.
181 if ((!fInner || (fInner && fInnerTransforms)) &&
182 (!fOuter || (fOuter && fOuterTransforms))) {
183 AliFMDDebug(5, ("Transforms for FMD%d already registered", fId));
186 AliFMDDebug(5, ("Initializing transforms for FMD%d", fId));
188 AliFatal("No TGeoManager defined");
192 // Implementation using alignable volume names.
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 for (size_t iring = 0; iring < 2; iring++) {
201 char ring = (iring == 0 ? 'I' : 'O');
202 TObjArray* trans = 0;
205 case 'I': r = fInner; trans = fInnerTransforms; break;
206 case 'O': r = fOuter; trans = fOuterTransforms; break;
208 if (!r || !trans) continue;
210 Int_t nModules = r->GetNModules();
211 if (nModules <= 0) continue;
213 // Loop over bottom/top
214 for (size_t ihalf = 0; ihalf < 2; ihalf++) {
215 char half = (ihalf == 0 ? 'T' : 'B');
216 Int_t base = (half == 'T' ? 0 : nModules / 2);
218 // Loop over modules in this half ring
219 for (Int_t imod = 0; imod < nModules / 2; imod++) {
220 // Find physical node entry
221 TString path(Form(SENSOR_FORMAT, fId, half, ring, base+imod));
222 TGeoPNEntry* entry = gGeoManager->GetAlignableEntry(path.Data());
224 AliError(Form("Alignable entry for sensor \"%s\" not found!",
228 TGeoPhysicalNode* pn = entry->GetPhysicalNode();
230 AliWarning(Form("Making physical volume for \"%s\"", path.Data()));
231 pn = gGeoManager->MakeAlignablePN(entry);
233 AliError(Form("No physical node for \"%s\"", path.Data()));
238 const TGeoMatrix* pm = pn->GetMatrix();
240 AliError(Form("No matrix for path \"%s\"", path.Data()));
243 // Get transformation matrix for this node, and store it.
244 TGeoMatrix* t = new TGeoHMatrix(*pm);
245 trans->AddAt(t, base+imod);
246 AliFMDDebug(1, ("Found matrix for path \"%s\": %p",path.Data(),pm));
250 if (HasAllTransforms('I') && HasAllTransforms('O')) return;
252 // Alternative implementation using TGeoIter.
253 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
255 AliFatal("No top-level volume defined");
259 TGeoIterator next(topVolume);
262 // Find the node corresponding to this detector, and then find the
264 Bool_t thisNodeFound = kFALSE;
265 Bool_t allInners = HasAllTransforms('I');
266 Bool_t allOuters = HasAllTransforms('O');
268 while ((node = static_cast<TGeoNode*>(next()))
269 && !(allInners && allOuters)) {
271 const Char_t* name = node->GetName();
273 AliFMDDebug(50, ("Got volume %s", name));
274 // Check if this node is this detector
275 // The base offset for numbers in the ASCII table is 48
276 if (IS_NODE_THIS(name)) {
277 AliFMDDebug(20, ("Found detector node '%s' for FMD%d", name, fId));
278 thisNodeFound = kTRUE;
280 // if the detector was found, then we're on that branch, and we
281 // check if this node represents a module in that branch.
282 if (thisNodeFound && IS_NODE_SENSOR(name)) {
283 AliFMDDebug(20, ("Found sensor node '%s' for FMD%d", name, fId));
285 Char_t ringid = name[1];
287 // Get the approprate ring
288 AliFMDRing* ring = GetRing(ringid);
291 // Check whether we have all the modules we need for this ring,
292 // and if so, go on to the next node.
293 Bool_t& done = (ring == fInner ? allInners : allOuters);
294 if ((done = HasAllTransforms(ringid))) {
295 AliFMDDebug(20, ("Already has all module transforms for ring %c",
300 // Get the approprate container
301 TObjArray* matricies = (ringid == 'i' || ringid == 'I'
302 ? fInnerTransforms : fOuterTransforms);
304 // Get the copy (module) number, and check that it hasn't
305 // already been added to the container.
306 Int_t copy = node->GetNumber();
307 if (matricies->At(copy)) {
308 AliWarning(Form("Have a transformation for module %d in ring %c",
313 // Get the global transformation matrix, and store it.
314 TGeoMatrix* trans = new TGeoHMatrix(*(next.GetCurrentMatrix()));
315 matricies->AddAt(trans, copy);
321 //____________________________________________________________________
323 AliFMDDetector::SetAlignableVolumes() const
325 // Set alignable volumes.
326 // This will define the alignable volumes.
327 // That is currently, the modules and the half-rings.
329 AliFMDDebug(10, ("Making alignable volumes for FMD%d", fId));
331 AliFatal("No TGeoManager defined");
334 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
336 AliFatal("No top-level volume defined");
341 TGeoIterator next(topVolume);
342 next.Reset(topVolume);
343 next.SetTopName(Form("/%s_1", topVolume->GetName()));
346 Int_t nInnerSensor = (fInner ? fInner->GetNModules() : 0);
347 Int_t nOuterSensor = (fOuter ? fOuter->GetNModules() : 0);
348 // Find the node corresponding to this detector, and then find the
350 Bool_t thisNodeFound = kFALSE;
351 Char_t thisHalf = '\0';
352 Int_t iInnerSensor = 0;
353 Int_t iOuterSensor = 0;
354 Bool_t hasTop = false;
355 Bool_t hasBottom = false;
358 while ((node = static_cast<TGeoNode*>(next()))
359 && (iInnerSensor < nInnerSensor || iOuterSensor < nOuterSensor
360 || !hasBottom || !hasTop)) {
362 const Char_t* name = node->GetName();
364 AliFMDDebug((name[0] == 'F' ? 40 : 50), ("Got volume %s", name));
365 // Check if this node is this detector
366 // The base offset for numbers in the ASCII table is 48
367 if (IS_NODE_THIS(name)) {
368 AliFMDDebug(20, ("Found detector node '%s' for FMD%d", name, fId));
369 thisNodeFound = kTRUE;
372 // if a half ring is found, then we're on that branch, and we
373 // check if this node represents a half ring on that branch
374 if (thisNodeFound && IS_NODE_HALF(name)) {
375 AliFMDDebug(30, ("Found half node '%s' for FMD%d", name, fId));
379 // Check if we're done
380 Bool_t done = (thisHalf == 'T' ? hasTop : hasBottom);
382 AliFMDDebug(20, ("Already has all halves for detector %c",name[1]));
387 case 'T': hasTop = true; break;
388 case 'B': hasBottom = true; break;
390 AliWarning(Form("Unknown part '%c' of FMD%d", fId));
391 continue; // because the node is unknown.
396 align = Form(HALF_FORMAT, fId, thisHalf);
399 // if the detector was found, then we're on that branch, and we
400 // check if this node represents a module in that branch.
401 if (thisNodeFound && thisHalf && IS_NODE_SENSOR(name)) {
402 AliFMDDebug(30, ("Found sensor node '%s' for FMD%d", name, fId));
404 Char_t ringid = name[1];
406 // check that the ring is valid
407 if (!GetRing(ringid)) {
408 AliWarning(Form("Invalid ring %c for FMD%d", ringid, fId));
412 // Check if we're done
415 case 'I': done = iInnerSensor >= nInnerSensor; break;
416 case 'O': done = iOuterSensor >= nOuterSensor; break;
420 AliFMDDebug(20, ("Already has all sensor volumes for ring %c",ringid));
423 // Get the copy (module) number, and check that it hasn't
424 // already been added to the container.
425 Int_t copy = node->GetNumber();
427 // path.Replace("ALIC", "/ALIC_1");
428 align = Form(SENSOR_FORMAT, fId, thisHalf, ringid, copy);
431 case 'I': iInnerSensor++; break;
432 case 'O': iOuterSensor++; break;
435 if (!align.IsNull() && !path.IsNull()) {
436 AliFMDDebug(20, ("Got %s -> %s", path.Data(), align.Data()));
438 gGeoManager->SetAlignableEntry(align.Data(),path.Data());
440 AliFatal(Form("Alignable entry %s not created. "
441 "Volume path %s not valid",
442 align.Data(),path.Data()));
443 #ifdef MAKE_ALIGNABLE_PHYSICAL
444 TGeoPhysicalNode* phys = gGeoManager->MakeAlignablePN(entry);
446 AliWarning(Form("Physical node entry %s not created. "
447 "Volume path %s not valid",
448 align.Data(),path.Data()));
452 AliFMDDebug(20, ("FMD%d: top: %d bottom: %d Inner: %d/%d Outer %d/%d",
453 fId, hasTop, hasBottom, iInnerSensor, nInnerSensor,
454 iOuterSensor, nOuterSensor));
460 //____________________________________________________________________
462 AliFMDDetector::GetRing(Char_t id) const
464 // Get the specified ring
466 // ID Id of ring ('I' or 'O')
470 case 'I': return GetInner();
472 case 'O': return GetOuter();
477 //____________________________________________________________________
479 AliFMDDetector::GetRingZ(Char_t id) const
481 // Get the z-coordinate specified ring
483 // ID Id of ring ('I' or 'O')
487 case 'I': return GetInnerZ();
489 case 'O': return GetOuterZ();
494 //____________________________________________________________________
496 AliFMDDetector::FindTransform(Char_t ring, UShort_t sector) const
498 // Find the transformation that corresponds to sector sector in ring
500 TObjArray* matricies = 0;
502 case 'i': case 'I': matricies = fInnerTransforms; break;
503 case 'o': case 'O': matricies = fOuterTransforms; break;
506 AliWarning(Form("Unknown ring %c of FMD%d", ring, fId));
509 UInt_t module = sector / 2;
510 TGeoMatrix* m = static_cast<TGeoMatrix*>(matricies->At(module));
512 AliWarning(Form("No matrix found for sector %d in FMD%d%c",
520 //____________________________________________________________________
522 AliFMDDetector::Detector2XYZ(Char_t ring,
529 // Translate detector coordinates (this,ring,sector,strip) into
530 // (x,y,z) coordinates (in global reference frame)
531 AliFMDRing* r = GetRing(ring);
533 TGeoMatrix* m = FindTransform(ring, sector);
535 Double_t rho = r->GetStripRadius(strip);
536 Double_t phi = ((sector % 2) - .5) * r->GetTheta();
537 Double_t siThick = r->GetSiThickness();
538 Double_t modThick = (siThick
539 + r->GetPrintboardThickness()
540 + r->GetCopperThickness()
541 + r->GetChipThickness()
543 AliFMDDebug(30, ("Rho %7.3f, angle %7.3f", rho, phi));
544 # define DEGRAD TMath::Pi() / 180.
545 Double_t local[] = { rho * TMath::Cos(phi * DEGRAD),
546 rho * TMath::Sin(phi * DEGRAD),
547 -modThick + siThick / 2 };
549 AliFMDDebug(30, ("Local (%7.3f,%7.3f,%7.3f)",local[0], local[1], local[2]));
550 m->LocalToMaster(local, master);
551 AliFMDDebug(30, ("Master (%7.3f,%7.3f,%7.3f)",
552 master[0],master[1],master[2]));
558 //____________________________________________________________________
560 AliFMDDetector::XYZ2Detector(Double_t x,
565 UShort_t& strip) const
567 // Translate (x,y,z) coordinates (in global reference frame) into
568 // detector coordinates (this,ring,sector,strip).
571 for (int j = 0; j < 2; j++) {
572 rng = GetRing(j == 0 ? 'I' : 'O');
574 Double_t ringZ = GetRingZ(j == 0 ? 'I' : 'O');
575 Double_t modSpace = TMath::Sign(rng->GetModuleSpacing(), ringZ);
576 if (TMath::Abs(z - ringZ) < 0.01 ||
577 TMath::Abs(z - ringZ + modSpace) < 0.01) break;
580 if (rng && rng->XYZ2Detector(x, y, z - GetRingZ(rng->GetId()),
590 //____________________________________________________________________