First simple particle EMbedding task
authorloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 8 May 2012 19:00:15 +0000 (19:00 +0000)
committerloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 8 May 2012 19:00:15 +0000 (19:00 +0000)
PWGGA/CMakelibPWGGAEMCALJetTasks.pkg
PWGGA/EMCALJetTasks/AliJetEmbeddingTask.cxx [new file with mode: 0644]
PWGGA/EMCALJetTasks/AliJetEmbeddingTask.h [new file with mode: 0644]
PWGGA/PWGGAEMCALJetTasksLinkDef.h

index f050c52..0694d0f 100644 (file)
@@ -28,6 +28,7 @@ set ( SRCS
  EMCALJetTasks/AliAnalysisTaskScale.cxx
  EMCALJetTasks/AliEmcalJetTask.cxx
  EMCALJetTasks/AliHadCorrTask.cxx
+ EMCALJetTasks/AliJetEmbeddingTask.cxx
 )
 
 string ( REPLACE ".cxx" ".h" HDRS "${SRCS}" )
diff --git a/PWGGA/EMCALJetTasks/AliJetEmbeddingTask.cxx b/PWGGA/EMCALJetTasks/AliJetEmbeddingTask.cxx
new file mode 100644 (file)
index 0000000..329ce58
--- /dev/null
@@ -0,0 +1,239 @@
+// $Id$
+//
+// Jet embedding task.
+//
+// Author: Salvatore Aiola, Constantin Loizides
+
+#include <TClonesArray.h>
+#include <TLorentzVector.h>
+#include <TRandom3.h>
+
+#include "AliAnalysisManager.h"
+#include "AliVEvent.h"
+#include "AliVCluster.h"
+#include "AliEMCALDigit.h"
+#include "AliEMCALRecPoint.h"
+#include "AliPicoTrack.h"
+#include "AliEMCALGeometry.h"
+#include "AliLog.h"
+
+#include "AliJetEmbeddingTask.h"
+
+ClassImp(AliJetEmbeddingTask)
+
+//________________________________________________________________________
+AliJetEmbeddingTask::AliJetEmbeddingTask() : 
+  AliAnalysisTaskSE("AliJetEmbeddingTask"),
+  fGeomName(),
+  fTracksName(),
+  fOutTracksName(),
+  fCaloName(),
+  fOutCaloName(),
+  fEtaMin(-1),
+  fEtaMax(1),
+  fPhiMin(0),
+  fPhiMax(TMath::Pi() * 2),
+  fPtMin(0),
+  fPtMax(0),
+  fCopyArray(kTRUE),
+  fNEmbClusters(0),
+  fNEmbTracks(0),
+  fGeom(0),
+  fClusters(0),
+  fOutClusters(0),
+  fTracks(0),
+  fOutTracks(0)
+{
+  // Default constructor.
+}
+
+//________________________________________________________________________
+AliJetEmbeddingTask::AliJetEmbeddingTask(const char *name) : 
+  AliAnalysisTaskSE(name),
+  fGeomName(""),
+  fTracksName("PicoTracks"),
+  fOutTracksName("PicoTracksEmbedded"),
+  fCaloName("CaloClustersCorr"),
+  fOutCaloName("CaloClustersCorrEmbedded"),
+  fEtaMin(-1),
+  fEtaMax(1),
+  fPhiMin(0),
+  fPhiMax(TMath::Pi() * 2),
+  fPtMin(50),
+  fPtMax(60),
+  fCopyArray(kTRUE),
+  fNEmbClusters(0),
+  fNEmbTracks(1),
+  fGeom(0),
+  fClusters(0),
+  fOutClusters(0),
+  fTracks(0),
+  fOutTracks(0)
+{
+  // Standard constructor.
+
+}
+
+//________________________________________________________________________
+AliJetEmbeddingTask::~AliJetEmbeddingTask()
+{
+  // Destructor
+}
+
+//________________________________________________________________________
+void AliJetEmbeddingTask::Init()
+{
+  // Init task.
+
+  if (fNEmbTracks > 0) {
+    fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
+
+    if (strcmp(fTracks->GetClass()->GetName(), "AliPicoTrack")) {
+      AliError("Can only embed PicoTracks!");
+      return;
+    }
+    if (!fTracks) {
+      AliError(Form("Couldn't retrieve tracks with name %s!", fTracksName.Data()));
+      return;
+    }
+
+    if (!fOutTracks) {
+      fOutTracksName = fTracksName;
+      if (fCopyArray) {
+       fOutTracksName += "Embedded";
+       fOutTracks = new TClonesArray(*fTracks);
+       fOutTracks->SetName(fOutTracksName);
+      }
+      else {
+       fOutTracks = fTracks;
+      }
+    }
+
+    if (fCopyArray) {
+      if (!(InputEvent()->FindListObject(fOutTracksName)))
+       InputEvent()->AddObject(fOutTracks);
+      fOutTracks->Clear();
+    }
+  }
+
+  if (fNEmbClusters > 0) {
+    fClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
+    if (!fClusters) {
+      AliError(Form("Couldn't retrieve clusters with name %s!", fCaloName.Data()));
+      return;
+    }
+
+    if (!fOutClusters) {
+      fOutCaloName = fCaloName;
+      if (fCopyArray) {
+       fOutCaloName += "Embedded";
+       fOutClusters = new TClonesArray(*fClusters);
+       fOutClusters->SetName(fOutCaloName);
+      }
+      else {
+       fOutClusters = fClusters;
+      }
+    }
+
+    if (fCopyArray) {
+      if (!(InputEvent()->FindListObject(fOutCaloName)))
+       InputEvent()->AddObject(fOutClusters);
+      fOutClusters->Clear();
+    }
+  }
+
+    if (!fGeom) {
+      if (fGeomName.Length()>0) {
+        fGeom = AliEMCALGeometry::GetInstance(fGeomName);
+        if (!fGeom)
+          AliError(Form("Could not get geometry with name %s!", fGeomName.Data()));
+      } else {
+        fGeom = AliEMCALGeometry::GetInstance();
+        if (!fGeom) 
+          AliError("Could not get default geometry!");
+      }
+    }
+}
+
+//________________________________________________________________________
+void AliJetEmbeddingTask::Embed() 
+{
+  // Embed particles.
+
+  if (fNEmbClusters > 0 && fOutClusters) {
+
+    const Int_t nClusters = fOutClusters->GetEntriesFast();
+    TClonesArray digits("AliEMCALDigit", 1);
+    
+    for (Int_t i = 0; i < fNEmbClusters; i++) {
+      Double_t pt  = gRandom->Rndm() * (fPtMax - fPtMin) + fPtMin;
+      Double_t eta = gRandom->Rndm() * (fEtaMax - fEtaMin) + fEtaMin;
+      Double_t phi = gRandom->Rndm() * (fPhiMax - fPhiMin) + fPhiMin;
+    
+      TLorentzVector nPart;
+      nPart.SetPtEtaPhiM(pt, eta, phi, 0);
+      Double_t e = nPart.E();
+      
+      Int_t absId = 0;
+      fGeom->GetAbsCellIdFromEtaPhi(eta, phi, absId);
+      
+      AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(digits.New(0));
+      digit->SetId(absId);
+      digit->SetIndexInList(0);
+      digit->SetType(AliEMCALDigit::kHG);
+      digit->SetAmplitude(e);
+      
+      AliEMCALRecPoint *recPoint = new AliEMCALRecPoint();
+      recPoint->AddDigit(*digit, e, kFALSE);
+      recPoint->EvalGlobalPosition(0, &digits);
+
+      TVector3 gpos;
+      recPoint->GetGlobalPosition(gpos);
+      Float_t g[3];
+      gpos.GetXYZ(g);
+      
+      AliVCluster *cluster = static_cast<AliVCluster*>(fOutClusters->New(nClusters + i));
+      cluster->SetType(AliVCluster::kEMCALClusterv1);
+      cluster->SetE(recPoint->GetEnergy());
+      cluster->SetPosition(g);
+      cluster->SetNCells(1);
+      UShort_t shortAbsId = absId;
+      cluster->SetCellsAbsId(&shortAbsId);
+      cluster->SetCellsAmplitudeFraction(NULL);
+      cluster->SetID(nClusters + i);
+      cluster->SetEmcCpvDistance(-1);
+      cluster->SetChi2(100); // MC flag!
+    }
+  }
+  if (fNEmbTracks > 0 && fOutTracks) {
+    Int_t nTracks = fOutTracks->GetEntriesFast();
+    
+    for (Int_t i = 0; i < fNEmbTracks; i++) {
+      Double_t pt  = gRandom->Rndm() * (fPtMax - fPtMin) + fPtMin;
+      Double_t eta = gRandom->Rndm() * (fEtaMax - fEtaMin) + fEtaMin;
+      Double_t phi = gRandom->Rndm() * (fPhiMax - fPhiMin) + fPhiMin;
+      
+      new ((*fOutTracks)[nTracks + i]) AliPicoTrack(pt, 
+                                                   eta, 
+                                                   phi, 
+                                                   1, 
+                                                   100,    // MC flag!      
+                                                   0, 
+                                                   0, 
+                                                   kFALSE);
+    }
+  }
+}
+
+//________________________________________________________________________
+void AliJetEmbeddingTask::UserExec(Option_t *) 
+{
+  // Execute per event.
+
+  Init();
+
+  Embed();
+}
diff --git a/PWGGA/EMCALJetTasks/AliJetEmbeddingTask.h b/PWGGA/EMCALJetTasks/AliJetEmbeddingTask.h
new file mode 100644 (file)
index 0000000..9231387
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef ALIJETEMBEDDINGTASK_H
+#define ALIJETEMBEDDINGTASK_H
+
+// $Id$
+
+class TClonesArray;
+class AliEMCALGeometry;
+
+#include "AliAnalysisTaskSE.h"
+
+class AliJetEmbeddingTask : public AliAnalysisTaskSE {
+ public:
+  AliJetEmbeddingTask();
+  AliJetEmbeddingTask(const char *name); 
+  virtual ~AliJetEmbeddingTask();
+
+  void         Init();
+  void         UserExec(Option_t* /*option*/);
+  void         Terminate(const Option_t* /*option*/) {;}
+
+  void         SetClusName(const char *n)            { fCaloName     = n;    }
+  void         SetTracksName(const char *n)          { fTracksName   = n;    }
+  void         SetEtaRange(Float_t min, Float_t max) { fEtaMin       = min;  fEtaMax = max; }
+  void         SetPhiRange(Float_t min, Float_t max) { fPhiMin       = min;  fPhiMax = max; }
+  void         SetPtRange(Float_t min, Float_t max)  { fPtMin        = min;  fPtMax  = max;  }
+  void         SetCopyArray(Bool_t copy)             { fCopyArray    = copy; }
+  void         SetNClusters(Int_t n)                 { fNEmbClusters = n;    }
+  void         SetNTracks(Int_t n)                   { fNEmbTracks   = n;    }
+  void         SetGeometryName(const char *n)        { fGeomName     = n;    }
+
+ protected:
+
+  virtual void           Embed();                 // do embedding
+
+  TString                fGeomName;               // EMCal geometry name
+  TString                fTracksName;             // name of track collection
+  TString                fOutTracksName;          // name of output track collection
+  TString                fCaloName;               // name of calo cluster collection
+  TString                fOutCaloName;            // name of output cluster collection
+  Float_t                fEtaMin;                 // eta minimum value
+  Float_t                fEtaMax;                 // eta maximum value
+  Float_t                fPhiMin;                 // phi minimum value
+  Float_t                fPhiMax;                 // phi maximum value
+  Float_t                fPtMin;                  // pt minimum value
+  Float_t                fPtMax;                  // pt maximum value
+  Bool_t                 fCopyArray;              // whether or not the array will be copied to a new one before embedding
+  Int_t                  fNEmbClusters;           // how many clusters are being embedded
+  Int_t                  fNEmbTracks;             // how many tracks are being embedded
+  AliEMCALGeometry      *fGeom;                   //!pointer to EMCal geometry
+  TClonesArray          *fClusters;               //!cluster collection
+  TClonesArray          *fOutClusters;            //!output cluster collection
+  TClonesArray          *fTracks;                 //!track collection
+  TClonesArray          *fOutTracks;              //!output track collection
+
+ private:
+  AliJetEmbeddingTask(const AliJetEmbeddingTask&);            // not implemented
+  AliJetEmbeddingTask &operator=(const AliJetEmbeddingTask&); // not implemented
+
+  ClassDef(AliJetEmbeddingTask, 1) // Jet embedding task
+};
+#endif
index c206165..dc96018 100644 (file)
@@ -6,6 +6,7 @@
 
 #pragma link C++ class AliAnalysisTaskScale+;
 #pragma link C++ class AliEmcalJetTask+;
+#pragma link C++ class AliJetEmbeddingTask+;
 #pragma link C++ class AliHadCorrTask+;
 
 #endif