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
105 fDefaultInit = kFALSE ;
109 //____________________________________________________________________________
110 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
115 // if (!fDefaultInit) {
116 // AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
118 // // remove the task from the folder list
119 // gime->RemoveTask("C",GetName()) ;
121 // // remove the data from the folder list
122 // TString name(GetName()) ;
123 // name.Remove(name.Index(":")) ;
124 // gime->RemoveObjects("D", name) ; // Digits
125 // gime->RemoveObjects("RE", name) ; // EMCARecPoints
126 // gime->RemoveObjects("RC", name) ; // CPVRecPoints
129 // gime->CloseFile() ;
135 //____________________________________________________________________________
136 const TString AliPHOSClusterizerv1::BranchName() const
138 TString branchName(GetName() ) ;
139 branchName.Remove(branchName.Index(Version())-1) ;
143 //____________________________________________________________________________
144 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
145 { //To be replased later by the method, reading individual parameters from the database
146 if(absId <= fEmcCrystals) //calibrate as EMC
147 return fADCpedestalEmc + amp*fADCchanelEmc ;
148 else //Digitize as CPV
149 return fADCpedestalCpv+ amp*fADCchanelCpv ;
151 //____________________________________________________________________________
152 void AliPHOSClusterizerv1::Exec(Option_t * option)
156 if( strcmp(GetName(), "")== 0 )
159 if(strstr(option,"tim"))
160 gBenchmark->Start("PHOSClusterizer");
162 if(strstr(option,"print"))
165 // gAlice->GetEvent(0) ;
167 // //check, if the branch with name of this" already exits?
168 // if(gAlice->TreeR()) {
169 // TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
171 // TBranch * branch = 0 ;
172 // Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ;
174 // TString branchname = GetName() ;
175 // branchname.Remove(branchname.Index(Version())-1) ;
177 // while ( (branch = (TBranch*)next()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) {
178 // if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
179 // phosemcfound = kTRUE ;
181 // else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
182 // phoscpvfound = kTRUE ;
184 // else if ((strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
185 // clusterizerfound = kTRUE ;
188 // if ( phoscpvfound || phosemcfound || clusterizerfound ) {
189 // cerr << "WARNING: AliPHOSClusterizer::Exec -> Emc(Cpv)RecPoints and/or Clusterizer branch with name "
190 // << branchname.Data() << " already exits" << endl ;
195 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
196 if(gime->BranchExists("RecPoints"))
198 Int_t nevents = gime->MaxEvent() ;
201 for(ievent = 0; ievent < nevents; ievent++){
203 gime->Event(ievent,"D") ;
206 GetCalibrationParameters() ;
208 fNumberOfEmcClusters = 0 ;
209 fNumberOfCpvClusters = 0 ;
212 // if(!ReadDigits(ievent)) continue; //reads digits for event ievent
219 WriteRecPoints(ievent) ;
221 if(strstr(option,"deb"))
222 PrintRecPoints(option) ;
224 //increment the total number of digits per run
225 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
226 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
229 if(strstr(option,"tim")){
230 gBenchmark->Stop("PHOSClusterizer");
231 cout << "AliPHOSClusterizer:" << endl ;
232 cout << " took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing "
233 << gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
239 //____________________________________________________________________________
240 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
241 Int_t nPar, Float_t * fitparameters) const
243 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
244 // The initial values for fitting procedure are set equal to the positions of local maxima.
245 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
247 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
248 TClonesArray * digits = gime->Digits() ;
251 gMinuit->mncler(); // Reset Minuit's list of paramters
252 gMinuit->SetPrintLevel(-1) ; // No Printout
253 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
254 // To set the address of the minimization function
256 TList * toMinuit = new TList();
257 toMinuit->AddAt(emcRP,0) ;
258 toMinuit->AddAt(digits,1) ;
260 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
262 // filling initial values for fit parameters
263 AliPHOSDigit * digit ;
267 Int_t nDigits = (Int_t) nPar / 3 ;
271 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
273 for(iDigit = 0; iDigit < nDigits; iDigit++){
274 digit = maxAt[iDigit];
279 geom->AbsToRelNumbering(digit->GetId(), relid) ;
280 geom->RelPosInModule(relid, x, z) ;
282 Float_t energy = maxAtEnergy[iDigit] ;
284 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
287 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
290 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
293 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
296 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
299 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
304 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
309 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
310 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
311 gMinuit->SetMaxIterations(5);
312 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
314 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
316 if(ierflg == 4){ // Minimum not found
317 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
320 for(index = 0; index < nPar; index++){
323 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
324 fitparameters[index] = val ;
332 //____________________________________________________________________________
333 void AliPHOSClusterizerv1::GetCalibrationParameters()
335 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
336 const AliPHOSDigitizer * dig = gime->Digitizer(BranchName()) ;
338 fADCchanelEmc = dig->GetEMCchannel() ;
339 fADCpedestalEmc = dig->GetEMCpedestal();
341 fADCchanelCpv = dig->GetCPVchannel() ;
342 fADCpedestalCpv = dig->GetCPVpedestal() ;
345 //____________________________________________________________________________
346 void AliPHOSClusterizerv1::Init()
348 // Make all memory allocations which can not be done in default constructor.
349 // Attach the Clusterizer task to the list of PHOS tasks
351 if ( strcmp(GetTitle(), "") == 0 )
352 SetTitle("galice.root") ;
354 TString branchname = GetName() ;
355 branchname.Remove(branchname.Index(Version())-1) ;
357 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(),branchname.Data(), fToSplit ) ;
359 cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ;
365 // construct the name of the file as /path/EMCAL.SDigits.root
366 //First - extract full path if necessary
367 TString fileName(GetTitle()) ;
368 Ssiz_t islash = fileName.Last('/') ;
369 if(islash<fileName.Length())
370 fileName.Remove(islash+1,fileName.Length()) ;
373 // Next - append the file name
374 fileName+="PHOS.RecData." ;
375 if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
376 fileName+=branchname ;
380 // Finally - check if the file already opened or open the file
381 fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));
383 fSplitFile = TFile::Open(fileName.Data(),"update") ;
388 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
389 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
392 gMinuit = new TMinuit(100) ;
394 gime->PostClusterizer(this) ;
395 gime->PostRecPoints(branchname) ;
397 // gime->PostDigits() ;
398 // gime->PostDigitizer() ;
402 //____________________________________________________________________________
403 void AliPHOSClusterizerv1::InitParameters()
406 fNumberOfCpvClusters = 0 ;
407 fNumberOfEmcClusters = 0 ;
409 fCpvClusteringThreshold = 0.0;
410 fEmcClusteringThreshold = 0.2;
412 fEmcLocMaxCut = 0.03 ;
413 fCpvLocMaxCut = 0.03 ;
418 fEmcTimeGate = 1.e-8 ;
422 // fHeaderFileName = GetTitle() ;
423 // fDigitsBranchTitle = GetName() ;
425 TString clusterizerName( GetName()) ;
426 if (clusterizerName.IsNull() )
427 clusterizerName = "Default" ;
428 clusterizerName.Append(":") ;
429 clusterizerName.Append(Version()) ;
430 SetName(clusterizerName) ;
431 fRecPointsInRun = 0 ;
435 //____________________________________________________________________________
436 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
438 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
440 // = 2 are not neighbour but do not continue searching
441 // neighbours are defined as digits having at least a common vertex
442 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
443 // which is compared to a digit (d2) not yet in a cluster
445 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
450 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
453 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
455 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
456 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
457 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
459 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
460 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
464 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
465 rv = 2; // Difference in row numbers is too large to look further
471 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
480 //____________________________________________________________________________
481 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
483 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
486 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
488 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
490 if(digit->GetId() <= nEMC ) rv = kTRUE;
495 //____________________________________________________________________________
496 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
498 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
501 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
503 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
505 if(digit->GetId() > nEMC ) rv = kTRUE;
510 //____________________________________________________________________________
511 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
514 // Creates new branches with given title
515 // fills and writes into TreeR.
518 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
519 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
520 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
521 TClonesArray * digits = gime->Digits() ;
528 TString name("TreeR") ;
530 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
533 treeR = gAlice->TreeR();
537 gAlice->MakeTree("R", fSplitFile);
538 treeR = gAlice->TreeR() ;
542 //Evaluate position, dispersion and other RecPoint properties...
543 for(index = 0; index < emcRecPoints->GetEntries(); index++)
544 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ;
546 emcRecPoints->Sort() ;
547 for(index = 0; index < emcRecPoints->GetEntries(); index++)
548 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
550 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
552 //Now the same for CPV
553 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
554 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ;
556 cpvRecPoints->Sort() ;
558 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
559 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
561 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
563 Int_t bufferSize = 32000 ;
564 Int_t splitlevel = 0 ;
567 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
568 emcBranch->SetTitle(BranchName());
571 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
572 cpvBranch->SetTitle(BranchName());
574 //And Finally clusterizer branch
575 AliPHOSClusterizerv1 * cl = this ;
576 TBranch * clusterizerBranch = treeR->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1",
577 &cl,bufferSize,splitlevel);
578 clusterizerBranch->SetTitle(BranchName());
582 clusterizerBranch->Fill() ;
584 treeR->AutoSave() ; //Write(0,kOverwrite) ;
585 if(gAlice->TreeR()!=treeR)
589 //____________________________________________________________________________
590 void AliPHOSClusterizerv1::MakeClusters()
592 // Steering method to construct the clusters stored in a list of Reconstructed Points
593 // A cluster is defined as a list of neighbour digits
595 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
597 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
598 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
599 emcRecPoints->Delete() ;
600 cpvRecPoints->Delete() ;
602 TClonesArray * digits = gime->Digits() ;
604 cerr << "ERROR: AliPHOSClusterizerv1::MakeClusters -> Digits with name "
605 << GetName() << " not found ! " << endl ;
608 TClonesArray * digitsC = (TClonesArray*)digits->Clone() ;
611 // Clusterization starts
613 TIter nextdigit(digitsC) ;
614 AliPHOSDigit * digit ;
615 Bool_t notremoved = kTRUE ;
617 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC
618 AliPHOSRecPoint * clu = 0 ;
620 TArrayI clusterdigitslist(1500) ;
623 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
624 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
626 Int_t iDigitInCluster = 0 ;
628 if ( IsInEmc(digit) ) {
629 // start a new EMC RecPoint
630 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
631 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
633 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
634 clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ;
635 fNumberOfEmcClusters++ ;
636 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
637 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
639 digitsC->Remove(digit) ;
643 // start a new CPV cluster
644 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
645 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
647 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
649 clu = (AliPHOSCpvRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters) ;
650 fNumberOfCpvClusters++ ;
651 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
652 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
654 digitsC->Remove(digit) ;
657 // Here we remove remaining EMC digits, which cannot make a cluster
660 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
662 digitsC->Remove(digit) ;
666 notremoved = kFALSE ;
673 AliPHOSDigit * digitN ;
675 while (index < iDigitInCluster){ // scan over digits already in cluster
676 digit = (AliPHOSDigit*)digits->At(clusterdigitslist[index]) ;
678 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
679 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
681 case 0 : // not a neighbour
683 case 1 : // are neighbours
684 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
685 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
687 digitsC->Remove(digitN) ;
689 case 2 : // too far from each other
698 } // loop over cluster
709 //____________________________________________________________________________
710 void AliPHOSClusterizerv1::MakeUnfolding()
712 // Unfolds clusters using the shape of an ElectroMagnetic shower
713 // Performs unfolding of all EMC/CPV clusters
715 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
718 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
719 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
720 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
721 TClonesArray * digits = gime->Digits() ;
723 // Unfold first EMC clusters
724 if(fNumberOfEmcClusters > 0){
726 Int_t nModulesToUnfold = geom->GetNModules() ;
728 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
730 for(index = 0 ; index < numberofNotUnfolded ; index++){
732 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
733 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
736 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
737 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
738 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
739 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
741 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
742 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
743 emcRecPoints->Remove(emcRecPoint);
744 emcRecPoints->Compress() ;
746 fNumberOfEmcClusters -- ;
747 numberofNotUnfolded-- ;
751 delete[] maxAtEnergy ;
754 // Unfolding of EMC clusters finished
757 // Unfold now CPV clusters
758 if(fNumberOfCpvClusters > 0){
760 Int_t nModulesToUnfold = geom->GetNModules() ;
762 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
764 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
766 AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
768 if(recPoint->GetPHOSMod()> nModulesToUnfold)
771 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ;
773 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
774 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
775 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
776 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
778 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
779 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
780 cpvRecPoints->Remove(emcRecPoint);
781 cpvRecPoints->Compress() ;
783 numberofCpvNotUnfolded-- ;
784 fNumberOfCpvClusters-- ;
788 delete[] maxAtEnergy ;
791 //Unfolding of Cpv clusters finished
795 //____________________________________________________________________________
796 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
798 // Shape of the shower (see PHOS TDR)
799 // If you change this function, change also the gradient evaluation in ChiSquare()
801 Double_t r4 = r*r*r*r ;
802 Double_t r295 = TMath::Power(r, 2.95) ;
803 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
807 //____________________________________________________________________________
808 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
810 AliPHOSDigit ** maxAt,
811 Float_t * maxAtEnergy)
813 // Performs the unfolding of a cluster with nMax overlapping showers
815 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
817 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
818 const TClonesArray * digits = gime->Digits() ;
819 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
820 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
822 Int_t nPar = 3 * nMax ;
823 Float_t * fitparameters = new Float_t[nPar] ;
825 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
827 // Fit failed, return and remove cluster
828 delete[] fitparameters ;
832 // create ufolded rec points and fill them with new energy lists
833 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
834 // and later correct this number in acordance with actual energy deposition
836 Int_t nDigits = iniEmc->GetMultiplicity() ;
837 Float_t * efit = new Float_t[nDigits] ;
838 Float_t xDigit=0.,zDigit=0.,distance=0. ;
839 Float_t xpar=0.,zpar=0.,epar=0. ;
841 AliPHOSDigit * digit = 0 ;
842 Int_t * emcDigits = iniEmc->GetDigitsList() ;
846 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
847 digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;
848 geom->AbsToRelNumbering(digit->GetId(), relid) ;
849 geom->RelPosInModule(relid, xDigit, zDigit) ;
853 while(iparam < nPar ){
854 xpar = fitparameters[iparam] ;
855 zpar = fitparameters[iparam+1] ;
856 epar = fitparameters[iparam+2] ;
858 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
859 distance = TMath::Sqrt(distance) ;
860 efit[iDigit] += epar * ShowerShape(distance) ;
865 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
866 // so that energy deposited in each cell is distributed betwin new clusters proportionally
867 // to its contribution to efit
869 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
873 while(iparam < nPar ){
874 xpar = fitparameters[iparam] ;
875 zpar = fitparameters[iparam+1] ;
876 epar = fitparameters[iparam+2] ;
879 AliPHOSEmcRecPoint * emcRP = 0 ;
881 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
883 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
884 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
886 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
887 emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
888 fNumberOfEmcClusters++ ;
890 else{//create new entries in fCpvRecPoints
891 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
892 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
894 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
895 emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
896 fNumberOfCpvClusters++ ;
900 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
901 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
902 geom->AbsToRelNumbering(digit->GetId(), relid) ;
903 geom->RelPosInModule(relid, xDigit, zDigit) ;
904 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
905 distance = TMath::Sqrt(distance) ;
906 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
907 eDigit = emcEnergies[iDigit] * ratio ;
908 emcRP->AddDigit( *digit, eDigit ) ;
912 delete[] fitparameters ;
917 //_____________________________________________________________________________
918 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
920 // Calculates the Chi square for the cluster unfolding minimization
921 // Number of parameters, Gradient, Chi squared, parameters, what to do
923 TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
925 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ;
926 TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ;
930 // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
932 Int_t * emcDigits = emcRP->GetDigitsList() ;
934 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
936 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
938 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
943 for(iparam = 0 ; iparam < nPar ; iparam++)
944 Grad[iparam] = 0 ; // Will evaluate gradient
948 AliPHOSDigit * digit ;
951 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
953 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
959 geom->AbsToRelNumbering(digit->GetId(), relid) ;
961 geom->RelPosInModule(relid, xDigit, zDigit) ;
963 if(iflag == 2){ // calculate gradient
966 while(iParam < nPar ){
967 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
969 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
970 distance = TMath::Sqrt( distance ) ;
972 efit += x[iParam] * ShowerShape(distance) ;
975 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
977 while(iParam < nPar ){
978 Double_t xpar = x[iParam] ;
979 Double_t zpar = x[iParam+1] ;
980 Double_t epar = x[iParam+2] ;
981 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
982 Double_t shape = sum * ShowerShape(dr) ;
983 Double_t r4 = dr*dr*dr*dr ;
984 Double_t r295 = TMath::Power(dr,2.95) ;
985 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
986 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
988 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
990 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
992 Grad[iParam] += shape ; // Derivative over energy
999 while(iparam < nPar ){
1000 Double_t xpar = x[iparam] ;
1001 Double_t zpar = x[iparam+1] ;
1002 Double_t epar = x[iparam+2] ;
1004 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
1005 distance = TMath::Sqrt(distance) ;
1006 efit += epar * ShowerShape(distance) ;
1009 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
1010 // Here we assume, that sigma = sqrt(E)
1015 //____________________________________________________________________________
1016 void AliPHOSClusterizerv1::Print(Option_t * option)const
1018 // Print clusterizer parameters
1020 if( strcmp(GetName(), "") !=0 ){
1024 TString taskName(GetName()) ;
1025 taskName.ReplaceAll(Version(), "") ;
1027 cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl
1028 << "Clusterizing digits from the file: " << taskName.Data() << endl
1029 << " Branch: " << GetName() << endl
1031 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
1032 << " EMC Local Maximum cut = " << fEmcLocMaxCut << endl
1033 << " EMC Logarothmic weight = " << fW0 << endl
1035 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
1036 << " CPV Local Maximum cut = " << fCpvLocMaxCut << endl
1037 << " CPV Logarothmic weight = " << fW0CPV << endl
1040 cout << " Unfolding on " << endl ;
1042 cout << " Unfolding off " << endl ;
1044 cout << "------------------------------------------------------------------" <<endl ;
1047 cout << " AliPHOSClusterizerv1 not initialized " << endl ;
1049 //____________________________________________________________________________
1050 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1052 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1054 TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints(BranchName()) ;
1055 TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints(BranchName()) ;
1057 cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ;
1058 cout << " Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and "
1059 << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
1061 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1062 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1064 if(strstr(option,"all")) {
1065 cout << "EMC clusters " << endl ;
1066 cout << " Index Ene(MeV) Multi Module X Y Z Lambda 1 Lambda 2 # of prim Primaries list " << endl;
1069 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1070 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1072 rp->GetLocalPosition(locpos);
1074 rp->GetElipsAxis(lambda);
1077 primaries = rp->GetPrimaries(nprimaries);
1079 cout << setw(4) << rp->GetIndexInList() << " "
1080 << setw(7) << setprecision(3) << rp->GetEnergy() << " "
1081 << setw(3) << rp->GetMultiplicity() << " "
1082 << setw(1) << rp->GetPHOSMod() << " "
1083 << setw(6) << setprecision(2) << locpos.X() << " "
1084 << setw(6) << setprecision(2) << locpos.Y() << " "
1085 << setw(6) << setprecision(2) << locpos.Z() << " "
1086 << setw(4) << setprecision(2) << lambda[0] << " "
1087 << setw(4) << setprecision(2) << lambda[1] << " "
1088 << setw(2) << nprimaries << " " ;
1090 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1091 cout << setw(4) << primaries[iprimary] << " " ;
1095 //Now plot CPV recPoints
1096 cout << "EMC clusters " << endl ;
1104 << " Primaries list " << endl;
1106 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1107 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
1108 cout << setw(6) << rp->GetIndexInList() << " ";
1109 cout << setw(6) << rp->GetPHOSMod() << " CPV ";
1112 rp->GetLocalPosition(locpos);
1113 cout << setw(6) << locpos.X() << " ";
1114 cout << setw(6) << locpos.Y() << " ";
1115 cout << setw(6) << locpos.Z() << " ";
1119 primaries = rp->GetPrimaries(nprimaries);
1120 cout << setw(6) << nprimaries << " ";
1122 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1123 cout << setw(4) << primaries[iprimary] << " ";
1128 cout << "-----------------------------------------------------------------------"<<endl ;