read 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;
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;
5f55af10 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
253 if(smn < 6)
254 {
255 irownew1 = 95 - row;
256 icolnew1 = col;
257 }
258 else if(smn >= 6 && smn < 12)
259 {
260 irownew1 = row;
261 icolnew1 = 47 - col;
262 }
263 else if(smn >= 12 && smn < 18)
264 {
265 irownew1 = 47 - row;
266 icolnew1 = col;
267 }
268 else if(smn >= 18 && smn < 24)
269 {
270 irownew1 = row;
271 icolnew1 = 95 - col;
272 }
273
274 if(smn < 12)
275 {
276 // SupeModule 1 and 2 : Rows are inverted to columns and vice versa
277 // and at the time of calculating the eta,phi it is again reverted
278 // back
279 irownew = icolnew1;
280 icolnew = irownew1;
281 }
282 else if( smn >= 12 && smn < 24)
283 {
284 irownew = irownew1;
285 icolnew = icolnew1;
286 }
287
288 if (det == 0)
289 {
290 preADC[smn][irownew][icolnew] = sig;
291 }
292 else if (det == 1)
293 {
294 cpvADC[smn][irownew][icolnew] = sig;
295 }
296
297 } // while loop
298
299 for (Int_t idet = 0; idet < kDet; idet++)
300 {
301 for (Int_t ismn = 0; ismn < kSMN; ismn++)
302 {
303 for (Int_t irow = 0; irow < kRow; irow++)
304 {
305 for (Int_t icol = 0; icol < kCol; icol++)
306 {
307 if (idet == 0)
308 {
309 fCellADC[irow][icol] =
310 (Double_t) preADC[ismn][irow][icol];
311 }
312 else if (idet == 1)
313 {
314 fCellADC[irow][icol] =
315 (Double_t) cpvADC[ismn][irow][icol];
316 }
317 } // row
318 } // col
319 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
320 Int_t nentries1 = pmdcont->GetEntries();
321 // cout << " nentries1 = " << nentries1 << endl;
322 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
323 {
324 AliPMDcluster *pmdcl =
325 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
326 idet = pmdcl->GetDetector();
327 ismn = pmdcl->GetSMN();
328 clusdata[0] = pmdcl->GetClusX();
329 clusdata[1] = pmdcl->GetClusY();
330 clusdata[2] = pmdcl->GetClusADC();
331 clusdata[3] = pmdcl->GetClusCells();
332 clusdata[4] = pmdcl->GetClusRadius();
333
334 AddRecPoint(idet,ismn,clusdata);
335 }
336 pmdcont->Clear();
337
338 fTreeR->Fill();
339 ResetRecpoint();
340
341 } // smn
342 } // det (pre, cpv)
343
344 ResetCellADC();
345 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
346 fPMDLoader->WriteRecPoints("OVERWRITE");
347
348 // delete the pointers
349 delete pmdclust;
350 delete pmdcont;
351
352 // cout << " ***** End::Digits2RecPoints :: Raw *****" << endl;
353}
354// ------------------------------------------------------------------------- //
ed228cbc 355void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
356{
357 fEcut = ecut;
358}
1758e4fe 359// ------------------------------------------------------------------------- //
ed228cbc 360void AliPMDClusterFinder::SetDebug(Int_t idebug)
361{
362 fDebug = idebug;
363}
1758e4fe 364// ------------------------------------------------------------------------- //
365void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
01709453 366{
b208c6a3 367 // Add Reconstructed points
368 //
01709453 369 TClonesArray &lrecpoints = *fRecpoints;
ed228cbc 370 AliPMDrecpoint1 *newrecpoint;
1758e4fe 371 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
ed228cbc 372 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
01709453 373 delete newrecpoint;
374}
1758e4fe 375// ------------------------------------------------------------------------- //
01709453 376void AliPMDClusterFinder::ResetCellADC()
377{
b208c6a3 378 // Reset the individual cell ADC value to zero
379 //
5e6a9312 380 for(Int_t irow = 0; irow < fgkRow; irow++)
01709453 381 {
5e6a9312 382 for(Int_t icol = 0; icol < fgkCol; icol++)
01709453 383 {
ed228cbc 384 fCellADC[irow][icol] = 0.;
01709453 385 }
386 }
387}
1758e4fe 388// ------------------------------------------------------------------------- //
01709453 389
390void AliPMDClusterFinder::ResetRecpoint()
391{
b208c6a3 392 // Clear the list of reconstructed points
01709453 393 fNpoint = 0;
394 if (fRecpoints) fRecpoints->Clear();
395}
1758e4fe 396// ------------------------------------------------------------------------- //
55601d47 397void AliPMDClusterFinder::Load()
398{
ebd83c56 399 // Load all the *.root files
55601d47 400 //
401 fPMDLoader->LoadDigits("READ");
402 fPMDLoader->LoadRecPoints("recreate");
403}
404// ------------------------------------------------------------------------- //
ebd83c56 405void AliPMDClusterFinder::UnLoad()
01709453 406{
b208c6a3 407 // Unload all the *.root files
408 //
ebd83c56 409 fPMDLoader->UnloadDigits();
410 fPMDLoader->UnloadRecPoints();
01709453 411}
1758e4fe 412// ------------------------------------------------------------------------- //