int RDK2Events::loadEvents(TString fileName,TString treeName) { if(eventFile!=nullptr){ eventFile->Close(); delete eventFile; } if(ranGen==nullptr) { ranGen=new TRandom3(); } eventFilePath = fileName; eventFile = new TFile(fileName,"READ"); //Check to see if file was succesfully opened if(eventFile->IsZombie()){ reset(); return -1; } //Get Tree from file eventTree=(TTree*) eventFile->Get(treeName); TBranch* n = eventTree->GetBranch("n"); numEvents=n->GetEntries(); eventStart=0; eventEnd=eventStart+numEvents-1; //Set our branch addresses for filling eventTree->SetBranchAddress("x0",&x0); eventTree->SetBranchAddress("y0",&y0); eventTree->SetBranchAddress("z0",&z0); eventTree->SetBranchAddress("ee0",&ee0); eventTree->SetBranchAddress("mxe0",&mxe0); eventTree->SetBranchAddress("mye0",&mye0); eventTree->SetBranchAddress("mze0",&mze0); eventTree->SetBranchAddress("ep0",&ep0); eventTree->SetBranchAddress("mxp0",&mxp0); eventTree->SetBranchAddress("myp0",&myp0); eventTree->SetBranchAddress("mzp0",&mzp0); eventTree->SetBranchAddress("eg0",&eg0); eventTree->SetBranchAddress("mxg0",&mxg0); eventTree->SetBranchAddress("myg0",&myg0); eventTree->SetBranchAddress("mzg0",&mzg0); //If eg0 is greater than 0 than it must be a four body decay if(eventTree->GetBranch("eg0")->GetEntry(0)>0) fourBody=true; else fourBody=false; return 0; }
int PlotSignals(char *filename, int plfrom=0, int plto=100, int same=1) { bragg_signal signal; TFile *fin=new TFile(filename); if (!fin->IsOpen()) { std::cout << "file not found! " << std::endl; return -1; } TTree *tree = (TTree*)fin->Get("bragg"); if (!tree) { std::cout << "Bragg tree not found! " << std::endl; return -2; } TBranch *br = tree->GetBranch("signals"); if (!br) { std::cout << "Signal branch not found! " << std::endl; return -3; } br->SetAddress(&signal); int nev = br->GetEntries(); std::cout << "Number of events in file : " << nev << std::endl; for (int i=plfrom; i<plto; i++) { br->GetEntry(i); plotSignal(signal,same); } return 0; }
bool is_same_size_tree(TTree *tree, Long_t *prev_entries, bool *first) { Long_t entries; TObjArray *ar = tree->GetListOfBranches(); for(Long_t i = 0; i < ar->GetEntries(); i++) { TBranch *br = (TBranch*)(*ar)[i]; entries = br->GetEntries(); if ((!*first) && (entries != *prev_entries)) { return false; } *prev_entries = entries; *first = false; } return true; }
// Commands executed in a GLOBAL scope, e.g. created hitograms aren't erased... void plot_HF(TString inputfile="simevent_HF.root", TString outputfile="HF_histo.root", Int_t drawmode = 2, TString reffile="../data/HF_ref.root") { // Option to no-action(0)/draw(1)/save(2) (default = 0) histograms in gif. //int doDraw = 0; int doDraw = drawmode; char * treename = "Events"; //The Title of Tree. delete gROOT->GetListOfFiles()->FindObject(inputfile); TFile * myf = new TFile(inputfile); TTree * tree = dynamic_cast<TTree*>(myf->Get("Events")); assert(tree != 0); TBranch * branchLayer = tree->GetBranch("PHcalValidInfoLayer_g4SimHits_HcalInfoLayer_CaloTest.obj"); assert(branchLayer != 0); TBranch * branchNxN = tree->GetBranch("PHcalValidInfoNxN_g4SimHits_HcalInfoNxN_CaloTest.obj"); assert(branchNxN != 0); TBranch * branchJets = tree->GetBranch( "PHcalValidInfoJets_g4SimHits_HcalInfoJets_CaloTest.obj"); assert(branchJets != 0); // Just number of entries (same for all branches) int nent = branchLayer->GetEntries(); cout << "Entries branchLayer : " << nent << endl; nent = branchJets->GetEntries(); cout << "Entries branchJets : " << nent << endl; nent = branchNxN->GetEntries(); cout << "Entries branchNxN : " << nent << endl; // Variables from branches PHcalValidInfoJets infoJets; branchJets->SetAddress( &infoJets); PHcalValidInfoLayer infoLayer; branchLayer->SetAddress( &infoLayer); PHcalValidInfoNxN infoNxN; branchNxN->SetAddress( &infoNxN); //*************************************************************************** // Histo titles-labels const int Nhist1 = 20, Nhist2 = 1; // N simple and N combined histos const int Nhist1spec = 5; // N special out of Nsimple total TH1F *h; // just a pointer TH1F *h1[Nhist1]; TH2F *h2g; // + eta-phi grid -related for all depthes char *label1[Nhist1]; char *label2g; // simple histos label1[0] = &"rJetHits.gif"; label1[1] = &"tJetHits.gif"; label1[2] = &"eJetHits.gif"; label1[3] = &"ecalJet.gif"; label1[4] = &"hcalJet.gif"; label1[5] = &"etotJet.gif"; label1[6] = &"jetE.gif"; label1[7] = &"jetEta.gif"; label1[8] = &"jetPhi.gif"; label1[9] = &"etaHits.gif"; label1[10] = &"phiHits.gif"; label1[11] = &"eHits.gif"; label1[12] = &"tHits.gif"; label1[13] = &"eEcalHF.gif"; label1[14] = &"eHcalHF.gif"; // special label1[15] = &"tHits_60ns.gif"; label1[16] = &"tHits_eweighted.gif"; label1[17] = &"nHits_HF.gif"; label1[18] = &"elongHF.gif"; label1[19] = &"eshortHF.gif"; label2g = &"Eta-phi_grid_all_depths.gif"; //*************************************************************************** //...Book histograms for (Int_t i = 0; i < Nhist1-Nhist1spec; i++) { char hname[3]; sprintf(hname,"h%d",i); if(i == 4 || i == 7 || i == 8 ) { if(i == 7) h1[i] = new TH1F(hname,label1[i],100,-5.,5.); if(i == 8) h1[i] = new TH1F(hname,label1[i],72,-3.1415926,3.1415926); if(i == 4) h1[i] = new TH1F(hname,label1[i],30,0.,150.); } else { h1[i] = new TH1F(hname,label1[i],100,1.,0.); } } // Special : global timing < 60 ns h1[15] = new TH1F("h15",label1[15],60,0.,60.); // Special : timing in the cluster (7x7) enery-weighted h1[16] = new TH1F("h16",label1[16],60,0.,60.); // Special : number of HCAL hits h1[17] = new TH1F("h17",label1[17],20,0.,20.); // Special : signal in long fibers h1[18] = new TH1F("h18",label1[18],50,0.,50.); // Special : signal in short fibers h1[19] = new TH1F("h19",label1[19],50,0.,50.); for (int i = 0; i < Nhist1; i++) { h1[i]->Sumw2(); } // eta-phi grid (for muon samples) h2g = new TH2F("Grid",label2g,1000,-5.,5.,576,-3.1415927,3.1415927); //*************************************************************************** //*************************************************************************** //...Fetch the data and fill the histogram // branches separately - for (int i = 0; i<nent; i++) { // cout << "Ev. " << i << endl; // -- get entries branchLayer ->GetEntry(i); branchNxN ->GetEntry(i); branchJets ->GetEntry(i); // -- Leading Jet int nJetHits = infoJets.njethit(); //cout << "nJetHits = " << nJetHits << endl; std::vector<float> rJetHits(nJetHits); rJetHits = infoJets.jethitr(); std::vector<float> tJetHits(nJetHits); tJetHits = infoJets.jethitt(); std::vector<float> eJetHits(nJetHits); eJetHits = infoJets.jethite(); float ecalJet = infoJets.ecaljet(); float hcalJet = infoJets.hcaljet(); float hoJet = infoJets.hojet(); float etotJet = infoJets.etotjet(); float detaJet = infoJets.detajet(); float dphiJet = infoJets.dphijet(); float drJet = infoJets.drjet(); float dijetM = infoJets.dijetm(); for (int j = 0; j < nJetHits; j++) { h1[0]->Fill(rJetHits[j]); h1[1]->Fill(tJetHits[j]); h1[2]->Fill(eJetHits[j]); } h1[3]->Fill(ecalJet); // h1[4]->Fill(hcalJet); // h1[5]->Fill(etotJet); // All Jets int nJets = infoJets.njet(); std::vector<float> jetE(nJets); jetE = infoJets.jete(); std::vector<float> jetEta(nJets); jetEta = infoJets.jeteta(); std::vector<float> jetPhi(nJets); jetPhi = infoJets.jetphi(); for (int j = 0; j < nJets; j++) { h1[6]->Fill(jetE[j]); h1[7]->Fill(jetEta[j]); h1[8]->Fill(jetPhi[j]); } // CaloHits from PHcalValidInfoLayer int nHits = infoLayer.nHit(); std::vector<float> idHits (nHits); idHits = infoLayer.idHit(); std::vector<float> phiHits (nHits); phiHits = infoLayer.phiHit(); std::vector<float> etaHits (nHits); etaHits = infoLayer.etaHit(); std::vector<float> layerHits (nHits); layerHits = infoLayer.layerHit(); std::vector<float> eHits (nHits); eHits = infoLayer.eHit(); std::vector<float> tHits (nHits); tHits = infoLayer.tHit(); int ne = 0, nh = 0; for (int j = 0; j < nHits; j++) { int layer = layerHits[j]-1; int id = (int)idHits[j]; if(id >= 10) {ne++;} else {nh++;} // cout << "Hit subdet = " << id << " lay = " << layer << endl; h1[9]->Fill(etaHits[j]); h1[10]->Fill(phiHits[j]); h1[11]->Fill(eHits[j]); h1[12]->Fill(tHits[j]); h1[15]->Fill(tHits[j]); h1[16]->Fill(tHits[j],eHits[j]); if(id < 6) { // HCAL only. Depth is needed, not layer !!! h2g->Fill(etaHits[j],phiHits[j]); } } h1[17]->Fill(Float_t(nh)); // The rest PHcalValidInfoLayer float elongHF = infoLayer.elonghf(); float eshortHF = infoLayer.eshorthf(); float eEcalHF = infoLayer.eecalhf(); float eHcalHF = infoLayer.ehcalhf(); h1[13]->Fill(eEcalHF); h1[14]->Fill(eHcalHF); h1[18]->Fill(elongHF); h1[19]->Fill(eshortHF); } // cout << "After event cycle " << i << endl; //...Prepare the main canva TCanvas *myc = new TCanvas("myc","",800,600); gStyle->SetOptStat(1111); // set stat :0 - nothing // Cycle for 1D distributions for (int ihist = 0; ihist < Nhist1 ; ihist++) { if(h1[ihist]->Integral() > 1.e-30 && h1[ihist]->Integral() < 1.e30 ) { h1[ihist]->SetLineColor(45); h1[ihist]->SetLineWidth(2); if(doDraw == 1) { h1[ihist]->Draw("h"); myc->SaveAs(label1[ihist]); } } } // eta-phi grid if(h2g->Integral() > 1.e-30 && h2g->Integral() < 1.e30 ) { h2g->SetMarkerColor(41); h2g->SetMarkerStyle(20); h2g->SetMarkerSize(0.2); h2g->SetLineColor(41); h2g->SetLineWidth(2); if(doDraw == 1) { h2g->Draw(); myc->SaveAs(label2g); } } // added by Julia Yarba //----------------------- // this is a temporary stuff that I've made // to create a reference ROOT histogram file if (doDraw == 2) { TFile OutFile(outputfile,"RECREATE") ; int ih = 0 ; for ( ih=0; ih<Nhist1; ih++ ) { h1[ih]->Write() ; } OutFile.Write() ; OutFile.Close() ; cout << outputfile << " histogram file created" << endl ; return; } /* return; */ // now perform Chi2 test for histograms using // "reference" and "current" histograms // open up ref. ROOT file // TFile RefFile(reffile) ; // service variables // TH1F* ref_hist = 0 ; int ih = 0 ; // loop over specials : timing, nhits, simhits-E // for ( ih=15; ih<20; ih++ ) { // service - name of the ref histo // char ref_hname[4] ; sprintf( ref_hname, "h%d", ih ) ; // retrive ref.histos one by one // ref_hist = (TH1F*)RefFile.Get( ref_hname ) ; // check if valid (no-NULL) // if ( ref_hist == NULL ) { // print warning in case of trouble // cout << "No such ref. histogram" << *ref_hname << endl ; } else { // everything OK - perform Chi2 test // Double_t *res; Double_t pval = h1[ih]->Chi2Test( ref_hist, "UU",res ) ; // output Chi2 comparison results // cout << "[OVAL] : histo " << ih << ", p-value= " << pval << endl ; } } // close ref. ROOT file // RefFile.Close() ; // at the end, close "current" ROOT tree file // myf->Close(); return ; }
void testTARGETMultReco(Char_t* dir = ".") { Char_t str[256]; // ######################################################## // defining pointers IlcRunLoader* runLoader; TFile* esdFile = 0; TTree* esdTree = 0; IlcESD* esd = 0; // ######################################################### // setup gilc and runloader if (gIlc) { delete gIlc->GetRunLoader(); delete gIlc; gIlc=0; } sprintf(str,"%s/gilc.root",dir); runLoader = IlcRunLoader::Open(str); if (runLoader == 0x0) { cout << "Can not open session"<<endl; return; } runLoader->LoadgIlc(); gIlc = runLoader->GetIlcRun(); runLoader->LoadKinematics(); runLoader->LoadHeader(); // ######################################################### // open esd file and get the tree // close it first to avoid memory leak if (esdFile) if (esdFile->IsOpen()) esdFile->Close(); sprintf(str,"%s/IlcESDs.root",dir); esdFile = TFile::Open(str); esdTree = (TTree*)esdFile->Get("esdTree"); TBranch * esdBranch = esdTree->GetBranch("ESD"); esdBranch->SetAddress(&esd); // ######################################################### // setup its stuff IlcTARGET* its=(IlcTARGET*)runLoader->GetIlcRun()->GetDetector("TARGET"); if (!its) { cout << " Can't get the TARGET!" << endl; return ; } IlcTARGETgeom* itsGeo=its->GetTARGETgeom(); if (!itsGeo) { cout << " Can't get the TARGET geometry!" << endl; return ; } IlcTARGETLoader* itsLoader = (IlcTARGETLoader*)runLoader->GetLoader("TARGETLoader"); if (!itsLoader) { cout << " Can't get the TARGET loader!" << endl; return ; } itsLoader->LoadRecPoints("read"); // ######################################################### IlcTARGETMultReconstructor* multReco = new IlcTARGETMultReconstructor(); multReco->SetGeometry(itsGeo); // ######################################################### // getting number of events Int_t nEvents = (Int_t)runLoader->GetNumberOfEvents(); Int_t nESDEvents = esdBranch->GetEntries(); if (nEvents!=nESDEvents) { cout << " Different number of events from runloader and esdtree!!!" << nEvents << " / " << nESDEvents << endl; return; } // ######################################################## // loop over number of events cout << nEvents << " event(s) found in the file set" << endl; for(Int_t i=0; i<nEvents; i++) { cout << "-------------------------" << endl << " event# " << i << endl; runLoader->GetEvent(i); esdBranch->GetEntry(i); // ######################################################## // get the EDS vertex const IlcESDVertex* vtxESD = esd->GetVertex(); Double_t vtx[3]; vtxESD->GetXYZ(vtx); Float_t esdVtx[3]; esdVtx[0] = vtx[0]; esdVtx[1] = vtx[1]; esdVtx[2] = vtx[2]; ///######################################################### // get TARGET clusters TTree* itsClusterTree = itsLoader->TreeR(); if (!itsClusterTree) { cerr<< " Can't get the TARGET cluster tree !\n"; return; } multReco->SetHistOn(kTRUE); multReco->Reconstruct(itsClusterTree, esdVtx, esdVtx); for (Int_t t=0; t<multReco->GetNTracklets(); t++) { cout << " tracklet " << t << " , theta = " << multReco->GetTracklet(t)[0] << " , phi = " << multReco->GetTracklet(t)[1] << endl; } } TFile* fout = new TFile("out.root","RECREATE"); multReco->SaveHists(); fout->Write(); fout->Close(); }
// Commands executed in a GLOBAL scope, e.g. created hitograms aren't erased... void plot_HE(TString inputfile="simevent_HE.root", TString outputfile="HE_histo.root", Int_t drawmode = 2, TString reffile="../data/HE_ref.root"){ // Option to no-action(0)/draw(1)/save(2) (default = 0) histograms in gif. //int doDraw = 0; int doDraw = drawmode; char * treename = "Events"; //The Title of Tree. delete gROOT->GetListOfFiles()->FindObject(inputfile); TFile * myf = new TFile(inputfile); TTree * tree = dynamic_cast<TTree*>(myf->Get("Events")); assert(tree != 0); TBranch * branchLayer = tree->GetBranch("PHcalValidInfoLayer_g4SimHits_HcalInfoLayer_CaloTest.obj"); assert(branchLayer != 0); TBranch * branchNxN = tree->GetBranch("PHcalValidInfoNxN_g4SimHits_HcalInfoNxN_CaloTest.obj"); assert(branchNxN != 0); TBranch * branchJets = tree->GetBranch( "PHcalValidInfoJets_g4SimHits_HcalInfoJets_CaloTest.obj"); assert(branchJets != 0); // Just number of entries (same for all branches) int nent = branchLayer->GetEntries(); cout << "Entries branchLayer : " << nent << endl; nent = branchJets->GetEntries(); cout << "Entries branchJets : " << nent << endl; nent = branchNxN->GetEntries(); cout << "Entries branchNxN : " << nent << endl; // Variables from branches PHcalValidInfoJets infoJets; branchJets->SetAddress( &infoJets); PHcalValidInfoLayer infoLayer; branchLayer->SetAddress( &infoLayer); PHcalValidInfoNxN infoNxN; branchNxN->SetAddress( &infoNxN); //*************************************************************************** // Histo titles-labels const int Nhist1 = 47, Nhist2 = 1; // N simple and N combined histos const int Nhist1spec = 7; // N special out of Nsimple total const int nLayersMAX = 20; const int nDepthsMAX = 5; TH1F *h; // just a pointer TH1F *h1[Nhist1]; TH1F *h1l[nLayersMAX]; // + all scint. layers separately TH1F *h1d[nDepthsMAX]; // + all depths TH2F *h2[Nhist2]; TH2F *h2g[5]; // + eta-phi grid -related for all depthes char *label1[Nhist1], *label2[Nhist2], *label1l[nLayersMAX ]; char *label1d[nDepthsMAX], *label2g[5]; // simple histos label1[0] = &"rJetHits.gif"; label1[1] = &"tJetHits.gif"; label1[2] = &"eJetHits.gif"; label1[3] = &"ecalJet.gif"; label1[4] = &"hcalJet.gif"; label1[5] = &"hoJet.gif"; label1[6] = &"etotJet.gif"; label1[7] = &"detaJet.gif"; label1[8] = &"dphiJet.gif"; label1[9] = &"drJet.gif"; label1[10] = &"jetE.gif"; label1[11] = &"jetEta.gif"; label1[12] = &"jetPhi.gif"; label1[13] = &"dijetM.gif"; label1[14] = &"ecalNxNr.gif"; label1[15] = &"hcalNxNr.gif"; label1[16] = &"hoNxNr.gif"; label1[17] = &"etotNxNr.gif"; label1[18] = &"ecalNxN.gif"; label1[19] = &"hcalNxN.gif"; label1[20] = &"hoNxN.gif"; label1[21] = &"etotNxN.gif"; label1[22] = &"layerHits.gif"; label1[23] = &"etaHits.gif"; label1[24] = &"phiHits.gif"; label1[25] = &"eHits.gif"; label1[26] = &"tHits.gif"; label1[27] = &"idHits.gif"; label1[28] = &"jitterHits.gif"; label1[29] = &"eIxI.gif"; label1[30] = &"tIxI.gif"; label1[31] = &"eLayer.gif"; label1[32] = &"eDepth.gif"; label1[33] = &"eHO.gif"; label1[34] = &"eHBHE.gif"; label1[35] = &"elongHF.gif"; label1[36] = &"eshortHF.gif"; label1[37] = &"eEcalHF.gif"; label1[38] = &"eHcalHF.gif"; // special label1[39] = &"NxN_trans_fraction.gif"; label1[40] = &"tHist_50ns.gif"; label1[41] = &"tHist_eweighted.gif"; label1[42] = &"nHits_ECAL.gif"; label1[43] = &"nHits_HCAL.gif"; label1[44] = &"nHits.gif"; label1[45] = &"longProf_eweighted.gif"; label1[46] = &"E_hcal.gif"; label1l[0] = &"layer_0.gif"; label1l[1] = &"layer_1.gif"; label1l[2] = &"layer_2.gif"; label1l[3] = &"layer_3.gif"; label1l[4] = &"layer_4.gif"; label1l[5] = &"layer_5.gif"; label1l[6] = &"layer_6.gif"; label1l[7] = &"layer_7.gif"; label1l[8] = &"layer_8.gif"; label1l[9] = &"layer_9.gif"; label1l[10] = &"layer_10.gif"; label1l[11] = &"layer_11.gif"; label1l[12] = &"layer_12.gif"; label1l[13] = &"layer_13.gif"; label1l[14] = &"layer_14.gif"; label1l[15] = &"layer_15.gif"; label1l[16] = &"layer_16.gif"; label1l[17] = &"layer_17.gif"; label1l[18] = &"layer_18.gif"; label1l[19] = &"layer_19.gif"; label1d[0] = &"depth_0.gif"; label1d[1] = &"depth_1.gif"; label1d[2] = &"depth_2.gif"; label1d[3] = &"depth_3.gif"; label1d[4] = &"depth_4.gif"; // more complicated histos and profiles label2[0] = &"JetHCALvsECAL.gif"; label2g[0] = &"Eta-phi_grid_depth_0.gif"; label2g[1] = &"Eta-phi_grid_depth_1.gif"; label2g[2] = &"Eta-phi_grid_depth_2.gif"; label2g[3] = &"Eta-phi_grid_depth_3.gif"; label2g[4] = &"Eta-phi_grid_all_depths.gif"; // Some constants const float fact = 117.0; // sampling factor which corresponds to those // for layer = 0,1 in SimG4HcalValidation.cc //*************************************************************************** //...Book histograms for (Int_t i = 0; i < Nhist1-Nhist1spec; i++) { char hname[3]; sprintf(hname,"h%d",i); if(i == 4 || i == 7 || i == 8 || i == 11 || i == 12 || i == 6) { if(i == 11) h1[i] = new TH1F(hname,label1[i],100,-5.,5.); if(i == 12) h1[i] = new TH1F(hname,label1[i],72,-3.1415926,3.1415926); if(i == 7 || i == 8) h1[i] = new TH1F(hname,label1[i],100,-0.1,0.1); if( i == 4) h1[i] = new TH1F(hname,label1[i],50,0.,100.); if( i == 6) h1[i] = new TH1F(hname,label1[i],50,0.,100.); } else { h1[i] = new TH1F(hname,label1[i],100,1.,0.); } } // Special : global timing < 50 ns h1[40] = new TH1F("h40",label1[40],50,0.,50.); // Special : timing in the cluster (7x7) enery-weighted h1[41] = new TH1F("h41",label1[41],30,0.,30.); // Special : number of ECAL&HCAL hits h1[42] = new TH1F("h42",label1[42],300,0.,3000.); h1[43] = new TH1F("h43",label1[43],300,0.,3000.); h1[44] = new TH1F("h44",label1[44],300,0.,3000.); // Special : Longitudinal profile h1[45] = new TH1F("h45",label1[45],20,0.,20.); // Etot HCAL TH1F *h1[46] = new TH1F("h46",label1[46],50,0.,1.0); for (int i = 0; i < Nhist1; i++) { if(i != 39) h1[i]->Sumw2(); } for (int i = 0; i < Nhist2; i++) { char hname[3]; sprintf(hname,"D%d",i); h2[i] = new TH2F(hname,label2[i],100,0.,100.,100,0.,100.); } // h[i]->Sumw2(); // to get errors properly calculated // scint. layers for (int i = 0; i < nLayersMAX; i++) { char hname[4]; sprintf(hname,"hl%d",i); h1l[i] = new TH1F(hname,label1l[i],40,0.,0.4); } // depths Float_t max[5] = {30000, 500, 500, 200, 200.}; for (int i = 0; i < nDepthsMAX; i++) { char hname[3]; sprintf(hname,"hd%d",i); h1d[i] = new TH1F(hname,label1d[i],100,0.,max[i]); } // eta-phi grid (for muon samples) for (int i = 0; i < 5; i++) { char hname[3]; sprintf(hname,"Dg%d",i); h2g[i] = new TH2F(hname,label2g[i],1000,-5.,5.,576,-3.1415927,3.1415927); } //*************************************************************************** //*************************************************************************** //...Fetch the data and fill the histogram // branches separately - for (int i = 0; i<nent; i++) { // cout << "Ev. " << i << endl; // -- get entries branchLayer ->GetEntry(i); branchNxN ->GetEntry(i); branchJets ->GetEntry(i); // -- Leading Jet int nJetHits = infoJets.njethit(); //cout << "nJetHits = " << nJetHits << endl; std::vector<float> rJetHits(nJetHits); rJetHits = infoJets.jethitr(); std::vector<float> tJetHits(nJetHits); tJetHits = infoJets.jethitt(); std::vector<float> eJetHits(nJetHits); eJetHits = infoJets.jethite(); float ecalJet = infoJets.ecaljet(); float hcalJet = infoJets.hcaljet(); float hoJet = infoJets.hojet(); float etotJet = infoJets.etotjet(); float detaJet = infoJets.detajet(); float dphiJet = infoJets.dphijet(); float drJet = infoJets.drjet(); float dijetM = infoJets.dijetm(); for (int j = 0; j < nJetHits; j++) { h1[0]->Fill(rJetHits[j]); h1[1]->Fill(tJetHits[j]); h1[2]->Fill(eJetHits[j]); } h1[3]->Fill(ecalJet); // h1[4]->Fill(hcalJet); // h1[5]->Fill(hoJet); h1[6]->Fill(etotJet); h2[0]->Fill(ecalJet,hcalJet); // h1[7]->Fill(detaJet); h1[8]->Fill(dphiJet); h1[9]->Fill(drJet); h1[13]->Fill(dijetM); // All Jets int nJets = infoJets.njet(); std::vector<float> jetE (nJets); jetE = infoJets.jete(); std::vector<float> jetEta(nJets); jetEta = infoJets.jeteta(); std::vector<float> jetPhi(nJets); jetPhi = infoJets.jetphi(); for (int j = 0; j < nJets; j++) { h1[10]->Fill(jetE[j]); h1[11]->Fill(jetEta[j]); h1[12]->Fill(jetPhi[j]); } // NxN quantities float ecalNxNr = infoNxN.ecalnxnr(); float hcalNxNr = infoNxN.hcalnxnr(); float hoNxNr = infoNxN.honxnr(); float etotNxNr = infoNxN.etotnxnr(); float ecalNxN = infoNxN.ecalnxn(); float hcalNxN = infoNxN.hcalnxn(); float hoNxN = infoNxN.honxn(); float etotNxN = infoNxN.etotnxn(); h1[14]->Fill(ecalNxNr); h1[15]->Fill(hcalNxNr); h1[16]->Fill(hoNxNr); h1[17]->Fill(etotNxNr); h1[18]->Fill(ecalNxN); h1[19]->Fill(hcalNxN); h1[20]->Fill(hoNxN); h1[21]->Fill(etotNxN); // CaloHits from PHcalValidInfoLayer int nHits = infoLayer.nHit(); std::vector<float> idHits(nHits); idHits = infoLayer.idHit(); std::vector<float> phiHits(nHits); phiHits = infoLayer.phiHit(); std::vector<float> etaHits(nHits); etaHits = infoLayer.etaHit(); std::vector<float> layerHits(nHits); layerHits = infoLayer.layerHit(); std::vector<float> eHits(nHits); eHits = infoLayer.eHit(); std::vector<float> tHits(nHits); tHits = infoLayer.tHit(); int ne = 0, nh = 0; for (int j = 0; j < nHits; j++) { int layer = layerHits[j]-1; int id = (int)idHits[j]; if(id >= 10) {ne++;} else {if (id < 5) nh++;} // cout << "Hit subdet = " << id << " lay = " << layer << endl; h1[22]->Fill(Float_t(layer)); h1[23]->Fill(etaHits[j]); h1[24]->Fill(phiHits[j]); h1[25]->Fill(eHits[j]); h1[26]->Fill(tHits[j]); h1[27]->Fill(idHits[j]); // h1[28]->Fill(jitterHits[j]); // no jitter anymore h1[40]->Fill(tHits[j]); h1[41]->Fill(tHits[j],eHits[j]); if(id < 6) { // HCAL only. Depth is needed, not layer !!! //if(layer == 0) h2g[0]->Fill(etaHits[j],phiHits[j]); //if(layer == 1) h2g[1]->Fill(etaHits[j],phiHits[j]); //if(layer == 2) h2g[2]->Fill(etaHits[j],phiHits[j]); //if(layer == 3) h2g[3]->Fill(etaHits[j],phiHits[j]); h2g[4]->Fill(etaHits[j],phiHits[j]); } } h1[42]->Fill(Float_t(ne)); h1[43]->Fill(Float_t(nh)); h1[44]->Fill(Float_t(nHits)); // NxN PHcalValidInfoNxN // cout << " nIxI = " << nIxI << endl; int nIxI = infoNxN.nnxn(); std::vector<float> idIxI(nIxI); idIxI = infoNxN.idnxn(); std::vector<float> eIxI(nIxI); eIxI = infoNxN.enxn(); std::vector<float> tIxI(nIxI); tIxI = infoNxN.tnxn(); for (int j = 0; j < nIxI ; j++) { // NB !!! j < nIxI h1[29]->Fill(eIxI[j]); h1[30]->Fill(tIxI[j]); h1[39]->Fill(idIxI[j],eIxI[j]); // transverse profile } // Layers and depths PHcalValidInfoLayer std::vector<float> eLayer(nLayersMAX); eLayer = infoLayer.elayer(); std::vector<float> eDepth(nDepthsMAX); eDepth = infoLayer.edepth(); float eTot = 0.; for (int j = 0; j < nLayersMAX ; j++) { h1[31]->Fill(eLayer[j]); h1l[j]->Fill(eLayer[j]); h1[45]->Fill((Float_t)(j),eLayer[j]); // HCAL SimHits only eTot += eLayer[j]; } for (int j = 0; j < nDepthsMAX; j++) { h1[32]->Fill(eDepth[j]); h1d[j]->Fill(eDepth[j]); } h1[46]->Fill(eTot); // The rest PHcalValidInfoLayer float eHO = infoLayer.eho(); float eHBHE = infoLayer.ehbhe(); float elongHF = infoLayer.elonghf(); float eshortHF = infoLayer.eshorthf(); float eEcalHF = infoLayer.eecalhf(); float eHcalHF = infoLayer.ehcalhf(); h1[33]->Fill(eHO); h1[34]->Fill(eHBHE); h1[35]->Fill(elongHF); h1[36]->Fill(eshortHF); h1[37]->Fill(eEcalHF); h1[38]->Fill(eHcalHF); } // cout << "After event cycle " << i << endl; //...Prepare the main canva TCanvas *myc = new TCanvas("myc","",800,600); gStyle->SetOptStat(1111); // set stat :0 - nothing // Cycle for 1D distributions for (int ihist = 0; ihist < Nhist1 ; ihist++) { if(h1[ihist]->Integral() > 1.e-30 && h1[ihist]->Integral() < 1.e30 ) { h1[ihist]->SetLineColor(45); h1[ihist]->SetLineWidth(2); if(doDraw == 1) { h1[ihist]->Draw("h"); myc->SaveAs(label1[ihist]); } } } // Cycle for energy in all layers for (int ihist = 0; ihist < nLayersMAX; ihist++) { if(h1l[ihist]->Integral() > 1.e-30 && h1l[ihist]->Integral() < 1.e30 ) { h1l[ihist]->SetLineColor(45); h1l[ihist]->SetLineWidth(2); if(doDraw == 1) { h1l[ihist]->Draw("h"); myc->SaveAs(label1l[ihist]); } } } // Cycle for 2D distributions // for (int ihist = 0; ihist < 1 ; ihist++) { for (int ihist = 0; ihist < Nhist2 ; ihist++) { if(h2[ihist]->Integral() > 1.e-30 && h2[ihist]->Integral() < 1.e30 ) { h2[ihist]->SetMarkerColor(45); h2[ihist]->SetMarkerStyle(20); h2[ihist]->SetMarkerSize(0.7); // marker size ! h2[ihist]->SetLineColor(45); h2[ihist]->SetLineWidth(2); if(doDraw == 1) { h2[ihist]->Draw(); myc->SaveAs(label2[ihist]); } } } // Cycle for eta-phi grids // for (int ihist = 0; ihist < 5 ; ihist++) { for (int ihist = 4; ihist < 5 ; ihist++) { if(h2g[ihist]->Integral() > 1.e-30 && h2g[ihist]->Integral() < 1.e30 ) { h2g[ihist]->SetMarkerColor(41); h2g[ihist]->SetMarkerStyle(20); h2g[ihist]->SetMarkerSize(0.2); h2g[ihist]->SetLineColor(41); h2g[ihist]->SetLineWidth(2); if(doDraw == 1) { h2g[ihist]->Draw(); myc->SaveAs(label2g[ihist]); } } } // added by Julia Yarba //----------------------- // this is a temporary stuff that I've made // to create a reference ROOT histogram file if (doDraw == 2) { TFile OutFile(outputfile,"RECREATE") ; int ih = 0 ; for ( ih=0; ih<nLayersMAX; ih++ ) { h1l[ih]->Write() ; } for ( ih=0; ih<Nhist1; ih++ ) { h1[ih]->Write() ; } OutFile.Write() ; OutFile.Close() ; cout << outputfile << " histogram file created" << endl ; return ; } /* return; */ // now perform Chi2 test for histograms that hold // energy deposition in the Hcal layers 1-10, using // "reference" and "current" histograms // open up ref. ROOT file // TFile RefFile(reffile) ; // service variables // TH1F* ref_hist = 0 ; int ih = 0 ; // loop over layers 1-10 // for ( ih=1; ih<11; ih++ ) { // service - name of the ref histo // char ref_hname[4] ; sprintf( ref_hname, "hl%d", ih ) ; // retrive ref.histos one by one // ref_hist = (TH1F*)RefFile.Get( ref_hname ) ; // check if valid (no-NULL) // if ( ref_hist == NULL ) { // print warning in case of trouble // cout << "No such ref. histogram" << *ref_hname << endl ; } else { // everything OK - perform Chi2 test // Double_t *res; Double_t pval = h1l[ih]->Chi2Test( ref_hist, "UU", res ) ; // output Chi2 comparison results // cout << "[OVAL] : Edep in Layer " << ih << ", p-value= " << pval << endl ; } } // loop over specials : timing, nhits(ECAL and HCAL) // for ( ih=40; ih<47; ih++ ) { // service - name of the ref histo // char ref_hname[4] ; sprintf( ref_hname, "h%d", ih ) ; // retrive ref.histos one by one // ref_hist = (TH1F*)RefFile.Get( ref_hname ) ; // check if valid (no-NULL) // if ( ref_hist == NULL ) { // print warning in case of trouble // cout << "No such ref. histogram" << *ref_hname << endl ; } else { // everything OK - perform Chi2 test // Double_t *res; Double_t pval = h1[ih]->Chi2Test( ref_hist, "UU", res) ; // output Chi2 comparison results // cout << "[OVAL] : histo " << ih << ", p-value= " << pval << endl ; } } // close ref. ROOT file // RefFile.Close() ; // at the end, close "current" ROOT tree file // myf->Close(); return ; }
void calibraPlastico(char* filename, int channel=4) { FILE *outfile[2]; outfile[0] = fopen("Chi2_511","w"); outfile[1] = fopen("Chi2_1275","w"); Int_t number_of_loop=0; Int_t i, j, k, i_sm, rsen[2]; Float_t r, alpha, energia; Int_t b_altezza; // energies Float_t E_peak[NUMENERGIES]; Float_t E_compton[NUMENERGIES]; E_peak[0] = 511.; E_peak[1] = 1275.; for (i=0; i<NUMENERGIES; i++) { E_compton[i] = 2*E_peak[i]*E_peak[i]/(511+2*E_peak[i]); printf("E_compton[%d] = %f;\n",i,E_compton[i]); } TTimer *timer = new TTimer("gSystem->ProcessEvents();", 50, kFALSE); TCanvas *c0 = new TCanvas("c0"); c0->cd(); h_ideal = new TH1F("h_ideal","Compton ideale",NBINS,0,MAXHISTONRG); // check file existance f_smearings = new TFile("smearings.root","UPDATE"); // check smearing samples existance for(i=0; i<NUMENERGIES; i++) { sprintf(smoothName,"smooth_%.1f_%d;1",E_peak[i],NSMEARINGS-2); if (!f_smearings->Get(smoothName)) { cout << smoothName << " " << f_smearings->FindObject(smoothName) << endl; // smearing for that energy do not exist printf("Non esistono.\n"); // ideal compton histogram for (j=0; j<NBINS; j++) { if (j>h_ideal->FindBin(50) && j<h_ideal->FindBin(E_compton[i])) { r = h_ideal->GetBinCenter(j)/E_peak[i]; alpha = E_peak[i]/511.0; energia = KN_NORM * (2+r*r/(alpha*alpha*(1-r)*(1-r))+r/(1-r) * (r-2/alpha)); h_ideal->SetBinContent(j,energia); } else { h_ideal->SetBinContent(j,0); } } h_ideal->Draw(); c0->Update(); timer->TurnOn(); timer->Reset(); timer->TurnOff(); // creazione spettri smussati for (i_sm=1; i_sm<NSMEARINGS; i_sm++) { sprintf(smoothName,"smooth_%.1f_%d",E_peak[i],i_sm); printf("Creo '%s': ",smoothName); h_smooth = new TH1F(smoothName,"Smooth",NBINS,0,MAXHISTONRG); // istogramma in energia for (j=1; j<h_ideal->FindBin(E_compton[i]); j++) { b_altezza = h_ideal->GetBinContent(j); for (k=1; k<b_altezza; k++){ h_smooth->Fill(gRandom->Gaus(h_ideal->GetBinCenter(j),i_sm)); } printf("."); } printf("\n"); h_smooth->Write(); } } } // ok, we've got the smearings! f_smearings->Close(); f_smearings = new TFile("smearings.root","READ"); // ---------------------------------- // retrieving "raw" histogram // ---------------------------------- TFile *infile = new TFile(filename); TTree *tree= (TTree*)infile->Get("acq_tree_0"); TBranch *branch = tree->GetBranch(Form("acq_ch%d",channel)); branch->SetAddress(&inc_data.timetag); TH1F *h_raw = new TH1F("h_raw","Acquisizione",NBINS,0,MAXHISTOCHN); UInt_t toentry=branch->GetEntries(); printf("getHistoFromFile: There are %d entries in the branch\n",toentry); for(i=0; i<toentry; i++) { branch->GetEntry(i); h_raw->Fill(inc_data.qlong); } h_raw->Draw(); TSpectrum *s = new TSpectrum(10); Int_t e, nPeaks, bTemp, bFirstPeak = 9999; Float_t *xPeaks; // trovo il primo picco nPeaks = s->Search(h_raw->Rebin(2, "h_raw_rebinned")); if (nPeaks>0) { xPeaks = s->GetPositionX(); // loop sui picchi per trovare il primo for (i=0;i<nPeaks;i++) { bTemp = h_raw->GetXaxis()->FindBin(xPeaks[i]); if (bTemp<bFirstPeak) { bFirstPeak = bTemp; } } } else { bFirstPeak = 0; } // sottraggo il fondo Compton Float_t *bgBins = new Float_t[NBINS]; TH1F *h_filtered = new TH1F("h_filtered","Picchi",NBINS,0,MAXHISTOCHN); /*for (i = 0; i < bFirstPeak; i++) { bgBins[i]=h_raw->GetBinContent(i+1); } s->Background(bgBins,bFirstPeak,20,TSpectrum::kBackDecreasingWindow,TSpectrum::kBackOrder2,kFALSE,TSpectrum::kBackSmoothing15,kFALSE); for (i = 0; i < bFirstPeak; i++) { h_filtered->SetBinContent(i+1, (h_raw->GetBinContent(i+1)-bgBins[i])); } for (i = 0; i < NBINS-bFirstPeak; i++) { bgBins[i]=h_raw->GetBinContent(bFirstPeak+i+1); } s->Background(bgBins,NBINS-bFirstPeak,20,TSpectrum::kBackDecreasingWindow,TSpectrum::kBackOrder2,kFALSE,TSpectrum::kBackSmoothing15,kFALSE); for (i = bFirstPeak; i < NBINS; i++) { h_filtered->SetBinContent(i+1, (h_raw->GetBinContent(i+1)-bgBins[i-bFirstPeak])); } //TCanvas * background = new TCanvas("background","Estimation of bg",10,10,1000,700);*/ for (i = 0; i < NBINS; i++) { bgBins[i]=h_raw->GetBinContent(i+1); } s->Background(bgBins, NBINS, 20, TSpectrum::kBackDecreasingWindow, TSpectrum::kBackOrder2, kFALSE, TSpectrum::kBackSmoothing15, kFALSE); for (i = 0; i < NBINS; i++) { h_filtered->SetBinContent(i+1, (h_raw->GetBinContent(i+1)-bgBins[i])); } h_raw->Draw("L"); h_filtered->SetLineColor(kRed); h_filtered->Draw("SAME L"); c0->Update(); // trovo i picchi e calibro nPeaks = s->Search(h_filtered->Rebin(2, "h_filtered_rebinned"),2,"",0.05); xPeaks = s->GetPositionX(); // sigma_fall[0] = 100; timer->TurnOn(); timer->Reset(); timer->TurnOff(); if (nPeaks<NUMENERGIES) { // trovati troppi pochi picchi printf("EPIC FAIL while calibrating - too few peaks!\n"); } else { // possiamo calibrare TGraphErrors *graphErr; TF1 *fitMeasPeaks, *fitfun; Float_t nrg[NUMENERGIES], shift[NUMENERGIES], sigma_fall[NUMENERGIES], a, b, bPeak, cPeak, nrgPeak, chi2, fondo, xmin, xmax, chi2min; // fitto i due picchi, mi servono le sigma... for (e=0; e<NUMENERGIES; e++) { xmin = xPeaks[e] - (0.5*xPeaks[e]); // fit left margin xmax = xPeaks[e] + (0.5*xPeaks[e]); // fit right margin fitMeasPeaks = new TF1("fitMeasPeaks","gaus",xmin,xmax); fitMeasPeaks->SetNpx(1000); fitMeasPeaks->SetParameters(1,xPeaks[e]); h_filtered->Fit("fitMeasPeaks","QNO","",xmin,xmax); sigma_fall[e] = fitMeasPeaks->GetParameter(2); printf("%f - %f - %f Sigma_fall[%d]: %f\n",xmin,xPeaks[e],xmax,e,sigma_fall[e]); // inizializzazione shift[e]=0; nrg[e]=E_compton[e]; } fitfun = new TF1("calfitfun","pol1",xPeaks[0],xPeaks[NUMENERGIES-1]); // costruiamo uno spettro sperimentale calibrato h_calib = (TH1F*)h_raw->Clone(); h_calib->SetNameTitle("h_calib","Acquisiz. calibrata"); Int_t debug = 0; Int_t loop_flag = 1; // do..while shift begin while(loop_flag) { number_of_loop++; loop_flag = 0; for (e=0; e<NUMENERGIES; e++) { // energie aggiornate nrg[e] = nrg[e]-shift[e]; printf("xPeaks[%d] = %f\tshift[%d] = %f\tnrg[%d] = %f\n",e,xPeaks[e],e,shift[e],e,nrg[e]); } // calibrazione fitfun->SetParLimits(0,-100,100); fitfun->SetParLimits(1,0.,1.); graphErr = new TGraphErrors(NUMENERGIES,xPeaks,nrg); graphErr->Fit(fitfun,"RN"); a = fitfun->GetParameter(1); b = fitfun->GetParameter(0);// graphErr->Delete(); printf("intercetta=%f pendenza=%f\n",b,a); h_calib->GetXaxis()->SetLimits(b,h_raw->GetBinCenter(NBINS)*a+b); h_calib->Draw(); c0->Update(); timer->TurnOn(); timer->Reset(); timer->TurnOff(); for (e=0; e<NUMENERGIES; e++) { chi2min = 9999999; printf("Looppo sull'energia %.1f\n",nrg[e]); // loop on smearings for (i_sm=19; i_sm<NSMEARINGS; i_sm++) { sprintf(smoothName,"smooth_%.1f_%d",E_peak[e],i_sm); h_smooth = (TH1F*)f_smearings->Get(smoothName); if (debug) printf("Recupero l'histo %s\n",smoothName); //h_smooth->Draw(); // momentaneamente assumiamo che il CE sia: bPeak = h_smooth->GetMaximumBin(); if (debug) printf("bPeak = %f\n",bPeak); nrgPeak = bPeak*MAXHISTONRG/NBINS; if (debug) printf("nrgPeak = %f\n",nrgPeak); t_shift = nrg[e]-nrgPeak; if (debug) printf("t_shift = %f\n",t_shift); cPeak = h_calib->FindBin(a*xPeaks[e]+b); if (debug) printf("peak calib: %.1f\n",cPeak); max_calib = h_calib->GetBinContent(cPeak); if (debug) printf("max_calib = %f\n",max_calib); max_smooth = h_smooth->GetBinContent(bPeak); if (debug) printf("max_smooth = %f\n",max_smooth); if (debug) printf("sigma_fall[%d] = %f\n",e,sigma_fall[e]); if (debug) printf("a*sigma_fall[%d] = %f\n",e,a*sigma_fall[e]); // definisco la funzione per il fit TF1 *f_smear_profile = new TF1("f_smear_profile",f_profile,nrgPeak-a*sigma_fall[e],nrgPeak+a*sigma_fall[e]*3,1); f_smear_profile->SetParameters(0,300); h_calib->Fit("f_smear_profile","QON","",a*xPeaks[e]+b-a*sigma_fall[e],a*xPeaks[e]+b+a*sigma_fall[e]*3); chi2 = f_smear_profile->GetChisquare(); if (debug) printf("i_sm: %i\tchiquadro: %f\n",i_sm,chi2); fondo = f_smear_profile->GetParameter(0); if (debug) printf("fondo = %f\n",fondo); if (debug) printf("i_sm: %d\tchi2min vs. chi2: %f %f\n",i_sm,chi2min,chi2); if (number_of_loop==1) {fprintf(outfile[e],"%i\t%f\t%f\n",i_sm,chi2, fondo);} if (chi2<chi2min) { chi2min = chi2; shift[e] = t_shift; rsen[e]=i_sm;} } // loop on smearings ends here if (debug) printf("shift[%d]: %f\n",e,t_shift); if (shift[e]>THRSHIFT) { loop_flag++; } if (number_of_loop==1) {fclose(outfile[e]);} } // end loop on energies } // while shift ends here printf("Esco con shift[0]=%.1f e shift[1]=%.1f\n",shift[0],shift[1]); cout << "Esco con risoluzione[0] = " << rsen[0] << " keV (" << rsen[0]*100/E_compton[0] << "%)"; cout << " e risoluzione[1] = " << rsen[1] << " keV (" << rsen[1]*100/E_compton[1] << "%)" << endl; printf("\nRESULTS: nrg1 = %f\tnrg2 = %f\n",nrg[0],nrg[1]); printf("RESULTS: m = %f\t q = %f\n",a,b); } // end if enough peaks infile->Close(); //f_smearings->Close(); }
/// Open new data file bool DDG4EventHandler::Open(const std::string&, const std::string& name) { if ( m_file.first ) m_file.first->Close(); m_hasFile = false; m_hasEvent = false; TFile* f = TFile::Open(name.c_str()); if ( f && !f->IsZombie() ) { m_file.first = f; TTree* t = (TTree*)f->Get("EVENT"); if ( t ) { TObjArray* br = t->GetListOfBranches(); m_file.second = t; m_entry = -1; m_branches.clear(); for(Int_t i=0; i<br->GetSize(); ++i) { TBranch* b = (TBranch*)br->At(i); if ( !b ) continue; m_branches[b->GetName()] = make_pair(b,(void*)0); printout(INFO,"DDG4EventHandler::open","+++ Branch %s has %ld entries.",b->GetName(),b->GetEntries()); } for(Int_t i=0; i<br->GetSize(); ++i) { TBranch* b = (TBranch*)br->At(i); if ( !b ) continue; b->SetAddress(&m_branches[b->GetName()].second); } m_hasFile = true; return true; } throw runtime_error("+++ Failed to access tree EVENT in ROOT file:"+name); } throw runtime_error("+++ Failed to open ROOT file:"+name); }