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 "AliPHOSCalibData.h"
41 #include "AliCDBEntry.h"
42 #include "AliCDBManager.h"
43 #include "AliPHOSTrigger.h"
44 #include "AliPHOSGeometry.h"
45 #include "AliPHOSDigit.h"
46 #include "AliPHOSTrackSegment.h"
47 #include "AliPHOSEmcRecPoint.h"
48 #include "AliPHOSRecParticle.h"
49 #include "AliPHOSRawFitterv0.h"
50 #include "AliPHOSRawFitterv1.h"
51 #include "AliPHOSRawFitterv2.h"
52 #include "AliPHOSRawDigiProducer.h"
53 #include "AliPHOSPulseGenerator.h"
55 ClassImp(AliPHOSReconstructor)
57 Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
58 TClonesArray* AliPHOSReconstructor::fgDigitsArray = 0; // Array of PHOS digits
59 TObjArray* AliPHOSReconstructor::fgEMCRecPoints = 0; // Array of EMC rec.points
60 AliPHOSCalibData * AliPHOSReconstructor::fgCalibData = 0 ;
63 //____________________________________________________________________________
64 AliPHOSReconstructor::AliPHOSReconstructor() :
65 fGeom(NULL),fClusterizer(NULL),fTSM(NULL),fPID(NULL)
68 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
69 fClusterizer = new AliPHOSClusterizerv1 (fGeom);
70 fTSM = new AliPHOSTrackSegmentMakerv1(fGeom);
71 fPID = new AliPHOSPIDv1 (fGeom);
72 fgDigitsArray = new TClonesArray("AliPHOSDigit",100);
73 fgEMCRecPoints= new TObjArray(100) ;
75 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
79 //____________________________________________________________________________
80 AliPHOSReconstructor::~AliPHOSReconstructor()
88 delete fgEMCRecPoints;
91 //____________________________________________________________________________
92 void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
94 // 'single-event' local reco method called by AliReconstruction;
95 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
96 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
97 // the global tracking.
99 fClusterizer->InitParameters();
100 fClusterizer->SetInput(digitsTree);
101 fClusterizer->SetOutput(clustersTree);
103 fClusterizer->Digits2Clusters("deb all") ;
105 fClusterizer->Digits2Clusters("") ;
108 //____________________________________________________________________________
109 void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
110 AliESDEvent* esd) const
112 // This method produces PHOS rec-particles,
113 // then it creates AliESDtracks out of them and
114 // write tracks to the ESD
117 // do current event; the loop over events is done by AliReconstruction::Run()
119 fTSM->SetInput(clustersTree);
121 fTSM->Clusters2TrackSegments("deb all") ;
123 fTSM->Clusters2TrackSegments("") ;
125 fPID->SetEnergyCorrectionOn(GetRecoParam()->GetEMCEnergyCorrectionOn());
127 fPID->SetInput(clustersTree, fTSM->GetTrackSegments()) ;
130 fPID->TrackSegments2RecParticles("deb all") ;
132 fPID->TrackSegments2RecParticles("") ;
134 TClonesArray *recParticles = fPID->GetRecParticles();
135 Int_t nOfRecParticles = recParticles->GetEntriesFast();
137 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
138 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
140 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
144 TBranch *branch = digitsTree->GetBranch("PHOS");
146 AliError("can't get the branch with the PHOS digits !");
149 branch->SetAddress(&fgDigitsArray);
152 // Get the clusters array
154 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
156 AliError("can't get the branch with the PHOS EMC clusters !");
160 emcbranch->SetAddress(&fgEMCRecPoints);
161 emcbranch->GetEntry(0);
163 //#########Calculate trigger and set trigger info###########
166 // tr.SetPatchSize(1);//create 4x4 patches
167 tr.SetSimulation(kFALSE);
168 tr.Trigger(fgDigitsArray);
170 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
171 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
172 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
173 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
175 Int_t iSM2x2 = tr.Get2x2SuperModule();
176 Int_t iSMnxn = tr.GetnxnSuperModule();
177 Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
178 Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
179 Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
180 Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
182 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",
183 maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
184 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",
185 maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
187 // Attention! PHOS modules in order to calculate AbsId need to be 1-5 not 0-4 as returns trigger.
188 Int_t iRelId2x2 []= {iSM2x2+1,0,iCrystalPhi2x2,iCrystalEta2x2};
190 Int_t iRelIdnxn []= {iSMnxn+1,0,iCrystalPhinxn,iCrystalEtanxn};
192 TVector3 pos2x2(-1,-1,-1);
193 TVector3 posnxn(-1,-1,-1);
194 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
195 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
196 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
197 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
199 TArrayF triggerPosition(6);
200 triggerPosition[0] = pos2x2(0) ;
201 triggerPosition[1] = pos2x2(1) ;
202 triggerPosition[2] = pos2x2(2) ;
203 triggerPosition[3] = posnxn(0) ;
204 triggerPosition[4] = posnxn(1) ;
205 triggerPosition[5] = posnxn(2) ;
207 TArrayF triggerAmplitudes(4);
208 triggerAmplitudes[0] = maxAmp2x2 ;
209 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
210 triggerAmplitudes[2] = maxAmpnxn ;
211 triggerAmplitudes[3] = ampOutOfPatchnxn ;
213 //esd->SetPHOSTriggerCells(triggerPosition);
214 esd->AddPHOSTriggerPosition(triggerPosition);
215 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
218 //########################################
219 //############# Fill CaloCells ###########
220 //########################################
222 Int_t nDigits = fgDigitsArray->GetEntries();
224 AliDebug(1,Form("%d digits",nDigits));
226 const Int_t knEMC = fGeom->GetNModules()*fGeom->GetNPhi()*fGeom->GetNZ();
227 AliESDCaloCells &phsCells = *(esd->GetPHOSCells());
228 phsCells.CreateContainer(nDigits);
229 phsCells.SetType(AliESDCaloCells::kPHOSCell);
231 // Add to CaloCells only EMC digits with non-zero energy
232 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
233 const AliPHOSDigit * dig = (const AliPHOSDigit*)fgDigitsArray->At(idig);
234 if(dig->GetId() <= knEMC &&
235 Calibrate(dig->GetEnergy(),dig->GetId()) > GetRecoParam()->GetEMCMinE() ){
236 phsCells.SetCell(idignew,dig->GetId(), Calibrate(dig->GetEnergy(),dig->GetId()), dig->GetTime());
240 phsCells.SetNumberOfCells(idignew);
243 //########################################
244 //############## Fill CaloClusters #######
245 //########################################
247 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
248 AliPHOSRecParticle *rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
251 // Get track segment and EMC rec.point associated with this rec.particle
252 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(fTSM->GetTrackSegments()
253 ->At(rp->GetPHOSTSIndex()));
255 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(fgEMCRecPoints->At(ts->GetEmcIndex()));
256 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
259 for (Int_t ixyz=0; ixyz<3; ixyz++)
260 xyz[ixyz] = rp->GetPos()[ixyz];
262 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
266 Int_t cellMult = emcRP->GetDigitsMultiplicity();
267 Int_t *digitsList = emcRP->GetDigitsList();
268 Float_t *rpElist = emcRP->GetEnergiesList() ;
269 UShort_t *absIdList = new UShort_t[cellMult];
270 Double_t *fracList = new Double_t[cellMult];
272 for (Int_t iCell=0; iCell<cellMult; iCell++) {
273 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(fgDigitsArray->At(digitsList[iCell]));
274 absIdList[iCell] = (UShort_t)(digit->GetId());
275 if (digit->GetEnergy() > 0)
276 fracList[iCell] = rpElist[iCell]/(Calibrate(digit->GetEnergy(),digit->GetId()));
283 Int_t *primList = emcRP->GetPrimaries(primMult);
286 if (GetRecoParam()->EMCEcore2ESD())
287 energy = emcRP->GetCoreEnergy();
289 energy = rp->Energy();
291 // fills the ESDCaloCluster
292 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
293 ec->SetPosition(xyz); //rec.point position in MARS
294 ec->SetE(energy); //total or core particle energy
295 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
296 ec->SetPid(rp->GetPID()) ; //array of particle identification
297 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
298 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
299 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
300 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
301 ec->SetClusterChi2(-1); //not yet implemented
302 ec->SetTOF(emcRP->GetTime()); //Time of flight
304 //Cells contributing to clusters
305 ec->SetNCells(cellMult);
306 ec->SetCellsAbsId(absIdList);
307 ec->SetCellsAmplitudeFraction(fracList);
309 //Distance to the nearest bad crystal
310 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
312 //Array of MC indeces
313 TArrayI arrayPrim(primMult,primList);
314 ec->AddLabels(arrayPrim);
317 TArrayI arrayTrackMatched(1);
318 arrayTrackMatched[0]= ts->GetTrackIndex();
319 ec->AddTracksMatched(arrayTrackMatched);
321 esd->AddCaloCluster(ec);
326 fgDigitsArray ->Delete();
327 fgEMCRecPoints->Delete();
328 recParticles ->Delete();
331 //____________________________________________________________________________
332 AliTracker* AliPHOSReconstructor::CreateTracker() const
334 // creates the PHOS tracker
335 return new AliPHOSTracker();
338 //____________________________________________________________________________
339 void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
341 // Converts raw data to
343 // Works on a single-event basis
346 AliPHOSRawFitterv0 * fitter ;
348 const TObjArray* maps = AliPHOSRecoParam::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(GetRecoParam()->EMCFitterVersion(),"v1")==0)
357 fitter=new AliPHOSRawFitterv1();
358 else if (strcmp(GetRecoParam()->EMCFitterVersion(),"v2")==0)
359 fitter=new AliPHOSRawFitterv2();
361 fitter=new AliPHOSRawFitterv0();
363 fitter->SubtractPedestals(GetRecoParam()->EMCSubtractPedestals());
364 fitter->SetAmpOffset (GetRecoParam()->GetGlobalAltroOffset());
365 fitter->SetAmpThreshold (GetRecoParam()->GetGlobalAltroThreshold());
367 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
368 digits->SetName("DIGITS");
369 Int_t bufsize = 32000;
370 digitsTree->Branch("PHOS", &digits, bufsize);
372 AliPHOSRawDigiProducer rdp(rawReader,mapping);
374 rdp.SetEmcMinAmp(GetRecoParam()->GetEMCRawDigitThreshold()); // in ADC
375 rdp.SetCpvMinAmp(GetRecoParam()->GetCPVMinE());
376 rdp.SetSampleQualityCut(GetRecoParam()->GetEMCSampleQualityCut());
377 rdp.MakeDigits(digits,fitter);
381 if (AliLog::GetGlobalDebugLevel() == 1) {
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));
408 //==================================================================================
409 Float_t AliPHOSReconstructor::Calibrate(Float_t amp, Int_t absId)const{
410 // Calibrate EMC digit, i.e. multiply its Amp by a factor read from CDB
412 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
414 //Determine rel.position of the cell absolute ID
416 geom->AbsToRelNumbering(absId,relId);
417 Int_t module=relId[0];
419 Int_t column=relId[3];
421 Float_t calibration = fgCalibData->GetADCchannelCpv(module,column,row);
422 return amp*calibration ;
425 Float_t calibration = fgCalibData->GetADCchannelEmc(module,column,row);
426 return amp*calibration ;