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 **************************************************************************/
18 //____________________________________________________________________
20 // Forward Multiplicity Detector based on Silicon wafers. This class
21 // contains the base procedures for the Forward Multiplicity detector
22 // Detector consists of 3 sub-detectors FMD1, FMD2, and FMD3, each of
23 // which has 1 or 2 rings of silicon sensors.
25 // This is the base class for all FMD manager classes.
27 // The actual code is done by various separate classes. Below is
28 // diagram showing the relationship between the various FMD classes
29 // that handles the simulation
32 // +----------+ +----------+
33 // | AliFMDv1 | | AliFMDv0 |
34 // +----------+ +----------+
35 // | | +-----------------+
36 // +----+--------------+ +--| AliFMDDigitizer |
37 // | | +-----------------+
38 // | +---------------------+ |
39 // | +- | AliFMDBaseDigitizer |<--+
40 // V 1 | +---------------------+ |
41 // +--------+<>--+ | +------------------+
42 // | AliFMD | +--| AliFMDSDigitizer |
43 // +--------+<>--+ +------------------+
44 // 1 | +-----------------+
45 // +-| AliFMDSimulator |
46 // +-----------------+
49 // +-------------+-------------+
51 // +--------------------+ +-------------------+
52 // | AliFMDGeoSimulator | | AliFMDG3Simulator |
53 // +--------------------+ +---------+---------+
57 // This defines the interface for the various parts of AliROOT that
58 // uses the FMD, like AliFMDSimulator, AliFMDDigitizer,
59 // AliFMDReconstructor, and so on.
62 // This is a concrete implementation of the AliFMD interface.
63 // It is the responsibility of this class to create the FMD
67 // This is a concrete implementation of the AliFMD interface.
68 // It is the responsibility of this class to create the FMD
69 // geometry, process hits in the FMD, and serve hits and digits to
70 // the various clients.
73 // This is the base class for the FMD simulation tasks. The
74 // simulator tasks are responsible to implment the geoemtry, and
77 // * AliFMDGeoSimulator
78 // This is a concrete implementation of the AliFMDSimulator that
79 // uses the TGeo classes directly only.
81 // * AliFMDG3Simulator
82 // This is a concrete implementation of the AliFMDSimulator that
83 // uses the TVirtualMC interface with GEANT 3.21-like messages.
86 // These files are not in the same directory, so there's no reason to
87 // ask the preprocessor to search in the current directory for these
88 // files by including them with `#include "..."'
89 #include <math.h> // __CMATH__
90 #include <TClonesArray.h> // ROOT_TClonesArray
91 #include <TGeometry.h> // ROOT_TGeomtry
92 #include <TNode.h> // ROOT_TNode
93 #include <TXTRU.h> // ROOT_TXTRU
94 #include <TRotMatrix.h> // ROOT_TRotMatrix
95 #include <TTUBE.h> // ROOT_TTUBE
96 #include <TTree.h> // ROOT_TTree
97 #include <TBrowser.h> // ROOT_TBrowser
98 #include <TMath.h> // ROOT_TMath
99 #include <TVirtualMC.h> // ROOT_TVirtualMC
101 #include <AliRunDigitizer.h> // ALIRUNDIGITIZER_H
102 #include <AliLoader.h> // ALILOADER_H
103 #include <AliRun.h> // ALIRUN_H
104 #include <AliMC.h> // ALIMC_H
105 #include <AliLog.h> // ALILOG_H
106 #include "AliFMD.h" // ALIFMD_H
107 #include "AliFMDDigit.h" // ALIFMDDIGIG_H
108 #include "AliFMDHit.h" // ALIFMDHIT_H
109 #include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
110 #include "AliFMDDetector.h" // ALIFMDDETECTOR_H
111 #include "AliFMDRing.h" // ALIFMDRING_H
112 #include "AliFMDDigitizer.h" // ALIFMDDIGITIZER_H
113 #include "AliFMDSimulator.h" // ALIFMDSIMULATOR_H
114 #include "AliFMDG3Simulator.h" // ALIFMDG3SIMULATOR_H
115 #include "AliFMDGeoSimulator.h" // ALIFMDGEOSIMULATOR_H
116 #include "AliFMDRawWriter.h" // ALIFMDRAWWRITER_H
118 //____________________________________________________________________
121 ; // This is to keep Emacs from indenting the next line
124 //____________________________________________________________________
132 // Default constructor for class AliFMD
134 AliDebug(10, "\tDefault CTOR");
140 //____________________________________________________________________
141 AliFMD::AliFMD(const AliFMD& other)
142 : AliDetector(other),
143 fSDigits(other.fSDigits),
144 fNsdigits(other.fNsdigits),
145 fDetailed(other.fDetailed),
146 fSimulator(other.fSimulator)
151 //____________________________________________________________________
152 AliFMD::AliFMD(const char *name, const char *title)
153 : AliDetector (name, title),
160 // Standard constructor for Forward Multiplicity Detector
162 AliDebug(10, "\tStandard CTOR");
164 // Initialise Hit array
166 gAlice->GetMCApp()->AddHitList(fHits);
168 // (S)Digits for the detectors disk
172 // CHC: What is this?
174 SetMarkerColor(kRed);
175 SetLineColor(kYellow);
178 //____________________________________________________________________
181 // Destructor for base class AliFMD
199 //____________________________________________________________________
201 AliFMD::operator=(const AliFMD& other)
203 AliDetector::operator=(other);
204 fSDigits = other.fSDigits;
205 fNsdigits = other.fNsdigits;
206 fDetailed = other.fDetailed;
207 fSimulator = other.fSimulator;
212 //====================================================================
214 // GEometry ANd Traking
216 //____________________________________________________________________
218 AliFMD::CreateGeometry()
221 // Create the geometry of Forward Multiplicity Detector. The actual
222 // construction of the geometry is delegated to the class AliFMDRing
223 // and AliFMDSubDetector and the relevant derived classes.
225 // The flow of this member function is:
227 // FOR rings fInner and fOuter DO
228 // AliFMDRing::Init();
231 // Set up hybrud card support (leg) volume shapes
233 // FOR rings fInner and fOuter DO
234 // AliFMDRing::SetupGeometry();
237 // FOR subdetectors fFMD1, fFMD2, and fFMD3 DO
238 // AliFMDSubDetector::SetupGeomtry();
241 // FOR subdetectors fFMD1, fFMD2, and fFMD3 DO
242 // AliFMDSubDetector::Geomtry();
246 AliFatal("Simulator object not made yet!");
249 fSimulator->DefineGeometry();
252 //____________________________________________________________________
253 void AliFMD::CreateMaterials()
255 // Register various materials and tracking mediums with the
258 AliDebug(10, "\tCreating materials");
261 AliFatal("Simulator object already instantised!");
264 AliFMDGeometry* geometry = AliFMDGeometry::Instance();
266 TVirtualMC* mc = TVirtualMC::GetMC();
267 Bool_t geo = mc->IsRootGeometrySupported();
269 fSimulator = new AliFMDGeoSimulator(this, fDetailed);
271 fSimulator = new AliFMDG3Simulator(this, fDetailed);
273 fSimulator->DefineMaterials();
276 //____________________________________________________________________
281 // Initialis the FMD after it has been built
285 cout << "\n" << ClassName() << ": " << flush;
286 for (i = 0; i < 35; i++) cout << "*";
287 cout << " FMD_INIT ";
288 for (i = 0; i < 35; i++) cout << "*";
289 cout << "\n" << ClassName() << ": " << flush;
291 // Here the FMD initialisation code (if any!)
292 for (i = 0; i < 80; i++) cout << "*";
299 //====================================================================
301 // Graphics and event display
303 //____________________________________________________________________
305 AliFMD::BuildGeometry()
308 // Build simple ROOT TNode geometry for event display
310 // Build a simplified geometry of the FMD used for event display
312 // The actual building of the TNodes is done by
313 // AliFMDSubDetector::SimpleGeometry.
314 AliDebug(10, "\tCreating a simplified geometry");
316 AliFMDGeometry* fmd = AliFMDGeometry::Instance();
318 static TXTRU* innerShape = 0;
319 static TXTRU* outerShape = 0;
320 static TObjArray* innerRot = 0;
321 static TObjArray* outerRot = 0;
323 if (!innerShape || !outerShape) {
324 // Make the shapes for the modules
325 for (Int_t i = 0; i < 2; i++) {
328 case 0: r = fmd->GetRing('I'); break;
329 case 1: r = fmd->GetRing('O'); break;
332 AliError(Form("no ring found for i=%d", i));
335 Double_t siThick = r->GetSiThickness();
336 const Int_t nv = r->GetNVerticies();
337 Double_t theta = r->GetTheta();
338 Int_t nmod = r->GetNModules();
340 TXTRU* shape = new TXTRU(r->GetName(), r->GetTitle(), "void", nv, 2);
341 for (Int_t j = 0; j < nv; j++) {
342 TVector2* vv = r->GetVertex(nv - 1 - j);
343 shape->DefineVertex(j, vv->X(), vv->Y());
345 shape->DefineSection(0, -siThick / 2, 1, 0, 0);
346 shape->DefineSection(1, +siThick / 2, 1, 0, 0);
347 shape->SetLineColor(GetLineColor());
349 TObjArray* rots = new TObjArray(nmod);
350 for (Int_t j = 0; j < nmod; j++) {
351 Double_t th = (j + .5) * theta * 2;
352 TString name(Form("FMD_ring_%c_rot_%02d", r->GetId(), j));
353 TString title(Form("FMD Ring %c Rotation # %d", r->GetId(), j));
354 TRotMatrix* rot = new TRotMatrix(name.Data(), title.Data(),
355 90, th, 90, fmod(90+th,360), 0, 0);
359 switch (r->GetId()) {
361 case 'I': innerShape = shape; innerRot = rots; break;
363 case 'O': outerShape = shape; outerRot = rots; break;
368 TNode* top = gAlice->GetGeometry()->GetNode("alice");
370 for (Int_t i = 1; i <= 3; i++) {
371 AliFMDDetector* det = fmd->GetDetector(i);
373 Warning("BuildGeometry", "FMD%d seems to be disabled", i);
377 Double_t rh = det->GetRing('I')->GetHighR();
379 if (det->GetRing('O')) {
380 w = TMath::Abs(det->GetRingZ('O') - det->GetRingZ('I'));
381 id = (TMath::Abs(det->GetRingZ('O'))
382 > TMath::Abs(det->GetRingZ('I')) ? 'O' : 'I');
383 rh = det->GetRing('O')->GetHighR();
385 w += (det->GetRing(id)->GetModuleSpacing() +
386 det->GetRing(id)->GetSiThickness());
387 TShape* shape = new TTUBE(det->GetName(), det->GetTitle(), "void",
388 det->GetRing('I')->GetLowR(), rh, w / 2);
389 Double_t z = (det->GetRingZ('I') - w / 2);
390 if (z > 0) z += det->GetRing(id)->GetModuleSpacing();
392 TNode* node = new TNode(det->GetName(), det->GetTitle(), shape,
396 for (Int_t j = 0; j < 2; j++) {
402 r = det->GetRing('I'); rshape = innerShape; rots = innerRot; break;
404 r = det->GetRing('O'); rshape = outerShape; rots = outerRot; break;
408 Double_t siThick = r->GetSiThickness();
409 Int_t nmod = r->GetNModules();
410 Double_t modspace = r->GetModuleSpacing();
411 Double_t rz = - (z - det->GetRingZ(r->GetId()));
413 for (Int_t k = 0; k < nmod; k++) {
415 Double_t offz = (k % 2 == 1 ? modspace : 0);
416 TRotMatrix* rot = static_cast<TRotMatrix*>(rots->At(k));
417 TString name(Form("%s%c_module_%02d", det->GetName(), r->GetId(),k));
418 TString title(Form("%s%c Module %d", det->GetName(), r->GetId(),k));
419 TNode* mnod = new TNode(name.Data(), title.Data(), rshape,
420 0, 0, rz - siThick / 2
421 + TMath::Sign(offz,z), rot);
422 mnod->SetLineColor(GetLineColor());
424 } // for (Int_t k = 0 ; ...)
425 } // for (Int_t j = 0 ; ...)
426 } // for (Int_t i = 1 ; ...)
429 //____________________________________________________________________
431 AliFMD::DrawDetector()
434 // Draw a shaded view of the Forward multiplicity detector
436 // DebugGuard guard("AliFMD::DrawDetector");
437 AliDebug(10, "\tDraw detector");
440 //Set ALIC mother transparent
441 gMC->Gsatt("ALIC","SEEN",0);
443 gMC->Gdopt("hide", "on");
444 gMC->Gdopt("shad", "on");
445 gMC->Gsatt("*", "fill", 7);
446 gMC->SetClipBox(".");
447 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
449 gMC->Gdraw("alic", 40, 30, 0, 12, 12, .055, .055);
450 gMC->Gdhead(1111, "Forward Multiplicity Detector");
451 gMC->Gdman(16, 10, "MAN");
452 gMC->Gdopt("hide", "off");
456 //____________________________________________________________________
458 AliFMD::DistanceToPrimitive(Int_t, Int_t)
461 // Calculate the distance from the mouse to the FMD on the screen
467 //====================================================================
469 // Hit and Digit managment
471 //____________________________________________________________________
473 AliFMD::MakeBranch(Option_t * option)
475 // Create Tree branches for the FMD.
479 // H Make a branch of TClonesArray of AliFMDHit's
480 // D Make a branch of TClonesArray of AliFMDDigit's
481 // S Make a branch of TClonesArray of AliFMDSDigit's
483 const Int_t kBufferSize = 16000;
484 TString branchname(GetName());
487 if (opt.Contains("H", TString::kIgnoreCase)) {
489 AliDetector::MakeBranch(option);
491 if (opt.Contains("D", TString::kIgnoreCase)) {
493 MakeBranchInTree(fLoader->TreeD(), branchname.Data(),
494 &fDigits, kBufferSize, 0);
496 if (opt.Contains("S", TString::kIgnoreCase)) {
498 MakeBranchInTree(fLoader->TreeS(), branchname.Data(),
499 &fSDigits, kBufferSize, 0);
503 //____________________________________________________________________
505 AliFMD::SetTreeAddress()
507 // Set branch address for the Hits, Digits, and SDigits Tree.
508 if (fLoader->TreeH()) HitsArray();
509 AliDetector::SetTreeAddress();
511 TTree *treeD = fLoader->TreeD();
514 TBranch* branch = treeD->GetBranch ("FMD");
515 if (branch) branch->SetAddress(&fDigits);
518 TTree *treeS = fLoader->TreeS();
521 TBranch* branch = treeS->GetBranch ("FMD");
522 if (branch) branch->SetAddress(&fSDigits);
528 //____________________________________________________________________
530 AliFMD::SetHitsAddressBranch(TBranch *b)
532 // Set the TClonesArray to read hits into.
533 b->SetAddress(&fHits);
536 //____________________________________________________________________
538 AliFMD::AddHit(Int_t track, Int_t *vol, Float_t *hits)
540 // Add a hit to the hits tree
542 // The information of the two arrays are decoded as
546 // ivol[0] [UShort_t ] Detector #
547 // ivol[1] [Char_t ] Ring ID
548 // ivol[2] [UShort_t ] Sector #
549 // ivol[3] [UShort_t ] Strip #
550 // hits[0] [Float_t ] Track's X-coordinate at hit
551 // hits[1] [Float_t ] Track's Y-coordinate at hit
552 // hits[3] [Float_t ] Track's Z-coordinate at hit
553 // hits[4] [Float_t ] X-component of track's momentum
554 // hits[5] [Float_t ] Y-component of track's momentum
555 // hits[6] [Float_t ] Z-component of track's momentum
556 // hits[7] [Float_t ] Energy deposited by track
557 // hits[8] [Int_t ] Track's particle Id #
558 // hits[9] [Float_t ] Time when the track hit
562 UShort_t(vol[0]), // Detector #
563 Char_t(vol[1]), // Ring ID
564 UShort_t(vol[2]), // Sector #
565 UShort_t(vol[3]), // Strip #
572 hits[6], // Energy loss
573 Int_t(hits[7]), // PDG
577 //____________________________________________________________________
579 AliFMD::AddHit(Int_t track,
595 // Add a hit to the list
600 // detector Detector # (1, 2, or 3)
601 // ring Ring ID ('I' or 'O')
602 // sector Sector # (For inner/outer rings: 0-19/0-39)
603 // strip Strip # (For inner/outer rings: 0-511/0-255)
604 // x Track's X-coordinate at hit
605 // y Track's Y-coordinate at hit
606 // z Track's Z-coordinate at hit
607 // px X-component of track's momentum
608 // py Y-component of track's momentum
609 // pz Z-component of track's momentum
610 // edep Energy deposited by track
611 // pdg Track's particle Id #
612 // t Time when the track hit
614 TClonesArray& a = *(HitsArray());
615 // Search through the list of already registered hits, and see if we
616 // find a hit with the same parameters. If we do, then don't create
617 // a new hit, but rather update the energy deposited in the hit.
618 // This is done, so that a FLUKA based simulation will get the
619 // number of hits right, not just the enerrgy deposition.
620 for (Int_t i = 0; i < fNhits; i++) {
621 if (!a.At(i)) continue;
622 AliFMDHit* hit = static_cast<AliFMDHit*>(a.At(i));
623 if (hit->Detector() == detector
624 && hit->Ring() == ring
625 && hit->Sector() == sector
626 && hit->Strip() == strip
627 && hit->Track() == track) {
628 Warning("AddHit", "already had a hit in FMD%d%c[%2d,%3d] for track # %d,"
629 " adding energy (%f) to that hit (%f) -> %f",
630 detector, ring, sector, strip, track, edep, hit->Edep(),
632 hit->SetEdep(hit->Edep() + edep);
636 // If hit wasn't already registered, do so know.
637 new (a[fNhits]) AliFMDHit(fIshunt, track, detector, ring, sector, strip,
638 x, y, z, px, py, pz, edep, pdg, t);
642 //____________________________________________________________________
644 AliFMD::AddDigit(Int_t* digits)
646 // Add a digit to the Digit tree
650 // digits[0] [UShort_t] Detector #
651 // digits[1] [Char_t] Ring ID
652 // digits[2] [UShort_t] Sector #
653 // digits[3] [UShort_t] Strip #
654 // digits[4] [UShort_t] ADC Count
655 // digits[5] [Short_t] ADC Count, -1 if not used
656 // digits[6] [Short_t] ADC Count, -1 if not used
658 AddDigit(UShort_t(digits[0]), // Detector #
659 Char_t(digits[1]), // Ring ID
660 UShort_t(digits[2]), // Sector #
661 UShort_t(digits[3]), // Strip #
662 UShort_t(digits[4]), // ADC Count1
663 Short_t(digits[5]), // ADC Count2
664 Short_t(digits[6])); // ADC Count3
667 //____________________________________________________________________
669 AliFMD::AddDigit(UShort_t detector,
677 // add a real digit - as coming from data
681 // detector Detector # (1, 2, or 3)
682 // ring Ring ID ('I' or 'O')
683 // sector Sector # (For inner/outer rings: 0-19/0-39)
684 // strip Strip # (For inner/outer rings: 0-511/0-255)
685 // count1 ADC count (a 10-bit word)
686 // count2 ADC count (a 10-bit word), or -1 if not used
687 // count3 ADC count (a 10-bit word), or -1 if not used
688 TClonesArray& a = *(DigitsArray());
691 AliFMDDigit(detector, ring, sector, strip, count1, count2, count3);
694 //____________________________________________________________________
696 AliFMD::AddSDigit(Int_t* digits)
698 // Add a digit to the SDigit tree
702 // digits[0] [UShort_t] Detector #
703 // digits[1] [Char_t] Ring ID
704 // digits[2] [UShort_t] Sector #
705 // digits[3] [UShort_t] Strip #
706 // digits[4] [Float_t] Total energy deposited
707 // digits[5] [UShort_t] ADC Count
708 // digits[6] [Short_t] ADC Count, -1 if not used
709 // digits[7] [Short_t] ADC Count, -1 if not used
711 AddSDigit(UShort_t(digits[0]), // Detector #
712 Char_t(digits[1]), // Ring ID
713 UShort_t(digits[2]), // Sector #
714 UShort_t(digits[3]), // Strip #
715 Float_t(digits[4]), // Edep
716 UShort_t(digits[5]), // ADC Count1
717 Short_t(digits[6]), // ADC Count2
718 Short_t(digits[7])); // ADC Count3
721 //____________________________________________________________________
723 AliFMD::AddSDigit(UShort_t detector,
732 // add a summable digit
736 // detector Detector # (1, 2, or 3)
737 // ring Ring ID ('I' or 'O')
738 // sector Sector # (For inner/outer rings: 0-19/0-39)
739 // strip Strip # (For inner/outer rings: 0-511/0-255)
740 // edep Total energy deposited
741 // count1 ADC count (a 10-bit word)
742 // count2 ADC count (a 10-bit word), or -1 if not used
743 // count3 ADC count (a 10-bit word), or -1 if not used
745 TClonesArray& a = *(SDigitsArray());
748 AliFMDSDigit(detector, ring, sector, strip, edep, count1, count2, count3);
751 //____________________________________________________________________
753 AliFMD::ResetSDigits()
756 // Reset number of digits and the digits array for this detector
759 if (fSDigits) fSDigits->Clear();
763 //____________________________________________________________________
767 // Initialize hit array if not already, and return pointer to it.
769 fHits = new TClonesArray("AliFMDHit", 1000);
775 //____________________________________________________________________
777 AliFMD::DigitsArray()
779 // Initialize digit array if not already, and return pointer to it.
781 fDigits = new TClonesArray("AliFMDDigit", 1000);
787 //____________________________________________________________________
789 AliFMD::SDigitsArray()
791 // Initialize digit array if not already, and return pointer to it.
793 fSDigits = new TClonesArray("AliFMDSDigit", 1000);
799 //====================================================================
803 //____________________________________________________________________
805 AliFMD::Hits2Digits()
807 // Create AliFMDDigit's from AliFMDHit's. This is done by making a
808 // AliFMDDigitizer, and executing that code.
810 AliRunDigitizer* manager = new AliRunDigitizer(1, 1);
811 manager->SetInputStream(0, "galice.root");
812 manager->SetOutputFile("H2Dfile");
814 /* AliDigitizer* dig =*/ CreateDigitizer(manager);
818 //____________________________________________________________________
820 AliFMD::Hits2SDigits()
822 // Create AliFMDSDigit's from AliFMDHit's. This is done by creating
823 // an AliFMDSDigitizer object, and executing it.
825 AliFMDSDigitizer* digitizer = new AliFMDSDigitizer("galice.root");
830 //____________________________________________________________________
832 AliFMD::CreateDigitizer(AliRunDigitizer* manager) const
834 // Create a digitizer object
835 AliFMDDigitizer* digitizer = new AliFMDDigitizer(manager);
839 //====================================================================
841 // Raw data simulation
843 //__________________________________________________________________
847 // Turn digits into raw data.
849 // This uses the class AliFMDRawWriter to do the job. Please refer
850 // to that class for more information.
851 AliFMDRawWriter writer(this);
856 //====================================================================
860 //__________________________________________________________________
862 AliFMD::Browse(TBrowser* b)
864 // Browse this object.
866 AliDebug(30, "\tBrowsing the FMD");
867 AliDetector::Browse(b);
868 if (fSimulator) b->Add(fSimulator);
869 b->Add(AliFMDGeometry::Instance());
872 //___________________________________________________________________