]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FORWARD/analysis2/AliForwarddNdetaTask.cxx
Fix coding violations
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliForwarddNdetaTask.cxx
1 //====================================================================
2 #include "AliForwarddNdetaTask.h"
3 #include <TMath.h>
4 #include <TH2D.h>
5 #include <TH1D.h>
6 #include <THStack.h>
7 #include <TList.h>
8 #include <AliAnalysisManager.h>
9 #include <AliAODEvent.h>
10 #include <AliAODHandler.h>
11 #include <AliAODInputHandler.h>
12 #include "AliForwardUtil.h"
13 #include "AliAODForwardMult.h"
14
15 //____________________________________________________________________
16 AliForwarddNdetaTask::AliForwarddNdetaTask()
17   : AliBasedNdetaTask(),
18     fSumPrimary(0),     //  Sum of primary histograms
19     fSNNString(0),
20     fSysString(0)
21 {
22   //
23   // Constructor 
24   // 
25 }
26
27 //____________________________________________________________________
28 AliForwarddNdetaTask::AliForwarddNdetaTask(const char* /* name */)
29   : AliBasedNdetaTask("Forward"), 
30     fSumPrimary(0),     //  Sum of primary histograms
31     fSNNString(0),
32     fSysString(0)
33 {
34   // 
35   // Constructor
36   // 
37   // Paramters
38   //   name    Name of task 
39 }
40
41 //____________________________________________________________________
42 AliForwarddNdetaTask::AliForwarddNdetaTask(const AliForwarddNdetaTask& o)
43   : AliBasedNdetaTask(o),
44     fSumPrimary(o.fSumPrimary),    // Sum of primary histograms
45     fSNNString(o.fSNNString),      //  
46     fSysString(o.fSysString)       //  
47 {
48   // 
49   // Copy constructor
50   // 
51 }
52
53 //____________________________________________________________________
54 TH2D*
55 AliForwarddNdetaTask::GetHistogram(const AliAODEvent* aod, Bool_t mc)
56 {
57   // 
58   // Retrieve the histogram 
59   // 
60   // Parameters:
61   //    aod AOD event 
62   //    mc  Whether to get the MC histogram or not
63   // 
64   // Return:
65   //    Retrieved histogram or null
66   //
67   TObject* obj = 0;
68   if (mc) obj = aod->FindListObject("ForwardMC");
69   else    obj = aod->FindListObject("Forward");
70
71   // We should have a forward object at least 
72   if (!obj) {
73     if (!mc) AliWarning("No Forward object found AOD");
74     return 0;
75   }
76   AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
77
78   // Here, we update the primary stuff 
79   if (mc) { 
80     TObject* oPrimary   = aod->FindListObject("primary");
81     if (oPrimary) {
82       TH2D* primary   = static_cast<TH2D*>(oPrimary);
83       // Add contribtion from MC 
84       
85       if(fTriggerMask == AliAODForwardMult::kInel) {
86         if (primary && !fSumPrimary) fSumPrimary = CloneHist(primary, "truth");
87         else if (primary) fSumPrimary->Add(primary);
88       }
89       
90       else if(fTriggerMask == AliAODForwardMult::kNSD && forward->IsTriggerBits(AliAODForwardMult::kMCNSD)) {
91         if (primary && !fSumPrimary) fSumPrimary = CloneHist(primary, "truth"); 
92         else if (primary) fSumPrimary->Add(primary);
93       }
94       
95       
96       
97       /*   if(fTriggerMask == AliAODForwardMult::kNSD && forward->IsTriggerBits(AliAODForwardMult::kMCNSD)) {
98            if (primary) fSumPrimary->Add(primary); 
99            
100            }
101            
102            else if (primary) fSumPrimary->Add(primary);*/
103       
104     }    
105   }
106   
107   // Here, we get the update 
108   if (!fSNNString) { 
109     UShort_t sNN = forward->GetSNN();
110     fSNNString = new TNamed("sNN", "");
111     fSNNString->SetTitle(AliForwardUtil::CenterOfMassEnergyString(sNN));
112     fSNNString->SetUniqueID(sNN);
113     fSums->Add(fSNNString);
114   
115     UShort_t sys = forward->GetSystem();
116     fSysString = new TNamed("sys", "");
117     fSysString->SetTitle(AliForwardUtil::CollisionSystemString(sys));
118     fSysString->SetUniqueID(sys);
119     fSums->Add(fSysString);
120   }
121
122   return &(forward->GetHistogram());
123 }
124
125 //________________________________________________________________________
126 void 
127 AliForwarddNdetaTask::Terminate(Option_t *) 
128 {
129   // Draw result to screen, or perform fitting, normalizations Called
130   // once at the end of the query
131   AliBasedNdetaTask::Terminate("");
132   if(!fSums) {
133     AliError("Could not retrieve TList fSums"); 
134     return; 
135   }
136   if (!fOutput) { 
137     AliError("Could not retrieve TList fOutput"); 
138     return; 
139   }
140
141   fSumPrimary     = static_cast<TH2D*>(fSums->FindObject("truth"));
142   fSNNString      = static_cast<TNamed*>(fSums->FindObject("sNN"));
143   fSysString      = static_cast<TNamed*>(fSums->FindObject("sys"));
144
145   fOutput->Add(fSNNString->Clone());
146   fOutput->Add(fSysString->Clone());
147
148   if (fSumPrimary) { 
149     Int_t nAll        = Int_t(fTriggers->GetBinContent(kAll));
150     Int_t nNSD        = Int_t(fTriggers->GetBinContent(kMCNSD));
151     
152     //  for(Int_t nn =1; nn<=fSumPrimary->GetNbinsX(); nn++) {
153     //  for(Int_t mm =1; mm<=fSumPrimary->GetNbinsY(); mm++) {
154     //  if(fSumPrimary->GetBinContent(nn,mm) > 0) std::cout<<fSumPrimary->GetBinContent(nn,mm)<<" +/-  "<<fSumPrimary->GetBinError(nn,mm)<<std::endl;
155     //  }
156     // }
157  
158     
159     //TH1D* dndetaTruth = ProjectX(fSumPrimary,"dndetaTruth",
160     //                   1,fSumPrimary->GetNbinsY(),false,true);
161     TH1D* dndetaTruth = fSumPrimary->ProjectionX("dndetaTruth",1,fSumPrimary->GetNbinsY(),"e");
162
163     
164     if(fTriggerMask == AliAODForwardMult::kNSD)
165       dndetaTruth->Scale(1./nNSD, "width");
166     else
167       dndetaTruth->Scale(1./nAll, "width");
168     
169     //for(Int_t nn =1; nn<=dndetaTruth->GetNbinsX(); nn++) {
170     //  if(dndetaTruth->GetBinContent(nn) > 0) std::cout<<dndetaTruth->GetBinContent(nn)<<" +/-  "<<dndetaTruth->GetBinError(nn)<<std::endl;
171     // }
172
173     
174     SetHistogramAttributes(dndetaTruth, kBlue+3, 22, "Monte-Carlo truth");
175     
176     fOutput->Add(dndetaTruth);
177     fOutput->Add(Rebin(dndetaTruth));
178   }
179   // If only there was a away to get sqrt{s_NN} and beam type 
180   
181
182   PostData(2, fOutput);
183 }
184
185 //________________________________________________________________________
186 //
187 // EOF
188 //