]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDClusterFinder.cxx
b21c55151e68b888b73df3385d288058540120d8
[u/mrichter/AliRoot.git] / PMD / AliPMDClusterFinder.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 //-----------------------------------------------------//
17 //                                                     //
18 //           Date   : August 05 2003                   //
19 //  This reads the file PMD.digits.root(TreeD),        //
20 //  calls the Clustering algorithm and stores the      //
21 //  clustering output in PMD.RecPoints.root(TreeR)     // 
22 //                                                     //
23 //-----------------------------------------------------//
24
25 #include <Riostream.h>
26 #include <TMath.h>
27 #include <TBRIK.h>
28 #include <TNode.h>
29 #include <TTree.h>
30 #include <TGeometry.h>
31 #include <TObjArray.h>
32 #include <TClonesArray.h>
33 #include <TFile.h>
34 #include <TNtuple.h>
35 #include <TParticle.h>
36
37 #include "AliRun.h"
38 #include "AliPMD.h"
39 #include "AliDetector.h"
40 #include "AliRunLoader.h"
41 #include "AliLoader.h"
42 #include "AliHeader.h"
43
44 #include "AliPMDdigit.h"
45 #include "AliPMDClusterFinder.h"
46 #include "AliPMDClustering.h"
47 #include "AliPMDcluster.h"
48 #include "AliPMDrecpoint1.h"
49
50
51 ClassImp(AliPMDClusterFinder)
52
53 AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
54   fRunLoader(runLoader),
55   fPMDLoader(runLoader->GetLoader("PMDLoader")),
56   fTreeD(0),
57   fTreeR(0),
58   fDigits(new TClonesArray("AliPMDdigit", 1000)),
59   fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
60   fNpoint(0),
61   fDebug(0),
62   fEcut(0.)
63 {
64 //
65 // Constructor
66 //
67 }
68 // ------------------------------------------------------------------------- //
69 AliPMDClusterFinder::~AliPMDClusterFinder()
70 {
71   // Destructor
72   if (fDigits)
73     {
74       fDigits->Delete();
75       delete fDigits;
76       fDigits=0;
77     }
78   if (fRecpoints)
79     {
80       fRecpoints->Delete();
81       delete fRecpoints;
82       fRecpoints=0;
83     }
84 }
85 // ------------------------------------------------------------------------- //
86
87 void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
88 {
89   // Converts digits to recpoints after running clustering
90   // algorithm on CPV plane and PREshower plane
91   //
92   Int_t    det = 0,smn = 0;
93   Int_t    xpos,ypos;
94   Float_t  adc;
95   Int_t    ismn;
96   Int_t    idet;
97   Float_t  clusdata[5];
98
99   TObjArray *pmdcont = new TObjArray();
100   AliPMDClustering *pmdclust = new AliPMDClustering();
101   pmdclust->SetDebug(fDebug);
102   pmdclust->SetEdepCut(fEcut);
103
104   fRunLoader->GetEvent(ievt);
105   //cout << " ***** Beginning::Digits2RecPoints *****" << endl;
106   fTreeD = fPMDLoader->TreeD();
107   if (fTreeD == 0x0)
108     {
109       cout << " Can not get TreeD" << endl;
110     }
111   AliPMDdigit  *pmddigit;
112   TBranch *branch = fTreeD->GetBranch("PMDDigit");
113   branch->SetAddress(&fDigits);
114
115   ResetRecpoint();
116   fTreeR = fPMDLoader->TreeR();
117   if (fTreeR == 0x0)
118     {
119       fPMDLoader->MakeTree("R");
120       fTreeR = fPMDLoader->TreeR();
121     }
122
123   Int_t bufsize = 16000;
124   fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize); 
125
126   Int_t nmodules = (Int_t) fTreeD->GetEntries();
127   
128   for (Int_t imodule = 0; imodule < nmodules; imodule++)
129     {
130       ResetCellADC();
131       fTreeD->GetEntry(imodule); 
132       Int_t nentries = fDigits->GetLast();
133       for (Int_t ient = 0; ient < nentries+1; ient++)
134         {
135           pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
136           
137           det    = pmddigit->GetDetector();
138           smn    = pmddigit->GetSMNumber();
139           xpos   = pmddigit->GetRow();
140           ypos   = pmddigit->GetColumn();
141           adc    = pmddigit->GetADC();
142           //Int_t trno   = pmddigit->GetTrackNumber();
143
144           fCellADC[xpos][ypos] = (Double_t) adc;
145         }
146
147       idet = det;
148       ismn = smn;
149       pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
150       
151       Int_t nentries1 = pmdcont->GetEntries();
152 //      cout << " nentries1 = " << nentries1 << endl;
153       for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
154         {
155           AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
156           idet        = pmdcl->GetDetector();
157           ismn        = pmdcl->GetSMN();
158           clusdata[0] = pmdcl->GetClusX();
159           clusdata[1] = pmdcl->GetClusY();
160           clusdata[2] = pmdcl->GetClusADC();
161           clusdata[3] = pmdcl->GetClusCells();
162           clusdata[4] = pmdcl->GetClusRadius();
163           
164           AddRecPoint(idet,ismn,clusdata);
165         }
166       pmdcont->Clear();
167       
168       fTreeR->Fill();
169       ResetRecpoint();
170
171     } // modules
172
173   ResetCellADC();
174   fPMDLoader = fRunLoader->GetLoader("PMDLoader");  
175   fPMDLoader->WriteRecPoints("OVERWRITE");
176
177   //   delete the pointers
178   delete pmdclust;
179   delete pmdcont;
180     
181   //  cout << " ***** End::Digits2RecPoints *****" << endl;
182 }
183 // ------------------------------------------------------------------------- //
184 void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
185 {
186   fEcut = ecut;
187 }
188 // ------------------------------------------------------------------------- //
189 void AliPMDClusterFinder::SetDebug(Int_t idebug)
190 {
191   fDebug = idebug;
192 }
193 // ------------------------------------------------------------------------- //
194 void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
195 {
196   // Add Reconstructed points
197   //
198   TClonesArray &lrecpoints = *fRecpoints;
199   AliPMDrecpoint1 *newrecpoint;
200   newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
201   new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
202   delete newrecpoint;
203 }
204 // ------------------------------------------------------------------------- //
205 void AliPMDClusterFinder::ResetCellADC()
206 {
207   // Reset the individual cell ADC value to zero
208   //
209   for(Int_t irow = 0; irow < fgkRow; irow++)
210     {
211       for(Int_t icol = 0; icol < fgkCol; icol++)
212         {
213           fCellADC[irow][icol] = 0.;
214         }
215     }
216 }
217 // ------------------------------------------------------------------------- //
218
219 void AliPMDClusterFinder::ResetRecpoint()
220 {
221   // Clear the list of reconstructed points
222   fNpoint = 0;
223   if (fRecpoints) fRecpoints->Clear();
224 }
225 // ------------------------------------------------------------------------- //
226 void AliPMDClusterFinder::Load()
227 {
228   // Load all the *.root files
229   //
230   fPMDLoader->LoadDigits("READ");
231   fPMDLoader->LoadRecPoints("recreate");
232 }
233 // ------------------------------------------------------------------------- //
234 void AliPMDClusterFinder::UnLoad()
235 {
236   // Unload all the *.root files
237   //
238   fPMDLoader->UnloadDigits();
239   fPMDLoader->UnloadRecPoints();
240 }
241 // ------------------------------------------------------------------------- //