Example #1
0
void ChainToTextFile(TChain* chain, const char* target)
{
  // write a text list of the files in the chain
  
  TObjArray* list = chain->GetListOfFiles();
  TIterator* iter = list->MakeIterator();
  TObject* obj = 0;

  ofstream outfile;
  outfile.open(target);

  while ((obj = iter->Next())) {
    TString fileName(obj->GetTitle());
    
    outfile << fileName.Data() << endl;
  }

  outfile.close();

  delete iter;
} 
int main(int argc, char *argv[])
{
  // Declaration of variables
  ExRootConfReader *confReader = 0;
  Delphes *modularDelphes = 0;
  DelphesFactory *factory = 0;
  TObjArray *allParticleOutputArray = 0;
  TObjArray *stableParticleOutputArray = 0;
  TObjArray *partonOutputArray = 0;

  Int_t event;

  TObjArray *inputArray = 0;
  TIterator *inputIterator = 0;
  Candidate *candidate = 0;
  TLorentzVector momentum;

  JetDefinition *definition = 0;
  vector<PseudoJet> inputList, outputList;
  PseudoJet jet;

  gROOT->SetBatch();

  int appargc = 1;
  char appName[] = "ExternalFastJetBasic";
  char *appargv[] = {appName};
  TApplication app(appName, &appargc, appargv);

  if(argc != 2)
  {
    cout << " Usage: " << appName << " config_file" << endl;
    cout << " config_file - configuration file in Tcl format." << endl;
    return 1;
  }

  try
  {
    // Initialization
    confReader = new ExRootConfReader;
    confReader->ReadFile(argv[1]);

    modularDelphes = new Delphes("Delphes");
    modularDelphes->SetConfReader(confReader);

    factory = modularDelphes->GetFactory();

    allParticleOutputArray = modularDelphes->ExportArray("allParticles");
    stableParticleOutputArray = modularDelphes->ExportArray("stableParticles");
    partonOutputArray = modularDelphes->ExportArray("partons");

    modularDelphes->InitTask();

    
    // fastjet definition
    ClusterSequence::print_banner();
    definition = new JetDefinition(antikt_algorithm, 0.5);
    
    // Define your input candidates to fastjet (by default particle-flow objects).
    // If you want pure calorimeter towers change "EFlowMerger/eflow" into "Calorimeter/towers":
     
    inputArray = modularDelphes->ImportArray("EFlowMerger/eflow");
      
    inputIterator = inputArray->MakeIterator();

    // Event loop
    for(event = 0; event < NEVENTS; ++event)
    {
      modularDelphes->Clear();
      
      // convert EVENT input array into Delphes internal format
      ConvertInput(event, factory, allParticleOutputArray, stableParticleOutputArray, partonOutputArray);
      
      // run Delphes reconstruction
      modularDelphes->ProcessTask();

      inputList.clear();
      inputIterator->Reset();
      
      
      // pass delphes candidates to fastjet clustering  
      while((candidate = static_cast<Candidate*>(inputIterator->Next())))
      {
        momentum = candidate->Momentum;
        jet = PseudoJet(momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
        inputList.push_back(jet);
      }
     
      // run clustering 
      ClusterSequence sequence(inputList, *definition);
      outputList.clear();
      outputList = sorted_by_pt(sequence.inclusive_jets(0.0));

      // tell the user what was done
      //  - the description of the algorithm used
      //  - show the inclusive jets as
      //      {index, rapidity, phi, pt}
      //----------------------------------------------------------
      cout << "Ran " << definition->description() << endl;

      // label the columns
      printf("%5s %15s %15s %15s\n","jet #", "rapidity", "phi", "pt");

      // print out the details for each jet
      for (unsigned int i = 0; i < outputList.size(); i++) {
        printf("%5u %15.8f %15.8f %15.8f\n",
               i, outputList[i].rap(), outputList[i].phi(),
               outputList[i].perp());
      }
    }

    // Finalization
    modularDelphes->FinishTask();
    delete modularDelphes;
    delete confReader;
    return 0;
  }
  catch(runtime_error &e)
  {
    cerr << "** ERROR: " << e.what() << endl;
    return 1;
  }
}
int main(int argc, char *argv[])
{
  char appName[] = "hepmc2pileup";
  stringstream message;
  FILE *inputFile = 0;
  DelphesFactory *factory = 0;
  TObjArray *stableParticleOutputArray = 0, *allParticleOutputArray = 0, *partonOutputArray = 0;
  TIterator *itParticle = 0;
  Candidate *candidate = 0;
  DelphesPileUpWriter *writer = 0;
  DelphesHepMCReader *reader = 0;
  Int_t i;
  Long64_t length, eventCounter;

  if(argc < 2)
  {
    cout << " Usage: " << appName << " output_file" << " [input_file(s)]" << endl;
    cout << " output_file - output binary pile-up file," << endl;
    cout << " input_file(s) - input file(s) in HepMC format," << endl;
    cout << " with no input_file, or when input_file is -, read standard input." << endl;
    return 1;
  }

  signal(SIGINT, SignalHandler);

  gROOT->SetBatch();

  int appargc = 1;
  char *appargv[] = {appName};
  TApplication app(appName, &appargc, appargv);

  try
  {
    writer = new DelphesPileUpWriter(argv[1]);

    factory = new DelphesFactory("ObjectFactory");
    allParticleOutputArray = factory->NewPermanentArray();
    stableParticleOutputArray = factory->NewPermanentArray();
    partonOutputArray = factory->NewPermanentArray();

    itParticle = stableParticleOutputArray->MakeIterator();

    reader = new DelphesHepMCReader;

    i = 2;
    do
    {
      if(interrupted) break;

      if(i == argc || strncmp(argv[i], "-", 2) == 0)
      {
        cout << "** Reading standard input" << endl;
        inputFile = stdin;
        length = -1;
      }
      else
      {
        cout << "** Reading " << argv[i] << endl;
        inputFile = fopen(argv[i], "r");

        if(inputFile == NULL)
        {
          message << "can't open " << argv[i];
          throw runtime_error(message.str());
        }

        fseek(inputFile, 0L, SEEK_END);
        length = ftello(inputFile);
        fseek(inputFile, 0L, SEEK_SET);

        if(length <= 0)
        {
          fclose(inputFile);
          ++i;
          continue;
        }
      }

      reader->SetInputFile(inputFile);

      ExRootProgressBar progressBar(length);

      // Loop over all objects
      eventCounter = 0;
      factory->Clear();
      reader->Clear();
      while(reader->ReadBlock(factory, allParticleOutputArray,
        stableParticleOutputArray, partonOutputArray) && !interrupted)
      {
        if(reader->EventReady())
        {
          ++eventCounter;

          itParticle->Reset();
          while((candidate = static_cast<Candidate*>(itParticle->Next())))
          {
            const TLorentzVector &position = candidate->Position;
            const TLorentzVector &momentum = candidate->Momentum;
            writer->WriteParticle(candidate->PID,
              position.X(), position.Y(), position.Z(), position.T(),
              momentum.Px(), momentum.Py(), momentum.Pz(), momentum.E());
          }

          writer->WriteEntry();

          factory->Clear();
          reader->Clear();
        }
        progressBar.Update(ftello(inputFile), eventCounter);
      }

      fseek(inputFile, 0L, SEEK_END);
      progressBar.Update(ftello(inputFile), eventCounter, kTRUE);
      progressBar.Finish();

      if(inputFile != stdin) fclose(inputFile);

      ++i;
    }
    while(i < argc);

    writer->WriteIndex();

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

    delete reader;
    delete factory;
    delete writer;

    return 0;
  }
  catch(runtime_error &e)
  {
    if(writer) delete writer;
    cerr << "** ERROR: " << e.what() << endl;
    return 1;
  }
}
void cafZFlatNtupleMaker(int ind, int partype, int syscode)
{
	gROOT->ProcessLine(".!date");
	gBenchmark->Start("metphoana_time");


	std::ostringstream ostr;
	ostr << ind;
	std::string base_dir("./");
	std::string str_ind = ostr.str();


	
	int datasets = 0;

		if (partype == 0) { //zee
			datasets = 8;
		} else if (partype == 1) { //zmumu
			datasets = 8;
		} else if (partype == 2) { //ztautau
			datasets = 2;
		}

	TStnAna* ap = new TStnAna();
	ap->GetInputModule()->SetPrintLevel(1);	// print file name as they are opened
	
	TStnCatalog* c = new TStnCatalog();
		
	TStnDataset *dsp[datasets];
	
		if (partype == 0) {
			dsp[0] = new TStnDataset("cdfpstn","ze1s6d");
			dsp[1] = new TStnDataset("cdfpstn","ze1sad");
			dsp[2] = new TStnDataset("cdfpstn","ze0scd");
			dsp[3] = new TStnDataset("cdfpstn","ze0sdd");
			dsp[4] = new TStnDataset("cdfpstn","ze0sed");
			dsp[5] = new TStnDataset("cdfpstn","ze0see");
			dsp[6] = new TStnDataset("cdfpstn","ze0seh");
			dsp[7] = new TStnDataset("cdfpstn","ze0sej");

			c->InitDataset(dsp[0]);
			c->InitDataset(dsp[1]);
			c->InitDataset(dsp[2]);
			c->InitDataset(dsp[3]);
			c->InitDataset(dsp[4]);
			c->InitDataset(dsp[5]);
			c->InitDataset(dsp[6]);
			c->InitDataset(dsp[7]);
			ap->AddDataset(dsp[0]);
			ap->AddDataset(dsp[1]);
			ap->AddDataset(dsp[2]);
			ap->AddDataset(dsp[3]);
			ap->AddDataset(dsp[4]);
			ap->AddDataset(dsp[5]);
			ap->AddDataset(dsp[6]);
			ap->AddDataset(dsp[7]);
		}

		if (partype == 1) {
			dsp[0] = new TStnDataset("cdfpstn","ze1s6m");
			dsp[1] = new TStnDataset("cdfpstn","ze1s9m");
			dsp[2] = new TStnDataset("cdfpstn","ze0sbm");
			dsp[3] = new TStnDataset("cdfpstn","ze0scm");
			dsp[4] = new TStnDataset("cdfpstn","ze0sdm");
			dsp[5] = new TStnDataset("cdfpstn","ze0sem");
			dsp[6] = new TStnDataset("cdfpstn","ze0sfm");
			dsp[7] = new TStnDataset("cdfpstn","ze0sgm");
			c->InitDataset(dsp[0]);
			c->InitDataset(dsp[1]);
			c->InitDataset(dsp[2]);
			c->InitDataset(dsp[3]);
			c->InitDataset(dsp[4]);
			c->InitDataset(dsp[5]);
			c->InitDataset(dsp[6]);
			c->InitDataset(dsp[7]);
			ap->AddDataset(dsp[0]);
			ap->AddDataset(dsp[1]);
			ap->AddDataset(dsp[2]);
			ap->AddDataset(dsp[3]);
			ap->AddDataset(dsp[4]);
			ap->AddDataset(dsp[5]);
			ap->AddDataset(dsp[6]);
			ap->AddDataset(dsp[7]);
		}

		if (partype == 2) {
			dsp[0] = new TStnDataset("cdfpstn","ze0s8t");
			dsp[1] = new TStnDataset("cdfpstn","ze0sat");
			c->InitDataset(dsp[0]);
			c->InitDataset(dsp[1]);
			ap->AddDataset(dsp[0]);
			ap->AddDataset(dsp[1]);
		}


		double sum=0;
		for (int i=0; i < datasets; i++) {
			std::cout << "Nfile="<< dsp[i]->GetNFiles() << std::endl;
			std::cout << "NEvts="<< dsp[i]->GetNEvents() << std::endl;
			sum+= dsp[i]->GetNEvents();
			TObjArray* myarr = dsp[i]->GetListOfFiles();
			TIterator *it = myarr->MakeIterator();
			TObject *obj;
			while (obj = (TObject*) it->Next()) {
				obj->Print();
			}
		}
		std::cout << "Total Evts="<< sum << std::endl;




	int split = 0;

	if (partype == 0 || partype == 1) split = 200;
	if (partype == 2) split = 10;	
	
		std::cout << "split, IND=" << ind << ", " << split <<std::endl;
		ap->SetSplit(ind, split);
		std::cout << "syscode, MomPdg, parType=" << syscode << ", " << 23 << ", " << partype <<std::endl;



	TH1::AddDirectory(kFALSE); //do not add these histos to memory 
	

  /******************************************************/
  // define all module here
  /******************************************************/
  
  //PassFailTree *passFailFile = new PassFailTree;
  //BadPointerChecker *ptChecker = new BadPointerChecker;
  
	TriggerModule* trigMod;
	trigMod = new TriggerModule;
		trigMod->SetGoodRunListFile("goodrun_v19_pho_00.txt");  // to p13
		trigMod->SetGoodRunBit(1);		//1= use good run, 0=do not use it
		trigMod->SetTriggerBit(0);		// 1= require tigger, 0=NO
		trigMod->SetMinVtx(0);
		trigMod->SetMaxVtx(1000);
		trigMod->SetUseVtxZcut(0);		//1= require z<60 0=not cut on z
	
	InitSuperPhotons* myinit = new InitSuperPhotons;

	TagTightPhotons* tagTight = new TagTightPhotons;
	TagLoosePhotons* tagLoose = new TagLoosePhotons;
	
	TagElectrons* tagTightEle = new TagElectrons;
	TagLooseElectrons* tagLooseEle = new TagLooseElectrons;

	PhoEleFilter* pef = new PhoEleFilter;

	TMyJetFilterModule *m5 = new TMyJetFilterModule();  //---------- My Vertex Filter Initialization
		m5->SetMinNjet15(1);				//Jets required to pass (Et>15GeV)
		m5->SetJTC_imode(0); 			// 0==MC; 1==data
		m5->SetJTC_systcode(syscode);			// if >0 +sigma deviation, <0 -sigma deviation, all corrections are added in quadratures up to the given correction level
		m5->SetUnclParamSwitch(0); 	// 0==photon parametrization; 1==Zee parametrization 
		m5->SetMaxDeltaPhiJMet(0.3); 	// controls dPhi in MyMetCleanUpCut
		m5->SetNpointsToGenerate(0); 	// number of pseudo-experiments per each event
		m5->SetSelectMetEvent(0); 		// 0==do nothing; 1==select event with large MET
		m5->SetRemoveDuplicate(0); 	// 0==do nothing; 1==remove "duplicate" events; -1==select "duplicate" events; "duplicate"==bad match with jets  
		m5->SetRemoveBadMet(0); 		// -1=select events with bad met; 1=remove events with bad met; 0==do nothing
		///m5->SetUseMetPDFscenario(1);  // this over writes the Npoints generates. scenarios 1=370
												//	2=1000, 3=100000,4=15873,5=100 default=100
		m5->SetDumpEvent(0); 			// 0==do nothing; 1==dump event
		m5->SetDumpEventFileName("DATA_dumpEvent.dat");
		m5->SetLargeMetEventFileName("DATA_largeMetEvent.dat");
		m5->SetDatFileName("DATA_jet.dat");
		

	//TagPMTSpikes* tagPMT = new TagPMTSpikes;
		//tagPMT->SetMode(1);	//1= pass only if no spikes found
	
	TagBeamHalo* tagBH = new TagBeamHalo();
	
	//TEmTimingModule* EmT = new TEmTimingModule();
	
	//SetEmTimes* setEmTime = new SetEmTimes;  // set EM time of super photons
		//setEmTime->SetEmTimeCorrectionFile("EmTCEMtable_p13.txt");

	TagPhoenixPhotons* tagPhoenix = new TagPhoenixPhotons;
	
	TagConvElectrons* tagConvEle = new TagConvElectrons;

	FlatStupleMaker_MC_EWK *flatS = new FlatStupleMaker_MC_EWK;	
		flatS->SetMomPDG(23);
		flatS->SetDecayType(partype);			//0=z->ee,1=z->nunu,2=z->tautau
		std::string Stuple;
			if (partype == 0) Stuple="Stuple_Zee.root"; 
			if (partype == 1) Stuple="Stuple_Zmm.root"; 
			if (partype == 2) Stuple="Stuple_Ztt.root"; 

		std::string stuplefile = base_dir + Stuple + str_ind;
		flatS->SetStupleName(stuplefile.c_str()); 
	
	//ap->AddModule(passFailFile,1);
	//ap->AddModule(ptChecker,1);
	ap->AddModule(trigMod,1);
	ap->AddModule(myinit,1);
	ap->AddModule(tagTight,1);
	ap->AddModule(tagLoose,1);
	ap->AddModule(tagTightEle,1);
	ap->AddModule(tagLooseEle,1);
	ap->AddModule(pef,1);
	ap->AddModule(m5,1);
	//ap->AddModule(tagPMT,1);
	ap->AddModule(tagBH,1);
	//ap->AddModule(EmT,1);
	//ap->AddModule(setEmTime,1);
	ap->AddModule(tagPhoenix,1);
	ap->AddModule(tagConvEle,1);
	ap->AddModule(flatS,1);

	ap->GetInputModule()->SetPrintLevel(1);	// print file name as they are opened
	ap->Run();
  	
	
	std::string filename = "FlatStuple.root"+str_ind;
	ap->SaveHist(filename.c_str(),2);
	std::cout << "/************* JOB SUMMARY ******************************/" <<std::endl;
	std::cout << "::::::::: Created ROOT file      => "<< filename << std::endl;
	//std::cout << "::::::::: Created Pass/Fail file => "<< passFailFile->GetFileName() << std::endl;
	gBenchmark->Show("metphoana_time");
	gROOT->ProcessLine(".!date");
	std::cout << "/********************************************************/" <<std::endl;
	
	//gROOT->ProcessLine(".q");
}