Additional protection
[u/mrichter/AliRoot.git] / FMD / AliFMD.cxx
CommitLineData
4c039060 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 **************************************************************************/
88cb7938 15
16/* $Id$ */
17
e802be3e 18//____________________________________________________________________
4347b38f 19//
37c4363a 20// Forward Multiplicity Detector based on Silicon wafers. This class
21// contains the base procedures for the Forward Multiplicity detector
1a1fdef7 22// Detector consists of 3 sub-detectors FMD1, FMD2, and FMD3, each of
23// which has 1 or 2 rings of silicon sensors.
37c4363a 24//
25// This is the base class for all FMD manager classes.
26//
4347b38f 27// The actual code is done by various separate classes. Below is
28// diagram showing the relationship between the various FMD classes
1a1fdef7 29// that handles the simulation
4347b38f 30//
31//
32// +----------+ +----------+
1a1fdef7 33// | AliFMDv1 | | AliFMDv0 |
4347b38f 34// +----------+ +----------+
1a1fdef7 35// | | +-----------------+
36// +----+--------------+ +--| AliFMDDigitizer |
37// | | +-----------------+
38// | +---------------------+ |
4ac75127 39// | +--| AliFMDBaseDigitizer |<--+
1a1fdef7 40// V 1 | +---------------------+ |
41// +--------+<>--+ | +------------------+
42// | AliFMD | +--| AliFMDSDigitizer |
43// +--------+<>--+ +------------------+
4ac75127 44// 1 | +-----------------+
45// +--| AliFMDSimulator |
46// +-----------------+
47// ^
48// |
49// +-------------+-------------+
50// | |
51// +--------------------+ +-------------------+
52// | AliFMDGeoSimulator | | AliFMDG3Simulator |
53// +--------------------+ +-------------------+
54// ^ ^
55// | |
56// +-----------------------+ +----------------------+
57// | AliFMDGeoOldSimulator | | AliFMDG3OldSimulator |
58// +-----------------------+ +----------------------+
4347b38f 59//
60//
61// * AliFMD
62// This defines the interface for the various parts of AliROOT that
1a1fdef7 63// uses the FMD, like AliFMDSimulator, AliFMDDigitizer,
64// AliFMDReconstructor, and so on.
65//
66// * AliFMDv0
67// This is a concrete implementation of the AliFMD interface.
68// It is the responsibility of this class to create the FMD
69// geometry.
4347b38f 70//
71// * AliFMDv1
72// This is a concrete implementation of the AliFMD interface.
73// It is the responsibility of this class to create the FMD
74// geometry, process hits in the FMD, and serve hits and digits to
75// the various clients.
76//
1a1fdef7 77// * AliFMDSimulator
78// This is the base class for the FMD simulation tasks. The
79// simulator tasks are responsible to implment the geoemtry, and
80// process hits.
4347b38f 81//
1a1fdef7 82// * AliFMDGeoSimulator
83// This is a concrete implementation of the AliFMDSimulator that
84// uses the TGeo classes directly only.
37c4363a 85//
1a1fdef7 86// * AliFMDG3Simulator
87// This is a concrete implementation of the AliFMDSimulator that
88// uses the TVirtualMC interface with GEANT 3.21-like messages.
37c4363a 89//
fe4da5cc 90
56b1929b 91// These files are not in the same directory, so there's no reason to
92// ask the preprocessor to search in the current directory for these
93// files by including them with `#include "..."'
1a1fdef7 94#include <math.h> // __CMATH__
56b1929b 95#include <TClonesArray.h> // ROOT_TClonesArray
96#include <TGeometry.h> // ROOT_TGeomtry
97#include <TNode.h> // ROOT_TNode
1a1fdef7 98#include <TXTRU.h> // ROOT_TXTRU
99#include <TRotMatrix.h> // ROOT_TRotMatrix
56b1929b 100#include <TTUBE.h> // ROOT_TTUBE
101#include <TTree.h> // ROOT_TTree
56b1929b 102#include <TBrowser.h> // ROOT_TBrowser
103#include <TMath.h> // ROOT_TMath
1a1fdef7 104#include <TVirtualMC.h> // ROOT_TVirtualMC
56b1929b 105
106#include <AliRunDigitizer.h> // ALIRUNDIGITIZER_H
107#include <AliLoader.h> // ALILOADER_H
108#include <AliRun.h> // ALIRUN_H
109#include <AliMC.h> // ALIMC_H
110#include <AliLog.h> // ALILOG_H
e802be3e 111#include "AliFMD.h" // ALIFMD_H
112#include "AliFMDDigit.h" // ALIFMDDIGIG_H
113#include "AliFMDHit.h" // ALIFMDHIT_H
1a1fdef7 114#include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
115#include "AliFMDDetector.h" // ALIFMDDETECTOR_H
116#include "AliFMDRing.h" // ALIFMDRING_H
e802be3e 117#include "AliFMDDigitizer.h" // ALIFMDDIGITIZER_H
1a1fdef7 118#include "AliFMDSimulator.h" // ALIFMDSIMULATOR_H
119#include "AliFMDG3Simulator.h" // ALIFMDG3SIMULATOR_H
120#include "AliFMDGeoSimulator.h" // ALIFMDGEOSIMULATOR_H
4ac75127 121#include "AliFMDG3OldSimulator.h" // ALIFMDG3OLDSIMULATOR_H
122#include "AliFMDGeoOldSimulator.h" // ALIFMDGEOOLDSIMULATOR_H
e802be3e 123#include "AliFMDRawWriter.h" // ALIFMDRAWWRITER_H
88cb7938 124
4347b38f 125//____________________________________________________________________
925e6570 126ClassImp(AliFMD)
1a1fdef7 127#if 0
128 ; // This is to keep Emacs from indenting the next line
129#endif
7e54281f 130
131//____________________________________________________________________
4347b38f 132AliFMD::AliFMD()
90da4514 133 : AliDetector(),
134 fSDigits(0),
afddaa11 135 fNsdigits(0),
1a1fdef7 136 fDetailed(kTRUE),
137 fSimulator(0)
fe4da5cc 138{
139 //
140 // Default constructor for class AliFMD
141 //
1a1fdef7 142 AliDebug(10, "\tDefault CTOR");
4ac75127 143 fHits = 0;
144 fDigits = 0;
145 fIshunt = 0;
146 fUseOld = kFALSE;
147 fUseDivided = kFALSE;
148 fUseAssembly = kFALSE;
149 fUseGeo = kTRUE;
fe4da5cc 150}
dc8af42e 151
4347b38f 152//____________________________________________________________________
56b1929b 153AliFMD::AliFMD(const AliFMD& other)
154 : AliDetector(other),
56b1929b 155 fSDigits(other.fSDigits),
156 fNsdigits(other.fNsdigits),
1a1fdef7 157 fDetailed(other.fDetailed),
158 fSimulator(other.fSimulator)
56b1929b 159{
160 // Copy constructor
4ac75127 161 fUseOld = other.fUseOld;
162 fUseDivided = other.fUseDivided;
163 fUseAssembly = other.fUseAssembly;
164 fUseGeo = other.fUseGeo;
56b1929b 165}
166
167//____________________________________________________________________
1a1fdef7 168AliFMD::AliFMD(const char *name, const char *title)
4347b38f 169 : AliDetector (name, title),
afddaa11 170 fSDigits(0),
171 fNsdigits(0),
1a1fdef7 172 fDetailed(kTRUE),
173 fSimulator(0)
fe4da5cc 174{
175 //
176 // Standard constructor for Forward Multiplicity Detector
177 //
1a1fdef7 178 AliDebug(10, "\tStandard CTOR");
4ac75127 179 fUseOld = kFALSE;
180 fUseDivided = kFALSE;
181 fUseAssembly = kFALSE;
182 fUseGeo = kTRUE;
dc8af42e 183
fe4da5cc 184 // Initialise Hit array
4347b38f 185 HitsArray();
186 gAlice->GetMCApp()->AddHitList(fHits);
d1280e40 187
4347b38f 188 // (S)Digits for the detectors disk
189 DigitsArray();
190 SDigitsArray();
191
192 // CHC: What is this?
dc8af42e 193 fIshunt = 0;
4347b38f 194 SetMarkerColor(kRed);
195 SetLineColor(kYellow);
fe4da5cc 196}
d28dcc0d 197
4347b38f 198//____________________________________________________________________
dc8af42e 199AliFMD::~AliFMD ()
d28dcc0d 200{
4347b38f 201 // Destructor for base class AliFMD
202 if (fHits) {
203 fHits->Delete();
204 delete fHits;
205 fHits = 0;
206 }
207 if (fDigits) {
208 fDigits->Delete();
209 delete fDigits;
210 fDigits = 0;
211 }
212 if (fSDigits) {
213 fSDigits->Delete();
214 delete fSDigits;
215 fSDigits = 0;
216 }
217}
218
56b1929b 219//____________________________________________________________________
220AliFMD&
221AliFMD::operator=(const AliFMD& other)
222{
223 AliDetector::operator=(other);
56b1929b 224 fSDigits = other.fSDigits;
225 fNsdigits = other.fNsdigits;
1a1fdef7 226 fDetailed = other.fDetailed;
227 fSimulator = other.fSimulator;
228
56b1929b 229 return *this;
230}
231
4347b38f 232//====================================================================
233//
234// GEometry ANd Traking
235//
236//____________________________________________________________________
237void
238AliFMD::CreateGeometry()
239{
4347b38f 240 //
37c4363a 241 // Create the geometry of Forward Multiplicity Detector. The actual
242 // construction of the geometry is delegated to the class AliFMDRing
243 // and AliFMDSubDetector and the relevant derived classes.
244 //
245 // The flow of this member function is:
246 //
247 // FOR rings fInner and fOuter DO
248 // AliFMDRing::Init();
249 // END FOR
250 //
251 // Set up hybrud card support (leg) volume shapes
252 //
253 // FOR rings fInner and fOuter DO
254 // AliFMDRing::SetupGeometry();
255 // END FOR
256 //
257 // FOR subdetectors fFMD1, fFMD2, and fFMD3 DO
258 // AliFMDSubDetector::SetupGeomtry();
259 // END FOR
260 //
261 // FOR subdetectors fFMD1, fFMD2, and fFMD3 DO
262 // AliFMDSubDetector::Geomtry();
263 // END FOR
1a1fdef7 264 //
265 if (!fSimulator) {
266 AliFatal("Simulator object not made yet!");
267 return;
268 }
269 fSimulator->DefineGeometry();
4347b38f 270}
271
272//____________________________________________________________________
273void AliFMD::CreateMaterials()
274{
275 // Register various materials and tracking mediums with the
276 // backend.
277 //
824466d5 278 AliDebug(10, "\tCreating materials");
56b1929b 279
1a1fdef7 280 if (fSimulator) {
281 AliFatal("Simulator object already instantised!");
282 return;
4347b38f 283 }
1a1fdef7 284 AliFMDGeometry* geometry = AliFMDGeometry::Instance();
285 geometry->Init();
4ac75127 286 TVirtualMC* mc = TVirtualMC::GetMC();
287 Bool_t geo = mc->IsRootGeometrySupported();
288 if (geo && fUseGeo) {
289 if (fUseOld)
290 fSimulator = new AliFMDGeoOldSimulator(this, fDetailed);
291 else
292 fSimulator = new AliFMDGeoSimulator(this, fDetailed);
293 }
294 else {
295 if (fUseOld)
296 fSimulator = new AliFMDG3OldSimulator(this, fDetailed);
297 else
298 fSimulator = new AliFMDG3Simulator(this, fDetailed);
299 }
300 AliDebug(1, Form("using a %s as simulation backend",
301 fSimulator->IsA()->GetName()));
302 fSimulator->UseDivided(fUseDivided);
303 fSimulator->UseAssembly(fUseAssembly);
1a1fdef7 304 fSimulator->DefineMaterials();
d28dcc0d 305}
dc8af42e 306
4347b38f 307//____________________________________________________________________
308void
309AliFMD::Init()
fe4da5cc 310{
311 //
4347b38f 312 // Initialis the FMD after it has been built
313 Int_t i;
314 //
4951e003 315 if (AliLog::GetGlobalDebugLevel()) {
7c09877a 316 cout << "\n" << ClassName() << ": " << flush;
317 for (i = 0; i < 35; i++) cout << "*";
318 cout << " FMD_INIT ";
319 for (i = 0; i < 35; i++) cout << "*";
320 cout << "\n" << ClassName() << ": " << flush;
4347b38f 321 //
322 // Here the FMD initialisation code (if any!)
7c09877a 323 for (i = 0; i < 80; i++) cout << "*";
324 cout << endl;
4347b38f 325 }
326 //
fe4da5cc 327 //
fe4da5cc 328}
dc8af42e 329
4347b38f 330//====================================================================
331//
332// Graphics and event display
333//
334//____________________________________________________________________
335void
336AliFMD::BuildGeometry()
b9a2d5e4 337{
4347b38f 338 //
339 // Build simple ROOT TNode geometry for event display
340 //
341 // Build a simplified geometry of the FMD used for event display
342 //
37c4363a 343 // The actual building of the TNodes is done by
344 // AliFMDSubDetector::SimpleGeometry.
824466d5 345 AliDebug(10, "\tCreating a simplified geometry");
b9a2d5e4 346
1a1fdef7 347 AliFMDGeometry* fmd = AliFMDGeometry::Instance();
348
349 static TXTRU* innerShape = 0;
350 static TXTRU* outerShape = 0;
351 static TObjArray* innerRot = 0;
352 static TObjArray* outerRot = 0;
353
354 if (!innerShape || !outerShape) {
355 // Make the shapes for the modules
356 for (Int_t i = 0; i < 2; i++) {
357 AliFMDRing* r = 0;
358 switch (i) {
359 case 0: r = fmd->GetRing('I'); break;
360 case 1: r = fmd->GetRing('O'); break;
361 }
362 if (!r) {
363 AliError(Form("no ring found for i=%d", i));
364 return;
365 }
366 Double_t siThick = r->GetSiThickness();
367 const Int_t nv = r->GetNVerticies();
368 Double_t theta = r->GetTheta();
369 Int_t nmod = r->GetNModules();
370
371 TXTRU* shape = new TXTRU(r->GetName(), r->GetTitle(), "void", nv, 2);
372 for (Int_t j = 0; j < nv; j++) {
373 TVector2* vv = r->GetVertex(nv - 1 - j);
374 shape->DefineVertex(j, vv->X(), vv->Y());
375 }
376 shape->DefineSection(0, -siThick / 2, 1, 0, 0);
377 shape->DefineSection(1, +siThick / 2, 1, 0, 0);
378 shape->SetLineColor(GetLineColor());
379
380 TObjArray* rots = new TObjArray(nmod);
381 for (Int_t j = 0; j < nmod; j++) {
382 Double_t th = (j + .5) * theta * 2;
383 TString name(Form("FMD_ring_%c_rot_%02d", r->GetId(), j));
384 TString title(Form("FMD Ring %c Rotation # %d", r->GetId(), j));
385 TRotMatrix* rot = new TRotMatrix(name.Data(), title.Data(),
386 90, th, 90, fmod(90+th,360), 0, 0);
387 rots->AddAt(rot, j);
388 }
389
390 switch (r->GetId()) {
391 case 'i':
392 case 'I': innerShape = shape; innerRot = rots; break;
393 case 'o':
394 case 'O': outerShape = shape; outerRot = rots; break;
395 }
396 }
397 }
398
4347b38f 399 TNode* top = gAlice->GetGeometry()->GetNode("alice");
400
1a1fdef7 401 for (Int_t i = 1; i <= 3; i++) {
402 AliFMDDetector* det = fmd->GetDetector(i);
403 if (!det) {
404 Warning("BuildGeometry", "FMD%d seems to be disabled", i);
405 continue;
406 }
407 Double_t w = 0;
408 Double_t rh = det->GetRing('I')->GetHighR();
409 Char_t id = 'I';
410 if (det->GetRing('O')) {
411 w = TMath::Abs(det->GetRingZ('O') - det->GetRingZ('I'));
412 id = (TMath::Abs(det->GetRingZ('O'))
413 > TMath::Abs(det->GetRingZ('I')) ? 'O' : 'I');
414 rh = det->GetRing('O')->GetHighR();
415 }
416 w += (det->GetRing(id)->GetModuleSpacing() +
417 det->GetRing(id)->GetSiThickness());
418 TShape* shape = new TTUBE(det->GetName(), det->GetTitle(), "void",
419 det->GetRing('I')->GetLowR(), rh, w / 2);
420 Double_t z = (det->GetRingZ('I') - w / 2);
421 if (z > 0) z += det->GetRing(id)->GetModuleSpacing();
422 top->cd();
423 TNode* node = new TNode(det->GetName(), det->GetTitle(), shape,
424 0, 0, z, 0);
425 fNodes->Add(node);
426
427 for (Int_t j = 0; j < 2; j++) {
428 AliFMDRing* r = 0;
429 TShape* rshape = 0;
430 TObjArray* rots = 0;
431 switch (j) {
432 case 0:
433 r = det->GetRing('I'); rshape = innerShape; rots = innerRot; break;
434 case 1:
435 r = det->GetRing('O'); rshape = outerShape; rots = outerRot; break;
436 }
437 if (!r) continue;
438
439 Double_t siThick = r->GetSiThickness();
440 Int_t nmod = r->GetNModules();
441 Double_t modspace = r->GetModuleSpacing();
442 Double_t rz = - (z - det->GetRingZ(r->GetId()));
443
444 for (Int_t k = 0; k < nmod; k++) {
445 node->cd();
446 Double_t offz = (k % 2 == 1 ? modspace : 0);
447 TRotMatrix* rot = static_cast<TRotMatrix*>(rots->At(k));
448 TString name(Form("%s%c_module_%02d", det->GetName(), r->GetId(),k));
449 TString title(Form("%s%c Module %d", det->GetName(), r->GetId(),k));
450 TNode* mnod = new TNode(name.Data(), title.Data(), rshape,
451 0, 0, rz - siThick / 2
452 + TMath::Sign(offz,z), rot);
453 mnod->SetLineColor(GetLineColor());
454 fNodes->Add(mnod);
455 } // for (Int_t k = 0 ; ...)
456 } // for (Int_t j = 0 ; ...)
457 } // for (Int_t i = 1 ; ...)
b9a2d5e4 458}
88cb7938 459
4347b38f 460//____________________________________________________________________
461void
462AliFMD::DrawDetector()
fe4da5cc 463{
464 //
37c4363a 465 // Draw a shaded view of the Forward multiplicity detector
fe4da5cc 466 //
4347b38f 467 // DebugGuard guard("AliFMD::DrawDetector");
824466d5 468 AliDebug(10, "\tDraw detector");
4347b38f 469
1a1fdef7 470#if 0
4347b38f 471 //Set ALIC mother transparent
472 gMC->Gsatt("ALIC","SEEN",0);
4347b38f 473 //
474 gMC->Gdopt("hide", "on");
475 gMC->Gdopt("shad", "on");
476 gMC->Gsatt("*", "fill", 7);
477 gMC->SetClipBox(".");
478 gMC->SetClipBox("*", 0, 1000, -1000, 1000, -1000, 1000);
479 gMC->DefaultRange();
480 gMC->Gdraw("alic", 40, 30, 0, 12, 12, .055, .055);
481 gMC->Gdhead(1111, "Forward Multiplicity Detector");
482 gMC->Gdman(16, 10, "MAN");
483 gMC->Gdopt("hide", "off");
1a1fdef7 484#endif
fe4da5cc 485}
dc8af42e 486
4347b38f 487//____________________________________________________________________
17323043 488Int_t
4347b38f 489AliFMD::DistanceToPrimitive(Int_t, Int_t)
fe4da5cc 490{
491 //
492 // Calculate the distance from the mouse to the FMD on the screen
493 // Dummy routine
494 //
495 return 9999;
496}
dc8af42e 497
4347b38f 498//====================================================================
499//
500// Hit and Digit managment
501//
502//____________________________________________________________________
503void
504AliFMD::MakeBranch(Option_t * option)
505{
506 // Create Tree branches for the FMD.
37c4363a 507 //
508 // Options:
509 //
510 // H Make a branch of TClonesArray of AliFMDHit's
511 // D Make a branch of TClonesArray of AliFMDDigit's
512 // S Make a branch of TClonesArray of AliFMDSDigit's
513 //
4347b38f 514 const Int_t kBufferSize = 16000;
515 TString branchname(GetName());
516 TString opt(option);
517
518 if (opt.Contains("H", TString::kIgnoreCase)) {
519 HitsArray();
520 AliDetector::MakeBranch(option);
521 }
522 if (opt.Contains("D", TString::kIgnoreCase)) {
523 DigitsArray();
524 MakeBranchInTree(fLoader->TreeD(), branchname.Data(),
525 &fDigits, kBufferSize, 0);
526 }
527 if (opt.Contains("S", TString::kIgnoreCase)) {
528 SDigitsArray();
529 MakeBranchInTree(fLoader->TreeS(), branchname.Data(),
530 &fSDigits, kBufferSize, 0);
531 }
532}
533
534//____________________________________________________________________
535void
536AliFMD::SetTreeAddress()
537{
afddaa11 538 // Set branch address for the Hits, Digits, and SDigits Tree.
4347b38f 539 if (fLoader->TreeH()) HitsArray();
540 AliDetector::SetTreeAddress();
541
542 TTree *treeD = fLoader->TreeD();
543 if (treeD) {
544 DigitsArray();
545 TBranch* branch = treeD->GetBranch ("FMD");
546 if (branch) branch->SetAddress(&fDigits);
547 }
548
549 TTree *treeS = fLoader->TreeS();
550 if (treeS) {
551 SDigitsArray();
552 TBranch* branch = treeS->GetBranch ("FMD");
553 if (branch) branch->SetAddress(&fSDigits);
554 }
555}
556
557
558
559//____________________________________________________________________
560void
561AliFMD::SetHitsAddressBranch(TBranch *b)
b9a2d5e4 562{
37c4363a 563 // Set the TClonesArray to read hits into.
4347b38f 564 b->SetAddress(&fHits);
b9a2d5e4 565}
566
4347b38f 567//____________________________________________________________________
568void
569AliFMD::AddHit(Int_t track, Int_t *vol, Float_t *hits)
570{
571 // Add a hit to the hits tree
572 //
573 // The information of the two arrays are decoded as
574 //
575 // Parameters
576 // track Track #
577 // ivol[0] [UShort_t ] Detector #
578 // ivol[1] [Char_t ] Ring ID
579 // ivol[2] [UShort_t ] Sector #
580 // ivol[3] [UShort_t ] Strip #
581 // hits[0] [Float_t ] Track's X-coordinate at hit
582 // hits[1] [Float_t ] Track's Y-coordinate at hit
583 // hits[3] [Float_t ] Track's Z-coordinate at hit
584 // hits[4] [Float_t ] X-component of track's momentum
585 // hits[5] [Float_t ] Y-component of track's momentum
586 // hits[6] [Float_t ] Z-component of track's momentum
587 // hits[7] [Float_t ] Energy deposited by track
588 // hits[8] [Int_t ] Track's particle Id #
37c4363a 589 // hits[9] [Float_t ] Time when the track hit
590 //
591 //
69b696b9 592 AddHitByFields(track,
593 UShort_t(vol[0]), // Detector #
594 Char_t(vol[1]), // Ring ID
595 UShort_t(vol[2]), // Sector #
596 UShort_t(vol[3]), // Strip #
597 hits[0], // X
598 hits[1], // Y
599 hits[2], // Z
600 hits[3], // Px
601 hits[4], // Py
602 hits[5], // Pz
603 hits[6], // Energy loss
604 Int_t(hits[7]), // PDG
605 hits[8]); // Time
4347b38f 606}
607
608//____________________________________________________________________
609void
69b696b9 610AliFMD::AddHitByFields(Int_t track,
611 UShort_t detector,
612 Char_t ring,
613 UShort_t sector,
614 UShort_t strip,
615 Float_t x,
616 Float_t y,
617 Float_t z,
618 Float_t px,
619 Float_t py,
620 Float_t pz,
621 Float_t edep,
622 Int_t pdg,
623 Float_t t)
b9a2d5e4 624{
dc8af42e 625 //
4347b38f 626 // Add a hit to the list
dc8af42e 627 //
4347b38f 628 // Parameters:
629 //
630 // track Track #
631 // detector Detector # (1, 2, or 3)
632 // ring Ring ID ('I' or 'O')
633 // sector Sector # (For inner/outer rings: 0-19/0-39)
634 // strip Strip # (For inner/outer rings: 0-511/0-255)
635 // x Track's X-coordinate at hit
636 // y Track's Y-coordinate at hit
637 // z Track's Z-coordinate at hit
638 // px X-component of track's momentum
639 // py Y-component of track's momentum
640 // pz Z-component of track's momentum
641 // edep Energy deposited by track
642 // pdg Track's particle Id #
643 // t Time when the track hit
644 //
645 TClonesArray& a = *(HitsArray());
646 // Search through the list of already registered hits, and see if we
647 // find a hit with the same parameters. If we do, then don't create
648 // a new hit, but rather update the energy deposited in the hit.
649 // This is done, so that a FLUKA based simulation will get the
650 // number of hits right, not just the enerrgy deposition.
ac4c3fbb 651 AliFMDHit* hit = 0;
4347b38f 652 for (Int_t i = 0; i < fNhits; i++) {
653 if (!a.At(i)) continue;
ac4c3fbb 654 hit = static_cast<AliFMDHit*>(a.At(i));
4347b38f 655 if (hit->Detector() == detector
656 && hit->Ring() == ring
657 && hit->Sector() == sector
658 && hit->Strip() == strip
659 && hit->Track() == track) {
37c4363a 660 Warning("AddHit", "already had a hit in FMD%d%c[%2d,%3d] for track # %d,"
661 " adding energy (%f) to that hit (%f) -> %f",
662 detector, ring, sector, strip, track, edep, hit->Edep(),
663 hit->Edep() + edep);
4347b38f 664 hit->SetEdep(hit->Edep() + edep);
665 return;
666 }
667 }
668 // If hit wasn't already registered, do so know.
ac4c3fbb 669 hit = new (a[fNhits]) AliFMDHit(fIshunt, track, detector, ring, sector,
670 strip, x, y, z, px, py, pz, edep, pdg, t);
4347b38f 671 fNhits++;
b9a2d5e4 672}
fe4da5cc 673
4347b38f 674//____________________________________________________________________
675void
69b696b9 676AliFMD::AddDigit(Int_t* digits, Int_t*)
fe4da5cc 677{
4347b38f 678 // Add a digit to the Digit tree
679 //
680 // Paramters
fe4da5cc 681 //
4347b38f 682 // digits[0] [UShort_t] Detector #
683 // digits[1] [Char_t] Ring ID
684 // digits[2] [UShort_t] Sector #
685 // digits[3] [UShort_t] Strip #
686 // digits[4] [UShort_t] ADC Count
687 // digits[5] [Short_t] ADC Count, -1 if not used
688 // digits[6] [Short_t] ADC Count, -1 if not used
689 //
69b696b9 690 AddDigitByFields(UShort_t(digits[0]), // Detector #
691 Char_t(digits[1]), // Ring ID
692 UShort_t(digits[2]), // Sector #
693 UShort_t(digits[3]), // Strip #
694 UShort_t(digits[4]), // ADC Count1
695 Short_t(digits[5]), // ADC Count2
696 Short_t(digits[6])); // ADC Count3
4347b38f 697}
698
699//____________________________________________________________________
700void
69b696b9 701AliFMD::AddDigitByFields(UShort_t detector,
702 Char_t ring,
703 UShort_t sector,
704 UShort_t strip,
705 UShort_t count1,
706 Short_t count2,
707 Short_t count3)
4347b38f 708{
709 // add a real digit - as coming from data
710 //
711 // Parameters
fe4da5cc 712 //
4347b38f 713 // detector Detector # (1, 2, or 3)
714 // ring Ring ID ('I' or 'O')
715 // sector Sector # (For inner/outer rings: 0-19/0-39)
716 // strip Strip # (For inner/outer rings: 0-511/0-255)
717 // count1 ADC count (a 10-bit word)
718 // count2 ADC count (a 10-bit word), or -1 if not used
719 // count3 ADC count (a 10-bit word), or -1 if not used
720 TClonesArray& a = *(DigitsArray());
721
722 new (a[fNdigits++])
723 AliFMDDigit(detector, ring, sector, strip, count1, count2, count3);
724}
725
726//____________________________________________________________________
727void
728AliFMD::AddSDigit(Int_t* digits)
729{
730 // Add a digit to the SDigit tree
731 //
732 // Paramters
b9a2d5e4 733 //
4347b38f 734 // digits[0] [UShort_t] Detector #
735 // digits[1] [Char_t] Ring ID
736 // digits[2] [UShort_t] Sector #
737 // digits[3] [UShort_t] Strip #
738 // digits[4] [Float_t] Total energy deposited
739 // digits[5] [UShort_t] ADC Count
740 // digits[6] [Short_t] ADC Count, -1 if not used
741 // digits[7] [Short_t] ADC Count, -1 if not used
742 //
69b696b9 743 AddSDigitByFields(UShort_t(digits[0]), // Detector #
744 Char_t(digits[1]), // Ring ID
745 UShort_t(digits[2]), // Sector #
746 UShort_t(digits[3]), // Strip #
747 Float_t(digits[4]), // Edep
748 UShort_t(digits[5]), // ADC Count1
749 Short_t(digits[6]), // ADC Count2
750 Short_t(digits[7])); // ADC Count3
4347b38f 751}
752
753//____________________________________________________________________
754void
69b696b9 755AliFMD::AddSDigitByFields(UShort_t detector,
756 Char_t ring,
757 UShort_t sector,
758 UShort_t strip,
759 Float_t edep,
760 UShort_t count1,
761 Short_t count2,
762 Short_t count3)
4347b38f 763{
764 // add a summable digit
765 //
766 // Parameters
b9a2d5e4 767 //
4347b38f 768 // detector Detector # (1, 2, or 3)
769 // ring Ring ID ('I' or 'O')
770 // sector Sector # (For inner/outer rings: 0-19/0-39)
771 // strip Strip # (For inner/outer rings: 0-511/0-255)
772 // edep Total energy deposited
773 // count1 ADC count (a 10-bit word)
774 // count2 ADC count (a 10-bit word), or -1 if not used
775 // count3 ADC count (a 10-bit word), or -1 if not used
37c4363a 776 //
4347b38f 777 TClonesArray& a = *(SDigitsArray());
778
779 new (a[fNsdigits++])
780 AliFMDSDigit(detector, ring, sector, strip, edep, count1, count2, count3);
fe4da5cc 781}
4347b38f 782
783//____________________________________________________________________
784void
785AliFMD::ResetSDigits()
d28dcc0d 786{
4347b38f 787 //
788 // Reset number of digits and the digits array for this detector
789 //
790 fNsdigits = 0;
791 if (fSDigits) fSDigits->Clear();
792}
793
794
795//____________________________________________________________________
796TClonesArray*
797AliFMD::HitsArray()
798{
799 // Initialize hit array if not already, and return pointer to it.
800 if (!fHits) {
801 fHits = new TClonesArray("AliFMDHit", 1000);
802 fNhits = 0;
803 }
804 return fHits;
805}
806
807//____________________________________________________________________
808TClonesArray*
809AliFMD::DigitsArray()
810{
811 // Initialize digit array if not already, and return pointer to it.
812 if (!fDigits) {
813 fDigits = new TClonesArray("AliFMDDigit", 1000);
814 fNdigits = 0;
815 }
816 return fDigits;
817}
818
819//____________________________________________________________________
820TClonesArray*
821AliFMD::SDigitsArray()
822{
823 // Initialize digit array if not already, and return pointer to it.
824 if (!fSDigits) {
825 fSDigits = new TClonesArray("AliFMDSDigit", 1000);
826 fNsdigits = 0;
827 }
828 return fSDigits;
829}
830
831//====================================================================
832//
833// Digitization
834//
835//____________________________________________________________________
836void
837AliFMD::Hits2Digits()
838{
37c4363a 839 // Create AliFMDDigit's from AliFMDHit's. This is done by making a
840 // AliFMDDigitizer, and executing that code.
841 //
a3537838 842 Warning("Hits2Digits", "Try not to use this method.\n"
843 "Instead, use AliSimulator");
4347b38f 844 AliRunDigitizer* manager = new AliRunDigitizer(1, 1);
845 manager->SetInputStream(0, "galice.root");
846 manager->SetOutputFile("H2Dfile");
dc8af42e 847
4347b38f 848 /* AliDigitizer* dig =*/ CreateDigitizer(manager);
849 manager->Exec("");
99d864b7 850 delete manager;
4347b38f 851}
852
853//____________________________________________________________________
854void
855AliFMD::Hits2SDigits()
856{
37c4363a 857 // Create AliFMDSDigit's from AliFMDHit's. This is done by creating
858 // an AliFMDSDigitizer object, and executing it.
859 //
56b1929b 860 AliFMDSDigitizer* digitizer = new AliFMDSDigitizer("galice.root");
56b1929b 861 digitizer->Exec("");
99d864b7 862 delete digitizer;
4347b38f 863}
864
dc8af42e 865
4347b38f 866//____________________________________________________________________
867AliDigitizer*
868AliFMD::CreateDigitizer(AliRunDigitizer* manager) const
869{
870 // Create a digitizer object
56b1929b 871 AliFMDDigitizer* digitizer = new AliFMDDigitizer(manager);
56b1929b 872 return digitizer;
4347b38f 873}
b9a2d5e4 874
4347b38f 875//====================================================================
876//
877// Raw data simulation
878//
879//__________________________________________________________________
880void
881AliFMD::Digits2Raw()
882{
37c4363a 883 // Turn digits into raw data.
884 //
e802be3e 885 // This uses the class AliFMDRawWriter to do the job. Please refer
886 // to that class for more information.
887 AliFMDRawWriter writer(this);
888 writer.Exec();
b9a2d5e4 889}
890
4347b38f 891
892//====================================================================
893//
894// Utility
895//
896//__________________________________________________________________
897void
898AliFMD::Browse(TBrowser* b)
899{
37c4363a 900 // Browse this object.
901 //
824466d5 902 AliDebug(30, "\tBrowsing the FMD");
4347b38f 903 AliDetector::Browse(b);
1a1fdef7 904 if (fSimulator) b->Add(fSimulator);
905 b->Add(AliFMDGeometry::Instance());
4347b38f 906}
907
4347b38f 908//___________________________________________________________________
909//
910// EOF
911//