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"),
70 // ID Id of detector (1,2, or 3)
71 // INNER Inner ring geometry
72 // OUTER Outer ring geometry (if any)
75 SetInnerHoneyHighR(0);
79 SetOuterHoneyHighR(0);
82 //____________________________________________________________________
83 AliFMDDetector::AliFMDDetector(const AliFMDDetector& other)
94 fInnerTransforms(other.fInnerTransforms),
95 fOuterTransforms(other.fOuterTransforms)
98 SetInnerHoneyLowR(other.GetInnerHoneyLowR());
99 SetInnerHoneyHighR(other.GetInnerHoneyHighR());
100 SetInnerZ(other.GetInnerZ());
101 SetOuterZ(other.GetOuterZ());
102 SetOuterHoneyLowR(other.GetOuterHoneyLowR());
103 SetOuterHoneyHighR(other.GetOuterHoneyHighR());
106 //____________________________________________________________________
108 AliFMDDetector::operator=(const AliFMDDetector& other)
110 // Assignment operator
111 SetName(other.GetName());
112 SetTitle(other.GetTitle());
114 fInner = other.fInner;
115 fOuter = other.fOuter;
116 fInnerTransforms = other.fInnerTransforms;
117 fOuterTransforms = other.fOuterTransforms;
118 SetInnerHoneyLowR(other.GetInnerHoneyLowR());
119 SetInnerHoneyHighR(other.GetInnerHoneyHighR());
120 SetInnerZ(other.GetInnerZ());
121 SetOuterZ(other.GetOuterZ());
122 SetOuterHoneyLowR(other.GetOuterHoneyLowR());
123 SetOuterHoneyHighR(other.GetOuterHoneyHighR());
127 //____________________________________________________________________
129 AliFMDDetector::Init()
133 SetInnerHoneyLowR(fInner->GetLowR() + 1.);
134 SetInnerHoneyHighR(fInner->GetHighR() + 1.);
137 SetOuterHoneyLowR(fOuter->GetLowR() + 1.);
138 SetOuterHoneyHighR(fOuter->GetHighR() + 1.);
142 //____________________________________________________________________
144 AliFMDDetector::HasAllTransforms(Char_t ring) const
146 // Check if we got all transformations for a given ring. Return
147 // true in that case.
148 AliFMDRing* r = GetRing(ring);
149 if (!r) return kTRUE;
150 TObjArray* matricies = (r == fInner ? fInnerTransforms : fOuterTransforms);
151 if (!matricies) return kTRUE;
152 if (matricies->GetEntries() == r->GetNModules()) return kTRUE;
156 #define IS_NODE_THIS(name) \
157 (name[0] == 'F' && name[2] == 'M' && name[1] == Char_t(48+fId) && \
158 (name[3] == 'T' || name[3] == 'B'))
159 #define IS_NODE_SENSOR(name) \
160 (name[0] == 'F' && (name[2] == 'B' || name[2] == 'F') && name[3] == 'H')
161 //#define IS_NODE_SENSOR(name)
162 // (name[0] == 'F' && name[2] == 'S' && name[3] == 'E')
163 #define IS_NODE_HALF(name) \
164 (name[0] == 'F' && name[2] == 'M' && (name[3] == 'B' || name[3] == 'T'))
165 #define HALF_FORMAT "FMD/FMD%d_%c"
166 #define SENSOR_FORMAT "FMD/FMD%d_%c/FMD%c_%02d"
168 //____________________________________________________________________
170 AliFMDDetector::InitTransformations()
172 // Find all local<->global transformations for this detector.
173 if ((!fInner || (fInner && fInnerTransforms)) &&
174 (!fOuter || (fOuter && fOuterTransforms))) {
175 AliFMDDebug(5, ("Transforms for FMD%d already registered", fId));
178 AliFMDDebug(5, ("Initializing transforms for FMD%d", fId));
180 AliFatal("No TGeoManager defined");
184 // Implementation using alignable volume names.
185 // Make container of transforms
186 if (fInner && !fInnerTransforms)
187 fInnerTransforms = new TObjArray(fInner->GetNModules());
188 if (fOuter && !fOuterTransforms)
189 fOuterTransforms = new TObjArray(fOuter->GetNModules());
192 for (size_t iring = 0; iring < 2; iring++) {
193 char ring = (iring == 0 ? 'I' : 'O');
194 TObjArray* trans = 0;
197 case 'I': r = fInner; trans = fInnerTransforms; break;
198 case 'O': r = fOuter; trans = fOuterTransforms; break;
200 if (!r || !trans) continue;
202 Int_t nModules = r->GetNModules();
203 if (nModules <= 0) continue;
205 // Loop over bottom/top
206 for (size_t ihalf = 0; ihalf < 2; ihalf++) {
207 char half = (ihalf == 0 ? 'T' : 'B');
208 Int_t base = (half == 'T' ? 0 : nModules / 2);
210 // Loop over modules in this half ring
211 for (Int_t imod = 0; imod < nModules / 2; imod++) {
212 // Find physical node entry
213 TString path(Form(SENSOR_FORMAT, fId, half, ring, base+imod));
214 TGeoPNEntry* entry = gGeoManager->GetAlignableEntry(path.Data());
216 AliError(Form("Alignable entry for sensor \"%s\" not found!",
220 TGeoPhysicalNode* pn = entry->GetPhysicalNode();
222 AliWarning(Form("Making physical volume for \"%s\"", path.Data()));
223 pn = gGeoManager->MakeAlignablePN(entry);
225 AliError(Form("No physical node for \"%s\"", path.Data()));
230 const TGeoMatrix* pm = pn->GetMatrix();
232 AliError(Form("No matrix for path \"%s\"", path.Data()));
235 // Get transformation matrix for this node, and store it.
236 TGeoMatrix* t = new TGeoHMatrix(*pm);
237 trans->AddAt(t, base+imod);
238 AliFMDDebug(5, ("Found matrix for path \"%s\": %p",path.Data(),pm));
242 if (HasAllTransforms('I') && HasAllTransforms('O')) return;
244 // Alternative implementation using TGeoIter.
245 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
247 AliFatal("No top-level volume defined");
251 TGeoIterator next(topVolume);
254 // Find the node corresponding to this detector, and then find the
256 Bool_t thisNodeFound = kFALSE;
257 Bool_t allInners = HasAllTransforms('I');
258 Bool_t allOuters = HasAllTransforms('O');
260 while ((node = static_cast<TGeoNode*>(next()))
261 && !(allInners && allOuters)) {
263 const Char_t* name = node->GetName();
265 AliFMDDebug(50, ("Got volume %s", name));
266 // Check if this node is this detector
267 // The base offset for numbers in the ASCII table is 48
268 if (IS_NODE_THIS(name)) {
269 AliFMDDebug(20, ("Found detector node '%s' for FMD%d", name, fId));
270 thisNodeFound = kTRUE;
272 // if the detector was found, then we're on that branch, and we
273 // check if this node represents a module in that branch.
274 if (thisNodeFound && IS_NODE_SENSOR(name)) {
275 AliFMDDebug(20, ("Found sensor node '%s' for FMD%d", name, fId));
277 Char_t ringid = name[1];
279 // Get the approprate ring
280 AliFMDRing* ring = GetRing(ringid);
283 // Check whether we have all the modules we need for this ring,
284 // and if so, go on to the next node.
285 Bool_t& done = (ring == fInner ? allInners : allOuters);
286 if ((done = HasAllTransforms(ringid))) {
287 AliFMDDebug(20, ("Already has all module transforms for ring %c",
292 // Get the approprate container
293 TObjArray* matricies = (ringid == 'i' || ringid == 'I'
294 ? fInnerTransforms : fOuterTransforms);
296 // Get the copy (module) number, and check that it hasn't
297 // already been added to the container.
298 Int_t copy = node->GetNumber();
299 if (matricies->At(copy)) {
300 AliWarning(Form("Have a transformation for module %d in ring %c",
305 // Get the global transformation matrix, and store it.
306 TGeoMatrix* trans = new TGeoHMatrix(*(next.GetCurrentMatrix()));
307 matricies->AddAt(trans, copy);
313 //____________________________________________________________________
315 AliFMDDetector::SetAlignableVolumes() const
317 // Set alignable volumes.
318 // This will define the alignable volumes.
319 // That is currently, the modules and the half-rings.
321 AliFMDDebug(10, ("Making alignable volumes for FMD%d", fId));
323 AliFatal("No TGeoManager defined");
326 TGeoVolume* topVolume = gGeoManager->GetTopVolume();
328 AliFatal("No top-level volume defined");
333 TGeoIterator next(topVolume);
334 next.Reset(topVolume);
335 next.SetTopName(Form("/%s_1", topVolume->GetName()));
338 Int_t nInnerSensor = (fInner ? fInner->GetNModules() : 0);
339 Int_t nOuterSensor = (fOuter ? fOuter->GetNModules() : 0);
340 // Find the node corresponding to this detector, and then find the
342 Bool_t thisNodeFound = kFALSE;
343 Char_t thisHalf = '\0';
344 Int_t iInnerSensor = 0;
345 Int_t iOuterSensor = 0;
346 Bool_t hasTop = false;
347 Bool_t hasBottom = false;
350 while ((node = static_cast<TGeoNode*>(next()))
351 && (iInnerSensor < nInnerSensor || iOuterSensor < nOuterSensor
352 || !hasBottom || !hasTop)) {
354 const Char_t* name = node->GetName();
356 AliFMDDebug((name[0] == 'F' ? 40 : 50), ("Got volume %s", name));
357 // Check if this node is this detector
358 // The base offset for numbers in the ASCII table is 48
359 if (IS_NODE_THIS(name)) {
360 AliFMDDebug(20, ("Found detector node '%s' for FMD%d", name, fId));
361 thisNodeFound = kTRUE;
364 // if a half ring is found, then we're on that branch, and we
365 // check if this node represents a half ring on that branch
366 if (thisNodeFound && IS_NODE_HALF(name)) {
367 AliFMDDebug(30, ("Found half node '%s' for FMD%d", name, fId));
371 // Check if we're done
372 Bool_t done = (thisHalf == 'T' ? hasTop : hasBottom);
374 AliFMDDebug(20, ("Already has all halves for detector %c",name[1]));
379 case 'T': hasTop = true; break;
380 case 'B': hasBottom = true; break;
382 AliWarning(Form("Unknown part '%c' of FMD%d", fId));
383 continue; // because the node is unknown.
388 align = Form(HALF_FORMAT, fId, thisHalf);
391 // if the detector was found, then we're on that branch, and we
392 // check if this node represents a module in that branch.
393 if (thisNodeFound && thisHalf && IS_NODE_SENSOR(name)) {
394 AliFMDDebug(30, ("Found sensor node '%s' for FMD%d", name, fId));
396 Char_t ringid = name[1];
398 // check that the ring is valid
399 if (!GetRing(ringid)) {
400 AliWarning(Form("Invalid ring %c for FMD%d", ringid, fId));
404 // Check if we're done
407 case 'I': done = iInnerSensor >= nInnerSensor; break;
408 case 'O': done = iOuterSensor >= nOuterSensor; break;
412 AliFMDDebug(20, ("Already has all sensor volumes for ring %c",ringid));
415 // Get the copy (module) number, and check that it hasn't
416 // already been added to the container.
417 Int_t copy = node->GetNumber();
419 // path.Replace("ALIC", "/ALIC_1");
420 align = Form(SENSOR_FORMAT, fId, thisHalf, ringid, copy);
423 case 'I': iInnerSensor++; break;
424 case 'O': iOuterSensor++; break;
427 if (!align.IsNull() && !path.IsNull()) {
428 AliFMDDebug(20, ("Got %s -> %s", path.Data(), align.Data()));
430 gGeoManager->SetAlignableEntry(align.Data(),path.Data());
432 AliFatal(Form("Alignable entry %s not created. "
433 "Volume path %s not valid",
434 align.Data(),path.Data()));
435 #ifdef MAKE_ALIGNABLE_PHYSICAL
436 TGeoPhysicalNode* phys = gGeoManager->MakeAlignablePN(entry);
438 AliWarning(Form("Physical node entry %s not created. "
439 "Volume path %s not valid",
440 align.Data(),path.Data()));
444 AliFMDDebug(20, ("FMD%d: top: %d bottom: %d Inner: %d/%d Outer %d/%d",
445 fId, hasTop, hasBottom, iInnerSensor, nInnerSensor,
446 iOuterSensor, nOuterSensor));
452 //____________________________________________________________________
454 AliFMDDetector::GetRing(Char_t id) const
456 // Get the specified ring
458 // ID Id of ring ('I' or 'O')
462 case 'I': return GetInner();
464 case 'O': return GetOuter();
469 //____________________________________________________________________
471 AliFMDDetector::GetRingZ(Char_t id) const
473 // Get the z-coordinate specified ring
475 // ID Id of ring ('I' or 'O')
479 case 'I': return GetInnerZ();
481 case 'O': return GetOuterZ();
486 //____________________________________________________________________
488 AliFMDDetector::FindTransform(Char_t ring, UShort_t sector) const
490 // Find the transformation that corresponds to sector sector in ring
492 TObjArray* matricies = 0;
494 case 'i': case 'I': matricies = fInnerTransforms; break;
495 case 'o': case 'O': matricies = fOuterTransforms; break;
498 AliWarning(Form("Unknown ring %c of FMD%d", ring, fId));
501 UInt_t module = sector / 2;
502 TGeoMatrix* m = static_cast<TGeoMatrix*>(matricies->At(module));
504 AliWarning(Form("No matrix found for sector %d in FMD%d%c",
512 //____________________________________________________________________
514 AliFMDDetector::Detector2XYZ(Char_t ring,
521 // Translate detector coordinates (this,ring,sector,strip) into
522 // (x,y,z) coordinates (in global reference frame)
523 AliFMDRing* r = GetRing(ring);
525 AliWarning(Form("No such ring FMD%d%c ", fId, ring));
528 TGeoMatrix* m = FindTransform(ring, sector);
530 AliWarning(Form("No transfrmation found for FMD%d%c[%02d]",
534 Double_t rho = r->GetStripRadius(strip);
535 Double_t phi = ((sector % 2) - .5) * r->GetTheta();
536 Double_t siThick = r->GetSiThickness();
538 Double_t modThick = (siThick
539 + r->GetPrintboardThickness()
540 + r->GetCopperThickness()
541 + r->GetChipThickness()
544 AliFMDDebug(30, ("Rho %7.3f, angle %7.3f", rho, phi));
545 Double_t local[] = { rho * TMath::Cos(phi * TMath::DegToRad()),
546 rho * TMath::Sin(phi * TMath::DegToRad()),
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 //____________________________________________________________________