d15a28e7 |
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 | |
b2a60966 |
16 | /* $Id$ */ |
17 | |
d72dfbc3 |
18 | /* $Log: |
19 | 1 October 2000. Yuri Kharlov: |
20 | AreNeighbours() |
21 | PPSD upper layer is considered if number of layers>1 |
22 | |
23 | 18 October 2000. Yuri Kharlov: |
24 | AliPHOSClusterizerv1() |
25 | CPV clusterizing parameters added |
26 | |
27 | MakeClusters() |
28 | After first PPSD digit remove EMC digits only once |
29 | */ |
9a1398dd |
30 | //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute) |
d15a28e7 |
31 | ////////////////////////////////////////////////////////////////////////////// |
9a1398dd |
32 | // Clusterization class. Performs clusterization (collects neighbouring active cells) and |
a4e98857 |
33 | // unfolds the clusters having several local maxima. |
34 | // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints), |
9a1398dd |
35 | // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all |
f035f6ce |
36 | // parameters including input digits branch title, thresholds etc.) |
a4e98857 |
37 | // This TTask is normally called from Reconstructioner, but can as well be used in |
38 | // standalone mode. |
39 | // Use Case: |
40 | // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root") |
41 | // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated |
9a1398dd |
42 | // //reads gAlice from header file "..." |
a4e98857 |
43 | // root [1] cl->ExecuteTask() |
9a1398dd |
44 | // //finds RecPoints in all events stored in galice.root |
a4e98857 |
45 | // root [2] cl->SetDigitsBranch("digits2") |
f035f6ce |
46 | // //sets another title for Digitis (input) branch |
a4e98857 |
47 | // root [3] cl->SetRecPointsBranch("recp2") |
f035f6ce |
48 | // //sets another title four output branches |
a4e98857 |
49 | // root [4] cl->SetEmcLocalMaxCut(0.03) |
9a1398dd |
50 | // //set clusterization parameters |
a4e98857 |
51 | // root [5] cl->ExecuteTask("deb all time") |
9a1398dd |
52 | // //once more finds RecPoints options are |
53 | // // deb - print number of found rec points |
54 | // // deb all - print number of found RecPoints and some their characteristics |
55 | // // time - print benchmarking results |
ed4205d8 |
56 | |
d15a28e7 |
57 | // --- ROOT system --- |
58 | |
9a1398dd |
59 | #include "TROOT.h" |
60 | #include "TFile.h" |
61 | #include "TFolder.h" |
d15a28e7 |
62 | #include "TMath.h" |
9a1398dd |
63 | #include "TMinuit.h" |
64 | #include "TTree.h" |
65 | #include "TSystem.h" |
66 | #include "TBenchmark.h" |
d15a28e7 |
67 | |
68 | // --- Standard library --- |
69 | |
de9ec31b |
70 | #include <iostream.h> |
9a1398dd |
71 | #include <iomanip.h> |
d15a28e7 |
72 | |
73 | // --- AliRoot header files --- |
74 | |
75 | #include "AliPHOSClusterizerv1.h" |
9a1398dd |
76 | #include "AliPHOSCpvRecPoint.h" |
d15a28e7 |
77 | #include "AliPHOSDigit.h" |
9a1398dd |
78 | #include "AliPHOSDigitizer.h" |
d15a28e7 |
79 | #include "AliPHOSEmcRecPoint.h" |
9a1398dd |
80 | #include "AliPHOS.h" |
7b7c1533 |
81 | #include "AliPHOSGetter.h" |
9a1398dd |
82 | #include "AliRun.h" |
d15a28e7 |
83 | |
84 | ClassImp(AliPHOSClusterizerv1) |
f035f6ce |
85 | |
d15a28e7 |
86 | //____________________________________________________________________________ |
7b7c1533 |
87 | AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer() |
d15a28e7 |
88 | { |
f035f6ce |
89 | // default ctor (to be used mainly by Streamer) |
f035f6ce |
90 | |
9a1398dd |
91 | fNumberOfCpvClusters = 0 ; |
d15a28e7 |
92 | fNumberOfEmcClusters = 0 ; |
f035f6ce |
93 | |
9a1398dd |
94 | fCpvClusteringThreshold = 0.0; |
c3c187e5 |
95 | fEmcClusteringThreshold = 0.2; |
9a1398dd |
96 | |
97 | fEmcLocMaxCut = 0.03 ; |
98 | fCpvLocMaxCut = 0.03 ; |
99 | |
100 | fW0 = 4.5 ; |
101 | fW0CPV = 4.0 ; |
9a1398dd |
102 | |
9688c1dd |
103 | fEmcTimeGate = 1.e-8 ; |
104 | |
105 | fToUnfold = kTRUE ; |
106 | |
7b7c1533 |
107 | fHeaderFileName = "" ; |
108 | fDigitsBranchTitle = "" ; |
9688c1dd |
109 | fRecPointsInRun = 0 ; |
9a1398dd |
110 | } |
7b7c1533 |
111 | |
9a1398dd |
112 | //____________________________________________________________________________ |
7b7c1533 |
113 | AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* name) |
114 | :AliPHOSClusterizer(headerFile, name) |
9a1398dd |
115 | { |
a4e98857 |
116 | // ctor with the indication of the file where header Tree and digits Tree are stored |
9a1398dd |
117 | |
7b7c1533 |
118 | |
9a1398dd |
119 | fNumberOfCpvClusters = 0 ; |
120 | fNumberOfEmcClusters = 0 ; |
f035f6ce |
121 | |
ed4205d8 |
122 | fCpvClusteringThreshold = 0.0; |
9a1398dd |
123 | fEmcClusteringThreshold = 0.2; |
9a1398dd |
124 | |
125 | fEmcLocMaxCut = 0.03 ; |
126 | fCpvLocMaxCut = 0.03 ; |
127 | |
d15a28e7 |
128 | fW0 = 4.5 ; |
c3c187e5 |
129 | fW0CPV = 4.0 ; |
9688c1dd |
130 | |
131 | fEmcTimeGate = 1.e-8 ; |
9a1398dd |
132 | |
2bd5457f |
133 | fToUnfold = kTRUE ; |
9a1398dd |
134 | |
7b7c1533 |
135 | fHeaderFileName = GetTitle() ; |
136 | fDigitsBranchTitle = GetName() ; |
9688c1dd |
137 | |
138 | TString clusterizerName( GetName()) ; |
139 | clusterizerName.Append(":") ; |
140 | clusterizerName.Append(Version()) ; |
141 | SetName(clusterizerName) ; |
2b60655b |
142 | fRecPointsInRun = 0 ; |
143 | |
2bd5457f |
144 | Init() ; |
9a1398dd |
145 | |
146 | } |
9688c1dd |
147 | //____________________________________________________________________________ |
148 | AliPHOSClusterizerv1::~AliPHOSClusterizerv1() |
149 | { |
150 | } |
9a1398dd |
151 | //____________________________________________________________________________ |
3758d9fc |
152 | Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const |
153 | { |
154 | if(absId <= fEmcCrystals) //calibrate as EMC |
155 | return fADCpedestalEmc + amp*fADCchanelEmc ; |
156 | else //Digitize as CPV |
157 | return fADCpedestalCpv+ amp*fADCchanelCpv ; |
158 | } |
159 | //____________________________________________________________________________ |
a4e98857 |
160 | void AliPHOSClusterizerv1::Exec(Option_t * option) |
161 | { |
7b7c1533 |
162 | // Steering method |
9a1398dd |
163 | |
7b7c1533 |
164 | if( strcmp(GetName(), "")== 0 ) |
165 | Init() ; |
9a1398dd |
166 | |
167 | if(strstr(option,"tim")) |
7d493c2c |
168 | gBenchmark->Start("PHOSClusterizer"); |
9a1398dd |
169 | |
7b7c1533 |
170 | if(strstr(option,"print")) |
171 | Print("") ; |
172 | |
127e12ac |
173 | gAlice->GetEvent(0) ; |
9688c1dd |
174 | |
175 | //check, if the branch with name of this" already exits? |
7b7c1533 |
176 | TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ; |
177 | TIter next(lob) ; |
178 | TBranch * branch = 0 ; |
179 | Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ; |
7b7c1533 |
180 | |
9688c1dd |
181 | TString branchname = GetName() ; |
182 | branchname.Remove(branchname.Index(Version())-1) ; |
183 | |
7b7c1533 |
184 | while ( (branch = (TBranch*)next()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) { |
9688c1dd |
185 | if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) ) |
7b7c1533 |
186 | phosemcfound = kTRUE ; |
187 | |
9688c1dd |
188 | else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) ) |
7b7c1533 |
189 | phoscpvfound = kTRUE ; |
190 | |
9688c1dd |
191 | else if ((strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) |
7b7c1533 |
192 | clusterizerfound = kTRUE ; |
193 | } |
194 | |
195 | if ( phoscpvfound || phosemcfound || clusterizerfound ) { |
196 | cerr << "WARNING: AliPHOSClusterizer::Exec -> Emc(Cpv)RecPoints and/or Clusterizer branch with name " |
9688c1dd |
197 | << branchname.Data() << " already exits" << endl ; |
7b7c1533 |
198 | return ; |
199 | } |
200 | |
127e12ac |
201 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
7b7c1533 |
202 | Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ; |
203 | Int_t ievent ; |
204 | |
205 | for(ievent = 0; ievent < nevents; ievent++){ |
01a599c9 |
206 | |
3758d9fc |
207 | if(ievent == 0) GetCalibrationParameters() ; |
127e12ac |
208 | |
209 | fNumberOfEmcClusters = 0 ; |
210 | fNumberOfCpvClusters = 0 ; |
211 | |
212 | gime->Event(ievent,"D") ; |
9688c1dd |
213 | |
214 | // if(!ReadDigits(ievent)) continue; //reads digits for event ievent |
215 | |
9a1398dd |
216 | MakeClusters() ; |
217 | |
9688c1dd |
218 | if(fToUnfold) MakeUnfolding() ; |
7b7c1533 |
219 | |
220 | WriteRecPoints(ievent) ; |
221 | |
94de8339 |
222 | if(strstr(option,"deb")) |
223 | PrintRecPoints(option) ; |
224 | |
225 | //increment the total number of digits per run |
226 | fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ; |
227 | fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ; |
228 | } |
9a1398dd |
229 | |
230 | if(strstr(option,"tim")){ |
231 | gBenchmark->Stop("PHOSClusterizer"); |
232 | cout << "AliPHOSClusterizer:" << endl ; |
233 | cout << " took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing " |
7b7c1533 |
234 | << gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ; |
9a1398dd |
235 | cout << endl ; |
236 | } |
237 | |
9a1398dd |
238 | } |
239 | |
240 | //____________________________________________________________________________ |
a0636361 |
241 | Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy, |
d1de15f5 |
242 | Int_t nPar, Float_t * fitparameters) const |
9a1398dd |
243 | { |
244 | // Calls TMinuit to fit the energy distribution of a cluster with several maxima |
a4e98857 |
245 | // The initial values for fitting procedure are set equal to the positions of local maxima. |
f035f6ce |
246 | // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers |
9a1398dd |
247 | |
7b7c1533 |
248 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
249 | TClonesArray * digits = gime->Digits() ; |
250 | |
251 | |
9a1398dd |
252 | gMinuit->mncler(); // Reset Minuit's list of paramters |
253 | gMinuit->SetPrintLevel(-1) ; // No Printout |
254 | gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ; |
255 | // To set the address of the minimization function |
256 | |
257 | TList * toMinuit = new TList(); |
258 | toMinuit->AddAt(emcRP,0) ; |
7b7c1533 |
259 | toMinuit->AddAt(digits,1) ; |
9a1398dd |
260 | |
261 | gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare |
262 | |
263 | // filling initial values for fit parameters |
264 | AliPHOSDigit * digit ; |
265 | |
266 | Int_t ierflg = 0; |
267 | Int_t index = 0 ; |
268 | Int_t nDigits = (Int_t) nPar / 3 ; |
269 | |
270 | Int_t iDigit ; |
271 | |
7b7c1533 |
272 | const AliPHOSGeometry * geom = gime->PHOSGeometry() ; |
9a1398dd |
273 | |
274 | for(iDigit = 0; iDigit < nDigits; iDigit++){ |
a0636361 |
275 | digit = maxAt[iDigit]; |
9a1398dd |
276 | |
277 | Int_t relid[4] ; |
7b7c1533 |
278 | Float_t x = 0.; |
279 | Float_t z = 0.; |
280 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
281 | geom->RelPosInModule(relid, x, z) ; |
9a1398dd |
282 | |
283 | Float_t energy = maxAtEnergy[iDigit] ; |
284 | |
285 | gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ; |
286 | index++ ; |
287 | if(ierflg != 0){ |
288 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ; |
289 | return kFALSE; |
290 | } |
291 | gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ; |
292 | index++ ; |
293 | if(ierflg != 0){ |
294 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ; |
295 | return kFALSE; |
296 | } |
297 | gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ; |
298 | index++ ; |
299 | if(ierflg != 0){ |
300 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ; |
301 | return kFALSE; |
302 | } |
303 | } |
304 | |
305 | Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly |
306 | // depends on it. |
307 | Double_t p1 = 1.0 ; |
308 | Double_t p2 = 0.0 ; |
309 | |
310 | gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls |
311 | gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient |
312 | gMinuit->SetMaxIterations(5); |
313 | gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings |
314 | |
315 | gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize |
316 | |
317 | if(ierflg == 4){ // Minimum not found |
318 | cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ; |
319 | return kFALSE ; |
320 | } |
321 | for(index = 0; index < nPar; index++){ |
322 | Double_t err ; |
323 | Double_t val ; |
324 | gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index |
325 | fitparameters[index] = val ; |
326 | } |
327 | |
328 | delete toMinuit ; |
329 | return kTRUE; |
c3c187e5 |
330 | |
d15a28e7 |
331 | } |
332 | |
3758d9fc |
333 | //____________________________________________________________________________ |
334 | void AliPHOSClusterizerv1::GetCalibrationParameters() |
335 | { |
336 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
337 | TString branchname = GetName() ; |
338 | branchname.Remove(branchname.Index(Version())-1) ; |
339 | AliPHOSDigitizer * dig = gime->Digitizer(branchname) ; |
340 | fADCchanelEmc = dig->GetEMCchannel() ; |
341 | fADCpedestalEmc = dig->GetEMCpedestal(); |
342 | |
343 | fADCchanelCpv = dig->GetCPVchannel() ; |
344 | fADCpedestalCpv = dig->GetCPVpedestal() ; |
345 | |
346 | } |
d15a28e7 |
347 | //____________________________________________________________________________ |
a4e98857 |
348 | void AliPHOSClusterizerv1::Init() |
349 | { |
2bd5457f |
350 | // Make all memory allocations which can not be done in default constructor. |
351 | // Attach the Clusterizer task to the list of PHOS tasks |
7b7c1533 |
352 | |
353 | if ( strcmp(GetTitle(), "") == 0 ) |
354 | SetTitle("galice.root") ; |
2bd5457f |
355 | |
9688c1dd |
356 | TString branchname = GetName() ; |
357 | branchname.Remove(branchname.Index(Version())-1) ; |
9a1398dd |
358 | |
9688c1dd |
359 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), branchname) ; |
7b7c1533 |
360 | if ( gime == 0 ) { |
361 | cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ; |
362 | return ; |
363 | } |
364 | |
3758d9fc |
365 | const AliPHOSGeometry * geom = gime->PHOSGeometry() ; |
366 | fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ; |
367 | |
7b7c1533 |
368 | if(!gMinuit) |
369 | gMinuit = new TMinuit(100) ; |
370 | |
127e12ac |
371 | gime->PostClusterizer(this) ; |
7b7c1533 |
372 | // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/recpointsName |
9688c1dd |
373 | gime->PostRecPoints(branchname ) ; |
127e12ac |
374 | |
9688c1dd |
375 | gime->PostDigits(branchname) ; |
376 | gime->PostDigitizer(branchname) ; |
7b7c1533 |
377 | |
9a1398dd |
378 | } |
7b7c1533 |
379 | |
9a1398dd |
380 | //____________________________________________________________________________ |
381 | Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const |
d15a28e7 |
382 | { |
b2a60966 |
383 | // Gives the neighbourness of two digits = 0 are not neighbour but continue searching |
384 | // = 1 are neighbour |
385 | // = 2 are not neighbour but do not continue searching |
a4e98857 |
386 | // neighbours are defined as digits having at least a common vertex |
b2a60966 |
387 | // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster |
388 | // which is compared to a digit (d2) not yet in a cluster |
389 | |
7b7c1533 |
390 | const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ; |
391 | |
d15a28e7 |
392 | Int_t rv = 0 ; |
393 | |
d15a28e7 |
394 | Int_t relid1[4] ; |
7b7c1533 |
395 | geom->AbsToRelNumbering(d1->GetId(), relid1) ; |
d15a28e7 |
396 | |
397 | Int_t relid2[4] ; |
7b7c1533 |
398 | geom->AbsToRelNumbering(d2->GetId(), relid2) ; |
d15a28e7 |
399 | |
9688c1dd |
400 | if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module |
92862013 |
401 | Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ; |
402 | Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ; |
d15a28e7 |
403 | |
92862013 |
404 | if (( coldiff <= 1 ) && ( rowdiff <= 1 )){ |
9688c1dd |
405 | if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate)) |
d15a28e7 |
406 | rv = 1 ; |
407 | } |
408 | else { |
409 | if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1)) |
410 | rv = 2; // Difference in row numbers is too large to look further |
411 | } |
412 | |
413 | } |
414 | else { |
415 | |
9688c1dd |
416 | if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) ) |
d15a28e7 |
417 | rv=2 ; |
418 | |
419 | } |
d72dfbc3 |
420 | |
d15a28e7 |
421 | return rv ; |
422 | } |
423 | |
d15a28e7 |
424 | |
425 | //____________________________________________________________________________ |
9a1398dd |
426 | Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const |
d15a28e7 |
427 | { |
b2a60966 |
428 | // Tells if (true) or not (false) the digit is in a PHOS-EMC module |
429 | |
9f616d61 |
430 | Bool_t rv = kFALSE ; |
7b7c1533 |
431 | const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ; |
d15a28e7 |
432 | |
2b629790 |
433 | Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ(); |
d15a28e7 |
434 | |
2b629790 |
435 | if(digit->GetId() <= nEMC ) rv = kTRUE; |
ed4205d8 |
436 | |
437 | return rv ; |
438 | } |
439 | |
ed4205d8 |
440 | //____________________________________________________________________________ |
9a1398dd |
441 | Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const |
ed4205d8 |
442 | { |
fad3e5b9 |
443 | // Tells if (true) or not (false) the digit is in a PHOS-CPV module |
ed4205d8 |
444 | |
445 | Bool_t rv = kFALSE ; |
7b7c1533 |
446 | const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ; |
ed4205d8 |
447 | |
2b629790 |
448 | Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ(); |
ed4205d8 |
449 | |
2b629790 |
450 | if(digit->GetId() > nEMC ) rv = kTRUE; |
d15a28e7 |
451 | |
452 | return rv ; |
453 | } |
9a1398dd |
454 | |
455 | //____________________________________________________________________________ |
7b7c1533 |
456 | void AliPHOSClusterizerv1::WriteRecPoints(Int_t event) |
a4e98857 |
457 | { |
7b7c1533 |
458 | |
459 | // Creates new branches with given title |
a4e98857 |
460 | // fills and writes into TreeR. |
9688c1dd |
461 | |
462 | TString branchName(GetName() ) ; |
463 | branchName.Remove(branchName.Index(Version())-1) ; |
464 | |
7b7c1533 |
465 | AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ; |
127e12ac |
466 | TObjArray * emcRecPoints = gime->EmcRecPoints(branchName) ; |
467 | TObjArray * cpvRecPoints = gime->CpvRecPoints(branchName) ; |
468 | TClonesArray * digits = gime->Digits(branchName) ; |
7b7c1533 |
469 | |
9a1398dd |
470 | Int_t index ; |
01a599c9 |
471 | //Evaluate position, dispersion and other RecPoint properties... |
7b7c1533 |
472 | for(index = 0; index < emcRecPoints->GetEntries(); index++) |
473 | ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ; |
9a1398dd |
474 | |
7b7c1533 |
475 | emcRecPoints->Sort() ; |
9a1398dd |
476 | |
7b7c1533 |
477 | for(index = 0; index < emcRecPoints->GetEntries(); index++) |
478 | ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ; |
9a1398dd |
479 | |
7b7c1533 |
480 | emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ; |
761e34c0 |
481 | |
9a1398dd |
482 | //Now the same for CPV |
7b7c1533 |
483 | for(index = 0; index < cpvRecPoints->GetEntries(); index++) |
484 | ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ; |
9a1398dd |
485 | |
7b7c1533 |
486 | cpvRecPoints->Sort() ; |
9a1398dd |
487 | |
7b7c1533 |
488 | for(index = 0; index < cpvRecPoints->GetEntries(); index++) |
489 | ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ; |
9a1398dd |
490 | |
7b7c1533 |
491 | cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ; |
9a1398dd |
492 | |
9a1398dd |
493 | //Make branches in TreeR for RecPoints and Clusterizer |
494 | char * filename = 0; |
495 | if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name |
496 | filename = new char[strlen(gAlice->GetBaseFile())+20] ; |
497 | sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ; |
498 | } |
499 | |
500 | //Make new branches |
501 | TDirectory *cwd = gDirectory; |
502 | |
7b7c1533 |
503 | |
9a1398dd |
504 | Int_t bufferSize = 32000 ; |
505 | Int_t splitlevel = 0 ; |
01a599c9 |
506 | |
507 | //First EMC |
7b7c1533 |
508 | TBranch * emcBranch = gAlice->TreeR()->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel); |
509 | emcBranch->SetTitle(branchName); |
9a1398dd |
510 | if (filename) { |
511 | emcBranch->SetFile(filename); |
512 | TIter next( emcBranch->GetListOfBranches()); |
761e34c0 |
513 | TBranch * sb ; |
514 | while ((sb=(TBranch*)next())) { |
515 | sb->SetFile(filename); |
9a1398dd |
516 | } |
01a599c9 |
517 | |
9a1398dd |
518 | cwd->cd(); |
519 | } |
520 | |
521 | //Now CPV branch |
7b7c1533 |
522 | TBranch * cpvBranch = gAlice->TreeR()->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel); |
523 | cpvBranch->SetTitle(branchName); |
9a1398dd |
524 | if (filename) { |
525 | cpvBranch->SetFile(filename); |
526 | TIter next( cpvBranch->GetListOfBranches()); |
761e34c0 |
527 | TBranch * sb; |
528 | while ((sb=(TBranch*)next())) { |
529 | sb->SetFile(filename); |
9a1398dd |
530 | } |
531 | cwd->cd(); |
532 | } |
533 | |
534 | //And Finally clusterizer branch |
127e12ac |
535 | AliPHOSClusterizerv1 * cl = (AliPHOSClusterizerv1*)gime->Clusterizer(branchName) ; |
7b7c1533 |
536 | TBranch * clusterizerBranch = gAlice->TreeR()->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1", |
9a1398dd |
537 | &cl,bufferSize,splitlevel); |
7b7c1533 |
538 | clusterizerBranch->SetTitle(branchName); |
9a1398dd |
539 | if (filename) { |
540 | clusterizerBranch->SetFile(filename); |
541 | TIter next( clusterizerBranch->GetListOfBranches()); |
761e34c0 |
542 | TBranch * sb ; |
543 | while ((sb=(TBranch*)next())) { |
544 | sb->SetFile(filename); |
9a1398dd |
545 | } |
546 | cwd->cd(); |
547 | } |
01a599c9 |
548 | emcBranch ->Fill() ; |
549 | cpvBranch ->Fill() ; |
761e34c0 |
550 | clusterizerBranch->Fill() ; |
eec3ac52 |
551 | |
780a31c1 |
552 | gAlice->TreeR()->Write(0,kOverwrite) ; |
553 | |
554 | delete [] filename ; |
9a1398dd |
555 | |
556 | } |
557 | |
558 | //____________________________________________________________________________ |
559 | void AliPHOSClusterizerv1::MakeClusters() |
560 | { |
561 | // Steering method to construct the clusters stored in a list of Reconstructed Points |
562 | // A cluster is defined as a list of neighbour digits |
127e12ac |
563 | TString branchName(GetName()) ; |
564 | branchName.Remove(branchName.Index(Version())-1) ; |
d15a28e7 |
565 | |
7b7c1533 |
566 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
567 | |
127e12ac |
568 | TObjArray * emcRecPoints = gime->EmcRecPoints(branchName) ; |
569 | TObjArray * cpvRecPoints = gime->CpvRecPoints(branchName) ; |
7d493c2c |
570 | emcRecPoints->Delete() ; |
571 | cpvRecPoints->Delete() ; |
7b7c1533 |
572 | |
127e12ac |
573 | TClonesArray * digits = gime->Digits(branchName) ; |
7b7c1533 |
574 | TClonesArray * digitsC = (TClonesArray*)digits->Clone() ; |
575 | |
576 | |
d15a28e7 |
577 | // Clusterization starts |
9a1398dd |
578 | |
7b7c1533 |
579 | TIter nextdigit(digitsC) ; |
d15a28e7 |
580 | AliPHOSDigit * digit ; |
92862013 |
581 | Bool_t notremoved = kTRUE ; |
6ad0bfa0 |
582 | |
7b7c1533 |
583 | while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC |
9a1398dd |
584 | AliPHOSRecPoint * clu = 0 ; |
c161df70 |
585 | |
d1de15f5 |
586 | TArrayI clusterdigitslist(1500) ; |
d15a28e7 |
587 | Int_t index ; |
f2bc1b87 |
588 | |
3758d9fc |
589 | if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) || |
590 | ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) { |
7a9d98f9 |
591 | |
d15a28e7 |
592 | Int_t iDigitInCluster = 0 ; |
7b7c1533 |
593 | |
6ad0bfa0 |
594 | if ( IsInEmc(digit) ) { |
83974468 |
595 | // start a new EMC RecPoint |
7b7c1533 |
596 | if(fNumberOfEmcClusters >= emcRecPoints->GetSize()) |
597 | emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ; |
598 | |
73a68ccb |
599 | emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ; |
7b7c1533 |
600 | clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ; |
7f5d510c |
601 | fNumberOfEmcClusters++ ; |
3758d9fc |
602 | clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ; |
9a1398dd |
603 | clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ; |
9f616d61 |
604 | iDigitInCluster++ ; |
7b7c1533 |
605 | digitsC->Remove(digit) ; |
ca77b032 |
606 | |
d72dfbc3 |
607 | } else { |
83974468 |
608 | |
9688c1dd |
609 | // start a new CPV cluster |
7b7c1533 |
610 | if(fNumberOfCpvClusters >= cpvRecPoints->GetSize()) |
611 | cpvRecPoints->Expand(2*fNumberOfCpvClusters+1); |
612 | |
73a68ccb |
613 | cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ; |
fad3e5b9 |
614 | |
9688c1dd |
615 | clu = (AliPHOSCpvRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters) ; |
7b7c1533 |
616 | fNumberOfCpvClusters++ ; |
3758d9fc |
617 | clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ; |
9a1398dd |
618 | clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ; |
9f616d61 |
619 | iDigitInCluster++ ; |
7b7c1533 |
620 | digitsC->Remove(digit) ; |
d15a28e7 |
621 | nextdigit.Reset() ; |
622 | |
7b7c1533 |
623 | // Here we remove remaining EMC digits, which cannot make a cluster |
fad3e5b9 |
624 | |
92862013 |
625 | if( notremoved ) { |
9f616d61 |
626 | while( ( digit = (AliPHOSDigit *)nextdigit() ) ) { |
9f616d61 |
627 | if( IsInEmc(digit) ) |
7b7c1533 |
628 | digitsC->Remove(digit) ; |
d15a28e7 |
629 | else |
630 | break ; |
d72dfbc3 |
631 | } |
632 | notremoved = kFALSE ; |
633 | } |
d15a28e7 |
634 | |
635 | } // else |
636 | |
637 | nextdigit.Reset() ; |
fad3e5b9 |
638 | |
d15a28e7 |
639 | AliPHOSDigit * digitN ; |
640 | index = 0 ; |
9f616d61 |
641 | while (index < iDigitInCluster){ // scan over digits already in cluster |
7b7c1533 |
642 | digit = (AliPHOSDigit*)digits->At(clusterdigitslist[index]) ; |
9f616d61 |
643 | index++ ; |
d15a28e7 |
644 | while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits |
d72dfbc3 |
645 | Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!! |
d15a28e7 |
646 | switch (ineb ) { |
9f616d61 |
647 | case 0 : // not a neighbour |
d72dfbc3 |
648 | break ; |
9f616d61 |
649 | case 1 : // are neighbours |
3758d9fc |
650 | clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ; |
9a1398dd |
651 | clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ; |
9f616d61 |
652 | iDigitInCluster++ ; |
7b7c1533 |
653 | digitsC->Remove(digitN) ; |
d15a28e7 |
654 | break ; |
9f616d61 |
655 | case 2 : // too far from each other |
d15a28e7 |
656 | goto endofloop; |
657 | } // switch |
658 | |
659 | } // while digitN |
fad3e5b9 |
660 | |
d15a28e7 |
661 | endofloop: ; |
662 | nextdigit.Reset() ; |
663 | |
664 | } // loop over cluster |
ad8cfaf4 |
665 | |
ad8cfaf4 |
666 | } // energy theshold |
ad8cfaf4 |
667 | |
31aa6d6c |
668 | |
d15a28e7 |
669 | } // while digit |
670 | |
7b7c1533 |
671 | delete digitsC ; |
9688c1dd |
672 | |
9a1398dd |
673 | } |
674 | |
675 | //____________________________________________________________________________ |
a4e98857 |
676 | void AliPHOSClusterizerv1::MakeUnfolding() |
677 | { |
678 | // Unfolds clusters using the shape of an ElectroMagnetic shower |
9688c1dd |
679 | // Performs unfolding of all EMC/CPV clusters |
9a1398dd |
680 | |
7b7c1533 |
681 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
682 | |
683 | const AliPHOSGeometry * geom = gime->PHOSGeometry() ; |
684 | TObjArray * emcRecPoints = gime->EmcRecPoints() ; |
685 | TObjArray * cpvRecPoints = gime->CpvRecPoints() ; |
686 | TClonesArray * digits = gime->Digits() ; |
687 | |
a4e98857 |
688 | // Unfold first EMC clusters |
9a1398dd |
689 | if(fNumberOfEmcClusters > 0){ |
690 | |
7b7c1533 |
691 | Int_t nModulesToUnfold = geom->GetNModules() ; |
9a1398dd |
692 | |
693 | Int_t numberofNotUnfolded = fNumberOfEmcClusters ; |
694 | Int_t index ; |
695 | for(index = 0 ; index < numberofNotUnfolded ; index++){ |
696 | |
7b7c1533 |
697 | AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ; |
9a1398dd |
698 | if(emcRecPoint->GetPHOSMod()> nModulesToUnfold) |
699 | break ; |
700 | |
701 | Int_t nMultipl = emcRecPoint->GetMultiplicity() ; |
a0636361 |
702 | AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ; |
9a1398dd |
703 | Float_t * maxAtEnergy = new Float_t[nMultipl] ; |
7b7c1533 |
704 | Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ; |
9a1398dd |
705 | |
706 | if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0 |
707 | UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ; |
7b7c1533 |
708 | emcRecPoints->Remove(emcRecPoint); |
709 | emcRecPoints->Compress() ; |
9a1398dd |
710 | index-- ; |
711 | fNumberOfEmcClusters -- ; |
712 | numberofNotUnfolded-- ; |
713 | } |
714 | |
715 | delete[] maxAt ; |
716 | delete[] maxAtEnergy ; |
717 | } |
718 | } |
a4e98857 |
719 | // Unfolding of EMC clusters finished |
9a1398dd |
720 | |
721 | |
a4e98857 |
722 | // Unfold now CPV clusters |
9a1398dd |
723 | if(fNumberOfCpvClusters > 0){ |
724 | |
9688c1dd |
725 | Int_t nModulesToUnfold = geom->GetNModules() ; |
9a1398dd |
726 | |
727 | Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ; |
728 | Int_t index ; |
729 | for(index = 0 ; index < numberofCpvNotUnfolded ; index++){ |
730 | |
7b7c1533 |
731 | AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ; |
9a1398dd |
732 | |
733 | if(recPoint->GetPHOSMod()> nModulesToUnfold) |
734 | break ; |
735 | |
736 | AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ; |
737 | |
738 | Int_t nMultipl = emcRecPoint->GetMultiplicity() ; |
a0636361 |
739 | AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ; |
9a1398dd |
740 | Float_t * maxAtEnergy = new Float_t[nMultipl] ; |
7b7c1533 |
741 | Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ; |
9a1398dd |
742 | |
743 | if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0 |
744 | UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ; |
7b7c1533 |
745 | cpvRecPoints->Remove(emcRecPoint); |
746 | cpvRecPoints->Compress() ; |
9a1398dd |
747 | index-- ; |
748 | numberofCpvNotUnfolded-- ; |
749 | fNumberOfCpvClusters-- ; |
750 | } |
751 | |
752 | delete[] maxAt ; |
753 | delete[] maxAtEnergy ; |
754 | } |
755 | } |
756 | //Unfolding of Cpv clusters finished |
757 | |
758 | } |
759 | |
9a1398dd |
760 | //____________________________________________________________________________ |
761 | Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r) |
762 | { |
763 | // Shape of the shower (see PHOS TDR) |
a4e98857 |
764 | // If you change this function, change also the gradient evaluation in ChiSquare() |
9a1398dd |
765 | |
766 | Double_t r4 = r*r*r*r ; |
767 | Double_t r295 = TMath::Power(r, 2.95) ; |
768 | Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ; |
769 | return shape ; |
770 | } |
771 | |
772 | //____________________________________________________________________________ |
773 | void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc, |
774 | Int_t nMax, |
a0636361 |
775 | AliPHOSDigit ** maxAt, |
9a1398dd |
776 | Float_t * maxAtEnergy) |
777 | { |
778 | // Performs the unfolding of a cluster with nMax overlapping showers |
779 | |
7b7c1533 |
780 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
781 | const AliPHOSGeometry * geom = gime->PHOSGeometry() ; |
afa51c4e |
782 | const TClonesArray * digits = gime->Digits() ; |
7b7c1533 |
783 | TObjArray * emcRecPoints = gime->EmcRecPoints() ; |
784 | TObjArray * cpvRecPoints = gime->CpvRecPoints() ; |
785 | |
9a1398dd |
786 | Int_t nPar = 3 * nMax ; |
787 | Float_t * fitparameters = new Float_t[nPar] ; |
788 | |
789 | Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ; |
790 | if( !rv ) { |
791 | // Fit failed, return and remove cluster |
792 | delete[] fitparameters ; |
793 | return ; |
794 | } |
795 | |
796 | // create ufolded rec points and fill them with new energy lists |
797 | // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[] |
798 | // and later correct this number in acordance with actual energy deposition |
799 | |
800 | Int_t nDigits = iniEmc->GetMultiplicity() ; |
801 | Float_t * efit = new Float_t[nDigits] ; |
7b7c1533 |
802 | Float_t xDigit=0.,zDigit=0.,distance=0. ; |
803 | Float_t xpar=0.,zpar=0.,epar=0. ; |
9a1398dd |
804 | Int_t relid[4] ; |
7b7c1533 |
805 | AliPHOSDigit * digit = 0 ; |
9a1398dd |
806 | Int_t * emcDigits = iniEmc->GetDigitsList() ; |
807 | |
808 | Int_t iparam ; |
809 | Int_t iDigit ; |
810 | for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){ |
7b7c1533 |
811 | digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ; |
812 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
813 | geom->RelPosInModule(relid, xDigit, zDigit) ; |
9a1398dd |
814 | efit[iDigit] = 0; |
815 | |
816 | iparam = 0 ; |
817 | while(iparam < nPar ){ |
818 | xpar = fitparameters[iparam] ; |
819 | zpar = fitparameters[iparam+1] ; |
820 | epar = fitparameters[iparam+2] ; |
821 | iparam += 3 ; |
822 | distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
823 | distance = TMath::Sqrt(distance) ; |
824 | efit[iDigit] += epar * ShowerShape(distance) ; |
825 | } |
826 | } |
827 | |
828 | |
829 | // Now create new RecPoints and fill energy lists with efit corrected to fluctuations |
830 | // so that energy deposited in each cell is distributed betwin new clusters proportionally |
831 | // to its contribution to efit |
832 | |
833 | Float_t * emcEnergies = iniEmc->GetEnergiesList() ; |
834 | Float_t ratio ; |
835 | |
836 | iparam = 0 ; |
837 | while(iparam < nPar ){ |
838 | xpar = fitparameters[iparam] ; |
839 | zpar = fitparameters[iparam+1] ; |
840 | epar = fitparameters[iparam+2] ; |
841 | iparam += 3 ; |
842 | |
7b7c1533 |
843 | AliPHOSEmcRecPoint * emcRP = 0 ; |
9a1398dd |
844 | |
845 | if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints... |
846 | |
7b7c1533 |
847 | if(fNumberOfEmcClusters >= emcRecPoints->GetSize()) |
848 | emcRecPoints->Expand(2*fNumberOfEmcClusters) ; |
9a1398dd |
849 | |
73a68ccb |
850 | (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ; |
7b7c1533 |
851 | emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters); |
9a1398dd |
852 | fNumberOfEmcClusters++ ; |
853 | } |
854 | else{//create new entries in fCpvRecPoints |
7b7c1533 |
855 | if(fNumberOfCpvClusters >= cpvRecPoints->GetSize()) |
856 | cpvRecPoints->Expand(2*fNumberOfCpvClusters) ; |
9a1398dd |
857 | |
73a68ccb |
858 | (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ; |
7b7c1533 |
859 | emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters); |
9a1398dd |
860 | fNumberOfCpvClusters++ ; |
861 | } |
862 | |
863 | Float_t eDigit ; |
864 | for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){ |
7b7c1533 |
865 | digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ; |
866 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
867 | geom->RelPosInModule(relid, xDigit, zDigit) ; |
9a1398dd |
868 | distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
869 | distance = TMath::Sqrt(distance) ; |
870 | ratio = epar * ShowerShape(distance) / efit[iDigit] ; |
871 | eDigit = emcEnergies[iDigit] * ratio ; |
872 | emcRP->AddDigit( *digit, eDigit ) ; |
873 | } |
874 | } |
875 | |
876 | delete[] fitparameters ; |
877 | delete[] efit ; |
878 | |
879 | } |
880 | |
881 | //_____________________________________________________________________________ |
882 | void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag) |
883 | { |
a4e98857 |
884 | // Calculates the Chi square for the cluster unfolding minimization |
9a1398dd |
885 | // Number of parameters, Gradient, Chi squared, parameters, what to do |
886 | |
887 | |
888 | TList * toMinuit = (TList*) gMinuit->GetObjectFit() ; |
889 | |
890 | AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ; |
891 | TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ; |
892 | |
893 | |
894 | |
895 | // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit |
896 | |
897 | Int_t * emcDigits = emcRP->GetDigitsList() ; |
898 | |
7b7c1533 |
899 | Int_t nOdigits = emcRP->GetDigitsMultiplicity() ; |
9a1398dd |
900 | |
901 | Float_t * emcEnergies = emcRP->GetEnergiesList() ; |
902 | |
01a599c9 |
903 | const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ; |
9a1398dd |
904 | fret = 0. ; |
905 | Int_t iparam ; |
906 | |
907 | if(iflag == 2) |
908 | for(iparam = 0 ; iparam < nPar ; iparam++) |
909 | Grad[iparam] = 0 ; // Will evaluate gradient |
910 | |
911 | Double_t efit ; |
912 | |
913 | AliPHOSDigit * digit ; |
914 | Int_t iDigit ; |
915 | |
7b7c1533 |
916 | for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) { |
9a1398dd |
917 | |
918 | digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ; |
919 | |
920 | Int_t relid[4] ; |
921 | Float_t xDigit ; |
922 | Float_t zDigit ; |
923 | |
924 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
925 | |
926 | geom->RelPosInModule(relid, xDigit, zDigit) ; |
927 | |
928 | if(iflag == 2){ // calculate gradient |
929 | Int_t iParam = 0 ; |
930 | efit = 0 ; |
931 | while(iParam < nPar ){ |
932 | Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ; |
933 | iParam++ ; |
934 | distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ; |
935 | distance = TMath::Sqrt( distance ) ; |
936 | iParam++ ; |
937 | efit += x[iParam] * ShowerShape(distance) ; |
938 | iParam++ ; |
939 | } |
940 | Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E) |
941 | iParam = 0 ; |
942 | while(iParam < nPar ){ |
943 | Double_t xpar = x[iParam] ; |
944 | Double_t zpar = x[iParam+1] ; |
945 | Double_t epar = x[iParam+2] ; |
946 | Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ); |
947 | Double_t shape = sum * ShowerShape(dr) ; |
948 | Double_t r4 = dr*dr*dr*dr ; |
949 | Double_t r295 = TMath::Power(dr,2.95) ; |
950 | Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) + |
951 | 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ; |
952 | |
953 | Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x |
954 | iParam++ ; |
955 | Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z |
956 | iParam++ ; |
957 | Grad[iParam] += shape ; // Derivative over energy |
958 | iParam++ ; |
959 | } |
960 | } |
961 | efit = 0; |
962 | iparam = 0 ; |
963 | |
964 | while(iparam < nPar ){ |
965 | Double_t xpar = x[iparam] ; |
966 | Double_t zpar = x[iparam+1] ; |
967 | Double_t epar = x[iparam+2] ; |
968 | iparam += 3 ; |
969 | Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
970 | distance = TMath::Sqrt(distance) ; |
971 | efit += epar * ShowerShape(distance) ; |
972 | } |
973 | |
974 | fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ; |
975 | // Here we assume, that sigma = sqrt(E) |
976 | } |
83974468 |
977 | |
d15a28e7 |
978 | } |
979 | |
980 | //____________________________________________________________________________ |
9a1398dd |
981 | void AliPHOSClusterizerv1::Print(Option_t * option)const |
d15a28e7 |
982 | { |
d1de15f5 |
983 | // Print clusterizer parameters |
984 | |
7b7c1533 |
985 | if( strcmp(GetName(), "") !=0 ){ |
9a1398dd |
986 | |
987 | // Print parameters |
7b7c1533 |
988 | |
989 | TString taskName(GetName()) ; |
990 | taskName.ReplaceAll(Version(), "") ; |
991 | |
992 | cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl |
9a1398dd |
993 | << "Clusterizing digits from the file: " << fHeaderFileName.Data() << endl |
994 | << " Branch: " << fDigitsBranchTitle.Data() << endl |
995 | << endl |
996 | << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl |
997 | << " EMC Local Maximum cut = " << fEmcLocMaxCut << endl |
998 | << " EMC Logarothmic weight = " << fW0 << endl |
999 | << endl |
1000 | << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl |
1001 | << " CPV Local Maximum cut = " << fCpvLocMaxCut << endl |
1002 | << " CPV Logarothmic weight = " << fW0CPV << endl |
9688c1dd |
1003 | << endl ; |
9a1398dd |
1004 | if(fToUnfold) |
1005 | cout << " Unfolding on " << endl ; |
1006 | else |
1007 | cout << " Unfolding off " << endl ; |
1008 | |
1009 | cout << "------------------------------------------------------------------" <<endl ; |
1010 | } |
1011 | else |
1012 | cout << " AliPHOSClusterizerv1 not initialized " << endl ; |
1013 | } |
1014 | //____________________________________________________________________________ |
a4e98857 |
1015 | void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option) |
1016 | { |
1017 | // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer |
9a1398dd |
1018 | |
7b7c1533 |
1019 | TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints() ; |
1020 | TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints() ; |
1021 | |
01a599c9 |
1022 | cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ; |
7b7c1533 |
1023 | cout << " Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and " |
1024 | << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ; |
9a1398dd |
1025 | |
2b60655b |
1026 | fRecPointsInRun += emcRecPoints->GetEntriesFast() ; |
1027 | fRecPointsInRun += cpvRecPoints->GetEntriesFast() ; |
1028 | |
9a1398dd |
1029 | if(strstr(option,"all")) { |
1030 | cout << "EMC clusters " << endl ; |
9688c1dd |
1031 | cout << " Index Ene(MeV) Multi Module X Y Z Lambda 1 Lambda 2 # of prim Primaries list " << endl; |
9a1398dd |
1032 | |
1033 | Int_t index ; |
7b7c1533 |
1034 | for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) { |
1035 | AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ; |
9a1398dd |
1036 | TVector3 locpos; |
1037 | rp->GetLocalPosition(locpos); |
9a1398dd |
1038 | Float_t lambda[2]; |
1039 | rp->GetElipsAxis(lambda); |
9a1398dd |
1040 | Int_t * primaries; |
1041 | Int_t nprimaries; |
1042 | primaries = rp->GetPrimaries(nprimaries); |
9a1398dd |
1043 | |
9688c1dd |
1044 | cout << setw(4) << rp->GetIndexInList() << " " |
1045 | << setw(7) << setprecision(3) << rp->GetEnergy() << " " |
1046 | << setw(3) << rp->GetMultiplicity() << " " |
1047 | << setw(1) << rp->GetPHOSMod() << " " |
1048 | << setw(6) << setprecision(2) << locpos.X() << " " |
1049 | << setw(6) << setprecision(2) << locpos.Y() << " " |
1050 | << setw(6) << setprecision(2) << locpos.Z() << " " |
1051 | << setw(4) << setprecision(2) << lambda[0] << " " |
1052 | << setw(4) << setprecision(2) << lambda[1] << " " |
1053 | << setw(2) << nprimaries << " " ; |
1054 | |
9a1398dd |
1055 | for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) |
9688c1dd |
1056 | cout << setw(4) << primaries[iprimary] << " " ; |
1057 | cout << endl ; |
9a1398dd |
1058 | } |
9a1398dd |
1059 | |
9688c1dd |
1060 | //Now plot CPV recPoints |
9a1398dd |
1061 | cout << "EMC clusters " << endl ; |
1062 | cout << " Index " |
1063 | << " Multi " |
1064 | << " Module " |
9a1398dd |
1065 | << " X " |
1066 | << " Y " |
1067 | << " Z " |
1068 | << " # of prim " |
1069 | << " Primaries list " << endl; |
1070 | |
7b7c1533 |
1071 | for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) { |
1072 | AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ; |
9a1398dd |
1073 | cout << setw(6) << rp->GetIndexInList() << " "; |
9688c1dd |
1074 | cout << setw(6) << rp->GetPHOSMod() << " CPV "; |
9a1398dd |
1075 | |
1076 | TVector3 locpos; |
1077 | rp->GetLocalPosition(locpos); |
9688c1dd |
1078 | cout << setw(6) << locpos.X() << " "; |
1079 | cout << setw(6) << locpos.Y() << " "; |
1080 | cout << setw(6) << locpos.Z() << " "; |
9a1398dd |
1081 | |
1082 | Int_t * primaries; |
9688c1dd |
1083 | Int_t nprimaries ; |
9a1398dd |
1084 | primaries = rp->GetPrimaries(nprimaries); |
9688c1dd |
1085 | cout << setw(6) << nprimaries << " "; |
9a1398dd |
1086 | |
1087 | for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) |
1088 | cout << setw(4) << primaries[iprimary] << " "; |
1089 | cout << endl; |
1090 | } |
1091 | |
1092 | |
9688c1dd |
1093 | cout << "-----------------------------------------------------------------------"<<endl ; |
9a1398dd |
1094 | } |
d15a28e7 |
1095 | } |
9a1398dd |
1096 | |