1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
19 // August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
20 // of new IO (à la PHOS)
21 //////////////////////////////////////////////////////////////////////////////
22 // Clusterization class. Performs clusterization (collects neighbouring active cells) and
23 // unfolds the clusters having several local maxima.
24 // Results are stored in TreeR#, branches EMCALTowerRP (EMC recPoints),
25 // EMCALPreShoRP (CPV RecPoints) and AliEMCALClusterizer (Clusterizer with all
26 // parameters including input digits branch title, thresholds etc.)
27 // This TTask is normally called from Reconstructioner, but can as well be used in
30 // root [0] AliEMCALClusterizerv1 * cl = new AliEMCALClusterizerv1("galice.root")
31 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
32 // //reads gAlice from header file "..."
33 // root [1] cl->ExecuteTask()
34 // //finds RecPoints in all events stored in galice.root
35 // root [2] cl->SetDigitsBranch("digits2")
36 // //sets another title for Digitis (input) branch
37 // root [3] cl->SetRecPointsBranch("recp2")
38 // //sets another title four output branches
39 // root [4] cl->SetTowerLocalMaxCut(0.03)
40 // //set clusterization parameters
41 // root [5] cl->ExecuteTask("deb all time")
42 // //once more finds RecPoints options are
43 // // deb - print number of found rec points
44 // // deb all - print number of found RecPoints and some their characteristics
45 // // time - print benchmarking results
47 // --- ROOT system ---
56 #include "TBenchmark.h"
58 // --- Standard library ---
61 // --- AliRoot header files ---
62 #include "AliEMCALGetter.h"
63 #include "AliEMCALClusterizerv1.h"
64 #include "AliEMCALTowerRecPoint.h"
65 #include "AliEMCALDigit.h"
66 #include "AliEMCALDigitizer.h"
68 #include "AliEMCALGeometry.h"
70 ClassImp(AliEMCALClusterizerv1)
72 //____________________________________________________________________________
73 AliEMCALClusterizerv1::AliEMCALClusterizerv1() : AliEMCALClusterizer()
75 // default ctor (to be used mainly by Streamer)
78 fDefaultInit = kTRUE ;
81 //____________________________________________________________________________
82 AliEMCALClusterizerv1::AliEMCALClusterizerv1(const TString alirunFileName, const TString eventFolderName)
83 :AliEMCALClusterizer(alirunFileName, eventFolderName)
85 // ctor with the indication of the file where header Tree and digits Tree are stored
89 fDefaultInit = kFALSE ;
93 //____________________________________________________________________________
94 AliEMCALClusterizerv1::~AliEMCALClusterizerv1()
100 //____________________________________________________________________________
101 const TString AliEMCALClusterizerv1::BranchName() const
107 //____________________________________________________________________________
108 Float_t AliEMCALClusterizerv1::Calibrate(Int_t amp) const
110 //To be replased later by the method, reading individual parameters from the database
111 return -fADCpedestalECA + amp * fADCchannelECA ;
114 //____________________________________________________________________________
115 void AliEMCALClusterizerv1::Exec(Option_t * option)
119 if(strstr(option,"tim"))
120 gBenchmark->Start("EMCALClusterizer");
122 if(strstr(option,"print"))
125 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
127 Int_t nevents = gime->MaxEvent() ;
130 for(ievent = 0; ievent < nevents; ievent++){
132 gime->Event(ievent,"D") ;
134 GetCalibrationParameters() ;
136 fNumberOfECAClusters = 0;
145 if(strstr(option,"deb"))
146 PrintRecPoints(option) ;
148 //increment the total number of recpoints per run
149 fRecPointsInRun += gime->ECARecPoints()->GetEntriesFast() ;
154 if(strstr(option,"tim")){
155 gBenchmark->Stop("EMCALClusterizer");
156 printf("Exec took %f seconds for Clusterizing %f seconds per event",
157 gBenchmark->GetCpuTime("EMCALClusterizer"), gBenchmark->GetCpuTime("EMCALClusterizer")/nevents ) ;
161 //____________________________________________________________________________
162 Bool_t AliEMCALClusterizerv1::FindFit(AliEMCALTowerRecPoint * emcRP, AliEMCALDigit ** maxAt, Float_t * maxAtEnergy,
163 Int_t nPar, Float_t * fitparameters) const
165 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
166 // The initial values for fitting procedure are set equal to the positions of local maxima.
167 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
169 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
170 TClonesArray * digits = gime->Digits() ;
172 gMinuit->mncler(); // Reset Minuit's list of paramters
173 gMinuit->SetPrintLevel(-1) ; // No Printout
174 gMinuit->SetFCN(AliEMCALClusterizerv1::UnfoldingChiSquare) ;
175 // To set the address of the minimization function
176 TList * toMinuit = new TList();
177 toMinuit->AddAt(emcRP,0) ;
178 toMinuit->AddAt(digits,1) ;
180 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
182 // filling initial values for fit parameters
183 AliEMCALDigit * digit ;
187 Int_t nDigits = (Int_t) nPar / 3 ;
191 AliEMCALGeometry * geom = gime->EMCALGeometry() ;
193 for(iDigit = 0; iDigit < nDigits; iDigit++){
194 digit = maxAt[iDigit];
199 geom->AbsToRelNumbering(digit->GetId(), relid) ;
200 geom->PosInAlice(relid, x, z) ;
202 Float_t energy = maxAtEnergy[iDigit] ;
204 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
207 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : x = %f", x ) ;
210 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
213 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : z = %f", z) ;
216 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
219 Error("FindFit", "EMCAL Unfolding Unable to set initial value for fit procedure : energy = %f", energy) ;
224 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
229 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
230 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
231 gMinuit->SetMaxIterations(5);
232 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
234 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
236 if(ierflg == 4){ // Minimum not found
237 Error("FindFit", "EMCAL Unfolding Fit not converged, cluster abandoned " ) ;
240 for(index = 0; index < nPar; index++){
243 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
244 fitparameters[index] = val ;
252 //____________________________________________________________________________
253 void AliEMCALClusterizerv1::GetCalibrationParameters()
255 // Gets the parameters for the calibration from the digitizer
256 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
258 if ( !gime->Digitizer() )
259 gime->LoadDigitizer();
260 AliEMCALDigitizer * dig = gime->Digitizer();
262 fADCchannelECA = dig->GetECAchannel() ;
263 fADCpedestalECA = dig->GetECApedestal();
266 //____________________________________________________________________________
267 void AliEMCALClusterizerv1::Init()
269 // Make all memory allocations which can not be done in default constructor.
270 // Attach the Clusterizer task to the list of EMCAL tasks
272 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName.Data());
274 AliEMCALGeometry * geom = gime->EMCALGeometry() ;
276 fNTowers = geom->GetNZ() * geom->GetNPhi() ;
278 gMinuit = new TMinuit(100) ;
280 if ( !gime->Clusterizer() )
281 gime->PostClusterizer(this);
284 //____________________________________________________________________________
285 void AliEMCALClusterizerv1::InitParameters()
287 // Initializes the parameters for the Clusterizer
288 fNumberOfECAClusters = 0;
289 fECAClusteringThreshold = 0.0045; // must be adjusted according to the noise leve set by digitizer
290 fECALocMaxCut = 0.03 ;
294 fRecPointsInRun = 0 ;
297 //____________________________________________________________________________
298 Int_t AliEMCALClusterizerv1::AreNeighbours(AliEMCALDigit * d1, AliEMCALDigit * d2)const
300 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
302 // = 2 are not neighbour but do not continue searching
303 // neighbours are defined as digits having at least a common vertex
304 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
305 // which is compared to a digit (d2) not yet in a cluster
307 AliEMCALGeometry * geom = AliEMCALGetter::Instance()->EMCALGeometry() ;
312 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
315 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
317 if ( (relid1[0] == relid2[0])){ // inside the same EMCAL Arm
318 Int_t rowdiff = TMath::Abs( relid1[1] - relid2[1] ) ;
319 Int_t coldiff = TMath::Abs( relid1[2] - relid2[2] ) ;
321 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
322 if(TMath::Abs(d1->GetTime() - d2->GetTime() ) < fTimeGate)
326 if((relid2[1] > relid1[1]) && (relid2[2] > relid1[2]+1))
327 rv = 2; // Difference in row numbers is too large to look further
333 if(relid1[0] < relid2[0])
338 printf("AreNeighbours: neighbours=%d, id1=%d, relid1=%d,%d,%d \n id2=%d, relid2=%d,%d,%d ",
339 rv, d1->GetId(), relid1[0], relid1[1], relid1[2],
340 d2->GetId(), relid2[0], relid2[1], relid2[2]) ;
345 //____________________________________________________________________________
346 void AliEMCALClusterizerv1::Unload()
348 // Unloads the Digits and RecPoints
349 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
350 gime->EmcalLoader()->UnloadDigits() ;
351 gime->EmcalLoader()->UnloadRecPoints() ;
354 //____________________________________________________________________________
355 void AliEMCALClusterizerv1::WriteRecPoints()
358 // Creates new branches with given title
359 // fills and writes into TreeR.
361 AliEMCALGetter *gime = AliEMCALGetter::Instance() ;
363 TObjArray * aECARecPoints = gime->ECARecPoints() ;
365 TClonesArray * digits = gime->Digits() ;
366 TTree * treeR = gime->TreeR(); ;
370 //Evaluate position, dispersion and other RecPoint properties for EC section
371 for(index = 0; index < aECARecPoints->GetEntries(); index++)
372 (dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(index)))->EvalAll(fECAW0,digits) ;
374 aECARecPoints->Sort() ;
376 for(index = 0; index < aECARecPoints->GetEntries(); index++)
377 (dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(index)))->SetIndexInList(index) ;
379 aECARecPoints->Expand(aECARecPoints->GetEntriesFast()) ;
381 Int_t bufferSize = 32000 ;
382 Int_t splitlevel = 0 ;
385 TBranch * branchECA = treeR->Branch("EMCALECARP","TObjArray",&aECARecPoints,bufferSize,splitlevel);
386 branchECA->SetTitle(BranchName());
390 gime->WriteRecPoints("OVERWRITE");
391 gime->WriteClusterizer("OVERWRITE");
394 //____________________________________________________________________________
395 void AliEMCALClusterizerv1::MakeClusters()
397 // Steering method to construct the clusters stored in a list of Reconstructed Points
398 // A cluster is defined as a list of neighbour digits
400 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
402 AliEMCALGeometry * geom = gime->EMCALGeometry() ;
404 TObjArray * aECARecPoints = gime->ECARecPoints() ;
406 aECARecPoints->Delete() ;
408 TClonesArray * digits = gime->Digits() ;
411 AliEMCALDigit * digit ;
414 // count the number of digits in ECA section
415 while ( (digit = dynamic_cast<AliEMCALDigit *>(next())) ) { // scan over the list of digits
416 if (geom->IsInECA(digit->GetId()))
419 Error("MakeClusters", "id = %d is a wrong ID!", digit->GetId()) ;
423 TClonesArray * digitsC = dynamic_cast<TClonesArray*>(digits->Clone()) ;
424 // Clusterization starts
426 TIter nextdigit(digitsC) ;
428 while ( (digit = dynamic_cast<AliEMCALDigit *>(nextdigit())) ) { // scan over the list of digitsC
429 AliEMCALRecPoint * clu = 0 ;
431 TArrayI clusterECAdigitslist(50);
433 Bool_t inECA = kFALSE;
434 if( geom->IsInECA(digit->GetId()) ) {
439 printf("MakeClusters: id = %d, ene = %f , thre = %f",
440 digit->GetId(),Calibrate(digit->GetAmp()), fECAClusteringThreshold) ;
442 if (inECA && (Calibrate(digit->GetAmp()) > fECAClusteringThreshold ) ){
444 Int_t iDigitInECACluster = 0;
446 if( geom->IsInECA(digit->GetId()) ) {
447 // start a new Tower RecPoint
448 if(fNumberOfECAClusters >= aECARecPoints->GetSize())
449 aECARecPoints->Expand(2*fNumberOfECAClusters+1) ;
450 AliEMCALTowerRecPoint * rp = new AliEMCALTowerRecPoint("") ;
452 aECARecPoints->AddAt(rp, fNumberOfECAClusters) ;
453 clu = dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(fNumberOfECAClusters)) ;
454 fNumberOfECAClusters++ ;
455 clu->AddDigit(*digit, Calibrate(digit->GetAmp())) ;
456 clusterECAdigitslist[iDigitInECACluster] = digit->GetIndexInList() ;
457 iDigitInECACluster++ ;
458 digitsC->Remove(digit) ;
460 printf("MakeClusters: OK id = %d, ene = %f , thre = %f ", digit->GetId(),Calibrate(digit->GetAmp()), fECAClusteringThreshold) ;
465 AliEMCALDigit * digitN ;
470 while (index < iDigitInECACluster){ // scan over digits already in cluster
471 digit = (AliEMCALDigit*)digits->At(clusterECAdigitslist[index]) ;
473 while ( (digitN = (AliEMCALDigit *)nextdigit()) ) { // scan over the reduced list of digits
474 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
476 case 0 : // not a neighbour
478 case 1 : // are neighbours
479 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp()) ) ;
480 clusterECAdigitslist[iDigitInECACluster] = digitN->GetIndexInList() ;
481 iDigitInECACluster++ ;
482 digitsC->Remove(digitN) ;
484 case 2 : // too far from each other
492 } // loop over ECA cluster
498 //____________________________________________________________________________
499 void AliEMCALClusterizerv1::MakeUnfolding() const
501 Fatal("AliEMCALClusterizerv1::MakeUnfolding", "--> Unfolding not implemented") ;
505 //____________________________________________________________________________
506 Double_t AliEMCALClusterizerv1::ShowerShape(Double_t r)
508 // Shape of the shower (see EMCAL TDR)
509 // If you change this function, change also the gradient evaluation in ChiSquare()
511 Double_t r4 = r*r*r*r ;
512 Double_t r295 = TMath::Power(r, 2.95) ;
513 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
517 //____________________________________________________________________________
518 void AliEMCALClusterizerv1::UnfoldCluster(AliEMCALTowerRecPoint * /*iniTower*/,
520 AliEMCALDigit ** /*maxAt*/,
521 Float_t * /*maxAtEnergy*/) const
523 // Performs the unfolding of a cluster with nMax overlapping showers
525 Fatal("UnfoldCluster", "--> Unfolding not implemented") ;
529 //_____________________________________________________________________________
530 void AliEMCALClusterizerv1::UnfoldingChiSquare(Int_t & /*nPar*/, Double_t * /*Grad*/,
532 Double_t * /*x*/, Int_t /*iflag*/)
534 // Calculates the Chi square for the cluster unfolding minimization
535 // Number of parameters, Gradient, Chi squared, parameters, what to do
537 ::Fatal("UnfoldingChiSquare","Unfolding not implemented") ;
539 //____________________________________________________________________________
540 void AliEMCALClusterizerv1::Print(Option_t * /*option*/)const
542 // Print clusterizer parameters
544 TString message("\n") ;
546 if( strcmp(GetName(), "") !=0 ){
550 TString taskName(GetName()) ;
551 taskName.ReplaceAll(Version(), "") ;
553 printf("--------------- ");
554 printf(taskName.Data()) ;
557 printf("-----------\n");
558 printf("Clusterizing digits from the file: ");
559 printf(taskName.Data());
560 printf("\n Branch: ");
562 printf("\n ECA Local Maximum cut = %f", fECALocMaxCut);
563 printf("\n ECA Logarothmic weight = %f", fECAW0);
565 printf("\nUnfolding on\n");
567 printf("\nUnfolding off\n");
569 printf("------------------------------------------------------------------");
572 printf("AliEMCALClusterizerv1 not initialized ") ;
575 //____________________________________________________________________________
576 void AliEMCALClusterizerv1::PrintRecPoints(Option_t * option)
578 // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
579 TObjArray * aECARecPoints = AliEMCALGetter::Instance()->ECARecPoints() ;
580 printf("PrintRecPoints: Clusterization result:") ;
582 printf("event # %d\n", gAlice->GetEvNumber() ) ;
583 printf(" Found %d ECA Rec Points\n ",
584 aECARecPoints->GetEntriesFast()) ;
586 fRecPointsInRun += aECARecPoints->GetEntriesFast() ;
588 if(strstr(option,"all")) {
590 printf("\n-----------------------------------------------------------------------\n") ;
591 printf("Clusters in ECAL section\n") ;
592 printf("Index Ene(GeV) Multi Module phi r theta X Y Z Dispersion Lambda 1 Lambda 2 # of prim Primaries list\n") ;
594 for (index = 0 ; index < aECARecPoints->GetEntries() ; index++) {
595 AliEMCALTowerRecPoint * rp = dynamic_cast<AliEMCALTowerRecPoint * >(aECARecPoints->At(index)) ;
597 rp->GetGlobalPosition(globalpos);
599 rp->GetLocalPosition(localpos);
601 rp->GetElipsAxis(lambda);
604 primaries = rp->GetPrimaries(nprimaries);
605 printf("\n%6d %8.4f %3d %2d %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4f %4f %2d : ",
606 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetEMCALArm(),
607 globalpos.X(), globalpos.Y(), globalpos.Z(), localpos.X(), localpos.Y(), localpos.Z(),
608 rp->GetDispersion(), lambda[0], lambda[1], nprimaries) ;
609 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
610 printf("%d ", primaries[iprimary] ) ;
613 printf("\n-----------------------------------------------------------------------\n");