예제 #1
0
double* Divide(const TArrayD* array , double val){
  TArrayD* temp = new TArrayD();
  array->Copy(*temp);
  for(int i = 0 ; i < temp->GetSize() ; i++)
    temp->SetAt(array->At(i) / val , i);
  
  return temp->GetArray();  
}
void showFunction2d(TF1* function, 
		    const TArrayD& testValuesX, const TArrayD& testValuesY, double metResolution, double metErr,
		    const TString& xAxisTitle, const TString& yAxisTitle,
		    const std::string& outputFileName)
{
  int numTestValuesX = testValuesX.GetSize();
  for ( int iTestValueX = 0; iTestValueX < numTestValuesX; ++iTestValueX ) {
    double testValueX = testValuesX[iTestValueX];

    std::vector<TF1*> functions;
    std::vector<std::string> legendEntries;

    int numTestValuesY = testValuesY.GetSize();
    for ( int iTestValueY = 0; iTestValueY < numTestValuesY; ++iTestValueY ) {
      double testValueY = testValuesY[iTestValueY];

      std::string functionName_nll = Form("%s_nll_%i", function->GetName(), iTestValueY);
      TF1* function_nll = 0;
      if ( metResolution > 0. ) {
	function_nll = 
	  new TF1(functionName_nll.data(), 
		  Form("-TMath::Log((%s)*TMath::Gaus(([1] - [0])*x, ([1] - [0]) + [2], [3]))", 
		       function->GetTitle()),
		  function->GetXmin(), function->GetXmax());
      } else {
	function_nll = new TF1(functionName_nll.data(), function->GetTitle(), function->GetXmin(), function->GetXmax());
      }
      function_nll->SetParameter(0, testValueX);
      function_nll->SetParameter(1, testValueY);
      function_nll->SetParameter(2, metErr);
      function_nll->SetParameter(3, metResolution);
      functions.push_back(function_nll);

      legendEntries.push_back(std::string(Form("m_{2} = %1.1f", testValueY)));
    }
 
    double yMax = 0.5*(0.1 + testValueX);

    size_t idx = outputFileName.find_last_of('.');
    TString outputFileName_plot = std::string(outputFileName, 0, idx).data();
    outputFileName_plot.Append(Form("_m1Eq%1.1f", testValueX));
    outputFileName_plot.ReplaceAll(".", "_");
    if ( idx != std::string::npos ) outputFileName_plot.Append(std::string(outputFileName, idx).data());
    showFunctions1d(functions, legendEntries, xAxisTitle, 0., yMax, yAxisTitle, outputFileName_plot.Data());

    for ( std::vector<TF1*>::iterator it = functions.begin();
	  it != functions.end(); ++it ) {
      delete (*it);
    }
  }
}
예제 #3
0
//------------------------------------------------------------------------------
// InvertAxis
//------------------------------------------------------------------------------
TH2F* InvertAxis(TH2* h2, TString hname)
{
  TArrayD* xarray = (TArrayD*)h2->GetXaxis()->GetXbins();
  TArrayD* yarray = (TArrayD*)h2->GetYaxis()->GetXbins();

  const UInt_t xsize = xarray->GetSize();
  const UInt_t ysize = yarray->GetSize();

  Double_t* xbins = new Double_t[xsize];
  Double_t* ybins = new Double_t[ysize];
  
  for (UInt_t i=0; i<xsize; i++) xbins[i] = xarray->GetAt(i);
  for (UInt_t i=0; i<ysize; i++) ybins[i] = yarray->GetAt(i);

  TH2F* h2inverted = new TH2F(hname, hname,
			      h2->GetNbinsY(), ybins,
			      h2->GetNbinsX(), xbins);

  for (UInt_t i=1; i<=h2inverted->GetNbinsX(); i++) {
    for (UInt_t j=1; j<=h2inverted->GetNbinsY(); j++) {

      h2inverted->SetBinContent(i, j, h2->GetBinContent(j, i));
      h2inverted->SetBinError  (i, j, h2->GetBinError  (j, i));
    }
  }

  delete [] xbins;
  delete [] ybins;

  return h2inverted;
}
예제 #4
0
Bool_t TZigZag::NearestPoints(Double_t x, TArrayI &I, TArrayD &W) const {
// One-dimensional case. Gives the 2 nearest points from point x in zigzag numbering.
//W are weights for the points, calculated according to the inverse of their distances
//from x
  const Double_t un  = 1.0;
  const Double_t eps = 1.0e-12;
  Int_t k;
  Double_t xl,xr,x1,x2,dx,dxs2,w0,w1,wt;
  I.Set(2);
  W.Set(2);
  dx   = (fXmax-fXmin)/fNx;
  dxs2 = dx/2;
  xl   = dxs2;
  xr   = dxs2 + (fNx-1)*dx;
  if (x<xl) {
    I[0] = 0;
    I[1] = 1;
    x1   = dxs2;
    x2   = dxs2 + dx;
  }
  else {
    if (x>xr) {
      I[0] = fNx - 1;
      I[1] = fNx - 2;
      x1   = dxs2 + (fNx-1)*dx;
      x2   = x1 - dx;
    }
    else {
      k    = Int_t((x-dxs2)/dx);
      I[0] = k;
      I[1] = k+1;
      x1   = dxs2 + k*dx;
      x2   = x1 + dx;
    }
  }
  w0   = TMath::Abs(x1-x);
  if (w0<eps) w0 = eps;
  w0   = un/w0;
  w1   = TMath::Abs(x2-x);
  if (w1<eps) w1 = eps;
  w1   = un/w1;
  wt   = w0 + w1;
  W[0] = w0/wt;
  W[1] = w1/wt;
  return kTRUE;
}
예제 #5
0
void buildFakeAngTree(const Char_t* outtag,
                      const Float_t timereso,     // ns
                      const UInt_t  simevts=1,
                      const Float_t thetaOpt=400, // deg
                      const Float_t phiOpt=400,   // deg
                      const Float_t coneOpt=400,  // deg
                      const UInt_t  rseed=23192,
                      const Float_t norm=100.0,   // mV
                      const Float_t noise=20.0,   // mV
                      const Char_t* outdir="/data/users/cjreed/work/simEvts",
                      const Char_t* infn="/w2/arianna/jtatar/nt.sigtemps.root",
                      const Char_t* geofn="/data/users/cjreed/work/"
                                          "BounceStudy/Stn10/"
                                          "CampSiteGeometry.root") {
   // if any of the angles (thetaOpt, phiOpt, coneOpt) > 360, a random
   // value will be used instead
   //
   // expect angles in the Templates tree to be in degrees
   //
   // expect the waveforms in the Templates tree to have amplitude 1
   
   TRandom3 rnd(rseed);
   
   
   geof = TFile::Open(geofn);
   gg = dynamic_cast<TGeoManager*>(geof->Get("CampSite2013"));
   site = dynamic_cast<const TSnGeoStnSite*>(gg->GetTopVolume());
   
   
   TVector3 pos[NSnConstants::kNchans], nvec[NSnConstants::kNchans];
   for (UChar_t ch=0; ch<NSnConstants::kNchans; ++ch) {
      site->SetLPDAPosition(ch, pos[ch]);
      site->SetLPDANormalVec(ch, nvec[ch]);
      Printf("pos ch%d:",ch);
      pos[ch].Print();
      Printf("normal ch%d:",ch);
      nvec[ch].Print();
   }
   
   TArrayD zeros(6);
   
   
   inf = TFile::Open(infn);
   nnt = dynamic_cast<TTree*>(inf->Get("Templates"));
   
   TString infns(infn);
   TString indir;
   Int_t fl(0);
   if (infns.Contains('/')) {
      fl = infns.Last('/') + 1;
      indir = infns(0, fl-1);
   }
   TString plaininfn = infns(fl, infns.Length()-fl);
   TString outfn = Form("%s/FakeEvts.%s.%s", outdir, outtag,
                        plaininfn.Data());
   outf = TFile::Open(outfn.Data(),"recreate");
   outf->cd();
   TParameter<Float_t> trp("TimeResolution", timereso);
   trp.Write();
   TParameter<Float_t> nmp("Normalization", norm);
   nmp.Write();
   TParameter<Float_t> nop("NoiseRMS", noise);
   nop.Write();
   TParameter<UInt_t> rsp("RandomSeed", rseed);
   rsp.Write();
   
   
   TSnCalWvData* wave = new TSnCalWvData;
   Float_t eang(0), hang(0), hpf(0), limiter(0), coneang(0);
   Bool_t bice(kFALSE);
   nnt->SetBranchAddress("wave.",&wave);
   nnt->SetBranchAddress("EAng",&eang);
   nnt->SetBranchAddress("HAng",&hang);
   nnt->SetBranchAddress("hpf",&hpf);
   nnt->SetBranchAddress("limiter",&limiter);
   nnt->SetBranchAddress("coneAng",&coneang);
   nnt->SetBranchAddress("bIce",&bice);
   // to look up waveform for EAng, HAng
   nnt->BuildIndex("EAng + (1000*HAng)","coneAng");
   // find the max angles
   Printf("finding allowed angles...");
   std::set<Float_t> Eangs, Hangs, Cangs;
   const Long64_t nnents = nnt->GetEntries();
   for (Long64_t i=0; i<nnents; ++i) {
      nnt->GetEntry(i);
      Eangs.insert(eang);
      Hangs.insert(hang);
      Cangs.insert(coneang);
   }
#ifdef DEBUG
   std::set<Float_t>::const_iterator ang, end = Eangs.end();
   Printf("EAngs:");
   for (ang=Eangs.begin(); ang!=end; ++ang) {
      Printf("%g",*ang);
   }
   Printf("HAngs:");
   for (ang=Hangs.begin(), end=Hangs.end(); ang!=end; ++ang) {
      Printf("%g",*ang);
   }
   Printf("ConeAngs:");
   for (ang=Cangs.begin(), end=Cangs.end(); ang!=end; ++ang) {
      Printf("%g",*ang);
   }
#endif
   
   Float_t theta(0), phi(0), cone(0);
   Float_t EAng[NSnConstants::kNchans], 
           HAng[NSnConstants::kNchans];
   Float_t CAng(0);
   TSnCalWvData* evdat = new TSnCalWvData;
   TSnEventMetadata* meta = new TSnEventMetadata;
   TSnEventHeader* hdr = new TSnEventHeader;
   //ot = nnt->CloneTree(0);
   //ot->SetName("SimTemplEvts");
   ot = new TTree("SimTemplEvts","simulated events from templates",1);
   ot->SetDirectory(outf);
   ot->Branch("EventMetadata.",&meta);
   ot->Branch("EventHeader.",&hdr);
   ot->Branch("EAng",&(EAng[0]),Form("EAng[%hhu]/F",NSnConstants::kNchans));
   ot->Branch("HAng",&(HAng[0]),Form("HAng[%hhu]/F",NSnConstants::kNchans));
   ot->Branch("CAng",&CAng,"CAng/F");
   ot->Branch("theta",&theta,"theta/F");
   ot->Branch("phi",&phi,"phi/F");
   ot->Branch("NuData.",&evdat);
   // some useful aliases
   TString an;
   for (UChar_t ch=0; ch<NSnConstants::kNchans; ++ch) {
      // to use as a cut for a particular channel:
      an = Form("Ch%d",ch);
      ot->SetAlias(an.Data(),
                   Form("(Iteration$>=(%hhu*%hhu)) && (Iteration$<(%hhu*%hhu))",
                        NSnConstants::kNsamps, ch,
                        NSnConstants::kNsamps,
                        static_cast<UChar_t>(ch+1)));
      // to use as a variable showing the sample number [0,127] for any chan
      an = Form("SmpCh%d",ch);
      ot->SetAlias(an.Data(),
                   Form("Iteration$-%u", static_cast<UInt_t>(ch)
                        *static_cast<UInt_t>(NSnConstants::kNsamps)));
      // e.g. Draw("RawData.fData:SmpCh2","EventHeader.fNum==21 && Ch2","l")
   }

   Printf("generating events...");
   TStopwatch timer;
   timer.Start();
   
   for (UInt_t i=0; i<simevts; ++i) {
      
      if ( (i%1000)==0 ) {
         fprintf(stderr,"Processing %u/%u ...            \r",i,simevts);
      }
      
      // choose angles
      theta = (thetaOpt>360.) ? TMath::ACos( rnd.Uniform(-1.0, 0.0) ) 
                              : thetaOpt * TMath::DegToRad();
      phi   = (phiOpt>360.) ? rnd.Uniform(0.0, TMath::TwoPi())
                            : phiOpt * TMath::DegToRad();
      cone  = (coneOpt>360.) 
         ? rnd.Uniform(*(Cangs.begin()), *(Cangs.rbegin()))
         : coneOpt; // leave this one in degrees (as in the tree)
      CAng = findNearestAllowedAngle(Cangs, cone);
      
#ifdef DEBUG
      Printf("--- theta=%g, phi=%g, cone=%g",
             theta*TMath::RadToDeg(), phi*TMath::RadToDeg(), cone);
#endif
      
      // calculate channel shifts
      TArrayD pwdt = NSnChanCorl::GetPlaneWaveOffsets(theta,
                                                      phi,
                                                      zeros,
                                                      pos,
                                                      kNgTopFirn);
      TVector3 dir;
      dir.SetMagThetaPhi(1.0, theta, phi);
      
#ifdef DEBUG
      TObjArray graphs;
      graphs.SetOwner(kTRUE);
      TCanvas* c1 = new TCanvas("c1","c1",800,700);
      c1->Divide(2,2);
#endif
      
      for (UChar_t ch=0; ch<NSnConstants::kNchans; ++ch) {
         
         // look up the EAng, fhang for this antenna
         Float_t feang(0), fhang(0);
         findEangHang(nvec[ch], dir, feang, fhang);
         feang  = TMath::Abs(TVector2::Phi_mpi_pi(feang));
         fhang  = TMath::Abs(TVector2::Phi_mpi_pi(fhang));
         feang *= TMath::RadToDeg();
         fhang *= TMath::RadToDeg();
         // find closest allowed angle
         EAng[ch] = findNearestAllowedAngle(Eangs, feang);
         HAng[ch] = findNearestAllowedAngle(Hangs, fhang);
         const Long64_t ni = 
            nnt->GetEntryNumberWithIndex(EAng[ch] + (1000*HAng[ch]), CAng);
#ifdef DEBUG
         Printf("EAng=%g (%g), HAng=%g (%g), CAng=%g, ni=%lld",
                EAng[ch],feang,HAng[ch],fhang,CAng,ni);
#endif
         if (ni>-1) {
            nnt->GetEntry(ni);
#ifdef DEBUG
            c1->cd(ch+1);
            TGraph* och = wave->NewGraphForChan(0, kTRUE);
            const Int_t ochnp = och->GetN();
            Double_t* ochy = och->GetY();
            for (Int_t k=0; k<ochnp; ++k, ++ochy) {
               *ochy *= norm;
            }
            graphs.Add(och);
            och->SetLineColor(kBlack);
            och->SetMarkerColor(kBlack);
            och->SetMarkerStyle(7);
            och->Draw("apl");
#endif
            
            // first calculate the shift between chans due to the angle
            // ch0 is always unshifted; other chans shifted w.r.t. ch0
            // jitter the shift by the specified timing resolution
            const Double_t shift = 
               rnd.Gaus( (ch==0) ? 0.0
                            : -pwdt.At( TSnRecoChanOffsets::IndexFor(ch, 0) ),
                         timereso);
            // get a graph of the waveform
            // data only in channel 0 of the template
            TGraph* gch = wave->NewGraphForChan(0, kTRUE);
            // "fit" the graph with an spline interpolation
            TSpline3* gsp = new TSpline3("stmp", gch);
            // evaluate the spline at the new sample positions
            // (shifted, but NOT wrapped)
            // and save that into the event data waveform
            Float_t* d = evdat->GetData(ch);
            const Float_t tstep = 1.0 / NSnConstants::kSampRate;
            const Float_t tlast = static_cast<Float_t>(NSnConstants::kNsamps-1)
               / NSnConstants::kSampRate;
            Float_t xloc = shift;
            for (UChar_t s=0; s<NSnConstants::kNsamps; ++s, ++d, xloc+=tstep) {
               if ( (xloc<0.0) || (xloc>=tlast) ) {
                  *d = 0.0;
               } else {
                  *d = gsp->Eval( xloc );
               }
            }
#ifdef DEBUG
            Printf("ch%hhu: shift=%g, dt=%g", ch, shift,
                   (ch==0) ? 0.0
                   : pwdt.At( TSnRecoChanOffsets::IndexFor(ch, 0) ));
            
            TGraph* fch = evdat->NewGraphForChan(ch, kTRUE);
            Double_t* y = gch->GetY();
            Double_t* fy = fch->GetY();
            for (UChar_t s=0; s<NSnConstants::kNsamps; ++s, ++y, ++fy) {
               *y *= norm;
               *fy *= norm;
            }
            
            gch->SetLineColor(kRed+1);
            gch->SetMarkerColor(kRed+1);
            gch->SetMarkerStyle(7);
            gch->Draw("pl");
            
            delete gsp;
            gsp = new TSpline3("stmp",gch);
            gsp->SetLineColor(kAzure-6);
            gsp->SetMarkerColor(kAzure-6);
            gsp->SetMarkerStyle(7);
            gsp->Draw("pl same");
            
            graphs.Add(fch);
            fch->SetLineColor(kOrange+7);
            fch->SetMarkerColor(kOrange+7);
            fch->SetMarkerStyle(7);
            fch->Draw("pl");
#endif


            d = evdat->GetData(ch);
            // finally add noise to the waveform
            for (UChar_t s=0; s<NSnConstants::kNsamps; ++s, ++d) {
               *d = rnd.Gaus( (*d) * norm, noise );
            }
            
#ifdef DEBUG
            TGraph* nch = evdat->NewGraphForChan(ch, kTRUE);
            graphs.Add(nch);
            nch->SetLineColor(kGreen+2);
            nch->SetMarkerColor(kGreen+2);
            nch->SetMarkerStyle(7);
            nch->Draw("pl");
#endif
            
            // cleanup
#ifdef DEBUG
            graphs.Add(gch);
            graphs.Add(gsp);
#else
            delete gch;
            delete gsp;
#endif
         }

      } // end channel loop

#ifdef DEBUG
      TObject* o(0);
      while ( (o=c1->WaitPrimitive())!=0 ) {
         gSystem->ProcessEvents();
      }
      delete c1;
#endif
         
         // save this event
         ot->Fill();
         
   } // end event loop

   fprintf(stderr,"\n");

   timer.Stop();
   Printf("Finished generating events in:");
   timer.Print();
   
   outf->Write();
   
   Printf("Wrote [%s]",outf->GetName());
   
   delete outf; outf=0; // close file
}
예제 #6
0
파일: getResV.C 프로젝트: XuQiao/HI
void getResv(int ispt){

	double theta[ntheta];
	TFile *f[nFileAll];
		
	for(int itheta=0;itheta<ntheta;itheta++)
        	theta[itheta]=itheta*TMath::Pi()/ntheta/nn;
        
        int nvv;
        const double *binv;
        if(ispt){             nvv = nptv;       binv = ptbinv;}
            else{             nvv = netav;          binv = etabinv;}

	string SumorProd = getenv("SUMORPROD");
	ofstream fstrv;
        if(ispt){
	if(SumorProd=="Sum")fstrv.open("v.txt");
	else fstrv.open("v_2.txt");
        }
        else{
	if(SumorProd=="Sum")fstrv.open("v_finer_eta.txt");
	else fstrv.open("v_2_finer_eta.txt");
        }
	TVectorD totmult[nbin],totpt[nbin], toteta[nbin];    
        TVectorD Nevent, totmultall, tottrkall,totmultall_, totmultallcorr;
	TVectorD V_int, V_interr;
	TVectorD* V_mean;
	TVectorD* deltaV_mean;
	TVectorD* V[nbin]; TVectorD* chi;
	TVectorD V_intcorr, V_intcorrerr;
	TVectorD totmulthisto_f[nbin][netav];
	TVectorD totmulthisto[nbin], totmulthistocorr[nbin];
	TVectorD* dDRe[nbin]; TVectorD* dDIm[nbin];
	TVectorD* dNRe[nbin][ntheta]; TVectorD* dNIm[nbin][ntheta];
	TComplex dD[nbin][ntheta], dN[nbin][ntheta][nvv];
	TVectorD avgmult[nbin];	TVectorD avgmultall;
	TVectorD avgtrk[nbin];	TVectorD avgtrkall;
	TVectorD avgpt[nbin], avgeta[nbin];
	TVectorD v[nbin][ntheta],vmean[nbin],deltav[nbin][ntheta],deltavmean[nbin];
	if(SumorProd=="Sum")	TFile *infile = TFile::Open("mergedV_Sum.root");
	else	TFile *infile = TFile::Open("mergedV_Prod.root");
	Nevent.ResizeTo(nbin);	Nevent.Zero();
	totmultall.ResizeTo(nbin);	totmultall.Zero();
	tottrkall.ResizeTo(nbin);	tottrkall.Zero();
	totmultall_.ResizeTo(nbin);	totmultall_.Zero();
	totmultallcorr.ResizeTo(nbin);	totmultallcorr.Zero();
	avgmultall.ResizeTo(nbin);
	avgtrkall.ResizeTo(nbin);
	V_int.ResizeTo(nbin);	V_int.Zero();
	V_interr.ResizeTo(nbin);	V_interr.Zero();
        if(ispt){
	V_intcorr.ResizeTo(nbin);	V_intcorr.Zero();
	V_intcorrerr.ResizeTo(nbin);	V_intcorrerr.Zero();
        }
	for(int ibin=0;ibin<nbin;ibin++){
		totmult[ibin].ResizeTo(nvv);	totmult[ibin].Zero();
                if(ispt){
                    for(int ietabin=0;ietabin<netav;ietabin++){
		totmulthisto_f[ibin][ietabin].ResizeTo(nvv);	
		totmulthisto_f[ibin][ietabin].Zero();
                    }
		totmulthisto[ibin].ResizeTo(nvv);
		totmulthisto[ibin].Zero();
		totmulthistocorr[ibin].ResizeTo(nvv);
		totmulthistocorr[ibin].Zero();
                }
		avgmult[ibin].ResizeTo(nvv);	avgpt[ibin].ResizeTo(nvv);  avgeta[ibin].ResizeTo(nvv);
		totpt[ibin].ResizeTo(nvv);	totpt[ibin].Zero(); 
                toteta[ibin].ResizeTo(nvv);     toteta[ibin].Zero();
		vmean[ibin].ResizeTo(nvv);	deltavmean[ibin].ResizeTo(nvv);
		V[ibin] = (TVectorD*) infile->Get(Form("D_%d/V",ibin));
		chi = (TVectorD*) infile->Get(Form("chi"));
		V_mean = (TVectorD*) infile->Get(Form("Vmean"));
		deltaV_mean = (TVectorD*) infile->Get(Form("deltaVmean"));
		for(int itheta=0;itheta<ntheta;itheta++){
			v[ibin][itheta].ResizeTo(nvv);	deltav[ibin][itheta].ResizeTo(nvv);
			dD[ibin][itheta]=0;
			for(int ivbin=0;ivbin<nvv;ivbin++){
				dN[ibin][itheta][ivbin]=0;
			}
		}
	}
        
        for(int ifile=0; ifile<nFileAll; ifile++){
            if(ispt){
	        if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/PbPb2011MB/Anav_Prod_%d.root",ifile));
	        else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/PbPb2011MB/Anav_Prod2_%d.root",ifile));
            }
            else{
	        if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/PbPb2011MB/finereta/Anaveta_Prod_%d.root",ifile));
	        else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/PbPb2011MB/finereta/Anaveta_Prod2_%d.root",ifile));
            }
		TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get("Nevent");	
		TVectorD* totmultall_t = (TVectorD*)f[ifile]->Get("totmultall");
		TVectorD* tottrkall_t = (TVectorD*)f[ifile]->Get("tottrk");
		for(int ibin=0;ibin<nbin;ibin++){
			TVectorD* totmult_t = (TVectorD*)f[ifile]->Get(Form("totmult_%d",ibin));
			TVectorD* totpt_t = (TVectorD*)f[ifile]->Get(Form("totpt_%d",ibin));
			TVectorD* toteta_t = (TVectorD*)f[ifile]->Get(Form("toteta_%d",ibin));
			dDRe[ibin] = (TVectorD*)f[ifile]->Get(Form("dDRe_%d",ibin));
			dDIm[ibin] = (TVectorD*)f[ifile]->Get(Form("dDIm_%d",ibin));
			Nevent[ibin]+=(*Nevent_t)[ibin];
			totmultall[ibin]+=(*totmultall_t)[ibin];
			tottrkall[ibin]+=(*tottrkall_t)[ibin];
			for(int ivbin=0;ivbin<nvv;ivbin++){
				totmult[ibin][ivbin]+=(*totmult_t)[ivbin];
				totpt[ibin][ivbin]+=(*totpt_t)[ivbin];
				toteta[ibin][ivbin]+=(*toteta_t)[ivbin];
			}
			for(int itheta=0;itheta<ntheta;itheta++){
				dNRe[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNRe_%d_%d",ibin,itheta));
				dNIm[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNIm_%d_%d",ibin,itheta));
				dD[ibin][itheta]+=TComplex((*dDRe[ibin])[itheta],(*dDIm[ibin])[itheta]);
				for(int ivbin=0;ivbin<nvv;ivbin++)
					dN[ibin][itheta][ivbin]+=TComplex((*dNRe[ibin][itheta])[ivbin],(*dNIm[ibin][itheta])[ivbin]);
			}
		}
	f[ifile]->Close();
	}
	
        double eff[netav];
        if(ispt){
	TH2F* hetapt[nbin];
	TH1D* hpt[nbin];
	TH2F* hetapteffcorr[nbin];
	TFile *fhisto = TFile::Open("histomerged.root");
	//TFile *feff = TFile::Open("/home/xuq7/HI/dNchdeta/Correction/trkEff_pp_all_42X_origin.root");
	TFile *feff = TFile::Open("/home/xuq7/HI/flow/LYZ/v2/TrackCorrections_HYDJET_442_OFFICIAL_Mar25.root");
	TH2F* heff = (TH2F*)feff->Get("rTotalEff3D");
      	//TH1D* hpteff = (TH1D*)heff->ProjectionY("hpteff",heff->GetXaxis()->FindBin(-2.4),heff->GetXaxis()->FindBin(2.4)-1,"o");
      	//TGraphError* hpteff = (TGraphErrors*)feff->Get("gEffPt");
	TArrayD *ptarr = (TArrayD*)heff->GetYaxis()->GetXbins();
	double *ptbinhisto = ptarr->GetArray();
	int NbinX = heff->GetXaxis()->GetNbins();
	int NbinY = heff->GetYaxis()->GetNbins();
	//hpteff->Scale(1.0/NbinX);
                }
        for(int ibin=0;ibin<nbin;ibin++)
		for(int itheta=0;itheta<ntheta;itheta++)
			dD[ibin][itheta]*=TComplex::Power(TComplex::I(),mm-1)/(Double_t)Nevent[ibin];
	
        for(int ibin=0;ibin<nbin;ibin++){
		avgmultall[ibin]=1.0*totmultall[ibin]/Nevent[ibin];
		avgtrkall[ibin]=1.0*tottrkall[ibin]/Nevent[ibin];
                if(ispt){
                hetapt[ibin] = (TH2F*)fhisto->Get(Form("D_%d/hetapt",ibin));
                hpt[ibin] = (TH1D*)fhisto->Get(Form("D_%d/hpt",ibin));
                //TH1D* hptre = (TH1D*)hpt[ibin]->Rebin(NbinY,Form("hptre_%d",ibin),ptbinhisto);
                //TH1D* hptre = (TH1D*)hpt[ibin]->Rebin(NbinY,Form("hptre_%d",ibin),ptbinhisto);
                hetapteffcorr[ibin] = (TH2F*)hetapt[ibin]->Clone(Form("hetapteffcorr_%d",ibin));
                //hpteffcorr[ibin]->Divide(hpteff);
                }
	        for(int ivbin=0;ivbin<nvv; ivbin++){
			vmean[ibin][ivbin]=0;
			deltavmean[ibin][ivbin]=0;
			avgmult[ibin][ivbin]=1.0*totmult[ibin][ivbin]/Nevent[ibin];
			avgpt[ibin][ivbin]=1.0*totpt[ibin][ivbin]/totmult[ibin][ivbin];
			avgeta[ibin][ivbin]=1.0*toteta[ibin][ivbin]/totmult[ibin][ivbin];
			for(int itheta=0;itheta<ntheta;itheta++){
				dN[ibin][itheta][ivbin]/=totmult[ibin][ivbin];
				TComplex Res=dN[ibin][itheta][ivbin]/dD[ibin][itheta];
				v[ibin][itheta][ivbin]=(*V[ibin])[itheta]*avgmultall[ibin]*TMath::BesselJ1(j01)/Besselj01(mm)*Res.Re();
				vmean[ibin][ivbin]+=v[ibin][itheta][ivbin];
				deltav[ibin][itheta][ivbin]=TMath::Cos(mm*nn*theta[itheta])/totmult[ibin][ivbin]*(TMath::Exp(j01*j01/2./(*chi)[ibin]/(*chi)[ibin]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Power(-1,mm)*TMath::Exp(-j01*j01/2./(*chi)[ibin]/(*chi)[ibin]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.)));
				deltavmean[ibin][ivbin]+=deltav[ibin][itheta][ivbin];
			//	fstrv<<itheta<<"\t"<<v[ibin][itheta][ivbin]<<"\t"<<deltav[ibin][itheta][ivbin]<<endl;
			}
		deltavmean[ibin][ivbin]=TMath::Sqrt(deltavmean[ibin][ivbin])/2./Besselj01(mm);
		//fstrv<<endl;
		vmean[ibin][ivbin]/=ntheta;
		deltavmean[ibin][ivbin]/=TMath::Sqrt(ntheta);
		fstrv<<binv[ivbin]<<"-"<<binv[ivbin+1]<<"\t"<<vmean[ibin][ivbin]<<"\t"<<deltavmean[ibin][ivbin]<<endl;
                if(ispt){
                    for(int ietabin=0;ietabin<netav;ietabin++){
                eff[ietabin] = heff->GetBinContent(heff->FindBin((etabinv[ietabin]+etabinv[ietabin+1])/2,(binv[ivbin]+binv[ivbin+1])/2));
                totmulthisto_f[ibin][ietabin][ivbin]=hetapt[ibin]->Integral(hetapt[ibin]->GetXaxis()->FindBin(etabinv[ietabin]+1e-4),hetapt[ibin]->GetXaxis()->FindBin(etabinv[ietabin+1]-1e-4),hetapt[ibin]->GetYaxis()->FindBin(binv[ivbin]+1e-4),hetapt[ibin]->GetYaxis()->FindBin(binv[ivbin+1]+1e-4));
                totmulthisto[ibin][ivbin]+=totmulthisto_f[ibin][ietabin][ivbin];
                }
                }
                
		V_int[ibin]+=vmean[ibin][ivbin]*totmult[ibin][ivbin];
		V_interr[ibin]+=deltavmean[ibin][ivbin]*totmult[ibin][ivbin];
		totmultall_[ibin]+=totmult[ibin][ivbin];
                if(ispt){
		if(binv[ivbin+1]>3.0) continue;
                    for(int ietabin=0;ietabin<netav;ietabin++)
                totmulthistocorr[ibin][ivbin]+=totmulthisto_f[ibin][ietabin][ivbin]/eff[ietabin];
		V_intcorr[ibin]+=vmean[ibin][ivbin]*totmulthistocorr[ibin][ivbin];
		V_intcorrerr[ibin]+=deltavmean[ibin][ivbin]*totmulthistocorr[ibin][ivbin];
                totmultallcorr[ibin]+=totmulthistocorr[ibin][ivbin];
		}
                }
		V_int[ibin]/=totmultall_[ibin];
		V_interr[ibin]/=totmultall_[ibin];
                if(ispt){
		V_intcorr[ibin]/=totmultallcorr[ibin];
		V_intcorrerr[ibin]/=totmultallcorr[ibin];
                }
	}
                if(ispt){
                fstrv<<endl<<"pt range\t\t"<<"totmult"<<"\t\t"<<"totmult from histo"<<"\t"<<"totmult corrected"<<endl;
	        for(int ibin=0;ibin<nbin;ibin++){
		for(int ivbin=0;ivbin<nvv; ivbin++){
                fstrv<<binv[ivbin]<<"-"<<binv[ivbin+1]<<"\t\t"<<totmult[ibin][ivbin]<<"\t"<<totmulthisto[ibin][ivbin]<<"\t"<<totmulthistocorr[ibin][ivbin]<<endl;
		}
		fstrv<<"Integral\t\t"<<totmultall_[ibin]<<"\t"<<hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(binv[0]),hpt[ibin]->GetXaxis()->FindBin(3.0)-1)<<"\t"<<totmultallcorr[ibin]<<endl;
		fstrv<<"V ref="<<(*V_mean)[ibin]<<"\t"<<"V int="<<V_int[ibin]<<"\t"<<"V int corr="<<V_intcorr[ibin]<<endl;
	        fstrv<<"V ref err="<<(*deltaV_mean)[ibin]<<"\t"<<"V int err="<<V_interr[ibin]<<"\t"<<"V int corr err="<<V_intcorrerr[ibin]<<endl;
	    }
                }
            else 
            for(int ibin=0;ibin<nbin;ibin++){
                for(int ivbin=0;ivbin<nvv; ivbin++){
                    fstrv<<binv[ivbin]<<"-"<<binv[ivbin+1]<<"\t\t"<<totmult[ibin][ivbin]<<endl;
                }
		fstrv<<"V ref="<<(*V_mean)[ibin]<<"\t"<<"V int="<<V_int[ibin]<<endl;
		fstrv<<"V ref err="<<(*deltaV_mean)[ibin]<<"\t"<<"V int err="<<V_interr[ibin]<<endl;
            }
        if(ispt){
	if(SumorProd=="Sum")TFile *fout = new TFile("mergedv_Prod.root","Recreate");
	else TFile *fout = new TFile("mergedv_Prod2.root","Recreate");
        }
        else{
	if(SumorProd=="Sum")TFile *fout = new TFile("mergedv_Prod_finer_eta.root","Recreate");
	else TFile *fout = new TFile("mergedv_Prod2_finer_eta.root","Recreate");
        }
	for(ibin=0;ibin<nbin;ibin++){
	Nevent.Write("Nevent");
	avgtrkall.Write("avgtrk");
	V_int.Write("V_int");
	V_interr.Write("V_interr");
        if(ispt){
	V_intcorr.Write("V_intcorr");
	V_intcorrerr.Write("V_intcorrerr");
        }
	TDirectory *dir0 = fout->mkdir(Form("D_%d",ibin));
	dir0->cd();
	avgpt[ibin].Write("avgpt");
	avgeta[ibin].Write("avgeta");
	totmult[ibin].Write("totmult");
	vmean[ibin].Write("vmean");
	deltavmean[ibin].Write("deltavmean");
         for(int itheta=0;itheta<ntheta;itheta++){
            TDirectory *dir1 = dir0->mkdir(Form("D_%d",itheta));dir1->cd();
            v[ibin][itheta].Write("v");
            deltav[ibin][itheta].Write("deltav");
        }
	}
	
	infile->Close();
	fout->Close();
}
예제 #7
0
파일: getResV.C 프로젝트: XuQiao/HI
void getResv(){

	double theta[ntheta];
	TFile *f[nFileAlltrack];
		
	for(int itheta=0;itheta<ntheta;itheta++)
        	theta[itheta]=itheta*TMath::Pi()/ntheta/nn;


	string SumorProd = getenv("SUMORPROD");
	string mdir = getenv("DIR");
	ofstream fstrv;
	if(SumorProd=="Sum")fstrv.open("v.txt");
	else fstrv.open("v_2.txt");
	TVectorD totmult[nbin], totpt[nbin];	TVectorD Nevent, totmultall, totmultall_;
	TVectorD totmulthisto[nbin], totmulthistocorr[nbin];
	TVectorD V_int, V_interr;
	TVectorD V_intcorr, V_intcorrerr;
	TVectorD* V_mean;
	TVectorD* deltaV_mean;
	TVectorD* V[nbin]; TVectorD* chi[nbin];
	TVectorD* dDRe[nbin]; TVectorD* dDIm[nbin];
	TVectorD* dNRe[nbin][ntheta]; TVectorD* dNIm[nbin][ntheta];
	TComplex dD[nbin][ntheta], dN[nbin][ntheta][nptv];
	TVectorD avgmult[nbin];	TVectorD avgmultall;
	TVectorD avgpt[nbin];
	TVectorD v[nbin][ntheta],vmean[nbin],deltav[nbin][ntheta],deltavmean[nbin];
	if(SumorProd=="Sum")	TFile *infile = TFile::Open("mergedV_Sum.root");
	else	TFile *infile = TFile::Open("mergedV_Prod.root");
	Nevent.ResizeTo(nbin);	Nevent.Zero();
	totmultall.ResizeTo(nbin);	totmultall.Zero();
	totmultall_.ResizeTo(nbin);	totmultall_.Zero();
	avgmultall.ResizeTo(nbin);
	V_int.ResizeTo(nbin);	V_int.Zero();
	V_interr.ResizeTo(nbin);	V_interr.Zero();
	V_intcorr.ResizeTo(nbin);	V_intcorr.Zero();
	V_intcorrerr.ResizeTo(nbin);	V_intcorrerr.Zero();
	for(int ibin=0;ibin<nbin;ibin++){
		totmult[ibin].ResizeTo(nptv);	totmult[ibin].Zero();
		totmulthisto[ibin].ResizeTo(nptv);	
		totmulthistocorr[ibin].ResizeTo(nptv);
		avgmult[ibin].ResizeTo(nptv);	avgpt[ibin].ResizeTo(nptv);
		totpt[ibin].ResizeTo(nptv);	totpt[ibin].Zero();
		vmean[ibin].ResizeTo(nptv);	deltavmean[ibin].ResizeTo(nptv);
		V[ibin] = (TVectorD*) infile->Get(Form("D_%d/D_0/V",ibin));
		chi[ibin] = (TVectorD*) infile->Get(Form("D_%d/chi",ibin));
		V_mean = (TVectorD*) infile->Get(Form("D_%d/Vmean",ibin));
		deltaV_mean = (TVectorD*) infile->Get(Form("D_%d/deltaVmean",ibin));
		for(int itheta=0;itheta<ntheta;itheta++){
			v[ibin][itheta].ResizeTo(nptv);	deltav[ibin][itheta].ResizeTo(nptv);
			dD[ibin][itheta]=0;
			for(int iptbin=0;iptbin<nptv;iptbin++){
				dN[ibin][itheta][iptbin]=0;
			}
		}
	}

        for(int ifile=0; ifile<nFileAlltrack; ifile++){
	        if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/lio/lfs/cms/store/user/qixu/flow/pbsjoboutput/PFcandpt01to10tracknormcpt03to6/%s/Anav_Prod_%d.root",mdir.c_str(),ifile));
	        else f[ifile] = TFile::Open(Form("/lio/lfs/cms/store/user/qixu/flow/pbsjoboutput/PFcandpt01to10tracknormcpt03to6/%s/Anav_Prod2_%d.root",mdir.c_str(),ifile));
		TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get("Nevent");	
		TVectorD* totmultall_t = (TVectorD*)f[ifile]->Get("totmultall");
		for(int ibin=0;ibin<nbin;ibin++){
			TVectorD* totmult_t = (TVectorD*)f[ifile]->Get(Form("totmult_%d",ibin));
			TVectorD* totpt_t = (TVectorD*)f[ifile]->Get(Form("totpt_%d",ibin));
			dDRe[ibin] = (TVectorD*)f[ifile]->Get(Form("dDRe_%d",ibin));
			dDIm[ibin] = (TVectorD*)f[ifile]->Get(Form("dDIm_%d",ibin));
			Nevent[ibin]+=(*Nevent_t)[ibin];
			totmultall[ibin]+=(*totmultall_t)[ibin];
			for(int iptbin=0;iptbin<nptv;iptbin++){
				totmult[ibin][iptbin]+=(*totmult_t)[iptbin];
				totpt[ibin][iptbin]+=(*totpt_t)[iptbin];
			}
			for(int itheta=0;itheta<ntheta;itheta++){
				dNRe[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNRe_%d_%d",ibin,itheta));
				dNIm[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNIm_%d_%d",ibin,itheta));
				dD[ibin][itheta]+=TComplex((*dDRe[ibin])[itheta],(*dDIm[ibin])[itheta]);
				for(int iptbin=0;iptbin<nptv;iptbin++)
					dN[ibin][itheta][iptbin]+=TComplex((*dNRe[ibin][itheta])[iptbin],(*dNIm[ibin][itheta])[iptbin]);
			}
		}
	f[ifile]->Close();
	}
	
	TH1D* hpt[nbin];
	TH1D* hpteffcorr[nbin];
	TFile *fhisto = TFile::Open("histomerged.root");
	TFile *feff = TFile::Open("/home/xuq7/HI/flow/LYZ/v2/TrackCorrections_HIJING_538_OFFICIAL_Mar24.root");
	TH2F* heff = (TH2F*)feff->Get("rTotalEff3D");
      	TH1D* hpteff = (TH1D*)heff->ProjectionY("hpteff",heff->GetXaxis()->FindBin(-2.4),heff->GetXaxis()->FindBin(2.4)-1,"o");
	TArrayD *ptarr = (TArrayD*)heff->GetYaxis()->GetXbins();
	double *ptbinhisto = ptarr->GetArray();
	int NbinX = heff->GetXaxis()->GetNbins();
	int NbinY = heff->GetYaxis()->GetNbins();
	hpteff->Scale(1.0/NbinX);
        
	for(int ibin=0;ibin<nbin;ibin++)
		for(int itheta=0;itheta<ntheta;itheta++)
			dD[ibin][itheta]*=TComplex::Power(TComplex::I(),mm-1)/(Double_t)Nevent[ibin];
	
	for(int ibin=0;ibin<nbin;ibin++){
		avgmultall[ibin]=1.0*totmultall[ibin]/Nevent[ibin];
                hpt[ibin] = (TH1D*)fhisto->Get(Form("D_%d/hpt",ibin));
                TH1D* hptre = (TH1D*)hpt[ibin]->Rebin(NbinY,"hptre",ptbinhisto);
                hpteffcorr[ibin] = (TH1D*)hptre->Clone(Form("hpteffcorr_%d",ibin));
                hpteffcorr[ibin]->Divide(hpteff);
		for(int iptbin=0;iptbin<nptv; iptbin++){
			vmean[ibin][iptbin]=0;
			deltavmean[ibin][iptbin]=0;
			avgmult[ibin][iptbin]=1.0*totmult[ibin][iptbin]/Nevent[ibin];
			avgpt[ibin][iptbin]=1.0*totpt[ibin][iptbin]/totmult[ibin][iptbin];
			for(int itheta=0;itheta<ntheta;itheta++){
				dN[ibin][itheta][iptbin]/=totmult[ibin][iptbin];
				TComplex Res=dN[ibin][itheta][iptbin]/dD[ibin][itheta];
				v[ibin][itheta][iptbin]=(*V[ibin])[itheta]*avgmultall[ibin]*TMath::BesselJ1(j01)/Besselj01(mm)*Res.Re();
				vmean[ibin][iptbin]+=v[ibin][itheta][iptbin];
				deltav[ibin][itheta][iptbin]=TMath::Cos(mm*nn*theta[itheta])/totmult[ibin][iptbin]*(TMath::Exp(j01*j01/2./(*chi[ibin])[0]/(*chi[ibin])[0]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Power(-1,mm)*TMath::Exp(-j01*j01/2./(*chi[ibin])[0]/(*chi[ibin])[0]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.)));
				deltavmean[ibin][iptbin]+=deltav[ibin][itheta][iptbin];
			//	fstrv<<itheta<<"\t"<<v[ibin][itheta][iptbin]<<"\t"<<deltav[ibin][itheta][iptbin]<<endl;
			}
		deltavmean[ibin][iptbin]=TMath::Sqrt(deltavmean[ibin][iptbin])/2./Besselj01(mm);
		//fstrv<<endl;
		vmean[ibin][iptbin]/=ntheta;
		deltavmean[ibin][iptbin]/=TMath::Sqrt(ntheta);
		fstrv<<ptbinv[iptbin]<<"-"<<ptbinv[iptbin+1]<<"\t"<<vmean[ibin][iptbin]<<"\t"<<deltavmean[ibin][iptbin]<<endl;
		if(ptbinv[iptbin+1]>3.0) continue;
                totmulthisto[ibin][iptbin]=hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(ptbinv[iptbin]),hpt[ibin]->GetXaxis()->FindBin(ptbinv[iptbin+1])-1);
                totmulthistocorr[ibin][iptbin]=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[iptbin]),hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[iptbin+1])-1);
		V_int[ibin]+=vmean[ibin][iptbin]*totmult[ibin][iptbin];
		V_interr[ibin]+=deltavmean[ibin][iptbin]*totmult[ibin][iptbin];
		V_intcorr[ibin]+=vmean[ibin][iptbin]*totmulthistocorr[ibin][iptbin];
		V_intcorrerr[ibin]+=deltavmean[ibin][iptbin]*totmulthistocorr[ibin][iptbin];
		totmultall_[ibin]+=totmult[ibin][iptbin];
		}
		V_int[ibin]/=totmultall_[ibin];
		V_interr[ibin]/=totmultall_[ibin];
		V_intcorr[ibin]/=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1);
		V_intcorrerr[ibin]/=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1);
	}

        fstrv<<endl<<"pt range\t\t"<<"totmult"<<"\t\t"<<"totmult from histo"<<"\t"<<"totmult corrected"<<endl;
	for(int ibin=0;ibin<nbin;ibin++){
		for(int iptbin=0;iptbin<nptv; iptbin++){
                fstrv<<ptbinv[iptbin]<<"-"<<ptbinv[iptbin+1]<<"\t\t"<<totmult[ibin][iptbin]<<"\t"<<totmulthisto[ibin][iptbin]<<"\t"<<totmulthistocorr[ibin][iptbin]<<endl;
		}
		fstrv<<"Integral\t\t"<<totmultall[ibin]<<"\t"<<hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(ptbinv[0]),hpt[ibin]->GetXaxis()->FindBin(3.0)-1)<<"\t"<<hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(ptbinv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1)<<endl;
		fstrv<<"V ref="<<(*V_mean)[ibin]<<"\t"<<"V int="<<V_int[ibin]<<"\t"<<"V int corr="<<V_intcorr[ibin]<<endl;
		fstrv<<"V ref err="<<(*deltaV_mean)[ibin]<<"\t"<<"V int err="<<V_interr[ibin]<<"\t"<<"V int corr err="<<V_intcorrerr[ibin]<<endl;
	}

	if(SumorProd=="Sum")TFile *fout = new TFile("mergedv_Prod.root","Recreate");
	else TFile *fout = new TFile("mergedv_Prod2.root","Recreate");
	for(ibin=0;ibin<nbin;ibin++){
	Nevent.Write("Nevent");
	V_int.Write("V_int");
	V_interr.Write("V_interr");
	V_intcorr.Write("V_intcorr");
	V_intcorrerr.Write("V_intcorrerr");
	TDirectory *dir = fout->mkdir(Form("D_%d",ibin));
	dir->cd();
	avgpt[ibin].Write("avgpt");
	totmult[ibin].Write("totmult");
	vmean[ibin].Write("vmean");
	deltavmean[ibin].Write("deltavmean");
	}
	
	infile->Close();
	fout->Close();
	
}
예제 #8
0
void rose_image()
{
   // Display image in a new canvas and pad.

   TImage *img = TImage::Open("rose512.jpg");

   if (!img) {
      printf("Could not create an image... exit\n");
      return;
   }

   img->SetConstRatio(0);
   img->SetImageQuality(TAttImage::kImgBest);

   TString fp = gEnv->GetValue("Root.TTFontPath", "");
   TString bc = fp + "/BlackChancery.ttf";
   TString ar = fp + "/arial.ttf";

   // draw text over image with funny font
   img->DrawText(120, 160, "Hello World!", 32, 
                 gROOT->GetColor(4)->AsHexString(), 
                 bc, TImage::kShadeBelow);

   // draw text over image with foreground specified by pixmap
   img->DrawText(250, 350, "goodbye cruel world ...", 24, 0, 
                 ar, TImage::kPlain, "fore.xpm");

   TImage *img2 = TImage::Open("mditestbg.xpm");

   // tile image
   img2->Tile(img->GetWidth(), img->GetHeight());

   c1 = new TCanvas("rose512", "examples of image manipulations", 760, 900);
   c1->Divide(2, 3);
   c1->cd(1);
   img->Draw("xxx");
   img->SetEditable(kTRUE);

   c1->cd(2);
   // averaging with mditestbg.xpm image
   TImage *img3 = (TImage*)img->Clone("img3");
   img3->Merge(img2, "allanon");
   img3->Draw();

   // contrasting (tint with itself)
   c1->cd(3);
   TImage *img4 = (TImage*)img->Clone("img4");
   img4->Merge(img4, "tint");

   // draw filled rectangle with magenta color
   img4->FillRectangle("#FF00FF", 20, 220, 40, 40);

   // Render multipoint alpha-blended gradient (R->G->B)
   img4->Gradient(0, "#FF0000 #00FF00 #220000FF", 0, 50, 50, 100, 100);

   // draw semi-transparent 3D button
   img4->Bevel(300, 20, 160, 40, "#ffffffff", "#fe000000", 3, 0);
   img4->DrawLine(10, 100, 100, 10, "#0000ff", 4);
   img4->Draw();

   // vectorize image. Reduce palette to 256 colors
   c1->cd(4);
   TImage *img5 = (TImage*)img->Clone("img5");
   img5->Vectorize(256);
   img5->Draw();

   // quantization of the image
   c1->cd(5);
   TImage *img6 = (TImage*)img->Clone("img6");
   TImagePalette *pal = (TImagePalette *)&img5->GetPalette();
   TArrayD *arr = img6->GetArray(50, 40, pal);
   img6->SetImage(arr->GetArray(), 50, 40, pal);
   img6->Draw();

   // HSV adjustment (convert red to yellow)
   c1->cd(6);
   TImage *img7 = (TImage*)img->Clone("img7");
   img7->HSV(0, 40, 40);
   img7->Draw();
}
예제 #9
0
파일: getResVsub.C 프로젝트: satan1028/HI
void getResvsub(int ispt=1){

	double theta[ntheta];
	TFile *f[nFileAll];
		
	for(int itheta=0;itheta<ntheta;itheta++)
        	theta[itheta]=itheta*TMath::Pi()/ntheta/nn;

        int nvv;
        const double *binv;

        if(ispt){             nvv = nptv;       binv = ptbinv;}
            else{             nvv = netav;          binv = etabinv;}

	string SumorProd = getenv("SUMORPROD");
	string mdir = getenv("DIR");
	ofstream fstrv;
        if(ispt){
	if(SumorProd=="Sum")fstrv.open("v_sub.txt");
	else fstrv.open("v_2_sub.txt");
        }
        else{
	if(SumorProd=="Sum")fstrv.open("v_eta_sub.txt");
	else fstrv.open("v_2_coarse_eta_sub.txt");
        }
	
	TVectorD Nevent[nbin], totmultall[nbin], totmultall_[nbin];
	TVectorD totmult[nbin], totpt[nbin],toteta[nbin];
	TVectorD totmulthisto[nbin], totmulthistocorr[nbin];
	TVectorD V_int[nbin], V_interr[nbin];
	TVectorD V_intcorr[nbin], V_intcorrerr[nbin];
	TVectorD* V_mean;
	TVectorD* deltaV_mean;
	TVectorD vmeanmean[nbin], deltavmeanmean[nbin], sigmavmeanmean[nbin], avgavgpt[nbin], avgavgeta[nbin];
	TVectorD* V[nbin]; TVectorD* chi[nbin];
	TVectorD* dDRe[nbin]; TVectorD* dDIm[nbin];
	TVectorD* dNRe[nbin][ntheta]; TVectorD* dNIm[nbin][ntheta];
	TComplex dD[nbin][ntheta], dN[nbin][ntheta][nvv];
	TVectorD avgmult[nbin];	TVectorD avgmultall;
	TVectorD avgpt[nbin],avgeta[nbin];
	TVectorD v[nbin][ntheta],vmean[nbin],deltav[nbin][ntheta],deltavmean[nbin];
	TVectorD IFILE[nbin];
	if(SumorProd=="Sum")	TFile *infile = TFile::Open("mergedV_Sum.root");
	else	TFile *infile = TFile::Open("mergedV_Prod.root");
        if(ispt){
	if(SumorProd=="Sum")TFile *fout = new TFile("mergedv_Prod_sub.root","Recreate");
	else TFile *fout = new TFile("mergedv_Prod2_sub.root","Recreate");
        }
        else{
	if(SumorProd=="Sum")TFile *fout = new TFile("mergedv_Prod_eta_sub.root","Recreate");
	else TFile *fout = new TFile("mergedv_Prod2_coarse_eta_sub.root","Recreate");
        }

	TVectorD Nevent_;       Nevent_.ResizeTo(nbin);  Nevent_.Zero();
	TH1D* hpt[nbin];
	TH1D* hpteffcorr[nbin];
	for(int ibin=0;ibin<nbin;ibin++){
        for(int ifile=0; ifile<nFileAll; ifile++){
            if(ispt){
        if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/Anav_Prod_%d.root",mdir.c_str(),ifile));
        else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/Anav_Prod2_%d.root",mdir.c_str(),ifile));
            }
            else{
        if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6c/coarsebins/%s/Anaveta_Prod_%d.root",mdir.c_str(),ifile));
        else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/coarsebins/%s/Anaveta_Prod2_%d.root",mdir.c_str(),ifile));
            }
        TVectorD* Nevent_t =  (TVectorD*)f[ifile]->Get(Form("Nevent"));
        Nevent_[ibin]+=(*Nevent_t)[ibin];
        f[ifile]->Close();
        }
	IFILE[ibin].ResizeTo(nsamples);
        Nevent[ibin].ResizeTo(nsamples);  Nevent[ibin].Zero();
        totmultall[ibin].ResizeTo(nsamples);      totmultall[ibin].Zero();
        totmultall_[ibin].ResizeTo(nsamples);      totmultall_[ibin].Zero();
        TDirectory *dir0 = fout->mkdir(Form("D_%d",ibin));


      	vmeanmean[ibin].ResizeTo(nvv);  vmeanmean[ibin].Zero();
        deltavmeanmean[ibin].ResizeTo(nvv);  deltavmeanmean[ibin].Zero();
       	sigmavmeanmean[ibin].ResizeTo(nvv);  sigmavmeanmean[ibin].Zero();
	avgavgpt[ibin].ResizeTo(nvv);	avgavgpt[ibin].Zero();
	avgavgeta[ibin].ResizeTo(nvv);	avgavgeta[ibin].Zero();
	V_interr[ibin].ResizeTo(nsamples);	V_interr[ibin].Zero();
	V_int[ibin].ResizeTo(nsamples);	V_int[ibin].Zero();
        if(ispt){
	V_intcorr[ibin].ResizeTo(nsamples);	V_intcorr[ibin].Zero();
	V_intcorrerr[ibin].ResizeTo(nsamples);	V_intcorrerr[ibin].Zero();
        }
        for(int isample=0;isample<nsamples;isample++){

	TVectorD Nevent0; Nevent0.ResizeTo(nbin);	Nevent0.Zero();
	avgmultall.ResizeTo(nbin);
		totmult[ibin].ResizeTo(nvv);	totmult[ibin].Zero();
                if(ispt){
		totmulthisto[ibin].ResizeTo(nvv); totmulthisto[ibin].Zero();
		totmulthistocorr[ibin].ResizeTo(nvv);totmulthistocorr[ibin].Zero();
                }
		avgmult[ibin].ResizeTo(nvv);	avgpt[ibin].ResizeTo(nvv);  avgeta[ibin].ResizeTo(nvv);
		totpt[ibin].ResizeTo(nvv);	totpt[ibin].Zero();
		toteta[ibin].ResizeTo(nvv);	toteta[ibin].Zero();
		vmean[ibin].ResizeTo(nvv);	deltavmean[ibin].ResizeTo(nvv);
		V[ibin] = (TVectorD*) infile->Get(Form("D_%d/V",ibin,isample));
		chi[ibin] = (TVectorD*) infile->Get(Form("chi",ibin,isample));
		V_mean = (TVectorD*) infile->Get(Form("Vmean",ibin,isample));
		deltaV_mean = (TVectorD*) infile->Get(Form("deltaVmean",ibin,isample));
		for(int itheta=0;itheta<ntheta;itheta++){
			v[ibin][itheta].ResizeTo(nvv);	deltav[ibin][itheta].ResizeTo(nvv);
			dD[ibin][itheta]=0;
			for(int ivbin=0;ivbin<nvv;ivbin++){
				dN[ibin][itheta][ivbin]=0;
			}
		}

        for(int ifile=0; ifile<nFileAll; ifile++){
            if(ispt){
	        if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/Anav_Prod_%d.root",mdir.c_str(),ifile));
	        else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/%s/Anav_Prod2_%d.root",mdir.c_str(),ifile));
            }
            else{
	        if(SumorProd=="Sum") f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/coarsebins/%s/Anaveta_Prod_%d.root",mdir.c_str(),ifile));
	        else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/tracknormcpt03to6/coarsebins/%s/Anaveta_Prod2_%d.root",mdir.c_str(),ifile));
            }
		TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get("Nevent");	
		TVectorD* totmultall_t = (TVectorD*)f[ifile]->Get("totmultall");
		Nevent0[ibin] += (*Nevent_t)[ibin];
                double start=isample*Nevent_[ibin]/nsamples;
                double end=(isample+1)*Nevent_[ibin]/nsamples;
                if(Nevent0[ibin]>start && Nevent0[ibin]<=end){
                        IFILE[ibin][isample]=(double)ifile;
                        Nevent[ibin][isample] += (*Nevent_t)[ibin];
			TVectorD* totmult_t = (TVectorD*)f[ifile]->Get(Form("totmult_%d",ibin));
			TVectorD* totpt_t = (TVectorD*)f[ifile]->Get(Form("totpt_%d",ibin));
			TVectorD* toteta_t = (TVectorD*)f[ifile]->Get(Form("toteta_%d",ibin));
			dDRe[ibin] = (TVectorD*)f[ifile]->Get(Form("dDRe_%d",ibin));
			dDIm[ibin] = (TVectorD*)f[ifile]->Get(Form("dDIm_%d",ibin));
			totmultall[ibin][isample]+=(*totmultall_t)[ibin];
			for(int ivbin=0;ivbin<nvv;ivbin++){
				totmult[ibin][ivbin]+=(*totmult_t)[ivbin];
				totpt[ibin][ivbin]+=(*totpt_t)[ivbin];
				toteta[ibin][ivbin]+=(*toteta_t)[ivbin];
			}
			for(int itheta=0;itheta<ntheta;itheta++){
				dNRe[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNRe_%d_%d",ibin,itheta));
				dNIm[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("dNIm_%d_%d",ibin,itheta));
				dD[ibin][itheta]+=TComplex((*dDRe[ibin])[itheta],(*dDIm[ibin])[itheta]);
				for(int ivbin=0;ivbin<nvv;ivbin++){
					if(ifile<188) dN[ibin][itheta][ivbin]+=TComplex((*dNRe[ibin][itheta])[ivbin],(*dNIm[ibin][itheta])[ivbin]);
                                        else dN[ibin][itheta][nvv-ivbin-1]+=TComplex((*dNRe[ibin][itheta])[ivbin],(*dNIm[ibin][itheta])[ivbin]);
                                }
			}
		}
	f[ifile]->Close();
	}
	
	TFile *fhisto = TFile::Open("histomerged.root");
	TFile *feff = TFile::Open("/home/xuq7/HI/flow/LYZ/v2/TrackCorrections_HIJING_538_OFFICIAL_Mar24.root");
	TH2F* heff = (TH2F*)feff->Get("rTotalEff3D");
      	TH1D* hpteff = (TH1D*)heff->ProjectionY("hpteff",heff->GetXaxis()->FindBin(-2.4),heff->GetXaxis()->FindBin(2.4)-1,"o");
	TArrayD *ptarr = (TArrayD*)heff->GetYaxis()->GetXbins();
	double *ptbinhisto = ptarr->GetArray();
	int NbinX = heff->GetXaxis()->GetNbins();
	int NbinY = heff->GetYaxis()->GetNbins();
	hpteff->Scale(1.0/NbinX);
        
		for(int itheta=0;itheta<ntheta;itheta++)
			dD[ibin][itheta]*=TComplex::Power(TComplex::I(),mm-1)/(Double_t)Nevent[ibin][isample];
	
		avgmultall[ibin]=1.0*totmultall[ibin][isample]/Nevent[ibin][isample];
                hpt[ibin] = (TH1D*)fhisto->Get(Form("D_%d/hpt",ibin));
                //TH1D* hptre = (TH1D*)hpt[ibin]->Rebin(NbinY,"hptre",ptbinhisto);
                //hpteffcorr[ibin] = (TH1D*)hptre->Clone(Form("hpteffcorr_%d",ibin));
                //hpteffcorr[ibin]->Divide(hpteff);
		for(int ivbin=0;ivbin<nvv; ivbin++){
			vmean[ibin][ivbin]=0;
			deltavmean[ibin][ivbin]=0;
			avgmult[ibin][ivbin]=1.0*totmult[ibin][ivbin]/Nevent[ibin][isample];
			avgpt[ibin][ivbin]=1.0*totpt[ibin][ivbin]/totmult[ibin][ivbin];
			avgeta[ibin][ivbin]=1.0*toteta[ibin][ivbin]/totmult[ibin][ivbin];
			for(int itheta=0;itheta<ntheta;itheta++){
				dN[ibin][itheta][ivbin]/=totmult[ibin][ivbin];
				TComplex Res=dN[ibin][itheta][ivbin]/dD[ibin][itheta];
				v[ibin][itheta][ivbin]=(*V[ibin])[itheta]*avgmultall[ibin]*TMath::BesselJ1(j01)/Besselj01(mm)*Res.Re();
				vmean[ibin][ivbin]+=v[ibin][itheta][ivbin];
				deltav[ibin][itheta][ivbin]=TMath::Cos(mm*nn*theta[itheta])/totmult[ibin][ivbin]*(TMath::Exp(j01*j01/2./(*chi[ibin])[0]/(*chi[ibin])[0]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Power(-1,mm)*TMath::Exp(-j01*j01/2./(*chi[ibin])[0]/(*chi[ibin])[0]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.)));
				deltavmean[ibin][ivbin]+=deltav[ibin][itheta][ivbin];
			//	fstrv<<itheta<<"\t"<<v[ibin][itheta][ivbin]<<"\t"<<deltav[ibin][itheta][ivbin]<<endl;
			}
		deltavmean[ibin][ivbin]=TMath::Sqrt(deltavmean[ibin][ivbin])/2./Besselj01(mm);
		//fstrv<<endl;
		vmean[ibin][ivbin]/=ntheta;
		deltavmean[ibin][ivbin]/=TMath::Sqrt(ntheta);
		fstrv<<binv[ivbin]<<"-"<<binv[ivbin+1]<<"\t"<<vmean[ibin][ivbin]<<"\t"<<deltavmean[ibin][ivbin]<<endl;
                if(ispt){
		if(binv[ivbin+1]>3.0) continue;
                totmulthisto[ibin][ivbin]=hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(binv[ivbin]),hpt[ibin]->GetXaxis()->FindBin(binv[ivbin+1])-1);
//                totmulthistocorr[ibin][ivbin]=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(binv[ivbin]),hpteffcorr[ibin]->GetXaxis()->FindBin(binv[ivbin+1])-1);
                totmulthistocorr[ibin][ivbin]=totmulthisto[ibin][ivbin]/hpteff->GetBinContent(hpteff->FindBin((binv[ivbin]+binv[ivbin+1])/2));
		V_int[ibin][isample]+=vmean[ibin][ivbin]*totmult[ibin][ivbin];
		V_interr[ibin][isample]+=deltavmean[ibin][ivbin]*totmult[ibin][ivbin];
		V_intcorr[ibin][isample]+=vmean[ibin][ivbin]*totmulthistocorr[ibin][ivbin];
		V_intcorrerr[ibin][isample]+=deltavmean[ibin][ivbin]*totmulthistocorr[ibin][ivbin];
                }
		totmultall_[ibin][isample]+=totmult[ibin][ivbin];
		}
		V_int[ibin][isample]/=totmultall_[ibin][isample];
		V_interr[ibin][isample]/=totmultall_[ibin][isample];
		//V_intcorr[ibin][isample]/=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(binv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1);
		//V_intcorr[ibin][isample]/=totmulthistocorr[ibin];
		//V_intcorrerr[ibin][isample]/=hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(binv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1);

                if(ispt){
        fstrv<<endl<<"pt range\t\t"<<"totmult"<<"\t\t"<<"totmult from histo"<<"\t"<<"totmult corrected"<<endl;
		for(int ivbin=0;ivbin<nvv; ivbin++){
                fstrv<<binv[ivbin]<<"-"<<binv[ivbin+1]<<"\t\t"<<totmult[ibin][ivbin]<<"\t"<<totmulthisto[ibin][ivbin]<<"\t"<<totmulthistocorr[ibin][ivbin]<<endl;
		}
		//fstrv<<"Integral\t\t"<<totmultall[ibin][isample]<<"\t"<<hpt[ibin]->Integral(hpt[ibin]->GetXaxis()->FindBin(binv[0]),hpt[ibin]->GetXaxis()->FindBin(3.0)-1)<<"\t"<<hpteffcorr[ibin]->Integral(hpteffcorr[ibin]->GetXaxis()->FindBin(binv[0]),hpteffcorr[ibin]->GetXaxis()->FindBin(3.0)-1)<<endl;
		fstrv<<"V ref="<<(*V_mean)[ibin]<<"\t"<<"V int="<<V_int[ibin][isample]<<"\t"<<"V int corr="<<V_intcorr[ibin][isample]<<endl;
		fstrv<<"V ref err="<<(*deltaV_mean)[ibin]<<"\t"<<"V int err="<<V_interr[ibin][isample]<<"\t"<<"V int corr err="<<V_intcorrerr[ibin][isample]<<endl;
                }
	TDirectory *dirsample = dir0->mkdir(Form("s_%d",isample));
        dirsample->cd();
	avgpt[ibin].Write("avgpt");
	avgeta[ibin].Write("avgeta");
	totmult[ibin].Write("totmult");
	vmean[ibin].Write("vmean");
	deltavmean[ibin].Write("deltavmean");
	for(int ivbin=0;ivbin<nvv; ivbin++){
		avgavgpt[ibin][ivbin]+=avgpt[ibin][ivbin]*Nevent[ibin][isample];
		avgavgeta[ibin][ivbin]+=avgeta[ibin][ivbin]*Nevent[ibin][isample];
		vmeanmean[ibin][ivbin]+=vmean[ibin][ivbin]/nsamples;
        	deltavmeanmean[ibin][ivbin]+=deltavmean[ibin][ivbin]/nsamples;
	        sigmavmeanmean[ibin][ivbin]+=TMath::Power(vmean[ibin][ivbin]/nsamples,2);
	}
	}//subsample loop
	dir0->cd();
        IFILE[ibin].Write("IFILE");
	V_int[ibin].Write("V_int");
	V_interr[ibin].Write("V_interr");
	V_intcorr[ibin].Write("V_intcorr");
	V_intcorrerr[ibin].Write("V_intcorrerr");
	Nevent[ibin].Write("Nevent");
	totmultall[ibin].Write("totmultall");
	for(int ivbin=0;ivbin<nvv; ivbin++){
		avgavgpt[ibin][ivbin]/=Nevent_[ibin];
		avgavgeta[ibin][ivbin]/=Nevent_[ibin];
        	sigmavmeanmean[ibin][ivbin]=TMath::Sqrt(sigmavmeanmean[ibin][ivbin]*nsamples-vmeanmean[ibin][ivbin]*vmeanmean[ibin][ivbin])/TMath::Sqrt(nsamples);
		}
	avgavgpt[ibin].Write("avgavgpt");
	avgavgeta[ibin].Write("avgavgeta");
        vmeanmean[ibin].Write("vmeanmean");
	deltavmeanmean[ibin].Write("deltavmeanmean");
        sigmavmeanmean[ibin].Write("sigmavmeanmean");
	}//ntrk bin loop
	infile->Close();
	fout->Close();
}
예제 #10
0
double *GetDat(int evt)	        {return fDat.GetArray()+evt*(kMaxData);}	
예제 #11
0
Bool_t TZigZag::PointsNear(Double_t x, Double_t y, Double_t &yi,
  TArrayD &Tn, TArrayD &Yn) const {
// Two-dimensional case. Finds in I,T,X,Y the 4 points of the grid around point (x,y).
//Then finds the 2 closest points along the zigzag in In,Tn,Xn,Yn.
// If point (x,y) not inside [fXmin,fXmax] and [fYmin,fYmax], make a projection
//towards center and stops at point just after entry and gives the 4 points for it.
  const Double_t un   = 1.0;
  const Double_t aeps = 1.0e-6;
  TArrayI Ii(4);
  TArrayD Ti(4);
  TArrayD Xi(4);
  TArrayD Yi(4);
  Bool_t ok;
  Int_t i;
  Int_t kx=0;
  Int_t ky=0;
  Double_t mx,my,eps;
  Double_t xc,xl,xr,dx,dxs2;
  Double_t yc,yl,yr,dy,dys2;
  Double_t xi,xp,yp;
  Double_t xle,xre,yle,yre;
  Tn.Set(2);
  Yn.Set(2);
  dx   = (fXmax-fXmin)/fNx;
  dxs2 = dx/2;
  dy   = (fYmax-fYmin)/fNy;
  dys2 = dy/2;
  xl   = dxs2;
  xr   = dxs2 + (fNx-1)*dx;
  yl   = dys2;
  yr   = dys2 + (fNy-1)*dy;
  if ((yr-yl) > (xr-xl)) eps = aeps*(yr-yl);
  else                   eps = aeps*(xr-xl);
  xle = xl + eps;
  xre = xr - eps;
  yle = yl + eps;
  yre = yr - eps;
  if ((x>=xle) && (x<=xre) && (y>=yle) && (y<=yre)) {
    xi = x;
    yi = y;
    kx = Int_t((xi-dxs2)/dx) + 1;
    ky = Int_t((yi-dys2)/dy) + 1;
    ok = kTRUE;
  }//end if ((x>xl) && (x<xr) && (y>yl) && (y<yr))
  else {
    xc = (fXmax-fXmin)/2;
    yc = (fYmax-fYmin)/2;
    mx  = (y-yc)/(x-xc);
    my  = un/mx;
    xi = xle;
    yi = yc + mx*(xi-xc);
    ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr);
    if (!ok) {
      xi = xre;
      yi = yc + mx*(xi-xc);
      ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr);
      if (!ok) {
        yi = yle;
        xi = xc + my*(yi-yc);
        ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr);
        if (!ok) {
          yi = yre;
          xi = xc + my*(yi-yc);
          ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr);
        }//end if (!ok)
      }//end if (!ok)
    }//end if (!ok)
    if (ok) {
      kx = Int_t((xi-dxs2)/dx) + 1;
      ky = Int_t((yi-dys2)/dy) + 1;
    }
    else {
      cout << "TZigZag::PointsNear : ERROR point inside not found" << endl;
    }
  }//end else if ((x>xl) && (x<xr) && (y>yl) && (y<yr))
  if (ok) {
//Point kx,ky
    xp    = dxs2 + (kx-1)*dx;
    yp    = dys2 + (ky-1)*dy;
    i     = NToZZ(kx,ky);
    Ii[0] = i;
    Ti[0] = T(i);
    Xi[0] = xp;
    Yi[0] = yp;
//Point kx+1,ky
    xp    = dxs2 + kx*dx;
    yp    = dys2 + (ky-1)*dy;
    i     = NToZZ(kx+1,ky);
    Ii[1] = i;
    Ti[1] = T(i);
    Xi[1] = xp;
    Yi[1] = yp;
//Point kx,ky+1
    xp    = dxs2 + (kx-1)*dx;
    yp    = dys2 + ky*dy;
    i     = NToZZ(kx,ky+1);
    Ii[2] = i;
    Ti[2] = T(i);
    Xi[2] = xp;
    Yi[2] = yp;
//Point kx+1,ky+1
    xp    = dxs2 + kx*dx;
    yp    = dys2 + ky*dy;
    i     = NToZZ(kx+1,ky+1);
    Ii[3] = i;
    Ti[3] = T(i);
    Xi[3] = xp;
    Yi[3] = yp;
//Finding the 2 points along the zigzag
    Order(4,Ii,Ti,Xi,Yi);
    Yn[0] = Yi[0];
    Tn[0] = Ti[0] + ((Ti[1] - Ti[0])/(Xi[1] -Xi[0]))*(xi - Xi[0]);
    Yn[1] = Yi[2];
    Tn[1] = Ti[2] + ((Ti[3] - Ti[2])/(Xi[3] -Xi[2]))*(xi - Xi[2]);
  }
  return ok;
}
예제 #12
0
Bool_t TZigZag::NearestPoints(Double_t x, Double_t y, Double_t z, TArrayI &I, TArrayD &W) const {
// 3-dimensional case. Gives the 8 nearest points from point x in zigzag numbering.
//W are weights for the points, calculated according to the inverse of their distances
//from x. If point (x,y) not inside [fXmin,fXmax],[fYmin,fYmax],[fZmin,fZmax], make a
//projection towards center and stops at point just after entry and gives the 8 points
//for it.
  const Double_t un   = 1.0;
  const Double_t aeps = 1.0e-6;
  Bool_t ok;
  Int_t i;
  Int_t kx=0;
  Int_t ky=0;
  Int_t kz=0;
  Double_t mx,my,mz,eps;
  Double_t xc,xl,xr,dx,dxs2;
  Double_t yc,yl,yr,dy,dys2;
  Double_t zc,zl,zr,dz,dzs2;
  Double_t xi,yi,zi,ti,xp,yp,zp;
  Double_t xle,xre,yle,yre,zle,zre;
  Double_t w0,w1,w2,w3,w4,w5,w6,w7,wt;
  I.Set(8);
  W.Set(8);
  for (i=0;i<8;i++) {
    I[i] = -1;
    W[i] = -un;
  }
  dx   = (fXmax-fXmin)/fNx;
  dxs2 = dx/2;
  dy   = (fYmax-fYmin)/fNy;
  dys2 = dy/2;
  dz   = (fZmax-fZmin)/fNy;
  dzs2 = dz/2;
  xl   = dxs2;
  xr   = dxs2 + (fNx-1)*dx;
  yl   = dys2;
  yr   = dys2 + (fNy-1)*dy;
  zl   = dzs2;
  zr   = dzs2 + (fNz-1)*dz;
  w0   = xr - xl;
  w1   = yr - yl;
  w2   = zr - zl;
  w0   = TMath::Max(w0,w1);
  w0   = TMath::Max(w0,w2);
  eps  = aeps*w0;
  if ((x>=xl) && (x<=xr) && (y>=yl) && (y<=yr) && (z>=zl) && (z<=zr)) {
    xi = x;
    yi = y;
    zi = z;
    kx = Int_t((xi-dxs2)/dx) + 1;
    ky = Int_t((yi-dys2)/dy) + 1;
    kz = Int_t((zi-dzs2)/dz) + 1;
    ok = kTRUE;
  }//end if ((x>xl) && (x<xr) && (y>yl) && (y<yr) && (z>zl) && (z<zr))
  else {
    xc = (fXmax-fXmin)/2;
    yc = (fYmax-fYmin)/2;
    zc = (fZmax-fZmin)/2;
    xle = xl + eps;
    xre = xr - eps;
    yle = yl + eps;
    yre = yr - eps;
    zle = zl + eps;
    zre = zr - eps;
    mx  = x - xc;
    my  = y - yc;
    mz  = z - zc;
//intercept with xle
    xi = xle;
    ti = (xi-xc)/mx;
    yi = yc + my*ti;
    zi = zc + mz*ti;
    ok = IsInside(xi,yi,zi,x,y,z,xc,yc,zc,xl,xr,yl,yr,zl,zr);
    if (!ok) {
//intercept with xre
      xi = xre;
      ti = (xi-xc)/mx;
      yi = yc + my*ti;
      zi = zc + mz*ti;
      ok = IsInside(xi,yi,zi,x,y,z,xc,yc,zc,xl,xr,yl,yr,zl,zr);
      if (!ok) {
//intercept with yle
        yi = yle;
        ti = (yi-yc)/my;
        xi = xc + mx*ti;
        zi = zc + mz*ti;
        ok = IsInside(xi,yi,zi,x,y,z,xc,yc,zc,xl,xr,yl,yr,zl,zr);
        if (!ok) {
//intercept with yre
          yi = yre;
          ti = (yi-yc)/my;
          xi = xc + mx*ti;
          zi = zc + mz*ti;
          ok = IsInside(xi,yi,zi,x,y,z,xc,yc,zc,xl,xr,yl,yr,zl,zr);
          if (!ok) {
//intercept with zle
            zi = zle;
            ti = (zi-zc)/mz;
            xi = xc + mx*ti;
            yi = yc + my*ti;
            ok = IsInside(xi,yi,zi,x,y,z,xc,yc,zc,xl,xr,yl,yr,zl,zr);
            if (!ok) {
//intercept with zre
              zi = zre;
              ti = (zi-zc)/mz;
              xi = xc + mx*ti;
              yi = yc + my*ti;
              ok = IsInside(xi,yi,zi,x,y,z,xc,yc,zc,xl,xr,yl,yr,zl,zr);
            }//end if (!ok) intercept with zre
          }//end if (!ok) intercept with zle
        }//end if (!ok) intercept with yre
      }//end if (!ok) intercept with yle
    }//end if (!ok) intercept with xre
    if (ok) {
      kx = Int_t((xi-dxs2)/dx) + 1;
      ky = Int_t((yi-dys2)/dy) + 1;
      kz = Int_t((zi-dzs2)/dz) + 1;
    }
    else {
      cout << "TZigZag::NearestPoints : ERROR point inside not found" << endl;
    }
  }//end else if ((x>xl) && (x<xr) && (y>yl) && (y<yr) && (z>zl) && (z<zr))
  if (ok) {
    Double_t fx,fy,fz;
//Point kx,ky,kz
    xp   = dxs2 + (kx-1)*dx;
    yp   = dys2 + (ky-1)*dy;
    zp   = dzs2 + (kz-1)*dz;
    fx   = x - xp;
    fy   = y - yp;
    fz   = z - zp;
    i    = NToZZ(kx,ky,kz);
    I[0] = i;
    w0   = TMath::Sqrt(fx*fx + fy*fy + fz*fz) + eps;
    w0   = un/w0;
//Point kx+1,ky,kz
    xp   = dxs2 + kx*dx;
    yp   = dys2 + (ky-1)*dy;
    zp   = dzs2 + (kz-1)*dz;
    fx   = x - xp;
    fy   = y - yp;
    fz   = z - zp;
    i    = NToZZ(kx+1,ky,kz);
    I[1] = i;
    w1   = TMath::Sqrt(fx*fx + fy*fy + fz*fz) + eps;
    w1   = un/w1;
//Point kx,ky+1,kz
    xp   = dxs2 + (kx-1)*dx;
    yp   = dys2 + ky*dy;
    zp   = dzs2 + (kz-1)*dz;
    fx   = x - xp;
    fy   = y - yp;
    fz   = z - zp;
    i    = NToZZ(kx,ky+1,kz);
    I[2] = i;
    w2   = TMath::Sqrt(fx*fx + fy*fy + fz*fz) + eps;
    w2   = un/w2;
//Point kx+1,ky+1,kz
    xp   = dxs2 + kx*dx;
    yp   = dys2 + ky*dy;
    zp   = dzs2 + (kz-1)*dz;
    fx   = x - xp;
    fy   = y - yp;
    fz   = z - zp;
    i    = NToZZ(kx+1,ky+1,kz);
    I[3] = i;
    w3   = TMath::Sqrt(fx*fx + fy*fy + fz*fz) + eps;
    w3   = un/w3;
//Point kx,ky,kz+1
    xp   = dxs2 + (kx-1)*dx;
    yp   = dys2 + (ky-1)*dy;
    zp   = dzs2 + kz*dz;
    fx   = x - xp;
    fy   = y - yp;
    fz   = z - zp;
    i    = NToZZ(kx,ky,kz+1);
    I[4] = i;
    w4   = TMath::Sqrt(fx*fx + fy*fy + fz*fz) + eps;
    w4   = un/w4;
//Point kx+1,ky,kz+1
    xp   = dxs2 + kx*dx;
    yp   = dys2 + (ky-1)*dy;
    zp   = dzs2 + kz*dz;
    fx   = x - xp;
    fy   = y - yp;
    fz   = z - zp;
    i    = NToZZ(kx+1,ky,kz+1);
    I[5] = i;
    w5   = TMath::Sqrt(fx*fx + fy*fy + fz*fz) + eps;
    w5   = un/w5;
//Point kx,ky+1,kz+1
    xp   = dxs2 + (kx-1)*dx;
    yp   = dys2 + ky*dy;
    zp   = dzs2 + kz*dz;
    fx   = x - xp;
    fy   = y - yp;
    fz   = z - zp;
    i    = NToZZ(kx,ky+1,kz+1);
    I[6] = i;
    w6   = TMath::Sqrt(fx*fx + fy*fy + fz*fz) + eps;
    w6   = un/w6;
//Point kx+1,ky+1,kz+1
    xp   = dxs2 + kx*dx;
    yp   = dys2 + ky*dy;
    zp   = dzs2 + kz*dz;
    fx   = x - xp;
    fy   = y - yp;
    fz   = z - zp;
    i    = NToZZ(kx+1,ky+1,kz+1);
    I[7] = i;
    w7   = TMath::Sqrt(fx*fx + fy*fy + fz*fz) + eps;
    w7   = un/w7;
//
    wt   = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7;
    W[0] = w0/wt;
    W[1] = w1/wt;
    W[2] = w2/wt;
    W[3] = w3/wt;
    W[4] = w4/wt;
    W[5] = w5/wt;
    W[6] = w6/wt;
    W[7] = w7/wt;
  }
  return ok;
}