]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALReconstructor.cxx
silvermy@ornl.gov - SMcalib - directory with tools for SuperModule calibrations at...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALReconstructor.cxx
CommitLineData
f6019cda 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
16/* $Id$ */
17
18//_________________________________________________________________________
fa42b1f3 19//--
20//-- Yves Schutz (SUBATECH)
f6019cda 21// Reconstruction class. Redesigned from the old AliReconstructionner class and
22// derived from STEER/AliReconstructor.
23//
85c25c2e 24//-- Aleksei Pavlinov : added staf for EMCAL jet trigger 9Apr 25, 2008)
25// : fgDigitsArr should read just once at event
26
f6019cda 27// --- ROOT system ---
85c25c2e 28#include <TList.h>
29#include <TClonesArray.h>
60d8ad94 30#include <TH2.h>
f6019cda 31
32// --- Standard library ---
33
34// --- AliRoot header files ---
f6019cda 35#include "AliEMCALReconstructor.h"
5dee926e 36
aaa3cb7c 37#include "AliCodeTimer.h"
af885e0f 38#include "AliESDEvent.h"
89ffc0b0 39#include "AliESDCaloCluster.h"
0e7c6655 40#include "AliESDCaloCells.h"
6a0cf740 41#include "AliESDtrack.h"
5dee926e 42#include "AliEMCALLoader.h"
98e9578e 43#include "AliEMCALRawUtils.h"
0e7c6655 44#include "AliEMCALDigit.h"
f6019cda 45#include "AliEMCALClusterizerv1.h"
5dee926e 46#include "AliEMCALRecPoint.h"
dc293ae9 47#include "AliEMCALPID.h"
0964c2e9 48#include "AliEMCALTrigger.h"
1d59832c 49#include "AliRawReader.h"
fa42b1f3 50#include "AliCDBEntry.h"
51#include "AliCDBManager.h"
65bdc82f 52#include "AliEMCALGeometry.h"
ac8ae9fe 53#include "AliEMCAL.h"
85c25c2e 54#include "AliEMCALHistoUtilities.h"
55#include "AliESDVZERO.h"
65bdc82f 56
72c58de0 57#include "AliRunLoader.h"
58#include "AliRun.h"
1d59832c 59
85c25c2e 60ClassImp(AliEMCALReconstructor)
f6019cda 61
ba6de5ea 62const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
65bdc82f 63AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
9517d886 64AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
85c25c2e 65TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // shoud read just once at event
f6019cda 66//____________________________________________________________________________
18a21c7c 67AliEMCALReconstructor::AliEMCALReconstructor()
85c25c2e 68 : fDebug(kFALSE), fList(0), fGeom(0)
f6019cda 69{
70 // ctor
65bdc82f 71
72 fgRawUtils = new AliEMCALRawUtils;
9517d886 73 fgClusterizer = new AliEMCALClusterizerv1;
72c58de0 74
75 //To make sure we match with the geometry in a simulation file,
76 //let's try to get it first. If not, take the default geometry
77 AliRunLoader *rl = AliRunLoader::GetRunLoader();
78 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
79 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
80 } else {
81 AliInfo(Form("Using default geometry in reconstruction"));
937d0661 82 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
65bdc82f 83 }
0e7c6655 84
72c58de0 85 if(!fGeom) AliFatal(Form("Could not get geometry!"));
86
f6019cda 87}
88
0a4cb131 89//____________________________________________________________________________
18a21c7c 90AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
91 : AliReconstructor(rec),
65bdc82f 92 fDebug(rec.fDebug),
85c25c2e 93 fList(rec.fList),
65bdc82f 94 fGeom(rec.fGeom)
0a4cb131 95{
96 //copy ctor
0a4cb131 97}
f6019cda 98
99//____________________________________________________________________________
100AliEMCALReconstructor::~AliEMCALReconstructor()
101{
102 // dtor
65bdc82f 103 delete fGeom;
aaa3cb7c 104 AliCodeTimer::Instance()->Print();
f6019cda 105}
106
85c25c2e 107//____________________________________________________________________________
108void AliEMCALReconstructor::Init()
109{
110 // Trigger hists - Oct 24, 2007
111 fList = AliEMCALHistoUtilities::GetTriggersListOfHists(kTRUE);
112}
113
f6019cda 114//____________________________________________________________________________
c47157cd 115void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
f6019cda 116{
117 // method called by AliReconstruction;
118 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
119 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
120 // the global tracking.
c47157cd 121 // Works on the current event.
fa42b1f3 122
aaa3cb7c 123 AliCodeTimerAuto("")
124
85c25c2e 125 ReadDigitsArrayFromTree(digitsTree);
0832a2bf 126 fgClusterizer->InitParameters();
4601e3a7 127 fgClusterizer->SetOutput(clustersTree);
128
85c25c2e 129 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
130
9517d886 131 fgClusterizer->SetInput(digitsTree);
9517d886 132
85c25c2e 133 if(Debug())
9517d886 134 fgClusterizer->Digits2Clusters("deb all") ;
85c25c2e 135 else
9517d886 136 fgClusterizer->Digits2Clusters("");
137
138 fgClusterizer->Clear();
85c25c2e 139
140 }
9517d886 141
f6019cda 142}
143
a68156e6 144//____________________________________________________________________________
c47157cd 145void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
98e9578e 146
a68156e6 147{
c47157cd 148 // Conversion from raw data to
149 // EMCAL digits.
150 // Works on a single-event basis
85c60a8e 151
98e9578e 152 rawReader->Reset() ;
98e9578e 153
3e5fa09c 154 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
c47157cd 155 Int_t bufsize = 32000;
156 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
98e9578e 157
65bdc82f 158 //must be done here because, in constructor, option is not yet known
159 fgRawUtils->SetOption(GetOption());
b4133f05 160
0832a2bf 161 fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
162 fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
163 fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
164 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
165 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
b4133f05 166
65bdc82f 167 fgRawUtils->Raw2Digits(rawReader,digitsArr);
c615db53 168
169 digitsTree->Fill();
170 digitsArr->Delete();
171 delete digitsArr;
172
a68156e6 173}
174
85c25c2e 175
f6019cda 176//____________________________________________________________________________
0e7c6655 177void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
c47157cd 178 AliESDEvent* esd) const
f6019cda 179{
98e9578e 180 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
85c25c2e 181 // and V0
c47157cd 182 // Works on the current event
85c25c2e 183 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
184 //return;
92da3372 185
6a0cf740 186 //######################################################
0964c2e9 187 //#########Calculate trigger and set trigger info###########
6a0cf740 188 //######################################################
85c25c2e 189
190 AliEMCALTrigger tr;
191 // tr.SetPatchSize(1); // create 4x4 patches
192 tr.SetSimulation(kFALSE); // Reconstruction mode
193 tr.SetDigitsList(fgDigitsArr);
194 // Get VZERO total multiplicity for jet trigger simulation
195 // The simulation of jey trigger will be incorrect if no VZERO data
196 // at ESD
197 AliESDVZERO* vZero = esd->GetVZEROData();
198 if(vZero) {
199 tr.SetVZER0Multiplicity(vZero->GetMTotV0A() + vZero->GetMTotV0C());
200 }
201 //
0964c2e9 202 tr.Trigger();
85c25c2e 203
0964c2e9 204 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
205 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
206 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
207 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
208
0964c2e9 209 Int_t iSM2x2 = tr.Get2x2SuperModule();
210 Int_t iSMnxn = tr.GetnxnSuperModule();
85c25c2e 211 Int_t iModulePhi2x2 = tr.Get2x2ModulePhi();
212 Int_t iModulePhinxn = tr.GetnxnModulePhi();
213 Int_t iModuleEta2x2 = tr.Get2x2ModuleEta();
214 Int_t iModuleEtanxn = tr.GetnxnModuleEta();
0964c2e9 215
85c25c2e 216 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iModulePhi2x2, iModuleEta2x2));
217 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iModulePhinxn, iModuleEtanxn));
0964c2e9 218
219 TVector3 pos2x2(-1,-1,-1);
220 TVector3 posnxn(-1,-1,-1);
221
85c25c2e 222 Int_t iAbsId2x2 = fGeom->GetAbsCellIdFromCellIndexes( iSM2x2, iModulePhi2x2, iModuleEta2x2) ; // should be changed to Module
223 Int_t iAbsIdnxn = fGeom->GetAbsCellIdFromCellIndexes( iSMnxn, iModulePhinxn, iModuleEtanxn) ;
65bdc82f 224 fGeom->GetGlobal(iAbsId2x2, pos2x2);
225 fGeom->GetGlobal(iAbsIdnxn, posnxn);
85c25c2e 226 //printf(" iAbsId2x2 %i iAbsIdnxn %i \n", iAbsId2x2, iAbsIdnxn);
0964c2e9 227
228 TArrayF triggerPosition(6);
229 triggerPosition[0] = pos2x2(0) ;
230 triggerPosition[1] = pos2x2(1) ;
231 triggerPosition[2] = pos2x2(2) ;
232 triggerPosition[3] = posnxn(0) ;
233 triggerPosition[4] = posnxn(1) ;
85c25c2e 234 triggerPosition[5] = posnxn(2) ;
235 //printf(" triggerPosition ");
236 //for(int i=0; i<6; i++) printf(" %i %f : ", i, triggerPosition[i]);
0964c2e9 237
238 TArrayF triggerAmplitudes(4);
239 triggerAmplitudes[0] = maxAmp2x2 ;
240 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
241 triggerAmplitudes[2] = maxAmpnxn ;
242 triggerAmplitudes[3] = ampOutOfPatchnxn ;
85c25c2e 243 //printf("\n triggerAmplitudes ");
244 //for(int i=0; i<4; i++) printf(" %i %f : ", i, triggerAmplitudes[i]);
245 //printf("\n");
85d4cbde 246 //tr.Print("");
60d8ad94 247 //
248 // Trigger jet staff
249 //
250 if(tr.GetNJetThreshold()>0) {
251 // Jet phi/eta
252 Int_t n0 = triggerPosition.GetSize();
253 const TH2F *hpatch = tr.GetJetMatrixE();
254 triggerPosition.Set(n0 + 2);
255 for(Int_t i=0; i<2; i++) triggerPosition[n0+i] = hpatch->GetMean(i+1);
256 // Add jet ampitudes
257 n0 = triggerAmplitudes.GetSize();
258 triggerAmplitudes.Set(n0 + tr.GetNJetThreshold());
259 Double_t *ampJet = tr.GetL1JetThresholds();
260 for(Int_t i=0; i<tr.GetNJetThreshold(); i++){
261 triggerAmplitudes[n0 + i] = Float_t(ampJet[i]);
262 }
263 }
0964c2e9 264 esd->AddEMCALTriggerPosition(triggerPosition);
265 esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
85c25c2e 266 // Fill trigger hists
267 AliEMCALHistoUtilities::FillTriggersListOfHists(fList,&triggerPosition,&triggerAmplitudes);
aaa3cb7c 268
0e7c6655 269 //########################################
270 //##############Fill CaloCells###############
271 //########################################
aaa3cb7c 272
0e7c6655 273 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
274 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
275 if (!branchdig) {
276 AliError("can't get the branch with the PHOS digits !");
277 return;
278 }
279 branchdig->SetAddress(&digits);
280 digitsTree->GetEvent(0);
281 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
282 AliDebug(1,Form("%d digits",nDigits));
283
284 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
285 emcCells.CreateContainer(nDigits);
286 emcCells.SetType(AliESDCaloCells::kEMCALCell);
287 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
288 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
289 if(dig->GetAmp() > 0 ){
290 emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());
291 idignew++;
292 }
293 }
294 emcCells.SetNumberOfCells(idignew);
295 emcCells.Sort();
296
297 //------------------------------------------------------------
298 //-----------------CLUSTERS-----------------------------
299 //------------------------------------------------------------
300 TObjArray *clusters = new TObjArray(100);
301 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
302 branch->SetAddress(&clusters);
303 clustersTree->GetEvent(0);
304
305 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
306 AliDebug(1,Form("%d clusters",nClusters));
307 esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
308
85c25c2e 309
6a0cf740 310 //######################################################
311 //#######################TRACK MATCHING###############
312 //######################################################
313 //Fill list of integers, each one is index of track to which the cluster belongs.
314
315 // step 1 - initialize array of matched track indexes
316 Int_t *matchedTrack = new Int_t[nClusters];
317 for (Int_t iclus = 0; iclus < nClusters; iclus++)
318 matchedTrack[iclus] = -1; // neg. index --> no matched track
319
320 // step 2, change the flag for all matched clusters found in tracks
321 Int_t iemcalMatch = -1;
322 Int_t endtpc = esd->GetNumberOfTracks();
323 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
324 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
325 iemcalMatch = track->GetEMCALcluster();
65f4a419 326 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
6a0cf740 327 }
85c25c2e 328
6a0cf740 329 //########################################
85c25c2e 330 //##############Fill CaloClusters#############
6a0cf740 331 //########################################
35397e76 332 esd->SetNumberOfEMCALClusters(nClusters);
5dee926e 333 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
c47157cd 334 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
8ada0ffe 335 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
85c60a8e 336 if (Debug()) clust->Print();
a7a5421e 337 // Get information from EMCAL reconstruction points
85c60a8e 338 Float_t xyz[3];
5dee926e 339 TVector3 gpos;
340 clust->GetGlobalPosition(gpos);
35397e76 341 for (Int_t ixyz=0; ixyz<3; ixyz++)
5dee926e 342 xyz[ixyz] = gpos[ixyz];
85c25c2e 343 Float_t elipAxis[2];
344 clust->GetElipsAxis(elipAxis);
35397e76 345 //Create digits lists
346 Int_t cellMult = clust->GetMultiplicity();
347 //TArrayS digiList(digitMult);
348 Float_t *amplFloat = clust->GetEnergiesList();
349 Int_t *digitInts = clust->GetAbsId();
350 TArrayS absIdList(cellMult);
eb972628 351 TArrayD fracList(cellMult);
35397e76 352
353 Int_t newCellMult = 0;
354 for (Int_t iCell=0; iCell<cellMult; iCell++) {
355 if (amplFloat[iCell] > 0) {
356 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
eb972628 357 //Uncomment when unfolding is done
358 //if(emcCells.GetCellAmplitude(digitInts[iCell])>0)
359 //fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell])*calibration);//get cell calibration value
360 //else
361 fracList[newCellMult] = 0;
35397e76 362 newCellMult++;
92da3372 363 }
92da3372 364 }
85c25c2e 365
eb972628 366 absIdList.Set(newCellMult);
367 fracList.Set(newCellMult);
368
35397e76 369 if(newCellMult > 0) { // accept cluster if it has some digit
370 nClustersNew++;
65721814 371 //Primaries
7592dfc4 372 Int_t parentMult = 0;
fa42b1f3 373 Int_t *parentList = clust->GetParents(parentMult);
a7a5421e 374 // fills the ESDCaloCluster
35397e76 375 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
376 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
7592dfc4 377 ec->SetPosition(xyz);
378 ec->SetE(clust->GetEnergy());
35397e76 379 ec->SetNCells(newCellMult);
380 //Change type of list from short to ushort
381 UShort_t *newAbsIdList = new UShort_t[newCellMult];
eb972628 382 Double_t *newFracList = new Double_t[newCellMult];
35397e76 383 for(Int_t i = 0; i < newCellMult ; i++) {
384 newAbsIdList[i]=absIdList[i];
eb972628 385 newFracList[i]=fracList[i];
35397e76 386 }
387 ec->SetCellsAbsId(newAbsIdList);
eb972628 388 ec->SetCellsAmplitudeFraction(newFracList);
35397e76 389 ec->SetClusterDisp(clust->GetDispersion());
390 ec->SetClusterChi2(-1); //not yet implemented
391 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
392 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
78902954 393 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
225cd96d 394 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
35397e76 395 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
396 arrayTrackMatched[0]= matchedTrack[iClust];
397 ec->AddTracksMatched(arrayTrackMatched);
398
399 TArrayI arrayParents(parentMult,parentList);
400 ec->AddLabels(arrayParents);
401
6a0cf740 402 // add the cluster to the esd object
eb972628 403 esd->AddCaloCluster(ec);
a7a5421e 404 delete ec;
85d4cbde 405 delete [] newAbsIdList ;
eb972628 406 delete [] newFracList ;
35397e76 407 }
408 } // cycle on clusters
85c25c2e 409
35397e76 410 delete [] matchedTrack;
85c25c2e 411
35397e76 412 esd->SetNumberOfEMCALClusters(nClustersNew);
413 //if(nClustersNew != nClusters)
414 //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
85c25c2e 415
35397e76 416 //Fill ESDCaloCluster with PID weights
85c25c2e 417 AliEMCALPID *pid = new AliEMCALPID;
418 //pid->SetPrintInfo(kTRUE);
419 pid->SetReconstructor(kTRUE);
420 pid->RunPID(esd);
85c25c2e 421 delete pid;
eb972628 422
35397e76 423 delete digits;
85c25c2e 424 delete clusters;
eb972628 425
35397e76 426 // printf(" ## AliEMCALReconstructor::FillESD() is ended : ncl %i -> %i ### \n ",nClusters, nClustersNew);
f6019cda 427}
dc293ae9 428
9517d886 429//__________________________________________________________________________
85c25c2e 430void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
431{
432 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
433 if(fgDigitsArr) {
434 // Clear previous digits
435 fgDigitsArr->Delete();
436 delete fgDigitsArr;
437 }
438 // Read the digits from the input tree
439 TBranch *branch = digitsTree->GetBranch("EMCAL");
440 if (!branch) {
441 AliError("can't get the branch with the EMCAL digits !");
442 return;
443 }
444 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
445 branch->SetAddress(&fgDigitsArr);
446 branch->GetEntry(0);
447}
98e9578e 448