New files from Basanta
[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
1758e4fe 53AliPMDClusterFinder::AliPMDClusterFinder():
54 fRunLoader(0),
55 fPMDLoader(0),
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//
65// Default Constructor
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
1758e4fe 81void AliPMDClusterFinder::OpengAliceFile(const Char_t *file, Option_t *option)
01709453 82{
b208c6a3 83 // Loads galice.root file and corresponding header, kinematics
84 // hits and sdigits or digits depending on the option
85 //
e191bb57 86 fRunLoader = AliRunLoader::Open(file,AliConfig::GetDefaultEventFolderName(),
01709453 87 "UPDATE");
88
89 if (!fRunLoader)
90 {
91 Error("Open","Can not open session for file %s.",file);
92 }
93
94 fRunLoader->LoadgAlice();
01709453 95 gAlice = fRunLoader->GetAliRun();
96
97 if (gAlice)
98 {
99 printf("<AliPMDdigitizer::Open> ");
100 printf("AliRun object found on file.\n");
101 }
102 else
103 {
104 printf("<AliPMDdigitizer::Open> ");
105 printf("Could not find AliRun object.\n");
106 }
b208c6a3 107 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
108 if (fPMDLoader == 0x0)
01709453 109 {
110 cerr<<"OpengAlice : Can not find PMD or PMDLoader\n";
111 }
112
113 const char *cDR = strstr(option,"DR");
114
115 if (cDR)
116 {
b208c6a3 117 fPMDLoader->LoadDigits("READ");
118 fPMDLoader->LoadRecPoints("recreate");
01709453 119 }
120}
1758e4fe 121// ------------------------------------------------------------------------- //
01709453 122
123void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
124{
b208c6a3 125 // Converts digits to recpoints after running clustering
126 // algorithm on CPV plane and PREshower plane
127 //
ed228cbc 128 Int_t det = 0,smn = 0;
01709453 129 Int_t xpos,ypos;
130 Float_t adc;
1758e4fe 131 Int_t ismn;
01709453 132 Int_t idet;
1758e4fe 133 Float_t clusdata[5];
ed228cbc 134
135 TObjArray *pmdcont = new TObjArray();
136 AliPMDcluster *pmdcl = new AliPMDcluster;
137 AliPMDClustering *pmdclust = new AliPMDClustering();
138 pmdclust->SetDebug(fDebug);
139 pmdclust->SetEdepCut(fEcut);
01709453 140
141 fRunLoader->GetEvent(ievt);
142 //cout << " ***** Beginning::Digits2RecPoints *****" << endl;
b208c6a3 143 fTreeD = fPMDLoader->TreeD();
144 if (fTreeD == 0x0)
01709453 145 {
146 cout << " Can not get TreeD" << endl;
147 }
148 AliPMDdigit *pmddigit;
b208c6a3 149 TBranch *branch = fTreeD->GetBranch("PMDDigit");
01709453 150 branch->SetAddress(&fDigits);
151
152 ResetRecpoint();
b208c6a3 153 fTreeR = fPMDLoader->TreeR();
154 if (fTreeR == 0x0)
01709453 155 {
b208c6a3 156 fPMDLoader->MakeTree("R");
157 fTreeR = fPMDLoader->TreeR();
01709453 158 }
159
160 Int_t bufsize = 16000;
b208c6a3 161 fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
01709453 162
b208c6a3 163 Int_t nmodules = (Int_t) fTreeD->GetEntries();
01709453 164
165 for (Int_t imodule = 0; imodule < nmodules; imodule++)
166 {
ed228cbc 167 ResetCellADC();
b208c6a3 168 fTreeD->GetEntry(imodule);
01709453 169 Int_t nentries = fDigits->GetLast();
170 for (Int_t ient = 0; ient < nentries+1; ient++)
171 {
172 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
173
174 det = pmddigit->GetDetector();
175 smn = pmddigit->GetSMNumber();
5e6a9312 176 xpos = pmddigit->GetRow();
177 ypos = pmddigit->GetColumn();
01709453 178 adc = pmddigit->GetADC();
ed228cbc 179 //Int_t trno = pmddigit->GetTrackNumber();
01709453 180
ed228cbc 181 fCellADC[xpos][ypos] = (Double_t) adc;
01709453 182 }
01709453 183
ed228cbc 184 idet = det;
1758e4fe 185 ismn = smn;
186 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
ed228cbc 187
188 Int_t nentries1 = pmdcont->GetEntries();
189 cout << " nentries1 = " << nentries1 << endl;
190 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
01709453 191 {
ed228cbc 192 pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
1758e4fe 193 idet = pmdcl->GetDetector();
194 ismn = pmdcl->GetSMN();
195 clusdata[0] = pmdcl->GetClusX();
196 clusdata[1] = pmdcl->GetClusY();
197 clusdata[2] = pmdcl->GetClusADC();
198 clusdata[3] = pmdcl->GetClusCells();
199 clusdata[4] = pmdcl->GetClusRadius();
01709453 200
1758e4fe 201 AddRecPoint(idet,ismn,clusdata);
ed228cbc 202 }
203 pmdcont->Clear();
204
b208c6a3 205 fTreeR->Fill();
ed228cbc 206 ResetRecpoint();
207
208 } // modules
209
01709453 210 ResetCellADC();
e1287360 211 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b208c6a3 212 fPMDLoader->WriteRecPoints("OVERWRITE");
01709453 213
214 // delete the pointers
215 delete pmdclust;
216 delete pmdcont;
217
218 // cout << " ***** End::Digits2RecPoints *****" << endl;
219}
1758e4fe 220// ------------------------------------------------------------------------- //
ed228cbc 221void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
222{
223 fEcut = ecut;
224}
1758e4fe 225// ------------------------------------------------------------------------- //
ed228cbc 226void AliPMDClusterFinder::SetDebug(Int_t idebug)
227{
228 fDebug = idebug;
229}
1758e4fe 230// ------------------------------------------------------------------------- //
231void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
01709453 232{
b208c6a3 233 // Add Reconstructed points
234 //
01709453 235 TClonesArray &lrecpoints = *fRecpoints;
ed228cbc 236 AliPMDrecpoint1 *newrecpoint;
1758e4fe 237 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
ed228cbc 238 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
01709453 239 delete newrecpoint;
240}
1758e4fe 241// ------------------------------------------------------------------------- //
01709453 242void AliPMDClusterFinder::ResetCellADC()
243{
b208c6a3 244 // Reset the individual cell ADC value to zero
245 //
5e6a9312 246 for(Int_t irow = 0; irow < fgkRow; irow++)
01709453 247 {
5e6a9312 248 for(Int_t icol = 0; icol < fgkCol; icol++)
01709453 249 {
ed228cbc 250 fCellADC[irow][icol] = 0.;
01709453 251 }
252 }
253}
1758e4fe 254// ------------------------------------------------------------------------- //
01709453 255
256void AliPMDClusterFinder::ResetRecpoint()
257{
b208c6a3 258 // Clear the list of reconstructed points
01709453 259 fNpoint = 0;
260 if (fRecpoints) fRecpoints->Clear();
261}
1758e4fe 262// ------------------------------------------------------------------------- //
01709453 263void AliPMDClusterFinder::UnLoad(Option_t *option)
264{
b208c6a3 265 // Unload all the *.root files
266 //
01709453 267 const char *cR = strstr(option,"R");
268
269 fRunLoader->UnloadgAlice();
01709453 270
271 if (cR)
272 {
b208c6a3 273 fPMDLoader->UnloadDigits();
e1287360 274 fPMDLoader->UnloadRecPoints();
01709453 275 }
276}
1758e4fe 277// ------------------------------------------------------------------------- //