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.85 2005/09/27 16:08:08 hristov
22 * New version of CDB storage framework (A.Colla)
24 * Revision 1.84 2005/09/21 10:02:47 kharlov
25 * Reading calibration from CDB (Boris Polichtchouk)
27 * Revision 1.82 2005/09/02 15:43:13 kharlov
28 * Add comments in GetCalibrationParameters and Calibrate
30 * Revision 1.81 2005/09/02 14:32:07 kharlov
31 * Calibration of raw data
33 * Revision 1.80 2005/08/24 15:31:36 kharlov
34 * Setting raw digits flag
36 * Revision 1.79 2005/07/25 15:53:53 kharlov
39 * Revision 1.78 2005/05/28 14:19:04 schutz
40 * Compilation warnings fixed by T.P.
44 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
45 //////////////////////////////////////////////////////////////////////////////
46 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
47 // unfolds the clusters having several local maxima.
48 // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
49 // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
50 // parameters including input digits branch title, thresholds etc.)
51 // This TTask is normally called from Reconstructioner, but can as well be used in
54 // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
55 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
56 // // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
57 // // and saves recpoints in branch named "recpointsname" (default = "digitsname")
58 // root [1] cl->ExecuteTask()
59 // //finds RecPoints in all events stored in galice.root
60 // root [2] cl->SetDigitsBranch("digits2")
61 // //sets another title for Digitis (input) branch
62 // root [3] cl->SetRecPointsBranch("recp2")
63 // //sets another title four output branches
64 // root [4] cl->SetEmcLocalMaxCut(0.03)
65 // //set clusterization parameters
66 // root [5] cl->ExecuteTask("deb all time")
67 // //once more finds RecPoints options are
68 // // deb - print number of found rec points
69 // // deb all - print number of found RecPoints and some their characteristics
70 // // time - print benchmarking results
72 // --- ROOT system ---
77 #include "TBenchmark.h"
79 // --- Standard library ---
81 // --- AliRoot header files ---
83 #include "AliPHOSGetter.h"
84 #include "AliPHOSGeometry.h"
85 #include "AliPHOSClusterizerv1.h"
86 #include "AliPHOSEmcRecPoint.h"
87 #include "AliPHOSCpvRecPoint.h"
88 #include "AliPHOSDigit.h"
89 #include "AliPHOSDigitizer.h"
90 #include "AliPHOSCalibrationDB.h"
91 #include "AliCDBManager.h"
92 #include "AliCDBStorage.h"
93 #include "AliCDBEntry.h"
95 ClassImp(AliPHOSClusterizerv1)
97 //____________________________________________________________________________
98 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
100 // default ctor (to be used mainly by Streamer)
103 fDefaultInit = kTRUE ;
106 //____________________________________________________________________________
107 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const TString alirunFileName, const TString eventFolderName)
108 :AliPHOSClusterizer(alirunFileName, eventFolderName)
110 // ctor with the indication of the file where header Tree and digits Tree are stored
114 fDefaultInit = kFALSE ;
117 //____________________________________________________________________________
118 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
123 //____________________________________________________________________________
124 const TString AliPHOSClusterizerv1::BranchName() const
129 //____________________________________________________________________________
130 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId)
132 // Convert digitized amplitude into energy.
133 // Calibration parameters are taken from calibration data base for raw data,
134 // or from digitizer parameters for simulated data.
138 AliPHOSGetter *gime = AliPHOSGetter::Instance();
139 gime->PHOSGeometry()->AbsToRelNumbering(absId,relId) ;
140 Int_t module = relId[0];
141 Int_t column = relId[3];
142 Int_t row = relId[2];
143 if(absId <= fEmcCrystals) { //calibrate as EMC
144 fADCchanelEmc = fCalibData->GetADCchannelEmc (module,column,row);
145 fADCpedestalEmc = fCalibData->GetADCpedestalEmc(module,column,row);
146 return fADCpedestalEmc + amp*fADCchanelEmc ;
148 else //calibrate as CPV, not implemented yet
152 if(absId <= fEmcCrystals) //calibrate as EMC
153 return fADCpedestalEmc + amp*fADCchanelEmc ;
154 else //calibrate as CPV
155 return fADCpedestalCpv+ amp*fADCchanelCpv ;
159 //____________________________________________________________________________
160 void AliPHOSClusterizerv1::Exec(Option_t *option)
162 // Steering method to perform clusterization for events
163 // in the range from fFirstEvent to fLastEvent.
164 // This range is optionally set by SetEventRange().
165 // if fLastEvent=-1 (by default), then process events until the end.
167 if(strstr(option,"tim"))
168 gBenchmark->Start("PHOSClusterizer");
170 if(strstr(option,"print")) {
175 GetCalibrationParameters() ;
177 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
179 gime->SetRawDigits(kFALSE);
181 gime->SetRawDigits(kTRUE);
183 if (fLastEvent == -1)
184 fLastEvent = gime->MaxEvent() - 1 ;
186 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // one event at the time
187 Int_t nEvents = fLastEvent - fFirstEvent + 1;
190 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
192 gime->Event(ievent ,"D"); // Read digits from simulated data
194 gime->Event(fRawReader,"W"); // Read digits from raw data
196 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
205 if(strstr(option,"deb"))
206 PrintRecPoints(option) ;
208 //increment the total number of recpoints per run
209 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
210 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
213 if(fWrite) //do not unload in "on flight" mode
216 if(strstr(option,"tim")){
217 gBenchmark->Stop("PHOSClusterizer");
218 AliInfo(Form("took %f seconds for Clusterizing %f seconds per event \n",
219 gBenchmark->GetCpuTime("PHOSClusterizer"),
220 gBenchmark->GetCpuTime("PHOSClusterizer")/nEvents )) ;
224 //____________________________________________________________________________
225 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
226 Int_t nPar, Float_t * fitparameters) const
228 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
229 // The initial values for fitting procedure are set equal to the positions of local maxima.
230 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
233 AliPHOSGetter * gime = AliPHOSGetter::Instance();
234 TClonesArray * digits = gime->Digits();
237 gMinuit->mncler(); // Reset Minuit's list of paramters
238 gMinuit->SetPrintLevel(-1) ; // No Printout
239 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
240 // To set the address of the minimization function
242 TList * toMinuit = new TList();
243 toMinuit->AddAt(emcRP,0) ;
244 toMinuit->AddAt(digits,1) ;
246 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
248 // filling initial values for fit parameters
249 AliPHOSDigit * digit ;
253 Int_t nDigits = (Int_t) nPar / 3 ;
257 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
259 for(iDigit = 0; iDigit < nDigits; iDigit++){
260 digit = maxAt[iDigit];
265 geom->AbsToRelNumbering(digit->GetId(), relid) ;
266 geom->RelPosInModule(relid, x, z) ;
268 Float_t energy = maxAtEnergy[iDigit] ;
270 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
273 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
276 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
279 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
282 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
285 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
290 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
295 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
296 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
297 gMinuit->SetMaxIterations(5);
298 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
300 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
302 if(ierflg == 4){ // Minimum not found
303 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
306 for(index = 0; index < nPar; index++){
309 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
310 fitparameters[index] = val ;
318 //____________________________________________________________________________
319 void AliPHOSClusterizerv1::GetCalibrationParameters()
321 // Set calibration parameters:
322 // if calibration database exists, they are read from database,
323 // otherwise, they are taken from digitizer.
325 // It is a user responsilibity to open CDB before reconstruction:
326 // AliCDBLocal *loc = new AliCDBLocal("CalibDB");
328 AliPHOSGetter * gime = AliPHOSGetter::Instance();
330 if(AliCDBManager::Instance()->IsDefaultStorageSet()){
331 AliCDBEntry *entry = (AliCDBEntry*) AliCDBManager::Instance()->GetDefaultStorage()
332 ->Get("PHOS/Calib/GainFactors_and_Pedestals",gAlice->GetRunNumber());
333 fCalibData = (AliPHOSCalibData*) entry->GetObject();
339 if ( !gime->Digitizer() )
340 gime->LoadDigitizer();
341 AliPHOSDigitizer * dig = gime->Digitizer();
342 fADCchanelEmc = dig->GetEMCchannel() ;
343 fADCpedestalEmc = dig->GetEMCpedestal();
345 fADCchanelCpv = dig->GetCPVchannel() ;
346 fADCpedestalCpv = dig->GetCPVpedestal() ;
350 //____________________________________________________________________________
351 void AliPHOSClusterizerv1::Init()
353 // Make all memory allocations which can not be done in default constructor.
354 // Attach the Clusterizer task to the list of PHOS tasks
356 AliPHOSGetter* gime = AliPHOSGetter::Instance() ;
358 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
360 AliPHOSGeometry * geom = gime->PHOSGeometry();
362 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
365 gMinuit = new TMinuit(100);
367 if ( !gime->Clusterizer() ) {
368 gime->PostClusterizer(this);
372 //____________________________________________________________________________
373 void AliPHOSClusterizerv1::InitParameters()
376 fNumberOfCpvClusters = 0 ;
377 fNumberOfEmcClusters = 0 ;
379 fCpvClusteringThreshold = 0.0;
380 fEmcClusteringThreshold = 0.2;
382 fEmcLocMaxCut = 0.03 ;
383 fCpvLocMaxCut = 0.03 ;
391 fEmcTimeGate = 1.e-8 ;
395 fRecPointsInRun = 0 ;
401 SetEventRange(0,-1) ;
404 //____________________________________________________________________________
405 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
407 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
409 // = 2 are not neighbour but do not continue searching
410 // neighbours are defined as digits having at least a common vertex
411 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
412 // which is compared to a digit (d2) not yet in a cluster
414 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
419 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
422 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
424 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
425 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
426 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
428 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
429 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
433 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
434 rv = 2; // Difference in row numbers is too large to look further
440 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
447 //____________________________________________________________________________
448 void AliPHOSClusterizerv1::CleanDigits(TClonesArray * digits){
449 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
450 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
451 Float_t cut = IsInEmc(digit) ? fEmcMinE : fCpvMinE ;
452 if(Calibrate(digit->GetAmp(),digit->GetId()) < cut)
453 digits->RemoveAt(i) ;
456 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
457 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
458 digit->SetIndexInList(i) ;
462 //____________________________________________________________________________
463 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
465 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
468 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
470 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
472 if(digit->GetId() <= nEMC ) rv = kTRUE;
477 //____________________________________________________________________________
478 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
480 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
484 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
486 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
488 if(digit->GetId() > nEMC ) rv = kTRUE;
493 //____________________________________________________________________________
494 void AliPHOSClusterizerv1::Unload()
496 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
497 gime->PhosLoader()->UnloadDigits() ;
498 gime->PhosLoader()->UnloadRecPoints() ;
501 //____________________________________________________________________________
502 void AliPHOSClusterizerv1::WriteRecPoints()
505 // Creates new branches with given title
506 // fills and writes into TreeR.
508 AliPHOSGetter * gime = AliPHOSGetter::Instance();
510 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
511 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
512 TClonesArray * digits = gime->Digits() ;
516 //Evaluate position, dispersion and other RecPoint properties..
517 Int_t nEmc = emcRecPoints->GetEntriesFast();
518 for(index = 0; index < nEmc; index++){
519 AliPHOSEmcRecPoint * rp = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) );
520 rp->Purify(fEmcMinE) ;
521 if(rp->GetMultiplicity()>0.) //If this RP is not empty
522 rp->EvalAll(fW0,digits) ;
524 emcRecPoints->RemoveAt(index) ;
528 emcRecPoints->Compress() ;
529 emcRecPoints->Sort() ;
530 // emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
531 for(index = 0; index < emcRecPoints->GetEntries(); index++){
532 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
535 //Now the same for CPV
536 for(index = 0; index < cpvRecPoints->GetEntries(); index++){
537 AliPHOSCpvRecPoint * rp = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) );
538 rp->EvalAll(fW0CPV,digits) ;
540 cpvRecPoints->Sort() ;
542 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
543 dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
545 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
547 if(fWrite){ //We write TreeR
548 TTree * treeR = gime->TreeR();
550 Int_t bufferSize = 32000 ;
551 Int_t splitlevel = 0 ;
554 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
555 emcBranch->SetTitle(BranchName());
558 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
559 cpvBranch->SetTitle(BranchName());
564 gime->WriteRecPoints("OVERWRITE");
565 gime->WriteClusterizer("OVERWRITE");
569 //____________________________________________________________________________
570 void AliPHOSClusterizerv1::MakeClusters()
572 // Steering method to construct the clusters stored in a list of Reconstructed Points
573 // A cluster is defined as a list of neighbour digits
576 AliPHOSGetter * gime = AliPHOSGetter::Instance();
578 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
579 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
581 emcRecPoints->Delete() ;
582 cpvRecPoints->Delete() ;
584 TClonesArray * digits = gime->Digits() ;
586 //Remove digits below threshold
587 CleanDigits(digits) ;
590 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
593 // Clusterization starts
595 TIter nextdigit(digitsC) ;
596 AliPHOSDigit * digit ;
597 Bool_t notremoved = kTRUE ;
599 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
602 AliPHOSRecPoint * clu = 0 ;
604 TArrayI clusterdigitslist(1500) ;
607 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
608 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
609 Int_t iDigitInCluster = 0 ;
611 if ( IsInEmc(digit) ) {
612 // start a new EMC RecPoint
613 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
614 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
616 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
617 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
618 fNumberOfEmcClusters++ ;
619 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
620 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
622 digitsC->Remove(digit) ;
626 // start a new CPV cluster
627 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
628 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
630 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
632 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
633 fNumberOfCpvClusters++ ;
634 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
635 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
637 digitsC->Remove(digit) ;
640 // Here we remove remaining EMC digits, which cannot make a cluster
643 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
645 digitsC->Remove(digit) ;
649 notremoved = kFALSE ;
656 AliPHOSDigit * digitN ;
658 while (index < iDigitInCluster){ // scan over digits already in cluster
659 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
661 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
662 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
664 case 0 : // not a neighbour
666 case 1 : // are neighbours
667 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
668 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
670 digitsC->Remove(digitN) ;
672 case 2 : // too far from each other
681 } // loop over cluster
692 //____________________________________________________________________________
693 void AliPHOSClusterizerv1::MakeUnfolding()
695 // Unfolds clusters using the shape of an ElectroMagnetic shower
696 // Performs unfolding of all EMC/CPV clusters
698 AliPHOSGetter * gime = AliPHOSGetter::Instance();
700 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
702 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
703 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
704 TClonesArray * digits = gime->Digits() ;
706 // Unfold first EMC clusters
707 if(fNumberOfEmcClusters > 0){
709 Int_t nModulesToUnfold = geom->GetNModules() ;
711 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
713 for(index = 0 ; index < numberofNotUnfolded ; index++){
715 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
716 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
719 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
720 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
721 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
722 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
724 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
725 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
726 emcRecPoints->Remove(emcRecPoint);
727 emcRecPoints->Compress() ;
729 fNumberOfEmcClusters -- ;
730 numberofNotUnfolded-- ;
733 emcRecPoint->SetNExMax(1) ; //Only one local maximum
737 delete[] maxAtEnergy ;
740 // Unfolding of EMC clusters finished
743 // Unfold now CPV clusters
744 if(fNumberOfCpvClusters > 0){
746 Int_t nModulesToUnfold = geom->GetNModules() ;
748 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
750 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
752 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
754 if(recPoint->GetPHOSMod()> nModulesToUnfold)
757 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
759 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
760 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
761 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
762 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
764 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
765 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
766 cpvRecPoints->Remove(emcRecPoint);
767 cpvRecPoints->Compress() ;
769 numberofCpvNotUnfolded-- ;
770 fNumberOfCpvClusters-- ;
774 delete[] maxAtEnergy ;
777 //Unfolding of Cpv clusters finished
781 //____________________________________________________________________________
782 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
784 // Shape of the shower (see PHOS TDR)
785 // If you change this function, change also the gradient evaluation in ChiSquare()
787 Double_t r4 = r*r*r*r ;
788 Double_t r295 = TMath::Power(r, 2.95) ;
789 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
793 //____________________________________________________________________________
794 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
796 AliPHOSDigit ** maxAt,
797 Float_t * maxAtEnergy)
799 // Performs the unfolding of a cluster with nMax overlapping showers
801 AliPHOSGetter * gime = AliPHOSGetter::Instance();
803 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
805 const TClonesArray * digits = gime->Digits() ;
806 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
807 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
809 Int_t nPar = 3 * nMax ;
810 Float_t * fitparameters = new Float_t[nPar] ;
812 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
814 // Fit failed, return and remove cluster
815 iniEmc->SetNExMax(-1) ;
816 delete[] fitparameters ;
820 // create ufolded rec points and fill them with new energy lists
821 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
822 // and later correct this number in acordance with actual energy deposition
824 Int_t nDigits = iniEmc->GetMultiplicity() ;
825 Float_t * efit = new Float_t[nDigits] ;
826 Float_t xDigit=0.,zDigit=0.,distance=0. ;
827 Float_t xpar=0.,zpar=0.,epar=0. ;
829 AliPHOSDigit * digit = 0 ;
830 Int_t * emcDigits = iniEmc->GetDigitsList() ;
834 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
835 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
836 geom->AbsToRelNumbering(digit->GetId(), relid) ;
837 geom->RelPosInModule(relid, xDigit, zDigit) ;
841 while(iparam < nPar ){
842 xpar = fitparameters[iparam] ;
843 zpar = fitparameters[iparam+1] ;
844 epar = fitparameters[iparam+2] ;
846 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
847 distance = TMath::Sqrt(distance) ;
848 efit[iDigit] += epar * ShowerShape(distance) ;
853 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
854 // so that energy deposited in each cell is distributed betwin new clusters proportionally
855 // to its contribution to efit
857 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
861 while(iparam < nPar ){
862 xpar = fitparameters[iparam] ;
863 zpar = fitparameters[iparam+1] ;
864 epar = fitparameters[iparam+2] ;
867 AliPHOSEmcRecPoint * emcRP = 0 ;
869 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
871 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
872 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
874 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
875 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
876 fNumberOfEmcClusters++ ;
877 emcRP->SetNExMax((Int_t)nPar/3) ;
879 else{//create new entries in fCpvRecPoints
880 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
881 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
883 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
884 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
885 fNumberOfCpvClusters++ ;
889 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
890 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
891 geom->AbsToRelNumbering(digit->GetId(), relid) ;
892 geom->RelPosInModule(relid, xDigit, zDigit) ;
893 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
894 distance = TMath::Sqrt(distance) ;
895 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
896 eDigit = emcEnergies[iDigit] * ratio ;
897 emcRP->AddDigit( *digit, eDigit ) ;
901 delete[] fitparameters ;
906 //_____________________________________________________________________________
907 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
909 // Calculates the Chi square for the cluster unfolding minimization
910 // Number of parameters, Gradient, Chi squared, parameters, what to do
912 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
914 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
915 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
919 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
921 Int_t * emcDigits = emcRP->GetDigitsList() ;
923 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
925 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
927 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
932 for(iparam = 0 ; iparam < nPar ; iparam++)
933 Grad[iparam] = 0 ; // Will evaluate gradient
937 AliPHOSDigit * digit ;
940 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
942 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
948 geom->AbsToRelNumbering(digit->GetId(), relid) ;
950 geom->RelPosInModule(relid, xDigit, zDigit) ;
952 if(iflag == 2){ // calculate gradient
955 while(iParam < nPar ){
956 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
958 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
959 distance = TMath::Sqrt( distance ) ;
961 efit += x[iParam] * ShowerShape(distance) ;
964 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
966 while(iParam < nPar ){
967 Double_t xpar = x[iParam] ;
968 Double_t zpar = x[iParam+1] ;
969 Double_t epar = x[iParam+2] ;
970 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
971 Double_t shape = sum * ShowerShape(dr) ;
972 Double_t r4 = dr*dr*dr*dr ;
973 Double_t r295 = TMath::Power(dr,2.95) ;
974 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
975 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
977 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
979 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
981 Grad[iParam] += shape ; // Derivative over energy
988 while(iparam < nPar ){
989 Double_t xpar = x[iparam] ;
990 Double_t zpar = x[iparam+1] ;
991 Double_t epar = x[iparam+2] ;
993 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
994 distance = TMath::Sqrt(distance) ;
995 efit += epar * ShowerShape(distance) ;
998 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
999 // Here we assume, that sigma = sqrt(E)
1004 //____________________________________________________________________________
1005 void AliPHOSClusterizerv1::Print(const Option_t *)const
1007 // Print clusterizer parameters
1010 TString taskName(GetName()) ;
1011 taskName.ReplaceAll(Version(), "") ;
1013 if( strcmp(GetName(), "") !=0 ) {
1015 message = "\n--------------- %s %s -----------\n" ;
1016 message += "Clusterizing digits from the file: %s\n" ;
1017 message += " Branch: %s\n" ;
1018 message += " EMC Clustering threshold = %f\n" ;
1019 message += " EMC Local Maximum cut = %f\n" ;
1020 message += " EMC Logarothmic weight = %f\n" ;
1021 message += " CPV Clustering threshold = %f\n" ;
1022 message += " CPV Local Maximum cut = %f\n" ;
1023 message += " CPV Logarothmic weight = %f\n" ;
1025 message += " Unfolding on\n" ;
1027 message += " Unfolding off\n" ;
1029 message += "------------------------------------------------------------------" ;
1032 message = " AliPHOSClusterizerv1 not initialized " ;
1034 AliInfo(Form("%s, %s %s %s %s %s %s %s %s %s %s", message.Data(),
1039 fEmcClusteringThreshold,
1042 fCpvClusteringThreshold,
1048 //____________________________________________________________________________
1049 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1051 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1053 AliPHOSGetter * gime = AliPHOSGetter::Instance();
1055 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1056 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1058 AliInfo(Form("\nevent %d \n Found %d EMC RecPoints and %d CPV RecPoints",
1059 gAlice->GetEvNumber(),
1060 emcRecPoints->GetEntriesFast(),
1061 cpvRecPoints->GetEntriesFast() )) ;
1063 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1064 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1067 if(strstr(option,"all")) {
1068 printf("\n EMC clusters \n") ;
1069 printf("Index Ene(MeV) Multi Module X Y Z Lambdas_1 Lambda_2 # of prim Primaries list\n") ;
1071 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1072 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1074 rp->GetLocalPosition(locpos);
1076 rp->GetElipsAxis(lambda);
1079 primaries = rp->GetPrimaries(nprimaries);
1080 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
1081 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
1082 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
1084 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
1085 printf("%d ", primaries[iprimary] ) ;
1090 //Now plot CPV recPoints
1091 printf("\n CPV clusters \n") ;
1092 printf("Index Ene(MeV) Module X Y Z \n") ;
1093 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1094 AliPHOSCpvRecPoint * rp = (AliPHOSCpvRecPoint * )cpvRecPoints->At(index) ;
1097 rp->GetLocalPosition(locpos);
1099 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f \n",
1100 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
1101 locpos.X(), locpos.Y(), locpos.Z()) ;