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