]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinderV2SPD.cxx
Removing the flat makefiles
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderV2SPD.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2003, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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                //
17 //                                                                        //
18 //          Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch            //
19 //          Unfolding switch from AliITSRecoParam: D. Elia, INFN Bari     //
20 //                                                                        //
21 ////////////////////////////////////////////////////////////////////////////
22
23
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"
37 #include "AliMagF.h"
38 #include "AliITSsegmentationSPD.h"
39
40 ClassImp(AliITSClusterFinderV2SPD)
41
42 //__________________________________________________________________________
43 AliITSClusterFinderV2SPD::AliITSClusterFinderV2SPD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),
44 fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1),
45 fNySPD(256),
46 fNzSPD(160),
47 fYpitchSPD(0.0050),
48 fZ1pitchSPD(0.0425),
49 fZ2pitchSPD(0.0625),
50 fHwSPD(0.64),
51 fHlSPD(3.48){
52
53   //Default constructor
54
55   fYSPD[0]=0.5*fYpitchSPD;
56   for (Int_t m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD; 
57   fZSPD[0]=fZ1pitchSPD;
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;
63   }
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; 
68     fZSPD[m]-=dz;
69   }
70
71 }
72 //__________________________________________________________________________
73 void AliITSClusterFinderV2SPD::FindRawClusters(Int_t mod){
74   //Find clusters V2
75   SetModule(mod);
76   FindClustersSPD(fDigits);
77
78 }
79 //__________________________________________________________________________
80 void AliITSClusterFinderV2SPD::RawdataToClusters(AliRawReader* rawReader){
81   //------------------------------------------------------------
82   // This function creates ITS clusters from raw data
83   //------------------------------------------------------------
84   rawReader->Reset();
85   AliITSRawStreamSPD inputSPD(rawReader);
86   FindClustersSPD(&inputSPD);
87
88 }
89 //__________________________________________________________________________
90 Int_t AliITSClusterFinderV2SPD::ClustersSPD(AliBin* bins, TClonesArray* digits,TClonesArray* clusters,Int_t maxBins,Int_t nzbins,Int_t iModule,Bool_t rawdata){
91   
92   //Cluster finder for SPD (from digits and from rawdata)
93   const Double_t kmictocm = 1.0e-4; // convert microns to cm.
94   const Double_t defaultField = 5.0; // default Bz value at which Tan(theta_Lorentz) is given in RecoParam
95
96   static AliITSRecoParam *repa = NULL;
97   if(!repa){
98     repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
99     if(!repa){
100       repa = AliITSRecoParam::GetHighFluxParam();
101       AliWarning("Using default AliITSRecoParam class");
102     }
103   }
104   const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(iModule);
105
106   // Lorentz angle correction
107   Double_t tanLorentzAngle=0; 
108   AliITSsegmentationSPD *seg = (AliITSsegmentationSPD*)(GetDetTypeRec()->GetSegmentationModel(0));
109   Double_t thick = 0.5*kmictocm*seg->Dy();  // Half Thickness in cm
110   if(repa->GetCorrectLorentzAngleSPD()) { // only if CorrectLorentzAngleSPD required
111     // here retrieve the value of the field
112     AliMagF* field = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField());
113     if (field == 0)
114       AliError("Cannot get magnetic field from TGeoGlobalMagField");
115     Float_t magField = field->SolenoidField();
116     tanLorentzAngle=repa->GetTanLorentzAngleHolesSPD() * magField / defaultField ;
117   }
118   //
119
120    if (repa->GetSPDRemoveNoisyFlag()) {
121     // Loop on noisy pixels and reset them
122     AliITSCalibrationSPD *cal =  
123       (AliITSCalibrationSPD*) fDetTypeRec->GetCalibrationModel(iModule);
124     for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){
125       Int_t row, col;
126       cal->GetBadPixel(ipix,row,col);
127       //PH      printf(" module %d   row %d  col %d \n",iModule,row,col);
128       Int_t index = (row+1) * nzbins + (col+1);
129       
130       bins[index].SetQ(0);
131       bins[index].SetMask(0xFFFFFFFE);
132     }
133   }
134   
135     if (repa->GetSPDRemoveDeadFlag()) {
136     // Loop on dead pixels and reset them
137     AliITSCalibrationSPD *cal =  
138       (AliITSCalibrationSPD*) fDetTypeRec->GetSPDDeadModel(iModule); 
139     if (cal->IsBad()) return 0; // if all ladder is dead, return to save time
140     for(Int_t ipix = 0; ipix<cal->GetNrBad(); ipix++){
141       Int_t row, col;
142       cal->GetBadPixel(ipix,row,col);
143       Int_t index = (row+1) * nzbins + (col+1);
144       bins[index].SetQ(0);
145       bins[index].SetMask(0xFFFFFFFE);
146     }
147   }
148   
149   Int_t nclu=0;
150   for(Int_t iBin =0; iBin < maxBins;iBin++){
151     if(bins[iBin].IsUsed()) continue;
152     Int_t nBins = 0; 
153     Int_t idxBins[200];
154     FindCluster(iBin,nzbins,bins,nBins,idxBins);
155     if (nBins == 200){
156       Error("ClustersSPD","SPD Too big cluster !\n"); 
157       continue;
158     }
159     Int_t milab[10];
160     for(Int_t ilab=0;ilab<10;ilab++){
161       milab[ilab]=-2;
162     }
163     if(rawdata){
164       milab[3]=fNdet[iModule];
165     }
166     Int_t ymin,ymax,zmin,zmax;
167     if(rawdata){
168       ymin = (idxBins[0] / nzbins) - 1;
169       ymax = ymin;
170       zmin = (idxBins[0] % nzbins) - 1;
171       zmax = zmin;
172     }
173     else{
174       AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[0]);
175       ymin=dig->GetCoord2();
176       ymax=ymin;
177       zmin=dig->GetCoord1();
178       zmax=zmin;
179     }
180     //PH     if(iModule == 24 || iModule == 25)  printf("\n");
181     for (Int_t idx = 0; idx < nBins; idx++) {
182       Int_t iy;
183       Int_t iz; 
184       if(rawdata){
185         iy  = (idxBins[idx] / nzbins) - 1;
186         iz  = (idxBins[idx] % nzbins) - 1;
187       }
188       else{
189         AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
190         iy = dig->GetCoord2();
191         iz = dig->GetCoord1();
192         //if(iModule == 24 || iModule == 25) printf(" ||  iy %d   iz %d  in Module %d \n",iy,iz,iModule);
193       }
194       if (ymin > iy) ymin = iy;
195       if (ymax < iy) ymax = iy;
196       if (zmin > iz) zmin = iz;
197       if (zmax < iz) zmax = iz;
198
199     }
200     if(!rawdata){
201       for(Int_t l=0;l<nBins;l++){
202         AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[l]);
203         for(Int_t dlab=0;dlab<10;dlab++){
204           Int_t digitlab = (dig->GetTracks())[dlab];
205           if(digitlab<0) continue;
206           AddLabel(milab,digitlab);
207         }
208         if (milab[9]>0) CheckLabels2(milab);
209       }
210       CheckLabels2(milab);
211     }
212     
213     Int_t idy =0; //max 2 clusters
214     if((iModule <= fLastSPD1) &&idy<3) idy=3;
215     if((iModule > fLastSPD1) &&idy<4) idy=4;
216     Int_t idz=3;
217
218     // Switch the unfolding OFF/ON
219     if(!repa->GetUseUnfoldingInClusterFinderSPD()) {
220       idy=ymax-ymin+1;
221       idz=zmax-zmin+1;
222     }
223     
224     for(Int_t iiz=zmin; iiz<=zmax;iiz+=idz){
225       for(Int_t iiy=ymin;iiy<=ymax;iiy+=idy){
226
227         Int_t ndigits=0;
228         Float_t y=0.,z=0.,q=0.;
229         for(Int_t idx=0;idx<nBins;idx++){
230           Int_t iy;
231           Int_t iz; 
232           if(rawdata){
233             iy  = (idxBins[idx] / nzbins)-1;
234             iz  = (idxBins[idx] % nzbins)-1;
235           }
236           else{
237             AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
238             iy = dig->GetCoord2();
239             iz = dig->GetCoord1();
240           }
241           if(zmax-zmin>=idz || ymax-ymin>=idy){
242             if(TMath::Abs(iy-iiy)>0.75*idy) continue;
243             if(TMath::Abs(iz-iiz)>0.75*idz) continue;
244           }
245           ndigits++;
246           Float_t qBin=0.;
247           if(rawdata) qBin = bins[idxBins[idx]].GetQ();
248           if(!rawdata){
249             AliITSdigitSPD* dig = (AliITSdigitSPD*)digits->UncheckedAt(idxBins[idx]);
250             qBin = (Float_t)dig->GetSignal();
251           }
252           y+= qBin * fYSPD[iy];
253           z+= qBin * fZSPD[iz];
254           q+= qBin;     
255         }// for idx
256         if(ndigits==0) continue;
257          
258         y /= q;
259         z /= q;
260         y -= fHwSPD;
261         z -= fHlSPD;
262
263         // Lorentz drift effect in local y
264         y -= tanLorentzAngle*thick;
265         //
266
267         Float_t hit[5]; //y,z,sigma(y)^2, sigma(z)^2, charge
268         {
269         Double_t loc[3]={y,0.,z},trk[3]={0.,0.,0.};
270         mT2L->MasterToLocal(loc,trk);
271         hit[0]=trk[1];
272         hit[1]=trk[2];
273         }
274         hit[2] = fYpitchSPD*fYpitchSPD/12.;
275         hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
276         hit[4] = 1.;
277
278         if(!rawdata) milab[3]=fNdet[iModule];
279         Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
280         if(!rawdata){
281          AliITSRecPoint cl(milab,hit,info);
282          cl.SetType(nBins);
283          fDetTypeRec->AddRecPoint(cl);
284         }
285         else{
286           Int_t label[4]={milab[0],milab[1],milab[2],milab[3]};
287           AliITSRecPoint cl(label, hit,info);
288           cl.SetType(nBins);
289           new (clusters->AddrAt(nclu)) 
290           AliITSRecPoint(cl);
291         } 
292         nclu++;
293       }// for iiy
294     }// for iiz
295   }//end for iBin
296   return nclu;
297   
298 }
299 //__________________________________________________________________________
300 void AliITSClusterFinderV2SPD::FindClustersSPD(AliITSRawStreamSPD* input) 
301 {
302   //------------------------------------------------------------
303   // SPD cluster finder for raw data (this method is called once per event)
304   // Now also fills fast-or fired map
305   //------------------------------------------------------------
306
307   AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();  
308   Int_t nClustersSPD = 0;
309   Int_t kNzBins = fNzSPD + 2;
310   Int_t kNyBins = fNySPD + 2;
311   Int_t kMaxBin = kNzBins * kNyBins;
312   AliBin *binsSPD = new AliBin[kMaxBin];
313   AliBin *binsSPDInit = new AliBin[kMaxBin];  
314   AliBin* bins = NULL;
315
316   // read raw data input stream
317   while (kTRUE) {
318     Bool_t next = input->Next();
319     if (!next || input->IsNewModule()) {
320       Int_t iModule = input->GetPrevModuleID();
321
322       // when all data from a module was read, search for clusters
323       if (bins) { 
324         TClonesArray* clusters = rpc->UncheckedGetClusters(iModule);
325         Int_t nClusters = ClustersSPD(bins,0,clusters,kMaxBin,kNzBins,iModule,kTRUE);
326         nClustersSPD += nClusters;
327         bins = NULL;
328       }
329
330       if (!next) break;
331       bins = binsSPD;
332       memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
333     }
334
335     if (next && bins) {
336       // fill the current digit into the bins array
337       Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
338       bins[index].SetIndex(index);
339       bins[index].SetQ(1);
340       bins[index].SetMask(1);
341     }
342   }
343
344   delete [] binsSPDInit;
345   delete [] binsSPD;
346   
347   AliDebug(1,Form("found clusters in ITS SPD: %d", nClustersSPD));
348   
349  
350     // Fill the FastOr fired map
351   for (UInt_t eq=0; eq<20; eq++) {
352     for (UInt_t hs=0; hs<6; hs++) {
353       for (UInt_t chip=0; chip<10; chip++) {
354         if (input->GetFastOrSignal(eq,hs,chip)) {
355           fDetTypeRec->SetFastOrFiredMapOnline(eq,hs,chip);
356         }
357       }
358     }
359   }
360   
361 }
362 //__________________________________________________________________________
363 void AliITSClusterFinderV2SPD::FindClustersSPD(TClonesArray *digits) {
364   //------------------------------------------------------------
365   // SPD cluster finder for digits (this method is called for each module)
366   // Now also fills the fast-or fired map
367   //------------------------------------------------------------
368
369
370   Int_t kNzBins = fNzSPD + 2;
371   const Int_t kMAXBIN=kNzBins*(fNySPD+2);
372
373   Int_t ndigits=digits->GetEntriesFast();
374   AliBin *bins=new AliBin[kMAXBIN];
375
376   Int_t idig;
377   AliITSdigitSPD *digit=0;
378   for (idig=0; idig<ndigits; idig++) {
379     digit=(AliITSdigitSPD*)digits->UncheckedAt(idig);
380     Int_t i=digit->GetCoord2()+1;   //y
381     Int_t j=digit->GetCoord1()+1;
382     Int_t index=i*kNzBins+j;
383
384     bins[index].SetIndex(idig);
385     bins[index].SetQ(1);
386     bins[index].SetMask(1);
387   }
388
389    
390   Int_t nClustersSPD = ClustersSPD(bins,digits,0,kMAXBIN,kNzBins,fModule,kFALSE); 
391   delete [] bins;
392
393   AliDebug(1,Form("found clusters in ITS SPD: %d", nClustersSPD));
394   
395     //  Fill the FastOr fired map
396   AliITSFOSignalsSPD* foSignals = fDetTypeRec->GetFOSignals();
397   if (foSignals) {
398     UInt_t eq = AliITSRawStreamSPD::GetOnlineEqIdFromOffline(fModule);
399     UInt_t hs = AliITSRawStreamSPD::GetOnlineHSFromOffline(fModule);
400     for(UInt_t ch=0; ch<5; ch++) {
401       UInt_t chip = AliITSRawStreamSPD::GetOnlineChipFromOffline(fModule,ch*32);
402       if (foSignals->GetSignal(eq,hs,chip)) {
403         fDetTypeRec->SetFastOrFiredMapOnline(eq,hs,chip);
404       }
405     }
406   }
407   
408 }