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