]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDBackgroundCorrection.cxx
Extacting the OCDB in a separate module. The detectors have write permission in the...
[u/mrichter/AliRoot.git] / FMD / AliFMDBackgroundCorrection.cxx
index 33e5a352ba8f31e920e3d77bd0f61ff9b3714200..4ebecb4f56111da2618944d6c189a2442a590e33 100644 (file)
@@ -42,7 +42,6 @@
 #include "AliFMDHit.h"
 #include "AliLoader.h" 
 #include "AliFMD.h"
-#include "TH2F.h"
 #include "AliGenEventHeader.h"
 #include "AliHeader.h"
 #include "TFile.h"
@@ -55,6 +54,8 @@
 #include "TList.h"
 #include "AliFMDAnaParameters.h"
 #include "AliFMDAnaCalibBackgroundCorrection.h"
+#include "AliTrackReference.h"
+#include "AliFMDStripIndex.h"
 
 ClassImp(AliFMDBackgroundCorrection)
 //_____________________________________________________________________
@@ -65,10 +66,11 @@ AliFMDBackgroundCorrection::AliFMDBackgroundCorrection() :
 {} 
 
 //_____________________________________________________________________
-AliFMDBackgroundCorrection::AliFMDInputBG::AliFMDInputBG() : 
-  AliFMDInput(),
+AliFMDBackgroundCorrection::AliFMDInputBG::AliFMDInputBG(Bool_t hits_not_trackref) : 
+  AliFMDInput("galice.root"),
   fPrimaryArray(),
   fHitArray(),
+  fHitMap(),
   fPrim(0),
   fHits(0),
   fZvtxCut(0),
@@ -76,17 +78,24 @@ AliFMDBackgroundCorrection::AliFMDInputBG::AliFMDInputBG() :
   fPrevTrack(-1),
   fPrevDetector(-1),
   fPrevRing('Q'),
+  fPrevSec(-1),
   fNbinsEta(100)
 {
   AddLoad(kTracks); 
-  AddLoad(kHits); 
+  if(hits_not_trackref)
+    AddLoad(kHits);
+  else
+    AddLoad(kTrackRefs);
   AddLoad(kKinematics); 
   AddLoad(kHeader);
+  
+  
 }
 
 //_____________________________________________________________________
 
-void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(const Int_t nvtxbins,
+void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(Bool_t from_hits,
+                                                             const Int_t nvtxbins,
                                                              Float_t zvtxcut, 
                                                              const Int_t nBinsEta, 
                                                              Bool_t storeInAlien, 
@@ -103,7 +112,7 @@ void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(const Int_t nvtxbi
     Simulate(nEvents);
   else {
     //AliCDBManager::Instance()->SetDefaultStorage("alien://Folder=/alice/data/2008/LHC08d/OCDB/");
-    AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
+    AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
     AliCDBManager::Instance()->SetRun(runNo);
     
 #if defined(__CINT__)
@@ -127,7 +136,7 @@ void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(const Int_t nvtxbi
     
   AliInfo("Processing hits and primaries ");
   
-  AliFMDInputBG input;
+  AliFMDInputBG input(from_hits);
   
   if(!inFile) {
   
@@ -261,7 +270,7 @@ void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(const Int_t nvtxbi
   
   if(storeInAlien) {
     AliCDBManager* cdb = AliCDBManager::Instance();
-    cdb->SetDefaultStorage("local://$ALICE_ROOT");
+    cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
     AliCDBId      id(AliFMDAnaParameters::GetBackgroundPath(),runNo,endRunNo);
     
     AliCDBMetaData* meta = new AliCDBMetaData;                         
@@ -297,53 +306,84 @@ void AliFMDBackgroundCorrection::Simulate(Int_t nEvents) {
 }
 
 //_____________________________________________________________________
-Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::ProcessHit( AliFMDHit* h, TParticle* p) {
-  
-  AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
-  TArrayF vertex;
-  genHeader->PrimaryVertex(vertex);
+Bool_t 
+AliFMDBackgroundCorrection::AliFMDInputBG::ProcessHit(AliFMDHit* h, 
+                                                     TParticle* /*p*/) 
+{
   
-  if(TMath::Abs(vertex.At(2)) > fZvtxCut) 
+  if(!h)
     return kTRUE;
+  Bool_t retval = ProcessEvent(h->Detector(),
+                              h->Ring(),
+                              h->Sector(),
+                              h->Strip(),
+                              h->Track(),
+                              h->Q());
+  
+  return retval;
+}
+//_____________________________________________________________________
+Bool_t 
+AliFMDBackgroundCorrection::AliFMDInputBG::ProcessTrackRef(AliTrackReference* tr, 
+                                                          TParticle* p) 
+{
+  if(!tr)
+    return kTRUE;
+  UShort_t det,sec,strip;
+  Char_t   ring;
+  AliFMDStripIndex::Unpack(tr->UserId(),det,ring,sec,strip);
+  Int_t         nTrack  = tr->GetTrack();
+  TDatabasePDG* pdgDB   = TDatabasePDG::Instance();
+  TParticlePDG* pdgPart = pdgDB->GetParticle(p->GetPdgCode());
+  Float_t       charge  = (pdgPart ? pdgPart->Charge() : 0);
+  Bool_t        retval  = ProcessEvent(det,ring,sec,strip,nTrack,charge);
+  return retval;
   
-  Double_t delta = 2*fZvtxCut/fNvtxBins;
-  Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
-  Int_t vertexBin = (Int_t)vertexBinDouble;
+}
+//_____________________________________________________________________
+Bool_t 
+AliFMDBackgroundCorrection::AliFMDInputBG::ProcessEvent(UShort_t det,
+                                                       Char_t   ring, 
+                                                       UShort_t sec, 
+                                                       UShort_t strip,
+                                                       Int_t    nTrack,
+                                                       Float_t  charge)
+{
   
-  Int_t i = h->Track();
   
-  if(h)
-    if(h->Q() !=  0 && (i != fPrevTrack || h->Detector() != fPrevDetector || h->Ring() != fPrevRing)) {
-      
-      Int_t det = h->Detector();
-      Char_t ring = h->Ring();
-      Int_t iring = (ring == 'I' ? 0 : 1);
-      
-      TObjArray* detArray  = (TObjArray*)fHitArray.At(det);
-      TObjArray* vtxArray  = (TObjArray*)detArray->At(iring);
-      TH2F* hHits          = (TH2F*)vtxArray->At(vertexBin);
-      
-      Float_t phi   = TMath::ATan2(h->Y(),h->X());
-      if(phi<0)
-       phi = phi+2*TMath::Pi();
-      Float_t theta = TMath::ATan2(TMath::Sqrt(TMath::Power(h->X(),2)+TMath::Power(h->Y(),2)),h->Z()+vertex.At(2));
-      Float_t eta   = -1*TMath::Log(TMath::Tan(0.5*theta));
-      hHits->Fill(eta,phi);
-      fHits++;
-      fPrevDetector = det;
-      fPrevRing     = ring;
-    }
-   
-  fPrevTrack = i;
+  
+  if(charge !=  0 && 
+     ((nTrack != fPrevTrack) || 
+      (det != fPrevDetector) || 
+      (ring != fPrevRing)    ||
+      (sec != fPrevSec))) {
+    fHitMap.operator()(det,ring,sec,strip) = 1;
+    fHits++;
+    
+  }
+  
+  fPrevDetector = det;
+  fPrevRing     = ring;
+  fPrevSec      = sec;
+  fPrevTrack    = nTrack;
+  
   return kTRUE;
+
 }
 
 //_____________________________________________________________________
-Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Init() {
-  
+Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Init() 
+{
   fPrimaryArray.SetOwner();
   fPrimaryArray.SetName("FMD_primary");
   
+  fPrimaryMapInner.SetBins(fNbinsEta, -6,6, 20, 0, 2*TMath::Pi());
+  fPrimaryMapOuter.SetBins(fNbinsEta, -6,6, 40, 0, 2*TMath::Pi());
+  fPrimaryMapInner.SetName("fPrimaryMapInner");
+  fPrimaryMapInner.SetName("fPrimaryMapOuter");
+  
+  fPrimaryMapInner.Sumw2();
+  fPrimaryMapOuter.Sumw2();
   for(Int_t iring = 0; iring<2;iring++) {
     Char_t ringChar = (iring == 0 ? 'I' : 'O');
     TObjArray* ringArray = new TObjArray();
@@ -364,49 +404,75 @@ Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Init() {
   fHitArray.SetOwner();
   fHitArray.SetName("FMD_hits");
    
-  for(Int_t det =1; det<=3;det++)
-    {
-      TObjArray* detArrayHits = new TObjArray();
-      detArrayHits->SetName(Form("FMD%d",det));
-      fHitArray.AddAtAndExpand(detArrayHits,det);
-      Int_t nRings = (det==1 ? 1 : 2);
-      for(Int_t ring = 0;ring<nRings;ring++)
-       {
-         Int_t nSec = (ring == 1 ? 40 : 20);
-         Char_t ringChar = (ring == 0 ? 'I' : 'O');
-         TObjArray* vtxArrayHits = new TObjArray();
-         vtxArrayHits->SetName(Form("FMD%d%c",det,ringChar));
-         detArrayHits->AddAtAndExpand(vtxArrayHits,ring);
-         for(Int_t v=0; v<fNvtxBins;v++)
-           {
-             
-             TH2F* hHits          = new TH2F(Form("hHits_FMD%d%c_vtx%d",det,ringChar,v),
-                                             Form("hHits_FMD%d%c_vtx%d",det,ringChar,v),
-                                             fNbinsEta, -6,6, nSec, 0, 2*TMath::Pi());
-             hHits->Sumw2();
-             vtxArrayHits->AddAtAndExpand(hHits,v);
-                     
-           } 
-       }
-      
+  for(Int_t det =1; det<=3;det++) {
+    TObjArray* detArrayHits = new TObjArray();
+    detArrayHits->SetName(Form("FMD%d",det));
+    fHitArray.AddAtAndExpand(detArrayHits,det);
+    Int_t nRings = (det==1 ? 1 : 2);
+    for(Int_t ring = 0;ring<nRings;ring++) {
+      Int_t nSec = (ring == 1 ? 40 : 20);
+      Char_t ringChar = (ring == 0 ? 'I' : 'O');
+      TObjArray* vtxArrayHits = new TObjArray();
+      vtxArrayHits->SetName(Form("FMD%d%c",det,ringChar));
+      detArrayHits->AddAtAndExpand(vtxArrayHits,ring);
+      for(Int_t v=0; v<fNvtxBins;v++) {
+       TH2F* hHits = new TH2F(Form("hHits_FMD%d%c_vtx%d", det,ringChar,v),
+                              Form("hHits_FMD%d%c_vtx%d", det,ringChar,v),
+                              fNbinsEta, -6,6, nSec, 0, 2*TMath::Pi());
+       hHits->Sumw2();
+       vtxArrayHits->AddAtAndExpand(hHits,v);
+       
+      } 
     }
+  }
 
-
-  
   AliFMDInput::Init();
   
-  
   return kTRUE;
 }
 //_____________________________________________________________________
 
-Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Begin(Int_t event ) {
+Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Begin(Int_t event ) 
+{
 
-  Bool_t retVal = AliFMDInput::Begin(event); 
+  Bool_t             retVal    = AliFMDInput::Begin(event); 
+  AliStack*          partStack = fLoader->Stack();
+  Int_t              nTracks   = partStack->GetNtrack();
+  
+  
+  for(Int_t j=0;j<nTracks;j++) {
+    TParticle* p           = partStack->Particle(j);
+    TDatabasePDG* pdgDB    = TDatabasePDG::Instance();
+    TParticlePDG* pdgPart  = pdgDB->GetParticle(p->GetPdgCode());
+    Float_t       charge   = (pdgPart ? pdgPart->Charge() : 0);
+    Float_t       phi      = TMath::ATan2(p->Py(),p->Px());
+    
+    if(phi<0) phi = phi+2*TMath::Pi();
+    // if(p->Theta() == 0) continue;
+    Float_t eta   = p->Eta();   
+    
+    // std::cout<<-1*TMath::Log(TMath::Tan(0.5*p->Theta()))<<std::endl;
+    
+    Bool_t primary = partStack->IsPhysicalPrimary(j);
+    //(charge!=0)&&(TMath::Abs(p->Vx() - vertex.At(0))<0.01)&&(TMath::Abs(p->Vy() - vertex.At(1))<0.01)&&(TMath::Abs(p->Vz() - vertex.At(2))<0.01);
+    if(primary && charge !=0) {
+      
+      
+      
+      fPrim++;
+      
+      fPrimaryMapInner.Fill(eta,phi);
+      fPrimaryMapOuter.Fill(eta,phi);
+    }
+  }
+  
+  return retVal;
+}
+//_____________________________________________________________________
+Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::End()  {
   
-  AliStack* partStack=fLoader->Stack();
+  Bool_t retval = AliFMDInput::End();
   
-  Int_t nTracks=partStack->GetNtrack();
   AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
   TArrayF vertex;
   genHeader->PrimaryVertex(vertex);
@@ -414,40 +480,63 @@ Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Begin(Int_t event ) {
   if(TMath::Abs(vertex.At(2)) > fZvtxCut) 
     return kTRUE;
   
-  Double_t delta = 2*fZvtxCut/fNvtxBins;
+  Double_t delta           = 2*fZvtxCut/fNvtxBins;
   Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
-  Int_t vertexBin = (Int_t)vertexBinDouble;
-  
-  for(Int_t j=0;j<nTracks;j++)
-       {
-         TParticle* p  = partStack->Particle(j);
-         //TDatabasePDG* pdgDB = TDatabasePDG::Instance();
-         //TParticlePDG* pdgPart = pdgDB->GetParticle(p->GetPdgCode());
-         //Float_t charge = (pdgPart ? pdgPart->Charge() : 0);
-         Float_t phi = TMath::ATan2(p->Py(),p->Px());
+  Int_t    vertexBin       = (Int_t)vertexBinDouble;
+  //Primaries
+  TObjArray* innerArray = (TObjArray*)fPrimaryArray.At(0);
+  TObjArray* outerArray = (TObjArray*)fPrimaryArray.At(1);
+  
+  TH2F* hPrimaryInner  = (TH2F*)innerArray->At(vertexBin);
+  TH2F* hPrimaryOuter  = (TH2F*)outerArray->At(vertexBin);
+  
+  hPrimaryInner->Add(&fPrimaryMapInner);
+  hPrimaryOuter->Add(&fPrimaryMapOuter);
+  
+  //Hits
+  for(UShort_t det=1;det<=3;det++) {
+    Int_t nRings = (det==1 ? 1 : 2);
+    for (UShort_t ir = 0; ir < nRings; ir++) {
+      Char_t   ring = (ir == 0 ? 'I' : 'O');
+      UShort_t nsec = (ir == 0 ? 20  : 40);
+      UShort_t nstr = (ir == 0 ? 512 : 256);
+      
+      for(UShort_t sec =0; sec < nsec;  sec++) {
+       
+       for(UShort_t strip = 0; strip < nstr; strip++) {
          
-         if(phi<0)
-           phi = phi+2*TMath::Pi();
-         if(p->Theta() == 0) continue;
-             Float_t eta   = -1*TMath::Log(TMath::Tan(0.5*p->Theta()));
+         if(fHitMap.operator()(det,ring,sec,strip) > 0) {
+         
+           Double_t x,y,z;
+           AliFMDGeometry* fmdgeo = AliFMDGeometry::Instance();
+           fmdgeo->Detector2XYZ(det,ring,sec,strip,x,y,z);
+           
+           Int_t iring = (ring == 'I' ? 0 : 1);
+           
+           TObjArray* detArray  = (TObjArray*)fHitArray.At(det);
+           TObjArray* vtxArray  = (TObjArray*)detArray->At(iring);
+           TH2F* hHits          = (TH2F*)vtxArray->At(vertexBin);
+           
+           Float_t   phi   = TMath::ATan2(y,x);
+           if(phi<0) phi   = phi+2*TMath::Pi();
+           Float_t   r     = TMath::Sqrt(TMath::Power(x,2)+TMath::Power(y,2));
+           Float_t   theta = TMath::ATan2(r,z-vertex.At(2));
+           Float_t   eta   = -1*TMath::Log(TMath::Tan(0.5*theta));
+           hHits->Fill(eta,phi);
+         }
          
-             Bool_t primary = partStack->IsPhysicalPrimary(j);
-             //(charge!=0)&&(TMath::Abs(p->Vx() - vertex.At(0))<0.01)&&(TMath::Abs(p->Vy() - vertex.At(1))<0.01)&&(TMath::Abs(p->Vz() - vertex.At(2))<0.01);
-             if(primary) {
-               fPrim++;
-               TObjArray* innerArray = (TObjArray*)fPrimaryArray.At(0);
-               TObjArray* outerArray = (TObjArray*)fPrimaryArray.At(1);
-               
-               TH2F* hPrimaryInner  = (TH2F*)innerArray->At(vertexBin);
-               TH2F* hPrimaryOuter  = (TH2F*)outerArray->At(vertexBin);
-               hPrimaryInner->Fill(eta,phi);
-               hPrimaryOuter->Fill(eta,phi);
-             }
        }
+      }
+    }
+  }
   
-  return retVal;
+  fPrimaryMapInner.Reset();
+  fPrimaryMapOuter.Reset();
+  fHitMap.Reset(0);
+  
+  return retval;
 }
-//_____________________________________________________________________
+
 //
 // EOF
 //