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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // ANALYSIS task to perrorm TPC calibration //
22 ///////////////////////////////////////////////////////////////////////////////
23 #include "AliTrackComparisonESD.h"
24 #include "AliTrackComparison.h"
26 #include "AliESDEvent.h"
27 #include "AliESDfriend.h"
28 #include "AliESDVertex.h"
29 #include "AliESDtrack.h"
30 #include "AliESDfriendTrack.h"
31 #include "AliExternalTrackParam.h"
32 #include "AliTrackPointArray.h"
33 #include "AliESDtrackCuts.h"
34 #include "AliTracker.h"
35 #include "AliESDCaloCluster.h"
36 #include "AliESDInputHandler.h"
37 #include "AliAnalysisManager.h"
38 #include "AliEMCALGeometry.h"
39 #include "AliCalorimeterUtils.h"
40 #include "AliESDCaloCells.h"
43 #include "TTimeStamp.h"
44 #include "AliHMPIDParam.h"
45 //#include <TGeoHMatrix>
46 #include "AliGeomManager.h"
47 #include "AliGRPManager.h"
49 ClassImp(AliTrackComparisonESD)
51 //________________________________________________________________________
52 AliTrackComparisonESD::AliTrackComparisonESD()
55 fESDCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
68 // default constructor
70 for(Int_t i=0; i<4; i++) fTransMatrix[i]=0;
74 //________________________________________________________________________
75 AliTrackComparisonESD::AliTrackComparisonESD(const char *name)
76 :AliAnalysisTask(name,""),
78 fESDCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
93 DefineInput(0, TChain::Class());
94 DefineOutput(0, TObjArray::Class());
96 for(Int_t i=0; i<4; i++) fTransMatrix[i]=0;
99 //________________________________________________________________________
100 AliTrackComparisonESD::~AliTrackComparisonESD() {
104 printf("AliTrackComparisonESD::~AliTrackComparisonESD");
106 if(fEMCAL) delete fEMCAL; fEMCAL=0;
107 if(fHMPID) delete fHMPID; fHMPID=0;
108 if(fTOF) delete fTOF; fTOF=0;
109 if(fOutput) fOutput->Delete();
110 //if(fOutput) delete fOutput;
111 if(fCaloUtil) delete fCaloUtil; fCaloUtil=0;
112 for(Int_t i=0; i<4; i++)
114 if(fTransMatrix[i]) {delete fTransMatrix[i];fTransMatrix[i]=0;}
118 //________________________________________________________________________
119 void AliTrackComparisonESD::ConnectInputData(Option_t *) {
123 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
125 //Printf("ERROR: Could not read chain from input slot 0");
128 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
130 //Printf("ERROR: Could not get ESDInputHandler");
133 //esdH->SetReadFriends(kTRUE);
134 //esdH->SetActiveBranches("ESDfriend");
135 fESD = esdH->GetEvent();
136 //Printf("*** CONNECTED NEW EVENT ****");
142 //________________________________________________________________________
143 void AliTrackComparisonESD::CreateOutputObjects() {
147 //OpenFile(0, "RECREATE");
148 TFile *ftmp = OpenFile(0);
149 if(!ftmp)AliError(Form("File %s not found!",ftmp->GetName()));
150 fOutput=new TObjArray(0);
151 fOutput->SetOwner(kTRUE);
153 fEMCAL = new AliTrackComparison("EMCAL","EMCAL");
154 fEMCAL->SetLayerID(20);
155 fEMCAL->SetFillAll(kFALSE);
157 fHMPID = new AliTrackComparison("HMPID","HMPID");
158 fHMPID->SetRangeDY(-5,5);
159 fHMPID->SetRangeDZ(-5,5);
160 fHMPID->SetLayerID(18);
161 fHMPID->SetFillAll(kFALSE);
163 fTOF = new AliTrackComparison("TOF","TOF");
164 fTOF->SetRangeDY(-5,5);
165 fTOF->SetRange1Pt(-1,1);
166 fTOF->SetLayerID(15);
167 fTOF->SetFillAll(kFALSE);
170 fOutput->Add(fEMCAL);
171 fOutput->Add(fHMPID);
174 Double_t rotationMatrix[4][9] = {{-0.014587, -0.999892, -0.002031, 0.999892, -0.014591, 0.001979, -0.002009, -0.002002, 0.999996},
175 {-0.014587, 0.999892, 0.002031, 0.999892, 0.014591, -0.001979, -0.002009, 0.002002, -0.999996},
176 {-0.345864, -0.938278, -0.003412, 0.938276, -0.345874, 0.003010, -0.004004, -0.002161, 0.999990},
177 {-0.345864, 0.938278, 0.003412, 0.938276, 0.345874, -0.003010, -0.004004, 0.002161, -0.999990}};
179 Double_t translationMatrix[4][3] = {{0.351659, 447.576446, 176.269742},
180 {1.062577, 446.893974, -173.728870},
181 {-154.213287, 419.306156, 176.753692},
182 {-153.018950, 418.623681, -173.243605}};
183 for(Int_t imx=0; imx<4; imx++)
185 fTransMatrix[imx] = new TGeoHMatrix();
186 fTransMatrix[imx]->SetRotation(rotationMatrix[imx]);
187 fTransMatrix[imx]->SetTranslation(translationMatrix[imx]);
188 fTransMatrix[imx]->Print();
192 fCaloUtil = new AliCalorimeterUtils();
199 //________________________________________________________________________
200 Bool_t AliTrackComparisonESD::SetupEvent() {
204 // check if something to be done
209 if (fCurrentRun == fESD->GetRunNumber())
212 fCurrentRun = fESD->GetRunNumber();
217 //________________________________________________________________________
218 void AliTrackComparisonESD::Exec(Option_t *) {
221 // Loop over tracks and call Process function
223 //Printf("ERROR: fESD not available");
227 if(!SetupEvent()) return;
230 fESDfriend=static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
232 //Printf("ERROR: fESDfriend not available");
237 if ( fESDfriend->GetNumberOfTracks() <=0 ) {
238 Printf("ERROR: fESDfriend Tracks not available");
244 const AliESDVertex *vertex = fESD->GetPrimaryVertex();
245 if(!vertex) AliError("No primary vertex found!\n");
247 vertex->GetXYZ(vPos);
248 if(TMath::Abs(vPos[2])>7) return;
251 //Get EMCAL clusters and cells
252 TRefArray *clusters = new TRefArray();
253 Int_t nclusters = fESD->GetEMCALClusters(clusters);
254 AliESDCaloCells *cells = fESD->GetEMCALCells();
255 // RecalClusterPos(clusters,cells);
257 // for(Int_t icl=0; icl<nclusters; icl++)
259 // AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
260 // cluster->GetPosition(pos);
261 // printf("cluster %d pass00 pos: (%5.3f,%5.3f,%5.3f,%5.3f)\n",icl,pos[0],pos[1],pos[2],TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]));
267 Int_t ntracks = fESD->GetNumberOfTracks();
268 for(Int_t itr=0; itr<ntracks; itr++)
270 AliESDtrack *track = fESD->GetTrack(itr);
271 if(!track || !fESDCuts->AcceptTrack(track)) continue;
273 AliESDfriendTrack *friendTrack = fESDfriend->GetTrack(itr);
274 if(!friendTrack) continue;
275 //printf(" --- %d < %d || %p | %p -- %p \n", itr, fESDfriend->GetNumberOfTracks(), track, fESDfriend, friendTrack);
276 ProcessTOF(track,friendTrack,vPos);
277 if(nclusters>0)ProcessEMCAL(track,friendTrack,clusters,cells,vPos);
278 ProcessHMPID(track,friendTrack,vPos);
285 //________________________________________________________________________
286 void AliTrackComparisonESD::ProcessTOF(AliESDtrack *track, AliESDfriendTrack *friendTrack, Double_t *vPos){
288 // Process TPC-TOF extrapolation
291 //printf("Enter function!\n");
292 if (track->GetTOFsignal()<=0) return;
293 if (!friendTrack) return;
294 if (!friendTrack->GetTPCOut()) return;
296 AliExternalTrackParam *pTPC = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
299 const AliTrackPointArray *points=friendTrack->GetTrackPointArray();
301 Int_t npoints = points->GetNPoints();
302 if(npoints>1000) return; //the default value is more than 30000, why not -1???
306 for (Int_t ipoint=0;ipoint<npoints;ipoint++){
307 if(!points->GetPoint(point,ipoint)) continue;
308 if(AliGeomManager::VolUIDToLayer(point.GetVolumeID())==AliGeomManager::kTOF)
311 fTOF->AddTracks(pTPC,&point,track->GetMass(),track->P(),vPos);
314 //Printf("# of track points in TOF: %d!\n",counter);
318 //________________________________________________________________________
319 void AliTrackComparisonESD::ProcessEMCAL(AliESDtrack *track, AliESDfriendTrack *friendTrack, TRefArray *clusters, AliESDCaloCells *cells, Double_t *vPos){
320 if(clusters->GetEntriesFast()==0) return;
322 Double_t rEMCal = 438;
327 AliExternalTrackParam *pTPC = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
332 AliExternalTrackParam *pTest = new AliExternalTrackParam(*pTPC);
333 if(!AliTracker::PropagateTrackToBxByBz(pTest, rEMCal , track->GetMass(), 1 , kFALSE,0.99,-1)) return;
334 if(!pTest->GetXYZ(trPos)) return;
336 Double_t trPhi = TMath::ATan2(trPos[1],trPos[0])*TMath::RadToDeg();
337 //printf("trPhi = %5.3f | eta = %5.3f\n",trPhi,pTest->Eta());
338 if(trPhi<80 || trPhi>120) return;
339 if(TMath::Abs(pTest->Eta())>0.7) return;
341 AliExternalTrackParam *p0=0;
342 AliTrackPoint *p1=new AliTrackPoint();
343 Int_t nclusters = clusters->GetEntries();
344 for(Int_t icl=0; icl<nclusters; icl++)
346 AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
347 if(!cluster) continue;
348 if(fCaloUtil->ClusterContainsBadChannel("EMCAL",cluster->GetCellsAbsId(),cluster->GetNCells()) ) continue;
349 if(!fCaloUtil->CheckCellFiducialRegion(cluster,cells,NULL,0) ) continue;
351 cluster->GetPosition(clPos);
353 clsV.SetXYZ(clPos[0],clPos[1],clPos[2]);
354 Double_t alpha = ((int)(clsV.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
355 clsV.RotateZ(-alpha);
357 if(!AliTrackerBase::PropagateTrackToBxByBz(p0,clsV.X(), track->GetMass(), 1,kFALSE,0.99,-1)) continue;
358 trkV.SetXYZ(p0->GetX(),p0->GetY(),p0->GetZ());
359 Double_t dist = TMath::Sqrt( TMath::Power(clsV.X()-trkV.X(),2)+TMath::Power(clsV.Y()-trkV.Y(),2)+TMath::Power(clsV.Z()-trkV.Z(),2) );
367 if(clsIndex==-1) return;
368 AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(clsIndex);
369 cluster->GetPosition(clPos);
370 //printf("cluster pos: (%5.3f,%5.3f,%5.3f,%5.3f)\n",clPos[0],clPos[1],clPos[2],TMath::Sqrt(clPos[0]*clPos[0]+clPos[1]*clPos[1]));
371 p1->SetXYZ(clPos[0],clPos[1],clPos[2],0);
372 //printf("Found EMCAL point!\n");
373 fEMCAL->AddTracks(pTPC,p1,track->GetMass(),track->P(),vPos);
381 //________________________________________________________________________
382 void AliTrackComparisonESD::ProcessHMPID(AliESDtrack *track, AliESDfriendTrack *friendTrack, Double_t *vPos){
384 // Process TPC-TOF extrapolation
386 if (track->GetHMPIDsignal()<=0) return;
388 AliExternalTrackParam *pTPC = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
393 track->GetHMPIDmip(x,y,q,nph);
394 Double_t pHmp[3]={0}, pHmp3=0;
395 if (track->GetOuterHmpPxPyPz(pHmp))
396 pHmp3 = TMath::Sqrt(pHmp[0]*pHmp[0]+pHmp[1]*pHmp[1]+pHmp[2]*pHmp[2]);
398 ch = track->GetHMPIDcluIdx()/1000000;
400 AliHMPIDParam *pParam = AliHMPIDParam::Instance();
401 TVector3 vG = pParam->Lors2Mars(ch,x,y);
403 AliTrackPoint *p1 = new AliTrackPoint();
404 p1->SetXYZ(vG.X(),vG.Y(),vG.Z());
405 //printf("Found HMPID point!\n");
406 fHMPID->AddTracks(pTPC,p1,track->GetMass(),pHmp3,vPos);
412 //________________________________________________________________________
413 void AliTrackComparisonESD::RecalClusterPos(TRefArray *clusters, AliESDCaloCells *cells){
417 Double_t iLocal[3], iGlobal[3];
420 Int_t nclusters = clusters->GetEntries();
421 for(Int_t icl=0; icl<nclusters; icl++)
423 AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
424 UShort_t *absId = cluster->GetCellsAbsId();
425 Int_t nCells = cluster->GetNCells();
426 for(Int_t i=0;i<3;i++)cPos[i]=0;
428 for(Int_t iCell=0; iCell<nCells; iCell++)
430 Double_t cellEnergy = cells->GetCellAmplitude(absId[iCell]);
431 Double_t dist = 1.31*(log(cluster->E())+4.82+0.5);
432 fGeom->RelPosCellInSModule(absId[iCell],dist,iLocal[0],iLocal[1],iLocal[2]);
433 //fGeom->GetGlobal(iLocal,iGlobal,fGeom->GetSuperModuleNumber(absId[iCell]));
434 Int_t sm = fGeom->GetSuperModuleNumber(absId[iCell]);
435 //matrix[sm]->Print();
436 //cout<<"sm = "<<sm<<endl;
437 fTransMatrix[sm]->LocalToMaster(iLocal,iGlobal);
439 Double_t w = TMath::Max( 0., 4.5 + TMath::Log( cellEnergy / cluster->E() ));
443 for(Int_t i=0; i<3; i++ )
444 cPos[i] += (w*iGlobal[i]);
449 for(int i=0; i<3; i++ )
452 cluster->SetPosition(cPos);
455 //cluster->GetPosition(pos);
456 //printf("cluster %d pass10 pos: (%5.3f,%5.3f,%5.3f)\n",icl,pos[0],pos[1],pos[2]);
457 }//End of cluster loop
460 //________________________________________________________________________
461 void AliTrackComparisonESD::Terminate(Option_t */*option*/) {
465 AliInfo("AliTrackComparisonESD::Terminate()\n");
469 //________________________________________________________________________
470 void AliTrackComparisonESD::FinishTaskOutput(){
472 // According description in AliAnalisysTask this method is call
473 // on the slaves before sending data
476 if(!fDebugOutputPath.IsNull()) {
477 RegisterDebugOutput();
481 //________________________________________________________________________
482 Long64_t AliTrackComparisonESD::Merge(TCollection *li) {
487 //________________________________________________________________________
488 void AliTrackComparisonESD::Analyze() {
490 // Analyze the content of the task
495 //________________________________________________________________________
496 void AliTrackComparisonESD::RegisterDebugOutput(){
502 //________________________________________________________________________
503 void AliTrackComparisonESD::InitCaloUtil(){
504 cout<<"Initialize bad channel map!"<<endl;
505 fCaloUtil->InitEMCALGeometry();
506 fCaloUtil->SetNumberOfCellsFromEMCALBorder(1);
507 //fCaloUtil->SetNumberOfCellsFromPHOSBorder(2);
508 fCaloUtil->SwitchOnNoFiducialBorderInEMCALEta0();
509 fCaloUtil->SwitchOnBadChannelsRemoval();
511 fCaloUtil->SetEMCALChannelStatus(0,3,13);
512 fCaloUtil->SetEMCALChannelStatus(0,44,1);
513 fCaloUtil->SetEMCALChannelStatus(0,3,13);
514 fCaloUtil->SetEMCALChannelStatus(0,20,7);
515 fCaloUtil->SetEMCALChannelStatus(0,38,2);
517 fCaloUtil->SetEMCALChannelStatus(1,4,7);
518 fCaloUtil->SetEMCALChannelStatus(1,4,13);
519 fCaloUtil->SetEMCALChannelStatus(1,9,20);
520 fCaloUtil->SetEMCALChannelStatus(1,14,15);
521 fCaloUtil->SetEMCALChannelStatus(1,23,16);
522 fCaloUtil->SetEMCALChannelStatus(1,32,23);
523 fCaloUtil->SetEMCALChannelStatus(1,37,5);
524 fCaloUtil->SetEMCALChannelStatus(1,40,1);
525 fCaloUtil->SetEMCALChannelStatus(1,40,2);
526 fCaloUtil->SetEMCALChannelStatus(1,40,5);
527 fCaloUtil->SetEMCALChannelStatus(1,41,0);
528 fCaloUtil->SetEMCALChannelStatus(1,41,1);
529 fCaloUtil->SetEMCALChannelStatus(1,41,2);
530 fCaloUtil->SetEMCALChannelStatus(1,41,4);
532 fCaloUtil->SetEMCALChannelStatus(2,14,15);
533 fCaloUtil->SetEMCALChannelStatus(2,18,16);
534 fCaloUtil->SetEMCALChannelStatus(2,18,17);
535 fCaloUtil->SetEMCALChannelStatus(2,18,18);
536 fCaloUtil->SetEMCALChannelStatus(2,18,20);
537 fCaloUtil->SetEMCALChannelStatus(2,18,21);
538 fCaloUtil->SetEMCALChannelStatus(2,18,23);
539 fCaloUtil->SetEMCALChannelStatus(2,19,16);
540 fCaloUtil->SetEMCALChannelStatus(2,19,17);
541 fCaloUtil->SetEMCALChannelStatus(2,19,19);
542 fCaloUtil->SetEMCALChannelStatus(2,19,20);
543 fCaloUtil->SetEMCALChannelStatus(2,19,21);
544 fCaloUtil->SetEMCALChannelStatus(2,19,22);
546 fCaloUtil->SetEMCALChannelStatus(3,4,7);
548 fCaloUtil->Print("");
549 cout<<"Done initialization!"<<endl;