void mk_sigaccanplots(string flavor = "112", bool tdrstyle = false) { setTDRStyle(tdrstyle); // gStyle->SetOptFit(1100); // chi2 and prob, not parameters gStyle->SetOptFit(0); // chi2 and prob, not parameters // gStyle->SetOptStat("irme"); // integral, RMS, mean, # of entries gStyle->SetStatFontSize(0.005); gStyle->SetStatY(0.4); float unused = 0.9, simtxt_y = 0.97; if (tdrstyle == false) { simtxt_y = 0.93; } TLatex *tex = new TLatex(unused, simtxt_y, "CMS simulation at #sqrt{s} = 8 TeV"); tex->SetNDC(); tex->SetTextAlign(12); // Left-adjusted tex->SetTextFont(42); float textsiz = 0.06; tex->SetTextSize(0.05); tex->SetLineWidth(2); // for(int k=0; k<3; k++){ // for(int k=0; k<2; k++){ for(int k=2; k<3; k++){ //Which plots to make //define input variables vector <TFile* > filelist_kin; // string uncert="btagup"; // if(k==1) uncert="btagdown"; string uncert="up"; if(k==1) uncert="down"; if(k==2) uncert=""; // filelist_kin.push_back(TFile::Open(("Acc_Gluino_NoLumi_pt110_8TeVxsec_BtagMap_2500GeV"+uncert+".root").c_str())); // filelist_kin.push_back(TFile::Open("Acc_Gluino_NoLumi_pt60_pt110_8TeVxsec_BtagMap.root")); // filelist_kin.push_back(TFile::Open(("Acc_RPV112" + uncert + ".root").c_str())); filelist_kin.push_back(TFile::Open(("Acc_RPV" + flavor + uncert + "_Sph4.root").c_str())); // filelist_kin.push_back(TFile::Open(("Acc_Gluino_NoLumi_pt60_pt110_8TeVxsec_BtagMap" + uncert + ".root").c_str())); TFile f1(("RPV_" + flavor + "_accandwdithtest"+uncert+".root").c_str(), "recreate"); f1.cd(); string nameIN; string cuts; string prefix; string postfix; string folder; string ptcut; folder="plots_paper/"; postfix=".pdf"; /////////////Plots for each Mass separatly////////////// /////////////----------------------------------------///////////// for (int p = 0; p < 2; p++) { // ptcut="112"; // if(p==1) ptcut="" + flavor; ptcut="60"; if (p==1) { ptcut="110"; textsiz = 0.045; } // string histname = string("GausWidth_vs_Mass_112") + ptcut; string histname = string("GausWidth_vs_Mass_" + flavor) + "_" + ptcut; cout<< histname << endl; TGraphErrors *h_GluinoHist_Fit = (TGraphErrors*) filelist_kin[0]->Get(histname.c_str())->Clone(); histname = string("GausAcceptance_vs_Mass_" + flavor) + "_" + ptcut; // histname = string("GausAcceptance_vs_Mass_112") + ptcut; cout<< histname << endl; TGraphErrors *h_GluinoHist_MCcomb = (TGraphErrors*) filelist_kin[0]->Get(histname.c_str())->Clone(); // histname = string("FullAcceptance_vs_Mass_" + flavor) + "_" + ptcut; histname = string("GausMean_vs_Mass_" + flavor) + "_" + ptcut; // histname = string("GausAcceptance_vs_Mass_112") + ptcut; cout<< histname << endl; // TGraphErrors *h_FullAccept = (TGraphErrors*) filelist_kin[0]->Get(histname.c_str())->Clone(); TGraph *h_FullAccept = (TGraph*) filelist_kin[0]->Get(histname.c_str())->Clone(); histname = string("GausMeanOffset_vs_Mass_" + flavor) + "_" + ptcut; cout<< histname << endl; TGraph *h_MeanOffset = (TGraph*) filelist_kin[0]->Get(histname.c_str())->Clone(); TCanvas * cGluinoFitsOpti = new TCanvas(("RPV_"+flavor +ptcut).c_str(), ("RPV_" + ptcut+"_"+cuts).c_str(), 800, 600); //h_GluinoHist_Fit->SetFillColor(kOrange-2); // h_GluinoHist_Fit->SetLineColor(kBlack); string title; string systematic = "pile-up"; // title="Gaussian Width vs. Mass for Light-ptcut RPV"; string tag = "qqb", sphericity = " Sphericity #geq 0.4"; if (flavor.compare("112") == 0) tag = "qqq"; else if (ptcut.compare("60") == 0) sphericity = ""; string titlepart = "Hadronic RPV #tilde{g} #rightarrow " + tag; string titleln2 = "\\Delta = 110 GeV"; string titleln3 = "6^{th}-jet p_{T} #geq " + ptcut + " GeV"; title = titlepart; // title = "Width for " + titlepart; /* if(k==0){ title="RPV gluino #bf{" + systematic + " up} m="+to_string(masses[i])+", ptcut = "+ptcut+", #Delta = 110 GeV, #bf{6^{th} Jet p_{T} = 60 GeV}"; if (i>=5 || p==0) title="RPV gluino #bf{" + systematic + " up} m="+to_string(masses[i])+", ptcut = "+ptcut+", #Delta = 110 GeV, #bf{6^{th} Jet p_{T} = 110 GeV}"; } if(k==1){ title="RPV gluino #bf{" + systematic + " down} m="+to_string(masses[i])+", ptcut = "+ptcut+", #Delta = 110 GeV, #bf{6^{th} Jet p_{T} = 60 GeV}"; if (i>=5 || p==0) title="RPV gluino #bf{" + systematic + " down} m="+to_string(masses[i])+", ptcut = "+ptcut+", #Delta = 110 GeV, #bf{6^{th} Jet p_{T} = 110 GeV}"; } if(k==2){ title="RPV gluino m="+to_string(masses[i])+", ptcut = "+ptcut+", #Delta = 110 GeV, #bf{6^{th} Jet p_{T} = 60 GeV}"; if (i>=5 || p==0) title="RPV gluino m="+to_string(masses[i])+", ptcut = "+ptcut+", #Delta = 110 GeV, #bf{6^{th} Jet p_{T} = 110 GeV}"; } */ h_GluinoHist_Fit->SetTitle(title.c_str()); float titpos = 0.2, titly = 0.89, headpos = 0.64; if (tdrstyle == false) { titpos -= 0.05; titly -= 0.05; headpos = 0.45; } TLatex *tex2 = new TLatex(titpos, titly, title.c_str()); tex2->SetNDC(); tex2->SetTextAlign(12); // Left-adjusted tex2->SetTextFont(42); tex2->SetTextSize(textsiz); tex2->SetLineWidth(2); TLatex *tex3 = new TLatex(titpos, titly - 0.07, titleln2.c_str()); tex3->SetNDC(); tex3->SetTextAlign(12); tex3->SetTextFont(42); tex3->SetTextSize(textsiz); tex3->SetLineWidth(2); TLatex *tex3a = new TLatex(titpos, titly - 0.14, titleln3.c_str()); tex3a->SetNDC(); tex3a->SetTextAlign(12); tex3a->SetTextFont(42); tex3a->SetTextSize(textsiz); tex3a->SetLineWidth(2); TLatex *tex4 = NULL; if (sphericity.size() > 0) { tex4 = new TLatex(titpos - 0.01, titly - 0.22, sphericity.c_str()); tex4->SetNDC(); tex4->SetTextAlign(12); tex4->SetTextFont(42); tex4->SetTextSize(textsiz); tex4->SetLineWidth(2); } float legx = 0.65; if (tdrstyle == false) { legx = 0.56; } TLegend *leg = new TLegend(legx, 0.2, legx + 0.3, 0.4); leg->SetBorderSize(1); leg->SetTextFont(62); leg->SetLineColor(kBlack); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(1001); //leg->SetHeader(); // leg->AddEntry(h_GluinoHist_Fit, "#splitline{Acceptance as function}{of gluino mass}","l"); h_GluinoHist_Fit->SetMarkerStyle(1); h_GluinoHist_Fit->SetMarkerColor(kWhite); // h_GluinoHist_Fit->SetMarkerColor(kGreen + 3); h_GluinoHist_Fit->SetMarkerSize(0.004); // h_GluinoHist_Fit->SetTitleSize(0.01); TF1 *fitfunc = h_GluinoHist_Fit->GetFunction("GausWidth"); string fitnamew = "fitcopy" + ptcut; TF1* fitfunccopy = (TF1 *) fitfunc->Clone(fitnamew.c_str()); if (fitfunc == NULL) cout << "Can't get fit func\n"; else { fitfunc->Delete(); fitfunccopy->SetLineWidth(3); fitfunccopy->SetLineColor(kGreen + 3); // fitfunc->SetLineStyle(3); // Dotted } float labsiz = 0.055; h_GluinoHist_Fit->GetXaxis()->SetLabelFont(62); h_GluinoHist_Fit->GetXaxis()->SetTitleFont(62); h_GluinoHist_Fit->GetYaxis()->SetLabelFont(62); h_GluinoHist_Fit->GetYaxis()->SetTitleFont(62); h_GluinoHist_Fit->GetYaxis()->SetTitle("Gaussian width [GeV]"); float offset = 0.8; if (tdrstyle == false) { h_GluinoHist_Fit->GetXaxis()->SetTitleOffset(offset); h_GluinoHist_Fit->GetYaxis()->SetTitleOffset(offset); } h_GluinoHist_Fit->GetXaxis()->SetTitle("Gluino mass [GeV]"); h_GluinoHist_Fit->GetXaxis()->SetTitleSize(labsiz); h_GluinoHist_Fit->GetYaxis()->SetTitleSize(labsiz); if (tdrstyle == false) { float axsize = 0.04; h_GluinoHist_Fit->GetXaxis()->SetLabelSize(axsize); h_GluinoHist_Fit->GetYaxis()->SetLabelSize(axsize); } if (flavor.compare("113_223") == 0 && ptcut == "60") h_GluinoHist_Fit->GetYaxis()->SetRangeUser(14.0, 50.0); h_GluinoHist_Fit->Draw("APX"); // X eliminates error bars // h_GluinoHist_Fit->Draw("AP"); // TH1 *fithist = (TH1 *) fitfunccopy->GetHistogram()->Clone(fitnamew.c_str()); TH1 *fithist = (TH1 *) fitfunccopy->GetHistogram()->Clone(); int fillcolor = kGreen + 2; int fillstyle = 3013; if (fithist != NULL) { int numBins = fithist->GetNbinsX(); for (int cnt = 1; cnt <= numBins; ++cnt) { setErr(fithist, cnt, flavor, "width"); } fithist->SetFillColor(fillcolor); fithist->SetFillStyle(fillstyle); fithist->Draw("CE3SAME"); } fitfunccopy->Draw("CSAME"); // h_GluinoHist_Fit->Draw("P"); // Draw points over fit line leg->AddEntry(fitfunccopy, "Gaussian width", "L"); leg->AddEntry(fithist, "Uncertainty", "F"); leg->Draw(); tex->SetX(headpos); tex->Draw(); tex2->Draw(); tex3->Draw(); tex3a->Draw(); if (tex4 != NULL) tex4->Draw(); cGluinoFitsOpti->Write(); cGluinoFitsOpti->SaveAs((folder + "RPVwidth" +flavor + ptcut+uncert+postfix).c_str()); TCanvas * cGluinoFitsOpt2 = new TCanvas(("RPVacc_"+flavor +ptcut).c_str(), ("RPV_" + ptcut+"_"+cuts).c_str(), 800, 600); // title="Acc. x Eff. for " + titlepart; title= titlepart; tex2->SetText(titpos,titly, title.c_str()); TLegend *leg2 = new TLegend(legx, 0.2, legx + 0.3, 0.4); leg2->SetBorderSize(1); leg2->SetTextFont(62); leg2->SetTextSize(0.04); leg2->SetLineColor(kBlack); leg2->SetLineStyle(1); leg2->SetLineWidth(1); leg2->SetFillColor(0); leg2->SetFillStyle(1001); TF1 *fitfuncA = h_GluinoHist_MCcomb->GetFunction("total"); string fitname = "fitcopyA" + ptcut; TF1* fitfunccopyA = (TF1 *) fitfuncA->Clone(fitname.c_str()); if (fitfuncA == NULL) cout << "Can't get fit func\n"; else { fitfuncA->Delete(); fitfunccopyA->SetLineWidth(3); fitfunccopyA->SetLineColor(kGreen + 3); // fitfunc->SetLineStyle(3); // Dotted } h_GluinoHist_MCcomb->SetMarkerStyle(1); // h_GluinoHist_MCcomb->SetMarkerColor(kBlack); h_GluinoHist_MCcomb->SetMarkerColor(kWhite); h_GluinoHist_MCcomb->SetTitle(title.c_str()); h_GluinoHist_MCcomb->GetXaxis()->SetLabelFont(62); h_GluinoHist_MCcomb->GetXaxis()->SetTitleFont(62); h_GluinoHist_MCcomb->GetYaxis()->SetLabelFont(62); // h_GluinoHist_MCcomb->GetYaxis()->SetLabelSize(62); h_GluinoHist_MCcomb->GetYaxis()->SetTitleFont(62); h_GluinoHist_MCcomb->GetYaxis()->SetTitle("Acceptance x Efficiency"); if (tdrstyle == false) { h_GluinoHist_MCcomb->GetXaxis()->SetTitleOffset(offset); h_GluinoHist_MCcomb->GetYaxis()->SetTitleOffset(offset + 0.35); } // h_GluinoHist_MCcomb->GetYaxis()->SetTitleOffset(1.4); h_GluinoHist_MCcomb->GetXaxis()->SetTitle("Gluino mass [GeV]"); h_GluinoHist_MCcomb->GetXaxis()->SetTitleSize(labsiz); if (tdrstyle == false) labsiz -= 0.01; h_GluinoHist_MCcomb->GetYaxis()->SetTitleSize(labsiz); if (tdrstyle == false) { float axsize = 0.035; h_GluinoHist_MCcomb->GetXaxis()->SetLabelSize(axsize); h_GluinoHist_MCcomb->GetYaxis()->SetLabelSize(axsize); } if (flavor.compare("113_223") == 0) { float ylimit = 0.05; if ( ptcut == "110") ylimit = 0.022; // gStyle->SetStatY(0.8); h_GluinoHist_MCcomb->GetYaxis()->SetRangeUser(0.0, ylimit); } // h_GluinoHist_MCcomb->Draw("AL"); h_GluinoHist_MCcomb->Draw("APX"); // fitfunccopyA->Draw("C same"); // TH1 *fithistA = (TH1 *) fitfunccopyA->GetHistogram()->Clone(fitname.c_str()); TH1 *fithistA = (TH1 *) fitfunccopyA->GetHistogram()->Clone(); if (fithistA != NULL) { int numBins = fithistA->GetNbinsX(); for (int cnt = 1; cnt <= numBins; ++cnt) { setErr(fithistA, cnt, flavor, "acceptance"); } fithistA->SetFillColor(fillcolor); fithistA->SetFillStyle(fillstyle); fithistA->Draw("CE3SAME"); } fitfunccopyA->Draw("CSAME"); // h_GluinoHist_MCcomb->Draw("P"); // Draw points over fit line tex->SetX(headpos); tex->Draw(); tex2->Draw(); tex3->Draw(); tex3a->Draw(); leg2->AddEntry(fitfunccopyA, "Acc. x Eff.", "L"); leg2->AddEntry(fithistA, "Uncertainty", "F"); leg2->Draw(); if (tex4 != NULL) tex4->Draw(); cGluinoFitsOpt2->Write(); cGluinoFitsOpt2->SaveAs((folder + "RPVacc" +flavor + ptcut+uncert+postfix).c_str()); /* gStyle->SetStatY(0.4); TCanvas * cGluinoFitsOpt3 = new TCanvas(("RPVfullacc_"+flavor +ptcut).c_str(), ("RPVfull_" + ptcut+"_"+cuts).c_str(), 800, 600); title="Gaussian Mean for " + titlepart; tex2->SetText(titpos, 0.89, title.c_str()); // title="Full Acceptance for " + titlepart; h_FullAccept->SetMarkerStyle(1); // h_FullAccept->SetMarkerColor(kWhite); h_FullAccept->SetLineColor(kRed); h_FullAccept->SetLineWidth(2.0); // h_FullAccept->SetTitle(title.c_str()); // h_FullAccept->GetYaxis()->SetTitle("Acceptance"); h_FullAccept->GetYaxis()->SetTitle("Gaussian Mean [GeV]"); h_FullAccept->GetXaxis()->SetTitleOffset(1.3); h_FullAccept->GetXaxis()->SetTitle("Gluino Mass [GeV]"); h_FullAccept->GetXaxis()->SetTitleSize(labsiz); h_FullAccept->GetYaxis()->SetTitleSize(labsiz); h_FullAccept->GetXaxis()->SetLabelSize(axsize); h_FullAccept->GetYaxis()->SetLabelSize(axsize); h_FullAccept->Draw("AL"); // h_FullAccept->Draw("APX"); // leg->Draw(); // h_GluinoHist_MCcomb->SetFillColor(10); // h_GluinoHist_MCcomb->SetLineColor(kBlack); // h_GluinoHist_MCcomb->Draw("samehist"); // f_GluinoGauss->SetLineColor(kRed); //f_GluinoGauss->Draw("same"); //f_GluinoP4->Draw("same"); tex->SetX(titpos); tex->Draw(); tex2->Draw(); tex3->Draw(); tex3a->Draw(); if (tex4 != NULL) tex4->Draw(); f1.cd(); cGluinoFitsOpt3->Write(); cGluinoFitsOpt3->SaveAs((folder + "RPVmean" +flavor + ptcut+uncert+postfix).c_str()); gStyle->SetStatY(0.4); TCanvas *cMeanOffset = new TCanvas(("RPVMeanOffset_"+flavor +ptcut).c_str(), ("RPVMeanOffset_" + ptcut + "_" + cuts).c_str(), 800, 600); axsize = 0.035; title="Mass Deviation for " + titlepart; titpos = 0.35; tex2->SetText(titpos, 0.89, title.c_str()); h_MeanOffset->SetMarkerStyle(1); h_MeanOffset->SetLineColor(kRed); h_MeanOffset->SetLineWidth(2.0); h_MeanOffset->GetYaxis()->SetTitleOffset(1.3); h_MeanOffset->GetYaxis()->SetTitle("Fractional Mass Deviation"); h_MeanOffset->GetXaxis()->SetTitleOffset(1.3); h_MeanOffset->GetXaxis()->SetTitle("Gluino Mass [GeV]"); h_MeanOffset->GetXaxis()->SetTitleSize(labsiz); h_MeanOffset->GetYaxis()->SetTitleSize(labsiz); h_MeanOffset->GetXaxis()->SetLabelSize(axsize); h_MeanOffset->GetYaxis()->SetLabelSize(axsize); TLine *max = new TLine(0.5, 0.1, 0.5, 0.9); max->SetLineColor(kGreen + 2); max->SetLineWidth(3); h_MeanOffset->Draw("AL"); max->DrawLineNDC(0.16, 0.49, 0.98, 0.49); tex->SetX(titpos); tex->Draw(); tex2->Draw(); tex3->SetX(titpos); tex3->Draw(); tex3a->SetX(titpos); tex3a->Draw(); if (tex4 != NULL) { tex4->SetX(titpos); tex4->Draw(); } f1.cd(); cMeanOffset->Write(); cMeanOffset->SaveAs((folder + "RPVmassdev" +flavor + ptcut+uncert+postfix).c_str()); */ } } }
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 DoTDeriMax1090Correction(TString SpectrumFileInput = "/lustre/miifs05/scratch/him-specf/hyp/steinen/COSYBeamtestAna/COSYnewMogon/June2014/COSYJune2014Dataset11_200,100,0,5339_SR1.root", TString FitFileInput = "/lustre/miifs05/scratch/him-specf/hyp/steinen/COSYBeamtestAna/COSYnewMogon/Fit/FitCOSYJune2014Dataset11_200,100,0,5339_SR1.root") { TH2D *hSpectrumTDeriMax1090_EnergyChannel; TH2D *hSpectrumTDeriMax1090Rel_EnergyChannel; TH2D *hSpectrumT1090_EnergyChannelCorr1; TNtuple *DataNTuple; TFile *SpectrumInput = new TFile(SpectrumFileInput.Data()); hSpectrumTDeriMax1090_EnergyChannel = (TH2D*) SpectrumInput->Get("Histograms/Energy_DeriMaxT90/Energy_DeriMaxT90_01"); hSpectrumTDeriMax1090_EnergyChannel->SetDirectory(0); hSpectrumTDeriMax1090Rel_EnergyChannel = (TH2D*) SpectrumInput->Get("Histograms/Energy_DeriMaxT90Rel/Energy_DeriMaxT90Rel_01"); hSpectrumTDeriMax1090Rel_EnergyChannel->SetDirectory(0); hSpectrumT1090_EnergyChannelCorr1 = (TH2D*) SpectrumInput->Get("Histograms/EnergyRt1090/EnergyRt1090CorrectionRt_01"); hSpectrumT1090_EnergyChannelCorr1->SetDirectory(0); SpectrumInput->Close(); //hSpectrumTDeriMax1090_EnergyChannel->Draw("colz"); TFile *FitInput = new TFile(FitFileInput.Data(),"Update"); DataNTuple = (TNtuple*)FitInput->Get("DataNTuple"); DataNTuple->Scan(); Int_t entries = (Int_t)DataNTuple->GetEntries(); cout<<"Number of Entries: "<<entries<< endl; const int entriesArrayValue =entries; TF1 *FitFunc[entriesArrayValue]; float Energy=0; float ChannelPeakPos=0; float ChannelRangeMin=0; float ChannelRangeMax=0; DataNTuple->SetBranchAddress("Energy",&Energy); DataNTuple->SetBranchAddress("ChannelPeakPos",&ChannelPeakPos); DataNTuple->SetBranchAddress("ChannelRangeMin",&ChannelRangeMin); DataNTuple->SetBranchAddress("ChannelRangeMax",&ChannelRangeMax); TCanvas* can=new TCanvas(); gPad->SetLogz(); hSpectrumTDeriMax1090_EnergyChannel->GetXaxis()->SetRangeUser(-30,250); hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->SetRangeUser(-0.1,0.95); for (Int_t ki=0;ki<entries;ki++) { DataNTuple->GetEntry(ki); //if (int(Energy) == 1332) //if (int(Energy) == 510) //if (ki == entries-1) { cout << ChannelRangeMin << " " << ChannelRangeMax << endl; //first correction via TDeriMaxT90Rel hSpectrumTDeriMax1090_EnergyChannel->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax); hSpectrumTDeriMax1090Rel_EnergyChannel->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax); //TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+pol0(3)",ChannelRangeMin,ChannelRangeMax); //FitFuncSlices->SetParameters(1000,ChannelPeakPos-10,4,10); //FitFuncSlices->SetParLimits(1,ChannelRangeMin,ChannelRangeMax); //FitFuncSlices->SetParLimits(2,0,10); //FitFuncSlices->SetParLimits(3,0,100); //gDirectory->ls(); TH1D *hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually=new TH1D("hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually","",hSpectrumTDeriMax1090Rel_EnergyChannel->GetNbinsX(),-0.3,1.3); //cout <<hSpectrumTDeriMax1090_EnergyChannel_MaxPos->GetEntries()<< endl; for(int binX = hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->FindBin(-0.1);binX <= hSpectrumTDeriMax1090Rel_EnergyChannel->GetXaxis()->FindBin(0.90);binX++) { cout << "binx " << binX << endl; TH1D *hProfileY =hSpectrumTDeriMax1090Rel_EnergyChannel->ProjectionY("_py",binX,binX); double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin()); TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20); TF1* FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",MaxValue-20,MaxValue+20); FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4); hProfileY->Fit(FitFuncGausSlices,"RNQ"); FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10); FitFuncSlices->SetParLimits(0,0,10000); FitFuncSlices->SetParLimits(1,MaxValue-10,MaxValue+10); FitFuncSlices->SetParLimits(2,0,10); FitFuncSlices->SetParLimits(3,0,100); hProfileY->Fit(FitFuncSlices,"RNQ"); cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetParError(1) <<endl; hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinContent(binX, FitFuncSlices->GetParameter(1)); hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1)); } hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->GetYaxis()->SetRangeUser(ChannelPeakPos-100,ChannelPeakPos+50); hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->GetXaxis()->SetRangeUser(-0.05,0.9); TF1 * funcCorrConst = new TF1("funcCorrConst","pol0",-0.03,0.03); funcCorrConst->SetLineColor(kRed); TF1 * funcCorrPol = new TF1("funcCorrPol",PolPiecewise,-0.05,0.9,6); funcCorrPol->SetLineColor(kBlue); funcCorrPol->SetParameter(0,0.04); funcCorrPol->SetParameter(1,ChannelPeakPos); hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->Fit(funcCorrConst,"R"); hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->Fit(funcCorrPol,"R+"); TCanvas* can2=new TCanvas(); gPad->SetLogz(); hSpectrumTDeriMax1090Rel_EnergyChannel->Draw("colz"); funcCorrPol->DrawCopy("same"); for(int i = 7;i>0;i--) funcCorrPol->SetParameter(i,funcCorrPol->GetParameter(i)/funcCorrPol->GetParameter(1)); funcCorrPol->Print(); char buf[20]; sprintf(buf, "funcCorrNorm_%d",ki); funcCorrPol->Write(buf,TObject::kOverwrite); funcCorrConst->Delete(); funcCorrPol->Delete(); //second correction via T1090 (after first) hSpectrumT1090_EnergyChannelCorr1->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax); //TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+pol0(3)",ChannelRangeMin,ChannelRangeMax); //FitFuncSlices->SetParameters(1000,ChannelPeakPos-10,4,10); //FitFuncSlices->SetParLimits(1,ChannelRangeMin,ChannelRangeMax); //FitFuncSlices->SetParLimits(2,0,10); //FitFuncSlices->SetParLimits(3,0,100); //gDirectory->ls(); TH1D *hSpectrumT1090_EnergyChannelCorr1_MaxPosManually=new TH1D("hSpectrumT1090_EnergyChannelCorr1_MaxPosManually","",hSpectrumT1090_EnergyChannelCorr1->GetNbinsX(),0,1000); //cout <<hSpectrumTDeriMax1090_EnergyChannel_MaxPos->GetEntries()<< endl; for(int binX = hSpectrumT1090_EnergyChannelCorr1->GetXaxis()->FindBin(30);binX <= hSpectrumT1090_EnergyChannelCorr1->GetXaxis()->FindBin(500);binX++) { cout << "binx " << binX << endl; TH1D *hProfileY =hSpectrumT1090_EnergyChannelCorr1->ProjectionY("_py",binX,binX); //hProfileY->Draw(); //return 0; double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin()); FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20); FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",MaxValue-20,MaxValue+20); FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4); hProfileY->Fit(FitFuncGausSlices,"RNQ"); FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10); FitFuncSlices->SetParLimits(0,0,10000); FitFuncSlices->SetParLimits(1,MaxValue-10,MaxValue+10); FitFuncSlices->SetParLimits(2,0,10); FitFuncSlices->SetParLimits(3,0,100); hProfileY->Fit(FitFuncSlices,"RNQ"); cout <<MaxValue<<" " << FitFuncSlices->GetParameter(1) << " " << FitFuncSlices->GetParError(1) <<endl; hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->SetBinContent(binX, FitFuncSlices->GetParameter(1)); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1)); } hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->GetYaxis()->SetRangeUser(ChannelPeakPos-100,ChannelPeakPos+50); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->GetXaxis()->SetRangeUser(30,500); new TCanvas(); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->Draw(); TF1 * funcCorrConst = new TF1("funcCorrConst","pol0",50,350); funcCorrConst->SetLineColor(kRed); TF1 * funcCorrPol = new TF1("funcCorrPol","pol6",50,300); funcCorrPol->SetLineColor(kBlue); funcCorrPol->SetParameter(0,0.04); funcCorrPol->SetParameter(1,ChannelPeakPos); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->Fit(funcCorrConst,"R"); hSpectrumT1090_EnergyChannelCorr1_MaxPosManually->Fit(funcCorrPol,"R+"); TCanvas* can2=new TCanvas(); gPad->SetLogz(); hSpectrumT1090_EnergyChannelCorr1->Draw("colz"); funcCorrPol->DrawCopy("same"); for(int i = 7;i>=0;i--) funcCorrPol->SetParameter(i,funcCorrPol->GetParameter(i)/funcCorrConst->GetParameter(0)); funcCorrPol->Print(); char buf[20]; sprintf(buf, "funcCorr2Norm_%d",ki); funcCorrPol->Write(buf,TObject::kOverwrite); funcCorrConst->Delete(); funcCorrPol->Delete(); //return 0; } } //can->ls(); gDirectory->Delete("ncCorrPol;1"); FitInput->ls(); //TCanvas* can3=new TCanvas(); //hSpectrumTDeriMax1090_EnergyChannel->ProfileX()->Draw(); //hSpectrumTDeriMax1090Rel_EnergyChannel->ProfileX()->Draw(); //hSpectrumTDeriMax1090Rel_EnergyChannel->Fit("pol3"); FitInput->Close(); }