ROOT logo
/**************************************************************************
* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
*                                                                        *
* Author: Yvonne Pachmayer <pachmay@physi.uni-heidelberg.de>             *
* Contributors are mentioned in the code where appropriate.              *
*                                                                        *
* Permission to use, copy, modify and distribute this software and its   *
* documentation strictly for non-commercial purposes is hereby granted   *
* without fee, provided that the above copyright notice appears in all   *
* copies and that both the copyright notice and this permission notice   *
* appear in the supporting documentation. The authors make no claims     *
* about the suitability of this software for any purpose. It is          *
* provided "as is" without express or implied warranty.                  *
**************************************************************************/
//
// The task:
// stores TPC TRD matching quantities in a THnSparse
// output can then be used for matching functions
//
// Author:
// Yvonne Pachmayer <pachmay@physi.uni-heidelberg.de>
//


#include "AliTRDPIDmatching.h"
#include "AliTRDPIDTree.h"
#include "TChain.h"
#include "AliAnalysisManager.h"
#include "AliESDEvent.h"
#include "AliESDtrackCuts.h"
#include "AliMCEvent.h"
#include "AliPID.h"
#include "AliESDtrack.h"
#include "AliPIDResponse.h"
#include "AliInputEventHandler.h"
#include "AliMCEventHandler.h"
#include "AliESDInputHandler.h"
#include "AliESDv0KineCuts.h"
#include "THnSparse.h"

using namespace std;

ClassImp(AliTRDPIDmatching)


//________________________________________________________________________
AliTRDPIDmatching::AliTRDPIDmatching(const char *name): AliTRDPIDTree(name),
  fESD(0), fMC(0), fTHntrdmatch(0), fOutputContainer(0), fesdTrackCuts(0), fHasMC(0)
{
    //
    // Constructor
    //

    DefineInput(0, TChain::Class());
    DefineOutput(1, TList::Class());

}

//________________________________________________________________________
AliTRDPIDmatching::~AliTRDPIDmatching()
{
    //
    // dtor
    //

  delete fOutputContainer;
  fOutputContainer = 0;
  
}


//________________________________________________________________________
void AliTRDPIDmatching::UserCreateOutputObjects()
{
    //
    // Output: THnSparse binning and esd track cuts
    //

    // V0 kine cuts
    fV0cuts = new AliESDv0KineCuts();
    // V0 PID Obj arrays
    fV0electrons = new TObjArray;
    fV0pions     = new TObjArray;
    fV0protons   = new TObjArray;

    fesdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts", "cuts");
    fesdTrackCuts->SetEtaRange(-0.9,+0.9);
    fesdTrackCuts->SetMinNClustersTPC(80);
    fesdTrackCuts->SetRequireTPCRefit(kTRUE);
    fesdTrackCuts->SetMaxDCAToVertexXY(3);
    fesdTrackCuts->SetMaxDCAToVertexZ(3.0);
    fesdTrackCuts->SetAcceptKinkDaughters(kFALSE);
    fesdTrackCuts->SetMaxChi2PerClusterTPC(4);
    fesdTrackCuts->SetRequireITSRefit(kTRUE);
    fesdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kAny);

    const Int_t kNdim = 5;
    //                       pid,  eta,  phi,  p,  trdtracklets
    Int_t bins[kNdim] =    {  7,    180,  280,      500,    7};
    Double_t xmin[kNdim] = {  0,   -0.9,    0.,    -10.,    0};
    Double_t xmax[kNdim] = {  7,    0.9,    7.,     10.,    7};

    fTHntrdmatch= new THnSparseF("trdmatching", "TRD matching; pid;eta;phi;p;ntrdtracklets", kNdim, bins, xmin, xmax);

    fOutputContainer = new TObjArray(1);
    fOutputContainer->SetName(GetName());
    fOutputContainer->SetOwner(kTRUE);
    fOutputContainer->Add(fTHntrdmatch);

    PostData(1, fOutputContainer);
}

//_____________________________________________________________________________
void AliTRDPIDmatching::UserExec(Option_t *)
{
    //
    // calls the Process function
    //
    AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());

    if (!esdH)
    {
	Printf("ERROR: Could not get ESDInputHandler \n");
    }
    else fESD = esdH->GetEvent();

    AliMCEventHandler *mcH = dynamic_cast<AliMCEventHandler*>((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());

    if(!mcH){
//	Printf("Error: Could not get MCtruthEventHandler \n");
	fHasMC = kFALSE;
    } else {
        fMC=mcH->MCEvent();
	fHasMC = kTRUE;
    }

    FillV0PIDlist();
    ProcessData(fESD);

    PostData(1, fOutputContainer);
    // Clear the V0 PID arrays
    ClearV0PIDlist();
}



//________________________________________________________________________
void AliTRDPIDmatching::ProcessData(AliESDEvent *const esdEvent)
{
    //
    // Process function; called for each event
    //

    AliMCParticle *mctrack = NULL;
    TParticle* mcparticle = NULL;

    if (!esdEvent) {
	Printf("ERROR: esdEvent not available");
	return;
    }

    if(!((AliESDInputHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))) Printf("ESD inputhandler not available \n");

    AliESDpid* fESDpid = ((AliESDInputHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->GetESDpid();

    if (!fESDpid) {
	Printf("ERROR: fESDpid not available");
	return;
    }

  



    for (Int_t iTracks = 0; iTracks < esdEvent->GetNumberOfTracks(); iTracks++)
    {
	AliESDtrack *trackESD = esdEvent->GetTrack(iTracks);
	if(!trackESD) continue;
	if(!fesdTrackCuts->AcceptTrack(trackESD)){continue;}

	const AliExternalTrackParam *paramIn = trackESD->GetInnerParam();
	Float_t precin=-1;
	if(paramIn) precin=paramIn->Pt();
	else continue;
        if(precin<0.3) continue; // lower momentum cut

	Double_t eta=trackESD->Eta();
	Double_t phi=trackESD->Phi();
	Int_t ntrdtracklets=trackESD->GetTRDntracklets();
	Int_t charge =trackESD->Charge();

	Int_t v0id=0;
	if(fHasMC==kFALSE)
	{
	    Int_t v0tagAllCharges = TMath::Abs(GetV0tag(iTracks));
	    if (v0tagAllCharges == -99) {
		AliError(Form("Problem with V0 tag list (requested V0 track for track %d from %d (list status %d))!", iTracks, esdEvent->GetNumberOfTracks(),
			      fV0tags != 0x0));
		v0id=0;
	    }

	    Bool_t isV0el=0;
	    Bool_t isV0pi=0;
	    Bool_t isV0pr=0;

            if(v0tagAllCharges == 11)   isV0el=1;
            if(v0tagAllCharges == 211)  isV0pi=1;
            if(v0tagAllCharges == 2212) isV0pr=1;

	    if(isV0el) { // electron
		v0id=1;
	    }
	    if(isV0pi) { // pion
		v0id=3;
	    }
	    if(isV0pr) { // proton
		v0id=5;
	    }
	}

	Int_t mcpid=0;
	if(fHasMC==kTRUE)
	{
	    if(!(mctrack = dynamic_cast<AliMCParticle *>(fMC->GetTrack(TMath::Abs(trackESD->GetLabel()))))) continue;
	    mcparticle = mctrack->Particle();
	    if(mcparticle)
	    {
		mcpid = mcparticle->GetPdgCode();
		if(TMath::Abs(mcpid)==11)   v0id=1;
		if(TMath::Abs(mcpid)==13)   v0id=2;
		if(TMath::Abs(mcpid)==211)  v0id=3;
		if(TMath::Abs(mcpid)==321)  v0id=4;
		if(TMath::Abs(mcpid)==2212) v0id=5;
	    }
	}



	Double_t contentSignal[5];
	contentSignal[0]=v0id;
	contentSignal[1]=eta;
	contentSignal[2]=phi;
	contentSignal[3]=precin*charge;
	contentSignal[4]=ntrdtracklets;

	fTHntrdmatch->Fill(contentSignal);

    } //track loop


    PostData(1, fOutputContainer);
}


//________________________________________________________________________
Int_t  AliTRDPIDmatching::CompareFloat(Float_t f1, Float_t f2) const
{
    //compares if the Float_t f1 is equal with f2 and returns 1 if true and 0 if false
    Float_t precision = 0.00001;
    if (((f1 - precision) < f2) &&
	((f1 + precision) > f2))
    {
	return 1;
    }
    else
    {
	return 0;
    }
}

//________________________________________________________________________
void AliTRDPIDmatching::Terminate(const Option_t *)
{
    //
    // Terminate function
    //

}
 AliTRDPIDmatching.cxx:1
 AliTRDPIDmatching.cxx:2
 AliTRDPIDmatching.cxx:3
 AliTRDPIDmatching.cxx:4
 AliTRDPIDmatching.cxx:5
 AliTRDPIDmatching.cxx:6
 AliTRDPIDmatching.cxx:7
 AliTRDPIDmatching.cxx:8
 AliTRDPIDmatching.cxx:9
 AliTRDPIDmatching.cxx:10
 AliTRDPIDmatching.cxx:11
 AliTRDPIDmatching.cxx:12
 AliTRDPIDmatching.cxx:13
 AliTRDPIDmatching.cxx:14
 AliTRDPIDmatching.cxx:15
 AliTRDPIDmatching.cxx:16
 AliTRDPIDmatching.cxx:17
 AliTRDPIDmatching.cxx:18
 AliTRDPIDmatching.cxx:19
 AliTRDPIDmatching.cxx:20
 AliTRDPIDmatching.cxx:21
 AliTRDPIDmatching.cxx:22
 AliTRDPIDmatching.cxx:23
 AliTRDPIDmatching.cxx:24
 AliTRDPIDmatching.cxx:25
 AliTRDPIDmatching.cxx:26
 AliTRDPIDmatching.cxx:27
 AliTRDPIDmatching.cxx:28
 AliTRDPIDmatching.cxx:29
 AliTRDPIDmatching.cxx:30
 AliTRDPIDmatching.cxx:31
 AliTRDPIDmatching.cxx:32
 AliTRDPIDmatching.cxx:33
 AliTRDPIDmatching.cxx:34
 AliTRDPIDmatching.cxx:35
 AliTRDPIDmatching.cxx:36
 AliTRDPIDmatching.cxx:37
 AliTRDPIDmatching.cxx:38
 AliTRDPIDmatching.cxx:39
 AliTRDPIDmatching.cxx:40
 AliTRDPIDmatching.cxx:41
 AliTRDPIDmatching.cxx:42
 AliTRDPIDmatching.cxx:43
 AliTRDPIDmatching.cxx:44
 AliTRDPIDmatching.cxx:45
 AliTRDPIDmatching.cxx:46
 AliTRDPIDmatching.cxx:47
 AliTRDPIDmatching.cxx:48
 AliTRDPIDmatching.cxx:49
 AliTRDPIDmatching.cxx:50
 AliTRDPIDmatching.cxx:51
 AliTRDPIDmatching.cxx:52
 AliTRDPIDmatching.cxx:53
 AliTRDPIDmatching.cxx:54
 AliTRDPIDmatching.cxx:55
 AliTRDPIDmatching.cxx:56
 AliTRDPIDmatching.cxx:57
 AliTRDPIDmatching.cxx:58
 AliTRDPIDmatching.cxx:59
 AliTRDPIDmatching.cxx:60
 AliTRDPIDmatching.cxx:61
 AliTRDPIDmatching.cxx:62
 AliTRDPIDmatching.cxx:63
 AliTRDPIDmatching.cxx:64
 AliTRDPIDmatching.cxx:65
 AliTRDPIDmatching.cxx:66
 AliTRDPIDmatching.cxx:67
 AliTRDPIDmatching.cxx:68
 AliTRDPIDmatching.cxx:69
 AliTRDPIDmatching.cxx:70
 AliTRDPIDmatching.cxx:71
 AliTRDPIDmatching.cxx:72
 AliTRDPIDmatching.cxx:73
 AliTRDPIDmatching.cxx:74
 AliTRDPIDmatching.cxx:75
 AliTRDPIDmatching.cxx:76
 AliTRDPIDmatching.cxx:77
 AliTRDPIDmatching.cxx:78
 AliTRDPIDmatching.cxx:79
 AliTRDPIDmatching.cxx:80
 AliTRDPIDmatching.cxx:81
 AliTRDPIDmatching.cxx:82
 AliTRDPIDmatching.cxx:83
 AliTRDPIDmatching.cxx:84
 AliTRDPIDmatching.cxx:85
 AliTRDPIDmatching.cxx:86
 AliTRDPIDmatching.cxx:87
 AliTRDPIDmatching.cxx:88
 AliTRDPIDmatching.cxx:89
 AliTRDPIDmatching.cxx:90
 AliTRDPIDmatching.cxx:91
 AliTRDPIDmatching.cxx:92
 AliTRDPIDmatching.cxx:93
 AliTRDPIDmatching.cxx:94
 AliTRDPIDmatching.cxx:95
 AliTRDPIDmatching.cxx:96
 AliTRDPIDmatching.cxx:97
 AliTRDPIDmatching.cxx:98
 AliTRDPIDmatching.cxx:99
 AliTRDPIDmatching.cxx:100
 AliTRDPIDmatching.cxx:101
 AliTRDPIDmatching.cxx:102
 AliTRDPIDmatching.cxx:103
 AliTRDPIDmatching.cxx:104
 AliTRDPIDmatching.cxx:105
 AliTRDPIDmatching.cxx:106
 AliTRDPIDmatching.cxx:107
 AliTRDPIDmatching.cxx:108
 AliTRDPIDmatching.cxx:109
 AliTRDPIDmatching.cxx:110
 AliTRDPIDmatching.cxx:111
 AliTRDPIDmatching.cxx:112
 AliTRDPIDmatching.cxx:113
 AliTRDPIDmatching.cxx:114
 AliTRDPIDmatching.cxx:115
 AliTRDPIDmatching.cxx:116
 AliTRDPIDmatching.cxx:117
 AliTRDPIDmatching.cxx:118
 AliTRDPIDmatching.cxx:119
 AliTRDPIDmatching.cxx:120
 AliTRDPIDmatching.cxx:121
 AliTRDPIDmatching.cxx:122
 AliTRDPIDmatching.cxx:123
 AliTRDPIDmatching.cxx:124
 AliTRDPIDmatching.cxx:125
 AliTRDPIDmatching.cxx:126
 AliTRDPIDmatching.cxx:127
 AliTRDPIDmatching.cxx:128
 AliTRDPIDmatching.cxx:129
 AliTRDPIDmatching.cxx:130
 AliTRDPIDmatching.cxx:131
 AliTRDPIDmatching.cxx:132
 AliTRDPIDmatching.cxx:133
 AliTRDPIDmatching.cxx:134
 AliTRDPIDmatching.cxx:135
 AliTRDPIDmatching.cxx:136
 AliTRDPIDmatching.cxx:137
 AliTRDPIDmatching.cxx:138
 AliTRDPIDmatching.cxx:139
 AliTRDPIDmatching.cxx:140
 AliTRDPIDmatching.cxx:141
 AliTRDPIDmatching.cxx:142
 AliTRDPIDmatching.cxx:143
 AliTRDPIDmatching.cxx:144
 AliTRDPIDmatching.cxx:145
 AliTRDPIDmatching.cxx:146
 AliTRDPIDmatching.cxx:147
 AliTRDPIDmatching.cxx:148
 AliTRDPIDmatching.cxx:149
 AliTRDPIDmatching.cxx:150
 AliTRDPIDmatching.cxx:151
 AliTRDPIDmatching.cxx:152
 AliTRDPIDmatching.cxx:153
 AliTRDPIDmatching.cxx:154
 AliTRDPIDmatching.cxx:155
 AliTRDPIDmatching.cxx:156
 AliTRDPIDmatching.cxx:157
 AliTRDPIDmatching.cxx:158
 AliTRDPIDmatching.cxx:159
 AliTRDPIDmatching.cxx:160
 AliTRDPIDmatching.cxx:161
 AliTRDPIDmatching.cxx:162
 AliTRDPIDmatching.cxx:163
 AliTRDPIDmatching.cxx:164
 AliTRDPIDmatching.cxx:165
 AliTRDPIDmatching.cxx:166
 AliTRDPIDmatching.cxx:167
 AliTRDPIDmatching.cxx:168
 AliTRDPIDmatching.cxx:169
 AliTRDPIDmatching.cxx:170
 AliTRDPIDmatching.cxx:171
 AliTRDPIDmatching.cxx:172
 AliTRDPIDmatching.cxx:173
 AliTRDPIDmatching.cxx:174
 AliTRDPIDmatching.cxx:175
 AliTRDPIDmatching.cxx:176
 AliTRDPIDmatching.cxx:177
 AliTRDPIDmatching.cxx:178
 AliTRDPIDmatching.cxx:179
 AliTRDPIDmatching.cxx:180
 AliTRDPIDmatching.cxx:181
 AliTRDPIDmatching.cxx:182
 AliTRDPIDmatching.cxx:183
 AliTRDPIDmatching.cxx:184
 AliTRDPIDmatching.cxx:185
 AliTRDPIDmatching.cxx:186
 AliTRDPIDmatching.cxx:187
 AliTRDPIDmatching.cxx:188
 AliTRDPIDmatching.cxx:189
 AliTRDPIDmatching.cxx:190
 AliTRDPIDmatching.cxx:191
 AliTRDPIDmatching.cxx:192
 AliTRDPIDmatching.cxx:193
 AliTRDPIDmatching.cxx:194
 AliTRDPIDmatching.cxx:195
 AliTRDPIDmatching.cxx:196
 AliTRDPIDmatching.cxx:197
 AliTRDPIDmatching.cxx:198
 AliTRDPIDmatching.cxx:199
 AliTRDPIDmatching.cxx:200
 AliTRDPIDmatching.cxx:201
 AliTRDPIDmatching.cxx:202
 AliTRDPIDmatching.cxx:203
 AliTRDPIDmatching.cxx:204
 AliTRDPIDmatching.cxx:205
 AliTRDPIDmatching.cxx:206
 AliTRDPIDmatching.cxx:207
 AliTRDPIDmatching.cxx:208
 AliTRDPIDmatching.cxx:209
 AliTRDPIDmatching.cxx:210
 AliTRDPIDmatching.cxx:211
 AliTRDPIDmatching.cxx:212
 AliTRDPIDmatching.cxx:213
 AliTRDPIDmatching.cxx:214
 AliTRDPIDmatching.cxx:215
 AliTRDPIDmatching.cxx:216
 AliTRDPIDmatching.cxx:217
 AliTRDPIDmatching.cxx:218
 AliTRDPIDmatching.cxx:219
 AliTRDPIDmatching.cxx:220
 AliTRDPIDmatching.cxx:221
 AliTRDPIDmatching.cxx:222
 AliTRDPIDmatching.cxx:223
 AliTRDPIDmatching.cxx:224
 AliTRDPIDmatching.cxx:225
 AliTRDPIDmatching.cxx:226
 AliTRDPIDmatching.cxx:227
 AliTRDPIDmatching.cxx:228
 AliTRDPIDmatching.cxx:229
 AliTRDPIDmatching.cxx:230
 AliTRDPIDmatching.cxx:231
 AliTRDPIDmatching.cxx:232
 AliTRDPIDmatching.cxx:233
 AliTRDPIDmatching.cxx:234
 AliTRDPIDmatching.cxx:235
 AliTRDPIDmatching.cxx:236
 AliTRDPIDmatching.cxx:237
 AliTRDPIDmatching.cxx:238
 AliTRDPIDmatching.cxx:239
 AliTRDPIDmatching.cxx:240
 AliTRDPIDmatching.cxx:241
 AliTRDPIDmatching.cxx:242
 AliTRDPIDmatching.cxx:243
 AliTRDPIDmatching.cxx:244
 AliTRDPIDmatching.cxx:245
 AliTRDPIDmatching.cxx:246
 AliTRDPIDmatching.cxx:247
 AliTRDPIDmatching.cxx:248
 AliTRDPIDmatching.cxx:249
 AliTRDPIDmatching.cxx:250
 AliTRDPIDmatching.cxx:251
 AliTRDPIDmatching.cxx:252
 AliTRDPIDmatching.cxx:253
 AliTRDPIDmatching.cxx:254
 AliTRDPIDmatching.cxx:255
 AliTRDPIDmatching.cxx:256
 AliTRDPIDmatching.cxx:257
 AliTRDPIDmatching.cxx:258
 AliTRDPIDmatching.cxx:259
 AliTRDPIDmatching.cxx:260
 AliTRDPIDmatching.cxx:261
 AliTRDPIDmatching.cxx:262
 AliTRDPIDmatching.cxx:263
 AliTRDPIDmatching.cxx:264
 AliTRDPIDmatching.cxx:265
 AliTRDPIDmatching.cxx:266
 AliTRDPIDmatching.cxx:267
 AliTRDPIDmatching.cxx:268
 AliTRDPIDmatching.cxx:269
 AliTRDPIDmatching.cxx:270
 AliTRDPIDmatching.cxx:271
 AliTRDPIDmatching.cxx:272
 AliTRDPIDmatching.cxx:273
 AliTRDPIDmatching.cxx:274
 AliTRDPIDmatching.cxx:275
 AliTRDPIDmatching.cxx:276
 AliTRDPIDmatching.cxx:277
 AliTRDPIDmatching.cxx:278