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