]>
Commit | Line | Data |
---|---|---|
71b7d225 | 1 | #define AliAnalysisTaskMuonAODfromGeneral_cxx |
2 | ||
27de2dfb | 3 | /* $Id$ */ |
4 | ||
71b7d225 | 5 | // 19 Nov 2007 |
aba89748 | 6 | // Class implementation for the specific muon AOD generation |
7 | // Extracts only muon tracks from a general AOD and builds dimuons | |
8 | // Livio Bianchi, Universita' di Torino | |
9 | ||
71b7d225 | 10 | |
11 | #include "TTree.h" | |
12 | #include "TROOT.h" | |
13 | #include "TH1.h" | |
14 | #include "TCanvas.h" | |
15 | #include "TSystem.h" | |
16 | #include "TRandom.h" | |
17 | ||
18 | #include "AliAODEvent.h" | |
aba89748 | 19 | #include "AliAnalysisTask.h" |
71b7d225 | 20 | #include "AliAnalysisTaskMuonAODfromGeneral.h" |
21 | #include "AliAODHandler.h" | |
22 | #include "AliAnalysisManager.h" | |
23 | #include "AliAODEventInfo.h" | |
24 | #include "AliAODDimuon.h" | |
25 | ||
26 | ClassImp(AliAnalysisTaskMuonAODfromGeneral) | |
27 | ||
28 | //________________________________________________________________________ | |
29 | AliAnalysisTaskMuonAODfromGeneral::AliAnalysisTaskMuonAODfromGeneral(const char *name, Double_t BeamEnergy): | |
30 | AliAnalysisTask(name, "AnalysisTaskMuonAODfromGeneral"), | |
31 | fInfos(0), | |
32 | fDimuons(0), | |
8b8b0b7a | 33 | fChain(0), |
34 | fOrgAOD(0), | |
71b7d225 | 35 | fNewAOD(0), |
36 | ft(0), | |
37 | fBeamEnergy(0) | |
38 | { // Constructor. | |
39 | // Input slot #0 works with an Ntuple | |
40 | SetBeamEnergy(BeamEnergy); | |
41 | DefineInput(0, TChain::Class()); | |
42 | // Output slot #0 writes into a TTree container | |
43 | DefineOutput(0, TTree::Class()); | |
44 | } | |
45 | ||
46 | //________________________________________________________________________ | |
47 | void AliAnalysisTaskMuonAODfromGeneral::ConnectInputData(Option_t *) { | |
48 | printf(" ConnectInputData %s\n", GetName()); | |
49 | // New connection to the AOD | |
50 | fChain = (TChain*)GetInputData(0); | |
51 | fOrgAOD = new AliAODEvent(); | |
52 | fOrgAOD->ReadFromTree(fChain); // This checks also if the branch address is already set | |
53 | } | |
54 | ||
55 | //________________________________________________________________________ | |
56 | void AliAnalysisTaskMuonAODfromGeneral::CreateOutputObjects() { | |
57 | printf("Creating output objects\n"); | |
58 | if(!fNewAOD)fNewAOD=new AliAODEvent(); | |
59 | fNewAOD->CreateStdContent(); | |
60 | ||
61 | if (!ft) { | |
62 | ft = new TTree("AOD","Muon AOD tree",0); | |
63 | ft->BranchRef(); | |
64 | ft->Branch(fNewAOD->GetList()); | |
65 | //ft->Print(); | |
66 | } | |
67 | ||
68 | //Add new Objects: MuonInfos & Dimuons | |
69 | fInfos = new AliAODEventInfo(); | |
70 | fNewAOD->AddObject(fInfos); | |
71 | const char *nameInfos = "MuonInfos"; | |
72 | fInfos->SetName(nameInfos); | |
73 | ft->Branch(nameInfos, &fInfos); | |
74 | fDimuons = new TClonesArray("AliAODDimuon",0); | |
75 | fNewAOD->AddObject(fDimuons); | |
76 | const char *nameDimuons = "Dimuons"; | |
77 | fDimuons->SetName(nameDimuons); | |
78 | ft->Branch(nameDimuons, &fDimuons); | |
79 | ||
80 | } | |
81 | ||
82 | //________________________________________________________________________ | |
83 | void AliAnalysisTaskMuonAODfromGeneral::Exec(Option_t *) { | |
84 | static int ncall=0; | |
85 | // Task making a Muon AOD | |
86 | // Get input data | |
87 | TChain *chain = (TChain*)GetInputData(0); | |
88 | Long64_t ientry = chain->GetReadEntry(); | |
89 | ientry=ientry; | |
90 | ||
91 | if (!fOrgAOD) return; | |
92 | ||
93 | Int_t nTracks=fOrgAOD->GetNumberOfTracks(); | |
94 | Int_t nMuTracks=0; | |
95 | Int_t nPosTracks = 0; | |
a6e0ebfe | 96 | Int_t mutrNumb[10]; for (Int_t i=0; i<10; mutrNumb[i++]=0) {} |
71b7d225 | 97 | for (Int_t iTrack=0; iTrack<nTracks; iTrack++){ |
98 | const Double_t *trackpid=fOrgAOD->GetTrack(iTrack)->PID(); | |
99 | if (trackpid[AliAODTrack::kMuon]==1.) { | |
100 | mutrNumb[nMuTracks]=iTrack; | |
101 | nMuTracks++; | |
102 | } | |
103 | if (fOrgAOD->GetTrack(iTrack)->Charge()> 0) nPosTracks++; | |
104 | } | |
105 | ||
106 | Bool_t ExistMuon=kFALSE; | |
107 | if (nMuTracks>0) ExistMuon=kTRUE; | |
108 | ||
109 | //-------------------------------------------------------------------- | |
110 | // set arrays and pointers | |
111 | Double_t pos[3]; | |
112 | Double_t covVtx[6]; | |
113 | ||
114 | // Access to the header | |
115 | AliAODHeader *header = fNewAOD->GetHeader(); | |
116 | ||
117 | // fill the header | |
118 | header->SetRunNumber (fOrgAOD->GetRunNumber() ); | |
119 | header->SetBunchCrossNumber(fOrgAOD->GetBunchCrossNumber()); | |
120 | header->SetOrbitNumber (fOrgAOD->GetOrbitNumber() ); | |
121 | header->SetPeriodNumber (fOrgAOD->GetPeriodNumber() ); | |
122 | header->SetTriggerMask (fOrgAOD->GetTriggerMask() ); | |
123 | header->SetTriggerCluster (fOrgAOD->GetTriggerCluster() ); | |
124 | header->SetEventType (fOrgAOD->GetEventType() ); | |
125 | header->SetMagneticField (fOrgAOD->GetMagneticField() ); | |
126 | header->SetZDCN1Energy (fOrgAOD->GetZDCN1Energy() ); | |
127 | header->SetZDCP1Energy (fOrgAOD->GetZDCP1Energy() ); | |
128 | header->SetZDCN2Energy (fOrgAOD->GetZDCN2Energy() ); | |
129 | header->SetZDCP2Energy (fOrgAOD->GetZDCP2Energy() ); | |
130 | header->SetZDCEMEnergy (0,fOrgAOD->GetZDCEMEnergy(0) ); | |
131 | header->SetZDCEMEnergy (1,fOrgAOD->GetZDCEMEnergy(1) ); | |
132 | header->SetRefMultiplicity (nTracks); | |
133 | header->SetRefMultiplicityPos(nPosTracks); | |
134 | header->SetRefMultiplicityNeg(nTracks - nPosTracks); | |
135 | header->SetMuonMagFieldScale(-999.); // FIXME | |
4649c75b | 136 | header->SetCentrality(0); // FIXME |
71b7d225 | 137 | |
71b7d225 | 138 | const AliAODVertex *vtx = fOrgAOD->GetPrimaryVertex(); |
b0c84a07 | 139 | if ( !vtx) { |
140 | // CHECK Gines | |
141 | AliError("Primary vertex is not defined"); | |
142 | return; | |
143 | } | |
71b7d225 | 144 | |
145 | Int_t nDimuons=nMuTracks*(nMuTracks-1)/2; | |
146 | ||
147 | // Access to the AOD container of vertices | |
148 | TClonesArray &vertices = *(fNewAOD->GetVertices()); | |
149 | Int_t jVertices=0; | |
150 | ||
151 | // Access to the AOD container of tracks | |
152 | TClonesArray &tracks = *(fNewAOD->GetTracks()); | |
153 | tracks.Delete(); | |
154 | Int_t jTracks=0; | |
155 | ||
156 | ||
157 | vtx->GetCovMatrix(covVtx); //covariance matrix | |
158 | ||
159 | AliAODVertex * primary = new(vertices[jVertices++]) | |
160 | AliAODVertex(pos, covVtx, vtx->GetChi2perNDF(), NULL, AliAODVertex::kPrimary); | |
161 | ||
162 | static int ncal=0; | |
163 | static int numtracks=0; | |
164 | for (Int_t iTrack=0; iTrack<nMuTracks; iTrack++) { | |
b0c84a07 | 165 | primary->AddDaughter(new(tracks[jTracks++]) |
71b7d225 | 166 | AliAODTrack((*(fOrgAOD->GetTrack(mutrNumb[iTrack]))))); |
167 | ncal++; | |
168 | } | |
169 | numtracks+=jTracks; | |
170 | ||
171 | fDimuons->Delete(); | |
172 | fDimuons->Expand(nDimuons); | |
173 | TClonesArray &rDimuons = *fDimuons; | |
174 | ||
175 | Int_t jDimuons=0; | |
176 | for(Int_t i=0; i<nMuTracks; i++){ | |
177 | for(Int_t j=i+1; j<nMuTracks; j++){ | |
866d8d78 | 178 | new(rDimuons[jDimuons++]) AliAODDimuon(tracks[i],tracks[j]); |
71b7d225 | 179 | } |
180 | } | |
181 | ||
182 | fInfos->SetBeamEnergy(fBeamEnergy); | |
aba89748 | 183 | fInfos->SetEv(fNewAOD); |
aba89748 | 184 | fInfos->SetHe(header); |
185 | fInfos->SetTr(fNewAOD->GetTracks()); | |
186 | fInfos->SetDi(fDimuons); | |
187 | fInfos->SelectTriggerBits(0,1,2,3,4,5); | |
71b7d225 | 188 | if(ExistMuon) ft->Fill(); |
189 | ncall++; | |
190 | ||
191 | // Post final data. It will be written to a file with option "RECREATE" | |
192 | PostData(0, ft); | |
193 | } | |
194 | ||
195 | //________________________________________________________________________ | |
196 | void AliAnalysisTaskMuonAODfromGeneral::Terminate(Option_t *) { | |
197 | // Draw some histogram at the end. | |
198 | ft->GetUserInfo()->Add(fNewAOD); | |
199 | ft->Write("",TObject::kOverwrite); | |
200 | ft->ResetBranchAddresses(); | |
201 | if (!gROOT->IsBatch()) { | |
202 | TCanvas *c1 = new TCanvas("c1","Pt",10,10,310,310); | |
203 | c1->SetFillColor(10); | |
204 | c1->SetHighLightColor(10); | |
205 | ||
206 | c1->cd(1)->SetLeftMargin(0.15); | |
207 | c1->cd(1)->SetBottomMargin(0.15); | |
208 | c1->cd(1)->SetLogy(); | |
209 | ft->Draw("tracks.Pt()"); | |
210 | //ft->Draw("dimuons.M()"); | |
211 | } | |
212 | } |