heather's optimisations
[u/mrichter/AliRoot.git] / PMD / AliPMDClusterFinder.cxx
CommitLineData
ed228cbc 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
01709453 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>
b208c6a3 26#include <TMath.h>
01709453 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"
01709453 47#include "AliPMDcluster.h"
96377d57 48#include "AliPMDrecpoint1.h"
01709453 49
50
51ClassImp(AliPMDClusterFinder)
b208c6a3 52
dfaeee5f 53AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
54 fRunLoader(runLoader),
55 fPMDLoader(runLoader->GetLoader("PMDLoader")),
1758e4fe 56 fTreeD(0),
57 fTreeR(0),
58 fDigits(0),
59 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
60 fNpoint(0),
61 fDebug(0),
62 fEcut(0.)
01709453 63{
b208c6a3 64//
dfaeee5f 65// Constructor
b208c6a3 66//
01709453 67}
1758e4fe 68// ------------------------------------------------------------------------- //
01709453 69AliPMDClusterFinder::~AliPMDClusterFinder()
70{
b208c6a3 71 // Destructor
1758e4fe 72 if (fRecpoints)
73 {
74 fRecpoints->Delete();
75 delete fRecpoints;
76 fRecpoints=0;
77 }
01709453 78}
1758e4fe 79// ------------------------------------------------------------------------- //
b208c6a3 80
01709453 81void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
82{
b208c6a3 83 // Converts digits to recpoints after running clustering
84 // algorithm on CPV plane and PREshower plane
85 //
ed228cbc 86 Int_t det = 0,smn = 0;
01709453 87 Int_t xpos,ypos;
88 Float_t adc;
1758e4fe 89 Int_t ismn;
01709453 90 Int_t idet;
1758e4fe 91 Float_t clusdata[5];
ed228cbc 92
93 TObjArray *pmdcont = new TObjArray();
94 AliPMDcluster *pmdcl = new AliPMDcluster;
95 AliPMDClustering *pmdclust = new AliPMDClustering();
96 pmdclust->SetDebug(fDebug);
97 pmdclust->SetEdepCut(fEcut);
01709453 98
99 fRunLoader->GetEvent(ievt);
100 //cout << " ***** Beginning::Digits2RecPoints *****" << endl;
b208c6a3 101 fTreeD = fPMDLoader->TreeD();
102 if (fTreeD == 0x0)
01709453 103 {
104 cout << " Can not get TreeD" << endl;
105 }
106 AliPMDdigit *pmddigit;
b208c6a3 107 TBranch *branch = fTreeD->GetBranch("PMDDigit");
01709453 108 branch->SetAddress(&fDigits);
109
110 ResetRecpoint();
b208c6a3 111 fTreeR = fPMDLoader->TreeR();
112 if (fTreeR == 0x0)
01709453 113 {
b208c6a3 114 fPMDLoader->MakeTree("R");
115 fTreeR = fPMDLoader->TreeR();
01709453 116 }
117
118 Int_t bufsize = 16000;
b208c6a3 119 fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
01709453 120
b208c6a3 121 Int_t nmodules = (Int_t) fTreeD->GetEntries();
01709453 122
123 for (Int_t imodule = 0; imodule < nmodules; imodule++)
124 {
ed228cbc 125 ResetCellADC();
b208c6a3 126 fTreeD->GetEntry(imodule);
01709453 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();
5e6a9312 134 xpos = pmddigit->GetRow();
135 ypos = pmddigit->GetColumn();
01709453 136 adc = pmddigit->GetADC();
ed228cbc 137 //Int_t trno = pmddigit->GetTrackNumber();
01709453 138
ed228cbc 139 fCellADC[xpos][ypos] = (Double_t) adc;
01709453 140 }
01709453 141
ed228cbc 142 idet = det;
1758e4fe 143 ismn = smn;
144 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
ed228cbc 145
146 Int_t nentries1 = pmdcont->GetEntries();
dfaeee5f 147// cout << " nentries1 = " << nentries1 << endl;
ed228cbc 148 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
01709453 149 {
ed228cbc 150 pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
1758e4fe 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();
01709453 158
1758e4fe 159 AddRecPoint(idet,ismn,clusdata);
ed228cbc 160 }
161 pmdcont->Clear();
162
b208c6a3 163 fTreeR->Fill();
ed228cbc 164 ResetRecpoint();
165
166 } // modules
167
01709453 168 ResetCellADC();
e1287360 169 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b208c6a3 170 fPMDLoader->WriteRecPoints("OVERWRITE");
01709453 171
172 // delete the pointers
173 delete pmdclust;
174 delete pmdcont;
175
176 // cout << " ***** End::Digits2RecPoints *****" << endl;
177}
1758e4fe 178// ------------------------------------------------------------------------- //
ed228cbc 179void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
180{
181 fEcut = ecut;
182}
1758e4fe 183// ------------------------------------------------------------------------- //
ed228cbc 184void AliPMDClusterFinder::SetDebug(Int_t idebug)
185{
186 fDebug = idebug;
187}
1758e4fe 188// ------------------------------------------------------------------------- //
189void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
01709453 190{
b208c6a3 191 // Add Reconstructed points
192 //
01709453 193 TClonesArray &lrecpoints = *fRecpoints;
ed228cbc 194 AliPMDrecpoint1 *newrecpoint;
1758e4fe 195 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
ed228cbc 196 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
01709453 197 delete newrecpoint;
198}
1758e4fe 199// ------------------------------------------------------------------------- //
01709453 200void AliPMDClusterFinder::ResetCellADC()
201{
b208c6a3 202 // Reset the individual cell ADC value to zero
203 //
5e6a9312 204 for(Int_t irow = 0; irow < fgkRow; irow++)
01709453 205 {
5e6a9312 206 for(Int_t icol = 0; icol < fgkCol; icol++)
01709453 207 {
ed228cbc 208 fCellADC[irow][icol] = 0.;
01709453 209 }
210 }
211}
1758e4fe 212// ------------------------------------------------------------------------- //
01709453 213
214void AliPMDClusterFinder::ResetRecpoint()
215{
b208c6a3 216 // Clear the list of reconstructed points
01709453 217 fNpoint = 0;
218 if (fRecpoints) fRecpoints->Clear();
219}
1758e4fe 220// ------------------------------------------------------------------------- //
55601d47 221void AliPMDClusterFinder::Load()
222{
223 // Unload all the *.root files
224 //
225 fPMDLoader->LoadDigits("READ");
226 fPMDLoader->LoadRecPoints("recreate");
227}
228// ------------------------------------------------------------------------- //
01709453 229void AliPMDClusterFinder::UnLoad(Option_t *option)
230{
b208c6a3 231 // Unload all the *.root files
232 //
01709453 233 const char *cR = strstr(option,"R");
234
235 fRunLoader->UnloadgAlice();
01709453 236
237 if (cR)
238 {
b208c6a3 239 fPMDLoader->UnloadDigits();
e1287360 240 fPMDLoader->UnloadRecPoints();
01709453 241 }
242}
1758e4fe 243// ------------------------------------------------------------------------- //