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 /* History of cvs commits:
21 * Revision 1.82 2005/09/02 15:43:13 kharlov
22 * Add comments in GetCalibrationParameters and Calibrate
24 * Revision 1.81 2005/09/02 14:32:07 kharlov
25 * Calibration of raw data
27 * Revision 1.80 2005/08/24 15:31:36 kharlov
28 * Setting raw digits flag
30 * Revision 1.79 2005/07/25 15:53:53 kharlov
33 * Revision 1.78 2005/05/28 14:19:04 schutz
34 * Compilation warnings fixed by T.P.
38 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
39 //////////////////////////////////////////////////////////////////////////////
40 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
41 // unfolds the clusters having several local maxima.
42 // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
43 // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
44 // parameters including input digits branch title, thresholds etc.)
45 // This TTask is normally called from Reconstructioner, but can as well be used in
48 // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
49 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
50 // // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
51 // // and saves recpoints in branch named "recpointsname" (default = "digitsname")
52 // root [1] cl->ExecuteTask()
53 // //finds RecPoints in all events stored in galice.root
54 // root [2] cl->SetDigitsBranch("digits2")
55 // //sets another title for Digitis (input) branch
56 // root [3] cl->SetRecPointsBranch("recp2")
57 // //sets another title four output branches
58 // root [4] cl->SetEmcLocalMaxCut(0.03)
59 // //set clusterization parameters
60 // root [5] cl->ExecuteTask("deb all time")
61 // //once more finds RecPoints options are
62 // // deb - print number of found rec points
63 // // deb all - print number of found RecPoints and some their characteristics
64 // // time - print benchmarking results
66 // --- ROOT system ---
71 #include "TBenchmark.h"
73 // --- Standard library ---
75 // --- AliRoot header files ---
77 #include "AliPHOSGetter.h"
78 #include "AliPHOSGeometry.h"
79 #include "AliPHOSClusterizerv1.h"
80 #include "AliPHOSEmcRecPoint.h"
81 #include "AliPHOSCpvRecPoint.h"
82 #include "AliPHOSDigit.h"
83 #include "AliPHOSDigitizer.h"
84 #include "AliPHOSCalibrationDB.h"
86 ClassImp(AliPHOSClusterizerv1)
88 //____________________________________________________________________________
89 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
91 // default ctor (to be used mainly by Streamer)
94 fDefaultInit = kTRUE ;
97 //____________________________________________________________________________
98 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const TString alirunFileName, const TString eventFolderName)
99 :AliPHOSClusterizer(alirunFileName, eventFolderName)
101 // ctor with the indication of the file where header Tree and digits Tree are stored
105 fDefaultInit = kFALSE ;
108 //____________________________________________________________________________
109 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
114 //____________________________________________________________________________
115 const TString AliPHOSClusterizerv1::BranchName() const
120 //____________________________________________________________________________
121 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId)
123 // Convert digitized amplitude into energy.
124 // Calibration parameters are taken from calibration data base for raw data,
125 // or from digitizer parameters for simulated data.
129 AliPHOSGetter *gime = AliPHOSGetter::Instance();
130 gime->PHOSGeometry()->AbsToRelNumbering(absId,relId) ;
131 Int_t module = relId[0];
132 Int_t row = relId[2];
133 Int_t column = relId[3];
134 if(absId <= fEmcCrystals) { //calibrate as EMC
135 fADCchanelEmc = fCalibData->GetADCchannelEmc (module,column,row);
136 fADCpedestalEmc = fCalibData->GetADCpedestalEmc(module,column,row);
137 return fADCpedestalEmc + amp*fADCchanelEmc ;
139 else //calibrate as CPV, not implemented yet
143 if(absId <= fEmcCrystals) //calibrate as EMC
144 return fADCpedestalEmc + amp*fADCchanelEmc ;
145 else //calibrate as CPV
146 return fADCpedestalCpv+ amp*fADCchanelCpv ;
150 //____________________________________________________________________________
151 void AliPHOSClusterizerv1::Exec(Option_t *option)
153 // Steering method to perform clusterization for events
154 // in the range from fFirstEvent to fLastEvent.
155 // This range is optionally set by SetEventRange().
156 // if fLastEvent=-1 (by default), then process events until the end.
158 if(strstr(option,"tim"))
159 gBenchmark->Start("PHOSClusterizer");
161 if(strstr(option,"print")) {
166 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
168 gime->SetRawDigits(kFALSE);
170 gime->SetRawDigits(kTRUE);
171 GetCalibrationParameters() ;
173 if (fLastEvent == -1)
174 fLastEvent = gime->MaxEvent() - 1 ;
176 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // one event at the time
177 Int_t nEvents = fLastEvent - fFirstEvent + 1;
180 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
182 gime->Event(ievent ,"D"); // Read digits from simulated data
184 gime->Event(fRawReader,"W"); // Read digits from raw data
186 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
195 if(strstr(option,"deb"))
196 PrintRecPoints(option) ;
198 //increment the total number of recpoints per run
199 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
200 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
203 if(fWrite) //do not unload in "on flight" mode
206 if(strstr(option,"tim")){
207 gBenchmark->Stop("PHOSClusterizer");
208 AliInfo(Form("took %f seconds for Clusterizing %f seconds per event \n",
209 gBenchmark->GetCpuTime("PHOSClusterizer"),
210 gBenchmark->GetCpuTime("PHOSClusterizer")/nEvents )) ;
214 //____________________________________________________________________________
215 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
216 Int_t nPar, Float_t * fitparameters) const
218 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
219 // The initial values for fitting procedure are set equal to the positions of local maxima.
220 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
223 AliPHOSGetter * gime = AliPHOSGetter::Instance();
224 TClonesArray * digits = gime->Digits();
227 gMinuit->mncler(); // Reset Minuit's list of paramters
228 gMinuit->SetPrintLevel(-1) ; // No Printout
229 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
230 // To set the address of the minimization function
232 TList * toMinuit = new TList();
233 toMinuit->AddAt(emcRP,0) ;
234 toMinuit->AddAt(digits,1) ;
236 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
238 // filling initial values for fit parameters
239 AliPHOSDigit * digit ;
243 Int_t nDigits = (Int_t) nPar / 3 ;
247 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
249 for(iDigit = 0; iDigit < nDigits; iDigit++){
250 digit = maxAt[iDigit];
255 geom->AbsToRelNumbering(digit->GetId(), relid) ;
256 geom->RelPosInModule(relid, x, z) ;
258 Float_t energy = maxAtEnergy[iDigit] ;
260 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
263 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
266 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
269 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
272 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
275 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
280 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
285 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
286 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
287 gMinuit->SetMaxIterations(5);
288 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
290 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
292 if(ierflg == 4){ // Minimum not found
293 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
296 for(index = 0; index < nPar; index++){
299 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
300 fitparameters[index] = val ;
308 //____________________________________________________________________________
309 void AliPHOSClusterizerv1::GetCalibrationParameters()
311 // Set calibration parameters:
312 // For raw data they are read from the calibration database,
313 // for simulated data they are taken from digitizer.
315 // It is a user responsilibity to open CDB and set
316 // AliPHOSCalibData object by the following operators:
318 // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
319 // AliPHOSCalibData* clb = (AliPHOSCalibData*)AliCDBStorage::Instance()
320 // ->Get(path_to_calibdata,run_number);
321 // AliPHOSGetter* gime = AliPHOSGetter::Instance("galice.root");
322 // gime->SetCalibData(clb);
324 AliPHOSGetter * gime = AliPHOSGetter::Instance();
325 if(gime->IsRawDigits()){
326 fCalibData = gime->CalibData();
329 if ( !gime->Digitizer() )
330 gime->LoadDigitizer();
331 AliPHOSDigitizer * dig = gime->Digitizer();
332 fADCchanelEmc = dig->GetEMCchannel() ;
333 fADCpedestalEmc = dig->GetEMCpedestal();
335 fADCchanelCpv = dig->GetCPVchannel() ;
336 fADCpedestalCpv = dig->GetCPVpedestal() ;
340 //____________________________________________________________________________
341 void AliPHOSClusterizerv1::Init()
343 // Make all memory allocations which can not be done in default constructor.
344 // Attach the Clusterizer task to the list of PHOS tasks
346 AliPHOSGetter* gime = AliPHOSGetter::Instance() ;
348 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
350 AliPHOSGeometry * geom = gime->PHOSGeometry();
352 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
355 gMinuit = new TMinuit(100);
357 if ( !gime->Clusterizer() ) {
358 gime->PostClusterizer(this);
362 //____________________________________________________________________________
363 void AliPHOSClusterizerv1::InitParameters()
366 fNumberOfCpvClusters = 0 ;
367 fNumberOfEmcClusters = 0 ;
369 fCpvClusteringThreshold = 0.0;
370 fEmcClusteringThreshold = 0.2;
372 fEmcLocMaxCut = 0.03 ;
373 fCpvLocMaxCut = 0.03 ;
381 fEmcTimeGate = 1.e-8 ;
385 fRecPointsInRun = 0 ;
391 SetEventRange(0,-1) ;
394 //____________________________________________________________________________
395 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
397 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
399 // = 2 are not neighbour but do not continue searching
400 // neighbours are defined as digits having at least a common vertex
401 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
402 // which is compared to a digit (d2) not yet in a cluster
404 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
409 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
412 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
414 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
415 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
416 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
418 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
419 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
423 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
424 rv = 2; // Difference in row numbers is too large to look further
430 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
437 //____________________________________________________________________________
438 void AliPHOSClusterizerv1::CleanDigits(TClonesArray * digits){
439 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
440 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
441 Float_t cut = IsInEmc(digit) ? fEmcMinE : fCpvMinE ;
442 if(Calibrate(digit->GetAmp(),digit->GetId()) < cut)
443 digits->RemoveAt(i) ;
446 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
447 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
448 digit->SetIndexInList(i) ;
452 //____________________________________________________________________________
453 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
455 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
458 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
460 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
462 if(digit->GetId() <= nEMC ) rv = kTRUE;
467 //____________________________________________________________________________
468 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
470 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
474 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
476 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
478 if(digit->GetId() > nEMC ) rv = kTRUE;
483 //____________________________________________________________________________
484 void AliPHOSClusterizerv1::Unload()
486 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
487 gime->PhosLoader()->UnloadDigits() ;
488 gime->PhosLoader()->UnloadRecPoints() ;
491 //____________________________________________________________________________
492 void AliPHOSClusterizerv1::WriteRecPoints()
495 // Creates new branches with given title
496 // fills and writes into TreeR.
498 AliPHOSGetter * gime = AliPHOSGetter::Instance();
500 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
501 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
502 TClonesArray * digits = gime->Digits() ;
506 //Evaluate position, dispersion and other RecPoint properties..
507 Int_t nEmc = emcRecPoints->GetEntriesFast();
508 for(index = 0; index < nEmc; index++){
509 AliPHOSEmcRecPoint * rp = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) );
510 rp->Purify(fEmcMinE) ;
511 if(rp->GetMultiplicity()>0.) //If this RP is not empty
512 rp->EvalAll(fW0,digits) ;
514 emcRecPoints->RemoveAt(index) ;
518 emcRecPoints->Compress() ;
519 emcRecPoints->Sort() ;
520 // emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
521 for(index = 0; index < emcRecPoints->GetEntries(); index++){
522 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
525 //Now the same for CPV
526 for(index = 0; index < cpvRecPoints->GetEntries(); index++){
527 AliPHOSCpvRecPoint * rp = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) );
528 rp->EvalAll(fW0CPV,digits) ;
530 cpvRecPoints->Sort() ;
532 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
533 dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
535 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
537 if(fWrite){ //We write TreeR
538 TTree * treeR = gime->TreeR();
540 Int_t bufferSize = 32000 ;
541 Int_t splitlevel = 0 ;
544 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
545 emcBranch->SetTitle(BranchName());
548 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
549 cpvBranch->SetTitle(BranchName());
554 gime->WriteRecPoints("OVERWRITE");
555 gime->WriteClusterizer("OVERWRITE");
559 //____________________________________________________________________________
560 void AliPHOSClusterizerv1::MakeClusters()
562 // Steering method to construct the clusters stored in a list of Reconstructed Points
563 // A cluster is defined as a list of neighbour digits
566 AliPHOSGetter * gime = AliPHOSGetter::Instance();
568 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
569 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
571 emcRecPoints->Delete() ;
572 cpvRecPoints->Delete() ;
574 TClonesArray * digits = gime->Digits() ;
576 //Remove digits below threshold
577 CleanDigits(digits) ;
580 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
583 // Clusterization starts
585 TIter nextdigit(digitsC) ;
586 AliPHOSDigit * digit ;
587 Bool_t notremoved = kTRUE ;
589 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
592 AliPHOSRecPoint * clu = 0 ;
594 TArrayI clusterdigitslist(1500) ;
597 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
598 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
599 Int_t iDigitInCluster = 0 ;
601 if ( IsInEmc(digit) ) {
602 // start a new EMC RecPoint
603 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
604 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
606 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
607 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
608 fNumberOfEmcClusters++ ;
609 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
610 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
612 digitsC->Remove(digit) ;
616 // start a new CPV cluster
617 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
618 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
620 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
622 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
623 fNumberOfCpvClusters++ ;
624 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
625 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
627 digitsC->Remove(digit) ;
630 // Here we remove remaining EMC digits, which cannot make a cluster
633 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
635 digitsC->Remove(digit) ;
639 notremoved = kFALSE ;
646 AliPHOSDigit * digitN ;
648 while (index < iDigitInCluster){ // scan over digits already in cluster
649 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
651 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
652 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
654 case 0 : // not a neighbour
656 case 1 : // are neighbours
657 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
658 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
660 digitsC->Remove(digitN) ;
662 case 2 : // too far from each other
671 } // loop over cluster
682 //____________________________________________________________________________
683 void AliPHOSClusterizerv1::MakeUnfolding()
685 // Unfolds clusters using the shape of an ElectroMagnetic shower
686 // Performs unfolding of all EMC/CPV clusters
688 AliPHOSGetter * gime = AliPHOSGetter::Instance();
690 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
692 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
693 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
694 TClonesArray * digits = gime->Digits() ;
696 // Unfold first EMC clusters
697 if(fNumberOfEmcClusters > 0){
699 Int_t nModulesToUnfold = geom->GetNModules() ;
701 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
703 for(index = 0 ; index < numberofNotUnfolded ; index++){
705 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
706 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
709 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
710 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
711 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
712 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
714 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
715 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
716 emcRecPoints->Remove(emcRecPoint);
717 emcRecPoints->Compress() ;
719 fNumberOfEmcClusters -- ;
720 numberofNotUnfolded-- ;
723 emcRecPoint->SetNExMax(1) ; //Only one local maximum
727 delete[] maxAtEnergy ;
730 // Unfolding of EMC clusters finished
733 // Unfold now CPV clusters
734 if(fNumberOfCpvClusters > 0){
736 Int_t nModulesToUnfold = geom->GetNModules() ;
738 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
740 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
742 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
744 if(recPoint->GetPHOSMod()> nModulesToUnfold)
747 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
749 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
750 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
751 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
752 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
754 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
755 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
756 cpvRecPoints->Remove(emcRecPoint);
757 cpvRecPoints->Compress() ;
759 numberofCpvNotUnfolded-- ;
760 fNumberOfCpvClusters-- ;
764 delete[] maxAtEnergy ;
767 //Unfolding of Cpv clusters finished
771 //____________________________________________________________________________
772 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
774 // Shape of the shower (see PHOS TDR)
775 // If you change this function, change also the gradient evaluation in ChiSquare()
777 Double_t r4 = r*r*r*r ;
778 Double_t r295 = TMath::Power(r, 2.95) ;
779 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
783 //____________________________________________________________________________
784 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
786 AliPHOSDigit ** maxAt,
787 Float_t * maxAtEnergy)
789 // Performs the unfolding of a cluster with nMax overlapping showers
791 AliPHOSGetter * gime = AliPHOSGetter::Instance();
793 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
795 const TClonesArray * digits = gime->Digits() ;
796 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
797 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
799 Int_t nPar = 3 * nMax ;
800 Float_t * fitparameters = new Float_t[nPar] ;
802 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
804 // Fit failed, return and remove cluster
805 iniEmc->SetNExMax(-1) ;
806 delete[] fitparameters ;
810 // create ufolded rec points and fill them with new energy lists
811 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
812 // and later correct this number in acordance with actual energy deposition
814 Int_t nDigits = iniEmc->GetMultiplicity() ;
815 Float_t * efit = new Float_t[nDigits] ;
816 Float_t xDigit=0.,zDigit=0.,distance=0. ;
817 Float_t xpar=0.,zpar=0.,epar=0. ;
819 AliPHOSDigit * digit = 0 ;
820 Int_t * emcDigits = iniEmc->GetDigitsList() ;
824 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
825 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
826 geom->AbsToRelNumbering(digit->GetId(), relid) ;
827 geom->RelPosInModule(relid, xDigit, zDigit) ;
831 while(iparam < nPar ){
832 xpar = fitparameters[iparam] ;
833 zpar = fitparameters[iparam+1] ;
834 epar = fitparameters[iparam+2] ;
836 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
837 distance = TMath::Sqrt(distance) ;
838 efit[iDigit] += epar * ShowerShape(distance) ;
843 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
844 // so that energy deposited in each cell is distributed betwin new clusters proportionally
845 // to its contribution to efit
847 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
851 while(iparam < nPar ){
852 xpar = fitparameters[iparam] ;
853 zpar = fitparameters[iparam+1] ;
854 epar = fitparameters[iparam+2] ;
857 AliPHOSEmcRecPoint * emcRP = 0 ;
859 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
861 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
862 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
864 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
865 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
866 fNumberOfEmcClusters++ ;
867 emcRP->SetNExMax((Int_t)nPar/3) ;
869 else{//create new entries in fCpvRecPoints
870 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
871 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
873 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
874 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
875 fNumberOfCpvClusters++ ;
879 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
880 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
881 geom->AbsToRelNumbering(digit->GetId(), relid) ;
882 geom->RelPosInModule(relid, xDigit, zDigit) ;
883 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
884 distance = TMath::Sqrt(distance) ;
885 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
886 eDigit = emcEnergies[iDigit] * ratio ;
887 emcRP->AddDigit( *digit, eDigit ) ;
891 delete[] fitparameters ;
896 //_____________________________________________________________________________
897 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
899 // Calculates the Chi square for the cluster unfolding minimization
900 // Number of parameters, Gradient, Chi squared, parameters, what to do
902 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
904 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
905 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
909 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
911 Int_t * emcDigits = emcRP->GetDigitsList() ;
913 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
915 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
917 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
922 for(iparam = 0 ; iparam < nPar ; iparam++)
923 Grad[iparam] = 0 ; // Will evaluate gradient
927 AliPHOSDigit * digit ;
930 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
932 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
938 geom->AbsToRelNumbering(digit->GetId(), relid) ;
940 geom->RelPosInModule(relid, xDigit, zDigit) ;
942 if(iflag == 2){ // calculate gradient
945 while(iParam < nPar ){
946 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
948 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
949 distance = TMath::Sqrt( distance ) ;
951 efit += x[iParam] * ShowerShape(distance) ;
954 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
956 while(iParam < nPar ){
957 Double_t xpar = x[iParam] ;
958 Double_t zpar = x[iParam+1] ;
959 Double_t epar = x[iParam+2] ;
960 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
961 Double_t shape = sum * ShowerShape(dr) ;
962 Double_t r4 = dr*dr*dr*dr ;
963 Double_t r295 = TMath::Power(dr,2.95) ;
964 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
965 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
967 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
969 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
971 Grad[iParam] += shape ; // Derivative over energy
978 while(iparam < nPar ){
979 Double_t xpar = x[iparam] ;
980 Double_t zpar = x[iparam+1] ;
981 Double_t epar = x[iparam+2] ;
983 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
984 distance = TMath::Sqrt(distance) ;
985 efit += epar * ShowerShape(distance) ;
988 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
989 // Here we assume, that sigma = sqrt(E)
994 //____________________________________________________________________________
995 void AliPHOSClusterizerv1::Print(const Option_t *)const
997 // Print clusterizer parameters
1000 TString taskName(GetName()) ;
1001 taskName.ReplaceAll(Version(), "") ;
1003 if( strcmp(GetName(), "") !=0 ) {
1005 message = "\n--------------- %s %s -----------\n" ;
1006 message += "Clusterizing digits from the file: %s\n" ;
1007 message += " Branch: %s\n" ;
1008 message += " EMC Clustering threshold = %f\n" ;
1009 message += " EMC Local Maximum cut = %f\n" ;
1010 message += " EMC Logarothmic weight = %f\n" ;
1011 message += " CPV Clustering threshold = %f\n" ;
1012 message += " CPV Local Maximum cut = %f\n" ;
1013 message += " CPV Logarothmic weight = %f\n" ;
1015 message += " Unfolding on\n" ;
1017 message += " Unfolding off\n" ;
1019 message += "------------------------------------------------------------------" ;
1022 message = " AliPHOSClusterizerv1 not initialized " ;
1024 AliInfo(Form("%s, %s %s %s %s %s %s %s %s %s %s", message.Data(),
1029 fEmcClusteringThreshold,
1032 fCpvClusteringThreshold,
1038 //____________________________________________________________________________
1039 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1041 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1043 AliPHOSGetter * gime = AliPHOSGetter::Instance();
1045 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1046 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1048 AliInfo(Form("\nevent %d \n Found %d EMC RecPoints and %d CPV RecPoints",
1049 gAlice->GetEvNumber(),
1050 emcRecPoints->GetEntriesFast(),
1051 cpvRecPoints->GetEntriesFast() )) ;
1053 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1054 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1057 if(strstr(option,"all")) {
1058 printf("\n EMC clusters \n") ;
1059 printf("Index Ene(MeV) Multi Module X Y Z Lambdas_1 Lambda_2 # of prim Primaries list\n") ;
1061 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1062 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1064 rp->GetLocalPosition(locpos);
1066 rp->GetElipsAxis(lambda);
1069 primaries = rp->GetPrimaries(nprimaries);
1070 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
1071 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
1072 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
1074 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
1075 printf("%d ", primaries[iprimary] ) ;
1080 //Now plot CPV recPoints
1081 printf("\n CPV clusters \n") ;
1082 printf("Index Ene(MeV) Module X Y Z \n") ;
1083 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1084 AliPHOSCpvRecPoint * rp = (AliPHOSCpvRecPoint * )cpvRecPoints->At(index) ;
1087 rp->GetLocalPosition(locpos);
1089 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f \n",
1090 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
1091 locpos.X(), locpos.Y(), locpos.Z()) ;