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