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