void ECALEndcapCorrectionFactorCalculator()
{
    std::string detectorModel("90");
    std::string recoVar("71");

    TString rootFilesToCompare("/r04/lc/sg568/HCAL_Optimisation_Studies/Calibration/Detector_Model_" + detectorModel + "/Reco_Stage_" + recoVar + "/MuonCalibration/RootFiles/*Photon*.root");
    std::string resultsFileName("ECALEndcapCorrectionFactorCalculator_DetectorModel" + detectorModel + "_RecoStage" + recoVar + ".txt");

    std::ofstream resultsFile;
    resultsFile.open (resultsFileName.c_str());

    float ecalTotalCaloHitEnergy(-1.f);
    std::vector<float> *pPfoTargetCosTheta(NULL);

    TChain *pTChain = new TChain("PfoAnalysisTree");
    pTChain->Add(rootFilesToCompare);
    pTChain->SetBranchAddress("ECalTotalCaloHitEnergy",&ecalTotalCaloHitEnergy);
    pTChain->SetBranchAddress("pfoTargetCosTheta",&pPfoTargetCosTheta);

    TCanvas *pTCanvas = new TCanvas("PhotonDistPic", "PhotonDistPic");
    TH2F *pPhotonDist = new TH2F("PhotonDist","PhotonDist",100,0,1,150,0,15);
    pPhotonDist->GetXaxis()->SetTitle("abs( cos (#theta_{#gamma}) )");
    pPhotonDist->GetYaxis()->SetTitle("ECal Calo Hit Energy [GeV]");

    for (int entry = 0; entry < pTChain->GetEntries(); entry++)
    {
//        std::cout << "Reading entry " << entry << std::endl;
        pTChain->GetEvent(entry);

        if (!pPfoTargetCosTheta->empty())
        {
//            std::cout << "Target cos theta : " << pPfoTargetCosTheta.at(0) << std::endl;
            pPhotonDist->Fill(TMath::Abs(pPfoTargetCosTheta->at(0)),ecalTotalCaloHitEnergy);
        }
    }

    TF1 *barrelFit = new TF1("BarrelFit","[0]",0.1,0.7);
    barrelFit->SetLineColor(kGray);
    barrelFit->SetLineWidth(4);

    TF1 *endcapFit = new TF1("EndcapFit","[0]",0.85,0.95);
    endcapFit->SetLineColor(kGray);
    endcapFit->SetLineWidth(4);

    pTCanvas->cd();
    pPhotonDist->Draw("COLZ");

    pPhotonDist->Fit(barrelFit,"QR+");
    pPhotonDist->Fit(endcapFit,"QR+");

    resultsFile << "For the barrel the best fit is : " << barrelFit->GetParameter(0) << std::endl;
    resultsFile << "For the endcap the best fit is : " << endcapFit->GetParameter(0) << std::endl;
    resultsFile << "ECALEndcapCorrectionFactorCalculator -> " << (barrelFit->GetParameter(0))/(endcapFit->GetParameter(0)) << std::endl;
    resultsFile.close();

    TString picName = "ECALEndcapCorrectionFactorCalculator_DetectorModel" + detectorModel + "_RecoStage" + recoVar + ".pdf";
    pTCanvas->SaveAs(picName);   
}
示例#2
0
void gauss2D()
{
  TH2F * h = new TH2F("h", "h", 41, -20.5, 20.5, 41, -20.5, 20.5);

  /*
  for (int i=0;i<50000;++i) {
    h->Fill(gRandom->Gaus(-1.5, 2.0), gRandom->Gaus(2.0, 4.0));
  }
  */
  double x, y, r;
  for (int i=0;i<100000;++i) {
    x = gRandom->Uniform(-5, 5);
    y = gRandom->Uniform(-5, 5);
    r = TMath::Sqrt(x*x+y*y);
    if (r>5) continue;
    h->Fill(x, y);
  }

  h->Draw("lego2");

  TF2 *f2 = new TF2("f2", func_, -20.5, 20.5, -20.5, 20.5, 5);
  f2->SetParameter(0, 1000);
  f2->SetParameter(1, 0);
  f2->SetParameter(2, 1);
  f2->SetParameter(3, 0);
  f2->SetParameter(4, 1);

  h->Fit(f2);

  //f2->Draw("surf");
  /*
  std::ofstream ofile("gauss2Ddump.txt");

  for (int bx=1;bx<=41;++bx) {
    for (int by=1;by<=41;++by) {
      ofile << h->GetXaxis()->GetBinCenter(bx) << "\t"
            << h->GetXaxis()->GetBinCenter(bx) << "\t"
            << h->GetBinContent(bx, by) << std::endl;
    }
  }
  */
}
示例#3
0
void RPCChambersCluster::variousStudyExperimentalFunction(TFile * fileToSave,TH1F * histo[10],const int & eventNum){
  
  // Save file is used to save all the reconstructed graphs with tracks in order to inspect them
  
  RPCChamber * currentChamberObj;
  RPCChamber * triggerObj;
  RPCLinkBoardChannel * currentChannelObj;
  int numberOfChambers = this->getNumberOfChambers();
  triggerObj = this->getTriggerObjectNumber(1);
  TGraphErrors * graphToFit;
  //currentChamberObj = this->getChamberNumber(1);
  int numberOfReferenceChambers = 0; // change this value for the three cases - CERN, Ghent and BARC
  vector<int> tempCluster;
  
  TH1F * hist1,* hist2,* hist3,* hist4, * numberOfClustersHisto, * topMinusEachChamberAvg, * bottomMinusEachChamberAvg,*clsSize ,
  * numberOfClustersInSamePartitions, * histClustersPartitionDistr, * SingleMultiHits;
  
  hist1 = histo[0];
  hist2 = histo[1];
  hist3 = histo[2];
  hist4 = histo[3];
  numberOfClustersHisto = histo[4];
  topMinusEachChamberAvg = histo[5];
  bottomMinusEachChamberAvg = histo[6];
  clsSize = histo[7];
  histClustersPartitionDistr = histo[8];
  SingleMultiHits = histo[9];
  
  int timeReference = 0;
  int timeWindow = 0;
  int firstScintilatorTime = 0 ;
  int secondScintilatorTime = 0;
  int difference_reference = 0;
  int coincidence_time = 0 ;
  if (triggerObj->getChannel(32)->hasHit()){
    coincidence_time = triggerObj->getChannel(32)->getHits().at(0);
  }
  
  ESiteFileType siteType = kIsCERNrawFile; // later make the method to take file type argument and to use it in here
  
  //TH1F * firstTriggerEntries  = new TH1F("ScintStats1","ScintStats1",0,500,500);
  //firstTriggerEntries->SetLineColor(kBlue);
  //firstTriggerEntries->SetFillColor(kBlue);
  
  switch (siteType) 
  {
    case kIsCERNrawFile:
      
      timeWindow = 500;
      
      numberOfReferenceChambers = 3;
      
      int countTwoHits=0;
      for (int i = 0 ; i < 13 ; i++){
	if(triggerObj->getChannel(i+1)->hasHit() ){
	  
	  if ( difference_reference == 0 || ( coincidence_time - triggerObj->getChannel(i+1)->getHits().at(0) ) < difference_reference ) {
	    
	    difference_reference = coincidence_time - triggerObj->getChannel(i+1)->getHits().at(0);
	    firstScintilatorTime = triggerObj->getChannel(i+1)->getHits().at(0);
	    
	  }
	}
      }
      
      difference_reference = 0;
      
      for (int i = 13 ; i < 31 ; i++) {
	if(triggerObj->getChannel(i+1)->hasHit() ){
	  
	  if ( difference_reference == 0 || ( coincidence_time - triggerObj->getChannel(i+1)->getHits().at(0) ) < difference_reference ) {
	    
	    difference_reference = coincidence_time - triggerObj->getChannel(i+1)->getHits().at(0);
	    secondScintilatorTime = triggerObj->getChannel(i+1)->getHits().at(0);
	    
	  }
	}
      }
      
      //timeReference = timeReference/2;
      /*
    case kIsGENTrawFile:
      timeWindow = 20;
      for(int i = 0 ; i < 32 ; i++){
	if(triggerObj->getChannel(i+1)->hasHit()) {
	  triggerObj->getChannel(i+1)->getHits().at(0);
	}
	break;
      }
    case kIsBARCrawFile:
      timeWindow = 0; 
      timeReference = 0;
      */
      
  }
  
  timeReference = (firstScintilatorTime+secondScintilatorTime)/2;
  
  //cout << " time reference : " << timeReference << endl;
  //cout << " trigger entries : ";
  for (int i=0; i < 32 ; i++){
    if (triggerObj->getChannel(i+1)->hasHit()){
//       cout << " trig channel : " << i+1 << " " << triggerObj->getChannel(i+1)->getHits().at(0) << " ";
    }
  }
  
  cout << endl;
//   cout << " most close trigger entries : top " << firstScintilatorTime << " bottom : " << secondScintilatorTime;
//   cout << endl;
  
  
  hist1->Fill(abs(firstScintilatorTime-secondScintilatorTime));
  hist2->Fill(coincidence_time - firstScintilatorTime);
  hist3->Fill(coincidence_time - secondScintilatorTime);
  
//   cout << "difference : " << firstScintilatorTime-secondScintilatorTime << endl;
  
  for (int totalChambers = 0 ; totalChambers < numberOfChambers ; totalChambers++){
    
    currentChamberObj = this->getChamberNumber(totalChambers+1);
     cout << "Chamber " << totalChambers+1 ;
    for (int j=0 ; j < 96 ;j++){
      
      currentChamberObj = this->getChamberNumber(totalChambers+1);
      currentChannelObj = currentChamberObj->getChannel(j+1);      
      if (currentChannelObj->hasHit()){
 	cout << " channel " << currentChannelObj->getOnlineNumber() << " time " << currentChannelObj->getHits().at(0);
      }
    }
     cout << endl;
    currentChamberObj->findAllClustersForTriggerTimeReferenceAndTimeWindow(timeReference,timeWindow);    
    // now check the clusterization methods
    // fill number of cluster when there is at least one
    if(currentChamberObj->getNumberOfClusters()){
      numberOfClustersHisto->Fill(currentChamberObj->getNumberOfClusters());
    }
  }
  
  cout << "-------------------" << endl;
//   cout << "Check new cluster methods" << endl;
  
  
  for (int totalChambers = 0 ; totalChambers < numberOfChambers ; totalChambers++){
    
    currentChamberObj = this->getChamberNumber(totalChambers+1);
//     cout << "Chamber " << totalChambers+1 ;
    for (int i = 0 ; i < currentChamberObj->getNumberOfClusters() ; i++){
      
      // make the difference to get the tolerance within one cluster 
      
      int smallestTime = 0;
      int biggestTime = 0;
      int currentValue = 0;
      int sizeOfCurrentCluster = currentChamberObj->getClusterNumber(i+1).size();
      tempCluster = currentChamberObj->getClusterNumber(i+1);
      int numberOfHits = 0 ;
      for (int j = 0 ; j < sizeOfCurrentCluster; j++){
	// Fill the size here
	SingleMultiHits->Fill(currentChamberObj->getStrip(tempCluster.at(j))->getHits().size());
	
      }
      
      clsSize->Fill(sizeOfCurrentCluster);
      
      for (int j = 0 ; j < sizeOfCurrentCluster ; j++ ){
	
	currentValue = currentChamberObj->getStripsHitsTimesForCluster(i+1).at(j);
	
	if ( j == 0 ) {
	  // init the values
	  smallestTime = currentChamberObj->getStripsHitsTimesForCluster(i+1).at(j);
	  biggestTime = currentChamberObj->getStripsHitsTimesForCluster(i+1).at(j);
	}
	else{
	  
	  if ( smallestTime >= currentValue ){
	    smallestTime = currentValue;
	  }
	  if( biggestTime <= currentValue){
	    biggestTime = currentValue;
	  } 
	}
      }
      
      if (biggestTime - smallestTime != 0){
	hist4->Fill(biggestTime-smallestTime);
      }
      int avgTimeForCluster = currentChamberObj->getAverageTimeForCluster(i+1);
      topMinusEachChamberAvg->Fill(abs(firstScintilatorTime - avgTimeForCluster));
      bottomMinusEachChamberAvg->Fill(abs(secondScintilatorTime - avgTimeForCluster));
      
//       cout << endl << "Cluster " << i+1 << " toptime " << biggestTime << " leasttime " << smallestTime ;
      
    }
    
//     cout << endl;
  }
  
//   cout << "-------Second check done-----------" << endl;
  
  // try with single cluster per chamber 
  
  vector<int> vectorOfReferenceChambers;
  
  for (int i=0; i < this->getNumberOfChambers() ; i ++){
    currentChamberObj = this->getChamberNumber(i+1);
    if (currentChamberObj->isReferenceChamber() && !currentChamberObj->getNumberOfClusters()){
      // the reference chamber does not have a hit (cluster), probably inefficient (or else) , skip the execution
      
      break;
    }
  }
  
  // remove the following when the configuration object is introduced // done, change the implementation
  vectorOfReferenceChambers.push_back(1); vectorOfReferenceChambers.push_back(4); vectorOfReferenceChambers.push_back(6);
  
  /** Determination of track starts here */ // Move this part in separated method 
  
  //TFile * goodTracks = new TFile("GoodTracks.root","UPDATE");
  //TFile * badTracks = new TFile("BadTracks.root","UPDATE");
  int globalCount = 1;
  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[2])->getNumberOfClusters() ; k++ ){
	
	// check the multiplicity. use 5 as upper limit number
	// with the test run 2202 - CERN channel 33 is noisy so there is a condition only for it here TO DO - remove the channel 33 condition // old function
	
	/** Hits : first , use the time to distinguish useless crap - like noisy channels 
	 *  
	 * 2. Check the partition plane (YZ plane) for vertical tracks. If the track is vertical don't search for consecutiveness and don't fill the YZ histo
	 * 3. Check the partitions plane for consecutiveness - one could not expect track that passes 3 -> 1 -> 3 partitions
	 * 
	*/ 
	
	if(this->getChamberNumber(vectorOfReferenceChambers[0])->getSizeOfCluster(i+1) > 5 ||
	  this->getChamberNumber(vectorOfReferenceChambers[1])->getSizeOfCluster(j+1) > 5 ||
	  this->getChamberNumber(vectorOfReferenceChambers[2])->getSizeOfCluster(k+1) > 5
	  ) continue;
	
	// 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 
	int RefChamberClusterPartition[3] ;
	int currentDifference = 0;
	bool positive = false;
	bool negative = false;
	int partitionPenetrated = 1;
	// the Y coordinate is the partition number ( 1 2 or 3 - A B or C)
	
	RefChamberClusterPartition[0] = this->getChamberNumber(vectorOfReferenceChambers[0])->getXYCoordinatesOfCluster(i+1).at(1);
	RefChamberClusterPartition[1] = this->getChamberNumber(vectorOfReferenceChambers[1])->getXYCoordinatesOfCluster(j+1).at(1);
	RefChamberClusterPartition[2] = this->getChamberNumber(vectorOfReferenceChambers[2])->getXYCoordinatesOfCluster(k+1).at(1);
	
	for ( int ii = 0; ii < 2 ; ii++ ){
	  direction = (RefChamberClusterPartition[ii] - RefChamberClusterPartition[ii+1]);
	  if (direction != 0) { 
	    direction = direction/abs(direction); 
	    partitionPenetrated++;
	  } // get only the sign ( +1 or -1)
	  if (direction && direction == -1)  positive = true;
	  if (direction && direction == 1 )  negative = true;
	  
	}
	
	// cannot have a track that goes in both direction
	// partition logic end here
	stringstream ss;
	ss << globalCount;
	string histoCounter = ss.str();
	
	
	TH2F * histXZ = new TH2F(histoCounter.c_str(),"XZ plane",110,0,110,68,0,34);
	
	
	histXZ->SetMarkerColor(kBlue);
	histXZ->SetMarkerStyle(kOpenTriangleDown); //  - open triangle down not found on noise server ? 
	
	double * xc = new double[3];
	double * yc = new double[3];
	double * zc = new double[3];
	
	vector<double> coordinates ;
	double xCoordinate = 0;
	int yCoordinate = 0;
	int zCoorinate = 0;
	
	coordinates = this->getChamberNumber(1)->getXYCoordinatesOfCluster(i+1);
	xCoordinate = coordinates.at(0);
	yCoordinate = coordinates.at(1);
	zCoorinate = 10*vectorOfReferenceChambers[0];
	
	int prevPartition = yCoordinate;
	xc[0] = xCoordinate;
	yc[0] = yCoordinate;
	zc[0] = 1*10;
	
	histXZ->Fill(zc[0],xCoordinate);
	cout << xCoordinate << " " << yCoordinate << endl;
	
	coordinates = this->getChamberNumber(4)->getXYCoordinatesOfCluster(j+1);
	xCoordinate = coordinates.at(0);
	yCoordinate = coordinates.at(1);
	
	xc[1] = xCoordinate;
	yc[1] = yCoordinate;
	zc[1] = 4*10;
	
	histXZ->Fill(zc[1],xCoordinate);
	prevPartition = yCoordinate;
	
	cout << xCoordinate << " " << yCoordinate << endl;	
	coordinates = this->getChamberNumber(6)->getXYCoordinatesOfCluster(k+1);
	xCoordinate = coordinates.at(0);
	yCoordinate = coordinates.at(1);
	
	xc[2] = xCoordinate;
	yc[2] = yCoordinate;
	zc[2] = 6*10;
	
	histXZ->Fill(zc[2],xCoordinate);
	cout << xCoordinate << " " << yCoordinate << endl;
	
	if ( positive && negative ) continue;
	
	TF1 * fitfunc = new TF1("FitTrack","[0]+x*[1]",0,100);
	Double_t * params = new Double_t[2];
	histXZ->Fit(fitfunc);
	fitfunc->GetParameters(params);
	cout << "par1 " << params[0] << " par2 " << params[1] << " chi2 " << fitfunc->GetChisquare() << endl;
	double channelToSearchHitIn ;
	
	for (int jj = 0 ; jj < this->getNumberOfChambers() ; jj++){
	  if (jj+1 != vectorOfReferenceChambers[0] || jj+1 != vectorOfReferenceChambers[1] || jj+1 != vectorOfReferenceChambers[1])
	    // add additional rule that the chamber should exist in the calibration object 
	  {
	    
	    channelToSearchHitIn = fitfunc->Eval((jj+1)*10);
	    cout << "Evaluated for chamber number " << jj+1 << " value : " << channelToSearchHitIn << endl;
	    
	  }
	  
	}
	// now here - what to return, and how to get the hits in the chambers under test from the function
	
	
	
	if (fitfunc->GetChisquare() > 20) continue; // cut the execution 
	if(fitfunc->GetChisquare() < 20){
	  //goodTracks->Write(trackHistoName.c_str());
	  histClustersPartitionDistr->Fill(partitionPenetrated);
	  //histXZ->SaveAs((trackHistoName+".root").c_str());  
	  // here search for hits in the chambers under test  
	  
	}
	
	/*
	else{
	  badTracks->Write(trackHistoName.c_str());
	}	
	*/
	
	//trackHistoName+=".root";
	//histXZ->SaveAs(trackHistoName.c_str());
	
	histXZ->Delete();
	
      }
    }
  }
//   badTracks->Close("R");
//   badTracks->Delete();
//   goodTracks->Close("R");
//   goodTracks->Delete();

}