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.
26 // --- ROOT system ---
27 #include <TClonesArray.h>
28 #include "TGeoManager.h"
29 #include "TGeoMatrix.h"
31 // --- Standard library ---
33 // --- AliRoot header files ---
34 #include "AliEMCALReconstructor.h"
36 #include "AliCodeTimer.h"
37 #include "AliCaloCalibPedestal.h"
38 #include "AliEMCALCalibData.h"
39 #include "AliESDEvent.h"
40 #include "AliESDCaloCluster.h"
41 #include "AliESDCaloCells.h"
42 #include "AliESDtrack.h"
43 #include "AliEMCALLoader.h"
44 #include "AliEMCALRawUtils.h"
45 #include "AliEMCALDigit.h"
46 #include "AliEMCALClusterizerv1.h"
47 #include "AliEMCALClusterizerv2.h"
48 #include "AliEMCALClusterizerNxN.h"
49 #include "AliEMCALRecPoint.h"
50 #include "AliEMCALPID.h"
51 #include "AliRawReader.h"
52 #include "AliCDBEntry.h"
53 #include "AliCDBManager.h"
54 #include "AliEMCALGeometry.h"
56 #include "AliESDVZERO.h"
57 #include "AliCDBManager.h"
58 #include "AliRunLoader.h"
60 #include "AliEMCALTriggerData.h"
61 #include "AliEMCALTriggerElectronics.h"
62 #include "AliEMCALTriggerDCSConfigDB.h"
63 #include "AliEMCALTriggerDCSConfig.h"
64 #include "AliEMCALTriggerData.h"
65 #include "AliEMCALTriggerRawDigit.h"
66 #include "AliEMCALTriggerPatch.h"
67 #include "AliEMCALTriggerTypes.h"
69 ClassImp(AliEMCALReconstructor)
71 const AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
72 AliEMCALRawUtils* AliEMCALReconstructor::fgRawUtils = 0; // EMCAL raw utilities class
73 AliEMCALClusterizer* AliEMCALReconstructor::fgClusterizer = 0; // EMCAL clusterizer class
74 TClonesArray* AliEMCALReconstructor::fgDigitsArr = 0; // list of digits, to be used multiple times
75 TObjArray* AliEMCALReconstructor::fgClustersArr = 0; // list of clusters, to be used multiple times
76 TClonesArray* AliEMCALReconstructor::fgTriggerDigits = 0; // list of trigger digits, to be used multiple times
77 AliEMCALTriggerElectronics* AliEMCALReconstructor::fgTriggerProcessor = 0x0;
78 //____________________________________________________________________________
79 AliEMCALReconstructor::AliEMCALReconstructor()
80 : fGeom(0),fCalibData(0),fPedestalData(0),fTriggerData(0x0), fMatches(0x0)
84 // AliDebug(2, "Mark.");
86 fgRawUtils = new AliEMCALRawUtils;
88 //To make sure we match with the geometry in a simulation file,
89 //let's try to get it first. If not, take the default geometry
90 AliRunLoader *rl = AliRunLoader::Instance();
92 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
93 if(emcal) fGeom = emcal->GetGeometry();
97 AliInfo(Form("Using default geometry in reconstruction"));
98 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
101 //Get calibration parameters
104 AliCDBEntry *entry = (AliCDBEntry*)
105 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
106 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
110 AliFatal("Calibration parameters not found in CDB!");
112 //Get calibration parameters
115 AliCDBEntry *entry = (AliCDBEntry*)
116 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
117 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
121 AliFatal("Dead map not found in CDB!");
123 if(!fGeom) AliFatal(Form("Could not get geometry!"));
125 AliEMCALTriggerDCSConfigDB* dcsConfigDB = AliEMCALTriggerDCSConfigDB::Instance();
127 const AliEMCALTriggerDCSConfig* dcsConfig = dcsConfigDB->GetTriggerDCSConfig();
129 if (!dcsConfig) AliFatal("No Trigger DCS Configuration from OCDB!");
130 fgTriggerProcessor = new AliEMCALTriggerElectronics( dcsConfig );
132 fTriggerData = new AliEMCALTriggerData();
134 //Init temporary list of digits
135 fgDigitsArr = new TClonesArray("AliEMCALDigit",1000);
136 fgClustersArr = new TObjArray(1000);
137 fgTriggerDigits = new TClonesArray("AliEMCALTriggerRawDigit",1000);
140 fMatches = new TList();
141 fMatches->SetOwner(kTRUE);
144 //____________________________________________________________________________
145 AliEMCALReconstructor::~AliEMCALReconstructor()
149 //AliDebug(2, "Mark.");
151 if(fGeom) delete fGeom;
153 //No need to delete, recovered from OCDB
154 //if(fCalibData) delete fCalibData;
155 //if(fPedestalData) delete fPedestalData;
158 fgDigitsArr->Clear("C");
163 fgClustersArr->Clear();
164 delete fgClustersArr;
168 fgTriggerDigits->Clear();
169 delete fgTriggerDigits;
172 if(fgRawUtils) delete fgRawUtils;
173 if(fgClusterizer) delete fgClusterizer;
174 if(fgTriggerProcessor) delete fgTriggerProcessor;
176 if(fMatches) { fMatches->Delete(); delete fMatches; fMatches = 0;}
178 AliCodeTimer::Instance()->Print();
181 //____________________________________________________________________________
182 void AliEMCALReconstructor::InitClusterizer() const
184 //Init the clusterizer with geometry and calibration pointers, avoid doing it twice.
185 Int_t clusterizerType = -1;
186 Int_t eventType = -1;
188 clusterizerType = GetRecParam()->GetClusterizerFlag();
189 eventType = GetRecParam()->GetEventSpecie();
192 AliCDBEntry *entry = (AliCDBEntry*)
193 AliCDBManager::Instance()->Get("EMCAL/Calib/RecoParam");
194 //Get The reco param for the default event specie
196 AliEMCALRecParam *recParam = (AliEMCALRecParam*)((TObjArray *) entry->GetObject())->At(0);
197 if(recParam) clusterizerType = recParam->GetClusterizerFlag();
201 //Check if clusterizer previously set corresponds to what is needed for this event type
203 if(eventType!=AliRecoParam::kCalib){
204 //printf("ReCreate clusterizer? Clusterizer set <%d>, Clusterizer in use <%s>\n",
205 // clusterizerType, fgClusterizer->Version());
207 if (clusterizerType == AliEMCALRecParam::kClusterizerv1 && !strcmp(fgClusterizer->Version(),"clu-v1")) return;
209 else if(clusterizerType == AliEMCALRecParam::kClusterizerNxN && !strcmp(fgClusterizer->Version(),"clu-NxN")) return;
211 else if(clusterizerType == AliEMCALRecParam::kClusterizerv2 && !strcmp(fgClusterizer->Version(),"clu-v2")) return;
213 //Need to create new clusterizer, the one set previously is not the correct one
214 delete fgClusterizer;
219 if (clusterizerType == AliEMCALRecParam::kClusterizerv1)
221 fgClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData,fPedestalData);
223 else if (clusterizerType == AliEMCALRecParam::kClusterizerNxN)
225 fgClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData,fPedestalData);
227 else if (clusterizerType == AliEMCALRecParam::kClusterizerv2)
229 fgClusterizer = new AliEMCALClusterizerv2 (fGeom, fCalibData,fPedestalData);
233 AliFatal(Form("Unknown clusterizer %d ", clusterizerType));
237 //____________________________________________________________________________
238 void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
240 // method called by AliReconstruction;
241 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
242 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
243 // the global tracking.
244 // Works on the current event.
246 AliCodeTimerAuto("",0)
248 //Get input digits and put them in fgDigitsArr, clear the list before
249 ReadDigitsArrayFromTree(digitsTree);
253 fgClusterizer->InitParameters();
254 fgClusterizer->SetOutput(clustersTree);
256 //Skip clusterization of LED events
257 if (GetRecParam()->GetEventSpecie()!=AliRecoParam::kCalib){
259 if(fgDigitsArr && fgDigitsArr->GetEntries()) {
261 fgClusterizer->SetInput(digitsTree);
263 //fgClusterizer->Digits2Clusters("deb all") ; //For debugging
264 fgClusterizer->Digits2Clusters("");
266 fgClusterizer->Clear();
268 }//digits array exists and has somethind
271 clustersTree->Fill();
273 // Deleting the recpoints at the end of the reconstruction call
274 fgClusterizer->DeleteRecPoints();
277 //____________________________________________________________________________
278 void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
281 // Conversion from raw data to
283 // Works on a single-event basis
287 fTriggerData->SetMode(1);
289 if(fgDigitsArr) fgDigitsArr->Clear("C");
291 TClonesArray *digitsTrg = new TClonesArray("AliEMCALTriggerRawDigit", 32 * 96);
293 Int_t bufsize = 32000;
294 digitsTree->Branch("EMCAL", &fgDigitsArr, bufsize);
295 digitsTree->Branch("EMTRG", &digitsTrg, bufsize);
297 //Skip calibration events do the rest
298 Bool_t doFit = kTRUE;
299 if ( !(GetRecParam()->FitLEDEvents()) && GetRecParam()->GetEventSpecie()==AliRecoParam::kCalib) doFit = kFALSE;
301 //must be done here because, in constructor, option is not yet known
302 fgRawUtils->SetOption(GetOption());
304 // fgRawUtils->SetRawFormatHighLowGainFactor(GetRecParam()->GetHighLowGainFactor());
306 // fgRawUtils->SetRawFormatOrder(GetRecParam()->GetOrderParameter());
307 // fgRawUtils->SetRawFormatTau(GetRecParam()->GetTau());
308 fgRawUtils->SetNoiseThreshold(GetRecParam()->GetNoiseThreshold());
309 fgRawUtils->SetNPedSamples(GetRecParam()->GetNPedSamples());
310 fgRawUtils->SetRemoveBadChannels(GetRecParam()->GetRemoveBadChannels());
311 if (!fgRawUtils->GetFittingAlgorithm()) fgRawUtils->SetFittingAlgorithm(GetRecParam()->GetFittingAlgorithm());
312 fgRawUtils->SetFALTROUsage(GetRecParam()->UseFALTRO());
314 //fgRawUtils->SetTimeMin(GetRecParam()->GetTimeMin());
315 //fgRawUtils->SetTimeMax(GetRecParam()->GetTimeMax());
317 // fgRawUtils->SetTimeMin(-99999 );
318 // fgRawUtils->SetTimeMax( 99999 );
320 fgRawUtils->Raw2Digits(rawReader,fgDigitsArr,fPedestalData,digitsTrg,fTriggerData);
322 }//skip calibration event
324 AliDebug(1," Calibration Event, skip!");
334 //____________________________________________________________________________
335 void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
336 AliESDEvent* esd) const
338 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
340 // Works on the current event
341 // printf(" ## AliEMCALReconstructor::FillESD() is started ### \n ");
344 //########################################
346 //########################################
348 static int saveOnce = 0;
350 Int_t v0M[2] = {0, 0};
352 AliESDVZERO* esdV0 = esd->GetVZEROData();
356 for (Int_t i = 0; i < 32; i++)
358 v0M[0] += (Int_t)esdV0->GetAdcV0C(i);
359 v0M[1] += (Int_t)esdV0->GetAdcV0A(i);
364 AliWarning("Cannot retrieve V0 ESD! Run w/ null V0 charges");
367 if (fgTriggerDigits) fgTriggerDigits->Clear();
369 TBranch *branchtrg = digitsTree->GetBranch("EMTRG");
373 AliError("Can't get the branch with the EMCAL trigger digits!");
377 branchtrg->SetAddress(&fgTriggerDigits);
378 branchtrg->GetEntry(0);
380 // Note: fgTriggerProcessor reset done at the end of this method
381 fgTriggerProcessor->Digits2Trigger(fgTriggerDigits, v0M, fTriggerData);
384 AliESDCaloTrigger* trgESD = esd->GetCaloTrigger("EMCAL");
388 trgESD->Allocate(fgTriggerDigits->GetEntriesFast());
390 for (Int_t i = 0; i < fgTriggerDigits->GetEntriesFast(); i++)
392 AliEMCALTriggerRawDigit* rdig = (AliEMCALTriggerRawDigit*)fgTriggerDigits->At(i);
395 if (fGeom->GetPositionInEMCALFromAbsFastORIndex(rdig->GetId(), px, py))
397 Int_t a = -1, t = -1, times[10];
399 rdig->GetMaximum(a, t);
400 rdig->GetL0Times(times);
402 trgESD->Add(px, py, a, t, times, rdig->GetNL0Times(), rdig->GetL1TimeSum(), rdig->GetTriggerBits());
406 trgESD->SetL1Threshold(0, fTriggerData->GetL1GammaThreshold());
408 trgESD->SetL1Threshold(1, fTriggerData->GetL1JetThreshold() );
411 fTriggerData->GetL1V0(v0);
414 trgESD->SetL1FrameMask(fTriggerData->GetL1FrameMask());
416 if (!saveOnce && fTriggerData->GetL1DataDecoded())
419 fTriggerData->GetL1TriggerType(type);
421 esd->SetCaloTriggerType(type);
428 fTriggerData->Reset();
430 //########################################
431 //##############Fill CaloCells###############
432 //########################################
434 //Get input digits and put them in fgDigitsArr, clear the list before
435 ReadDigitsArrayFromTree(digitsTree);
437 Int_t nDigits = fgDigitsArr->GetEntries(), idignew = 0 ;
438 AliDebug(1,Form("%d digits",nDigits));
439 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
440 emcCells.CreateContainer(nDigits);
441 emcCells.SetType(AliVCaloCells::kEMCALCell);
444 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
445 const AliEMCALDigit * dig = (const AliEMCALDigit*)fgDigitsArr->At(idig);
446 time = dig->GetTime(); // Time already calibrated in clusterizer
447 energy = dig->GetAmplitude(); // energy calibrated in clusterizer
449 fgClusterizer->Calibrate(energy,time,dig->GetId()); //Digits already calibrated in clusterizers
450 if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
451 emcCells.SetCell(idignew,dig->GetId(),energy, time);
456 emcCells.SetNumberOfCells(idignew);
459 //------------------------------------------------------------
460 //-----------------CLUSTERS-----------------------------
461 //------------------------------------------------------------
462 clustersTree->SetBranchStatus("*",0); //disable all branches
463 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
464 if(fgClustersArr) fgClustersArr->Clear();
465 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
466 branch->SetAddress(&fgClustersArr);
468 //clustersTree->GetEvent(0);
470 Int_t nClusters = fgClustersArr->GetEntries(), nClustersNew=0;
471 AliDebug(1,Form("%d clusters",nClusters));
474 //########################################
475 //##############Fill CaloClusters#############
476 //########################################
477 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
478 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)fgClustersArr->At(iClust);
480 //if(clust->GetClusterType()== AliVCluster::kEMCALClusterv1) nRP++; else nPC++;
481 // clust->Print(); //For debugging
482 // Get information from EMCAL reconstruction points
485 clust->GetGlobalPosition(gpos);
486 for (Int_t ixyz=0; ixyz<3; ixyz++)
487 xyz[ixyz] = gpos[ixyz];
489 clust->GetElipsAxis(elipAxis);
490 //Create digits lists
491 Int_t cellMult = clust->GetMultiplicity();
492 //TArrayS digiList(digitMult);
493 Float_t *amplFloat = clust->GetEnergiesList();
494 Int_t *digitInts = clust->GetAbsId();
495 TArrayS absIdList(cellMult);
496 TArrayD fracList(cellMult);
498 Int_t newCellMult = 0;
499 for (Int_t iCell=0; iCell<cellMult; iCell++) {
500 if (amplFloat[iCell] > 0) {
501 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
503 if(emcCells.GetCellAmplitude(digitInts[iCell])>0 && GetRecParam()->GetUnfold()){
504 fracList[newCellMult] = amplFloat[iCell]/(emcCells.GetCellAmplitude(digitInts[iCell]));//get cell calibration value
508 fracList[newCellMult] = 0;
514 absIdList.Set(newCellMult);
515 fracList.Set(newCellMult);
517 if(newCellMult > 0) { // accept cluster if it has some digit
520 Int_t parentMult = 0;
521 Int_t *parentList = clust->GetParents(parentMult);
522 // fills the ESDCaloCluster
523 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
524 ec->SetType(AliVCluster::kEMCALClusterv1);
525 ec->SetPosition(xyz);
526 ec->SetE(clust->GetEnergy());
528 //Distance to the nearest bad crystal
529 ec->SetDistanceToBadChannel(clust->GetDistanceToBadTower());
531 ec->SetNCells(newCellMult);
532 //Change type of list from short to ushort
533 UShort_t *newAbsIdList = new UShort_t[newCellMult];
534 Double_t *newFracList = new Double_t[newCellMult];
535 for(Int_t i = 0; i < newCellMult ; i++) {
536 newAbsIdList[i]=absIdList[i];
537 newFracList[i] =fracList[i];
539 ec->SetCellsAbsId(newAbsIdList);
540 ec->SetCellsAmplitudeFraction(newFracList);
541 ec->SetDispersion(clust->GetDispersion());
542 ec->SetChi2(-1); //not yet implemented
543 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
544 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
545 ec->SetTOF(clust->GetTime()) ; //time-of-fligh
546 ec->SetNExMax(clust->GetNExMax()); //number of local maxima
549 TArrayI arrayParents(parentMult,parentList);
550 ec->AddLabels(arrayParents);
555 Int_t nTracks = esd->GetNumberOfTracks();
556 for (Int_t itrack = 0; itrack < nTracks; itrack++)
558 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
559 if(track->GetEMCALcluster()==iClust)
561 Double_t dEta=-999, dPhi=-999;
562 Bool_t isMatch = CalculateResidual(track, ec, dEta, dPhi);
565 // AliDebug(10, "Not good");
568 AliEMCALMatch *match = new AliEMCALMatch();
569 match->SetIndexT(itrack);
570 match->SetDistance(TMath::Sqrt(dEta*dEta+dPhi*dPhi));
571 match->SetdEta(dEta);
572 match->SetdPhi(dPhi);
573 fMatches->Add(match);
576 fMatches->Sort(kSortAscending); //Sort matched tracks from closest to furthest
577 Int_t nMatch = fMatches->GetEntries();
578 TArrayI arrayTrackMatched(nMatch);
579 for(Int_t imatch=0; imatch<nMatch; imatch++)
581 AliEMCALMatch *match = (AliEMCALMatch*)fMatches->At(imatch);
582 arrayTrackMatched[imatch] = match->GetIndexT();
585 ec->SetTrackDistance(match->GetdPhi(), match->GetdEta());
588 ec->AddTracksMatched(arrayTrackMatched);
590 //add the cluster to the esd object
591 esd->AddCaloCluster(ec);
594 delete [] newAbsIdList ;
595 delete [] newFracList ;
597 } // cycle on clusters
600 //Reset the index of matched cluster for tracks
601 //to the one in CaloCluster array
602 Int_t ncls = esd->GetNumberOfCaloClusters();
603 for(Int_t icl=0; icl<ncls; icl++)
605 AliESDCaloCluster *cluster = esd->GetCaloCluster(icl);
606 if(!cluster || !cluster->IsEMCAL()) continue;
607 TArrayI *trackIndex = cluster->GetTracksMatched();
608 for(Int_t itr=0; itr<trackIndex->GetSize(); itr++)
610 AliESDtrack *track = esd->GetTrack(trackIndex->At(itr));
611 track->SetEMCALcluster(cluster->GetID());
616 //Fill ESDCaloCluster with PID weights
617 AliEMCALPID *pid = new AliEMCALPID;
618 //pid->SetPrintInfo(kTRUE);
619 pid->SetReconstructor(kTRUE);
623 //Store EMCAL misalignment matrixes
624 FillMisalMatrixes(esd) ;
628 //==================================================================================
629 void AliEMCALReconstructor::FillMisalMatrixes(AliESDEvent* esd)const{
630 //Store EMCAL matrixes in ESD Header
632 //Check, if matrixes was already stored
633 for(Int_t sm = 0 ; sm < fGeom->GetNumberOfSuperModules(); sm++){
634 if(esd->GetEMCALMatrix(sm)!=0)
638 //Create and store matrixes
640 AliError("Can not store misal. matrixes: no gGeoManager! \n") ;
643 //Note, that owner of copied marixes will be header
644 const Int_t bufsize = 255;
646 TGeoHMatrix * m = 0x0;
647 for(Int_t sm = 0; sm < fGeom->GetNumberOfSuperModules(); sm++){
648 snprintf(path,bufsize,"/ALIC_1/XEN1_1/SMOD_%d",sm+1) ; //In Geometry modules numbered 1,2,.,5
649 if(sm >= 10) snprintf(path,bufsize,"/ALIC_1/XEN1_1/SM10_%d",sm-10+1) ;
651 if (gGeoManager->CheckPath(path)){
652 gGeoManager->cd(path);
653 m = gGeoManager->GetCurrentMatrix() ;
654 // printf("================================================= \n");
655 // printf("AliEMCALReconstructor::FixMisalMatrixes(), sm %d, \n",sm);
657 esd->SetEMCALMatrix(new TGeoHMatrix(*m),sm) ;
658 // printf("================================================= \n");
661 esd->SetEMCALMatrix(NULL,sm) ;
666 //__________________________________________________________________________
667 void AliEMCALReconstructor::ReadDigitsArrayFromTree(TTree *digitsTree) const
669 // Read the digits from the input tree
670 // See AliEMCALClusterizer::SetInput(TTree *digitsTree);
672 // Clear previous digits in the list
674 fgDigitsArr->Clear("C");
677 // It should not happen, but just in case ...
678 fgDigitsArr = new TClonesArray("AliEMCALDigit",100);
681 // Read the digits from the input tree
682 TBranch *branch = digitsTree->GetBranch("EMCAL");
684 AliError("can't get the branch with the EMCAL digits !");
688 branch->SetAddress(&fgDigitsArr);
692 //==================================================================================
693 Bool_t AliEMCALReconstructor::CalculateResidual(AliESDtrack *track, AliESDCaloCluster *cluster, Double_t &dEta, Double_t &dPhi)const
696 // calculate the residual between track and cluster
699 // If the esdFriend is available, use the TPCOuter point as the starting point of extrapolation
700 // Otherwise use the TPCInner point
701 AliExternalTrackParam *trkParam = 0;
702 const AliESDfriendTrack* friendTrack = track->GetFriendTrack();
703 if(friendTrack && friendTrack->GetTPCOut())
704 trkParam = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
706 trkParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
707 if(!trkParam) return kFALSE;
709 //Perform extrapolation
713 AliExternalTrackParam trkParamTmp (*trkParam);
714 cluster->GetPosition(clsPos);
715 TVector3 vec(clsPos[0],clsPos[1],clsPos[2]);
716 Double_t alpha = ((int)(vec.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
717 //Rotate to proper local coordinate
719 trkParamTmp.Rotate(alpha);
720 //extrapolation is done here
721 if(!AliTrackerBase::PropagateTrackToBxByBz(&trkParamTmp, vec.X(), track->GetMass(), GetRecParam()->GetExtrapolateStep(), kFALSE, 0.8, -1))
724 //Calculate the residuals
725 trkParamTmp.GetXYZ(trkPos);
727 TVector3 clsPosVec(clsPos[0],clsPos[1],clsPos[2]);
728 TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
730 Double_t clsPhi = clsPosVec.Phi();
731 if(clsPhi<0) clsPhi+=2*TMath::Pi();
732 Double_t trkPhi = trkPosVec.Phi();
733 if(trkPhi<0) trkPhi+=2*TMath::Pi();
735 dPhi = clsPhi-trkPhi;
736 dEta = clsPosVec.Eta()-trkPosVec.Eta();
742 //==================================================================================
744 AliEMCALReconstructor::AliEMCALMatch::AliEMCALMatch()
751 //default constructor
756 //==================================================================================
758 AliEMCALReconstructor::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
760 fIndexT(copy.fIndexT),
761 fDistance(copy.fDistance),
769 //==================================================================================
771 Int_t AliEMCALReconstructor::AliEMCALMatch::Compare(const TObject *obj) const
774 // Compare wrt the residual
777 AliEMCALReconstructor::AliEMCALMatch *that = (AliEMCALReconstructor::AliEMCALMatch*)obj;
779 Double_t thisDist = fDistance;//fDistance;
780 Double_t thatDist = that->fDistance;//that->GetDistance();
782 if (thisDist > thatDist) return 1;
783 else if (thisDist < thatDist) return -1;