void spectator(Float_t b, Int_t* NSpectp, Int_t* NSpectn) { Float_t SppvsB[6] = {3.633,-1.518,1.360,-.4899e-1,-.2398e-2,.1066e-3}; Float_t SpnvsB[6] = {5.639,-1.685,1.803,-.3129e-1,-.6618e-2,.2352e-3}; Float_t Sigmap[4] = {.5668,-.2200e-1,.3657e-3,-.2201e-5}; Float_t Sigman[4] = {.4185,-.9798e-2,.1052e-3,-.4238e-6}; Float_t rnsp = SppvsB[0]+SppvsB[1]*b+SppvsB[2]*(b*b)+SppvsB[3]*(b*b*b)+ SppvsB[4]*(b*b*b*b)+SppvsB[5]*(b*b*b*b*b); Float_t rnsn = SpnvsB[0]+SpnvsB[1]*b+SpnvsB[2]*(b*b)+SpnvsB[3]*(b*b*b)+ SpnvsB[4]*(b*b*b*b)+SpnvsB[5]*(b*b*b*b*b); Float_t snsp = Sigmap[0]+Sigmap[1]*rnsp+Sigmap[2]*(rnsp*rnsp)+Sigmap[3]* (rnsp*rnsp*rnsp); Float_t snsn = Sigman[0]+Sigman[1]*rnsn+Sigman[2]*(rnsn*rnsn)+Sigman[3]* (rnsn*rnsn*rnsn); snsp = snsp*rnsp; snsn = snsn*rnsn; Float_t xgaup = gRandom->Gaus(0.0,1.0); snsp = snsp*xgaup; Float_t xgaun = gRandom->Gaus(0.0,1.0); snsn = snsn*xgaun; rnsp=rnsp+snsp; rnsn=rnsn+snsn; *NSpectp = Int_t(rnsp); *NSpectn = Int_t(rnsn); }
void flower() { //0. Indices for custom colors. Color_t indices[3] = {}; if (FindFreeCustomColorIndices(3, indices) != 3) { ::Error("flower", "failed to create custom colors"); return; } //1. I have to create a canvas to initialize gVirtualX. TCanvas * const cnv = new TCanvas("Chrysanthemum", "Chrysanthemum", 900, 900); if (gVirtualX && !gVirtualX->InheritsFrom("TGCocoa")) { ::Error("flower", "This macro requires OS X version of ROOT with cocoa enabled"); delete cnv; return; } cnv->cd();//Just to suppress a warning if compiled. vector_type xs, ys; //2. Create graphs and custom colors for each graph. create_flower(xs, ys, 300, 6); TGraph * const gr1 = new TGraph(Int_t(xs.size()), &xs[0], &ys[0]); new TColor(indices[0], 0., 0., 0.5, "custom_blue", 0.7); gr1->SetFillColor(indices[0]); gr1->SetName("part1"); gr1->SetTitle("part1"); create_flower(xs, ys, 500000, 8); TGraph * const gr2 = new TGraph(Int_t(xs.size()), &xs[0], &ys[0]); new TColor(indices[1], 0.5, 0., 0.5, "custom_purple", 0.5); gr2->SetFillColor(indices[1]); gr2->SetName("part2"); gr2->SetTitle("part2"); create_flower(xs, ys, 100000, 10); TGraph * const gr3 = new TGraph(Int_t(xs.size()), &xs[0], &ys[0]); //If you want to see the difference, change 0.2 to 1 in the next call: new TColor(indices[2], 1., 0., 0.4, "custom_magenta", 0.2); gr3->SetFillColor(indices[2]); gr3->SetName("part3"); gr3->SetTitle("part3"); //3. Create a final multigraph. //Otcveli, uzh davno ... nu ti ponEl. TMultiGraph * const flower = new TMultiGraph("Chrysanthemum", "Chrysanthemum"); flower->Add(gr1); flower->Add(gr2); flower->Add(gr3); flower->Draw("AFP"); }
void OneBin(Int_t bin, TH1* h0900, TH1* h2760, TH1* h7000, TH1* h8000, TMultiGraph* mg, TNtuple* tuple, Double_t sysErr=0.076) { Info("OneBin", "Getting one bin %d,%p,%p,%p,%p,%p", bin, h0900,h2760,h7000,h8000,tuple); Double_t eta = h0900->GetXaxis()->GetBinCenter(bin); Double_t w = h0900->GetXaxis()->GetBinWidth(bin); Info("", "Eta=%f +/- %f", eta, w); Double_t e[] = { 900., 2760., 7000., 8000., 0 }; TH1* h[] = { h0900, h2760, h7000, h8000, 0 }; Float_t x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; x[0] = eta; x[1] = w; TGraphErrors* g = new TGraphErrors(0); g->SetName(Form("eta%03d", bin)); g->SetTitle(Form("%f", eta)); g->SetMarkerStyle(bin % 10 + 20); g->SetMarkerColor(bin % 6 + 2); Double_t* pe = e; TH1** ph = h; Int_t i = 0; Int_t j = 1; while (*pe && *ph) { Double_t c = (*ph)->GetBinContent(bin); Double_t v = sysErr*c; if (c > 1e-6){ g->SetPoint(i, *pe, c); g->SetPointError(i, w, v); x[Int_t(2*j+0)] = c; x[Int_t(2*j+1)] = v; i++; } j++; pe++; ph++; } if (tuple) tuple->Fill(x); if (i > 0) mg->Add(g); else delete g; }
void tclwrite(Int_t split) { // Generate a Tree with a TClonesArray // The array can be split or not TFile f("tcl.root","recreate"); f.SetCompressionLevel(1); //try level 2 also TTree T("T","test tcl"); TClonesArray *arr = new TClonesArray("TLine"); TClonesArray &ar = *arr; T.Branch("tcl",&arr,256000,split); //By default a TClonesArray is created with its BypassStreamer bit set. //However, because TLine has a custom Streamer, this bit was reset //by TTree::Branch above. We set again this bit because the current //version of TLine uses the automatic Streamer. //BypassingStreamer saves space and time. arr->BypassStreamer(); for (Int_t ev=0;ev<10000;ev++) { ar.Clear(); Int_t nlines = Int_t(gRandom->Gaus(50,10)); if(nlines < 0) nlines = 1; for (Int_t i=0;i<nlines;i++) { Float_t x1 = gRandom->Rndm(); Float_t y1 = gRandom->Rndm(); Float_t x2 = gRandom->Rndm(); Float_t y2 = gRandom->Rndm(); new(ar[i]) TLine(x1,y1,x2,y2); } T.Fill(); } T.Print(); T.Write(); }
void tread(const char* input) { std::cout << "Input file : " << input << std::endl; A* a = new A(); TFile* tfi = new TFile(input,"READ"); TTree* tree = (TTree*)tfi->Get("tree"); tree->SetBranchAddress("A",&a); Int_t nevent = Int_t(tree->GetEntries()); for (Int_t jentry=0; jentry<nevent;jentry++) { Int_t ientry = tree->LoadTree(jentry); if (ientry < 0) break; tree->GetEntry(jentry); //a->Dump(); a->Dump2(); } tfi->Close(); delete a; }
//Return a graph of the llscan TGraph * LLscanResult::GetGraph() { double* pvs = new double[parameterValues.size()] ; double* llvs = new double[parameterValues.size()] ; double llmax = 0 ; for(unsigned int i=0; i< parameterValues.size() ; ++i ){ pvs[i] = parameterValues[i] ; llvs[i] = llvalues_offset[i] ; if( llvs[i] > llmax ) llmax = llvs[i] ; } TGraph* gr = new TGraph( Int_t(parameterValues.size()), pvs, llvs ) ; //gr->SetTitle("LL Scan for Parameter xxx"); gr->SetMarkerStyle(1); gr->SetLineWidth(2); gr->SetMarkerColor(4); gr->SetLineColor(4); gr->GetYaxis()->SetRangeUser( 0., llmax*1.2 ); gr->GetYaxis()->SetLimits( 0., llmax*1.2 ); gr->SetMinimum( 0.0 ); gr->SetMaximum( llmax*1.2 ); gr->Draw("ALP"); string title("LL Scan for Parameter ") ; title+=parameterName.c_str(); gr->SetTitle(title.c_str()); gr->GetXaxis()->SetTitle(parameterName.c_str()); return gr ; }
void stereo_straw_g1() { ostringstream fname; fname << "stereo_straw_" << numLayers << "_layers_" << Int_t(floor(innerRadius)) << "_x_" << Int_t(floor(outerRadius)) << ".01.geo"; const char* filename = (fname.str()).c_str(); // output file for straw endcap geometry ofstream* f = new ofstream(filename, ios::out | ios::trunc); //************************* Main procedure START ***************************** Mpdshape* layer = initDrawLayer(f, TVector3(angleLayers, 0.0, 0.0), TVector3(0, 0, initDist + layerThickness/2.0), 0); Mpdshape* layerR = initDrawLayer(f, TVector3(angleLayers, 0.0, 0.0), TVector3(0, 0, initDist + layerThickness*1 + layerThickness/2.0), angleStereo); Mpdshape* layerL = initDrawLayer(f, TVector3(angleLayers, 0.0, 0.0), TVector3(0, 0, initDist + layerThickness*2 + layerThickness/2.0), -angleStereo); drawLayer(layer, TVector3(angleLayers,0,0), TVector3(0,0,initDist + layerThickness*3 + layerThickness/2.0)); for (Int_t i = 4; i < numLayers; i+=4) { drawLayer(layer, TVector3((i/4.+1)*angleLayers,0,0), TVector3(0,0, initDist + layerThickness/2.0 + i*layerThickness)); drawLayer(layerR, TVector3((i/4.+1)*angleLayers,0,0), TVector3(0,0, initDist + layerThickness/2.0 + (i+1)*layerThickness)); drawLayer(layerL, TVector3((i/4.+1)*angleLayers,0,0), TVector3(0,0, initDist + layerThickness/2.0 + (i+2)*layerThickness)); drawLayer(layer, TVector3((i/4.+1)*angleLayers,0,0), TVector3(0,0, initDist + layerThickness/2.0 + (i+3)*layerThickness)); } //*********************** Main procedure END ********************************* delete layerL; delete layer; delete layerR; f->close(); return; }
void RecAna::Loop() { // In a Root session, you can do: // Root > .L RecAna.C // Root > RecAna t(filename) // Root > t.GetEvent(evt); // Fill t data members with event number evt // Root > t.Show(); // Show values of current event e // Root > t.Show(evt); // Read and show values of entry evt // Root > t.Loop(); // Loop on all entries // // This is the loop skeleton // To read only selected branches, Insert statements like: // METHOD1: // fTree->SetBranchStatus("*",0); // disable all branches // fTree->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fTree->GetEntry(i); // read all branches //by b_branchname->GetEntry(i); //read only this branch if (fTree == 0) return; Int_t nentries = Int_t(fTree->GetEntries()); Int_t nbytes = 0, nb = 0; for (Int_t i=0; i<nentries;i++) { if (LoadTree(i) < 0) break; nb = fTree->GetEntry(i); nbytes += nb; } }
Int_t EventAnalyzer::XYtoIndex(Double_t x, Double_t y) { if(x < -54. || x >= 54. || y < -36. || y >= 36.){ cout << "The coordinate is out of range. x = " << x << ", y = " << y << endl; exit(0); } TString alphabet[8] = {"A", "B", "C", "D", "E", "F", "G", "H"}; x += 9. * 6.; y += 9. * 4.; Int_t wellX = Int_t(x / 9.); Int_t wellY = Int_t(y / 9.); return (wellX + wellY * 12); }
//____________________________________________________________________ TH1* One(TDirectory* newDir, TDirectory* oldDir, Double_t c1, Double_t c2) { TString name; name.Form("cent%03dd%02d_%03dd%02d", Int_t(c1), Int_t(c1*100)%100, Int_t(c2), Int_t(c2*100)%100); TDirectory* newSubDir = GetD(newDir, name); TDirectory* oldSubDir = GetD(oldDir, name); if (!newSubDir || !oldSubDir) return 0; Int_t newDim = 0; if (TString(newDir->GetName()).Contains("etaipz")) newDim = 3; else if (TString(newDir->GetName()).Contains("eta")) newDim = 2; else if (TString(newDir->GetName()).Contains("const")) newDim = 1; Int_t oldDim = 0; if (TString(oldDir->GetName()).Contains("etaipz")) oldDim = 3; else if (TString(oldDir->GetName()).Contains("eta")) oldDim = 2; else if (TString(oldDir->GetName()).Contains("const")) oldDim = 1; TDirectory* newSubSubDir = GetD(newSubDir, Form("results%dd",newDim)); TDirectory* oldSubSubDir = GetD(oldSubDir, Form("results%dd",oldDim)); if (!newSubSubDir || !oldSubSubDir) return 0; TH1* newRes = GetH1(newSubSubDir, "result"); TH1* oldRes = GetH1(oldSubSubDir, "result"); if (!newRes || !oldRes) return 0; TH1* ratio = static_cast<TH1*>(newRes->Clone(name)); ratio->SetDirectory(0); ratio->SetTitle(Form("%5.1f - %5.1f%%", c1, c2)); ratio->SetYTitle("New / Old"); ratio->Divide(oldRes); fMin = TMath::Min(fMin, ratio->GetMinimum()); fMax = TMath::Max(fMax, ratio->GetMaximum()); Printf("Calculated %s/%s", newDir->GetName(), oldDir->GetName()); if (!fLegend) return ratio; TLegendEntry* e = fLegend->AddEntry("", Form("%3.0f - %3.0f%%", c1, c2), "f"); e->SetFillStyle(1001); e->SetFillColor(ratio->GetMarkerColor()); return ratio; }
TString EventAnalyzer::XYtoWell(Double_t x, Double_t y) { if(x < -54. || x >= 54. || y < -36. || y >= 36.){ cout << "The coordinate is out of range. x = " << x << ", y = " << y << endl; exit(0); } TString alphabet[8] = {"H", "G", "F", "E", "D", "C", "B", "A"}; x += 9. * 6.; y += 9. * 4.; Int_t wellX = Int_t(x / 9.); Int_t wellY = Int_t(y / 9.); // readable? return Form("%s%02d", alphabet[wellY].Data(), wellX + 1); }
void tv3Read1() { //first read example showing how to read all branches TVector3 *v = 0; TFile *f = new TFile("v3.root"); TTree *T = (TTree*)f->Get("T"); T->SetBranchAddress("v3",&v); TH1F *h1 = new TH1F("x","x component of TVector3",100,-3,3); Int_t nentries = Int_t(T->GetEntries()); for (Int_t i=0;i<nentries;i++) { T->GetEntry(i); h1->Fill(v->x()); } h1->Draw(); }
void tv3Read2() { //second read example illustrating how to read one branch only TVector3 *v = 0; TFile *f = new TFile("v3.root"); TTree *T = (TTree*)f->Get("T"); T->SetBranchAddress("v3",&v); TBranch *by = T->GetBranch("fY"); TH1F *h2 = new TH1F("y","y component of TVector3",100,-5,20); Int_t nentries = Int_t(T->GetEntries()); for (Int_t i=0;i<nentries;i++) { by->GetEntry(i); h2->Fill(v->y()); } h2->Draw(); }
TH1* his( TH1* input, Int_t nbins, Double_t xlow, Double_t xhigh ) { if ( !input ) { return 0; } TString name( TString(input->GetName()) + "Clone" ); TH1F* output = new TH1F( name, "", input->GetNbinsX(), xlow, xhigh ); for ( Int_t bin = 1; bin < input->GetNbinsX()+1; ++bin ) { Double_t centre = input->GetBinLowEdge(bin) + input->GetBinWidth(bin)/2.; if ( centre > xlow && centre < xhigh && input->GetBinContent(bin) > 0. ) { output->Fill( centre, input->GetBinContent(bin) ); } } output->Sumw2(); output->Rebin(Int_t(input->GetNbinsX()/nbins)); return output; }
/* * This function, when fed a histogram, tree, * a floating point min_value variable, and a boolean, will fill each entry * inside the specificed branch into the histogram, so long as each entry * is a floating point number GREATER than the min_value. If normalize is * set to 'true', the histogram will be normalize based on its number of * entries. The axes titles are furthermore assumed to be generic and have * been already set. */ void fill_histogram(TH1F * const h, TTree * const t, const Float_t min_value) { Float_t measured_energy; Float_t true_energy; t->SetBranchAddress("e", &measured_energy); t->SetBranchAddress("ge", &true_energy); Int_t nentries = Int_t(t->GetEntries()); for (Int_t i = 0; i < nentries; ++i) { if (t->LoadTree(i) < 0) break; t->GetEntry(i); if (measured_energy > min_value && true_energy > 0.1) h->Fill(measured_energy); } }
TH1D * smartGausProfileXSQRTN (TH2F * strip, double width){ TProfile * stripProfile = strip->ProfileX () ; // (from FitSlices of TH2.h) double xmin = stripProfile->GetXaxis ()->GetXmin () ; double xmax = stripProfile->GetXaxis ()->GetXmax () ; int profileBins = stripProfile->GetNbinsX () ; std::string name = strip->GetName () ; name += "_smartGaus_X" ; TH1D * prof = new TH1D(name.c_str (),strip->GetTitle (),profileBins,xmin,xmax) ; int cut = 0 ; // minimum number of entries per fitted bin int nbins = strip->GetXaxis ()->GetNbins () ; int binmin = 1 ; int ngroup = 1 ; // bins per step int binmax = nbins ; // loop over the strip bins for (int bin=binmin ; bin<=binmax ; bin += ngroup) { TH1D *hpy = strip->ProjectionY ("_temp",bin,bin+ngroup-1,"e") ; if (hpy == 0) continue ; int nentries = Int_t (hpy->GetEntries ()) ; if (nentries == 0 || nentries < cut) {delete hpy ; continue ;} Int_t biny = bin + ngroup/2 ; TF1 * gaussian = new TF1 ("gaussian","gaus", hpy->GetMean () - width * hpy->GetRMS (), hpy->GetMean () + width * hpy->GetRMS ()) ; gaussian->SetParameter (1,hpy->GetMean ()) ; gaussian->SetParameter (2,hpy->GetRMS ()) ; hpy->Fit ("gaussian","RQL") ; // hpy->GetXaxis ()->SetRangeUser ( hpy->GetMean () - width * hpy->GetRMS (), hpy->GetMean () + width * hpy->GetRMS ()) ; prof->Fill (strip->GetXaxis ()->GetBinCenter (biny), gaussian->GetParameter (1)) ; prof->SetBinError (biny,gaussian->GetParameter (2) / sqrt(hpy->GetEntries())) ; // prof->SetBinError (biny,gaussian->GetParError (1)) ; delete gaussian ; delete hpy ; } // loop over the bins delete stripProfile ; return prof ; }
Bool_t TZigZag::NearestPoints(Double_t x, TArrayI &I, TArrayD &W) const { // One-dimensional case. Gives the 2 nearest points from point x in zigzag numbering. //W are weights for the points, calculated according to the inverse of their distances //from x const Double_t un = 1.0; const Double_t eps = 1.0e-12; Int_t k; Double_t xl,xr,x1,x2,dx,dxs2,w0,w1,wt; I.Set(2); W.Set(2); dx = (fXmax-fXmin)/fNx; dxs2 = dx/2; xl = dxs2; xr = dxs2 + (fNx-1)*dx; if (x<xl) { I[0] = 0; I[1] = 1; x1 = dxs2; x2 = dxs2 + dx; } else { if (x>xr) { I[0] = fNx - 1; I[1] = fNx - 2; x1 = dxs2 + (fNx-1)*dx; x2 = x1 - dx; } else { k = Int_t((x-dxs2)/dx); I[0] = k; I[1] = k+1; x1 = dxs2 + k*dx; x2 = x1 + dx; } } w0 = TMath::Abs(x1-x); if (w0<eps) w0 = eps; w0 = un/w0; w1 = TMath::Abs(x2-x); if (w1<eps) w1 = eps; w1 = un/w1; wt = w0 + w1; W[0] = w0/wt; W[1] = w1/wt; return kTRUE; }
void tree::Loop() { if (fChain == 0) return; Int_t nentries = Int_t(fChain->GetEntriesFast()); Int_t nbytes = 0, nb = 0; for (Int_t jentry=0; jentry<nentries;jentry++) { Int_t ientry = LoadTree(jentry); if (ientry < 0) break; nbytes = fChain->GetEntry(jentry); for (Int_t i = 0; i < foo_; i++) cout << "Foo: " << foo_fFoo[i] << endl; } }
void TestShaping(int max=4) { TArrayI adcs(10); TGraph* orig = new TGraph(adcs.fN); orig->SetName("Original"); orig->SetTitle("Original"); orig->SetMarkerStyle(25); orig->SetMarkerColor(1); orig->SetMarkerSize(2); orig->SetLineColor(1); for (Int_t i = 0; i < adcs.fN; i++) { adcs.fArray[i] = Int_t(gRandom->Uniform(0, 1023)); orig->SetPoint(i, i, adcs.fArray[i]); } TCanvas* c = new TCanvas("c", "c"); c->SetFillColor(0); c->SetTopMargin(.02); c->SetRightMargin(.02); TH1* h = new TH1F("frame","frame", adcs.fN+1, -2, adcs.fN); h->SetMinimum(0); h->SetMaximum(1300); h->SetStats(0); h->Draw(""); orig->Draw("pl same"); TLegend* l = new TLegend(adcs.fN*3./4, 1023, adcs.fN, 1300, "", ""); l->SetFillColor(0); l->SetBorderSize(1); l->AddEntry(orig, orig->GetTitle(), "lp"); for (int i = 1; i <= max; i++) { TGraph* g = makeGraph(adcs, i); g->Draw("pl same"); l->AddEntry(g, g->GetTitle(), "lp"); } l->Draw(); c->Modified(); c->Update(); c->cd(); }
Bool_t TGeoPgon::Contains(Double_t *point) const { // test if point is inside this shape // check total z range if (point[2]<fZ[0]) return kFALSE; if (point[2]>fZ[fNz-1]) return kFALSE; Double_t divphi = fDphi/fNedges; // now check phi Double_t phi = TMath::ATan2(point[1], point[0])*TMath::RadToDeg(); while (phi < fPhi1) phi += 360.0; Double_t ddp = phi-fPhi1; if (ddp>fDphi) return kFALSE; // now find phi division Int_t ipsec = TMath::Min(Int_t(ddp/divphi), fNedges-1); Double_t ph0 = (fPhi1+divphi*(ipsec+0.5))*TMath::DegToRad(); // now check projected distance Double_t r = point[0]*TMath::Cos(ph0) + point[1]*TMath::Sin(ph0); // find in which Z section the point is in Int_t iz = TMath::BinarySearch(fNz, fZ, point[2]); if (iz==fNz-1) { if (r<fRmin[iz]) return kFALSE; if (r>fRmax[iz]) return kFALSE; return kTRUE; } Double_t dz = fZ[iz+1]-fZ[iz]; Double_t rmin, rmax; if (dz<1E-8) { // we are at a radius-changing plane rmin = TMath::Min(fRmin[iz], fRmin[iz+1]); rmax = TMath::Max(fRmax[iz], fRmax[iz+1]); if (r<rmin) return kFALSE; if (r>rmax) return kFALSE; return kTRUE; } // now compute rmin and rmax and test the value of r Double_t dzrat = (point[2]-fZ[iz])/dz; rmin = fRmin[iz]+dzrat*(fRmin[iz+1]-fRmin[iz]); // is the point inside the 'hole' at the center of the volume ? if (r < rmin) return kFALSE; rmax = fRmax[iz]+dzrat*(fRmax[iz+1]-fRmax[iz]); if (r > rmax) return kFALSE; return kTRUE; }
void tester::Loop() { if (fChain == 0) return; int aa = 1000; int nn = 0; Int_t nentries = Int_t(fChain->GetEntriesFast()); Int_t nbytes = 0, nb = 0; for (Int_t jentry=0; jentry<=10000;jentry++) { // for (Int_t jentry=0; jentry<nentries;jentry++) { Int_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; if(jentry/aa>nn) cout << "Event #" << jentry << endl; nn = jentry/aa; } cout << "complete"; }
void analyze(Int_t step){ // TOF propagation factors (TOF efficiencies) fEfficiencyPiTOF = new TF1("fEfficiencyPiTOF","(x > 0.3)*0.7",0,10); fEfficiencyKaTOF = new TF1("fEfficiencyKaTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10); fEfficiencyPrTOF = new TF1("fEfficiencyPrTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10); // teoretical separation (perfect if equal to the one simualted in sim.C) fseparation = new TF1("f","[0]+[1]/x",0,100); fseparation->SetParameter(0,0.); fseparation->SetParameter(1,7.); fseparationPiKa = new TF1("fPiKa","[0]+[1]/TMath::Power(x,2.5)",0,100); fseparationPiKa->SetParameter(0,2.34); fseparationPiKa->SetParameter(1,10); fseparationKaPr = new TF1("fKaPr","[0]+[1]/TMath::Power(x,2.5)",0,100); fseparationKaPr->SetParameter(0,1); fseparationKaPr->SetParameter(1,56); // x=p, y=pt/p (normalized at the number of sigma assuming 80 ps resolution) fTOFpi = new TF2("fTOFpi","3.7/y*(sqrt(x*x+0.0193210)/x-1)*37.47405725",0.3,10,0.5,1); fTOFka = new TF2("fTOFka","3.7/y*(sqrt(x*x+0.243049)/x-1)*37.47405725",0.3,10,0.5,1); fTOFpr = new TF2("fTOFpr","3.7/y*(sqrt(x*x+0.879844)/x-1)*37.47405725",0.3,10,0.5,1); // x=p, already normalized in number of sigma (sigma assumed 3.5=7% of the MIP) fTPCpi = new TF1("fTPCpi",BetheBlochAleph,0,10,6); fTPCpi->SetParameter(0,fKp1); fTPCpi->SetParameter(1,fKp2); fTPCpi->SetParameter(2,fKp3); fTPCpi->SetParameter(3,fKp4); fTPCpi->SetParameter(4,fKp5); fTPCpi->SetParameter(5,0.139); fTPCka = new TF1("fTPCka",BetheBlochAleph,0,10,6); fTPCka->SetParameter(0,fKp1); fTPCka->SetParameter(1,fKp2); fTPCka->SetParameter(2,fKp3); fTPCka->SetParameter(3,fKp4); fTPCka->SetParameter(4,fKp5); fTPCka->SetParameter(5,0.493); fTPCpr = new TF1("fTPCpr",BetheBlochAleph,0,10,6); fTPCpr->SetParameter(0,fKp1); fTPCpr->SetParameter(1,fKp2); fTPCpr->SetParameter(2,fKp3); fTPCpr->SetParameter(3,fKp4); fTPCpr->SetParameter(4,fKp5); fTPCpr->SetParameter(5,0.938); Float_t width = 1.0; addshift =0; invwidth = 1./width; Float_t widthTOF = 1.0; addshiftTOF =0; invwidthTOF = 1./widthTOF; TH1D *priorsPt[6]; TH1D *newpriorsPt[6]; TH1D *truePt[6]; TH1D *allPtPos = new TH1D("allPtP","All positive;p_{T} (GeV/#it{c});N",100,0,10); TH1D *allPtNeg = new TH1D("allPtN","All negative;p_{T} (GeV/#it{c});N",100,0,10); TH3D *priorsKs[3][3]; TH3D *newpriorsKs[3][3]; TH3D *truePidKs[3][3]; TH3D *trueKs; TH2D *priorsPhi[3][3]; TH2D *newpriorsPhi[3][3]; TH2D *truePidPhi[3][3]; TH2D *truePhi; TH3D *priorsLc[3][3][3]; TH3D *newpriorsLc[3][3][3]; TH3D *truePidLc[3][3][3]; TH3D *trueLc,*mypidLc; TH3D *priorsLcbar[3][3][3]; TH3D *newpriorsLcbar[3][3][3]; TH3D *truePidLcbar[3][3][3]; TH3D *trueLcbar,*mypidLcbar; Int_t nbinPtFrKa = 8; Int_t nbinPtFrPi = 8; Int_t nbinY = 1; Int_t nbinpol=nbinPtFrKa*nbinPtFrPi*nbinY; Double_t normbin = 1./nbinpol; Int_t nbinmlc = 100; Int_t nbinptlc = 10; const char *spec[3] = {"Pi","Ka","Pr"}; if(step==0){ priorsPt[0] = new TH1D("oldpriorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10); for(Int_t i=1;i<=100;i++) priorsPt[0]->SetBinContent(i,1); priorsPt[1] = new TH1D("oldpriorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10); priorsPt[2] = new TH1D("oldpriorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10); priorsPt[3] = new TH1D("oldpriorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10); priorsPt[4] = new TH1D("oldpriorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10); priorsPt[5] = new TH1D("oldpriorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10); priorsPt[1]->Add(priorsPt[0]); priorsPt[2]->Add(priorsPt[0]); priorsPt[3]->Add(priorsPt[0]); priorsPt[4]->Add(priorsPt[0]); priorsPt[5]->Add(priorsPt[0]); // Ks and phi priors for(Int_t i=0; i< 3;i++){ for(Int_t j=0; j< 3;j++){ priorsKs[i][j] = new TH3D(Form("oldpriorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001); priorsPhi[i][j] = new TH2D(Form("oldpriorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10); if(i==0 && j==0){ for(Int_t ibx=1;ibx<=200;ibx++) for(Int_t iby=1;iby<=40;iby++){ for(Int_t ibz=1;ibz <= nbinpol;ibz++) priorsKs[i][j]->SetBinContent(ibx,iby,ibz,1); priorsPhi[i][j]->SetBinContent(ibx,iby,1); } } else{ priorsKs[i][j]->Add(priorsKs[0][0]); priorsPhi[i][j]->Add(priorsPhi[0][0]); } for(Int_t k=0; k< 3;k++){ priorsLc[i][j][k] = new TH3D(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); priorsLcbar[i][j][k] = new TH3D(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); if(i==0 && j==0 && k==0){ for(Int_t ibx=1;ibx<=nbinmlc;ibx++) for(Int_t iby=1;iby<=nbinptlc;iby++){ for(Int_t ibz=1;ibz <= nbinpol;ibz++){ priorsLc[i][j][k]->SetBinContent(ibx,iby,ibz,1); priorsLcbar[i][j][k]->SetBinContent(ibx,iby,ibz,1); } } } else{ priorsLc[i][j][k]->Add(priorsLc[0][0][0]); priorsLcbar[i][j][k]->Add(priorsLc[0][0][0]); } } } } } else{ TFile *fin = new TFile(Form("step%i.root",step)); priorsPt[0] = (TH1D *) fin->Get("priorsPtPiP"); priorsPt[0]->SetName("oldpriorsPtPiP"); priorsPt[1] = (TH1D *) fin->Get("priorsPtKaP"); priorsPt[1]->SetName("oldpriorsPtPiP"); priorsPt[2] = (TH1D *) fin->Get("priorsPtPrP"); priorsPt[2]->SetName("oldpriorsPtPiP"); priorsPt[3] = (TH1D *) fin->Get("priorsPtPiM"); priorsPt[3]->SetName("oldpriorsPtPiM"); priorsPt[4] = (TH1D *) fin->Get("priorsPtKaM"); priorsPt[4]->SetName("oldpriorsPtKaM"); priorsPt[5] = (TH1D *) fin->Get("priorsPtPrM"); priorsPt[5]->SetName("oldpriorsPtPrM"); // Ks and phi priors for(Int_t i=0; i< 3;i++){ for(Int_t j=0; j< 3;j++){ priorsKs[i][j] = (TH3D *) fin->Get(Form("priorsKs%s%s",spec[i],spec[j])); priorsKs[i][j]->SetName(Form("oldpriorsKs%s%s",spec[i],spec[j])); priorsPhi[i][j] = (TH2D *) fin->Get(Form("priorsPhi%s%s",spec[i],spec[j])); priorsPhi[i][j]->SetName(Form("oldpriorsPhi%s%s",spec[i],spec[j])); for(Int_t k=0; k< 3;k++){ priorsLc[i][j][k] = (TH3D *) fin->Get(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k])); priorsLc[i][j][k]->SetName(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k])); priorsLcbar[i][j][k] = (TH3D *) fin->Get(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k])); priorsLcbar[i][j][k]->SetName(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k])); } } } } newpriorsPt[0] = new TH1D("priorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10); newpriorsPt[1] = new TH1D("priorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10); newpriorsPt[2] = new TH1D("priorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10); newpriorsPt[3] = new TH1D("priorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10); newpriorsPt[4] = new TH1D("priorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10); newpriorsPt[5] = new TH1D("priorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10); // Ks and phi priors distributions for(Int_t i=0; i< 3;i++){ for(Int_t j=0; j< 3;j++){ newpriorsKs[i][j] = new TH3D(Form("priorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001); newpriorsPhi[i][j] = new TH2D(Form("priorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10); for(Int_t k=0; k< 3;k++){ newpriorsLc[i][j][k] = new TH3D(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); newpriorsLcbar[i][j][k] = new TH3D(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); } } } truePt[0] = new TH1D("truePtPiP","Pion (+) truth;p_{T} (GeV/#it{c});N",100,0,10); truePt[1] = new TH1D("truePtKaP","Kaon (+) truth;p_{T} (GeV/#it{c});N",100,0,10); truePt[2] = new TH1D("truePtPrP","Proton (+) truth;p_{T} (GeV/#it{c});N",100,0,10); truePt[3] = new TH1D("truePtPiM","Pion (-) truth;p_{T} (GeV/#it{c});N",100,0,10); truePt[4] = new TH1D("truePtKaM","Kaon (-) truth;p_{T} (GeV/#it{c});N",100,0,10); truePt[5] = new TH1D("truePtPrM","Proton (-) truth;p_{T} (GeV/#it{c});N",100,0,10); // Ks and phi truePid distributions for(Int_t i=0; i< 3;i++){ for(Int_t j=0; j< 3;j++){ truePidKs[i][j] = new TH3D(Form("truePidKs%s%s",spec[i],spec[j]),Form("K^{0*} truePid for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001); truePidPhi[i][j] = new TH2D(Form("truePidPhi%s%s",spec[i],spec[j]),Form("#phi truePid for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10); for(Int_t k=0; k< 3;k++){ truePidLc[i][j][k] = new TH3D(Form("truePidLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); truePidLcbar[i][j][k] = new TH3D(Form("truePidLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); } } } trueKs = new TH3D(Form("trueKs"),Form("K^{0*} true;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001); truePhi = new TH2D(Form("truePhi"),Form("#phi true;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),100,0.98,1.05,40,0,10); trueLc = new TH3D(Form("trueLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); trueLcbar = new TH3D(Form("trueLcbar"),Form("#overline{#Lambda}_{c}^{-} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1); mypidLc = new TH3D(Form("mypidLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); mypidLcbar = new TH3D(Form("mypidLcbar"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.); // define particle types (particle type array) particle::AddParticleType("pi+",0.139,1); // 0 particle::AddParticleType("pi-",0.139,-1); // 1 particle::AddParticleType("K+",0.493,1); // 2 particle::AddParticleType("K-",0.493,-1); // 3 particle::AddParticleType("p+",0.938,1); // 4 particle::AddParticleType("p-",0.938,-1); // 5 particle::AddParticleType("K0*",0.896,0,5.05e-02); // 6 particle::AddParticleType("K0bar*",0.896,0,5.05e-02); // 7 particle::AddParticleType("Phi",1.02,0,0.00426); // 8 particle::AddParticleType("Delta++",1.232,2,0.118); // 9 particle::AddParticleType("Delta--",1.232,-2,0.118); // 10 particle::AddParticleType("Lambdac+",2.28646,1,0.008); // 11 particle::AddParticleType("Lambdacbar-",2.28646,-1,0.008); // 12 particle::AddParticleType("Lambda1520",1.5195,-1,0.0000156); // 12 particle d1("pi+"); particle d2("K+"); particle d3("p+"); particle d4("pi-"); particle d5("K-"); particle d6("p-"); particle prong1; particle prong2; particle prong3; particle polarKs("K0*"); particle polarLc("Lambdac+"); Int_t charge[] = {1,-1,1,-1,1,-1,0,0,0,2,-2,1,-1}; particle ppos[20000]; particle pneg[20000]; Float_t weightsPos[20000][3]; Float_t weightsNeg[20000][3]; Int_t passMyPIDPos[20000][3]; Int_t passMyPIDNeg[20000][3]; Int_t npos=0; Int_t nneg=0; Float_t signal,signalTOF,signalTPC,pt,pz,phi,ptComb,ptComb3prong,invmass; Float_t ptd,pzd,phid; Float_t priors[3],prob[3]; Float_t priors2[3][3],prob2[3][3]; Float_t priors3[3][3][3],prob3[3][3][3]; Int_t iev=-1,id,mother; Int_t cev; TFile *fout = new TFile(Form("step%i.root",step+1),"RECREATE"); // TTree *treeKs = new TTree("treeKs","treeKs"); // Float_t ptPair,massPair,ptD1,ptD2,weightD1[3],weightD2[3],weightFill; // Int_t isTrue,isTruePid; // treeKs->Branch("ptPair",&ptPair,"ptPair/F"); // treeKs->Branch("massPair",&massPair,"massPair/F"); // treeKs->Branch("ptPi",&ptD1,"ptPi/F"); // treeKs->Branch("ptKa",&ptD2,"ptKa/F"); // treeKs->Branch("weightPi",weightD1,"wightPi[3]/F"); // treeKs->Branch("weightKa",weightD2,"wightKa[3]/F"); // treeKs->Branch("weightFill",&weightFill,"wightFill/F"); // treeKs->Branch("isTruePid",&isTruePid,"isTruePid/I"); // treeKs->Branch("isTrue",&isTrue,"isTrue/I"); TH1F *hcentr = new TH1F("hcentr","",100,0,100); FILE *flist = fopen("lista","r"); char namefile[100]; Float_t weight1[3],weight2[3],weight3[3]; Float_t ptPi,ptKa,ptPr; TH1F *htemp; while(fscanf(flist,"%s",namefile)==1){ TFile *fin = new TFile(namefile); printf("file = %s\n",namefile); TList *l = (TList *) fin->Get("TOFpid"); htemp = (TH1F *) l->At(0); if(!hcentr) hcentr = new TH1F(*htemp); else hcentr->Add(htemp); TTree *t = (TTree *) l->At(1); Int_t n = t->GetEntries(); for(Int_t i=0;i < n;i++){ t->GetEvent(i); ptPi = t->GetLeaf("ptPi")->GetValue(); ptKa = t->GetLeaf("ptPi")->GetValue(); ptPr = t->GetLeaf("ptPi")->GetValue(); pt = t->GetLeaf("pt")->GetValue(); invmass = t->GetLeaf("mass")->GetValue(); weight1[0] = t->GetLeaf("weightPi")->GetValue(0); weight1[1] = t->GetLeaf("weightPi")->GetValue(1); weight1[2] = t->GetLeaf("weightPi")->GetValue(2); weight2[0] = t->GetLeaf("weightKa")->GetValue(0); weight2[1] = t->GetLeaf("weightKa")->GetValue(1); weight2[2] = t->GetLeaf("weightKa")->GetValue(2); weight3[0] = t->GetLeaf("weightPr")->GetValue(0); weight3[1] = t->GetLeaf("weightPr")->GetValue(1); weight3[2] = t->GetLeaf("weightPr")->GetValue(2); Float_t pt1 = Int_t(ptPi/(ptPi+ptKa+ptPr)*nbinPtFrPi); Float_t pt2 = Int_t(ptKa/(ptPi+ptKa+ptPr)*nbinPtFrKa); Float_t polar = 0;//TMath::Abs(polarLc.GetY());//ptComb3prong/ptot;//(pt2*nbinpol + pt1)*invpollc; polar = ((pt1*nbinPtFrKa + pt2 + polar)*nbinY)*normbin; Int_t ibinx = priorsLc[0][0][0]->GetXaxis()->FindBin(invmass); Int_t ibiny = priorsLc[0][0][0]->GetYaxis()->FindBin(pt); Int_t ibinz = priorsLc[0][0][0]->GetZaxis()->FindBin(polar); for(Int_t ipr=0;ipr<3;ipr++) for(Int_t jpr=0;jpr<3;jpr++) for(Int_t kpr=0;kpr<3;kpr++) priors3[ipr][jpr][kpr] = priorsLc[ipr][jpr][kpr]->GetBinContent(ibinx,ibiny,ibinz); GetProb3(weight1,weight2,weight3,priors3,prob3); for(Int_t ipr=0;ipr<3;ipr++) for(Int_t jpr=0;jpr<3;jpr++) for(Int_t kpr=0;kpr<3;kpr++){ newpriorsLc[ipr][jpr][kpr]->Fill(invmass,pt,polar,prob3[ipr][jpr][kpr]); } } t->Delete(); fin->Close(); } printf("Write output\n"); fout->cd(); hcentr->Write(); //if(step==0) treeKs->Write(); for(Int_t i=0;i<6;i++){ newpriorsPt[i]->Write(); truePt[i]->Write(); } for(Int_t i=0;i<3;i++){ for(Int_t j=0;j<3;j++){ priorsPhi[i][j]->Write(); newpriorsKs[i][j]->Write(); newpriorsPhi[i][j]->Write(); truePidKs[i][j]->Write(); truePidPhi[i][j]->Write(); for(Int_t k=0;k<3;k++){ newpriorsLc[i][j][k]->Write(); truePidLc[i][j][k]->Write(); newpriorsLcbar[i][j][k]->Write(); truePidLcbar[i][j][k]->Write(); } } } trueKs->Write(); truePhi->Write(); trueLc->Write(); trueLcbar->Write(); mypidLc->Write(); mypidLcbar->Write(); fout->Close(); }
/** * Make a GraphSysErr object * * @param d Directory * @param c1 Least centrality * @param c2 Largest centrality * * @return Newly created GraphSysErr */ TObject* MakeGSE(TDirectory* d, Double_t c1, Double_t c2) { if (!gROOT->GetClass("GraphSysErr")) return 0; TString bin; bin.Form("%03dd%02d_%03dd%02d", Int_t(c1), Int_t(c1*100)%100, Int_t(c2), Int_t(c2*100)%100); TString sub(bin); sub.Prepend("cent"); sub.Append("/dndeta"); TString nme(bin); nme.Prepend("CENT_"); TH1* g = GetH1(d, sub); if (!g) return 0; Color_t col = g->GetMarkerColor(); // Double_t bg = (1-c1/100)*(2-0.1)+0.1; // Double_t c = TMath::Power(c1/100,2)*(6.2-0.4)+0.4; Double_t bg = CSysEval(c2, 0.02, 0.001); Double_t c = CSysEval(c2, 0.005, 0.075); GraphSysErr* gse = new GraphSysErr(g->GetNbinsX()); gse->SetName(nme); gse->SetTitle(Form("%5.1f - %5.1f%%", c1, c2)); gse->SetKey("author", "PREGHENELLA : 20150"); gse->SetKey("title", "dNch/deta in PbPb at 5023 GeV"); gse->SetKey("obskey", "DN/DETARAP"); gse->SetKey("reackey", "PB PB --> CHARGED X"); gse->SetKey("laboratory", "CERN"); gse->SetKey("accelerator", "LHC"); gse->SetKey("detector", "TRACKLETS"); gse->SetKey("reference", "ALICE-AN-2830"); gse->AddQualifier("CENTRALITY IN PCT", Form("%.1f TO %.1f",c1,c2)); gse->AddQualifier("SQRT(S)/NUCLEON IN GEV", "5023"); gse->SetXTitle("ETARAP"); gse->SetYTitle("DN/DETARAP"); gse->SetMarkerStyle(g->GetMarkerStyle()); gse->SetMarkerSize(g->GetMarkerSize()); gse->SetDataOption(GraphSysErr::kNoTick); gse->SetMarkerColor(col); gse->SetLineColor(col); gse->SetFillColor(col); gse->SetSumFillColor(col); gse->SetSumLineColor(col); gse->SetSumOption(GraphSysErr::kBox); gse->SetCommonSumFillColor(col); gse->SetCommonSumLineColor(col); gse->SetCommonSumOption(GraphSysErr::kBox); MakeCommon(gse, "Particle composition", 0.01, col); MakeCommon(gse, "Weak decay", 0.01, col); MakeCommon(gse, "pT extrapolation", 0.02, col); MakeCommon(gse, "EG dependence", 0.02, col); MakeCommon(gse, "Background subrtaction", bg, col); MakeCommon(gse, "Centrality", c, col); Int_t acc = MakeP2P(gse, "Acceptance", col); Int_t j = 0; for (Int_t i = 1; i <= g->GetNbinsX(); i++) { Double_t eta = g->GetXaxis()->GetBinCenter(i); Double_t eEta = g->GetXaxis()->GetBinWidth(i)/2; Double_t xo = TMath::Abs(eta)+eEta; if (xo > 2) continue; Double_t ea = 0.02*TMath::Power(xo/2,2); gse->SetPoint(j, eta, g->GetBinContent(i)); gse->SetPointError(j, eEta, eEta); gse->SetStatError(j, g->GetBinError(i),g->GetBinError(i)); gse->SetSysError(acc, j, eEta, eEta, ea/100, ea/100); j++; } return gse; }
void paracoor( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); TTree* tree = (TTree*)file->Get("TestTree"); if(!tree) { cout << "--- No TestTree saved in ROOT file. Parallel coordinates will not be plotted" << endl; return; } // first get list of leaves in tree TObjArray* leafList = tree->GetListOfLeaves(); vector<TString> vars; vector<TString> mvas; for (Int_t iar=0; iar<leafList->GetSize(); iar++) { TLeaf* leaf = (TLeaf*)leafList->At(iar); if (leaf != 0) { TString leafName = leaf->GetName(); if (leafName != "type" && leafName != "weight" && leafName != "boostweight" && leafName != "class" && leafName != "className" && leafName != "classID" && !leafName.Contains("prob_")) { // is MVA ? if (TMVAGlob::ExistMethodName( leafName )) { mvas.push_back( leafName ); } else { vars.push_back( leafName ); } } } } cout << "--- Found: " << vars.size() << " variables" << endl; cout << "--- Found: " << mvas.size() << " MVA(s)" << endl; TString type[2] = { "Signal", "Background" }; const Int_t nmva = mvas.size(); TCanvas* csig[nmva]; TCanvas* cbkg[nmva]; for (Int_t imva=0; imva<mvas.size(); imva++) { cout << "--- Plotting parallel coordinates for : " << mvas[imva] << " & input variables" << endl; for (Int_t itype=0; itype<2; itype++) { // create draw option TString varstr = mvas[imva] + ":"; for (Int_t ivar=0; ivar<vars.size(); ivar++) varstr += vars[ivar] + ":"; varstr.Resize( varstr.Last( ':' ) ); // create canvas TString mvashort = mvas[imva]; mvashort.ReplaceAll("MVA_",""); TCanvas* c1 = (itype == 0) ? csig[imva] : cbkg[imva]; c1 = new TCanvas( Form( "c1_%i",itype ), Form( "Parallel coordinate representation for %s and input variables (%s events)", mvashort.Data(), type[itype].Data() ), 50*(itype), 50*(itype), 750, 500 ); tree->Draw( varstr.Data(), Form("classID==%i",1-itype) , "para" ); c1->ToggleEditor(); gStyle->SetOptTitle(0); TParallelCoord* para = (TParallelCoord*)gPad->GetListOfPrimitives()->FindObject( "ParaCoord" ); TParallelCoordVar* mvavar = (TParallelCoordVar*)para->GetVarList()->FindObject( mvas[imva] ); Double_t minrange = tree->GetMinimum( mvavar->GetName() ); Double_t maxrange = tree->GetMaximum( mvavar->GetName() ); Double_t width = 0.2*(maxrange - minrange); Double_t x1 = minrange, x2 = x1 + width; TParallelCoordRange* parrange = new TParallelCoordRange( mvavar, x1, x2 ); parrange->SetLineColor(4); mvavar->AddRange( parrange ); para->AddSelection("-1"); for (Int_t ivar=1; ivar<TMath::Min(Int_t(vars.size()) + 1,3); ivar++) { TParallelCoordVar* var = (TParallelCoordVar*)para->GetVarList()->FindObject( vars[ivar] ); minrange = tree->GetMinimum( var->GetName() ); maxrange = tree->GetMaximum( var->GetName() ); width = 0.2*(maxrange - minrange); switch (ivar) { case 0: { x1 = minrange; x2 = x1 + width; break; } case 1: { x1 = 0.5*(maxrange + minrange - width)*0.02; x2 = x1 + width*0.02; break; } case 2: { x1 = maxrange - width; x2 = x1 + width; break; } } parrange = new TParallelCoordRange( var, x1, x2 ); parrange->SetLineColor( ivar == 0 ? 2 : ivar == 1 ? 5 : 6 ); var->AddRange( parrange ); para->AddSelection( Form("%i",ivar) ); } c1->Update(); TString fname = Form( "plots/paracoor_c%i_%s", imva, itype == 0 ? "S" : "B" ); TMVAGlob::imgconv( c1, fname ); } } }
void ariel_aa::Loop() { TFile plotz("cuts-testing.root","recreate"); // My variables float minMass = 4.75; float maxMass = 6.0; float div = 0.04; int nBins = (maxMass - minMass)/div; float acoll = 0.00; float asig = 0.00; float apt = 0.00; float asmt = 0.00; // ------------ HISTOGRAMS FOR MASS < 1 GeV ------------------------------------------ // dl_sig varied histograms, low mass TH1F* m_1_dlsig_3_0 = new TH1F("m_1_dlsig_3_0", "low mass, dlsig 3_0", 40,minMass,maxMass); TH1F* m_1_dlsig_3_2 = new TH1F("m_1_dlsig_3_2", "low mass, dlsig 3_2", 40,minMass,maxMass); TH1F* m_1_dlsig_3_4 = new TH1F("m_1_dlsig_3_4", "low mass, dlsig 3_4", 40,minMass,maxMass); TH1F* m_1_dlsig_3_6 = new TH1F("m_1_dlsig_3_6", "low mass, dlsig 3_6", 40,minMass,maxMass); TH1F* m_1_dlsig_3_8 = new TH1F("m_1_dlsig_3_8", "low mass, dlsig 3_8", 40,minMass,maxMass); TH1F* m_1_dlsig_4_0 = new TH1F("m_1_dlsig_4_0", "low mass, dlsig 4_0", 40,minMass,maxMass); TH1F* m_1_dlsig_4_2 = new TH1F("m_1_dlsig_4_2", "low mass, dlsig 4_2", 40,minMass,maxMass); TH1F* m_1_dlsig_4_4 = new TH1F("m_1_dlsig_4_4", "low mass, dlsig 4_4", 40,minMass,maxMass); TH1F* m_1_dlsig_4_6 = new TH1F("m_1_dlsig_4_6", "low mass, dlsig 4_6", 40,minMass,maxMass); TH1F* m_1_dlsig_4_8 = new TH1F("m_1_dlsig_4_8", "low mass, dlsig 4_8", 40,minMass,maxMass); TH1F* m_1_dlsig_5_0 = new TH1F("m_1_dlsig_5_0", "low mass, dlsig 5_0", 40,minMass,maxMass); TH1F* m_1_dlsig_5_2 = new TH1F("m_1_dlsig_5_2", "low mass, dlsig 5_2", 40,minMass,maxMass); TH1F* m_1_dlsig_5_4 = new TH1F("m_1_dlsig_5_4", "low mass, dlsig 5_4", 40,minMass,maxMass); TH1F* m_1_dlsig_5_6 = new TH1F("m_1_dlsig_5_6", "low mass, dlsig 5_6", 40,minMass,maxMass); TH1F* m_1_dlsig_5_8 = new TH1F("m_1_dlsig_5_8", "low mass, dlsig 5_8", 40,minMass,maxMass); TH1F* m_1_dlsig_6_0 = new TH1F("m_1_dlsig_6_0", "low mass, dlsig 6_0", 40,minMass,maxMass); if (fChain == 0) return; int aa = 5000; int nn = 0; Int_t nentries = Int_t(fChain->GetEntries()); cout <<"Number of entries " << nentries << endl; Int_t nbytes = 0, nb = 0; Int_t iCountF = 0; Int_t flag = 0; Float_t dm[10]; Int_t count_m = 0; //for (Int_t jentry=0; jentry<10000;jentry++) { for (Int_t jentry=0; jentry<nentries;jentry++) { // cout << "now at event # "<< jentry << endl; Int_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; if(jentry/aa>nn) cout << "Event #" << jentry << endl; nn = jentry/aa; Int_t iFound = 0; if(PV_npv<1 || PV_ntrk[0]<2) continue; // Fill histograms with vertex info count_m = 0; for(int j=0; j<BPSIK_nvtx; j++) { int jpsi_id = BPSIK_id[j]; //require JPSI if( (PSI_q1[jpsi_id]+PSI_q2[jpsi_id])==0 && PSI_chi2[jpsi_id]<10.0 && PSI_pt1[jpsi_id]>=1.5 && PSI_pt2[jpsi_id]>=1.5 && PSI_smt1[jpsi_id]>=1 && PSI_smt2[jpsi_id]>=1 && PSI_mass[jpsi_id]>2.8 && PSI_mass[jpsi_id]<3.3 && PSI_pt[jpsi_id]>3.) { float mass = BPSIK_mass[j]; float massc1 = BPSIK_massc1[j]; float massc2 = BPSIK_massc2[j]; float chi2 = BPSIK_chi2[j]; float dl = BPSIK_dl[j]; float coll = BPSIK_collinearity[j]; float dl_sig = dl/BPSIK_dlError[j]; float Kch2 = BPSIK_kchi2vtx[j]; float Kpt = BPSIK_kpt[j]; int Ksmt = BPSIK_khits[j]; int flag =0; // Keep kch2, chi2, Ksmt, Kpt, coll constant, vary dl_sig: if(Kch2<=10 && chi2<20 && Ksmt>=0 && Kpt>1.0 && coll>0.95){ if (dl_sig>=3.0){m_1_dlsig_3_0->Fill(massc1);} if (dl_sig>=3.2){m_1_dlsig_3_2->Fill(massc1);} if (dl_sig>=3.4){m_1_dlsig_3_4->Fill(massc1);} if (dl_sig>=3.6){m_1_dlsig_3_6->Fill(massc1);} if (dl_sig>=3.8){m_1_dlsig_3_8->Fill(massc1);} if (dl_sig>=4.0){m_1_dlsig_4_0->Fill(massc1);} if (dl_sig>=4.2){m_1_dlsig_4_2->Fill(massc1);} if (dl_sig>=4.4){m_1_dlsig_4_4->Fill(massc1);} if (dl_sig>=4.6){m_1_dlsig_4_6->Fill(massc1);} if (dl_sig>=4.8){m_1_dlsig_4_8->Fill(massc1);} if (dl_sig>=5.0){m_1_dlsig_5_0->Fill(massc1);} if (dl_sig>=5.2){m_1_dlsig_5_2->Fill(massc1);} if (dl_sig>=5.4){m_1_dlsig_5_4->Fill(massc1);} if (dl_sig>=5.6){m_1_dlsig_5_6->Fill(massc1);} if (dl_sig>=5.8){m_1_dlsig_5_8->Fill(massc1);} if (dl_sig>=6.0){m_1_dlsig_6_0->Fill(massc1);} } } } } plotz->Write(); cout << "COMPLETE!"; }
//void pi0_mfitpeak(char *FileName, char *HistName, Int_t etapi0flag) void pi0_mfitpeak(TH1F *mh1, Int_t etapi0flag, float xmin, float xmax, int npol,float res[],int posFlag, const char *dirName, const char *histName, float text_x, float text_y, const char *texName) { TGaxis::SetMaxDigits(3); // TVirtualFitter::SetDefaultFitter("Minuit"); // This script attempts to fit any pi0 peak so that the freaking fit function would converge // currently background is fitted to a pol4 function and the peak by a gaussian; // results are not very nice // usage .x pi0_mfitpeak.C++ ("pi0calib.root","minv_spb") // or eg. .x pi0_mfitpeak.C ("../pi0anal/pi0ana_punorm.root","minv_spb",0) gROOT->Reset(); // gStyle->SetOptFit(); // gStyle->SetOptFit(0); // gStyle->SetOptStat(0); // gStyle->SetOptTitle(0); Bool_t NOTE=1; if(NOTE) gStyle->SetCanvasBorderMode(0); gStyle->SetPadTopMargin(0.08); gStyle->SetPadBottomMargin(0.12); gStyle->SetPadLeftMargin(0.15); gStyle->SetPadRightMargin(0.08); mh1->GetXaxis()->SetRangeUser(xmin,xmax); Int_t highx=500; TCanvas *c2 = new TCanvas("c2","",200,10,highx,500); // cout<<FileName<<" "<<HistName<<endl; // TFile f(FileName); // TH1F *mh1 = (TH1F*) f.Get(HistName); mh1->SetMarkerStyle(20); mh1->SetMarkerSize(1.); mh1->SetStats(0); // 1/0 to set the stat box mh1->GetXaxis()->SetTitle("Invariant Mass of Photon Pairs (GeV/c^{2})"); float binwidth = mh1->GetBinWidth(1); char *ytitle = new char[100]; sprintf(ytitle,"Photon Pairs / %4.3f GeV/c^{2}",binwidth); mh1->GetYaxis()->SetTitle(ytitle); mh1->GetXaxis()->SetTitleSize(0.055); mh1->GetYaxis()->SetTitleSize(0.055); mh1->GetXaxis()->SetLabelSize(0.045); mh1->GetYaxis()->SetLabelSize(0.045); mh1->GetXaxis()->SetTitleOffset(0.90); mh1->GetXaxis()->CenterTitle(); mh1->GetYaxis()->SetTitleOffset(1.32); // First work with the histogram and find the peak and fit ranges TAxis *xaxis = mh1->GetXaxis(); Float_t binsiz= xaxis->GetBinCenter(3) - xaxis->GetBinCenter(2); Int_t nbins = xaxis->GetNbins(); Float_t nevtperbin0[10000]; Float_t errorbin0[10000]; Float_t nevttot; Float_t maxbin=0; Int_t nmaxbin=0, nminbord=0, nmaxbord=nbins; for (Int_t nn=1; nn <= nbins; nn++) { nevtperbin0[nn] = mh1->GetBinContent(nn); if(nevtperbin0[nn] > maxbin) { maxbin=nevtperbin0[nn]; nmaxbin=nn; } errorbin0[nn] = mh1->GetBinError(nn); nevttot+=nevtperbin0[nn]; if(nevtperbin0[nn] > 0 && nminbord == 0) nminbord=nn; if(nevtperbin0[nn] == 0 && (nn > nminbord +10) && nmaxbord==0 && nminbord > 0) nmaxbord=nn; } cout<<"Minbordl "<<nminbord<<" with events: "<<nevtperbin0[nminbord]<<endl; cout<<"Maxbordl "<<nmaxbord<<" with events: "<<nevtperbin0[nmaxbord]<<endl; nminbord+=0; nmaxbord-=0; Int_t nmin0=nminbord; while(nevtperbin0[nminbord] < nevtperbin0[nmaxbin]*0.025) nminbord++; while(nevtperbin0[nmaxbord] < nevtperbin0[nmaxbin]*0.025) nmaxbord--; // the above was just to get the info and low/high bins // Set the fit range ! This is for total fit ! Float_t fitl=xmin; float fith=xmax; // Float_t fitl=0.07, fith=0.2;// this works better for pileup // Float_t fitl=0.08, fith=0.18;// this works even better for pileup // if(etapi0flag == 1) // { // fitl=0.35; fith=0.75; //} // if(fitl < xaxis->GetBinCenter(nmin0)) fitl = xaxis->GetBinCenter(nmin0); //if(fith > xaxis->GetBinCenter(nmaxbord)) fith = xaxis->GetBinCenter(nmaxbord); cout<<" fit range "<<fitl<<" -- "<<fith<<endl; cout <<"Bin size "<<binsiz<<endl; cout<<"Total events "<<nevttot<<endl; cout<<"MaxBin "<<nmaxbin<<" with events: "<<nevtperbin0[nmaxbin]<<endl; cout<<"Minbord "<<nminbord<<" with events: "<<nevtperbin0[nminbord]<<endl; cout<<"Maxbord "<<nmaxbord<<" with events: "<<nevtperbin0[nmaxbord]<<endl; mh1->DrawCopy("sep"); Float_t lowgauss=0.135-4.*0.010; Float_t highgauss=0.135+4.*0.010; if(etapi0flag == 1) { lowgauss=0.55-5.*0.025; highgauss=0.55+5.*0.025; } Int_t nlowgauss=Int_t((lowgauss-xaxis->GetBinCenter(1))/Float_t(binsiz)+0.5); Int_t nhighgauss=Int_t((highgauss-xaxis->GetBinCenter(1))/Float_t(binsiz)+0.5); cout <<xaxis->GetBinCenter(nlowgauss)<<" "<<xaxis->GetBinCenter(nhighgauss)<<endl; // now make the "background" histogram and fit it with p4 Float_t lowvalgauss=nevtperbin0[nlowgauss]; Float_t increm=(nevtperbin0[nhighgauss]-nevtperbin0[nlowgauss])/Float_t(nhighgauss-nlowgauss); TH1F *hbkg = (TH1F*)mh1->Clone(); hbkg->SetName("bkg_clone"); for (Int_t nn=nlowgauss; nn<=nhighgauss; nn++) { hbkg->SetBinContent(nn,Float_t(lowvalgauss+(nn-nlowgauss)*increm)); hbkg->SetBinError(nn,sqrt(lowvalgauss+(nn-nlowgauss)*increm)); } hbkg->DrawCopy("samesep"); // break; // Now define the "gaussian" histogram TH1F *hgauss = (TH1F*)mh1->Clone(); hgauss->SetName("gauss_clone"); hgauss->Sumw2(); hgauss->Add(mh1,hbkg,1,-1); // if errors are independent Add needs to be used ! for (Int_t nn=1; nn <= nbins; nn++) { if(hgauss->GetBinContent(nn) < 0.) hgauss->SetBinContent(nn,0.001*nevtperbin0[nmaxbin]); hgauss->SetBinError(nn,sqrt(hgauss->GetBinContent(nn))); } // Declare function with wich to fit TF1 *g1 = new TF1("g1","gaus",lowgauss,highgauss); hgauss->Fit(g1,"R0"); hgauss->DrawCopy("sep"); g1->Draw("same"); // break; char *polff = new char[20]; sprintf(polff,"pol%d",npol); TF1 *p4bkg; if(etapi0flag != 1) p4bkg = new TF1("pm2",polff, xaxis->GetBinCenter(nminbord),xaxis->GetBinCenter(nmaxbord)); else p4bkg = new TF1("pm2",polff, 0.35,0.75); hbkg->Fit(p4bkg,"R0"); hbkg->DrawCopy("sep"); p4bkg->SetLineStyle(kDashed); p4bkg->Draw("same"); // break; Double_t par[20],parf[20],errparf[20]; g1->GetParameters(&par[0]); p4bkg->GetParameters(&par[3]); char *totff = new char[20]; sprintf(totff,"gaus(0)+pol%d(3)",npol); TF1 *total = new TF1("total",totff,fitl,fith); TF1 *p4bkgfin = new TF1("pm2",polff,fitl,fith); total->SetParameters(par); if(etapi0flag==0){ total->SetParLimits(1,0.10,0.15); total->SetParLimits(2,0.135*0.06,0.135*0.3); }else{ total->SetParLimits(1,0.35,0.65); } // total->FixParameter(1,1.21340e-01); // total->FixParameter(2,2.69780e-02); mh1->Fit(total,"R0"); cout<<" yield.. "<< total->GetParameter(0) <<"+/- " << total->GetParError(0)<<endl; total->GetParameters(parf); for( Int_t nn=0; nn < 3+npol+1; nn++) errparf[nn]=total->GetParError(nn); g1->SetParameters(&parf[0]); p4bkgfin->SetParameters(&parf[3]); cout <<" Piz Mass = "<<parf[1]*1000.<<" +- "<<errparf[1]*1000.<< " Sigma ="<<parf[2]*1000.<<" +- "<<errparf[2]*1000.<<endl; cout << " Sigma Rel. = "<< parf[2]/parf[1]<<" +- " << errparf[2]/parf[1] <<endl; Float_t int_min=parf[1]-3.*parf[2]; Float_t int_max=parf[1]+3.*parf[2]; Float_t sig_peak=g1->Integral(int_min,int_max)/binsiz; Float_t bkgd_peak=p4bkgfin->Integral(int_min,int_max)/binsiz; cout<<" In +-3. sigma window: Signal="<<sig_peak<<" Bkgd="<<bkgd_peak<<endl; Float_t SB=sig_peak/bkgd_peak; Float_t SBerr=SB*(sqrt(1./sig_peak+1./bkgd_peak)); cout<<" Signal/Bkgd "<<SB<<" +- "<<SBerr<<endl; int_min=parf[1]-2.*parf[2]; int_max=parf[1]+2.*parf[2]; sig_peak=g1->Integral(int_min,int_max)/binsiz; bkgd_peak=p4bkgfin->Integral(int_min,int_max)/binsiz; cout<<" In +-2.sigma window: Signal="<<sig_peak<<" Bkgd="<<bkgd_peak<<endl; SB=sig_peak/bkgd_peak; SBerr=SB*(sqrt(1./sig_peak+1./bkgd_peak)); cout<<" Signal/Bkgd "<<SB<<" +- "<<SBerr<<endl; float S = sig_peak; float B = bkgd_peak; int_min=parf[1]-20.*parf[2]; int_max=parf[1]+20.*parf[2]; float S_all = g1->Integral(int_min,int_max)/binsiz; float test_sall = parf[0] * parf[2] * sqrt(acos(-1)) / binsiz; cout<<"signal all: "<< S_all << " "<< test_sall <<endl; float Serr_all = errparf[0]/ parf[0] * S_all; res[0] = S_all; res[1] = Serr_all; res[2] = parf[1]; res[3] = errparf[1]; res[4] = parf[2]; res[5] = errparf[2]; res[6] = SB; res[7] = SBerr; total->SetLineWidth(3); total->SetLineColor(kBlue); p4bkgfin->SetLineWidth(3); p4bkgfin->SetLineColor(kRed); mh1->DrawCopy("sep"); // total->SetRange(0.07,0.185); // p4bkgfin->SetRange(0.07,0.185); total->Draw("same"); p4bkgfin->SetLineStyle(kDashed); p4bkgfin->Draw("same"); TLatex l; // l.SetTextSize(0.06); l.SetTextSize(0.05); l.SetTextColor(1); l.SetNDC(); float sigma = parf[2]/ parf[1]*100; float sigmaerr = errparf[2]/ parf[1]*100; char *sigma_name = new char[50]; if(sigmaerr>0.005) sprintf(sigma_name,"#sigma = %3.2f #pm %3.2f %% ",sigma,sigmaerr); else sprintf(sigma_name,"#sigma = %3.2f %% ",sigma); if(posFlag==1){ l.DrawLatex(0.54,0.75,sigma_name); }else if( posFlag==2){ l.DrawLatex(0.54,0.3,sigma_name); } // sprintf(sigma_name,"S/B = %3.2f #pm %3.2f ",SB,SBerr); // sprintf(sigma_name,"S = %2.1f #pm %2.1f",S_all,Serr_all); // // l.DrawLatex(0.5,0.5,sigma_name); sprintf(sigma_name,"M = %3.1f #pm %3.1f MeV",parf[1]*1000.,errparf[1]*1000); if(posFlag==1){ l.DrawLatex(0.54,0.82,sigma_name); }else if( posFlag==2){ l.DrawLatex(0.54,0.37,sigma_name); } ///l.DrawLatex(0.169,470.,"d)"); c2->Modified(); c2->Update(); // c2->SaveAs("nice_pi0.gif"); if( text_x >0 && text_y >0){ TLatex * tex = new TLatex(text_x, text_y, texName); tex->SetNDC(); tex->SetTextSize(0.06); tex->SetLineWidth(2); tex->Draw(); } char *filename = new char[1000]; sprintf(filename,"%s/%s.gif",dirName,histName); c2->Print(filename); sprintf(filename,"%s/%s.C",dirName,histName); c2->Print(filename); // .x pi0_mfitpeak.C ("pi0ana_508030.root","minv_spb",0) // .x pi0_mfitpeak.C ("pi0ana_npu.root","minv_bkg",0) // .x pi0_mfitpeak.C ("pi0ana_punormv2.root","minv_spb",0) }
{ gROOT -> Reset(); TFile f("human_phantom.root"); TDirectory* dir = (TDirectory*)f.Get("human_phantom_ntuple"); TTree* ntuple = (TTree*)dir->Get("1"); ntuple -> Print(); // Print the content of the ntuple Int_t nevent = Int_t(ntuple->GetEntries()); Double_t xx; Double_t edep; ntuple->GetBranch("organID")->SetAddress(&xx); ntuple->GetBranch("edep")->SetAddress(&edep); for ( Int_t i=0; i<nevent; i++ ) { ntuple->GetEvent(i); cout << "organ ID, edep (MeV): " << xx << ", " << edep << endl; } }
void doCoinc3(const char *fileIn="SAVO-01-SAVO-02-SAVO-03-2016-01-26.root"){ Int_t adayMin = (yearRange[0]-2007) * 1000 + monthRange[0]*50 + dayRange[0]; Int_t adayMax = (yearRange[1]-2007) * 1000 + monthRange[1]*50 + dayRange[1]; // define some histos TH1F *hDeltaTheta12 = new TH1F("hDeltaTheta12","#Delta#theta_{12} below the peak (500 ns);#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhi12 = new TH1F("hDeltaPhi12","#Delta#phi_{12} below the peak (500 ns);#Delta#phi (#circ)",200,-360,360); TH1F *hDeltaThetaBack12 = new TH1F("hDeltaThetaBack12","#Delta#theta_{12} out of the peak (> 1000 ns) - normalized;#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhiBack12 = new TH1F("hDeltaPhiBack12","#Delta#phi_{12} out of the peak (> 1000 ns) - normalized;#Delta#phi (#circ)",200,-360,360); TH1F *hThetaRel12 = new TH1F("hThetaRel12","#theta_{rel}_{12} below the peak (500 ns);#theta_{rel} (#circ)",100,0,120); TH1F *hThetaRelBack12 = new TH1F("hThetaRelBack12","#theta_{rel}_{12} out of the peak (> 1000 ns) - normalized;#theta_{rel} (#circ)",100,0,120); TH1F *hDeltaTheta13 = new TH1F("hDeltaTheta13","#Delta#theta_{13} below the peak (500 ns);#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhi13 = new TH1F("hDeltaPhi13","#Delta#phi_{13} below the peak (500 ns);#Delta#phi (#circ)",200,-360,360); TH1F *hDeltaThetaBack13 = new TH1F("hDeltaThetaBack13","#Delta#theta_{13} out of the peak (> 1000 ns) - normalized;#Delta#theta (#circ)",100,-60,60); TH1F *hDeltaPhiBack13 = new TH1F("hDeltaPhiBack13","#Delta#phi_{13} out of the peak (> 1000 ns) - normalized;#Delta#phi (#circ)",200,-360,360); TH1F *hThetaRel13 = new TH1F("hThetaRel13","#theta_{rel}_{13} below the peak (500 ns);#theta_{rel} (#circ)",100,0,120); TH1F *hThetaRelBack13 = new TH1F("hThetaRelBack13","#theta_{rel}_{13} out of the peak (> 1000 ns) - normalized;#theta_{rel} (#circ)",100,0,120); TFile *f = new TFile(fileIn); TTree *t = (TTree *) f->Get("tree"); TTree *tel[3]; tel[0] = (TTree *) f->Get("treeTel1"); tel[1] = (TTree *) f->Get("treeTel2"); tel[2] = (TTree *) f->Get("treeTel3"); TTree *telC = (TTree *) f->Get("treeTimeCommon"); // quality info of runs Bool_t runstatus[3][10][12][31][500]; //#telescope, year-2007, month, day, run if(tel[0] && tel[1] && tel[2]){ for(Int_t i=0;i < 3;i++){ // loop on telescopes for(Int_t j=0;j < tel[i]->GetEntries();j++){ // loop on runs tel[i]->GetEvent(j); Int_t aday = (tel[i]->GetLeaf("year")->GetValue()-2007) * 1000 + tel[i]->GetLeaf("month")->GetValue()*50 + tel[i]->GetLeaf("day")->GetValue(); if(aday < adayMin || aday > adayMax) continue; if(tel[i]->GetLeaf("FractionGoodTrack")->GetValue() < fracGT[i]) continue; // cut on fraction of good track if(tel[i]->GetLeaf("timeduration")->GetValue()*tel[i]->GetLeaf("rateHitPerRun")->GetValue() < hitevents[i]) continue; // cut on the number of event if(tel[i]->GetLeaf("ratePerRun")->GetValue() < rateMin[i] || tel[i]->GetLeaf("ratePerRun")->GetValue() > rateMax[i]) continue; // cut on the rate if(tel[i]->GetLeaf("run")->GetValue() > 499) continue; // run < 500 Float_t missinghitfrac = (tel[i]->GetLeaf("ratePerRun")->GetValue()-tel[i]->GetLeaf("rateHitPerRun")->GetValue()-2)/(tel[i]->GetLeaf("ratePerRun")->GetValue()-2); if(missinghitfrac < minmissingHitFrac[i] || missinghitfrac > maxmissingHitFrac[i]) continue; runstatus[i][Int_t(tel[i]->GetLeaf("year")->GetValue())-2007][Int_t(tel[i]->GetLeaf("month")->GetValue())][Int_t(tel[i]->GetLeaf("day")->GetValue())][Int_t(tel[i]->GetLeaf("run")->GetValue())] = kTRUE; } } } else{ telC = NULL; } Int_t n = t->GetEntries(); // counter for seconds Int_t nsec = 0; Int_t nsecGR = 0; // for good runs Int_t isec = -1; // used only in case the tree with time info is not available if(telC){ for(Int_t i=0; i < telC->GetEntries();i++){ telC->GetEvent(i); nsec += telC->GetLeaf("timeduration")->GetValue(); if(telC->GetLeaf("run")->GetValue() > 499 || telC->GetLeaf("run2")->GetValue() > 499 || telC->GetLeaf("run3")->GetValue() > 499) continue; if(!runstatus[0][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run")->GetValue())]) continue; if(!runstatus[1][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run2")->GetValue())]) continue; if(!runstatus[2][Int_t(telC->GetLeaf("year")->GetValue())-2007][Int_t(telC->GetLeaf("month")->GetValue())][Int_t(telC->GetLeaf("day")->GetValue())][Int_t(telC->GetLeaf("run2")->GetValue())]) continue; nsecGR += telC->GetLeaf("timeduration")->GetValue(); } } char title[600]; TH1F *h; TH2F *h2; sprintf(title,"correction assuming #Delta#phi_{12} = %4.2f, #DeltaL_{12} = %.1f m, #Delta#phi_{13} = %4.2f, #DeltaL_{13} = %.1f m;#Deltat_{13} (ns) when |#Deltat_{12}| < %i ns;entries",angle12,distance12,angle13,distance13,timeCutOn12); h = new TH1F("hCoinc",title,nbint,tmin,tmax); sprintf(title,"correction assuming #Delta#phi_{12} = %4.2f, #DeltaL_{12} = %.1f m, #Delta#phi_{13} = %4.2f, #DeltaL_{13} = %.1f m;#Deltat_{12} (ns);#Deltat_{13} (ns);entries",angle12,distance12,angle13,distance13,timeCutOn12); h2 = new TH2F("hCoinc2D",title,nbint,tmin,tmax,nbint,tmin,tmax); Float_t DeltaT12,DeltaT13; Float_t phiAv,thetaAv,corr12,corr13; Float_t Theta1,Theta2,Theta3; Float_t Phi1,Phi2,Phi3; Float_t v1[3],v2[3],v3[3],vSP12,vSP13; // variable to recompute ThetaRel on the fly for(Int_t i=0;i<n;i++){ t->GetEvent(i); // if(t->GetLeaf("RunNumber1") && (t->GetLeaf("RunNumber1")->GetValue() > 499 || t->GetLeaf("RunNumber2")->GetValue() > 499) || t->GetLeaf("RunNumber3")->GetValue() > 499)) continue; // if(tel[0] && !runstatus[0][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber1")->GetValue())]) continue; // if(tel[1] && !runstatus[1][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]) continue; // if(tel[2] && !runstatus[2][Int_t(t->GetLeaf("year")->GetValue())-2007][Int_t(t->GetLeaf("month")->GetValue())][Int_t(t->GetLeaf("day")->GetValue())][Int_t(t->GetLeaf("RunNumber2")->GetValue())]) continue; Int_t timec = t->GetLeaf("ctime1")->GetValue(); if(! telC){ if(isec == -1) isec = timec; if(timec != isec){ if(timec - isec < 20){ // printf("diff = %i\n",timec-isec); nsec +=(timec - isec); nsecGR +=(timec - isec); } isec = timec; } } Float_t thetarel12 = t->GetLeaf("ThetaRel12")->GetValue(); Float_t thetarel13 = t->GetLeaf("ThetaRel13")->GetValue(); Theta1 = t->GetLeaf("Theta1")->GetValue()*TMath::DegToRad(); Theta2 = t->GetLeaf("Theta2")->GetValue()*TMath::DegToRad(); Theta3 = t->GetLeaf("Theta3")->GetValue()*TMath::DegToRad(); Phi1 = t->GetLeaf("Phi1")->GetValue()*TMath::DegToRad(); Phi2 = t->GetLeaf("Phi2")->GetValue()*TMath::DegToRad(); Phi3 = t->GetLeaf("Phi3")->GetValue()*TMath::DegToRad(); if(recomputeThetaRel){ // recompute ThetaRel applying corrections Phi1 -= phi1Corr*TMath::DegToRad(); Phi2 -= phi2Corr*TMath::DegToRad(); Phi3 -= phi3Corr*TMath::DegToRad(); if(Phi1 > 2*TMath::Pi()) Phi1 -= 2*TMath::Pi(); if(Phi1 < 0) Phi1 += 2*TMath::Pi(); if(Phi2 > 2*TMath::Pi()) Phi2 -= 2*TMath::Pi(); if(Phi2 < 0) Phi2 += 2*TMath::Pi(); if(Phi3 > 2*TMath::Pi()) Phi3 -= 2*TMath::Pi(); if(Phi3 < 0) Phi3 += 2*TMath::Pi(); v1[0] = TMath::Sin(Theta1)*TMath::Cos(Phi1); v1[1] = TMath::Sin(Theta1)*TMath::Sin(Phi1); v1[2] = TMath::Cos(Theta1); v2[0] = TMath::Sin(Theta2)*TMath::Cos(Phi2); v2[1] = TMath::Sin(Theta2)*TMath::Sin(Phi2); v2[2] = TMath::Cos(Theta2); v3[0] = TMath::Sin(Theta3)*TMath::Cos(Phi3); v3[1] = TMath::Sin(Theta3)*TMath::Sin(Phi3); v3[2] = TMath::Cos(Theta3); v2[0] *= v1[0]; v2[1] *= v1[1]; v2[2] *= v1[2]; v3[0] *= v1[0]; v3[1] *= v1[1]; v3[2] *= v1[2]; vSP12 = v2[0] + v2[1] + v2[2]; vSP13 = v3[0] + v3[1] + v3[2]; thetarel12 = TMath::ACos(vSP12)*TMath::RadToDeg(); thetarel13 = TMath::ACos(vSP13)*TMath::RadToDeg(); } // cuts if(thetarel12 > maxthetarel) continue; if(thetarel13 > maxthetarel) continue; if(t->GetLeaf("ChiSquare1")->GetValue() > maxchisquare) continue; if(t->GetLeaf("ChiSquare2")->GetValue() > maxchisquare) continue; if(t->GetLeaf("ChiSquare3")->GetValue() > maxchisquare) continue; DeltaT12 = t->GetLeaf("DiffTime12")->GetValue(); DeltaT13 = t->GetLeaf("DiffTime13")->GetValue(); // get primary direction if(TMath::Abs(Phi1-Phi2) < TMath::Pi()) phiAv = (Phi1+Phi2)*0.5; else phiAv = (Phi1+Phi2)*0.5 + TMath::Pi(); if(TMath::Abs(phiAv-Phi3) < TMath::Pi()) phiAv = (phiAv*2+Phi2)*0.33333333333; else if(phiAv > Phi3) phiAv = (phiAv*2+Phi3+2*TMath::Pi())*0.33333333333; else phiAv = (phiAv*2+4*TMath::Pi()+Phi3)*0.33333333333; thetaAv = (Theta1+Theta2+Theta3)*0.333333333333; // extra cuts if needed // if(TMath::Cos(Phi1-Phi2) < 0.) continue; corr12 = distance12 * TMath::Sin(thetaAv)*TMath::Cos(phiAv-angle12)/2.99792458000000039e-01 + deltatCorr12; corr13 = distance13 * TMath::Sin(thetaAv)*TMath::Cos(phiAv-angle13)/2.99792458000000039e-01 + deltatCorr13; if(TMath::Abs(DeltaT12-corr12) < timeCutOn12) h->Fill(DeltaT13-corr13); h2->Fill(DeltaT12-corr12,DeltaT13-corr13); if(TMath::Abs(DeltaT12-corr12) < 500){ hDeltaTheta12->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhi12->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRel12->Fill(thetarel12); } else if(TMath::Abs(DeltaT12-corr12) > 1000 && TMath::Abs(DeltaT12-corr12) < 6000){ hDeltaThetaBack12->Fill((Theta1-Theta2)*TMath::RadToDeg()); hDeltaPhiBack12->Fill((Phi1-Phi2)*TMath::RadToDeg()); hThetaRelBack12->Fill(thetarel12); } if(TMath::Abs(DeltaT13-corr13) < 500){ hDeltaTheta13->Fill((Theta1-Theta3)*TMath::RadToDeg()); hDeltaPhi13->Fill((Phi1-Phi3)*TMath::RadToDeg()); hThetaRel13->Fill(thetarel13); } else if(TMath::Abs(DeltaT13-corr13) > 1000 && TMath::Abs(DeltaT13-corr13) < 6000){ hDeltaThetaBack13->Fill((Theta1-Theta3)*TMath::RadToDeg()); hDeltaPhiBack13->Fill((Phi1-Phi3)*TMath::RadToDeg()); hThetaRelBack13->Fill(thetarel13); } } h->SetStats(0); hDeltaThetaBack12->Sumw2(); hDeltaPhiBack12->Sumw2(); hThetaRelBack12->Sumw2(); hDeltaThetaBack12->Scale(0.1); hDeltaPhiBack12->Scale(0.1); hThetaRelBack12->Scale(0.1); hDeltaThetaBack13->Sumw2(); hDeltaPhiBack13->Sumw2(); hThetaRelBack13->Sumw2(); hDeltaThetaBack13->Scale(0.1); hDeltaPhiBack13->Scale(0.1); hThetaRelBack13->Scale(0.1); Float_t val,eval; TCanvas *c1=new TCanvas(); TF1 *ff = new TF1("ff","[0]*[4]/[2]/sqrt(2*TMath::Pi())*TMath::Exp(-(x-[1])*(x-[1])*0.5/[2]/[2]) + [3]*[4]/6/[2]"); ff->SetParName(0,"signal"); ff->SetParName(1,"mean"); ff->SetParName(2,"sigma"); ff->SetParName(3,"background"); ff->SetParName(4,"bin width"); ff->SetParameter(0,42369); ff->SetParameter(1,0); ff->SetParLimits(2,10,1000); ff->SetParameter(2,150); // fix witdh if needed ff->SetParameter(3,319); ff->FixParameter(4,20000./nbint); // bin width ff->SetNpx(1000); h->Fit(ff); val = ff->GetParameter(2); eval = ff->GetParError(2); printf("significance = %f\n",ff->GetParameter(0)/sqrt(ff->GetParameter(0) + ff->GetParameter(3))); h->Draw(); TF1 *func1 = (TF1 *) h->GetListOfFunctions()->At(0); func1->SetLineColor(2); h->SetLineColor(4); TPaveText *text = new TPaveText(1500,(h->GetMinimum()+(h->GetMaximum()-h->GetMinimum())*0.6),9500,h->GetMaximum()); text->SetFillColor(0); sprintf(title,"width = %5.1f #pm %5.1f",func1->GetParameter(2),func1->GetParError(2)); text->AddText(title); sprintf(title,"signal (S) = %5.1f #pm %5.1f",func1->GetParameter(0),func1->GetParError(0)); text->AddText(title); sprintf(title,"background (B) (3#sigma) = %5.1f #pm %5.1f",func1->GetParameter(3),func1->GetParError(3)); text->AddText(title); sprintf(title,"significance (S/#sqrt{S+B}) = %5.1f",func1->GetParameter(0)/sqrt(func1->GetParameter(0)+func1->GetParameter(3))); text->AddText(title); text->SetFillStyle(0); text->SetBorderSize(0); text->Draw("SAME"); printf("n_day = %f\nn_dayGR = %f\n",nsec*1./86400,nsecGR*1./86400); text->AddText(Form("rate = %f #pm %f per day",func1->GetParameter(0)*86400/nsecGR,func1->GetParError(0)*86400/nsecGR)); TFile *fo = new TFile("output-SAVO-010203.root","RECREATE"); h->Write(); h2->Write(); hDeltaTheta12->Write(); hDeltaPhi12->Write(); hThetaRel12->Write(); hDeltaThetaBack12->Write(); hDeltaPhiBack12->Write(); hThetaRelBack12->Write(); hDeltaTheta13->Write(); hDeltaPhi13->Write(); hThetaRel13->Write(); hDeltaThetaBack13->Write(); hDeltaPhiBack13->Write(); hThetaRelBack13->Write(); fo->Close(); }
/** * Extract ALICE PbPb @ 5.02TeV over |eta|<2 * * @param filename Input file name * @param outname Output file name * @param reweigh Whether it is reweighed */ void Extract(const char* filename="dndneta.pbpb502.20151124.root", const char* outname="TRACKLETS_5023_PbPb.input", Bool_t reweigh=false) { if (filename == 0) return; TFile* file = TFile::Open(filename, "READ"); TObjArray* arr = static_cast<TObjArray*>(file->Get("TObjArray")); // Now count number of bins Int_t nBins = 0; TIter next(arr); TObject* obj = 0; while ((obj = next())) { if (TString(obj->GetName()).Contains("DataCorrSignal")) nBins++; } Info("ExtractdNdeta", "Defining %d centrality bins", nBins); TArrayD c(nBins+1); if (nBins == 5) { c[0] = 0; c[1] = 10; c[2] = 20; c[3] = 40; c[4] = 60; c[5] = 80; } else if (nBins >= 9) { c[0] = 0; c[1] = 5; c[2] = 10; c[3] = 20; c[4] = 30; c[5] = 40; c[6] = 50; c[7] = 60; c[8] = 70; c[9] = 80; if (nBins >= 10) c[10] = 90; if (nBins >= 11) c[11] = 100; } THStack* all = new THStack("all","all"); std::ofstream out(outname); std::ostream& o = out; // std::cout; // std::ostream& o = std::cout; o << "*author: SHAHOYAN : 2015\n" << "*title: Full centrality dependence of the charged " << "particle pseudo-rapidity density over the widest " << "possible pseudo-rapidity range in Pb-Pb collisions " << "at 5.02 TeV\n" << "*detector: TRACKLETS\n" << "*experiment: CERN-LHC-TRACKLETS\n" << "*comment: CERN-LHC: We present the charged particle pseudo-rapidity " << "density of charged particles in Pb-Pb collisions at sqrt(s)/nucleon " "= 5.02 over the widest possible pseudo-rapidity and centrality range " << "possible.\n" << std::endl; for (Int_t i = 0; i < nBins; i++) { TString hName = Form("bin%d_DataCorrSignal_PbPb",i); TH1* h = static_cast<TH1*>(arr->FindObject(hName)); if (!h) { hName.ReplaceAll("PbPb", "PBPB"); h = static_cast<TH1*>(arr->FindObject(hName)); if (!h) { Warning("", "Histogram (%s) missing for bin %d", hName.Data(), i); arr->Print(); continue; } } Color_t col = PbPbColor(c[i], c[i+1]); h->SetLineColor(col); h->SetMarkerColor(col); h->SetFillColor(col); all->Add(h); Info("","Making GSE for %0d%% to %3d%% (%d)", Int_t(c[i]), Int_t(c[i+1]), col); MakeGSE(o, h, c[i], c[i+1], reweigh); } // all->Draw("nostack"); o << "*E" << std::endl; out.close(); TCanvas* can = new TCanvas("c","C", 1600, 800); can->SetRightMargin(0.2); can->SetTopMargin(0.01); TLegend* cl = new TLegend(1-can->GetRightMargin(), can->GetBottomMargin(),.99, 1-can->GetTopMargin()); cl->SetFillStyle(0); cl->SetBorderSize(0); gROOT->LoadMacro("$HOME/GraphSysErr/GraphSysErr.C+"); TList* ll = GraphSysErr::Import(outname); // ll->ls(); TIter next(ll); TObject* obj = 0; Bool_t first = true; TH1* frame = 0; Double_t min=100000, max=0; Int_t i = 0; while ((obj = next())) { if (c[i+1] > 80) break; GraphSysErr* g = static_cast<GraphSysErr*>(obj); Color_t col = PbPbColor(c[i], c[i+1]); TLegendEntry* e = cl->AddEntry("", Form("%4.1f-%4.1f%%", c[i], c[i+1]), "F"); e->SetFillColor(col); e->SetFillStyle(1001); g->SetLineColor(col); g->SetMarkerColor(col); g->SetFillColor(col); // g->Print("qual"); g->SetDataOption(GraphSysErr::kNoTick); g->SetSumOption(GraphSysErr::kBox); g->SetSumLineColor(col); g->SetSumFillColor(col); g->SetCommonSumOption(GraphSysErr::kBox); g->SetCommonSumLineColor(col); g->SetCommonSumFillColor(col); g->SetName(Form("tracklets%03dd%02d_%03dd%02d", Int_t(c[i]), Int_t(c[i]*100) % 100, Int_t(c[i+1]), Int_t(c[i+1]*100) % 100)); g->SetTitle(Form("%4.1f - %4.1f%%", c[i], c[i+1])); if (first) g->Draw("combine stat quad axis xbase=2.5"); else g->Draw("combine stat quad xbase=2.5"); if (!frame) frame = g->GetMulti()->GetHistogram(); first = false; Double_t mn, mx; g->GetMinMax("combine stat quad", mn, mx); FindLeastLargest(g, c[i], c[i+1]); min = TMath::Min(min, mn); max = TMath::Max(max, mx); i++; } frame->SetMinimum(min*.9); frame->SetMaximum(max*1.1); cl->Draw(); TFile* outFile = TFile::Open(Form("PbPb5023midRapidity%s.root", reweigh ? "Reweighed" : "Normal"), "RECREATE"); ll->Write("container",TObject::kSingleKey); outFile->Write(); can->SaveAs(Form("PbPb5023midRapidity%s.png", reweigh ? "Reweighed" : "Normal")); }
/** * * * @param o * @param useWeights * @param correct * * @ingroup pwglf_forward_scripts_tests */ void TestPoisson(Double_t o=.3, bool useWeights=false, bool correct=true) { const char* load = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C"; if (!gROOT->GetClass("AliAODForwardMult")) { gROOT->Macro(load); gROOT->GetInterpreter()->UnloadFile(gSystem->ExpandPathName(load)); } // --- Parameters of this script ----------------------------------- Int_t nBin = 5; // Our detector matrix size Int_t nMax = TMath::Max(Int_t(nBin * nBin * o + .5)+nBin/2,nBin); Int_t nEv = 10000; // Number of events Double_t mp = o; // The 'hit' probability TH2D* base = new TH2D("base", "Basic histogram", nBin,-.5, nBin-.5, nBin, -.5, nBin-.5); base->SetXTitle("#eta"); base->SetYTitle("#varphi"); base->SetDirectory(0); base->SetOption("colz"); Int_t tN1=nMax; Double_t tMin1; Double_t tMax1; Int_t tN2=nMax*10; Double_t tMin2; Double_t tMax2=nMax; MakeIntegerAxis(tN1, tMin1, tMax1); MakeIntegerAxis(tN2, tMin2, tMax2); TH2D* corr = new TH2D("comp", "Comparison", tN1, tMin1, tMax1, tN2, tMin2, tMax2); corr->SetXTitle("Input"); corr->SetYTitle("Poisson"); corr->SetDirectory(0); corr->SetOption("colz"); corr->SetStats(0); TLine* lcorr = new TLine(0, 0, tMax2, tMax2); Int_t mm = TMath::Max(Int_t(nBin * o + .5),nBin/2); tN2=mm*10; tMax2 = mm; MakeIntegerAxis(tN2, tMin2, tMax2); Info("", "Making mean w/nbins=%d,range=[%f,%f]", tN2, tMin2, tMax2); TH2D* mean = new TH2D("mean", "Mean comparison", tN2, tMin2, tMax2, tN2, tMin2, tMax2); mean->SetXTitle("Input"); mean->SetYTitle("Poisson"); mean->SetDirectory(0); mean->SetOption("colz"); mean->SetStats(0); TLine* lmean = new TLine(tMin2, tMin2, tMax2, tMax2); TH1D* dist = new TH1D("dist", "Distribution of hits", tN1, tMin1, tMax1); dist->SetXTitle("s"); dist->SetYTitle("P(s)"); dist->SetFillColor(kRed+1); dist->SetFillStyle(3001); dist->SetDirectory(0); TH1D* diff = new TH1D("diff", "P-T", 100, -25, 25); diff->SetXTitle("Difference"); diff->SetFillColor(kRed+1); diff->SetFillStyle(3001); diff->SetYTitle("Prob"); AliPoissonCalculator* c = new AliPoissonCalculator("ignored"); c->Init(nBin ,nBin); for (Int_t i = 0; i < nEv; i++) { c->Reset(base); base->Reset(); for (Int_t iEta = 0; iEta < nBin; iEta++) { for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { // Throw a die Int_t m = gRandom->Poisson(mp); dist->Fill(m); // Fill into our base histogram base->Fill(iEta, iPhi, m); // Fill into poisson calculator c->Fill(iEta, iPhi, m > 0, (useWeights ? m : 1)); } } // Calculate the result TH2D* res = c->Result(correct); // Now loop and compare Double_t mBase = 0; Double_t mPois = 0; for (Int_t iEta = 0; iEta < nBin; iEta++) { for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { Double_t p = res->GetBinContent(iEta, iPhi); Double_t t = base->GetBinContent(iEta, iPhi); mBase += t; mPois += p; corr->Fill(t, p); diff->Fill(p-t); } } Int_t nn = nBin * nBin; mean->Fill(mBase / nn, mPois / nn); } TCanvas* cc = new TCanvas("c", "c", 900, 900); cc->SetFillColor(0); cc->SetFillStyle(0); cc->SetBorderMode(0); cc->SetRightMargin(0.02); cc->SetTopMargin(0.02); cc->Divide(2,2); TVirtualPad* pp = cc->cd(1); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetLogz(); pp->SetGridx(); pp->SetGridy(); corr->Draw(); lcorr->Draw(); pp = cc->cd(2); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.02); pp->SetTopMargin(0.02); #if 0 c->GetMean()->Draw(); #elif 1 pp->SetLogy(); diff->Draw(); #elif 1 c->GetOccupancy()->Draw(); #else pp->SetLogy(); dist->SetStats(0); dist->Scale(1. / dist->Integral()); dist->Draw(); TH1D* m1 = c->GetMean(); m1->Scale(1. / m1->Integral()); m1->Draw("same"); Double_t eI; Double_t ii = 100 * dist->Integral(2, 0); TLatex* ll = new TLatex(.97, .85, Form("Input #bar{m}: %5.3f", mp)); ll->SetNDC(); ll->SetTextFont(132); ll->SetTextAlign(31); ll->Draw(); ll->DrawLatex(.97, .75, Form("Result #bar{m}: %5.3f", dist->GetMean())); ll->DrawLatex(.97, .65, Form("Occupancy: #int_{1}^{#infty}P(s)ds = %6.2f%%", ii)); #endif pp = cc->cd(3); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetGridx(); pp->SetGridy(); c->GetCorrection()->Draw(); pp = cc->cd(4); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetLogz(); pp->SetGridx(); pp->SetGridy(); mean->Draw(); lmean->Draw(); cc->cd(); }