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