コード例 #1
0
ファイル: commonTools.C プロジェクト: TENorbert/usercode-2
// Creates a TLorentzVector from pt, eta, phi and mass
TLorentzVector convert(const double & pt, const double & eta, const double & phi, const double & mass)
{
  double px = pt*cos(phi);
  double py = pt*sin(phi);
  double tmp = 2*atan(exp(-eta));
  double pz = pt*cos(tmp)/sin(tmp);
  double E  = sqrt(px*px+py*py+pz*pz+mass*mass);

  return TLorentzVector(px,py,pz,E);
}
コード例 #2
0
ファイル: checkOpenHLT.C プロジェクト: Hosein47/usercode
TLorentzVector checkOpenHLT::fromPtEtaPhiToPxPyPz( const double & pt, const double & eta, const double & phi )
{
  double px = pt*cos(phi);
  double py = pt*sin(phi);
  double tmp = 2*atan(exp(-eta));
  double pz = pt*cos(tmp)/sin(tmp);
  double E = sqrt(px*px+py*py+pz*pz+muMass*muMass);

  return TLorentzVector(px,py,pz,E);
}
コード例 #3
0
SimParticle PFReconstructor::reconstructCluster(const Cluster& cluster, papas::Layer layer, double energy,
                                                const TVector3& vertex) {
  // construct a photon if it is an ecal
  // construct a neutral hadron if it is an hcal
  int pdgId = 0;
  if (energy < 0) {
    energy = cluster.energy();
  }
  // double charge = ParticlePData::particleCharge(pdgId);
  if (layer == papas::Layer::kEcal) {
    pdgId = 22;  // photon
  } else if (layer == papas::Layer::kHcal) {
    pdgId = 130;  // K0
  } else {
    // TODO raise ValueError('layer must be equal to ecal_in or hcal_in')
  }
  // assert(pdg_id)
  double mass = ParticlePData::particleMass(pdgId);

  if (energy < mass)  // null particle
    return SimParticle();

  double momentum;
  if (mass == 0) {
    momentum = energy;
  }  //#avoid sqrt for zero mass
  else {
    momentum = sqrt(pow(energy, 2) - pow(mass, 2));
  }
  TVector3 p3 = cluster.position().Unit() * momentum;
  TLorentzVector p4 = TLorentzVector(p3.Px(), p3.Py(), p3.Pz(), energy);  // mass is not accurate here

  IdType newid = Id::makeRecParticleId();
  SimParticle particle{newid, pdgId, 0., p4, vertex};
  // TODO discuss with Colin
  particle.path()->addPoint(papas::Position::kEcalIn, cluster.position());
  if (layer == papas::Layer::kHcal) {  // alice not sure
    particle.path()->addPoint(papas::Position::kHcalIn, cluster.position());
  }

  // alice: Colin this may be a bit strange
  // because we can make a photon with a
  // path where the point is actually that
  // of the hcal?
  // nb this only is problem if the cluster and the assigned layer are different
  // particle.setPath(path);
  // particle.clusters[layer] = cluster  # not sure about this either when hcal is used to make an ecal cluster?
  m_locked[cluster.id()] = true;  // alice : just OK but not nice if hcal used to make ecal.
  // TODO make more flexible and able to detect what type of cluster
  PDebug::write("Made Reconstructed{} from Merged{}", particle, cluster);
  return particle;
}
コード例 #4
0
SimParticle PFReconstructor::reconstructTrack(const Track& track) {
  // , Clusters = None): cluster argument does not ever seem to be used at present
  /*construct a charged hadron from the track
   */
  IdType newid = Id::makeRecParticleId();
  int pdgId = 211 * track.charge();
  TLorentzVector p4 = TLorentzVector();
  p4.SetVectM(track.p3(), ParticlePData::particleMass(pdgId));
  SimParticle particle{newid, pdgId, track.charge(), p4, track};

  m_locked[track.id()] = true;
  PDebug::write("Made Reconstructed{} from Smeared{}", particle, track);
  // std::cout << "made particle pdgid: " << particle.pdgId() << " from track: " << track;  // TODO << particle;
  return particle;
}
コード例 #5
0
ファイル: PhaseSpace.C プロジェクト: goi42/lhcb
void PhaseSpace( int d ) {
	int decay(d);

	gROOT->ProcessLine(".x ~/lhcb/lhcbStyle.C");
	if (!gROOT->GetClass("TGenPhaseSpace")) gSystem->Load("libPhysics");

	const double mBs(5.36677);
	const double mBd(5.2794);
	const double mLb(5.6195);
	const double mpi(0.13957);
	const double mK(0.493677);
	const double mp(0.938272);
	const double mJpsi(3.096916);
	const double mPsi(3.686093);

	TLorentzVector Lb;
	Double_t masses[3];
	double min(5.2);
	double max(5.5);
	string title1;
	string title2;

	switch (decay) {
		case 1:
			cout << "Simluated decay: Bs -> psi(2S) K K" << endl;
			Lb = TLorentzVector(0.0, 0.0, 0.0, mBs);
			masses[0] = mPsi; masses[1] = mK; masses[2] = mK;
			min = 5.2;
			max = 5.35;
			cout << "Reconstructed final state: psi(2S) K pi" << endl;
			cout << "Reconstructed final state: psi(2S) pi K" << endl;
			title1 = "m(#psi(2S)K(K#rightarrow#pi)) [GeV]";
			title2 = "m(#psi(2S)(K#rightarrow#pi)K) [GeV]";
			break;
		case 2:
			cout << "Simluated decay: Bd -> psi(2S) pi pi" << endl;
			Lb = TLorentzVector(0.0, 0.0, 0.0, mBd);
			masses[0] = mPsi; masses[1] = mpi; masses[2] = mpi;
			min = 5.2;
			max = 5.5;
			cout << "Reconstructed final state: psi(2S) pi K" << endl;
			cout << "Reconstructed final state: psi(2S) K pi" << endl;
			title1 = "m(#psi(2S)#pi(#pi#rightarrowK)) [GeV]";
			title2 = "m(#psi(2S)(#pi#rightarrowK)#pi) [GeV]";
			break;
		case 3:
			cout << "Simluated decay: Bs -> psi(2S) pi pi" << endl;
			Lb = TLorentzVector(0.0, 0.0, 0.0, mBs);
			masses[0] = mPsi; masses[1] = mpi; masses[2] = mpi;
			min = 5.4;
			max = 5.7;
			cout << "Reconstructed final state: psi(2S) pi K" << endl;
			cout << "Reconstructed final state: psi(2S) K pi" << endl;
			title1 = "m(#psi(2S)#pi(#pi#rightarrowK)) [GeV]";
			title2 = "m(#psi(2S)(#pi#rightarrowK)#pi) [GeV]";
			break;
		case 4:
			cout << "Simluated decay: Lb -> psi(2S) K p" << endl;
			Lb = TLorentzVector(0.0, 0.0, 0.0, mLb);
			masses[0] = mPsi; masses[1] = mK; masses[2] = mp;
			min = 4.9;
			max = 5.4;
			cout << "Reconstructed final state: psi(2S) K pi" << endl;
			cout << "Reconstructed final state: psi(2S) pi K" << endl;
			title1 = "m(#psi(2S)K(p#rightarrow#pi)) [GeV]";
			title2 = "m(#psi(2S)(K#rightarrow#pi)(p#rightarrowK) [GeV]";
			break;
		case 5:
			cout << "Simluated decay: Lb -> psi(2S) pi p" << endl;
			Lb = TLorentzVector(0.0, 0.0, 0.0, mLb);
			masses[0] = mPsi; masses[1] = mpi; masses[2] = mp;
			min = 5.2;
			max = 5.5;
			cout << "Reconstructed final state: psi(2S) pi K" << endl;
			cout << "Reconstructed final state: psi(2S) K pi" << endl;
			title1 = "m(#psi(2S)#pi(p#rightarrowK)) [GeV]";
			title2 = "m(#psi(2S)(#pi#rightarrowK)(p#rightarrow#pi) [GeV]";
			break;
		case 6:
			cout << "Simluated decay: Bs -> psi(2S) K pi" << endl;
			Lb = TLorentzVector(0.0, 0.0, 0.0, mBs);
			masses[0] = mPsi; masses[1] = mK; masses[2] = mpi;
			min = 5.5;
			max = 5.8;
			cout << "Reconstructed final state: psi(2S) K p" << endl;
			cout << "Reconstructed final state: psi(2S) p pi" << endl;
			title1 = "m(#psi(2S)K(#pi#rightarrowp)) [GeV]";
			title2 = "m(#psi(2S)(K#rightarrowp)#pi) [GeV]";
			break;
	}

	TGenPhaseSpace event;
	event.SetDecay(Lb, 3, masses);

	TH1F *h1 = new TH1F("h1","h1", 50, 5.2, 5.8);
	TH1F *h2 = new TH1F("h2","h2", 50, min, max);
	TH1F *h3 = new TH1F("h3","h3", 50, min, max);
	TH2F *h4 = new TH2F("h4","h4", 50, 4.5*4.5, 5.5*5.5, 50, 3.6*3.6, 5.7*5.7);
	h1->Sumw2();
	h2->Sumw2();
	h3->Sumw2();
	h4->Sumw2();

	for (Int_t n=0;n<10000;n++) {
		Double_t weight = event.Generate();

		TLorentzVector *pPsi = event.GetDecay(0);

		TLorentzVector *pHadron1 = event.GetDecay(1);
		TLorentzVector *pHadron2 = event.GetDecay(2);

		TLorentzVector pHadron1_as_kaon  (pHadron1->Px(), pHadron1->Py(), pHadron1->Pz(), sqrt(pHadron1->P()*pHadron1->P() + mK *mK)); 
		TLorentzVector pHadron1_as_pion  (pHadron1->Px(), pHadron1->Py(), pHadron1->Pz(), sqrt(pHadron1->P()*pHadron1->P() + mpi*mpi)); 
		TLorentzVector pHadron1_as_proton(pHadron1->Px(), pHadron1->Py(), pHadron1->Pz(), sqrt(pHadron1->P()*pHadron1->P() + mp *mp)); 
		TLorentzVector pHadron2_as_kaon  (pHadron2->Px(), pHadron2->Py(), pHadron2->Pz(), sqrt(pHadron2->P()*pHadron2->P() + mK *mK)); 
		TLorentzVector pHadron2_as_pion  (pHadron2->Px(), pHadron2->Py(), pHadron2->Pz(), sqrt(pHadron2->P()*pHadron2->P() + mpi*mpi)); 
		TLorentzVector pHadron2_as_proton(pHadron2->Px(), pHadron2->Py(), pHadron2->Pz(), sqrt(pHadron2->P()*pHadron2->P() + mp *mp)); 
		TLorentzVector pB        = *pPsi + *pHadron1         + *pHadron2;
		TLorentzVector pB_wrong1;
		TLorentzVector pB_wrong2;
		switch (decay) {
			case 1:
				pB_wrong1 = *pPsi + *pHadron1 + pHadron2_as_pion;
				pB_wrong2 = *pPsi +  pHadron1_as_pion + *pHadron2;
				break;
			case 2:
				pB_wrong1 = *pPsi + *pHadron1 + pHadron2_as_kaon;
				pB_wrong2 = *pPsi +  pHadron1_as_kaon + *pHadron2;
				break;
			case 3:
				pB_wrong1 = *pPsi + *pHadron1 + pHadron2_as_kaon;
				pB_wrong2 = *pPsi +  pHadron1_as_kaon + *pHadron2;
				break;
			case 4:
				pB_wrong1 = *pPsi + *pHadron1 + pHadron2_as_pion;
				pB_wrong2 = *pPsi +  pHadron1_as_pion + pHadron2_as_kaon;
				break;
			case 5:
				pB_wrong1 = *pPsi + *pHadron1 + pHadron2_as_kaon;
				pB_wrong2 = *pPsi +  pHadron1_as_kaon + pHadron2_as_pion;
				break;
			case 6:
				pB_wrong1 = *pPsi + *pHadron1 + pHadron2_as_proton;
				pB_wrong2 = *pPsi +  pHadron1_as_proton + *pHadron2;
				break;
		}
		TLorentzVector pPsiHadron1 = *pPsi + *pHadron1;
		TLorentzVector pPsiHadron2 = *pPsi + *pHadron2;

		h1->Fill(pB.M() ,weight);
		h2->Fill(pB_wrong1.M() ,weight);
		h3->Fill(pB_wrong2.M() ,weight);
		h4->Fill(pPsiHadron1.M2() ,pPsiHadron2.M2() ,weight);
	}
	TCanvas * c = new TCanvas();
	c->Divide(2,1);
	//c->cd(1);
	//h1->Draw();
	//h1->GetXaxis()->SetTitle("m(#psi(2S)p#pi) [GeV]");
	//h1->GetXaxis()->SetTitle("m(#psi(2S)pK) [GeV]");
	c->cd(1);
	h2->Draw();
	h2->GetXaxis()->SetTitle(title1.c_str());
	c->cd(2);
	h3->Draw();
	h3->GetXaxis()->SetTitle(title2.c_str());
	//c->cd(4);
	//h4->Draw();
	char buf[20];
	sprintf(buf, "plot%d.pdf", decay);
	c->SaveAs(buf);
}
コード例 #6
0
ファイル: test.C プロジェクト: GaelTouquet/analysis-cpp
{
  gSystem.Load("libanalysiscpp-tools");
  JetClusterizer jc;
  jc.add_p4(TLorentzVector(10,0,0,10));
  jc.add_p4(TLorentzVector(20,0,0,20));
  jc.add_p4(TLorentzVector(0,40,0,40));
  jc.clusterize();
  std::cout<<"njets "<<jc.n_jets()<<std::endl;
  TLorentzVector jet = jc.jet(0);
  std::cout<<"jet E "<<jet.E()<<std::endl;
  gApplication.Terminate();
}
コード例 #7
0
ファイル: RhoToolsTest.C プロジェクト: freekang/rhoframework
void Sputnik::Launch()
{
    cout << "starting RhoToolsTest" << endl;
    
    // the tests are organized as blocks to let variables
    // go out of scope.  In the output, each block is 
    // separated by a lines of ----
    
    
    // start testing OpAdd4
    
    ostream& theStream = cerr; 
    theStream  <<  "Before Testing OpAdd4 " << endl;
    theStream << endl;
    
    
    TOpAdd4 b4;
    {
	cout << "create a pair of objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),0);
	TCandidate c2(TLorentzVector(0,2,0,0),0);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	
	cout << "after OpAdd4.Fill(c3, c1, c2); "<<endl;
	b4.Fill(c3,c1,c2);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	
	TCandidate c4(TLorentzVector(0,0,3,0),0);
	cout <<endl<< "c4(); c4 = OpAdd4().combine( c1, c2); "<<endl;
	c4 = TOpAdd4().Combine(c1,c2);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout << "---------------------------------------------------"<<endl;
    }
    
    {
	cout << "create objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),0);
	TCandidate c2(TLorentzVector(0,2,0,0),0);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	TCandidate c4(TLorentzVector(0,0,0,4),0);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout <<endl<< "OpAdd4.Fill(c4,c1,c2,c3); "<<endl;
	b4.Fill(c4,c3,c2,c1);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	
	cout << "---------------------------------------------------"<<endl;
    }
    
    {
	cout << "create objects:" << endl;
	TCandidate c1(TLorentzVector(1,0,0,0),1);
	TCandidate c2(TLorentzVector(0,2,0,0),-1);
	TCandidate c3(TLorentzVector(0,0,3,0),0);
	TCandidate c4(TLorentzVector(0,0,0,4),0);
	TCandidate c5(TLorentzVector(0,0,0,0),5);
	TCandidate c6(TLorentzVector(0,0,0,0),6);
	TCandidate c7(TLorentzVector(0,0,0,0),7);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	cout <<endl<< "after Add4::Fill(c5,c1,c2); Add4::Fill(c6,c3,c4); "<<endl;
	b4.Fill(c5,c1,c2);
	b4.Fill(c6,c3,c4);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	cout <<endl<< "after Add4::Fill(c7,c5,c6); "<<endl;
	b4.Fill(c7,c5,c6);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	
	// do some additional checks of copying, etc
	cout <<endl<< "after c8(c7);"<<endl;
	TCandidate c8(c7);
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	
	cout <<endl<< "create c9(c1); then c9 = c7;"<<endl;
	TCandidate c9(c1); c9 = c7;
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	PC("c9",c9);
	
	cout <<endl<< "c9 = c5;"<<endl;
	c9 = c5;
	PC("c1",c1);
	PC("c2",c2);
	PC("c3",c3);
	PC("c4",c4);
	PC("c5",c5);
	PC("c6",c6);
	PC("c7",c7);
	PC("c8",c8);
	PC("c9",c9);
	
	cout << endl;
	cout << "testing Overlaps:"<<endl;
	cout << "c1 and c2: "<<(c1.Overlaps(c2)?"t":"f")<<endl;
	cout << "c9 and c5: "<<(c9.Overlaps(c5)?"t":"f")<<endl;
	cout << "c8 and c5: "<<(c8.Overlaps(c5)?"t":"f")<<endl;
	cout << "c7 and c5: "<<(c7.Overlaps(c5)?"t":"f")<<endl;
	cout << "c6 and c5: "<<(c6.Overlaps(c5)?"t":"f")<<endl;
	cout << "c5 and c5: "<<(c5.Overlaps(c5)?"t":"f")<<endl;
	cout << "c5 and c9: "<<(c5.Overlaps(c9)?"t":"f")<<endl;
	cout << "c5 and c8: "<<(c5.Overlaps(c8)?"t":"f")<<endl;
	cout << "c5 and c7: "<<(c5.Overlaps(c7)?"t":"f")<<endl;
	cout << "c5 and c6: "<<(c5.Overlaps(c6)?"t":"f")<<endl;
	cout << "c5 and c5: "<<(c5.Overlaps(c5)?"t":"f")<<endl;
	cout << "---------------------------------------------------"<<endl;
    }
    
    //
    // start testing OpMakeTree
    
    theStream  <<  "Before Making Tree " << endl;
    theStream << endl;
    
    {
	
	cout << "Initialization of Pdt " << endl;
	//Pdt::readMCppTable("PARENT/PDT/pdt.table");
	TDatabasePDG *Pdt = TRho::Instance()->GetPDG();
	cout << "done." << endl;
	
	// now let's consider the Y(4S)
	double beamAngle  = 0.0204;
	double beamDeltaP = 9.-3.1; 
	
	TVector3 pY4S( -beamDeltaP*sin(beamAngle),0, 
	    beamDeltaP*cos(beamAngle) );
	TCandidate Y4S( pY4S, Pdt->GetParticle("Upsilon(4S)") );
	TTreeNavigator::PrintTree( Y4S );
	cout << "theta " << Y4S.P3().Theta() << endl;
	cout << "phi "   << Y4S.P3().Phi() << endl;
	
	// instanciate a Booster
	TBooster cmsBooster( &Y4S , kTRUE);
	
	// Let's imagine a photon with a certain angle in the CMS frame
	
	// a photon 
	double ePhot = 1.;
	double photAngle = 30*3.1416/180.;
	double photPhi   = 45*3.1416/180.;
	TCandidate 
	    photon( TVector3( ePhot*sin(photAngle)*cos(photPhi), ePhot*sin(photAngle)*sin(photPhi), ePhot*cos(photAngle) ), 
	    Pdt->GetParticle("gamma") );
	
	cout << endl << "The original photon in the CMS frame " << endl;
	TTreeNavigator::PrintTree( photon );
	cout << "theta " << photon.P3().Theta() << endl;
	cout << "phi "   << photon.P3().Phi() << endl;
	
	// the same photon in the LAB frame :
	TCandidate boostedPhoton = cmsBooster.BoostFrom( photon );
	TLorentzVector theLabP4 = cmsBooster.BoostedP4( photon, TBooster::From );
	cout << "the lab Four-Vector (" << 
	    theLabP4.X() << "," << theLabP4.Y() << "," << theLabP4.Z() << ";" << theLabP4.E() << ")" << endl;
	cout << endl << "The lab boosted photon " << endl;
	TTreeNavigator::PrintTree( boostedPhoton );
	cout << "theta " << boostedPhoton.P3().Theta() << endl;
	cout << "phi "   << boostedPhoton.P3().Phi() << endl;
	
	// now boost back in the CMS frame
	TLorentzVector theP4 = cmsBooster.BoostedP4( boostedPhoton, TBooster::To );
	cout << "the Four-Vector in CMS frame (" << 
	    theP4.X() << "," << theP4.Y() << "," << theP4.Z() << ";" << theP4.E() << ")" << endl;
	cout << " from cand :    (" << 
	    photon.P4().X() << "," << photon.P4().Y() << "," << photon.P4().Z() << ";" <<photon.P4().E() << ")" << endl;
	
	
	double mPsi = Pdt->GetParticle("J/psi")->Mass();
	double mMu  = Pdt->GetParticle("mu+")->Mass();
	double mPi  = Pdt->GetParticle("pi+")->Mass();
	double mK   = Pdt->GetParticle("K+")->Mass();
	double mB   = Pdt->GetParticle("B+")->Mass();
	double mDst = Pdt->GetParticle("D*+")->Mass();
	double mD0  = Pdt->GetParticle("D0")->Mass();
	double mRho = Pdt->GetParticle("rho+")->Mass();
	
	//
	// Let's start with a simple example   :  B+ -> J/Psi K+
	//
	
	// muons in the J/Psi frame
	double E(0.), P(0.), th(0.), ph(0.);
	TVector3 p3;
	
	th = 0.3;
	ph = 1.3;
	P  = 0.5*sqrt( pow(mPsi,2) - 4*pow(mMu,2) );
	E  = sqrt( pow(mMu,2) + pow(P,2) );
	p3 = TVector3( sin(th)*cos(ph)*P, sin(th)*sin(ph)*P, cos(th)*P );
	
	TLorentzVector mu1P4(  p3, E );
	TLorentzVector mu2P4( -p3, E );
	
	// J/psi in the B frame
	th = 1.1;
	ph = 0.5;
	P = 0.5*sqrt((pow(mB,2)-pow(mPsi-mK,2))*(pow(mB,2)-pow(mPsi+mK,2)))/mB;
	p3 = TVector3( sin(th)*cos(ph)*P, sin(th)*sin(ph)*P, cos(th)*P );
	E = sqrt( pow(mPsi,2) + pow(P,2) ); 
	TVector3 boostVector( p3.X()/E, p3.Y()/E,p3.Z()/E );
	mu1P4.Boost( boostVector );
	mu2P4.Boost( boostVector );
	E = sqrt( pow(mK,2) + pow(P,2) ); 
	TLorentzVector KP4( -p3, E );
	
	// create the TCandidates
	TCandidate* mu1 = new TCandidate( mu1P4.Vect(), Pdt->GetParticle("mu+") );
	TCandidate* mu2 = new TCandidate( mu2P4.Vect(), Pdt->GetParticle("mu-") );
	TCandidate* K   = new TCandidate( KP4.Vect(), Pdt->GetParticle("K+") );
	
	// now create the Make Tree operator
	TOpMakeTree op;
	
	// now create the J/Psi
	TCandidate psi = op.Combine( *mu1, *mu2 );
	psi.SetType( "J/psi" );
	psi.SetMassConstraint();
	
	cout << endl << "The original psi " << endl;
	TTreeNavigator::PrintTree( psi );
	
	// now create the B+
	TCandidate B = op.Combine( psi, *K );
	B.SetType( "B+" );
	B.SetMassConstraint();
	
	cout << endl << "The B " << endl;
	TTreeNavigator::PrintTree( B );
	
	// create a TTreeNavigator
	TTreeNavigator treeNavigator( B );
	TTreeNavigator::PrintTree( psi );
	
	theStream << "After tree making" << endl;
	theStream << endl;
	
	//instanciate the fitter with the B Candidate
	VAbsFitter* fitter = new TDummyFitter( psi );
	
	theStream << "After fitter construction " << endl;
	theStream << endl;
	
	// get the "fitted" TCandidates
	TCandidate fittedPsi = fitter->GetFitted( psi );
	TTreeNavigator::PrintTree( fittedPsi );
	
	TCandListIterator iterDau =  psi.DaughterIterator();
	TCandidate* dau=0;
	while( dau=iterDau.Next() )
	{
	    TCandidate fittedDau = fitter->GetFitted( *dau );
	    TTreeNavigator::PrintTree( fittedDau );
	}
	
	delete fitter;
	
	fitter = new TDummyFitter( B );
	
	// get the "fitted" TCandidates
	TCandidate fittedB = fitter->GetFitted( B );
	TTreeNavigator::PrintTree( fittedB );
	
	iterDau.Rewind();
	dau=0;
	while( dau=iterDau.Next() )
	{
	    TCandidate fittedDau = fitter->GetFitted( *dau );
	    TTreeNavigator::PrintTree( fittedDau );
	}
	
	TCandidate hello = fitter->GetFitted( psi );
	TTreeNavigator::PrintTree( hello );
	
	delete fitter;
	
	theStream << "After fitter deletion " << endl;
	theStream << endl;
	
	// first let's boost the kaon
	TCandidate boostedKaon = cmsBooster.BoostTo( *K );
	cout << endl << "The boosted Kaon " << endl;
	TTreeNavigator::PrintTree( *K );
	
	// let's boost the psi
	TCandidate boostedPsi = cmsBooster.BoostTo( psi );
	cout << endl << "The boosted Psi " << endl;
	TTreeNavigator::PrintTree( boostedPsi );
	
	
	theStream << "before tree boosting " << endl;
	theStream << endl;
	
	// now let's boost the B in the Y4S frame
	TCandidate boostedB = cmsBooster.BoostTo( B );
	
	// let's see the tree
	cout << endl << "The boosted B " << endl;
	TTreeNavigator::PrintTree( boostedB );
	
	theStream << "after tree boosting " << endl;
	theStream << endl;
	
	// now let's boost a list
	TCandList theList;
	theList.Add( psi );
	theList.Add( *K );
	theList.Add( B );
	TCandList theBoostedList;
	cmsBooster.BoostTo( theList, theBoostedList );
	TCandListIterator iter(theBoostedList);
	TCandidate* c(0);
	while( c=iter.Next() )
	{
	    cout << "boosted cand " << c->PdtEntry()->GetName() << endl;
	    TTreeNavigator::PrintTree( *c );
	}
	
	
	theBoostedList.Cleanup();
	
	PrintAncestors( *mu1 );
	
	delete mu1;
	delete mu2;
	delete K;
	
	cout << "---------------------------------------------------"<<endl;
     }
     
     theStream  <<  "At the end of the test program " << endl;
     theStream << endl;
}
コード例 #8
0
ファイル: mainTest.C プロジェクト: lmdodd/HHKinFit
int main(int argc, char* argv[])
{
  TFile* f = new TFile("example/ntuple.root","READ");
  TTree* t = (TTree*) f->Get("EleTauKinFit");
  
  TH1F* h_chi2  = new TH1F("h_chi2", "distribution of #chi^{2}_{fit};#chi^{2}_{fit};entries/1", 100,0,25);
  TH1F* h_prob  = new TH1F("h_prob", "distribution of fit probability;P_{fit};entries/0.05", 100,0,1);
  TH1F* h_pull1 = new TH1F("h_pull1","pull distribution E_{b1};pull;entries/0.25", 20,-5,5);
  TH1F* h_pull2 = new TH1F("h_pull2","pull distribution E_{b2};pull;entries/0.25", 20,-5,5);
  
  Int_t event_start = 0;//t->GetEntriesFast();
  Int_t max_nevent = 100;//t->GetEntriesFast();

  //Leaf types  
   Int_t           njets;
   Double_t        b1_dR;
   Double_t        b1_csv;
   Double_t        b1_px;
   Double_t        b1_py;
   Double_t        b1_pz;
   Double_t        b1_E;
   Double_t        b2_dR;
   Double_t        b2_csv;
   Double_t        b2_px;
   Double_t        b2_py;
   Double_t        b2_pz;
   Double_t        b2_E;
   Double_t        tauvis1_dR;
   Double_t        tauvis1_px;
   Double_t        tauvis1_py;
   Double_t        tauvis1_pz;
   Double_t        tauvis1_E;
   Double_t        tauvis2_dR;
   Double_t        tauvis2_px;
   Double_t        tauvis2_py;
   Double_t        tauvis2_pz;
   Double_t        tauvis2_E;
   Double_t        met_pt;
   Double_t        met_px;
   Double_t        met_py;
   Double_t        met_cov00;
   Double_t        met_cov10;
   Double_t        met_cov01;
   Double_t        met_cov11;


  // List of branches
   TBranch        *b_njets;
   TBranch        *b_b1_dR;
   TBranch        *b_b1_csv;
   TBranch        *b_b1_px;
   TBranch        *b_b1_py;
   TBranch        *b_b1_pz;
   TBranch        *b_b1_E;
   TBranch        *b_b2_dR;
   TBranch        *b_b2_csv;
   TBranch        *b_b2_px;
   TBranch        *b_b2_py;
   TBranch        *b_b2_pz;
   TBranch        *b_b2_E;
   TBranch        *b_tauvis1_dR;
   TBranch        *b_tauvis1_px;
   TBranch        *b_tauvis1_py;
   TBranch        *b_tauvis1_pz;
   TBranch        *b_tauvis1_E;
   TBranch        *b_tauvis2_dR;
   TBranch        *b_tauvis2_px;
   TBranch        *b_tauvis2_py;
   TBranch        *b_tauvis2_pz;
   TBranch        *b_tauvis2_E;
   TBranch        *b_met_pt;
   TBranch        *b_met_px;
   TBranch        *b_met_py;
   TBranch        *b_met_cov00;
   TBranch        *b_met_cov10;
   TBranch        *b_met_cov01;
   TBranch        *b_met_cov11;
     
   t->SetBranchAddress("Njets", &njets, &b_njets);
   t->SetBranchAddress("b1_dR", &b1_dR, &b_b1_dR);
   t->SetBranchAddress("b1_csv", &b1_csv, &b_b1_csv);
   t->SetBranchAddress("b1_px", &b1_px, &b_b1_px);
   t->SetBranchAddress("b1_py", &b1_py, &b_b1_py);
   t->SetBranchAddress("b1_pz", &b1_pz, &b_b1_pz);
   t->SetBranchAddress("b1_E", &b1_E, &b_b1_E);
   t->SetBranchAddress("b2_dR", &b2_dR, &b_b2_dR);
   t->SetBranchAddress("b2_csv", &b2_csv, &b_b2_csv);
   t->SetBranchAddress("b2_px", &b2_px, &b_b2_px);
   t->SetBranchAddress("b2_py", &b2_py, &b_b2_py);
   t->SetBranchAddress("b2_pz", &b2_pz, &b_b2_pz);
   t->SetBranchAddress("b2_E", &b2_E, &b_b2_E);
   t->SetBranchAddress("tauvis1_dR", &tauvis1_dR, &b_tauvis1_dR);
   t->SetBranchAddress("tauvis1_px", &tauvis1_px, &b_tauvis1_px);
   t->SetBranchAddress("tauvis1_py", &tauvis1_py, &b_tauvis1_py);
   t->SetBranchAddress("tauvis1_pz", &tauvis1_pz, &b_tauvis1_pz);
   t->SetBranchAddress("tauvis1_E", &tauvis1_E, &b_tauvis1_E);
   t->SetBranchAddress("tauvis2_dR", &tauvis2_dR, &b_tauvis2_dR);
   t->SetBranchAddress("tauvis2_px", &tauvis2_px, &b_tauvis2_px);
   t->SetBranchAddress("tauvis2_py", &tauvis2_py, &b_tauvis2_py);
   t->SetBranchAddress("tauvis2_pz", &tauvis2_pz, &b_tauvis2_pz);
   t->SetBranchAddress("tauvis2_E", &tauvis2_E, &b_tauvis2_E);
   t->SetBranchAddress("met_pt", &met_pt, &b_met_pt);
   t->SetBranchAddress("met_px", &met_px, &b_met_px);
   t->SetBranchAddress("met_py", &met_py, &b_met_py);
   t->SetBranchAddress("met_cov00", &met_cov00, &b_met_cov00);
   t->SetBranchAddress("met_cov10", &met_cov10, &b_met_cov10);
   t->SetBranchAddress("met_cov01", &met_cov01, &b_met_cov01);
   t->SetBranchAddress("met_cov11", &met_cov11, &b_met_cov11);

  //define the testd hypotheses
  std::vector<Int_t> hypo_mh1;
  hypo_mh1.push_back(125);
  std::vector<Int_t> hypo_mh2;
  hypo_mh2.push_back(125);
  
  // event loop
  for (int i = event_start; i < max_nevent; i++) {
    t->GetEntry(i);
    
    //use only btaged jets and check for correct gen match
    if (b1_csv<0.681 || b2_csv<0.681 || njets < 2 || b1_dR > 0.2 || b2_dR > 0.2 || tauvis1_dR > 0.1 || tauvis2_dR > 0.1)   continue;
    
    //define input vectors
    TLorentzVector b1      = TLorentzVector(b1_px,b1_py,b1_pz,b1_E);
    TLorentzVector b2      = TLorentzVector(b2_px,b2_py,b2_pz,b2_E);
        
    //intance of fitter master class
    HHDiJetKinFitMaster kinFits = HHDiJetKinFitMaster(&b1,&b2,false);
    kinFits.addMhHypothesis(hypo_mh1);
    kinFits.doFullFit();

    //obtain results from different hypotheses
    Double_t chi2_best = kinFits.getBestChi2FullFit();
    std::pair<Int_t, Int_t> bestHypo = kinFits.getBestHypoFullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_chi2 = kinFits.getChi2FullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_fitprob = kinFits.getFitProbFullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_pull_b1 = kinFits.getPullB1FullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_pull_b2 = kinFits.getPullB2FullFit();
    std::map< std::pair<Int_t, Int_t>, Int_t> fit_convergence = kinFits.getConvergenceFullFit();

    std::cout << "#############################" << std::endl;
    std::cout << "EVENT" << i << std::endl;
    std::cout << "#############################" << std::endl;
    std::cout << "=====================================" << std::endl;
    std::cout << "njets:           " << njets << std::endl;
    std::cout << "event:           " << i << std::endl;
    std::cout << "best chi2:       " << chi2_best << std::endl;
    std::cout << "best hypothesis: " << bestHypo.first << " " << bestHypo.second << std::endl;
    std::cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << std::endl;

   //individual loop over results
    for (std::vector<Int_t>::iterator mh1 = hypo_mh1.begin(); mh1 != hypo_mh1.end(); mh1++){
      std::pair< Int_t, Int_t > hypo(*mh1,-1);
        
      //sanity cuts: use only converged fits and events with chi2<25 and make sure used cov was positive definit (this needs to be fixed!)
        
        std::cout << *mh1 << " " << "chi2_fit:    " << fit_results_chi2.at(hypo) << std::endl;
        std::cout << *mh1 << " " << "prob_fit:    " << fit_results_fitprob.at(hypo) << std::endl;
        std::cout << *mh1 << " " << "pull_b1:     " << fit_results_pull_b1.at(hypo) << std::endl;
        std::cout << *mh1 << " " << "pull_b2:     " << fit_results_pull_b2.at(hypo) << std::endl;
        std::cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << std::endl;

        h_chi2->Fill(fit_results_chi2.at(hypo));
        h_prob->Fill(fit_results_fitprob.at(hypo));
        h_pull1->Fill(fit_results_pull_b1.at(hypo));
        h_pull2->Fill(fit_results_pull_b2.at(hypo));
    }
    system(Form("mv out.root out/out%u.root",i));
    std::cout << "////////////////////////////////////////////////////////" << std::endl;
    std::cout << "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" << std::endl;
    std::cout << "////////////////////////////////////////////////////////" << std::endl;
    std::cout << "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" << std::endl;
    std::cout << "////////////////////////////////////////////////////////" << std::endl;
    std::cout << "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" << std::endl;
    std::cout << "////////////////////////////////////////////////////////" << std::endl;
  }
   

  TFile fout("result.root","RECREATE");
  h_chi2->Write();
  h_prob->Write();
  h_pull1->Write();
  h_pull2->Write();
  
  std::cout << max_nevent << std::endl;
  
  return (0);
}
コード例 #9
0
ファイル: NeroMet.cpp プロジェクト: blallen/NeroProducer
int NeroMet::analyze(const edm::Event& iEvent){

    if ( mOnlyMc  ) return 0; // in principle I would like to have the gen met: TODO

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);
    if ( not handle.isValid() ) cout<<"[NeroMet]::[analyze]::[ERROR] handle is not valid"<<endl;

    if (rerunPuppi) {
        iEvent.getByToken(token_puppiRerun,handle_puppiRerun);
        if ( not handle_puppiRerun.isValid() ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] handle_puppiRerun is not valid"<<endl;

        iEvent.getByToken(token_puppiRerunUncorr,handle_puppiRerunUncorr);
        if ( not handle_puppiRerunUncorr.isValid() ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] handle_puppiRerunUncorr is not valid"<<endl;
    } else {
        iEvent.getByToken(token_puppi,handle_puppi);
        if ( not handle_puppi.isValid() ) cout<<"[NeroMet]::[analyze]::[ERROR] handle_puppi is not valid"<<endl;
    }


    // -- iEvent.getByToken(token_puppiUncorr,handle_puppiUncorr);
    // -- if ( not handle_puppiUncorr.isValid() ) cout<<"[NeroMet]::[analyze]::[ERROR] handle_puppiUncorr is not valid"<<endl;
    //--

    const pat::MET &met = handle->front();

    caloMet_Pt = met.caloMETPt();
    caloMet_Phi = met.caloMETPhi();
    caloMet_SumEt = met.caloMETSumEt();


    // FILL
    new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector( met.px(),met.py(),met.pz(),met.energy()  );

    sumEtRaw = met.uncorSumEt();

    ptJESUP -> push_back( met.shiftedPt(pat::MET::JetEnUp) );
    ptJESDOWN -> push_back( met.shiftedPt(pat::MET::JetEnDown) );

    rawMet_Pt = met.uncorPt(); 
    rawMet_Phi = met.uncorPhi();


    if (IsExtend())
    {
        //MetNoMu
        TLorentzVector metnomu(met.px(),met.py(),met.pz(),met.energy());
        TLorentzVector tkMet(0,0,0,0); 
        TLorentzVector pfmet_3p0(0,0,0,0); 

        if ( pf == NULL ) cout<<"[NeroMet]::[analyze]::[ERROR] PF pointer is null. Run NeroPF. "<<endl; 

        for (unsigned int i = 0, n = pf->handle->size(); i < n; ++i) {
            const pat::PackedCandidate &cand = (*pf->handle)[i];

            // only up to eta 3
            if (std::abs(cand.pdgId()) == 13)
                metnomu += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());  

            // only charge hadrons
            if ( cand.charge() != 0 )
                tkMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());

            if (std::abs(cand.eta()) < 3.0 ) 
                pfmet_3p0 += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
        }
        

        *pfMet_e3p0 = TLorentzVector( -pfmet_3p0 );
        *metNoMu = TLorentzVector(metnomu);  // no minus
        *trackMet = TLorentzVector( -tkMet );

        if (rerunPuppi) {
            auto &puppi = handle_puppiRerun->front(); 
            *metPuppi =  TLorentzVector( puppi.px(), puppi.py(),puppi.pz(),puppi.energy() );
            sumEtRawPuppi = handle_puppiRerunUncorr->front().sumEt();
        } else {
            auto &puppi = handle_puppi->front(); 
            *metPuppi =  TLorentzVector( puppi.px(), puppi.py(),puppi.pz(),puppi.energy() );
            //sumEtRawPuppi = handle_puppiUncorr->front().sumEt();
            sumEtRawPuppi = puppi.uncorSumEt();
        }

        for(Syst mysyst = (Syst)0; mysyst < MaxSyst ; mysyst = (Syst)((int)mysyst +1 ) )
        {
            pat::MET::METUncertainty miniAODUnc=pat::MET::METUncertaintySize;
            // JetResUp=0, JetResDown=1, JetEnUp=2, JetEnDown=3,
            // MuonEnUp=4, MuonEnDown=5, ElectronEnUp=6, ElectronEnDown=7,
            // TauEnUp=8, TauEnDown=9, UnclusteredEnUp=10, UnclusteredEnDown=11,
            // PhotonEnUp=12, PhotonEnDown=13, NoShift=14, METUncertaintySize=15,
            // JetResUpSmear=16, JetResDownSmear=17, METFullUncertaintySize=18
            // translate
            switch (mysyst)
            {
                case  JesUp : {miniAODUnc = pat::MET::JetEnUp; break;}
                case  JesDown : {miniAODUnc = pat::MET::JetEnDown; break;}
                case  JerUp : {miniAODUnc = pat::MET::JetResUp; break;}
                case  JerDown : {miniAODUnc = pat::MET::JetResDown; break;}
                case  UnclusterUp : {miniAODUnc = pat::MET::UnclusteredEnUp; break;}
                case  UnclusterDown : {miniAODUnc = pat::MET::UnclusteredEnDown; break;}
                case  TauUp : {miniAODUnc = pat::MET::TauEnUp; break;}
                case  TauDown : {miniAODUnc = pat::MET::TauEnDown; break;}
                case  PhotonUp : {miniAODUnc = pat::MET::PhotonEnDown; break;}
                case  PhotonDown : {miniAODUnc = pat::MET::PhotonEnDown; break;}
                case  ElectronUp : {miniAODUnc = pat::MET::ElectronEnUp; break;}
                case  ElectronDown : {miniAODUnc = pat::MET::ElectronEnDown; break;}
                case  MuonUp : {miniAODUnc = pat::MET::MuonEnUp; break;}
                case  MuonDown : {miniAODUnc = pat::MET::MuonEnDown; break;}
                default : break;
            }

            if (miniAODUnc == pat::MET::METUncertaintySize)
                cout <<"[NeroMet]::[analyze]::[WARNING] unable to translate met syst,"<< int(mysyst) <<endl;

            /*
            new ( (*metPuppiSyst)[ mysyst ] ) TLorentzVector( 
                    puppi . shiftedP4( miniAODUnc).px(), 
                    puppi . shiftedP4(miniAODUnc).py(),  
                    puppi . shiftedP4(miniAODUnc).pz(),  
                    puppi . shiftedP4(miniAODUnc).energy()
                    );
            */

            new ( (*metSyst)[ mysyst ] ) TLorentzVector( 
                    met . shiftedP4( miniAODUnc).px(), 
                    met . shiftedP4(miniAODUnc).py(),  
                    met . shiftedP4(miniAODUnc).pz(),  
                    met . shiftedP4(miniAODUnc).energy()
                    );
        }// end syst loop
        

    }    
    // GEN INFO
    if ( not iEvent.isRealData () ){
        new ( (*genP4)[genP4->GetEntriesFast()]) TLorentzVector( met.genMET()->px(),met.genMET()->py(),met.genMET()->pz(),met.genMET()->energy()  );
    }


    return 0;
}
コード例 #10
0
ファイル: GrowTree.C プロジェクト: swang373/VHbbUF
////////////////////////////////////////////////////////////////////////////////
/// Main                                                                     ///
////////////////////////////////////////////////////////////////////////////////
void GrowTree(TString process, std::string regMethod="BDTG", Long64_t beginEntry=0, Long64_t endEntry=-1)
{
    gROOT->SetBatch(1);
    TH1::SetDefaultSumw2(1);
    gROOT->LoadMacro("HelperFunctions.h");  //< make functions visible to TTreeFormula

    if (!TString(gROOT->GetVersion()).Contains("5.34")) {
        std::cout << "INCORRECT ROOT VERSION! Please use 5.34:" << std::endl;
        std::cout << "source /uscmst1/prod/sw/cms/slc5_amd64_gcc462/lcg/root/5.34.02-cms/bin/thisroot.csh" << std::endl;
        std::cout << "Return without doing anything." << std::endl;
        return;
    }

    const TString indir   = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Phys14_PU20bx25/skimV11/";
    const TString outdir  = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Phys14_PU20bx25/skimV11/step3/";
    const TString prefix  = "skim_";
    const TString suffix  = ".root";

    TFile *input = TFile::Open(indir + prefix + process + suffix);
    if (!input) {
        std::cout << "ERROR: Could not open input file." << std::endl;
        exit(1);
    }
    /// Make output directory if it doesn't exist
    if (gSystem->AccessPathName(outdir))
        gSystem->mkdir(outdir);

    std::cout << "--- GrowTree                 : Using input file: " << input->GetName() << std::endl;
    TTree *inTree = (TTree *) input->Get("tree");
    TH1F  *hcount = (TH1F *) input->Get("Count");
    TFile *output(0);
    if (beginEntry == 0 && endEntry == -1)
        output = TFile::Open(outdir + "Step3_" + process + suffix, "RECREATE");
    else
        output = TFile::Open(outdir + "Step3_" + process + TString::Format("_%Li_%Li", beginEntry, endEntry) + suffix, "RECREATE");
    TTree *outTree = inTree->CloneTree(0); // Do no copy the data yet
    /// The clone should not delete any shared i/o buffers.
    ResetDeleteBranches(outTree);
    


    ///-- Set branch addresses -------------------------------------------------
    EventInfo EVENT;
    double hJet_pt[MAXJ], hJet_eta[MAXJ], hJet_phi[MAXJ], hJet_m[MAXJ], hJet_ptRaw[MAXJ], hJet_genPt[MAXJ];
    int hJCidx[2];

    inTree->SetBranchStatus("*", 1);

    inTree->SetBranchStatus("hJCidx",1);
    inTree->SetBranchStatus("Jet_*",1);
    inTree->SetBranchAddress("hJCidx", &hJCidx);
    inTree->SetBranchAddress("Jet_pt", &hJet_pt);

    inTree->SetBranchAddress("Jet_eta", &hJet_eta);
    inTree->SetBranchAddress("Jet_phi", &hJet_phi);
    inTree->SetBranchAddress("Jet_mass", &hJet_m);
    inTree->SetBranchAddress("Jet_rawPt", &hJet_ptRaw);

    inTree->SetBranchAddress("Jet_mcPt", &hJet_genPt);


    ///-- Make new branches ----------------------------------------------------
    int EVENT_run, EVENT_event;  // set these as TTree index?
    float lumi_ = lumi, efflumi, efflumi_old, 
        efflumi_UEPS_up, efflumi_UEPS_down;
    float hJet_ptReg[2];
    float HptNorm, HptGen, HptReg;
    float HmassNorm, HmassGen, HmassReg;

    outTree->Branch("EVENT_run", &EVENT_run, "EVENT_run/I");
    outTree->Branch("EVENT_event", &EVENT_event, "EVENT_event/I");
    outTree->Branch("lumi", &lumi_, "lumi/F");
    outTree->Branch("efflumi", &efflumi, "efflumi/F");
    outTree->Branch("efflumi_old", &efflumi_old, "efflumi_old/F");
    outTree->Branch("efflumi_UEPS_up", &efflumi_UEPS_up, "efflumi_UEPS_up/F");
    outTree->Branch("efflumi_UEPS_down", &efflumi_UEPS_down, "efflumi_UEPS_down/F");
    outTree->Branch("hJet_ptReg", &hJet_ptReg, "hJet_ptReg[2]/F");
    
    outTree->Branch("HptNorm", &HptNorm, "HptNorm/F");
    outTree->Branch("HptGen", &HptGen, "HptGen/F");
    outTree->Branch("HptReg", &HptReg, "HptReg/F");
    outTree->Branch("HmassNorm", &HmassNorm, "HmassNorm/F");
    outTree->Branch("HmassGen", &HmassGen, "HmassGen/F");
    outTree->Branch("HmassReg", &HmassReg, "HmassReg/F");

    /// Get effective lumis
    std::map < std::string, float > efflumis = GetLumis();
    efflumi = efflumis[process.Data()];
    assert(efflumi > 0);
    efflumi_old       = efflumi;
    efflumi_UEPS_up   = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(3);
    efflumi_UEPS_down = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(4);



    TTreeFormula* ttf_lheweight = new TTreeFormula("ttf_lheweight", Form("%f", efflumi), inTree);
#ifdef STITCH
    std::map < std::string, std::string > lheweights = GetLHEWeights();
    TString process_lhe = process;
    if (process_lhe.BeginsWith("WJets") && process_lhe != "WJetsHW")
        process_lhe = "WJets";
    else if (process_lhe.BeginsWith("ZJets") && process_lhe != "ZJetsHW")
        process_lhe = "ZJets";
    else 
        process_lhe = "";
    TString lheweight = lheweights[process_lhe.Data()];
    if (lheweight != "") {
        delete ttf_lheweight;
        
        // Bug fix for ZJetsPtZ100
        if (process == "ZJetsPtZ100")
            lheweight.ReplaceAll("lheV_pt", "999");
        std::cout << "BUGFIX: " << lheweight << std::endl;
        ttf_lheweight = new TTreeFormula("ttf_lheweight", lheweight, inTree);
    }
#endif
    ttf_lheweight->SetQuickLoad(1);

    // regression stuff here

    
    ///-- Setup TMVA Reader ----------------------------------------------------
    TMVA::Tools::Instance();  //< This loads the library
    TMVA::Reader * reader = new TMVA::Reader("!Color:!Silent");

    /// Get the variables
    const std::vector < std::string > & inputExpressionsReg = GetInputExpressionsReg();
    
   const UInt_t nvars = inputExpressionsReg.size();
   
    Float_t readerVars[nvars];
    int idx_rawpt = -1, idx_pt = -1, idx_et = -1, idx_mt = -1;
   
    for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) {
        const TString& expr = inputExpressionsReg.at(iexpr);
        reader->AddVariable(expr, &readerVars[iexpr]);
        if      (expr.BeginsWith("breg_rawptJER := "))  idx_rawpt = iexpr;
        else if (expr.BeginsWith("breg_pt := "))        idx_pt = iexpr;
        else if (expr.BeginsWith("breg_et := "))        idx_et = iexpr;
        else if (expr.BeginsWith("breg_mt := "))        idx_mt = iexpr;
    }
    //    assert(idx_rawpt!=-1 && idx_pt!=-1 && idx_et!=-1 && idx_mt!=-1);
    assert(idx_rawpt!=-1 && idx_pt!=-1 );

    /// Setup TMVA regression inputs
    const std::vector < std::string > & inputExpressionsReg0 = GetInputExpressionsReg0();
    const std::vector < std::string > & inputExpressionsReg1 = GetInputExpressionsReg1();
    assert(inputExpressionsReg0.size() == nvars);
    assert(inputExpressionsReg1.size() == nvars);

    /// Load TMVA weights
    TString weightdir  = "weights/";
    TString weightfile = weightdir + "TMVARegression_" + regMethod + ".testweights.xml";
    reader->BookMVA(regMethod + " method", weightfile);
    
    TStopwatch sw;
    sw.Start();


    /// Create TTreeFormulas
    TTreeFormula *ttf = 0;
    std::vector < TTreeFormula * >::const_iterator formIt, formItEnd;
    std::vector < TTreeFormula * > inputFormulasReg0;
    std::vector < TTreeFormula * > inputFormulasReg1;
    std::vector < TTreeFormula * > inputFormulasFJReg0;
    std::vector < TTreeFormula * > inputFormulasFJReg1;
    std::vector < TTreeFormula * > inputFormulasFJReg2;

    
    for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) {
        ttf = new TTreeFormula(Form("ttfreg%i_0", iexpr), inputExpressionsReg0.at(iexpr).c_str(), inTree);
        ttf->SetQuickLoad(1);
        inputFormulasReg0.push_back(ttf);
        ttf = new TTreeFormula(Form("ttfreg%i_1", iexpr), inputExpressionsReg1.at(iexpr).c_str(), inTree);
        ttf->SetQuickLoad(1);
        inputFormulasReg1.push_back(ttf);
    }
 


    ///-- Loop over events -----------------------------------------------------
    Int_t curTree = inTree->GetTreeNumber();
    const Long64_t nentries = inTree->GetEntries();
    if (endEntry < 0)  endEntry = nentries;

    Long64_t ievt = 0;
    for (ievt=TMath::Max(ievt, beginEntry); ievt<TMath::Min(nentries, endEntry); ievt++) {
        if (ievt % 2000 == 0)
            std::cout << "--- ... Processing event: " << ievt << std::endl;
    
        const Long64_t local_entry = inTree->LoadTree(ievt);  // faster, but only for TTreeFormula
        if (local_entry < 0)  break;
        inTree->GetEntry(ievt);  // same event as received by LoadTree()

        if (inTree->GetTreeNumber() != curTree) {
            curTree = inTree->GetTreeNumber();

            for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++)
                (*formIt)->UpdateFormulaLeaves();  // if using TChain
            for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++)
                (*formIt)->UpdateFormulaLeaves();  // if using TChain
            for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++)
                (*formIt)->UpdateFormulaLeaves();  // if using TChain
            for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++)
                (*formIt)->UpdateFormulaLeaves();  // if using TChain
            for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++)
                (*formIt)->UpdateFormulaLeaves();  // if using TChain

            ttf_lheweight->UpdateFormulaLeaves();
        }


        /// These need to be called when arrays of variable size are used in TTree.
        for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++)
            (*formIt)->GetNdata();
        for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++)
            (*formIt)->GetNdata();
        for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++)
            (*formIt)->GetNdata();
        for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++)
            (*formIt)->GetNdata();
        for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++)
            (*formIt)->GetNdata();

        ttf_lheweight->GetNdata();
        /// Fill branches
        EVENT_run = EVENT.run;
        EVENT_event = EVENT.event;



#ifdef STITCH        
        efflumi           = ttf_lheweight->EvalInstance();
	//        efflumi_UEPS_up   = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(3);
        //efflumi_UEPS_down = efflumi * hcount->GetBinContent(2) / hcount->GetBinContent(4);
#endif
    
        bool verbose = false;
 
	for (Int_t ihj = 0; ihj < 2; ihj++) {

   
            /// Evaluate TMVA regression output
            for (UInt_t iexpr = 0; iexpr < nvars; iexpr++) {
                if (ihj==0) {
                    readerVars[iexpr] = inputFormulasReg0.at(iexpr)->EvalInstance();

                } else if (ihj==1) {
                    readerVars[iexpr] = inputFormulasReg1.at(iexpr)->EvalInstance();
                }
            }

	    hJet_ptReg[ihj]               = (reader->EvaluateRegression(regMethod + " method"))[0];
            if (verbose)  std::cout << readerVars[idx_pt] << " " << readerVars[idx_rawpt] <<  " " << hJet_pt[ihj] << " " << hJet_ptReg[ihj] << " " << hJet_genPt[ihj] << std::endl;
        const TLorentzVector p4Zero                     = TLorentzVector(0., 0., 0., 0.);
	//	int idx =  hJCidx[0] ;
	//	std::cout << "the regressed pt for jet 0 is " << hJet_ptReg[0] << "; the hJCidx is " << hJCidx[0] << ", hence the origianl pt is " <<  hJet_pt[idx] << std::endl;

	
       
        const TLorentzVector& hJet_p4Norm_0             = makePtEtaPhiM(hJet_pt[hJCidx[0]]                , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]);
        const TLorentzVector& hJet_p4Norm_1             = makePtEtaPhiM(hJet_pt[hJCidx[1]]                , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]);
        const TLorentzVector& hJet_p4Gen_0              = hJet_genPt[hJCidx[0]] > 0 ? 
                                                          makePtEtaPhiM(hJet_genPt[hJCidx[0]]             , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]) : p4Zero;
        const TLorentzVector& hJet_p4Gen_1              = hJet_genPt[hJCidx[1]] > 0 ? 
                                                          makePtEtaPhiM(hJet_genPt[hJCidx[1]]             , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]) : p4Zero;
        const TLorentzVector& hJet_p4Reg_0              = makePtEtaPhiM(hJet_ptReg[0]             , hJet_pt[hJCidx[0]], hJet_eta[hJCidx[0]], hJet_phi[hJCidx[0]], hJet_m[hJCidx[0]]);
        const TLorentzVector& hJet_p4Reg_1              = makePtEtaPhiM(hJet_ptReg[1]             , hJet_pt[hJCidx[1]], hJet_eta[hJCidx[1]], hJet_phi[hJCidx[1]], hJet_m[hJCidx[1]]);
        HptNorm             = (hJet_p4Norm_0             + hJet_p4Norm_1            ).Pt();
        HptGen              = (hJet_p4Gen_0              + hJet_p4Gen_1             ).Pt();
        HptReg              = (hJet_p4Reg_0              + hJet_p4Reg_1             ).Pt();
        HmassNorm             = (hJet_p4Norm_0             + hJet_p4Norm_1            ).M();
        HmassGen              = (hJet_p4Gen_0              + hJet_p4Gen_1             ).M();
        HmassReg              = (hJet_p4Reg_0              + hJet_p4Reg_1             ).M();
	//        std::cout << "HmassReg is " << HmassReg << std::endl; 
	
	}
        outTree->Fill();  // fill it!
    }  // end loop over TTree entries

    /// Get elapsed time
    sw.Stop();
    std::cout << "--- End of event loop: ";
    sw.Print();

    output->cd();
    outTree->Write();
    output->Close();
    input->Close();

    delete input;
    delete output;
    for (formIt=inputFormulasReg0.begin(), formItEnd=inputFormulasReg0.end(); formIt!=formItEnd; formIt++)
        delete *formIt;
    for (formIt=inputFormulasReg1.begin(), formItEnd=inputFormulasReg1.end(); formIt!=formItEnd; formIt++)
        delete *formIt;
    for (formIt=inputFormulasFJReg0.begin(), formItEnd=inputFormulasFJReg0.end(); formIt!=formItEnd; formIt++)
        delete *formIt;
    for (formIt=inputFormulasFJReg1.begin(), formItEnd=inputFormulasFJReg1.end(); formIt!=formItEnd; formIt++)
        delete *formIt;
    for (formIt=inputFormulasFJReg2.begin(), formItEnd=inputFormulasFJReg2.end(); formIt!=formItEnd; formIt++)
        delete *formIt;

    delete ttf_lheweight;

    std::cout << "==> GrowTree is done!" << std::endl << std::endl;
    return;
}
コード例 #11
0
int NeroMetRecluster::analyze(const edm::Event& iEvent){

    if ( mOnlyMc  ) return 0; // in principle I would like to have the gen met: TODO

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);
    if ( not handle.isValid() ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] handle is not valid"<<endl;

    iEvent.getByToken(token_puppi,handle_puppi);
    if ( not handle_puppi.isValid() ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] handle_puppi is not valid"<<endl;

    iEvent.getByToken(token_puppiUncorr,handle_puppiUncorr);
    if ( not handle_puppiUncorr.isValid() ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] handle_puppiUncorr is not valid"<<endl;
    //--

    const pat::MET &met = handle->front();

    caloMet_Pt = met.caloMETPt();
    caloMet_Phi = met.caloMETPhi();
    caloMet_SumEt = met.caloMETSumEt();


    // FILL
    new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector( met.px(),met.py(),met.pz(),met.energy()  );

    sumEtRaw = met.uncorSumEt();

    ptJESUP -> push_back( met.shiftedPt(pat::MET::JetEnUp) );
    ptJESDOWN -> push_back( met.shiftedPt(pat::MET::JetEnDown) );

    rawMet_Pt = met.uncorPt(); 
    rawMet_Phi = met.uncorPhi();


    if (IsExtend())
    {
        //MetNoMu
        TLorentzVector metnomu(met.px(),met.py(),met.pz(),met.energy());
        TLorentzVector tkMet(0,0,0,0); 
        TLorentzVector pfmet_3p0(0,0,0,0); 

        if ( pf == NULL ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] PF pointer is null. Run NeroPF. "<<endl; 

        for (unsigned int i = 0, n = pf->handle->size(); i < n; ++i) {
            const pat::PackedCandidate &cand = (*pf->handle)[i];

            // only up to eta 3
            if (std::abs(cand.pdgId()) == 13)
                metnomu += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());  

            // only charge hadrons
            if ( cand.charge() != 0 )
                tkMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());

            if (std::abs(cand.eta()) < 3.0 ) 
                pfmet_3p0 += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
        }

        *pfMet_e3p0 = TLorentzVector( -pfmet_3p0 );
        *metNoMu = TLorentzVector(metnomu);  // no minus
        *trackMet = TLorentzVector( -tkMet );

        auto &puppi = handle_puppi->front(); 
        *metPuppi =  TLorentzVector( puppi.px(), puppi.py(),puppi.pz(),puppi.energy() );
        sumEtRawPuppi = handle_puppiUncorr->front().sumEt();

    }    
    // GEN INFO
    if ( not iEvent.isRealData () ){
        new ( (*genP4)[genP4->GetEntriesFast()]) TLorentzVector( met.genMET()->px(),met.genMET()->py(),met.genMET()->pz(),met.genMET()->energy()  );
    }


    return 0;
}
コード例 #12
0
ファイル: example.C プロジェクト: bvormwald/HHKinFit
int main(int argc, char* argv[])
{
  TFile* f = new TFile("example/ntuple.root","READ");
  TTree* t = (TTree*) f->Get("EleTauKinFit");
  
  TH1F* h_mH    = new TH1F("h_mH",   "distribution of mH_{fit};mH_{fit} [GeV];entries/5GeV", 40,200,400);
  TH1F* h_chi2  = new TH1F("h_chi2", "distribution of #chi^{2}_{fit};#chi^{2}_{fit};entries/1", 100,0,25);
  TH1F* h_prob  = new TH1F("h_prob", "distribution of fit probability;P_{fit};entries/0.05", 100,0,1);
  TH1F* h_pull1 = new TH1F("h_pull1","pull distribution E_{b1};pull;entries/0.25", 20,-5,5);
  TH1F* h_pull2 = new TH1F("h_pull2","pull distribution E_{b2};pull;entries/0.25", 20,-5,5);
  TH1F* h_pullB = new TH1F("h_pullB","pull distribution balance;pull;entries/0.25", 20,-5,5);
  
  Int_t max_nevent = t->GetEntriesFast();

  //Leaf types  
   Int_t           njets;
   Double_t        b1_dR;
   Double_t        b1_csv;
   Double_t        b1_px;
   Double_t        b1_py;
   Double_t        b1_pz;
   Double_t        b1_E;
   Double_t        b2_dR;
   Double_t        b2_csv;
   Double_t        b2_px;
   Double_t        b2_py;
   Double_t        b2_pz;
   Double_t        b2_E;
   Double_t        tauvis1_dR;
   Double_t        tauvis1_px;
   Double_t        tauvis1_py;
   Double_t        tauvis1_pz;
   Double_t        tauvis1_E;
   Double_t        tauvis2_dR;
   Double_t        tauvis2_px;
   Double_t        tauvis2_py;
   Double_t        tauvis2_pz;
   Double_t        tauvis2_E;
   Double_t        met_pt;
   Double_t        met_px;
   Double_t        met_py;
   Double_t        met_cov00;
   Double_t        met_cov10;
   Double_t        met_cov01;
   Double_t        met_cov11;


  // List of branches
   TBranch        *b_njets;
   TBranch        *b_b1_dR;
   TBranch        *b_b1_csv;
   TBranch        *b_b1_px;
   TBranch        *b_b1_py;
   TBranch        *b_b1_pz;
   TBranch        *b_b1_E;
   TBranch        *b_b2_dR;
   TBranch        *b_b2_csv;
   TBranch        *b_b2_px;
   TBranch        *b_b2_py;
   TBranch        *b_b2_pz;
   TBranch        *b_b2_E;
   TBranch        *b_tauvis1_dR;
   TBranch        *b_tauvis1_px;
   TBranch        *b_tauvis1_py;
   TBranch        *b_tauvis1_pz;
   TBranch        *b_tauvis1_E;
   TBranch        *b_tauvis2_dR;
   TBranch        *b_tauvis2_px;
   TBranch        *b_tauvis2_py;
   TBranch        *b_tauvis2_pz;
   TBranch        *b_tauvis2_E;
   TBranch        *b_met_pt;
   TBranch        *b_met_px;
   TBranch        *b_met_py;
   TBranch        *b_met_cov00;
   TBranch        *b_met_cov10;
   TBranch        *b_met_cov01;
   TBranch        *b_met_cov11;
     
   t->SetBranchAddress("Njets", &njets, &b_njets);
   t->SetBranchAddress("b1_dR", &b1_dR, &b_b1_dR);
   t->SetBranchAddress("b1_csv", &b1_csv, &b_b1_csv);
   t->SetBranchAddress("b1_px", &b1_px, &b_b1_px);
   t->SetBranchAddress("b1_py", &b1_py, &b_b1_py);
   t->SetBranchAddress("b1_pz", &b1_pz, &b_b1_pz);
   t->SetBranchAddress("b1_E", &b1_E, &b_b1_E);
   t->SetBranchAddress("b2_dR", &b2_dR, &b_b2_dR);
   t->SetBranchAddress("b2_csv", &b2_csv, &b_b2_csv);
   t->SetBranchAddress("b2_px", &b2_px, &b_b2_px);
   t->SetBranchAddress("b2_py", &b2_py, &b_b2_py);
   t->SetBranchAddress("b2_pz", &b2_pz, &b_b2_pz);
   t->SetBranchAddress("b2_E", &b2_E, &b_b2_E);
   t->SetBranchAddress("tauvis1_dR", &tauvis1_dR, &b_tauvis1_dR);
   t->SetBranchAddress("tauvis1_px", &tauvis1_px, &b_tauvis1_px);
   t->SetBranchAddress("tauvis1_py", &tauvis1_py, &b_tauvis1_py);
   t->SetBranchAddress("tauvis1_pz", &tauvis1_pz, &b_tauvis1_pz);
   t->SetBranchAddress("tauvis1_E", &tauvis1_E, &b_tauvis1_E);
   t->SetBranchAddress("tauvis2_dR", &tauvis2_dR, &b_tauvis2_dR);
   t->SetBranchAddress("tauvis2_px", &tauvis2_px, &b_tauvis2_px);
   t->SetBranchAddress("tauvis2_py", &tauvis2_py, &b_tauvis2_py);
   t->SetBranchAddress("tauvis2_pz", &tauvis2_pz, &b_tauvis2_pz);
   t->SetBranchAddress("tauvis2_E", &tauvis2_E, &b_tauvis2_E);
   t->SetBranchAddress("met_pt", &met_pt, &b_met_pt);
   t->SetBranchAddress("met_px", &met_px, &b_met_px);
   t->SetBranchAddress("met_py", &met_py, &b_met_py);
   t->SetBranchAddress("met_cov00", &met_cov00, &b_met_cov00);
   t->SetBranchAddress("met_cov10", &met_cov10, &b_met_cov10);
   t->SetBranchAddress("met_cov01", &met_cov01, &b_met_cov01);
   t->SetBranchAddress("met_cov11", &met_cov11, &b_met_cov11);

  //define the testd hypotheses
  std::vector<Int_t> hypo_mh1;
  hypo_mh1.push_back(125);
  std::vector<Int_t> hypo_mh2;
  hypo_mh2.push_back(125);
  
  // event loop
  for (int i = 0; i < max_nevent; i++) {
    t->GetEntry(i);
    
    //use only btaged jets and check for correct gen match
    if (b1_csv<0.681 || b2_csv<0.681 || njets < 2 || b1_dR > 0.2 || b2_dR > 0.2 || tauvis1_dR > 0.1 || tauvis2_dR > 0.1)   continue;
    
    //define input vectors
    TLorentzVector b1      = TLorentzVector(b1_px,b1_py,b1_pz,b1_E);
    TLorentzVector b2      = TLorentzVector(b2_px,b2_py,b2_pz,b2_E);
    TLorentzVector tau1vis = TLorentzVector(tauvis1_px,tauvis1_py,tauvis1_pz,tauvis1_E);
    TLorentzVector tau2vis = TLorentzVector(tauvis2_px,tauvis2_py,tauvis2_pz,tauvis2_E);
    
    TLorentzVector ptmiss  = TLorentzVector(met_px,met_py,0,met_pt);
    TMatrixD metcov(2,2);
    metcov(0,0)=met_cov00;
    metcov(1,0)=met_cov10;
    metcov(0,1)=met_cov01;    
    metcov(1,1)=met_cov11;
    
    //intance of fitter master class
    HHKinFitMaster kinFits = HHKinFitMaster(&b1,&b2,&tau1vis,&tau2vis);
    kinFits.setAdvancedBalance(&ptmiss,metcov);
    //kinFits.setSimpleBalance(ptmiss.Pt(),10); //alternative which uses only the absolute value of ptmiss in the fit
    kinFits.addMh1Hypothesis(hypo_mh1);
    kinFits.addMh2Hypothesis(hypo_mh2);
    kinFits.doFullFit();

    //obtain results from different hypotheses
    Double_t chi2_best = kinFits.getBestChi2FullFit();
    Double_t mh_best = kinFits.getBestMHFullFit();
    std::pair<Int_t, Int_t> bestHypo = kinFits.getBestHypoFullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_chi2 = kinFits.getChi2FullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_fitprob = kinFits.getFitProbFullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_mH = kinFits.getMHFullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_pull_b1 = kinFits.getPullB1FullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_pull_b2 = kinFits.getPullB2FullFit();
    std::map< std::pair<Int_t, Int_t>, Double_t> fit_results_pull_balance = kinFits.getPullBalanceFullFit();
    std::map< std::pair<Int_t, Int_t>, Int_t> fit_convergence = kinFits.getConvergenceFullFit();

    std::cout << "#############################" << std::endl;
    std::cout << "EVENT" << i << std::endl;
    std::cout << "#############################" << std::endl;
    std::cout << "=====================================" << std::endl;
    std::cout << "event:           " << i << std::endl;
    std::cout << "best chi2:       " << chi2_best << std::endl;
    std::cout << "best hypothesis: " << bestHypo.first << " " << bestHypo.second << std::endl;
    std::cout << "best mH=         " << mh_best << std::endl;
    std::cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << std::endl;

   //individual loop over results
    for (std::vector<Int_t>::iterator mh2 = hypo_mh2.begin(); mh2 != hypo_mh2.end(); mh2++){
      for (std::vector<Int_t>::iterator mh1 = hypo_mh1.begin(); mh1 != hypo_mh1.end(); mh1++){
        std::pair< Int_t, Int_t > hypo(*mh1,*mh2);
        
        //sanity cuts: use only converged fits and events with chi2<25 and make sure used cov was positive definit (this needs to be fixed!)
        if (fit_convergence.at(hypo)>0 && fit_results_chi2.at(hypo)<25 && fit_results_pull_balance.at(hypo)>0){
        
          std::cout << *mh1 << " " << *mh2 << " " << "chi2_fit:    " << fit_results_chi2.at(hypo) << std::endl;
          std::cout << *mh1 << " " << *mh2 << " " << "prob_fit:    " << fit_results_fitprob.at(hypo) << std::endl;
          std::cout << *mh1 << " " << *mh2 << " " << "mH_fit=      " << fit_results_mH.at(hypo) << std::endl;
          std::cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << std::endl;

          h_mH->Fill(fit_results_mH.at(hypo));
          h_chi2->Fill(fit_results_chi2.at(hypo));
          h_prob->Fill(fit_results_fitprob.at(hypo));
          h_pull1->Fill(fit_results_pull_b1.at(hypo));
          h_pull2->Fill(fit_results_pull_b2.at(hypo));
          h_pullB->Fill(fit_results_pull_balance.at(hypo));
        }
      }
    }    
  }

  TFile fout("result.root","RECREATE");
  h_mH->Write();
  h_chi2->Write();
  h_prob->Write();
  h_pull1->Write();
  h_pull2->Write();
  h_pullB->Write();
  
  return (0);
}
コード例 #13
0
ファイル: Analysis.C プロジェクト: francescorubbo/VariableR
Bool_t Analysis::Process(Long64_t entry)
{

  jpt  ->clear();    
  jeta ->clear(); 
  jphi ->clear(); 
  jmass->clear();
  jconst->clear();
  toppt->clear();
  jhasb->clear();
  jhasq->clear();
  
  if (entry%1==0) cout << "\r Events  " << entry << "\r" << flush;
  this->GetEntry(entry);
    
  double rho = 2*173.5;
  double min_r = 0.4;
  double max_r = 1.5;
  double ptmin = 200.;

  // fill jets
  //-----------------------------------------------
  vector<fastjet::PseudoJet> pseudojets; pseudojets.clear();
  for (int ijet=0;ijet<jets_n;++ijet){
    if(jets_isBad->at(ijet)!=0) return kFALSE;
    if(jets_pt->at(ijet)<20.) continue;
    if(fabs(jets_eta->at(ijet))>2.8) continue;
    TLorentzVector tvit = TLorentzVector();
    tvit.SetPtEtaPhiE(jets_pt->at(ijet),
		      jets_eta->at(ijet),
		      jets_phi->at(ijet),
		      jets_e->at(ijet));
    pseudojets.push_back( fastjet::PseudoJet(tvit.Px(), tvit.Py(), 
					     tvit.Pz(), tvit.E()) );
  }

  // fill truth
  //----------------------------------------------
  vector<int> tops;
  vector<int> Wq1s;
  vector<int> Wq2s;
  vector<int> bs;
  for (int imc=0;imc<mc_n;++imc)
    if (fabs(mc_pdgId->at(imc))==6){
      int windex = mc_children_index->at(imc)[0];
      int bindex = mc_children_index->at(imc)[1];
      int wq1 = mc_children_index->at(windex)[0];
      int wq2 = mc_children_index->at(windex)[1];
      if(fabs(mc_pdgId->at(wq1))>5 || fabs(mc_pdgId->at(wq2))>5) continue;
      tops.push_back( imc );
      Wq1s.push_back( wq1 );
      Wq2s.push_back( wq2 );
      bs.push_back( bindex );
      toppt->push_back( mc_pt->at(imc) );
    }//endif

  for (int it=0;it<tops.size();++it){
    fastjet::PseudoJet wq1; wq1.reset_PtYPhiM(1e-10,mc_eta->at(Wq1s[it]),mc_phi->at(Wq1s[it]));
    fastjet::PseudoJet wq2; wq2.reset_PtYPhiM(1e-10,mc_eta->at(Wq2s[it]),mc_phi->at(Wq2s[it]));
    fastjet::PseudoJet bq; bq.reset_PtYPhiM(1e-10,mc_eta->at(bs[it]),mc_phi->at(bs[it]));
    wq1.set_user_info(new MyUserInfo(it, false));
    wq1.set_user_info(new MyUserInfo(it, false));
    bq.set_user_info(new MyUserInfo(it, true));
    pseudojets.push_back( wq1 );
    pseudojets.push_back( wq2 );
    pseudojets.push_back( bq );
  }// top loop

  fastjet::contrib::VariableRPlugin lvjet_pluginAKT(rho, min_r, max_r, fastjet::contrib::VariableRPlugin::AKTLIKE);
  fastjet::JetDefinition jet_def(&lvjet_pluginAKT);
  fastjet::ClusterSequence clust_seqAKT(pseudojets, jet_def);
  vector<fastjet::PseudoJet> inclusive_jetsAKT = clust_seqAKT.inclusive_jets(ptmin);

  for (int ijet=0;ijet<inclusive_jetsAKT.size();++ijet){
    fastjet::PseudoJet *jet = &(inclusive_jetsAKT[ijet]);
    jpt->push_back( jet->pt() );
    jeta->push_back( jet->eta() );
    jphi->push_back( jet->phi() );
    jmass->push_back( jet->m() );
    int ntruth=0;
    vector<int> hasb;
    vector<int> hasq;
    for (int iconst=0;iconst<jet->constituents().size();++iconst){
      fastjet::PseudoJet *jetconst = &(jet->constituents()[iconst]);
      if (jetconst->has_user_info<MyUserInfo>()){
	ntruth++;
	int topid = jetconst->user_info<MyUserInfo>().top();
	bool isbq = jetconst->user_info<MyUserInfo>().isbq();
	if(isbq) hasb.push_back(topid);
	else hasq.push_back(topid);
      }//endif is truth
    }//loop constituents
    jconst->push_back( jet->constituents().size()-ntruth );
    jhasb->push_back( hasb );
    jhasq->push_back( hasq );
  }// loop reclustered jets

  outtree->Fill();

  return kTRUE;
}
コード例 #14
0
int main() 
{

	// -- Declaring Cuba variables -- //
	int comp, nregions, neval, fail;
	cubareal integral[NCOMP], error[NCOMP], prob[NCOMP];
	
	// -- ThreeBodyDecay initialization-- // 
	muon.SetMotherMPThetaPhi(M,muon_p,muon_theta,muon_phi);
	muon.SetBitBoostBack(BitBoostBack);

	// -- Set up pointers to the momenta
	P  = muon.P;
	p1 = muon.p[0];
	p2 = muon.p[1];
	p3 = muon.p[2];

	// -- Get muon kinematics
   double P_gamma  = P->Gamma();
   double P_beta   = P->Beta();
   double P_M      = P->M();
   double P_MomMag = P->P();

	// -- Polarization vector -- //
	// -- Custom vector construction
   k0_custom = TLorentzVector(1.0, 0.0, 0.0, 1.0);
   // k0_custom = TLorentzVector(3, 2, 0.0, 1.0);
   // k0_custom = TLorentzVector(1.0, 0.0, 0.0, 1.0);
	double alpha = 1;

	// -- Phyicsal vector construction
	k0_physical[3] = 1;
	for (int i = 0; i<3; i++)
	{ k0_physical[i] = (*P)[i]/P_MomMag; }

	for (int nu = 0; nu<4; nu++)
	{ k0_physical[nu] = alpha*k0_physical[nu]/(P_M*P_gamma*(1+P_beta)); }
	
	// -- Choosing k0 auxiliary vector
	if ( k0_flag == 1)
	{ k0 = k0_custom; }

	if ( k0_flag == 2)
	{ k0 = k0_physical; }

	// Get pk0 scalar product
	double Pk0 = P->Dot(k0);

	// Custom spin polarization vector with p and k0
	if (polvec_flag == 1)
	{
		for(int nu = 0; nu<4; nu++)
		{ polvec[nu] = ( (*P)[nu]/M) - (M/Pk0)*k0[nu]; }
	}

	// Helicity spin ampltiude vector
	// Note:
	// This should be equivalent to the custom pol. vector
	// when choosing physical k0
	// Default:
	if (polvec_flag == 2)
	{

		TVector3 phat(1.0,0.0,0.0);
		phat.SetPhi(phat_phi);
		phat.SetTheta(phat_theta);

		polvec = TLorentzVector(phat,P->Beta());

		for(int nu = 0; nu<4; nu++)
		{ polvec[nu] = polvec[nu]*P_gamma; }
	}

	phat34 = TVector3(1.0,0.0,0.0);
   phat34.SetPhi(phat34_phi);
   phat34.SetTheta(phat34_theta);
	polvec34 = TLorentzVector(phat34,0);



/////////////////////////////////////////////////////////////////////////

#if 1

  printf("-------------------- Vegas test --------------------\n");

  Vegas(NDIM, NCOMP, Integrand, USERDATA, NVEC,
    EPSREL, EPSABS, VERBOSE, SEED,
    MINEVAL, MAXEVAL, NSTART, NINCREASE, NBATCH,
    GRIDNO, STATEFILE, SPIN,
    &neval, &fail, integral, error, prob);

  printf("VEGAS RESULT:\tneval %d\tfail %d\n",
    neval, fail);
  comp = 0;
    printf("VEGAS RESULT:\t%.8f +- %.8f\tp = %.3f\n",
      (double)integral[comp], (double)error[comp], (double)prob[comp]);
#endif

#if 0
  printf("\n-------------------- Suave test --------------------\n");

  Suave(NDIM, NCOMP, Integrand, USERDATA, NVEC,
    EPSREL, EPSABS, VERBOSE | LAST, SEED,
    MINEVAL, MAXEVAL, NNEW, NMIN, FLATNESS,
    STATEFILE, SPIN,
    &nregions, &neval, &fail, integral, error, prob);

  printf("SUAVE RESULT:\tnregions %d\tneval %d\tfail %d\n",
    nregions, neval, fail);
  comp = 0;
    printf("SUAVE RESULT:\t%.8f +- %.8f\tp = %.3f\n",
      (double)integral[comp], (double)error[comp], (double)prob[comp]);
#endif

#if 0
  printf("\n------------------- Divonne test -------------------\n");

  Divonne(NDIM, NCOMP, Integrand, USERDATA, NVEC,
    EPSREL, EPSABS, VERBOSE, SEED,
    MINEVAL, MAXEVAL, KEY1, KEY2, KEY3, MAXPASS,
    BORDER, MAXCHISQ, MINDEVIATION,
    NGIVEN, LDXGIVEN, NULL, NEXTRA, NULL,
    STATEFILE, SPIN,
    &nregions, &neval, &fail, integral, error, prob);

  printf("DIVONNE RESULT:\tnregions %d\tneval %d\tfail %d\n",
    nregions, neval, fail);
  for( comp = 0; comp < NCOMP; ++comp )
    printf("DIVONNE RESULT:\t%.8f +- %.8f\tp = %.3f\n",
      (double)integral[comp], (double)error[comp], (double)prob[comp]);
#endif

#if 0
  printf("\n-------------------- Cuhre test --------------------\n");

  Cuhre(NDIM, NCOMP, Integrand, USERDATA, NVEC,
    EPSREL, EPSABS, VERBOSE | LAST,
    MINEVAL, MAXEVAL, KEY,
    STATEFILE, SPIN,
    &nregions, &neval, &fail, integral, error, prob);

  printf("CUHRE RESULT:\tnregions %d\tneval %d\tfail %d\n",
    nregions, neval, fail);
  for( comp = 0; comp < NCOMP; ++comp )
    printf("CUHRE RESULT:\t%.8f +- %.8f\tp = %.3f\n",
      (double)integral[comp], (double)error[comp], (double)prob[comp]);
#endif

  double result = (double)integral[comp];

  // If result is unpolarized divide by 2.0
  if ( (ampltiude == 0) || (ampltiude == 34) )
  { result = result / 2.0;}

  double PSConst = muon.GetPSConst();
  double result_wogamma = result * PSConst * G_Fermi * G_Fermi / M / 2.0  ;
  result = result * PSConst * G_Fermi * G_Fermi / P->E() / 2.0 ;

  double ratio_formula = result/gamma_formula;
  double ratio_PDG = result/gamma_PDG;

  double  tau = hbar/result;
  double ctau = tau*c;

  double  tau_wogamma = hbar/result_wogamma;
  double ctau_wogamma = tau_wogamma*c;


  // -- Displaying info -- //

  printf("\n");
  printf("###############################################\n");
  printf("### --- Muon decay lifetime calculation --- ###\n");
  printf("###############################################\n");

  printf("\n");

  printf("--------------------------\n");
  printf("--- Physical constants ---\n");
  printf("--------------------------\n");

  printf("\n");
  printf("hbar:    %12.6e [GeV s]\n", hbar);
  printf("c:       %12.6e [m/s]\n", c);
  printf("hbar*c:  %12.6e [GeV fm]\n", hbar_c);
  printf("G_Fermi: %12.6e [GeV^{-2}]\n", G_Fermi);

  printf("\n");
  printf("Muon constants:\n");
  printf("m (muon):                  %12.6f [GeV]\n", M);
  printf("c_tau:                     %12.6e  [fm]\n", c_tau_muon);
  printf("Gamma(PDG) = hbarc/c_tau = %12.6e [GeV]\n", gamma_PDG);

  printf("\n");
  printf("Other masses:\n");
  printf("m (elec):       %12.6f [GeV]\n", m1);
  printf("m (nu_e):       %12.6f [GeV]\n", m2);
  printf("m (nu_m):       %12.6f [GeV]\n", m3);

  printf("\n");
  printf("-------------------------\n");
  printf("---   Decay process   ---\n");
  printf("-------------------------\n");

  printf("\n");
  printf("(muon)- ---> (electron)- (nu_mu) (nu_electronbar)\n");
  printf("  p     --->      q        k            k' \n");
  printf("  p     --->      q        k1           k2 \n");
  printf("  P     --->     p1        p2           p3 \n");
  printf("\n");

  printf("-------------------------\n");
  printf("---   Configuration   ---\n");
  printf("-------------------------\n");

  printf("\n");
  printf("############\n");
  printf("### Muon ###\n");
  printf("############\n");
  printf("\n");
  printf("|mom|:  %12.6f [GeV/c]\n", muon_p);
  printf("theta:  %12.6f [rad]\n", muon_theta);
  printf("phi:    %12.6f [rad]\n", muon_phi);
  printf("gamma:  %12.6f \n", P->Gamma());
  printf("beta:   %12.6f \n", P->Beta());
  printf("\n");
  printf("Momentum:\n");
  displayTLorentzVector(P);
  printf("\n");

  printf("Unitvector pointing in the direction of momentum:\n");
  printf("x: %12.6f\n", (*P)[0]/P->P());
  printf("y: %12.6f\n", (*P)[1]/P->P());
  printf("z: %12.6f\n", (*P)[1]/P->P());
  printf("\n");


  printf("################################\n");
  printf("### Spin Polarization vector ###\n");
  printf("################################\n");
  printf("### - Denoted by s^{mu}         \n");
  printf("\n");


  if ( (ampltiude == -1) || (ampltiude == 0) || (ampltiude == 1) )
  {

  if ( polvec_flag == 1 )
  {

   printf("polvec_flag: %d\n", polvec_flag);
  	printf("Spin polarization defined with auxiliary vector k0:\n");
  	printf("s^{mu} = P^{mu}/M - (m/Pk0)*k0^{mu}\n");
   printf("\n");

  	printf("k0_flag: %d\n", k0_flag);
   if ( k0_flag == 1 )
	{ printf("Custom k0:\n"); }

   if ( k0_flag == 2 )
	{ 
		printf("Choice of k0, yielding helicity polarization vector.\n");
		printf("Physical k0:\n");
	}

  	displayTLorentzVector(&k0);
  	printf("\n");

  }

  if ( polvec_flag == 2 )
  {
   printf("polvec_flag: %d\n", polvec_flag);
  	printf("Spin polarization vector = helicity polarization vector\n");
 	printf("s^{mu} = ( |pvec|^2 , p0 pvec) / (m |pvec|)) = \n");
 	printf("       = gamma (beta,phat vector)\n");
   printf("\n");
  }

  printf("Spin polarization vector components:\n");
  displayTLorentzVector(&polvec);

  }

  if ( (ampltiude == 3) || (ampltiude == 4) || (ampltiude == 34) )
  {
  	 printf("Spin polarization vector defined in rest frame of the muon\n");
  	 printf("s^{mu} = (0,phat34)\n");

   printf("\n");
  	 printf("where the phat34 is pointing towards:\n");
  	 printf("phat34 theta: %12.6f\n", phat34_theta);
  	 printf("phat34 phi:   %12.6f\n", phat34_phi);

   printf("\n");
  	 printf("phat34 components:\n");
  	 printf("x: %12.6f\n", phat34[0]);
  	 printf("y: %12.6f\n", phat34[1]);
  	 printf("z: %12.6f\n", phat34[2]);

  }

  printf("\n");
  printf("--------------------------\n");
  printf("--- Consistency checks ---\n");
  printf("--------------------------\n");

  printf("\n");
  printf("- Lorentz scalar product (ps) = 0 (orthogonality check)\n");
  printf("(ps): %12.6e     (should give really small value)\n", (*P)*polvec);

  printf("\n");
  printf("- k0^{2} = 0 (massless auxuliary vector)\n");
  printf("(k0)^2: %12.6e     (should give really small value)\n", k0.M2());


  printf("\n");
  printf("------------------\n");
  printf("--- Ampltidude ---\n");
  printf("------------------\n");

  printf("\n");
  printf("Amplitude formula chosen: --->  %d  <--- \n", ampltiude);
  printf("\n");

  printf("Amplitude formula list:\n");
  printf("(No):  ---------------------- Formula ---------------------------- (polarization)\n");
  printf("- Default case:                              \n");
  printf(" (0): 128 * (p k') * (q k)                                         (unpolarized)\n");
  printf("(-1):  64 * (p k') * (q k) + 64 * M * (s k') * (q k)               (polarized)\n");
  printf("(+1):  64 * (p k') * (q k) - 64 * M * (s k') * (q k)               (polarized)\n");

  printf("- Custom:                              \n");
  printf(" (+3): 64 * gamma * ( 1 - beta ) *     (M * (k')^{0}) * (q k) -    (polarized)\n");
  printf("      -64 * gamma * ( 1 - beta ) * M *    (s k')      * (q k)                 \n");
  printf(" (+4): 64 * gamma * ( 1 + beta ) *     (M * (k')^{0}) * (q k) +    (polarized)\n");
  printf("      +64 * gamma * ( 1 + beta ) * M *    (s k')      * (q k)                 \n");
  printf("(+34): sum of (+3) and (+4)                                        (unpolarized)\n");

  printf("\n");
  printf("Notations:\n");
  printf("(muon)- ---> (electron)- (nu_mu) (nu_electronbar)\n");
  printf("  p     --->      q        k            k' \n");
  printf("  p     --->      q        k1           k2 \n");
  printf("  P     --->     p1        p2           p3 \n");
  printf("\n");

  printf("Leftover factors multiplying the result:\n");
  printf("- Coupling constant\n");
  printf("  G_Fermi^{2}\n");

  printf("- Initial particle state normalization:\n");
  printf("  1.0/(2*E) = 1.0/2*M (in the rest frame)\n");

  printf("- Spin averaging for the muon (only if unpolarized):\n");
  printf("  1.0/2.0\n");

  printf("\n");
  printf("ThreeBodyDecay class\n");
  printf("PSConstant (formula)  s23_length/pow(M_PI,3.0)/128.0\n");
  printf("PSConstant  (numval): %12.6e \n", PSConst);

  printf("\n");
  printf("---------------------------\n");
  printf("--- Other formulas used ---\n");
  printf("---------------------------\n");

  printf("\n");
  printf("Textbook result of the integration:\n");
  printf("Gamma: G_Fermi^{2}*m_mu^{5}/(192*pi^{3})\n");

  printf("\n");
  printf("tau  = hbar/Gamma\n");
  printf("ctau = c*tau\n");
  
  printf("\n");
  printf("-------------------------\n");
  printf("--- Numerical results ---\n");
  printf("-------------------------\n");

  printf("Don't forget: our result are quoted in the LAB frame, while the PDG and\n");
  printf("              the textbook formula are calculated in the muon rest frame!\n");
  printf("\n");

  printf("# Important flags:\n", ampltiude);
  printf("- k0_type:                    %d (see above at 'Spin polarization', 1 = custom, 2 = physical)\n", k0_flag);
  printf("- spin_polarization:          %d (see above at 'Spin polarization', 1 = computed with k0, 2 = helicity)\n", polvec_flag);
  printf("- Amplitude formula chosen:   %d (see above at 'Amplitude' )\n", ampltiude);
  printf("\n");
  printf("Note: Choosing (k0_type = 2) and (spin_polarization = 1) should give the same result as\n");
  printf("      choosing (spin_polarization = 2) by definition\n");
  printf("\n");

  printf("Gamma(PDG):                             %12.6e [GeV] (note: this is the total gamma!)\n", gamma_PDG);
  printf("Gamma(textbook):                        %12.6e [GeV]\n", gamma_formula);
  printf("Gamma(our result w/o gamma factor):     %12.6e [GeV]\n", result_wogamma);
  printf("Gamma(our result):                      %12.6e [GeV]\n", result);

  printf("\n");
  printf("ctau(PDG):                              %12.6e [m]\n", c_tau_muon*1e-15);
  printf("ctau(textbook):                         %12.6e [m]\n", ctau_formula*1e-15);
  printf("ctau(our result w/o gamma factor):      %12.6e [m]\n", ctau_wogamma);
  printf("ctau(our result):                       %12.6e [m]\n", ctau);
  printf("\n");
  printf("# Muon configuration\n");
  printf("beta:                                                %12.6f\n", P->Beta());
  printf("gamma:                                               %12.6f <-\n", P->Gamma());

  printf("\n");
  printf("# Ratios\n");
  printf("ratio of ctau's: (our result)/(textbook rest frame)  %12.6f <-\n", ctau/ctau_formula/1e-15);
  printf("ratio of the above two values:                       %12.6f\n", P->Gamma()/(ctau/ctau_formula/1e-15));
  printf("\n");
  printf("Note: You should compare the values of 'gamma' with the 'ratio of ctau's',\n");
  printf("      as they should be equal.\n");
  printf("      The 'ratio of the above two values' gives a measure how well they agree.\n");
  printf("      It should be close to unity, but there could be some tiny deviation as\n");
  printf("      this is after all a numerical integration.\n");

  printf("\n");
  printf("VEGAS RESULT:\t%.8f +- %.8f\tp = %.3f\n",
    (double)integral[comp], (double)error[comp], (double)prob[comp]);


  return 0;

}
コード例 #15
0
ファイル: MuMu_Analysis.C プロジェクト: jkiesele/miscStuff
Bool_t MuMu_Analysis::Process(Long64_t entry)
{

  GetAllBranches(entry);


  totalEventCount++;
  double totalevents=9.66875e+06;
  if((int)(100*totalEventCount)%(int)(totalevents) ==0) std::cout << totalEventCount << "\t\tEvents processed \tca. " << (int) totalEventCount/totalevents* 100 << "%" << std::endl;

  TString DataType;  
  DataType="def";
  DataType=(TString)*(dataType->begin());

  bool isData=c_step0.isData(DataType);

 

  bool b_step1=false; 
  bool b_step2=false; 
  bool b_step3=false; 
  bool b_step4=false; 
  bool b_step5=false; 
  bool b_step6=false; 
  bool b_step7=false; 
  bool b_step8=false;
  bool b_step9=false;

  //loop over leptons

  bool rescale=true;

  float isocutmuons = 0.2;//0.3;//0.2; //0.2;  //0.2;//0.2; pf // 0.15 comb
  float isocutelecs = 0.17; //0.3;//0.17;//0.17; //0.17; //0.17;//0.17;
  bool pfIso = true;
  float leptontype = 1; // 1 muon -1 electron
  TString dataset;
  if(leptontype==1) dataset="mumu";
  else dataset = "ee";
  bool oppocharge=true;
  float globalElecEnergyScale=1.0;
  //if(DataType == "ee_200rereco.root" || DataType == "ee_800prompt.root" ) globalElecEnergyScale=1.005; //just play around

  bool probefirst=true;      //SET SWITCH ALSO DOWN IN terminate()!

  float tempiso=100;

  std::vector<float> VLepPt;
  std::vector<float> VLepEta, VLepPhi, VLepE, VLepPx, VLepPy, VLepPz, VLepPfIso, VLepCombIso;
  std::vector<int> VLepQ, VLepType;


  //h_lepMulti0.fill(DataType, (int)lepPt->size(), PUweight);
  
  int CheckCharge=100;
  if(probefirst){
    CheckCharge=*(lepQ->begin());                // take first leading lepton
    VLepPt.push_back(*(lepPt->begin()));
    VLepEta.push_back(*(lepEta->begin()));
    VLepCombIso.push_back(*(lepCombIso->begin()));
    VLepPfIso.push_back(*(lepPfIso->begin()));
    VLepE.push_back(*(lepE->begin()));
    VLepPx.push_back(*(lepPx->begin()));
    VLepPy.push_back(*(lepPy->begin()));
    VLepPz.push_back(*(lepPz->begin()));
    VLepQ.push_back(*(lepQ->begin()));
    VLepType.push_back(*(lepType->begin()));
    VLepPhi.push_back(*(lepPhi->begin()));
    //new
  }

  int k=0;
  for(unsigned int i=0; i<lepPt->size(); i++){ //isocut and chargecut -> builds leptonvectors start with the second leading pt lepton!!!
    if(pfIso) tempiso=*(lepPfIso->begin()+i);
    else tempiso=*(lepCombIso->begin()+i);
    k++;

    if(tempiso < isocutmuons && *(lepType->begin()+i) == 1 && *(lepQ->begin()+i) != CheckCharge){ //
      VLepPt.push_back(*(lepPt->begin()+i));
      VLepEta.push_back(*(lepEta->begin()+i));
      VLepCombIso.push_back(*(lepCombIso->begin()+i));
      VLepPfIso.push_back(*(lepPfIso->begin()+i));
      VLepE.push_back(*(lepE->begin()+i));
      VLepPx.push_back(*(lepPx->begin()+i));
      VLepPy.push_back(*(lepPy->begin()+i));
      VLepPz.push_back(*(lepPz->begin()+i));
      VLepQ.push_back(*(lepQ->begin()+i));
      VLepType.push_back(*(lepType->begin()+i));
      VLepPhi.push_back(*(lepPhi->begin()+i));
      CheckCharge=VLepQ[0]; //new
      break; //new
    }
    else if(tempiso < isocutelecs && *(lepType->begin()+i) == -1 && *(lepQ->begin()+i) != CheckCharge){ //
      VLepPt.push_back(*(lepPt->begin()+i)*globalElecEnergyScale);
      VLepEta.push_back(*(lepEta->begin()+i));
      VLepCombIso.push_back(*(lepCombIso->begin()+i));
      VLepPfIso.push_back(*(lepPfIso->begin()+i));
      VLepE.push_back(*(lepE->begin()+i)*globalElecEnergyScale);
      VLepPx.push_back(*(lepPx->begin()+i)*globalElecEnergyScale);
      VLepPy.push_back(*(lepPy->begin()+i)*globalElecEnergyScale);
      VLepPz.push_back(*(lepPz->begin()+i)*globalElecEnergyScale);
      VLepQ.push_back(*(lepQ->begin()+i));
      VLepType.push_back(*(lepType->begin()+i));
      VLepPhi.push_back(*(lepPhi->begin()+i));
      CheckCharge=VLepQ[0]; //new
      break; //new
    }
    //if(VLepType.size()==1 && oppocharge) CheckCharge=VLepQ[0];
    //else if(VLepType.size()==1 && !oppocharge) CheckCharge= - VLepQ[0];
  }

  //second leading probe lep
  if(!probefirst){
    for(unsigned int i=0; i<lepPt->size(); i++){ //isocut and chargecut -> builds leptonvectors start with the second leading pt lepton!!!
      if(pfIso) tempiso=*(lepPfIso->begin()+i);
      else tempiso=*(lepCombIso->begin()+i);
      k++;

      if( *(lepType->begin()+i) == 1 && *(lepQ->begin()+i) != CheckCharge){ //
	VLepPt.push_back(*(lepPt->begin()+i));
	VLepEta.push_back(*(lepEta->begin()+i));
	VLepCombIso.push_back(*(lepCombIso->begin()+i));
	VLepPfIso.push_back(*(lepPfIso->begin()+i));
	VLepE.push_back(*(lepE->begin()+i));
	VLepPx.push_back(*(lepPx->begin()+i));
	VLepPy.push_back(*(lepPy->begin()+i));
	VLepPz.push_back(*(lepPz->begin()+i));
	VLepQ.push_back(*(lepQ->begin()+i));
	VLepType.push_back(*(lepType->begin()+i));
	VLepPhi.push_back(*(lepPhi->begin()+i));
	break; //new
      }
      else if( *(lepType->begin()+i) == -1 && *(lepQ->begin()+i) != CheckCharge){ //
	VLepPt.push_back(*(lepPt->begin()+i)*globalElecEnergyScale);
	VLepEta.push_back(*(lepEta->begin()+i));
	VLepCombIso.push_back(*(lepCombIso->begin()+i));
	VLepPfIso.push_back(*(lepPfIso->begin()+i));
	VLepE.push_back(*(lepE->begin()+i)*globalElecEnergyScale);
	VLepPx.push_back(*(lepPx->begin()+i)*globalElecEnergyScale);
	VLepPy.push_back(*(lepPy->begin()+i)*globalElecEnergyScale);
	VLepPz.push_back(*(lepPz->begin()+i)*globalElecEnergyScale);
	VLepQ.push_back(*(lepQ->begin()+i));
	VLepType.push_back(*(lepType->begin()+i));
	VLepPhi.push_back(*(lepPhi->begin()+i));
	break; //new
      }
    }

  }




  double dimass=-1;

  if(VLepPt.size() > 1){  //two isolated leptons create dimass out of highest pt pair

    TLorentzVector diLepVector = TLorentzVector(VLepPx[0] + VLepPx[1], VLepPy[0] + VLepPy[1], VLepPz[0] + VLepPz[1], VLepE[0] + VLepE[1]);

    dimass=diLepVector.M();

    b_step1=true;
    testcounter++;
      
    if(VLepType[0] == leptontype &&  VLepType[1] == leptontype) b_step2=true;
    if(dimass > 12)                     b_step3=true;
    if((dimass < 76.0 || dimass > 106.0))     b_step4=true; //dimass > 50 && 
    if(jetMulti>0)                      b_step5=true;
    if(jetMulti>1)                      b_step6=true;
    if(*(metEt->begin()) > 30)          b_step7=true;

  }

  if(b_step1 && b_step2 && b_step3 && !b_step4 && b_step6){     // select Z peak

    int lepno;
    if(probefirst) lepno=0;
    else lepno=1;

    if(isData) IsoStudiesData0->Fill(VLepPt[lepno]);      // Fill histo pt dependent with first lepton
    if(DataType== dataset+"_dy"+dataset+"50inf.root") IsoStudiesZMC0->Fill(VLepPt[lepno]); 
    if(DataType== dataset+"_ttbarsignal.root" || DataType== dataset+" _ttbarviatau.root")   IsoStudiesttMC0->Fill(VLepPt[lepno]);         //Fill pt dep for Z MC



    if(VLepPfIso[lepno]<isocutmuons){ //new
      if(isData) IsoStudiesData1->Fill(VLepPt[lepno]);
      if(DataType== dataset+"_dy"+dataset+"50inf.root") IsoStudiesZMC1->Fill(VLepPt[lepno]);  
    if(DataType== dataset+"_ttbarsignal.root" || DataType== dataset+" _ttbarviatau.root")   IsoStudiesttMC1->Fill(VLepPt[lepno]);
       
    }

  }



  double btagWPM=3.3;
  double btagWP=1.7;
  int btagmultiM=0;
  int btagmulti=0;

  for(std::vector<double>::const_iterator ajetTCHE = jetBTagTCHE->begin(); ajetTCHE < jetBTagTCHE->end(); ajetTCHE++){
    if(*ajetTCHE > btagWPM) btagmultiM++;
    if(*ajetTCHE > btagWP) btagmulti++;
  }

  if(btagmulti > 0) b_step8=true;
  if(btagmultiM > 0) b_step9=true;







return kTRUE;
}
コード例 #16
0
Int_t MakeDeltappHists(TString str_infile, TString str_outfile) {
	TFile* f_in = new TFile(str_infile);
	TTree* t_in = (TTree*)f_in->FindObjectAny("pipl_pim_Tree");
	
	Double_t PiPlus_px;  t_in->SetBranchAddress("PiPlus_px",&PiPlus_px);
	Double_t PiPlus_py;  t_in->SetBranchAddress("PiPlus_py",&PiPlus_py);
	Double_t PiPlus_pz;  t_in->SetBranchAddress("PiPlus_pz",&PiPlus_pz);
	Double_t PiPlus_E;   t_in->SetBranchAddress("PiPlus_E",&PiPlus_E);
	Double_t PiMinus_px; t_in->SetBranchAddress("PiMinus_px",&PiMinus_px);
	Double_t PiMinus_py; t_in->SetBranchAddress("PiMinus_py",&PiMinus_py);
	Double_t PiMinus_pz; t_in->SetBranchAddress("PiMinus_pz",&PiMinus_pz);
	Double_t PiMinus_E;  t_in->SetBranchAddress("PiMinus_E",&PiMinus_E);
	Double_t Proton_px;  t_in->SetBranchAddress("Proton_px",&Proton_px);
	Double_t Proton_py;  t_in->SetBranchAddress("Proton_py",&Proton_py);
	Double_t Proton_pz;  t_in->SetBranchAddress("Proton_pz",&Proton_pz);
	Double_t Proton_E;   t_in->SetBranchAddress("Proton_E",&Proton_E);
	Double_t pipl_pim_m; t_in->SetBranchAddress("pipl_pim_m",&pipl_pim_m);
	Int_t is_perp;       t_in->SetBranchAddress("is_perp",&is_perp);
	Int_t is_para;       t_in->SetBranchAddress("is_para",&is_para);
	Int_t is_45;         t_in->SetBranchAddress("is_45",&is_45);
	Int_t is_135;        t_in->SetBranchAddress("is_135",&is_135);
	Int_t is_amo;        t_in->SetBranchAddress("is_amo",&is_amo);
	Double_t rf_deltaT;  t_in->SetBranchAddress("rf_deltaT",&rf_deltaT);
	Double_t beamE;      t_in->SetBranchAddress("beamE",&beamE);
	Double_t kinfit_CL;  t_in->SetBranchAddress("kinfit_CL",&kinfit_CL);
	Double_t MM2;        t_in->SetBranchAddress("MM2",&MM2);
	Int_t Run;           t_in->SetBranchAddress("Run",&Run);
	Int_t Event;         t_in->SetBranchAddress("Event",&Event);
	
	TH1F* h_massdist_intime = new TH1F("h_massdist_intime","Pi^{+} Proton Mass Spectrum",NBINS_INVMASS,1.,4.5);
	TH1F* h_massdist_outoftime = new TH1F("h_massdist_outoftime","Pi^{+} Proton Mass Spectrum",NBINS_INVMASS,1.,4.5);
	TH1F* h_massdist_accidsub = new TH1F("h_massdist_accidsub","Pi^{+} Proton Mass Spectrum",NBINS_INVMASS,1.,4.5);

    TH2F* h_proton_p_theta_intime = new TH2F("h_proton_p_theta_intime","Proton Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);
    TH2F* h_proton_p_theta_outoftime = new TH2F("h_proton_p_theta_outoftime","Proton Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);
    TH2F* h_proton_p_theta_accidsub = new TH2F("h_proton_p_theta_accidsub","Proton Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);

    TH2F* h_pip_p_theta_intime = new TH2F("h_pip_p_theta_intime","Pi^{+} Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);
    TH2F* h_pip_p_theta_outoftime = new TH2F("h_pip_p_theta_outoftime","Pi^{+} Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);
    TH2F* h_pip_p_theta_accidsub = new TH2F("h_pip_p_theta_accidsub","Pi^{+} Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);
	
    TH2F* h_pim_p_theta_intime = new TH2F("h_pim_p_theta_intime","Pi^{-} Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);
    TH2F* h_pim_p_theta_outoftime = new TH2F("h_pim_p_theta_outoftime","Pi^{-} Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);
    TH2F* h_pim_p_theta_accidsub = new TH2F("h_pim_p_theta_accidsub","Pi^{-} Momentum v. Theta; #theta (degress); p (GeV/c)", 70, 0, 140, 50, 0, 10);

	
	Long64_t nentries = t_in->GetEntries();
	cout << "Number of entries to get through: " << nentries << endl;
	for(size_t i =0; i<nentries; ++i) {
		t_in->GetEntry(i);
		if(i%100000==0) cout << "i: " << i << endl;
	
		TLorentzVector p4_PiPlus = TLorentzVector(PiPlus_px,PiPlus_py,PiPlus_pz,PiPlus_E);
		TLorentzVector p4_PiMinus = TLorentzVector(PiMinus_px,PiMinus_py,PiMinus_pz,PiMinus_E);
		TLorentzVector p4_Proton = TLorentzVector(Proton_px,Proton_py,Proton_pz,Proton_E);
	
		Double_t pipl_pim_mass = (p4_PiPlus+p4_PiMinus).M();
		Double_t pipl_proton_mass = (p4_PiPlus+p4_Proton).M();
	
		//All cuts applied here
		if(pipl_pim_mass<PIPL_PIM_M_CUT_LO_HISTOGRAMMING) continue;
		if(pipl_pim_mass>PIPL_PIM_M_CUT_HI_HISTOGRAMMING) continue;
	
		if(fabs(rf_deltaT)<RF_PERIOD*0.5) {
			h_massdist_intime->Fill(pipl_proton_mass);
            if(pipl_proton_mass < 1.3) {
                h_proton_p_theta_intime->Fill(p4_Proton.Vect().Theta()*180./TMath::Pi(), p4_Proton.Vect().Mag());
                h_pip_p_theta_intime->Fill(p4_PiPlus.Vect().Theta()*180./TMath::Pi(), p4_PiPlus.Vect().Mag());
                h_pim_p_theta_intime->Fill(p4_PiMinus.Vect().Theta()*180./TMath::Pi(), p4_PiMinus.Vect().Mag());
            }
		}
		if(fabs(rf_deltaT)>RF_PERIOD*0.5) {
			h_massdist_outoftime->Fill(pipl_proton_mass);
            if(pipl_proton_mass < 1.3) {
                h_proton_p_theta_outoftime->Fill(p4_Proton.Vect().Theta()*180./TMath::Pi(), p4_Proton.Vect().Mag());
                h_pip_p_theta_outoftime->Fill(p4_PiPlus.Vect().Theta()*180./TMath::Pi(), p4_PiPlus.Vect().Mag());
                h_pim_p_theta_outoftime->Fill(p4_PiMinus.Vect().Theta()*180./TMath::Pi(), p4_PiMinus.Vect().Mag());
            }
		}
	
	}
	
	//Accidental subtraction
	h_massdist_intime->Sumw2();
	h_massdist_outoftime->Sumw2();
	Double_t Delta_t_scalefactor = 1. / (2*NBEAM_BUNCHES_HISTOGRAMMING);
	h_massdist_accidsub->Add(h_massdist_intime,h_massdist_outoftime,1,-1.*Delta_t_scalefactor);	
    h_massdist_accidsub->Rebin(5);

	h_massdist_accidsub->GetXaxis()->SetTitle("#pi^{+} proton inv. mass (GeV)");
	h_massdist_accidsub->GetYaxis()->SetTitle("Counts");
	
    h_proton_p_theta_intime->Sumw2();
    h_proton_p_theta_outoftime->Sumw2();
    h_proton_p_theta_accidsub->Add(h_proton_p_theta_intime,h_proton_p_theta_outoftime,1,-1.*Delta_t_scalefactor);
    h_pip_p_theta_intime->Sumw2();
    h_pip_p_theta_outoftime->Sumw2();
    h_pip_p_theta_accidsub->Add(h_pip_p_theta_intime,h_pip_p_theta_outoftime,1,-1.*Delta_t_scalefactor);
    h_pim_p_theta_intime->Sumw2();
    h_pim_p_theta_outoftime->Sumw2();
    h_pim_p_theta_accidsub->Add(h_pim_p_theta_intime,h_pim_p_theta_outoftime,1,-1.*Delta_t_scalefactor);

	TFile* outfile = new TFile( str_outfile, "RECREATE" );
	outfile->cd();
	h_massdist_intime->Write();
	h_massdist_outoftime->Write();
	h_massdist_accidsub->Write();
    h_proton_p_theta_intime->Write();
    h_proton_p_theta_outoftime->Write();
    h_proton_p_theta_accidsub->Write();
    h_pip_p_theta_intime->Write();
    h_pip_p_theta_outoftime->Write();
    h_pip_p_theta_accidsub->Write();
    h_pim_p_theta_intime->Write();
    h_pim_p_theta_outoftime->Write();
    h_pim_p_theta_accidsub->Write();
	outfile->Close();
	
	cout << "Done with histogram generation" << endl;
	
	return 0;
}
コード例 #17
0
ファイル: GrowTree.C プロジェクト: swang373/VHbbUF
// Copied from http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/TopQuarkAnalysis/SingleTop/src/TopProducer.cc?revision=1.9&view=markup
TLorentzVector getNu4Momentum(const TLorentzVector& TLepton, const TLorentzVector& TMET)
{
  const math::XYZTLorentzVector Lepton(TLepton.Px(), TLepton.Py(), TLepton.Pz(), TLepton.E());
  const math::XYZTLorentzVector MET(TMET.Px(), TMET.Py(), 0., TMET.E());

  double  mW = 80.38;

  //std::vector<math::XYZTLorentzVector> result;
  std::vector<TLorentzVector> result;

  //  double Wmt = sqrt(pow(Lepton.et()+MET.pt(),2) - pow(Lepton.px()+MET.px(),2) - pow(Lepton.py()+MET.py(),2) );
    
  double MisET2 = (MET.px()*MET.px() + MET.py()*MET.py());
  double mu = (mW*mW)/2 + MET.px()*Lepton.px() + MET.py()*Lepton.py();
  double a  = (mu*Lepton.pz())/(Lepton.energy()*Lepton.energy() - Lepton.pz()*Lepton.pz());
  double a2 = TMath::Power(a,2);
  double b  = (TMath::Power(Lepton.energy(),2.)*(MisET2) - TMath::Power(mu,2.))/(TMath::Power(Lepton.energy(),2) - TMath::Power(Lepton.pz(),2));
  double pz1(0),pz2(0),pznu(0);
  int nNuSol(0);

  //math::XYZTLorentzVector p4nu_rec;
  TLorentzVector p4nu_rec;
  math::XYZTLorentzVector p4W_rec;
  math::XYZTLorentzVector p4b_rec;
  math::XYZTLorentzVector p4Top_rec;
  math::XYZTLorentzVector p4lep_rec;

  p4lep_rec.SetPxPyPzE(Lepton.px(),Lepton.py(),Lepton.pz(),Lepton.energy());
  
  //math::XYZTLorentzVector p40_rec(0,0,0,0);

  if(a2-b > 0 ){
    //if(!usePositiveDeltaSolutions_)
    //  {
    //    result.push_back(p40_rec);
    //    return result;
    //  }
    double root = sqrt(a2-b);
    pz1 = a + root;
    pz2 = a - root;
    nNuSol = 2;

    //if(usePzPlusSolutions_)pznu = pz1;    
    //if(usePzMinusSolutions_)pznu = pz2;
    //if(usePzAbsValMinimumSolutions_){
      pznu = pz1;
      if(fabs(pz1)>fabs(pz2)) pznu = pz2;
    //}

    double Enu = sqrt(MisET2 + pznu*pznu);

    p4nu_rec.SetPxPyPzE(MET.px(), MET.py(), pznu, Enu);

    result.push_back(p4nu_rec);

  }
  else{
    //if(!useNegativeDeltaSolutions_){
    //  result.push_back(p40_rec);
    //  return result;
    //}
    //    double xprime = sqrt(mW;

    double ptlep = Lepton.pt(),pxlep=Lepton.px(),pylep=Lepton.py(),metpx=MET.px(),metpy=MET.py();

    double EquationA = 1;
    double EquationB = -3*pylep*mW/(ptlep);
    double EquationC = mW*mW*(2*pylep*pylep)/(ptlep*ptlep)+mW*mW-4*pxlep*pxlep*pxlep*metpx/(ptlep*ptlep)-4*pxlep*pxlep*pylep*metpy/(ptlep*ptlep);
    double EquationD = 4*pxlep*pxlep*mW*metpy/(ptlep)-pylep*mW*mW*mW/ptlep;

    std::vector<long double> solutions = EquationSolve<long double>((long double)EquationA,(long double)EquationB,(long double)EquationC,(long double)EquationD);

    std::vector<long double> solutions2 = EquationSolve<long double>((long double)EquationA,-(long double)EquationB,(long double)EquationC,-(long double)EquationD);

    double deltaMin = 14000*14000;
    double zeroValue = -mW*mW/(4*pxlep); 
    double minPx=0;
    double minPy=0;

    //    std::cout<<"a "<<EquationA << " b " << EquationB  <<" c "<< EquationC <<" d "<< EquationD << std::endl; 
      
    //if(usePxMinusSolutions_){
      for( int i =0; i< (int)solutions.size();++i){
      if(solutions[i]<0 ) continue;
      double p_x = (solutions[i]*solutions[i]-mW*mW)/(4*pxlep); 
      double p_y = ( mW*mW*pylep + 2*pxlep*pylep*p_x -mW*ptlep*solutions[i])/(2*pxlep*pxlep);
      double Delta2 = (p_x-metpx)*(p_x-metpx)+(p_y-metpy)*(p_y-metpy); 

      //      std::cout<<"intermediate solution1 met x "<<metpx << " min px " << p_x  <<" met y "<<metpy <<" min py "<< p_y << std::endl; 

      if(Delta2< deltaMin && Delta2 > 0){deltaMin = Delta2;
      minPx=p_x;
      minPy=p_y;}
      //     std::cout<<"solution1 met x "<<metpx << " min px " << minPx  <<" met y "<<metpy <<" min py "<< minPy << std::endl; 
      }
    //}

    //if(usePxPlusSolutions_){
      for( int i =0; i< (int)solutions2.size();++i){
        if(solutions2[i]<0 ) continue;
        double p_x = (solutions2[i]*solutions2[i]-mW*mW)/(4*pxlep); 
        double p_y = ( mW*mW*pylep + 2*pxlep*pylep*p_x +mW*ptlep*solutions2[i])/(2*pxlep*pxlep);
        double Delta2 = (p_x-metpx)*(p_x-metpx)+(p_y-metpy)*(p_y-metpy); 
        //  std::cout<<"intermediate solution2 met x "<<metpx << " min px " << minPx  <<" met y "<<metpy <<" min py "<< minPy << std::endl; 
        if(Delta2< deltaMin && Delta2 > 0){deltaMin = Delta2;
          minPx=p_x;
          minPy=p_y;
        }
        //        std::cout<<"solution2 met x "<<metpx << " min px " << minPx  <<" met y "<<metpy <<" min py "<< minPy << std::endl; 
      }
    //}

    double pyZeroValue= ( mW*mW*pxlep + 2*pxlep*pylep*zeroValue);
    double delta2ZeroValue= (zeroValue-metpx)*(zeroValue-metpx) + (pyZeroValue-metpy)*(pyZeroValue-metpy);

    if(deltaMin==14000*14000) return TLorentzVector(0,0,0,0);
    //if(deltaMin==14000*14000) return result.front();
    //    else std::cout << " test " << std::endl;

    if(delta2ZeroValue < deltaMin){
      deltaMin = delta2ZeroValue;
      minPx=zeroValue;
      minPy=pyZeroValue;}

    //    std::cout<<" MtW2 from min py and min px "<< sqrt((minPy*minPy+minPx*minPx))*ptlep*2 -2*(pxlep*minPx + pylep*minPy)  <<std::endl;
    ///    ////Y part   

    double mu_Minimum = (mW*mW)/2 + minPx*pxlep + minPy*pylep;
    double a_Minimum  = (mu_Minimum*Lepton.pz())/(Lepton.energy()*Lepton.energy() - Lepton.pz()*Lepton.pz());
    pznu = a_Minimum;

    //if(!useMetForNegativeSolutions_){
      double Enu = sqrt(minPx*minPx+minPy*minPy + pznu*pznu);
      p4nu_rec.SetPxPyPzE(minPx, minPy, pznu , Enu);
    //}
    //else{
    //  pznu = a;
    //  double Enu = sqrt(metpx*metpx+metpy*metpy + pznu*pznu);
    //  p4nu_rec.SetPxPyPzE(metpx, metpy, pznu , Enu);
    //}
    result.push_back(p4nu_rec);
  }
  return result.front();
}
コード例 #18
0
ファイル: NeroMet.cpp プロジェクト: BradBachu/NeroProducer-1
int NeroMet::analyze(const edm::Event& iEvent){

    if ( mOnlyMc  ) return 0; // in principle I would like to have the gen met: TODO

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);
    const pat::MET &met = handle->front();

    // FILL
    new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector( met.px(),met.py(),met.pz(),met.energy()  );

    ptJESUP -> push_back( met.shiftedPt(pat::MET::JetEnUp) );
    ptJESDOWN -> push_back( met.shiftedPt(pat::MET::JetEnDown) );


    if (IsExtend())
    {
        //MetNoMu
        TLorentzVector metnomu(met.px(),met.py(),met.pz(),met.energy());
        TLorentzVector pfmet_e3p0(0,0,0,0);
        TLorentzVector chMet(0,0,0,0); 
        TLorentzVector nhMet(0,0,0,0); 
        TLorentzVector phoMet(0,0,0,0); 
        
    
        if ( pf == NULL ) cout<<"[NeroMet]::[analyze]::[ERROR] PF pointer is null. Run NeroPF. "<<endl; 
        
        for (unsigned int i = 0, n = pf->handle->size(); i < n; ++i) {
            const pat::PackedCandidate &cand = (*pf->handle)[i];
            
            // only up to eta 3
            if (std::abs(cand.eta()) < 3.0)
                pfmet_e3p0 += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
            
            if (std::abs(cand.pdgId()) == 13)
                metnomu += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());  
            
            // only charge hadrons
            if ( cand.charge() != 0 and cand.pdgId() > 20 )
                chMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
            if ( cand.charge() == 0 and cand.pdgId() == 22 ) 
                phoMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
            if ( cand.charge() == 0 and cand.pdgId() != 22 ) 
                nhMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
        }
        
        *metNoMu = TLorentzVector(metnomu);    
        *metChargedHadron = TLorentzVector(chMet);
        *metNeutralHadron = TLorentzVector(nhMet);
        *metNeutralEM = TLorentzVector(phoMet);
        *pfMet_e3p0 = TLorentzVector(pfmet_e3p0);
    
    }    
    // GEN INFO
    if ( not iEvent.isRealData () ){
        new ( (*genP4)[genP4->GetEntriesFast()]) TLorentzVector( met.genMET()->px(),met.genMET()->py(),met.genMET()->pz(),met.genMET()->energy()  );
    }


    return 0;
}
コード例 #19
0
ParticleVector::ParticleVector(int type)
{
    this->type = type;
    TLorentzVector();
}
コード例 #20
0
void Select_CC1pip(char const *InpFileName, char const *OupFileName,
                   bool db = false) {
  TFile *inpF = new TFile(InpFileName);

  if (!inpF || !inpF->IsOpen()) {
    std::cerr << "[ERROR]: Could not open input file: " << InpFileName
              << std::endl;
    exit(1);
  }

  TTree *stdhep = static_cast<TTree *>(inpF->Get("giRooTracker"));

  if (!stdhep) {
    std::cerr
        << "[ERROR]: Could not read TTree (\"giRooTracker\") from input file: "
        << InpFileName << std::endl;
    exit(1);
  }

  Double_t EvtWght;
  Int_t GiStdHepN;
  Int_t GiStdHepPdg[100];
  Int_t GiStdHepStatus[100];
  Double_t GiStdHepP4[100][4];

  stdhep->SetBranchAddress("EvtWght", &EvtWght);
  stdhep->SetBranchAddress("StdHepN", &GiStdHepN);
  stdhep->SetBranchAddress("StdHepPdg", GiStdHepPdg);
  stdhep->SetBranchAddress("StdHepP4", GiStdHepP4);
  stdhep->SetBranchAddress("StdHepStatus", GiStdHepStatus);

  TFile *oupF = new TFile(OupFileName, "RECREATE");
  TTree *oupT = new TTree("CC1PipQ2", "");
  Float_t Q2;
  oupT->Branch("Q2", &Q2);
  oupT->Branch("EvtWght", &EvtWght);

  Long64_t nentries = stdhep->GetEntries();
  for (Long64_t evt = 0; evt < nentries; ++evt) {
    stdhep->GetEntry(evt);

    TLorentzVector pnu(0, 0, 0, 0);
    TLorentzVector pmu(0, 0, 0, 0);

    Int_t NPiPlus = 0;
    Int_t NOtherPi = 0;

    if (db) {
      std::cout << "Ev[" << evt << "] ------- " << std::endl;
    }

    // Loop through particle stack
    for (Int_t prt = 0; prt < GiStdHepN; ++prt) {
      // Inital numu
      if ((GiStdHepStatus[prt] == 0) && (GiStdHepPdg[prt] == 14)) {
        pnu = TLorentzVector(GiStdHepP4[prt][0], GiStdHepP4[prt][1],
                             GiStdHepP4[prt][2], GiStdHepP4[prt][3]);
        if (db) {
          std::cout << "\tFound nu at " << prt << " Mom: ("
                    << GiStdHepP4[prt][0] << ", " << GiStdHepP4[prt][1] << ", "
                    << GiStdHepP4[prt][2] << ", " << GiStdHepP4[prt][3] << ") "
                    << std::endl;
        }
      }
      // Final mu
      if ((GiStdHepStatus[prt] == 1) && (GiStdHepPdg[prt] == 13)) {
        pmu = TLorentzVector(GiStdHepP4[prt][0], GiStdHepP4[prt][1],
                             GiStdHepP4[prt][2], GiStdHepP4[prt][3]);
        if (db) {
          std::cout << "\tFound mu at " << prt << " Mom: ("
                    << GiStdHepP4[prt][0] << ", " << GiStdHepP4[prt][1] << ", "
                    << GiStdHepP4[prt][2] << ", " << GiStdHepP4[prt][3] << ") "
                    << std::endl;
        }
      }
      // Final pi+
      if ((GiStdHepStatus[prt] == 1) && (GiStdHepPdg[prt] == 211)) {
        NPiPlus++;
      }
      // Final other pi
      if ((GiStdHepStatus[prt] == 1) &&
          ((GiStdHepPdg[prt] == 111) || (GiStdHepPdg[prt] == -211))) {
        NOtherPi++;
      }
    }
    // cc1pip selection
    if ((NPiPlus == 1) && (NOtherPi == 0) && (pnu.Vect().Mag2() > 0) &&
        (pmu.Vect().Mag2() > 0)) {
      Q2 = -1. * (pnu - pmu).Mag2();
      if (db) {
        std::cout << "Ev[" << evt << "] -- Q2: " << Q2
                  << ", pnu.Mag(): " << pnu.Vect().Mag()
                  << ", pmu.Mag(): " << pmu.Vect().Mag() << std::endl;
      }
      oupT->Fill();
    }
    if (db) {
      std::cout << "====================" << std::endl;
    }
  }
  oupT->Write();
  oupF->Write();
  oupF->Save();
}