]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDClusterFinder.cxx
fd8499e03c4c37b25f40a7a20f71da390622ff04
[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(0),
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 (fRecpoints)
73     {
74       fRecpoints->Delete();
75       delete fRecpoints;
76       fRecpoints=0;
77     }
78 }
79 // ------------------------------------------------------------------------- //
80
81 void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
82 {
83   // Converts digits to recpoints after running clustering
84   // algorithm on CPV plane and PREshower plane
85   //
86   Int_t    det = 0,smn = 0;
87   Int_t    xpos,ypos;
88   Float_t  adc;
89   Int_t    ismn;
90   Int_t    idet;
91   Float_t  clusdata[5];
92
93   TObjArray *pmdcont = new TObjArray();
94   AliPMDcluster  *pmdcl  = new AliPMDcluster;
95   AliPMDClustering *pmdclust = new AliPMDClustering();
96   pmdclust->SetDebug(fDebug);
97   pmdclust->SetEdepCut(fEcut);
98
99   fRunLoader->GetEvent(ievt);
100   //cout << " ***** Beginning::Digits2RecPoints *****" << endl;
101   fTreeD = fPMDLoader->TreeD();
102   if (fTreeD == 0x0)
103     {
104       cout << " Can not get TreeD" << endl;
105     }
106   AliPMDdigit  *pmddigit;
107   TBranch *branch = fTreeD->GetBranch("PMDDigit");
108   branch->SetAddress(&fDigits);
109
110   ResetRecpoint();
111   fTreeR = fPMDLoader->TreeR();
112   if (fTreeR == 0x0)
113     {
114       fPMDLoader->MakeTree("R");
115       fTreeR = fPMDLoader->TreeR();
116     }
117
118   Int_t bufsize = 16000;
119   fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize); 
120
121   Int_t nmodules = (Int_t) fTreeD->GetEntries();
122   
123   for (Int_t imodule = 0; imodule < nmodules; imodule++)
124     {
125       ResetCellADC();
126       fTreeD->GetEntry(imodule); 
127       Int_t nentries = fDigits->GetLast();
128       for (Int_t ient = 0; ient < nentries+1; ient++)
129         {
130           pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
131           
132           det    = pmddigit->GetDetector();
133           smn    = pmddigit->GetSMNumber();
134           xpos   = pmddigit->GetRow();
135           ypos   = pmddigit->GetColumn();
136           adc    = pmddigit->GetADC();
137           //Int_t trno   = pmddigit->GetTrackNumber();
138
139           fCellADC[xpos][ypos] = (Double_t) adc;
140         }
141
142       idet = det;
143       ismn = smn;
144       pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
145       
146       Int_t nentries1 = pmdcont->GetEntries();
147 //      cout << " nentries1 = " << nentries1 << endl;
148       for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
149         {
150           pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
151           idet        = pmdcl->GetDetector();
152           ismn        = pmdcl->GetSMN();
153           clusdata[0] = pmdcl->GetClusX();
154           clusdata[1] = pmdcl->GetClusY();
155           clusdata[2] = pmdcl->GetClusADC();
156           clusdata[3] = pmdcl->GetClusCells();
157           clusdata[4] = pmdcl->GetClusRadius();
158           
159           AddRecPoint(idet,ismn,clusdata);
160         }
161       pmdcont->Clear();
162       
163       fTreeR->Fill();
164       ResetRecpoint();
165
166     } // modules
167
168   ResetCellADC();
169   fPMDLoader = fRunLoader->GetLoader("PMDLoader");  
170   fPMDLoader->WriteRecPoints("OVERWRITE");
171
172   //   delete the pointers
173   delete pmdclust;
174   delete pmdcont;
175     
176   //  cout << " ***** End::Digits2RecPoints *****" << endl;
177 }
178 // ------------------------------------------------------------------------- //
179 void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
180 {
181   fEcut = ecut;
182 }
183 // ------------------------------------------------------------------------- //
184 void AliPMDClusterFinder::SetDebug(Int_t idebug)
185 {
186   fDebug = idebug;
187 }
188 // ------------------------------------------------------------------------- //
189 void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
190 {
191   // Add Reconstructed points
192   //
193   TClonesArray &lrecpoints = *fRecpoints;
194   AliPMDrecpoint1 *newrecpoint;
195   newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
196   new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
197   delete newrecpoint;
198 }
199 // ------------------------------------------------------------------------- //
200 void AliPMDClusterFinder::ResetCellADC()
201 {
202   // Reset the individual cell ADC value to zero
203   //
204   for(Int_t irow = 0; irow < fgkRow; irow++)
205     {
206       for(Int_t icol = 0; icol < fgkCol; icol++)
207         {
208           fCellADC[irow][icol] = 0.;
209         }
210     }
211 }
212 // ------------------------------------------------------------------------- //
213
214 void AliPMDClusterFinder::ResetRecpoint()
215 {
216   // Clear the list of reconstructed points
217   fNpoint = 0;
218   if (fRecpoints) fRecpoints->Clear();
219 }
220 // ------------------------------------------------------------------------- //
221 void AliPMDClusterFinder::Load()
222 {
223   // Unload all the *.root files
224   //
225   fPMDLoader->LoadDigits("READ");
226   fPMDLoader->LoadRecPoints("recreate");
227 }
228 // ------------------------------------------------------------------------- //
229 void AliPMDClusterFinder::UnLoad(Option_t *option)
230 {
231   // Unload all the *.root files
232   //
233   const char *cR = strstr(option,"R");
234
235   fRunLoader->UnloadgAlice();
236
237   if (cR)
238     {
239       fPMDLoader->UnloadDigits();
240       fPMDLoader->UnloadRecPoints();
241     }
242 }
243 // ------------------------------------------------------------------------- //