void fullPedestalAnalysis(string inputDIR, string outputDIR, string inputCablingMap, string outputFileName){ gROOT->ProcessLine("gErrorIgnoreLevel = 1"); // open the file and prepare the cluster tree, adding the other trees as frined --> memory consuming std::cout<<"##################################"<<std::endl; std::cout<<"###### fullPedestalAnalysis ######"<<std::endl; std::cout<<"##################################"<<std::endl; clock_t tStart = clock(); // prepare style and load macros setTDRStyle(); gROOT->SetBatch(kTRUE); system(("mkdir -p "+outputDIR).c_str()); ifstream file; std::cout<<"### Make input file list"<<std::endl; system(("find "+inputDIR+" -name \"*.root\" > file.temp").c_str()); std::ifstream infile; string line; vector<string> fileList; infile.open("file.temp",ifstream::in); if(infile.is_open()){ while(!infile.eof()){ getline(infile,line); if(line != "" and TString(line).Contains(".root") and line !="\n"){ fileList.push_back(line); } } } system("rm file.temp"); std::sort(fileList.begin(),fileList.end()); TFile* cablingFile = TFile::Open(inputCablingMap.c_str(),"READ"); cablingFile->cd(); TTree* readoutMap = (TTree*) cablingFile->FindObjectAny("readoutMap"); TTreeReader reader(readoutMap); TTreeReaderValue<uint32_t> detid (reader,"detid"); TTreeReaderValue<uint16_t> fecCrate (reader,"fecCrate"); TTreeReaderValue<uint16_t> fecSlot (reader,"fecSlot"); TTreeReaderValue<uint16_t> fecRing (reader,"fecRing"); TTreeReaderValue<uint16_t> ccuAdd (reader,"ccuAdd"); TTreeReaderValue<uint16_t> ccuChan (reader,"ccuChan"); TTreeReaderValue<uint16_t> lldChannel (reader,"lldChannel"); TTreeReaderValue<uint16_t> fedId (reader,"fedId"); TTreeReaderValue<uint16_t> fedCh (reader,"fedCh"); // output tree TFile* ouputTreeFile = new TFile((outputDIR+"/"+outputFileName).c_str(),"RECREATE"); ouputTreeFile->cd(); ouputTreeFile->SetCompressionLevel(0); TTree* outputTree = new TTree("pedestalFullNoise","pedestalFullNoise"); // branches uint32_t detid_,fedKey_; uint16_t fecCrate_,fecSlot_, fecRing_, ccuAdd_, ccuChan_, lldChannel_, fedId_, fedCh_, apvId_, stripId_; float noiseMean_,noiseRMS_, noiseSkewness_, noiseKurtosis_; float fitChi2_, fitChi2Probab_, fitStatus_; float fitGausMean_, fitGausSigma_, fitGausNormalization_; float fitGausMeanError_, fitGausSigmaError_, fitGausNormalizationError_; float noiseIntegral3Sigma_, noiseIntegral3SigmaFromFit_; float noiseIntegral4Sigma_, noiseIntegral4SigmaFromFit_; float noiseIntegral5Sigma_, noiseIntegral5SigmaFromFit_; float kSValue_, kSProbab_, jBValue_, jBProbab_, aDValue_, aDProbab_; vector<float> noiseDistribution_, noiseDistributionError_; float xMin_, xMax_, nBin_ ; outputTree->Branch("detid",&detid_,"detid/i"); outputTree->Branch("fedKey",&fedKey_,"fedKey/i"); outputTree->Branch("fecCrate",&fecCrate_,"fecCrate/s"); outputTree->Branch("fecSlot",&fecSlot_,"fecSlot/s"); outputTree->Branch("fecRing",&fecRing_,"fecRing/s"); outputTree->Branch("ccuAdd",&ccuAdd_,"ccuAdd/s"); outputTree->Branch("ccuChan",&ccuChan_,"ccuChan/s"); outputTree->Branch("lldChannel",&lldChannel_,"lldChannel/s"); outputTree->Branch("fedId",&fedId_,"fedId/s"); outputTree->Branch("fedCh",&fedCh_,"fedCh/s"); outputTree->Branch("apvId",&apvId_,"apvId/s"); outputTree->Branch("stripId",&stripId_,"stripId/s"); outputTree->Branch("noiseMean",&noiseMean_,"noiseMean/F"); outputTree->Branch("noiseRMS",&noiseRMS_,"noiseRMS/F"); outputTree->Branch("noiseSkewness",&noiseSkewness_,"noiseSkewness/F"); outputTree->Branch("noiseKurtosis",&noiseKurtosis_,"noiseKurtosis/F"); outputTree->Branch("fitGausNormalization",&fitGausNormalization_,"fitGausNormalization/F"); outputTree->Branch("fitGausMean",&fitGausMean_,"fitGausMean/F"); outputTree->Branch("fitGausSigma",&fitGausSigma_,"fitGausSigma/F"); outputTree->Branch("fitGausNormalizationError",&fitGausNormalizationError_,"fitGausNormalizationError/F"); outputTree->Branch("fitGausMeanError",&fitGausMeanError_,"fitGausMeanError/F"); outputTree->Branch("fitGausSigmaError",&fitGausSigmaError_,"fitGausSigmaError/F"); outputTree->Branch("fitChi2",&fitChi2_,"fitChi2/F"); outputTree->Branch("fitChi2Probab",&fitChi2Probab_,"fitChi2Probab/F"); outputTree->Branch("fitStatus",&fitStatus_,"fitStatus_F"); outputTree->Branch("noiseIntegral3Sigma",&noiseIntegral3Sigma_,"noiseIntegral3Sigma/F"); outputTree->Branch("noiseIntegral3SigmaFromFit",&noiseIntegral3SigmaFromFit_,"noiseIntegral3SigmaFromFit/F"); outputTree->Branch("noiseIntegral4Sigma",&noiseIntegral4Sigma_,"noiseIntegral4Sigma/F"); outputTree->Branch("noiseIntegral4SigmaFromFit",&noiseIntegral4SigmaFromFit_,"noiseIntegral4SigmaFromFit/F"); outputTree->Branch("noiseIntegral5Sigma",&noiseIntegral4Sigma_,"noiseIntegral5Sigma/F"); outputTree->Branch("noiseIntegral5SigmaFromFit",&noiseIntegral4SigmaFromFit_,"noiseIntegral5SigmaFromFit/F"); outputTree->Branch("kSValue",&kSValue_,"kSValue/F"); outputTree->Branch("jBValue",&jBValue_,"jBValue/F"); outputTree->Branch("aDValue",&aDValue_,"aDValue/F"); outputTree->Branch("kSProbab",&kSProbab_,"kSProbab/F"); outputTree->Branch("jBProbab",&jBProbab_,"jBProbab/F"); outputTree->Branch("aDProbab",&aDProbab_,"aDProbab/F"); outputTree->Branch("xMin",&xMin_,"xMin/F"); outputTree->Branch("xMax",&xMax_,"xMax/F"); outputTree->Branch("nBin",&nBin_,"nBin/F"); bool histoBranches = false; // Loop on the file list to extract each histogram 2D DQM histo with full noise distribution TH1F* histoNoiseStrip = NULL; TF1* fitFunc = NULL; TH1F* randomHisto = NULL; TFitResultPtr result; for(auto file : fileList){ cout<<"input file: "<<file<<endl; TFile* inputFile = TFile::Open(file.c_str(),"READ"); inputFile->cd(); // take into account that the DQM file structure for strips is always the same --> use cabling map to browse the histograms reader.SetEntry(0); TH2* histoNoise = NULL; long int iChannel = 0; int noFitResult = 0; while(reader.Next()){ cout.flush(); if(iChannel %10 == 0) cout<<"\r"<<"iChannel "<<100*double(iChannel)/(readoutMap->GetEntries()/reductionFactor)<<" % "; if(iChannel > double(readoutMap->GetEntries())/reductionFactor) break; iChannel++; TString objName; uint32_t fedKey = SiStripFedKey(*fedId,SiStripFedKey::feUnit(*fedCh),SiStripFedKey::feChan(*fedCh)).key(); std::stringstream stream; stream << std::hex << fedKey; string fedKeyStr = stream.str(); if(fedKeyStr.size() == 4) objName = Form("DQMData/SiStrip/ControlView/FecCrate%d/FecSlot%d/FecRing%d/CcuAddr%d/CcuChan%d/ExpertHisto_PedsFullNoise_FedKey0x0000%s_LldChannel%d_Noise2D",*fecCrate,*fecSlot,*fecRing,*ccuAdd,*ccuChan,fedKeyStr.c_str(),*lldChannel); else if(fedKeyStr.size() == 5) objName = Form("DQMData/SiStrip/ControlView/FecCrate%d/FecSlot%d/FecRing%d/CcuAddr%d/CcuChan%d/ExpertHisto_PedsFullNoise_FedKey0x000%s_LldChannel%d_Noise2D",*fecCrate,*fecSlot,*fecRing,*ccuAdd,*ccuChan,fedKeyStr.c_str(),*lldChannel); else cerr<<"hex number to short "<<fedKeyStr<<" --> please check "<<endl; inputFile->GetObject(objName.Data(),histoNoise); // extract single strip noise histogram --> loop on the y-axis uint16_t apvID = 0; uint16_t stripID = 0; if(histoNoiseStrip == 0 or histoNoiseStrip == NULL){ histoNoiseStrip = new TH1F ("histoNoiseStrip","",histoNoise->GetNbinsX(),histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax()); histoNoiseStrip->Sumw2(); } for(int iBinY = 0; iBinY < histoNoise->GetNbinsY(); iBinY++){ histoNoiseStrip->Reset(); histoNoiseStrip->SetDirectory(0); // two multiplexed APV per line if(iBinY < histoNoise->GetNbinsY()/2) apvID = 1; else apvID = 2; // strip id stripID++; if(stripID > 128) stripID = 1; // loop on x-axis bin for(int iBinX = 0; iBinX < histoNoise->GetNbinsX(); iBinX++){ histoNoiseStrip->SetBinContent(iBinX+1,histoNoise->GetBinContent(iBinX+1,iBinY+1)); histoNoiseStrip->SetBinError(iBinX+1,histoNoise->GetBinError(iBinX+1,iBinY+1)); } // to initialize branches detid_ = 0; fedKey_ = 0; fecCrate_ = 0; fecSlot_ = 0; fecRing_ = 0; ccuAdd_ = 0; ccuChan_ = 0; lldChannel_ = 0; fedId_ = 0; fedCh_ = 0; apvId_ = 0; stripId_ = 0; noiseMean_ = 0.; noiseRMS_ = 0.; noiseSkewness_ = 0.; noiseKurtosis_ = 0.; fitGausMean_ = 0.; fitGausSigma_ = 0.;fitGausNormalization_ = 0.; fitGausMeanError_ = 0.; fitGausSigmaError_ = 0.;fitGausNormalizationError_ = 0.; fitChi2_ = 0.; fitChi2Probab_ = 0.; fitStatus_ = -1.; noiseIntegral3Sigma_ = 0.; noiseIntegral3SigmaFromFit_ = 0.; noiseIntegral4Sigma_ = 0.; noiseIntegral4SigmaFromFit_ = 0.; noiseIntegral5Sigma_ = 0.; noiseIntegral5SigmaFromFit_ = 0.; kSProbab_ = 0.; jBProbab_ = 0.; kSValue_ = 0.; jBValue_ = 0.; aDValue_= 0.; aDProbab_ = 0.; nBin_ = 0.; xMin_ = 0.; xMax_ = 0.; // basic info detid_ = *detid; fedKey_ = fedKey; fecCrate_ = *fecCrate; fecSlot_ = *fecSlot; fecRing_ = *fecRing; ccuAdd_ = *ccuAdd; ccuChan_ = *ccuChan; lldChannel_ = *lldChannel; fedId_ = *fedId; fedCh_ = *fedCh; apvId_ = apvID; stripId_ = stripID; // basic info of nioise distribution noiseMean_ = histoNoiseStrip->GetMean(); noiseRMS_ = histoNoiseStrip->GetRMS(); noiseSkewness_ = histoNoiseStrip->GetSkewness(); noiseKurtosis_ = histoNoiseStrip->GetKurtosis(); float integral = histoNoiseStrip->Integral(); noiseIntegral3Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*3),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*3)))/integral; noiseIntegral4Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*4),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*4)))/integral; noiseIntegral5Sigma_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+noiseRMS_*5),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-noiseRMS_*5)))/integral; // make a gaussian fit if(fitFunc == NULL or fitFunc == 0){ fitFunc = new TF1 ("fitFunc","gaus(0)",histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax()); } fitFunc->SetRange(histoNoise->GetXaxis()->GetXmin(),histoNoise->GetXaxis()->GetXmax()); fitFunc->SetParameters(histoNoiseStrip->Integral(),noiseMean_,noiseRMS_); result = histoNoiseStrip->Fit(fitFunc,"QSR"); if(result.Get()){ fitStatus_ = result->Status(); fitGausNormalization_ = fitFunc->GetParameter(0); fitGausMean_ = fitFunc->GetParameter(1); fitGausSigma_ = fitFunc->GetParameter(2); fitGausNormalizationError_ = fitFunc->GetParError(0); fitGausMeanError_ = fitFunc->GetParError(1); fitGausSigmaError_ = fitFunc->GetParError(2); fitChi2_ = result->Chi2(); fitChi2Probab_ = result->Prob(); noiseIntegral3SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*3),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*3)))/histoNoiseStrip->Integral(); noiseIntegral4SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*4),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*4)))/histoNoiseStrip->Integral(); noiseIntegral5SigmaFromFit_ = (histoNoiseStrip->Integral(histoNoiseStrip->FindBin(noiseMean_+fitGausSigma_*5),histoNoiseStrip->GetNbinsX()+1) + histoNoiseStrip->Integral(0,histoNoiseStrip->FindBin(noiseMean_-fitGausSigma_*5)))/histoNoiseStrip->Integral(); jBValue_ = (histoNoiseStrip->Integral()/6)*(noiseSkewness_*noiseSkewness_+(noiseKurtosis_*noiseKurtosis_)/4); jBProbab_ = ROOT::Math::chisquared_cdf_c(jBValue_,2); if(randomHisto == 0 or randomHisto == NULL) randomHisto = (TH1F*) histoNoiseStrip->Clone("randomHisto"); randomHisto->Reset(); randomHisto->SetDirectory(0); if(integral != 0){ if(generateRandomDistribution){ randomHisto->FillRandom("fitFunc",histoNoiseStrip->Integral()); kSValue_ = histoNoiseStrip->KolmogorovTest(randomHisto,"MN"); kSProbab_ = histoNoiseStrip->KolmogorovTest(randomHisto,"N"); aDValue_ = histoNoiseStrip->AndersonDarlingTest(randomHisto,"T"); aDProbab_ = histoNoiseStrip->AndersonDarlingTest(randomHisto); } else{ randomHisto->Add(fitFunc); kSValue_ = histoNoiseStrip->KolmogorovTest(randomHisto,"MN"); kSProbab_ = histoNoiseStrip->KolmogorovTest(randomHisto,"N"); // AD test ROOT::Fit::BinData data1; ROOT::Fit::BinData data2; ROOT::Fit::FillData(data1,histoNoiseStrip,0); data2.Initialize(randomHisto->GetNbinsX()+1,1); for(int ibin = 0; ibin < randomHisto->GetNbinsX(); ibin++){ if(histoNoiseStrip->GetBinContent(ibin+1) != 0 or randomHisto->GetBinContent(ibin+1) >= 1) data2.Add(randomHisto->GetBinCenter(ibin+1),randomHisto->GetBinContent(ibin+1),randomHisto->GetBinError(ibin+1)); } double probab; double value; ROOT::Math::GoFTest::AndersonDarling2SamplesTest(data1,data2,probab,value); aDValue_ = value; aDProbab_ = probab; } } } else noFitResult++; if(not histoBranches){ noiseDistribution_.clear(); noiseDistributionError_.clear(); outputTree->Branch("noiseDistribution","vector<float>",&noiseDistribution_); outputTree->Branch("noiseDistributionError","vector<float>",&noiseDistributionError_); histoBranches = true; } // set histogram noiseDistribution_.clear(); noiseDistributionError_.clear(); for(int iBin = 0; iBin < histoNoiseStrip->GetNbinsX(); iBin++){ noiseDistribution_.push_back(histoNoiseStrip->GetBinContent(iBin+1)); noiseDistributionError_.push_back(histoNoiseStrip->GetBinError(iBin+1)); } nBin_ = histoNoiseStrip->GetNbinsX(); xMin_ = histoNoise->GetXaxis()->GetBinLowEdge(1); xMax_ = histoNoise->GetXaxis()->GetBinLowEdge(histoNoise->GetNbinsX()+1); // fill all branches for each strip ouputTreeFile->cd(); outputTree->Fill(); } } inputFile->Close(); std::cout<<std::endl; cout<<"No fit results found for "<<100*double(noFitResult)/iChannel<<endl; } outputTree->BuildIndex("detid"); outputTree->Write(outputTree->GetName(),TObject::kOverwrite); ouputTreeFile->Close(); cablingFile->Close(); /* Do your stuff here */ cout<<"Time taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC<<endl; }
//------------------------------------------------------------------- void Alignment_1(int cluster_length_leftCut = 2,int cluster_length_rightCut = 7,float TotSignal_Cut = 5){ gStyle->SetOptStat(11111111); gStyle->SetOptFit(111111111); //gAnaCombine->LinkBranches(); ofstream outputlog("./AMS/AMSAlignment_1.txt",ios::out | ios::app); outputlog<<"\nfile: "<<gRootIOSvc->GetInputFileName()<<".\tCluster length: "<<cluster_length_leftCut<<"~"<<cluster_length_rightCut<<".\tTotal signale cut "<<TotSignal_Cut<<endl; TH1D *h_ladder_stripID[5][2]; TH1D *h_Refer[5][2]; char name[80]; for(short lid =0;lid<5;++lid){ for(short sid=0;sid<2;++sid){ snprintf(name,80,"ladder_%d-side_%d",lid,sid); h_ladder_stripID[lid][sid] = new TH1D(name,name,500,0,1100); snprintf(name,80,"ladder_%d-side_%d VS ladder 0",lid,sid); h_Refer[lid][sid] = new TH1D(name,name,200,-200,200); } snprintf(name,80,"ladder_%d",lid); h_ladder_stripID[lid][0]->SetTitle(name); snprintf(name,80,"Seed Address ladder_%d",lid); h_Refer[lid][0]->SetTitle(name); } TChain *tree = gAnaCombine->GetTree(); long nEvt = tree->GetEntries(); std::vector<Cluster*> clusterIndex[5][2]; for(long ievt=0;ievt<nEvt;++ievt){ tree->GetEntry(ievt); short nCluster = gAnaCombine->fEvtAMS->GetEntriesFast(); for(int iclu=0;iclu<nCluster;++iclu){ Cluster *acluster = (Cluster*)gAnaCombine->fEvtAMS->At(iclu); if(acluster->GetTotSig()>TotSignal_Cut && cluster_length_leftCut<=acluster->length && acluster->length <= cluster_length_rightCut){ int ladder = acluster->ladder; if(ladder==5){ ladder = 2; }else if(ladder == 4){ ladder = 3; }else if(ladder == 3){ ladder = 4; } clusterIndex[ladder][acluster->side].push_back(acluster); } } if(clusterIndex[0][0].size() == 1 && clusterIndex[0][1].size() == 1){ for(short il=0;il<5;++il){ for(short is=0;is<2;++is){ if(clusterIndex[il][is].size() == 1){ h_ladder_stripID[il][is]->Fill(clusterIndex[il][is][0]->GetSeedAdd()); h_Refer[il][is]->Fill(clusterIndex[il][is][0]->GetSeedAdd() - clusterIndex[0][is][0]->GetSeedAdd()); } clusterIndex[il][is].clear(); } } } } snprintf(name,80,"AMS Alignment_1_a: cluster length %d~%d, total signal cut %f",cluster_length_leftCut,cluster_length_rightCut,TotSignal_Cut); TCanvas *c1 = new TCanvas(name,name); c1->Divide(2,3); snprintf(name,80,"AMS Alignment_1_b: cluster length %d~%d, totalt signal cut %f",cluster_length_leftCut,cluster_length_rightCut,TotSignal_Cut); TF1 *gausFit = new TF1("GausFit","gaus",0,150); TCanvas *c2 = new TCanvas(name,name); c2->Divide(2,3); double mean=0.,sigma =0.; for(short lid=0;lid<5;++lid){ c1->cd(lid+1); h_ladder_stripID[lid][0]->Draw(); h_ladder_stripID[lid][1]->SetLineColor(6); h_ladder_stripID[lid][1]->Draw("same"); c2->cd(lid+1); h_Refer[lid][0]->Draw(); mean = h_Refer[lid][0]->GetMean(); sigma = h_Refer[lid][0]->GetRMS(); gausFit->SetRange(mean-2.5*sigma,mean+2.5*sigma); h_Refer[lid][0]->Fit(gausFit,"R0Q"); gausFit->DrawCopy("lsame"); outputlog<<lid<<" "<<gausFit->GetParameter(1)<<" "<<gausFit->GetParameter(2)<<" "; h_Refer[lid][1]->SetLineColor(6); h_Refer[lid][1]->Draw("same"); mean = h_Refer[lid][1]->GetMean(); sigma = h_Refer[lid][1]->GetRMS(); gausFit->SetRange(mean-2.5*sigma,mean+2.5*sigma); h_Refer[lid][1]->Fit(gausFit,"R0Q"); gausFit->DrawCopy("lsame"); outputlog<<gausFit->GetParameter(1)<<" "<<gausFit->GetParameter(2)<<endl; } }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax, bool ispPb, int count){ //cout<<cut.Data()<<endl; //static int count=0; //count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",50,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",50,5,6); TString iNP="7.26667e+00*Gaus(x,5.10472e+00,2.63158e-02)/(sqrt(2*3.14159)*2.63158e-02)+4.99089e+01*Gaus(x,4.96473e+00,9.56645e-02)/(sqrt(2*3.14159)*9.56645e-02)+3.94417e-01*(3.74282e+01*Gaus(x,5.34796e+00,3.11510e-02)+1.14713e+01*Gaus(x,5.42190e+00,1.00544e-01))"; TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); TH1D *hraw = new TH1D(Form("hraw%d",count),"",50,5,6); clean0(hraw); hraw = (TH1D*)h->Clone(Form("hraw%d",count)); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParLimits(8,0.01,0.05); f->SetParLimits(7,0,1); f->SetParLimits(5,0,1000); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi%d",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(5)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass%d",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (20 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); hraw->Draw("same"); double yield = mass->Integral(5,6)/0.02; double yieldErr = mass->Integral(5,6)/0.02*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"pPb #sqrt{s_{NN}} = 5.02 TeV",""); leg->AddEntry(h,Form("%.0f < p_{T}^{B} < %.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B} = %.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B} = %.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); if(ispPb)c->SaveAs(Form("../ResultsBplus/BMass-%d.pdf",count)); else c->SaveAs(Form("../ResultsBplus_pp/BMass-%d.pdf",count)); h->Write(); hMC->Write(); f->Write(); background->Write(); Bkpi->Write(); mass->Write(); hraw->Write(); return mass; }
//void testFit(int count=3,Double_t ptmin=30.,Double_t ptmax=40,TString sample="PbPb") void compareUpgrade(int option=2) { int count; Double_t ptmin; Double_t ptmax; TString sample; int nmin,nmax,mymaxhisto; if (option==1) {count=3; ptmin=30.; ptmax=40; sample="PbPb"; mymaxhisto=2000; }; if (option==2) {count=1; ptmin=2.; ptmax=3; sample="PbPbMB"; mymaxhisto=600000;}; TCanvas* c= new TCanvas(Form("c%d",count),"",600,600); TFile *file=new TFile(Form("FitsFiles/Fits_%s_%d.root",sample.Data(), count)); TH1D* h = (TH1D*)file->Get(Form("h-%d",count)); TH1D* hMCSignal = (TH1D*)file->Get(Form("hMCSignal-%d",count)); TH1D* hMCSwapped = (TH1D*)file->Get(Form("hMCSwapped-%d",count)); TF1* f = new TF1(Form("f%d",count),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); h->GetEntries(); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); /* TCanvas*mycanvas=new TCanvas("mycanvas","mycanvas",1000,500); mycanvas->Divide(2,1); mycanvas->cd(1); hMCSignal->Draw(); mycanvas->cd(2); hMCSwapped->Draw(); mycanvas->SaveAs("mycanvas.pdf"); */ h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); std::cout<<"parameter 10="<<f->GetParameter(10)<<std::endl; TF1* background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass%d",count),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap%d",count),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldtotal = f->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"yield signal="<<yield<<std::endl; std::cout<<"total counts="<<yieldtotal<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.04); Tl.SetTextFont(42); Tl.DrawLatex(0.18,0.93, "#scale[1.25]{CMS} Performance"); Tl.DrawLatex(0.65,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TLatex* tex; tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); h->GetFunction(Form("f%d",count))->Delete(); TH1F* histo_copy_nofitfun = ( TH1F * ) h->Clone("histo_copy_nofitfun"); histo_copy_nofitfun->Draw("esame"); TH1D* hTest = new TH1D("hTest","",nbinsmasshisto,minhisto,maxhisto); for (int m=0;m<yieldtotal;m++){ double r = f->GetRandom(); hTest->Fill(r); } TF1* ffaketotal=(TF1*)f->Clone("ffake"); TF1* ffakemass=(TF1*)mass->Clone("ffakemass"); TF1* ffakebackground=(TF1*)background->Clone("ffakebackground"); TF1* ffakemassSwap=(TF1*)massSwap->Clone("ffakemassSwap"); Double_t yieldtotal_original = ffaketotal->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldmass_original = ffakemass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldbackground_original = ffakebackground->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldswapped_original = ffakemassSwap->Integral(minhisto,maxhisto)/binwidthmass; TH1D* hTestFake = new TH1D("hTestFake","",nbinsmasshisto,minhisto,maxhisto); ffakemass->SetParameter(2,ffaketotal->GetParameter(2)*0.8); ffakemass->SetParameter(10,ffaketotal->GetParameter(10)*0.8); Double_t yieldmass_modified= ffakemass->Integral(minhisto,maxhisto)/binwidthmass; cout<<"mass original="<<yieldmass_original<<endl; cout<<"mass modified="<<yieldmass_modified<<endl; for (int m=0;m<yieldmass_original*scalefactor;m++){ double r = ffakemass->GetRandom(); hTestFake->Fill(r); } for (int m=0;m<(int)(yieldbackground_original*scalefactor*bkgreduction);m++){ double r = ffakebackground->GetRandom(); hTestFake->Fill(r); } for (int m=0;m<(int)(yieldswapped_original*scalefactor*bkgreduction);m++){ double r = ffakemassSwap->GetRandom(); hTestFake->Fill(r); } TCanvas*c2=new TCanvas("c2","c2",500,500); c2->cd(); hTest->SetMaximum(2000); hTest->SetXTitle("m_{#piK} (GeV/c^{2})"); hTest->SetYTitle("Entries / (5 MeV/c^{2})"); hTest->GetXaxis()->CenterTitle(); hTest->GetYaxis()->CenterTitle(); hTest->SetAxisRange(0,hTest->GetMaximum()*1.*1.2,"Y"); hTest->GetXaxis()->SetTitleOffset(1.3); hTest->GetYaxis()->SetTitleOffset(1.8); hTest->GetXaxis()->SetLabelOffset(0.007); hTest->GetYaxis()->SetLabelOffset(0.007); hTest->GetXaxis()->SetTitleSize(0.045); hTest->GetYaxis()->SetTitleSize(0.045); hTest->GetXaxis()->SetTitleFont(42); hTest->GetYaxis()->SetTitleFont(42); hTest->GetXaxis()->SetLabelFont(42); hTest->GetYaxis()->SetLabelFont(42); hTest->GetXaxis()->SetLabelSize(0.04); hTest->GetYaxis()->SetLabelSize(0.04); hTest->SetMarkerSize(0.8); hTest->SetMarkerStyle(20); hTest->SetStats(0); hTest->Draw("e"); hTest->SetLineColor(1); hTest->SetMarkerColor(1); hTestFake->SetLineColor(2); hTestFake->SetMarkerColor(2); hTest->Draw("ep"); hTestFake->Draw("epsame"); TLegend* myleg = new TLegend(0.2177419,0.6292373,0.6633065,0.7266949,NULL,"brNDC"); myleg->SetBorderSize(0); myleg->SetTextSize(0.04); myleg->SetTextFont(42); myleg->SetFillStyle(0); myleg->AddEntry(hTest,"Current CMS, |y|<1, L_{int}=0.5/nb","pl"); myleg->AddEntry(hTestFake,"Upgraded CMS, |y|<2, L_{int}=1.5/nb","l"); myleg->Draw("same"); TLatex* mytex; mytex = new TLatex(0.22,0.83,Form("%.0f < p_{T} < %.0f GeV/c",ptmin,ptmax)); mytex->SetNDC(); mytex->SetTextFont(42); mytex->SetTextSize(0.04); mytex->SetLineWidth(2); mytex->Draw(); TLatex* mychannel; mychannel = new TLatex(0.22,0.765,"D^{0} #rightarrow K#pi"); mychannel->SetNDC(); mychannel->SetTextFont(42); mychannel->SetTextSize(0.055); mychannel->SetLineWidth(2); mychannel->Draw(); TLatex myTl; myTl.SetNDC(); myTl.SetTextAlign(12); myTl.SetTextSize(0.04); myTl.SetTextFont(42); myTl.DrawLatex(0.2,0.90, "#scale[1.25]{CMS} Performance"); myTl.DrawLatex(0.63,0.90, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TFile*foutput=new TFile(Form("foutput_%s.root",sample.Data()),"recreate"); foutput->cd(); hTest->SetName("hTest"); hTestFake->SetName("hTestFake"); hTest->SetMaximum(mymaxhisto); hTest->Write(); hTestFake->SetMaximum(mymaxhisto); hTestFake->Write(); hMCSignal->Write(); hMCSwapped->Write(); c2->SaveAs(Form("PlotsUpgrade/canvasPerformance%s.pdf",sample.Data())); c2->SaveAs(Form("PlotsUpgrade/canvasPerformance%s.png",sample.Data())); }
TH1D* getYield(TTree* nt, TTree* ntMC, TString triggerpass, TString triggername, TString prescale, TString variable, TString varname, TString varlatex, Int_t BIN_NUM, Double_t BIN_MIN, Double_t BIN_MAX, TString addcut="") { TH1D* hDistrib = new TH1D(Form("h%s_Distrib_%s",triggername.Data(),varname.Data()),"",BIN_NUM,BIN_MIN,BIN_MAX); for(float ivar=0;ivar<BIN_NUM;ivar++) { TCanvas* c = new TCanvas(Form("c%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"",500,500); TH1D* h = new TH1D(Form("h%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),";D^{0} mass (GeV/c^{2});Candidates",60,1.7,2.0); TH1D* hMC = new TH1D(Form("hMC%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"",60,1.75,1.95); TH1D* hSW = new TH1D(Form("hSW%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"",60,1.75,1.95); Float_t varmin = BIN_MIN+ivar*((BIN_MAX-BIN_MIN)/BIN_NUM); Float_t varmax = BIN_MIN+(ivar+1)*((BIN_MAX-BIN_MIN)/BIN_NUM); nt->Project(Form("h%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),Form("Dmass%s",prescale.Data()),Form("%s%s&&(%s>%f&&%s<%f)%s",prefilter.Data(),addcut.Data(),variable.Data(),varmin,variable.Data(),varmax,triggerpass.Data())); ntMC->Project(Form("hMC%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"Dmass",Form("%s%s&&(%s>%f&&%s<%f)%s",prefilterMC.Data(),addcut.Data(),variable.Data(),varmin,variable.Data(),varmax,"&&1")); ntMC->Project(Form("hSW%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"Dmass",Form("%s%s&&(%s>%f&&%s<%f)%s",prefilterSW.Data(),addcut.Data(),variable.Data(),varmin,variable.Data(),varmax,"&&1")); h->SetMaximum(h->GetMaximum()*1.20); h->Draw(); TF1* f = new TF1(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.14159)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.14159)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.14159)*[8]*(1+[11])))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); f->FixParameter(11,0); h->GetEntries(); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"q","",1.7,2.0); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"q","",1.7,2.0); f->ReleaseParameter(1); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hMC->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L m","",1.7,2.0); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hSW->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hSW->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hSW->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); hSW->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L m","",1.7,2.0); f->FixParameter(7,hMC->Integral(0,1000)/(hSW->Integral(0,1000)+hMC->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"q","",1.7,2.0); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"q","",1.7,2.0); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); f->ReleaseParameter(11); f->SetParLimits(11,-1.,1.); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L q","",1.7,2.0); h->Fit(Form("f%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"L m","",1.7,2.0); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); TF1* background = new TF1(Form("background%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(1.7,2.0); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.14159)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.14159)*[5]*(1+[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(11)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap%s_Fit_%s_%.0f",triggername.Data(),varname.Data(),ivar),"[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.14159)*[3]*(1+[4]))"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8),f->GetParameter(11)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(1.7,2.0); mass->Draw("same"); massSwap->SetRange(1.7,2.0); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(1.7,2.0)/0.005; Double_t yieldErr = (mass->Integral(1.7,2.0)/0.005)*(mass->GetParError(0)/mass->GetParameter(0)); std::cout<<"YIELD="<<yield<<std::endl; // Draw the legend:) TLegend* leg = myLegend(0.20,0.60,0.53,0.94); leg->SetFillColor(0); leg->SetBorderSize(0); leg->AddEntry((TObject*)0,"CMS Preliminary",""); if(isPbPb) leg->AddEntry((TObject*)0,"PbPb #sqrt{s_{NN}}= 5.02 TeV",""); else leg->AddEntry((TObject*)0,"pp #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry((TObject*)0,Form("%.1f<%s<%.1f",varmin,varlatex.Data(),varmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->Draw(); TLegend* leg2 = myLegend(0.45,0.80,0.90,0.94); leg2->SetFillColor(0); leg2->SetBorderSize(0); leg2->AddEntry(h,"D meson",""); leg2->AddEntry(h,Form("M_{D}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{D}=%.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); hDistrib->SetBinContent(ivar+1,yield); hDistrib->SetBinError(ivar+1,yieldErr); if(isPbPb) c->SaveAs(Form("fitefficiencyPbPb/c%s_Fit_%s_%.0f.pdf",triggername.Data(),varname.Data(),ivar)); else c->SaveAs(Form("fitefficiencyPP/c%s_Fit_%s_%.0f.pdf",triggername.Data(),varname.Data(),ivar)); } TCanvas* cDistrib = new TCanvas(Form("c%s_Distrib_%s",triggername.Data(),varname.Data()),"",500,500); hDistrib->Draw(); hDistrib->SetStats(0); if(isPbPb) cDistrib->SaveAs(Form("fitefficiencyPbPb/c%s_Distrib_%s.pdf",triggername.Data(),varname.Data())); else cDistrib->SaveAs(Form("fitefficiencyPP/data/pp/c%s_Distrib_%s.pdf",triggername.Data(),varname.Data())); return hDistrib; }
void bToDRawYield() { gStyle->SetTextSize(0.05); gStyle->SetTextFont(42); gStyle->SetPadRightMargin(0.04); gStyle->SetPadLeftMargin(0.14); gStyle->SetPadTopMargin(0.1); gStyle->SetPadBottomMargin(0.14); gStyle->SetTitleX(.0f); gStyle->SetOptFit(1111); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); TCanvas* c4 = new TCanvas("c4","",800,600); c4->Divide(2,2); TCanvas* c2 = new TCanvas("c2","",400,600); c2->Divide(1,2); TCanvas* c1 = new TCanvas(); TCanvas* c15 = new TCanvas("c15","",1300,1000); // c15->Divide(3,5); c15->Divide(5,5); TFile* fPP = new TFile("bFeedDownPP.hist.root"); TFile* fPPMB = new TFile("bFeedDownPPMB.hist.root"); TFile* fPPMC = new TFile("bFeedDownPPMC.hist.root"); TFile* fPPMBMC = new TFile("bFeedDownPPMBMC.hist.root"); TH3D* hDataPP = (TH3D*)fPP->Get("hData"); TH3D* hSidebandPP = (TH3D*)fPP->Get("hSideband"); TH3D* hDataPPMB = (TH3D*)fPPMB->Get("hData"); TH3D* hSidebandPPMB = (TH3D*)fPPMB->Get("hSideband"); TH3D* hPtMD0DcaPP = (TH3D*)fPP->Get("hPtMD0Dca"); TH3D* hPtMD0DcaPPMB = (TH3D*)fPPMB->Get("hPtMD0Dca"); TH3D* hMCPSignalPP = (TH3D*)fPPMC->Get("hMCPSignal"); TH3D* hMCNPSignalPP = (TH3D*)fPPMC->Get("hMCNPSignal"); TH3D* hMCPSignalPPMB = (TH3D*)fPPMBMC->Get("hMCPSignal"); TH3D* hMCNPSignalPPMB = (TH3D*)fPPMBMC->Get("hMCNPSignal"); TH3D* hPtMD0DcaMCPSignalPP = (TH3D*)fPPMC->Get("hPtMD0DcaMCPSignal"); TH3D* hPtMD0DcaMCPSwappedPP = (TH3D*)fPPMC->Get("hPtMD0DcaMCPSwapped"); TH3D* hPtMD0DcaMCPSignalPPMB =(TH3D*)fPPMBMC->Get("hPtMD0DcaMCPSignal"); TH3D* hPtMD0DcaMCPSwappedPPMB = (TH3D*)fPPMBMC->Get("hPtMD0DcaMCPSwapped"); TH3D* hData = (TH3D*)hDataPP->Clone("hData"); hData->Sumw2(); hData->Add(hDataPPMB); TH3D* hSideband = (TH3D*)hSidebandPP->Clone("hSideband"); hSideband->Sumw2(); hSideband->Add(hSidebandPPMB); TH3D* hPtMD0Dca = (TH3D*)hPtMD0DcaPP->Clone("hPtMD0Dca"); hPtMD0Dca->Sumw2(); hPtMD0Dca->Add(hPtMD0DcaPPMB); TH3D* hMCPSignal = (TH3D*)hMCPSignalPP->Clone("hMCPSignal"); hMCPSignal->Sumw2(); hMCPSignal->Add(hMCPSignalPPMB); TH3D* hMCNPSignal = (TH3D*)hMCNPSignalPP->Clone("hMCNPSignal"); hMCNPSignal->Sumw2(); hMCNPSignal->Add(hMCNPSignalPPMB); TH3D* hPtMD0DcaMCPSignal = (TH3D*)hPtMD0DcaMCPSignalPP->Clone("hPtMD0DcaMCPSignal"); hPtMD0DcaMCPSignal->Sumw2(); hPtMD0DcaMCPSignal->Add(hPtMD0DcaMCPSignalPPMB); TH3D* hPtMD0DcaMCPSwapped =(TH3D*)hPtMD0DcaMCPSwappedPP->Clone("hPtMD0DcaMCPSwapped"); hPtMD0DcaMCPSwapped->Sumw2(); hPtMD0DcaMCPSwapped->Add(hPtMD0DcaMCPSwappedPPMB); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.06); texCms->SetTextFont(42); TLatex* texCol = new TLatex(0.96,0.93, "PP #sqrt{s_{NN}} = 5.02 TeV"); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.06); texCol->SetTextFont(42); // const int nPtBins = 14; // float ptBins[nPtBins+1] = {2.,3.,4.,5.,6.,8.,10.,12.5,15.0,20.,25.,30.,40.,60.,100}; const int nPtBins = 9; float ptBins[nPtBins+1] = {2.,4.,6.,8.,10.,12.5,20.,40.,60.,100}; float pts[nPtBins]; float ptErrors[nPtBins]; float promptFraction[nPtBins]; float totalYield[nPtBins]; float totalYieldInvMassFit[nPtBins]; float totalYieldInvMassFitError[nPtBins]; float bToDYield[nPtBins]; float bToDYieldError[nPtBins]; float bToDYieldErrorDataOnly[nPtBins]; float promptDYield[nPtBins]; float promptDYieldError[nPtBins]; float promptDYieldErrorDataOnly[nPtBins]; TH1D *D0DcaDataOut[nPtBins]; /* const int nBinY = 14; Float_t binsY[nBinY+1]; float firstBinYWidth = 0.001; float binYWidthRatio = 1.27; binsY[0]=0; for(int i=1; i<=nBinY; i++) binsY[i] = binsY[i-1]+firstBinYWidth*pow(binYWidthRatio,i-1); cout<<"last y bin: "<<binsY[nBinY]<<endl; */ const int nBinY = 20; Float_t binsY[nBinY+1] = {-0.0734,-0.0562,-0.0428,-0.0320,-0.0236,-0.0170,-0.0118,-0.0078,-0.0046,-0.002,0.0,0.002,0.0046,0.0078,0.0118,0.0170,0.0236,0.0320,0.0428,0.0562,0.0734}; for(int i=1; i<=nPtBins; i++) { pts[i-1] = 0.5*(ptBins[i-1]+ptBins[i]); ptErrors[i-1] = 0.5*(ptBins[i]-ptBins[i-1]); float ptLow = ptBins[i-1]; float ptHigh = ptBins[i]; cout<<endl<<"======================================="<<endl; cout<<"pT range: "<<ptLow<<" "<<ptHigh<<endl; TLatex* texPtY = new TLatex(0.32,0.82,Form("%.1f < p_{T} < %.1f GeV/c |y| < 1.0",ptLow,ptHigh)); texPtY->SetNDC(); texPtY->SetTextFont(42); texPtY->SetTextSize(0.06); texPtY->SetLineWidth(2); TLatex* texPt = new TLatex(0.18,0.82,Form("%.1f < p_{T} < %.1f GeV/c",ptLow,ptHigh)); texPt->SetNDC(); texPt->SetTextFont(42); texPt->SetTextSize(0.06); texPt->SetLineWidth(2); TLatex* texY = new TLatex(0.18,0.74,Form("|y| < 1.0")); texY->SetNDC(); texY->SetTextFont(42); texY->SetTextSize(0.06); texY->SetLineWidth(2); c2->cd(1); hPtMD0Dca->GetZaxis()->SetRange(1,100); hPtMD0Dca->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hPtMD0DcaMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hPtMD0DcaMCPSwapped->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); TH1D* hMData = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_%1.1f_%1.1f", ptLow, ptHigh)); TH1D* hMMCSignal = (TH1D*)hPtMD0DcaMCPSignal->Project3D("y"); TH1D* hMMCSwapped = (TH1D*)hPtMD0DcaMCPSwapped->Project3D("y"); setColorTitleLabel(hMData); setColorTitleLabel(hMMCSignal); setColorTitleLabel(hMMCSwapped); TF1* fMass = fitMass(hMData, hMMCSignal, hMMCSwapped); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); TF1* fSignalAndSwapped = new TF1("fSignalAndSwapped","[0]*([3]*([5]*Gaus(x,[1],[2]*(1+[7]))/(sqrt(2*3.1415927)*[2]*(1+[7]))+(1-[5])*Gaus(x,[1],[6]*(1+[7]))/(sqrt(2*3.1415927)*[6]*(1+[7])))+(1-[3])*Gaus(x,[1],[4]*(1+[7]))/(sqrt(2*3.1415927)*[4]*(1+[7])))", 1.7, 2.0); fSignalAndSwapped->SetParameter(0,fMass->GetParameter(0)); fSignalAndSwapped->SetParameter(1,fMass->GetParameter(1)); fSignalAndSwapped->SetParameter(2,fMass->GetParameter(2)); fSignalAndSwapped->SetParameter(3,fMass->GetParameter(7)); fSignalAndSwapped->SetParameter(4,fMass->GetParameter(8)); fSignalAndSwapped->SetParameter(5,fMass->GetParameter(9)); fSignalAndSwapped->SetParameter(6,fMass->GetParameter(10)); fSignalAndSwapped->SetParameter(7,fMass->GetParameter(11)); TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,fMass->GetParameter(3)); background->SetParameter(1,fMass->GetParameter(4)); background->SetParameter(2,fMass->GetParameter(5)); background->SetParameter(3,fMass->GetParameter(6)); cout<<"MC signal width: "<<fMass->GetParameter(2)<<" "<<fMass->GetParameter(10)<<endl; cout<<"MC swapped width: "<<fMass->GetParameter(8)<<endl; float massD = 1.8649; float massSignal1 = massD-0.025; float massSignal2 = massD+0.025; float massSideBand1 = massD-0.1; float massSideBand2 = massD-0.075; float massSideBand3 = massD+0.075; float massSideBand4 = massD+0.1; float scaleSideBandBackground = background->Integral(massSignal1, massSignal2)/(background->Integral(massSideBand1, massSideBand2)+background->Integral(massSideBand3, massSideBand4)); cout<<"scaleSideBandBackground: "<<scaleSideBandBackground<<endl; totalYieldInvMassFit[i-1] = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1); totalYieldInvMassFitError[i-1] = fMass->GetParError(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1); cout<<"totalYieldInvMassFit: "<<totalYieldInvMassFit[i-1]<<" +- "<<totalYieldInvMassFitError[i-1]<<endl; float scaleSideBandMethodSignal = fSignalAndSwapped->GetParameter(0)*fSignalAndSwapped->GetParameter(3) / (fSignalAndSwapped->Integral(massSignal1, massSignal2)-fSignalAndSwapped->Integral(massSideBand1, massSideBand2)-fSignalAndSwapped->Integral(massSideBand3, massSideBand4)); cout<<"scaleSideBandMethodSignal: "<<scaleSideBandMethodSignal<<endl; TLatex* texScale = new TLatex(0.18,0.66,Form("side band bg scale: %1.3f", scaleSideBandBackground)); texScale->SetNDC(); texScale->SetTextFont(42); texScale->SetTextSize(0.06); texScale->SetLineWidth(2); texScale->Draw(); TLine* lineSignal1 = new TLine(massSignal1, 0, massSignal1, hMData->GetMaximum()*0.5); TLine* lineSignal2 = new TLine(massSignal2, 0, massSignal2, hMData->GetMaximum()*0.5); TLine* lineSideBand1 = new TLine(massSideBand1, 0, massSideBand1, hMData->GetMaximum()*0.5); TLine* lineSideBand2 = new TLine(massSideBand2, 0, massSideBand2, hMData->GetMaximum()*0.5); TLine* lineSideBand3 = new TLine(massSideBand3, 0, massSideBand3, hMData->GetMaximum()*0.5); TLine* lineSideBand4 = new TLine(massSideBand4, 0, massSideBand4, hMData->GetMaximum()*0.5); lineSignal1->Draw(); lineSignal2->Draw(); lineSideBand1->Draw(); lineSideBand2->Draw(); lineSideBand3->Draw(); lineSideBand4->Draw(); c2->cd(2); gPad->SetLogy(); hData->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hSideband->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); hMCNPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001); TH1D* hD0DcaData0 = (TH1D*)hData->Project3D("y")->Clone("hD0DcaData0"); TH1D* hD0DcaSideband = (TH1D*)hSideband->Project3D("y")->Clone("hD0DcaSideband"); TH1D* hD0DcaMCPSignal0 = (TH1D*)hMCPSignal->Project3D("y")->Clone("hD0DcaMCPSignal0"); TH1D* hD0DcaMCNPSignal0 = (TH1D*)hMCNPSignal->Project3D("y")->Clone("hD0DcaMCNPSignal0"); float integralRawYieldMCP = hD0DcaMCPSignal0->Integral(); float integralRawYieldMCNP = hD0DcaMCNPSignal0->Integral(); cout<<"integralRawYieldMCP: "<<integralRawYieldMCP<<endl; cout<<"integralRawYieldMCNP: "<<integralRawYieldMCNP<<endl; hD0DcaMCPSignal = hD0DcaMCPSignal0; hD0DcaMCNPSignal = hD0DcaMCNPSignal0; divideBinWidth(hD0DcaData0); divideBinWidth(hD0DcaSideband); setColorTitleLabel(hD0DcaData0, 1); hD0DcaData0->GetXaxis()->SetRangeUser(-0.07,0.07); hD0DcaData0->GetYaxis()->SetTitle("counts per cm"); TH1D* hD0DcaSideband0 = (TH1D*)hD0DcaSideband->Clone("hD0DcaSideband0"); hD0DcaSideband->Scale(scaleSideBandBackground); TH1D* hD0DcaDataSubSideBand = (TH1D*)hD0DcaData0->Clone("hD0DcaDataSubSideBand"); hD0DcaDataSubSideBand->Add(hD0DcaSideband,-1); hD0DcaDataSubSideBand->Scale(scaleSideBandMethodSignal); hD0DcaData0->SetMarkerSize(0.6); hD0DcaData0->Draw(); hD0DcaSideband->Draw("hsame"); hD0DcaSideband0->SetLineStyle(2); hD0DcaSideband0->Draw("hsame"); TLegend* leg1 = new TLegend(0.44,0.6,0.90,0.76,NULL,"brNDC"); leg1->SetBorderSize(0); leg1->SetTextSize(0.06); leg1->SetTextFont(42); leg1->SetFillStyle(0); leg1->AddEntry(hD0DcaData0,"D^{0} candidate","pl"); leg1->AddEntry(hD0DcaSideband,"side band","l"); leg1->AddEntry(hD0DcaSideband0,"side band unscaled","l"); leg1->Draw("same"); texCms->Draw(); texCol->Draw(); texPtY->Draw(); c2->SaveAs(Form("plots/PP_%.0f_%.0f_sideBand.pdf",ptLow,ptHigh)); c2->cd(1); hMMCSignal->Draw(); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); c2->cd(2); gPad->SetLogy(0); hMMCSwapped->Draw(); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); c2->SaveAs(Form("plots/PP_%.0f_%.0f_McInvMassFit.pdf",ptLow,ptHigh)); c15->cd(1); fitMass(hMData, hMMCSignal, hMMCSwapped); texPt->Draw(); texY->Draw(); TH1D* hD0DcaDataFit = new TH1D("hD0DcaDataFit", ";D^{0} DCA (cm);dN / d(D^{0} DCA) (cm^{-1})", nBinY, binsY); for(int j=1; j<=20; j++) { c15->cd(j+1); hPtMD0Dca->GetZaxis()->SetRange(j,j); float D0DcaLow = hPtMD0Dca->GetZaxis()->GetBinLowEdge(j); float D0DcaHigh = hPtMD0Dca->GetZaxis()->GetBinUpEdge(j); TH1D* hMData_D0Dca = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_pt_%1.1f_%1.1f_D0Dca_%1.4f_%1.4f", ptLow, ptHigh, D0DcaLow, D0DcaHigh)); setColorTitleLabel(hMData_D0Dca); fMass = fitMass(hMData_D0Dca, hMMCSignal, hMMCSwapped); float yield = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1); float yieldError = fMass->GetParError(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1); hD0DcaDataFit->SetBinContent(j, yield); hD0DcaDataFit->SetBinError(j, yieldError); TLatex* texD0Dca = new TLatex(0.18,0.82,Form("D^{0} DCA: %1.4f - %1.4f",D0DcaLow,D0DcaHigh)); texD0Dca->SetNDC(); texD0Dca->SetTextFont(42); texD0Dca->SetTextSize(0.06); texD0Dca->SetLineWidth(2); texD0Dca->Draw(); TLatex* texYield = new TLatex(0.18,0.74,Form("D^{0} yield: %1.0f #pm %1.0f",yield,yieldError)); texYield->SetNDC(); texYield->SetTextFont(42); texYield->SetTextSize(0.06); texYield->SetLineWidth(2); texYield->Draw(); } c15->SaveAs(Form("plots/PP_%.0f_%.0f_invMassFit.pdf",ptLow,ptHigh)); if(pts[i-1]<=20) { D0DcaDataOut[i-1]=(TH1D*)hD0DcaDataFit->Clone(Form("D0DcaDataOut_pt%i",i-1));} if(pts[i-1]>20) { D0DcaDataOut[i-1]=(TH1D*)hD0DcaDataSubSideBand->Clone(Form("D0DcaDataOut_pt%i",i-1)); mutiplyBinWidth(D0DcaDataOut[i-1]); } divideBinWidth(hD0DcaDataFit); c4->cd(1); gPad->SetLogy(); normalize(hD0DcaMCPSignal); setColorTitleLabel(hD0DcaMCPSignal, 2); hD0DcaMCPSignal->GetXaxis()->SetRangeUser(-0.07,0.07); normalize(hD0DcaMCNPSignal); setColorTitleLabel(hD0DcaMCNPSignal, 4); hD0DcaMCNPSignal->GetXaxis()->SetRangeUser(-0.07,0.07); hD0DcaMCNPSignal->GetYaxis()->SetTitle("dN / d(D^{0} DCA) (cm^{-1})"); hD0DcaMCNPSignal->GetXaxis()->SetTitle("D^{0} DCA (cm)"); hD0DcaMCNPSignal->SetMaximum(hD0DcaMCPSignal->GetMaximum()*3.); hD0DcaMCNPSignal->Draw(""); hD0DcaMCPSignal->Draw("same"); TLegend* leg2 = new TLegend(0.54,0.72,0.90,0.88,NULL,"brNDC"); leg2->SetBorderSize(0); leg2->SetTextSize(0.06); leg2->SetTextFont(42); leg2->SetFillStyle(0); leg2->AddEntry(hD0DcaMCPSignal,"MC Prompt D^{0}","pl"); leg2->AddEntry(hD0DcaMCNPSignal,"MC Non-prompt D^{0}","pl"); leg2->Draw("same"); c4->cd(2); gPad->SetLogy(); TH1D* hD0DcaData = hD0DcaDataFit; if(pts[i-1]>8) hD0DcaData = hD0DcaDataSubSideBand; setColorTitleLabel(hD0DcaData, 1); double integralTotalYield = hD0DcaData->Integral(1,hD0DcaData->GetXaxis()->GetNbins(),"width"); cout<<"integralTotalYield: "<<integralTotalYield<<endl; TF1* fMix = new TF1("fMix",&funMix, -0.5, 0.5, 2); fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield); fMix->SetParLimits(0,0,2*integralTotalYield); fMix->SetParLimits(1,0,2*integralTotalYield); fMix->SetLineColor(2); fMix->SetFillColor(kRed-9); fMix->SetFillStyle(1001); float fitRangeL = -0.08; float fitRangeH = 0.08; hD0DcaData->GetXaxis()->SetRangeUser(-0.07,0.07); hD0DcaData->Draw(); int fitStatus = 1; TFitResultPtr fitResult; double fitPrecision = 1.e-6; while(fitStatus) { TFitter::SetPrecision(fitPrecision); fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield); fMix->SetParError(0,0.1*integralTotalYield); fMix->SetParError(1,0.1*integralTotalYield); fitResult = hD0DcaData->Fit("fMix","E SNQ0", "", fitRangeL, fitRangeH); fitStatus = fitResult->Status(); cout<<"fit precision: "<<TFitter::GetPrecision()<<" status: "<<fitStatus<<endl; if(fitStatus) fitPrecision *= 10; } cout<<"============== do main fit ============"<<endl; fMix->SetParameters(integralTotalYield,0.9); fMix->SetParError(0,0.1*integralTotalYield); fMix->SetParError(1,0.1); fMix->SetNpx(10000); fitResult = hD0DcaData->Fit("fMix","E S0", "", fitRangeL, fitRangeH); hD0DcaData->GetFunction("fMix")->Draw("flsame"); fitStatus = fitResult->Status(); cout<<"fit precision: "<<TFitter::GetPrecision()<<" status: "<<fitStatus<<endl; TF1* fNP = new TF1("fNP",&funNonPrompt, 0., 0.5, 2); fNP->SetParameters(fMix->GetParameter(0),fMix->GetParameter(1)); fNP->SetRange(fitRangeL,fitRangeH); fNP->SetLineColor(4); fNP->SetFillStyle(1001); fNP->SetFillColor(kBlue-9); fNP->SetNpx(10000); fNP->Draw("same"); hD0DcaData->Draw("same"); promptDYield[i-1] = fMix->GetParameter(0); promptDYieldErrorDataOnly[i-1] = fMix->GetParError(0); bToDYield[i-1] = fMix->GetParameter(1); bToDYieldErrorDataOnly[i-1] = fMix->GetParError(1); totalYield[i-1] = promptDYield[i-1]+bToDYield[i-1]; promptFraction[i-1] = promptDYield[i-1]/totalYield[i-1]; cout<<"chi2 / NDF: "<<fitResult->Chi2()<<" / "<<fitResult->Ndf()<<endl; texCms->Draw(); texCol->Draw(); texPtY->Draw(); TLatex* texPrompt = new TLatex(0.4,0.73,Form("Prompt D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(0),fMix->GetParError(0))); texPrompt->SetNDC(); texPrompt->SetTextFont(42); texPrompt->SetTextSize(0.06); texPrompt->SetLineWidth(2); texPrompt->Draw(); TLatex* texNonPrompt = new TLatex(0.4,0.65,Form("B to D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(1),fMix->GetParError(1))); texNonPrompt->SetNDC(); texNonPrompt->SetTextFont(42); texNonPrompt->SetTextSize(0.06); texNonPrompt->SetLineWidth(2); texNonPrompt->Draw(); TLegend* leg4 = new TLegend(0.56,0.38,0.90,0.62); leg4->SetBorderSize(0); leg4->SetTextSize(0.06); leg4->SetTextFont(42); leg4->SetFillStyle(0); leg4->AddEntry(hD0DcaData,"Data","pl"); leg4->AddEntry(fMix,"Prompt D^{0}","f"); leg4->AddEntry(fNP,"B to D^{0}","f"); leg4->Draw("same"); //smear MC smaple with the error, to simulate the MC statistic error effect. c4->cd(3); hD0DcaMCPSignal = (TH1D*)hD0DcaMCPSignal0->Clone("hMCPSignal"); hD0DcaMCNPSignal = (TH1D*)hD0DcaMCNPSignal0->Clone("hMCNPSignal"); TH1D* hNPYield = new TH1D("hNPYield", ";hNPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1))); TH1D* hPYield = new TH1D("hPYield", ";hPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1))); setColorTitleLabel(hNPYield, 1); setColorTitleLabel(hPYield, 1); int nSmear = 1000; for(int j=0; j<nSmear; j++) { RandomSmear(hD0DcaMCPSignal0, hD0DcaMCPSignal); RandomSmear(hD0DcaMCNPSignal0, hD0DcaMCNPSignal); fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield); fMix->SetParError(0,0.1*integralTotalYield); fMix->SetParError(1,0.1*integralTotalYield); hD0DcaData->Fit("fMix","E QN0"); hPYield->Fill(fMix->GetParameter(0)); hNPYield->Fill(fMix->GetParameter(1)); } hPYield->GetXaxis()->SetTitle("prompt D^{0} yield"); hPYield->GetYaxis()->SetTitle("counts"); hPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hPYield->GetMaximum()); hPYield->SetMarkerStyle(20); hPYield->SetStats(0); hPYield->Draw("e"); hPYield->Fit("gaus"); TLatex* texGaussMeanSigmaP = new TLatex(0.27,0.83,Form("#mu: %.0f #sigma: %.0f",hPYield->GetFunction("gaus")->GetParameter(1),hPYield->GetFunction("gaus")->GetParameter(2))); texGaussMeanSigmaP->SetNDC(); texGaussMeanSigmaP->SetTextFont(42); texGaussMeanSigmaP->SetTextSize(0.06); texGaussMeanSigmaP->SetLineWidth(2); texGaussMeanSigmaP->Draw(); float promptYieldErrorMc = hPYield->GetFunction("gaus")->GetParameter(2); promptDYieldError[i-1] = sqrt(pow(promptDYieldErrorDataOnly[i-1],2)+pow(promptYieldErrorMc,2)); c4->cd(4); hNPYield->GetXaxis()->SetTitle("B to D^{0} yield"); hNPYield->GetYaxis()->SetTitle("counts"); hNPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hNPYield->GetMaximum()); hNPYield->SetMarkerStyle(20); hNPYield->SetStats(0); hNPYield->Draw("e"); hNPYield->Fit("gaus"); TLatex* texGaussMeanSigmaNP = new TLatex(0.27,0.83,Form("#mu: %.0f #sigma: %.0f",hNPYield->GetFunction("gaus")->GetParameter(1),hNPYield->GetFunction("gaus")->GetParameter(2))); texGaussMeanSigmaNP->SetNDC(); texGaussMeanSigmaNP->SetTextFont(42); texGaussMeanSigmaNP->SetTextSize(0.06); texGaussMeanSigmaNP->SetLineWidth(2); texGaussMeanSigmaNP->Draw(); float bToDYieldErrorMc = hNPYield->GetFunction("gaus")->GetParameter(2); bToDYieldError[i-1] = sqrt(pow(bToDYieldErrorDataOnly[i-1],2)+pow(bToDYieldErrorMc,2)); cout<<"prompt D yield: "<<promptDYield[i-1]<<" +- "<<promptDYieldError[i-1]<<" (+- "<<promptDYieldErrorDataOnly[i-1]<<" +- "<<promptYieldErrorMc<<" )"<<endl; cout<<"B to D yield: "<<bToDYield[i-1]<<" +- "<<bToDYieldError[i-1]<<" (+- "<<bToDYieldErrorDataOnly[i-1]<<" +- "<<bToDYieldErrorMc<<" )"<<endl; cout<<"total yield: "<<totalYield[i-1]<<endl; cout<<"prompt fraction: "<<promptFraction[i-1]<<endl; float promptMCScale = promptDYield[i-1]/integralRawYieldMCP; float nonPromptMCScale = bToDYield[i-1]/integralRawYieldMCNP; cout<<"promptMCScale: "<<promptMCScale<<endl; cout<<"nonPromptMCScale: "<<nonPromptMCScale<<endl; //restore original unsmeared histograms before saving plots delete hD0DcaMCPSignal; delete hD0DcaMCNPSignal; hD0DcaMCPSignal = hD0DcaMCPSignal0; hD0DcaMCNPSignal = hD0DcaMCNPSignal0; hD0DcaData->Fit("fMix","E QN0"); c4->SaveAs(Form("plots/PP_%.0f_%.0f_fit.pdf",ptLow,ptHigh)); c1->cd(); TH1D* hD0DcaDataOverFit = (TH1D*)hD0DcaData->Clone("hD0DcaDataOverFit"); hD0DcaDataOverFit->Divide(fMix); hD0DcaDataOverFit->GetYaxis()->SetTitle("data / fit"); hD0DcaDataOverFit->GetYaxis()->SetRangeUser(0,5); hD0DcaDataOverFit->GetXaxis()->SetRangeUser(-0.07,0.07); setColorTitleLabel(hD0DcaDataOverFit, 1); hD0DcaDataOverFit->Draw("e"); TF1* fLine1 = new TF1("fLine1", "1", 0,1); fLine1->Draw("same"); hD0DcaDataOverFit->Draw("esame"); c1->SaveAs(Form("plots/dataOverFit_%.0f_%.0f_fit.pdf",ptLow,ptHigh)); delete hD0DcaMCPSignal; delete hD0DcaMCNPSignal; } c1->cd(); TH1D* hStupidJie = new TH1D("hStupidJie", "", 100, 0, 100); hStupidJie->GetYaxis()->SetRangeUser(0,1); hStupidJie->GetXaxis()->SetTitle("p_{T} (GeV/c)"); hStupidJie->GetYaxis()->SetTitle("prompt fraction"); hStupidJie->SetStats(0); hStupidJie->Draw(); TGraph* grFraction = new TGraph(nPtBins, pts, promptFraction); grFraction->SetName("grPromptFraction"); grFraction->SetMarkerStyle(20); grFraction->Draw("psame"); c1->SaveAs("promptFraction.pdf"); c1->SetLogy(); TH1D* hBtoDRawYield = new TH1D("hBtoDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins); for(int i=1; i<=nPtBins; i++) { if(bToDYield[i-1] <= 0) continue; hBtoDRawYield->SetBinContent(i, bToDYield[i-1]); hBtoDRawYield->SetBinError(i, bToDYieldError[i-1]); } divideBinWidth(hBtoDRawYield); setColorTitleLabel(hBtoDRawYield, 1); c1->SetBottomMargin(0.14); hBtoDRawYield->Draw("p"); c1->SaveAs("BtoD.pdf"); TH1D* hPromptDRawYield = new TH1D("hPromptDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins); for(int i=1; i<=nPtBins; i++) { if(promptDYield[i-1] <= 0) continue; hPromptDRawYield->SetBinContent(i, promptDYield[i-1]); hPromptDRawYield->SetBinError(i, promptDYieldError[i-1]); } divideBinWidth(hPromptDRawYield); setColorTitleLabel(hPromptDRawYield, 1); c1->SetBottomMargin(0.14); hPromptDRawYield->Draw("p"); c1->SaveAs("promptD.pdf"); TH1D* hTotalDYieldInvMassFit = new TH1D("hTotalDYieldInvMassFit", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins); for(int i=1; i<=nPtBins; i++) { if(totalYieldInvMassFit[i-1] <= 0) continue; hTotalDYieldInvMassFit->SetBinContent(i, totalYieldInvMassFit[i-1]); hTotalDYieldInvMassFit->SetBinError(i, totalYieldInvMassFitError[i-1]); } divideBinWidth(hTotalDYieldInvMassFit); setColorTitleLabel(hTotalDYieldInvMassFit, 1); hTotalDYieldInvMassFit->Draw("p"); c1->SaveAs("totalDInvMassFit.pdf"); TFile* fOut = new TFile("bFeedDownResult.root", "recreate"); fOut->WriteTObject(grFraction); fOut->WriteTObject(hBtoDRawYield); fOut->WriteTObject(hPromptDRawYield); fOut->WriteTObject(hTotalDYieldInvMassFit); fOut->cd(); for (int i = 0; i<nPtBins;i++){ D0DcaDataOut[i]->Write(); } fOut->Write(); fOut->Close(); cout<<"end of main"<<endl; }
TF1 *fit(TTree *nt, TTree *ntMC, Double_t ptmin, Double_t ptmax, int isMC,bool isPbPb,TF1* &total,Float_t centmin, Float_t centmax) { //cout<<cut.Data()<<endl; static Int_t count=0; count++; TCanvas* c= new TCanvas(Form("c%d",count),"",600,600); TH1D* h = new TH1D(Form("h%d",count),"",nbinsmasshisto,minhisto,maxhisto); // TF1* f = new TF1(Form("f%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [6]*Gaus(x,[7],[8])/(sqrt(2*3.14159)*[8]) + [9]+[10]*x "); // TF1* f = new TF1(Form("f%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [9]+[10]*x "); TF1* f = new TF1(Form("f%d",count),"[0]*TMath::Erf((x-[1])/[2]) + [0] + [9]+[10]*x "); if(isMC==1) nt->Project(Form("h%d",count),"Bmass",Form("%s*(%s&&Bpt>%f&&Bpt<%f)","1",seldata.Data(),ptmin,ptmax)); else nt->Project(Form("h%d",count),"Bmass",Form("(%s&&Bpt>%f&&Bpt<%f)",seldata.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(0, 1e-2, 1e4); f->SetParLimits(1, 5.02, 5.06); f->SetParLimits(2, 0.001, 0.1); f->SetParLimits(3, 1e-2, 1e4); f->SetParLimits(4, 5.06, 5.10); f->SetParLimits(5, 0.001, 0.1); f->SetParLimits(6, 0, 1e4); f->SetParLimits(7, 5.3, 5.4); f->SetParLimits(8, 0.001, 0.5); f->SetParLimits(9, 0, 1e5); f->SetParLimits(10, -500, 100); f->SetParameter(0,1e2); f->SetParameter(1,5.03); f->SetParameter(2,0.05); f->SetParameter(0,1e2); f->SetParameter(1,5.03); f->SetParameter(2,0.05); f->SetParameter(3,1e2); f->SetParameter(4,5.07); f->SetParameter(5,0.05); f->SetParameter(6,1e2); f->SetParameter(7,5.35); f->SetParameter(8,0.05); f->SetParameter(9,1e3); f->SetParameter(10,-1); //error fn f->SetParLimits(0, 1e1, 1e3); f->SetParLimits(1, 5., 5.3); f->SetParLimits(2, -10, 0); f->SetParameter(0,100); f->SetParameter(1,5.1); f->SetParameter(2,0); h->GetEntries(); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(9)); background->SetParameter(1,f->GetParameter(10)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); // TF1 *mass = new TF1(Form("fmass%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5]) + [6]*Gaus(x,[7],[8])/(sqrt(2*3.14159)*[8])"); // mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(3),f->GetParameter(4),f->GetParameter(5),f->GetParameter(6),f->GetParameter(7),f->GetParameter(8)); //TF1 *mass = new TF1(Form("fmass%d",count),"[0]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]) + [3]*Gaus(x,[4],[5])/(sqrt(2*3.14159)*[5])"); //mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(3),f->GetParameter(4),f->GetParameter(5)); TF1 *mass = new TF1(Form("fmass%d",count),"[0]*TMath::Erf((x-[1])/[2]) + [0]"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2)); //mass->SetParError(0,f->GetParError(0)); //mass->SetParError(1,f->GetParError(1)); //mass->SetParError(2,f->GetParError(2)); mass->SetLineColor(2); h->SetXTitle("m_{#mu#muK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Peaking BG","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol; if(collisionsystem=="pp"||collisionsystem=="PP") texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","pp")); else texCol= new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV","PbPb")); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* tex; tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); if(centMax>0){ TString texper="%"; tex = new TLatex(0.22,0.71,Form("Centrality %.0f-%.0f%s",centMin,centMax,texper.Data()));//0.2612903,0.8425793 tex->SetNDC(); tex->SetTextColor(1); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); tex->Draw(); } tex = new TLatex(0.22,0.83,"|y| < 2.4"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); total=f; h->Write(); f->Write(); if(!isPbPb) c->SaveAs(Form("plotNP/BMass%s_%d.pdf",collisionsystem.Data(),count)); else c->SaveAs(Form("plotNP/BMass%s_%.0f_%.0f_%d.pdf",collisionsystem.Data(),centMin,centMax,count)); return mass; }
void ClusterWidthAnalysisTreeMaker::FitProfiles(std::map<ULong64_t , std::vector<TProfile*> > &ProfVsAngle, string output_file){ TFile * myFile = new TFile(output_file.c_str(), "recreate"); ULong64_t detid; double voltage; double errvoltage; double Slope; double errSlope; double Origin; double errOrigin; double Chi2; int index; TTree *tree = new TTree("T", "summary information"); tree->Branch("DetID",&detid, "DetID/l"); tree->Branch("Voltage",&voltage,"Voltage/D"); tree->Branch("Index",&index,"Index/I"); tree->Branch("errVoltage",&errvoltage,"errVoltage/D"); tree->Branch("Slope",&Slope,"Slope/D"); tree->Branch("errSlope",&errSlope,"errSlope/D"); tree->Branch("Origin",&Origin,"Origin/D"); tree->Branch("errOrigin",&errOrigin,"errOrigin/D"); tree->Branch("Chi2",&Chi2,"Chi2/D"); //TCanvas* c1 = new TCanvas(); TH1F* hChi2 = new TH1F("hChi2", "hChi2", 100, 0, 100); unsigned int nfitrm=0; for(std::map<ULong64_t , std::vector<TProfile*> >::iterator iter = ProfVsAngle.begin(); iter != ProfVsAngle.end(); ++iter){ unsigned int i=0; // voltage index std::set< int >::iterator itVolt; std::set< int > Voltage = VSmaker.getVoltageList(); for( itVolt=Voltage.begin(); itVolt!=Voltage.end(); itVolt++){ //std::cout<<"going through the measurement: " << i << std::endl; TString thestring; thestring.Form("DetID_%llu_prof_%u",iter->first,i); if(i>=iter->second.size()) { std::cout<<" Wrong number of voltage steps. "<<std::endl; i++; continue;} TProfile* Prof = iter->second[i]; if(!Prof) { std::cout<<" Profile "<<thestring.Data()<<"_"<<i<<" not found."<<std::endl; i++; continue;} //if(Histo->GetEntries()) hNhits->Fill(Histo->Integral()); /*if(Histo->Integral()<20) //0.1 { //std::cout<<" Not enought entries for histo "<<thestring.Data()<<std::endl; i++; continue;}*/ detid = iter->first; bool rmfit=false; TF1* pol = new TF1("pol", "pol1", -3, 3); pol->SetRange(-1,0); Prof->Fit("pol", "qr"); double chi2 = pol->GetChisquare()/pol->GetNDF(); hChi2->Fill(chi2); if(chi2>10) rmfit=true; if( rmfit || // TIB modules // TIB - 1.4.2.5 detid==369121605 || detid==369121606 || detid==369121614 || detid==369121613 || detid==369121610 || detid==369121609 || // TIB - 1.2.2.1 detid==369121390 || detid==369121382 || detid==369121386 || detid==369121385 || detid==369121389 || detid==369121381 || // others in TIB detid==369121437 || detid==369142077 || detid==369121722 || detid==369125534 || detid==369137018 || detid==369121689 || detid==369121765 || detid==369137045 || detid==369169740 || detid==369121689 || // TOB modules // TOB + 4.3.3.8 detid/10==436281512 || detid/10==436281528 || detid/10==436281508 || detid/10==436281524 || detid/10==436281520 || detid/10==436281516 || // others in TOB detid/10==436228249 || detid/10==436232694 || detid/10==436228805 || detid/10==436244722 || detid/10==436245110 || detid/10==436249546 || detid/10==436310808 || detid/10==436312136 || detid/10==436315600 || // without 'sensors' option detid==436281512 || detid==436281528 || detid==436281508 || detid==436281524 || detid==436281520 || detid==436281516 || detid==436228249 || detid==436232694 || detid==436228805 || detid==436244722 || detid==436245110 || detid==436249546 || detid==436310808 || detid==436312136 || detid==436315600 || // TID modules detid==402664070 || detid==402664110 || // TEC modules in small scans detid==470148196 || detid==470148200 || detid==470148204 || detid==470148228 || detid==470148232 || detid==470148236 || detid==470148240 || detid==470148261 || detid==470148262 || detid==470148265 || detid==470148266 || detid==470148292 || detid==470148296 || detid==470148300 || detid==470148304 || detid==470148324 || detid==470148328 || detid==470148332 || detid==470148336 || detid==470148340 ) { Prof->Write(); std::cout << " Saving histo : " << thestring.Data() << std::endl; } if(rmfit) {nfitrm++; i++; continue;} int subdet = ((detid>>25)&0x7); int TECgeom=0; if(subdet==6) TECgeom = ((detid>>5)&0x7); // save values detid = iter->first; voltage = *itVolt; index = i; errvoltage = 2 ; Slope = pol->GetParameter(1); errSlope = pol->GetParError(1); Origin = pol->GetParameter(0); errOrigin = pol->GetParError(0); Chi2 = chi2; tree->Fill(); i++; } } tree->Write(); //hNhits->Write(); //// If you want to store all the individual detId histograms uncomments this line !!!! //myFile->Write(); myFile->Close(); }
void nudgeVpd( string vpdParams, string qaFile, double fitLow = -10.0, double fitHigh = 10.0 ) { Reporter rp( "VpdNudge.pdf" ); rp.newPage(); ifstream infile; infile.open( vpdParams.c_str() ); ofstream outfile; outfile.open( "vpd_4DB.nudged.dat" ); TFile * qa = new TFile( qaFile.c_str() ); TH1D * dz = (TH1D*) qa->Get( "zvertexDelta" ); dz->GetXaxis()->SetRangeUser( fitLow * 1.5, fitHigh * 1.5 ); TF1 *g = new TF1( "gaus", "gaus" ); g->SetRange( fitLow, fitHigh ); dz->Draw(); gPad->SetLogy(1); dz->Fit( g, "R" ); rp.savePage(); double mean = g->GetParameter( 1 ); cout << "Adjust mean by " << -mean << " [cm]" << endl; const Float_t c_light = 29.9792458; double dt = 2 * (mean) / c_light; cout << "dt = " << dt << " [ns]" << endl; /** * Read in and write out new */ for ( int i = 0; i < 38; i++ ) { int channel = -1, nBins = -1; infile >> channel; infile >> nBins; outfile << channel << endl; outfile << nBins << endl; //copy the bin edges for ( int iBin = 0; iBin <= nBins; iBin ++ ) { double bv = -1; infile >> bv; outfile << bv << " "; } outfile << endl; // copy the corrections for ( int iBin = 0; iBin <= nBins; iBin ++ ) { double bv = -1; infile >> bv; if ( channel < 20 ) // only apply correction to one side outfile << (bv + dt) << " "; else outfile << bv << " "; } outfile << endl; } // loop on channels infile.close(); outfile.close(); delete qa; delete g; }
void PlotPhCal(const char *filename = "phCalibration_C0.dat", int col, int row) { Init(); int value, a, b, n; double x[10], y[10]; char string[200]; double aovergain, gain, par1; TF1 *pol2Fit = new TF1("pol2Fit", "pol2"); pol2Fit->SetRange(50,500); TF1 *linFit = new TF1("linFit", "pol1"); linFit->SetRange(150,600); TF1 *ursFit = new TF1("ursFit", Fitfcn, 40., 1500., 4); ursFit->SetParameter(0,0.00382); ursFit->SetParameter(1,0.886); ursFit->SetParameter(2,112.7); ursFit->SetParameter(3,113.0); TGraphErrors *graph = new TGraphErrors(); TGraph *gSlope = new TGraph(); FILE *inputFile = fopen(filename, "r"); for (int i = 0; i < 4; i++) fgets(string, 200, inputFile); for (int icol = 0; icol < 52; ++icol) { for (int irow = 0; irow < 80; ++irow) { n = 0; for (int point = 0; point < 10; point++) { fscanf(inputFile, "%s", string); if (strcmp(string, "N/A") == 0) value = 7777; else { value = atoi(string); } if ((icol == col) && (irow == row)) { if (point == 0) x[n] = 50; else if (point == 1) x[n] = 100; else if (point == 2) x[n] = 150; else if (point == 3) x[n] = 200; else if (point == 4) x[n] = 250; else if (point == 5) x[n] = 210; else if (point == 6) x[n] = 350; else if (point == 7) x[n] = 490; else if (point == 8) x[n] = 560; else if (point == 9) x[n] = 1400; if (value != 7777) { // y[n] = value; // in testboard adc range y[n] = (value + 400) / 7; // in 8 bit experiment adc range graph->SetPoint(n, x[n], y[n]); // graph->SetPointError(n, 2, 10); // in testboard adc range graph->SetPointError(n, 2, 10/6); // in 8 bit experiment adc range n++; } } } fscanf(inputFile, "%s %2i %2i", string, &a, &b); //comment } } graph->GetXaxis()->SetTitle("Vcal [low range DAC units]"); graph->GetYaxis()->SetTitle("PH [ADC units]"); graph->GetYaxis()->SetTitleOffset(1.2); graph->GetXaxis()->SetTitleSize(0.055); graph->GetYaxis()->SetTitleSize(0.055); graph->GetXaxis()->SetLabelSize(0.04); graph->GetYaxis()->SetLabelSize(0.05); graph->GetXaxis()->SetTitleOffset(1.15); graph->GetYaxis()->SetTitleOffset(1.2); graph->SetTitle(""); graph->SetLineStyle(1); graph->SetLineWidth(2); // graph->Fit("linFit","R"); // gain = linFit->GetParameter(1); graph->Fit("ursFit","R"); graph->Draw("A*"); par1 = ursFit->GetParameter(1); NewLatex()->DrawLatex(0.55, 0.5, Form("p_{1} = %.1f ", par1)); // NewLatex()->DrawLatex(0.45, 0.4, "NON-LINEAR pixel"); // PlotPhCal("/home/l_tester/ptr/moduleDB/M0567-070115.08:23/T-10a/phCalibration_C12.dat",7,23) NewLatex()->DrawLatex(0.5, 0.4, "LINEAR pixel"); // PlotPhCal("/home/l_tester/ptr/moduleDB/M0493-061206.10:45/T-10a/phCalibration_C1.dat",7,23) }
// Determine sensitivity to tracker dynamic inefficiency // by studying ratio of jet responses in Runs G and F (and BCD / F, E / F) void drawAvsB() { setTDRStyle(); string epocha = "BCD";//"BCD";//"H";//"F";//"BCD";//"F";//"E";//"BCD";//"F"; string epochb = "GH";//"G";//"BCD";//"G";//"E";//"E";//"F";//"G"; // Add the rest as well string epocha2 = "";//"EF"; string epochb2 = "";//"G"; string type = "data"; vector<string> methods; methods.push_back("mpfchs1"); methods.push_back("ptchs"); bool nozjptb = false; bool nogjmpf = false; bool nogjptb = true; bool mjvsjes = false; vector<string> samples; samples.push_back("zeejet"); samples.push_back("zmmjet"); samples.push_back("gamjet"); //samples.push_back("multijet"); cout << "draw"<<epocha<<"vs"<<epochb<<endl; const char *ct = type.c_str(); const char *pa = epocha.c_str(); const char *pb = epochb.c_str(); const char *pa2 = epocha2.c_str(); const char *pb2 = epochb2.c_str(); TFile *fg = new TFile(Form("rootfiles/jecdata%s.root",pb),"READ"); assert(fg && !fg->IsZombie()); TFile *ff = new TFile(Form("rootfiles/jecdata%s.root",pa),"READ"); assert(ff && !ff->IsZombie()); TFile *fg2(0), *ff2(0); if (epochb2!="") fg2 = new TFile(Form("rootfiles/jecdata%s.root",pb2),"READ"); if (epocha2!="") ff2 = new TFile(Form("rootfiles/jecdata%s.root",pa2),"READ"); TH1D *h = new TH1D("h", Form(";p_{T,ref} (GeV);%s ratio (%s / %s)", (type=="ratio" ? "Data/MC" : type=="data" ? "Data/data" : "MC/MC"), (epocha + (epocha2!="" ? "+"+epocha2 : "")).c_str(), (epochb + (epochb2!="" ? "+"+epochb2 : "")).c_str()), 3470,30,3500); h->SetMinimum(0.90); h->SetMaximum(1.15); h->GetXaxis()->SetMoreLogLabels(); h->GetXaxis()->SetNoExponent(); if (epocha=="F" && epochb=="G") lumi_13TeV = "Run2016F+G, 3.1+7.1 fb^{-1}"; if (epocha=="BCD" && epochb=="G") lumi_13TeV = "Run2016BCD+H, 12.9+8.8 fb^{-1}"; if (epocha=="BCD" && epochb=="G") lumi_13TeV = "Run2016BCD+FearlyGH, 12.9+16.8 fb^{-1}"; if (epocha=="BCD" && epochb=="F") lumi_13TeV = "Run2016BCD+F, 13+3.1 fb^{-1}"; if (epocha=="BCD" && epochb=="E") lumi_13TeV = "Run2016BCD+E, 13+4.0 fb^{-1}"; if (epocha=="E" && epochb=="F") lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}"; if (epocha=="F" && epochb=="E") lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}"; if ((epocha=="BCDEF" && epochb=="GH") || (epocha=="BCD" && epocha2=="EF" && epochb=="H" && epochb2=="G")) lumi_13TeV = "Run2016BCDEF+GH, 19.7+16.8 fb^{-1}"; if (epocha=="EF" && epochb=="BCD") lumi_13TeV = "Run2016BCD+EF, 12.9+6.8 fb^{-1}"; if (epocha=="H" && epochb=="G") lumi_13TeV = "Run2016G+H, 8.0+8.8 fb^{-1}"; if ((epocha=="BCD" && epocha2=="EF" && epochb=="G" && epochb2=="H")) lumi_13TeV = "Run2016BCDFearly+FlateGH, 19.7+16.8 fb^{-1}"; if ((epocha=="BCD" && epocha2=="" && ((epochb=="GH" && epochb2=="") || (epochb=="G" && epochb2=="H")))) lumi_13TeV = "Run2016BCD+FlateGH, 12.9+16.8 fb^{-1}"; if ((epocha=="EF" && epocha2=="" && ((epochb=="GH" && epochb2=="") || (epochb=="G" && epochb2=="H")))) lumi_13TeV = "Run2016EF+FlateGH, 6.8+16.8 fb^{-1}"; if ((epocha=="EF" && epocha2=="" && epochb=="G" && epochb2=="H")) lumi_13TeV = "Run2016EFearly+FlateGH, 6.8+16.8 fb^{-1}"; TCanvas *c1 = tdrCanvas("c1",h,4,11,true); c1->SetLogx(); TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextSize(0.045); TMultiGraph *mg = new TMultiGraph(); string s = "draw"+epocha+(epocha2!="" ? "p" + epocha2 : "") +"vs"+epochb+(epochb2!="" ? "p" + epochb2 : ""); TGraphErrors *gmjb(0), *gmpf(0); for (unsigned int im = 0; im != methods.size(); ++im) { const char *cm = methods[im].c_str(); tex->DrawLatex(0.20,0.75-0.06*im,cm); s += "_" + methods[im]; for (unsigned int is = 0; is != samples.size(); ++is) { const char *cs = samples[is].c_str(); TGraphErrors *gg = (TGraphErrors*)fg->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); cout << cm << " " << cs << endl << flush; assert(gg); if (fg2) { TGraphErrors *gg2 = (TGraphErrors*)fg2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gg2); gg = addGraph(gg,gg2); } TGraphErrors *gf = (TGraphErrors*)ff->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gf); if (ff2) { TGraphErrors *gf2 = (TGraphErrors*)ff2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gf2); gf = addGraph(gf,gf2); } if (!(gf->GetN()==gg->GetN())) { // Remove highest pT point is that is the offender (BCD vs GH) if (gg->GetN()>gf->GetN() && fabs(gg->GetX()[gg->GetN()-1]/gf->GetX()[gf->GetN()-1]-1)>0.1 && fabs(gg->GetX()[gg->GetN()-2]/gf->GetX()[gf->GetN()-1]-1)<0.1) { cout << "Remove point B(N-1)" << endl; gg->RemovePoint(gg->GetN()-1); } else { cout << "sample " << samples[is] << " method " << methods[im] << " gf->N: " << gf->GetN() << " gg->N: " << gg->GetN() << endl; cout << " x_gf(N-1)=" << gf->GetX()[gf->GetN()-1] << " x_gg(N-1)=" << gg->GetX()[gg->GetN()-1] << " x_gg(N-2)=" << gg->GetX()[gg->GetN()-2] << endl; } assert(gf->GetN()==gg->GetN()); } TGraphErrors *g = (TGraphErrors*)gg->Clone(Form("ge_%s_%s",cm,cs)); for (int i = 0; i != g->GetN(); ++i) { double yg = gg->GetY()[i]; double yf = gf->GetY()[i]; g->SetPoint(i, gg->GetX()[i], yf / yg); double ex = gg->GetEX()[i]; double eg = gg->GetEY()[i]; double ef = gf->GetEY()[i]; g->SetPointError(i, ex, yf/yg*sqrt(pow(eg/yg,2)+pow(ef/yf,2))); } //g->Draw(is==0 ? "AP" : "SAMEP"); g->SetLineWidth(1+is); g->Draw("SAMEPZ"); if (samples[is]=="gamjet" && methods[im]=="mpfchs1" && nogjmpf) { tex->SetTextColor(kBlue); tex->DrawLatex(0.20,0.63,"#gamma+jet MPF excl. from fit"); tex->SetTextColor(kBlack); } else if (samples[is]=="gamjet" && methods[im]=="ptchs" && nogjptb) { tex->SetTextColor(kBlue); tex->DrawLatex(0.20,0.63,"#gamma+jet p_{T}^{bal} excl. from fit"); tex->SetTextColor(kBlack); } else if ((samples[is]=="zmmjet" || samples[is]=="zeejet") && methods[im]=="ptchs" && nozjptb) { tex->SetTextColor(kRed); tex->DrawLatex(0.20,0.63,"Z+jet p_{T}^{bal} excl. from fit"); tex->SetTextColor(kBlack); } else if (samples[is]=="multijet") { g->SetMarkerColor(kGray+1); g->SetLineColor(kGray+1); if (methods[im]=="ptchs") gmjb = g; if (methods[im]=="mpfchs1") gmpf = g; } else mg->Add(g); } // for is } // for im if (nogjmpf) s += "_nogjmpf"; if (nogjptb) s += "_nogptb"; if (nozjptb) s += "_nozptb"; if (mjvsjes) { s += "_mjvsjes"; tex->SetTextColor(kBlack); tex->DrawLatex(0.20,0.58,"Multijet vs JES fit"); } TF1 *fjes = new TF1("fjes",jesFit,30,2200,2); fjes->SetParameters(0.99,0.05); mg->Fit(fjes,"RN"); fjes->SetLineColor(kBlack); fjes->SetLineStyle(kDashed); fjes->SetLineWidth(2); fjes->SetRange(10.,3500.); fjes->Draw("SAME"); //TF1 *ft = new TF1("ft","1-[0]-[1]*pow(x,[2]) + ([3]+[4]*log(x))/x",30,2200); //ft->SetParameters(0,0.05,-0.5,1,0.1); //ft->FixParameter(3,0); // Logarithmic sigmoid //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-log(abs([1])))" // "/(log(abs([2])+abs([1]))-log(abs([1])))))", 30,2200); //ft->SetParameters(0.98, 150, 50); TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))",30,2200); //ft->SetParameters(0.98,log(145),log(190)-log(145)); //ft->SetParameters(0.982,4.967,0.271); //ft->SetParameters(0.976,5.040,0.370); // ENDCAP //ft->SetParameters(0.985,5.0,0.3); ft->SetParameters(0.985,5.025,0.3); //ft->FixParameter(1,5.03); // semi-weighted average of BCD and EF //ft->FixParameter(2,0.395); // combined fit to BCD+EF / G+H // ( 12.9*5.055+6.8*5.000)/(12.9+6.8) ft->FixParameter(1,5.036); // semi-weighted average of BCD/GH and EF/GH // ( 12.9*0.344 + 6.8*0.455)/(12.9+6.8) ft->FixParameter(2,0.391); // combined fit to BCD+EF / GH // Log-sigmoid + powerlaw //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))" // "*(1-[3]*pow(x,[4]))",30,2200); //ft->SetParameters(0.982,4.967,0.271,0.1,-0.2); // Double powerlaw //TF1 *ft = new TF1("ft","[4]-[0]*pow(x,[1])-[2]*pow(x,[3])",30,2200); //ft->SetParameters(0.05,-0.15,0.01,-0.3,1); mg->Fit(ft,"RN"); ft->SetLineColor(kBlue); ft->SetLineWidth(2); ft->SetRange(10.,3500.); ft->Draw("SAME"); // Map multijet with response ratio if (gmpf) { // we have multijet available TGraphErrors *gmpf2 = (TGraphErrors*)gmpf->Clone("gmpf2"); gmpf2->SetMarkerColor(kBlack);//kGray+1); gmpf2->SetLineColor(kBlack);//kGray+1); for (int i = 0; i != gmpf->GetN(); ++i) { if (mjvsjes) { gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i], fjes->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]); gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i], gmpf->GetEY()[i]); } else { gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i], ft->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]); gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i], gmpf->GetEY()[i]); } } gmpf2->Draw("SAMEPz"); } // multijet tex->SetTextColor(kBlue); tex->DrawLatex(0.50,0.85,Form("#chi^{2} / NDF = %1.1f / %d", ft->GetChisquare(), ft->GetNDF())); tex->SetTextColor(kBlack); tex->SetTextSize(0.040); tex->DrawLatex(0.50,0.80,Form("(#chi^{2} / NDF = %1.1f / %d)", fjes->GetChisquare(), fjes->GetNDF())); tex->SetTextColor(kBlue-9); tex->SetTextSize(0.030); tex->DrawLatex(0.20,0.25,ft->GetExpFormula()); tex->DrawLatex(0.20,0.20, Form("p_{0}=%1.3f#pm%1.3f" ", p_{1}=%1.3f#pm%1.3f" ", p_{2}=%1.3f#pm%1.3f", ft->GetParameter(0),ft->GetParError(0), ft->GetParameter(1),ft->GetParError(1), ft->GetParameter(2),ft->GetParError(2))); if (ft->GetNpar()>3) tex->DrawLatex(0.20,0.17, Form("p_{3}=%1.3f#pm%1.3f" ", p_{4}=%1.3f#pm%1.3f", ft->GetParameter(3),ft->GetParError(3), ft->GetParameter(4),ft->GetParError(4))); c1->SaveAs(Form("pdf/%s.pdf",s.c_str())); for (int i = 0; i != ft->GetNpar(); ++i) { cout << Form("%s%1.4g",i==0 ? "{" : ", ",ft->GetParameter(i)); } cout << "}" << endl; }
TF1 *fit(TTree *nt, TTree *ntMC, double ptmin,double ptmax) { //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",30,5.03,5.93); // TH1D *hBck = new TH1D(Form("hBck%d",count),"",40,5,6); TH1D *hMC = new TH1D(Form("hMC%d",count),"",30,5.03,5.93); // Fit function //QM2014 //TString iNP="6.71675e+00*Gaus(x,5.30142e+00,8.42680e-02)/(sqrt(2*3.14159)*8.42680e-02)+4.06744e+01*Gaus(x,5.00954e+00,8.11305e-02)/(sqrt(2*3.14159)*8.11305e-02)+5.99974e-01*(2.376716*Gaus(x,5.640619,0.095530)/(sqrt(2*3.14159)*0.095530)+3.702342*Gaus(x,5.501706,0.046222)/(sqrt(2*3.14159)*0.046222))+1.31767e-01*(61.195688*Gaus(x,5.127566,0.087439)/(sqrt(2*3.14159)*0.087439)+58.943919*Gaus(x,5.246471,0.041983)/(sqrt(2*3.14159)*0.041983))"; TString iNP="2.28629e1*Gaus(x,5.02606,6.84e-2)/(sqrt(2*3.14159)*(6.84e-2))+3.85695*Gaus(x,5.27701,0.04305)/(sqrt(2*3.14159)*(0.04305))"; TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[6]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax)); // nt->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax)); // nt2->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax)); // cout <<"nsig = "<<hBck->GetEntries(); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.08); f->SetParLimits(8,0.01,0.1); f->SetParLimits(7,0,1); f->SetParLimits(6,0,1000); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(8,setparam3); f->FixParameter(1,fixparam1); f->FixParameter(6,0); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(7,f->GetParameter(7)); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(6); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; cout<<"======= chi2 ======="<<endl; cout<<f->GetChisquare()<<endl; cout<<"===== chi2 end ====="<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(6)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3005); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(7,f->GetParError(7)); mass->SetParError(8,f->GetParError(8)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (30 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.5,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); // hBck->Draw("hist same"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); cout <<"fit result:"<<f->GetParameter(0)*2.5<<" "<<f->Integral(5,6)/h->GetBinWidth(1)<<endl; double yield = mass->Integral(5,6)/0.03; double yieldErr = mass->Integral(5,6)/0.03*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),""); leg2->Draw(); //c->SaveAs(Form("../ResultsBzero/BMass-%d.pdf",count)); c->SaveAs("../../../BzeroDefault.pdf"); return mass; }
int main (int argc, char**argv){ if(argc!=3){ std::cerr<<" Wrongs input "<<std::endl; return -1; } std::string inputFile1 = argv[1]; std::string inputFile2 = argv[2]; std::cout<<" InputFile1 = "<<inputFile1<<std::endl; std::cout<<" InputFile2 = "<<inputFile2<<std::endl; std::ifstream File1 (inputFile1.c_str()); std::ifstream File2 (inputFile2.c_str()); if(!File1.is_open()){ std::cerr << "** ERROR: Can't open '" << inputFile1 << "' for input" << std::endl; return -1; } if(!File2.is_open()){ std::cerr << "** ERROR: Can't open '" << inputFile2 << "' for input" << std::endl; return -1; } // Set style options gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetOptTitle(1); gStyle->SetOptStat(0); gStyle->SetFitFormat("6.3g"); gStyle->SetPalette(1); gStyle->SetOptTitle(0); gStyle->SetTextFont(42); gStyle->SetTextSize(0.05); gStyle->SetTitleFont(42,"xyz"); gStyle->SetTitleSize(0.05); gStyle->SetLabelFont(42,"xyz"); gStyle->SetLabelSize(0.05); gStyle->SetTitleXOffset(0.8); gStyle->SetTitleYOffset(1.1); gROOT->ForceStyle(); int iPhi, iEta, iz; double ic, eic; /// Histo for first ic set TString Name = Form("mapEB_%s",inputFile1.c_str()); TH2F * map1_EB = new TH2F(Name,Name,360,1, 361, 171, -85, 86); Name = Form("mapEEp_%s",inputFile1.c_str()); TH2F * map1_EEp = new TH2F(Name,Name,100,1, 101, 100, 1, 101); Name = Form("mapEEm_%s",inputFile1.c_str()); TH2F * map1_EEm = new TH2F(Name,Name,100,1, 101, 100, 1, 101); std::cout<<" Opening first file ..... reading "<<std::endl; while (!File1.eof()){ File1 >> iEta >> iPhi >> iz >> ic >> eic ; if(iz==0) map1_EB->Fill(iPhi,iEta,ic); if(iz==1) map1_EEp->Fill(iEta,iPhi,ic); if(iz==-1)map1_EEm->Fill(iEta,iPhi,ic); } std::cout<<" End first file "<<std::endl; std::cout<<" Opening second file ..... reading "<<std::endl; /// Histo for first ic set Name = Form("mapEB_%s",inputFile2.c_str()); TH2F * map2_EB = new TH2F(Name,Name,360,1, 361, 171, -85, 86); Name = Form("mapEEp_%s",inputFile2.c_str()); TH2F * map2_EEp = new TH2F(Name,Name,100,1, 101, 100, 1, 101); Name = Form("mapEEm_%s",inputFile2.c_str()); TH2F * map2_EEm = new TH2F(Name,Name,100,1, 101, 100, 1, 101); while (!File2.eof()){ File2 >> iEta >> iPhi >> iz >> ic >> eic ; if(iz==0) map2_EB->Fill(iPhi,iEta,ic); if(iz==1) map2_EEp->Fill(iEta,iPhi,ic); if(iz==-1) map2_EEm->Fill(iEta,iPhi,ic); } std::cout<<" End second file "<<std::endl; TApplication* theApp = new TApplication("Application",&argc, argv); /// Set of two ic sets Name = Form("diffmapEB"); TH2F * diffmap_EB = (TH2F*) map1_EB->Clone("diffmapEB"); diffmap_EB->Reset(); Name = Form("diffmapEEp"); TH2F * diffmap_EEp = (TH2F*) map1_EEp->Clone("diffmapEEp"); diffmap_EEp->Reset(); Name = Form("diffmapEEm"); TH2F * diffmap_EEm = (TH2F*) map1_EEm->Clone("diffmapEEm"); diffmap_EEm->Reset(); Name = Form("ratiomapEB"); TH2F * ratiomap_EB = (TH2F*) map1_EB->Clone("ratiomapEB"); ratiomap_EB->Reset(); Name = Form("ratiomapEEp"); TH2F * ratiomap_EEp = (TH2F*) map1_EEp->Clone("ratiomapEEp"); ratiomap_EEp->Reset(); Name = Form("ratiomapEEm"); TH2F * ratiomap_EEm = (TH2F*) map1_EEm->Clone("ratiomapEEm"); ratiomap_EEm->Reset(); Name = Form("diffHistEB"); TH1F * diffHistEB = new TH1F(Name,Name,100,-0.6,0.6); diffHistEB->SetLineWidth(2); Name = Form("diffHistEEp"); TH1F * diffHistEEp = new TH1F(Name,Name,100,-0.6,0.6); diffHistEEp->SetLineWidth(2); Name = Form("diffHistEEm"); TH1F * diffHistEEm = new TH1F(Name,Name,100,-0.6,0.6); diffHistEEm->SetLineWidth(2); Name = Form("correlationEB"); TH2F * correlationEB = new TH2F(Name,Name,100,0.2,2.,100,0.2,2.); Name = Form("correlationEEp"); TH2F * correlationEEp= new TH2F(Name,Name,100,0.2,2.,100,0.2,2.); Name = Form("correlationEEm"); TH2F * correlationEEm= new TH2F(Name,Name,100,0.2,2.,100,0.2,2.); for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){ for(int iEta=1; iEta<map1_EB->GetNbinsY()+1; iEta++){ if(map1_EB->GetBinContent(iPhi,iEta)==-1. || map2_EB->GetBinContent(iPhi,iEta)==-1.){ diffmap_EB->SetBinContent(iPhi,iEta,-1.); ratiomap_EB->SetBinContent(iPhi,iEta,-1.); continue;} diffmap_EB->SetBinContent(iPhi,iEta,map1_EB->GetBinContent(iPhi,iEta)-map2_EB->GetBinContent(iPhi,iEta)); diffHistEB->Fill(map1_EB->GetBinContent(iPhi,iEta)-map2_EB->GetBinContent(iPhi,iEta)); ratiomap_EB->SetBinContent(iPhi,iEta,map1_EB->GetBinContent(iPhi,iEta)/map2_EB->GetBinContent(iPhi,iEta)); correlationEB->Fill(map1_EB->GetBinContent(iPhi,iEta),map2_EB->GetBinContent(iPhi,iEta)); } } for(int ix =1; ix<map1_EEp->GetNbinsX()+1; ix++){ for(int iy=1; iy<map1_EEp->GetNbinsY()+1; iy++){ if(map1_EEp->GetBinContent(ix,iy)==-1. || map2_EEp->GetBinContent(ix,iy)==-1.){ diffmap_EEp->SetBinContent(ix,iy,-1.); ratiomap_EEp->SetBinContent(ix,iy,-1.); continue;} diffmap_EEp->SetBinContent(ix,iy,map1_EEp->GetBinContent(ix,iy)-map2_EEp->GetBinContent(ix,iy)); diffHistEEp->Fill(map1_EEp->GetBinContent(ix,iy)-map2_EEp->GetBinContent(ix,iy)); ratiomap_EEp->SetBinContent(ix,iy,map1_EEp->GetBinContent(ix,iy)/map2_EEp->GetBinContent(ix,iy)); correlationEEp->Fill(map1_EEp->GetBinContent(ix,iy),map2_EEp->GetBinContent(ix,iy)); } } for(int ix =1; ix<map1_EEm->GetNbinsX()+1; ix++){ for(int iy=1; iy<map1_EEm->GetNbinsY()+1; iy++){ if(map1_EEm->GetBinContent(ix,iy)==-1. || map2_EEm->GetBinContent(ix,iy)==-1.){ diffmap_EEm->SetBinContent(ix,iy,-1.); ratiomap_EEm->SetBinContent(ix,iy,-1.); continue;} diffmap_EEm->SetBinContent(ix,iy,map1_EEm->GetBinContent(ix,iy)-map2_EEm->GetBinContent(ix,iy)); diffHistEEm->Fill(map1_EEm->GetBinContent(ix,iy)-map2_EEm->GetBinContent(ix,iy)); ratiomap_EEm->SetBinContent(ix,iy,map1_EEm->GetBinContent(ix,iy)/map2_EEm->GetBinContent(ix,iy)); correlationEEm->Fill(map1_EEm->GetBinContent(ix,iy),map2_EEm->GetBinContent(ix,iy)); } } /// Profile along phi for EB: TGraphErrors *phiProjectionEB1 = new TGraphErrors(); phiProjectionEB1->SetMarkerStyle(20); phiProjectionEB1->SetMarkerSize(1); phiProjectionEB1->SetMarkerColor(kBlue); TGraphErrors *phiProjectionEB2 = new TGraphErrors(); phiProjectionEB2->SetMarkerStyle(20); phiProjectionEB2->SetMarkerSize(1); phiProjectionEB2->SetMarkerColor(kRed); for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){ double sumEta=0, nEta=0; for(int iEta =1; iEta<map1_EB->GetNbinsY()+1; iEta++){ if(map1_EB->GetBinContent(iPhi,iEta)==-1. || map1_EB->GetBinContent(iPhi,iEta)==0.) continue; sumEta=sumEta+map1_EB->GetBinContent(iPhi,iEta); nEta++; } phiProjectionEB1->SetPoint(iPhi-1,iPhi-1,sumEta/nEta); phiProjectionEB1->SetPointError(iPhi-1,0.,0.002); } for(int iPhi =1; iPhi<map2_EB->GetNbinsX()+1; iPhi++){ double sumEta=0, nEta=0; for(int iEta =1; iEta<map2_EB->GetNbinsY()+1; iEta++){ if(map2_EB->GetBinContent(iPhi,iEta)==-1.||map2_EB->GetBinContent(iPhi,iEta)==0. ) continue; sumEta=sumEta+map2_EB->GetBinContent(iPhi,iEta); nEta++; } phiProjectionEB2->SetPoint(iPhi-1,iPhi-1,sumEta/nEta); phiProjectionEB2->SetPointError(iPhi-1,0.,0.002); } /// Profile along phi for EE+: TEndcapRings *eRings = new TEndcapRings(); std::vector<double> vectSum; std::vector<double> vectCounter; vectCounter.assign(360,0.); vectSum.assign(360,0.); TGraphErrors *phiProjectionEEp1 = new TGraphErrors(); phiProjectionEEp1->SetMarkerStyle(20); phiProjectionEEp1->SetMarkerSize(1); phiProjectionEEp1->SetMarkerColor(kBlue); TGraphErrors *phiProjectionEEp2 = new TGraphErrors(); phiProjectionEEp2->SetMarkerStyle(20); phiProjectionEEp2->SetMarkerSize(1); phiProjectionEEp2->SetMarkerColor(kRed); for(int ix=1; ix<map1_EEp->GetNbinsX()+1;ix++){ for(int iy=1; iy<map1_EEp->GetNbinsY()+1;iy++){ if(map1_EEp->GetBinContent(ix,iy)==-1. || map1_EEp->GetBinContent(ix,iy)==0. ) continue; int iPhi = int(eRings->GetEndcapIphi(ix,iy,1)); vectSum.at(iPhi)=vectSum.at(iPhi)+map1_EEp->GetBinContent(ix,iy); vectCounter.at(iPhi)=vectCounter.at(iPhi)+1; } } int j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; phiProjectionEEp1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } for(int ix=1; ix<map2_EEp->GetNbinsX()+1;ix++){ for(int iy=1; iy<map2_EEp->GetNbinsY()+1;iy++){ if(map2_EEp->GetBinContent(ix,iy)==-1. ||map2_EEp->GetBinContent(ix,iy)==0.) continue; int iPhi = int(eRings->GetEndcapIphi(ix,iy,1)); vectSum.at(iPhi)=vectSum.at(iPhi)+map2_EEp->GetBinContent(ix,iy); vectCounter.at(iPhi)=vectCounter.at(iPhi)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; phiProjectionEEp2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } /// Profile along phi for EE-: TGraphErrors *phiProjectionEEm1 = new TGraphErrors(); phiProjectionEEm1->SetMarkerStyle(20); phiProjectionEEm1->SetMarkerSize(1); phiProjectionEEm1->SetMarkerColor(kBlue); TGraphErrors *phiProjectionEEm2 = new TGraphErrors(); phiProjectionEEm2->SetMarkerStyle(20); phiProjectionEEm2->SetMarkerSize(1); phiProjectionEEm2->SetMarkerColor(kRed); for(int ix=1; ix<map1_EEm->GetNbinsX()+1;ix++){ for(int iy=1; iy<map1_EEm->GetNbinsY()+1;iy++){ if(map1_EEm->GetBinContent(ix,iy)==-1. || map1_EEm->GetBinContent(ix,iy)==0. ) continue; int iPhi = int(eRings->GetEndcapIphi(ix,iy,-1)); vectSum.at(iPhi)=vectSum.at(iPhi)+map1_EEm->GetBinContent(ix,iy); vectCounter.at(iPhi)=vectCounter.at(iPhi)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; phiProjectionEEm1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } for(int ix=1; ix<map2_EEm->GetNbinsX()+1;ix++){ for(int iy=1; iy<map2_EEm->GetNbinsY()+1;iy++){ if(map2_EEm->GetBinContent(ix,iy)==-1. || map2_EEm->GetBinContent(ix,iy)==0.) continue; int iPhi = int(eRings->GetEndcapIphi(ix,iy,-1)); vectSum.at(iPhi)=vectSum.at(iPhi)+map2_EEm->GetBinContent(ix,iy); vectCounter.at(iPhi)=vectCounter.at(iPhi)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; phiProjectionEEm2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } /// projection along eta for EB TGraphErrors *etaProjectionEB1 = new TGraphErrors(); etaProjectionEB1->SetMarkerStyle(20); etaProjectionEB1->SetMarkerSize(1); etaProjectionEB1->SetMarkerColor(kBlue); TGraphErrors *etaProjectionEB2 = new TGraphErrors(); etaProjectionEB2->SetMarkerStyle(20); etaProjectionEB2->SetMarkerSize(1); etaProjectionEB2->SetMarkerColor(kRed); for(int iEta =1; iEta<map1_EB->GetNbinsY()+1; iEta++){ double sumPhi=0, nPhi=0; for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){ if(map1_EB->GetBinContent(iPhi,iEta)==-1.) continue; sumPhi=sumPhi+map1_EB->GetBinContent(iPhi,iEta); nPhi++; } etaProjectionEB1->SetPoint(iEta-1,iEta-1,sumPhi/nPhi); etaProjectionEB1->SetPointError(iEta-1,0.,0.002); } for(int iEta =1; iEta<map2_EB->GetNbinsY()+1; iEta++){ double sumPhi=0, nPhi=0; for(int iPhi =1; iPhi<map2_EB->GetNbinsX()+1; iPhi++){ if(map2_EB->GetBinContent(iPhi,iEta)==-1.) continue; sumPhi=sumPhi+map2_EB->GetBinContent(iPhi,iEta); nPhi++; } etaProjectionEB2->SetPoint(iEta-1,iEta-1,sumPhi/nPhi); etaProjectionEB2->SetPointError(iEta-1,0.,0.002); } /// projection along eta for EE+: TGraphErrors *etaProjectionEEp1 = new TGraphErrors(); etaProjectionEEp1->SetMarkerStyle(20); etaProjectionEEp1->SetMarkerSize(1); etaProjectionEEp1->SetMarkerColor(kBlue); TGraphErrors *etaProjectionEEp2 = new TGraphErrors(); etaProjectionEEp2->SetMarkerStyle(20); etaProjectionEEp2->SetMarkerSize(1); etaProjectionEEp2->SetMarkerColor(kRed); vectCounter.clear(); vectSum.clear(); vectCounter.assign(360,0.); vectSum.assign(360,0.); for(int ix=1; ix<map1_EEp->GetNbinsX()+1;ix++){ for(int iy=1; iy<map1_EEp->GetNbinsY()+1;iy++){ if(map1_EEp->GetBinContent(ix,iy)==-1. || map1_EEp->GetBinContent(ix,iy)==0.) continue; int iEta = int(eRings->GetEndcapIeta(ix,iy,1)); if(iEta<0 || iEta>360)continue; vectSum.at(iEta)=vectSum.at(iEta)+map1_EEp->GetBinContent(ix,iy); vectCounter.at(iEta)=vectCounter.at(iEta)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0) continue; etaProjectionEEp1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } for(int ix=1; ix<map2_EEp->GetNbinsX()+1;ix++){ for(int iy=1; iy<map2_EEp->GetNbinsY()+1;iy++){ if(map2_EEp->GetBinContent(ix,iy)==-1. || map2_EEp->GetBinContent(ix,iy)==0. ) continue; int iEta = int(eRings->GetEndcapIeta(ix,iy,1)); if(iEta<0 || iEta>360)continue; vectSum.at(iEta)=vectSum.at(iEta)+map2_EEp->GetBinContent(ix,iy); vectCounter.at(iEta)=vectCounter.at(iEta)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0) continue; etaProjectionEEp2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } /// projection along eta for EE-: TGraphErrors *etaProjectionEEm1 = new TGraphErrors(); etaProjectionEEm1->SetMarkerStyle(20); etaProjectionEEm1->SetMarkerSize(1); etaProjectionEEm1->SetMarkerColor(kBlue); TGraphErrors *etaProjectionEEm2 = new TGraphErrors(); etaProjectionEEm2->SetMarkerStyle(20); etaProjectionEEm2->SetMarkerSize(1); etaProjectionEEm2->SetMarkerColor(kRed); for(int ix=1; ix<map1_EEm->GetNbinsX()+1;ix++){ for(int iy=1; iy<map1_EEm->GetNbinsY()+1;iy++){ if(map1_EEm->GetBinContent(ix,iy)==-1.||map1_EEm->GetBinContent(ix,iy)==0.) continue; int iEta = int(eRings->GetEndcapIeta(ix,iy,1)); if(iEta<0 || iEta>360)continue; vectSum.at(iEta)=vectSum.at(iEta)+map1_EEm->GetBinContent(ix,iy); vectCounter.at(iEta)=vectCounter.at(iEta)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; etaProjectionEEm1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } for(int ix=1; ix<map2_EEm->GetNbinsX()+1;ix++){ for(int iy=1; iy<map2_EEm->GetNbinsY()+1;iy++){ if(map2_EEm->GetBinContent(ix,iy)==-1. || map2_EEm->GetBinContent(ix,iy)==0.) continue; int iEta = int(eRings->GetEndcapIeta(ix,iy,1)); if(iEta<0 || iEta>171)continue; vectSum.at(iEta)=vectSum.at(iEta)+map2_EEm->GetBinContent(ix,iy); vectCounter.at(iEta)=vectCounter.at(iEta)+1; } } j=0; for(unsigned int i=0; i<vectCounter.size();i++){ if(vectCounter.at(i)==0)continue; etaProjectionEEm2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i)); j++; } for(unsigned int i=0; i<vectSum.size(); i++){ vectSum.at(i)=0; vectCounter.at(i)=0; } /// phi Profile Histos EB cout<<" Phi Profile Histos "<<endl; TH1F* phiProfileEB1 = new TH1F ("phiProfileEB1","phiProfileEB1",60,0.7,1.3); TH1F* phiProfileEB2 = new TH1F ("phiProfileEB2","phiProfileEB2",60,0.7,1.3); for(int i=0; i<phiProjectionEB1->GetN() ; i++){ double x=0,y=0; phiProjectionEB1->GetPoint(i,x,y); phiProfileEB1->Fill(y); } for(int i=0; i<phiProjectionEB2->GetN() ; i++){ double x=0,y=0; phiProjectionEB2->GetPoint(i,x,y); phiProfileEB2->Fill(y); } TF1 *fgaus = new TF1("fgaus","gaus",-10,10); fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEB1->GetRMS()); fgaus->SetRange(1-5*phiProfileEB1->GetRMS(),1+5*phiProfileEB1->GetRMS()); fgaus->SetLineColor(kBlue); phiProfileEB1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<phiProfileEB1->GetMean()<<" RMS dist "<<phiProfileEB1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEB2->GetRMS()); fgaus->SetRange(1-5*phiProfileEB2->GetRMS(),1+5*phiProfileEB2->GetRMS()); fgaus->SetLineColor(kRed); phiProfileEB2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<phiProfileEB2->GetMean()<<" RMS dist "<<phiProfileEB2->GetRMS()<<endl; /// phi Profile Histos EE+ TH1F* phiProfileEEp1 = new TH1F ("phiProfileEEp1","phiProfileEEp1",60,0.6,1.6); TH1F* phiProfileEEp2 = new TH1F ("phiProfileEEp2","phiProfileEEp2",60,0.6,1.6); for(int i=0; i<phiProjectionEEp1->GetN() ; i++){ double x=0,y=0; phiProjectionEEp1->GetPoint(i,x,y); phiProfileEEp1->Fill(y); } for(int i=0; i<phiProjectionEEp2->GetN() ; i++){ double x=0,y=0; phiProjectionEEp2->GetPoint(i,x,y); phiProfileEEp2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEEp1->GetRMS()); fgaus->SetRange(1-5*phiProfileEEp1->GetRMS(),1+5*phiProfileEEp1->GetRMS()); fgaus->SetLineColor(kBlue); phiProfileEEp1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<phiProfileEEp1->GetMean()<<" RMS dist "<<phiProfileEEp1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEEp2->GetRMS()); fgaus->SetRange(1-5*phiProfileEEp2->GetRMS(),1+5*phiProfileEEp2->GetRMS()); fgaus->SetLineColor(kRed); phiProfileEEp2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<phiProfileEEp2->GetMean()<<" RMS dist "<<phiProfileEEp2->GetRMS()<<endl; /// phi Profile Histos EE- TH1F* phiProfileEEm1 = new TH1F ("phiProfileEEm1","phiProfileEEm1",60,0.6,1.6); TH1F* phiProfileEEm2 = new TH1F ("phiProfileEEm2","phiProfileEEm2",60,0.6,1.6); for(int i=0; i<phiProjectionEEm1->GetN() ; i++){ double x=0,y=0; phiProjectionEEm1->GetPoint(i,x,y); phiProfileEEm1->Fill(y); } for(int i=0; i<phiProjectionEEm2->GetN() ; i++){ double x=0,y=0; phiProjectionEEm2->GetPoint(i,x,y); phiProfileEEm2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEEm1->GetRMS()); fgaus->SetRange(1-5*phiProfileEEm1->GetRMS(),1+5*phiProfileEEm1->GetRMS()); fgaus->SetLineColor(kBlue); phiProfileEEm1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<phiProfileEEm1->GetMean()<<" RMS dist "<<phiProfileEEm1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,phiProfileEEm2->GetRMS()); fgaus->SetRange(1-5*phiProfileEEm2->GetRMS(),1+5*phiProfileEEm2->GetRMS()); fgaus->SetLineColor(kRed); phiProfileEEm2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<phiProfileEEm2->GetMean()<<" RMS dist "<<phiProfileEEm2->GetRMS()<<endl; /// eta Profile Histos EB cout<<" Eta Profile Histos "<<endl; TH1F* etaProfileEB1 = new TH1F ("etaProfileEB1","etaProfileEB1",60,0.85,1.15); TH1F* etaProfileEB2 = new TH1F ("etaProfileEB2","etaProfileEB2",60,0.85,1.15); for(int i=0; i<etaProjectionEB1->GetN() ; i++){ double x=0,y=0; etaProjectionEB1->GetPoint(i,x,y); etaProfileEB1->Fill(y); } for(int i=0; i<etaProjectionEB2->GetN() ; i++){ double x=0,y=0; etaProjectionEB2->GetPoint(i,x,y); etaProfileEB2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEB1->GetRMS()); fgaus->SetRange(1-5*etaProfileEB1->GetRMS(),1+5*etaProfileEB1->GetRMS()); fgaus->SetLineColor(kBlue); etaProfileEB1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<etaProfileEB1->GetMean()<<" RMS dist "<<etaProfileEB1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEB2->GetRMS()); fgaus->SetRange(1-5*etaProfileEB2->GetRMS(),1+5*etaProfileEB2->GetRMS()); fgaus->SetLineColor(kRed); etaProfileEB2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<etaProfileEB2->GetMean()<<" RMS dist "<<etaProfileEB2->GetRMS()<<endl; /// eta Profile Histos EE+ TH1F* etaProfileEEp1 = new TH1F ("etaProfileEEp1","etaProfileEEp1",35,0.,2.5); TH1F* etaProfileEEp2 = new TH1F ("etaProfileEEp2","etaProfileEEp2",35,0.,2.5); for(int i=0; i<etaProjectionEEp1->GetN() ; i++){ double x=0,y=0; etaProjectionEEp1->GetPoint(i,x,y); etaProfileEEp1->Fill(y); } for(int i=0; i<etaProjectionEEp2->GetN() ; i++){ double x=0,y=0; etaProjectionEEp2->GetPoint(i,x,y); etaProfileEEp2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEEp1->GetRMS()); fgaus->SetRange(1-5*etaProfileEEp1->GetRMS(),1+5*etaProfileEEp1->GetRMS()); fgaus->SetLineColor(kBlue); etaProfileEEp1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<etaProfileEEp1->GetMean()<<" RMS dist "<<etaProfileEEp1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEEp2->GetRMS()); fgaus->SetRange(1-5*etaProfileEEp2->GetRMS(),1+5*etaProfileEEp2->GetRMS()); fgaus->SetLineColor(kRed); etaProfileEEp2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<etaProfileEEp2->GetMean()<<" RMS dist "<<etaProfileEEp2->GetRMS()<<endl; /// eta Profile Histos EB TH1F* etaProfileEEm1 = new TH1F ("etaProfileEEm1","etaProfileEEm1",35,0.,2.5); TH1F* etaProfileEEm2 = new TH1F ("etaProfileEEm2","etaProfileEEm2",35,0.,2.5); for(int i=0; i<etaProjectionEEm1->GetN() ; i++){ double x=0,y=0; etaProjectionEEm1->GetPoint(i,x,y); etaProfileEEm1->Fill(y); } for(int i=0; i<etaProjectionEEm2->GetN() ; i++){ double x=0,y=0; etaProjectionEEm2->GetPoint(i,x,y); etaProfileEEm2->Fill(y); } fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEEm1->GetRMS()); fgaus->SetRange(1-5*etaProfileEEm1->GetRMS(),1+5*etaProfileEEm1->GetRMS()); fgaus->SetLineColor(kBlue); etaProfileEEm1->Fit("fgaus","QRME"); cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" First Set : Mean dist = "<<etaProfileEEm1->GetMean()<<" RMS dist "<<etaProfileEEm1->GetRMS()<<endl; fgaus->SetParameter(1,1); fgaus->SetParameter(2,etaProfileEEm2->GetRMS()); fgaus->SetRange(1-5*etaProfileEEm2->GetRMS(),1+5*etaProfileEEm2->GetRMS()); fgaus->SetLineColor(kRed); etaProfileEEm2->Fit("fgaus","QRME"); cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl; cout<<" Second Set : Mean dist = "<<etaProfileEEm2->GetMean()<<" RMS dist "<<etaProfileEEm2->GetRMS()<<endl; ///------------------------------------------------------------------------ ///----------------------------------------------------------------- ///--- Draw plots ///----------------------------------------------------------------- TCanvas *c[30]; c[0] = new TCanvas("hdiffEB","hdiffEB"); c[0]->SetLeftMargin(0.1); c[0]->SetRightMargin(0.13); c[0]->SetGridx(); diffmap_EB->GetXaxis()->SetNdivisions(1020); diffmap_EB->GetXaxis() -> SetLabelSize(0.03); diffmap_EB->GetXaxis() ->SetTitle("i#phi"); diffmap_EB->GetYaxis() ->SetTitle("i#eta"); diffmap_EB->GetZaxis() ->SetRangeUser(-0.1,0.1); diffmap_EB->Draw("COLZ"); c[1] = new TCanvas("histdiffEB","histdiffEB"); c[1]->SetLeftMargin(0.1); c[1]->SetRightMargin(0.13); c[1]->SetLogy(); diffHistEB->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); diffHistEB->Draw(); c[2] = new TCanvas("hratioEB","hratioEB"); c[2]->SetLeftMargin(0.1); c[2]->SetRightMargin(0.13); c[2]->SetGridx(); ratiomap_EB->GetXaxis()->SetNdivisions(1020); ratiomap_EB->GetXaxis() -> SetLabelSize(0.03); ratiomap_EB->GetXaxis() ->SetTitle("i#phi"); ratiomap_EB->GetYaxis() ->SetTitle("i#eta"); ratiomap_EB->GetZaxis() ->SetRangeUser(0.95,1.05); ratiomap_EB->Draw("COLZ"); c[3] = new TCanvas("correlationEB","correlationEB"); c[3]->SetLeftMargin(0.1); c[3]->SetRightMargin(0.13); c[3]->SetGridx(); c[3]->SetGridy(); correlationEB->GetXaxis()->SetNdivisions(1020); correlationEB->GetXaxis() -> SetLabelSize(0.03); correlationEB->GetXaxis() ->SetTitle("c_{#pi}"); correlationEB->GetYaxis() ->SetTitle("c_{ele}"); correlationEB->Draw("COLZ"); c[4] = new TCanvas("hdiffEEp","hdiffEEp"); c[4]->SetLeftMargin(0.1); c[4]->SetRightMargin(0.13); c[4]->SetGridx(); diffmap_EEp->GetXaxis()->SetNdivisions(1020); diffmap_EEp->GetXaxis() -> SetLabelSize(0.03); diffmap_EEp->GetXaxis() ->SetTitle("ix"); diffmap_EEp->GetYaxis() ->SetTitle("iy"); diffmap_EEp->GetZaxis() ->SetRangeUser(-0.15,0.15); diffmap_EEp->Draw("COLZ"); c[5] = new TCanvas("histdiffEEp","histdiffEEp"); c[5]->SetLeftMargin(0.1); c[5]->SetRightMargin(0.13); c[5]->SetLogy(); diffHistEEp->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); diffHistEEp->Draw(); c[6] = new TCanvas("hratioEEp","hratioEEp"); c[6]->SetLeftMargin(0.1); c[6]->SetRightMargin(0.13); c[6]->SetGridx(); ratiomap_EEp->GetXaxis()->SetNdivisions(1020); ratiomap_EEp->GetXaxis() -> SetLabelSize(0.03); ratiomap_EEp->GetXaxis() ->SetTitle("ix"); ratiomap_EEp->GetYaxis() ->SetTitle("iy"); ratiomap_EEp->GetZaxis() ->SetRangeUser(0.9,1.1); ratiomap_EEp->Draw("COLZ"); c[7] = new TCanvas("correlationEEp","correlationEEp"); c[7]->SetLeftMargin(0.1); c[7]->SetRightMargin(0.13); c[7]->SetGridx(); c[7]->SetGridy(); correlationEEp->GetXaxis()->SetNdivisions(1020); correlationEEp->GetXaxis() -> SetLabelSize(0.03); correlationEEp->GetXaxis() ->SetTitle("c_{#pi}"); correlationEEp->GetYaxis() ->SetTitle("c_{ele}"); correlationEEp->Draw("COLZ"); c[8] = new TCanvas("hdiffEEm","hdiffEEm"); c[8]->SetLeftMargin(0.1); c[8]->SetRightMargin(0.13); c[8]->SetGridx(); diffmap_EEm->GetXaxis()->SetNdivisions(1020); diffmap_EEm->GetXaxis() -> SetLabelSize(0.03); diffmap_EEm->GetXaxis() ->SetTitle("ix"); diffmap_EEm->GetYaxis() ->SetTitle("iy"); diffmap_EEm->GetZaxis() ->SetRangeUser(-0.15,0.15); diffmap_EEm->Draw("COLZ"); c[9] = new TCanvas("histdiffEEm","histdiffEEm"); c[9]->SetLeftMargin(0.1); c[9]->SetRightMargin(0.13); c[9]->SetLogy(); diffHistEEm->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); diffHistEEm->Draw(); c[10] = new TCanvas("hratioEEm","hratioEEm"); c[10]->SetLeftMargin(0.1); c[10]->SetRightMargin(0.13); c[10]->SetGridx(); ratiomap_EEm->GetXaxis()->SetNdivisions(1020); ratiomap_EEm->GetXaxis() -> SetLabelSize(0.03); ratiomap_EEm->GetXaxis() ->SetTitle("ix"); ratiomap_EEm->GetYaxis() ->SetTitle("iy"); ratiomap_EEm->GetZaxis() ->SetRangeUser(0.9,1.1); ratiomap_EEm->Draw("COLZ"); c[11] = new TCanvas("correlationEEm","correlationEEm"); c[11]->SetLeftMargin(0.1); c[11]->SetRightMargin(0.13); c[11]->SetGridx(); c[11]->SetGridy(); correlationEEm->GetXaxis()->SetNdivisions(1020); correlationEEm->GetXaxis() -> SetLabelSize(0.03); correlationEEm->GetXaxis() ->SetTitle("c_{#pi}"); correlationEEm->GetYaxis() ->SetTitle("c_{ele}"); correlationEEm->Draw("COLZ"); c[12] = new TCanvas("phiProjectionEB","phiProjectionEB"); c[12]->SetGridx(); c[12]->SetGridy(); phiProjectionEB1->GetHistogram()->GetYaxis()-> SetRangeUser(0.85,1.1); phiProjectionEB1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361); phiProjectionEB1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); phiProjectionEB1->GetHistogram()->GetXaxis()-> SetTitle("i#phi"); phiProjectionEB1->Draw("apl"); phiProjectionEB2->Draw("plsame"); TLegend * leg1 = new TLegend(0.75,0.75,0.89, 0.89); leg1->AddEntry(phiProjectionEB1,"IC set 1","LP"); leg1->AddEntry(phiProjectionEB2,"IC set 2","LP"); leg1->SetFillColor(0); leg1->Draw("same"); c[13] = new TCanvas("phiProjectionEEp","phiProjectionEEp"); c[13]->SetGridx(); c[13]->SetGridy(); phiProjectionEEp1->GetHistogram()->GetYaxis()-> SetRangeUser(0.7,1.4); phiProjectionEEp1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361); phiProjectionEEp1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); phiProjectionEEp1->GetHistogram()->GetXaxis()-> SetTitle("i#phi"); phiProjectionEEp1->Draw("apl"); phiProjectionEEp2->Draw("plsame"); TLegend * leg2 = new TLegend(0.75,0.75,0.89, 0.89); leg2->AddEntry(phiProjectionEEp1,"IC set 1","LP"); leg2->AddEntry(phiProjectionEEp2,"IC set 2","LP"); leg2->SetFillColor(0); leg2->Draw("same"); c[14] = new TCanvas("phiProjectionEEm","phiProjectionEEm"); c[14]->SetGridx(); c[14]->SetGridy(); phiProjectionEEm1->GetHistogram()->GetYaxis()-> SetRangeUser(0.7,1.4); phiProjectionEEm1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361); phiProjectionEEm1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); phiProjectionEEm1->GetHistogram()->GetXaxis()-> SetTitle("i#phi"); phiProjectionEEm1->Draw("apl"); phiProjectionEEm2->Draw("plsame"); TLegend * leg3 = new TLegend(0.75,0.75,0.89, 0.89); leg3->AddEntry(phiProjectionEEm1,"IC set 1","LP"); leg3->AddEntry(phiProjectionEEm2,"IC set 2","LP"); leg3->SetFillColor(0); leg3->Draw("same"); c[15] = new TCanvas("etaProjectionEB","etaProjectionEB"); c[15]->SetGridx(); c[15]->SetGridy(); etaProjectionEB1->GetHistogram()->GetYaxis()-> SetRangeUser(0.9,1.1); etaProjectionEB1->GetHistogram()->GetXaxis()-> SetRangeUser(0,171); etaProjectionEB1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); etaProjectionEB1->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); etaProjectionEB1->Draw("apl"); etaProjectionEB2->Draw("plsame"); TLegend * leg4 = new TLegend(0.75,0.75,0.89, 0.89); leg4->AddEntry(etaProjectionEB1,"IC set 1","LP"); leg4->AddEntry(etaProjectionEB2,"IC set 2","LP"); leg4->SetFillColor(0); leg1->Draw("same"); c[16] = new TCanvas("etaProjectionEEp","etaProjectionEEp"); c[16]->SetGridx(); c[16]->SetGridy(); etaProjectionEEp1->GetHistogram()->GetYaxis()-> SetRangeUser(0.55,1.5); etaProjectionEEp1->GetHistogram()->GetXaxis()-> SetRangeUser(85,125); etaProjectionEEp1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); etaProjectionEEp1->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); etaProjectionEEp1->Draw("apl"); etaProjectionEEp2->Draw("plsame"); TLegend * leg5 = new TLegend(0.75,0.75,0.89, 0.89); leg5->AddEntry(etaProjectionEEp1,"IC set 1","LP"); leg5->AddEntry(etaProjectionEEp2,"IC set 2","LP"); leg5->SetFillColor(0); leg5->Draw("same"); c[17] = new TCanvas("etaProjectionEEm","etaProjectionEEm"); c[17]->SetGridx(); c[17]->SetGridy(); etaProjectionEEm1->GetHistogram()->GetYaxis()-> SetRangeUser(0.55,1.5); etaProjectionEEm1->GetHistogram()->GetXaxis()-> SetRangeUser(85,125); etaProjectionEEm1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC"); etaProjectionEEm1->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); etaProjectionEEm1->Draw("apl"); etaProjectionEEm2->Draw("plsame"); TLegend * leg6 = new TLegend(0.75,0.75,0.89, 0.89); leg6->AddEntry(etaProjectionEEm1,"IC set 1","LP"); leg6->AddEntry(etaProjectionEEm2,"IC set 2","LP"); leg6->SetFillColor(0); leg6->Draw("same"); c[18] = new TCanvas("phiProfileEB","phiProfileEB"); c[18]->SetGridx(); c[18]->SetGridy(); phiProfileEB1->GetXaxis()->SetTitle("#bar{IC}"); phiProfileEB1->SetLineColor(kBlue); phiProfileEB1->SetMarkerSize(0.8); phiProfileEB1->SetLineWidth(2); phiProfileEB2->SetLineColor(kRed); phiProfileEB2->SetMarkerSize(0.8); phiProfileEB2->SetLineWidth(2); phiProfileEB1->Draw(); phiProfileEB2->Draw("same"); TLegend * leg7 = new TLegend(0.6,0.7,0.89, 0.89); leg7->SetFillColor(0); leg7->AddEntry(phiProfileEB1,"EB Projection I set ", "LP"); leg7->AddEntry(phiProfileEB2,"EB Projection II set ", "LP"); leg7->Draw("same"); c[19] = new TCanvas("phiProfileEEp","phiProfileEEp"); c[19]->SetGridx(); c[19]->SetGridy(); phiProfileEEp1->GetXaxis()->SetTitle("#bar{IC}"); phiProfileEEp1->SetLineColor(kBlue); phiProfileEEp1->SetMarkerSize(0.8); phiProfileEEp1->SetLineWidth(2); phiProfileEEp2->SetLineColor(kRed); phiProfileEEp2->SetMarkerSize(0.8); phiProfileEEp2->SetLineWidth(2); phiProfileEEp1->Draw(); phiProfileEEp2->Draw("same"); TLegend * leg8 = new TLegend(0.6,0.7,0.89, 0.89); leg8->SetFillColor(0); leg8->AddEntry(phiProfileEEp1,"EE+ Projection I set ", "LP"); leg8->AddEntry(phiProfileEEp2,"EE+ Projection II set ", "LP"); leg8->Draw("same"); c[20] = new TCanvas("phiProfileEEm","phiProfileEEm"); c[20]->SetGridx(); c[20]->SetGridy(); phiProfileEEm1->GetXaxis()->SetTitle("#bar{IC}"); phiProfileEEm1->SetLineColor(kBlue); phiProfileEEm1->SetMarkerSize(0.8); phiProfileEEm1->SetLineWidth(2); phiProfileEEm2->SetLineColor(kRed); phiProfileEEm2->SetMarkerSize(0.8); phiProfileEEm2->SetLineWidth(2); phiProfileEEm1->Draw(); phiProfileEEm2->Draw("same"); TLegend * leg9 = new TLegend(0.6,0.7,0.89, 0.89); leg9->SetFillColor(0); leg9->AddEntry(phiProfileEEm1,"EE- Projection I set ", "LP"); leg9->AddEntry(phiProfileEEm2,"EE- Projection II set ", "LP"); leg9->Draw("same"); c[21] = new TCanvas("etaProfileEB","etaProfileEB"); c[21]->SetGridx(); c[21]->SetGridy(); etaProfileEB1->GetXaxis()->SetTitle("#bar{IC}"); etaProfileEB1->SetLineColor(kBlue); etaProfileEB1->SetMarkerSize(0.8); etaProfileEB1->SetLineWidth(2); etaProfileEB2->SetLineColor(kRed); etaProfileEB2->SetMarkerSize(0.8); etaProfileEB2->SetLineWidth(2); etaProfileEB1->Draw(); etaProfileEB2->Draw("same"); TLegend * leg10 = new TLegend(0.6,0.7,0.89, 0.89); leg10->SetFillColor(0); leg10->AddEntry(etaProfileEB1,"EB Projection I set ", "LP"); leg10->AddEntry(etaProfileEB2,"EB Projection II set ", "LP"); leg10->Draw("same"); c[22] = new TCanvas("etaProfileEEp","etaProfileEEp"); c[22]->SetGridx(); c[22]->SetGridy(); etaProfileEEp1->GetXaxis()->SetTitle("#bar{IC}"); etaProfileEEp1->SetLineColor(kBlue); etaProfileEEp1->SetMarkerSize(0.8); etaProfileEEp1->SetLineWidth(2); etaProfileEEp2->SetLineColor(kRed); etaProfileEEp2->SetMarkerSize(0.8); etaProfileEEp2->SetLineWidth(2); etaProfileEEp1->Draw(); etaProfileEEp2->Draw("same"); TLegend * leg11 = new TLegend(0.6,0.7,0.89, 0.89); leg11->SetFillColor(0); leg11->AddEntry(phiProfileEEp1,"EE+ Projection I set ", "LP"); leg11->AddEntry(phiProfileEEp2,"EE+ Projection II set ", "LP"); leg11->Draw("same"); c[23] = new TCanvas("etaProfileEEm","etaProfileEEm"); c[23]->SetGridx(); c[23]->SetGridy(); etaProfileEEm1->GetXaxis()->SetTitle("#bar{IC}"); etaProfileEEm1->SetLineColor(kBlue); etaProfileEEm1->SetMarkerSize(0.8); etaProfileEEm1->SetLineWidth(2); etaProfileEEm2->SetLineColor(kRed); etaProfileEEm2->SetMarkerSize(0.8); etaProfileEEm2->SetLineWidth(2); etaProfileEEm1->Draw(); etaProfileEEm2->Draw("same"); TLegend * leg12 = new TLegend(0.6,0.7,0.89, 0.89); leg12->SetFillColor(0); leg12->AddEntry(phiProfileEEm1,"EE- Projection I set ", "LP"); leg12->AddEntry(phiProfileEEm2,"EE- Projection II set ", "LP"); leg12->Draw("same"); theApp->Run(); return 0; }
void combinedFit() { TH1D * hB = new TH1D("hB","histo B",100,0,100); TH1D * hSB = new TH1D("hSB","histo S+B",100, 0,100); TF1 * fB = new TF1("fB","expo",0,100); fB->SetParameters(1,-0.05); hB->FillRandom("fB"); TF1 * fS = new TF1("fS","gaus",0,100); fS->SetParameters(1,30,5); hSB->FillRandom("fB",2000); hSB->FillRandom("fS",1000); // perform now global fit TF1 * fSB = new TF1("fSB","expo + gaus(2)",0,100); ROOT::Math::WrappedMultiTF1 wfB(*fB,1); ROOT::Math::WrappedMultiTF1 wfSB(*fSB,1); ROOT::Fit::DataOptions opt; ROOT::Fit::DataRange rangeB; // set the data range rangeB.SetRange(10,90); ROOT::Fit::BinData dataB(opt,rangeB); ROOT::Fit::FillData(dataB, hB); ROOT::Fit::DataRange rangeSB; rangeSB.SetRange(10,50); ROOT::Fit::BinData dataSB(opt,rangeSB); ROOT::Fit::FillData(dataSB, hSB); ROOT::Fit::Chi2Function chi2_B(dataB, wfB); ROOT::Fit::Chi2Function chi2_SB(dataSB, wfSB); GlobalChi2 globalChi2(chi2_B, chi2_SB); ROOT::Fit::Fitter fitter; const int Npar = 6; double par0[Npar] = { 5,5,-0.1,100, 30,10}; // create before the parameter settings in order to fix or set range on them fitter.Config().SetParamsSettings(6,par0); // fix 5-th parameter fitter.Config().ParSettings(4).Fix(); // set limits on the third and 4-th parameter fitter.Config().ParSettings(2).SetLimits(-10,-1.E-4); fitter.Config().ParSettings(3).SetLimits(0,10000); fitter.Config().ParSettings(3).SetStepSize(5); fitter.Config().MinimizerOptions().SetPrintLevel(0); fitter.Config().SetMinimizer("Minuit2","Migrad"); // fit FCN function directly // (specify optionally data size and flag to indicate that is a chi2 fit) fitter.FitFCN(6,globalChi2,0,dataB.Size()+dataSB.Size(),true); ROOT::Fit::FitResult result = fitter.Result(); result.Print(std::cout); TCanvas * c1 = new TCanvas("Simfit","Simultaneous fit of two histograms", 10,10,700,700); c1->Divide(1,2); c1->cd(1); gStyle->SetOptFit(1111); fB->SetFitResult( result, iparB); fB->SetRange(rangeB().first, rangeB().second); fB->SetLineColor(kBlue); hB->GetListOfFunctions()->Add(fB); hB->Draw(); c1->cd(2); fSB->SetFitResult( result, iparSB); fSB->SetRange(rangeSB().first, rangeSB().second); fSB->SetLineColor(kRed); hSB->GetListOfFunctions()->Add(fSB); hSB->Draw(); }
TF1* fit(TH1D* h, TH1D* hMCSignal, TH1D* hMCSwapped, Float_t ptmin, Float_t ptmax, Int_t j) { TCanvas* c = new TCanvas(Form("c_%.0f_%.0f_%d",ptmin,ptmax,j),"",600,600); TF1* f = new TF1(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.14159)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.14159)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.14159)*[8]*(1+[11])))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.5); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); f->FixParameter(11,0); h->GetEntries(); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); /* f->ReleaseParameter(11); f->SetParLimits(11,-1.,1.); */ h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f_%d",ptmin,ptmax,j),"L m","",minhisto,maxhisto); TF1* background = new TF1(Form("background_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("mass_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.14159)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.14159)*[5]*(1+[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(11)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("massSwap_%.0f_%.0f_%d",ptmin,ptmax,j),"[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.14159)*[3]*(1+[4]))"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8),f->GetParameter(11)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); DrawCmsTlatex("PbPb"); TLatex* tex; tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); TString texper="%"; tex = new TLatex(0.22,0.72,Form("Centrality %.0f-%.0f%s",centMin,centMax,texper.Data())); tex->SetNDC(); tex->SetTextColor(1); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); tex->Draw(); c->SaveAs(Form("plots/Mass_cent_%.0f_%.0f_pt_%.0f_%.0f_%s.pdf",centMin,centMax,ptmin,ptmax,tfend[j].Data())); return mass; }
TF1* fit(TString variable, TString variableplot, TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax, int isMC) { static int count=0; count++; TCanvas* c= new TCanvas(Form("c%d",count),"",600,600); TH1D* h = new TH1D(Form("h-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TH1D* hMCSignal = new TH1D(Form("hMCSignal-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TH1D* hMCSwapped = new TH1D(Form("hMCSwapped-%d",count),"",nbinsmasshisto,minhisto,maxhisto); TF1* f = new TF1(Form("f%d",count),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); TString mycut=Form("(%s&&(%s)>%f&&(%s)<%f)",seldata.Data(),variable.Data(),ptmin,variable.Data(),ptmax); if(isMC==1) nt->Project(Form("h-%d",count),"Dmass",TCut(weight)*TCut(mycut)); else nt->Project(Form("h-%d",count),"Dmass",Form("(%s&&(%s)>%f&&(%s)<%f)",seldata.Data(),variable.Data(),ptmin,variable.Data(),ptmax)); ntMC->Project(Form("hMCSignal-%d",count),"Dmass",Form("%s*(%s&&(%s)>%f&&(%s)<%f&&(Dgen==23333))",weight.Data(),selmc.Data(),variable.Data(),ptmin,variable.Data(),ptmax)); ntMC->Project(Form("hMCSwapped-%d",count),"Dmass",Form("%s*(%s&&(%s)>%f&&(%s)<%f&&(Dgen==23344))",weight.Data(),selmc.Data(),variable.Data(),ptmin,variable.Data(),ptmax)); TFile *fout=new TFile(Form("FitsFiles/Fits_%s_%d.root",collisionsystem.Data(),count),"recreate"); fout->cd(); hMCSignal->Write(); hMCSwapped->Write(); h->Write(); fout->Close(); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); h->GetEntries(); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); TF1* background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass%d",count),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap%d",count),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<"and error"<<yieldErr<<std::endl; std::cout<<"relative error="<<yieldErr/yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.04); Tl.SetTextFont(42); Tl.DrawLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); Tl.DrawLatex(0.65,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TLatex* tex; tex = new TLatex(0.22,0.78,Form("%.1f < %s < %.1f",ptmin,variableplot.Data(),ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); h->GetFunction(Form("f%d",count))->Delete(); TH1F* histo_copy_nofitfun = ( TH1F * ) h->Clone("histo_copy_nofitfun"); histo_copy_nofitfun->Draw("esame"); // if(nBins==1) c->SaveAs(Form("DMass-inclusive%s_%d.pdf",collisionsystem.Data(),count)); else c->SaveAs(Form("DMass%s_%d.pdf",collisionsystem.Data(),count)); return mass; }
void DrawCalibrationPlotsEB( Char_t* infile1 = "/data1/rgerosa/L3_Weight/PromptSkim_Single_Double_Electron_recoFlag/EB/WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_noEP.root", Char_t* infile2 = "/data1/rgerosa/L3_Weight/PromptSkim_Single_Double_Electron_recoFlag/EB/Even_WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_noEP.root", Char_t* infile3 = "/data1/rgerosa/L3_Weight/PromptSkim_Single_Double_Electron_recoFlag/EB/Odd_WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_noEP.root", int evalStat = 0, Char_t* fileType = "png", Char_t* dirName = ".") { bool printPlots = false; // by TT int nbins = 500; // by xtal //int nbins = 500; // Set style options gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetOptTitle(0); gStyle->SetOptStat(1110); gStyle->SetOptFit(0); gStyle->SetFitFormat("6.3g"); gStyle->SetPalette(1); gStyle->SetTextFont(42); gStyle->SetTextSize(0.05); gStyle->SetTitleFont(42,"xyz"); gStyle->SetTitleSize(0.05); gStyle->SetLabelFont(42,"xyz"); gStyle->SetLabelSize(0.05); gStyle->SetTitleXOffset(0.8); gStyle->SetTitleYOffset(1.1); gROOT->ForceStyle(); if ( !infile1 ) { cout << " No input file specified !" << endl; return; } if ( evalStat && (!infile2 || !infile3 )){ cout << " No input files to evaluate statistical precision specified !" << endl; return; } cout << "Making calibration plots for: " << infile1 << endl; TFile *f = new TFile(infile1); TH2F *h_scale_EB = (TH2F*)f->Get("h_scale_EB"); TH2F *hcmap = (TH2F*) h_scale_EB->Clone("hcmap"); hcmap -> Reset("ICEMS"); // Mean over phi for (int iEta = 1 ; iEta < h_scale_EB->GetNbinsY()+1 ; iEta ++) { float SumIC = 0; int numIC = 0; for(int iPhi = 1 ; iPhi < h_scale_EB->GetNbinsX()+1 ; iPhi++) { if( h_scale_EB->GetBinContent(iPhi,iEta) !=0) { SumIC = SumIC + h_scale_EB->GetBinContent(iPhi,iEta); numIC ++ ; } } for (int iPhi = 1; iPhi< h_scale_EB->GetNbinsX()+1 ; iPhi++) { if(numIC!=0 && SumIC!=0) hcmap->SetBinContent(iPhi,iEta,h_scale_EB->GetBinContent(iPhi,iEta)/(SumIC/numIC)); } } //----------------------------------------------------------------- //--- Build the precision vs ieta plot starting from the TH2F of IC //----------------------------------------------------------------- TH1F *hoccall = new TH1F("hoccall", "hoccall", 1000,0.,1000.); for (int jbin = 1; jbin < h_occupancy-> GetNbinsY()+1; jbin++){ for (int ibin = 1; ibin < h_occupancy-> GetNbinsX()+1; ibin++){ float ic = h_occupancy->GetBinContent(ibin,jbin); hoccall->Fill(ic); } } TH1F *hspreadall = new TH1F("hspreadall", "hspreadall", 800,0.,2.); for (int jbin = 1; jbin < hcmap-> GetNbinsY()+1; jbin++){ for (int ibin = 1; ibin < hcmap-> GetNbinsX()+1; ibin++){ float ic = hcmap->GetBinContent(ibin,jbin); if (ic>0 && ic<2 && ic !=1) { hspreadall->Fill(ic); } } } TH1F *hspread[172]; char hname[100]; char htitle[100]; for (int jbin = 1; jbin < hcmap-> GetNbinsY()+1; jbin++){ //float etaring = hcmap-> GetYaxis()->GetBinLowEdge(jbin); float etaring = hcmap-> GetYaxis()->GetBinCenter(jbin); sprintf(hname,"hspread_ring_ieta%02d",etaring); hspread[jbin-1]= new TH1F(hname, hname, nbins/2,0.5,1.5); for (int ibin = 1; ibin < hcmap-> GetNbinsX()+1; ibin++){ float ic = hcmap->GetBinContent(ibin,jbin); if (ic>0 && ic<2 && ic!=1) { hspread[jbin-1]->Fill(ic); } } } TGraphErrors *sigma_vs_ieta = new TGraphErrors(); sigma_vs_ieta->SetMarkerStyle(20); sigma_vs_ieta->SetMarkerSize(1); sigma_vs_ieta->SetMarkerColor(kBlue+2); TGraphErrors *scale_vs_ieta = new TGraphErrors(); scale_vs_ieta->SetMarkerStyle(20); scale_vs_ieta->SetMarkerSize(1); scale_vs_ieta->SetMarkerColor(kBlue+2); TF1 *fgaus = new TF1("fgaus","gaus",-10,10); int np = 0; for (int i = 1; i < hcmap-> GetNbinsY()+1; i++){ float etaring = hcmap-> GetYaxis()->GetBinCenter(i); //float etaring = hcmap-> GetYaxis()->GetBinLowEdge(i); if (int(etaring)==0) continue; if (hspread[i-1]-> GetEntries() == 0) continue; if (fabs(etaring) > 60) hspread[i-1]->Rebin(2); float e = 0.5*hcmap-> GetYaxis()->GetBinWidth(i); fgaus->SetParameter(1,1); fgaus->SetParameter(2,hspread[i-1]->GetRMS()); fgaus->SetRange(1-5*hspread[i-1]->GetRMS(),1+5*hspread[i-1]->GetRMS()); hspread[i-1]->Fit("fgaus","QR"); sigma_vs_ieta-> SetPoint(np,etaring,fgaus->GetParameter(2)/fgaus->GetParameter(1)); //cout << etaring << " " << fgaus->GetParameter(2)/fgaus->GetParameter(1) << endl; sigma_vs_ieta-> SetPointError(np, e ,fgaus->GetParError(2)/fgaus->GetParameter(1)); scale_vs_ieta-> SetPoint(np,etaring,fgaus->GetParameter(1)); scale_vs_ieta-> SetPointError(np,e,fgaus->GetParError(1)); np++; } if (evalStat){ TFile *f2 = new TFile(infile2); TH2F *h_scale_EB_2 = (TH2F*)f2->Get("h_scale_EB"); TH2F *hcmap2 = (TH2F*) h_scale_EB->Clone("hcmap2"); hcmap2 -> Reset("ICEMS"); // Mean over phi for (int iEta = 1 ; iEta < h_scale_EB_2->GetNbinsY()+1 ; iEta ++) { float SumIC = 0; int numIC = 0; for(int iPhi = 1 ; iPhi < h_scale_EB_2->GetNbinsX()+1 ; iPhi++) { if( h_scale_EB_2->GetBinContent(iPhi,iEta) !=0) { SumIC = SumIC + h_scale_EB_2->GetBinContent(iPhi,iEta); numIC ++ ; } } for (int iPhi = 1; iPhi< h_scale_EB_2->GetNbinsX()+1 ; iPhi++) { if(numIC!=0 && SumIC!=0) hcmap2->SetBinContent(iPhi,iEta,h_scale_EB_2->GetBinContent(iPhi,iEta)/(SumIC/numIC)); } } TFile *f3 = new TFile(infile3); TH2F *h_scale_EB_3 = (TH2F*)f3->Get("h_scale_EB"); TH2F *hcmap3 = (TH2F*) h_scale_EB->Clone("hcmap3"); hcmap3 -> Reset("ICEMS"); // Mean over phi for (int iEta = 1 ; iEta < h_scale_EB_3->GetNbinsY()+1 ; iEta ++) { float SumIC = 0; int numIC = 0; for(int iPhi = 1 ; iPhi < h_scale_EB_3->GetNbinsX()+1 ; iPhi++) { if( h_scale_EB_3->GetBinContent(iPhi,iEta) !=0) { SumIC = SumIC + h_scale_EB_3->GetBinContent(iPhi,iEta); numIC ++ ; } } for (int iPhi = 1; iPhi< h_scale_EB_3->GetNbinsX()+1 ; iPhi++) { if(numIC!=0 && SumIC!=0) hcmap3->SetBinContent(iPhi,iEta,h_scale_EB_3->GetBinContent(iPhi,iEta)/(SumIC/numIC)); } } TH1F *hstatprecision[171]; for (int jbin = 1; jbin < hcmap2-> GetNbinsY()+1; jbin++){ //int etaring = -85+(jbin-1); float etaring = hcmap2-> GetYaxis()->GetBinCenter(jbin); sprintf(hname,"hstatprecision_ring_ieta%02d",etaring); hstatprecision[jbin-1] = new TH1F(hname, hname, nbins,-0.5,0.5); for (int ibin = 1; ibin < hcmap2-> GetNbinsX()+1; ibin++){ float ic1 = hcmap2->GetBinContent(ibin,jbin); float ic2 = hcmap3->GetBinContent(ibin,jbin); if (ic1>0 && ic1<2 && ic1!=1 && ic2>0 && ic2 <2 && ic2!=1){ hstatprecision[jbin-1]->Fill((ic1-ic2)/(ic1+ic2)); // sigma (diff/sum) gives the stat. precision on teh entire sample } } } TGraphErrors *statprecision_vs_ieta = new TGraphErrors(); statprecision_vs_ieta->SetMarkerStyle(20); statprecision_vs_ieta->SetMarkerSize(1); statprecision_vs_ieta->SetMarkerColor(kRed+2); int n = 0; for (int i = 1; i < hcmap2-> GetNbinsY()+1; i++){ etaring = hcmap2-> GetYaxis()->GetBinCenter(i); //etaring = hcmap2-> GetYaxis()->GetBinLowEdge(i); if (etaring==0) continue; if ( hstatprecision[i-1]->GetEntries() == 0) continue; if (fabs(etaring) > 60)hstatprecision[i-1]->Rebin(2); float e = 0.5*hcmap2-> GetYaxis()->GetBinWidth(i); fgaus->SetParameter(1,1); fgaus->SetParameter(2,hstatprecision[i-1]->GetRMS()); fgaus->SetRange(-5*hstatprecision[i-1]->GetRMS(),5*hstatprecision[i-1]->GetRMS()); hstatprecision[i-1]->Fit("fgaus","QR"); statprecision_vs_ieta-> SetPoint(n,etaring,fgaus->GetParameter(2)); statprecision_vs_ieta-> SetPointError(n,e,fgaus->GetParError(2)); n++; } TGraphErrors *residual_vs_ieta = new TGraphErrors(); residual_vs_ieta->SetMarkerStyle(20); residual_vs_ieta->SetMarkerSize(1); residual_vs_ieta->SetMarkerColor(kGreen+2); for (int i= 0; i < statprecision_vs_ieta-> GetN(); i++){ double spread, espread; double stat, estat; double residual, eresidual; double xdummy,ex; sigma_vs_ieta-> GetPoint(i, xdummy, spread ); espread = sigma_vs_ieta-> GetErrorY(i); statprecision_vs_ieta-> GetPoint(i, xdummy, stat ); estat = statprecision_vs_ieta-> GetErrorY(i); ex = statprecision_vs_ieta-> GetErrorX(i); if (spread > stat ){ residual = sqrt( spread*spread - stat*stat ); eresidual = sqrt( pow(spread*espread,2) + pow(stat*estat,2))/residual; } else { residual = 0; eresidual = 0; } cout << residual << " " << eresidual << endl; residual_vs_ieta->SetPoint(i,xdummy, residual); residual_vs_ieta->SetPointError(i,ex,eresidual); } } //------------------------------------------------------------------------ //----------------------------------------------------------------- //--- Draw plots //----------------------------------------------------------------- TCanvas *c[10]; // --- plot 0 : map of coefficients c[0] = new TCanvas("cmap","cmap"); c[0] -> cd(); c[0]->SetLeftMargin(0.1); c[0]->SetRightMargin(0.13); c[0]->SetGridx(); hcmap->GetXaxis()->SetNdivisions(1020); hcmap->GetXaxis() -> SetLabelSize(0.03); hcmap->Draw("COLZ"); hcmap->GetXaxis() ->SetTitle("i#phi"); hcmap->GetYaxis() ->SetTitle("i#eta"); hcmap->GetZaxis() ->SetRangeUser(0.9,1.1); c[7] = new TCanvas("cmap2","cmap2"); c[7] -> cd(); c[7]->SetLeftMargin(0.1); c[7]->SetRightMargin(0.13); c[7]->SetGridx(); h_scale_EB->GetXaxis()->SetNdivisions(1020); h_scale_EB->GetXaxis() -> SetLabelSize(0.03); h_scale_EB->Draw("COLZ"); h_scale_EB->GetXaxis() ->SetTitle("i#phi"); h_scale_EB->GetYaxis() ->SetTitle("i#eta"); h_scale_EB->GetZaxis() ->SetRangeUser(0.9,1.1); // --- plot 1 : ring precision vs ieta c[1] = new TCanvas("csigma","csigma"); c[1]->SetGridx(); c[1]->SetGridy(); sigma_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.00,0.10); sigma_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); sigma_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("#sigma_{c}"); sigma_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); sigma_vs_ieta->Draw("ap"); if (evalStat){ statprecision_vs_ieta->Draw("psame"); sigma_vs_ieta->Draw("psame"); TLegend * leg = new TLegend(0.6,0.7,0.89, 0.89); leg->SetFillColor(0); leg->AddEntry(statprecision_vs_ieta,"statistical precision", "LP"); leg->AddEntry(sigma_vs_ieta,"spread", "LP"); leg->Draw("same"); } // --- plot 2 : scale vs ieta c[2] = new TCanvas("c_scale_vs_ieta","c_scale_vs_ieta"); c[2]->SetGridx(); c[2]->SetGridy(); scale_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.95,1.05); scale_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); scale_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("scale"); scale_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); scale_vs_ieta->Draw("ap"); // --- plot 3 : spread all coefficients c[3] = new TCanvas("cspread","cspread",500,500); hspreadall->SetFillStyle(3004); hspreadall->SetFillColor(kGreen+2); hspreadall->GetXaxis()-> SetRangeUser(0.8,1.2); hspreadall->GetXaxis()-> SetTitle("c"); hspreadall->Draw("hs"); gPad->Update(); TPaveStats *s_spread = (TPaveStats*)(hspreadall->GetListOfFunctions()->FindObject("stats")); s_spread -> SetX1NDC(0.55); //new x start position s_spread -> SetX2NDC(0.85); //new x end position s_spread -> SetY1NDC(0.750); //new x start position s_spread -> SetY2NDC(0.85); //new x end position s_spread -> SetOptStat(1110); s_spread -> SetTextColor(kGreen+2); s_spread -> SetTextSize(0.03); s_spread -> Draw("sames"); //--- plot 4 : occupancy map c[4] = new TCanvas("cOcc","cOcc"); c[4]->SetLeftMargin(0.1); c[4]->SetRightMargin(0.13); c[4]-> cd(); c[4]->SetGridx(); h_occupancy->GetXaxis()->SetNdivisions(1020); h_occupancy->GetXaxis() -> SetLabelSize(0.03); h_occupancy->Draw("COLZ"); h_occupancy->GetXaxis() ->SetTitle("i#phi"); h_occupancy->GetYaxis() ->SetTitle("i#eta"); // --- plot 5 : statistical precision vs ieta if (evalStat){ c[5] = new TCanvas("cstat","cstat"); c[5]->SetGridx(); c[5]->SetGridy(); statprecision_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.10); statprecision_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); statprecision_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("#sigma((c_{P}-c_{D})/(c_{P}+c_{D}))"); statprecision_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); statprecision_vs_ieta->Draw("ap"); // TF1 *fp = new TF1("fp","pol0"); // fp->SetRange(-40,40); // statprecision_vs_ieta->Fit("fp","QRN"); // float stat = fp->GetParameter(0); // float estat = fp->GetParError(0); // cout << "Statistical precision in |ieta| < 40 --> " << stat << " +/- " << estat << endl; // sigma_vs_ieta->Fit("fp","QRN"); // float spread = fp->GetParameter(0); // float espread = fp->GetParError(0); // cout << "Spread in |ieta| < 40 --> " << spread << " +/- " << espread << endl; // float residual = sqrt( spread*spread - stat*stat ); // float eresidual = sqrt( pow(spread*espread,2) + pow(stat*estat,2))/residual; // cout << "Residual miscalibration : " << residual << " +/- " << eresidual << endl; c[6] = new TCanvas("cresidual","cresidual"); c[6]->SetGridx(); c[6]->SetGridy(); residual_vs_ieta->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.05); residual_vs_ieta->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); residual_vs_ieta->GetHistogram()->GetYaxis()-> SetTitle("residual spread"); residual_vs_ieta->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); residual_vs_ieta->Draw("ap"); } //----------------------------------------------------------------- //--- Print plots //----------------------------------------------------------------- if (printPlots){ //gStyle->SetOptStat(1110); c[0]->Print("IC_map.png",fileType); c[1]->Print("IC_precision_vs_ieta.png",fileType); c[2]->Print("IC_scale_vs_ieta.png",fileType); c[3]->Print("IC_spread.png",fileType); c[4]->Print("occupancy_map.png",fileType); } }
double extractLimitAtQuantile(TString inFileName, TString plotName, double d_quantile ){ TFile *f = TFile::Open(inFileName); TF1 *expoFit = new TF1("expoFit","[0]*exp([1]*(x-[2]))", rMin, rMax); TGraphErrors *limitPlot_ = new TGraphErrors(); /* bool done = false; */ if (_debug > 0) std::cout << "Search for upper limit using pre-computed grid of p-values" << std::endl; readAllToysFromFile(limitPlot_, f, d_quantile ); f->Close(); limitPlot_->Sort(); double minDist=1e3; int n= limitPlot_->GetN(); cout<<" Number of points in limitPlot_ : "<<n<<endl; if(n<=0) return 0; clsMin.first=0; clsMin.second=0; clsMax.first=0; clsMax.second=0; limit = 0; limitErr = 0; for (int i = 0; i < n; ++i) { double x = limitPlot_->GetX()[i], y = limitPlot_->GetY()[i]; //, ey = limitPlot_->GetErrorY(i); if (fabs(y-clsTarget) < minDist) { limit = x; minDist = fabs(y-clsTarget); } } int ntmp =0; for (int j = 0; j < n; ++j) { int i = n-j-1; double x = limitPlot_->GetX()[i], y = limitPlot_->GetY()[i], ey = limitPlot_->GetErrorY(i); if (y-3*ey >= clsTarget && ntmp<=2) { rMin = x; clsMin = CLs_t(y,ey); ntmp ++ ; } } ntmp =0; for (int i = 0; i < n; ++i) { double x = limitPlot_->GetX()[i], y = limitPlot_->GetY()[i], ey = limitPlot_->GetErrorY(i); if (y+3*ey <= clsTarget && ntmp<=2) { rMax = x; clsMax = CLs_t(y,ey); ntmp ++ ; } } if((clsMin.first==0 and clsMin.second==0) ) { rMin = limitPlot_->GetX()[0]; clsMin=CLs_t(limitPlot_->GetY()[0], limitPlot_->GetErrorY(0)); } if((clsMax.first==0 and clsMax.second==0)) { rMax = limitPlot_->GetX()[n-1]; clsMax=CLs_t(limitPlot_->GetY()[n-1], limitPlot_->GetErrorY(n-1)); } if (_debug > 0) std::cout << " after scan x ~ " << limit << ", bounds [ " << rMin << ", " << rMax << "]" << std::endl; limitErr = std::max(limit-rMin, rMax-limit); expoFit->SetRange(rMin,rMax); //expoFit.SetRange(limitPlot_->GetXaxis()->GetXmin(),limitPlot_->GetXaxis()->GetXmax()); //expoFit->SetRange(1.7,2.25); if (limitErr < std::max(rAbsAccuracy_, rRelAccuracy_ * limit)) { if (_debug > 1) std::cout << " reached accuracy " << limitErr << " below " << std::max(rAbsAccuracy_, rRelAccuracy_ * limit) << std::endl; /* done = true; */ } //if (!done) { // didn't reach accuracy with scan, now do fit if (1) { // didn't reach accuracy with scan, now do fit if (_debug) { std::cout << "\n -- HybridNew, before fit -- \n"; std::cout << "Limit: r" << " < " << limit << " +/- " << limitErr << " [" << rMin << ", " << rMax << "]\n"; std::cout<<"rMin="<<rMin<<" clsMin="<<clsMin.first<<", rMax="<<rMax<<" clsMax="<<clsMax.first<<endl; } expoFit->FixParameter(0,clsTarget); expoFit->SetParameter(1,log(clsMax.first/clsMin.first)/(rMax-rMin)); expoFit->SetParameter(2,limit); double rMinBound, rMaxBound; expoFit->GetRange(rMinBound, rMaxBound); limitErr = std::max(fabs(rMinBound-limit), fabs(rMaxBound-limit)); int npoints = 0; for (int j = 0; j < limitPlot_->GetN(); ++j) { if (limitPlot_->GetX()[j] >= rMinBound && limitPlot_->GetX()[j] <= rMaxBound) npoints++; } for (int i = 0, imax = 0; i <= imax; ++i, ++npoints) { limitPlot_->Sort(); limitPlot_->Fit(expoFit,(_debug <= 1 ? "QNR EX0" : "NR EXO")); if (_debug) { std::cout << "Fit to " << npoints << " points: " << expoFit->GetParameter(2) << " +/- " << expoFit->GetParError(2) << std::endl; } // only when both "cls+3e<0.05 and cls-3e>0.05" are satisfied, we require below ... // if ((rMin < expoFit->GetParameter(2)) && (expoFit->GetParameter(2) < rMax) && (expoFit->GetParError(2) < 0.5*(rMaxBound-rMinBound))) { // sanity check fit result limit = expoFit->GetParameter(2); limitErr = expoFit->GetParError(2); if (limitErr < std::max(rAbsAccuracy_, rRelAccuracy_ * limit)) break; // } } } if (limitPlot_) { TCanvas *c1 = new TCanvas("c1","c1"); limitPlot_->Sort(); limitPlot_->SetLineWidth(2); double rMinBound, rMaxBound; expoFit->GetRange(rMinBound, rMaxBound); if(bPlotInFittedRange){ limitPlot_->GetXaxis()->SetRangeUser(rMinBound, rMaxBound); limitPlot_->GetYaxis()->SetRangeUser(0.5*clsTarget, 1.5*clsTarget); } limitPlot_->Draw("AP"); expoFit->Draw("SAME"); TLine line(limitPlot_->GetX()[0], clsTarget, limitPlot_->GetX()[limitPlot_->GetN()-1], clsTarget); line.SetLineColor(kRed); line.SetLineWidth(2); line.Draw(); line.DrawLine(limit, 0, limit, limitPlot_->GetY()[0]); line.SetLineWidth(1); line.SetLineStyle(2); line.DrawLine(limit-limitErr, 0, limit-limitErr, limitPlot_->GetY()[0]); line.DrawLine(limit+limitErr, 0, limit+limitErr, limitPlot_->GetY()[0]); limitPlot_->SetTitle(";#mu;CLs"); c1->Print(plotName+".gif"); c1->Print(plotName+".root"); if(_debug)limitPlot_->Print("v"); } std::cout << "\n -- Hybrid New -- \n"; if(limit<0) { limit=0; cout<<" WARNING: fitted limit <0, need more toys and more points of signal strength"<<endl; } std::cout << "Limit: r" << " < " << limit << " +/- " << limitErr << " @ " << (1-clsTarget) * 100 << "% CL\n"; return limit; }
void draw_clouds_profiles() { // gROOT->ProcessLine(".L ../utils.C"); // gROOT->ProcessLine(".L AliLRCFit.cxx"); TFile *f[8]; // f[0] = new TFile( "output_classesByV0M_LHC10h.root" ); // f[0] = new TFile( "output_classesByV0M_LHC10h_c10_5_1.root" ); f[0] = new TFile( "output_classesByV0M_LHC10h_c10_5_25_1_05.root" ); // f[0] = new TFile( "output_classesByV0M_LHC11h_FemtoPlus_c10_5_CUT_OUTLIERS.root" ); // f[0] = new TFile( "output_classesByV0M_LHC15o_fieldMM_c10_5_CUT_OUTLIERS.root" ); // f[0] = new TFile( "output_classesByV0M_LHC15o_fieldPP_c10_5_CUT_OUTLIERS.root" ); // const int nCW = 2; //nCentrWidths // const double cWidths[nCW] = { 10, 5 }; //width of the centrality bins // const double cStep[nCW] = { 5, 2.5 }; //centrality bins step // const int nCentrBins[nCW] = { 17, 35 }; //n centrality bins // const int nCW = 3; //nCentrWidths // const double cWidths[nCW] = { 10, 5, 1.0 }; //width of the centrality bins // const double cStep[nCW] = { 5, 2.5, 1.0 }; //centrality bins step // const int nCentrBins[nCW] = { 17, 35, 90 }; //n centrality bins // const int nCW = 4; //nCentrWidths // const double cWidths[nCW] = { 10, 5, 1.0, 0.5 }; //width of the centrality bins // const double cStep[nCW] = { 5, 2.5, 1.0, 1.0 }; //centrality bins step // const int nCentrBins[nCW] = { 17, 35, 90, 90 }; //n centrality bins const int nCW = 5; //nCentrWidths const double cWidths[nCW] = { 10, 5, 2.5, 1.0, 0.5 }; //width of the centrality bins const double cStep[nCW] = { 5, 2.5, 2.5, 1.0, 1.0 }; //centrality bins step const int nCentrBins[nCW] = { 17, 35, 36, 90, 90 }; //n centrality bins TH2D *hist2D;//[200][3]; TProfile *profile;//[200][3]; int cW = 2; int etaW = 1; int phiW = 0; const int kCorrType = 1; //0-NN, 1-PtPt, 2-PtN TCanvas *canv_tmp_for_fit = new TCanvas("canv_tmp_for_fit","canv_tmp_for_fit",50,50,300,300 ); TCanvas *canv_2D_clouds = new TCanvas("canv_2D_clouds","canv_2D_clouds",150,250,1400,600 ); tuneCanvas(canv_2D_clouds); canv_2D_clouds->Divide(2,1); gStyle->SetOptStat( kFALSE ); TGraph *grFromFit2D = new TGraph; bool firstDraw = true; // for ( int cBin = 0; cBin < nCentrBins[cW]; cBin++ ) for ( int cBin = nCentrBins[cW]-1; cBin >= 0; cBin-- ) { if (cBin%2!=0) continue; // cout << "cBin=" << cBin << endl; float cBinMin = cStep[cW] * cBin; float cBinMax = cWidths[cW] + cStep[cW] * cBin; // ##### pad 1 - clouds tunePad( canv_2D_clouds->cd(1) ); if ( kCorrType == 0 ) { hist2D = (TH2D*)f[0]->Get( Form("hist2D_NN_c%.1f-%.1f_etaW_%d_phiW_%d", cBinMin, cBinMax, etaW, phiW) ); hist2D->SetTitle( ""); hist2D->GetXaxis()->SetTitle( "N_{ch} Forward"); hist2D->GetYaxis()->SetTitle( "N_{ch} Backward"); hist2D->GetXaxis()->SetRangeUser(0,650); hist2D->GetYaxis()->SetRangeUser(0,650); } else if ( kCorrType == 1 ) { hist2D = (TH2D*)f[0]->Get( Form("hist2D_PtPt_c%.1f-%.1f_etaW_%d_phiW_%d", cBinMin, cBinMax, etaW, phiW) ); hist2D->SetTitle( ""); hist2D->GetXaxis()->SetTitle( "#LTp_{T}#GT Forward"); hist2D->GetYaxis()->SetTitle( "#LTp_{T}#GT Backward"); } hist2D->SetMarkerColor(kOrange-9+cBin); tuneHist2D_onPad(hist2D); hist2D->GetXaxis()->CenterTitle(); hist2D->GetYaxis()->CenterTitle(); // removeBinsWithFewEntries(hist2D); hist2D->DrawCopy( firstDraw ? "" : "same" ); // ##### pad 2 - profiles tunePad( canv_2D_clouds->cd(2) ); profile = hist2D->ProfileX(); //(TProfile*)f[0]->Get( Form("hist2D_c%.1f-%.1f_etaW_%d_phiW_%d_pfx", cBinMin, cBinMax, etaW, phiW) ); if ( kCorrType == 0 ) { profile->SetTitle( ""); profile->GetYaxis()->SetTitle( "#LTN_{ch}#GT Backward"); profile->GetXaxis()->SetRangeUser(0,650); profile->GetYaxis()->SetRangeUser(0,650); } else if ( kCorrType == 1 ) { profile->SetTitle( ""); profile->GetYaxis()->SetTitle( "#LT#LTp_{T}#GT#GT Backward"); } profile->SetLineColor(kOrange-9+cBin); profile->SetMarkerStyle(7); tuneProfile_onPad( profile ); profile->GetYaxis()->CenterTitle(); deleteProfileEmptyBinErrors(profile); canv_tmp_for_fit->cd(); profile->Fit("pol1","Q");//,"",0.25,1.2);//,"N"); canv_2D_clouds->cd(2); TF1 *fit = profile->GetFunction("pol1"); Double_t p0 = fit->GetParameter(0); Double_t p1 = fit->GetParameter(1); grFromFit2D->SetPoint(grFromFit2D->GetN(), (cBinMax+cBinMin)/2, p1); double meanX = hist2D->ProjectionX()->GetMean(); double rmsX = hist2D->ProjectionX()->GetRMS(); fit->SetRange( meanX-3*rmsX, meanX+3*rmsX ); fit->SetLineColorAlpha( kRed, 0.6 ); fit->Draw("same"); profile->DrawCopy( firstDraw ? "" : "same" ); firstDraw = false; } TGraphErrors *grByFormula; /*[cW][etaW]*/ if ( kCorrType == 0 ) { grByFormula = (TGraphErrors*)f[0]->Get( Form( "grNN_c%d_eta%d", cW, etaW ) ); } else if ( kCorrType == 1 ) { grByFormula = (TGraphErrors*)f[0]->Get( Form( "grPtPt_c%d_eta%d", cW, etaW ) ); } TCanvas *canv_GrCoeff = new TCanvas("canv_GrCoeff","canv_GrCoeff",20,150,900,700 ); grByFormula->Draw("APL"); grFromFit2D->SetLineColor(kRed); grFromFit2D->DrawClone("PL"); return; TGraphErrors *gr[10][10]; for ( int cW = 0; cW < 2; cW++ ) for ( int etaW = 0; etaW < 3; etaW++ ) gr[cW][etaW] = (TGraphErrors*)f[0]->Get( Form( "grPtPt_c%d_eta%d", cW, etaW ) ); drawGraph( gr[1][0], 24, kBlack, "APL" ); drawGraph( gr[0][0], 20, kBlack, "PL" ); // drawGraph( gr[1][1], 24, kBlue, "PL" ); // drawGraph( gr[0][1], 20, kBlue, "PL" ); // drawGraph( gr[1][2], 24, kGreen, "PL" ); // drawGraph( gr[0][2], 20, kGreen, "PL" ); //// drawGraph( gr[6], 24, kRed, "PL" ); // drawGraph( gr[7], 20, kRed, "PL" ); f[1] = new TFile( "output_histos_graphs_LHC15o_fieldMM.root" ); TGraphErrors *grMM[10][10]; for ( int cW = 0; cW < 2; cW++ ) for ( int etaW = 0; etaW < 3; etaW++ ) grMM[cW][etaW] = (TGraphErrors*)f[1]->Get( Form( "grPtPt_c%d_eta%d", cW, etaW ) ); drawGraph( grMM[1][0], 24, kGreen, "PL" ); drawGraph( grMM[0][0], 20, kGreen, "PL" ); // drawGraph( grMM[1][1], 24, kRed, "PL" ); // drawGraph( grMM[0][1], 20, kRed, "PL" ); // drawGraph( grMM[1][2], 24, kGreen, "PL" ); // drawGraph( grMM[0][2], 20, kGreen, "PL" ); // gROOT->ProcessLine( ".q"); }
TF1* fit(Double_t ptmin, Double_t ptmax) { TCanvas* c = new TCanvas(Form("c_%.0f_%.0f",ptmin,ptmax),"",600,600); TFile* infile = new TFile(Form("%s_%s_%.0f_%.0f.root",infname.Data(),collisionsystem.Data(),ptmin,ptmax)); TH1D* h = (TH1D*)infile->Get("h"); h->SetName(Form("h_%.0f_%.0f",ptmin,ptmax)); TH1D* hMCSignal = (TH1D*)infile->Get("hMCSignal"); hMCSignal->SetName(Form("hMCSignal_%.0f_%.0f",ptmin,ptmax)); TH1D* hMCSwapped = (TH1D*)infile->Get("hMCSwapped"); hMCSwapped->SetName(Form("hMCSwapped_%.0f_%.0f",ptmin,ptmax)); TF1* f = new TF1(Form("f_%.0f_%.0f",ptmin,ptmax),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); h->GetEntries(); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->SetLineColor(kRed); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"q","",minhisto,maxhisto); f->ReleaseParameter(1); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L q","",minhisto,maxhisto); h->Fit(Form("f_%.0f_%.0f",ptmin,ptmax),"L m","",minhisto,maxhisto); TF1* background = new TF1(Form("background_%.0f_%.0f",ptmin,ptmax),"[0]+[1]*x+[2]*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass_%.0f_%.0f",ptmin,ptmax),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap_%.0f_%.0f",ptmin,ptmax),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"YIELD="<<yield<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary"); texCms->SetNDC(); texCms->SetTextAlign(12); texCms->SetTextSize(0.04); texCms->SetTextFont(42); texCms->Draw(); TLatex* texCol = new TLatex(0.96,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); texCol->SetNDC(); texCol->SetTextAlign(32); texCol->SetTextSize(0.04); texCol->SetTextFont(42); texCol->Draw(); TLatex* texPt = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); texPt->SetNDC(); texPt->SetTextFont(42); texPt->SetTextSize(0.04); texPt->SetLineWidth(2); texPt->Draw(); TLatex* texY = new TLatex(0.22,0.83,"|y| < 1.0"); texY->SetNDC(); texY->SetTextFont(42); texY->SetTextSize(0.04); texY->SetLineWidth(2); texY->Draw(); TLatex* texYield = new TLatex(0.22,0.73,Form("N_{D} = %.0f #pm %.0f",yield,yieldErr)); texYield->SetNDC(); texYield->SetTextFont(42); texYield->SetTextSize(0.04); texYield->SetLineWidth(2); texYield->Draw(); c->SaveAs(Form("plotFits/DMass_poly2_%s_%.0f_%.0f.pdf",collisionsystem.Data(),ptmin,ptmax)); TCanvas* cPull = new TCanvas(Form("cPull_%.0f_%.0f",ptmin,ptmax),"",600,700); TH1D* hPull = (TH1D*)h->Clone("hPull"); for(int i=0;i<h->GetNbinsX();i++) { Double_t nfit = f->Integral(h->GetBinLowEdge(i+1),h->GetBinLowEdge(i+1)+h->GetBinWidth(i+1))/h->GetBinWidth(i+1); hPull->SetBinContent(i+1,(h->GetBinContent(i+1)-nfit)/h->GetBinError(i+1)); hPull->SetBinError(i+1,0); } hPull->SetMinimum(-4.); hPull->SetMaximum(4.); hPull->SetYTitle("Pull"); hPull->GetXaxis()->SetTitleOffset(1.); hPull->GetYaxis()->SetTitleOffset(0.65); hPull->GetXaxis()->SetLabelOffset(0.007); hPull->GetYaxis()->SetLabelOffset(0.007); hPull->GetXaxis()->SetTitleSize(0.12); hPull->GetYaxis()->SetTitleSize(0.12); hPull->GetXaxis()->SetLabelSize(0.1); hPull->GetYaxis()->SetLabelSize(0.1); hPull->GetYaxis()->SetNdivisions(504); TLine* lPull = new TLine(1.7, 0, 2., 0); lPull->SetLineWidth(1); lPull->SetLineStyle(7); lPull->SetLineColor(1); TPad* pFit = new TPad("pFit","",0,0.3,1,1); pFit->SetBottomMargin(0); pFit->Draw(); pFit->cd(); h->Draw("e"); background->Draw("same"); mass->Draw("same"); massSwap->Draw("same"); f->Draw("same"); leg->Draw("same"); texCms->Draw(); texCol->Draw(); texPt->Draw(); texY->Draw(); texYield->Draw(); cPull->cd(); TPad* pPull = new TPad("pPull","",0,0,1,0.3); pPull->SetTopMargin(0); pPull->SetBottomMargin(0.3); pPull->Draw(); pPull->cd(); hPull->Draw("p"); lPull->Draw(); cPull->cd(); cPull->SaveAs(Form("plotFits/DMass_poly2_%s_%.0f_%.0f_Pull.pdf",collisionsystem.Data(),ptmin,ptmax)); return mass; }
void plotPedestalAnalysis(string inputFileName, string outputDIR, bool testDoubleGaussianChannels){ system(("mkdir -p "+outputDIR).c_str()); setTDRStyle(); gROOT->SetBatch(kTRUE); TFile* inputFile = TFile::Open(inputFileName.c_str(),"READ"); inputFile->cd(); TTree* tree = (TTree*) inputFile->Get("pedestalFullNoise"); uint32_t detid,fedKey; uint16_t fecCrate,fecSlot, fecRing, ccuAdd, ccuChan, lldChannel, fedId, fedCh, apvId, stripId; float fitChi2Probab, kSProbab, jBProbab, aDProbab, fitChi2; float noiseSkewness, noiseKurtosis; float fitGausMean, fitGausSigma, fitGausNormalization; float fitGausMeanError, fitGausSigmaError, fitGausNormalizationError; vector<float>* noiseDistribution = 0; vector<float>* noiseDistributionError = 0; float nBin, xMin, xMax; tree->SetBranchStatus("*",kFALSE); tree->SetBranchStatus("detid",kTRUE); tree->SetBranchStatus("fedKey",kTRUE); tree->SetBranchStatus("fecCrate",kTRUE); tree->SetBranchStatus("fecSlot",kTRUE); tree->SetBranchStatus("fecRing",kTRUE); tree->SetBranchStatus("ccuAdd",kTRUE); tree->SetBranchStatus("ccuChan",kTRUE); tree->SetBranchStatus("lldChannel",kTRUE); tree->SetBranchStatus("fedId",kTRUE); tree->SetBranchStatus("fedCh",kTRUE); tree->SetBranchStatus("apvId",kTRUE); tree->SetBranchStatus("stripId",kTRUE); tree->SetBranchStatus("fitChi2",kTRUE); tree->SetBranchStatus("fitChi2Probab",kTRUE); tree->SetBranchStatus("kSProbab",kTRUE); tree->SetBranchStatus("jBProbab",kTRUE); tree->SetBranchStatus("aDProbab",kTRUE); tree->SetBranchStatus("fitGausNormalization",kTRUE); tree->SetBranchStatus("fitGausMean",kTRUE); tree->SetBranchStatus("fitGausSigma",kTRUE); tree->SetBranchStatus("fitGausNormalizationError",kTRUE); tree->SetBranchStatus("fitGausMeanError",kTRUE); tree->SetBranchStatus("fitGausSigmaError",kTRUE); tree->SetBranchStatus("noiseSkewness",kTRUE); tree->SetBranchStatus("noiseKurtosis",kTRUE); tree->SetBranchStatus("noiseDistribution",kTRUE); tree->SetBranchStatus("noiseDistributionError",kTRUE); tree->SetBranchStatus("nBin",kTRUE); tree->SetBranchStatus("xMin",kTRUE); tree->SetBranchStatus("xMax",kTRUE); tree->SetBranchAddress("detid",&detid); tree->SetBranchAddress("fedKey",&fedKey); tree->SetBranchAddress("fecCrate",&fecCrate); tree->SetBranchAddress("fecSlot",&fecSlot); tree->SetBranchAddress("fecRing",&fecRing); tree->SetBranchAddress("ccuAdd",&ccuAdd); tree->SetBranchAddress("ccuChan",&ccuChan); tree->SetBranchAddress("lldChannel",&lldChannel); tree->SetBranchAddress("fedId",&fedId); tree->SetBranchAddress("fedCh",&fedCh); tree->SetBranchAddress("apvId",&apvId); tree->SetBranchAddress("stripId",&stripId); tree->SetBranchAddress("fitGausNormalization",&fitGausNormalization); tree->SetBranchAddress("fitGausMean",&fitGausMean); tree->SetBranchAddress("fitGausSigma",&fitGausSigma); tree->SetBranchAddress("fitGausNormalizationError",&fitGausNormalizationError); tree->SetBranchAddress("fitGausMeanError",&fitGausMeanError); tree->SetBranchAddress("fitGausSigmaError",&fitGausSigmaError); tree->SetBranchAddress("fitChi2",&fitChi2); tree->SetBranchAddress("fitChi2Probab",&fitChi2Probab); tree->SetBranchAddress("noiseSkewness",&noiseSkewness); tree->SetBranchAddress("noiseKurtosis",&noiseKurtosis); tree->SetBranchAddress("kSProbab",&kSProbab); tree->SetBranchAddress("aDProbab",&aDProbab); tree->SetBranchAddress("jBProbab",&jBProbab); tree->SetBranchAddress("noiseDistribution",&noiseDistribution); tree->SetBranchAddress("noiseDistributionError",&noiseDistributionError); tree->SetBranchAddress("nBin",&nBin); tree->SetBranchAddress("xMin",&xMin); tree->SetBranchAddress("xMax",&xMax); TFile* badStripsNFilledBins = new TFile((outputDIR+"/badStripsNFilledBins.root").c_str(),"RECREATE"); TFile* badKsTest = new TFile((outputDIR+"/badStripsKsTest.root").c_str(),"RECREATE"); TFile* badjBTest = new TFile((outputDIR+"/badStripsjBTest.root").c_str(),"RECREATE"); TFile* badChi2Test = new TFile((outputDIR+"/badStripsChi2Test.root").c_str(),"RECREATE"); TFile* badaDTest = new TFile((outputDIR+"/badStripsaDTest.root").c_str(),"RECREATE"); TFile* badCombinedTest = new TFile((outputDIR+"/badStripsCombined.root").c_str(),"RECREATE"); TFile* badJBNotKSTest = new TFile((outputDIR+"/badStripsjBNotKS.root").c_str(),"RECREATE"); TFile* badaDNotKSandjBTest = new TFile((outputDIR+"/badStripaDNotKSNotjB.root").c_str(),"RECREATE"); TFile* badChi2NotKSandjBandaDTest = new TFile((outputDIR+"/badStripsChi2NotKsandjBandaD.root").c_str(),"RECREATE"); long int nbadNFilledBins = 0; long int nbadKsTest = 0; long int nbadjBTest = 0; long int nbadaDTest = 0; long int nbadChi2Test = 0; long int nbadCombinedTest = 0; long int nbadJBNotKSTest = 0; long int nbadaDNotKSandjBTest = 0; long int nbadChi2NotKSandjBandaDTest = 0; long int nbadDoublePeakDistance = 0; long int nbadDoublePeakAshman = 0; long int nbadDoublePeakChi2 = 0; long int nbadDoublePeakAmplitude = 0; long int nbadDoublePeakBimodality = 0; long int nbadDoublePeakCombined = 0; TCanvas* canvas = new TCanvas("canvas","canvas",600,650); map<uint32_t,uint32_t> moduleDenominator; map<uint32_t,uint32_t> moduleNumerator; // map<uint32_t,uint32_t> moduleNonEdgeNumerator; // map<uint32_t,uint32_t> moduleAPVEdgeNumerator; map<uint32_t,uint32_t> moduleNumeratorFilledBins; map<uint32_t,uint32_t> moduleNumeratorKS; map<uint32_t,uint32_t> moduleNumeratorJB; map<uint32_t,uint32_t> moduleNumeratorDoublePeak; vector<TrackerStrip> badStrip; TH1F* noiseHist = NULL; TF1* noiseFit = NULL; TF1* noiseFit2Gaus = NULL; TFitResultPtr result; TH1F* chi2Distance = new TH1F("chi2Distance","",100,0,1); chi2Distance->Sumw2(); TH1F* peakDistance = new TH1F("peakDistance","",100,0,3); peakDistance->Sumw2(); TH1F* ashmanDistance = new TH1F("ashmanDistance","",100,0,5); ashmanDistance->Sumw2(); TH1F* bimodalityDistance = new TH1F("bimodalityDistance","",100,0,1); bimodalityDistance->Sumw2(); TH1F* amplitudeRatioDistance = new TH1F("amplitudeRatioDistance","",100,0,3); amplitudeRatioDistance->Sumw2(); TFile* multiPeakChannelsChi2 = new TFile((outputDIR+"/multiPeakChannelsChi2.root").c_str(),"RECREATE"); TFile* multiPeakChannelsDistance = new TFile((outputDIR+"/multiPeakChannelsDistance.root").c_str(),"RECREATE"); TFile* multiPeakChannelsAshman = new TFile((outputDIR+"/multiPeakChannelsAshman.root").c_str(),"RECREATE"); TFile* multiPeakChannelsAmplitude = new TFile((outputDIR+"/multiPeakChannelsAmplitude.root").c_str(),"RECREATE"); TFile* multiPeakChannelsBimodality = new TFile((outputDIR+"/multiPeakChannelsBimodality.root").c_str(),"RECREATE"); TFile* multiPeakChannelsCombined = new TFile((outputDIR+"/multiPeakChannelsCombined.root").c_str(),"RECREATE"); int nonNullBins = 0; float chi2Ratio = 0; float distance = 0; float ashman = 0; float bimodality = 0; float amplitudeRatio = 0; bool isfound = false; string fedKeyStr ; TString name ; std::map<string,string> fitParam; for(long int iChannel = 0; iChannel < tree->GetEntries(); iChannel++){ tree->GetEntry(iChannel); cout.flush(); if(iChannel %10000 == 0) cout<<"\r"<<"iChannel "<<100*double(iChannel)/(tree->GetEntries()/reductionFactor)<<" % "; if(iChannel > double(tree->GetEntries())/reductionFactor) break; // skip problematic fed id isfound = false; for(auto skipfed : skipFEDid){ if(fedId == skipfed) isfound = true; } if(isfound) continue; // make selections to identify bad noisy channels (not gaussian ones) std::stringstream stream; stream << std::hex << fedKey; fedKeyStr = stream.str(); if(fedKeyStr.size() == 4) name = Form("fecCrate%d_fecSlot%d_fecRing%d_ccuAdd%d_ccuCh%d_fedKey0x0000%s_lldCh%d_apv%d_strip%d",fecCrate,fecSlot,fecRing,ccuAdd,ccuChan,fedKeyStr.c_str(),lldChannel,apvId,stripId); else if(fedKeyStr.size() == 5) name = Form("fecCrate%d_fecSlot%d_fecRing%d_ccuAdd%d_ccuCh%d_fedKey0x000%s_lldCh%d_apv%d_strip%d",fecCrate,fecSlot,fecRing,ccuAdd,ccuChan,fedKeyStr.c_str(),lldChannel,apvId,stripId); fitParam.clear(); stringstream sMean; sMean << std::scientific << fitGausMean; fitParam["fitGausMean"] = sMean.str(); stringstream sSigma; sSigma << std::scientific << fitGausSigma; fitParam["fitGausSigma"] = sSigma.str(); stringstream sSkew; sSkew << std::scientific << noiseSkewness; fitParam["noiseSkewness"] = sSkew.str(); stringstream sKurt; sKurt << std::scientific << noiseKurtosis; fitParam["noiseKurtosis"] = sKurt.str(); stringstream sKS; sKS << std::scientific << kSProbab; fitParam["kSProbab"] = sKS.str(); stringstream sJB; sJB << std::scientific << jBProbab; fitParam["jBProbab"] = sJB.str(); stringstream sChi2; sChi2 << std::scientific << fitChi2Probab; fitParam["fitChi2Probab"] = sChi2.str(); stringstream sAD; sAD << std::scientific << aDProbab; fitParam["aDProbab"] = sAD.str(); moduleDenominator[detid] = moduleDenominator[detid]+1; if(noiseHist == NULL){ noiseHist = new TH1F ("noiseHist","",nBin,xMin,xMax); noiseHist->Sumw2(); } noiseHist->Reset(); for(int iBin = 0; iBin < noiseDistribution->size(); iBin++){ noiseHist->SetBinContent(iBin+1,noiseDistribution->at(iBin)); noiseHist->SetBinError(iBin+1,noiseDistributionError->at(iBin)); } if(noiseFit == NULL) noiseFit = new TF1 ("noiseFist","gaus(0)",xMin,xMax); noiseFit->SetRange(xMin,xMax); noiseFit->SetParameters(fitGausNormalization,fitGausMean,fitGausSigma); noiseFit->SetParError(0,fitGausNormalizationError); noiseFit->SetParError(1,fitGausMeanError); noiseFit->SetParError(2,fitGausSigmaError); nonNullBins = 0; for(int iBin = 0; iBin < noiseHist->GetNbinsX(); iBin++){ if(noiseHist->GetBinContent(iBin+1) != 0) nonNullBins++; } if(nonNullBins < nFilledBinSelection or noiseHist->GetRMS() < minimumRMS){ badStripsNFilledBins->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); nbadNFilledBins++; moduleNumeratorFilledBins[detid] +=1; continue; } if(kSProbab < quantile3sigma){ badKsTest->cd(); nbadKsTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); moduleNumeratorKS[detid] += 1; } if(jBProbab < quantile5sigma){ badjBTest->cd(); nbadjBTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(fitChi2Probab < quantile4sigma){ badChi2Test->cd(); nbadChi2Test++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(aDProbab < quantile3sigma){ badaDTest->cd(); nbadaDTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(jBProbab < quantile5sigma and kSProbab > quantile3sigma and kSProbab < quantile){ badJBNotKSTest->cd(); nbadJBNotKSTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); moduleNumeratorJB[detid] += 1; } if(aDProbab < quantile3sigma and jBProbab > quantile5sigma and kSProbab > quantile3sigma and kSProbab < quantile){ badaDNotKSandjBTest->cd(); nbadaDNotKSandjBTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(fitChi2Probab < quantile4sigma and jBProbab > quantile5sigma and kSProbab > quantile3sigma and kSProbab < quantile and aDProbab > quantile3sigma){ badChi2NotKSandjBandaDTest->cd(); nbadChi2NotKSandjBandaDTest++; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); } if(kSProbab < quantile3sigma or (kSProbab > quantile3sigma and kSProbab < quantile and jBProbab < quantile5sigma) or (kSProbab > quantile3sigma and kSProbab < quantile and jBProbab > quantile5sigma and aDProbab < quantile3sigma) or (kSProbab > quantile3sigma and kSProbab < quantile and jBProbab > quantile5sigma and aDProbab > quantile3sigma and fitChi2Probab < quantile4sigma)){ badCombinedTest->cd(); nbadCombinedTest++; moduleNumerator[detid] = moduleNumerator[detid]+1; //if(stripId == 1 or stripId == 128) // moduleAPVEdgeNumerator[detid] = moduleAPVEdgeNumerator[detid]+1; //else // moduleNonEdgeNumerator[detid] = moduleNonEdgeNumerator[detid]+1; storeOutputCanvas(canvas,noiseHist,noiseFit,name,fitParam); name = Form("fecCrate%d_fecSlot%d_fecRing%d_ccuAdd%d_ccuCh%d_fedKey0x0000%s_lldCh%d_apv%d_strip%d",fecCrate,fecSlot,fecRing,ccuAdd,ccuChan,fedKeyStr.c_str(),lldChannel,apvId,stripId); badStrip.push_back(TrackerStrip(fecCrate,fecSlot,fecRing,ccuAdd,ccuChan,uint32_t(atoi(fedKeyStr.c_str())),lldChannel,apvId,stripId)); //try to identify double peaked channels if(testDoubleGaussianChannels){ if(noiseFit2Gaus == NULL) // double gaussian in which the sigma is constrained to be the same --> identifing clear two peak channels noiseFit2Gaus = new TF1("dgaus","[0]*exp(-((x-[1])*(x-[1]))/(2*[2]*[2]))+[3]*exp(-((x-[4])*(x-[4]))/(2*[5]*[5]))",xMin,xMax); noiseFit2Gaus->SetRange(xMin,xMax); noiseFit2Gaus->SetParameter(0,fitGausNormalization/2); noiseFit2Gaus->SetParameter(3,fitGausNormalization/2); noiseFit2Gaus->SetParameter(1,1.); noiseFit2Gaus->SetParameter(4,-1.); noiseFit2Gaus->SetParameter(2,fitGausSigma); noiseFit2Gaus->SetParameter(5,fitGausSigma); noiseFit2Gaus->SetParLimits(1,0.,xMax); noiseFit2Gaus->SetParLimits(4,xMin,0); result = noiseHist->Fit(noiseFit2Gaus,"QSR"); chi2Ratio = 0; distance = 0; ashman = 0; bimodality = 0; amplitudeRatio = 0; if(result.Get() or noiseHist->Integral() == 0){ //compute the chi2 ratio chi2Ratio = 0.5*ROOT::Math::chisquared_cdf_c((fitChi2/(result->Ndf()+3))/(result->Chi2()/result->Ndf()),1); chi2Distance->Fill(chi2Ratio); distance = fabs(noiseFit2Gaus->GetParameter(1)-noiseFit2Gaus->GetParameter(4))/(2*sqrt(noiseFit2Gaus->GetParameter(2)*noiseFit2Gaus->GetParameter(5))); peakDistance->Fill(distance); ashman = TMath::Power(2,0.5)*abs(noiseFit2Gaus->GetParameter(1)-noiseFit2Gaus->GetParameter(4))/(sqrt(pow(noiseFit2Gaus->GetParameter(2),2)+pow(noiseFit2Gaus->GetParameter(5),2))); ashmanDistance->Fill(ashman); if(nonNullBins > 3) bimodality = (noiseHist->GetSkewness()*noiseHist->GetSkewness()+1)/(noiseHist->GetKurtosis()+3*(nonNullBins-1)*(nonNullBins-1)/((nonNullBins-2)*(nonNullBins-3))); else bimodality = (noiseHist->GetSkewness()*noiseHist->GetSkewness()+1)/(noiseHist->GetKurtosis()); bimodalityDistance->Fill(bimodality); amplitudeRatio = std::min(noiseFit2Gaus->GetParameter(0),noiseFit2Gaus->GetParameter(3))/std::max(noiseFit2Gaus->GetParameter(0),noiseFit2Gaus->GetParameter(3)); amplitudeRatioDistance->Fill(amplitudeRatio); if(distance > 1){ multiPeakChannelsDistance->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakDistance++; } if(ashman > 2){ multiPeakChannelsAshman->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakAshman++; } if(chi2Ratio < 0.05){ multiPeakChannelsChi2->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakChi2++; } if(amplitudeRatio > 0.85){ multiPeakChannelsAmplitude->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakAmplitude++; } if(bimodality > 0.55){ multiPeakChannelsBimodality->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakBimodality++; } if(ashman > 2 && amplitudeRatio > 0.85){ multiPeakChannelsCombined->cd(); storeOutputCanvas(canvas,noiseHist,noiseFit,noiseFit2Gaus,name); nbadDoublePeakCombined++; moduleNumeratorDoublePeak[detid]++; } } } } } // plot the chi2 and peak distance if(testDoubleGaussianChannels){ storeOutputCanvas(canvas,chi2Distance,"chi2TestStatistics",outputDIR); storeOutputCanvas(canvas,peakDistance,"peakDistanceTestStatistics",outputDIR); storeOutputCanvas(canvas,ashmanDistance,"ashmanTestStatistics",outputDIR); storeOutputCanvas(canvas,amplitudeRatioDistance,"amplitudeRatioDistance",outputDIR); storeOutputCanvas(canvas,bimodalityDistance,"bimodalityDistance",outputDIR); } std::cout<<std::endl; badStripsNFilledBins->Close(); badKsTest->Close(); badaDTest->Close(); badjBTest->Close(); badChi2Test->Close(); badCombinedTest->Close(); badJBNotKSTest->Close(); badaDNotKSandjBTest->Close(); badChi2NotKSandjBandaDTest->Close(); multiPeakChannelsCombined->Close(); ////// multiPeakChannelsChi2->Close(); multiPeakChannelsDistance->Close(); multiPeakChannelsAshman->Close(); multiPeakChannelsAmplitude->Close(); multiPeakChannelsBimodality->Close(); cout<<"#### Bad Nfilled bins "<<nbadNFilledBins<<" --> "<<double(nbadNFilledBins)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad KS Test Channels "<<nbadKsTest<<" ---> "<<double(nbadKsTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad JB Test Channels "<<nbadjBTest<<" ---> "<<double(nbadjBTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad AD Test Channels "<<nbadaDTest<<" ---> "<<double(nbadaDTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad Chi2 Test Channels "<<nbadChi2Test<<" ---> "<<double(nbadChi2Test)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad JB but not KS Test Channels "<<nbadJBNotKSTest<<" ---> "<<double(nbadJBNotKSTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad AD but not KS and not JB Test Channels "<<nbadaDNotKSandjBTest<<" ---> "<<double(nbadaDNotKSandjBTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad Chi2 but not KS and JB and AD Test Channels "<<nbadChi2NotKSandjBandaDTest<<" ---> "<<double(nbadChi2NotKSandjBandaDTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"#### Bad Combined Test Channels "<<nbadCombinedTest<<" ---> "<<double(nbadCombinedTest)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; if(testDoubleGaussianChannels){ cout<<"###############################"<<endl; cout<<"#### Multiple peak finder ####"<<endl; cout<<"##############################"<<endl; cout<<"Two peak by Chi2 "<<nbadDoublePeakChi2<<" --> "<<double(nbadDoublePeakChi2)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Distance "<<nbadDoublePeakDistance<<" --> "<<double(nbadDoublePeakDistance)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Ashman "<<nbadDoublePeakAshman<<" --> "<<double(nbadDoublePeakAshman)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Amplitude "<<nbadDoublePeakAmplitude<<" --> "<<double(nbadDoublePeakAmplitude)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Bimodality "<<nbadDoublePeakBimodality<<" --> "<<double(nbadDoublePeakBimodality)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; cout<<"Two peak by Combibed "<<nbadDoublePeakCombined<<" ---> "<<double(nbadDoublePeakCombined)/(tree->GetEntries()/reductionFactor)<<" % "<<endl; } /// -------> ofstream channelMap ((outputDIR+"/fractionOfGoodChannels.txt").c_str()); for(auto module : moduleDenominator) channelMap << module.first <<" "<< 1. - double(moduleNumerator[module.first])/double(moduleDenominator[module.first]) << "\n"; channelMap.close(); /// -------> ofstream nchannelMapFilledBins ((outputDIR+"/numberBadChannelsFilledBins.txt").c_str()); for(auto module : moduleNumeratorFilledBins) nchannelMapFilledBins << module.first <<" "<< moduleNumeratorFilledBins[module.first] << "\n"; nchannelMapFilledBins.close(); /// -------> ofstream nchannelMap ((outputDIR+"/numberBadChannels.txt").c_str()); for(auto module : moduleNumerator) nchannelMap << module.first <<" "<< moduleNumerator[module.first] << "\n"; nchannelMap.close(); /// -------> // ofstream nNonEdgechannelMap ((outputDIR+"/numberBadChannelsNonEdge.txt").c_str()); // for(auto module : moduleNonEdgeNumerator) // nNonEdgechannelMap << module.first <<" "<< moduleNonEdgeNumerator[module.first] << "\n"; // nNonEdgechannelMap.close(); /// -------> // ofstream nAPVEdgechannelMap ((outputDIR+"/numberBadChannelsAPVEdge.txt").c_str()); // for(auto module : moduleAPVEdgeNumerator) // nAPVEdgechannelMap << module.first <<" "<< moduleAPVEdgeNumerator[module.first] << "\n"; // nAPVEdgechannelMap.close(); /// -------> ofstream nchannelMapKS ((outputDIR+"/numberBadChannelsKS.txt").c_str()); for(auto module : moduleNumeratorKS) nchannelMapKS << module.first <<" "<< moduleNumeratorKS[module.first] << "\n"; nchannelMapKS.close(); /// -------> ofstream nchannelMapJB ((outputDIR+"/numberBadChannelsJB.txt").c_str()); for(auto module : moduleNumeratorJB) nchannelMapJB << module.first <<" "<< moduleNumeratorKS[module.first] << "\n"; nchannelMapJB.close(); /// -------> ofstream nchannelMapDoublePeak ((outputDIR+"/numberBadChannelsDoublePeak.txt").c_str()); for(auto module : moduleNumeratorDoublePeak) nchannelMapDoublePeak << module.first <<" "<< moduleNumeratorDoublePeak[module.first] << "\n"; nchannelMapDoublePeak.close(); // ------> detailed info of bad strips ofstream badStripDump ((outputDIR+"/badStripDump.txt").c_str()); for(auto badstrip : badStrip){ badStripDump<< badstrip.fecCrate_<<" "<<badstrip.fecSlot_<<" "<<badstrip.fecRing_<<" "<<badstrip.ccuAdd_<<" "<<badstrip.ccuCh_<<" "<<badstrip.fedKey_<<" "<<badstrip.lldCh_<<" "<<badstrip.apvid_<<" "<<badstrip.stripid_<<" \n"; } badStripDump.close(); }
TF1* fitMass(TH1D* hData, TH1D* hMCSignal, TH1D* hMCSwapped) { Double_t setparam0=100.; Double_t setparam1=1.865; Double_t setparam2=0.03; Double_t setparam10=0.005; Double_t setparam8=0.1; Double_t setparam9=0.1; Double_t fixparam1=1.865; Double_t minhisto=1.7; Double_t maxhisto=2.0; TF1* f = new TF1("fMass","[0]*([7]*([9]*Gaus(x,[1],[2]*(1+[11]))/(sqrt(2*3.1415927)*[2]*(1+[11]))+(1-[9])*Gaus(x,[1],[10]*(1+[11]))/(sqrt(2*3.1415927)*[10]*(1+[11])))+(1-[7])*Gaus(x,[1],[8]*(1+[11]))/(sqrt(2*3.1415927)*[8]*(1+[11])))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.005,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); f->FixParameter(11,0); hMCSignal->Fit("fMass","q","",minhisto,maxhisto); hMCSignal->Fit("fMass","q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit("fMass","L q","",minhisto,maxhisto); hMCSignal->Fit("fMass","L q","",minhisto,maxhisto); hMCSignal->Fit("fMass","L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L q","",minhisto,maxhisto); hMCSwapped->Fit("fMass","L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); hData->Fit("fMass","q","",minhisto,maxhisto); hData->Fit("fMass","q","",minhisto,maxhisto); f->ReleaseParameter(1); f->SetParLimits(1,1.86,1.87); f->ReleaseParameter(11); f->SetParLimits(11,-0.2,0.2); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L q","",minhisto,maxhisto); hData->Fit("fMass","L m","",minhisto,maxhisto); TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1("fSignal","[0]*([3]*([4]*Gaus(x,[1],[2]*(1+[6]))/(sqrt(2*3.1415927)*[2]*(1+[6]))+(1-[4])*Gaus(x,[1],[5]*(1+[6]))/(sqrt(2*3.1415927)*[5]*(1+[6]))))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10),f->GetParameter(11)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1("fBackground","[0]*(1-[2])*Gaus(x,[1],[3]*(1+[4]))/(sqrt(2*3.1415927)*[3]*(1+[4]))"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8),f->GetParameter(11)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); hData->SetXTitle("m_{#piK} (GeV/c^{2})"); hData->SetYTitle("Entries / (5 MeV/c^{2})"); hData->SetAxisRange(0,hData->GetBinContent(hData->GetMaximumBin())*1.4*1.2,"Y"); hData->SetMarkerSize(0.3); hData->Draw("e"); cout<<"hData->GetMaximum(): "<<hData->GetMaximum()<<endl; background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/hData->GetBinWidth(1); Double_t yieldErr = mass->Integral(minhisto,maxhisto)/hData->GetBinWidth(1)*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"integral function yield: "<<yield<<" fit yield: "<<f->GetParameter(0)*f->GetParameter(7)/hData->GetBinWidth(1)<<" +- "<<f->GetParError(0)*f->GetParameter(7)/hData->GetBinWidth(1)<<std::endl; TLegend* leg = new TLegend(0.65,0.5,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.06); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(hData,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); hData->GetFunction("fMass")->Delete(); TH1D* hDataNoFitFun = (TH1D*) hData->Clone("hDataNoFitFun"); hDataNoFitFun->Draw("esame"); return f; }
//void asymmetry(std::string algoType="caloItCone5") { void asymmetry() { int nBins = 5; TChain* chain = new TChain("jetTree"); int nFiles=49; for(int i=1; i<(nFiles+1); ++i) { char name[100]; sprintf(name, "2ndLevelOutputFiles/2ndLevelOutputFile_%d.root/jetTree", i); chain->Add(name); } int nJetReco_caloItCone5; chain->SetBranchAddress("nJetReco_caloItCone5", &nJetReco_caloItCone5); Float_t ptReco_caloItCone5[40]; chain->SetBranchAddress("ptReco_caloItCone5", ptReco_caloItCone5); Float_t phiReco_caloItCone5[40]; chain->SetBranchAddress("phiReco_caloItCone5", phiReco_caloItCone5); std::vector< TH1F* > h1_asymmetry_less10; std::vector< TH1F* > h1_asymmetry_less12; std::vector< TH1F* > h1_asymmetry_less15; std::vector< TH1F* > h1_asymmetry_less17; std::vector< TH1F* > h1_asymmetry_less20; std::vector< TH1F* > h1_asymmetry_less30; for(int i=0; i<nBins; ++i) { char histName[40]; sprintf(histName, "less10_bin%d", i); TH1F* less10 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less10.push_back(less10); sprintf(histName, "less12_bin%d", i); TH1F* less12 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less12.push_back(less12); sprintf(histName, "less15_bin%d", i); TH1F* less15 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less15.push_back(less15); sprintf(histName, "less17_bin%d", i); TH1F* less17 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less17.push_back(less17); sprintf(histName, "less20_bin%d", i); TH1F* less20 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less20.push_back(less20); sprintf(histName, "less30_bin%d", i); TH1F* less30 = new TH1F(histName, "", 100, -0.6, 0.6); h1_asymmetry_less30.push_back(less30); } TRandom t; Int_t nEntries = chain->GetEntries(); //for(int iEntry=0; iEntry<100000; ++iEntry) { for(int iEntry=0; iEntry<nEntries; ++iEntry) { if( (iEntry % 100000) == 0 ) std::cout << "Entry #" << iEntry << " /" << nEntries << std::endl; chain->GetEntry(iEntry); //------------ CALO IT CONE 0.5 if( nJetReco_caloItCone5 > 2 ) { Float_t pt1(0.), pt2(0.), pt3(0.); Float_t phi1(0.), phi2(0.); for(int iJet = 0; iJet<nJetReco_caloItCone5; ++iJet ) { Float_t ptJet = ptReco_caloItCone5[iJet]; if( ptJet > pt1 ) { pt3=pt2; pt2=pt1; pt1=ptJet; phi1=phiReco_caloItCone5[iJet]; } else if( ptJet > pt2 ) { pt3=pt2; pt2=ptJet; phi2=phiReco_caloItCone5[iJet]; } else if( ptJet > pt3 ) { pt3=ptJet; } } //for jets Float_t pi = 3.14159; //Float_t deltaPhi = acos(cos(phi1-phi2)); Float_t deltaPhi = phi1-phi2; if( deltaPhi > pi ) deltaPhi-=2*pi; if( deltaPhi < -pi ) deltaPhi+=2*pi; if( (pt3 < 30.) && (deltaPhi>2.7) ) { Float_t asymmetry = (pt1-pt2)/(pt1+pt2); Float_t oneHalfProb = t.Uniform(1.); if(oneHalfProb<0.5) asymmetry *= -1.; Float_t averagePt = (pt1+pt2)/2.; int iBin=-1; if( (averagePt > 80.)&&(averagePt < 100.) ) iBin=0; else if( (averagePt > 100.)&&(averagePt < 125.) ) iBin=1; else if( (averagePt > 125.)&&(averagePt < 160.) ) iBin=2; else if( (averagePt > 160.)&&(averagePt < 190.) ) iBin=3; else if( (averagePt > 190.)&&(averagePt < 215.) ) iBin=4; if(iBin!=-1) { h1_asymmetry_less30[iBin]->Fill(asymmetry); if( pt3 < 20. ) h1_asymmetry_less20[iBin]->Fill(asymmetry); if( pt3 < 17. ) h1_asymmetry_less17[iBin]->Fill(asymmetry); if( pt3 < 15. ) h1_asymmetry_less15[iBin]->Fill(asymmetry); if( pt3 < 12. ) h1_asymmetry_less12[iBin]->Fill(asymmetry); if( pt3 < 10. ) h1_asymmetry_less10[iBin]->Fill(asymmetry); } // if ibin } //if pt3 < 30 } //if nJet>2 } //for entries TCanvas* c_prova = new TCanvas("c_prova", "c_prova", 800, 600); c_prova->cd(); Double_t Lower[nBins]; Lower[0] = 80.; Lower[1] = 100.; Lower[2] = 125.; Lower[3] = 160.; Lower[4] = 190.; Lower[5] = 215.; TH1F* h1_resolution_vs_pt = new TH1F("resolution_vs_pt", "Jet Energy Resolution vs. Average Jet p_{T}", nBins, Lower); h1_resolution_vs_pt->SetXTitle("Average p_{T}^{RECO} [GeV/c]"); h1_resolution_vs_pt->SetYTitle("#sigma(p_{T})/p_{T}"); for(int iBin=0; iBin<nBins; ++iBin) { int nPoints = 6; Float_t x[nPoints], y[nPoints]; Float_t err_x[nPoints], err_y[nPoints]; x[0] = 10.; x[1] = 12.; x[2] = 15.; x[3] = 17.; x[4] = 20.; x[5] = 30.; y[0] = sqrt(2)*h1_asymmetry_less10[iBin]->GetRMS(); y[1] = sqrt(2)*h1_asymmetry_less12[iBin]->GetRMS(); y[2] = sqrt(2)*h1_asymmetry_less15[iBin]->GetRMS(); y[3] = sqrt(2)*h1_asymmetry_less17[iBin]->GetRMS(); y[4] = sqrt(2)*h1_asymmetry_less20[iBin]->GetRMS(); y[5] = sqrt(2)*h1_asymmetry_less30[iBin]->GetRMS(); err_x[0] = 0.; err_x[1] = 0.; err_x[2] = 0.; err_x[3] = 0.; err_x[4] = 0.; err_x[5] = 0.; err_y[0] = y[0]/sqrt(h1_asymmetry_less10[iBin]->GetEntries()); err_y[1] = y[1]/sqrt(h1_asymmetry_less12[iBin]->GetEntries()); err_y[2] = y[2]/sqrt(h1_asymmetry_less15[iBin]->GetEntries()); err_y[3] = y[3]/sqrt(h1_asymmetry_less17[iBin]->GetEntries()); err_y[4] = y[4]/sqrt(h1_asymmetry_less20[iBin]->GetEntries()); err_y[5] = y[5]/sqrt(h1_asymmetry_less30[iBin]->GetEntries()); TGraphErrors* resolution_vs_pt3 = new TGraphErrors(nPoints, x, y, err_x, err_y); resolution_vs_pt3->SetMarkerStyle(20); TF1* line = new TF1("line", "[0] + [1]*x"); line->SetParameter(0, y[0]); line->SetParameter(1, (y[1]-y[0])/(x[1]-x[0])); line->SetRange(0., 32.); resolution_vs_pt3->Fit(line, "R"); char plotName[70]; sprintf(plotName, "asymmetry/asymmetry_less10_%d.eps", iBin); h1_asymmetry_less10[iBin]->Draw(); c_prova->SaveAs(plotName); sprintf(plotName, "asymmetry/asymmetry_less20_%d.eps", iBin); h1_asymmetry_less20[iBin]->Draw(); c_prova->SaveAs(plotName); sprintf(plotName, "asymmetry/asymmetry_less30_%d.eps", iBin); h1_asymmetry_less30[iBin]->Draw(); c_prova->SaveAs(plotName); sprintf(plotName, "asymmetry/resolution_vs_pt3_%d.eps", iBin); resolution_vs_pt3->Draw("AP"); c_prova->SaveAs(plotName); h1_resolution_vs_pt->SetBinContent(iBin+1, line->GetParameter(0)); h1_resolution_vs_pt->SetBinError(iBin+1, line->GetParError(0)); } //for pt bins TFile* outFile = new TFile("asymmetryOutputFile.root", "RECREATE"); outFile->cd(); h1_resolution_vs_pt->Write(); outFile->Close(); outFile->Write(); } //asymmetry
void DrawCalibrationPlotsEE ( Char_t* infile1 = "data_LC_20120131_ALPHA_test_prompt/SingleElectron_Run2011AB-WElectron-data_LC_20120131_ALPHA_test_prompt_EoPcaibEE_11032011_Z_R9_EE.root", Char_t* infile2 = "data_LC_20120131_ALPHA_test_prompt/Even_SingleElectron_Run2011AB-WElectron-data_LC_20120131_ALPHA_test_prompt_EoPcaibEE_11032011_Z_R9_EE.root", Char_t* infile3 = "data_LC_20120131_ALPHA_test_prompt/Odd_SingleElectron_Run2011AB-WElectron-data_LC_20120131_ALPHA_test_prompt_EoPcaibEE_11032011_Z_R9_EE.root", //Char_t* infile1 = "FT_R_42_V21B/WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_R9_EE.root", //Char_t* infile2 = "FT_R_42_V21B/Even_WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_R9_EE.root", //Char_t* infile3 = "FT_R_42_V21B/Odd_WZAnalysis_PromptSkim_W-DoubleElectron_FT_R_42_V21B_Z_R9_EE.root", int evalStat = 1, bool isMC=false, Char_t* fileType = "png", Char_t* dirName = ".") { bool printPlots = false; /// by xtal int nbins = 250; /// Set style options gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetOptTitle(0); gStyle->SetOptStat(11110); gStyle->SetOptFit(0); gStyle->SetFitFormat("6.3g"); gStyle->SetPalette(1); gStyle->SetTextFont(42); gStyle->SetTextSize(0.05); gStyle->SetTitleFont(42,"xyz"); gStyle->SetTitleSize(0.05); gStyle->SetLabelFont(42,"xyz"); gStyle->SetLabelSize(0.05); gStyle->SetTitleXOffset(0.8); gStyle->SetTitleYOffset(1.1); gROOT->ForceStyle(); if ( !infile1 ) { cout << " No input file specified !" << endl; return; } if ( evalStat && (!infile2 || !infile3 )){ cout << " No input files to evaluate statistical precision specified !" << endl; return; } cout << "Making calibration plots for: " << infile1 << endl; /// imput file with full statistic normlized to the mean in a ring TFile *f = new TFile(infile1); TH2F *hcmap[2]; hcmap[0] = (TH2F*)f->Get("h_scale_map_EEM"); hcmap[1] = (TH2F*)f->Get("h_scale_map_EEP"); /// ring geometry for the endcap TH2F *hrings[2]; hrings[0] = (TH2F*)hcmap[0]->Clone("hringsEEM"); hrings[1] = (TH2F*)hcmap[0]->Clone("hringsEEP"); hrings[0] ->Reset("ICMES"); hrings[1] ->Reset("ICMES"); hrings[0] ->ResetStats(); hrings[1] ->ResetStats(); FILE *fRing; fRing = fopen("macros/eerings.dat","r"); int x,y,z,ir; while(fscanf(fRing,"(%d,%d,%d) %d \n",&x,&y,&z,&ir) !=EOF ) { if(z>0) hrings[1]->Fill(x,y,ir); if(z<0) hrings[0]->Fill(x,y,ir); } TFile *f4 = TFile::Open("MCtruthIC_EE.root"); TFile *f5 = TFile::Open("MCRecoIC_EE.root"); TH2F *hcmapMcT_EEP = (TH2F*)f4->Get("h_scale_EEP"); TH2F *hcmapMcT_EEM = (TH2F*)f4->Get("h_scale_EEM"); TH2F *hcmapMcR_EEP = (TH2F*)f5->Get("h_scale_EEP"); TH2F *hcmapMcR_EEM = (TH2F*)f5->Get("h_scale_EEM"); ///-------------------------------------------------------------------------------- ///--- Build the precision vs ring plot starting from the TH2F of IC folded and not ///-------------------------------------------------------------------------------- char hname[100]; char htitle[100]; TH1F *hspread[2][50]; TH1F* hspreadAll [40]; TH2F* ICComparison [2]; ICComparison[0] = (TH2F*) hcmapMcT_EEP->Clone("ICComparison_EEM"); ICComparison[1] = (TH2F*) hcmapMcT_EEM->Clone("ICComparison_EEP"); ICComparison[0]->Reset("ICMES"); ICComparison[1]->Reset("ICMES"); ICComparison[0]->ResetStats(); ICComparison[1]->ResetStats(); for (int k = 0; k < 2; k++){ for (int iring = 0; iring < 40 ; iring++){ if (k==0) { sprintf(hname,"hspreadAll_ring%02d",iring); hspreadAll[iring] = new TH1F(hname, hname, nbins,0.,2.); sprintf(hname,"hspreadEEM_MCTruth_ring%02d",iring); hspread[k][iring] = new TH1F(hname, hname, nbins,0.,2.); } else{ sprintf(hname,"hspreadEEP_ring%02d",iring); hspread[k][iring] = new TH1F(hname, hname, nbins,0.,2.); } } } /// spread all distribution, spread for EE+ and EE- and comparison with the MC truth for (int k = 0; k < 2 ; k++){ for (int ix = 1; ix < 101; ix++){ for (int iy = 1; iy < 101; iy++){ int iz = k; if (k==0) iz = -1; int mybin = hcmap[k] -> FindBin(ix,iy); int ring = hrings[1]-> GetBinContent(mybin); float ic = hcmap[k]->GetBinContent(mybin); float ic2=0; if(k==0 && hcmapMcT_EEM->GetBinContent(mybin)!=0 && hcmapMcR_EEM->GetBinContent(mybin)!=0 ) ic2 = hcmapMcT_EEM->GetBinContent(mybin)/hcmapMcR_EEM->GetBinContent(mybin); else if(hcmapMcT_EEP->GetBinContent(mybin)!=0 && hcmapMcR_EEP->GetBinContent(mybin)!=0 ) ic2 = hcmapMcT_EEP->GetBinContent(mybin)/hcmapMcR_EEP->GetBinContent(mybin); if ( ic>0 && ic2>0 ) { hspread[k][ring]->Fill(ic); hspreadAll[ring]->Fill(ic); ICComparison[k]->Fill(ix,iy,ic/ic2); } } } } /// Graph Error for spread EE+ and EE- TGraphErrors *sigma_vs_ring[3]; sigma_vs_ring[0] = new TGraphErrors(); sigma_vs_ring[0]->SetMarkerStyle(20); sigma_vs_ring[0]->SetMarkerSize(1); sigma_vs_ring[0]->SetMarkerColor(kBlue+2); sigma_vs_ring[1] = new TGraphErrors(); sigma_vs_ring[1]->SetMarkerStyle(20); sigma_vs_ring[1]->SetMarkerSize(1); sigma_vs_ring[1]->SetMarkerColor(kBlue+2); sigma_vs_ring[2] = new TGraphErrors(); sigma_vs_ring[2]->SetMarkerStyle(20); sigma_vs_ring[2]->SetMarkerSize(1); sigma_vs_ring[2]->SetMarkerColor(kBlue+2); /// Graph for scale vs ring EE+, EE- and folded TGraphErrors *scale_vs_ring[3]; scale_vs_ring[0] = new TGraphErrors(); scale_vs_ring[0]->SetMarkerStyle(20); scale_vs_ring[0]->SetMarkerSize(1); scale_vs_ring[0]->SetMarkerColor(kBlue+2); scale_vs_ring[1] = new TGraphErrors(); scale_vs_ring[1]->SetMarkerStyle(20); scale_vs_ring[1]->SetMarkerSize(1); scale_vs_ring[1]->SetMarkerColor(kBlue+2); scale_vs_ring[2] = new TGraphErrors(); scale_vs_ring[2]->SetMarkerStyle(20); scale_vs_ring[2]->SetMarkerSize(1); scale_vs_ring[2]->SetMarkerColor(kBlue+2); TF1 *fgaus = new TF1("fgaus","gaus",-10,10); int np[3] = {0}; /// Gaussian fit for EE+ and EE- for (int k = 0; k < 2 ; k++){ for (int iring = 0; iring < 40; iring++){ if (hspread[k][iring]-> GetEntries() == 0) continue; float e = 0.5*hcmap[k]-> GetYaxis()->GetBinWidth(1); fgaus->SetParameter(1,1); fgaus->SetParameter(2,hspread[k][iring]->GetRMS()); fgaus->SetRange(1-5*hspread[k][iring]->GetRMS(),1+5*hspread[k][iring]->GetRMS()); hspread[k][iring]->Fit("fgaus","QR"); sigma_vs_ring[k]-> SetPoint(np[k],iring,fgaus->GetParameter(2)); sigma_vs_ring[k]-> SetPointError(np[k], e ,fgaus->GetParError(2)); scale_vs_ring[k]-> SetPoint(np[k],iring,fgaus->GetParameter(1)); scale_vs_ring[k]-> SetPointError(np[k],e,fgaus->GetParError(1)); np[k]++; } } for (int iring = 0; iring < 40; iring++){ if (hspreadAll[iring]-> GetEntries() == 0) continue; float e = 0.5*hcmap[0]-> GetYaxis()->GetBinWidth(1); fgaus->SetParameter(1,1); fgaus->SetParameter(2,hspreadAll[iring]->GetRMS()); fgaus->SetRange(1-5*hspreadAll[iring]->GetRMS(),1+5*hspreadAll[iring]->GetRMS()); hspreadAll[iring]->Fit("fgaus","QR"); sigma_vs_ring[2]-> SetPoint(np[2],iring,fgaus->GetParameter(2)); sigma_vs_ring[2]-> SetPointError(np[2], e ,fgaus->GetParError(2)); scale_vs_ring[2]-> SetPoint(np[2],iring,fgaus->GetParameter(1)); scale_vs_ring[2]-> SetPointError(np[2],e,fgaus->GetParError(1)); np[2]++; } /// Intercalibration constant vs phi /* TGraphErrors *IC_vs_phi[2]; IC_vs_phi[0] = new TGraphErrors(); IC_vs_phi[0]->SetMarkerStyle(20); IC_vs_phi[0]->SetMarkerSize(1); IC_vs_phi[0]->SetMarkerColor(kBlue+2); IC_vs_phi[1] = new TGraphErrors(); IC_vs_phi[1]->SetMarkerStyle(20); IC_vs_phi[1]->SetMarkerSize(1); IC_vs_phi[1]->SetMarkerColor(kBlue+2); TH1F* Spread_vs_phi[2][360]; for (int k = 0; k < 2; k++){ for (int iphi = 0; iphi < 360 ; iphi++){ if (k==0) { sprintf(hname,"hspread_vs_phi%02d_EEP",iphi); Spread_vs_phi[k][iphi] = new TH1F(hname, hname, nbins,0.,2.); } else{ sprintf(hname,"hspread_vs_ring%02d_EEM",iphi); Spread_vs_phi[k][iphi] = new TH1F(hname, hname, nbins,0.,2.);} } } for (int k = 0; k < 2 ; k++){ for (int ix = 1; ix < 101; ix++){ for (int iy = 1; iy < 101; iy++){ float iphibin; if((atan2(iy-50.,ix-50.)-int(atan2(iy-50.,ix-50.)))*(360./(2.*3.14159)) <0.5) iphibin=floor(180.+atan2(iy-50.,ix-50.)*(360./(2.*3.14159))); else iphibin=ceil(180.+atan2(iy-50.,ix-50.)*(360./(2.*3.14159))); if(iphibin>359) iphibin=359; int mybin = hcmap[k] -> FindBin(ix,iy); float ic = hcmap[k]->GetBinContent(mybin); if ( ic>0 ) { Spread_vs_phi[k][iphibin] ->Fill(ic); } } } } int N[2]={0}; for (int k = 0; k < 2 ; k++){ for (int iphi = 0; iphi < 360; iphi++){ if (Spread_vs_phi[k][iphi]-> GetEntries() == 0) continue; IC_vs_phi[k]-> SetPoint(N[k],iphi,Spread_vs_phi[k][iphi]->GetMean()); IC_vs_phi[k]-> SetPointError(N[k],0,Spread_vs_phi[k][iphi]->GetRMS()/sqrt(Spread_vs_phi[k][iphi]->GetEntries())); N[k]++; } } */ ///----------------- Statistical Precision and Residual -------------------- TGraphErrors *statprecision_vs_ring[3]; statprecision_vs_ring[0] = new TGraphErrors(); statprecision_vs_ring[0]->SetMarkerStyle(20); statprecision_vs_ring[0]->SetMarkerSize(1); statprecision_vs_ring[0]->SetMarkerColor(kRed+2); statprecision_vs_ring[1] = new TGraphErrors(); statprecision_vs_ring[1]->SetMarkerStyle(20); statprecision_vs_ring[1]->SetMarkerSize(1); statprecision_vs_ring[1]->SetMarkerColor(kRed+2); statprecision_vs_ring[2] = new TGraphErrors(); statprecision_vs_ring[2]->SetMarkerStyle(20); statprecision_vs_ring[2]->SetMarkerSize(1); statprecision_vs_ring[2]->SetMarkerColor(kRed+2); TGraphErrors *residual_vs_ring[3]; residual_vs_ring[0] = new TGraphErrors(); residual_vs_ring[0]->SetMarkerStyle(20); residual_vs_ring[0]->SetMarkerSize(1); residual_vs_ring[0]->SetMarkerColor(kGreen+2); residual_vs_ring[1] = new TGraphErrors(); residual_vs_ring[1]->SetMarkerStyle(20); residual_vs_ring[1]->SetMarkerSize(1); residual_vs_ring[1]->SetMarkerColor(kGreen+2); residual_vs_ring[2] = new TGraphErrors(); residual_vs_ring[2]->SetMarkerStyle(20); residual_vs_ring[2]->SetMarkerSize(1); residual_vs_ring[2]->SetMarkerColor(kGreen+2); if (evalStat){ /// acquisition file for statistical precision TFile *f2 = new TFile(infile2); TFile *f3 = new TFile(infile3); TH2F *hcmap2[2]; hcmap2[0] = (TH2F*)f2->Get("h_scale_map_EEM"); hcmap2[1] = (TH2F*)f2->Get("h_scale_map_EEP"); TH2F *hcmap3[2]; hcmap3[0] = (TH2F*)f3->Get("h_scale_map_EEM"); hcmap3[1] = (TH2F*)f3->Get("h_scale_map_EEP"); TH1F *hstatprecision[2][40]; TH1F *hstatprecisionAll[40]; /// stat precision histos for each EE ring for (int k = 0; k < 2; k++){ for (int iring = 0; iring < 40 ; iring ++){ if (k==0) { sprintf(hname,"hstatprecisionAll_ring%02d",iring); hstatprecisionAll[iring] = new TH1F(hname, hname, nbins,-2.,2.); sprintf(hname,"hstatprecisionEEM_ring%02d",iring); hstatprecision[k][iring] = new TH1F(hname, hname, nbins,-2.,2.); } else { sprintf(hname,"hstatprecisionEEP_ring%02d",iring); hstatprecision[k][iring] = new TH1F(hname, hname, nbins,-2.,2.); } } } for (int k = 0; k < 2 ; k++){ for (int ix = 1; ix < 102; ix++){ for (int iy = 1; iy < 102; iy++){ int iz = k; if (k==0) iz = -1; int mybin = hcmap2[k] -> FindBin(ix,iy); int ring = hrings[1]-> GetBinContent(mybin); float ic1 = hcmap2[k]->GetBinContent(mybin); float ic2 = hcmap3[k]->GetBinContent(mybin); if (ic1>0 && ic2 >0){ hstatprecision[k][ring]->Fill((ic1-ic2)/(ic1+ic2)); /// sigma (diff/sum) gives the stat. precision on teh entire sample hstatprecisionAll[ring]->Fill((ic1-ic2)/(ic1+ic2)); } } } } TCanvas* c44 [120]; /// Gaussian fit of the even/odd distribution (rms of the distribution can be also used) int n[3] = {0}; for (int k = 0; k < 2; k++){ for (int iring = 0; iring < 40 ; iring++){ if ( hstatprecision[k][iring]->GetEntries() == 0) continue; float e = 0.5*hcmap2[k]-> GetYaxis()->GetBinWidth(1); fgaus->SetParameter(1,1); fgaus->SetParameter(2,hstatprecision[k][iring]->GetRMS()); fgaus->SetRange(-5*hstatprecision[k][iring]->GetRMS(),5*hstatprecision[k][iring]->GetRMS()); TString name = Form("ff%d_%d",iring,k); hstatprecision[k][iring]->Fit("fgaus","QR"); statprecision_vs_ring[k]-> SetPoint(n[k],iring,fgaus->GetParameter(2)); statprecision_vs_ring[k]-> SetPointError(n[k],e,fgaus->GetParError(2)); n[k]++; } } for (int iring = 0; iring < 40 ; iring++){ if ( hstatprecisionAll[iring]->GetEntries() == 0) continue; float e = 0.5*hcmap2[0]-> GetYaxis()->GetBinWidth(1); fgaus->SetParameter(1,1); fgaus->SetParameter(2,hstatprecisionAll[iring]->GetRMS()); fgaus->SetRange(-5*hstatprecisionAll[iring]->GetRMS(),5*hstatprecisionAll[iring]->GetRMS()); TString name = Form("ffAll%d",iring); hstatprecisionAll[iring]->Fit("fgaus","QR"); statprecision_vs_ring[2]-> SetPoint(n[2],iring,fgaus->GetParameter(2)); statprecision_vs_ring[2]-> SetPointError(n[2],e,fgaus->GetParError(2)); n[2]++; } TH1F *hresidual[3]; hresidual[0] = new TH1F("hresidualEEM","hresidualEEM",1000,0,1); hresidual[1] = new TH1F("hresidualEEP","hresidualEEP",1000,0,1); hresidual[2] = new TH1F("hresidualAll","hresidualAll",1000,0,1); TH1F *hstat[3]; hstat[0] = new TH1F("hstatEEM","hstatEEM",1000,0,0.5); hstat[1] = new TH1F("hstatEEP","hstatEEP",1000,0,0.5); hstat[2] = new TH1F("hstatAll","hstatAll",1000,0,0.5); TH1F *hspre[3]; hspre[0] = new TH1F("hspreEEM","hspreEEM",1000,0,0.5); hspre[1] = new TH1F("hspreEEP","hspreEEP",1000,0,0.5); hspre[2] = new TH1F("hspreAll","hspreAll",1000,0,0.5); /// Residual spread plot for (int k = 0; k < 3 ; k++){ for (int i= 0; i < statprecision_vs_ring[k]-> GetN(); i++){ double spread, espread; double stat, estat; double residual, eresidual; double xdummy,ex; sigma_vs_ring[k]-> GetPoint(i, xdummy, spread ); espread = sigma_vs_ring[k]-> GetErrorY(i); statprecision_vs_ring[k]-> GetPoint(i, xdummy, stat ); estat = statprecision_vs_ring[k]-> GetErrorY(i); ex = statprecision_vs_ring[k]-> GetErrorX(i); if (spread > stat ){ residual = sqrt( spread*spread - stat*stat ); eresidual = sqrt( pow(spread*espread,2) + pow(stat*estat,2))/residual; } else { residual = 0; eresidual = 0; } residual_vs_ring[k]->SetPoint(i,xdummy, residual); residual_vs_ring[k]->SetPointError(i,ex,eresidual); } } } ///----------------------------------------------------------------- ///--- Draw plots ///----------------------------------------------------------------- TCanvas *cEEP[12]; TCanvas *cEEM[12]; /// --- plot 0 : map of coefficients cEEP[0] = new TCanvas("cmapEEP","cmapEEP"); cEEP[0] -> cd(); cEEP[0]->SetLeftMargin(0.1); cEEP[0]->SetRightMargin(0.13); cEEP[0]->SetGridx(); cEEP[0]->SetGridy(); // hcmap[1]->GetXaxis()->SetNdivisions(1020); hcmap[1]->GetXaxis() -> SetLabelSize(0.03); hcmap[1]->Draw("COLZ"); hcmap[1]->GetXaxis() ->SetTitle("ix"); hcmap[1]->GetYaxis() ->SetTitle("iy"); hcmap[1]->GetZaxis() ->SetRangeUser(0.8,1.2); cEEM[0] = new TCanvas("cmapEEM","cmapEEM"); cEEM[0] -> cd(); cEEM[0]->SetLeftMargin(0.1); cEEM[0]->SetRightMargin(0.13); cEEM[0]->SetGridx(); cEEM[0]->SetGridy(); //hcmap[0]->GetXaxis()->SetNdivisions(1020); hcmap[0]->GetXaxis() -> SetLabelSize(0.03); hcmap[0]->Draw("COLZ"); hcmap[0]->GetXaxis() ->SetTitle("ix"); hcmap[0]->GetYaxis() ->SetTitle("iy"); hcmap[0]->GetZaxis() ->SetRangeUser(0.8,1.2); /// --- plot 1 : ring precision vs ieta cEEP[1] = new TCanvas("csigmaEEP","csigmaEEP"); cEEP[1]->SetGridx(); cEEP[1]->SetGridy(); sigma_vs_ring[1]->GetHistogram()->GetYaxis()-> SetRangeUser(0.00,0.20); sigma_vs_ring[1]->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); sigma_vs_ring[1]->GetHistogram()->GetYaxis()-> SetTitle("#sigma_{c}"); sigma_vs_ring[1]->GetHistogram()->GetXaxis()-> SetTitle("ring"); sigma_vs_ring[1]->Draw("ap"); if (evalStat){ statprecision_vs_ring[1]->Draw("psame"); sigma_vs_ring[1]->Draw("psame"); TLegend * leg = new TLegend(0.6,0.7,0.89, 0.89); leg->SetFillColor(0); leg->AddEntry(statprecision_vs_ring[1],"statistical precision", "LP"); leg->AddEntry(sigma_vs_ring[1],"spread", "LP"); leg->Draw("same"); } cEEM[1] = new TCanvas("csigmaEEM","csigmaEEM"); cEEM[1]->SetGridx(); cEEM[1]->SetGridy(); sigma_vs_ring[0]->GetHistogram()->GetYaxis()-> SetRangeUser(0.00,0.20); sigma_vs_ring[0]->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); sigma_vs_ring[0]->GetHistogram()->GetYaxis()-> SetTitle("#sigma_{c}"); sigma_vs_ring[0]->GetHistogram()->GetXaxis()-> SetTitle("ring"); sigma_vs_ring[0]->Draw("ap"); if (evalStat){ statprecision_vs_ring[0]->Draw("psame"); sigma_vs_ring[0]->Draw("psame"); TLegend * leg = new TLegend(0.6,0.7,0.89, 0.89); leg->SetFillColor(0); leg->AddEntry(statprecision_vs_ring[0],"statistical precision", "LP"); leg->AddEntry(sigma_vs_ring[0],"spread", "LP"); leg->Draw("same"); } /// --- plot 5 : statistical precision vs ieta if (evalStat){ cEEP[5] = new TCanvas("cstat","cstat"); cEEP[5]->SetGridx(); cEEP[5]->SetGridy(); statprecision_vs_ring[1]->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.10); statprecision_vs_ring[1]->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); statprecision_vs_ring[1]->GetHistogram()->GetYaxis()-> SetTitle("#sigma((c_{P}-c_{D})/(c_{P}+c_{D}))"); statprecision_vs_ring[1]->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); statprecision_vs_ring[1]->Draw("ap"); cEEP[6] = new TCanvas("cresidualP","cresidualP"); cEEP[6]->SetGridx(); cEEP[6]->SetGridy(); residual_vs_ring[1]->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.10); residual_vs_ring[1]->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); residual_vs_ring[1]->GetHistogram()->GetYaxis()-> SetTitle("residual spread"); residual_vs_ring[1]->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); residual_vs_ring[1]->Draw("ap"); cEEM[5] = new TCanvas("cstatM","cstatM"); cEEM[5]->SetGridx(); cEEM[5]->SetGridy(); statprecision_vs_ring[0]->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.10); statprecision_vs_ring[0]->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); statprecision_vs_ring[0]->GetHistogram()->GetYaxis()-> SetTitle("#sigma((c_{P}-c_{D})/(c_{P}+c_{D}))"); statprecision_vs_ring[0]->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); statprecision_vs_ring[0]->Draw("ap"); cEEM[6] = new TCanvas("cresidualM","cresidualM"); cEEM[6]->SetGridx(); cEEM[6]->SetGridy(); residual_vs_ring[0]->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.10); residual_vs_ring[0]->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); residual_vs_ring[0]->GetHistogram()->GetYaxis()-> SetTitle("residual spread"); residual_vs_ring[0]->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); residual_vs_ring[0]->Draw("ap"); cEEP[8] = new TCanvas("csigmaFolded","csigmaFolded"); cEEP[8]->SetGridx(); cEEP[8]->SetGridy(); sigma_vs_ring[2]->GetHistogram()->GetYaxis()-> SetRangeUser(0.00,0.20); sigma_vs_ring[2]->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); sigma_vs_ring[2]->GetHistogram()->GetYaxis()-> SetTitle("#sigma_{c}"); sigma_vs_ring[2]->GetHistogram()->GetXaxis()-> SetTitle("ring"); sigma_vs_ring[2]->Draw("ap"); if (evalStat){ statprecision_vs_ring[2]->Draw("psame"); sigma_vs_ring[2]->Draw("psame"); TLegend * leg = new TLegend(0.6,0.7,0.89, 0.89); leg->SetFillColor(0); leg->AddEntry(statprecision_vs_ring[2],"statistical precision", "LP"); leg->AddEntry(sigma_vs_ring[2],"spread", "LP"); leg->Draw("same"); } cEEP[9] = new TCanvas("cresidualFolded","cresidualFolded"); cEEP[9]->SetGridx(); cEEP[9]->SetGridy(); residual_vs_ring[2]->GetHistogram()->GetYaxis()-> SetRangeUser(0.0001,0.10); residual_vs_ring[2]->GetHistogram()->GetXaxis()-> SetRangeUser(-85,85); residual_vs_ring[2]->GetHistogram()->GetYaxis()-> SetTitle("residual spread"); residual_vs_ring[2]->GetHistogram()->GetXaxis()-> SetTitle("i#eta"); residual_vs_ring[2]->Draw("ap"); /// save precision for MC comparison if(isMC==true) { TFile * output = new TFile ("StatPrec_MC_EE.root","RECREATE"); output->cd(); statprecision_vs_ring[0]->SetName("gr_stat_prec_EEP"); statprecision_vs_ring[1]->SetName("gr_stat_prec_EEM"); statprecision_vs_ring[2]->SetName("gr_stat_prec"); statprecision_vs_ring[0]->Write(); statprecision_vs_ring[1]->Write(); statprecision_vs_ring[2]->Write(); } } /// Comparison Plot MC - Data TCanvas* canEEP[10], *canEEM[10]; if(isMC == true) { canEEM[0] = new TCanvas("ICComparison MC EEM","ICComparison MC EEM"); canEEM[0]->SetGridx(); canEEM[0]->SetGridy(); ICComparison[0]->GetXaxis() -> SetLabelSize(0.03); ICComparison[0]->Draw("COLZ"); ICComparison[0]->GetXaxis() ->SetTitle("ix"); ICComparison[0]->GetYaxis() ->SetTitle("iy"); ICComparison[0]->GetZaxis() ->SetRangeUser(0.85,1.15); canEEP[0] = new TCanvas("ICComparison MC EEP","ICComparison MC EEP"); canEEP[0]->SetGridx(); canEEP[0]->SetGridy(); ICComparison[1]->GetXaxis() -> SetLabelSize(0.03); ICComparison[1]->Draw("COLZ"); ICComparison[1]->GetXaxis() ->SetTitle("ix"); ICComparison[1]->GetYaxis() ->SetTitle("iy"); ICComparison[1]->GetZaxis() ->SetRangeUser(0.85,1.15); TFile* output = new TFile ("IC_MC_4Correction.root","RECREATE"); output->cd(); ICComparison[0]->Write(); ICComparison[1]->Write(); output->Close(); } TFile *exisistingEE = new TFile ("existingEE.root","READ"); TH2F* exmap = (TH2F*) exisistingEE->Get("endcap"); TH2F* warning_Map_EEP = (TH2F*) exmap->Clone("warning_Map_EEP"); warning_Map_EEP->Reset("ICMES"); warning_Map_EEP->Reset(); TH2F* warning_Map_EEM = (TH2F*) exmap->Clone("warning_Map_EEM"); warning_Map_EEM->Reset("ICMES"); warning_Map_EEM->Reset(); if(isMC == false) { std::ofstream outTxt ("Calibration_Coefficient_EE_dinamic_alpha.txt",std::ios::out); outTxt << "---------------------------------------------------------------" << std::endl; outTxt << std::fixed << std::setprecision(0) << std::setw(10) << "iX" << std::fixed << std::setprecision(0) << std::setw(10) << "iY" << std::fixed << std::setprecision(0) << std::setw(10) << "iZ" << std::fixed << std::setprecision(6) << std::setw(15) << "IC" << std::fixed << std::setprecision(6) << std::setw(15) << "error" << std::endl; outTxt << "---------------------------------------------------------------" << std::endl; for (int ix = 1; ix < hcmap[0]->GetNbinsX()+1 ; ix ++) { for (int iy = 1; iy < hcmap[0] -> GetNbinsY()+1; iy++) { if( exmap->GetBinContent(ix,iy) !=1) continue; double x,statPrec; statprecision_vs_ring[0]->GetPoint(hrings[0]->GetBinContent(ix,iy),x,statPrec); outTxt << std::fixed << std::setprecision(0) << std::setw(10) << hcmap[0]->GetXaxis()->GetBinLowEdge(ix) << std::fixed << std::setprecision(0) << std::setw(10) << hcmap[0]->GetYaxis()->GetBinLowEdge(iy) << std::fixed << std::setprecision(0) << std::setw(10) << "-1"; if( hcmap[0]->GetBinContent(ix,iy) == 0. ) { outTxt << std::fixed << std::setprecision(6) << std::setw(15) << "-1." << std::fixed << std::setprecision(6) << std::setw(15) << "999." << std::endl; } else { outTxt << std::fixed << std::setprecision(6) << std::setw(15) << hcmap[0]->GetBinContent(ix,iy) << std::fixed << std::setprecision(6) << std::setw(15) << statPrec << std::endl; //warning_Map_EEM->Fill(ix,iy); } } } for (int ix = 1; ix < hcmap[1]->GetNbinsX()+1 ; ix ++) { for (int iy = 1; iy < hcmap[1] -> GetNbinsY()+1; iy++) { if( exmap->GetBinContent(ix,iy) !=1) continue; double x,statPrec; statprecision_vs_ring[1]->GetPoint(hrings[1]->GetBinContent(ix,iy),x,statPrec); outTxt << std::fixed << std::setprecision(0) << std::setw(10) << hcmap[1]->GetXaxis()->GetBinLowEdge(ix) << std::fixed << std::setprecision(0) << std::setw(10) << hcmap[1]->GetYaxis()->GetBinLowEdge(iy) << std::fixed << std::setprecision(0) << std::setw(10) << "1"; if( hcmap[1]->GetBinContent(ix,iy) == 0. ) { outTxt << std::fixed << std::setprecision(6) << std::setw(15) << "-1." << std::fixed << std::setprecision(6) << std::setw(15) << "999." << std::endl; } else { outTxt << std::fixed << std::setprecision(6) << std::setw(15) << hcmap[1]->GetBinContent(ix,iy) << std::fixed << std::setprecision(6) << std::setw(15) << statPrec << std::endl; //warning_Map_EEM->Fill(ix,iy); } } } } canEEP[1] = new TCanvas("Warning_EEP","Warning_EEP"); canEEP[1]->SetGridx(); canEEP[1]->SetGridy(); warning_Map_EEP->GetXaxis() -> SetLabelSize(0.03); warning_Map_EEP->Draw("COLZ"); warning_Map_EEP->GetXaxis() ->SetTitle("ix"); warning_Map_EEP->GetYaxis() ->SetTitle("iy"); warning_Map_EEP->GetZaxis() ->SetRangeUser(0.85,1.15); canEEM[1] = new TCanvas("Warning_EEM","Warning_EEM"); canEEM[1]->SetGridx(); canEEM[1]->SetGridy(); warning_Map_EEM->GetXaxis() -> SetLabelSize(0.03); warning_Map_EEM->Draw("COLZ"); warning_Map_EEM->GetXaxis() ->SetTitle("ix"); warning_Map_EEM->GetYaxis() ->SetTitle("iy"); warning_Map_EEM->GetZaxis() ->SetRangeUser(0.85,1.15); }
//------------------------------------ //function to fit energy distributions energyRes* get_res(int snum, Double_t energy, bool do_pion, bool use_f_pion, bool do_fit, bool do_show, bool do_print=false, bool do_batch=false){ Sample* sp = sample_map[snum]; if(!sp) { std::cout << "Sample " << snum << " is not loaded." << std::endl; energyRes* theRes = new energyRes(0,0); return theRes; } //select correct file std::string fpre = sp->fpre; if(do_pion) fpre += "_pion"; else fpre += "_elec"; //make filenames std::stringstream drawname, fname, piname; fname << sp->dir << "/" << fpre << "_" << energy << "gev_10k.root"; if(do_pion) piname << "#pi^{-} " << energy << " GeV"; else piname << "e^{-} " << energy << " GeV"; //open file and tree TFile* _file; _file = TFile::Open((fname.str()).c_str()); TTree* totalTree = (TTree*)_file->Get("Total"); //default histo settings //double Emin = 0.1*energies[num]; //lower cut to remove weird peaks near E=zero double Emin = 0; double Emax = 2*energy; int nbins = 100; //ecal & hcal energies need to be calibrated get_sampling_factors(snum); //make tree drawing expressions //define mip as ecal < 1 gev = 1000 mev if(use_f_pion) drawname << sp->sam_pion; else drawname << sp->sam_elec; if(sp->det==Hcal) drawname << "*(hcal+" << sp->zeroWt << "*zero)/1000"; else drawname << "*ecal/1000"; drawname << ">>htemp(" << nbins << "," << Emin << "," << Emax << ")"; //std::cout << drawname.str() << std::endl; TH1F* h_res; //to store histos drawn from tree TF1* gfit; TF1* gsnL; TF1* gsnR; //plotting variables TCanvas* can; TPad* pad; TLegend* leg; TPaveText* pave; TPaveText* pave_par; TLine *aLline; TLine *aRline; //create instance of energyRes object energyRes* theRes = new energyRes(energy,2); //draw w/ appropriate cut totalTree->Draw((drawname.str()).c_str(),"","hist goff"); h_res = (TH1F*)gDirectory->Get("htemp"); h_res->SetTitle(""); h_res->GetXaxis()->SetTitle("Energy [GeV]"); h_res->SetLineWidth(2); h_res->SetLineColor(kBlack); //names std::string ofit; if(do_fit) ofit = "fit"; else ofit = "nofit"; std::stringstream oname; oname << pdir << "/" << fpre; if(use_f_pion) oname << "_fpion"; oname << "_response_" << ofit << "_" << energy << "gev"; //get values from histo Double_t m = h_res->GetMean(); Double_t me = h_res->GetMeanError(); //Double_t m = h_res->GetBinCenter(h_res->GetMaximumBin()); //peak Double_t s = h_res->GetRMS(); Double_t se = h_res->GetRMSError(); Int_t N = h_res->GetEntries(); std::vector<Double_t> stats(3,0); std::vector<Double_t> stat_err(3,0); stats[0] = N; stat_err[0] = 0; stats[1] = m; stat_err[1] = me; stats[2] = s; stat_err[2] = se; //find peak TSpectrum *spec = new TSpectrum(5); if(nbins < 100) spec->Search(h_res,6,"nobackground nodraw goff"); //turn off background removal when nbins too small else spec->Search(h_res,6,"nodraw goff"); Float_t* xpos = spec->GetPositionX(); Float_t* ypos = spec->GetPositionY(); Double_t p = xpos[0]; Double_t ph = ypos[0]; if(do_show) std::cout << "peak: " << p << std::endl; //setup fitting function & do fit if (do_fit){ gfit = new TF1("resp","gaus",0,h_res->GetXaxis()->GetXmax()); //if(do_jet){ // gfit->SetParameters(ph,p,s); // if(m > p) gfit->SetRange(p-1.5*s,p+1.0*s); //high tail // else gfit->SetRange(p-1.0*s,p+1.5*s); //low tail //} //else{ gfit->SetParameters((Double_t)N,m,s); gfit->SetRange(m-2*s,m+1*s); //fit within 2 std devs //if(m > p) gfit->SetRange(p-2*s,p+1*s); //high tail //else gfit->SetRange(p-1*s,p+2*s); //low tail //} //formatting gfit->SetLineColor(kRed); gfit->SetMarkerColor(kRed); gfit->SetLineWidth(2); //fit h_res->Fit(gfit,"LNQR"); } //store parameters theRes->setStats(stats,stat_err); if(do_fit) theRes->setFit(gfit); //store histo h_res->SetDirectory(0); theRes->setHist(h_res); std::stringstream muname, signame, musigname, aLname, nLname, aRname, nRname, Nname, chiname; muname.precision(2); signame.precision(2); musigname.precision(3); aLname.precision(2); nLname.precision(2); aRname.precision(2); nRname.precision(2); chiname.precision(5); if (do_fit) { muname << fixed << "#mu = " << gfit->GetParameter(1) << " #pm " << gfit->GetParError(1); signame << fixed << "#sigma = " << gfit->GetParameter(2) << " #pm " << gfit->GetParError(2); musigname << fixed << "#sigma/#mu = " << gfit->GetParameter(2)/gfit->GetParameter(1) << " #pm " << gfit->GetParameter(2)/gfit->GetParameter(1) * sqrt( Power(gfit->GetParError(1),2)/Power(gfit->GetParameter(1),2) + Power(gfit->GetParError(2),2)/Power(gfit->GetParameter(2),2) ); //aLname << fixed << "a_{L} = " << gfit->GetParameter(3) << " #pm " << gfit->GetParError(3); //nLname << fixed << "n_{L} = " << gfit->GetParameter(4) << " #pm " << gfit->GetParError(4); //aRname << fixed << "a_{R} = " << gfit->GetParameter(5) << " #pm " << gfit->GetParError(5); //nRname << fixed << "n_{R} = " << gfit->GetParameter(6) << " #pm " << gfit->GetParError(6); chiname << fixed << "#chi^{2}/ndf = " << gfit->GetChisquare()/gfit->GetNDF(); } else { muname << fixed << "Mean = " << m << " #pm " << me; signame << fixed << "RMS = " << s << " #pm " << se; musigname << fixed << "RMS/Mean = " << s/m << " #pm " << s/m*sqrt((me*me)/(m*m)+(se*se)/(s*s)); } Nname << "N = " << N; //plotting if (do_show){ can = new TCanvas((oname.str()).c_str(),(oname.str()).c_str(),700,500); can->cd(); pad = new TPad("graph","",0,0,1,1); pad->SetMargin(0.12,0.05,0.15,0.05); pad->Draw(); pad->cd(); //formatting h_res->SetStats(kTRUE); gStyle->SetOptStat("mr"); h_res->GetYaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetYaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetXaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetXaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetYaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC())); h_res->GetXaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC())); //plot histo and fit h_res->Draw("hist"); if(do_fit) gfit->Draw("same"); //determine placing of legend and paves - par pave goes on side with more space Double_t xmin; if (m/((h_res->GetXaxis()->GetXmax() + h_res->GetXaxis()->GetXmin())/2) < 1) xmin = 0.65; else xmin = 0.2; if(do_fit) { //legend leg = new TLegend(xmin,0.78,xmin+0.2,0.88); leg->AddEntry(h_res,"Standalone"); leg->AddEntry(gfit,"Fit"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.05); leg->SetTextFont(42); leg->Draw("same"); can->Update(); /* //left line Double_t bndL = gfit->GetParameter(1) - gfit->GetParameter(2)*gfit->GetParameter(3); aLline = new TLine(bndL,pad->GetUymin(),bndL,pad->GetUymax()); aLline->SetLineStyle(2); aLline->SetLineWidth(3); aLline->SetLineColor(kBlue); aLline->Draw("same"); //left gaussian gsnL = new TF1("gsn","gaus",Emin,bndL); gsnL->SetParameters(gfit->GetParameter(0),gfit->GetParameter(1),gfit->GetParameter(2)); gsnL->SetLineColor(kRed); gsnL->SetMarkerColor(kRed); gsnL->SetLineWidth(2); gsnL->SetLineStyle(2); gsnL->Draw("same"); //line Double_t bndR = gfit->GetParameter(1) + gfit->GetParameter(2)*gfit->GetParameter(5); aRline = new TLine(bndR,pad->GetUymin(),bndR,pad->GetUymax()); aRline->SetLineStyle(2); aRline->SetLineWidth(3); aRline->SetLineColor(kBlue); aRline->Draw("same"); //right gaussian gsnR = new TF1("gsn","gaus",bndR,Emax); gsnR->SetParameters(gfit->GetParameter(0),gfit->GetParameter(1),gfit->GetParameter(2)); gsnR->SetLineColor(kRed); gsnR->SetMarkerColor(kRed); gsnR->SetLineWidth(2); gsnR->SetLineStyle(2); gsnR->Draw("same"); */ } //pave pave = new TPaveText(xmin,0.68,xmin+0.2,0.78,"NDC"); pave->AddText(sp->name.c_str()); pave->AddText((piname.str()).c_str()); pave->SetFillColor(0); pave->SetBorderSize(0); pave->SetTextFont(42); pave->SetTextSize(0.05); pave->Draw("same"); //par pave Double_t ymin1; //if(do_fit) ymin1 = 0.26; //else ymin1 = 0.51; ymin1 = 0.47; pave_par = new TPaveText(xmin,ymin1,xmin+0.2,ymin1+0.05*4,"NDC"); pave_par->AddText((Nname.str()).c_str()); pave_par->AddText((muname.str()).c_str()); pave_par->AddText((signame.str()).c_str()); pave_par->AddText((musigname.str()).c_str()); //if(do_fit){ // pave_par->AddText((aLname.str()).c_str()); // pave_par->AddText((nLname.str()).c_str()); // pave_par->AddText((aRname.str()).c_str()); // pave_par->AddText((nRname.str()).c_str()); // pave_par->AddText((chiname.str()).c_str()); //} pave_par->SetFillColor(0); pave_par->SetBorderSize(0); pave_par->SetTextFont(42); pave_par->SetTextSize(0.05); pave_par->Draw("same"); std::cout << "response:" << std::endl; std::cout << Nname.str() << std::endl; std::cout << muname.str() << std::endl; std::cout << signame.str() << std::endl; std::cout << musigname.str() << std::endl; if(do_fit){ // std::cout << "aL = " << gfit->GetParameter(3) << " +/- " << gfit->GetParError(3) << std::endl; // std::cout << "nL = " << gfit->GetParameter(4) << " +/- " << gfit->GetParError(4) << std::endl; // std::cout << "aR = " << gfit->GetParameter(5) << " +/- " << gfit->GetParError(5) << std::endl; // std::cout << "nR = " << gfit->GetParameter(6) << " +/- " << gfit->GetParError(6) << std::endl; std::cout << "chi^2/ndf = " << gfit->GetChisquare()/gfit->GetNDF() << std::endl; } if(do_print) can->Print((oname.str()+"."+pformat).c_str(),pformat.c_str()); if(do_batch) _file->Close(); } else { _file->Close(); } //return data structure with relevant info return theRes; }
TF1 *fit(TTree *nt,TTree *ntMC,double ptmin,double ptmax) { //cout<<cut.Data()<<endl; static int count=0; count++; TCanvas *c= new TCanvas(Form("c%d",count),"",600,600); TH1D *h = new TH1D(Form("h%d",count),"",24,5.03,5.99); TH1D *hMC = new TH1D(Form("hMC%d",count),"",24,5.03,5.99); // Fit function TString iNP="Gaus(x,5.36800e+00,5.77122e-02)/(sqrt(2*3.14159)*abs(5.77122e-02))"; TF1 *f = new TF1(Form("f%d",count),"[0]*(Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]))+ [3]+[4]*x+[5]*x*x + [11]*("+iNP+")"); nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y.Data(),ptmin,ptmax)); clean0(h); h->Draw(); f->SetParLimits(4,-1000,0); f->SetParLimits(2,0.01,0.05); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->FixParameter(1,fixparam1); f->SetParLimits(11,0,1000); f->SetParameter(11,10); f->FixParameter(11,0); f->FixParameter(9,0); h->GetEntries(); hMC->Fit(Form("f%d",count),"q","",5,6); hMC->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L q","",5,6); hMC->Fit(Form("f%d",count),"L m","",5,6); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); h->Fit(Form("f%d",count),"q","",5,6); h->Fit(Form("f%d",count),"q","",5,6); f->ReleaseParameter(1); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L q","",5,6); h->Fit(Form("f%d",count),"L m","",5,6); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); cout <<h->GetEntries()<<endl; // function for background shape plotting. take the fit result from f TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(5,6); background->SetLineStyle(2); // function for signal shape plotting. take the fit result from f TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*("+iNP+")"); Bkpi->SetParameter(0,f->GetParameter(11)); Bkpi->SetLineColor(kGreen+1); Bkpi->SetFillColor(kGreen+1); // Bkpi->SetRange(5.00,5.28); Bkpi->SetRange(5.00,6.00); Bkpi->SetLineStyle(1); Bkpi->SetFillStyle(3004); // function for signal shape plotting. take the fit result from f TF1 *mass = new TF1(Form("fmass",count),"[0]*(Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2]))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetLineColor(2); mass->SetLineStyle(2); // cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl; h->SetMarkerStyle(24); h->SetStats(0); h->Draw("e"); h->SetXTitle("M_{B} (GeV/c^{2})"); h->SetYTitle("Entries / (40 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetTitleOffset(1.,"Y"); h->SetAxisRange(0,h->GetMaximum()*1.2,"Y"); Bkpi->Draw("same"); background->Draw("same"); mass->SetRange(5,6); mass->Draw("same"); mass->SetLineStyle(2); mass->SetFillStyle(3004); mass->SetFillColor(2); f->Draw("same"); double yield = mass->Integral(5,6)/0.040; double yieldErr = mass->Integral(5,6)/0.04*mass->GetParError(0)/mass->GetParameter(0); // Draw the legend:) TLegend *leg = myLegend(0.50,0.5,0.86,0.89); leg->AddEntry(h,"CMS Preliminary",""); leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV",""); leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),""); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"Signal","f"); leg->AddEntry(background,"Combinatorial Background","l"); // leg->AddEntry(Bkpi,"Non-prompt J/#psi","f"); leg->Draw(); TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50); leg2->AddEntry(h,"B meson",""); leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",mass->GetParameter(1)*1000.,mass->GetParError(1)*1000.),""); leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f", yield, yieldErr),""); leg2->Draw(); c->SaveAs(Form("PDFVariation/data/2Gto1G/ResultsBs/BMass-%d.pdf",count)); return mass; }
void fitX(TString infname="/data/twang/BfinderRun2/DoubleMu/BfinderData_pp_20151202_bPt0jpsiPt0tkPt0p5/finder_pp_merged.root") { TFile *inf = new TFile(infname.Data()); TTree *ntmix = (TTree*) inf->Get("Bfinder/ntmix"); TH1D *h = new TH1D("h","",40,3.6,4); TCut cutTrk = "1"; //original YJ //TCut cutTrk = "Btrk1PixelHit>=2&&Btrk1StripHit>=7&&Btrk1Chi2ndf<5&&Btrk2PixelHit>=2&&Btrk2StripHit>=7&&Btrk2Chi2ndf<5"; TCut cutTotal="Btype==7&&Bpt>10&&abs(Beta)<10&&sqrt((Bmumueta-Btrk1Eta)*(Bmumueta-Btrk1Eta)+(Bmumuphi-Btrk1Phi)*(Bmumuphi-Btrk1Phi))<9999"&&cutTrk; TCanvas *c = new TCanvas("c","",750,600); ntmix->Draw("Bmass>>h",cutTotal); TFile*output=new TFile("histoX.root","recreate"); output->cd(); h->Write(); output->Close(); h->Sumw2(); TF1 *f = new TF1("f","[0]+[1]*x+[2]*x*x+[8]*x*x*x+[9]*x*x*x*x+[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])"); f->SetLineColor(4); f->SetParameters(-2.2597e4,1.326e4,-1.727e3,50,3.686,0.00357,1,3.8725,0.0054); f->FixParameter(4,3.686); f->FixParameter(5,0.00357); f->FixParameter(7,3.8725); h->Fit("f","LL"); h->Fit("f",""); h->Fit("f","LL"); h->Fit("f","LL","",3.65,3.94); h->Fit("f","LL","",3.65,3.94); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(7); h->Fit("f","LL","",3.65,3.94); h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]"); h->SetYTitle("Entries"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3 ,"Y"); TF1 *f2 = new TF1("f2","[0]+[1]*x+[2]*x*x+0*Gaus(x,[4],[5])+0*Gaus(x,[7],[5])"); f2->SetParameter(0,f->GetParameter(0)); f2->SetParameter(1,f->GetParameter(1)); f2->SetParameter(2,f->GetParameter(2)); TF1 *f3 = new TF1("f3","[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])"); f3->SetParameter(3,f->GetParameter(3)); f3->SetParameter(4,f->GetParameter(4)); f3->SetParameter(5,f->GetParameter(5)); f3->SetParameter(6,f->GetParameter(6)); f3->SetParameter(7,f->GetParameter(7)); f3->SetParameter(8,f->GetParameter(8)); f->SetLineColor(4); f2->SetLineColor(4); f3->SetRange(3.65,3.94); f2->SetRange(3.65,3.94); f2->SetLineStyle(2); f3->SetLineStyle(2); f2->Draw("same"); f3->SetLineColor(2); f3->SetFillStyle(3004); f3->SetFillColor(2); f3->Draw("same"); TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)"); l->Draw(); TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)"); l2->Draw(); TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary"); l3->Draw(); TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV"); l4->Draw(); cout<<ntmix->GetEntries()<<endl; TH1D *hProj = (TH1D*)h->Clone("hProj"); hProj->Clear(); f->SetRange(3.6,4); for (int i=0;i<h->GetEntries()*11;i++) { hProj->Fill(f->GetRandom()); } TCanvas *c2 = new TCanvas("c2","",750,600); hProj->SetTitle("Estimated Projection"); hProj->Draw("e"); }