AliPhysics  f05a842 (f05a842)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliSimpleHeaderTask.C
Go to the documentation of this file.
1 
10 #ifndef ALISIMPLEHEADERTASK_C
11 #define ALISIMPLEHEADERTASK_C
12 #include <AliAnalysisTaskSE.h>
13 #ifndef __CINT__
14 # include "AliAODSimpleHeader.C"
15 # include <AliVVertex.h>
16 # include <AliVertex.h>
17 # include <AliAnalysisManager.h>
18 # include <AliVEventHandler.h>
19 # include <AliInputEventHandler.h>
20 # include <AliMultSelection.h>
21 # include <AliAODHandler.h>
22 # include <AliCollisionGeometry.h>
23 # include <AliGenEventHeader.h>
24 # include <AliGenCocktailEventHeader.h>
25 # include <AliMCEvent.h>
26 # include <AliLog.h>
27 # include <AliCentrality.h>
28 #else
29 class AliAODSimpleHeader;
30 class AliVEvent;
31 class AliMCEvent;
32 class AliMultSelection; // Auto-load
33 #endif
34 
41 {
42 public:
52  AliSimpleHeaderTask(const char* name);
72  Bool_t Connect();
79  static AliSimpleHeaderTask* Create();
92  Bool_t GetRecIP(AliVEvent* event);
100  Bool_t GetSim(AliMCEvent* event);
108  Bool_t GetCent(AliVEvent* event);
116  Bool_t GetCentOld(AliVEvent* event);
121  void UserExec(Option_t* /*option*/);
124 
125  ClassDef(AliSimpleHeaderTask,1); // Task to make simple header
126 };
127 
128 
129 //____________________________________________________________________
131  : AliAnalysisTaskSE(),
132  fHeader(0)
133 {}
134 //____________________________________________________________________
136  : AliAnalysisTaskSE(name),
137  fHeader(0)
138 {}
139 //____________________________________________________________________
141  : AliAnalysisTaskSE(o),
142  fHeader(0)
143 {}
144 //____________________________________________________________________
147 {
148  return *this;
149 }
150 //____________________________________________________________________
152 {
153  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
154  if (!mgr) {
155  AliError("No analysis manager to connect to.");
156  return false;
157  }
158  AliAODHandler* ah =
159  dynamic_cast<AliAODHandler*>(mgr->GetOutputEventHandler());
160  if (!ah) {
161  AliError("No AOD output handler!");
162  return false;
163  }
164 
165  // Add to the manager
166  mgr->AddTask(this);
167 
168  // Always connect input
169  mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer());
170 }
171 
172 //____________________________________________________________________
174 {
175  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
176  AliAODHandler* ah =
177  dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
178  if (!ah) {
179  AliWarning("No AOD output handler set in analysis manager");
180  SetZombie();
181  return;
182  }
183 
185  TObject* obj = fHeader;
186 
187  ah->AddBranch("AliAODSimpleHeader", &obj);
188 }
189 
190 //____________________________________________________________________
192 {
193  const Double_t maxDispersion = 0.04;
194  const Double_t maxZError = 0.25;
195  const AliVVertex* ip = event->GetPrimaryVertex();
196  if (ip->GetNContributors() <= 0) return false;
197  // If this is from the Z vertexer, do some checks
198  if (ip->IsFromVertexerZ()) {
199  // Get covariance matrix
200  Double_t covar[6];
201  ip->GetCovarianceMatrix(covar);
202  Double_t sigmaZ = TMath::Sqrt(covar[5]);
203  if (sigmaZ >= maxZError) {
204  AliWarningF("IPz resolution = %f >= %f", sigmaZ, maxZError);
205  return false;
206  }
207 
208  // If this IP doesn not derive from AliVertex, don't check dispersion.
209  if (ip->IsA()->InheritsFrom(AliVertex::Class())) {
210  const AliVertex* ipv = static_cast<const AliVertex*>(ip);
211  // Dispersion is the parameter used by the vertexer for finding the IP.
212  if (ipv->GetDispersion() >= maxDispersion) {
213  AliWarningF("IP dispersion = %f >= %f",
214  ipv->GetDispersion(), maxDispersion);
215  return false;
216  }
217  }
218  }
219  fHeader->fRecIP.SetXYZ(ip->GetX(), ip->GetY(), ip->GetZ());
220 }
221 //____________________________________________________________________
223 {
224  if (!event) return false;
225 
226  TArrayF genIP(3);
227  AliGenEventHeader* genHeader = event->GenEventHeader();
228  if (!genHeader) {
229  AliWarning("No generator header found in MC event");
230  return false;
231  }
232  genHeader->PrimaryVertex(genIP);
233  fHeader->fSimIP.SetXYZ(genIP[0], genIP[1], genIP[2]);
234  AliCollisionGeometry* geomHeader =
235  dynamic_cast<AliCollisionGeometry*>(genHeader);
236  if (!geomHeader &&
237  genHeader->IsA()->InheritsFrom(AliGenCocktailEventHeader::Class())) {
238  // Cocktail, so we need to find the geometry in one of the
239  // cocktail headers.
240  AliGenCocktailEventHeader* ctHeader =
241  static_cast<AliGenCocktailEventHeader*>(genHeader);
242  TIter next(ctHeader->GetHeaders());
243  AliGenEventHeader* subHeader = 0;
244  while ((subHeader = static_cast<AliGenEventHeader*>(next()))) {
245  geomHeader = dynamic_cast<AliCollisionGeometry*>(subHeader);
246  if (geomHeader) break;
247  }
248  } // end-cocktail
249  if (!geomHeader) return true;
250 
251  fHeader->fImpactParameter = geomHeader->ImpactParameter();
252  fHeader->fReactionPlane = geomHeader->ReactionPlaneAngle();
253  fHeader->fProjectileNpart = geomHeader->ProjectileParticipants();
254  fHeader->fTargetNpart = geomHeader->TargetParticipants();
255  fHeader->fNcoll = (geomHeader->NN()+
256  geomHeader->NNw()+
257  geomHeader->NwN()+
258  geomHeader->NwNw());
259  geomHeader->GetNDiffractive(fHeader->fProjectileNsd,
261  fHeader->fNdd);
262  return true;
263 }
264 //____________________________________________________________________
266 {
267  AliMultSelection* cent =
268  static_cast<AliMultSelection*>(event->FindListObject("MultSelection"));
269  if (!cent) {
270  AliWarning("No centrality in event");
271  return false;
272  }
273  const Double_t safety = 1e-3;
274  Double_t centPer = cent->GetMultiplicityPercentile("V0M");
275  if (centPer < -safety) return false;
276  if (centPer < +safety) centPer = safety;
277  else if (centPer > 100-safety) centPer = 100-safety;
278 
279  fHeader->fCent = centPer;
280 
281  AliMultEstimator* estTracklets = cent->GetEstimator("SPDTracklets");
282  if (estTracklets)
283  fHeader->fNTracklets = estTracklets->GetValue();
284 
285  return true;
286 }
287 //____________________________________________________________________
289 {
290  AliCentrality* c = event->GetCentrality();
291  if (!c) return false;
292 
293  fHeader->fCentOld = c->GetCentralityPercentileUnchecked("V0M");
294  return true;
295 }
296 //____________________________________________________________________
298 {
299  if (!fHeader) return;
300 
301  AliVEvent* event = InputEvent();
302  fHeader->Clear();
303  fHeader->fTriggers = fInputHandler->IsEventSelected();
304  Bool_t centOK = GetCent(event);
305  Bool_t centOldOK = GetCentOld(event);
306  Bool_t recOK = GetRecIP(event);
307  Bool_t simOK = GetSim(MCEvent());
308 
309  if (!simOK || !recOK) return; // Do not insist that event is written
310 
311  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
312  AliAODHandler* ah =
313  dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
314  if (!ah) return;
315 
316  // Mark event for store
317  ah->SetFillAOD(kTRUE);
318 }
319 
320 //====================================================================
322 {
323  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
324  if (!mgr) {
325  ::Error("Create","No analysis manager to connect to.");
326  return 0;
327  }
328  AliAODHandler* ah =
329  dynamic_cast<AliAODHandler*>(mgr->GetOutputEventHandler());
330  if (!ah) {
331  ::Error("Create","No AOD output handler!");
332  return 0;
333  }
334  AliSimpleHeaderTask* ret = new AliSimpleHeaderTask("simpleHeader");
335  if (!ret->Connect()) return 0;
336 
337  return ret;
338 }
339 
340 #endif
341 //
342 // EOF
343 //
344 
345 
double Double_t
Definition: External.C:58
Bool_t GetCentOld(AliVEvent *event)
TCanvas * c
Definition: TestFitELoss.C:172
Bool_t GetRecIP(AliVEvent *event)
ClassDef(AliSimpleHeaderTask, 1)
static AliSimpleHeaderTask * Create()
AliSimpleHeaderTask & operator=(const AliSimpleHeaderTask &o)
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
AliAODSimpleHeader * fHeader
Bool_t GetSim(AliMCEvent *event)
A simplified AOD header.
Bool_t GetCent(AliVEvent *event)
void UserExec(Option_t *)
void Clear(Option_t *option="")