comments removed
[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;
b208c6a3 107 fTreeD = fPMDLoader->TreeD();
108 if (fTreeD == 0x0)
01709453 109 {
110 cout << " Can not get TreeD" << endl;
111 }
112 AliPMDdigit *pmddigit;
b208c6a3 113 TBranch *branch = fTreeD->GetBranch("PMDDigit");
01709453 114 branch->SetAddress(&fDigits);
115
116 ResetRecpoint();
b208c6a3 117 fTreeR = fPMDLoader->TreeR();
118 if (fTreeR == 0x0)
01709453 119 {
b208c6a3 120 fPMDLoader->MakeTree("R");
121 fTreeR = fPMDLoader->TreeR();
01709453 122 }
123
124 Int_t bufsize = 16000;
b208c6a3 125 fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
01709453 126
b208c6a3 127 Int_t nmodules = (Int_t) fTreeD->GetEntries();
01709453 128
129 for (Int_t imodule = 0; imodule < nmodules; imodule++)
130 {
ed228cbc 131 ResetCellADC();
b208c6a3 132 fTreeD->GetEntry(imodule);
01709453 133 Int_t nentries = fDigits->GetLast();
134 for (Int_t ient = 0; ient < nentries+1; ient++)
135 {
136 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
137
138 det = pmddigit->GetDetector();
139 smn = pmddigit->GetSMNumber();
5e6a9312 140 xpos = pmddigit->GetRow();
141 ypos = pmddigit->GetColumn();
01709453 142 adc = pmddigit->GetADC();
ed228cbc 143 //Int_t trno = pmddigit->GetTrackNumber();
ed228cbc 144 fCellADC[xpos][ypos] = (Double_t) adc;
01709453 145 }
01709453 146
ed228cbc 147 idet = det;
1758e4fe 148 ismn = smn;
8616b098 149 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
ed228cbc 150
151 Int_t nentries1 = pmdcont->GetEntries();
dfaeee5f 152// cout << " nentries1 = " << nentries1 << endl;
ed228cbc 153 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
01709453 154 {
ebd83c56 155 AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
1758e4fe 156 idet = pmdcl->GetDetector();
157 ismn = pmdcl->GetSMN();
158 clusdata[0] = pmdcl->GetClusX();
159 clusdata[1] = pmdcl->GetClusY();
160 clusdata[2] = pmdcl->GetClusADC();
161 clusdata[3] = pmdcl->GetClusCells();
162 clusdata[4] = pmdcl->GetClusRadius();
01709453 163
1758e4fe 164 AddRecPoint(idet,ismn,clusdata);
ed228cbc 165 }
166 pmdcont->Clear();
167
b208c6a3 168 fTreeR->Fill();
ed228cbc 169 ResetRecpoint();
170
171 } // modules
172
01709453 173 ResetCellADC();
e1287360 174 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
b208c6a3 175 fPMDLoader->WriteRecPoints("OVERWRITE");
01709453 176
177 // delete the pointers
178 delete pmdclust;
179 delete pmdcont;
180
181 // cout << " ***** End::Digits2RecPoints *****" << endl;
182}
1758e4fe 183// ------------------------------------------------------------------------- //
5f55af10 184
185void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
186{
187 // Converts digits to recpoints after running clustering
188 // algorithm on CPV plane and PREshower plane
189 //
190
191 Float_t clusdata[5];
192
193
194 rawReader->Reset();
195 AliPMDRawStream pmdinput(rawReader);
196
197 TObjArray *pmdcont = new TObjArray();
198 AliPMDClustering *pmdclust = new AliPMDClustering();
199 pmdclust->SetDebug(fDebug);
200 pmdclust->SetEdepCut(fEcut);
201
202 fRunLoader->GetEvent(ievt);
203
204 ResetRecpoint();
205 fTreeR = fPMDLoader->TreeR();
206 if (fTreeR == 0x0)
207 {
208 fPMDLoader->MakeTree("R");
209 fTreeR = fPMDLoader->TreeR();
210 }
211
212 Int_t bufsize = 16000;
213 fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
214
215 Int_t irownew = 0;
216 Int_t icolnew = 0;
217 Int_t irownew1 = 0;
218 Int_t icolnew1 = 0;
219 const Int_t kDet = 2;
220 const Int_t kSMN = 24;
221 const Int_t kRow = 48;
222 const Int_t kCol = 96;
223 Int_t preADC[kSMN][kRow][kCol];
224 Int_t cpvADC[kSMN][kRow][kCol];
225
226 for (Int_t i = 0; i < kSMN; i++)
227 {
228 for (Int_t j = 0; j < kRow; j++)
229 {
230 for (Int_t k = 0; k < kCol; k++)
231 {
232 preADC[i][j][k] = 0;
233 cpvADC[i][j][k] = 0;
234 }
235 }
236 }
237 ResetCellADC();
238
239 while(pmdinput.Next())
240 {
241 Int_t det = pmdinput.GetDetector();
242 Int_t smn = pmdinput.GetSMN();
243 //Int_t mcm = pmdinput.GetMCM();
244 //Int_t chno = pmdinput.GetChannel();
245 Int_t row = pmdinput.GetRow();
246 Int_t col = pmdinput.GetColumn();
247 Int_t sig = pmdinput.GetSignal();
248
249 //cout << " det = " << det << " smn = " << smn
250 // << " row = " << row << " col = " << col
251 // << " sig = " << sig << endl;
252
dfc7b483 253 // Transform all the (0,0) coordinates to the geant frame
5f55af10 254 if(smn < 6)
255 {
256 irownew1 = 95 - row;
257 icolnew1 = col;
258 }
259 else if(smn >= 6 && smn < 12)
260 {
261 irownew1 = row;
262 icolnew1 = 47 - col;
263 }
264 else if(smn >= 12 && smn < 18)
265 {
266 irownew1 = 47 - row;
267 icolnew1 = col;
268 }
269 else if(smn >= 18 && smn < 24)
270 {
271 irownew1 = row;
272 icolnew1 = 95 - col;
273 }
274
dfc7b483 275 // for smn < 12 : row = 96, column = 48
276 // for smn>= 12 and < 24 : row = 48, column = 96
277 // In order to make it uniform dimension, smn < 12 are inverted
278 // i.i., row becomes column and column becomes row
279 // for others it remains same
280 // This is further inverted back while calculating eta and phi
5f55af10 281 if(smn < 12)
282 {
283 // SupeModule 1 and 2 : Rows are inverted to columns and vice versa
284 // and at the time of calculating the eta,phi it is again reverted
285 // back
286 irownew = icolnew1;
287 icolnew = irownew1;
288 }
289 else if( smn >= 12 && smn < 24)
290 {
291 irownew = irownew1;
292 icolnew = icolnew1;
293 }
294
295 if (det == 0)
296 {
297 preADC[smn][irownew][icolnew] = sig;
298 }
299 else if (det == 1)
300 {
301 cpvADC[smn][irownew][icolnew] = sig;
302 }
303
304 } // while loop
305
306 for (Int_t idet = 0; idet < kDet; idet++)
307 {
308 for (Int_t ismn = 0; ismn < kSMN; ismn++)
309 {
310 for (Int_t irow = 0; irow < kRow; irow++)
311 {
312 for (Int_t icol = 0; icol < kCol; icol++)
313 {
314 if (idet == 0)
315 {
316 fCellADC[irow][icol] =
317 (Double_t) preADC[ismn][irow][icol];
318 }
319 else if (idet == 1)
320 {
321 fCellADC[irow][icol] =
322 (Double_t) cpvADC[ismn][irow][icol];
323 }
324 } // row
325 } // col
326 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
327 Int_t nentries1 = pmdcont->GetEntries();
328 // cout << " nentries1 = " << nentries1 << endl;
329 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
330 {
331 AliPMDcluster *pmdcl =
332 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
333 idet = pmdcl->GetDetector();
334 ismn = pmdcl->GetSMN();
335 clusdata[0] = pmdcl->GetClusX();
336 clusdata[1] = pmdcl->GetClusY();
337 clusdata[2] = pmdcl->GetClusADC();
338 clusdata[3] = pmdcl->GetClusCells();
339 clusdata[4] = pmdcl->GetClusRadius();
340
341 AddRecPoint(idet,ismn,clusdata);
342 }
343 pmdcont->Clear();
344
345 fTreeR->Fill();
346 ResetRecpoint();
347
348 } // smn
349 } // det (pre, cpv)
350
351 ResetCellADC();
352 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
353 fPMDLoader->WriteRecPoints("OVERWRITE");
354
355 // delete the pointers
356 delete pmdclust;
357 delete pmdcont;
358
359 // cout << " ***** End::Digits2RecPoints :: Raw *****" << endl;
360}
361// ------------------------------------------------------------------------- //
ed228cbc 362void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
363{
364 fEcut = ecut;
365}
1758e4fe 366// ------------------------------------------------------------------------- //
ed228cbc 367void AliPMDClusterFinder::SetDebug(Int_t idebug)
368{
369 fDebug = idebug;
370}
1758e4fe 371// ------------------------------------------------------------------------- //
372void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
01709453 373{
b208c6a3 374 // Add Reconstructed points
375 //
01709453 376 TClonesArray &lrecpoints = *fRecpoints;
ed228cbc 377 AliPMDrecpoint1 *newrecpoint;
1758e4fe 378 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
ed228cbc 379 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
01709453 380 delete newrecpoint;
381}
1758e4fe 382// ------------------------------------------------------------------------- //
01709453 383void AliPMDClusterFinder::ResetCellADC()
384{
b208c6a3 385 // Reset the individual cell ADC value to zero
386 //
5e6a9312 387 for(Int_t irow = 0; irow < fgkRow; irow++)
01709453 388 {
5e6a9312 389 for(Int_t icol = 0; icol < fgkCol; icol++)
01709453 390 {
ed228cbc 391 fCellADC[irow][icol] = 0.;
01709453 392 }
393 }
394}
1758e4fe 395// ------------------------------------------------------------------------- //
01709453 396
397void AliPMDClusterFinder::ResetRecpoint()
398{
b208c6a3 399 // Clear the list of reconstructed points
01709453 400 fNpoint = 0;
401 if (fRecpoints) fRecpoints->Clear();
402}
1758e4fe 403// ------------------------------------------------------------------------- //
55601d47 404void AliPMDClusterFinder::Load()
405{
ebd83c56 406 // Load all the *.root files
55601d47 407 //
408 fPMDLoader->LoadDigits("READ");
409 fPMDLoader->LoadRecPoints("recreate");
410}
411// ------------------------------------------------------------------------- //
ebd83c56 412void AliPMDClusterFinder::UnLoad()
01709453 413{
b208c6a3 414 // Unload all the *.root files
415 //
ebd83c56 416 fPMDLoader->UnloadDigits();
417 fPMDLoader->UnloadRecPoints();
01709453 418}
1758e4fe 419// ------------------------------------------------------------------------- //