12 #include <TParticle.h>
15 #include <TTreeStream.h>
16 #include <AliAnalysisManager.h>
17 #include <AliESDInputHandler.h>
19 #include "AliMCEvent.h"
20 #include "AliMCEventHandler.h"
21 #include "AliMathBase.h"
24 #include "AliExternalTrackParam.h"
25 #include "AliTracker.h"
26 #include "AliTPCseed.h"
28 #include "AliTPCComparisonPID.h"
30 #include <THnSparse.h>
39 ClassImp(AliTPCComparisonPID)
41 //________________________________________________________________________
42 AliTPCComparisonPID::AliTPCComparisonPID() :
44 fMCinfo(0), //! MC event handler
54 // Default constructor (should not be used)
58 AliTPCComparisonPID::AliTPCComparisonPID(const AliTPCComparisonPID& info) :
59 AliAnalysisTask(info),
60 fMCinfo(info.fMCinfo), //! MC event handler
71 // Dummy Copy constructor - no copy constructor for THnSparse
77 //________________________________________________________________________
78 AliTPCComparisonPID::AliTPCComparisonPID(const char *name) :
79 AliAnalysisTask(name, "AliTPCComparisonPID"),
80 fMCinfo(0), //! MC event handler
92 // Input slot #0 works with a TChain
93 DefineInput(0, TChain::Class());
94 // Output slot #0 writes into a TList
95 DefineOutput(0, AliTPCComparisonPID::Class());
101 void AliTPCComparisonPID::Init(){
103 // Init dEdx histogram
105 // 0 - particle specie as defined in the AliPID - negatives+5 <0,9>
106 // 1 - momenta - at the entrance of the TPC
107 // 2 - tan lambda- fP[3]
109 // 4 - measurement - dEdx or dEdx/BB
111 Double_t xmin[5], xmax[5];
115 xmin[0]=0; xmax[0]=10;
118 xmin[1]=0.1; xmax[1]=3;
121 xmin[2]=-1.5; xmax[2]=1.5;
126 xmin[3]=0.1; xmax[3]=100;
130 xmin[4]=20; xmax[4]=400;
131 fTPCsignal = new THnSparseF("TPC signal","TPC signal",5,nbins,xmin,xmax);
133 xmin[4]=25; xmax[4]=75;
134 fTPCsignal = new THnSparseF("TPC signal Norm","TPC signal Norm",5,nbins,xmin,xmax);
142 AliTPCComparisonPID::~AliTPCComparisonPID(){
146 if (fDebugLevel>0) printf("AliTPCComparisonPID::~AliTPCComparisonPID\n");
147 if (fDebugStreamer) delete fDebugStreamer;
150 delete fTPCsignalNorm;
154 //________________________________________________________________________
155 void AliTPCComparisonPID::ConnectInputData(Option_t *)
158 // Connect the input data
161 cout << "AnalysisTaskTPCCluster::ConnectInputData()" << endl;
163 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
165 //Printf("ERROR: Could not read chain from input slot 0");
168 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
170 //Printf("ERROR: Could not get ESDInputHandler");
173 fESD = esdH->GetEvent();
174 //Printf("*** CONNECTED NEW EVENT ****");
177 AliMCEventHandler* mcinfo = (AliMCEventHandler*) (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
178 mcinfo->SetReadTR(kTRUE);
180 fMCinfo = mcinfo->MCEvent();
190 //________________________________________________________________________
191 void AliTPCComparisonPID::CreateOutputObjects()
194 // Connect the output objects
197 cout << "AnalysisTaskTPCCluster::CreateOutputObjects()" << endl;
202 //________________________________________________________________________
203 void AliTPCComparisonPID::Exec(Option_t *) {
205 // Execute analysis for current event
209 cout << "AliTPCComparisonPID::Exec()" << endl;
212 // If MC has been connected
215 cout << "Not MC info\n" << endl;
228 //________________________________________________________________________
229 void AliTPCComparisonPID::Terminate(Option_t *) {
234 printf("AliTPCComparisonPID: Terminate() \n");
236 if (fDebugLevel>0) printf("AliMCtrackingTestTask::Terminate\n");
237 if (fDebugStreamer) delete fDebugStreamer;
244 TTreeSRedirector *AliTPCComparisonPID::GetDebugStreamer(){
246 // Get Debug streamer
247 // In case debug streamer not yet initialized and StreamLevel>0 create new one
249 if (fStreamLevel==0) return 0;
250 if (fDebugStreamer) return fDebugStreamer;
253 dsName+="Debug.root";
254 dsName.ReplaceAll(" ","");
255 fDebugStreamer = new TTreeSRedirector(dsName.Data());
256 return fDebugStreamer;
262 void AliTPCComparisonPID::ProcessMCInfo(){
267 Int_t npart = fMCinfo->GetNumberOfTracks();
268 Int_t ntracks = fESD->GetNumberOfTracks();
269 if (npart<=0) return;
270 if (ntracks<=0) return;
273 TParticle * particle= new TParticle;
274 TClonesArray * trefs = new TClonesArray("AliTrackReference");
276 for (Int_t itrack=0;itrack<ntracks;itrack++){
277 AliESDtrack *track = fESD->GetTrack(itrack);
278 const AliExternalTrackParam *in=track->GetInnerParam();
280 Int_t ipart = TMath::Abs(track->GetLabel());
282 Int_t status = fMCinfo->GetParticleAndTR(ipart, particle, trefs);
283 if (status<0) continue;
284 if (!particle) continue;
285 if (!trefs) continue;
288 Double_t mom = in->GetP();
289 Double_t dedx=track->GetTPCsignal();
290 Double_t mass = particle->GetMass();
291 Double_t bg =mom/mass;
292 Double_t betheBloch = AliMathBase::BetheBlochAleph(bg);
298 Int_t pdg = particle->GetPdgCode();
299 for (Int_t iType=0;iType<5;iType++) {
300 if (AliPID::ParticleCode(iType)==TMath::Abs(pdg)){
306 x[2]= track->GetTgl();
307 x[3]= TMath::Log(bg);
310 x[4]=dedx/betheBloch;
311 fTPCsignalNorm->Fill(x);
318 void AliTPCComparisonPID::FinishTaskOutput()
321 // According description in AliAnalisysTask this method is call
322 // on the slaves before sending data
325 gSystem->Exec("pwd");
326 RegisterDebugOutput();
331 void AliTPCComparisonPID::RegisterDebugOutput(){
336 // store - copy debug output to the destination position
337 // currently ONLY for local copy
340 dsName+="Debug.root";
341 dsName.ReplaceAll(" ","");
342 TString dsName2=fDebugOutputPath.Data();
343 gSystem->MakeDirectory(dsName2.Data());
344 dsName2+=gSystem->HostName();
345 gSystem->MakeDirectory(dsName2.Data());
347 dsName2+=gSystem->BaseName(gSystem->pwd());
349 gSystem->MakeDirectory(dsName2.Data());
351 AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
352 printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
353 TFile::Cp(dsName.Data(),dsName2.Data());