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 **************************************************************************/
18 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
19 //////////////////////////////////////////////////////////////////////////////
20 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
21 // unfolds the clusters having several local maxima.
22 // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
23 // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
24 // parameters including input digits branch title, thresholds etc.)
25 // This TTask is normally called from Reconstructioner, but can as well be used in
28 // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
29 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
30 // // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
31 // // and saves recpoints in branch named "recpointsname" (default = "digitsname")
32 // root [1] cl->ExecuteTask()
33 // //finds RecPoints in all events stored in galice.root
34 // root [2] cl->SetDigitsBranch("digits2")
35 // //sets another title for Digitis (input) branch
36 // root [3] cl->SetRecPointsBranch("recp2")
37 // //sets another title four output branches
38 // root [4] cl->SetEmcLocalMaxCut(0.03)
39 // //set clusterization parameters
40 // root [5] cl->ExecuteTask("deb all time")
41 // //once more finds RecPoints options are
42 // // deb - print number of found rec points
43 // // deb all - print number of found RecPoints and some their characteristics
44 // // time - print benchmarking results
46 // --- ROOT system ---
51 #include "TBenchmark.h"
53 // --- Standard library ---
55 // --- AliRoot header files ---
57 #include "AliPHOSGetter.h"
58 #include "AliPHOSGeometry.h"
59 #include "AliPHOSClusterizerv1.h"
60 #include "AliPHOSEmcRecPoint.h"
61 #include "AliPHOSCpvRecPoint.h"
62 #include "AliPHOSDigit.h"
63 #include "AliPHOSDigitizer.h"
64 #include "AliPHOSCalibrationDB.h"
66 ClassImp(AliPHOSClusterizerv1)
68 //____________________________________________________________________________
69 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
71 // default ctor (to be used mainly by Streamer)
74 fDefaultInit = kTRUE ;
77 //____________________________________________________________________________
78 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const TString alirunFileName, const TString eventFolderName)
79 :AliPHOSClusterizer(alirunFileName, eventFolderName)
81 // ctor with the indication of the file where header Tree and digits Tree are stored
85 fDefaultInit = kFALSE ;
88 //____________________________________________________________________________
89 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
94 //____________________________________________________________________________
95 const TString AliPHOSClusterizerv1::BranchName() const
100 //____________________________________________________________________________
101 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
103 //To be replaced later by the method, reading individual parameters from the database
105 return fCalibrationDB->Calibrate(amp,absId) ;
108 if(absId <= fEmcCrystals) //calibrate as EMC
109 return fADCpedestalEmc + amp*fADCchanelEmc ;
110 else //calibrate as CPV
111 return fADCpedestalCpv+ amp*fADCchanelCpv ;
115 //____________________________________________________________________________
116 void AliPHOSClusterizerv1::Exec(Option_t *option)
118 // Steering method to perform clusterization for events
119 // in the range from fFirstEvent to fLastEvent.
120 // This range is optionally set by SetEventRange().
121 // if fLastEvent=-1 (by default), then process events until the end.
123 if(strstr(option,"tim"))
124 gBenchmark->Start("PHOSClusterizer");
126 if(strstr(option,"print")) {
131 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
132 GetCalibrationParameters() ;
134 if (fLastEvent == -1)
135 fLastEvent = gime->MaxEvent() - 1 ;
137 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // one event at the time
138 Int_t nEvents = fLastEvent - fFirstEvent + 1;
141 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
142 gime->Event(ievent, "D");
144 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
153 if(strstr(option,"deb"))
154 PrintRecPoints(option) ;
156 //increment the total number of recpoints per run
157 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
158 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
161 if(fWrite) //do not unload in "on flight" mode
164 if(strstr(option,"tim")){
165 gBenchmark->Stop("PHOSClusterizer");
166 AliInfo(Form("took %f seconds for Clusterizing %f seconds per event \n",
167 gBenchmark->GetCpuTime("PHOSClusterizer"),
168 gBenchmark->GetCpuTime("PHOSClusterizer")/nEvents )) ;
172 //____________________________________________________________________________
173 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
174 Int_t nPar, Float_t * fitparameters) const
176 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
177 // The initial values for fitting procedure are set equal to the positions of local maxima.
178 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
181 AliPHOSGetter * gime = AliPHOSGetter::Instance();
182 TClonesArray * digits = gime->Digits();
185 gMinuit->mncler(); // Reset Minuit's list of paramters
186 gMinuit->SetPrintLevel(-1) ; // No Printout
187 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
188 // To set the address of the minimization function
190 TList * toMinuit = new TList();
191 toMinuit->AddAt(emcRP,0) ;
192 toMinuit->AddAt(digits,1) ;
194 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
196 // filling initial values for fit parameters
197 AliPHOSDigit * digit ;
201 Int_t nDigits = (Int_t) nPar / 3 ;
205 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
207 for(iDigit = 0; iDigit < nDigits; iDigit++){
208 digit = maxAt[iDigit];
213 geom->AbsToRelNumbering(digit->GetId(), relid) ;
214 geom->RelPosInModule(relid, x, z) ;
216 Float_t energy = maxAtEnergy[iDigit] ;
218 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
221 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
224 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
227 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
230 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
233 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
238 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
243 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
244 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
245 gMinuit->SetMaxIterations(5);
246 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
248 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
250 if(ierflg == 4){ // Minimum not found
251 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
254 for(index = 0; index < nPar; index++){
257 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
258 fitparameters[index] = val ;
266 //____________________________________________________________________________
267 void AliPHOSClusterizerv1::GetCalibrationParameters()
270 AliPHOSGetter * gime = AliPHOSGetter::Instance();
271 if(gime->IsRawDigits()){
272 fCalibrationDB = gime->CalibrationDB();
275 if ( !gime->Digitizer() )
276 gime->LoadDigitizer();
277 AliPHOSDigitizer * dig = gime->Digitizer();
278 fADCchanelEmc = dig->GetEMCchannel() ;
279 fADCpedestalEmc = dig->GetEMCpedestal();
281 fADCchanelCpv = dig->GetCPVchannel() ;
282 fADCpedestalCpv = dig->GetCPVpedestal() ;
286 //____________________________________________________________________________
287 void AliPHOSClusterizerv1::Init()
289 // Make all memory allocations which can not be done in default constructor.
290 // Attach the Clusterizer task to the list of PHOS tasks
292 AliPHOSGetter* gime = AliPHOSGetter::Instance() ;
294 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
296 AliPHOSGeometry * geom = gime->PHOSGeometry();
298 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
301 gMinuit = new TMinuit(100);
303 if ( !gime->Clusterizer() ) {
304 gime->PostClusterizer(this);
308 //____________________________________________________________________________
309 void AliPHOSClusterizerv1::InitParameters()
312 fNumberOfCpvClusters = 0 ;
313 fNumberOfEmcClusters = 0 ;
315 fCpvClusteringThreshold = 0.0;
316 fEmcClusteringThreshold = 0.2;
318 fEmcLocMaxCut = 0.03 ;
319 fCpvLocMaxCut = 0.03 ;
327 fEmcTimeGate = 1.e-8 ;
331 fRecPointsInRun = 0 ;
337 SetEventRange(0,-1) ;
340 //____________________________________________________________________________
341 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
343 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
345 // = 2 are not neighbour but do not continue searching
346 // neighbours are defined as digits having at least a common vertex
347 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
348 // which is compared to a digit (d2) not yet in a cluster
350 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
355 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
358 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
360 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
361 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
362 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
364 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
365 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
369 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
370 rv = 2; // Difference in row numbers is too large to look further
376 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
383 //____________________________________________________________________________
384 void AliPHOSClusterizerv1::CleanDigits(TClonesArray * digits){
385 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
386 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
387 Float_t cut = IsInEmc(digit) ? fEmcMinE : fCpvMinE ;
388 if(Calibrate(digit->GetAmp(),digit->GetId()) < cut)
389 digits->RemoveAt(i) ;
392 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
393 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
394 digit->SetIndexInList(i) ;
398 //____________________________________________________________________________
399 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
401 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
404 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
406 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
408 if(digit->GetId() <= nEMC ) rv = kTRUE;
413 //____________________________________________________________________________
414 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
416 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
420 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
422 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
424 if(digit->GetId() > nEMC ) rv = kTRUE;
429 //____________________________________________________________________________
430 void AliPHOSClusterizerv1::Unload()
432 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
433 gime->PhosLoader()->UnloadDigits() ;
434 gime->PhosLoader()->UnloadRecPoints() ;
437 //____________________________________________________________________________
438 void AliPHOSClusterizerv1::WriteRecPoints()
441 // Creates new branches with given title
442 // fills and writes into TreeR.
444 AliPHOSGetter * gime = AliPHOSGetter::Instance();
446 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
447 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
448 TClonesArray * digits = gime->Digits() ;
452 //Evaluate position, dispersion and other RecPoint properties..
453 Int_t nEmc = emcRecPoints->GetEntriesFast();
454 for(index = 0; index < nEmc; index++){
455 AliPHOSEmcRecPoint * rp = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) );
456 rp->Purify(fEmcMinE) ;
457 if(rp->GetMultiplicity()>0.) //If this RP is not empty
458 rp->EvalAll(fW0,digits) ;
460 emcRecPoints->RemoveAt(index) ;
464 emcRecPoints->Compress() ;
465 emcRecPoints->Sort() ;
466 // emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
467 for(index = 0; index < emcRecPoints->GetEntries(); index++){
468 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
471 //Now the same for CPV
472 for(index = 0; index < cpvRecPoints->GetEntries(); index++){
473 AliPHOSCpvRecPoint * rp = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) );
474 rp->EvalAll(fW0CPV,digits) ;
476 cpvRecPoints->Sort() ;
478 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
479 dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
481 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
483 if(fWrite){ //We write TreeR
484 TTree * treeR = gime->TreeR();
486 Int_t bufferSize = 32000 ;
487 Int_t splitlevel = 0 ;
490 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
491 emcBranch->SetTitle(BranchName());
494 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
495 cpvBranch->SetTitle(BranchName());
500 gime->WriteRecPoints("OVERWRITE");
501 gime->WriteClusterizer("OVERWRITE");
505 //____________________________________________________________________________
506 void AliPHOSClusterizerv1::MakeClusters()
508 // Steering method to construct the clusters stored in a list of Reconstructed Points
509 // A cluster is defined as a list of neighbour digits
512 AliPHOSGetter * gime = AliPHOSGetter::Instance();
514 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
515 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
517 emcRecPoints->Delete() ;
518 cpvRecPoints->Delete() ;
520 TClonesArray * digits = gime->Digits() ;
522 //Remove digits below threshold
523 CleanDigits(digits) ;
526 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
529 // Clusterization starts
531 TIter nextdigit(digitsC) ;
532 AliPHOSDigit * digit ;
533 Bool_t notremoved = kTRUE ;
535 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
538 AliPHOSRecPoint * clu = 0 ;
540 TArrayI clusterdigitslist(1500) ;
543 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
544 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
545 Int_t iDigitInCluster = 0 ;
547 if ( IsInEmc(digit) ) {
548 // start a new EMC RecPoint
549 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
550 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
552 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
553 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
554 fNumberOfEmcClusters++ ;
555 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
556 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
558 digitsC->Remove(digit) ;
562 // start a new CPV cluster
563 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
564 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
566 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
568 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
569 fNumberOfCpvClusters++ ;
570 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
571 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
573 digitsC->Remove(digit) ;
576 // Here we remove remaining EMC digits, which cannot make a cluster
579 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
581 digitsC->Remove(digit) ;
585 notremoved = kFALSE ;
592 AliPHOSDigit * digitN ;
594 while (index < iDigitInCluster){ // scan over digits already in cluster
595 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
597 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
598 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
600 case 0 : // not a neighbour
602 case 1 : // are neighbours
603 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
604 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
606 digitsC->Remove(digitN) ;
608 case 2 : // too far from each other
617 } // loop over cluster
628 //____________________________________________________________________________
629 void AliPHOSClusterizerv1::MakeUnfolding()
631 // Unfolds clusters using the shape of an ElectroMagnetic shower
632 // Performs unfolding of all EMC/CPV clusters
634 AliPHOSGetter * gime = AliPHOSGetter::Instance();
636 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
638 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
639 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
640 TClonesArray * digits = gime->Digits() ;
642 // Unfold first EMC clusters
643 if(fNumberOfEmcClusters > 0){
645 Int_t nModulesToUnfold = geom->GetNModules() ;
647 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
649 for(index = 0 ; index < numberofNotUnfolded ; index++){
651 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
652 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
655 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
656 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
657 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
658 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
660 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
661 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
662 emcRecPoints->Remove(emcRecPoint);
663 emcRecPoints->Compress() ;
665 fNumberOfEmcClusters -- ;
666 numberofNotUnfolded-- ;
669 emcRecPoint->SetNExMax(1) ; //Only one local maximum
673 delete[] maxAtEnergy ;
676 // Unfolding of EMC clusters finished
679 // Unfold now CPV clusters
680 if(fNumberOfCpvClusters > 0){
682 Int_t nModulesToUnfold = geom->GetNModules() ;
684 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
686 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
688 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
690 if(recPoint->GetPHOSMod()> nModulesToUnfold)
693 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
695 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
696 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
697 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
698 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
700 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
701 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
702 cpvRecPoints->Remove(emcRecPoint);
703 cpvRecPoints->Compress() ;
705 numberofCpvNotUnfolded-- ;
706 fNumberOfCpvClusters-- ;
710 delete[] maxAtEnergy ;
713 //Unfolding of Cpv clusters finished
717 //____________________________________________________________________________
718 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
720 // Shape of the shower (see PHOS TDR)
721 // If you change this function, change also the gradient evaluation in ChiSquare()
723 Double_t r4 = r*r*r*r ;
724 Double_t r295 = TMath::Power(r, 2.95) ;
725 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
729 //____________________________________________________________________________
730 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
732 AliPHOSDigit ** maxAt,
733 Float_t * maxAtEnergy)
735 // Performs the unfolding of a cluster with nMax overlapping showers
737 AliPHOSGetter * gime = AliPHOSGetter::Instance();
739 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
741 const TClonesArray * digits = gime->Digits() ;
742 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
743 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
745 Int_t nPar = 3 * nMax ;
746 Float_t * fitparameters = new Float_t[nPar] ;
748 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
750 // Fit failed, return and remove cluster
751 iniEmc->SetNExMax(-1) ;
752 delete[] fitparameters ;
756 // create ufolded rec points and fill them with new energy lists
757 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
758 // and later correct this number in acordance with actual energy deposition
760 Int_t nDigits = iniEmc->GetMultiplicity() ;
761 Float_t * efit = new Float_t[nDigits] ;
762 Float_t xDigit=0.,zDigit=0.,distance=0. ;
763 Float_t xpar=0.,zpar=0.,epar=0. ;
765 AliPHOSDigit * digit = 0 ;
766 Int_t * emcDigits = iniEmc->GetDigitsList() ;
770 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
771 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
772 geom->AbsToRelNumbering(digit->GetId(), relid) ;
773 geom->RelPosInModule(relid, xDigit, zDigit) ;
777 while(iparam < nPar ){
778 xpar = fitparameters[iparam] ;
779 zpar = fitparameters[iparam+1] ;
780 epar = fitparameters[iparam+2] ;
782 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
783 distance = TMath::Sqrt(distance) ;
784 efit[iDigit] += epar * ShowerShape(distance) ;
789 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
790 // so that energy deposited in each cell is distributed betwin new clusters proportionally
791 // to its contribution to efit
793 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
797 while(iparam < nPar ){
798 xpar = fitparameters[iparam] ;
799 zpar = fitparameters[iparam+1] ;
800 epar = fitparameters[iparam+2] ;
803 AliPHOSEmcRecPoint * emcRP = 0 ;
805 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
807 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
808 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
810 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
811 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
812 fNumberOfEmcClusters++ ;
813 emcRP->SetNExMax((Int_t)nPar/3) ;
815 else{//create new entries in fCpvRecPoints
816 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
817 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
819 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
820 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
821 fNumberOfCpvClusters++ ;
825 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
826 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
827 geom->AbsToRelNumbering(digit->GetId(), relid) ;
828 geom->RelPosInModule(relid, xDigit, zDigit) ;
829 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
830 distance = TMath::Sqrt(distance) ;
831 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
832 eDigit = emcEnergies[iDigit] * ratio ;
833 emcRP->AddDigit( *digit, eDigit ) ;
837 delete[] fitparameters ;
842 //_____________________________________________________________________________
843 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
845 // Calculates the Chi square for the cluster unfolding minimization
846 // Number of parameters, Gradient, Chi squared, parameters, what to do
848 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
850 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
851 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
855 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
857 Int_t * emcDigits = emcRP->GetDigitsList() ;
859 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
861 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
863 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
868 for(iparam = 0 ; iparam < nPar ; iparam++)
869 Grad[iparam] = 0 ; // Will evaluate gradient
873 AliPHOSDigit * digit ;
876 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
878 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
884 geom->AbsToRelNumbering(digit->GetId(), relid) ;
886 geom->RelPosInModule(relid, xDigit, zDigit) ;
888 if(iflag == 2){ // calculate gradient
891 while(iParam < nPar ){
892 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
894 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
895 distance = TMath::Sqrt( distance ) ;
897 efit += x[iParam] * ShowerShape(distance) ;
900 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
902 while(iParam < nPar ){
903 Double_t xpar = x[iParam] ;
904 Double_t zpar = x[iParam+1] ;
905 Double_t epar = x[iParam+2] ;
906 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
907 Double_t shape = sum * ShowerShape(dr) ;
908 Double_t r4 = dr*dr*dr*dr ;
909 Double_t r295 = TMath::Power(dr,2.95) ;
910 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
911 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
913 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
915 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
917 Grad[iParam] += shape ; // Derivative over energy
924 while(iparam < nPar ){
925 Double_t xpar = x[iparam] ;
926 Double_t zpar = x[iparam+1] ;
927 Double_t epar = x[iparam+2] ;
929 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
930 distance = TMath::Sqrt(distance) ;
931 efit += epar * ShowerShape(distance) ;
934 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
935 // Here we assume, that sigma = sqrt(E)
940 //____________________________________________________________________________
941 void AliPHOSClusterizerv1::Print()const
943 // Print clusterizer parameters
946 TString taskName(GetName()) ;
947 taskName.ReplaceAll(Version(), "") ;
949 if( strcmp(GetName(), "") !=0 ) {
951 message = "\n--------------- %s %s -----------\n" ;
952 message += "Clusterizing digits from the file: %s\n" ;
953 message += " Branch: %s\n" ;
954 message += " EMC Clustering threshold = %f\n" ;
955 message += " EMC Local Maximum cut = %f\n" ;
956 message += " EMC Logarothmic weight = %f\n" ;
957 message += " CPV Clustering threshold = %f\n" ;
958 message += " CPV Local Maximum cut = %f\n" ;
959 message += " CPV Logarothmic weight = %f\n" ;
961 message += " Unfolding on\n" ;
963 message += " Unfolding off\n" ;
965 message += "------------------------------------------------------------------" ;
968 message = " AliPHOSClusterizerv1 not initialized " ;
970 AliInfo(Form("%s, %s %s %s %s %s %s %s %s %s %s", message.Data(),
975 fEmcClusteringThreshold,
978 fCpvClusteringThreshold,
984 //____________________________________________________________________________
985 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
987 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
989 AliPHOSGetter * gime = AliPHOSGetter::Instance();
991 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
992 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
994 AliInfo(Form("\nevent %d \n Found %d EMC RecPoints and %d CPV RecPoints",
995 gAlice->GetEvNumber(),
996 emcRecPoints->GetEntriesFast(),
997 cpvRecPoints->GetEntriesFast() )) ;
999 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1000 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1003 if(strstr(option,"all")) {
1004 printf("\n EMC clusters \n") ;
1005 printf("Index Ene(MeV) Multi Module X Y Z Lambdas_1 Lambda_2 # of prim Primaries list\n") ;
1007 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1008 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1010 rp->GetLocalPosition(locpos);
1012 rp->GetElipsAxis(lambda);
1015 primaries = rp->GetPrimaries(nprimaries);
1016 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
1017 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
1018 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
1020 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
1021 printf("%d ", primaries[iprimary] ) ;
1026 //Now plot CPV recPoints
1027 printf("\n CPV clusters \n") ;
1028 printf("Index Ene(MeV) Module X Y Z \n") ;
1029 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1030 AliPHOSCpvRecPoint * rp = (AliPHOSCpvRecPoint * )cpvRecPoints->At(index) ;
1033 rp->GetLocalPosition(locpos);
1035 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f \n",
1036 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
1037 locpos.X(), locpos.Y(), locpos.Z()) ;