AliRoot Core  edcc906 (edcc906)
AliMFTClusterFinder.cxx
Go to the documentation of this file.
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  **************************************************************************/
15 
16 //====================================================================================================================================================
17 //
18 // Class for finding and building the clusters of the ALICE Muon Forward Tracker
19 //
20 // Contact author: antonio.uras@cern.ch
21 //
22 //====================================================================================================================================================
23 
24 #include "AliLog.h"
25 #include "TObjArray.h"
26 #include "TClonesArray.h"
27 #include "AliMFTDigit.h"
28 #include "AliMFTCluster.h"
29 #include "AliMFTPlane.h"
30 #include "AliMFTSegmentation.h"
31 #include "TTree.h"
32 #include "TMath.h"
33 #include "AliMFTConstants.h"
34 #include "AliMFTClusterFinder.h"
35 #include "TRandom.h"
36 #include "AliMFTGeometry.h"
37 #include "AliCodeTimer.h"
38 
42 
43 ClassImp(AliMFTClusterFinder)
44 
45 //====================================================================================================================================================
46 
48  TObject(),
49  fDigitsInCluster(0),
50  fCurrentDigit(0),
51  fCurrentCluster(0),
52  fSegmentation(0),
53  fNPlanes(0),
54  fApplyMisalignment(kFALSE),
55  fStopWatch(0)
56 {
57 
58  // Default constructor
59  AliInfo("start");
60 
61  for (Int_t iPlane=0; iPlane<fNMaxPlanes; iPlane++) fClustersPerPlane[iPlane] = NULL;
62  fDigitsInCluster = new TClonesArray("AliMFTDigit", fNMaxDigitsPerCluster);
63  fDigitsInCluster -> SetOwner(kTRUE);
64  fStopWatch = new TStopwatch();
65  fStopWatch -> Reset();
66  AliDebug(1, "... done!");
67 
68 }
69 
70 //====================================================================================================================================================
71 
73 
74  AliDebug(1, "Deleting AliMFTClusterFinder...");
75 
76  for (Int_t iPlane=0; iPlane<fNMaxPlanes; iPlane++) {
77  if (fClustersPerPlane[iPlane]) fClustersPerPlane[iPlane]->Delete(); delete fClustersPerPlane[iPlane]; fClustersPerPlane[iPlane] = 0x0;
78  }
80 
81  delete fStopWatch;
82 
83  AliDebug(1, "... done!");
84 
85 }
86 
87 //====================================================================================================================================================
88 
89 void AliMFTClusterFinder::Clear(const Option_t* /*opt*/) {
90 
91  AliDebug(1, "Clearing AliMFTClusterFinder...");
92 
93  for (Int_t iPlane=0; iPlane<fNMaxPlanes; iPlane++) {
94  if(fClustersPerPlane[iPlane]) fClustersPerPlane[iPlane]->Clear("C");
95  }
96  if(fDigitsInCluster) fDigitsInCluster->Clear("C");
97 
98  AliDebug(1, "... done!");
99 
100 }
101 
102 //====================================================================================================================================================
103 
104 void AliMFTClusterFinder::Init(const Char_t *nameGeomFile) {
105 
106  AliInfo("start");
108  fSegmentation = mftGeo->GetSegmentation();
110  AliInfo("Done");
111 }
112 
113 //====================================================================================================================================================
114 
116 
117  // Cleaning up and preparation for the clustering procedure
118 
119  AliDebug(1, "Starting Event...");
120 
121  for (Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
122  fClustersPerPlane[iPlane]->Delete();
123  }
124 
125  AliDebug(1, "... done!");
126 
127 }
128 
129 //====================================================================================================================================================
130 
132  AliCodeTimerAuto("",0);
133 
134  // where the clusterization is performed
136 
137  AliInfo("Starting Clusterization for MFT");
138  AliDebug(1, Form("nPlanes = %d", fNPlanes));
139 
140  if (!fStopWatch) fStopWatch = new TStopwatch();
141  fStopWatch -> Reset();
142 
143  StartEvent();
144  Bool_t isDigAvailableForNewCluster = kTRUE;
145 
146  TClonesArray *myDigitList = 0;
147 
148  for (Int_t iPlane=0; iPlane<AliMFTConstants::kNDisks; iPlane++) {
149 
150 
151  const Int_t nDetElem = mftGeo->GetDiskNSensors(iPlane);
152  AliDebug(1, Form("Plane %02d : # Det Elem = %d ", iPlane,nDetElem));
153 
154  TClonesArray *clustersPerDetElem[nDetElem];
155  for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) clustersPerDetElem[iDetElem] = new TClonesArray("AliMFTCluster");
156 
157  myDigitList = (TClonesArray*) pDigitList->At(iPlane);
158 
159  AliInfo( Form("myDigitList->GetEntries() = %d", myDigitList->GetEntries()));
160 
161  Int_t cycleOverDigits = 0;
162  Double_t myCutForAvailableDigits = 0;
163 
164  Int_t currentDetElem = -1;
165  Int_t currentDetElemLocal = -1;
166  Bool_t areThereSkippedDigits = kFALSE;
167 
168  fStopWatch -> Start();
169 
170  while (myDigitList->GetEntries()) {
171 
172  for (Int_t iDig=0; iDig<myDigitList->GetEntries(); iDig++) {
173 
174  fCurrentDigit = (AliMFTDigit*) myDigitList->At(iDig);
175 
176  if (!iDig) {
177  if (fCurrentDigit->GetDetElemID() != currentDetElem) {
178  // first iteration over the digits of a specific detection element
179  currentDetElem = fCurrentDigit->GetDetElemID();
180  currentDetElemLocal = mftGeo->GetDetElemLocalID(currentDetElem);
181  cycleOverDigits = 0;
182  myCutForAvailableDigits = fCutForAvailableDigits;
183  }
184  else if (fCurrentDigit->GetDetElemID()==currentDetElem && areThereSkippedDigits) {
185  // second (or further) iteration over the digits of a specific detection element
186  cycleOverDigits++;
187  myCutForAvailableDigits -= 0.5;
188  }
189  areThereSkippedDigits = kFALSE;
190  }
191  else {
192  areThereSkippedDigits = kTRUE;
193  if (fCurrentDigit->GetDetElemID() != currentDetElem) break;
194  }
195 
196  isDigAvailableForNewCluster = kTRUE;
197 
198  for (Int_t iCluster=0; iCluster<clustersPerDetElem[currentDetElemLocal]->GetEntries(); iCluster++) {
199  fCurrentCluster = (AliMFTCluster*) clustersPerDetElem[currentDetElemLocal]->At(iCluster);
202  myDigitList->Remove(fCurrentDigit);
203  myDigitList->Compress();
204  iDig--;
205  isDigAvailableForNewCluster = kFALSE;
206  break;
207  }
208  if (fCurrentCluster->GetDistanceFromPixel(fCurrentDigit) < myCutForAvailableDigits) {
209  areThereSkippedDigits = kTRUE;
210  isDigAvailableForNewCluster=kFALSE;
211  }
212  }
213 
214  if (isDigAvailableForNewCluster) {
215  AliMFTCluster *newCluster = new AliMFTCluster();
216  newCluster->AddPixel(fCurrentDigit);
217  myDigitList->Remove(fCurrentDigit);
218  myDigitList->Compress();
219  iDig--;
220  new ((*clustersPerDetElem[currentDetElemLocal])[clustersPerDetElem[currentDetElemLocal]->GetEntries()]) AliMFTCluster(*newCluster);
221  delete newCluster;
222  }
223 
224  } // end of cycle over the digits
225 
226  } // no more digits to check in current plane!
227 
228  fStopWatch -> Print("m");
229 
230  AliInfo(Form("Plane %d: clusters found in %f seconds\n",iPlane,fStopWatch->CpuTime()));
231  fStopWatch->Start();
232 
233  // Now we merge the cluster lists coming from each detection element, to build the cluster list of the plane
234 
235  Double_t misalignmentPhi = 2.*TMath::Pi()*gRandom->Rndm();
236  Double_t misalignmentX = fMisalignmentMagnitude*TMath::Cos(misalignmentPhi);
237  Double_t misalignmentY = fMisalignmentMagnitude*TMath::Sin(misalignmentPhi);
238 
239  AliMFTCluster *newCluster = NULL;
240  for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) {
241  for (Int_t iCluster=0; iCluster<clustersPerDetElem[iDetElem]->GetEntries(); iCluster++) {
242  newCluster = (AliMFTCluster*) (clustersPerDetElem[iDetElem]->At(iCluster));
243  newCluster -> TerminateCluster();
244  if (fApplyMisalignment) {
245  newCluster -> SetClusterEditable(kTRUE);
246  newCluster -> SetX(newCluster->GetX()+misalignmentX);
247  newCluster -> SetY(newCluster->GetY()+misalignmentY);
248  newCluster -> SetClusterEditable(kFALSE);
249  }
250  new ((*fClustersPerPlane[iPlane])[fClustersPerPlane[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
251  }
252  }
253 
254  printf("%d Clusters in plane %02d merged in %f seconds\n", fClustersPerPlane[iPlane]->GetEntries(), iPlane, fStopWatch->CpuTime());
255 
256  for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) {
257  clustersPerDetElem[iDetElem] -> Delete();
258  delete clustersPerDetElem[iDetElem];
259  }
260 
261  myDigitList -> Delete();
262 
263  } // end of cycle over the planes
264 
265 }
266 
267 //====================================================================================================================================================
268 
270 
271  // Creating the cluster branches, one for each plane (see AliMFTReconstructor::Reconstruct)
272 
273  AliDebug(1, "Making Cluster Branch");
274 
275  CreateClusters();
276 
277  if (treeCluster) {
278  for(Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
279  AliDebug(1, Form("Setting Branch Plane_%02d for treeCluster",iPlane));
280  if (treeCluster->GetBranch(Form("Plane_%02d",iPlane))) continue;
281  AliDebug(1, Form("Branch Plane_%02d does not exist, creating!",iPlane));
282  treeCluster->Branch(Form("Plane_%02d",iPlane), &(fClustersPerPlane[iPlane]));
283  }
284  }
285 
286 }
287 
288 //====================================================================================================================================================
289 
291 
292  // Addressing the cluster branches, one for each plane (see AliMFTReconstructor::Reconstruct)
293 
294  if (treeCluster && treeCluster->GetBranch("Plane_00")) {
295  CreateClusters();
296  for(Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
297  if (treeCluster->GetBranch(Form("Plane_%02d",iPlane))) {
298  treeCluster->SetBranchAddress(Form("Plane_%02d",iPlane), &(fClustersPerPlane[iPlane]));
299  }
300  else AliError(Form("No branch available with name Plane_%02d", iPlane));
301  }
302  }
303 
304 }
305 
306 //====================================================================================================================================================
307 
309 
310  // create cluster list
311 
312  AliDebug(1, Form("Creating clusters list: nPlanes = %d",fNPlanes));
313 
314  if (fClustersPerPlane[0]) return;
315 
316  for(Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
317  AliDebug(1, Form("plane %02d", iPlane));
318  fClustersPerPlane[iPlane] = new TClonesArray("AliMFTCluster");
319  fClustersPerPlane[iPlane] -> SetOwner(kTRUE);
320 
321  }
322 
323 }
324 
325 //====================================================================================================================================================
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
Int_t GetDetElemID() const
Definition: AliMFTDigit.h:53
static const Double_t fCutForAttachingDigits
TClonesArray * fClustersPerPlane[fNMaxPlanes]
static const Double_t fCutForAttachingDigits
#define TObjArray
AliMFTDigit * fCurrentDigit
void MakeClusterBranch(TTree *treeCluster)
Double_t GetY() const
Definition: AliMFTCluster.h:42
void SetClusterTreeAddress(TTree *treeCluster)
AliMFTSegmentation * GetSegmentation() const
Returns pointer to the segmentation.
static const Double_t fCutForAvailableDigits
void Print(const char *method, TStopwatch &timer, Int_t n)
static const Double_t fMisalignmentMagnitude
Double_t GetDistanceFromPixel(AliMFTDigit *pixel)
#define AliInfo(message)
Definition: AliLog.h:484
static const Int_t fNMaxPlanes
static AliMFTGeometry * Instance()
Retuns MFT Geometry singleton object.
Double_t GetX() const
Definition: AliMFTCluster.h:41
#define AliCodeTimerAuto(message, counter)
Definition: AliCodeTimer.h:137
void DigitsToClusters(const TObjArray *pDigitList)
AliMFTSegmentation * fSegmentation
virtual void Clear(const Option_t *)
static const Double_t fMisalignmentMagnitude
TChain * treeCluster
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
TClonesArray * fDigitsInCluster
[fNPlanes] list of clusters [per plane]
Bool_t AddPixel(AliMFTDigit *pixel)
Int_t GetDiskNSensors(Int_t diskId) const
Returns the number of sensors on the entire disk (top+bottom)
AliMFTCluster * fCurrentCluster
#define AliError(message)
Definition: AliLog.h:591
static const Int_t kNDisks
Number of Disk.
static const Double_t fCutForAvailableDigits
Int_t GetDetElemLocalID(Int_t detElem) const
Returns the local ID of the sensor on the disk.
Class Handling both Virutal Segmentation and Real Volumes.
void Init(const Char_t *nameGeomFile)