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 ---
51 #include "TBenchmark.h"
53 // --- Standard library ---
55 // --- AliRoot header files ---
56 #include "AliPHOSGetter.h"
57 #include "AliPHOSGeometry.h"
58 #include "AliPHOSClusterizerv1.h"
59 #include "AliPHOSEmcRecPoint.h"
60 #include "AliPHOSCpvRecPoint.h"
61 #include "AliPHOSDigit.h"
62 #include "AliPHOSDigitizer.h"
64 ClassImp(AliPHOSClusterizerv1)
66 //____________________________________________________________________________
67 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
69 // default ctor (to be used mainly by Streamer)
72 fDefaultInit = kTRUE ;
75 //____________________________________________________________________________
76 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const TString alirunFileName, const TString eventFolderName)
77 :AliPHOSClusterizer(alirunFileName, eventFolderName)
79 // ctor with the indication of the file where header Tree and digits Tree are stored
83 fDefaultInit = kFALSE ;
86 //____________________________________________________________________________
87 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
91 // delete fPedestals ;
96 //____________________________________________________________________________
97 const TString AliPHOSClusterizerv1::BranchName() const
102 //____________________________________________________________________________
103 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
105 //To be replaced later by the method, reading individual parameters from the database
106 // if(fCalibrationDB)
107 // return fCalibrationDB->Calibrate(amp,absId) ;
108 // else{ //simulation
109 if(absId <= fEmcCrystals) //calibrate as EMC
110 return fADCpedestalEmc + amp*fADCchanelEmc ;
111 else //calibrate as CPV
112 return fADCpedestalCpv+ amp*fADCchanelCpv ;
116 //____________________________________________________________________________
117 void AliPHOSClusterizerv1::Exec(Option_t *option)
119 // Steering method to perform clusterization for events
120 // in the range from fFirstEvent to fLastEvent.
121 // This range is optionally set by SetEventRange().
122 // if fLastEvent=-1 (by default), then process events until the end.
124 if(strstr(option,"tim"))
125 gBenchmark->Start("PHOSClusterizer");
127 if(strstr(option,"print")) {
132 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
134 if (fLastEvent == -1)
135 fLastEvent = gime->MaxEvent() - 1 ;
137 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // one event at the time
138 Int_t nEvents = fLastEvent - fFirstEvent + 1;
141 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
142 gime->Event(ievent, "D");
144 GetCalibrationParameters() ;
146 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
155 if(strstr(option,"deb"))
156 PrintRecPoints(option) ;
158 //increment the total number of recpoints per run
159 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
160 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
165 if(strstr(option,"tim")){
166 gBenchmark->Stop("PHOSClusterizer");
167 Info("Exec", " took %f seconds for Clusterizing %f seconds per event \n",
168 gBenchmark->GetCpuTime("PHOSClusterizer"),
169 gBenchmark->GetCpuTime("PHOSClusterizer")/nEvents ) ;
173 //____________________________________________________________________________
174 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
175 Int_t nPar, Float_t * fitparameters) const
177 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
178 // The initial values for fitting procedure are set equal to the positions of local maxima.
179 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
182 AliPHOSGetter * gime = AliPHOSGetter::Instance();
183 TClonesArray * digits = gime->Digits();
186 gMinuit->mncler(); // Reset Minuit's list of paramters
187 gMinuit->SetPrintLevel(-1) ; // No Printout
188 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
189 // To set the address of the minimization function
191 TList * toMinuit = new TList();
192 toMinuit->AddAt(emcRP,0) ;
193 toMinuit->AddAt(digits,1) ;
195 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
197 // filling initial values for fit parameters
198 AliPHOSDigit * digit ;
202 Int_t nDigits = (Int_t) nPar / 3 ;
206 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
208 for(iDigit = 0; iDigit < nDigits; iDigit++){
209 digit = maxAt[iDigit];
214 geom->AbsToRelNumbering(digit->GetId(), relid) ;
215 geom->RelPosInModule(relid, x, z) ;
217 Float_t energy = maxAtEnergy[iDigit] ;
219 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
222 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
225 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
228 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
231 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
234 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
239 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
244 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
245 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
246 gMinuit->SetMaxIterations(5);
247 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
249 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
251 if(ierflg == 4){ // Minimum not found
252 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
255 for(index = 0; index < nPar; index++){
258 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
259 fitparameters[index] = val ;
267 //____________________________________________________________________________
268 void AliPHOSClusterizerv1::GetCalibrationParameters()
271 AliPHOSGetter * gime = AliPHOSGetter::Instance();
273 if ( !gime->Digitizer() )
274 gime->LoadDigitizer();
275 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 ;
326 SetEventRange(0,-1) ;
329 //____________________________________________________________________________
330 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
332 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
334 // = 2 are not neighbour but do not continue searching
335 // neighbours are defined as digits having at least a common vertex
336 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
337 // which is compared to a digit (d2) not yet in a cluster
339 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
344 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
347 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
349 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
350 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
351 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
353 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
354 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
358 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
359 rv = 2; // Difference in row numbers is too large to look further
365 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
374 //____________________________________________________________________________
375 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
377 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
380 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
382 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
384 if(digit->GetId() <= nEMC ) rv = kTRUE;
389 //____________________________________________________________________________
390 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
392 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
396 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
398 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
400 if(digit->GetId() > nEMC ) rv = kTRUE;
405 //____________________________________________________________________________
406 void AliPHOSClusterizerv1::Unload()
408 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
409 gime->PhosLoader()->UnloadDigits() ;
410 gime->PhosLoader()->UnloadRecPoints() ;
413 //____________________________________________________________________________
414 void AliPHOSClusterizerv1::WriteRecPoints()
417 // Creates new branches with given title
418 // fills and writes into TreeR.
420 AliPHOSGetter * gime = AliPHOSGetter::Instance();
422 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
423 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
424 TClonesArray * digits = gime->Digits() ;
426 TTree * treeR = gime->TreeR();
429 //Evaluate position, dispersion and other RecPoint properties...
430 for(index = 0; index < emcRecPoints->GetEntries(); index++)
431 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->EvalAll(fW0,digits) ;
433 emcRecPoints->Sort() ;
434 for(index = 0; index < emcRecPoints->GetEntries(); index++)
435 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
437 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
439 //Now the same for CPV
440 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
441 dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) )->EvalAll(fW0CPV,digits) ;
443 cpvRecPoints->Sort() ;
445 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
446 dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
448 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
450 Int_t bufferSize = 32000 ;
451 Int_t splitlevel = 0 ;
454 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
455 emcBranch->SetTitle(BranchName());
458 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
459 cpvBranch->SetTitle(BranchName());
464 gime->WriteRecPoints("OVERWRITE");
465 gime->WriteClusterizer("OVERWRITE");
468 //____________________________________________________________________________
469 void AliPHOSClusterizerv1::MakeClusters()
471 // Steering method to construct the clusters stored in a list of Reconstructed Points
472 // A cluster is defined as a list of neighbour digits
475 AliPHOSGetter * gime = AliPHOSGetter::Instance();
477 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
478 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
480 emcRecPoints->Delete() ;
481 cpvRecPoints->Delete() ;
483 TClonesArray * digits = gime->Digits() ;
485 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
488 // Clusterization starts
490 TIter nextdigit(digitsC) ;
491 AliPHOSDigit * digit ;
492 Bool_t notremoved = kTRUE ;
494 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
497 AliPHOSRecPoint * clu = 0 ;
499 TArrayI clusterdigitslist(1500) ;
502 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
503 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
504 Int_t iDigitInCluster = 0 ;
506 if ( IsInEmc(digit) ) {
507 // start a new EMC RecPoint
508 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
509 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
511 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
512 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
513 fNumberOfEmcClusters++ ;
514 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
515 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
517 digitsC->Remove(digit) ;
521 // start a new CPV cluster
522 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
523 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
525 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
527 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
528 fNumberOfCpvClusters++ ;
529 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
530 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
532 digitsC->Remove(digit) ;
535 // Here we remove remaining EMC digits, which cannot make a cluster
538 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
540 digitsC->Remove(digit) ;
544 notremoved = kFALSE ;
551 AliPHOSDigit * digitN ;
553 while (index < iDigitInCluster){ // scan over digits already in cluster
554 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
556 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
557 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
559 case 0 : // not a neighbour
561 case 1 : // are neighbours
562 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
563 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
565 digitsC->Remove(digitN) ;
567 case 2 : // too far from each other
576 } // loop over cluster
587 //____________________________________________________________________________
588 void AliPHOSClusterizerv1::MakeUnfolding()
590 // Unfolds clusters using the shape of an ElectroMagnetic shower
591 // Performs unfolding of all EMC/CPV clusters
593 AliPHOSGetter * gime = AliPHOSGetter::Instance();
595 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
597 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
598 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
599 TClonesArray * digits = gime->Digits() ;
601 // Unfold first EMC clusters
602 if(fNumberOfEmcClusters > 0){
604 Int_t nModulesToUnfold = geom->GetNModules() ;
606 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
608 for(index = 0 ; index < numberofNotUnfolded ; index++){
610 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
611 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
614 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
615 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
616 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
617 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
619 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
620 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
621 emcRecPoints->Remove(emcRecPoint);
622 emcRecPoints->Compress() ;
624 fNumberOfEmcClusters -- ;
625 numberofNotUnfolded-- ;
629 delete[] maxAtEnergy ;
632 // Unfolding of EMC clusters finished
635 // Unfold now CPV clusters
636 if(fNumberOfCpvClusters > 0){
638 Int_t nModulesToUnfold = geom->GetNModules() ;
640 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
642 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
644 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
646 if(recPoint->GetPHOSMod()> nModulesToUnfold)
649 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
651 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
652 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
653 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
654 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
656 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
657 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
658 cpvRecPoints->Remove(emcRecPoint);
659 cpvRecPoints->Compress() ;
661 numberofCpvNotUnfolded-- ;
662 fNumberOfCpvClusters-- ;
666 delete[] maxAtEnergy ;
669 //Unfolding of Cpv clusters finished
673 //____________________________________________________________________________
674 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
676 // Shape of the shower (see PHOS TDR)
677 // If you change this function, change also the gradient evaluation in ChiSquare()
679 Double_t r4 = r*r*r*r ;
680 Double_t r295 = TMath::Power(r, 2.95) ;
681 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
685 //____________________________________________________________________________
686 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
688 AliPHOSDigit ** maxAt,
689 Float_t * maxAtEnergy)
691 // Performs the unfolding of a cluster with nMax overlapping showers
693 AliPHOSGetter * gime = AliPHOSGetter::Instance();
695 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
697 const TClonesArray * digits = gime->Digits() ;
698 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
699 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
701 Int_t nPar = 3 * nMax ;
702 Float_t * fitparameters = new Float_t[nPar] ;
704 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
706 // Fit failed, return and remove cluster
707 delete[] fitparameters ;
711 // create ufolded rec points and fill them with new energy lists
712 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
713 // and later correct this number in acordance with actual energy deposition
715 Int_t nDigits = iniEmc->GetMultiplicity() ;
716 Float_t * efit = new Float_t[nDigits] ;
717 Float_t xDigit=0.,zDigit=0.,distance=0. ;
718 Float_t xpar=0.,zpar=0.,epar=0. ;
720 AliPHOSDigit * digit = 0 ;
721 Int_t * emcDigits = iniEmc->GetDigitsList() ;
725 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
726 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
727 geom->AbsToRelNumbering(digit->GetId(), relid) ;
728 geom->RelPosInModule(relid, xDigit, zDigit) ;
732 while(iparam < nPar ){
733 xpar = fitparameters[iparam] ;
734 zpar = fitparameters[iparam+1] ;
735 epar = fitparameters[iparam+2] ;
737 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
738 distance = TMath::Sqrt(distance) ;
739 efit[iDigit] += epar * ShowerShape(distance) ;
744 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
745 // so that energy deposited in each cell is distributed betwin new clusters proportionally
746 // to its contribution to efit
748 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
752 while(iparam < nPar ){
753 xpar = fitparameters[iparam] ;
754 zpar = fitparameters[iparam+1] ;
755 epar = fitparameters[iparam+2] ;
758 AliPHOSEmcRecPoint * emcRP = 0 ;
760 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
762 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
763 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
765 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
766 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
767 fNumberOfEmcClusters++ ;
769 else{//create new entries in fCpvRecPoints
770 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
771 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
773 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
774 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
775 fNumberOfCpvClusters++ ;
779 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
780 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
781 geom->AbsToRelNumbering(digit->GetId(), relid) ;
782 geom->RelPosInModule(relid, xDigit, zDigit) ;
783 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
784 distance = TMath::Sqrt(distance) ;
785 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
786 eDigit = emcEnergies[iDigit] * ratio ;
787 emcRP->AddDigit( *digit, eDigit ) ;
791 delete[] fitparameters ;
796 //_____________________________________________________________________________
797 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
799 // Calculates the Chi square for the cluster unfolding minimization
800 // Number of parameters, Gradient, Chi squared, parameters, what to do
802 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
804 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
805 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
809 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
811 Int_t * emcDigits = emcRP->GetDigitsList() ;
813 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
815 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
817 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
822 for(iparam = 0 ; iparam < nPar ; iparam++)
823 Grad[iparam] = 0 ; // Will evaluate gradient
827 AliPHOSDigit * digit ;
830 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
832 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
838 geom->AbsToRelNumbering(digit->GetId(), relid) ;
840 geom->RelPosInModule(relid, xDigit, zDigit) ;
842 if(iflag == 2){ // calculate gradient
845 while(iParam < nPar ){
846 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
848 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
849 distance = TMath::Sqrt( distance ) ;
851 efit += x[iParam] * ShowerShape(distance) ;
854 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
856 while(iParam < nPar ){
857 Double_t xpar = x[iParam] ;
858 Double_t zpar = x[iParam+1] ;
859 Double_t epar = x[iParam+2] ;
860 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
861 Double_t shape = sum * ShowerShape(dr) ;
862 Double_t r4 = dr*dr*dr*dr ;
863 Double_t r295 = TMath::Power(dr,2.95) ;
864 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
865 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
867 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
869 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
871 Grad[iParam] += shape ; // Derivative over energy
878 while(iparam < nPar ){
879 Double_t xpar = x[iparam] ;
880 Double_t zpar = x[iparam+1] ;
881 Double_t epar = x[iparam+2] ;
883 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
884 distance = TMath::Sqrt(distance) ;
885 efit += epar * ShowerShape(distance) ;
888 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
889 // Here we assume, that sigma = sqrt(E)
894 //____________________________________________________________________________
895 void AliPHOSClusterizerv1::Print()const
897 // Print clusterizer parameters
900 TString taskName(GetName()) ;
901 taskName.ReplaceAll(Version(), "") ;
903 if( strcmp(GetName(), "") !=0 ) {
905 message = "\n--------------- %s %s -----------\n" ;
906 message += "Clusterizing digits from the file: %s\n" ;
907 message += " Branch: %s\n" ;
908 message += " EMC Clustering threshold = %f\n" ;
909 message += " EMC Local Maximum cut = %f\n" ;
910 message += " EMC Logarothmic weight = %f\n" ;
911 message += " CPV Clustering threshold = %f\n" ;
912 message += " CPV Local Maximum cut = %f\n" ;
913 message += " CPV Logarothmic weight = %f\n" ;
915 message += " Unfolding on\n" ;
917 message += " Unfolding off\n" ;
919 message += "------------------------------------------------------------------" ;
922 message = " AliPHOSClusterizerv1 not initialized " ;
924 Info("Print", message.Data(),
929 fEmcClusteringThreshold,
932 fCpvClusteringThreshold,
938 //____________________________________________________________________________
939 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
941 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
943 AliPHOSGetter * gime = AliPHOSGetter::Instance();
945 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
946 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
948 printf("\nevent %d \n", gAlice->GetEvNumber()) ;
949 printf(" Found %d EMC RecPoints and %d CPV RecPoints \n",
950 emcRecPoints->GetEntriesFast(),cpvRecPoints->GetEntriesFast()) ;
952 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
953 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
956 if(strstr(option,"all")) {
957 printf("\n EMC clusters \n") ;
958 printf("Index Ene(MeV) Multi Module X Y Z Lambdas_1 Lambda_2 # of prim Primaries list\n") ;
960 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
961 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
963 rp->GetLocalPosition(locpos);
965 rp->GetElipsAxis(lambda);
968 primaries = rp->GetPrimaries(nprimaries);
969 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
970 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
971 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
973 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
974 printf("%d ", primaries[iprimary] ) ;
979 //Now plot CPV recPoints
980 printf("\n CPV clusters \n") ;
981 printf("Index Ene(MeV) Module X Y Z \n") ;
982 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
983 AliPHOSCpvRecPoint * rp = (AliPHOSCpvRecPoint * )cpvRecPoints->At(index) ;
986 rp->GetLocalPosition(locpos);
988 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f \n",
989 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
990 locpos.X(), locpos.Y(), locpos.Z()) ;