ROOT logo
//=====================================================//
//Macro that reads the output of the flow analysis and 
//retrieves the QC and the MH containers.
//The macro produces an output called outputMH.root 
//that contains the four histograms related to the 
//3 particle correlator and the two integrated v2{2,QC} 
//and v2{4,QC}
//Author: Panos.Christakoglou@cern.ch

void plotMH(const char* filename = "AnalysisResults.root",
	    const char* analysisType = "TPC only",
	    Int_t centrality = 0) {
  gStyle->SetPalette(1,0);

  //----------------------------------------------------------
  // >>>>>>>>>>> Load libraries <<<<<<<<<<<<<< 
  //----------------------------------------------------------
  gSystem->AddIncludePath("-I$ROOTSYS/include");
  gSystem->Load("libGeom");
  gSystem->Load("libVMC");
  gSystem->Load("libXMLIO");
  gSystem->Load("libPhysics");
  
  gSystem->AddIncludePath("-I$ALICE_ROOT/include");
  gSystem->Load("libANALYSIS");
  gSystem->Load("libPWGflowBase");

  //----------------------------------------------------------
  // >>>>>>>>>>> Open file - Get objects <<<<<<<<<<<<<< 
  //----------------------------------------------------------
  TFile *fInput = TFile::Open(filename);
  if(!fInput) {
    Printf("File not found!!!");
    break;
  }
  //f->ls();

  //Get the TList of the MH
  TList *listMH = GetMHResults(fInput,analysisType,centrality);

  //Get the TList of the QC
  TList *listQC = GetQCResults(fInput,analysisType,centrality);

  TFile *fOutput = TFile::Open("outputMH.root","recreate");
  listMH->Write();
  listQC->Write();
  fOutput->Close();
}

//____________________________________________________________//
TList *GetQCResults(TFile *fInput,
		    const char* analysisType = 0x0,
		    Int_t centrality = -1) {
  //Function that reads the TDirectoryFile of the MH
  //and returns a TList with the relevant plots.
  TList *listOutput = new TList();
  listOutput->SetName("listQC");

  //______________________________________________________________//
  //Global variables
  const Int_t nQCMethods = 4;
  AliFlowCommonHistResults *commonHistRes[nQCMethods];
  TString methodIntegratedFlowQC[nQCMethods] = {"2ndOrderQC",
						"4thOrderQC",
						"6thOrderQC",
						"8thOrderQC"};
  TString gAliFlowCommonHistName[nQCMethods];

  //______________________________________________________________//
  //Get the TDirectoryFile
  TString directoryNameQC = 0;
  directoryNameQC = "outputQCanalysis"; 
  if(analysisType) directoryNameQC += analysisType;
  TDirectoryFile *outputQCanalysis = dynamic_cast<TDirectoryFile *>(fInput->Get(directoryNameQC.Data()));
  if(!outputQCanalysis) {
    Printf("QC directory not found!!!");
    break;
  }
  //outputQCanalysis->ls();

  //______________________________________________________________//
  //Get the TList
  TString listNameQC = 0;
  if(centrality > -1) {
    listNameQC = "cobjQC_outputCentrality"; 
    listNameQC += centrality; listNameQC += ".root";
  }
  else listNameQC = "cobjQC";
  TList *cobjQC = dynamic_cast<TList *>(outputQCanalysis->Get(listNameQC.Data()));
  if(!cobjQC) {
    Printf("QC object list not found!!!");
    break;
  }

  //Common hist for QC
  Double_t nAnalyzedEvents = 0.;
  AliFlowCommonHist *commonHistQC = dynamic_cast<AliFlowCommonHist *>(cobjQC->FindObject("AliFlowCommonHistQC"));
  if(commonHistQC) {
    TList *clistQCCommonHist = dynamic_cast<TList *>(commonHistQC->GetHistList());
    if(clistQCCommonHist) {
      TH1F *gHistMultRPQC = dynamic_cast<TH1F *>(clistQCCommonHist->FindObject("Control_Flow_MultRP_AliFlowCommonHistQC"));
      if(gHistMultRPQC)
	nAnalyzedEvents = gHistMultRPQC->GetEntries();
    }
  }

  //2nd order QC
  gAliFlowCommonHistName[0] = "AliFlowCommonHistResults";
  gAliFlowCommonHistName[0] += methodIntegratedFlowQC[0].Data();
  commonHistRes[0] = dynamic_cast<AliFlowCommonHistResults *>(cobjQC->FindObject(gAliFlowCommonHistName[0].Data()));
  //Printf("AliFlowCommonHist name %s",gAliFlowCommonHistName[0].Data());
  TH1D *histQC_2 = commonHistRes[0]->GetHistIntFlowRP();
  histQC_2->SetName("fHistIntegratedFlowRPQC_2");

  //4th order QC
  gAliFlowCommonHistName[1] = "AliFlowCommonHistResults";
  gAliFlowCommonHistName[1] += methodIntegratedFlowQC[1].Data();
  commonHistRes[1] = dynamic_cast<AliFlowCommonHistResults *>(cobjQC->FindObject(gAliFlowCommonHistName[1].Data()));
  //Printf("AliFlowCommonHist name %s",gAliFlowCommonHistName[1].Data());
  TH1D *histQC_4 = commonHistRes[1]->GetHistIntFlowRP();
  histQC_4->SetName("fHistIntegratedFlowRPQC_4");

  //6th order QC
  gAliFlowCommonHistName[2] = "AliFlowCommonHistResults";
  gAliFlowCommonHistName[2] += methodIntegratedFlowQC[2].Data();
  commonHistRes[2] = dynamic_cast<AliFlowCommonHistResults *>(cobjQC->FindObject(gAliFlowCommonHistName[2].Data()));
  //Printf("AliFlowCommonHist name %s",gAliFlowCommonHistName[2].Data());
  TH1D *histQC_6 = commonHistRes[2]->GetHistIntFlowRP();
  histQC_6->SetName("fHistIntegratedFlowRPQC_6");

  //8th order QC
  gAliFlowCommonHistName[3] = "AliFlowCommonHistResults";
  gAliFlowCommonHistName[3] += methodIntegratedFlowQC[3].Data();
  commonHistRes[3] = dynamic_cast<AliFlowCommonHistResults *>(cobjQC->FindObject(gAliFlowCommonHistName[3].Data()));
  //Printf("AliFlowCommonHist name %s",gAliFlowCommonHistName[3].Data());
  TH1D *histQC_8 = commonHistRes[3]->GetHistIntFlowRP();
  histQC_8->SetName("fHistIntegratedFlowRPQC_8");

  TH1D *gHistEvents = new TH1D("gHistEvents",";;N_{analyzed events}",
			       1,0.5,1.5);
  gHistEvents->SetBinContent(1,nAnalyzedEvents);
  //______________________________________________________________//
  //Print the results
  Printf("\n============================================================");
  Printf("Analyzed events: %d",(Int_t)nAnalyzedEvents);
  Printf("v2(2,QC): %lf +- %lf",histQC_2->GetBinContent(1),
	 histQC_2->GetBinError(1));
  Printf("v2(4,QC): %lf +- %lf",histQC_4->GetBinContent(1),
	 histQC_4->GetBinError(1));
  Printf("v2(6,QC): %lf +- %lf",histQC_6->GetBinContent(1),
	 histQC_6->GetBinError(1));
  Printf("v2(8,QC): %lf +- %lf",histQC_8->GetBinContent(1),
	 histQC_8->GetBinError(1));
  Printf("============================================================");

  listOutput->Add(histQC_2);
  listOutput->Add(histQC_4);
  listOutput->Add(histQC_6);
  listOutput->Add(histQC_8);
  listOutput->Add(gHistEvents);

  return listOutput;
}

//____________________________________________________________//
TList *GetMHResults(TFile *fInput,
		    const char* analysisType = 0x0,
		    Int_t centrality = -1) {
  //Function that reads the TDirectoryFile of the MH
  //and returns a TList with the relevant plots.
  TList *listOutput = new TList();
  listOutput->SetName("listMH");

  //______________________________________________________________//
  //Get the TDirectoryFile
  TString directoryNameMH = 0;
  directoryNameMH = "outputMHanalysis"; 
  if(analysisType) directoryNameMH += analysisType;
  TDirectoryFile *outputMHanalysis = dynamic_cast<TDirectoryFile *>(fInput->Get(directoryNameMH.Data()));
  if(!outputMHanalysis) {
    Printf("MH directory not found!!!");
    break;
  }
  //outputMHanalysis->ls();

  //______________________________________________________________//
  //Get the TList
  TString listNameMH = 0;
  if(centrality > -1) {
    listNameMH = "cobjMH_outputCentrality"; 
    listNameMH += centrality; listNameMH += ".root";
  }
  else listNameMH = "cobjMH";
  TList *cobjMH = dynamic_cast<TList *>(outputMHanalysis->Get(listNameMH.Data()));
  if(!cobjMH) {
    Printf("MH object list not found!!!");
    break;
  }
  //cobjMH->ls();

  //______________________________________________________________//
  //Get the daughter TLists
  TList *listWeights = dynamic_cast<TList *>(cobjMH->At(0));
  //listWeights->ls();
  TList *listProfiles = dynamic_cast<TList *>(cobjMH->At(1));
  //listProfiles->ls();
  TList *listResults = dynamic_cast<TList *>(cobjMH->At(2));
  //listResults->ls();

  if((!listWeights)||(!listProfiles)||(!listResults)) {
    Printf("MH output lists not found!!!");
    break;
  }

  //______________________________________________________________//
  TProfile *fAnalysisSettings = dynamic_cast<TProfile *>(cobjMH->At(3));

  //______________________________________________________________//
  //Get the objects from the Results list
  TH1D *f3pCorrelatorHist = dynamic_cast<TH1D *>(listResults->At(0));
  TH1D *fDetectorBiasHist = dynamic_cast<TH1D *>(listResults->At(1));
  TH1D *f3pCorrelatorVsMHist = dynamic_cast<TH1D *>(listResults->At(2));
  TH1D *fDetectorBiasVsMHist = dynamic_cast<TH1D *>(listResults->At(3));

  //______________________________________________________________//
  //Get the objects from the Profile list
  TProfile *f3pCorrelatorPro = dynamic_cast<TProfile *>(listProfiles->At(0));
  TProfile *fNonIsotropicTermsPro = dynamic_cast<TProfile *>(listProfiles->At(1));
  TProfile *f3pCorrelatorVsMPro = dynamic_cast<TProfile *>(listProfiles->At(2));
  TProfile2D *fNonIsotropicTermsVsMPro = dynamic_cast<TProfile2D *>(listProfiles->At(3));
  TProfile *f3pCorrelatorVsPtSumPro = dynamic_cast<TProfile *>(listProfiles->At(4));
  TProfile *f3pCorrelatorVsPtDiffPro = dynamic_cast<TProfile *>(listProfiles->At(5));
  
  //______________________________________________________________//
  //Draw the histograms
  TCanvas *c0 = new TCanvas("c0","Analysis settings",0,0,500,500);
  c0->SetHighLightColor(10); c0->SetFillColor(10);
  fAnalysisSettings->Draw();

  TCanvas *c1 = new TCanvas("c1","3p correlator",50,50,500,500);
  c1->SetHighLightColor(10); c1->SetFillColor(10);
  f3pCorrelatorHist->Draw("E");

  TCanvas *c2 = new TCanvas("c2","Detector bias",100,100,500,500);
  c2->SetHighLightColor(10); c2->SetFillColor(10);
  fDetectorBiasHist->Draw("E");

  TCanvas *c3 = new TCanvas("c3","3p correlator vs M",150,150,500,500);
  c3->SetHighLightColor(10); c3->SetFillColor(10);
  f3pCorrelatorVsMHist->Draw("E");

  TCanvas *c4 = new TCanvas("c4","Detector bias vs M",200,200,500,500);
  c4->SetHighLightColor(10); c4->SetFillColor(10);
  fDetectorBiasVsMHist->Draw("E");

  TCanvas *c5 = new TCanvas("c5","3p correlator (pro)",500,0,500,500);
  c5->SetHighLightColor(10); c5->SetFillColor(10);
  f3pCorrelatorPro->Draw("E");

  TCanvas *c6 = new TCanvas("c6","Non isotropic terms",550,50,500,500);
  c6->SetHighLightColor(10); c6->SetFillColor(10);
  fNonIsotropicTermsPro->Draw("E");

  TCanvas *c7 = new TCanvas("c7","3p correlator vs M (pro)",600,100,500,500);
  c7->SetHighLightColor(10); c7->SetFillColor(10);
  f3pCorrelatorVsMPro->Draw("E");

  TCanvas *c8 = new TCanvas("c8","Non isotropic terms vs M (pro)",650,150,500,500);
  c8->SetHighLightColor(10); c8->SetFillColor(10);
  fNonIsotropicTermsVsMPro->Draw("colz");

  TCanvas *c9 = new TCanvas("c9","3p correlator vs sum pt",700,200,500,500);
  c9->SetHighLightColor(10); c9->SetFillColor(10);
  f3pCorrelatorVsPtSumPro->Draw("E");

  TCanvas *c10 = new TCanvas("c10","3p correlator vs diff pt",750,250,500,500);
  c10->SetHighLightColor(10); c10->SetFillColor(10);
  f3pCorrelatorVsPtDiffPro->Draw("E");

  Double_t g3pCorrelatorValue = 0., g3pCorrelatorError = 0.;
  GetCorrelatorAndError(f3pCorrelatorVsPtSumPro,
			//GetCorrelatorAndError(f3pCorrelatorVsPtDiffPro,
			g3pCorrelatorValue,
			g3pCorrelatorError,1,20);
			
  //______________________________________________________________//
  //Print the results
  Printf("============================================================");
  cout<<"<cos(psi1 + psi2 - 2phi3)>: "<<
    g3pCorrelatorValue <<
    " +- " <<
    g3pCorrelatorError << endl;
  cout<<"<cos(phi1 + phi2 - 2phi3)>: "<<
    f3pCorrelatorHist->GetBinContent(1) <<
    " +- " <<
    f3pCorrelatorHist->GetBinError(1)<<endl;
  Printf("============================================================");

  listOutput->Add(f3pCorrelatorHist);
  listOutput->Add(f3pCorrelatorVsMHist);
  listOutput->Add(f3pCorrelatorVsPtSumPro);
  listOutput->Add(f3pCorrelatorVsPtDiffPro);

  return listOutput;
}

//____________________________________________________________//
void GetCorrelatorAndError(TProfile *f3pCorrelatorVsPt,
			   Double_t &g3pCorrelatorValue,
			   Double_t &g3pCorrelatorError,
			   Int_t iBinLow = 0,
			   Int_t iBinHigh = 0) {
  //Function to return the average value of the 3p correlator 
  //<cos(psi1 + psi2 - 2phi3)> and its error.
  //The first argument is one of the 3p TProfile objects vs pt.
  //The second and third argument give the integral and its error.
  //The fourth and fifth, if specified, indicate the lowest and 
  //highest bin the calculation should be performed for.
  Int_t gBinLow = 1, gBinHigh = f3pCorrelatorVsPt->GetNbinsX();
  if(iBinLow) gBinLow = iBinLow;
  if(iBinHigh) gBinHigh = iBinHigh;
  
  Int_t iBinCounter = 0;
  Double_t gSumBinContentTimesWeight = 0., gSumWeight = 0.;
  Double_t gSumBinContentTimesWeightSquared = 0.;
  for(Int_t iBin = gBinLow; iBin <= gBinHigh; iBin++) {
    iBinCounter += 1;
    
    gSumBinContentTimesWeight += f3pCorrelatorVsPt->GetBinContent(iBin)*f3pCorrelatorVsPt->GetBinEntries(iBin);
    gSumWeight += f3pCorrelatorVsPt->GetBinEntries(iBin);
    gSumBinContentTimesWeightSquared += TMath::Power(gSumBinContentTimesWeight,2);
  }

  Printf("%lf - %d",gSumWeight,iBinCounter);
  //Calculate the g3pCorrelatorValue and its error
  g3pCorrelatorValue = -1000.;
  g3pCorrelatorError = 1000.;
  if((gSumWeight)&&(iBinCounter)) {
    g3pCorrelatorValue = gSumBinContentTimesWeight/(gSumWeight*iBinCounter);
    g3pCorrelatorError = TMath::Sqrt(gSumBinContentTimesWeightSquared/TMath::Power(gSumWeight,2))/iBinCounter;
  }

  return;
}

 plotMH.C:1
 plotMH.C:2
 plotMH.C:3
 plotMH.C:4
 plotMH.C:5
 plotMH.C:6
 plotMH.C:7
 plotMH.C:8
 plotMH.C:9
 plotMH.C:10
 plotMH.C:11
 plotMH.C:12
 plotMH.C:13
 plotMH.C:14
 plotMH.C:15
 plotMH.C:16
 plotMH.C:17
 plotMH.C:18
 plotMH.C:19
 plotMH.C:20
 plotMH.C:21
 plotMH.C:22
 plotMH.C:23
 plotMH.C:24
 plotMH.C:25
 plotMH.C:26
 plotMH.C:27
 plotMH.C:28
 plotMH.C:29
 plotMH.C:30
 plotMH.C:31
 plotMH.C:32
 plotMH.C:33
 plotMH.C:34
 plotMH.C:35
 plotMH.C:36
 plotMH.C:37
 plotMH.C:38
 plotMH.C:39
 plotMH.C:40
 plotMH.C:41
 plotMH.C:42
 plotMH.C:43
 plotMH.C:44
 plotMH.C:45
 plotMH.C:46
 plotMH.C:47
 plotMH.C:48
 plotMH.C:49
 plotMH.C:50
 plotMH.C:51
 plotMH.C:52
 plotMH.C:53
 plotMH.C:54
 plotMH.C:55
 plotMH.C:56
 plotMH.C:57
 plotMH.C:58
 plotMH.C:59
 plotMH.C:60
 plotMH.C:61
 plotMH.C:62
 plotMH.C:63
 plotMH.C:64
 plotMH.C:65
 plotMH.C:66
 plotMH.C:67
 plotMH.C:68
 plotMH.C:69
 plotMH.C:70
 plotMH.C:71
 plotMH.C:72
 plotMH.C:73
 plotMH.C:74
 plotMH.C:75
 plotMH.C:76
 plotMH.C:77
 plotMH.C:78
 plotMH.C:79
 plotMH.C:80
 plotMH.C:81
 plotMH.C:82
 plotMH.C:83
 plotMH.C:84
 plotMH.C:85
 plotMH.C:86
 plotMH.C:87
 plotMH.C:88
 plotMH.C:89
 plotMH.C:90
 plotMH.C:91
 plotMH.C:92
 plotMH.C:93
 plotMH.C:94
 plotMH.C:95
 plotMH.C:96
 plotMH.C:97
 plotMH.C:98
 plotMH.C:99
 plotMH.C:100
 plotMH.C:101
 plotMH.C:102
 plotMH.C:103
 plotMH.C:104
 plotMH.C:105
 plotMH.C:106
 plotMH.C:107
 plotMH.C:108
 plotMH.C:109
 plotMH.C:110
 plotMH.C:111
 plotMH.C:112
 plotMH.C:113
 plotMH.C:114
 plotMH.C:115
 plotMH.C:116
 plotMH.C:117
 plotMH.C:118
 plotMH.C:119
 plotMH.C:120
 plotMH.C:121
 plotMH.C:122
 plotMH.C:123
 plotMH.C:124
 plotMH.C:125
 plotMH.C:126
 plotMH.C:127
 plotMH.C:128
 plotMH.C:129
 plotMH.C:130
 plotMH.C:131
 plotMH.C:132
 plotMH.C:133
 plotMH.C:134
 plotMH.C:135
 plotMH.C:136
 plotMH.C:137
 plotMH.C:138
 plotMH.C:139
 plotMH.C:140
 plotMH.C:141
 plotMH.C:142
 plotMH.C:143
 plotMH.C:144
 plotMH.C:145
 plotMH.C:146
 plotMH.C:147
 plotMH.C:148
 plotMH.C:149
 plotMH.C:150
 plotMH.C:151
 plotMH.C:152
 plotMH.C:153
 plotMH.C:154
 plotMH.C:155
 plotMH.C:156
 plotMH.C:157
 plotMH.C:158
 plotMH.C:159
 plotMH.C:160
 plotMH.C:161
 plotMH.C:162
 plotMH.C:163
 plotMH.C:164
 plotMH.C:165
 plotMH.C:166
 plotMH.C:167
 plotMH.C:168
 plotMH.C:169
 plotMH.C:170
 plotMH.C:171
 plotMH.C:172
 plotMH.C:173
 plotMH.C:174
 plotMH.C:175
 plotMH.C:176
 plotMH.C:177
 plotMH.C:178
 plotMH.C:179
 plotMH.C:180
 plotMH.C:181
 plotMH.C:182
 plotMH.C:183
 plotMH.C:184
 plotMH.C:185
 plotMH.C:186
 plotMH.C:187
 plotMH.C:188
 plotMH.C:189
 plotMH.C:190
 plotMH.C:191
 plotMH.C:192
 plotMH.C:193
 plotMH.C:194
 plotMH.C:195
 plotMH.C:196
 plotMH.C:197
 plotMH.C:198
 plotMH.C:199
 plotMH.C:200
 plotMH.C:201
 plotMH.C:202
 plotMH.C:203
 plotMH.C:204
 plotMH.C:205
 plotMH.C:206
 plotMH.C:207
 plotMH.C:208
 plotMH.C:209
 plotMH.C:210
 plotMH.C:211
 plotMH.C:212
 plotMH.C:213
 plotMH.C:214
 plotMH.C:215
 plotMH.C:216
 plotMH.C:217
 plotMH.C:218
 plotMH.C:219
 plotMH.C:220
 plotMH.C:221
 plotMH.C:222
 plotMH.C:223
 plotMH.C:224
 plotMH.C:225
 plotMH.C:226
 plotMH.C:227
 plotMH.C:228
 plotMH.C:229
 plotMH.C:230
 plotMH.C:231
 plotMH.C:232
 plotMH.C:233
 plotMH.C:234
 plotMH.C:235
 plotMH.C:236
 plotMH.C:237
 plotMH.C:238
 plotMH.C:239
 plotMH.C:240
 plotMH.C:241
 plotMH.C:242
 plotMH.C:243
 plotMH.C:244
 plotMH.C:245
 plotMH.C:246
 plotMH.C:247
 plotMH.C:248
 plotMH.C:249
 plotMH.C:250
 plotMH.C:251
 plotMH.C:252
 plotMH.C:253
 plotMH.C:254
 plotMH.C:255
 plotMH.C:256
 plotMH.C:257
 plotMH.C:258
 plotMH.C:259
 plotMH.C:260
 plotMH.C:261
 plotMH.C:262
 plotMH.C:263
 plotMH.C:264
 plotMH.C:265
 plotMH.C:266
 plotMH.C:267
 plotMH.C:268
 plotMH.C:269
 plotMH.C:270
 plotMH.C:271
 plotMH.C:272
 plotMH.C:273
 plotMH.C:274
 plotMH.C:275
 plotMH.C:276
 plotMH.C:277
 plotMH.C:278
 plotMH.C:279
 plotMH.C:280
 plotMH.C:281
 plotMH.C:282
 plotMH.C:283
 plotMH.C:284
 plotMH.C:285
 plotMH.C:286
 plotMH.C:287
 plotMH.C:288
 plotMH.C:289
 plotMH.C:290
 plotMH.C:291
 plotMH.C:292
 plotMH.C:293
 plotMH.C:294
 plotMH.C:295
 plotMH.C:296
 plotMH.C:297
 plotMH.C:298
 plotMH.C:299
 plotMH.C:300
 plotMH.C:301
 plotMH.C:302
 plotMH.C:303
 plotMH.C:304
 plotMH.C:305
 plotMH.C:306
 plotMH.C:307
 plotMH.C:308
 plotMH.C:309
 plotMH.C:310
 plotMH.C:311
 plotMH.C:312
 plotMH.C:313
 plotMH.C:314
 plotMH.C:315
 plotMH.C:316
 plotMH.C:317
 plotMH.C:318
 plotMH.C:319
 plotMH.C:320
 plotMH.C:321
 plotMH.C:322
 plotMH.C:323
 plotMH.C:324
 plotMH.C:325
 plotMH.C:326
 plotMH.C:327
 plotMH.C:328
 plotMH.C:329
 plotMH.C:330
 plotMH.C:331
 plotMH.C:332
 plotMH.C:333
 plotMH.C:334
 plotMH.C:335
 plotMH.C:336
 plotMH.C:337
 plotMH.C:338
 plotMH.C:339
 plotMH.C:340
 plotMH.C:341
 plotMH.C:342
 plotMH.C:343
 plotMH.C:344
 plotMH.C:345
 plotMH.C:346