]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDClusterFinder.cxx
unused stuff deleted
[u/mrichter/AliRoot.git] / PMD / AliPMDClusterFinder.cxx
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
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>
26 #include <TTree.h>
27 #include <TObjArray.h>
28 #include <TClonesArray.h>
29
30 #include "AliLog.h"
31 #include "AliRunLoader.h"
32 #include "AliLoader.h"
33 #include "AliRawReader.h"
34
35 #include "AliPMDdigit.h"
36 #include "AliPMDClusterFinder.h"
37 #include "AliPMDClustering.h"
38 #include "AliPMDClusteringV1.h"
39 #include "AliPMDcluster.h"
40 #include "AliPMDrecpoint1.h"
41 #include "AliPMDrechit.h"
42 #include "AliPMDRawStream.h"
43 #include "AliPMDCalibData.h"
44 #include "AliPMDPedestal.h"
45 #include "AliPMDddldata.h"
46
47 #include "AliDAQ.h"
48 #include "AliCDBManager.h"
49 #include "AliCDBEntry.h"
50
51
52
53 ClassImp(AliPMDClusterFinder)
54
55 AliPMDClusterFinder::AliPMDClusterFinder():
56   fRunLoader(0),
57   fPMDLoader(0),
58   fCalibGain(GetCalibGain()),
59   fCalibPed(GetCalibPed()),
60   fTreeD(0),
61   fTreeR(0),
62   fDigits(new TClonesArray("AliPMDdigit", 1000)),
63   fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
64   fRechits(new TClonesArray("AliPMDrechit", 1000)),
65   fNpoint(0),
66   fNhit(0),
67   fDetNo(0),
68   fEcut(0.)
69 {
70 //
71 // Constructor
72 //
73 }
74 // ------------------------------------------------------------------------- //
75 AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
76   fRunLoader(runLoader),
77   fPMDLoader(runLoader->GetLoader("PMDLoader")),
78   fCalibGain(GetCalibGain()),
79   fCalibPed(GetCalibPed()),
80   fTreeD(0),
81   fTreeR(0),
82   fDigits(new TClonesArray("AliPMDdigit", 1000)),
83   fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
84   fRechits(new TClonesArray("AliPMDrechit", 1000)),
85   fNpoint(0),
86   fNhit(0),
87   fDetNo(0),
88   fEcut(0.)
89 {
90 //
91 // Constructor
92 //
93 }
94 // ------------------------------------------------------------------------- //
95 AliPMDClusterFinder::AliPMDClusterFinder(const AliPMDClusterFinder & finder):
96   TObject(finder),
97   fRunLoader(0),
98   fPMDLoader(0),
99   fCalibGain(GetCalibGain()),
100   fCalibPed(GetCalibPed()),
101   fTreeD(0),
102   fTreeR(0),
103   fDigits(NULL),
104   fRecpoints(NULL),
105   fRechits(NULL),
106   fNpoint(0),
107   fNhit(0),
108   fDetNo(0),
109   fEcut(0.)
110 {
111   // copy constructor
112   AliError("Copy constructor not allowed");
113 }
114 // ------------------------------------------------------------------------- //
115 AliPMDClusterFinder &AliPMDClusterFinder::operator=(const AliPMDClusterFinder & /*finder*/)
116 {
117  // assignment op
118   AliError("Assignment Operator not allowed");
119   return *this;
120 }
121 // ------------------------------------------------------------------------- //
122 AliPMDClusterFinder::~AliPMDClusterFinder()
123 {
124   // Destructor
125   if (fDigits)
126     {
127         fDigits->Clear();
128     }
129   if (fRecpoints)
130     {
131       fRecpoints->Clear();
132     }
133   if (fRechits)
134     {
135       fRechits->Clear();
136     }
137 }
138 // ------------------------------------------------------------------------- //
139
140 void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
141 {
142   // Converts digits to recpoints after running clustering
143   // algorithm on CPV plane and PREshower plane
144   //
145
146   Int_t    det = 0,smn = 0;
147   Int_t    xpos,ypos;
148   Float_t  adc;
149   Int_t    ismn;
150   Int_t    idet;
151   Float_t  clusdata[6];
152
153   TObjArray *pmdcont = new TObjArray();
154   AliPMDClustering *pmdclust = new AliPMDClusteringV1();
155
156   pmdclust->SetEdepCut(fEcut);
157
158   fRunLoader->GetEvent(ievt);
159
160
161   fTreeD = fPMDLoader->TreeD();
162   if (fTreeD == 0x0)
163     {
164       AliFatal("AliPMDClusterFinder: Can not get TreeD");
165
166     }
167   AliPMDdigit  *pmddigit;
168   TBranch *branch = fTreeD->GetBranch("PMDDigit");
169   branch->SetAddress(&fDigits);
170
171   ResetRecpoint();
172
173   fTreeR = fPMDLoader->TreeR();
174   if (fTreeR == 0x0)
175     {
176       fPMDLoader->MakeTree("R");
177       fTreeR = fPMDLoader->TreeR();
178     }
179
180   Int_t bufsize = 16000;
181   TBranch * branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize); 
182   TBranch * branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize); 
183
184   Int_t nmodules = (Int_t) fTreeD->GetEntries();
185
186   for (Int_t imodule = 0; imodule < nmodules; imodule++)
187     {
188       ResetCellADC();
189       fTreeD->GetEntry(imodule); 
190       Int_t nentries = fDigits->GetLast();
191       for (Int_t ient = 0; ient < nentries+1; ient++)
192         {
193           pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
194           
195           det    = pmddigit->GetDetector();
196           smn    = pmddigit->GetSMNumber();
197           xpos   = pmddigit->GetRow();
198           ypos   = pmddigit->GetColumn();
199           adc    = pmddigit->GetADC();
200           
201           // CALIBRATION
202           Float_t gain = fCalibGain->GetGainFact(det,smn,xpos,ypos);
203           // printf("adc = %d gain = %f\n",adc,gain);
204           
205           adc = adc*gain;
206
207           //Int_t trno   = pmddigit->GetTrackNumber();
208           fCellADC[xpos][ypos] = (Double_t) adc;
209         }
210
211       idet = det;
212       ismn = smn;
213       pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
214       
215       Int_t nentries1 = pmdcont->GetEntries();
216
217       AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
218
219       for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
220         {
221           AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
222           idet        = pmdcl->GetDetector();
223           ismn        = pmdcl->GetSMN();
224           clusdata[0] = pmdcl->GetClusX();
225           clusdata[1] = pmdcl->GetClusY();
226           clusdata[2] = pmdcl->GetClusADC();
227           clusdata[3] = pmdcl->GetClusCells();
228           clusdata[4] = pmdcl->GetClusSigmaX();
229           clusdata[5] = pmdcl->GetClusSigmaY();
230
231           AddRecPoint(idet,ismn,clusdata);
232
233           Int_t ncell = (Int_t) clusdata[3];
234           for(Int_t ihit = 0; ihit < ncell; ihit++)
235             {
236               Int_t celldataX = pmdcl->GetClusCellX(ihit);
237               Int_t celldataY = pmdcl->GetClusCellY(ihit);
238               AddRecHit(celldataX, celldataY);
239             }
240           branch2->Fill();
241           ResetRechit();
242         }
243       pmdcont->Delete();
244       
245       branch1->Fill();
246       ResetRecpoint();
247
248     } // modules
249
250   ResetCellADC();
251   fPMDLoader = fRunLoader->GetLoader("PMDLoader");  
252   fPMDLoader->WriteRecPoints("OVERWRITE");
253
254   //   delete the pointers
255   delete pmdclust;
256   delete pmdcont;
257     
258 }
259 // ------------------------------------------------------------------------- //
260
261 void AliPMDClusterFinder::Digits2RecPoints(TTree *digitsTree,
262                                            TTree *clustersTree)
263 {
264   // Converts digits to recpoints after running clustering
265   // algorithm on CPV plane and PREshower plane
266   //
267
268   Int_t    det = 0,smn = 0;
269   Int_t    xpos,ypos;
270   Float_t  adc;
271   Int_t    ismn;
272   Int_t    idet;
273   Float_t  clusdata[6];
274
275   TObjArray *pmdcont = new TObjArray();
276   AliPMDClustering *pmdclust = new AliPMDClusteringV1();
277
278   pmdclust->SetEdepCut(fEcut);
279
280   AliPMDdigit  *pmddigit;
281   TBranch *branch = digitsTree->GetBranch("PMDDigit");
282   branch->SetAddress(&fDigits);
283
284   ResetRecpoint();
285
286   Int_t bufsize = 16000;
287   TBranch * branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize); 
288   TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize); 
289
290   Int_t nmodules = (Int_t) digitsTree->GetEntries();
291
292   for (Int_t imodule = 0; imodule < nmodules; imodule++)
293     {
294       ResetCellADC();
295       digitsTree->GetEntry(imodule); 
296       Int_t nentries = fDigits->GetLast();
297       for (Int_t ient = 0; ient < nentries+1; ient++)
298         {
299           pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
300           
301           det    = pmddigit->GetDetector();
302           smn    = pmddigit->GetSMNumber();
303           xpos   = pmddigit->GetRow();
304           ypos   = pmddigit->GetColumn();
305           adc    = pmddigit->GetADC();
306
307           // Pedestal Subtraction
308           Int_t   pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,xpos,ypos);
309           Int_t   pedrms1    = (Int_t) pedmeanrms%1000;
310           Float_t pedrms     = (Float_t)pedrms1/10.;
311           Float_t pedmean    = (Float_t) (pedmeanrms - pedrms1)/1000.0;
312           //printf("%f %f\n",pedmean, pedrms);
313
314           Float_t adc1 = adc - (pedmean + 3.0*pedrms);
315
316           // CALIBRATION
317           Float_t gain = fCalibGain->GetGainFact(det,smn,xpos,ypos);
318           // printf("adc = %d gain = %f\n",adc,gain);
319
320           adc = adc1*gain;
321
322           //Int_t trno   = pmddigit->GetTrackNumber();
323           fCellADC[xpos][ypos] = (Double_t) adc;
324         }
325
326       idet = det;
327       ismn = smn;
328       pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
329       
330       Int_t nentries1 = pmdcont->GetEntries();
331
332       AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
333
334       for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
335         {
336           AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
337           idet        = pmdcl->GetDetector();
338           ismn        = pmdcl->GetSMN();
339           clusdata[0] = pmdcl->GetClusX();
340           clusdata[1] = pmdcl->GetClusY();
341           clusdata[2] = pmdcl->GetClusADC();
342           clusdata[3] = pmdcl->GetClusCells();
343           clusdata[4] = pmdcl->GetClusSigmaX();
344           clusdata[5] = pmdcl->GetClusSigmaY();
345
346           AddRecPoint(idet,ismn,clusdata);
347
348           Int_t ncell = (Int_t) clusdata[3];
349           for(Int_t ihit = 0; ihit < ncell; ihit++)
350             {
351               Int_t celldataX = pmdcl->GetClusCellX(ihit);
352               Int_t celldataY = pmdcl->GetClusCellY(ihit);
353               AddRecHit(celldataX, celldataY);
354             }
355           branch2->Fill();
356           ResetRechit();
357         }
358       pmdcont->Delete();
359       
360       branch1->Fill();
361       ResetRecpoint();
362
363     } // modules
364
365   ResetCellADC();
366
367   //   delete the pointers
368   delete pmdclust;
369   delete pmdcont;
370     
371 }
372 // ------------------------------------------------------------------------- //
373
374 void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
375                                            TTree *clustersTree)
376 {
377   // Converts RAW data to recpoints after running clustering
378   // algorithm on CPV and PREshower plane
379   //
380   // This method is called at the time of reconstruction
381
382
383   Float_t  clusdata[6];
384   TObjArray pmdddlcont;
385
386   TObjArray *pmdcont = new TObjArray();
387   AliPMDClustering *pmdclust = new AliPMDClusteringV1();
388
389   pmdclust->SetEdepCut(fEcut);
390
391   ResetRecpoint();
392
393   Int_t bufsize = 16000;
394   TBranch *branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize); 
395
396   TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize); 
397
398   const Int_t kRow = 48;
399   const Int_t kCol = 96;
400
401   Int_t idet = 0;
402   Int_t iSMN = 0;
403
404   Int_t indexDDL = -1;
405   AliPMDRawStream pmdinput(rawReader);
406
407   while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
408   {
409       if (indexDDL < 4)
410         {
411           iSMN = 6;
412         }
413       else if (indexDDL >= 4)
414         {
415           iSMN = 12;
416         }
417       Int_t ***precpvADC;
418       precpvADC = new int **[iSMN];
419       for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
420       for (Int_t i=0; i<iSMN;i++)
421         {
422           for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
423         }
424       for (Int_t i = 0; i < iSMN; i++)
425         {
426           for (Int_t j = 0; j < kRow; j++)
427             {
428               for (Int_t k = 0; k < kCol; k++)
429                 {
430                   precpvADC[i][j][k] = 0;
431                 }
432             }
433         }
434       ResetCellADC();
435
436       Int_t indexsmn = 0;
437       Int_t ientries = pmdddlcont.GetEntries();
438       for (Int_t ient = 0; ient < ientries; ient++)
439         {
440           AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
441           
442           Int_t det = pmdddl->GetDetector();
443           Int_t smn = pmdddl->GetSMN();
444           //Int_t mcm = pmdddl->GetMCM();
445           //Int_t chno = pmdddl->GetChannel();
446           Int_t row = pmdddl->GetRow();
447           Int_t col = pmdddl->GetColumn();
448           Int_t sig = pmdddl->GetSignal();
449
450           // Pedestal Subtraction
451           Int_t   pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,row,col);
452           Int_t   pedrms1    = (Int_t) pedmeanrms%1000;
453           Float_t pedrms     = (Float_t)pedrms1/10.;
454           Float_t pedmean    = (Float_t) (pedmeanrms - pedrms1)/1000.0;
455
456           //printf("%f %f\n",pedmean, pedrms);
457
458           // Float_t sig1 = (Float_t) sig;
459           Float_t sig1 = (Float_t) sig - (pedmean + 3.0*pedrms);
460
461           // CALIBRATION
462           Float_t gain = fCalibGain->GetGainFact(det,smn,row,col);
463           //printf("sig = %d gain = %f\n",sig,gain);
464           sig = (Int_t) (sig1*gain);
465
466           if (indexDDL < 4)
467             {
468               if (det != 0)
469                 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
470                               indexDDL, det));
471               indexsmn = smn - indexDDL * 6;
472             }
473           else if (indexDDL == 4)
474             {
475               if (det != 1)
476                 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
477                               indexDDL, det));
478               if (smn < 6)
479                 {
480                   indexsmn = smn;
481                 }
482               else if (smn >= 18 && smn < 24)
483                 {
484                   indexsmn = smn - 12;
485                 }
486             }
487           else if (indexDDL == 5)
488             {
489               if (det != 1)
490                 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
491                               indexDDL, det));
492               if (smn >= 6 && smn < 12)
493                 {
494                   indexsmn = smn - 6;
495                 }
496               else if (smn >= 12 && smn < 18)
497                 {
498                   indexsmn = smn - 6;
499                 }
500             }         
501           precpvADC[indexsmn][row][col] = sig;
502         }
503       
504       //pmdddlcont.Clear();
505       pmdddlcont.Delete();
506
507       Int_t ismn = 0;
508       for (indexsmn = 0; indexsmn < iSMN; indexsmn++)
509         {
510           ResetCellADC();
511           for (Int_t irow = 0; irow < kRow; irow++)
512             {
513               for (Int_t icol = 0; icol < kCol; icol++)
514                 {
515                   fCellADC[irow][icol] = 
516                     (Double_t) precpvADC[indexsmn][irow][icol];
517                 } // row
518             }     // col
519           
520           if (indexDDL < 4)
521             {
522               ismn = indexsmn + indexDDL * 6;
523               idet = 0;
524             }
525           else if (indexDDL == 4)
526             {
527               if (indexsmn < 6)
528                 {
529                   ismn = indexsmn;
530                 }
531               else if (indexsmn >= 6 && indexsmn < 12)
532                 {
533                   ismn = indexsmn + 12;
534                 }
535               idet = 1;
536             }
537           else if (indexDDL == 5)
538             {
539               if (indexsmn < 6)
540                 {
541                   ismn = indexsmn + 6;
542                 }
543               else if (indexsmn >= 6 && indexsmn < 12)
544                 {
545                   ismn = indexsmn + 6;
546                 }
547               idet = 1;
548             }
549
550           pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
551           Int_t nentries1 = pmdcont->GetEntries();
552
553           AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
554
555           for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
556             {
557               AliPMDcluster *pmdcl = 
558                 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
559               idet        = pmdcl->GetDetector();
560               ismn        = pmdcl->GetSMN();
561               clusdata[0] = pmdcl->GetClusX();
562               clusdata[1] = pmdcl->GetClusY();
563               clusdata[2] = pmdcl->GetClusADC();
564               clusdata[3] = pmdcl->GetClusCells();
565               clusdata[4] = pmdcl->GetClusSigmaX();
566               clusdata[5] = pmdcl->GetClusSigmaY();
567
568               AddRecPoint(idet,ismn,clusdata);
569
570               Int_t ncell = (Int_t) clusdata[3];
571               for(Int_t ihit = 0; ihit < ncell; ihit++)
572                 {
573                   Int_t celldataX = pmdcl->GetClusCellX(ihit);
574                   Int_t celldataY = pmdcl->GetClusCellY(ihit);
575                   AddRecHit(celldataX, celldataY);
576                 }
577               branch2->Fill();
578               ResetRechit();
579
580             }
581           pmdcont->Delete();
582           
583           branch1->Fill();
584           ResetRecpoint();
585
586
587         } // smn
588
589       for (Int_t i=0; i<iSMN; i++)
590         {
591           for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
592         }
593       for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
594       delete precpvADC;
595
596     } // DDL Loop
597   
598   ResetCellADC();
599   
600   //   delete the pointers
601   delete pmdclust;
602   delete pmdcont;
603
604 }
605 // ------------------------------------------------------------------------- //
606
607 void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
608 {
609   // Converts RAW data to recpoints after running clustering
610   // algorithm on CPV and PREshower plane
611   //
612
613   Float_t  clusdata[6];
614   TObjArray pmdddlcont;
615   TObjArray *pmdcont = new TObjArray();
616
617   AliPMDClustering *pmdclust = new AliPMDClusteringV1();
618
619   pmdclust->SetEdepCut(fEcut);
620
621   fRunLoader->GetEvent(ievt);
622
623   ResetRecpoint();
624
625   fTreeR = fPMDLoader->TreeR();
626   if (fTreeR == 0x0)
627     {
628       fPMDLoader->MakeTree("R");
629       fTreeR = fPMDLoader->TreeR();
630     }
631   Int_t bufsize = 16000;
632   TBranch *branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize); 
633   TBranch *branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize); 
634
635   const Int_t kRow = 48;
636   const Int_t kCol = 96;
637
638   Int_t idet = 0;
639   Int_t iSMN = 0;
640
641   AliPMDRawStream pmdinput(rawReader);
642   Int_t indexDDL = -1;
643
644   while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0) {
645
646       if (indexDDL < 4)
647         {
648           iSMN = 6;
649         }
650       else if (indexDDL >= 4)
651         {
652           iSMN = 12;
653         }
654       Int_t ***precpvADC;
655       precpvADC = new int **[iSMN];
656       for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
657       for (Int_t i=0; i<iSMN;i++)
658         {
659           for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
660         }
661       for (Int_t i = 0; i < iSMN; i++)
662         {
663           for (Int_t j = 0; j < kRow; j++)
664             {
665               for (Int_t k = 0; k < kCol; k++)
666                 {
667                   precpvADC[i][j][k] = 0;
668                 }
669             }
670         }
671       ResetCellADC();
672
673     
674       Int_t indexsmn = 0;
675       Int_t ientries = pmdddlcont.GetEntries();
676       for (Int_t ient = 0; ient < ientries; ient++)
677         {
678           AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
679           
680           Int_t det = pmdddl->GetDetector();
681           Int_t smn = pmdddl->GetSMN();
682           //Int_t mcm = pmdddl->GetMCM();
683           //Int_t chno = pmdddl->GetChannel();
684           Int_t row = pmdddl->GetRow();
685           Int_t col = pmdddl->GetColumn();
686           Int_t sig = pmdddl->GetSignal();
687
688           // Pedestal Subtraction
689           Int_t   pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,row,col);
690           Int_t   pedrms1    = (Int_t) pedmeanrms%1000;
691           Float_t pedrms     = (Float_t)pedrms1/10.;
692           Float_t pedmean    = (Float_t) (pedmeanrms - pedrms1)/1000.0;
693
694           //printf("%f %f\n",pedmean, pedrms);
695
696           //Float_t sig1 = (Float_t) sig;
697           Float_t sig1 = (Float_t) sig - (pedmean + 3.0*pedrms);
698           // CALIBRATION
699           Float_t gain = fCalibGain->GetGainFact(det,smn,row,col);
700
701           //printf("sig = %d gain = %f\n",sig,gain);
702           sig = (Int_t) (sig1*gain);
703
704
705           if (indexDDL < 4)
706             {
707               if (det != 0)
708                 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
709                               indexDDL, det));
710               indexsmn = smn - indexDDL * 6;
711             }
712           else if (indexDDL == 4)
713             {
714               if (det != 1)
715                 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
716                               indexDDL, det));
717               if (smn < 6)
718                 {
719                   indexsmn = smn;
720                 }
721               else if (smn >= 18 && smn < 24)
722                 {
723                   indexsmn = smn - 12;
724                 }
725             }
726           else if (indexDDL == 5)
727             {
728               if (det != 1)
729                 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
730                               indexDDL, det));
731               if (smn >= 6 && smn < 12)
732                 {
733                   indexsmn = smn - 6;
734                 }
735               else if (smn >= 12 && smn < 18)
736                 {
737                   indexsmn = smn - 6;
738                 }
739             }         
740           precpvADC[indexsmn][row][col] = sig;
741
742         }
743       
744       pmdddlcont.Delete();
745
746       Int_t ismn = 0;
747       for (indexsmn = 0; indexsmn < iSMN; indexsmn++)
748         {
749           ResetCellADC();
750           for (Int_t irow = 0; irow < kRow; irow++)
751             {
752               for (Int_t icol = 0; icol < kCol; icol++)
753                 {
754                   fCellADC[irow][icol] = 
755                     (Double_t) precpvADC[indexsmn][irow][icol];
756                 } // row
757             }     // col
758
759           
760           if (indexDDL < 4)
761             {
762               ismn = indexsmn + indexDDL * 6;
763               idet = 0;
764             }
765           else if (indexDDL == 4)
766             {
767               if (indexsmn < 6)
768                 {
769                   ismn = indexsmn;
770                 }
771               else if (indexsmn >= 6 && indexsmn < 12)
772                 {
773                   ismn = indexsmn + 12;
774                 }
775               idet = 1;
776             }
777           else if (indexDDL == 5)
778             {
779               if (indexsmn < 6)
780                 {
781                   ismn = indexsmn + 6;
782                 }
783               else if (indexsmn >= 6 && indexsmn < 12)
784                 {
785                   ismn = indexsmn + 6;
786                 }
787               idet = 1;
788             }
789
790           pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
791           Int_t nentries1 = pmdcont->GetEntries();
792
793           AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
794
795           for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
796             {
797               AliPMDcluster *pmdcl = 
798                 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
799               idet        = pmdcl->GetDetector();
800               ismn        = pmdcl->GetSMN();
801               clusdata[0] = pmdcl->GetClusX();
802               clusdata[1] = pmdcl->GetClusY();
803               clusdata[2] = pmdcl->GetClusADC();
804               clusdata[3] = pmdcl->GetClusCells();
805               clusdata[4] = pmdcl->GetClusSigmaX();
806               clusdata[5] = pmdcl->GetClusSigmaY();
807
808               AddRecPoint(idet,ismn,clusdata);
809
810               Int_t ncell = (Int_t) clusdata[3];
811               for(Int_t ihit = 0; ihit < ncell; ihit++)
812                 {
813                   Int_t celldataX = pmdcl->GetClusCellX(ihit);
814                   Int_t celldataY = pmdcl->GetClusCellY(ihit);
815                   AddRecHit(celldataX, celldataY);
816                 }
817               branch2->Fill();
818               ResetRechit();
819
820             }
821           pmdcont->Delete();
822           
823           branch1->Fill();
824           ResetRecpoint();
825
826
827         } // smn
828
829       for (Int_t i=0; i<iSMN; i++)
830         {
831           for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
832         }
833       for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
834       delete precpvADC;
835     } // DDL Loop
836   
837   ResetCellADC();
838   
839   fPMDLoader = fRunLoader->GetLoader("PMDLoader");  
840   fPMDLoader->WriteRecPoints("OVERWRITE");
841
842   //   delete the pointers
843   delete pmdclust;
844   delete pmdcont;
845
846 }
847 // ------------------------------------------------------------------------- //
848 void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
849 {
850   fEcut = ecut;
851 }
852 // ------------------------------------------------------------------------- //
853 void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
854 {
855   // Add Reconstructed points
856   //
857   TClonesArray &lrecpoints = *fRecpoints;
858   AliPMDrecpoint1 *newrecpoint;
859   newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
860   new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
861   delete newrecpoint;
862 }
863 // ------------------------------------------------------------------------- //
864 void AliPMDClusterFinder::AddRecHit(Int_t celldataX,Int_t celldataY)
865 {
866   // Add associated cell hits to the Reconstructed points
867   //
868   TClonesArray &lrechits = *fRechits;
869   AliPMDrechit *newrechit;
870   newrechit = new AliPMDrechit(celldataX, celldataY);
871   new(lrechits[fNhit++]) AliPMDrechit(newrechit);
872   delete newrechit;
873 }
874 // ------------------------------------------------------------------------- //
875 void AliPMDClusterFinder::ResetCellADC()
876 {
877   // Reset the individual cell ADC value to zero
878   //
879   for(Int_t irow = 0; irow < fgkRow; irow++)
880     {
881       for(Int_t icol = 0; icol < fgkCol; icol++)
882         {
883           fCellADC[irow][icol] = 0.;
884         }
885     }
886 }
887 // ------------------------------------------------------------------------- //
888
889 void AliPMDClusterFinder::ResetRecpoint()
890 {
891   // Clear the list of reconstructed points
892   fNpoint = 0;
893   if (fRecpoints) fRecpoints->Clear();
894 }
895 // ------------------------------------------------------------------------- //
896 void AliPMDClusterFinder::ResetRechit()
897 {
898   // Clear the list of reconstructed points
899   fNhit = 0;
900   if (fRechits) fRechits->Clear();
901 }
902 // ------------------------------------------------------------------------- //
903 void AliPMDClusterFinder::Load()
904 {
905   // Load all the *.root files
906   //
907   fPMDLoader->LoadDigits("READ");
908   fPMDLoader->LoadRecPoints("recreate");
909 }
910 // ------------------------------------------------------------------------- //
911 void AliPMDClusterFinder::LoadClusters()
912 {
913   // Load all the *.root files
914   //
915   fPMDLoader->LoadRecPoints("recreate");
916 }
917 // ------------------------------------------------------------------------- //
918 void AliPMDClusterFinder::UnLoad()
919 {
920   // Unload all the *.root files
921   //
922   fPMDLoader->UnloadDigits();
923   fPMDLoader->UnloadRecPoints();
924 }
925 // ------------------------------------------------------------------------- //
926 void AliPMDClusterFinder::UnLoadClusters()
927 {
928   // Unload all the *.root files
929   //
930   fPMDLoader->UnloadRecPoints();
931 }
932 // ------------------------------------------------------------------------- //
933
934 AliPMDCalibData* AliPMDClusterFinder::GetCalibGain() const
935 {
936   // The run number will be centralized in AliCDBManager,
937   // you don't need to set it here!
938   // Added by ZA
939   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
940   
941   if(!entry)  AliFatal("Calibration object retrieval failed! ");
942   
943   AliPMDCalibData *calibdata=0;
944   if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
945   
946   if (!calibdata)  AliFatal("No calibration data from calibration database !");
947   
948   return calibdata;
949 }
950
951 // ------------------------------------------------------------------------- //
952
953 AliPMDPedestal* AliPMDClusterFinder::GetCalibPed() const
954 {
955   // The run number will be centralized in AliCDBManager,
956   // you don't need to set it here!
957   AliCDBEntry  *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
958   
959   if(!entry) AliFatal("Pedestal object retrieval failed!");
960     
961   AliPMDPedestal *pedestal = 0;
962   if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
963   
964   if (!pedestal)  AliFatal("No pedestal data from pedestal database !");
965   
966   return pedestal;
967 }