//Nella release 4 ci sono i TGraph e i fit sui TGraph. Ho perso così l'info in Z che avevo.


#include <fstream>
#include <sstream>
#include <string>
#include <math.h>
#include <iostream>
#include <TTree.h>
#include <TClassEdit.h>
#include <TObject.h>
#include <TList.h>
#include <TSystem.h>
#include <TSystemDirectory.h>
#include <TString.h>
#include <TFile.h>
#include <TClass.h>
#include <TCanvas.h>
#include <TH1.h>
#include <TH1F.h>
#include <TH2D.h>
#include <TLatex.h>
#include <TPad.h>
#include <TPaveLabel.h>
#include <TChain.h>
#include <TGraph.h>
#include <TMultiGraph.h>
#include <TLine.h>
#include <TStyle.h>
#include <TF1.h>
#include <TH1F.h>
#include <TTree.h>
#include <TCanvas.h>
#include <PamLevel2.h>

#include <CaloDoubleShower.h> // ADD HEADER FILE HERE

using namespace std;



void example(TString dir, TString flist, TString treelist="+ALL"){


  
  PamLevel2 *pam_event = new PamLevel2(dir,flist);       // << create pamela event
  TChain *T = pam_event->GetPamTree();

  CaloDoubleShower *cn = new CaloDoubleShower(pam_event);  // CREATE CaloDoubleShower OBJECT GIVING PamLevel2 POINTER

  cn->LoadMagneticField(); // THIS IS NEEDED SINCE FROM THE FORTRAN ROUTINES THE MAGNETIC FIELD IS NOT AUTOMATICALLY LOADED. NOT NEEDED IF THE FIELD WILL BE OR HAS BEEN LOADED BY
                           // OTHER ROUTINES (LIKE TrkTrajectory or similar)
 
  Int_t nevent = pam_event->GetEntries();
  cout<< " Events= "<<nevent<<"\n";

  const Int_t size=nevent;
 
  //
  // loop over events
  //
  //  for (Int_t i=0; i<nevent;i++){
  for (Int_t i=0; i<50;i++){
    
    if ( i%10000 == 0) cout<<i<<endl;
    //
    T->GetEntry(i);  // get the entry, also pam_event->GetEntry is fine
    
    cn->Print(); // this will simply print on the terminal the determined CaloNuclei values
    
    Float_t dblsq = cn->GetDblsQ();    // double shower energy on the x
    Int_t dbls = cn->GetDblsFlag();    // double shower flag
    //
    // do something
    //
    //
    // if you want to do it for other tracks and not only for the track number 0 (default) you can do this way:
    //
    Float_t mipt[100];
    memset(mipt,0.,100*sizeof(Float_t));
    for (Int_t nt = 0; nt < pam_event->GetTrkLevel2()->GetNTracks(); nt++){
      PamTrack *track = pam_event->GetTrack(nt);
      cn->Process(nt);
      cn->Print(nt);
      //
      // do something as before
      //
    };
    //

  }   
  printf(" end!\n");
 
};
//



