コード例 #1
0
ファイル: shib-resource.cpp プロジェクト: svn2github/cpp-sp
ResourcePriv::ResourcePriv(const char *str)
{
  string ctx = "shibtarget.Resource";
  log = &(log4cpp::Category::getInstance(ctx));

  m_url = str;

  // XXX: The Resource is just the hostname!
  const char* colon=strchr(str,':');
  const char* slash=strchr(colon+3,'/');
  m_resource = m_url.substr(0, slash-str);

  log->info("creating resource: \"%s\" -> \"%s\"", str, m_resource.c_str());

  // Now figure out the designators
  string server = m_url.substr(colon-str+3, slash-(colon+3));

  log->debug("server is \"%s\"", server.c_str());

  ShibTargetConfig& config = ShibTargetConfig::getConfig();
  ShibINI& ini = config.getINI();

  string tag;
  if (ini.get_tag (server, SHIBTARGET_TAG_REQATTRS, true, &tag)) {
    // Now parse the request attributes tag...

    log->debug("Request Attributes: \"%s\"", tag.c_str());

    auto_ptr<char> tag_str(strdup(tag.c_str()));

    char *tags = tag_str.get(), *tagptr = NULL, *the_tag;
#ifdef HAVE_STRTOK_R
    while ((the_tag = strtok_r(tags, " \t\r\n", &tagptr)) != NULL && *the_tag) {
#else
    while ((the_tag = strtok(tags, " \t\r\n")) != NULL && *the_tag) {
#endif
      // Make sure we don't loop ad-infinitum
      tags = NULL;

      log->debug ("Parsed attribute string: \"%s\"", the_tag);
      log->debug ("tagptr = %p", tagptr);
      
      // transcode the attribute string from the tag
      auto_ptr<XMLCh> temp(XMLString::transcode(the_tag));

      // Now create the SAML Attribute from this name
      try {
	SAMLAttribute *attr =
	  new SAMLAttribute(temp.get(),
			    shibboleth::Constants::SHIB_ATTRIBUTE_NAMESPACE_URI);
	if (attr)
	  designators.push_back(attr);
      } catch ( ... ) { }
    }
  } else
コード例 #2
0
ファイル: dummyPlotter.cpp プロジェクト: CeF3TB/H4_2015
int main( int argc, char* argv[] ) {

    DrawTools::setStyle();


    if( argc<2 ) {
        std::cout << "ERROR. You need to specify the name of the run you want to process." << std::endl;
        exit(1);
    }

    std::string runName = "";
    std::string tag = "V00";

    if( argc>1 ) {
        std::string runName_str(argv[1]);
        runName = runName_str;
        if( argc>2 ) {
            std::string tag_str(argv[2]);
            tag = tag_str;
        }
    } else {

        std::cout << "Usage:" << std::endl;
        std::cout << "./makeAnalysisTree [runName] ([tag]) ([config])" << std::endl;
        exit(12345);

    }

    std::string fileName = "./analysisTrees_"+tag+"/Reco_" + runName + ".root";

    TFile* file = TFile::Open(fileName.c_str());
    if( file==0 ) {
        std::cout << "ERROR! Din't find file " << fileName << std::endl;
        std::cout << "Exiting." << std::endl;
        exit(11);
    }
    TTree* tree = (TTree*)file->Get("recoTree");

    TCanvas c1("dummy");
    tree->Draw("(cef3_time_at_frac50[1]-mcp_time_frac50):cef3_maxAmpl[1]>>h","cef3_time_at_thresh[1]>0 && cef3_time_at_thresh[1]<50 && mcp_max_amplitude>300 && cef3_maxAmpl[1]>10 && TMath::Abs(cef3_time_at_frac50[1]-mcp_time_frac50)<20","colz");
    tree->Draw("(cef3_time_at_frac50[1]-mcp_time_frac50):cef3_maxAmpl[1]>>hprof","cef3_time_at_thresh[1]>0 && cef3_time_at_thresh[1]<50 && mcp_max_amplitude>300 && cef3_maxAmpl[1]>10 && TMath::Abs(cef3_time_at_frac50[1]-mcp_time_frac50)<20","profXsamep");
    c1.SaveAs("stocazzo.png");


}
コード例 #3
0
int main( int argc, char* argv[] ) {

  
  runName = "test_10";
  if( argc>1 ) {
    std::string runName_str(argv[1]);
    runName = runName_str;
  }

  std::string tag = "V02";
  if( argc>2 ) {
    std::string tag_str(argv[2]);
    tag = tag_str;
  }


  std::string fileName = "PosAnTrees_" + tag + "/PosAn_" + runName + ".root";
  TFile* file = TFile::Open( fileName.c_str() );
  std::cout << "-> Opened file: " << fileName << std::endl;
  
  std::string outputdir = "Plots_" + runName + "_" + tag;
  std::string mkdir_command = "mkdir -p " + outputdir;
  system(mkdir_command.c_str());


  TStyle* style = DrawTools::setStyle();
  style->cd();

  drawSinglePositionPlot( outputdir, file, runName, "" );
  drawSinglePositionPlot( outputdir, file, runName, "_singleEle" );


  drawPositionResolutionXY( outputdir, file, runName, "bgo", "Beam" );

  return 0;

}
コード例 #4
0
ファイル: plotterSimpleMaps.cpp プロジェクト: CeF3TB/H4_2015
int main( int argc, char* argv[] ) {

  DrawTools::setStyle();

  std::string tag = "V00";
  std::string config = "SiPM2015Config";
  
  if( argc>1 ) {
    std::string tag_str(argv[1]);
    tag = tag_str;
    if( argc>2 ) {
      std::string config_str(argv[2]);
      config=config_str;
    }
  } else {
    std::cout << "Usage:" << std::endl;
    std::cout << "./plotterMaps ([tag]) ([config])" << std::endl;
    exit(12345);
  }

  std::cout<<config<<std::endl;
  
  theConfiguration_=readConfiguration(config);

  std::string constDirName = "plots_Simplemaps_";
  constDirName+=theConfiguration_.setup;
  if(theConfiguration_.addTagFileName){
    constDirName+="_";
    constDirName+=theConfiguration_.tagFileName;
  }
  system(Form("mkdir -p %s", constDirName.c_str()));

  
  TString dir(constDirName);

  
  
  TString filename= "plots_timingPerformance_"+theConfiguration_.setup+"/mapCreatorOutput_"+tag+".root";
  
  TFile* file = TFile::Open(filename.Data());

  std::map<TString,TH1F*> histoNames;
  std::map<TString,TH2F*> histoNames2D;
  

  TList* list = file->GetListOfKeys() ;
  if (!list) { printf("<E> No keys found in file\n") ; exit(1) ; }
  TIter next(list) ;
  TKey* key ;
  TObject* obj ;

  
  while ( key = (TKey*)next() ) {
    obj = key->ReadObj() ;
    if (    (strcmp(obj->IsA()->GetName(),"TProfile")!=0)
	    && (!obj->InheritsFrom("TH2"))
	    && (!obj->InheritsFrom("TH1")) 
	    ) {
      printf("<W> Object %s is not 1D or 2D histogram : "
	     "will not be converted\n",obj->GetName()) ;
    }
    printf("Histo name:%s title:%s\n",obj->GetName(),obj->GetTitle());
    if((strcmp(obj->IsA()->GetName(),"TH1F"))==0){
      histoNames[obj->GetName()]=(TH1F*)obj;
    }else if ((strcmp(obj->IsA()->GetName(),"TH2F"))==0){
      histoNames2D[obj->GetName()]=(TH2F*)obj;
    }
  }



  for(std::map<TString,TH2F*>::const_iterator out=histoNames2D.begin();out!=histoNames2D.end();++out){

    gStyle->SetPadRightMargin(0.19);//for the palette and ztitle
    TCanvas c1;
    TH2F* histo=(TH2F*)out->second->Clone(out->first+"_clone");
    histo->GetZaxis()->SetTitleOffset(1.4);
    if(out->first.Contains("amplitude"))histo->SetZTitle("Amplitude [ADC]");
    if(out->first.Contains("timing"))histo->SetZTitle("#DeltaT [ns]");
    histo->Draw("colz");
    c1.SaveAs(dir+"/"+out->first+".pdf");
    c1.SaveAs(dir+"/"+out->first+".png");
  }





    gStyle->SetPadRightMargin(0.10);
    TH1F* maxAmpl_sel_fibre=(TH1F*)file->Get("maxAmpl_sel_fibre");
    TH1F* maxAmpl_sel_channel=(TH1F*)file->Get("maxAmpl_sel_channel");

    TCanvas c2;
    maxAmpl_sel_channel->GetXaxis()->SetRangeUser(0,800.);
    maxAmpl_sel_channel->SetLineWidth(2);
    maxAmpl_sel_fibre->SetLineWidth(2);
    maxAmpl_sel_channel->DrawNormalized();
    maxAmpl_sel_fibre->DrawNormalized("same");



    TPaveText* pave = DrawTools::getLabelTop_expOnXaxis("Electron Beam");
    pave->Draw("same");
    
    c2.SaveAs(dir+"/maxAmpl_comparison.pdf");
    c2.SaveAs(dir+"/maxAmpl_comparison.png");



}
コード例 #5
0
int main(int argc, char* argv[]){
TApplication* a = new TApplication("a", 0, 0);
 TStyle* style=  DrawTools::setStyle();
 style->cd();

  std::string outputdir = "CalibComparisonPlots/";
  std::string mkdir_command = "mkdir -p " + outputdir;
  system( mkdir_command.c_str() );

  std::string runName0 = "BTF_259_20140502-012847_beam";
  std::string runName1 = "BTF_259_20140502-012847_beam";
  std::string runName2 = "BTF_259_20140502-012847_beam";
  std::string runName3 = "BTF_259_20140502-012847_beam";
  std::string runName4 = "BTF_259_20140502-012847_beam";


  //std::string tag = "default";
  std::string tag = "V03";

  std::string inputDir = "./CeF3Calibration";


  if( argc == 5 ) {
    std::string runName_str0(argv[1]);
    runName0 = runName_str0;
    std::string runName_str1(argv[2]);
    runName1 = runName_str1;
    std::string runName_str2(argv[3]);
    runName2 = runName_str2;
    std::string tag_str(argv[4]);
    tag = tag_str;
  } else if(argc == 7){
       std::string runName_str0(argv[1]);
    runName0 = runName_str0;
    std::string runName_str1(argv[2]);
    runName1 = runName_str1;
    std::string runName_str2(argv[3]);
    runName2 = runName_str2;
    std::string runName_str3(argv[4]);
    runName3 = runName_str3;
    std::string runName_str4(argv[5]);
    runName4 = runName_str4;
    std::string tag_str(argv[6]);
    tag = tag_str;
  } else{
    std::cout<<"Usage:"<<std::endl;
    std::cout<<"./calibrateCef3 BTF_XX BTF_XX BTF_XX tag "<<std::endl;
    exit(12345);
  }




TCanvas* canny = new TCanvas("canny", "",200,200);
 canny->cd();

  ifstream in;

  float x;
  int nlines;
  TNtuple *ntuple = new TNtuple("ntuple","data from .txt file", "x");

  double corr0[4];
  double corr_uncert0[4];
  double corr1[4];
  double corr_uncert1[4];
  double corr2[4];
  double corr_uncert2[4];
  double corr3[4];
  double corr_uncert3[4];
  double corr4[4];
  double corr_uncert4[4];

 
    int const ntot = 10;
    TString openname[ntot] = {
      Form("%s/constants_%s_%s.txt",inputDir.c_str(),runName0.c_str(), tag.c_str() ), Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(),runName0.c_str(), tag.c_str()),   Form("%s/constants_%s_%s.txt", inputDir.c_str(),runName1.c_str(), tag.c_str()), Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(),runName1.c_str(), tag.c_str()),   Form("%s/constants_%s_%s.txt",inputDir.c_str(), runName2.c_str(), tag.c_str() ),Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(), runName2.c_str(), tag.c_str() ),  Form("%s/constants_%s_%s.txt", inputDir.c_str(), runName3.c_str(), tag.c_str() ), Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(), runName3.c_str(), tag.c_str() ),     Form("%s/constants_%s_%s.txt", inputDir.c_str(), runName4.c_str(), tag.c_str() ),Form("%s/constants_uncert_%s_%s.txt", inputDir.c_str(), runName4.c_str(), tag.c_str() ) };


  for(int i=0; i<ntot+1; ++i){

    in.open(openname[i-1]);


    while (nlines<4) {
      in>>x;
      if(!in.good()) break;
      ntuple->Fill(x);
      nlines++;
    }

in.close();
 nlines=0;
}

    ntuple->SetBranchAddress("x",&x);

    for(int j=0; j<4; ++j){
      ntuple->GetEntry(j);
      corr0[j]= x;
      ntuple->GetEntry(j+4);
      corr_uncert0[j]=x;

      ntuple->GetEntry(j+8);
      corr1[j]= x;
      ntuple->GetEntry(j+12);
      corr_uncert1[j]=x;

      ntuple->GetEntry(j+16);
      corr2[j]= x;
      ntuple->GetEntry(j+20);
      corr_uncert2[j]=x;

      if(argc==7){

      ntuple->GetEntry(j+24);
      corr3[j]= x;
      ntuple->GetEntry(j+28);
      corr_uncert3[j]=x;

      ntuple->GetEntry(j+32);
      corr4[j]= x;
      ntuple->GetEntry(j+36);
      corr_uncert4[j]=x;
}
    }



  double ch0[4] = {-0.1,0.9,1.9,2.9};
  double ch1[4]={-0.05,0.95,1.95, 2.95};
  double ch2[4] = {0,1,2,3};
  double ch3[4] = {0.05,1.05,2.05,3.05};
  double ch4[4] ={0.1,1.1,2.1,3.1};
  double cherr[4]={0,0,0,0};


  TGraphErrors* graf0 = new TGraphErrors(4,ch0,corr0,cherr,corr_uncert0);
  graf0->SetMarkerStyle(9);
  graf0->SetMarkerSize(0.5);
  graf0->SetMarkerColor(kGreen+1);
  TGraphErrors* graf1 = new TGraphErrors(4,ch1,corr1,cherr,corr_uncert1);
  graf1->SetMarkerStyle(9);
  graf1->SetMarkerSize(0.5);
  graf1->SetMarkerColor(kBlue);
  TGraphErrors* graf2 = new TGraphErrors(4,ch2,corr2,cherr,corr_uncert2);
  graf2->SetMarkerStyle(9);
  graf2->SetMarkerSize(0.5);
  graf2->SetMarkerColor(kMagenta);



TMultiGraph *multi=new TMultiGraph();
 multi->Add(graf0); multi->Add(graf1); multi->Add(graf2);


 TLegend* leg = new TLegend(0.7, 0.7, 0.9, 0.9);

 if(argc==5){
  leg->AddEntry(graf0,"Run 92","P");
  leg->AddEntry(graf1,"Run 246","P");
  leg->AddEntry(graf2,"Run 259","P");


 multi->SetTitle(";Channel Nr.;Correction Factor");
  multi->Draw("AP");
  multi->GetYaxis()->SetRangeUser(0.975,1.025);
  multi->GetXaxis()->SetNdivisions(4);




}


  if(argc==7){ 
  graf1->SetMarkerColor(kCyan+1);
  graf2->SetMarkerColor(kBlue);
 
  TGraphErrors* graf3 = new TGraphErrors(4,ch3,corr3,cherr,corr_uncert3);
  graf3->SetMarkerStyle(9);
  graf3->SetMarkerSize(0.5);
  graf3->SetMarkerColor(kViolet-1);
  TGraphErrors* graf4 = new TGraphErrors(4,ch4,corr4,cherr,corr_uncert4);
  graf4->SetMarkerStyle(9);
  graf4->SetMarkerSize(0.5);
  graf4->SetMarkerColor(kPink+7);


multi->Add(graf3); 
multi->Add(graf4);
multi->SetTitle(";Channel Nr.;Correction Factor");


 multi->Draw("AP");

  leg->AddEntry(graf0,"98.3 MeV","P");
  leg->AddEntry(graf1,"147.4 MeV","P");
  leg->AddEntry(graf2,"196.5 MeV","P");
  leg->AddEntry(graf3,"294.8 MeV","P");
  leg->AddEntry(graf4,"491.4 MeV","P");

  //multi->GetYaxis()->SetRangeUser(0.9,1.1);



  multi->GetXaxis()->SetNdivisions(4);


  }



 multi->SetTitle(";Channel Nr.;Correction Factor");




multi->Draw("AP");
canny->Update();



  leg->SetFillColor(0);
  leg->Draw("same");

  TLine* lin = new TLine(-0.25,1.,3.25,1.);
  lin->SetLineColor(kRed);
  lin->Draw();



  if(argc==5){canny->SaveAs( Form( "%s/comparison_%s.pdf", outputdir.c_str(), tag.c_str() ));
  }  else if(argc==7){  canny->SaveAs( Form( "%s/comparison_energy_%s.pdf", outputdir.c_str(), tag.c_str() ));}

 delete canny;

return 0;
}
コード例 #6
0
int main( int argc, char* argv[]) {


  std::string tag = "V00";
  if( argc>1 ) {
    std::string tag_str(argv[1]);
    tag = tag_str;
  }

  DrawTools::setStyle();

  TFile* file_mc = TFile::Open("EEShash_491MeV_10000ev_smear.root");

  TFile* file_data = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_259_beam.root", tag.c_str()));

  TTree* tree_data = (TTree*)file_data->Get("posTree");
  TTree* tree_mc = (TTree*)file_mc->Get("EEShash");

  std::string outputdir = "ResolutionStudiesPlots_"+tag;
  std::string mkdir_command = "mkdir -p " + outputdir;
  system( mkdir_command.c_str() );
  
  TF1* f1_data = FitTools::fitSingleElectronPeak( outputdir, "data", tree_data );

  ResoStruct rs_data = getRespAndReso(f1_data, 0.01);



  float LYSF_ideal[] = {1., 1., 1., 1., 1., 1., 1., 1., 1., 1.};
  float LYSF_real [] = {0.85, 0.94, 0.95, 0.98, 1.00, 1.02, 1.05, 1.05, 1.05, 0.74};
  float LYSF_hole [] = {0.85, 0.94, 0.95, 0.98, 1.00, 0.00, 1.05, 1.05, 1.05, 0.74};

  ResoStruct rs_ideal = getResponseResolutionMC( outputdir, tree_mc, LYSF_ideal, "ideal" );
  ResoStruct rs_real  = getResponseResolutionMC( outputdir, tree_mc, LYSF_real, "real" );
  ResoStruct rs_hole  = getResponseResolutionMC( outputdir, tree_mc, LYSF_hole, "hole" );
  
  std::cout << std::endl;
  std::cout << "* DATA: " << std::endl;
  std::cout << "reso: " << rs_data.reso << " +/- " << rs_data.reso_error << std::endl;
  std::cout << "Sres: " << rs_data.Sres << " +/- " << rs_data.Sres_error << std::endl;
  
  std::cout << "MC reso ideal: "<< rs_ideal.reso << " +/- " << rs_ideal.reso_error << std::endl;
  std::cout << "MC reso real: " << rs_real .reso << " +/- " << rs_real .reso_error << std::endl;
  std::cout << "MC reso hole: " << rs_hole .reso << " +/- " << rs_hole .reso_error << std::endl;

  std::cout << "MC Sres ideal: " << rs_ideal.Sres << " +/- " << rs_ideal.Sres_error << std::endl;
  std::cout << "MC Sres real: "  << rs_real .Sres << " +/- " << rs_real .Sres_error << std::endl;
  std::cout << "MC Sres hole: "  << rs_hole .Sres << " +/- " << rs_hole .Sres_error << std::endl;

  std::cout << std::endl;
  std::cout << "-> Adding photostatistics to MC (25% QE): " << std::endl;
  ResoStruct rs_ideal_ps = addPhotoStatistics( rs_ideal, 0.25 );
  ResoStruct rs_real_ps  = addPhotoStatistics( rs_real, 0.25 );
  ResoStruct rs_hole_ps  = addPhotoStatistics( rs_hole, 0.25 );
  
  std::cout << "MC reso ideal: "<< rs_ideal_ps.reso << " +/- " << rs_ideal_ps.reso_error << std::endl;
  std::cout << "MC reso real: " << rs_real_ps .reso << " +/- " << rs_real_ps .reso_error << std::endl;
  std::cout << "MC reso hole: " << rs_hole_ps .reso << " +/- " << rs_hole_ps .reso_error << std::endl;

  std::cout << "MC Sres ideal: " << rs_ideal_ps.Sres << " +/- " << rs_ideal_ps.Sres_error << std::endl;
  std::cout << "MC Sres real: "  << rs_real_ps .Sres << " +/- " << rs_real_ps .Sres_error << std::endl;
  std::cout << "MC Sres hole: "  << rs_hole_ps .Sres << " +/- " << rs_hole_ps .Sres_error << std::endl;


  std::cout << "-> Adding photostatistics to MC (15% QE): " << std::endl;
  rs_ideal_ps = addPhotoStatistics( rs_ideal, 0.15 );
  rs_real_ps  = addPhotoStatistics( rs_real, 0.15 );
  rs_hole_ps  = addPhotoStatistics( rs_hole, 0.15 );
  
  std::cout << "MC reso ideal: "<< rs_ideal_ps.reso << " +/- " << rs_ideal_ps.reso_error << std::endl;
  std::cout << "MC reso real: " << rs_real_ps .reso << " +/- " << rs_real_ps .reso_error << std::endl;
  std::cout << "MC reso hole: " << rs_hole_ps .reso << " +/- " << rs_hole_ps .reso_error << std::endl;

  std::cout << "MC Sres ideal: " << rs_ideal_ps.Sres << " +/- " << rs_ideal_ps.Sres_error << std::endl;
  std::cout << "MC Sres real: "  << rs_real_ps .Sres << " +/- " << rs_real_ps .Sres_error << std::endl;
  std::cout << "MC Sres hole: "  << rs_hole_ps .Sres << " +/- " << rs_hole_ps .Sres_error << std::endl;


  



  // FIRST: DIAGONAL13 SCAN

  TFile* file_mc_3x3y = TFile::Open("EEShash_491MeV_10000ev_smear_3x3y.root");
  TFile* file_mc_6x6y = TFile::Open("EEShash_491MeV_10000ev_smear_6x6y.root");
  TFile* file_mc_9x9y = TFile::Open("EEShash_491MeV_10000ev_smear_9x9y.root");
  TFile* file_mc_11p3x11p3y = TFile::Open("EEShash_491MeV_10000ev_smear_11p3x11p3y.root");

  TTree* tree_mc_3x3y = (TTree*)file_mc_3x3y->Get("EEShash");
  TTree* tree_mc_6x6y = (TTree*)file_mc_6x6y->Get("EEShash");
  TTree* tree_mc_9x9y = (TTree*)file_mc_9x9y->Get("EEShash");
  TTree* tree_mc_11p3x11p3y = (TTree*)file_mc_11p3x11p3y->Get("EEShash");

  //TFile* file_data_3x3y       = TFile::Open("AnalysisTrees_V00/Reco_BTF_141_20140430-183508_beam.root");
  //TFile* file_data_6x6y       = TFile::Open("AnalysisTrees_V00/Reco_BTF_143_20140430-191455_beam.root");
  //TFile* file_data_9x9y       = TFile::Open("AnalysisTrees_V00/Reco_BTF_167_20140430-210839_beam.root");
  //TFile* file_data_11p3x11p3y = TFile::Open("AnalysisTrees_V00/Reco_BTF_219_20140501-092151_beam.root");

  //TTree* tree_data_3x3y = (TTree*)file_data_3x3y->Get("recoTree");
  //TTree* tree_data_6x6y = (TTree*)file_data_6x6y->Get("recoTree");
  //TTree* tree_data_9x9y = (TTree*)file_data_9x9y->Get("recoTree");
  //TTree* tree_data_11p3x11p3y = (TTree*)file_data_11p3x11p3y->Get("recoTree");

  TFile* file_data_3x3y       = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_141_beam.root", tag.c_str()));
  TFile* file_data_6x6y       = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_143_beam.root", tag.c_str()));
  TFile* file_data_9x9y       = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_167_beam.root", tag.c_str()));
  TFile* file_data_11p3x11p3y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_219_beam.root", tag.c_str()));

  TTree* tree_data_3x3y = (TTree*)file_data_3x3y->Get("posTree");
  TTree* tree_data_6x6y = (TTree*)file_data_6x6y->Get("posTree");
  TTree* tree_data_9x9y = (TTree*)file_data_9x9y->Get("posTree");
  TTree* tree_data_11p3x11p3y = (TTree*)file_data_11p3x11p3y->Get("posTree");

  std::vector<LateralScanStruct> lss_diag;
  lss_diag.push_back( LateralScanStruct(0., tree_data, tree_mc) );
  lss_diag.push_back( LateralScanStruct(3.*sqrt(2.), tree_data_3x3y, tree_mc_3x3y) );
  lss_diag.push_back( LateralScanStruct(6.*sqrt(2.), tree_data_6x6y, tree_mc_6x6y) );
  lss_diag.push_back( LateralScanStruct(9.*sqrt(2.), tree_data_9x9y, tree_mc_9x9y) );
  lss_diag.push_back( LateralScanStruct(11.3*sqrt(2.), tree_data_11p3x11p3y, tree_mc_11p3x11p3y) );

  std::string fullVarName_mc = getVarName(LYSF_hole);
  drawLateralScan( outputdir, "diag13", lss_diag, "Diagonal", fullVarName_mc );



  // SECOND: DIAGONAL02 SCAN

  //TFile* file_data_d02_3x3y       = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_94_beam.root", tag.c_str()));
  //TFile* file_data_d02_6x6y       = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_96_beam.root", tag.c_str()));
  //TFile* file_data_d02_9x9y       = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_98_beam.root", tag.c_str()));
  //TFile* file_data_d02_m9xm9y     = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_171_beam.root", tag.c_str()));
  //TFile* file_data_d02_m6xm6y     = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_173_beam.root", tag.c_str()));
  //TFile* file_data_d02_m3xm3y     = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_176_beam.root", tag.c_str()));

  TFile* file_data_d02_9x9y     = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_171_beam.root", tag.c_str()));
  TFile* file_data_d02_6x6y     = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_173_beam.root", tag.c_str()));
  TFile* file_data_d02_3x3y     = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_176_beam.root", tag.c_str()));

  TTree* tree_data_d02_3x3y   = (TTree*)file_data_d02_3x3y->Get("posTree");
  TTree* tree_data_d02_6x6y   = (TTree*)file_data_d02_6x6y->Get("posTree");
  TTree* tree_data_d02_9x9y   = (TTree*)file_data_d02_9x9y->Get("posTree");
  //TTree* tree_data_d02_m3xm3y = (TTree*)file_data_d02_m3xm3y->Get("posTree");
  //TTree* tree_data_d02_m6xm6y = (TTree*)file_data_d02_m6xm6y->Get("posTree");
  //TTree* tree_data_d02_m9xm9y = (TTree*)file_data_d02_m9xm9y->Get("posTree");

  std::vector<LateralScanStruct> lss_diag02;
  lss_diag02.push_back( LateralScanStruct(0.,  tree_data, tree_mc) );
  lss_diag02.push_back( LateralScanStruct(3.*sqrt(2.),  tree_data_d02_3x3y, tree_mc_3x3y) );
  lss_diag02.push_back( LateralScanStruct(6.*sqrt(2.),  tree_data_d02_6x6y, tree_mc_6x6y) );
  lss_diag02.push_back( LateralScanStruct(9.*sqrt(2.),  tree_data_d02_9x9y, tree_mc_9x9y) );
  //lss_diag02.push_back( LateralScanStruct(-3.*sqrt(2.), tree_data_d02_m3xm3y, tree_mc_3x3y) );
  //lss_diag02.push_back( LateralScanStruct(-6.*sqrt(2.), tree_data_d02_m6xm6y, tree_mc_6x6y) );
  //lss_diag02.push_back( LateralScanStruct(-9.*sqrt(2.), tree_data_d02_m9xm9y, tree_mc_9x9y) );

  drawLateralScan( outputdir, "diag02", lss_diag02, "Diagonal", fullVarName_mc );




  // THIRD: HORIZONTAL SCAN


  TFile* file_mc_2x0y  = TFile::Open("EEShash_491MeV_10000ev_smear_2x0y.root");
  TFile* file_mc_4x0y  = TFile::Open("EEShash_491MeV_10000ev_smear_4x0y.root");
  TFile* file_mc_6x0y  = TFile::Open("EEShash_491MeV_10000ev_smear_6x0y.root");
  TFile* file_mc_8x0y  = TFile::Open("EEShash_491MeV_10000ev_smear_8x0y.root");
  TFile* file_mc_10x0y = TFile::Open("EEShash_491MeV_10000ev_smear_10x0y.root");
  TFile* file_mc_12x0y = TFile::Open("EEShash_491MeV_10000ev_smear_12x0y.root");

  TTree* tree_mc_2x0y    = (TTree*)file_mc_2x0y ->Get("EEShash");
  TTree* tree_mc_4x0y    = (TTree*)file_mc_4x0y ->Get("EEShash");  
  TTree* tree_mc_6x0y    = (TTree*)file_mc_6x0y ->Get("EEShash");
  TTree* tree_mc_8x0y    = (TTree*)file_mc_8x0y ->Get("EEShash");
  TTree* tree_mc_10x0y   = (TTree*)file_mc_10x0y->Get("EEShash");
  TTree* tree_mc_12x0y   = (TTree*)file_mc_12x0y->Get("EEShash");

  TFile* file_data_12x0y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_144_20140430-200741_beam.root", tag.c_str()));
  TFile* file_data_10x0y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_145_20140430-201024_beam.root", tag.c_str()));
  TFile* file_data_8x0y   = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_146_20140430-201243_beam.root", tag.c_str()));
  TFile* file_data_6x0y   = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_147_20140430-201509_beam.root", tag.c_str()));
  TFile* file_data_4x0y   = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_148_20140430-201719_beam.root", tag.c_str()));
  TFile* file_data_2x0y   = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_149_20140430-201913_beam.root", tag.c_str()));
  TFile* file_data_m2x0y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_151_20140430-202639_beam.root", tag.c_str()));
  TFile* file_data_m4x0y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_152_20140430-202852_beam.root", tag.c_str()));
  TFile* file_data_m6x0y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_153_20140430-203054_beam.root", tag.c_str()));
  TFile* file_data_m8x0y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_154_20140430-203255_beam.root", tag.c_str()));
  TFile* file_data_m10x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_155_20140430-203551_beam.root", tag.c_str()));
  TFile* file_data_m12x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_156_20140430-203818_beam.root", tag.c_str()));

  TTree* tree_data_2x0y    = (TTree*)file_data_2x0y  ->Get("posTree");
  TTree* tree_data_4x0y    = (TTree*)file_data_4x0y  ->Get("posTree");  
  TTree* tree_data_6x0y    = (TTree*)file_data_6x0y  ->Get("posTree");
  TTree* tree_data_8x0y    = (TTree*)file_data_8x0y  ->Get("posTree");
  TTree* tree_data_10x0y   = (TTree*)file_data_10x0y ->Get("posTree");
  TTree* tree_data_12x0y   = (TTree*)file_data_12x0y ->Get("posTree");
  TTree* tree_data_m2x0y   = (TTree*)file_data_m2x0y ->Get("posTree");
  TTree* tree_data_m4x0y   = (TTree*)file_data_m4x0y ->Get("posTree");  
  TTree* tree_data_m6x0y   = (TTree*)file_data_m6x0y ->Get("posTree");
  TTree* tree_data_m8x0y   = (TTree*)file_data_m8x0y ->Get("posTree");
  TTree* tree_data_m10x0y  = (TTree*)file_data_m10x0y->Get("posTree");
  TTree* tree_data_m12x0y  = (TTree*)file_data_m12x0y->Get("posTree");

  std::vector<LateralScanStruct> lss_horiz;
  lss_horiz.push_back( LateralScanStruct(0., tree_data, tree_mc) );
  lss_horiz.push_back( LateralScanStruct(2., tree_data_2x0y, tree_mc_2x0y) );
  lss_horiz.push_back( LateralScanStruct(4., tree_data_4x0y, tree_mc_4x0y) );
  lss_horiz.push_back( LateralScanStruct(6., tree_data_6x0y, tree_mc_6x0y) );
  lss_horiz.push_back( LateralScanStruct(8., tree_data_8x0y, tree_mc_8x0y) );
  lss_horiz.push_back( LateralScanStruct(10., tree_data_10x0y, tree_mc_10x0y) );
  lss_horiz.push_back( LateralScanStruct(12., tree_data_12x0y, tree_mc_12x0y) );
  lss_horiz.push_back( LateralScanStruct(-2., tree_data_m2x0y, tree_mc_2x0y) );
  lss_horiz.push_back( LateralScanStruct(-4., tree_data_m4x0y, tree_mc_4x0y) );
  lss_horiz.push_back( LateralScanStruct(-6., tree_data_m6x0y, tree_mc_6x0y) );
  lss_horiz.push_back( LateralScanStruct(-8., tree_data_m8x0y, tree_mc_8x0y) );
  lss_horiz.push_back( LateralScanStruct(-10., tree_data_m10x0y, tree_mc_10x0y) );
  lss_horiz.push_back( LateralScanStruct(-12., tree_data_m12x0y, tree_mc_12x0y) );

  drawLateralScan( outputdir, "horiz", lss_horiz, "Horizontal", fullVarName_mc );







  // FOURTH: VERTICAL SCAN


  TFile* file_data_0x2y   = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_160_20140430-204719_beam.root", tag.c_str()));
  TFile* file_data_0x4y   = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_159_20140430-204525_beam.root", tag.c_str()));
  TFile* file_data_0x6y   = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_158_20140430-204306_beam.root", tag.c_str()));
  TFile* file_data_0x8y   = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_157_20140430-204053_beam.root", tag.c_str()));
  TFile* file_data_0xm2y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_162_20140430-205129_beam.root", tag.c_str()));
  TFile* file_data_0xm4y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_163_20140430-205337_beam.root", tag.c_str()));
  TFile* file_data_0xm6y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_164_20140430-205542_beam.root", tag.c_str()));
  TFile* file_data_0xm8y  = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_165_20140430-205756_beam.root", tag.c_str()));

  TTree* tree_data_0x2y  = (TTree*)file_data_0x2y ->Get("posTree");
  TTree* tree_data_0x4y  = (TTree*)file_data_0x4y ->Get("posTree");  
  TTree* tree_data_0x6y  = (TTree*)file_data_0x6y ->Get("posTree");
  TTree* tree_data_0x8y  = (TTree*)file_data_0x8y ->Get("posTree");
  TTree* tree_data_0xm2y  = (TTree*)file_data_0xm2y ->Get("posTree");
  TTree* tree_data_0xm4y  = (TTree*)file_data_0xm4y ->Get("posTree");  
  TTree* tree_data_0xm6y  = (TTree*)file_data_0xm6y ->Get("posTree");
  TTree* tree_data_0xm8y  = (TTree*)file_data_0xm8y ->Get("posTree");

  std::vector<LateralScanStruct> lss_vert;
  lss_vert.push_back( LateralScanStruct(0.,  tree_data, tree_mc) );
  lss_vert.push_back( LateralScanStruct(2.,  tree_data_0x2y, tree_mc_2x0y) );
  lss_vert.push_back( LateralScanStruct(4.,  tree_data_0x4y, tree_mc_4x0y) );
  lss_vert.push_back( LateralScanStruct(6.,  tree_data_0x6y, tree_mc_6x0y) );
  lss_vert.push_back( LateralScanStruct(8.,  tree_data_0x8y, tree_mc_8x0y) );
  lss_vert.push_back( LateralScanStruct(-2., tree_data_0xm2y, tree_mc_2x0y) );
  lss_vert.push_back( LateralScanStruct(-4., tree_data_0xm4y, tree_mc_4x0y) );
  lss_vert.push_back( LateralScanStruct(-6., tree_data_0xm6y, tree_mc_6x0y) );
  lss_vert.push_back( LateralScanStruct(-8., tree_data_0xm8y, tree_mc_8x0y) );

  drawLateralScan( outputdir, "vert", lss_vert, "Vertical", fullVarName_mc );

  return 0;

}
コード例 #7
0
ファイル: drawResolution.cpp プロジェクト: CeF3TB/H4_2015
int main( int argc, char* argv[] ) {


  DrawTools::setStyle();
  std::vector<float> energies;
  std::vector<float> reso;
  std::vector<float> resoErr;
  std::vector<int> runs;

  energies.push_back(20);
  energies.push_back(50);
  energies.push_back(100);
  energies.push_back(150);
  energies.push_back(200);
  energies.push_back(250);

  //HV 1450
  runs.push_back(2851);
  runs.push_back(2801);
  runs.push_back(2778);
  runs.push_back(2822);
  runs.push_back(2872);
  runs.push_back(2894);


//HV 1050
//  runs.push_back(2864);
//  runs.push_back(2814);
//  runs.push_back(2795);
//  runs.push_back(2849);
//  runs.push_back(2885);
//  runs.push_back(2907);
  
  std::string tag = "V00";
  if( argc>1 ) {
    std::string tag_str(argv[1]);
    tag = tag_str;
  }

  TGraphErrors* gr_reso_vs_energy[5];
  TGraphErrors* gr_resoMaxAmplFit_vs_energy[5];
  for(int i=0;i<5;++i) {
    gr_reso_vs_energy[i]= new TGraphErrors(0);
    gr_resoMaxAmplFit_vs_energy[i]= new TGraphErrors(0);
  }

  std::string outdir = "plots_reso_" + tag;
  system( Form("mkdir -p %s", outdir.c_str()) );

  float sigma_noise[5];//sigma of maxAmpl in pedestal events
//  sigma_noise[0]=2.47;
//  sigma_noise[1]=2.54;
//  sigma_noise[2]=2.19;
//  sigma_noise[3]=2.15;
  sigma_noise[0]=1.78;
  sigma_noise[1]=1.24;
  sigma_noise[2]=1.66;
  sigma_noise[3]=1.05;
  sigma_noise[4]=sqrt(2.49*2.49*sigma_noise[0]*sigma_noise[0]+0.81*0.81*sigma_noise[1]*sigma_noise[1]+16.8*16.8*sigma_noise[2]*sigma_noise[2]+0.73*0.73*sigma_noise[3]*sigma_noise[3]);//weighted mean of sigmas with intercalib of V03 //FIXME, don't do it hardcoded
  bool subtract_noise=true;

  for (int i=0;i<runs.size();++i){
    TString run;
    run.Form("%d",runs[i]); 
    
       

    TFile *inputFile=TFile::Open("CherenkovPlots_"+run+"_"+tag.c_str()+".root");
    TVectorD* res=(TVectorD*)inputFile->Get("resValueMaxAmpl");
    TVectorD* resErr=(TVectorD*)inputFile->Get("resErrValueMaxAmpl");

    TVectorD* meanValuemaxAmpl_fit=(TVectorD*)inputFile->Get("meanValuemaxAmpl_fit");

    TVectorD* resMaxAmplFit=(TVectorD*)inputFile->Get("resValuemaxAmpl_fit");
    TVectorD* resErrMaxAmplFit=(TVectorD*)inputFile->Get("resErrValuemaxAmpl_fit");

    for(int j=0;j<5;++j){
      gr_reso_vs_energy[j]->SetPoint( i, energies[i], (*res)[j] );
      gr_reso_vs_energy[j]->SetPointError( i, 0, (*resErr)[j] );

      if(!subtract_noise){
	gr_resoMaxAmplFit_vs_energy[j]->SetPoint( i, energies[i], (*resMaxAmplFit)[j] );
	gr_resoMaxAmplFit_vs_energy[j]->SetPointError( i, 0, (*resErrMaxAmplFit)[j] );
      }else{
	std::cout<<"run:"<<runs[i]<<" res_original:"<<(*resMaxAmplFit)[j]<<" sigma_noise:"<<sigma_noise[j]<<" final:"<<sqrt((*resMaxAmplFit)[j]*(*resMaxAmplFit)[j]-100*sigma_noise[j]/(*meanValuemaxAmpl_fit)[j]*100*sigma_noise[j]/(*meanValuemaxAmpl_fit)[j])<<" mean:"<<(*meanValuemaxAmpl_fit)[j]<<std::endl;
	gr_resoMaxAmplFit_vs_energy[j]->SetPoint( i, energies[i], sqrt((*resMaxAmplFit)[j]*(*resMaxAmplFit)[j]-100*sigma_noise[j]/(*meanValuemaxAmpl_fit)[j]*100*sigma_noise[j]/(*meanValuemaxAmpl_fit)[j]) );
	gr_resoMaxAmplFit_vs_energy[j]->SetPointError( i, 0, (*resErrMaxAmplFit)[j] );
      }

    }
  }

  for(int i=0;i<5;++i){
    TString fibre;
    fibre.Form("%d",i); 

    if(gr_reso_vs_energy[i]){
      TCanvas* c1 = new TCanvas( "c1", "", 600, 600 );
      c1->cd();
      TH2D* h2_axes2 = new TH2D( "axes", "", 100, -0.0, 305. , 10, 0.0, 25 );
      h2_axes2->SetXTitle("Beam Energy [GeV]");
      h2_axes2->SetYTitle("Energy Resolution [%]");
      h2_axes2->Draw("");
      
      gr_reso_vs_energy[i]->SetMarkerStyle(20);
      gr_reso_vs_energy[i]->SetMarkerSize(1.6);
      gr_reso_vs_energy[i]->SetMarkerColor(kBlue);
      gr_reso_vs_energy[i]->Draw("p same");

      //              TF1 *fun= new TF1("fun","sqrt([0]*[0]/(x*x)+[1]*[1])",1, 250.+15.);
      //            TF1 *fun= new TF1("fun","sqrt([0]*[0]/x+[1]*[1])",1, 250.+15.);
            TF1 *fun= new TF1("fun",  "sqrt([0]*[0]/x+[1]*[1]+ [2]*[2]/(x*x))",1, 250+5.);
      fun->SetParameter(1, 4.);
      fun->SetParameter(0, 20.);
      fun->SetParameter(2, 20.);
      gr_reso_vs_energy[i]->Fit(fun,"RN");
      fun->SetLineWidth(1.);
      fun->SetLineColor(kBlue+2);
      fun->Draw("L same");

      TLegend* leg_neat = new TLegend(0.4, 0.92-0.06*5 , 0.8, 0.92);
      leg_neat->SetTextSize(0.038);
      std::string ene="Data fibre ";
      //  ene+=Form("%.0f",energies[i]);
      //    ene+=" GeV";
      ene+=fibre;
      if(i!=4)    leg_neat->AddEntry(gr_reso_vs_energy[i],ene.c_str(),"p");
      else leg_neat->AddEntry(gr_reso_vs_energy[i],"Data CeF_{3}","p");
      //      leg_neat->AddEntry((TObject*)0 ,Form("S =  %.2f\n%s #pm %.2f / #sqrt{E [GeV]}",fun->GetParameter(0),"%",fun->GetParError(0) ),"");
      leg_neat->AddEntry((TObject*)0 ,Form("S =  %.2f\n%s #pm %.2f",fun->GetParameter(0),"%",fun->GetParError(0) ),"");
      leg_neat->AddEntry( (TObject*)0 ,Form("C =  %.2f\n%s  #pm %.2f",(fun->GetParameter(1)) ,"%",fun->GetParError(1) ),"");
      leg_neat->AddEntry( (TObject*)0 ,Form("N =  %.2f\n%s #pm %.2f",(fun->GetParameter(2))/100 ," GeV" ,fun->GetParError(2)/100),"");
      leg_neat->SetFillColor(0);
      leg_neat->Draw("same");
      std::cout<<"parameters: S="<<fun->GetParameter(0)<<" C="<<fun->GetParameter(1)<<" N="<<fun->GetParameter(2)<<std::endl;


      c1->SaveAs(outdir+"/reso_HV1450_"+fibre+".png");
      c1->SaveAs(outdir+"/reso_HV1450_"+fibre+".pdf");
    }

    if(gr_resoMaxAmplFit_vs_energy[i]){
      TCanvas* c1 = new TCanvas( "c1", "", 600, 600 );
      c1->cd();
      TH2D* h2_axes2 = new TH2D( "axes", "", 100, -0.0, 305. , 10, 0.0, 25 );
      h2_axes2->SetXTitle("Beam Energy [GeV]");
      h2_axes2->SetYTitle("Energy Resolution [%]");
      h2_axes2->Draw("");
      
      gr_resoMaxAmplFit_vs_energy[i]->SetMarkerStyle(20);
      gr_resoMaxAmplFit_vs_energy[i]->SetMarkerSize(1.6);
      gr_resoMaxAmplFit_vs_energy[i]->SetMarkerColor(kBlue);
      gr_resoMaxAmplFit_vs_energy[i]->Draw("p same");

      //              TF1 *fun= new TF1("fun","sqrt([0]*[0]/(x*x)+[1]*[1])",1, 250.+15.);
                  TF1 *fun= new TF1("fun","sqrt([0]*[0]/x+[1]*[1])",1, 250.+15.);
      //      TF1 *fun= new TF1("fun",  "sqrt([0]*[0]/x+[1]*[1]+ [2]*[2]/(x*x))",1, 250+5.);
      fun->SetParameter(1, 4.);
      fun->SetParameter(0, 20.);
      fun->SetParameter(2, 20.);
      gr_resoMaxAmplFit_vs_energy[i]->Fit(fun,"RN");
      fun->SetLineWidth(1.);
      fun->SetLineColor(kBlue+2);
      fun->Draw("L same");


      TLegend* leg_neat = new TLegend(0.42, 0.89-0.06*3.5 , 0.85, 0.89);
      leg_neat->SetTextSize(0.038);
      std::string ene="Data fibre ";
      //  ene+=Form("%.0f",energies[i]);
      //    ene+=" GeV";
      ene+=fibre;
      if(i!=4)    leg_neat->AddEntry(gr_resoMaxAmplFit_vs_energy[i],ene.c_str(),"p");
      else leg_neat->AddEntry(gr_resoMaxAmplFit_vs_energy[i],"Data CeF_{3}","p");
      //leg_neat->AddEntry((TObject*)0 ,Form("S =  %.2f\n%s / #sqrt{E [GeV]}",fun->GetParameter(0),"%" ),"");
      leg_neat->AddEntry((TObject*)0 ,Form("S =  %.2f\n%s #pm %.2f",fun->GetParameter(0),"%",fun->GetParError(0) ),"");
      leg_neat->AddEntry( (TObject*)0 ,Form("C =  %.2f\n%s  #pm %.2f",(fun->GetParameter(1)) ,"%",fun->GetParError(1) ),"");
      //      leg_neat->AddEntry( (TObject*)0 ,Form("N =  %.2f\n%s #pm %.2f",(fun->GetParameter(2))/100 ," GeV" ,fun->GetParError(2)/100),"");

      leg_neat->SetFillColor(0);
      leg_neat->Draw("same");
      std::cout<<"parameters: S="<<fun->GetParameter(0)<<" C="<<fun->GetParameter(1)<<" N="<<fun->GetParameter(2)<<std::endl;
      TPaveText* pave = DrawTools::getLabelTop_expOnXaxis("Electron Beam");
      pave->Draw("same");

      c1->SaveAs(outdir+"/reso_maxAmplFit_HV1450_"+fibre+".png");
      c1->SaveAs(outdir+"/reso_maxAmplFit_HV1450_"+fibre+".pdf");
    }

  }
  return 0;
}
コード例 #8
0
int main( int argc, char* argv[] ) {


  std::string runName = "precalib_BGO_pedestal_noSource";
  if( argc>1 ) {
    std::string runName_str(argv[1]);
    runName = runName_str;
  }

  std::string tag = "V00";
  if( argc>2 ) {
    std::string tag_str(argv[2]);
    tag = tag_str;
  }

  TString runName_tstr(runName);
  bool isOnlyRunNumber = !(runName_tstr.BeginsWith("BTF_"));


  TChain* tree = new TChain("recoTree");
  if( isOnlyRunNumber ) {
    std::cout << "-> We believe you are passing the program only the run number!" << std::endl;
    std::cout << "-> So for instance you are passing '246' for run 'BTF_246_20140501-212512_beam'" << std::endl;
    std::cout << "(if this is not the case this means TROUBLE)" << std::endl;
    std::cout << "-> Will look for runs matching run number: " << runName << std::endl;
    tree->Add(Form("analysisTrees_%s/Reco_BTF_%s_*beam.root/recoTree", tag.c_str(), runName.c_str()) );
    if( tree->GetEntries()==0 ) {
      std::cout << "WARNING! Didn't find any events matching run: " << runName << std::endl;
      std::cout << "Exiting" << std::endl;
      exit(1913);
    }
  } else {
    std::string fileName = "analysisTrees_"+tag+"/Reco_" + runName + ".root";
    TFile* file = TFile::Open(fileName.c_str());
    if( file==0 ) {
      std::cout << "ERROR! Din't find file " << fileName << std::endl;
      std::cout << "Exiting." << std::endl;
      exit(11);
    }
    tree = (TChain*)file->Get("recoTree");
  }

  UInt_t evtNumber;
  tree->SetBranchAddress( "evtNumber", &evtNumber );
  UInt_t adcData[40];
  tree->SetBranchAddress( "adcData", adcData );
  UInt_t adcBoard[40];
  tree->SetBranchAddress( "adcBoard", adcBoard );
  UInt_t adcChannel[40];
  tree->SetBranchAddress( "adcChannel", adcChannel );


  unsigned int runNumber;
  int nHodoFibersX;
  int nHodoFibersY;
  int nHodoClustersX;
  int nHodoClustersY;
  float cef3_corr[CEF3_CHANNELS];
  float bgo_corr[BGO_CHANNELS];
  float scintFront;
  float pos_hodoClustX[HODOX_CHANNELS];
  float pos_hodoClustY[HODOY_CHANNELS];
  int nFibres_hodoClustX[HODOX_CHANNELS];
  int nFibres_hodoClustY[HODOY_CHANNELS];
  float xBeam, yBeam;
  bool isSingleEle_scintFront;
  bool cef3_ok;
  bool cef3_corr_ok;
  bool bgo_ok;
  bool bgo_corr_ok;

  tree->SetBranchAddress( "runNumber", &runNumber );

  tree->SetBranchAddress( "scintFront", &scintFront );
  tree->SetBranchAddress( "cef3_corr", cef3_corr );
  tree->SetBranchAddress( "bgo_corr", bgo_corr );

  tree->SetBranchAddress( "nHodoFibersX", &nHodoFibersX );
  tree->SetBranchAddress( "nHodoFibersY", &nHodoFibersY );
  tree->SetBranchAddress( "nHodoClustersX", &nHodoClustersX );
  tree->SetBranchAddress( "pos_hodoClustX", pos_hodoClustX );
  tree->SetBranchAddress( "nFibres_hodoClustX", nFibres_hodoClustX );
  tree->SetBranchAddress( "nHodoClustersY", &nHodoClustersY );
  tree->SetBranchAddress( "pos_hodoClustY", pos_hodoClustY );
  tree->SetBranchAddress( "nFibres_hodoClustY", nFibres_hodoClustY );
  tree->SetBranchAddress( "scintFront", &scintFront );
  tree->SetBranchAddress( "isSingleEle_scintFront", &isSingleEle_scintFront );
  tree->SetBranchAddress( "xBeam", &xBeam );
  tree->SetBranchAddress( "yBeam", &yBeam );

  tree->SetBranchAddress( "cef3_ok", &cef3_ok );
  tree->SetBranchAddress( "cef3_corr_ok", &cef3_corr_ok );
  tree->SetBranchAddress( "bgo_ok", &bgo_ok );
  tree->SetBranchAddress( "bgo_corr_ok", &bgo_corr_ok );

  int nentries = tree->GetEntries();


  if( isOnlyRunNumber ) {
    // modify runname in such a way that it's useful for getBeamPosition and outfile:
    runName = "BTF_" + runName + "_beam";
  }

  std::string outputdir = "SingleElectronSelectionTrees_"+tag;
  system( Form("mkdir -p %s", outputdir.c_str()) );
  std::string outfileName = outputdir + "/SingleEleSelAn_" + runName + ".root";
  TFile* outfile = TFile::Open( outfileName.c_str(), "RECREATE" );

  TTree* outTree = new TTree("singleEleSelTree","singleEleSelTree");

  outTree->Branch( "run", &runNumber, "run/i" );
  outTree->Branch( "scintFront", &scintFront, "scintFront/F" );
  outTree->Branch( "isSingleEle_scintFront", &isSingleEle_scintFront, "isSingleEle_scintFront/O" );
  outTree->Branch( "nHodoClustersX", &nHodoClustersX, "nHodoClustersX/I" );
  outTree->Branch( "nHodoClustersY", &nHodoClustersY, "nHodoClustersY/I" );
  outTree->Branch( "cef3_corr", cef3_corr, "cef3_corr[4]/F" );
  outTree->Branch( "bgo_corr", bgo_corr, "bgo_corr[8]/F" );
  outTree->Branch( "bgo_corr_ok", &bgo_corr_ok, "bgo_corr_ok/O");
  outTree->Branch( "xBeam", &xBeam, "xBeam/F" );
  outTree->Branch( "yBeam", &yBeam, "yBeam/F" );

  TH1D* h1_cef3_corr_tot = new TH1D("cef3_corr_tot", "", 1500, 0., 15000);

  for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) {
    tree->GetEntry(iEntry);
    
    if( iEntry % 10000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl;
    if( cef3_ok ) {
      
      
      std::vector<float> v_cef3_corr;
      for(unsigned i=0; i<CEF3_CHANNELS; ++i) v_cef3_corr.push_back(cef3_corr[i]);
      
      float eTot_corr = sumVector(v_cef3_corr);

      if( cef3_corr_ok ) {
	h1_cef3_corr_tot->Fill(eTot_corr);
      }
      outTree->Fill();
    }

  }

  FitResults fr_0 = fitSingleHisto( h1_cef3_corr_tot, 0.,0., 1000., 11500. );

  outfile->cd();
  h1_cef3_corr_tot->Write();
  outTree->Write();
  outfile->Close();
  std::cout << "-> Histograms saved in: " << outfile->GetName() << std::endl;



  return 0;

}
コード例 #9
0
ファイル: calibrateCeF3.cpp プロジェクト: CeF3TB/H4_2014
int main( int argc, char* argv[] ) {


  DrawTools::setStyle();

  std::string inputDir = "./analysisTrees";
  std::string runName = "323";
  std::string tag = "V01";

  if( argc == 3 ) {
    std::string runName_str(argv[1]);
    runName = runName_str;
    std::string tag_str(argv[2]);
    tag = tag_str;
  }else if (argc==4){
    std::string inputDir_str(argv[2]);
    inputDir =inputDir_str;
  } else{
    std::cout<<"Usage:"<<std::endl;
    std::cout<<"./calibrateCef3 runNr tag [inputDir]"<<std::endl;
    exit(12345);
  }

  if(tag!="default") inputDir = inputDir + "_"+tag;



  TFile* file = TFile::Open(Form("%s/Reco_%s.root", inputDir.c_str(),runName.c_str()));
  std::cout<<"opening file:"<<file->GetName();


  TTree* tree = (TTree*)file->Get("recoTree");

  std::string outputdir = "CeF3Calibration/";
  std::string mkdir_command = "mkdir -p " + outputdir;
  system( mkdir_command.c_str() );

  std::string ofsName = outputdir +Form( "/constants_%s_%s.txt", runName.c_str(), tag.c_str() );
  ofstream ofs(ofsName.c_str());
  std::string ofsNameU = outputdir + Form( "/constants_uncert_%s_%s.txt", runName.c_str(), tag.c_str() );
  ofstream ofsU(ofsNameU.c_str());



  std::vector<float> cef3_calibration;
  std::vector<float> cef3_calib_uncert;


  for( unsigned i=0; i<4; ++i ) {
    TF1* f1 = fitSingleElectronPeak( outputdir, i, tree );
    float mean  = f1->GetParameter(1);
    float sigma = f1->GetParameter(2);
    float mean_err = f1->GetParError(1);
    std::cout << std::endl;
    std::cout << "Channel " << i << std::endl;
    std::cout << "  Mean       : " << mean << std::endl;
    std::cout << "  Sigma      : " << sigma << std::endl;
    std::cout << "  Resolution : " << sigma/mean << std::endl;

    cef3_calibration.push_back(mean);
    cef3_calib_uncert.push_back(mean_err);
  }


  float cef3CalibrationAverage = sumVector(cef3_calibration)/cef3_calibration.size();

  for(unsigned i=0; i<cef3_calibration.size(); ++i ){
    cef3_calib_uncert[i] = abs(cef3CalibrationAverage-cef3_calibration[i]/4.)/(cef3_calibration[i]*cef3_calibration[i])*cef3_calib_uncert[i];
    ofsU << cef3_calib_uncert[i] << std::endl;

    cef3_calibration[i] = cef3CalibrationAverage/cef3_calibration[i];
    ofs << cef3_calibration[i] << std::endl;
  }



  ofs.close();
  ofsU.close();


  if(checkIntercal == true){
    checkIntercalibration(cef3_calibration, cef3_calib_uncert, outputdir, runName, tag);
  }

  std::cout << "-> Saved constants in: " << ofsName << std::endl;


  checkTotalResolution( outputdir, tree );




  return 0;

}
コード例 #10
0
ファイル: alignTracking.cpp プロジェクト: CeF3TB/H4_2015
int main( int argc, char* argv[] ) {


  DrawTools::setStyle();
  TGaxis::SetMaxDigits(3);

  std::string tag="V0";
  std::string runName = "";
  if( argc<3 ) {
    std::cout << "USAGE: ./alignTracking [startTag] [run]" << std::endl;
    exit(11);
  } else if(argc>1) {
    std::string tag_str(argv[1]);
    tag = tag_str;
    if(argc>2){
     std::string runName_str(argv[2]);
     runName = runName_str;
    }
  }
    // this is the dir in which the offsets will be saved:
  std::string constDirName = "Alignment";
  system(Form("mkdir -p %s", constDirName.c_str()));


  std::string constFileName = constDirName+"/offsets_"+tag+".txt";
  AlignmentOfficer alignOfficer(constFileName);


  //  TFile* file = TFile::Open("data/run_487.root");
  // TFile* file = TFile::Open("data/run_428.root"); //200 GeV
  //  TFile* file = TFile::Open("data/run_407.root"); //150 GeV
  //  TFile* file = TFile::Open("data/run_418.root"); //100 GeV  
//TFile* file = TFile::Open("data/run_398.root"); //50 GeV
  // TFile* file = TFile::Open("data/run_455.root"); //20 GeV
  // TFile* file = TFile::Open("data/run_508.root"); //20 GeV seems to be better than run 455
  //  TFile* file = TFile::Open("data/run_457.root"); //15 GeV
  //TFile* file = TFile::Open("data/run_431.root"); //10 GeV
  //  TFile* file = TFile::Open("data/run_273.root");
  std::string fileName="dcap://t3se01.psi.ch:22125//pnfs/psi.ch/cms/trivcat/store/user/micheli/rawData/output_run"+runName+".root";
  char* hostName = getenv ("HOSTNAME");
  TString hostString(hostName);
  bool isLxplus = hostString.Contains("lxplus");
  if(isLxplus) fileName= "xroot://t3se01.psi.ch:1094//store/user/micheli/rawData/output_run" + runName + ".root"; 


  TFile* file = TFile::Open(fileName.c_str());
  TTree* tree = (TTree*)file->Get("outputTree");
  std::cout<<"Reading run:"<<runName<<std::endl;

  // Declaration of leaf types
   UInt_t          runNumber;
   UInt_t          spillNumber;
   UInt_t          evtNumber;
   std::vector<float>   *BGOvalues;
   std::vector<float>   *SCINTvalues;
   std::vector<float>   *TDCreco;
   std::vector<float>   *digi_charge_integrated;
   std::vector<float>   *digi_max_amplitude;
   std::vector<float>   *digi_pedestal;
   std::vector<float>   *digi_pedestal_rms;
   std::vector<float>   *digi_time_at_frac30;
   std::vector<float>   *digi_time_at_frac50;
   std::vector<float>   *digi_time_at_max;
   std::vector<bool>    *HODOX1;
   std::vector<bool>    *HODOX2;
   std::vector<bool>    *HODOY1;
   std::vector<bool>    *HODOY2;
   std::vector<float>   *HODOSMALLvalues;
   Float_t         TableX;
   Float_t         TableY;
   Float_t         CeF3HV;
   Float_t         BGOHV;
   Float_t         BeamEnergy;
   Float_t         BeamTilt;
   Int_t           IsPhysics;
   std::vector<int>     *nTdcHits;
   std::vector<float>   *digi_charge_integrated_sub;
   std::vector<float>   *digi_max_amplitude_sub;
   std::vector<float>   *digi_pedestal_sub;
   std::vector<float>   *digi_pedestal_rms_sub;
   std::vector<float>   *digi_charge_integrated_corr2;
   std::vector<float>   *digi_max_amplitude_corr2;

  // List of branches
   TBranch        *b_runNumber;   //!
   TBranch        *b_spillNumber;   //!
   TBranch        *b_evtNumber;   //!
   TBranch        *b_BGOvalues;   //!
   TBranch        *b_SCINTvalues;   //!
   TBranch        *b_HODOSMALLvalues;   //!
   TBranch        *b_TDCreco;   //!
   TBranch        *b_digi_charge_integrated;   //!
   TBranch        *b_digi_max_amplitude;   //!
   TBranch        *b_digi_pedestal;   //!
   TBranch        *b_digi_pedestal_rms;   //!
   TBranch        *b_digi_time_at_frac30;   //!
   TBranch        *b_digi_time_at_frac50;   //!
   TBranch        *b_digi_time_at_max;   //!
   TBranch        *b_HODOX1;   //!
   TBranch        *b_HODOX2;   //!
   TBranch        *b_HODOY1;   //!
   TBranch        *b_HODOY2;   //!
   TBranch        *b_TableX;   //!
   TBranch        *b_TableY;   //!
   TBranch        *b_CeF3HV;   //!
   TBranch        *b_BGOHV;   //!
   TBranch        *b_BeamEnergy;   //!
   TBranch        *b_BeamTilt;   //!
   TBranch        *b_IsPhysics;   //!
   TBranch        *b_nTdcHits;   //!
   TBranch        *b_digi_charge_integrated_sub;   //!
   TBranch        *b_digi_max_amplitude_sub;   //!
   TBranch        *b_digi_pedestal_sub;   //!
   TBranch        *b_digi_pedestal_rms_sub;   //!
   TBranch        *b_digi_charge_integrated_corr2;   //!
   TBranch        *b_digi_max_amplitude_corr2;   //!

  // Set object pointer
   BGOvalues = 0;
   SCINTvalues = 0;
   TDCreco = 0;
   HODOSMALLvalues = 0;
   digi_charge_integrated = 0;
   digi_max_amplitude = 0;
   digi_pedestal = 0;
   digi_pedestal_rms = 0;
   digi_time_at_frac30 = 0;
   digi_time_at_frac50 = 0;
   digi_time_at_max = 0;
   HODOX1 = 0;
   HODOX2 = 0;
   HODOY1 = 0;
   HODOY2 = 0;
   nTdcHits = 0;
   digi_charge_integrated_sub = 0;
   digi_max_amplitude_sub = 0;
   digi_pedestal_sub = 0;
   digi_pedestal_rms_sub = 0;
   digi_charge_integrated_corr2 = 0;
   digi_max_amplitude_corr2 = 0;


   //Set Branch Adresses and branch pointers 
   tree->SetBranchAddress("runNumber", &runNumber, &b_runNumber);
   tree->SetBranchAddress("spillNumber", &spillNumber, &b_spillNumber);
   tree->SetBranchAddress("evtNumber", &evtNumber, &b_evtNumber);
   tree->SetBranchAddress("BGOvalues", &BGOvalues, &b_BGOvalues);
   tree->SetBranchAddress("SCINTvalues", &SCINTvalues, &b_SCINTvalues);
   tree->SetBranchAddress("HODOSMALLvalues", &HODOSMALLvalues, &b_HODOSMALLvalues);
   tree->SetBranchAddress("TDCreco", &TDCreco, &b_TDCreco);
   tree->SetBranchAddress("digi_charge_integrated", &digi_charge_integrated, &b_digi_charge_integrated);
   tree->SetBranchAddress("digi_max_amplitude", &digi_max_amplitude, &b_digi_max_amplitude);
   tree->SetBranchAddress("digi_pedestal", &digi_pedestal, &b_digi_pedestal);
   tree->SetBranchAddress("digi_pedestal_rms", &digi_pedestal_rms, &b_digi_pedestal_rms);
   tree->SetBranchAddress("digi_time_at_frac30", &digi_time_at_frac30, &b_digi_time_at_frac30);
   tree->SetBranchAddress("digi_time_at_frac50", &digi_time_at_frac50, &b_digi_time_at_frac50);
   tree->SetBranchAddress("digi_time_at_max", &digi_time_at_max, &b_digi_time_at_max);
   tree->SetBranchAddress("HODOX1", &HODOX1, &b_HODOX1);
   tree->SetBranchAddress("HODOX2", &HODOX2, &b_HODOX2);
   tree->SetBranchAddress("HODOY1", &HODOY1, &b_HODOY1);
   tree->SetBranchAddress("HODOY2", &HODOY2, &b_HODOY2);
   tree->SetBranchAddress("TableX", &TableX, &b_TableX);
   tree->SetBranchAddress("TableY", &TableY, &b_TableY);
   tree->SetBranchAddress("CeF3HV", &CeF3HV, &b_CeF3HV);
   tree->SetBranchAddress("BGOHV", &BGOHV, &b_BGOHV);
   tree->SetBranchAddress("BeamEnergy", &BeamEnergy, &b_BeamEnergy);
   tree->SetBranchAddress("BeamTilt", &BeamTilt, &b_BeamTilt);
   tree->SetBranchAddress("IsPhysics", &IsPhysics, &b_IsPhysics);
   tree->SetBranchAddress("nTdcHits", &nTdcHits, &b_nTdcHits);
   tree->SetBranchAddress("digi_charge_integrated_sub", &digi_charge_integrated_sub, &b_digi_charge_integrated_sub);
   tree->SetBranchAddress("digi_max_amplitude_sub", &digi_max_amplitude_sub, &b_digi_max_amplitude_sub);
   tree->SetBranchAddress("digi_pedestal_sub", &digi_pedestal_sub, &b_digi_pedestal_sub);
   tree->SetBranchAddress("digi_pedestal_rms_sub", &digi_pedestal_rms_sub, &b_digi_pedestal_rms_sub);
   tree->SetBranchAddress("digi_charge_integrated_corr2", &digi_charge_integrated_corr2, &b_digi_charge_integrated_corr2);
   tree->SetBranchAddress("digi_max_amplitude_corr2", &digi_max_amplitude_corr2, &b_digi_max_amplitude_corr2);


  int nClusters_hodoX1;
  int nFibres_hodoX1[HODOX1_CHANNELS];
  float pos_hodoX1[HODOX1_CHANNELS];
  int nClusters_hodoY1;
  int nFibres_hodoY1[HODOY1_CHANNELS];
  float pos_hodoY1[HODOY1_CHANNELS];

  int nClusters_hodoX2;
  int nFibres_hodoX2[HODOX2_CHANNELS];
  float pos_hodoX2[HODOX2_CHANNELS];
  int nClusters_hodoY2;
  int nFibres_hodoY2[HODOY2_CHANNELS];
  float pos_hodoY2[HODOY2_CHANNELS];

  float wc_x;
  float wc_y;


  //int nBins = 80*2*2*2*2;
  int nBins = 80;
  //   int nBinsWC = 40*5;
  int nBinsWC = 80;
  float xMin = -20.;
  float xMax =  20.;

  TH1F* h1_wc_y_low = new TH1F("wc_y_low", "", nBinsWC, xMin, xMax);
  TH1F* h1_wc_y_hi  = new TH1F("wc_y_hi" , "", nBinsWC, xMin, xMax);
  TH1F* h1_wc_x_low = new TH1F("wc_x_low", "", nBinsWC, xMin, xMax);
  TH1F* h1_wc_x_hi  = new TH1F("wc_x_hi" , "", nBinsWC, xMin, xMax);

  TH1F* h1_hodoY1_low = new TH1F("hodoY1_low", "", nBins, xMin, xMax);
  TH1F* h1_hodoY1_hi  = new TH1F("hodoY1_hi" , "", nBins, xMin, xMax);
  TH1F* h1_hodoX1_low = new TH1F("hodoX1_low", "", nBins, xMin, xMax);
  TH1F* h1_hodoX1_hi  = new TH1F("hodoX1_hi" , "", nBins, xMin, xMax);

  TH1F* h1_hodoY2_low = new TH1F("hodoY2_low", "", nBins, xMin, xMax);
  TH1F* h1_hodoY2_hi  = new TH1F("hodoY2_hi" , "", nBins, xMin, xMax);
  TH1F* h1_hodoX2_low = new TH1F("hodoX2_low", "", nBins, xMin, xMax);
  TH1F* h1_hodoX2_hi  = new TH1F("hodoX2_hi" , "", nBins, xMin, xMax);


  int nentries = tree->GetEntries();
  if(nentries>10000)  nentries=10000;
  for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) {

    tree->GetEntry(iEntry);

     if( iEntry %  10000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl;

     std::vector<bool> hodoX1_values(HODOX1_CHANNELS, -1.);
     std::vector<bool> hodoY1_values(HODOY1_CHANNELS, -1.);
     assignValuesBool( hodoX1_values, *HODOX1, 0. );
     assignValuesBool( hodoY1_values, *HODOY1, 0. );


     std::vector<bool> hodoX2_values(HODOX2_CHANNELS, -1.);
     std::vector<bool> hodoY2_values(HODOY2_CHANNELS, -1.);
     assignValuesBool( hodoX2_values, *HODOX2, 0 );
     assignValuesBool( hodoY2_values, *HODOY2, 0 );


     std::vector<float> hodoSmallX_values(HODOSMALLX_CHANNELS, -1.);
     std::vector<float> hodoSmallY_values(HODOSMALLY_CHANNELS, -1.);
     assignValues( hodoSmallY_values, *HODOSMALLvalues, 0 );
     assignValues( hodoSmallX_values, *HODOSMALLvalues, 4 );

     // hodo cluster reconstruction
     int clusterMaxFibres = 4;
     doHodoReconstructionBool( hodoX1_values    , nClusters_hodoX1    , nFibres_hodoX1    , pos_hodoX1    , 0.5, clusterMaxFibres, 0.  );
     doHodoReconstructionBool( hodoY1_values    , nClusters_hodoY1    , nFibres_hodoY1    , pos_hodoY1    , 0.5, clusterMaxFibres, 0.  );
     doHodoReconstructionBool( hodoX2_values    , nClusters_hodoX2    , nFibres_hodoX2    , pos_hodoX2    , 0.5, clusterMaxFibres, 0.  );
     doHodoReconstructionBool( hodoY2_values    , nClusters_hodoY2    , nFibres_hodoY2    , pos_hodoY2    , 0.5, clusterMaxFibres, 0.  );

     alignOfficer.fix("hodoX1", nClusters_hodoX1, pos_hodoX1);
     alignOfficer.fix("hodoY1", nClusters_hodoY1, pos_hodoY1);
     alignOfficer.fix("hodoX2", nClusters_hodoX2, pos_hodoX2);
     alignOfficer.fix("hodoY2", nClusters_hodoY2, pos_hodoY2);

     wc_x = TDCreco->at(0);
     wc_y = TDCreco->at(1);
     if( runNumber>=170 ) wc_y = -wc_y; // temporary fix

     wc_x += alignOfficer.getOffset("wc_x");
     wc_y += alignOfficer.getOffset("wc_y");

//     float hodoSmallY_low = digi_max_amplitude->at(6);
//     float hodoSmallY_hi  = digi_max_amplitude->at(7);
////     //float hodoSmallX_low = digi_max_amplitude->at(5);
////     //float hodoSmallX_hi  = digi_max_amplitude->at(4);
//     float hodoSmallX_low = digi_max_amplitude->at(4);
//     float hodoSmallX_hi  = digi_max_amplitude->at(5);

     bool isOctober2015Run=  (runNumber > 3900. && runNumber<4600);

     float hodoSmallY_low = HODOSMALLvalues->at(1);
     float hodoSmallY_hi  = HODOSMALLvalues->at(2);
     float hodoSmallX_low = HODOSMALLvalues->at(5);
     float hodoSmallX_hi  = HODOSMALLvalues->at(6);

     if (isOctober2015Run){
       hodoSmallY_low = HODOSMALLvalues->at(0);
       hodoSmallY_hi  = HODOSMALLvalues->at(1);
       hodoSmallX_low = HODOSMALLvalues->at(2);
       hodoSmallX_hi  = HODOSMALLvalues->at(3);
     }

     //     std::cout<< hodoSmallY_low<<" "<<hodoSmallY_hi<<" "<<hodoSmallX_low<<" "<<hodoSmallX_hi<<std::endl;
     std::vector<float> pedMeanX,pedMeanY, pedSigmaX, pedSigmaY;
     if(!isOctober2015Run){
       pedMeanY.push_back(141.30);
       pedMeanY.push_back(152.90);
       pedMeanX.push_back(139.89);
       pedMeanX.push_back(151.73);
       
       pedSigmaY.push_back(1.25);
       pedSigmaY.push_back(1.60);
       pedSigmaX.push_back(1.32);
       pedSigmaX.push_back(1.31);
     }else{//ped value for october 2015 run
       pedMeanY.push_back(212.5);
       pedMeanY.push_back(202.0);
       pedMeanX.push_back(218.6);//this channels are not working in these runs....
       pedMeanX.push_back(208.0);
       
       pedSigmaY.push_back(1.51);
       pedSigmaY.push_back(1.67);
       pedSigmaX.push_back(2.04);
       pedSigmaX.push_back(1.83);

     }

  // y low
     if( hodoSmallY_low>pedMeanY[0]+5*pedSigmaY[0] ) {

     int posOf2FibClustY1Low = 0;
    int   posOf2FibClustY2Low=0;

     int nrOf2FibreClustersY1Low = 0;
       for( int i=0; i<nClusters_hodoY1; ++i ) {
         if( nFibres_hodoY1[i]==2  )  {  
	   ++nrOf2FibreClustersY1Low;
	   posOf2FibClustY1Low= i ;} 
       }
 
	  //And for Y2 LOW:
     int nrOf2FibreClustersY2Low = 0;
       for( int i=0; i<nClusters_hodoY2; ++i ) {
         if( nFibres_hodoY2[i]==2  )  {  
	   ++nrOf2FibreClustersY2Low;
	   posOf2FibClustY2Low=i;  } 
       }

       if((nrOf2FibreClustersY2Low==1||nClusters_hodoY2==1)&& (nrOf2FibreClustersY1Low==1 || nClusters_hodoY1==1) && abs(wc_y) <200 && nTdcHits->at(2)>0 && nTdcHits->at(3)>0 &&  nTdcHits->at(2)<3 && nTdcHits->at(3)<3 && ( nTdcHits->at(2) + nTdcHits->at(3))<4){
	 h1_wc_y_low->Fill( wc_y );
	 h1_hodoY1_low->Fill( pos_hodoY1[posOf2FibClustY1Low] );
	 h1_hodoY2_low->Fill( pos_hodoY2[posOf2FibClustY2Low] );     
     }
     }

   // y hi
     if( hodoSmallY_hi>pedMeanY[1]+5*pedSigmaY[1] ) {

     int posOf2FibClustY1Hi = 0;
    int   posOf2FibClustY2Hi=0;

     int nrOf2FibreClustersY1Hi = 0;
       for( int i=0; i<nClusters_hodoY1; ++i ) {
         if( nFibres_hodoY1[i]==2  )  {  
	   ++nrOf2FibreClustersY1Hi;
	   posOf2FibClustY1Hi= i ;} 
       }
 
	  //And for Y2 HI:
     int nrOf2FibreClustersY2Hi = 0;
       for( int i=0; i<nClusters_hodoY2; ++i ) {
         if( nFibres_hodoY2[i]==2  )  {  
	   ++nrOf2FibreClustersY2Hi;
	   posOf2FibClustY2Hi=i;  } 
       }

       if((nrOf2FibreClustersY2Hi==1||nClusters_hodoY2==1)&& (nrOf2FibreClustersY1Hi==1 || nClusters_hodoY1==1) && abs(wc_y) <200 && nTdcHits->at(2)>0 && nTdcHits->at(3)>0 &&  nTdcHits->at(2)<3 && nTdcHits->at(3)<3 && ( nTdcHits->at(2) + nTdcHits->at(3))<4){
	 h1_wc_y_hi->Fill( wc_y );
	 h1_hodoY1_hi->Fill( pos_hodoY1[ posOf2FibClustY1Hi] );
	 h1_hodoY2_hi->Fill( pos_hodoY2[posOf2FibClustY2Hi] );     
     }
     }


  // x low
     if( hodoSmallX_low>pedMeanX[0]+5*pedSigmaX[0] ) {

     int posOf2FibClustX1Low = 0;
    int   posOf2FibClustX2Low=0;

     int nrOf2FibreClustersX1Low = 0;
       for( int i=0; i<nClusters_hodoX1; ++i ) {
         if( nFibres_hodoX1[i]==2  )  {  
	   ++nrOf2FibreClustersX1Low;
	   posOf2FibClustX1Low= i ;} 
       }
 
	  //And for X2 LOW:
     int nrOf2FibreClustersX2Low = 0;
       for( int i=0; i<nClusters_hodoX2; ++i ) {
         if( nFibres_hodoX2[i]==2  )  {  
	   ++nrOf2FibreClustersX2Low;
	   posOf2FibClustX2Low=i;  } 
       }

       if((nrOf2FibreClustersX2Low==1||nClusters_hodoX2==1)&& (nrOf2FibreClustersX1Low==1 || nClusters_hodoX1==1) &&  abs(wc_x)<200 && nTdcHits->at(0)>0 && nTdcHits->at(1)>0 && nTdcHits->at(0)<3 && nTdcHits->at(1)<3 &&  ( nTdcHits->at(0) + nTdcHits->at(1) )<4){
	 h1_wc_x_low->Fill( wc_x );
	 h1_hodoX1_low->Fill( pos_hodoX1[ posOf2FibClustX1Low] );
	 h1_hodoX2_low->Fill( pos_hodoX2[posOf2FibClustX2Low] );     
     }
     }

   // x hi
     if( hodoSmallX_hi>pedMeanX[1]+5*pedSigmaX[1] ) {

     int posOf2FibClustX1Hi = 0;
    int   posOf2FibClustX2Hi=0;

     int nrOf2FibreClustersX1Hi = 0;
       for( int i=0; i<nClusters_hodoX1; ++i ) {
         if( nFibres_hodoX1[i]==2  )  {  
	   ++nrOf2FibreClustersX1Hi;
	   posOf2FibClustX1Hi= i ;} 
       }
 
	  //And for X2 HI:
     int nrOf2FibreClustersX2Hi = 0;
       for( int i=0; i<nClusters_hodoX2; ++i ) {
         if( nFibres_hodoX2[i]==2  )  {  
	   ++nrOf2FibreClustersX2Hi;
	   posOf2FibClustX2Hi=i;  } 
       }

       if((nrOf2FibreClustersX2Hi==1||nClusters_hodoX2==1)&& (nrOf2FibreClustersX1Hi==1 || nClusters_hodoX1==1) && abs(wc_x) <200 && nTdcHits->at(0)>0 && nTdcHits->at(1)>0 &&  nTdcHits->at(0)<3 && nTdcHits->at(1)<3 && ( nTdcHits->at(0) + nTdcHits->at(1) )<4){
	 h1_wc_x_hi->Fill( wc_x );
	 h1_hodoX1_hi->Fill( pos_hodoX1[ posOf2FibClustX1Hi] );
	 h1_hodoX2_hi->Fill( pos_hodoX2[posOf2FibClustX2Hi] );     
     }
     }




  } // for entries


  std::string outputdir = "AlignmentPlots_"+tag;
  system( Form("mkdir -p %s", outputdir.c_str()));

  float offset_wc_y_low = fitAndDraw( outputdir, h1_wc_y_low );
  float offset_wc_y_hi  = fitAndDraw( outputdir, h1_wc_y_hi );
  float offset_wc_x_low = fitAndDraw( outputdir, h1_wc_x_low );
  float offset_wc_x_hi  = fitAndDraw( outputdir, h1_wc_x_hi );
  float offset_hodoY1_low = fitAndDraw( outputdir, h1_hodoY1_low );
  float offset_hodoY1_hi  = fitAndDraw( outputdir, h1_hodoY1_hi );
  float offset_hodoX1_low = fitAndDraw( outputdir, h1_hodoX1_low );
  float offset_hodoX1_hi  = fitAndDraw( outputdir, h1_hodoX1_hi );
  float offset_hodoY2_low = fitAndDraw( outputdir, h1_hodoY2_low );
  float offset_hodoY2_hi  = fitAndDraw( outputdir, h1_hodoY2_hi );
  float offset_hodoX2_low = fitAndDraw( outputdir, h1_hodoX2_low );
  float offset_hodoX2_hi  = fitAndDraw( outputdir, h1_hodoX2_hi );

  float offset_wc_y   = 0.5*(offset_wc_y_low  +offset_wc_y_hi);
  float offset_wc_x   = 0.5*(offset_wc_x_low  +offset_wc_x_hi);
  float offset_hodoY1 = 0.5*(offset_hodoY1_low+offset_hodoY1_hi);
  float offset_hodoX1 = 0.5*(offset_hodoX1_low+offset_hodoX1_hi);
  float offset_hodoY2 = 0.5*(offset_hodoY2_low+offset_hodoY2_hi);
  float offset_hodoX2 = 0.5*(offset_hodoX2_low+offset_hodoX2_hi);

  std::cout << "offset_wc_y: "   <<  offset_wc_y << std::endl;
  std::cout << "offset_wc_x: "   <<  offset_wc_x << std::endl;
  std::cout << "offset_hodoY1: " <<  offset_hodoY1 << std::endl;
  std::cout << "offset_hodoX1: " <<  offset_hodoX1 << std::endl;
  std::cout << "offset_hodoY2: " <<  offset_hodoY2 << std::endl;
  std::cout << "offset_hodoX2: " <<  offset_hodoX2 << std::endl;

  
  std::string ofsName = constDirName + "/offsets_new.txt";
  ofstream ofs(ofsName.c_str());
  ofs << "wc_y "   << -offset_wc_y << std::endl;
  ofs << "wc_x "   << -offset_wc_x << std::endl;
  ofs << "hodoY1 " << -offset_hodoY1 << std::endl;
  ofs << "hodoX1 " << -offset_hodoX1 << std::endl;
  ofs << "hodoY2 " << -offset_hodoY2 << std::endl;
  ofs << "hodoX2 " << -offset_hodoX2 << std::endl;
  ofs.close();

  std::cout << "-> Saved offsets in: " << ofsName << std::endl;

  return 0;

}
コード例 #11
0
int main( int argc, char* argv[] ) {


  std::string runName = "precalib_BGO_pedestal_noSource";
  if( argc>1 ) {
    std::string runName_str(argv[1]);
    runName = runName_str;
  }

  std::string tag = "V00";
  if( argc>2 ) {
    std::string tag_str(argv[2]);
    tag = tag_str;
  }

  TString runName_tstr(runName);
  bool isOnlyRunNumber = !(runName_tstr.BeginsWith("BTF_"));


  TChain* tree = new TChain("recoTree");
  if( isOnlyRunNumber ) {
    std::cout << "-> We believe you are passing the program only the run number!" << std::endl;
    std::cout << "-> So for instance you are passing '246' for run 'BTF_246_20140501-212512_beam'" << std::endl;
    std::cout << "(if this is not the case this means TROUBLE)" << std::endl;
    std::cout << "-> Will look for runs matching run number: " << runName << std::endl;
    tree->Add(Form("analysisTrees_%s/Reco_BTF_%s_*beam.root/recoTree", tag.c_str(), runName.c_str()) );
    if( tree->GetEntries()==0 ) {
      std::cout << "WARNING! Didn't find any events matching run: " << runName << std::endl;
      std::cout << "Exiting" << std::endl;
      exit(1913);
    }
  } else {
    std::string fileName = "analysisTrees_"+tag+"/Reco_" + runName + ".root";
    TFile* file = TFile::Open(fileName.c_str());
    if( file==0 ) {
      std::cout << "ERROR! Din't find file " << fileName << std::endl;
      std::cout << "Exiting." << std::endl;
      exit(11);
    }
    tree = (TChain*)file->Get("recoTree");
  }





  UInt_t evtNumber;
  tree->SetBranchAddress( "evtNumber", &evtNumber );
  UInt_t adcData[40];
  tree->SetBranchAddress( "adcData", adcData );
  UInt_t adcBoard[40];
  tree->SetBranchAddress( "adcBoard", adcBoard );
  UInt_t adcChannel[40];
  tree->SetBranchAddress( "adcChannel", adcChannel );


  unsigned int runNumber;
  int nHodoFibersX;
  int nHodoFibersY;
  int nHodoClustersX;
  int nHodoClustersY;
  float cef3_corr[CEF3_CHANNELS];
  float bgo_corr[BGO_CHANNELS];
  float scintFront;
  float pos_hodoClustX[HODOX_CHANNELS];
  float pos_hodoClustY[HODOY_CHANNELS];
  int nFibres_hodoClustX[HODOX_CHANNELS];
  int nFibres_hodoClustY[HODOY_CHANNELS];
  float xBeam, yBeam;
  bool isSingleEle_scintFront;
  bool cef3_ok;
  bool cef3_corr_ok;
  bool bgo_ok;
  bool bgo_corr_ok;

  tree->SetBranchAddress( "runNumber", &runNumber );

  tree->SetBranchAddress( "scintFront", &scintFront );
  tree->SetBranchAddress( "cef3_corr", cef3_corr );
  tree->SetBranchAddress( "bgo_corr", bgo_corr );

  tree->SetBranchAddress( "nHodoFibersX", &nHodoFibersX );
  tree->SetBranchAddress( "nHodoFibersY", &nHodoFibersY );
  tree->SetBranchAddress( "nHodoClustersX", &nHodoClustersX );
  tree->SetBranchAddress( "pos_hodoClustX", pos_hodoClustX );
  tree->SetBranchAddress( "nFibres_hodoClustX", nFibres_hodoClustX );
  tree->SetBranchAddress( "nHodoClustersY", &nHodoClustersY );
  tree->SetBranchAddress( "pos_hodoClustY", pos_hodoClustY );
  tree->SetBranchAddress( "nFibres_hodoClustY", nFibres_hodoClustY );
  tree->SetBranchAddress( "scintFront", &scintFront );
  tree->SetBranchAddress( "isSingleEle_scintFront", &isSingleEle_scintFront );
  tree->SetBranchAddress( "xBeam", &xBeam );
  tree->SetBranchAddress( "yBeam", &yBeam );

  tree->SetBranchAddress( "cef3_ok", &cef3_ok );
  tree->SetBranchAddress( "cef3_corr_ok", &cef3_corr_ok );
  tree->SetBranchAddress( "bgo_ok", &bgo_ok );
  tree->SetBranchAddress( "bgo_corr_ok", &bgo_corr_ok );




  int nBins = 500;
  float xMax = 25.*3./2.;


  TH1D* h1_xPos = new TH1D("xPos", "", nBins, -xMax, xMax);
  TH1D* h1_yPos = new TH1D("yPos", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos = new TH2D("xyPos", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle = new TH1D("xPos_singleEle", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle = new TH1D("yPos_singleEle", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle = new TH2D("xyPos_singleEle", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_new = new TH1D("xPos_new", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_new = new TH1D("yPos_new", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_new = new TH2D("xyPos_new", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_new_singleEle = new TH1D("xPos_new_singleEle", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_new_singleEle = new TH1D("yPos_new_singleEle", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_new_singleEle = new TH2D("xyPos_new_singleEle", "", nBins, -xMax, xMax, nBins, -xMax, xMax);


  TH1D* h1_xPos_bgo = new TH1D("xPos_bgo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_bgo = new TH1D("yPos_bgo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_bgo = new TH2D("xyPos_bgo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle_bgo = new TH1D("xPos_singleEle_bgo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle_bgo = new TH1D("yPos_singleEle_bgo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_bgo = new TH2D("xyPos_singleEle_bgo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_hodo = new TH1D("xPos_hodo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_hodo = new TH1D("yPos_hodo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_hodo = new TH2D("xyPos_hodo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle_hodo = new TH1D("xPos_singleEle_hodo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle_hodo = new TH1D("yPos_singleEle_hodo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_hodo = new TH2D("xyPos_singleEle_hodo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle_hodoClust = new TH1D("xPos_singleEle_hodoClust", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle_hodoClust = new TH1D("yPos_singleEle_hodoClust", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_hodoClust = new TH2D("xyPos_singleEle_hodoClust", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_calo = new TH1D("xPos_calo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo = new TH1D("yPos_calo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_calo = new TH2D("xyPos_calo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_singleEle_calo = new TH1D("xPos_singleEle_calo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_singleEle_calo = new TH1D("yPos_singleEle_calo", "", nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_calo = new TH2D("xyPos_singleEle_calo", "", nBins, -xMax, xMax, nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_hodo = new TH1D("xPos_calo_vs_hodo", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_hodo = new TH1D("yPos_calo_vs_hodo", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_beam = new TH1D("xPos_calo_vs_beam", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_beam = new TH1D("yPos_calo_vs_beam", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_hodo_singleElectron = new TH1D("xPos_calo_vs_hodo_singleElectron", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_hodo_singleElectron = new TH1D("yPos_calo_vs_hodo_singleElectron", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_beam_singleElectron = new TH1D("xPos_calo_vs_beam_singleElectron", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_beam_singleElectron = new TH1D("yPos_calo_vs_beam_singleElectron", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_hodo_singleElectron_HR = new TH1D("xPos_calo_vs_hodo_singleElectron_HR", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_hodo_singleElectron_HR = new TH1D("yPos_calo_vs_hodo_singleElectron_HR", "", nBins, -xMax, xMax);

  TH1D* h1_xPos_calo_vs_beam_singleElectron_HR = new TH1D("xPos_calo_vs_beam_singleElectron_HR", "", nBins, -xMax, xMax);
  TH1D* h1_yPos_calo_vs_beam_singleElectron_HR = new TH1D("yPos_calo_vs_beam_singleElectron_HR", "", nBins, -xMax, xMax);


  TH2D* h2_correlation_cef3_hodo_xPos = new TH2D("correlation_cef3_hodo_xPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_cef3_hodo_yPos = new TH2D("correlation_cef3_hodo_yPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);

  TH2D* h2_correlation_cef3_bgo_xPos = new TH2D("correlation_cef3_bgo_xPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_cef3_bgo_yPos = new TH2D("correlation_cef3_bgo_yPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);

  TH2D* h2_correlation_hodo_bgo_xPos = new TH2D("correlation_hodo_bgo_xPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_hodo_bgo_yPos = new TH2D("correlation_hodo_bgo_yPos", "", 100, -12.5, 12.5,  100, -12.5, 12.5);


  TH2D* h2_correlation_cef3_hodo_xPos_singleEle = new TH2D("correlation_cef3_hodo_xPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_cef3_hodo_yPos_singleEle = new TH2D("correlation_cef3_hodo_yPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);

  TH2D* h2_correlation_cef3_bgo_xPos_singleEle = new TH2D("correlation_cef3_bgo_xPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_cef3_bgo_yPos_singleEle = new TH2D("correlation_cef3_bgo_yPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);

  TH2D* h2_correlation_hodo_bgo_xPos_singleEle = new TH2D("correlation_hodo_bgo_xPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);
  TH2D* h2_correlation_hodo_bgo_yPos_singleEle = new TH2D("correlation_hodo_bgo_yPos_singleEle", "", 100, -12.5, 12.5,  100, -12.5, 12.5);



  int nentries = tree->GetEntries();


  if( isOnlyRunNumber ) {
    // modify runname in such a way that it's useful for getBeamPosition and outfile:
    runName = "BTF_" + runName + "_beam";
  }



  std::string outputdir = "PosAnTrees_"+tag;
  system( Form("mkdir -p %s", outputdir.c_str()) );
  std::string outfileName = outputdir + "/PosAn_" + runName + ".root";
  TFile* outfile = TFile::Open( outfileName.c_str(), "RECREATE" );

  TTree* outTree = new TTree("posTree","posTree");
  float xPos_calo_, yPos_calo_;
  float xPos_bgo_, yPos_bgo_;
  float xPos_new_, yPos_new_;
  float xPos_regr2D_, yPos_regr2D_;
  float r02_, r13_;

  outTree->Branch( "isSingleEle_scintFront", &isSingleEle_scintFront, "isSingleEle_scintFront/O" );
  outTree->Branch( "nHodoClustersX", &nHodoClustersX, "nHodoClustersX/I" );
  outTree->Branch( "nHodoClustersY", &nHodoClustersY, "nHodoClustersY/I" );
  outTree->Branch( "cef3_corr", cef3_corr, "cef3_corr[4]/F" );
  outTree->Branch( "r02", &r02_, "r02_/F" );
  outTree->Branch( "r13", &r13_, "r13_/F" );
  outTree->Branch( "xBeam", &xBeam, "xBeam/F" );
  outTree->Branch( "yBeam", &yBeam, "yBeam/F" );
  outTree->Branch( "xPos_bgo", &xPos_bgo_, "xPos_bgo_/F" );
  outTree->Branch( "yPos_bgo", &yPos_bgo_, "yPos_bgo_/F" );
  outTree->Branch( "xPos_calo", &xPos_calo_, "xPos_calo_/F" );
  outTree->Branch( "yPos_calo", &yPos_calo_, "yPos_calo_/F" );
  outTree->Branch( "xPos_new", &xPos_new_, "xPos_new_/F" );
  outTree->Branch( "yPos_new", &yPos_new_, "yPos_new_/F" );
  outTree->Branch( "xPos_regr2D", &xPos_regr2D_, "xPos_regr2D_/F" );
  outTree->Branch( "yPos_regr2D", &yPos_regr2D_, "yPos_regr2D_/F" );

  float diag02_calo_;
  float diag13_calo_;
  outTree->Branch( "diag02_calo", &diag02_calo_, "diag02_calo_/F" );
  outTree->Branch( "diag13_calo", &diag13_calo_, "diag13_calo_/F" );
  float diag02_new_;
  float diag13_new_;
  outTree->Branch( "diag02_new", &diag02_new_, "diag02_new_/F" );
  outTree->Branch( "diag13_new", &diag13_new_, "diag13_new_/F" );
  float diag02_beam_;
  float diag13_beam_;
  outTree->Branch( "diag02_beam", &diag02_beam_, "diag02_beam_/F" );
  outTree->Branch( "diag13_beam", &diag13_beam_, "diag13_beam_/F" );

  
  std::vector<float> xbgo, ybgo;
  for( unsigned i=0; i<BGO_CHANNELS; ++i ) {
    float x,y;
    RunHelper::getBGOCoordinates( i, x, y );
    xbgo.push_back( x );
    ybgo.push_back( y );
  }


  
  



  float cef3_regr[CEF3_CHANNELS];
  //TMVA::Reader* readerRegrX = new TMVA::Reader( "!Color:!Silent" );
  //readerRegrX->AddVariable("cef3_corr[0]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[0] );
  //readerRegrX->AddVariable("cef3_corr[1]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[1] );
  //readerRegrX->AddVariable("cef3_corr[2]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[2] );
  //readerRegrX->AddVariable("cef3_corr[3]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[3] );

  //TMVA::Reader* readerRegrY = new TMVA::Reader( "!Color:!Silent" );
  //readerRegrY->AddVariable("cef3_corr[0]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[0] );
  //readerRegrY->AddVariable("cef3_corr[1]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[1] );
  //readerRegrY->AddVariable("cef3_corr[2]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[2] );
  //readerRegrY->AddVariable("cef3_corr[3]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3])", &cef3_regr[3] ); // let try this trick

  //TMVA::Reader* readerRegr2D = new TMVA::Reader( "!Color:!Silent" );
  //readerRegr2D->AddVariable("cef3_corr[0]", &cef3_corr_[0] );
  //readerRegr2D->AddVariable("cef3_corr[1]", &cef3_corr_[1] );
  //readerRegr2D->AddVariable("cef3_corr[2]", &cef3_corr_[2] );
  //readerRegr2D->AddVariable("cef3_corr[3]", &cef3_corr_[3] );
  //readerRegr2D->BookMVA( "MLP", "TMVA/weights/TMVARegression_MLP.weights.xml" );


  std::vector<std::string> methodNames;
  //methodNames.push_back("BDTG");
  ////methodNames.push_back("FDA_MT");
  //methodNames.push_back("LD");
  //methodNames.push_back("MLP");
  ////methodNames.push_back("PDERS");

 
  //
  //std::cout << "-> Booking TMVA Reader" << std::endl;
  //for( unsigned i=0; i<methodNames.size(); ++i ) {
  //  readerRegrX->BookMVA( methodNames[i], Form("TMVA/weights/TMVARegression_%s.weights.xml", methodNames[i].c_str()) ); 
  //  readerRegrY->BookMVA( methodNames[i], Form("TMVA/weights/TMVARegression_%s.weights.xml", methodNames[i].c_str()) ); 
  //}


  std::vector< TH1D* > h1_xPos_regr_vs_calo;
  std::vector< TH1D* > h1_yPos_regr_vs_calo;
  std::vector< TH2D* > h2_xyPos_regr;
  std::vector< TH1D* > h1_xPos_regr_vs_calo_singleEle;
  std::vector< TH1D* > h1_yPos_regr_vs_calo_singleEle;
  std::vector< TH2D* > h2_xyPos_singleEle_regr;
  for( unsigned i=0; i<methodNames.size(); ++i ) {
    TH1D* newHistx = new TH1D( Form("xPos_regr%s_vs_calo", methodNames[i].c_str()), "", nBins, -xMax, xMax);
    h1_xPos_regr_vs_calo.push_back( newHistx );
    TH1D* newHisty = new TH1D( Form("yPos_regr%s_vs_calo", methodNames[i].c_str()), "", nBins, -xMax, xMax);
    h1_yPos_regr_vs_calo.push_back( newHisty );
    TH2D* newHistxy = new TH2D( Form("xyPos_regr%s", methodNames[i].c_str()), "", nBins, -xMax, xMax, nBins, -xMax, xMax);
    h2_xyPos_regr.push_back( newHistxy );
    TH1D* newHistx_singleEle = new TH1D( Form("xPos_regr%s_vs_calo_singleEle", methodNames[i].c_str()), "", nBins, -xMax, xMax);
    h1_xPos_regr_vs_calo_singleEle.push_back( newHistx_singleEle );
    TH1D* newHisty_singleEle = new TH1D( Form("yPos_regr%s_vs_calo_singleEle", methodNames[i].c_str()), "", nBins, -xMax, xMax);
    h1_yPos_regr_vs_calo_singleEle.push_back( newHisty_singleEle );
    TH2D* newHistxy_singleEle = new TH2D( Form("xyPos_singleEle_regr%s", methodNames[i].c_str()), "", nBins, -xMax, xMax, nBins, -xMax, xMax);
    h2_xyPos_singleEle_regr.push_back( newHistxy_singleEle );
  }


  TH2D* h2_xyPos_regr2D = new TH2D("xyPos_regr2D", "", nBins, -xMax, xMax, nBins, -xMax, xMax);
  TH2D* h2_xyPos_singleEle_regr2D = new TH2D("xyPos_singleEle_regr2D", "", nBins, -xMax, xMax, nBins, -xMax, xMax);





  for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) {

    xPos_bgo_ = -999.;
    yPos_bgo_ = -999.;

    xPos_calo_ = -999.;
    yPos_calo_ = -999.;


    tree->GetEntry(iEntry);

    if( iEntry % 5000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl;

    if( !bgo_corr_ok ) continue;

    r02_ = cef3_corr[0]/cef3_corr[2];
    r13_ = cef3_corr[1]/cef3_corr[3];

    // FIRST GET POSITION FROM HODOSCOPE:


    float xPos_hodo = getMeanposHodo(nHodoClustersX, pos_hodoClustX);
    float yPos_hodo = getMeanposHodo(nHodoClustersY, pos_hodoClustY);



    if( xPos_hodo>-100. )
      h1_xPos_hodo->Fill(xPos_hodo);
    if( yPos_hodo>-100. )
      h1_yPos_hodo->Fill(yPos_hodo);

    if( xPos_hodo>-100. && yPos_hodo>-100. ) 
      h2_xyPos_hodo->Fill(xPos_hodo, yPos_hodo);


    if( isSingleEle_scintFront ) {

      if( xPos_hodo>-100. )
        h1_xPos_singleEle_hodo->Fill(xPos_hodo);
      if( yPos_hodo>-100. )
        h1_yPos_singleEle_hodo->Fill(yPos_hodo);

      if( xPos_hodo>-100. && yPos_hodo>-100. ) 
        h2_xyPos_singleEle_hodo->Fill(xPos_hodo, yPos_hodo);

    }



    std::vector<float> xPosW_bgo;
    std::vector<float> yPosW_bgo;

    std::vector<float> v_bgo_corr;
    for( unsigned i=0; i<BGO_CHANNELS; ++i ) v_bgo_corr.push_back(bgo_corr[i]);

    float eTot_bgo_corr = sumVector(v_bgo_corr);

    if( bgo_ok && bgo_corr_ok ) {

      //   0  1  2
      //   3     4
      //   5  6  7

      xPosW_bgo.push_back(bgo_corr[0]*xbgo[0]);
      xPosW_bgo.push_back(bgo_corr[1]*xbgo[1]);
      xPosW_bgo.push_back(bgo_corr[2]*xbgo[2]);
      xPosW_bgo.push_back(bgo_corr[3]*xbgo[3]);
      xPosW_bgo.push_back(bgo_corr[4]*xbgo[4]);
      xPosW_bgo.push_back(bgo_corr[5]*xbgo[5]);
      xPosW_bgo.push_back(bgo_corr[6]*xbgo[6]);
      xPosW_bgo.push_back(bgo_corr[7]*xbgo[7]);
      
      yPosW_bgo.push_back(bgo_corr[0]*ybgo[0]);
      yPosW_bgo.push_back(bgo_corr[1]*ybgo[1]);
      yPosW_bgo.push_back(bgo_corr[2]*ybgo[2]);
      yPosW_bgo.push_back(bgo_corr[3]*ybgo[3]);
      yPosW_bgo.push_back(bgo_corr[4]*ybgo[4]);
      yPosW_bgo.push_back(bgo_corr[5]*ybgo[5]);
      yPosW_bgo.push_back(bgo_corr[6]*ybgo[6]);
      yPosW_bgo.push_back(bgo_corr[7]*ybgo[7]);
      

      xPos_bgo_ = sumVector( xPosW_bgo )/eTot_bgo_corr;
      yPos_bgo_ = sumVector( yPosW_bgo )/eTot_bgo_corr;
      
      h1_xPos_bgo->Fill( xPos_bgo_ );
      h1_yPos_bgo->Fill( yPos_bgo_ );
      h2_xyPos_bgo->Fill( xPos_bgo_, yPos_bgo_ );

      h2_correlation_hodo_bgo_xPos->Fill( xPos_hodo, xPos_bgo_ );
      h2_correlation_hodo_bgo_yPos->Fill( yPos_hodo, yPos_bgo_ );
      
      if( isSingleEle_scintFront ) {

        h1_xPos_singleEle_bgo->Fill( xPos_bgo_ );
        h1_yPos_singleEle_bgo->Fill( yPos_bgo_ );
        h2_xyPos_singleEle_bgo->Fill( xPos_bgo_, yPos_bgo_ );

        h2_correlation_hodo_bgo_xPos_singleEle->Fill( xPos_hodo, xPos_bgo_ );
        h2_correlation_hodo_bgo_yPos_singleEle->Fill( yPos_hodo, yPos_bgo_ );

      }
      
    }  // if bgo ok



    // THEN USE CeF3 DATA:

    if( cef3_ok ) {


      std::vector<float> v_cef3_corr;
      for(unsigned i=0; i<CEF3_CHANNELS; ++i) v_cef3_corr.push_back(cef3_corr[i]);

      float eTot_corr = sumVector(v_cef3_corr);

      

      if( cef3_corr_ok ) {


        //   0      1
        //          
        //          
        //   3      2


        float position = 12. - 0.696; // using FN's infallible trigonometry

        //std::vector

        std::vector<float> xPosW;
        xPosW.push_back(cef3_corr[0]*(-position));
        xPosW.push_back(cef3_corr[1]*(+position));
        xPosW.push_back(cef3_corr[2]*(+position));
        xPosW.push_back(cef3_corr[3]*(-position));

        std::vector<float> yPosW;
        yPosW.push_back(cef3_corr[0]*(+position));
        yPosW.push_back(cef3_corr[1]*(+position));
        yPosW.push_back(cef3_corr[2]*(-position));
        yPosW.push_back(cef3_corr[3]*(-position));


        getCeF3Position( v_cef3_corr, xPos_new_, yPos_new_ );
        //diag02_new_ = xPos_new_;
        //diag13_new_ = yPos_new_;

        float pi = 3.14159;
        float theta = pi/4.; // 45 degrees 
        TVector2 vnew( xPos_new_, yPos_new_ );
        TVector2 dnew = vnew.Rotate(-theta);
        diag02_new_ = dnew.Y();
        diag13_new_ = dnew.X();


        TVector2 vBeam( xBeam, yBeam );
        TVector2 dBeam = vBeam.Rotate(-theta);
        diag02_beam_ = dBeam.Y();
        diag13_beam_ = dBeam.X();

        float xPos = sumVector(xPosW)/eTot_corr;
        float yPos = sumVector(yPosW)/eTot_corr;

        h1_xPos->Fill( xPos );
        h1_yPos->Fill( yPos );

        h2_xyPos->Fill( xPos, yPos );

        h1_xPos_new->Fill( xPos_new_ );
        h1_yPos_new->Fill( yPos_new_ );

        h2_xyPos_new->Fill( xPos_new_, yPos_new_ );


        // positioning with all 9 calorimeter channels:
        //float xPos_calo = sumVector( xPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.07); // cef3 is in 0,0
        //float yPos_calo = sumVector( yPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.08); // so counts only in denominator
        xPos_calo_ = sumVector( xPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.06); // cef3 is in 0,0
        yPos_calo_ = sumVector( yPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.10); // so counts only in denominator
        //float xPos_calo = sumVector( xPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.791577); // cef3 is in 0,0
        //float yPos_calo = sumVector( yPosW_bgo )/(eTot_bgo_corr + eTot_corr*0.791577); // so counts only in denominator

        TVector2 vcalo( xPos_calo_, yPos_calo_ );
        TVector2 dcalo = vcalo.Rotate(-theta);
        diag02_calo_ = dcalo.Y();
        diag13_calo_ = dcalo.X();

        //xPos_regr2D_ = readerRegr2D->EvaluateRegression( "MLP" )[0];
        //yPos_regr2D_ = readerRegr2D->EvaluateRegression( "MLP" )[1];

        cef3_regr[0] = cef3_corr[0]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]);
        cef3_regr[1] = cef3_corr[1]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]);
        cef3_regr[2] = cef3_corr[2]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]);
        cef3_regr[3] = cef3_corr[3]/(cef3_corr[0]+cef3_corr[1]+cef3_corr[2]+cef3_corr[3]);
  
        if( bgo_ok && bgo_corr_ok ) {

          h1_xPos_calo->Fill( xPos_calo_ );
          h1_yPos_calo->Fill( yPos_calo_ );
          h2_xyPos_calo->Fill( xPos_calo_, yPos_calo_ );

          //for( unsigned i=0; i<methodNames.size(); ++i ) {
          //  Float_t xPos_regr = (readerRegrX->EvaluateRegression( methodNames[i] ))[0];
          //  Float_t yPos_regr = (readerRegrY->EvaluateRegression( methodNames[i] ))[0];
          //  h1_xPos_regr_vs_calo[i]->Fill( xPos_regr-xPos_calo_ );
          //  h1_yPos_regr_vs_calo[i]->Fill( yPos_regr-yPos_calo_ );
          //  h2_xyPos_regr[i]->Fill( xPos_regr, yPos_regr );
          //}
          //h2_xyPos_regr2D->Fill( xPos_regr2D_, yPos_regr2D_ );

          h1_xPos_calo_vs_hodo->Fill( xPos_calo_-xPos_hodo );
          h1_yPos_calo_vs_hodo->Fill( yPos_calo_-yPos_hodo );

          h1_xPos_calo_vs_beam->Fill( xPos_calo_-xBeam );
          h1_yPos_calo_vs_beam->Fill( yPos_calo_-yBeam );

          // CORRELATIONS BETWEEN CALO AND HODO:

          h2_correlation_cef3_bgo_xPos->Fill( xPos, xPos_bgo_ );
          h2_correlation_cef3_bgo_yPos->Fill( yPos, yPos_bgo_ );

        }

        if( isSingleEle_scintFront ) {

          h1_xPos_singleEle->Fill( xPos );
          h1_yPos_singleEle->Fill( yPos );
          h2_xyPos_singleEle->Fill( xPos, yPos );

          h1_xPos_new_singleEle->Fill( xPos_new_ );
          h1_yPos_new_singleEle->Fill( yPos_new_ );
          h2_xyPos_new_singleEle->Fill( xPos_new_, yPos_new_ );

          h1_xPos_calo_vs_hodo_singleElectron->Fill( xPos_calo_-xPos_hodo );
          h1_yPos_calo_vs_hodo_singleElectron->Fill( yPos_calo_-yPos_hodo );

          h1_xPos_calo_vs_beam_singleElectron->Fill( xPos_calo_-xBeam );
          h1_yPos_calo_vs_beam_singleElectron->Fill( yPos_calo_-yBeam );

          if( nHodoClustersX==1 && nHodoClustersY==1 && nFibres_hodoClustX[0]<=2 && nFibres_hodoClustY[0]<=2 ) {

            h1_xPos_calo_vs_hodo_singleElectron_HR->Fill( xPos_calo_-xPos_hodo );
            h1_yPos_calo_vs_hodo_singleElectron_HR->Fill( yPos_calo_-yPos_hodo );
  
            h1_xPos_calo_vs_beam_singleElectron_HR->Fill( xPos_calo_-xBeam );
            h1_yPos_calo_vs_beam_singleElectron_HR->Fill( yPos_calo_-yBeam );

          }


          h2_correlation_cef3_hodo_xPos_singleEle->Fill( xPos, xPos_hodo );
          h2_correlation_cef3_hodo_yPos_singleEle->Fill( yPos, yPos_hodo );

  
          if( bgo_ok && bgo_corr_ok ) {

            h1_xPos_singleEle_calo->Fill( xPos_calo_ );
            h1_yPos_singleEle_calo->Fill( yPos_calo_ );
            h2_xyPos_singleEle_calo->Fill( xPos_calo_, yPos_calo_ );

            //for( unsigned i=0; i<methodNames.size(); ++i ) {
            //  Float_t xPos_regr = (readerRegrX->EvaluateRegression( methodNames[i] ))[0];
            //  Float_t yPos_regr = (readerRegrY->EvaluateRegression( methodNames[i] ))[0];
            //  h1_xPos_regr_vs_calo_singleEle[i]->Fill( xPos_regr-xPos_calo_ );
            //  h1_yPos_regr_vs_calo_singleEle[i]->Fill( yPos_regr-yPos_calo_ );
            //  h2_xyPos_singleEle_regr[i]->Fill( xPos_regr, yPos_regr );
            //}

            //h2_xyPos_singleEle_regr2D->Fill( xPos_regr2D_, yPos_regr2D_ );

            h2_correlation_cef3_bgo_xPos_singleEle->Fill( xPos, xPos_bgo_ );
            h2_correlation_cef3_bgo_yPos_singleEle->Fill( yPos, yPos_bgo_ );

          }

        }

        
        outTree->Fill();


      } // if cef3_ok

    }

  }


  outfile->cd();

  outTree->Write();


  for( unsigned i=0; i<h1_xPos_regr_vs_calo.size(); ++i ) {
    h1_xPos_regr_vs_calo[i]->Write();
    h1_yPos_regr_vs_calo[i]->Write();
    h1_xPos_regr_vs_calo_singleEle[i]->Write();
    h1_yPos_regr_vs_calo_singleEle[i]->Write();
    h2_xyPos_regr[i]->Write();
    h2_xyPos_singleEle_regr[i]->Write();
  }




  h1_xPos->Write();
  h1_yPos->Write();
  h2_xyPos->Write();

  h1_xPos_singleEle->Write();
  h1_yPos_singleEle->Write();
  h2_xyPos_singleEle->Write();

  h1_xPos_new->Write();
  h1_yPos_new->Write();
  h2_xyPos_new->Write();

  h1_xPos_new_singleEle->Write();
  h1_yPos_new_singleEle->Write();
  h2_xyPos_new_singleEle->Write();

  
  
  h1_xPos_bgo->Write();
  h1_yPos_bgo->Write();
  h2_xyPos_bgo->Write();
  

  h1_xPos_hodo->Write();
  h1_yPos_hodo->Write();
  h2_xyPos_hodo->Write();

  
  h1_xPos_calo_vs_hodo->Write();
  h1_yPos_calo_vs_hodo->Write();

  h1_xPos_calo_vs_beam->Write();
  h1_yPos_calo_vs_beam->Write();
  
  h1_xPos_calo_vs_hodo_singleElectron->Write();
  h1_yPos_calo_vs_hodo_singleElectron->Write();

  h1_xPos_calo_vs_beam_singleElectron->Write();
  h1_yPos_calo_vs_beam_singleElectron->Write();
  
  h1_xPos_calo_vs_hodo_singleElectron_HR->Write();
  h1_yPos_calo_vs_hodo_singleElectron_HR->Write();

  h1_xPos_calo_vs_beam_singleElectron_HR->Write();
  h1_yPos_calo_vs_beam_singleElectron_HR->Write();
  

  std::cout << std::endl;

  

  h2_correlation_cef3_hodo_xPos->Write();
  h2_correlation_cef3_hodo_yPos->Write();

  h2_correlation_cef3_bgo_xPos->Write();
  h2_correlation_cef3_bgo_yPos->Write();

  h2_correlation_hodo_bgo_xPos->Write();
  h2_correlation_hodo_bgo_yPos->Write();

  h1_xPos_singleEle_bgo->Write();
  h1_yPos_singleEle_bgo->Write();
  h2_xyPos_singleEle_bgo->Write();
  
  h1_xPos_singleEle_hodo->Write();
  h1_yPos_singleEle_hodo->Write();
  h2_xyPos_singleEle_hodo->Write();

  h1_xPos_singleEle_hodoClust->Write();
  h1_yPos_singleEle_hodoClust->Write();
  h2_xyPos_singleEle_hodoClust->Write();

  h1_xPos_calo->Write();
  h1_yPos_calo->Write();
  h2_xyPos_calo->Write();
  
  h1_xPos_singleEle_calo->Write();
  h1_yPos_singleEle_calo->Write();
  h2_xyPos_singleEle_calo->Write();
  

  h2_correlation_cef3_hodo_xPos_singleEle->Write();
  h2_correlation_cef3_hodo_yPos_singleEle->Write();

  h2_correlation_cef3_bgo_xPos_singleEle->Write();
  h2_correlation_cef3_bgo_yPos_singleEle->Write();

  h2_correlation_hodo_bgo_xPos_singleEle->Write();
  h2_correlation_hodo_bgo_yPos_singleEle->Write();


  outfile->Close();
  std::cout << "-> Histograms saved in: " << outfile->GetName() << std::endl;


  return 0;

}
コード例 #12
0
int main( int argc, char* argv[] ) {

  DrawTools::setStyle();
  
  
  std::string tag = "V00";
  std::string config = "SiPM2015Config";
  
  if( argc>1 ) {
    std::string tag_str(argv[1]);
    tag = tag_str;
    if( argc>2 ) {
      std::string config_str(argv[2]);
      config=config_str;
    }
  } else {
    std::cout << "Usage:" << std::endl;
    std::cout << "./timingStudies ([tag]) ([config])" << std::endl;
    exit(12345);
  }

  std::cout<<config<<std::endl;
  
  theConfiguration_=readConfiguration(config);
  


  std::vector<float> energies;
  std::vector<int> wp_channel;
  std::vector<int> wp_fibre;
  std::vector<int> runs;

  for (int i=0;i<theConfiguration_.energies.size();++i){
    energies.push_back(theConfiguration_.energies[i]);
    wp_channel.push_back(theConfiguration_.wp_channel[i]);
    wp_fibre.push_back(theConfiguration_.wp_fibre[i]);
    runs.push_back(theConfiguration_.runs[i]);
  }

  std::string constDirName = "plots_timing_";
  constDirName+=theConfiguration_.setup;
  system(Form("mkdir -p %s", constDirName.c_str()));
  TString dir(constDirName);

  TGraphErrors* resVsEnergy_channel = new TGraphErrors(0);
  TGraphErrors* resVsEnergy_fibre = new TGraphErrors(0);

  std::vector<TGraphErrors*> resVsAmplitude;


  for (int i=0;i<runs.size();++i){
    TString run;
    run.Form("%d",runs[i]); 
    resVsAmplitude.push_back(new TGraphErrors(0));


    TFile* file = TFile::Open(dir+"/timingStudiesSiPM_"+tag+"_"+run+".root");

    if( file==0 ) {
      std::cout << "ERROR! Din't find file for run" << runs[i] << std::endl;
      std::cout << "Exiting." << std::endl;
      exit(11);
    }
    
    //channel
    TVectorD* resValueTime_channel=(TVectorD*)file->Get("resValueTime_channel");
    TVectorD* resErrValueTime_channel=(TVectorD*)file->Get("resErrValueTime_channel");
    TVectorD* resValueAmplitude_channel=(TVectorD*)file->Get("resValueAmplitude_channel");
    TVectorD* resErrValueAmplitude_channel=(TVectorD*)file->Get("resErrValueAmplitude_channel");
    TVectorD* resErrRelativeValueTime_channel=(TVectorD*)file->Get("resErrRelativeValueTime_channel");
    TVectorD* nEntriesTime_channel=(TVectorD*)file->Get("nEntriesTime_channel");

    //fibre
    TVectorD* resValueTime_fibre=(TVectorD*)file->Get("resValueTime_fibre");
    TVectorD* resErrValueTime_fibre=(TVectorD*)file->Get("resErrValueTime_fibre");

    
    //    resVsEnergy->SetPoint( i, energies[i],(*resValueTime)[wp_100[i]] );
    //FIXME    resVsEnergy->SetPointError( i, 0, (*resErrValueTime)[wp_100[i]]);


    resVsEnergy_channel->SetPoint( i, energies[i], (*resValueTime_channel)[wp_channel[i]]);
    resVsEnergy_channel->SetPointError( i, 0,(*resErrValueTime_channel)[wp_channel[i]] );

    resVsEnergy_fibre->SetPoint( i, energies[i], (*resValueTime_fibre)[wp_fibre[i]]);
    resVsEnergy_fibre->SetPointError( i, 0,(*resErrValueTime_fibre)[wp_fibre[i]] );
 

    for (int j=0;j<resValueTime_channel->GetNoElements();j++){
      //      std::cout<<j<<" "<<(*resValueAmplitude_channel)[j]<<std::endl;
      if ((*resValueAmplitude_channel)[j]<10)continue;
      resVsAmplitude[i]->SetPoint(j,(20+j*10),(*resValueAmplitude_channel)[j]);
      resVsAmplitude[i]->SetPointError(j,0,(*resErrValueAmplitude_channel)[j]);
    }

    
  }
  

  TFile * outFile = new TFile(dir+"/plotsTimingStudiesSiPM_"+tag+".root","recreate");

  TCanvas* c1 = new TCanvas( "c1", "", 600, 600 );

  float yup=1.1*(resVsAmplitude[2]->GetY())[0];
  if((resVsAmplitude[2]->GetY())[0]<10) yup = 1.1*(resVsAmplitude[1]->GetY())[0];
  float  xlow=(resVsAmplitude[2]->GetX())[0]-10;
  if(xlow<10)xlow = (resVsAmplitude[1]->GetX())[0]-10;
  float xup=(resVsAmplitude[2]->GetX())[resVsAmplitude[2]->GetN()-1]+10; 
  if(xup<10)xup = (resVsAmplitude[2]->GetX())[resVsAmplitude[2]->GetN()-1]+10; 
  TH2D* h2_axes_2 = new TH2D( "axes_2", "", 100, xlow,xup , 110, 0., yup);

  //  std::cout<<(resVsEnergy_channel->GetY())[0]+(resVsEnergy_channel->GetErrorY(0))<<std::endl;

  TH2D* h2_axes_3 = new TH2D( "axes_1", "", 100, -0.0, 250. , 110, 60., 1.1*((resVsEnergy_channel->GetY())[0]+(resVsEnergy_channel->GetErrorY(0))));  
  h2_axes_3->SetXTitle("Beam Energy [GeV]");
  h2_axes_3->SetYTitle("time_{Fibre}-time_{mcp} [ps]");

  TH2D* h2_axes_4 = new TH2D( "axes_1", "", 100, -0.0, 250. , 110, 60., 1.1*((resVsEnergy_fibre->GetY())[0]+(resVsEnergy_fibre->GetErrorY(0))));  
  h2_axes_4->SetXTitle("Beam Energy [GeV]");
  h2_axes_4->SetYTitle("time_{Fibre}-time_{mcp} [ps]");

  
  //resolution vs energy
  //channel
  TF1* f_ene= new TF1("fun_ene","[1]/x+[0]",(resVsEnergy_channel->GetX())[0]-10,(resVsEnergy_channel->GetX())[resVsEnergy_channel->GetN()-1] +10);

  h2_axes_3->Draw("");
  resVsEnergy_channel->Fit("fun_ene");

  TLegend* lego_2 = new TLegend(0.47, 0.7, 0.8, 0.92);
  lego_2->SetTextSize(0.038);
  lego_2->AddEntry(  (TObject*)0 ,"f(x) = p0 + p1/x", "");
  lego_2->AddEntry(  (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f_ene->GetParameter(0), f_ene->GetParError(0) ), "");
  lego_2->AddEntry(  (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f_ene->GetParameter(1), f_ene->GetParError(1) ), "");
  lego_2->SetFillColor(0);
  lego_2->Draw("same");


  resVsEnergy_channel->SetMarkerStyle(20);
  resVsEnergy_channel->SetMarkerSize(1.6);
  resVsEnergy_channel->SetMarkerColor(kBlue);
  resVsEnergy_channel->Draw("p same");
  resVsEnergy_channel->SetName("resVsEnergy_channel");
  resVsEnergy_channel->Write();

  c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_channel.png");
  c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_channel.pdf");  
  //fibre
  h2_axes_4->Draw("");
  resVsEnergy_fibre->Fit("fun_ene");

  lego_2->Clear();
  lego_2->SetTextSize(0.038);
  lego_2->AddEntry(  (TObject*)0 ,"f(x) = p0 + p1/x", "");
  lego_2->AddEntry(  (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f_ene->GetParameter(0), f_ene->GetParError(0) ), "");
  lego_2->AddEntry(  (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f_ene->GetParameter(1), f_ene->GetParError(1) ), "");
  lego_2->SetFillColor(0);
  lego_2->Draw("same");


  resVsEnergy_fibre->SetMarkerStyle(20);
  resVsEnergy_fibre->SetMarkerSize(1.6);
  resVsEnergy_fibre->SetMarkerColor(kBlue);
  resVsEnergy_fibre->Draw("p same");
  resVsEnergy_fibre->SetName("resVsEnergy_fibre");
  resVsEnergy_fibre->Write();

  c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_fibre.png");
  c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_fibre.pdf");  

  for(int i=0;i<runs.size();++i){ 
    TString ene;
    ene.Form("%.0f",energies[i]); 
    std::string energy(Form("%.0f", energies[i]));

    h2_axes_2->SetYTitle("#sigma_{t} [ps]");
    h2_axes_2->GetXaxis()->SetTitle("Amplitude [ADC]");
    h2_axes_2->Draw(""); 

    TF1* f= new TF1("fun","[1]/x+[0]",(resVsAmplitude[i]->GetX())[0]-10,(resVsAmplitude[i]->GetX())[resVsAmplitude[i]->GetN()-1] +10);
    resVsAmplitude[i]->Fit("fun");

    resVsAmplitude[i]->SetName("resVsAmplitude_"+ene);
    resVsAmplitude[i]->SetMarkerStyle(20);
    resVsAmplitude[i]->SetMarkerSize(1.6);
    resVsAmplitude[i]->SetMarkerColor(kBlue);
    resVsAmplitude[i]->Draw("p same");


    TPaveText* pave = DrawTools::getLabelTop_expOnXaxis(energy+" GeV Electron Beam");
    pave->Draw("same");



    TLegend* lego = new TLegend(0.47, 0.7, 0.8, 0.92);
    lego->SetTextSize(0.038);
    lego->AddEntry(  (TObject*)0 ,"f(x) = p0 + p1/x", "");
    lego->AddEntry(  (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f->GetParameter(0), f->GetParError(0) ), "");
    lego->AddEntry(  (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f->GetParameter(1), f->GetParError(1) ), "");
    lego->SetFillColor(0);
    lego->Draw("same");

    c1->SaveAs(dir+"/timingResolutionVsAmplitudeSiPM_"+ene+"GeV.png");
    c1->SaveAs(dir+"/timingResolutionVsAmplitudeSiPM_"+ene+"GeV.pdf");  

 

    resVsAmplitude[i]->Write();
  }

  outFile->Write();
  outFile->Close();

  return 0;

}
コード例 #13
0
ファイル: plotterMaps.cpp プロジェクト: CeF3TB/H4_2015
int main( int argc, char* argv[] ) {

  DrawTools::setStyle();

  std::string tag = "V00";
  std::string config = "SiPM2015Config";
  
  if( argc>1 ) {
    std::string tag_str(argv[1]);
    tag = tag_str;
    if( argc>2 ) {
      std::string config_str(argv[2]);
      config=config_str;
    }
  } else {
    std::cout << "Usage:" << std::endl;
    std::cout << "./plotterMaps ([tag]) ([config])" << std::endl;
    exit(12345);
  }

  std::cout<<config<<std::endl;
  
  theConfiguration_=readConfiguration(config);

  std::string constDirName = "plots_maps_";
  constDirName+=theConfiguration_.setup;
  if(theConfiguration_.addTagFileName){
    constDirName+="_";
    constDirName+=theConfiguration_.tagFileName;
  }
  system(Form("mkdir -p %s", constDirName.c_str()));

  
  TString dir(constDirName);



  std::vector<int> runs;
  std::vector<float> energies;
  for (int i=0;i<theConfiguration_.runs.size()+1;++i){//+1 for all the run together
    if(i<theConfiguration_.runs.size()){
      runs.push_back(theConfiguration_.runs[i]);
      energies.push_back(theConfiguration_.energies[i]);
    }

    TString filename= "plots_timing_"+theConfiguration_.setup+"/timingStudiesSiPM_"+tag+"_";

    if(i<theConfiguration_.runs.size()){
      filename+=runs[i];
    }else{
      filename+="total";
    }
    filename+=".root";

    TFile* file = TFile::Open(filename.Data());
    
    TH2F* timing_map_total=(TH2F*)file->Get("timing_map_channel");
    TH2F* amplitude_map_total=(TH2F*)file->Get("amplitude_map_channel");
    TH2F* amplitude_map_fibre2=(TH2F*)file->Get("amplitude_map_fibre2");

    TH2F* timing_map_sel_channel=(TH2F*)file->Get("timing_map_sel_channel");
    TH2F* amplitude_map_sel_channel=(TH2F*)file->Get("amplitude_map_sel_channel");

    TH2F* timing_map_sel_fibre=(TH2F*)file->Get("timing_map_sel_fibre");
    TH2F* amplitude_map_sel_fibre=(TH2F*)file->Get("amplitude_map_sel_fibre");

    TH1F* maxAmpl_sel_fibre=(TH1F*)file->Get("maxAmpl_sel_fibre");
    TH1F* maxAmpl_sel_channel=(TH1F*)file->Get("maxAmpl_sel_channel");


    TString runString;
    if(i<theConfiguration_.runs.size()){
      runString+=runs[i];
    }else{
      runString+="total";

      //for total we do normalized plots
      float max= amplitude_map_total->GetMaximum();
      amplitude_map_total->Scale(1./max);
      amplitude_map_total->SetAxisRange(0,1,"Z");
      
      max= amplitude_map_fibre2->GetMaximum();
      amplitude_map_fibre2->Scale(1./max);
      amplitude_map_fibre2->SetAxisRange(0,1,"Z");
      
      max= amplitude_map_sel_channel->GetMaximum();
      amplitude_map_sel_channel->Scale(1./max);
      amplitude_map_sel_channel->SetAxisRange(0,1,"Z");
     
      max= amplitude_map_sel_fibre->GetMaximum();
      amplitude_map_sel_fibre->Scale(1./max);
      amplitude_map_sel_fibre->SetAxisRange(0,1,"Z");

      //timing should be scaled for number of files after hadd      
      timing_map_total->Scale(1./runs.size());
      timing_map_total->SetAxisRange(-0.1,0.9,"Z");

      timing_map_sel_channel->Scale(1./runs.size());
      timing_map_sel_channel->SetAxisRange(-0.1,0.9,"Z");

      timing_map_sel_fibre->Scale(1./runs.size());
      timing_map_sel_fibre->SetAxisRange(-0.1,0.6,"Z");

    }


    gStyle->SetPadRightMargin(0.17);//for the palette
    TCanvas c1;
    amplitude_map_total->Draw("colz");
    c1.SaveAs(dir+"/amplitude_map_"+runString+".pdf");
    c1.SaveAs(dir+"/amplitude_map_"+runString+".png");

    c1.Clear();
    amplitude_map_fibre2->Draw("colz");
    c1.SaveAs(dir+"/amplitude_map_fibre2_"+runString+".pdf");
    c1.SaveAs(dir+"/amplitude_map_fibre2_"+runString+".png");


    c1.Clear();
    timing_map_total->Draw("colz");
    c1.SaveAs(dir+"/timing_map_"+runString+".pdf");
    c1.SaveAs(dir+"/timing_map_"+runString+".png");

    c1.Clear();
    amplitude_map_sel_channel->Draw("colz");
    c1.SaveAs(dir+"/amplitude_map_sel_channel"+runString+".pdf");
    c1.SaveAs(dir+"/amplitude_map_sel_channel"+runString+".png");

    c1.Clear();
    timing_map_sel_channel->Draw("colz");
    c1.SaveAs(dir+"/timing_map_sel_channel"+runString+".pdf");
    c1.SaveAs(dir+"/timing_map_sel_channel"+runString+".png");

    c1.Clear();
    amplitude_map_sel_fibre->Draw("colz");
    c1.SaveAs(dir+"/amplitude_map_sel_fibre"+runString+".pdf");
    c1.SaveAs(dir+"/amplitude_map_sel_fibre"+runString+".png");

    c1.Clear();
    timing_map_sel_fibre->Draw("colz");
    c1.SaveAs(dir+"/timing_map_sel_fibre"+runString+".pdf");
    c1.SaveAs(dir+"/timing_map_sel_fibre"+runString+".png");

    gStyle->SetPadRightMargin(0.10);
    TCanvas c2;
    maxAmpl_sel_channel->GetXaxis()->SetRangeUser(0,800.);
    maxAmpl_sel_channel->SetLineWidth(2);
    maxAmpl_sel_fibre->SetLineWidth(2);
    maxAmpl_sel_channel->DrawNormalized();
    maxAmpl_sel_fibre->DrawNormalized("same");



    if(i<theConfiguration_.runs.size()){
      std::string energy(Form("%.0f",energies[i]));
      TPaveText* pave = DrawTools::getLabelTop_expOnXaxis(energy+" GeV Electron Beam");
      pave->Draw("same");
    }else{
      std::string energy(Form("%.0f",energies[i]));
      TPaveText* pave = DrawTools::getLabelTop_expOnXaxis("Electron Beam");
      pave->Draw("same");
    }

    c2.SaveAs(dir+"/maxAmpl_comparison_"+runString+".pdf");
    c2.SaveAs(dir+"/maxAmpl_comparison_"+runString+".png");

  }

}
コード例 #14
0
int main( int argc, char* argv[] ) {

  std::string runName = "precalib_BGO_pedestal_noSource";
  std::string tag = "default";
  if( argc>2 ) {
    std::string runName_str(argv[1]);
    runName = runName_str;
    std::string tag_str(argv[2]);
    tag = tag_str;
  }else{
    std::cout<<"Usage:"<<std::endl;
    std::cout<<"./makeSimulationToAnalysisTree BeamEnergy(in MeV) tag"<<std::endl;
    exit(12345);
  }

  TString runName_tstr(runName);


  bool isIdeal = false;

  //run name = energy for now, might have to change this for different beams...
    std::string fileName = "OriginalSimulationData/EEShash" + runName + ".root";
    TFile* file = TFile::Open(fileName.c_str());
    if( file==0 ) {
    std::string fileName = "OriginalSimulationData/EEShashIdeal_" + runName + ".root";
    TFile* file = TFile::Open(fileName.c_str());
    isIdeal = true;
    }
    if( file==0 ) {
      std::cout << "ERROR! Din't find file " << fileName << std::endl;
      std::cout << "Exiting." << std::endl;
      exit(11);
    }

  TChain* tree = new TChain("EEShash");
  tree = (TChain*)file->Get("EEShash");





  //std::string outdir = "analysisTrees_" + tag;
  std::string outdir = "OriginalSimulationData";
  system( Form("mkdir -p %s", outdir.c_str()) );
  std::string outfileName;
  if(isIdeal==0){ outfileName = outdir + "/Reco_Simulation" + runName + ".root";}
  else { outfileName = outdir + "/Reco_Simulation_Ideal_" + runName + ".root";}
  TFile* outfile = TFile::Open( outfileName.c_str(), "RECREATE" );
  

  TTree* outTree = new TTree("recoTree","recoTree");

  double Eact_0;
  tree->SetBranchAddress("Eact_0", &Eact_0);
  double Eact_1;
  tree->SetBranchAddress("Eact_1", &Eact_1);
  double Eact_2;
  tree->SetBranchAddress("Eact_2", &Eact_2);
  double Eact_3;
  tree->SetBranchAddress("Eact_3", &Eact_3);
  double Eact_4;
  tree->SetBranchAddress("Eact_4", &Eact_4);
  double Eact_5;
  tree->SetBranchAddress("Eact_5", &Eact_5);
  double Eact_6;
  tree->SetBranchAddress("Eact_6", &Eact_6);
  double Eact_7;
  tree->SetBranchAddress("Eact_7", &Eact_7);
  double Eact_8;
  tree->SetBranchAddress("Eact_8", &Eact_8);
  double Eact_9;
  tree->SetBranchAddress("Eact_9", &Eact_9);
  double Eact_10;
  tree->SetBranchAddress("Eact_10", &Eact_10);

  double Eact_11;
  tree->SetBranchAddress("Eact_11", &Eact_11);
  double Eact_12;
  tree->SetBranchAddress("Eact_12", &Eact_12);
  double Eact_13;
  tree->SetBranchAddress("Eact_13", &Eact_13);
  double Eact_14;
  tree->SetBranchAddress("Eact_14", &Eact_14);


  double Ebgo_0;
  tree->SetBranchAddress( "Ebgo_0", &Ebgo_0);
  double Ebgo_1;
  tree->SetBranchAddress( "Ebgo_1", &Ebgo_1);
  double Ebgo_2;
  tree->SetBranchAddress( "Ebgo_2", &Ebgo_2);
  double Ebgo_3;
  tree->SetBranchAddress("Ebgo_3", &Ebgo_3);
  double Ebgo_4;
  tree->SetBranchAddress("Ebgo_4", &Ebgo_4);
  double Ebgo_5;
  tree->SetBranchAddress("Ebgo_5", &Ebgo_5);
  double Ebgo_6;
  tree->SetBranchAddress("Ebgo_6", &Ebgo_6);
  double Ebgo_7;
  tree->SetBranchAddress("Ebgo_7", &Ebgo_7);

  double Ebgo;
  tree->SetBranchAddress("Ebgo", &Ebgo);

  double Eabs;
  tree->SetBranchAddress("Eabs", &Eabs);
  double Eact;
  tree->SetBranchAddress("Eact", &Eact);

  double Escint1;
  tree->SetBranchAddress("Escint1", &Escint1);

  double Ehodo11;
  tree->SetBranchAddress("Ehodo11", &Ehodo11);

  double Ehodo12;
  tree->SetBranchAddress("Ehodo12", &Ehodo12);


  double Escint;
  tree->SetBranchAddress("Escint", &Escint);

  double Ehodo;
  tree->SetBranchAddress("Ehodo", &Ehodo);

  double xPosition;
  tree->SetBranchAddress("xPosition",&xPosition);
  double yPosition;
  tree->SetBranchAddress("yPosition",&yPosition);


  float cef3_corr_[CEF3_CHANNELS],bgo_corr_[BGO_CHANNELS];
  bool isSingleEle_scintFront_=1;
  int nHodoClustersY=1; int nHodoClustersX=1;
  int nHodoClusters1Y=1; int nHodoClusters1X=1;
  float E_abs;

  float xPos;
  float yPos;

  int bgo_chan=BGO_CHANNELS;
  int cef3_chan=CEF3_CHANNELS;

  outTree->Branch( "nHodoClustersX", &nHodoClustersX, "nHodoClustersX/I" );
  outTree->Branch( "nHodoClustersY", &nHodoClustersY, "nHodoClustersY/I" );
  outTree->Branch( "nHodoClusters1X", &nHodoClusters1X, "nHodoClusters1X/I" );
  outTree->Branch( "nHodoClusters1Y", &nHodoClusters1Y, "nHodoClusters1Y/I" );

  outTree->Branch( "cef3_chan", &cef3_chan, "cef3_chan/I" );
  outTree->Branch( "bgo_chan", &bgo_chan, "bgo_chan/I" );

  outTree->Branch( "bgo_corr", bgo_corr_, "bgo_corr_[bgo_chan]/F" );
  outTree->Branch( "cef3_corr", cef3_corr_, "cef3_corr_[cef3_chan]/F" );

  outTree->Branch( "isSingleEle_scintFront", &isSingleEle_scintFront_, "isSingleEle_scintFront_/O" );

  outTree->Branch( "E_abs", &E_abs, "E_abs/F");

  outTree->Branch( "xPos", &xPos, "xPos/F");
  outTree->Branch( "yPos", &yPos, "yPos/F");


  float LYSF[] = {0.85, 0.94, 0.95, 0.98, 1.00, 1.02, 1.05, 1.05, 1.05, 0.74};

  // float LYSF[] = {0.85, 0.94, 0.95, 0.98, 1.00, 0.7, 1.05, 1.05, 1.05, 0.74};

  // float LYSF[] =  {0.87, 0.96, 0.97, 1.00, 1.02, 1.04, 1.07, 1.07, 1.08, 0.75};
  //as a test with the best being the best one
  //  float LYSF[] =  {0.81, 0.89, 0.90, 0.93, 0.95, 0.97, 1.00, 1.00, 1.00, 0.70};


  //Test if 6.crystal fails
  //  float LYSFH[] = {0.87, 0.96, 0.97, 1.00, 1.02, 0.50, 1.07, 1.07, 1.08, 1.07, 1.08, 1.09, 1.09, 1.04, 0.75};
  ///



   float LYSFH[] = {0.87, 0.96, 0.97, 1.00, 1.02, 1.04, 1.07, 1.07, 1.08, 1.07, 1.08, 1.09, 1.09, 1.04, 0.75};

  /*
    std::string fullVarName = "";
    for( unsigned i=0; i<15; ++i ) {
    std::string plusSign = (i==0) ? "" : " + ";
    std::string thisPiece(Form("%s%f*Eact_%d", plusSign.c_str(), LYSFH[i], i));
    fullVarName += thisPiece;
    }
  
  */
  
  unsigned nentries = tree->GetEntries();
  
  double hodoEff;
  double scintEff;
  
  for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) {
    
    tree->GetEntry(iEntry);
    
    if( iEntry % 5000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl;
 
 
        
    xPos = xPosition;
    yPos = yPosition;
    
    if(Ehodo11>0.1){
       nHodoClustersX=1;
      hodoEff++;
    } else{   nHodoClusters1X=0;}

    if(Ehodo12>0.1){
      nHodoClustersY=1; 
      hodoEff++;
    } else{   nHodoClusters1Y=0; }
   
    
    if(Escint1>0.25){
      isSingleEle_scintFront_=1;
      scintEff++;
    } else{       isSingleEle_scintFront_=0;}
    
   
 
   


    if(Ehodo>0.1){
       nHodoClustersX=1; nHodoClustersY=1;
      hodoEff++;
    } else{   nHodoClustersX=0;  nHodoClustersY=0;}
  
    /*
    if(Escint>0.25 && Escint< 1.5){
      isSingleEle_scintFront_=1;
      scintEff++;
    } else{       isSingleEle_scintFront_=0;}     
    */ 
    
    E_abs= Eabs;


    
    std::vector<float> cef3_corr;
    for( int i=0; i<CEF3_CHANNELS; ++i ) cef3_corr.push_back(-1.);
    
    std::vector<float> bgo_corr;
    for( int i=0; i<BGO_CHANNELS; ++i ) bgo_corr.push_back(-1.);
 
    /*
     
     for(int i=0; i<10; ++i){
     cef3_corr[0]= (LYSF[0]*Eact_0+LYSF[1]*Eact_1+LYSF[2]*Eact_2 +LYSF[3]*Eact_3 +LYSF[4]*Eact_4 +LYSF[5]*Eact_5 +LYSF[6]*Eact_6 +LYSF[7]*Eact_7 +LYSF[8]*Eact_8 +LYSF[9]*Eact_9)/4. ; //yes not very elegant, but it didn't want to work otherwise
     // cef3_corr[0] = Eact /4.;
     }
    */
      
  
    
    for(int i=0; i<15; ++i){
      cef3_corr[0]= (LYSFH[0]*Eact_0+LYSFH[1]*Eact_1+LYSFH[2]*Eact_2 +LYSFH[3]*Eact_3 +LYSFH[4]*Eact_4 +LYSFH[5]*Eact_5 +LYSFH[6]*Eact_6 +LYSFH[7]*Eact_7 +LYSFH[8]*Eact_8 +LYSFH[9]*Eact_9 +LYSFH[10]*Eact_10  +LYSFH[11]*Eact_11 +LYSFH[12]*Eact_12 +LYSFH[13]*Eact_13  +LYSFH[14]*Eact_14 )/4. ; //yes not very elegant, but it didn't want to work otherwise

      //  cef3_corr[0] = Eact /4.;
     }   
    

    
    bgo_corr[0] = Ebgo/8.;
    bgo_corr[1] = Ebgo/8.;
    bgo_corr[2] = Ebgo/8.;
    bgo_corr[3] = Ebgo/8.;
    bgo_corr[4] = Ebgo/8.;
    bgo_corr[5] = Ebgo/8.;
    bgo_corr[6] = Ebgo/8.;
    bgo_corr[7] = Ebgo/8.;
    
    
    for(int k=0; k<CEF3_CHANNELS; ++k){
      cef3_corr_[k] = cef3_corr[0];
    }
    
    for (int k=0; k<BGO_CHANNELS; ++k){ 
      bgo_corr_[k] = bgo_corr[k];
    }
    
    
    outTree->Fill();
  }
  
  
  outfile->cd();
  outTree->Write();
  outfile->Close();
  
  std::cout << "-> Simulated Analysis Tree saved in: " << outfile->GetName() << std::endl;

  std::cout << "Scintillator efficiency = " << scintEff/nentries << std::endl;
  std::cout << "Hodoscope efficiency = " << hodoEff/nentries << std::endl;
 

  return 0;

}