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 **************************************************************************/
19 1 October 2000. Yuri Kharlov:
21 PPSD upper layer is considered if number of layers>1
23 18 October 2000. Yuri Kharlov:
24 AliPHOSClusterizerv1()
25 CPV clusterizing parameters added
28 After first PPSD digit remove EMC digits only once
30 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
31 //////////////////////////////////////////////////////////////////////////////
32 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
33 // unfolds the clusters having several local maxima.
34 // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
35 // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
36 // parameters including input digits branch title, thresholds etc.)
37 // This TTask is normally called from Reconstructioner, but can as well be used in
40 // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
41 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
42 // // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
43 // // and saves recpoints in branch named "recpointsname" (default = "digitsname")
44 // root [1] cl->ExecuteTask()
45 // //finds RecPoints in all events stored in galice.root
46 // root [2] cl->SetDigitsBranch("digits2")
47 // //sets another title for Digitis (input) branch
48 // root [3] cl->SetRecPointsBranch("recp2")
49 // //sets another title four output branches
50 // root [4] cl->SetEmcLocalMaxCut(0.03)
51 // //set clusterization parameters
52 // root [5] cl->ExecuteTask("deb all time")
53 // //once more finds RecPoints options are
54 // // deb - print number of found rec points
55 // // deb all - print number of found RecPoints and some their characteristics
56 // // time - print benchmarking results
58 // --- ROOT system ---
67 #include "TBenchmark.h"
69 // --- Standard library ---
74 // --- AliRoot header files ---
76 #include "AliPHOSClusterizerv1.h"
77 #include "AliPHOSCpvRecPoint.h"
78 #include "AliPHOSDigit.h"
79 #include "AliPHOSDigitizer.h"
80 #include "AliPHOSEmcRecPoint.h"
82 #include "AliPHOSGetter.h"
85 ClassImp(AliPHOSClusterizerv1)
87 //____________________________________________________________________________
88 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
90 // default ctor (to be used mainly by Streamer)
93 fDefaultInit = kTRUE ;
96 //____________________________________________________________________________
97 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* name, const Bool_t toSplit)
98 :AliPHOSClusterizer(headerFile, name, toSplit)
100 // ctor with the indication of the file where header Tree and digits Tree are stored
104 fDefaultInit = kFALSE ;
108 //____________________________________________________________________________
109 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
116 //____________________________________________________________________________
117 const TString AliPHOSClusterizerv1::BranchName() const
119 TString branchName(GetName() ) ;
120 branchName.Remove(branchName.Index(Version())-1) ;
124 //____________________________________________________________________________
125 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
126 { //To be replased later by the method, reading individual parameters from the database
128 if(absId <= fEmcCrystals) //calibrate as EMC
129 return fADCpedestalEmc + amp*fADCchanelEmc ;
131 else //Digitize as CPV
132 return fADCpedestalCpv+ amp*fADCchanelCpv ;
135 //____________________________________________________________________________
136 void AliPHOSClusterizerv1::Exec(Option_t * option)
140 if( strcmp(GetName(), "")== 0 )
143 if(strstr(option,"tim"))
144 gBenchmark->Start("PHOSClusterizer");
146 if(strstr(option,"print"))
149 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
150 if(gime->BranchExists("RecPoints"))
152 Int_t nevents = gime->MaxEvent() ;
155 for(ievent = 0; ievent < nevents; ievent++){
157 gime->Event(ievent,"D") ;
160 GetCalibrationParameters() ;
162 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
169 WriteRecPoints(ievent) ;
171 if(strstr(option,"deb"))
172 PrintRecPoints(option) ;
174 //increment the total number of digits per run
175 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
176 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
179 if(strstr(option,"tim")){
180 gBenchmark->Stop("PHOSClusterizer");
181 cout << "AliPHOSClusterizer:" << endl ;
182 cout << " took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing "
183 << gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
189 //____________________________________________________________________________
190 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
191 Int_t nPar, Float_t * fitparameters) const
193 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
194 // The initial values for fitting procedure are set equal to the positions of local maxima.
195 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
197 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
198 TClonesArray * digits = gime->Digits() ;
201 gMinuit->mncler(); // Reset Minuit's list of paramters
202 gMinuit->SetPrintLevel(-1) ; // No Printout
203 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
204 // To set the address of the minimization function
206 TList * toMinuit = new TList();
207 toMinuit->AddAt(emcRP,0) ;
208 toMinuit->AddAt(digits,1) ;
210 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
212 // filling initial values for fit parameters
213 AliPHOSDigit * digit ;
217 Int_t nDigits = (Int_t) nPar / 3 ;
221 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
223 for(iDigit = 0; iDigit < nDigits; iDigit++){
224 digit = maxAt[iDigit];
229 geom->AbsToRelNumbering(digit->GetId(), relid) ;
230 geom->RelPosInModule(relid, x, z) ;
232 Float_t energy = maxAtEnergy[iDigit] ;
234 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
237 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
240 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
243 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
246 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
249 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
254 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
259 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
260 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
261 gMinuit->SetMaxIterations(5);
262 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
264 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
266 if(ierflg == 4){ // Minimum not found
267 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
270 for(index = 0; index < nPar; index++){
273 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
274 fitparameters[index] = val ;
282 //____________________________________________________________________________
283 void AliPHOSClusterizerv1::GetCalibrationParameters()
285 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
286 const AliPHOSDigitizer * dig = gime->Digitizer(BranchName()) ;
288 fADCchanelEmc = dig->GetEMCchannel() ;
289 fADCpedestalEmc = dig->GetEMCpedestal();
291 fADCchanelCpv = dig->GetCPVchannel() ;
292 fADCpedestalCpv = dig->GetCPVpedestal() ;
296 //____________________________________________________________________________
297 void AliPHOSClusterizerv1::Init()
299 // Make all memory allocations which can not be done in default constructor.
300 // Attach the Clusterizer task to the list of PHOS tasks
302 if ( strcmp(GetTitle(), "") == 0 )
303 SetTitle("galice.root") ;
305 TString branchname = GetName() ;
306 branchname.Remove(branchname.Index(Version())-1) ;
308 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(),branchname.Data(), fToSplit ) ;
310 cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ;
316 // construct the name of the file as /path/EMCAL.SDigits.root
317 //First - extract full path if necessary
318 TString fileName(GetTitle()) ;
319 Ssiz_t islash = fileName.Last('/') ;
320 if(islash<fileName.Length())
321 fileName.Remove(islash+1,fileName.Length()) ;
324 // Next - append the file name
325 fileName+="PHOS.RecData." ;
326 if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
327 fileName+=branchname ;
331 // Finally - check if the file already opened or open the file
332 fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));
334 fSplitFile = TFile::Open(fileName.Data(),"update") ;
339 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
340 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
343 gMinuit = new TMinuit(100) ;
345 gime->PostClusterizer(this) ;
346 gime->PostRecPoints(branchname) ;
350 //____________________________________________________________________________
351 void AliPHOSClusterizerv1::InitParameters()
354 fNumberOfCpvClusters = 0 ;
355 fNumberOfEmcClusters = 0 ;
357 fCpvClusteringThreshold = 0.0;
358 fEmcClusteringThreshold = 0.2;
360 fEmcLocMaxCut = 0.03 ;
361 fCpvLocMaxCut = 0.03 ;
366 fEmcTimeGate = 1.e-8 ;
370 TString clusterizerName( GetName()) ;
371 if (clusterizerName.IsNull() )
372 clusterizerName = "Default" ;
373 clusterizerName.Append(":") ;
374 clusterizerName.Append(Version()) ;
375 SetName(clusterizerName) ;
376 fRecPointsInRun = 0 ;
380 //____________________________________________________________________________
381 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
383 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
385 // = 2 are not neighbour but do not continue searching
386 // neighbours are defined as digits having at least a common vertex
387 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
388 // which is compared to a digit (d2) not yet in a cluster
390 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
395 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
398 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
400 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
401 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
402 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
404 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
405 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
409 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
410 rv = 2; // Difference in row numbers is too large to look further
416 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
425 //____________________________________________________________________________
426 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
428 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
431 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
433 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
435 if(digit->GetId() <= nEMC ) rv = kTRUE;
440 //____________________________________________________________________________
441 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
443 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
446 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
448 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
450 if(digit->GetId() > nEMC ) rv = kTRUE;
455 //____________________________________________________________________________
456 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
459 // Creates new branches with given title
460 // fills and writes into TreeR.
463 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
464 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
465 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
466 TClonesArray * digits = gime->Digits() ;
473 TString name("TreeR") ;
475 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
478 treeR = gAlice->TreeR();
482 gAlice->MakeTree("R", fSplitFile);
483 treeR = gAlice->TreeR() ;
487 //Evaluate position, dispersion and other RecPoint properties...
488 for(index = 0; index < emcRecPoints->GetEntries(); index++)
489 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ;
491 emcRecPoints->Sort() ;
492 for(index = 0; index < emcRecPoints->GetEntries(); index++)
493 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
495 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
497 //Now the same for CPV
498 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
499 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ;
501 cpvRecPoints->Sort() ;
503 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
504 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
506 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
508 Int_t bufferSize = 32000 ;
509 Int_t splitlevel = 0 ;
512 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
513 emcBranch->SetTitle(BranchName());
516 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
517 cpvBranch->SetTitle(BranchName());
519 //And Finally clusterizer branch
520 AliPHOSClusterizerv1 * cl = this ;
521 TBranch * clusterizerBranch = treeR->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1",
522 &cl,bufferSize,splitlevel);
523 clusterizerBranch->SetTitle(BranchName());
527 clusterizerBranch->Fill() ;
530 if(gAlice->TreeR()!=treeR)
534 //____________________________________________________________________________
535 void AliPHOSClusterizerv1::MakeClusters()
537 // Steering method to construct the clusters stored in a list of Reconstructed Points
538 // A cluster is defined as a list of neighbour digits
540 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
542 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
543 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
544 emcRecPoints->Delete() ;
545 cpvRecPoints->Delete() ;
547 TClonesArray * digits = gime->Digits() ;
549 cerr << "ERROR: AliPHOSClusterizerv1::MakeClusters -> Digits with name "
550 << GetName() << " not found ! " << endl ;
553 TClonesArray * digitsC = (TClonesArray*)digits->Clone() ;
556 // Clusterization starts
558 TIter nextdigit(digitsC) ;
559 AliPHOSDigit * digit ;
560 Bool_t notremoved = kTRUE ;
562 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC
563 AliPHOSRecPoint * clu = 0 ;
565 TArrayI clusterdigitslist(1500) ;
568 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
569 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
571 Int_t iDigitInCluster = 0 ;
573 if ( IsInEmc(digit) ) {
574 // start a new EMC RecPoint
575 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
576 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
578 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
579 clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ;
580 fNumberOfEmcClusters++ ;
581 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
582 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
584 digitsC->Remove(digit) ;
588 // start a new CPV cluster
589 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
590 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
592 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
594 clu = (AliPHOSCpvRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters) ;
595 fNumberOfCpvClusters++ ;
596 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
597 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
599 digitsC->Remove(digit) ;
602 // Here we remove remaining EMC digits, which cannot make a cluster
605 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
607 digitsC->Remove(digit) ;
611 notremoved = kFALSE ;
618 AliPHOSDigit * digitN ;
620 while (index < iDigitInCluster){ // scan over digits already in cluster
621 digit = (AliPHOSDigit*)digits->At(clusterdigitslist[index]) ;
623 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
624 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
626 case 0 : // not a neighbour
628 case 1 : // are neighbours
629 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
630 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
632 digitsC->Remove(digitN) ;
634 case 2 : // too far from each other
643 } // loop over cluster
654 //____________________________________________________________________________
655 void AliPHOSClusterizerv1::MakeUnfolding()
657 // Unfolds clusters using the shape of an ElectroMagnetic shower
658 // Performs unfolding of all EMC/CPV clusters
660 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
663 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
664 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
665 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
666 TClonesArray * digits = gime->Digits() ;
668 // Unfold first EMC clusters
669 if(fNumberOfEmcClusters > 0){
671 Int_t nModulesToUnfold = geom->GetNModules() ;
673 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
675 for(index = 0 ; index < numberofNotUnfolded ; index++){
677 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
678 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
681 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
682 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
683 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
684 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
686 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
687 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
688 emcRecPoints->Remove(emcRecPoint);
689 emcRecPoints->Compress() ;
691 fNumberOfEmcClusters -- ;
692 numberofNotUnfolded-- ;
696 delete[] maxAtEnergy ;
699 // Unfolding of EMC clusters finished
702 // Unfold now CPV clusters
703 if(fNumberOfCpvClusters > 0){
705 Int_t nModulesToUnfold = geom->GetNModules() ;
707 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
709 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
711 AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
713 if(recPoint->GetPHOSMod()> nModulesToUnfold)
716 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ;
718 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
719 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
720 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
721 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
723 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
724 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
725 cpvRecPoints->Remove(emcRecPoint);
726 cpvRecPoints->Compress() ;
728 numberofCpvNotUnfolded-- ;
729 fNumberOfCpvClusters-- ;
733 delete[] maxAtEnergy ;
736 //Unfolding of Cpv clusters finished
740 //____________________________________________________________________________
741 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
743 // Shape of the shower (see PHOS TDR)
744 // If you change this function, change also the gradient evaluation in ChiSquare()
746 Double_t r4 = r*r*r*r ;
747 Double_t r295 = TMath::Power(r, 2.95) ;
748 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
752 //____________________________________________________________________________
753 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
755 AliPHOSDigit ** maxAt,
756 Float_t * maxAtEnergy)
758 // Performs the unfolding of a cluster with nMax overlapping showers
760 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
762 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
763 const TClonesArray * digits = gime->Digits() ;
764 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
765 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
767 Int_t nPar = 3 * nMax ;
768 Float_t * fitparameters = new Float_t[nPar] ;
770 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
772 // Fit failed, return and remove cluster
773 delete[] fitparameters ;
777 // create ufolded rec points and fill them with new energy lists
778 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
779 // and later correct this number in acordance with actual energy deposition
781 Int_t nDigits = iniEmc->GetMultiplicity() ;
782 Float_t * efit = new Float_t[nDigits] ;
783 Float_t xDigit=0.,zDigit=0.,distance=0. ;
784 Float_t xpar=0.,zpar=0.,epar=0. ;
786 AliPHOSDigit * digit = 0 ;
787 Int_t * emcDigits = iniEmc->GetDigitsList() ;
791 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
792 digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;
793 geom->AbsToRelNumbering(digit->GetId(), relid) ;
794 geom->RelPosInModule(relid, xDigit, zDigit) ;
798 while(iparam < nPar ){
799 xpar = fitparameters[iparam] ;
800 zpar = fitparameters[iparam+1] ;
801 epar = fitparameters[iparam+2] ;
803 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
804 distance = TMath::Sqrt(distance) ;
805 efit[iDigit] += epar * ShowerShape(distance) ;
810 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
811 // so that energy deposited in each cell is distributed betwin new clusters proportionally
812 // to its contribution to efit
814 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
818 while(iparam < nPar ){
819 xpar = fitparameters[iparam] ;
820 zpar = fitparameters[iparam+1] ;
821 epar = fitparameters[iparam+2] ;
824 AliPHOSEmcRecPoint * emcRP = 0 ;
826 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
828 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
829 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
831 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
832 emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
833 fNumberOfEmcClusters++ ;
835 else{//create new entries in fCpvRecPoints
836 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
837 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
839 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
840 emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
841 fNumberOfCpvClusters++ ;
845 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
846 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
847 geom->AbsToRelNumbering(digit->GetId(), relid) ;
848 geom->RelPosInModule(relid, xDigit, zDigit) ;
849 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
850 distance = TMath::Sqrt(distance) ;
851 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
852 eDigit = emcEnergies[iDigit] * ratio ;
853 emcRP->AddDigit( *digit, eDigit ) ;
857 delete[] fitparameters ;
862 //_____________________________________________________________________________
863 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
865 // Calculates the Chi square for the cluster unfolding minimization
866 // Number of parameters, Gradient, Chi squared, parameters, what to do
868 TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
870 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ;
871 TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ;
875 // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
877 Int_t * emcDigits = emcRP->GetDigitsList() ;
879 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
881 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
883 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
888 for(iparam = 0 ; iparam < nPar ; iparam++)
889 Grad[iparam] = 0 ; // Will evaluate gradient
893 AliPHOSDigit * digit ;
896 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
898 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
904 geom->AbsToRelNumbering(digit->GetId(), relid) ;
906 geom->RelPosInModule(relid, xDigit, zDigit) ;
908 if(iflag == 2){ // calculate gradient
911 while(iParam < nPar ){
912 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
914 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
915 distance = TMath::Sqrt( distance ) ;
917 efit += x[iParam] * ShowerShape(distance) ;
920 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
922 while(iParam < nPar ){
923 Double_t xpar = x[iParam] ;
924 Double_t zpar = x[iParam+1] ;
925 Double_t epar = x[iParam+2] ;
926 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
927 Double_t shape = sum * ShowerShape(dr) ;
928 Double_t r4 = dr*dr*dr*dr ;
929 Double_t r295 = TMath::Power(dr,2.95) ;
930 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
931 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
933 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
935 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
937 Grad[iParam] += shape ; // Derivative over energy
944 while(iparam < nPar ){
945 Double_t xpar = x[iparam] ;
946 Double_t zpar = x[iparam+1] ;
947 Double_t epar = x[iparam+2] ;
949 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
950 distance = TMath::Sqrt(distance) ;
951 efit += epar * ShowerShape(distance) ;
954 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
955 // Here we assume, that sigma = sqrt(E)
960 //____________________________________________________________________________
961 void AliPHOSClusterizerv1::Print(Option_t * option)const
963 // Print clusterizer parameters
965 if( strcmp(GetName(), "") !=0 ){
969 TString taskName(GetName()) ;
970 taskName.ReplaceAll(Version(), "") ;
972 cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl
973 << "Clusterizing digits from the file: " << taskName.Data() << endl
974 << " Branch: " << GetName() << endl
976 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
977 << " EMC Local Maximum cut = " << fEmcLocMaxCut << endl
978 << " EMC Logarothmic weight = " << fW0 << endl
980 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
981 << " CPV Local Maximum cut = " << fCpvLocMaxCut << endl
982 << " CPV Logarothmic weight = " << fW0CPV << endl
985 cout << " Unfolding on " << endl ;
987 cout << " Unfolding off " << endl ;
989 cout << "------------------------------------------------------------------" <<endl ;
992 cout << " AliPHOSClusterizerv1 not initialized " << endl ;
994 //____________________________________________________________________________
995 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
997 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
999 TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints(BranchName()) ;
1000 TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints(BranchName()) ;
1002 cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ;
1003 cout << " Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and "
1004 << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
1006 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1007 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1009 if(strstr(option,"all")) {
1010 cout << "EMC clusters " << endl ;
1011 cout << " Index Ene(MeV) Multi Module X Y Z Lambda 1 Lambda 2 # of prim Primaries list " << endl;
1014 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1015 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1017 rp->GetLocalPosition(locpos);
1019 rp->GetElipsAxis(lambda);
1022 primaries = rp->GetPrimaries(nprimaries);
1024 cout << setw(4) << rp->GetIndexInList() << " "
1025 << setw(7) << setprecision(3) << rp->GetEnergy() << " "
1026 << setw(3) << rp->GetMultiplicity() << " "
1027 << setw(1) << rp->GetPHOSMod() << " "
1028 << setw(6) << setprecision(2) << locpos.X() << " "
1029 << setw(6) << setprecision(2) << locpos.Y() << " "
1030 << setw(6) << setprecision(2) << locpos.Z() << " "
1031 << setw(4) << setprecision(2) << lambda[0] << " "
1032 << setw(4) << setprecision(2) << lambda[1] << " "
1033 << setw(2) << nprimaries << " " ;
1035 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1036 cout << setw(4) << primaries[iprimary] << " " ;
1040 //Now plot CPV recPoints
1041 cout << "EMC clusters " << endl ;
1049 << " Primaries list " << endl;
1051 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1052 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
1053 cout << setw(6) << rp->GetIndexInList() << " ";
1054 cout << setw(6) << rp->GetPHOSMod() << " CPV ";
1057 rp->GetLocalPosition(locpos);
1058 cout << setw(6) << locpos.X() << " ";
1059 cout << setw(6) << locpos.Y() << " ";
1060 cout << setw(6) << locpos.Z() << " ";
1064 primaries = rp->GetPrimaries(nprimaries);
1065 cout << setw(6) << nprimaries << " ";
1067 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1068 cout << setw(4) << primaries[iprimary] << " ";
1073 cout << "-----------------------------------------------------------------------"<<endl ;