1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
19 //////////////////////////////////////////////////////////////////////////////
20 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
21 // unfolds the clusters having several local maxima.
22 // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
23 // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
24 // parameters including input digits branch title, thresholds etc.)
25 // This TTask is normally called from Reconstructioner, but can as well be used in
28 // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
29 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
30 // // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
31 // // and saves recpoints in branch named "recpointsname" (default = "digitsname")
32 // root [1] cl->ExecuteTask()
33 // //finds RecPoints in all events stored in galice.root
34 // root [2] cl->SetDigitsBranch("digits2")
35 // //sets another title for Digitis (input) branch
36 // root [3] cl->SetRecPointsBranch("recp2")
37 // //sets another title four output branches
38 // root [4] cl->SetEmcLocalMaxCut(0.03)
39 // //set clusterization parameters
40 // root [5] cl->ExecuteTask("deb all time")
41 // //once more finds RecPoints options are
42 // // deb - print number of found rec points
43 // // deb all - print number of found RecPoints and some their characteristics
44 // // time - print benchmarking results
46 // --- ROOT system ---
55 #include "TBenchmark.h"
57 // --- Standard library ---
58 //#include <iostream.h>
60 // --- AliRoot header files ---
61 #include "AliPHOSGetter.h"
62 #include "AliPHOSClusterizerv1.h"
63 #include "AliPHOSEmcRecPoint.h"
64 #include "AliPHOSCpvRecPoint.h"
65 #include "AliPHOSDigit.h"
66 #include "AliPHOSDigitizer.h"
68 #include "AliPHOSCalibrationDB.h"
70 ClassImp(AliPHOSClusterizerv1)
72 //____________________________________________________________________________
73 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
75 // default ctor (to be used mainly by Streamer)
78 fDefaultInit = kTRUE ;
81 //____________________________________________________________________________
82 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const TString alirunFileName, const TString eventFolderName)
83 :AliPHOSClusterizer(alirunFileName, eventFolderName)
85 // ctor with the indication of the file where header Tree and digits Tree are stored
89 fDefaultInit = kFALSE ;
92 //____________________________________________________________________________
93 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
97 // delete fPedestals ;
102 //____________________________________________________________________________
103 const TString AliPHOSClusterizerv1::BranchName() const
108 //____________________________________________________________________________
109 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
111 //To be replaced later by the method, reading individual parameters from the database
112 // if(fCalibrationDB)
113 // return fCalibrationDB->Calibrate(amp,absId) ;
114 // else{ //simulation
115 if(absId <= fEmcCrystals) //calibrate as EMC
116 return fADCpedestalEmc + amp*fADCchanelEmc ;
117 else //calibrate as CPV
118 return fADCpedestalCpv+ amp*fADCchanelCpv ;
122 //____________________________________________________________________________
123 void AliPHOSClusterizerv1::Exec(Option_t * option)
127 if(strstr(option,"tim"))
128 gBenchmark->Start("PHOSClusterizer");
130 if(strstr(option,"print"))
133 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
136 Int_t nevents = gime->MaxEvent() ;
139 for(ievent = 0; ievent < nevents; ievent++)
141 gime->Event(ievent, "D");
143 GetCalibrationParameters() ;
145 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
154 if(strstr(option,"deb"))
155 PrintRecPoints(option) ;
157 //increment the total number of recpoints per run
158 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
159 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
164 if(strstr(option,"tim")){
165 gBenchmark->Stop("PHOSClusterizer");
166 Info("Exec", " took %f seconds for Clusterizing %f seconds per event \n",
167 gBenchmark->GetCpuTime("PHOSClusterizer"),
168 gBenchmark->GetCpuTime("PHOSClusterizer")/nevents ) ;
172 //____________________________________________________________________________
173 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
174 Int_t nPar, Float_t * fitparameters) const
176 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
177 // The initial values for fitting procedure are set equal to the positions of local maxima.
178 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
181 AliPHOSGetter * gime = AliPHOSGetter::Instance();
182 TClonesArray * digits = gime->Digits();
185 gMinuit->mncler(); // Reset Minuit's list of paramters
186 gMinuit->SetPrintLevel(-1) ; // No Printout
187 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
188 // To set the address of the minimization function
190 TList * toMinuit = new TList();
191 toMinuit->AddAt(emcRP,0) ;
192 toMinuit->AddAt(digits,1) ;
194 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
196 // filling initial values for fit parameters
197 AliPHOSDigit * digit ;
201 Int_t nDigits = (Int_t) nPar / 3 ;
205 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
207 for(iDigit = 0; iDigit < nDigits; iDigit++){
208 digit = maxAt[iDigit];
213 geom->AbsToRelNumbering(digit->GetId(), relid) ;
214 geom->RelPosInModule(relid, x, z) ;
216 Float_t energy = maxAtEnergy[iDigit] ;
218 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
221 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
224 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
227 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
230 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
233 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
238 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
243 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
244 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
245 gMinuit->SetMaxIterations(5);
246 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
248 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
250 if(ierflg == 4){ // Minimum not found
251 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
254 for(index = 0; index < nPar; index++){
257 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
258 fitparameters[index] = val ;
266 //____________________________________________________________________________
267 void AliPHOSClusterizerv1::GetCalibrationParameters()
270 AliPHOSGetter * gime = AliPHOSGetter::Instance();
272 if ( !gime->Digitizer() )
273 gime->LoadDigitizer();
274 AliPHOSDigitizer * dig = gime->Digitizer();
276 fADCchanelEmc = dig->GetEMCchannel() ;
277 fADCpedestalEmc = dig->GetEMCpedestal();
279 fADCchanelCpv = dig->GetCPVchannel() ;
280 fADCpedestalCpv = dig->GetCPVpedestal() ;
282 // fCalibrationDB = gime->CalibrationDB();
285 //____________________________________________________________________________
286 void AliPHOSClusterizerv1::Init()
288 // Make all memory allocations which can not be done in default constructor.
289 // Attach the Clusterizer task to the list of PHOS tasks
291 AliPHOSGetter* gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
293 AliPHOSGeometry * geom = gime->PHOSGeometry();
295 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
298 gMinuit = new TMinuit(100);
300 if ( !gime->Clusterizer() )
301 gime->PostClusterizer(this);
304 //____________________________________________________________________________
305 void AliPHOSClusterizerv1::InitParameters()
308 fNumberOfCpvClusters = 0 ;
309 fNumberOfEmcClusters = 0 ;
311 fCpvClusteringThreshold = 0.0;
312 fEmcClusteringThreshold = 0.2;
314 fEmcLocMaxCut = 0.03 ;
315 fCpvLocMaxCut = 0.03 ;
320 fEmcTimeGate = 1.e-8 ;
324 fRecPointsInRun = 0 ;
328 //____________________________________________________________________________
329 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
331 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
333 // = 2 are not neighbour but do not continue searching
334 // neighbours are defined as digits having at least a common vertex
335 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
336 // which is compared to a digit (d2) not yet in a cluster
338 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
343 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
346 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
348 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
349 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
350 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
352 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
353 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
357 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
358 rv = 2; // Difference in row numbers is too large to look further
364 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
373 //____________________________________________________________________________
374 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
376 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
379 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
381 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
383 if(digit->GetId() <= nEMC ) rv = kTRUE;
388 //____________________________________________________________________________
389 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
391 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
395 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
397 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
399 if(digit->GetId() > nEMC ) rv = kTRUE;
404 //____________________________________________________________________________
405 void AliPHOSClusterizerv1::Unload()
407 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
408 gime->PhosLoader()->UnloadDigits() ;
409 gime->PhosLoader()->UnloadRecPoints() ;
412 //____________________________________________________________________________
413 void AliPHOSClusterizerv1::WriteRecPoints()
416 // Creates new branches with given title
417 // fills and writes into TreeR.
419 AliPHOSGetter * gime = AliPHOSGetter::Instance();
421 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
422 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
423 TClonesArray * digits = gime->Digits() ;
425 TTree * treeR = gime->TreeR();
428 //Evaluate position, dispersion and other RecPoint properties...
429 for(index = 0; index < emcRecPoints->GetEntries(); index++)
430 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->EvalAll(fW0,digits) ;
432 emcRecPoints->Sort() ;
433 for(index = 0; index < emcRecPoints->GetEntries(); index++)
434 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
436 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
438 //Now the same for CPV
439 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
440 dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) )->EvalAll(fW0CPV,digits) ;
442 cpvRecPoints->Sort() ;
444 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
445 dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
447 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
449 Int_t bufferSize = 32000 ;
450 Int_t splitlevel = 0 ;
453 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
454 emcBranch->SetTitle(BranchName());
457 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
458 cpvBranch->SetTitle(BranchName());
463 gime->WriteRecPoints("OVERWRITE");
464 gime->WriteClusterizer("OVERWRITE");
467 //____________________________________________________________________________
468 void AliPHOSClusterizerv1::MakeClusters()
470 // Steering method to construct the clusters stored in a list of Reconstructed Points
471 // A cluster is defined as a list of neighbour digits
474 AliPHOSGetter * gime = AliPHOSGetter::Instance();
476 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
477 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
479 emcRecPoints->Delete() ;
480 cpvRecPoints->Delete() ;
482 TClonesArray * digits = gime->Digits() ;
484 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
487 // Clusterization starts
489 TIter nextdigit(digitsC) ;
490 AliPHOSDigit * digit ;
491 Bool_t notremoved = kTRUE ;
493 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
496 AliPHOSRecPoint * clu = 0 ;
498 TArrayI clusterdigitslist(1500) ;
501 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
502 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
503 Int_t iDigitInCluster = 0 ;
505 if ( IsInEmc(digit) ) {
506 // start a new EMC RecPoint
507 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
508 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
510 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
511 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
512 fNumberOfEmcClusters++ ;
513 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
514 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
516 digitsC->Remove(digit) ;
520 // start a new CPV cluster
521 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
522 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
524 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
526 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
527 fNumberOfCpvClusters++ ;
528 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
529 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
531 digitsC->Remove(digit) ;
534 // Here we remove remaining EMC digits, which cannot make a cluster
537 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
539 digitsC->Remove(digit) ;
543 notremoved = kFALSE ;
550 AliPHOSDigit * digitN ;
552 while (index < iDigitInCluster){ // scan over digits already in cluster
553 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
555 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
556 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
558 case 0 : // not a neighbour
560 case 1 : // are neighbours
561 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
562 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
564 digitsC->Remove(digitN) ;
566 case 2 : // too far from each other
575 } // loop over cluster
586 //____________________________________________________________________________
587 void AliPHOSClusterizerv1::MakeUnfolding()
589 // Unfolds clusters using the shape of an ElectroMagnetic shower
590 // Performs unfolding of all EMC/CPV clusters
592 AliPHOSGetter * gime = AliPHOSGetter::Instance();
594 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
596 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
597 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
598 TClonesArray * digits = gime->Digits() ;
600 // Unfold first EMC clusters
601 if(fNumberOfEmcClusters > 0){
603 Int_t nModulesToUnfold = geom->GetNModules() ;
605 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
607 for(index = 0 ; index < numberofNotUnfolded ; index++){
609 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
610 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
613 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
614 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
615 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
616 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
618 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
619 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
620 emcRecPoints->Remove(emcRecPoint);
621 emcRecPoints->Compress() ;
623 fNumberOfEmcClusters -- ;
624 numberofNotUnfolded-- ;
628 delete[] maxAtEnergy ;
631 // Unfolding of EMC clusters finished
634 // Unfold now CPV clusters
635 if(fNumberOfCpvClusters > 0){
637 Int_t nModulesToUnfold = geom->GetNModules() ;
639 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
641 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
643 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
645 if(recPoint->GetPHOSMod()> nModulesToUnfold)
648 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
650 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
651 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
652 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
653 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
655 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
656 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
657 cpvRecPoints->Remove(emcRecPoint);
658 cpvRecPoints->Compress() ;
660 numberofCpvNotUnfolded-- ;
661 fNumberOfCpvClusters-- ;
665 delete[] maxAtEnergy ;
668 //Unfolding of Cpv clusters finished
672 //____________________________________________________________________________
673 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
675 // Shape of the shower (see PHOS TDR)
676 // If you change this function, change also the gradient evaluation in ChiSquare()
678 Double_t r4 = r*r*r*r ;
679 Double_t r295 = TMath::Power(r, 2.95) ;
680 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
684 //____________________________________________________________________________
685 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
687 AliPHOSDigit ** maxAt,
688 Float_t * maxAtEnergy)
690 // Performs the unfolding of a cluster with nMax overlapping showers
692 AliPHOSGetter * gime = AliPHOSGetter::Instance();
694 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
696 const TClonesArray * digits = gime->Digits() ;
697 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
698 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
700 Int_t nPar = 3 * nMax ;
701 Float_t * fitparameters = new Float_t[nPar] ;
703 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
705 // Fit failed, return and remove cluster
706 delete[] fitparameters ;
710 // create ufolded rec points and fill them with new energy lists
711 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
712 // and later correct this number in acordance with actual energy deposition
714 Int_t nDigits = iniEmc->GetMultiplicity() ;
715 Float_t * efit = new Float_t[nDigits] ;
716 Float_t xDigit=0.,zDigit=0.,distance=0. ;
717 Float_t xpar=0.,zpar=0.,epar=0. ;
719 AliPHOSDigit * digit = 0 ;
720 Int_t * emcDigits = iniEmc->GetDigitsList() ;
724 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
725 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
726 geom->AbsToRelNumbering(digit->GetId(), relid) ;
727 geom->RelPosInModule(relid, xDigit, zDigit) ;
731 while(iparam < nPar ){
732 xpar = fitparameters[iparam] ;
733 zpar = fitparameters[iparam+1] ;
734 epar = fitparameters[iparam+2] ;
736 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
737 distance = TMath::Sqrt(distance) ;
738 efit[iDigit] += epar * ShowerShape(distance) ;
743 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
744 // so that energy deposited in each cell is distributed betwin new clusters proportionally
745 // to its contribution to efit
747 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
751 while(iparam < nPar ){
752 xpar = fitparameters[iparam] ;
753 zpar = fitparameters[iparam+1] ;
754 epar = fitparameters[iparam+2] ;
757 AliPHOSEmcRecPoint * emcRP = 0 ;
759 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
761 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
762 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
764 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
765 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
766 fNumberOfEmcClusters++ ;
768 else{//create new entries in fCpvRecPoints
769 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
770 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
772 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
773 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
774 fNumberOfCpvClusters++ ;
778 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
779 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
780 geom->AbsToRelNumbering(digit->GetId(), relid) ;
781 geom->RelPosInModule(relid, xDigit, zDigit) ;
782 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
783 distance = TMath::Sqrt(distance) ;
784 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
785 eDigit = emcEnergies[iDigit] * ratio ;
786 emcRP->AddDigit( *digit, eDigit ) ;
790 delete[] fitparameters ;
795 //_____________________________________________________________________________
796 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
798 // Calculates the Chi square for the cluster unfolding minimization
799 // Number of parameters, Gradient, Chi squared, parameters, what to do
801 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
803 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
804 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
808 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
810 Int_t * emcDigits = emcRP->GetDigitsList() ;
812 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
814 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
816 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
821 for(iparam = 0 ; iparam < nPar ; iparam++)
822 Grad[iparam] = 0 ; // Will evaluate gradient
826 AliPHOSDigit * digit ;
829 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
831 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
837 geom->AbsToRelNumbering(digit->GetId(), relid) ;
839 geom->RelPosInModule(relid, xDigit, zDigit) ;
841 if(iflag == 2){ // calculate gradient
844 while(iParam < nPar ){
845 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
847 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
848 distance = TMath::Sqrt( distance ) ;
850 efit += x[iParam] * ShowerShape(distance) ;
853 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
855 while(iParam < nPar ){
856 Double_t xpar = x[iParam] ;
857 Double_t zpar = x[iParam+1] ;
858 Double_t epar = x[iParam+2] ;
859 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
860 Double_t shape = sum * ShowerShape(dr) ;
861 Double_t r4 = dr*dr*dr*dr ;
862 Double_t r295 = TMath::Power(dr,2.95) ;
863 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
864 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
866 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
868 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
870 Grad[iParam] += shape ; // Derivative over energy
877 while(iparam < nPar ){
878 Double_t xpar = x[iparam] ;
879 Double_t zpar = x[iparam+1] ;
880 Double_t epar = x[iparam+2] ;
882 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
883 distance = TMath::Sqrt(distance) ;
884 efit += epar * ShowerShape(distance) ;
887 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
888 // Here we assume, that sigma = sqrt(E)
893 //____________________________________________________________________________
894 void AliPHOSClusterizerv1::Print()const
896 // Print clusterizer parameters
899 TString taskName(GetName()) ;
900 taskName.ReplaceAll(Version(), "") ;
902 if( strcmp(GetName(), "") !=0 ) {
904 message = "\n--------------- %s %s -----------\n" ;
905 message += "Clusterizing digits from the file: %s\n" ;
906 message += " Branch: %s\n" ;
907 message += " EMC Clustering threshold = %f\n" ;
908 message += " EMC Local Maximum cut = %f\n" ;
909 message += " EMC Logarothmic weight = %f\n" ;
910 message += " CPV Clustering threshold = %f\n" ;
911 message += " CPV Local Maximum cut = %f\n" ;
912 message += " CPV Logarothmic weight = %f\n" ;
914 message += " Unfolding on\n" ;
916 message += " Unfolding off\n" ;
918 message += "------------------------------------------------------------------" ;
921 message = " AliPHOSClusterizerv1 not initialized " ;
923 Info("Print", message.Data(),
928 fEmcClusteringThreshold,
931 fCpvClusteringThreshold,
937 //____________________________________________________________________________
938 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
940 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
942 AliPHOSGetter * gime = AliPHOSGetter::Instance();
944 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
945 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
949 message = "\nevent " ;
950 message += gAlice->GetEvNumber() ;
951 message += "\n Found " ;
952 message += emcRecPoints->GetEntriesFast() ;
953 message += " EMC RecPoints and " ;
954 message += cpvRecPoints->GetEntriesFast() ;
955 message += " CPV RecPoints \n" ;
957 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
958 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
960 char * tempo = new char[8192];
962 if(strstr(option,"all")) {
963 message += "\nEMC clusters\n" ;
964 message += "Index Ene(MeV) Multi Module X Y Z Lambda 1 Lambda 2 # of prim Primaries list\n" ;
966 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
967 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
969 rp->GetLocalPosition(locpos);
971 rp->GetElipsAxis(lambda);
974 primaries = rp->GetPrimaries(nprimaries);
975 sprintf(tempo, "\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
976 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
977 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
980 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
981 sprintf(tempo, "%d ", primaries[iprimary] ) ;
985 //Now plot CPV recPoints
986 message += "Index Ene(MeV) Module X Y Z # of prim Primaries list\n" ;
987 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
988 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
991 rp->GetLocalPosition(locpos);
995 primaries = rp->GetPrimaries(nprimaries);
996 sprintf(tempo, "\n%6d %8.2f %2d %4.1f %4.1f %4.1f %2d : ",
997 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
998 locpos.X(), locpos.Y(), locpos.Z(), nprimaries) ;
1000 primaries = rp->GetPrimaries(nprimaries);
1001 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
1002 sprintf(tempo, "%d ", primaries[iprimary] ) ;
1009 Info("Print", message.Data() ) ;