void BoundaryCreator::Save() { if (fFile==0) return; if (!fFile->IsOpen()) { std::cerr << "BoundaryCreator::fFile is not open!" << std::endl; return; } TDirectory *dir = fFile->GetDirectory("BoundaryCreatorOutput"); if (dir==0) { dir = fFile->mkdir("BoundaryCreatorOutput"); } dir->cd(); for (UInt_t i=0; i<fGrids.size(); i++) { GSBoundaryFinder gsbf(fGrids.at(i)); TCutG* boundary = gsbf.GetBoundary(); if (boundary) { std::ostringstream ss("Boundary", std::ios::out|std::ios::app); ss << i; boundary->SetName(ss.str().data()); boundary->Write("",TObject::kOverwrite); } } fFile->cd(); }
TCanvas *fit2a() { TCanvas *c = new TCanvas(); gStyle->SetOptStat(kTRUE); gStyle->SetPalette(1); const Int_t npar = 15; Double_t f2params[npar] = {100,-3,3,-3,3,160,0,0.8,0,0.9,40,4,0.7,4,0.7}; TF2 *f2 = new TF2("f2",fun2,-10,10,-10,10, npar); f2->SetParameters(f2params); //Create an histogram and fill it randomly with f2 TH2F *h2 = new TH2F("h2","From f2",40,-10,10,40,-10,10); Int_t nentries = 100000; h2->FillRandom("f2",nentries); //Fit h2 with original function f2 Float_t ratio = 4*nentries/100000; f2params[ 0] *= ratio; f2params[ 5] *= ratio; f2params[10] *= ratio; f2->SetParameters(f2params); h2->Fit("f2","N"); TCutG *cutg = new TCutG("cutg",5); cutg->SetPoint(0,-7,-7); cutg->SetPoint(1, 2,-7); cutg->SetPoint(2, 2, 2); cutg->SetPoint(3,-7, 2); cutg->SetPoint(4,-7,-7); h2->Draw("lego2 0"); h2->SetFillColor(38); f2->SetNpx(80); f2->SetNpy(80); f2->Draw("surf1 same bb [cutg]"); return c; }
void FirstContour() { TString dir = gSystem->UnixPathName(__FILE__); dir.ReplaceAll("FirstContour.C","../hsimple.C"); dir.ReplaceAll("/./","/"); if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data()); TFile *file = (TFile*)gROOT->ProcessLineFast("hsimple(1)"); if (!file) return; TTree *ntuple = (TTree*)file->Get("ntuple"); TCanvas *c1 = new TCanvas("c1","Contours",10,10,800,600); gStyle->SetPalette(1); ntuple->Draw("py:px","px*px+py*py < 20", "contz,list"); //we must call Update to force the canvas to be painted. When //painting the contour plot, the list of contours is generated //and a reference to it added to the Root list of special objects c1->Update(); TCanvas *c2 = new TCanvas("c2","First contour",100,100,800,600); TObjArray *contours = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours"); if (!contours) return; TList *lcontour1 = (TList*)contours->At(0); if (!lcontour1) return; TGraph *gc1 = (TGraph*)lcontour1->First(); if (!gc1) return; if (gc1->GetN() < 10) return; gc1->SetMarkerStyle(21); gc1->Draw("alp"); //We make a TCutG object with the array obtained from this graph TCutG *cutg = new TCutG("cutg",gc1->GetN(),gc1->GetX(),gc1->GetY()); //We create a polymarker object with npmax points. const Int_t npmax = 50000; TPolyMarker *pm = new TPolyMarker(npmax); Int_t np = 0; while(1) { Double_t x = -4 +8*gRandom->Rndm(); Double_t y = -4 +8*gRandom->Rndm(); if (cutg->IsInside(x,y)) { pm->SetPoint(np,x,y); np++; if (np == npmax) break; } } pm->Draw(); }
//--------------------------------------------------------------------- void MMMLoadCuts(SiliconData *si) { printf("Load MMM Front-Back Energy cut\n"); TCutG *cutg = new TCutG("FrontBackEnergyCut",8); cutg->SetVarX("EnergyBack"); cutg->SetVarY("EnergyFront"); cutg->SetTitle("Graph"); cutg->SetFillColor(1); /* cutg->SetPoint(0,8625.54,9448.89); cutg->SetPoint(1,9436.42,9393.27); cutg->SetPoint(2,9398.71,8336.6); cutg->SetPoint(3,8512.39,8253.18); cutg->SetPoint(4,610.991,300.318); cutg->SetPoint(5,516.703,912.076); cutg->SetPoint(6,8625.54,9143.01); cutg->SetPoint(7,8625.54,9448.89); */ cutg->SetPoint(0,500.,0.); cutg->SetPoint(1,0.,500.); cutg->SetPoint(2,14500.,15000.); cutg->SetPoint(3,15000.,14500.); cutg->SetPoint(4,500.,0.); MMMFrontBackEnergyCut = cutg; }
/*===========================================================================*/ void d2dwin(Char_t *fnam, Char_t *wnam, Int_t n, Char_t *c) { c1=(TCanvas *)gROOT->FindObject(c); c1->cd(n); TCutG *mycutg; TFile *fcutg; fcutg = new TFile(fnam); mycutg=(TCutG *)fcutg->Get(wnam); fcutg->Close(); if (mycutg != NULL) { mycutg->SetLineColor(2); mycutg->Draw(); } f1 = new TFile(rootfilename,"READ"); return; }
void rotate2DN(const char* filename,int detNum){ TFile *f = new TFile(filename); TCanvas* cnew= new TCanvas("cnew","",800.,500.); cnew->cd(); stringstream sss; sss<<"Transposed-"<<filename; TFile f1(sss.str().c_str(),"RECREATE"); for (int i=0;i<detNum;i++){ stringstream orig ; orig<<"hNc"<<i ; TH2D* h1=(TH2D*)f->Get(orig.str().c_str()); string gname = h1->GetTitle(); stringstream hname ; hname<<"hN"<<i; TH2D* Hnew = new TH2D(hname.str().c_str(),gname.c_str(),1700.,0.,1700.,8000.,0.,8000.); for (int x=0;x<8000;x++){ for (int y=0;y<1600;y++){ int bin = h1->GetBinContent(x,y); Hnew->Fill(y,x,bin); } } cout<<"Histogram Number "<<i<<" transpose completed"<<endl; cnew->cd(); Hnew->SetMinimum(7); Hnew->GetYaxis()->SetRangeUser(1300,1600); Hnew->GetYaxis()->SetTitle("Energy (keV)"); Hnew->GetXaxis()->SetTitle("Cycle Number"); Hnew->Draw("COLZ"); TCutG *cutg = new TCutG("NaIcut1",5); cutg->SetVarX("y"); cutg->SetVarY("x"); cutg->SetPoint(0,0,1350); cutg->SetPoint(1,1500,1350); cutg->SetPoint(2,1500,1500); cutg->SetPoint(3,0,1500); cutg->SetPoint(4,0,1350); TProfile *profx = Hnew->ProfileX(Form("profx_%d",i),1,-1,"[NaIcut1]"); profx->SetLineColor(kRed); profx->Draw("same"); cnew->Update(); gname = gname + ".pdf"; cnew->SaveAs(gname.c_str()); } f1.Write(); }
TCutG* GetErrorBand(string name, TGraph* Low, TGraph* High) { TCutG* cutg = new TCutG(name.c_str(),Low->GetN()+High->GetN()+2); cutg->SetFillColor(kGreen-7); cutg->SetLineStyle(0); cutg->SetLineColor(0); int I = 0; for(int i=0;i<Low->GetN();i++){ cutg->SetPoint(I,Low ->GetX()[i] , Low ->GetY()[i] );I++; } cutg->SetPoint(I,Low ->GetX()[Low ->GetN()-1] , Low ->GetY()[Low ->GetN()-1] );I++; cutg->SetPoint(I,High->GetX()[High->GetN()-1] , High->GetY()[High->GetN()-1] );I++; for(int i=0;i<High->GetN() ;i++){cutg->SetPoint(I,High->GetX()[High->GetN()-1-i], High->GetY()[High->GetN()-1-i]);I++;} return cutg; }
TCutG* GetErrorBand(string name, int N, double* Mass, double* Low, double* High) { TCutG* cutg = new TCutG(name.c_str(),2*N+2); cutg->SetFillColor(kGreen-7); cutg->SetLineStyle(0); cutg->SetLineColor(0); int I = 0; for(int i=0;i<N;i++){cutg->SetPoint(I,Mass[i] , Low[i] );I++; } cutg->SetPoint(I,Mass[N-1] , Low[N-1] );I++; cutg->SetPoint(I,Mass[N-1] , High[N-1] );I++; for(int i=0;i<N;i++){cutg->SetPoint(I,Mass[N-1-i], High[N-1-i]);I++;} return cutg; }
void run_plot(TString FileNameHead = "output_proto",TString fileKine="../Kinematics/Decay_kinematics/10Be_4He_19MeV.txt",TString fileKine2="../Kinematics/Decay_kinematics/10Be_12C_19MeV.txt") { TString workdir = getenv("VMCWORKDIR"); TString FilePath = workdir + "/macro/Unpack_GETDecoder2/"; TString FileNameTail = ".root"; TString FileName = FilePath + FileNameHead + FileNameTail; std::cout<<" Opening File : "<<FileName.Data()<<std::endl; TFile* file = new TFile(FileName.Data(),"READ"); //TFile* file = new TFile(FileNameHead_chain.Data(),"READ"); TTree* tree = (TTree*) file -> Get("cbmsim"); Int_t nEvents = tree -> GetEntriesFast(); std::cout<<" Number of events : "<<nEvents<<std::endl; TCanvas *c2 = new TCanvas("c2","c2",200,10,700,700); c2->Divide(2,1); TCanvas *c3 = new TCanvas("c3","c3",200,10,700,700); //c3->Divide(2,1); TH2D* Q02_Kine = new TH2D("Q02_Kine","Q02_Kine",1000,0,180,1000,0,180); Q02_Kine->SetMarkerColor(2); Q02_Kine->SetMarkerStyle(20); Q02_Kine->SetMarkerSize(0.7); TH2D* Q13_Kine = new TH2D("Q13_Kine","Q13_Kine",1000,0,180,1000,0,180); Q13_Kine->SetMarkerColor(2); Q13_Kine->SetMarkerStyle(20); Q13_Kine->SetMarkerSize(0.7); TH1D* Vertex = new TH1D("Vertex","Vertex",100,0,1000); TH2D* Vertex_vs_Angle = new TH2D("Vertex_vs_Angle","Vertex_vs_Angle",1000,0,1000,200,0,180); TCutG *cutg = new TCutG("CUTG",27); cutg->SetVarX("Q02_Kine"); cutg->SetVarY(""); cutg->SetTitle("Graph"); cutg->SetFillColor(1); cutg->SetPoint(0,13.91253,83.41335); cutg->SetPoint(1,16.43826,70.76698); cutg->SetPoint(2,29.69832,47.3185); cutg->SetPoint(3,32.22404,36.51639); cutg->SetPoint(4,49.90412,29.13934); cutg->SetPoint(5,68.21562,18.86417); cutg->SetPoint(6,79.79186,15.70258); cutg->SetPoint(7,86.73761,10.96019); cutg->SetPoint(8,86.52713,6.217797); cutg->SetPoint(9,77.05566,5.427399); cutg->SetPoint(10,69.26801,8.325526); cutg->SetPoint(11,55.79747,15.17564); cutg->SetPoint(12,50.53555,20.9719); cutg->SetPoint(13,35.80215,25.97775); cutg->SetPoint(14,31.17165,21.23536); cutg->SetPoint(15,24.43639,19.3911); cutg->SetPoint(16,19.80589,24.39695); cutg->SetPoint(17,20.01637,30.98361); cutg->SetPoint(18,22.75257,36.25293); cutg->SetPoint(19,21.91066,46.79157); cutg->SetPoint(20,16.0173,54.16862); cutg->SetPoint(21,8.229653,66.02459); cutg->SetPoint(22,6.545836,73.13817); cutg->SetPoint(23,7.177267,86.04801); cutg->SetPoint(24,11.59729,88.15574); cutg->SetPoint(25,13.70206,83.41335); cutg->SetPoint(26,13.91253,83.41335); TCutG *cutg2 = new TCutG("CUTG2",6); cutg2->SetVarX("Q02_Kine"); cutg2->SetVarY(""); cutg2->SetTitle("Graph"); cutg2->SetFillColor(1); cutg2->SetPoint(0,54.85507,28.95589); cutg2->SetPoint(1,64.59005,23.76482); cutg2->SetPoint(2,64.52764,10.0358); cutg2->SetPoint(3,54.81763,12.22152); cutg2->SetPoint(4,54.86755,29.0242); cutg2->SetPoint(5,54.85507,28.95589); TCutG *cutg3 = new TCutG("CUTG2",6); cutg3->SetVarX("Q02_Kine"); cutg3->SetVarY(""); cutg3->SetTitle("Graph"); cutg3->SetFillColor(1); cutg3->SetPoint(0,27.46418,21.43491); cutg3->SetPoint(1,37.45702,16.44231); cutg3->SetPoint(2,37.13467,2.463016); cutg3->SetPoint(3,27.46418,4.792898); cutg3->SetPoint(4,27.78653,21.43491); cutg3->SetPoint(5,27.46418,21.43491); TTreeReader Reader1("cbmsim", file); TTreeReaderValue<TClonesArray> analysisArray(Reader1, "ATProtoEventAna"); Int_t evnt = 0; while (Reader1.Next()) { if(evnt%1000==0) std::cout<<" Event : "<<evnt<<std::endl; evnt++; ATProtoEventAna* analysis = (ATProtoEventAna*) analysisArray->At(0); //Double_t ATProtoAnalysis::*HoughDist = &ATProtoAnalysis::fHoughDist; std::vector<Double_t> *AngleFit = analysis->GetAngleFit(); std::vector<Double_t> *Par0 = analysis->GetPar0(); std::vector<Double_t> *vertex = analysis->GetVertex(); std::vector<Double_t> *Chi2 = analysis->GetChi2(); std::vector<Int_t> *NDF = analysis->GetNDF(); if( TMath::Abs(vertex->at(0) - vertex->at(2))<20 && (vertex->at(0)>0 && vertex->at(2)>0)) if( Chi2->at(0)/NDF->at(0)<10.0 && Chi2->at(2)/NDF->at(2)<10.0 ) Q02_Kine->Fill(AngleFit->at(0),AngleFit->at(2)); if( TMath::Abs(vertex->at(1) - vertex->at(3))<20 && (vertex->at(1)>0 && vertex->at(3)>0)) if( Chi2->at(1)/NDF->at(1)<10.0 && Chi2->at(3)/NDF->at(3)<10.0 ) Q02_Kine->Fill(AngleFit->at(1),AngleFit->at(3)); if(cutg->IsInside(AngleFit->at(0),AngleFit->at(2)) ) { Vertex->Fill(Par0->at(0)); Vertex_vs_Angle->Fill(Par0->at(0),AngleFit->at(0)); } if(cutg->IsInside(AngleFit->at(1),AngleFit->at(3)) ) { Vertex->Fill(Par0->at(1)); Vertex_vs_Angle->Fill(Par0->at(1),AngleFit->at(1)); } //if(cutg3->IsInside(AngleFit->at(0),AngleFit->at(2)) ) std::cout<<evnt<<std::endl; } Double_t *ThetaCMS = new Double_t[20000]; Double_t *ThetaLabRec = new Double_t[20000]; Double_t *EnerLabRec = new Double_t[20000]; Double_t *ThetaLabSca = new Double_t[20000]; Double_t *EnerLabSca = new Double_t[20000]; Double_t *ThetaCMS2 = new Double_t[20000]; Double_t *ThetaLabRec2 = new Double_t[20000]; Double_t *EnerLabRec2 = new Double_t[20000]; Double_t *ThetaLabSca2 = new Double_t[20000]; Double_t *EnerLabSca2 = new Double_t[20000]; std::ifstream *kineStr = new std::ifstream(fileKine.Data()); Int_t numKin=0; if(!kineStr->fail()) { while(!kineStr->eof()) { *kineStr>>ThetaCMS[numKin]>>ThetaLabRec[numKin]>>EnerLabRec[numKin]>>ThetaLabSca[numKin]>>EnerLabSca[numKin]; numKin++; } } else if(kineStr->fail()) std::cout<<" Warning : No Kinematics file found for this reaction! Please run the macro on $SIMPATH/macro/Kinematics/Decay_kinematics/Mainrel.cxx"<<std::endl;
void CsIProj() { TFile *file = new TFile("../root/NZ_55_New.root"); TFile *gates = new TFile("../gates/zlines.root"); TFile *gates2 = new TFile("../gates/zlines_new.root"); ofstream ofile("CsI_55A_New.dat"); TCanvas *mycan = (TCanvas*)gROOT->FindObjectAny("mycan"); if(!mycan) { mycan = new TCanvas("mycan","mycan"); mycan->Divide(1,2); } ostringstream outstring; string name; int p1= 30, p2=50; //+- fit limits up to 2 peaks. May be different. int const num_par = 5; //number of peaks times 2(pol1)+3(gaus). for(int ic =0;ic<56;ic++) { outstring.str(""); outstring << "dEE/dEE_" << ic; name = outstring.str(); mycan->cd(1); TH2I *hist = (TH2I*)file->Get(name.c_str()); hist->Draw("col"); hist->GetXaxis()->SetRangeUser(200.,1800.); hist->GetYaxis()->SetRangeUser(5.,50.); if(ic <16 || ic > 31) TCutG *mycut = (TCutG*)gates->Get(Form("Zline_%i_2_4",ic)); else TCutG *mycut = (TCutG*)gates2->Get(Form("Zline_%i_2_4",ic)); mycut->Draw(); file->cd(); outstring.str(""); outstring << "CsI/CsIGate/ECsI_" << ic << "_Gate"; name = outstring.str(); gPad->SetLogz(); mycan->cd(2); TH1I * proj = (TH1I*)file->Get(name.c_str()); proj->Draw(); proj->Rebin(4); proj->GetXaxis()->SetRangeUser(700.,1800.); mycan->Modified(); mycan->Update(); TMarker * mark; mark=(TMarker*)mycan->WaitPrimitive("TMarker"); //Get the Background limits int bkg_lo = mark->GetX(); delete mark; mark=(TMarker*)mycan->WaitPrimitive("TMarker"); int bkg_hi = mark->GetX(); delete mark; mark=(TMarker*)mycan->WaitPrimitive("TMarker"); // Get the 1st peak initial guess int peak1 = mark->GetX(); delete mark; double par[num_par] = {0.}; double out[num_par] = {0.}; int peak1_lo = peak1 - p1, peak1_hi = peak1 + p1; // Peak center and limits TF1 *l1 = new TF1("l1", "pol1", bkg_lo, bkg_hi); TF1 *g1 = new TF1("g1", "gaus", peak1_lo,peak1_hi); TF1 *total = new TF1("total", "pol1(0)+gaus(2)", bkg_lo,bkg_hi); proj->Fit(l1,"R"); proj->Fit(g1,"R+"); l1->GetParameters(&par[0]); g1->GetParameters(&par[2]); total->SetParameters(par); proj->Fit(total,"R"); total->GetParameters(out); ofile << ic << " " << out[3] << endl; outstring.str(""); outstring << "55A_" << ic; name = outstring.str(); total->SetName(name.c_str()); total->Draw("same"); mycan->Modified(); mycan->Update(); bool IsGood = 0; cout << "Good fit?" << endl; cin >> IsGood; if(IsGood) { ofile << ic << " " << out[3] << endl; } else ofile << ic << " " << -1 << endl; } return; }
//dEdx cut based on graphical cut defined in dEdxCut.cpp void RunDedxCut(TString inputfile, TString outputfile, TString system, Int_t energy) { cout << "Running dE/dx mode with energy " << energy << endl; TCutG* cutg = initialise_dedx_cutg(system, energy); cout << "Graphcut intialized" << endl; TFile *input_rootfile = new TFile(inputfile); TTree* input_tree = (TTree*)input_rootfile->Get("events"); ParticleTree output_tree(outputfile); Event *event = new Event(); Particle *particle; input_tree->SetBranchAddress("event",&event); const Long64_t treeNentries = input_tree->GetEntries(); Long64_t ev; UInt_t Npa; UInt_t part; Float_t local_dedx; Float_t dedx_uppercut = 3.; if(!(system.CompareTo("PbPb"))) { if((energy == 158 ) || (energy == 160)) dedx_uppercut = 1.65; else if(energy == 20) dedx_uppercut = 1.6; } float p; cout << "Cut dE/dx > " << dedx_uppercut << " applied" << endl; for(ev=0; ev<treeNentries; ++ev) { if(!(ev%500)) cout << "Event: " << ev << endl; input_tree->GetEntry(ev); Npa = event->GetNpa(); output_tree.BeginEvent(); for(part=0; part<Npa; part++) { particle = event->GetParticle(part); p = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2)+TMath::Power(particle->GetPz(),2)); local_dedx = choose_dedx(particle, system); if(cutg->IsInside(p,local_dedx)) continue; if(local_dedx > dedx_uppercut) continue; output_tree.AddParticle(particle->GetCharge(), particle->GetBx(), particle->GetBy(), particle->GetPx(), particle->GetPy(), particle->GetPz(), particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(), particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc()); } output_tree.EndEvent(); } output_tree.Close(); input_rootfile->Close(); }
//Definitions of graphical cuts for all pp energies and 20/158 energies of PbPb TCutG* initialise_dedx_cutg(TString system, Int_t energy) { TCutG *cutg = new TCutG(); if(!(system.CompareTo("pp"))) { switch(energy) { case 158: { std::cout << "Using p+p@158 cut (12E002)" << std::endl; cutg = new TCutG("dedx_cut",10); cutg->SetTitle("e^{-} dE/dx cut for 12E002 p+p @ 158 GeV/c"); cutg->SetFillColor(1); cutg->SetPoint(0,0.344283,1.90); cutg->SetPoint(1,0.344283,1.20); cutg->SetPoint(2,1.58,1.35); cutg->SetPoint(3,3.4829,1.40727); cutg->SetPoint(4,10.50171,1.45138); cutg->SetPoint(5,20,1.49148); cutg->SetPoint(6,20,1.65589); cutg->SetPoint(7,2.57344,1.90); cutg->SetPoint(8,0.396975,1.90); cutg->SetPoint(9,0.3442825,1.90); break; } case 80: { std::cout << "Using p+p@80 cut (12E002)" << std::endl; cutg = new TCutG("dedx_cut",13); cutg->SetTitle("e^{-} dE/dx cut for 12E002 p+p @ 80 GeV/c"); cutg->SetFillColor(1); cutg->SetPoint(0,0.284871,1.84884); cutg->SetPoint(1,0.369055,1.36919); cutg->SetPoint(2,0.705019,1.33804); cutg->SetPoint(3,2.03808,1.38164); cutg->SetPoint(4,5.38127,1.43148); cutg->SetPoint(5,12.3227,1.46885); cutg->SetPoint(6,24.1579,1.52492); cutg->SetPoint(7,23.5404,1.62458); cutg->SetPoint(8,8.14319,1.76786); cutg->SetPoint(9,2.67477,1.89867); cutg->SetPoint(10,0.974441,1.95473); cutg->SetPoint(11,0.404061,1.96096); cutg->SetPoint(12,0.284871,1.84884); break; } case 40: { std::cout << "Using p+p@40 cut (12E002)" << std::endl; cutg = new TCutG("dedx_cut",12); cutg->SetTitle("e^{-} dE/dx cut for 12E002 p+p @ 40 GeV/c"); cutg->SetFillColor(1); cutg->SetPoint(0,0.171942,1.26952); cutg->SetPoint(1,0.761963,1.33804); cutg->SetPoint(2,2.11879,1.38164); cutg->SetPoint(3,9.6357,1.48754); cutg->SetPoint(4,13.4915,1.51246); cutg->SetPoint(5,10.8264,1.72425); cutg->SetPoint(6,1.47457,1.87998); cutg->SetPoint(7,0.580588,1.91736); cutg->SetPoint(8,0.153032,1.86752); cutg->SetPoint(9,0.0843649,1.72425); cutg->SetPoint(10,0.0960249,1.61836); cutg->SetPoint(11,0.171942,1.26952); break; } case 31: { std::cout << "Using p+p@31 cut (12E002)" << std::endl; cutg = new TCutG("dedx_cut",13); cutg->SetTitle("e^{-} dE/dx cut for 12E002 p+p @ 31 GeV/c"); cutg->SetFillColor(1); cutg->SetPoint(0,0.127665,1.26329); cutg->SetPoint(1,0.420062,1.30689); cutg->SetPoint(2,1.06687,1.3505); cutg->SetPoint(3,2.78069,1.40656); cutg->SetPoint(4,10.1478,1.46262); cutg->SetPoint(5,12.6459,1.51869); cutg->SetPoint(6,12.1642,1.6495); cutg->SetPoint(7,2.74493,1.74917); cutg->SetPoint(8,0.611444,1.81146); cutg->SetPoint(9,0.267016,1.83638); cutg->SetPoint(10,0.101128,1.73671); cutg->SetPoint(11,0.0877058,1.56229); cutg->SetPoint(12,0.127665,1.26329); break; } case 20: { std::cout << "Using p+p@20 cut (12E002)" << std::endl; cutg = new TCutG("dedx_cut",11); cutg->SetTitle("e^{-} dE/dx cut for 12E002 p+p @ 20 GeV/c"); cutg->SetFillColor(1); cutg->SetPoint(0,0.0459112,1.62458); cutg->SetPoint(1,0.627482,1.78654); cutg->SetPoint(2,3.20625,1.7554); cutg->SetPoint(3,9.38942,1.61836); cutg->SetPoint(4,9.14944,1.48131); cutg->SetPoint(5,3.46521,1.42525); cutg->SetPoint(6,1.0396,1.38787); cutg->SetPoint(7,0.465898,1.31312); cutg->SetPoint(8,0.193189,1.27575); cutg->SetPoint(9,0.0843649,1.14493); cutg->SetPoint(10,0.0459112,1.62458); break; } } } else if(!(system.CompareTo("PbPb"))) { switch(energy) { case 160: case 158: { std::cout << "Using Pb+Pb@158 cut (00B)" << std::endl; cutg = new TCutG("dedx_cut",18); cutg->SetTitle("e^{-} dE/dx cut for 00B Pb+Pb @ 160 GeV/c"); cutg->SetPoint(0,0.425317,1.89959); cutg->SetPoint(1,2.7223,1.89959); cutg->SetPoint(2,4.71651,1.86649); cutg->SetPoint(3,7.05759,1.83339); cutg->SetPoint(4,10.8218,1.7861); cutg->SetPoint(5,19.449,1.66315); cutg->SetPoint(6,19.2129,1.5733); cutg->SetPoint(7,12.0792,1.53074); cutg->SetPoint(8,6.02148,1.48818); cutg->SetPoint(9,3.78571,1.43143); cutg->SetPoint(10,2.59251,1.38887); cutg->SetPoint(11,1.5522,1.35577); cutg->SetPoint(12,1.02473,1.28484); cutg->SetPoint(13,0.701748,1.25646); cutg->SetPoint(14,0.529891,1.21863); cutg->SetPoint(15,0.376419,1.2139); cutg->SetPoint(16,0.376419,1.89959); cutg->SetPoint(17,0.425317,1.89959); break; } case 20: { std::cout << "Using Pb+Pb@20 cut (03A)" << std::endl; cutg = new TCutG("dedx_cut",15); cutg->SetTitle("e^{-} dE/dx cut for 03A Pb+Pb @ 20 GeV/c"); cutg->SetFillColor(1); cutg->SetPoint(0,0.0606792,1.7197); cutg->SetPoint(1,1.02568,1.83407); cutg->SetPoint(2,2.90105,1.80999); cutg->SetPoint(3,6.87075,1.70766); cutg->SetPoint(4,6.87075,1.60534); cutg->SetPoint(5,2.90105,1.52709); cutg->SetPoint(6,1.59862,1.44282); cutg->SetPoint(7,0.837351,1.37059); cutg->SetPoint(8,0.523797,1.34651); cutg->SetPoint(9,0.260795,1.31641); cutg->SetPoint(10,0.192372,1.2803); cutg->SetPoint(11,0.157049,1.21409); cutg->SetPoint(12,0.0630318,1.25622); cutg->SetPoint(13,0.0599146,1.5933); cutg->SetPoint(14,0.0606792,1.7197); break; } } } else std::cout << "Unknown system" << std::endl << "Type \"pp\" or \"PbPb\"" << std::endl; cutg->SetVarX("TMath::Log10(p)"); cutg->SetVarY("dedx"); return cutg; }
int main(int argc, char * argv[]) { TFile *f = new TFile(argv[1]); TFile *f2 = new TFile(argv[2]); TTree *tree = (TTree*) f->Get("adc"); // TCut CutXYZ = TCut; // TCut CutTrigger; TCutG *CutZX = (TCutG*) f2->Get("cutg_0_3_B2"); TCutG *CutZY = (TCutG*) f2->Get("cutg_1_3_B2"); TCut broadCut = "ch6 > 1100"; TCut crystal = "FloodX > -1.5 && FloodX < -1 && FloodY > -1.45 &&FloodY < -0.9"; // TCut crystal = "FloodX > -4 && FloodX < -3.6 && FloodY > -1.28 &&FloodY < -1.02"; TCut photopeak = "ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 > 9500 && ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 < 12500"; // TCut photopeak = "ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 > 8500 && ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 < 11000"; TCut trigger = "TriggerChannel == 6"; // TCut trigger = "TriggerChannel == 2"; std::string w = "ch6/(ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15)"; // std::string w = "ch2/(ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15)"; TCut wCut = "FloodZ > 0.3 && FloodZ < 0.5"; TH1F *h = new TH1F("h","h",1000,0,35000); TH1F *hSum = new TH1F("hSum","hSum",1000,0,35000); TH1F *hCorrSig = new TH1F("hCorrSig","hCorrSig",1000,0,35000); TH1F *hCorrLinear = new TH1F("hCorrLinear","hCorrLinear",1000,0,35000); TH2F *h2 =new TH2F ("h2","h2",1000,-7,7,1000,-7,7); TH3I *h3 = new TH3I("h3","h3",100,-3,0,100,-3,0,100,0,1); TH1F *hAll = new TH1F("hAll","hAll",500,0,1); TH1F *hNear = new TH1F("hNear","hNear",500,0,1); TH1F *hFloodZ = new TH1F("hFloodZ","hFloodZ",500,0,1); TH2F *scatter = new TH2F("scatter","scatter",500,0,1,500,0,1); TH2F *correction = new TH2F("correction","correction",500,0,1,1000,0,35000); TCanvas *multi = new TCanvas("multi","multi",1800,1200); multi->Divide(3,3); multi->cd(1); // h2->GetXaxis()->SetRangeUser(-4.1,-3.5); // h2->GetYaxis()->SetRangeUser(-1.3,-1.0); // std::cout << "quiiiiiiiiiiiiiiiiii" << std::endl; tree->Draw("FloodZ:FloodY:FloodX >> h3",broadCut+trigger+CutZX->GetName()+CutZY->GetName()); // std::cout << "dopo" << std::endl; h2->GetXaxis()->SetRangeUser(-1.5,-1); h2->GetYaxis()->SetRangeUser(-1.45,-0.9); h3->GetXaxis()->SetRangeUser(-3,0); h3->GetYaxis()->SetRangeUser(-3,0); // tree->Draw("FloodY:FloodX >> h2","","COLZ"); // multi->cd(2); // tree->Draw("ch1+ch2+ch3+ch5+ch6+ch7+ch9+ch10+ch11 >> h",crystal); multi->cd(2); tree->Draw("ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 >> hSum",broadCut+trigger+CutZX->GetName()+CutZY->GetName()); multi->cd(3); // tree->Draw("ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 : ch2/(ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15) >> correction",crystal+photopeak,"COLZ"); tree->Draw("ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 : FloodZ >> correction",trigger+photopeak+broadCut+CutZX->GetName()+CutZY->GetName(),"COLZ"); multi->cd(4); correction->FitSlicesY(0, 0, -1, 0, "RQ"); TH1D *spectrum2d_1 = (TH1D*)gDirectory->Get("correction_1"); // _1 is the TH1D automatically created by ROOT when FitSlicesX is called, holding the TH1F of the mean values spectrum2d_1->GetYaxis()->SetRangeUser(10200,11400); TF1 *sig1 = new TF1("sig1", sigmoid,0,1,4); sig1->SetParameter( 0, 10500); sig1->SetParameter( 1, 700); sig1->SetParameter( 2, 30); sig1->SetParameter( 3, 0.4); double a = sig1->GetParameter(0); double b = sig1->GetParameter(1); double c = sig1->GetParameter(2); double d = sig1->GetParameter(3); spectrum2d_1->Fit(sig1,"QR"); double medianPoint = d - (1/c)*TMath::Log(3); medianPoint = 0.3966; std::cout << "medianPoint = " << medianPoint << std::endl; multi->cd(5); std::stringstream baseVar,var; std::stringstream sSig0,sSigw; sSig0 << "(" << a << " + (" << b << " * ( 0.5 - 1/(1 + TMath::Exp( -" << c << " * ( " << medianPoint << " - " << d << ") ) ) ) ) ) "; sSigw << "(" << a << " + (" << b << " * ( 0.5 - 1/(1 + TMath::Exp( -" << c << " * ( " << "FloodZ" << " - " << d << ") ) ) ) ) )"; baseVar << "((ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15) * (" << sSig0.str() << " / " << sSigw.str() << "))"; // baseVar << "((ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15) + ( " // << b // << " * ( 0.5 - 1/(1 + TMath::Exp( -" // << c // << " * ( " // << "FloodZ" // << " - " // << d // << ") ) ) ) )) "; var << baseVar.str() << ">> hCorrSig"; tree->Draw(var.str().c_str(),broadCut+trigger+CutZX->GetName()+CutZY->GetName()); TF1 *gauss = new TF1("gauss","[0]*exp(-0.5*((x-[1])/[2])**2)",10000,12000); gauss->SetParameter(0,1600); gauss->SetParameter(1,10000); gauss->SetParameter(2,600); hCorrSig->Fit(gauss,"RQ"); std::stringstream cutPeakSig ; cutPeakSig << baseVar.str() << ">" << gauss->GetParameter(1) - 4.0*gauss->GetParameter(2) << " && " << baseVar.str() << "<" << gauss->GetParameter(1) + 4.0*gauss->GetParameter(2) ; TCut photopeakCorrSig = cutPeakSig.str().c_str(); TH1F *clone = new TH1F("clone","clone",1000,0,35000); clone->SetFillStyle(3001); clone->SetFillColor(3); var.str(""); var << baseVar.str() << ">> clone"; tree->Draw(var.str().c_str(),broadCut+trigger+CutZX->GetName()+CutZY->GetName()+photopeakCorrSig,"same"); // clone->Draw("same"); var.str(""); multi->cd(7); TH1D* spectrum2d_1_copy = (TH1D*) spectrum2d_1->Clone(); spectrum2d_1_copy->Draw(); spectrum2d_1_copy->GetYaxis()->SetRangeUser(10200,11400); TF1 *linearCrystal = new TF1("linearCrystal", "[0]*x + [1]",0.35,0.42); spectrum2d_1_copy->Fit(linearCrystal,"RQ"); multi->cd(8); baseVar.str(""); baseVar << "(( ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 ) * ( (" << linearCrystal->GetParameter(0) * medianPoint + linearCrystal->GetParameter(1) << ") / (" << linearCrystal->GetParameter(0) << "* FloodZ + "<< linearCrystal->GetParameter(1) << " ))) >> hCorrLinear"; // baseVar << "(( ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15 ) - ( (" << w << " - " << d - (1/c)*TMath::Log(1 + (b/(a+(b/2) -a))) << " ) * ( " << linearCrystal->GetParameter(0) << ") )) >> hCorrLinear"; tree->Draw(baseVar.str().c_str(),broadCut+trigger+CutZX->GetName()+CutZY->GetName()); // TF1 *gauss2 = new TF1("gauss2","[0]*exp(-0.5*((x-[1])/[2])**2)",10000,12000); // gauss2->SetParameter(0,1600); // gauss2->SetParameter(1,10000); // gauss2->SetParameter(2,600); // hCorrLinear->Fit(gauss2,"RQ"); // multi->cd(7); // tree->Draw("FloodZ >> hFloodZ",crystal+photopeak); // TF1 *fit1 = new TF1("fit1",thetaFunction,0,1,3); // fit1->SetParameter( 0, 0.36); // on this w histo, the first bin above 20% max // fit1->SetParameter( 1, 0.54); // on this w histo, the last bin above 20% max // fit1->SetParameter( 2, 1200); // hFloodZ->Fit(fit1,"R"); multi->cd(6); tree->Draw("ch6/(ch1+ch2+ch3+ch5+ch6+ch7+ch9+ch10+ch11) >> hNear",broadCut+ photopeakCorrSig+CutZX->GetName()+CutZY->GetName()); TF1 *fit2 = new TF1("fit2",thetaFunction,0,1,3); fit2->SetParameter( 0, 0.36); // on this w histo, the first bin above 20% max fit2->SetParameter( 1, 0.54); // on this w histo, the last bin above 20% max fit2->SetParameter( 2, 1200); hNear->Fit(fit2,"RQ"); multi->cd(9); tree->Draw("ch6/(ch0+ch1+ch2+ch3+ch4+ch5+ch6+ch7+ch8+ch9+ch10+ch11+ch12+ch13+ch14+ch15) >> hAll",broadCut+photopeakCorrSig+CutZX->GetName()+CutZY->GetName()); TF1 *fit3 = new TF1("fit1",thetaFunction,0,1,3); fit3->SetParameter( 0, 0.1); // on this w histo, the first bin above 20% max fit3->SetParameter( 1, 0.8); // on this w histo, the last bin above 20% max fit3->SetParameter( 2, 1200); hAll->Fit(fit3,"RQ"); std::cout << linearCrystal->GetParameter(0) << " " << linearCrystal->GetParameter(1) << std::endl; std::cout << fit2->GetParameter(0) << " " << fit2->GetParameter(1) << std::endl; std::cout << fit3->GetParameter(0) << " " << fit3->GetParameter(1) << std::endl; std::cout << "Energy Resolution Corrected (Sigmoid) = " << gauss->GetParameter(2)*2.355 / gauss->GetParameter(1) << std::endl; std::cout << "Near Channels - Delta w = " << fit2->GetParameter(1) - fit2->GetParameter(0) << std::endl; std::cout << "All Channels - Delta w = " << fit3->GetParameter(1) - fit3->GetParameter(0) << std::endl; TFile *fOut= new TFile("afile.root","RECREATE"); fOut->cd(); multi->Write(); fOut->Close(); return 0; }