]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG1/TRD/AliTRDinfoGen.cxx
fix warnings
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDinfoGen.cxx
index b8f17e1e59bc0b544b5d4ac75aee219b40417c58..85b55422430b100814de370d0c7ac8b53a442236 100644 (file)
@@ -35,7 +35,8 @@
 #include <TObjArray.h>
 #include <TObject.h>
 #include <TString.h>
-#include <TH1F.h>
+#include <TH1S.h>
+#include <TPad.h>
 #include <TFile.h>
 #include <TTree.h>
 #include <TROOT.h>
 
 #include "AliLog.h"
 #include "AliAnalysisManager.h"
+#include "AliGeomManager.h"
+#include "AliCDBManager.h"
+#include "AliCDBEntry.h"
+#include "AliCDBPath.h"
 #include "AliESDEvent.h"
 #include "AliMCEvent.h"
 #include "AliESDInputHandler.h"
 #include "AliESDfriendTrack.h"
 #include "AliESDHeader.h"
 #include "AliESDtrack.h"
+#include "AliESDv0.h"
 #include "AliESDtrackCuts.h"
 #include "AliMCParticle.h"
 #include "AliPID.h"
 #include "AliStack.h"
-#include "AliTRDtrackV1.h"
 #include "AliTrackReference.h"
-#include "AliTRDgeometry.h"
-#include "AliTRDcluster.h"
-#include "AliTRDseedV1.h"
 #include "TTreeStream.h"
 
 #include <cstdio>
 #include <climits>
 #include <cstring>
 #include <iostream>
+#include <memory>
 
+#include "AliTRDReconstructor.h"
+#include "AliTRDrecoParam.h"
+#include "AliTRDcalibDB.h"
+#include "AliTRDtrackerV1.h"
+#include "AliTRDgeometry.h"
+#include "AliTRDtrackV1.h"
+#include "AliTRDseedV1.h"
+#include "AliTRDcluster.h"
 #include "AliTRDinfoGen.h"
 #include "info/AliTRDtrackInfo.h"
 #include "info/AliTRDeventInfo.h"
@@ -85,12 +96,13 @@ const Float_t AliTRDinfoGen::fgkTRD = 365.;
 const Float_t AliTRDinfoGen::fgkEvVertexZ = 15.;
 const Int_t   AliTRDinfoGen::fgkEvVertexN = 1;
 
-const Float_t AliTRDinfoGen::fgkTrkDCAxy  = 40.;
-const Float_t AliTRDinfoGen::fgkTrkDCAz   = 15.;
-const Int_t   AliTRDinfoGen::fgkNclTPC    = 10;
+const Float_t AliTRDinfoGen::fgkTrkDCAxy  = 3.;
+const Float_t AliTRDinfoGen::fgkTrkDCAz   = 10.;
+const Int_t   AliTRDinfoGen::fgkNclTPC    = 70;
 const Float_t AliTRDinfoGen::fgkPt        = 0.2;
 const Float_t AliTRDinfoGen::fgkEta       = 0.9;
-
+AliTRDReconstructor* AliTRDinfoGen::fgReconstructor(NULL);
+AliTRDgeometry* AliTRDinfoGen::fgGeo(NULL);
 //____________________________________________________________________
 AliTRDinfoGen::AliTRDinfoGen()
   :AliAnalysisTaskSE()
@@ -99,6 +111,8 @@ AliTRDinfoGen::AliTRDinfoGen()
   ,fMCev(NULL)
   ,fEventCut(NULL)
   ,fTrackCut(NULL)
+  ,fV0Cut(NULL)
+  ,fOCDB("local://$ALICE_ROOT/OCDB")
   ,fTrackInfo(NULL)
   ,fEventInfo(NULL)
   ,fV0Info(NULL)
@@ -106,12 +120,13 @@ AliTRDinfoGen::AliTRDinfoGen()
   ,fTracksSA(NULL)
   ,fTracksKink(NULL)
   ,fV0List(NULL)
+  ,fContainer(NULL)
   ,fDebugStream(NULL)
 {
   //
   // Default constructor
   //
-  SetNameTitle("infoGen", "MC-REC TRD-track list generator");
+  SetNameTitle("TRDinfoGen", "MC-REC TRD-track list generator");
 }
 
 //____________________________________________________________________
@@ -122,6 +137,8 @@ AliTRDinfoGen::AliTRDinfoGen(char* name)
   ,fMCev(NULL)
   ,fEventCut(NULL)
   ,fTrackCut(NULL)
+  ,fV0Cut(NULL)
+  ,fOCDB("local://$ALICE_ROOT/OCDB")
   ,fTrackInfo(NULL)
   ,fEventInfo(NULL)
   ,fV0Info(NULL)
@@ -129,6 +146,7 @@ AliTRDinfoGen::AliTRDinfoGen(char* name)
   ,fTracksSA(NULL)
   ,fTracksKink(NULL)
   ,fV0List(NULL)
+  ,fContainer(NULL)
   ,fDebugStream(NULL)
 {
   //
@@ -140,15 +158,18 @@ AliTRDinfoGen::AliTRDinfoGen(char* name)
   DefineOutput(kTracksKink, TObjArray::Class());
   DefineOutput(kEventInfo, AliTRDeventInfo::Class());
   DefineOutput(kV0List, TObjArray::Class());
+  DefineOutput(kMonitor, TObjArray::Class()); // histogram list
 }
 
 //____________________________________________________________________
 AliTRDinfoGen::~AliTRDinfoGen()
 {
 // Destructor
-  
+  if(fgGeo) delete fgGeo;
+  if(fgReconstructor) delete fgReconstructor;
   if(fDebugStream) delete fDebugStream;
   if(fEvTrigger) delete fEvTrigger;
+  if(fV0Cut) delete fV0Cut;
   if(fTrackCut) delete fTrackCut;
   if(fEventCut) delete fEventCut;
   if(fTrackInfo) delete fTrackInfo; fTrackInfo = NULL;
@@ -167,9 +188,26 @@ AliTRDinfoGen::~AliTRDinfoGen()
     fTracksKink = NULL;
   }
   if(fV0List){ 
-    fV0List->Delete(); delete fV0List;
+    fV0List->Delete(); 
+    delete fV0List;
     fV0List = NULL;
   }
+  if(fContainer){ 
+    fContainer->Delete(); 
+    delete fContainer;
+    fContainer = NULL;
+  }
+}
+
+//____________________________________________________________________
+Bool_t AliTRDinfoGen::GetRefFigure(Int_t)
+{
+  if(!gPad){
+    AliWarning("Please provide a canvas to draw results.");
+    return kFALSE;
+  }
+  fContainer->At(0)->Draw("bar");
+  return kTRUE;
 }
 
 //____________________________________________________________________
@@ -186,6 +224,51 @@ void AliTRDinfoGen::UserCreateOutputObjects()
   fTracksSA = new TObjArray(20); fTracksSA->SetOwner(kTRUE);
   fTracksKink = new TObjArray(20); fTracksKink->SetOwner(kTRUE);
   fV0List = new TObjArray(10); fV0List->SetOwner(kTRUE);
+
+  // define general monitor
+  fContainer = new TObjArray(1); fContainer->SetOwner(kTRUE);
+  TH1 *h=new TH1S("hStat", "Run statistics;Observable;Entries", 12, -0.5, 11.5);
+  TAxis *ax(h->GetXaxis());
+  ax->SetBinLabel( 1, "ESD");
+  ax->SetBinLabel( 2, "MC");
+  ax->SetBinLabel( 3, "V0");
+  ax->SetBinLabel( 4, "TPC");
+  ax->SetBinLabel( 5, "TRDin");
+  ax->SetBinLabel( 6, "TRDout");
+  ax->SetBinLabel( 7, "Barrel");
+  ax->SetBinLabel( 8, "BarrelMC");
+  ax->SetBinLabel( 9, "SA");
+  ax->SetBinLabel(10, "SAMC");
+  ax->SetBinLabel(11, "Kink");
+  ax->SetBinLabel(12, "KinkMC");
+  fContainer->AddAt(h, 0);
+  PostData(kMonitor, fContainer);
+}
+
+//____________________________________________________________________
+Bool_t AliTRDinfoGen::Load(const Char_t *file, const Char_t *dir, const Char_t *name)
+{
+// Load data from performance file
+
+  if(!TFile::Open(file)){
+    AliWarning(Form("Couldn't open file %s.", file));
+    return kFALSE;
+  }
+  if(dir){
+    if(!gFile->cd(dir)){
+      AliWarning(Form("Couldn't cd to %s in %s.", dir, file));
+      return kFALSE;
+    }
+  }
+  TObjArray *o(NULL);
+  const Char_t *tn=(name ? name : GetName());
+  if(!(o = (TObjArray*)gDirectory->Get(tn))){
+    AliWarning(Form("Missing histogram container %s.", tn));
+    return kFALSE;
+  }
+  fContainer = (TObjArray*)o->Clone(GetName());
+  gFile->Close();
+  return kTRUE;
 }
 
 //____________________________________________________________________
@@ -194,18 +277,66 @@ void AliTRDinfoGen::UserExec(Option_t *){
   // Run the Analysis
   //
 
-  fESDev = dynamic_cast<AliESDEvent*>(InputEvent());
-  fMCev = MCEvent();
+  fTracksBarrel->Delete();
+  fTracksSA->Delete();
+  fTracksKink->Delete();
+  fV0List->Delete();
+  fEventInfo->Delete("");
 
+  fESDev = dynamic_cast<AliESDEvent*>(InputEvent());
   if(!fESDev){
     AliError("Failed retrieving ESD event");
     return;
   }
+  // WARNING
+  // This part may conflict with other detectors !!
+  if(!IsInitOCDB()){ 
+    AliInfo("Initializing OCDB ...");
+    // prepare OCDB access
+    AliCDBManager* ocdb = AliCDBManager::Instance();
+    ocdb->SetDefaultStorage(fOCDB.Data());
+    ocdb->SetRun(fESDev->GetRunNumber());
+    // create geo manager
+    AliCDBEntry* obj = ocdb->Get(AliCDBPath("GRP", "Geometry", "Data"));
+    AliGeomManager::SetGeometry((TGeoManager*)obj->GetObject());
+    AliGeomManager::GetNalignable("TRD");
+    AliGeomManager::ApplyAlignObjsFromCDB("TRD");
+    fgGeo = new AliTRDgeometry;
+
+    // set no of time bins
+    AliTRDtrackerV1::SetNTimeBins(AliTRDcalibDB::Instance()->GetNumberOfTimeBinsDCS());
+    AliInfo(Form("OCDB :  Loc[%s] Run[%d] TB[%d]", fOCDB.Data(), ocdb->GetRun(), AliTRDtrackerV1::GetNTimeBins()));
+
+    AliInfo(Form("Initializing TRD reco params for EventSpecie[%d]...",
+      fESDev->GetEventSpecie()));
+    fgReconstructor = new AliTRDReconstructor();
+    obj = ocdb->Get(AliCDBPath("TRD", "Calib", "RecoParam"));
+    obj->PrintMetaData();
+    TObjArray *recos((TObjArray*)obj->GetObject());
+    for(Int_t ireco(0); ireco<recos->GetEntriesFast(); ireco++){
+      AliTRDrecoParam *reco((AliTRDrecoParam*)recos->At(ireco));
+      Int_t es(reco->GetEventSpecie());
+      if(!(es&fESDev->GetEventSpecie())) continue;
+      fgReconstructor->SetRecoParam(reco);
+      TString s;
+      if(es&AliRecoParam::kLowMult) s="LowMult";
+      else if(es&AliRecoParam::kHighMult) s="HighMult";
+      else if(es&AliRecoParam::kCosmic) s="Cosmic";
+      else if(es&AliRecoParam::kCalib) s="Calib";
+      else s="Unknown";
+      AliInfo(Form("Using reco params for %s", s.Data()));
+      break;
+    }
+    SetInitOCDB();
+  }
+
+  // link MC if available
+  fMCev = MCEvent();
 
   // event selection : trigger cut
   if(UseLocalEvSelection() && fEvTrigger){ 
     Bool_t kTRIGGERED(kFALSE);
-    const TObjArray *trig = fEvTrigger->Tokenize(" ");
+    std::auto_ptr<TObjArray> trig(fEvTrigger->Tokenize(" "));
     for(Int_t itrig=trig->GetEntriesFast(); itrig--;){
       const Char_t *trigClass(((TObjString*)(*trig)[itrig])->GetName());
       if(fESDev->IsTriggerClassFired(trigClass)) {
@@ -247,11 +378,6 @@ void AliTRDinfoGen::UserExec(Option_t *){
     return;
   }
 
-  fTracksBarrel->Delete();
-  fTracksSA->Delete();
-  fTracksKink->Delete();
-  fV0List->Delete();
-  fEventInfo->Delete("");
   new(fEventInfo)AliTRDeventInfo(fESDev->GetHeader(), const_cast<AliESDRun *>(fESDev->GetESDRun()));
   
   Bool_t *trackMap(NULL);
@@ -278,7 +404,28 @@ void AliTRDinfoGen::UserExec(Option_t *){
   AliTRDtrackV1 *track = NULL;
   AliTRDseedV1 *tracklet = NULL;
   AliTRDcluster *cl = NULL;
+
+
+  // LOOP 0 - over ESD v0s
+  Float_t bField(fESDev->GetMagneticField());
+  AliESDv0 *v0(NULL);
+  Int_t v0pid[AliPID::kSPECIES];
+  for(Int_t iv0(0); iv0<fESDev->GetNumberOfV0s(); iv0++){
+    if(!(v0 = fESDev->GetV0(iv0))) continue;
+    // register v0
+    if(fV0Cut) new(fV0Info) AliTRDv0Info(*fV0Cut);
+    else new(fV0Info) AliTRDv0Info();
+    fV0Info->SetMagField(bField);
+    fV0Info->SetV0tracks(fESDev->GetTrack(v0->GetPindex()), fESDev->GetTrack(v0->GetNindex()));
+    fV0Info->SetV0Info(v0);
+    fV0List->Add(new AliTRDv0Info(*fV0Info));//  kFOUND=kFALSE;
+  }
+
+
+  // LOOP 1 - over ESD tracks
+  AliTRDv0Info *v0info=NULL;
   for(Int_t itrk = 0; itrk < nTracksESD; itrk++){
+    new(fTrackInfo) AliTRDtrackInfo();
     esdTrack = fESDev->GetTrack(itrk);
     AliDebug(3, Form("\n%3d ITS[%d] TPC[%d] TRD[%d]\n", itrk, esdTrack->GetNcls(0), esdTrack->GetNcls(1), esdTrack->GetNcls(2)));
 
@@ -322,9 +469,10 @@ void AliTRDinfoGen::UserExec(Option_t *){
         iref++;
       }
 
-      new(fTrackInfo) AliTRDtrackInfo();
+      fTrackInfo->SetMC();
       fTrackInfo->SetPDG(fPdg);
       fTrackInfo->SetPrimary(mcParticle->Particle()->IsPrimary());
+      fTrackInfo->SetLabel(label);
       Int_t jref = iref;//, kref = 0;
       while(jref<nRefs){
         ref = mcParticle->GetTrackReference(jref);
@@ -334,9 +482,6 @@ void AliTRDinfoGen::UserExec(Option_t *){
         jref++;
       }
       AliDebug(3, Form("NtrackRefs[%d(%d)]", fTrackInfo->GetNTrackRefs(), nRefs));
-    } else {
-      new (fTrackInfo) AliTRDtrackInfo();
-      fTrackInfo->SetPDG(fPdg);
     }
 
     // copy some relevant info to TRD track info
@@ -353,13 +498,25 @@ void AliTRDinfoGen::UserExec(Option_t *){
         dedx[in++]=esdTrack->GetTRDslice(il, is);
     for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++) dedx[in++]=esdTrack->GetTRDmomentum(il);
     fTrackInfo->SetSlices(in, dedx);
-    fTrackInfo->SetLabel(label);
     fTrackInfo->SetNumberOfClustersRefit(esdTrack->GetNcls(2));
     // some other Informations which we may wish to store in order to find problematic cases
     fTrackInfo->SetKinkIndex(esdTrack->GetKinkIndex(0));
     fTrackInfo->SetTPCncls(static_cast<UShort_t>(esdTrack->GetNcls(1)));
     nclsTrklt = 0;
   
+    // set V0pid info
+    for(Int_t iv(0); iv<fV0List->GetEntriesFast(); iv++){
+      if(!(v0info = (AliTRDv0Info*)fV0List->At(iv))) continue;
+      if(!v0info->fTrackP && !v0info->fTrackN) continue;
+      if(!v0info->HasTrack(fTrackInfo)) continue;
+      memset(v0pid, 0, AliPID::kSPECIES*sizeof(Int_t));
+      fTrackInfo->SetV0();
+      for(Int_t is=AliPID::kSPECIES; is--;){v0pid[is] = v0info->GetPID(is, fTrackInfo);}
+      fTrackInfo->SetV0pid(v0pid);
+      fTrackInfo->SetV0();
+      //const AliTRDtrackInfo::AliESDinfo *ei = fTrackInfo->GetESDinfo();
+      break;
+    }
 
     // read REC info
     esdFriendTrack = fESDfriend->GetTrack(itrk);
@@ -399,25 +556,28 @@ void AliTRDinfoGen::UserExec(Option_t *){
             AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] Pt[%5.2f]", fESDev->GetEventNumberInFile(), itrk, esdTrack->Pt()));
             selected = kFALSE;
           }
-          if(TMath::Abs(esdTrack->Eta()) > fgkEta){
+          if(selected && TMath::Abs(esdTrack->Eta()) > fgkEta){
             AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] Eta[%5.2f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(esdTrack->Eta())));
             selected = kFALSE;
           }
-          if(esdTrack->GetTPCNcls() < fgkNclTPC){ 
+          if(selected && esdTrack->GetTPCNcls() < fgkNclTPC){ 
             AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] NclTPC[%d]", fESDev->GetEventNumberInFile(), itrk, esdTrack->GetTPCNcls()));
             selected = kFALSE;
           }
           Float_t par[2], cov[3];
           esdTrack->GetImpactParameters(par, cov);
           if(IsCollision()){ // cuts on DCA
-            if(TMath::Abs(par[0]) > fgkTrkDCAxy){ 
+            if(selected && TMath::Abs(par[0]) > fgkTrkDCAxy){ 
               AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] DCAxy[%f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(par[0])));
               selected = kFALSE;
             }
-            if(TMath::Abs(par[1]) > fgkTrkDCAz){ 
+            if(selected && TMath::Abs(par[1]) > fgkTrkDCAz){ 
               AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] DCAz[%f]", fESDev->GetEventNumberInFile(), itrk, TMath::Abs(par[1])));
               selected = kFALSE;
             }
+          } else if(selected && fMCev && !fMCev->IsPhysicalPrimary(alab)){;
+            AliDebug(2, Form("Reject Ev[%4d] Trk[%3d] Primary", fESDev->GetEventNumberInFile(), itrk));
+            selected = kFALSE;
           }
         }
         if(fTrackCut && !fTrackCut->IsSelected(esdTrack)) selected = kFALSE;
@@ -436,13 +596,7 @@ void AliTRDinfoGen::UserExec(Option_t *){
     fTrackInfo->Delete("");
   }
 
-//   AliESDv0 *v0 = NULL;
-//   for(Int_t iv0=0; iv0<fESD->GetNumberOfV0s(); iv0++){
-//     if(!(v0 = fESD->GetV0(iv0))) continue;
-//     fV0List->Add(new AliTRDv0Info(v0));
-//   }
-
-  // Insert also MC tracks which are passing TRD where the track is not reconstructed
+  // LOOP 2 - over MC tracks which are passing TRD where the track is not reconstructed
   if(HasMCdata()){
     AliDebug(10, "Output of the MC track map:");
     for(Int_t itk = 0; itk < nTracksMC;  itk++) AliDebug(10, Form("trackMap[%d] = %s", itk, trackMap[itk] == kTRUE ? "TRUE" : "kFALSE"));
@@ -455,6 +609,7 @@ void AliTRDinfoGen::UserExec(Option_t *){
       Int_t iref = 0; AliTrackReference *ref = NULL; 
       Int_t nRefsTRD = 0;
       new(fTrackInfo) AliTRDtrackInfo();
+      fTrackInfo->SetMC();
       fTrackInfo->SetPDG(fPdg);
       while(iref<nRefs){ // count TRD TR
         Bool_t kIN(kFALSE);
@@ -498,16 +653,30 @@ void AliTRDinfoGen::UserExec(Option_t *){
     }
     delete[] trackMap;
   }
-  AliDebug(2, Form(
-    "\nEv[%3d] Tracks: ESD[%d] MC[%d]\n"
+  AliDebug(1, Form(
+    "\nEv[%3d] Tracks: ESD[%d] MC[%d] V0[%d]\n"
     "        TPCout[%d] TRDin[%d] TRDout[%d]\n"
     "        Barrel[%3d+%3d=%3d] SA[%2d+%2d=%2d] Kink[%2d+%2d=%2d]"
-    ,(Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC
+    ,(Int_t)AliAnalysisManager::GetAnalysisManager()->GetCurrentEntry(), nTracksESD, nTracksMC, fV0List->GetEntries()
     , nTPC, nTRDin, nTRDout
     ,nBarrel, nBarrelMC, fTracksBarrel->GetEntries()
     ,nSA, nSAMC, fTracksSA->GetEntries()
     ,nKink, nKinkMC, fTracksKink->GetEntries()
   ));
+  // save track statistics
+  TH1 *h((TH1S*)fContainer->At(0));
+  h->Fill( 0., nTracksESD);
+  h->Fill( 1., nTracksMC);
+  h->Fill( 2., fV0List->GetEntries());
+  h->Fill( 3., nTPC);
+  h->Fill( 4., nTRDin);
+  h->Fill( 5., nTRDout);
+  h->Fill( 6., nBarrel);
+  h->Fill( 7., nBarrelMC);
+  h->Fill( 8., nSA);
+  h->Fill( 9., nSAMC);
+  h->Fill(10., nKink);
+  h->Fill(11., nKinkMC);
 
   PostData(kTracksBarrel, fTracksBarrel);
   PostData(kTracksSA, fTracksSA);
@@ -516,6 +685,15 @@ void AliTRDinfoGen::UserExec(Option_t *){
   PostData(kV0List, fV0List);
 }
 
+//____________________________________________________________________
+void AliTRDinfoGen::SetLocalV0Selection(AliTRDv0Info *v0)
+{
+// Set V0 cuts from outside
+
+  if(!fV0Cut) fV0Cut = new AliTRDv0Info(*v0);
+  else new(fV0Cut) AliTRDv0Info(*v0);
+}
+
 //____________________________________________________________________
 void AliTRDinfoGen::SetTrigger(const Char_t *trigger)
 {
@@ -535,3 +713,4 @@ TTreeSRedirector* AliTRDinfoGen::DebugStream()
 }
 
 
+