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 "AliCDBManager.h"
48 #include "AliGRPManager.h"
50 ClassImp(AliTrackComparisonESD)
52 //________________________________________________________________________
53 AliTrackComparisonESD::AliTrackComparisonESD()
56 fESDCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
60 fOcdbPath("local:///lustre/alice/alien/alice/data/2010/OCDB"),
70 // default constructor
72 for(Int_t i=0; i<4; i++) fTransMatrix[i]=0;
76 //________________________________________________________________________
77 AliTrackComparisonESD::AliTrackComparisonESD(const char *name)
78 :AliAnalysisTask(name,""),
80 fESDCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
84 fOcdbPath("local:///lustre/alice/alien/alice/data/2010/OCDB"),
96 DefineInput(0, TChain::Class());
97 DefineOutput(0, TObjArray::Class());
99 for(Int_t i=0; i<4; i++) fTransMatrix[i]=0;
102 //________________________________________________________________________
103 AliTrackComparisonESD::~AliTrackComparisonESD() {
107 printf("AliTrackComparisonESD::~AliTrackComparisonESD");
109 if(fEMCAL) delete fEMCAL; fEMCAL=0;
110 if(fHMPID) delete fHMPID; fHMPID=0;
111 if(fTOF) delete fTOF; fTOF=0;
112 if(fOutput) fOutput->Delete();
113 //if(fOutput) delete fOutput;
114 if(fCaloUtil) delete fCaloUtil; fCaloUtil=0;
115 for(Int_t i=0; i<4; i++)
117 if(fTransMatrix[i]) {delete fTransMatrix[i];fTransMatrix[i]=0;}
121 //________________________________________________________________________
122 void AliTrackComparisonESD::ConnectInputData(Option_t *) {
126 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
128 //Printf("ERROR: Could not read chain from input slot 0");
131 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
133 //Printf("ERROR: Could not get ESDInputHandler");
136 //esdH->SetReadFriends(kTRUE);
137 //esdH->SetActiveBranches("ESDfriend");
138 fESD = esdH->GetEvent();
139 //Printf("*** CONNECTED NEW EVENT ****");
145 //________________________________________________________________________
146 void AliTrackComparisonESD::CreateOutputObjects() {
150 //OpenFile(0, "RECREATE");
151 TFile *ftmp = OpenFile(0);
152 if(!ftmp)AliError(Form("File %s not found!",ftmp->GetName()));
153 fOutput=new TObjArray(0);
154 fOutput->SetOwner(kTRUE);
156 fEMCAL = new AliTrackComparison("EMCAL","EMCAL");
157 fEMCAL->SetLayerID(20);
158 fEMCAL->SetFillAll(kFALSE);
160 fHMPID = new AliTrackComparison("HMPID","HMPID");
161 fHMPID->SetRangeDY(-5,5);
162 fHMPID->SetRangeDZ(-5,5);
163 fHMPID->SetLayerID(18);
164 fHMPID->SetFillAll(kFALSE);
166 fTOF = new AliTrackComparison("TOF","TOF");
167 fTOF->SetRangeDY(-5,5);
168 fTOF->SetRange1Pt(-1,1);
169 fTOF->SetLayerID(15);
170 fTOF->SetFillAll(kFALSE);
173 fOutput->Add(fEMCAL);
174 fOutput->Add(fHMPID);
177 Double_t rotationMatrix[4][9] = {{-0.014587, -0.999892, -0.002031, 0.999892, -0.014591, 0.001979, -0.002009, -0.002002, 0.999996},
178 {-0.014587, 0.999892, 0.002031, 0.999892, 0.014591, -0.001979, -0.002009, 0.002002, -0.999996},
179 {-0.345864, -0.938278, -0.003412, 0.938276, -0.345874, 0.003010, -0.004004, -0.002161, 0.999990},
180 {-0.345864, 0.938278, 0.003412, 0.938276, 0.345874, -0.003010, -0.004004, 0.002161, -0.999990}};
182 Double_t translationMatrix[4][3] = {{0.351659, 447.576446, 176.269742},
183 {1.062577, 446.893974, -173.728870},
184 {-154.213287, 419.306156, 176.753692},
185 {-153.018950, 418.623681, -173.243605}};
186 for(Int_t imx=0; imx<4; imx++)
188 fTransMatrix[imx] = new TGeoHMatrix();
189 fTransMatrix[imx]->SetRotation(rotationMatrix[imx]);
190 fTransMatrix[imx]->SetTranslation(translationMatrix[imx]);
191 fTransMatrix[imx]->Print();
195 fCaloUtil = new AliCalorimeterUtils();
202 //________________________________________________________________________
203 Bool_t AliTrackComparisonESD::SetupEvent() {
207 // check if something to be done
212 if (fCurrentRun == fESD->GetRunNumber())
215 fCurrentRun = fESD->GetRunNumber();
218 printf("setting run to %d\n",fCurrentRun);
219 AliCDBManager::Instance()->SetDefaultStorage(fOcdbPath.Data());
220 AliCDBManager::Instance()->SetRun(fCurrentRun);
223 if ( !TGeoGlobalMagField::Instance()->GetField() ) {
224 printf("Loading field map...\n");
225 AliGRPManager grpMan;
226 if( !grpMan.ReadGRPEntry() ) {
227 printf("Cannot get GRP entry\n");
230 if( !grpMan.SetMagField() ) {
231 printf("Problem with magnetic field setup\n");
237 printf("Loading geometry...\n");
238 AliGeomManager::LoadGeometry();
239 if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD TOF PHOS EMCAL HMPID") ) {
240 //printf("Problem with align objects\n");
242 fGeom = AliEMCALGeometry::GetInstance("EMCAL_FIRSTYEARV1");
243 printf("%s\n",fGeom->GetName());
246 printf("EMCAL geometry not loaded!\n");
252 //________________________________________________________________________
253 void AliTrackComparisonESD::Exec(Option_t *) {
256 // Loop over tracks and call Process function
258 //Printf("ERROR: fESD not available");
262 if(!SetupEvent()) return;
265 fESDfriend=static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
267 //Printf("ERROR: fESDfriend not available");
272 if ( fESDfriend->GetNumberOfTracks() <=0 ) {
273 Printf("ERROR: fESDfriend Tracks not available");
279 const AliESDVertex *vertex = fESD->GetPrimaryVertex();
280 if(!vertex) AliError("No primary vertex found!\n");
282 vertex->GetXYZ(vPos);
283 if(TMath::Abs(vPos[2])>7) return;
286 //Get EMCAL clusters and cells
287 TRefArray *clusters = new TRefArray();
288 Int_t nclusters = fESD->GetEMCALClusters(clusters);
289 AliESDCaloCells *cells = fESD->GetEMCALCells();
290 RecalClusterPos(clusters,cells);
292 // for(Int_t icl=0; icl<nclusters; icl++)
294 // AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
295 // cluster->GetPosition(pos);
296 // 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]));
302 Int_t ntracks = fESD->GetNumberOfTracks();
303 for(Int_t itr=0; itr<ntracks; itr++)
305 AliESDtrack *track = fESD->GetTrack(itr);
306 if(!track || !fESDCuts->AcceptTrack(track)) continue;
308 AliESDfriendTrack *friendTrack = fESDfriend->GetTrack(itr);
309 if(!friendTrack) continue;
310 //printf(" --- %d < %d || %p | %p -- %p \n", itr, fESDfriend->GetNumberOfTracks(), track, fESDfriend, friendTrack);
311 ProcessTOF(track,friendTrack,vPos);
312 if(nclusters>0)ProcessEMCAL(track,friendTrack,clusters,cells,vPos);
313 ProcessHMPID(track,friendTrack,vPos);
320 //________________________________________________________________________
321 void AliTrackComparisonESD::ProcessTOF(AliESDtrack *track, AliESDfriendTrack *friendTrack, Double_t *vPos){
323 // Process TPC-TOF extrapolation
326 //printf("Enter function!\n");
327 if (track->GetTOFsignal()<=0) return;
328 if (!friendTrack) return;
329 if (!friendTrack->GetTPCOut()) return;
331 AliExternalTrackParam *pTPC = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
334 const AliTrackPointArray *points=friendTrack->GetTrackPointArray();
336 Int_t npoints = points->GetNPoints();
337 if(npoints>1000) return; //the default value is more than 30000, why not -1???
341 for (Int_t ipoint=0;ipoint<npoints;ipoint++){
342 if(!points->GetPoint(point,ipoint)) continue;
343 if(AliGeomManager::VolUIDToLayer(point.GetVolumeID())==AliGeomManager::kTOF)
346 fTOF->AddTracks(pTPC,&point,track->GetMass(),track->P(),vPos);
349 //Printf("# of track points in TOF: %d!\n",counter);
353 //________________________________________________________________________
354 void AliTrackComparisonESD::ProcessEMCAL(AliESDtrack *track, AliESDfriendTrack *friendTrack, TRefArray *clusters, AliESDCaloCells *cells, Double_t *vPos){
355 if(clusters->GetEntriesFast()==0) return;
357 Double_t rEMCal = 438;
362 AliExternalTrackParam *pTPC = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
367 AliExternalTrackParam *pTest = new AliExternalTrackParam(*pTPC);
368 if(!AliTracker::PropagateTrackToBxByBz(pTest, rEMCal , track->GetMass(), 1 , kFALSE,0.99,-1)) return;
369 if(!pTest->GetXYZ(trPos)) return;
371 Double_t trPhi = TMath::ATan2(trPos[1],trPos[0])*TMath::RadToDeg();
372 //printf("trPhi = %5.3f | eta = %5.3f\n",trPhi,pTest->Eta());
373 if(trPhi<80 || trPhi>120) return;
374 if(TMath::Abs(pTest->Eta())>0.7) return;
376 AliExternalTrackParam *p0=0;
377 AliTrackPoint *p1=new AliTrackPoint();
378 Int_t nclusters = clusters->GetEntries();
379 for(Int_t icl=0; icl<nclusters; icl++)
381 AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
382 if(!cluster) continue;
383 if(fCaloUtil->ClusterContainsBadChannel("EMCAL",cluster->GetCellsAbsId(),cluster->GetNCells()) ) continue;
384 if(!fCaloUtil->CheckCellFiducialRegion(cluster,cells,NULL,0) ) continue;
386 cluster->GetPosition(clPos);
388 clsV.SetXYZ(clPos[0],clPos[1],clPos[2]);
389 Double_t alpha = ((int)(clsV.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
390 clsV.RotateZ(-alpha);
392 if(!AliTrackerBase::PropagateTrackToBxByBz(p0,clsV.X(), track->GetMass(), 1,kFALSE,0.99,-1)) continue;
393 trkV.SetXYZ(p0->GetX(),p0->GetY(),p0->GetZ());
394 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) );
402 if(clsIndex==-1) return;
403 AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(clsIndex);
404 cluster->GetPosition(clPos);
405 //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]));
406 p1->SetXYZ(clPos[0],clPos[1],clPos[2],0);
407 //printf("Found EMCAL point!\n");
408 fEMCAL->AddTracks(pTPC,p1,track->GetMass(),track->P(),vPos);
416 //________________________________________________________________________
417 void AliTrackComparisonESD::ProcessHMPID(AliESDtrack *track, AliESDfriendTrack *friendTrack, Double_t *vPos){
419 // Process TPC-TOF extrapolation
421 if (track->GetHMPIDsignal()<=0) return;
423 AliExternalTrackParam *pTPC = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
428 track->GetHMPIDmip(x,y,q,nph);
429 Double_t pHmp[3]={0}, pHmp3=0;
430 if (track->GetOuterHmpPxPyPz(pHmp))
431 pHmp3 = TMath::Sqrt(pHmp[0]*pHmp[0]+pHmp[1]*pHmp[1]+pHmp[2]*pHmp[2]);
433 ch = track->GetHMPIDcluIdx()/1000000;
435 AliHMPIDParam *pParam = AliHMPIDParam::Instance();
436 TVector3 vG = pParam->Lors2Mars(ch,x,y);
438 AliTrackPoint *p1 = new AliTrackPoint();
439 p1->SetXYZ(vG.X(),vG.Y(),vG.Z());
440 //printf("Found HMPID point!\n");
441 fHMPID->AddTracks(pTPC,p1,track->GetMass(),pHmp3,vPos);
447 //________________________________________________________________________
448 void AliTrackComparisonESD::RecalClusterPos(TRefArray *clusters, AliESDCaloCells *cells){
449 Double_t iLocal[3], iGlobal[3];
452 Int_t nclusters = clusters->GetEntries();
453 for(Int_t icl=0; icl<nclusters; icl++)
455 AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
456 UShort_t *absId = cluster->GetCellsAbsId();
457 Int_t nCells = cluster->GetNCells();
458 for(Int_t i=0;i<3;i++)cPos[i]=0;
460 for(Int_t iCell=0; iCell<nCells; iCell++)
462 Double_t cellEnergy = cells->GetCellAmplitude(absId[iCell]);
463 Double_t dist = 1.31*(log(cluster->E())+4.82+0.5);
464 fGeom->RelPosCellInSModule(absId[iCell],dist,iLocal[0],iLocal[1],iLocal[2]);
465 //fGeom->GetGlobal(iLocal,iGlobal,fGeom->GetSuperModuleNumber(absId[iCell]));
466 Int_t sm = fGeom->GetSuperModuleNumber(absId[iCell]);
467 //matrix[sm]->Print();
468 //cout<<"sm = "<<sm<<endl;
469 fTransMatrix[sm]->LocalToMaster(iLocal,iGlobal);
471 Double_t w = TMath::Max( 0., 4.5 + TMath::Log( cellEnergy / cluster->E() ));
475 for(Int_t i=0; i<3; i++ )
476 cPos[i] += (w*iGlobal[i]);
481 for(int i=0; i<3; i++ )
484 cluster->SetPosition(cPos);
487 //cluster->GetPosition(pos);
488 //printf("cluster %d pass10 pos: (%5.3f,%5.3f,%5.3f)\n",icl,pos[0],pos[1],pos[2]);
489 }//End of cluster loop
492 //________________________________________________________________________
493 void AliTrackComparisonESD::Terminate(Option_t */*option*/) {
497 AliInfo("AliTrackComparisonESD::Terminate()\n");
501 //________________________________________________________________________
502 void AliTrackComparisonESD::FinishTaskOutput(){
504 // According description in AliAnalisysTask this method is call
505 // on the slaves before sending data
508 if(!fDebugOutputPath.IsNull()) {
509 RegisterDebugOutput();
513 //________________________________________________________________________
514 Long64_t AliTrackComparisonESD::Merge(TCollection *li) {
519 //________________________________________________________________________
520 void AliTrackComparisonESD::Analyze() {
522 // Analyze the content of the task
527 //________________________________________________________________________
528 void AliTrackComparisonESD::RegisterDebugOutput(){
534 //________________________________________________________________________
535 void AliTrackComparisonESD::InitCaloUtil(){
536 cout<<"Initialize bad channel map!"<<endl;
537 fCaloUtil->InitEMCALGeometry();
538 fCaloUtil->SetNumberOfCellsFromEMCALBorder(1);
539 //fCaloUtil->SetNumberOfCellsFromPHOSBorder(2);
540 fCaloUtil->SwitchOnNoFiducialBorderInEMCALEta0();
541 fCaloUtil->SwitchOnBadChannelsRemoval();
543 fCaloUtil->SetEMCALChannelStatus(0,3,13);
544 fCaloUtil->SetEMCALChannelStatus(0,44,1);
545 fCaloUtil->SetEMCALChannelStatus(0,3,13);
546 fCaloUtil->SetEMCALChannelStatus(0,20,7);
547 fCaloUtil->SetEMCALChannelStatus(0,38,2);
549 fCaloUtil->SetEMCALChannelStatus(1,4,7);
550 fCaloUtil->SetEMCALChannelStatus(1,4,13);
551 fCaloUtil->SetEMCALChannelStatus(1,9,20);
552 fCaloUtil->SetEMCALChannelStatus(1,14,15);
553 fCaloUtil->SetEMCALChannelStatus(1,23,16);
554 fCaloUtil->SetEMCALChannelStatus(1,32,23);
555 fCaloUtil->SetEMCALChannelStatus(1,37,5);
556 fCaloUtil->SetEMCALChannelStatus(1,40,1);
557 fCaloUtil->SetEMCALChannelStatus(1,40,2);
558 fCaloUtil->SetEMCALChannelStatus(1,40,5);
559 fCaloUtil->SetEMCALChannelStatus(1,41,0);
560 fCaloUtil->SetEMCALChannelStatus(1,41,1);
561 fCaloUtil->SetEMCALChannelStatus(1,41,2);
562 fCaloUtil->SetEMCALChannelStatus(1,41,4);
564 fCaloUtil->SetEMCALChannelStatus(2,14,15);
565 fCaloUtil->SetEMCALChannelStatus(2,18,16);
566 fCaloUtil->SetEMCALChannelStatus(2,18,17);
567 fCaloUtil->SetEMCALChannelStatus(2,18,18);
568 fCaloUtil->SetEMCALChannelStatus(2,18,20);
569 fCaloUtil->SetEMCALChannelStatus(2,18,21);
570 fCaloUtil->SetEMCALChannelStatus(2,18,23);
571 fCaloUtil->SetEMCALChannelStatus(2,19,16);
572 fCaloUtil->SetEMCALChannelStatus(2,19,17);
573 fCaloUtil->SetEMCALChannelStatus(2,19,19);
574 fCaloUtil->SetEMCALChannelStatus(2,19,20);
575 fCaloUtil->SetEMCALChannelStatus(2,19,21);
576 fCaloUtil->SetEMCALChannelStatus(2,19,22);
578 fCaloUtil->SetEMCALChannelStatus(3,4,7);
580 fCaloUtil->Print("");
581 cout<<"Done initialization!"<<endl;