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