]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMD.cxx
604e344bc7aecbcf97efd8a5732aa2eb52f36136
[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 <TGeometry.h>
44 #include <TNode.h>
45 #include <TTree.h>
46 #include <TVirtualMC.h>
47
48 #include "AliLog.h"
49 #include "AliLoader.h" 
50 #include "AliPMDLoader.h" 
51 #include "AliPMD.h"
52 #include "AliRun.h"
53 #include "AliMC.h"
54 #include "AliPMDDigitizer.h"
55 #include "AliPMDhit.h"
56 #include "AliPMDDDLRawData.h"
57 #include "AliPMDRawToSDigits.h"
58   
59 ClassImp(AliPMD)
60  
61 //_____________________________________________________________________________
62 AliPMD::AliPMD()
63 {
64   //
65   // Default constructor
66   //
67   fIshunt = 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
85   fIshunt =  0;
86   
87   fPar[0] = 1;
88   fPar[1] = 1;
89   fPar[2] = 0.8;
90   fPar[3] = 0.02;
91   fIn[0]  = 6;
92   fIn[1]  = 20;
93   fIn[2]  = 600;
94   fIn[3]  = 27;
95   fIn[4]  = 27;
96   fGeo[0] = 0;
97   fGeo[1] = 0.2;
98   fGeo[2] = 4;
99   fPadSize[0] = 0.8;
100   fPadSize[1] = 1.0;
101   fPadSize[2] = 1.2;
102   fPadSize[3] = 1.5;
103 }
104
105 AliLoader* AliPMD::MakeLoader(const char* topfoldername)
106 {
107   // Makes PMD Loader
108  
109   fLoader = new AliPMDLoader(GetName(),topfoldername);
110  
111   if (fLoader)
112     {
113       AliDebug(100,"Success");
114     }
115   else
116     {
117       AliError("Failure");
118     }
119
120   return fLoader;
121 }
122
123 AliPMD::~AliPMD()
124 {
125   //
126   // Destructor
127   //
128 }
129
130 //_____________________________________________________________________________
131 void AliPMD::AddHit(Int_t track, Int_t *vol, Float_t *hits)
132 {
133   //
134   // Add a PMD hit
135   //
136   TClonesArray &lhits = *fHits;
137   AliPMDhit *newcell, *curcell;
138   //  printf("PMD++ Adding energy %f, prim %d, vol %d %d %d %d %d %d %d %d\n",
139   // hits[3],gAlice->GetPrimary(track-1),vol[0],vol[1],vol[2],vol[3],
140   // vol[4],vol[5],vol[6],vol[7]);
141
142   newcell = new AliPMDhit(fIshunt, track, vol, hits);
143   Int_t i;
144   for (i=0; i<fNhits; i++) {
145     //
146     // See if this cell has already been hit
147     curcell=(AliPMDhit*) lhits[i];
148     if (*curcell==*newcell) {
149 //        printf("Cell with same numbers found\n") ; curcell->Print();
150       *curcell = *curcell+*newcell;
151 //        printf("Cell after addition\n") ; curcell->Print();
152       delete newcell;
153       return;
154     }
155   }
156   new(lhits[fNhits++]) AliPMDhit(newcell);
157   delete newcell;
158 }
159  
160 //_____________________________________________________________________________
161 void AliPMD::SetPAR(Float_t p1, Float_t p2, Float_t p3,Float_t p4)
162 {
163   //
164   // Set PMD parameters
165   //
166   fPar[0] = p1;
167   fPar[1] = p2;
168   fPar[2] = p3;
169   fPar[3] = p4;
170 }
171  
172 //_____________________________________________________________________________
173 void AliPMD::SetIN(Float_t p1, Float_t p2, Float_t p3,Float_t p4,Float_t p5)
174 {
175   //
176   // Set PMD parameters
177   //
178   fIn[0] = p1;
179   fIn[1] = p2;
180   fIn[2] = p3;
181   fIn[3] = p4;
182   fIn[4] = p5;
183 }
184  
185 //_____________________________________________________________________________
186 void AliPMD::SetGEO(Float_t p1, Float_t p2, Float_t p3)
187 {
188   //
189   // Set geometry parameters
190   //
191   fGeo[0] = p1;
192   fGeo[1] = p2;
193   fGeo[2] = p3;
194 }
195  
196 //_____________________________________________________________________________
197 void AliPMD::SetPadSize(Float_t p1, Float_t p2, Float_t p3,Float_t p4)
198 {
199   //
200   // Set pad size
201   //
202   fPadSize[0] = p1;
203   fPadSize[1] = p2;
204   fPadSize[2] = p3;
205   fPadSize[3] = p4;
206 }
207  
208 //_____________________________________________________________________________
209 void AliPMD::StepManager()
210 {
211   //
212   // Called at every step in PMD
213   //
214 }
215
216 void AliPMD::MakeBranch(Option_t* option)
217 {
218     // Create Tree branches for the PMD
219     
220     const char *cH = strstr(option,"H");
221     if (cH && fLoader->TreeH() && (fHits == 0x0))
222       fHits   = new TClonesArray("AliPMDhit",  405);
223     
224     AliDetector::MakeBranch(option);
225 }
226
227
228 void AliPMD::SetTreeAddress()
229 {
230   // Set branch address
231
232     if (fLoader->TreeH() && fHits==0x0)
233       fHits   = new TClonesArray("AliPMDhit",  405);
234       
235     AliDetector::SetTreeAddress();
236 }
237
238 //____________________________________________________________________________
239 void AliPMD::Hits2SDigits()  
240
241 // create summable digits
242
243   AliRunLoader* runLoader = fLoader->GetRunLoader(); 
244   AliPMDDigitizer* pmdDigitizer = new AliPMDDigitizer;
245   pmdDigitizer->OpengAliceFile(fLoader->GetRunLoader()->GetFileName().Data(),
246                                "HS");
247   pmdDigitizer->SetZPosition(361.5);
248
249   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
250     pmdDigitizer->Hits2SDigits(iEvent);
251   }
252   fLoader->UnloadHits();
253   fLoader->UnloadSDigits();
254   delete pmdDigitizer;
255 }
256 //____________________________________________________________________________
257 void AliPMD::SDigits2Digits()  
258
259   // creates sdigits to digits
260 }
261 //____________________________________________________________________________
262 void AliPMD::Hits2Digits()  
263
264 // create digits
265
266   AliRunLoader* runLoader = fLoader->GetRunLoader(); 
267   AliPMDDigitizer* pmdDigitizer = new AliPMDDigitizer;
268   pmdDigitizer->OpengAliceFile(fLoader->GetRunLoader()->GetFileName().Data(),
269                                "HD");
270   pmdDigitizer->SetZPosition(361.5);
271
272   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
273     pmdDigitizer->Hits2Digits(iEvent);
274   }
275   fLoader->UnloadHits();
276   fLoader->UnloadDigits();
277   delete pmdDigitizer;
278
279 }
280 // ---------------------------------------------------------------------------
281 AliDigitizer* AliPMD::CreateDigitizer(AliRunDigitizer* manager) const
282
283   return new AliPMDDigitizer(manager);
284 }
285 // ---------------------------------------------------------------------------
286 void AliPMD::Digits2Raw()
287
288 // convert digits of the current event to raw data
289
290   fLoader->LoadDigits();
291   TTree* digits = fLoader->TreeD();
292   if (!digits) {
293     AliError("No digits tree");
294     return;
295   }
296
297   AliPMDDDLRawData rawWriter;
298   rawWriter.WritePMDRawData(digits);
299
300   fLoader->UnloadDigits();
301 }
302
303 Bool_t AliPMD::Raw2SDigits(AliRawReader *rawReader)
304 {
305   // converts raw to sdigits
306   AliRunLoader* runLoader = fLoader->GetRunLoader(); 
307   //runLoader->GetEvent(ievt);
308
309   AliPMDRawToSDigits pmdr2sd;
310   pmdr2sd.Raw2SDigits(runLoader, rawReader);
311   fLoader->UnloadSDigits();
312   return kTRUE;
313 }
314