]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSReconstructor.cxx
remove bad modules BEFORE cleaning digits
[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//_________________________________________________________________________
a5e00016 19//--
20//-- Yves Schutz (SUBATECH)
dfe0be07 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"
a5e00016 33#include "AliESDCaloCells.h"
f444a19f 34#include "AliPHOSReconstructor.h"
7acf6008 35#include "AliPHOSClusterizerv1.h"
7acf6008 36#include "AliPHOSTrackSegmentMakerv1.h"
37#include "AliPHOSPIDv1.h"
23904d16 38#include "AliPHOSTracker.h"
d22dd3b4 39#include "AliRawReader.h"
64df000d 40#include "AliPHOSTrigger.h"
41#include "AliPHOSGeometry.h"
86121c91 42#include "AliPHOSRecoParam.h"
3799bcb5 43#include "AliPHOSRecoParamEmc.h"
44#include "AliPHOSRecoParamCpv.h"
9a2cdbdf 45#include "AliPHOSDigit.h"
46#include "AliPHOSTrackSegment.h"
47#include "AliPHOSEmcRecPoint.h"
48#include "AliPHOSRecParticle.h"
49#include "AliPHOSRawDecoder.h"
77ea1c6f 50#include "AliPHOSRawDecoderv1.h"
710634f4 51#include "AliPHOSRawDecoderv2.h"
9a2cdbdf 52#include "AliPHOSRawDigiProducer.h"
53#include "AliPHOSPulseGenerator.h"
e957fea8 54
f444a19f 55ClassImp(AliPHOSReconstructor)
d15a28e7 56
2e60107f 57Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
3799bcb5 58AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamEmc =0; // EMC rec. parameters
59AliPHOSRecoParam* AliPHOSReconstructor::fgkRecoParamCpv =0; // CPV rec. parameters
2e60107f 60
d15a28e7 61//____________________________________________________________________________
9a2cdbdf 62AliPHOSReconstructor::AliPHOSReconstructor() :
63 fGeom(NULL)
d15a28e7 64{
b2a60966 65 // ctor
0379a13e 66
3799bcb5 67 if (!fgkRecoParamEmc) {
68 AliWarning("The Reconstruction parameters for EMC nonitialized - Used default one");
69 fgkRecoParamEmc = AliPHOSRecoParamEmc::GetEmcDefaultParameters();
70 }
71
72 if (!fgkRecoParamCpv) {
73 AliWarning("The Reconstruction parameters for CPV nonitialized - Used default one");
74 fgkRecoParamCpv = AliPHOSRecoParamCpv::GetCpvDefaultParameters();
75 }
76
9a2cdbdf 77 fGeom = AliPHOSGeometry::GetInstance("IHEP","");
e68222ce 78}
6ad0bfa0 79
0379a13e 80//____________________________________________________________________________
81 AliPHOSReconstructor::~AliPHOSReconstructor()
82{
83 // dtor
9a2cdbdf 84 delete fGeom;
0379a13e 85}
7acf6008 86
7acf6008 87//____________________________________________________________________________
9a2cdbdf 88void AliPHOSReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
35293055 89{
9a2cdbdf 90 // 'single-event' local reco method called by AliReconstruction;
dfe0be07 91 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
af885e0f 92 // segment maker needs access to the AliESDEvent object to retrieve the tracks reconstructed by
dfe0be07 93 // the global tracking.
9a2cdbdf 94
95 AliPHOSClusterizerv1 clu(fGeom);
96 clu.SetInput(digitsTree);
97 clu.SetOutput(clustersTree);
a68156e6 98 if ( Debug() )
9a2cdbdf 99 clu.Digits2Clusters("deb all") ;
a68156e6 100 else
9a2cdbdf 101 clu.Digits2Clusters("") ;
a68156e6 102}
103
104//____________________________________________________________________________
9a2cdbdf 105void AliPHOSReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
106 AliESDEvent* esd) const
a68156e6 107{
9a2cdbdf 108 // This method produces PHOS rec-particles,
109 // then it creates AliESDtracks out of them and
110 // write tracks to the ESD
111
112 AliPHOSTrackSegmentMaker *tsm = new AliPHOSTrackSegmentMakerv1(fGeom);
e68222ce 113 AliPHOSPID *pid = new AliPHOSPIDv1 (fGeom);
114
9a2cdbdf 115 // do current event; the loop over events is done by AliReconstruction::Run()
116 tsm->SetESD(esd) ;
117 tsm->SetInput(clustersTree);
118 if ( Debug() )
119 tsm->Clusters2TrackSegments("deb all") ;
120 else
121 tsm->Clusters2TrackSegments("") ;
35293055 122
9a2cdbdf 123 pid->SetInput(clustersTree, tsm->GetTrackSegments()) ;
124 pid->SetESD(esd) ;
dfe0be07 125 if ( Debug() )
9a2cdbdf 126 pid->TrackSegments2RecParticles("deb all") ;
dfe0be07 127 else
9a2cdbdf 128 pid->TrackSegments2RecParticles("") ;
7acf6008 129
77ea1c6f 130
23904d16 131 // This function creates AliESDtracks from AliPHOSRecParticles
132 // and
133 // writes them to the ESD
bf72996e 134
9a2cdbdf 135 TClonesArray *recParticles = pid->GetRecParticles();
dfe0be07 136 Int_t nOfRecParticles = recParticles->GetEntries();
a5fa6165 137
85c60a8e 138 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
dd7ee508 139 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
a5e00016 140
9a2cdbdf 141 AliDebug(2,Form("%d rec. particles, option %s",nOfRecParticles,GetOption()));
a5e00016 142
143 // Read digits array
144
145 TBranch *branch = digitsTree->GetBranch("PHOS");
146 if (!branch) {
147 AliError("can't get the branch with the PHOS digits !");
148 return;
149 }
150 TClonesArray *digitsArray = new TClonesArray("AliPHOSDigit",100);
151 branch->SetAddress(&digitsArray);
152 branch->GetEntry(0);
153
154 // Get the clusters array
155
156 TBranch *emcbranch = clustersTree->GetBranch("PHOSEmcRP");
157 if (!emcbranch) {
158 AliError("can't get the branch with the PHOS EMC clusters !");
159 return;
160 }
161
162 TObjArray *emcRecPoints = new TObjArray(100) ;
163 emcbranch->SetAddress(&emcRecPoints);
164 emcbranch->GetEntry(0);
8013c27e 165
64df000d 166 //#########Calculate trigger and set trigger info###########
a5e00016 167
64df000d 168 AliPHOSTrigger tr ;
169 // tr.SetPatchSize(1);//create 4x4 patches
170 tr.Trigger();
171
172 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
173 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
174 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
175 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
176
64df000d 177 Int_t iSM2x2 = tr.Get2x2SuperModule();
178 Int_t iSMnxn = tr.GetnxnSuperModule();
179 Int_t iCrystalPhi2x2 = tr.Get2x2CrystalPhi();
180 Int_t iCrystalPhinxn = tr.GetnxnCrystalPhi();
181 Int_t iCrystalEta2x2 = tr.Get2x2CrystalEta();
182 Int_t iCrystalEtanxn = tr.GetnxnCrystalEta();
183
a5e00016 184 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d",
185 maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCrystalPhi2x2, iCrystalEta2x2));
186 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d",
187 maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCrystalPhinxn, iCrystalEtanxn));
64df000d 188
24b8fcca 189 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 190 Int_t iAbsId2x2 =-1;
24b8fcca 191 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 192 Int_t iAbsIdnxn =-1;
193 TVector3 pos2x2(-1,-1,-1);
194 TVector3 posnxn(-1,-1,-1);
9a2cdbdf 195 fGeom->RelToAbsNumbering(iRelId2x2, iAbsId2x2);
196 fGeom->RelToAbsNumbering(iRelIdnxn, iAbsIdnxn);
197 fGeom->RelPosInAlice(iAbsId2x2, pos2x2);
198 fGeom->RelPosInAlice(iAbsIdnxn, posnxn);
64df000d 199
200 TArrayF triggerPosition(6);
201 triggerPosition[0] = pos2x2(0) ;
202 triggerPosition[1] = pos2x2(1) ;
203 triggerPosition[2] = pos2x2(2) ;
204 triggerPosition[3] = posnxn(0) ;
205 triggerPosition[4] = posnxn(1) ;
206 triggerPosition[5] = posnxn(2) ;
207
208 TArrayF triggerAmplitudes(4);
209 triggerAmplitudes[0] = maxAmp2x2 ;
210 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
211 triggerAmplitudes[2] = maxAmpnxn ;
212 triggerAmplitudes[3] = ampOutOfPatchnxn ;
213
214 //esd->SetPHOSTriggerCells(triggerPosition);
215 esd->AddPHOSTriggerPosition(triggerPosition);
216 esd->AddPHOSTriggerAmplitudes(triggerAmplitudes);
217
e68222ce 218
a5e00016 219 //########################################
220 //############# Fill CaloCells ###########
221 //########################################
222
223 Int_t nDigits = digitsArray->GetEntries();
224 Int_t idignew = 0 ;
225 AliDebug(1,Form("%d digits",nDigits));
226
227 const Int_t knEMC = fGeom->GetNModules()*fGeom->GetNPhi()*fGeom->GetNZ();
228 AliESDCaloCells &phsCells = *(esd->GetPHOSCells());
229 phsCells.CreateContainer(nDigits);
230 phsCells.SetType(AliESDCaloCells::kPHOSCell);
231
232 // Add to CaloCells only EMC digits with non-zero energy
233 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
234 const AliPHOSDigit * dig = (const AliPHOSDigit*)digitsArray->At(idig);
235 if(dig->GetId() <= knEMC && dig->GetEnergy() > 0 ){
710634f4 236 //printf("i %d; id %d; amp %f; time %e\n",
237 //idignew,dig->GetId(),dig->GetEnergy(), dig->GetTime());
a5e00016 238 phsCells.SetCell(idignew,dig->GetId(), dig->GetEnergy(), dig->GetTime());
239 idignew++;
240 }
e68222ce 241 }
a5e00016 242 phsCells.SetNumberOfCells(idignew);
243 phsCells.Sort();
e68222ce 244
a5e00016 245 //########################################
246 //############## Fill CaloClusters #######
247 //########################################
f4e0dd30 248
dfe0be07 249 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
a5e00016 250 AliPHOSRecParticle *rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
dfe0be07 251 if (Debug())
252 rp->Print();
25ed816e 253 // Get track segment and EMC rec.point associated with this rec.particle
a5e00016 254 AliPHOSTrackSegment *ts = static_cast<AliPHOSTrackSegment *>(tsm->GetTrackSegments()
255 ->At(rp->GetPHOSTSIndex()));
9a2cdbdf 256
a5e00016 257 AliPHOSEmcRecPoint *emcRP = static_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(ts->GetEmcIndex()));
25ed816e 258 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
e68222ce 259
85c60a8e 260 Float_t xyz[3];
8013c27e 261 for (Int_t ixyz=0; ixyz<3; ixyz++)
262 xyz[ixyz] = rp->GetPos()[ixyz];
dd7ee508 263
264 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
77ea1c6f 265
a5e00016 266 // Create cell lists
267
268 Int_t cellMult = emcRP->GetDigitsMultiplicity();
269 Int_t *digitsList = emcRP->GetDigitsList();
270 Float_t *rpElist = emcRP->GetEnergiesList() ;
271 UShort_t *absIdList = new UShort_t[cellMult];
272 Double_t *fracList = new Double_t[cellMult];
273
274 for (Int_t iCell=0; iCell<cellMult; iCell++) {
275 AliPHOSDigit *digit = static_cast<AliPHOSDigit *>(digitsArray->At(digitsList[iCell]));
276 absIdList[iCell] = (UShort_t)(digit->GetId());
277 if (digit->GetEnergy() > 0)
278 fracList[iCell] = rpElist[iCell]/digit->GetEnergy();
279 else
280 fracList[iCell] = 0;
25ed816e 281 }
77ea1c6f 282
7592dfc4 283 //Primaries
284 Int_t primMult = 0;
4dd59c4a 285 Int_t *primList = emcRP->GetPrimaries(primMult);
a5e00016 286
7592dfc4 287 // fills the ESDCaloCluster
8ada0ffe 288 ec->SetClusterType(AliESDCaloCluster::kPHOSCluster);
a5e00016 289 ec->SetPosition(xyz); //rec.point position in MARS
290 ec->SetE(rp->Energy()); //total particle energy
25ed816e 291 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
e68222ce 292 ec->SetPid(rp->GetPID()) ; //array of particle identification
25ed816e 293 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
294 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
295 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
a5e00016 296 ec->SetEmcCpvDistance(ts->GetCpvDistance("r")); //Only radius, what about separate x,z????
25ed816e 297 ec->SetClusterChi2(-1); //not yet implemented
298 ec->SetM11(-1) ; //not yet implemented
3744a6cf 299
a5e00016 300 //Cells contributing to clusters
301 ec->SetNCells(cellMult);
302 ec->SetCellsAbsId(absIdList);
303 ec->SetCellsAmplitudeFraction(fracList);
7592dfc4 304
3744a6cf 305 //Distance to the nearest bad crystal
306 ec->SetDistanceToBadChannel(emcRP->GetDistanceToBadCrystal());
7592dfc4 307
308 //Array of MC indeces
4dd59c4a 309 TArrayI arrayPrim(primMult,primList);
7592dfc4 310 ec->AddLabels(arrayPrim);
311
312 //Array of tracks uncomment when available in future
313 //TArrayS arrayTrackMatched(1);// Only one track, temporal solution.
314 //arrayTrackMatched[0]= (Short_t)(matchedTrack[iClust]);
315 //ec->AddTracksMatched(arrayTrackMatched);
64df000d 316
dfe0be07 317 // add the track to the esd object
a5e00016 318
85c60a8e 319 esd->AddCaloCluster(ec);
9a2cdbdf 320 delete ec;
e68222ce 321 }
a5e00016 322 digitsArray ->Delete();
323 delete digitsArray;
324 emcRecPoints->Delete();
325 delete emcRecPoints;
e68222ce 326 delete tsm;
327 delete pid;
dd7ee508 328}
329
e68222ce 330//____________________________________________________________________________
d76c31f4 331AliTracker* AliPHOSReconstructor::CreateTracker() const
dd7ee508 332{
9a2cdbdf 333 // creates the PHOS tracker
334 return new AliPHOSTracker();
335}
dd7ee508 336
1267d56d 337//____________________________________________________________________________
9a2cdbdf 338void AliPHOSReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
339{
340 // Converts raw data to
341 // PHOS digits
342 // Works on a single-event basis
dd7ee508 343
9a2cdbdf 344 rawReader->Reset() ;
dd7ee508 345
77ea1c6f 346 AliPHOSRawDecoder * dc ;
347
b3006690 348 const TObjArray* maps = AliPHOSRecoParamEmc::GetMappings();
349 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
350
351 AliAltroMapping *mapping[4];
352 for(Int_t i = 0; i < 4; i++) {
353 mapping[i] = (AliAltroMapping*)maps->At(i);
354 }
355
77ea1c6f 356 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v1")==0)
b3006690 357 dc=new AliPHOSRawDecoderv1(rawReader,mapping);
710634f4 358 else
359 if(strcmp(fgkRecoParamEmc->DecoderVersion(),"v2")==0)
360 dc=new AliPHOSRawDecoderv2(rawReader,mapping);
361 else
362 dc=new AliPHOSRawDecoder(rawReader,mapping);
77ea1c6f 363
a7660309 364 dc->SetOldRCUFormat(fgkRecoParamEmc->IsOldRCUFormat());
86121c91 365
77ea1c6f 366 dc->SubtractPedestals(fgkRecoParamEmc->SubtractPedestals());
86121c91 367
9a2cdbdf 368 TClonesArray *digits = new TClonesArray("AliPHOSDigit",1);
369 digits->SetName("DIGITS");
370 Int_t bufsize = 32000;
371 digitsTree->Branch("PHOS", &digits, bufsize);
dd7ee508 372
a28333c5 373 AliPHOSRawDigiProducer pr(fgkRecoParamEmc,fgkRecoParamCpv);
77ea1c6f 374 pr.MakeDigits(digits,dc);
375
376 delete dc ;
7592dfc4 377
9a2cdbdf 378 //!!!!for debug!!!
a28333c5 379/*
9a2cdbdf 380 Int_t modMax=-111;
381 Int_t colMax=-111;
382 Int_t rowMax=-111;
383 Float_t eMax=-333;
384 //!!!for debug!!!
385
386 Int_t relId[4];
387 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
388 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
389 if(digit->GetEnergy()>eMax) {
390 fGeom->AbsToRelNumbering(digit->GetId(),relId);
391 eMax=digit->GetEnergy();
392 modMax=relId[0];
393 rowMax=relId[2];
394 colMax=relId[3];
dd7ee508 395 }
396 }
397
9a2cdbdf 398 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
399 modMax,colMax,rowMax,eMax));
a28333c5 400*/
9a2cdbdf 401 digitsTree->Fill();
e68222ce 402 digits->Delete();
403 delete digits;
d7d3b67b 404}