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