示例#1
0
void pointsed(TString filename = "btagpatanalyzerpy.root", TString check="") {
	TString cmssw;
	// 167
	
	cmssw = "$3.1.0_pre9$";
	
	TFile *f = TFile::Open(filename);
/////////////////////////////////////////////////////////////////////////////////////////
	std::vector< TString > checks;
	checks.push_back("");
	checks.push_back("Corr30_");
	checks.push_back("Corr30t0_");
	checks.push_back("Corr30t1_");
	checks.push_back("Corr30t2_");
	checks.push_back("Corr30t0_nConstituent_");
	checks.push_back("Corr30t1_nConstituent_");
	checks.push_back("Corr30t2_nConstituent_");
	checks.push_back("Uncor10_");
	checks.push_back("Uncor10t0_");
	checks.push_back("Uncor10t1_");
	checks.push_back("Uncor10t2_");
	checks.push_back("Uncor10t0_nConstituent_");
	checks.push_back("Uncor10t1_nConstituent_");
	checks.push_back("Uncor10t2_nConstituent_");
/////////////////////////////////////////////////////////////////////////////////////////
	std::vector< TString > taggers;
	std::vector< TString > labeltag;
        std::vector< int> colorlines;
	taggers.push_back( "TC2" );colorlines.push_back( 1 );labeltag.push_back( "TCHE");
	taggers.push_back( "TC3" );colorlines.push_back( 2 );labeltag.push_back( "TCHP");
	taggers.push_back( "TP"  );colorlines.push_back( 3 );labeltag.push_back( "JP");
	taggers.push_back( "SSV" );colorlines.push_back( 4 );labeltag.push_back( "SSV");
	taggers.push_back( "CSV" );colorlines.push_back( 5 );labeltag.push_back( "CSV");
	taggers.push_back( "MSV" );colorlines.push_back( 6 );labeltag.push_back( "CSVMVAB");
	taggers.push_back( "SMT" );colorlines.push_back( 8 );labeltag.push_back( "SMT");
	taggers.push_back( "BTP" );colorlines.push_back( 9 );labeltag.push_back( "JBP");
	taggers.push_back( "SMTbyIP3d" );colorlines.push_back( 11 );labeltag.push_back( "SMTByIP3d");
	taggers.push_back( "SMTbyPt" );colorlines.push_back( 12 );labeltag.push_back( "SMTByPt");
	taggers.push_back( "SETbyIP3d" );colorlines.push_back( 13 );labeltag.push_back( "SETByIP3d");
	taggers.push_back( "SETbyPt" );colorlines.push_back( 14 );labeltag.push_back( "SETByPt");
//	taggers.push_back( "IPM" );colorlines.push_back( 11 );labeltag.push_back( "IPMVAB");
//	taggers.push_back( "SMNIPT" );colorlines.push_back( 12 );labeltag.push_back( "SMTNoIP");

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
//ed	for ( size_t ichks = 0; ichks < checks.size(); ++ichks ) {
//ed		TString check = checks[ichks];
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
        TString PerfTitle= check;
        if (check == "") PerfTitle="uncorr pt>30";
	if (check == "Corr30_") PerfTitle="pt>30";
	if (check == "Corr30t0_") PerfTitle="pt>30, #tracks > 0";
	if (check == "Corr30t1_") PerfTitle="pt>30, #tracks > 1";
	if (check == "Corr30t2_") PerfTitle="pt>30, #tracks > 2";
	if (check == "Corr30t0_nConstituent_") PerfTitle="pt>30, #tracks > 0 & nConstituents >1";
	if (check == "Corr30t1_nConstituent_") PerfTitle="pt>30, #tracks > 1 & nConstituents >1";
	if (check == "Corr30t2_nConstituent_") PerfTitle="pt>30, #tracks > 2 & nConstituents >1";
	if (check == "Uncor10_") PerfTitle="uncorr pt>10";
	if (check == "Uncor10t0_") PerfTitle="uncorr pt>10 #tracks > 0";
	if (check == "Uncor10t1_") PerfTitle="uncorr pt>10 #tracks > 1";
	if (check == "Uncor10t2_") PerfTitle="uncorr pt>10 #tracks > 2";
	if (check == "Uncor10t0_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 0 & nConstituents >1";
	if (check == "Uncor10t1_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 1 & nConstituents >1";
	if (check == "Uncor10t2_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 2 & nConstituents >1";

	std::vector< TString > discriminators;
        for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
  		discriminators.push_back( check+"disc"+taggers[itagger]+"_udsg" );
	}
//	discriminators.push_back( "discTC3_udsg" );
//	discriminators.push_back( "discTP_udsg" );

	TCanvas *cv = new TCanvas("cv","cv",900,900);
	TMultiGraph *mg =new TMultiGraph();
	TLegend *legend0 = new TLegend(0.68,0.12,0.88,0.32);
        // inverted axis
	TMultiGraph *mginv =new TMultiGraph();
	TLegend *legend1 = new TLegend(0.65,0.18,0.85,0.48);
	std::ofstream salida("BTagPATop3"+check+".txt");
	
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {

		TString tag    = check+"g"+taggers[itagger]+"_udsg";
		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tag);

		
		TGraph *dgraph = (TGraph*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+discriminators[itagger]);
//		TGraph *udsgvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),dgraph->GetX());
		dgraph->Sort();
//		udsgvsdgraph->Sort();

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		g->SetLineColor(itagger+1);
                legend0 -> AddEntry(g,taggers[itagger],"l");
		mg->Add(g);

                //inverted axis
		TGraphErrors *ginv = new TGraphErrors(agraph->GetN(),agraph->GetX(),agraph->GetY(),agraph->GetEX(),agraph->GetEY());
		ginv->Sort();
		ginv->SetLineColor(colorlines[itagger]);
		ginv->SetMarkerStyle(8);
		ginv->SetMarkerColor(colorlines[itagger]);
                legend1 -> AddEntry(ginv,labeltag[itagger],"l");
		mginv->Add(ginv);

		std::cout << " Tagger: " << tag << std::endl;
		std::cout << " Loose(10%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.1) << " b-eff = " << g->Eval(0.1) << std::endl;
		std::cout << " Medium(1%):  " << " cut > " << std::setprecision(4) << dgraph->Eval(0.01) << " b-eff = " << g->Eval(0.01) << std::endl;
		std::cout << " Tight(0.1%) = " << " cut > " << std::setprecision(4) << dgraph->Eval(0.001) << " b-eff = " << g->Eval(0.001) << std::endl;
                salida << " " << taggers[itagger] << endl;
	        salida << " #bin \t b-eff  \t err-beff \t  non-beff \t err-non-b"<< endl;
        	for ( size_t i=0;i< agraph->GetN();i++){ 
			salida	<< "  " << (i+1) << " \t "
				<< agraph->GetX()[i] <<" \t " 
				<< agraph->GetEX()[i]<<" \t "
				<< agraph->GetY()[i] <<" \t "
				<< agraph->GetEY()[i]
                       		<< " "<< endl;
		}

	}
//	cv->SetLogx();
	mg->Draw("ALP");
	mg->GetYaxis()->SetTitle("b-eff");
	mg->GetXaxis()->SetTitle("udsg-mistagging");
	legend0 -> Draw();
        cv-> SetGrid();
	cv-> Print ("BTagPATop"+check+".eps");
	cv-> Print ("BTagPATop"+check+".png");
	cv->cd(0);
	cv->SetLogx();
	mg->Draw("ALP");
	legend0 -> Draw();
	cv-> Print ("BTagPATop1"+check+".eps");
	cv-> Print ("BTagPATop1"+check+".png");
        //inverted axis
	TCanvas *cvinv = new TCanvas("cvinv","cvinv",700,700);
        cvinv->SetLogy(0);
	mginv->Draw("ALP");
	mginv->GetXaxis()->SetTitle("b-eff");
	mginv->GetYaxis()->SetTitle("udsg-mistagging");
	legend1 -> Draw();
        cvinv->SetGrid();
	cvinv-> Print ("BTagPATop2"+check+".eps");
	cvinv-> Print ("BTagPATop2"+check+".png");
	cvinv->cd(0);
//	cvinv->Update();
//	cvinv->SetLogx();
//	mginv->SetXmin(10^-4);
//      axis range using a histogram helper
    TH2D*hpx = new TH2D("hpx",PerfTitle,200,0.0,1.005,200,0.00002,1.05);
        hpx->SetStats(kFALSE);
		hpx->Draw();
	hpx->GetXaxis()->SetTitle("b-eff");
	hpx->GetYaxis()->SetTitle("udsg-mistagging");
	cvinv->SetLogy(1);
	mginv->Draw("AP");
	legend1 -> Draw();
	cvinv-> Print ("BTagPATop3"+check+".eps");
	cvinv-> Print ("BTagPATop3"+check+".png");
	//ed}
}
示例#2
0
map<int,vector<double> > RPCChambersCluster::getReconstructedHits(vector<unsigned> vectorOfReferenceChambers, const int & timeWindow,const int & timeReference,bool & isVerticalTrack,map<int,double> & scintilatorsCoordinates,const bool & keepRecoTrack,TFile * fileForRecoTracks,const int & eventNum,const double & correlationFactor, const ESiteFileType & fileType){
  
  // 
  
  map<int,vector<double> > mapOfHits; //
  // the default value for Chi2goodness is 20 
  //double best_chi2goodnes_value = Chi2goodness+10 ; // this variable is used as reference so that it holds the best chi2 found for a track, so its used only a track with better chi2 to be accepted
  double currentBestCorrFact = -2;
  
  int lastFitPoint = 0;
  
  for (int i = 0 ; i < this->getNumberOfChambers() ; i++){
    this->getChamberNumber(i+1)->findAllClustersForTriggerTimeReferenceAndTimeWindow(timeReference,timeWindow,5);
    //cout  << "Chamber is " << i+1 << endl;
  }
  
  vector<vector<int> > vectorOfClusterNumberCombinations;  
  
  if (fileType == kIsCERNrawFile ){
    
    assert(vectorOfReferenceChambers.size() == 3 );
    
    lastFitPoint = 9;
    
    for ( int i = 0 ; i < this->getChamberNumber(vectorOfReferenceChambers[0])->getNumberOfClusters() ; i++ ){
      for( int j = 0 ; j < this->getChamberNumber(vectorOfReferenceChambers[1])->getNumberOfClusters() ; j++ ){
	for( int k = 0 ; k < this->getChamberNumber(vectorOfReferenceChambers[vectorOfReferenceChambers.size()-1])->getNumberOfClusters() ; k++ ){
	  
	  vector<int> singleCombination;
	  
	  singleCombination.push_back(i+1);
	  singleCombination.push_back(j+1);
	  singleCombination.push_back(k+1);
	  
	  for (int f = 0 ; f < singleCombination.size() ; f++){	  
	    if(this->getChamberNumber(vectorOfReferenceChambers[f])->getSizeOfCluster(singleCombination.at(f)) > 5 ) continue;	  
	    // don't insert combination if there is too big cluster. 
	  }
	  
	  vectorOfClusterNumberCombinations.push_back(singleCombination);
	  
	}
      }
    }
  }
  
  if (fileType == kIsBARCrawFile || fileType == kIsGENTrawFile ){
    // add implementation for BARC and Ghent stand . 
    lastFitPoint = 5;
    
    assert(vectorOfReferenceChambers.size() == 2);
    
    for ( int i = 0 ; i < this->getChamberNumber(vectorOfReferenceChambers[0])->getNumberOfClusters() ; i++ ){
      for( int j = 0 ; j < this->getChamberNumber(vectorOfReferenceChambers[1])->getNumberOfClusters() ; j++ ){
      
	vector<int> singleCombination;
	singleCombination.push_back(i+1);
	singleCombination.push_back(j+1);
	
	for (int f = 0 ; f < singleCombination.size() ; f++){
	  if(this->getChamberNumber(vectorOfReferenceChambers[f])->getSizeOfCluster(singleCombination.at(f)) > 5 ) continue;
	  // don't insert combination if there is too big cluster. 
	}
	
	vectorOfClusterNumberCombinations.push_back(singleCombination);
      
      }
    }
  }
  
  string topScintToString, botScintToString;
  
  for (int combinationsVectorElement = 0 ; combinationsVectorElement < vectorOfClusterNumberCombinations.size() ; combinationsVectorElement ++){
    
    // the partition logic start  here - track could pass more than one partition
    
    int direction = 0 ; // direction should describe how the partition changes from one reference chamber to another. It 
    vector<int> RefChamberClusterPartition;
    bool positive = false;
    bool negative = false;
    int partitionPenetrated = 1;
    
    // the Y coordinate is the partition number (1 2 or 3 - A B or C)
    
    vector<int> clusterNum = vectorOfClusterNumberCombinations.at(combinationsVectorElement);
    
    for (int ii = 0; ii < clusterNum.size() ; ii++){
      RefChamberClusterPartition.push_back(this->getChamberNumber(vectorOfReferenceChambers[ii])->getXYCoordinatesOfCluster(clusterNum.at(ii)).at(1));
    }
    
    isVerticalTrack = true;
    
    for ( int ii = 0; ii < RefChamberClusterPartition.size() - 1 ; ii++ ){
      direction = (RefChamberClusterPartition.at(ii) - RefChamberClusterPartition.at(ii+1));
      if (direction != 0) { 
	direction = direction/abs(direction); 
	partitionPenetrated++;
      } // get only the sign ( +1 or -1)
      if (direction && direction == -1)  { positive = true; isVerticalTrack = false; }
      if (direction && direction == 1 )  { negative = true; isVerticalTrack = false; }
    }
    
    if ( positive && negative ) continue;
    // cannot have a track that goes in both direction
    
    /*
    TH1F * histXZ = new TH1F("fitHistogram","XZ plane",110,0,11);
    histXZ->GetYaxis()->SetRangeUser(-20,52);
    histXZ->SetMarkerColor(kBlue);
    histXZ->SetMarkerStyle(kCircle);
    histXZ->GetXaxis()->SetTitle("Shelf number");
    histXZ->GetYaxis()->SetTitle("Channel number");
    */
    
    TF1 * fitfunc = new TF1("FitTrack","[0]+x*[1]",0,lastFitPoint+1);
    
    TGraphErrors * graphXZ = new TGraphErrors();
    graphXZ->GetXaxis()->SetTitle("Shelf number");
    graphXZ->GetYaxis()->SetTitle("Channel number");
    //graphXZ->SetLineColor(0);
    graphXZ->SetMarkerColor(kBlack);
    graphXZ->SetMarkerStyle(kFullCircle);
    graphXZ->SetName("fit graph");
    graphXZ->SetTitle("XZ plane");
    graphXZ->GetXaxis()->SetTitle("Muon station");
    graphXZ->GetYaxis()->SetTitle("Channel number");
    
    fitfunc->SetLineColor(kBlue);        
    
    vector<double> coordinates;
    double xCoordinate = 0;
    int yCoordinate = 0;
    int zCoorinate = 0;
    
    
    for (int ii=0 ; ii < vectorOfReferenceChambers.size() ; ii++){
      
      coordinates = this->getChamberNumber(vectorOfReferenceChambers[ii])->getXYCoordinatesOfCluster(clusterNum[ii]);
      xCoordinate = coordinates.at(0);
      yCoordinate = coordinates.at(1);
      zCoorinate = 10*vectorOfReferenceChambers[ii];
      Double_t errorValue = this->getChamberNumber(vectorOfReferenceChambers[ii])->getSizeOfCluster(clusterNum[ii]);
//       histXZ->SetBinContent(zCoorinate,xCoordinate);  
//       histXZ->SetBinError(zCoorinate,errorValue/2);
      //cout << xCoordinate << " " << yCoordinate << endl;
      graphXZ->SetPoint(ii,vectorOfReferenceChambers[ii],xCoordinate);
      graphXZ->SetPointError(ii,0,errorValue/2);
    }
    
    Double_t params[2];
    graphXZ->Fit(fitfunc,"RFQ");
    fitfunc->GetParameters(params);
    
    //cout << "par1 " << params[0] << " par2 " << params[1] << " chi2 " << fitfunc->GetChisquare() << endl;
    // The resudials - difference between estimated fit value and the middle of the nearest cluster
    
    int prevReference = 0 , nextReference = 0 , prevReferencePartition = 0 , nextReferencePartition = 0; 
    bool currentChamberIsReference = false;
    int startCounter = 0, endCounter = 0;
    
    if ( abs(graphXZ->GetCorrelationFactor()) >= correlationFactor && abs(graphXZ->GetCorrelationFactor()) > currentBestCorrFact ) {
      // in case of only one partition, get the partition number of the first reference point
      currentBestCorrFact = abs(graphXZ->GetCorrelationFactor());
      
      int referenceChambersIncrementor = 0;
      bool negativeChannelNumberIsFound = false;
      
      // ---------
            
      for ( int currentChNumber = 0 ; currentChNumber < this->getNumberOfChambers() ; currentChNumber++ ) {
	// check where the chamber is according to the reference chambers
	vector<double> vectorOfpartitionsAndHit;
	double channelNum = fitfunc->Eval(currentChNumber+1);

	/** four cases 1. the chamber is before the first reference 2. the chamber is after the last reference 3. the chamber is between two references 4. the chamber is a reference */
	
	for(int refCheck = 0 ; refCheck < vectorOfReferenceChambers.size(); refCheck++){
	  // find the surounding references
	  if (currentChNumber+1 == vectorOfReferenceChambers.at(refCheck)){
	    currentChamberIsReference = true;
	    break;
	  }
	  if ( vectorOfReferenceChambers.at(refCheck) > currentChNumber+1 && refCheck == 0 ){
	    // its before the first reference chamber
	    nextReference = vectorOfReferenceChambers.at(refCheck);
	    nextReferencePartition = this->getChamberNumber(nextReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1);
	    break;
	    
	  }
	  
	  if ( vectorOfReferenceChambers.at(refCheck) < currentChNumber+1 && refCheck == vectorOfReferenceChambers.size() - 1 ){
	    // its after the last chamber
	    prevReference = vectorOfReferenceChambers.at(refCheck);
	    prevReferencePartition = this->getChamberNumber(prevReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1);
	    break;    
	  }
	  if ( vectorOfReferenceChambers.at(refCheck) < currentChNumber+1 && vectorOfReferenceChambers.at(refCheck+1) > currentChNumber+1 ){
	    // its between two references
	    prevReference = vectorOfReferenceChambers.at(refCheck) ;
	    nextReference = vectorOfReferenceChambers.at(refCheck+1);
	    prevReferencePartition = this->getChamberNumber(prevReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1);
	    nextReferencePartition = this->getChamberNumber(nextReference)->getXYCoordinatesOfCluster(clusterNum[refCheck+1]).at(1);
	    break;    
	  }
	}
	
	// end of partition possibilities
	
	if(!currentChamberIsReference){
	  
	  if (nextReference && prevReference == 0){
	    if (positive){
	      prevReferencePartition = 1;      
	    }
	    if(negative){
	      prevReferencePartition = this->getChamberNumber(1)->getClones();      
	    }    
	  }
	  
	  if (prevReferencePartition && nextReferencePartition == 0){
	    if (positive){
	      nextReferencePartition = this->getChamberNumber(1)->getClones();      
	    }
	    if(negative){
	      nextReferencePartition = 1;      
	    }    
	  }
	  
	  if (partitionPenetrated == 1 ){
	    prevReferencePartition = yCoordinate;
	    nextReferencePartition = yCoordinate;    
	    
	    int firstRef = vectorOfReferenceChambers.at(0);
	    int lastRef = vectorOfReferenceChambers.at(vectorOfReferenceChambers.size() - 1);
	    int ccham =  currentChNumber+1;
	    
	    if(! (lastRef > ccham && firstRef < ccham) ){
	      // all partitions are possible, chambers are out of the reference scope
	      prevReferencePartition = this->getChamberNumber(1)->getClones(); 
	      nextReferencePartition = 1; // 3 in case of ecap chamber      
	    }
	  }
	  
	  if (positive){ startCounter = prevReferencePartition; endCounter = nextReferencePartition; }
	  else { startCounter = nextReferencePartition ; endCounter = prevReferencePartition ; }
	  
	  for (int currentCounter = startCounter ; currentCounter <= endCounter; currentCounter ++ ){
	    assert(currentCounter > 0 && currentCounter < 4);
	    vectorOfpartitionsAndHit.push_back(currentCounter);    
	  }
	}
	
	else{
	  vectorOfpartitionsAndHit.push_back(this->getChamberNumber(currentChNumber+1)->getXYCoordinatesOfCluster(clusterNum[referenceChambersIncrementor]).at(1));
	  referenceChambersIncrementor ++;
	}
	
	prevReference = 0 ; nextReference = 0 ; prevReferencePartition = 0 ; nextReferencePartition = 0; currentChamberIsReference = false;
	//cout << "Chamber " << l+1 << " " <<  coordinates.at(1) << " " << fitfunc->Eval(l+1) << " " << endl;
	
	int channelNumberToStore = channelNum;
	if (channelNumberToStore < 96/this->getChamberNumber(1)->getClones()){
	  channelNumberToStore += 1;
	} // add one to represent the fired channel, or none if the channel is on the right border
	
	vectorOfpartitionsAndHit.push_back(channelNumberToStore); // the last element is the number of the channel
	
	// Debug lines
	/**
	cout << "Chamber is " << currentChNumber+1 << " partitions " ;
	for (int thesize = 0 ; thesize < vectorOfpartitionsAndHit.size() - 1; thesize++){
	  cout << vectorOfpartitionsAndHit.at(thesize) << " " ;
	}
	
	cout << "channel " << vectorOfpartitionsAndHit.at(vectorOfpartitionsAndHit.size()-1) << endl;
	*/
	
	mapOfHits[currentChNumber+1] = vectorOfpartitionsAndHit;
	
      }      
      
      // ---------- scintilators coordinates estimate
      
      for (int scintNum = 0 ; scintNum < 31 ; scintNum++){
	if(this->getTriggerObjectNumber(1)->getChannel(scintNum+1)->hasHit() && vectorOfClusterNumberCombinations.size() == 1 ) {
	  if (scintNum < 10) { scintilatorsCoordinates[scintNum+1] = graphXZ->Eval(0); topScintToString = boost::lexical_cast<string>(scintNum+1); }
	  else { scintilatorsCoordinates[scintNum+1] = graphXZ->Eval(lastFitPoint+1); botScintToString = boost::lexical_cast<string>(scintNum+1); }
	}
      }      
    }
    
    // get only vertical tracks from the A partition if there are only two scint hits
    if (keepRecoTrack && isVerticalTrack && !mapOfHits.empty() && scintilatorsCoordinates.size() == 2){
      
      graphXZ->SetName(boost::lexical_cast<string>(eventNum).c_str());
      string partition;
      if (mapOfHits.find(vectorOfReferenceChambers.at(0))->second.at(0) == 1) partition = "A";
      else if (mapOfHits.find(vectorOfReferenceChambers.at(0))->second.at(0) == 2) partition = "B";
      else partition = "C";
      
      graphXZ->SetTitle(("Correlation factor is "+boost::lexical_cast<string>(graphXZ->GetCorrelationFactor()) + " trigger channels top: " + topScintToString + " bottom: " + botScintToString ).c_str());
      if(abs(graphXZ->GetCorrelationFactor()) >= correlationFactor) {
	
	string scintCombination="_"+topScintToString+"_"+botScintToString+"_"+partition;
	TDirectory * dir = fileForRecoTracks->GetDirectory(scintCombination.c_str(),true);
	
	if(!dir) {  
	  //fileForRecoTracks->ls();
	  fileForRecoTracks->mkdir(scintCombination.c_str()) ;
	  fileForRecoTracks->cd("");
	} 
	
	fileForRecoTracks->cd(scintCombination.c_str());
	//cout << fileForRecoTracks->GetPath() << endl;
      }
      else{ fileForRecoTracks->cd("") ; fileForRecoTracks->cd("badTracks") ; }
      
      graphXZ->Write(graphXZ->GetName(),TObject::kOverwrite);
      fileForRecoTracks->cd("");
      //fileForRecoTracks->Write(graphXZ->GetName(),TObject::kOverwrite);
    }
    
    fitfunc->Delete();
    //histXZ->Delete();
    graphXZ->Delete();
    
  }  
  
  return mapOfHits;
}
void AnalyzeClipping(TString inputWaveName = "sum trigger input ch5 960mV",
TString outputWaveName = "sum trigger output ch5 - 2V clip - 960mV input", 
Double_t inputDelay = 1.1E-8, Double_t lowerCut = 16E-9, Double_t upperCut = 23E-9,
const char *inFile = "Data.root",const char *WaveformsFile = "Waveforms.root") {
	
	//try to access data file and in case of failure return
	if(gSystem->AccessPathName(inFile,kFileExists)) {
		cout << "Error: file " << inFile << " does not exsist. Run .x DataParse.C to create it" << endl;
		return;
	}

	TFile *f = TFile::Open(inFile);
	TFolder *dataSet;
	
	TString dataFolderS = "SumTriggerBoardData";
	dataFolderS.Append(";1");

	dataSet = (TFolder*)f->Get(dataFolderS);
	
	cout << dataSet << endl;

	cout << dataSet->GetName() << endl;
	
	Int_t nScope = 150; // number of measurements done by the scope evey time
	
	//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;
	}
	
	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");

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

		listOfGraphs->Add(gWave);
	}
	
	// Global variables
	
	Double_t *xInput, *xOutput, *yInput, *yOutput;
	
	// V input 960 mV
	
	TString path = "Clipping/Output width analysis/Channel 5/V input 960mV/";
	
	TGraphErrors *gClip960mV = TBGraphErrors(dataSet,path,"V clip","Output FWHM",1,nScope);
	
	gClip960mV->SetMarkerStyle(20);
	gClip960mV->SetMarkerSize(0.8);
	gClip960mV->GetXaxis()->SetTitle("V clipping (mV)");
	gClip960mV->GetYaxis()->SetTitle("Output FWHM (ns)");
	
	TCanvas *cClip960mV = new TCanvas("cClip960mV","Output FWHM in function of V clipping",800,600);
	gClip960mV->Draw("APEL");
	
	// Expected output FWHM
	
	TGraphErrors *gInput960mV = listOfGraphs->FindObject("sum trigger input ch5 960mV graph");
	
	Double_t *xClip = gClip960mV->GetX();
	Int_t nClip = gClip960mV->GetN();
	cout << "nClip = " << nClip << endl;
	Long64_t graphPoints = gInput960mV->GetN();
	yInput = gInput960mV->GetY();
	xInput = gInput960mV->GetX();
	
	vector<double> xFirst(nClip);
	vector<double> xLast(nClip);
	Double_t half;
	
	Int_t flag = 0;
	
	vector<double> yConv(graphPoints);
	for(Int_t i = 0; i < graphPoints; i++) {
		yConv[i] = -(yInput[i]);
		yConv[i] *= 1000;
		if(xInput[i] + inputDelay < lowerCut || xInput[i] + inputDelay > upperCut) 
			yConv[i] = 0;
	}
	
	Double_t yInput960mVMax = TMath::MaxElement(graphPoints,&yConv[0]);
	
	for(Int_t i = 0; i < nClip; i++) {
		if(xClip[i] > yInput960mVMax) half = yInput960mVMax;
		else half = xClip[i];
		
		half /=2;
		cout << half << endl;
		
		flag = 0;
		
		for(Int_t j = 0; j < graphPoints - 3; j++) {
			if((yConv[j + 1] - half)*(yConv[j] - half) < 0 && flag == 0) {
				xFirst[i] = xInput[j];
				flag = 1;
				cout << "found first point! " << xFirst[i] << endl;
				continue;
			}
			if((yConv[j + 1] - half)*(yConv[j] - half) < 0 && flag == 1) {
				xLast[i] = xInput[j];
				cout << "found last point! " << xLast[i] << endl;
				break;
			}
		}
	}
	
	vector<double> expectedFWHM960mV(nClip);
	for(Int_t i = 0; i < expectedFWHM960mV.size(); i++) {
		expectedFWHM960mV[i] = xLast[i] - xFirst[i];
		// convert from seconds to nanoseconds
		expectedFWHM960mV[i] *= 10E8;
		cout << "expectedFWHM960mV[" << i << "] = " << expectedFWHM960mV[i] << endl;
	}
	
	// expected FWHM 960 mV graph
	
	TGraphErrors *gExpClip960mV = new TGraphErrors(nClip,xClip,&expectedFWHM960mV[0],0,0);
	gExpClip960mV->SetLineStyle(7);
	gExpClip960mV->SetMarkerStyle(20);
	gExpClip960mV->SetMarkerSize(0.8);
	
	// V input 1.9 V
	
	path = "Clipping/Output width analysis/Channel 5/V input 1.9V/";
	
	TGraphErrors *gClip1Point9V = TBGraphErrors(dataSet,path,"V clip","Output FWHM",1,nScope);
	
	gClip1Point9V->SetMarkerStyle(20);
	gClip1Point9V->SetMarkerSize(0.8);
	gClip1Point9V->SetLineColor(kRed);
	gClip1Point9V->GetXaxis()->SetTitle("V clipping (mV)");
	gClip1Point9V->GetYaxis()->SetTitle("Output FWHM (ns)");
	TCanvas *cClip1Point9V = new TCanvas("cClip1Point9V","Output FWHM in function of V clipping",800,600);
	gClip1Point9V->Draw("APEL");
	
	// Expected output FWHM
	
	TGraphErrors *gInput1Point9V = listOfGraphs->FindObject("sum trigger input ch5 1900mV graph");
	
	xClip = gClip1Point9V->GetX();
	nClip = gClip1Point9V->GetN();
	cout << "nClip = " << nClip << endl;
	graphPoints = gInput1Point9V->GetN();
	yInput = gInput1Point9V->GetY();
	xInput = gInput1Point9V->GetX();
	
	vector<double> xFirst(nClip);
	vector<double> xLast(nClip);
	
	flag = 0;
	
	vector<double> yConv(graphPoints);
	for(Int_t i = 0; i < graphPoints; i++) {
		yConv[i] = -(yInput[i]);
		yConv[i] *= 1000;
		if(xInput[i] + inputDelay < lowerCut || xInput[i] + inputDelay > upperCut) yConv[i] = 0;
	}
	
	Double_t yInput1Point9VMax = TMath::MaxElement(graphPoints,&yConv[0]);
	
	for(Int_t i = 0; i < nClip; i++) {
		if(xClip[i] > yInput1Point9VMax) half = yInput1Point9VMax;
		else half = xClip[i];
		
		half /= 2;
		cout << half << endl;
		
		flag = 0;
		
		for(Int_t j = 0; j < graphPoints - 3; j++) {
			if((yConv[j + 1] - half)*(yConv[j] - half) < 0 && flag == 0) {
				xFirst[i] = xInput[j];
				flag = 1;
				cout << "found first point! " << xFirst[i] << endl;
				continue;
			}
			if((yConv[j + 1] - half)*(yConv[j] - half) < 0 && flag == 1) {
				xLast[i] = xInput[j];
				cout << "found last point! " << xLast[i] << endl;
				break;
			}
		}
	}
	
	vector<double> expectedFWHM1Point9V(nClip);
	for(Int_t i = 0; i < expectedFWHM1Point9V.size(); i++) {
		expectedFWHM1Point9V[i] = xLast[i] - xFirst[i];
		// convert from seconds to nanoseconds
		expectedFWHM1Point9V[i] *= 10E8;
		cout << "expectedFWHM1Point9V[" << i << "] = " << expectedFWHM1Point9V[i] << endl;
	}
	
	// expected FWHM 960 mV graph
	
	TGraphErrors *gExpClip1Point9V = new TGraphErrors(nClip,xClip,&expectedFWHM1Point9V[0],0,0);
	gExpClip1Point9V->SetLineStyle(7);
	gExpClip1Point9V->SetLineColor(kRed);
	gExpClip1Point9V->SetMarkerStyle(20);
	gExpClip1Point9V->SetMarkerSize(0.8);
	
	// Collection of Output FWHM graphs, 2 amplitudes, serveral V clipping
	
	TMultiGraph *mgClipOutputFWHM = new TMultiGraph();
	mgClipOutputFWHM->SetTitle("Collection of Output FWHM graphs, 2 amplitudes, serveral V clipping");
	
	mgClipOutputFWHM->Add(gClip1Point9V);
	mgClipOutputFWHM->Add(gClip960mV);
	mgClipOutputFWHM->Add(gExpClip960mV);
	mgClipOutputFWHM->Add(gExpClip1Point9V);
	
	
	TCanvas *cmgClipOutputFWHM = new TCanvas("cmgClipOutputFWHM","Collection of Output FWHM graphs, 2 amplitudes, serveral V clipping");
	mgClipOutputFWHM->Draw("APEL");
	
	cmgClipOutputFWHM->Modified();
	mgClipOutputFWHM->GetXaxis()->SetTitle("V clipping (mV)");
	mgClipOutputFWHM->GetYaxis()->SetTitle("Output FWHM (ns)");
	cmgClipOutputFWHM->Update();
		
	legend = new TLegend(0.6,0.67,0.89,0.86,"V input");
	legend->AddEntry(gClip1Point9V, "1.9 V", "lp");
	legend->AddEntry(gClip960mV, "960 mV", "lp");
	legend->AddEntry(gExpClip960mV, "Exp 960 mV", "lp");
	legend->AddEntry(gExpClip1Point9V, "Exp 1.9 V", "lp");
	legend->SetTextSize(0.04);
	legend->SetMargin(0.5);
	legend->Draw();
	
	// Hysteresis plot: V output (t) in function of V input (t) for several clipping values
	
	// variables used in the analysis
	
	Long64_t iInputMax, iOutputMax;
	Float_t xInputMax, xOutputMax, xInputHalf, xOutputHalf;
	Double_t InputMax, OutputMax, InputHalf, OutputHalf;
	
	Long64_t firstIndex = 0;
	Long64_t lastIndex = 0;
	Long64_t inputGraphPoints = 0;
	Long64_t outputGraphPoints = 0;
	
	// hard coded values to cut the x axis of both waves
	// Input wave
	
	inputWaveName += " graph";
	
	TGraphErrors *gInput = listOfGraphs->FindObject(inputWaveName);
	gInput->SetLineColor(kRed);
	gInput->SetLineWidth(2);
	
	xInput = gInput->GetX();
	yInput = gInput->GetY();
	inputGraphPoints = gInput->GetN();
	
	cout << inputGraphPoints << endl;
	
	// Invert the input wave
	
	for(Int_t i = 0; i < inputGraphPoints; i++) {
		yInput[i] = -(yInput[i]);
	}
	
	// find the x at which the graph reaches the max value
	
	iInputMax = TMath::LocMax(inputGraphPoints, yInput);
	xInputMax = xInput[iInputMax];
	cout << "iInputMax = " << iInputMax << endl;
	cout << "xInputMax = " << xInputMax << endl;
	InputMax = gInput->Eval(xInput[iInputMax]);
	cout << "InputMax = " << InputMax << endl;
	
	// Output wave
	
	outputWaveName += " graph";
	
	TGraphErrors *gOutput = listOfGraphs->FindObject(outputWaveName);
	gOutput->SetLineWidth(2);
	
	xOutput = gOutput->GetX();
	yOutput = gOutput->GetY();
	outputGraphPoints = gOutput->GetN();
	
	// find the x at which the graph reaches the max value
	
	iOutputMax = TMath::LocMax(outputGraphPoints, yOutput);
	xOutputMax = xOutput[iOutputMax];
	cout << "iOutputMax = " << iOutputMax << endl;
	cout << "xOutputMax = " << xOutputMax << endl;
	OutputMax = gOutput->Eval(xOutput[iOutputMax]);
	cout << "OutputMax = " << OutputMax << endl;
	
	// compute x delay between max points
	
	Double_t delay = xOutputMax - xInputMax;
	cout << "delay = " << delay << endl;
	
	// Shift the x axis of the input graph and create a new graph with only a portion of the first graph
	
	for(Int_t i = 0; i < inputGraphPoints; i++) {
		xInput[i] += inputDelay;
		
		if(xInput[i] >= lowerCut) {
			if(firstIndex == 0) firstIndex = i;
		}

		if(xInput[i] <= upperCut)
			lastIndex = i;
	}
	
	cout << "firstIndex = " << firstIndex << endl;
	cout << "lastIndex = " << lastIndex << endl;
	cout << "xInput[firstIndex] = " << xInput[firstIndex] << endl;
	cout << lastIndex - firstIndex << endl;
	
	Long64_t input2GraphPoints = lastIndex - firstIndex;
	
	TGraphErrors *gInput2 = new TGraphErrors(input2GraphPoints);
	gInput2->SetTitle(inputWaveName);
	
	for(Int_t i = firstIndex; i <= lastIndex; i++) {
		gInput2->SetPoint(i - firstIndex,xInput[i],yInput[i]);
	}
	
	TCanvas *cgInput2 = new TCanvas("cgInput2", "cgInput2", 1200,800);
	gInput2->Draw("AL");
	
	// create a new graph with only a portion of the first graph
	
	firstIndex = 0;
	lastIndex = 0;
	
	for(Int_t i = 0; i < outputGraphPoints; i++) {
		if(xOutput[i] >= lowerCut) {
			if(firstIndex == 0) firstIndex = i;
		}

		if(xOutput[i] <= upperCut)
			lastIndex = i;
	}
	
	cout << "firstIndex = " << firstIndex << endl;
	cout << "lastIndex = " << lastIndex << endl;
	cout << "xOutput[firstIndex] = " << xOutput[firstIndex] << endl;
	cout << lastIndex - firstIndex << endl;
	
	Long64_t output2GraphPoints = lastIndex - firstIndex;
	
	TGraphErrors *gOutput2 = new TGraphErrors(output2GraphPoints);
	gOutput2->SetTitle(outputWaveName);
	
	for(Int_t i = firstIndex; i <= lastIndex; i++) {
		gOutput2->SetPoint(i - firstIndex,xOutput[i],yOutput[i]);
	}
	
	TCanvas *cgOutput2 = new TCanvas("cgOutput2", "cgOutput2", 1200,800);
	gOutput2->Draw("AL");
	
	// first hysteresis plot
	
	Double_t step;
	
	Double_t *xInput2;
	xInput2 = gInput2->GetX();
	
	cout << "xInput2[input2GraphPoints - 1] = " << xInput2[input2GraphPoints - 1] << endl;
	cout << "xInput2[0] = " << xInput2[0] << endl;
	
	step = (xInput2[input2GraphPoints - 1] - xInput2[0])/output2GraphPoints;
	
	cout << "step = " << step << endl;
	
	// in case gInput2 and gOutput2 contain a different number of points create the hysteresis plot with gOutput2 points
	// and modify the yInput2 to match the number of points of yOutput2
	
	vector<double> yInput2;
	
	for(Int_t i = 0; i < output2GraphPoints; i++) {
		yInput2.push_back(gInput2->Eval(xInput2[0] + i*step));
	}
	
	Double_t *yOutput2;
	yOutput2 = gOutput2->GetY();
	
	TGraphErrors *gHyst = new TGraphErrors(output2GraphPoints, &yInput2.at(0),yOutput2);
	gHyst->SetTitle("Hysteresis plot");
	
	gHyst->GetXaxis()->SetTitle("Vin(t) [mV]");
	gHyst->GetYaxis()->SetTitle("Vout(t) [mV]");
	gHyst->GetYaxis()->SetTitleOffset(1.4);
	
	TCanvas *cgHyst = new TCanvas("cgHyst", "cgHyst", 1200,800);
	cgHyst->SetLeftMargin(0.12);
	gHyst->Draw("AL");
	
	// collection of graphs
	
	TMultiGraph *mgInputOutput = new TMultiGraph();
	mgInputOutput->Add(gInput);
	mgInputOutput->Add(gOutput);
	mgInputOutput->SetTitle("Input and output");
	
	TCanvas *cmgInputOutput = new TCanvas("cmgInputOutput", "Input and output", 1200,800);
	mgInputOutput->Draw("AL");
	cmgInputOutput->Update();
	legend = new TLegend(0.65,0.68,0.86,0.86);
	legend->AddEntry(gInput, "Input", "lp");
	legend->AddEntry(gOutput, "Output", "lp");
	legend->SetMargin(0.4);
	legend->SetTextSize(0.04);
	legend->Draw();
	cmgInputOutput->Modified();

	
}
示例#4
0
void disceff(TString filename) {
	gROOT->SetStyle("Plain");
	
	TString cmssw;
	// 167
	
	cmssw = "$3.1.0_pre9$";
		
	TFile *f = TFile::Open(filename);

	std::vector< TString > taggers;
	taggers.push_back( "TC2" );
	taggers.push_back( "TC3" );
	taggers.push_back( "TP" );
	taggers.push_back( "BTP" );
	taggers.push_back( "SSV" );
	taggers.push_back( "CSV" );
	taggers.push_back( "MSV" );
	taggers.push_back( "SMT" );
	taggers.push_back( "SETbyIP3d" );
	taggers.push_back( "SETbyPt" );
	taggers.push_back( "SMTbyIP3d" );
	taggers.push_back( "SMTbyPt" );

	std::vector< TString > discriminators;
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
		discriminators.push_back( "disc"+taggers[itagger]+"_udsg" );
	}
//	discriminators.push_back( "discTC3_udsg" );
//	discriminators.push_back( "discTP_udsg" );

	const int dim=taggers.size();
        TCanvas *cv[dim];
	TMultiGraph* mg[dim];
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
		TString tag = "g"+taggers[itagger]+"_udsg";
		TString tagb = "g"+taggers[itagger]+"_b";
		TString tagc = "g"+taggers[itagger]+"_c";
		cv[itagger] = new TCanvas("cv_"+taggers[itagger],"cv_"+taggers[itagger],700,700);
		TLegend *legend0 = new TLegend(0.68,0.70,0.88,0.90);

		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tag);
		TGraphErrors *bgraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tagb);
		TGraphErrors *cgraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tagc);

		TGraph *dgraph = (TGraph*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+discriminators[itagger]);
		TGraph *bvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),bgraph->GetY());
		TGraph *cvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),cgraph->GetY());
		TGraph *lvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),agraph->GetY());
		TGraph *udsgvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),dgraph->GetX());
		dgraph->Sort();
//		udsgvsdgraph->Sort();
//		udsgvsdgraph->SetLineColor(1);
//              legend0 -> AddEntry(udsgvsdgraph,"control","l");
		lvsdgraph->Sort();
		lvsdgraph->SetLineColor(2);
                legend0 -> AddEntry(lvsdgraph,tag,"l");
		cvsdgraph->Sort();
		cvsdgraph->SetLineColor(3);
                legend0 -> AddEntry(cvsdgraph,tagc,"l");
		bvsdgraph->Sort();
		bvsdgraph->SetLineColor(4);
                legend0 -> AddEntry(bvsdgraph,tagb,"l");
		mg[itagger]= new TMultiGraph();
//		mg[itagger]->Add(udsgvsdgraph);
		mg[itagger]->Add(lvsdgraph);
		mg[itagger]->Add(cvsdgraph);
		mg[itagger]->Add(bvsdgraph);
//		mg[itagger]->Add(dgraph);

		cv[itagger]->cd(1);
		mg[itagger]->Draw("ALP");
		mg[itagger]->GetYaxis()->SetTitle("eff");
		mg[itagger]->GetXaxis()->SetTitle("discriminant");
		legend0 -> Draw();
		cv[itagger]->Update();
	        cv[itagger]->cd(0);
		cv[itagger]-> Print ("BTagPATeff_vs_disc"+taggers[itagger]+".eps");
		cv[itagger]-> Print ("BTagPATeff_vs_disc"+taggers[itagger]+".ps");

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		g->SetLineColor(itagger+1);

		std::cout << " Tagger: " << tag << std::endl;
		std::cout << " Loose(10%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.1) << " b-eff = " << g->Eval(0.1) << std::endl;
		std::cout << " Medium(1%):  " << " cut > " << std::setprecision(4) << dgraph->Eval(0.01) << " b-eff = " << g->Eval(0.01) << std::endl;
		std::cout << " Tight(0.1%) = " << " cut > " << std::setprecision(4) << dgraph->Eval(0.001) << " b-eff = " << g->Eval(0.001) << std::endl;

	}//end for
 
	
}
void make1DLimit(TString combine_dir,TString type= "WH",bool blind=true){
  //TString combine_dir = "test_runSusyHgg/signalInj_sms_ChiWH_0_175/";
  //WH
  wh_limits.push_back(wh_125);
  wh_limits.push_back(wh_150);
  wh_limits.push_back(wh_175);
  wh_limits.push_back(wh_200);
  //HH
  hh_limits.push_back(hh_125);
  hh_limits.push_back(hh_150);
  hh_limits.push_back(hh_175);
  hh_limits.push_back(hh_200);

  TGraph obser( (200-125)/25 );
  TGraph graph( (200-125)/25 );
  TGraphAsymmErrors error( (200-125)/25 );
  TGraphAsymmErrors error2S( (200-125)/25 );

  TGraph obser_r( (200-125)/25 );
  TGraph graph_r( (200-125)/25 );
  TGraphAsymmErrors error_r( (200-125)/25 );
  TGraphAsymmErrors error_r2S( (200-125)/25 );
  
  TGraphErrors* theo = 0;
  if(type=="WH") theo = getTheoXSec("xsecs/CharginoNeutralino.txt");
  else theo = getTheoXSec("xsecs/Higgsino_ElectroHiggs.txt");
  //else theo = getTheoXSec("/home/amott/HggApp/SusyHgg/xsecs/Higgsino.txt");

  for(int m=125;m<=200;m+=25) {
    int i=(m-125)/25;
    TFile limit_file(Form("%s/higgsCombineChi%s_0_%d.Asymptotic.mH120.root",combine_dir.Data(),type.Data(),m) );
    TTree *limit_tree = (TTree*)limit_file.Get("limit");
    TTreeFormula limit_form("get_limit","limit",limit_tree);
    
    float down_2s = -1;
    float down = -1;
    float exp = -1;
    float up = -1;
    float up_2s = -1;
    float obs = -1;

    if( type == "WH" )
      {
	down_2s = wh_limits.at(i)[0];
	down = wh_limits.at(i)[1];
	exp = wh_limits.at(i)[2];
	up = wh_limits.at(i)[3];
	up_2s = wh_limits.at(i)[4];
	obs = wh_limits.at(i)[5];
      }
    else if ( type == "HH")
      {
	down_2s = hh_limits.at(i)[0];
	down = hh_limits.at(i)[1];
	exp = hh_limits.at(i)[2];
	up = hh_limits.at(i)[3];
	up_2s = hh_limits.at(i)[4];
	obs = hh_limits.at(i)[5];
      }
    else
      {
	std::cerr << "UNRECOGNIZED OPTION!!! QUITTING" << std::endl;
      }
    
    if(i==0) m+=5; //first point is actually at m=130
    graph.SetPoint(i,float(m), exp);
    error.SetPoint(i,float(m), exp);
    error2S.SetPoint(i, float(m), exp);
    error.SetPointError(i, 0, 0, exp-down, up-exp);
    error2S.SetPointError(i, 0 , 0 , exp-down_2s, up_2s-exp);
  
    graph_r.SetPoint(i,float(m),exp/theo->Eval(m));
    error_r.SetPoint(i,float(m),exp/theo->Eval(m));
    error_r2S.SetPoint(i,float(m),exp/theo->Eval(m));
    error_r.SetPointError(i,0,0,(exp-down)/theo->Eval(m),(up-exp)/theo->Eval(m));
    error_r2S.SetPointError(i, 0, 0, (exp-down_2s)/theo->Eval(m), (up_2s-exp)/theo->Eval(m) );
    
  
    obser.SetPoint(i,float(m),obs);
    obser_r.SetPoint(i,float(m),obs/theo->Eval(m));
    if(i==0) m-=5;
  }


    TCanvas cv;
    cv.SetLogy();
    cv.SetGrid(1,1);
    theo->SetMaximum(1e2);
    theo->SetMinimum(1e-2);
    theo->GetYaxis()->SetLabelSize(0.05);
    theo->GetYaxis()->SetTitleSize(0.06);
    theo->GetYaxis()->SetTitleOffset(0.8);
    theo->GetYaxis()->SetTitle("95% CL #sigma upper limit (pb)");
    theo->GetXaxis()->SetTitle("m_{chargino} (GeV)");
    if(type=="HH") theo->GetXaxis()->SetTitle("m_{neutralino} (GeV)");
    theo->SetFillColor(kBlue);
    theo->SetLineStyle(kDotted);
    theo->SetLineWidth(2);
    
    error.SetMaximum(1e2);
    error.SetMinimum(1e-2);
    error.GetYaxis()->SetLabelSize(0.04);
    error.GetYaxis()->SetTitleSize(0.06);
    error.GetYaxis()->SetTitleOffset(0.8);
    error.GetXaxis()->SetLabelSize(0.04);
    error.GetXaxis()->SetTitleSize(0.05);
    error.GetXaxis()->SetTitleOffset(0.9);
    error.GetYaxis()->SetTitle("95% CL #sigma upper limit (pb)");
    error.GetXaxis()->SetTitle("m_{chargino} (GeV)");
    if(type=="HH") error.GetXaxis()->SetTitle("m_{neutralino} (GeV)");
    error.SetFillColor(kGreen);
    error2S.SetFillColor(kYellow);
    error2S.SetTitle("");
    error.SetTitle("");
    error.Draw("A3");
    error2S.Draw("3SAME");
    error.Draw("3");
    
    theo->SetTitle("");
    theo->Draw("3C");

    graph.SetLineStyle(kDashed);
    graph.SetLineWidth(2.0);
    graph.SetTitle("");
    graph.Draw("C");

    obser.SetLineStyle(1);
    obser.SetLineWidth(2.0);
    obser.SetTitle("");
    if(!blind) obser.Draw("C");

    TLegend leg(0.65,0.65,0.89,0.89);
    leg.SetFillColor(0);
    leg.SetBorderSize(0);
    leg.AddEntry(&graph,"expected","l");
    leg.AddEntry(&error,"expected #pm1#sigma","F");
    leg.AddEntry(&error2S,"expected #pm2#sigma","F");
    leg.AddEntry(theo,"theoretical","f");
    if(!blind)     leg.AddEntry(&obser,"observed","l");

    leg.Draw("SAME");

    TLatex latex;
    latex.SetNDC();
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);    
    float extraTextSize = extraOverCmsTextSize*cmsSize;
    latex.SetTextFont(lumifont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(cmsSize);    
    latex.DrawLatex(lumix, lumiy,lumiText);
    
    latex.SetTextFont(cmsTextFont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(cmsSize);
    latex.DrawLatex(cmsx, cmsy, CMSText);
    
    latex.SetTextFont(extraTextFont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(extraTextSize);
    latex.DrawLatex(extrax, extray, extraText);

    TString infix=(blind ? "" : "_OBS");
    cv.SaveAs(combine_dir+"/expected_exclusion_"+type+"_1D"+infix+"_v2.png");
    cv.SaveAs(combine_dir+"/expected_exclusion_"+type+"_1D"+infix+"_v2.pdf");
    cv.SaveAs(combine_dir+"/expected_exclusion_"+type+"_1D"+infix+"_v2.C");

    error_r.SetMaximum(1e2);
    error_r.SetMinimum(1e-2);

    error_r.SetTitle("");
    error_r.GetYaxis()->SetLabelSize(0.04);
    error_r.GetYaxis()->SetTitleSize(0.06);
    error_r.GetYaxis()->SetTitleOffset(0.8);
    error_r.GetXaxis()->SetLabelSize(0.04);
    error_r.GetXaxis()->SetTitleSize(0.05);
    error_r.GetXaxis()->SetTitleOffset(0.9);
    error_r.GetYaxis()->SetTitle("#sigma_{95%}/#sigma_{NLO}");
    if(type=="HH") error_r.GetXaxis()->SetTitle("m_{neutralino} (GeV)");
    else error_r.GetXaxis()->SetTitle("m_{chargino} (GeV)");
    error_r.SetFillColor(kGreen);
    error_r2S.SetFillColor(kYellow);
    error_r2S.SetTitle("");
    error_r.Draw("A3");
    error_r2S.Draw("3SAME");
    error_r.Draw("3SAME");

    graph_r.SetLineStyle(kDashed);
    graph_r.SetLineWidth(2);
    graph_r.SetTitle("");
    graph_r.Draw("C");

    TLine l(125,1,205,1);
    l.SetLineWidth(3);
    l.SetLineColor(kBlue);
    //l.Draw("SAME");

    obser_r.SetLineWidth(2);
    if(!blind) obser_r.Draw("C");
    leg.Draw("SAME");

    //lbl.SetY(0.20);
    //leg.SetY1NDC(0.28);
    //leg.SetY2NDC(0.43);

    //prelim.Draw();
    //lbl.Draw();
    latex.SetTextFont(lumifont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(cmsSize);    
    latex.DrawLatex(lumix, lumiy,lumiText);
    
    latex.SetTextFont(cmsTextFont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(cmsSize);
    latex.DrawLatex(cmsx, cmsy, CMSText);
    
    latex.SetTextFont(extraTextFont);
    latex.SetTextAlign(31); 
    latex.SetTextSize(extraTextSize);
    latex.DrawLatex(extrax, extray, extraText);
    
    cv.SaveAs(combine_dir+"/expected_exclusion_ratio_"+type+"_1D"+infix+"_v2.png");
    cv.SaveAs(combine_dir+"/expected_exclusion_ratio_"+type+"_1D"+infix+"_v2.pdf");
    cv.SaveAs(combine_dir+"/expected_exclusion_ratio_"+type+"_1D"+infix+"_v2.C");
}
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();


}
示例#7
0
void points(TString filename) {

	
	TString cmssw;
	// 167
	
	cmssw = "$1.6.7$";
	
	TFile *f = TFile::Open(filename);

	std::vector< TString > taggers;
	taggers.push_back( "gTC2_udsg" );
	taggers.push_back( "gTC3_udsg" );
	taggers.push_back( "gTP_udsg" );
	taggers.push_back( "gJBP_udsg" );
 	taggers.push_back( "gSSV_udsg" );
 	taggers.push_back( "gCSV_udsg" );

	std::vector< TString > discriminators;
	discriminators.push_back( "discTC2_udsg" );
	discriminators.push_back( "discTC3_udsg" );
	discriminators.push_back( "discTP_udsg" );
	discriminators.push_back( "discJBP_udsg" );
 	discriminators.push_back( "discSSV_udsg" );
 	discriminators.push_back( "discCSV_udsg" );

	//TCanvas *cv_TC = new TCanvas("cv_TC","cv_TC",700,700);
	//TCanvas *cv_TP = new TCanvas("cv_TP","cv_TP",700,700);

	std::cout << "Tagger & Point & Discriminator & light mistag & b-efficiency \\\\ \\hline" << std::endl;
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {

		TString tag = taggers[itagger];
		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("Histograms/MCtruth/"+tag);

		//if (taggers == "gTC2_udsg" || taggers =
		
		TGraph *dgraph = (TGraph*) gDirectory->Get("Histograms/MCtruth/"+discriminators[itagger]);
		dgraph->Sort();

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		
		//cv[itagger] = new TCanvas("cv","cv",600,600);
		//g->Draw("ACP");
		TString se = " & ";
		
		
		std::cout << tag << se << "Loose" << se << std::setprecision(3) << dgraph->Eval(0.1) << se << "0.1" << se << std::setprecision(2) << g->Eval(0.1) << "\\\\" << std::endl;
		std::cout << tag << se << "Medium" << se << std::setprecision(3) << dgraph->Eval(0.01) << se << "0.01" << se << std::setprecision(2) << g->Eval(0.01) << "\\\\" << std::endl;
		std::cout << tag << se << "Tight" << se << std::setprecision(3) << dgraph->Eval(0.001) << se << "0.001" << se << std::setprecision(2) << g->Eval(0.001) << "\\\\ \\hline" << std::endl;
		
	}

	
}