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"
41 #include "TTimeStamp.h"
42 #include "AliHMPIDParam.h"
43 //#include <TGeoHMatrix>
44 #include "AliGeomManager.h"
45 //#include "AliCDBManager.h"
46 //#include "AliGRPManager.h"
48 ClassImp(AliTrackComparisonESD)
50 //________________________________________________________________________
51 AliTrackComparisonESD::AliTrackComparisonESD()
54 fESDCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
58 // fOcdbPath("local:///lustre/alice/alien/alice/data/2010/OCDB"),
69 // default constructor
71 for(Int_t i=0; i<4; i++) fTransMatrix[i]=0;
75 //________________________________________________________________________
76 AliTrackComparisonESD::AliTrackComparisonESD(const char *name)
77 :AliAnalysisTask(name,""),
79 fESDCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
83 // 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");
108 if(fOutput) delete fOutput; fOutput=0;
109 if(fEMCAL) delete fEMCAL; fEMCAL=0;
110 if(fHMPID) delete fHMPID; fHMPID=0;
111 if(fTOF) delete fTOF; fTOF=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();
195 //________________________________________________________________________
196 Bool_t AliTrackComparisonESD::SetupEvent() {
200 // check if something to be done
205 if (fCurrentRun == fESD->GetRunNumber())
208 fCurrentRun = fESD->GetRunNumber();
211 // printf("setting run to %d\n",fCurrentRun);
212 // AliCDBManager::Instance()->SetDefaultStorage(fOcdbPath.Data());
213 // AliCDBManager::Instance()->SetRun(fCurrentRun);
216 // if ( !TGeoGlobalMagField::Instance()->GetField() ) {
217 // printf("Loading field map...\n");
218 // AliGRPManager grpMan;
219 // if( !grpMan.ReadGRPEntry() ) {
220 // printf("Cannot get GRP entry\n");
223 // if( !grpMan.SetMagField() ) {
224 // printf("Problem with magnetic field setup\n");
230 // printf("Loading geometry...\n");
231 // AliGeomManager::LoadGeometry();
232 // if( !AliGeomManager::ApplyAlignObjsFromCDB("GRP ITS TPC TRD TOF PHOS EMCAL HMPID") ) {
233 // //printf("Problem with align objects\n");
235 fGeom = AliEMCALGeometry::GetInstance("EMCAL_FIRSTYEARV1");
236 printf("%s\n",fGeom->GetName());
239 printf("EMCAL geometry not loaded!\n");
245 //________________________________________________________________________
246 void AliTrackComparisonESD::Exec(Option_t *) {
249 // Loop over tracks and call Process function
251 //Printf("ERROR: fESD not available");
255 if(!SetupEvent()) return;
258 fESDfriend=static_cast<AliESDfriend*>(fESD->FindListObject("AliESDfriend"));
260 //Printf("ERROR: fESDfriend not available");
265 if ( fESDfriend->GetNumberOfTracks() <=0 ) {
266 //Printf("ERROR: fESDfriend Tracks not available");
272 const AliESDVertex *vertex = fESD->GetPrimaryVertex();
273 if(!vertex) AliError("No primary vertex found!\n");
275 vertex->GetXYZ(vPos);
276 if(TMath::Abs(vPos[2])>7) return;
279 //Get EMCAL clusters and cells
280 TRefArray *clusters = new TRefArray();
281 Int_t nclusters = fESD->GetEMCALClusters(clusters);
282 AliESDCaloCells *cells = fESD->GetEMCALCells();
283 RecalClusterPos(clusters,cells);
285 // for(Int_t icl=0; icl<nclusters; icl++)
287 // AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
288 // cluster->GetPosition(pos);
289 // 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]));
295 Int_t ntracks = fESD->GetNumberOfTracks();
296 for(Int_t itr=0; itr<ntracks; itr++)
298 AliESDtrack *track = fESD->GetTrack(itr);
299 if(!track || !fESDCuts->AcceptTrack(track)) continue;
301 AliESDfriendTrack *friendTrack = fESDfriend->GetTrack(itr);
302 if(!friendTrack) continue;
303 //printf(" --- %d < %d || %p | %p -- %p \n", itr, fESDfriend->GetNumberOfTracks(), track, fESDfriend, friendTrack);
304 ProcessTOF(track,friendTrack,vPos);
305 if(nclusters>0)ProcessEMCAL(track,friendTrack,clusters,vPos);
306 ProcessHMPID(track,friendTrack,vPos);
313 //________________________________________________________________________
314 void AliTrackComparisonESD::ProcessTOF(AliESDtrack *track, AliESDfriendTrack *friendTrack, Double_t *vPos){
316 // Process TPC-TOF extrapolation
319 //printf("Enter function!\n");
320 if (track->GetTOFsignal()<=0) return;
321 if (!friendTrack) return;
322 if (!friendTrack->GetTPCOut()) return;
324 AliExternalTrackParam *pTPC = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
327 const AliTrackPointArray *points=friendTrack->GetTrackPointArray();
329 Int_t npoints = points->GetNPoints();
330 if(npoints>1000) return; //the default value is more than 30000, why not -1???
334 for (Int_t ipoint=0;ipoint<npoints;ipoint++){
335 //cout<<"(npoints,ipoint) = ("<<npoints<<","<<ipoint<<")"<<endl;
336 if(!points->GetPoint(point,ipoint)) continue;
340 //Float_t r=TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
342 //printf("fVolumeID %d | LayerID %d\n",point.GetVolumeID(),AliGeomManager::VolUIDToLayer(point.GetVolumeID()));
344 //if (r<350) continue;
345 //if (r>400) continue;
346 //cout<<"r="<<r<<endl;
347 if(AliGeomManager::VolUIDToLayer(point.GetVolumeID())==AliGeomManager::kTOF)
350 fTOF->AddTracks(pTPC,&point,track->GetMass(),track->P(),vPos);
353 //Printf("# of track points in TOF: %d!\n",counter);
356 //________________________________________________________________________
357 void AliTrackComparisonESD::ProcessEMCAL(AliESDtrack *track, AliESDfriendTrack *friendTrack, TRefArray *clusters, Double_t *vPos){
358 if(clusters->GetEntriesFast()==0) return;
360 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 AliExternalTrackParam *p0=0;
372 AliTrackPoint *p1=new AliTrackPoint();
373 Int_t nclusters = clusters->GetEntries();
374 for(Int_t icl=0; icl<nclusters; icl++)
376 AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
377 if(!cluster) continue;
378 cluster->GetPosition(clPos);
379 if( TMath::Abs(clPos[0]-trPos[0])>fCutX || TMath::Abs(clPos[1]-trPos[1])>fCutY || TMath::Abs(clPos[2]-trPos[2]>fCutZ) ) continue;
382 //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]));
383 p1->SetXYZ(clPos[0],clPos[1],clPos[2],0);
384 //printf("Found EMCAL point!\n");
385 fEMCAL->AddTracks(p0,p1,track->GetMass(),cluster->E(),vPos);
392 //________________________________________________________________________
393 void AliTrackComparisonESD::ProcessHMPID(AliESDtrack *track, AliESDfriendTrack *friendTrack, Double_t *vPos){
395 // Process TPC-TOF extrapolation
397 if (track->GetHMPIDsignal()<=0) return;
399 AliExternalTrackParam *pTPC = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
404 track->GetHMPIDmip(x,y,q,nph);
405 Double_t pHmp[3]={0}, pHmp3=0;
406 if (track->GetOuterHmpPxPyPz(pHmp))
407 pHmp3 = TMath::Sqrt(pHmp[0]*pHmp[0]+pHmp[1]*pHmp[1]+pHmp[2]*pHmp[2]);
409 ch = track->GetHMPIDcluIdx()/1000000;
411 AliHMPIDParam *pParam = AliHMPIDParam::Instance();
412 TVector3 vG = pParam->Lors2Mars(ch,x,y);
414 AliTrackPoint *p1 = new AliTrackPoint();
415 p1->SetXYZ(vG.X(),vG.Y(),vG.Z());
416 //printf("Found HMPID point!\n");
417 fHMPID->AddTracks(pTPC,p1,track->GetMass(),pHmp3,vPos);
422 //________________________________________________________________________
423 void AliTrackComparisonESD::RecalClusterPos(TRefArray *clusters, AliESDCaloCells *cells){
424 Double_t iLocal[3], iGlobal[3];
427 Int_t nclusters = clusters->GetEntries();
428 for(Int_t icl=0; icl<nclusters; icl++)
430 AliESDCaloCluster *cluster = (AliESDCaloCluster*) clusters->At(icl);
431 UShort_t *absId = cluster->GetCellsAbsId();
432 Int_t nCells = cluster->GetNCells();
433 for(Int_t i=0;i<3;i++)cPos[i]=0;
435 for(Int_t iCell=0; iCell<nCells; iCell++)
437 Double_t cellEnergy = cells->GetCellAmplitude(absId[iCell]);
438 Double_t dist = 1.31*(log(cluster->E())+4.82+0.5);
439 fGeom->RelPosCellInSModule(absId[iCell],dist,iLocal[0],iLocal[1],iLocal[2]);
440 //fGeom->GetGlobal(iLocal,iGlobal,fGeom->GetSuperModuleNumber(absId[iCell]));
441 Int_t sm = fGeom->GetSuperModuleNumber(absId[iCell]);
442 //matrix[sm]->Print();
443 //cout<<"sm = "<<sm<<endl;
444 fTransMatrix[sm]->LocalToMaster(iLocal,iGlobal);
446 Double_t w = TMath::Max( 0., 4.5 + TMath::Log( cellEnergy / cluster->E() ));
450 for(Int_t i=0; i<3; i++ )
451 cPos[i] += (w*iGlobal[i]);
456 for(int i=0; i<3; i++ )
459 cluster->SetPosition(cPos);
462 //cluster->GetPosition(pos);
463 //printf("cluster %d pass10 pos: (%5.3f,%5.3f,%5.3f)\n",icl,pos[0],pos[1],pos[2]);
464 }//End of cluster loop
467 //________________________________________________________________________
468 void AliTrackComparisonESD::Terminate(Option_t */*option*/) {
472 AliInfo("AliTrackComparisonESD::Terminate()\n");
476 //________________________________________________________________________
477 void AliTrackComparisonESD::FinishTaskOutput(){
479 // According description in AliAnalisysTask this method is call
480 // on the slaves before sending data
483 if(!fDebugOutputPath.IsNull()) {
484 RegisterDebugOutput();
488 //________________________________________________________________________
489 Long64_t AliTrackComparisonESD::Merge(TCollection *li) {
494 //________________________________________________________________________
495 void AliTrackComparisonESD::Analyze() {
497 // Analyze the content of the task
502 //________________________________________________________________________
503 void AliTrackComparisonESD::RegisterDebugOutput(){