1 /**************************************************************************
2 * Copyright(c) 1998-2003, 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 **************************************************************************/
15 ////////////////////////////////////////////////////////////////////////////
16 // Implementation of the ITS clusterer V2 class //
18 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch //
19 // Unfolding switch from AliITSRecoParam: D. Elia, INFN Bari //
21 ////////////////////////////////////////////////////////////////////////////
24 #include <TGeoGlobalMagField.h>
25 #include "AliITSCalibrationSPD.h"
26 #include "AliITSClusterFinderV2SPD.h"
27 #include "AliITSRecPoint.h"
28 #include "AliITSgeomTGeo.h"
29 #include "AliITSDetTypeRec.h"
30 #include "AliITSReconstructor.h"
31 #include "AliRawReader.h"
32 #include "AliITSRawStreamSPD.h"
33 #include <TClonesArray.h>
34 #include "AliITSdigitSPD.h"
35 #include "AliITSFOSignalsSPD.h"
36 #include "AliITSRecPointContainer.h"
38 #include "AliITSsegmentationSPD.h"
40 ClassImp(AliITSClusterFinderV2SPD)
42 //__________________________________________________________________________
43 AliITSClusterFinderV2SPD::AliITSClusterFinderV2SPD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),
44 fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1),
55 fYSPD[0]=0.5*fYpitchSPD;
56 for (Int_t m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD;
58 for (Int_t m=1; m<fNzSPD; m++) {
59 Double_t dz=fZ1pitchSPD;
60 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
61 m==127 || m==128) dz=fZ2pitchSPD;
62 fZSPD[m]=fZSPD[m-1]+dz;
64 for (Int_t m=0; m<fNzSPD; m++) {
65 Double_t dz=0.5*fZ1pitchSPD;
66 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
67 m==127 || m==128) dz=0.5*fZ2pitchSPD;
72 //__________________________________________________________________________
73 void AliITSClusterFinderV2SPD::FindRawClusters(Int_t mod){
76 FindClustersSPD(fDigits);
79 //__________________________________________________________________________
80 void AliITSClusterFinderV2SPD::RawdataToClusters(AliRawReader* rawReader){
81 //------------------------------------------------------------
82 // This function creates ITS clusters from raw data
83 //------------------------------------------------------------
86 AliITSRawStreamSPD inputSPD(rawReader);
87 FindClustersSPD(&inputSPD);
90 //__________________________________________________________________________
91 Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,TClonesArray* clusters,Int_t maxBins,Int_t nzbins,Int_t iModule,Bool_t rawdata){
93 //Cluster finder for SPD (from digits and from rawdata)
94 const Double_t kmictocm = 1.0e-4; // convert microns to cm.
95 const Double_t defaultField = 5.0; // default Bz value at which Tan(theta_Lorentz) is given in RecoParam
97 static AliITSRecoParam *repa = NULL;
99 repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
101 repa = AliITSRecoParam::GetHighFluxParam();
102 AliWarning("Using default AliITSRecoParam class");
105 const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(iModule);
107 // Lorentz angle correction
108 Double_t tanLorentzAngle=0;
109 AliITSsegmentationSPD *seg = (AliITSsegmentationSPD*)(GetDetTypeRec()->GetSegmentationModel(0));
110 Double_t thick = 0.5*kmictocm*seg->Dy(); // Half Thickness in cm
111 if(repa->GetCorrectLorentzAngleSPD()) { // only if CorrectLorentzAngleSPD required
112 // here retrieve the value of the field
113 AliMagF* field = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField());
115 AliError("Cannot get magnetic field from TGeoGlobalMagField");
118 Float_t magField = field->SolenoidField();
119 tanLorentzAngle=repa->GetTanLorentzAngleHolesSPD() * magField / defaultField ;
124 if (repa->GetSPDRemoveNoisyFlag()) {
125 // Loop on noisy pixels and reset them
126 AliITSCalibrationSPD *cal =
127 (AliITSCalibrationSPD*) fDetTypeRec->GetCalibrationModel(iModule);
128 for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){
130 cal->GetBadPixel(ipix,row,col);
131 //PH printf(" module %d row %d col %d \n",iModule,row,col);
132 Int_t index = (row+1) * nzbins + (col+1);
135 bins[index].SetMask(0xFFFFFFFE);
139 if (repa->GetSPDRemoveDeadFlag()) {
140 // Loop on dead pixels and reset them
141 AliITSCalibrationSPD *cal =
142 (AliITSCalibrationSPD*) fDetTypeRec->GetSPDDeadModel(iModule);
143 if (cal->IsBad()) return 0; // if all ladder is dead, return to save time
144 for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){
146 cal->GetBadPixel(ipix,row,col);
147 Int_t index = (row+1) * nzbins + (col+1);
149 bins[index].SetMask(0xFFFFFFFE);
151 AliITSCalibrationSPD *calSparse = (AliITSCalibrationSPD*) fDetTypeRec->GetSPDSparseDeadModel(iModule);
152 for(Int_t ipix = 0; ipix<calSparse->GetNrBad(); ipix++){
154 calSparse->GetBadPixel(ipix,row,col);
155 Int_t index = (row+1) * nzbins + (col+1);
157 bins[index].SetMask(0xFFFFFFFE);
163 for(Int_t iBin =0; iBin < maxBins;iBin++){
164 if(bins[iBin].IsUsed()) continue;
167 FindCluster(iBin,nzbins,bins,nBins,idxBins);
169 Error("ClustersSPD","SPD Too big cluster !\n");
173 for(Int_t ilab=0;ilab<10;ilab++){
177 milab[3]=fNdet[iModule];
179 Int_t ymin,ymax,zmin,zmax;
181 ymin = (idxBins[0] / nzbins) - 1;
183 zmin = (idxBins[0] % nzbins) - 1;
187 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[0]);
188 ymin=dig->GetCoord2();
190 zmin=dig->GetCoord1();
193 //PH if(iModule == 24 || iModule == 25) printf("\n");
194 for (Int_t idx = 0; idx < nBins; idx++) {
198 iy = (idxBins[idx] / nzbins) - 1;
199 iz = (idxBins[idx] % nzbins) - 1;
202 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
203 iy = dig->GetCoord2();
204 iz = dig->GetCoord1();
205 //if(iModule == 24 || iModule == 25) printf(" || iy %d iz %d in Module %d \n",iy,iz,iModule);
207 if (ymin > iy) ymin = iy;
208 if (ymax < iy) ymax = iy;
209 if (zmin > iz) zmin = iz;
210 if (zmax < iz) zmax = iz;
214 for(Int_t l=0;l<nBins;l++){
215 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[l]);
216 for(Int_t dlab=0;dlab<10;dlab++){
217 Int_t digitlab = (dig->GetTracks())[dlab];
218 if(digitlab<0) continue;
219 AddLabel(milab,digitlab);
221 if (milab[9]>0) CheckLabels2(milab);
226 Int_t idy =0; //max 2 clusters
227 if((iModule <= fLastSPD1) &&idy<3) idy=3;
228 if((iModule > fLastSPD1) &&idy<4) idy=4;
231 // Switch the unfolding OFF/ON
232 if(!repa->GetUseUnfoldingInClusterFinderSPD()) {
237 for(Int_t iiz=zmin; iiz<=zmax;iiz+=idz){
238 for(Int_t iiy=ymin;iiy<=ymax;iiy+=idy){
241 Float_t y=0.,z=0.,q=0.;
242 for(Int_t idx=0;idx<nBins;idx++){
246 iy = (idxBins[idx] / nzbins)-1;
247 iz = (idxBins[idx] % nzbins)-1;
250 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
251 iy = dig->GetCoord2();
252 iz = dig->GetCoord1();
254 if(zmax-zmin>=idz || ymax-ymin>=idy){
255 if(TMath::Abs(iy-iiy)>0.75*idy) continue;
256 if(TMath::Abs(iz-iiz)>0.75*idz) continue;
261 qBin = bins[idxBins[idx]].GetQ();
262 if (fRawID2ClusID) { // RS: Register cluster id in raw words list
263 int rwid = bins[idxBins[idx]].GetRawID();
264 if (fRawID2ClusID->GetSize()<=rwid) fRawID2ClusID->Set( (rwid+10)<<1 );
265 (*fRawID2ClusID)[rwid] = milab[0] = fNClusters+1; // RS: store clID+1 as a reference to the cluster
269 AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
270 qBin = (Float_t)dig->GetSignal();
272 y+= qBin * fYSPD[iy];
273 z+= qBin * fZSPD[iz];
276 if(ndigits==0) continue;
283 // Lorentz drift effect in local y
284 y -= tanLorentzAngle*thick;
287 Float_t hit[6]; //y,z,sigma(y)^2, sigma(z)^2, charge
289 Double_t loc[3]={y,0.,z},trk[3]={0.,0.,0.};
290 mT2L->MasterToLocal(loc,trk);
294 hit[2] = fYpitchSPD*fYpitchSPD/12.;
295 hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
299 if(!rawdata) milab[3]=fNdet[iModule];
300 Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
302 AliITSRecPoint cl(milab,hit,info);
304 fDetTypeRec->AddRecPoint(cl);
307 Int_t label[4]={milab[0],milab[1],milab[2],milab[3]};
308 AliITSRecPoint cl(label, hit,info);
310 new (clusters->AddrAt(nclu))
321 //__________________________________________________________________________
322 void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStreamSPD* input)
324 //------------------------------------------------------------
325 // SPD cluster finder for raw data (this method is called once per event)
326 // Now also fills fast-or fired map
327 //------------------------------------------------------------
329 AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();
330 Int_t nClustersSPD = 0;
331 Int_t kNzBins = fNzSPD + 2;
332 Int_t kNyBins = fNySPD + 2;
333 Int_t kMaxBin = kNzBins * kNyBins;
334 AliBin *binsSPD = new AliBin[kMaxBin];
335 AliBin *binsSPDInit = new AliBin[kMaxBin];
338 // read raw data input stream
339 int countRW = 0; //RS
340 if (fRawID2ClusID) fRawID2ClusID->Reset(); //RS if array was provided, we shall store the rawID -> ClusterID
343 Bool_t next = input->Next();
344 if (!next || input->IsNewModule()) {
345 Int_t iModule = input->GetPrevModuleID();
347 // when all data from a module was read, search for clusters
349 TClonesArray* clusters = rpc->UncheckedGetClusters(iModule);
350 Int_t nClusters = ClustersSPD(bins,0,clusters,kMaxBin,kNzBins,iModule,kTRUE);
351 nClustersSPD += nClusters;
357 memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
361 // fill the current digit into the bins array
362 Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
363 bins[index].SetIndex(index);
365 bins[index].SetMask(1);
366 bins[index].SetRawID(countRW); //RS register raw id
371 delete [] binsSPDInit;
374 AliDebug(1,Form("found clusters in ITS SPD: %d", nClustersSPD));
377 // Fill the FastOr fired map
378 for (UInt_t eq=0; eq<20; eq++) {
379 for (UInt_t hs=0; hs<6; hs++) {
380 for (UInt_t chip=0; chip<10; chip++) {
381 if (input->GetFastOrSignal(eq,hs,chip)) {
382 fDetTypeRec->SetFastOrFiredMapOnline(eq,hs,chip);
389 //__________________________________________________________________________
390 void AliITSClusterFinderV2SPD::FindClustersSPD(TClonesArray *digits) {
391 //------------------------------------------------------------
392 // SPD cluster finder for digits (this method is called for each module)
393 // Now also fills the fast-or fired map
394 //------------------------------------------------------------
397 Int_t kNzBins = fNzSPD + 2;
398 const Int_t kMAXBIN=kNzBins*(fNySPD+2);
400 Int_t ndigits=digits->GetEntriesFast();
401 AliBin *bins=new AliBin[kMAXBIN];
404 AliITSdigitSPD *digit=0;
405 for (idig=0; idig<ndigits; idig++) {
406 digit=(AliITSdigitSPD*)digits->UncheckedAt(idig);
407 Int_t i=digit->GetCoord2()+1; //y
408 Int_t j=digit->GetCoord1()+1;
409 Int_t index=i*kNzBins+j;
411 bins[index].SetIndex(idig);
413 bins[index].SetMask(1);
417 Int_t nClustersSPD = ClustersSPD(bins,digits,0,kMAXBIN,kNzBins,fModule,kFALSE);
420 AliDebug(1,Form("found clusters in ITS SPD: %d", nClustersSPD));
422 // Fill the FastOr fired map
423 AliITSFOSignalsSPD* foSignals = fDetTypeRec->GetFOSignals();
425 UInt_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(fModule);
426 UInt_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(fModule);
427 for(UInt_t ch=0; ch<5; ch++) {
428 UInt_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(fModule,ch*32);
429 if (foSignals->GetSignal(eq,hs,chip)) {
430 fDetTypeRec->SetFastOrFiredMapOnline(eq,hs,chip);