1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 1 October 2000. Yuri Kharlov:
21 PPSD upper layer is considered if number of layers>1
23 18 October 2000. Yuri Kharlov:
24 AliPHOSClusterizerv1()
25 CPV clusterizing parameters added
28 After first PPSD digit remove EMC digits only once
30 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
31 //////////////////////////////////////////////////////////////////////////////
32 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
33 // unfolds the clusters having several local maxima.
34 // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
35 // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
36 // parameters including input digits branch title, thresholds etc.)
37 // This TTask is normally called from Reconstructioner, but can as well be used in
40 // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
41 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
42 // // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
43 // // and saves recpoints in branch named "recpointsname" (default = "digitsname")
44 // root [1] cl->ExecuteTask()
45 // //finds RecPoints in all events stored in galice.root
46 // root [2] cl->SetDigitsBranch("digits2")
47 // //sets another title for Digitis (input) branch
48 // root [3] cl->SetRecPointsBranch("recp2")
49 // //sets another title four output branches
50 // root [4] cl->SetEmcLocalMaxCut(0.03)
51 // //set clusterization parameters
52 // root [5] cl->ExecuteTask("deb all time")
53 // //once more finds RecPoints options are
54 // // deb - print number of found rec points
55 // // deb all - print number of found RecPoints and some their characteristics
56 // // time - print benchmarking results
58 // --- ROOT system ---
67 #include "TBenchmark.h"
69 // --- Standard library ---
74 // --- AliRoot header files ---
76 #include "AliPHOSClusterizerv1.h"
77 #include "AliPHOSCpvRecPoint.h"
78 #include "AliPHOSDigit.h"
79 #include "AliPHOSDigitizer.h"
80 #include "AliPHOSEmcRecPoint.h"
82 #include "AliPHOSGetter.h"
85 ClassImp(AliPHOSClusterizerv1)
87 //____________________________________________________________________________
88 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
90 // default ctor (to be used mainly by Streamer)
95 //____________________________________________________________________________
96 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* name, const char * from)
97 :AliPHOSClusterizer(headerFile, name)
99 // ctor with the indication of the file where header Tree and digits Tree are stored
111 //____________________________________________________________________________
112 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
115 // gime=0 if Clusterizer created by default ctor (to get just the parameters)
118 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
121 // remove the task from the folder list
122 gime->RemoveTask("C",GetName()) ;
124 // remove the data from the folder list
125 TString name(GetName()) ;
126 name.Remove(name.Index(":")) ;
127 gime->RemoveObjects("D", name) ; // Digits
128 gime->RemoveObjects("RE", name) ; // EMCARecPoints
129 gime->RemoveObjects("RC", name) ; // CPVRecPoints
138 //____________________________________________________________________________
139 const TString AliPHOSClusterizerv1::BranchName() const
141 TString branchName(GetName() ) ;
142 branchName.Remove(branchName.Index(Version())-1) ;
146 //____________________________________________________________________________
147 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
149 if(absId <= fEmcCrystals) //calibrate as EMC
150 return fADCpedestalEmc + amp*fADCchanelEmc ;
151 else //Digitize as CPV
152 return fADCpedestalCpv+ amp*fADCchanelCpv ;
154 //____________________________________________________________________________
155 void AliPHOSClusterizerv1::Exec(Option_t * option)
159 if( strcmp(GetName(), "")== 0 )
162 if(strstr(option,"tim"))
163 gBenchmark->Start("PHOSClusterizer");
165 if(strstr(option,"print"))
168 gAlice->GetEvent(0) ;
170 //check, if the branch with name of this" already exits?
171 if(gAlice->TreeR()) {
172 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
174 TBranch * branch = 0 ;
175 Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ;
177 TString branchname = GetName() ;
178 branchname.Remove(branchname.Index(Version())-1) ;
180 while ( (branch = (TBranch*)next()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) {
181 if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
182 phosemcfound = kTRUE ;
184 else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
185 phoscpvfound = kTRUE ;
187 else if ((strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
188 clusterizerfound = kTRUE ;
191 if ( phoscpvfound || phosemcfound || clusterizerfound ) {
192 cerr << "WARNING: AliPHOSClusterizer::Exec -> Emc(Cpv)RecPoints and/or Clusterizer branch with name "
193 << branchname.Data() << " already exits" << endl ;
198 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
199 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
202 for(ievent = 0; ievent < nevents; ievent++){
204 if(ievent == 0) GetCalibrationParameters() ;
206 fNumberOfEmcClusters = 0 ;
207 fNumberOfCpvClusters = 0 ;
209 gime->Event(ievent,"D") ;
211 // if(!ReadDigits(ievent)) continue; //reads digits for event ievent
218 WriteRecPoints(ievent) ;
220 if(strstr(option,"deb"))
221 PrintRecPoints(option) ;
223 //increment the total number of digits per run
224 fRecPointsInRun += gime->EmcRecPoints(BranchName())->GetEntriesFast() ;
225 fRecPointsInRun += gime->CpvRecPoints(BranchName())->GetEntriesFast() ;
228 if(strstr(option,"tim")){
229 gBenchmark->Stop("PHOSClusterizer");
230 cout << "AliPHOSClusterizer:" << endl ;
231 cout << " took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing "
232 << gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
238 //____________________________________________________________________________
239 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
240 Int_t nPar, Float_t * fitparameters) const
242 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
243 // The initial values for fitting procedure are set equal to the positions of local maxima.
244 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
246 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
247 TClonesArray * digits = gime->Digits(fFrom) ;
250 gMinuit->mncler(); // Reset Minuit's list of paramters
251 gMinuit->SetPrintLevel(-1) ; // No Printout
252 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
253 // To set the address of the minimization function
255 TList * toMinuit = new TList();
256 toMinuit->AddAt(emcRP,0) ;
257 toMinuit->AddAt(digits,1) ;
259 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
261 // filling initial values for fit parameters
262 AliPHOSDigit * digit ;
266 Int_t nDigits = (Int_t) nPar / 3 ;
270 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
272 for(iDigit = 0; iDigit < nDigits; iDigit++){
273 digit = maxAt[iDigit];
278 geom->AbsToRelNumbering(digit->GetId(), relid) ;
279 geom->RelPosInModule(relid, x, z) ;
281 Float_t energy = maxAtEnergy[iDigit] ;
283 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
286 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
289 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
292 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
295 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
298 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
303 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
308 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
309 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
310 gMinuit->SetMaxIterations(5);
311 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
313 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
315 if(ierflg == 4){ // Minimum not found
316 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
319 for(index = 0; index < nPar; index++){
322 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
323 fitparameters[index] = val ;
331 //____________________________________________________________________________
332 void AliPHOSClusterizerv1::GetCalibrationParameters()
334 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
335 TString branchname = GetName() ;
336 branchname.Remove(branchname.Index(Version())-1) ;
337 AliPHOSDigitizer * dig = gime->Digitizer(fFrom) ;
338 fADCchanelEmc = dig->GetEMCchannel() ;
339 fADCpedestalEmc = dig->GetEMCpedestal();
341 fADCchanelCpv = dig->GetCPVchannel() ;
342 fADCpedestalCpv = dig->GetCPVpedestal() ;
345 //____________________________________________________________________________
346 void AliPHOSClusterizerv1::Init()
348 // Make all memory allocations which can not be done in default constructor.
349 // Attach the Clusterizer task to the list of PHOS tasks
351 if ( strcmp(GetTitle(), "") == 0 )
352 SetTitle("galice.root") ;
354 TString branchname = GetName() ;
355 branchname.Remove(branchname.Index(Version())-1) ;
357 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), fFrom.Data()) ;
359 cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ;
363 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
364 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
367 gMinuit = new TMinuit(100) ;
368 gime->PostClusterizer(this) ;
369 // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/recpointsName
370 gime->PostRecPoints(branchname) ;
372 gime->PostDigits(fFrom) ;
373 gime->PostDigitizer(fFrom) ;
377 //____________________________________________________________________________
378 void AliPHOSClusterizerv1::InitParameters()
381 fNumberOfCpvClusters = 0 ;
382 fNumberOfEmcClusters = 0 ;
384 fCpvClusteringThreshold = 0.0;
385 fEmcClusteringThreshold = 0.2;
387 fEmcLocMaxCut = 0.03 ;
388 fCpvLocMaxCut = 0.03 ;
393 fEmcTimeGate = 1.e-8 ;
397 fHeaderFileName = GetTitle() ;
398 fDigitsBranchTitle = GetName() ;
400 TString clusterizerName( GetName()) ;
401 if (clusterizerName.IsNull() )
402 clusterizerName = "Default" ;
403 clusterizerName.Append(":") ;
404 clusterizerName.Append(Version()) ;
405 SetName(clusterizerName) ;
406 fRecPointsInRun = 0 ;
410 //____________________________________________________________________________
411 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
413 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
415 // = 2 are not neighbour but do not continue searching
416 // neighbours are defined as digits having at least a common vertex
417 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
418 // which is compared to a digit (d2) not yet in a cluster
420 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
425 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
428 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
430 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
431 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
432 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
434 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
435 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
439 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
440 rv = 2; // Difference in row numbers is too large to look further
446 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
455 //____________________________________________________________________________
456 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
458 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
461 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
463 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
465 if(digit->GetId() <= nEMC ) rv = kTRUE;
470 //____________________________________________________________________________
471 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
473 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
476 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
478 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
480 if(digit->GetId() > nEMC ) rv = kTRUE;
485 //____________________________________________________________________________
486 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
489 // Creates new branches with given title
490 // fills and writes into TreeR.
493 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
494 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
495 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
496 TClonesArray * digits = gime->Digits(fFrom) ;
497 TTree * treeR = gAlice->TreeR();
499 if (!gAlice->TreeR() )
500 gAlice->MakeTree("R", fSplitFile);
501 treeR = gAlice->TreeR() ;
504 //Evaluate position, dispersion and other RecPoint properties...
505 for(index = 0; index < emcRecPoints->GetEntries(); index++)
506 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ;
508 emcRecPoints->Sort() ;
509 for(index = 0; index < emcRecPoints->GetEntries(); index++)
510 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
512 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
514 //Now the same for CPV
515 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
516 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ;
518 cpvRecPoints->Sort() ;
520 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
521 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
523 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
525 Int_t bufferSize = 32000 ;
526 Int_t splitlevel = 0 ;
529 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
530 emcBranch->SetTitle(BranchName());
533 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
534 cpvBranch->SetTitle(BranchName());
536 //And Finally clusterizer branch
537 AliPHOSClusterizerv1 * cl = this ;
538 TBranch * clusterizerBranch = treeR->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1",
539 &cl,bufferSize,splitlevel);
540 clusterizerBranch->SetTitle(BranchName());
544 clusterizerBranch->Fill() ;
546 treeR->AutoSave() ; //Write(0,kOverwrite) ;
550 //____________________________________________________________________________
551 void AliPHOSClusterizerv1::MakeClusters()
553 // Steering method to construct the clusters stored in a list of Reconstructed Points
554 // A cluster is defined as a list of neighbour digits
556 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
558 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
559 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
560 emcRecPoints->Delete() ;
561 cpvRecPoints->Delete() ;
563 TClonesArray * digits = gime->Digits(fFrom) ;
565 cerr << "ERROR: AliPHOSClusterizerv1::MakeClusters -> Digits with name "
566 << fFrom << " not found ! " << endl ;
569 TClonesArray * digitsC = (TClonesArray*)digits->Clone() ;
572 // Clusterization starts
574 TIter nextdigit(digitsC) ;
575 AliPHOSDigit * digit ;
576 Bool_t notremoved = kTRUE ;
578 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC
579 AliPHOSRecPoint * clu = 0 ;
581 TArrayI clusterdigitslist(1500) ;
584 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
585 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
587 Int_t iDigitInCluster = 0 ;
589 if ( IsInEmc(digit) ) {
590 // start a new EMC RecPoint
591 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
592 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
594 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
595 clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ;
596 fNumberOfEmcClusters++ ;
597 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
598 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
600 digitsC->Remove(digit) ;
604 // start a new CPV cluster
605 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
606 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
608 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
610 clu = (AliPHOSCpvRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters) ;
611 fNumberOfCpvClusters++ ;
612 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
613 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
615 digitsC->Remove(digit) ;
618 // Here we remove remaining EMC digits, which cannot make a cluster
621 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
623 digitsC->Remove(digit) ;
627 notremoved = kFALSE ;
634 AliPHOSDigit * digitN ;
636 while (index < iDigitInCluster){ // scan over digits already in cluster
637 digit = (AliPHOSDigit*)digits->At(clusterdigitslist[index]) ;
639 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
640 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
642 case 0 : // not a neighbour
644 case 1 : // are neighbours
645 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
646 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
648 digitsC->Remove(digitN) ;
650 case 2 : // too far from each other
659 } // loop over cluster
670 //____________________________________________________________________________
671 void AliPHOSClusterizerv1::MakeUnfolding()
673 // Unfolds clusters using the shape of an ElectroMagnetic shower
674 // Performs unfolding of all EMC/CPV clusters
676 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
679 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
680 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
681 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
682 TClonesArray * digits = gime->Digits(fFrom) ;
684 // Unfold first EMC clusters
685 if(fNumberOfEmcClusters > 0){
687 Int_t nModulesToUnfold = geom->GetNModules() ;
689 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
691 for(index = 0 ; index < numberofNotUnfolded ; index++){
693 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
694 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
697 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
698 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
699 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
700 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
702 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
703 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
704 emcRecPoints->Remove(emcRecPoint);
705 emcRecPoints->Compress() ;
707 fNumberOfEmcClusters -- ;
708 numberofNotUnfolded-- ;
712 delete[] maxAtEnergy ;
715 // Unfolding of EMC clusters finished
718 // Unfold now CPV clusters
719 if(fNumberOfCpvClusters > 0){
721 Int_t nModulesToUnfold = geom->GetNModules() ;
723 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
725 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
727 AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
729 if(recPoint->GetPHOSMod()> nModulesToUnfold)
732 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ;
734 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
735 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
736 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
737 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
739 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
740 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
741 cpvRecPoints->Remove(emcRecPoint);
742 cpvRecPoints->Compress() ;
744 numberofCpvNotUnfolded-- ;
745 fNumberOfCpvClusters-- ;
749 delete[] maxAtEnergy ;
752 //Unfolding of Cpv clusters finished
756 //____________________________________________________________________________
757 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
759 // Shape of the shower (see PHOS TDR)
760 // If you change this function, change also the gradient evaluation in ChiSquare()
762 Double_t r4 = r*r*r*r ;
763 Double_t r295 = TMath::Power(r, 2.95) ;
764 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
768 //____________________________________________________________________________
769 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
771 AliPHOSDigit ** maxAt,
772 Float_t * maxAtEnergy)
774 // Performs the unfolding of a cluster with nMax overlapping showers
776 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
778 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
779 const TClonesArray * digits = gime->Digits(fFrom) ;
780 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
781 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
783 Int_t nPar = 3 * nMax ;
784 Float_t * fitparameters = new Float_t[nPar] ;
786 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
788 // Fit failed, return and remove cluster
789 delete[] fitparameters ;
793 // create ufolded rec points and fill them with new energy lists
794 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
795 // and later correct this number in acordance with actual energy deposition
797 Int_t nDigits = iniEmc->GetMultiplicity() ;
798 Float_t * efit = new Float_t[nDigits] ;
799 Float_t xDigit=0.,zDigit=0.,distance=0. ;
800 Float_t xpar=0.,zpar=0.,epar=0. ;
802 AliPHOSDigit * digit = 0 ;
803 Int_t * emcDigits = iniEmc->GetDigitsList() ;
807 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
808 digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;
809 geom->AbsToRelNumbering(digit->GetId(), relid) ;
810 geom->RelPosInModule(relid, xDigit, zDigit) ;
814 while(iparam < nPar ){
815 xpar = fitparameters[iparam] ;
816 zpar = fitparameters[iparam+1] ;
817 epar = fitparameters[iparam+2] ;
819 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
820 distance = TMath::Sqrt(distance) ;
821 efit[iDigit] += epar * ShowerShape(distance) ;
826 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
827 // so that energy deposited in each cell is distributed betwin new clusters proportionally
828 // to its contribution to efit
830 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
834 while(iparam < nPar ){
835 xpar = fitparameters[iparam] ;
836 zpar = fitparameters[iparam+1] ;
837 epar = fitparameters[iparam+2] ;
840 AliPHOSEmcRecPoint * emcRP = 0 ;
842 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
844 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
845 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
847 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
848 emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
849 fNumberOfEmcClusters++ ;
851 else{//create new entries in fCpvRecPoints
852 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
853 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
855 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
856 emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
857 fNumberOfCpvClusters++ ;
861 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
862 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
863 geom->AbsToRelNumbering(digit->GetId(), relid) ;
864 geom->RelPosInModule(relid, xDigit, zDigit) ;
865 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
866 distance = TMath::Sqrt(distance) ;
867 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
868 eDigit = emcEnergies[iDigit] * ratio ;
869 emcRP->AddDigit( *digit, eDigit ) ;
873 delete[] fitparameters ;
878 //_____________________________________________________________________________
879 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
881 // Calculates the Chi square for the cluster unfolding minimization
882 // Number of parameters, Gradient, Chi squared, parameters, what to do
884 TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
886 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ;
887 TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ;
891 // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
893 Int_t * emcDigits = emcRP->GetDigitsList() ;
895 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
897 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
899 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
904 for(iparam = 0 ; iparam < nPar ; iparam++)
905 Grad[iparam] = 0 ; // Will evaluate gradient
909 AliPHOSDigit * digit ;
912 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
914 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
920 geom->AbsToRelNumbering(digit->GetId(), relid) ;
922 geom->RelPosInModule(relid, xDigit, zDigit) ;
924 if(iflag == 2){ // calculate gradient
927 while(iParam < nPar ){
928 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
930 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
931 distance = TMath::Sqrt( distance ) ;
933 efit += x[iParam] * ShowerShape(distance) ;
936 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
938 while(iParam < nPar ){
939 Double_t xpar = x[iParam] ;
940 Double_t zpar = x[iParam+1] ;
941 Double_t epar = x[iParam+2] ;
942 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
943 Double_t shape = sum * ShowerShape(dr) ;
944 Double_t r4 = dr*dr*dr*dr ;
945 Double_t r295 = TMath::Power(dr,2.95) ;
946 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
947 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
949 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
951 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
953 Grad[iParam] += shape ; // Derivative over energy
960 while(iparam < nPar ){
961 Double_t xpar = x[iparam] ;
962 Double_t zpar = x[iparam+1] ;
963 Double_t epar = x[iparam+2] ;
965 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
966 distance = TMath::Sqrt(distance) ;
967 efit += epar * ShowerShape(distance) ;
970 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
971 // Here we assume, that sigma = sqrt(E)
976 //____________________________________________________________________________
977 void AliPHOSClusterizerv1::Print(Option_t * option)const
979 // Print clusterizer parameters
981 if( strcmp(GetName(), "") !=0 ){
985 TString taskName(GetName()) ;
986 taskName.ReplaceAll(Version(), "") ;
988 cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl
989 << "Clusterizing digits from the file: " << fHeaderFileName.Data() << endl
990 << " Branch: " << fDigitsBranchTitle.Data() << endl
992 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
993 << " EMC Local Maximum cut = " << fEmcLocMaxCut << endl
994 << " EMC Logarothmic weight = " << fW0 << endl
996 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
997 << " CPV Local Maximum cut = " << fCpvLocMaxCut << endl
998 << " CPV Logarothmic weight = " << fW0CPV << endl
1001 cout << " Unfolding on " << endl ;
1003 cout << " Unfolding off " << endl ;
1005 cout << "------------------------------------------------------------------" <<endl ;
1008 cout << " AliPHOSClusterizerv1 not initialized " << endl ;
1010 //____________________________________________________________________________
1011 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1013 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1015 TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints(BranchName()) ;
1016 TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints(BranchName()) ;
1018 cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ;
1019 cout << " Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and "
1020 << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
1022 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1023 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1025 if(strstr(option,"all")) {
1026 cout << "EMC clusters " << endl ;
1027 cout << " Index Ene(MeV) Multi Module X Y Z Lambda 1 Lambda 2 # of prim Primaries list " << endl;
1030 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1031 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1033 rp->GetLocalPosition(locpos);
1035 rp->GetElipsAxis(lambda);
1038 primaries = rp->GetPrimaries(nprimaries);
1040 cout << setw(4) << rp->GetIndexInList() << " "
1041 << setw(7) << setprecision(3) << rp->GetEnergy() << " "
1042 << setw(3) << rp->GetMultiplicity() << " "
1043 << setw(1) << rp->GetPHOSMod() << " "
1044 << setw(6) << setprecision(2) << locpos.X() << " "
1045 << setw(6) << setprecision(2) << locpos.Y() << " "
1046 << setw(6) << setprecision(2) << locpos.Z() << " "
1047 << setw(4) << setprecision(2) << lambda[0] << " "
1048 << setw(4) << setprecision(2) << lambda[1] << " "
1049 << setw(2) << nprimaries << " " ;
1051 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1052 cout << setw(4) << primaries[iprimary] << " " ;
1056 //Now plot CPV recPoints
1057 cout << "EMC clusters " << endl ;
1065 << " Primaries list " << endl;
1067 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1068 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
1069 cout << setw(6) << rp->GetIndexInList() << " ";
1070 cout << setw(6) << rp->GetPHOSMod() << " CPV ";
1073 rp->GetLocalPosition(locpos);
1074 cout << setw(6) << locpos.X() << " ";
1075 cout << setw(6) << locpos.Y() << " ";
1076 cout << setw(6) << locpos.Z() << " ";
1080 primaries = rp->GetPrimaries(nprimaries);
1081 cout << setw(6) << nprimaries << " ";
1083 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1084 cout << setw(4) << primaries[iprimary] << " ";
1089 cout << "-----------------------------------------------------------------------"<<endl ;