/* ---- 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; vector towers; 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(0,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(1,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 PTmisS(0,0,0,0); 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(); towers.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) ) ) { PTmis = PTmis + genMomentum;//ptmis 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) if(pid != pMU) { // PTmisS = PTmisS + genMomentum; towers.push_back(PhysicsTower(LorentzVector(genMomentum.Px(),genMomentum.Py(),genMomentum.Pz(), genMomentum.E()))); if(genMomentum.Et()>0.5)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 TLorentzVector TowerTLV(0.,0.,0.,0.); for(unsigned int i=0; i < towers.size(); i++) { TowerTLV.SetPxPyPzE(towers[i].fourVector.px,towers[i].fourVector.py,towers[i].fourVector.pz,towers[i].fourVector.E); if(TowerTLV.Et()>0.5)PTmisS = PTmisS + TowerTLV; } elementEtmis= (ETMIS*) branchetmis->NewEntry(); elementEtmis->Et = (PTmis).Et(); elementEtmis->EtSmeare = (PTmisS).Et()-(PTmis).Et(); //***************************** 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.Et(); elementJet->SmearePT = JETSm.Et()/JET.Et(); } } // for itJet : loop on all jets treeWriter->Fill(); } // Loop over all events treeWriter->Write(); cout << "** Exiting..." << endl; delete treeWriter; delete treeReader; delete DET; if(converter) delete converter; }