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
61 //____________________________________________________________________________
62 AliPHOSReconstructor::AliPHOSReconstructor() :
67 if (!fgkRecoParamEmc) {
68 AliWarning("The Reconstruction parameters for EMC nonitialized - Used default one");
69 fgkRecoParamEmc = AliPHOSRecoParamEmc::GetEmcDefaultParameters();
72 if (!fgkRecoParamCpv) {
73 AliWarning("The Reconstruction parameters for CPV nonitialized - Used default one");
74 fgkRecoParamCpv = AliPHOSRecoParamCpv::GetCpvDefaultParameters();
77 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
80 //____________________________________________________________________________
81 AliPHOSReconstructor::~AliPHOSReconstructor()
87 //____________________________________________________________________________
88 void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
90 // 'single-event' local reco method called by AliReconstruction;
91 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
92 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
93 // the global tracking.
95 AliPHOSClusterizerv1 clu(fGeom);
96 clu.SetInput(digitsTree);
97 clu.SetOutput(clustersTree);
99 clu.Digits2Clusters("deb all") ;
101 clu.Digits2Clusters("") ;
104 //____________________________________________________________________________
105 void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
106 AliESDEvent* esd) const
108 // This method produces PHOS rec-particles,
109 // then it creates AliESDtracks out of them and
110 // write tracks to the ESD
112 AliPHOSTrackSegmentMaker *tsm = new AliPHOSTrackSegmentMakerv1(fGeom);
113 AliPHOSPID *pid = new AliPHOSPIDv1 (fGeom);
115 // do current event; the loop over events is done by AliReconstruction::Run()
117 tsm->SetInput(clustersTree);
119 tsm->Clusters2TrackSegments("deb all") ;
121 tsm->Clusters2TrackSegments("") ;
123 pid->SetInput(clustersTree, tsm->GetTrackSegments()) ;
126 pid->TrackSegments2RecParticles("deb all") ;
128 pid->TrackSegments2RecParticles("") ;
131 // This function creates AliESDtracks from AliPHOSRecParticles
133 // writes them to the ESD
135 TClonesArray *recParticles = pid->GetRecParticles();
136 Int_t nOfRecParticles = recParticles->GetEntries();
138 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
139 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
141 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
145 TBranch *branch = digitsTree->GetBranch("PHOS");
147 AliError("can't get the branch with the PHOS digits !");
150 TClonesArray *digitsArray = new TClonesArray("AliPHOSDigit",100);
151 branch->SetAddress(&digitsArray);
154 // Get the clusters array
156 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
158 AliError("can't get the branch with the PHOS EMC clusters !");
162 TObjArray *emcRecPoints = new TObjArray(100) ;
163 emcbranch->SetAddress(&emcRecPoints);
164 emcbranch->GetEntry(0);
166 //#########Calculate trigger and set trigger info###########
169 // tr.SetPatchSize(1);//create 4x4 patches
172 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
173 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
174 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
175 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
177 Int_t iSM2x2 = tr.Get2x2SuperModule();
178 Int_t iSMnxn = tr.GetnxnSuperModule();
179 Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
180 Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
181 Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
182 Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
184 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",
185 maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
186 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",
187 maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
189 Int_t iRelId2x2 []= {iSM2x2+1,0,iCrystalPhi2x2,iCrystalEta2x2};// PHOS modules in order to calculate AbsId need to be 1-5 not 0-4 as returns trigger.
191 Int_t iRelIdnxn []= {iSMnxn+1,0,iCrystalPhinxn,iCrystalEtanxn};// PHOS modules in order to calculate AbsId need to be 1-5 not 0-4 as returns trigger.
193 TVector3 pos2x2(-1,-1,-1);
194 TVector3 posnxn(-1,-1,-1);
195 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
196 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
197 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
198 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
200 TArrayF triggerPosition(6);
201 triggerPosition[0] = pos2x2(0) ;
202 triggerPosition[1] = pos2x2(1) ;
203 triggerPosition[2] = pos2x2(2) ;
204 triggerPosition[3] = posnxn(0) ;
205 triggerPosition[4] = posnxn(1) ;
206 triggerPosition[5] = posnxn(2) ;
208 TArrayF triggerAmplitudes(4);
209 triggerAmplitudes[0] = maxAmp2x2 ;
210 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
211 triggerAmplitudes[2] = maxAmpnxn ;
212 triggerAmplitudes[3] = ampOutOfPatchnxn ;
214 //esd->SetPHOSTriggerCells(triggerPosition);
215 esd->AddPHOSTriggerPosition(triggerPosition);
216 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
219 //########################################
220 //############# Fill CaloCells ###########
221 //########################################
223 Int_t nDigits = digitsArray->GetEntries();
225 AliDebug(1,Form("%d digits",nDigits));
227 const Int_t knEMC = fGeom->GetNModules()*fGeom->GetNPhi()*fGeom->GetNZ();
228 AliESDCaloCells &phsCells = *(esd->GetPHOSCells());
229 phsCells.CreateContainer(nDigits);
230 phsCells.SetType(AliESDCaloCells::kPHOSCell);
232 // Add to CaloCells only EMC digits with non-zero energy
233 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
234 const AliPHOSDigit * dig = (const AliPHOSDigit*)digitsArray->At(idig);
235 if(dig->GetId() <= knEMC && dig->GetEnergy() > 0 ){
236 //printf("i %d; id %d; amp %f; time %e\n",
237 //idignew,dig->GetId(),dig->GetEnergy(), dig->GetTime());
238 phsCells.SetCell(idignew,dig->GetId(), dig->GetEnergy(), dig->GetTime());
242 phsCells.SetNumberOfCells(idignew);
245 //########################################
246 //############## Fill CaloClusters #######
247 //########################################
249 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
250 AliPHOSRecParticle *rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
253 // Get track segment and EMC rec.point associated with this rec.particle
254 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(tsm->GetTrackSegments()
255 ->At(rp->GetPHOSTSIndex()));
257 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(ts->GetEmcIndex()));
258 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
261 for (Int_t ixyz=0; ixyz<3; ixyz++)
262 xyz[ixyz] = rp->GetPos()[ixyz];
264 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
268 Int_t cellMult = emcRP->GetDigitsMultiplicity();
269 Int_t *digitsList = emcRP->GetDigitsList();
270 Float_t *rpElist = emcRP->GetEnergiesList() ;
271 UShort_t *absIdList = new UShort_t[cellMult];
272 Double_t *fracList = new Double_t[cellMult];
274 for (Int_t iCell=0; iCell<cellMult; iCell++) {
275 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(digitsArray->At(digitsList[iCell]));
276 absIdList[iCell] = (UShort_t)(digit->GetId());
277 if (digit->GetEnergy() > 0)
278 fracList[iCell] = rpElist[iCell]/digit->GetEnergy();
285 Int_t *primList = emcRP->GetPrimaries(primMult);
287 // fills the ESDCaloCluster
288 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
289 ec->SetPosition(xyz); //rec.point position in MARS
290 ec->SetE(rp->Energy()); //total particle energy
291 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
292 ec->SetPid(rp->GetPID()) ; //array of particle identification
293 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
294 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
295 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
296 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
297 ec->SetClusterChi2(-1); //not yet implemented
298 ec->SetM11(-1) ; //not yet implemented
300 //Cells contributing to clusters
301 ec->SetNCells(cellMult);
302 ec->SetCellsAbsId(absIdList);
303 ec->SetCellsAmplitudeFraction(fracList);
305 //Distance to the nearest bad crystal
306 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
308 //Array of MC indeces
309 TArrayI arrayPrim(primMult,primList);
310 ec->AddLabels(arrayPrim);
312 //Array of tracks uncomment when available in future
313 //TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
314 //arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
315 //ec->AddTracksMatched(arrayTrackMatched);
317 // add the track to the esd object
319 esd->AddCaloCluster(ec);
322 digitsArray ->Delete();
324 emcRecPoints->Delete();
330 //____________________________________________________________________________
331 AliTracker* AliPHOSReconstructor::CreateTracker() const
333 // creates the PHOS tracker
334 return new AliPHOSTracker();
337 //____________________________________________________________________________
338 void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
340 // Converts raw data to
342 // Works on a single-event basis
346 AliPHOSRawDecoder * dc ;
348 const TObjArray* maps = AliPHOSRecoParamEmc::GetMappings();
349 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
351 AliAltroMapping *mapping[4];
352 for(Int_t i = 0; i < 4; i++) {
353 mapping[i] = (AliAltroMapping*)maps->At(i);
356 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0)
357 dc=new AliPHOSRawDecoderv1(rawReader,mapping);
359 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v2")==0)
360 dc=new AliPHOSRawDecoderv2(rawReader,mapping);
362 dc=new AliPHOSRawDecoder(rawReader,mapping);
364 dc->SetOldRCUFormat(fgkRecoParamEmc->IsOldRCUFormat());
366 dc->SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
368 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
369 digits->SetName("DIGITS");
370 Int_t bufsize = 32000;
371 digitsTree->Branch("PHOS", &digits, bufsize);
373 AliPHOSRawDigiProducer pr(fgkRecoParamEmc,fgkRecoParamCpv);
374 pr.MakeDigits(digits,dc);
387 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
388 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
389 if(digit->GetEnergy()>eMax) {
390 fGeom->AbsToRelNumbering(digit->GetId(),relId);
391 eMax=digit->GetEnergy();
398 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
399 modMax,colMax,rowMax,eMax));