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 | |
d15a28e7 |
18 | //_________________________________________________________________________ |
b2a60966 |
19 | // Implementation version 1 of algorithm class to construct PHOS track segments |
20 | // Associates EMC and PPSD clusters |
21 | // Unfolds the EMC cluster |
22 | // |
23 | //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) |
24 | // |
d15a28e7 |
25 | |
26 | // --- ROOT system --- |
27 | |
28 | #include "TObjArray.h" |
29 | #include "TClonesArray.h" |
9f616d61 |
30 | #include "TObjectTable.h" |
d15a28e7 |
31 | |
32 | // --- Standard library --- |
33 | |
de9ec31b |
34 | #include <iostream.h> |
d15a28e7 |
35 | |
36 | // --- AliRoot header files --- |
37 | |
38 | #include "AliPHOSTrackSegmentMakerv1.h" |
98cbd830 |
39 | #include "AliPHOSIndexToObject.h" |
d15a28e7 |
40 | #include "AliPHOSTrackSegment.h" |
41 | #include "AliPHOSLink.h" |
42 | #include "AliPHOSv0.h" |
43 | #include "AliRun.h" |
44 | |
92862013 |
45 | extern void UnfoldingChiSquare(Int_t &nPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ; |
9f616d61 |
46 | |
d15a28e7 |
47 | ClassImp( AliPHOSTrackSegmentMakerv1) |
48 | |
49 | |
50 | //____________________________________________________________________________ |
b2a60966 |
51 | AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker() |
d15a28e7 |
52 | { |
9f616d61 |
53 | // ctor |
b2a60966 |
54 | |
28c3a259 |
55 | fR0 = 10. ; |
d15a28e7 |
56 | //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0), |
98cbd830 |
57 | fDelta = fR0 + fGeom->GetCrystalSize(0) ; |
6727be7e |
58 | fMinuit = new TMinuit(100) ; |
59 | fUnfoldFlag = kTRUE ; |
d15a28e7 |
60 | } |
61 | |
9f616d61 |
62 | //____________________________________________________________________________ |
63 | AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1() |
64 | { |
65 | // dtor |
b2a60966 |
66 | |
67 | delete fMinuit ; |
9f616d61 |
68 | } |
b2a60966 |
69 | |
d15a28e7 |
70 | //____________________________________________________________________________ |
71 | Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy, |
92862013 |
72 | Int_t nPar, Float_t * fitparameters) |
9f616d61 |
73 | { |
b2a60966 |
74 | // Calls TMinuit to fit the energy distribution of a cluster with several maxima |
6ad0bfa0 |
75 | |
9f616d61 |
76 | gMinuit->SetPrintLevel(-1) ; // No Printout |
77 | gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function |
78 | gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare |
79 | |
80 | // filling initial values for fit parameters |
d15a28e7 |
81 | AliPHOSDigit * digit ; |
9f616d61 |
82 | |
83 | Int_t ierflg = 0; |
84 | Int_t index = 0 ; |
92862013 |
85 | Int_t nDigits = (Int_t) nPar / 3 ; |
9f616d61 |
86 | |
d15a28e7 |
87 | Int_t iDigit ; |
9f616d61 |
88 | |
89 | |
92862013 |
90 | for(iDigit = 0; iDigit < nDigits; iDigit++){ |
d15a28e7 |
91 | digit = (AliPHOSDigit *) maxAt[iDigit]; |
92 | |
92862013 |
93 | Int_t relid[4] ; |
d15a28e7 |
94 | Float_t x ; |
95 | Float_t z ; |
98cbd830 |
96 | fGeom->AbsToRelNumbering(digit->GetId(), relid) ; |
97 | fGeom->RelPosInModule(relid, x, z) ; |
d15a28e7 |
98 | |
92862013 |
99 | Float_t energy = maxAtEnergy[iDigit] ; |
d15a28e7 |
100 | |
9f616d61 |
101 | gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ; |
102 | index++ ; |
d15a28e7 |
103 | if(ierflg != 0){ |
104 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ; |
105 | return kFALSE; |
106 | } |
9f616d61 |
107 | gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ; |
108 | index++ ; |
d15a28e7 |
109 | if(ierflg != 0){ |
110 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ; |
111 | return kFALSE; |
112 | } |
92862013 |
113 | gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ; |
9f616d61 |
114 | index++ ; |
d15a28e7 |
115 | if(ierflg != 0){ |
92862013 |
116 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ; |
d15a28e7 |
117 | return kFALSE; |
6ad0bfa0 |
118 | } |
d15a28e7 |
119 | } |
120 | |
9f616d61 |
121 | Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly |
122 | // depends on it. |
123 | Double_t p1 = 1.0 ; |
124 | Double_t p2 = 0.0 ; |
125 | |
126 | gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TgMinuit to reduce function calls |
127 | gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient |
d15a28e7 |
128 | gMinuit->SetMaxIterations(5); |
9f616d61 |
129 | gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings |
98cbd830 |
130 | |
9f616d61 |
131 | gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize |
98cbd830 |
132 | |
9f616d61 |
133 | if(ierflg == 4){ // Minimum not found |
134 | cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ; |
d15a28e7 |
135 | return kFALSE ; |
136 | } |
92862013 |
137 | for(index = 0; index < nPar; index++){ |
d15a28e7 |
138 | Double_t err ; |
139 | Double_t val ; |
9f616d61 |
140 | gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index |
92862013 |
141 | fitparameters[index] = val ; |
d15a28e7 |
142 | } |
98cbd830 |
143 | |
d15a28e7 |
144 | return kTRUE; |
9f616d61 |
145 | |
d15a28e7 |
146 | } |
9f616d61 |
147 | |
d15a28e7 |
148 | //____________________________________________________________________________ |
98cbd830 |
149 | void AliPHOSTrackSegmentMakerv1::FillOneModule(AliPHOSRecPoint::RecPointsList * emcIn, |
28c3a259 |
150 | TArrayI * emcOut, |
88714635 |
151 | AliPHOSRecPoint::RecPointsList * ppsdIn, |
28c3a259 |
152 | TArrayI * ppsdOutUp, |
153 | TArrayI * ppsdOutLow, |
88714635 |
154 | Int_t & phosmod, |
155 | Int_t & emcStopedAt, |
156 | Int_t & ppsdStopedAt) |
9f616d61 |
157 | { |
98cbd830 |
158 | // Fill xxxOut arrays with clusters from one PHOS module |
9f616d61 |
159 | |
160 | AliPHOSEmcRecPoint * emcRecPoint ; |
d15a28e7 |
161 | AliPHOSPpsdRecPoint * ppsdRecPoint ; |
162 | Int_t index ; |
6ad0bfa0 |
163 | |
92862013 |
164 | Int_t nEmcUnfolded = emcIn->GetEntries() ; |
28c3a259 |
165 | emcOut->Set(nEmcUnfolded); |
166 | Int_t inEmcOut = 0 ; |
92862013 |
167 | for(index = emcStopedAt; index < nEmcUnfolded; index++){ |
6ad0bfa0 |
168 | |
98cbd830 |
169 | emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ; |
9f616d61 |
170 | |
98cbd830 |
171 | if(emcRecPoint->GetPHOSMod() != phosmod ) |
172 | break ; |
31aa6d6c |
173 | |
28c3a259 |
174 | emcOut->AddAt(emcRecPoint->GetIndexInList(),inEmcOut) ; |
175 | inEmcOut++ ; |
d15a28e7 |
176 | } |
28c3a259 |
177 | emcOut->Set(inEmcOut) ; |
178 | |
d15a28e7 |
179 | emcStopedAt = index ; |
180 | |
28c3a259 |
181 | ppsdOutLow->Set(ppsdIn->GetEntries()) ; |
182 | ppsdOutUp->Set(ppsdIn->GetEntries()) ; |
183 | Int_t inPpsdLow = 0; |
184 | Int_t inPpsdUp = 0; |
d15a28e7 |
185 | for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){ |
83974468 |
186 | ppsdRecPoint = (AliPHOSPpsdRecPoint *) ppsdIn->At(index) ; |
92862013 |
187 | if(ppsdRecPoint->GetPHOSMod() != phosmod ) |
9f616d61 |
188 | break ; |
d15a28e7 |
189 | if(ppsdRecPoint->GetUp() ) |
28c3a259 |
190 | ppsdOutUp->AddAt(index,inPpsdUp++) ; |
d15a28e7 |
191 | else |
28c3a259 |
192 | ppsdOutLow->AddAt(index,inPpsdLow++) ; |
d15a28e7 |
193 | } |
28c3a259 |
194 | ppsdOutLow->Set(inPpsdLow); |
195 | ppsdOutUp->Set(inPpsdUp); |
d15a28e7 |
196 | ppsdStopedAt = index ; |
6ad0bfa0 |
197 | |
d15a28e7 |
198 | } |
199 | //____________________________________________________________________________ |
92862013 |
200 | Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar) |
d15a28e7 |
201 | { |
b2a60966 |
202 | // Calculates the distance between the EMC RecPoint and the PPSD RecPoint |
203 | |
92862013 |
204 | Float_t r = fR0 ; |
d15a28e7 |
205 | |
206 | TVector3 vecEmc ; |
207 | TVector3 vecPpsd ; |
208 | |
92862013 |
209 | emcclu->GetLocalPosition(vecEmc) ; |
d15a28e7 |
210 | PpsdClu->GetLocalPosition(vecPpsd) ; |
92862013 |
211 | if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){ |
d15a28e7 |
212 | if(vecPpsd.X() >= vecEmc.X() - fDelta ){ |
213 | if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){ |
6ad0bfa0 |
214 | // Correct to difference in CPV and EMC position due to different distance to center. |
215 | // we assume, that particle moves from center |
98cbd830 |
216 | Float_t dCPV = fGeom->GetIPtoOuterCoverDistance(); |
217 | Float_t dEMC = fGeom->GetIPtoCrystalSurface() ; |
92862013 |
218 | dEMC = dEMC / dCPV ; |
219 | vecPpsd = dEMC * vecPpsd - vecEmc ; |
220 | r = vecPpsd.Mag() ; |
d15a28e7 |
221 | } // if zPpsd >= zEmc - fDelta |
92862013 |
222 | toofar = kFALSE ; |
d15a28e7 |
223 | } // if xPpsd >= xEmc - fDelta |
224 | else |
92862013 |
225 | toofar = kTRUE ; |
d15a28e7 |
226 | } |
227 | else |
92862013 |
228 | toofar = kTRUE ; |
d15a28e7 |
229 | |
92862013 |
230 | return r ; |
d15a28e7 |
231 | } |
232 | |
233 | //____________________________________________________________________________ |
28c3a259 |
234 | void AliPHOSTrackSegmentMakerv1::MakeLinks(TArrayI * emcRecPoints, TArrayI * ppsdRecPointsUp, |
235 | TArrayI * ppsdRecPointsLow, TClonesArray * linklowArray, |
92862013 |
236 | TClonesArray *linkupArray) |
d15a28e7 |
237 | { |
b2a60966 |
238 | // Finds distances (links) between all EMC and PPSD clusters, which are not further apart from each other than fR0 |
239 | |
d15a28e7 |
240 | |
92862013 |
241 | AliPHOSPpsdRecPoint * ppsdlow ; |
242 | AliPHOSPpsdRecPoint * ppsdup ; |
243 | AliPHOSEmcRecPoint * emcclu ; |
28c3a259 |
244 | |
d15a28e7 |
245 | Int_t iLinkLow = 0 ; |
246 | Int_t iLinkUp = 0 ; |
247 | |
28c3a259 |
248 | Int_t iEmcRP; |
249 | |
250 | for(iEmcRP = 0; iEmcRP < emcRecPoints->GetSize(); iEmcRP++ ) { |
251 | emcclu = (AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emcRecPoints->At(iEmcRP),"emc") ; |
92862013 |
252 | Bool_t toofar ; |
d15a28e7 |
253 | |
28c3a259 |
254 | Int_t iPpsdLow ; |
255 | |
256 | for(iPpsdLow = 0; iPpsdLow < ppsdRecPointsLow->GetSize();iPpsdLow++ ) { |
257 | |
258 | ppsdlow = (AliPHOSPpsdRecPoint *) fPlease->GimeRecPoint(ppsdRecPointsLow->At(iPpsdLow),"ppsd") ; |
92862013 |
259 | Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdlow, toofar) ; |
d15a28e7 |
260 | |
92862013 |
261 | if(toofar) |
d15a28e7 |
262 | break ; |
83974468 |
263 | if(r < fR0){ |
28c3a259 |
264 | new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcRP, iPpsdLow) ; |
265 | } |
d15a28e7 |
266 | } |
267 | |
28c3a259 |
268 | Int_t iPpsdUp = 0 ; |
269 | for(iPpsdUp = 0; iPpsdUp < ppsdRecPointsUp->GetSize();iPpsdUp++ ) { |
270 | |
271 | ppsdup = (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdRecPointsUp->At(iPpsdUp),"ppsd") ; |
92862013 |
272 | Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdup, toofar) ; |
d15a28e7 |
273 | |
92862013 |
274 | if(toofar) |
d15a28e7 |
275 | break ; |
83974468 |
276 | if(r < fR0) { |
28c3a259 |
277 | new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iPpsdUp) ; |
278 | } |
d15a28e7 |
279 | } |
28c3a259 |
280 | } |
d15a28e7 |
281 | |
92862013 |
282 | linklowArray->Sort() ; //first links with smallest distances |
283 | linkupArray->Sort() ; |
d15a28e7 |
284 | } |
28c3a259 |
285 | |
d15a28e7 |
286 | //____________________________________________________________________________ |
28c3a259 |
287 | void AliPHOSTrackSegmentMakerv1::MakePairs(TArrayI * emcRecPoints, |
288 | TArrayI * ppsdRecPointsUp, |
289 | TArrayI * ppsdRecPointsLow, |
88714635 |
290 | TClonesArray * linklowArray, |
291 | TClonesArray * linkupArray, |
292 | AliPHOSTrackSegment::TrackSegmentsList * trsl) |
6ad0bfa0 |
293 | { |
294 | |
295 | // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance |
296 | |
92862013 |
297 | TIter nextLow(linklowArray) ; |
298 | TIter nextUp(linkupArray) ; |
d15a28e7 |
299 | |
300 | AliPHOSLink * linkLow ; |
301 | AliPHOSLink * linkUp ; |
302 | |
28c3a259 |
303 | Int_t emc ; |
304 | Int_t ppsdLow ; |
305 | Int_t ppsdUp ; |
d15a28e7 |
306 | |
28c3a259 |
307 | AliPHOSPpsdRecPoint * nullpointer = 0 ; |
308 | ppsdUp = 0 ; |
9f616d61 |
309 | |
d15a28e7 |
310 | while ( (linkLow = (AliPHOSLink *)nextLow() ) ){ |
28c3a259 |
311 | |
312 | emc = emcRecPoints->At(linkLow->GetEmc()) ; |
313 | ppsdLow = ppsdRecPointsLow->At(linkLow->GetPpsd()) ; |
314 | if( (emc >= 0) && (ppsdLow >= 0) ){ // RecPoints not removed yet |
315 | |
316 | new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *)fPlease->GimeRecPoint(emc,"emc"), |
317 | nullpointer, |
318 | (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdLow,"ppsd") ) ; |
319 | ((AliPHOSTrackSegment* )trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments); |
320 | //replace index of emc to negative and shifted index of TS |
321 | emcRecPoints->AddAt(-2 - fNTrackSegments,linkLow->GetEmc()) ; |
322 | //replace index of emc to negative and shifted index of TS |
323 | ppsdRecPointsLow->AddAt(-2 - fNTrackSegments,linkLow->GetPpsd()) ; |
324 | fNTrackSegments++ ; |
325 | |
6ad0bfa0 |
326 | } |
d15a28e7 |
327 | } |
28c3a259 |
328 | |
329 | while ( (linkUp = (AliPHOSLink *)nextUp() ) ){ |
330 | emc = emcRecPoints->At(linkUp->GetEmc()) ; |
331 | if(emc != -1){ //without ppsd Up yet |
d15a28e7 |
332 | |
28c3a259 |
333 | ppsdUp = ppsdRecPointsUp->At(linkUp->GetPpsd()) ; |
334 | |
335 | if(emc >= 0){ //without ppsd Low => create new TS |
336 | |
337 | fNTrackSegments = trsl->GetEntries() ; |
338 | new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emc,"emc"), |
339 | (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdUp,"ppsd"), |
340 | nullpointer) ; |
341 | ((AliPHOSTrackSegment *) trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments); |
342 | fNTrackSegments++ ; |
343 | } |
344 | else{ // append ppsd Up to existing TS |
345 | ((AliPHOSTrackSegment *)trsl->At(-2-emc))->SetPpsdUpRecPoint((AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdUp,"ppsd")); |
d15a28e7 |
346 | } |
28c3a259 |
347 | emcRecPoints->AddAt(-1,linkUp->GetEmc()) ; //Mark that PPSD Up found |
d15a28e7 |
348 | |
28c3a259 |
349 | } |
350 | } |
351 | |
352 | Int_t iEmcRP ; |
353 | for(iEmcRP = 0; iEmcRP <emcRecPoints->GetSize() ; iEmcRP++ ){ |
354 | emc = emcRecPoints->At(iEmcRP) ; |
355 | if(emc >=0 ){ |
356 | ppsdUp = 0; |
357 | ppsdLow = 0; |
358 | new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emc,"emc"), |
359 | nullpointer, nullpointer ) ; |
360 | ((AliPHOSTrackSegment *) trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments); |
361 | fNTrackSegments++; |
d15a28e7 |
362 | } |
b2a60966 |
363 | |
d15a28e7 |
364 | } |
28c3a259 |
365 | |
d15a28e7 |
366 | } |
367 | |
368 | //____________________________________________________________________________ |
88714635 |
369 | void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl, |
370 | AliPHOSRecPoint::RecPointsList * emcl, |
371 | AliPHOSRecPoint::RecPointsList * ppsdl, |
372 | AliPHOSTrackSegment::TrackSegmentsList * trsl) |
d15a28e7 |
373 | { |
b2a60966 |
374 | // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list |
98cbd830 |
375 | |
92862013 |
376 | Int_t phosmod = 1 ; |
9f616d61 |
377 | Int_t emcStopedAt = 0 ; |
d15a28e7 |
378 | Int_t ppsdStopedAt = 0 ; |
28c3a259 |
379 | |
380 | fNTrackSegments = 0 ; |
381 | |
d15a28e7 |
382 | |
28c3a259 |
383 | TArrayI * emcRecPoints = new TArrayI(1000) ; // these arrays keep indexes |
384 | TArrayI * ppsdRecPointsUp = new TArrayI(1000) ; // of RecPoints, which are |
385 | TArrayI * ppsdRecPointsLow = new TArrayI(1000) ; // kept in TClonesArray's emcl and ppsdl |
d15a28e7 |
386 | |
387 | |
92862013 |
388 | TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100); |
389 | TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100); |
6ad0bfa0 |
390 | |
28c3a259 |
391 | |
98cbd830 |
392 | if(fUnfoldFlag){ |
393 | UnfoldAll(dl, emcl) ; // Unfolds all EMC clusters |
394 | } |
d15a28e7 |
395 | |
28c3a259 |
396 | |
98cbd830 |
397 | while(phosmod <= fGeom->GetNModules() ){ |
398 | |
399 | FillOneModule(emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ; |
400 | |
401 | MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ; |
402 | |
92862013 |
403 | MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ; |
98cbd830 |
404 | |
28c3a259 |
405 | emcRecPoints->Reset() ; |
98cbd830 |
406 | |
28c3a259 |
407 | ppsdRecPointsUp->Reset() ; |
98cbd830 |
408 | |
28c3a259 |
409 | ppsdRecPointsLow->Reset() ; |
98cbd830 |
410 | |
92862013 |
411 | linkupArray->Clear() ; |
98cbd830 |
412 | |
92862013 |
413 | linklowArray->Clear() ; |
98cbd830 |
414 | |
92862013 |
415 | phosmod++ ; |
d15a28e7 |
416 | } |
28c3a259 |
417 | |
92862013 |
418 | delete emcRecPoints ; |
419 | emcRecPoints = 0 ; |
98cbd830 |
420 | |
92862013 |
421 | delete ppsdRecPointsUp ; |
422 | ppsdRecPointsUp = 0 ; |
9f616d61 |
423 | |
92862013 |
424 | delete ppsdRecPointsLow ; |
425 | ppsdRecPointsLow = 0 ; |
9f616d61 |
426 | |
92862013 |
427 | delete linkupArray ; |
428 | linkupArray = 0 ; |
9f616d61 |
429 | |
92862013 |
430 | delete linklowArray ; |
431 | linklowArray = 0 ; |
d15a28e7 |
432 | } |
433 | |
434 | //____________________________________________________________________________ |
9f616d61 |
435 | Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r) |
436 | { |
b2a60966 |
437 | // Shape of the shower (see PHOS TDR) |
438 | // If you change this function, change also the gradien evaluation in ChiSquare() |
439 | |
6ad0bfa0 |
440 | Double_t r4 = r*r*r*r ; |
441 | Double_t r295 = TMath::Power(r, 2.95) ; |
d15a28e7 |
442 | Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ; |
443 | return shape ; |
444 | } |
445 | |
98cbd830 |
446 | //____________________________________________________________________________ |
447 | void AliPHOSTrackSegmentMakerv1::UnfoldAll(DigitsList * dl, AliPHOSRecPoint::RecPointsList * emcIn) |
448 | { |
449 | // Performs unfolding of all EMC clusters, sorts them and resets indexes in RecPoints |
450 | |
451 | AliPHOSEmcRecPoint * emcRecPoint ; |
452 | Int_t index ; |
453 | Int_t nEmcUnfolded = emcIn->GetEntries() ; |
454 | |
455 | for(index = 0 ; index < nEmcUnfolded; index++){ |
456 | |
457 | emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ; |
458 | |
459 | Int_t nMultipl = emcRecPoint->GetMultiplicity() ; |
460 | Int_t * maxAt = new Int_t[nMultipl] ; |
461 | Float_t * maxAtEnergy = new Float_t[nMultipl] ; |
462 | Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ; |
463 | |
464 | if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0 |
465 | |
466 | UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy) ; |
467 | emcIn->Remove(emcRecPoint); |
468 | emcIn->Compress() ; |
469 | index-- ; |
470 | nEmcUnfolded-- ; |
471 | } |
472 | |
473 | delete[] maxAt ; |
474 | delete[] maxAtEnergy ; |
475 | } //Unfolding finished |
476 | |
477 | emcIn->Sort() ; |
478 | |
479 | // to set index to new and correct index of old RecPoints |
28c3a259 |
480 | for( index = 0 ; index < emcIn->GetEntries() ; index++){ |
98cbd830 |
481 | |
482 | ((AliPHOSEmcRecPoint *) emcIn->At(index))->SetIndexInList(index) ; |
483 | |
484 | } |
485 | |
28c3a259 |
486 | emcIn->Sort() ; |
487 | |
98cbd830 |
488 | } |
d15a28e7 |
489 | //____________________________________________________________________________ |
88714635 |
490 | void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl, |
491 | AliPHOSRecPoint::RecPointsList * emcIn, |
492 | AliPHOSEmcRecPoint * iniEmc, |
493 | Int_t nMax, |
494 | int * maxAt, |
98cbd830 |
495 | Float_t * maxAtEnergy) |
d15a28e7 |
496 | { |
b2a60966 |
497 | // Performs the unfolding of a cluster with nMax overlapping showers |
498 | // This is time consuming (use the (Un)SetUnfolFlag() ) |
499 | |
92862013 |
500 | Int_t nPar = 3 * nMax ; |
31aa6d6c |
501 | Float_t * fitparameters = new Float_t[nPar] ; |
98cbd830 |
502 | |
9f616d61 |
503 | |
92862013 |
504 | Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ; |
31aa6d6c |
505 | if( !rv ) { |
506 | // Fit failed, return and remove cluster |
507 | delete[] fitparameters ; |
d15a28e7 |
508 | return ; |
31aa6d6c |
509 | } |
98cbd830 |
510 | |
511 | |
d15a28e7 |
512 | Float_t xDigit ; |
513 | Float_t zDigit ; |
92862013 |
514 | Int_t relid[4] ; |
d15a28e7 |
515 | |
92862013 |
516 | Int_t nDigits = iniEmc->GetMultiplicity() ; |
d15a28e7 |
517 | Float_t xpar ; |
518 | Float_t zpar ; |
92862013 |
519 | Float_t epar ; |
520 | Float_t distance ; |
521 | Float_t ratio ; |
31aa6d6c |
522 | Float_t * efit = new Float_t[nDigits] ; |
d15a28e7 |
523 | Int_t iparam ; |
524 | Int_t iDigit ; |
525 | |
526 | AliPHOSDigit * digit ; |
527 | AliPHOSEmcRecPoint * emcRP ; |
6ad0bfa0 |
528 | Int_t * emcDigits = iniEmc->GetDigitsList() ; |
d15a28e7 |
529 | Float_t * emcEnergies = iniEmc->GetEnergiesList() ; |
530 | |
531 | Int_t iRecPoint = emcIn->GetEntries() ; |
532 | |
92862013 |
533 | for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){ |
98cbd830 |
534 | digit = fPlease->GimeDigit( emcDigits[iDigit] ) ; |
535 | fGeom->AbsToRelNumbering(digit->GetId(), relid) ; |
536 | fGeom->RelPosInModule(relid, xDigit, zDigit) ; |
92862013 |
537 | efit[iDigit] = 0; |
d15a28e7 |
538 | iparam = 0 ; |
539 | |
92862013 |
540 | while(iparam < nPar ){ |
541 | xpar = fitparameters[iparam] ; |
542 | zpar = fitparameters[iparam+1] ; |
543 | epar = fitparameters[iparam+2] ; |
d15a28e7 |
544 | iparam += 3 ; |
92862013 |
545 | distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
546 | distance = TMath::Sqrt(distance) ; |
b2a60966 |
547 | efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ; |
d15a28e7 |
548 | } |
d15a28e7 |
549 | } |
550 | |
551 | iparam = 0 ; |
552 | Float_t eDigit ; |
553 | |
98cbd830 |
554 | |
92862013 |
555 | while(iparam < nPar ){ |
556 | xpar = fitparameters[iparam] ; |
557 | zpar = fitparameters[iparam+1] ; |
558 | epar = fitparameters[iparam+2] ; |
d15a28e7 |
559 | iparam += 3 ; |
98cbd830 |
560 | |
28c3a259 |
561 | if(iRecPoint >= emcIn->GetSize()) |
562 | emcIn->Expand(2*iRecPoint) ; |
563 | (*emcIn)[iRecPoint] = new AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ; |
564 | |
98cbd830 |
565 | emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint); |
566 | iRecPoint++ ; |
d15a28e7 |
567 | |
92862013 |
568 | for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){ |
98cbd830 |
569 | digit = fPlease->GimeDigit( emcDigits[iDigit] ) ; |
570 | fGeom->AbsToRelNumbering(digit->GetId(), relid) ; |
571 | fGeom->RelPosInModule(relid, xDigit, zDigit) ; |
92862013 |
572 | distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
573 | distance = TMath::Sqrt(distance) ; |
b2a60966 |
574 | ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ; |
92862013 |
575 | eDigit = emcEnergies[iDigit] * ratio ; |
9f616d61 |
576 | emcRP->AddDigit( *digit, eDigit ) ; |
d15a28e7 |
577 | } |
578 | |
d15a28e7 |
579 | } |
31aa6d6c |
580 | |
581 | delete[] fitparameters ; |
582 | delete[] efit ; |
583 | |
d15a28e7 |
584 | } |
6ad0bfa0 |
585 | |
d15a28e7 |
586 | //______________________________________________________________________________ |
92862013 |
587 | void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag) |
d15a28e7 |
588 | { |
b2a60966 |
589 | // Calculates th Chi square for the cluster unfolding minimization |
590 | // Number of parameters, Gradient, Chi squared, parameters, what to do |
98cbd830 |
591 | |
9f616d61 |
592 | AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit |
98cbd830 |
593 | |
6ad0bfa0 |
594 | Int_t * emcDigits = emcRP->GetDigitsList() ; |
98cbd830 |
595 | |
596 | Int_t nOfDigits = emcRP->GetDigitsMultiplicity() ; |
597 | |
d15a28e7 |
598 | Float_t * emcEnergies = emcRP->GetEnergiesList() ; |
98cbd830 |
599 | |
600 | AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ; |
601 | |
602 | AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ; |
603 | |
d15a28e7 |
604 | fret = 0. ; |
605 | Int_t iparam ; |
606 | |
9f616d61 |
607 | if(iflag == 2) |
92862013 |
608 | for(iparam = 0 ; iparam < nPar ; iparam++) |
9f616d61 |
609 | Grad[iparam] = 0 ; // Will evaluate gradient |
610 | |
98cbd830 |
611 | Double_t efit ; |
612 | |
d15a28e7 |
613 | AliPHOSDigit * digit ; |
98cbd830 |
614 | Int_t iDigit ; |
615 | |
616 | for( iDigit = 0 ; iDigit < nOfDigits ; iDigit++) { |
617 | |
618 | digit = please->GimeDigit( emcDigits[iDigit] ) ; |
9f616d61 |
619 | |
92862013 |
620 | Int_t relid[4] ; |
d15a28e7 |
621 | Float_t xDigit ; |
622 | Float_t zDigit ; |
98cbd830 |
623 | |
92862013 |
624 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
98cbd830 |
625 | |
92862013 |
626 | geom->RelPosInModule(relid, xDigit, zDigit) ; |
98cbd830 |
627 | |
9f616d61 |
628 | if(iflag == 2){ // calculate gradient |
629 | Int_t iParam = 0 ; |
92862013 |
630 | efit = 0 ; |
631 | while(iParam < nPar ){ |
632 | Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ; |
9f616d61 |
633 | iParam++ ; |
92862013 |
634 | distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ; |
635 | distance = TMath::Sqrt( distance ) ; |
9f616d61 |
636 | iParam++ ; |
92862013 |
637 | efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ; |
9f616d61 |
638 | iParam++ ; |
639 | } |
92862013 |
640 | Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E) |
9f616d61 |
641 | iParam = 0 ; |
92862013 |
642 | while(iParam < nPar ){ |
9f616d61 |
643 | Double_t xpar = x[iParam] ; |
644 | Double_t zpar = x[iParam+1] ; |
92862013 |
645 | Double_t epar = x[iParam+2] ; |
9f616d61 |
646 | Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ); |
647 | Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ; |
648 | Double_t r4 = dr*dr*dr*dr ; |
649 | Double_t r295 = TMath::Power(dr,2.95) ; |
650 | Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) + |
651 | 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ; |
652 | |
92862013 |
653 | Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x |
9f616d61 |
654 | iParam++ ; |
92862013 |
655 | Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z |
9f616d61 |
656 | iParam++ ; |
657 | Grad[iParam] += shape ; // Derivative over energy |
658 | iParam++ ; |
659 | } |
660 | } |
92862013 |
661 | efit = 0; |
9f616d61 |
662 | iparam = 0 ; |
98cbd830 |
663 | |
92862013 |
664 | while(iparam < nPar ){ |
9f616d61 |
665 | Double_t xpar = x[iparam] ; |
666 | Double_t zpar = x[iparam+1] ; |
92862013 |
667 | Double_t epar = x[iparam+2] ; |
9f616d61 |
668 | iparam += 3 ; |
92862013 |
669 | Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
670 | distance = TMath::Sqrt(distance) ; |
671 | efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ; |
9f616d61 |
672 | } |
98cbd830 |
673 | |
92862013 |
674 | fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ; |
9f616d61 |
675 | // Here we assume, that sigma = sqrt(E) |
d15a28e7 |
676 | } |
98cbd830 |
677 | |
d15a28e7 |
678 | } |