Add new global configuration for prod shuttle.
[u/mrichter/AliRoot.git] / MFT / AliMFTClusterFinder.cxx
CommitLineData
820b4d9e 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 "AliMFTSegmentation.h"
30#include "TTree.h"
31#include "TMath.h"
d4643a10 32#include "AliMFTConstants.h"
820b4d9e 33#include "AliMFTClusterFinder.h"
65273893 34#include "TRandom.h"
820b4d9e 35
d4643a10 36const Double_t AliMFTClusterFinder::fCutForAvailableDigits = AliMFTConstants::fCutForAvailableDigits;
37const Double_t AliMFTClusterFinder::fCutForAttachingDigits = AliMFTConstants::fCutForAttachingDigits;
65273893 38const Double_t AliMFTClusterFinder::fMisalignmentMagnitude = AliMFTConstants::fMisalignmentMagnitude;
d4643a10 39
820b4d9e 40ClassImp(AliMFTClusterFinder)
41
42//====================================================================================================================================================
43
44AliMFTClusterFinder::AliMFTClusterFinder() :
45 TObject(),
46 fDigitsInCluster(0),
d4643a10 47 fCurrentDigit(0),
48 fCurrentCluster(0),
820b4d9e 49 fSegmentation(0),
e21f8bf5 50 fNPlanes(0),
65273893 51 fApplyMisalignment(kFALSE),
52 fStopWatch(0)
820b4d9e 53{
54
55 // Default constructor
56
57 for (Int_t iPlane=0; iPlane<fNMaxPlanes; iPlane++) fClustersPerPlane[iPlane] = NULL;
58 fDigitsInCluster = new TClonesArray("AliMFTDigit", fNMaxDigitsPerCluster);
ffc53def 59 fDigitsInCluster -> SetOwner(kTRUE);
65273893 60 fStopWatch = new TStopwatch();
61 fStopWatch -> Reset();
820b4d9e 62
63}
64
65//====================================================================================================================================================
66
67AliMFTClusterFinder::~AliMFTClusterFinder() {
ffc53def 68
820b4d9e 69 AliDebug(1, "Deleting AliMFTClusterFinder...");
ffc53def 70
71 for (Int_t iPlane=0; iPlane<fNMaxPlanes; iPlane++) {
72 if (fClustersPerPlane[iPlane]) fClustersPerPlane[iPlane]->Delete(); delete fClustersPerPlane[iPlane]; fClustersPerPlane[iPlane] = 0x0;
73 }
74 if (fDigitsInCluster) fDigitsInCluster->Delete(); delete fDigitsInCluster; fDigitsInCluster = NULL;
75 delete fSegmentation; fSegmentation=NULL;
e21f8bf5 76
65273893 77 delete fStopWatch;
ffc53def 78
79 AliDebug(1, "... done!");
80
81}
820b4d9e 82
ffc53def 83//====================================================================================================================================================
820b4d9e 84
ffc53def 85void AliMFTClusterFinder::Clear(const Option_t* /*opt*/) {
86
87 AliDebug(1, "Clearing AliMFTClusterFinder...");
88
89 for (Int_t iPlane=0; iPlane<fNMaxPlanes; iPlane++) {
90 if(fClustersPerPlane[iPlane]) fClustersPerPlane[iPlane]->Clear("C");
91 }
92 if(fDigitsInCluster) fDigitsInCluster->Clear("C");
93 fSegmentation->Clear("C");
94
820b4d9e 95 AliDebug(1, "... done!");
ffc53def 96
820b4d9e 97}
98
99//====================================================================================================================================================
100
9cc245f6 101void AliMFTClusterFinder::Init(const Char_t *nameGeomFile) {
820b4d9e 102
103 fSegmentation = new AliMFTSegmentation(nameGeomFile);
104 fNPlanes = fSegmentation -> GetNPlanes();
105
106}
107
108//====================================================================================================================================================
109
110void AliMFTClusterFinder::StartEvent() {
111
112 // Cleaning up and preparation for the clustering procedure
113
114 AliDebug(1, "Starting Event...");
115
116 for (Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
b5ab1ac4 117 fClustersPerPlane[iPlane]->Delete();
820b4d9e 118 }
119
120 AliDebug(1, "... done!");
121
122}
123
124//====================================================================================================================================================
125
126void AliMFTClusterFinder::DigitsToClusters(const TObjArray *pDigitList) {
127
128 // where the clusterization is performed
129
130 AliInfo("Starting Clusterization for MFT");
131 AliDebug(1, Form("nPlanes = %d", fNPlanes));
132
65273893 133 if (!fStopWatch) fStopWatch = new TStopwatch();
134 fStopWatch -> Reset();
e21f8bf5 135
820b4d9e 136 StartEvent();
d4643a10 137 Bool_t isDigAvailableForNewCluster = kTRUE;
820b4d9e 138
b5ab1ac4 139 TClonesArray *myDigitList = 0;
140
820b4d9e 141 for (Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
142
143 AliDebug(1, Form("Plane %02d", iPlane));
144
e21f8bf5 145 Int_t nDetElem = fSegmentation->GetPlane(iPlane)->GetNActiveElements();
146 TClonesArray *clustersPerDetElem[fNMaxDetElemPerPlane] = {0};
147 for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) clustersPerDetElem[iDetElem] = new TClonesArray("AliMFTCluster");
148
b5ab1ac4 149 myDigitList = (TClonesArray*) pDigitList->At(iPlane);
820b4d9e 150
151 AliDebug(1, Form("myDigitList->GetEntries() = %d", myDigitList->GetEntries()));
152
d4643a10 153 Int_t cycleOverDigits = 0;
e21f8bf5 154 Double_t myCutForAvailableDigits = 0;
7230691d 155
e21f8bf5 156 Int_t currentDetElem = -1;
157 Int_t currentDetElemLocal = -1;
158 Bool_t areThereSkippedDigits = kFALSE;
159
65273893 160 fStopWatch -> Start();
e21f8bf5 161
d4643a10 162 while (myDigitList->GetEntries()) {
7230691d 163
d4643a10 164 for (Int_t iDig=0; iDig<myDigitList->GetEntries(); iDig++) {
7230691d 165
d4643a10 166 fCurrentDigit = (AliMFTDigit*) myDigitList->At(iDig);
e21f8bf5 167
168 if (!iDig) {
169 if (fCurrentDigit->GetDetElemID() != currentDetElem) {
170 // first iteration over the digits of a specific detection element
171 currentDetElem = fCurrentDigit->GetDetElemID();
172 currentDetElemLocal = fSegmentation->GetDetElemLocalID(currentDetElem);
e21f8bf5 173 cycleOverDigits = 0;
174 myCutForAvailableDigits = fCutForAvailableDigits;
175 }
176 else if (fCurrentDigit->GetDetElemID()==currentDetElem && areThereSkippedDigits) {
177 // second (or further) iteration over the digits of a specific detection element
178 cycleOverDigits++;
179 myCutForAvailableDigits -= 0.5;
180 }
181 areThereSkippedDigits = kFALSE;
182 }
183 else {
184 areThereSkippedDigits = kTRUE;
185 if (fCurrentDigit->GetDetElemID() != currentDetElem) break;
186 }
187
d4643a10 188 isDigAvailableForNewCluster = kTRUE;
7230691d 189
e21f8bf5 190 for (Int_t iCluster=0; iCluster<clustersPerDetElem[currentDetElemLocal]->GetEntries(); iCluster++) {
191 fCurrentCluster = (AliMFTCluster*) clustersPerDetElem[currentDetElemLocal]->At(iCluster);
d4643a10 192 if (fCurrentCluster->GetDistanceFromPixel(fCurrentDigit) < fCutForAttachingDigits) {
193 fCurrentCluster->AddPixel(fCurrentDigit);
194 myDigitList->Remove(fCurrentDigit);
195 myDigitList->Compress();
196 iDig--;
197 isDigAvailableForNewCluster = kFALSE;
198 break;
199 }
200 if (fCurrentCluster->GetDistanceFromPixel(fCurrentDigit) < myCutForAvailableDigits) isDigAvailableForNewCluster=kFALSE;
201 }
7230691d 202
d4643a10 203 if (isDigAvailableForNewCluster) {
204 AliMFTCluster *newCluster = new AliMFTCluster();
205 newCluster->AddPixel(fCurrentDigit);
206 myDigitList->Remove(fCurrentDigit);
207 myDigitList->Compress();
208 iDig--;
e21f8bf5 209 new ((*clustersPerDetElem[currentDetElemLocal])[clustersPerDetElem[currentDetElemLocal]->GetEntries()]) AliMFTCluster(*newCluster);
210 delete newCluster;
d4643a10 211 }
e21f8bf5 212
d4643a10 213 } // end of cycle over the digits
7230691d 214
d4643a10 215 } // no more digits to check in current plane!
7230691d 216
65273893 217 fStopWatch -> Print("m");
e21f8bf5 218
65273893 219 printf("Plane %d: clusters found in %f seconds\n",iPlane,fStopWatch->CpuTime());
220 fStopWatch->Start();
e21f8bf5 221
222 // Now we merge the cluster lists coming from each detection element, to build the cluster list of the plane
223
65273893 224 Double_t misalignmentPhi = 2.*TMath::Pi()*gRandom->Rndm();
225 Double_t misalignmentX = fMisalignmentMagnitude*TMath::Cos(misalignmentPhi);
226 Double_t misalignmentY = fMisalignmentMagnitude*TMath::Sin(misalignmentPhi);
227
e21f8bf5 228 AliMFTCluster *newCluster = NULL;
229 for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) {
230 for (Int_t iCluster=0; iCluster<clustersPerDetElem[iDetElem]->GetEntries(); iCluster++) {
231 newCluster = (AliMFTCluster*) (clustersPerDetElem[iDetElem]->At(iCluster));
232 newCluster -> TerminateCluster();
65273893 233 if (fApplyMisalignment) {
234 newCluster -> SetClusterEditable(kTRUE);
235 newCluster -> SetX(newCluster->GetX()+misalignmentX);
236 newCluster -> SetY(newCluster->GetY()+misalignmentY);
237 newCluster -> SetClusterEditable(kFALSE);
238 }
026547c6 239 new ((*fClustersPerPlane[iPlane])[fClustersPerPlane[iPlane]->GetEntries()]) AliMFTCluster(*newCluster);
e21f8bf5 240 }
d4643a10 241 }
7230691d 242
65273893 243 printf("%d Clusters in plane %02d merged in %f seconds\n", fClustersPerPlane[iPlane]->GetEntries(), iPlane, fStopWatch->CpuTime());
e21f8bf5 244
e21f8bf5 245 for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) {
246 clustersPerDetElem[iDetElem] -> Delete();
247 delete clustersPerDetElem[iDetElem];
248 }
820b4d9e 249
b5ab1ac4 250 myDigitList -> Delete();
251
d4643a10 252 } // end of cycle over the planes
820b4d9e 253
254}
255
256//====================================================================================================================================================
257
258void AliMFTClusterFinder::MakeClusterBranch(TTree *treeCluster) {
259
260 // Creating the cluster branches, one for each plane (see AliMFTReconstructor::Reconstruct)
261
262 AliDebug(1, "Making Cluster Branch");
263
264 CreateClusters();
265
266 if (treeCluster) {
267 for(Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
268 AliDebug(1, Form("Setting Branch Plane_%02d for treeCluster",iPlane));
d6080682 269 if (treeCluster->GetBranch(Form("Plane_%02d",iPlane))) continue;
820b4d9e 270 AliDebug(1, Form("Branch Plane_%02d does not exist, creating!",iPlane));
d6080682 271 treeCluster->Branch(Form("Plane_%02d",iPlane), &(fClustersPerPlane[iPlane]));
820b4d9e 272 }
273 }
274
275}
276
277//====================================================================================================================================================
278
279void AliMFTClusterFinder::SetClusterTreeAddress(TTree *treeCluster) {
280
281 // Addressing the cluster branches, one for each plane (see AliMFTReconstructor::Reconstruct)
282
283 if (treeCluster && treeCluster->GetBranch("Plane_00")) {
284 CreateClusters();
285 for(Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
286 if (treeCluster->GetBranch(Form("Plane_%02d",iPlane))) {
287 treeCluster->SetBranchAddress(Form("Plane_%02d",iPlane), &(fClustersPerPlane[iPlane]));
288 }
289 else AliError(Form("No branch available with name Plane_%02d", iPlane));
290 }
291 }
292
293}
294
295//====================================================================================================================================================
296
297void AliMFTClusterFinder::CreateClusters() {
298
299 // create cluster list
300
301 AliDebug(1, Form("Creating clusters list: nPlanes = %d",fNPlanes));
302
303 if (fClustersPerPlane[0]) return;
304
305 for(Int_t iPlane=0; iPlane<fNPlanes; iPlane++) {
306 AliDebug(1, Form("plane %02d", iPlane));
307 fClustersPerPlane[iPlane] = new TClonesArray("AliMFTCluster");
ffc53def 308 fClustersPerPlane[iPlane] -> SetOwner(kTRUE);
309
820b4d9e 310 }
311
312}
313
314//====================================================================================================================================================