void draw_grid(int i,int j,int k)                       //This draws the grid and changes the color the grid according to the player
{   beginFrame();
    Line h1(0,0,600,0),h2(0,100,600,100),               // "h" is the horizontal lines and "v" is the vertical lines
    h3(0,200,600,200),h4(0,300,600,300),
    h5(0,400,600,400),h6(0,500,600,500),
    h7(0,600,600,600),h8(0,700,600,700),
    h9(0,800,600,800);
    Line v1(0,0,0,800),v2(100,0,100,800),
    v3(200,0,200,800),v4(300,0,300,800),
    v5(400,0,400,800),v6(500,0,500,800),
    v7(600,0,600,800);
    h1.setColor(COLOR(255*i,255*j,255*k)),h2.setColor(COLOR(255*i,255*j,255*k)),
    h3.setColor(COLOR(255*i,255*j,255*k)),h4.setColor(COLOR(255*i,255*j,255*k)),
    h5.setColor(COLOR(255*i,255*j,255*k)),h6.setColor(COLOR(255*i,255*j,255*k)),
    h7.setColor(COLOR(255*i,255*j,255*k)),h8.setColor(COLOR(255*i,255*j,255*k)),
    h9.setColor(COLOR(255*i,255*j,255*k));
    v1.setColor(COLOR(255*i,255*j,255*k)),v2.setColor(COLOR(255*i,255*j,255*k)),
    v3.setColor(COLOR(255*i,255*j,255*k)),v4.setColor(COLOR(255*i,255*j,255*k)),
    v5.setColor(COLOR(255*i,255*j,255*k)),v6.setColor(COLOR(255*i,255*j,255*k)),
    v7.setColor(COLOR(255*i,255*j,255*k));
    h1.imprint(),h2.imprint(),
    h3.imprint(),h4.imprint(),
    h5.imprint(),h6.imprint(),
    h7.imprint(),h8.imprint(),h9.imprint();
    v1.imprint(),v2.imprint(),
    v3.imprint(),v4.imprint(),
    v5.imprint(),v6.imprint(),v7.imprint();
    endFrame();
}
Beispiel #2
0
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Sig_Handlers_Test"));

  ACE_Sig_Handlers multi_handlers;
  ACE_Select_Reactor reactor_impl (&multi_handlers);
  ACE_Reactor reactor (&reactor_impl);
  ACE_Reactor::instance (&reactor);

  // Create a bevy of handlers.

  Test_SIGINT_Handler h1 (ACE_Reactor::instance (), "h1");
  Test_SIGINT_Handler h2 (ACE_Reactor::instance (), "h2");
  Test_SIGINT_Handler h3 (ACE_Reactor::instance (), "h3");
  Test_SIGINT_Handler h4 (ACE_Reactor::instance (), "h4");
  Test_SIGINT_Handler h5 (ACE_Reactor::instance (), "h5");
  Test_SIGINT_Handler h6 (ACE_Reactor::instance (), "h6");
  Test_SIGINT_Handler h7 (ACE_Reactor::instance (), "h7");
  Test_SIGINT_Handler h8 (ACE_Reactor::instance (), "h8");

  Test_SIGINT_Shutdown_Handler h0 (ACE_Reactor::instance ());

  // Wait for user to type SIGINT.
  while (!ACE_Reactor::instance ()->reactor_event_loop_done ())
    {
      ACE_DEBUG ((LM_DEBUG,"\nwaiting for SIGINT\n"));
      if (ACE_Reactor::instance ()->handle_events () == -1)
        ACE_ERROR ((LM_ERROR,"%p\n","handle_events"));
    }

  ACE_END_TEST;
  return 0;
}
 Calendar* Hebrew::update_from_fixed (double date, Calendar* c)
 {    
   double approx = floor (98496.0f/35975351.0f * (date - rep_.d_epoch ())) + 1.0f;
   double y = approx - 1.0f;
   double mx = y;
   while (new_year (y) <= date)
     {
       y += 1.0f;
       if (y > mx)
         mx = y;
     }
   double year = mx;
   Hebrew h1 (year, NISAN, 1);
   Month start = date < h1.to_fixed_date () ? TISHRI : NISAN;
   double m = static_cast<double> (start);
   double mn = m;
   while (true)
     {
       Hebrew h2 (year, m, last_day_of_month (static_cast<Month> (m), year));               
       bool b = (date <= h2.to_fixed_date());
       if (m < mn) mn = m;
       if (b)
         break;
       m += 1.0f;        
     }
   double month = mn;
   Hebrew h3 (year, month, 1);
   double day = 1 + date - h3.to_fixed_date ();
   Hebrew* ret = dynamic_cast<Hebrew*> (c);
   ret->rep_ = ThreePartRepresentation (rep_.d_epoch (), year, month, day);
   return c;
 }
Beispiel #4
0
int main()
{
  decltype(auto) i = f();
  same_type<decltype(i),int&>();
  decltype(auto) i2 = i;
  same_type<decltype(i2),int&>();
  decltype(auto) i3 = ::i;
  same_type<decltype(i3),int>();
  decltype(auto) i4 = (::i);
  same_type<decltype(i4),int&>();
  decltype(auto) i5 = a.i;
  same_type<decltype(i5),int>();
  decltype(auto) i6 = (a.i);
  same_type<decltype(i6),int&>();
  decltype(auto) i7 = true ? ::i : ::i;
  same_type<decltype(i7),int&>();

  same_type<decltype(g()),int&>();
  same_type<decltype(h1()),int>();
  same_type<decltype(h2()),int&>();
  same_type<decltype(h2a()),int&>();
  same_type<decltype(h3()),int>();
  same_type<decltype(h4()),int&>();
  same_type<decltype(h5(a)),int>();
  same_type<decltype(h6(a)),int&>();
}
Beispiel #5
0
 ST Hermite(ST m0, ST y0, ST y1, ST m1, FT t)
 {
     return
         m0 * h3(t) +
         y0 * h1(t) +
         y1 * h2(t) +
         m1 * h4(t);
 }
void convertHFShowerLibrary() {
  TFile *nF=new TFile("david.root","RECREATE","hiThere",1);
  TTree *nT=new TTree("HFSimHits","HF simple tree");
  std::vector<float> *parts=new std::vector<float>();
  std::vector<float> *partsHad=new std::vector<float>();
  nT->Branch("emParticles", &parts);
  nT->GetBranch("emParticles")->SetBasketSize(1);
  nT->Branch("hadParticles", &partsHad);
  nT->GetBranch("hadParticles")->SetBasketSize(1);

  TDirectory *target=gDirectory;
  TFile *oF=TFile::Open("HFShowerLibrary_npmt_noatt_eta4_16en_v3_orig.root");
  TTree *t=(TTree*)oF->Get("HFSimHits");
  TTreeReader fReader(t);
  TTreeReaderArray<Float_t> b1(fReader, "emParticles.position_.fCoordinates.fX");
  TTreeReaderArray<Float_t> b2(fReader, "emParticles.position_.fCoordinates.fY");
  TTreeReaderArray<Float_t> b3(fReader, "emParticles.position_.fCoordinates.fZ");
  TTreeReaderArray<Float_t> b4(fReader, "emParticles.lambda_");
  TTreeReaderArray<Float_t> b5(fReader, "emParticles.time_");

  TTreeReaderArray<Float_t> h1(fReader, "hadParticles.position_.fCoordinates.fX");
  TTreeReaderArray<Float_t> h2(fReader, "hadParticles.position_.fCoordinates.fY");
  TTreeReaderArray<Float_t> h3(fReader, "hadParticles.position_.fCoordinates.fZ");
  TTreeReaderArray<Float_t> h4(fReader, "hadParticles.lambda_");
  TTreeReaderArray<Float_t> h5(fReader, "hadParticles.time_");


  target->cd();
  while ( fReader.Next() ) {
    parts->clear();
    unsigned int s=b1.GetSize();
    parts->resize(5*s);
    for ( unsigned int i=0; i<b1.GetSize(); i++) {
      (*parts)[i]=(b1[i]);
      (*parts)[i+1*s]=(b2[i]);
      (*parts)[i+2*s]=(b3[i]);
      (*parts)[i+3*s]=(b4[i]);
      (*parts)[i+4*s]=(b5[i]);
    }  

    partsHad->clear();
    s=h1.GetSize();
    partsHad->resize(5*s);
    for ( unsigned int i=0; i<h1.GetSize(); i++) {
      (*partsHad)[i]=(h1[i]);
      (*partsHad)[i+1*s]=(h2[i]);
      (*partsHad)[i+2*s]=(h3[i]);
      (*partsHad)[i+3*s]=(h4[i]);
      (*partsHad)[i+4*s]=(h5[i]);
    }  

    nT->Fill();
  }

  nT->Write();
  nF->Close();
}
// check wait in new thread
void test_case_1()
{
	boost::uint32_t n = 3;
	tsk::spin::manual_reset_event ev;

	tsk::handle< boost::uint32_t > h1(
			tsk::async(
				tsk::make_task(
					wait_fn,
					n, boost::ref( ev) ),
				tsk::new_thread() ) );
	tsk::handle< boost::uint32_t > h2(
			tsk::async(
				tsk::make_task(
					wait_fn,
					n, boost::ref( ev) ),
				tsk::new_thread() ) );

	boost::this_thread::sleep( pt::millisec( 250) );
	BOOST_CHECK( ! h1.is_ready() );
	BOOST_CHECK( ! h2.is_ready() );

	ev.set();

	boost::this_thread::sleep( pt::millisec( 250) );
	BOOST_CHECK( h1.is_ready() );
	BOOST_CHECK( h2.is_ready() );
	BOOST_CHECK_EQUAL( h1.get(), n);
	BOOST_CHECK_EQUAL( h2.get(), n);

	ev.reset();

	tsk::handle< boost::uint32_t > h3(
			tsk::async(
				tsk::make_task(
					wait_fn,
					n, boost::ref( ev) ),
				tsk::new_thread() ) );
	tsk::handle< boost::uint32_t > h4(
			tsk::async(
				tsk::make_task(
					wait_fn,
					n, boost::ref( ev) ),
				tsk::new_thread() ) );

	boost::this_thread::sleep( pt::millisec( 250) );
	BOOST_CHECK( ! h3.is_ready() );
	BOOST_CHECK( ! h4.is_ready() );

	ev.set();

	boost::this_thread::sleep( pt::millisec( 250) );
	BOOST_CHECK( h3.is_ready() );
	BOOST_CHECK( h4.is_ready() );
	BOOST_CHECK_EQUAL( h3.get(), n);
	BOOST_CHECK_EQUAL( h4.get(), n);
}
Beispiel #8
0
static void ex1() {
    unsynch_mpq_manager        qm;
    polynomial::manager        pm(qm);
    polynomial_ref x(pm);
    polynomial_ref a(pm);
    polynomial_ref b(pm);
    polynomial_ref c(pm);
    x = pm.mk_polynomial(pm.mk_var());
    a = pm.mk_polynomial(pm.mk_var());
    b = pm.mk_polynomial(pm.mk_var());
    c = pm.mk_polynomial(pm.mk_var());
    polynomial_ref p(pm);
    p = (a + 2*b)*(x^3) + x*a + (b^2);
    polynomial_ref p1(pm);
    p1 = derivative(p, 0);
    polynomial_ref h2(pm);
    unsigned d;
    h2 = pseudo_remainder(p, p1, 0, d);
    std::cout << "d: " << d << "\n";
    std::cout << "p: "; pp(p, 0); std::cout << "\np': "; pp(p1, 0); std::cout << "\nh2: "; pp(h2, 0); std::cout << "\n";
    polynomial_ref h3(pm);
    h3 = pseudo_remainder(p1, h2, 0, d);
    std::cout << "d: " << d << "\n";
    std::cout << "h3: "; pp(h3, 0); std::cout << "\n";

    algebraic_numbers::manager am(qm);
    scoped_anum v1(am), v2(am);
    am.set(v1, 2);
    am.root(v1, 3, v1);
    am.set(v2, 3);
    am.root(v2, 3, v2);

    polynomial::simple_var2value<anum_manager> x2v(am);
    x2v.push_back(1, v1);
    x2v.push_back(2, v2);
    std::cout << "sign(h3(v1,v2)): " << am.eval_sign_at(h3, x2v) << "\n";
    scoped_anum v0(am);
    am.set(v0, -1);
    x2v.push_back(0, v0);
    std::cout << "sign(h2(v1,v2)): " << am.eval_sign_at(h2, x2v) << "\n";
    std::cout << "sign(p'(v1,v2)): " << am.eval_sign_at(p1, x2v) << "\n";
    std::cout << "sign(p(v1,v2)): " << am.eval_sign_at(p, x2v) << "\n";

    polynomial::simple_var2value<anum_manager> x2v2(am);
    x2v2.push_back(1, v1);
    x2v2.push_back(2, v2);
    scoped_mpq tmp(qm);
    qm.set(tmp, -1);
    qm.div(tmp, mpz(2), tmp);
    std::cout << "tmp: "; qm.display(std::cout, tmp); std::cout << " "; qm.display_decimal(std::cout, tmp, 10); std::cout << "\n";
    am.set(v0, tmp);
    x2v2.push_back(0, v0);
    std::cout << "v0: " << v0 << "\n";
    std::cout << "sign(h2(v1,v2)): " << am.eval_sign_at(h2, x2v2) << "\n";
    std::cout << "sign(p'(v1,v2)): " << am.eval_sign_at(p1, x2v2) << "\n";
    std::cout << "sign(p(v1,v2)): " << am.eval_sign_at(p, x2v2) << "\n";
}
Beispiel #9
0
TEST_F(HalfTest, Vec) {
    float4 f4(1,2,3,4);
    half4 h4(f4);
    half3 h3(f4.xyz);
    half2 h2(f4.xy);

    EXPECT_EQ(f4, h4);
    EXPECT_EQ(f4.xyz, h3);
    EXPECT_EQ(f4.xy, h2);
}
int main() {
    int counts[10] = {0,0,0,0,0,0,0,0,0,0};
    unsigned samples[8] = {333, 632, 1090, 459, 238, 1982, 3411, 379};
    int i;

    for ( i = 0; i < 8; ++i )
        counts[h2(samples[i], 11)-1]++;
    report("Samples with h2", counts);
    for ( i = 0; i < 992; ++i )
        counts[h2(3412+i, 11)-1]++;
    report("Adding 3412-4403", counts);
    for ( i = 0; i < 10; ++i )
        counts[i] = 0;
    for ( i = 0; i < 8; ++i )
        counts[h3(samples[i], 11)-1]++;
    report("Samples with h3", counts);
    for ( i = 0; i < 992; ++i )
        counts[h3(3412+i, 11)-1]++;
    report("Adding 3412-4403", counts);
}
Beispiel #11
0
 mini_pow mini_pow_hash( const fc::sha512& h1 )
 {
     auto h2 = fc::sha512::hash( (char*)&h1, sizeof(h1) );
     mini_pow p;
     fc::bigint  h3( (char*)&h2, sizeof(h2) );
     int64_t lz = 512 - h3.log2();
     h3 <<= lz;
     std::vector<char> bige = h3;
     bige[0] = 255-lz;
     memcpy( p.data, bige.data(), sizeof(p) );
     return p;
 }
Beispiel #12
0
int
ACE_TMAIN (int argc, ACE_TCHAR *[])
{
  // If argc > 1 then allow multiple handlers per-signal, else just
  // allow 1 handler per-signal.
  ACE_Sig_Handlers multi_handlers;

#if defined (ACE_WIN32)
  ACE_WFMO_Reactor reactor_impl (argc > 1
                                 ? &multi_handlers
                                 : (ACE_Sig_Handler *) 0);
#else
  ACE_Select_Reactor reactor_impl (argc > 1
                                   ? &multi_handlers
                                   : (ACE_Sig_Handler *) 0);
#endif /* ACE_WIN32 */
  ACE_Reactor reactor (&reactor_impl);

  if (argc > 1)
    {
      // Register an "external" signal handler so that the
      // ACE_Sig_Handlers code will have something to incorporate!

      ACE_SignalHandler eh = (ACE_SignalHandler) external_handler;
      ACE_Sig_Action sa (eh);

      sa.register_action (SIGINT);
    }

  // Create a bevy of handlers.
  Sig_Handler_1 h1 (reactor, "howdy");
  Sig_Handler_1 h2 (reactor, "doody");
  Sig_Handler_2 h3 (reactor, "tutty");
  Sig_Handler_2 h4 (reactor, "fruity");

  // Wait for user to type SIGINT and SIGQUIT.

  for (;;)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "\nwaiting for SIGINT or SIGQUIT\n"));

      if (reactor.handle_events () == -1)
        ACE_ERROR ((LM_ERROR,
                    "%p\n",
                    "handle_events"));
    }

  ACE_NOTREACHED (return 0);
}
Beispiel #13
0
/**
 * Decrypt a single block of data.
 */
void skipjack_decrypt(byte tab[10][256], byte in[8], byte out[8]) {
	word32 w1, w2, w3, w4;

	w1 = (in[0] << 8) + in[1];
	w2 = (in[2] << 8) + in[3];
	w3 = (in[4] << 8) + in[5];
	w4 = (in[6] << 8) + in[7];

	/* stepping rule A: */
	h1(tab, w2); w3 ^= w2 ^ 32;
	h0(tab, w3); w4 ^= w3 ^ 31;
	h4(tab, w4); w1 ^= w4 ^ 30;
	h3(tab, w1); w2 ^= w1 ^ 29;
	h2(tab, w2); w3 ^= w2 ^ 28;
	h1(tab, w3); w4 ^= w3 ^ 27;
	h0(tab, w4); w1 ^= w4 ^ 26;
	h4(tab, w1); w2 ^= w1 ^ 25;

	/* stepping rule B: */
	w1 ^= w2 ^ 24; h3(tab, w2);
	w2 ^= w3 ^ 23; h2(tab, w3);
	w3 ^= w4 ^ 22; h1(tab, w4);
	w4 ^= w1 ^ 21; h0(tab, w1);
	w1 ^= w2 ^ 20; h4(tab, w2);
	w2 ^= w3 ^ 19; h3(tab, w3);
	w3 ^= w4 ^ 18; h2(tab, w4);
	w4 ^= w1 ^ 17; h1(tab, w1);

	/* stepping rule A: */
	h0(tab, w2); w3 ^= w2 ^ 16;
	h4(tab, w3); w4 ^= w3 ^ 15;
	h3(tab, w4); w1 ^= w4 ^ 14;
	h2(tab, w1); w2 ^= w1 ^ 13;
	h1(tab, w2); w3 ^= w2 ^ 12;
	h0(tab, w3); w4 ^= w3 ^ 11;
	h4(tab, w4); w1 ^= w4 ^ 10;
	h3(tab, w1); w2 ^= w1 ^  9;

	/* stepping rule B: */
	w1 ^= w2 ^ 8; h2(tab, w2);
	w2 ^= w3 ^ 7; h1(tab, w3);
	w3 ^= w4 ^ 6; h0(tab, w4);
	w4 ^= w1 ^ 5; h4(tab, w1);
	w1 ^= w2 ^ 4; h3(tab, w2);
	w2 ^= w3 ^ 3; h2(tab, w3);
	w3 ^= w4 ^ 2; h1(tab, w4);
	w4 ^= w1 ^ 1; h0(tab, w1);

	out[0] = (byte)(w1 >> 8); out[1] = (byte)w1;
	out[2] = (byte)(w2 >> 8); out[3] = (byte)w2;
	out[4] = (byte)(w3 >> 8); out[5] = (byte)w3;
	out[6] = (byte)(w4 >> 8); out[7] = (byte)w4;

}
Beispiel #14
0
int main() {

    Sac<int> s;
    Sac<Horloge> b1(4);

    s+= 4;
    s+= 6;
    s+= 9;
    s+= 8;

    IterateurSac<int> it(s);
    int somme;

    cout << "Itérateur de sac avec un sac de int" << endl;

    for(somme=0; !it; ++it){
        somme += *it;
        cout << "Élément: " << *it << endl;
    }

    cout << "la somme de tous les éléments est: " << somme << endl << endl;

    Horloge h1(16,2,4,0);
    Horloge h2(5,22,56,0);
    Horloge h3(7,15,8,0);
    Horloge h4(19,7,14,0);
    Horloge h5(55,9,5,0);
    Horloge h6(1,21,22,0);

    b1+= h1;
    b1+= h2;
    b1+= h3;
    b1+= h4;
    b1+= h5;
    b1+= h6;

    cout << "Itérateur de sac avec un sac d'horloge" << endl;

    IterateurSac<Horloge> it2(b1);
    for(; !it2; ++it2){
        cout << "Horloge: " << *it2 << endl;
    }

    system("PAUSE");
    return 0;
}
Beispiel #15
0
 void testHeaders()
 {
     bh h1;
     expect(h1.empty());
     fill(1, h1);
     expect(h1.size() == 1);
     bh h2;
     h2 = h1;
     expect(h2.size() == 1);
     h2.insert("2", "2");
     expect(std::distance(h2.begin(), h2.end()) == 2);
     h1 = std::move(h2);
     expect(h1.size() == 2);
     expect(h2.size() == 0);
     bh h3(std::move(h1));
     expect(h3.size() == 2);
     expect(h1.size() == 0);
 }
Beispiel #16
0
int main( int argc, char *argv[])
{
	try
	{
		tsk::static_pool< tsk::unbounded_prio_queue< int > > pool( tsk::poolsize( 3) ); 

		tsk::task< int > t1( fibonacci_fn, 10);
		tsk::task< int > t2( fibonacci_fn, 10);
		tsk::task< int > t3( fibonacci_fn, 10);
		tsk::task< int > t4( fibonacci_fn, 10);

		tsk::handle< int > h1(
			tsk::async( boost::move( t1) ) );
		tsk::handle< int > h2(
			tsk::async(
				boost::move( t2),
				tsk::new_thread() ) );
		tsk::handle< int > h3(
			tsk::async(
				boost::move( t3),
				2,
				pool) );
		tsk::handle< int > h4(
			tsk::async(
				boost::move( t4),
				2,
				pool) );

		std::cout << h1.get() << std::endl;
		std::cout << h2.get() << std::endl;
		std::cout << h3.get() << std::endl;
		std::cout << h4.get() << std::endl;

		return EXIT_SUCCESS;
	}
	catch ( std::exception const& e)
	{ std::cerr << "exception: " << e.what() << std::endl; }
	catch ( ... )
	{ std::cerr << "unhandled" << std::endl; }

	return EXIT_FAILURE;
}
Beispiel #17
0
 ListNode *sortList(ListNode *head) {
     if (head == NULL) return NULL;
     int val = head->val;
     ListNode h1(0), h2(0), h3(0), *t1 = &h1, *t2 = &h2, *t3 = &h3;
     for (auto p = head; p; p = p->next){
         if (p->val == val){
             t2 = t2->next = p;
         }else if (p->val < val){
             t1 = t1->next = p;
         }else{
             t3 = t3->next = p;
         }
     }
     t1->next = t2->next = t3->next = NULL;
     h1.next = sortList(h1.next);
     for (t1 = &h1; t1->next; t1 = t1->next);
     t1->next = h2.next;
     t2->next = sortList(h3.next);
     return h1.next;
 }
void main(j) {
  if (j & 1) {
    f1();
  }
  if (j & 2) {
    f2();
  }
  if (j & 3) {
    f3();
  }
  if (j & 4) {
    f4();
  }
  if (j & 5) {
    g1();
  }
  if (j & 6) {
    g2();
  }
  if (j & 7) {
    g3();
  }
  if (j & 8) {
    h1();
  }
  if (j & 9) {
    h2();
  }
  if (j & 10) {
    h3();
  }
  if (j & 11) {
    h4();
  }
  if (j & 12) {
    int v;
    k(&v);
  }

}
Beispiel #19
0
/**
 * Decrypt a single block of data.
 */
void SKIPJACK::Dec::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
{
	word w1, w2, w3, w4;
	Block::Get(inBlock)(w4)(w3)(w2)(w1);

	/* stepping rule A: */
	h1(tab, w2); w3 ^= w2 ^ 32;
	h0(tab, w3); w4 ^= w3 ^ 31;
	h4(tab, w4); w1 ^= w4 ^ 30;
	h3(tab, w1); w2 ^= w1 ^ 29;
	h2(tab, w2); w3 ^= w2 ^ 28;
	h1(tab, w3); w4 ^= w3 ^ 27;
	h0(tab, w4); w1 ^= w4 ^ 26;
	h4(tab, w1); w2 ^= w1 ^ 25;

	/* stepping rule B: */
	w1 ^= w2 ^ 24; h3(tab, w2);
	w2 ^= w3 ^ 23; h2(tab, w3);
	w3 ^= w4 ^ 22; h1(tab, w4);
	w4 ^= w1 ^ 21; h0(tab, w1);
	w1 ^= w2 ^ 20; h4(tab, w2);
	w2 ^= w3 ^ 19; h3(tab, w3);
	w3 ^= w4 ^ 18; h2(tab, w4);
	w4 ^= w1 ^ 17; h1(tab, w1);

	/* stepping rule A: */
	h0(tab, w2); w3 ^= w2 ^ 16;
	h4(tab, w3); w4 ^= w3 ^ 15;
	h3(tab, w4); w1 ^= w4 ^ 14;
	h2(tab, w1); w2 ^= w1 ^ 13;
	h1(tab, w2); w3 ^= w2 ^ 12;
	h0(tab, w3); w4 ^= w3 ^ 11;
	h4(tab, w4); w1 ^= w4 ^ 10;
	h3(tab, w1); w2 ^= w1 ^  9;

	/* stepping rule B: */
	w1 ^= w2 ^ 8; h2(tab, w2);
	w2 ^= w3 ^ 7; h1(tab, w3);
	w3 ^= w4 ^ 6; h0(tab, w4);
	w4 ^= w1 ^ 5; h4(tab, w1);
	w1 ^= w2 ^ 4; h3(tab, w2);
	w2 ^= w3 ^ 3; h2(tab, w3);
	w3 ^= w4 ^ 2; h1(tab, w4);
	w4 ^= w1 ^ 1; h0(tab, w1);

	Block::Put(xorBlock, outBlock)(w4)(w3)(w2)(w1);
}
Beispiel #20
0
void calcH(tNodeQueue *p, tNodeQueue *m, int heuristica) {
    m->elem->p = p->elem;
    switch (heuristica) {
        case 1:
            m->elem->h = h1(m->elem->matrix);
            break;
        case 2:
            m->elem->h = h2(m->elem->matrix);
            break;
        case 3:
            m->elem->h = h3(m->elem->matrix);
            break;
        case 4:
            m->elem->h = h4(m->elem->matrix, p1, p2, p3);
            break;
        case 5:
            m->elem->h = h5(m->elem->matrix);
            break;

    }
    m->elem->f = m->elem->h + m->elem->g;
}
Beispiel #21
0
void test_constructor () {                      // test constructors
  typedef CoolSharedVector<int> SharedVec;
  CoolHandle< SharedVec > h0;
//  CoolHandle< CoolSharedVector<int> > h0;
  TEST ("Handle h0", ptr(h0), NULL);            // empty handle

  CoolSharedVector<int>* v0 = new CoolSharedVector<int>();
  TEST ("Type* ptr", v0->reference_count(), 0); // count initially 0

  CoolHandle<CoolSharedVector<int> > h1(v0);            // construct from ptr
  TEST ("Handle h1(Type*)", h1->reference_count(), 1); 
  {
    CoolHandle<CoolSharedVector<int> > h2(*v0); // construct from obj
    TEST ("Handle h2(Type&)", v0->reference_count(), 2);
    {
      CoolHandle<CoolSharedVector<int> > h3(h1);        // copy constructor
      TEST ("Handle h3(Handle&)", v0->reference_count(), 3);
    }
    TEST ("~Handle", v0->reference_count(), 2);
  }
  TEST ("~Handle", v0->reference_count(), 1);
}
void main(){

	// handle
	Handle h;
	
	assert(!h.isFinished());
	//assert(h.getReply<int>() == NULL);

	// task
	MyTaskScheduler scheduler(5);

	Handle h1;

	h1 = scheduler.RunAsynTask(MyDouble, 10, NULL, "MyDouble");

	Handle h2 = scheduler.RunAsynTask(MyTriple, 10, &h1,	"MyTriple");

	Handle h4 = scheduler.RunAsynTask(MyTriple, 20, NULL, "MyTriple2");

	assert(60==*h4.getReply<int>());

	int *pRpy2 = h2.getReply<int>();
	
	assert(*pRpy2 == 30);
	
	assert(h1.isFinished());
	int *pRpy1 = h1.getReply<int>();
	assert(*pRpy1 == 20);

	Handle h3(h2);
	assert(*h3.getReply<int>() == 30);


	//int a;
	//assert(typeid(int*) == typeid((void*)&a));
}
Beispiel #23
0
void jecplots(){

  gROOT->SetStyle("Plain");
   
  gStyle->SetPalette(1);
  gStyle->SetOptStat(1111111);  // Show overflow, underflow + SumOfWeights 
  gStyle->SetOptFit(111110); 
  gStyle->SetOptFile(1); 
  
  gStyle->SetMarkerStyle(20);
  gStyle->SetMarkerSize(.3);
  gStyle->SetMarkerColor(1);

  TCanvas* c0 = new TCanvas("c0"," ",200,10,500,500);
  c0->Clear();

  TFile g("/tmp/delre/vbf.root");
  TFile g1("/tmp/delre/vbf1.root");
  TFile g2("/tmp/delre/vbf2.root");
  TFile g3("/tmp/delre/vbf3.root");
  TFile g4("/tmp/delre/vbf4.root");
  TFile h("/tmp/delre/vh.root");
  TFile h1("/tmp/delre/vh1.root");
  TFile h2("/tmp/delre/vh2.root");
  TFile h3("/tmp/delre/vh3.root");
  TFile h4("/tmp/delre/vh4.root");

  g.cd();
  JECresovbf->SetTitle("");
  JECresovbf->SetStats(0);
  JECresovbf->SetXTitle("(p_{T}^{meas}-p_{T}^{gen}))/p_{T}^{gen}");
  JECresovbf->Draw();
  g1.cd();
  JECresovbf->SetLineColor(kRed);
  JECresovbf->Draw("same");
  g2.cd();
  JECresovbf->SetLineColor(kBlue);
  JECresovbf->Draw("same");
  
  c0->SaveAs("JECsyst_vbf.png");
  
  h.cd();
  JECresovh->SetTitle("");
  JECresovh->SetStats(0);
  JECresovh->SetXTitle("(p_{T}^{meas}-p_{T}^{gen}))/p_{T}^{gen}");
  JECresovh->Draw();
  h1.cd();
  JECresovh->SetLineColor(kRed);
  JECresovh->Draw("same");
  h2.cd();
  JECresovh->SetLineColor(kBlue);
  JECresovh->Draw("same");
  
  c0->SaveAs("JECsyst_vh.png");
   
  g4.cd();
  JECresovbf->SetLineColor(kRed);
  JECresovbf->SetTitle("");
  JECresovbf->SetStats(0);
  JECresovbf->SetXTitle("(p_{T}^{meas}-p_{T}^{gen}))/p_{T}^{gen}");
  JECresovbf->Draw();
  g.cd();
  JECresovbf->Draw("same");
  g3.cd();
  JECresovbf->SetLineColor(kBlue);
  JECresovbf->Draw("same");
  
  c0->SaveAs("JERsyst_vbf.png");
  
  h4.cd();
  JECresovh->SetTitle("");
  JECresovh->SetLineColor(kRed);
  JECresovh->SetStats(0);
  JECresovh->SetXTitle("(p_{T}^{meas}-p_{T}^{gen}))/p_{T}^{gen}");
  JECresovh->Draw();
  h.cd();
  JECresovh->Draw("same");
  h3.cd();
  JECresovh->SetLineColor(kBlue);
  JECresovh->Draw("same");
  
  c0->SaveAs("JERsyst_vh.png");
   

}
Beispiel #24
0
void test01()
{
    {
        String on1;
        on1 = "//atp:77/root/cimv25:"
              "TennisPlayer.last=\"Rafter\",first=\"Patrick\"";

        String on2;
        on2 = "//atp:77/root/cimv25:"
              "TennisPlayer.first=\"Patrick\",last=\"Rafter\"";

        CIMObjectPath r = on1;
        PEGASUS_TEST_ASSERT(r.toString() != on1);
        PEGASUS_TEST_ASSERT(r.toString() == on2);

        CIMObjectPath r2 = r;
        CIMObjectPath r3 = CIMObjectPath
            ("//atp:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");

        if (verbose)
        {
            XmlWriter::printValueReferenceElement(r, false);
            cout << r.toString() << endl;
        }

        Buffer mofOut;
        MofWriter::appendValueReferenceElement(mofOut, r);
        r.clear();
    }

    {
        CIMObjectPath r1 = CIMObjectPath
            ("MyClass.z=true,y=1234,x=\"Hello World\"");
        CIMObjectPath r2 = CIMObjectPath
            ("myclass.X=\"Hello World\",Z=true,Y=1234");
        CIMObjectPath r3 = CIMObjectPath ("myclass.X=\"Hello\",Z=true,Y=1234");
        // cout << r1.toString() << endl;
        // cout << r2.toString() << endl;
        PEGASUS_TEST_ASSERT(r1 == r2);
        PEGASUS_TEST_ASSERT(r1 != r3);
    }

    // Test case independence and order independence of parameters.
    {
        CIMObjectPath r1 = CIMObjectPath ("X.a=123,b=true");
        CIMObjectPath r2 = CIMObjectPath ("x.B=TRUE,A=123");
        PEGASUS_TEST_ASSERT(r1 == r2);
        PEGASUS_TEST_ASSERT(r1.makeHashCode() == r2.makeHashCode());

        CIMObjectPath r3 = CIMObjectPath ("x.B=TRUE,A=123,c=FALSE");
        PEGASUS_TEST_ASSERT(r1 != r3);
        String keyValue;

        Array<CIMKeyBinding> kbArray;
        {
            Boolean found = false;
            kbArray = r3.getKeyBindings();
            for (Uint32 i = 0; i < kbArray.size(); i++)
            {
                if (verbose)
                {
                    cout << "keyName= " <<  kbArray[i].getName().getString()
                         << " Value= " << kbArray[i].getValue() << endl;
                }
                if ( kbArray[i].getName() == CIMName ("B") )
                {
                    keyValue = kbArray[i].getValue();
                    if(keyValue == "TRUE")
                    found = true;
                }
            }
            if(!found)
            {
                cerr << "Key Binding Test error " << endl;
                exit(1);
            }
            //ATTN: KS 12 May 2002 P3 DEFER - keybinding manipulation. too
            // simplistic.
            // This code demonstrates that it is not easy to manipulate and
            // test keybindings.  Needs better tool both in CIMObjectPath and
            // separate.
        }
    }


    // Test building from component parts of CIM Reference.
    {
        CIMObjectPath r1 ("atp:77", CIMNamespaceName ("root/cimv25"),
            CIMName ("TennisPlayer"));
        CIMObjectPath r2 ("//atp:77/root/cimv25:TennisPlayer.");
        //cout << "r1 " << r1.toString() << endl;
        //cout << "r2 " << r2.toString() << endl;

        PEGASUS_TEST_ASSERT(r1 == r2);
        PEGASUS_TEST_ASSERT(r1.toString() == r2.toString());

    }


    {
        String hostName = "atp:77";
        String nameSpace = "root/cimv2";
        String className = "tennisplayer";

        CIMObjectPath r1;
        r1.setHost(hostName);
        r1.setNameSpace(nameSpace);
        r1.setClassName(className);
        PEGASUS_TEST_ASSERT(r1.getClassName().equal(CIMName ("TENNISPLAYER")));
        PEGASUS_TEST_ASSERT(!r1.getClassName().equal(CIMName ("blob")));


        String newHostName = r1.getHost();
        //cout << "HostName = " << newHostName << endl;

        CIMObjectPath r2 (hostName, nameSpace, className);
        PEGASUS_TEST_ASSERT(r1 == r2);
    }

    // Test cases for the Hostname.  CIMObjectPaths allows the
    // host to include the domain. Eg. xyz.company.com

    // First, try a good hostname
    CIMObjectPath h0("//usoPen-9.ustA-1-a.org:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h1("//usoPen-9:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h2("//usoPen-9/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h3("//usoPen-9.ustA-1-a.org:0/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h4("//usoPen-9.ustA-1-a.org:9876/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h5("//usoPen-9.ustA-1-a.org:65535/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h6("//usopen-9.usta-1-a.1org:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h7("//192.168.1.com:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h8("//192.168.0.org/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h9("//192.168.1.80.com:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h10("//192.168.0.80.org/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h11("//192.168.1.80.255.com:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h12("//192.168.0.80.254.org/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h13("//192.168.257.80.com:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h14("//192.256.0.80.org/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    CIMObjectPath h15("//localhost/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h16("//ou812/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h17("//u812/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    // Hostname with '_' character support checks, see bug#2556.
    CIMObjectPath h18("//_atp:9999/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h19("//a_tp/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h20("//atp_:9999/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h21("//atp_-9:9999/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h22(
        "//_a_t_p_-9.ustA-1-a.org:9999/_root/_cimv25:_TennisPlayer");
    CIMObjectPath h23("//_/root/cimv25:_TennisPlayer");
    CIMObjectPath h24("//_______/root/cimv25:_TennisPlayer");

    // try IPAddress as hostname which should be good
    CIMObjectPath h_ip0("//192.168.1.80:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    CIMObjectPath h_ip1("//192.168.0.255/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    // Try IPv6 Addresses.
    CIMObjectPath ip6_1("//[::1]:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    CIMObjectPath ip6_2("//[::ffff:192.1.2.3]:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    CIMObjectPath ip6_3("//[fffe:233:321:234d:e45:fad4:78:12]:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");

    CIMObjectPath ip6_4("//[fffe::]:77/root/cimv25:"
        "TennisPlayer.first=\"Chris\",last=\"Evert\"");


    Boolean errorDetected = false;

    // Invalid IPV6 Addresses
    try
    { // IPv6 addresses must be enclosed in brackets
        CIMObjectPath ip6_mb("//fffe::12ef:127/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    { // IPv6 address invalid
        CIMObjectPath ip6_invalid("//[fffe::sd:77]/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
       //Port number out of range.
       CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:9876543210/root/cimv25:"
           "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
       //Port number out of range.
       CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:65536/root/cimv25:"
           "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
       //Port number out of range.
       CIMObjectPath h_Port("//usoPen-9.ustA-1-a.org:100000/root/cimv25:"
           "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
       errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        //more than three digits in an octect
        CIMObjectPath h_ErrIp0("//192.1600008.1.80:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Octet out of range
        CIMObjectPath op("//192.168.256.80:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Missing port is okay, needs be ignored
        CIMObjectPath op("//192.168.1.80:/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(!errorDetected);

    errorDetected = false;
    try
    {
        // Too many octets
        CIMObjectPath op("//192.168.1.80.12/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Too few octets
        CIMObjectPath op("//192.168.80:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Missing port is okay, needs be ignored
        CIMObjectPath op("//usopen-9.usta-1-a.org:/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(!errorDetected);

    errorDetected = false;
    try
    {
        // Hostname (IP) without trailing '/' (with port)
        CIMObjectPath op("//192.168.256.80:77");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Hostname (IP) without trailing '/' (without port)
        CIMObjectPath op("//192.168.256.80");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Hostname without trailing '/' (with port)
        CIMObjectPath op("//usopen-9.usta-1-a.org:77");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Hostname without trailing '/' (without port)
        CIMObjectPath op("//usopen-9.usta-1-a.org");
    }
    catch (const Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Invalid first character
        CIMObjectPath op("//+usopen-9.usta-1-a.1org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Non-alphanum char (?)
        CIMObjectPath op("//usopen-9.usta?-1-a.org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Leading dot
        CIMObjectPath op("//.usopen-9.usta-1-a.org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Dot in the wrong spot (before a -)
        CIMObjectPath op("//usopen.-9.usta-1-a.org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Two dots in a row
        CIMObjectPath op("//usopen-9.usta-1-a..org:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);

    errorDetected = false;
    try
    {
        // Trailing dot
        CIMObjectPath op("//usopen-9.usta-1-a.org.:77/root/cimv25:"
            "TennisPlayer.first=\"Chris\",last=\"Evert\"");
    }
    catch (Exception&)
    {
        errorDetected = true;
    }
    PEGASUS_TEST_ASSERT(errorDetected);
}
Beispiel #25
0
void p_dist_look(Int_t mode=0) {
  gROOT->SetStyle("Plain");

  TFile f("p_dists.root");
  gROOT->cd();
  TGraph *sm=(TGraph*)f.Get("sm")->Clone();
  TGraph *mf=(TGraph*)f.Get("mf")->Clone();
  TGraph *corr=(TGraph*)f.Get("corr")->Clone();
  TGraph *tot=(TGraph*)f.Get("tot")->Clone();
  f.Close();

  TFile g("../ref/polish/O16/graph.root");
  gROOT->cd();
  TGraph *as_mf=(TGraph*)g.Get("polish_n_mf")->Clone();
  TGraph *as_corr=(TGraph*)g.Get("polish_n_corr")->Clone();
  f.Close();

  if (mode==1) {
    tot->DrawClone("ap");
    sm->DrawClone("psame");
    mf->DrawClone("psame");
    corr->DrawClone("psame");
    gPad->SetLogy();
  }

  if (mode==2) {
    mf->DrawClone("ap");
    corr->DrawClone("psame");
    as_mf->SetMarkerColor(kRed);
    as_mf->DrawClone("psame");
    as_corr->SetMarkerColor(kBlue);
    as_corr->DrawClone("psame");
    gPad->SetLogy();
    
  }

  if (mode==3) {
    Int_t n_points=tot->GetN();
    Int_t n_bins=n_points;

    Double_t p_max,y;
    tot->GetPoint(n_points-1,p_max,y);

    TH1D h1("h1","",n_bins,0.0,p_max);
    TH1D h2("h2","",n_bins,0.0,p_max);
    TH1D h3("h3","",n_bins,0.0,p_max);
    TH1D h4("h4","",n_bins,0.0,p_max);

    for (Int_t iBin=1;iBin<=n_bins;iBin++) {
      Double_t value1=sm->Eval(h1.GetBinCenter(iBin));
      value1*=4.0*TMath::Pi()*pow(h1.GetBinCenter(iBin),2);
      h1.SetBinContent(iBin,value1);

      Double_t value2=mf->Eval(h2.GetBinCenter(iBin));
      value2*=4.0*TMath::Pi()*pow(h2.GetBinCenter(iBin),2);
      h2.SetBinContent(iBin,value2);

      Double_t value3=tot->Eval(h3.GetBinCenter(iBin));
      value3*=4.0*TMath::Pi()*pow(h3.GetBinCenter(iBin),2);
      h3.SetBinContent(iBin,value3);

      Double_t value4=corr->Eval(h4.GetBinCenter(iBin));
      value4*=4.0*TMath::Pi()*pow(h4.GetBinCenter(iBin),2);
      h4.SetBinContent(iBin,value4);
    }

    h1.SetStats(kFALSE);
    h1.SetTitle(";p (GeV);N_{target nucleons}/GeV");
    h2.SetLineColor(kRed);
    h3.SetLineColor(kBlue);
    h4.SetLineColor(kGreen);

    h1.DrawCopy();
    h2.DrawCopy("same");
    h4.DrawCopy("same");
    h3.DrawCopy("same");

    TLegend legend(0.45,0.6,0.9,0.9,"^{16}O");
    legend.SetBorderSize(0);
    legend.SetFillStyle(0);
    legend.AddEntry(&h1,"Smith-Moniz","l");
    legend.AddEntry(&h2,"Ciofi degli Atti-Simula mean field (MF)","l");
    legend.AddEntry(&h4,"Ciofi degli Atti-Simula correlated (corr)","l");
    legend.AddEntry(&h3,"Ciofi degli Atti-Simula total","l");
    legend.DrawClone("same");

    gPad->SetLogy(0);
    cout << "h1.int: " << h1.Integral("width") << endl;
    cout << "h2.int: " << h2.Integral("width") << endl;
    cout << "h3.int: " << h3.Integral("width") << endl;
    cout << "h4.int: " << h4.Integral("width") << endl;
  }
  
  delete sm;
  delete mf;
  delete corr;
  delete tot;
}
Beispiel #26
0
MarkdownEdit::MarkdownEdit(LiteApi::IApplication *app, LiteApi::IEditor *editor, QObject *parent) :
    QObject(parent), m_liteApp(app)
{
    m_editor = LiteApi::getTextEditor(editor);
    if (!m_editor) {
        return;
    }
    m_ed = LiteApi::getPlainTextEdit(editor);
    if (!m_ed) {
        return;
    }
    m_ed->setLineWrapMode(QPlainTextEdit::WidgetWidth);

    LiteApi::IActionContext *actionContext = m_liteApp->actionManager()->getActionContext(this,"Markdown");

    QAction *h1 = new QAction(QIcon("icon:markdown/images/h1.png"),tr("Header (h1)"),this);
    actionContext->regAction(h1,"Header1","Ctrl+1");

    QAction *h2 = new QAction(QIcon("icon:markdown/images/h2.png"),tr("Header (h2)"),this);
    actionContext->regAction(h2,"Header2","Ctrl+2");

    QAction *h3 = new QAction(QIcon("icon:markdown/images/h3.png"),tr("Header (h3)"),this);
    actionContext->regAction(h3,"Header3","Ctrl+3");

    QAction *h4 = new QAction(QIcon("icon:markdown/images/h4.png"),tr("Header (h4)"),this);
    actionContext->regAction(h4,"Header4","Ctrl+4");

    QAction *h5 = new QAction(QIcon("icon:markdown/images/h5.png"),tr("Header (h5)"),this);
    actionContext->regAction(h5,"Header5","Ctrl+5");

    QAction *h6 = new QAction(QIcon("icon:markdown/images/h6.png"),tr("Header (h6)"),this);
    actionContext->regAction(h6,"Header6","Ctrl+6");

    QAction *bold = new QAction(QIcon("icon:markdown/images/bold.png"),tr("Bold"),this);
    actionContext->regAction(bold,"Bold",QKeySequence::Bold);

    QAction *italic = new QAction(QIcon("icon:markdown/images/italic.png"),tr("Italic"),this);
    actionContext->regAction(italic,"Italic",QKeySequence::Italic);

    QAction *code = new QAction(QIcon("icon:markdown/images/code.png"),tr("Inline Code"),this);
    actionContext->regAction(code,"InlineCode","Ctrl+K");

    QAction *link = new QAction(QIcon("icon:markdown/images/link.png"),tr("Link"),this);
    actionContext->regAction(link,"Link","Ctrl+Shift+L");

    QAction *image = new QAction(QIcon("icon:markdown/images/image.png"),tr("Image"),this);
    actionContext->regAction(image,"Image","Ctrl+Shift+I");

    QAction *ul = new QAction(QIcon("icon:markdown/images/ul.png"),tr("Unordered List"),this);
    actionContext->regAction(ul,"UnorderedList","Ctrl+Shift+U");

    QAction *ol = new QAction(QIcon("icon:markdown/images/ol.png"),tr("Ordered List"),this);
    actionContext->regAction(ol,"OrderedList","Ctrl+Shift+O");

    QAction *bq = new QAction(QIcon("icon:markdown/images/quote.png"),tr("Blockquote"),this);
    actionContext->regAction(bq,"Blockquote","Ctrl+Shift+Q");

    QAction *hr = new QAction(QIcon("icon:markdown/images/hr.png"),tr("Horizontal Rule"),this);
    actionContext->regAction(hr,"HorizontalRule","Ctrl+Shift+H");

    QToolBar *toolBar = LiteApi::findExtensionObject<QToolBar*>(editor,"LiteApi.QToolBar");

    QMenu *menu = LiteApi::getEditMenu(editor);
    if (menu) {
        menu->addSeparator();
        QMenu *h = menu->addMenu(tr("Heading"));
        h->addAction(h1);
        h->addAction(h2);
        h->addAction(h3);
        h->addAction(h4);
        h->addAction(h5);
        h->addAction(h6);
        menu->addSeparator();
        menu->addAction(link);
        menu->addAction(image);
        menu->addSeparator();
        menu->addAction(bold);
        menu->addAction(italic);
        menu->addAction(code);
        menu->addSeparator();
        menu->addAction(ul);
        menu->addAction(ol);
        menu->addSeparator();
        menu->addAction(bq);
        menu->addAction(hr);
    }
    menu = LiteApi::getContextMenu(editor);
    if (menu) {
        menu->addSeparator();
        menu->addAction(link);
        menu->addAction(image);
        menu->addSeparator();
        menu->addAction(bold);
        menu->addAction(italic);
        menu->addAction(code);
        menu->addSeparator();
        menu->addAction(ul);
        menu->addAction(ol);
        menu->addSeparator();
        menu->addAction(bq);
        menu->addAction(hr);
    }

    if (toolBar) {
        toolBar->addSeparator();
        toolBar->addAction(h1);
        toolBar->addAction(h2);
        toolBar->addAction(h3);
        toolBar->addSeparator();
        toolBar->addAction(link);
        toolBar->addAction(image);
        toolBar->addSeparator();
        toolBar->addAction(bold);
        toolBar->addAction(italic);
        toolBar->addAction(code);
        toolBar->addSeparator();
        toolBar->addAction(ul);
        toolBar->addAction(ol);
        toolBar->addSeparator();
        toolBar->addAction(bq);
        toolBar->addAction(hr);
        //updateToolTip(toolBar);
    }

    connect(editor,SIGNAL(destroyed()),this,SLOT(deleteLater()));
    connect(h1,SIGNAL(triggered()),this,SLOT(h1()));
    connect(h2,SIGNAL(triggered()),this,SLOT(h2()));
    connect(h3,SIGNAL(triggered()),this,SLOT(h3()));
    connect(h4,SIGNAL(triggered()),this,SLOT(h4()));
    connect(h5,SIGNAL(triggered()),this,SLOT(h5()));
    connect(h6,SIGNAL(triggered()),this,SLOT(h6()));
    connect(bold,SIGNAL(triggered()),this,SLOT(bold()));
    connect(italic,SIGNAL(triggered()),this,SLOT(italic()));
    connect(code,SIGNAL(triggered()),this,SLOT(code()));
    connect(link,SIGNAL(triggered()),this,SLOT(link()));
    connect(image,SIGNAL(triggered()),this,SLOT(image()));
    connect(ul,SIGNAL(triggered()),this,SLOT(ul()));
    connect(ol,SIGNAL(triggered()),this,SLOT(ol()));
    connect(bq,SIGNAL(triggered()),this,SLOT(bq()));
    connect(hr,SIGNAL(triggered()),this,SLOT(hr()));

    //m_ed->installEventFilter(this);
}
Beispiel #27
0
/* --std=c90 -Wv */
void f1(void) { int i; struct tag { int x; } x; int *p; i(); x(); p(); }
void f2(void) { void h2(int, double); void g2(); h2(0, 1); g2(0, 1); }    /* prototype vs. non-prototype */
void f3(void) { struct tag { int x; } h3(void), x; int g3(void), y; x = h3(); y = g3(); }    /* struct vs. non-struct */
Beispiel #28
0
//------------------------------------------------------------------------------
StatusCode THistWrite::execute()
//------------------------------------------------------------------------------
{
  MsgStream log( msgSvc(), name() );

  Rndm::Numbers gauss(randSvc(),       Rndm::Gauss(0.,15.));

  static int n = 0;

  double x = sin(double(n)) * 52. + 50.;

  TH1 *h(0);
  TH2 *h2(0);
  if (m_ths->getHist("TempHist1",h).isSuccess()) {
    h->Fill(x);
  } else {
    log << MSG::ERROR << "Couldn't retrieve TempHist 1" << endmsg;
  }

  if (m_ths->getHist("other/TempHist1a",h).isSuccess()) {
    h->Fill(x);
  } else {
    log << MSG::ERROR << "Couldn't retrieve TempHist 1a" << endmsg;
  }


  if (m_ths->getHist("/new/Tree2",h).isSuccess()) {
    h->Fill(x);
  } else {
    log << MSG::ERROR << "Couldn't retrieve Tree2" << endmsg;
  }

  if (m_ths->getHist("/upd/xxx/gauss1d",h).isSuccess()) {
    for (int i=0; i<1000; ++i) {
      h->Fill(gauss(),1.);
    }
  } else {
    log << MSG::ERROR << "Couldn't retrieve 1Dgauss" << endmsg;
  }

  if (m_ths->getHist("/rec/gauss2d",h2).isSuccess()) {
    for (int i=0; i<1000; ++i) {
      h2->Fill(gauss(),gauss(),1.);
    }
  } else {
    log << MSG::ERROR << "Couldn't retrieve 2Dgauss" << endmsg;
  }

  TH3 *h3(0);
  if (m_ths->getHist("/rec/gauss3d",h3).isSuccess()) {
    for (int i=0; i<1000; ++i) {
      h3->Fill(gauss(),gauss(),gauss(),1.);
    }
  } else {
    log << MSG::ERROR << "Couldn't retrieve 3Dgauss" << endmsg;
  }

  TTree *tr;
  if (m_ths->getTree("/rec/trees/stuff/tree1",tr).isFailure()) {
    log << MSG::ERROR << "Couldn't retrieve tree tree1" << endmsg;
  } else {
    if (n == 0) {
      int p1,p2,p3;
      tr->Branch("branch1",&p1,"point1/I");
      tr->Branch("branch2",&p2,"point2/I");
      tr->Branch("branch3",&p3,"point3/I");

      for (int i=0; i<1000; i++) {
	p1 = i;
	p2 = i%10;
	p3 = i%7;

	tr->Fill();
      }
    }
  }


  n++;
  return StatusCode::SUCCESS;
}
Beispiel #29
0
void roo_fitWH()
{
  TString poscharge = "Plus";
  TString negcharge = "Minus";

  std::vector<TString> charge(2);
  charge.at(0) = poscharge;
  charge.at(1) = negcharge;

  TString canvas_name_plus = "muon_MC_WHelicityFramePlots_PlusICVar";
  TCanvas *c0 = new TCanvas(canvas_name_plus,"",450,400);
  TString canvas_name_minus = "muon_MC_WHelicityFramePlots_MinusICVar";
  TCanvas *c1 = new TCanvas(canvas_name_minus,"",450,400);
 
  // Run both for + and - charges
  for(unsigned int j=0; j<charge.size(); j++) {
   
    //  if (j==1) break; // do only + charge fit
    if (realData) { sfactor=36; }

      // Nominal values are taken from a fit to the MC W data (scaled to 100pb-1)
    RooRealVar *fLnom, *fRnom, *f0nom;
    if (j==0) { 
      fLnom=new RooRealVar("fL_nom","fLnom",0.556);
      fRnom=new RooRealVar("fR_nom","fRnom",0.234);
      f0nom=new RooRealVar("f0_nom","f0nom",0.210);
    } else {
      fLnom=new RooRealVar("fL_nom","fLnom",0.523);
      fRnom=new RooRealVar("fR_nom","fRnom",0.265);
      f0nom=new RooRealVar("f0_nom","f0nom",0.212);
    }

    TString Hist1 = "RECO_PolPlots_50toinf/RECO_ICVarPF"+ charge.at(j) + "_LH";
    TString Hist2 = "RECO_PolPlots_50toinf/RECO_ICVarPF"+ charge.at(j) + "_RH";
    TString Hist3 = "RECO_PolPlots_50toinf/RECO_ICVarPF"+ charge.at(j) + "_LO";
    TString Hist_data1 = "RECO_PolPlots_50toinf/RECO_ICVarPF"+ charge.at(j);
    
    TH1D *mc1 = (TH1D*)sigfile->Get(Hist1);
    TH1D *mc2 = (TH1D*)sigfile->Get(Hist2);
    TH1D *mc3 = (TH1D*)sigfile->Get(Hist3);
    
    TH1D *sighist = (TH1D*)sigfile->Get(Hist_data1); // W signal histogram
    TH1D *bkghist=(TH1D*)bkgfile->Get(Hist_data1); // Bkg histogram
    TH1D *hdata=(TH1D*)datafile->Get(Hist_data1); // Real data histogram

    // //we are only fitting for fL and fR
    // double accFactor1 = refTempHist1->Integral() / mc1->Integral();
    // double accFactor2 = refTempHist2->Integral() / mc2->Integral();
    // double accFactor3 = refTempHist3->Integral() / mc3->Integral();
    // double normFactor = (mc1->Integral() + mc2->Integral() + mc3->Integral()) / (refTempHist1->Integral() + refTempHist2->Integral() + refTempHist3->Integral());
    
    mc1->Rebin(rbin); mc2->Rebin(rbin); mc3->Rebin(rbin);
    sighist->Rebin(rbin); bkghist->Rebin(rbin); hdata->Rebin(rbin);

      // Scale to sfactor/pb if MC
    //if (!realData) {
    if (toyMC) sfactor=400;
    sighist->Scale(sfactor); bkghist->Scale(sfactor);
      // }
      //datahist->Scale(invWeightW);//to get MC errors - otherwise comment out

    Double_t nbkg=0;

    TH1D *datahist;
    if (realData) { datahist=hdata;
    } else {
      datahist=(TH1D*)sighist->Clone();
      if (addbkg) {datahist->Add(bkghist); }
    }
    if (addbkg) { 
      //nbkg=bkghist->Integral();
      nbkg=bkghist->Integral(bkghist->FindBin(xmin+quanta),bkghist->FindBin(xmax-quanta));
    }

    //Double_t istat=datahist->Integral();
    //Double_t f_sig=(sighist->Integral())/istat; // signal fraction
    Double_t istat=datahist->Integral(datahist->FindBin(xmin+quanta),datahist->FindBin(xmax-quanta));
    Double_t f_sig=(sighist->Integral(sighist->FindBin(xmin+quanta),sighist->FindBin(xmax-quanta)))/istat;
    Double_t f_bkg=nbkg/istat; // bkg fraction


      // Start RooFit session
    RooRealVar x("x","LP",xmin,xmax);
      // Import binned Data
    RooDataHist data1("data1","dataset with WHICVarPlus",x,mc1);
    RooDataHist data2("data2","dataset with WHICVarPlus",x,mc2);
    RooDataHist data3("data3","dataset with WHICVarPlus",x,mc3);
  
    RooDataHist test("data","dataset with WHICVarPlus",x,datahist);
    RooDataHist data_bkg("data4","dataset with ICVar",x,bkghist);

    // Relative fractions - allow them to float to negative values too if needs be
    //   if (fitMode==0) {
    RooRealVar f1("fL","fL fraction",fLnom->getVal(),0.,1.);
    RooRealVar f2("fR","fR fraction", fRnom->getVal(),0.,1.);
    RooFormulaVar f3("f0","1-fL-fR",RooArgList(f1,f2));
    if (fitMode) {
      f1.setVal((fLnom->getVal()-fRnom->getVal())); f1.setRange(-1.,1.); 
      f1.setPlotLabel("f_{L}-f_{R}"); 
      f2.setVal(f0nom->getVal()); 
      f2.setPlotLabel("f_{0}");
    } 
    // } else {
    //   RooRealVar f1("fL","fL fraction",(fLnom->getVal()-fRnom->getVal()),-1.,1.);
    //   RooRealVar f2("fR","fR fraction", (fLnom->getVal()+fRnom->getVal()),-1.,1.);
    //   RooFormulaVar f3("f0","1-fL-fR",RooArgList(f1,f2));
    // }
    RooRealVar fsub("fsub","fsub par",(fLnom->getVal()-fRnom->getVal()),-1.,1.);
    RooRealVar fsum("fsum","fsum par",(fLnom->getVal()+fRnom->getVal()), -1.,1.);
    
    // Background template
    RooHistPdf *bkg = new RooHistPdf("bkg","bkg",x,data_bkg);
    // Bkg fraction
    RooRealVar fbkg("f_{bkg}","f_bkg fraction",f_bkg);

      // Templates 
    RooHistPdf h1("h1","h1",x,data1); // left-handed template histogram
    RooHistPdf h2("h2","h2",x,data2); // right-handed template histo
    RooHistPdf h3("h3","h3",x,data3); // longitudinal template histo

      // Construct model PDF
    RooAbsPdf *sig, *model;

    if (charge.at(j) == "Plus") { // plus charge PDFs
      if (addParameter) { sig = new RooWPlusExtended("sigmodel","model",x,f1,f2,fsub);
      } else { sig = new RooWPlus("sigmodel","model",x,f1,f2); } 
    } else if (charge.at(j) == "Minus") { // minus charge PDFs
      if (addParameter) { sig = new RooWMinusExtended("sigmodel","model",x,f1,f2,fsub);
      } else { sig = new RooWMinus("sigmodel","model",x,f1,f2); } 
    }
    
    if (addbkg) {
      model = new RooAddPdf("model","model",RooArgList(*bkg,*sig),fbkg);
    } else { model = sig; }
    
    // Set the Fit Range
    x.setRange("fitrange",-0.0,1.3);
    // Construct likelihood ( + penalty term)
    RooNLLVar nll("nll","nll",*model,test,Range("fitrange"));
    RooRealVar pen("pen","penalty term",(0.5*1./(0.01*0.01)));
    RooFormulaVar nllPen("nllPen","nll+pen*fsub^2",RooArgList(nll,pen,fsub));
    
      // Fitting
    RooMinuit *m;
    if (!addParameter) { m = new RooMinuit(nll); }
    else {  m = new RooMinuit(nllPen);}

    if (!toyMC) {
      m->migrad(); m->hesse();
    }
    RooFitResult *res1 = m->save();
    
    // Re-diced data 
    // Int_t nevt=static_cast<int>(istat);
    // RooDataSet *gtest = model->generate(x,nevt);
    
    // Fitting
    //   RooFitResult * res1 = model.fitTo(test,Minos(kFALSE), Save());
    //       res1->Print();
   
    if(makePlots) {
   



      // Temp PDF for plotting purposes
      // RooAddPdf temp("temp","component 1",RooArgList(*h1,*h2,*h3),RooArgList(*f1,*f2)) ;
      // Plotting
      gROOT->SetStyle("Plain");  
      gStyle->SetOptFit(0);
      gStyle->SetOptTitle(0);
      gStyle->SetOptStat(0);      //gStyle->SetCanvasDefH(600); //Height of canvas
      //gStyle->SetCanvasDefW(600); //Width of canvas   
      if(charge.at(j) == "Plus") { c0->cd();
	//c0->Divide(2,1);c0->cd(1);
      }
      if(charge.at(j) == "Minus") { c1->cd();
	//c1->Divide(2,1);c1->cd(1);
      }
      //RooPlot* frame = new RooPlot(0.0,1.3,0,800);
      RooPlot* frame = x.frame();


      test.plotOn(frame,Name("data")); 
      model->plotOn(frame,Name("model")); 
      // model->paramOn(frame);//, Format("NELU", AutoPrecision(2)), Layout(0.1,0.5,0.9));
        
      //  h1.plotOn(frame);
      //     h2.plotOn(frame);
      //    h3.plotOn(frame);

       //  model->plotOn(frame, Components(h1),LineColor(kRed),LineStyle(kDashed));
       //     temp->plotOn(frame, Components(h2),LineColor(kGreen),LineStyle(kDashed));
      //  temp->plotOn(frame, Components(h3),LineColor(kYellow),LineStyle(kDashed));
      if (addbkg) {
	//  model->plotOn(frame, Components(h1),FillColor(5),DrawOption("F"));
     	//model->plotOn(frame,Components(*bkg),FillColor(5),DrawOption(""));
      } 

   
  hdata->GetYaxis()->SetTitle("Events / 0.1");
  if(charge.at(j) == "Plus") {  hdata->GetXaxis()->SetTitle("#it{L_{P}}(#mu^{+})");}
  if(charge.at(j) == "Minus") {hdata->GetXaxis()->SetTitle("#it{L_{P}}(#mu^{-})");}
      hdata->GetXaxis()->SetTitleSize(0.06);
      hdata->GetXaxis()->SetTitleOffset(1.);
      hdata->GetYaxis()->SetTitleSize(0.06);
      hdata->GetYaxis()->SetTitleOffset(1.2);
      hdata->GetXaxis()->SetLabelSize(0.055);
      hdata->GetYaxis()->SetLabelSize(0.055);
      hdata->GetXaxis()->SetRangeUser(0.0,1.29);
      hdata->GetYaxis()->SetRangeUser(0.0,600);
      hdata->SetMarkerStyle(20);

      //  mc1->Draw("same");
      // Goodness-of-fit
      Double_t chi2= frame->chiSquare("model","data",3);
      Double_t nllmin=res1->minNll();
      cout << "" << endl;
      cout << "Printing out the goodness-of-fit measure:" << endl;
      cout << "chi2 = " << chi2 << "\t" << "min NLL = " << nllmin << endl;
      res1->Print();

      //   TCanvas* testt  = new TCanvas ("testt","hj");
      cout <<"intetral: "<<   hdata->Integral()<<endl;
      hdata->GetXaxis()->SetRangeUser(0.0,1.29);
      cout <<   hdata->Integral()<<endl;
      
      hdata->Draw("");
      //  frame->Draw("same");
      mc1->GetXaxis()->SetRangeUser(0.0,1.29);
      float f_l_a =  mc1->Integral();
      mc2->GetXaxis()->SetRangeUser(0.0,1.29);
      float f_r_a =  mc2->Integral();
      mc3->GetXaxis()->SetRangeUser(0.0,1.29);
      float f_0_a =  mc3->Integral();

      float allData =  hdata->Integral();
      float EWKBkg = allData*(f_bkg);
      float WData = allData*(1-f_bkg);

      float f_l = 0.5*(1-f2.getVal()+f1.getVal());
      float f_r = 0.5*(1-f2.getVal()-f1.getVal());
      float f_0 = f2.getVal();
      cout << "f_l: "<< f_l<< ",f_r: "<< f_r<< ", f_0: "<< f_0<< " 1= "<< f_l+f_r+f_0<< endl;
      float allW = f_l*f_l_a+f_r*f_r_a+f_0*f_0_a;

      //hdata->Draw("");
      //    bkghist->GetXaxis()->SetRangeUser(0.0,1.3);
      bkghist->Scale(EWKBkg/bkghist->Integral());
      bkghist->Draw("samehist");
      bkghist->SetLineColor(kYellow);
      bkghist->SetFillColor(kYellow);

      mc1->Scale(f_l*WData/allW);
      mc2->Scale(f_r*WData/allW);
      mc3->Scale(f_0*WData/allW);
      mc1->SetLineColor(kRed);
      mc2->SetLineColor(kGreen);
      mc3->SetLineColor(kBlue);
      mc1->SetLineWidth(3);
      mc2->SetLineWidth(3);
      mc3->SetLineWidth(3);
      mc1->SetLineStyle(2);
      mc2->SetLineStyle(3);
      mc3->SetLineStyle(4);
      mc1->Draw("samehist");
      mc2->Draw("samehist");
      mc3->Draw("samehist");

      TH1D* allHists = (TH1D*)mc1->Clone();
      allHists->Add(mc2,1);
      allHists->Add(mc3,1);
      allHists->Add(bkghist,1);
      allHists->SetLineWidth(3);
      //   frame->SetOptFit(0);

        frame->Draw("same");
      //   allHists->Draw("same");
	TLegend* aleg;
	//if(charge.at(j) == "Minus") aleg = new TLegend(0.2,0.69,0.6,0.9,"");
	//  if(charge.at(j) == "Plus") 
	//aleg =  new TLegend(0.5,0.6,0.7,0.9,"");//new TLegend(0.8,0.69,0.95,0.9,"");
      aleg = new TLegend(0.2017937,0.7419355,0.4775785,0.9193548,NULL,"brNDC");
      aleg->SetNColumns(2);
      aleg->SetFillColor(0);
      aleg->SetLineColor(0);
      aleg->AddEntry(mc1,"f_{L}","lf");
      aleg->AddEntry(mc2,"f_{R}","lf");
      aleg->AddEntry(mc3,"f_{0}","lf");
      aleg->AddEntry(bkghist,"EWK","lf");
      TH1* dummyhist = new TH1F("", "", 1, 0, 1);
      dummyhist->SetLineColor(kBlue);
      dummyhist->SetLineWidth(3);
      aleg->AddEntry(dummyhist, "fit result", "lf");
      aleg->AddEntry(hdata, "data","P");

      aleg->Draw("same");

      //TLatex* preliminary; 

      //TLatex* text;
      //if(false) {
	//text = new TLatex(0.35,480,"#splitline{f_{L}-f_{R}=0.240#pm0.036(stat.)#pm0.031(syst.)}{f_{0}=0.183#pm0.087(stat.)#pm0.123(syst.)}");
	//preliminary = new TLatex(0.35,550,"CMS preliminary: #it{L} = 36pb^{-1}@ 7 TeV");
      //}

      //if(true){
	//text = new TLatex(0.05,480,"#splitline{f_{L}-f_{R}=0.310#pm0.036(stat.)#pm0.017(syst.)}{f_{0}=0.171#pm0.085(stat.)#pm0.099(syst.)}");
	//preliminary = new TLatex(0.05,550,"#splitline{CMS, #sqrt{s} = 7 TeV,}{#it{L_{int}} = 36 pb^{-1}}");}
      //preliminary->SetTextSize(0.043);
      //preliminary->Draw("same");
      
      //text->SetTextSize(0.043);
      //  text->Draw("same");
      /*
	// Draw Minuit contours
      if(charge.at(j) == "Plus") { c0->cd(2);
      } else { c1->cd(2); }

	// RooPlot *rcont=m->contour(f1,f2,1,2);
	// rcont->Draw();
      RooPlot *rcontour=new RooPlot(f1,f2);
      res1->plotOn(rcontour,f1,f2,"ME123VHB");
      rcontour->Draw();
      if (fitMode) {
	rcontour->GetXaxis()->SetTitle("f_{L}-f_{R}");
	rcontour->GetYaxis()->SetTitle("f_{0}");
      } else {
	rcontour->GetXaxis()->SetTitle("f_{L}");
	rcontour->GetYaxis()->SetTitle("f_{R}");
      }
      */

    }

    TLatex * text = new TLatex(0.7451931,500.8655,"#splitline{CMS,  #sqrt{s} = 7 TeV}{L_{ int} = 36 pb^{-1}}");
    text->SetTextSize(0.043);
    text->SetLineWidth(2);
    text->Draw("same");

     
    const TMatrixDSym& cor = res1->correlationMatrix();
    const TMatrixDSym& cov = res1->covarianceMatrix();
    
    //Print correlation, covariance matrix
    cout << "correlation matrix" << endl; cor.Print();
    cout << "covariance matrix" << endl; cov.Print();
  
    cout << f1 << endl; cout << f2 << endl;
    if (!fitMode) {
      cout << "f0 = " << f3 << " +/- " << f3.getPropagatedError(*res1) << endl;
    }
  }
     
  if(makePlots) {
    c0->Print(canvas_name_plus+".pdf");
    c1->Print(canvas_name_minus+".pdf");
  }

  if (toyMC) {

    // MC STudies
  Int_t nevt=istat;
  Int_t nEXP=100;

  RooMCStudy mgr(*model,*model,x,"","mhrv");
  mgr.generateAndFit(nEXP,nevt,kTRUE);
  
  TCanvas *cp0 = new TCanvas("c0","",1200,400);
  cp0->Divide(3,1);
  cp0->cd(1);
  RooPlot *p1=mgr.plotParam(f1); p1->Draw(); 
  if (fitMode) p1->SetTitle(";f_{L}-f_{R};number of toys");
  cp0->cd(2);
  RooPlot *p2 = mgr.plotError(f1); p2->Draw();
  if (fitMode) p2->SetTitle(";#delta (f_{L}-f_{R});number of toys");
  cp0->cd(3);
  // f1 pull
  RooPlot* m1pframe = mgr.plotPull(f1,-3.,3.,30,kTRUE);
  m1pframe->Draw();
  if (fitMode) {
    m1pframe->SetTitle(";f_{L}-f_{R};number of toys");
  }

  TCanvas *cp02 = new TCanvas("c1","",1200,400);
  cp02->Divide(3,1);
  cp02->cd(1);
  RooPlot *p3=mgr.plotParam(f2); p3->Draw();
  if (fitMode) p3->SetTitle(";f_{0};number of toys");
  cp02->cd(2);
  RooPlot *p4=mgr.plotError(f2); p4->Draw();
  if (fitMode) p4->SetTitle(";#delta f_{0}; number of toys");
  cp02->cd(3);
  // f2 pull
  RooPlot* m2pframe = mgr.plotPull(f2,-3.,3.,30,kTRUE);
  m2pframe->Draw();
  if (fitMode) {
    m2pframe->SetTitle(";f_{0};number of toys");
  }

  TCanvas *cnll = new TCanvas("cnll","");
  RooPlot* nllframe = mgr.plotNLL();
  // nllframe->Draw();


  }

  return;
}
void
test8()
{
    printf("\ntesting n-ary array functions: g(), h() ...\n");
    int32_t n;

    printf("\ncreating A...\n");
    A * a = new A();
    const A * ac = a;

    h0();

    h1(1);

    h2(1, 2);

    h3(1, 2, 3);

    n = h0r();
    assert(n == 0);

    n = h1r(1);
    assert(n == 1);

    n = h2r(1, 2);
    assert(n == 3);

    n = h3r(1, 2, 3);
    assert(n == 6);

    ac->g0c();

    ac->g1c(1);

    ac->g2c(1, 2);

    ac->g3c(1, 2, 3);

    a->g0();

    a->g1(1);

    a->g2(1, 2);

    a->g3(1, 2, 3);

    n = ac->g0rc();
    assert(n == 0);

    n = ac->g1rc(1);
    assert(n == 1);

    n = ac->g2rc(1, 2);
    assert(n == 3);

    n = ac->g3rc(1, 2, 3);
    assert(n == 6);

    n = a->g0r();
    assert(n == 0);

    n = a->g1r(1);
    assert(n == 1);

    n = a->g2r(1, 2);
    assert(n == 3);

    n = a->g3r(1, 2, 3);
    assert(n == 6);

    printf("delete A...\n");
    delete a;
}