]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSReconstructor.cxx
ALTRO mappings gets from OCDB.
[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"
b3006690 30#include "AliAltroMapping.h"
af885e0f 31#include "AliESDEvent.h"
33ba95c3 32#include "AliESDCaloCluster.h"
f444a19f 33#include "AliPHOSReconstructor.h"
7acf6008 34#include "AliPHOSClusterizerv1.h"
7acf6008 35#include "AliPHOSTrackSegmentMakerv1.h"
36#include "AliPHOSPIDv1.h"
23904d16 37#include "AliPHOSTracker.h"
d22dd3b4 38#include "AliRawReader.h"
64df000d 39#include "AliPHOSTrigger.h"
40#include "AliPHOSGeometry.h"
86121c91 41#include "AliPHOSRecoParam.h"
3799bcb5 42#include "AliPHOSRecoParamEmc.h"
43#include "AliPHOSRecoParamCpv.h"
9a2cdbdf 44#include "AliPHOSDigit.h"
45#include "AliPHOSTrackSegment.h"
46#include "AliPHOSEmcRecPoint.h"
47#include "AliPHOSRecParticle.h"
48#include "AliPHOSRawDecoder.h"
77ea1c6f 49#include "AliPHOSRawDecoderv1.h"
9a2cdbdf 50#include "AliPHOSRawDigiProducer.h"
51#include "AliPHOSPulseGenerator.h"
e957fea8 52
f444a19f 53ClassImp(AliPHOSReconstructor)
d15a28e7 54
2e60107f 55Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
3799bcb5 56AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamEmc =0; // EMC rec. parameters
57AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamCpv =0; // CPV rec. parameters
2e60107f 58
d15a28e7 59//____________________________________________________________________________
9a2cdbdf 60AliPHOSReconstructor::AliPHOSReconstructor() :
61 fGeom(NULL)
d15a28e7 62{
b2a60966 63 // ctor
0379a13e 64
3799bcb5 65 if (!fgkRecoParamEmc) {
66 AliWarning("The Reconstruction parameters for EMC nonitialized - Used default one");
67 fgkRecoParamEmc = AliPHOSRecoParamEmc::GetEmcDefaultParameters();
68 }
69
70 if (!fgkRecoParamCpv) {
71 AliWarning("The Reconstruction parameters for CPV nonitialized - Used default one");
72 fgkRecoParamCpv = AliPHOSRecoParamCpv::GetCpvDefaultParameters();
73 }
74
9a2cdbdf 75 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
e68222ce 76}
6ad0bfa0 77
0379a13e 78//____________________________________________________________________________
79 AliPHOSReconstructor::~AliPHOSReconstructor()
80{
81 // dtor
9a2cdbdf 82 delete fGeom;
0379a13e 83}
7acf6008 84
7acf6008 85//____________________________________________________________________________
9a2cdbdf 86void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
35293055 87{
9a2cdbdf 88 // 'single-event' local reco method called by AliReconstruction;
dfe0be07 89 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
af885e0f 90 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
dfe0be07 91 // the global tracking.
9a2cdbdf 92
93 AliPHOSClusterizerv1 clu(fGeom);
94 clu.SetInput(digitsTree);
95 clu.SetOutput(clustersTree);
a68156e6 96 if ( Debug() )
9a2cdbdf 97 clu.Digits2Clusters("deb all") ;
a68156e6 98 else
9a2cdbdf 99 clu.Digits2Clusters("") ;
a68156e6 100}
101
102//____________________________________________________________________________
9a2cdbdf 103void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
104 AliESDEvent* esd) const
a68156e6 105{
9a2cdbdf 106 // This method produces PHOS rec-particles,
107 // then it creates AliESDtracks out of them and
108 // write tracks to the ESD
109
110 AliPHOSTrackSegmentMaker *tsm = new AliPHOSTrackSegmentMakerv1(fGeom);
e68222ce 111 AliPHOSPID *pid = new AliPHOSPIDv1 (fGeom);
112
9a2cdbdf 113 // do current event; the loop over events is done by AliReconstruction::Run()
114 tsm->SetESD(esd) ;
115 tsm->SetInput(clustersTree);
116 if ( Debug() )
117 tsm->Clusters2TrackSegments("deb all") ;
118 else
119 tsm->Clusters2TrackSegments("") ;
35293055 120
9a2cdbdf 121 pid->SetInput(clustersTree, tsm->GetTrackSegments()) ;
122 pid->SetESD(esd) ;
dfe0be07 123 if ( Debug() )
9a2cdbdf 124 pid->TrackSegments2RecParticles("deb all") ;
dfe0be07 125 else
9a2cdbdf 126 pid->TrackSegments2RecParticles("") ;
7acf6008 127
77ea1c6f 128
23904d16 129 // This function creates AliESDtracks from AliPHOSRecParticles
130 // and
131 // writes them to the ESD
bf72996e 132
9a2cdbdf 133 TClonesArray *recParticles = pid->GetRecParticles();
dfe0be07 134 Int_t nOfRecParticles = recParticles->GetEntries();
a5fa6165 135
85c60a8e 136 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
dd7ee508 137 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
a5fa6165 138
9a2cdbdf 139 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
8013c27e 140
64df000d 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
e68222ce 193 // Read digits array
194 TBranch *branch = digitsTree->GetBranch("PHOS");
195 if (!branch) {
196 AliError("can't get the branch with the PHOS digits !");
197 return;
198 }
199 TClonesArray *fDigitsArr = new TClonesArray("AliPHOSDigit",100);
200 branch->SetAddress(&fDigitsArr);
201 branch->GetEntry(0);
202
203 // Get the clusters array
204 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
205 if (!emcbranch) {
206 AliError("can't get the branch with the PHOS EMC clusters !");
207 return;
208 }
209
210 TObjArray *fEmcRecPoints = new TObjArray(100) ;
211 emcbranch->SetAddress(&fEmcRecPoints);
212 emcbranch->GetEntry(0);
213
64df000d 214 //Fill CaloClusters
f4e0dd30 215 const Float_t kBigShort = std::numeric_limits<short int>::max() - 1;
216 const Float_t nsec100 = 1e9*100.; // units of 0.01 ns
217 const Float_t gev500 = 500.; // units of GeV/500
218
dfe0be07 219 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
220 AliPHOSRecParticle * rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
221 if (Debug())
222 rp->Print();
25ed816e 223 // Get track segment and EMC rec.point associated with this rec.particle
9a2cdbdf 224 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(tsm->GetTrackSegments()->At(rp->GetPHOSTSIndex()));
225
e68222ce 226 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(fEmcRecPoints->At(ts->GetEmcIndex()));
25ed816e 227 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
e68222ce 228
85c60a8e 229 Float_t xyz[3];
8013c27e 230 for (Int_t ixyz=0; ixyz<3; ixyz++)
231 xyz[ixyz] = rp->GetPos()[ixyz];
dd7ee508 232
233 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
77ea1c6f 234
7592dfc4 235 //Create digits lists
25ed816e 236 Int_t digitMult = emcRP->GetDigitsMultiplicity();
237 Int_t *digitsList = emcRP->GetDigitsList();
77ea1c6f 238 Float_t *rpElist = emcRP->GetEnergiesList() ;
7592dfc4 239 Short_t *amplList = new Short_t[digitMult];
240 Short_t *timeList = new Short_t[digitMult];
241 Short_t *digiList = new Short_t[digitMult];
25ed816e 242
77ea1c6f 243
7592dfc4 244 // Convert Float_t* and Int_t* to Short_t* to save memory
25ed816e 245 for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
77ea1c6f 246
e68222ce 247 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(fDigitsArr->At(digitsList[iDigit]));
f4e0dd30 248 amplList[iDigit] =
77ea1c6f 249 (Short_t)(TMath::Min(rpElist[iDigit]*gev500,kBigShort)); // Energy in units of GeV/500
250// We should add here not full energy of digit, but unfolded one, stored in RecPoint
251// amplList[iDigit] =
252// (Short_t)(TMath::Min(digit->GetEnergy()*gev500,kBigShort)); // Energy in units of GeV/500
253 timeList[iDigit] =
254 (Short_t)(TMath::Max(-kBigShort,TMath::Min(digit->GetTime()*nsec100,kBigShort))); // time in units of 0.01 ns
7592dfc4 255 digiList[iDigit] = (Short_t)(digit->GetId());
25ed816e 256 }
7592dfc4 257
77ea1c6f 258
259
7592dfc4 260 //Primaries
261 Int_t primMult = 0;
4dd59c4a 262 Int_t *primList = emcRP->GetPrimaries(primMult);
263
7592dfc4 264 // fills the ESDCaloCluster
265
8ada0ffe 266 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
267 ec->SetPosition(xyz); //rec.point position in MARS
268 ec->SetE(rp->Energy()); //total particle energy
25ed816e 269 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
e68222ce 270 ec->SetPid(rp->GetPID()) ; //array of particle identification
25ed816e 271 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
272 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
273 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
77ea1c6f 274 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
25ed816e 275 ec->SetClusterChi2(-1); //not yet implemented
276 ec->SetM11(-1) ; //not yet implemented
3744a6cf 277
7592dfc4 278 //Digits Lists
279 TArrayS arrayAmpList(digitMult,amplList);
280 TArrayS arrayTimeList(digitMult,timeList);
281 TArrayS arrayIndexList(digitMult,digiList);
282 ec->AddDigitAmplitude(arrayAmpList);
283 ec->AddDigitTime(arrayTimeList);
284 ec->AddDigitIndex(arrayIndexList);
285
3744a6cf 286 //Distance to the nearest bad crystal
287 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
7592dfc4 288
289 //Array of MC indeces
4dd59c4a 290 TArrayI arrayPrim(primMult,primList);
7592dfc4 291 ec->AddLabels(arrayPrim);
292
293 //Array of tracks uncomment when available in future
294 //TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
295 //arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
296 //ec->AddTracksMatched(arrayTrackMatched);
64df000d 297
dfe0be07 298 // add the track to the esd object
85c60a8e 299 esd->AddCaloCluster(ec);
9a2cdbdf 300 delete ec;
9a2cdbdf 301 delete [] amplList;
302 delete [] timeList;
303 delete [] digiList;
e68222ce 304 }
6e0b8dc1 305 fDigitsArr ->Delete();
306 delete fDigitsArr;
307 fEmcRecPoints->Delete();
308 delete fEmcRecPoints;
e68222ce 309 delete tsm;
310 delete pid;
dd7ee508 311}
312
e68222ce 313//____________________________________________________________________________
d76c31f4 314AliTracker* AliPHOSReconstructor::CreateTracker() const
dd7ee508 315{
9a2cdbdf 316 // creates the PHOS tracker
317 return new AliPHOSTracker();
318}
dd7ee508 319
1267d56d 320//____________________________________________________________________________
9a2cdbdf 321void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
322{
323 // Converts raw data to
324 // PHOS digits
325 // Works on a single-event basis
dd7ee508 326
9a2cdbdf 327 rawReader->Reset() ;
dd7ee508 328
77ea1c6f 329 AliPHOSRawDecoder * dc ;
330
b3006690 331 const TObjArray* maps = AliPHOSRecoParamEmc::GetMappings();
332 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
333
334 AliAltroMapping *mapping[4];
335 for(Int_t i = 0; i < 4; i++) {
336 mapping[i] = (AliAltroMapping*)maps->At(i);
337 }
338
77ea1c6f 339 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0)
b3006690 340 dc=new AliPHOSRawDecoderv1(rawReader,mapping);
77ea1c6f 341 else
b3006690 342 dc=new AliPHOSRawDecoder(rawReader,mapping);
77ea1c6f 343
9a2cdbdf 344 TString option = GetOption();
345 if (option.Contains("OldRCUFormat"))
77ea1c6f 346 dc->SetOldRCUFormat(kTRUE);
9a2cdbdf 347 else
77ea1c6f 348 dc->SetOldRCUFormat(kFALSE);
86121c91 349
77ea1c6f 350 dc->SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
86121c91 351
9a2cdbdf 352 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
353 digits->SetName("DIGITS");
354 Int_t bufsize = 32000;
355 digitsTree->Branch("PHOS", &digits, bufsize);
dd7ee508 356
9a2cdbdf 357 AliPHOSRawDigiProducer pr;
77ea1c6f 358 pr.MakeDigits(digits,dc);
359
360 delete dc ;
7592dfc4 361
9a2cdbdf 362 //ADC counts -> GeV
77ea1c6f 363 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0){ //"Energy" calculated as fit
364 for(Int_t i=0; i<digits->GetEntries(); i++) {
365 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
366 digit->SetEnergy(digit->GetEnergy()*0.005); //We assume here 5 MeV/ADC channel
367 digit->SetTime(digit->GetTime()*1.e-7) ; //Here we assume sample step==100 ns TO BE FIXED!!!!!!!!!!!!!
368 }
369 }
370 else{ //Digits energy calculated as maximal energy
371 for(Int_t i=0; i<digits->GetEntries(); i++) {
372 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
373 digit->SetEnergy(digit->GetEnergy()/AliPHOSPulseGenerator::GeV2ADC());
374 }
9a2cdbdf 375 }
376
1267d56d 377 // Clean up digits below the noise threshold
378 // Assuming the digit noise to be 4 MeV, we suppress digits within
379 // 3-sigma of the noise.
380 // This parameter should be passed via AliPHOSRecoParamEmc later
381
382 const Double_t emcDigitThreshold = 0.012;
383 for(Int_t i=0; i<digits->GetEntries(); i++) {
384 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
385 if(digit->GetEnergy() < emcDigitThreshold)
386 digits->RemoveAt(i) ;
387 }
388 digits->Compress() ;
389
9a2cdbdf 390 //!!!!for debug!!!
391 Int_t modMax=-111;
392 Int_t colMax=-111;
393 Int_t rowMax=-111;
394 Float_t eMax=-333;
395 //!!!for debug!!!
396
397 Int_t relId[4];
398 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
399 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
400 if(digit->GetEnergy()>eMax) {
401 fGeom->AbsToRelNumbering(digit->GetId(),relId);
402 eMax=digit->GetEnergy();
403 modMax=relId[0];
404 rowMax=relId[2];
405 colMax=relId[3];
dd7ee508 406 }
407 }
408
9a2cdbdf 409 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
410 modMax,colMax,rowMax,eMax));
dd7ee508 411
9a2cdbdf 412 digitsTree->Fill();
e68222ce 413 digits->Delete();
414 delete digits;
d7d3b67b 415}