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() ;
135 Int_t nevents = gime->MaxEvent() ;
138 for(ievent = 0; ievent < nevents; ievent++)
140 gime->Event(ievent, "D");
142 GetCalibrationParameters() ;
144 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
153 if(strstr(option,"deb"))
154 PrintRecPoints(option) ;
156 //increment the total number of recpoints per run
157 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
158 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
163 if(strstr(option,"tim")){
164 gBenchmark->Stop("PHOSClusterizer");
165 Info("Exec", " took %f seconds for Clusterizing %f seconds per event \n",
166 gBenchmark->GetCpuTime("PHOSClusterizer"),
167 gBenchmark->GetCpuTime("PHOSClusterizer")/nevents ) ;
171 //____________________________________________________________________________
172 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
173 Int_t nPar, Float_t * fitparameters) const
175 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
176 // The initial values for fitting procedure are set equal to the positions of local maxima.
177 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
180 AliPHOSGetter * gime = AliPHOSGetter::Instance();
181 TClonesArray * digits = gime->Digits();
184 gMinuit->mncler(); // Reset Minuit's list of paramters
185 gMinuit->SetPrintLevel(-1) ; // No Printout
186 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
187 // To set the address of the minimization function
189 TList * toMinuit = new TList();
190 toMinuit->AddAt(emcRP,0) ;
191 toMinuit->AddAt(digits,1) ;
193 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
195 // filling initial values for fit parameters
196 AliPHOSDigit * digit ;
200 Int_t nDigits = (Int_t) nPar / 3 ;
204 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
206 for(iDigit = 0; iDigit < nDigits; iDigit++){
207 digit = maxAt[iDigit];
212 geom->AbsToRelNumbering(digit->GetId(), relid) ;
213 geom->RelPosInModule(relid, x, z) ;
215 Float_t energy = maxAtEnergy[iDigit] ;
217 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
220 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
223 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
226 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
229 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
232 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
237 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
242 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
243 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
244 gMinuit->SetMaxIterations(5);
245 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
247 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
249 if(ierflg == 4){ // Minimum not found
250 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
253 for(index = 0; index < nPar; index++){
256 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
257 fitparameters[index] = val ;
265 //____________________________________________________________________________
266 void AliPHOSClusterizerv1::GetCalibrationParameters()
269 AliPHOSGetter * gime = AliPHOSGetter::Instance();
271 if ( !gime->Digitizer() )
272 gime->LoadDigitizer();
273 AliPHOSDigitizer * dig = gime->Digitizer();
275 fADCchanelEmc = dig->GetEMCchannel() ;
276 fADCpedestalEmc = dig->GetEMCpedestal();
278 fADCchanelCpv = dig->GetCPVchannel() ;
279 fADCpedestalCpv = dig->GetCPVpedestal() ;
281 // fCalibrationDB = gime->CalibrationDB();
284 //____________________________________________________________________________
285 void AliPHOSClusterizerv1::Init()
287 // Make all memory allocations which can not be done in default constructor.
288 // Attach the Clusterizer task to the list of PHOS tasks
290 AliPHOSGetter* gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
292 AliPHOSGeometry * geom = gime->PHOSGeometry();
294 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
297 gMinuit = new TMinuit(100);
299 if ( !gime->Clusterizer() )
300 gime->PostClusterizer(this);
303 //____________________________________________________________________________
304 void AliPHOSClusterizerv1::InitParameters()
307 fNumberOfCpvClusters = 0 ;
308 fNumberOfEmcClusters = 0 ;
310 fCpvClusteringThreshold = 0.0;
311 fEmcClusteringThreshold = 0.2;
313 fEmcLocMaxCut = 0.03 ;
314 fCpvLocMaxCut = 0.03 ;
319 fEmcTimeGate = 1.e-8 ;
323 fRecPointsInRun = 0 ;
327 //____________________________________________________________________________
328 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
330 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
332 // = 2 are not neighbour but do not continue searching
333 // neighbours are defined as digits having at least a common vertex
334 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
335 // which is compared to a digit (d2) not yet in a cluster
337 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
342 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
345 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
347 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
348 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
349 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
351 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
352 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
356 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
357 rv = 2; // Difference in row numbers is too large to look further
363 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
372 //____________________________________________________________________________
373 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
375 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
378 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
380 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
382 if(digit->GetId() <= nEMC ) rv = kTRUE;
387 //____________________________________________________________________________
388 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
390 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
394 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
396 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
398 if(digit->GetId() > nEMC ) rv = kTRUE;
403 //____________________________________________________________________________
404 void AliPHOSClusterizerv1::Unload()
406 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
407 gime->PhosLoader()->UnloadDigits() ;
408 gime->PhosLoader()->UnloadRecPoints() ;
411 //____________________________________________________________________________
412 void AliPHOSClusterizerv1::WriteRecPoints()
415 // Creates new branches with given title
416 // fills and writes into TreeR.
418 AliPHOSGetter * gime = AliPHOSGetter::Instance();
420 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
421 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
422 TClonesArray * digits = gime->Digits() ;
424 TTree * treeR = gime->TreeR();
427 //Evaluate position, dispersion and other RecPoint properties...
428 for(index = 0; index < emcRecPoints->GetEntries(); index++)
429 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->EvalAll(fW0,digits) ;
431 emcRecPoints->Sort() ;
432 for(index = 0; index < emcRecPoints->GetEntries(); index++)
433 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
435 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
437 //Now the same for CPV
438 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
439 dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) )->EvalAll(fW0CPV,digits) ;
441 cpvRecPoints->Sort() ;
443 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
444 dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
446 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
448 Int_t bufferSize = 32000 ;
449 Int_t splitlevel = 0 ;
452 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
453 emcBranch->SetTitle(BranchName());
456 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
457 cpvBranch->SetTitle(BranchName());
462 gime->WriteRecPoints("OVERWRITE");
463 gime->WriteClusterizer("OVERWRITE");
466 //____________________________________________________________________________
467 void AliPHOSClusterizerv1::MakeClusters()
469 // Steering method to construct the clusters stored in a list of Reconstructed Points
470 // A cluster is defined as a list of neighbour digits
473 AliPHOSGetter * gime = AliPHOSGetter::Instance();
475 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
476 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
478 emcRecPoints->Delete() ;
479 cpvRecPoints->Delete() ;
481 TClonesArray * digits = gime->Digits() ;
483 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
486 // Clusterization starts
488 TIter nextdigit(digitsC) ;
489 AliPHOSDigit * digit ;
490 Bool_t notremoved = kTRUE ;
492 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
495 AliPHOSRecPoint * clu = 0 ;
497 TArrayI clusterdigitslist(1500) ;
500 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
501 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
502 Int_t iDigitInCluster = 0 ;
504 if ( IsInEmc(digit) ) {
505 // start a new EMC RecPoint
506 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
507 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
509 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
510 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
511 fNumberOfEmcClusters++ ;
512 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
513 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
515 digitsC->Remove(digit) ;
519 // start a new CPV cluster
520 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
521 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
523 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
525 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
526 fNumberOfCpvClusters++ ;
527 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
528 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
530 digitsC->Remove(digit) ;
533 // Here we remove remaining EMC digits, which cannot make a cluster
536 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
538 digitsC->Remove(digit) ;
542 notremoved = kFALSE ;
549 AliPHOSDigit * digitN ;
551 while (index < iDigitInCluster){ // scan over digits already in cluster
552 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
554 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
555 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
557 case 0 : // not a neighbour
559 case 1 : // are neighbours
560 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
561 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
563 digitsC->Remove(digitN) ;
565 case 2 : // too far from each other
574 } // loop over cluster
585 //____________________________________________________________________________
586 void AliPHOSClusterizerv1::MakeUnfolding()
588 // Unfolds clusters using the shape of an ElectroMagnetic shower
589 // Performs unfolding of all EMC/CPV clusters
591 AliPHOSGetter * gime = AliPHOSGetter::Instance();
593 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
595 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
596 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
597 TClonesArray * digits = gime->Digits() ;
599 // Unfold first EMC clusters
600 if(fNumberOfEmcClusters > 0){
602 Int_t nModulesToUnfold = geom->GetNModules() ;
604 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
606 for(index = 0 ; index < numberofNotUnfolded ; index++){
608 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
609 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
612 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
613 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
614 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
615 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
617 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
618 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
619 emcRecPoints->Remove(emcRecPoint);
620 emcRecPoints->Compress() ;
622 fNumberOfEmcClusters -- ;
623 numberofNotUnfolded-- ;
627 delete[] maxAtEnergy ;
630 // Unfolding of EMC clusters finished
633 // Unfold now CPV clusters
634 if(fNumberOfCpvClusters > 0){
636 Int_t nModulesToUnfold = geom->GetNModules() ;
638 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
640 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
642 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
644 if(recPoint->GetPHOSMod()> nModulesToUnfold)
647 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
649 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
650 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
651 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
652 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
654 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
655 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
656 cpvRecPoints->Remove(emcRecPoint);
657 cpvRecPoints->Compress() ;
659 numberofCpvNotUnfolded-- ;
660 fNumberOfCpvClusters-- ;
664 delete[] maxAtEnergy ;
667 //Unfolding of Cpv clusters finished
671 //____________________________________________________________________________
672 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
674 // Shape of the shower (see PHOS TDR)
675 // If you change this function, change also the gradient evaluation in ChiSquare()
677 Double_t r4 = r*r*r*r ;
678 Double_t r295 = TMath::Power(r, 2.95) ;
679 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
683 //____________________________________________________________________________
684 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
686 AliPHOSDigit ** maxAt,
687 Float_t * maxAtEnergy)
689 // Performs the unfolding of a cluster with nMax overlapping showers
691 AliPHOSGetter * gime = AliPHOSGetter::Instance();
693 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
695 const TClonesArray * digits = gime->Digits() ;
696 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
697 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
699 Int_t nPar = 3 * nMax ;
700 Float_t * fitparameters = new Float_t[nPar] ;
702 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
704 // Fit failed, return and remove cluster
705 delete[] fitparameters ;
709 // create ufolded rec points and fill them with new energy lists
710 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
711 // and later correct this number in acordance with actual energy deposition
713 Int_t nDigits = iniEmc->GetMultiplicity() ;
714 Float_t * efit = new Float_t[nDigits] ;
715 Float_t xDigit=0.,zDigit=0.,distance=0. ;
716 Float_t xpar=0.,zpar=0.,epar=0. ;
718 AliPHOSDigit * digit = 0 ;
719 Int_t * emcDigits = iniEmc->GetDigitsList() ;
723 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
724 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
725 geom->AbsToRelNumbering(digit->GetId(), relid) ;
726 geom->RelPosInModule(relid, xDigit, zDigit) ;
730 while(iparam < nPar ){
731 xpar = fitparameters[iparam] ;
732 zpar = fitparameters[iparam+1] ;
733 epar = fitparameters[iparam+2] ;
735 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
736 distance = TMath::Sqrt(distance) ;
737 efit[iDigit] += epar * ShowerShape(distance) ;
742 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
743 // so that energy deposited in each cell is distributed betwin new clusters proportionally
744 // to its contribution to efit
746 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
750 while(iparam < nPar ){
751 xpar = fitparameters[iparam] ;
752 zpar = fitparameters[iparam+1] ;
753 epar = fitparameters[iparam+2] ;
756 AliPHOSEmcRecPoint * emcRP = 0 ;
758 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
760 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
761 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
763 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
764 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
765 fNumberOfEmcClusters++ ;
767 else{//create new entries in fCpvRecPoints
768 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
769 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
771 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
772 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
773 fNumberOfCpvClusters++ ;
777 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
778 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
779 geom->AbsToRelNumbering(digit->GetId(), relid) ;
780 geom->RelPosInModule(relid, xDigit, zDigit) ;
781 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
782 distance = TMath::Sqrt(distance) ;
783 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
784 eDigit = emcEnergies[iDigit] * ratio ;
785 emcRP->AddDigit( *digit, eDigit ) ;
789 delete[] fitparameters ;
794 //_____________________________________________________________________________
795 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
797 // Calculates the Chi square for the cluster unfolding minimization
798 // Number of parameters, Gradient, Chi squared, parameters, what to do
800 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
802 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
803 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
807 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
809 Int_t * emcDigits = emcRP->GetDigitsList() ;
811 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
813 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
815 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
820 for(iparam = 0 ; iparam < nPar ; iparam++)
821 Grad[iparam] = 0 ; // Will evaluate gradient
825 AliPHOSDigit * digit ;
828 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
830 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
836 geom->AbsToRelNumbering(digit->GetId(), relid) ;
838 geom->RelPosInModule(relid, xDigit, zDigit) ;
840 if(iflag == 2){ // calculate gradient
843 while(iParam < nPar ){
844 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
846 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
847 distance = TMath::Sqrt( distance ) ;
849 efit += x[iParam] * ShowerShape(distance) ;
852 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
854 while(iParam < nPar ){
855 Double_t xpar = x[iParam] ;
856 Double_t zpar = x[iParam+1] ;
857 Double_t epar = x[iParam+2] ;
858 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
859 Double_t shape = sum * ShowerShape(dr) ;
860 Double_t r4 = dr*dr*dr*dr ;
861 Double_t r295 = TMath::Power(dr,2.95) ;
862 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
863 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
865 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
867 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
869 Grad[iParam] += shape ; // Derivative over energy
876 while(iparam < nPar ){
877 Double_t xpar = x[iparam] ;
878 Double_t zpar = x[iparam+1] ;
879 Double_t epar = x[iparam+2] ;
881 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
882 distance = TMath::Sqrt(distance) ;
883 efit += epar * ShowerShape(distance) ;
886 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
887 // Here we assume, that sigma = sqrt(E)
892 //____________________________________________________________________________
893 void AliPHOSClusterizerv1::Print()const
895 // Print clusterizer parameters
898 TString taskName(GetName()) ;
899 taskName.ReplaceAll(Version(), "") ;
901 if( strcmp(GetName(), "") !=0 ) {
903 message = "\n--------------- %s %s -----------\n" ;
904 message += "Clusterizing digits from the file: %s\n" ;
905 message += " Branch: %s\n" ;
906 message += " EMC Clustering threshold = %f\n" ;
907 message += " EMC Local Maximum cut = %f\n" ;
908 message += " EMC Logarothmic weight = %f\n" ;
909 message += " CPV Clustering threshold = %f\n" ;
910 message += " CPV Local Maximum cut = %f\n" ;
911 message += " CPV Logarothmic weight = %f\n" ;
913 message += " Unfolding on\n" ;
915 message += " Unfolding off\n" ;
917 message += "------------------------------------------------------------------" ;
920 message = " AliPHOSClusterizerv1 not initialized " ;
922 Info("Print", message.Data(),
927 fEmcClusteringThreshold,
930 fCpvClusteringThreshold,
936 //____________________________________________________________________________
937 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
939 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
941 AliPHOSGetter * gime = AliPHOSGetter::Instance();
943 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
944 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
946 printf("\nevent %d \n", gAlice->GetEvNumber()) ;
947 printf(" Found %d EMC RecPoints and %d CPV RecPoints \n",
948 emcRecPoints->GetEntriesFast(),cpvRecPoints->GetEntriesFast()) ;
950 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
951 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
954 if(strstr(option,"all")) {
955 printf("\n EMC clusters \n") ;
956 printf("Index Ene(MeV) Multi Module X Y Z Lambdas_1 Lambda_2 # of prim Primaries list\n") ;
958 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
959 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
961 rp->GetLocalPosition(locpos);
963 rp->GetElipsAxis(lambda);
966 primaries = rp->GetPrimaries(nprimaries);
967 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
968 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
969 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
971 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
972 printf("%d ", primaries[iprimary] ) ;
977 //Now plot CPV recPoints
978 printf("\n CPV clusters \n") ;
979 printf("Index Ene(MeV) Module X Y Z \n") ;
980 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
981 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
984 rp->GetLocalPosition(locpos);
986 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f \n",
987 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
988 locpos.X(), locpos.Y(), locpos.Z()) ;