]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliAnalysisTaskFilterSteer.cxx
Fix for bug #74065: Commit and Port AliFileMerger for Pass0
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskFilterSteer.cxx
CommitLineData
91bf40f8 1/**************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*$Id$
17
18*/
19
20/////////////////////////////////////////////////////////////
21//
739f0aa6 22// Filtering task:
23// Selection of only 1% of the events for which to keep
24// the ESD friend
91bf40f8 25//
26// /////////////////////////////////////////////////////////////
27
28#include <TTree.h>
29#include <TChain.h>
30
31#include "AliLog.h"
32#include "AliESDInputHandler.h"
33#include "AliESDtrack.h"
34#include "AliESDEvent.h"
35#include "AliESDfriend.h"
36#include "AliAnalysisTaskFilter.h"
37#include "AliAnalysisManager.h"
739f0aa6 38#include "AliAnalysisTaskFilterSteer.h"
91bf40f8 39#include "TRandom.h"
40
41
739f0aa6 42ClassImp(AliAnalysisTaskFilterSteer)
91bf40f8 43
44
45//________________________________________________________________________
739f0aa6 46AliAnalysisTaskFilterSteer::AliAnalysisTaskFilterSteer():
91bf40f8 47AliAnalysisTaskFilter(),
739f0aa6 48fFraction(0.01),
91bf40f8 49fESDInput(0),
50fESDfriendInput(0)
51{
52 // Constructor
53
54 // Define input and output slots here
55 // Input slot #0 works with a TChain
56 DefineInput(0, TChain::Class());
57 // Output slot #0 writes into a TTree
58 //DefineOutput(0,TTree::Class());
59}
60
61//________________________________________________________________________
739f0aa6 62AliAnalysisTaskFilterSteer::AliAnalysisTaskFilterSteer(const char* name):
91bf40f8 63AliAnalysisTaskFilter(name),
739f0aa6 64fFraction(0.01),
91bf40f8 65fESDInput(0),
66fESDfriendInput(0)
67{
68 // Constructor
69
70 // Define input and output slots here
71 // Input slot #0 works with a TChain
72 DefineInput(0, TChain::Class());
73 // Output slot #0 writes into a TTree
74 //DefineOutput(0,TTree::Class());
75}
76
77//________________________________________________________________________
739f0aa6 78AliAnalysisTaskFilterSteer::~AliAnalysisTaskFilterSteer()
91bf40f8 79{
80
81 // dtor
82
83}
84
85//________________________________________________________________________
739f0aa6 86void AliAnalysisTaskFilterSteer::Init()
91bf40f8 87{
88 // Initialization
89
90 return;
91}
92
93//________________________________________________________________________
739f0aa6 94void AliAnalysisTaskFilterSteer::UserCreateOutputObjects()
91bf40f8 95{
96 //
97 // Create the output container
98 //
99
100 return;
101}
102
103//________________________________________________________________________
739f0aa6 104void AliAnalysisTaskFilterSteer::UserExec(Option_t */*option*/)
91bf40f8 105{
106
739f0aa6 107 //
108 // Applying random selection of the events
91bf40f8 109
110 fESDInput = dynamic_cast<AliESDEvent*>(InputEvent()); // get the input ESD
739f0aa6 111 fESDfriendInput = InputFriend(); // get the input friend
91bf40f8 112 if(!fESDInput) {
739f0aa6 113 printf("AliAnalysisTaskFilterSteer::Exec(): no ESD \n");
91bf40f8 114 return;
115 }
116 if(!fESDfriendInput) {
739f0aa6 117 printf("AliAnalysisTaskFilterSteer::Exec(): no ESDfriend \n");
91bf40f8 118 return;
119 }
739f0aa6 120
91bf40f8 121 // attach ESDfriend
122
123 AliESDfriend* esdFriendOutput = (AliESDfriend*)ESDfriend();
739f0aa6 124 AliDebug(3,Form("Number of ESD tracks in input = %d ",fESDInput->GetNumberOfTracks()));
125 AliDebug(3,Form("Number of tracks in input friends = %d ",fESDfriendInput->GetNumberOfTracks()));
126 AliDebug(3,Form("Number of tracks in output friendsNew before filtering = %d ",esdFriendOutput->GetNumberOfTracks()));
91bf40f8 127
128 //
739f0aa6 129 // keeping all the tracks for the randomly "fFraction" of the total number of events
91bf40f8 130 //
739f0aa6 131
91bf40f8 132 for (Int_t i = 0; i< fESDInput->GetNumberOfTracks(); i++){
739f0aa6 133 AliESDfriendTrack* tOld = (AliESDfriendTrack*)fESDfriendInput->GetTrack(i);
134 AddFriendTrackAt(tOld,i);
91bf40f8 135 }
739f0aa6 136 AliDebug(2,Form("Number of tracks in output friendsNew after filtering = %d ",esdFriendOutput->GetNumberOfTracks()));
137 AliDebug(2,Form("Number of tracks in output friendsNew after filtering with GetEntries() = %d ",esdFriendOutput->GetEntriesInTracks()));
138
91bf40f8 139 return;
140}
141
142//________________________________________________________________________
739f0aa6 143void AliAnalysisTaskFilterSteer::Terminate(Option_t */*option*/)
91bf40f8 144{
145 // Terminate analysis
146 //
739f0aa6 147 AliDebug(2,"AliAnalysisTaskFilterSteer: Terminate() \n");
91bf40f8 148
149 return;
150}
151//________________________________________________________________________
739f0aa6 152Bool_t AliAnalysisTaskFilterSteer::UserSelectESDfriendForCurrentEvent()
91bf40f8 153{
739f0aa6 154 //
155 // Selecting or discarding current event
156 //
157 Double_t number = gRandom->Rndm();
158 if (number<fFraction){
159 // keeping event
160 AliDebug(2,Form("*****************Selecting event (number = %f)",number));
161 return kTRUE;
162 }
163 AliDebug(2,Form("*****************Skipping event (number = %f)",number));
164 return kFALSE;
91bf40f8 165}