コード例 #1
0
ファイル: fakeDAQ.C プロジェクト: brettviren/WbLS
void fakeDAQ(const char* outFile = "/Users/chaozhang/Projects/LBNE/WbLS/software/WbLSDAQ/data/test/fakedata.root")
{
    // WblsDaq::Spinner spinner("/Users/chaozhang/Projects/LBNE/WbLS/software/WbLSDAQ/data/test/example2.root");
    // TTree* header = spinner.header_tree();
    // TTree* footer = spinner.footer_tree();
    // TTree* events = spinner.event_tree();
    
    TFile* fp = TFile::Open("/Users/chaozhang/Projects/LBNE/WbLS/software/WbLSDAQ/data/test/example2.root"); // intentional leak
    TTree* header = (TTree*)fp->Get("Header");
    TTree* footer = (TTree*)fp->Get("Footer");
    TTree* events = (TTree*)fp->Get("FADCData");
    
    const int N = 120; // fake 400 events
    int nentries = events->GetEntries();
    gRandom->SetSeed(0);
    int startN = int(gRandom->Uniform(nentries));
    TString sel = Form("Entry$>=%d && Entry$<%d", startN, startN + N);
    TFile f(outFile, "recreate");    
    TTree *th = header->CopyTree("Entry$<8");
    TTree *tf = footer->CopyTree("Entry$<8");
    TTree *te = events->CopyTree(sel.Data());
    // TTree *te = events->CopyTree("Entry$>1850 && Entry$<1970");
    // cout << sel << endl;
    th->Write();
    tf->Write();
    te->Write();
    f.Close();
    // cout << outFile << endl;
}
コード例 #2
0
ファイル: runupdates.C プロジェクト: jlsalmon/roottest
void runupdates() { 

   TFile *f = new TFile("blah.root","RECREATE"); 
   f->cd(); 
   struct mys{
      Float_t x[3];
   }; 
   mys mys_t; 

   mys_t.x[0] = 1.1; 
   mys_t.x[1] = 12.2; 
   mys_t.x[2] = 13.3; 

   TTree *t = new TTree("mytree","mytree"); 
   t->Branch("mybranch",&mys_t,"x[3]/F"); 
   t->Fill(); 
   t->Write(); 
   f->Close(); 

   for (int i = 0; i < 500; i++) { 
      std::cerr << " i = " << i << std::endl; 
      TFile *fnew = new TFile("blah.root","UPDATE"); 
      TTree *tnew = (TTree*)fnew->Get("mytree");
      tnew->SetBranchAddress("mybranch",&mys_t);
      if (i % 3 == 0) tnew->Fill(); 
      tnew->Write("",TObject::kOverwrite); 
      delete fnew; 
   } 
}
コード例 #3
0
ファイル: Run4select.C プロジェクト: jintonic/gerdalinchenII
void pre(Int_t setID)
{
    TChain* pstr = new TChain("PSTree","root");
    if (setID==1) {
        for (Int_t i=1; i<10; i++)
            pstr->AddFile(Form("/remote/pclg-10/SIEGFRIED_II/Cd_SII_PS/Cd_In_SII_PS000%d.root",i));
        for (Int_t i=70; i<85; i++)
            pstr->AddFile(Form("/remote/pclg-10/SIEGFRIED_II/Cd_SII_PS/Cd_In_SII_PS00%d.root",i));
    }
    else if (setID==2)
        for (Int_t i=10; i<30; i++)
            pstr->AddFile(Form("/remote/pclg-10/SIEGFRIED_II/Cd_SII_PS/Cd_In_SII_PS00%d.root",i));
    else if (setID==3)
        for (Int_t i=30; i<50; i++)
            pstr->AddFile(Form("/remote/pclg-10/SIEGFRIED_II/Cd_SII_PS/Cd_In_SII_PS00%d.root",i));
    else if (setID==4)
        for (Int_t i=50; i<70; i++)
            pstr->AddFile(Form("/remote/pclg-10/SIEGFRIED_II/Cd_SII_PS/Cd_In_SII_PS00%d.root",i));

    Int_t Cha_MCAEnergy[8];
    pstr->SetBranchAddress("Cha_MCAEnergy",Cha_MCAEnergy);

    TFile* foutput = new TFile(Form("Run4pre%d.root",setID),"recreate");
    TTree *newtree = pstr->CloneTree(0);

    const Int_t Ncha = 7;

    Int_t Nevt = pstr->GetEntries();
    cout<<"Total Events: "<<Nevt<<endl;

    for (Int_t i=0; i<Nevt; i++) {
        if (i%10000==0)
            cout<<"Now event: "<<i<<endl;

        pstr->GetEntry(i);

        Int_t Nseg=0;
        for (Int_t j=1; j<Ncha-1; j++) {
            if (Cha_MCAEnergy[j]>1000 && Cha_MCAEnergy[j]<7000) {
                Nseg++;
            }
        }
        if (Nseg==1) {
            newtree->Fill();
        }
        if (i%10000==0) newtree->Write();
    }

    newtree->Write();
    foutput->Close();
}
コード例 #4
0
void ConvertFastFrameData(string cUserFileName, string cUserColSep, Bool_t bIsGermanDecimal){
	// +++ open Fast Frame data file +++
	ifstream UserDataFile(cUserFileName.c_str()); // open data file
	if(UserDataFile.fail()){ // if opening fails, exit
		cerr << "Failed to open " << cUserFileName << "!" << endl;
		exit (-1);
	}
	// +++ create ROOT output file +++
	string cOutputFileName = cUserFileName + ".root"; // append .root to existing file name
	TFile OutputFile(cOutputFileName.c_str(),"RECREATE"); // create new ROOT file, if existing already it will be overwritten
	if (OutputFile.IsZombie()) { // if creating new ROOT file fails, exit program
       cout << "Error opening file" << endl;
		UserDataFile.close();
       exit(-1);
    }
	// +++ parse header information +++
	FASTFRAME_HEADER FastFrameHeaderData;
	TTree *tFastFrameHeaderData = ParseForHeaderData(&UserDataFile,&FastFrameHeaderData,cUserColSep,bIsGermanDecimal);
	if(tFastFrameHeaderData==NULL){
		cerr << "Error while parsing header data!" << endl;
		exit (-1);
	}
	// +++ parse timestamp data +++
	TTree *tFastFrameTimestamps = ParseForTimestampData(&UserDataFile,FastFrameHeaderData.nRecordLength,cUserColSep,bIsGermanDecimal);
	if(tFastFrameTimestamps==NULL){
		cerr << "Error while parsing timestamp data!" << endl;
		exit (-1);
	}
	// +++ parse amplitude data +++
	TTree *tFastFrameAmplitudes = ParseForAmplitudeData(&UserDataFile,FastFrameHeaderData.nRecordLength,cUserColSep,bIsGermanDecimal);
	if(tFastFrameAmplitudes==NULL){
		cerr << "Error while parsing amplitude data!" << endl;
		exit (-1);
	}
	if(FastFrameHeaderData.nFastFrameCount!=tFastFrameAmplitudes->GetEntries()){
		cerr << "Mismatch of decoded event numbers!" << endl;
		exit (-1);
	}
	// +++ write TTrees to output file +++
	OutputFile.cd();
	tFastFrameHeaderData->Write();
	tFastFrameTimestamps->Write();
	tFastFrameAmplitudes->Write();
	// +++ cleaning up +++
	UserDataFile.close();
	delete tFastFrameHeaderData;
	delete tFastFrameTimestamps;
	delete tFastFrameAmplitudes;
}
コード例 #5
0
void createTree(const char* fn , Int_t seed) {
  TFile* f = TFile::Open(fn,"update");
  f->cd();
  Double_t aD;
  Float_t aF;
  Int_t aI;
  Double_t aVD[5];
  vector<Double_t> aSD(10);
  vector<Double_t>* pSD = &aSD;
  TTree *t = new TTree("TestTree","TestTree");
  t->Branch("aDouble",&aD,"aDouble/D");
  t->Branch("aFloat",&aF,"aFloat/F");
  t->Branch("aInt",&aI,"aInt/I");
  t->Branch("aArrayD",&(aVD[0]),"aArrayD[5]/D");
  t->Branch("aStdVecD","vector<Double_t>",&pSD);

  TRandom rn(seed);
  for ( Int_t evt = 0 ; evt < 1000 ; ++ evt ) {
    aD = rn.Gaus();
    aF = rn.Uniform();
    aI = rn.Integer(100);
    for ( Int_t i = 0 ; i<10 ; ++i ){
      if ( i < 5 ) aVD[i] = rn.Gaus( i , 0.1 );
      aSD[i] = rn.Gaus( -i , 0.1 );
    }
    t->Fill();
  }
  t->Print();
  t->Write();
  f->Close();
}
コード例 #6
0
void clonesA_Event_w()
{
// protect against old ROOT versions
   if ( gROOT->GetVersionInt() < 30503 ) {
      cout << "Works only with ROOT version >= 3.05/03" << endl;
      return;
   }
   if ( gROOT->GetVersionDate() < 20030406 ) {
      cout << "Works only with ROOT CVS version after 5. 4. 2003" << endl;
      return;
   }

   //write a Tree
   TFile *hfile = new TFile("clonesA_Event.root","RECREATE","Test TClonesArray");
   TTree *tree  = new TTree("clonesA_Event","An example of a ROOT tree");
   TUsrSevtData1 *event1 = new TUsrSevtData1();
   TUsrSevtData2 *event2 = new TUsrSevtData2();
   tree->Branch("top1","TUsrSevtData1",&event1,8000,99);
   tree->Branch("top2","TUsrSevtData2",&event2,8000,99);
   for (Int_t ev = 0; ev < 10; ev++) {
      cout << "event " << ev << endl;
      event1->SetEvent(ev);
      event2->SetEvent(ev);
      tree->Fill();
      if (ev <3) tree->Show(ev);
   }
   tree->Write();
   tree->Print();
   delete hfile;
}
コード例 #7
0
ファイル: SkimFlatCat.C プロジェクト: jalmond/LQanalyzer
void SkimFlatCat::Loop()
{

   if (fChain == 0) return;
   

   TFile *skimfile = new TFile("Skim.root","recreate"); 
   fChain->LoadTree(0); 
   
   TTree *newtree = fChain->CloneTree(0);
 
   
   Long64_t nentries = fChain->GetEntriesFast();
   Int_t nselected = 0;
   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
     if(!(jentry%10000)) std::cout << jentry << " :  "<<  fChain->GetEntries() << std::endl; 
     Long64_t ientry = LoadTree(jentry);
   
     if (ientry < 0) break;
     nb = fChain->GetEntry(jentry);   nbytes += nb;
     
     if (Cut(ientry) < 0) continue;
     nselected++;
     
     newtree->Fill();
   }
   std::cout << "Selected " << nselected << " out of " << fChain->GetEntries() << std::endl; 
   newtree->Write();
   skimfile->Close();
}
コード例 #8
0
void DiHiggs_h2tohh(TString inputFile, TString outputFile)
//void DiHiggs_htobb()
{
  //gSystem->Load("libDelphes");

  TChain *chain = new TChain("Delphes");
  //const char *inputFile("/home/taohuang/Herwig++/Delphes-3.2.0/delphes_output.root");
  //const char *inputFile("/fdata/hepx/store/user/taohuang/Hhh/delphes320_B3_100k.root");
  chain->Add(inputFile);

  ExRootTreeReader *treeReader = new ExRootTreeReader(chain);


  TTree *evtree = new TTree("evtree","event tree");
  
  
  AnalyseEvents(treeReader, evtree);
  //evtree->Print();
  TFile *file = new TFile(outputFile,"recreate");
  evtree->Write();
  file->Close();

  cout << "** Exiting..." << endl;

  delete treeReader;
  delete chain;
  delete evtree;
  delete file;
}
コード例 #9
0
void oniaTreeMassCut(int oniamode=1) 
{

  TChain* myTree = new TChain("hionia/myTree","");     
  myTree->Add("OniaTree_DoubleMu_Run2015E-PromptReco-v1_Run_262157_262328_noCUT.root");

  Double_t massmin = -1;
  Double_t massmax = -1;

  TString signame;
  if (oniamode==1) {
    signame = TString("Jpsi");
    massmin = 2.0;
    massmax = 5.0;
  }
  else if (oniamode==2) {
    signame = TString("Upsilon");
    massmin = 9;
    massmax = 10;
  }
  TFile *fout = new TFile("OniaTree_Reduced.root","RECREATE");  
   
  TTree *myNewTree = massCut((TChain*)myTree , massmin, massmax);
 
  fout->cd();

  TDirectory *cdtof = myNewTree->mkdir("hionia");
  cdtof->cd();
  myNewTree->Write("myTree");

  fout->Write();
  fout->Close();
}
コード例 #10
0
int main (int argc, char** argv)
{
  gRandom->SetSeed (time (0)) ;

  TF1 pol2pie ("pol2pie", "-1*(x-5)*(x-5) + 70", 0., 10.) ;
  TF1 flatFunc ("flatFunc", "3", 0., 10.) ;

   typedef struct {
      Float_t x,y ;
   } VARS;

  static VARS vars ;
  TTree al ("sample","bkg test sample") ;
  al.Branch ("vars",&vars,"x/F:y/f") ;

  for (int i = 0 ; i < 10000 ; ++i)
    {
      vars.x = pol2pie.GetRandom () ;
      vars.y = flatFunc.GetRandom () ;
      al.Fill () ;
    }
  TFile out (argv[1],"recreate") ;
  al.Write () ;
  out.Close () ;
  
  return 0 ;

}
コード例 #11
0
ファイル: test.cpp プロジェクト: ETHZ/h2gglobe
int main(){
  
  RooMsgService::instance().setGlobalKillBelow(ERROR);
  
  TFile *bkgFile = TFile::Open("comb_svn/hgg.inputbkgdata_8TeV_MVA.root");
  RooWorkspace *bkgWS = (RooWorkspace*)bkgFile->Get("cms_hgg_workspace");
  RooRealVar *mass = (RooRealVar*)bkgWS->var("CMS_hgg_mass");
  RooDataSet *data = (RooDataSet*)bkgWS->data("data_mass_cat0");

  RooRealVar *p1 = new RooRealVar("p1","p1",-2.,-10.,0.);
  RooRealVar *p2 = new RooRealVar("p2","p2",-0.001,-0.01,0.01);
  RooRealVar *p3 = new RooRealVar("p3","p3",-0.0001,-0.01,0.01);

  //RooPowerLawSum *pow1 = new RooPowerLawSum("pow","pow",*mass,RooArgList(*p1));
  //RooPowerLawSum *pow2 = new RooPowerLawSum("pow","pow",*mass,RooArgList(*p1,*p2));
  //RooPowerLawSum *pow3 = new RooPowerLawSum("pow","pow",*mass,RooArgList(*p1,*p2,*p3));

  RooExponentialSum *pow1 = new RooExponentialSum("pow1","pow1",*mass,RooArgList(*p1));
  RooExponentialSum *pow2 = new RooExponentialSum("pow2","pow2",*mass,RooArgList(*p1,*p2));
  RooExponentialSum *pow3 = new RooExponentialSum("pow3","pow3",*mass,RooArgList(*p1,*p2,*p3));

  TCanvas *canv = new TCanvas();
  RooPlot *frame = mass->frame();
  data->plotOn(frame);
  
  cout << "bus" << endl;
  pow1->fitTo(*data,PrintEvalErrors(-1),PrintLevel(-1),Warnings(-1),Verbose(-1));
  cout << "bus" << endl;
  pow1->plotOn(frame);
  pow2->fitTo(*data);
  pow2->plotOn(frame,LineColor(kRed),LineStyle(kDashed));
  pow3->fitTo(*data);
  pow3->plotOn(frame,LineColor(kGreen),LineStyle(7));
  frame->Draw();
  canv->Print("test.pdf");

  TFile *outFile = new TFile("test.root","RECREATE");

  TTree *tree = new TTree("tree","tree");

  vector<double> mu;
  mu.push_back(1.);
  mu.push_back(2.);
  mu.push_back(3.);
  mu.push_back(4.);
  vector<string> label;
  label.push_back("pol");
  label.push_back("pow");
  label.push_back("lau");
  label.push_back("exp");

  tree->Branch("mu",&mu);
  tree->Branch("label",&label);

  tree->Fill();
  outFile->cd();
  tree->Write();
  outFile->Close();
  return 0;
}
コード例 #12
0
ファイル: KVEventSelector.cpp プロジェクト: pwigg/kaliveda
void KVEventSelector::SlaveTerminate()
{
   // The SlaveTerminate() function is called after all entries or objects
   // have been processed. When running with PROOF SlaveTerminate() is called
   // on each slave server.
	// if tree have been defined in the CreateTrees method
	// manage the merge of them in ProofLite session
	//
	
   if (ltree->GetEntries()>0){
	
		if (writeFile) {
      	TDirectory *savedir = gDirectory;
      	TTree* tt = 0;
			for (Int_t ii=0;ii<ltree->GetEntries();ii+=1){
				tt = (TTree* )ltree->At(ii);
				writeFile->cd();
				tt->Write();
			}
      	mergeFile->Print();
      	fOutput->Add(mergeFile);
      
			for (Int_t ii=0;ii<ltree->GetEntries();ii+=1){
				tt = (TTree* )ltree->At(ii);
				tt->SetDirectory(0);
      	}
		
			gDirectory = savedir;
      	writeFile->Close();
   	}

	}

}
コード例 #13
0
void SkimRazorControlSample_RazorCuts( string inputfile, string outputfile) {
  
 
  //*******************************************************************************************
  //Read file
  //*******************************************************************************************                
  TFile *outputFile = new TFile(outputfile.c_str(), "RECREATE");

  ControlSampleEvents *events = new ControlSampleEvents;
  events->LoadTree(inputfile.c_str());

  //create new normalized tree
  outputFile->cd();
  TTree *outputTree = events->tree_->CloneTree(0);  
  cout << "Events in the original ntuple: " << events->tree_->GetEntries() << "\n";

  for(UInt_t ientry=0; ientry < events->tree_->GetEntries(); ientry++) {       	
    events->tree_->GetEntry(ientry);      
    if (ientry % 1000000 == 0) cout << "Event " << ientry << endl;      
    
    if ( events->MR > 300 && events->Rsq>0.0 ) {
      outputTree->Fill();
    }
  }

  cout << "Events Passing Skimming: " << outputTree->GetEntries() << "\n";
  cout << "Skim Efficiency : " <<  double(outputTree->GetEntries()) / events->tree_->GetEntries() << "\n";
  outputTree->Write();
  outputFile->Close();
  delete outputFile;

}
コード例 #14
0
void XRootOutput :: SetHeader(const int i, const double t, const double I, const double R, const double V)
{
  TTree* tree = new TTree("head", "data info");

  int id;
  double time, curr, res, volt;

  tree->Branch("id", &id, "id/I");
  tree->Branch("time", &time, "time/D");
  tree->Branch("I", &curr, "I/D");
  tree->Branch("R", &res, "R/D");
  tree->Branch("V", &volt, "V/D");

  id = i;
  time = t;
  curr = I;
  res = R;
  volt = V;

  tree->Fill();
  tree->Write();

  fInfo->Branch("name", &fName);
  fInfo->Branch("mshz", &fMshZ, "mshz/I");
  fInfo->Branch("mshp", &fMshP, "mshp/I");
  fInfo->Branch("mshr", &fMshR, "mshr/I");
}
コード例 #15
0
void ProduceTree(const char* filename, const char* treename, 
                 Int_t numentries, Int_t compression,
                 int numbranches, int branchsize, int buffersize) {
   TFile f(filename,"RECREATE");
   f.SetCompressionLevel(compression);
   
   TTree* t = new TTree(treename, treename);
   t->SetMaxTreeSize(19000000000.);
   
   Float_t* data = new Float_t[numbranches * branchsize];
   for (int i=0;i<numbranches * branchsize;i++)
      data[i] = 1.2837645786 * i;
      
   for (int nbr=0;nbr<numbranches;nbr++) {
      TString brname = "Branch";
      brname+=nbr;
      
      TString format = brname;
      format+="[";
      format+=branchsize;
      format+="]/F";
      
      t->Branch(brname.Data(),&(data[nbr*branchsize]),format.Data(), buffersize*branchsize*sizeof(Float_t));
   }   
   
   for (int n=0;n<numentries;n++)
     t->Fill();
   
   t->Write();
   
   delete t;
   
   delete[] data;
}
コード例 #16
0
void TreeFlattener::MakeFlatTree(){
  TFile* InFile = new TFile(InputFile);
  TTree* InTree =(TTree*)InFile->Get(TreeName.data());

  for(auto& B : BranchesToFlatten){
    int status=InTree->SetBranchAddress(B.BranchName.data(),&(B.StackedBranch));
    std::cout<<"Branch Set Status = "<<status<<"for branch "<<B.BranchName<<std::endl;
    if(status!=0){
      BranchAddressError BError(B.BranchName);
      throw BError;
    }
  }
  TFile* TOutFile  = new TFile(OutputFile,"RECREATE");
  TTree* NewTree = InTree->CloneTree(0);
  
  for(auto& B : BranchesToFlatten){
    std::string TypeName=B.BranchName+"/D";
    NewTree->Branch(B.FlatBranchName.data(),&(B.FlatBranch),TypeName.data());
  }
  LoopTimer LT(0.10);
  Long64_t N=InTree->GetEntries();
  for(int i=0;i<N;++i){
    LT.DeclareLoopStart(N);
    InTree->GetEntry(i);
    for(auto& B: BranchesToFlatten){
      B.FlatBranch=B.StackedBranch[0];
    }

    NewTree->Fill();
  }
  NewTree->Write();
  TOutFile->Close();
}
コード例 #17
0
//*************************************************************************************************
//Main part of the macro
//*************************************************************************************************
void NormalizeHwwNtuple(const string InputFilename, const string datasetName,
                        const string OutputFilename, const int nsel) {

    TTree* HwwTree = getTreeFromFile(InputFilename.c_str(),nsel);
    assert(HwwTree);

    MitNtupleEvent event(HwwTree);

    Double_t normalizationWeight = getNormalizationWeight(InputFilename, datasetName);

    //*************************************************************************************************
    //Create new normalized tree
    //*************************************************************************************************
    TFile *outputFile = new TFile(OutputFilename.c_str(), "RECREATE");
    outputFile->cd();

    TTree *normalizedTree = HwwTree->CloneTree(0);

    cout << "Events in the ntuple: " << HwwTree->GetEntries() << endl;

    for (int n=0; n<HwwTree->GetEntries(); n++) {
        event.GetEntry(n);
        event.H_weight = event.H_weight * normalizationWeight;
        normalizedTree->Fill();
    }

    normalizedTree->Write();
    outputFile->Close();
}
コード例 #18
0
ファイル: mergeFiles.C プロジェクト: fcostanz/StopAnalysis
void CopyDir(TDirectory *source) {
   //copy all objects and subdirs of directory source as a subdir of the current directory   
   source->ls();
   TDirectory *savdir = gDirectory;
   TDirectory *adir = savdir->mkdir(source->GetName());
   adir->cd();
   //loop on all entries of this directory
   TKey *key;
   TIter nextkey(source->GetListOfKeys());
   while ((key = (TKey*)nextkey())) {
      const char *classname = key->GetClassName();
      TClass *cl = gROOT->GetClass(classname);
      if (!cl) continue;
      if (cl->InheritsFrom(TDirectory::Class())) {
         source->cd(key->GetName());
         TDirectory *subdir = gDirectory;
         adir->cd();
         CopyDir(subdir);
         adir->cd();
      } else if (cl->InheritsFrom(TTree::Class())) {
         TTree *T = (TTree*)source->Get(key->GetName());
         adir->cd();
         TTree *newT = T->CloneTree(-1,"fast");
         newT->Write();
      } else {
         source->cd();
         TObject *obj = key->ReadObj();
         adir->cd();
         obj->Write();
         delete obj;
     }
  }
  adir->SaveSelf(kTRUE);
  savdir->cd();
}
コード例 #19
0
ファイル: DrawConsistency.C プロジェクト: c-dilks/scalers11t
void DrawConsistency()
{
  TFile * cons_file = new TFile("cons_file.root","RECREATE");
  TTree * tr = new TTree();
  // cons is run number or fill number, depending on what study you're doing
  tr->ReadFile("cons_study","cons/I:tbit/I:cbit/I:spinbit/I:p0/D:p0_err/D");
  tr->Write("tr");
}
コード例 #20
0
ファイル: Run4select.C プロジェクト: jintonic/gerdalinchenII
void morestrict()
{
    const Int_t Ncha = 6;

    Float_t N[Ncha]  = {0};
    Float_t dN[Ncha] = {0};

    Float_t ADC[Ncha]  = {0};
    Float_t dADC[Ncha] = {0};

    Float_t ADCw[Ncha]  = {0};
    Float_t dADCw[Ncha] = {0};

    ifstream dat;
    dat.open("Run4Nseg.txt");
    cout<<"channel \t ADC \t dADC \t ADCw \t dADCw \t N \t dN"<<endl;
    for (Int_t i=1; i<Ncha; i++) {
        dat>>ADC[i]>>dADC[i]>>ADCw[i]>>dADCw[i]>>N[i]>>dN[i];
        cout<<i<<" \t "<<ADC[i]<<" \t "<<dADC[i]<<" \t "
            <<ADCw[i]<<" \t "<<dADCw[i]<<" \t "
            <<N[i]<<" \t "<<dN[i]<<endl;
    }
    dat.close();

    TChain* pstr = new TChain("pstree","root");
    pstr->AddFile("Run4selected.root");

    Int_t Cha_MCAEnergy[8];
    pstr->SetBranchAddress("Cha_MCAEnergy",Cha_MCAEnergy);

    TFile* foutput = new TFile("Run4smaller.root","recreate");
    TTree *newtree = pstr->CloneTree(0);

    Int_t Nevt = pstr->GetEntries();
    cout<<"total events: "<<Nevt<<endl;

    for (Int_t i=0; i<Nevt; i++) {
        if (i%10000==0)
            cout<<"now event: "<<i<<endl;

        pstr->GetEntry(i);

        Int_t Nseg=0;
        for (Int_t j=1; j<Ncha; j++) {
            if (Cha_MCAEnergy[j]>ADC[j]-ADCw[j] &&
                    Cha_MCAEnergy[j]<ADC[j]+ADCw[j]) {
                Nseg++;
            }
        }

        if (Nseg==1) {
            newtree->Fill();
        }
    }

    newtree->Write();
    foutput->Close();
}
コード例 #21
0
void skim_2j_gammalep_3lep(string inpath = "/nfs-6/userdata/mt2/V00-00-03", string outpath = "/nfs-6/userdata/mt2/V00-00-03_skim_nj2_ht450_mt2gt50", string tag = "ttall_msdecays") {
  
  //--------------------------------------------------
  // cut for output files
  //--------------------------------------------------

  // NOTE: string below doesn't work correctly, implicitly requires all events to have 2 leptons
  //  const char* sel = "((njets >= 2 || njets_up >= 2 || njets_dn >= 2) || (evt_type == 2 && nlep > 0 && abs(lep_pdgId[0]) == 13) || (nlep > 2 && lep_pt[0] > 25 && lep_pt[1] > 20)) ";
  
  const char* sel = "((njets >= 2 || njets_up >= 2 || njets_dn >= 2) || (evt_type == 2 && nlep > 0) || (nlep > 2)) ";

  cout << "Skimming with selection : "<<sel<<endl;

  //--------------------------------------------------
  // input and output file
  //--------------------------------------------------
  
  const char* infilename = Form("%s/%s*.root",inpath.c_str(),tag.c_str());
  const char* outfilename = Form("%s/%s.root",outpath.c_str(),tag.c_str());
  
  //--------------------------------------------------
  // cout stuff
  //--------------------------------------------------
  
  cout << "Reading in : " << infilename << endl;
  cout << "Writing to : " << outfilename << endl;
  cout << "Selection : " << sel << endl;
  
  //--------------------------------------------------
  // read input file, write to output files
  //--------------------------------------------------
  
  //long long max_tree_size = 5000000000LL; // 5GB
  long long max_tree_size = 2500000000LL; // 2.5GB
  TTree::SetMaxTreeSize(max_tree_size);
  
  TChain *chain = new TChain("t");
  chain->Add(infilename);

  unsigned int input_entries = chain->GetEntries();
  cout << "Input tree has entries: " << input_entries << endl;
  
  //-------------------
  // skim
  //-------------------
  
  TFile *outfile = TFile::Open(outfilename, "RECREATE");
  assert( outfile != 0 );
  TTree* outtree = chain->CopyTree( sel );
  unsigned int output_entries = outtree->GetEntries();
  cout << "Output tree has entries: " << output_entries << endl
       << "Reduction factor of: " << double(input_entries)/double(output_entries) << endl;
  outtree->Write();
  outfile->Close();

}
コード例 #22
0
void rads2Hist(){
  TFile * output_file = new TFile("RADS_Data.root", "RECREATE"); //Pointer to ROOT output file 
  TH1D * hist = new TH1D("hist", "Radiation Dosimetry with Altitude", 100, 0, 10000); //1D histogram of doubles
  TTree * t = new TTree("t", "RADS_Data"); //Pointer to tree to store data
  t->ReadFile("RADS_long.dat", "RAD_cpm/I"); // Add integer variable to tree called RAD_cpm
  t->Write(); //Write tree to ROOT file
  output_file->Close();
  
  
}
コード例 #23
0
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;
};
コード例 #24
0
bool
convertEvtToTree(const string&  evtFileName              = "testEvents.evt",
                 const string&  outFileName              = "testEvents.root",
                 const long int maxNmbEvents             = -1,
                 const string&  outTreeName              = "rootPwaEvtTree",
                 const string&  prodKinPartNamesObjName  = "prodKinParticles",
                 const string&  prodKinMomentaLeafName   = "prodKinMomenta",
                 const string&  decayKinPartNamesObjName = "decayKinParticles",
                 const string&  decayKinMomentaLeafName  = "decayKinMomenta",
                 const bool     debug                    = false)
{
	// open input file
	printInfo << "opening input file '" << evtFileName << "'" << endl;
	ifstream evtFile(evtFileName.c_str());
	if (not evtFile or not evtFile.good()) {
		printWarn << "cannot open input file '" << evtFileName << "'" << endl;
		return false;
	}

	// create output file
	printInfo << "creating output file '" << outFileName << "'" << endl;
	TFile* outFile = TFile::Open(outFileName.c_str(), "RECREATE");
	if (not outFile) {
		printErr << "cannot open output file '" << outFileName << "'" << endl;
		return false;
	}

	// create tree
	TTree* tree = new TTree(outTreeName.c_str(), outTreeName.c_str());
	if (not tree) {
		printErr << "problems creating tree '" << outTreeName << "' "
		         << "in file '" << outFileName << "'" << endl;
		return false;
	}

	// doit
	TClonesArray* prodKinPartNames  = new TClonesArray("TObjString");
	TClonesArray* decayKinPartNames = new TClonesArray("TObjString");
	const bool    success           = fillTreeFromEvt(evtFile, *tree,
	                                                  *prodKinPartNames, *decayKinPartNames,
	                                                  maxNmbEvents,
	                                                  prodKinMomentaLeafName, decayKinMomentaLeafName,
	                                                  debug);
	tree->Write();
	prodKinPartNames->Write (prodKinPartNamesObjName.c_str (), TObject::kSingleKey);
	decayKinPartNames->Write(decayKinPartNamesObjName.c_str(), TObject::kSingleKey);

	outFile->Close();
	if (success)
		printSucc << "wrote events to file '" << outFileName << "'" << endl;
	else
		printWarn << "problems processing events" << endl;
	return success;
}
コード例 #25
0
ファイル: Copy.C プロジェクト: laerad84/Analysis
void Copy(){

  TFile* tfin = new TFile("/Volume0/ExpData/2012_Feb_Beam/RootFile_cosmic/CosmicResult_20120209.root");

  TFile* tfOut = new TFile("test.root","Recreate");
  TTree* tr   = (TTree*)tfin->Get("GainFitPar");
  TTree* trClone = tr->CopyTree("");
  trClone->Write();
  tfOut->Close();

}
コード例 #26
0
void mergetree(TString file1 = "/afs/cern.ch/work/s/shuai/public/diboson/trees/test/testnewsh/fullsig/treeEDBR_TTBAR_xww.root", TString file2 = "/afs/cern.ch/work/s/shuai/public/diboson/trees/test/testnewsh/fullsideband/treeEDBR_TTBAR_xww.root",TString outfile = "mergetreeTest.root")
{
	cout<<"file1 :"<<file1<<endl;
	cout<<"file2 :"<<file2<<endl;
	TChain * chain = new TChain("SelectedCandidates");
	chain->Add(file1);
	int nsig = chain->GetEntries();
	chain->Add(file2);
	int ntotal = chain->GetEntries();
	int nside = ntotal-nsig;
	cout<<"file1 entries: "<<nsig<<endl;
	cout<<"file2 entries: "<<nside<<endl;
	cout<<"file1+file2 entries: "<<ntotal<<endl;	
	
    TFile * outputfile = new TFile(outfile,"RECREATE");
	TTree * outTree = chain->CloneTree(0);

    int nCands;
	//int nEvt;
    chain->SetBranchAddress("nCands",&nCands);
    //chain->SetBranchAddress("nEvt",&nEvt);

	vector <int> sideEvent;

	//save events with signal region candidate for filesig
	for(int i =0; i<nsig; i++)
	{
		//if(i%10000==0)cout<<i<<endl;
		//if(i>200000)break;
		chain->GetEntry(i);
		//cout<<nEvt<<endl;
		//chain->GetEntry(nsig+i);
		//cout<<nEvt<<endl;
		
		if(nCands>0)outTree->Fill();//this event have signal region candidate ( 2 means there are Wmunu and Welenu. This will be filtered by loose lepton veto  )
		else sideEvent.push_back(nsig+i);	
	}
	
	for(int j=0; j<sideEvent.size(); j++ )
	{
		//if(j%10000==0)cout<<j<<endl;
		//if(j>200000)break;
		int n = sideEvent.at(j);
		chain->GetEntry(n);
		if(nCands>0)outTree->Fill();
	}
	
	cout<<"outTree entries: "<<outTree->GetEntries()<<endl;
	
	outputfile->cd();
	outTree->Write();
	outputfile->Close();
}
コード例 #27
0
void makeCentrality(){

  TFile* infData = TFile::Open("/afs/cern.ch/user/a/azsigmon/eos/cms/store/group/phys_heavyions/velicanu/forest/Run2015E/HIExpressPhysics/Merged/HIForestMinbiasUPC_run262548.root");

  float bounds[200] = {
0, 0, 4.89949, 7.99844, 8.92695, 9.66829, 10.4113, 11.0529, 11.7822, 12.4533, 13.1472, 13.9668, 14.7675, 15.5483, 16.4161, 17.3047, 18.1283, 19.0679, 20.051, 21.0405, 22.2351, 23.2812, 24.5173, 25.897, 27.1474, 28.459, 29.9013, 31.3157, 32.7494, 34.3873, 36.0111, 37.7366, 39.4742, 41.2605, 43.0352, 45.1332, 47.3762, 49.6964, 51.879, 54.4101, 56.8655, 59.4357, 61.9746, 64.6677, 67.6169, 70.5101, 73.4362, 76.9011, 80.2528, 83.2244, 86.7075, 90.251, 94.0596, 98.2499, 102.294, 106.763, 111.263, 116.182, 120.897, 125.363, 130.158, 135.085, 140.409, 146.08, 151.909, 157.415, 163.238, 169.32, 175.464, 182.866, 189.667, 197.613, 204.473, 212.603, 220.045, 227.635, 235.659, 244.188, 253.487, 261.769, 269.849, 278.664, 288.425, 297.848, 306.746, 316.694, 327.771, 337.893, 348.05, 359.054, 370.201, 381.906, 394.094, 406.909, 419.204, 432.827, 446.383, 460.286, 474.495, 489.801, 503.344, 517.537, 531.617, 545.604, 562.185, 577.949, 594.962, 612.415, 630.409, 647.859, 665.238, 683.566, 701.988, 721.231, 740.548, 759.612, 778.229, 797.684, 819.26, 844.711, 865.76, 888.009, 910.645, 931.656, 952.614, 974.873, 1001.99, 1026.11, 1050.47, 1074.6, 1096.31, 1123.83, 1148.94, 1174.01, 1199.23, 1228.52, 1258.23, 1286.83, 1317.29, 1347.72, 1376.62, 1405.23, 1440.22, 1472.31, 1505, 1539.24, 1572.41, 1607.52, 1638.3, 1675.36, 1714.35, 1749.18, 1787.1, 1826.05, 1866.69, 1905.91, 1944.2, 1985.24, 2025.87, 2069.84, 2116.89, 2163.97, 2207.1, 2253.35, 2297.07, 2343.68, 2386.1, 2436.58, 2485.76, 2539.44, 2590.07, 2641.06, 2692.61, 2740.54, 2797.53, 2853.44, 2906.16, 2970.53, 3026.77, 3083.32, 3140.47, 3207.33, 3268.97, 3335.02, 3411.45, 3479.12, 3553.01, 3626.72, 3694.18, 3765.61, 3840.09, 3916.15, 4000.97, 4081.75, 4173.33, 4264.96, 4367.08, 4463.28, 4572.44, 4702.18
};

  TTree* tref = (TTree*)infData->Get("hiEvtAnalyzer/HiTree");
  float hf; int hiBin;
  tref->SetBranchAddress("hiHF", &hf);
  tref->SetBranchAddress("hiBin", &hiBin);

  /*TTree *tskim = (TTree*)infData->Get("skimanalysis/HltTree");
  int phfCoincFilter3, pprimaryVertexFilter;
  tskim->SetBranchAddress("phfCoincFilter3", &phfCoincFilter3);
  tskim->SetBranchAddress("pprimaryVertexFilter", &pprimaryVertexFilter);

  TTree *thlt = (TTree*)infData->Get("hltanalysis/HltTree");
  int hlt_mbhfand;
  thlt->SetBranchAddress("HLT_HIL1MinimumBiasHF1AND_v1", &hlt_mbhfand);*/

  TFile* outf = new TFile("compare_centralitybins.root","recreate");
  int newbin;
  TTree* t = new TTree("anaCentrality","analysis level centrality");
  t->Branch("newBin",&newbin,"newBin/I");
  t->Branch("oldBin",&hiBin,"newBin/I");

  int N = tref->GetEntries();
  for(int i = 0; i < N; ++i){
    tref->GetEntry(i);
    //thlt->GetEntry(i);
    //tskim->GetEntry(i);
    if(i % 10000 == 0) cout<<"processing event : "<<i<<endl;
    //if(phfCoincFilter3 != 1) continue;
    //if(pprimaryVertexFilter != 1) continue;
    //if(hlt_mbhfand != 1) continue;

    newbin = 199;
    for(int b = 0; b < 200; ++b){
      if(hf >= bounds[199-b]){
	newbin = b;
	break;	    
      }
    }

    t->Fill();
  }

  t->Write();
  outf->Write();

}
コード例 #28
0
ファイル: Flux.C プロジェクト: zhangzc11/CPTV
void Flux()
{
	Double_t WidthOfBin = 86164.09/24.00;// 1 sidereal day = 86164.09 seconds
	Double_t StartTime = 1324678393.80705;
	Double_t EndTime = 1385769600.00000;
	const int NumOfBin = 17016;// (EndTime - StartTime)/WidthOfBin;//17016
	Double_t StartTime_Pow = 1324684800.00;//2011-12-24-00:00:00(UTC),the start time of the power data file.

	Double_t Flux_Save[8];

	ReadData();

	FILE* m_outfile = fopen("DayRate.txt", "w");
	for(int Bin=0;Bin<NumOfDay;Bin++)
	{
		fprintf(m_outfile,"%10d",Bin);
		for(int i=0;i<8;i++)
		{
			fprintf(m_outfile,"%10.3f",FluxIJ[i][Bin]);
		}
		fprintf(m_outfile,"\n");
	}
	fclose(m_outfile);

	

   TFile  *Fout = new TFile("Flux.root","recreate");
   TTree *FluxTree = new TTree("Flux","Flux");
   FluxTree->Branch("Flux",Flux_Save,"Flux_Save[8]/D");

   for(int Bin=0;Bin<NumOfBin;Bin++)
  {
	int N_Day = int((Bin*WidthOfBin + StartTime- StartTime_Pow)/86400.0);

	 if(N_Day<0)
	  {
		  N_Day=0;
	  }
	  if(N_Day>NumOfDay -1)
	  {
		  N_Day = NumOfDay-1;
	  }

	for(int Det=0;Det<8;Det++)
	{
		Flux_Save[Det] = FluxIJ[Det][N_Day];
	}

	FluxTree->Fill();
   }
   FluxTree->Write();
	
}
コード例 #29
0
void applyCutSignal(){
  TFile* file ;
  TChain* tree = new TChain("angles");
  tree->Add("../datafiles/JHUGenFiles/SMHiggs_125_JHU.root");
  double mZZ, m2, m1, costhetastar, costheta1, costheta2, phi, phi1,sepLD;
  tree->SetBranchAddress("zzmass",&mZZ);
  tree->SetBranchAddress("z2mass",&m2);
  tree->SetBranchAddress("z1mass",&m1);
  tree->SetBranchAddress("costhetastar",&costhetastar);
  tree->SetBranchAddress("phi",&phi);
  tree->SetBranchAddress("costheta1",&costheta1);
  tree->SetBranchAddress("costheta2",&costheta2);
  tree->SetBranchAddress("phi1",&phi1);

  TFile* fileOut; 
  double mZZout, m2out, m1out, costhetastarout, costheta1out, costheta2out, phiout, phi1out, Psig, Pbkg, D;
  fileOut = new TFile("../datafiles/JHUGenFiles/SMHiggs_125_JHU_withCuts.root","RECREATE");

  TTree* treeOut = new TTree("angles","angles, mzz, D");
  treeOut->Branch("zzmass",&mZZout,"zzmass/D");
  treeOut->Branch("z2mass",&m2out,"z2mass/D");
  treeOut->Branch("z1mass",&m1out,"z1mass/D");
  treeOut->Branch("costhetastar",&costhetastarout,"costhetastar/D");
  treeOut->Branch("phi",&phiout,"phi/D");
  treeOut->Branch("costheta1",&costheta1out,"costheta1/D");
  treeOut->Branch("costheta2",&costheta2out,"costheta2/D");
  treeOut->Branch("phi1",&phi1out,"phi1/D");

  for (Int_t i=0; i<tree->GetEntries();i++) {
    tree->GetEvent(i); 
    if(mZZ>180 || mZZ<110)
      continue;
    //if(m1+m2>125)
    //continue;
    if((i%10000)==0)
      cout<<"event "<<i<<endl;

    mZZout=mZZ;
    m1out= m1;
    m2out=m2;
    costhetastarout=costhetastar;
    costheta1out=costheta1;
    costheta2out=costheta2;
    phiout=phi;
    phi1out=phi1;
    if(m1>20 && m2>20)
      treeOut->Fill();
 }

  fileOut->cd();
  treeOut->Write();
}
コード例 #30
0
ファイル: basic2.C プロジェクト: Y--/root
void basic2() {
   TString dir = gROOT->GetTutorialsDir();
   dir.Append("/tree/");
   dir.ReplaceAll("/./","/");

   TFile *f = new TFile("basic2.root","RECREATE");
   TH1F *h1 = new TH1F("h1","x distribution",100,-4,4);
   TTree *T = new TTree("ntuple","data from ascii file");
   Long64_t nlines = T->ReadFile(Form("%sbasic.dat",dir.Data()),"x:y:z");
   printf(" found %lld points\n",nlines);
   T->Draw("x","z>2");
   T->Write();
}