Ejemplo n.º 1
0
void KVTenseur3::GetRotation(TRotation & rot)
{
   //Sets rotation matrix corresponding to eigenvectors of diagonalized tensor.
   //According to ROOT physics vectors convention, this is an 'active' rotation
   //(see TRotation class description). Note that KVParticle::SetFrame automatically
   //uses this matrix in such a way as to describe particles in the coordinate frame
   //corresponding to the rotated axes.
   //
   //By convention, the three eigenvectors (V1, V2, V3) are numbered in increasing
   //order of size of the corresponding eigenvalue (V3 <--> largest eignevalue <--> "flow" axis).
   //The new coordinate axes are defined (arbitrarily) as follows :
   //      V1 --->  X' 
   //      V2 --->  Y'
   //      V3 --->  Z'

   //make orthonormal basis vectors from 3 eignevectors
   TVector3 V1 = GetVep(1);
   TVector3 V2 = GetVep(2);
   TVector3 V3 = GetVep(3);
   if (V3.Z() < 0)
      V3 = -V3;
   rot.MakeBasis(V1, V2, V3);
   //set rotation matrix
   rot.SetToIdentity();
   rot.RotateAxes(V1, V2, V3);
}
Ejemplo n.º 2
0
vector<TParticle*> LMCphysGen::GenCerPhotons(TParticle *part, LMCstep *step, Int_t N) {

  const Double_t hbarc = 0.197326960277E-6; //GeV.nm 
  vector <TParticle*> v;
  //rotation matrix to transform vectors from geom -> part
  TRotation rm;
  TVector3 vt(part->Px(), part->Py(), part->Pz());
  rm.RotateX(vt.Theta()); //rotate on X
  rm.RotateZ(vt.Phi()); //rotate on Z
  TVector3 pdir = vt.Unit();
  // rotation matrix from part->geom
  TRotation im = rm.Inverse();
  //generate photons
  Double_t Emin = 2.*TMath::Pi()* hbarc / 200.; //GeV
  Double_t Emax = 2.*TMath::Pi()* hbarc / 700.; //GeV

  TVector3 InitPoint = step->GetInitPoint(); 
  Double_t stepLength = step->GetStepLength();
  for (int i=0; i< N; i++) {
    Double_t thetaCer = step->GetCerAngle();
    Double_t phi = (RandGen->Rndm())*2.*TMath::Pi();  
    TVector3 photonDir(sin(thetaCer)*cos(phi), sin(thetaCer)*sin(phi), cos(thetaCer));
    TVector3 photonDirDet = im*photonDir;                         //transform photon direction from particle to detector frame
    Double_t photonE      = Emin + (RandGen->Rndm())*(Emax-Emin); //cerenkov photon flat on energy (GeV)
    TVector3 photonMomDet = photonE*photonDirDet;                 //on detector frame
    TVector3 GenPoint     = InitPoint + stepLength*(RandGen->Rndm())*pdir;
    v.push_back(new TParticle(22,0,0,0,0,0,photonMomDet.X(),photonMomDet.Y(),photonMomDet.Z(),photonE,GenPoint.X(),GenPoint.Y(),GenPoint.Z(),0));
  }

  return v;

}
Ejemplo n.º 3
0
void polGen(double rapdilepton_min = 1,
		double rapdilepton_max = 1,
		double pTdilepton_min = 1,
		double pTdilepton_max = 1,
		double mass_signal_peak  =  1,
		double mass_signal_sigma =  1,
		double n_sigmas_signal = 1,
		int n_events = 50000,
		double f_BG = 0.5,
		double lambda_theta_sig=1,
		double lambda_phi_sig=1,
		double lambda_thetaphi_sig=1,
		double lambda_theta_bkg=1,
		double lambda_phi_bkg=1,
		double lambda_thetaphi_bkg=1,
		int frameSig=1,//CS...1, HX...2, PX...3
		int frameBkg=1,//CS...1, HX...2, PX...3
		int nGen=1,
		Char_t *dirstruct = "ToyDirectory_Default"
){

	char frameSigName[200];
	if(frameSig==1)sprintf(frameSigName,"CS");
	if(frameSig==2)sprintf(frameSigName,"HX");
	if(frameSig==3)sprintf(frameSigName,"PX");
	char frameBkgName[200];
	if(frameBkg==1)sprintf(frameBkgName,"CS");
	if(frameBkg==2)sprintf(frameBkgName,"HX");
	if(frameBkg==3)sprintf(frameBkgName,"PX");


	if(frameSig==2) HX_is_natural_sig=true; if(frameSig==3) PX_is_natural_sig=true; //else CS is the natural frame by default
	if(frameBkg==2) HX_is_natural_bkg=true; if(frameBkg==3) PX_is_natural_bkg=true; //else CS is the natural frame by default

	cout<<"Number of Events to be generated ........... "<<n_events<<endl;
	cout<<"pT min ..................................... "<<pTdilepton_min<<endl;
	cout<<"pT max ..................................... "<<pTdilepton_max<<endl;
	cout<<"Rapidity min ............................... "<<rapdilepton_min<<endl;
	cout<<"Rapidity max ............................... "<<rapdilepton_max<<endl;
	cout<<"Background Fraction ........................ "<<f_BG<<endl;
	cout<<"Injected lambda_theta Signal ............... "<<lambda_theta_sig<<" , in the "<<frameSigName<<" frame"<<endl;
	cout<<"Injected lambda_phi Signal ................. "<<lambda_phi_sig<<" , in the "<<frameSigName<<" frame"<<endl;
	cout<<"Injected lambda_thetaphi Signal ............ "<<lambda_thetaphi_sig<<" , in the "<<frameSigName<<" frame"<<endl;
	cout<<"Injected lambda_theta Background............ "<<lambda_theta_bkg<<" , in the "<<frameBkgName<<" frame"<<endl;
	cout<<"Injected lambda_phi Background ............. "<<lambda_phi_bkg<<" , in the "<<frameBkgName<<" frame"<<endl;
	cout<<"Injected lambda_thetaphi Background ........ "<<lambda_thetaphi_bkg<<" , in the "<<frameBkgName<<" frame"<<endl;
	cout<<"Number of Generation ....................... "<<nGen<<endl;
	cout<<"Directory Structure of Output .............. "<<dirstruct<<endl;


	double mass_min = mass_signal_peak - n_sigmas_signal*mass_signal_sigma;
	double mass_max = mass_signal_peak + n_sigmas_signal*mass_signal_sigma;

	char outfilename [500];
	sprintf(outfilename,"%s/genData.root",dirstruct);

  gROOT->Reset();

  delete gRandom;
  gRandom = new TRandom3(0);

  TF1* pT_distr = new TF1("pT_distr",func_pT_gen,pTdilepton_min,pTdilepton_max,0);
  TF1* rap_distr = new TF1("rap_distr",func_rap_gen,rapdilepton_min,rapdilepton_max,0);

  TFile* hfileout = new TFile(outfilename, "RECREATE", "genData");
  TTree* genData = new TTree("genData","genData");

  // Structure of output ntuple

  TLorentzVector* lepP = new TLorentzVector(0.,0.,0.,0.);
  genData->Branch("lepP","TLorentzVector",&lepP);
  TLorentzVector* lepN = new TLorentzVector(0.,0.,0.,0.);
  genData->Branch("lepN","TLorentzVector",&lepN);

  double costh_CS;  genData->Branch("costh_CS",     &costh_CS,     "costh_CS/D");
  double phi_CS;    genData->Branch("phi_CS",       &phi_CS,       "phi_CS/D"  );
  double phith_CS;  genData->Branch("phith_CS",     &phith_CS,     "phith_CS/D");

  double costh_HX;  genData->Branch("costh_HX",     &costh_HX,     "costh_HX/D");
  double phi_HX;    genData->Branch("phi_HX",       &phi_HX,       "phi_HX/D"  );
  double phith_HX;  genData->Branch("phith_HX",     &phith_HX,     "phith_HX/D");

  double costh_PX;  genData->Branch("costh_PX",     &costh_PX,     "costh_PX/D");
  double phi_PX;    genData->Branch("phi_PX",       &phi_PX,       "phi_PX/D"  );
  double phith_PX;  genData->Branch("phith_PX",     &phith_PX,     "phith_PX/D");

  double cosalpha;  genData->Branch("cosalpha",     &cosalpha,     "cosalpha/D");

  double pT;        genData->Branch("pT",           &pT,           "pT/D"  );
  double rap;       genData->Branch("rap",          &rap,          "rap/D" );
  double mass;      genData->Branch("mass",         &mass,         "mass/D");

  double deltaHXCS; genData->Branch("deltaHXCS",    &deltaHXCS,    "deltaHXCS/D");

  int isBG;         genData->Branch("isBG",         &isBG,         "isBG/I");


  // extremes and binning of lambda_gen extraction histos
  const double l_min = -1;
  const double l_max =  1;
  const double l_step_1D = 0.02;


  TH1D* h_costh2_CS = new TH1D( "h_costh2_CS", "", int((l_max-l_min)/l_step_1D), l_min, l_max );
  TH1D* h_cos2ph_CS = new TH1D( "h_cos2ph_CS", "", int((l_max-l_min)/l_step_1D), l_min, l_max );
  TH1D* h_sin2thcosph_CS = new TH1D( "h_sin2thcosph_CS", "", int((l_max-l_min)/l_step_1D), l_min, l_max );

  TH1D* h_costh2_HX = new TH1D( "h_costh2_HX", "", int((l_max-l_min)/l_step_1D), l_min, l_max );
  TH1D* h_cos2ph_HX = new TH1D( "h_cos2ph_HX", "", int((l_max-l_min)/l_step_1D), l_min, l_max );
  TH1D* h_sin2thcosph_HX = new TH1D( "h_sin2thcosph_HX", "", int((l_max-l_min)/l_step_1D), l_min, l_max );

  TH1D* h_costh2_PX = new TH1D( "h_costh2_PX", "", int((l_max-l_min)/l_step_1D), l_min, l_max );
  TH1D* h_cos2ph_PX = new TH1D( "h_cos2ph_PX", "", int((l_max-l_min)/l_step_1D), l_min, l_max );
  TH1D* h_sin2thcosph_PX = new TH1D( "h_sin2thcosph_PX", "", int((l_max-l_min)/l_step_1D), l_min, l_max );

  double costh2;
  double cos2ph;
  double sin2thcosph;
  double Phi;

  const int n_step = n_events/5;
  int n_step_=1;


  cout << endl;
  cout << "Generating " << n_events << " dilepton events"<< endl;
  cout << "------------------------------------------------------------" << endl;
  cout << "Progress: "<<endl;



/////////////////// CYCLE OF EVENTS ////////////////////////
  for(int i_event = 1; i_event <= n_events; i_event++){

	    if (i_event%n_step == 0) {cout << n_step_*20 <<" % "<<endl; n_step_++;}

	    // generation of dilepton in the pp event in the pp CM

    // mass

    isBG = 0;

    if ( gRandom->Uniform() < f_BG ) { mass = gRandom->Uniform(mass_min, mass_max); isBG = 1; }
                                        else { do { mass = gRandom->Gaus(mass_signal_peak, mass_signal_sigma); }
                                               while ( mass < mass_min || mass > mass_max ); }

    // pT:

    pT = pT_distr->GetRandom();

    // pL:

    double rap_sign = gRandom->Uniform(-1., 1.); rap_sign /= TMath::Abs(rap_sign);
    rap = rap_distr->GetRandom() * rap_sign;
    double mT = sqrt( mass*mass + pT*pT );
    double pL1 = 0.5 *mT * exp(rap);
    double pL2 = - 0.5 *mT * exp(-rap);
    double pL = pL1 + pL2;

    // Phi:

    double Phi = 2. * gPI * gRandom->Uniform(1.);

    // 4-vector:

    TLorentzVector dilepton;
    dilepton.SetXYZM( pT * cos(Phi) , pT * sin(Phi), pL, mass );


    // generation of polarization (generic reference frame)

    double lambda_theta    = lambda_theta_sig;
    double lambda_phi      = lambda_phi_sig;
    double lambda_thetaphi = lambda_thetaphi_sig;
    bool HX_is_natural = HX_is_natural_sig;
    bool PX_is_natural = PX_is_natural_sig;

    if ( isBG ) {
       lambda_theta    = lambda_theta_bkg;
       lambda_phi      = lambda_phi_bkg;
       lambda_thetaphi = lambda_thetaphi_bkg;
       HX_is_natural = HX_is_natural_bkg;
       PX_is_natural = PX_is_natural_bkg;
    }


    double costhphidistr_max = 1. + TMath::Abs(lambda_phi) + TMath::Abs(lambda_thetaphi);
    double costhphidistr_rnd;
    double costhphidistr;
    double costh_gen;
    double sinth_gen;
    double phi_gen;

    if ( lambda_theta > 0. ) costhphidistr_max += lambda_theta;

    do { costh_gen = -1. + 2. * gRandom->Uniform(1.);
         phi_gen   = 2. * gPI * gRandom->Uniform(1.);
         sinth_gen = sqrt( 1. - costh_gen*costh_gen );
         costhphidistr_rnd = costhphidistr_max * gRandom->Uniform(1.);
         costhphidistr = 1. + lambda_theta    * costh_gen*costh_gen
                            + lambda_phi      * sinth_gen*sinth_gen * cos(2.*phi_gen)
                            + lambda_thetaphi * 2.* sinth_gen*costh_gen * cos(phi_gen);
       } while ( costhphidistr_rnd > costhphidistr );


    // lepton momentum in the dilepton rest frame:

    double p_lepton_DILEP = sqrt( 0.25*mass*mass - Mlepton*Mlepton );

    TLorentzVector lepton_DILEP;

    lepton_DILEP.SetXYZM( p_lepton_DILEP * sinth_gen * cos(phi_gen),
                          p_lepton_DILEP * sinth_gen * sin(phi_gen),
                          p_lepton_DILEP * costh_gen,
                          Mlepton );


    // reference directions to calculate angles:

    TVector3 lab_to_dilep = -dilepton.BoostVector();

    TLorentzVector beam1_DILEP = beam1_LAB;
    beam1_DILEP.Boost(lab_to_dilep);         // beam1 in the dilepton rest frame
    TLorentzVector beam2_DILEP = beam2_LAB;
    beam2_DILEP.Boost(lab_to_dilep);         // beam2 in the dilepton rest frame

    TVector3 beam1_direction     = beam1_DILEP.Vect().Unit();
    TVector3 beam2_direction     = beam2_DILEP.Vect().Unit();
    TVector3 dilep_direction     = dilepton.Vect().Unit();
    TVector3 beam1_beam2_bisect  = ( beam1_direction - beam2_direction ).Unit();


    deltaHXCS = dilep_direction.Angle(beam1_beam2_bisect) * 180./gPI;

    // all polarization frames have the same Y axis = the normal to the plane formed by
    // the directions of the colliding hadrons

    TVector3 Yaxis = ( beam1_direction.Cross( beam2_direction ) ).Unit();

    // flip of y axis with rapidity

    if ( rap < 0 ) Yaxis = - Yaxis;

    TVector3 perpendicular_to_beam = ( beam1_beam2_bisect.Cross( Yaxis ) ).Unit();


    // step 1: transform (rotation) lepton momentum components from generation frame
    // to the frame with x,y,z axes as in the laboratory

    TVector3 oldZaxis = beam1_beam2_bisect;
    if ( HX_is_natural ) oldZaxis = dilep_direction;
    if ( PX_is_natural ) oldZaxis = perpendicular_to_beam;

    TVector3 oldYaxis = Yaxis;
    TVector3 oldXaxis = oldYaxis.Cross(oldZaxis);

    TRotation rotation;
    rotation.RotateAxes(oldXaxis, oldYaxis, oldZaxis);
                     // transforms coordinates from the "old" frame to the "xyz" frame

    TLorentzVector lepton_DILEP_xyz = lepton_DILEP;

    lepton_DILEP_xyz.Transform(rotation);
                     // lepton_DILEP_xyz is the lepton in the dilepton rest frame
                     // wrt to the lab axes

    // lepton 4-vectors in the LAB frame:

    TVector3 dilep_to_lab = dilepton.BoostVector();

    *lepP = lepton_DILEP_xyz;
    lepP->Boost(dilep_to_lab);
    lepN->SetPxPyPzE(-lepton_DILEP_xyz.Px(),-lepton_DILEP_xyz.Py(),-lepton_DILEP_xyz.Pz(),lepton_DILEP_xyz.E());
    lepN->Boost(dilep_to_lab);


    /////////////////////////////////////////////////////////////////////
    // CS frame


    TVector3 newZaxis = beam1_beam2_bisect;
    TVector3 newYaxis = Yaxis;
    TVector3 newXaxis = newYaxis.Cross( newZaxis );

    rotation.SetToIdentity();
    rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
    rotation.Invert();  // transforms coordinates from the "xyz" frame to the new frame

    TVector3 lepton_DILEP_rotated = lepton_DILEP_xyz.Vect();

    lepton_DILEP_rotated.Transform(rotation);

    costh_CS = lepton_DILEP_rotated.CosTheta();

    phi_CS = lepton_DILEP_rotated.Phi() * 180. / gPI;

    if ( costh_CS < 0. ) phith_CS = phi_CS - 135.;
    if ( costh_CS > 0. ) phith_CS = phi_CS - 45.;

    if ( phith_CS < -180. ) phith_CS = 360. + phith_CS;


    /////////////////////////////////////////////////////////////////////
    // HELICITY frame

    newZaxis = dilep_direction;
    newYaxis = Yaxis;
    newXaxis = newYaxis.Cross( newZaxis );

    rotation.SetToIdentity();
    rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
    rotation.Invert();

    lepton_DILEP_rotated = lepton_DILEP_xyz.Vect();

    lepton_DILEP_rotated.Transform(rotation);

    costh_HX = lepton_DILEP_rotated.CosTheta();

    phi_HX = lepton_DILEP_rotated.Phi() * 180. / gPI;

    if ( costh_HX < 0. ) phith_HX = phi_HX - 135.;
    if ( costh_HX > 0. ) phith_HX = phi_HX - 45.;

    if ( phith_HX < -180. ) phith_HX = 360. + phith_HX;


    /////////////////////////////////////////////////////////////////////
    // PERPENDICULAR HELICITY frame

    newZaxis = perpendicular_to_beam;
    newYaxis = Yaxis;
    newXaxis = newYaxis.Cross( newZaxis );

    rotation.SetToIdentity();
    rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
    rotation.Invert();

    lepton_DILEP_rotated = lepton_DILEP_xyz.Vect();

    lepton_DILEP_rotated.Transform(rotation);

    costh_PX = lepton_DILEP_rotated.CosTheta();

    phi_PX = lepton_DILEP_rotated.Phi() * 180. / gPI;

    if ( costh_PX < 0. ) phith_PX = phi_PX - 135.;
    if ( costh_PX > 0. ) phith_PX = phi_PX - 45.;

    if ( phith_PX < -180. ) phith_PX = 360. + phith_PX;


    /////////////////////////////////////////////////////////////////////
    // invariant polarization angle

    cosalpha = sqrt( 1. - pow(costh_PX, 2.) ) * sin( lepton_DILEP_rotated.Phi() );



////// Filling Histograms of costh2, cos2ph and sin2thcosph for the extraction of the actual generated polarization

    if ( !isBG ){
		costh2=pow(costh_CS,2.);
	    Phi = phi_CS/180. * gPI ;
	    cos2ph = cos(2.*Phi);
	    sin2thcosph= sin(2.*acos(costh_CS))*cos(Phi);
	    h_costh2_CS->Fill( costh2 );
	    h_cos2ph_CS->Fill( cos2ph );
	    h_sin2thcosph_CS->Fill( sin2thcosph );

	    costh2=pow(costh_HX,2.);
	    Phi = phi_HX/180. * gPI ;
	    cos2ph = cos(2.*Phi);
	    sin2thcosph= sin(2.*acos(costh_HX))*cos(Phi);
	    h_costh2_HX->Fill( costh2 );
	    h_cos2ph_HX->Fill( cos2ph );
	    h_sin2thcosph_HX->Fill( sin2thcosph );

	    costh2=pow(costh_PX,2.);
	    Phi = phi_PX/180. * gPI ;
	    cos2ph = cos(2.*Phi);
	    sin2thcosph= sin(2.*acos(costh_PX))*cos(Phi);
	    h_costh2_PX->Fill( costh2 );
	    h_cos2ph_PX->Fill( cos2ph );
	    h_sin2thcosph_PX->Fill( sin2thcosph );
    }


//  filling of the ntuple:

    genData->Fill();


  } // end of external loop (generated events)

  cout << endl;


  double lamth_CS;
  double lamph_CS;
  double lamtp_CS;
  costh2=h_costh2_CS->GetMean();
  lamth_CS = (1. - 3. * costh2 ) / ( costh2 - 3./5. );
  cos2ph=h_cos2ph_CS->GetMean();
  lamph_CS = cos2ph * (3. + lamth_CS);
  sin2thcosph=h_sin2thcosph_CS->GetMean();
  lamtp_CS = sin2thcosph * 5./4. * (3. + lamth_CS);

  double lamth_HX;
  double lamph_HX;
  double lamtp_HX;
  costh2=h_costh2_HX->GetMean();
  lamth_HX = (1. - 3. * costh2 ) / ( costh2 - 3./5. );
  cos2ph=h_cos2ph_HX->GetMean();
  lamph_HX = cos2ph * (3. + lamth_HX);
  sin2thcosph=h_sin2thcosph_HX->GetMean();
  lamtp_HX = sin2thcosph * 5./4. * (3. + lamth_HX);

  double lamth_PX;
  double lamph_PX;
  double lamtp_PX;
  costh2=h_costh2_PX->GetMean();
  lamth_PX = (1. - 3. * costh2 ) / ( costh2 - 3./5. );
  cos2ph=h_cos2ph_PX->GetMean();
  lamph_PX = cos2ph * (3. + lamth_PX);
  sin2thcosph=h_sin2thcosph_PX->GetMean();
  lamtp_PX = sin2thcosph * 5./4. * (3. + lamth_PX);


  char resfilename[200];
  sprintf(resfilename,"%s/GenResults.root",dirstruct);
  TFile* GenResultFile = new TFile(resfilename, "RECREATE", "GenResultFile");

  TTree* GenResults = new TTree("GenResults","GenResults");
  GenResults->Branch("lthCS",         &lamth_CS,         "lthCS/D");
  GenResults->Branch("lphCS",         &lamph_CS,         "lphCS/D");
  GenResults->Branch("ltpCS",         &lamtp_CS,         "ltpCS/D");
  GenResults->Branch("lthHX",         &lamth_HX,         "lthHX/D");
  GenResults->Branch("lphHX",         &lamph_HX,         "lphHX/D");
  GenResults->Branch("ltpHX",         &lamtp_HX,         "ltpHX/D");
  GenResults->Branch("lthPX",         &lamth_PX,         "lthPX/D");
  GenResults->Branch("lphPX",         &lamph_PX,         "lphPX/D");
  GenResults->Branch("ltpPX",         &lamtp_PX,         "ltpPX/D");

  GenResults->Fill();


  GenResultFile->Write();
  GenResultFile->Close();

  hfileout->Write();
  hfileout->Close();

} // end of main
Ejemplo n.º 4
0
//=========================================
// calculation of decay angular parameters
//=========================================
void calcPol(TLorentzVector muplus_LAB,
	     TLorentzVector muminus_LAB){
  
  TLorentzVector qqbar_LAB = muplus_LAB + muminus_LAB;
  Double_t rapidity = qqbar_LAB.Rapidity();

  // boost beams and positive muon into the q-qbar rest frame:
  TVector3 LAB_to_QQBAR = -qqbar_LAB.BoostVector();

  TLorentzVector beam1_QQBAR = eff::beam1_LAB;
  beam1_QQBAR.Boost( LAB_to_QQBAR );

  TLorentzVector beam2_QQBAR = eff::beam2_LAB;
  beam2_QQBAR.Boost( LAB_to_QQBAR );

  TLorentzVector muplus_QQBAR = muplus_LAB;
  muplus_QQBAR.Boost( LAB_to_QQBAR );

  // reference directions in the Jpsi rest frame:

  TVector3 beam1_direction     = beam1_QQBAR.Vect().Unit();
  TVector3 beam2_direction     = beam2_QQBAR.Vect().Unit();
  TVector3 qqbar_direction     = qqbar_LAB.Vect().Unit();
  TVector3 beam1_beam2_bisect  = ( beam1_direction - beam2_direction ).Unit();

  // all polarization frames have the same Y axis = the normal to the plane formed by
  // the directions of the colliding hadrons
  TVector3 Yaxis = ( beam1_direction.Cross( beam2_direction ) ).Unit();
  if ( rapidity < 0. ) Yaxis = -Yaxis; //H: added (5 Dec 2010)

  /////////////////////////////////////////////////////////////////////
  // CS frame

  TVector3 newZaxis = beam1_beam2_bisect;
  TVector3 newYaxis = Yaxis;
  TVector3 newXaxis = newYaxis.Cross( newZaxis );

  TRotation rotation;
  rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  rotation.Invert();   // transforms coordinates from the "xyz" system
  // to the "new" (rotated) system having the polarization axis
  // as z axis

  TVector3 muplus_QQBAR_rotated(muplus_QQBAR.Vect());
  
  muplus_QQBAR_rotated.Transform( rotation );

  thisCosTh[eff::CS] = muplus_QQBAR_rotated.CosTheta();

  thisPhi_rad[eff::CS] = muplus_QQBAR_rotated.Phi();
  thisPhi[eff::CS] = muplus_QQBAR_rotated.Phi() * 180. / TMath::Pi();
  //if ( thisPhi[eff::CS] < 0. ) thisPhi[eff::CS]= 360. + thisPhi[eff::CS];      // phi defined in degrees from 0 to 360
  //  thisPhi[eff::CS] += 180.; //H: don't add anything...

  /////////////////////////////////////////////////////////////////////
  // HELICITY frame

  newZaxis = qqbar_direction;
  newYaxis = Yaxis;
  newXaxis = newYaxis.Cross( newZaxis );

  rotation.SetToIdentity();
  rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  rotation.Invert();

  muplus_QQBAR_rotated = muplus_QQBAR.Vect();

  muplus_QQBAR_rotated.Transform( rotation );

  thisCosTh[eff::HX] = muplus_QQBAR_rotated.CosTheta();

  thisPhi_rad[eff::HX] = muplus_QQBAR_rotated.Phi();
  thisPhi[eff::HX] = muplus_QQBAR_rotated.Phi() * 180. / TMath::Pi();
  //if ( thisPhi[eff::HX] < 0. ) thisPhi[eff::HX] = 360. + thisPhi[eff::HX]; // phi defined in degrees from 0 to 360
  //thisPhi[eff::HX] += 180.;//H: don't add anything...
 
  /////////////////////////////////////////////////////////////////////
  // GJ1 frame

  newZaxis = beam1_direction;
  newYaxis = Yaxis;
  newXaxis = newYaxis.Cross( newZaxis );

  rotation.SetToIdentity();
  rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  rotation.Invert();

  muplus_QQBAR_rotated = muplus_QQBAR.Vect();

  muplus_QQBAR_rotated.Transform( rotation );

  thisCosTh[eff::GJ1] = muplus_QQBAR_rotated.CosTheta();

  thisPhi_rad[eff::GJ1] = muplus_QQBAR_rotated.Phi();
  thisPhi[eff::GJ1] = muplus_QQBAR_rotated.Phi() * 180. / TMath::Pi();
  //if ( thisPhi[eff::GJ1] < 0. ) thisPhi[eff::GJ1] = 360. + thisPhi[eff::GJ1]; // phi defined in degrees from 0 to 360
  //thisPhi[eff::GJ1] += 180.;//H: don't add anything...

  /////////////////////////////////////////////////////////////////////
  // GJ2 frame

  newZaxis = beam2_direction;
  newYaxis = Yaxis;
  newXaxis = newYaxis.Cross( newZaxis );

  rotation.SetToIdentity();
  rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  rotation.Invert();

  muplus_QQBAR_rotated = muplus_QQBAR.Vect();

  muplus_QQBAR_rotated.Transform( rotation );

  thisCosTh[eff::GJ2] = muplus_QQBAR_rotated.CosTheta();

  thisPhi_rad[eff::GJ2] = muplus_QQBAR_rotated.Phi();
  thisPhi[eff::GJ2] = muplus_QQBAR_rotated.Phi() * 180. / TMath::Pi();
  //if ( thisPhi[eff::GJ2] < 0. ) thisPhi[eff::GJ2] = 360. + thisPhi[eff::GJ2]; // phi defined in degrees from 0 to 360
  //thisPhi[eff::GJ2] += 180.;//H: don't add anything...
  /////////////////////////////////////////////////////////////////////
  // sGJ frame (symmetrized GJ)

  newZaxis = beam1_direction; if( rapidity < 0. ) newZaxis = beam2_direction;
  newYaxis = Yaxis;

  // try to swith the following line on or off
  //if( rapidity < 0. ) newYaxis = -Yaxis;

  newXaxis = newYaxis.Cross( newZaxis );

  rotation.SetToIdentity();
  rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  rotation.Invert();

  muplus_QQBAR_rotated = muplus_QQBAR.Vect();

  muplus_QQBAR_rotated.Transform( rotation );

  thisCosTh[eff::sGJ] = muplus_QQBAR_rotated.CosTheta();

  thisPhi_rad[eff::sGJ] = muplus_QQBAR_rotated.Phi();
  thisPhi[eff::sGJ] = muplus_QQBAR_rotated.Phi() * 180. / TMath::Pi();
  //if ( thisPhi[eff::sGJ] < 0. ) thisPhi[eff::sGJ] = 360. + thisPhi[eff::sGJ]; // phi defined in degrees from 0 to 360
  //thisPhi[eff::sGJ] += 180.;//H: don't add anything...

  /////////////////////////////////////////////////////////////////////
  // PHX frame ("perpendicular helicity frame" - z axis perpendicular
  // to the CS axis)

  newZaxis = newZaxis = ( beam1_beam2_bisect.Cross( Yaxis ) ).Unit();
  newYaxis = Yaxis;
  newXaxis = newYaxis.Cross( newZaxis );

  rotation.SetToIdentity();
  rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  rotation.Invert();

  muplus_QQBAR_rotated = muplus_QQBAR.Vect();

  muplus_QQBAR_rotated.Transform( rotation );

  thisCosTh[eff::PHX] = muplus_QQBAR_rotated.CosTheta();

  thisPhi_rad[eff::PHX] = muplus_QQBAR_rotated.Phi();
  thisPhi[eff::PHX] = muplus_QQBAR_rotated.Phi() * 180. / TMath::Pi();
  //if ( thisPhi[eff::PHX] < 0. ) thisPhi[eff::PHX] = 360. + thisPhi[eff::PHX]; // phi defined in degrees from 0 to 360
  //thisPhi[eff::PHX] += 180.;//H: don't add anything...
}
SimulationOutput* LightSimulator::Run(){
    
  TRandom3 randgen = TRandom3(0);

  if (debug) cout << ntoys*nrays << " light propagations to simulate" << endl;

  long counter_ray=0;

  if (output) delete output;
  output = new SimulationOutput(deposit);
    
  if (!isinsideboundaries()) return output;

  for (int nrun = 0; nrun<ntoys; nrun++){
            
    vector<Int_t> myphotons(4,0);

    for (int nray = 0; nray<nrays; nray++){

      counter_ray++;
      //	if (counter_ray%(ntoys*nrays/10)==0) cout << "Done " << counter_ray << " rays" << endl;

      Double_t phi = randgen.Uniform(-Pi(),Pi());
      Double_t costheta = randgen.Uniform(-1,1);
      TVector3 dir; dir.SetMagThetaPhi(1,ACos(costheta),phi);
      LightRay lr(deposit.position,dir);

      bool matched = false;
      Int_t matchx = 999;
      Int_t matchy = 999;
      Int_t firstmatchx = 999;
      Int_t firstmatchy = 999;

      Int_t index=0;
      MatchObject m;
      vector<MatchObject> matches;
      while (index>=0 && index<pars.max_distance_unit_propagation && index<Max(firstmatchx,firstmatchy)){
	if (propray(lr,kNS,index,matchx,m)){
	  if (!matched) firstmatchx=matchx;
	  matched=true;
	  matches.push_back(m);
	}
	if (propray(lr,kEW,index,matchy,m)){
	  if (!matched) firstmatchy=matchy;
	  matched=true;
	  matches.push_back(m);
	}
	index++;
      }

      vector<GoodMatchObject> goodmatches=convert_matches(matches);
	
      Double_t pathxy = pars.max_distance_unit_propagation*10*pars.xtalsize;
      GoodMatchObject finalmatch;
      for (size_t i=0; i<goodmatches.size(); i++){
	Double_t path = sqrt(pow(goodmatches[i].positionx-lr.origin.x(),2)+pow(goodmatches[i].positiony-lr.origin.y(),2));
	if (path<pathxy) {pathxy=path; finalmatch=goodmatches[i];}
      }
      if (pathxy>1e4){
	if (debug) cout << "LOOPER" << endl;
	continue;
      }

      Int_t channel = findchannel(finalmatch.x,finalmatch.y)-1;
     
      if (debug) cout << finalmatch.x << " " << finalmatch.y << " " << pathxy << " " << channel+1 << endl;

      Double_t path3d = pathxy/Sin(lr.dirvect.Theta());
     
      TVector3 rotated_origin_xy = lr.origin; rotated_origin_xy.SetZ(0);
      TVector3 rotated_impact = TVector3(finalmatch.positionx,finalmatch.positiony,0);
      TRotation r;
      r.RotateZ(-Pi()/4);
      rotated_origin_xy = r*rotated_origin_xy;
      rotated_impact = r*rotated_impact;

      Int_t nx = 0;
      Int_t ny = 0;
      Int_t nz = 0;
      {
	Int_t sx = finalmatch.x+finalmatch.y;
	if (sx==0) nx=0;
	else if (sx>0) nx = sx/2-1;
	else nx = TMath::Abs(sx)/2;
	Int_t dy = finalmatch.y-finalmatch.x;
	if (dy==0) ny=0;
	else if (dy>0) ny = dy/2-1;
	else ny = TMath::Abs(dy)/2;
	Float_t finalz = path3d*Cos(lr.dirvect.Theta())+deposit.position.z()-pars.xtalheight/2;
	nz = Int_t((fabs(finalz)+pars.xtalheight/2)/pars.xtalheight);
      }
      Int_t all_crossings = nx+ny+nz;

      Int_t my_paper_refl = 0;

      TVector2 difference = TVector2(fabs(rotated_origin_xy.x()-rotated_impact.x()),fabs(rotated_origin_xy.y()-rotated_impact.y()));
      if (difference.Phi()<limit_angle) my_paper_refl+=nx;
      if (Pi()/2-difference.Phi()<limit_angle) my_paper_refl+=ny;
      if (lr.dirvect.Theta()<limit_angle) my_paper_refl+=nz;

      Double_t att_absorption_point = randgen.Exp(pars.light_att_length);
      if (path3d>att_absorption_point) continue;

      Double_t prob_loss_in_reflections = pow(pars.eff_reflection_paper,my_paper_refl)*pow(pars.eff_reflection_total,all_crossings-my_paper_refl);
      if (randgen.Uniform()>prob_loss_in_reflections*pars.eff_lightcoll) continue;
	
      Double_t scintillation_delay = randgen.Exp(pars.scintillation_typ_timescale);

      Double_t arrival_time = deposit.time+path3d/pars.speed_of_light+scintillation_delay;
      if (arrival_time>pars.limit_arrival_time) continue;

      myphotons.at(channel)++;
      output->chamfer_pulseshape[channel]->Fill(arrival_time);
      output->reflections_paper->Fill(my_paper_refl);
      output->reflections_total->Fill(all_crossings-my_paper_refl);
      output->reflections_all->Fill(all_crossings);
      output->optical_path->Fill(path3d);
	
    }

    for (int i=0; i<4; i++) output->chamfer_photons[i]->Fill(myphotons[i]);

  }

  for (int i=0; i<4; i++) Normalize(output->chamfer_pulseshape[i]);
  Normalize(output->reflections_paper);
  Normalize(output->reflections_total);
  Normalize(output->reflections_all);
  Normalize(output->optical_path);

  return output;

};
Ejemplo n.º 6
0
void test_allEvt::ComputeAllVarPietro(TLorentzVector lepP,TLorentzVector lepN){
  // Preliminary definitions:

  const double pbeam = 7000.; // exact number irrelevant as long as pbeam >> Mprot
  const double Mprot = 0.9382720;
  const double Mlepton = 0.10566;  // (muon)
  const double gPI = TMath::Pi();
  const double Ebeam = sqrt( pbeam*pbeam + Mprot*Mprot );
  TLorentzVector beam1_LAB( 0., 0., pbeam, Ebeam );
  TLorentzVector beam2_LAB( 0., 0., -pbeam, Ebeam );


  // assuming that we have a TTree "data" (data ntuple) containing the 4-vectors lepP and lepN of lepton and antilepton

  // event by event (in some loop over dilepton events in the data ntuple):


  // data->GetEvent( i_event );

  // double lepP_pT  = lepP->Pt();
  // double lepN_pT  = lepN->Pt();

  // double lepP_eta = lepP->PseudoRapidity();
  // double lepN_eta = lepN->PseudoRapidity();

  // dilepton 4-vector:

  TLorentzVector dilepton = lepP + lepN;
  double pT   = dilepton.Pt();
  double rap  = dilepton.Rapidity();
  double mass = dilepton.M();

  // calculation of decay angles in three polarization frames

  // reference directions to calculate angles:

  TVector3 lab_to_dilep = -dilepton.BoostVector();

  TLorentzVector beam1_DILEP = beam1_LAB;
  beam1_DILEP.Boost(lab_to_dilep);         // beam1 in the dilepton rest frame
  TLorentzVector beam2_DILEP = beam2_LAB;
  beam2_DILEP.Boost(lab_to_dilep);         // beam2 in the dilepton rest frame

  TVector3 beam1_direction     = beam1_DILEP.Vect().Unit();
  TVector3 beam2_direction     = beam2_DILEP.Vect().Unit();
  TVector3 dilep_direction     = dilepton.Vect().Unit();
  TVector3 beam1_beam2_bisect  = ( beam1_direction - beam2_direction ).Unit();


  // all polarization frames have the same Y axis = the normal to the plane formed by
  // the directions of the colliding hadrons:

  TVector3 Yaxis = ( beam1_direction.Cross( beam2_direction ) ).Unit();

  // flip of y axis with rapidity:

  if ( rap < 0. ) Yaxis = - Yaxis;

  TVector3 perpendicular_to_beam = ( beam1_beam2_bisect.Cross( Yaxis ) ).Unit();


  // positive lepton in the dilepton rest frame:

  TLorentzVector lepton_DILEP = lepP;
  lepton_DILEP.Boost(lab_to_dilep);

  // CS frame angles:

  TVector3 newZaxis = beam1_beam2_bisect;
  TVector3 newYaxis = Yaxis;
  TVector3 newXaxis = newYaxis.Cross( newZaxis );

  TRotation rotation;
  rotation.SetToIdentity();
  rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  rotation.Invert();  // transforms coordinates from the "xyz" frame to the new frame
  TVector3 lepton_DILEP_rotated = lepton_DILEP.Vect();
  lepton_DILEP_rotated.Transform(rotation);

  /* double */ costh_CS = lepton_DILEP_rotated.CosTheta();
  /* double */ phi_CS   = lepton_DILEP_rotated.Phi() * 180. / gPI;
  double phith_CS;
  if ( costh_CS < 0. ) phith_CS = phi_CS - 135.;
  if ( costh_CS > 0. ) phith_CS = phi_CS - 45.;
  if ( phith_CS < -180. ) phith_CS = 360. + phith_CS;
  phi_CS   = phi_CS / 180. * gPI;


  // HELICITY frame angles:

  newZaxis = dilep_direction;
  newYaxis = Yaxis;
  newXaxis = newYaxis.Cross( newZaxis );

  rotation.SetToIdentity();
  rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  rotation.Invert();
  lepton_DILEP_rotated = lepton_DILEP.Vect();
  lepton_DILEP_rotated.Transform(rotation);

  /* double */ costh_HX = lepton_DILEP_rotated.CosTheta();
  /* double */ phi_HX   = lepton_DILEP_rotated.Phi() * 180. / gPI;
  double phith_HX;
  if ( costh_HX < 0. ) phith_HX = phi_HX - 135.;
  if ( costh_HX > 0. ) phith_HX = phi_HX - 45.;
  if ( phith_HX < -180. ) phith_HX = 360. + phith_HX;
  phi_HX   = phi_HX / 180. * gPI;


  // // PERPENDICULAR HELICITY frame angles:

  // newZaxis = perpendicular_to_beam;
  // newYaxis = Yaxis;
  // newXaxis = newYaxis.Cross( newZaxis );

  // rotation.SetToIdentity();
  // rotation.RotateAxes( newXaxis, newYaxis, newZaxis );
  // rotation.Invert();
  // lepton_DILEP_rotated = lepton_DILEP.Vect();
  // lepton_DILEP_rotated.Transform(rotation);

  // double costh_PX = lepton_DILEP_rotated.CosTheta();
  // double phi_PX   = lepton_DILEP_rotated.Phi() * 180. / gPI;
  // double phith_PX;
  // if ( costh_PX < 0. ) phith_PX = phi_PX - 135.;
  // if ( costh_PX > 0. ) phith_PX = phi_PX - 45.;
  // if ( phith_PX < -180. ) phith_PX = 360. + phith_PX;
  // phi_PX   = phi_PX / 180. * gPI;



}