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 "AliESDEvent.h"
31 #include "AliESDCaloCluster.h"
32 #include "AliPHOSReconstructor.h"
33 #include "AliPHOSClusterizerv1.h"
34 #include "AliPHOSTrackSegmentMakerv1.h"
35 #include "AliPHOSPIDv1.h"
36 #include "AliPHOSTracker.h"
37 #include "AliRawReader.h"
38 #include "AliPHOSTrigger.h"
39 #include "AliPHOSGeometry.h"
40 #include "AliPHOSRecoParam.h"
41 #include "AliPHOSRecoParamEmc.h"
42 #include "AliPHOSRecoParamCpv.h"
43 #include "AliPHOSDigit.h"
44 #include "AliPHOSTrackSegment.h"
45 #include "AliPHOSEmcRecPoint.h"
46 #include "AliPHOSRecParticle.h"
47 #include "AliPHOSRawDecoder.h"
48 #include "AliPHOSRawDecoderv1.h"
49 #include "AliPHOSRawDigiProducer.h"
50 #include "AliPHOSPulseGenerator.h"
52 ClassImp(AliPHOSReconstructor)
54 Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
55 AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamEmc =0; // EMC rec. parameters
56 AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamCpv =0; // CPV rec. parameters
58 //____________________________________________________________________________
59 AliPHOSReconstructor::AliPHOSReconstructor() :
64 if (!fgkRecoParamEmc) {
65 AliWarning("The Reconstruction parameters for EMC nonitialized - Used default one");
66 fgkRecoParamEmc = AliPHOSRecoParamEmc::GetEmcDefaultParameters();
69 if (!fgkRecoParamCpv) {
70 AliWarning("The Reconstruction parameters for CPV nonitialized - Used default one");
71 fgkRecoParamCpv = AliPHOSRecoParamCpv::GetCpvDefaultParameters();
74 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
77 //____________________________________________________________________________
78 AliPHOSReconstructor::~AliPHOSReconstructor()
84 //____________________________________________________________________________
85 void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
87 // 'single-event' local reco method called by AliReconstruction;
88 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
89 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
90 // the global tracking.
92 AliPHOSClusterizerv1 clu(fGeom);
93 clu.SetInput(digitsTree);
94 clu.SetOutput(clustersTree);
96 clu.Digits2Clusters("deb all") ;
98 clu.Digits2Clusters("") ;
101 //____________________________________________________________________________
102 void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
103 AliESDEvent* esd) const
105 // This method produces PHOS rec-particles,
106 // then it creates AliESDtracks out of them and
107 // write tracks to the ESD
109 AliPHOSTrackSegmentMaker *tsm = new AliPHOSTrackSegmentMakerv1(fGeom);
110 AliPHOSPID *pid = new AliPHOSPIDv1 (fGeom);
112 // do current event; the loop over events is done by AliReconstruction::Run()
114 tsm->SetInput(clustersTree);
116 tsm->Clusters2TrackSegments("deb all") ;
118 tsm->Clusters2TrackSegments("") ;
120 pid->SetInput(clustersTree, tsm->GetTrackSegments()) ;
123 pid->TrackSegments2RecParticles("deb all") ;
125 pid->TrackSegments2RecParticles("") ;
128 // This function creates AliESDtracks from AliPHOSRecParticles
130 // writes them to the ESD
132 TClonesArray *recParticles = pid->GetRecParticles();
133 Int_t nOfRecParticles = recParticles->GetEntries();
135 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
136 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
138 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
140 //#########Calculate trigger and set trigger info###########
143 // tr.SetPatchSize(1);//create 4x4 patches
146 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
147 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
148 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
149 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
151 Int_t iSM2x2 = tr.Get2x2SuperModule();
152 Int_t iSMnxn = tr.GetnxnSuperModule();
153 Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
154 Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
155 Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
156 Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
158 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
159 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
161 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.
163 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.
165 TVector3 pos2x2(-1,-1,-1);
166 TVector3 posnxn(-1,-1,-1);
167 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
168 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
169 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
170 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
172 TArrayF triggerPosition(6);
173 triggerPosition[0] = pos2x2(0) ;
174 triggerPosition[1] = pos2x2(1) ;
175 triggerPosition[2] = pos2x2(2) ;
176 triggerPosition[3] = posnxn(0) ;
177 triggerPosition[4] = posnxn(1) ;
178 triggerPosition[5] = posnxn(2) ;
180 TArrayF triggerAmplitudes(4);
181 triggerAmplitudes[0] = maxAmp2x2 ;
182 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
183 triggerAmplitudes[2] = maxAmpnxn ;
184 triggerAmplitudes[3] = ampOutOfPatchnxn ;
186 //esd->SetPHOSTriggerCells(triggerPosition);
187 esd->AddPHOSTriggerPosition(triggerPosition);
188 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
190 //######################################
193 TBranch *branch = digitsTree->GetBranch("PHOS");
195 AliError("can't get the branch with the PHOS digits !");
198 TClonesArray *fDigitsArr = new TClonesArray("AliPHOSDigit",100);
199 branch->SetAddress(&fDigitsArr);
202 // Get the clusters array
203 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
205 AliError("can't get the branch with the PHOS EMC clusters !");
209 TObjArray *fEmcRecPoints = new TObjArray(100) ;
210 emcbranch->SetAddress(&fEmcRecPoints);
211 emcbranch->GetEntry(0);
214 const Float_t kBigShort = std::numeric_limits<short int>::max() - 1;
215 const Float_t nsec100 = 1e9*100.; // units of 0.01 ns
216 const Float_t gev500 = 500.; // units of GeV/500
218 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
219 AliPHOSRecParticle * rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
222 // Get track segment and EMC rec.point associated with this rec.particle
223 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(tsm->GetTrackSegments()->At(rp->GetPHOSTSIndex()));
225 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(fEmcRecPoints->At(ts->GetEmcIndex()));
226 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
229 for (Int_t ixyz=0; ixyz<3; ixyz++)
230 xyz[ixyz] = rp->GetPos()[ixyz];
232 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
234 //Create digits lists
235 Int_t digitMult = emcRP->GetDigitsMultiplicity();
236 Int_t *digitsList = emcRP->GetDigitsList();
237 Float_t *rpElist = emcRP->GetEnergiesList() ;
238 Short_t *amplList = new Short_t[digitMult];
239 Short_t *timeList = new Short_t[digitMult];
240 Short_t *digiList = new Short_t[digitMult];
243 // Convert Float_t* and Int_t* to Short_t* to save memory
244 for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
246 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(fDigitsArr->At(digitsList[iDigit]));
248 (Short_t)(TMath::Min(rpElist[iDigit]*gev500,kBigShort)); // Energy in units of GeV/500
249 // We should add here not full energy of digit, but unfolded one, stored in RecPoint
250 // amplList[iDigit] =
251 // (Short_t)(TMath::Min(digit->GetEnergy()*gev500,kBigShort)); // Energy in units of GeV/500
253 (Short_t)(TMath::Max(-kBigShort,TMath::Min(digit->GetTime()*nsec100,kBigShort))); // time in units of 0.01 ns
254 digiList[iDigit] = (Short_t)(digit->GetId());
261 Int_t *primInts = emcRP->GetPrimaries(primMult);
262 Short_t *primList = new Short_t[primMult];
263 for (Int_t ipr=0; ipr<primMult; ipr++)
264 primList[ipr] = (Short_t)(primInts[ipr]);
266 // fills the ESDCaloCluster
268 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
269 ec->SetPosition(xyz); //rec.point position in MARS
270 ec->SetE(rp->Energy()); //total particle energy
271 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
272 ec->SetPid(rp->GetPID()) ; //array of particle identification
273 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
274 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
275 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
276 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
277 ec->SetClusterChi2(-1); //not yet implemented
278 ec->SetM11(-1) ; //not yet implemented
281 TArrayS arrayAmpList(digitMult,amplList);
282 TArrayS arrayTimeList(digitMult,timeList);
283 TArrayS arrayIndexList(digitMult,digiList);
284 ec->AddDigitAmplitude(arrayAmpList);
285 ec->AddDigitTime(arrayTimeList);
286 ec->AddDigitIndex(arrayIndexList);
288 //Distance to the nearest bad crystal
289 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
291 //Array of MC indeces
292 TArrayS arrayPrim(primMult,primList);
293 ec->AddLabels(arrayPrim);
295 //Array of tracks uncomment when available in future
296 //TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
297 //arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
298 //ec->AddTracksMatched(arrayTrackMatched);
300 // add the track to the esd object
301 esd->AddCaloCluster(ec);
308 fDigitsArr ->Delete();
310 fEmcRecPoints->Delete();
311 delete fEmcRecPoints;
316 //____________________________________________________________________________
317 AliTracker* AliPHOSReconstructor::CreateTracker() const
319 // creates the PHOS tracker
320 return new AliPHOSTracker();
323 //____________________________________________________________________________
324 void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
326 // Converts raw data to
328 // Works on a single-event basis
332 AliPHOSRawDecoder * dc ;
334 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0)
335 dc=new AliPHOSRawDecoderv1(rawReader);
337 dc=new AliPHOSRawDecoder(rawReader);
339 TString option = GetOption();
340 if (option.Contains("OldRCUFormat"))
341 dc->SetOldRCUFormat(kTRUE);
343 dc->SetOldRCUFormat(kFALSE);
345 dc->SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
347 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
348 digits->SetName("DIGITS");
349 Int_t bufsize = 32000;
350 digitsTree->Branch("PHOS", &digits, bufsize);
352 AliPHOSRawDigiProducer pr;
353 pr.MakeDigits(digits,dc);
358 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0){ //"Energy" calculated as fit
359 for(Int_t i=0; i<digits->GetEntries(); i++) {
360 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
361 digit->SetEnergy(digit->GetEnergy()*0.005); //We assume here 5 MeV/ADC channel
362 digit->SetTime(digit->GetTime()*1.e-7) ; //Here we assume sample step==100 ns TO BE FIXED!!!!!!!!!!!!!
365 else{ //Digits energy calculated as maximal energy
366 for(Int_t i=0; i<digits->GetEntries(); i++) {
367 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
368 digit->SetEnergy(digit->GetEnergy()/AliPHOSPulseGenerator::GeV2ADC());
372 // Clean up digits below the noise threshold
373 // Assuming the digit noise to be 4 MeV, we suppress digits within
374 // 3-sigma of the noise.
375 // This parameter should be passed via AliPHOSRecoParamEmc later
377 const Double_t emcDigitThreshold = 0.012;
378 for(Int_t i=0; i<digits->GetEntries(); i++) {
379 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
380 if(digit->GetEnergy() < emcDigitThreshold)
381 digits->RemoveAt(i) ;
393 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
394 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
395 if(digit->GetEnergy()>eMax) {
396 fGeom->AbsToRelNumbering(digit->GetId(),relId);
397 eMax=digit->GetEnergy();
404 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
405 modMax,colMax,rowMax,eMax));