]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - JETAN/AliAnalysisTaskJetBackgroundSubtract.cxx
satisfy coding conventions
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskJetBackgroundSubtract.cxx
index 8f7a183b046a7e65f9ac34d00e8e86b6f36dfacc..4244b817009249102964e2997f419406ab68f52d 100644 (file)
@@ -25,6 +25,7 @@
 #include <TH2F.h>
 #include <THnSparse.h>
 #include <TSystem.h>
+#include <TObjArray.h>
 #include <TInterpreter.h>
 #include <TList.h>
 #include <TLorentzVector.h>
@@ -44,6 +45,9 @@
 ClassImp(AliAnalysisTaskJetBackgroundSubtract)
 
 AliAnalysisTaskJetBackgroundSubtract::~AliAnalysisTaskJetBackgroundSubtract(){
+  // 
+  // destructor
+  //
   delete fJBArray;
   delete fOutJetArrayList;
   delete fInJetArrayList;
@@ -54,12 +58,13 @@ AliAnalysisTaskJetBackgroundSubtract::AliAnalysisTaskJetBackgroundSubtract():
   fAODOut(0x0),
   fAODIn(0x0),  
   fAODExtension(0x0),
-  fJBArray(new TObjArray()),
+  fJBArray(0),
   fBackgroundBranch(""),
   fNonStdFile(""),
   fReplaceString1("B0"),
   fReplaceString2("B%d"),
   fSubtraction(k4Area),
+  fKeepJets(kFALSE),
   fInJetArrayList(0x0),
   fOutJetArrayList(0x0),
   fh2CentvsRho(0x0),
@@ -81,12 +86,13 @@ AliAnalysisTaskJetBackgroundSubtract::AliAnalysisTaskJetBackgroundSubtract(const
   fAODOut(0x0),
   fAODIn(0x0),  
   fAODExtension(0x0),
-  fJBArray(new TObjArray()),
+  fJBArray(0),
   fBackgroundBranch(""),
   fNonStdFile(""),
   fReplaceString1("B0"),
   fReplaceString2("B%d"),
   fSubtraction(k4Area),
+  fKeepJets(kFALSE),
   fInJetArrayList(0x0),
   fOutJetArrayList(0x0),
   fh2CentvsRho(0x0),
@@ -106,6 +112,8 @@ AliAnalysisTaskJetBackgroundSubtract::AliAnalysisTaskJetBackgroundSubtract(const
 
 Bool_t AliAnalysisTaskJetBackgroundSubtract::Notify()
 {
+  //
+  // exec with every new file
   //
   fAODIn = dynamic_cast<AliAODEvent*>(InputEvent());
 
@@ -116,7 +124,7 @@ Bool_t AliAnalysisTaskJetBackgroundSubtract::Notify()
   fInJetArrayList->Clear();
   fOutJetArrayList->Clear();
 
-  for(int iJB = 0;iJB<fJBArray->GetEntries();iJB++){
+  for(int iJB = 0;iJB<(fJBArray?fJBArray->GetEntries():0);iJB++){
     TObjString *ostr = (TObjString*)fJBArray->At(iJB);
  
   
@@ -199,7 +207,7 @@ void AliAnalysisTaskJetBackgroundSubtract::UserCreateOutputObjects()
   if(!fInJetArrayList)fInJetArrayList =new TList();
   if(!fOutJetArrayList)fOutJetArrayList =new TList();
 
-  for(int iJB = 0;iJB<fJBArray->GetEntries();iJB++){
+  for(int iJB = 0;iJB<(fJBArray?fJBArray->GetEntries():0);iJB++){
     TObjString *ostr = (TObjString*)fJBArray->At(iJB);
     TString newName(ostr->GetString().Data());
     if(!newName.Contains(fReplaceString1.Data())){
@@ -231,7 +239,15 @@ void AliAnalysisTaskJetBackgroundSubtract::UserCreateOutputObjects()
   fHistList->SetOwner();
   PostData(1, fHistList); // post data in any case once
 
-  for(int iJB = 0;iJB<fJBArray->GetEntries();iJB++){
+  // 
+  
+  // delta pT vs. area vs. cent vs. mult
+  const Int_t nSparseBinsDelta = 4;
+  const Int_t nBinsDelta[nSparseBinsDelta] =   {   241,  10,  10,  25}; 
+  const Double_t xminDelta[nSparseBinsDelta] = {-120.5,   0,   0,   0};
+  const Double_t xmaxDelta[nSparseBinsDelta] = { 120.5, 1.0, 100,5000};
+  for(int iJB = 0;iJB<(fJBArray?fJBArray->GetEntries():0);iJB++){
     TObjString *ostr = (TObjString*)fJBArray->At(iJB);
     TString oldName(ostr->GetString().Data()); 
     TString newName(ostr->GetString().Data()); 
@@ -241,8 +257,11 @@ void AliAnalysisTaskJetBackgroundSubtract::UserCreateOutputObjects()
       continue;
     }
     newName.ReplaceAll(fReplaceString1.Data(),Form(fReplaceString2.Data(),fSubtraction));
+    
     TH2F *hTmp = new TH2F(Form("h2PtInPtOut_%d",iJB),Form(";%s p_{T}; %s p_{T}",oldName.Data(),newName.Data()),200,0,200.,400,-200.,200.);
     fHistList->Add(hTmp);
+    THnSparseF *hFTmp = new THnSparseF(Form("hnDPtAreaCentMult_%d",iJB),Form("%s delta;#delta p_{T};Area;cent;mult",newName.Data()),nSparseBinsDelta,nBinsDelta,xminDelta,xmaxDelta);
+    fHistList->Add(hFTmp);
   }
 
   Bool_t oldStatus = TH1::AddDirectoryStatus();
@@ -253,13 +272,13 @@ void AliAnalysisTaskJetBackgroundSubtract::UserCreateOutputObjects()
   //    
 
  
-    fh2CentvsRho = new TH2F("fh2CentvsRho","centrality vs background density",100,0.,100.,2000,0.,200.);
-    fh2CentvsSigma = new TH2F("fh2CentvsSigma","centrality vs backgroun sigma",100,0.,100.,1000,0.,50.);
+    fh2CentvsRho = new TH2F("fh2CentvsRho","centrality vs background density", 100,0.,100.,600,0.,300.);
+    fh2CentvsSigma = new TH2F("fh2CentvsSigma","centrality vs backgroun sigma",100,0.,100.,500,0.,50.);
     fHistList->Add(fh2CentvsRho);
     fHistList->Add(fh2CentvsSigma);
 
-    fh2MultvsRho = new TH2F("fh2MultvsRho","mult vs background density",1000,0.,5000.,300,0.,300.);
-    fh2MultvsSigma = new TH2F("fh2MultvsSigma","mult vs backgroun sigma",1000,0.,5000.,500,0.,50.);
+    fh2MultvsRho = new TH2F("fh2MultvsRho","mult vs background density", 100,0.,5000.,600,0.,300.);
+    fh2MultvsSigma = new TH2F("fh2MultvsSigma","mult vs background sigma",100,0.,5000.,500,0.,50.);
     fHistList->Add(fh2MultvsRho);
     fHistList->Add(fh2MultvsSigma);
 
@@ -274,7 +293,6 @@ void AliAnalysisTaskJetBackgroundSubtract::UserCreateOutputObjects()
      fHistList->Add(fh2ShiftPhiLeading);
    }
     
-
   // =========== Switch on Sumw2 for all histos ===========
   for (Int_t i=0; i<fHistList->GetEntries(); ++i) {
     TH1 *h1 = dynamic_cast<TH1*>(fHistList->At(i));
@@ -289,7 +307,7 @@ void AliAnalysisTaskJetBackgroundSubtract::UserCreateOutputObjects()
 
   if(fBackgroundBranch.Length()==0)
     AliError(Form("%s:%d No BackgroundBranch defined",(char*)__FILE__,__LINE__));
-  if(fJBArray->GetEntries()==0)
+  if((fJBArray?fJBArray->GetEntries():0)==0)
     AliError(Form("%s:%d No Jet Branches defined defined",(char*)__FILE__,__LINE__));
 }
 
@@ -303,10 +321,13 @@ void AliAnalysisTaskJetBackgroundSubtract::Init()
 
 void AliAnalysisTaskJetBackgroundSubtract::UserExec(Option_t */*option*/)
 {
+  //
+  // Execute for every selected event
+  //
 
   if (fDebug > 1) printf("AnalysisTaskJetBackgroundSubtract::UserExec() \n");
   ResetOutJets();
-  if(fBackgroundBranch.Length()==0||fJBArray->GetEntries()==0){
+  if(fBackgroundBranch.Length()==0||(fJBArray?fJBArray->GetEntries():0)==0){
     if(fDebug)Printf("%s:%d No background subtraction done",(char*)__FILE__,__LINE__);
     PostData(1,fHistList);
   }
@@ -431,102 +452,112 @@ void AliAnalysisTaskJetBackgroundSubtract::UserExec(Option_t */*option*/)
       continue;
     }
     TH2F* h2PtInOut = (TH2F*)fHistList->FindObject(Form("h2PtInPtOut_%d",iJB));
+    THnSparseF* hnDPtAreaCentMult = (THnSparseF*)fHistList->FindObject(Form("hnDPtAreaCentMult_%d",iJB));
     // loop over all jets
     Int_t nOut = 0;
       
+    Double_t deltaPt[4];
+    deltaPt[2] = cent;
+    deltaPt[3] = mult;
 
     for(int i = 0;i < jarray->GetEntriesFast();i++){
       AliAODJet *jet = (AliAODJet*)jarray->At(i);
       AliAODJet tmpNewJet(*jet);
       Bool_t bAdd = false;
-     
+      Float_t ptSub = 0;
+
 
       if(fSubtraction==kArea){ 
        Double_t background = rho * jet->EffectiveAreaCharged();
-       Float_t ptSub = jet->Pt() - background; 
+       ptSub = jet->Pt() - background; 
        if(fDebug>2){
          Printf("%s:%d Jet %d %3.3f %3.3f",(char*)__FILE__,__LINE__,i,jet->Pt(),ptSub);
        }
-       if(ptSub<0){
+       if(ptSub<=0){
          // optionally rescale it and keep??
-         bAdd = false; // RescaleJetMomentum(&tmpNewJet,0.1);
-         if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),ptSub);
+         if(fKeepJets){
+            bAdd = RescaleJetMomentum(&tmpNewJet,0.1);
+         }
+         else{
+           bAdd = false;
+         }
        }
        else{
          bAdd = RescaleJetMomentum(&tmpNewJet,ptSub);
-         if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),ptSub);
        }
        // add background estimates to the new jet object
        // allows to recover old p_T and rho...
        tmpNewJet.SetBgEnergy(background,0);
+       tmpNewJet.SetPtSubtracted(ptSub,0);
       }// kAREA
       else if(fSubtraction==kRhoRecalc){
        Double_t background = rho * jet->EffectiveAreaCharged();
-       Float_t ptSub = jet->Pt() - background; 
+       ptSub = jet->Pt() - background; 
         if(fDebug>2){
          Printf("%s:%d Jet %d %3.3f %3.3f %3.3f %3.3f",(char*)__FILE__,__LINE__,i,jet->Pt(),ptSub,background,rho);}
-       if(ptSub<0){
-         // optionally rescale it and keep??
-         bAdd = false;// RescaleJetMomentum(&tmpNewJet,0.1);
-         if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),ptSub);
+       if(ptSub<=0){
+         // optionally rescale it and keep
+         if(fKeepJets){
+            bAdd = RescaleJetMomentum(&tmpNewJet,0.1);
+         }
+         else{
+           bAdd = false;
+         }
        }
        else{
          bAdd = RescaleJetMomentum(&tmpNewJet,ptSub);
-         if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),ptSub);
        }
        // add background estimates to the new jet object
        // allows to recover old p_T and rho...
        tmpNewJet.SetBgEnergy(background,0);
-
+       tmpNewJet.SetPtSubtracted(ptSub,0);
       }//kRhoRecalc
        else if(fSubtraction==kRhoRC){
        Double_t background = rho * jet->EffectiveAreaCharged();
-       Float_t ptSub = jet->Pt() - background; 
+       ptSub = jet->Pt() - background; 
        if(fDebug>2){   Printf("%s:%d Jet %d %3.3f %3.3f %3.3f %3.3f",(char*)__FILE__,__LINE__,i,jet->Pt(),ptSub,background,rho);}
-       if(ptSub<0){
-         // optionally rescale it and keep??
-         bAdd = false; // RescaleJetMomentum(&tmpNewJet,0.1);
-         if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),ptSub);
+       if(ptSub<=0){
+         if(fKeepJets){
+            bAdd = RescaleJetMomentum(&tmpNewJet,0.1);
+         }
+         else{
+           bAdd = false;
+         }
        }
        else{
          bAdd = RescaleJetMomentum(&tmpNewJet,ptSub);
-         if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),ptSub);
        }
        // add background estimates to the new jet object
        // allows to recover old p_T and rho...
        tmpNewJet.SetBgEnergy(background,0);
-
+       tmpNewJet.SetPtSubtracted(ptSub,0);
        }//kRhoRC
 
        else if(fSubtraction==k4Area&&jet->VectorAreaCharged()){
-
-        
         backgroundv.SetPxPyPzE(rho*(jet->VectorAreaCharged())->Px(),rho*(jet->VectorAreaCharged())->Py(),rho*(jet->VectorAreaCharged())->Pz(),rho*(jet->VectorAreaCharged())->E());
-        if((backgroundv.E()>jet->E())&&(backgroundv.Pt()>jet->Pt())){
-       
-          // optionally rescale it and keep??
-          bAdd = false; // RescaleJetMomentum(&tmpNewJet,0.1);
-          if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),jet->Pt()-backgroundv.Pt());
+        ptSub = jet->Pt()-backgroundv.Pt();
+        if((backgroundv.E()>=jet->E())||(backgroundv.Pt()>=jet->Pt())){
+          if(fKeepJets){
+            bAdd =  RescaleJetMomentum(&tmpNewJet,0.1);
+          }
+          else{
+            bAdd = false;
+          }
         }
         else{
           bAdd = RescaleJet4vector(&tmpNewJet,backgroundv);
         }
         // add background estimates to the new jet object
         // allows to recover old p_T and rho...
-        tmpNewJet.SetBgEnergy(backgroundv.P(),0);
+        tmpNewJet.SetBgEnergy(backgroundv.Pt(),0);
+        tmpNewJet.SetPtSubtracted(ptSub,0);
         
        }//kArea4vector  
 
-
-
-
-
-
       if(bAdd){
         AliAODJet *newJet = new ((*jarrayOut)[nOut++]) AliAODJet(tmpNewJet);
        // what about track references, clear for now...
        if(fSubtraction==k4Area){
-         if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),jet->Pt()-newJet->Pt());
          fh2ShiftEta->Fill(jet->Eta(),newJet->Eta());
          fh2ShiftPhi->Fill(jet->Phi(),newJet->Phi());
          if(i==0){fh2ShiftEtaLeading->Fill(jet->Eta(),newJet->Eta());
@@ -540,6 +571,12 @@ void AliAnalysisTaskJetBackgroundSubtract::UserExec(Option_t */*option*/)
          if(vp)newJet->AddTrack(vp);
        }
       }
+      if(h2PtInOut)h2PtInOut->Fill(jet->Pt(),ptSub);
+      if(hnDPtAreaCentMult){
+       deltaPt[0] = ptSub;
+       deltaPt[1] = jet->EffectiveAreaCharged();
+       hnDPtAreaCentMult->Fill(deltaPt);
+      }
     }
     if(jarrayOut)jarrayOut->Sort();
    }
@@ -585,10 +622,14 @@ Bool_t AliAnalysisTaskJetBackgroundSubtract::RescaleJet4vector(AliAODJet *jet,TL
 
 Double_t AliAnalysisTaskJetBackgroundSubtract::RecalcRho(TClonesArray* bkgClusters,Double_t meanarea){
   
+  //
+  // recalc rhoo
+  // 
+
   Double_t ptarea=0.;
   Int_t count=0;
   Double_t rho=0.; 
-  const Double_t Rlimit2=0.8*0.8;  //2*jet radius.
+  const Double_t rLimit2=0.8*0.8;  //2*jet radius.
   TClonesArray* jarray=0;
   
   for(int iJB = 0;iJB<fInJetArrayList->GetEntries();iJB++){
@@ -610,7 +651,7 @@ Double_t AliAnalysisTaskJetBackgroundSubtract::RecalcRho(TClonesArray* bkgCluste
        (first->Phi()-clus->Phi())*(first->Phi()-clus->Phi());
       Double_t distance2= (second->Eta()-clus->Eta())*(second->Eta()-clus->Eta())+
        (second->Phi()-clus->Phi())*(second->Phi()-clus->Phi());
-      if((distance1<Rlimit2)||(distance2<Rlimit2)) continue;    
+      if((distance1<rLimit2)||(distance2<rLimit2)) continue;    
       ptarea=ptarea+clus->Pt()/clus->EffectiveAreaCharged(); 
       count=count+1;}
     if(count!=0) rho=ptarea/count; 
@@ -618,12 +659,16 @@ Double_t AliAnalysisTaskJetBackgroundSubtract::RecalcRho(TClonesArray* bkgCluste
   return rho;
 }
 
-   Double_t AliAnalysisTaskJetBackgroundSubtract::RhoRC(TClonesArray* bkgClustersRC){
+Double_t AliAnalysisTaskJetBackgroundSubtract::RhoRC(TClonesArray* bkgClustersRC){
+
+  // 
+  // calc rho from random cones
+  //
   
        Double_t ptarea=0.;
        Int_t count=0;
        Double_t rho=0.; 
-       const Double_t Rlimit2=0.8*0.8;  //2*jet radius.
+       const Double_t rLimit2=0.8*0.8;  //2*jet radius.
        TClonesArray* jarray=0;
         for(int iJB = 0;iJB<fInJetArrayList->GetEntries();iJB++){
          TObjString *ostr = (TObjString*)fInJetArrayList->At(iJB);
@@ -644,7 +689,7 @@ Double_t AliAnalysisTaskJetBackgroundSubtract::RecalcRho(TClonesArray* bkgCluste
             (first->Phi()-clus->Phi())*(first->Phi()-clus->Phi());
           Double_t distance2= (second->Eta()-clus->Eta())*(second->Eta()-clus->Eta())+
             (second->Phi()-clus->Phi())*(second->Phi()-clus->Phi());
-          if((distance1<Rlimit2)||(distance2<Rlimit2)) continue;    
+          if((distance1<rLimit2)||(distance2<rLimit2)) continue;    
           ptarea=ptarea+clus->Pt()/clus->EffectiveAreaCharged(); 
           count=count+1;}
          if(count!=0) rho=ptarea/count;  }
@@ -660,6 +705,10 @@ Double_t AliAnalysisTaskJetBackgroundSubtract::RecalcRho(TClonesArray* bkgCluste
 
 
 void AliAnalysisTaskJetBackgroundSubtract::ResetOutJets(){
+  //
+  // Reset the output jets
+  //
+
   if(!fOutJetArrayList)return;
   for(int iJB = 0;iJB<fOutJetArrayList->GetEntries();iJB++){
     TClonesArray* jarray = (TClonesArray*)fOutJetArrayList->At(iJB);
@@ -669,6 +718,11 @@ void AliAnalysisTaskJetBackgroundSubtract::ResetOutJets(){
 
 
 void AliAnalysisTaskJetBackgroundSubtract::PrintAODContents(){
+
+  //
+  // guess from the name what this function does
+  //
+
   if(fAODIn){
     Printf("%s:%d >>>>>> Input",(char*)__FILE__,__LINE__);
     fAODIn->Print();
@@ -684,6 +738,10 @@ void AliAnalysisTaskJetBackgroundSubtract::PrintAODContents(){
 }
 
 Int_t AliAnalysisTaskJetBackgroundSubtract::MultFromJetRefs(TClonesArray* jets){
+  //
+  // calculate multiplicty based on jet references
+  //
+
   if(!jets)return 0;
 
   Int_t refMult = 0;
@@ -697,3 +755,8 @@ Int_t AliAnalysisTaskJetBackgroundSubtract::MultFromJetRefs(TClonesArray* jets){
   return refMult;
 
 }
+
+void  AliAnalysisTaskJetBackgroundSubtract::AddJetBranch(const char* c){
+  if(!fJBArray)fJBArray = new TObjArray();
+  fJBArray->Add(new TObjString(c));
+}