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"
47 #include "AliCDBManager.h"
48 #include "AliCDBEntry.h"
52 ClassImp(AliPMDClusterFinder)
54 AliPMDClusterFinder::AliPMDClusterFinder():
57 fCalibData(GetCalibData()),
60 fDigits(new TClonesArray("AliPMDdigit", 1000)),
61 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
62 fRechits(new TClonesArray("AliPMDrechit", 1000)),
72 // ------------------------------------------------------------------------- //
73 AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
74 fRunLoader(runLoader),
75 fPMDLoader(runLoader->GetLoader("PMDLoader")),
76 fCalibData(GetCalibData()),
79 fDigits(new TClonesArray("AliPMDdigit", 1000)),
80 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
81 fRechits(new TClonesArray("AliPMDrechit", 1000)),
91 // ------------------------------------------------------------------------- //
92 AliPMDClusterFinder::AliPMDClusterFinder(const AliPMDClusterFinder & finder):
96 fCalibData(GetCalibData()),
108 AliError("Copy constructor not allowed");
110 // ------------------------------------------------------------------------- //
111 AliPMDClusterFinder &AliPMDClusterFinder::operator=(const AliPMDClusterFinder & /*finder*/)
114 AliError("Assignment Operator not allowed");
117 // ------------------------------------------------------------------------- //
118 AliPMDClusterFinder::~AliPMDClusterFinder()
129 fRecpoints->Delete();
140 // ------------------------------------------------------------------------- //
142 void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt)
144 // Converts digits to recpoints after running clustering
145 // algorithm on CPV plane and PREshower plane
148 Int_t det = 0,smn = 0;
155 TObjArray *pmdcont = new TObjArray();
156 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
158 pmdclust->SetEdepCut(fEcut);
160 fRunLoader->GetEvent(ievt);
163 fTreeD = fPMDLoader->TreeD();
166 AliFatal("AliPMDClusterFinder: Can not get TreeD");
169 AliPMDdigit *pmddigit;
170 TBranch *branch = fTreeD->GetBranch("PMDDigit");
171 branch->SetAddress(&fDigits);
175 fTreeR = fPMDLoader->TreeR();
178 fPMDLoader->MakeTree("R");
179 fTreeR = fPMDLoader->TreeR();
182 Int_t bufsize = 16000;
183 TBranch * branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
184 TBranch * branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize);
186 Int_t nmodules = (Int_t) fTreeD->GetEntries();
188 for (Int_t imodule = 0; imodule < nmodules; imodule++)
191 fTreeD->GetEntry(imodule);
192 Int_t nentries = fDigits->GetLast();
193 for (Int_t ient = 0; ient < nentries+1; ient++)
195 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
197 det = pmddigit->GetDetector();
198 smn = pmddigit->GetSMNumber();
199 xpos = pmddigit->GetRow();
200 ypos = pmddigit->GetColumn();
201 adc = pmddigit->GetADC();
204 Float_t gain = fCalibData->GetGainFact(det,smn,xpos,ypos);
205 // printf("adc = %d gain = %f\n",adc,gain);
209 //Int_t trno = pmddigit->GetTrackNumber();
210 fCellADC[xpos][ypos] = (Double_t) adc;
215 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
217 Int_t nentries1 = pmdcont->GetEntries();
219 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
221 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
223 AliPMDcluster *pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
224 idet = pmdcl->GetDetector();
225 ismn = pmdcl->GetSMN();
226 clusdata[0] = pmdcl->GetClusX();
227 clusdata[1] = pmdcl->GetClusY();
228 clusdata[2] = pmdcl->GetClusADC();
229 clusdata[3] = pmdcl->GetClusCells();
230 clusdata[4] = pmdcl->GetClusSigmaX();
231 clusdata[5] = pmdcl->GetClusSigmaY();
233 AddRecPoint(idet,ismn,clusdata);
235 Int_t ncell = (Int_t) clusdata[3];
236 for(Int_t ihit = 0; ihit < ncell; ihit++)
238 Int_t celldataX = pmdcl->GetClusCellX(ihit);
239 Int_t celldataY = pmdcl->GetClusCellY(ihit);
240 AddRecHit(celldataX, celldataY);
253 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
254 fPMDLoader->WriteRecPoints("OVERWRITE");
256 // delete the pointers
261 // ------------------------------------------------------------------------- //
263 void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
266 // Converts RAW data to recpoints after running clustering
267 // algorithm on CPV and PREshower plane
269 // This method is called at the time of reconstruction
273 TObjArray pmdddlcont;
275 TObjArray *pmdcont = new TObjArray();
276 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
278 pmdclust->SetEdepCut(fEcut);
282 Int_t bufsize = 16000;
283 TBranch *branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize);
285 TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize);
287 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
288 const Int_t kRow = 48;
289 const Int_t kCol = 96;
295 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
301 else if (indexDDL >= 4)
306 precpvADC = new int **[iSMN];
307 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
308 for (Int_t i=0; i<iSMN;i++)
310 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
312 for (Int_t i = 0; i < iSMN; i++)
314 for (Int_t j = 0; j < kRow; j++)
316 for (Int_t k = 0; k < kCol; k++)
318 precpvADC[i][j][k] = 0;
324 AliPMDRawStream pmdinput(rawReader);
326 rawReader->Select("PMD", indexDDL, indexDDL);
328 pmdinput.DdlData(indexDDL,&pmdddlcont);
331 Int_t ientries = pmdddlcont.GetEntries();
332 for (Int_t ient = 0; ient < ientries; ient++)
334 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
336 Int_t det = pmdddl->GetDetector();
337 Int_t smn = pmdddl->GetSMN();
338 //Int_t mcm = pmdddl->GetMCM();
339 //Int_t chno = pmdddl->GetChannel();
340 Int_t row = pmdddl->GetRow();
341 Int_t col = pmdddl->GetColumn();
342 Int_t sig = pmdddl->GetSignal();
344 Float_t sig1 = (Float_t) sig;
346 Float_t gain = fCalibData->GetGainFact(det,smn,row,col);
347 //printf("sig = %d gain = %f\n",sig,gain);
348 sig = (Int_t) (sig1*gain);
353 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
355 indexsmn = smn - indexDDL * 6;
357 else if (indexDDL == 4)
360 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
366 else if (smn >= 18 && smn < 24)
371 else if (indexDDL == 5)
374 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
376 if (smn >= 6 && smn < 12)
380 else if (smn >= 12 && smn < 18)
385 precpvADC[indexsmn][row][col] = sig;
391 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
394 for (Int_t irow = 0; irow < kRow; irow++)
396 for (Int_t icol = 0; icol < kCol; icol++)
398 fCellADC[irow][icol] =
399 (Double_t) precpvADC[indexsmn][irow][icol];
405 ismn = indexsmn + indexDDL * 6;
408 else if (indexDDL == 4)
414 else if (indexsmn >= 6 && indexsmn < 12)
416 ismn = indexsmn + 12;
420 else if (indexDDL == 5)
426 else if (indexsmn >= 6 && indexsmn < 12)
433 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
434 Int_t nentries1 = pmdcont->GetEntries();
436 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
438 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
440 AliPMDcluster *pmdcl =
441 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
442 idet = pmdcl->GetDetector();
443 ismn = pmdcl->GetSMN();
444 clusdata[0] = pmdcl->GetClusX();
445 clusdata[1] = pmdcl->GetClusY();
446 clusdata[2] = pmdcl->GetClusADC();
447 clusdata[3] = pmdcl->GetClusCells();
448 clusdata[4] = pmdcl->GetClusSigmaX();
449 clusdata[5] = pmdcl->GetClusSigmaY();
451 AddRecPoint(idet,ismn,clusdata);
453 Int_t ncell = (Int_t) clusdata[3];
454 for(Int_t ihit = 0; ihit < ncell; ihit++)
456 Int_t celldataX = pmdcl->GetClusCellX(ihit);
457 Int_t celldataY = pmdcl->GetClusCellY(ihit);
458 AddRecHit(celldataX, celldataY);
472 for (Int_t i=0; i<iSMN; i++)
474 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
476 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
482 // delete the pointers
487 // ------------------------------------------------------------------------- //
489 void AliPMDClusterFinder::Digits2RecPoints(Int_t ievt, AliRawReader *rawReader)
491 // Converts RAW data to recpoints after running clustering
492 // algorithm on CPV and PREshower plane
496 TObjArray pmdddlcont;
497 TObjArray *pmdcont = new TObjArray();
499 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
501 pmdclust->SetEdepCut(fEcut);
503 fRunLoader->GetEvent(ievt);
507 fTreeR = fPMDLoader->TreeR();
510 fPMDLoader->MakeTree("R");
511 fTreeR = fPMDLoader->TreeR();
513 Int_t bufsize = 16000;
514 TBranch *branch1 = fTreeR->Branch("PMDRecpoint", &fRecpoints, bufsize);
515 TBranch *branch2 = fTreeR->Branch("PMDRechit", &fRechits, bufsize);
517 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
518 const Int_t kRow = 48;
519 const Int_t kCol = 96;
524 for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++)
530 else if (indexDDL >= 4)
535 precpvADC = new int **[iSMN];
536 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
537 for (Int_t i=0; i<iSMN;i++)
539 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
541 for (Int_t i = 0; i < iSMN; i++)
543 for (Int_t j = 0; j < kRow; j++)
545 for (Int_t k = 0; k < kCol; k++)
547 precpvADC[i][j][k] = 0;
553 rawReader->Select("PMD", indexDDL, indexDDL);
555 AliPMDRawStream pmdinput(rawReader);
556 pmdinput.DdlData(indexDDL,&pmdddlcont);
559 Int_t ientries = pmdddlcont.GetEntries();
560 for (Int_t ient = 0; ient < ientries; ient++)
562 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
564 Int_t det = pmdddl->GetDetector();
565 Int_t smn = pmdddl->GetSMN();
566 //Int_t mcm = pmdddl->GetMCM();
567 //Int_t chno = pmdddl->GetChannel();
568 Int_t row = pmdddl->GetRow();
569 Int_t col = pmdddl->GetColumn();
570 Int_t sig = pmdddl->GetSignal();
572 Float_t sig1 = (Float_t) sig;
574 Float_t gain = fCalibData->GetGainFact(det,smn,row,col);
576 //printf("sig = %d gain = %f\n",sig,gain);
577 sig = (Int_t) (sig1*gain);
583 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
585 indexsmn = smn - indexDDL * 6;
587 else if (indexDDL == 4)
590 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
596 else if (smn >= 18 && smn < 24)
601 else if (indexDDL == 5)
604 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
606 if (smn >= 6 && smn < 12)
610 else if (smn >= 12 && smn < 18)
615 precpvADC[indexsmn][row][col] = sig;
622 for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++)
625 for (Int_t irow = 0; irow < kRow; irow++)
627 for (Int_t icol = 0; icol < kCol; icol++)
629 fCellADC[irow][icol] =
630 (Double_t) precpvADC[indexsmn][irow][icol];
637 ismn = indexsmn + indexDDL * 6;
640 else if (indexDDL == 4)
646 else if (indexsmn >= 6 && indexsmn < 12)
648 ismn = indexsmn + 12;
652 else if (indexDDL == 5)
658 else if (indexsmn >= 6 && indexsmn < 12)
665 pmdclust->DoClust(idet,ismn,fCellADC,pmdcont);
666 Int_t nentries1 = pmdcont->GetEntries();
668 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
670 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
672 AliPMDcluster *pmdcl =
673 (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
674 idet = pmdcl->GetDetector();
675 ismn = pmdcl->GetSMN();
676 clusdata[0] = pmdcl->GetClusX();
677 clusdata[1] = pmdcl->GetClusY();
678 clusdata[2] = pmdcl->GetClusADC();
679 clusdata[3] = pmdcl->GetClusCells();
680 clusdata[4] = pmdcl->GetClusSigmaX();
681 clusdata[5] = pmdcl->GetClusSigmaY();
683 AddRecPoint(idet,ismn,clusdata);
685 Int_t ncell = (Int_t) clusdata[3];
686 for(Int_t ihit = 0; ihit < ncell; ihit++)
688 Int_t celldataX = pmdcl->GetClusCellX(ihit);
689 Int_t celldataY = pmdcl->GetClusCellY(ihit);
690 AddRecHit(celldataX, celldataY);
704 for (Int_t i=0; i<iSMN; i++)
706 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
708 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
714 fPMDLoader = fRunLoader->GetLoader("PMDLoader");
715 fPMDLoader->WriteRecPoints("OVERWRITE");
717 // delete the pointers
722 // ------------------------------------------------------------------------- //
723 void AliPMDClusterFinder::SetCellEdepCut(Float_t ecut)
727 // ------------------------------------------------------------------------- //
728 void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
730 // Add Reconstructed points
732 TClonesArray &lrecpoints = *fRecpoints;
733 AliPMDrecpoint1 *newrecpoint;
734 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
735 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
738 // ------------------------------------------------------------------------- //
739 void AliPMDClusterFinder::AddRecHit(Int_t celldataX,Int_t celldataY)
741 // Add associated cell hits to the Reconstructed points
743 TClonesArray &lrechits = *fRechits;
744 AliPMDrechit *newrechit;
745 newrechit = new AliPMDrechit(celldataX, celldataY);
746 new(lrechits[fNhit++]) AliPMDrechit(newrechit);
749 // ------------------------------------------------------------------------- //
750 void AliPMDClusterFinder::ResetCellADC()
752 // Reset the individual cell ADC value to zero
754 for(Int_t irow = 0; irow < fgkRow; irow++)
756 for(Int_t icol = 0; icol < fgkCol; icol++)
758 fCellADC[irow][icol] = 0.;
762 // ------------------------------------------------------------------------- //
764 void AliPMDClusterFinder::ResetRecpoint()
766 // Clear the list of reconstructed points
768 if (fRecpoints) fRecpoints->Clear();
770 // ------------------------------------------------------------------------- //
771 void AliPMDClusterFinder::ResetRechit()
773 // Clear the list of reconstructed points
775 if (fRechits) fRechits->Clear();
777 // ------------------------------------------------------------------------- //
778 void AliPMDClusterFinder::Load()
780 // Load all the *.root files
782 fPMDLoader->LoadDigits("READ");
783 fPMDLoader->LoadRecPoints("recreate");
785 // ------------------------------------------------------------------------- //
786 void AliPMDClusterFinder::LoadClusters()
788 // Load all the *.root files
790 fPMDLoader->LoadRecPoints("recreate");
792 // ------------------------------------------------------------------------- //
793 void AliPMDClusterFinder::UnLoad()
795 // Unload all the *.root files
797 fPMDLoader->UnloadDigits();
798 fPMDLoader->UnloadRecPoints();
800 // ------------------------------------------------------------------------- //
801 void AliPMDClusterFinder::UnLoadClusters()
803 // Unload all the *.root files
805 fPMDLoader->UnloadRecPoints();
807 // ------------------------------------------------------------------------- //
809 AliPMDCalibData* AliPMDClusterFinder::GetCalibData() const
811 // The run number will be centralized in AliCDBManager,
812 // you don't need to set it here!
814 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
817 AliWarning("Calibration object retrieval failed! Dummy calibration will be used.");
819 // this just remembers the actual default storage. No problem if it is null.
820 AliCDBStorage *origStorage = AliCDBManager::Instance()->GetDefaultStorage();
821 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
823 entry = AliCDBManager::Instance()->Get("PMD/Calib/Data");
825 // now reset the original default storage to AliCDBManager...
826 AliCDBManager::Instance()->SetDefaultStorage(origStorage);
829 AliPMDCalibData *calibdata=0;
830 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
832 if (!calibdata) AliError("No calibration data from calibration database !");