AliPhysics  ec7afe5 (ec7afe5)
 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*/);
127  void Print(Option_t* option="") const;
130 
131  ClassDef(AliSimpleHeaderTask,1); // Task to make simple header
132 };
133 
134 
135 //____________________________________________________________________
137  : AliAnalysisTaskSE(),
138  fHeader(0)
139 {}
140 //____________________________________________________________________
142  : AliAnalysisTaskSE(name),
143  fHeader(0)
144 {}
145 //____________________________________________________________________
147  : AliAnalysisTaskSE(o),
148  fHeader(0)
149 {}
150 //____________________________________________________________________
153 {
154  return *this;
155 }
156 //____________________________________________________________________
158 {
159  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
160  if (!mgr) {
161  AliError("No analysis manager to connect to.");
162  return false;
163  }
164  AliAODHandler* ah =
165  dynamic_cast<AliAODHandler*>(mgr->GetOutputEventHandler());
166  if (!ah) {
167  AliError("No AOD output handler!");
168  return false;
169  }
170 
171  // Add to the manager
172  mgr->AddTask(this);
173 
174  // Always connect input
175  mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer());
176 }
177 
178 //____________________________________________________________________
180 {
181  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
182  AliAODHandler* ah =
183  dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
184  if (!ah) {
185  AliWarning("No AOD output handler set in analysis manager");
186  SetZombie();
187  return;
188  }
189 
191  TObject* obj = fHeader;
192 
193  ah->AddBranch("AliAODSimpleHeader", &obj);
194 }
195 
196 //____________________________________________________________________
198 {
199  const Double_t maxDispersion = 0.04;
200  const Double_t maxZError = 0.25;
201  const AliVVertex* ip = event->GetPrimaryVertex();
202  if (ip->GetNContributors() <= 0) return false;
203  // If this is from the Z vertexer, do some checks
204  if (ip->IsFromVertexerZ()) {
205  // Get covariance matrix
206  Double_t covar[6];
207  ip->GetCovarianceMatrix(covar);
208  Double_t sigmaZ = TMath::Sqrt(covar[5]);
209  if (sigmaZ >= maxZError) {
210  AliWarningF("IPz resolution = %f >= %f", sigmaZ, maxZError);
211  return false;
212  }
213 
214  // If this IP doesn not derive from AliVertex, don't check dispersion.
215  if (ip->IsA()->InheritsFrom(AliVertex::Class())) {
216  const AliVertex* ipv = static_cast<const AliVertex*>(ip);
217  // Dispersion is the parameter used by the vertexer for finding the IP.
218  if (ipv->GetDispersion() >= maxDispersion) {
219  AliWarningF("IP dispersion = %f >= %f",
220  ipv->GetDispersion(), maxDispersion);
221  return false;
222  }
223  }
224  }
225  fHeader->fRecIP.SetXYZ(ip->GetX(), ip->GetY(), ip->GetZ());
226 }
227 //____________________________________________________________________
229 {
230  if (!event) return false;
231 
232  TArrayF genIP(3);
233  AliGenEventHeader* genHeader = event->GenEventHeader();
234  if (!genHeader) {
235  AliWarning("No generator header found in MC event");
236  return false;
237  }
238  genHeader->PrimaryVertex(genIP);
239  fHeader->fSimIP.SetXYZ(genIP[0], genIP[1], genIP[2]);
240  AliCollisionGeometry* geomHeader =
241  dynamic_cast<AliCollisionGeometry*>(genHeader);
242  if (!geomHeader &&
243  genHeader->IsA()->InheritsFrom(AliGenCocktailEventHeader::Class())) {
244  // Cocktail, so we need to find the geometry in one of the
245  // cocktail headers.
246  AliGenCocktailEventHeader* ctHeader =
247  static_cast<AliGenCocktailEventHeader*>(genHeader);
248  TIter next(ctHeader->GetHeaders());
249  AliGenEventHeader* subHeader = 0;
250  while ((subHeader = static_cast<AliGenEventHeader*>(next()))) {
251  geomHeader = dynamic_cast<AliCollisionGeometry*>(subHeader);
252  if (geomHeader) break;
253  }
254  } // end-cocktail
255  if (!geomHeader) return true;
256 
257  fHeader->fImpactParameter = geomHeader->ImpactParameter();
258  fHeader->fReactionPlane = geomHeader->ReactionPlaneAngle();
259  fHeader->fProjectileNpart = geomHeader->ProjectileParticipants();
260  fHeader->fTargetNpart = geomHeader->TargetParticipants();
261  fHeader->fNcoll = (geomHeader->NN()+
262  geomHeader->NNw()+
263  geomHeader->NwN()+
264  geomHeader->NwNw());
265  geomHeader->GetNDiffractive(fHeader->fProjectileNsd,
267  fHeader->fNdd);
268  return true;
269 }
270 //____________________________________________________________________
272 {
273  AliMultSelection* cent =
274  static_cast<AliMultSelection*>(event->FindListObject("MultSelection"));
275  if (!cent) {
276  AliWarning("No centrality in event");
277  return false;
278  }
279  const Double_t safety = 1e-3;
280  Double_t centPer = cent->GetMultiplicityPercentile("V0M");
281  if (centPer < -safety) return false;
282  if (centPer < +safety) centPer = safety;
283  else if (centPer > 100-safety) centPer = 100-safety;
284 
285  fHeader->fCent = centPer;
286 
287  AliMultEstimator* estTracklets = cent->GetEstimator("SPDTracklets");
288  if (estTracklets)
289  fHeader->fNTracklets = estTracklets->GetValue();
290 
291  return true;
292 }
293 //____________________________________________________________________
295 {
296  AliCentrality* c = event->GetCentrality();
297  if (!c) return false;
298 
299  fHeader->fCentOld = c->GetCentralityPercentileUnchecked("V0M");
300  return true;
301 }
302 //____________________________________________________________________
304 {
305  if (!fHeader) return;
306 
307  AliVEvent* event = InputEvent();
308  fHeader->Clear();
309  fHeader->fTriggers = fInputHandler->IsEventSelected();
310  Bool_t centOK = GetCent(event);
311  Bool_t centOldOK = GetCentOld(event);
312  Bool_t recOK = GetRecIP(event);
313  Bool_t simOK = GetSim(MCEvent());
314 
315  if (!simOK || !recOK) return; // Do not insist that event is written
316 
317  AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
318  AliAODHandler* ah =
319  dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
320  if (!ah) return;
321 
322  // Mark event for store
323  ah->SetFillAOD(kTRUE);
324 }
325 
326 //____________________________________________________________________
327 void AliSimpleHeaderTask::Print(Option_t* /*option*/) const
328 {
329  Printf("%s: %s", ClassName(), GetName());
330  Printf(" Task to copy content of header to a simplified header");
331 }
332 //====================================================================
334 {
335  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
336  if (!mgr) {
337  ::Error("Create","No analysis manager to connect to.");
338  return 0;
339  }
340  AliAODHandler* ah =
341  dynamic_cast<AliAODHandler*>(mgr->GetOutputEventHandler());
342  if (!ah) {
343  ::Error("Create","No AOD output handler!");
344  return 0;
345  }
346  AliSimpleHeaderTask* ret = new AliSimpleHeaderTask("simpleHeader");
347  if (!ret->Connect()) return 0;
348 
349  return ret;
350 }
351 
352 #endif
353 //
354 // EOF
355 //
356 
357 
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()
void Print(Option_t *option="") const
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="")