Ejemplo n.º 1
0
//========================================================================
void joingraphsX(const char* myname, const char* g1 , int autocolors=1 ){

TMultiGraph *mg;
 TString myname2=myname;
 myname2.ReplaceAll(".","_"); 
 myname2.ReplaceAll(" ","_"); 
 myname2.ReplaceAll("_mysql_dat","_mysql_MG"); 
 if (  ( gROOT->GetListOfSpecials()->FindObject(myname2.Data()) )  ||
       ((gPad!=NULL)&&(gPad->FindObject(myname2.Data()) ))  ){
   mg=(TMultiGraph*)gROOT->GetListOfSpecials()->FindObject( myname2.Data() );
   if (mg==NULL){mg=(TMultiGraph*)gPad->FindObject( myname2.Data() );}
   printf("JG...TMultiGraph %s found...\n",myname2.Data() );
 }else{
   printf("JG...TMultiGraph %s created\n",myname2.Data() );
  mg=new TMultiGraph();
  mg->SetNameTitle(myname2.Data(),myname2.Data());
  gROOT->GetListOfSpecials()->Add( mg );
 }
 TGraphErrors *o;
 o=(TGraphErrors*)gROOT->GetListOfSpecials()->FindObject( g1 );
 if (o==NULL){ o=(TGraphErrors*)gDirectory->FindObject( g1 ); }
if (o==NULL){
  printf("JG...graph %ld NOT found...\n", (int64_t)g1 );
 }else{

  int ent=0;
  if ( mg->GetListOfGraphs()!=NULL){
    ent=mg->GetListOfGraphs()->GetEntries();
  }
  //  ent=1;
  printf("JG...multigraph entries =%d\n", ent);


  //  if (mg->GetListOfGraphs()->FindObject(o->GetTitle())==NULL){
  TGraphErrors *grexi=NULL;
  TList *glog= mg->GetListOfGraphs();
  if (glog!=NULL){grexi=(TGraphErrors*)glog->FindObject(o->GetName()) ;}

  printf("JG...TEST1 Graph name %s  ---------------\n", 
	 o->GetName() );
  if (grexi!=NULL){
    int col=grexi->GetLineColor();
    printf("JG...Graph name %s exists, color=%d doing nothing\n", o->GetName() ,  col );
    printf("%s\n","JG   removing");
    mg->RecursiveRemove(grexi);
    printf("%s\n","JG  adding");
    mg->Add(  (TGraphErrors*)o  , "PL"  )  ;
    o->SetLineColor(col);
    o->SetMarkerColor(col);
  }else{
    //    printf("TEST2 Graph name %s not yet in MG\n",o->GetName()  );
    if (autocolors==1){ // for new
      //      printf("setting autocolor %d\n",  ent);
      o->SetLineColor(ent+1);
      o->SetMarkerColor(ent+1);
    }else{
      //      printf("NO autocolor (graphs=%d)\n",  ent);
    }
    // char oname[100];
    // sprintf(oname,"%s",o->GetName());
    // printf("%s /%s/\n", "JG...  looking for duplicity", oname );

    // TObject *dupl=NULL;
    // if ( (o!=NULL)&&(mg->GetListOfGraphs()!=NULL)){ dupl=(TObject*)mg->GetListOfGraphs()->FindObject( oname ); }
    // printf("%s\n", "JG...  looking for duplicity" );
    // if (dupl!=NULL){
    //   printf("%s\n", "JG...    duplicite  found" );
    //   for (int i=0;i<mg->GetListOfGraphs()->GetEntries();i++){
    // 	if (mg->GetListOfGraphs()->At(i)==dupl){
    // 	  mg->GetListOfGraphs()->RemoveAt(i);
    // 	  break;
    // 	}
    //   }
    // }
    printf("%s\n", "JG...  adding the object" );
    mg->Add(  (TGraphErrors*)o  , "PL"  )  ;
  }//=========else NEW
  double ttmax=0.,ttmin=0.;
  for (int i=0;i<mg->GetListOfGraphs()->GetEntries();i++){
    printf("JG...  %d. %10s,  total=%d\n", i, 
	   mg->GetListOfGraphs()->At(i)->GetName(),mg->GetListOfGraphs()->GetEntries() );
    TGraphErrors *ge=(TGraphErrors*)mg->GetListOfGraphs()->At(i);
    int n = ge->GetN();
    double* x = ge->GetX();
    int locmin = TMath::LocMin(n,x);
    double tmin = x[locmin];
    int locmax = TMath::LocMax(n,x);
    double tmax = x[locmax];
    if (ttmin==ttmax){ttmax=tmax;ttmin=tmin;}
    //    printf("%f  -  %f\n", tmin, tmax);
    if (ttmax<tmax){ttmax=tmax;}
    if (ttmin>tmin){ttmin=tmin;}
    //    printf("%d. %s\n", i, mg->GetListOfGraphs()->At(i)->GetTitle() );
  }// for all graphs
  
  if (mg->GetXaxis()!=NULL){ // if not drawn, no possibility to change-refresh!
    mg->GetXaxis()->SetLimits(  ttmin,ttmax );
    mg->GetXaxis()->SetTimeDisplay(1);
    mg->GetXaxis()->SetTimeFormat("#splitline{%d.%m}{%H:%M}");
  }
  
    //    printf("Graph title %s added, exists=%d\n", o->GetTitle(), grexi );
    //  }else{
    //   mg->RecursiveRemove(  (TGraphErrors*)o  )  ;
    //  }
 }//graph found?

 //  gROOT->GetListOfSpecials()->Add(  gROOT->GetListOfSpecials()->FindObject( g1 )   );
 //// for (int i=0;i<imax;i++){  mg->Add( gg[i],"lp");  }

}////========== void joingraphsX(const char* myname, const char* g1 ){ ================
Ejemplo n.º 2
0
int main( int argc, char* argv[] )
{
	//	Mute ROOT
	gErrorIgnoreLevel = kFatal;
	title();
	usage();

	//	If we were provided no input files, exit 'cleanly'
	if( argc < 2 ) exit(-42);

	//	Use UUID based seed from ROOT, just used primarily for unique identification of ROOT objects
	TRandom3* rand_gen = new TRandom3();

	//	Setup the Canvas and such
	EdStyle* RapidFit_Style = new EdStyle();
	RapidFit_Style->SetStyle();

	vector<string> input_filenames;
	vector<string> other_params;
	for( int i=1; i< argc; ++i )
	{
		if( argv[i][0] == '-' )	other_params.push_back( argv[i] );
		else	input_filenames.push_back( argv[i] );
	}

	string helpOption="--help";
	string helpOption2="-help";
	if( StringOperations::VectorContains( &other_params, &helpOption ) != -1 || StringOperations::VectorContains( &other_params, &helpOption2 ) != -1 )
	{
		helpFunction();
		exit(0);
	}

	string SummeriseText="--Summarise";
	string SummeriseText2="-Summarise";
	if( StringOperations::VectorContains( &other_params, &SummeriseText ) != -1 || StringOperations::VectorContains( &other_params, &SummeriseText2 ) != -1 )
	{
		Summarise( input_filenames, other_params );
		exit(0);
	}

	string restoreXML="--RestoreXML";
	string restoreXML2="-RestoreXML";
	if( StringOperations::VectorContains( &other_params, &restoreXML ) != -1 || StringOperations::VectorContains( &other_params, &restoreXML2 ) != -1 )
	{
		RestoreXML( input_filenames, other_params );
		exit(0);
	}

	vector<TTree*> input_trees = ROOT_File_Processing::GetMultipleTrees( input_filenames, RapidFitOutputTupleName );

	string CorrMatrixName="corr_matrix";
	vector<TTree*> corr_trees = ROOT_File_Processing::GetMultipleTrees( input_filenames, CorrMatrixName );

	if( !corr_trees.empty() )
	{
		vector<string> argv_str;
		for( unsigned int i=0; i< (unsigned) argc; ++i ) argv_str.push_back( argv[i] );
		string CorrMatrix = "--CorrMatrix";
		if( StringOperations::VectorContains( &argv_str , &CorrMatrix ) != -1 )
		{
			CorrMatrix::Analyse( corr_trees, other_params );
		}
	}

	int good_files=0;
	for( unsigned int i=0; i< input_trees.size(); ++i )
	{
		if( input_trees[i] != NULL ) ++good_files;
	}

	vector<pair<string,string> > Directories_in_file;
	TFile* ProjFile=NULL;
	if( good_files==0 )
	{
		ProjFile = ROOT_File_Processing::OpenFile( argv[1] );
		(void) ProjFile;
		TString top_dir = gDirectory->GetPath();

		ROOT_File_Processing::get_TDirectory_list( top_dir, &Directories_in_file );
		if( Directories_in_file.size() != 0 ) ++good_files;
	}

	if( good_files == 0 )
	{
		cerr << "\n\tNo usable files found as arguments, exiting...\n" << endl;
		exit(-99);
	}


	//	Construct study_to_plot objects for each input tree found

	vector<struct study_to_plot*> Studies_to_Plot;

	for( unsigned int file_i=0; file_i < input_trees.size(); ++file_i )
	{
		vector<string> controlled_parameters_scan = RapidFit_Output_File::get_control_parameters( input_trees[file_i] );

		vector<string> controlled_parameters;
		for( vector<string>::iterator index_i = controlled_parameters_scan.begin(); index_i != controlled_parameters_scan.end(); ++index_i )
		{
			controlled_parameters.push_back( StringOperations::RemoveSuffix( *index_i, "_scan" ).Data() );
		}
		struct study_to_plot* this_study = new study_to_plot;

		if( controlled_parameters.empty() )
		{
			cout << "No controlled parameters." << endl;
			this_study->tree_to_plot = input_trees[file_i];
			Studies_to_Plot.push_back( this_study );
			continue;
		}


		bool has_toys = RapidFit_Output_File::HasToys( input_trees[file_i], controlled_parameters, rand_gen );

		this_study->control_parameters = controlled_parameters;
		this_study->tree_to_plot = input_trees[file_i];
		this_study->found_toys = has_toys;

		Studies_to_Plot.push_back( this_study );
	}

	//	Perform analysis

	//	Construct Objects which must be used to store the result from mutliple scans for merging the output
	TMultiGraph* GraphsToOverlay = new TMultiGraph( "top_level_overlay", "top_level_overlay" );

	TString Here = TString( gSystem->pwd() );
	for( vector<struct study_to_plot*>::iterator study_i =  Studies_to_Plot.begin(); study_i != Studies_to_Plot.end(); ++study_i )
	{
		if( (*study_i)->control_parameters.empty() == true )
		{
			cout << "\n\tFound 0 Scanned Parameters but found fit data, performing Toy Study Analysis.\n" << endl;
			ToyStudyAnalysis::Toy_Study( (*study_i)->tree_to_plot, rand_gen, other_params );
		}
		else
		{
			if( (*study_i)->found_toys == true )
			{
				cout << "\n\tFound Toys in a file used to perform a scan, performing a FelmanCousins Analysis.\n" << endl;
				FeldmanCousinsAnalysis::DoFCAnalysis( (*study_i)->tree_to_plot, (*study_i)->control_parameters, rand_gen, other_params );
			}
			else
			{
				if( (*study_i)->control_parameters.size() == 1 )
				{
					cout << "\n\tPlotting the Results in LLscan format.\n" << endl;
					TGraph* thisGraph = RapidLL::PlotRapidLL( (*study_i)->control_parameters[0], (*study_i)->tree_to_plot, rand_gen, other_params );
					GraphsToOverlay->Add( thisGraph );
				}
				else if( (*study_i)->control_parameters.size() == 2 )
				{
					//Rapid2DLL::PlotRapid2DLL( (*study_i)->control_parameters[0], (*study_i)->control_parameters[1], (*study_i)->tree_to_plot, rand_gen, other_params );
					Rapid2DLL::PlotRapidFit2DLL( (*study_i)->control_parameters[0], (*study_i)->control_parameters[1], (*study_i)->tree_to_plot, rand_gen, other_params );
				}
			}
		}
		gSystem->cd( Here );
	}

	//	Merge multiple outputs
	if( GraphsToOverlay->GetListOfGraphs() != NULL )
	{
		if( GraphsToOverlay->GetListOfGraphs()->Capacity() > 1 )
		{
			RapidLL::OverlayMutliplePlots( GraphsToOverlay );
		}
	}
	//	2D case possible to be written but as of this time 2012/10 There is no useful call to write this so it has not been addressed

	cout << endl;
	cout << "Any segfaults beyond here are likely problems with ROOT..." << endl;
	cout << "Goodbye from RapidPlot :D" << endl;
	cout << endl;

	return 0;
}
Ejemplo n.º 3
0
  /** 
   * Process a single type - i.e., one of <i>symmetric</i>,
   * <i>positive</i>, <i>negative</i>, or <i>other</i> - by looping
   * over all contained objects and call ProcessBin for each found
   * bin.
   * 
   * @param measured     Input collection of measured data
   * @param corrections  Input collection of correction data
   * @param method       Unfolding method to use 
   * @param regParam     Regularisation parameter
   * @param out          Output directory. 
   * @param sys          Collision system
   * @param sNN          Collision energy 
   */
  void ProcessType(TCollection* measured, 
		   TCollection* corrections,
		   UInt_t       method,
		   Double_t     regParam,
		   TDirectory*  out,
		   UShort_t     sys, 
		   UShort_t     sNN)
  {
    Printf("  Processing %s ...", measured->GetName());
    TDirectory* dir = out->mkdir(measured->GetName());
    
    // Make some summary stacks 
    THStack*  allMeasured  = new THStack("measured",      
					 "Measured P(#it{N}_{ch})");
    THStack*  allTruth     = new THStack("truth",        
					 "MC 'truth' P(#it{N}_{ch})");
    THStack*  allTruthA    = new THStack("truthAccepted",
					 "MC 'truth' accepted P(#it{N}_{ch})");
    THStack*  allUnfolded  = new THStack("unfolded",
					 "Unfolded P(#it{N}_{ch})");
    THStack*  allCorrected = new THStack("corrected",
					 "Corrected P(#it{N}_{ch})");
    THStack*  allRatio     = (sys != 1 ? 0 : 
			      new THStack("ratios", "Ratios to other"));
    TMultiGraph* allALICE  = (sys != 1 ? 0 : 
			      new TMultiGraph("alice", "ALICE Published"));
    TMultiGraph* allCMS    = (sys != 1 ? 0 : 
			      new TMultiGraph("cms", "CMS Published"));

    // Loop over the list of objects. 
    static TRegexp regex("[pm][0-9]d[0-9]*_[pm][0-9]d[0-9]*");
    TIter          next(measured);
    TObject*       o = 0;
    Int_t          i = 0;
    Double_t       r = regParam;
    while ((o = next())) {
      // Go back to where we where 
      dir->cd();
      
      // if not a collection, don't bother 
      if (!o->IsA()->InheritsFrom(TCollection::Class())) continue;
    
      // If it doesn't match our regular expression, don't bother 
      TString n(o->GetName());
      if (n.Index(regex) == kNPOS) { 
	// Warning("ScanType", "%s in %s doesn't match eta range regexp", 
	//         n.Data(), real->GetName());
	continue;
      }
      TCollection* mBin = static_cast<TCollection*>(o);
      TCollection* cBin = GetCollection(corrections, n.Data());
      if (!cBin) continue;

      THStack* binS = ProcessBin(mBin, cBin, method, r, dir);
      if (!binS) continue;

      TH1* result = 0;
      Bin2Stack(binS, i, allMeasured, allTruth, allTruthA, 
		allUnfolded, allCorrected, result);

      TGraph* alice = 0;
      TGraph* cms   = 0;
      Other2Stack(o->GetName(), i, sNN, allALICE, allCMS, alice, cms);
      Ratio2Stack(i, result, alice, cms, allRatio);
      i++;
    }
    dir->Add(allMeasured);
    dir->Add(allTruth);
    dir->Add(allTruthA);
    dir->Add(allUnfolded);
    dir->Add(allCorrected);
    if (allALICE && allALICE->GetListOfGraphs()) {
      if (allALICE->GetListOfGraphs()->GetEntries() > 0)
	dir->Add(allALICE);
      else 
	delete allALICE;
    }
    if (allCMS && allCMS->GetListOfGraphs()) {
      if (allCMS->GetListOfGraphs()->GetEntries() > 0) 
	dir->Add(allCMS);
      else 
	delete allCMS;
    }
    if (allRatio && allRatio->GetHists()) { 
      if (allRatio->GetHists()->GetEntries() > 0) 
	dir->Add(allRatio);
      else 
	delete allRatio;
    }
  }