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();
82 Printf("ERROR: Could not get AliMultiAODInputHandler");
85 fBufferSize = fInputHandler->GetBufferSize();
86 if (fBufferSize>100) {
87 printf("\n*** WARNING AliAnalysisTaskCreateMixedDimuons::ConnectInputData -> Trying to set fBufferSize>100, forcing fBufferSize=100 ***\n\n");
90 for (Int_t i=0; i<fBufferSize; i++) fInputAOD[i] = (AliAODEvent*) fInputHandler->GetEvent(i);
94 printf("<- AliAnalysisTaskCreateMixedDimuons::ConnectInputData\n");
98 //=================================================================================
100 void AliAnalysisTaskCreateMixedDimuons::UserCreateOutputObjects() {
102 // Here the user-defined output containers should be created!!!
105 fOutputUserHandler = new AliAODHandler();
107 fOutputUserHandler -> Init("");
109 fOutputUserAOD = fOutputUserHandler -> GetAOD();
111 fOutputUserAODTree = fOutputUserHandler -> GetTree();
115 //=================================================================================
117 void AliAnalysisTaskCreateMixedDimuons::UserExec(Option_t *) {
119 if (!fOutputUserAOD) {
120 Printf("ERROR: fOutputUserAOD not available\n");
124 printf("Calling USER EXEC\n\n");
126 for (Int_t iEv=0; iEv<fBufferSize; iEv++) {
127 for (Int_t jEv=0; jEv<iEv; jEv++) {
129 Int_t nTracksEv[2] = {0};
130 Int_t nFWMuonsEv[2] = {0};
132 nTracksEv[0] = fInputAOD[iEv]->GetNumberOfTracks();
133 nTracksEv[1] = fInputAOD[jEv]->GetNumberOfTracks();
134 // Check if both events contain std aod tracks
135 if (!dynamic_cast<AliAODTrack*>(fInputAOD[iEv]->GetTrack(0)) || dynamic_cast<AliAODTrack*>(fInputAOD[jEv]->GetTrack(0))){
136 AliFatal("Not a standard AOD");
139 for (Int_t i=0; i<nTracksEv[0]; i++) if(((AliAODTrack*)fInputAOD[iEv]->GetTrack(i))->IsMuonTrack()) nFWMuonsEv[0]++;
140 for (Int_t i=0; i<nTracksEv[1]; i++) if(((AliAODTrack*)fInputAOD[jEv]->GetTrack(i))->IsMuonTrack()) nFWMuonsEv[1]++;
142 // Muon track mixing to fill a mass spectrum
144 if (nFWMuonsEv[0] && nFWMuonsEv[1]) {
146 Int_t rndMuonTrack[2] = {0};
147 rndMuonTrack[0] = gRandom->Integer(nFWMuonsEv[0]);
148 rndMuonTrack[1] = gRandom->Integer(nFWMuonsEv[1]);
150 Int_t nFWMUonsAdded = 0;
151 Int_t nPosTracksAdded = 0;
152 Int_t nNegTracksAdded = 0;
154 AliAODVertex *vertex = new AliAODVertex();
157 vertex -> SetZ(fPoolMuon->GetMeanPrimaryVertexZ());
159 Int_t muonCounter[2] = {0};
161 // adding tracks and vertex to the output event...
163 for (Int_t i=0; i<nTracksEv[0]; i++) {
164 if(((AliAODTrack*)fInputAOD[iEv]->GetTrack(i))->IsMuonTrack()) {
165 if (fDebug) printf("fInputAOD[%d]->GetTrack(%d) = %p pt = %f uniqueID = %d\n",
166 iEv,i,fInputAOD[iEv]->GetTrack(i),fInputAOD[iEv]->GetTrack(i)->Pt(),
167 fInputAOD[iEv]->GetTrack(i)->GetUniqueID());
168 if (muonCounter[0]==rndMuonTrack[0]) {
169 fOutputUserAOD->AddTrack((AliAODTrack*)fInputAOD[iEv]->GetTrack(i));
171 if (fInputAOD[iEv]->GetTrack(i)->Charge()>0) nPosTracksAdded++;
172 else nNegTracksAdded++;
178 for (Int_t i=0; i<nTracksEv[1]; i++) {
179 if(((AliAODTrack*)fInputAOD[jEv]->GetTrack(i))->IsMuonTrack()) {
180 if (fDebug) printf("fInputAOD[%d]->GetTrack(%d) = %p pt = %f uniqueID = %d\n",
181 jEv,i,fInputAOD[jEv]->GetTrack(i),fInputAOD[jEv]->GetTrack(i)->Pt(),
182 fInputAOD[jEv]->GetTrack(i)->GetUniqueID());
183 if (muonCounter[1]==rndMuonTrack[1]) {
184 fOutputUserAOD->AddTrack((AliAODTrack*)fInputAOD[jEv]->GetTrack(i));
186 if (fInputAOD[jEv]->GetTrack(i)->Charge()>0) nPosTracksAdded++;
187 else nNegTracksAdded++;
193 fOutputUserAOD->AddVertex(vertex);
198 for (Int_t i=0; i<nFWMUonsAdded; i++) {
199 AliAODTrack *tr = dynamic_cast<AliAODTrack*>( fOutputUserAOD->GetTrack(i));
200 if(!tr) AliFatal("Not a standard AOD");
201 printf("fOutputUserAOD->GetTrack(%d) = %p pt = %f\n",i,tr,tr->Pt());
206 AliAODHeader * header = dynamic_cast<AliAODHeader*>(fOutputUserAOD->GetHeader());
207 if(!header) AliFatal("Not a standard AOD");
208 header->SetRefMultiplicity(nFWMUonsAdded);
209 header->SetRefMultiplicityPos(nPosTracksAdded);
210 header->SetRefMultiplicityNeg(nNegTracksAdded);
212 fOutputUserHandler -> FinishEvent();
216 PostData(1, fOutputUserAODTree);
224 //===================================================================================
226 void AliAnalysisTaskCreateMixedDimuons::Terminate(Option_t *) {
228 // Called once at the end of the query
230 printf("\n\nCalling TERMINATE \n\n\n");
232 fOutputUserHandler -> Terminate();
236 //===================================================================================