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("PHOSClusterizer");
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 gAlice->GetEvent(ievent) ;
189 gAlice->SetEvent(ievent) ;
191 if(!ReadDigits(ievent)) //reads digits for event fEvent
199 WriteRecPoints(ievent) ;
201 if(strstr(option,"deb"))
202 PrintRecPoints(option) ;
205 if(strstr(option,"tim")){
206 gBenchmark->Stop("PHOSClusterizer");
207 cout << "AliPHOSClusterizer:" << endl ;
208 cout << " took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing "
209 << gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
215 //____________________________________________________________________________
216 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
217 Int_t nPar, Float_t * fitparameters) const
219 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
220 // The initial values for fitting procedure are set equal to the positions of local maxima.
221 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
223 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
224 TClonesArray * digits = gime->Digits() ;
227 gMinuit->mncler(); // Reset Minuit's list of paramters
228 gMinuit->SetPrintLevel(-1) ; // No Printout
229 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
230 // To set the address of the minimization function
232 TList * toMinuit = new TList();
233 toMinuit->AddAt(emcRP,0) ;
234 toMinuit->AddAt(digits,1) ;
236 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
238 // filling initial values for fit parameters
239 AliPHOSDigit * digit ;
243 Int_t nDigits = (Int_t) nPar / 3 ;
247 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
249 for(iDigit = 0; iDigit < nDigits; iDigit++){
250 digit = (AliPHOSDigit *) maxAt[iDigit];
255 geom->AbsToRelNumbering(digit->GetId(), relid) ;
256 geom->RelPosInModule(relid, x, z) ;
258 Float_t energy = maxAtEnergy[iDigit] ;
260 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
263 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
266 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
269 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
272 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
275 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
280 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
285 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
286 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
287 gMinuit->SetMaxIterations(5);
288 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
290 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
292 if(ierflg == 4){ // Minimum not found
293 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
296 for(index = 0; index < nPar; index++){
299 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
300 fitparameters[index] = val ;
308 //____________________________________________________________________________
309 void AliPHOSClusterizerv1::Init()
311 // Make all memory allocations which can not be done in default constructor.
312 // Attach the Clusterizer task to the list of PHOS tasks
314 if ( strcmp(GetTitle(), "") == 0 )
315 SetTitle("galice.root") ;
317 TString taskName(GetName()) ;
318 taskName.ReplaceAll(Version(), "") ;
320 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), taskName.Data()) ;
322 cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ;
327 gMinuit = new TMinuit(100) ;
329 //add Task to //YSAlice/tasks/Reconstructioner/PHOS
330 TTask * aliceRe = (TTask*)gROOT->FindObjectAny("YSAlice/tasks/Reconstructioner") ;
331 TTask * phosRe = (TTask*)aliceRe->GetListOfTasks()->FindObject("PHOS") ;
333 // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/recpointsName
334 gime->Post(GetTitle(), "R", taskName.Data() ) ;
338 //____________________________________________________________________________
339 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
341 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
343 // = 2 are not neighbour but do not continue searching
344 // neighbours are defined as digits having at least a common vertex
345 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
346 // which is compared to a digit (d2) not yet in a cluster
348 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
353 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
356 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
358 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module and the same PPSD Module
359 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
360 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
362 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
366 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
367 rv = 2; // Difference in row numbers is too large to look further
373 if( (relid1[0] < relid2[0]) || (relid1[1] < relid2[1]) )
378 //Do NOT clusterize upper PPSD
379 if( IsInPpsd(d1) && IsInPpsd(d2) &&
381 relid1[1] < geom->GetNumberOfPadsPhi()*geom->GetNumberOfPadsPhi() ) rv = 2 ;
387 //____________________________________________________________________________
388 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
390 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
393 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
396 geom->AbsToRelNumbering(digit->GetId(), relid) ;
398 if ( relid[1] == 0 ) rv = kTRUE;
403 //____________________________________________________________________________
404 Bool_t AliPHOSClusterizerv1::IsInPpsd(AliPHOSDigit * digit) const
406 // Tells if (true) or not (false) the digit is in a PHOS-PPSD module
409 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
412 geom->AbsToRelNumbering(digit->GetId(), relid) ;
414 if ( relid[1] > 0 && relid[0] > geom->GetNCPVModules() ) rv = kTRUE;
419 //____________________________________________________________________________
420 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
422 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
425 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
428 geom->AbsToRelNumbering(digit->GetId(), relid) ;
430 if ( relid[1] > 0 && relid[0] <= geom->GetNCPVModules() ) rv = kTRUE;
434 //____________________________________________________________________________
435 Bool_t AliPHOSClusterizerv1::ReadDigits(Int_t event)
437 // reads digitis with specified title from TreeD
439 fNumberOfEmcClusters = 0 ;
440 fNumberOfCpvClusters = 0 ;
442 if ( gAlice->TreeD()==0) {
443 cerr << "ERROR: AliPHOSClusterizerv1::ReadDigits There is no Digit Tree" << endl;
447 //set address of the Digits and Digitizer
448 TBranch * digitsBranch = 0;
449 TBranch * digitizerBranch = 0;
450 TObjArray * lob = (TObjArray*)gAlice->TreeD()->GetListOfBranches() ;
452 TBranch * branch = 0 ;
453 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
455 TString taskName(GetName()) ;
456 taskName.ReplaceAll(Version(), "") ;
458 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
459 if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
461 digitsBranch = branch ;
464 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
465 digitizerfound = kTRUE ;
466 digitizerBranch = branch ;
469 if ( !phosfound || !digitizerfound ) {
470 cerr << "WARNING: AliPHOSClusterizerv1::ReadDigits -> Digits and/or Digitizer branch with name " << taskName.Data()
471 << " not found" << endl ;
475 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
477 TClonesArray * digits = gime->Digits() ;
479 digitsBranch->SetAddress(&digits) ;
481 AliPHOSDigitizer * digitizer = gime->Digitizer() ;
482 digitizerBranch->SetAddress(&digitizer) ;
484 digitsBranch->GetEntry(0) ;
485 digitizerBranch->GetEntry(0) ;
487 fPedestal = digitizer->GetPedestal() ;
488 fSlope = digitizer->GetSlope() ;
493 //____________________________________________________________________________
494 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
497 // Creates new branches with given title
498 // fills and writes into TreeR.
500 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
501 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
502 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
503 TClonesArray * digits = gime->Digits() ;
506 //Evaluate position, dispersion and other RecPoint properties...
507 for(index = 0; index < emcRecPoints->GetEntries(); index++)
508 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ;
510 emcRecPoints->Sort() ;
512 for(index = 0; index < emcRecPoints->GetEntries(); index++)
513 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
515 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
517 //Now the same for CPV
518 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
519 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ;
521 cpvRecPoints->Sort() ;
523 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
524 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
526 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
528 gAlice->GetEvent(event) ;
529 if(gAlice->TreeR()==0)
530 gAlice->MakeTree("R") ;
532 //Make branches in TreeR for RecPoints and Clusterizer
534 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
535 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
536 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
540 TDirectory *cwd = gDirectory;
542 TString branchName(GetName()) ;
543 branchName.ReplaceAll(Version(), "") ;
545 Int_t bufferSize = 32000 ;
546 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);
591 clusterizerBranch->Fill() ;
593 gAlice->TreeR()->Write(0,kOverwrite) ;
597 //____________________________________________________________________________
598 void AliPHOSClusterizerv1::MakeClusters()
600 // Steering method to construct the clusters stored in a list of Reconstructed Points
601 // A cluster is defined as a list of neighbour digits
603 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
605 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
606 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
607 emcRecPoints->Delete() ;
608 cpvRecPoints->Delete() ;
610 TClonesArray * digits = gime->Digits() ;
611 TClonesArray * digitsC = (TClonesArray*)digits->Clone() ;
614 // Clusterization starts
616 TIter nextdigit(digitsC) ;
617 AliPHOSDigit * digit ;
618 Bool_t notremoved = kTRUE ;
620 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC
621 AliPHOSRecPoint * clu = 0 ;
623 TArrayI clusterdigitslist(1500) ;
626 if (( IsInEmc (digit) && Calibrate(digit->GetAmp()) > fEmcClusteringThreshold ) ||
627 ( IsInPpsd(digit) && Calibrate(digit->GetAmp()) > fPpsdClusteringThreshold ) ||
628 ( IsInCpv (digit) && Calibrate(digit->GetAmp()) > fCpvClusteringThreshold ) ) {
630 Int_t iDigitInCluster = 0 ;
632 if ( IsInEmc(digit) ) {
633 // start a new EMC RecPoint
634 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
635 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
637 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(), fNumberOfEmcClusters) ;
638 clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ;
639 fNumberOfEmcClusters++ ;
640 clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ;
641 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
643 digitsC->Remove(digit) ;
647 // start a new PPSD/CPV cluster
648 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
649 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
652 cpvRecPoints->AddAt(new AliPHOSPpsdRecPoint(),fNumberOfCpvClusters) ;
654 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(), fNumberOfCpvClusters) ;
656 clu = (AliPHOSPpsdRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters) ;
657 fNumberOfCpvClusters++ ;
658 clu->AddDigit(*digit, Calibrate(digit->GetAmp()) ) ;
659 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
661 digitsC->Remove(digit) ;
664 // Here we remove remaining EMC digits, which cannot make a cluster
667 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
669 digitsC->Remove(digit) ;
673 notremoved = kFALSE ;
680 AliPHOSDigit * digitN ;
682 while (index < iDigitInCluster){ // scan over digits already in cluster
683 digit = (AliPHOSDigit*)digits->At(clusterdigitslist[index]) ;
685 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
686 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
688 case 0 : // not a neighbour
690 case 1 : // are neighbours
691 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp() ) ) ;
692 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
694 digitsC->Remove(digitN) ;
696 case 2 : // too far from each other
705 } // loop over cluster
716 //____________________________________________________________________________
717 void AliPHOSClusterizerv1::MakeUnfolding()
719 // Unfolds clusters using the shape of an ElectroMagnetic shower
720 // Performs unfolding of all EMC/CPV but NOT ppsd clusters
722 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
724 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
725 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
726 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
727 TClonesArray * digits = gime->Digits() ;
729 // Unfold first EMC clusters
730 if(fNumberOfEmcClusters > 0){
732 Int_t nModulesToUnfold = geom->GetNModules() ;
734 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
736 for(index = 0 ; index < numberofNotUnfolded ; index++){
738 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
739 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
742 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
743 Int_t * maxAt = new Int_t[nMultipl] ;
744 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
745 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
747 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
748 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
749 emcRecPoints->Remove(emcRecPoint);
750 emcRecPoints->Compress() ;
752 fNumberOfEmcClusters -- ;
753 numberofNotUnfolded-- ;
757 delete[] maxAtEnergy ;
760 // Unfolding of EMC clusters finished
763 // Unfold now CPV clusters
764 if(fNumberOfCpvClusters > 0){
766 Int_t nModulesToUnfold = geom->GetNCPVModules() ;
768 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
770 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
772 AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
774 if(recPoint->GetPHOSMod()> nModulesToUnfold)
777 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ;
779 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
780 Int_t * maxAt = new Int_t[nMultipl] ;
781 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
782 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
784 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
785 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
786 cpvRecPoints->Remove(emcRecPoint);
787 cpvRecPoints->Compress() ;
789 numberofCpvNotUnfolded-- ;
790 fNumberOfCpvClusters-- ;
794 delete[] maxAtEnergy ;
797 //Unfolding of Cpv clusters finished
801 //____________________________________________________________________________
802 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
804 // Shape of the shower (see PHOS TDR)
805 // If you change this function, change also the gradient evaluation in ChiSquare()
807 Double_t r4 = r*r*r*r ;
808 Double_t r295 = TMath::Power(r, 2.95) ;
809 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
813 //____________________________________________________________________________
814 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
817 Float_t * maxAtEnergy)
819 // Performs the unfolding of a cluster with nMax overlapping showers
821 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
822 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
823 TClonesArray * digits = gime->Digits() ;
824 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
825 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
827 Int_t nPar = 3 * nMax ;
828 Float_t * fitparameters = new Float_t[nPar] ;
830 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
832 // Fit failed, return and remove cluster
833 delete[] fitparameters ;
837 // create ufolded rec points and fill them with new energy lists
838 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
839 // and later correct this number in acordance with actual energy deposition
841 Int_t nDigits = iniEmc->GetMultiplicity() ;
842 Float_t * efit = new Float_t[nDigits] ;
843 Float_t xDigit=0.,zDigit=0.,distance=0. ;
844 Float_t xpar=0.,zpar=0.,epar=0. ;
846 AliPHOSDigit * digit = 0 ;
847 Int_t * emcDigits = iniEmc->GetDigitsList() ;
851 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
852 digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;
853 geom->AbsToRelNumbering(digit->GetId(), relid) ;
854 geom->RelPosInModule(relid, xDigit, zDigit) ;
858 while(iparam < nPar ){
859 xpar = fitparameters[iparam] ;
860 zpar = fitparameters[iparam+1] ;
861 epar = fitparameters[iparam+2] ;
863 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
864 distance = TMath::Sqrt(distance) ;
865 efit[iDigit] += epar * ShowerShape(distance) ;
870 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
871 // so that energy deposited in each cell is distributed betwin new clusters proportionally
872 // to its contribution to efit
874 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
878 while(iparam < nPar ){
879 xpar = fitparameters[iparam] ;
880 zpar = fitparameters[iparam+1] ;
881 epar = fitparameters[iparam+2] ;
884 AliPHOSEmcRecPoint * emcRP = 0 ;
886 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
888 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
889 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
891 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint() ;
892 emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
893 fNumberOfEmcClusters++ ;
895 else{//create new entries in fCpvRecPoints
896 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
897 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
899 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint() ;
900 emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
901 fNumberOfCpvClusters++ ;
905 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
906 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
907 geom->AbsToRelNumbering(digit->GetId(), relid) ;
908 geom->RelPosInModule(relid, xDigit, zDigit) ;
909 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
910 distance = TMath::Sqrt(distance) ;
911 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
912 eDigit = emcEnergies[iDigit] * ratio ;
913 emcRP->AddDigit( *digit, eDigit ) ;
917 delete[] fitparameters ;
922 //_____________________________________________________________________________
923 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
925 // Calculates the Chi square for the cluster unfolding minimization
926 // Number of parameters, Gradient, Chi squared, parameters, what to do
929 TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
931 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ;
932 TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ;
936 // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
938 Int_t * emcDigits = emcRP->GetDigitsList() ;
940 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
942 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
944 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
949 for(iparam = 0 ; iparam < nPar ; iparam++)
950 Grad[iparam] = 0 ; // Will evaluate gradient
954 AliPHOSDigit * digit ;
957 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
959 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
965 geom->AbsToRelNumbering(digit->GetId(), relid) ;
967 geom->RelPosInModule(relid, xDigit, zDigit) ;
969 if(iflag == 2){ // calculate gradient
972 while(iParam < nPar ){
973 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
975 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
976 distance = TMath::Sqrt( distance ) ;
978 efit += x[iParam] * ShowerShape(distance) ;
981 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
983 while(iParam < nPar ){
984 Double_t xpar = x[iParam] ;
985 Double_t zpar = x[iParam+1] ;
986 Double_t epar = x[iParam+2] ;
987 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
988 Double_t shape = sum * ShowerShape(dr) ;
989 Double_t r4 = dr*dr*dr*dr ;
990 Double_t r295 = TMath::Power(dr,2.95) ;
991 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
992 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
994 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
996 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
998 Grad[iParam] += shape ; // Derivative over energy
1005 while(iparam < nPar ){
1006 Double_t xpar = x[iparam] ;
1007 Double_t zpar = x[iparam+1] ;
1008 Double_t epar = x[iparam+2] ;
1010 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
1011 distance = TMath::Sqrt(distance) ;
1012 efit += epar * ShowerShape(distance) ;
1015 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
1016 // Here we assume, that sigma = sqrt(E)
1021 //____________________________________________________________________________
1022 void AliPHOSClusterizerv1::Print(Option_t * option)const
1024 // Print clusterizer parameters
1026 if( strcmp(GetName(), "") !=0 ){
1030 TString taskName(GetName()) ;
1031 taskName.ReplaceAll(Version(), "") ;
1033 cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl
1034 << "Clusterizing digits from the file: " << fHeaderFileName.Data() << endl
1035 << " Branch: " << fDigitsBranchTitle.Data() << endl
1037 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
1038 << " EMC Local Maximum cut = " << fEmcLocMaxCut << endl
1039 << " EMC Logarothmic weight = " << fW0 << endl
1041 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
1042 << " CPV Local Maximum cut = " << fCpvLocMaxCut << endl
1043 << " CPV Logarothmic weight = " << fW0CPV << endl
1045 << " PPSD Clustering threshold = " << fPpsdClusteringThreshold << endl;
1047 cout << " Unfolding on " << endl ;
1049 cout << " Unfolding off " << endl ;
1051 cout << "------------------------------------------------------------------" <<endl ;
1054 cout << " AliPHOSClusterizerv1 not initialized " << endl ;
1056 //____________________________________________________________________________
1057 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1059 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1061 TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints() ;
1062 TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints() ;
1064 cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ;
1065 cout << " Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and "
1066 << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
1068 if(strstr(option,"all")) {
1069 cout << "EMC clusters " << endl ;
1081 << " Primaries list " << endl;
1084 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1085 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1087 cout << setw(6) << rp->GetIndexInList() << " ";
1088 cout << setw(6) << rp->GetEnergy() << " ";
1089 cout << setw(6) << rp->GetMultiplicity()<< " ";
1090 cout << setw(6) << rp->GetPHOSMod() << " ";
1093 rp->GetLocalPosition(locpos);
1094 cout << setw(8) << locpos.X() << " ";
1095 cout << setw(8) << locpos.Y() << " ";
1096 cout << setw(8) << locpos.Z() << " ";
1099 rp->GetElipsAxis(lambda);
1100 cout << setw(10)<< lambda[0] << " ";
1101 cout << setw(10)<< lambda[1] << " ";
1106 primaries = rp->GetPrimaries(nprimaries);
1107 cout << setw(8) << primaries << " ";
1109 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1110 cout << setw(4) << primaries[iprimary] << " ";
1115 //Now plot CPV/PPSD recPoints
1116 cout << "EMC clusters " << endl ;
1125 << " Primaries list " << endl;
1127 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1128 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
1129 cout << setw(6) << rp->GetIndexInList() << " ";
1130 cout << setw(6) << rp->GetPHOSMod() << " ";
1132 if( (strcmp(rp->ClassName() , "AliPHOSPpsdRecPoint" )) == 0){
1133 AliPHOSPpsdRecPoint * ppsd = (AliPHOSPpsdRecPoint*) rp ;
1143 rp->GetLocalPosition(locpos);
1144 cout << setw(8) << locpos.X() << " ";
1145 cout << setw(8) << locpos.Y() << " ";
1146 cout << setw(8) << locpos.Z() << " ";
1150 primaries = rp->GetPrimaries(nprimaries);
1151 cout << setw(8) << primaries << " ";
1153 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1154 cout << setw(4) << primaries[iprimary] << " ";
1159 cout << "-------------------------------------------------"<<endl ;