Changes needed by ANSI/ISO compilance
[u/mrichter/AliRoot.git] / PMD / AliPMD.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 //                                                                           //
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 /*
28 <img src="picts/AliPMDClass.gif">
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>
42 #include <TClonesArray.h>
43 #include <TFile.h>
44 #include <TGeometry.h>
45 #include <TNode.h>
46 #include <TTree.h>
47 #include <TVirtualMC.h>
48
49 #include "AliConst.h" 
50 #include "AliLoader.h" 
51 #include "AliPMDLoader.h" 
52 #include "AliPMD.h"
53 #include "AliPMDRecPoint.h"
54 #include "AliRun.h"
55 #include "AliMC.h"
56 #include "AliPMDDigitizer.h"
57 #include "AliPMDhit.h"
58   
59 ClassImp(AliPMD)
60  
61 //_____________________________________________________________________________
62 AliPMD::AliPMD()
63 {
64   //
65   // Default constructor
66   //
67   fIshunt = 0;
68
69   fRecPoints  = 0;
70
71 }
72  
73 //_____________________________________________________________________________
74 AliPMD::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);
84   gAlice->GetMCApp()->AddHitList(fHits);
85
86   fRecPoints  = new TClonesArray("AliPMDRecPoint",10000); 
87   fNRecPoints = 0;
88   
89
90   fIshunt =  0;
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
110 AliLoader* AliPMD::MakeLoader(const char* topfoldername)
111 {
112   // Makes PMD Loader
113  
114   fLoader = new AliPMDLoader(GetName(),topfoldername);
115  
116   if (fLoader)
117     {
118       cout<<"Success"<<endl;
119     }
120   else
121     {
122       cout<<"Failure"<<endl;
123     }
124
125   return fLoader;
126 }
127
128 AliPMD::~AliPMD()
129 {
130   //
131   // Default constructor
132   //
133     delete fRecPoints;
134     fNRecPoints=0;
135 }
136
137 //_____________________________________________________________________________
138 void 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;
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
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) {
156 //        printf("Cell with same numbers found\n") ; curcell->Print();
157       *curcell = *curcell+*newcell;
158 //        printf("Cell after addition\n") ; curcell->Print();
159       delete newcell;
160       return;
161     }
162   }
163   new(lhits[fNhits++]) AliPMDhit(newcell);
164   delete newcell;
165 }
166  
167 //_____________________________________________________________________________
168 void AliPMD::BuildGeometry()
169 {
170   //
171   // Build simple ROOT TNode geometry for event display
172   //
173
174   TNode *node, *top;
175   const int kColorPMD  = kRed;
176
177   //
178   top=gAlice->GetGeometry()->GetNode("alice");
179
180   // PMD
181   new TBRIK("S_PMD","PMD box","void",300,300,5);
182   top->cd();
183   node = new TNode("PMD","PMD","S_PMD",0,0,-600,"");
184   node->SetLineColor(kColorPMD);
185   fNodes->Add(node);
186 }
187
188 //_____________________________________________________________________________
189 Int_t AliPMD::DistancetoPrimitive(Int_t , Int_t ) const
190 {
191   //
192   // Distance from mouse to detector on the screen
193   // dummy routine
194   //
195    return 9999;
196 }
197  
198 //_____________________________________________________________________________
199 void 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 //_____________________________________________________________________________
211 void 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 //_____________________________________________________________________________
224 void 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 //_____________________________________________________________________________
235 void 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 //_____________________________________________________________________________
247 void AliPMD::StepManager()
248 {
249   //
250   // Called at every step in PMD
251   //
252 }
253
254 void 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
263 void AliPMD::MakeBranch(Option_t* option)
264 {
265     // Create Tree branches for the PMD
266     
267     const char *cR = strstr(option,"R");
268     const char *cH = strstr(option,"H");
269     if (cH && fLoader->TreeH() && (fHits == 0x0))
270       fHits   = new TClonesArray("AliPMDhit",  405);
271     
272     AliDetector::MakeBranch(option);
273
274     if (cR  && fLoader->TreeR()) {
275       printf("Make Branch - TreeR address %p\n",(void*)fLoader->TreeR());
276     
277       const Int_t kBufferSize = 4000;
278       char branchname[30];
279       
280       sprintf(branchname,"%sRecPoints",GetName());
281       if (fRecPoints == 0x0) {
282         fRecPoints  = new TClonesArray("AliPMDRecPoint",10000); 
283       }
284       MakeBranchInTree(fLoader->TreeR(), branchname, &fRecPoints, kBufferSize,0);
285    }    
286 }
287
288
289 void AliPMD::SetTreeAddress()
290 {
291   // Set branch address for the TreeR
292     char branchname[30];
293     
294     if (fLoader->TreeH() && fHits==0x0)
295       fHits   = new TClonesArray("AliPMDhit",  405);
296       
297     AliDetector::SetTreeAddress();
298
299     TBranch *branch;
300     TTree *treeR = fLoader->TreeR();
301
302     sprintf(branchname,"%s",GetName());
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        }
312     }
313 }
314
315 void AliPMD::ResetHits()
316 {
317   //
318   // Reset number of hits and the hits array
319   //
320     AliDetector::ResetHits();
321     fNRecPoints   = 0;
322     if (fRecPoints)   fRecPoints->Clear();
323 }
324 //____________________________________________________________________________
325 void 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");
333   pmdDigitizer->SetZPosition(361.5);
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 }
342 //____________________________________________________________________________
343 void AliPMD::SDigits2Digits()  
344
345   // creates sdigits to digits
346 }
347 //____________________________________________________________________________
348 void 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 AliDigitizer* AliPMD::CreateDigitizer(AliRunDigitizer* manager) const
368
369   return new AliPMDDigitizer(manager);
370 }
371 // ---------------------------------------------------------------------------
372
373