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>
32 #include "AliRunLoader.h"
33 #include "AliLoader.h"
34 #include "AliRawReader.h"
36 #include "AliPMDdigit.h"
37 #include "AliPMDClusterFinder.h"
38 #include "AliPMDClustering.h"
39 #include "AliPMDClusteringV1.h"
40 #include "AliPMDcluster.h"
41 #include "AliPMDrecpoint1.h"
42 #include "AliPMDrechit.h"
43 #include "AliPMDRawStream.h"
44 #include "AliPMDCalibData.h"
45 #include "AliPMDPedestal.h"
46 #include "AliPMDddldata.h"
47 #include "AliPMDHotData.h"
48 #include "AliPMDNoiseCut.h"
49 #include "AliPMDddlinfoData.h"
50 #include "AliPMDRecoParam.h"
51 #include "AliPMDReconstructor.h"
54 #include "AliCDBManager.h"
55 #include "AliCDBEntry.h"
59 ClassImp(AliPMDClusterFinder)
61 AliPMDClusterFinder::AliPMDClusterFinder():
64 fCalibGain(GetCalibGain()),
65 fCalibPed(GetCalibPed()),
66 fCalibHot(GetCalibHot()),
67 fNoiseCut(GetNoiseCut()),
68 fDdlinfo(GetDdlinfoData()),
72 fDigits(new TClonesArray("AliPMDdigit", 1000)),
73 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
74 fRechits(new TClonesArray("AliPMDrechit", 1000)),
83 // ------------------------------------------------------------------------- //
84 AliPMDClusterFinder::AliPMDClusterFinder(AliRunLoader* runLoader):
85 fRunLoader(runLoader),
86 fPMDLoader(runLoader->GetLoader("PMDLoader")),
87 fCalibGain(GetCalibGain()),
88 fCalibPed(GetCalibPed()),
89 fCalibHot(GetCalibHot()),
90 fNoiseCut(GetNoiseCut()),
91 fDdlinfo(GetDdlinfoData()),
95 fDigits(new TClonesArray("AliPMDdigit", 1000)),
96 fRecpoints(new TClonesArray("AliPMDrecpoint1", 1000)),
97 fRechits(new TClonesArray("AliPMDrechit", 1000)),
106 // ------------------------------------------------------------------------- //
107 AliPMDClusterFinder::AliPMDClusterFinder(const AliPMDClusterFinder & finder):
111 fCalibGain(GetCalibGain()),
112 fCalibPed(GetCalibPed()),
113 fCalibHot(GetCalibHot()),
114 fNoiseCut(GetNoiseCut()),
115 fDdlinfo(GetDdlinfoData()),
127 AliError("Copy constructor not allowed");
129 // ------------------------------------------------------------------------- //
130 AliPMDClusterFinder &AliPMDClusterFinder::operator=(const AliPMDClusterFinder & /*finder*/)
133 AliError("Assignment Operator not allowed");
136 // ------------------------------------------------------------------------- //
137 AliPMDClusterFinder::~AliPMDClusterFinder()
154 // ------------------------------------------------------------------------- //
156 void AliPMDClusterFinder::Digits2RecPoints(TTree *digitsTree,
159 // Converts digits to recpoints after running clustering
160 // algorithm on CPV plane and PREshower plane
162 // This algorithm is called during the reconstruction from digits
164 Int_t det = 0, smn = 0;
165 Int_t xpos = 0, ypos = 0;
169 Float_t clusdata[6] = {0.,0.,0.,0.,0.,0.};
171 AliPMDcluster *pmdcl = 0x0;
173 TObjArray *pmdcont = new TObjArray();
175 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
177 // Fetch the reco param object
179 fRecoParam = AliPMDReconstructor::GetRecoParam();
180 if(fRecoParam == 0x0)
182 AliFatal("No Reco Param found for PMD!!!");
186 AliPMDdigit *pmddigit;
187 TBranch *branch = digitsTree->GetBranch("PMDDigit");
188 branch->SetAddress(&fDigits);
192 Int_t bufsize = 16000;
193 TBranch * branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize);
194 TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize);
196 Int_t nmodules = (Int_t) digitsTree->GetEntries();
198 for (Int_t imodule = 0; imodule < nmodules; imodule++)
203 digitsTree->GetEntry(imodule);
204 Int_t nentries = fDigits->GetLast();
205 for (Int_t ient = 0; ient < nentries+1; ient++)
207 pmddigit = (AliPMDdigit*)fDigits->UncheckedAt(ient);
209 det = pmddigit->GetDetector();
210 smn = pmddigit->GetSMNumber();
211 xpos = pmddigit->GetRow();
212 ypos = pmddigit->GetColumn();
213 adc = pmddigit->GetADC();
215 if(det < 0 || det > 1)
217 AliError(Form("*CPV/PRE NUMBER WRONG %d *",det));
220 if(smn == -1 || smn > 23)
222 AliError(Form("*MODULE NUMBER WRONG %d *",smn));
226 if(xpos < 0 || xpos > 47 || ypos < 0 || ypos > 95)
228 AliError(Form("*Row %d and Column NUMBER %d NOT Valid *",
233 // Pedestal Subtraction
234 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,xpos,ypos);
235 Int_t pedrms1 = (Int_t) pedmeanrms%100;
236 Float_t pedrms = (Float_t)pedrms1/10.;
237 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
238 //printf("%f %f\n",pedmean, pedrms);
240 Float_t adc1 = adc - (pedmean + 3.0*pedrms);
242 // Hot cell - set the cell adc = 0
243 Float_t hotflag = fCalibHot->GetHotChannel(det,smn,xpos,ypos);
244 if (hotflag == 1.) adc1 = 0;
247 Float_t gain = fCalibGain->GetGainFact(det,smn,xpos,ypos);
248 // printf("adc = %d gain = %f\n",adc,gain);
252 fCellTrack[xpos][ypos] = pmddigit->GetTrackNumber();
253 fCellPid[xpos][ypos] = pmddigit->GetTrackPid();
254 fCellADC[xpos][ypos] = (Double_t) adc;
256 totADCMod += (Int_t) adc;
263 if (totADCMod <= 0) continue;
265 // Set the minimum noise cut per module before clustering
267 // Int_t imod = idet*24 + ismn;
270 // Int_t cluspar = fRecoParam->GetPbPbParam()->GetClusteringParam();
271 Int_t cluspar = fRecoParam->GetPPParam()->GetClusteringParam();
272 // Int_t cluspar = fRecoParam->GetCosmicParam()->GetClusteringParam();
274 //_______________________________________________________//
275 //Added to switch Refine and crude Clustering - satya//
276 // temporary solution - will be sorted out later
278 static AliPMDRecoParam *reconp = NULL;
279 reconp = (AliPMDRecoParam*)AliPMDReconstructor::GetRecoParam();
285 if( reconp->GetClusteringParam() == 1)
287 if( reconp->GetClusteringParam() == 2)
290 //_______________________________________________________//
292 pmdclust->SetClusteringParam(cluspar);
295 pmdclust->SetEdepCut(encut);
296 pmdclust->DoClust(idet,ismn,fCellTrack,fCellPid,fCellADC,pmdcont);
298 Int_t nentries1 = pmdcont->GetEntries();
300 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
302 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
304 pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
305 idet = pmdcl->GetDetector();
306 ismn = pmdcl->GetSMN();
307 clusdata[0] = pmdcl->GetClusX();
308 clusdata[1] = pmdcl->GetClusY();
309 clusdata[2] = pmdcl->GetClusADC();
310 clusdata[3] = pmdcl->GetClusCells();
311 clusdata[4] = pmdcl->GetClusSigmaX();
312 clusdata[5] = pmdcl->GetClusSigmaY();
314 AddRecPoint(idet,ismn,clusdata);
316 Int_t ncell = (Int_t) clusdata[3];
317 if (ncell > 19) ncell = 19;
318 for(Int_t ihit = 0; ihit < ncell; ihit++)
320 Int_t celldataX = pmdcl->GetClusCellX(ihit);
321 Int_t celldataY = pmdcl->GetClusCellY(ihit);
322 Int_t celldataTr = pmdcl->GetClusCellTrack(ihit);
323 Int_t celldataPid = pmdcl->GetClusCellPid(ihit);
324 Float_t celldataAdc = pmdcl->GetClusCellAdc(ihit);
325 AddRecHit(celldataX, celldataY, celldataTr, celldataPid, celldataAdc);
340 // delete the pointers
344 // ------------------------------------------------------------------------- //
346 void AliPMDClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
349 // Converts RAW data to recpoints after running clustering
350 // algorithm on CPV and PREshower plane
352 // This method is called at the time of reconstruction from RAW data
355 AliPMDddldata *pmdddl = 0x0;
356 AliPMDcluster *pmdcl = 0x0;
359 TObjArray pmdddlcont;
361 TObjArray *pmdcont = new TObjArray();
363 AliPMDClustering *pmdclust = new AliPMDClusteringV1();
365 // access the ddlinfo database to fetch the no of modules per DDL
367 Int_t moduleddl[6] = {0,0,0,0,0,0};
369 for(Int_t jddl = 0; jddl < 6; jddl++)
371 moduleddl[jddl] = fDdlinfo->GetNoOfModulePerDdl(jddl);
374 // Set the minimum noise cut per module before clustering
376 fRecoParam = AliPMDReconstructor::GetRecoParam();
378 if(fRecoParam == 0x0)
380 AliFatal("No Reco Param found for PMD!!!");
385 Int_t bufsize = 16000;
386 TBranch *branch1 = clustersTree->Branch("PMDRecpoint", &fRecpoints, bufsize);
388 TBranch * branch2 = clustersTree->Branch("PMDRechit", &fRechits, bufsize);
390 const Int_t kRow = 48;
391 const Int_t kCol = 96;
397 AliPMDRawStream pmdinput(rawReader);
399 while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
401 iSMN = moduleddl[indexDDL];
404 precpvADC = new int **[iSMN];
405 for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow];
406 for (Int_t i=0; i<iSMN;i++)
408 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
410 for (Int_t i = 0; i < iSMN; i++)
412 for (Int_t j = 0; j < kRow; j++)
414 for (Int_t k = 0; k < kCol; k++)
416 precpvADC[i][j][k] = 0;
423 Int_t ientries = pmdddlcont.GetEntries();
424 for (Int_t ient = 0; ient < ientries; ient++)
426 pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
428 Int_t det = pmdddl->GetDetector();
429 Int_t smn = pmdddl->GetSMN();
430 //Int_t mcm = pmdddl->GetMCM();
431 //Int_t chno = pmdddl->GetChannel();
432 Int_t row = pmdddl->GetRow();
433 Int_t col = pmdddl->GetColumn();
434 Int_t sig = pmdddl->GetSignal();
437 if(det < 0 || det > 1)
439 AliError(Form("*CPV/PRE NUMBER WRONG %d *",det));
442 if(smn < 0 || smn > 23)
444 AliError(Form("*MODULE NUMBER WRONG %d *",smn));
447 if(row < 0 || row > 47 || col < 0 || col > 95)
449 AliError(Form("*Row %d and Column NUMBER %d NOT Valid *",
455 // Pedestal Subtraction
456 Int_t pedmeanrms = fCalibPed->GetPedMeanRms(det,smn,row,col);
457 Int_t pedrms1 = (Int_t) pedmeanrms%100;
458 Float_t pedrms = (Float_t)pedrms1/10.;
459 Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
461 //printf("%f %f\n",pedmean, pedrms);
463 // Float_t sig1 = (Float_t) sig;
464 Float_t sig1 = (Float_t) sig - (pedmean + 3.0*pedrms);
466 // Hot cell - set the cell adc = 0
467 Float_t hotflag = fCalibHot->GetHotChannel(det,smn,row,col);
468 if (hotflag == 1.) sig1 = 0;
471 Float_t gain = fCalibGain->GetGainFact(det,smn,row,col);
472 //printf("sig = %d gain = %f\n",sig,gain);
473 sig = (Int_t) (sig1*gain);
478 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
488 else if (smn >= 18 && smn < 24)
492 else if (indexDDL >= 1 && indexDDL < 4)
495 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
497 indexsmn = smn - indexDDL * 6;
499 else if (indexDDL == 4)
502 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
508 else if (smn >= 18 && smn < 24)
513 else if (indexDDL == 5)
516 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
518 if (smn >= 6 && smn < 18)
524 precpvADC[indexsmn][row][col] = sig;
532 for (indexsmn = 0; indexsmn < iSMN; indexsmn++)
536 for (Int_t irow = 0; irow < kRow; irow++)
538 for (Int_t icol = 0; icol < kCol; icol++)
540 fCellTrack[irow][icol] = -1;
541 fCellPid[irow][icol] = -1;
543 fCellADC[irow][icol] =
544 (Double_t) precpvADC[indexsmn][irow][icol];
545 totAdcMod += precpvADC[indexsmn][irow][icol];
560 else if (indexsmn >= 6 && indexsmn < 12)
561 ismn = indexsmn + 12;
565 else if (indexDDL >= 1 && indexDDL < 4)
567 ismn = indexsmn + indexDDL * 6;
570 else if (indexDDL == 4)
576 else if (indexsmn >= 6 && indexsmn < 12)
578 ismn = indexsmn + 12;
582 else if (indexDDL == 5)
588 if (totAdcMod <= 0) continue;
590 Int_t imod = idet*24 + ismn;
592 // Int_t cluspar = fRecoParam->GetPbPbParam()->GetClusteringParam();
593 Int_t cluspar = fRecoParam->GetPPParam()->GetClusteringParam();
594 // Int_t cluspar = fRecoParam->GetCosmicParam()->GetClusteringParam();
596 //_______________________________________________________//
597 //Added to switch Refine and crude Clustering - satya//
598 // temporary solution - will be sorted out later
600 static AliPMDRecoParam *reconp = NULL;
601 reconp = (AliPMDRecoParam*)AliPMDReconstructor::GetRecoParam();
606 if( reconp->GetClusteringParam() == 1)
608 if( reconp->GetClusteringParam() == 2)
611 //_______________________________________________________//
613 pmdclust->SetClusteringParam(cluspar);
614 Float_t encut = fNoiseCut->GetNoiseCut(imod);
616 pmdclust->SetEdepCut(encut);
617 pmdclust->DoClust(idet,ismn,fCellTrack,fCellPid,fCellADC,pmdcont);
619 Int_t nentries1 = pmdcont->GetEntries();
621 AliDebug(1,Form("Total number of clusters/module = %d",nentries1));
623 for (Int_t ient1 = 0; ient1 < nentries1; ient1++)
625 pmdcl = (AliPMDcluster*)pmdcont->UncheckedAt(ient1);
626 idet = pmdcl->GetDetector();
627 ismn = pmdcl->GetSMN();
628 clusdata[0] = pmdcl->GetClusX();
629 clusdata[1] = pmdcl->GetClusY();
630 clusdata[2] = pmdcl->GetClusADC();
631 clusdata[3] = pmdcl->GetClusCells();
632 clusdata[4] = pmdcl->GetClusSigmaX();
633 clusdata[5] = pmdcl->GetClusSigmaY();
635 AddRecPoint(idet,ismn,clusdata);
637 Int_t ncell = (Int_t) clusdata[3];
638 if (ncell > 19) ncell = 19;
639 for(Int_t ihit = 0; ihit < ncell; ihit++)
641 Int_t celldataX = pmdcl->GetClusCellX(ihit);
642 Int_t celldataY = pmdcl->GetClusCellY(ihit);
643 Int_t celldataTr = pmdcl->GetClusCellTrack(ihit);
644 Int_t celldataPid = pmdcl->GetClusCellPid(ihit);
645 Float_t celldataAdc = pmdcl->GetClusCellAdc(ihit);
646 AddRecHit(celldataX, celldataY, celldataTr, celldataPid, celldataAdc);
660 for (Int_t i=0; i<iSMN; i++)
662 for (Int_t j=0; j<kRow; j++) delete [] precpvADC[i][j];
664 for (Int_t i=0; i<iSMN; i++) delete [] precpvADC[i];
672 // delete the pointers
676 // ------------------------------------------------------------------------- //
677 void AliPMDClusterFinder::AddRecPoint(Int_t idet,Int_t ismn,Float_t *clusdata)
679 // Add Reconstructed points
681 TClonesArray &lrecpoints = *fRecpoints;
682 AliPMDrecpoint1 *newrecpoint;
683 newrecpoint = new AliPMDrecpoint1(idet, ismn, clusdata);
684 new(lrecpoints[fNpoint++]) AliPMDrecpoint1(newrecpoint);
687 // ------------------------------------------------------------------------- //
688 void AliPMDClusterFinder::AddRecHit(Int_t celldataX,Int_t celldataY,
689 Int_t celldataTr, Int_t celldataPid,
692 // Add associated cell hits to the Reconstructed points
694 TClonesArray &lrechits = *fRechits;
695 AliPMDrechit *newrechit;
696 newrechit = new AliPMDrechit(celldataX, celldataY, celldataTr, celldataPid, celldataAdc);
697 new(lrechits[fNhit++]) AliPMDrechit(newrechit);
700 // ------------------------------------------------------------------------- //
701 void AliPMDClusterFinder::ResetCellADC()
703 // Reset the individual cell ADC value to zero
705 for(Int_t irow = 0; irow < fgkRow; irow++)
707 for(Int_t icol = 0; icol < fgkCol; icol++)
709 fCellTrack[irow][icol] = -1;
710 fCellPid[irow][icol] = -1;
711 fCellADC[irow][icol] = 0.;
715 // ------------------------------------------------------------------------- //
716 void AliPMDClusterFinder::ResetRecpoint()
718 // Clear the list of reconstructed points
720 if (fRecpoints) fRecpoints->Clear();
722 // ------------------------------------------------------------------------- //
723 void AliPMDClusterFinder::ResetRechit()
725 // Clear the list of reconstructed points
727 if (fRechits) fRechits->Clear();
729 // ------------------------------------------------------------------------- //
730 void AliPMDClusterFinder::Load()
732 // Load all the *.root files
734 fPMDLoader->LoadDigits("READ");
735 fPMDLoader->LoadRecPoints("recreate");
737 // ------------------------------------------------------------------------- //
738 void AliPMDClusterFinder::LoadClusters()
740 // Load all the *.root files
742 fPMDLoader->LoadRecPoints("recreate");
744 // ------------------------------------------------------------------------- //
745 void AliPMDClusterFinder::UnLoad()
747 // Unload all the *.root files
749 fPMDLoader->UnloadDigits();
750 fPMDLoader->UnloadRecPoints();
752 // ------------------------------------------------------------------------- //
753 void AliPMDClusterFinder::UnLoadClusters()
755 // Unload all the *.root files
757 fPMDLoader->UnloadRecPoints();
759 // ------------------------------------------------------------------------- //
760 AliPMDCalibData* AliPMDClusterFinder::GetCalibGain() const
762 // The run number will be centralized in AliCDBManager,
763 // you don't need to set it here!
765 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Gain");
767 if(!entry) AliFatal("Calibration object retrieval failed! ");
769 AliPMDCalibData *calibdata=0;
770 if (entry) calibdata = (AliPMDCalibData*) entry->GetObject();
772 if (!calibdata) AliFatal("No calibration data from calibration database !");
776 // ------------------------------------------------------------------------- //
777 AliPMDPedestal* AliPMDClusterFinder::GetCalibPed() const
779 // The run number will be centralized in AliCDBManager,
780 // you don't need to set it here!
781 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ped");
783 if(!entry) AliFatal("Pedestal object retrieval failed!");
785 AliPMDPedestal *pedestal = 0;
786 if (entry) pedestal = (AliPMDPedestal*) entry->GetObject();
788 if (!pedestal) AliFatal("No pedestal data from pedestal database !");
792 //--------------------------------------------------------------------//
793 AliPMDHotData* AliPMDClusterFinder::GetCalibHot() const
795 // The run number will be centralized in AliCDBManager,
796 // you don't need to set it here!
797 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Hot");
799 if(!entry) AliFatal("HotData object retrieval failed!");
801 AliPMDHotData *hot = 0;
802 if (entry) hot = (AliPMDHotData*) entry->GetObject();
804 if (!hot) AliFatal("No hot data from database !");
808 //--------------------------------------------------------------------//
809 AliPMDNoiseCut* AliPMDClusterFinder::GetNoiseCut() const
811 // The run number will be centralized in AliCDBManager,
812 // you don't need to set it here!
813 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/NoiseCut");
815 if(!entry) AliFatal("Noisecut object retrieval failed!");
817 AliPMDNoiseCut *ncut = 0;
818 if (entry) ncut = (AliPMDNoiseCut*) entry->GetObject();
820 if (!ncut) AliFatal("No noise cut data from database !");
824 //--------------------------------------------------------------------//
825 AliPMDddlinfoData* AliPMDClusterFinder::GetDdlinfoData() const
827 // The run number will be centralized in AliCDBManager,
828 // you don't need to set it here!
829 AliCDBEntry *entry = AliCDBManager::Instance()->Get("PMD/Calib/Ddlinfo");
831 if(!entry) AliFatal("ddlinfo object retrieval failed!");
833 AliPMDddlinfoData *ddlinfo = 0;
834 if (entry) ddlinfo = (AliPMDddlinfoData*) entry->GetObject();
836 if (!ddlinfo) AliFatal("No ddl info data from database !");