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