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 "AliPHOSGetter.h"
84 ClassImp(AliPHOSClusterizerv1)
86 //____________________________________________________________________________
87 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
89 // default ctor (to be used mainly by Streamer)
91 fNumberOfCpvClusters = 0 ;
92 fNumberOfEmcClusters = 0 ;
94 fCpvClusteringThreshold = 0.0;
95 fEmcClusteringThreshold = 0.2;
97 fEmcLocMaxCut = 0.03 ;
98 fCpvLocMaxCut = 0.03 ;
103 fEmcTimeGate = 1.e-8 ;
107 fHeaderFileName = "" ;
108 fDigitsBranchTitle = "" ;
109 fRecPointsInRun = 0 ;
112 //____________________________________________________________________________
113 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const char* headerFile,const char* name)
114 :AliPHOSClusterizer(headerFile, name)
116 // ctor with the indication of the file where header Tree and digits Tree are stored
119 fNumberOfCpvClusters = 0 ;
120 fNumberOfEmcClusters = 0 ;
122 fCpvClusteringThreshold = 0.0;
123 fEmcClusteringThreshold = 0.2;
125 fEmcLocMaxCut = 0.03 ;
126 fCpvLocMaxCut = 0.03 ;
131 fEmcTimeGate = 1.e-8 ;
135 fHeaderFileName = GetTitle() ;
136 fDigitsBranchTitle = GetName() ;
138 TString clusterizerName( GetName()) ;
139 clusterizerName.Append(":") ;
140 clusterizerName.Append(Version()) ;
141 SetName(clusterizerName) ;
142 fRecPointsInRun = 0 ;
147 //____________________________________________________________________________
148 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
151 //____________________________________________________________________________
152 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
154 if(absId <= fEmcCrystals) //calibrate as EMC
155 return fADCpedestalEmc + amp*fADCchanelEmc ;
156 else //Digitize as CPV
157 return fADCpedestalCpv+ amp*fADCchanelCpv ;
159 //____________________________________________________________________________
160 void AliPHOSClusterizerv1::Exec(Option_t * option)
164 if( strcmp(GetName(), "")== 0 )
167 if(strstr(option,"tim"))
168 gBenchmark->Start("PHOSClusterizer");
170 if(strstr(option,"print"))
173 gAlice->GetEvent(0) ;
175 //check, if the branch with name of this" already exits?
176 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
178 TBranch * branch = 0 ;
179 Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ;
181 TString branchname = GetName() ;
182 branchname.Remove(branchname.Index(Version())-1) ;
184 while ( (branch = (TBranch*)next()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) {
185 if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
186 phosemcfound = kTRUE ;
188 else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
189 phoscpvfound = kTRUE ;
191 else if ((strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
192 clusterizerfound = kTRUE ;
195 if ( phoscpvfound || phosemcfound || clusterizerfound ) {
196 cerr << "WARNING: AliPHOSClusterizer::Exec -> Emc(Cpv)RecPoints and/or Clusterizer branch with name "
197 << branchname.Data() << " already exits" << endl ;
201 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
202 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
205 for(ievent = 0; ievent < nevents; ievent++){
207 if(ievent == 0) GetCalibrationParameters() ;
209 fNumberOfEmcClusters = 0 ;
210 fNumberOfCpvClusters = 0 ;
212 gime->Event(ievent,"D") ;
214 // if(!ReadDigits(ievent)) continue; //reads digits for event ievent
218 if(fToUnfold) MakeUnfolding() ;
220 WriteRecPoints(ievent) ;
222 if(strstr(option,"deb")) PrintRecPoints(option) ;
225 if(strstr(option,"tim")){
226 gBenchmark->Stop("PHOSClusterizer");
227 cout << "AliPHOSClusterizer:" << endl ;
228 cout << " took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing "
229 << gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
235 //____________________________________________________________________________
236 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
237 Int_t nPar, Float_t * fitparameters) const
239 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
240 // The initial values for fitting procedure are set equal to the positions of local maxima.
241 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
243 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
244 TClonesArray * digits = gime->Digits() ;
247 gMinuit->mncler(); // Reset Minuit's list of paramters
248 gMinuit->SetPrintLevel(-1) ; // No Printout
249 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
250 // To set the address of the minimization function
252 TList * toMinuit = new TList();
253 toMinuit->AddAt(emcRP,0) ;
254 toMinuit->AddAt(digits,1) ;
256 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
258 // filling initial values for fit parameters
259 AliPHOSDigit * digit ;
263 Int_t nDigits = (Int_t) nPar / 3 ;
267 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
269 for(iDigit = 0; iDigit < nDigits; iDigit++){
270 digit = (AliPHOSDigit *) maxAt[iDigit];
275 geom->AbsToRelNumbering(digit->GetId(), relid) ;
276 geom->RelPosInModule(relid, x, z) ;
278 Float_t energy = maxAtEnergy[iDigit] ;
280 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
283 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
286 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
289 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
292 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
295 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
300 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
305 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
306 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
307 gMinuit->SetMaxIterations(5);
308 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
310 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
312 if(ierflg == 4){ // Minimum not found
313 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
316 for(index = 0; index < nPar; index++){
319 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
320 fitparameters[index] = val ;
328 //____________________________________________________________________________
329 void AliPHOSClusterizerv1::GetCalibrationParameters()
331 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
332 TString branchname = GetName() ;
333 branchname.Remove(branchname.Index(Version())-1) ;
334 AliPHOSDigitizer * dig = gime->Digitizer(branchname) ;
335 fADCchanelEmc = dig->GetEMCchannel() ;
336 fADCpedestalEmc = dig->GetEMCpedestal();
338 fADCchanelCpv = dig->GetCPVchannel() ;
339 fADCpedestalCpv = dig->GetCPVpedestal() ;
342 //____________________________________________________________________________
343 void AliPHOSClusterizerv1::Init()
345 // Make all memory allocations which can not be done in default constructor.
346 // Attach the Clusterizer task to the list of PHOS tasks
348 if ( strcmp(GetTitle(), "") == 0 )
349 SetTitle("galice.root") ;
351 TString branchname = GetName() ;
352 branchname.Remove(branchname.Index(Version())-1) ;
354 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), branchname) ;
356 cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ;
360 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
361 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
364 gMinuit = new TMinuit(100) ;
366 gime->PostClusterizer(this) ;
367 // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/recpointsName
368 gime->PostRecPoints(branchname ) ;
370 gime->PostDigits(branchname) ;
371 gime->PostDigitizer(branchname) ;
375 //____________________________________________________________________________
376 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
378 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
380 // = 2 are not neighbour but do not continue searching
381 // neighbours are defined as digits having at least a common vertex
382 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
383 // which is compared to a digit (d2) not yet in a cluster
385 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
390 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
393 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
395 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
396 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
397 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
399 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
400 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
404 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
405 rv = 2; // Difference in row numbers is too large to look further
411 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
420 //____________________________________________________________________________
421 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
423 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
426 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
429 geom->AbsToRelNumbering(digit->GetId(), relid) ;
431 if ( relid[1] == 0 ) rv = kTRUE;
436 //____________________________________________________________________________
437 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
439 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
442 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
445 geom->AbsToRelNumbering(digit->GetId(), relid) ;
447 if ( relid[1] != 0 ) rv = kTRUE;
452 //____________________________________________________________________________
453 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
456 // Creates new branches with given title
457 // fills and writes into TreeR.
459 TString branchName(GetName() ) ;
460 branchName.Remove(branchName.Index(Version())-1) ;
462 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
463 TObjArray * emcRecPoints = gime->EmcRecPoints(branchName) ;
464 TObjArray * cpvRecPoints = gime->CpvRecPoints(branchName) ;
465 TClonesArray * digits = gime->Digits(branchName) ;
468 //Evaluate position, dispersion and other RecPoint properties...
469 for(index = 0; index < emcRecPoints->GetEntries(); index++)
470 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ;
472 emcRecPoints->Sort() ;
474 for(index = 0; index < emcRecPoints->GetEntries(); index++)
475 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
477 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
479 //Now the same for CPV
480 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
481 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ;
483 cpvRecPoints->Sort() ;
485 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
486 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
488 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
490 //Make branches in TreeR for RecPoints and Clusterizer
492 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
493 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
494 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
498 TDirectory *cwd = gDirectory;
501 Int_t bufferSize = 32000 ;
502 Int_t splitlevel = 0 ;
505 TBranch * emcBranch = gAlice->TreeR()->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
506 emcBranch->SetTitle(branchName);
508 emcBranch->SetFile(filename);
509 TIter next( emcBranch->GetListOfBranches());
511 while ((sb=(TBranch*)next())) {
512 sb->SetFile(filename);
519 TBranch * cpvBranch = gAlice->TreeR()->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
520 cpvBranch->SetTitle(branchName);
522 cpvBranch->SetFile(filename);
523 TIter next( cpvBranch->GetListOfBranches());
525 while ((sb=(TBranch*)next())) {
526 sb->SetFile(filename);
531 //And Finally clusterizer branch
532 AliPHOSClusterizerv1 * cl = (AliPHOSClusterizerv1*)gime->Clusterizer(branchName) ;
533 TBranch * clusterizerBranch = gAlice->TreeR()->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1",
534 &cl,bufferSize,splitlevel);
535 clusterizerBranch->SetTitle(branchName);
537 clusterizerBranch->SetFile(filename);
538 TIter next( clusterizerBranch->GetListOfBranches());
540 while ((sb=(TBranch*)next())) {
541 sb->SetFile(filename);
547 clusterizerBranch->Fill() ;
549 gAlice->TreeR()->Write(0,kOverwrite) ;
553 //____________________________________________________________________________
554 void AliPHOSClusterizerv1::MakeClusters()
556 // Steering method to construct the clusters stored in a list of Reconstructed Points
557 // A cluster is defined as a list of neighbour digits
558 TString branchName(GetName()) ;
559 branchName.Remove(branchName.Index(Version())-1) ;
561 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
563 TObjArray * emcRecPoints = gime->EmcRecPoints(branchName) ;
564 TObjArray * cpvRecPoints = gime->CpvRecPoints(branchName) ;
565 emcRecPoints->Delete() ;
566 cpvRecPoints->Delete() ;
568 TClonesArray * digits = gime->Digits(branchName) ;
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() ;
678 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
679 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
680 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
681 TClonesArray * digits = gime->Digits() ;
683 // Unfold first EMC clusters
684 if(fNumberOfEmcClusters > 0){
686 Int_t nModulesToUnfold = geom->GetNModules() ;
688 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
690 for(index = 0 ; index < numberofNotUnfolded ; index++){
692 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
693 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
696 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
697 Int_t * maxAt = new Int_t[nMultipl] ;
698 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
699 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
701 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
702 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
703 emcRecPoints->Remove(emcRecPoint);
704 emcRecPoints->Compress() ;
706 fNumberOfEmcClusters -- ;
707 numberofNotUnfolded-- ;
711 delete[] maxAtEnergy ;
714 // Unfolding of EMC clusters finished
717 // Unfold now CPV clusters
718 if(fNumberOfCpvClusters > 0){
720 Int_t nModulesToUnfold = geom->GetNModules() ;
722 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
724 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
726 AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
728 if(recPoint->GetPHOSMod()> nModulesToUnfold)
731 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ;
733 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
734 Int_t * maxAt = new Int_t[nMultipl] ;
735 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
736 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
738 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
739 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
740 cpvRecPoints->Remove(emcRecPoint);
741 cpvRecPoints->Compress() ;
743 numberofCpvNotUnfolded-- ;
744 fNumberOfCpvClusters-- ;
748 delete[] maxAtEnergy ;
751 //Unfolding of Cpv clusters finished
755 //____________________________________________________________________________
756 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
758 // Shape of the shower (see PHOS TDR)
759 // If you change this function, change also the gradient evaluation in ChiSquare()
761 Double_t r4 = r*r*r*r ;
762 Double_t r295 = TMath::Power(r, 2.95) ;
763 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
767 //____________________________________________________________________________
768 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
771 Float_t * maxAtEnergy)
773 // Performs the unfolding of a cluster with nMax overlapping showers
775 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
776 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
777 TClonesArray * digits = gime->Digits() ;
778 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
779 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
781 Int_t nPar = 3 * nMax ;
782 Float_t * fitparameters = new Float_t[nPar] ;
784 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
786 // Fit failed, return and remove cluster
787 delete[] fitparameters ;
791 // create ufolded rec points and fill them with new energy lists
792 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
793 // and later correct this number in acordance with actual energy deposition
795 Int_t nDigits = iniEmc->GetMultiplicity() ;
796 Float_t * efit = new Float_t[nDigits] ;
797 Float_t xDigit=0.,zDigit=0.,distance=0. ;
798 Float_t xpar=0.,zpar=0.,epar=0. ;
800 AliPHOSDigit * digit = 0 ;
801 Int_t * emcDigits = iniEmc->GetDigitsList() ;
805 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
806 digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;
807 geom->AbsToRelNumbering(digit->GetId(), relid) ;
808 geom->RelPosInModule(relid, xDigit, zDigit) ;
812 while(iparam < nPar ){
813 xpar = fitparameters[iparam] ;
814 zpar = fitparameters[iparam+1] ;
815 epar = fitparameters[iparam+2] ;
817 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
818 distance = TMath::Sqrt(distance) ;
819 efit[iDigit] += epar * ShowerShape(distance) ;
824 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
825 // so that energy deposited in each cell is distributed betwin new clusters proportionally
826 // to its contribution to efit
828 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
832 while(iparam < nPar ){
833 xpar = fitparameters[iparam] ;
834 zpar = fitparameters[iparam+1] ;
835 epar = fitparameters[iparam+2] ;
838 AliPHOSEmcRecPoint * emcRP = 0 ;
840 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
842 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
843 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
845 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint() ;
846 emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
847 fNumberOfEmcClusters++ ;
849 else{//create new entries in fCpvRecPoints
850 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
851 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
853 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint() ;
854 emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
855 fNumberOfCpvClusters++ ;
859 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
860 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
861 geom->AbsToRelNumbering(digit->GetId(), relid) ;
862 geom->RelPosInModule(relid, xDigit, zDigit) ;
863 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
864 distance = TMath::Sqrt(distance) ;
865 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
866 eDigit = emcEnergies[iDigit] * ratio ;
867 emcRP->AddDigit( *digit, eDigit ) ;
871 delete[] fitparameters ;
876 //_____________________________________________________________________________
877 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
879 // Calculates the Chi square for the cluster unfolding minimization
880 // Number of parameters, Gradient, Chi squared, parameters, what to do
883 TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
885 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ;
886 TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ;
890 // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
892 Int_t * emcDigits = emcRP->GetDigitsList() ;
894 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
896 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
898 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
903 for(iparam = 0 ; iparam < nPar ; iparam++)
904 Grad[iparam] = 0 ; // Will evaluate gradient
908 AliPHOSDigit * digit ;
911 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
913 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
919 geom->AbsToRelNumbering(digit->GetId(), relid) ;
921 geom->RelPosInModule(relid, xDigit, zDigit) ;
923 if(iflag == 2){ // calculate gradient
926 while(iParam < nPar ){
927 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
929 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
930 distance = TMath::Sqrt( distance ) ;
932 efit += x[iParam] * ShowerShape(distance) ;
935 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
937 while(iParam < nPar ){
938 Double_t xpar = x[iParam] ;
939 Double_t zpar = x[iParam+1] ;
940 Double_t epar = x[iParam+2] ;
941 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
942 Double_t shape = sum * ShowerShape(dr) ;
943 Double_t r4 = dr*dr*dr*dr ;
944 Double_t r295 = TMath::Power(dr,2.95) ;
945 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
946 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
948 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
950 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
952 Grad[iParam] += shape ; // Derivative over energy
959 while(iparam < nPar ){
960 Double_t xpar = x[iparam] ;
961 Double_t zpar = x[iparam+1] ;
962 Double_t epar = x[iparam+2] ;
964 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
965 distance = TMath::Sqrt(distance) ;
966 efit += epar * ShowerShape(distance) ;
969 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
970 // Here we assume, that sigma = sqrt(E)
975 //____________________________________________________________________________
976 void AliPHOSClusterizerv1::Print(Option_t * option)const
978 // Print clusterizer parameters
980 if( strcmp(GetName(), "") !=0 ){
984 TString taskName(GetName()) ;
985 taskName.ReplaceAll(Version(), "") ;
987 cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl
988 << "Clusterizing digits from the file: " << fHeaderFileName.Data() << endl
989 << " Branch: " << fDigitsBranchTitle.Data() << endl
991 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
992 << " EMC Local Maximum cut = " << fEmcLocMaxCut << endl
993 << " EMC Logarothmic weight = " << fW0 << endl
995 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
996 << " CPV Local Maximum cut = " << fCpvLocMaxCut << endl
997 << " CPV Logarothmic weight = " << fW0CPV << endl
1000 cout << " Unfolding on " << endl ;
1002 cout << " Unfolding off " << endl ;
1004 cout << "------------------------------------------------------------------" <<endl ;
1007 cout << " AliPHOSClusterizerv1 not initialized " << endl ;
1009 //____________________________________________________________________________
1010 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1012 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1014 TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints() ;
1015 TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints() ;
1017 cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ;
1018 cout << " Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and "
1019 << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
1021 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1022 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1024 if(strstr(option,"all")) {
1025 cout << "EMC clusters " << endl ;
1026 cout << " Index Ene(MeV) Multi Module X Y Z Lambda 1 Lambda 2 # of prim Primaries list " << endl;
1029 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1030 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1032 rp->GetLocalPosition(locpos);
1034 rp->GetElipsAxis(lambda);
1037 primaries = rp->GetPrimaries(nprimaries);
1039 cout << setw(4) << rp->GetIndexInList() << " "
1040 << setw(7) << setprecision(3) << rp->GetEnergy() << " "
1041 << setw(3) << rp->GetMultiplicity() << " "
1042 << setw(1) << rp->GetPHOSMod() << " "
1043 << setw(6) << setprecision(2) << locpos.X() << " "
1044 << setw(6) << setprecision(2) << locpos.Y() << " "
1045 << setw(6) << setprecision(2) << locpos.Z() << " "
1046 << setw(4) << setprecision(2) << lambda[0] << " "
1047 << setw(4) << setprecision(2) << lambda[1] << " "
1048 << setw(2) << nprimaries << " " ;
1050 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1051 cout << setw(4) << primaries[iprimary] << " " ;
1055 //Now plot CPV recPoints
1056 cout << "EMC clusters " << endl ;
1064 << " Primaries list " << endl;
1066 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1067 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
1068 cout << setw(6) << rp->GetIndexInList() << " ";
1069 cout << setw(6) << rp->GetPHOSMod() << " CPV ";
1072 rp->GetLocalPosition(locpos);
1073 cout << setw(6) << locpos.X() << " ";
1074 cout << setw(6) << locpos.Y() << " ";
1075 cout << setw(6) << locpos.Z() << " ";
1079 primaries = rp->GetPrimaries(nprimaries);
1080 cout << setw(6) << nprimaries << " ";
1082 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1083 cout << setw(4) << primaries[iprimary] << " ";
1088 cout << "-----------------------------------------------------------------------"<<endl ;