// Save to .root file void SaveOutput(TString name,TList &list) { TFile *out = new TFile(name,"RECREATE"); TDirectory *pwd = gDirectory; for(int i=0;i<list.GetSize();i++) { TDecayMode *dm = list.At(i); TDirectory *subdir = out->mkdir(dm->GetName()); subdir->cd(); subdir->Append(dm); subdir->Append(dm->histograms); pwd->cd(); } if(!genDesc) cout<<"WARNING! No Generator description in files!"<<endl; else out->Append(genDesc); if(userHisto) { TDecayMode *uh = (TDecayMode*) userHisto; cout<<"INFO: Appending user histograms"<<endl; TDirectoryFile *histos = out->mkdir("USER_HISTOGRAMS"); TIter nexthist(uh->histograms); TKey *key_hist=0; TH1D *h; while(h=(TH1D*)nexthist()) histos->Append(h); } out->Write(); out->Close(); delete out; }
/** * This function draws histograms of kinematic characteristics of the Z, Y and J/Psi samples */ void KinematicsComparison() { gROOT->SetBatch(true); gROOT->SetStyle("Plain"); TFile * inputFileList[3] = { new TFile("ResolutionAnalyzer_JPsi.root","READ"), new TFile("ResolutionAnalyzer_Y.root","READ"), new TFile("ResolutionAnalyzer_Z.root","READ") }; TFile * outputFile = new TFile("KinematicsComparison.root", "RECREATE"); int inputScaleList[3] = { 126629, 48122, 1667 }; outputFile->cd(); // Resonance comparison histograms // ------------------------------- TDirectory * resonancesDir = outputFile->mkdir("Resonances"); resonancesDir->cd(); // drawKinematics( inputFileList, 0, "RecoResonance_Pt", "resonance Pt", "Pt(GeV)", "arbitrary units", "expected number of events in 3.3/pb" ); // Pt drawKinematics( inputFileList, inputScaleList, "RecoResonance_Pt", "resonance Pt", "pt(GeV)", "arbitrary units", "expected number of events in 3.3/pb" ); // Eta drawKinematics( inputFileList, inputScaleList, "RecoResonance_Eta", "resonance #eta", "#eta", "arbitrary units", "expected number of events in 3.3/pb" ); // Phi drawKinematics( inputFileList, inputScaleList, "RecoResonance_Phi", "resonance #phi", "#phi", "arbitrary units", "expected number of events in 3.3/pb" ); // Histograms of muons from the resonances // --------------------------------------- TDirectory * resonancesMuonsDir = outputFile->mkdir("ResonanceMuons"); resonancesMuonsDir->cd(); // DeltaPt drawKinematics( inputFileList, 0, "RecoResonanceMuons_Pt", "pt of muons from resonance", "pt(GeV)", "arbitrary units", "", "muons from " ); // Eta drawKinematics( inputFileList, 0, "RecoResonanceMuons_Eta", "#eta of muons from resonance", "#eta", "arbitrary units", "", "muons from " ); // Phi drawKinematics( inputFileList, 0, "RecoResonanceMuons_Phi", "#phi of muons from resonance", "#phi", "arbitrary units", "", "muons from " ); // Histograms of Deltas of muons from the resonances // ------------------------------------------------- TDirectory * resonancesMuonsDeltasDir = outputFile->mkdir("ResonanceMuonsDeltas"); resonancesMuonsDeltasDir->cd(); // DeltaCotgTheta drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaCotgTheta", "#Delta Cotg(#theta) of muons from resonance", "Cotg(#theta)", "arbitrary units", "", "muons from " ); // DeltaTheta drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaTheta", "#Delta#theta of muons from resonance", "#Delta#theta", "arbitrary units", "", "muons from " ); // DeltaEta drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaEta", "|#Delta#eta| of muons from resonance", "|#Delta#eta|", "arbitrary units", "", "muons from " ); // DeltaEtaSign drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaEtaSign", "#Delta#eta with sign of muons from resonance", "#Delta#eta", "arbitrary units", "", "muons from " ); // DeltaPhi drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaPhi", "#Delta#phi of muons from resonance", "#Delta#phi", "arbitrary units", "", "muons from " ); // DeltaR drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaR", "#Delta R of muons from resonance", "#Delta R", "arbitrary units", "", "muons from " ); }
int main(int argc, char *argv[]) { std::auto_ptr<TRint> application(new TRint("histInMemory", 0, 0)); TH1F *hist1 = new TH1F("hist1", "hist1", 50, 0, 10); TH1F *hist2 = new TH1F("hist2", "hist2", 50, 0, 10); TH1F *hist3 = new TH1F("hist3", "hist3", 50, 0, 10); TH1F *hist4 = new TH1F("hist4", "hist4", 50, 0, 10); TH1F *hist5 = new TH1F("hist5", "hist5", 50, 0, 10); { TRandom3 *random = new TRandom3(1); for(int i = 0; 10000 > i; ++i) { hist1->Fill(random->Gaus(5, 1)); hist2->Fill(random->Poisson(5)); hist3->Fill(random->Uniform(0, 10)); hist4->Fill(random->Gaus(4, 1)); hist5->Fill(random->Poisson(3)); } delete random; } TFile *output = new TFile("output.root", "RECREATE"); TDirectory *group1 = output->mkdir("group1"); group1->cd(); hist1->Write(); hist2->Write(); TDirectory *group2 = output->mkdir("group2"); group2->cd(); hist3->Write(); hist4->Write(); hist5->Write(); delete output; application->Run(true); delete hist1; delete hist2; delete hist3; delete hist4; delete hist5; return 0; }
void ControlPlotter::config() { if (baseName_!="") { outFile_->mkdir(baseName_.c_str()); outFile_->cd(baseName_.c_str()); system(string("mkdir -p results/plots/" + fileName_ + "/" + baseName_).c_str()); } string name = (baseName_ + "_hTrkHits"); hTH1_["hTrkHits"] = new TH1F(name.c_str(),name.c_str(),20,0.5,20.5); name = (baseName_ + "_hChi2"); hTH1_["hChi2"] = new TH1F(name.c_str(),name.c_str(),20,0.5,20.5); name = (baseName_ + "_hGmtMatchedCands"); hTH1_["hGmtMatchedCands"] = new TH1F(name.c_str(),name.c_str(),11,-0.5,10.5); name = (baseName_ + "_hGmtDeltaPhi"); hTH1_["hGmtDeltaPhi"] = new TH1F(name.c_str(),name.c_str(),100,0.,TMath::Pi()); name = (baseName_ + "_hGmtDeltaEta"); hTH1_["hGmtDeltaEta"] = new TH1F(name.c_str(),name.c_str(),100,-1.,1.); name = (baseName_ + "_hGmtDeltaPhiVsEta"); hTH1_["hGmtDeltaPhiVsEta"] = new TH2F(name.c_str(),name.c_str(),24,-2.4,2.4,200,0.,TMath::Pi()); name = (baseName_ + "_hGmtDeltaEtaVsEta"); hTH1_["hGmtDeltaEtaVsEta"] = new TH2F(name.c_str(),name.c_str(),24,-2.4,2.4,200,-1.,1.); }
int createRootFile() { TFile* pRootFile = new TFile("myfile.root", "RECREATE"); if (pRootFile == NULL) { std::cout << "Error creating ROOT file" << std::endl; return 1; } TDirectory* pTestDir = pRootFile->mkdir("TestDir"); if (pTestDir == NULL) { std::cout << "Error creating directory in ROOT file" << std::endl; delete pRootFile; return 1; } std::string name = "testobj"; MyROOTObject* pMyObj = new MyROOTObject(17, 1.2e3, name); std::cout << *pMyObj << std::endl; pTestDir->cd(); pMyObj->Write(pMyObj->GetName()); if (pMyObj != NULL) { delete pMyObj; } if (pRootFile != NULL) { if (pRootFile->IsOpen() && !pRootFile->IsZombie()) { pRootFile->Close(); delete pRootFile; } } }
void real_emission_jackknife(TString dir="real_aajj_splitted_for_jackknife", TString nameroot="outphoton_aajj_effunf_mu1", int N=20){ TFile *outfile = new TFile(Form("%s/%s_jackknifed.root",dir.Data(),nameroot.Data()),"recreate"); outfile->mkdir("effunf"); vector<TFile*> files; for (int i=1; i<=N; i++){ files.push_back(new TFile(Form("%s/%s_splitted_%d.root",dir.Data(),nameroot.Data(),i),"read")); } for (std::vector<TString>::const_iterator it = diffvariables_list.begin(); it!=diffvariables_list.end(); it++){ for (int reg=0; reg<3; reg++) { TString diffvar = *it; vector<TH1F*> histos; TString thisname = Form("htruth_%s_%d",diffvar.Data(),reg); TString thisnamedir = Form("effunf/%s",thisname.Data()); for (uint i=0; i<files.size(); i++){ histos.push_back((TH1F*)(files.at(i)->Get(thisnamedir.Data()))); } TH1F *out = JackknifammiStiHistos(histos); out->SetName(thisname.Data()); out->Print(); outfile->cd("effunf"); out->Write(); #ifdef DEBUG return; #endif } } outfile->Close(); };
void FileSaver::writeObjsInFolder(string folder, bool recreate) { cout<<"*** Updating "<<filename.c_str()<<" file in "<< folder << endl; TFile * fileFinalPlots; if(recreate) fileFinalPlots=TFile::Open(filename.c_str(), "RECREATE"); else fileFinalPlots=TFile::Open(filename.c_str(), "UPDATE"); if (!fileFinalPlots->GetDirectory(folder.c_str())) fileFinalPlots->mkdir(folder.c_str()); fileFinalPlots->cd (folder.c_str()); cout<<"vrce: "<<fArr->At(0)<<endl; if(fArr->At(0)){ cout<<fArr->At(0)->GetName()<<endl; for (int i = 0; i <= fArr->GetLast(); i++){ cout<<fArr->At(i)<<" "<<fArr->At(i)->GetName()<<endl; fArr->At(i)->Write(fArr->At(i)->GetName(),2); cout<<"Object saved ..."<<endl; } } fileFinalPlots->Flush(); fileFinalPlots->Write(); fileFinalPlots->Close(); fArr->Clear(); return; }
void FillHistograms(TString SAMPLE) { cout<<"Processing sample "<<SAMPLE<<endl; //TString PATH("root://eoscms//eos/cms/store/cmst3/user/kkousour/ttH/flat/"); TString PATH("/afs/cern.ch/work/k/kkousour/private/CMSSW_7_4_12/src/KKousour/TopAnalysis/prod/ttH/"); TFile *inf = TFile::Open(PATH+"flatTree_"+SAMPLE+".root"); TFile *outf = TFile::Open(TString::Format("Histo_%s.root",SAMPLE.Data()),"RECREATE"); TIter nextKey(inf->GetListOfKeys()); TKey *key; while ((key = (TKey*)nextKey())) { TString dirName(key->GetName()); cout<<"Found directory "<<dirName<<endl; TH1F *hPass = (TH1F*)inf->Get(dirName+"/TriggerPass"); outf->mkdir(dirName); TDirectory *dir = (TDirectory*)outf->Get(dirName); TTree *tr = (TTree*)inf->Get(dirName+"/events"); TreeClass myTree(tr); dir->cd(); hPass->Write("TriggerPass"); myTree.Loop(dir); cout<<"Loop finished"<<endl; dir->Close(); delete tr; } outf->Close(); inf->Close(); }
void nsubvsV2(){ const int N=16; ofstream fstrVns; TFile *f; if(isSum==0){ fstrVns.open("nsV2_Prod.txt"); f= new TFile("V2_nsvssub_Prod.root","Recreate"); } else { fstrVns.open("nsV2_Sum.txt"); f= new TFile("V2_nsvssub_Sum.root","Recreate"); } const int nsamples[N]={1,2,3,4,5,6,8,10,15,20,30,75,50,100,150,300}; double nsamples_[N], Vmeanmean[N], deltaVmeanmean[N]; TVectorD vecVmeanmean_, vecnsamples, vecdeltaVmeanmean_, vecsigmaVmeanmean; vecVmeanmean_.ResizeTo(N);vecnsamples.ResizeTo(N);vecdeltaVmeanmean_.ResizeTo(N);vecsigmaVmeanmean.ResizeTo(N); for(int ibin=0; ibin<nbin ;ibin++){ TDirectory *dir0 = f->mkdir(Form("D_%d",ibin)); for(int i=0;i<N;i++){ TVectorD vecVmeanmean = getResVsub(nsamples[i]); vecnsamples[i]=(double)nsamples[i]; vecVmeanmean_[i] = vecVmeanmean[ibin]; vecdeltaVmeanmean_[i] = vecVmeanmean[ibin+nbin]/TMath::Sqrt(nsamples[i]); vecsigmaVmeanmean[i] = vecVmeanmean[ibin+nbin*2]/TMath::Sqrt(nsamples[i]); fstrVns<<nsamples[i]<<"\t"<<vecVmeanmean_[i]<<"\t"<<vecdeltaVmeanmean_[i]<<"\t"<<vecsigmaVmeanmean[i]<<endl; } dir0->cd(); vecVmeanmean_.Write("Vmeanmean"); vecdeltaVmeanmean_.Write("deltaVmeanmean"); vecnsamples.Write("nsamples"); } f->Close(); }
void beffAnalysis(const char* input, const char* output) { // input TFile* inputFile = TFile::Open(input); TTree* btagEff = (TTree*)inputFile->Get("btagEff"); // output TFile* outputFile = TFile::Open(output,"RECREATE"); // histogram with proper binning... cloned later on Double_t binning[23] = {20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,120,140,160,180,200,1000}; TH1F* ptSpectrum = new TH1F("PtSpectrum","PtSpectrum",22,binning); ptSpectrum->Sumw2(); // produce the ratio plot for the 12 combinations of (CSVL,CSVM,CSVT),(Barrel,Endcap),(b,c,l) TClonesArray algorithms("TCut",3); new(algorithms[0]) TCut("CSVL","csv>0.244"); new(algorithms[1]) TCut("CSVM","csv>0.679"); new(algorithms[2]) TCut("CSVT","csv>0.898"); TClonesArray etaRegions("TCut",2); new(etaRegions[0]) TCut("Barrel","abs(eta)<=1.2"); new(etaRegions[1]) TCut("Endcaps","abs(eta)>1.2"); TClonesArray flavor("TCut",3); new(flavor[0]) TCut("l","abs(flavor)!=4 && abs(flavor)!=5"); new(flavor[1]) TCut("c","abs(flavor)==4"); new(flavor[2]) TCut("b","abs(flavor)==5"); for(int i=0; i< algorithms.GetEntries() ; ++i) { outputFile->mkdir(((TCut*)algorithms.At(i))->GetName()); outputFile->cd(((TCut*)algorithms.At(i))->GetName()); for(int j=0; j< etaRegions.GetEntries() ; ++j) { for(int k=0; k< flavor.GetEntries() ; ++k) { // histogram before tagging TH1F* pretag = ptSpectrum->Clone("pretag"); btagEff->Draw("pt>>pretag",((*(TCut*)etaRegions.At(j))&&(*(TCut*)flavor.At(k)))*"eventWeight"); // histogram after tagging TH1F* posttag = ptSpectrum->Clone("posttag"); btagEff->Draw("pt>>posttag",((*(TCut*)algorithms.At(i))&&(*(TCut*)etaRegions.At(j))&&(*(TCut*)flavor.At(k)))*"eventWeight"); // ratio TH1F* ratio = posttag->Clone(Form("h_eff_bTagOverGoodJet_pt%s_%s",((TCut*)flavor.At(k))->GetName(), ((TCut*)etaRegions.At(j))->GetName())); ratio->Divide(pretag); // cleanup delete pretag; delete posttag; } } } // cleanup algorithms.Delete(); etaRegions.Delete(); flavor.Delete(); ptSpectrum->SetDirectory(0); outputFile->Write(); outputFile->Close(); inputFile->Close(); }
void store(){ if (!TClass::GetDict("NBD")) { gROOT->ProcessLine(".L /afs/cern.ch/user/q/qixu/CMSSW_6_2_5/src/Centrality/NBD_Glauber_fit/NBD/NBDclass.C+"); } TH1::AddDirectory(kFALSE); int Gth=atoi(getenv("GTH")); int sth=atoi(getenv("STH")); NBD *l; struct para1 var; if(sth==0){TString dirname = "std"; var = var1; if(Gth<nGlau) l = new NBD(datafile,stdGlaulist[Gth],histoname);else l = new NBD(datafile,stdGlaulist[0],histoname);} else if(sth==1){TString dirname ="Gri055"; var = var2; if(Gth<nGlau) l = new NBD(datafile,Gri055Glaulist[Gth],histoname);else l = new NBD(datafile,Gri055Glaulist[0],histoname);} else {TString dirname ="Gri101"; var = var3; if(Gth<nGlau) l = new NBD(datafile,Gri101Glaulist[Gth],histoname);else l = new NBD(datafile,Gri101Glaulist[0],histoname);} l->initmu(var.mumin,var.mumax,var.mustep); l->initk(var.kmin,var.kmax,var.kstep); if(Gth<nGlau) l->initx(var.xmin,var.xmax); else if(Gth-nGlau==0) l->initx(var.xmin-binshift,var.xmax); else l->initx(var.xmin+binshift,var.xmax); // l->fit(); if(sth==0) l->assign(bestlist1[Gth].mubest,bestlist1[Gth].kbest); else if(sth==1) l->assign(bestlist2[Gth].mubest,bestlist2[Gth].kbest); else l->assign(bestlist3[Gth].mubest,bestlist3[Gth].kbest); l->initN(bin,N,method); l->calcvar(); TFile *outfile = new TFile(outG,"Update"); if(Gth==0 && sth==0){ l->dataname.Write("dataname",TObject::kOverwrite); l->histoname.Write("histoname",TObject::kOverwrite); } TDirectory *dir = outfile->GetDirectory(dirname); if (!dir) {outfile->mkdir(dirname); TDirectory *dir = outfile->GetDirectory(dirname);} dir->cd(); TString name; if(Gth==0) name = "G0"; else if(Gth<nGlau) name = Form("Glau_%d",Gth); else name = Form("bin_%d",Gth-nGlau+1); TDirectory *subdir = dir->GetDirectory(name); if(!subdir) {dir->mkdir(name); TDirectory *subdir = dir->GetDirectory(name);} subdir->cd(); l->method.Write("method",TObject::kOverwrite); l->Glaubername.Write("Glaubername",TObject::kOverwrite); l->xmin.Write("xmin",TObject::kOverwrite);l->xmax.Write("xmax",TObject::kOverwrite); l->mubest.Write("mubest",TObject::kOverwrite);l->kbest.Write("kbest",TObject::kOverwrite); l->chis.Write("chis",TObject::kOverwrite);l->Ndf.Write("Ndf",TObject::kOverwrite); l->NcollAver.Write("NcollAver",TObject::kOverwrite);l->NpartAver.Write("NpartAver",TObject::kOverwrite);l->BAver.Write("BAver",TObject::kOverwrite); l->centbin.Write("centbin",TObject::kOverwrite); l->kpoint.Write("kpoint",TObject::kOverwrite); l->centbin_.Write("centbin_",TObject::kOverwrite); l->kpoint_.Write("kpoint_",TObject::kOverwrite); l->Npartdis->Write(); l->Grgrid->Write("Grgrid",TObject::kOverwrite); outfile->Close(); }
void FakeAnalysis::finish() { TFile *file = histfiles::initializeTFile( this ); if(file==NULL) return; string directory_name("Fake_Hist"); file->mkdir(directory_name.c_str()); _histos.save(file, directory_name); file->Close(); }
void merge(){ TVectorD Nevent; Nevent.ResizeTo(nbin); Nevent.Zero(); // TVectorD totmultall; totmultall.ResizeTo(nbin); totmultall.Zero(); // TVectorD avgmultall; avgmultall.ResizeTo(nbin); avgmultall.Zero(); TVectorD tottrk; tottrk.ResizeTo(nbin); tottrk.Zero(); // TVectorD totptall; totptall.ResizeTo(nbin); totptall.Zero(); // TVectorD totetaall; totetaall.ResizeTo(nbin); totetaall.Zero(); TVectorD avgtrk; avgtrk.ResizeTo(nbin); avgtrk.Zero(); // TVectorD avgmult; avgmult.ResizeTo(nbin); TH2F* s[nbin]; TH2F* b[nbin]; for(int ibin=0;ibin<nbin;ibin++){ s[ibin] = new TH2F(Form("s_%d",ibin),Form("signal",ibin),detastep,detamin,detamax,dphistep,dphimin,dphimax); s[ibin]->Sumw2(); b[ibin] = new TH2F(Form("b_%d",ibin), "background",detastep,detamin,detamax,dphistep,dphimin,dphimax); b[ibin]->Sumw2(); } TFile *fout = new TFile(Form("Anav3_merged.root"),"Recreate"); TFile *f[nFileAll]; for(int ifile=; ifile<63; ifile++){ f[ifile] = TFile::Open(Form("%s/Anav3_%d.root",outdir.Data(),ifile)); if(!f[ifile]) continue; TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get(Form("Nevent")); // TVectorD* totmultall_t = (TVectorD*)f[ifile]->Get(Form("totmultall")); TVectorD* tottrk_t = (TVectorD*)f[ifile]->Get(Form("tottrk")); // TVectorD* totptall_t = (TVectorD*)f[ifile]->Get(Form("totptall")); // TVectorD* totetaall_t = (TVectorD*)f[ifile]->Get(Form("totetaall")); for(int ibin=0;ibin<nbin;ibin++){ // totptall[ibin] += (*totptall_t)[ibin]; // totetaall[ibin] += (*totetaall_t)[ibin]; Nevent[ibin] += (*Nevent_t)[ibin]; // totmultall[ibin] += (*totmultall_t)[ibin]; tottrk[ibin] += (*tottrk_t)[ibin]; TH1D* s_t = (TH1D*)f[ifile]->Get(Form("signal_%d",ibin)); TH1D* b_t = (TH1D*)f[ifile]->Get(Form("background_%d",ibin)); s[ibin]->Add(s_t); b[ibin]->Add(b_t); } f[ifile]->Close(); } for(int ibin=0;ibin<nbin;ibin++){ avgtrk[ibin] = tottrk[ibin]/Nevent[ibin]; TH1D* hr = (TH1D*)s[ibin]->Clone("hr"); hr->Divide(b[ibin]); hr->Scale(b[ibin]->GetBinContent(b[ibin]->FindBin(0,0))); fout->cd(); Nevent.Write("Nevent"); avgtrk.Write("avgtrk"); TDirectory *dir0 = (TDirectory*)fout->mkdir(Form("D_%d",ibin)); dir0->cd(); s[ibin]->Write("s"); b[ibin]->Write("b"); hr->Write(); } }
int produceEnergyHistos(CSPrereqs& csp) { cout << endl << "Mapping " << csp.name << " TOF histogram to energy domain..." << endl; // open input file TFile* inputFile = new TFile(inputFileName.c_str(),"READ"); if(!inputFile->IsOpen()) { cerr << "Error: failed to open " << inputFileName << " to fill histos." << endl; return 1; } // create output file TFile* outputFile = new TFile(outputFileName.c_str(),"RECREATE"); for(auto& channelName : config.cs.DETECTOR_NAMES) { TDirectory* detectorDirectory = inputFile->GetDirectory(channelName.c_str()); if(!detectorDirectory) { cerr << "Error: failed to find " << channelName << " directory in " << inputFileName << "." << endl; return 1; } TDirectory* outputDirectory = outputFile->mkdir(channelName.c_str(),channelName.c_str()); // find TOF histograms in input file for(int i=0; i<config.target.TARGET_ORDER.size(); i++) { string targetName = config.target.TARGET_ORDER[i]; string TOFHistoName = targetName + "TOFCorrected"; detectorDirectory->cd(); TH1D* TOF = (TH1D*)detectorDirectory->Get(TOFHistoName.c_str()); if(!TOF) { cerr << "Error: failed to open " << TOFHistoName << " in " << inputFileName << endl; return 1; } outputDirectory->cd(); TH1D* correctedEnergy = convertTOFtoEnergy(TOF, targetName + "Energy"); TOF->Write(); correctedEnergy->Write(); } } outputFile->Close(); inputFile->Close(); return 0; }
void takeHist(TString fname){ TFile * in = TFile::Open(fname); TH1D * h2 = ((TH2D*)in->Get("Default_allW/Default_allWcosTheta2D"))->ProjectionY(); h2->Add((TH1D*)in->Get("Default_allW/Default_allWcosTheta")); TH3D * h1 = new TH3D("tmp","", 1000, -1., 1., 100, -1., 1., 10, -1. ,1.); TFile * out = new TFile(fname+"Sec", "recreate"); out->mkdir("Default_allW")->cd(); h2->Write("Default_allWcosTheta"); h1->Write("Default_allWcosTheta3D"); out->Close(); }
void changeThis(TString s, TString name){ TFile * fOld = TFile::Open(s,"UPDATE"); TH1D * h = (TH1D*)((TH1D*)fOld->Get(name+"/"+name+"cosTheta"))->Clone("Default_allWcosTheta"); fOld->mkdir("Default_allW")->cd(); h->Write(); fOld->cd(); fOld->Close(); } //10976.661 //18068.028
void TagAndProbe::Terminate() { GetOutputList()->Print(); tTagAndProbeMuIso_ = dynamic_cast<TTree*>(GetOutputList()->FindObject("TagAndProbeMuIso")); TFile *outPutFile = new TFile("TagAndProbe_HT400_NJets3_4_MinDeltaPhi-9999_activity0DR1_test.root","RECREATE"); outPutFile->cd(); outPutFile->mkdir("MuIso"); TDirectory *dMuIso = (TDirectory*)outPutFile->Get("MuIso"); dMuIso->cd(); tTagAndProbeMuIso_->Write(); outPutFile->mkdir("MuReco"); TDirectory *dMuReco = (TDirectory*)outPutFile->Get("MuReco"); dMuReco->cd(); tTagAndProbeMuReco_->Write(); outPutFile->mkdir("ElecIso"); TDirectory *dElecIso = (TDirectory*)outPutFile->Get("ElecIso"); dElecIso->cd(); tTagAndProbeElecIso_->Write(); outPutFile->mkdir("ElecReco"); TDirectory *dElecReco = (TDirectory*)outPutFile->Get("ElecReco"); dElecReco->cd(); tTagAndProbeElecReco_->Write(); outPutFile->Close(); if(truthMatching_) { std::cout<<"Truth matching result for the Tag lepton:\n"; std::cout<<"IsoMuon: Matched to truth: "<<eventsGenMatchForTagLeptonIsoMu_<<" not matched: "<<eventsFailingGenMatchForTagLeptonIsoMu_<<" loss: "<<eventsFailingGenMatchForTagLeptonIsoMu_/(eventsFailingGenMatchForTagLeptonIsoMu_ + eventsGenMatchForTagLeptonIsoMu_)*100<<"%\n"; std::cout<<"RecoMuon: Matched to truth: "<<eventsGenMatchForTagLeptonRecoMu_<<" not matched: "<<eventsFailingGenMatchForTagLeptonRecoMu_<<" loss: "<<eventsFailingGenMatchForTagLeptonRecoMu_/(eventsFailingGenMatchForTagLeptonRecoMu_ + eventsGenMatchForTagLeptonRecoMu_)*100<<"%\n"; std::cout<<"IsoElec: Matched to truth: "<<eventsGenMatchForTagLeptonIsoElec_<<" not matched: "<<eventsFailingGenMatchForTagLeptonIsoElec_<<" loss: "<<eventsFailingGenMatchForTagLeptonIsoElec_/(eventsFailingGenMatchForTagLeptonIsoElec_ + eventsGenMatchForTagLeptonIsoElec_)*100<<"%\n"; std::cout<<"RecoElec: Matched to truth: "<<eventsGenMatchForTagLeptonRecoElec_<<" not matched: "<<eventsFailingGenMatchForTagLeptonRecoElec_<<" loss: "<<eventsFailingGenMatchForTagLeptonRecoElec_/(eventsFailingGenMatchForTagLeptonRecoElec_ + eventsGenMatchForTagLeptonRecoElec_)*100<<"%\n"; } // The Terminate() function is the last function to be called during // a query. It always runs on the client, it can be used to present // the results graphically or save the results to file. }
void createHistos(const char* fn) { TFile* f = TFile::Open(fn,"update"); TH1F* h2 = new TH1F("h2","Random Guas -2",100,-4,4); h2->FillRandom("gaus"); h2->Write(); f->mkdir("ADirectory"); f->cd("ADirectory"); TH1F* h1= new TH1F("h1","Random Gaus",100,-10,10); h1->FillRandom("gaus"); h1->Write(); TH1F* h3 = new TH1F("h3","Random Gaus -3",100,0,4); h3->FillRandom("gaus"); h2->Write(); f->Close(); }
void CompareCFLADiffCuts() { TFile newFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/15-NoOppChargeCut/All/CFs.root"); TDirectory *newDir = newFile.GetDirectory("Merged"); vector<TH1D*> newCFs; newCFs.push_back((TH1D*)newDir->Get("CFLamALam010")); newCFs.push_back((TH1D*)newDir->Get("CFLamALam1030")); newCFs.push_back((TH1D*)newDir->Get("CFLamALam3050")); TFile oldFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/08-NewAvgSepCuts/All/CFs.root"); TDirectory *oldDir = oldFile.GetDirectory("Merged"); vector<TH1D*> oldCFs; oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam010")); oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam1030")); oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam3050")); TFile *compareFile = new TFile("Compare.root","update"); TDirectory *dir = compareFile->GetDirectory("Delta"); if(!dir) dir = compareFile->mkdir("Delta"); for(UInt_t i = 0; i < newCFs.size(); i++) { // TH1D *ratio = (TH1D*)newCFs[i]->Clone(); // TString name = ratio->GetName(); // ratio->SetName(name + "Ratio"); // ratio->SetTitle(name + "Ratio"); // ratio->Divide(oldCFs[i]); // TH1D *barlowRatio = ComputeRogerBarlowRatio(newCFs[i], oldCFs[i]); // barlowRatio->SetName(name + "BarlowRatio"); // barlowRatio->SetTitle(name + "BarlowRatio"); TString name = newCFs[i]->GetName(); TH1D *barlowDifference = ComputeRogerBarlowDifference(newCFs[i], oldCFs[i]); barlowDifference->SetName(name + "BarlowDifference"); barlowDifference->SetTitle(name + "BarlowDifference"); dir->cd(); // ratio->Write(); // barlowRatio->Write(); barlowDifference->Write(barlowDifference->GetName(), TObject::kOverwrite); Chi2TestWithZero(barlowDifference); FitWithConstant(barlowDifference, compareFile); // LookAtMean(barlowDifference); RebinHist(barlowDifference, compareFile); ManuallyRebin(barlowDifference, compareFile); } compareFile->Close(); }
TFile *createRootFile(TString fileName,TString STlepCut,TString HTCut,TH1D *hIn,TString histoName) { TH1::SetDefaultSumw2(); TFile *fout = new TFile(fileName,"UPDATE"); fout->mkdir("ANplots"+STlepCut+"_NOLPsecondD"+HTCut); fout->ls(); fout->cd("ANplots"+STlepCut+"_NOLPsecondD"+HTCut); fout->pwd(); TH1D *hOut = (TH1D*)hIn->Clone(histoName); hOut->SetName(histoName); hOut->Write(histoName); fout->Close(); return fout; }
void addAndWeight(TString directory, TString plot, TFile& outputfile, double scalingFactor) { // get the histograms, erase existing at the beginning hists_.clear(); loadingHists(directory+"/"+plot); // normalize to luminosity (and add samples) combineFiles(scalingFactor); // define output plot TH1F* weightedPlot=(TH1F*)hists_[files_.size()]->Clone(); // write output to directory if(outputfile.GetDirectory(directory)==0){ outputfile.mkdir(directory); outputfile.cd(directory); } weightedPlot->Write(plot); std::cout << " " << plot; }
void CreateFile(const char *fname) { TFile *example = (TFile*)gROOT->ProcessLineFast("hsimple(1)"); if (!example) return; TH1F *hpx = (TH1F*)example->Get("hpx"); hpx->SetName("hpx1"); TFile::Cp(example->GetName(), fname); TFile *file = TFile::Open(fname, "UPDATE"); file->mkdir("folder")->cd(); hpx->Write(); file->Close(); example->Close(); TString sname(fname); if (sname.Contains("000")) { TFile::Cp(fname, "original.root"); TFile::Open("original.root"); } }
void FillHistograms(TString SAMPLE) { cout<<"Processing sample "<<SAMPLE<<endl; TString PATH("../../prod/ttbar/"); TFile *inf = TFile::Open(PATH+"flatTree_"+SAMPLE+".root"); TFile *outf = TFile::Open(TString::Format("Histo_%s.root",SAMPLE.Data()),"RECREATE"); TIter nextKey(inf->GetListOfKeys()); TKey *key; while ((key = (TKey*)nextKey())) { TString dirName(key->GetName()); cout<<"Found directory "<<dirName<<endl; TH1F *hPass = (TH1F*)inf->Get(dirName+"/TriggerPass"); outf->mkdir(dirName); TDirectory *dir = (TDirectory*)outf->Get(dirName); TTree *tr = (TTree*)inf->Get(dirName+"/events"); if (dirName.Contains("Boost")) { TreeClassBoosted myTree(tr); dir->cd(); hPass->Write("TriggerPass"); myTree.Loop(dir); cout<<"Loop finished"<<endl; dir->Close(); cout<<"directory closed"<<endl; delete tr; cout<<"Tree deleted"<<endl; } else { TreeClassResolved myTree(tr); dir->cd(); hPass->Write("TriggerPass"); myTree.Loop(dir); cout<<"Loop finished"<<endl; dir->Close(); cout<<"directory closed"<<endl; delete tr; cout<<"Tree deleted"<<endl; } } outf->Close(); inf->Close(); }
void doit() { TFile* base = new TFile("f.db","recreate"); TDirectory* a = base->mkdir("a","First Level Dir"); a->cd(); TH1D* ha = new TH1D("ha","ha",10,0,1); TDirectory* aa = a->mkdir("aa","Second Level Dira"); aa->cd(); TH1D* haa = new TH1D("haa","haa",10,0,1); a->ls(); printf(" a: created@ %p found@ %p\n", a,base->FindObjectAny("a")); printf("ha: created@ %p found@ %p\n",ha,base->FindObjectAny("ha")); printf("ha: created@ %p --found@ %p\n",ha,base->FindObjectAny("a/ha")); #ifdef ClingWorkAroundMissingImplicitAuto TDirectory *k = (TDirectory*)base->FindObjectAny("a"); #else k = (TDirectory*)base->FindObjectAny("a"); #endif printf("ha: created@ %p found@ %p\n",ha,k->FindObjectAny("ha")); printf("aa: created@ %p found@ %p\n",aa,base->FindObjectAny("aa")); printf("aa: created@ %p --found@ %p\n",aa,base->FindObjectAny("a/aa")); printf("aa: created@ %p found@ %p\n",aa,k->FindObjectAny("aa")); printf("haa: created@ %p found@ %p\n",haa,base->FindObjectAny("haa")); printf("haa: created@ %p --found@ %p\n",haa,base->FindObjectAny("aa/haa")); printf("haa: created@ %p --found@ %p\n",haa,base->FindObjectAny("a/aa/haa")); printf("haa: created@ %p found@ %p\n",haa,k->FindObjectAny("haa")); printf("haa: created@ %p --found@ %p\n",haa,k->FindObjectAny("aa/haa")); #ifdef ClingWorkAroundMissingImplicitAuto TDirectory *kk = (TDirectory*)k->FindObjectAny("aa"); #else kk = (TDirectory*)k->FindObjectAny("aa"); #endif printf("haa: created@ %p found@ %p\n",haa,kk->FindObjectAny("haa")); base->Write(); }
void AdaptFileStructure(TString fileName) { TFile* f = TFile::Open(fileName.Data(), "READ"); TList* cList = new TList(); cList->SetName("cList"); cList->SetOwner(kTRUE); for (Int_t i = 0; i < gFile->GetNkeys(); i++) { TObject* obj = f->GetListOfKeys()->At(i); TString name = obj->GetName(); TObject* obj2 = f->Get(name.Data()); cList->Add(obj2); } TString fileNameOutput = fileName; fileNameOutput.ReplaceAll(".root", "_commonStructure.root"); TFile* fOut = TFile::Open(fileNameOutput.Data(), "RECREATE"); fOut->mkdir("PWGLF_PPVsMultXCheck_MC"); fOut->cd("PWGLF_PPVsMultXCheck_MC"); cList->Write("cList", TObject::kSingleKey); fOut->Close(); f->Close(); }
//_________________________________________________________________ void SelectPPCoincMapRegions::Terminate() { std::cout << std::endl; #ifdef DEBUG std::cout << "found mismatched multiplicities b/t anything and fragment "; for (UInt_t i=0; i<fNRegions+2; i++) { std::cout << "\nregion: " << std::setw(3) << i << "mult: " << std::setw(10) << std::setw(4) << mult_mismatch[i]; } std::cout << std::endl; #endif FNameManager fnm; std::string base = fnm.GetHistFileBase(true); if (willSave==kTRUE) { TFile *histfile = new TFile(Form("%s%i.root",base.data(),runnumber[runcount-1]),"UPDATE"); TDirectory *dir = dynamic_cast<TDirectory*>(histfile->Get("coinc_map_regions")); if (dir==0) { dir = histfile->mkdir("coinc_map_regions"); } dir->cd(); std::map<UInt_t,TH1D*>::iterator it; for (it=regional_coinc.begin(); it!=regional_coinc.end(); it++) { it->second->Write("",TObject::kOverwrite); } histfile->cd(); histfile->Close(); } }
void buildFullModel(){ gROOT->SetBatch(1); TFile *fin = TFile::Open("Output_skimtrees.root"); // Set up categories and cut-strings std::vector<std::string> cut_selections; //cut_selections.push_back(" metRaw > 200 "); cut_selections.push_back(" !( jet1mprune > 60 && jet1tau2o1 <0.45 && jet1pt>250) "); cut_selections.push_back(" ( jet1mprune > 60 && jet1tau2o1 <0.45 && jet1pt>250) "); TFile *fout = new TFile(outfilename.c_str(),"RECREATE"); int nselections = cut_selections.size(); for (int sel_i=0;sel_i<nselections;sel_i++){ TDirectory *fdir = fout->mkdir(Form("category_%d",sel_i)); cutstring = cut_selections[sel_i]; buildModel(sel_i,fin,fdir); TNamed cstr(Form("cuts_category_%d",sel_i), cut_selections[sel_i].c_str()); fdir->cd(); cstr.Write(); } }
int main(int argc, char **argv) { if (argc <= 2) { std::cout << "Purpose: convert a JSON file in a TObjString" << std::endl; std::cout << "Context: deep learning for flavour tagging in athena" << std::endl; std::cout << "Inputs:" << std::endl; std::cout << " - input JSON file" << std::endl; std::cout << " - output ROOT file" << std::endl; std::cout << "Usage:" << std::endl; std::cout << " - AGILE_write $INPUT_JSON_FILE $OUTPUT_ROOT_FILE" << std::endl; return 1; } std::string input = argv[1]; std::cout << "input JSON file " << input << std::endl; std::string output = argv[2]; std::cout << "output ROOT file " << output << std::endl; TFile *f = new TFile(output.c_str(), "update","",0); f->mkdir("DL1/AntiKt4EMTopo"); f->cd("DL1/AntiKt4EMTopo"); std::ifstream input_file(input); std::string line_string; std::string input_file_str; while (std::getline(input_file, line_string)) { input_file_str += line_string+ ' ' ; } TObjString comment(input_file_str.c_str()); comment.Write("weights"); f->Write(); f->Close(); delete f; return 0; }
void makeCentralityTable(int nbins = 40, const string label = "hf", const char * tag = "HFhitBins", double MXS = 0.){ // This macro assumes all inefficiency is in the most peripheral bin. double EFF = 1. - MXS; // Retrieving data int nFiles = 1; vector<string> infiles; // TFile* infile = new TFile("/net/hisrv0001/home/yetkin/pstore02/ana/Hydjet_MinBias_d20100222/Hydjet_MinBias_4TeV_runs1to300.root"); // fwlite::Event event(infile); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs1to10.root"); // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs11to20.root"); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs21to30.root"); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs31to40.root"); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs41to50.root"); infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs51to60.root"); // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs61to70.root"); // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs71to80.root"); // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs81to90.root") // infiles.push_back("~/hibat0007/aod/JulyExercise/MinBias0707/MinBias0707_runs91to100.root"); fwlite::ChainEvent event(infiles); vector<int> runnums; // Creating output table TFile* outFile = new TFile("tables.root","update"); TDirectory* dir = outFile->mkdir(tag); dir->cd(); TH1D::SetDefaultSumw2(); CentralityBins* bins = new CentralityBins("noname","Test tag", nbins); bins->table_.reserve(nbins); // Setting up variables & branches double binboundaries[nbinsMax+1]; vector<float> values; // Determining bins of cross section // loop over events unsigned int events=0; for(event.toBegin(); !event.atEnd(); ++event, ++events){ edm::EventBase const & ev = event; if( events % 100 == 0 ) cout<<"Processing event : "<<events<<endl; edm::Handle<edm::GenHIEvent> mc; ev.getByLabel(edm::InputTag("heavyIon"),mc); edm::Handle<reco::Centrality> cent; ev.getByLabel(edm::InputTag("hiCentrality"),cent); double b = mc->b(); double npart = mc->Npart(); double ncoll = mc->Ncoll(); double nhard = mc->Nhard(); double hf = cent->EtHFhitSum(); double hftp = cent->EtHFtowerSumPlus(); double hftm = cent->EtHFtowerSumMinus(); double eb = cent->EtEBSum(); double eep = cent->EtEESumPlus(); double eem = cent->EtEESumMinus(); double parameter = 0; if(label.compare("npart") == 0) parameter = npart; if(label.compare("ncoll") == 0) parameter = ncoll; if(label.compare("nhard") == 0) parameter = nhard; if(label.compare("b") == 0) parameter = b; if(label.compare("hf") == 0) parameter = hf; if(label.compare("hft") == 0) parameter = hftp + hftm; if(label.compare("eb") == 0) parameter = eb; if(label.compare("ee") == 0) parameter = eep+eem; values.push_back(parameter); int run = event.id().run(); if(runnums.size() == 0 || runnums[runnums.size()-1] != run) runnums.push_back(run); } if(label.compare("b") == 0) sort(values.begin(),values.end(),descend); else sort(values.begin(),values.end()); double max = values[events-1]; binboundaries[nbins] = max; cout<<"-------------------------------------"<<endl; cout<<label.data()<<" based cuts are : "<<endl; cout<<"("; int bin = 0; for(int i = 0; i< nbins; ++i){ // Find the boundary int offset = (int)(MXS*events); double xsec = events*(1 + MXS); // Below should be replaced with an integral // when inefficiency is better parametrized // than a step function. int entry = (int)(i*(xsec/nbins)) - offset; binboundaries[i] = values[entry]; cout<<" "<<binboundaries[i]; if(i < nbins - 1) cout<<","; else cout<<")"<<endl; } cout<<"-------------------------------------"<<endl; // Determining Glauber results in various bins TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,500,0,500); TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,2000,0,2000); TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,250,0,250); TH2D* hb = new TH2D("hb","",nbins,binboundaries,300,0,30); for(event.toBegin(); !event.atEnd(); ++event){ edm::EventBase const & ev = event; edm::Handle<edm::GenHIEvent> mc; ev.getByLabel(edm::InputTag("heavyIon"),mc); edm::Handle<reco::Centrality> cent; ev.getByLabel(edm::InputTag("hiCentrality"),cent); double b = mc->b(); double npart = mc->Npart(); double ncoll = mc->Ncoll(); double nhard = mc->Nhard(); double hf = cent->EtHFhitSum(); double hftp = cent->EtHFtowerSumPlus(); double hftm = cent->EtHFtowerSumMinus(); double eb = cent->EtEBSum(); double eep = cent->EtEESumPlus(); double eem = cent->EtEESumMinus(); double parameter = 0; if(label.compare("npart") == 0) parameter = npart; if(label.compare("ncoll") == 0) parameter = ncoll; if(label.compare("nhard") == 0) parameter = nhard; if(label.compare("b") == 0) parameter = b; if(label.compare("hf") == 0) parameter = hf; if(label.compare("hft") == 0) parameter = hftp + hftm; if(label.compare("eb") == 0) parameter = eb; if(label.compare("ee") == 0) parameter = eep+eem; hNpart->Fill(parameter,npart); hNcoll->Fill(parameter,ncoll); hNhard->Fill(parameter,nhard); hb->Fill(parameter,b); } // Fitting Glauber distributions in bins to get mean and sigma values TF1* fGaus = new TF1("fb","gaus(0)",0,2); fGaus->SetParameter(0,1); fGaus->SetParameter(1,0.04); fGaus->SetParameter(2,0.02); fitSlices(hNpart,fGaus); fitSlices(hNcoll,fGaus); fitSlices(hNhard,fGaus); fitSlices(hb,fGaus); /* hNpart->FitSlicesY(); hNcoll->FitSlicesY(); hNhard->FitSlicesY(); hb->FitSlicesY(); */ TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1"); TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2"); TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1"); TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2"); TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1"); TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2"); TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1"); TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2"); cout<<"-------------------------------------"<<endl; cout<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl; // Enter values in table for(int i = 0; i < nbins; ++i){ bins->table_[nbins-i-1].n_part_mean = hNpartMean->GetBinContent(i); bins->table_[nbins-i-1].n_part_var = hNpartSigma->GetBinContent(i); bins->table_[nbins-i-1].n_coll_mean = hNcollMean->GetBinContent(i); bins->table_[nbins-i-1].n_coll_var = hNcollSigma->GetBinContent(i); bins->table_[nbins-i-1].b_mean = hbMean->GetBinContent(i); bins->table_[nbins-i-1].b_var = hbSigma->GetBinContent(i); bins->table_[nbins-i-1].n_hard_mean = hNhardMean->GetBinContent(i); bins->table_[nbins-i-1].n_hard_var = hNhardSigma->GetBinContent(i); bins->table_[nbins-i-1].bin_edge = binboundaries[i]; cout<<i<<" " <<hNpartMean->GetBinContent(i)<<" " <<hNpartSigma->GetBinContent(i)<<" " <<hNcollMean->GetBinContent(i)<<" " <<hNcollSigma->GetBinContent(i)<<" " <<hbMean->GetBinContent(i)<<" " <<hbSigma->GetBinContent(i)<<" " <<binboundaries[i]<<" " <<endl; } cout<<"-------------------------------------"<<endl; // Save the table in output file if(onlySaveTable){ TH1D* hh = (TH1D*)gDirectory->Get("hNpart_0"); hh->Delete(); hh = (TH1D*)gDirectory->Get("hNcoll_0"); hh->Delete(); hh = (TH1D*)gDirectory->Get("hNhard_0"); hh->Delete(); hh = (TH1D*)gDirectory->Get("hb_0"); hh->Delete(); hNpart->Delete(); hNpartMean->Delete(); hNpartSigma->Delete(); hNcoll->Delete(); hNcollMean->Delete(); hNcollSigma->Delete(); hNhard->Delete(); hNhardMean->Delete(); hNhardSigma->Delete(); hb->Delete(); hbMean->Delete(); hbSigma->Delete(); } for(int i = 0; i < runnums.size(); ++i){ CentralityBins* binsForRun = (CentralityBins*) bins->Clone(); binsForRun->SetName(Form("run%d",runnums[i])); binsForRun->Write(); } bins->Delete(); outFile->Write(); }
void getResV(){ //------------------------Deal with the number and get the output stored in txt files and root files string SumorProd = getenv("SUMORPROD"); double Vmax[nbin], eps[nbin]; for(int ibin=0; ibin<nbin ;ibin++){ //Vmax[ibin]=0.065*(trkbin[ibin]+30); Vmax[ibin]=0.065*avgmultIn; //eps[ibin]=0.00025*(trkbin[ibin]+30); eps[ibin]=0.00025*avgmultIn; } ofstream fstrV; double theta[ntheta]; TVectorD avgmult[nbin], avgpt[nbin], totmult[nbin], totpt[nbin]; TVectorD Qx1[nbin], Qy1[nbin], Q2[nbin]; TVectorD Gmod2[nbin][nptV][ntheta]; TVectorD sigma2[nbin][nptV],deltaV[nbin][nptV]; TVectorD sigma2_[nbin],chi_[nbin]; TVectorD deltaVmean[nbin], Vmean[nbin]; TVectorD r[nbin]; TVectorD r0[nbin][nptV], V[nbin][nptV], chi[nbin][nptV]; TVectorD GRe[nbin][nptV][ntheta]; TVectorD* GRe_t[nbin][nptV][ntheta]; TVectorD GIm[nbin][nptV][ntheta]; TVectorD* GIm_t[nbin][nptV][ntheta]; TComplex G[nbin][nptV][ntheta][nstepr]; if(SumorProd=="Sum") fstrV.open("V_Sum.txt"); else fstrV.open("V_Prod.txt"); TFile *f[nFileAll]; for(int ibin=0; ibin<nbin; ibin++){ r[ibin].ResizeTo(nstepr); for(int ir=0; ir<nstepr; ir++){ if(isSimple==0) r[ibin][ir]=j01/(Vmax[ibin]-eps[ibin]*ir); else r[ibin][ir]=0.00025*20*(ir+1); } } TVectorD Nevent; Nevent.ResizeTo(nbin); Nevent.Zero(); TVectorD totmultall; totmultall.ResizeTo(nbin); totmultall.Zero(); TVectorD avgmultall; avgmultall.ResizeTo(nbin); avgmultall.Zero(); TVectorD tottrk; tottrk.ResizeTo(nbin); tottrk.Zero(); TVectorD avgtrk; avgtrk.ResizeTo(nbin); avgtrk.Zero(); for(int itheta=0;itheta<ntheta;itheta++) theta[itheta]=itheta*TMath::Pi()/ntheta/nn; for(int ibin=0;ibin<nbin;ibin++){ for(int iptbin=0;iptbin<nptV;iptbin++){ r0[ibin][iptbin].ResizeTo(ntheta); sigma2[ibin][iptbin].ResizeTo(ntheta); V[ibin][iptbin].ResizeTo(ntheta); deltaV[ibin][iptbin].ResizeTo(ntheta); chi[ibin][iptbin].ResizeTo(ntheta); for(int itheta=0;itheta<ntheta;itheta++){ Gmod2[ibin][iptbin][itheta].ResizeTo(nstepr); GRe[ibin][iptbin][itheta].ResizeTo(nstepr); GRe[ibin][iptbin][itheta].Zero(); GIm[ibin][iptbin][itheta].ResizeTo(nstepr); GIm[ibin][iptbin][itheta].Zero(); } } avgmult[ibin].ResizeTo(nptV); deltaVmean[ibin].ResizeTo(nptV); Vmean[ibin].ResizeTo(nptV); totpt[ibin].ResizeTo(nptV); totpt[ibin].Zero(); totmult[ibin].ResizeTo(nptV); totmult[ibin].Zero(); avgpt[ibin].ResizeTo(nptV); Qx1[ibin].ResizeTo(nptV); Qx1[ibin].Zero(); Qy1[ibin].ResizeTo(nptV); Qy1[ibin].Zero(); Q2[ibin].ResizeTo(nptV); Q2[ibin].Zero(); sigma2_[ibin].ResizeTo(nptV);sigma2_[ibin].Zero(); chi_[ibin].ResizeTo(nptV);chi_[ibin].Zero(); } for(int ifile=0; ifile<nFileAll; ifile++){ if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/lio/lfs/cms/store/user/qixu/flow/pbsjoboutput/PFcandpt03to6/M300260/AnaV_Sum_%d.root",ifile)); else f[ifile] = TFile::Open(Form("/lio/lfs/cms/store/user/qixu/flow/pbsjoboutput/PFcandpt03to6/M300260/AnaV_Prod_%d.root",ifile)); TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get(Form("Nevent")); TVectorD* totmultall_t = (TVectorD*)f[ifile]->Get(Form("totmultall")); TVectorD* tottrk_t = (TVectorD*)f[ifile]->Get(Form("tottrk")); for(int ibin=0;ibin<nbin;ibin++){ for(int iptbin=0;iptbin<nptV;iptbin++){ for(int itheta=0;itheta<ntheta;itheta++){ GRe_t[ibin][iptbin][itheta] = (TVectorD*)f[ifile]->Get(Form("GRe_%d_%d_%d",ibin,iptbin,itheta)); GIm_t[ibin][iptbin][itheta] = (TVectorD*)f[ifile]->Get(Form("GIm_%d_%d_%d",ibin,iptbin,itheta)); for(ir=0; ir<nstepr; ir++){ GRe[ibin][iptbin][itheta][ir] += (*GRe_t[ibin][iptbin][itheta])[ir]; GIm[ibin][iptbin][itheta][ir] += (*GIm_t[ibin][iptbin][itheta])[ir]; } } } TVectorD* Qx1_t = (TVectorD*)f[ifile]->Get(Form("Qx1_%d",ibin)); TVectorD* Qy1_t = (TVectorD*)f[ifile]->Get(Form("Qy1_%d",ibin)); TVectorD* Q2_t = (TVectorD*)f[ifile]->Get(Form("Q2_%d",ibin)); TVectorD* totmult_t = (TVectorD*)f[ifile]->Get(Form("totmult_%d",ibin)); TVectorD* totpt_t = (TVectorD*)f[ifile]->Get(Form("totpt_%d",ibin)); for(int iptbin=0;iptbin<nptV;iptbin++){ Qx1[ibin][iptbin] += (*Qx1_t)[iptbin]; Qy1[ibin][iptbin] += (*Qy1_t)[iptbin]; Q2[ibin][iptbin] += (*Q2_t)[iptbin]; totmult[ibin][iptbin] += (*totmult_t)[iptbin]; totpt[ibin][iptbin] += (*totpt_t)[iptbin]; } Nevent[ibin] += (*Nevent_t)[ibin]; totmultall[ibin] += (*totmultall_t)[ibin]; tottrk[ibin] += (*tottrk_t)[ibin]; } f[ifile]->Close(); } fstrV<<setprecision(4)<<fixed; fstrV<<"ibin"<<"\t"<<"iptbin"<<"\t"<<"itheta"<<"\t"<<"r0"<<"\t"<<"V"<<"\t"<<"sigma2"<<"\t"<<"chi"<<"\t"<<"Vn Errors"<<endl; for(int ibin=0;ibin<nbin;ibin++){ avgmultall[ibin]=totmultall[ibin]/Nevent[ibin]; avgtrk[ibin]=tottrk[ibin]/Nevent[ibin]; for(int iptbin=0;iptbin<nptV;iptbin++){ for(int itheta=0;itheta<ntheta;itheta++){ for(ir=0; ir<nstepr; ir++){ G[ibin][iptbin][itheta][ir]=TComplex(GRe[ibin][iptbin][itheta][ir],GIm[ibin][iptbin][itheta][ir]); G[ibin][iptbin][itheta][ir]/=Nevent[ibin]; Gmod2[ibin][iptbin][itheta][ir]=TMath::Power(TComplex::Abs(G[ibin][iptbin][itheta][ir]),2); } for(ir=0; ir<nstepr-1; ir++) if(ir!=0 && Gmod2[ibin][iptbin][itheta][ir]<=Gmod2[ibin][iptbin][itheta][ir-1] && Gmod2[ibin][iptbin][itheta][ir]<=Gmod2[ibin][iptbin][itheta][ir+1]) break; if(ir!=0 && ir<nstepr-1) r0[ibin][iptbin][itheta]=r[ibin][ir]; else if(ir==0) {cout<<"ibin="<<ibin<<"\t"<<"iptbin="<<iptbin<<"\t"<<"itheta="<<itheta<<"\tminimum lies on ir = 0, please select proper range!"<<endl; continue;} else {cout<<"ibin="<<ibin<<"\t"<<"iptbin="<<iptbin<<"\t"<<"itheta="<<itheta<<"\tminimum lies on ir = maximum "<<nstepr-1<<", please select proper range!"<<endl; continue;} avgmult[ibin][iptbin]=1.0*totmult[ibin][iptbin]/Nevent[ibin]; avgpt[ibin][iptbin]=1.0*totpt[ibin][iptbin]/totmult[ibin][iptbin]; if(isSimple==0) V[ibin][iptbin][itheta]=Vmax[ibin]-ir*eps[ibin]+eps[ibin]*(Gmod2[ibin][iptbin][itheta][ir+1]-Gmod2[ibin][iptbin][itheta][ir-1])/2./(Gmod2[ibin][iptbin][itheta][ir-1]-2*Gmod2[ibin][iptbin][itheta][ir]+Gmod2[ibin][iptbin][itheta][ir+1]); else V[ibin][iptbin][itheta]=j01/r0[ibin][iptbin][itheta]; //simple method V[ibin][iptbin][itheta]/=avgmult[ibin][iptbin]; sigma2[ibin][iptbin][itheta]=Q2[ibin][iptbin]/Nevent[ibin]-(Qx1[ibin][iptbin]/Nevent[ibin])*(Qx1[ibin][iptbin]/Nevent[ibin])-(Qy1[ibin][iptbin]/Nevent[ibin])*(Qy1[ibin][iptbin]/Nevent[ibin])-(V[ibin][iptbin][itheta]*avgmult[ibin][iptbin])*(V[ibin][iptbin][itheta]*avgmult[ibin][iptbin]); sigma2_[ibin][iptbin]+=sigma2[ibin][iptbin][itheta]; Vmean[ibin][iptbin]+=V[ibin][iptbin][itheta]; chi[ibin][iptbin][itheta]=V[ibin][iptbin][itheta]*avgmult[ibin][iptbin]/TMath::Sqrt(sigma2[ibin][iptbin][itheta]); deltaV[ibin][iptbin][itheta]=V[ibin][iptbin][itheta]/j01/TMath::BesselJ1(j01)*TMath::Sqrt((TMath::Exp(j01*j01/2./chi[ibin][iptbin][itheta]/chi[ibin][iptbin][itheta])+TMath::Exp(-j01*j01/2./chi[ibin][iptbin][itheta]/chi[ibin][iptbin][itheta])*TMath::BesselJ0(2*j01))/2./Nevent[ibin]); fstrV<<ibin<<"\t"<<iptbin<<"\t"<<itheta<<"\t"<<r0[ibin][iptbin][itheta]<<"\t"<<V[ibin][iptbin][itheta]<<"\t"<<sigma2[ibin][iptbin][itheta]<<"\t"<<chi[ibin][iptbin][itheta]<<"\t"<<deltaV[ibin][iptbin][itheta]<<endl; } //deltaVmean[ibin][iptbin]+=TMath::Exp(j01*j01/2./chi[ibin][iptbin][itheta]/chi[ibin][iptbin][itheta]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Exp(-j01*j01/2./chi[ibin][iptbin][itheta]/chi[ibin][iptbin][itheta]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.)); sigma2_[ibin][iptbin]/=ntheta; Vmean[ibin][iptbin]/=ntheta; sigma2_[ibin][iptbin]-=TMath::Power(Vmean[ibin][iptbin]*avgmult[ibin][iptbin],2); chi_[ibin][iptbin]=Vmean[ibin][iptbin]*avgmult[ibin][iptbin]/TMath::Sqrt(sigma2_[ibin][iptbin]); for(int itheta=0;itheta<ntheta;itheta++){ deltaVmean[ibin][iptbin]+=TMath::Exp(j01*j01/2./chi_[ibin][iptbin]/chi_[ibin][iptbin]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Exp(-j01*j01/2./chi_[ibin][iptbin]/chi_[ibin][iptbin]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.)); } fstrV<<endl; deltaVmean[ibin][iptbin]=Vmean[ibin][iptbin]/j01/TMath::BesselJ1(j01)*TMath::Sqrt(deltaVmean[ibin][iptbin]/ntheta/2./Nevent[ibin]); } fstrV<<endl; } fstrV<<"ibin"<<"\t"<<"iptbin"<<"\t"<<"avgmult"<<"\t"<<"avgpt"<<"\t"<<"Vn mean"<<"\t"<<"Vn mean Error"<<endl; for(int ibin=0;ibin<nbin;ibin++){ for(int iptbin=0;iptbin<nptV;iptbin++){ fstrV<<ibin<<"\t"<<iptbin<<"\t"<<avgmult[ibin][iptbin]<<"\t"<<avgpt[ibin][iptbin]<<"\t"<<Vmean[ibin][iptbin]<<"\t"<<deltaVmean[ibin][iptbin]<<endl; } fstrV<<endl; } fstrV<<"ibin"<<"\t"<<"Nevent"<<"\t"<<"totmultall"<<"\t"<<"avgmultall"<<"\t"<<"avgtrk"<<endl; for(int ibin=0;ibin<nbin;ibin++){ fstrV<<ibin<<"\t"<<Nevent[ibin]<<"\t"<<totmultall[ibin]<<"\t"<<avgmultall[ibin]<<"\t"<<avgtrk[ibin]<<endl; fstrV<<endl; } if(SumorProd=="Sum") TString outname = "mergedV_Sum.root"; else TString outname="mergedV_Prod.root"; TFile *outf = new TFile(outname,"Recreate"); Nevent.Write("Nevent"); totmultall.Write("totmultall"); avgmultall.Write("avgmultall"); tottrk.Write("tottrk"); avgtrk.Write("avgtrk"); for(int ibin=0;ibin<nbin;ibin++){ TDirectory *dir0 = outf->mkdir(Form("D_%d",ibin,itheta));dir0->cd(); r[ibin].Write("r"); Qx1[ibin].Write("Qx1"); Qy1[ibin].Write("Qy1"); Q2[ibin].Write("Q2"); totmult[ibin].Write("totmult"); totpt[ibin].Write("totpt"); avgmult[ibin].Write("avgmult"); avgpt[ibin].Write("avgpt"); Vmean[ibin].Write("Vmean"); deltaVmean[ibin].Write("deltaVmean"); for(int iptbin=0;iptbin<nptV;iptbin++){ TDirectory *dir1 = dir0->mkdir(Form("D_%d",iptbin));dir1->cd(); sigma2[ibin][iptbin].Write("sigma2"); chi[ibin][iptbin].Write("chi"); deltaV[ibin][iptbin].Write("deltaV"); r0[ibin][iptbin].Write("r0"); V[ibin][iptbin].Write("V"); for(int itheta=0;itheta<ntheta;itheta++){ TDirectory *dir2 = dir1->mkdir(Form("D_%d",itheta));dir2->cd(); GRe[ibin][iptbin][itheta].Write(Form("GRe")); GIm[ibin][iptbin][itheta].Write(Form("GIm")); Gmod2[ibin][iptbin][itheta].Write(Form("G2")); } } } outf->Close(); }