4 #include "AliAnalysisTaskME.h"
5 #include "AliAnalysisManager.h"
7 #include "AliAODEvent.h"
8 #include "AliAODTrack.h"
9 #include "AliAODVertex.h"
10 #include "AliMultiEventInputHandler.h"
11 #include "AliAODHandler.h"
13 #include "AliAnalysisTaskCreateMixedDimuons.h"
14 #include "AliEventPoolMuon.h"
15 #include "TDatabasePDG.h"
18 // Example of an analysis task creating aod events filled with mixed muon pairs
20 // Authors Alessandro De Falco and Antonio Uras, INFN Cagliari
21 // alessandro.de.falco@ca.infn.it antonio.uras@ca.infn.it
23 #define AliAnalysisTaskCreateMixedDimuons_CXX
25 ClassImp(AliAnalysisTaskCreateMixedDimuons)
27 //=================================================================================
29 AliAnalysisTaskCreateMixedDimuons::AliAnalysisTaskCreateMixedDimuons(const char *name)
30 : AliAnalysisTaskME(name),
32 fOutputUserHandler(0x0),
34 fOutputUserAODTree(0X0),
41 // Default input and output containers
42 DefineInput (0, TChain::Class());
44 // User-defined input and output containers
45 DefineOutput(1, TTree::Class());
47 // ---------------------------------------------------------------
54 for (Int_t i=0; i<100; i++) fInputAOD[i] = 0;
56 fOutputUserHandler = 0;
58 fOutputUserAODTree = 0;
62 //=================================================================================
64 void AliAnalysisTaskCreateMixedDimuons::ConnectInputData(Option_t *) {
66 // Connect ESD or AOD here
69 printf("-> AliAnalysisTaskCreateMixedDimuons::ConnectInputData\n");
71 TTree* tree = (TTree*) GetInputData(0);
74 Printf("ERROR: Could not read chain from input slot 0");
78 fInputHandler = (AliMultiEventInputHandler*) AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
79 fPoolMuon = (AliEventPoolMuon*) AliAnalysisManager::GetAnalysisManager()->GetEventPool();
80 fBufferSize = fInputHandler->GetBufferSize();
81 if (fBufferSize>100) {
82 printf("\n*** WARNING AliAnalysisTaskCreateMixedDimuons::ConnectInputData -> Trying to set fBufferSize>100, forcing fBufferSize=100 ***\n\n");
86 if (!fInputHandler) Printf("ERROR: Could not get AliMultiAODInputHandler");
87 else for (Int_t i=0; i<fBufferSize; i++) fInputAOD[i] = (AliAODEvent*) fInputHandler->GetEvent(i);
90 printf("<- AliAnalysisTaskCreateMixedDimuons::ConnectInputData\n");
94 //=================================================================================
96 void AliAnalysisTaskCreateMixedDimuons::UserCreateOutputObjects() {
98 // Here the user-defined output containers should be created!!!
101 fOutputUserHandler = new AliAODHandler();
103 fOutputUserHandler -> Init("");
105 fOutputUserAOD = fOutputUserHandler -> GetAOD();
107 fOutputUserAODTree = fOutputUserHandler -> GetTree();
111 //=================================================================================
113 void AliAnalysisTaskCreateMixedDimuons::UserExec(Option_t *) {
116 Printf("ERROR: fInputAOD not available\n");
120 if (!fOutputUserAOD) {
121 Printf("ERROR: fOutputUserAOD not available\n");
125 printf("Calling USER EXEC\n\n");
127 for (Int_t iEv=0; iEv<fBufferSize; iEv++) {
128 for (Int_t jEv=0; jEv<iEv; jEv++) {
130 Int_t nTracksEv[2] = {0};
131 Int_t nFWMuonsEv[2] = {0};
133 nTracksEv[0] = fInputAOD[iEv]->GetNTracks();
134 nTracksEv[1] = fInputAOD[jEv]->GetNTracks();
136 for (Int_t i=0; i<nTracksEv[0]; i++) if(fInputAOD[iEv]->GetTrack(i)->IsMuonTrack()) nFWMuonsEv[0]++;
137 for (Int_t i=0; i<nTracksEv[1]; i++) if(fInputAOD[jEv]->GetTrack(i)->IsMuonTrack()) nFWMuonsEv[1]++;
139 // Muon track mixing to fill a mass spectrum
141 if (nFWMuonsEv[0] && nFWMuonsEv[1]) {
143 Int_t rndMuonTrack[2] = {0};
144 rndMuonTrack[0] = gRandom->Integer(nFWMuonsEv[0]);
145 rndMuonTrack[1] = gRandom->Integer(nFWMuonsEv[1]);
147 Int_t nFWMUonsAdded = 0;
148 Int_t nPosTracksAdded = 0;
149 Int_t nNegTracksAdded = 0;
151 AliAODVertex *vertex = new AliAODVertex();
154 vertex -> SetZ(fPoolMuon->GetMeanPrimaryVertexZ());
156 Int_t muonCounter[2] = {0};
158 // adding tracks and vertex to the output event...
160 for (Int_t i=0; i<nTracksEv[0]; i++) {
161 if(fInputAOD[iEv]->GetTrack(i)->IsMuonTrack()) {
162 if (fDebug) printf("fInputAOD[%d]->GetTrack(%d) = %p pt = %f uniqueID = %d\n",
163 iEv,i,fInputAOD[iEv]->GetTrack(i),fInputAOD[iEv]->GetTrack(i)->Pt(),
164 fInputAOD[iEv]->GetTrack(i)->GetUniqueID());
165 if (muonCounter[0]==rndMuonTrack[0]) {
166 fOutputUserAOD->AddTrack(fInputAOD[iEv]->GetTrack(i));
168 if (fInputAOD[iEv]->GetTrack(i)->Charge()>0) nPosTracksAdded++;
169 else nNegTracksAdded++;
175 for (Int_t i=0; i<nTracksEv[1]; i++) {
176 if(fInputAOD[jEv]->GetTrack(i)->IsMuonTrack()) {
177 if (fDebug) printf("fInputAOD[%d]->GetTrack(%d) = %p pt = %f uniqueID = %d\n",
178 jEv,i,fInputAOD[jEv]->GetTrack(i),fInputAOD[jEv]->GetTrack(i)->Pt(),
179 fInputAOD[jEv]->GetTrack(i)->GetUniqueID());
180 if (muonCounter[1]==rndMuonTrack[1]) {
181 fOutputUserAOD->AddTrack(fInputAOD[jEv]->GetTrack(i));
183 if (fInputAOD[jEv]->GetTrack(i)->Charge()>0) nPosTracksAdded++;
184 else nNegTracksAdded++;
190 fOutputUserAOD->AddVertex(vertex);
195 for (Int_t i=0; i<nFWMUonsAdded; i++) {
196 AliAODTrack *tr = (AliAODTrack*) fOutputUserAOD->GetTrack(i);
197 printf("fOutputUserAOD->GetTrack(%d) = %p pt = %f\n",i,tr,tr->Pt());
201 fOutputUserAOD->GetHeader()->SetRefMultiplicity(nFWMUonsAdded);
202 fOutputUserAOD->GetHeader()->SetRefMultiplicityPos(nPosTracksAdded);
203 fOutputUserAOD->GetHeader()->SetRefMultiplicityNeg(nNegTracksAdded);
205 fOutputUserHandler -> FinishEvent();
209 PostData(1, fOutputUserAODTree);
217 //===================================================================================
219 void AliAnalysisTaskCreateMixedDimuons::Terminate(Option_t *) {
221 // Called once at the end of the query
223 printf("\n\nCalling TERMINATE \n\n\n");
225 fOutputUserHandler -> Terminate();
229 //===================================================================================