2 // This class is the task for connecting together
3 // MC information and the RC information
5 // The task is a wrapper over two components
7 // AliESDRecInfoMaker.h
17 #include <TTreeStream.h>
18 #include <AliAnalysisManager.h>
19 #include <AliESDInputHandler.h>
21 #include "AliMCEvent.h"
22 #include "AliMCEventHandler.h"
25 #include "AliMCTrackingTestTask.h"
26 #include "AliGenInfoMaker.h"
30 #include "AliMCInfo.h"
31 #include "AliComparisonObject.h"
32 #include "AliESDRecInfo.h"
33 #include "AliTPCParamSR.h"
34 #include "AliTracker.h"
41 ClassImp(AliMCTrackingTestTask)
43 //________________________________________________________________________
44 AliMCTrackingTestTask::AliMCTrackingTestTask() :
46 fMCinfo(0), //! MC event handler
54 // Default constructor (should not be used)
58 AliMCTrackingTestTask::AliMCTrackingTestTask(const AliMCTrackingTestTask& /*info*/) :
60 fMCinfo(0), //! MC event handler
69 // Default constructor
75 //________________________________________________________________________
76 AliMCTrackingTestTask::AliMCTrackingTestTask(const char *name) :
77 AliAnalysisTask(name, "AliMCTrackingTestTask"),
78 fMCinfo(0), //! MC event handler
88 // Input slot #0 works with a TChain
89 DefineInput(0, TChain::Class());
90 // Output slot #0 writes into a TList
91 DefineOutput(0, TObjArray::Class());
96 AliMCTrackingTestTask::~AliMCTrackingTestTask(){
100 if (fDebugLevel>0) printf("AliMCTrackingTestTask::~AliMCTrackingTestTask\n");
101 if (fDebugStreamer) delete fDebugStreamer;
106 //________________________________________________________________________
107 void AliMCTrackingTestTask::ConnectInputData(Option_t *)
110 // Connect the input data
113 cout << "AnalysisTaskTPCCluster::ConnectInputData()" << endl;
115 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
117 //Printf("ERROR: Could not read chain from input slot 0");
120 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
122 //Printf("ERROR: Could not get ESDInputHandler");
125 fESD = esdH->GetEvent();
126 //Printf("*** CONNECTED NEW EVENT ****");
129 AliMCEventHandler* mcinfo = (AliMCEventHandler*) (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
130 mcinfo->SetReadTR(kTRUE);
132 fMCinfo = mcinfo->MCEvent();
142 //________________________________________________________________________
143 void AliMCTrackingTestTask::CreateOutputObjects()
146 // Connect the output objects
149 cout << "AnalysisTaskTPCCluster::CreateOutputObjects()" << endl;
154 //________________________________________________________________________
155 void AliMCTrackingTestTask::Exec(Option_t *) {
157 // Execute analysis for current event
161 cout << "AliMCTrackingTestTask::Exec()" << endl;
164 // If MC has been connected
167 cout << "Not MC info\n" << endl;
179 //________________________________________________________________________
180 void AliMCTrackingTestTask::Terminate(Option_t *) {
185 printf("AliMCTrackingTestTask: Terminate() \n");
187 if (fDebugLevel>0) printf("AliMCtrackingTestTask::Terminate\n");
188 if (fDebugStreamer) delete fDebugStreamer;
195 TTreeSRedirector *AliMCTrackingTestTask::GetDebugStreamer(){
197 // Get Debug streamer
198 // In case debug streamer not yet initialized and StreamLevel>0 create new one
200 if (fStreamLevel==0) return 0;
201 if (fDebugStreamer) return fDebugStreamer;
204 dsName+="Debug.root";
205 dsName.ReplaceAll(" ","");
206 fDebugStreamer = new TTreeSRedirector(dsName.Data());
207 return fDebugStreamer;
215 AliExternalTrackParam * AliMCTrackingTestTask::MakeTrack(const AliTrackReference* ref, TParticle*part)
218 // Make track out of the track ref
219 // part - TParticle used to determine chargr
220 // the covariance matrix - equal 0 - starting from ideal MC position
221 Double_t xyz[3]={ref->X(),ref->Y(),ref->Z()};
222 Double_t pxyz[3]={ref->Px(),ref->Py(),ref->Pz()};
224 for (Int_t i=0; i<21;i++) cv[i]=0;
225 if (!part->GetPDG()) return 0;
226 AliExternalTrackParam * param = new AliExternalTrackParam(xyz,pxyz,cv,TMath::Nint(part->GetPDG()->Charge()/3.));
230 Bool_t AliMCTrackingTestTask::PropagateToPoint(AliExternalTrackParam *param, Double_t *xyz, Double_t mass, Float_t step){
232 // Propagate track to point xyz using
233 // AliTracker::PropagateTo functionality
235 // param - track parameters
236 // xyz - position to propagate
237 // mass - particle mass
238 // step - step to be used
239 Double_t radius=TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
240 AliTracker::PropagateTrackTo(param, radius+step, mass, step, kTRUE,0.8);
241 AliTracker::PropagateTrackTo(param, radius+0.5, mass, 0.5, kTRUE,0.8);
242 Double_t sxyz[3]={0,0,0};
243 AliESDVertex vertex(xyz,sxyz);
244 Bool_t isOK = param->PropagateToDCA(&vertex,AliTracker::GetBz(),10);
249 void AliMCTrackingTestTask::ProcessMCInfo(){
254 TParticle * particle= new TParticle;
255 TClonesArray * trefs = new TClonesArray("AliTrackReference");
256 const Double_t kPcut=0.1;
261 Int_t npart = fMCinfo->GetNumberOfTracks();
262 if (npart==0) return;
263 Double_t vertex[4]={0,0,0,0};
264 fMCinfo->GetParticleAndTR(0, particle, trefs);
266 vertex[0]=particle->Vx();
267 vertex[1]=particle->Vy();
268 vertex[2]=particle->Vz();
269 vertex[3]=particle->R();
274 for (Int_t ipart=0;ipart<npart;ipart++){
275 Int_t status = fMCinfo->GetParticleAndTR(ipart, particle, trefs);
276 if (status<0) continue;
277 if (!particle) continue;
278 if (!trefs) continue;
279 Int_t nref = trefs->GetEntries();
280 if (nref<5) continue;
281 AliTrackReference * tpcIn=0;
282 AliTrackReference * tpcOut=0;
283 AliTrackReference * trdIn=0;
284 AliTrackReference * trdOut=0;
285 AliTrackReference * itsIn=0;
286 AliTrackReference * itsOut=0;
289 for (Int_t iref=0;iref<nref;iref++){
290 AliTrackReference * ref = (AliTrackReference*)trefs->At(iref);
293 Float_t dir = ref->X()*ref->Px()+ref->Y()*ref->Py();
295 if (dir<0) break; // oposite direction - looping track - return back
296 if (ref->P()<kPcut) continue;
297 if (ref->R()<rmax) break;
298 //if (ref->R()<rmin) break;
300 if (ref->DetectorId()==AliTrackReference::kTPC){
304 if (ref->R()>tpcIn->R()) tpcOut = ref;
308 if (ref->DetectorId()==AliTrackReference::kITS){
312 if (ref->R()>itsIn->R()) itsOut = ref;
316 if (ref->DetectorId()==AliTrackReference::kTRD){
320 if (ref->R()>trdIn->R()) trdOut = ref;
323 if (ref->R()<rmin) rmin=ref->R();
324 if (ref->R()>rmax) rmax=ref->R();
326 if (tpcIn && tpcOut) ProcessRefTracker(tpcIn,tpcOut,particle,1);
327 if (itsIn && itsOut) ProcessRefTracker(itsIn,itsOut,particle,0);
328 if (trdIn && trdOut) ProcessRefTracker(trdIn,trdOut,particle,2);
334 void AliMCTrackingTestTask::ProcessRefTracker(AliTrackReference* refIn, AliTrackReference* refOut, TParticle*part,Int_t type){
336 // Test propagation from In to out
338 AliExternalTrackParam *param = 0;
339 AliExternalTrackParam *paramMC = 0;
340 Double_t xyzIn[3]={refIn->X(),refIn->Y(), refIn->Z()};
341 Double_t mass = part->GetMass();
344 param=MakeTrack(refOut,part);
345 paramMC=MakeTrack(refOut,part);
347 PropagateToPoint(param,xyzIn, mass, step);
348 TTreeSRedirector *pcstream = GetDebugStreamer();
351 param->GetXYZ(gpos.GetMatrixArray());
352 param->GetPxPyPz(gmom.GetMatrixArray());
370 void AliMCTrackingTestTask::FinishTaskOutput()
373 // According description in AliAnalisysTask this method is call
374 // on the slaves before sending data
377 gSystem->Exec("pwd");
378 RegisterDebugOutput();
383 void AliMCTrackingTestTask::RegisterDebugOutput(){
388 // store - copy debug output to the destination position
389 // currently ONLY for local copy
392 dsName+="Debug.root";
393 dsName.ReplaceAll(" ","");
394 TString dsName2=fDebugOutputPath.Data();
395 gSystem->MakeDirectory(dsName2.Data());
396 dsName2+=gSystem->HostName();
397 gSystem->MakeDirectory(dsName2.Data());
399 dsName2+=gSystem->BaseName(gSystem->pwd());
401 gSystem->MakeDirectory(dsName2.Data());
403 AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
404 printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
405 TFile::Cp(dsName.Data(),dsName2.Data());
410 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros");
411 gROOT->LoadMacro("$ALICE_ROOT/TPC/macros/AliXRDPROOFtoolkit.cxx+")
412 AliXRDPROOFtoolkit tool;
413 TChain * chain = tool.MakeChain("mctracking.txt","MC",0,100);
417 chain->SetAlias("pdg","(p.fPdgCode)");
418 chain->SetAlias("dPRec","(refOut.P()-par.P())/refIn.P()");
419 chain->SetAlias("dPMC","(refOut.P()-refIn.P())/refIn->P()");