1 /**************************************************************************
2 * Copyright(c) 2007-2009, 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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
19 // Implementation of the ITS clusterer V2 class //
21 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch //
22 // Last revision: 13-05-09 Enrico Fragiacomo //
23 // enrico.fragiacomo@ts.infn.it //
25 ///////////////////////////////////////////////////////////////////////////
27 #include <Riostream.h>
30 #include "AliITSClusterFinderV2SSD.h"
31 #include "AliITSRecPoint.h"
32 #include "AliITSgeomTGeo.h"
33 #include "AliITSDetTypeRec.h"
34 #include "AliRawReader.h"
35 #include "AliITSRawStreamSSD.h"
36 #include <TClonesArray.h>
37 #include "AliITSdigitSSD.h"
38 #include "AliITSReconstructor.h"
39 #include "AliITSCalibrationSSD.h"
40 #include "AliITSsegmentationSSD.h"
42 Short_t *AliITSClusterFinderV2SSD::fgPairs = 0x0;
43 Int_t AliITSClusterFinderV2SSD::fgPairsSize = 0;
44 const Float_t AliITSClusterFinderV2SSD::fgkThreshold = 5.;
46 const Float_t AliITSClusterFinderV2SSD::fgkCosmic2008StripShifts[16][9] =
47 {{-0.35,-0.35,-0.35,-0.35,-0.35,-0.35,-0.35,-0.35,-0.35}, // DDL 512
48 {-0.35,-0.35,-0.35,-0.35,-0.35,-0.35,-0.35,-0.35,-0.35}, // DDL 513
49 {-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15}, // DDL 514
50 {-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15}, // DDL 515
51 { 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // DDL 516
52 { 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // DDL 517
53 {-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15}, // DDL 518
54 {-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15}, // DDL 519
55 {-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.25,-0.15}, // DDL 520
56 {-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15,-0.15}, // DDL 521
57 {-0.10,-0.10,-0.10,-0.40,-0.40,-0.40,-0.10,-0.10,-0.45}, // DDL 522
58 {-0.10,-0.10,-0.10,-0.35,-0.35,-0.35,-0.10,-0.35,-0.50}, // DDL 523
59 { 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // DDL 524
60 { 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // DDL 525
61 { 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35}, // DDL 526
62 { 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45}}; // DDL 527
64 ClassImp(AliITSClusterFinderV2SSD)
67 AliITSClusterFinderV2SSD::AliITSClusterFinderV2SSD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),
68 fLastSSD1(AliITSgeomTGeo::GetModuleIndex(6,1,1)-1)
74 //______________________________________________________________________
75 AliITSClusterFinderV2SSD::AliITSClusterFinderV2SSD(const AliITSClusterFinderV2SSD &cf) : AliITSClusterFinder(cf), fLastSSD1(cf.fLastSSD1)
80 //______________________________________________________________________
81 AliITSClusterFinderV2SSD& AliITSClusterFinderV2SSD::operator=(const AliITSClusterFinderV2SSD& cf ){
82 // Assignment operator
84 this->~AliITSClusterFinderV2SSD();
85 new(this) AliITSClusterFinderV2SSD(cf);
90 void AliITSClusterFinderV2SSD::FindRawClusters(Int_t mod){
94 FindClustersSSD(fDigits);
98 void AliITSClusterFinderV2SSD::FindClustersSSD(TClonesArray *alldigits) {
99 //------------------------------------------------------------
100 // Actual SSD cluster finder
101 //------------------------------------------------------------
102 Int_t smaxall=alldigits->GetEntriesFast();
103 if (smaxall==0) return;
106 //---------------------------------------
107 // load recoparam and calibration
109 static AliITSRecoParam *repa = NULL;
111 repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
113 repa = AliITSRecoParam::GetHighFluxParam();
114 AliWarning("Using default AliITSRecoParam class");
118 AliITSCalibrationSSD* cal = (AliITSCalibrationSSD*)GetResp(fModule);
121 //---------------------------------------
124 //------------------------------------
125 // fill the digits array with zero-suppression condition
126 // Signal is converted in KeV
129 for (Int_t i=0;i<smaxall; i++){
130 AliITSdigitSSD *d=(AliITSdigitSSD*)alldigits->UncheckedAt(i);
132 if(d->IsSideP()) noise = cal->GetNoiseP(d->GetStripNumber());
133 else noise = cal->GetNoiseN(d->GetStripNumber());
134 if (d->GetSignal()<3.*noise) continue;
136 if(d->IsSideP()) gain = cal->GetGainP(d->GetStripNumber());
137 else gain = cal->GetGainN(d->GetStripNumber());
139 Float_t q=gain*d->GetSignal(); //
140 q=cal->ADCToKeV(q); // converts the charge in KeV from ADC units
141 d->SetSignal(Int_t(q));
145 Int_t smax = digits.GetEntriesFast();
147 //------------------------------------
150 const Int_t kMax=1000;
152 Ali1Dcluster pos[kMax], neg[kMax];
153 Float_t y=0., q=0., qmax=0.;
154 Int_t lab[4]={-2,-2,-2,-2};
158 cout<<"-----------------------------"<<endl;
159 cout<<"this is module "<<fModule;
164 //--------------------------------------------------------
165 // start 1D-clustering from the first digit in the digits array
167 AliITSdigitSSD *d=(AliITSdigitSSD*)digits.UncheckedAt(0);
169 y += d->GetCoord2()*d->GetSignal();
171 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
174 noise = cal->GetNoiseP(d->GetStripNumber());
175 gain = cal->GetGainP(d->GetStripNumber());
178 noise = cal->GetNoiseN(d->GetStripNumber());
179 gain = cal->GetGainN(d->GetStripNumber());
182 noise=cal->ADCToKeV(noise); // converts noise in KeV from ADC units
184 if(qmax>fgkThreshold*noise) flag5=1; // seed for the cluster
187 cout<<d->GetSignal()<<" "<<noise<<" "<<flag5<<" "<<
188 d->GetCoord1()<<" "<<d->GetCoord2()<<endl;
191 Int_t curr=d->GetCoord2();
192 Int_t flag=d->GetCoord1();
194 // Note: the first side which will be processed is supposed to be the
195 // P-side which is neg
198 if(flag) {n=&np; c=pos;} // in case we have only Nstrips (P was bad!)
202 for (Int_t ilab=0;ilab<10;ilab++){
205 milab[0]=d->GetTrack(0); milab[1]=d->GetTrack(1); milab[2]=d->GetTrack(2);
208 //----------------------------------------------------------
209 // search for neighboring digits
211 for (Int_t s=1; s<smax; s++) {
212 d=(AliITSdigitSSD*)digits.UncheckedAt(s);
213 Int_t strip=d->GetCoord2();
215 // if digits is not a neighbour or side did not change
216 // and at least one of the previous digits met the seed condition
217 // then creates a new 1D cluster
218 if ( ( ((strip-curr) > 1) || (flag!=d->GetCoord1()) ) ) {
221 //cout<<"here1"<<endl;
226 c[*n].SetLabels(milab);
228 if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
229 // Note: fUseUnfoldingInClusterFinderSSD=kFALSE by default in RecoParam
231 //Split suspiciously big cluster
233 c[*n].SetY(y/q-0.25*nd);
237 Error("FindClustersSSD","Too many 1D clusters !");
240 c[*n].SetY(y/q+0.25*nd);
243 c[*n].SetLabels(milab);
250 Error("FindClustersSSD","Too many 1D clusters !");
260 lab[0]=lab[1]=lab[2]=-2;
261 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
263 // if side changed from P to N, switch to pos 1D clusters
264 // (if for some reason the side changed from N to P then do the opposite)
265 if (flag!=d->GetCoord1())
266 { if(!flag) {n=&np; c=pos;} else {n=&nn; c=neg;} }
268 } // end create new 1D cluster from previous neighboring digits
270 // continues adding digits to the previous cluster
271 // or start a new one
274 y += d->GetCoord2()*d->GetSignal();
278 noise = cal->GetNoiseP(d->GetStripNumber());
279 gain = cal->GetGainP(d->GetStripNumber());
282 noise = cal->GetNoiseN(d->GetStripNumber());
283 gain = cal->GetGainN(d->GetStripNumber());
286 noise=cal->ADCToKeV(noise); // converts the charge in KeV from ADC units
288 if(d->GetSignal()>fgkThreshold*noise) flag5=1;
291 cout<<d->GetSignal()<<" "<<noise<<" "<<flag5<<" "<<
292 d->GetCoord1()<<" "<<d->GetCoord2()<<endl;
295 if (d->GetSignal()>qmax) {
297 lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
299 for (Int_t ilab=0;ilab<10;ilab++) {
300 if (d->GetTrack(ilab)>=0) AddLabel(milab, (d->GetTrack(ilab)));
305 } // loop over digits, no more digits in the digits array
308 // add the last 1D cluster
311 // cout<<"here2"<<endl;
316 c[*n].SetLabels(lab);
318 if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
320 //Split suspiciously big cluster
322 c[*n].SetY(y/q-0.25*nd);
326 Error("FindClustersSSD","Too many 1D clusters !");
329 c[*n].SetY(y/q+0.25*nd);
332 c[*n].SetLabels(lab);
338 Error("FindClustersSSD","Too many 1D clusters !");
342 } // if flag5 last 1D cluster added
345 //------------------------------------------------------
346 // call FindClustersSSD to pair neg and pos 1D clusters
347 // and create recpoints from the crosses
348 // Note1: neg are Pside and pos are Nside!!
349 // Note2: if there are no Pside digits nn=0 (bad strips!!) (same for Nside)
351 // cout<<nn<<" Pside and "<<np<<" Nside clusters"<<endl;
352 FindClustersSSD(neg, nn, pos, np);
354 //-----------------------------------------------------
359 void AliITSClusterFinderV2SSD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
361 //------------------------------------------------------------
362 // This function creates ITS clusters from raw data
363 //------------------------------------------------------------
365 AliITSRawStreamSSD inputSSD(rawReader);
366 FindClustersSSD(&inputSSD,clusters);
370 void AliITSClusterFinderV2SSD::FindClustersSSD(AliITSRawStreamSSD* input,
371 TClonesArray** clusters)
373 //------------------------------------------------------------
374 // Actual SSD cluster finder for raw data
375 //------------------------------------------------------------
377 static AliITSRecoParam *repa = NULL;
379 repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
381 repa = AliITSRecoParam::GetHighFluxParam();
382 AliWarning("Using default AliITSRecoParam class");
386 Int_t nClustersSSD = 0;
387 const Int_t kMax = 1000;
388 Ali1Dcluster clusters1D[2][kMax];
389 Int_t nClusters[2] = {0, 0};
390 Int_t lab[3]={-2,-2,-2};
396 // Float_t pedestal=0.;
398 AliITSCalibrationSSD* cal=NULL;
400 Int_t matrix[12][1536];
407 Int_t osignal = 65535;
411 // read raw data input stream
414 // reset signal matrix
415 for(Int_t i=0; i<12; i++) { for(Int_t j=0; j<1536; j++) { matrix[i][j] = 65535;} }
417 if((osignal!=65535)&&(ostrip>0)&&(ostrip<1536)) {
419 matrix[oadc][ostrip] = osignal; // recover data from previous occurence of input->Next()
422 // buffer data for ddl=iddl and ad=iad
425 next = input->Next();
426 if((!next)&&(input->flag)) continue;
427 Int_t ddl=input->GetDDL();
428 Int_t ad=input->GetAD();
429 Int_t adc = input->GetADC(); adc = (adc<6)? adc : adc - 2;
430 Int_t strip = input->GetStrip();
431 if(input->GetSideFlag()) strip=1535-strip;
432 Int_t signal = input->GetSignal();
434 if((ddl==iddl)&&(ad==iad)&&(strip>0)&&(strip<1536)) {n++; matrix[adc][strip] = signal;}
435 else {if ((strip<1536) && (strip>0)) {oddl=iddl; oad=iad; oadc = adc; ostrip = strip; osignal=signal; iddl=ddl; iad=ad; break;}}
437 if(!next) {oddl=iddl; oad=iad; oadc = adc; ostrip = strip; osignal=signal; iddl=ddl; iad=ad; break;}
442 if(!next && oddl<0) break;
444 if(n==0) continue; // first occurence
448 if (repa->GetUseCosmicRunShiftsSSD()) { // Special condition for 2007/2008 cosmic data
449 dStrip = fgkCosmic2008StripShifts[oddl][oad-1];
451 if (TMath::Abs(dStrip) > 1.5)
452 AliError(Form("Indexing error ? oddl = %d, dStrip %f\n",oddl,dStrip));
454 for(Int_t iadc=0; iadc<12; iadc++) { // loop over ADC index for ddl=oddl and ad=oad
456 Int_t iimod = (oad - 1) * 12 + iadc;
457 Int_t iModule = AliITSRawStreamSSD::GetModuleNumber(oddl,iimod);
458 if(iModule==-1) continue;
459 cal = (AliITSCalibrationSSD*)GetResp(iModule);
465 for(Int_t istrip=0; istrip<768; istrip++) { // P-side
466 Int_t signal = matrix[iadc][istrip];
467 pedestal = cal->GetPedestalP(istrip);
468 matrix[iadc][istrip]=signal-(Int_t)pedestal;
474 for(Int_t l=0; l<6; l++) {
476 for(Int_t n=20; n<108; n++) cmode+=matrix[iadc][l*128+n];
478 for(Int_t n=0; n<128; n++) matrix[iadc][l*128+n]-=(Int_t)cmode;
484 for(istrip=0; istrip<768; istrip++) { // P-side
486 Int_t signal = TMath::Abs(matrix[iadc][istrip]);
489 noise = cal->GetNoiseP(istrip); if(noise<1.) signal = 65535;
490 if(signal<3*noise) signal = 65535; // in case ZS was not done in hw do it now
492 // if(cal->IsPChannelBad(istrip)) signal=0;
495 gain = cal->GetGainP(istrip);
496 signal = (Int_t) ( signal * gain ); // signal is corrected for gain
497 if(signal>fgkThreshold*noise) flag5=1;
498 signal = (Int_t) cal->ADCToKeV( signal ); // signal is converted in KeV
500 q += signal; // add digit to current cluster
501 y += istrip * signal;
508 if ( (nDigits>0) && flag5 ) {
510 Ali1Dcluster& cluster = clusters1D[0][nClusters[0]++];
512 if(q!=0) cluster.SetY(y/q + dStrip);
513 else cluster.SetY(istrip + dStrip -1);
516 cluster.SetNd(nDigits);
517 cluster.SetLabels(lab);
519 if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
521 //Split suspiciously big cluster
522 if (nDigits > 4&&nDigits < 25) {
523 if(q!=0) cluster.SetY(y/q + dStrip - 0.25*nDigits);
524 else cluster.SetY(istrip-1 + dStrip - 0.25*nDigits);
526 if (nClusters[0] == kMax) {
527 Error("FindClustersSSD", "Too many 1D clusters !");
530 Ali1Dcluster& cluster2 = clusters1D[0][nClusters[0]++];
531 if(q!=0) cluster2.SetY(y/q + dStrip + 0.25*nDigits);
532 else cluster2.SetY(istrip-1 + dStrip + 0.25*nDigits);
533 cluster2.SetQ(0.5*q);
534 cluster2.SetNd(nDigits);
535 cluster2.SetLabels(lab);
546 } // loop over strip on P-side
548 // if last strip does have signal
551 if ( (nDigits>0) && flag5 ) {
553 Ali1Dcluster& cluster = clusters1D[0][nClusters[0]++];
555 if(q!=0) cluster.SetY(y/q + dStrip);
556 else cluster.SetY(istrip - 1 + dStrip);
559 cluster.SetNd(nDigits);
560 cluster.SetLabels(lab);
562 if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
564 //Split suspiciously big cluster
565 if (nDigits > 4&&nDigits < 25) {
566 if(q!=0) cluster.SetY(y/q + dStrip - 0.25*nDigits);
567 else cluster.SetY(istrip-1 + dStrip - 0.25*nDigits);
569 if (nClusters[0] == kMax) {
570 Error("FindClustersSSD", "Too many 1D clusters !");
573 Ali1Dcluster& cluster2 = clusters1D[0][nClusters[0]++];
574 if(q!=0) cluster2.SetY(y/q + dStrip + 0.25*nDigits);
575 else cluster2.SetY(istrip-1 + dStrip + 0.25*nDigits);
576 cluster2.SetQ(0.5*q);
577 cluster2.SetNd(nDigits);
578 cluster2.SetLabels(lab);
590 for(Int_t istrip=768; istrip<1536; istrip++) { // P-side
591 Int_t signal = matrix[iadc][istrip];
592 pedestal = cal->GetPedestalN(1535-istrip);
593 matrix[iadc][istrip]=signal-(Int_t)pedestal;
598 for(Int_t l=6; l<12; l++) {
600 for(Int_t n=20; n<108; n++) cmode+=matrix[iadc][l*128+n];
602 for(Int_t n=0; n<128; n++) matrix[iadc][l*128+n]-=(Int_t)cmode;
609 for(Int_t iistrip=768; iistrip<1536; iistrip++) { // N-side
611 Int_t signal = TMath::Abs(matrix[iadc][iistrip]);
612 strip = 1535-iistrip;
615 noise = cal->GetNoiseN(strip); if(noise<1.) signal=65535;
617 // if(cal->IsNChannelBad(strip)) signal=0;
619 if(signal<3*noise) signal = 65535; // in case ZS was not done in hw do it now
622 gain = cal->GetGainN(strip);
623 signal = (Int_t) ( signal * gain); // signal is corrected for gain
624 if(signal>fgkThreshold*noise) flag5=1;
625 signal = (Int_t) cal->ADCToKeV( signal ); // signal is converted in KeV
627 // add digit to current cluster
636 if ( (nDigits>0) && flag5 ) {
638 Ali1Dcluster& cluster = clusters1D[1][nClusters[1]++];
640 if(q!=0) cluster.SetY(y/q - dStrip);
641 else cluster.SetY(strip+1 - dStrip);
644 cluster.SetNd(nDigits);
645 cluster.SetLabels(lab);
647 if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
649 //Split suspiciously big cluster
650 if (nDigits > 4&&nDigits < 25) {
651 cluster.SetY(y/q - dStrip - 0.25*nDigits);
653 if (nClusters[1] == kMax) {
654 Error("FindClustersSSD", "Too many 1D clusters !");
657 Ali1Dcluster& cluster2 = clusters1D[1][nClusters[1]++];
658 cluster2.SetY(y/q - dStrip + 0.25*nDigits);
659 cluster2.SetQ(0.5*q);
660 cluster2.SetNd(nDigits);
661 cluster2.SetLabels(lab);
672 } // loop over strips on N-side
676 if ( (nDigits>0) && flag5 ) {
678 Ali1Dcluster& cluster = clusters1D[1][nClusters[1]++];
680 if(q!=0) cluster.SetY(y/q - dStrip);
681 else cluster.SetY(strip - dStrip + 1);
684 cluster.SetNd(nDigits);
685 cluster.SetLabels(lab);
687 if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
689 //Split suspiciously big cluster
690 if (nDigits > 4&&nDigits < 25) {
691 if(q!=0) cluster.SetY(y/q - dStrip - 0.25*nDigits);
692 else cluster.SetY(strip+1 - dStrip - 0.25*nDigits);
694 if (nClusters[1] == kMax) {
695 Error("FindClustersSSD", "Too many 1D clusters !");
698 Ali1Dcluster& cluster2 = clusters1D[1][nClusters[1]++];
699 if(q!=0) cluster2.SetY(y/q - dStrip + 0.25*nDigits);
700 else cluster2.SetY(strip+1 - dStrip + 0.25*nDigits);
701 cluster2.SetQ(0.5*q);
702 cluster2.SetNd(nDigits);
703 cluster2.SetLabels(lab);
715 if((nClusters[0])&&(nClusters[1])) {
717 clusters[iModule] = new TClonesArray("AliITSRecPoint");
719 FindClustersSSD(&clusters1D[0][0], nClusters[0],
720 &clusters1D[1][0], nClusters[1], clusters[iModule]);
721 Int_t nClustersn = clusters[iModule]->GetEntriesFast();
722 nClustersSSD += nClustersn;
725 nClusters[0] = nClusters[1] = 0;
734 Info("FindClustersSSD", "found clusters in ITS SSD: %d", nClustersSSD);
737 void AliITSClusterFinderV2SSD::
738 FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
739 Ali1Dcluster* pos, Int_t np,
740 TClonesArray *clusters) {
741 //------------------------------------------------------------
742 // Actual SSD cluster finder
743 //------------------------------------------------------------
745 const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
747 //---------------------------------------
750 static AliITSRecoParam *repa = NULL;
752 repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
754 repa = AliITSRecoParam::GetHighFluxParam();
755 AliWarning("Using default AliITSRecoParam class");
759 TClonesArray &cl=*clusters;
761 AliITSsegmentationSSD *seg = dynamic_cast<AliITSsegmentationSSD*>(fDetTypeRec->GetSegmentationModel(2));
762 if (fModule>fLastSSD1)
767 Float_t hwSSD = seg->Dx()*1e-4/2;
768 Float_t hlSSD = seg->Dz()*1e-4/2;
770 Int_t idet=fNdet[fModule];
774 Int_t *cnegative = new Int_t[np];
775 Int_t *cused1 = new Int_t[np];
776 Int_t *negativepair = new Int_t[10*np];
777 Int_t *cpositive = new Int_t[nn];
778 Int_t *cused2 = new Int_t[nn];
779 Int_t *positivepair = new Int_t[10*nn];
780 for (Int_t i=0;i<np;i++) {cnegative[i]=0; cused1[i]=0;}
781 for (Int_t i=0;i<nn;i++) {cpositive[i]=0; cused2[i]=0;}
782 for (Int_t i=0;i<10*np;i++) {negativepair[i]=0;}
783 for (Int_t i=0;i<10*nn;i++) {positivepair[i]=0;}
785 if ((np*nn) > fgPairsSize) {
787 if (fgPairs) delete [] fgPairs;
788 fgPairsSize = 4*np*nn;
789 fgPairs = new Short_t[fgPairsSize];
791 memset(fgPairs,0,sizeof(Short_t)*np*nn);
794 // find available pairs
796 for (Int_t i=0; i<np; i++) {
797 Float_t yp=pos[i].GetY();
798 if ( (pos[i].GetQ()>0) && (pos[i].GetQ()<3) ) continue;
799 for (Int_t j=0; j<nn; j++) {
800 if ( (neg[j].GetQ()>0) && (neg[j].GetQ()<3) ) continue;
801 Float_t yn=neg[j].GetY();
804 seg->GetPadCxz(yn, yp, xt, zt);
805 //cout<<yn<<" "<<yp<<" "<<xt<<" "<<zt<<endl;
807 if (TMath::Abs(xt)<hwSSD+0.01)
808 if (TMath::Abs(zt)<hlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
809 Int_t in = i*10+cnegative[i];
810 Int_t ip = j*10+cpositive[j];
811 if ((in < 10*np) && (ip < 10*nn)) {
812 negativepair[in] =j; //index
814 cnegative[i]++; //counters
819 AliError(Form("Index out of range: ip=%d, in=%d",ip,in));
825 // try to recover points out of but close to the module boundaries
827 for (Int_t i=0; i<np; i++) {
828 Float_t yp=pos[i].GetY();
829 if ( (pos[i].GetQ()>0) && (pos[i].GetQ()<3) ) continue;
830 for (Int_t j=0; j<nn; j++) {
831 if ( (neg[j].GetQ()>0) && (neg[j].GetQ()<3) ) continue;
832 // if both 1Dclusters have an other cross continue
833 if (cpositive[j]&&cnegative[i]) continue;
834 Float_t yn=neg[j].GetY();
837 seg->GetPadCxz(yn, yp, xt, zt);
839 if (TMath::Abs(xt)<hwSSD+0.1)
840 if (TMath::Abs(zt)<hlSSD+0.15) {
841 // tag 1Dcluster (eventually will produce low quality recpoint)
842 if (cnegative[i]==0) pos[i].SetNd(100); // not available pair
843 if (cpositive[j]==0) neg[j].SetNd(100); // not available pair
844 Int_t in = i*10+cnegative[i];
845 Int_t ip = j*10+cpositive[j];
846 if ((in < 10*np) && (ip < 10*nn)) {
847 negativepair[in] =j; //index
849 cnegative[i]++; //counters
854 AliError(Form("Index out of range: ip=%d, in=%d",ip,in));
865 if(repa->GetUseChargeMatchingInClusterFinderSSD()==kTRUE) {
871 for (Int_t ip=0;ip<np;ip++){
872 Float_t xbest=1000,zbest=1000,qbest=0;
874 // select gold clusters
875 if ( (cnegative[ip]==1) && cpositive[negativepair[10*ip]]==1){
876 Float_t yp=pos[ip].GetY();
877 Int_t j = negativepair[10*ip];
879 if( (pos[ip].GetQ()==0) && (neg[j].GetQ() ==0) ) {
880 // both bad, hence continue;
881 // mark both as used (to avoid recover at the end)
887 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
888 //cout<<"ratio="<<ratio<<endl;
890 // charge matching (note that if posQ or negQ is 0 -> ratio=1 and the following condition is met
891 if (TMath::Abs(ratio)>0.2) continue; // note: 0.2=3xsigma_ratio calculated in cosmics tests
894 Float_t yn=neg[j].GetY();
897 seg->GetPadCxz(yn, yp, xt, zt);
902 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
903 if( (pos[ip].GetQ()==0)||(neg[j].GetQ()==0)) qbest*=2; // in case of bad strips on one side keep all charge from the other one
906 Double_t loc[3]={xbest,0.,zbest},trk[3]={0.,0.,0.};
907 mT2L->MasterToLocal(loc,trk);
912 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
913 for (Int_t ilab=0;ilab<3;ilab++){
914 milab[ilab] = pos[ip].GetLabel(ilab);
915 milab[ilab+3] = neg[j].GetLabel(ilab);
919 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
920 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fModule]};
922 lp[2]=0.0022*0.0022; //SigmaY2
923 lp[3]=0.110*0.110; //SigmaZ2
924 // out-of-diagonal element of covariance matrix
925 if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
926 else if ( (info[0]>1) && (info[1]>1) ) {
927 lp[2]=0.0016*0.0016; //SigmaY2
928 lp[3]=0.08*0.08; //SigmaZ2
933 if (info[0]==1) { lp[5]=-0.00014;}
934 else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
937 AliITSRecPoint * cl2;
939 if(clusters){ // Note clusters != 0 when method is called for rawdata
942 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
944 cl2->SetChargeRatio(ratio);
948 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
953 if(pos[ip].GetQ()==0) cl2->SetType(3);
954 if(neg[j].GetQ()==0) cl2->SetType(4);
960 else{ // Note clusters == 0 when method is called for digits
962 cl2 = new AliITSRecPoint(milab,lp,info);
964 cl2->SetChargeRatio(ratio);
968 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
973 if(pos[ip].GetQ()==0) cl2->SetType(3);
974 if(neg[j].GetQ()==0) cl2->SetType(4);
979 fDetTypeRec->AddRecPoint(*cl2);
985 for (Int_t ip=0;ip<np;ip++){
986 Float_t xbest=1000,zbest=1000,qbest=0;
989 // select "silber" cluster
990 if ( cnegative[ip]==1 && cpositive[negativepair[10*ip]]==2){
991 Int_t in = negativepair[10*ip];
992 Int_t ip2 = positivepair[10*in];
993 if (ip2==ip) ip2 = positivepair[10*in+1];
994 Float_t pcharge = pos[ip].GetQ()+pos[ip2].GetQ();
998 ratio = (pcharge-neg[in].GetQ())/(pcharge+neg[in].GetQ());
999 if ( (TMath::Abs(ratio)<0.2) && (pcharge!=0) ) {
1000 //if ( (TMath::Abs(pcharge-neg[in].GetQ())<30) && (pcharge!=0) ) { //
1004 if ( (fgPairs[ip*nn+in]==100)&&(pos[ip].GetQ() ) ) { //
1006 Float_t yp=pos[ip].GetY();
1007 Float_t yn=neg[in].GetY();
1010 seg->GetPadCxz(yn, yp, xt, zt);
1014 qbest =pos[ip].GetQ();
1015 Double_t loc[3]={xbest,0.,zbest},trk[3]={0.,0.,0.};
1016 mT2L->MasterToLocal(loc,trk);
1021 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1022 for (Int_t ilab=0;ilab<3;ilab++){
1023 milab[ilab] = pos[ip].GetLabel(ilab);
1024 milab[ilab+3] = neg[in].GetLabel(ilab);
1027 CheckLabels2(milab);
1028 ratio = (pos[ip].GetQ()-neg[in].GetQ())/(pos[ip].GetQ()+neg[in].GetQ());
1029 milab[3]=(((ip<<10) + in)<<10) + idet; // pos|neg|det
1030 Int_t info[3] = {pos[ip].GetNd(),neg[in].GetNd(),fNlayer[fModule]};
1032 lp[2]=0.0022*0.0022; //SigmaY2
1033 lp[3]=0.110*0.110; //SigmaZ2
1034 // out-of-diagonal element of covariance matrix
1035 if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
1036 else if ( (info[0]>1) && (info[1]>1) ) {
1037 lp[2]=0.0016*0.0016; //SigmaY2
1038 lp[3]=0.08*0.08; //SigmaZ2
1043 if (info[0]==1) { lp[5]=-0.00014;}
1044 else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
1047 AliITSRecPoint * cl2;
1050 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1051 cl2->SetChargeRatio(ratio);
1053 fgPairs[ip*nn+in] = 5;
1054 if ((pos[ip].GetNd()+neg[in].GetNd())>6){ //multi cluster
1056 fgPairs[ip*nn+in] = 6;
1060 cl2 = new AliITSRecPoint(milab,lp,info);
1061 cl2->SetChargeRatio(ratio);
1063 fgPairs[ip*nn+in] = 5;
1064 if ((pos[ip].GetNd()+neg[in].GetNd())>6){ //multi cluster
1066 fgPairs[ip*nn+in] = 6;
1069 fDetTypeRec->AddRecPoint(*cl2);
1078 // if (!(cused1[ip2] || cused2[in])){ //
1079 if ( (fgPairs[ip2*nn+in]==100) && (pos[ip2].GetQ()) ) {
1081 Float_t yp=pos[ip2].GetY();
1082 Float_t yn=neg[in].GetY();
1085 seg->GetPadCxz(yn, yp, xt, zt);
1089 qbest =pos[ip2].GetQ();
1091 Double_t loc[3]={xbest,0.,zbest},trk[3]={0.,0.,0.};
1092 mT2L->MasterToLocal(loc,trk);
1097 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1098 for (Int_t ilab=0;ilab<3;ilab++){
1099 milab[ilab] = pos[ip2].GetLabel(ilab);
1100 milab[ilab+3] = neg[in].GetLabel(ilab);
1103 CheckLabels2(milab);
1104 ratio = (pos[ip2].GetQ()-neg[in].GetQ())/(pos[ip2].GetQ()+neg[in].GetQ());
1105 milab[3]=(((ip2<<10) + in)<<10) + idet; // pos|neg|det
1106 Int_t info[3] = {pos[ip2].GetNd(),neg[in].GetNd(),fNlayer[fModule]};
1108 lp[2]=0.0022*0.0022; //SigmaY2
1109 lp[3]=0.110*0.110; //SigmaZ2
1110 // out-of-diagonal element of covariance matrix
1111 if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
1112 else if ( (info[0]>1) && (info[1]>1) ) {
1113 lp[2]=0.0016*0.0016; //SigmaY2
1114 lp[3]=0.08*0.08; //SigmaZ2
1119 if (info[0]==1) { lp[5]=-0.00014;}
1120 else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
1123 AliITSRecPoint * cl2;
1125 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1127 cl2->SetChargeRatio(ratio);
1129 fgPairs[ip2*nn+in] =5;
1130 if ((pos[ip2].GetNd()+neg[in].GetNd())>6){ //multi cluster
1132 fgPairs[ip2*nn+in] =6;
1136 cl2 = new AliITSRecPoint(milab,lp,info);
1137 cl2->SetChargeRatio(ratio);
1139 fgPairs[ip2*nn+in] =5;
1140 if ((pos[ip2].GetNd()+neg[in].GetNd())>6){ //multi cluster
1142 fgPairs[ip2*nn+in] =6;
1145 fDetTypeRec->AddRecPoint(*cl2);
1154 } // charge matching condition
1156 } // 2 Pside cross 1 Nside
1157 } // loop over Pside clusters
1162 for (Int_t jn=0;jn<nn;jn++){
1163 if (cused2[jn]) continue;
1164 Float_t xbest=1000,zbest=1000,qbest=0;
1165 // select "silber" cluster
1166 if ( cpositive[jn]==1 && cnegative[positivepair[10*jn]]==2){
1167 Int_t ip = positivepair[10*jn];
1168 Int_t jn2 = negativepair[10*ip];
1169 if (jn2==jn) jn2 = negativepair[10*ip+1];
1170 Float_t pcharge = neg[jn].GetQ()+neg[jn2].GetQ();
1174 ratio = (pcharge-pos[ip].GetQ())/(pcharge+pos[ip].GetQ());
1175 if ( (TMath::Abs(ratio)<0.2) && (pcharge!=0) ) {
1178 if ( (TMath::Abs(pcharge-pos[ip].GetQ())<30) && // charge matching
1179 (pcharge!=0) ) { // reject combinations of bad strips
1185 // if (!(cused1[ip]||cused2[jn])){
1186 if ( (fgPairs[ip*nn+jn]==100) && (neg[jn].GetQ()) ) { //
1188 Float_t yn=neg[jn].GetY();
1189 Float_t yp=pos[ip].GetY();
1192 seg->GetPadCxz(yn, yp, xt, zt);
1196 qbest =neg[jn].GetQ();
1199 Double_t loc[3]={xbest,0.,zbest},trk[3]={0.,0.,0.};
1200 mT2L->MasterToLocal(loc,trk);
1206 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1207 for (Int_t ilab=0;ilab<3;ilab++){
1208 milab[ilab] = pos[ip].GetLabel(ilab);
1209 milab[ilab+3] = neg[jn].GetLabel(ilab);
1212 CheckLabels2(milab);
1213 ratio = (pos[ip].GetQ()-neg[jn].GetQ())/(pos[ip].GetQ()+neg[jn].GetQ());
1214 milab[3]=(((ip<<10) + jn)<<10) + idet; // pos|neg|det
1215 Int_t info[3] = {pos[ip].GetNd(),neg[jn].GetNd(),fNlayer[fModule]};
1217 lp[2]=0.0022*0.0022; //SigmaY2
1218 lp[3]=0.110*0.110; //SigmaZ2
1219 // out-of-diagonal element of covariance matrix
1220 if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
1221 else if ( (info[0]>1) && (info[1]>1) ) {
1222 lp[2]=0.0016*0.0016; //SigmaY2
1223 lp[3]=0.08*0.08; //SigmaZ2
1228 if (info[0]==1) { lp[5]=-0.00014;}
1229 else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
1232 AliITSRecPoint * cl2;
1234 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1236 cl2->SetChargeRatio(ratio);
1238 fgPairs[ip*nn+jn] =7;
1239 if ((pos[ip].GetNd()+neg[jn].GetNd())>6){ //multi cluster
1241 fgPairs[ip*nn+jn]=8;
1246 cl2 = new AliITSRecPoint(milab,lp,info);
1247 cl2->SetChargeRatio(ratio);
1249 fgPairs[ip*nn+jn] =7;
1250 if ((pos[ip].GetNd()+neg[jn].GetNd())>6){ //multi cluster
1252 fgPairs[ip*nn+jn]=8;
1255 fDetTypeRec->AddRecPoint(*cl2);
1261 // if (!(cused1[ip]||cused2[jn2])){
1262 if ( (fgPairs[ip*nn+jn2]==100)&&(neg[jn2].GetQ() ) ) { //
1264 Float_t yn=neg[jn2].GetY();
1265 Double_t yp=pos[ip].GetY();
1268 seg->GetPadCxz(yn, yp, xt, zt);
1272 qbest =neg[jn2].GetQ();
1275 Double_t loc[3]={xbest,0.,zbest},trk[3]={0.,0.,0.};
1276 mT2L->MasterToLocal(loc,trk);
1282 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1283 for (Int_t ilab=0;ilab<3;ilab++){
1284 milab[ilab] = pos[ip].GetLabel(ilab);
1285 milab[ilab+3] = neg[jn2].GetLabel(ilab);
1288 CheckLabels2(milab);
1289 ratio = (pos[ip].GetQ()-neg[jn2].GetQ())/(pos[ip].GetQ()+neg[jn2].GetQ());
1290 milab[3]=(((ip<<10) + jn2)<<10) + idet; // pos|neg|det
1291 Int_t info[3] = {pos[ip].GetNd(),neg[jn2].GetNd(),fNlayer[fModule]};
1293 lp[2]=0.0022*0.0022; //SigmaY2
1294 lp[3]=0.110*0.110; //SigmaZ2
1295 // out-of-diagonal element of covariance matrix
1296 if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
1297 else if ( (info[0]>1) && (info[1]>1) ) {
1298 lp[2]=0.0016*0.0016; //SigmaY2
1299 lp[3]=0.08*0.08; //SigmaZ2
1304 if (info[0]==1) { lp[5]=-0.00014;}
1305 else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
1308 AliITSRecPoint * cl2;
1310 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1313 cl2->SetChargeRatio(ratio);
1314 fgPairs[ip*nn+jn2]=7;
1316 if ((pos[ip].GetNd()+neg[jn2].GetNd())>6){ //multi cluster
1318 fgPairs[ip*nn+jn2]=8;
1323 cl2 = new AliITSRecPoint(milab,lp,info);
1324 cl2->SetChargeRatio(ratio);
1325 fgPairs[ip*nn+jn2]=7;
1327 if ((pos[ip].GetNd()+neg[jn2].GetNd())>6){ //multi cluster
1329 fgPairs[ip*nn+jn2]=8;
1332 fDetTypeRec->AddRecPoint(*cl2);
1341 } // charge matching condition
1343 } // 2 Nside cross 1 Pside
1344 } // loop over Pside clusters
1348 for (Int_t ip=0;ip<np;ip++){
1350 if(cused1[ip]) continue;
1353 Float_t xbest=1000,zbest=1000,qbest=0;
1357 if ( (cnegative[ip]==2) && cpositive[negativepair[10*ip]]==2){
1358 Float_t minchargediff =4.;
1359 Float_t minchargeratio =0.2;
1362 for (Int_t di=0;di<cnegative[ip];di++){
1363 Int_t jc = negativepair[ip*10+di];
1364 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1365 ratio = (pos[ip].GetQ()-neg[jc].GetQ())/(pos[ip].GetQ()+neg[jc].GetQ());
1366 //if (TMath::Abs(chargedif)<minchargediff){
1367 if (TMath::Abs(ratio)<0.2){
1369 minchargediff = TMath::Abs(chargedif);
1370 minchargeratio = TMath::Abs(ratio);
1373 if (j<0) continue; // not proper cluster
1377 for (Int_t di=0;di<cnegative[ip];di++){
1378 Int_t jc = negativepair[ip*10+di];
1379 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1380 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1382 if (count>1) continue; // more than one "proper" cluster for positive
1386 for (Int_t dj=0;dj<cpositive[j];dj++){
1387 Int_t ic = positivepair[j*10+dj];
1388 Float_t chargedif = pos[ic].GetQ()-neg[j].GetQ();
1389 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1391 if (count>1) continue; // more than one "proper" cluster for negative
1396 for (Int_t dj=0;dj<cnegative[jp];dj++){
1397 Int_t ic = positivepair[jp*10+dj];
1398 Float_t chargedif = pos[ic].GetQ()-neg[jp].GetQ();
1399 if (TMath::Abs(chargedif)<minchargediff+4.) count++;
1401 if (count>1) continue;
1402 if (fgPairs[ip*nn+j]<100) continue;
1407 //almost gold clusters
1408 Float_t yp=pos[ip].GetY();
1409 Float_t yn=neg[j].GetY();
1411 seg->GetPadCxz(yn, yp, xt, zt);
1413 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1415 Double_t loc[3]={xbest,0.,zbest},trk[3]={0.,0.,0.};
1416 mT2L->MasterToLocal(loc,trk);
1421 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1422 for (Int_t ilab=0;ilab<3;ilab++){
1423 milab[ilab] = pos[ip].GetLabel(ilab);
1424 milab[ilab+3] = neg[j].GetLabel(ilab);
1427 CheckLabels2(milab);
1428 if ((neg[j].GetQ()==0)&&(pos[ip].GetQ()==0)) continue; // reject crosses of bad strips!!
1429 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1430 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1431 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fModule]};
1433 lp[2]=0.0022*0.0022; //SigmaY2
1434 lp[3]=0.110*0.110; //SigmaZ2
1435 // out-of-diagonal element of covariance matrix
1436 if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
1437 else if ( (info[0]>1) && (info[1]>1) ) {
1438 lp[2]=0.0016*0.0016; //SigmaY2
1439 lp[3]=0.08*0.08; //SigmaZ2
1444 if (info[0]==1) { lp[5]=-0.00014;}
1445 else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
1448 AliITSRecPoint * cl2;
1450 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1452 cl2->SetChargeRatio(ratio);
1454 fgPairs[ip*nn+j]=10;
1455 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1457 fgPairs[ip*nn+j]=11;
1463 cl2 = new AliITSRecPoint(milab,lp,info);
1464 cl2->SetChargeRatio(ratio);
1466 fgPairs[ip*nn+j]=10;
1467 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1469 fgPairs[ip*nn+j]=11;
1474 fDetTypeRec->AddRecPoint(*cl2);
1479 } // loop over Pside 1Dclusters
1483 for (Int_t ip=0;ip<np;ip++){
1485 if(cused1[ip]) continue;
1488 Float_t xbest=1000,zbest=1000,qbest=0;
1490 // manyxmany clusters
1492 if ( (cnegative[ip]<5) && cpositive[negativepair[10*ip]]<5){
1493 Float_t minchargediff =4.;
1495 for (Int_t di=0;di<cnegative[ip];di++){
1496 Int_t jc = negativepair[ip*10+di];
1497 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1498 if (TMath::Abs(chargedif)<minchargediff){
1500 minchargediff = TMath::Abs(chargedif);
1503 if (j<0) continue; // not proper cluster
1506 for (Int_t di=0;di<cnegative[ip];di++){
1507 Int_t jc = negativepair[ip*10+di];
1508 Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1509 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1511 if (count>1) continue; // more than one "proper" cluster for positive
1515 for (Int_t dj=0;dj<cpositive[j];dj++){
1516 Int_t ic = positivepair[j*10+dj];
1517 Float_t chargedif = pos[ic].GetQ()-neg[j].GetQ();
1518 if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1520 if (count>1) continue; // more than one "proper" cluster for negative
1525 for (Int_t dj=0;dj<cnegative[jp];dj++){
1526 Int_t ic = positivepair[jp*10+dj];
1527 Float_t chargedif = pos[ic].GetQ()-neg[jp].GetQ();
1528 if (TMath::Abs(chargedif)<minchargediff+4.) count++;
1530 if (count>1) continue;
1531 if (fgPairs[ip*nn+j]<100) continue;
1534 //almost gold clusters
1535 Float_t yp=pos[ip].GetY();
1536 Float_t yn=neg[j].GetY();
1540 seg->GetPadCxz(yn, yp, xt, zt);
1544 qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1547 Double_t loc[3]={xbest,0.,zbest},trk[3]={0.,0.,0.};
1548 mT2L->MasterToLocal(loc,trk);
1553 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1554 for (Int_t ilab=0;ilab<3;ilab++){
1555 milab[ilab] = pos[ip].GetLabel(ilab);
1556 milab[ilab+3] = neg[j].GetLabel(ilab);
1559 CheckLabels2(milab);
1560 if ((neg[j].GetQ()==0)&&(pos[ip].GetQ()==0)) continue; // reject crosses of bad strips!!
1561 ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1562 milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1563 Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fModule]};
1565 lp[2]=0.0022*0.0022; //SigmaY2
1566 lp[3]=0.110*0.110; //SigmaZ2
1567 // out-of-diagonal element of covariance matrix
1568 if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
1569 else if ( (info[0]>1) && (info[1]>1) ) {
1570 lp[2]=0.0016*0.0016; //SigmaY2
1571 lp[3]=0.08*0.08; //SigmaZ2
1576 if (info[0]==1) { lp[5]=-0.00014;}
1577 else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
1580 AliITSRecPoint * cl2;
1582 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1584 cl2->SetChargeRatio(ratio);
1586 fgPairs[ip*nn+j]=12;
1587 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1589 fgPairs[ip*nn+j]=13;
1595 cl2 = new AliITSRecPoint(milab,lp,info);
1596 cl2->SetChargeRatio(ratio);
1598 fgPairs[ip*nn+j]=12;
1599 if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1601 fgPairs[ip*nn+j]=13;
1606 fDetTypeRec->AddRecPoint(*cl2);
1611 } // loop over Pside 1Dclusters
1613 } // use charge matching
1616 // recover all the other crosses
1618 for (Int_t i=0; i<np; i++) {
1619 Float_t xbest=1000,zbest=1000,qbest=0;
1620 Float_t yp=pos[i].GetY();
1621 if ((pos[i].GetQ()>0)&&(pos[i].GetQ()<3)) continue;
1622 for (Int_t j=0; j<nn; j++) {
1623 // for (Int_t di = 0;di<cpositive[i];di++){
1624 // Int_t j = negativepair[10*i+di];
1625 if ((neg[j].GetQ()>0)&&(neg[j].GetQ()<3)) continue;
1627 if ((neg[j].GetQ()==0)&&(pos[i].GetQ()==0)) continue; // reject crosses of bad strips!!
1629 if (cused2[j]||cused1[i]) continue;
1630 if (fgPairs[i*nn+j]>0 &&fgPairs[i*nn+j]<100) continue;
1631 ratio = (pos[i].GetQ()-neg[j].GetQ())/(pos[i].GetQ()+neg[j].GetQ());
1632 Float_t yn=neg[j].GetY();
1635 seg->GetPadCxz(yn, yp, xt, zt);
1637 if (TMath::Abs(xt)<hwSSD+0.01)
1638 if (TMath::Abs(zt)<hlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1641 qbest=0.5*(pos[i].GetQ()+neg[j].GetQ());
1644 Double_t loc[3]={xbest,0.,zbest},trk[3]={0.,0.,0.};
1645 mT2L->MasterToLocal(loc,trk);
1650 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1651 for (Int_t ilab=0;ilab<3;ilab++){
1652 milab[ilab] = pos[i].GetLabel(ilab);
1653 milab[ilab+3] = neg[j].GetLabel(ilab);
1656 CheckLabels2(milab);
1657 milab[3]=(((i<<10) + j)<<10) + idet; // pos|neg|det
1658 Int_t info[3] = {pos[i].GetNd(),neg[j].GetNd(),fNlayer[fModule]};
1660 lp[2]=0.0022*0.0022; //SigmaY2
1661 lp[3]=0.110*0.110; //SigmaZ2
1662 // out-of-diagonal element of covariance matrix
1663 if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
1664 else if ( (info[0]>1) && (info[1]>1) ) {
1665 lp[2]=0.0016*0.0016; //SigmaY2
1666 lp[3]=0.08*0.08; //SigmaZ2
1671 if (info[0]==1) { lp[5]=-0.00014;}
1672 else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
1675 AliITSRecPoint * cl2;
1677 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1679 cl2->SetChargeRatio(ratio);
1680 cl2->SetType(100+cpositive[j]+cnegative[i]);
1682 if(pos[i].GetQ()==0) cl2->SetType(200+cpositive[j]+cnegative[i]);
1683 if(neg[j].GetQ()==0) cl2->SetType(300+cpositive[j]+cnegative[i]);
1687 cl2 = new AliITSRecPoint(milab,lp,info);
1688 cl2->SetChargeRatio(ratio);
1689 cl2->SetType(100+cpositive[j]+cnegative[i]);
1691 if(pos[i].GetQ()==0) cl2->SetType(200+cpositive[j]+cnegative[i]);
1692 if(neg[j].GetQ()==0) cl2->SetType(300+cpositive[j]+cnegative[i]);
1694 fDetTypeRec->AddRecPoint(*cl2);
1703 if(repa->GetUseBadChannelsInClusterFinderSSD()==kTRUE) {
1705 //---------------------------------------------------------
1706 // recover crosses of good 1D clusters with bad strips on the other side
1707 // Note1: at first iteration skip modules with a bad side (or almost), (would produce too many fake!)
1708 // Note2: for modules with a bad side see below
1710 AliITSCalibrationSSD* cal = (AliITSCalibrationSSD*)GetResp(fModule);
1711 Int_t countPbad=0, countNbad=0;
1712 for(Int_t ib=0; ib<768; ib++) {
1713 if(cal->IsPChannelBad(ib)) countPbad++;
1714 if(cal->IsNChannelBad(ib)) countNbad++;
1716 // AliInfo(Form("module %d has %d P- and %d N-bad strips",fModule,countPbad,countNbad));
1718 if( (countPbad<100) && (countNbad<100) ) { // no bad side!!
1720 for (Int_t i=0; i<np; i++) { // loop over Nside 1Dclusters with no crosses
1721 if(cnegative[i]) continue; // if intersecting Pside clusters continue;
1723 // for(Int_t ib=0; ib<768; ib++) { // loop over all Pstrips
1724 for(Int_t ib=15; ib<753; ib++) { // loop over all Pstrips
1726 if(cal->IsPChannelBad(ib)) { // check if strips is bad
1727 Float_t yN=pos[i].GetY();
1729 seg->GetPadCxz(1.*ib, yN, xt, zt);
1732 // bad Pstrip is crossing the Nside 1Dcluster -> create recpoint
1734 if ( (TMath::Abs(xt)<hwSSD+0.01) && (TMath::Abs(zt)<hlSSD+0.01) ) {
1735 Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
1736 mT2L->MasterToLocal(loc,trk);
1739 lp[4]=pos[i].GetQ(); //Q
1740 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1741 for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = pos[i].GetLabel(ilab);
1742 CheckLabels2(milab);
1743 milab[3]=( (i<<10) << 10 ) + idet; // pos|neg|det
1744 Int_t info[3] = {pos[i].GetNd(),0,fNlayer[fModule]};
1746 // out-of-diagonal element of covariance matrix
1747 if (info[0]==1) lp[5]=0.0065;
1750 lp[2]=0.0022*0.0022; //SigmaY2
1751 lp[3]=0.110*0.110; //SigmaZ2
1752 lp[5]=-0.00012; // out-of-diagonal element of covariance matrix
1754 AliITSRecPoint * cl2;
1756 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1757 cl2->SetChargeRatio(1.);
1761 cl2 = new AliITSRecPoint(milab,lp,info);
1762 cl2->SetChargeRatio(1.);
1764 fDetTypeRec->AddRecPoint(*cl2);
1767 } // cross is within the detector
1773 } // end loop over Pstrips
1775 } // end loop over Nside 1D clusters
1777 for (Int_t j=0; j<nn; j++) { // loop over Pside 1D clusters with no crosses
1778 if(cpositive[j]) continue;
1780 // for(Int_t ib=0; ib<768; ib++) { // loop over all Nside strips
1781 for(Int_t ib=15; ib<753; ib++) { // loop over all Nside strips
1783 if(cal->IsNChannelBad(ib)) { // check if strip is bad
1784 Float_t yP=neg[j].GetY();
1786 seg->GetPadCxz(yP, 1.*ib, xt, zt);
1789 // bad Nstrip is crossing the Pside 1Dcluster -> create recpoint
1791 if ( (TMath::Abs(xt)<hwSSD+0.01) && (TMath::Abs(zt)<hlSSD+0.01) ) {
1792 Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
1793 mT2L->MasterToLocal(loc,trk);
1796 lp[4]=neg[j].GetQ(); //Q
1797 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1798 for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = neg[j].GetLabel(ilab);
1799 CheckLabels2(milab);
1800 milab[3]=( j << 10 ) + idet; // pos|neg|det
1801 Int_t info[3]={0,(Int_t)neg[j].GetNd(),fNlayer[fModule]};
1803 lp[2]=0.0022*0.0022; //SigmaY2
1804 lp[3]=0.110*0.110; //SigmaZ2
1805 lp[5]=-0.00012; // out-of-diagonal element of covariance matrix
1807 AliITSRecPoint * cl2;
1809 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1810 cl2->SetChargeRatio(1.);
1814 cl2 = new AliITSRecPoint(milab,lp,info);
1815 cl2->SetChargeRatio(1.);
1817 fDetTypeRec->AddRecPoint(*cl2);
1820 } // cross is within the detector
1825 } // end loop over Nstrips
1826 } // end loop over Pside 1D clusters
1830 //---------------------------------------------------------
1832 else if( (countPbad>700) && (countNbad<100) ) { // bad Pside!!
1834 for (Int_t i=0; i<np; i++) { // loop over Nside 1Dclusters with no crosses
1835 if(cnegative[i]) continue; // if intersecting Pside clusters continue;
1838 Float_t yN=pos[i].GetY();
1840 if (seg->GetLayer()==5) yP = yN + (7.6/1.9);
1841 else yP = yN - (7.6/1.9);
1842 seg->GetPadCxz(yP, yN, xt, zt);
1844 if ( (TMath::Abs(xt)<hwSSD+0.01) && (TMath::Abs(zt)<hlSSD+0.01) ) {
1845 Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
1846 mT2L->MasterToLocal(loc,trk);
1849 lp[4]=pos[i].GetQ(); //Q
1850 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1851 for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = pos[i].GetLabel(ilab);
1852 CheckLabels2(milab);
1853 milab[3]=( (i<<10) << 10 ) + idet; // pos|neg|det
1854 Int_t info[3] = {(Int_t)pos[i].GetNd(),0,fNlayer[fModule]};
1856 lp[2]=0.031*0.031; //SigmaY2
1857 lp[3]=1.15*1.15; //SigmaZ2
1860 AliITSRecPoint * cl2;
1862 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1863 cl2->SetChargeRatio(1.);
1867 cl2 = new AliITSRecPoint(milab,lp,info);
1868 cl2->SetChargeRatio(1.);
1870 fDetTypeRec->AddRecPoint(*cl2);
1873 } // cross is within the detector
1877 } // end loop over Nside 1D clusters
1879 } // bad Pside module
1881 else if( (countNbad>700) && (countPbad<100) ) { // bad Nside!!
1883 for (Int_t j=0; j<nn; j++) { // loop over Pside 1D clusters with no crosses
1884 if(cpositive[j]) continue;
1887 Float_t yP=neg[j].GetY();
1889 if (seg->GetLayer()==5) yN = yP - (7.6/1.9);
1890 else yN = yP + (7.6/1.9);
1891 seg->GetPadCxz(yP, yN, xt, zt);
1893 if ( (TMath::Abs(xt)<hwSSD+0.01) && (TMath::Abs(zt)<hlSSD+0.01) ) {
1894 Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
1895 mT2L->MasterToLocal(loc,trk);
1898 lp[4]=neg[j].GetQ(); //Q
1899 for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1900 for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = neg[j].GetLabel(ilab);
1901 CheckLabels2(milab);
1902 milab[3]=( j << 10 ) + idet; // pos|neg|det
1903 Int_t info[3] = {0,(Int_t)neg[j].GetNd(),fNlayer[fModule]};
1905 lp[2]=0.0085*0.0085; //SigmaY2
1906 lp[3]=1.15*1.15; //SigmaZ2
1909 AliITSRecPoint * cl2;
1911 cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
1912 cl2->SetChargeRatio(1.);
1916 cl2 = new AliITSRecPoint(milab,lp,info);
1917 cl2->SetChargeRatio(1.);
1919 fDetTypeRec->AddRecPoint(*cl2);
1922 } // cross is within the detector
1926 } // end loop over Pside 1D clusters
1928 } // bad Nside module
1930 //---------------------------------------------------------
1932 } // use bad channels
1934 //cout<<ncl<<" clusters for this module"<<endl;
1936 delete [] cnegative;
1938 delete [] negativepair;
1939 delete [] cpositive;
1941 delete [] positivepair;