#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #include "TH1F.h" #include "TF1.h" #include "TF2.h" #include "TF3.h" #include "TH2F.h" #include "TH3F.h" #include "TImage.h" #include "TCanvas.h" #include "TFile.h" #include "TExec.h" #include "TLine.h" #include "TProfile.h" #include "TError.h" #include "TNtuple.h" #include "TVector.h" #include "TGraph.h" #include "TGraph2D.h" #include "TGraphErrors.h" #include "TMultiGraph.h" #include "TPolyLine3D.h" #include "TPad.h" #include "TGaxis.h" #include "TAttLine.h" #include "TAttFill.h" #include "TApplication.h" #include "THStack.h" #include #include #include "TTree.h" #include "TBranch.h" #include "TChain.h" #include #include #include #include #include "TStyle.h" #include "TTreeViewer.h" #include "TTreeReader.h" #include "TTreeReaderValue.h" #include "TTreeReaderArray.h" #include "TLegend.h" #include "TLatex.h" #include "TPaveStats.h" #include #include #include #include #include #include #include #include #include #include #include "TAxis3D.h" #include "TView.h" #include #include "TPaletteAxis.h" #include "TDecompLU.h" #include "TPolyMarker3D.h" #include "TMarker3DBox.h" #include "TGLViewer.h" #include "TView3D.h" #include "TRootBrowser.h" #include "TBrowser.h" #include "TBenchmark.h" #include "TSystem.h" int main(int argc, char* argv[]){ TApplication *myApp = new TApplication("myApp", &argc, argv ,0,-1); if (argc<1+1){//I'll ask for one argument in argv cout<Start("all"); //starts the timer TFile file("TenTracks-ohdu2-run300-Zoomed.root"); //opens the file TTreeReader reader("hitSumm", &file); //declares the reader // To create the values I want. Name and template type must match the ones in the tree TTreeReaderValue nSavedPix(reader, "nSavedPix"); TTreeReaderValue flag(reader, "flag"); TTreeReaderValue xMax(reader, "xMax"); TTreeReaderValue xMin(reader, "xMin"); TTreeReaderValue yMax(reader, "yMax"); TTreeReaderValue yMin(reader, "yMin"); TTreeReaderValue E0(reader, "E0"); TTreeReaderValue gain(reader, "gainCu"); TTreeReaderArray xPix(reader, "xPix"); TTreeReaderArray yPix(reader, "yPix"); TTreeReaderArray level(reader, "level"); TTreeReaderArray ePix(reader, "ePix"); int TrackCounter=0; //track counter int TopTracks=9; //Number of tracks I'll work with (max is 9) int zoom1=1000; int zoom2=1200; //Limits if I want to work in a sub section bool saveImage=(bool) strtof(argv[1], NULL); string FileNameT=Form("%dTracksFitted",TopTracks); // Pre-defining variables I'll use later float Chisq=0; int NDF=0; // Start looping in the tree while (reader.Next()) { //I'll ask that there're no errors if(*flag!=0) continue; if (*xMinzoom2) continue; if(TopTracks<0 || TrackCounter>=TopTracks) break; TH2F * hTracks= new TH2F("Tracks",Form("Track %d",TrackCounter+1), *xMax-*xMin+10+10,*xMin-5,*xMax+5+10, *yMax-*yMin+10+10,*yMin-5,*yMax+5+10); //To draw the whole tracks ostringstream hTitle; hTitle<<"Track "<SetTitle(Form("Track %d",TrackCounter+1)); // Looping over all saved pixels in the track to fill the histogram for (int j=0;j<*nSavedPix;++j){ if(level[j]>0) break;// Filter pixels in level 0 // Now I'll fill the histogram, setting the bin's content to ePix/gain=energy in keV: hTracks->SetBinContent(xPix[j]-(*xMin-5), yPix[j]-(*yMin-5), ePix[j]/ *gain); } //ends the loop {// Begin fitting hTracks->Fit("pol1","Q"); hTracks->GetFunction("pol1")->SetRange(*xMin,*xMax); } Chisq=hTracks->GetFunction("pol1")->GetChisquare(); NDF=hTracks->GetFunction("pol1")->GetNDF(); TCanvas *c = new TCanvas("c", "Canvas",60,60,600,600); c->SetFillColor(kWhite); c->SetFrameFillColor(kWhite);// The background is white gStyle->SetPalette(kRainBow); //for the rainbow palette TGaxis::SetMaxDigits(4); //Significant digits in both axis and colorbar c->SetLogz(); hTracks->GetFunction("pol1")->SetLineColor(kBlack); hTracks->GetXaxis()->SetTitle("x axis"); hTracks->GetYaxis()->SetTitle("y axis"); hTracks->GetYaxis()->SetTitleOffset(0.95); hTracks->SetMinimum(0); hTracks->SetMaximum(10); hTracks->Draw("colz"); {//To form a legend gStyle->SetOptStat(0); TLegend *legend = new TLegend(0.15, 0.8, 0.65, 0.9); ostringstream legChisq; legChisq<<"Chi square/NDF: "<Draw(); c->Update(); } // Saving the histograms in an unique pdf file if(saveImage){ c->Draw();c->Modified(); c->Update(); if(TopTracks>1){ if(TrackCounter+1==1) c->Print(("Histograms/"+FileNameT+".pdf(").c_str(),"pdf"); else if(TrackCounter+1==TopTracks) c->Print(("Histograms/"+FileNameT+".pdf)").c_str(),"pdf"); else c->Print(("Histograms/"+FileNameT+".pdf").c_str(),"pdf"); } else if(TopTracks==1) c->Print(("Histograms/"+FileNameT+".pdf").c_str(),"pdf"); delete c; } TrackCounter++; }//Ends looping the tree cout<<"Tracks looped (flag=0): "<Stop("all"); //stops and returns the timer cout<Run(); // allows the halt of the script execution return 0; }