TEST(SegmentArray, SubSeq) { CudppPlanFactory planPool; SegmentArray<int> a(&planPool, 30); for (int i = 0; i != a.getSize(); i++) { a[i] = i; } MirroredArray<int> lows(1); MirroredArray<int> his(1); lows[0] = 5; his[0] = 10; SegmentArray<int> sub(&planPool); a.subseq(lows, his, sub); EXPECT_EQ(sub[0], 5); EXPECT_EQ(sub[1], 6); EXPECT_EQ(sub.getSegLength()[0], his[0]-lows[0]); }
std::istream& HTTPClientSession::receiveResponse(HTTPResponse& response) { delete _pRequestStream; _pRequestStream = 0; do { response.clear(); HTTPHeaderInputStream his(*this); try { response.read(his); } catch (MessageException&) { close(); if (networkException()) networkException()->rethrow(); else throw; } catch (Exception&) { close(); throw; } } while (response.getStatus() == HTTPResponse::HTTP_CONTINUE); _mustReconnect = getKeepAlive() && !response.getKeepAlive(); if (!_expectResponseBody) _pResponseStream = new HTTPFixedLengthInputStream(*this, 0); else if (response.getChunkedTransferEncoding()) _pResponseStream = new HTTPChunkedInputStream(*this); else if (response.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH) _pResponseStream = new HTTPFixedLengthInputStream(*this, response.getContentLength()); else _pResponseStream = new HTTPInputStream(*this); return *_pResponseStream; }
std::istream& HTTPClientSession::receiveResponse(HTTPResponse& response) { _pRequestStream = 0; if (networkException()) networkException()->rethrow(); do { response.clear(); HTTPHeaderInputStream his(*this); try { response.read(his); } catch (MessageException&) { close(); if (networkException()) networkException()->rethrow(); else throw; } catch (Exception&) { close(); throw; } } while (false /* response.getStatus() == HTTPResponse::HTTP_CONTINUE */); _mustReconnect = getKeepAlive() && !response.getKeepAlive(); if (!_expectResponseBody || response.getStatus() < 200 || response.getStatus() == HTTPResponse::HTTP_NO_CONTENT || response.getStatus() == HTTPResponse::HTTP_NOT_MODIFIED) _pResponseStream.reset(new HTTPFixedLengthInputStream(*this, 0)); else if (response.getChunkedTransferEncoding()) throw NotImplementedException("HTTPClientSession::receiveResponse ChunkedInputStream"); else if (response.hasContentLength()) _pResponseStream.reset(new HTTPFixedLengthInputStream(*this, response.getContentLength())); else throw NotImplementedException("HTTPClientSession::receiveResponse HTTPIOStream"); return *_pResponseStream; }
void Item::getAttackMsg(const Creature* c, const string& enemyName) const { auto weaponInfo = getWeaponInfo(); auto swingMsg = [&] (const char* verb) { c->secondPerson("You "_s + verb + " your " + getName() + " at " + enemyName); c->thirdPerson(c->getName().the() + " " + verb + "s " + his(c->getAttributes().getGender()) + " " + getName() + " at " + enemyName); }; auto biteMsg = [&] (const char* verb2, const char* verb3) { c->secondPerson("You "_s + verb2 + " " + enemyName); c->thirdPerson(c->getName().the() + " " + verb3 + " " + enemyName); }; switch (weaponInfo.attackMsg) { case AttackMsg::SWING: swingMsg("swing"); break; case AttackMsg::THRUST: swingMsg("thrust"); break; case AttackMsg::WAVE: swingMsg("wave"); break; case AttackMsg::KICK: biteMsg("kick", "kicks"); break; case AttackMsg::BITE: biteMsg("bite", "bites"); break; case AttackMsg::TOUCH: biteMsg("touch", "touches"); break; case AttackMsg::CLAW: biteMsg("claw", "claws"); break; case AttackMsg::SPELL: biteMsg("curse", "curses"); break; } }
void FitSignals(TTree * treeB, TCut cut, Int_t max){ AliSignalProcesor proc; TF1 * f1 = proc.GetAsymGauss(); TTreeSRedirector cstream("FitSignal.root"); TFile *f = cstream.GetFile(); char lname[100]; sprintf(lname,"Fit%s", cut.GetTitle()); TEventList *list = new TEventList(lname,lname); sprintf(lname,">>Fit%s", cut.GetTitle()); treeB->Draw(lname,cut); treeB->SetEventList(list); Int_t nFits=0; for (Int_t ievent=0; ievent<list->GetN(); ievent++){ if (nFits>max) break; if (nFits%50==0) printf("%d\n",nFits); char ename[100]; sprintf(ename,"Fit%d", ievent); Double_t nsample = treeB->Draw("Graph.fY-Mean09:Graph.fX","","",1,ievent); Double_t * signal = treeB->GetV1(); Double_t * time = treeB->GetV2(); Double_t maxpos =0; Double_t max = 0; for (Int_t ipos = 0; ipos<nsample; ipos++){ if (signal[ipos]>max){ max = signal[ipos]; maxpos = ipos; } } Int_t first = TMath::Max(maxpos-10,0.); Int_t last = TMath::Min(maxpos+60, nsample); // f->cd(); TH1F his(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his.SetBinContent(ipos+1,signal[ipos+first]); } treeB->Draw("Sector:Row:Pad","","",1,ievent); Double_t sector = treeB->GetV1()[0]; Double_t row = treeB->GetV2()[0]; Double_t pad = treeB->GetV3()[0]; // TGraph graph(last-first,&time[first],&signal[first]); f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2); // TH1F * his = (TH1F*)graph.GetHistogram(); his.Fit(f1,"q"); his.Write(ename); gPad->Clear(); his.Draw(); gPad->Update(); Double_t params[6]; for (Int_t ipar=0; ipar<6; ipar++) params[ipar] = f1->GetParameters()[ipar]; Double_t chi2 = TFitter::GetFitter()->Chisquare(6,params); TMatrixD cov(6,6); cov.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix()); // // tail cancellation // Double_t x0[1000]; Double_t x1[1000]; Double_t x2[1000]; for (Int_t ipos=0; ipos<last-first; ipos++){ x0[ipos] = signal[ipos+first]; } proc.TailCancelationALTRO1(x0,x1,0.85*0.339,0.09,last-first); proc.TailCancelationALTRO1(x1,x2,0.85,0.789,last-first); // sprintf(ename,"Cancel1_%d", ievent); TH1F his1(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his1.SetBinContent(ipos+1,x1[ipos]); } his1.Write(ename); sprintf(ename,"Cancel2_%d", ievent); TH1F his2(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his2.SetBinContent(ipos+1,x1[ipos]); } f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2); his2.Fit(f1,"q"); his2.Write(ename); Double_t params2[6]; for (Int_t ipar=0; ipar<6; ipar++) params2[ipar] = f1->GetParameters()[ipar]; Double_t chi22 = TFitter::GetFitter()->Chisquare(6,params2); TMatrixD cov2(6,6); cov2.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix()); TGraph gr0(last-first, &time[first],x0); TGraph gr1(last-first, &time[first],x1); TGraph gr2(last-first, &time[first],x2); // cstream<<"Fit"<< "Sector="<<sector<< "Row="<<row<< "Pad="<<pad<< "First="<<first<< "Max="<<max<< "MaxPos="<<maxpos<< "chi2="<<chi2<< "chi22="<<chi22<< "Cov="<<&cov<< "Cov2="<<&cov2<< "gr0.="<<&gr0<< "gr1.="<<&gr1<< "gr2.="<<&gr2<< "p0="<<params[0]<< "p1="<<params[1]<< "p2="<<params[2]<< "p3="<<params[3]<< "p4="<<params[4]<< "p5="<<params[5]<< "p02="<<params2[0]<< "p12="<<params2[1]<< "p22="<<params2[2]<< "p32="<<params2[3]<< "p42="<<params2[4]<< "p52="<<params2[5]<< "\n"; // delete his; nFits++; } }
int ratio5() { // Constants and arrays Int_t multi = 2; const Int_t n_at = 3; Int_t at[n_at] = { 500, 510, 550 }; //for ( int ii = 0; ii < n_at; ++ii ) { at[ii] = 500 + ii * 10; } TString eq = "Gt"; const Int_t n = 4; float pt[n] = { 50., 40., 30., 20. }; Int_t colour[n] = { 1, 2, 3, 4 }; const Int_t m = 2; Int_t style[m] = { kOpenSquare, kFullSquare }; const Int_t ngr = 1000; double x3[ngr]; double r[ngr]; int count = 0; // General style gStyle->SetOptStat(0); // // Canvas for RECO curves // TCanvas* reco_canvas = new TCanvas("Reco"); // reco_canvas->SetFillColor(0); // reco_canvas->SetLineColor(0); // reco_canvas->SetLogy(); // TLegend* reco_legend = new TLegend( 0.5, 0.7, 0.88, 0.88, NULL, "brNDC" ); // reco_legend->SetFillColor(0); // reco_legend->SetLineColor(0); // bool empty = true; // double reco_max = 1.e-15.; // double reco_min = 1.e15; // Loop through pt bins for ( Int_t i = 0; i < 1; ++i ) { std::stringstream pt_can; pt_can << "PtBin" << pt[i]; // Canvas for Pt bin TCanvas* pt_canvas = new TCanvas(TString(pt_can.str()),""); pt_canvas->SetFillColor(0); pt_canvas->SetLineColor(0); pt_canvas->SetLogy(); TLegend* pt_legend = new TLegend( 0.82, 0.5, 0.98, 0.9, NULL, "brNDC" ); pt_legend->SetFillColor(0); pt_legend->SetLineColor(0); bool empty = true; double pt_max = 1.e-15.; double pt_min = 1.e15; std::vector<TH1*> pt_ratio; pt_canvas->SetRightMargin(0.2); // Open files std::stringstream ss; ss << "results/4/Reco" << pt[i] << "_QCDPythia6.root"; TString name(ss.str()); TFile* file = new TFile(name); if ( file->IsZombie() || !(file->IsOpen()) ) { continue; } file->cd(); // Loop through AlphaT thresolds for ( Int_t iat = 0; iat < n_at; ++iat ) { // Loop through RECO and GEN for ( Int_t j = 0; j < m; ++j ) { // Define names of histos to open std::stringstream pre; std::stringstream post; if ( j == 0 ) { pre << "Ratio" << at[iat] << "/GenHt" << eq << "PreAlphaT" << at[iat] << "_" << multi; post << "Ratio" << at[iat] << "/GenHt" << eq << "PostAlphaT" << at[iat] << "_" << multi; std::cout << pre.str() << std::endl; std::cout << post.str() << std::endl; } else if ( j == 1 ) { pre << "Ratio" << at[iat] << "/Ht" << eq << "PreAlphaT" << at[iat] << "_" << multi; post << "Ratio" << at[iat] << "/Ht" << eq << "PostAlphaT" << at[iat] << "_" << multi; std::cout << pre.str() << std::endl; std::cout << post.str() << std::endl; } // Create ratio histo TH1* denominator = his( (TH1*)file->Get(TString(pre.str())), 45, 200., 650. ); TH1* numerator = his( (TH1*)file->Get(TString(post.str())), 45, 200., 650. ); int rebin = 5; numerator->Rebin(rebin); denominator->Rebin(rebin); TH1* ratio = (TH1*)numerator->Clone(); ratio->Divide(denominator); //ratio->Divide(numerator,denominator,1.,1.,"b"); //@@ poisson errors ratio->SetMarkerStyle(style[j]); ratio->SetMarkerSize(1.2); ratio->SetMarkerColor(iat+1);//colour[iat]); ratio->SetBarOffset(0.1*i); //ratio->GetXaxis()->SetRangeUser(100.,550.); ratio->GetYaxis()->SetRangeUser(1.e-7,1.e-1); ratio->GetXaxis()->SetTitle("HT_{reco} [GeV]"); ratio->GetYaxis()->SetTitle("R(#alpha_{T})"); if ( ratio->GetMaximum() > 0. && ratio->GetMaximum() > pt_max ) { pt_max = ratio->GetMaximum(); } if ( ratio->GetMinimum() > 0. && ratio->GetMinimum() < pt_min ) { pt_min = ratio->GetMinimum(); } pt_ratio.push_back(ratio); if ( empty ) { ratio->Draw(""); empty = false; } else { ratio->Draw("same"); } //ratio->GetYaxis()->SetRangeUser(pt_min/1.1,pt_max*1.1); // Text for legend std::stringstream pt_leg; if ( j == 0 ) { pt_leg << "#alpha_{T} = " << at[iat]/1000. << ", GEN"; } else if ( j == 1 ) { pt_leg << "#alpha_{T} = " << at[iat]/1000. << ", RECO"; } pt_legend->AddEntry( ratio, TString(pt_leg.str()), "lep" ); // // Draw histos on canvas for RECO only // if ( j == 1 ) { // reco_canvas->cd(); // if ( i == 0 ) ratio->Draw(""); // else ratio->Draw("same"); // std::stringstream reco_leg; // reco_leg << "p_{T}^{min} = " << pt[i]; // reco_legend->AddEntry( ratio, TString(reco_leg.str()), "lep" ); // } } } // if (0) { // int nbins = ratio->GetNbinsX(); // int bin_width = ratio->GetBinWidth(1); // double lower = 0.; // double upper = 1400.; // int bin_lower = int( ( lower - ratio->GetBinLowEdge(1) ) / bin_width ); // for ( Int_t ii = bin_lower; ii < ratio->GetNbinsX()-1; ++ii ) { // if ( ratio->GetBinContent(ii) > 0. ) { // lower = ratio->GetBinCenter(ii); // break; // } // } // int bin_upper = int( ( upper - ratio->GetBinLowEdge(1) ) / bin_width ); // for ( Int_t ii = bin_upper; ii > 0; --ii ) { // if ( ratio->GetBinContent(ii) > 0. ) { // upper = ratio->GetBinCenter(ii); // break; // } // } // if (0) { // std::cout << " bin_width: " << bin_width // << " bin_lower: " << bin_lower // << " bin_upper: " << bin_upper // << " lower: " << lower // << " upper: " << upper // << std::endl; // } // TF1* fit = new TF1(sample[i],"expo",lower,upper); // fit->SetLineColor(colour[i]); // fit->SetLineWidth(1); // ratio->Fit(sample[i],"QR","same"); // } pt_canvas->cd(); // for ( Int_t iii = 0; iii < pt_ratio.size(); ++iii ) { // TH1* ratio = pt_ratio[iii]; // if ( !ratio ) { continue; } // if ( ii == 0 ) { ratio->Draw(""); } // else { ratio->Draw("same"); } // ratio->GetYaxis()->SetRangeUser(pt_min/1.1,pt_max*1.1); // } pt_legend->Draw("same"); pt_canvas->Update(); pt_canvas->SaveAs(TString(pt_can.str()+".png")); // pt_canvas->SaveAs(TString(pt_can.str()+".C")); } // reco_canvas->cd(); // reco_legend->Draw("same"); // reco_canvas->Update(); // reco_canvas->SaveAs(TString("Reco.png")); // reco_canvas->SaveAs(TString("Reco.C")); // TCanvas* c2 = new TCanvas("C2"); // c2->SetLogy(); // c2->SetFillColor(0); // gStyle->SetOptStat(0); // if ( count > 0 ) { // TGraph* graph = new TGraph(count,x3,r); // graph->Draw("a*"); // } }