AliESDCaloCluster.cxx,.h: Removed fM11 and related getter and setter,
[u/mrichter/AliRoot.git] / PHOS / AliPHOSReconstructor.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
d15a28e7 18//_________________________________________________________________________
a5e00016 19//--
20//-- Yves Schutz (SUBATECH)
dfe0be07 21// Reconstruction class. Redesigned from the old AliReconstructionner class and
22// derived from STEER/AliReconstructor.
23//
d15a28e7 24// --- ROOT system ---
00cfce1d 25
d15a28e7 26// --- Standard library ---
364de5c6 27
d15a28e7 28// --- AliRoot header files ---
9a2cdbdf 29#include "AliLog.h"
b3006690 30#include "AliAltroMapping.h"
af885e0f 31#include "AliESDEvent.h"
33ba95c3 32#include "AliESDCaloCluster.h"
a5e00016 33#include "AliESDCaloCells.h"
f444a19f 34#include "AliPHOSReconstructor.h"
7acf6008 35#include "AliPHOSClusterizerv1.h"
7acf6008 36#include "AliPHOSTrackSegmentMakerv1.h"
37#include "AliPHOSPIDv1.h"
23904d16 38#include "AliPHOSTracker.h"
d22dd3b4 39#include "AliRawReader.h"
64df000d 40#include "AliPHOSTrigger.h"
41#include "AliPHOSGeometry.h"
86121c91 42#include "AliPHOSRecoParam.h"
3799bcb5 43#include "AliPHOSRecoParamEmc.h"
44#include "AliPHOSRecoParamCpv.h"
9a2cdbdf 45#include "AliPHOSDigit.h"
46#include "AliPHOSTrackSegment.h"
47#include "AliPHOSEmcRecPoint.h"
48#include "AliPHOSRecParticle.h"
49#include "AliPHOSRawDecoder.h"
77ea1c6f 50#include "AliPHOSRawDecoderv1.h"
710634f4 51#include "AliPHOSRawDecoderv2.h"
9a2cdbdf 52#include "AliPHOSRawDigiProducer.h"
53#include "AliPHOSPulseGenerator.h"
e957fea8 54
f444a19f 55ClassImp(AliPHOSReconstructor)
d15a28e7 56
2e60107f 57Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
3799bcb5 58AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamEmc =0; // EMC rec. parameters
59AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamCpv =0; // CPV rec. parameters
2e60107f 60
d15a28e7 61//____________________________________________________________________________
9a2cdbdf 62AliPHOSReconstructor::AliPHOSReconstructor() :
8d8258f6 63 fGeom(NULL),fClusterizer(NULL)
d15a28e7 64{
b2a60966 65 // ctor
0379a13e 66
3799bcb5 67 if (!fgkRecoParamEmc) {
68 AliWarning("The Reconstruction parameters for EMC nonitialized - Used default one");
69 fgkRecoParamEmc = AliPHOSRecoParamEmc::GetEmcDefaultParameters();
70 }
71
72 if (!fgkRecoParamCpv) {
73 AliWarning("The Reconstruction parameters for CPV nonitialized - Used default one");
74 fgkRecoParamCpv = AliPHOSRecoParamCpv::GetCpvDefaultParameters();
75 }
76
8d8258f6 77 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
78 fClusterizer = new AliPHOSClusterizerv1(fGeom);
e68222ce 79}
6ad0bfa0 80
0379a13e 81//____________________________________________________________________________
82 AliPHOSReconstructor::~AliPHOSReconstructor()
83{
84 // dtor
9a2cdbdf 85 delete fGeom;
8d8258f6 86 delete fClusterizer;
0379a13e 87}
7acf6008 88
7acf6008 89//____________________________________________________________________________
9a2cdbdf 90void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
35293055 91{
9a2cdbdf 92 // 'single-event' local reco method called by AliReconstruction;
dfe0be07 93 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
af885e0f 94 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
dfe0be07 95 // the global tracking.
9a2cdbdf 96
8d8258f6 97 fClusterizer->SetInput(digitsTree);
98 fClusterizer->SetOutput(clustersTree);
a68156e6 99 if ( Debug() )
8d8258f6 100 fClusterizer->Digits2Clusters("deb all") ;
a68156e6 101 else
8d8258f6 102 fClusterizer->Digits2Clusters("") ;
a68156e6 103}
104
105//____________________________________________________________________________
9a2cdbdf 106void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
107 AliESDEvent* esd) const
a68156e6 108{
9a2cdbdf 109 // This method produces PHOS rec-particles,
110 // then it creates AliESDtracks out of them and
111 // write tracks to the ESD
112
113 AliPHOSTrackSegmentMaker *tsm = new AliPHOSTrackSegmentMakerv1(fGeom);
e68222ce 114 AliPHOSPID *pid = new AliPHOSPIDv1 (fGeom);
115
9a2cdbdf 116 // do current event; the loop over events is done by AliReconstruction::Run()
117 tsm->SetESD(esd) ;
118 tsm->SetInput(clustersTree);
119 if ( Debug() )
120 tsm->Clusters2TrackSegments("deb all") ;
121 else
122 tsm->Clusters2TrackSegments("") ;
35293055 123
9a2cdbdf 124 pid->SetInput(clustersTree, tsm->GetTrackSegments()) ;
125 pid->SetESD(esd) ;
dfe0be07 126 if ( Debug() )
9a2cdbdf 127 pid->TrackSegments2RecParticles("deb all") ;
dfe0be07 128 else
9a2cdbdf 129 pid->TrackSegments2RecParticles("") ;
7acf6008 130
77ea1c6f 131
23904d16 132 // This function creates AliESDtracks from AliPHOSRecParticles
133 // and
134 // writes them to the ESD
bf72996e 135
9a2cdbdf 136 TClonesArray *recParticles = pid->GetRecParticles();
dfe0be07 137 Int_t nOfRecParticles = recParticles->GetEntries();
a5fa6165 138
85c60a8e 139 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
dd7ee508 140 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
a5e00016 141
9a2cdbdf 142 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
a5e00016 143
144 // Read digits array
145
146 TBranch *branch = digitsTree->GetBranch("PHOS");
147 if (!branch) {
148 AliError("can't get the branch with the PHOS digits !");
149 return;
150 }
151 TClonesArray *digitsArray = new TClonesArray("AliPHOSDigit",100);
152 branch->SetAddress(&digitsArray);
153 branch->GetEntry(0);
154
155 // Get the clusters array
156
157 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
158 if (!emcbranch) {
159 AliError("can't get the branch with the PHOS EMC clusters !");
160 return;
161 }
162
163 TObjArray *emcRecPoints = new TObjArray(100) ;
164 emcbranch->SetAddress(&emcRecPoints);
165 emcbranch->GetEntry(0);
8013c27e 166
64df000d 167 //#########Calculate trigger and set trigger info###########
a5e00016 168
64df000d 169 AliPHOSTrigger tr ;
170 // tr.SetPatchSize(1);//create 4x4 patches
bfae5a5d 171 tr.SetSimulation(kFALSE);
172 tr.Trigger(digitsArray);
64df000d 173
174 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
175 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
176 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
177 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
178
64df000d 179 Int_t iSM2x2 = tr.Get2x2SuperModule();
180 Int_t iSMnxn = tr.GetnxnSuperModule();
181 Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
182 Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
183 Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
184 Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
185
a5e00016 186 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",
187 maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
188 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",
189 maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
64df000d 190
bfae5a5d 191 // Attention! PHOS modules in order to calculate AbsId need to be 1-5 not 0-4 as returns trigger.
192 Int_t iRelId2x2 []= {iSM2x2+1,0,iCrystalPhi2x2,iCrystalEta2x2};
64df000d 193 Int_t iAbsId2x2 =-1;
bfae5a5d 194 Int_t iRelIdnxn []= {iSMnxn+1,0,iCrystalPhinxn,iCrystalEtanxn};
64df000d 195 Int_t iAbsIdnxn =-1;
196 TVector3 pos2x2(-1,-1,-1);
197 TVector3 posnxn(-1,-1,-1);
9a2cdbdf 198 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
199 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
200 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
201 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
64df000d 202
203 TArrayF triggerPosition(6);
204 triggerPosition[0] = pos2x2(0) ;
205 triggerPosition[1] = pos2x2(1) ;
206 triggerPosition[2] = pos2x2(2) ;
207 triggerPosition[3] = posnxn(0) ;
208 triggerPosition[4] = posnxn(1) ;
209 triggerPosition[5] = posnxn(2) ;
210
211 TArrayF triggerAmplitudes(4);
212 triggerAmplitudes[0] = maxAmp2x2 ;
213 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
214 triggerAmplitudes[2] = maxAmpnxn ;
215 triggerAmplitudes[3] = ampOutOfPatchnxn ;
216
217 //esd->SetPHOSTriggerCells(triggerPosition);
218 esd->AddPHOSTriggerPosition(triggerPosition);
219 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
220
e68222ce 221
a5e00016 222 //########################################
223 //############# Fill CaloCells ###########
224 //########################################
225
226 Int_t nDigits = digitsArray->GetEntries();
227 Int_t idignew = 0 ;
228 AliDebug(1,Form("%d digits",nDigits));
229
230 const Int_t knEMC = fGeom->GetNModules()*fGeom->GetNPhi()*fGeom->GetNZ();
231 AliESDCaloCells &phsCells = *(esd->GetPHOSCells());
232 phsCells.CreateContainer(nDigits);
233 phsCells.SetType(AliESDCaloCells::kPHOSCell);
234
235 // Add to CaloCells only EMC digits with non-zero energy
236 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
237 const AliPHOSDigit * dig = (const AliPHOSDigit*)digitsArray->At(idig);
238 if(dig->GetId() <= knEMC && dig->GetEnergy() > 0 ){
710634f4 239 //printf("i %d; id %d; amp %f; time %e\n",
240 //idignew,dig->GetId(),dig->GetEnergy(), dig->GetTime());
a5e00016 241 phsCells.SetCell(idignew,dig->GetId(), dig->GetEnergy(), dig->GetTime());
242 idignew++;
243 }
e68222ce 244 }
a5e00016 245 phsCells.SetNumberOfCells(idignew);
246 phsCells.Sort();
e68222ce 247
a5e00016 248 //########################################
249 //############## Fill CaloClusters #######
250 //########################################
f4e0dd30 251
dfe0be07 252 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
a5e00016 253 AliPHOSRecParticle *rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
dfe0be07 254 if (Debug())
255 rp->Print();
25ed816e 256 // Get track segment and EMC rec.point associated with this rec.particle
a5e00016 257 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(tsm->GetTrackSegments()
258 ->At(rp->GetPHOSTSIndex()));
9a2cdbdf 259
a5e00016 260 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(ts->GetEmcIndex()));
25ed816e 261 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
e68222ce 262
85c60a8e 263 Float_t xyz[3];
8013c27e 264 for (Int_t ixyz=0; ixyz<3; ixyz++)
265 xyz[ixyz] = rp->GetPos()[ixyz];
dd7ee508 266
267 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
77ea1c6f 268
a5e00016 269 // Create cell lists
270
271 Int_t cellMult = emcRP->GetDigitsMultiplicity();
272 Int_t *digitsList = emcRP->GetDigitsList();
273 Float_t *rpElist = emcRP->GetEnergiesList() ;
274 UShort_t *absIdList = new UShort_t[cellMult];
275 Double_t *fracList = new Double_t[cellMult];
276
277 for (Int_t iCell=0; iCell<cellMult; iCell++) {
278 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(digitsArray->At(digitsList[iCell]));
279 absIdList[iCell] = (UShort_t)(digit->GetId());
280 if (digit->GetEnergy() > 0)
281 fracList[iCell] = rpElist[iCell]/digit->GetEnergy();
282 else
283 fracList[iCell] = 0;
25ed816e 284 }
77ea1c6f 285
7592dfc4 286 //Primaries
287 Int_t primMult = 0;
4dd59c4a 288 Int_t *primList = emcRP->GetPrimaries(primMult);
a5e00016 289
7592dfc4 290 // fills the ESDCaloCluster
8ada0ffe 291 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
a5e00016 292 ec->SetPosition(xyz); //rec.point position in MARS
293 ec->SetE(rp->Energy()); //total particle energy
25ed816e 294 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
e68222ce 295 ec->SetPid(rp->GetPID()) ; //array of particle identification
25ed816e 296 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
297 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
298 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
a5e00016 299 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
25ed816e 300 ec->SetClusterChi2(-1); //not yet implemented
78902954 301 ec->SetTOF(emcRP->GetTime()); //Time of flight
302
a5e00016 303 //Cells contributing to clusters
304 ec->SetNCells(cellMult);
305 ec->SetCellsAbsId(absIdList);
306 ec->SetCellsAmplitudeFraction(fracList);
7592dfc4 307
3744a6cf 308 //Distance to the nearest bad crystal
309 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
7592dfc4 310
311 //Array of MC indeces
4dd59c4a 312 TArrayI arrayPrim(primMult,primList);
7592dfc4 313 ec->AddLabels(arrayPrim);
314
315 //Array of tracks uncomment when available in future
316 //TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
317 //arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
318 //ec->AddTracksMatched(arrayTrackMatched);
64df000d 319
dfe0be07 320 // add the track to the esd object
a5e00016 321
85c60a8e 322 esd->AddCaloCluster(ec);
9a2cdbdf 323 delete ec;
e68222ce 324 }
a5e00016 325 digitsArray ->Delete();
326 delete digitsArray;
327 emcRecPoints->Delete();
328 delete emcRecPoints;
e68222ce 329 delete tsm;
330 delete pid;
dd7ee508 331}
332
e68222ce 333//____________________________________________________________________________
d76c31f4 334AliTracker* AliPHOSReconstructor::CreateTracker() const
dd7ee508 335{
9a2cdbdf 336 // creates the PHOS tracker
337 return new AliPHOSTracker();
338}
dd7ee508 339
1267d56d 340//____________________________________________________________________________
9a2cdbdf 341void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
342{
343 // Converts raw data to
344 // PHOS digits
345 // Works on a single-event basis
dd7ee508 346
9a2cdbdf 347 rawReader->Reset() ;
dd7ee508 348
77ea1c6f 349 AliPHOSRawDecoder * dc ;
350
b3006690 351 const TObjArray* maps = AliPHOSRecoParamEmc::GetMappings();
352 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
353
354 AliAltroMapping *mapping[4];
355 for(Int_t i = 0; i < 4; i++) {
356 mapping[i] = (AliAltroMapping*)maps->At(i);
357 }
358
77ea1c6f 359 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0)
b3006690 360 dc=new AliPHOSRawDecoderv1(rawReader,mapping);
710634f4 361 else
362 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v2")==0)
363 dc=new AliPHOSRawDecoderv2(rawReader,mapping);
364 else
365 dc=new AliPHOSRawDecoder(rawReader,mapping);
77ea1c6f 366
77ea1c6f 367 dc->SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
86121c91 368
9a2cdbdf 369 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
370 digits->SetName("DIGITS");
371 Int_t bufsize = 32000;
372 digitsTree->Branch("PHOS", &digits, bufsize);
dd7ee508 373
a28333c5 374 AliPHOSRawDigiProducer pr(fgkRecoParamEmc,fgkRecoParamCpv);
77ea1c6f 375 pr.MakeDigits(digits,dc);
376
377 delete dc ;
7592dfc4 378
9a2cdbdf 379 //!!!!for debug!!!
a28333c5 380/*
9a2cdbdf 381 Int_t modMax=-111;
382 Int_t colMax=-111;
383 Int_t rowMax=-111;
384 Float_t eMax=-333;
385 //!!!for debug!!!
386
387 Int_t relId[4];
388 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
389 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
390 if(digit->GetEnergy()>eMax) {
391 fGeom->AbsToRelNumbering(digit->GetId(),relId);
392 eMax=digit->GetEnergy();
393 modMax=relId[0];
394 rowMax=relId[2];
395 colMax=relId[3];
dd7ee508 396 }
397 }
398
9a2cdbdf 399 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
400 modMax,colMax,rowMax,eMax));
a28333c5 401*/
9a2cdbdf 402 digitsTree->Fill();
e68222ce 403 digits->Delete();
404 delete digits;
d7d3b67b 405}