coverity fix
[u/mrichter/AliRoot.git] / PWG4 / totEt / AliAnalysisHadEt.cxx
index 3d086c2..e0cc8ef 100644 (file)
@@ -8,6 +8,7 @@
 // it has daughters, AliAnalysisHadEtMonteCarlo and 
 // AliAnalysisHadEtReconstructed which loop over either Monte Carlo data or 
 // real data to get Et
+
 #include "AliAnalysisHadEt.h"
 #include "TMath.h"
 #include "TList.h"
 #include "TDatabasePDG.h"
 #include "TParticle.h"
 #include "Rtypes.h"
+#include "AliPDG.h"
 
 using namespace std;
 
 ClassImp(AliAnalysisHadEt);
 
 
-Int_t AliAnalysisHadEt::fgnumOfEtaBins = 46;
-Float_t AliAnalysisHadEt::fgEtaAxis[47]={-0.78, -0.74, -0.7, -0.66, -0.62, -0.58, -0.54, -0.5, -0.46, -0.42, -0.38, -0.34, -0.3, -0.26, -0.22, -0.18, -0.14, -0.12, -0.1, -0.08, -0.06, -0.04, -0.02, -0.0, 0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.18, 0.22, 0.26, 0.3, 0.34, 0.38, 0.42, 0.46, 0.5, 0.54, 0.58, 0.62, 0.66, 0.7, 0.74, 0.78};
+Int_t AliAnalysisHadEt::fgnumOfEtaBins = 16;
+Float_t AliAnalysisHadEt::fgEtaAxis[17]={-0.78, -0.7, -0.58, -0.46, -0.34, -0.22, -0.12, -0.06, -0.0, 0.06, 0.12, 0.22, 0.34, 0.46, 0.58, 0.7, 0.78};
 Int_t AliAnalysisHadEt::fgNumOfPtBins = 111;
 Float_t AliAnalysisHadEt::fgPtAxis[117]=
   {0.0,0.01,0.02,0.03,0.04, 0.05, 0.06,0.07,0.08,0.09, 0.10,0.11, .12,0.13, .14,0.15, .16,0.17, .18,0.19,
@@ -39,144 +41,72 @@ Float_t AliAnalysisHadEt::fgPtAxis[117]=
   1.25, 1.3,1.35,1.40,1.45, 1.50, 1.55, 1.6,1.65, 1.7, 1.75, 1.8,1.85, 1.9,1.95,
    2.0, 2.2, 2.4, 2.6, 2.8, 3.00, 3.20, 3.4, 3.6, 3.8, 4.00, 4.2, 4.4, 4.6, 4.8,
    5.0, 5.5, 6.0, 6.5, 7.0, 7.50, 8.00, 8.5, 9.0, 9.5, 10.0,12.0,14.0,16.0,18.0,
-  20.0,25.0,30.0,35.0,40.0, 45.0, 50.0}; 
-
-AliAnalysisHadEt::AliAnalysisHadEt() :
-        fHistogramNameSuffix("")
-       ,fCuts(0)
-        ,fPdgDB(0)
-        ,fPiPlusCode(0)
-        ,fPiMinusCode(0)
-        ,fKPlusCode(0)
-        ,fKMinusCode(0)
-        ,fProtonCode(0)
-        ,fAntiProtonCode(0)
-        ,fLambdaCode(0)
-        ,fAntiLambdaCode(0)
-        ,fK0SCode(0)
-        ,fOmegaCode(0)
-        ,fAntiOmegaCode(0)
-        ,fXi0Code(0)
-        ,fAntiXi0Code(0)
-        ,fXiCode(0)
-        ,fAntiXiCode(0)
-        ,fSigmaCode(0)
-        ,fAntiSigmaCode(0)
-        ,fK0LCode(0)
-        ,fNeutronCode(0)
-        ,fAntiNeutronCode(0)
-        ,fEPlusCode(0)
-        ,fEMinusCode(0)
-        ,fPionMass(0)
-       ,fSumEt(0)
-       ,fSumEtAcc(0)
-       ,fTotEt(0)
-       ,fTotEtAcc(0)
-       ,fTotNeutralEt(0)
-       ,fTotNeutralEtAcc(0)
-       ,fTotChargedEt(0)
-       ,fTotChargedEtAcc(0)
-       ,fMultiplicity(0)
-       ,fChargedMultiplicity(0)
-       ,fNeutralMultiplicity(0)
-        ,fEsdtrackCutsITSTPC(0)
-        ,fEsdtrackCutsTPC(0)
-       ,fEsdtrackCutsITS(0)
-        ,fhistoList(0)
+  20.0,25.0,30.0,35.0,40.0, 45.0, 50.0};
+Float_t AliAnalysisHadEt::fgResAxis[81] = {-0.150,-0.140,-0.130,-0.120,-0.110,-0.100,-0.090,-0.080,-0.070,-0.060,
+                                          -0.050,-0.045,-0.040,-0.035,-0.030,-0.025,-0.024,-0.023,-0.022,-0.021,
+                                          -0.020,-0.019,-0.018,-0.017,-0.016,-0.015,-0.014,-0.013,-0.012,-0.011,
+                                          -0.010,-0.009,-0.008,-0.007,-0.006,-0.005,-0.004,-0.003,-0.002,-0.001,
+                                          -0.000,0.001,0.002,0.003,0.004,0.005,0.006,0.007,0.008,0.009,
+                                          0.010,0.011,0.012,0.013,0.014,0.015,0.016,0.017,0.018,0.019,
+                                          0.020,0.021,0.022,0.023,0.024,0.025,0.030,0.035,0.040,0.045,
+                                          0.050,0.060,0.070,0.080,0.090,0.100,0.110,0.120,0.130,0.140,
+                                          0.150,};
+// Float_t AliAnalysisHadEt::fgResAxis[31] = {-0.15,-0.14,-0.13,-0.12,-0.11,-0.1,-0.09,-0.08,-0.07,-0.06,-0.05,-0.04,-0.03,-0.02,-0.01,0.0,0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.1,0.11,0.12,0.13,0.14,0.15};
+Int_t AliAnalysisHadEt::fgNumOfResBins = 80;
+
+
+AliAnalysisHadEt::AliAnalysisHadEt() : AliAnalysisEtCommon()
+                                    ,fSumEt(0)
+                                    ,fSumEtAcc(0)
+                                    ,fTotEt(0)
+                                    ,fTotEtAcc(0)
+                                    ,fTotNeutralEt(0)
+                                    ,fTotNeutralEtAcc(0)
+                                    ,fTotChargedEt(0)
+                                    ,fTotChargedEtAcc(0)
+                                    ,fMultiplicity(0)
+                                    ,fChargedMultiplicity(0)
+                                    ,fNeutralMultiplicity(0)
+                                    ,fhistoList(0)
+                                    ,fGoodEvent(0)
 {//default constructor
 
 }
 
 AliAnalysisHadEt::~AliAnalysisHadEt()
 {//destructor
-
+  delete fEsdtrackCutsITSTPC;
+  delete fEsdtrackCutsITS;
+  delete fEsdtrackCutsTPC;
 }
 
 Int_t AliAnalysisHadEt::AnalyseEvent(AliVEvent *event)
 { //this line is basically here to eliminate a compiler warning that event is not used.  Making it a virtual function did not work with the plugin.
-  cout<<"This event has "<<event->GetNumberOfTracks()<<" tracks"<<endl;
-     ResetEventValues();
-     AliMCEvent *mcEvent = dynamic_cast<AliMCEvent*>(event);
-
-    // Let's play with the stack!
-    AliStack *stack = mcEvent->Stack();
-
-    Int_t nPrim = stack->GetNtrack();
-
-    for (Int_t iPart = 0; iPart < nPrim; iPart++)
-    {
-
-        TParticle *part = stack->Particle(iPart);
-
-        if (!part)
-         {
-            Printf("ERROR: Could not get particle %d", iPart);
-            continue;
-         }
-    }
+  AliAnalysisEtCommon::AnalyseEvent(event);
+  ResetEventValues();
   return 0;
 }
 
-void AliAnalysisHadEt::FillOutputList()
-{//fill the output histogram list with histograms in all AliAnalysisHadEt's
-}
 
 void AliAnalysisHadEt::Init()
-{//Initiate member vaiables to reasonable values
-  if (!fCuts) fCuts = new AliAnalysisEtCuts();
-
-  if(!fPdgDB) fPdgDB = new TDatabasePDG();
-  SetParticleCodes();  
-}
-
-void AliAnalysisHadEt::CreateHistograms()
-{//creates histograms included in all AliAnalysisHadEt's
-}
-
-void AliAnalysisHadEt::FillHistograms()
-{//Fills histograms filled for all AliAnalysisHadEt's
+{// clear variables, set up cuts and PDG info
+  AliAnalysisEtCommon::Init();
 }
 
 void AliAnalysisHadEt::ResetEventValues()
 {//Resets event values of et to zero
-    fTotEt = 0;
-    fTotEtAcc = 0;
-    fTotNeutralEt = 0;
-    fTotNeutralEtAcc = 0;
-    fTotChargedEt  = 0;
-    fTotChargedEtAcc = 0;
-    fMultiplicity = 0;
-    fChargedMultiplicity = 0;
-    fNeutralMultiplicity = 0;
-}
-
-void AliAnalysisHadEt::SetParticleCodes()
-{  //the codes are defined in $ROOTSYS/etc/pdg_table.txt
-  fPionMass = fPdgDB->GetParticle("pi+")->Mass();
-  fPiPlusCode = fPdgDB->GetParticle("pi+")->PdgCode();
-  fPiMinusCode = fPdgDB->GetParticle("pi-")->PdgCode();
-  fKPlusCode = fPdgDB->GetParticle("K+")->PdgCode();
-  fKMinusCode = fPdgDB->GetParticle("K-")->PdgCode();
-  fProtonCode = fPdgDB->GetParticle("proton")->PdgCode();
-  fAntiProtonCode = fPdgDB->GetParticle("antiproton")->PdgCode();
-  fLambdaCode = fPdgDB->GetParticle("Lambda0")->PdgCode();
-  fAntiLambdaCode = fPdgDB->GetParticle("Lambda0_bar")->PdgCode();
-  fK0SCode = fPdgDB->GetParticle("K_S0")->PdgCode();
-  fOmegaCode = fPdgDB->GetParticle("Omega-")->PdgCode();
-  fAntiOmegaCode = fPdgDB->GetParticle("Omega+")->PdgCode();
-  fXi0Code = fPdgDB->GetParticle("Xi0")->PdgCode();
-  fAntiXi0Code = fPdgDB->GetParticle("Xi0_bar")->PdgCode();
-  fXiCode = fPdgDB->GetParticle("Xi-")->PdgCode();
-  fAntiXiCode = fPdgDB->GetParticle("Xi-_bar")->PdgCode();
-  fSigmaCode = fPdgDB->GetParticle("Sigma-")->PdgCode();
-  fAntiSigmaCode = fPdgDB->GetParticle("Sigma+")->PdgCode();
-  fK0LCode = fPdgDB->GetParticle("K_L0")->PdgCode();
-  fNeutronCode = fPdgDB->GetParticle("neutron")->PdgCode();
-  fAntiNeutronCode = fPdgDB->GetParticle("antineutron")->PdgCode();
-  fEPlusCode = fPdgDB->GetParticle("e+")->PdgCode();
-  fEMinusCode = fPdgDB->GetParticle("e-")->PdgCode();
+  AliAnalysisEtCommon::ResetEventValues();
+  fTotEt = 0;
+  fTotEtAcc = 0;
+  fTotNeutralEt = 0;
+  fTotNeutralEtAcc = 0;
+  fTotChargedEt  = 0;
+  fTotChargedEtAcc = 0;
+  fMultiplicity = 0;
+  fChargedMultiplicity = 0;
+  fNeutralMultiplicity = 0;
+  
 }
-
 void AliAnalysisHadEt::CreateEtaPtHisto2D(TString name, TString title)
 {     //creates a 2-d histogram in eta and phi and adds it to the list of histograms to be saved
   TString *histoname   = new TString();
@@ -184,7 +114,6 @@ void AliAnalysisHadEt::CreateEtaPtHisto2D(TString name, TString title)
 
   histoname->Append(name);
   histotitle->Append(title);
-  //TH2F *h1 = new TH2F("h1", "Histogram with Gaussian random distribution", fgNumOfPtBins, ptBinsArray, fgnumOfEtaBins, etaBinsArray);
 
   TH2F *histo = new TH2F(histoname->Data(),histotitle->Data(),fgNumOfPtBins, fgPtAxis, fgnumOfEtaBins, fgEtaAxis);
   histo->SetYTitle("#eta");
@@ -196,17 +125,49 @@ void AliAnalysisHadEt::CreateEtaPtHisto2D(TString name, TString title)
   delete histotitle;
     
 }
+void AliAnalysisHadEt::CreateResolutionPtHisto2D(TString name, TString title, TString xtitle, TString ytitle)
+{     //creates a 2-d histogram in eta and phi and adds it to the list of histograms to be saved
+  TString *histoname   = new TString();
+  TString *histotitle   = new TString();
+
+  histoname->Append(name);
+  histotitle->Append(title);
+
+  //TH2F *histo = new TH2F(histoname->Data(),histotitle->Data(),fgNumOfPtBins, fgPtAxis, fgNumOfResBins, fgResAxis);
+  TH2F *histo = new TH2F(histoname->Data(),histotitle->Data(),fgNumOfPtBins, fgPtAxis, fgNumOfResBins, fgResAxis);
+  histo->SetYTitle(ytitle);
+  histo->SetXTitle(xtitle);
+  histo->SetZTitle("Number of entries");
+  histo->Sumw2();
+  fhistoList->Add(histo);
+  delete histoname;
+  delete histotitle;
+    
+}
+void AliAnalysisHadEt::CreatePtHisto1D(TString name, TString title, TString xtitle, TString ytitle)
+{     //creates a 2-d histogram in eta and phi and adds it to the list of histograms to be saved
+  TString *histoname   = new TString();
+  TString *histotitle   = new TString();
+
+  histoname->Append(name);
+  histotitle->Append(title);
+
+  TH1F *histo = new TH1F(histoname->Data(),histotitle->Data(),fgNumOfPtBins, fgPtAxis);
+  histo->SetYTitle(ytitle);
+  histo->SetXTitle(xtitle);
+  histo->Sumw2();
+  fhistoList->Add(histo);
+  delete histoname;
+  delete histotitle;
+    
+}
 
 void AliAnalysisHadEt::CreateHisto1D(TString name, TString title, TString xtitle, TString ytitle,Int_t xbins, Float_t xlow,Float_t xhigh)
 {     //creates a 1d histogram of the given dimensions and adds it to the list of histograms to be saved
   TString *histoname   = new TString();
   TString *histotitle   = new TString();
-  
-  //cout<<"creating "<<name<<endl;
-
   histoname->Append(name);
   histotitle->Append(title);
-  // printf("%s \n ",histoname->Data());
   TH1F *histo = new TH1F(histoname->Data(),histotitle->Data(),xbins,xlow,xhigh);
   histo->SetYTitle(ytitle);
   histo->SetXTitle(xtitle);
@@ -214,18 +175,13 @@ void AliAnalysisHadEt::CreateHisto1D(TString name, TString title, TString xtitle
   fhistoList->Add(histo);
   delete histoname;
   delete histotitle;
-    
 }
 void AliAnalysisHadEt::CreateIntHisto1D(TString name, TString title, TString xtitle, TString ytitle,Int_t xbins, Int_t xlow,Int_t xhigh)
 {     //creates a 1d integer histogram and adds it to the list of histograms to be saved
   TString *histoname   = new TString();
   TString *histotitle   = new TString();
-  
-  //cout<<"creating "<<name<<endl;
-
   histoname->Append(name);
   histotitle->Append(title);
-  // printf("%s \n ",histoname->Data());
   TH1I *histo = new TH1I(histoname->Data(),histotitle->Data(),xbins,xlow,xhigh);
   histo->SetYTitle(ytitle);
   histo->SetXTitle(xtitle);
@@ -239,12 +195,8 @@ void AliAnalysisHadEt::CreateHisto2D(TString name, TString title, TString xtitle
 {     //creates a 2d histogram and adds it to the list of histograms to be saved
   TString *histoname   = new TString();
   TString *histotitle   = new TString();
-  
-  //cout<<"creating "<<name<<endl;
-
   histoname->Append(name);
   histotitle->Append(title);
-  // printf("%s \n ",histoname->Data());
   TH2F *histo = new TH2F(histoname->Data(),histotitle->Data(),xbins,xlow,xhigh,ybins,ylow,yhigh);
   histo->SetYTitle(ytitle);
   histo->SetXTitle(xtitle);
@@ -258,12 +210,8 @@ void AliAnalysisHadEt::CreateIntHisto2D(TString name, TString title, TString xti
 {     //creates a 2-d integer histogram and adds it to the list of histograms to be saved
   TString *histoname   = new TString();
   TString *histotitle   = new TString();
-  
-  //cout<<"creating "<<name<<endl;
-
   histoname->Append(name);
   histotitle->Append(title);
-  // printf("%s \n ",histoname->Data());
   TH2I *histo = new TH2I(histoname->Data(),histotitle->Data(),xbins,xlow,xhigh,ybins,ylow,yhigh);
   histo->SetYTitle(ytitle);
   histo->SetXTitle(xtitle);
@@ -278,8 +226,6 @@ void AliAnalysisHadEt::CreateEtaHisto1D(TString name, TString title)
 {     //creates 1d histogram in eta and adds it to the list of histograms to be saved
   TString *histoname   = new TString();
   TString *histotitle   = new TString();
-  
-
   histoname->Append(name);
   histotitle->Append(title);
   TH1F *histo = new TH1F(histoname->Data(),histotitle->Data(),fgnumOfEtaBins, fgEtaAxis);
@@ -289,13 +235,11 @@ void AliAnalysisHadEt::CreateEtaHisto1D(TString name, TString title)
   fhistoList->Add(histo);
   delete histoname;
   delete histotitle;
-    
 }
 void AliAnalysisHadEt::FillHisto1D(TString histname, Float_t x, Float_t weight)
 {//fills a 1d histogram with the name histoname with the value x and the weight "weight"
   TH1F     *histo; 
   TString  *name   = new TString();
-
   name->Append(histname);       
   histo = (TH1F *)fhistoList->FindObject(name->Data()); 
   if(histo){
@@ -308,7 +252,6 @@ void AliAnalysisHadEt::FillHisto2D(TString histname, Float_t x, Float_t y, Float
 {//fills a 2d histogram with the name histoname with the value x and the weight "weight"
   TH2F     *histo; 
   TString  *name   = new TString();
-  
   name->Append(histname);       
   histo = (TH2F *)fhistoList->FindObject(name->Data()); 
   if(histo){
@@ -326,7 +269,7 @@ Float_t AliAnalysisHadEt::Et(TParticle *part, float mass){//function to calculat
        //for antinucleons we specifically want to return the kinetic energy plus twice the rest mass
        return (part->Energy()+part->GetMass())*TMath::Sin(part->Theta());
       }
-      if(part->GetPDG(0)->PdgCode()==2212 || part->GetPDG(0)->PdgCode()==2112){//antiproton or antineutron
+      if(part->GetPDG(0)->PdgCode()==2212 || part->GetPDG(0)->PdgCode()==2112){//proton or neutron
        //for nucleons we specifically want to return the kinetic energy only
        return (part->Energy()-part->GetMass())*TMath::Sin(part->Theta());
       }
@@ -340,3 +283,29 @@ Float_t AliAnalysisHadEt::Et(TParticle *part, float mass){//function to calculat
   }
   return 0.0;
 }
+Float_t AliAnalysisHadEt::Et(Float_t p, Float_t theta, Int_t pid, Short_t charge) const {//function to calculate et in the same way as it would be calculated in a calorimeter
+  if(pid==AliAnalysisEtCommon::fgPiPlusCode || pid==AliAnalysisEtCommon::fgPiMinusCode){//Nothing special for pions
+    return TMath::Sqrt(p*p + fgPionMass*fgPionMass) * TMath::Sin(theta);
+  }
+  if(pid==AliAnalysisEtCommon::fgKPlusCode || pid==AliAnalysisEtCommon::fgKMinusCode){//Nothing special for kaons
+    return TMath::Sqrt(p*p + AliAnalysisEtCommon::fgKaonMass*AliAnalysisEtCommon::fgKaonMass) * TMath::Sin(theta);
+  }
+  if(pid==AliAnalysisEtCommon::fgEPlusCode || pid==AliAnalysisEtCommon::fgEMinusCode){//Nothing special for electrons
+    return TMath::Sqrt(p*p + AliAnalysisEtCommon::fgElectronMass*AliAnalysisEtCommon::fgElectronMass) * TMath::Sin(theta);
+  }
+  if(pid==AliAnalysisEtCommon::fgProtonCode || pid==AliAnalysisEtCommon::fgAntiProtonCode){//But for protons we must be careful...
+    if(charge<0.0){//antiprotns: kinetic energy plus twice the rest mass
+      return (TMath::Sqrt(p*p + AliAnalysisEtCommon::fgProtonMass*AliAnalysisEtCommon::fgProtonMass) + AliAnalysisEtCommon::fgProtonMass) * TMath::Sin(theta);
+    }
+    if(charge>0.0){//antiprotns: kinetic energy only
+      return (TMath::Sqrt(p*p + AliAnalysisEtCommon::fgProtonMass*AliAnalysisEtCommon::fgProtonMass) - AliAnalysisEtCommon::fgProtonMass) * TMath::Sin(theta);
+    }
+  }
+  //cerr<<"Uh-oh!  Et not set properly!"<<endl;
+  return 0.0;
+}
+
+Float_t AliAnalysisHadEt::TrueP(float pTrec) const {
+  if(pTrec>1.0) return pTrec;
+  return pTrec/(1-599.334*pTrec+7285.15*pTrec*pTrec)+pTrec;
+}