Code for simulation, sdigitization and digitization moved from macros to compiled...
[u/mrichter/AliRoot.git] / PMD / AliPMD.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 **************************************************************************/
15
88cb7938 16/* $Id$ */
4c039060 17
fe4da5cc 18///////////////////////////////////////////////////////////////////////////////
6edc06da 19//
fe4da5cc 20// //
21// Photon Multiplicity Detector //
22// This class contains the basic functions for the Photon Multiplicity //
23// Detector. Functions specific to one particular geometry are //
24// contained in the derived classes //
25// //
26//Begin_Html
27/*
1439f98e 28<img src="picts/AliPMDClass.gif">
fe4da5cc 29</pre>
30<br clear=left>
31<font size=+2 color=red>
32<p>The responsible person for this module is
33<a href="mailto:sub@vecdec.veccal.ernet.in">Subhasis Chattopadhyay</a>.
34</font>
35<pre>
36*/
37//End_Html
38// //
39///////////////////////////////////////////////////////////////////////////////
40
41#include <TBRIK.h>
4fa198c6 42#include <TClonesArray.h>
2ab0c725 43#include <TFile.h>
88cb7938 44#include <TGeometry.h>
45#include <TNode.h>
46#include <TTree.h>
47#include <TVirtualMC.h>
94de3818 48
fe4da5cc 49#include "AliConst.h"
88cb7938 50#include "AliLoader.h"
51#include "AliPMD.h"
4fa198c6 52#include "AliPMDRecPoint.h"
88cb7938 53#include "AliRun.h"
5d12ce38 54#include "AliMC.h"
85a5290f 55#include "AliPMDDigitizer.h"
4fa198c6 56
fe4da5cc 57ClassImp(AliPMD)
58
59//_____________________________________________________________________________
60AliPMD::AliPMD()
61{
62 //
63 // Default constructor
64 //
65 fIshunt = 0;
0cc62300 66
427f8f1d 67 fRecPoints = 0;
2ab0c725 68
fe4da5cc 69}
70
71//_____________________________________________________________________________
72AliPMD::AliPMD(const char *name, const char *title)
73 : AliDetector(name,title)
74{
75 //
76 // Default constructor
77 //
78
79 //
80 // Allocate the array of hits
81 fHits = new TClonesArray("AliPMDhit", 405);
5d12ce38 82 gAlice->GetMCApp()->AddHitList(fHits);
4fa198c6 83
84 fRecPoints = new TClonesArray("AliPMDRecPoint",10000);
85 fNRecPoints = 0;
fe4da5cc 86
4fa198c6 87
4187e4de 88 fIshunt = 0;
fe4da5cc 89
90 fPar[0] = 1;
91 fPar[1] = 1;
92 fPar[2] = 0.8;
93 fPar[3] = 0.02;
94 fIn[0] = 6;
95 fIn[1] = 20;
96 fIn[2] = 600;
97 fIn[3] = 27;
98 fIn[4] = 27;
99 fGeo[0] = 0;
100 fGeo[1] = 0.2;
101 fGeo[2] = 4;
102 fPadSize[0] = 0.8;
103 fPadSize[1] = 1.0;
104 fPadSize[2] = 1.2;
105 fPadSize[3] = 1.5;
106}
107
1661e612 108AliLoader* AliPMD::MakeLoader(const char* topfoldername)
109{
110 cout<<"AliPMD::MakeLoader ";
111
112 fLoader = new AliPMDLoader(GetName(),topfoldername);
113
114 if (fLoader)
115 {
116 cout<<"Success"<<endl;
117 }
118 else
119 {
120 cout<<"Failure"<<endl;
121 }
122
123 return fLoader;
124}
125
4fa198c6 126AliPMD::~AliPMD()
127{
128 //
129 // Default constructor
130 //
131 delete fRecPoints;
132 fNRecPoints=0;
133}
134
fe4da5cc 135//_____________________________________________________________________________
136void AliPMD::AddHit(Int_t track, Int_t *vol, Float_t *hits)
137{
138 //
139 // Add a PMD hit
140 //
141 TClonesArray &lhits = *fHits;
142 AliPMDhit *newcell, *curcell;
41c97e7a 143 // printf("PMD++ Adding energy %f, prim %d, vol %d %d %d %d %d %d %d %d\n",
144 // hits[3],gAlice->GetPrimary(track-1),vol[0],vol[1],vol[2],vol[3],
145 // vol[4],vol[5],vol[6],vol[7]);
146
fe4da5cc 147 newcell = new AliPMDhit(fIshunt, track, vol, hits);
148 Int_t i;
149 for (i=0; i<fNhits; i++) {
150 //
151 // See if this cell has already been hit
152 curcell=(AliPMDhit*) lhits[i];
153 if (*curcell==*newcell) {
6edc06da 154// printf("Cell with same numbers found\n") ; curcell->Print();
fe4da5cc 155 *curcell = *curcell+*newcell;
6edc06da 156// printf("Cell after addition\n") ; curcell->Print();
fe4da5cc 157 delete newcell;
158 return;
159 }
160 }
161 new(lhits[fNhits++]) AliPMDhit(newcell);
162 delete newcell;
163}
164
165//_____________________________________________________________________________
166void AliPMD::BuildGeometry()
167{
168 //
169 // Build simple ROOT TNode geometry for event display
170 //
171
172 TNode *Node, *Top;
173 const int kColorPMD = kRed;
174
175 //
176 Top=gAlice->GetGeometry()->GetNode("alice");
177
178 // PMD
179 new TBRIK("S_PMD","PMD box","void",300,300,5);
180 Top->cd();
d651cc98 181 Node = new TNode("PMD","PMD","S_PMD",0,0,-600,"");
fe4da5cc 182 Node->SetLineColor(kColorPMD);
183 fNodes->Add(Node);
184}
185
186//_____________________________________________________________________________
187Int_t AliPMD::DistancetoPrimitive(Int_t , Int_t )
188{
189 //
190 // Distance from mouse to detector on the screen
191 // dummy routine
192 //
193 return 9999;
194}
195
196//_____________________________________________________________________________
197void AliPMD::SetPAR(Float_t p1, Float_t p2, Float_t p3,Float_t p4)
198{
199 //
200 // Set PMD parameters
201 //
202 fPar[0] = p1;
203 fPar[1] = p2;
204 fPar[2] = p3;
205 fPar[3] = p4;
206}
207
208//_____________________________________________________________________________
209void AliPMD::SetIN(Float_t p1, Float_t p2, Float_t p3,Float_t p4,Float_t p5)
210{
211 //
212 // Set PMD parameters
213 //
214 fIn[0] = p1;
215 fIn[1] = p2;
216 fIn[2] = p3;
217 fIn[3] = p4;
218 fIn[4] = p5;
219}
220
221//_____________________________________________________________________________
222void AliPMD::SetGEO(Float_t p1, Float_t p2, Float_t p3)
223{
224 //
225 // Set geometry parameters
226 //
227 fGeo[0] = p1;
228 fGeo[1] = p2;
229 fGeo[2] = p3;
230}
231
232//_____________________________________________________________________________
233void AliPMD::SetPadSize(Float_t p1, Float_t p2, Float_t p3,Float_t p4)
234{
235 //
236 // Set pad size
237 //
238 fPadSize[0] = p1;
239 fPadSize[1] = p2;
240 fPadSize[2] = p3;
241 fPadSize[3] = p4;
242}
243
244//_____________________________________________________________________________
245void AliPMD::StepManager()
246{
247 //
248 // Called at every step in PMD
249 //
250}
251
4fa198c6 252void AliPMD::AddRecPoint(const AliPMDRecPoint &p)
253{
254 //
255 // Add a PMD reconstructed hit to the list
256 //
257 TClonesArray &lrecpoints = *fRecPoints;
258 new(lrecpoints[fNRecPoints++]) AliPMDRecPoint(p);
259}
260
88cb7938 261void AliPMD::MakeBranch(Option_t* option)
4fa198c6 262{
263 // Create Tree branches for the PMD
4fa198c6 264
5cf7bbad 265 const char *cR = strstr(option,"R");
88cb7938 266 const char *cH = strstr(option,"H");
267 if (cH && fLoader->TreeH() && (fHits == 0x0))
268 fHits = new TClonesArray("AliPMDhit", 405);
2ab0c725 269
88cb7938 270 AliDetector::MakeBranch(option);
4fa198c6 271
88cb7938 272 if (cR && fLoader->TreeR()) {
273 printf("Make Branch - TreeR address %p\n",fLoader->TreeR());
2ab0c725 274
275 const Int_t kBufferSize = 4000;
276 char branchname[30];
277
278 sprintf(branchname,"%sRecPoints",GetName());
88cb7938 279 if (fRecPoints == 0x0) {
280 fRecPoints = new TClonesArray("AliPMDRecPoint",10000);
2ab0c725 281 }
88cb7938 282 MakeBranchInTree(fLoader->TreeR(), branchname, &fRecPoints, kBufferSize,0);
2ab0c725 283 }
4fa198c6 284}
285
286
287void AliPMD::SetTreeAddress()
288{
289 // Set branch address for the TreeR
290 char branchname[30];
88cb7938 291
1da4d0d9 292 if (fLoader->TreeH() && fHits==0x0)
88cb7938 293 fHits = new TClonesArray("AliPMDhit", 405);
294
4fa198c6 295 AliDetector::SetTreeAddress();
296
297 TBranch *branch;
88cb7938 298 TTree *treeR = fLoader->TreeR();
4fa198c6 299
300 sprintf(branchname,"%s",GetName());
88cb7938 301 if (treeR) {
302 branch = treeR->GetBranch(branchname);
303 if (branch)
304 {
305 if (fRecPoints == 0x0) {
306 fRecPoints = new TClonesArray("AliPMDRecPoint",10000);
307 }
308 branch->SetAddress(&fRecPoints);
309 }
4fa198c6 310 }
311}
312
313void AliPMD::ResetHits()
314{
315 //
316 // Reset number of hits and the hits array
317 //
d3b63a89 318 AliDetector::ResetHits();
319 fNRecPoints = 0;
320 if (fRecPoints) fRecPoints->Clear();
4fa198c6 321}
322
fe4da5cc 323///////////////////////////////////////////////////////////////////////////////
324// //
325// Photon Multiplicity Detector Version 1 //
326// //
327//Begin_Html
328/*
1439f98e 329<img src="picts/AliPMDv1Class.gif">
fe4da5cc 330*/
331//End_Html
332// //
333///////////////////////////////////////////////////////////////////////////////
334
4fa198c6 335
336
fe4da5cc 337ClassImp(AliPMDhit)
338
339//_____________________________________________________________________________
6edc06da 340AliPMDhit::AliPMDhit(Int_t shunt,Int_t track, Int_t *vol, Float_t *hits):
fe4da5cc 341 AliHit(shunt, track)
342{
343 //
344 // Add a PMD hit
345 //
346 Int_t i;
41c97e7a 347 for (i=0;i<8;i++) fVolume[i] = vol[i];
fe4da5cc 348 fX=hits[0];
349 fY=hits[1];
350 fZ=hits[2];
351 fEnergy=hits[3];
352}
6edc06da 353
85a5290f 354
355//____________________________________________________________________________
356void AliPMD::Hits2SDigits()
357{
358// create summable digits
359
360 AliRunLoader* runLoader = fLoader->GetRunLoader();
361 AliPMDDigitizer* pmdDigitizer = new AliPMDDigitizer;
362 pmdDigitizer->OpengAliceFile(fLoader->GetRunLoader()->GetFileName().Data(),
363 "HS");
364 pmdDigitizer->SetZPosition(365.0);
365
366 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
367 pmdDigitizer->Hits2SDigits(iEvent);
368 }
369 fLoader->UnloadHits();
370 fLoader->UnloadSDigits();
371 delete pmdDigitizer;
372}