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