]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/FLOW/AliFlowCommon/AliFlowAnalysisWithScalarProduct.cxx
restore event cuts and change couts and printf's to alilog
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowCommon / AliFlowAnalysisWithScalarProduct.cxx
index 55037eaeb9592e81293c925ab50d42edbbd4825a..f76ae26345ed941bbefa2ee308e440f072231ba0 100644 (file)
 
 #define AliFlowAnalysisWithScalarProduct_cxx
  
-#include "Riostream.h"  //needed as include
-#include "TFile.h"      //needed as include
+#include "Riostream.h"
+#include "TFile.h"      
 #include "TList.h"
 #include "TMath.h"
 #include "TProfile.h"
 #include "TVector2.h"
+#include "TH1D.h"
+#include "TH2D.h"
 
-class TH1F;
-
-#include "AliFlowCommonConstants.h"    //needed as include
+#include "AliFlowCommonConstants.h"
 #include "AliFlowEventSimple.h"
 #include "AliFlowTrackSimple.h"
 #include "AliFlowCommonHist.h"
 #include "AliFlowCommonHistResults.h"
 #include "AliFlowAnalysisWithScalarProduct.h"
-
-class AliFlowVector;
+#include "AliFlowVector.h"
 
 //////////////////////////////////////////////////////////////////////////////
 // AliFlowAnalysisWithScalarProduct:
@@ -47,6 +46,7 @@ ClassImp(AliFlowAnalysisWithScalarProduct)
   AliFlowAnalysisWithScalarProduct::AliFlowAnalysisWithScalarProduct():
    fEventNumber(0),
    fDebug(kFALSE),
+   fRelDiffMsub(1.),
    fWeightsList(NULL),
    fUsePhiWeights(kFALSE),
    fPhiWeights(NULL),
@@ -56,6 +56,7 @@ ClassImp(AliFlowAnalysisWithScalarProduct)
    fHistProUQPtRP(NULL),
    fHistProUQPtPOI(NULL),
    fHistProQaQb(NULL),
+   fHistProQaQbNorm(NULL),
    fHistSumOfLinearWeights(NULL),
    fHistSumOfQuadraticWeights(NULL),
    fHistProUQQaQbPtRP(NULL),
@@ -63,7 +64,17 @@ ClassImp(AliFlowAnalysisWithScalarProduct)
    fHistProUQQaQbPtPOI(NULL),
    fHistProUQQaQbEtaPOI(NULL),
    fCommonHists(NULL),
-   fCommonHistsRes(NULL)
+   fCommonHistsRes(NULL),
+   fHistQaQb(NULL),
+   fHistQaQbNorm(NULL),
+   fHistQaQbCos(NULL),
+   fHistResolution(NULL),
+   fHistQaNorm(NULL),
+   fHistQaNormvsMa(NULL),
+   fHistQbNorm(NULL),
+   fHistQbNormvsMb(NULL),
+   fHistMavsMb(NULL)
+
 {
   // Constructor.
   fWeightsList = new TList();
@@ -128,6 +139,12 @@ void AliFlowAnalysisWithScalarProduct::Init() {
   //Define all histograms
   cout<<"---Analysis with the Scalar Product Method--- Init"<<endl;
 
+  //save old value and prevent histograms from being added to directory
+  //to avoid name clashes in case multiple analaysis objects are used
+  //in an analysis
+  Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
+  TH1::AddDirectory(kFALSE);
   Int_t iNbinsPt   = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
   Double_t dPtMin  = AliFlowCommonConstants::GetMaster()->GetPtMin();       
   Double_t dPtMax  = AliFlowCommonConstants::GetMaster()->GetPtMax();
@@ -159,6 +176,10 @@ void AliFlowAnalysisWithScalarProduct::Init() {
   fHistProQaQb->SetYTitle("<QaQb>");
   fHistList->Add(fHistProQaQb);
 
+  fHistProQaQbNorm = new TProfile("FlowPro_QaQbNorm_SP","FlowPro_QaQbNorm_SP", 1, 0.5, 1.5,"s");
+  fHistProQaQbNorm->SetYTitle("<QaQb/MaMb>");
+  fHistList->Add(fHistProQaQbNorm);
+
   fHistSumOfLinearWeights = new TH1D("Flow_SumOfLinearWeights_SP","Flow_SumOfLinearWeights_SP",1,-0.5, 0.5);
   fHistSumOfLinearWeights -> SetYTitle("sum (*)");
   fHistSumOfLinearWeights -> SetXTitle("sum (Ma*Mb)");
@@ -192,26 +213,26 @@ void AliFlowAnalysisWithScalarProduct::Init() {
   TString weightFlag[3] = {"w_Qu_","w_Qu^2_","w_QuQaQb_"}; 
   for(Int_t i=0;i<3;i++)
   {
-   fHistSumOfWeightsPtRP[i] = new TH1D(Form("Flow_SumOfWeights%dPtRP_SP",weightFlag[i].Data()),
-                              Form("Flow_SumOfWeights%dPtRP_SP",weightFlag[i].Data()),iNbinsPt,dPtMin,dPtMax);
+   fHistSumOfWeightsPtRP[i] = new TH1D(Form("Flow_SumOfWeights%sPtRP_SP",weightFlag[i].Data()),
+                              Form("Flow_SumOfWeights%sPtRP_SP",weightFlag[i].Data()),iNbinsPt,dPtMin,dPtMax);
    fHistSumOfWeightsPtRP[i] -> SetYTitle("sum (*)");
    fHistSumOfWeightsPtRP[i] -> SetXTitle("p_{T}");
    fHistList->Add(fHistSumOfWeightsPtRP[i]);
  
-   fHistSumOfWeightsEtaRP[i] = new TH1D(Form("Flow_SumOfWeights%dEtaRP_SP",weightFlag[i].Data()),
-                               Form("Flow_SumOfWeights%dEtaRP_SP",weightFlag[i].Data()),iNbinsEta,dEtaMin,dEtaMax);
+   fHistSumOfWeightsEtaRP[i] = new TH1D(Form("Flow_SumOfWeights%sEtaRP_SP",weightFlag[i].Data()),
+                               Form("Flow_SumOfWeights%sEtaRP_SP",weightFlag[i].Data()),iNbinsEta,dEtaMin,dEtaMax);
    fHistSumOfWeightsEtaRP[i] -> SetYTitle("sum (*)");
    fHistSumOfWeightsEtaRP[i] -> SetXTitle("#eta");
    fHistList->Add(fHistSumOfWeightsEtaRP[i]);
   
-   fHistSumOfWeightsPtPOI[i] = new TH1D(Form("Flow_SumOfWeights%dPtPOI_SP",weightFlag[i].Data()),
-                               Form("Flow_SumOfWeights%dPtPOI_SP",weightFlag[i].Data()),iNbinsPt,dPtMin,dPtMax);
+   fHistSumOfWeightsPtPOI[i] = new TH1D(Form("Flow_SumOfWeights%sPtPOI_SP",weightFlag[i].Data()),
+                               Form("Flow_SumOfWeights%sPtPOI_SP",weightFlag[i].Data()),iNbinsPt,dPtMin,dPtMax);
    fHistSumOfWeightsPtPOI[i] -> SetYTitle("sum (*)");
    fHistSumOfWeightsPtPOI[i] -> SetXTitle("p_{T}");
    fHistList->Add(fHistSumOfWeightsPtPOI[i]);
  
-   fHistSumOfWeightsEtaPOI[i] = new TH1D(Form("Flow_SumOfWeights%dEtaPOI_SP",weightFlag[i].Data()),
-                                Form("Flow_SumOfWeights%dEtaPOI_SP",weightFlag[i].Data()),iNbinsEta,dEtaMin,dEtaMax);
+   fHistSumOfWeightsEtaPOI[i] = new TH1D(Form("Flow_SumOfWeights%sEtaPOI_SP",weightFlag[i].Data()),
+                                Form("Flow_SumOfWeights%sEtaPOI_SP",weightFlag[i].Data()),iNbinsEta,dEtaMin,dEtaMax);
    fHistSumOfWeightsEtaPOI[i] -> SetYTitle("sum (*)");
    fHistSumOfWeightsEtaPOI[i] -> SetXTitle("#eta");
    fHistList->Add(fHistSumOfWeightsEtaPOI[i]);
@@ -222,6 +243,52 @@ void AliFlowAnalysisWithScalarProduct::Init() {
   fCommonHistsRes = new AliFlowCommonHistResults("AliFlowCommonHistResultsSP");
   fHistList->Add(fCommonHistsRes);  
 
+  fHistQaQb = new TH1D("Flow_QaQb_SP","Flow_QaQb_SP",200,-100.,100.);
+  fHistQaQb -> SetYTitle("dN/dQaQb");
+  fHistQaQb -> SetXTitle("QaQb");
+  fHistList->Add(fHistQaQb);
+
+  fHistQaQbNorm = new TH1D("Flow_QaQbNorm_SP","Flow_QaQbNorm_SP",44,-1.1,1.1);
+  fHistQaQbNorm -> SetYTitle("dN/d(QaQb/MaMb)");
+  fHistQaQbNorm -> SetXTitle("QaQb/MaMb");
+  fHistList->Add(fHistQaQbNorm);
+
+  fHistQaQbCos = new TH1D("Flow_QaQbCos_SP","Flow_QaQbCos_SP",63,0.,TMath::Pi());
+  fHistQaQbCos -> SetYTitle("dN/d(#phi)");
+  fHistQaQbCos -> SetXTitle("#phi");
+  fHistList->Add(fHistQaQbCos);
+
+  fHistResolution = new TH1D("Flow_resolution_SP","Flow_resolution_SP",100,-1.0,1.0);
+  fHistResolution -> SetYTitle("dN/d(cos(2(#phi_a - #phi_b))");
+  fHistResolution -> SetXTitle("cos(2*(#phi_a - #phi_b))");
+  fHistList->Add(fHistResolution);
+
+  fHistQaNorm = new TH1D("Flow_QaNorm_SP","Flow_QaNorm_SP",22,0.,1.1);
+  fHistQaNorm -> SetYTitle("dN/d(|Qa/Ma|)");
+  fHistQaNorm -> SetXTitle("|Qa/Ma|");
+  fHistList->Add(fHistQaNorm);
+
+  fHistQaNormvsMa = new TH2D("Flow_QaNormvsMa_SP","Flow_QaNormvsMa_SP",100,0.,100.,22,0.,1.1);
+  fHistQaNormvsMa -> SetYTitle("|Qa/Ma|");
+  fHistQaNormvsMa -> SetXTitle("Ma");
+  fHistList->Add(fHistQaNormvsMa);
+
+  fHistQbNorm = new TH1D("Flow_QbNorm_SP","Flow_QbNorm_SP",22,0.,1.1);
+  fHistQbNorm -> SetYTitle("dN/d(|Qb/Mb|)");
+  fHistQbNorm -> SetXTitle("|Qb/Mb|");
+  fHistList->Add(fHistQbNorm);
+
+  fHistQbNormvsMb = new TH2D("Flow_QbNormvsMb_SP","Flow_QbNormvsMb_SP",100,0.,100.,22,0.,1.1);
+  fHistQbNormvsMb -> SetYTitle("|Qb/Mb|");
+  fHistQbNormvsMb -> SetXTitle("|Mb|");
+  fHistList->Add(fHistQbNormvsMb);
+
+  fHistMavsMb = new TH2D("Flow_MavsMb_SP","Flow_MavsMb_SP",100,0.,100.,100,0.,100.);
+  fHistMavsMb -> SetYTitle("Ma");
+  fHistMavsMb -> SetXTitle("Mb");
+  fHistList->Add(fHistMavsMb);
+
+
   //weights
   if(fUsePhiWeights) {
     if(!fWeightsList) {
@@ -238,19 +305,18 @@ void AliFlowAnalysisWithScalarProduct::Init() {
   } // end of if(fUsePhiWeights)
 
   fEventNumber = 0;  //set number of events to zero    
+
+  TH1::AddDirectory(oldHistAddStatus);
 }
 
 //-----------------------------------------------------------------------
 void AliFlowAnalysisWithScalarProduct::Make(AliFlowEventSimple* anEvent) {
 
-  //Calculate flow based on  <QaQb/MaMb> = <v^2>\r
+  //Calculate flow based on  <QaQb/MaMb> = <v^2>
 
   //Fill histograms
   if (anEvent) {
 
-    //fill control histograms     
-    fCommonHists->FillControlHistograms(anEvent);
-        
     //get Q vectors for the eta-subevents
     AliFlowVector* vQarray = new AliFlowVector[2];
     if (fUsePhiWeights) {
@@ -263,161 +329,179 @@ void AliFlowAnalysisWithScalarProduct::Make(AliFlowEventSimple* anEvent) {
     //subevent b
     AliFlowVector vQb = vQarray[1];
 
-    //get total Q vector = the sum of subevent a and subevent b
-    AliFlowVector vQ = vQa + vQb;
-    //weight the Q vectors for the subevents by the multiplicity
-    //Note: Weight Q only in the particle loop when it is clear if it should be (m-1) or M
-    Double_t dQXa = 0;
-    Double_t dQYa = 0;
+    //check that the subevents are not empty:
     Double_t dMa = vQa.GetMult();
-    if (dMa != 0) {
-    dQXa = vQa.X()/dMa; 
-    dQYa = vQa.Y()/dMa;
-    } else {cout<<"empty subevent"<<endl; }
-    vQa.Set(dQXa,dQYa);
-        
-    Double_t dQXb = 0;
-    Double_t dQYb = 0;
     Double_t dMb = vQb.GetMult();
-    if (dMb != 0) {
-    dQXb = vQb.X()/dMb; 
-    dQYb = vQb.Y()/dMb;
-    } else {cout<<"empty subevent"<<endl; }
-    vQb.Set(dQXb,dQYb);
-    
-        
-    //scalar product of the two subevents
-    Double_t dQaQb = (vQa*vQb);
-    fHistProQaQb -> Fill(1.,dQaQb,dMa*dMb);  //Fill (QaQb/MaMb) with weight (MaMb). 
-    //needed for the error calculation:
-    fHistSumOfLinearWeights -> Fill(0.,dMa*dMb);
-    fHistSumOfQuadraticWeights -> Fill(0.,pow(dMa*dMb,2.));
-
-
-    //loop over the tracks of the event
-    AliFlowTrackSimple*   pTrack = NULL; 
-    Int_t iNumberOfTracks = anEvent->NumberOfTracks(); 
-    Double_t dMq =  vQ.GetMult();
+    if (dMa != 0 && dMb != 0) {
+      
+
+      //request that the subevent multiplicities are not too different
+      Double_t dRelDiff = TMath::Abs((dMa - dMb)/(dMa + dMb));
+      if (dRelDiff < fRelDiffMsub) {
+
+       //fill control histograms     
+       fCommonHists->FillControlHistograms(anEvent);
+
+       //fill some SP control histograms
+       fHistProQaQb -> Fill(1.,vQa*vQb,1.); //Fill with weight 1 -> Weight with MaMb????
+       fHistQaQbCos ->Fill(0.5*TMath::ACos((vQa/vQa.Mod())*(vQb/vQb.Mod())));  //Acos(Qa*Qb) = 2*phi
+       fHistResolution -> Fill(TMath::Cos( vQa.Phi()- vQb.Phi() ));  //vQa.Phi() returns 2*phi
+       fHistQaQb -> Fill(vQa*vQb);
+       fHistMavsMb -> Fill(dMb,dMa);
+
+       //get total Q vector = the sum of subevent a and subevent b
+       AliFlowVector vQ = vQa + vQb;
+       //weight the Q vectors for the subevents by the multiplicity
+       //Note: Weight Q only in the particle loop when it is clear if it should be (m-1) or M
+       Double_t dQXa = vQa.X()/dMa; 
+       Double_t dQYa = vQa.Y()/dMa;
+       vQa.Set(dQXa,dQYa);
+       
+       Double_t dQXb = vQb.X()/dMb; 
+       Double_t dQYb = vQb.Y()/dMb;
+       vQb.Set(dQXb,dQYb);
         
-    for (Int_t i=0;i<iNumberOfTracks;i++) 
-      {
-       pTrack = anEvent->GetTrack(i) ; 
-       if (pTrack){
-         Double_t dPhi = pTrack->Phi();
-         //set default phi weight to 1
-         Double_t dW = 1.; 
-         //phi weight of pTrack
-         if(fUsePhiWeights && fPhiWeights) {
-           Int_t iNBinsPhi = fPhiWeights->GetNbinsX();
-           dW = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*iNBinsPhi/TMath::TwoPi())));  
-           //bin = 1 + value*nbins/range
-           //TMath::Floor rounds to the lower integer
-         }     
-
-         //calculate vU
-         TVector2 vU;
-         Double_t dUX = TMath::Cos(2*dPhi);
-         Double_t dUY = TMath::Sin(2*dPhi);
-         vU.Set(dUX,dUY);
-         Double_t dModulus = vU.Mod();
-         if (dModulus!=0.) vU.Set(dUX/dModulus,dUY/dModulus);  // make length 1
-         else cerr<<"dModulus is zero!"<<endl;
-
-         //redefine the Q vector and devide by its multiplicity
-         TVector2 vQm;
-         Double_t dQmX = 0.;
-         Double_t dQmY = 0.;
-         //subtract particle from the flowvector if used to define it
-         if (pTrack->InSubevent(0) || pTrack->InSubevent(1)) { 
-           dQmX = (vQ.X() - dW*dUX)/(dMq-1);
-           dQmY = (vQ.Y() - dW*dUY)/(dMq-1);
-           
-           vQm.Set(dQmX,dQmY);
-                   
-           //dUQ = scalar product of vU and vQm
-           Double_t dUQ = (vU * vQm);
-           Double_t dPt = pTrack->Pt();
-           Double_t dEta = pTrack->Eta();
-           //fill the profile histograms
-           if (pTrack->InRPSelection()) {
-             fHistProUQetaRP -> Fill(dEta,dUQ,(dMq-1)); //Fill (Qu/(Mq-1)) with weight (Mq-1) 
-             //needed for the error calculation:
-             fHistProUQQaQbEtaRP -> Fill(dEta,dUQ*dQaQb,(dMq-1)*dMa*dMb); //Fill [Qu/(Mq-1)]*[QaQb/MaMb] with weight (Mq-1)MaMb            
-             fHistProUQPtRP -> Fill(dPt,dUQ,(dMq-1));                     //Fill (Qu/(Mq-1)) with weight (Mq-1)
-             fHistProUQQaQbPtRP -> Fill(dPt,dUQ*dQaQb,(dMq-1)*dMa*dMb);   //Fill [Qu/(Mq-1)]*[QaQb/MaMb] with weight (Mq-1)MaMb        
-         
-             fHistSumOfWeightsEtaRP[0]->Fill(dEta,(dMq-1));        // sum of Mq-1     
-             fHistSumOfWeightsEtaRP[1]->Fill(dEta,pow((dMq-1),2.));// sum of (Mq-1)^2     
-             fHistSumOfWeightsEtaRP[2]->Fill(dEta,(dMq-1)*dMa*dMb);// sum of (Mq-1)*MaMb     
-             fHistSumOfWeightsPtRP[0]->Fill(dPt,(dMq-1));          // sum of Mq-1     
-             fHistSumOfWeightsPtRP[1]->Fill(dPt,pow((dMq-1),2.));  // sum of (Mq-1)^2     
-             fHistSumOfWeightsPtRP[2]->Fill(dPt,(dMq-1)*dMa*dMb);  // sum of (Mq-1)*MaMb     
-           }
-           if (pTrack->InPOISelection()) {
-             fHistProUQetaPOI -> Fill(dEta,dUQ,(dMq-1));//Fill (Qu/(Mq-1)) with weight (Mq-1)
-             //needed for the error calculation:
-             fHistProUQQaQbEtaPOI -> Fill(dEta,dUQ*dQaQb,(dMq-1)*dMa*dMb); //Fill [Qu/(Mq-1)]*[QaQb/MaMb] with weight (Mq-1)MaMb           
-             fHistProUQPtPOI -> Fill(dPt,dUQ,(dMq-1));                     //Fill (Qu/(Mq-1)) with weight (Mq-1)
-             fHistProUQQaQbPtPOI -> Fill(dPt,dUQ*dQaQb,(dMq-1)*dMa*dMb);   //Fill [Qu/(Mq-1)]*[QaQb/MaMb] with weight (Mq-1)MaMb           
-         
-             fHistSumOfWeightsEtaPOI[0]->Fill(dEta,(dMq-1));        // sum of Mq-1     
-             fHistSumOfWeightsEtaPOI[1]->Fill(dEta,pow((dMq-1),2.));// sum of (Mq-1)^2     
-             fHistSumOfWeightsEtaPOI[2]->Fill(dEta,(dMq-1)*dMa*dMb);// sum of (Mq-1)*MaMb     
-             fHistSumOfWeightsPtPOI[0]->Fill(dPt,(dMq-1));          // sum of Mq-1     
-             fHistSumOfWeightsPtPOI[1]->Fill(dPt,pow((dMq-1),2.)); // sum of (Mq-1)^2     
-             fHistSumOfWeightsPtPOI[2]->Fill(dPt,(dMq-1)*dMa*dMb); // sum of (Mq-1)*MaMb     
-           }  
-           
-         } else { //do not subtract the particle from the flowvector
-           dQmX = vQ.X()/dMq;
-           dQmY = vQ.Y()/dMq;
+       //scalar product of the two subevents
+       Double_t dQaQb = (vQa*vQb);
+       fHistProQaQbNorm -> Fill(1.,dQaQb,dMa*dMb);  //Fill (QaQb/MaMb) with weight (MaMb). 
+       //needed for the error calculation:
+       fHistSumOfLinearWeights -> Fill(0.,dMa*dMb);
+       fHistSumOfQuadraticWeights -> Fill(0.,pow(dMa*dMb,2.));
+
+       //fill some SP control histograms
+       fHistQaQbNorm ->Fill(vQa*vQb);
+       fHistQaNorm ->Fill(vQa.Mod());
+       fHistQaNormvsMa->Fill(dMa,vQa.Mod());
+       fHistQbNorm ->Fill(vQb.Mod());
+       fHistQbNormvsMb->Fill(dMb,vQb.Mod());
+       
+       //loop over the tracks of the event
+       AliFlowTrackSimple*   pTrack = NULL; 
+       Int_t iNumberOfTracks = anEvent->NumberOfTracks(); 
+       Double_t dMq =  vQ.GetMult();
+      
+       for (Int_t i=0;i<iNumberOfTracks;i++) 
+         {
+           pTrack = anEvent->GetTrack(i) ; 
+           if (pTrack){
+             Double_t dPhi = pTrack->Phi();
+             //set default phi weight to 1
+             Double_t dW = 1.; 
+             //phi weight of pTrack
+             if(fUsePhiWeights && fPhiWeights) {
+               Int_t iNBinsPhi = fPhiWeights->GetNbinsX();
+               dW = fPhiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*iNBinsPhi/TMath::TwoPi())));  
+               //bin = 1 + value*nbins/range
+               //TMath::Floor rounds to the lower integer
+             }     
            
-           vQm.Set(dQmX,dQmY);
+             //calculate vU
+             TVector2 vU;
+             Double_t dUX = TMath::Cos(2*dPhi);
+             Double_t dUY = TMath::Sin(2*dPhi);
+             vU.Set(dUX,dUY);
+             Double_t dModulus = vU.Mod();
+             if (dModulus!=0.) vU.Set(dUX/dModulus,dUY/dModulus);  // make length 1
+             else cerr<<"dModulus is zero!"<<endl;
            
-           //dUQ = scalar product of vU and vQm
-           Double_t dUQ = (vU * vQm);
-           Double_t dPt = pTrack->Pt();
-           Double_t dEta = pTrack->Eta();
-           //fill the profile histograms
-           if (pTrack->InRPSelection()) {
-             fHistProUQetaRP -> Fill(dEta,dUQ,dMq);                   //Fill (Qu/Mq) with weight Mq 
-             //needed for the error calculation:
-             fHistProUQQaQbEtaRP -> Fill(dEta,dUQ*dQaQb,dMq*dMa*dMb); //Fill [Qu/Mq]*[QaQb/MaMb] with weight Mq*MaMb       
-             fHistProUQPtRP -> Fill(dPt,dUQ,dMq);                     //Fill (Qu/Mq) with weight Mq 
-             fHistProUQQaQbPtRP -> Fill(dPt,dUQ*dQaQb,dMq*dMa*dMb);   //Fill [Qu/Mq]*[QaQb/MaMb] with weight Mq*MaMb       
-         
-             fHistSumOfWeightsEtaRP[0]->Fill(dEta,dMq);        // sum of Mq     
-             fHistSumOfWeightsEtaRP[1]->Fill(dEta,pow(dMq,2.));// sum of Mq^2     
-             fHistSumOfWeightsEtaRP[2]->Fill(dEta,dMq*dMa*dMb);// sum of Mq*MaMb     
-             fHistSumOfWeightsPtRP[0]->Fill(dPt,dMq);          // sum of Mq     
-             fHistSumOfWeightsPtRP[1]->Fill(dPt,pow(dMq,2.));  // sum of Mq^2     
-             fHistSumOfWeightsPtRP[2]->Fill(dPt,dMq*dMa*dMb);  // sum of Mq*MaMb     
-           }
-           if (pTrack->InPOISelection()) {
-             fHistProUQetaPOI -> Fill(dEta,dUQ,dMq); //Fill (Qu/Mq) with weight Mq 
-             //needed for the error calculation:
-             fHistProUQQaQbEtaPOI -> Fill(dEta,dUQ*dQaQb,dMq*dMa*dMb); //Fill [Qu/Mq]*[QaQb/MaMb] with weight Mq*MaMb      
-             fHistProUQPtPOI -> Fill(dPt,dUQ,dMq);                     //Fill (Qu/Mq) with weight Mq 
-             fHistProUQQaQbPtPOI -> Fill(dPt,dUQ*dQaQb,dMq*dMa*dMb);   //Fill [Qu/Mq]*[QaQb/MaMb] with weight Mq*MaMb      
+             //redefine the Q vector and devide by its multiplicity
+             TVector2 vQm;
+             Double_t dQmX = 0.;
+             Double_t dQmY = 0.;
+             //subtract particle from the flowvector if used to define it
+             if (pTrack->InSubevent(0) || pTrack->InSubevent(1)) { 
+               dQmX = (vQ.X() - dW*dUX)/(dMq-1);
+               dQmY = (vQ.Y() - dW*dUY)/(dMq-1);
+               vQm.Set(dQmX,dQmY);
              
-             fHistSumOfWeightsEtaPOI[0]->Fill(dEta,dMq);        // sum of Mq     
-             fHistSumOfWeightsEtaPOI[1]->Fill(dEta,pow(dMq,2.));// sum of Mq^2     
-             fHistSumOfWeightsEtaPOI[2]->Fill(dEta,dMq*dMa*dMb);// sum of Mq*MaMb     
-             fHistSumOfWeightsPtPOI[0]->Fill(dPt,dMq);          // sum of Mq     
-             fHistSumOfWeightsPtPOI[1]->Fill(dPt,pow(dMq,2.));  // sum of Mq^2     
-             fHistSumOfWeightsPtPOI[2]->Fill(dPt,dMq*dMa*dMb);  // sum of Mq*MaMb     
-           }  
-         }//track not in subevents
-         
-       }//track
-
-      }//loop over tracks
-    
-    fEventNumber++;
-    //    cout<<"@@@@@ "<<fEventNumber<<" events processed"<<endl;
+               //dUQ = scalar product of vU and vQm
+               Double_t dUQ = (vU * vQm);
+               Double_t dPt = pTrack->Pt();
+               Double_t dEta = pTrack->Eta();
+               //fill the profile histograms
+               if (pTrack->InRPSelection()) {
+                 fHistProUQetaRP -> Fill(dEta,dUQ,(dMq-1)); //Fill (Qu/(Mq-1)) with weight (Mq-1) 
+                 //needed for the error calculation:
+                 fHistProUQQaQbEtaRP -> Fill(dEta,dUQ*dQaQb,(dMq-1)*dMa*dMb); //Fill [Qu/(Mq-1)]*[QaQb/MaMb] with weight (Mq-1)MaMb        
+                 fHistProUQPtRP -> Fill(dPt,dUQ,(dMq-1));                     //Fill (Qu/(Mq-1)) with weight (Mq-1)
+                 fHistProUQQaQbPtRP -> Fill(dPt,dUQ*dQaQb,(dMq-1)*dMa*dMb);   //Fill [Qu/(Mq-1)]*[QaQb/MaMb] with weight (Mq-1)MaMb    
+                 
+                 fHistSumOfWeightsEtaRP[0]->Fill(dEta,(dMq-1));        // sum of Mq-1     
+                 fHistSumOfWeightsEtaRP[1]->Fill(dEta,pow((dMq-1),2.));// sum of (Mq-1)^2     
+                 fHistSumOfWeightsEtaRP[2]->Fill(dEta,(dMq-1)*dMa*dMb);// sum of (Mq-1)*MaMb     
+                 fHistSumOfWeightsPtRP[0]->Fill(dPt,(dMq-1));          // sum of Mq-1     
+                 fHistSumOfWeightsPtRP[1]->Fill(dPt,pow((dMq-1),2.));  // sum of (Mq-1)^2     
+                 fHistSumOfWeightsPtRP[2]->Fill(dPt,(dMq-1)*dMa*dMb);  // sum of (Mq-1)*MaMb     
+               }
+               if (pTrack->InPOISelection()) {
+                 fHistProUQetaPOI -> Fill(dEta,dUQ,(dMq-1));//Fill (Qu/(Mq-1)) with weight (Mq-1)
+                 //needed for the error calculation:
+                 fHistProUQQaQbEtaPOI -> Fill(dEta,dUQ*dQaQb,(dMq-1)*dMa*dMb); //Fill [Qu/(Mq-1)]*[QaQb/MaMb] with weight (Mq-1)MaMb       
+                 fHistProUQPtPOI -> Fill(dPt,dUQ,(dMq-1));                     //Fill (Qu/(Mq-1)) with weight (Mq-1)
+                 fHistProUQQaQbPtPOI -> Fill(dPt,dUQ*dQaQb,(dMq-1)*dMa*dMb);   //Fill [Qu/(Mq-1)]*[QaQb/MaMb] with weight (Mq-1)MaMb       
+                 
+                 fHistSumOfWeightsEtaPOI[0]->Fill(dEta,(dMq-1));        // sum of Mq-1     
+                 fHistSumOfWeightsEtaPOI[1]->Fill(dEta,pow((dMq-1),2.));// sum of (Mq-1)^2     
+                 fHistSumOfWeightsEtaPOI[2]->Fill(dEta,(dMq-1)*dMa*dMb);// sum of (Mq-1)*MaMb     
+                 fHistSumOfWeightsPtPOI[0]->Fill(dPt,(dMq-1));          // sum of Mq-1     
+                 fHistSumOfWeightsPtPOI[1]->Fill(dPt,pow((dMq-1),2.)); // sum of (Mq-1)^2     
+                 fHistSumOfWeightsPtPOI[2]->Fill(dPt,(dMq-1)*dMa*dMb); // sum of (Mq-1)*MaMb     
+               }  
+               
+             } else { //do not subtract the particle from the flowvector
+               dQmX = vQ.X()/dMq;
+               dQmY = vQ.Y()/dMq;
+               vQm.Set(dQmX,dQmY);
+             
+               //dUQ = scalar product of vU and vQm
+               Double_t dUQ = (vU * vQm);
+               Double_t dPt = pTrack->Pt();
+               Double_t dEta = pTrack->Eta();
+               //fill the profile histograms
+               if (pTrack->InRPSelection()) {
+                 fHistProUQetaRP -> Fill(dEta,dUQ,dMq);                   //Fill (Qu/Mq) with weight Mq 
+                 //needed for the error calculation:
+                 fHistProUQQaQbEtaRP -> Fill(dEta,dUQ*dQaQb,dMq*dMa*dMb); //Fill [Qu/Mq]*[QaQb/MaMb] with weight Mq*MaMb           
+                 fHistProUQPtRP -> Fill(dPt,dUQ,dMq);                     //Fill (Qu/Mq) with weight Mq 
+                 fHistProUQQaQbPtRP -> Fill(dPt,dUQ*dQaQb,dMq*dMa*dMb);   //Fill [Qu/Mq]*[QaQb/MaMb] with weight Mq*MaMb           
+                 
+                 fHistSumOfWeightsEtaRP[0]->Fill(dEta,dMq);        // sum of Mq     
+                 fHistSumOfWeightsEtaRP[1]->Fill(dEta,pow(dMq,2.));// sum of Mq^2     
+                 fHistSumOfWeightsEtaRP[2]->Fill(dEta,dMq*dMa*dMb);// sum of Mq*MaMb     
+                 fHistSumOfWeightsPtRP[0]->Fill(dPt,dMq);          // sum of Mq     
+                 fHistSumOfWeightsPtRP[1]->Fill(dPt,pow(dMq,2.));  // sum of Mq^2     
+                 fHistSumOfWeightsPtRP[2]->Fill(dPt,dMq*dMa*dMb);  // sum of Mq*MaMb     
+               }
+               if (pTrack->InPOISelection()) {
+                 fHistProUQetaPOI -> Fill(dEta,dUQ,dMq); //Fill (Qu/Mq) with weight Mq 
+                 //needed for the error calculation:
+                 fHistProUQQaQbEtaPOI -> Fill(dEta,dUQ*dQaQb,dMq*dMa*dMb); //Fill [Qu/Mq]*[QaQb/MaMb] with weight Mq*MaMb          
+                 fHistProUQPtPOI -> Fill(dPt,dUQ,dMq);                     //Fill (Qu/Mq) with weight Mq 
+                 fHistProUQQaQbPtPOI -> Fill(dPt,dUQ*dQaQb,dMq*dMa*dMb);   //Fill [Qu/Mq]*[QaQb/MaMb] with weight Mq*MaMb          
+                 
+                 fHistSumOfWeightsEtaPOI[0]->Fill(dEta,dMq);        // sum of Mq     
+                 fHistSumOfWeightsEtaPOI[1]->Fill(dEta,pow(dMq,2.));// sum of Mq^2     
+                 fHistSumOfWeightsEtaPOI[2]->Fill(dEta,dMq*dMa*dMb);// sum of Mq*MaMb     
+                 fHistSumOfWeightsPtPOI[0]->Fill(dPt,dMq);          // sum of Mq     
+                 fHistSumOfWeightsPtPOI[1]->Fill(dPt,pow(dMq,2.));  // sum of Mq^2     
+                 fHistSumOfWeightsPtPOI[2]->Fill(dPt,dMq*dMa*dMb);  // sum of Mq*MaMb     
+               }  
+             }//track not in subevents
+             
+           }//track
+           
+         }//loop over tracks
+       
+       fEventNumber++;
+
+      } //difference Ma and Mb
+
+    }// subevents not empty 
     delete [] vQarray;
-  }
-}
+
+  } //event
+
+}//end of Make()
 
 //--------------------------------------------------------------------  
 void AliFlowAnalysisWithScalarProduct::GetOutputHistograms(TList *outputListHistos){
@@ -431,17 +515,18 @@ void AliFlowAnalysisWithScalarProduct::GetOutputHistograms(TList *outputListHist
     AliFlowCommonHistResults *pCommonHistResults = dynamic_cast<AliFlowCommonHistResults*> 
       (outputListHistos->FindObject("AliFlowCommonHistResultsSP"));
     TProfile* pHistProQaQb     = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_QaQb_SP"));
+    TProfile* pHistProQaQbNorm = dynamic_cast<TProfile*>(outputListHistos->FindObject("FlowPro_QaQbNorm_SP"));
+    TH1D*     pHistSumOfLinearWeights    = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_SumOfLinearWeights_SP"));
+    TH1D*     pHistSumOfQuadraticWeights = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_SumOfQuadraticWeights_SP"));
+
     TProfile* pHistProUQetaRP  = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_UQetaRP_SP"));
     TProfile* pHistProUQetaPOI = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_UQetaPOI_SP"));
     TProfile* pHistProUQPtRP   = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_UQPtRP_SP"));
     TProfile* pHistProUQPtPOI  = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_UQPtPOI_SP"));
-    TH1D*     pHistSumOfLinearWeights    = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_SumOfLinearWeights_SP"));
-    TH1D*     pHistSumOfQuadraticWeights = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_SumOfQuadraticWeights_SP"));
     TProfile* pHistProUQQaQbPtRP    = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_UQQaQbPtRP_SP"));
     TProfile* pHistProUQQaQbEtaRP   = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_UQQaQbEtaRP_SP"));
     TProfile* pHistProUQQaQbPtPOI   = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_UQQaQbPtPOI_SP"));
     TProfile* pHistProUQQaQbEtaPOI  = dynamic_cast<TProfile*>(outputListHistos->FindObject("Flow_UQQaQbEtaPOI_SP"));
-
     TString weightFlag[3] = {"w_Qu_","w_Qu^2_","w_QuQaQb_"}; 
     TH1D* pHistSumOfWeightsPtRP[3] = {NULL};                    
     TH1D* pHistSumOfWeightsEtaRP[3] = {NULL};                    
@@ -449,20 +534,47 @@ void AliFlowAnalysisWithScalarProduct::GetOutputHistograms(TList *outputListHist
     TH1D* pHistSumOfWeightsEtaPOI[3] = {NULL};                    
     for(Int_t i=0;i<3;i++)
     {
-     pHistSumOfWeightsPtRP[i]   = dynamic_cast<TH1D*>(outputListHistos->FindObject(Form("Flow_SumOfWeights%dPtRP_SP",weightFlag[i].Data())));
-     pHistSumOfWeightsEtaRP[i]  = dynamic_cast<TH1D*>(outputListHistos->FindObject(Form("Flow_SumOfWeights%dEtaRP_SP",weightFlag[i].Data())));
-     pHistSumOfWeightsPtPOI[i]  = dynamic_cast<TH1D*>(outputListHistos->FindObject(Form("Flow_SumOfWeights%dPtPOI_SP",weightFlag[i].Data())));
-     pHistSumOfWeightsEtaPOI[i] = dynamic_cast<TH1D*>(outputListHistos->FindObject(Form("Flow_SumOfWeights%dEtaPOI_SP",weightFlag[i].Data())));
+     pHistSumOfWeightsPtRP[i]   = dynamic_cast<TH1D*>(outputListHistos->FindObject(Form("Flow_SumOfWeights%sPtRP_SP",weightFlag[i].Data())));
+     pHistSumOfWeightsEtaRP[i]  = dynamic_cast<TH1D*>(outputListHistos->FindObject(Form("Flow_SumOfWeights%sEtaRP_SP",weightFlag[i].Data())));
+     pHistSumOfWeightsPtPOI[i]  = dynamic_cast<TH1D*>(outputListHistos->FindObject(Form("Flow_SumOfWeights%sPtPOI_SP",weightFlag[i].Data())));
+     pHistSumOfWeightsEtaPOI[i] = dynamic_cast<TH1D*>(outputListHistos->FindObject(Form("Flow_SumOfWeights%sEtaPOI_SP",weightFlag[i].Data())));
     }
 
+    TH1D*     pHistQaQb     = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_QaQb_SP"));
+    TH1D*     pHistQaQbNorm = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_QaQbNorm_SP"));
+    TH1D*     pHistQaQbCos  = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_QaQbCos_SP"));
+    TH1D*     pHistResolution = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_resolution_SP"));
+    TH1D*     pHistQaNorm   = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_QaNorm_SP"));
+    TH2D*     pHistQaNormvsMa   = dynamic_cast<TH2D*>(outputListHistos->FindObject("Flow_QaNormvsMa_SP"));
+    TH1D*     pHistQbNorm   = dynamic_cast<TH1D*>(outputListHistos->FindObject("Flow_QbNorm_SP"));
+    TH2D*     pHistQbNormvsMb   = dynamic_cast<TH2D*>(outputListHistos->FindObject("Flow_QbNormvsMb_SP"));
+    TH2D*     pHistMavsMb = dynamic_cast<TH2D*>(outputListHistos->FindObject("Flow_MavsMb_SP"));
+
     //pass the pointers to the task
-    if (pCommonHist && pCommonHistResults && pHistProQaQb &&
-       pHistProUQetaRP && pHistProUQetaPOI && pHistProUQPtRP && pHistProUQPtPOI 
-       && pHistSumOfLinearWeights && pHistSumOfQuadraticWeights && pHistProUQQaQbPtRP
-       && pHistProUQQaQbEtaRP && pHistProUQQaQbPtPOI && pHistProUQQaQbEtaPOI) {
+    if (pCommonHist && pCommonHistResults && pHistProQaQb && pHistProQaQbNorm &&
+       pHistSumOfLinearWeights && pHistSumOfQuadraticWeights && 
+       pHistQaQb && pHistQaQbNorm && pHistQaQbCos && pHistResolution &&
+       pHistQaNorm && pHistQaNormvsMa && pHistQbNorm && pHistQbNormvsMb && 
+       pHistMavsMb &&
+       pHistProUQetaRP && pHistProUQetaPOI && 
+       pHistProUQPtRP && pHistProUQPtPOI &&  
+       pHistProUQQaQbPtRP && pHistProUQQaQbEtaRP && 
+       pHistProUQQaQbPtPOI && pHistProUQQaQbEtaPOI) {
       this -> SetCommonHists(pCommonHist);
       this -> SetCommonHistsRes(pCommonHistResults);
       this -> SetHistProQaQb(pHistProQaQb);
+      this -> SetHistProQaQbNorm(pHistProQaQbNorm);
+      this -> SetHistSumOfLinearWeights(pHistSumOfLinearWeights);
+      this -> SetHistSumOfQuadraticWeights(pHistSumOfQuadraticWeights); 
+      this -> SetHistQaQb(pHistQaQb);
+      this -> SetHistQaQbNorm(pHistQaQbNorm);
+      this -> SetHistQaQbCos(pHistQaQbCos);
+      this -> SetHistResolution(pHistResolution);
+      this -> SetHistQaNorm(pHistQaNorm);
+      this -> SetHistQaNormvsMa(pHistQaNormvsMa);
+      this -> SetHistQbNorm(pHistQbNorm);
+      this -> SetHistQbNormvsMb(pHistQbNormvsMb);
+      this -> SetHistMavsMb(pHistMavsMb);
       this -> SetHistProUQetaRP(pHistProUQetaRP);
       this -> SetHistProUQetaPOI(pHistProUQetaPOI);
       this -> SetHistProUQPtRP(pHistProUQPtRP);
@@ -471,25 +583,24 @@ void AliFlowAnalysisWithScalarProduct::GetOutputHistograms(TList *outputListHist
       this -> SetHistProUQQaQbEtaRP(pHistProUQQaQbEtaRP);
       this -> SetHistProUQQaQbPtPOI(pHistProUQQaQbPtPOI);
       this -> SetHistProUQQaQbEtaPOI(pHistProUQQaQbEtaPOI);      
-      this -> SetHistSumOfLinearWeights(pHistSumOfLinearWeights);
-      this -> SetHistSumOfQuadraticWeights(pHistSumOfQuadraticWeights);      
-      }  
-   
-   for(Int_t i=0;i<3;i++)
-   {
-    if(pHistSumOfWeightsPtRP[i]) this -> SetHistSumOfWeightsPtRP(pHistSumOfWeightsPtRP[i],i);      
-    if(pHistSumOfWeightsEtaRP[i]) this -> SetHistSumOfWeightsPtRP(pHistSumOfWeightsEtaRP[i],i);      
-    if(pHistSumOfWeightsPtPOI[i]) this -> SetHistSumOfWeightsPtRP(pHistSumOfWeightsPtPOI[i],i);      
-    if(pHistSumOfWeightsEtaPOI[i]) this -> SetHistSumOfWeightsPtRP(pHistSumOfWeightsEtaPOI[i],i);      
-   }   
-      
+         
+      for(Int_t i=0;i<3;i++) {
+       if(pHistSumOfWeightsPtRP[i]) this -> SetHistSumOfWeightsPtRP(pHistSumOfWeightsPtRP[i],i);      
+       if(pHistSumOfWeightsEtaRP[i]) this -> SetHistSumOfWeightsEtaRP(pHistSumOfWeightsEtaRP[i],i);      
+       if(pHistSumOfWeightsPtPOI[i]) this -> SetHistSumOfWeightsPtPOI(pHistSumOfWeightsPtPOI[i],i);      
+       if(pHistSumOfWeightsEtaPOI[i]) this -> SetHistSumOfWeightsEtaPOI(pHistSumOfWeightsEtaPOI[i],i);      
+      }   
+
+    } else {
+      cout<<"WARNING: Histograms needed to run Finish() in SP are not accessable!"<<endl; }
+         
   } // end of if(outputListHistos)
 }            
 
 //--------------------------------------------------------------------            
 void AliFlowAnalysisWithScalarProduct::Finish() {
    
-  //calculate flow and fill the AliFlowCommonHistResults\r
+  //calculate flow and fill the AliFlowCommonHistResults
   if (fDebug) cout<<"AliFlowAnalysisWithScalarProduct::Finish()"<<endl;
 
   cout<<"*************************************"<<endl;
@@ -501,17 +612,29 @@ void AliFlowAnalysisWithScalarProduct::Finish() {
   Int_t iNbinsPt  = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
   Int_t iNbinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
    
-   
+  //Calculate the event plane resolution
+  //----------------------------------
+  Double_t dCos2phi = fHistResolution->GetMean();
+  if (dCos2phi !=0.0){
+    Double_t dResolution = TMath::Sqrt(2*dCos2phi); 
+    cout<<"An estimate of the event plane resolution is: "<<dResolution<<endl;
+    cout<<endl;
+  }
+
   //Calculate reference flow (noname)
   //----------------------------------
   //weighted average over (QaQb/MaMb) with weight (MaMb)
-  Double_t dQaQb  = fHistProQaQb->GetBinContent(1);
-  Double_t dV = TMath::Sqrt(dQaQb); 
+  Double_t dQaQb  = fHistProQaQbNorm->GetBinContent(1);
+  Double_t dV = -999.; 
+  if(dQaQb>=0.)
+  {
+   dV = TMath::Sqrt(dQaQb); 
+  }
   //statistical error of dQaQb: 
   //  statistical error = term1 * spread * term2:
   //  term1 = sqrt{sum_{i=1}^{N} w^2}/(sum_{i=1}^{N} w)
   //  term2 = 1/sqrt(1-term1^2) 
-  Double_t dSpreadQaQb = fHistProQaQb->GetBinError(1);
+  Double_t dSpreadQaQb = fHistProQaQbNorm->GetBinError(1);
   Double_t dSumOfLinearWeights = fHistSumOfLinearWeights->GetBinContent(1);
   Double_t dSumOfQuadraticWeights = fHistSumOfQuadraticWeights->GetBinContent(1);
   Double_t dTerm1 = 0.;
@@ -533,24 +656,22 @@ void AliFlowAnalysisWithScalarProduct::Finish() {
        
   //Calculate differential flow and integrated flow (RP, POI)
   //---------------------------------------------------------
-
   //v as a function of eta for RP selection
-  for(Int_t b=0;b<iNbinsEta;b++) {
+  for(Int_t b=1;b<iNbinsEta+1;b++) {
     Double_t duQpro = fHistProUQetaRP->GetBinContent(b);
-    Double_t dv2pro = 0.;
+    Double_t dv2pro = -999.;
     if (dV!=0.) { dv2pro = duQpro/dV; }
     //calculate the statistical error
     Double_t dv2ProErr = CalculateStatisticalError(b, dStatErrorQaQb, fHistProUQetaRP, fHistProUQQaQbEtaRP, fHistSumOfWeightsEtaRP);
-    
     //fill TH1D
-    fCommonHistsRes->FillDifferentialFlowEtaRP(b, dv2pro, dv2ProErr); 
+    fCommonHistsRes->FillDifferentialFlowEtaRP(b, dv2pro, dv2ProErr);   
   } //loop over bins b
   
 
   //v as a function of eta for POI selection
-  for(Int_t b=0;b<iNbinsEta;b++) {
+  for(Int_t b=1;b<iNbinsEta+1;b++) {
     Double_t duQpro = fHistProUQetaPOI->GetBinContent(b);
-    Double_t dv2pro = 0.;
+    Double_t dv2pro = -999.;
     if (dV!=0.) { dv2pro = duQpro/dV; }
     //calculate the statistical error
     Double_t dv2ProErr = CalculateStatisticalError(b, dStatErrorQaQb, fHistProUQetaPOI, fHistProUQQaQbEtaPOI, fHistSumOfWeightsEtaPOI);
@@ -566,9 +687,9 @@ void AliFlowAnalysisWithScalarProduct::Finish() {
   Double_t dSumRP = 0.;
   Double_t dErrVRP =0.;
   
-  for(Int_t b=0;b<iNbinsPt;b++) {
+  for(Int_t b=1;b<iNbinsPt+1;b++) {
     Double_t duQpro = fHistProUQPtRP->GetBinContent(b);
-    Double_t dv2pro = 0.;
+    Double_t dv2pro = -999.;
     if (dV!=0.) { dv2pro = duQpro/dV; }
     //calculate the statistical error
     Double_t dv2ProErr = CalculateStatisticalError(b, dStatErrorQaQb, fHistProUQPtRP, fHistProUQQaQbPtRP, fHistSumOfWeightsPtRP);
@@ -600,9 +721,9 @@ void AliFlowAnalysisWithScalarProduct::Finish() {
   Double_t dSumPOI = 0.;
   Double_t dErrVPOI =0.;
   
-  for(Int_t b=0;b<iNbinsPt;b++) {
+  for(Int_t b=1;b<iNbinsPt+1;b++) {
     Double_t duQpro = fHistProUQPtPOI->GetBinContent(b);
-    Double_t dv2pro = 0.;
+    Double_t dv2pro = -999.;
     if (dV!=0.) { dv2pro = duQpro/dV; }
     //calculate the statistical error
     Double_t dv2ProErr = CalculateStatisticalError(b, dStatErrorQaQb, fHistProUQPtPOI, fHistProUQQaQbPtPOI, fHistSumOfWeightsPtPOI);
@@ -620,7 +741,7 @@ void AliFlowAnalysisWithScalarProduct::Finish() {
   } //loop over bins b
   
   if (dSumPOI != 0.) {
-    dVPOI /= dSumPOI; //the pt distribution should be normalised\r
+    dVPOI /= dSumPOI; //the pt distribution should be normalised
     dErrVPOI /= (dSumPOI*dSumPOI);
     dErrVPOI = TMath::Sqrt(dErrVPOI);
   }
@@ -637,11 +758,11 @@ void AliFlowAnalysisWithScalarProduct::Finish() {
 
 //--------------------------------------------------------------------            
 Double_t AliFlowAnalysisWithScalarProduct::CalculateStatisticalError(Int_t b, Double_t aStatErrorQaQb, TProfile* pHistProUQ, TProfile* pHistProUQQaQb, TH1D** pHistSumOfWeights) {
-
   //calculate the statistical error for differential flow for bin b
   Double_t duQproSpread = pHistProUQ->GetBinError(b);
   Double_t sumOfMq = pHistSumOfWeights[0]->GetBinContent(b);
   Double_t sumOfMqSquared = pHistSumOfWeights[1]->GetBinContent(b);
+  Double_t dQaQb = fHistProQaQbNorm->GetBinContent(1);
   Double_t dTerm1 = 0.;
   Double_t dTerm2 = 0.;
   if(sumOfMq) {
@@ -651,7 +772,6 @@ Double_t AliFlowAnalysisWithScalarProduct::CalculateStatisticalError(Int_t b, Do
     dTerm2 = 1./pow(1.-pow(dTerm1,2.),0.5); 
   }
   Double_t duQproErr = dTerm1*duQproSpread*dTerm2;
-  
   // covariances:
   Double_t dTerm1Cov = pHistSumOfWeights[2]->GetBinContent(b);
   Double_t dTerm2Cov = fHistSumOfLinearWeights->GetBinContent(1);
@@ -661,16 +781,17 @@ Double_t AliFlowAnalysisWithScalarProduct::CalculateStatisticalError(Int_t b, Do
     Double_t dDenominator = 1.-dTerm1Cov/(dTerm2Cov*dTerm3Cov);
     Double_t dPrefactor = dTerm1Cov/(dTerm2Cov*dTerm3Cov);
     if(dDenominator!=0) {
-      Double_t dCovariance = (pHistProUQQaQb->GetBinContent(b)-fHistProQaQb->GetBinContent(1)*pHistProUQ->GetBinContent(b))/dDenominator;            
+      Double_t dCovariance = (pHistProUQQaQb->GetBinContent(b)-dQaQb*pHistProUQ->GetBinContent(b))/dDenominator;            
       dWeightedCovariance = dCovariance*dPrefactor; 
     }
   }
+  
   Double_t dv2ProErr = 0.; // final statitical error: 
-  if(fHistProQaQb->GetBinContent(1)>0.) {
-    Double_t dv2ProErrorSquared = (1./4.)*pow(fHistProQaQb->GetBinContent(1),-3.)*
+  if(dQaQb>0.) {
+    Double_t dv2ProErrorSquared = (1./4.)*pow(dQaQb,-3.)*
       (pow(pHistProUQ->GetBinContent(b),2.)*pow(aStatErrorQaQb,2.)
-       + 4.*pow(fHistProQaQb->GetBinContent(1),2.)*pow(duQproErr,2.)
-       - 4.*fHistProQaQb->GetBinContent(1)*pHistProUQ->GetBinContent(b)*dWeightedCovariance);
+       + 4.*pow(dQaQb,2.)*pow(duQproErr,2.)
+       - 4.*dQaQb*pHistProUQ->GetBinContent(b)*dWeightedCovariance);
     if(dv2ProErrorSquared>0.) dv2ProErr = pow(dv2ProErrorSquared,0.5);
   }