]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSReconstructor.cxx
Fixed index (Adam)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSReconstructor.cxx
CommitLineData
d15a28e7 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
a3dfe79c 19//*--
dfe0be07 20//*-- Yves Schutz (SUBATECH)
21// Reconstruction class. Redesigned from the old AliReconstructionner class and
22// derived from STEER/AliReconstructor.
23//
d15a28e7 24// --- ROOT system ---
25
d15a28e7 26// --- Standard library ---
364de5c6 27
d15a28e7 28// --- AliRoot header files ---
9a2cdbdf 29#include "AliLog.h"
af885e0f 30#include "AliESDEvent.h"
33ba95c3 31#include "AliESDCaloCluster.h"
f444a19f 32#include "AliPHOSReconstructor.h"
7acf6008 33#include "AliPHOSClusterizerv1.h"
7acf6008 34#include "AliPHOSTrackSegmentMakerv1.h"
35#include "AliPHOSPIDv1.h"
23904d16 36#include "AliPHOSTracker.h"
d22dd3b4 37#include "AliRawReader.h"
64df000d 38#include "AliPHOSTrigger.h"
39#include "AliPHOSGeometry.h"
86121c91 40#include "AliPHOSRecoParam.h"
3799bcb5 41#include "AliPHOSRecoParamEmc.h"
42#include "AliPHOSRecoParamCpv.h"
9a2cdbdf 43#include "AliPHOSDigit.h"
44#include "AliPHOSTrackSegment.h"
45#include "AliPHOSEmcRecPoint.h"
46#include "AliPHOSRecParticle.h"
47#include "AliPHOSRawDecoder.h"
48#include "AliPHOSRawDigiProducer.h"
49#include "AliPHOSPulseGenerator.h"
e957fea8 50
f444a19f 51ClassImp(AliPHOSReconstructor)
d15a28e7 52
2e60107f 53Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
3799bcb5 54AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamEmc =0; // EMC rec. parameters
55AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamCpv =0; // CPV rec. parameters
2e60107f 56
d15a28e7 57//____________________________________________________________________________
9a2cdbdf 58AliPHOSReconstructor::AliPHOSReconstructor() :
59 fGeom(NULL)
d15a28e7 60{
b2a60966 61 // ctor
0379a13e 62
3799bcb5 63 if (!fgkRecoParamEmc) {
64 AliWarning("The Reconstruction parameters for EMC nonitialized - Used default one");
65 fgkRecoParamEmc = AliPHOSRecoParamEmc::GetEmcDefaultParameters();
66 }
67
68 if (!fgkRecoParamCpv) {
69 AliWarning("The Reconstruction parameters for CPV nonitialized - Used default one");
70 fgkRecoParamCpv = AliPHOSRecoParamCpv::GetCpvDefaultParameters();
71 }
72
9a2cdbdf 73 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
6ad0bfa0 74}
75
0379a13e 76//____________________________________________________________________________
77 AliPHOSReconstructor::~AliPHOSReconstructor()
78{
79 // dtor
9a2cdbdf 80 delete fGeom;
0379a13e 81}
7acf6008 82
7acf6008 83//____________________________________________________________________________
9a2cdbdf 84void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
35293055 85{
9a2cdbdf 86 // 'single-event' local reco method called by AliReconstruction;
dfe0be07 87 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
af885e0f 88 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
dfe0be07 89 // the global tracking.
9a2cdbdf 90
91 AliPHOSClusterizerv1 clu(fGeom);
92 clu.SetInput(digitsTree);
93 clu.SetOutput(clustersTree);
a68156e6 94 if ( Debug() )
9a2cdbdf 95 clu.Digits2Clusters("deb all") ;
a68156e6 96 else
9a2cdbdf 97 clu.Digits2Clusters("") ;
a68156e6 98}
99
100//____________________________________________________________________________
9a2cdbdf 101void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
102 AliESDEvent* esd) const
a68156e6 103{
9a2cdbdf 104 // This method produces PHOS rec-particles,
105 // then it creates AliESDtracks out of them and
106 // write tracks to the ESD
107
108 AliPHOSTrackSegmentMaker *tsm = new AliPHOSTrackSegmentMakerv1(fGeom);
9a2cdbdf 109 AliPHOSPID *pid = new AliPHOSPIDv1(fGeom);
d76c31f4 110
9a2cdbdf 111 // do current event; the loop over events is done by AliReconstruction::Run()
112 tsm->SetESD(esd) ;
113 tsm->SetInput(clustersTree);
114 if ( Debug() )
115 tsm->Clusters2TrackSegments("deb all") ;
116 else
117 tsm->Clusters2TrackSegments("") ;
35293055 118
9a2cdbdf 119 pid->SetInput(clustersTree, tsm->GetTrackSegments()) ;
120 pid->SetESD(esd) ;
dfe0be07 121 if ( Debug() )
9a2cdbdf 122 pid->TrackSegments2RecParticles("deb all") ;
dfe0be07 123 else
9a2cdbdf 124 pid->TrackSegments2RecParticles("") ;
7acf6008 125
9a2cdbdf 126
23904d16 127 // This function creates AliESDtracks from AliPHOSRecParticles
128 // and
129 // writes them to the ESD
bf72996e 130
9a2cdbdf 131 TClonesArray *recParticles = pid->GetRecParticles();
dfe0be07 132 Int_t nOfRecParticles = recParticles->GetEntries();
a5fa6165 133
134
85c60a8e 135 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
dd7ee508 136 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
a5fa6165 137
9a2cdbdf 138 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
8013c27e 139
64df000d 140
141 //#########Calculate trigger and set trigger info###########
142
143 AliPHOSTrigger tr ;
144 // tr.SetPatchSize(1);//create 4x4 patches
145 tr.Trigger();
146
147 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
148 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
149 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
150 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
151
64df000d 152 Int_t iSM2x2 = tr.Get2x2SuperModule();
153 Int_t iSMnxn = tr.GetnxnSuperModule();
154 Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
155 Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
156 Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
157 Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
158
159 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
160 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
161
24b8fcca 162 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.
64df000d 163 Int_t iAbsId2x2 =-1;
24b8fcca 164 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.
64df000d 165 Int_t iAbsIdnxn =-1;
166 TVector3 pos2x2(-1,-1,-1);
167 TVector3 posnxn(-1,-1,-1);
9a2cdbdf 168 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
169 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
170 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
171 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
64df000d 172
173 TArrayF triggerPosition(6);
174 triggerPosition[0] = pos2x2(0) ;
175 triggerPosition[1] = pos2x2(1) ;
176 triggerPosition[2] = pos2x2(2) ;
177 triggerPosition[3] = posnxn(0) ;
178 triggerPosition[4] = posnxn(1) ;
179 triggerPosition[5] = posnxn(2) ;
180
181 TArrayF triggerAmplitudes(4);
182 triggerAmplitudes[0] = maxAmp2x2 ;
183 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
184 triggerAmplitudes[2] = maxAmpnxn ;
185 triggerAmplitudes[3] = ampOutOfPatchnxn ;
186
187 //esd->SetPHOSTriggerCells(triggerPosition);
188 esd->AddPHOSTriggerPosition(triggerPosition);
189 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
190
191 //######################################
7592dfc4 192
64df000d 193 //Fill CaloClusters
f4e0dd30 194 const Float_t kBigShort = std::numeric_limits<short int>::max() - 1;
195 const Float_t nsec100 = 1e9*100.; // units of 0.01 ns
196 const Float_t gev500 = 500.; // units of GeV/500
197
dfe0be07 198 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
199 AliPHOSRecParticle * rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
200 if (Debug())
201 rp->Print();
25ed816e 202 // Get track segment and EMC rec.point associated with this rec.particle
9a2cdbdf 203 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(tsm->GetTrackSegments()->At(rp->GetPHOSTSIndex()));
204
205 // Get the clusters array
206 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
207 if (!emcbranch) {
208 AliError("can't get the branch with the PHOS EMC clusters !");
209 return;
210 }
211 TObjArray *emcRecPoints = new TObjArray(100) ;
212 emcbranch->SetAddress(&emcRecPoints);
213 emcbranch->GetEntry(0);
214
215 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(ts->GetEmcIndex()));
25ed816e 216 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
7592dfc4 217
85c60a8e 218 Float_t xyz[3];
8013c27e 219 for (Int_t ixyz=0; ixyz<3; ixyz++)
220 xyz[ixyz] = rp->GetPos()[ixyz];
dd7ee508 221
222 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
223
7592dfc4 224 //Create digits lists
25ed816e 225 Int_t digitMult = emcRP->GetDigitsMultiplicity();
226 Int_t *digitsList = emcRP->GetDigitsList();
7592dfc4 227 Short_t *amplList = new Short_t[digitMult];
228 Short_t *timeList = new Short_t[digitMult];
229 Short_t *digiList = new Short_t[digitMult];
25ed816e 230
9a2cdbdf 231 // Read digits array
232 TBranch *branch = digitsTree->GetBranch("PHOS");
233 if (!branch) {
234 AliError("can't get the branch with the PHOS digits !");
235 return;
236 }
237 TClonesArray *digitsArr = new TClonesArray("AliPHOSDigit",100);
238 branch->SetAddress(&digitsArr);
239 branch->GetEntry(0);
240
7592dfc4 241 // Convert Float_t* and Int_t* to Short_t* to save memory
25ed816e 242 for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
9a2cdbdf 243 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(digitsArr->At(digitsList[iDigit]));
f4e0dd30 244 amplList[iDigit] =
245 (Short_t)(TMath::Min(digit->GetEnergy()*gev500,kBigShort)); // Energy in units of GeV/500
246 timeList[iDigit] =
247 (Short_t)(TMath::Min(digit->GetTime()*nsec100,kBigShort)); // time in units of 0.01 ns
7592dfc4 248 digiList[iDigit] = (Short_t)(digit->GetId());
25ed816e 249 }
7592dfc4 250
251 //Primaries
252 Int_t primMult = 0;
253 Int_t *primInts = emcRP->GetPrimaries(primMult);
254 Short_t *primList = new Short_t[primMult];
255 for (Int_t ipr=0; ipr<primMult; ipr++)
256 primList[ipr] = (Short_t)(primInts[ipr]);
257
258 // fills the ESDCaloCluster
259
34541ea2 260 ec->SetPHOS(kTRUE);
7592dfc4 261 ec->SetPosition(xyz); //rec.point position in MARS
262 ec->SetE(rp->Energy()); //total particle energy
25ed816e 263 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
264 ec->SetPid (rp->GetPID()) ; //array of particle identification
25ed816e 265 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
266 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
267 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
25ed816e 268 ec->SetEmcCpvDistance(-1); //not yet implemented
269 ec->SetClusterChi2(-1); //not yet implemented
270 ec->SetM11(-1) ; //not yet implemented
3744a6cf 271
7592dfc4 272 //Digits Lists
273 TArrayS arrayAmpList(digitMult,amplList);
274 TArrayS arrayTimeList(digitMult,timeList);
275 TArrayS arrayIndexList(digitMult,digiList);
276 ec->AddDigitAmplitude(arrayAmpList);
277 ec->AddDigitTime(arrayTimeList);
278 ec->AddDigitIndex(arrayIndexList);
279
3744a6cf 280 //Distance to the nearest bad crystal
281 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
7592dfc4 282
283 //Array of MC indeces
284 TArrayS arrayPrim(primMult,primList);
285 ec->AddLabels(arrayPrim);
286
287 //Array of tracks uncomment when available in future
288 //TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
289 //arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
290 //ec->AddTracksMatched(arrayTrackMatched);
64df000d 291
dfe0be07 292 // add the track to the esd object
85c60a8e 293 esd->AddCaloCluster(ec);
9a2cdbdf 294 delete ec;
295 delete [] primList;
296 delete [] amplList;
297 delete [] timeList;
298 delete [] digiList;
dd7ee508 299 }
300}
301
d76c31f4 302AliTracker* AliPHOSReconstructor::CreateTracker() const
dd7ee508 303{
9a2cdbdf 304 // creates the PHOS tracker
305 return new AliPHOSTracker();
306}
dd7ee508 307
9a2cdbdf 308void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
309{
310 // Converts raw data to
311 // PHOS digits
312 // Works on a single-event basis
dd7ee508 313
9a2cdbdf 314 rawReader->Reset() ;
dd7ee508 315
9a2cdbdf 316 AliPHOSRawDecoder dc(rawReader);
317 TString option = GetOption();
318 if (option.Contains("OldRCUFormat"))
319 dc.SetOldRCUFormat(kTRUE);
320 else
321 dc.SetOldRCUFormat(kFALSE);
86121c91 322
323 dc.SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
324
9a2cdbdf 325 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
326 digits->SetName("DIGITS");
327 Int_t bufsize = 32000;
328 digitsTree->Branch("PHOS", &digits, bufsize);
dd7ee508 329
9a2cdbdf 330 AliPHOSRawDigiProducer pr;
331 pr.MakeDigits(digits,&dc);
7592dfc4 332
9a2cdbdf 333 //ADC counts -> GeV
334 for(Int_t i=0; i<digits->GetEntries(); i++) {
335 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
336 digit->SetEnergy(digit->GetEnergy()/AliPHOSPulseGenerator::GeV2ADC());
337 }
338
339 //!!!!for debug!!!
340 Int_t modMax=-111;
341 Int_t colMax=-111;
342 Int_t rowMax=-111;
343 Float_t eMax=-333;
344 //!!!for debug!!!
345
346 Int_t relId[4];
347 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
348 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
349 if(digit->GetEnergy()>eMax) {
350 fGeom->AbsToRelNumbering(digit->GetId(),relId);
351 eMax=digit->GetEnergy();
352 modMax=relId[0];
353 rowMax=relId[2];
354 colMax=relId[3];
dd7ee508 355 }
356 }
357
9a2cdbdf 358 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
359 modMax,colMax,rowMax,eMax));
dd7ee508 360
9a2cdbdf 361 digitsTree->Fill();
d7d3b67b 362}