]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMD.cxx
Temporary commenting out the TGeo specific geometry (to be fixed soon)
[u/mrichter/AliRoot.git] / FMD / AliFMD.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 //____________________________________________________________________
19 //                                                                          
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. 
24 //                                                       
25 // This is the base class for all FMD manager classes. 
26 //                    
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
30 //
31 //
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 //                  +-----------------+
47 //                           ^              
48 //                           |
49 //             +-------------+-------------+
50 //             |                           |          
51 //    +--------------------+   +-------------------+
52 //    | AliFMDGeoSimulator |   | AliFMDG3Simulator | 
53 //    +--------------------+   +---------+---------+
54 //      
55 //
56 // *  AliFMD 
57 //    This defines the interface for the various parts of AliROOT that
58 //    uses the FMD, like AliFMDSimulator, AliFMDDigitizer, 
59 //    AliFMDReconstructor, and so on. 
60 //
61 // *  AliFMDv0
62 //    This is a concrete implementation of the AliFMD interface. 
63 //    It is the responsibility of this class to create the FMD
64 //    geometry.
65 //
66 // *  AliFMDv1 
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. 
71 //  
72 // *  AliFMDSimulator
73 //    This is the base class for the FMD simulation tasks.   The
74 //    simulator tasks are responsible to implment the geoemtry, and
75 //    process hits. 
76 //                                                                          
77 // *  AliFMDGeoSimulator
78 //    This is a concrete implementation of the AliFMDSimulator that
79 //    uses the TGeo classes directly only. 
80 //
81 // *  AliFMDG3Simulator
82 //    This is a concrete implementation of the AliFMDSimulator that
83 //    uses the TVirtualMC interface with GEANT 3.21-like messages.
84 //
85
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
100
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
117
118 //____________________________________________________________________
119 ClassImp(AliFMD)
120 #if 0
121   ; // This is to keep Emacs from indenting the next line 
122 #endif 
123
124 //____________________________________________________________________
125 AliFMD::AliFMD()
126   : fSDigits(0), 
127     fNsdigits(0),
128     fDetailed(kTRUE),
129     fSimulator(0)
130 {
131   //
132   // Default constructor for class AliFMD
133   //
134   AliDebug(10, "\tDefault CTOR");
135   fHits     = 0;
136   fDigits   = 0;
137   fIshunt   = 0;
138 }
139
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)
147 {
148   // Copy constructor 
149 }
150
151 //____________________________________________________________________
152 AliFMD::AliFMD(const char *name, const char *title)
153   : AliDetector (name, title),
154     fSDigits(0),
155     fNsdigits(0),
156     fDetailed(kTRUE),
157     fSimulator(0)
158 {
159   //
160   // Standard constructor for Forward Multiplicity Detector
161   //
162   AliDebug(10, "\tStandard CTOR");
163
164   // Initialise Hit array
165   HitsArray();
166   gAlice->GetMCApp()->AddHitList(fHits);
167
168   // (S)Digits for the detectors disk
169   DigitsArray();
170   SDigitsArray();
171   
172   // CHC: What is this?
173   fIshunt = 0;
174   SetMarkerColor(kRed);
175   SetLineColor(kYellow);
176 }
177
178 //____________________________________________________________________
179 AliFMD::~AliFMD ()
180 {
181   // Destructor for base class AliFMD
182   if (fHits) {
183     fHits->Delete();
184     delete fHits;
185     fHits = 0;
186   }
187   if (fDigits) {
188     fDigits->Delete();
189     delete fDigits;
190     fDigits = 0;
191   }
192   if (fSDigits) {
193     fSDigits->Delete();
194     delete fSDigits;
195     fSDigits = 0;
196   }
197 }
198
199 //____________________________________________________________________
200 AliFMD&
201 AliFMD::operator=(const AliFMD& other)
202 {
203   AliDetector::operator=(other);
204   fSDigits              = other.fSDigits; 
205   fNsdigits             = other.fNsdigits;
206   fDetailed             = other.fDetailed;
207   fSimulator            = other.fSimulator;
208   
209   return *this;
210 }
211
212 //====================================================================
213 //
214 // GEometry ANd Traking
215 //
216 //____________________________________________________________________
217 void 
218 AliFMD::CreateGeometry()
219 {
220   //
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. 
224   //
225   // The flow of this member function is:
226   //
227   //   FOR rings fInner and fOuter DO  
228   //     AliFMDRing::Init();
229   //   END FOR
230   // 
231   //   Set up hybrud card support (leg) volume shapes  
232   // 
233   //   FOR rings fInner and fOuter DO  
234   //     AliFMDRing::SetupGeometry();
235   //   END FOR
236   // 
237   //   FOR subdetectors fFMD1, fFMD2, and fFMD3 DO 
238   //     AliFMDSubDetector::SetupGeomtry();
239   //   END FOR
240   // 
241   //   FOR subdetectors fFMD1, fFMD2, and fFMD3 DO 
242   //     AliFMDSubDetector::Geomtry();
243   //   END FOR
244   //
245   if (!fSimulator) {
246     AliFatal("Simulator object not made yet!");
247     return;
248   }
249   fSimulator->DefineGeometry();
250 }    
251
252 //____________________________________________________________________
253 void AliFMD::CreateMaterials() 
254 {
255   // Register various materials and tracking mediums with the
256   // backend.   
257   // 
258   AliDebug(10, "\tCreating materials");
259
260   if (fSimulator) {
261     AliFatal("Simulator object already instantised!");
262     return;
263   }
264   AliFMDGeometry* geometry = AliFMDGeometry::Instance();
265   geometry->Init();
266 //   TVirtualMC* mc = TVirtualMC::GetMC();
267 //   Bool_t geo = mc->IsRootGeometrySupported();
268 //   if (geo)
269 //     fSimulator = new AliFMDGeoSimulator(this, fDetailed);
270 //   else 
271     fSimulator = new AliFMDG3Simulator(this, fDetailed);
272   
273   fSimulator->DefineMaterials();
274 }
275
276 //____________________________________________________________________
277 void  
278 AliFMD::Init()
279 {
280   //
281   // Initialis the FMD after it has been built
282   Int_t i;
283   //
284   if (fDebug) {
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;
290     //
291     // Here the FMD initialisation code (if any!)
292     for (i = 0; i < 80; i++) cout << "*";
293     cout << endl;
294   }
295   //
296   //
297 }
298
299 //====================================================================
300 //
301 // Graphics and event display
302 //
303 //____________________________________________________________________
304 void 
305 AliFMD::BuildGeometry()
306 {
307   //
308   // Build simple ROOT TNode geometry for event display
309   //
310   // Build a simplified geometry of the FMD used for event display  
311   // 
312   // The actual building of the TNodes is done by
313   // AliFMDSubDetector::SimpleGeometry. 
314   AliDebug(10, "\tCreating a simplified geometry");
315
316   AliFMDGeometry* fmd = AliFMDGeometry::Instance();
317   
318   static TXTRU*     innerShape = 0;
319   static TXTRU*     outerShape = 0;
320   static TObjArray* innerRot   = 0;
321   static TObjArray* outerRot   = 0;
322
323   if (!innerShape || !outerShape) {
324     // Make the shapes for the modules 
325     for (Int_t i = 0; i < 2; i++) {
326       AliFMDRing* r = 0;
327       switch (i) {
328       case 0: r = fmd->GetRing('I'); break;
329       case 1: r = fmd->GetRing('O'); break;
330       }
331       if (!r) {
332         AliError(Form("no ring found for i=%d", i));
333         return;
334       }
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();
339       
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());
344       }
345       shape->DefineSection(0, -siThick / 2, 1, 0, 0);
346       shape->DefineSection(1, +siThick / 2, 1, 0, 0);
347       shape->SetLineColor(GetLineColor());
348       
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);
356         rots->AddAt(rot, j);
357       }
358       
359       switch (r->GetId()) {
360       case 'i':
361       case 'I': innerShape = shape; innerRot = rots; break;
362       case 'o':
363       case 'O': outerShape = shape; outerRot = rots; break;
364       }
365     }
366   }
367   
368   TNode* top = gAlice->GetGeometry()->GetNode("alice");
369   
370   for (Int_t i = 1; i <= 3; i++) {
371     AliFMDDetector* det = fmd->GetDetector(i);
372     if (!det) {
373       Warning("BuildGeometry", "FMD%d seems to be disabled", i);
374       continue;
375     }
376     Double_t w  = 0;
377     Double_t rh = det->GetRing('I')->GetHighR();
378     Char_t   id = 'I';
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();
384     }
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();
391     top->cd();
392     TNode* node = new TNode(det->GetName(), det->GetTitle(), shape, 
393                             0, 0, z, 0);
394     fNodes->Add(node);
395     
396     for (Int_t j = 0; j < 2; j++) {
397       AliFMDRing* r      = 0;
398       TShape*     rshape = 0;
399       TObjArray*  rots   = 0;
400       switch (j) {
401       case 0: 
402         r = det->GetRing('I'); rshape = innerShape; rots = innerRot; break;
403       case 1: 
404         r = det->GetRing('O'); rshape = outerShape; rots = outerRot; break;
405       }
406       if (!r) continue;
407       
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()));
412       
413       for (Int_t k = 0; k < nmod; k++) {
414         node->cd();
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());
423         fNodes->Add(mnod);
424       } // for (Int_t k = 0 ; ...)
425     } // for (Int_t j = 0 ; ...)
426   } // for (Int_t i = 1 ; ...)
427 }
428
429 //____________________________________________________________________
430 void 
431 AliFMD::DrawDetector()
432 {
433   //
434   // Draw a shaded view of the Forward multiplicity detector
435   //
436   // DebugGuard guard("AliFMD::DrawDetector");
437   AliDebug(10, "\tDraw detector");
438   
439 #if 0
440   //Set ALIC mother transparent
441   gMC->Gsatt("ALIC","SEEN",0);
442   //
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);
448   gMC->DefaultRange();
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");
453 #endif
454 }
455
456 //____________________________________________________________________
457 Int_t 
458 AliFMD::DistanceToPrimitive(Int_t, Int_t)
459 {
460   //
461   // Calculate the distance from the mouse to the FMD on the screen
462   // Dummy routine
463   //
464   return 9999;
465 }
466
467 //====================================================================
468 //
469 // Hit and Digit managment 
470 //
471 //____________________________________________________________________
472 void 
473 AliFMD::MakeBranch(Option_t * option)
474 {
475   // Create Tree branches for the FMD.
476   //
477   // Options:
478   //
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
482   // 
483   const Int_t kBufferSize = 16000;
484   TString branchname(GetName());
485   TString opt(option);
486   
487   if (opt.Contains("H", TString::kIgnoreCase)) {
488     HitsArray();
489     AliDetector::MakeBranch(option); 
490   }
491   if (opt.Contains("D", TString::kIgnoreCase)) { 
492     DigitsArray();
493     MakeBranchInTree(fLoader->TreeD(), branchname.Data(),
494                      &fDigits, kBufferSize, 0);
495   }
496   if (opt.Contains("S", TString::kIgnoreCase)) { 
497     SDigitsArray();
498     MakeBranchInTree(fLoader->TreeS(), branchname.Data(),
499                      &fSDigits, kBufferSize, 0);
500   }
501 }
502
503 //____________________________________________________________________
504 void 
505 AliFMD::SetTreeAddress()
506 {
507   // Set branch address for the Hits, Digits, and SDigits Tree.
508   if (fLoader->TreeH()) HitsArray();
509   AliDetector::SetTreeAddress();
510
511   TTree *treeD = fLoader->TreeD();
512   if (treeD) {
513     DigitsArray();
514     TBranch* branch = treeD->GetBranch ("FMD");
515     if (branch) branch->SetAddress(&fDigits);
516   }
517
518   TTree *treeS = fLoader->TreeS();
519   if (treeS) {
520     SDigitsArray();
521     TBranch* branch = treeS->GetBranch ("FMD");
522     if (branch) branch->SetAddress(&fSDigits);
523   }
524 }
525
526
527
528 //____________________________________________________________________
529 void 
530 AliFMD::SetHitsAddressBranch(TBranch *b)
531 {
532   // Set the TClonesArray to read hits into. 
533   b->SetAddress(&fHits);
534 }
535
536 //____________________________________________________________________
537 void 
538 AliFMD::AddHit(Int_t track, Int_t *vol, Float_t *hits) 
539 {
540   // Add a hit to the hits tree 
541   // 
542   // The information of the two arrays are decoded as 
543   // 
544   // Parameters
545   //    track                Track #
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
559   // 
560   // 
561   AddHitByFields(track, 
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 # 
566                  hits[0],           // X
567                  hits[1],           // Y
568                  hits[2],           // Z
569                  hits[3],           // Px
570                  hits[4],           // Py
571                  hits[5],           // Pz
572                  hits[6],           // Energy loss 
573                  Int_t(hits[7]),    // PDG 
574                  hits[8]);          // Time
575 }
576
577 //____________________________________________________________________
578 void 
579 AliFMD::AddHitByFields(Int_t    track, 
580                        UShort_t detector, 
581                        Char_t   ring, 
582                        UShort_t sector, 
583                        UShort_t strip, 
584                        Float_t  x, 
585                        Float_t  y, 
586                        Float_t  z,
587                        Float_t  px, 
588                        Float_t  py, 
589                        Float_t  pz,
590                        Float_t  edep,
591                        Int_t    pdg,
592                        Float_t  t)
593 {
594   //
595   // Add a hit to the list
596   //
597   // Parameters:
598   // 
599   //    track     Track #
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 
613   // 
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(),
631               hit->Edep() + edep);
632       hit->SetEdep(hit->Edep() + edep);
633       return;
634     }
635   }
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);
639   fNhits++;
640 }
641
642 //____________________________________________________________________
643 void 
644 AliFMD::AddDigit(Int_t* digits, Int_t*)
645 {
646   // Add a digit to the Digit tree 
647   // 
648   // Paramters 
649   //
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 
657   // 
658   AddDigitByFields(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 
665 }
666
667 //____________________________________________________________________
668 void 
669 AliFMD::AddDigitByFields(UShort_t detector, 
670                          Char_t   ring, 
671                          UShort_t sector, 
672                          UShort_t strip, 
673                          UShort_t count1, 
674                          Short_t  count2,
675                          Short_t  count3)
676 {
677   // add a real digit - as coming from data
678   // 
679   // Parameters 
680   //
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());
689   
690   new (a[fNdigits++]) 
691     AliFMDDigit(detector, ring, sector, strip, count1, count2, count3);
692 }
693
694 //____________________________________________________________________
695 void 
696 AliFMD::AddSDigit(Int_t* digits)
697 {
698   // Add a digit to the SDigit tree 
699   // 
700   // Paramters 
701   //
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 
710   // 
711   AddSDigitByFields(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 
719 }
720
721 //____________________________________________________________________
722 void 
723 AliFMD::AddSDigitByFields(UShort_t detector, 
724                           Char_t   ring, 
725                           UShort_t sector, 
726                           UShort_t strip, 
727                           Float_t  edep,
728                           UShort_t count1, 
729                           Short_t  count2,
730                           Short_t  count3)
731 {
732   // add a summable digit
733   // 
734   // Parameters 
735   //
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
744   //
745   TClonesArray& a = *(SDigitsArray());
746   
747   new (a[fNsdigits++]) 
748     AliFMDSDigit(detector, ring, sector, strip, edep, count1, count2, count3);
749 }
750
751 //____________________________________________________________________
752 void 
753 AliFMD::ResetSDigits()
754 {
755   //
756   // Reset number of digits and the digits array for this detector
757   //
758   fNsdigits   = 0;
759   if (fSDigits) fSDigits->Clear();
760 }
761
762
763 //____________________________________________________________________
764 TClonesArray*
765 AliFMD::HitsArray() 
766 {
767   // Initialize hit array if not already, and return pointer to it. 
768   if (!fHits) { 
769     fHits = new TClonesArray("AliFMDHit", 1000);
770     fNhits = 0;
771   }
772   return fHits;
773 }
774
775 //____________________________________________________________________
776 TClonesArray*
777 AliFMD::DigitsArray() 
778 {
779   // Initialize digit array if not already, and return pointer to it. 
780   if (!fDigits) { 
781     fDigits = new TClonesArray("AliFMDDigit", 1000);
782     fNdigits = 0;
783   }
784   return fDigits;
785 }
786
787 //____________________________________________________________________
788 TClonesArray*
789 AliFMD::SDigitsArray() 
790 {
791   // Initialize digit array if not already, and return pointer to it. 
792   if (!fSDigits) { 
793     fSDigits = new TClonesArray("AliFMDSDigit", 1000);
794     fNsdigits = 0;
795   }
796   return fSDigits;
797 }
798
799 //====================================================================
800 //
801 // Digitization 
802 //
803 //____________________________________________________________________
804 void 
805 AliFMD::Hits2Digits() 
806 {
807   // Create AliFMDDigit's from AliFMDHit's.  This is done by making a
808   // AliFMDDigitizer, and executing that code.
809   // 
810   AliRunDigitizer* manager = new AliRunDigitizer(1, 1);
811   manager->SetInputStream(0, "galice.root");
812   manager->SetOutputFile("H2Dfile");
813   
814   /* AliDigitizer* dig =*/ CreateDigitizer(manager);
815   manager->Exec("");
816 }
817
818 //____________________________________________________________________
819 void 
820 AliFMD::Hits2SDigits() 
821 {
822   // Create AliFMDSDigit's from AliFMDHit's.  This is done by creating
823   // an AliFMDSDigitizer object, and executing it. 
824   // 
825   AliFMDSDigitizer* digitizer = new AliFMDSDigitizer("galice.root");
826   digitizer->Exec("");
827 }
828
829   
830 //____________________________________________________________________
831 AliDigitizer* 
832 AliFMD::CreateDigitizer(AliRunDigitizer* manager) const
833 {
834   // Create a digitizer object 
835   AliFMDDigitizer* digitizer = new AliFMDDigitizer(manager);
836   return digitizer;
837 }
838
839 //====================================================================
840 //
841 // Raw data simulation 
842 //
843 //__________________________________________________________________
844 void 
845 AliFMD::Digits2Raw() 
846 {
847   // Turn digits into raw data. 
848   // 
849   // This uses the class AliFMDRawWriter to do the job.   Please refer
850   // to that class for more information. 
851   AliFMDRawWriter writer(this);
852   writer.Exec();
853 }
854
855
856 //====================================================================
857 //
858 // Utility 
859 //
860 //__________________________________________________________________
861 void 
862 AliFMD::Browse(TBrowser* b) 
863 {
864   // Browse this object. 
865   //
866   AliDebug(30, "\tBrowsing the FMD");
867   AliDetector::Browse(b);
868   if (fSimulator) b->Add(fSimulator);
869   b->Add(AliFMDGeometry::Instance());
870 }
871
872 //___________________________________________________________________
873 //
874 // EOF
875 //