New methods Reconstruct and FillESD added
[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>
01709453 26#include <TTree.h>
01709453 27#include <TObjArray.h>
28#include <TClonesArray.h>
01709453 29
01709453 30#include "AliRunLoader.h"
31#include "AliLoader.h"
5f55af10 32#include "AliRawReader.h"
01709453 33
34#include "AliPMDdigit.h"
35#include "AliPMDClusterFinder.h"
36#include "AliPMDClustering.h"
01709453 37#include "AliPMDcluster.h"
96377d57 38#include "AliPMDrecpoint1.h"
5f55af10 39#include "AliPMDRawStream.h"
01709453 40
41ClassImp(AliPMDClusterFinder)
b208c6a3 42
dfaeee5f 43AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
44 fRunLoader(runLoader),
45 fPMDLoader(runLoader->GetLoader("PMDLoader")),
1758e4fe 46 fTreeD(0),
47 fTreeR(0),
ebd83c56 48 fDigits(new TClonesArray("AliPMDdigit", 1000)),
1758e4fe 49 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
50 fNpoint(0),
51 fDebug(0),
52 fEcut(0.)
01709453 53{
b208c6a3 54//
dfaeee5f 55// Constructor
b208c6a3 56//
01709453 57}
1758e4fe 58// ------------------------------------------------------------------------- //
01709453 59AliPMDClusterFinder::~AliPMDClusterFinder()
60{
b208c6a3 61 // Destructor
ebd83c56 62 if (fDigits)
63 {
64 fDigits->Delete();
65 delete fDigits;
66 fDigits=0;
67 }
1758e4fe 68 if (fRecpoints)
69 {
70 fRecpoints->Delete();
71 delete fRecpoints;
72 fRecpoints=0;
73 }
01709453 74}
1758e4fe 75// ------------------------------------------------------------------------- //
b208c6a3 76
01709453 77void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
78{
b208c6a3 79 // Converts digits to recpoints after running clustering
80 // algorithm on CPV plane and PREshower plane
81 //
ed228cbc 82 Int_t det = 0,smn = 0;
01709453 83 Int_t xpos,ypos;
84 Float_t adc;
1758e4fe 85 Int_t ismn;
01709453 86 Int_t idet;
1758e4fe 87 Float_t clusdata[5];
ed228cbc 88
89 TObjArray *pmdcont = new TObjArray();
ed228cbc 90 AliPMDClustering *pmdclust = new AliPMDClustering();
91 pmdclust->SetDebug(fDebug);
92 pmdclust->SetEdepCut(fEcut);
01709453 93
94 fRunLoader->GetEvent(ievt);
95 //cout << " ***** Beginning::Digits2RecPoints *****" << endl;
01b56f5c 96
b208c6a3 97 fTreeD = fPMDLoader->TreeD();
98 if (fTreeD == 0x0)
01709453 99 {
100 cout << " Can not get TreeD" << endl;
101 }
102 AliPMDdigit *pmddigit;
b208c6a3 103 TBranch *branch = fTreeD->GetBranch("PMDDigit");
01709453 104 branch->SetAddress(&fDigits);
105
106 ResetRecpoint();
01b56f5c 107
b208c6a3 108 fTreeR = fPMDLoader->TreeR();
109 if (fTreeR == 0x0)
01709453 110 {
b208c6a3 111 fPMDLoader->MakeTree("R");
112 fTreeR = fPMDLoader->TreeR();
01709453 113 }
114
115 Int_t bufsize = 16000;
b208c6a3 116 fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
01709453 117
b208c6a3 118 Int_t nmodules = (Int_t) fTreeD->GetEntries();
01b56f5c 119
01709453 120 for (Int_t imodule = 0; imodule < nmodules; imodule++)
121 {
ed228cbc 122 ResetCellADC();
b208c6a3 123 fTreeD->GetEntry(imodule);
01709453 124 Int_t nentries = fDigits->GetLast();
125 for (Int_t ient = 0; ient < nentries+1; ient++)
126 {
127 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
128
129 det = pmddigit->GetDetector();
130 smn = pmddigit->GetSMNumber();
5e6a9312 131 xpos = pmddigit->GetRow();
132 ypos = pmddigit->GetColumn();
01709453 133 adc = pmddigit->GetADC();
ed228cbc 134 //Int_t trno = pmddigit->GetTrackNumber();
ed228cbc 135 fCellADC[xpos][ypos] = (Double_t) adc;
01709453 136 }
01709453 137
ed228cbc 138 idet = det;
1758e4fe 139 ismn = smn;
8616b098 140 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
ed228cbc 141
142 Int_t nentries1 = pmdcont->GetEntries();
dfaeee5f 143// cout << " nentries1 = " << nentries1 << endl;
ed228cbc 144 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
01709453 145 {
ebd83c56 146 AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
1758e4fe 147 idet = pmdcl->GetDetector();
148 ismn = pmdcl->GetSMN();
149 clusdata[0] = pmdcl->GetClusX();
150 clusdata[1] = pmdcl->GetClusY();
151 clusdata[2] = pmdcl->GetClusADC();
152 clusdata[3] = pmdcl->GetClusCells();
153 clusdata[4] = pmdcl->GetClusRadius();
01b56f5c 154
1758e4fe 155 AddRecPoint(idet,ismn,clusdata);
ed228cbc 156 }
157 pmdcont->Clear();
158
b208c6a3 159 fTreeR->Fill();
ed228cbc 160 ResetRecpoint();
161
162 } // modules
163
01709453 164 ResetCellADC();
e1287360 165 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b208c6a3 166 fPMDLoader->WriteRecPoints("OVERWRITE");
01709453 167
168 // delete the pointers
169 delete pmdclust;
170 delete pmdcont;
171
172 // cout << " ***** End::Digits2RecPoints *****" << endl;
173}
1758e4fe 174// ------------------------------------------------------------------------- //
5f55af10 175
176void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
177{
01b56f5c 178 // Converts RAW data to recpoints after running clustering
179 // algorithm on CPV and PREshower plane
5f55af10 180 //
181
182 Float_t clusdata[5];
183
5f55af10 184 TObjArray *pmdcont = new TObjArray();
185 AliPMDClustering *pmdclust = new AliPMDClustering();
186 pmdclust->SetDebug(fDebug);
187 pmdclust->SetEdepCut(fEcut);
188
189 fRunLoader->GetEvent(ievt);
190
191 ResetRecpoint();
01b56f5c 192
5f55af10 193 fTreeR = fPMDLoader->TreeR();
194 if (fTreeR == 0x0)
195 {
196 fPMDLoader->MakeTree("R");
197 fTreeR = fPMDLoader->TreeR();
198 }
5f55af10 199 Int_t bufsize = 16000;
200 fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
01b56f5c 201
202 const Int_t kDDL = 6;
5f55af10 203 const Int_t kRow = 48;
204 const Int_t kCol = 96;
5f55af10 205
01b56f5c 206 Int_t idet = 0;
207 Int_t iSMN = 0;
208
209 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
5f55af10 210 {
01b56f5c 211 if (indexDDL < 4)
5f55af10 212 {
01b56f5c 213 iSMN = 6;
5f55af10 214 }
01b56f5c 215 else if (indexDDL >= 4)
5f55af10 216 {
01b56f5c 217 iSMN = 12;
5f55af10 218 }
01b56f5c 219 Int_t ***precpvADC;
220 precpvADC = new int **[iSMN];
221 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
222 for (Int_t i=0; i<iSMN;i++)
5f55af10 223 {
01b56f5c 224 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
5f55af10 225 }
01b56f5c 226 for (Int_t i = 0; i < iSMN; i++)
227 {
228 for (Int_t j = 0; j < kRow; j++)
229 {
230 for (Int_t k = 0; k < kCol; k++)
231 {
232 precpvADC[i][j][k] = 0;
233 }
234 }
235 }
236 ResetCellADC();
237 rawReader->Reset();
238 AliPMDRawStream pmdinput(rawReader);
239 rawReader->Select(12, indexDDL, indexDDL);
240 while(pmdinput.Next())
241 {
242 Int_t det = pmdinput.GetDetector();
243 Int_t smn = pmdinput.GetSMN();
244 //Int_t mcm = pmdinput.GetMCM();
245 //Int_t chno = pmdinput.GetChannel();
246 Int_t row = pmdinput.GetRow();
247 Int_t col = pmdinput.GetColumn();
248 Int_t sig = pmdinput.GetSignal();
249
250 Int_t indexsmn = 0;
5f55af10 251
01b56f5c 252 if (indexDDL < 4)
253 {
254 if (det != 0)
255 printf(" *** DDL %d and Detector NUMBER %d NOT MATCHING *** ",
256 indexDDL, det);
257 indexsmn = smn - indexDDL * 6;
258 }
259 else if (indexDDL == 4)
260 {
261 if (det != 1)
262 printf(" *** DDL %d and Detector NUMBER %d NOT MATCHING *** ",
263 indexDDL, det);
264 if (smn < 6)
265 {
266 indexsmn = smn;
267 }
268 else if (smn >= 12 && smn < 18)
269 {
270 indexsmn = smn - 6;
271 }
272 }
273 else if (indexDDL == 5)
274 {
275 if (det != 1)
276 printf(" *** DDL %d and Detector NUMBER %d NOT MATCHING *** ",
277 indexDDL, det);
278 if (smn >= 6 && smn < 12)
279 {
280 indexsmn = smn - 6;
281 }
282 else if (smn >= 18 && smn < 24)
283 {
284 indexsmn = smn - 12;
285 }
286 }
287 precpvADC[indexsmn][row][col] = sig;
288 } // while loop
289
290 Int_t ismn = 0;
291 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
5f55af10 292 {
01b56f5c 293 ResetCellADC();
5f55af10 294 for (Int_t irow = 0; irow < kRow; irow++)
295 {
296 for (Int_t icol = 0; icol < kCol; icol++)
297 {
01b56f5c 298 fCellADC[irow][icol] =
299 (Double_t) precpvADC[indexsmn][irow][icol];
5f55af10 300 } // row
301 } // col
01b56f5c 302 if (indexDDL < 4)
303 {
304 ismn = indexsmn + indexDDL * 6;
305 idet = 0;
306 }
307 else if (indexDDL == 4)
308 {
309 if (indexsmn < 6)
310 {
311 ismn = indexsmn;
312 }
313 else if (indexsmn >= 6 && indexsmn < 12)
314 {
315 ismn = indexsmn + 6;
316 }
317 idet = 1;
318 }
319 else if (indexDDL == 5)
320 {
321 if (indexsmn < 6)
322 {
323 ismn = indexsmn + 6;
324 }
325 else if (indexsmn >= 6 && indexsmn < 12)
326 {
327 ismn = indexsmn + 12;
328 }
329 idet = 1;
330 }
331
332
5f55af10 333 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
334 Int_t nentries1 = pmdcont->GetEntries();
335 // cout << " nentries1 = " << nentries1 << endl;
336 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
337 {
338 AliPMDcluster *pmdcl =
339 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
340 idet = pmdcl->GetDetector();
341 ismn = pmdcl->GetSMN();
342 clusdata[0] = pmdcl->GetClusX();
343 clusdata[1] = pmdcl->GetClusY();
344 clusdata[2] = pmdcl->GetClusADC();
345 clusdata[3] = pmdcl->GetClusCells();
346 clusdata[4] = pmdcl->GetClusRadius();
01b56f5c 347
5f55af10 348 AddRecPoint(idet,ismn,clusdata);
349 }
350 pmdcont->Clear();
351
352 fTreeR->Fill();
353 ResetRecpoint();
01b56f5c 354
355
5f55af10 356 } // smn
5f55af10 357
01b56f5c 358 for (Int_t i=0; i<iSMN; i++)
359 {
360 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
361 }
362 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
363 delete precpvADC;
364 } // DDL Loop
365
5f55af10 366 ResetCellADC();
01b56f5c 367
5f55af10 368 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
369 fPMDLoader->WriteRecPoints("OVERWRITE");
370
371 // delete the pointers
372 delete pmdclust;
373 delete pmdcont;
374
375 // cout << " ***** End::Digits2RecPoints :: Raw *****" << endl;
376}
377// ------------------------------------------------------------------------- //
ed228cbc 378void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
379{
380 fEcut = ecut;
381}
1758e4fe 382// ------------------------------------------------------------------------- //
ed228cbc 383void AliPMDClusterFinder::SetDebug(Int_t idebug)
384{
385 fDebug = idebug;
386}
1758e4fe 387// ------------------------------------------------------------------------- //
388void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
01709453 389{
b208c6a3 390 // Add Reconstructed points
391 //
01709453 392 TClonesArray &lrecpoints = *fRecpoints;
ed228cbc 393 AliPMDrecpoint1 *newrecpoint;
1758e4fe 394 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
ed228cbc 395 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
01709453 396 delete newrecpoint;
397}
1758e4fe 398// ------------------------------------------------------------------------- //
01709453 399void AliPMDClusterFinder::ResetCellADC()
400{
b208c6a3 401 // Reset the individual cell ADC value to zero
402 //
5e6a9312 403 for(Int_t irow = 0; irow < fgkRow; irow++)
01709453 404 {
5e6a9312 405 for(Int_t icol = 0; icol < fgkCol; icol++)
01709453 406 {
ed228cbc 407 fCellADC[irow][icol] = 0.;
01709453 408 }
409 }
410}
1758e4fe 411// ------------------------------------------------------------------------- //
01709453 412
413void AliPMDClusterFinder::ResetRecpoint()
414{
b208c6a3 415 // Clear the list of reconstructed points
01709453 416 fNpoint = 0;
417 if (fRecpoints) fRecpoints->Clear();
418}
1758e4fe 419// ------------------------------------------------------------------------- //
55601d47 420void AliPMDClusterFinder::Load()
421{
ebd83c56 422 // Load all the *.root files
55601d47 423 //
424 fPMDLoader->LoadDigits("READ");
425 fPMDLoader->LoadRecPoints("recreate");
426}
427// ------------------------------------------------------------------------- //
01b56f5c 428void AliPMDClusterFinder::LoadClusters()
429{
430 // Load all the *.root files
431 //
432 fPMDLoader->LoadRecPoints("recreate");
433}
434// ------------------------------------------------------------------------- //
ebd83c56 435void AliPMDClusterFinder::UnLoad()
01709453 436{
b208c6a3 437 // Unload all the *.root files
438 //
ebd83c56 439 fPMDLoader->UnloadDigits();
440 fPMDLoader->UnloadRecPoints();
01709453 441}
1758e4fe 442// ------------------------------------------------------------------------- //
01b56f5c 443void AliPMDClusterFinder::UnLoadClusters()
444{
445 // Unload all the *.root files
446 //
447 fPMDLoader->UnloadRecPoints();
448}
449// ------------------------------------------------------------------------- //