1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
20 //-- Yves Schutz (SUBATECH)
21 // Reconstruction class. Redesigned from the old AliReconstructionner class and
22 // derived from STEER/AliReconstructor.
24 // --- ROOT system ---
26 // --- Standard library ---
28 // --- AliRoot header files ---
30 #include "AliAltroMapping.h"
31 #include "AliESDEvent.h"
32 #include "AliESDCaloCluster.h"
33 #include "AliESDCaloCells.h"
34 #include "AliPHOSReconstructor.h"
35 #include "AliPHOSClusterizerv1.h"
36 #include "AliPHOSTrackSegmentMakerv1.h"
37 #include "AliPHOSPIDv1.h"
38 #include "AliPHOSTracker.h"
39 #include "AliRawReader.h"
40 #include "AliCDBEntry.h"
41 #include "AliCDBManager.h"
42 #include "AliPHOSTrigger.h"
43 #include "AliPHOSGeometry.h"
44 #include "AliPHOSDigit.h"
45 #include "AliPHOSTrackSegment.h"
46 #include "AliPHOSEmcRecPoint.h"
47 #include "AliPHOSRecParticle.h"
48 #include "AliPHOSRawDecoder.h"
49 #include "AliPHOSRawDecoderv1.h"
50 #include "AliPHOSRawDecoderv2.h"
51 #include "AliPHOSRawDigiProducer.h"
52 #include "AliPHOSPulseGenerator.h"
54 ClassImp(AliPHOSReconstructor)
56 Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
57 TClonesArray* AliPHOSReconstructor::fgDigitsArray = 0; // Array of PHOS digits
58 TObjArray* AliPHOSReconstructor::fgEMCRecPoints = 0; // Array of EMC rec.points
60 //____________________________________________________________________________
61 AliPHOSReconstructor::AliPHOSReconstructor() :
62 fGeom(NULL),fClusterizer(NULL),fTSM(NULL),fPID(NULL)
65 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
66 fClusterizer = new AliPHOSClusterizerv1 (fGeom);
67 fTSM = new AliPHOSTrackSegmentMakerv1(fGeom);
68 fPID = new AliPHOSPIDv1 (fGeom);
69 fgDigitsArray = new TClonesArray("AliPHOSDigit",100);
70 fgEMCRecPoints= new TObjArray(100) ;
73 //____________________________________________________________________________
74 AliPHOSReconstructor::~AliPHOSReconstructor()
82 delete fgEMCRecPoints;
85 //____________________________________________________________________________
86 void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
88 // 'single-event' local reco method called by AliReconstruction;
89 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
90 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
91 // the global tracking.
93 fClusterizer->InitParameters();
94 fClusterizer->SetInput(digitsTree);
95 fClusterizer->SetOutput(clustersTree);
97 fClusterizer->Digits2Clusters("deb all") ;
99 fClusterizer->Digits2Clusters("") ;
102 //____________________________________________________________________________
103 void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
104 AliESDEvent* esd) const
106 // This method produces PHOS rec-particles,
107 // then it creates AliESDtracks out of them and
108 // write tracks to the ESD
111 // do current event; the loop over events is done by AliReconstruction::Run()
113 fTSM->SetInput(clustersTree);
115 fTSM->Clusters2TrackSegments("deb all") ;
117 fTSM->Clusters2TrackSegments("") ;
119 fPID->SetEnergyCorrectionOn(GetRecoParam()->GetEMCEnergyCorrectionOn());
121 fPID->SetInput(clustersTree, fTSM->GetTrackSegments()) ;
124 fPID->TrackSegments2RecParticles("deb all") ;
126 fPID->TrackSegments2RecParticles("") ;
128 TClonesArray *recParticles = fPID->GetRecParticles();
129 Int_t nOfRecParticles = recParticles->GetEntriesFast();
131 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
132 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
134 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
138 TBranch *branch = digitsTree->GetBranch("PHOS");
140 AliError("can't get the branch with the PHOS digits !");
143 branch->SetAddress(&fgDigitsArray);
146 // Get the clusters array
148 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
150 AliError("can't get the branch with the PHOS EMC clusters !");
154 emcbranch->SetAddress(&fgEMCRecPoints);
155 emcbranch->GetEntry(0);
157 //#########Calculate trigger and set trigger info###########
160 // tr.SetPatchSize(1);//create 4x4 patches
161 tr.SetSimulation(kFALSE);
162 tr.Trigger(fgDigitsArray);
164 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
165 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
166 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
167 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
169 Int_t iSM2x2 = tr.Get2x2SuperModule();
170 Int_t iSMnxn = tr.GetnxnSuperModule();
171 Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
172 Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
173 Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
174 Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
176 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",
177 maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
178 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",
179 maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
181 // Attention! PHOS modules in order to calculate AbsId need to be 1-5 not 0-4 as returns trigger.
182 Int_t iRelId2x2 []= {iSM2x2+1,0,iCrystalPhi2x2,iCrystalEta2x2};
184 Int_t iRelIdnxn []= {iSMnxn+1,0,iCrystalPhinxn,iCrystalEtanxn};
186 TVector3 pos2x2(-1,-1,-1);
187 TVector3 posnxn(-1,-1,-1);
188 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
189 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
190 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
191 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
193 TArrayF triggerPosition(6);
194 triggerPosition[0] = pos2x2(0) ;
195 triggerPosition[1] = pos2x2(1) ;
196 triggerPosition[2] = pos2x2(2) ;
197 triggerPosition[3] = posnxn(0) ;
198 triggerPosition[4] = posnxn(1) ;
199 triggerPosition[5] = posnxn(2) ;
201 TArrayF triggerAmplitudes(4);
202 triggerAmplitudes[0] = maxAmp2x2 ;
203 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
204 triggerAmplitudes[2] = maxAmpnxn ;
205 triggerAmplitudes[3] = ampOutOfPatchnxn ;
207 //esd->SetPHOSTriggerCells(triggerPosition);
208 esd->AddPHOSTriggerPosition(triggerPosition);
209 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
212 //########################################
213 //############# Fill CaloCells ###########
214 //########################################
216 Int_t nDigits = fgDigitsArray->GetEntries();
218 AliDebug(1,Form("%d digits",nDigits));
220 const Int_t knEMC = fGeom->GetNModules()*fGeom->GetNPhi()*fGeom->GetNZ();
221 AliESDCaloCells &phsCells = *(esd->GetPHOSCells());
222 phsCells.CreateContainer(nDigits);
223 phsCells.SetType(AliESDCaloCells::kPHOSCell);
225 // Add to CaloCells only EMC digits with non-zero energy
226 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
227 const AliPHOSDigit * dig = (const AliPHOSDigit*)fgDigitsArray->At(idig);
228 if(dig->GetId() <= knEMC && dig->GetEnergy() > GetRecoParam()->GetEMCMinE() ){
229 //printf("i %d; id %d; amp %f; time %e\n",
230 //idignew,dig->GetId(),dig->GetEnergy(), dig->GetTime());
231 phsCells.SetCell(idignew,dig->GetId(), dig->GetEnergy(), dig->GetTime());
235 phsCells.SetNumberOfCells(idignew);
238 //########################################
239 //############## Fill CaloClusters #######
240 //########################################
242 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
243 AliPHOSRecParticle *rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
246 // Get track segment and EMC rec.point associated with this rec.particle
247 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(fTSM->GetTrackSegments()
248 ->At(rp->GetPHOSTSIndex()));
250 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(fgEMCRecPoints->At(ts->GetEmcIndex()));
251 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
254 for (Int_t ixyz=0; ixyz<3; ixyz++)
255 xyz[ixyz] = rp->GetPos()[ixyz];
257 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
261 Int_t cellMult = emcRP->GetDigitsMultiplicity();
262 Int_t *digitsList = emcRP->GetDigitsList();
263 Float_t *rpElist = emcRP->GetEnergiesList() ;
264 UShort_t *absIdList = new UShort_t[cellMult];
265 Double_t *fracList = new Double_t[cellMult];
267 for (Int_t iCell=0; iCell<cellMult; iCell++) {
268 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(fgDigitsArray->At(digitsList[iCell]));
269 absIdList[iCell] = (UShort_t)(digit->GetId());
270 if (digit->GetEnergy() > 0)
271 fracList[iCell] = rpElist[iCell]/digit->GetEnergy();
278 Int_t *primList = emcRP->GetPrimaries(primMult);
281 if (GetRecoParam()->EMCEcore2ESD())
282 energy = emcRP->GetCoreEnergy();
284 energy = rp->Energy();
286 // fills the ESDCaloCluster
287 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
288 ec->SetPosition(xyz); //rec.point position in MARS
289 ec->SetE(energy); //total or core particle energy
290 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
291 ec->SetPid(rp->GetPID()) ; //array of particle identification
292 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
293 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
294 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
295 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
296 ec->SetClusterChi2(-1); //not yet implemented
297 ec->SetTOF(emcRP->GetTime()); //Time of flight
299 //Cells contributing to clusters
300 ec->SetNCells(cellMult);
301 ec->SetCellsAbsId(absIdList);
302 ec->SetCellsAmplitudeFraction(fracList);
304 //Distance to the nearest bad crystal
305 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
307 //Array of MC indeces
308 TArrayI arrayPrim(primMult,primList);
309 ec->AddLabels(arrayPrim);
312 TArrayI arrayTrackMatched(1);
313 arrayTrackMatched[0]= ts->GetTrackIndex();
314 ec->AddTracksMatched(arrayTrackMatched);
316 esd->AddCaloCluster(ec);
321 fgDigitsArray ->Delete();
322 fgEMCRecPoints->Delete();
323 recParticles ->Delete();
326 //____________________________________________________________________________
327 AliTracker* AliPHOSReconstructor::CreateTracker() const
329 // creates the PHOS tracker
330 return new AliPHOSTracker();
333 //____________________________________________________________________________
334 void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
336 // Converts raw data to
338 // Works on a single-event basis
341 AliPHOSRawDecoder * dc ;
343 const TObjArray* maps = AliPHOSRecoParam::GetMappings();
344 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
346 AliAltroMapping *mapping[4];
347 for(Int_t i = 0; i < 4; i++) {
348 mapping[i] = (AliAltroMapping*)maps->At(i);
351 if (strcmp(GetRecoParam()->EMCDecoderVersion(),"v1")==0)
352 dc=new AliPHOSRawDecoderv1(rawReader,mapping);
353 else if (strcmp(GetRecoParam()->EMCDecoderVersion(),"v2")==0)
354 dc=new AliPHOSRawDecoderv2(rawReader,mapping);
356 dc=new AliPHOSRawDecoder(rawReader,mapping);
358 dc->SubtractPedestals(GetRecoParam()->EMCSubtractPedestals());
360 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
361 digits->SetName("DIGITS");
362 Int_t bufsize = 32000;
363 digitsTree->Branch("PHOS", &digits, bufsize);
365 AliPHOSRawDigiProducer pr(GetRecoParam());
366 pr.MakeDigits(digits,dc);
379 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
380 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
381 if(digit->GetEnergy()>eMax) {
382 fGeom->AbsToRelNumbering(digit->GetId(),relId);
383 eMax=digit->GetEnergy();
390 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
391 modMax,colMax,rowMax,eMax));