#include <vector>
using std::cout;
using std::endl;

void gam_conv_pid(TString InputFile ="../MCgen2/pid_complete.root"){


  TString OutputFile = "gam_conv_pid.root";
  TDatabasePDG *Database = new TDatabasePDG();
  
	
	TFile *outfile = TFile::Open(OutputFile,"RECREATE");
	TH1F *energy = new TH1F("energy"," reconstructed photon energy ",100, 0., 1.5);

  // ---------------- Open the Inputefile and get Access to the specific Branch
  TFile *file = TFile::Open(InputFile,"READ");
  TTree *tree = (TTree*) file->Get("cbmsim");
  TClonesArray* hit_array=new TClonesArray("PndPidNeutralCand"); 
  PndPidNeutralCand* punkt= new PndPidNeutralCand();
  TBranchElement *brscitpoint = (TBranchElement*) tree->GetBranch("PidNeutralCand");

  Int_t br_entries,ar_entries;

  brscitpoint->SetAddress(&hit_array);
  br_entries = brscitpoint->GetEntries();

  for (Int_t j=0;j<br_entries;j++){
    brscitpoint->GetEntry(j); 
    

    ar_entries = hit_array->GetEntriesFast();

    for (Int_t k = 0; k < ar_entries; k++){
      punkt = (PndPidNeutralCand*) hit_array->At(k);


      //inside the loop------------------------------------------------------


	Double_t cls_energy = punkt->GetEmcCalEnergy(); 
	energy->Fill(cls_energy); 
 }

  }  //loop end

  
outfile->cd();
energy->Write();
outfile->Save();

}


