/* ---- FastSim ---- A Fast Simulator for general purpose LHC detector S. Ovyn ~~~~ severine.ovyn@uclouvain.be Center for Particle Physics and Phenomenology (CP3) Universite Catholique de Louvain (UCL) Louvain-la-Neuve, Belgium */ /// \file Smearing.cpp /// \brief executable for the FastSim #include "TChain.h" #include "TApplication.h" #include "Utilities/ExRootAnalysis/interface/ExRootTreeReader.h" #include "Utilities/ExRootAnalysis/interface/ExRootTreeWriter.h" #include "Utilities/ExRootAnalysis/interface/ExRootTreeBranch.h" #include "H_BeamParticle.h" #include "H_BeamLine.h" #include "H_RomanPot.h" #include "interface/DataConverter.h" #include "interface/HEPEVTConverter.h" #include "interface/LHEFConverter.h" #include "interface/STDHEPConverter.h" #include "interface/SmearUtil.h" #include "Utilities/Fastjet/include/fastjet/PseudoJet.hh" #include "Utilities/Fastjet/include/fastjet/ClusterSequence.hh" // get info on how fastjet was configured #include "Utilities/Fastjet/include/fastjet/config.h" // make sure we have what is needed #ifdef ENABLE_PLUGIN_SISCONE # include "Utilities/Fastjet/plugins/SISCone/SISConePlugin.hh" #endif #ifdef ENABLE_PLUGIN_CDFCONES # include "Utilities/Fastjet/plugins/CDFCones/CDFMidPointPlugin.hh" # include "Utilities/Fastjet/plugins/CDFCones/CDFJetCluPlugin.hh" #endif #include #include #include "interface/TreeClasses.h" using namespace std; //------------------------------------------------------------------------------ void PairingJet(TLorentzVector &JETSm, TLorentzVector JET, vector sorted_jetsS) { JETSm.SetPxPyPzE(0,0,0,0); float deltaRtest=5000; for (unsigned int i = 0; i < sorted_jetsS.size(); i++) { TLorentzVector Att; Att.SetPxPyPzE(sorted_jetsS[i].px(),sorted_jetsS[i].py(),sorted_jetsS[i].pz(),sorted_jetsS[i].E()); if(DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()) < deltaRtest) { deltaRtest = DeltaR(JET.Phi(),JET.Eta(),Att.Phi(),Att.Eta()); if(deltaRtest < 0.25) { JETSm = Att; } } } } int main(int argc, char *argv[]) { int appargc = 2; char *appName = "Smearing"; char *appargv[] = {appName, "-b"}; TApplication app(appName, &appargc, appargv); if(argc != 4 && argc != 3) { cout << " Usage: " << argv[0] << " input_file" << " output_file" << " data_card " << endl; cout << " input_list - list of files in Ntpl, StdHep of LHEF format," << endl; cout << " output_file - output file." << endl; cout << " data_card - Datacard containing resolution variables for the detector simulation (optional) "< outputfilename.length() ) { cout << "output_file should be a .root file!\n"; return -1; } TFile *outputFile = TFile::Open(outputfilename.c_str(), "RECREATE"); // Creates the file, but should be closed just after outputFile->Close(); string line; ifstream infile(inputFileList.c_str()); infile >> line; // the first line determines the type of input files DataConverter *converter=0; if(strstr(line.c_str(),".hep")) { cout<<"*************************************************************************"<UseBranch("Particle"); TIter itGen((TCollection*)branchGen); //write the output root file ExRootTreeWriter *treeWriter = new ExRootTreeWriter(outputfilename, "Analysis"); ExRootTreeBranch *branchjet = treeWriter->NewBranch("JetPTResol", RESOLJET::Class()); ExRootTreeBranch *branchelec = treeWriter->NewBranch("ElecEResol", RESOLELEC::Class()); ExRootTreeBranch *branchmuon = treeWriter->NewBranch("MuonPTResol", RESOLMUON::Class()); ExRootTreeBranch *branchtaujet = treeWriter->NewBranch("TauJetPTResol", TAUHAD::Class()); ExRootTreeBranch *branchetmis = treeWriter->NewBranch("ETmisResol",ETMIS::Class()); TRootGenParticle *particle; TRootETmis *etmisc; RESOLELEC *elementElec; RESOLMUON *elementMuon; RESOLJET *elementJet; TAUHAD *elementTaujet; ETMIS *elementEtmis; //read the datacard input file string DetDatacard(""); if(argc==4) DetDatacard =argv[3]; RESOLution *DET = new RESOLution(); DET->ReadDataCard(DetDatacard); TLorentzVector genMomentum(0,0,0,0); LorentzVector jetMomentum; vector TrackCentral; vector input_particles;//for FastJet algorithm vector inclusive_jets; vector sorted_jets; vector input_particlesS;//for FastJet algorithm vector inclusive_jetsS; vector sorted_jetsS; fastjet::JetDefinition jet_def; fastjet::JetDefinition jet_defS; fastjet::JetDefinition::Plugin * plugins; fastjet::JetDefinition::Plugin * pluginsS; // set up a CDF midpoint jet definition #ifdef ENABLE_PLUGIN_CDFCONES plugins = new fastjet::CDFJetCluPlugin(DET->C_SEEDTHRESHOLD,DET->CONERADIUS,DET->C_ADJACENCYCUT,DET->C_MAXITERATIONS,DET->C_IRATCH,DET->C_OVERLAPTHRESHOLD); jet_def = fastjet::JetDefinition(plugins); #else plugins = NULL; #endif // set up a CDF midpoint jet definition #ifdef ENABLE_PLUGIN_CDFCONES pluginsS = new fastjet::CDFJetCluPlugin(2,DET->CONERADIUS,DET->C_ADJACENCYCUT,DET->C_MAXITERATIONS,DET->C_IRATCH,DET->C_OVERLAPTHRESHOLD); jet_defS = fastjet::JetDefinition(pluginsS); #else pluginsS = NULL; #endif // Loop over all events Long64_t entry, allEntries = treeReader->GetEntries(); cout << "** Chain contains " << allEntries << " events" << endl; for(entry = 0; entry < allEntries; ++entry) { TLorentzVector PTmis(0,0,0,0); treeReader->ReadEntry(entry); treeWriter->Clear(); if((entry % 100) == 0 && entry > 0 ) cout << "** Processing element # " << entry << endl; TSimpleArray bGen; itGen.Reset(); TrackCentral.clear(); TSimpleArray NFCentralQ; input_particles.clear(); inclusive_jets.clear(); sorted_jets.clear(); input_particlesS.clear(); inclusive_jetsS.clear(); sorted_jetsS.clear(); // Loop over all particles in event while( (particle = (TRootGenParticle*) itGen.Next()) ) { genMomentum.SetPxPyPzE(particle->Px, particle->Py, particle->Pz, particle->E); int pid = abs(particle->PID); float eta = fabs(particle->Eta); if(particle->Status == 1) { input_particles.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E())); } // keeps only final particles, visible by the central detector, including the fiducial volume // the ordering of conditions have been optimised for speed : put first the STATUS condition if( (particle->Status == 1) && ( (pid == pMU && eta < DET->MAX_MU) || (pid != pMU && (pid != pNU1) && (pid != pNU2) && (pid != pNU3) && eta < DET->MAX_CALO_FWD) ) ) { switch(pid) { case pE: // all electrons with eta < DET->MAX_CALO_FWD DET->SmearElectron(genMomentum); break; // case pE case pGAMMA: // all photons with eta < DET->MAX_CALO_FWD DET->SmearElectron(genMomentum); break; // case pGAMMA case pMU: // all muons with eta < DET->MAX_MU DET->SmearMu(genMomentum); break; // case pMU case pLAMBDA: // all lambdas with eta < DET->MAX_CALO_FWD case pK0S: // all K0s with eta < DET->MAX_CALO_FWD DET->SmearHadron(genMomentum, 0.7); break; // case hadron default: // all other final particles with eta < DET->MAX_CALO_FWD DET->SmearHadron(genMomentum, 1.0); break; } // switch (pid) // all final particles but muons and neutrinos // for calorimetric towers and mission PT if(genMomentum.E()!=0) PTmis = PTmis + genMomentum;//ptmis if(pid != pMU && genMomentum.Pt() > DET->PT_TRACKS_MIN) { input_particlesS.push_back(fastjet::PseudoJet(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E())); } // all final charged particles if( ((rand()%100) < DET->TRACKING_EFF) && (genMomentum.E()!=0) && (fabs(particle->Eta) < DET->MAX_TRACKER) && (genMomentum.Pt() > DET->PT_TRACKS_MIN ) && // pt too small to be taken into account (pid != pGAMMA) && (pid != pPI0) && (pid != pK0L) && (pid != pN) && (pid != pSIGMA0) && (pid != pDELTA0) && (pid != pK0S) // not charged particles : invisible by tracker ) TrackCentral.push_back(genMomentum); } // switch } // while //***************************** double ptmin=1; if(input_particles.size()!=0) { fastjet::ClusterSequence clust_seq(input_particles, jet_def); inclusive_jets = clust_seq.inclusive_jets(ptmin); sorted_jets = sorted_by_pt(inclusive_jets); } if(input_particlesS.size()!=0) { fastjet::ClusterSequence clust_seqS(input_particlesS, jet_defS); inclusive_jetsS = clust_seqS.inclusive_jets(ptmin); sorted_jetsS = sorted_by_pt(inclusive_jetsS); } TLorentzVector JETSm(0,0,0,0); for (unsigned int i = 0; i < sorted_jets.size(); i++) { TLorentzVector JET(0,0,0,0); JET.SetPxPyPzE(sorted_jets[i].px(),sorted_jets[i].py(),sorted_jets[i].pz(),sorted_jets[i].E()); PairingJet(JETSm,JET,sorted_jetsS); if(JETSm.Pt()>1) { elementJet= (RESOLJET*) branchjet->NewEntry(); elementJet->NonSmearePT = JET.Pt(); elementJet->SmearePT = (JETSm.Pt()/JET.Pt()); /*cout<<"valeur obtenue "<Fill(); } // Loop over all events treeWriter->Write(); cout << "** Exiting..." << endl; delete treeWriter; delete treeReader; delete DET; if(converter) delete converter; }