AliPhysics  608b256 (608b256)
AliCopyHeaderTask.cxx
Go to the documentation of this file.
1 
11 #include "AliCopyHeaderTask.h"
12 #include "AliESDEvent.h"
13 #include "AliAODEvent.h"
14 #include "AliCentrality.h"
15 #include "AliInputEventHandler.h"
16 #include "TFile.h"
17 #include "AliEventplane.h"
18 #include "AliESDVertex.h"
19 #include "AliAODVertex.h"
20 #include "AliESDtrackCuts.h"
21 #include "AliAnalysisManager.h"
22 #include "AliMultSelection.h"
23 #include "AliAODHandler.h"
24 
25 ClassImp(AliCopyHeaderTask)
26 #if 0
27 ; // for emacs - do not remove
28 #endif
29 
30 
31 //____________________________________________________________________
34 {
35  if (this == &other) return *this;
36  AliAnalysisTaskSE::operator=(other);
40  fCopyV0 = other.fCopyV0;
41  fCopyAD = other.fCopyAD;
42  fCopyZDC = other.fCopyZDC;
43  if (fMultSelection) {
44  delete fMultSelection;
45  fMultSelection = 0;
46  }
47  if (other.fMultSelection)
48  fMultSelection = new AliMultSelection(*other.fMultSelection);
49  return *this;
50 }
51 
52 //____________________________________________________________________
54  : AliAnalysisTaskSE(other),
58  fCopyV0(other.fCopyV0),
59  fCopyAD(other.fCopyAD),
60  fCopyZDC(other.fCopyZDC),
62 {
63  if (other.fMultSelection)
64  fMultSelection = new AliMultSelection(*other.fMultSelection);
65 }
66 
67 //____________________________________________________________________
68 void
70 {
71  TObjArray* tokens = what.Tokenize(",");
72  TObject* token = 0;
73  TIter next(tokens);
74  while ((token = next())) {
75  TString opt(token->GetName());
76  Bool_t enable = true;
77  Int_t rem = 0;
78  if (opt.BeginsWith("+")) { rem = 1; enable = true; }
79  else if (opt.BeginsWith("-")) { rem = 1; enable = false; }
80  if (rem > 0) opt.Remove(0,1);
81 
82  opt.ToLower();
83 
84  if (opt.BeginsWith("cent")) SetCopyCentrality(enable);
85  else if (opt.BeginsWith("trac")) SetCopyTracklets(enable);
86  else if (opt.BeginsWith("v0") || opt.BeginsWith("vzero"))
87  SetCopyV0(enable);
88  else if (opt.BeginsWith("ad")) SetCopyAD(enable);
89  else if (opt.BeginsWith("zdc")) SetCopyZDC(enable);
90  else if (opt.BeginsWith("ref")) SetCalculateRefMult(enable);
91  }
92  tokens->Delete();
93 }
94 
95 
96 
97 //____________________________________________________________________
98 void
100 {
101  if (!fCopyCentrality) return;
102 
103  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
104  AliAODHandler* ah =
105  dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
106  if (!ah) {
107  AliWarning("No AOD output handler set in analysis manager");
108  return;
109  }
110 
111  fMultSelection = new AliMultSelection("MultSelection");
112  ah->AddBranch("AliMultSelection", &fMultSelection);
113 }
114 //____________________________________________________________________
115 void
117 {
118  //
119  // Called at every event
120  //
121  // Copies information from ESD header to AOD header
122  //
123 
124  // --- Get the I/O objects -----------------------------------------
125  AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
126  AliAODEvent* aod = dynamic_cast<AliAODEvent*>(AODEvent());
127  if (!esd) {
128  AliWarning("Missing ESD event");
129  return;
130  }
131  if (!aod) {
132  AliWarning("Missing AOD event");
133  return;
134  }
135 
136  // --- Load the data -----------------------------------------------
137  LoadBranches();
138 
139  // --- Get or create the header ------------------------------------
140  AliAODHeader* aodHeader = dynamic_cast<AliAODHeader*>(aod->GetHeader());
141  if(!aodHeader) AliFatal("Not a standard AOD");
142  if (!aodHeader) {
143  AliWarning("Missing AOD header");
144  aodHeader = new AliAODHeader(esd->GetRunNumber(),
145  esd->GetBunchCrossNumber(),
146  esd->GetOrbitNumber(),
147  esd->GetPeriodNumber());
148  aod->AddHeader(aodHeader);
149  }
150 
151  // --- Various event/run stuff -------------------------------------
152  aodHeader->SetRunNumber(esd->GetRunNumber());
153  aodHeader->SetOfflineTrigger(fInputHandler->IsEventSelected());
154  aodHeader->SetBunchCrossNumber(esd->GetBunchCrossNumber());
155  aodHeader->SetOrbitNumber(esd->GetOrbitNumber());
156  aodHeader->SetPeriodNumber(esd->GetPeriodNumber());
157  aodHeader->SetEventType(esd->GetEventType());
158  aodHeader->SetEventNumberESDFile(esd->GetHeader()->GetEventNumberInFile());
159 
160  // --- Centrality --------------------------------------------------
161  if(esd->GetCentrality())
162  aodHeader->SetCentrality(esd->GetCentrality());
163  else
164  aodHeader->SetCentrality(0);
165 
166  // --- Trigger -----------------------------------------------------
167  aodHeader->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
168  aodHeader->SetTriggerMask(esd->GetTriggerMask());
169  aodHeader->SetTriggerCluster(esd->GetTriggerCluster());
170  aodHeader->SetL0TriggerInputs(esd->GetHeader()->GetL0TriggerInputs());
171  aodHeader->SetL1TriggerInputs(esd->GetHeader()->GetL1TriggerInputs());
172  aodHeader->SetL2TriggerInputs(esd->GetHeader()->GetL2TriggerInputs());
173 
174  // --- Magnetic field, ZDC signal ----------------------------------
175  aodHeader->SetMagneticField(esd->GetMagneticField());
176  aodHeader->SetMuonMagFieldScale(esd->GetCurrentDip()/6000.);
177  aodHeader->SetZDCN1Energy(esd->GetZDCN1Energy());
178  aodHeader->SetZDCP1Energy(esd->GetZDCP1Energy());
179  aodHeader->SetZDCN2Energy(esd->GetZDCN2Energy());
180  aodHeader->SetZDCP2Energy(esd->GetZDCP2Energy());
181  aodHeader->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
182 
183  // --- V channel equalization factors ------------------------------
184  aodHeader->SetVZEROEqFactors(esd->GetVZEROEqFactors());
185 
186 
187  // --- Interacting beams -------------------------------------------
188  AliESDHeader* esdHeader = esd->GetHeader();
189  if (esdHeader) {
190  aodHeader->SetIRInt2InteractionMap(esdHeader->GetIRInt2InteractionMap());
191  aodHeader->SetIRInt1InteractionMap(esdHeader->GetIRInt1InteractionMap());
192  }
193 
194  // --- ESD file name -----------------------------------------------
195  TTree* tree = fInputHandler->GetTree();
196  if (tree) {
197  TFile* file = tree->GetCurrentFile();
198  if (file) aodHeader->SetESDFileName(file->GetName());
199  }
200 
201  // --- TPC event plane ---------------------------------------------
202  AliEventplane* ep = esd->GetEventplane();
203  if (ep) aodHeader->SetEventplane(ep);
204 
205  // --- Copy primary vertices ---------------------------------------
206  CopyVertex(*aod, esd->GetPrimaryVertex(), AliAODVertex::kPrimary);
207  CopyVertex(*aod, esd->GetPrimaryVertexSPD(), AliAODVertex::kMainSPD);
208  CopyVertex(*aod, esd->GetPrimaryVertexTPC(), AliAODVertex::kMainTPC);
209 
210  // --- Loop over pile-ups vertices ---------------------------------
211  for (Int_t i = 0; i < esd->GetNumberOfPileupVerticesSPD(); i++)
212  CopyVertex(*aod, esd->GetPileupVertexSPD(i), AliAODVertex::kPileupSPD);
213  for (Int_t i = 0; i < esd->GetNumberOfPileupVerticesTracks(); i++)
214  CopyVertex(*aod, esd->GetPileupVertexTracks(i),AliAODVertex::kPileupTracks);
215 
216 
217  // --- Reference multiplicities ------------------------------------
218  if (fCalculateRefMult) {
219  AliESDtrackCuts::MultEstTrackType estType =
220  esd->GetPrimaryVertexTracks()->GetStatus()
221  ? AliESDtrackCuts::kTrackletsITSTPC
222  : AliESDtrackCuts::kTracklets;
223  Int_t mult05 = AliESDtrackCuts::GetReferenceMultiplicity(esd,estType,0.5);
224  Int_t mult08 = AliESDtrackCuts::GetReferenceMultiplicity(esd,estType,0.8);
225  aodHeader->SetRefMultiplicityComb05(mult05);
226  aodHeader->SetRefMultiplicityComb08(mult08);
227  }
228  // --- Copy multiplicity object ------------------------------------
229  // AliAnalysisTaskESDfilter::ConvertTracklets(const AliESDEvent& esd)
230  if (fCopyTracklets) {
231  AliMultiplicity* mul = esd->GetMultiplicity();
232  AliAODTracklets* tracklets = (aod->GetTracklets());
233  if (mul && mul->GetNumberOfTracklets() > 0 && tracklets) {
234  Int_t nTracklets = mul->GetNumberOfTracklets();
235  tracklets->CreateContainer(nTracklets);
236  for (Int_t i = 0; i < nTracklets; i++) {
237  tracklets->SetTracklet(i,
238  mul->GetTheta(i),
239  mul->GetPhi(i),
240  mul->GetDeltaPhi(i),
241  mul->GetLabel(i, 0),
242  mul->GetLabel(i, 1));
243  }
244  tracklets->SetFiredChipMap (mul->GetFiredChipMap());
245  tracklets->SetFastOrFiredChipMap(mul->GetFastOrFiredChipMap());
246  tracklets->SetFiredChips (0, mul->GetNumberOfFiredChips(0));
247  tracklets->SetFiredChips (1, mul->GetNumberOfFiredChips(1));
248  }
249  }
250 
251  // --- Copy V0 data ------------------------------------------------
252  if (fCopyV0) {
253  AliAODVZERO* vzeroData = aod->GetVZEROData();
254  *vzeroData = *(esd->GetVZEROData());
255  }
256  // --- Copy V0 data ------------------------------------------------
257  if (fCopyAD) {
258  AliAODAD* adData = aod->GetADData();
259  *adData = *(esd->GetADData());
260  }
261  // --- Copy ZDC data ------------------------------------------------
262  if (fCopyZDC) {
263  AliESDZDC* esdZDC = esd->GetZDCData();
264  AliAODZDC* zdcAOD = aod->GetZDCData();
265  zdcAOD->SetZEM1Energy(esdZDC->GetZEM1Energy());
266  zdcAOD->SetZEM2Energy(esdZDC->GetZEM2Energy());
267  zdcAOD->SetZNCTowers(esdZDC->GetZNCTowerEnergy(),
268  esdZDC->GetZNCTowerEnergyLR());
269  zdcAOD->SetZNATowers(esdZDC->GetZNATowerEnergy(),
270  esdZDC->GetZNATowerEnergyLR());
271  zdcAOD->SetZPCTowers(esdZDC->GetZPCTowerEnergy(),
272  esdZDC->GetZPCTowerEnergyLR());
273  zdcAOD->SetZPATowers(esdZDC->GetZPATowerEnergy(),
274  esdZDC->GetZPATowerEnergyLR());
275  zdcAOD->SetZDCParticipants(esdZDC->GetZDCParticipants(),
276  esdZDC->GetZDCPartSideA(),
277  esdZDC->GetZDCPartSideC());
278  zdcAOD->SetZDCImpactParameter(esdZDC->GetImpactParameter(),
279  esdZDC->GetImpactParamSideA(),
280  esdZDC->GetImpactParamSideC());
281  zdcAOD->SetZDCTDCSum(esdZDC->GetZNTDCSum(0));
282  zdcAOD->SetZDCTDCDiff(esdZDC->GetZNTDCDiff(0));
283  if(esdZDC->IsZNChit()){
284  Int_t cable = 10;
285  if(esdZDC->IsZDCTDCcablingSet()){ // RUN2
286  if(esdZDC->GetZNCTDCChannel()>0)
287  cable = esdZDC->GetZNCTDCChannel();
288  else
289  cable = 16;
290  }
291  zdcAOD->SetZNCTDC(esdZDC->GetZDCTDCCorrected(cable, 0)); //RUN1
292  }
293  if(esdZDC->IsZNAhit()){
294  Int_t cable = 12;
295  if(esdZDC->IsZDCTDCcablingSet()){ // RUN2
296  if(esdZDC->GetZNATDCChannel()>0)
297  cable = esdZDC->GetZNATDCChannel();
298  else
299  cable = 18;
300  }
301  zdcAOD->SetZNATDC(esdZDC->GetZDCTDCCorrected(cable, 0));
302  }
303  if(esdZDC->IsZPChit()){
304  Int_t cable = 11;
305  if(esdZDC->IsZDCTDCcablingSet()){ // RUN2
306  if(esdZDC->GetZPCTDCChannel()>0)
307  cable = esdZDC->GetZPCTDCChannel();
308  else
309  cable = 17;
310  }
311  zdcAOD->SetZPCTDC(esdZDC->GetZDCTDCCorrected(cable, 0));
312  }
313  if(esdZDC->IsZPAhit()){
314  Int_t cable = 13;
315  if(esdZDC->IsZDCTDCcablingSet()){ // RUN2
316  if(esdZDC->GetZPATDCChannel()>0)
317  cable = esdZDC->GetZPATDCChannel();
318  else
319  cable = 19;
320  }
321  zdcAOD->SetZPATDC(esdZDC->GetZDCTDCCorrected(cable, 0));
322  }
323  }
324  // --- Copy centrality estimates -----------------------------------
325  if (fMultSelection) {
326  TObject* outO = InputEvent()->FindListObject("MultSelection");
327  if (outO) {
328  AliMultSelection* outS = static_cast<AliMultSelection*>(outO);
329  fMultSelection->Set(outS);
330  }
331  }
332 }
333 
334 //____________________________________________________________________
335 void
337  const AliESDVertex* vtx,
338  Int_t type)
339 {
340  if (!vtx) return;
341 
342  // --- Get array of V0's from AOD ----------------------------------
343  TClonesArray* arr = aod.GetVertices();
344  if (!arr) return;
345 
346  // --- Now get some stuff vertex to copy to AOD --------------------
347  Int_t n = arr->GetEntriesFast();
348  Double_t pos[] = { 0., 0., 0. };
349  Double_t cov[] = { 0., 0., 0., 0., 0., 0. };
350  Double_t chi2 = vtx->GetChi2toNDF();
351  vtx->GetXYZ(pos);
352  vtx->GetCovMatrix(cov);
353 
354  // --- Create new AOD vertex and set stuff -------------------------
355  AliAODVertex* out = new((*arr)[n]) AliAODVertex(pos, cov, chi2, 0, -1, type);
356  out->SetName(vtx->GetName());
357  out->SetTitle(vtx->GetTitle());
358  out->SetBC(vtx->GetBC());
359 
360  // --- If from a track vertex, make sure we set the contributors ---
361  TString tit(out->GetTitle());
362  if (!tit.Contains("VertexerTracks"))
363  out->SetNContributors(vtx->GetNContributors());
364 }
365 
366 //____________________________________________________________________
367 void
369 {
370  // Called at the end of the job - does nothing
371 }
372 
373 //____________________________________________________________________
374 Bool_t
376 {
377  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
378  if (!mgr) {
379  Error("Connect", "No analysis manager to connect to.");
380  return false;
381  }
382 
383  // Add to the manager
384  mgr->AddTask(this);
385 
386  // Always connect input
387  mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer());
388 
389  return true;
390 }
391 
392 //
393 // EOF
394 //
virtual void UserCreateOutputObjects()
virtual void SetCopyV0(Bool_t copy)
double Double_t
Definition: External.C:58
virtual void SetCopyOptions(const TString &what)
virtual void SetCopyCentrality(Bool_t copy=true)
A task to copy the ESD header to AOD.
virtual void SetCopyAD(Bool_t copy)
void CopyVertex(AliAODEvent &aod, const AliESDVertex *vtx, Int_t type)
virtual void UserExec(Option_t *option)
int Int_t
Definition: External.C:63
AliCopyHeaderTask(const char *name="header")
virtual void SetCopyZDC(Bool_t copy)
virtual void SetCalculateRefMult(Bool_t calc=true)
virtual void Terminate(Option_t *option)
AliCopyHeaderTask & operator=(const AliCopyHeaderTask &other)
virtual void SetCopyTracklets(Bool_t copy=true)
TFile * file
TList with histograms for a given trigger.
AliMultSelection * fMultSelection
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
virtual Bool_t Connect()