]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMD.cxx
Code for simulation, sdigitization and digitization moved from macros to compiled...
[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 #include "AliMC.h"
55 #include "AliPMDDigitizer.h"
56   
57 ClassImp(AliPMD)
58  
59 //_____________________________________________________________________________
60 AliPMD::AliPMD()
61 {
62   //
63   // Default constructor
64   //
65   fIshunt = 0;
66
67   fRecPoints  = 0;
68
69 }
70  
71 //_____________________________________________________________________________
72 AliPMD::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);
82   gAlice->GetMCApp()->AddHitList(fHits);
83
84   fRecPoints  = new TClonesArray("AliPMDRecPoint",10000); 
85   fNRecPoints = 0;
86   
87
88   fIshunt =  0;
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
108 AliLoader* 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
126 AliPMD::~AliPMD()
127 {
128   //
129   // Default constructor
130   //
131     delete fRecPoints;
132     fNRecPoints=0;
133 }
134
135 //_____________________________________________________________________________
136 void 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;
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
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) {
154 //        printf("Cell with same numbers found\n") ; curcell->Print();
155       *curcell = *curcell+*newcell;
156 //        printf("Cell after addition\n") ; curcell->Print();
157       delete newcell;
158       return;
159     }
160   }
161   new(lhits[fNhits++]) AliPMDhit(newcell);
162   delete newcell;
163 }
164  
165 //_____________________________________________________________________________
166 void 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();
181   Node = new TNode("PMD","PMD","S_PMD",0,0,-600,"");
182   Node->SetLineColor(kColorPMD);
183   fNodes->Add(Node);
184 }
185
186 //_____________________________________________________________________________
187 Int_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 //_____________________________________________________________________________
197 void 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 //_____________________________________________________________________________
209 void 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 //_____________________________________________________________________________
222 void 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 //_____________________________________________________________________________
233 void 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 //_____________________________________________________________________________
245 void AliPMD::StepManager()
246 {
247   //
248   // Called at every step in PMD
249   //
250 }
251
252 void 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
261 void AliPMD::MakeBranch(Option_t* option)
262 {
263     // Create Tree branches for the PMD
264     
265     const char *cR = strstr(option,"R");
266     const char *cH = strstr(option,"H");
267     if (cH && fLoader->TreeH() && (fHits == 0x0))
268       fHits   = new TClonesArray("AliPMDhit",  405);
269     
270     AliDetector::MakeBranch(option);
271
272     if (cR  && fLoader->TreeR()) {
273       printf("Make Branch - TreeR address %p\n",fLoader->TreeR());
274     
275       const Int_t kBufferSize = 4000;
276       char branchname[30];
277       
278       sprintf(branchname,"%sRecPoints",GetName());
279       if (fRecPoints == 0x0) {
280         fRecPoints  = new TClonesArray("AliPMDRecPoint",10000); 
281       }
282       MakeBranchInTree(fLoader->TreeR(), branchname, &fRecPoints, kBufferSize,0);
283    }    
284 }
285
286
287 void AliPMD::SetTreeAddress()
288 {
289   // Set branch address for the TreeR
290     char branchname[30];
291     
292     if (fLoader->TreeH() && fHits==0x0)
293       fHits   = new TClonesArray("AliPMDhit",  405);
294       
295     AliDetector::SetTreeAddress();
296
297     TBranch *branch;
298     TTree *treeR = fLoader->TreeR();
299
300     sprintf(branchname,"%s",GetName());
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        }
310     }
311 }
312
313 void AliPMD::ResetHits()
314 {
315   //
316   // Reset number of hits and the hits array
317   //
318     AliDetector::ResetHits();
319     fNRecPoints   = 0;
320     if (fRecPoints)   fRecPoints->Clear();
321 }
322
323 ///////////////////////////////////////////////////////////////////////////////
324 //                                                                           //
325 //  Photon Multiplicity Detector Version 1                                   //
326 //                                                                           //
327 //Begin_Html
328 /*
329 <img src="picts/AliPMDv1Class.gif">
330 */
331 //End_Html
332 //                                                                           //
333 ///////////////////////////////////////////////////////////////////////////////
334
335
336
337 ClassImp(AliPMDhit)
338   
339 //_____________________________________________________________________________
340 AliPMDhit::AliPMDhit(Int_t shunt,Int_t track, Int_t *vol, Float_t *hits):
341   AliHit(shunt, track)
342 {
343   //
344   // Add a PMD hit
345   //
346   Int_t i;
347   for (i=0;i<8;i++) fVolume[i] = vol[i];
348   fX=hits[0];
349   fY=hits[1];
350   fZ=hits[2];
351   fEnergy=hits[3];
352 }
353   
354
355 //____________________________________________________________________________
356 void 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 }