1 /***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-----------------------------------------------------//
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) //
23 //-----------------------------------------------------//
25 #include <Riostream.h>
27 #include <TObjArray.h>
28 #include <TClonesArray.h>
31 #include "AliRunLoader.h"
32 #include "AliLoader.h"
33 #include "AliRawReader.h"
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 "AliPMDddldata.h"
46 #include "AliCDBManager.h"
47 #include "AliCDBEntry.h"
51 ClassImp(AliPMDClusterFinder)
53 AliPMDClusterFinder::AliPMDClusterFinder():
56 fCalibData(GetCalibData()),
59 fDigits(new TClonesArray("AliPMDdigit", 1000)),
60 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
61 fRechits(new TClonesArray("AliPMDrechit", 1000)),
71 // ------------------------------------------------------------------------- //
72 AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
73 fRunLoader(runLoader),
74 fPMDLoader(runLoader->GetLoader("PMDLoader")),
75 fCalibData(GetCalibData()),
78 fDigits(new TClonesArray("AliPMDdigit", 1000)),
79 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
80 fRechits(new TClonesArray("AliPMDrechit", 1000)),
90 // ------------------------------------------------------------------------- //
91 AliPMDClusterFinder::AliPMDClusterFinder(const AliPMDClusterFinder & /*finder*/):
95 AliError("Copy constructor not allowed");
97 // ------------------------------------------------------------------------- //
98 AliPMDClusterFinder &AliPMDClusterFinder::operator=(const AliPMDClusterFinder & /*finder*/)
101 AliError("Assignment Operator not allowed");
104 // ------------------------------------------------------------------------- //
105 AliPMDClusterFinder::~AliPMDClusterFinder()
116 fRecpoints->Delete();
127 // ------------------------------------------------------------------------- //
129 void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
131 // Converts digits to recpoints after running clustering
132 // algorithm on CPV plane and PREshower plane
134 Int_t det = 0,smn = 0;
141 TObjArray *pmdcont = new TObjArray();
142 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
144 pmdclust->SetEdepCut(fEcut);
146 fRunLoader->GetEvent(ievt);
149 fTreeD = fPMDLoader->TreeD();
152 AliFatal("AliPMDClusterFinder: Can not get TreeD");
155 AliPMDdigit *pmddigit;
156 TBranch *branch = fTreeD->GetBranch("PMDDigit");
157 branch->SetAddress(&fDigits);
161 fTreeR = fPMDLoader->TreeR();
164 fPMDLoader->MakeTree("R");
165 fTreeR = fPMDLoader->TreeR();
168 Int_t bufsize = 16000;
169 TBranch * branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
170 TBranch * branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize);
172 Int_t nmodules = (Int_t) fTreeD->GetEntries();
174 for (Int_t imodule = 0; imodule < nmodules; imodule++)
177 fTreeD->GetEntry(imodule);
178 Int_t nentries = fDigits->GetLast();
179 for (Int_t ient = 0; ient < nentries+1; ient++)
181 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
183 det = pmddigit->GetDetector();
184 smn = pmddigit->GetSMNumber();
185 xpos = pmddigit->GetRow();
186 ypos = pmddigit->GetColumn();
187 adc = pmddigit->GetADC();
190 Float_t gain = fCalibData->GetGainFact(det,smn,xpos,ypos);
191 // printf("adc = %d gain = %f\n",adc,gain);
196 //Int_t trno = pmddigit->GetTrackNumber();
197 fCellADC[xpos][ypos] = (Double_t) adc;
202 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
204 Int_t nentries1 = pmdcont->GetEntries();
206 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
208 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
210 AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
211 idet = pmdcl->GetDetector();
212 ismn = pmdcl->GetSMN();
213 clusdata[0] = pmdcl->GetClusX();
214 clusdata[1] = pmdcl->GetClusY();
215 clusdata[2] = pmdcl->GetClusADC();
216 clusdata[3] = pmdcl->GetClusCells();
217 clusdata[4] = pmdcl->GetClusSigmaX();
218 clusdata[5] = pmdcl->GetClusSigmaY();
220 AddRecPoint(idet,ismn,clusdata);
222 Int_t ncell = (Int_t) clusdata[3];
223 for(Int_t ihit = 0; ihit < ncell; ihit++)
225 Int_t celldataX = pmdcl->GetClusCellX(ihit);
226 Int_t celldataY = pmdcl->GetClusCellY(ihit);
227 AddRecHit(celldataX, celldataY);
240 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
241 fPMDLoader->WriteRecPoints("OVERWRITE");
243 // delete the pointers
248 // ------------------------------------------------------------------------- //
250 void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
253 // Converts RAW data to recpoints after running clustering
254 // algorithm on CPV and PREshower plane
258 TObjArray pmdddlcont;
260 TObjArray *pmdcont = new TObjArray();
261 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
263 pmdclust->SetEdepCut(fEcut);
267 Int_t bufsize = 16000;
268 TBranch *branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize);
270 TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize);
272 const Int_t kDDL = 6;
273 const Int_t kRow = 48;
274 const Int_t kCol = 96;
279 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
285 else if (indexDDL >= 4)
290 precpvADC = new int **[iSMN];
291 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
292 for (Int_t i=0; i<iSMN;i++)
294 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
296 for (Int_t i = 0; i < iSMN; i++)
298 for (Int_t j = 0; j < kRow; j++)
300 for (Int_t k = 0; k < kCol; k++)
302 precpvADC[i][j][k] = 0;
308 AliPMDRawStream pmdinput(rawReader);
309 rawReader->Select("PMD", indexDDL, indexDDL);
310 pmdinput.DdlData(&pmdddlcont);
312 Int_t ientries = pmdddlcont.GetEntries();
313 for (Int_t ient = 0; ient < ientries; ient++)
315 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
317 Int_t det = pmdddl->GetDetector();
318 Int_t smn = pmdddl->GetSMN();
319 //Int_t mcm = pmdddl->GetMCM();
320 //Int_t chno = pmdddl->GetChannel();
321 Int_t row = pmdddl->GetRow();
322 Int_t col = pmdddl->GetColumn();
323 Int_t sig = pmdddl->GetSignal();
325 Float_t sig1 = (Float_t) sig;
327 Float_t gain = fCalibData->GetGainFact(det,smn,row,col);
328 //printf("sig = %d gain = %f\n",sig,gain);
329 sig = (Int_t) (sig1*gain);
334 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
336 indexsmn = smn - indexDDL * 6;
338 else if (indexDDL == 4)
341 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
347 else if (smn >= 18 && smn < 24)
352 else if (indexDDL == 5)
355 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
357 if (smn >= 6 && smn < 12)
361 else if (smn >= 12 && smn < 18)
366 precpvADC[indexsmn][row][col] = sig;
372 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
375 for (Int_t irow = 0; irow < kRow; irow++)
377 for (Int_t icol = 0; icol < kCol; icol++)
379 fCellADC[irow][icol] =
380 (Double_t) precpvADC[indexsmn][irow][icol];
386 ismn = indexsmn + indexDDL * 6;
389 else if (indexDDL == 4)
395 else if (indexsmn >= 6 && indexsmn < 12)
397 ismn = indexsmn + 12;
401 else if (indexDDL == 5)
407 else if (indexsmn >= 6 && indexsmn < 12)
414 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
415 Int_t nentries1 = pmdcont->GetEntries();
417 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
419 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
421 AliPMDcluster *pmdcl =
422 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
423 idet = pmdcl->GetDetector();
424 ismn = pmdcl->GetSMN();
425 clusdata[0] = pmdcl->GetClusX();
426 clusdata[1] = pmdcl->GetClusY();
427 clusdata[2] = pmdcl->GetClusADC();
428 clusdata[3] = pmdcl->GetClusCells();
429 clusdata[4] = pmdcl->GetClusSigmaX();
430 clusdata[5] = pmdcl->GetClusSigmaY();
432 AddRecPoint(idet,ismn,clusdata);
434 Int_t ncell = (Int_t) clusdata[3];
435 for(Int_t ihit = 0; ihit < ncell; ihit++)
437 Int_t celldataX = pmdcl->GetClusCellX(ihit);
438 Int_t celldataY = pmdcl->GetClusCellY(ihit);
439 AddRecHit(celldataX, celldataY);
453 for (Int_t i=0; i<iSMN; i++)
455 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
457 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
463 // delete the pointers
468 // ------------------------------------------------------------------------- //
470 void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
472 // Converts RAW data to recpoints after running clustering
473 // algorithm on CPV and PREshower plane
477 TObjArray pmdddlcont;
478 TObjArray *pmdcont = new TObjArray();
480 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
482 pmdclust->SetEdepCut(fEcut);
484 fRunLoader->GetEvent(ievt);
488 fTreeR = fPMDLoader->TreeR();
491 fPMDLoader->MakeTree("R");
492 fTreeR = fPMDLoader->TreeR();
494 Int_t bufsize = 16000;
495 TBranch *branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
496 TBranch *branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize);
498 const Int_t kDDL = 6;
499 const Int_t kRow = 48;
500 const Int_t kCol = 96;
505 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
511 else if (indexDDL >= 4)
516 precpvADC = new int **[iSMN];
517 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
518 for (Int_t i=0; i<iSMN;i++)
520 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
522 for (Int_t i = 0; i < iSMN; i++)
524 for (Int_t j = 0; j < kRow; j++)
526 for (Int_t k = 0; k < kCol; k++)
528 precpvADC[i][j][k] = 0;
534 AliPMDRawStream pmdinput(rawReader);
535 rawReader->Select("PMD", indexDDL, indexDDL);
537 pmdinput.DdlData(&pmdddlcont);
540 Int_t ientries = pmdddlcont.GetEntries();
541 for (Int_t ient = 0; ient < ientries; ient++)
543 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
545 Int_t det = pmdddl->GetDetector();
546 Int_t smn = pmdddl->GetSMN();
547 //Int_t mcm = pmdddl->GetMCM();
548 //Int_t chno = pmdddl->GetChannel();
549 Int_t row = pmdddl->GetRow();
550 Int_t col = pmdddl->GetColumn();
551 Int_t sig = pmdddl->GetSignal();
553 Float_t sig1 = (Float_t) sig;
555 Float_t gain = fCalibData->GetGainFact(det,smn,row,col);
556 //printf("sig = %d gain = %f\n",sig,gain);
557 sig = (Int_t) (sig1*gain);
563 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
565 indexsmn = smn - indexDDL * 6;
567 else if (indexDDL == 4)
570 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
576 else if (smn >= 18 && smn < 24)
581 else if (indexDDL == 5)
584 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
586 if (smn >= 6 && smn < 12)
590 else if (smn >= 12 && smn < 18)
595 precpvADC[indexsmn][row][col] = sig;
602 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
605 for (Int_t irow = 0; irow < kRow; irow++)
607 for (Int_t icol = 0; icol < kCol; icol++)
609 fCellADC[irow][icol] =
610 (Double_t) precpvADC[indexsmn][irow][icol];
617 ismn = indexsmn + indexDDL * 6;
620 else if (indexDDL == 4)
626 else if (indexsmn >= 6 && indexsmn < 12)
628 ismn = indexsmn + 12;
632 else if (indexDDL == 5)
638 else if (indexsmn >= 6 && indexsmn < 12)
645 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
646 Int_t nentries1 = pmdcont->GetEntries();
648 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
650 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
652 AliPMDcluster *pmdcl =
653 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
654 idet = pmdcl->GetDetector();
655 ismn = pmdcl->GetSMN();
656 clusdata[0] = pmdcl->GetClusX();
657 clusdata[1] = pmdcl->GetClusY();
658 clusdata[2] = pmdcl->GetClusADC();
659 clusdata[3] = pmdcl->GetClusCells();
660 clusdata[4] = pmdcl->GetClusSigmaX();
661 clusdata[5] = pmdcl->GetClusSigmaY();
663 AddRecPoint(idet,ismn,clusdata);
665 Int_t ncell = (Int_t) clusdata[3];
666 for(Int_t ihit = 0; ihit < ncell; ihit++)
668 Int_t celldataX = pmdcl->GetClusCellX(ihit);
669 Int_t celldataY = pmdcl->GetClusCellY(ihit);
670 AddRecHit(celldataX, celldataY);
684 for (Int_t i=0; i<iSMN; i++)
686 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
688 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
694 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
695 fPMDLoader->WriteRecPoints("OVERWRITE");
697 // delete the pointers
702 // ------------------------------------------------------------------------- //
703 void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
707 // ------------------------------------------------------------------------- //
708 void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
710 // Add Reconstructed points
712 TClonesArray &lrecpoints = *fRecpoints;
713 AliPMDrecpoint1 *newrecpoint;
714 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
715 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
718 // ------------------------------------------------------------------------- //
719 void AliPMDClusterFinder::AddRecHit(Int_t celldataX,Int_t celldataY)
721 // Add associated cell hits to the Reconstructed points
723 TClonesArray &lrechits = *fRechits;
724 AliPMDrechit *newrechit;
725 newrechit = new AliPMDrechit(celldataX, celldataY);
726 new(lrechits[fNhit++]) AliPMDrechit(newrechit);
729 // ------------------------------------------------------------------------- //
730 void AliPMDClusterFinder::ResetCellADC()
732 // Reset the individual cell ADC value to zero
734 for(Int_t irow = 0; irow < fgkRow; irow++)
736 for(Int_t icol = 0; icol < fgkCol; icol++)
738 fCellADC[irow][icol] = 0.;
742 // ------------------------------------------------------------------------- //
744 void AliPMDClusterFinder::ResetRecpoint()
746 // Clear the list of reconstructed points
748 if (fRecpoints) fRecpoints->Clear();
750 // ------------------------------------------------------------------------- //
751 void AliPMDClusterFinder::ResetRechit()
753 // Clear the list of reconstructed points
755 if (fRechits) fRechits->Clear();
757 // ------------------------------------------------------------------------- //
758 void AliPMDClusterFinder::Load()
760 // Load all the *.root files
762 fPMDLoader->LoadDigits("READ");
763 fPMDLoader->LoadRecPoints("recreate");
765 // ------------------------------------------------------------------------- //
766 void AliPMDClusterFinder::LoadClusters()
768 // Load all the *.root files
770 fPMDLoader->LoadRecPoints("recreate");
772 // ------------------------------------------------------------------------- //
773 void AliPMDClusterFinder::UnLoad()
775 // Unload all the *.root files
777 fPMDLoader->UnloadDigits();
778 fPMDLoader->UnloadRecPoints();
780 // ------------------------------------------------------------------------- //
781 void AliPMDClusterFinder::UnLoadClusters()
783 // Unload all the *.root files
785 fPMDLoader->UnloadRecPoints();
787 // ------------------------------------------------------------------------- //
789 AliPMDCalibData* AliPMDClusterFinder::GetCalibData() const
791 // The run number will be centralized in AliCDBManager,
792 // you don't need to set it here!
794 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
797 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
799 // this just remembers the actual default storage. No problem if it is null.
800 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
801 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
803 entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
805 // now reset the original default storage to AliCDBManager...
806 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
809 AliPMDCalibData *calibdata=0;
810 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
812 if (!calibdata) AliError("No calibration data from calibration database !");