void ResultFormatter::AddBranch( TTree* inputTree, const string& BranchName, const vector<double>& DoubleData ) { if( inputTree->GetEntries() != 0 ) { if( inputTree->GetEntries() != (int) DoubleData.size() ) { cerr << "CANNOT ADD DOUBLE BRANCH: " << BranchName << " TO: " << inputTree->GetName() << endl; return; } } TString branchName( BranchName ); TString branchLabel=branchName; branchLabel.Append("/D"); double thisValue=0.; TBranch* newBranch = inputTree->Branch( branchName, &thisValue, branchLabel ); inputTree->SetEntries( (int) DoubleData.size() ); for( unsigned int i=0; i< DoubleData.size(); ++i ) { thisValue=DoubleData[i]; newBranch->Fill(); } return; }
void pulseHeights(Int_t board=112, TString file="latest.root", Int_t xmin=300, Int_t xmax=50){ TFile *f = new TFile(file); // create a pointer to an event object for reading the branch values. TBEvent *event = new TBEvent(); TTree *t1041 = (TTree*) f->Get("t1041"); TBranch *bevent = t1041->GetBranch("tbevent"); bevent->SetAddress(&event); TH1F *hpulse[32]; for (int i=0; i<32; i++){ TString name; name.Form("h%d_%2d",board,i); hpulse[i]=new TH1F(name,name,xmax-xmin,xmin,xmax); } // loop over events for (Int_t i=0; i< t1041->GetEntries(); i++) { t1041->GetEntry(i); // loop over PADE channels for (Int_t j=0; j<event->NPadeChan(); j++){ if (event->GetPadeChan(j).GetBoardID() != board) continue; int chan=event->GetPadeChan(j).GetChannelID(); hpulse[chan]->Fill(event->GetPadeChan(j).GetMax()); } } }
void OnlineGUI::GetTreeVars() { // Utility to find all of the variables (leaf's/branches) within a // Specified TTree and put them within the treeVars vector. treeVars.clear(); TObjArray *branchList; vector <TString> currentTree; for(UInt_t i=0; i<fRootTree.size(); i++) { currentTree.clear(); branchList = fRootTree[i]->GetListOfBranches(); TIter next(branchList); TBranch *brc; while((brc=(TBranch*)next())!=0) { TString found = brc->GetName(); // Not sure if the line below is so smart... currentTree.push_back(found); } treeVars.push_back(currentTree); } #ifdef DEBUG2 for(UInt_t iTree=0; iTree<treeVars.size(); iTree++) { cout << "In Tree " << iTree << ": " << endl; for(UInt_t i=0; i<treeVars[iTree].size(); i++) { cout << treeVars[iTree][i] << endl; } } #endif }
/// 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); }
void AnalysisModuleRunner::begin_in_file(const string & infile){ std::unique_ptr<TFile> file(TFile::Open(infile.c_str(), "read")); if(read_trigger){ std::map<int, std::vector<std::string>> runid_to_triggernames; // find triggernames for all runs in this file: TTree * intree = dynamic_cast<TTree*>(file->Get("AnalysisTree")); if(!intree) throw runtime_error("Did not find AnalysisTree in input file"); std::vector<std::string> trigger_names; std::vector<std::string> *ptrigger_names = &trigger_names; int runid = 0; TBranch* runb = 0; TBranch* tnb = 0; intree->SetBranchAddress("run", &runid, &runb); intree->SetBranchAddress("triggerNames", &ptrigger_names, &tnb); if(runb==0 || tnb==0){ throw runtime_error("did not find branches for setting up trigger names"); } int nentries = intree->GetEntries(); int last_runid = -1; for(int i=0; i<nentries; ++i){ runb->GetEntry(i); if(last_runid == runid) continue; last_runid = runid; assert(runid >= 1); tnb->GetEntry(i); if(!trigger_names.empty()){ runid_to_triggernames[runid] = trigger_names; } } LOG_INFO("Found " << runid_to_triggernames.size() << " trigger infos in file '" << infile << "'"); helper->set_infile_triggernames(move(runid_to_triggernames)); } }
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; }
/// Load the specified event Int_t DDG4EventHandler::ReadEvent(Long64_t event_number) { m_data.clear(); m_hasEvent = false; if ( hasFile() ) { if ( event_number >= m_file.second->GetEntries() ) { event_number = m_file.second->GetEntries()-1; printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Cannot read across End-of-file! Reading last event:%d.",event_number); } else if ( event_number < 0 ) { event_number = 0; printout(ERROR,"DDG4EventHandler","+++ nextEvent: Cannot read across Start-of-file! Reading first event:%d.",event_number); } Int_t nbytes = m_file.second->GetEntry(event_number); if ( nbytes >= 0 ) { printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Read %d bytes of event data for entry:%d",nbytes,event_number); for(Branches::const_iterator i=m_branches.begin(); i != m_branches.end(); ++i) { TBranch* b = (*i).second.first; std::vector<void*>* ptr_data = *(std::vector<void*>**)b->GetAddress(); m_data[b->GetClassName()].push_back(make_pair(b->GetName(),ptr_data->size())); } m_hasEvent = true; return nbytes; } printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Cannot read event data for entry:%d",event_number); throw runtime_error("+++ EventHandler::readEvent: Failed to read event"); } throw runtime_error("+++ EventHandler::readEvent: No file open!"); }
hw() { Float_t data; TFile *f=new TFile("data.root"); TTree* tree = f->Get("mytree"); TBranch* branch = tree->GetBranch("data"); branch->SetAddress(&data); TH1F* h1 = new TH1F("h1","h1",200,0.0,5.0); for(Int_t i= 0 ; i< tree->GetEntries() ; i++) { tree->GetEntry(i); h1->Fill( data) ; } TF1 *f2 = new TF1("f2", "[0]*x+[1]+gaus(2)", 0.0, 5.0); f2->SetParameter(3,3.7); TVirtualFitter *min = TVirtualFitter::Fitter(0,2); TVirtualFitter::SetDefaultFitter("Minuit"); TFitResultPtr fitresult = h1->Fit("f2", "MES"); cout<< "Parameter 0" << fitresult->Parameter(0) << "+-" << fitresult->ParError(0) << endl; cout<< "Parameter 1" <<fitresult->Parameter(1) << "+-" << fitresult->ParError(1) << endl; cout << "Chi2 " << fitresult->Chi2() << endl; cout << "NDF " << fitresult->Ndf() << endl; cout << "Chi2 probability " << fitresult->Prob() << endl; TMatrixD covmat(fitresult->GetCovarianceMatrix()); cout << "Covariance matrix" << endl; covmat.Print(); TCanvas *c1 = new TCanvas("c1", "binned line fit", 600, 600); c1->Draw(); h1->Draw(); }
unsigned int loop(T& tree, TH3F* hist3D, TH2F* hist2D) { unsigned int nEvtsRead = 0; unsigned int nEB = 0; Long64_t N = tree.fChain->GetEntriesFast(); for (Long64_t iEvt = 0; iEvt < N; ++iEvt) { Long64_t localEntry = tree.LoadTree(iEvt); if (localEntry < 0) break; ++nEvtsRead; tree.fChain->GetEntry(iEvt); TObject* object = tree.fChain->GetListOfBranches()->FindObject("totalWeight"); TBranch* branch = NULL; Float_t totalWeight = 1.0; if (object != 0) { branch = (TBranch*)object; totalWeight = *(Float_t*)branch->GetAddress(); } if (fabs(tree.probe_SC_eta) < 1.4442) { ++nEB; hist3D->Fill(tree.dRTagProbe, tree.probe_nJets05, tree.event_nPV, totalWeight); hist2D->Fill(tree.dRTagProbe, tree.probe_passing, totalWeight); } } cout << "No. of probes in EB: " << nEB << endl; return nEvtsRead; }
vector<TString> getAliasNames(TTree *t) { vector<TString> v_aliasnames; TList *t_list = t->GetListOfAliases(); for(int i = 0; i < t_list->GetSize(); i++) { TString aliasname(t_list->At(i)->GetName()); TBranch *branch = t->GetBranch(t->GetAlias(aliasname.Data())); TString branchname(branch->GetName()); TString branchtitle(branch->GetTitle()); if(branchname.BeginsWith("intss") || branchname.BeginsWith("floatss") || branchname.BeginsWith("doubless") || branchname.Contains("LorentzVectorss") || branchname.Contains("timestamp") ) { cout << "Sorry, I dont know about vector of vectors of objects. " << "Will be skipping " << aliasname << endl; continue; } if(branchname.Contains("TString") ) { cout << "Sorry, I don't know how to graphically represent TStrings in only 3 dimensions" << " Put in a feature request. Will be skipping " << aliasname << endl; continue; } v_aliasnames.push_back(aliasname); } sort(v_aliasnames.begin(), v_aliasnames.end()); return v_aliasnames; }
void updateweight(TString filename) { auto f = new TFile(filename,"update"); auto nt = (TTree *)f->Get("nt"); float prew, weight; TBranch *bw; bw = nt->Branch("weight",&weight); nt->SetBranchAddress("prew",&prew); int n = nt->GetEntries(); int onep = n/100; for (int i=0;i<n;i++) { if (i%onep==0) cout<<i/onep<<endl; nt->GetEntry(i); weight = prew; bw->Fill(); } nt->Write(); f->Close(); }
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; }
void scanDiffRecoTracks(std::string eName, std::string eoName, std::string branchReg = "recoTracks_*"){ gSystem->Load("libFWCoreFWLite"); gROOT->ProcessLine("AutoLibraryLoader::enable();"); TChain* e = new TChain("Events"); e->SetScanField(0); e->Add(eName.c_str()); TChain* eo = new TChain("Events"); eo->SetScanField(0); eo->Add(eoName.c_str()); e->AddFriend(eo, "eo"); TRegexp regg(branchReg.c_str(), kTRUE); TChain* tc = e ; TObjArray* tl = tc->GetListOfBranches(); Int_t nBr = tl->GetSize(); for (int iB=0;iB<nBr;++iB){ TBranch* br = (TBranch*)(tl->At(iB)); TString ts(br->GetName()); if(ts.Index(regg)>=0){ std::cout<<ts.Data()<<std::endl; tc->Scan(Form("Sum$(%s.obj.pt()>0):Sum$(eo.%s.obj.pt()>0):Sum$(%s.obj.pt()):Sum$(%s.obj.pt())-Sum$(eo.%s.obj.pt())", ts.Data(), ts.Data(), ts.Data(), ts.Data(), ts.Data()),"", ""); } } //> e.tecoTracks.recoT0.txt }
void make_scan_results() { TFile *f = TFile::Open("scan_results.root", "UPDATE"); f->Delete("SR;*"); T = new TTree("SR", "Scanning results"); TClonesArray* ts = new TClonesArray("IlcESDtrack", 32); TBranch * tb = T->Branch("T", &ts); delete ts; IlcMultiplicity *ms = 0; TBranch *mb = T->Branch("M", &ms); for (Int_t v = 0; v < 3; ++v) { vvv[v].vert = 0; vvv[v].branch = T->Branch(vvv[v].bname, &vvv[v].vert); } for (Int_t i=0; i<=9999; ++i) { TString name; name.Form("Tracks_%04d", i); ts = (TClonesArray*) f->Get(name); if (ts == 0) continue; name.Form("Tracklets_%04d", i); ms = (IlcMultiplicity*) f->Get(name); if (ms == 0) Error("make_scan_results", "'%s' not found.", name.Data()); tb->SetAddress(&ts); mb->SetAddress(&ms); for (Int_t v = 0; v < 3; ++v) { name.Form("%s_%04d", vvv[v].oname, i); vvv[v].vert = (IlcESDVertex*) f->Get(name); if (vvv[v].vert == 0) Error("make_scan_results", "'%s' not found.", name.Data()); vvv[v].branch->SetAddress(&vvv[v].vert); } T->Fill(); delete ts; delete ms; for (Int_t v = 0; v < 3; ++v) delete vvv[v].vert; } T->Write(); f->Close(); delete f; }
//_____________________________________// Bool_t UpdateTag(TString faliroot, TString froot, TString fgeant, TString turl, TString guid, TString fperiod, TString fpass, TString fname) { cout<<"> Updating tags...."<<endl; const char * tagPattern = "tag.root"; // Open the working directory void * dirp = gSystem->OpenDirectory(gSystem->pwd()); const char * name = 0x0; // Add all files matching *pattern* to the chain while((name = gSystem->GetDirEntry(dirp))) { cout<<">>> Adding to chain file " << name << "...." << endl; if (strstr(name,tagPattern)) { TFile *f = TFile::Open(name,"read") ; AliRunTag *tag = 0x0; AliFileTag *flTag = 0x0; TTree *fTree = (TTree *)f->Get("T"); if (!fTree) { f->Close(); continue; } fTree->SetBranchAddress("AliTAG",&tag); //Defining new tag objects AliRunTag *newTag = 0x0; TTree ttag("T","A Tree with event tags"); TBranch * btag = ttag.Branch("AliTAG", &newTag); btag->SetCompressionLevel(9); cout<<">>>>> Found " << fTree->GetEntries() << " entries...." << endl; for(Int_t iTagFiles = 0; iTagFiles < fTree->GetEntries(); iTagFiles++) { fTree->GetEntry(0); newTag = new AliRunTag(*tag); newTag->SetAlirootVersion(faliroot); newTag->SetRootVersion(froot); newTag->SetGeant3Version(fgeant); newTag->SetLHCPeriod(fperiod); newTag->SetReconstructionPass(fpass); newTag->SetProductionName(fname); cout << "Found " << newTag->GetNFiles() << " file tags" << endl; for(Int_t j = 0; j < newTag->GetNFiles(); j++) { flTag = (AliFileTag *) newTag->GetFileTag(j); flTag->SetTURL(turl); flTag->SetGUID(guid); } ttag.Fill(); delete tag; delete newTag; }//tag file loop TFile* ftag = TFile::Open(name, "recreate"); ftag->cd(); ttag.Write(); ftag->Close(); }//pattern check }//directory loop return kTRUE; }
void printTreeSummary(TTree *t) { cout << "The TTree \"" << t->GetName() << "\" takes " << sizeOnDisk(t) << " bytes on disk\n"; size_t n = t->GetListOfBranches()->GetEntries(); for( size_t i = 0; i < n; ++ i ) { TBranch *br =dynamic_cast<TBranch*>(t->GetListOfBranches()->At(i)); cout << " It's branch \"" << br->GetName() << "\" takes " << sizeOnDisk(br,true) << " bytes on disk\n"; } }
void printBranchSummary(TBranch *br) { cout << "The branch \"" << br->GetName() << "\" takes " << sizeOnDisk(br,true) << " bytes on disk\n"; size_t n = br->GetListOfBranches()->GetEntries(); for( size_t i = 0; i < n; ++ i ) { TBranch *subbr = dynamic_cast<TBranch*>(br->GetListOfBranches()->At(i)); cout << " It's sub-branch \"" << subbr->GetName() << "\" takes " << sizeOnDisk(subbr,true) << " bytes on disk\n"; } }
void D3PDSelector::loadData(std::string key) { if (m_loaded.find(key) == m_loaded.end()) { TBranch* toload = m_branches.find(key)->second; toload->GetEntry(m_curentry); m_loaded[key] = true; } }
void displaySingleChannelWaveforms(TString fdat, int board, int channel) { gStyle->SetOptStat(0); TFile *f = new TFile(fdat); if (f->IsZombie()){ cout << "Cannot open file: " << fdat << endl; return; } TBEvent *event = new TBEvent(); TTree *t1041 = (TTree*)f->Get("t1041"); TBranch *bevent = t1041->GetBranch("tbevent"); bevent->SetAddress(&event); TCanvas * canv = new TCanvas("canv", "canv", 2000, 2000); canv->cd(); TH1F * dummy = new TH1F("dummy", "dummy", 120, 0, 120); dummy->GetYaxis()->SetRangeUser(0, 2500); dummy->Draw(); vector<TH1F*> waves; TH1F * wave = new TH1F("wave", "wave", 120, 0, 120); int nplots = 0; for (Int_t i = 0; i < t1041->GetEntries(); i++) { t1041->GetEntry(i); for (int j = 0; j < event->NPadeChan(); j++){ PadeChannel pch = event->GetPadeChan(j); if((int)pch.GetBoardID() != board || (int)pch.GetChannelID() != channel) continue; pch.GetHist(wave); nplots++; TH1F * wavecopy = (TH1F*)wave->Clone("wave_"+TString(Form("%d", nplots))); waves.push_back(wavecopy); } } int nBigPeaks = 0; for(unsigned int ui = 0; ui < waves.size(); ui++) { if(waves[ui]->GetMaximum() > 400) { waves[ui]->SetLineColor(nBigPeaks+2); nBigPeaks++; } waves[ui]->Draw("same"); } }
void ResetDeleteBranches(TTree* tree) { TObjArray* branches = tree->GetListOfBranches(); Int_t nb = branches->GetEntriesFast(); for (Int_t i = 0; i < nb; ++i) { TBranch* br = (TBranch*) branches->UncheckedAt(i); if (br->InheritsFrom(TBranchElement::Class())) { ((TBranchElement*) br)->ResetDeleteObject(); } } }
int test_event() { TTree *T = (TTree*)gFile->Get("T"); SillyStlEvent *event = new SillyStlEvent(); event->foo = 0xfa3; TBranch *branch = T->GetBranch("test"); branch->SetAddress(&event); T->GetEvent(0); return event->foo.to_ulong() != 0xfa2; }
void Write(bool write=false) { TFile *f = new TFile("RootRelations.root", "RECREATE", "Root RootRelations test",0); TTree *tree = new TTree("T","An example of a ROOT tree"); Relation1D<int,float>* obj = new Relation1D<int,float>(); if (gDebug>0) { fprintf(stderr,"Relation1D<int,float> is %p\n",obj); fprintf(stderr,"DataObject is %p\n",(DataObject*)obj); fprintf(stderr,"Relation<int,float> is %p\n",(Relation<int,float>*)obj); fprintf(stderr,"m_direct is %p\n",&(obj->m_direct)); fprintf(stderr,"m_direct.m_entries is %p\n",&(obj->m_direct.m_entries)); } TBranch *b = tree->Branch("B", "Relation1D<int,float>", &obj); if (write) { printf("relations' write\n"); for(int i=0; i < 10; ++i) { obj->m_direct.m_entries.push_back(std::pair<int,float>(10*i,i)); DataTObject *dobj = new ( obj->m_direct.m_tentries[0] ) DataTObject(i*22,i*22/3.0); DataTObject *dobj2 = new ( (*(obj->m_direct.m_ptentries))[0] ) DataTObject(i*44,i*44/3.0); if (!dobj || !dobj2) return; printf("byte written for entry #%d: %d\n",i,tree->Fill()); if (gDebug>0) { printf("byte re-read for the same entry: %d %p\n", tree->GetEvent(i), obj); } if (i<0) { fprintf(stderr,"the pointer are %p and %p\n", dobj,obj->m_direct.m_tentries.At(0)); } printf("values written for entry #%d: %d, %f, %d, %f, %d, %f\n", i, obj->m_direct.m_entries[0].first, obj->m_direct.m_entries[0].second, ((DataTObject*)obj->m_direct.m_tentries.At(0))->i, ((DataTObject*)obj->m_direct.m_tentries.At(0))->j, ((DataTObject*)obj->m_direct.m_ptentries->At(0))->i, ((DataTObject*)obj->m_direct.m_ptentries->At(0))->j ); obj->m_direct.m_entries.clear(); obj->m_direct.m_tentries.Clear(); } b->Write(); tree->Write(); tree->Print(); f->Write(); } delete f; };
/********************* * BRANCHES * ******************* */ void Tree::selectBranches() { //Deactivate all branches (used branches activated below) tree->SetBranchStatus("*", 0); TBranch *branch; //Timestamp branch = tree->GetBranch("Time"); branch->SetStatus(1); branch->SetAddress(&branchTime); //ECal energy branch = tree->GetBranch("EcalEnergy"); branch->SetStatus(1); branch->SetAddress(&branchEcalEnergy); //Rigidity branch = tree->GetBranch("TrackerRigidity"); branch->SetStatus(1); branch->SetAddress(&branchTrackerRigidity); //Ecal BDT branch = tree->GetBranch("EcalBDT"); branch->SetStatus(1); branch->SetAddress(&branchEcalBDT); }
void testgeo(const char* rootfile) { // Clear global scope gROOT->Reset(); // Load the library with class dictionary info gSystem->Load("libWCSimRoot.so"); // Open the file, replace if you've named it something else TFile file(rootfile); // Get the a pointer to the tree from the file TTree *gtree = (TTree*)file.Get("wcsimGeoT"); // Get the number of events int nevent = gtree->GetEntries(); printf("geo nevent %d\n",nevent); // Create a WCSimRootGeom to put stuff from the tree in WCSimRootGeom* wcsimrootgeom = new WCSimRootGeom(); // Set the branch address for reading from the tree TBranch *branch = gtree->GetBranch("wcsimrootgeom"); branch->SetAddress(&wcsimrootgeom); // Now loop over "events" (should be only one for geo tree) int ev; for (ev=0;ev<nevent; ev++) { // Read the event from the tree into the WCSimRootGeom instance gtree->GetEntry(ev); printf("Cyl radius %f\n", wcsimrootgeom->GetWCCylRadius()); printf("Cyl length %f\n", wcsimrootgeom->GetWCCylLength()); printf("PMT radius %f\n", wcsimrootgeom->GetWCPMTRadius()); printf("Offset x y z %f %f %f\n", wcsimrootgeom->GetWCOffset(0), wcsimrootgeom->GetWCOffset(1),wcsimrootgeom->GetWCOffset(2)); int numpmt = wcsimrootgeom->GetWCNumPMT(); printf("Num PMTs %d\n", numpmt); int i; for (i=0;i<((numpmt<20)?numpmt:20);i++){ WCSimRootPMT pmt; pmt = wcsimrootgeom->GetPMT(i); printf ("pmt %d %d %d\n",i,pmt.GetTubeNo(), pmt.GetCylLoc()); printf ("position: %f %f %f\n", pmt.GetPosition(0), pmt.GetPosition(1),pmt.GetPosition(2)); printf ("orientation: %f %f %f\n", pmt.GetOrientation(0), pmt.GetOrientation(1),pmt.GetOrientation(2)); } } // End of loop over events }
AppResult GeneratorReader::beginRun(AppEvent& event) { TTree *Events = 0; if( event.get("Events",Events) || !Events ) return AppResult(AppResult::STOP|AppResult::ERROR,"No 'Events' tree found"); TBranch *inputGen = Events->GetBranch("BNmcparticles_BNproducer_MCstatus3_BEANs."); if( !inputGen ) return AppResult(AppResult::STOP|AppResult::ERROR,"No 'BNmcparticles_BNproducer_MCstatus3_BEANs.' branch found"); inputGen->SetAddress(&__genParticles); return AppResult(); }
void kt_test_pico(TString fin="test.root") { gROOT->Reset(); gROOT->Clear(); // ktJet lib if (gClassTable->GetID("ktJet") < 0) { cout<<"Load ktJet lib ..."<<endl; gSystem->Load("libKtJet.so"); } cout<<endl; cout<<" Test STAR pico Dst interface"<<endl; cout<<" ----------------------------"<<endl; cout<<endl; cout<<"Open STAR pico Dst file : "<<fin<<endl; cout<<endl; TFile *inFile = TFile::Open(fin); inFile->cd(); TTree *outT = inFile->Get("JetTree"); TStarJetPicoEvent *event = new TStarJetPicoEvent(); TBranch *branch = outT->GetBranch("PicoJetTree"); branch->SetAddress(&event); Int_t ievents = outT->GetEntries(); cout<<"Number of events = "<<ievents<<endl; ktStarPico *mQA=new ktStarPico(true); mQA->PrintQACuts(); for (Int_t i = 0; i<ievents; i++) { if (i>250) continue; outT->GetEvent(i); mQA->DoQAOnly(event); } mQA->WriteQAOutputFile("QA_test_out.root"); //inFile->Close(); delete mQA; cout<<endl; cout<<"Done ;-)"<<endl; cout<<endl; }
mTree(TTree *t){ name=t->GetName(); entries=(long)t->GetEntries(); totSize=t->GetZipBytes(); leaves=t->GetListOfBranches()->GetEntriesFast(); for (int i=0; i<leaves; i++) { TBranch* branch = (TBranch*)t->GetListOfBranches()->UncheckedAt(i); branch->SetAddress(0); // cout <<i<<"\t"<<branch->GetName()<<"\t BS: "<< branch->GetBasketSize()<<"\t size: "<< branch->GetTotalSize()<< "\ttotbytes: "<<branch->GetTotBytes() << endl; branchSizes.insert(std::pair<string,long>(branch->GetName(),branch->GetZipBytes())); } }
void addBranchToTreesInFiles() { //************************************************************ // Variables // vector<TString> fileName; fileName.push_back( "PhotonJetPt15_realPhotons.root" ); fileName.push_back( "PhotonJetPt30_realPhotons.root" ); // The following 4 variables set the scale float invLuminosityToScaleTo = 200; // in pb-1 vector<float> crossSection; crossSection.push_back( 2.9E5 ); crossSection.push_back( 3.2E4 ); vector<float> filterEffeciency; filterEffeciency.push_back( 1.0 ); filterEffeciency.push_back( 1.0 ); vector<float> eventsAnalyzied; eventsAnalyzied.push_back( 950E3 ); eventsAnalyzied.push_back( 670E3 ); // END of setting scale TString treeName = "TreePhotonMatched"; // END of Variables // //************************************************************ // Loop over all the Files for (int i=0; i < fileName.size(); i++) { TFile* currentFile = new TFile(fileName[i],"update"); // this is the variable to be added Float_t scale=crossSection[i]*invLuminosityToScaleTo*filterEffeciency[i]/eventsAnalyzied[i]; cout << "Opened " << fileName[i] << ", adding new branch with value=" << scale; TTree *tree = (TTree*)currentFile->Get(treeName); TBranch *newBranch = tree->Branch("weight", &scale,"weight/F"); // Loop over all the entries, and add the new branch Int_t numEntries = (Int_t)tree->GetEntries(); for (Int_t j=0; j<numEntries; j++) { newBranch->Fill(); } tree->Write("",TObject::kOverwrite); // save new version only currentFile->Close(); cout << "...closed file." << endl; } }
//_____________________________________// Bool_t UpdateTag(TString faliroot, TString froot, TString fgeant, TString turl, TString guid) { cout<<"Updating tags....."<<endl; const char * tagPattern = "tag.root"; // Open the working directory void * dirp = gSystem->OpenDirectory(gSystem->pwd()); const char * name = 0x0; // Add all files matching *pattern* to the chain while((name = gSystem->GetDirEntry(dirp))) { if (strstr(name,tagPattern)) { TFile *f = TFile::Open(name,"read") ; AliRunTag *tag = new AliRunTag; AliEventTag *evTag = new AliEventTag; TTree *fTree = (TTree *)f->Get("T"); fTree->SetBranchAddress("AliTAG",&tag); //Defining new tag objects AliRunTag *newTag = new AliRunTag(); TTree ttag("T","A Tree with event tags"); TBranch * btag = ttag.Branch("AliTAG", &newTag); btag->SetCompressionLevel(9); for(Int_t iTagFiles = 0; iTagFiles < fTree->GetEntries(); iTagFiles++) { fTree->GetEntry(iTagFiles); newTag->SetRunId(tag->GetRunId()); newTag->SetAlirootVersion(faliroot); newTag->SetRootVersion(froot); newTag->SetGeant3Version(fgeant); const TClonesArray *tagList = tag->GetEventTags(); for(Int_t j = 0; j < tagList->GetEntries(); j++) { evTag = (AliEventTag *) tagList->At(j); evTag->SetTURL(turl); evTag->SetGUID(guid); newTag->AddEventTag(*evTag); } ttag.Fill(); newTag->Clear(); }//tag file loop TFile* ftag = TFile::Open(name, "recreate"); ftag->cd(); ttag.Write(); ftag->Close(); delete tag; delete newTag; }//pattern check }//directory loop return kTRUE; }
void getlist(ostream& out, TBranch* branch, int depth=0) { TObjArray* array = branch->GetListOfBranches(); if ( ! array ) return; if ( depth > 10 ) return; string name; int nitems = array->GetEntries(); for (int i = 0; i < nitems; i++) { TBranch* b = (TBranch*)((*array)[i]); if ( ! b ) continue; string branchname(b->GetName()); out << SPACE.substr(0,4*depth) << branchname << endl; TObjArray* a = b->GetListOfLeaves(); if ( a ) { int n = a->GetEntries(); { for (int j = 0; j < n; j++) { TLeaf* leaf = (TLeaf*)((*a)[j]); int count = 0; int ndata = 0; TLeaf* leafc = leaf->GetLeafCounter(count); if ( ! leafc) ndata = leaf->GetLen(); else ndata = leafc->GetMaximum(); string leafname(leaf->GetName()); out << SPACE.substr(0,4*(depth+1)) << ndata << " " << leafname << endl; } } // else if ( n == 1 ) // { // TBranch* bc = (TBranch*)((*a)[j]); // string leafname(bc->GetName()); // if ( leafname != branchname ) // out << SPACE.substr(0,4*(depth+1)) << leafname << endl; // } } getlist(out, b, depth+1); } }