]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSClusterizerv1.cxx
polish
[u/mrichter/AliRoot.git] / PHOS / AliPHOSClusterizerv1.cxx
CommitLineData
d15a28e7 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
b2a60966 16/* $Id$ */
17
9a1398dd 18//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (SUBATECH & Kurchatov Institute)
d15a28e7 19//////////////////////////////////////////////////////////////////////////////
9a1398dd 20// Clusterization class. Performs clusterization (collects neighbouring active cells) and
a4e98857 21// unfolds the clusters having several local maxima.
22// Results are stored in TreeR#, branches PHOSEmcRP (EMC recPoints),
9a1398dd 23// PHOSCpvRP (CPV RecPoints) and AliPHOSClusterizer (Clusterizer with all
f035f6ce 24// parameters including input digits branch title, thresholds etc.)
a4e98857 25// This TTask is normally called from Reconstructioner, but can as well be used in
26// standalone mode.
27// Use Case:
fc12304f 28// root [0] AliPHOSClusterizerv1 * cl = new AliPHOSClusterizerv1("galice.root", "recpointsname", "digitsname")
a4e98857 29// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
fc12304f 30// // reads gAlice from header file "galice.root", uses digits stored in the branch names "digitsname" (default = "Default")
31// // and saves recpoints in branch named "recpointsname" (default = "digitsname")
a4e98857 32// root [1] cl->ExecuteTask()
9a1398dd 33// //finds RecPoints in all events stored in galice.root
a4e98857 34// root [2] cl->SetDigitsBranch("digits2")
f035f6ce 35// //sets another title for Digitis (input) branch
a4e98857 36// root [3] cl->SetRecPointsBranch("recp2")
f035f6ce 37// //sets another title four output branches
a4e98857 38// root [4] cl->SetEmcLocalMaxCut(0.03)
9a1398dd 39// //set clusterization parameters
a4e98857 40// root [5] cl->ExecuteTask("deb all time")
9a1398dd 41// //once more finds RecPoints options are
42// // deb - print number of found rec points
43// // deb all - print number of found RecPoints and some their characteristics
44// // time - print benchmarking results
ed4205d8 45
d15a28e7 46// --- ROOT system ---
47
48#include "TMath.h"
9a1398dd 49#include "TMinuit.h"
50#include "TTree.h"
9a1398dd 51#include "TBenchmark.h"
d15a28e7 52
53// --- Standard library ---
54
d15a28e7 55// --- AliRoot header files ---
88cb7938 56#include "AliPHOSGetter.h"
e957fea8 57#include "AliPHOSGeometry.h"
d15a28e7 58#include "AliPHOSClusterizerv1.h"
88cb7938 59#include "AliPHOSEmcRecPoint.h"
9a1398dd 60#include "AliPHOSCpvRecPoint.h"
d15a28e7 61#include "AliPHOSDigit.h"
9a1398dd 62#include "AliPHOSDigitizer.h"
d15a28e7 63
64ClassImp(AliPHOSClusterizerv1)
f035f6ce 65
d15a28e7 66//____________________________________________________________________________
7b7c1533 67 AliPHOSClusterizerv1::AliPHOSClusterizerv1() : AliPHOSClusterizer()
d15a28e7 68{
f035f6ce 69 // default ctor (to be used mainly by Streamer)
f035f6ce 70
8d0f3f77 71 InitParameters() ;
92f521a9 72 fDefaultInit = kTRUE ;
9a1398dd 73}
7b7c1533 74
9a1398dd 75//____________________________________________________________________________
88cb7938 76AliPHOSClusterizerv1::AliPHOSClusterizerv1(const TString alirunFileName, const TString eventFolderName)
77:AliPHOSClusterizer(alirunFileName, eventFolderName)
9a1398dd 78{
a4e98857 79 // ctor with the indication of the file where header Tree and digits Tree are stored
9a1398dd 80
8d0f3f77 81 InitParameters() ;
2bd5457f 82 Init() ;
92f521a9 83 fDefaultInit = kFALSE ;
9a1398dd 84}
fc12304f 85
9688c1dd 86//____________________________________________________________________________
87 AliPHOSClusterizerv1::~AliPHOSClusterizerv1()
88{
0bc3b8ed 89 // dtor
90
88cb7938 91 // delete fPedestals ;
92// delete fGains ;
9688c1dd 93}
fc12304f 94
88cb7938 95
fc12304f 96//____________________________________________________________________________
97const TString AliPHOSClusterizerv1::BranchName() const
98{
88cb7938 99 return GetName();
fc12304f 100}
101
9a1398dd 102//____________________________________________________________________________
3758d9fc 103Float_t AliPHOSClusterizerv1::Calibrate(Int_t amp, Int_t absId) const
88cb7938 104{
105 //To be replaced later by the method, reading individual parameters from the database
106 // if(fCalibrationDB)
107 // return fCalibrationDB->Calibrate(amp,absId) ;
108 // else{ //simulation
109 if(absId <= fEmcCrystals) //calibrate as EMC
110 return fADCpedestalEmc + amp*fADCchanelEmc ;
111 else //calibrate as CPV
112 return fADCpedestalCpv+ amp*fADCchanelCpv ;
113 // }
3758d9fc 114}
548f0134 115
3758d9fc 116//____________________________________________________________________________
eabde521 117void AliPHOSClusterizerv1::Exec(Option_t *option)
a4e98857 118{
eabde521 119 // Steering method to perform clusterization for events
120 // in the range from fFirstEvent to fLastEvent.
121 // This range is optionally set by SetEventRange().
122 // if fLastEvent=-1 (by default), then process events until the end.
9a1398dd 123
124 if(strstr(option,"tim"))
7d493c2c 125 gBenchmark->Start("PHOSClusterizer");
9a1398dd 126
eabde521 127 if(strstr(option,"print")) {
88cb7938 128 Print() ;
eabde521 129 return ;
130 }
bed9e3fb 131
88cb7938 132 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
133
9cae45af 134 if (fLastEvent == -1)
135 fLastEvent = gime->MaxEvent() - 1 ;
136 else
137 fLastEvent = TMath::Min(fLastEvent,gime->MaxEvent());
eabde521 138 Int_t nEvents = fLastEvent - fFirstEvent + 1;
fbf811ec 139
9cae45af 140 Int_t ievent ;
141
142 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
88cb7938 143 gime->Event(ievent, "D");
144
145 GetCalibrationParameters() ;
bed9e3fb 146
548f0134 147 fNumberOfEmcClusters = fNumberOfCpvClusters = 0 ;
9a1398dd 148
88cb7938 149 MakeClusters() ;
150
fc12304f 151 if(fToUnfold)
152 MakeUnfolding() ;
7b7c1533 153
88cb7938 154 WriteRecPoints();
7b7c1533 155
94de8339 156 if(strstr(option,"deb"))
157 PrintRecPoints(option) ;
158
88cb7938 159 //increment the total number of recpoints per run
fbf811ec 160 fRecPointsInRun += gime->EmcRecPoints()->GetEntriesFast() ;
161 fRecPointsInRun += gime->CpvRecPoints()->GetEntriesFast() ;
88cb7938 162 }
163
164 Unload();
9a1398dd 165
166 if(strstr(option,"tim")){
167 gBenchmark->Stop("PHOSClusterizer");
21cd0c07 168 Info("Exec", " took %f seconds for Clusterizing %f seconds per event \n",
169 gBenchmark->GetCpuTime("PHOSClusterizer"),
eabde521 170 gBenchmark->GetCpuTime("PHOSClusterizer")/nEvents ) ;
88cb7938 171 }
9a1398dd 172}
173
174//____________________________________________________________________________
a0636361 175Bool_t AliPHOSClusterizerv1::FindFit(AliPHOSEmcRecPoint * emcRP, AliPHOSDigit ** maxAt, Float_t * maxAtEnergy,
d1de15f5 176 Int_t nPar, Float_t * fitparameters) const
9a1398dd 177{
178 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
a4e98857 179 // The initial values for fitting procedure are set equal to the positions of local maxima.
f035f6ce 180 // Cluster will be fitted as a superposition of nPar/3 electromagnetic showers
9a1398dd 181
88cb7938 182
183 AliPHOSGetter * gime = AliPHOSGetter::Instance();
184 TClonesArray * digits = gime->Digits();
7b7c1533 185
186
9a1398dd 187 gMinuit->mncler(); // Reset Minuit's list of paramters
188 gMinuit->SetPrintLevel(-1) ; // No Printout
189 gMinuit->SetFCN(AliPHOSClusterizerv1::UnfoldingChiSquare) ;
190 // To set the address of the minimization function
191
192 TList * toMinuit = new TList();
193 toMinuit->AddAt(emcRP,0) ;
7b7c1533 194 toMinuit->AddAt(digits,1) ;
9a1398dd 195
196 gMinuit->SetObjectFit(toMinuit) ; // To tranfer pointer to UnfoldingChiSquare
197
198 // filling initial values for fit parameters
199 AliPHOSDigit * digit ;
200
201 Int_t ierflg = 0;
202 Int_t index = 0 ;
203 Int_t nDigits = (Int_t) nPar / 3 ;
204
205 Int_t iDigit ;
206
7b7c1533 207 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
9a1398dd 208
209 for(iDigit = 0; iDigit < nDigits; iDigit++){
a0636361 210 digit = maxAt[iDigit];
9a1398dd 211
212 Int_t relid[4] ;
7b7c1533 213 Float_t x = 0.;
214 Float_t z = 0.;
215 geom->AbsToRelNumbering(digit->GetId(), relid) ;
216 geom->RelPosInModule(relid, x, z) ;
9a1398dd 217
218 Float_t energy = maxAtEnergy[iDigit] ;
219
220 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
221 index++ ;
222 if(ierflg != 0){
21cd0c07 223 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : x = %f\n", x ) ;
9a1398dd 224 return kFALSE;
225 }
226 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
227 index++ ;
228 if(ierflg != 0){
21cd0c07 229 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : z =%f\n", z ) ;
9a1398dd 230 return kFALSE;
231 }
232 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
233 index++ ;
234 if(ierflg != 0){
21cd0c07 235 Warning("FindFit", "PHOS Unfolding unable to set initial value for fit procedure : energy = %f\n", energy ) ;
9a1398dd 236 return kFALSE;
237 }
238 }
239
240 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
241 // depends on it.
242 Double_t p1 = 1.0 ;
243 Double_t p2 = 0.0 ;
244
245 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
246 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
247 gMinuit->SetMaxIterations(5);
248 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
249
250 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
251
252 if(ierflg == 4){ // Minimum not found
21cd0c07 253 Warning("FindFit", "PHOS Unfolding fit not converged, cluster abandoned\n" );
9a1398dd 254 return kFALSE ;
255 }
256 for(index = 0; index < nPar; index++){
257 Double_t err ;
258 Double_t val ;
259 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
260 fitparameters[index] = val ;
261 }
262
263 delete toMinuit ;
264 return kTRUE;
c3c187e5 265
d15a28e7 266}
267
3758d9fc 268//____________________________________________________________________________
269void AliPHOSClusterizerv1::GetCalibrationParameters()
270{
fbf811ec 271
88cb7938 272 AliPHOSGetter * gime = AliPHOSGetter::Instance();
c2cd5471 273
88cb7938 274 if ( !gime->Digitizer() )
275 gime->LoadDigitizer();
276 AliPHOSDigitizer * dig = gime->Digitizer();
277
278 fADCchanelEmc = dig->GetEMCchannel() ;
279 fADCpedestalEmc = dig->GetEMCpedestal();
280
281 fADCchanelCpv = dig->GetCPVchannel() ;
282 fADCpedestalCpv = dig->GetCPVpedestal() ;
283
284 // fCalibrationDB = gime->CalibrationDB();
3758d9fc 285}
548f0134 286
d15a28e7 287//____________________________________________________________________________
a4e98857 288void AliPHOSClusterizerv1::Init()
289{
2bd5457f 290 // Make all memory allocations which can not be done in default constructor.
291 // Attach the Clusterizer task to the list of PHOS tasks
88cb7938 292
293 AliPHOSGetter* gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
fbf811ec 294
88cb7938 295 AliPHOSGeometry * geom = gime->PHOSGeometry();
296
3758d9fc 297 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
298
7b7c1533 299 if(!gMinuit)
88cb7938 300 gMinuit = new TMinuit(100);
fbf811ec 301
88cb7938 302 if ( !gime->Clusterizer() )
303 gime->PostClusterizer(this);
9a1398dd 304}
7b7c1533 305
8d0f3f77 306//____________________________________________________________________________
307void AliPHOSClusterizerv1::InitParameters()
308{
309
310 fNumberOfCpvClusters = 0 ;
311 fNumberOfEmcClusters = 0 ;
312
313 fCpvClusteringThreshold = 0.0;
314 fEmcClusteringThreshold = 0.2;
315
316 fEmcLocMaxCut = 0.03 ;
317 fCpvLocMaxCut = 0.03 ;
318
319 fW0 = 4.5 ;
320 fW0CPV = 4.0 ;
321
322 fEmcTimeGate = 1.e-8 ;
323
324 fToUnfold = kTRUE ;
88cb7938 325
8d0f3f77 326 fRecPointsInRun = 0 ;
c2cd5471 327
eabde521 328 SetEventRange(0,-1) ;
8d0f3f77 329}
330
9a1398dd 331//____________________________________________________________________________
332Int_t AliPHOSClusterizerv1::AreNeighbours(AliPHOSDigit * d1, AliPHOSDigit * d2)const
d15a28e7 333{
b2a60966 334 // Gives the neighbourness of two digits = 0 are not neighbour but continue searching
335 // = 1 are neighbour
336 // = 2 are not neighbour but do not continue searching
a4e98857 337 // neighbours are defined as digits having at least a common vertex
b2a60966 338 // The order of d1 and d2 is important: first (d1) should be a digit already in a cluster
339 // which is compared to a digit (d2) not yet in a cluster
340
88cb7938 341 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
7b7c1533 342
d15a28e7 343 Int_t rv = 0 ;
344
d15a28e7 345 Int_t relid1[4] ;
7b7c1533 346 geom->AbsToRelNumbering(d1->GetId(), relid1) ;
d15a28e7 347
348 Int_t relid2[4] ;
7b7c1533 349 geom->AbsToRelNumbering(d2->GetId(), relid2) ;
d15a28e7 350
9688c1dd 351 if ( (relid1[0] == relid2[0]) && (relid1[1]==relid2[1]) ) { // inside the same PHOS module
92862013 352 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
353 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
d15a28e7 354
92862013 355 if (( coldiff <= 1 ) && ( rowdiff <= 1 )){
9688c1dd 356 if((relid1[1] != 0) || (TMath::Abs(d1->GetTime() - d2->GetTime() ) < fEmcTimeGate))
d15a28e7 357 rv = 1 ;
358 }
359 else {
360 if((relid2[2] > relid1[2]) && (relid2[3] > relid1[3]+1))
88cb7938 361 rv = 2; // Difference in row numbers is too large to look further
d15a28e7 362 }
363
364 }
365 else {
366
9688c1dd 367 if( (relid1[0] < relid2[0]) || (relid1[1] != relid2[1]) )
d15a28e7 368 rv=2 ;
369
370 }
d72dfbc3 371
d15a28e7 372 return rv ;
373}
374
d15a28e7 375
376//____________________________________________________________________________
9a1398dd 377Bool_t AliPHOSClusterizerv1::IsInEmc(AliPHOSDigit * digit) const
d15a28e7 378{
b2a60966 379 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
380
9f616d61 381 Bool_t rv = kFALSE ;
88cb7938 382 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
d15a28e7 383
2b629790 384 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
d15a28e7 385
2b629790 386 if(digit->GetId() <= nEMC ) rv = kTRUE;
ed4205d8 387
388 return rv ;
389}
390
ed4205d8 391//____________________________________________________________________________
9a1398dd 392Bool_t AliPHOSClusterizerv1::IsInCpv(AliPHOSDigit * digit) const
ed4205d8 393{
fad3e5b9 394 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
ed4205d8 395
396 Bool_t rv = kFALSE ;
88cb7938 397
398 AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
ed4205d8 399
2b629790 400 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
ed4205d8 401
2b629790 402 if(digit->GetId() > nEMC ) rv = kTRUE;
d15a28e7 403
404 return rv ;
405}
9a1398dd 406
407//____________________________________________________________________________
88cb7938 408void AliPHOSClusterizerv1::Unload()
409{
410 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
411 gime->PhosLoader()->UnloadDigits() ;
412 gime->PhosLoader()->UnloadRecPoints() ;
413}
414
415//____________________________________________________________________________
416void AliPHOSClusterizerv1::WriteRecPoints()
a4e98857 417{
7b7c1533 418
419 // Creates new branches with given title
a4e98857 420 // fills and writes into TreeR.
88cb7938 421
422 AliPHOSGetter * gime = AliPHOSGetter::Instance();
423
fbf811ec 424 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
425 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
426 TClonesArray * digits = gime->Digits() ;
fbf811ec 427
88cb7938 428 TTree * treeR = gime->TreeR();
fbf811ec 429
9a1398dd 430 Int_t index ;
01a599c9 431 //Evaluate position, dispersion and other RecPoint properties...
88cb7938 432 for(index = 0; index < emcRecPoints->GetEntries(); index++)
433 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->EvalAll(fW0,digits) ;
434
7b7c1533 435 emcRecPoints->Sort() ;
7b7c1533 436 for(index = 0; index < emcRecPoints->GetEntries(); index++)
88cb7938 437 dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) )->SetIndexInList(index) ;
fbf811ec 438
7b7c1533 439 emcRecPoints->Expand(emcRecPoints->GetEntriesFast()) ;
fbf811ec 440
9a1398dd 441 //Now the same for CPV
7b7c1533 442 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
e957fea8 443 dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) )->EvalAll(digits) ;
fbf811ec 444
7b7c1533 445 cpvRecPoints->Sort() ;
fbf811ec 446
7b7c1533 447 for(index = 0; index < cpvRecPoints->GetEntries(); index++)
88cb7938 448 dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) )->SetIndexInList(index) ;
fbf811ec 449
7b7c1533 450 cpvRecPoints->Expand(cpvRecPoints->GetEntriesFast()) ;
9a1398dd 451
9a1398dd 452 Int_t bufferSize = 32000 ;
453 Int_t splitlevel = 0 ;
8d0f3f77 454
01a599c9 455 //First EMC
8d0f3f77 456 TBranch * emcBranch = treeR->Branch("PHOSEmcRP","TObjArray",&emcRecPoints,bufferSize,splitlevel);
fc12304f 457 emcBranch->SetTitle(BranchName());
9a1398dd 458
459 //Now CPV branch
8d0f3f77 460 TBranch * cpvBranch = treeR->Branch("PHOSCpvRP","TObjArray",&cpvRecPoints,bufferSize,splitlevel);
fc12304f 461 cpvBranch->SetTitle(BranchName());
9a1398dd 462
01a599c9 463 emcBranch ->Fill() ;
464 cpvBranch ->Fill() ;
88cb7938 465
466 gime->WriteRecPoints("OVERWRITE");
467 gime->WriteClusterizer("OVERWRITE");
9a1398dd 468}
469
470//____________________________________________________________________________
471void AliPHOSClusterizerv1::MakeClusters()
472{
473 // Steering method to construct the clusters stored in a list of Reconstructed Points
474 // A cluster is defined as a list of neighbour digits
d15a28e7 475
88cb7938 476
477 AliPHOSGetter * gime = AliPHOSGetter::Instance();
478
479 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
480 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
7b7c1533 481
7d493c2c 482 emcRecPoints->Delete() ;
483 cpvRecPoints->Delete() ;
7b7c1533 484
fbf811ec 485 TClonesArray * digits = gime->Digits() ;
88cb7938 486
487 TClonesArray * digitsC = static_cast<TClonesArray*>( digits->Clone() ) ;
7b7c1533 488
489
d15a28e7 490 // Clusterization starts
9a1398dd 491
7b7c1533 492 TIter nextdigit(digitsC) ;
d15a28e7 493 AliPHOSDigit * digit ;
92862013 494 Bool_t notremoved = kTRUE ;
6ad0bfa0 495
88cb7938 496 while ( (digit = dynamic_cast<AliPHOSDigit *>( nextdigit()) ) ) { // scan over the list of digitsC
497
498
9a1398dd 499 AliPHOSRecPoint * clu = 0 ;
c161df70 500
d1de15f5 501 TArrayI clusterdigitslist(1500) ;
d15a28e7 502 Int_t index ;
f2bc1b87 503
3758d9fc 504 if (( IsInEmc (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fEmcClusteringThreshold ) ||
505 ( IsInCpv (digit) && Calibrate(digit->GetAmp(),digit->GetId()) > fCpvClusteringThreshold ) ) {
d15a28e7 506 Int_t iDigitInCluster = 0 ;
7b7c1533 507
6ad0bfa0 508 if ( IsInEmc(digit) ) {
88cb7938 509 // start a new EMC RecPoint
510 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
511 emcRecPoints->Expand(2*fNumberOfEmcClusters+1) ;
512
513 emcRecPoints->AddAt(new AliPHOSEmcRecPoint(""), fNumberOfEmcClusters) ;
514 clu = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
515 fNumberOfEmcClusters++ ;
516 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId())) ;
517 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
518 iDigitInCluster++ ;
519 digitsC->Remove(digit) ;
ca77b032 520
d72dfbc3 521 } else {
88cb7938 522
523 // start a new CPV cluster
524 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
525 cpvRecPoints->Expand(2*fNumberOfCpvClusters+1);
526
527 cpvRecPoints->AddAt(new AliPHOSCpvRecPoint(""), fNumberOfCpvClusters) ;
528
529 clu = dynamic_cast<AliPHOSCpvRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
530 fNumberOfCpvClusters++ ;
531 clu->AddDigit(*digit, Calibrate(digit->GetAmp(),digit->GetId()) ) ;
532 clusterdigitslist[iDigitInCluster] = digit->GetIndexInList() ;
533 iDigitInCluster++ ;
534 digitsC->Remove(digit) ;
d15a28e7 535 nextdigit.Reset() ;
88cb7938 536
537 // Here we remove remaining EMC digits, which cannot make a cluster
538
92862013 539 if( notremoved ) {
88cb7938 540 while( ( digit = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) {
9f616d61 541 if( IsInEmc(digit) )
88cb7938 542 digitsC->Remove(digit) ;
d15a28e7 543 else
88cb7938 544 break ;
545 }
546 notremoved = kFALSE ;
547 }
548
d15a28e7 549 } // else
550
551 nextdigit.Reset() ;
fad3e5b9 552
d15a28e7 553 AliPHOSDigit * digitN ;
554 index = 0 ;
9f616d61 555 while (index < iDigitInCluster){ // scan over digits already in cluster
88cb7938 556 digit = dynamic_cast<AliPHOSDigit*>( digits->At(clusterdigitslist[index]) ) ;
557 index++ ;
558 while ( (digitN = dynamic_cast<AliPHOSDigit *>( nextdigit() ) ) ) { // scan over the reduced list of digits
559 Int_t ineb = AreNeighbours(digit, digitN); // call (digit,digitN) in THAT oder !!!!!
d15a28e7 560 switch (ineb ) {
9f616d61 561 case 0 : // not a neighbour
88cb7938 562 break ;
563 case 1 : // are neighbours
564 clu->AddDigit(*digitN, Calibrate( digitN->GetAmp(), digitN->GetId() ) ) ;
565 clusterdigitslist[iDigitInCluster] = digitN->GetIndexInList() ;
566 iDigitInCluster++ ;
567 digitsC->Remove(digitN) ;
568 break ;
9f616d61 569 case 2 : // too far from each other
88cb7938 570 goto endofloop;
571 } // switch
572
573 } // while digitN
574
d15a28e7 575 endofloop: ;
88cb7938 576 nextdigit.Reset() ;
577
d15a28e7 578 } // loop over cluster
ad8cfaf4 579
ad8cfaf4 580 } // energy theshold
ad8cfaf4 581
31aa6d6c 582
d15a28e7 583 } // while digit
584
7b7c1533 585 delete digitsC ;
9688c1dd 586
9a1398dd 587}
588
589//____________________________________________________________________________
a4e98857 590void AliPHOSClusterizerv1::MakeUnfolding()
591{
592 // Unfolds clusters using the shape of an ElectroMagnetic shower
9688c1dd 593 // Performs unfolding of all EMC/CPV clusters
9a1398dd 594
88cb7938 595 AliPHOSGetter * gime = AliPHOSGetter::Instance();
fc12304f 596
7b7c1533 597 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
88cb7938 598
599 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
600 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
fbf811ec 601 TClonesArray * digits = gime->Digits() ;
7b7c1533 602
a4e98857 603 // Unfold first EMC clusters
9a1398dd 604 if(fNumberOfEmcClusters > 0){
605
7b7c1533 606 Int_t nModulesToUnfold = geom->GetNModules() ;
9a1398dd 607
608 Int_t numberofNotUnfolded = fNumberOfEmcClusters ;
609 Int_t index ;
610 for(index = 0 ; index < numberofNotUnfolded ; index++){
611
88cb7938 612 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(index) ) ;
9a1398dd 613 if(emcRecPoint->GetPHOSMod()> nModulesToUnfold)
88cb7938 614 break ;
9a1398dd 615
616 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
a0636361 617 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
9a1398dd 618 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
7b7c1533 619 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fEmcLocMaxCut,digits) ;
9a1398dd 620
621 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
88cb7938 622 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
623 emcRecPoints->Remove(emcRecPoint);
624 emcRecPoints->Compress() ;
625 index-- ;
626 fNumberOfEmcClusters -- ;
627 numberofNotUnfolded-- ;
9a1398dd 628 }
629
630 delete[] maxAt ;
631 delete[] maxAtEnergy ;
632 }
633 }
a4e98857 634 // Unfolding of EMC clusters finished
9a1398dd 635
636
a4e98857 637 // Unfold now CPV clusters
9a1398dd 638 if(fNumberOfCpvClusters > 0){
639
9688c1dd 640 Int_t nModulesToUnfold = geom->GetNModules() ;
9a1398dd 641
642 Int_t numberofCpvNotUnfolded = fNumberOfCpvClusters ;
643 Int_t index ;
644 for(index = 0 ; index < numberofCpvNotUnfolded ; index++){
645
88cb7938 646 AliPHOSRecPoint * recPoint = dynamic_cast<AliPHOSRecPoint *>( cpvRecPoints->At(index) ) ;
9a1398dd 647
648 if(recPoint->GetPHOSMod()> nModulesToUnfold)
88cb7938 649 break ;
9a1398dd 650
88cb7938 651 AliPHOSEmcRecPoint * emcRecPoint = dynamic_cast<AliPHOSEmcRecPoint*>(recPoint) ;
9a1398dd 652
653 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
a0636361 654 AliPHOSDigit ** maxAt = new AliPHOSDigit*[nMultipl] ;
9a1398dd 655 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
7b7c1533 656 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy,fCpvLocMaxCut,digits) ;
9a1398dd 657
658 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
88cb7938 659 UnfoldCluster(emcRecPoint, nMax, maxAt, maxAtEnergy) ;
660 cpvRecPoints->Remove(emcRecPoint);
661 cpvRecPoints->Compress() ;
662 index-- ;
663 numberofCpvNotUnfolded-- ;
664 fNumberOfCpvClusters-- ;
9a1398dd 665 }
666
667 delete[] maxAt ;
668 delete[] maxAtEnergy ;
669 }
670 }
671 //Unfolding of Cpv clusters finished
672
673}
674
9a1398dd 675//____________________________________________________________________________
676Double_t AliPHOSClusterizerv1::ShowerShape(Double_t r)
677{
678 // Shape of the shower (see PHOS TDR)
a4e98857 679 // If you change this function, change also the gradient evaluation in ChiSquare()
9a1398dd 680
681 Double_t r4 = r*r*r*r ;
682 Double_t r295 = TMath::Power(r, 2.95) ;
683 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
684 return shape ;
685}
686
687//____________________________________________________________________________
688void AliPHOSClusterizerv1::UnfoldCluster(AliPHOSEmcRecPoint * iniEmc,
88cb7938 689 Int_t nMax,
690 AliPHOSDigit ** maxAt,
691 Float_t * maxAtEnergy)
9a1398dd 692{
693 // Performs the unfolding of a cluster with nMax overlapping showers
694
88cb7938 695 AliPHOSGetter * gime = AliPHOSGetter::Instance();
fc12304f 696
7b7c1533 697 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
88cb7938 698
fbf811ec 699 const TClonesArray * digits = gime->Digits() ;
700 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
701 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
7b7c1533 702
9a1398dd 703 Int_t nPar = 3 * nMax ;
704 Float_t * fitparameters = new Float_t[nPar] ;
705
706 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
707 if( !rv ) {
88cb7938 708 // Fit failed, return and remove cluster
9a1398dd 709 delete[] fitparameters ;
710 return ;
711 }
712
713 // create ufolded rec points and fill them with new energy lists
714 // First calculate energy deposited in each sell in accordance with fit (without fluctuations): efit[]
715 // and later correct this number in acordance with actual energy deposition
716
717 Int_t nDigits = iniEmc->GetMultiplicity() ;
718 Float_t * efit = new Float_t[nDigits] ;
7b7c1533 719 Float_t xDigit=0.,zDigit=0.,distance=0. ;
720 Float_t xpar=0.,zpar=0.,epar=0. ;
9a1398dd 721 Int_t relid[4] ;
7b7c1533 722 AliPHOSDigit * digit = 0 ;
9a1398dd 723 Int_t * emcDigits = iniEmc->GetDigitsList() ;
724
725 Int_t iparam ;
726 Int_t iDigit ;
727 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
88cb7938 728 digit = dynamic_cast<AliPHOSDigit*>( digits->At(emcDigits[iDigit] ) ) ;
7b7c1533 729 geom->AbsToRelNumbering(digit->GetId(), relid) ;
730 geom->RelPosInModule(relid, xDigit, zDigit) ;
9a1398dd 731 efit[iDigit] = 0;
732
733 iparam = 0 ;
734 while(iparam < nPar ){
735 xpar = fitparameters[iparam] ;
736 zpar = fitparameters[iparam+1] ;
737 epar = fitparameters[iparam+2] ;
738 iparam += 3 ;
739 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
740 distance = TMath::Sqrt(distance) ;
741 efit[iDigit] += epar * ShowerShape(distance) ;
742 }
743 }
744
745
746 // Now create new RecPoints and fill energy lists with efit corrected to fluctuations
747 // so that energy deposited in each cell is distributed betwin new clusters proportionally
748 // to its contribution to efit
749
750 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
751 Float_t ratio ;
752
753 iparam = 0 ;
754 while(iparam < nPar ){
755 xpar = fitparameters[iparam] ;
756 zpar = fitparameters[iparam+1] ;
757 epar = fitparameters[iparam+2] ;
758 iparam += 3 ;
759
7b7c1533 760 AliPHOSEmcRecPoint * emcRP = 0 ;
9a1398dd 761
762 if(iniEmc->IsEmc()){ //create new entries in fEmcRecPoints...
763
7b7c1533 764 if(fNumberOfEmcClusters >= emcRecPoints->GetSize())
88cb7938 765 emcRecPoints->Expand(2*fNumberOfEmcClusters) ;
9a1398dd 766
73a68ccb 767 (*emcRecPoints)[fNumberOfEmcClusters] = new AliPHOSEmcRecPoint("") ;
88cb7938 768 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( emcRecPoints->At(fNumberOfEmcClusters) ) ;
9a1398dd 769 fNumberOfEmcClusters++ ;
770 }
771 else{//create new entries in fCpvRecPoints
7b7c1533 772 if(fNumberOfCpvClusters >= cpvRecPoints->GetSize())
88cb7938 773 cpvRecPoints->Expand(2*fNumberOfCpvClusters) ;
9a1398dd 774
73a68ccb 775 (*cpvRecPoints)[fNumberOfCpvClusters] = new AliPHOSCpvRecPoint("") ;
88cb7938 776 emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( cpvRecPoints->At(fNumberOfCpvClusters) ) ;
9a1398dd 777 fNumberOfCpvClusters++ ;
778 }
779
780 Float_t eDigit ;
781 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
88cb7938 782 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) ) ;
7b7c1533 783 geom->AbsToRelNumbering(digit->GetId(), relid) ;
784 geom->RelPosInModule(relid, xDigit, zDigit) ;
9a1398dd 785 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
786 distance = TMath::Sqrt(distance) ;
787 ratio = epar * ShowerShape(distance) / efit[iDigit] ;
788 eDigit = emcEnergies[iDigit] * ratio ;
789 emcRP->AddDigit( *digit, eDigit ) ;
88cb7938 790 }
9a1398dd 791 }
792
793 delete[] fitparameters ;
794 delete[] efit ;
795
796}
797
798//_____________________________________________________________________________
799void AliPHOSClusterizerv1::UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
800{
a4e98857 801 // Calculates the Chi square for the cluster unfolding minimization
9a1398dd 802 // Number of parameters, Gradient, Chi squared, parameters, what to do
803
88cb7938 804 TList * toMinuit = dynamic_cast<TList*>( gMinuit->GetObjectFit() ) ;
9a1398dd 805
88cb7938 806 AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint*>( toMinuit->At(0) ) ;
807 TClonesArray * digits = dynamic_cast<TClonesArray*>( toMinuit->At(1) ) ;
9a1398dd 808
809
810
88cb7938 811 // AliPHOSEmcRecPoint * emcRP = dynamic_cast<AliPHOSEmcRecPoint *>( gMinuit->GetObjectFit() ) ; // EmcRecPoint to fit
9a1398dd 812
813 Int_t * emcDigits = emcRP->GetDigitsList() ;
814
7b7c1533 815 Int_t nOdigits = emcRP->GetDigitsMultiplicity() ;
9a1398dd 816
817 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
88cb7938 818
819 const AliPHOSGeometry * geom = AliPHOSGetter::Instance()->PHOSGeometry() ;
9a1398dd 820 fret = 0. ;
821 Int_t iparam ;
822
823 if(iflag == 2)
824 for(iparam = 0 ; iparam < nPar ; iparam++)
825 Grad[iparam] = 0 ; // Will evaluate gradient
826
827 Double_t efit ;
828
829 AliPHOSDigit * digit ;
830 Int_t iDigit ;
831
7b7c1533 832 for( iDigit = 0 ; iDigit < nOdigits ; iDigit++) {
9a1398dd 833
88cb7938 834 digit = dynamic_cast<AliPHOSDigit*>( digits->At( emcDigits[iDigit] ) );
9a1398dd 835
836 Int_t relid[4] ;
837 Float_t xDigit ;
838 Float_t zDigit ;
839
840 geom->AbsToRelNumbering(digit->GetId(), relid) ;
841
842 geom->RelPosInModule(relid, xDigit, zDigit) ;
843
844 if(iflag == 2){ // calculate gradient
845 Int_t iParam = 0 ;
846 efit = 0 ;
847 while(iParam < nPar ){
88cb7938 848 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
849 iParam++ ;
850 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
851 distance = TMath::Sqrt( distance ) ;
852 iParam++ ;
853 efit += x[iParam] * ShowerShape(distance) ;
854 iParam++ ;
9a1398dd 855 }
88cb7938 856 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
9a1398dd 857 iParam = 0 ;
858 while(iParam < nPar ){
88cb7938 859 Double_t xpar = x[iParam] ;
860 Double_t zpar = x[iParam+1] ;
861 Double_t epar = x[iParam+2] ;
862 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
863 Double_t shape = sum * ShowerShape(dr) ;
864 Double_t r4 = dr*dr*dr*dr ;
865 Double_t r295 = TMath::Power(dr,2.95) ;
866 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
867 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
868
869 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
870 iParam++ ;
871 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
872 iParam++ ;
873 Grad[iParam] += shape ; // Derivative over energy
874 iParam++ ;
9a1398dd 875 }
876 }
877 efit = 0;
878 iparam = 0 ;
879
880 while(iparam < nPar ){
881 Double_t xpar = x[iparam] ;
882 Double_t zpar = x[iparam+1] ;
883 Double_t epar = x[iparam+2] ;
884 iparam += 3 ;
885 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
886 distance = TMath::Sqrt(distance) ;
887 efit += epar * ShowerShape(distance) ;
888 }
889
88cb7938 890 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
9a1398dd 891 // Here we assume, that sigma = sqrt(E)
892 }
83974468 893
d15a28e7 894}
895
896//____________________________________________________________________________
88cb7938 897void AliPHOSClusterizerv1::Print()const
d15a28e7 898{
d1de15f5 899 // Print clusterizer parameters
900
21cd0c07 901 TString message ;
902 TString taskName(GetName()) ;
903 taskName.ReplaceAll(Version(), "") ;
904
905 if( strcmp(GetName(), "") !=0 ) {
9a1398dd 906 // Print parameters
21cd0c07 907 message = "\n--------------- %s %s -----------\n" ;
908 message += "Clusterizing digits from the file: %s\n" ;
909 message += " Branch: %s\n" ;
910 message += " EMC Clustering threshold = %f\n" ;
911 message += " EMC Local Maximum cut = %f\n" ;
912 message += " EMC Logarothmic weight = %f\n" ;
913 message += " CPV Clustering threshold = %f\n" ;
914 message += " CPV Local Maximum cut = %f\n" ;
915 message += " CPV Logarothmic weight = %f\n" ;
9a1398dd 916 if(fToUnfold)
21cd0c07 917 message += " Unfolding on\n" ;
9a1398dd 918 else
21cd0c07 919 message += " Unfolding off\n" ;
9a1398dd 920
21cd0c07 921 message += "------------------------------------------------------------------" ;
9a1398dd 922 }
21cd0c07 923 else
924 message = " AliPHOSClusterizerv1 not initialized " ;
925
926 Info("Print", message.Data(),
927 taskName.Data(),
928 GetTitle(),
929 taskName.Data(),
930 GetName(),
931 fEmcClusteringThreshold,
932 fEmcLocMaxCut,
933 fW0,
934 fCpvClusteringThreshold,
935 fCpvLocMaxCut,
936 fW0CPV ) ;
9a1398dd 937}
21cd0c07 938
939
9a1398dd 940//____________________________________________________________________________
a4e98857 941void AliPHOSClusterizerv1::PrintRecPoints(Option_t * option)
942{
943 // Prints list of RecPoints produced at the current pass of AliPHOSClusterizer
9a1398dd 944
88cb7938 945 AliPHOSGetter * gime = AliPHOSGetter::Instance();
946
947 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
948 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
7b7c1533 949
709e117a 950 printf("\nevent %d \n", gAlice->GetEvNumber()) ;
951 printf(" Found %d EMC RecPoints and %d CPV RecPoints \n",
952 emcRecPoints->GetEntriesFast(),cpvRecPoints->GetEntriesFast()) ;
88cb7938 953
954 fRecPointsInRun += emcRecPoints->GetEntriesFast() ;
955 fRecPointsInRun += cpvRecPoints->GetEntriesFast() ;
956
11f9c5ff 957
9a1398dd 958 if(strstr(option,"all")) {
709e117a 959 printf("\n EMC clusters \n") ;
960 printf("Index Ene(MeV) Multi Module X Y Z Lambdas_1 Lambda_2 # of prim Primaries list\n") ;
9a1398dd 961 Int_t index ;
7b7c1533 962 for (index = 0 ; index < emcRecPoints->GetEntries() ; index++) {
963 AliPHOSEmcRecPoint * rp = (AliPHOSEmcRecPoint * )emcRecPoints->At(index) ;
9a1398dd 964 TVector3 locpos;
965 rp->GetLocalPosition(locpos);
9a1398dd 966 Float_t lambda[2];
967 rp->GetElipsAxis(lambda);
9a1398dd 968 Int_t * primaries;
969 Int_t nprimaries;
970 primaries = rp->GetPrimaries(nprimaries);
709e117a 971 printf("\n%6d %8.2f %3d %2d %4.1f %4.1f %4.1f %4f %4f %2d : ",
11f9c5ff 972 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(), rp->GetPHOSMod(),
973 locpos.X(), locpos.Y(), locpos.Z(), lambda[0], lambda[1], nprimaries) ;
3bf72d32 974
21cd0c07 975 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
709e117a 976 printf("%d ", primaries[iprimary] ) ;
21cd0c07 977 }
709e117a 978 printf("\n") ;
979 }
980
981 //Now plot CPV recPoints
982 printf("\n CPV clusters \n") ;
983 printf("Index Ene(MeV) Module X Y Z \n") ;
984 for (index = 0 ; index < cpvRecPoints->GetEntries() ; index++) {
985 AliPHOSRecPoint * rp = (AliPHOSRecPoint * )cpvRecPoints->At(index) ;
11f9c5ff 986
709e117a 987 TVector3 locpos;
988 rp->GetLocalPosition(locpos);
11f9c5ff 989
709e117a 990 printf("\n%6d %8.2f %2d %4.1f %4.1f %4.1f \n",
11f9c5ff 991 rp->GetIndexInList(), rp->GetEnergy(), rp->GetPHOSMod(),
709e117a 992 locpos.X(), locpos.Y(), locpos.Z()) ;
88cb7938 993 }
9a1398dd 994 }
d15a28e7 995}
9a1398dd 996