Exemplo n.º 1
0
int main() {
	TList *list = new TList();
	printf_s("list.First() = %s\n", list->First());
	printf_s("list.Pop() = %s\n", list->Pop());

	list->Push("Hola");
	printf_s("Pushed \"Hola\"!\n");
	list->Push("Holita");
	printf_s("Pushed \"Holita\"!\n");
	list->Push("Que tal?");
	printf_s("Pushed \"Que tal?\"!\n");

	printf_s("list.Next() = %s\n", list->Next());
	printf_s("list.Next() = %s\n", list->Next());
	printf_s("list.Next() = %s\n", list->Next());
	printf_s("list.Next() = %s\n", list->Next());

	printf_s("list.First() = %s\n", list->First());
	printf_s("list.Pop() = %s\n", list->Pop());
	printf_s("list.First() = %s\n", list->First());

	list->Push("Hola");

	list->Reset();
	printf_s("list reset!\n");

	printf_s("list.First() = %s\n", list->First());
	printf_s("list.Next() = %s\n", list->Next());

	delete list;

	getchar();
}
void collectContours(map<string,TGraph2D *>& m_graphs,
		     const vector<string>&  keys,
		     map<string,double>& m_contourlevels,
		     map<string,TList *>& m_contours)
{
  cout << "CollectContours" << endl;

  TCanvas *canv = new TCanvas("dummy","dummy",100,100);
  //canv->Divide(3,2);

  std::cout << "keys.size() = " << keys.size() << std::endl;

  //process TGraph2Ds into contours at levels m_contourlevels
  for (size_t i=0; i<keys.size(); i++) {
    double clev = m_contourlevels[keys[i]];
    TGraph2D *gr2d = m_graphs[keys[i]];
    std::cout << "gr2d = " << gr2d << std::endl;
    std::cout << "gr2d->GetN() = " << gr2d->GetN() << std::endl;


    if (gr2d && (gr2d->GetN() > 0)) {
      gr2d->GetHistogram()->SetContour(1, &clev);
      //canv->cd(i+1);
      cout << "drawing... " << endl;

      gr2d->Draw("CONT LIST"); // it's stupid, but only "CONT" will generate the list
      gPad->Update();

      TObjArray *contours = (TObjArray *)gROOT->GetListOfSpecials()->FindObject("contours");
      assert(contours);

      TList *newlist = 0;
      for (int ci=0; ci<contours->GetEntriesFast(); ci++) {
	TList *contLevel = (TList*)contours->At(ci);
	printf("%s: Contour %d has %d Graphs\n", keys[i].c_str(), ci, contLevel->GetSize());

	if (contLevel->GetSize()) {
	  assert(contLevel->First());
	  if (!newlist) newlist = new TList();
	  TGraph *curv = (TGraph*)(contLevel->First());

	  for (int j=0; j<contLevel->GetSize(); j++) {
	    newlist->Add((TGraph *)(curv->Clone()));
	    curv=(TGraph *)(contLevel->After(curv));
	  }
	}
      } // contour loop

      cout << "Inserting contour list for "<< keys[i] << " newlist="<<newlist<<endl;
      m_contours[keys[i]] = newlist;

    } // if (gr2d)
  } // key loop

  //delete canv;
}                                                     // collectContours
Exemplo n.º 3
0
void KVClassFactory::AddAllBaseConstructors()
{
    // Add constructors with the same signature as all base class constructors
    // (apart from the default ctor or any copy constructors, which are a special case)
    // By default, all constructors are 'public'.

    if(!fBaseClass) return;

    KVHashList clist;
    clist.AddAll(fBaseClass->GetListOfMethods());
    KVSeqCollection* constructors = clist.GetSubListWithName(fBaseClassName);
    TIter next_ctor(constructors);
    TMethod* method;
    while( (method = (TMethod*)next_ctor()) )
    {
        if(!method->GetNargs()) continue; // ignore default ctor
        TList* args = method->GetListOfMethodArgs();
        TMethodArg* arg = (TMethodArg*)args->First();
        TString typenam=arg->GetFullTypeName();
        if(typenam.Contains(fBaseClassName)) continue; // ignore copy ctor
        KVClassMethod* ctor;
        if(arg->GetDefault()) ctor = AddConstructor( typenam, arg->GetName(), arg->GetDefault() );
        else ctor = AddConstructor(typenam, arg->GetName());
        for(int i=1; i<method->GetNargs(); i++){
            arg = (TMethodArg*)args->At(i);
            if(arg->GetDefault()) ctor->AddArgument( arg->GetFullTypeName(), arg->GetName(), arg->GetDefault() );
            else ctor->AddArgument(arg->GetFullTypeName(), arg->GetName());
        }
    }

    delete constructors;
}
Exemplo n.º 4
0
void TGo4LogInfo::linkedObjectUpdated(const char * linkname, TObject * obj)
{
   TList* lst = dynamic_cast<TList*>(obj);
   if (lst != 0) {
      TListIter iter(lst, kFALSE);
      TObject* obj = 0;
      while ((obj = iter()) != 0) {
         // first item is id of current status message, used to submit next request
         if (obj==lst->First()) continue;

         const char* msg = obj->GetName();

         const char* separ = strchr(msg,':');
         if ((separ==0) || (strlen(separ)<3)) continue;

         Long64_t tm = TString(msg, separ-msg).Atoll();

         QDateTime dt;
         dt.setTime_t((time_t) tm);

         separ++;
         int level = 1;
         if (*separ=='2') level=2; else
         if (*separ=='3') level=3;

         AddMessage(dt, level, separ+2);
      }
   } else
   if (obj!=0) {
      AddMessage(QDateTime::currentDateTime(), 0, obj->GetName());
   }
}
Exemplo n.º 5
0
void compareHistos( char *Current, char *Reference=0 ) {

    TText* te = new TText();
    te->SetTextSize(0.1);

    TFile * curfile = new TFile( TString(Current)+".root" );
    TFile * reffile = curfile;
    if (Reference) reffile = new TFile(TString(Reference)+".root");


    char * prefix="DQMData/MixingV/Mixing";
//1-Dimension Histogram
    TDirectory * refDir=reffile->GetDirectory(prefix);
    TDirectory * curDir=curfile->GetDirectory(prefix);
    TList* list = refDir->GetListOfKeys();
    TObject*  object = list->First();
    int iHisto = 0;
    char title[50];
    while (object) {
        // find histo objects
        std::cout << " object :" << object->GetName() << std::endl;
        TProfile * h1 = dynamic_cast<TProfile*>( refDir->Get(object->GetName()));
        TProfile * h2 = dynamic_cast<TProfile*>( curDir->Get(object->GetName()));
        bool isHisto = (refDir->Get(object->GetName()))->InheritsFrom("TProfile");
        std::cout << " isHisto = " << isHisto << std::endl;
        if (isHisto && h1 && h2 && *h1->GetName()== *h2->GetName()) {
            iHisto++;
            char title[50];
            // draw and  compare
            std::cout << " Start draw and compare" << std::endl;
            TCanvas c1;
            TProfile htemp2;
            h2->Copy(htemp2);// to keep 2 distinct histos

            h1->SetLineColor(2);
            htemp2.SetLineColor(3);
            h1->SetLineStyle(3);
            h1->SetMarkerColor(3);
            htemp2.SetLineStyle(5);
            htemp2.SetMarkerColor(5);
            TLegend leg(0.1, 0.15, 0.2, 0.25);
            leg.AddEntry(h1, "Reference", "l");
            leg.AddEntry(&htemp2, "New ", "l");

            h1->Draw();
            htemp2.Draw("Same");
            leg.Draw();
            sprintf(title,"%s%s", object->GetName(),".gif");
            c1.Print(title);
        }

        // go to next object
        object = list->After(object);
    }
}
Exemplo n.º 6
0
void DoCompare( char *Current, char *Reference=0 ){

 TText* te = new TText();
 te->SetTextSize(0.1);
 
 gROOT->ProcessLine(".x HistoCompare.C");
 HistoCompare * myPV = new HistoCompare();

 TFile * curfile = new TFile( TString(Current)+".root" );
 TFile * reffile = curfile;
 if (Reference) reffile = new TFile(TString(Reference)+".root");


 char * prefix="DQMData/MixingV/";
 //1-Dimension Histogram
 TDirectory * refDir=reffile->GetDirectory(prefix);
 TDirectory * curDir=curfile->GetDirectory(prefix);
 TList* list = refDir->GetListOfKeys();  
 TObject*  object = list->First();
 int iHisto = 0; char title[50];
 while (object) {
   // find histo objects
   TH1F * h1 = dynamic_cast<TH1F*>( refDir->Get(object->GetName()));
   TH1F * h2 = dynamic_cast<TH1F*>( curDir->Get(object->GetName()));
   bool isHisto = (refDir->Get(object->GetName()))->InheritsFrom("TH1F");
   if (isHisto && h1 && h2 && *h1->GetName()== *h2->GetName()) {
     iHisto++;
      char title[50];
      // draw and  compare
   TCanvas c1;
   TH1F htemp2;
   h2->Copy(htemp2);// to keep 2 distinct histos

   h1->SetLineColor(2);
   htemp2.SetLineColor(3);
   h1->SetLineStyle(3);
   htemp2.SetLineStyle(5);
   TLegend leg(0.1, 0.15, 0.2, 0.25);
   leg.AddEntry(h1, "Reference", "l");
   leg.AddEntry(&htemp2, "New ", "l");

   h1->Draw();
   htemp2.Draw("Same"); 
   leg.Draw();
   myPV->PVCompute(h1,&htemp2, te);
   sprintf(title,"%s%s", object->GetName(),".eps");
   c1.Print(title);
   }
   // go to next object
   object = list->After(object);
   }
}
TGraph* ContourGraph( TH2F* hist,double xmin=16, double xmax=90) {

    //temporary canvas
    TCanvas* MOO = new TCanvas( TString::Format("dummy_canvas_%s", hist->GetName()), "A scan of m_{0} versus m_{12}", 0, 0, 650,640);
    MOO->cd();

    TGraph* gr0 = new TGraph();
    TH2F* h = (TH2F*)hist->Clone();
    TGraph* gr = (TGraph*)gr0->Clone(TString::Format("gr_%s", h->GetName()));

    cout << "==> Will dumb histogram: " << h->GetName() << " into a graph" <<endl;

    h->SetContour( 1 );
    //h->GetXaxis()->SetRangeUser(250,1200);
    h->GetXaxis()->SetRangeUser(xmin, xmax);
    //h->GetYaxis()->SetRangeUser(2,50);

    double pval = CombinationGlob::cl_percent[1];
    std::cout << pval << std::endl; 
    double signif = TMath::NormQuantile(1-pval);
    h->SetContourLevel( 0, signif );
    h->Draw("CONT LIST");
    h->SetDirectory(0);
    gPad->Update();

    TObjArray *contours = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
    Int_t ncontours     = contours->GetSize();
    cout << "Found " << ncontours << " contours " << endl;

    TList *list = (TList*)contours->At(0);
    contours->Print("v");
    if(!list) return NULL;

    gr = (TGraph*)list->First();
    if(!gr) return NULL;

    gr->SetName(TString::Format("gr_%s", hist->GetName()));
    //gr->SetName(hist->GetName());
    int N = gr->GetN();
    double x0, y0;
    for(int j=0; j<N; j++) {
        gr->GetPoint(j,x0,y0);
        cout << j << " : " << x0 << " : "<<y0 << endl;
    }
    //  //  gr->SetMarkerSize(2.0);    
    //gr->Draw("ALP");

    delete MOO;

    cout << "Generated graph " << gr << " with name " << gr->GetName() << endl;
    return gr;
}
Exemplo n.º 8
0
TList PlotAlignmentValidation::getTreeList()
{
   TList treeList = new TList();
  TFile *first_source = (TFile*)sourcelist->First();
  std::cout<<first_source->GetName()<<std::endl;
  TDirectoryFile *d=(TDirectoryFile*)first_source->Get( treeBaseDir.c_str() ); 
  treeList.Add( (TTree*)(*d).Get("TkOffVal") );
 
  if( moreThanOneSource ==true ){
    TFile *nextsource = (TFile*)sourcelist->After( first_source );
    while ( nextsource ) {
      std::cout<<nextsource->GetName()<<std::endl;
      d=(TDirectoryFile*)nextsource->Get("TrackerOfflineValidation"); 
      
      treeList.Add((TTree*)(*d).Get("TkOffVal"));
      
      nextsource = (TFile*)sourcelist->After( nextsource );
    }
  }return treeList;
}
Exemplo n.º 9
0
  /** 
   * Get or create a stack legend.  This is done by adding a TLegend
   * object to the list of functions for the first histogram in the
   * stack.
   * 
   * @param stack Stack to get the legend from/modify 
   * 
   * @return The legend object or null
   */
  TLegend* StackLegend(THStack* stack) 
  {
    TList* hists = stack->GetHists();
    if (!hists) return 0;
    
    TObject* first = hists->First();
    if (!first) return 0;

    TH1*    hist = static_cast<TH1*>(first);
    TList*  list = hist->GetListOfFunctions();
    TObject* o   = list->FindObject("legend");
    if (o) return static_cast<TLegend*>(o);
    
    TLegend* l = new TLegend(0.65, 0.65, 0.9, 0.9, "", "NDC");
    l->SetName("legend");
    l->SetBorderSize(0);
    l->SetFillColor(0);
    l->SetFillStyle(0);
    l->SetTextFont(42);
    list->Add(l);
    
    return l;
  }
Exemplo n.º 10
0
TList* getContours(const TH2* hist,double contourLevel,const TString filename)
{
  TH2* h = (TH2*)hist->Clone("_clone");
  double limitValue[1] = {contourLevel};
  h->SetContour(1,limitValue);
  TCanvas* c = new TCanvas("contour_canvas","Contour List",0,0,600,600);
  h->Draw("CONT LIST");
  c->Update();
  TList* contours = (TList*)((TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours"))->At(0);
  TGraph* contour = (TGraph*)contours->First();
  if(filename!="") 
    {
      for(unsigned int j = 0; j < contours->GetSize(); j++)
	{
	  TString newFilename = filename+"_";
	  newFilename+=j;
	  contour->SaveAs(newFilename+".C");
	  contour = (TGraph*)contours->After(contour); // Get Next graph
	}
    }
  delete h;
  delete c;
  return contours;
}
Exemplo n.º 11
0
void merge(TString outfile, TString firstfile, TString pat=defaultPattern)
{
        TList   decayModes;
	bool    save=false;
        TString dir=".";
	TString first="";
	long    flags=0,id=0,size=0,modtime=0;
	if(firstfile.Contains("~"))
	{
		cout<<"ERROR: input path cannot contain '~' character."<<endl;
		return;
	}
	// Check pattern
	TRegexp pattern(pat,true);
	if(pattern.Status()!=0)
	{
		cout<<"ERROR: Wrong regular expression."<<endl;
		return;
	}
	// Load libraries
        loadLibs();
	gSystem->GetPathInfo(firstfile, &id, &size, &flags, &modtime);
	bool isDirectory = flags&2;
	if(isDirectory)
	{
		dir=firstfile;
		first="";
	}
	else
	{
		//Separate directory from filename
		int separator=firstfile.Last('/');
		if(separator!=-1) dir=firstfile(0,separator+1);
		first=firstfile(separator+1,firstfile.Length());
	}
	cout<<"Output file: "<<outfile<<endl;
	cout<<"Input  dir:  "<<dir<<endl;
	if(!isDirectory) cout<<"First  file: "<<first<<endl;
	cout<<endl;
	// Get file list and add first file if present
        TList *files = getFileList(first,dir,pattern);
	if(!isDirectory)
	{
		TFile *ff = new TFile(firstfile,"READ");
		files->AddBefore(files->First(),ff);
	}
	// Merge files
	TIter next(files);
	TFile *file;
        while(file = (TFile*)next())
        {
		if(!file->IsOpen()) continue;
                ReadFile(file,decayModes);
                cout<<"=============================="<<endl;
                save=true;
        }
	// Save output
        if(save)
	{
		cout<<"Saving..."<<endl;
		SaveOutput(outfile,decayModes);
		cout<<"Output saved to "<<outfile<<endl<<endl;
	}
	else    cout<<"Nothing to save."<<endl<<endl;
	// Closing files
	cout<<"Closing files..."<<endl;
	TIter cl(files);
        while(file = (TFile*)cl()) { file->Close(); delete file; }
	delete files;
	gSystem->Exit(0);
}
Exemplo n.º 12
0
void ttreesToHistograms() {
//********************************************************************
//****                      Variables                           ****//
cout << "Loading variables into vectors..." << endl;

vector<TString> fileName;
fileName.push_back( "rootfiles0/PhotonJetPt15_Summer09.root"  );//file0
fileName.push_back( "rootfiles0/PhotonJetPt30_Summer09.root"  );//file1
fileName.push_back( "rootfiles0/PhotonJetPt80_Summer09.root"  );//file2
fileName.push_back( "rootfiles0/PhotonJetPt170_Summer09.root" );//file3
fileName.push_back( "rootfiles0/PhotonJetPt300_Summer09.root" );//file4
fileName.push_back( "rootfiles0/PhotonJetPt470_Summer09.root" );//file5
fileName.push_back( "rootfiles0/PhotonJetPt800_Summer09.root" );//file6

TString treeName = "TreePhotonJet";

TString outputFileName = "PhotonJetHists-2009-09-02-matchesReco.root";


//*********************************
//**** Set Scale
// The following 4 number set the scale
// example:
//   scale = (integrated luminosity (1/pb))*(cross section (pb))*(filter eff)/(events analyzed)
float invLuminosityToScaleTo = 200; // in pb-1

vector<float> crossSection;
crossSection.push_back( 2.887E5 -3.222E4 );  // in pb
crossSection.push_back( 3.222E4 -1.010E3 );
crossSection.push_back( 1.010E3 -5.143E1 );
crossSection.push_back( 5.143E1 -4.193E0 );
crossSection.push_back( 4.193E0 -4.515E-1 );
crossSection.push_back( 4.515E-1 -2.003E-2 );
crossSection.push_back( 2.003E-2 );

vector<float> filterEffeciency;
filterEffeciency.push_back( 1.0 );
filterEffeciency.push_back( 1.0 );
filterEffeciency.push_back( 1.0 );
filterEffeciency.push_back( 1.0 );
filterEffeciency.push_back( 1.0 );
filterEffeciency.push_back( 1.0 );
filterEffeciency.push_back( 1.0 );

vector<float> eventsAnalyzied;
eventsAnalyzied.push_back( 1073270 );
eventsAnalyzied.push_back( 1088546 );
eventsAnalyzied.push_back(  993509 );
eventsAnalyzied.push_back( 1483940 );
eventsAnalyzied.push_back( 1024589 );
eventsAnalyzied.push_back( 1014413 );
eventsAnalyzied.push_back( 1216320 );
// END of setting scale
//*********************************


//*********************************
//****         Set Cuts      ****//
// Variables will be plotted for each "location"
vector<TString> locationCut;
locationCut.push_back( "abs(hardGenPhoton_eta)>1.55&&abs(hardGenPhoton_eta)<2.5" );
locationCut.push_back( "abs(hardGenPhoton_eta)<1.45" );

vector<TString> locationName;
locationName.push_back( "Endcap" );
locationName.push_back( "Barrel" );

// These cuts will be merged into one giant cut, applied to all plots for all files
vector<TString> cuts;
cuts.push_back( "hardGenPhoton_et>15.0&&photon_et>15.0&&photon_matches_hardGen>0.5" );

// These cuts will be applied only to corresponding file
vector<TString> fileCuts;
fileCuts.push_back( "event_genEventScale>15&&event_genEventScale<30"    ); //file0
fileCuts.push_back( "event_genEventScale>30&&event_genEventScale<80"    ); //file1
fileCuts.push_back( "event_genEventScale>80&&event_genEventScale<170"   ); //file2
fileCuts.push_back( "event_genEventScale>170&&event_genEventScale<300"  ); //file3
fileCuts.push_back( "event_genEventScale>300&&event_genEventScale<470"  ); //file4
fileCuts.push_back( "event_genEventScale>470&&event_genEventScale<800"  ); //file5
fileCuts.push_back( "event_genEventScale>800&&event_genEventScale<1400" ); //file6
//**** END of setting cuts
//*********************************


//*********************************
int locationVariablesToPlot[2][2]; // [a][b], a=number of locations, b=2 (for min,max range of variables to plot)
locationVariablesToPlot[0][0] = 16; // Endcap
locationVariablesToPlot[0][1] = 35;
locationVariablesToPlot[1][0] = 16; // Barrel
locationVariablesToPlot[1][1] = 35;
/*locationVariablesToPlot[2][0] = 0;
locationVariablesToPlot[2][1] = 4;
locationVariablesToPlot[3][0] = 0;
locationVariablesToPlot[3][1] = 4;
locationVariablesToPlot[4][0] = 0;
locationVariablesToPlot[4][1] = 4;
locationVariablesToPlot[5][0] = 0;
locationVariablesToPlot[5][1] = 4;
locationVariablesToPlot[6][0] = 0;
locationVariablesToPlot[6][1] = 4;
locationVariablesToPlot[7][0] = 0;
locationVariablesToPlot[7][1] = 4;*/

// Variables you want plotted
vector<TString> variableToPlot;
// --- the following require gen level info
variableToPlot.push_back( "hardGenPhoton_et"  );  // 0
variableToPlot.push_back( "hardGenPhoton_eta" );
variableToPlot.push_back( "hardGenPhoton_phi" );
variableToPlot.push_back( "fmod(hardGenPhoton_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" );
variableToPlot.push_back( "abs(hardGenPhoton_eta)" ); // 4
variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy" );
variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_energy"   );
variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:abs(hardGenPhoton_eta)" );
variableToPlot.push_back( "(recPhoton.energy-hardGenPhoton_energy)/hardGenPhoton_energy:hardGenPhoton_phiMod"   );
variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_et"       );
variableToPlot.push_back( "photon_hadronicOverEm:abs(hardGenPhoton_eta)" ); // 10
variableToPlot.push_back( "photon_hadronicOverEm:hardGenPhoton_phiMod"   );
variableToPlot.push_back( "photon_eta-hardGenPhoton_eta" );
variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:hardGenPhoton_et" );
variableToPlot.push_back( "photon_eta-hardGenPhoton_eta:abs(hardGenPhoton_eta)" );
variableToPlot.push_back( "deltaPhiGenRecPhoton" );  // 15
// --- the following require only rec photons
variableToPlot.push_back( "photon_et"  );         // 16
variableToPlot.push_back( "photon_eta" );
variableToPlot.push_back( "photon_phi" );
variableToPlot.push_back( "fmod(photon_phi+3.141592,20.0*3.141592/180.0)-10.0*3.141592/180.0" );
variableToPlot.push_back( "abs(photon_eta)" );    // 20
variableToPlot.push_back( "photon_r9" );
variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03" );
variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03"  );
variableToPlot.push_back( "photon_trkSumPtSolidConeDR03"   );
variableToPlot.push_back( "photon_trkSumPtHollowConeDR03"  ); //25
variableToPlot.push_back( "photon_nTrkSolidConeDR03"  );
variableToPlot.push_back( "photon_nTrkHollowConeDR03" );
variableToPlot.push_back( "photon_hadronicOverEm"     );
variableToPlot.push_back( "photon_r2x5" );
variableToPlot.push_back( "photon_ecalRecHitSumEtConeDR03/photon_et" ); // 30
variableToPlot.push_back( "photon_hcalTowerSumEtConeDR03/photon_et"  );
variableToPlot.push_back( "photon_trkSumPtSolidConeDR03/photon_et"   );
variableToPlot.push_back( "photon_trkSumPtHollowConeDR03/photon_et"  );
// --- the following require jets
/*variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet_phi)"  );
variableToPlot.push_back( "calcDeltaPhi(photon_phi,jet2_phi)" ); // 35
variableToPlot.push_back( "calcDeltaPhi(jet_phi,jet2_phi)"    );*/
variableToPlot.push_back( "(photon_et-jet_et)/photon_et"      );
variableToPlot.push_back( "jet2_et/photon_et"                 );

// Histograms for the above variables
vector<TH1*> histogram;
// --- the following require gen level info
histogram.push_back( new TH1F("photonGenEt",     "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV",  50,  0, 750)  );  // 0
histogram.push_back( new TH1F("photonGenEta",    "Photon #eta ;#eta;entries per 0.1 bin",   61, -3.05,   3.05) );
histogram.push_back( new TH1F("photonGenPhi",    "Photon #phi ;#phi;entries per bin",   62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) );
histogram.push_back( new TH1F("photonGenPhiMod", "Photon #phi_{mod} ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) );
histogram.push_back( new TH1F("photonGenAbsEta", "Photon |#eta| ", 51, 0.00,   2.55) );
histogram.push_back( new TH1F("photonDeltaE",    "(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) ", 50, -0.8, 0.3) );
histogram.push_back( new TH2F("photonDeltaE_vs_E","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs E(#gamma_{gen}) ", 50, 0, 3000, 50, -0.8, 0.3) );
histogram.push_back( new TH2F("photonDeltaE_vs_AbsEta","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs |#eta(#gamma_{gen}|) ", 51, 0.0, 2.5, 50, -0.8, 0.3) );
histogram.push_back( new TH2F("photonDeltaE_vs_PhiMod","(E(#gamma_{rec})-E(#gamma_{gen}))/E(#gamma_{gen}) vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, -0.9, 0.2) );
histogram.push_back( new TH2F("photonHoverE_vs_Et",     "H/E vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 50, 0.0, 0.2) );
histogram.push_back( new TH2F("photonHoverE_vs_AbsEta", "H/E vs |#eta(#gamma_{gen})| ", 51, 0.0, 2.5, 50, 0.0, 0.2) );
histogram.push_back( new TH2F("photonHoverE_vs_PhiMod", "H/E vs #phi_{mod}(#gamma_{gen}) ", 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329, 50, 0.0, 0.2) );
histogram.push_back( new TH1F("photonDeltaEta", "#Delta#eta(#gamma_{rec},#gamma_{gen}) ;#Delta#eta(#gamma_{rec},#gamma_{gen});entries/bin", 41, -0.01, 0.01) );
histogram.push_back( new TH2F("photonDeltaEta_vs_Et",    "#Delta#eta(#gamma_{rec},#gamma_{gen}) vs E_{T}(#gamma_{gen}) ", 50, 0, 1000, 41, -0.1, 0.1) );
histogram.push_back( new TH2F("photonDeltaEta_vs_AbsEta","#Delta#eta(#gamma_{rec},#gamma_{gen}) vs #eta(#gamma_{gen})", 51, 0.0, 2.55, 41, -0.1, 0.1) );
histogram.push_back( new TH1F("photonDeltaPhi",          "#Delta#phi(#gamma_{rec},#gamma_{gen}) ;#Delta#phi(#gamma_{rec},#gamma_{gen});entries/bin", 41, 0.0, 0.01) ); // 15
// --- the following require only rec photons
histogram.push_back( new TH1F("photonEt",        "Photon E_{T} ;E_{T} (GeV);entries per 15 GeV", 50,  0,    750   ) ); // 16
histogram.push_back( new TH1F("photonEta",       "Photon #eta ;#eta;entries per 0.1"           , 61, -3.05,   3.05) );
histogram.push_back( new TH1F("photonPhi",       "Photon #phi ;#phi;entries per bin"           , 62, (-1.-1./30.)*TMath::Pi(), (1.+1./30.)*TMath::Pi()) );
histogram.push_back( new TH1F("photonPhiMod",    "Photon #phi_{mod} "                          , 42, (-1.-1./20)*0.1745329, (1.+1./20.)*0.1745329) );
histogram.push_back( new TH1F("photonAbsEta",    "Photon |#eta| "                              , 51, 0.00,  2.55) );  // 20
histogram.push_back( new TH1F("photonR9",        "R9 = E(3x3) / E(SuperCluster)  ;R9;entries/bin"   , 50, 0.6, 1.0) );
histogram.push_back( new TH1F("photonEcalIso",   "#SigmaEcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0  , 15) );
histogram.push_back( new TH1F("photonHcalIso",   "#SigmaHcal Rec Hit E_{T} in Hollow #DeltaR cone " , 50, 0  , 15) );
histogram.push_back( new TH1F("photonTrackSolidIso",     "#Sigmatrack p_{T} in Solid #DeltaR cone " , 50, 0  , 15) );
histogram.push_back( new TH1F("photonTrackHollowIso",    "#Sigmatrack p{T} in Hollow #DeltaR cone " , 50, 0  , 15) );  // 25
histogram.push_back( new TH1F("photonTrackCountSolid",   "Number of tracks in Solid #DeltaR cone ;Number of Tracks;entries/bin" , 25, -0.5, 24.5) );
histogram.push_back( new TH1F("photonTrackCountHollow",  "Number of tracks in Hollow #DeltaR cone ;Number of Tracks;entries/bin", 25, -0.5, 24.5) );
histogram.push_back( new TH1F("photonHoverE",            "Hadronic / EM ", 50, 0.0, 0.2) );
histogram.push_back( new TH1F("photonScSeedE2x5over5x5", "E2x5/E5x5  "   , 50, 0.6, 1.0) );
histogram.push_back( new TH1F("photonEcalIsoOverE",        "#SigmaEcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) ); // 30
histogram.push_back( new TH1F("photonHcalIsoOverE",        "#SigmaHcal Rec Hit E_{T} in #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) );
histogram.push_back( new TH1F("photonTrackSolidIsoOverE" , "#SigmaTrack p_{T} in #DeltaR cone / Photon E_{T} "        , 50, -0.1, 1.0) );
histogram.push_back( new TH1F("photonTrackHollowIsoOverE", "#SigmaTrack p_{T} in Hollow #DeltaR cone / Photon E_{T} " , 50, -0.1, 1.0) );
// --- the following require jets
/*histogram.push_back( new TH1F("h_deltaPhi_photon_jet", "#Delta#phi between Highest E_{T} #gamma and jet;#Delta#phi(#gamma,1^{st} jet)"               , 50, 0, 3.1415926) );
histogram.push_back( new TH1F("h_deltaPhi_photon_jet2","#Delta#phi between Highest E_{T} #gamma and 2^{nd} highest jet;#Delta#phi(#gamma,2^{nd} jet)", 50, 0, 3.1415926) );
histogram.push_back( new TH1F("h_deltaPhi_jet_jet2"  , "#Delta#phi between Highest E_{T} jet and 2^{nd} jet;#Delta#phi(1^{st} jet,2^{nd} jet)"       , 50, 0, 3.1415926) );*/
histogram.push_back( new TH1F("h_deltaEt_photon_jet" , "(E_{T}(#gamma)-E_{T}(jet))/E_{T}(#gamma) when #Delta#phi(#gamma,1^{st} jet) > 2.8;#DeltaE_{T}(#gamma,1^{st} jet)/E_{T}(#gamma)", 20, -1.0, 1.0) );
histogram.push_back( new TH1F("h_jet2_etOverPhotonEt", "E_{T}(2^{nd} highest jet) / E_{T}(#gamma);E_{T}(2^{nd} Jet)/E_{T}(#gamma)", 20, 0.0, 4.0) );
//****                  END of Variables                        ****//
//********************************************************************




//********************************************************************
//****                Main part of Program                      ****//

 // Human error checking
 if (variableToPlot.size() != histogram.size() ) {
   cout << "Should have equal entries in histogram and variableToPlot vector." << endl;
   return;
 }
 if (fileName.size() > crossSection.size() ) {
   cout << "Should have equal entries in fileName and crossSection vetor." << endl;
   return;
 }
 if (fileName.size() > fileCuts.size() ) {
   cout << "Should have equal entries in fileName and fileCuts vector." << endl;
   return;
 }

 // Combine all the cuts into one
 cout << endl << "Cuts that will be applied to everything: " << endl << "  ";
 TCut allCuts = "";
 for (int i =0; i<cuts.size(); i++) {
   allCuts += cuts[i];
   if (i>0) cout << "&&";
   cout << "(" << cuts[i] << ")";
 }
 cout << endl << endl;


 // Open the files & set their scales
 cout << endl << "Histograms will be scaled to " << invLuminosityToScaleTo << "pb-1 " << endl;
 cout << "Looking for TTree named \"" << treeName << "\" in files..." << endl;
 vector<float> fileScale;
 TList *fileList = new TList();
 for (int i=0; i < fileName.size(); i++) {

   TFile* currentFile = TFile::Open(fileName[i]);
   fileList->Add(currentFile);
   float currentScale = crossSection[i]*invLuminosityToScaleTo*filterEffeciency[i]/eventsAnalyzied[i];
   fileScale.push_back( currentScale );

   // Display entries in that file's TTree
   TTree* tree;
   currentFile->GetObject(treeName, tree);
   cout << "file" << i <<": " << fileName[i] << " contains " << tree->GetEntries(allCuts) << " entries, and will be scaled by " << 
currentScale << endl;
 }
 cout << endl << endl;


 //Create output file
 TFile *outputFile = TFile::Open( outputFileName, "RECREATE" );


 //************************************************************
 //                 Core of the Script                       //
 // Loop over locations
 for (int l=0; l<locationName.size(); l++) {
   TString currentLocation = locationName[l];
   TCut currentCuts = allCuts;
   currentCuts += locationCut[l];
   cout << "Creating plots for " << currentLocation << ", " << locationCut[l] << endl;
  
   // Loop over variables to plot
   for (int i=0; i<variableToPlot.size(); i++) {
     // should we plot this variable for this location?
     if (i<locationVariablesToPlot[l][0] || i>locationVariablesToPlot[l][1]) continue;

     TString currentHistType  = histogram[i]->IsA()->GetName();
     TString currentHistName  = TString(histogram[i]->GetName())  + "_" + currentLocation;
     TString currentHistTitle = TString(histogram[i]->GetTitle()) + "(" + currentLocation + ")";
     cout << "  " << variableToPlot[i] << " >> " << currentHistName;
     TString currentHistDrawOpt;
     if (currentHistType=="TH2F") {
       currentHistDrawOpt="goffbox";
     } else {
       currentHistDrawOpt="egoff";
     }
     TH1* currentHist = (TH1*)histogram[i]->Clone(currentHistName);  // Creates clone with name currentHistName
     currentHist->Sumw2(); // store errors
     currentHist->SetTitle(currentHistTitle);
     //cout << " from file";

     // Plot from the first file
     int f = 0;
     //cout << f;
     TTree *tree;
     TFile *current_file = (TFile*)fileList->First();
     current_file->cd();
     current_file->GetObject(treeName, tree);
     tree->Draw(variableToPlot[i]+">>"+currentHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt);
     currentHist->Scale(fileScale[f]);
     f++;

     // Loop over files
     current_file = (TFile*)fileList->After( current_file );
     while ( current_file ) {
       current_file->cd();
       //cout << ", file" << f;
       current_file->GetObject(treeName, tree);

       TString tempHistName = currentHistName+"Temp";
       TH1* tempHist = (TH1*)currentHist->Clone(tempHistName);
       tree->Draw(variableToPlot[i]+">>"+tempHistName,currentCuts+TCut(fileCuts[f]),currentHistDrawOpt);
       tempHist->Scale(fileScale[f]);
       currentHist->Add(tempHist);
       tempHist->Delete();

       current_file = (TFile*)fileList->After( current_file );
       f++;
     } // End of loop over files

     outputFile->cd();
     currentHist->Write();
     cout << endl;
   } // End of loop over variabls to plot
 } // End of loop over locations
 //                  END of Core of Script                   //
 //************************************************************

 cout << endl;
 cout << "Wrote file " << outputFileName << endl;
 cout << endl;
 outputFile->Close();
}
/*************************************************************************************
 * createMFOutfile: moves the MLB distributions into an output file for use in 
 *                  R. Nally's MassFit.C code.
 *  input:  the main() arguments array
 *  output: writes to an output file the histograms, in a MassFit.C-readable format 
 *
 *  Structure-wise: can be implemented into class easily.
 ***********************************/
void createMFOutfile(const char* argv[]) {
  TFile *f = new TFile(argv[2]);

  //create the output file we'd like to write histograms to
  TFile *output = new TFile(outfileName, "RECREATE");
  
  //get the filesystem information from the file
  f->cd();
  TList *alokDirs = (TList*) f->GetListOfKeys();

  //create a list of "All" histograms and initialize (TODO)
  TList *allHists = new TList;

  //loop through the directories in the input file
  for(int idir=0; alokDirs->At(idir-1) != alokDirs->Last(); idir++) {
    //if it's not mlb, we don't care
    if(!TString(alokDirs->At(idir)->GetName()).Contains("_Mlb")) continue;
    
    //get the file directory information, its histograms
    TDirectory *cDir  = (TDirectory*) f->Get(alokDirs->At(idir)->GetName());
    TList *alokHistos = (TList*)      cDir->GetListOfKeys();

    //loop through the histograms in the current directory 
    for(int ihisto=0; alokHistos->At(ihisto-1) != alokHistos->Last(); ihisto++) {
      // don't consider the graph objects
      if(TString(alokHistos->At(ihisto)->GetName()).Contains("Graph_")) continue; 

      // clone the histogram, give it a new name
      TString cloneName = formatName(alokHistos->At(ihisto)->GetName(),nominalWidth);
      TH1F *thisto = (TH1F*) cDir->Get(alokHistos->At(ihisto)->GetName());
      TH1F *tclone = (TH1F*) thisto->Clone(cloneName);

      // open the outfile and write the histo in
      output->cd();
      TList *outkeys = (TList*) output->GetListOfKeys();

      // if the histogram already exists, add thisto to the existing one
      // messy, but removes the need for magic
      for(int iout=0; outkeys->At(iout-1) != outkeys->Last(); iout++) {
        if(outkeys->At(iout)->GetName() == cloneName) {
          cout<<" - found another histogram in output with name "<<cloneName<<endl;
          TH1F *theHisto = (TH1F*) output->Get(cloneName);
          cout<<" - got the same histogram from the output file"<<endl;
          TH1F *tHclone  = (TH1F*) theHisto->Clone(cloneName);
          cout<<" - cloned the histogram"<<endl;

          cout<<" - adding in clone"<<endl;
          tclone->Add(tHclone);

          cout<<" - deleting the original histogram from the output file"<<endl;
          output->Delete(cloneName + TString(";1"));
          cout<<" - deleted thing from output file"<<endl;
          cout<<" - tclone looks like "<<tclone<<endl;
        }
      }
      cout<<" - writing the tclone to file"<<endl;
      tclone->Write();

      // reopen the input root file and clean up
      f->cd();
      delete thisto;
      delete tclone;
    }
  }

  f->Close();
  output->cd();
  output->Close();

  // if we want to interpolate, start making more histograms
  if(interpolate) {
    // Have to reopen the outfile because ROOT is odd
    TFile *output2 = new TFile(outfileName, "UPDATE");
    output2->cd();

    std::pair<double,TString> maxPair = *moreFiles.begin();
    double maxWidth = maxPair.first;

    // check that it makes sense to interpolate with our settings
    if(maxWidth <= nominalWidth) {
      cout<<"\n\nERROR: Max width is less than or equal to the nominal width! Exiting."<<endl;
      exit(EXIT_FAILURE);
    }

    // open the input file and loop through the relevant directories
    TFile *maxFile = new TFile(maxPair.second);
    for(int i=0; i<lepsSize; i++) {
      // change directory and get the name of the folder we want to access
      maxFile->cd();
      char a[128];
      sprintf(a, "mlbwa_%s_Mlb", leps[i]);
      TDirectory *tDir = (TDirectory*) maxFile->Get(a);
      TList *alok = tDir->GetListOfKeys();

      // get the maxWidth histogram in this folder, clone and rename it
      TString maxHName = alok->First()->GetName();
      TString maxCloneName = formatName(maxHName, maxWidth);
      TH1F *maxHisto = (TH1F*) tDir->Get(maxHName);
      TH1F *maxClone = (TH1F*) maxHisto->Clone(maxCloneName);

      // write this max histogram to the outfile
      output2->cd();
      maxClone->Write();

      // get the corresponding nominal histogram from the outfile
      TH1F *nomHisto = (TH1F*) output2->Get(formatName(maxHName,nominalWidth));

      TCanvas *c = new TCanvas("");
      nomHisto->Draw();
      c->SaveAs(formatName(maxHName,nominalWidth)+TString(".pdf"));


      // for each interpolation, create a morphed histogram and write to outfile
      for(int i=interpolations; i>0; i--) {
        double tWidth = nominalWidth + i*(maxWidth - nominalWidth)/(interpolations+1);
        TString interpName = formatName(maxHName, tWidth);
        TH1F *interpHisto = (TH1F*) th1fmorph(interpName, interpName,nomHisto,maxHisto,
                                               nominalWidth,maxWidth,tWidth,nomHisto->Integral(),1);
        interpHisto->Write();
      }
    }

    maxFile->cd();
    maxFile->Close();
    output2->cd();
    output2->Close();

    // Otherwise, we want to collect signal histograms of different weights
  } else {
    // Have to reopen the outfile because ROOT is odd
    TFile *output2 = new TFile(outfileName, "UPDATE");
    output2->cd();

    // Loop through the additional files
    for(std::vector<std::pair<double, TString> >::const_iterator pf=moreFiles.begin();
                                                                 pf!=moreFiles.end();
                                                                 pf++) {

        // This is the current file and width
        TFile *curFile = new TFile(pf->second, "READ");
        double curWid  = pf->first;

        // Loop through lepton final states
        for(int i=0; i<lepsSize; i++) {
            curFile->cd();

            // Get the desired directory
            char dirName[128];
            sprintf(dirName, "mlbwa_%s_Mlb", leps[i]);
            TDirectory *curDir = (TDirectory*) curFile->Get(dirName);

            // Get the names of the first histogram in the directory
            //     (we don't want more than one additional signal histo per extra file)
            // Format it with the usual method
            TString histName   = TString(curDir->GetListOfKeys()->First()->GetName());
            TString cloneName  = formatName(histName,curWid);
            
            // Get the mlb histo
            TH1D *curHisto = (TH1D*) curDir->Get(histName)->Clone(cloneName);

            // Write to the outfile
            output2->cd();
            curHisto->Write();
        }

        curFile->Close();
    }

    output2->cd();
    output2->Close();
  }

}
Exemplo n.º 14
0
int main() {
	TList *list = new TList();
	printf_s("list.First() = %s\n", list->First());
	printf_s("list.Pop() = %s\n", list->Pop());

	list->Push("Hola");
	printf_s("Pushed \"Hola\"!\n");
	list->Push("Holita");
	printf_s("Pushed \"Holita\"!\n");
	list->Push("Que tal?");
	printf_s("Pushed \"Que tal?\"!\n");

	printf_s("list.Next() = %s\n", list->Next());
	printf_s("list.Next() = %s\n", list->Next());
	printf_s("list.Next() = %s\n", list->Next());
	printf_s("list.Next() = %s\n", list->Next());

	printf_s("list.First() = %s\n", list->First());
	printf_s("list.Pop() = %s\n", list->Pop());
	printf_s("list.First() = %s\n", list->First());

	list->Push("Hola");

	list->Reset();
	printf_s("list reset!\n");

	printf_s("list.First() = %s\n", list->First());
	printf_s("list.Next() = %s\n", list->Next());

	//copy constructor
	list->Push("Hola");
	list->Push("que");

	TList *list2 = new TList(*list);

	printf_s("list2.First() = %s\n", list2->First());
	printf_s("list2.Next() = %s\n", list2->Next());

	list2->Push("tal?");
	printf_s("list2.Next() = %s\n", list2->Next());

	delete list2;

	list->Push("tal");
	list->Push("estas?");

	//TList GetReverseList(TList lstSrc)
	TList listRev = GetReverseList(*list);

	printf_s("listRev.First() = %s\n", listRev.First());
	printf_s("listRev.Next() = %s\n", listRev.Next());
	printf_s("listRev.Next() = %s\n", listRev.Next());
	printf_s("listRev.Next() = %s\n", listRev.Next());

	//TList * GetReverseList(TList &lstSrc, TList *listCopy)
	//this is the way to avoid returning an object in the Stack
	TList * listInv = new TList();

	GetReverseList(*list, listInv);
	printf_s("listInv.First() = %s\n", listInv->First());
	printf_s("listInv.Next() = %s\n", listInv->Next());
	printf_s("listInv.Next() = %s\n", listInv->Next());
	printf_s("listInv.Next() = %s\n", listInv->Next());

	delete list;
	delete listInv;

	getchar();
}
Exemplo n.º 15
0
double fourrier() {

  gStyle->SetOptStat(0);
  gStyle->SetPadLeftMargin(0.13);
  gStyle->SetPadBottomMargin(0.13);
  //gStyle->SetTitleOffset(0.0,"X");
  gStyle->SetTitleFontSize(0.08);
  gStyle->SetTitleFont(62);
  //gStyle->SetTitleAlign(33);
  //TGaxis::SetMaxDigits(3);

  double pars[] = { 6.35356e+00,
		    1.0,
		    4.13113e+00,
  		    -4.43669e+00,
		    0.1,
		    0.01,
		    0.1,
		    9.64513e+03,
		    1.22279e+00,
  		    4.66147e-04,
  		    2.96494e-05,
  		    -6.21090e-06,
		    1.0,
		    -3.23049e-06
  };

  TLegend *tl = new TLegend(0.25,0.6,0.85,0.8);
  //TLegend *tl = new TLegend(0.462644, 0.651163, 0.862069, 0.852008);
  tl->SetBorderSize(0);

  TFile *f = TFile::Open("hadd_out/hadd.pi.root");
  TEfficiency* eff = (TEfficiency*) f->Get("prob_cut_9/eff1d_mom_e_id");
  tl->AddEntry(eff,"#pi^{#pm} mis-id prob. (p^{EID}_{comb} > 0.9)","pl");

  bool draw_func = false;
  if (draw_func) {
    TFile *f2 = TFile::Open("../new_test/eid90pct/anav2_pip_pim_brem_plab5.5.root");
    TEfficiency* eff2 = (TEfficiency*) f2->Get("pi_eff1d_total_smooth1d_clone");
    TList *list = (TList*) eff2->GetListOfFunctions();
    TF1* fsmth = (TF1*) list->First();
    tl->AddEntry(fsmth,"parametrization");
  }

  TCanvas *tc = new TCanvas("tc","tc");
  tc->cd();
  eff->Draw();
  //
  tc->Update();
  //eff->GetPaintedGraph()->GetHistogram()->SetMinimum(0);
  //eff->GetPaintedGraph()->GetHistogram()->SetMaximum(0.006);
  eff->GetPaintedGraph()->SetMinimum(5e-6);
  eff->GetPaintedGraph()->SetMaximum(0.007);
  eff->Draw();
  //eff->SetTitle(Form("%s;p_{MC}[GeV/c];#varepsilon(#pi^{#pm})^{EID}",eff->GetTitle()));
  //eff->SetTitle(Form("#varepsilon(#pi^{#pm}) for combined eID prob > 90%%;p_{MC}[GeV/c];#varepsilon(#pi^{#pm})^{EID}"));
  eff->SetTitle(Form(";p_{MC}[GeV/c];#varepsilon(#pi^{#pm})^{EID}"));

  set_style(eff->GetPaintedGraph());

  if (draw_func) fsmth->Draw("same");

  gPad->SetLogy();
  tc->Update();

  tl->Draw();

  //TF1* f1 = new TF1("f1",func,0.0001,12,14);
  //for (int ii=0; ii < 14; ++ii) {
  //  if (ii==9||ii==10||ii==11)
  //    f1->FixParameter(ii,pars[ii]);
  //  else
  //    f1->SetParameter(ii,pars[ii]);
  //}
  //eff->Fit(f1,"+RME");
  //eff->Draw();
  //cout << "Eff (0.01)= " << f1->Eval(0.01) << endl;
  //cout << "Eff (0.1)= " << f1->Eval(0.1) << endl;
  //cout << "Eff (0.2)= " << f1->Eval(0.2) << endl;
  //cout << "Eff (0.5)= " << f1->Eval(0.5) << endl;
  //cout << "Eff (1.0)= " << f1->Eval(1.0) << endl;
  //TF1* f2 = new TF1("f1",func,0.0001,12,13);
  //for (int ii=0; ii < 13; ++ii) {
  //  if (ii!=12)
  //    f2->SetParameter(ii,f1->GetParameter(ii));
  //  else
  //    f2->SetParameter(ii,100*f1->GetParameter(ii));
  //}
  //f2->SetLineColor(4);
  //f2->Draw("same");

}
void
draw2DLimitContours(map<string,TList *>& m_contours,
		    const TString& par1,
		    const TString& par2,
		    const TString& plotprefix,
		    TLegend *legend)
{

  //from here we build the two-dimensional aTGC limit

  TCanvas *finalPlot = new TCanvas("final","limits",500,500);
  finalPlot->cd();

  cout << "Drawing expected 68%" << endl;

  TList *contLevel = m_contours["exp68"];
  TGraph *curv;

  std::cout << "m_contours.size() = " << m_contours.size() << std::endl;

  for (map<string,TList *>::const_iterator iter = m_contours.begin(); iter != m_contours.end(); iter++ ){
    std::cout << "iter->first = " << iter->first << std::endl;
    std::cout << "iter->second = " << iter->second << std::endl;
  }

  std::cout << "contLevel = " << contLevel << std::endl;

  assert(contLevel);

  curv = (TGraph*)(contLevel->First());

  curv->GetXaxis()->SetLimits(parmin(par1),parmax(par1));
  curv->GetYaxis()->SetRangeUser(parmin(par2),parmax(par2));

  curv->SetTitle();
  curv->GetXaxis()->SetTitle(par2latex(par1));
  curv->GetXaxis()->SetTitleFont(42);
  curv->GetYaxis()->SetTitle(par2latex(par2));
  curv->GetYaxis()->SetTitleFont(42);
  curv->GetYaxis()->SetTitleOffset(1.20);

  for (int i=0; i<contLevel->GetSize(); i++) {
    assert(curv);
    curv->SetLineColor(kBlue);
    curv->SetLineWidth(2);
    curv->SetLineStyle(9);
    if (!i) {
      curv->Draw("AC");
      legend->AddEntry(curv,"Expected 68% C.L.","L");
    } else 
      curv->Draw("SAME C");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing expected 95%" << endl;
  
  contLevel = m_contours["exp95"];

  curv = (TGraph*)(contLevel->First());

  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kGreen);
    curv->SetLineWidth(2);
    curv->SetLineStyle(9);
    curv->Draw("SAME C");
    if (!i) legend->AddEntry(curv,"Expected 95% C.L.","L");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing expected 99%" << endl;

  contLevel = m_contours["exp99"];
  curv = (TGraph*)(contLevel->First());
  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kRed);
    curv->SetLineWidth(2);
    curv->SetLineStyle(9);
    curv->Draw("SAME C");
    if (!i) legend->AddEntry(curv,"Expected 99% C.L.","L");
    curv=(TGraph *)(contLevel->After(curv));
  }

  
  contLevel = m_contours["obs95"];

  if (contLevel) {
    cout << "Drawing obs95" << endl;

    curv = (TGraph*)(contLevel->First());

    for (int i=0; i<contLevel->GetSize(); i++) {
      curv->Draw("SAME C");
      curv->SetLineWidth(2);
      if (!i) legend->AddEntry(curv,"Observed 95% C.L.","L");
      curv=(TGraph *)(contLevel->After(curv));
    }
  }

  
  TGraph *SMpoint = new TGraph(1);
  SMpoint->SetPoint(1,0,0);
  //SMpoint->Draw("SAME Po");
  
  //smLabel = TPaveText(0,
  //                    m_contours["-2s"]->GetYaxis()->GetXmax()/8,
  //                    m_contours["-2s"]->GetXaxis()->GetXmax()/3->5,
  //                    -m_contours["-2s"]->GetYaxis()->GetXmax()/8);
  //smLabel->SetFillStyle(0);
  //smLabel->SetBorderSize(0);
  //smLabel->AddText(" SM");
  //smLabel->Draw();

  legend->Draw();

  TPaveText *text = new TPaveText(0.566,0.87,0.965,1.101,"NDC");
  text->SetFillStyle(0);
  text->SetBorderSize(0);
  //text->AddText(Form("95%% CL Limit on %s and %s",par2latex(par1).Data(),par2latex(par2).Data()));
  text->AddText(0,0.35,Form("#intL dt= %.1f fb^{-1}, #sqrt{s} = %d TeV",intlumifbinv,beamcometev));
  text->Draw();

  // text2 = TPaveText(0.155,0.199,0.974,0.244,"NDC");
  // text2->SetFillStyle(0);
  // text2->SetBorderSize(0);
  // text2->AddText("Values outside contour excluded");
  // text2->Draw();

  //text3 = TPaveText(0.506,0.699,0.905,0.758,"NDC");
  //text3->SetFillStyle(0);
  //text3->SetBorderSize(0);
  //text3->AddText(options.flavorText);
  //text3->Draw();    
  
  gPad->SetGrid(1,1);

  finalPlot->RedrawAxis();
  finalPlot->ResetAttPad();
  finalPlot->Update();

  finalPlot->Draw();
  finalPlot->Update();
  finalPlot->Modified();
  finalPlot->Update();
  finalPlot->Print(Form("%s.pdf",plotprefix.Data()));
  finalPlot->Print(Form("%s.eps",plotprefix.Data()));
  //finalPlot->Print(Form("%s.png",plotprefix.Data()));

}                                                 // draw2DlimitContours
void
draw2DLimitBFstyle(map<string,TList *>& m_contours,
		     const TString& par1,
		     const TString& par2,
		     const TString& plotprefix,
		     TLegend *legend)
{

  //from here we build the two-dimensional aTGC limit

  TCanvas *finalPlot = new TCanvas("final","limits",500,500);
  finalPlot->cd();

  cout << "Drawing +2s" << endl;

  TList *contLevel = m_contours["+2s"];
  TGraph *curv;

  assert(contLevel);

  curv = (TGraph*)(contLevel->First());

  //curv->GetYaxis()->SetRangeUser(-1.25*curv->GetYaxis()->GetXmax(),
	  			   //+2.0*curv->GetYaxis()->GetXmax());
  //curv->GetYaxis()->SetRangeUser(-0.1,0.15);
  curv->GetYaxis()->SetRangeUser(parmin(par2),parmax(par2));

  curv->SetTitle();
  curv->GetXaxis()->SetTitle(par2latex(par1));
  curv->GetXaxis()->SetTitleFont(42);
  curv->GetYaxis()->SetTitle(par2latex(par2));
  curv->GetYaxis()->SetTitleFont(42);
  curv->GetYaxis()->SetTitleOffset(1.20);

  for (int i=0; i<contLevel->GetSize(); i++) {
    assert(curv);
    curv->SetLineColor(kYellow);
    curv->SetFillColor(kYellow);
    curv->GetXaxis()->SetLimits(parmin(par1),parmax(par1));
    if (!i) {
      curv->Draw("ACF");
      legend->AddEntry(curv,"#pm 2#sigma","F");
    } else 
      curv->Draw("SAME CF");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing +1s" << endl;
  
  contLevel = m_contours["+1s"];

  curv = (TGraph*)(contLevel->First());

  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kGreen);
    curv->SetFillColor(kGreen);
    curv->Draw("SAME CF");
    if (!i) legend->AddEntry(curv,"#pm 1#sigma","F");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing -1s" << endl;

  contLevel = m_contours["-1s"];
  curv = (TGraph*)(contLevel->First());
  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kYellow);
    curv->SetFillColor(kYellow);
    curv->Draw("SAME CF");
    curv=(TGraph *)(contLevel->After(curv));
  }

  cout << "Drawing -2s" << endl;
  
  contLevel = m_contours["-2s"];

  if (!contLevel)
    //  this can happen more often for this contour if there is insufficient
    // sensitivity close to the SM
    cerr << "No contour level for +2s, have to fill in the central region" << endl;
  else {
    curv = (TGraph*)(contLevel->First());
    for (int i=0; i<contLevel->GetSize(); i++) {
      curv->SetFillColor(kWhite);
      curv->SetLineColor(kYellow);
      curv->Draw("SAME CF");
      curv=(TGraph *)(contLevel->After(curv));
    }
  }
  cout << "Drawing median" << endl;
  
  curv = (TGraph*)(m_contours["median"]->First());
  curv->SetLineColor(kBlack);
  curv->SetLineWidth(2);
  curv->SetLineStyle(2);
  curv->Draw("SAME C");

  legend->AddEntry(curv,"Expected","L");
  
  cout << "Drawing obs" << endl;

  contLevel = m_contours["obs"];
  curv = (TGraph*)(contLevel->First());
  for (int i=0; i<contLevel->GetSize(); i++) {
    curv->SetLineColor(kBlack);
    curv->SetLineWidth(2);
    curv->Draw("SAME C");
    if (!i) legend->AddEntry(curv,"Observed","L");
    curv=(TGraph *)(contLevel->After(curv));
  }

  
  TGraph *SMpoint = new TGraph(1);
  SMpoint->SetPoint(1,0,0);
  SMpoint->Draw("SAME Po");
  
  // smLabel = TPaveText(0,
  //                     m_contours["-2s"]->GetYaxis()->GetXmax()/8,
  //                     m_contours["-2s"]->GetXaxis()->GetXmax()/3->5,
  //                     -m_contours["-2s"]->GetYaxis()->GetXmax()/8);
  // smLabel->SetFillStyle(0);
  // smLabel->SetBorderSize(0);
  // smLabel->AddText(" SM");
  // smLabel->Draw();

  legend->Draw();

  TPaveText *text = new TPaveText(0.566,0.87,0.965,1.101,"NDC");
  text->SetFillStyle(0);
  text->SetBorderSize(0);
  text->AddText(Form("95%% CL Limit on %s and %s",par2latex(par1).Data(),par2latex(par2).Data()));
  text->AddText(0,0.35,Form("#intL dt= %.1f fb^{-1}, #sqrt{s} = %d TeV",intlumifbinv,beamcometev));
  text->Draw();

  // text2 = TPaveText(0.155,0.199,0.974,0.244,"NDC");
  // text2->SetFillStyle(0);
  // text2->SetBorderSize(0);
  // text2->AddText("Values outside contour excluded");
  // text2->Draw();

  //text3 = TPaveText(0.506,0.699,0.905,0.758,"NDC");
  //text3->SetFillStyle(0);
  //text3->SetBorderSize(0);
  //text3->AddText(options.flavorText);
  //text3->Draw();    
  
  finalPlot->RedrawAxis();
  finalPlot->ResetAttPad();
  finalPlot->Update();

  finalPlot->Draw();
  finalPlot->Update();
  finalPlot->Modified();
  finalPlot->Update();
  finalPlot->Print(Form("%s.pdf",plotprefix.Data()));
  finalPlot->Print(Form("%s.eps",plotprefix.Data()));
  finalPlot->Print(Form("%s.png",plotprefix.Data()));

}                                                  // draw2DlimitBFstyle
void AnalyzeWaveforms(char *WaveformsFile = "Waveforms.root", const int nAddedChannels = 5) {
	
	//try to access waveforms file and in case of failure return
	if(gSystem->AccessPathName(WaveformsFile,kFileExists)) {
		cout << "Error: file " << WaveformsFile << " does not exsist. Run .x WaveformsFileMaker.C to create it" << endl;
		return;
	}
	//	gStyle->SetOptFit(111);
	//	gStyle->SetStatFormat("1.3E");
	//	gStyle->SetFitFormat("1.3E");
	
	// fetch the list of trees contained in the waveforms file
	// for every tree generate a waveform graph

	TFile *f = TFile::Open(WaveformsFile);
	TList *listOfKeys = f->GetListOfKeys();
	Int_t numberOfKeys = listOfKeys->GetEntries();
	TList *listOfGraphs = new TList();
	
	// if the waveform file name begins with the string "comparator" it goes in this list
	TList *listOfCompWaves = new TList();
	// if the waveform file name begins with the string "sum output" it goes in this list
	TList *listOfAdderWaves = new TList();

	for(Int_t i = 0; i < numberOfKeys; i++) {
		TString *keyName = new TString(listOfKeys->At(i)->GetName());
		TTree *tree = (TTree*)f->Get(keyName->Data());
		Float_t x = 0;
		Float_t y = 0;
		tree->SetBranchAddress("x",&x);
		tree->SetBranchAddress("y",&y);
		Int_t nentries = tree->GetEntries();

		TString *gName = new TString(keyName->Data());
		gName->Append(" graph");
		TGraphErrors *gWave = new TGraphErrors(nentries);
		gWave->SetName(gName->Data());
		gWave->SetTitle(gName->Data());
		gWave->GetXaxis()->SetTitle("Time");
		gWave->GetYaxis()->SetTitle("Voltage");
	//	gWave->SetBit(TH1::kCanRebin);

		for (Int_t j = 0; j < nentries; j++) {
			tree->GetEntry(j);
			gWave->SetPoint(j,x,y);
		}

		listOfGraphs->Add(gWave);

		if(keyName->BeginsWith("comparator"))
			listOfCompWaves->Add(gWave);

		if(keyName->BeginsWith("sum output"))
			listOfAdderWaves->Add(gWave);

	/*	TString *cName = new TString(keyName->Data());
		cName->Append(" canvas");
		TCanvas *cy = new TCanvas(cName->Data(),cName->Data(),800,600);
		gWave->Draw("AL"); */
	}
	
	cout << listOfAdderWaves->GetEntries() << endl;

	// analysis for waves with no delay

	// global variables

	Double_t xMin,xMax,yStart,yEnd;
	Int_t graphPoints;
	Double_t step;

	// comparator outputs waves sum

	TGraphErrors *gFirstCompWave = (TGraphErrors *)listOfCompWaves->First();

	graphPoints = gFirstCompWave->GetN();
	gFirstCompWave->GetPoint(0,xMin,yStart);
	gFirstCompWave->GetPoint(graphPoints - 1,xMax,yEnd); 

	step = (xMax - xMin)/graphPoints;
	cout << gFirstCompWave->GetName() << endl;
	cout << "xMin = " << xMin << "  xMax = " << xMax << "  graphPoints = " << graphPoints << endl;

	TGraphErrors *gCompSum = new TGraphErrors(graphPoints);
	gCompSum->SetLineColor(kBlue);
	gCompSum->SetLineWidth(2);
	gCompSum->SetName("Comparator Outputs Sum");
	gCompSum->SetTitle("Comparator Outputs Sum");
	Int_t nCompWaves = listOfCompWaves->GetEntries();
	Float_t gx,gy = 0;
	
	// Alpha coefficiens are now written "hard coded" here
	Float_t alphaArray[3] = {0.199,0.201,0.197};
	
	// Deleays coming from the multiplexer are written "hard coded" here
	Float_t muxDelayArray[3] = {0,77.14E-12,192.01E-12};

	for(Int_t i = 0; i < graphPoints; i++) {
		for(Int_t j = 0; j < nCompWaves; j++) {
			TGraphErrors *gCompWave = (TGraphErrors *)listOfCompWaves->At(j);
			gy += (gCompWave->Eval(xMin + i*step + muxDelayArray[j]))*alphaArray[j];
		}
		gCompSum->SetPoint(i,xMin + i*step,gy);
		gy = 0;
	}
	
	// note that there is a manual correction on the x axis for the comparator waves sum to compare them better in the multigraph
	
	Double_t *xArray = gCompSum->GetX();
	for(Int_t i = 0; i < graphPoints; i++) {
		xArray[i] += 5.6E-9;
	}

//	TCanvas *cCompSum = new TCanvas("cCompSum","Comparator Outputs Sum",800,600);
//	gCompSum->Draw("AL");

	// adder outputs waves sum
	
	// THE ANALYSIS FOR THE ADDER OUTPUT WITH NOT DELAY AND 3 CHANNELS ADDED IS DEPRECATED.
	// THERE WAS A MISTAKE IN THE DATA TAKING
	// I'LL KEEP THE CODE HERE FOR FURTHER REFERENCE

/*
	TGraphErrors *gFirstAdderWave = (TGraphErrors *)listOfAdderWaves->First();

	graphPoints = gFirstAdderWave->GetN();
	gFirstAdderWave->GetPoint(0,xMin,yStart);
	gFirstAdderWave->GetPoint(graphPoints - 1,xMax,yEnd);

	step = (xMax - xMin)/graphPoints;
	cout << gFirstAdderWave->GetName() << endl;
	cout << "xMin : " << xMin << "  xMax : " << xMax << endl;

	TGraphErrors *gAdderSum = new TGraphErrors(graphPoints);
	gAdderSum->SetLineWidth(2);
//	gAdderSum->SetLineColor(kGreen);
	gAdderSum->SetLineStyle(9);
	gAdderSum->SetName("Sum of the adder outputs with no delay");
	gAdderSum->SetTitle("Sum of the adder outputs with no delay");
	Int_t nAdderWaves = listOfAdderWaves->GetEntries();
	gy = 0;

	for(Int_t i = 0; i < graphPoints; i++) {
		for(Int_t j = 0; j < nAdderWaves; j++) {
			TGraphErrors *gAdderWave = (TGraphErrors *)listOfAdderWaves->At(j);
			gy += gAdderWave->Eval(xMin + i*step);
		} 
		gAdderSum->SetPoint(i,xMin + i*step,gy);
		gy = 0;
	}

//	TCanvas *cAdderSum = new TCanvas("cAdderSum","Sum of the adder outputs",800,600);
//	gAdderSum->Draw("AL"); 
	
	TGraphErrors *g3ChannelsSumNoDelay = listOfGraphs->FindObject("sum_output_3_channels_(3) graph");
	g3ChannelsSumNoDelay->SetLineColor(kRed);
	g3ChannelsSumNoDelay->SetLineWidth(2);
	
	// note that there is a manual correction on the x axis for the adder output to compare it better in the multigraph
	
	Double_t *xArray = g3ChannelsSumNoDelay->GetX();
	graphPoints = g3ChannelsSumNoDelay->GetN();
	
	for(Int_t i = 0; i < graphPoints; i++) {
		xArray[i] -= 600E-12;
	}
	
	// comparison among the computed adder output ,the real one and the sum of the comparator outputs with alpha coefficients correction
	
	TMultiGraph *mgSumNoDelay = new TMultiGraph();
	mgSumNoDelay->Add(g3ChannelsSumNoDelay);
	mgSumNoDelay->Add(gAdderSum);
	mgSumNoDelay->Add(gCompSum);
	mgSumNoDelay->SetTitle("Collection of graphs for 3 channels sum with no delay");
	
	TCanvas *cmgSumNoDelay = new TCanvas("cmgSumNoDelay", "Collection of graphs for 3 channels sum with no delay", 1200,800);
	cmgSumNoDelay->Update();
	mgSumNoDelay->Draw("AL");
	
	legend = new TLegend(0.6,0.78,0.99,0.99);
	legend->AddEntry(g3ChannelsSumNoDelay, "Actual sum done by the adder", "lp");
	legend->AddEntry(gAdderSum, "Sum of the adder outputs", "lp");
	legend->AddEntry(gCompSum, "Sum of the comparator outputs","lp");
	legend->Draw();
	
	mgSumNoDelay->GetXaxis()->SetTitle("Seconds");
	mgSumNoDelay->GetYaxis()->SetTitle("Volts");
	TPaveText *title = (TPaveText*)cmgSumNoDelay->GetPrimitive("title");
	title->SetX1NDC(0.009);
	title->SetY1NDC(0.94);
	title->SetX2NDC(0.56);
	title->SetY2NDC(0.99);
	cmgSumNoDelay->Modified();
*/
	
	
	// analysis for delayed adder outputs
	
	Int_t nAdderWaves = listOfAdderWaves->GetEntries();

	TGraphErrors *g3ChannelsSumDelay = listOfGraphs->FindObject("sum_output_3_channels_(1-1-1) graph");
	g3ChannelsSumDelay->SetLineColor(kRed);
	g3ChannelsSumDelay->SetLineWidth(2);

	// Delay coming from cables are written "hard coded" here
	Float_t cablesDelayArray[3] = {0,1.45E-9,3.21E-9};
	
	graphPoints = g3ChannelsSumDelay->GetN();
	//g3ChannelsSumDelay->GetPoint(0,xMin,yStart);
	//g3ChannelsSumDelay->GetPoint(graphPoints - 1,xMax,yEnd);
	xMin = 6E-9;
	xMax = 16E-9;
	step = (xMax - xMin)/graphPoints;
	cout << "Sum of the adder outputs with delay" << endl;
	cout << "xMin : " << xMin << "  xMax : " << xMax << endl;

	TGraphErrors *gAdderSumDelay = new TGraphErrors(graphPoints);
	gAdderSumDelay->SetLineColor(kBlue);
	gAdderSumDelay->SetLineWidth(2);
	gAdderSumDelay->SetName("Sum of the adder outputs with delay");
	gAdderSumDelay->SetTitle("Sum of the adder outputs with delay");

	gy = 0;
	
	// note that there is a manual correction on the delay of 500E-12 to compare the adder output better in the multigraph

	for(Int_t i = 0; i < graphPoints; i++) {
		for(Int_t j = 0; j < nAdderWaves; j++) {
			TGraphErrors *gAdderWave = (TGraphErrors *)listOfAdderWaves->At(j);
			gy += gAdderWave->Eval(xMin + i*step + cablesDelayArray[j] - 500E-12);
		} 
		gAdderSumDelay->SetPoint(i,xMin + i*step,gy);
		gy = 0;
	}

	//	TCanvas *cSumSumDelay = new TCanvas("cSumSumDelay","Sum of the sum outputs with delay",800,600);
	//	gAdderSumDelay->Draw("APEL");

	TMultiGraph *mg3ChannelsSumDelay = new TMultiGraph();
	mg3ChannelsSumDelay->Add(gAdderSumDelay);
	mg3ChannelsSumDelay->Add(g3ChannelsSumDelay);
	mg3ChannelsSumDelay->SetTitle("Collection of graphs for 3 channels sum with delay");

	TCanvas *cmg3ChannelsSumDelay = new TCanvas("cmg3ChannelsSumDelay", "Collection of graphs for 3 channels sum with delay", 1200, 800);
	cmg3ChannelsSumDelay->Update();
	
	legend = new TLegend(0.6,0.78,0.99,0.99);
	legend->AddEntry(g3ChannelsSumDelay, "Actual sum done by the adder", "lp");
	legend->AddEntry(gAdderSumDelay, "Sum of the delayed adder outputs", "lp");
	mg3ChannelsSumDelay->Draw("AL");
	legend->Draw();
	
	mg3ChannelsSumDelay->GetXaxis()->SetTitle("Seconds");
	mg3ChannelsSumDelay->GetYaxis()->SetTitle("Volts");
	
	TPaveText *title = (TPaveText*)cmg3ChannelsSumDelay->GetPrimitive("title");
	title->SetX1NDC(0.009);
	title->SetY1NDC(0.94);
	title->SetX2NDC(0.56);
	title->SetY2NDC(0.99);
	
	cmg3ChannelsSumDelay->Modified();

/*
	// delay test just to try a different method

	TMultiGraph *mgDelayTest = new TMultiGraph();
	Double_t gxTest,gyTest;

	TGraphErrors *gDelayTest0 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(0))->GetN());
	for(Int_t j = 0; j < gDelayTest0->GetN(); j++) {
		((TGraphErrors *)listOfAdderWaves->At(0))->GetPoint(j,gxTest,gyTest);
		gDelayTest0->SetPoint(j,gxTest - cablesDelayArray[0],gyTest);
	}
	mgDelayTest->Add(gDelayTest0);

	TGraphErrors *gDelayTest1 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(1))->GetN());
	for(Int_t j = 0; j < gDelayTest1->GetN(); j++) {
		((TGraphErrors *)listOfAdderWaves->At(1))->GetPoint(j,gxTest,gyTest);
		gDelayTest1->SetPoint(j,gxTest - cablesDelayArray[1],gyTest);
	}
	mgDelayTest->Add(gDelayTest1);

	TGraphErrors *gDelayTest2 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(2))->GetN());
	for(Int_t j = 0; j < gDelayTest2->GetN(); j++) {
		((TGraphErrors *)listOfAdderWaves->At(2))->GetPoint(j,gxTest,gyTest);
		gDelayTest2->SetPoint(j,gxTest - cablesDelayArray[2],gyTest);
	}
	mgDelayTest->Add(gDelayTest2);

//	TCanvas *cmgDelayTest = new TCanvas("cmgDelayTest", "cmgDelayTest", 800,600);
//	mgDelayTest->Draw("APEL");

	graphPoints = 12000;
	xMin = 2E-9;
	xMax = 22E-9;
	step = (xMax - xMin)/graphPoints;
	cout << "xMin : " << xMin << "  xMax : " << xMax << endl;

	Double_t delayTest0xMin,delayTest0xMax,delayTest1xMin,delayTest1xMax,delayTest2xMin,delayTest2xMax;
	gDelayTest0->GetPoint(0,delayTest0xMin,gyTest);
	gDelayTest0->GetPoint(gDelayTest0->GetN() - 1,delayTest0xMax,gyTest);
	gDelayTest1->GetPoint(0,delayTest1xMin,gyTest);
	gDelayTest1->GetPoint(gDelayTest1->GetN() - 1,delayTest1xMax,gyTest);
	gDelayTest2->GetPoint(0,delayTest2xMin,gyTest);
	gDelayTest2->GetPoint(gDelayTest2->GetN() - 1,delayTest2xMax,gyTest);

	cout << delayTest0xMin << endl;

	TGraphErrors *gAdderSumDelayV2 = new TGraphErrors(graphPoints);
	for(Int_t i = 0; i < graphPoints; i++) {
		gyTest = gDelayTest0->Eval(xMin + i*step);
		gyTest += gDelayTest1->Eval(xMin + i*step);
		gyTest += gDelayTest2->Eval(xMin + i*step);
		gAdderSumDelayV2->SetPoint(i,xMin + i*step+ 500E-12,gyTest);
	} 
	
	gAdderSumDelayV2->SetLineColor(kGreen);
	gAdderSumDelayV2->SetLineWidth(2);
	mg3ChannelsSumDelay->Add(gAdderSumDelayV2);
	c3ChannelsSumDelay->Modified();

	TCanvas *cAdderSumDelayV2 = new TCanvas("cAdderSumDelayV2","cAdderSumDelayV2",800,600);
	gAdderSumDelayV2->Draw("APL");
*/

	// List of waves representing the adder output with 5,4,3,2,1 channels in input

	TGraphErrors *gAdder5Channels = listOfGraphs->FindObject("adder output 5 channels v2 graph");
	TGraphErrors *gAdder4Channels = listOfGraphs->FindObject("adder output 4 channels v2 graph");
	TGraphErrors *gAdder3Channels = listOfGraphs->FindObject("adder output 3 channels v2 graph");
	TGraphErrors *gAdder2Channels = listOfGraphs->FindObject("adder output 2 channels v2 graph");
	TGraphErrors *gAdder1Channel = listOfGraphs->FindObject("adder output 1 channel v2 graph");
	
	TGraphErrors *gAdderSingleCh0 = listOfGraphs->FindObject("single sum output ch 0 input 500 mV DT 100 mV graph");
	TGraphErrors *gAdderSingleCh1 = listOfGraphs->FindObject("single sum output ch 1 input 500 mV DT 100 mV graph");
	TGraphErrors *gAdderSingleCh4 = listOfGraphs->FindObject("single sum output ch 4 input 500 mV DT 100 mV graph");
	TGraphErrors *gAdderSingleCh5 = listOfGraphs->FindObject("single sum output ch 5 input 500 mV DT 100 mV graph");
	TGraphErrors *gAdderSingleCh7 = listOfGraphs->FindObject("single sum output ch 7 input 500 mV DT 100 mV graph");
	
	TMultiGraph *mgAdder54321Channels = new TMultiGraph();
	mgAdder54321Channels->SetTitle("Collection of graphs for different numbers of added channels");
	mgAdder54321Channels->Add(gAdder5Channels);
	mgAdder54321Channels->Add(gAdder4Channels);
	mgAdder54321Channels->Add(gAdder3Channels);
	mgAdder54321Channels->Add(gAdder2Channels);
	mgAdder54321Channels->Add(gAdder1Channel);
	
	TCanvas *cmgAdder54321Channels = new TCanvas("cmgAdder54321Channels", "Collection of graphs for different numbers of added channels",1200,800);
	mgAdder54321Channels->Draw("AL");
	cmgAdder54321Channels->Update();
	mgAdder54321Channels->GetXaxis()->SetTitle("seconds");
	mgAdder54321Channels->GetYaxis()->SetTitle("Volts");	
	cmgAdder54321Channels->Modified();
	
	// analysis of the linearity of the adder
	
	Double_t addedVMax[nAddedChannels];
	addedVMax[0] = TMath::MaxElement(gAdder1Channel->GetN(), gAdder1Channel->GetY());
	addedVMax[1] = TMath::MaxElement(gAdder2Channels->GetN(), gAdder2Channels->GetY());
	addedVMax[2] = TMath::MaxElement(gAdder3Channels->GetN(), gAdder3Channels->GetY());
	addedVMax[3] = TMath::MaxElement(gAdder4Channels->GetN(), gAdder4Channels->GetY());
	addedVMax[4] = TMath::MaxElement(gAdder5Channels->GetN(), gAdder5Channels->GetY());
	
	Double_t singleVMax[nAddedChannels];
	singleVMax[0] = TMath::MaxElement(gAdderSingleCh0->GetN(), gAdderSingleCh0->GetY());
	singleVMax[1] = TMath::MaxElement(gAdderSingleCh1->GetN(), gAdderSingleCh1->GetY());
	singleVMax[2] = TMath::MaxElement(gAdderSingleCh4->GetN(), gAdderSingleCh4->GetY());
	singleVMax[3] = TMath::MaxElement(gAdderSingleCh5->GetN(), gAdderSingleCh5->GetY());
	singleVMax[4] = TMath::MaxElement(gAdderSingleCh7->GetN(), gAdderSingleCh7->GetY());
	
	vector<double> expectedVMax(nAddedChannels);
	Double_t previousVmax = 0;
	for(Int_t i = 0; i < expectedVMax.size(); i++) {
		expectedVMax[i] = singleVMax[i] + previousVmax;
		previousVmax = expectedVMax[i];
		cout << "singleVMax[" <<i <<"] = " << singleVMax[i] <<  endl;
		cout << "addedVMax[" <<i <<"] = " << addedVMax[i] <<  endl;
		cout << "expectedVMax[" <<i <<"] = " << expectedVMax[i] <<  endl;
	}
	
	TGraph *gAdderLinearity = new TGraph(expectedVMax.size(),&expectedVMax[0],addedVMax);
	gAdderLinearity->SetTitle("Linearity of the adder");
	gAdderLinearity->GetXaxis()->SetTitle("Expected amplitude value (V)");
	gAdderLinearity->GetYaxis()->SetTitle("Actual amplitude value (V)");
	gAdderLinearity->GetYaxis()->SetTitleOffset(1.3);
	
	TCanvas *cgAdderLinearity = new TCanvas("cgAdderLinearity","Linearity of the adder",800,600);
	cgAdderLinearity->SetGrid();
	cgAdderLinearity->Update();
	gAdderLinearity->SetMarkerStyle(20);
	gAdderLinearity->SetMarkerSize(0.8);
	//gAdderLinearity->Fit("pol1","Q+","",expectedVMax[0],expectedVMax[2]);
	TF1 *line = new TF1("line","x",expectedVMax.back(),expectedVMax.front());
	gAdderLinearity->Draw("APEL");
	line->Draw("SAME");
	//gAdderLinearity->GetFunction("pol1")->SetRange(expectedVMax.back(),expectedVMax.front());;
	cgAdderLinearity->SetLeftMargin(0.13);
	cgAdderLinearity->Modified();
	
	f->Close();


}
Exemplo n.º 19
0
TCanvas *ContourList(){

   const Double_t PI = TMath::Pi();

   TCanvas* c = new TCanvas("c","Contour List",0,0,600,600);
   c->SetRightMargin(0.15);
   c->SetTopMargin(0.15);

   Int_t i, j, TotalConts;

   Int_t nZsamples   = 80;
   Int_t nPhiSamples = 80;

   Double_t HofZwavelength = 4.0;       // 4 meters
   Double_t dZ             =  HofZwavelength/(Double_t)(nZsamples - 1);
   Double_t dPhi           = 2*PI/(Double_t)(nPhiSamples - 1);

   TArrayD z(nZsamples);
   TArrayD HofZ(nZsamples);
   TArrayD phi(nPhiSamples);
   TArrayD FofPhi(nPhiSamples);

   // Discretized Z and Phi Values
   for ( i = 0; i < nZsamples; i++) {
      z[i] = (i)*dZ - HofZwavelength/2.0;
      HofZ[i] = SawTooth(z[i], HofZwavelength);
   }

   for(Int_t i=0; i < nPhiSamples; i++){
      phi[i] = (i)*dPhi;
      FofPhi[i] = sin(phi[i]);
   }

   // Create Histogram
   TH2D *HistStreamFn = new TH2D("HstreamFn",
   "#splitline{Histogram with negative and positive contents. Six contours are defined.}{It is plotted with options CONT LIST to retrieve the contours points in TGraphs}",
   nZsamples, z[0], z[nZsamples-1], nPhiSamples, phi[0], phi[nPhiSamples-1]);

   // Load Histogram Data
   for (Int_t i = 0; i < nZsamples; i++) {
      for(Int_t j = 0; j < nPhiSamples; j++){
         HistStreamFn->SetBinContent(i,j, HofZ[i]*FofPhi[j]);
      }
   }

   gStyle->SetPalette(1);
   gStyle->SetOptStat(0);
   gStyle->SetTitleW(0.99);
   gStyle->SetTitleH(0.08);

   Double_t contours[6];
   contours[0] = -0.7;
   contours[1] = -0.5;
   contours[2] = -0.1;
   contours[3] =  0.1;
   contours[4] =  0.4;
   contours[5] =  0.8;

   HistStreamFn->SetContour(6, contours);

   // Draw contours as filled regions, and Save points
   HistStreamFn->Draw("CONT Z LIST");
   c->Update(); // Needed to force the plotting and retrieve the contours in TGraphs

   // Get Contours
   TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
   TList* contLevel = NULL;
   TGraph* curv     = NULL;
   TGraph* gc       = NULL;

   Int_t nGraphs    = 0;
   Int_t TotalConts = 0;

   if (conts == NULL){
      printf("*** No Contours Were Extracted!\n");
      TotalConts = 0;
      return;
   } else {
      TotalConts = conts->GetSize();
   }

   printf("TotalConts = %d\n", TotalConts);

   for(i = 0; i < TotalConts; i++){
      contLevel = (TList*)conts->At(i);
      printf("Contour %d has %d Graphs\n", i, contLevel->GetSize());
      nGraphs += contLevel->GetSize();
   }

   nGraphs = 0;

   TCanvas* c1 = new TCanvas("c1","Contour List",610,0,600,600);
   c1->SetTopMargin(0.15);
   TH2F *hr = new TH2F("hr",
   "#splitline{Negative contours are returned first (highest to lowest). Positive contours are returned from}{lowest to highest. On this plot Negative contours are drawn in red and positive contours in blue.}",
   2, -2, 2, 2, 0, 6.5);

   hr->Draw();
   Double_t x0, y0, z0;
   TLatex l;
   l.SetTextSize(0.03);
   char val[20];

   for(i = 0; i < TotalConts; i++){
      contLevel = (TList*)conts->At(i);
      if (i<3) z0 = contours[2-i];
      else     z0 = contours[i];
      printf("Z-Level Passed in as:  Z = %f\n", z0);

      // Get first graph from list on curves on this level
      curv = (TGraph*)contLevel->First();
      for(j = 0; j < contLevel->GetSize(); j++){
         curv->GetPoint(0, x0, y0);
         if (z0<0) curv->SetLineColor(kRed);
         if (z0>0) curv->SetLineColor(kBlue);
         nGraphs ++;
         printf("\tGraph: %d  -- %d Elements\n", nGraphs,curv->GetN());

	 // Draw clones of the graphs to avoid deletions in case the 1st
	 // pad is redrawn.
         gc = (TGraph*)curv->Clone();
         gc->Draw("C");

         sprintf(val,"%g",z0);
         l.DrawLatex(x0,y0,val);
         curv = (TGraph*)contLevel->After(curv); // Get Next graph
      }
   }
   c1->Update();
   printf("\n\n\tExtracted %d Contours and %d Graphs \n", TotalConts, nGraphs );
   gStyle->SetTitleW(0.);
   gStyle->SetTitleH(0.);
   return c1;
}
Exemplo n.º 20
0
void plotMSSM(const TString& what="(ggA+bbA)*BRAZh*BRhbb"){
  const double BRZll=0.06726;
  const double fb2pb=1000;
  //TString scale(Form("*%f*%f",BRZll,fb2pb));
  TString scale("");

  TString cname(what);
  cname.ReplaceAll("*","x");
  cname.ReplaceAll("(","U");
  cname.ReplaceAll(")","U");
  cname+="_MSSM_mhmax";
  //
  TString goodName(what);
  goodName.ReplaceAll("mh","m_{h}");
  goodName.ReplaceAll("ggA","#sigma_{gg#rightarrowA}");
  goodName.ReplaceAll("bbA","#sigma_{bb#rightarrowA}");
  goodName.ReplaceAll("BRAZh","B(A#rightarrowZh)");
  goodName.ReplaceAll("BRhbb","B(h#rightarrowbb)");
  //goodName+=("*B(Z#rightarrowll)");
  //goodName+=("[pb] ");
  goodName+=("[GeV] ");
  TString goodType("MSSM m_{h}^{max}");
  //goodName=("#sigma*B(pp#rightarrowA#rightarrowZh#rightarrowllbb) [fb]");
  //goodName=("#sigma*B(pp#rightarrowA) [fb]");
  //goodName=("BR(A#rightarrowZh)");
  //goodName=("BR(h#rightarrowbb)");

  //if (m>0) mass=(Form(" * (mA==%d)",m));
  //TString ok(" * validity * stability * perturbativity * unitarity ");
  //TString ok(" * unitarity");
  TString ok("");


  TChain* ch=new TChain("TreeMSSM");

  ch->Add("lsf_working_dir_M225_20636539/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M250_20636540/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M275_20636541/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M300_20636542/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M325_20636543/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M350_20636544/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M400_20636545/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M500_20636546/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M600_20636547/parameter_MSSM.root");

  //double tanbeta[30]={1,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,400,500,600,700,800,900,1000,1100,10000};
  //double tanbeta[51]={0,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380,400,420,440,460,480,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,2000,3000,4000,5000,6000};
  double tanbeta[51]={0,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380,400,420,440,460,500,550,580,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,2000,3000,4000,5000,6000};
  Double_t bin_tb[50];
  for (unsigned int i=0; i<50; i++) {
    bin_tb[i]=0.005*(tanbeta[i]+tanbeta[i+1]);
    //cout << "bin_tb[" << i << "]=" << bin_tb[i] << " " << tanbeta[i+1]/100. << endl;
  }

  double mA[11]={200,225,250,275,300,325,350,400,500,600,700};
  Double_t bin_mA[10];
  for (unsigned int i=0; i<=10; ++i) {
    bin_mA[i]=0.5*(mA[i]+mA[i+1]);
    //cout << "bin_mA["<<i<<"]="  << bin_mA[i] << endl;
  }
  bin_mA[10]=650;
  
  TH2F* hggA=new TH2F("hggA","ggA cross section vs tan#beta,m_{A}; m_{A} GeV; tan#beta",9,bin_mA,49,bin_tb);
  hggA->Sumw2();
  //hggA->Draw();
  TString cut=what+scale+ok;
  cout << "CUT: " << cut << endl;
  ch->Project("hggA","tb:mA",cut);

  TStyle *tdrStyle = gROOT->GetStyle("tdrStyle");
  // Double_t level[15]={.01,.02,.05,.1,.2,.5,1.,2.,5.,10.,20.,50.,100.,200.,500.};
  // hggA->SetContour(14,level);
  // hggA->SetMinimum(level[0]);
  //
  //Double_t level[10]={1.,5.,10.,20.,50.,100.,200.,500.,800.,1000.}; // for x-section
  //Double_t level[10]={100,105,110.,115.,120.,123,125.7,127,130.,135.}; // for mh
  Double_t level[10]={1,2,3.,4.,120.,123,125.7,127,130.,135.}; // for mh
  //Double_t level[10]={.01,.1,.2,0.5,0.6,0.65,0.7,0.75,0.8,0.9}; // for BR
  //Double_t level[10]={.01,.02,.05,.07,.1,.15,0.2,0.5,0.75,1.}; // for BR
  hggA->SetContour(9,level);
  hggA->SetMinimum(level[0]);
  
  Double_t level[7]={122.7.,123.7,125.4,126.0,127.7,128.7.,150}; // for mh
  hggA->SetContour(6,level);
  hggA->SetMinimum(90);
  Int_t colors[7] = {kWhite,kGreen,kGreen+2,kBlack,kGreen+2,kGreen,kWhite};
  tdrStyle->SetPalette((sizeof(colors)/sizeof(Int_t)), colors);

// DRAW
  tdrStyle->SetOptStat(0);
  // tdrStyle->SetPadGridX(true);
  // tdrStyle->SetPadGridY(true);
  // tdrStyle->SetPadTopMargin(0.05);
  // tdrStyle->SetPadBottomMargin(0.13);
  tdrStyle->SetTitleYOffset(1.3);
  tdrStyle->SetTitleXOffset(1.6);
  tdrStyle->SetTitleOffset(1.3,"Z");
  // tdrStyle->SetOptLogz(1);
  // tdrStyle->SetOptLogy(1);
  tdrStyle->SetPadRightMargin(0.14);
  //tdrStyle->SetPalette(1);


  tdrStyle->cd();
  gROOT->ForceStyle();

  cout << "Creating canvas " << cname << endl;
  TCanvas* c1=new TCanvas(cname,goodName,1200,600);
  cout << " done " << c1->GetName() << endl;
  c1->Divide(2);

  c1->cd(1);
  hggA->DrawCopy("lego2");
  gPad->SetLogz();
  gPad->SetLogy();
  //gPad->SetPhi(120);
  gPad->SetPhi(-150);
  //gPad->SetTheta(30);
  gPad->UseCurrentStyle();
  gPad->Update();

  TLatex tl;
  tl.SetTextSize(0.04);
  tl.SetNDC();
  tl.DrawLatex(0.1,0.95,goodName);
  tl.SetTextAlign(11);
  tl.DrawLatex(0.1,0.89,goodType);

  c1->cd(2);
 // tdrStyle->SetPadLeftMargin(0.25);

  gPad->UseCurrentStyle();
  gPad->Update();
  hggA->GetXaxis()->SetTitleOffset(1.1);
  hggA->GetYaxis()->SetTitleOffset(1.1);
  hggA->GetZaxis()->SetTitleOffset(100);
  //hggA->Smooth();
  gPad->SetLogy(kFALSE);
  hggA->DrawCopy("zcont1");
  tl.DrawLatex(0.15,0.97,goodName);
  tl.SetTextAlign(11);
  tl.DrawLatex(0.2,0.9,goodType);

  TCanvas* ctmp=new TCanvas(cname,goodName,600,600);
  hggA->GetYaxis()->SetRangeUser(0.1,10.);
  hggA->DrawCopy("zcont1");
  tl.DrawLatex(0.83,0.97,goodName);
  tl.SetTextAlign(11);
  tl.DrawLatex(0.2,0.9,goodType);
  pCan(ctmp,cname+"_Lin");

  // TH1F* test=new TH1F("test","ggA cross section vs tan#beta; tan#beta",27,bin_tb);
  // ch->Project("test","tb",what);
  // test->Draw();


  TCanvas* c2=new TCanvas(cname+"Obs",goodName,800,800);
  gPad->UseCurrentStyle();
  gPad->Update();
  hggA->GetXaxis()->SetTitleOffset(1.1);
  hggA->GetYaxis()->SetTitleOffset(1.1);
  hggA->DrawCopy("cont list");
  gPad->Update();

  //return;
  // Get Contours
   TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
   TList* contLevel = NULL;
   TGraph* curv     = NULL;
   TGraph* gc       = NULL;

   Int_t nGraphs    = 0;
   Int_t TotalConts = 0;

   if (conts == NULL){
      printf("*** No Contours Were Extracted!\n");
      TotalConts = 0;
      return;
   } else {
      TotalConts = conts->GetSize();
   }

   printf("TotalConts = %d\n", TotalConts);

   for(i = 0; i < TotalConts; i++){
      contLevel = (TList*)conts->At(i);
      printf("Contour %d has %d Graphs\n", i, contLevel->GetSize());
      nGraphs += contLevel->GetSize();
   }

   nGraphs = 0;

   TH2F *hr = new TH2F("hr", ";m_{A};tan#beta", 2, 225, 600, 2, 0.1, 100);

   hr->GetXaxis()->SetTitleOffset(1.1);
   hr->GetXaxis()->SetRangeUser(200,650);
   hr->GetYaxis()->SetTitleOffset(1.2);
   hr->GetYaxis()->SetNdivisions(110,kFALSE);
   hr->GetXaxis()->SetNdivisions(20205,kFALSE);
   hr->Draw();
   Double_t x0, y0, z0;
   TLatex l;
   l.SetTextSize(0.03);
   l.SetTextAlign(32);
   char val[20];

   for(i = 0; i < TotalConts; i++){
      contLevel = (TList*)conts->At(i);
      z0 = level[i];
      printf("Z-Level Passed in as:  Z = %f\n", z0);

      // Get first graph from list on curves on this level
      curv = (TGraph*)contLevel->First();
      for(j = 0; j < contLevel->GetSize(); j++){
        // last point
         //curv->GetPoint(curv->GetN()-1, x0, y0);
        // first point
         curv->GetPoint(2, x0, y0);

         // if (z0<0) curv->SetLineColor(kRed);
         // if (z0>0) curv->SetLineColor(kBlue);
         nGraphs ++;
         printf("\tGraph: %d  -- %d Elements\n", nGraphs,curv->GetN());

	 // Draw clones of the graphs to avoid deletions in case the 1st
	 // pad is redrawn.
         gc = (TGraph*)curv->Clone();
         gc->Draw("C");

         if (z0>=.01) sprintf(val,"%0.2f",z0);
         if (z0>=.1) sprintf(val,"%0.2f",z0);
         if (z0>=1) sprintf(val,"%0.0f",z0);
         l.DrawLatex(x0*0.99,y0,val);
         curv = (TGraph*)contLevel->After(curv); // Get Next graph
      }
   }
   gPad->SetLogy();
   gPad->SetGridx();
   gPad->SetGridy();
   gPad->SetRightMargin(0.05);
   gPad->SetTopMargin(0.10);
   c2->Update();
   printf("\n\n\tExtracted %d Contours and %d Graphs \n", TotalConts, nGraphs );



  tl.SetTextAlign(31);
  tl.DrawLatex(0.8,0.85,goodName);

  tl.SetTextAlign(31);
  tl.DrawLatex(0.8,0.77,goodType);


  pCan(c2,cname+"_BW");

   c1->cd(1);
   gPad->SetLogy();
   gPad->SetLogz();
   c1->cd(2);
   gPad->SetLogy();
   c1->Update();
  pCan(c1,cname);
}
Exemplo n.º 21
0
void drawContour(TString bino="bino", TString jet="nojet", bool print=false) {

  bool useCustomGetContour = false;

  //  TString data_dir = "table_20120131/multiChannel"; // answering preapproval questions
  TString data_dir = "table_20120209/multiChannel"; // last success after answering preapproval questions
  //TString data_dir = ".";

  gStyle->SetOptStat(0);

  TString label = bino + "_mN375_met100_" + jet;
  if(bino.Contains("mNScan")) label = bino + "_met100_" + jet;

  gStyle->SetPalette(1);
  gStyle->SetPadLeftMargin(0.15);

  //  TString option2D = "CONT4 Z";
  TString option2D = "COL Z";

  // for bino & wino
  const int nG = 21;
  const int nS = 21;
  float mGVals[nG+1] = {400, 480, 560, 640, 720, 800, 880, 960, 1040, 1120, 1200, 1280, 1360, 1440, 1520, 1600, 1680, 1760, 1840, 1920, 2000, 2100};
  float mSVals[nS+1] = {400, 480, 560, 640, 720, 800, 880, 960, 1040, 1120, 1200, 1280, 1360, 1440, 1520, 1600, 1680, 1760, 1840, 1920, 2000, 2100};

  // to make valuse on the center of each bin
  float* mGBins = new float[nG+1];
  float* mSBins = new float[nS+1];
  for(int i=0; i<nG+1; i++) mGBins[i] = mGVals[i]-40;
  for(int i=0; i<nS+1; i++) mSBins[i] = mSVals[i]-40;


  // for mNScan
  const int nX = 10;
  const int nY = 23;
  float xVals[nX+1] = {150, 250, 350, 450, 550, 650, 750, 850, 950, 1050, 1150};
  float yVals[nY+1] = {240, 320, 400, 480, 560, 640, 720, 800, 880, 960, 1040, 1120, 1200, 1280, 1360, 1440, 1520, 1600, 1680, 1760, 1840, 1920, 2000, 2100};

  float* xBins = new float[nX+1];
  float* yBins = new float[nY+1];

  for(int i=0; i<nX+1; i++) xBins[i] = xVals[i]-50;
  for(int i=0; i<nY+1; i++) yBins[i] = yVals[i]-40;


  TFile* fout = new TFile("hist_exclusion_"+label+".root","RECREATE");

  const int nxs = 6;
  TString xsname[nxs] = {"xsec","xsec_1L","xsec_1H","xsec_2L","xsec_2H","acc"};
  TH2D* h_xs[nxs];
  for(int i=0; i<nxs; i++) {
    if(bino.Contains("mNScan")) h_xs[i] = new TH2D(xsname[i],xsname[i],nX,xBins,nY,yBins);
    else h_xs[i] = new TH2D(xsname[i],xsname[i],nS,mSBins,nG,mGBins);
  }

  const int nlimit = 6;
  TString limitname[nlimit] = {"limit", "exp", "exp_1L","exp_1H","exp_2L","exp_2H"};
  TH2D* h_limit[nlimit];
  for(int i=0; i<nlimit; i++) {
    if(bino.Contains("mNScan")) h_limit[i] = new TH2D(limitname[i],limitname[i],nX,xBins,nY,yBins);
    else h_limit[i] = new TH2D(limitname[i],limitname[i],nS,mSBins,nG,mGBins);
  }

  TString datafile = data_dir + "/" + bino + "_" + jet + ".table";

  std::ifstream fin;
  fin.open(datafile.Data());
  while(1){
    // #echo "mS mG mN acc xsec xsecPDFError xsecRSErrorNeg xsecRSErrorPos obsLimit expLimit exp_m1s exp_m2s exp_p1s exp_p2s"
    int mS, mG, mN;
    double acc, xsec, xsecPDFError, xsecRSErrorNeg, xsecRSErrorPos, obsLimit, expLimit, exp_m1s, exp_m2s, exp_p1s, exp_p2s;
    fin >> mS >> mG >> mN >> acc >> xsec >> xsecPDFError >> xsecRSErrorNeg >> xsecRSErrorPos >> obsLimit >> expLimit >> exp_m1s >> exp_m2s >> exp_p1s >> exp_p2s;
    if(!fin.good()) break;

//     std::cout << mS << ", " << mG << ", " << mN << ", " << acc << ", " << xsec << ", " << xsecPDFError << ", "
// 	      << xsecRSErrorNeg << ", " << xsecRSErrorPos << ", " << obsLimit << ", " << expLimit << ", "
// 	      << exp_m1s << ", " << exp_m2s << ", " << exp_p1s << ", " << exp_p2s << std::endl;

    double oneSigma_L = std::sqrt(xsecRSErrorNeg * xsecRSErrorNeg + xsecPDFError * xsecPDFError);
    double oneSigma_H = std::sqrt(xsecRSErrorPos * xsecRSErrorPos + xsecPDFError * xsecPDFError);

    if(bino.Contains("mNScan")) {
      if(mS != 2500) continue;
      h_xs[5]->Fill(mN,mG,acc);
      h_xs[0]->Fill(mN,mG,xsec);
      h_xs[1]->Fill(mN,mG,xsec - xsec*oneSigma_L);
      h_xs[2]->Fill(mN,mG,xsec + xsec*oneSigma_H);
      h_xs[3]->Fill(mN,mG,xsec - xsec*2*oneSigma_L);
      h_xs[4]->Fill(mN,mG,xsec + xsec*2*oneSigma_H);

      h_limit[0]->Fill(mN,mG,obsLimit*xsec);
      h_limit[1]->Fill(mN,mG,expLimit*xsec);
      h_limit[2]->Fill(mN,mG,exp_m1s*xsec);
      h_limit[3]->Fill(mN,mG,exp_p1s*xsec);
      h_limit[4]->Fill(mN,mG,exp_m2s*xsec);
      h_limit[5]->Fill(mN,mG,exp_p2s*xsec);
    }
    else {
      if(mN != 375) continue;
      h_xs[5]->Fill(mS,mG,acc);
      h_xs[0]->Fill(mS,mG,xsec);
      h_xs[1]->Fill(mS,mG,xsec - xsec*oneSigma_L);
      h_xs[2]->Fill(mS,mG,xsec + xsec*oneSigma_H);
      h_xs[3]->Fill(mS,mG,xsec - xsec*2*oneSigma_L);
      h_xs[4]->Fill(mS,mG,xsec + xsec*2*oneSigma_H);

      h_limit[0]->Fill(mS,mG,obsLimit*xsec);
      h_limit[1]->Fill(mS,mG,expLimit*xsec);
      h_limit[2]->Fill(mS,mG,exp_m1s*xsec);
      h_limit[3]->Fill(mS,mG,exp_p1s*xsec);
      h_limit[4]->Fill(mS,mG,exp_m2s*xsec);
      h_limit[5]->Fill(mS,mG,exp_p2s*xsec);
    }// if - else

  }// while
  fin.close();

  for(int i=0; i<nxs; i++) fillPotHoles(h_xs[i]);
  for(int i=0; i<nlimit; i++) fillPotHoles(h_limit[i]);


  TGraph* noRegion2 = new TGraph(3);
  noRegion2->SetPoint(0,200,200);
  noRegion2->SetPoint(1,1100,200);
  noRegion2->SetPoint(2,1100,1100);
  noRegion2->SetFillColor(16);

  TLatex* lat44 = new TLatex(0.7,0.25,"#tilde{g} NLSP");
  lat44->SetNDC(true);
  lat44->SetTextSize(0.04);


  TString title;

  TCanvas* can_acc = new TCanvas("can_acc_"+label,"can_acc_"+label,1000,800);
  can_acc->SetRightMargin(0.19);
  h_xs[5]->GetXaxis()->SetNdivisions(505);
  h_xs[5]->GetYaxis()->SetNdivisions(505);
  h_xs[5]->GetYaxis()->SetTitleOffset(1.2);
  h_xs[5]->GetZaxis()->SetTitleOffset(1.2);
  title = ";m_{#tilde{q}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});Acceptance";
  if(bino.Contains("mNScan")) title = ";m_{#chi^{0}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});Acceptance";
  h_xs[5]->SetTitle(title);
  h_xs[5]->Draw(option2D);
  if(bino.Contains("mNScan")){
    noRegion2->Draw("same f");
    lat44->Draw("same");
  }
  if(print) {
    can_acc->Print("",".gif");
    can_acc->Print("",".pdf");
  }



  TCanvas* can_xs = new TCanvas("can_xsec_"+label,"can_xsec_"+label,1000,800);
  can_xs->SetRightMargin(0.17);
  can_xs->SetLogz();
  h_xs[0]->GetXaxis()->SetNdivisions(505);
  h_xs[0]->GetYaxis()->SetNdivisions(505);
  h_xs[0]->GetYaxis()->SetTitleOffset(1.2);
  h_xs[0]->GetZaxis()->SetTitleOffset(1.0);
  title = ";m_{#tilde{q}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});Cross Section (pb)";
  if(bino.Contains("mNScan")) title = ";m_{#chi^{0}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});Cross Section (pb)";
  h_xs[0]->SetTitle(title);
  h_xs[0]->Draw(option2D);
  if(bino.Contains("mNScan")){
    noRegion2->Draw("same f");
    lat44->Draw("same");
  }
  if(print) {
    can_xs->Print("",".gif");
    can_xs->Print("",".pdf");
  }

  TCanvas* can_limit = new TCanvas("can_limit_"+label,"can_limit_"+label,1000,800);
  can_limit->SetRightMargin(0.2);
  h_limit[0]->GetXaxis()->SetNdivisions(505);
  h_limit[0]->GetYaxis()->SetNdivisions(505);
  h_limit[0]->GetYaxis()->SetTitleOffset(1.2);
  h_limit[0]->GetZaxis()->SetTitleOffset(1.3);
  if(bino.Contains("wino")){
    can_limit->SetRightMargin(0.17);
    h_limit[0]->GetZaxis()->SetTitleOffset(1.0);
  }

  title = ";m_{#tilde{q}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});95% CL Upper Limit (pb)";
  if(bino.Contains("mNScan")) title = ";m_{#chi^{0}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2});95% CL Upper Limit (pb)";
  h_limit[0]->SetTitle(title);
  h_limit[0]->Draw(option2D);
  if(bino.Contains("mNScan")){
    noRegion2->Draw("same f");
    lat44->Draw("same");
  }
  if(print) {
    can_limit->Print("",".gif");
    can_limit->Print("",".pdf");
  }

  // now find exclusion curves
  TCanvas* can_diff = new TCanvas("can_diff_"+label,"can_diff_"+label,1200,800);
  //  can_diff->Divide(nlimit,nxs);
  TH2D* h_excl[nlimit][nxs-1];
  for(int i=0; i<nlimit; i++) {
    for(int j=0; j<nxs-1; j++) {

      h_excl[i][j] = (TH2D*) h_limit[i]->Clone("exclusion_"+limitname[i]+"_"+xsname[j]);
      int nbinsx = h_excl[i][j]->GetXaxis()->GetNbins();
      int nbinsy = h_excl[i][j]->GetYaxis()->GetNbins();

      for( int ibx=1; ibx<=nbinsx; ++ibx){
	for( int iby=1; iby<=nbinsy; ++iby){
	  double x1 = h_limit[i]->GetBinContent(ibx,iby);
	  double x2 = h_xs[j]->GetBinContent(ibx,iby);
	  h_excl[i][j]->SetBinContent(ibx,iby,x2-x1);
	  x1 = h_limit[i]->GetBinError(ibx,iby);
	  x2 = h_xs[j]->GetBinError(ibx,iby);
	  h_excl[i][j]->SetBinError(ibx,iby,std::sqrt(x1*x1+x2*x2));
	}// for iby
      }// for ibx
      fixBadCells(h_excl[i][j]);
      if(i==0 && j==0) h_excl[i][j]->Draw("TEXT");
    }// for j
  }// for i


  float xmin = 400;
  float ymin = 400;
  float xmax = 2000;
  float ymax = 2000;
  if(bino.Contains("mNScan")){
    xmin = 200;
    xmax = 1500;
    ymin = 300;
    ymax = 2000;
  }


  TGraph* curv[nlimit][nxs-1];
  TGraphSmooth* gsmooth = new TGraphSmooth("normal");

  TH2D* h_back;
  if(bino.Contains("mNScan")) h_back = new TH2D("h_back",";m_{#tilde{#chi^{0}}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2})",100,xmin,xmax,100,ymin,ymax);
  else h_back = new TH2D("h_back",";m_{#tilde{q}} (GeV/c^{2});m_{#tilde{g}} (GeV/c^{2})",100,xmin,xmax,100,ymin,ymax);

  h_back->GetXaxis()->SetNdivisions(505);
  h_back->GetYaxis()->SetNdivisions(505);
  h_back->GetYaxis()->SetTitleOffset(1.2);


  double contours[2]={ 0.0, 1.0 };
  TCanvas *can_excl01 = new TCanvas("can_excl01_"+label, "can_excl01_"+label,1200,800);
  can_excl01->Divide(nlimit,nxs-1);
  for(int i=0; i<nlimit; i++) {
    for(int j=0; j<nxs-1; j++) {

      can_excl01->cd(j*nlimit + i + 1);
      h_back->Draw();

      if(useCustomGetContour) {
        curv[i][j] = getContour(h_excl[i][j],"excl_curv_"+limitname[i]+"_"+xsname[j]);
        curv[i][j]->Draw("SAME L");
      }
      else {
	h_excl[i][j]->SetContour(2,contours);
	h_excl[i][j]->Draw("SAME CONT LIST");
	gPad->Update();

	TObjArray *contsM = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
	TList* contLevel = (TList*)contsM->At(0);
	curv[i][j] = (TGraph*)contLevel->First()->Clone("excl_curv_"+limitname[i]+"_"+xsname[j]);
      }
      //      PrintPoints(curv[i][j]);
      //      RemovePoints(curv[i][j]);

    }// for j
  }// for i

  if(bino.Contains("mNScan")) {
    for(int i=0; i<nlimit; i++) {
      for(int j=0; j<nxs-1; j++) {
	RemovePoints(curv[i][j]);
      }
    }

    for(int i=0; i<nlimit; i++) {
      for(int j=0; j<nxs-1; j++) {
	double x,y;
	int whichone = curv[i][j]->GetN()-1;
	curv[i][j]->GetPoint(whichone-1,x,y);
	curv[i][j]->SetPoint(whichone,y,y);
      }
    }
  }

  TGraphSmooth* gs[nlimit][nxs-1];
  TGraph* curvS[nlimit][nxs-1];
  for(int i=0; i<nlimit; i++) {
    for(int j=0; j<nxs-1; j++) {
      //      gs[i][j] = new TGraphSmooth("normal");
      //      curvS[i][j] = gs[i][j]->SmoothSuper(curv[i][j]);
      curvS[i][j] = (TGraph*) curv[i][j]->Clone();
      curvS[i][j]->SetName("excl_curvS_"+limitname[i]+"_"+xsname[j]);
    }
  }

  std::cout << "curv[3][0]----------------- N : " << curv[3][0]->GetN() << std::endl;
  PrintPoints(curv[3][0]);
  std::cout << "curvS[3][0]----------------- N : " << curvS[3][0]->GetN() << std::endl;
  PrintPoints(curvS[3][0]);
  std::cout << "---------------------------------" << std::endl;


  // make excluded region
  TGraph* excludedRegion = new TGraph(curvS[0][0]->GetN()+3);
  int nbins = curvS[0][0]->GetN();
  for(int i=0; i<nbins; i++){
    double x,y;
    curvS[0][0]->GetPoint(i,x,y);
    excludedRegion->SetPoint(i,x,y);
  }

  excludedRegion->SetPoint(nbins,xmax,ymin);
  excludedRegion->SetPoint(nbins+1,xmin,ymin);
  excludedRegion->SetPoint(nbins+2,xmin,ymax);

  // make band graph
  TGraph* exp1sigma_aroundExp = makeBandGraph(curvS[2][0],curvS[3][0]);


  TCanvas* can_excl02 = new TCanvas("can_excl02_"+label, "can_excl02_"+label,1000,800);
  h_back->Draw();
  //  can_excl02->SetGrid(1,1);

  // ecluded region
  excludedRegion->SetFillColor(kBlue-10);
  excludedRegion->SetFillStyle(1001);
  excludedRegion->Draw("SAME F");

  // experimental 1 sigma band around expected limit
  exp1sigma_aroundExp->SetFillColor(kOrange-3);
  exp1sigma_aroundExp->SetFillStyle(1001);
  exp1sigma_aroundExp->Draw("SAME F");

  // expected limit
  curvS[1][0]->SetLineStyle(9);
  curvS[1][0]->SetLineWidth(2);
  curvS[1][0]->SetLineColor(kOrange+9);
  curvS[1][0]->Draw("SAME L");

  // theory 1 sigma around expected limit
  curvS[1][1]->SetLineStyle(3);
  curvS[1][1]->SetLineWidth(1);
  curvS[1][1]->SetLineColor(kOrange+9);
  curvS[1][1]->Draw("SAME L");

  curvS[1][2]->SetLineStyle(3);
  curvS[1][2]->SetLineWidth(1);
  curvS[1][2]->SetLineColor(kOrange+9);
  curvS[1][2]->Draw("SAME L");

  // observed limit
  curvS[0][0]->SetLineWidth(3);
  curvS[0][0]->SetLineColor(4);
  curvS[0][0]->Draw("SAME L");

  // theory 1 sigma around observed limit
  curvS[0][1]->SetLineStyle(3);
  curvS[0][1]->SetLineWidth(2);
  curvS[0][1]->SetLineColor(kBlue);
  curvS[0][1]->Draw("SAME L");

  curvS[0][2]->SetLineStyle(3);
  curvS[0][2]->SetLineWidth(2);
  curvS[0][2]->SetLineColor(kBlue);
  curvS[0][2]->Draw("SAME L");


  PrintPoints(curvS[0][0]);


  float leg_xmin = 0.65;
  float leg_xmax = 0.9;
  float leg_ymin = 0.5;
  float leg_ymax = 0.8;
  if(bino.Contains("mNScan")){
    leg_xmin -= 0.45;
    leg_xmax -= 0.45;
  }


  TLegend* leg;
  if(bino.Contains("mNScan")) leg = new TLegend(leg_xmin,leg_ymin,leg_xmax,leg_ymax,"","brNDC");
  else leg = new TLegend(leg_xmin,leg_ymin,leg_xmax,leg_ymax,"GGM "+bino+"-like #tilde{#chi}^{0}","brNDC");
  leg->SetFillColor(0);
  leg->SetLineColor(0);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);
  leg->SetTextSize(0.03);
  if(bino.Contains("mNScan")) leg->AddEntry("NULL","m_{#tilde{q}} = 2500 (GeV/c^{2})","h");
  else leg->AddEntry("NULL","m_{#tilde{#chi}^{0}} = 375 (GeV/c^{2})","h");
  TString jetRequirement = "Without jet requirement";
  if(jet.Contains("1jet")) jetRequirement = "At least 1 jet requirement";
  leg->AddEntry("NULL",jetRequirement,"h");
  leg->AddEntry("NULL","NLO Limits","h");
  leg->AddEntry(curvS[0][0],"Observed","L");
  leg->AddEntry(curvS[0][1],"#pm1#sigma (theory)","L");
  leg->AddEntry(curvS[1][0],"Expected","L");
  leg->AddEntry(curvS[1][1],"#pm1#sigma (theory)","L");
  leg->AddEntry(exp1sigma_aroundExp,"#pm1#sigma (experimental)","F");
  leg->Draw("same");

  TLatex* lat = new TLatex(leg_xmin+0.02,0.87,"CMS Preliminary");
  lat->SetNDC(true);
  lat->SetTextFont(43);
  lat->SetTextSize(30);
  lat->Draw("same");

  TLatex* lat2 = new TLatex(leg_xmin,0.83,"#int #font[12]{L}dt = 4.7fb^{-1}, #sqrt{s} = 7 TeV");
  lat2->SetNDC(true);
  lat2->SetTextFont(43);
  lat2->SetTextSize(24);
  lat2->Draw("same");

  float xv = 0.25;
  float yv = 0.25;
  if(bino.Contains("wino")){
    xv = 0.23;
    yv = 0.23;
  }
  if(bino.Contains("mNScan")){
    xv = 0.2;
    yv = 0.3;
  }
  TLatex* lat3 = new TLatex(xv,yv,"Excluded");
  lat3->SetNDC(true);
  lat3->SetTextFont(52);
  lat3->SetTextSize(0.06);
  lat3->Draw("same");

  TGraph* noRegion = new TGraph(3);
  noRegion->SetPoint(0,TMath::Min(xmin,ymin),TMath::Min(xmin,ymin));
  noRegion->SetPoint(1,xmax,ymin);
  noRegion->SetPoint(2,TMath::Min(xmax,ymax),TMath::Min(xmax,ymax));
  noRegion->SetFillColor(16);

  TLatex* lat4 = new TLatex(0.7,0.25,"#tilde{g} NLSP");
  lat4->SetNDC(true);
  lat4->SetTextSize(0.04);

  if(bino.Contains("mNScan")){
    noRegion->Draw("same f");
    lat4->Draw("same");
  }

  can_excl02->RedrawAxis();


  if(print) {
    can_excl02->Print("",".gif");
    can_excl02->Print("",".pdf");
  }

  fout->cd();
  fout->Write();

  can_acc->Write();
  can_xs->Write();
  can_limit->Write();
  can_excl01->Write();
  can_excl02->Write();

  for(int i=0; i<nlimit; i++){
    for(int j=0; j<nxs-1; j++){
      curv[i][j]->Write();
      curvS[i][j]->Write();
    }
  }


}