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 "AliPHOSTrigger.h"
41 #include "AliPHOSGeometry.h"
42 #include "AliPHOSRecoParam.h"
43 #include "AliPHOSRecoParamEmc.h"
44 #include "AliPHOSRecoParamCpv.h"
45 #include "AliPHOSDigit.h"
46 #include "AliPHOSTrackSegment.h"
47 #include "AliPHOSEmcRecPoint.h"
48 #include "AliPHOSRecParticle.h"
49 #include "AliPHOSRawDecoder.h"
50 #include "AliPHOSRawDecoderv1.h"
51 #include "AliPHOSRawDecoderv2.h"
52 #include "AliPHOSRawDigiProducer.h"
53 #include "AliPHOSPulseGenerator.h"
55 ClassImp(AliPHOSReconstructor)
57 Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
58 AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamEmc =0; // EMC rec. parameters
59 AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamCpv =0; // CPV rec. parameters
60 TClonesArray* AliPHOSReconstructor::fgDigitsArray = 0; // Array of PHOS digits
61 TObjArray* AliPHOSReconstructor::fgEMCRecPoints = 0; // Array of EMC rec.points
63 //____________________________________________________________________________
64 AliPHOSReconstructor::AliPHOSReconstructor() :
65 fGeom(NULL),fClusterizer(NULL),fTSM(NULL),fPID(NULL)
69 if (!fgkRecoParamEmc) {
70 AliWarning("The Reconstruction parameters for EMC nonitialized - Used default one");
71 fgkRecoParamEmc = AliPHOSRecoParamEmc::GetEmcDefaultParameters();
74 if (!fgkRecoParamCpv) {
75 AliWarning("The Reconstruction parameters for CPV nonitialized - Used default one");
76 fgkRecoParamCpv = AliPHOSRecoParamCpv::GetCpvDefaultParameters();
79 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
80 fClusterizer = new AliPHOSClusterizerv1 (fGeom);
81 fTSM = new AliPHOSTrackSegmentMakerv1(fGeom);
82 fPID = new AliPHOSPIDv1 (fGeom);
83 fgDigitsArray = new TClonesArray("AliPHOSDigit",100);
84 fgEMCRecPoints= new TObjArray(100) ;
87 //____________________________________________________________________________
88 AliPHOSReconstructor::~AliPHOSReconstructor()
96 delete fgEMCRecPoints;
99 //____________________________________________________________________________
100 void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
102 // 'single-event' local reco method called by AliReconstruction;
103 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
104 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
105 // the global tracking.
107 fClusterizer->SetInput(digitsTree);
108 fClusterizer->SetOutput(clustersTree);
110 fClusterizer->Digits2Clusters("deb all") ;
112 fClusterizer->Digits2Clusters("") ;
115 //____________________________________________________________________________
116 void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
117 AliESDEvent* esd) const
119 // This method produces PHOS rec-particles,
120 // then it creates AliESDtracks out of them and
121 // write tracks to the ESD
124 // do current event; the loop over events is done by AliReconstruction::Run()
126 fTSM->SetInput(clustersTree);
128 fTSM->Clusters2TrackSegments("deb all") ;
130 fTSM->Clusters2TrackSegments("") ;
132 fPID->SetInput(clustersTree, fTSM->GetTrackSegments()) ;
135 fPID->TrackSegments2RecParticles("deb all") ;
137 fPID->TrackSegments2RecParticles("") ;
139 TClonesArray *recParticles = fPID->GetRecParticles();
140 Int_t nOfRecParticles = recParticles->GetEntriesFast();
142 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
143 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
145 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
149 TBranch *branch = digitsTree->GetBranch("PHOS");
151 AliError("can't get the branch with the PHOS digits !");
154 branch->SetAddress(&fgDigitsArray);
157 // Get the clusters array
159 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
161 AliError("can't get the branch with the PHOS EMC clusters !");
165 emcbranch->SetAddress(&fgEMCRecPoints);
166 emcbranch->GetEntry(0);
168 //#########Calculate trigger and set trigger info###########
171 // tr.SetPatchSize(1);//create 4x4 patches
172 tr.SetSimulation(kFALSE);
173 tr.Trigger(fgDigitsArray);
175 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
176 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
177 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
178 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
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();
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));
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};
195 Int_t iRelIdnxn []= {iSMnxn+1,0,iCrystalPhinxn,iCrystalEtanxn};
197 TVector3 pos2x2(-1,-1,-1);
198 TVector3 posnxn(-1,-1,-1);
199 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
200 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
201 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
202 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
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) ;
212 TArrayF triggerAmplitudes(4);
213 triggerAmplitudes[0] = maxAmp2x2 ;
214 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
215 triggerAmplitudes[2] = maxAmpnxn ;
216 triggerAmplitudes[3] = ampOutOfPatchnxn ;
218 //esd->SetPHOSTriggerCells(triggerPosition);
219 esd->AddPHOSTriggerPosition(triggerPosition);
220 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
223 //########################################
224 //############# Fill CaloCells ###########
225 //########################################
227 Int_t nDigits = fgDigitsArray->GetEntries();
229 AliDebug(1,Form("%d digits",nDigits));
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);
236 // Add to CaloCells only EMC digits with non-zero energy
237 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
238 const AliPHOSDigit * dig = (const AliPHOSDigit*)fgDigitsArray->At(idig);
239 if(dig->GetId() <= knEMC && dig->GetEnergy() > 0 ){
240 //printf("i %d; id %d; amp %f; time %e\n",
241 //idignew,dig->GetId(),dig->GetEnergy(), dig->GetTime());
242 phsCells.SetCell(idignew,dig->GetId(), dig->GetEnergy(), dig->GetTime());
246 phsCells.SetNumberOfCells(idignew);
249 //########################################
250 //############## Fill CaloClusters #######
251 //########################################
253 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
254 AliPHOSRecParticle *rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
257 // Get track segment and EMC rec.point associated with this rec.particle
258 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(fTSM->GetTrackSegments()
259 ->At(rp->GetPHOSTSIndex()));
261 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(fgEMCRecPoints->At(ts->GetEmcIndex()));
262 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
265 for (Int_t ixyz=0; ixyz<3; ixyz++)
266 xyz[ixyz] = rp->GetPos()[ixyz];
268 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
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];
278 for (Int_t iCell=0; iCell<cellMult; iCell++) {
279 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(fgDigitsArray->At(digitsList[iCell]));
280 absIdList[iCell] = (UShort_t)(digit->GetId());
281 if (digit->GetEnergy() > 0)
282 fracList[iCell] = rpElist[iCell]/digit->GetEnergy();
289 Int_t *primList = emcRP->GetPrimaries(primMult);
292 if (fgkRecoParamEmc->Ecore2ESD())
293 energy = emcRP->GetCoreEnergy();
295 energy = rp->Energy();
297 // fills the ESDCaloCluster
298 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
299 ec->SetPosition(xyz); //rec.point position in MARS
300 ec->SetE(energy); //total or core particle energy
301 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
302 ec->SetPid(rp->GetPID()) ; //array of particle identification
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
306 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
307 ec->SetClusterChi2(-1); //not yet implemented
308 ec->SetTOF(emcRP->GetTime()); //Time of flight
310 //Cells contributing to clusters
311 ec->SetNCells(cellMult);
312 ec->SetCellsAbsId(absIdList);
313 ec->SetCellsAmplitudeFraction(fracList);
315 //Distance to the nearest bad crystal
316 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
318 //Array of MC indeces
319 TArrayI arrayPrim(primMult,primList);
320 ec->AddLabels(arrayPrim);
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);
327 // add the track to the esd object
329 esd->AddCaloCluster(ec);
334 fgDigitsArray ->Delete();
335 fgEMCRecPoints->Delete();
336 recParticles ->Delete();
339 //____________________________________________________________________________
340 AliTracker* AliPHOSReconstructor::CreateTracker() const
342 // creates the PHOS tracker
343 return new AliPHOSTracker();
346 //____________________________________________________________________________
347 void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
349 // Converts raw data to
351 // Works on a single-event basis
355 AliPHOSRawDecoder * dc ;
357 const TObjArray* maps = AliPHOSRecoParamEmc::GetMappings();
358 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
360 AliAltroMapping *mapping[4];
361 for(Int_t i = 0; i < 4; i++) {
362 mapping[i] = (AliAltroMapping*)maps->At(i);
365 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0)
366 dc=new AliPHOSRawDecoderv1(rawReader,mapping);
368 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v2")==0)
369 dc=new AliPHOSRawDecoderv2(rawReader,mapping);
371 dc=new AliPHOSRawDecoder(rawReader,mapping);
373 dc->SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
375 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
376 digits->SetName("DIGITS");
377 Int_t bufsize = 32000;
378 digitsTree->Branch("PHOS", &digits, bufsize);
380 AliPHOSRawDigiProducer pr(fgkRecoParamEmc,fgkRecoParamCpv);
381 pr.MakeDigits(digits,dc);
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();
405 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
406 modMax,colMax,rowMax,eMax));