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