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
170 tr.SetSimulation(kFALSE);
171 tr.Trigger(digitsArray);
173 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
174 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
175 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
176 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
178 Int_t iSM2x2 = tr.Get2x2SuperModule();
179 Int_t iSMnxn = tr.GetnxnSuperModule();
180 Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
181 Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
182 Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
183 Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
185 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",
186 maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
187 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",
188 maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
190 // Attention! PHOS modules in order to calculate AbsId need to be 1-5 not 0-4 as returns trigger.
191 Int_t iRelId2x2 []= {iSM2x2+1,0,iCrystalPhi2x2,iCrystalEta2x2};
193 Int_t iRelIdnxn []= {iSMnxn+1,0,iCrystalPhinxn,iCrystalEtanxn};
195 TVector3 pos2x2(-1,-1,-1);
196 TVector3 posnxn(-1,-1,-1);
197 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
198 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
199 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
200 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
202 TArrayF triggerPosition(6);
203 triggerPosition[0] = pos2x2(0) ;
204 triggerPosition[1] = pos2x2(1) ;
205 triggerPosition[2] = pos2x2(2) ;
206 triggerPosition[3] = posnxn(0) ;
207 triggerPosition[4] = posnxn(1) ;
208 triggerPosition[5] = posnxn(2) ;
210 TArrayF triggerAmplitudes(4);
211 triggerAmplitudes[0] = maxAmp2x2 ;
212 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
213 triggerAmplitudes[2] = maxAmpnxn ;
214 triggerAmplitudes[3] = ampOutOfPatchnxn ;
216 //esd->SetPHOSTriggerCells(triggerPosition);
217 esd->AddPHOSTriggerPosition(triggerPosition);
218 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
221 //########################################
222 //############# Fill CaloCells ###########
223 //########################################
225 Int_t nDigits = digitsArray->GetEntries();
227 AliDebug(1,Form("%d digits",nDigits));
229 const Int_t knEMC = fGeom->GetNModules()*fGeom->GetNPhi()*fGeom->GetNZ();
230 AliESDCaloCells &phsCells = *(esd->GetPHOSCells());
231 phsCells.CreateContainer(nDigits);
232 phsCells.SetType(AliESDCaloCells::kPHOSCell);
234 // Add to CaloCells only EMC digits with non-zero energy
235 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
236 const AliPHOSDigit * dig = (const AliPHOSDigit*)digitsArray->At(idig);
237 if(dig->GetId() <= knEMC && dig->GetEnergy() > 0 ){
238 //printf("i %d; id %d; amp %f; time %e\n",
239 //idignew,dig->GetId(),dig->GetEnergy(), dig->GetTime());
240 phsCells.SetCell(idignew,dig->GetId(), dig->GetEnergy(), dig->GetTime());
244 phsCells.SetNumberOfCells(idignew);
247 //########################################
248 //############## Fill CaloClusters #######
249 //########################################
251 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
252 AliPHOSRecParticle *rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
255 // Get track segment and EMC rec.point associated with this rec.particle
256 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(tsm->GetTrackSegments()
257 ->At(rp->GetPHOSTSIndex()));
259 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(ts->GetEmcIndex()));
260 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
263 for (Int_t ixyz=0; ixyz<3; ixyz++)
264 xyz[ixyz] = rp->GetPos()[ixyz];
266 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
270 Int_t cellMult = emcRP->GetDigitsMultiplicity();
271 Int_t *digitsList = emcRP->GetDigitsList();
272 Float_t *rpElist = emcRP->GetEnergiesList() ;
273 UShort_t *absIdList = new UShort_t[cellMult];
274 Double_t *fracList = new Double_t[cellMult];
276 for (Int_t iCell=0; iCell<cellMult; iCell++) {
277 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(digitsArray->At(digitsList[iCell]));
278 absIdList[iCell] = (UShort_t)(digit->GetId());
279 if (digit->GetEnergy() > 0)
280 fracList[iCell] = rpElist[iCell]/digit->GetEnergy();
287 Int_t *primList = emcRP->GetPrimaries(primMult);
289 // fills the ESDCaloCluster
290 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
291 ec->SetPosition(xyz); //rec.point position in MARS
292 ec->SetE(rp->Energy()); //total particle energy
293 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
294 ec->SetPid(rp->GetPID()) ; //array of particle identification
295 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
296 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
297 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
298 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
299 ec->SetClusterChi2(-1); //not yet implemented
300 ec->SetM11(-1) ; //not yet implemented
302 //Cells contributing to clusters
303 ec->SetNCells(cellMult);
304 ec->SetCellsAbsId(absIdList);
305 ec->SetCellsAmplitudeFraction(fracList);
307 //Distance to the nearest bad crystal
308 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
310 //Array of MC indeces
311 TArrayI arrayPrim(primMult,primList);
312 ec->AddLabels(arrayPrim);
314 //Array of tracks uncomment when available in future
315 //TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
316 //arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
317 //ec->AddTracksMatched(arrayTrackMatched);
319 // add the track to the esd object
321 esd->AddCaloCluster(ec);
324 digitsArray ->Delete();
326 emcRecPoints->Delete();
332 //____________________________________________________________________________
333 AliTracker* AliPHOSReconstructor::CreateTracker() const
335 // creates the PHOS tracker
336 return new AliPHOSTracker();
339 //____________________________________________________________________________
340 void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
342 // Converts raw data to
344 // Works on a single-event basis
348 AliPHOSRawDecoder * dc ;
350 const TObjArray* maps = AliPHOSRecoParamEmc::GetMappings();
351 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
353 AliAltroMapping *mapping[4];
354 for(Int_t i = 0; i < 4; i++) {
355 mapping[i] = (AliAltroMapping*)maps->At(i);
358 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0)
359 dc=new AliPHOSRawDecoderv1(rawReader,mapping);
361 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v2")==0)
362 dc=new AliPHOSRawDecoderv2(rawReader,mapping);
364 dc=new AliPHOSRawDecoder(rawReader,mapping);
366 dc->SetOldRCUFormat(fgkRecoParamEmc->IsOldRCUFormat());
368 dc->SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
370 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
371 digits->SetName("DIGITS");
372 Int_t bufsize = 32000;
373 digitsTree->Branch("PHOS", &digits, bufsize);
375 AliPHOSRawDigiProducer pr(fgkRecoParamEmc,fgkRecoParamCpv);
376 pr.MakeDigits(digits,dc);
389 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
390 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
391 if(digit->GetEnergy()>eMax) {
392 fGeom->AbsToRelNumbering(digit->GetId(),relId);
393 eMax=digit->GetEnergy();
400 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
401 modMax,colMax,rowMax,eMax));