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