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")
41 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
42 // //reads gAlice from header file "..."
43 // root [1] cl->ExecuteTask()
44 // //finds RecPoints in all events stored in galice.root
45 // root [2] cl->SetDigitsBranch("digits2")
46 // //sets another title for Digitis (input) branch
47 // root [3] cl->SetRecPointsBranch("recp2")
48 // //sets another title four output branches
49 // root [4] cl->SetEmcLocalMaxCut(0.03)
50 // //set clusterization parameters
51 // root [5] cl->ExecuteTask("deb all time")
52 // //once more finds RecPoints options are
53 // // deb - print number of found rec points
54 // // deb all - print number of found RecPoints and some their characteristics
55 // // time - print benchmarking results
57 // --- ROOT system ---
66 #include "TBenchmark.h"
68 // --- Standard library ---
73 // --- AliRoot header files ---
75 #include "AliPHOSClusterizerv1.h"
76 #include "AliPHOSCpvRecPoint.h"
77 #include "AliPHOSDigit.h"
78 #include "AliPHOSDigitizer.h"
79 #include "AliPHOSEmcRecPoint.h"
81 #include "AliPHOSPpsdRecPoint.h"
82 #include "AliPHOSGetter.h"
85 ClassImp(AliPHOSClusterizerv1)
87 //____________________________________________________________________________
88 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
90 // default ctor (to be used mainly by Streamer)
92 fNumberOfCpvClusters = 0 ;
93 fNumberOfEmcClusters = 0 ;
95 fCpvClusteringThreshold = 0.0;
96 fEmcClusteringThreshold = 0.2;
97 fPpsdClusteringThreshold = 0.0000002 ;
99 fEmcLocMaxCut = 0.03 ;
100 fCpvLocMaxCut = 0.03 ;
105 fHeaderFileName = "" ;
106 fDigitsBranchTitle = "" ;
110 //____________________________________________________________________________
111 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* name)
112 :AliPHOSClusterizer(headerFile, name)
114 // ctor with the indication of the file where header Tree and digits Tree are stored
117 fNumberOfCpvClusters = 0 ;
118 fNumberOfEmcClusters = 0 ;
120 fCpvClusteringThreshold = 0.0;
121 fEmcClusteringThreshold = 0.2;
122 fPpsdClusteringThreshold = 0.0000002 ;
124 fEmcLocMaxCut = 0.03 ;
125 fCpvLocMaxCut = 0.03 ;
132 fHeaderFileName = GetTitle() ;
133 fDigitsBranchTitle = GetName() ;
135 TString tempo(GetName()) ;
136 tempo.Append(Version()) ;
137 SetName(tempo.Data()) ;
143 //____________________________________________________________________________
144 void AliPHOSClusterizerv1::Exec(Option_t * option)
148 if( strcmp(GetName(), "")== 0 )
151 if(strstr(option,"tim"))
152 gBenchmark->Start("PHOSClusterizerv1");
154 if(strstr(option,"print"))
157 //check, if the branch with name of this" already exits?
158 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
160 TBranch * branch = 0 ;
161 Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ;
163 TString taskName(GetName()) ;
164 taskName.ReplaceAll(Version(), "") ;
166 while ( (branch = (TBranch*)next()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) {
167 if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
168 phosemcfound = kTRUE ;
170 else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
171 phoscpvfound = kTRUE ;
173 else if ( (strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
174 clusterizerfound = kTRUE ;
177 if ( phoscpvfound || phosemcfound || clusterizerfound ) {
178 cerr << "WARNING: AliPHOSClusterizer::Exec -> Emc(Cpv)RecPoints and/or Clusterizer branch with name "
179 << taskName.Data() << " already exits" << endl ;
183 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
186 for(ievent = 0; ievent < nevents; ievent++){
188 if(!ReadDigits(ievent)) //reads digits for event fEvent
196 WriteRecPoints(ievent) ;
198 if(strstr(option,"deb"))
199 PrintRecPoints(option) ;
202 if(strstr(option,"tim")){
203 gBenchmark->Stop("PHOSClusterizer");
204 cout << "AliPHOSClusterizer:" << endl ;
205 cout << " took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing "
206 << gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
212 //____________________________________________________________________________
213 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
214 Int_t nPar, Float_t * fitparameters) const
216 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
217 // The initial values for fitting procedure are set equal to the positions of local maxima.
218 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
220 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
221 TClonesArray * digits = gime->Digits() ;
224 gMinuit->mncler(); // Reset Minuit's list of paramters
225 gMinuit->SetPrintLevel(-1) ; // No Printout
226 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
227 // To set the address of the minimization function
229 TList * toMinuit = new TList();
230 toMinuit->AddAt(emcRP,0) ;
231 toMinuit->AddAt(digits,1) ;
233 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
235 // filling initial values for fit parameters
236 AliPHOSDigit * digit ;
240 Int_t nDigits = (Int_t) nPar / 3 ;
244 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
246 for(iDigit = 0; iDigit < nDigits; iDigit++){
247 digit = (AliPHOSDigit *) maxAt[iDigit];
252 geom->AbsToRelNumbering(digit->GetId(), relid) ;
253 geom->RelPosInModule(relid, x, z) ;
255 Float_t energy = maxAtEnergy[iDigit] ;
257 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
260 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
263 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
266 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
269 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
272 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
277 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
282 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
283 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
284 gMinuit->SetMaxIterations(5);
285 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
287 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
289 if(ierflg == 4){ // Minimum not found
290 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
293 for(index = 0; index < nPar; index++){
296 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
297 fitparameters[index] = val ;
305 //____________________________________________________________________________
306 void AliPHOSClusterizerv1::Init()
308 // Make all memory allocations which can not be done in default constructor.
309 // Attach the Clusterizer task to the list of PHOS tasks
311 if ( strcmp(GetTitle(), "") == 0 )
312 SetTitle("galice.root") ;
314 TString taskName(GetName()) ;
315 taskName.ReplaceAll(Version(), "") ;
317 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), taskName.Data()) ;
319 cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ;
324 gMinuit = new TMinuit(100) ;
326 //add Task to //YSAlice/tasks/Reconstructioner/PHOS
327 TTask * aliceRe = (TTask*)gROOT->FindObjectAny("YSAlice/tasks/Reconstructioner") ;
328 TTask * phosRe = (TTask*)aliceRe->GetListOfTasks()->FindObject("PHOS") ;
330 // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/recpointsName
331 gime->Post(GetTitle(), "R", taskName.Data() ) ;
335 //____________________________________________________________________________
336 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
338 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
340 // = 2 are not neighbour but do not continue searching
341 // neighbours are defined as digits having at least a common vertex
342 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
343 // which is compared to a digit (d2) not yet in a cluster
345 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
350 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
353 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
355 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module and the same PPSD Module
356 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
357 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
359 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
363 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
364 rv = 2; // Difference in row numbers is too large to look further
370 if( (relid1[0] < relid2[0]) || (relid1[1] < relid2[1]) )
375 //Do NOT clusterize upper PPSD
376 if( IsInPpsd(d1) && IsInPpsd(d2) &&
378 relid1[1] < geom->GetNumberOfPadsPhi()*geom->GetNumberOfPadsPhi() ) rv = 2 ;
384 //____________________________________________________________________________
385 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
387 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
390 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
393 geom->AbsToRelNumbering(digit->GetId(), relid) ;
395 if ( relid[1] == 0 ) rv = kTRUE;
400 //____________________________________________________________________________
401 Bool_t AliPHOSClusterizerv1::IsInPpsd(AliPHOSDigit * digit) const
403 // Tells if (true) or not (false) the digit is in a PHOS-PPSD module
406 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
409 geom->AbsToRelNumbering(digit->GetId(), relid) ;
411 if ( relid[1] > 0 && relid[0] > geom->GetNCPVModules() ) rv = kTRUE;
416 //____________________________________________________________________________
417 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
419 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
422 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
425 geom->AbsToRelNumbering(digit->GetId(), relid) ;
427 if ( relid[1] > 0 && relid[0] <= geom->GetNCPVModules() ) rv = kTRUE;
431 //____________________________________________________________________________
432 Bool_t AliPHOSClusterizerv1::ReadDigits(Int_t event)
434 // reads digitis with specified title from TreeD
436 fNumberOfEmcClusters = 0 ;
437 fNumberOfCpvClusters = 0 ;
439 // Get Digits Tree header from file
440 gAlice->GetEvent(event) ;
441 gAlice->SetEvent(event) ;
443 if ( gAlice->TreeD()==0) {
444 cerr << "ERROR: AliPHOSClusterizerv1::ReadDigits There is no Digit Tree" << endl;
448 //set address of the Digits and Digitizer
449 TBranch * digitsBranch = 0;
450 TBranch * digitizerBranch = 0;
451 TObjArray * lob = (TObjArray*)gAlice->TreeD()->GetListOfBranches() ;
453 TBranch * branch = 0 ;
454 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
456 TString taskName(GetName()) ;
457 taskName.ReplaceAll(Version(), "") ;
459 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
460 if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
462 digitsBranch = branch ;
465 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
466 digitizerfound = kTRUE ;
467 digitizerBranch = branch ;
470 if ( !phosfound || !digitizerfound ) {
471 cerr << "WARNING: AliPHOSClusterizerv1::ReadDigits -> Digits and/or Digitizer branch with name " << taskName.Data()
472 << " not found" << endl ;
476 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
478 TClonesArray * digits = gime->Digits() ;
480 digitsBranch->SetAddress(&digits) ;
482 AliPHOSDigitizer * digitizer = gime->Digitizer() ;
483 digitizerBranch->SetAddress(&digitizer) ;
485 digitsBranch->GetEntry(0) ;
486 digitizerBranch->GetEntry(0) ;
488 fPedestal = digitizer->GetPedestal() ;
489 fSlope = digitizer->GetSlope() ;
494 //____________________________________________________________________________
495 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
498 // Creates new branches with given title
499 // fills and writes into TreeR.
501 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
502 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
503 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
504 TClonesArray * digits = gime->Digits() ;
507 //Evaluate poisition, dispersion and other RecPoint properties...
508 for(index = 0; index < emcRecPoints->GetEntries(); index++)
509 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ;
511 emcRecPoints->Sort() ;
513 for(index = 0; index < emcRecPoints->GetEntries(); index++)
514 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
516 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
518 //Now the same for CPV
519 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
520 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ;
522 cpvRecPoints->Sort() ;
524 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
525 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
527 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
529 gAlice->GetEvent(event) ;
530 if(gAlice->TreeR()==0)
531 gAlice->MakeTree("R") ;
533 //Make branches in TreeR for RecPoints and Clusterizer
535 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
536 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
537 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
541 TDirectory *cwd = gDirectory;
543 TString branchName(GetName()) ;
544 branchName.ReplaceAll(Version(), "") ;
547 Int_t bufferSize = 32000 ;
548 Int_t splitlevel = 0 ;
549 TBranch * emcBranch = gAlice->TreeR()->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
550 emcBranch->SetTitle(branchName);
552 emcBranch->SetFile(filename);
553 TIter next( emcBranch->GetListOfBranches());
555 while ((sb=(TBranch*)next())) {
556 sb->SetFile(filename);
563 TBranch * cpvBranch = gAlice->TreeR()->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
564 cpvBranch->SetTitle(branchName);
566 cpvBranch->SetFile(filename);
567 TIter next( cpvBranch->GetListOfBranches());
569 while ((sb=(TBranch*)next())) {
570 sb->SetFile(filename);
575 //And Finally clusterizer branch
576 AliPHOSClusterizerv1 * cl = (AliPHOSClusterizerv1*)gime->Clusterizer(GetName()) ;
577 TBranch * clusterizerBranch = gAlice->TreeR()->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1",
578 &cl,bufferSize,splitlevel);
579 clusterizerBranch->SetTitle(branchName);
581 clusterizerBranch->SetFile(filename);
582 TIter next( clusterizerBranch->GetListOfBranches());
584 while ((sb=(TBranch*)next())) {
585 sb->SetFile(filename);
592 clusterizerBranch->Fill() ;
594 gAlice->TreeR()->Write(0,kOverwrite) ;
598 //____________________________________________________________________________
599 void AliPHOSClusterizerv1::MakeClusters()
601 // Steering method to construct the clusters stored in a list of Reconstructed Points
602 // A cluster is defined as a list of neighbour digits
604 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
606 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
607 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
608 emcRecPoints->Clear() ;
609 cpvRecPoints->Clear() ;
611 TClonesArray * digits = gime->Digits() ;
612 TClonesArray * digitsC = (TClonesArray*)digits->Clone() ;
615 // Clusterization starts
617 TIter nextdigit(digitsC) ;
618 AliPHOSDigit * digit ;
619 Bool_t notremoved = kTRUE ;
621 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC
622 AliPHOSRecPoint * clu = 0 ;
624 TArrayI clusterdigitslist(1500) ;
627 if (( IsInEmc (digit) && Calibrate(digit->GetAmp()) > fEmcClusteringThreshold ) ||
628 ( IsInPpsd(digit) && Calibrate(digit->GetAmp()) > fPpsdClusteringThreshold ) ||
629 ( IsInCpv (digit) && Calibrate(digit->GetAmp()) > fCpvClusteringThreshold ) ) {
631 Int_t iDigitInCluster = 0 ;
633 if ( IsInEmc(digit) ) {
634 // start a new EMC RecPoint
635 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
636 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
638 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(), fNumberOfEmcClusters) ;
639 clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ;
640 fNumberOfEmcClusters++ ;
641 clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ;
642 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
644 digitsC->Remove(digit) ;
648 // start a new PPSD/CPV cluster
649 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
650 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
653 cpvRecPoints->AddAt(new AliPHOSPpsdRecPoint(),fNumberOfCpvClusters) ;
655 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(), fNumberOfCpvClusters) ;
657 clu = (AliPHOSPpsdRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters) ;
658 fNumberOfCpvClusters++ ;
659 clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;
660 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
662 digitsC->Remove(digit) ;
665 // Here we remove remaining EMC digits, which cannot make a cluster
668 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
670 digitsC->Remove(digit) ;
674 notremoved = kFALSE ;
681 AliPHOSDigit * digitN ;
683 while (index < iDigitInCluster){ // scan over digits already in cluster
684 digit = (AliPHOSDigit*)digits->At(clusterdigitslist[index]) ;
686 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
687 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
689 case 0 : // not a neighbour
691 case 1 : // are neighbours
692 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
693 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
695 digitsC->Remove(digitN) ;
697 case 2 : // too far from each other
706 } // loop over cluster
717 //____________________________________________________________________________
718 void AliPHOSClusterizerv1::MakeUnfolding()
720 // Unfolds clusters using the shape of an ElectroMagnetic shower
721 // Performs unfolding of all EMC/CPV but NOT ppsd clusters
723 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
725 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
726 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
727 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
728 TClonesArray * digits = gime->Digits() ;
730 // Unfold first EMC clusters
731 if(fNumberOfEmcClusters > 0){
733 Int_t nModulesToUnfold = geom->GetNModules() ;
735 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
737 for(index = 0 ; index < numberofNotUnfolded ; index++){
739 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
740 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
743 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
744 Int_t * maxAt = new Int_t[nMultipl] ;
745 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
746 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
748 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
749 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
750 emcRecPoints->Remove(emcRecPoint);
751 emcRecPoints->Compress() ;
753 fNumberOfEmcClusters -- ;
754 numberofNotUnfolded-- ;
758 delete[] maxAtEnergy ;
761 // Unfolding of EMC clusters finished
764 // Unfold now CPV clusters
765 if(fNumberOfCpvClusters > 0){
767 Int_t nModulesToUnfold = geom->GetNCPVModules() ;
769 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
771 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
773 AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
775 if(recPoint->GetPHOSMod()> nModulesToUnfold)
778 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ;
780 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
781 Int_t * maxAt = new Int_t[nMultipl] ;
782 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
783 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
785 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
786 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
787 cpvRecPoints->Remove(emcRecPoint);
788 cpvRecPoints->Compress() ;
790 numberofCpvNotUnfolded-- ;
791 fNumberOfCpvClusters-- ;
795 delete[] maxAtEnergy ;
798 //Unfolding of Cpv clusters finished
802 //____________________________________________________________________________
803 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
805 // Shape of the shower (see PHOS TDR)
806 // If you change this function, change also the gradient evaluation in ChiSquare()
808 Double_t r4 = r*r*r*r ;
809 Double_t r295 = TMath::Power(r, 2.95) ;
810 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
814 //____________________________________________________________________________
815 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
818 Float_t * maxAtEnergy)
820 // Performs the unfolding of a cluster with nMax overlapping showers
822 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
823 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
824 TClonesArray * digits = gime->Digits() ;
825 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
826 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
828 Int_t nPar = 3 * nMax ;
829 Float_t * fitparameters = new Float_t[nPar] ;
831 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
833 // Fit failed, return and remove cluster
834 delete[] fitparameters ;
838 // create ufolded rec points and fill them with new energy lists
839 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
840 // and later correct this number in acordance with actual energy deposition
842 Int_t nDigits = iniEmc->GetMultiplicity() ;
843 Float_t * efit = new Float_t[nDigits] ;
844 Float_t xDigit=0.,zDigit=0.,distance=0. ;
845 Float_t xpar=0.,zpar=0.,epar=0. ;
847 AliPHOSDigit * digit = 0 ;
848 Int_t * emcDigits = iniEmc->GetDigitsList() ;
852 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
853 digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;
854 geom->AbsToRelNumbering(digit->GetId(), relid) ;
855 geom->RelPosInModule(relid, xDigit, zDigit) ;
859 while(iparam < nPar ){
860 xpar = fitparameters[iparam] ;
861 zpar = fitparameters[iparam+1] ;
862 epar = fitparameters[iparam+2] ;
864 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
865 distance = TMath::Sqrt(distance) ;
866 efit[iDigit] += epar * ShowerShape(distance) ;
871 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
872 // so that energy deposited in each cell is distributed betwin new clusters proportionally
873 // to its contribution to efit
875 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
879 while(iparam < nPar ){
880 xpar = fitparameters[iparam] ;
881 zpar = fitparameters[iparam+1] ;
882 epar = fitparameters[iparam+2] ;
885 AliPHOSEmcRecPoint * emcRP = 0 ;
887 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
889 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
890 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
892 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint() ;
893 emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
894 fNumberOfEmcClusters++ ;
896 else{//create new entries in fCpvRecPoints
897 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
898 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
900 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint() ;
901 emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
902 fNumberOfCpvClusters++ ;
906 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
907 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
908 geom->AbsToRelNumbering(digit->GetId(), relid) ;
909 geom->RelPosInModule(relid, xDigit, zDigit) ;
910 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
911 distance = TMath::Sqrt(distance) ;
912 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
913 eDigit = emcEnergies[iDigit] * ratio ;
914 emcRP->AddDigit( *digit, eDigit ) ;
918 delete[] fitparameters ;
923 //_____________________________________________________________________________
924 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
926 // Calculates the Chi square for the cluster unfolding minimization
927 // Number of parameters, Gradient, Chi squared, parameters, what to do
930 TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
932 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ;
933 TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ;
937 // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
939 Int_t * emcDigits = emcRP->GetDigitsList() ;
941 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
943 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
945 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
951 for(iparam = 0 ; iparam < nPar ; iparam++)
952 Grad[iparam] = 0 ; // Will evaluate gradient
956 AliPHOSDigit * digit ;
959 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
961 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
967 geom->AbsToRelNumbering(digit->GetId(), relid) ;
969 geom->RelPosInModule(relid, xDigit, zDigit) ;
971 if(iflag == 2){ // calculate gradient
974 while(iParam < nPar ){
975 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
977 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
978 distance = TMath::Sqrt( distance ) ;
980 efit += x[iParam] * ShowerShape(distance) ;
983 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
985 while(iParam < nPar ){
986 Double_t xpar = x[iParam] ;
987 Double_t zpar = x[iParam+1] ;
988 Double_t epar = x[iParam+2] ;
989 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
990 Double_t shape = sum * ShowerShape(dr) ;
991 Double_t r4 = dr*dr*dr*dr ;
992 Double_t r295 = TMath::Power(dr,2.95) ;
993 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
994 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
996 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
998 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
1000 Grad[iParam] += shape ; // Derivative over energy
1007 while(iparam < nPar ){
1008 Double_t xpar = x[iparam] ;
1009 Double_t zpar = x[iparam+1] ;
1010 Double_t epar = x[iparam+2] ;
1012 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
1013 distance = TMath::Sqrt(distance) ;
1014 efit += epar * ShowerShape(distance) ;
1017 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
1018 // Here we assume, that sigma = sqrt(E)
1023 //____________________________________________________________________________
1024 void AliPHOSClusterizerv1::Print(Option_t * option)const
1026 // Print clusterizer parameters
1028 if( strcmp(GetName(), "") !=0 ){
1032 TString taskName(GetName()) ;
1033 taskName.ReplaceAll(Version(), "") ;
1035 cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl
1036 << "Clusterizing digits from the file: " << fHeaderFileName.Data() << endl
1037 << " Branch: " << fDigitsBranchTitle.Data() << endl
1039 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
1040 << " EMC Local Maximum cut = " << fEmcLocMaxCut << endl
1041 << " EMC Logarothmic weight = " << fW0 << endl
1043 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
1044 << " CPV Local Maximum cut = " << fCpvLocMaxCut << endl
1045 << " CPV Logarothmic weight = " << fW0CPV << endl
1047 << " PPSD Clustering threshold = " << fPpsdClusteringThreshold << endl;
1049 cout << " Unfolding on " << endl ;
1051 cout << " Unfolding off " << endl ;
1053 cout << "------------------------------------------------------------------" <<endl ;
1056 cout << " AliPHOSClusterizerv1 not initialized " << endl ;
1058 //____________________________________________________________________________
1059 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1061 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1063 TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints() ;
1064 TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints() ;
1066 cout << "AliPHOSClusterizerv1: " << endl ;
1067 cout << " Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and "
1068 << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
1070 if(strstr(option,"all")) {
1071 cout << "EMC clusters " << endl ;
1083 << " Primaries list " << endl;
1086 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1087 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1089 cout << setw(6) << rp->GetIndexInList() << " ";
1090 cout << setw(6) << rp->GetEnergy() << " ";
1091 cout << setw(6) << rp->GetMultiplicity()<< " ";
1092 cout << setw(6) << rp->GetPHOSMod() << " ";
1095 rp->GetLocalPosition(locpos);
1096 cout << setw(8) << locpos.X() << " ";
1097 cout << setw(8) << locpos.Y() << " ";
1098 cout << setw(8) << locpos.Z() << " ";
1101 rp->GetElipsAxis(lambda);
1102 cout << setw(10)<< lambda[0] << " ";
1103 cout << setw(10)<< lambda[1] << " ";
1108 primaries = rp->GetPrimaries(nprimaries);
1109 cout << setw(8) << primaries << " ";
1111 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1112 cout << setw(4) << primaries[iprimary] << " ";
1117 //Now plot CPV/PPSD recPoints
1118 cout << "EMC clusters " << endl ;
1127 << " Primaries list " << endl;
1129 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1130 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
1131 cout << setw(6) << rp->GetIndexInList() << " ";
1132 cout << setw(6) << rp->GetPHOSMod() << " ";
1134 if( (strcmp(rp->ClassName() , "AliPHOSPpsdRecPoint" )) == 0){
1135 AliPHOSPpsdRecPoint * ppsd = (AliPHOSPpsdRecPoint*) rp ;
1145 rp->GetLocalPosition(locpos);
1146 cout << setw(8) << locpos.X() << " ";
1147 cout << setw(8) << locpos.Y() << " ";
1148 cout << setw(8) << locpos.Z() << " ";
1152 primaries = rp->GetPrimaries(nprimaries);
1153 cout << setw(8) << primaries << " ";
1155 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1156 cout << setw(4) << primaries[iprimary] << " ";
1161 cout << "-------------------------------------------------"<<endl ;