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 //____________________________________________________________________
133 // Default constructor for class AliFMD
135 AliDebug(10, "\tDefault CTOR");
141 //____________________________________________________________________
142 AliFMD::AliFMD(const AliFMD& other)
143 : AliDetector(other),
144 fSDigits(other.fSDigits),
145 fNsdigits(other.fNsdigits),
146 fDetailed(other.fDetailed),
147 fSimulator(other.fSimulator)
152 //____________________________________________________________________
153 AliFMD::AliFMD(const char *name, const char *title)
154 : AliDetector (name, title),
161 // Standard constructor for Forward Multiplicity Detector
163 AliDebug(10, "\tStandard CTOR");
165 // Initialise Hit array
167 gAlice->GetMCApp()->AddHitList(fHits);
169 // (S)Digits for the detectors disk
173 // CHC: What is this?
175 SetMarkerColor(kRed);
176 SetLineColor(kYellow);
179 //____________________________________________________________________
182 // Destructor for base class AliFMD
200 //____________________________________________________________________
202 AliFMD::operator=(const AliFMD& other)
204 AliDetector::operator=(other);
205 fSDigits = other.fSDigits;
206 fNsdigits = other.fNsdigits;
207 fDetailed = other.fDetailed;
208 fSimulator = other.fSimulator;
213 //====================================================================
215 // GEometry ANd Traking
217 //____________________________________________________________________
219 AliFMD::CreateGeometry()
222 // Create the geometry of Forward Multiplicity Detector. The actual
223 // construction of the geometry is delegated to the class AliFMDRing
224 // and AliFMDSubDetector and the relevant derived classes.
226 // The flow of this member function is:
228 // FOR rings fInner and fOuter DO
229 // AliFMDRing::Init();
232 // Set up hybrud card support (leg) volume shapes
234 // FOR rings fInner and fOuter DO
235 // AliFMDRing::SetupGeometry();
238 // FOR subdetectors fFMD1, fFMD2, and fFMD3 DO
239 // AliFMDSubDetector::SetupGeomtry();
242 // FOR subdetectors fFMD1, fFMD2, and fFMD3 DO
243 // AliFMDSubDetector::Geomtry();
247 AliFatal("Simulator object not made yet!");
250 fSimulator->DefineGeometry();
253 //____________________________________________________________________
254 void AliFMD::CreateMaterials()
256 // Register various materials and tracking mediums with the
259 AliDebug(10, "\tCreating materials");
262 AliFatal("Simulator object already instantised!");
265 AliFMDGeometry* geometry = AliFMDGeometry::Instance();
267 // TVirtualMC* mc = TVirtualMC::GetMC();
268 // Bool_t geo = mc->IsRootGeometrySupported();
270 // fSimulator = new AliFMDGeoSimulator(this, fDetailed);
272 fSimulator = new AliFMDG3Simulator(this, fDetailed);
274 fSimulator->DefineMaterials();
277 //____________________________________________________________________
282 // Initialis the FMD after it has been built
285 if (AliLog::GetGlobalDebugLevel()) {
286 cout << "\n" << ClassName() << ": " << flush;
287 for (i = 0; i < 35; i++) cout << "*";
288 cout << " FMD_INIT ";
289 for (i = 0; i < 35; i++) cout << "*";
290 cout << "\n" << ClassName() << ": " << flush;
292 // Here the FMD initialisation code (if any!)
293 for (i = 0; i < 80; i++) cout << "*";
300 //====================================================================
302 // Graphics and event display
304 //____________________________________________________________________
306 AliFMD::BuildGeometry()
309 // Build simple ROOT TNode geometry for event display
311 // Build a simplified geometry of the FMD used for event display
313 // The actual building of the TNodes is done by
314 // AliFMDSubDetector::SimpleGeometry.
315 AliDebug(10, "\tCreating a simplified geometry");
317 AliFMDGeometry* fmd = AliFMDGeometry::Instance();
319 static TXTRU* innerShape = 0;
320 static TXTRU* outerShape = 0;
321 static TObjArray* innerRot = 0;
322 static TObjArray* outerRot = 0;
324 if (!innerShape || !outerShape) {
325 // Make the shapes for the modules
326 for (Int_t i = 0; i < 2; i++) {
329 case 0: r = fmd->GetRing('I'); break;
330 case 1: r = fmd->GetRing('O'); break;
333 AliError(Form("no ring found for i=%d", i));
336 Double_t siThick = r->GetSiThickness();
337 const Int_t nv = r->GetNVerticies();
338 Double_t theta = r->GetTheta();
339 Int_t nmod = r->GetNModules();
341 TXTRU* shape = new TXTRU(r->GetName(), r->GetTitle(), "void", nv, 2);
342 for (Int_t j = 0; j < nv; j++) {
343 TVector2* vv = r->GetVertex(nv - 1 - j);
344 shape->DefineVertex(j, vv->X(), vv->Y());
346 shape->DefineSection(0, -siThick / 2, 1, 0, 0);
347 shape->DefineSection(1, +siThick / 2, 1, 0, 0);
348 shape->SetLineColor(GetLineColor());
350 TObjArray* rots = new TObjArray(nmod);
351 for (Int_t j = 0; j < nmod; j++) {
352 Double_t th = (j + .5) * theta * 2;
353 TString name(Form("FMD_ring_%c_rot_%02d", r->GetId(), j));
354 TString title(Form("FMD Ring %c Rotation # %d", r->GetId(), j));
355 TRotMatrix* rot = new TRotMatrix(name.Data(), title.Data(),
356 90, th, 90, fmod(90+th,360), 0, 0);
360 switch (r->GetId()) {
362 case 'I': innerShape = shape; innerRot = rots; break;
364 case 'O': outerShape = shape; outerRot = rots; break;
369 TNode* top = gAlice->GetGeometry()->GetNode("alice");
371 for (Int_t i = 1; i <= 3; i++) {
372 AliFMDDetector* det = fmd->GetDetector(i);
374 Warning("BuildGeometry", "FMD%d seems to be disabled", i);
378 Double_t rh = det->GetRing('I')->GetHighR();
380 if (det->GetRing('O')) {
381 w = TMath::Abs(det->GetRingZ('O') - det->GetRingZ('I'));
382 id = (TMath::Abs(det->GetRingZ('O'))
383 > TMath::Abs(det->GetRingZ('I')) ? 'O' : 'I');
384 rh = det->GetRing('O')->GetHighR();
386 w += (det->GetRing(id)->GetModuleSpacing() +
387 det->GetRing(id)->GetSiThickness());
388 TShape* shape = new TTUBE(det->GetName(), det->GetTitle(), "void",
389 det->GetRing('I')->GetLowR(), rh, w / 2);
390 Double_t z = (det->GetRingZ('I') - w / 2);
391 if (z > 0) z += det->GetRing(id)->GetModuleSpacing();
393 TNode* node = new TNode(det->GetName(), det->GetTitle(), shape,
397 for (Int_t j = 0; j < 2; j++) {
403 r = det->GetRing('I'); rshape = innerShape; rots = innerRot; break;
405 r = det->GetRing('O'); rshape = outerShape; rots = outerRot; break;
409 Double_t siThick = r->GetSiThickness();
410 Int_t nmod = r->GetNModules();
411 Double_t modspace = r->GetModuleSpacing();
412 Double_t rz = - (z - det->GetRingZ(r->GetId()));
414 for (Int_t k = 0; k < nmod; k++) {
416 Double_t offz = (k % 2 == 1 ? modspace : 0);
417 TRotMatrix* rot = static_cast<TRotMatrix*>(rots->At(k));
418 TString name(Form("%s%c_module_%02d", det->GetName(), r->GetId(),k));
419 TString title(Form("%s%c Module %d", det->GetName(), r->GetId(),k));
420 TNode* mnod = new TNode(name.Data(), title.Data(), rshape,
421 0, 0, rz - siThick / 2
422 + TMath::Sign(offz,z), rot);
423 mnod->SetLineColor(GetLineColor());
425 } // for (Int_t k = 0 ; ...)
426 } // for (Int_t j = 0 ; ...)
427 } // for (Int_t i = 1 ; ...)
430 //____________________________________________________________________
432 AliFMD::DrawDetector()
435 // Draw a shaded view of the Forward multiplicity detector
437 // DebugGuard guard("AliFMD::DrawDetector");
438 AliDebug(10, "\tDraw detector");
441 //Set ALIC mother transparent
442 gMC->Gsatt("ALIC","SEEN",0);
444 gMC->Gdopt("hide", "on");
445 gMC->Gdopt("shad", "on");
446 gMC->Gsatt("*", "fill", 7);
447 gMC->SetClipBox(".");
448 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
450 gMC->Gdraw("alic", 40, 30, 0, 12, 12, .055, .055);
451 gMC->Gdhead(1111, "Forward Multiplicity Detector");
452 gMC->Gdman(16, 10, "MAN");
453 gMC->Gdopt("hide", "off");
457 //____________________________________________________________________
459 AliFMD::DistanceToPrimitive(Int_t, Int_t)
462 // Calculate the distance from the mouse to the FMD on the screen
468 //====================================================================
470 // Hit and Digit managment
472 //____________________________________________________________________
474 AliFMD::MakeBranch(Option_t * option)
476 // Create Tree branches for the FMD.
480 // H Make a branch of TClonesArray of AliFMDHit's
481 // D Make a branch of TClonesArray of AliFMDDigit's
482 // S Make a branch of TClonesArray of AliFMDSDigit's
484 const Int_t kBufferSize = 16000;
485 TString branchname(GetName());
488 if (opt.Contains("H", TString::kIgnoreCase)) {
490 AliDetector::MakeBranch(option);
492 if (opt.Contains("D", TString::kIgnoreCase)) {
494 MakeBranchInTree(fLoader->TreeD(), branchname.Data(),
495 &fDigits, kBufferSize, 0);
497 if (opt.Contains("S", TString::kIgnoreCase)) {
499 MakeBranchInTree(fLoader->TreeS(), branchname.Data(),
500 &fSDigits, kBufferSize, 0);
504 //____________________________________________________________________
506 AliFMD::SetTreeAddress()
508 // Set branch address for the Hits, Digits, and SDigits Tree.
509 if (fLoader->TreeH()) HitsArray();
510 AliDetector::SetTreeAddress();
512 TTree *treeD = fLoader->TreeD();
515 TBranch* branch = treeD->GetBranch ("FMD");
516 if (branch) branch->SetAddress(&fDigits);
519 TTree *treeS = fLoader->TreeS();
522 TBranch* branch = treeS->GetBranch ("FMD");
523 if (branch) branch->SetAddress(&fSDigits);
529 //____________________________________________________________________
531 AliFMD::SetHitsAddressBranch(TBranch *b)
533 // Set the TClonesArray to read hits into.
534 b->SetAddress(&fHits);
537 //____________________________________________________________________
539 AliFMD::AddHit(Int_t track, Int_t *vol, Float_t *hits)
541 // Add a hit to the hits tree
543 // The information of the two arrays are decoded as
547 // ivol[0] [UShort_t ] Detector #
548 // ivol[1] [Char_t ] Ring ID
549 // ivol[2] [UShort_t ] Sector #
550 // ivol[3] [UShort_t ] Strip #
551 // hits[0] [Float_t ] Track's X-coordinate at hit
552 // hits[1] [Float_t ] Track's Y-coordinate at hit
553 // hits[3] [Float_t ] Track's Z-coordinate at hit
554 // hits[4] [Float_t ] X-component of track's momentum
555 // hits[5] [Float_t ] Y-component of track's momentum
556 // hits[6] [Float_t ] Z-component of track's momentum
557 // hits[7] [Float_t ] Energy deposited by track
558 // hits[8] [Int_t ] Track's particle Id #
559 // hits[9] [Float_t ] Time when the track hit
562 AddHitByFields(track,
563 UShort_t(vol[0]), // Detector #
564 Char_t(vol[1]), // Ring ID
565 UShort_t(vol[2]), // Sector #
566 UShort_t(vol[3]), // Strip #
573 hits[6], // Energy loss
574 Int_t(hits[7]), // PDG
578 //____________________________________________________________________
580 AliFMD::AddHitByFields(Int_t track,
596 // Add a hit to the list
601 // detector Detector # (1, 2, or 3)
602 // ring Ring ID ('I' or 'O')
603 // sector Sector # (For inner/outer rings: 0-19/0-39)
604 // strip Strip # (For inner/outer rings: 0-511/0-255)
605 // x Track's X-coordinate at hit
606 // y Track's Y-coordinate at hit
607 // z Track's Z-coordinate at hit
608 // px X-component of track's momentum
609 // py Y-component of track's momentum
610 // pz Z-component of track's momentum
611 // edep Energy deposited by track
612 // pdg Track's particle Id #
613 // t Time when the track hit
615 TClonesArray& a = *(HitsArray());
616 // Search through the list of already registered hits, and see if we
617 // find a hit with the same parameters. If we do, then don't create
618 // a new hit, but rather update the energy deposited in the hit.
619 // This is done, so that a FLUKA based simulation will get the
620 // number of hits right, not just the enerrgy deposition.
621 for (Int_t i = 0; i < fNhits; i++) {
622 if (!a.At(i)) continue;
623 AliFMDHit* hit = static_cast<AliFMDHit*>(a.At(i));
624 if (hit->Detector() == detector
625 && hit->Ring() == ring
626 && hit->Sector() == sector
627 && hit->Strip() == strip
628 && hit->Track() == track) {
629 Warning("AddHit", "already had a hit in FMD%d%c[%2d,%3d] for track # %d,"
630 " adding energy (%f) to that hit (%f) -> %f",
631 detector, ring, sector, strip, track, edep, hit->Edep(),
633 hit->SetEdep(hit->Edep() + edep);
637 // If hit wasn't already registered, do so know.
638 new (a[fNhits]) AliFMDHit(fIshunt, track, detector, ring, sector, strip,
639 x, y, z, px, py, pz, edep, pdg, t);
643 //____________________________________________________________________
645 AliFMD::AddDigit(Int_t* digits, Int_t*)
647 // Add a digit to the Digit tree
651 // digits[0] [UShort_t] Detector #
652 // digits[1] [Char_t] Ring ID
653 // digits[2] [UShort_t] Sector #
654 // digits[3] [UShort_t] Strip #
655 // digits[4] [UShort_t] ADC Count
656 // digits[5] [Short_t] ADC Count, -1 if not used
657 // digits[6] [Short_t] ADC Count, -1 if not used
659 AddDigitByFields(UShort_t(digits[0]), // Detector #
660 Char_t(digits[1]), // Ring ID
661 UShort_t(digits[2]), // Sector #
662 UShort_t(digits[3]), // Strip #
663 UShort_t(digits[4]), // ADC Count1
664 Short_t(digits[5]), // ADC Count2
665 Short_t(digits[6])); // ADC Count3
668 //____________________________________________________________________
670 AliFMD::AddDigitByFields(UShort_t detector,
678 // add a real digit - as coming from data
682 // detector Detector # (1, 2, or 3)
683 // ring Ring ID ('I' or 'O')
684 // sector Sector # (For inner/outer rings: 0-19/0-39)
685 // strip Strip # (For inner/outer rings: 0-511/0-255)
686 // count1 ADC count (a 10-bit word)
687 // count2 ADC count (a 10-bit word), or -1 if not used
688 // count3 ADC count (a 10-bit word), or -1 if not used
689 TClonesArray& a = *(DigitsArray());
692 AliFMDDigit(detector, ring, sector, strip, count1, count2, count3);
695 //____________________________________________________________________
697 AliFMD::AddSDigit(Int_t* digits)
699 // Add a digit to the SDigit tree
703 // digits[0] [UShort_t] Detector #
704 // digits[1] [Char_t] Ring ID
705 // digits[2] [UShort_t] Sector #
706 // digits[3] [UShort_t] Strip #
707 // digits[4] [Float_t] Total energy deposited
708 // digits[5] [UShort_t] ADC Count
709 // digits[6] [Short_t] ADC Count, -1 if not used
710 // digits[7] [Short_t] ADC Count, -1 if not used
712 AddSDigitByFields(UShort_t(digits[0]), // Detector #
713 Char_t(digits[1]), // Ring ID
714 UShort_t(digits[2]), // Sector #
715 UShort_t(digits[3]), // Strip #
716 Float_t(digits[4]), // Edep
717 UShort_t(digits[5]), // ADC Count1
718 Short_t(digits[6]), // ADC Count2
719 Short_t(digits[7])); // ADC Count3
722 //____________________________________________________________________
724 AliFMD::AddSDigitByFields(UShort_t detector,
733 // add a summable digit
737 // detector Detector # (1, 2, or 3)
738 // ring Ring ID ('I' or 'O')
739 // sector Sector # (For inner/outer rings: 0-19/0-39)
740 // strip Strip # (For inner/outer rings: 0-511/0-255)
741 // edep Total energy deposited
742 // count1 ADC count (a 10-bit word)
743 // count2 ADC count (a 10-bit word), or -1 if not used
744 // count3 ADC count (a 10-bit word), or -1 if not used
746 TClonesArray& a = *(SDigitsArray());
749 AliFMDSDigit(detector, ring, sector, strip, edep, count1, count2, count3);
752 //____________________________________________________________________
754 AliFMD::ResetSDigits()
757 // Reset number of digits and the digits array for this detector
760 if (fSDigits) fSDigits->Clear();
764 //____________________________________________________________________
768 // Initialize hit array if not already, and return pointer to it.
770 fHits = new TClonesArray("AliFMDHit", 1000);
776 //____________________________________________________________________
778 AliFMD::DigitsArray()
780 // Initialize digit array if not already, and return pointer to it.
782 fDigits = new TClonesArray("AliFMDDigit", 1000);
788 //____________________________________________________________________
790 AliFMD::SDigitsArray()
792 // Initialize digit array if not already, and return pointer to it.
794 fSDigits = new TClonesArray("AliFMDSDigit", 1000);
800 //====================================================================
804 //____________________________________________________________________
806 AliFMD::Hits2Digits()
808 // Create AliFMDDigit's from AliFMDHit's. This is done by making a
809 // AliFMDDigitizer, and executing that code.
811 AliRunDigitizer* manager = new AliRunDigitizer(1, 1);
812 manager->SetInputStream(0, "galice.root");
813 manager->SetOutputFile("H2Dfile");
815 /* AliDigitizer* dig =*/ CreateDigitizer(manager);
820 //____________________________________________________________________
822 AliFMD::Hits2SDigits()
824 // Create AliFMDSDigit's from AliFMDHit's. This is done by creating
825 // an AliFMDSDigitizer object, and executing it.
827 AliFMDSDigitizer* digitizer = new AliFMDSDigitizer("galice.root");
833 //____________________________________________________________________
835 AliFMD::CreateDigitizer(AliRunDigitizer* manager) const
837 // Create a digitizer object
838 AliFMDDigitizer* digitizer = new AliFMDDigitizer(manager);
842 //====================================================================
844 // Raw data simulation
846 //__________________________________________________________________
850 // Turn digits into raw data.
852 // This uses the class AliFMDRawWriter to do the job. Please refer
853 // to that class for more information.
854 AliFMDRawWriter writer(this);
859 //====================================================================
863 //__________________________________________________________________
865 AliFMD::Browse(TBrowser* b)
867 // Browse this object.
869 AliDebug(30, "\tBrowsing the FMD");
870 AliDetector::Browse(b);
871 if (fSimulator) b->Add(fSimulator);
872 b->Add(AliFMDGeometry::Instance());
875 //___________________________________________________________________