]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSClusterFinder.cxx
Histogram ranges changed to cut off saturation peak and noise
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinder.cxx
CommitLineData
b0f5e3fc 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
04366a57 15////////////////////////////////////////////////////////////////////////////
16// //
17// Base Class used to find //
18// the reconstructed points for ITS //
19// See also AliITSClusterFinderSPD, AliITSClusterFinderSDD, //
20// AliITSClusterFinderSDD AliITSClusterFinderV2 //
21////////////////////////////////////////////////////////////////////////////
88cb7938 22
b0f5e3fc 23#include "AliITSClusterFinder.h"
04366a57 24#include "AliITSRecPoint.h"
7d62fb64 25#include "AliITSdigit.h"
26#include "AliITSDetTypeRec.h"
aacedc3e 27#include "AliITSMap.h"
1f3e997f 28#include "AliITSgeomTGeo.h"
b0f5e3fc 29
b0f5e3fc 30ClassImp(AliITSClusterFinder)
31
9de0700b 32//----------------------------------------------------------------------
aacedc3e 33AliITSClusterFinder::AliITSClusterFinder():
34TObject(),
35fDebug(0),
36fModule(0),
37fDigits(0),
38fNdigits(0),
8ba39da9 39fDetTypeRec(0),
aacedc3e 40fClusters(0),
41fNRawClusters(0),
42fMap(0),
43fNperMax(0),
44fDeclusterFlag(0),
45fClusterSize(0),
46fNPeaks(-1){
9de0700b 47 // default cluster finder
aacedc3e 48 // Input:
49 // none.
50 // Output:
51 // none.
52 // Return:
53 // A default constructed AliITSCulsterFinder
9de0700b 54}
55//----------------------------------------------------------------------
8ba39da9 56AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp):
aacedc3e 57TObject(),
58fDebug(0),
59fModule(0),
60fDigits(0),
61fNdigits(0),
e56160b8 62fDetTypeRec(dettyp),
aacedc3e 63fClusters(0),
64fNRawClusters(0),
65fMap(0),
66fNperMax(0),
67fDeclusterFlag(0),
68fClusterSize(0),
69fNPeaks(-1){
70 // Standard constructor for cluster finder
71 // Input:
72 // AliITSsegmentation *seg The segmentation class to be used
73 // AliITSresponse *res The response class to be used
74 // Output:
75 // none.
76 // Return:
77 // A Standard constructed AliITSCulsterFinder
b0f5e3fc 78
79 SetNperMax();
80 SetClusterSize();
81 SetDeclusterFlag();
aacedc3e 82}
83//----------------------------------------------------------------------
8ba39da9 84AliITSClusterFinder::AliITSClusterFinder(AliITSDetTypeRec* dettyp,
85 TClonesArray *digits):
aacedc3e 86TObject(),
87fDebug(0),
88fModule(0),
89fDigits(digits),
90fNdigits(0),
8ba39da9 91fDetTypeRec(dettyp),
aacedc3e 92fClusters(0),
93fNRawClusters(0),
94fMap(0),
95fNperMax(0),
96fDeclusterFlag(0),
97fClusterSize(0),
98fNPeaks(-1){
99 // Standard + cluster finder constructor
100 // Input:
101 // AliITSsegmentation *seg The segmentation class to be used
102 // AliITSresponse *res The response class to be used
103 // TClonesArray *digits Array of digits to be used
104 // Output:
105 // none.
106 // Return:
107 // A Standard constructed AliITSCulsterFinder
b0f5e3fc 108
aacedc3e 109 fNdigits = fDigits->GetEntriesFast();
110 SetNperMax();
111 SetClusterSize();
112 SetDeclusterFlag();
b0f5e3fc 113}
a971ed8e 114
04366a57 115//______________________________________________________________________
a971ed8e 116AliITSClusterFinder::AliITSClusterFinder(const AliITSClusterFinder &source) : TObject(source),
117fDebug(source.fDebug),
118fModule(source.fModule),
119fDigits(),
120fNdigits(source.fNdigits),
121fDetTypeRec(),
122fClusters(),
123fNRawClusters(source.fNRawClusters),
124fMap(),
125fNperMax(source.fNperMax),
126fDeclusterFlag(source.fDeclusterFlag),
127fClusterSize(source.fClusterSize),
128fNPeaks(source.fNPeaks) {
04366a57 129 // Copy constructor
130 // Copies are not allowed. The method is protected to avoid misuse.
a971ed8e 131 AliError("Copy constructor not allowed\n");
04366a57 132}
a971ed8e 133
04366a57 134
135//______________________________________________________________________
e56160b8 136//AliITSClusterFinder& AliITSClusterFinder::operator=(const AliITSClusterFinder& /* source */){
04366a57 137 // Assignment operator
138 // Assignment is not allowed. The method is protected to avoid misuse.
e56160b8 139// Fatal("= operator","Assignment operator not allowed\n");
140// return *this;
141//}
04366a57 142
9de0700b 143//----------------------------------------------------------------------
144AliITSClusterFinder::~AliITSClusterFinder(){
145 // destructor cluster finder
aacedc3e 146 // Input:
147 // none.
148 // Output:
149 // none.
150 // Return:
151 // none.
b0f5e3fc 152
aacedc3e 153 if(fMap) {delete fMap;}
9de0700b 154 // Zero local pointers. Other classes own these pointers.
9de0700b 155 fMap = 0;
156 fDigits = 0;
157 fNdigits = 0;
158 fNRawClusters = 0;
159 fNperMax = 0;
160 fDeclusterFlag= 0;
161 fClusterSize = 0;
162 fNPeaks = 0;
7d62fb64 163 fDetTypeRec = 0;
04366a57 164
7d62fb64 165}
b0f5e3fc 166//__________________________________________________________________________
7d62fb64 167void AliITSClusterFinder::InitGeometry(){
1f3e997f 168 //
169 // Initialisation of ITS geometry
170 //
171 Int_t mmax=AliITSgeomTGeo::GetNModules();
172 for (Int_t m=0; m<mmax; m++) {
173 Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
1f3e997f 174 fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
04366a57 175 fNlayer[m] = lay-1;
176 }
b0f5e3fc 177}
04366a57 178
179
7d62fb64 180
9de0700b 181//----------------------------------------------------------------------
182void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c){
183 // Add a raw cluster copy to the list
aacedc3e 184 // Input:
185 // Int_t branch The branch to which the cluster is to be added to
186 // AliITSRawCluster *c The cluster to be added to the array of clusters
187 // Output:
188 // none.
189 // Return:
190 // none.
b0f5e3fc 191
7d62fb64 192 if(!fDetTypeRec) {
193 Error("AddCluster","fDetTypeRec is null!");
194 return;
195 }
196 fDetTypeRec->AddCluster(branch,c);
197 fNRawClusters++;
9355b256 198}
9de0700b 199//----------------------------------------------------------------------
200void AliITSClusterFinder::AddCluster(Int_t branch, AliITSRawCluster *c,
201 AliITSRecPoint &rp){
aacedc3e 202 // Add a raw cluster copy to the list and the RecPoint
203 // Input:
204 // Int_t branch The branch to which the cluster is to be added to
205 // AliITSRawCluster *c The cluster to be added to the array of clusters
206 // AliITSRecPoint &rp The RecPoint to be added to the array of RecPoints
207 // Output:
208 // none.
209 // Return:
210 // none.
7d62fb64 211 if(!fDetTypeRec) {
212 Error("AddCluster","fDetTypeRec is null!");
213 return;
214 }
9355b256 215
7d62fb64 216 fDetTypeRec->AddCluster(branch,c);
217 fNRawClusters++;
218 fDetTypeRec->AddRecPoint(rp);
04366a57 219
7d62fb64 220}
221/*
04366a57 222//______________________________________________________________________
223void AliITSClusterFinder::CheckLabels(Int_t lab[3]) {
224 //------------------------------------------------------------
225 // Tries to find mother's labels
226 //------------------------------------------------------------
227
228 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
229 // Check if simulation
230 AliMC* mc = gAlice->GetMCApp();
231 if(!mc)return;
232
233 Int_t ntracks = mc->GetNtrack();
234 for (Int_t i=0;i<3;i++){
235 Int_t label = lab[i];
236 if (label>=0 && label<ntracks) {
237 TParticle *part=(TParticle*)mc->Particle(label);
238 if (part->P() < 0.005) {
239 Int_t m=part->GetFirstMother();
240 if (m<0) {
241 continue;
242 }
243 if (part->GetStatusCode()>0) {
244 continue;
245 }
246 lab[i]=m;
247 }
248 }
249 }
250
251}
7d62fb64 252*/
f8d9a5b8 253//______________________________________________________________________
254void AliITSClusterFinder::FindRawClusters(Int_t module){
255 // Default Cluster finder.
256 // Input:
257 // Int_t module Module number for which culster are to be found.
258 // Output:
259 // none.
260 // Return:
261 // none.
262 const Int_t kelms = 10;
263 Int_t ndigits = fDigits->GetEntriesFast();
264 TObjArray *digs = new TObjArray(ndigits);
265 TObjArray *clusts = new TObjArray(ndigits); // max # cluster
266 TObjArray *clust0=0; // A spacific cluster of digits
267 TObjArray *clust1=0; // A spacific cluster of digits
268 AliITSdigit *dig=0; // locat pointer to a digit
f824982a 269 Int_t i=0,nc=0,j[4],k,k2=0;
f8d9a5b8 270
271 // Copy all digits for this module into a local TObjArray.
aacedc3e 272 for(i=0;i<ndigits;i++) digs->AddAt(new AliITSdigit(*(GetDigit(i))),i);
f8d9a5b8 273 digs->Sort();
274 // First digit is a cluster.
275 i = 0;
276 nc = 0;
277 clusts->AddAt(new TObjArray(kelms),nc);
278 clust0 = (TObjArray*)(clusts->At(nc));
279 clust0->AddAtFree(digs->At(i)); // move owner ship from digs to clusts
280 nc++;
281 for(i=1;i<ndigits;i++){
aacedc3e 282 if(IsNeighbor(digs,i,j)){
283 dig = (AliITSdigit*)(digs->At(j[0]));
284 // Add to existing cluster. Find which cluster this digis
285 for(k=0;k<nc;k++){
286 clust0 = ((TObjArray*)(clusts->At(k)));
287 if(clust0->IndexOf(dig)>=0) break;
288 } // end for k
289 if(k>=nc){
290 Fatal("FindRawClusters","Digit not found as expected");
291 } // end if
292 if(j[1]>=0){
293 dig = (AliITSdigit*)(digs->At(j[1]));
294 // Add to existing cluster. Find which cluster this digis
295 for(k2=0;k2<nc;k2++){
296 clust1 = ((TObjArray*)(clusts->At(k2)));
297 if(clust1->IndexOf(dig)>=0) break;
298 } // end for k2
299 if(k2>=nc){
300 Fatal("FindRawClusters","Digit not found as expected");
301 } // end if
302 } // end if j[1]>=0
303 // Found cluster with neighboring digits add this one to it.
304 if(clust0==clust1){ // same cluster
305 clust0->AddAtFree(digs->At(i));
306 clust0 = 0; // finished with cluster. zero for safty
307 clust1 = 0; // finished wit hcluster. zero for safty
308 }else{ // two different clusters which need to be merged.
309 clust0->AddAtFree(digs->At(i)); // Add digit to this cluster.
310 for(k=0;k<clust1->GetEntriesFast();k++){
311 // move clust1 into clust0
312 //move digit to this cluster
313 clust0->AddAtFree(clust1->At(k));
314 clust1->AddAt(0,k); // zero this one
315 } // end for k
316 delete clust1;
317 clusts->AddAt(0,k2); // zero array of clusters element clust1
318 clust0 = 0; // finished with cluster. zero for safty
319 clust1 = 0; // finished wit hcluster. zero for safty
320 } // end if clust0==clust1
321 }else{// New cluster
322 clusts->AddAt(new TObjArray(kelms),nc);
323 clust0 = ((TObjArray*)(clusts->At(nc)));
324 // move owner ship from digs to clusts
325 clust0->AddAtFree(digs->At(i));
326 clust0 = 0; // finished with cluster. zero for safty
327 nc++;
328 } // End if IsNeighbor
f8d9a5b8 329 } // end for i
330 // There are now nc clusters in clusts. Each element of clust is an
331 // array of digits which are clustered together.
332
333 // For each cluster call detector specific CreateRecPoints
334 for(i=0;i<nc;i++) CreateRecPoints((TObjArray*)(clusts->At(i)),module);
335
336 // clean up at the end.
337 for(i=0;i<nc;i++){
aacedc3e 338 clust0 =(TObjArray*)(clusts->At(i));
339 // Digits deleted below, so zero this TObjArray
340 for(k=0;k<clust0->GetEntriesFast();k++) clust0->AddAt(0,k);
341 delete clust0; // Delete this TObjArray
342 clusts->AddAt(0,i); // Contents deleted above, so zero it.
f8d9a5b8 343 } // end for i
344 delete clusts; // Delete this TObjArray/
345 // Delete the digits then the TObjArray which containted them.
346 for(i=0;i<ndigits;i++) delete ((AliITSdigit*)(digs->At(i)));
347 delete digs;
348}
349//______________________________________________________________________
aacedc3e 350Bool_t AliITSClusterFinder::IsNeighbor(TObjArray *digs,Int_t i,Int_t n[])const{
f8d9a5b8 351 // Locagical function which checks to see if digit i has a neighbor.
352 // If so, then it returns kTRUE and its neighbor index j.
353 // This routine checks if the digits are side by side or one before the
354 // other. Requires that the array of digits be in proper order.
355 // Returns kTRUE in the following cases.
356 // ji 0j if kdiagonal j0 0i
357 // 00 0i if kdiagonal 0i j0
358 // Inputs:
359 // TObjArray *digs Array to search for neighbors in
360 // Int_t i Index of digit for which we are searching for
361 // a neighbor of.
362 // Output:
363 // Int_t j[4] Index of one or more of the digits which is a
364 // neighbor of digit a index i.
365 // Return:
366 // Bool_t kTRUE if a neighbor was found kFALSE otherwise.
367 Int_t ix,jx,iz,jz,j;
368 const Bool_t kdiagonal=kFALSE;
369 Bool_t nei[4];
370
371 // No neighbors found if array empty.
372 if(digs->GetEntriesFast()<=0) return kFALSE;
373 // can not be a digit with first element or elements out or range
374 if(i<=0 || i>=digs->GetEntriesFast()) return kFALSE;
375
376 for(j=0;j<4;j++){n[j] = -1;nei[j]=kFALSE;}
377 ix = ((AliITSdigit*)(digs->At(i)))->GetCoord1();
378 iz = ((AliITSdigit*)(digs->At(i)))->GetCoord2();
379 for(j=0;j<i;j++){
aacedc3e 380 jx = ((AliITSdigit*)(digs->At(j)))->GetCoord1();
381 jz = ((AliITSdigit*)(digs->At(j)))->GetCoord2();
382 if(jx+1==ix && jz ==iz){n[0] = j;nei[0] = kTRUE;}
383 if(jx ==ix && jz+1==iz){n[1] = j;nei[1] = kTRUE;}
384 if(jx+1==ix && jz+1==iz){n[2] = j;nei[2] = kTRUE;}
385 if(jx+1==ix && jz-1==iz){n[3] = j;nei[3] = kTRUE;}
f8d9a5b8 386 } // end for k
387 if(nei[0]||nei[1]) return kTRUE;
388 if(kdiagonal&&(nei[2]||nei[3])) return kTRUE;
389 // no Neighbors found.
390 return kFALSE;
391}
aacedc3e 392
393//______________________________________________________________________
7d62fb64 394void AliITSClusterFinder::Print(ostream *os) const{
aacedc3e 395 //Standard output format for this class
396 // Inputs:
397 // ostream *os Output stream
398 // Output:
399 // ostream *os Output stream
400 // Return:
401 // none.
402
403 *os << fDebug<<",";
404 *os << fModule<<",";
405 *os << fNdigits<<",";
406 *os << fNRawClusters<<",";
407 *os << fNperMax<<",";
408 *os << fDeclusterFlag<<",";
409 *os << fClusterSize<<",";
410 *os << fNPeaks<<endl;
411}
412//______________________________________________________________________
7d62fb64 413void AliITSClusterFinder::Read(istream *is) {
aacedc3e 414 //Standard input for this class
415 // Inputs:
416 // istream *is Input stream
417 // Output:
418 // istream *is Input stream
419 // Return:
420 // none.
421
422 *is >> fDebug;
423 *is >> fModule;
424 *is >> fNdigits;
425 *is >> fNRawClusters;
426 *is >> fNperMax;
427 *is >> fDeclusterFlag;
428 *is >> fClusterSize;
429 *is >> fNPeaks;
430}
431//______________________________________________________________________
432ostream &operator<<(ostream &os,AliITSClusterFinder &source){
433 // Standard output streaming function.
434 // Inputs:
435 // ostream *os Output stream
436 // AliITSClusterFinder &source Class to be printed
437 // Output:
438 // ostream *os Output stream
439 // Return:
440 // none.
441
442 source.Print(&os);
443 return os;
444}
445//______________________________________________________________________
446istream &operator>>(istream &is,AliITSClusterFinder &source){
447 // Standard output streaming function.
448 // Inputs:
449 // istream *is Input stream
450 // AliITSClusterFinder &source Class to be read in.
451 // Output:
452 // istream *is Input stream
453 // Return:
454 // none.
455
456 source.Read(&is);
457 return is;
458}