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.86 2005/11/14 21:52:43 hristov
24 * Revision 1.85 2005/09/27 16:08:08 hristov
25 * New version of CDB storage framework (A.Colla)
27 * Revision 1.84 2005/09/21 10:02:47 kharlov
28 * Reading calibration from CDB (Boris Polichtchouk)
30 * Revision 1.82 2005/09/02 15:43:13 kharlov
31 * Add comments in GetCalibrationParameters and Calibrate
33 * Revision 1.81 2005/09/02 14:32:07 kharlov
34 * Calibration of raw data
36 * Revision 1.80 2005/08/24 15:31:36 kharlov
37 * Setting raw digits flag
39 * Revision 1.79 2005/07/25 15:53:53 kharlov
42 * Revision 1.78 2005/05/28 14:19:04 schutz
43 * Compilation warnings fixed by T.P.
47 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
48 //////////////////////////////////////////////////////////////////////////////
49 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
50 // unfolds the clusters having several local maxima.
51 // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
52 // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
53 // parameters including input digits branch title, thresholds etc.)
54 // This TTask is normally called from Reconstructioner, but can as well be used in
57 // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
58 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
59 // // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
60 // // and saves recpoints in branch named "recpointsname" (default = "digitsname")
61 // root [1] cl->ExecuteTask()
62 // //finds RecPoints in all events stored in galice.root
63 // root [2] cl->SetDigitsBranch("digits2")
64 // //sets another title for Digitis (input) branch
65 // root [3] cl->SetRecPointsBranch("recp2")
66 // //sets another title four output branches
67 // root [4] cl->SetEmcLocalMaxCut(0.03)
68 // //set clusterization parameters
69 // root [5] cl->ExecuteTask("deb all time")
70 // //once more finds RecPoints options are
71 // // deb - print number of found rec points
72 // // deb all - print number of found RecPoints and some their characteristics
73 // // time - print benchmarking results
75 // --- ROOT system ---
80 #include "TBenchmark.h"
82 // --- Standard library ---
84 // --- AliRoot header files ---
86 #include "AliPHOSGetter.h"
87 #include "AliPHOSGeometry.h"
88 #include "AliPHOSClusterizerv1.h"
89 #include "AliPHOSEmcRecPoint.h"
90 #include "AliPHOSCpvRecPoint.h"
91 #include "AliPHOSDigit.h"
92 #include "AliPHOSDigitizer.h"
93 #include "AliPHOSCalibrationDB.h"
94 #include "AliCDBManager.h"
95 #include "AliCDBStorage.h"
96 #include "AliCDBEntry.h"
98 ClassImp(AliPHOSClusterizerv1)
100 //____________________________________________________________________________
101 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
103 // default ctor (to be used mainly by Streamer)
106 fDefaultInit = kTRUE ;
109 //____________________________________________________________________________
110 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const TString alirunFileName, const TString eventFolderName)
111 :AliPHOSClusterizer(alirunFileName, eventFolderName)
113 // ctor with the indication of the file where header Tree and digits Tree are stored
117 fDefaultInit = kFALSE ;
120 //____________________________________________________________________________
121 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
126 //____________________________________________________________________________
127 const TString AliPHOSClusterizerv1::BranchName() const
132 //____________________________________________________________________________
133 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId)
135 // Convert digitized amplitude into energy.
136 // Calibration parameters are taken from calibration data base for raw data,
137 // or from digitizer parameters for simulated data.
141 AliPHOSGetter *gime = AliPHOSGetter::Instance();
142 gime->PHOSGeometry()->AbsToRelNumbering(absId,relId) ;
143 Int_t module = relId[0];
144 Int_t column = relId[3];
145 Int_t row = relId[2];
146 if(absId <= fEmcCrystals) { //calibrate as EMC
147 fADCchanelEmc = fCalibData->GetADCchannelEmc (module,column,row);
148 fADCpedestalEmc = fCalibData->GetADCpedestalEmc(module,column,row);
149 return fADCpedestalEmc + amp*fADCchanelEmc ;
151 else //calibrate as CPV, not implemented yet
155 if(absId <= fEmcCrystals) //calibrate as EMC
156 return fADCpedestalEmc + amp*fADCchanelEmc ;
157 else //calibrate as CPV
158 return fADCpedestalCpv+ amp*fADCchanelCpv ;
162 //____________________________________________________________________________
163 void AliPHOSClusterizerv1::Exec(Option_t *option)
165 // Steering method to perform clusterization for events
166 // in the range from fFirstEvent to fLastEvent.
167 // This range is optionally set by SetEventRange().
168 // if fLastEvent=-1 (by default), then process events until the end.
170 if(strstr(option,"tim"))
171 gBenchmark->Start("PHOSClusterizer");
173 if(strstr(option,"print")) {
178 GetCalibrationParameters() ;
180 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
182 gime->SetRawDigits(kFALSE);
184 gime->SetRawDigits(kTRUE);
186 if (fLastEvent == -1)
187 fLastEvent = gime->MaxEvent() - 1 ;
189 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // one event at the time
190 Int_t nEvents = fLastEvent - fFirstEvent + 1;
193 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
195 gime->Event(ievent ,"D"); // Read digits from simulated data
197 gime->Event(fRawReader,"W"); // Read digits from raw data
199 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
208 if(strstr(option,"deb"))
209 PrintRecPoints(option) ;
211 //increment the total number of recpoints per run
212 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
213 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
216 if(fWrite) //do not unload in "on flight" mode
219 if(strstr(option,"tim")){
220 gBenchmark->Stop("PHOSClusterizer");
221 AliInfo(Form("took %f seconds for Clusterizing %f seconds per event \n",
222 gBenchmark->GetCpuTime("PHOSClusterizer"),
223 gBenchmark->GetCpuTime("PHOSClusterizer")/nEvents )) ;
227 //____________________________________________________________________________
228 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
229 Int_t nPar, Float_t * fitparameters) const
231 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
232 // The initial values for fitting procedure are set equal to the positions of local maxima.
233 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
236 AliPHOSGetter * gime = AliPHOSGetter::Instance();
237 TClonesArray * digits = gime->Digits();
240 gMinuit->mncler(); // Reset Minuit's list of paramters
241 gMinuit->SetPrintLevel(-1) ; // No Printout
242 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
243 // To set the address of the minimization function
245 TList * toMinuit = new TList();
246 toMinuit->AddAt(emcRP,0) ;
247 toMinuit->AddAt(digits,1) ;
249 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
251 // filling initial values for fit parameters
252 AliPHOSDigit * digit ;
256 Int_t nDigits = (Int_t) nPar / 3 ;
260 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
262 for(iDigit = 0; iDigit < nDigits; iDigit++){
263 digit = maxAt[iDigit];
268 geom->AbsToRelNumbering(digit->GetId(), relid) ;
269 geom->RelPosInModule(relid, x, z) ;
271 Float_t energy = maxAtEnergy[iDigit] ;
273 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
276 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
279 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
282 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
285 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
288 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
293 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
298 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
299 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
300 gMinuit->SetMaxIterations(5);
301 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
303 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
305 if(ierflg == 4){ // Minimum not found
306 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
309 for(index = 0; index < nPar; index++){
312 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
313 fitparameters[index] = val ;
321 //____________________________________________________________________________
322 void AliPHOSClusterizerv1::GetCalibrationParameters()
324 // Set calibration parameters:
325 // if calibration database exists, they are read from database,
326 // otherwise, they are taken from digitizer.
328 // It is a user responsilibity to open CDB before reconstruction, for example:
329 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
331 AliPHOSGetter * gime = AliPHOSGetter::Instance();
333 if(AliCDBManager::Instance()->IsDefaultStorageSet()){
334 AliCDBEntry *entry = (AliCDBEntry*) AliCDBManager::Instance()->GetDefaultStorage()
335 ->Get("PHOS/GainFactors_and_Pedestals/Calibration",gAlice->GetRunNumber());
336 fCalibData = (AliPHOSCalibData*) entry->GetObject();
342 if ( !gime->Digitizer() )
343 gime->LoadDigitizer();
344 AliPHOSDigitizer * dig = gime->Digitizer();
345 fADCchanelEmc = dig->GetEMCchannel() ;
346 fADCpedestalEmc = dig->GetEMCpedestal();
348 fADCchanelCpv = dig->GetCPVchannel() ;
349 fADCpedestalCpv = dig->GetCPVpedestal() ;
353 //____________________________________________________________________________
354 void AliPHOSClusterizerv1::Init()
356 // Make all memory allocations which can not be done in default constructor.
357 // Attach the Clusterizer task to the list of PHOS tasks
359 AliPHOSGetter* gime = AliPHOSGetter::Instance() ;
361 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
363 AliPHOSGeometry * geom = gime->PHOSGeometry();
365 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
368 gMinuit = new TMinuit(100);
370 if ( !gime->Clusterizer() ) {
371 gime->PostClusterizer(this);
375 //____________________________________________________________________________
376 void AliPHOSClusterizerv1::InitParameters()
379 fNumberOfCpvClusters = 0 ;
380 fNumberOfEmcClusters = 0 ;
382 fCpvClusteringThreshold = 0.0;
383 fEmcClusteringThreshold = 0.2;
385 fEmcLocMaxCut = 0.03 ;
386 fCpvLocMaxCut = 0.03 ;
394 fEmcTimeGate = 1.e-8 ;
398 fRecPointsInRun = 0 ;
404 SetEventRange(0,-1) ;
407 //____________________________________________________________________________
408 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
410 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
412 // = 2 are not neighbour but do not continue searching
413 // neighbours are defined as digits having at least a common vertex
414 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
415 // which is compared to a digit (d2) not yet in a cluster
417 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
422 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
425 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
427 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
428 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
429 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
431 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
432 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
436 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
437 rv = 2; // Difference in row numbers is too large to look further
443 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
450 //____________________________________________________________________________
451 void AliPHOSClusterizerv1::CleanDigits(TClonesArray * digits){
452 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
453 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
454 Float_t cut = IsInEmc(digit) ? fEmcMinE : fCpvMinE ;
455 if(Calibrate(digit->GetAmp(),digit->GetId()) < cut)
456 digits->RemoveAt(i) ;
459 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
460 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
461 digit->SetIndexInList(i) ;
465 //____________________________________________________________________________
466 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
468 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
471 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
473 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
475 if(digit->GetId() <= nEMC ) rv = kTRUE;
480 //____________________________________________________________________________
481 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
483 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
487 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
489 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
491 if(digit->GetId() > nEMC ) rv = kTRUE;
496 //____________________________________________________________________________
497 void AliPHOSClusterizerv1::Unload()
499 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
500 gime->PhosLoader()->UnloadDigits() ;
501 gime->PhosLoader()->UnloadRecPoints() ;
504 //____________________________________________________________________________
505 void AliPHOSClusterizerv1::WriteRecPoints()
508 // Creates new branches with given title
509 // fills and writes into TreeR.
511 AliPHOSGetter * gime = AliPHOSGetter::Instance();
513 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
514 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
515 TClonesArray * digits = gime->Digits() ;
519 //Evaluate position, dispersion and other RecPoint properties..
520 Int_t nEmc = emcRecPoints->GetEntriesFast();
521 for(index = 0; index < nEmc; index++){
522 AliPHOSEmcRecPoint * rp = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) );
523 rp->Purify(fEmcMinE) ;
524 if(rp->GetMultiplicity()>0.) //If this RP is not empty
525 rp->EvalAll(fW0,digits) ;
527 emcRecPoints->RemoveAt(index) ;
531 emcRecPoints->Compress() ;
532 emcRecPoints->Sort() ;
533 // emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
534 for(index = 0; index < emcRecPoints->GetEntries(); index++){
535 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
538 //Now the same for CPV
539 for(index = 0; index < cpvRecPoints->GetEntries(); index++){
540 AliPHOSCpvRecPoint * rp = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) );
541 rp->EvalAll(fW0CPV,digits) ;
543 cpvRecPoints->Sort() ;
545 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
546 dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
548 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
550 if(fWrite){ //We write TreeR
551 TTree * treeR = gime->TreeR();
553 Int_t bufferSize = 32000 ;
554 Int_t splitlevel = 0 ;
557 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
558 emcBranch->SetTitle(BranchName());
561 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
562 cpvBranch->SetTitle(BranchName());
567 gime->WriteRecPoints("OVERWRITE");
568 gime->WriteClusterizer("OVERWRITE");
572 //____________________________________________________________________________
573 void AliPHOSClusterizerv1::MakeClusters()
575 // Steering method to construct the clusters stored in a list of Reconstructed Points
576 // A cluster is defined as a list of neighbour digits
579 AliPHOSGetter * gime = AliPHOSGetter::Instance();
581 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
582 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
584 emcRecPoints->Delete() ;
585 cpvRecPoints->Delete() ;
587 TClonesArray * digits = gime->Digits() ;
589 //Remove digits below threshold
590 CleanDigits(digits) ;
593 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
596 // Clusterization starts
598 TIter nextdigit(digitsC) ;
599 AliPHOSDigit * digit ;
600 Bool_t notremoved = kTRUE ;
602 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
605 AliPHOSRecPoint * clu = 0 ;
607 TArrayI clusterdigitslist(1500) ;
610 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
611 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
612 Int_t iDigitInCluster = 0 ;
614 if ( IsInEmc(digit) ) {
615 // start a new EMC RecPoint
616 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
617 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
619 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
620 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
621 fNumberOfEmcClusters++ ;
622 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
623 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
625 digitsC->Remove(digit) ;
629 // start a new CPV cluster
630 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
631 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
633 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
635 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
636 fNumberOfCpvClusters++ ;
637 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
638 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
640 digitsC->Remove(digit) ;
643 // Here we remove remaining EMC digits, which cannot make a cluster
646 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
648 digitsC->Remove(digit) ;
652 notremoved = kFALSE ;
659 AliPHOSDigit * digitN ;
661 while (index < iDigitInCluster){ // scan over digits already in cluster
662 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
664 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
665 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
667 case 0 : // not a neighbour
669 case 1 : // are neighbours
670 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
671 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
673 digitsC->Remove(digitN) ;
675 case 2 : // too far from each other
684 } // loop over cluster
695 //____________________________________________________________________________
696 void AliPHOSClusterizerv1::MakeUnfolding()
698 // Unfolds clusters using the shape of an ElectroMagnetic shower
699 // Performs unfolding of all EMC/CPV clusters
701 AliPHOSGetter * gime = AliPHOSGetter::Instance();
703 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
705 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
706 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
707 TClonesArray * digits = gime->Digits() ;
709 // Unfold first EMC clusters
710 if(fNumberOfEmcClusters > 0){
712 Int_t nModulesToUnfold = geom->GetNModules() ;
714 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
716 for(index = 0 ; index < numberofNotUnfolded ; index++){
718 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
719 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
722 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
723 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
724 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
725 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
727 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
728 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
729 emcRecPoints->Remove(emcRecPoint);
730 emcRecPoints->Compress() ;
732 fNumberOfEmcClusters -- ;
733 numberofNotUnfolded-- ;
736 emcRecPoint->SetNExMax(1) ; //Only one local maximum
740 delete[] maxAtEnergy ;
743 // Unfolding of EMC clusters finished
746 // Unfold now CPV clusters
747 if(fNumberOfCpvClusters > 0){
749 Int_t nModulesToUnfold = geom->GetNModules() ;
751 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
753 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
755 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
757 if(recPoint->GetPHOSMod()> nModulesToUnfold)
760 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
762 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
763 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
764 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
765 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
767 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
768 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
769 cpvRecPoints->Remove(emcRecPoint);
770 cpvRecPoints->Compress() ;
772 numberofCpvNotUnfolded-- ;
773 fNumberOfCpvClusters-- ;
777 delete[] maxAtEnergy ;
780 //Unfolding of Cpv clusters finished
784 //____________________________________________________________________________
785 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
787 // Shape of the shower (see PHOS TDR)
788 // If you change this function, change also the gradient evaluation in ChiSquare()
790 Double_t r4 = r*r*r*r ;
791 Double_t r295 = TMath::Power(r, 2.95) ;
792 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
796 //____________________________________________________________________________
797 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
799 AliPHOSDigit ** maxAt,
800 Float_t * maxAtEnergy)
802 // Performs the unfolding of a cluster with nMax overlapping showers
804 AliPHOSGetter * gime = AliPHOSGetter::Instance();
806 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
808 const TClonesArray * digits = gime->Digits() ;
809 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
810 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
812 Int_t nPar = 3 * nMax ;
813 Float_t * fitparameters = new Float_t[nPar] ;
815 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
817 // Fit failed, return and remove cluster
818 iniEmc->SetNExMax(-1) ;
819 delete[] fitparameters ;
823 // create ufolded rec points and fill them with new energy lists
824 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
825 // and later correct this number in acordance with actual energy deposition
827 Int_t nDigits = iniEmc->GetMultiplicity() ;
828 Float_t * efit = new Float_t[nDigits] ;
829 Float_t xDigit=0.,zDigit=0.,distance=0. ;
830 Float_t xpar=0.,zpar=0.,epar=0. ;
832 AliPHOSDigit * digit = 0 ;
833 Int_t * emcDigits = iniEmc->GetDigitsList() ;
837 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
838 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
839 geom->AbsToRelNumbering(digit->GetId(), relid) ;
840 geom->RelPosInModule(relid, xDigit, zDigit) ;
844 while(iparam < nPar ){
845 xpar = fitparameters[iparam] ;
846 zpar = fitparameters[iparam+1] ;
847 epar = fitparameters[iparam+2] ;
849 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
850 distance = TMath::Sqrt(distance) ;
851 efit[iDigit] += epar * ShowerShape(distance) ;
856 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
857 // so that energy deposited in each cell is distributed betwin new clusters proportionally
858 // to its contribution to efit
860 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
864 while(iparam < nPar ){
865 xpar = fitparameters[iparam] ;
866 zpar = fitparameters[iparam+1] ;
867 epar = fitparameters[iparam+2] ;
870 AliPHOSEmcRecPoint * emcRP = 0 ;
872 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
874 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
875 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
877 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
878 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
879 fNumberOfEmcClusters++ ;
880 emcRP->SetNExMax((Int_t)nPar/3) ;
882 else{//create new entries in fCpvRecPoints
883 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
884 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
886 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
887 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
888 fNumberOfCpvClusters++ ;
892 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
893 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
894 geom->AbsToRelNumbering(digit->GetId(), relid) ;
895 geom->RelPosInModule(relid, xDigit, zDigit) ;
896 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
897 distance = TMath::Sqrt(distance) ;
898 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
899 eDigit = emcEnergies[iDigit] * ratio ;
900 emcRP->AddDigit( *digit, eDigit ) ;
904 delete[] fitparameters ;
909 //_____________________________________________________________________________
910 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
912 // Calculates the Chi square for the cluster unfolding minimization
913 // Number of parameters, Gradient, Chi squared, parameters, what to do
915 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
917 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
918 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
922 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
924 Int_t * emcDigits = emcRP->GetDigitsList() ;
926 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
928 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
930 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
935 for(iparam = 0 ; iparam < nPar ; iparam++)
936 Grad[iparam] = 0 ; // Will evaluate gradient
940 AliPHOSDigit * digit ;
943 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
945 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
951 geom->AbsToRelNumbering(digit->GetId(), relid) ;
953 geom->RelPosInModule(relid, xDigit, zDigit) ;
955 if(iflag == 2){ // calculate gradient
958 while(iParam < nPar ){
959 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
961 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
962 distance = TMath::Sqrt( distance ) ;
964 efit += x[iParam] * ShowerShape(distance) ;
967 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
969 while(iParam < nPar ){
970 Double_t xpar = x[iParam] ;
971 Double_t zpar = x[iParam+1] ;
972 Double_t epar = x[iParam+2] ;
973 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
974 Double_t shape = sum * ShowerShape(dr) ;
975 Double_t r4 = dr*dr*dr*dr ;
976 Double_t r295 = TMath::Power(dr,2.95) ;
977 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
978 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
980 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
982 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
984 Grad[iParam] += shape ; // Derivative over energy
991 while(iparam < nPar ){
992 Double_t xpar = x[iparam] ;
993 Double_t zpar = x[iparam+1] ;
994 Double_t epar = x[iparam+2] ;
996 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
997 distance = TMath::Sqrt(distance) ;
998 efit += epar * ShowerShape(distance) ;
1001 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
1002 // Here we assume, that sigma = sqrt(E)
1007 //____________________________________________________________________________
1008 void AliPHOSClusterizerv1::Print(const Option_t *)const
1010 // Print clusterizer parameters
1013 TString taskName(GetName()) ;
1014 taskName.ReplaceAll(Version(), "") ;
1016 if( strcmp(GetName(), "") !=0 ) {
1018 message = "\n--------------- %s %s -----------\n" ;
1019 message += "Clusterizing digits from the file: %s\n" ;
1020 message += " Branch: %s\n" ;
1021 message += " EMC Clustering threshold = %f\n" ;
1022 message += " EMC Local Maximum cut = %f\n" ;
1023 message += " EMC Logarothmic weight = %f\n" ;
1024 message += " CPV Clustering threshold = %f\n" ;
1025 message += " CPV Local Maximum cut = %f\n" ;
1026 message += " CPV Logarothmic weight = %f\n" ;
1028 message += " Unfolding on\n" ;
1030 message += " Unfolding off\n" ;
1032 message += "------------------------------------------------------------------" ;
1035 message = " AliPHOSClusterizerv1 not initialized " ;
1037 AliInfo(Form("%s, %s %s %s %s %s %s %s %s %s %s", message.Data(),
1042 fEmcClusteringThreshold,
1045 fCpvClusteringThreshold,
1051 //____________________________________________________________________________
1052 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1054 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1056 AliPHOSGetter * gime = AliPHOSGetter::Instance();
1058 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1059 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1061 AliInfo(Form("\nevent %d \n Found %d EMC RecPoints and %d CPV RecPoints",
1062 gAlice->GetEvNumber(),
1063 emcRecPoints->GetEntriesFast(),
1064 cpvRecPoints->GetEntriesFast() )) ;
1066 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1067 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1070 if(strstr(option,"all")) {
1071 printf("\n EMC clusters \n") ;
1072 printf("Index Ene(MeV) Multi Module X Y Z Lambdas_1 Lambda_2 # of prim Primaries list\n") ;
1074 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1075 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1077 rp->GetLocalPosition(locpos);
1079 rp->GetElipsAxis(lambda);
1082 primaries = rp->GetPrimaries(nprimaries);
1083 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
1084 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
1085 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
1087 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
1088 printf("%d ", primaries[iprimary] ) ;
1093 //Now plot CPV recPoints
1094 printf("\n CPV clusters \n") ;
1095 printf("Index Ene(MeV) Module X Y Z \n") ;
1096 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1097 AliPHOSCpvRecPoint * rp = (AliPHOSCpvRecPoint * )cpvRecPoints->At(index) ;
1100 rp->GetLocalPosition(locpos);
1102 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f \n",
1103 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
1104 locpos.X(), locpos.Y(), locpos.Z()) ;