Addition of missing script
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AddTaskCopyHeader.C
1 #include "AliAnalysisTaskSE.h"
2 #include "AliInputEventHandler.h"
3 #include "AliESDEvent.h"
4 #include "AliAODEvent.h"
5 #include "AliCentrality.h"
6 #include "AliAnalysisManager.h"
7 #include <TROOT.h>
8
9 class CopyHeaderTask : public AliAnalysisTaskSE
10 {
11 public:
12   CopyHeaderTask(const char* name="header") 
13     : AliAnalysisTaskSE(name)
14   {}
15   CopyHeaderTask(const CopyHeaderTask& other) 
16     : AliAnalysisTaskSE(other)
17   {}
18   virtual ~CopyHeaderTask() {}
19   CopyHeaderTask& operator=(const CopyHeaderTask& other) 
20   {
21     AliAnalysisTaskSE::operator=(other);
22     return *this;
23   }
24   /** 
25    * @{ 
26    * @name Implementation of interface methods
27    */
28   virtual void   UserCreateOutputObjects() {}
29   virtual void   Init() {}
30   virtual void   LocalInit() {Init();}
31   virtual void   UserExec(Option_t *option);
32   virtual void   Terminate(Option_t *option);
33   /* @} */
34
35   ClassDef(CopyHeaderTask,1);
36 };
37
38 void
39 CopyHeaderTask::UserExec(Option_t*)
40 {
41   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
42   AliAODEvent* aod = dynamic_cast<AliAODEvent*>(AODEvent());
43
44   if (!esd) { 
45     AliWarning("Missing ESD event");
46     return;
47   }
48   if (!aod) { 
49     AliWarning("Missing AOD event");
50     return;
51   }
52   
53   AliAODHeader* aodHeader = aod->GetHeader();
54   if (!aodHeader) { 
55     AliWarning("Missing AOD header");
56     return;
57   }
58
59   aodHeader->SetRunNumber(esd->GetRunNumber());
60   aodHeader->SetOfflineTrigger(fInputHandler->IsEventSelected());
61   aodHeader->SetBunchCrossNumber(esd->GetBunchCrossNumber());
62   aodHeader->SetOrbitNumber(esd->GetOrbitNumber());
63   aodHeader->SetPeriodNumber(esd->GetPeriodNumber());
64   aodHeader->SetEventType(esd->GetEventType());
65   aodHeader->SetEventNumberESDFile(esd->GetHeader()->GetEventNumberInFile());
66   if(esd->GetCentrality())
67     aodHeader->SetCentrality(new AliCentrality(*(esd->GetCentrality())));
68   else
69     aodHeader->SetCentrality(0);
70
71   aodHeader->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
72   aodHeader->SetTriggerMask(esd->GetTriggerMask()); 
73   aodHeader->SetTriggerCluster(esd->GetTriggerCluster());
74   aodHeader->SetL0TriggerInputs(esd->GetHeader()->GetL0TriggerInputs());    
75   aodHeader->SetL1TriggerInputs(esd->GetHeader()->GetL1TriggerInputs());    
76   aodHeader->SetL2TriggerInputs(esd->GetHeader()->GetL2TriggerInputs());    
77   
78   aodHeader->SetMagneticField(esd->GetMagneticField());
79   aodHeader->SetMuonMagFieldScale(esd->GetCurrentDip()/6000.);
80   aodHeader->SetZDCN1Energy(esd->GetZDCN1Energy());
81   aodHeader->SetZDCP1Energy(esd->GetZDCP1Energy());
82   aodHeader->SetZDCN2Energy(esd->GetZDCN2Energy());
83   aodHeader->SetZDCP2Energy(esd->GetZDCP2Energy());
84   aodHeader->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));
85 }
86
87 void
88 CopyHeaderTask::Terminate(Option_t*)
89 {}
90
91 void
92 AddTaskCopyHeader()
93 {
94   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
95   if (!mgr) {
96     Error("AddTaskFMD", "No analysis manager to connect to.");
97     return;
98   }   
99   
100   gROOT->Macro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
101   
102   CopyHeaderTask* task = new CopyHeaderTask;
103   mgr->AddTask(task);
104   
105   // AliAnalysisDataContainer* histOut = 
106   //   mgr->CreateContainer("Forward", TList::Class(), 
107   //             AliAnalysisManager::kOutputContainer,outputfile);
108   mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
109   // mgr->ConnectOutput(task, 1, histOut);
110 }
111 //
112 // EOF
113 //