]>
Commit | Line | Data |
---|---|---|
a9457410 | 1 | // $Id$ |
6e9fad59 | 2 | // |
3 | // Task to skim ESD files. | |
4 | // | |
cd231d42 | 5 | // Author: C.Loizides |
a9457410 | 6 | |
7 | #include "AliEsdSkimTask.h" | |
8 | #include <TClonesArray.h> | |
9 | #include <TFile.h> | |
10 | #include <TTree.h> | |
6e9fad59 | 11 | #include "AliAnalysisManager.h" |
bc826438 | 12 | #include "AliCentrality.h" |
a9457410 | 13 | #include "AliESDEvent.h" |
bc826438 | 14 | #include "AliESDFMD.h" |
a9457410 | 15 | #include "AliESDtrackCuts.h" |
bc826438 | 16 | #include "AliEsdTrackExt.h" |
0e003bf1 | 17 | #include "AliEventplane.h" |
76121c9a | 18 | #include "AliInputEventHandler.h" |
a9457410 | 19 | #include "AliMultiplicity.h" |
0e003bf1 | 20 | #include "AliPicoTrack.h" |
76121c9a | 21 | #include "AliVEventHandler.h" |
a9457410 | 22 | |
23 | //_________________________________________________________________________________________________ | |
24 | AliEsdSkimTask::AliEsdSkimTask(const char *opt) : | |
25 | AliAnalysisTaskSE(opt), fEvent(0), fTree(0), fCuts(0), | |
26 | fDoZDC(1), fDoV0(1), fDoT0(1), fDoTPCv(1), fDoSPDv(1), fDoPriv(1), | |
0e003bf1 | 27 | fDoEmCs(1), fDoPCs(0), fDoEmT(1), fDoPT(0), fDoTracks(0), fDoFmd(1), |
28 | fDoMult(1), fDoTof(0), fDoPileup(1), fDoClus(0), fEmcNames(""), | |
06460aec | 29 | fDoMiniTracks(0), fTracks("Tracks"), fPhosClusOnly(0), fEmcalClusOnly(0), |
30 | fDoSaveBytes(0), fDoCent(1), fDoRP(1), fRemoveCP(0), fResetCov(1), | |
31 | fDoPicoTracks(0) | |
a9457410 | 32 | { |
33 | // Constructor. | |
34 | ||
35 | if (!opt) | |
36 | return; | |
37 | ||
bc826438 | 38 | fBranchNames = "ESD:AliESDHeader.,AliESDRun."; |
39 | ||
a9457410 | 40 | DefineOutput(1, TTree::Class()); |
41 | } | |
42 | ||
43 | //_________________________________________________________________________________________________ | |
44 | void AliEsdSkimTask::UserExec(Option_t */*opt*/) | |
45 | { | |
46 | // Process event. | |
47 | ||
48 | AliESDEvent *esdin = dynamic_cast<AliESDEvent*>(InputEvent()); | |
49 | if (!esdin) | |
50 | return; | |
51 | ||
6e9fad59 | 52 | AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager(); |
53 | ||
0e003bf1 | 54 | fEvent->ResetStdContent(); |
a9457410 | 55 | |
6e9fad59 | 56 | TList* objsin = esdin->GetList(); |
57 | TList* objsout = fEvent->GetList(); | |
a9457410 | 58 | |
bc826438 | 59 | AliESDHeader *header = dynamic_cast<AliESDHeader*>(objsout->FindObject("AliESDHeader")); |
a9457410 | 60 | if (header) { |
6e9fad59 | 61 | am->LoadBranch("AliESDHeader."); |
0e003bf1 | 62 | if (!fDoSaveBytes) { |
63 | *header = *esdin->GetHeader(); | |
64 | } else { | |
65 | AliESDHeader *hin = esdin->GetHeader(); | |
66 | header->SetTriggerMask(hin->GetTriggerMask()); | |
67 | header->SetOrbitNumber(hin->GetOrbitNumber()); | |
68 | header->SetTimeStamp(hin->GetTimeStamp()); | |
69 | header->SetEventType(hin->GetEventType()); | |
70 | header->SetEventSpecie(hin->GetEventSpecie()); | |
71 | header->SetEventNumberInFile(hin->GetEventNumberInFile()); | |
72 | header->SetBunchCrossNumber(hin->GetBunchCrossNumber()); | |
73 | header->SetPeriodNumber(hin->GetPeriodNumber()); | |
74 | header->SetTriggerCluster(hin->GetTriggerCluster()); | |
75 | header->SetL0TriggerInputs(hin->GetL0TriggerInputs()); | |
76 | header->SetL1TriggerInputs(hin->GetL1TriggerInputs()); | |
77 | header->SetL2TriggerInputs(hin->GetL2TriggerInputs()); | |
78 | for (Int_t i=0;i<24;++i) { | |
79 | const char *name = hin->GetTriggerInputName(i,0); | |
80 | if (name) | |
81 | header->SetActiveTriggerInputs(name,i); | |
82 | } | |
83 | for (Int_t i=0;i<24;++i) { | |
84 | const char *name = hin->GetTriggerInputName(i,1); | |
85 | if (name) | |
86 | header->SetActiveTriggerInputs(name,i+24); | |
87 | } | |
88 | for (Int_t i=0;i<12;++i) { | |
89 | const char *name = hin->GetTriggerInputName(i,2); | |
90 | if (name) | |
91 | header->SetActiveTriggerInputs(name,i+48); | |
92 | } | |
93 | } | |
76121c9a | 94 | header->SetUniqueID(((AliInputEventHandler*)(am->GetInputEventHandler()))->IsEventSelected()); |
0e003bf1 | 95 | if (am->GetInputEventHandler()) { |
96 | TTree *tree = am->GetInputEventHandler()->GetTree(); | |
97 | if (tree) { | |
98 | TFile *cfile = tree->GetCurrentFile(); | |
99 | if (cfile) { | |
100 | TString cname(cfile->GetName()); | |
101 | header->SetTitle(cname); | |
102 | } | |
103 | } | |
104 | } | |
a9457410 | 105 | } |
bc826438 | 106 | AliESDRun *run = dynamic_cast<AliESDRun*>(objsout->FindObject("AliESDRun")); |
a9457410 | 107 | if (run) { |
6e9fad59 | 108 | am->LoadBranch("AliESDRun."); |
a9457410 | 109 | *run = *esdin->GetESDRun(); |
110 | } | |
06460aec | 111 | AliCentrality *cent = dynamic_cast<AliCentrality*>(objsout->FindObject("Centrality")); |
bc826438 | 112 | if (cent) { |
113 | cent->Reset(); | |
114 | AliCentrality *centin = esdin->GetCentrality(); | |
115 | cent->SetQuality(centin->GetQuality()); | |
116 | cent->SetCentralityV0M(centin->GetCentralityPercentileUnchecked("V0M")); | |
117 | cent->SetCentralityFMD(centin->GetCentralityPercentileUnchecked("FMD")); | |
118 | cent->SetCentralityTRK(centin->GetCentralityPercentileUnchecked("TRK")); | |
119 | cent->SetCentralityTKL(centin->GetCentralityPercentileUnchecked("TKL")); | |
120 | cent->SetCentralityCL0(centin->GetCentralityPercentileUnchecked("CL0")); | |
121 | cent->SetCentralityCL1(centin->GetCentralityPercentileUnchecked("CL1")); | |
122 | cent->SetCentralityV0MvsFMD(centin->GetCentralityPercentileUnchecked("V0MvsFMD")); | |
123 | cent->SetCentralityTKLvsV0M(centin->GetCentralityPercentileUnchecked("TKLvsV0M")); | |
124 | cent->SetCentralityZEMvsZDC(centin->GetCentralityPercentileUnchecked("ZEMvsZDC")); | |
125 | } | |
06460aec | 126 | AliEventplane *ep = dynamic_cast<AliEventplane*>(objsout->FindObject("Eventplane")); |
bc826438 | 127 | if (ep) { |
128 | ep->Reset(); | |
129 | AliEventplane *epin = esdin->GetEventplane(); | |
130 | if (!fDoSaveBytes) { | |
131 | *ep = *epin; | |
132 | } else { | |
133 | if (epin->GetQVector()) { | |
134 | ep->SetQVector(new TVector2(*epin->GetQVector())); | |
135 | ep->SetEventplaneQ(epin->GetEventplane("Q")); | |
136 | ep->SetQsub(new TVector2(*epin->GetQsub1()),new TVector2(*epin->GetQsub2())); | |
137 | ep->SetQsubRes(epin->GetQsubRes()); | |
138 | } | |
139 | } | |
140 | } | |
06460aec | 141 | if (fDoZDC) { |
142 | AliESDZDC *zdc = dynamic_cast<AliESDZDC*>(objsout->FindObject("AliESDZDC")); | |
143 | if (zdc) { | |
144 | am->LoadBranch("AliESDZDC."); | |
145 | *zdc = *esdin->GetESDZDC(); | |
146 | } | |
a9457410 | 147 | } |
06460aec | 148 | if (fDoV0) { |
149 | AliESDVZERO *v0 = dynamic_cast<AliESDVZERO*>(objsout->FindObject("AliESDVZERO")); | |
150 | if (v0) { | |
151 | am->LoadBranch("AliESDVZERO."); | |
152 | *v0 = *esdin->GetVZEROData(); | |
153 | } | |
a9457410 | 154 | } |
06460aec | 155 | if (fDoT0) { |
156 | AliESDTZERO *t0 = dynamic_cast<AliESDTZERO*>(objsout->FindObject("AliESDTZERO")); | |
157 | if (t0) { | |
158 | am->LoadBranch("AliESDTZERO."); | |
159 | *t0 = *esdin->GetESDTZERO(); | |
160 | } | |
a9457410 | 161 | } |
06460aec | 162 | if (fDoTPCv) { |
163 | AliESDVertex *tpcv = dynamic_cast<AliESDVertex*>(objsout->FindObject("TPCVertex")); | |
164 | if (tpcv) { | |
165 | am->LoadBranch("TPCVertex."); | |
166 | *tpcv = *esdin->GetPrimaryVertexTPC(); | |
167 | } | |
a9457410 | 168 | } |
06460aec | 169 | if (fDoSPDv) { |
170 | AliESDVertex *spdv = dynamic_cast<AliESDVertex*>(objsout->FindObject("SPDVertex")); | |
171 | if (spdv) { | |
172 | am->LoadBranch("SPDVertex."); | |
173 | *spdv = *esdin->GetPrimaryVertexSPD(); | |
174 | } | |
a9457410 | 175 | } |
06460aec | 176 | if (fDoPriv) { |
177 | AliESDVertex *priv = dynamic_cast<AliESDVertex*>(objsout->FindObject("PrimaryVertex")); | |
178 | if (priv) { | |
179 | am->LoadBranch("PrimaryVertex."); | |
180 | *priv = *esdin->GetPrimaryVertexTracks(); | |
181 | } | |
a9457410 | 182 | } |
06460aec | 183 | if (fDoEmCs) { |
184 | AliESDCaloCells *ecells = dynamic_cast<AliESDCaloCells*>(objsout->FindObject("EMCALCells")); | |
185 | if (ecells) { | |
186 | am->LoadBranch("EMCALCells."); | |
187 | *ecells = *esdin->GetEMCALCells(); | |
188 | } | |
a9457410 | 189 | } |
06460aec | 190 | if (fDoPCs) { |
191 | AliESDCaloCells *pcells = dynamic_cast<AliESDCaloCells*>(objsout->FindObject("PHOSCells")); | |
192 | if (pcells) { | |
193 | am->LoadBranch("PHOSCells."); | |
194 | *pcells = *esdin->GetPHOSCells(); | |
195 | } | |
a9457410 | 196 | } |
06460aec | 197 | if (fDoEmT) { |
198 | AliESDCaloTrigger *etrig = dynamic_cast<AliESDCaloTrigger*>(objsout->FindObject("EMCALTrigger")); | |
199 | if (etrig) { | |
200 | am->LoadBranch("EMCALTrigger."); | |
201 | *etrig = *esdin->GetCaloTrigger("EMCAL"); | |
202 | } | |
a9457410 | 203 | } |
06460aec | 204 | if (fDoPT) { |
205 | AliESDCaloTrigger *ptrig = dynamic_cast<AliESDCaloTrigger*>(objsout->FindObject("PHOSTrigger")); | |
206 | if (ptrig) { | |
207 | am->LoadBranch("PHOSTrigger."); | |
208 | *ptrig = *esdin->GetCaloTrigger("PHOS"); | |
bc826438 | 209 | } |
210 | } | |
06460aec | 211 | if (fDoFmd) { |
212 | AliESDFMD *fmd = dynamic_cast<AliESDFMD*>(objsout->FindObject("AliESDFMD")); | |
213 | if (fmd) { | |
214 | am->LoadBranch("AliESDFMD."); | |
215 | if (!fDoSaveBytes) { | |
216 | *fmd = *esdin->GetFMDData(); | |
217 | } | |
bc826438 | 218 | } |
a9457410 | 219 | } |
06460aec | 220 | if (fDoMult) { |
221 | AliMultiplicity *mult = dynamic_cast<AliMultiplicity*>(objsout->FindObject("AliMultiplicity")); | |
222 | if (mult) { | |
223 | am->LoadBranch("AliMultiplicity."); | |
224 | if (!fDoSaveBytes) { | |
225 | *mult = *esdin->GetMultiplicity(); | |
226 | } else { | |
227 | const AliMultiplicity *multin = esdin->GetMultiplicity();; | |
228 | mult->SetFiredChips(0, multin->GetNumberOfFiredChips(0)); | |
229 | mult->SetFiredChips(1, multin->GetNumberOfFiredChips(1)); | |
230 | for (Int_t i=0; i<6; ++i) | |
231 | mult->SetITSClusters(i,multin->GetNumberOfITSClusters(i)); | |
232 | } | |
233 | } | |
a9457410 | 234 | } |
06460aec | 235 | if (fDoTof) { |
236 | AliTOFHeader *tofh = dynamic_cast<AliTOFHeader*>(objsout->FindObject("AliTOFHeader")); | |
237 | if (tofh) { | |
238 | am->LoadBranch("AliTOFHeader."); | |
239 | *tofh = *esdin->GetTOFHeader(); | |
a9457410 | 240 | } |
241 | } | |
06460aec | 242 | if (fDoPileup) { |
243 | TClonesArray *spup = dynamic_cast<TClonesArray*>(objsout->FindObject("SPDPileupVertices")); | |
244 | if (spup) { | |
245 | am->LoadBranch("SPDPileupVertices"); | |
246 | Int_t N = esdin->GetNumberOfPileupVerticesSPD(); | |
247 | for (Int_t i=0; i<N; ++i) { | |
248 | const AliESDVertex *vtx = esdin->GetPileupVertexSPD(i); | |
249 | if (vtx) | |
250 | fEvent->AddPileupVertexSPD(vtx); | |
251 | } | |
252 | } | |
253 | TClonesArray *tpup = dynamic_cast<TClonesArray*>(objsout->FindObject("TrkPileupVertices")); | |
254 | if (tpup) { | |
255 | am->LoadBranch("TrkPileupVertices"); | |
256 | Int_t N = esdin->GetNumberOfPileupVerticesTracks(); | |
257 | for (Int_t i=0; i<N; ++i) { | |
258 | const AliESDVertex *vtx = esdin->GetPileupVertexTracks(i); | |
259 | if (vtx) | |
260 | fEvent->AddPileupVertexTracks(vtx); | |
261 | } | |
a9457410 | 262 | } |
263 | } | |
06460aec | 264 | if (fDoClus) { |
265 | TClonesArray *clus = dynamic_cast<TClonesArray*>(objsout->FindObject("CaloClusters")); | |
266 | if (clus) { | |
267 | am->LoadBranch("CaloClusters"); | |
268 | Int_t N = esdin->GetNumberOfCaloClusters(); | |
269 | for (Int_t i=0; i<N; ++i) { | |
270 | AliESDCaloCluster *c = esdin->GetCaloCluster(i); | |
271 | if (!c) | |
272 | continue; | |
273 | if (fPhosClusOnly && c->IsEMCAL()) | |
274 | continue; | |
275 | if (fEmcalClusOnly && c->IsPHOS()) | |
276 | continue; | |
a9457410 | 277 | fEvent->AddCaloCluster(c); |
06460aec | 278 | } |
a9457410 | 279 | } |
280 | } | |
6e9fad59 | 281 | TObjArray *namearr = fEmcNames.Tokenize(";"); |
282 | if (namearr) { | |
283 | for (Int_t i=0; i<namearr->GetEntries(); ++i) { | |
284 | TString cname(namearr->At(i)->GetName()); | |
285 | if (cname.Length()<=0) | |
286 | continue; | |
287 | TClonesArray *arrin = dynamic_cast<TClonesArray*>(objsin->FindObject(cname)); | |
bc826438 | 288 | if (!arrin) { |
289 | AliFatal(Form("Can not find input clusters with name %s", cname.Data())); | |
290 | return; | |
291 | } | |
6e9fad59 | 292 | TClonesArray *arrout = dynamic_cast<TClonesArray*>(objsout->FindObject(cname)); |
bc826438 | 293 | if (!arrout) { |
294 | AliFatal(Form("Can not find output clusters with name %s", cname.Data())); | |
295 | return; | |
296 | } | |
6e9fad59 | 297 | arrout->Delete(); |
eb997149 | 298 | Double_t emin=0.1; |
299 | if (cname.Contains("FEE")) | |
300 | emin = 1; | |
6e9fad59 | 301 | const Int_t N = arrin->GetEntries(); |
302 | for (Int_t iC=0, nC=0; iC<N; ++iC) { | |
303 | AliESDCaloCluster *c = dynamic_cast<AliESDCaloCluster*>(arrin->At(iC)); | |
304 | if (!c) | |
305 | continue; | |
eb997149 | 306 | if (c->E()<emin) |
307 | continue; | |
0e003bf1 | 308 | AliESDCaloCluster *newCluster = new ((*arrout)[nC]) AliESDCaloCluster(*c); |
309 | newCluster->SetID(nC); | |
310 | ++nC; | |
6e9fad59 | 311 | } |
312 | } | |
313 | delete namearr; | |
314 | } | |
a9457410 | 315 | if (fDoTracks) { |
06460aec | 316 | if (fTracks == "Tracks") |
317 | am->LoadBranch("Tracks"); | |
bc826438 | 318 | TClonesArray *tracksin = dynamic_cast<TClonesArray*>(objsin->FindObject(fTracks)); |
319 | if (!tracksin) { | |
6e9fad59 | 320 | AliFatal(Form("Can not find tracks with name %s", fTracks.Data())); |
321 | return; | |
322 | } | |
06460aec | 323 | TString trkoutname("Tracks"); |
324 | if (fDoPicoTracks) | |
325 | trkoutname = "PicoTracks"; | |
326 | TClonesArray *tracksout = 0; | |
327 | tracksout = dynamic_cast<TClonesArray*>(objsout->FindObject(trkoutname)); | |
bc826438 | 328 | if (!tracksout) { |
06460aec | 329 | AliFatal(Form("Can not find tracks with name %s", trkoutname.Data())); |
bc826438 | 330 | return; |
331 | } | |
06460aec | 332 | tracksout->Delete(); |
333 | TString classname(tracksin->GetClass()->GetName()); | |
334 | if (classname == "AliPicoTrack") { | |
335 | if (!fDoPicoTracks) { | |
336 | AliFatal(Form("Need to enable fDoPicoTracks when reading AliPicoTracks")); | |
337 | return; | |
338 | } | |
339 | const Int_t Ntracks = tracksin->GetEntries(); | |
340 | for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) { | |
341 | AliPicoTrack *track = dynamic_cast<AliPicoTrack*>(tracksin->At(iTracks)); | |
06460aec | 342 | if (!track) |
a9457410 | 343 | continue; |
06460aec | 344 | new ((*tracksout)[nacc]) AliPicoTrack(*track); |
345 | ++nacc; | |
a9457410 | 346 | } |
06460aec | 347 | } else { |
348 | const Int_t Ntracks = tracksin->GetEntries(); | |
349 | for (Int_t iTracks = 0, nacc = 0; iTracks < Ntracks; ++iTracks) { | |
350 | AliESDtrack *track = dynamic_cast<AliESDtrack*>(tracksin->At(iTracks)); | |
351 | if (!track) | |
352 | continue; | |
353 | if (fCuts) { | |
354 | if (!fCuts->IsSelected(track)) | |
355 | continue; | |
0e003bf1 | 356 | } |
06460aec | 357 | if (fDoPicoTracks) { |
358 | AliEsdTrackExt newtrack(*track); | |
359 | Double_t etaemc = 0; | |
360 | Double_t phiemc = 0; | |
361 | if (newtrack.IsEMCAL()) { | |
362 | etaemc = newtrack.GetEmcEta(); | |
363 | phiemc = newtrack.GetEmcPhi(); | |
364 | } | |
365 | new ((*tracksout)[nacc]) AliPicoTrack(newtrack.Pt(), newtrack.Eta(), newtrack.Phi(), | |
366 | newtrack.Charge(), newtrack.GetLabel(), | |
367 | etaemc, phiemc, newtrack.IsEMCAL()); | |
368 | ++nacc; | |
0e003bf1 | 369 | } else { |
06460aec | 370 | AliEsdTrackExt *newtrack = new ((*tracksout)[nacc]) AliEsdTrackExt(*track); |
371 | if (fDoMiniTracks) { | |
372 | newtrack->MakeMiniTrack(0,fRemoveCP); | |
373 | newtrack->ResetCovariance(fResetCov); | |
374 | } else { | |
375 | newtrack->DeleteParams(); | |
376 | } | |
377 | newtrack->SetID(nacc); | |
378 | ++nacc; | |
0e003bf1 | 379 | } |
6e9fad59 | 380 | } |
a9457410 | 381 | } |
a9457410 | 382 | } |
383 | fTree->Fill(); | |
384 | } | |
385 | ||
386 | //_________________________________________________________________________________________________ | |
387 | void AliEsdSkimTask::UserCreateOutputObjects() | |
388 | { | |
389 | // Create output objects. | |
390 | ||
0e003bf1 | 391 | TFile *file = OpenFile(1); |
6e9fad59 | 392 | fTree = new TTree("esdTree", "Tree with skimmed ESD objects"); |
06460aec | 393 | file->SetCompressionLevel(5); |
0e003bf1 | 394 | fTree->SetDirectory(file); |
395 | fTree->SetAutoFlush(-10*1024*1024); | |
396 | ||
a9457410 | 397 | fEvent = new AliESDEvent; |
06460aec | 398 | fEvent->CreateStdContent(); |
bc826438 | 399 | if (fDoCent) { |
400 | AliCentrality *cent = new AliCentrality; | |
bc826438 | 401 | fEvent->AddObject(cent); |
402 | } | |
403 | if (fDoRP) { | |
404 | AliEventplane *ep = new AliEventplane; | |
bc826438 | 405 | fEvent->AddObject(ep); |
406 | } | |
6e9fad59 | 407 | TObjArray *namearr = fEmcNames.Tokenize(";"); |
408 | if (namearr) { | |
409 | for (Int_t i=0; i<namearr->GetEntries(); ++i) { | |
410 | TString cname(namearr->At(i)->GetName()); | |
411 | if (cname.Length()<=0) | |
412 | continue; | |
413 | TClonesArray *arr = new TClonesArray("AliESDCaloCluster",0); | |
414 | arr->SetName(cname); | |
415 | fEvent->AddObject(arr); | |
416 | } | |
417 | delete namearr; | |
418 | } | |
419 | if (fDoTracks) { | |
0e003bf1 | 420 | if (fDoPicoTracks) { |
06460aec | 421 | TClonesArray *arr = new TClonesArray("AliPicoTrack",0); |
422 | arr->SetName("PicoTracks"); | |
423 | fEvent->AddObject(arr); | |
bc826438 | 424 | } else { |
06460aec | 425 | TObject *obj = fEvent->GetList()->FindObject("Tracks"); |
426 | fEvent->GetList()->Remove(obj); | |
427 | TClonesArray *arr = new TClonesArray("AliEsdTrackExt",0); | |
bc826438 | 428 | arr->SetName("Tracks"); |
06460aec | 429 | fEvent->AddObject(arr); |
bc826438 | 430 | } |
6e9fad59 | 431 | } |
a9457410 | 432 | fEvent->GetStdContent(); |
433 | fEvent->WriteToTree(fTree); | |
434 | fTree->GetUserInfo()->Add(fEvent); | |
a9457410 | 435 | PostData(1,fTree); |
436 | } |