fNPrimaries now increased if adding
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALClusterizerv1.cxx
CommitLineData
483b0559 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 **************************************************************************/
173558f2 15
483b0559 16/* $Id$ */
483b0559 17/* $Log:
18 1 October 2000. Yuri Kharlov:
19 AreNeighbours()
20 PPSD upper layer is considered if number of layers>1
483b0559 21 18 October 2000. Yuri Kharlov:
22 AliEMCALClusterizerv1()
23 CPV clusterizing parameters added
483b0559 24 MakeClusters()
25 After first PPSD digit remove EMC digits only once
26*/
27//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
05a92d59 28// August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
29// of new IO (à la PHOS)
483b0559 30//////////////////////////////////////////////////////////////////////////////
31// Clusterization class. Performs clusterization (collects neighbouring active cells) and
32// unfolds the clusters having several local maxima.
33// Results are stored in TreeR#, branches EMCALTowerRP (EMC recPoints),
34// EMCALPreShoRP (CPV RecPoints) and AliEMCALClusterizer (Clusterizer with all
35// parameters including input digits branch title, thresholds etc.)
36// This TTask is normally called from Reconstructioner, but can as well be used in
37// standalone mode.
38// Use Case:
39// root [0] AliEMCALClusterizerv1 * cl = new AliEMCALClusterizerv1("galice.root")
40// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
41// //reads gAlice from header file "..."
42// root [1] cl->ExecuteTask()
43// //finds RecPoints in all events stored in galice.root
44// root [2] cl->SetDigitsBranch("digits2")
45// //sets another title for Digitis (input) branch
46// root [3] cl->SetRecPointsBranch("recp2")
47// //sets another title four output branches
48// root [4] cl->SetTowerLocalMaxCut(0.03)
49// //set clusterization parameters
50// root [5] cl->ExecuteTask("deb all time")
51// //once more finds RecPoints options are
52// // deb - print number of found rec points
53// // deb all - print number of found RecPoints and some their characteristics
54// // time - print benchmarking results
55
56// --- ROOT system ---
57
58#include "TROOT.h"
59#include "TFile.h"
60#include "TFolder.h"
61#include "TMath.h"
62#include "TMinuit.h"
63#include "TTree.h"
64#include "TSystem.h"
65#include "TBenchmark.h"
66
67// --- Standard library ---
68
173558f2 69
483b0559 70// --- AliRoot header files ---
71
72#include "AliEMCALClusterizerv1.h"
73#include "AliEMCALDigit.h"
74#include "AliEMCALDigitizer.h"
75#include "AliEMCALTowerRecPoint.h"
76#include "AliEMCAL.h"
77#include "AliEMCALGetter.h"
05a92d59 78#include "AliEMCALGeometry.h"
483b0559 79#include "AliRun.h"
80
81ClassImp(AliEMCALClusterizerv1)
82
83//____________________________________________________________________________
84 AliEMCALClusterizerv1::AliEMCALClusterizerv1() : AliEMCALClusterizer()
85{
86 // default ctor (to be used mainly by Streamer)
87
839828a6 88 InitParameters() ;
ef305168 89 fDefaultInit = kTRUE ;
483b0559 90}
91
92//____________________________________________________________________________
05a92d59 93AliEMCALClusterizerv1::AliEMCALClusterizerv1(const char* headerFile, const char* name, const Bool_t toSplit)
94:AliEMCALClusterizer(headerFile, name, toSplit)
483b0559 95{
96 // ctor with the indication of the file where header Tree and digits Tree are stored
97
839828a6 98 InitParameters() ;
483b0559 99 Init() ;
05a92d59 100 fDefaultInit = kFALSE ;
483b0559 101
102}
05a92d59 103
483b0559 104//____________________________________________________________________________
105 AliEMCALClusterizerv1::~AliEMCALClusterizerv1()
106{
ef305168 107 // dtor
05a92d59 108 fSplitFile = 0 ;
839828a6 109
ef305168 110}
111
112//____________________________________________________________________________
113const TString AliEMCALClusterizerv1::BranchName() const
9859bfc0 114{
ef305168 115 TString branchName(GetName() ) ;
116 branchName.Remove(branchName.Index(Version())-1) ;
117 return branchName ;
483b0559 118}
839828a6 119
483b0559 120//____________________________________________________________________________
121Float_t AliEMCALClusterizerv1::Calibrate(Int_t amp, Bool_t inpresho) const
9859bfc0 122{
123 //To be replased later by the method, reading individual parameters from the database
483b0559 124 if ( inpresho ) // calibrate as pre shower
9859bfc0 125 return -fADCpedestalPreSho + amp * fADCchannelPreSho ;
483b0559 126 else //calibrate as tower
127 return -fADCpedestalTower + amp * fADCchannelTower ;
128}
05a92d59 129
483b0559 130//____________________________________________________________________________
131void AliEMCALClusterizerv1::Exec(Option_t * option)
132{
133 // Steering method
134
135 if( strcmp(GetName(), "")== 0 )
136 Init() ;
137
138 if(strstr(option,"tim"))
139 gBenchmark->Start("EMCALClusterizer");
140
141 if(strstr(option,"print"))
142 Print("") ;
143
483b0559 144 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
05a92d59 145 if(gime->BranchExists("RecPoints"))
146 return ;
147 Int_t nevents = gime->MaxEvent() ;
483b0559 148 Int_t ievent ;
149
150 for(ievent = 0; ievent < nevents; ievent++){
151
05a92d59 152 gime->Event(ievent,"D") ;
153
483b0559 154 if(ievent == 0)
155 GetCalibrationParameters() ;
156
157 fNumberOfTowerClusters = fNumberOfPreShoClusters = 0 ;
05a92d59 158
483b0559 159 MakeClusters() ;
160
161 if(fToUnfold)
162 MakeUnfolding() ;
163
164 WriteRecPoints(ievent) ;
165
166 if(strstr(option,"deb"))
167 PrintRecPoints(option) ;
168
169 //increment the total number of digits per run
170 fRecPointsInRun += gime->TowerRecPoints()->GetEntriesFast() ;
171 fRecPointsInRun += gime->PreShowerRecPoints()->GetEntriesFast() ;
172 }
173
174 if(strstr(option,"tim")){
175 gBenchmark->Stop("EMCALClusterizer");
9859bfc0 176 Info("Exec", "took %f seconds for Clusterizing %f seconds per event",
177 gBenchmark->GetCpuTime("EMCALClusterizer"), gBenchmark->GetCpuTime("EMCALClusterizer")/nevents ) ;
483b0559 178 }
179
180}
181
182//____________________________________________________________________________
a0636361 183Bool_t AliEMCALClusterizerv1::FindFit(AliEMCALTowerRecPoint * emcRP, AliEMCALDigit ** maxAt, Float_t * maxAtEnergy,
483b0559 184 Int_t nPar, Float_t * fitparameters) const
185{
186 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
187 // The initial values for fitting procedure are set equal to the positions of local maxima.
188 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
189
190 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
191 TClonesArray * digits = gime->Digits() ;
192
193
194 gMinuit->mncler(); // Reset Minuit's list of paramters
195 gMinuit->SetPrintLevel(-1) ; // No Printout
196 gMinuit->SetFCN(AliEMCALClusterizerv1::UnfoldingChiSquare) ;
197 // To set the address of the minimization function
483b0559 198 TList * toMinuit = new TList();
199 toMinuit->AddAt(emcRP,0) ;
200 toMinuit->AddAt(digits,1) ;
201
202 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
203
204 // filling initial values for fit parameters
205 AliEMCALDigit * digit ;
206
207 Int_t ierflg = 0;
208 Int_t index = 0 ;
209 Int_t nDigits = (Int_t) nPar / 3 ;
210
211 Int_t iDigit ;
212
213 AliEMCALGeometry * geom = gime->EMCALGeometry() ;
214
215 for(iDigit = 0; iDigit < nDigits; iDigit++){
a0636361 216 digit = maxAt[iDigit];
483b0559 217
218 Int_t relid[4] ;
219 Float_t x = 0.;
220 Float_t z = 0.;
221 geom->AbsToRelNumbering(digit->GetId(), relid) ;
222 geom->PosInAlice(relid, x, z) ;
223
224 Float_t energy = maxAtEnergy[iDigit] ;
225
226 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
227 index++ ;
228 if(ierflg != 0){
9859bfc0 229 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : x = %f", x ) ;
483b0559 230 return kFALSE;
231 }
232 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
233 index++ ;
234 if(ierflg != 0){
9859bfc0 235 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : z = %f", z) ;
483b0559 236 return kFALSE;
237 }
238 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
239 index++ ;
240 if(ierflg != 0){
9859bfc0 241 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : energy = %f", energy) ;
483b0559 242 return kFALSE;
243 }
244 }
245
246 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
247 // depends on it.
248 Double_t p1 = 1.0 ;
249 Double_t p2 = 0.0 ;
250
251 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
252 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
253 gMinuit->SetMaxIterations(5);
254 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
255
256 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
257
258 if(ierflg == 4){ // Minimum not found
9859bfc0 259 Error("FindFit", "EMCAL Unfolding Fit not converged, cluster abandoned " ) ;
483b0559 260 return kFALSE ;
261 }
262 for(index = 0; index < nPar; index++){
263 Double_t err ;
264 Double_t val ;
265 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
266 fitparameters[index] = val ;
267 }
268
269 delete toMinuit ;
270 return kTRUE;
271
272}
273
274//____________________________________________________________________________
275void AliEMCALClusterizerv1::GetCalibrationParameters()
276{
277 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
05a92d59 278 const AliEMCALDigitizer * dig = gime->Digitizer(BranchName()) ;
483b0559 279
280 fADCchannelTower = dig->GetTowerchannel() ;
281 fADCpedestalTower = dig->GetTowerpedestal();
282
283 fADCchannelPreSho = dig->GetPreShochannel() ;
284 fADCpedestalPreSho = dig->GetPreShopedestal() ;
483b0559 285}
05a92d59 286
483b0559 287//____________________________________________________________________________
288void AliEMCALClusterizerv1::Init()
289{
290 // Make all memory allocations which can not be done in default constructor.
291 // Attach the Clusterizer task to the list of EMCAL tasks
292
293 if ( strcmp(GetTitle(), "") == 0 )
294 SetTitle("galice.root") ;
295
296 TString branchname = GetName() ;
297 branchname.Remove(branchname.Index(Version())-1) ;
298
05a92d59 299 AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), branchname.Data(), fToSplit ) ;
483b0559 300 if ( gime == 0 ) {
9859bfc0 301 Error("Init", "Could not obtain the Getter object !" ) ;
483b0559 302 return ;
303 }
05a92d59 304
305 fSplitFile = 0 ;
306 if(fToSplit){
307 // construct the name of the file as /path/EMCAL.SDigits.root
308 //First - extract full path if necessary
309 TString fileName(GetTitle()) ;
310 Ssiz_t islash = fileName.Last('/') ;
311 if(islash<fileName.Length())
312 fileName.Remove(islash+1,fileName.Length()) ;
313 else
314 fileName="" ;
315 // Next - append the file name
316 fileName+="EMCAL.RecData." ;
317 if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
318 fileName+=branchname ;
319 fileName+="." ;
320 }
321 fileName+="root" ;
322 // Finally - check if the file already opened or open the file
323 fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));
324 if(!fSplitFile)
325 fSplitFile = TFile::Open(fileName.Data(),"update") ;
326 }
327
483b0559 328 const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
329 fNTowers = geom->GetNZ() * geom->GetNPhi() ;
483b0559 330 if(!gMinuit)
331 gMinuit = new TMinuit(100) ;
332
333 gime->PostClusterizer(this) ;
483b0559 334 gime->PostRecPoints(branchname ) ;
05a92d59 335
483b0559 336}
337
338//____________________________________________________________________________
839828a6 339void AliEMCALClusterizerv1::InitParameters()
340{
9859bfc0 341 fNumberOfPreShoClusters = fNumberOfTowerClusters = 0 ;
839828a6 342 fPreShoClusteringThreshold = 0.0001;
9859bfc0 343 fTowerClusteringThreshold = 0.2;
839828a6 344 fTowerLocMaxCut = 0.03 ;
345 fPreShoLocMaxCut = 0.03 ;
346
347 fW0 = 4.5 ;
348 fW0CPV = 4.0 ;
349
350 fTimeGate = 1.e-8 ;
351
352 fToUnfold = kFALSE ;
9859bfc0 353
839828a6 354 TString clusterizerName( GetName()) ;
355 if (clusterizerName.IsNull() )
356 clusterizerName = "Default" ;
357 clusterizerName.Append(":") ;
358 clusterizerName.Append(Version()) ;
359 SetName(clusterizerName) ;
360 fRecPointsInRun = 0 ;
05a92d59 361
839828a6 362}
363
364//____________________________________________________________________________
483b0559 365Int_t AliEMCALClusterizerv1::AreNeighbours(AliEMCALDigit * d1, AliEMCALDigit * d2)const
366{
367 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
368 // = 1 are neighbour
369 // = 2 are not neighbour but do not continue searching
370 // neighbours are defined as digits having at least a common vertex
371 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
372 // which is compared to a digit (d2) not yet in a cluster
373
374 AliEMCALGeometry * geom = AliEMCALGetter::GetInstance()->EMCALGeometry() ;
375
376 Int_t rv = 0 ;
377
378 Int_t relid1[4] ;
379 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
380
381 Int_t relid2[4] ;
382 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
383
384 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same EMCAL Arm
385 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
386 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
387
388 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
389 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fTimeGate))
390 rv = 1 ;
391 }
392 else {
393 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
394 rv = 2; // Difference in row numbers is too large to look further
395 }
396
397 }
398 else {
399
400 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
401 rv=2 ;
483b0559 402 }
483b0559 403 return rv ;
404}
405
483b0559 406//____________________________________________________________________________
407Bool_t AliEMCALClusterizerv1::IsInTower(AliEMCALDigit * digit) const
408{
409 // Tells if (true) or not (false) the digit is in a EMCAL-Tower
410
411 Bool_t rv = kFALSE ;
412 if (!digit->IsInPreShower())
413 rv = kTRUE;
414 return rv ;
415}
416
417//____________________________________________________________________________
418Bool_t AliEMCALClusterizerv1::IsInPreShower(AliEMCALDigit * digit) const
419{
420 // Tells if (true) or not (false) the digit is in a EMCAL-PreShower
421
422 Bool_t rv = kFALSE ;
423 if (digit->IsInPreShower())
424 rv = kTRUE;
425 return rv ;
426}
427
428//____________________________________________________________________________
429void AliEMCALClusterizerv1::WriteRecPoints(Int_t event)
430{
431
432 // Creates new branches with given title
433 // fills and writes into TreeR.
434
483b0559 435 AliEMCALGetter *gime = AliEMCALGetter::GetInstance() ;
05a92d59 436 TObjArray * towerRecPoints = gime->TowerRecPoints() ;
437 TObjArray * preshoRecPoints = gime->PreShowerRecPoints() ;
438 TClonesArray * digits = gime->Digits() ;
839828a6 439 TTree * treeR ;
05a92d59 440
441 if(fToSplit){
442 if(!fSplitFile)
443 return ;
444 fSplitFile->cd() ;
445 TString name("TreeR") ;
446 name += event ;
447 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
448 }
449 else{
450 treeR = gAlice->TreeR();
451 }
483b0559 452
05a92d59 453 if(!treeR){
839828a6 454 gAlice->MakeTree("R", fSplitFile);
05a92d59 455 treeR = gAlice->TreeR() ;
456 }
457
458 Int_t index ;
483b0559 459 //Evaluate position, dispersion and other RecPoint properties...
460 for(index = 0; index < towerRecPoints->GetEntries(); index++)
461 (dynamic_cast<AliEMCALTowerRecPoint *>(towerRecPoints->At(index)))->EvalAll(fW0,digits) ;
05a92d59 462
483b0559 463 towerRecPoints->Sort() ;
464
465 for(index = 0; index < towerRecPoints->GetEntries(); index++)
466 (dynamic_cast<AliEMCALTowerRecPoint *>(towerRecPoints->At(index)))->SetIndexInList(index) ;
467
468 towerRecPoints->Expand(towerRecPoints->GetEntriesFast()) ;
ef305168 469 //Now the same for pre shower
483b0559 470 for(index = 0; index < preshoRecPoints->GetEntries(); index++)
471 (dynamic_cast<AliEMCALRecPoint *>(preshoRecPoints->At(index)))->EvalAll(fW0CPV,digits) ;
483b0559 472 preshoRecPoints->Sort() ;
473
474 for(index = 0; index < preshoRecPoints->GetEntries(); index++)
475 (dynamic_cast<AliEMCALRecPoint *>(preshoRecPoints->At(index)))->SetIndexInList(index) ;
476
477 preshoRecPoints->Expand(preshoRecPoints->GetEntriesFast()) ;
478
483b0559 479 Int_t bufferSize = 32000 ;
9859bfc0 480 Int_t splitlevel = 0 ;
173558f2 481
ef305168 482 //First Tower branch
05a92d59 483 TBranch * towerBranch = treeR->Branch("EMCALTowerRP","TObjArray",&towerRecPoints,bufferSize,splitlevel);
484 towerBranch->SetTitle(BranchName());
485
ef305168 486 //Now Pre Shower branch
05a92d59 487 TBranch * preshoBranch = treeR->Branch("EMCALPreShoRP","TObjArray",&preshoRecPoints,bufferSize,splitlevel);
488 preshoBranch->SetTitle(BranchName());
483b0559 489
490 //And Finally clusterizer branch
ef305168 491 AliEMCALClusterizerv1 * cl = (AliEMCALClusterizerv1*)gime->Clusterizer(BranchName()) ;
839828a6 492 TBranch * clusterizerBranch = treeR->Branch("AliEMCALClusterizer","AliEMCALClusterizerv1",
483b0559 493 &cl,bufferSize,splitlevel);
ef305168 494 clusterizerBranch->SetTitle(BranchName());
839828a6 495
05a92d59 496 towerBranch ->Fill() ;
497 preshoBranch ->Fill() ;
483b0559 498 clusterizerBranch->Fill() ;
499
839828a6 500 treeR->AutoSave() ; //Write(0,kOverwrite) ;
05a92d59 501 if(gAlice->TreeR()!=treeR)
502 treeR->Delete();
483b0559 503}
504
505//____________________________________________________________________________
506void AliEMCALClusterizerv1::MakeClusters()
507{
508 // Steering method to construct the clusters stored in a list of Reconstructed Points
509 // A cluster is defined as a list of neighbour digits
05a92d59 510
483b0559 511 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
512
05a92d59 513 TObjArray * towerRecPoints = gime->TowerRecPoints(BranchName()) ;
514 TObjArray * preshoRecPoints = gime->PreShowerRecPoints(BranchName()) ;
483b0559 515 towerRecPoints->Delete() ;
516 preshoRecPoints->Delete() ;
517
05a92d59 518 TClonesArray * digits = gime->Digits() ;
519 if ( !digits ) {
9859bfc0 520 Fatal("MakeClusters -> Digits with name %s not found", GetName() ) ;
05a92d59 521 }
483b0559 522 TClonesArray * digitsC = dynamic_cast<TClonesArray*>(digits->Clone()) ;
523
524
525 // Clusterization starts
526
527 TIter nextdigit(digitsC) ;
528 AliEMCALDigit * digit ;
529 Bool_t notremoved = kTRUE ;
530
531 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigit())) ) { // scan over the list of digitsC
532 AliEMCALRecPoint * clu = 0 ;
533
534 TArrayI clusterdigitslist(1500) ;
535 Int_t index ;
483b0559 536 if (( IsInTower (digit) && Calibrate(digit->GetAmp(),digit->IsInPreShower()) > fTowerClusteringThreshold ) ||
537 ( IsInPreShower (digit) && Calibrate(digit->GetAmp(),digit->IsInPreShower()) > fPreShoClusteringThreshold ) ) {
538
539 Int_t iDigitInCluster = 0 ;
540
541 if ( IsInTower(digit) ) {
542 // start a new Tower RecPoint
543 if(fNumberOfTowerClusters >= towerRecPoints->GetSize())
544 towerRecPoints->Expand(2*fNumberOfTowerClusters+1) ;
37b680d1 545 AliEMCALTowerRecPoint * rp = new AliEMCALTowerRecPoint("") ;
546 rp->SetTower() ;
547 towerRecPoints->AddAt(rp, fNumberOfTowerClusters) ;
483b0559 548 clu = dynamic_cast<AliEMCALTowerRecPoint *>(towerRecPoints->At(fNumberOfTowerClusters)) ;
549 fNumberOfTowerClusters++ ;
550 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->IsInPreShower())) ;
551 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
552 iDigitInCluster++ ;
553 digitsC->Remove(digit) ;
554
555 } else {
556
557 // start a new Pre Shower cluster
558 if(fNumberOfPreShoClusters >= preshoRecPoints->GetSize())
559 preshoRecPoints->Expand(2*fNumberOfPreShoClusters+1);
560
561 preshoRecPoints->AddAt(new AliEMCALTowerRecPoint(""), fNumberOfPreShoClusters) ;
562
563 clu = dynamic_cast<AliEMCALTowerRecPoint *>(preshoRecPoints->At(fNumberOfPreShoClusters)) ;
564 fNumberOfPreShoClusters++ ;
565 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->IsInPreShower() ) );
566 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
567 iDigitInCluster++ ;
568 digitsC->Remove(digit) ;
569 nextdigit.Reset() ;
570
571 // Here we remove remaining Tower digits, which cannot make a cluster
572
573 if( notremoved ) {
574 while( ( digit = dynamic_cast<AliEMCALDigit *>(nextdigit()) ) ) {
575 if( IsInTower(digit) )
576 digitsC->Remove(digit) ;
577 else
578 break ;
579 }
580 notremoved = kFALSE ;
581 }
582
583 } // else
584
585 nextdigit.Reset() ;
586
587 AliEMCALDigit * digitN ;
588 index = 0 ;
589 while (index < iDigitInCluster){ // scan over digits already in cluster
590 digit = (AliEMCALDigit*)digits->At(clusterdigitslist[index]) ;
591 index++ ;
592 while ( (digitN = (AliEMCALDigit *)nextdigit()) ) { // scan over the reduced list of digits
593 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
594 switch (ineb ) {
595 case 0 : // not a neighbour
596 break ;
597 case 1 : // are neighbours
598 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->IsInPreShower() ) ) ;
599 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
600 iDigitInCluster++ ;
601 digitsC->Remove(digitN) ;
602 break ;
603 case 2 : // too far from each other
604 goto endofloop;
605 } // switch
606
607 } // while digitN
608
609 endofloop: ;
610 nextdigit.Reset() ;
483b0559 611 } // loop over cluster
9859bfc0 612 } // energy theshold
613 } // while digit
483b0559 614 delete digitsC ;
483b0559 615}
616
617//____________________________________________________________________________
618void AliEMCALClusterizerv1::MakeUnfolding()
619{
620 Fatal("AliEMCALClusterizerv1::MakeUnfolding", "--> Unfolding not implemented") ;
9859bfc0 621
483b0559 622}
623
624//____________________________________________________________________________
625Double_t AliEMCALClusterizerv1::ShowerShape(Double_t r)
626{
627 // Shape of the shower (see EMCAL TDR)
628 // If you change this function, change also the gradient evaluation in ChiSquare()
629
630 Double_t r4 = r*r*r*r ;
631 Double_t r295 = TMath::Power(r, 2.95) ;
632 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
633 return shape ;
634}
635
636//____________________________________________________________________________
637void AliEMCALClusterizerv1::UnfoldCluster(AliEMCALTowerRecPoint * iniTower,
638 Int_t nMax,
a0636361 639 AliEMCALDigit ** maxAt,
483b0559 640 Float_t * maxAtEnergy)
641{
642 // Performs the unfolding of a cluster with nMax overlapping showers
483b0559 643
9859bfc0 644 Fatal("UnfoldCluster", "--> Unfolding not implemented") ;
173558f2 645
483b0559 646}
647
648//_____________________________________________________________________________
649void AliEMCALClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
650{
651 // Calculates the Chi square for the cluster unfolding minimization
652 // Number of parameters, Gradient, Chi squared, parameters, what to do
483b0559 653
9859bfc0 654 ::Fatal("UnfoldingChiSquare","Unfolding not implemented") ;
483b0559 655}
483b0559 656//____________________________________________________________________________
657void AliEMCALClusterizerv1::Print(Option_t * option)const
658{
659 // Print clusterizer parameters
660
9859bfc0 661 TString message("\n") ;
662
483b0559 663 if( strcmp(GetName(), "") !=0 ){
664
665 // Print parameters
666
667 TString taskName(GetName()) ;
668 taskName.ReplaceAll(Version(), "") ;
9859bfc0 669
670 message += "--------------- " ;
671 message += taskName.Data() ;
672 message += " " ;
673 message += GetTitle() ;
674 message += "-----------\n" ;
675 message += "Clusterizing digits from the file: " ;
676 message += taskName.Data() ;
677 message += "\n Branch: " ;
678 message += GetName() ;
679 message += "\n EMC Clustering threshold = " ;
680 message += fTowerClusteringThreshold ;
681 message += "\n EMC Local Maximum cut = " ;
682 message += fTowerLocMaxCut ;
683 message += "\n EMC Logarothmic weight = " ;
684 message += fW0 ;
f6eaf97a 685 message += "\n Pre Shower Clustering threshold = " ;
9859bfc0 686 message += fPreShoClusteringThreshold ;
f6eaf97a 687 message += "\n Pre Shower Local Maximum cut = " ;
9859bfc0 688 message += fPreShoLocMaxCut ;
f6eaf97a 689 message += "\n Pre Shower Logarothmic weight = " ;
9859bfc0 690 message += fW0CPV ;
483b0559 691 if(fToUnfold)
9859bfc0 692 message +="\nUnfolding on\n" ;
483b0559 693 else
9859bfc0 694 message += "\nUnfolding off\n";
483b0559 695
9859bfc0 696 message += "------------------------------------------------------------------" ;
483b0559 697 }
698 else
9859bfc0 699 message += "AliEMCALClusterizerv1 not initialized " ;
700
701 Info("Print", message.Data() ) ;
483b0559 702}
173558f2 703
483b0559 704//____________________________________________________________________________
705void AliEMCALClusterizerv1::PrintRecPoints(Option_t * option)
706{
707 // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
708
709 TObjArray * towerRecPoints = AliEMCALGetter::GetInstance()->TowerRecPoints() ;
710 TObjArray * preshoRecPoints = AliEMCALGetter::GetInstance()->PreShowerRecPoints() ;
711
9859bfc0 712 TString message("\n") ;
173558f2 713
9859bfc0 714 message += "event " ;
715 message += gAlice->GetEvNumber() ;
716 message += "\n Found " ;
717 message += towerRecPoints->GetEntriesFast() ;
718 message += " TOWER Rec Points and " ;
719 message += preshoRecPoints->GetEntriesFast() ;
720 message += " PRE SHOWER RecPoints\n" ;
173558f2 721
483b0559 722 fRecPointsInRun += towerRecPoints->GetEntriesFast() ;
723 fRecPointsInRun += preshoRecPoints->GetEntriesFast() ;
724
11f9c5ff 725 char * tempo = new char[8192];
726
483b0559 727 if(strstr(option,"all")) {
728
9859bfc0 729 message += "Tower clusters\n" ;
11f9c5ff 730 message += "Index Ene(MeV) Multi Module phi r theta Lambda 1 Lambda 2 # of prim Primaries list\n" ;
483b0559 731
732 Int_t index ;
733 for (index = 0 ; index < towerRecPoints->GetEntries() ; index++) {
734 AliEMCALTowerRecPoint * rp = dynamic_cast<AliEMCALTowerRecPoint * >(towerRecPoints->At(index)) ;
735 TVector3 globalpos;
736 rp->GetGlobalPosition(globalpos);
737 Float_t lambda[2];
738 rp->GetElipsAxis(lambda);
739 Int_t * primaries;
740 Int_t nprimaries;
741 primaries = rp->GetPrimaries(nprimaries);
11f9c5ff 742 sprintf(tempo, "\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
743 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetEMCALArm(),
744 globalpos.X(), globalpos.Y(), globalpos.Z(), lambda[0], lambda[1], nprimaries) ;
745 message += tempo ;
483b0559 746
9859bfc0 747 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
11f9c5ff 748 sprintf(tempo, "%d ", primaries[iprimary] ) ;
749 message += tempo ;
9859bfc0 750 }
483b0559 751 }
752
753 //Now plot Pre shower recPoints
754
9859bfc0 755 message += "\n-----------------------------------------------------------------------\n" ;
173558f2 756
9859bfc0 757 message += "PreShower clusters\n" ;
11f9c5ff 758 message += "Index Ene(MeV) Multi Module phi r theta Lambda 1 Lambda 2 # of prim Primaries list\n" ;
483b0559 759
760 for (index = 0 ; index < preshoRecPoints->GetEntries() ; index++) {
761 AliEMCALTowerRecPoint * rp = dynamic_cast<AliEMCALTowerRecPoint *>(preshoRecPoints->At(index)) ;
762 TVector3 globalpos;
763 rp->GetGlobalPosition(globalpos);
764 Float_t lambda[2];
765 rp->GetElipsAxis(lambda);
9859bfc0 766 Int_t * primaries;
483b0559 767 Int_t nprimaries;
768 primaries = rp->GetPrimaries(nprimaries);
11f9c5ff 769 sprintf(tempo, "\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
770 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetEMCALArm(),
771 globalpos.X(), globalpos.Y(), globalpos.Z(), lambda[0], lambda[1], nprimaries) ;
772 message += tempo ;
773
9859bfc0 774 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
11f9c5ff 775 sprintf(tempo, "%d ", primaries[iprimary] ) ;
776 message += tempo ;
9859bfc0 777 }
483b0559 778 }
779
9859bfc0 780 message += "\n-----------------------------------------------------------------------" ;
483b0559 781 }
11f9c5ff 782 delete tempo ;
9859bfc0 783 Info("PrintRecPoints", message.Data() ) ;
784
483b0559 785}