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