1 //-------------------------------------------------------------------------
2 // Implementation of the ITS clusterer V2 class
4 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
5 //-------------------------------------------------------------------------
6 //uncomment the line below for running with V1 cluster finder classes
11 #include "AliITSclustererV2.h"
12 #include "AliITSclusterV2.h"
13 #include "AliRawReader.h"
14 #include "AliITSRawStreamSPD.h"
15 #include "AliITSRawStreamSDD.h"
16 #include "AliITSRawStreamSSD.h"
20 #include <TClonesArray.h>
21 #include "AliITSgeom.h"
22 #include "AliITSdigitSPD.h"
23 #include "AliITSdigitSDD.h"
24 #include "AliITSdigitSSD.h"
27 ClassImp(AliITSclustererV2)
29 extern AliRun *gAlice;
31 AliITSclustererV2::AliITSclustererV2(const AliITSgeom *geom) {
32 //------------------------------------------------------------
33 // Standard constructor
34 //------------------------------------------------------------
35 AliITSgeom *g=(AliITSgeom*)geom;
40 Int_t mmax=geom->GetIndexMax();
42 Fatal("AliITSclustererV2","Too many ITS subdetectors !");
45 for (m=0; m<mmax; m++) {
46 Int_t lay,lad,det; g->GetModuleId(m,lay,lad,det);
47 Float_t x,y,z; g->GetTrans(lay,lad,det,x,y,z);
48 Double_t rot[9]; g->GetRotMatrix(lay,lad,det,rot);
49 Double_t alpha=TMath::ATan2(rot[1],rot[0])+TMath::Pi();
50 Double_t ca=TMath::Cos(alpha), sa=TMath::Sin(alpha);
51 fYshift[m] = x*ca + y*sa;
52 fZshift[m] = (Double_t)z;
53 fNdet[m] = (lad-1)*g->GetNdetectors(lay) + (det-1);
55 fNModules = g->GetIndexMax();
58 fLastSPD1=g->GetModuleIndex(2,1,1)-1;
59 fNySPD=256; fNzSPD=160;
61 fZ1pitchSPD=0.0425; fZ2pitchSPD=0.0625;
62 fHwSPD=0.64; fHlSPD=3.48;
63 fYSPD[0]=0.5*fYpitchSPD;
64 for (m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD;
66 for (m=1; m<fNzSPD; m++) {
67 Double_t dz=fZ1pitchSPD;
68 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
69 m==127 || m==128) dz=fZ2pitchSPD;
70 fZSPD[m]=fZSPD[m-1]+dz;
72 for (m=0; m<fNzSPD; m++) {
73 Double_t dz=0.5*fZ1pitchSPD;
74 if (m==31 || m==32 || m==63 || m==64 || m==95 || m==96 ||
75 m==127 || m==128) dz=0.5*fZ2pitchSPD;
80 fNySDD=256; fNzSDD=256;
83 fHwSDD=3.5085; fHlSDD=3.7632;
87 fLastSSD1=g->GetModuleIndex(6,1,1)-1;
96 Int_t AliITSclustererV2::Digits2Clusters(TTree *dTree, TTree *cTree) {
97 //------------------------------------------------------------
98 // This function creates ITS clusters
99 //------------------------------------------------------------
103 Error("Digits2Clusters","Can't get the tree with digits !");
107 TClonesArray *digitsSPD=new TClonesArray("AliITSdigitSPD",3000);
108 dTree->SetBranchAddress("ITSDigitsSPD",&digitsSPD);
109 TClonesArray *digitsSDD=new TClonesArray("AliITSdigitSDD",3000);
110 dTree->SetBranchAddress("ITSDigitsSDD",&digitsSDD);
111 TClonesArray *digitsSSD=new TClonesArray("AliITSdigitSSD",3000);
112 dTree->SetBranchAddress("ITSDigitsSSD",&digitsSSD);
114 TClonesArray *clusters=new TClonesArray("AliITSclusterV2",1000);
115 TBranch *branch=cTree->GetBranch("Clusters");
116 if (!branch) cTree->Branch("Clusters",&clusters);
117 else branch->SetAddress(&clusters);
119 Int_t mmax=(Int_t)dTree->GetEntries();
121 for (fI=0; fI<mmax; fI++) {
124 if (digitsSPD->GetEntriesFast()!=0)
125 FindClustersSPD(digitsSPD,clusters);
126 else if(digitsSDD->GetEntriesFast()!=0)
127 FindClustersSDD(digitsSDD,clusters);
128 else if(digitsSSD->GetEntriesFast()!=0)
129 FindClustersSSD(digitsSSD,clusters);
131 ncl+=clusters->GetEntriesFast();
151 Info("Digits2Clusters","Number of found clusters : %d",ncl);
156 void AliITSclustererV2::Digits2Clusters(AliRawReader* rawReader) {
157 //------------------------------------------------------------
158 // This function creates ITS clusters from raw data
159 //------------------------------------------------------------
160 AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
162 Error("Digits2Clusters", "no run loader found");
165 AliLoader* itsLoader = runLoader->GetLoader("ITSLoader");
167 Error("Digits2Clusters", "no loader for ITS found");
170 if (!itsLoader->TreeR()) itsLoader->MakeTree("R");
171 TTree* cTree = itsLoader->TreeR();
173 TClonesArray *array=new TClonesArray("AliITSclusterV2",1000);
174 cTree->Branch("Clusters",&array);
177 TClonesArray** clusters = new TClonesArray*[fNModules];
178 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
179 clusters[iModule] = NULL;
181 // one TClonesArray per module
184 AliITSRawStreamSPD inputSPD(rawReader);
185 FindClustersSPD(&inputSPD, clusters);
188 AliITSRawStreamSDD inputSDD(rawReader);
189 FindClustersSDD(&inputSDD, clusters);
192 AliITSRawStreamSSD inputSSD(rawReader);
193 FindClustersSSD(&inputSSD, clusters);
195 // write all clusters to the tree
197 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
198 array = clusters[iModule];
200 Error("Digits2Clusters", "data for module %d missing!", iModule);
201 array = new TClonesArray("AliITSclusterV2");
203 cTree->SetBranchAddress("Clusters", &array);
205 nClusters += array->GetEntriesFast();
208 itsLoader->WriteRecPoints("OVERWRITE");
212 Info("Digits2Clusters", "total number of found clusters in ITS: %d\n",
216 //**** Fast clusters *******************************
217 #include "TParticle.h"
220 #include "AliITSmodule.h"
221 #include "AliITSRecPoint.h"
222 #include "AliITSsimulationFastPoints.h"
223 #include "AliITSRecPoint.h"
225 static void CheckLabels(Int_t lab[3]) {
226 //------------------------------------------------------------
227 // Tries to find mother's labels
228 //------------------------------------------------------------
231 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
233 while (part->P() < 0.005) {
234 Int_t m=part->GetFirstMother();
236 Info("CheckLabels","Primary momentum: %f",part->P());
239 if (part->GetStatusCode()>0) {
240 Info("CheckLabels","Primary momentum: %f",part->P());
244 part=(TParticle*)gAlice->GetMCApp()->Particle(label);
246 if (lab[1]<0) lab[1]=label;
247 else if (lab[2]<0) lab[2]=label;
248 else ;//cerr<<"CheckLabels : No empty labels !\n";
252 void AliITSclustererV2::RecPoints2Clusters
253 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
254 //------------------------------------------------------------
255 // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS
256 // subdetector indexed by idx
257 //------------------------------------------------------------
258 TClonesArray &cl=*clusters;
259 Int_t ncl=points->GetEntriesFast();
260 for (Int_t i=0; i<ncl; i++) {
261 AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
263 lp[0]=-(-p->GetX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
264 lp[1]= -p->GetZ()+fZshift[idx];
265 lp[2]=p->GetSigmaX2();
266 lp[3]=p->GetSigmaZ2();
267 lp[4]=p->GetQ()*36./23333.; //electrons -> ADC
269 lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
272 new (cl[i]) AliITSclusterV2(lab,lp);
276 Int_t AliITSclustererV2::Hits2Clusters(TTree *hTree, TTree *cTree) {
277 //------------------------------------------------------------
278 // This function creates ITS clusters
279 //------------------------------------------------------------
281 Error("Hits2Clusters","gAlice==0 !");
285 AliITS *its = (AliITS*)gAlice->GetModule("ITS");
287 Error("Hits2Clusters","Can't find the ITS !");
290 AliITSgeom *geom=its->GetITSgeom();
291 Int_t mmax=geom->GetIndexMax();
293 its->InitModules(-1,mmax);
294 its->FillModules(hTree,0);
296 TClonesArray *clusters=new TClonesArray("AliITSclusterV2",1000);
297 TBranch *branch=cTree->GetBranch("Clusters");
298 if (!branch) cTree->Branch("Clusters",&clusters);
299 else branch->SetAddress(&clusters);
301 static TClonesArray *points=its->RecPoints();
302 AliITSsimulationFastPoints sim;
304 for (Int_t m=0; m<mmax; m++) {
305 AliITSmodule *mod=its->GetModule(m);
306 sim.CreateFastRecPoints(mod,m,gRandom);
308 RecPoints2Clusters(points, m, clusters);
309 its->ResetRecPoints();
311 ncl+=clusters->GetEntriesFast();
316 Info("Hits2Clusters","Number of found fast clusters : %d",ncl);
325 //***********************************
329 void AliITSclustererV2::
330 FindCluster(Int_t k,Int_t maxz,AliBin *bins,Int_t &n,Int_t *idx) {
331 //------------------------------------------------------------
332 // returns an array of indices of digits belonging to the cluster
333 // (needed when the segmentation is not regular)
334 //------------------------------------------------------------
335 if (n<200) idx[n++]=bins[k].GetIndex();
338 if (bins[k-maxz].IsNotUsed()) FindCluster(k-maxz,maxz,bins,n,idx);
339 if (bins[k-1 ].IsNotUsed()) FindCluster(k-1 ,maxz,bins,n,idx);
340 if (bins[k+maxz].IsNotUsed()) FindCluster(k+maxz,maxz,bins,n,idx);
341 if (bins[k+1 ].IsNotUsed()) FindCluster(k+1 ,maxz,bins,n,idx);
343 if (bins[k-maxz-1].IsNotUsed()) FindCluster(k-maxz-1,maxz,bins,n,idx);
344 if (bins[k-maxz+1].IsNotUsed()) FindCluster(k-maxz+1,maxz,bins,n,idx);
345 if (bins[k+maxz-1].IsNotUsed()) FindCluster(k+maxz-1,maxz,bins,n,idx);
346 if (bins[k+maxz+1].IsNotUsed()) FindCluster(k+maxz+1,maxz,bins,n,idx);
350 void AliITSclustererV2::
351 FindClustersSPD(const TClonesArray *digits, TClonesArray *clusters) {
352 //------------------------------------------------------------
353 // Actual SPD cluster finder
354 //------------------------------------------------------------
355 Int_t kNzBins = fNzSPD + 2;
356 const Int_t kMAXBIN=kNzBins*(fNySPD+2);
358 Int_t ndigits=digits->GetEntriesFast();
359 AliBin *bins=new AliBin[kMAXBIN];
363 for (k=0; k<ndigits; k++) {
364 d=(AliITSdigitSPD*)digits->UncheckedAt(k);
365 Int_t i=d->GetCoord2()+1; //y
366 Int_t j=d->GetCoord1()+1;
367 bins[i*kNzBins+j].SetIndex(k);
368 bins[i*kNzBins+j].SetMask(1);
371 Int_t n=0; TClonesArray &cl=*clusters;
372 for (k=0; k<kMAXBIN; k++) {
373 if (!bins[k].IsNotUsed()) continue;
374 Int_t ni=0, idx[200];
375 FindCluster(k,kNzBins,bins,ni,idx);
377 Info("FindClustersSPD","Too big cluster !");
386 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
387 Int_t ymin=d->GetCoord2(),ymax=ymin;
388 Int_t zmin=d->GetCoord1(),zmax=zmin;
389 Float_t y=0.,z=0.,q=0.;
390 for (Int_t l=0; l<ni; l++) {
391 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
393 if (ymin > d->GetCoord2()) ymin=d->GetCoord2();
394 if (ymax < d->GetCoord2()) ymax=d->GetCoord2();
395 if (zmin > d->GetCoord1()) zmin=d->GetCoord1();
396 if (zmax < d->GetCoord1()) zmax=d->GetCoord1();
398 Int_t lab0=(d->GetTracks())[0];
402 } else if (lab[1]<0) {
403 if (lab0!=lab[0]) lab[1]=lab0;
404 } else if (lab[2]<0) {
406 if (lab0!=lab[1]) lab[2]=lab0;
409 Float_t qq=d->GetSignal();
410 y+=qq*fYSPD[d->GetCoord2()]; z+=qq*fZSPD[d->GetCoord1()]; q+=qq;
413 y-=fHwSPD; z-=fHlSPD;
416 lp[0]=-(-y+fYshift[fI]); if (fI<=fLastSPD1) lp[0]=-lp[0];
417 lp[1]= -z+fZshift[fI];
418 lp[2]= fYpitchSPD*fYpitchSPD/12.;
419 lp[3]= fZ1pitchSPD*fZ1pitchSPD/12.;
421 lp[4]= (zmax-zmin+1)*100 + (ymax-ymin+1);
424 d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
425 new (cl[n]) AliITSclusterV2(lab,lp); n++;
431 void AliITSclustererV2::FindClustersSPD(AliITSRawStream* input,
432 TClonesArray** clusters)
434 //------------------------------------------------------------
435 // Actual SPD cluster finder for raw data
436 //------------------------------------------------------------
438 Int_t nClustersSPD = 0;
439 Int_t kNzBins = fNzSPD + 2;
440 Int_t kNyBins = fNySPD + 2;
441 Int_t kMaxBin = kNzBins * kNyBins;
444 // read raw data input stream
446 Bool_t next = input->Next();
447 if (!next || input->IsNewModule()) {
448 Int_t iModule = input->GetPrevModuleID();
450 // when all data from a module was read, search for clusters
452 clusters[iModule] = new TClonesArray("AliITSclusterV2");
455 for (Int_t iBin = 0; iBin < kMaxBin; iBin++) {
456 if (bins[iBin].IsUsed()) continue;
459 FindCluster(iBin, kNzBins, bins, nBins, idxBins);
461 Error("FindClustersSPD", "SPD: Too big cluster !\n");
469 // label[3] = iModule;
470 label[3] = fNdet[iModule];
472 Int_t ymin = (idxBins[0] / kNzBins) - 1;
474 Int_t zmin = (idxBins[0] % kNzBins) - 1;
479 for (Int_t idx = 0; idx < nBins; idx++) {
480 Int_t iy = (idxBins[idx] / kNzBins) - 1;
481 Int_t iz = (idxBins[idx] % kNzBins) - 1;
482 if (ymin > iy) ymin = iy;
483 if (ymax < iy) ymax = iy;
484 if (zmin > iz) zmin = iz;
485 if (zmax < iz) zmax = iz;
487 Float_t qBin = bins[idxBins[idx]].GetQ();
488 y += qBin * fYSPD[iy];
489 z += qBin * fZSPD[iz];
497 Float_t hit[5]; // y, z, sigma(y)^2, sigma(z)^2, charge
498 hit[0] = -y-fYshift[iModule];
499 if (iModule <= fLastSPD1) hit[0] = -hit[0];
500 hit[1] = z+fZshift[iModule];
501 hit[2] = fYpitchSPD*fYpitchSPD/12.;
502 hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
504 hit[4] = (zmax-zmin+1)*100 + (ymax-ymin+1);
506 //CheckLabels(label);
507 new (clusters[iModule]->AddrAt(nClusters))
508 AliITSclusterV2(label, hit);
512 nClustersSPD += nClusters;
517 bins = new AliBin[kMaxBin];
520 // fill the current digit into the bins array
521 Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
522 bins[index].SetIndex(index);
523 bins[index].SetMask(1);
527 Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD);
531 Bool_t AliITSclustererV2::IsMaximum(Int_t k,Int_t max,const AliBin *bins) {
532 //------------------------------------------------------------
533 //is this a local maximum ?
534 //------------------------------------------------------------
535 UShort_t q=bins[k].GetQ();
536 if (q==1023) return kFALSE;
537 if (bins[k-max].GetQ() > q) return kFALSE;
538 if (bins[k-1 ].GetQ() > q) return kFALSE;
539 if (bins[k+max].GetQ() > q) return kFALSE;
540 if (bins[k+1 ].GetQ() > q) return kFALSE;
541 if (bins[k-max-1].GetQ() > q) return kFALSE;
542 if (bins[k+max-1].GetQ() > q) return kFALSE;
543 if (bins[k+max+1].GetQ() > q) return kFALSE;
544 if (bins[k-max+1].GetQ() > q) return kFALSE;
548 void AliITSclustererV2::
549 FindPeaks(Int_t k,Int_t max,AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
550 //------------------------------------------------------------
552 //------------------------------------------------------------
554 if (IsMaximum(k,max,b)) {
555 idx[n]=k; msk[n]=(2<<n);
559 if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
560 if (b[k-1 ].GetMask()&1) FindPeaks(k-1 ,max,b,idx,msk,n);
561 if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
562 if (b[k+1 ].GetMask()&1) FindPeaks(k+1 ,max,b,idx,msk,n);
565 void AliITSclustererV2::
566 MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
567 //------------------------------------------------------------
569 //------------------------------------------------------------
570 UShort_t q=bins[k].GetQ();
572 bins[k].SetMask(bins[k].GetMask()|m);
574 if (bins[k-max].GetQ() <= q)
575 if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
576 if (bins[k-1 ].GetQ() <= q)
577 if ((bins[k-1 ].GetMask()&m) == 0) MarkPeak(k-1 ,max,bins,m);
578 if (bins[k+max].GetQ() <= q)
579 if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
580 if (bins[k+1 ].GetQ() <= q)
581 if ((bins[k+1 ].GetMask()&m) == 0) MarkPeak(k+1 ,max,bins,m);
584 void AliITSclustererV2::
585 MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,AliITSclusterV2 &c) {
586 //------------------------------------------------------------
587 //make cluster using digits of this peak
588 //------------------------------------------------------------
589 Float_t q=(Float_t)bins[k].GetQ();
590 Int_t i=k/max, j=k-i*max;
593 c.SetY(c.GetY()+i*q);
594 c.SetZ(c.GetZ()+j*q);
595 c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
596 c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
598 bins[k].SetMask(0xFFFFFFFE);
600 if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
601 if (bins[k-1 ].GetMask() == m) MakeCluster(k-1 ,max,bins,m,c);
602 if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);
603 if (bins[k+1 ].GetMask() == m) MakeCluster(k+1 ,max,bins,m,c);
606 void AliITSclustererV2::
607 FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins,
608 const TClonesArray *digits, TClonesArray *clusters) {
609 //------------------------------------------------------------
610 // Actual SDD cluster finder
611 //------------------------------------------------------------
612 Int_t ncl=0; TClonesArray &cl=*clusters;
613 for (Int_t s=0; s<2; s++)
614 for (Int_t i=0; i<nMaxBin; i++) {
615 if (bins[s][i].IsUsed()) continue;
616 Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
617 FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
619 if (npeaks>30) continue;
622 for (k=0; k<npeaks-1; k++){//mark adjacent peaks
623 if (idx[k] < 0) continue; //this peak is already removed
624 for (l=k+1; l<npeaks; l++) {
625 if (idx[l] < 0) continue; //this peak is already removed
626 Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
627 Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
628 Int_t di=TMath::Abs(ki - li);
629 Int_t dj=TMath::Abs(kj - lj);
630 if (di>1 || dj>1) continue;
631 if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
642 for (k=0; k<npeaks; k++) {
643 MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
646 for (k=0; k<npeaks; k++) {
647 if (idx[k] < 0) continue; //removed peak
649 MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
652 Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
653 Float_t w=par->GetPadPitchWidth(sec);
654 c.SetSigmaY2((s2 + 1./12.)*w*w);
656 c.SetSigmaY2(c.GetSigmaY2()*0.108);
657 if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
660 s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
662 c.SetSigmaZ2((s2 + 1./12.)*w*w);
664 c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
665 if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
669 c.SetSigmaY2(0.0030*0.0030);
670 c.SetSigmaZ2(0.0020*0.0020);
671 c.SetDetectorIndex(fNdet[fI]);
673 Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
676 y=(y-0.5)*fYpitchSDD;
678 y-=fYoffSDD; //delay ?
681 z=(z-0.5)*fZpitchSDD;
689 c.SetQ(q/12.7); //to be consistent with the SSD charges
691 if (c.GetQ() < 20.) continue; //noise cluster
694 AliBin *b=&bins[s][idx[k]];
695 AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
696 Int_t l0=(d->GetTracks())[0];
698 b=&bins[s][idx[k]-1];
700 d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
701 l0=(d->GetTracks())[0];
705 b=&bins[s][idx[k]+1];
707 d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
708 l0=(d->GetTracks())[0];
712 b=&bins[s][idx[k]-nzBins];
714 d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
715 l0=(d->GetTracks())[0];
719 b=&bins[s][idx[k]+nzBins];
721 d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
722 l0=(d->GetTracks())[0];
727 b=&bins[s][idx[k]+nzBins+1];
729 d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
730 l0=(d->GetTracks())[0];
734 b=&bins[s][idx[k]+nzBins-1];
736 d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
737 l0=(d->GetTracks())[0];
741 b=&bins[s][idx[k]-nzBins+1];
743 d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
744 l0=(d->GetTracks())[0];
748 b=&bins[s][idx[k]-nzBins-1];
750 d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
751 l0=(d->GetTracks())[0];
757 lab[0]=(d->GetTracks())[0];
758 lab[1]=(d->GetTracks())[1];
759 lab[2]=(d->GetTracks())[2];
761 c.SetLabel(lab[0],0);
762 c.SetLabel(lab[1],1);
763 c.SetLabel(lab[2],2);
767 new (cl[ncl]) AliITSclusterV2(c); ncl++;
772 void AliITSclustererV2::
773 FindClustersSDD(const TClonesArray *digits, TClonesArray *clusters) {
774 //------------------------------------------------------------
775 // Actual SDD cluster finder
776 //------------------------------------------------------------
777 Int_t kNzBins = fNzSDD + 2;
778 const Int_t kMAXBIN=kNzBins*(fNySDD+2);
781 bins[0]=new AliBin[kMAXBIN];
782 bins[1]=new AliBin[kMAXBIN];
785 Int_t i, ndigits=digits->GetEntriesFast();
786 for (i=0; i<ndigits; i++) {
787 d=(AliITSdigitSDD*)digits->UncheckedAt(i);
788 Int_t y=d->GetCoord2()+1; //y
789 Int_t z=d->GetCoord1()+1; //z
790 Int_t q=d->GetSignal();
794 bins[0][y*kNzBins+z].SetQ(q);
795 bins[0][y*kNzBins+z].SetMask(1);
796 bins[0][y*kNzBins+z].SetIndex(i);
799 bins[1][y*kNzBins+z].SetQ(q);
800 bins[1][y*kNzBins+z].SetMask(1);
801 bins[1][y*kNzBins+z].SetIndex(i);
805 FindClustersSDD(bins, kMAXBIN, kNzBins, digits, clusters);
811 void AliITSclustererV2::FindClustersSDD(AliITSRawStream* input,
812 TClonesArray** clusters)
814 //------------------------------------------------------------
815 // Actual SDD cluster finder for raw data
816 //------------------------------------------------------------
817 Int_t nClustersSDD = 0;
818 Int_t kNzBins = fNzSDD + 2;
819 Int_t kMaxBin = kNzBins * (fNySDD+2);
820 AliBin* bins[2] = {NULL, NULL};
822 // read raw data input stream
824 Bool_t next = input->Next();
825 if (!next || input->IsNewModule()) {
826 Int_t iModule = input->GetPrevModuleID();
828 // when all data from a module was read, search for clusters
830 clusters[iModule] = new TClonesArray("AliITSclusterV2");
832 FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
833 Int_t nClusters = clusters[iModule]->GetEntriesFast();
834 nClustersSDD += nClusters;
840 bins[0] = new AliBin[kMaxBin];
841 bins[1] = new AliBin[kMaxBin];
844 // fill the current digit into the bins array
845 Int_t iz = input->GetCoord1()+1;
846 Int_t side = ((iz <= fNzSDD) ? 0 : 1);
848 Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
849 bins[side][index].SetQ(input->GetSignal());
850 bins[side][index].SetMask(1);
851 bins[side][index].SetIndex(index);
854 Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
857 void AliITSclustererV2::
858 FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
859 Ali1Dcluster* pos, Int_t np,
860 TClonesArray *clusters) {
861 //------------------------------------------------------------
862 // Actual SSD cluster finder
863 //------------------------------------------------------------
864 TClonesArray &cl=*clusters;
866 Int_t lab[4]={-2,-2,-2,-2};
867 Float_t tanp=fTanP, tann=fTanN;
868 if (fI>fLastSSD1) {tann=fTanP; tanp=fTanN;}
870 Int_t idet=fNdet[fI];
872 for (Int_t i=0; i<np; i++) {
873 //Float_t dq_min=1.e+33;
874 Float_t ybest=1000,zbest=1000,qbest=0;
875 Float_t yp=pos[i].GetY()*fYpitchSSD;
876 for (Int_t j=0; j<nn; j++) {
877 //if (pos[i].fTracks[0] != neg[j].fTracks[0]) continue;
878 Float_t yn=neg[j].GetY()*fYpitchSSD;
879 Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
880 Float_t yt=yn + tann*zt;
881 zt-=fHlSSD; yt-=fHwSSD;
882 if (TMath::Abs(yt)<fHwSSD+0.01)
883 if (TMath::Abs(zt)<fHlSSD+0.01) {
884 //if (TMath::Abs(pos[i].GetQ()-neg[j].GetQ())<dq_min) {
885 //dq_min=TMath::Abs(pos[i].GetQ()-neg[j].GetQ());
887 qbest=0.5*(pos[i].GetQ()+neg[j].GetQ());
889 lab[0]=pos[i].GetLabel(0);
890 lab[1]=pos[i].GetLabel(1);
891 lab[2]=neg[i].GetLabel(0);
892 lab[3]=(((i<<10) + j)<<10) + idet; // pos|neg|det
894 lp[0]=-(-ybest+fYshift[fI]);
895 lp[1]= -zbest+fZshift[fI];
896 lp[2]=0.0025*0.0025; //SigmaY2
897 lp[3]=0.110*0.110; //SigmaZ2
898 if (pos[i].GetNd()+neg[j].GetNd() > 4) {
905 new (cl[ncl]) AliITSclusterV2(lab,lp); ncl++;
912 lp[0]=-ybest-fYshift[fI];
913 lp[1]= zbest+fZshift[fI];
914 lp[2]=0.002*0.002; //SigmaY2
915 lp[3]=0.080*0.080; //SigmaZ2
918 new (cl[ncl]) AliITSclusterV2(lab,lp); ncl++;
924 void AliITSclustererV2::
925 FindClustersSSD(const TClonesArray *digits, TClonesArray *clusters) {
926 //------------------------------------------------------------
927 // Actual SSD cluster finder
928 //------------------------------------------------------------
929 Int_t smax=digits->GetEntriesFast();
932 const Int_t MAX=1000;
934 Ali1Dcluster pos[MAX], neg[MAX];
935 Float_t y=0., q=0., qmax=0.;
936 Int_t lab[4]={-2,-2,-2,-2};
938 AliITSdigitSSD *d=(AliITSdigitSSD*)digits->UncheckedAt(0);
940 y += d->GetCoord2()*d->GetSignal();
942 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
943 Int_t curr=d->GetCoord2();
944 Int_t flag=d->GetCoord1();
948 for (Int_t s=1; s<smax; s++) {
949 d=(AliITSdigitSSD*)digits->UncheckedAt(s);
950 Int_t strip=d->GetCoord2();
951 if ((strip-curr) > 1 || flag!=d->GetCoord1()) {
955 c[*n].SetLabels(lab);
956 //Split suspiciously big cluster
958 c[*n].SetY(y/q-0.5*nd);
962 Error("FindClustersSSD","Too many 1D clusters !");
965 c[*n].SetY(y/q+0.5*nd);
968 c[*n].SetLabels(lab);
972 Error("FindClustersSSD","Too many 1D clusters !");
977 lab[0]=lab[1]=lab[2]=-2;
978 if (flag!=d->GetCoord1()) { n=&np; c=pos; }
982 y += d->GetCoord2()*d->GetSignal();
984 if (d->GetSignal()>qmax) {
986 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
993 c[*n].SetLabels(lab);
994 //Split suspiciously big cluster
996 c[*n].SetY(y/q-0.5*nd);
1000 Error("FindClustersSSD","Too many 1D clusters !");
1003 c[*n].SetY(y/q+0.5*nd);
1006 c[*n].SetLabels(lab);
1010 Error("FindClustersSSD","Too many 1D clusters !");
1014 FindClustersSSD(neg, nn, pos, np, clusters);
1017 void AliITSclustererV2::FindClustersSSD(AliITSRawStream* input,
1018 TClonesArray** clusters)
1020 //------------------------------------------------------------
1021 // Actual SSD cluster finder for raw data
1022 //------------------------------------------------------------
1023 Int_t nClustersSSD = 0;
1024 const Int_t MAX = 1000;
1025 Ali1Dcluster clusters1D[2][MAX];
1026 Int_t nClusters[2] = {0, 0};
1030 Int_t prevStrip = -1;
1031 Int_t prevFlag = -1;
1033 // read raw data input stream
1035 Bool_t next = input->Next();
1037 // check if a new cluster starts
1038 Int_t strip = input->GetCoord2();
1039 Int_t flag = input->GetCoord1();
1040 if ((!next || input->IsNewModule() ||
1041 (strip-prevStrip > 1) || (flag != prevFlag)) &&
1043 if (nClusters[prevFlag] == MAX) {
1044 Error("FindClustersSSD", "Too many 1D clusters !");
1047 Ali1Dcluster& cluster = clusters1D[prevFlag][nClusters[prevFlag]++];
1050 cluster.SetNd(nDigits);
1052 //Split suspiciously big cluster
1054 cluster.SetY(y/q - 0.5*nDigits);
1055 cluster.SetQ(0.5*q);
1056 if (nClusters[prevFlag] == MAX) {
1057 Error("FindClustersSSD", "Too many 1D clusters !");
1060 Ali1Dcluster& cluster2 = clusters1D[prevFlag][nClusters[prevFlag]++];
1061 cluster2.SetY(y/q + 0.5*nDigits);
1062 cluster2.SetQ(0.5*q);
1063 cluster2.SetNd(nDigits);
1069 if (!next || input->IsNewModule()) {
1070 Int_t iModule = input->GetPrevModuleID();
1072 // when all data from a module was read, search for clusters
1073 if (prevFlag >= 0) {
1074 clusters[iModule] = new TClonesArray("AliITSclusterV2");
1076 FindClustersSSD(&clusters1D[0][0], nClusters[0],
1077 &clusters1D[1][0], nClusters[1], clusters[iModule]);
1078 Int_t nClusters = clusters[iModule]->GetEntriesFast();
1079 nClustersSSD += nClusters;
1083 nClusters[0] = nClusters[1] = 0;
1088 // add digit to current cluster
1089 q += input->GetSignal();
1090 y += strip * input->GetSignal();
1096 Info("FindClustersSSD", "found clusters in ITS SSD: %d", nClustersSSD);
1101 #include "AliITSDetType.h"
1103 #include "AliITSsegmentationSPD.h"
1104 #include "AliITSClusterFinderSPD.h"
1106 #include "AliITSresponseSDD.h"
1107 #include "AliITSsegmentationSDD.h"
1108 #include "AliITSClusterFinderSDD.h"
1110 #include "AliITSsegmentationSSD.h"
1111 #include "AliITSClusterFinderSSD.h"
1114 void AliITSclustererV2::
1115 FindClustersSPD(const TClonesArray *digits, TClonesArray *clusters) {
1116 //------------------------------------------------------------
1117 // Actual SPD cluster finding based on AliITSClusterFinderSPD
1118 //------------------------------------------------------------
1119 static AliITS *its=(AliITS*)gAlice->GetModule("ITS");
1120 static TClonesArray *points=its->RecPoints();
1121 static AliITSsegmentationSPD *seg=
1122 (AliITSsegmentationSPD *)its->DetType(0)->GetSegmentationModel();
1123 static AliITSClusterFinderSPD cf(seg, (TClonesArray*)digits, points);
1125 cf.FindRawClusters(fI);
1126 RecPoints2Clusters(points, fI, clusters);
1127 its->ResetRecPoints();
1131 void AliITSclustererV2::
1132 FindClustersSDD(const TClonesArray *digits, TClonesArray *clusters) {
1133 //------------------------------------------------------------
1134 // Actual SDD cluster finding based on AliITSClusterFinderSDD
1135 //------------------------------------------------------------
1136 static AliITS *its=(AliITS*)gAlice->GetModule("ITS");
1137 static TClonesArray *points=its->RecPoints();
1138 static AliITSresponseSDD *resp=
1139 (AliITSresponseSDD *)its->DetType(1)->GetResponseModel();
1140 static AliITSsegmentationSDD *seg=
1141 (AliITSsegmentationSDD *)its->DetType(1)->GetSegmentationModel();
1142 static AliITSClusterFinderSDD
1143 cf(seg,resp,(TClonesArray*)digits,its->ClustersAddress(1));
1145 cf.FindRawClusters(fI);
1146 Int_t nc=points->GetEntriesFast();
1147 while (nc--) { //To be consistent with the SSD cluster charges
1148 AliITSRecPoint *p=(AliITSRecPoint*)points->UncheckedAt(nc);
1149 p->SetQ(p->GetQ()/12.);
1151 RecPoints2Clusters(points, fI, clusters);
1152 its->ResetClusters(1);
1153 its->ResetRecPoints();
1157 void AliITSclustererV2::
1158 FindClustersSSD(const TClonesArray *digits, TClonesArray *clusters) {
1159 //------------------------------------------------------------
1160 // Actual SSD cluster finding based on AliITSClusterFinderSSD
1161 //------------------------------------------------------------
1162 static AliITS *its=(AliITS*)gAlice->GetModule("ITS");
1163 static TClonesArray *points=its->RecPoints();
1164 static AliITSsegmentationSSD *seg=
1165 (AliITSsegmentationSSD *)its->DetType(2)->GetSegmentationModel();
1166 static AliITSClusterFinderSSD cf(seg,(TClonesArray*)digits);
1168 cf.FindRawClusters(fI);
1169 RecPoints2Clusters(points, fI, clusters);
1170 its->ResetRecPoints();