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.88 2006/01/11 08:54:52 hristov
22 * Additional protection in case no calibration entry was found
24 * Revision 1.87 2005/11/22 08:46:43 kharlov
25 * Updated to new CDB (Boris Polichtchouk)
27 * Revision 1.86 2005/11/14 21:52:43 hristov
30 * Revision 1.85 2005/09/27 16:08:08 hristov
31 * New version of CDB storage framework (A.Colla)
33 * Revision 1.84 2005/09/21 10:02:47 kharlov
34 * Reading calibration from CDB (Boris Polichtchouk)
36 * Revision 1.82 2005/09/02 15:43:13 kharlov
37 * Add comments in GetCalibrationParameters and Calibrate
39 * Revision 1.81 2005/09/02 14:32:07 kharlov
40 * Calibration of raw data
42 * Revision 1.80 2005/08/24 15:31:36 kharlov
43 * Setting raw digits flag
45 * Revision 1.79 2005/07/25 15:53:53 kharlov
48 * Revision 1.78 2005/05/28 14:19:04 schutz
49 * Compilation warnings fixed by T.P.
53 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
54 //////////////////////////////////////////////////////////////////////////////
55 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
56 // unfolds the clusters having several local maxima.
57 // Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
58 // PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
59 // parameters including input digits branch title, thresholds etc.)
60 // This TTask is normally called from Reconstructioner, but can as well be used in
63 // root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
64 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
65 // // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
66 // // and saves recpoints in branch named "recpointsname" (default = "digitsname")
67 // root [1] cl->ExecuteTask()
68 // //finds RecPoints in all events stored in galice.root
69 // root [2] cl->SetDigitsBranch("digits2")
70 // //sets another title for Digitis (input) branch
71 // root [3] cl->SetRecPointsBranch("recp2")
72 // //sets another title four output branches
73 // root [4] cl->SetEmcLocalMaxCut(0.03)
74 // //set clusterization parameters
75 // root [5] cl->ExecuteTask("deb all time")
76 // //once more finds RecPoints options are
77 // // deb - print number of found rec points
78 // // deb all - print number of found RecPoints and some their characteristics
79 // // time - print benchmarking results
81 // --- ROOT system ---
86 #include "TBenchmark.h"
88 // --- Standard library ---
90 // --- AliRoot header files ---
92 #include "AliPHOSGetter.h"
93 #include "AliPHOSGeometry.h"
94 #include "AliPHOSClusterizerv1.h"
95 #include "AliPHOSEmcRecPoint.h"
96 #include "AliPHOSCpvRecPoint.h"
97 #include "AliPHOSDigit.h"
98 #include "AliPHOSDigitizer.h"
99 #include "AliPHOSCalibrationDB.h"
100 #include "AliCDBManager.h"
101 #include "AliCDBStorage.h"
102 #include "AliCDBEntry.h"
104 ClassImp(AliPHOSClusterizerv1)
106 //____________________________________________________________________________
107 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
109 // default ctor (to be used mainly by Streamer)
112 fDefaultInit = kTRUE ;
115 //____________________________________________________________________________
116 AliPHOSClusterizerv1::AliPHOSClusterizerv1(const TString alirunFileName, const TString eventFolderName)
117 :AliPHOSClusterizer(alirunFileName, eventFolderName)
119 // ctor with the indication of the file where header Tree and digits Tree are stored
123 fDefaultInit = kFALSE ;
126 //____________________________________________________________________________
127 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
132 //____________________________________________________________________________
133 const TString AliPHOSClusterizerv1::BranchName() const
138 //____________________________________________________________________________
139 Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId)
141 // Convert digitized amplitude into energy.
142 // Calibration parameters are taken from calibration data base for raw data,
143 // or from digitizer parameters for simulated data.
147 AliPHOSGetter *gime = AliPHOSGetter::Instance();
148 gime->PHOSGeometry()->AbsToRelNumbering(absId,relId) ;
149 Int_t module = relId[0];
150 Int_t column = relId[3];
151 Int_t row = relId[2];
152 if(absId <= fEmcCrystals) { //calibrate as EMC
153 fADCchanelEmc = fCalibData->GetADCchannelEmc (module,column,row);
154 fADCpedestalEmc = fCalibData->GetADCpedestalEmc(module,column,row);
155 return fADCpedestalEmc + amp*fADCchanelEmc ;
157 else { //calibrate as CPV
158 fADCchanelCpv = fCalibData->GetADCchannelCpv (module,column,row);
159 fADCpedestalCpv = fCalibData->GetADCpedestalCpv(module,column,row);
160 return fADCpedestalCpv + amp*fADCchanelCpv ;
164 if(absId <= fEmcCrystals) //calibrate as EMC
165 return fADCpedestalEmc + amp*fADCchanelEmc ;
166 else //calibrate as CPV
167 return fADCpedestalCpv+ amp*fADCchanelCpv ;
171 //____________________________________________________________________________
172 void AliPHOSClusterizerv1::Exec(Option_t *option)
174 // Steering method to perform clusterization for events
175 // in the range from fFirstEvent to fLastEvent.
176 // This range is optionally set by SetEventRange().
177 // if fLastEvent=-1 (by default), then process events until the end.
179 if(strstr(option,"tim"))
180 gBenchmark->Start("PHOSClusterizer");
182 if(strstr(option,"print")) {
187 GetCalibrationParameters() ;
189 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
191 gime->SetRawDigits(kFALSE);
193 gime->SetRawDigits(kTRUE);
195 if (fLastEvent == -1)
196 fLastEvent = gime->MaxEvent() - 1 ;
198 fLastEvent = TMath::Min(fFirstEvent, gime->MaxEvent()); // one event at the time
199 Int_t nEvents = fLastEvent - fFirstEvent + 1;
202 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
204 gime->Event(ievent ,"D"); // Read digits from simulated data
206 gime->Event(fRawReader,"W"); // Read digits from raw data
208 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
217 if(strstr(option,"deb"))
218 PrintRecPoints(option) ;
220 //increment the total number of recpoints per run
221 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
222 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
225 if(fWrite) //do not unload in "on flight" mode
228 if(strstr(option,"tim")){
229 gBenchmark->Stop("PHOSClusterizer");
230 AliInfo(Form("took %f seconds for Clusterizing %f seconds per event \n",
231 gBenchmark->GetCpuTime("PHOSClusterizer"),
232 gBenchmark->GetCpuTime("PHOSClusterizer")/nEvents )) ;
236 //____________________________________________________________________________
237 Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
238 Int_t nPar, Float_t * fitparameters) const
240 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
241 // The initial values for fitting procedure are set equal to the positions of local maxima.
242 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
245 AliPHOSGetter * gime = AliPHOSGetter::Instance();
246 TClonesArray * digits = gime->Digits();
249 gMinuit->mncler(); // Reset Minuit's list of paramters
250 gMinuit->SetPrintLevel(-1) ; // No Printout
251 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
252 // To set the address of the minimization function
254 TList * toMinuit = new TList();
255 toMinuit->AddAt(emcRP,0) ;
256 toMinuit->AddAt(digits,1) ;
258 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
260 // filling initial values for fit parameters
261 AliPHOSDigit * digit ;
265 Int_t nDigits = (Int_t) nPar / 3 ;
269 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
271 for(iDigit = 0; iDigit < nDigits; iDigit++){
272 digit = maxAt[iDigit];
277 geom->AbsToRelNumbering(digit->GetId(), relid) ;
278 geom->RelPosInModule(relid, x, z) ;
280 Float_t energy = maxAtEnergy[iDigit] ;
282 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
285 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
288 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
291 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
294 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
297 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
302 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
307 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
308 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
309 gMinuit->SetMaxIterations(5);
310 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
312 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
314 if(ierflg == 4){ // Minimum not found
315 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
318 for(index = 0; index < nPar; index++){
321 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
322 fitparameters[index] = val ;
330 //____________________________________________________________________________
331 void AliPHOSClusterizerv1::GetCalibrationParameters()
333 // Set calibration parameters:
334 // if calibration database exists, they are read from database,
335 // otherwise, they are taken from digitizer.
337 // It is a user responsilibity to open CDB before reconstruction, for example:
338 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
340 AliPHOSGetter * gime = AliPHOSGetter::Instance();
341 fCalibData = new AliPHOSCalibData(gAlice->GetRunNumber());
345 if ( !gime->Digitizer() )
346 gime->LoadDigitizer();
347 AliPHOSDigitizer * dig = gime->Digitizer();
348 fADCchanelEmc = dig->GetEMCchannel() ;
349 fADCpedestalEmc = dig->GetEMCpedestal();
351 fADCchanelCpv = dig->GetCPVchannel() ;
352 fADCpedestalCpv = dig->GetCPVpedestal() ;
356 //____________________________________________________________________________
357 void AliPHOSClusterizerv1::Init()
359 // Make all memory allocations which can not be done in default constructor.
360 // Attach the Clusterizer task to the list of PHOS tasks
362 AliPHOSGetter* gime = AliPHOSGetter::Instance() ;
364 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
366 AliPHOSGeometry * geom = gime->PHOSGeometry();
368 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
371 gMinuit = new TMinuit(100);
373 if ( !gime->Clusterizer() ) {
374 gime->PostClusterizer(this);
378 //____________________________________________________________________________
379 void AliPHOSClusterizerv1::InitParameters()
382 fNumberOfCpvClusters = 0 ;
383 fNumberOfEmcClusters = 0 ;
385 fCpvClusteringThreshold = 0.0;
386 fEmcClusteringThreshold = 0.2;
388 fEmcLocMaxCut = 0.03 ;
389 fCpvLocMaxCut = 0.03 ;
397 fEmcTimeGate = 1.e-8 ;
401 fRecPointsInRun = 0 ;
407 SetEventRange(0,-1) ;
410 //____________________________________________________________________________
411 Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
413 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
415 // = 2 are not neighbour but do not continue searching
416 // neighbours are defined as digits having at least a common vertex
417 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
418 // which is compared to a digit (d2) not yet in a cluster
420 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
425 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
428 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
430 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
431 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
432 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
434 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
435 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
439 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
440 rv = 2; // Difference in row numbers is too large to look further
446 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
453 //____________________________________________________________________________
454 void AliPHOSClusterizerv1::CleanDigits(TClonesArray * digits){
455 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
456 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
457 Float_t cut = IsInEmc(digit) ? fEmcMinE : fCpvMinE ;
458 if(Calibrate(digit->GetAmp(),digit->GetId()) < cut)
459 digits->RemoveAt(i) ;
462 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
463 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
464 digit->SetIndexInList(i) ;
468 //____________________________________________________________________________
469 Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
471 // Tells if (true) or not (false) the digit is in a PHOS-EMC 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 Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
486 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
490 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
492 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
494 if(digit->GetId() > nEMC ) rv = kTRUE;
499 //____________________________________________________________________________
500 void AliPHOSClusterizerv1::Unload()
502 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
503 gime->PhosLoader()->UnloadDigits() ;
504 gime->PhosLoader()->UnloadRecPoints() ;
507 //____________________________________________________________________________
508 void AliPHOSClusterizerv1::WriteRecPoints()
511 // Creates new branches with given title
512 // fills and writes into TreeR.
514 AliPHOSGetter * gime = AliPHOSGetter::Instance();
516 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
517 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
518 TClonesArray * digits = gime->Digits() ;
522 //Evaluate position, dispersion and other RecPoint properties..
523 Int_t nEmc = emcRecPoints->GetEntriesFast();
524 for(index = 0; index < nEmc; index++){
525 AliPHOSEmcRecPoint * rp = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) );
526 rp->Purify(fEmcMinE) ;
527 if(rp->GetMultiplicity()>0.) //If this RP is not empty
528 rp->EvalAll(fW0,digits) ;
530 emcRecPoints->RemoveAt(index) ;
534 emcRecPoints->Compress() ;
535 emcRecPoints->Sort() ;
536 // emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
537 for(index = 0; index < emcRecPoints->GetEntries(); index++){
538 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
541 //Now the same for CPV
542 for(index = 0; index < cpvRecPoints->GetEntries(); index++){
543 AliPHOSCpvRecPoint * rp = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) );
544 rp->EvalAll(fW0CPV,digits) ;
546 cpvRecPoints->Sort() ;
548 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
549 dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
551 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
553 if(fWrite){ //We write TreeR
554 TTree * treeR = gime->TreeR();
556 Int_t bufferSize = 32000 ;
557 Int_t splitlevel = 0 ;
560 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
561 emcBranch->SetTitle(BranchName());
564 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
565 cpvBranch->SetTitle(BranchName());
570 gime->WriteRecPoints("OVERWRITE");
571 gime->WriteClusterizer("OVERWRITE");
575 //____________________________________________________________________________
576 void AliPHOSClusterizerv1::MakeClusters()
578 // Steering method to construct the clusters stored in a list of Reconstructed Points
579 // A cluster is defined as a list of neighbour digits
582 AliPHOSGetter * gime = AliPHOSGetter::Instance();
584 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
585 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
587 emcRecPoints->Delete() ;
588 cpvRecPoints->Delete() ;
590 TClonesArray * digits = gime->Digits() ;
592 //Remove digits below threshold
593 CleanDigits(digits) ;
596 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
599 // Clusterization starts
601 TIter nextdigit(digitsC) ;
602 AliPHOSDigit * digit ;
603 Bool_t notremoved = kTRUE ;
605 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
608 AliPHOSRecPoint * clu = 0 ;
610 TArrayI clusterdigitslist(1500) ;
613 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
614 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
615 Int_t iDigitInCluster = 0 ;
617 if ( IsInEmc(digit) ) {
618 // start a new EMC RecPoint
619 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
620 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
622 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
623 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
624 fNumberOfEmcClusters++ ;
625 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
626 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
628 digitsC->Remove(digit) ;
632 // start a new CPV cluster
633 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
634 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
636 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
638 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
639 fNumberOfCpvClusters++ ;
640 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
641 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
643 digitsC->Remove(digit) ;
646 // Here we remove remaining EMC digits, which cannot make a cluster
649 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
651 digitsC->Remove(digit) ;
655 notremoved = kFALSE ;
662 AliPHOSDigit * digitN ;
664 while (index < iDigitInCluster){ // scan over digits already in cluster
665 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
667 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
668 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
670 case 0 : // not a neighbour
672 case 1 : // are neighbours
673 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
674 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
676 digitsC->Remove(digitN) ;
678 case 2 : // too far from each other
687 } // loop over cluster
698 //____________________________________________________________________________
699 void AliPHOSClusterizerv1::MakeUnfolding()
701 // Unfolds clusters using the shape of an ElectroMagnetic shower
702 // Performs unfolding of all EMC/CPV clusters
704 AliPHOSGetter * gime = AliPHOSGetter::Instance();
706 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
708 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
709 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
710 TClonesArray * digits = gime->Digits() ;
712 // Unfold first EMC clusters
713 if(fNumberOfEmcClusters > 0){
715 Int_t nModulesToUnfold = geom->GetNModules() ;
717 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
719 for(index = 0 ; index < numberofNotUnfolded ; index++){
721 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
722 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
725 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
726 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
727 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
728 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
730 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
731 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
732 emcRecPoints->Remove(emcRecPoint);
733 emcRecPoints->Compress() ;
735 fNumberOfEmcClusters -- ;
736 numberofNotUnfolded-- ;
739 emcRecPoint->SetNExMax(1) ; //Only one local maximum
743 delete[] maxAtEnergy ;
746 // Unfolding of EMC clusters finished
749 // Unfold now CPV clusters
750 if(fNumberOfCpvClusters > 0){
752 Int_t nModulesToUnfold = geom->GetNModules() ;
754 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
756 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
758 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
760 if(recPoint->GetPHOSMod()> nModulesToUnfold)
763 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
765 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
766 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
767 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
768 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
770 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
771 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
772 cpvRecPoints->Remove(emcRecPoint);
773 cpvRecPoints->Compress() ;
775 numberofCpvNotUnfolded-- ;
776 fNumberOfCpvClusters-- ;
780 delete[] maxAtEnergy ;
783 //Unfolding of Cpv clusters finished
787 //____________________________________________________________________________
788 Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
790 // Shape of the shower (see PHOS TDR)
791 // If you change this function, change also the gradient evaluation in ChiSquare()
793 Double_t r4 = r*r*r*r ;
794 Double_t r295 = TMath::Power(r, 2.95) ;
795 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
799 //____________________________________________________________________________
800 void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
802 AliPHOSDigit ** maxAt,
803 Float_t * maxAtEnergy)
805 // Performs the unfolding of a cluster with nMax overlapping showers
807 AliPHOSGetter * gime = AliPHOSGetter::Instance();
809 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
811 const TClonesArray * digits = gime->Digits() ;
812 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
813 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
815 Int_t nPar = 3 * nMax ;
816 Float_t * fitparameters = new Float_t[nPar] ;
818 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
820 // Fit failed, return and remove cluster
821 iniEmc->SetNExMax(-1) ;
822 delete[] fitparameters ;
826 // create ufolded rec points and fill them with new energy lists
827 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
828 // and later correct this number in acordance with actual energy deposition
830 Int_t nDigits = iniEmc->GetMultiplicity() ;
831 Float_t * efit = new Float_t[nDigits] ;
832 Float_t xDigit=0.,zDigit=0.,distance=0. ;
833 Float_t xpar=0.,zpar=0.,epar=0. ;
835 AliPHOSDigit * digit = 0 ;
836 Int_t * emcDigits = iniEmc->GetDigitsList() ;
840 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
841 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
842 geom->AbsToRelNumbering(digit->GetId(), relid) ;
843 geom->RelPosInModule(relid, xDigit, zDigit) ;
847 while(iparam < nPar ){
848 xpar = fitparameters[iparam] ;
849 zpar = fitparameters[iparam+1] ;
850 epar = fitparameters[iparam+2] ;
852 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
853 distance = TMath::Sqrt(distance) ;
854 efit[iDigit] += epar * ShowerShape(distance) ;
859 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
860 // so that energy deposited in each cell is distributed betwin new clusters proportionally
861 // to its contribution to efit
863 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
867 while(iparam < nPar ){
868 xpar = fitparameters[iparam] ;
869 zpar = fitparameters[iparam+1] ;
870 epar = fitparameters[iparam+2] ;
873 AliPHOSEmcRecPoint * emcRP = 0 ;
875 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
877 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
878 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
880 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
881 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
882 fNumberOfEmcClusters++ ;
883 emcRP->SetNExMax((Int_t)nPar/3) ;
885 else{//create new entries in fCpvRecPoints
886 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
887 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
889 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
890 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
891 fNumberOfCpvClusters++ ;
895 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
896 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
897 geom->AbsToRelNumbering(digit->GetId(), relid) ;
898 geom->RelPosInModule(relid, xDigit, zDigit) ;
899 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
900 distance = TMath::Sqrt(distance) ;
901 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
902 eDigit = emcEnergies[iDigit] * ratio ;
903 emcRP->AddDigit( *digit, eDigit ) ;
907 delete[] fitparameters ;
912 //_____________________________________________________________________________
913 void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
915 // Calculates the Chi square for the cluster unfolding minimization
916 // Number of parameters, Gradient, Chi squared, parameters, what to do
918 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
920 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
921 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
925 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
927 Int_t * emcDigits = emcRP->GetDigitsList() ;
929 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
931 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
933 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
938 for(iparam = 0 ; iparam < nPar ; iparam++)
939 Grad[iparam] = 0 ; // Will evaluate gradient
943 AliPHOSDigit * digit ;
946 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
948 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
954 geom->AbsToRelNumbering(digit->GetId(), relid) ;
956 geom->RelPosInModule(relid, xDigit, zDigit) ;
958 if(iflag == 2){ // calculate gradient
961 while(iParam < nPar ){
962 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
964 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
965 distance = TMath::Sqrt( distance ) ;
967 efit += x[iParam] * ShowerShape(distance) ;
970 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
972 while(iParam < nPar ){
973 Double_t xpar = x[iParam] ;
974 Double_t zpar = x[iParam+1] ;
975 Double_t epar = x[iParam+2] ;
976 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
977 Double_t shape = sum * ShowerShape(dr) ;
978 Double_t r4 = dr*dr*dr*dr ;
979 Double_t r295 = TMath::Power(dr,2.95) ;
980 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
981 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
983 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
985 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
987 Grad[iParam] += shape ; // Derivative over energy
994 while(iparam < nPar ){
995 Double_t xpar = x[iparam] ;
996 Double_t zpar = x[iparam+1] ;
997 Double_t epar = x[iparam+2] ;
999 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
1000 distance = TMath::Sqrt(distance) ;
1001 efit += epar * ShowerShape(distance) ;
1004 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
1005 // Here we assume, that sigma = sqrt(E)
1010 //____________________________________________________________________________
1011 void AliPHOSClusterizerv1::Print(const Option_t *)const
1013 // Print clusterizer parameters
1016 TString taskName(GetName()) ;
1017 taskName.ReplaceAll(Version(), "") ;
1019 if( strcmp(GetName(), "") !=0 ) {
1021 message = "\n--------------- %s %s -----------\n" ;
1022 message += "Clusterizing digits from the file: %s\n" ;
1023 message += " Branch: %s\n" ;
1024 message += " EMC Clustering threshold = %f\n" ;
1025 message += " EMC Local Maximum cut = %f\n" ;
1026 message += " EMC Logarothmic weight = %f\n" ;
1027 message += " CPV Clustering threshold = %f\n" ;
1028 message += " CPV Local Maximum cut = %f\n" ;
1029 message += " CPV Logarothmic weight = %f\n" ;
1031 message += " Unfolding on\n" ;
1033 message += " Unfolding off\n" ;
1035 message += "------------------------------------------------------------------" ;
1038 message = " AliPHOSClusterizerv1 not initialized " ;
1040 AliInfo(Form("%s, %s %s %s %s %s %s %s %s %s %s", message.Data(),
1045 fEmcClusteringThreshold,
1048 fCpvClusteringThreshold,
1054 //____________________________________________________________________________
1055 void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
1057 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
1059 AliPHOSGetter * gime = AliPHOSGetter::Instance();
1061 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
1062 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
1064 AliInfo(Form("\nevent %d \n Found %d EMC RecPoints and %d CPV RecPoints",
1065 gAlice->GetEvNumber(),
1066 emcRecPoints->GetEntriesFast(),
1067 cpvRecPoints->GetEntriesFast() )) ;
1069 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
1070 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
1073 if(strstr(option,"all")) {
1074 printf("\n EMC clusters \n") ;
1075 printf("Index Ene(MeV) Multi Module X Y Z Lambdas_1 Lambda_2 # of prim Primaries list\n") ;
1077 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
1078 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
1080 rp->GetLocalPosition(locpos);
1082 rp->GetElipsAxis(lambda);
1085 primaries = rp->GetPrimaries(nprimaries);
1086 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
1087 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
1088 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
1090 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
1091 printf("%d ", primaries[iprimary] ) ;
1096 //Now plot CPV recPoints
1097 printf("\n CPV clusters \n") ;
1098 printf("Index Ene(MeV) Module X Y Z \n") ;
1099 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
1100 AliPHOSCpvRecPoint * rp = (AliPHOSCpvRecPoint * )cpvRecPoints->At(index) ;
1103 rp->GetLocalPosition(locpos);
1105 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f \n",
1106 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
1107 locpos.X(), locpos.Y(), locpos.Z()) ;