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 ---
71 // --- AliRoot header files ---
72 #include "AliPHOSClusterizerv1.h"
73 #include "AliPHOSCpvRecPoint.h"
74 #include "AliPHOSDigit.h"
75 #include "AliPHOSDigitizer.h"
76 #include "AliPHOSEmcRecPoint.h"
78 #include "AliPHOSGetter.h"
80 #include "AliPHOSCalibrManager.h"
81 #include "AliPHOSCalibrationData.h"
83 ClassImp(AliPHOSClusterizerv1)
85 //____________________________________________________________________________
86 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
88 // default ctor (to be used mainly by Streamer)
91 fDefaultInit = kTRUE ;
94 //____________________________________________________________________________
95 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* name, const Bool_t toSplit)
96 :AliPHOSClusterizer(headerFile, name, toSplit)
98 // ctor with the indication of the file where header Tree and digits Tree are stored
102 fDefaultInit = kFALSE ;
106 //____________________________________________________________________________
107 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
127 if(fPedestals || fGains ){ //use calibration data
128 if(!fPedestals || !fGains ){
129 Error("Calibrate","Either Pedestals of Gains not set!") ;
132 Float_t en=(amp - fPedestals->Data(absId))*fGains->Data(absId) ;
139 if(absId <= fEmcCrystals) //calibrate as EMC
140 return fADCpedestalEmc + amp*fADCchanelEmc ;
141 else //calibrate as CPV
142 return fADCpedestalCpv+ amp*fADCchanelCpv ;
146 //____________________________________________________________________________
147 void AliPHOSClusterizerv1::Exec(Option_t * option)
150 if( strcmp(GetName(), "")== 0 )
153 if(strstr(option,"tim"))
154 gBenchmark->Start("PHOSClusterizer");
156 if(strstr(option,"print"))
159 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
160 if(gime->BranchExists("RecPoints"))
163 //test, if this is real data:
164 TBranch * eh = gAlice->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
165 if(eh){ //Read CalibrationData
166 AliPHOSCalibrManager * cmngr=AliPHOSCalibrManager::GetInstance() ;
167 if(!cmngr){ //not defined yet
168 cmngr=AliPHOSCalibrManager::GetInstance("PHOSBTCalibration.root") ;
172 fPedestals = new AliPHOSCalibrationData("Pedestals",fCalibrVersion) ;
173 cmngr->ReadFromRoot(*fPedestals,fCalibrRun) ;
176 fGains = new AliPHOSCalibrationData("Gains",fCalibrVersion) ;
177 cmngr->ReadFromRoot(*fGains,fCalibrRun) ;
180 Int_t nevents = gime->MaxEvent() ;
183 for(ievent = 0; ievent < nevents; ievent++){
184 gime->Event(ievent,"D") ;
185 Int_t pattern = gime->EventPattern() ;
187 printf("pattern %d \n",pattern) ;
189 Error("Exec","Patterns for reconstruction of events are not set, use SetPatterns() ") ;
192 Bool_t skip = kTRUE ;
193 Int_t npat = fPatterns->GetSize() ;
194 for(Int_t i = 0; i<npat;i++)
195 if(pattern==fPatterns->At(i)){
204 GetCalibrationParameters() ;
206 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
213 WriteRecPoints(ievent) ;
215 if(strstr(option,"deb"))
216 PrintRecPoints(option) ;
218 //increment the total number of digits per run
219 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
220 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
223 if(strstr(option,"tim")){
224 gBenchmark->Stop("PHOSClusterizer");
225 Info("Exec", " took %f seconds for Clusterizing %f seconds per event \n",
226 gBenchmark->GetCpuTime("PHOSClusterizer"),
227 gBenchmark->GetCpuTime("PHOSClusterizer")/nevents ) ;
231 //____________________________________________________________________________
232 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
233 Int_t nPar, Float_t * fitparameters) const
235 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
236 // The initial values for fitting procedure are set equal to the positions of local maxima.
237 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
239 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
240 TClonesArray * digits = gime->Digits() ;
243 gMinuit->mncler(); // Reset Minuit's list of paramters
244 gMinuit->SetPrintLevel(-1) ; // No Printout
245 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
246 // To set the address of the minimization function
248 TList * toMinuit = new TList();
249 toMinuit->AddAt(emcRP,0) ;
250 toMinuit->AddAt(digits,1) ;
252 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
254 // filling initial values for fit parameters
255 AliPHOSDigit * digit ;
259 Int_t nDigits = (Int_t) nPar / 3 ;
263 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
265 for(iDigit = 0; iDigit < nDigits; iDigit++){
266 digit = maxAt[iDigit];
271 geom->AbsToRelNumbering(digit->GetId(), relid) ;
272 geom->RelPosInModule(relid, x, z) ;
274 Float_t energy = maxAtEnergy[iDigit] ;
276 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
279 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
282 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
285 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
288 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
291 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
296 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
301 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
302 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
303 gMinuit->SetMaxIterations(5);
304 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
306 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
308 if(ierflg == 4){ // Minimum not found
309 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
312 for(index = 0; index < nPar; index++){
315 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
316 fitparameters[index] = val ;
324 //____________________________________________________________________________
325 void AliPHOSClusterizerv1::GetCalibrationParameters()
327 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
329 const TTask * task = gime->Digitizer(BranchName()) ;
330 if(strcmp(task->IsA()->GetName(),"AliPHOSDigitizer")==0){
331 const AliPHOSDigitizer * dig = static_cast<const AliPHOSDigitizer *>(task) ;
333 fADCchanelEmc = dig->GetEMCchannel() ;
334 fADCpedestalEmc = dig->GetEMCpedestal();
336 fADCchanelCpv = dig->GetCPVchannel() ;
337 fADCpedestalCpv = dig->GetCPVpedestal() ;
341 // fCalibrationDB = gime->CalibrationDB();
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 Error("Init", "Could not obtain the Getter object !") ;
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) ;
399 //____________________________________________________________________________
400 void AliPHOSClusterizerv1::InitParameters()
403 fNumberOfCpvClusters = 0 ;
404 fNumberOfEmcClusters = 0 ;
406 fCpvClusteringThreshold = 0.0;
407 fEmcClusteringThreshold = 0.2;
409 fEmcLocMaxCut = 0.03 ;
410 fCpvLocMaxCut = 0.03 ;
415 fEmcTimeGate = 1.e-8 ;
419 fPurifyThreshold = 0.012 ;
423 fCalibrVersion= "v1" ;
427 TString clusterizerName( GetName()) ;
428 if (clusterizerName.IsNull() )
429 clusterizerName = "Default" ;
430 clusterizerName.Append(":") ;
431 clusterizerName.Append(Version()) ;
432 SetName(clusterizerName) ;
433 fRecPointsInRun = 0 ;
438 //____________________________________________________________________________
439 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
441 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
443 // = 2 are not neighbour but do not continue searching
444 // neighbours are defined as digits having at least a common vertex
445 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
446 // which is compared to a digit (d2) not yet in a cluster
448 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
453 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
456 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
458 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
459 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
460 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
462 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
463 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
467 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
468 rv = 2; // Difference in row numbers is too large to look further
474 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
483 //____________________________________________________________________________
484 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
486 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
489 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
491 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
493 if(digit->GetId() <= nEMC ) rv = kTRUE;
498 //____________________________________________________________________________
499 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
501 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
504 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
506 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
508 if(digit->GetId() > nEMC ) rv = kTRUE;
513 //____________________________________________________________________________
514 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
517 // Creates new branches with given title
518 // fills and writes into TreeR.
521 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
522 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
523 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
524 TClonesArray * digits = gime->Digits() ;
531 TString name("TreeR") ;
533 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
536 treeR = gAlice->TreeR();
541 gAlice->MakeTree("R", fSplitFile);
543 gAlice->MakeTree("R", gROOT->GetFile(GetTitle()));
544 treeR = gAlice->TreeR() ;
548 //Evaluate position, dispersion and other RecPoint properties...
549 for(index = 0; index < emcRecPoints->GetEntries(); index++){
550 AliPHOSEmcRecPoint * emcrp = static_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(index)) ;
551 emcrp->Purify(fPurifyThreshold) ;
552 if(emcrp->GetMultiplicity())
553 emcrp->EvalAll(fW0,digits) ;
555 emcRecPoints->Remove(emcrp) ;
558 emcRecPoints->Compress() ;
559 emcRecPoints->Sort() ;
560 for(index = 0; index < emcRecPoints->GetEntries(); index++)
561 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
563 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
565 //Now the same for CPV
566 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
567 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ;
569 cpvRecPoints->Sort() ;
571 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
572 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
574 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
576 Int_t bufferSize = 32000 ;
577 Int_t splitlevel = 0 ;
580 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
581 emcBranch->SetTitle(BranchName());
584 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
585 cpvBranch->SetTitle(BranchName());
587 //And Finally clusterizer branch
588 AliPHOSClusterizerv1 * cl = this ;
589 TBranch * clusterizerBranch = treeR->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1",
590 &cl,bufferSize,splitlevel);
591 clusterizerBranch->SetTitle(BranchName());
595 clusterizerBranch->Fill() ;
598 if(gAlice->TreeR()!=treeR)
602 //____________________________________________________________________________
603 void AliPHOSClusterizerv1::MakeClusters()
605 // Steering method to construct the clusters stored in a list of Reconstructed Points
606 // A cluster is defined as a list of neighbour digits
608 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
610 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
611 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
612 emcRecPoints->Delete() ;
613 cpvRecPoints->Delete() ;
615 TClonesArray * digits = gime->Digits() ;
617 Fatal("MakeClusters", "Digits with name %s not found !", BranchName().Data() ) ;
619 TClonesArray * digitsC = (TClonesArray*)digits->Clone() ;
622 // Clusterization starts
624 TIter nextdigit(digitsC) ;
625 AliPHOSDigit * digit ;
626 Bool_t notremoved = kTRUE ;
628 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC
629 AliPHOSRecPoint * clu = 0 ;
631 TArrayI clusterdigitslist(1500) ;
633 // cout << "digit " << digit << " " << Calibrate(digit->GetAmp(),digit->GetId()) << endl ;
635 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
636 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
637 Int_t iDigitInCluster = 0 ;
639 if ( IsInEmc(digit) ) {
640 // start a new EMC RecPoint
641 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
642 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
644 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
645 clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ;
646 fNumberOfEmcClusters++ ;
647 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
648 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
650 digitsC->Remove(digit) ;
654 // start a new CPV cluster
655 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
656 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
658 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
660 clu = (AliPHOSCpvRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters) ;
661 fNumberOfCpvClusters++ ;
662 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
663 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
665 digitsC->Remove(digit) ;
668 // Here we remove remaining EMC digits, which cannot make a cluster
671 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
673 digitsC->Remove(digit) ;
677 notremoved = kFALSE ;
684 AliPHOSDigit * digitN ;
686 while (index < iDigitInCluster){ // scan over digits already in cluster
687 digit = (AliPHOSDigit*)digits->At(clusterdigitslist[index]) ;
689 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
690 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
692 case 0 : // not a neighbour
694 case 1 : // are neighbours
695 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
696 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
698 digitsC->Remove(digitN) ;
700 case 2 : // too far from each other
709 } // loop over cluster
720 //____________________________________________________________________________
721 void AliPHOSClusterizerv1::MakeUnfolding()
723 // Unfolds clusters using the shape of an ElectroMagnetic shower
724 // Performs unfolding of all EMC/CPV clusters
726 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
729 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
730 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
731 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
732 TClonesArray * digits = gime->Digits() ;
734 // Unfold first EMC clusters
735 if(fNumberOfEmcClusters > 0){
737 Int_t nModulesToUnfold = geom->GetNModules() ;
739 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
741 for(index = 0 ; index < numberofNotUnfolded ; index++){
743 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
744 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
747 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
748 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
749 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
750 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
752 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
753 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
754 if(emcRecPoint->GetNExMax()!=-1){ //Do not remove clusters which failed to unfold
755 emcRecPoints->Remove(emcRecPoint);
756 emcRecPoints->Compress() ;
758 fNumberOfEmcClusters -- ;
759 numberofNotUnfolded-- ;
763 emcRecPoint->SetNExMax(1) ; //Only one local maximum
766 delete[] maxAtEnergy ;
769 // Unfolding of EMC clusters finished
772 // Unfold now CPV clusters
773 if(fNumberOfCpvClusters > 0){
775 Int_t nModulesToUnfold = geom->GetNModules() ;
777 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
779 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
781 AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
783 if(recPoint->GetPHOSMod()> nModulesToUnfold)
786 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ;
788 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
789 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
790 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
791 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
793 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
794 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
795 cpvRecPoints->Remove(emcRecPoint);
796 cpvRecPoints->Compress() ;
798 numberofCpvNotUnfolded-- ;
799 fNumberOfCpvClusters-- ;
803 delete[] maxAtEnergy ;
806 //Unfolding of Cpv clusters finished
810 //____________________________________________________________________________
811 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
813 // Shape of the shower (see PHOS TDR)
814 // If you change this function, change also the gradient evaluation in ChiSquare()
816 Double_t r4 = r*r*r*r ;
817 Double_t r295 = TMath::Power(r, 2.95) ;
818 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
822 //____________________________________________________________________________
823 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
825 AliPHOSDigit ** maxAt,
826 Float_t * maxAtEnergy)
828 // Performs the unfolding of a cluster with nMax overlapping showers
830 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
832 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
833 const TClonesArray * digits = gime->Digits() ;
834 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
835 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
837 Int_t nPar = 3 * nMax ;
838 Float_t * fitparameters = new Float_t[nPar] ;
840 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
842 // Fit failed, return
843 iniEmc->SetNExMax(-1) ;
844 delete[] fitparameters ;
848 // create ufolded rec points and fill them with new energy lists
849 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
850 // and later correct this number in acordance with actual energy deposition
852 Int_t nDigits = iniEmc->GetMultiplicity() ;
853 Float_t * efit = new Float_t[nDigits] ;
854 Float_t xDigit=0.,zDigit=0.,distance=0. ;
855 Float_t xpar=0.,zpar=0.,epar=0. ;
857 AliPHOSDigit * digit = 0 ;
858 Int_t * emcDigits = iniEmc->GetDigitsList() ;
862 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
863 digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;
864 geom->AbsToRelNumbering(digit->GetId(), relid) ;
865 geom->RelPosInModule(relid, xDigit, zDigit) ;
869 while(iparam < nPar ){
870 xpar = fitparameters[iparam] ;
871 zpar = fitparameters[iparam+1] ;
872 epar = fitparameters[iparam+2] ;
874 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
875 distance = TMath::Sqrt(distance) ;
876 efit[iDigit] += epar * ShowerShape(distance) ;
881 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
882 // so that energy deposited in each cell is distributed betwin new clusters proportionally
883 // to its contribution to efit
885 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
889 while(iparam < nPar ){
890 xpar = fitparameters[iparam] ;
891 zpar = fitparameters[iparam+1] ;
892 epar = fitparameters[iparam+2] ;
895 AliPHOSEmcRecPoint * emcRP = 0 ;
897 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
899 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
900 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
902 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
903 emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
904 fNumberOfEmcClusters++ ;
905 emcRP->SetNExMax((Int_t)nPar/3) ;
907 else{//create new entries in fCpvRecPoints
908 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
909 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
911 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
912 emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
913 fNumberOfCpvClusters++ ;
917 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
918 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
919 geom->AbsToRelNumbering(digit->GetId(), relid) ;
920 geom->RelPosInModule(relid, xDigit, zDigit) ;
921 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
922 distance = TMath::Sqrt(distance) ;
923 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
924 eDigit = emcEnergies[iDigit] * ratio ;
925 emcRP->AddDigit( *digit, eDigit ) ;
929 delete[] fitparameters ;
934 //_____________________________________________________________________________
935 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
937 // Calculates the Chi square for the cluster unfolding minimization
938 // Number of parameters, Gradient, Chi squared, parameters, what to do
940 TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
942 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ;
943 TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ;
947 // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
949 Int_t * emcDigits = emcRP->GetDigitsList() ;
951 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
953 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
955 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
960 for(iparam = 0 ; iparam < nPar ; iparam++)
961 Grad[iparam] = 0 ; // Will evaluate gradient
965 AliPHOSDigit * digit ;
968 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
970 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
976 geom->AbsToRelNumbering(digit->GetId(), relid) ;
978 geom->RelPosInModule(relid, xDigit, zDigit) ;
980 if(iflag == 2){ // calculate gradient
983 while(iParam < nPar ){
984 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
986 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
987 distance = TMath::Sqrt( distance ) ;
989 efit += x[iParam] * ShowerShape(distance) ;
993 if(emcEnergies[iDigit] > 0)
994 sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ;
995 // Here we assume, that sigma = sqrt(E)
997 while(iParam < nPar ){
998 Double_t xpar = x[iParam] ;
999 Double_t zpar = x[iParam+1] ;
1000 Double_t epar = x[iParam+2] ;
1001 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
1002 Double_t shape = sum * ShowerShape(dr) ;
1003 Double_t r4 = dr*dr*dr*dr ;
1004 Double_t r295 = TMath::Power(dr,2.95) ;
1005 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
1006 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
1008 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
1010 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
1012 Grad[iParam] += shape ; // Derivative over energy
1019 while(iparam < nPar ){
1020 Double_t xpar = x[iparam] ;
1021 Double_t zpar = x[iparam+1] ;
1022 Double_t epar = x[iparam+2] ;
1024 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
1025 distance = TMath::Sqrt(distance) ;
1026 efit += epar * ShowerShape(distance) ;
1029 if(emcEnergies[iDigit] > 0) //for the case if rounding error
1030 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/
1031 emcEnergies[iDigit] ;
1032 // Here we assume, that sigma = sqrt(E)
1037 //____________________________________________________________________________
1038 void AliPHOSClusterizerv1::Print(Option_t * option)const
1040 // Print clusterizer parameters
1043 TString taskName(GetName()) ;
1044 taskName.ReplaceAll(Version(), "") ;
1046 if( strcmp(GetName(), "") !=0 ) {
1048 message = "\n--------------- %s %s -----------\n" ;
1049 message += "Clusterizing digits from the file: %s\n" ;
1050 message += " Branch: %s\n" ;
1051 message += " EMC Clustering threshold = %f\n" ;
1052 message += " EMC Local Maximum cut = %f\n" ;
1053 message += " EMC Logarothmic weight = %f\n" ;
1054 message += " CPV Clustering threshold = %f\n" ;
1055 message += " CPV Local Maximum cut = %f\n" ;
1056 message += " CPV Logarothmic weight = %f\n" ;
1058 message += " Unfolding on\n" ;
1060 message += " Unfolding off\n" ;
1062 message += "------------------------------------------------------------------" ;
1065 message = " AliPHOSClusterizerv1 not initialized " ;
1067 Info("Print", message.Data(),
1072 fEmcClusteringThreshold,
1075 fCpvClusteringThreshold,
1081 //____________________________________________________________________________
1082 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1084 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1086 TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints(BranchName()) ;
1087 TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints(BranchName()) ;
1089 if(strstr(option,"deb")){
1090 printf("event %d, found %d EmcRecPoints and %d CPV RecPoints \n",
1091 gAlice->GetEvNumber(),
1092 emcRecPoints->GetEntriesFast(),
1093 cpvRecPoints->GetEntriesFast()) ;
1097 if(strstr(option,"all")) {
1098 printf("\nEMC clusters\n" );
1099 printf("Index Ene(MeV) Multi Module X Y Z Lambda 1 Lambda 2 # of prim Primaries list\n" );
1101 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1102 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1104 rp->GetLocalPosition(locpos);
1106 rp->GetElipsAxis(lambda);
1109 primaries = rp->GetPrimaries(nprimaries);
1110 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
1111 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
1112 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
1114 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
1115 printf("%d ", primaries[iprimary] ) ;
1118 //Now plot CPV recPoints
1119 printf("\n CPV RecPoints \n") ;
1120 printf("Index Ene(MeV) Module X Y Z # of prim Primaries list\n") ;
1121 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1122 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
1125 rp->GetLocalPosition(locpos);
1129 primaries = rp->GetPrimaries(nprimaries);
1130 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f %2d : ",
1131 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
1132 locpos.X(), locpos.Y(), locpos.Z(), nprimaries) ;
1133 primaries = rp->GetPrimaries(nprimaries);
1134 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
1135 printf("%d ", primaries[iprimary] ) ;