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()
117 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
119 // remove the task from the folder list
120 gime->RemoveTask("C",GetName()) ;
122 // remove the data from the folder list
123 TString name(GetName()) ;
124 name.Remove(name.Index(":")) ;
125 gime->RemoveObjects("D", name) ; // Digits
126 gime->RemoveObjects("RE", name) ; // EMCARecPoints
127 gime->RemoveObjects("RC", name) ; // CPVRecPoints
134 //____________________________________________________________________________
135 const TString AliPHOSClusterizerv1::BranchName() const
137 TString branchName(GetName() ) ;
138 branchName.Remove(branchName.Index(Version())-1) ;
142 //____________________________________________________________________________
143 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
145 if(absId <= fEmcCrystals) //calibrate as EMC
146 return fADCpedestalEmc + amp*fADCchanelEmc ;
147 else //Digitize as CPV
148 return fADCpedestalCpv+ amp*fADCchanelCpv ;
150 //____________________________________________________________________________
151 void AliPHOSClusterizerv1::Exec(Option_t * option)
155 if( strcmp(GetName(), "")== 0 )
158 if(strstr(option,"tim"))
159 gBenchmark->Start("PHOSClusterizer");
161 if(strstr(option,"print"))
164 gAlice->GetEvent(0) ;
166 //check, if the branch with name of this" already exits?
167 if(gAlice->TreeR()) {
168 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
170 TBranch * branch = 0 ;
171 Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ;
173 TString branchname = GetName() ;
174 branchname.Remove(branchname.Index(Version())-1) ;
176 while ( (branch = (TBranch*)next()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) {
177 if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
178 phosemcfound = kTRUE ;
180 else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
181 phoscpvfound = kTRUE ;
183 else if ((strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
184 clusterizerfound = kTRUE ;
187 if ( phoscpvfound || phosemcfound || clusterizerfound ) {
188 cerr << "WARNING: AliPHOSClusterizer::Exec -> Emc(Cpv)RecPoints and/or Clusterizer branch with name "
189 << branchname.Data() << " already exits" << endl ;
194 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
195 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
198 for(ievent = 0; ievent < nevents; ievent++){
200 if(ievent == 0) GetCalibrationParameters() ;
202 fNumberOfEmcClusters = 0 ;
203 fNumberOfCpvClusters = 0 ;
205 gime->Event(ievent,"D") ;
207 // if(!ReadDigits(ievent)) continue; //reads digits for event ievent
214 WriteRecPoints(ievent) ;
216 if(strstr(option,"deb"))
217 PrintRecPoints(option) ;
219 //increment the total number of digits per run
220 fRecPointsInRun += gime->EmcRecPoints(BranchName())->GetEntriesFast() ;
221 fRecPointsInRun += gime->CpvRecPoints(BranchName())->GetEntriesFast() ;
224 if(strstr(option,"tim")){
225 gBenchmark->Stop("PHOSClusterizer");
226 cout << "AliPHOSClusterizer:" << endl ;
227 cout << " took " << gBenchmark->GetCpuTime("PHOSClusterizer") << " seconds for Clusterizing "
228 << gBenchmark->GetCpuTime("PHOSClusterizer")/nevents << " seconds per event " << endl ;
234 //____________________________________________________________________________
235 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
236 Int_t nPar, Float_t * fitparameters) const
238 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
239 // The initial values for fitting procedure are set equal to the positions of local maxima.
240 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
242 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
243 TClonesArray * digits = gime->Digits(fFrom) ;
246 gMinuit->mncler(); // Reset Minuit's list of paramters
247 gMinuit->SetPrintLevel(-1) ; // No Printout
248 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
249 // To set the address of the minimization function
251 TList * toMinuit = new TList();
252 toMinuit->AddAt(emcRP,0) ;
253 toMinuit->AddAt(digits,1) ;
255 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
257 // filling initial values for fit parameters
258 AliPHOSDigit * digit ;
262 Int_t nDigits = (Int_t) nPar / 3 ;
266 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
268 for(iDigit = 0; iDigit < nDigits; iDigit++){
269 digit = maxAt[iDigit];
274 geom->AbsToRelNumbering(digit->GetId(), relid) ;
275 geom->RelPosInModule(relid, x, z) ;
277 Float_t energy = maxAtEnergy[iDigit] ;
279 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
282 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
285 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
288 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
291 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
294 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
299 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
304 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
305 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
306 gMinuit->SetMaxIterations(5);
307 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
309 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
311 if(ierflg == 4){ // Minimum not found
312 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
315 for(index = 0; index < nPar; index++){
318 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
319 fitparameters[index] = val ;
327 //____________________________________________________________________________
328 void AliPHOSClusterizerv1::GetCalibrationParameters()
330 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
331 TString branchname = GetName() ;
332 branchname.Remove(branchname.Index(Version())-1) ;
333 AliPHOSDigitizer * dig = gime->Digitizer(fFrom) ;
334 fADCchanelEmc = dig->GetEMCchannel() ;
335 fADCpedestalEmc = dig->GetEMCpedestal();
337 fADCchanelCpv = dig->GetCPVchannel() ;
338 fADCpedestalCpv = dig->GetCPVpedestal() ;
341 //____________________________________________________________________________
342 void AliPHOSClusterizerv1::Init()
344 // Make all memory allocations which can not be done in default constructor.
345 // Attach the Clusterizer task to the list of PHOS tasks
347 if ( strcmp(GetTitle(), "") == 0 )
348 SetTitle("galice.root") ;
350 TString branchname = GetName() ;
351 branchname.Remove(branchname.Index(Version())-1) ;
353 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), fFrom.Data()) ;
355 cerr << "ERROR: AliPHOSClusterizerv1::Init -> Could not obtain the Getter object !" << endl ;
359 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
360 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
363 gMinuit = new TMinuit(100) ;
364 gime->PostClusterizer(this) ;
365 // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/recpointsName
366 gime->PostRecPoints(branchname) ;
368 gime->PostDigits(fFrom) ;
369 gime->PostDigitizer(fFrom) ;
373 //____________________________________________________________________________
374 void AliPHOSClusterizerv1::InitParameters()
377 fNumberOfCpvClusters = 0 ;
378 fNumberOfEmcClusters = 0 ;
380 fCpvClusteringThreshold = 0.0;
381 fEmcClusteringThreshold = 0.2;
383 fEmcLocMaxCut = 0.03 ;
384 fCpvLocMaxCut = 0.03 ;
389 fEmcTimeGate = 1.e-8 ;
393 fHeaderFileName = GetTitle() ;
394 fDigitsBranchTitle = GetName() ;
396 TString clusterizerName( GetName()) ;
397 if (clusterizerName.IsNull() )
398 clusterizerName = "Default" ;
399 clusterizerName.Append(":") ;
400 clusterizerName.Append(Version()) ;
401 SetName(clusterizerName) ;
402 fRecPointsInRun = 0 ;
406 //____________________________________________________________________________
407 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
409 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
411 // = 2 are not neighbour but do not continue searching
412 // neighbours are defined as digits having at least a common vertex
413 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
414 // which is compared to a digit (d2) not yet in a cluster
416 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
421 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
424 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
426 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
427 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
428 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
430 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
431 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
435 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
436 rv = 2; // Difference in row numbers is too large to look further
442 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
451 //____________________________________________________________________________
452 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
454 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
457 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
459 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
461 if(digit->GetId() <= nEMC ) rv = kTRUE;
466 //____________________________________________________________________________
467 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
469 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
472 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
474 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
476 if(digit->GetId() > nEMC ) rv = kTRUE;
481 //____________________________________________________________________________
482 void AliPHOSClusterizerv1::WriteRecPoints(Int_t event)
485 // Creates new branches with given title
486 // fills and writes into TreeR.
489 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
490 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
491 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
492 TClonesArray * digits = gime->Digits(fFrom) ;
493 TTree * treeR = gAlice->TreeR();
495 if (!gAlice->TreeR() )
496 gAlice->MakeTree("R", fSplitFile);
497 treeR = gAlice->TreeR() ;
500 //Evaluate position, dispersion and other RecPoint properties...
501 for(index = 0; index < emcRecPoints->GetEntries(); index++)
502 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->EvalAll(fW0,digits) ;
504 emcRecPoints->Sort() ;
505 for(index = 0; index < emcRecPoints->GetEntries(); index++)
506 ((AliPHOSEmcRecPoint *)emcRecPoints->At(index))->SetIndexInList(index) ;
508 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
510 //Now the same for CPV
511 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
512 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->EvalAll(fW0CPV,digits) ;
514 cpvRecPoints->Sort() ;
516 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
517 ((AliPHOSRecPoint *)cpvRecPoints->At(index))->SetIndexInList(index) ;
519 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
521 Int_t bufferSize = 32000 ;
522 Int_t splitlevel = 0 ;
525 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
526 emcBranch->SetTitle(BranchName());
529 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
530 cpvBranch->SetTitle(BranchName());
532 //And Finally clusterizer branch
533 AliPHOSClusterizerv1 * cl = this ;
534 TBranch * clusterizerBranch = treeR->Branch("AliPHOSClusterizer","AliPHOSClusterizerv1",
535 &cl,bufferSize,splitlevel);
536 clusterizerBranch->SetTitle(BranchName());
540 clusterizerBranch->Fill() ;
542 treeR->AutoSave() ; //Write(0,kOverwrite) ;
546 //____________________________________________________________________________
547 void AliPHOSClusterizerv1::MakeClusters()
549 // Steering method to construct the clusters stored in a list of Reconstructed Points
550 // A cluster is defined as a list of neighbour digits
552 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
554 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
555 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
556 emcRecPoints->Delete() ;
557 cpvRecPoints->Delete() ;
559 TClonesArray * digits = gime->Digits(fFrom) ;
561 cerr << "ERROR: AliPHOSClusterizerv1::MakeClusters -> Digits with name "
562 << fFrom << " not found ! " << endl ;
565 TClonesArray * digitsC = (TClonesArray*)digits->Clone() ;
568 // Clusterization starts
570 TIter nextdigit(digitsC) ;
571 AliPHOSDigit * digit ;
572 Bool_t notremoved = kTRUE ;
574 while ( (digit = (AliPHOSDigit *)nextdigit()) ) { // scan over the list of digitsC
575 AliPHOSRecPoint * clu = 0 ;
577 TArrayI clusterdigitslist(1500) ;
580 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
581 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
583 Int_t iDigitInCluster = 0 ;
585 if ( IsInEmc(digit) ) {
586 // start a new EMC RecPoint
587 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
588 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
590 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
591 clu = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters) ;
592 fNumberOfEmcClusters++ ;
593 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
594 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
596 digitsC->Remove(digit) ;
600 // start a new CPV cluster
601 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
602 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
604 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
606 clu = (AliPHOSCpvRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters) ;
607 fNumberOfCpvClusters++ ;
608 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
609 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
611 digitsC->Remove(digit) ;
614 // Here we remove remaining EMC digits, which cannot make a cluster
617 while( ( digit = (AliPHOSDigit *)nextdigit() ) ) {
619 digitsC->Remove(digit) ;
623 notremoved = kFALSE ;
630 AliPHOSDigit * digitN ;
632 while (index < iDigitInCluster){ // scan over digits already in cluster
633 digit = (AliPHOSDigit*)digits->At(clusterdigitslist[index]) ;
635 while ( (digitN = (AliPHOSDigit *)nextdigit()) ) { // scan over the reduced list of digits
636 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
638 case 0 : // not a neighbour
640 case 1 : // are neighbours
641 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
642 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
644 digitsC->Remove(digitN) ;
646 case 2 : // too far from each other
655 } // loop over cluster
666 //____________________________________________________________________________
667 void AliPHOSClusterizerv1::MakeUnfolding()
669 // Unfolds clusters using the shape of an ElectroMagnetic shower
670 // Performs unfolding of all EMC/CPV clusters
672 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
675 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
676 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
677 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
678 TClonesArray * digits = gime->Digits(fFrom) ;
680 // Unfold first EMC clusters
681 if(fNumberOfEmcClusters > 0){
683 Int_t nModulesToUnfold = geom->GetNModules() ;
685 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
687 for(index = 0 ; index < numberofNotUnfolded ; index++){
689 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint *) emcRecPoints->At(index) ;
690 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
693 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
694 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
695 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
696 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
698 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
699 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
700 emcRecPoints->Remove(emcRecPoint);
701 emcRecPoints->Compress() ;
703 fNumberOfEmcClusters -- ;
704 numberofNotUnfolded-- ;
708 delete[] maxAtEnergy ;
711 // Unfolding of EMC clusters finished
714 // Unfold now CPV clusters
715 if(fNumberOfCpvClusters > 0){
717 Int_t nModulesToUnfold = geom->GetNModules() ;
719 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
721 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
723 AliPHOSRecPoint * recPoint = (AliPHOSRecPoint *) cpvRecPoints->At(index) ;
725 if(recPoint->GetPHOSMod()> nModulesToUnfold)
728 AliPHOSEmcRecPoint * emcRecPoint = (AliPHOSEmcRecPoint*) recPoint ;
730 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
731 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
732 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
733 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
735 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
736 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
737 cpvRecPoints->Remove(emcRecPoint);
738 cpvRecPoints->Compress() ;
740 numberofCpvNotUnfolded-- ;
741 fNumberOfCpvClusters-- ;
745 delete[] maxAtEnergy ;
748 //Unfolding of Cpv clusters finished
752 //____________________________________________________________________________
753 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
755 // Shape of the shower (see PHOS TDR)
756 // If you change this function, change also the gradient evaluation in ChiSquare()
758 Double_t r4 = r*r*r*r ;
759 Double_t r295 = TMath::Power(r, 2.95) ;
760 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
764 //____________________________________________________________________________
765 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
767 AliPHOSDigit ** maxAt,
768 Float_t * maxAtEnergy)
770 // Performs the unfolding of a cluster with nMax overlapping showers
772 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
774 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
775 const TClonesArray * digits = gime->Digits(fFrom) ;
776 TObjArray * emcRecPoints = gime->EmcRecPoints(BranchName()) ;
777 TObjArray * cpvRecPoints = gime->CpvRecPoints(BranchName()) ;
779 Int_t nPar = 3 * nMax ;
780 Float_t * fitparameters = new Float_t[nPar] ;
782 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
784 // Fit failed, return and remove cluster
785 delete[] fitparameters ;
789 // create ufolded rec points and fill them with new energy lists
790 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
791 // and later correct this number in acordance with actual energy deposition
793 Int_t nDigits = iniEmc->GetMultiplicity() ;
794 Float_t * efit = new Float_t[nDigits] ;
795 Float_t xDigit=0.,zDigit=0.,distance=0. ;
796 Float_t xpar=0.,zpar=0.,epar=0. ;
798 AliPHOSDigit * digit = 0 ;
799 Int_t * emcDigits = iniEmc->GetDigitsList() ;
803 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
804 digit = (AliPHOSDigit*) digits->At(emcDigits[iDigit] ) ;
805 geom->AbsToRelNumbering(digit->GetId(), relid) ;
806 geom->RelPosInModule(relid, xDigit, zDigit) ;
810 while(iparam < nPar ){
811 xpar = fitparameters[iparam] ;
812 zpar = fitparameters[iparam+1] ;
813 epar = fitparameters[iparam+2] ;
815 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
816 distance = TMath::Sqrt(distance) ;
817 efit[iDigit] += epar * ShowerShape(distance) ;
822 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
823 // so that energy deposited in each cell is distributed betwin new clusters proportionally
824 // to its contribution to efit
826 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
830 while(iparam < nPar ){
831 xpar = fitparameters[iparam] ;
832 zpar = fitparameters[iparam+1] ;
833 epar = fitparameters[iparam+2] ;
836 AliPHOSEmcRecPoint * emcRP = 0 ;
838 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
840 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
841 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
843 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
844 emcRP = (AliPHOSEmcRecPoint *) emcRecPoints->At(fNumberOfEmcClusters);
845 fNumberOfEmcClusters++ ;
847 else{//create new entries in fCpvRecPoints
848 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
849 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
851 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
852 emcRP = (AliPHOSEmcRecPoint *) cpvRecPoints->At(fNumberOfCpvClusters);
853 fNumberOfCpvClusters++ ;
857 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
858 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
859 geom->AbsToRelNumbering(digit->GetId(), relid) ;
860 geom->RelPosInModule(relid, xDigit, zDigit) ;
861 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
862 distance = TMath::Sqrt(distance) ;
863 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
864 eDigit = emcEnergies[iDigit] * ratio ;
865 emcRP->AddDigit( *digit, eDigit ) ;
869 delete[] fitparameters ;
874 //_____________________________________________________________________________
875 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
877 // Calculates the Chi square for the cluster unfolding minimization
878 // Number of parameters, Gradient, Chi squared, parameters, what to do
880 TList * toMinuit = (TList*) gMinuit->GetObjectFit() ;
882 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint*) toMinuit->At(0) ;
883 TClonesArray * digits = (TClonesArray*)toMinuit->At(1) ;
887 // AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
889 Int_t * emcDigits = emcRP->GetDigitsList() ;
891 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
893 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
895 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
900 for(iparam = 0 ; iparam < nPar ; iparam++)
901 Grad[iparam] = 0 ; // Will evaluate gradient
905 AliPHOSDigit * digit ;
908 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
910 digit = (AliPHOSDigit*) digits->At( emcDigits[iDigit] ) ;
916 geom->AbsToRelNumbering(digit->GetId(), relid) ;
918 geom->RelPosInModule(relid, xDigit, zDigit) ;
920 if(iflag == 2){ // calculate gradient
923 while(iParam < nPar ){
924 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
926 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
927 distance = TMath::Sqrt( distance ) ;
929 efit += x[iParam] * ShowerShape(distance) ;
932 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
934 while(iParam < nPar ){
935 Double_t xpar = x[iParam] ;
936 Double_t zpar = x[iParam+1] ;
937 Double_t epar = x[iParam+2] ;
938 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
939 Double_t shape = sum * ShowerShape(dr) ;
940 Double_t r4 = dr*dr*dr*dr ;
941 Double_t r295 = TMath::Power(dr,2.95) ;
942 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
943 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
945 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
947 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
949 Grad[iParam] += shape ; // Derivative over energy
956 while(iparam < nPar ){
957 Double_t xpar = x[iparam] ;
958 Double_t zpar = x[iparam+1] ;
959 Double_t epar = x[iparam+2] ;
961 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
962 distance = TMath::Sqrt(distance) ;
963 efit += epar * ShowerShape(distance) ;
966 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
967 // Here we assume, that sigma = sqrt(E)
972 //____________________________________________________________________________
973 void AliPHOSClusterizerv1::Print(Option_t * option)const
975 // Print clusterizer parameters
977 if( strcmp(GetName(), "") !=0 ){
981 TString taskName(GetName()) ;
982 taskName.ReplaceAll(Version(), "") ;
984 cout << "---------------"<< taskName.Data() << " " << GetTitle()<< "-----------" << endl
985 << "Clusterizing digits from the file: " << fHeaderFileName.Data() << endl
986 << " Branch: " << fDigitsBranchTitle.Data() << endl
988 << " EMC Clustering threshold = " << fEmcClusteringThreshold << endl
989 << " EMC Local Maximum cut = " << fEmcLocMaxCut << endl
990 << " EMC Logarothmic weight = " << fW0 << endl
992 << " CPV Clustering threshold = " << fCpvClusteringThreshold << endl
993 << " CPV Local Maximum cut = " << fCpvLocMaxCut << endl
994 << " CPV Logarothmic weight = " << fW0CPV << endl
997 cout << " Unfolding on " << endl ;
999 cout << " Unfolding off " << endl ;
1001 cout << "------------------------------------------------------------------" <<endl ;
1004 cout << " AliPHOSClusterizerv1 not initialized " << endl ;
1006 //____________________________________________________________________________
1007 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1009 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1011 TObjArray * emcRecPoints = AliPHOSGetter::GetInstance()->EmcRecPoints(BranchName()) ;
1012 TObjArray * cpvRecPoints = AliPHOSGetter::GetInstance()->CpvRecPoints(BranchName()) ;
1014 cout << "AliPHOSClusterizerv1: : event "<<gAlice->GetEvNumber() << endl ;
1015 cout << " Found "<< emcRecPoints->GetEntriesFast() << " EMC Rec Points and "
1016 << cpvRecPoints->GetEntriesFast() << " CPV RecPoints" << endl ;
1018 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1019 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1021 if(strstr(option,"all")) {
1022 cout << "EMC clusters " << endl ;
1023 cout << " Index Ene(MeV) Multi Module X Y Z Lambda 1 Lambda 2 # of prim Primaries list " << endl;
1026 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1027 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1029 rp->GetLocalPosition(locpos);
1031 rp->GetElipsAxis(lambda);
1034 primaries = rp->GetPrimaries(nprimaries);
1036 cout << setw(4) << rp->GetIndexInList() << " "
1037 << setw(7) << setprecision(3) << rp->GetEnergy() << " "
1038 << setw(3) << rp->GetMultiplicity() << " "
1039 << setw(1) << rp->GetPHOSMod() << " "
1040 << setw(6) << setprecision(2) << locpos.X() << " "
1041 << setw(6) << setprecision(2) << locpos.Y() << " "
1042 << setw(6) << setprecision(2) << locpos.Z() << " "
1043 << setw(4) << setprecision(2) << lambda[0] << " "
1044 << setw(4) << setprecision(2) << lambda[1] << " "
1045 << setw(2) << nprimaries << " " ;
1047 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1048 cout << setw(4) << primaries[iprimary] << " " ;
1052 //Now plot CPV recPoints
1053 cout << "EMC clusters " << endl ;
1061 << " Primaries list " << endl;
1063 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1064 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
1065 cout << setw(6) << rp->GetIndexInList() << " ";
1066 cout << setw(6) << rp->GetPHOSMod() << " CPV ";
1069 rp->GetLocalPosition(locpos);
1070 cout << setw(6) << locpos.X() << " ";
1071 cout << setw(6) << locpos.Y() << " ";
1072 cout << setw(6) << locpos.Z() << " ";
1076 primaries = rp->GetPrimaries(nprimaries);
1077 cout << setw(6) << nprimaries << " ";
1079 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
1080 cout << setw(4) << primaries[iprimary] << " ";
1085 cout << "-----------------------------------------------------------------------"<<endl ;