int main(int argc, char* argv[]) { if (argc < 2) { std::cout << "Insufficient arguments" << std::endl; std::cout << "Usage : simulate <params file>" << std::endl; exit(1); } // arguments std::string paramfile = std::string(argv[1]); Experiment* e; // read parameters from file and create experiment object e = new Experiment(paramfile); std::cout << "Simulation parameters" << std::endl; std::cout << "From file : " << paramfile << std::endl; std::cout << *e << std::endl; // setup tree to write out TFile f("outfile.root", "RECREATE"); TTree *tree = new TTree("T", "Experiments from the Stopped Particle MC"); tree->Branch("Experiment", "Experiment", &e); // fills file std::ofstream fillsfile; fillsfile.open("fills.txt"); // setup simulation Simulator sim; // set parameters sim.setParameters(e); // set observed events sim.setupObservedEvents(); // set up luminosity data sim.setupLumi(false, true, true, e->lumiFile); // set up lifetime mask sim.setupLifetimeMask(); // sim.getLhcFills().print(std::cout); // simulate everything at once unsigned firstFill = e->fills.at(0); unsigned lastFill = e->fills.at(e->fills.size()-1); // expected background sim.calculateExpectedBG(firstFill, lastFill); // get observed events sim.calculateObservedEvents(firstFill, lastFill); // run MC sim.simulateSignal(firstFill, lastFill); // calculate limit sim.calculateLimit(); std::cout << std::endl; // write results summary std::ofstream summaryfile; summaryfile.open("summary.txt", std::ios::app); e->summary(summaryfile); summaryfile.close(); std::cout << *e << std::endl; tree->Fill(); f.cd(); tree->Write(); fillsfile.close(); return 0; }
// provide either a root file or text file with root file paths int createTrainingTree(TString infile, TString outfile) { //static // initialize variables for filling struct Float_t fEnergyGeV, fPrimaryZenithDeg, fPrimaryAzimuthDeg, fLength, fWidth, fSize, fDist, fTimeGradient, fLoss; triggeredSimEvent trigSimEvent = triggeredSimEvent(); // for writing // for branch, if type is other than float, need to specify types with varname/F, for example const char* leafList = "fEnergyGeV:fLength:fWidth:fSize"; //:fPrimaryZenithDeg:fPrimaryAzimuthDeg:fTimeGradient:fLoss:fDist // quality cuts int NTubesMin = 5; // default in VEGAS float distanceUpper = 1.38; // 1.43 [degrees] // create output file for writing new branch TFile hfile(outfile,"RECREATE","simplified ROOT file with single branch structure for training on simulated events"); // Create a ROOT Tree TTree *trainTree = new TTree("Training","ROOT tree with single training branch"); //trainTree->Branch("triggeredSimEvent", &trigSimEvent, leafList); trainTree->Branch("fEnergyGeV", &fEnergyGeV, "fEnergyGeV"); trainTree->Branch("fLength", &fLength, "fLength"); trainTree->Branch("fWidth", &fWidth, "fWidth"); trainTree->Branch("fSize", &fSize, "fSize"); trainTree->Branch("fDist", &fDist, "fDist"); trainTree->Branch("fLoss", &fLoss, "fLoss"); trainTree->Branch("fTimeGradient", &fTimeGradient, "fTimeGradient"); trainTree->Branch("fPrimaryAzimuthDeg", &fPrimaryAzimuthDeg, "fPrimaryAzimuthDeg"); // should make 4 branches for each telescope //noise parameter (same as when producing tables) //// set up input to connect simulated events to shower events ///// // open input file for reading only VARootIO* pfRootIO = new VARootIO(string(infile.Data()), true); pfRootIO->loadTheRootFile(); if(!pfRootIO->IsOpen()) { cerr << "Couldn't open " << infile << endl; return 1; } // parameterised event data holds shower params for each telescope VAParameterisedEventData* paramData = nullptr; TTree* paramEventsTree = pfRootIO->loadTheParameterisedEventTree(); paramEventsTree->SetBranchAddress("P", ¶mData); //vector<VAParameterisedEventTelData*> vfTels //VAHillasData* pfHillasData; // get the simulation tree for true energy, etc. TTree* simTree = pfRootIO->loadTheSimulationEventTree(); VASimulationData* simData = nullptr; simTree->SetBranchAddress("Sim", &simData); // check for trees and branches if(!paramEventsTree) { cerr << "Couldn't get a pointer to the shower tree" << endl; return 1; } if(!simTree) { cerr << "Couldn't get a pointer to the simulation tree" << endl; return 1; } if(!simTree->GetBranch(gSimulatedEventsBranchName.c_str())) { cerr << "Couldn't find a branch called " << gSimulatedEventsBranchName << endl; return false; } cout << "simulated events: " << simTree->GetEntries() << endl; cout << "parameterised events: " << paramEventsTree->GetEntries() << endl; cout << "Building simulation index" << endl; paramEventsTree->BuildIndex("fRunNum", "fArrayEventNum"); //paramEventsTree->BuildIndex("P.fRunNum", "P.fArrayEventNum"); //simTree->BuildIndex("fRunNum", "fArrayEventNum"); cout << "done" << endl; // now loop over all entries unsigned long long int simEntries = simTree->GetEntries(); for(unsigned long long int i = 0; i < simEntries; i++) { if(simTree->GetEntry(i) <= 0) { cerr << "could not get entry " << i <<endl; return 1; } if(i%1000000 == 0) { cout << "event\t" << i <<endl; } // check simData is not null and generated an array event if(simData && simData->fTriggeredArray) { // Long64_t stereoEntryNumber = paramEventsTree-> GetEntryWithIndex(simData->fRunNum, simData->fArrayEventNum); // ensure shower event is valid if(stereoEntryNumber >= 0 && paramData) { //VAParameterisedEventTelData* = paramData-> VAHillasData* hillasData = paramData->vfTels.at(0)->pfHillasData; // check quality (cuts) if(hillasData->fGoodImage && hillasData->fPixelsInImage >= NTubesMin && hillasData->fDist <= distanceUpper){ // && NTubes >= NTubesMin, DistanceUpper // now set the appropriate values in the struct before filling tree fLength = hillasData->fLength; fWidth = hillasData->fWidth; fSize = hillasData->fSize; fTimeGradient = hillasData->fTimeGradient; fLoss = hillasData->fLoss; fDist = hillasData->fDist; // energy needs to come from simulated event fEnergyGeV = simData->fEnergyGeV; // direction fPrimaryAzimuthDeg = simData->fPrimaryAzimuthDeg; fPrimaryZenithDeg = simData->fPrimaryZenithDeg; } // if telescope image is good // write the event to the tree in new branch trainTree->Fill(); /* uint32_t fRunNum; //The number of the run - important when many runs get //combined since the fEventIndex and fArrayEventNum //will no longer be unique uint32_t fArrayEventNum;//Event number - unique for single run only. double fOriginRA; //Ra and Dec of center of camera at event time. double fOriginDec; //In radians double fOriginElevationRad; //Elevation of the camera center at event time double fOriginAzimuthRad; //Azimuth of the camera center at event time uint16_t fTelId; //Telescope ID (node # T1=0)this telescope event double fXO; //X in cameraplane(deg) of assumed source position double fYO; //Y in cameraplane(deg) of assumed source position // Used to recenter camera plane to // Field-of-view(FOV) where XO,YO is now 0,0 in fov double fXC; //X in FOV(deg) of centroid location double fYC; //Y in FOV(deg) of centroid location double fCosPsi; //Direction cosigns of major axis double fSinPsi; double fAsymmetry; //Asymmetry along major axis double fMinorAsymmetry;//Asymmetry along minor axis VAEventType fTriggerCode; bool fGoodImage; //Flag that this image can be analyized(size>0) bool fIsL2Triggered;//Flag that this telescope had an L2 trigger */ } // successfully got param data entry corresponding to triggered sim event } // successfully got sim data that triggered array } // for loop over entries in simulation tree // write all (branches) to this file hfile.Write(); cout << "tree written to file! " << outfile <<endl; hfile.Close(); //pfRootIO->Close(); //delete VASimulationData(); return 0; // great job! } // createTrainingTree
void MCReader(int eventNo, TString option) { int tmpcode; cout << "start: " << flush; tmpcode = system("date"); DSReader r("test3.root"); DS::Root *ds = r.GetEvent(eventNo-3); cout << "ds loaded: " << flush; tmpcode = system("date"); DS::MC *mc = ds->GetMC(); int size_mc = mc->GetMCTrackCount(); cout << "total tracks: " << size_mc << endl; vector<float> xx, yy, zz, tt, ll, wlwl; for (int i=0; i < size_mc; i++) { DS::MCTrack *track = mc->GetMCTrack(i); if (i % 100000 == 0) cout << "processing track " << i << endl; if (! (track->GetParticleName() == "opticalphoton") ) continue; int size_step = track->GetMCTrackStepCount(); for (int j=0; j < size_step; j++) { DS::MCTrackStep *step = track->GetMCTrackStep(j); // Copy over initial step if ( option == "Cerenkov" || option == "Transportation" || option == "Attenuation" || option == "G4FastSimulationManagerProcess" ) { if (! (step->GetProcess() == option) ) continue; } else { cout << "Sorry, option not recognized" << endl; } TVector3 vec = step->GetEndpoint(); // if (vec.Mag()>10000) continue; xx.push_back(vec.X()); yy.push_back(vec.Y()); zz.push_back(vec.Z()); tt.push_back(step->GetGlobalTime()); ll.push_back(step->GetLength()); wlwl.push_back(1240e-6/step->GetKE()); // nm TString name = step->GetProcess(); if (! ( name == "Cerenkov" || name == "Transportation" || name == "Attenuation" || name == "G4FastSimulationManagerProcess") ) { cout << step->GetProcess() << endl; } // if (! (step->GetProcess() == "Cerenkov") ) { // } } } cout << "end processing: " << flush; tmpcode = system("date"); TString rootFileName = TString::Format("%i-%s.root", eventNo, option.Data()); float x, y, z, t, l, wl; TTree *tree = new TTree("MCTrack", "MC Track Info"); tree->Branch("x", &x); tree->Branch("y", &y); tree->Branch("z", &z); tree->Branch("t", &t); tree->Branch("l", &l); tree->Branch("wl", &wl); TFile f(rootFileName.Data(), "recreate"); int size = xx.size(); for (int i=0; i<size; i++) { x = xx[i]; y = yy[i]; z = zz[i]; t = tt[i]; wl = wlwl[i]; l = ll[i]; tree->Fill(); } tree->Write(); // TGraph2D g(x.size(), &x[0], &y[0], &z[0]); // g.Write(); f.Close(); cout << "ROOT file saved to " << rootFileName << endl; // TrackNav nav(ds, true); // TrackCursor c = nav.Cursor(true); // cout << "track loaded: " << flush; tmpcode = system("date"); TString jsonFileName = TString::Format("%i-%s.json", eventNo, option.Data()); ofstream out(jsonFileName.Data()); out << fixed << setprecision(0); out << "{" << endl; print_vector(out, xx, "x"); print_vector(out, yy, "y"); print_vector(out, zz, "z"); out << fixed << setprecision(1); print_vector(out, tt, "t"); out << '"' << "type" << '"' << ":" << '"' << "MCTrack" << '"' << endl; out << "}" << endl; out.close(); cout << "JSON file saved to " << jsonFileName << endl; }
int main( int argc, char* argv[] ) { std::string runName = "precalib_BGO_pedestal_noSource"; if( argc>1 ) { std::string runName_str(argv[1]); runName = runName_str; } std::string tag = "V00"; if( argc>2 ) { std::string tag_str(argv[2]); tag = tag_str; } TString runName_tstr(runName); bool isOnlyRunNumber = !(runName_tstr.BeginsWith("BTF_")); TChain* tree = new TChain("recoTree"); if( isOnlyRunNumber ) { std::cout << "-> We believe you are passing the program only the run number!" << std::endl; std::cout << "-> So for instance you are passing '246' for run 'BTF_246_20140501-212512_beam'" << std::endl; std::cout << "(if this is not the case this means TROUBLE)" << std::endl; std::cout << "-> Will look for runs matching run number: " << runName << std::endl; tree->Add(Form("analysisTrees_%s/Reco_BTF_%s_*beam.root/recoTree", tag.c_str(), runName.c_str()) ); if( tree->GetEntries()==0 ) { std::cout << "WARNING! Didn't find any events matching run: " << runName << std::endl; std::cout << "Exiting" << std::endl; exit(1913); } } else { std::string fileName = "analysisTrees_"+tag+"/Reco_" + runName + ".root"; TFile* file = TFile::Open(fileName.c_str()); if( file==0 ) { std::cout << "ERROR! Din't find file " << fileName << std::endl; std::cout << "Exiting." << std::endl; exit(11); } tree = (TChain*)file->Get("recoTree"); } UInt_t evtNumber; tree->SetBranchAddress( "evtNumber", &evtNumber ); UInt_t adcData[40]; tree->SetBranchAddress( "adcData", adcData ); UInt_t adcBoard[40]; tree->SetBranchAddress( "adcBoard", adcBoard ); UInt_t adcChannel[40]; tree->SetBranchAddress( "adcChannel", adcChannel ); unsigned int runNumber; int nHodoFibersX; int nHodoFibersY; int nHodoClustersX; int nHodoClustersY; float cef3_corr[CEF3_CHANNELS]; float bgo_corr[BGO_CHANNELS]; float scintFront; float pos_hodoClustX[HODOX_CHANNELS]; float pos_hodoClustY[HODOY_CHANNELS]; int nFibres_hodoClustX[HODOX_CHANNELS]; int nFibres_hodoClustY[HODOY_CHANNELS]; float xBeam, yBeam; bool isSingleEle_scintFront; bool cef3_ok; bool cef3_corr_ok; bool bgo_ok; bool bgo_corr_ok; tree->SetBranchAddress( "runNumber", &runNumber ); tree->SetBranchAddress( "scintFront", &scintFront ); tree->SetBranchAddress( "cef3_corr", cef3_corr ); tree->SetBranchAddress( "bgo_corr", bgo_corr ); tree->SetBranchAddress( "nHodoFibersX", &nHodoFibersX ); tree->SetBranchAddress( "nHodoFibersY", &nHodoFibersY ); tree->SetBranchAddress( "nHodoClustersX", &nHodoClustersX ); tree->SetBranchAddress( "pos_hodoClustX", pos_hodoClustX ); tree->SetBranchAddress( "nFibres_hodoClustX", nFibres_hodoClustX ); tree->SetBranchAddress( "nHodoClustersY", &nHodoClustersY ); tree->SetBranchAddress( "pos_hodoClustY", pos_hodoClustY ); tree->SetBranchAddress( "nFibres_hodoClustY", nFibres_hodoClustY ); tree->SetBranchAddress( "scintFront", &scintFront ); tree->SetBranchAddress( "isSingleEle_scintFront", &isSingleEle_scintFront ); tree->SetBranchAddress( "xBeam", &xBeam ); tree->SetBranchAddress( "yBeam", &yBeam ); tree->SetBranchAddress( "cef3_ok", &cef3_ok ); tree->SetBranchAddress( "cef3_corr_ok", &cef3_corr_ok ); tree->SetBranchAddress( "bgo_ok", &bgo_ok ); tree->SetBranchAddress( "bgo_corr_ok", &bgo_corr_ok ); int nentries = tree->GetEntries(); if( isOnlyRunNumber ) { // modify runname in such a way that it's useful for getBeamPosition and outfile: runName = "BTF_" + runName + "_beam"; } std::string outputdir = "SingleElectronSelectionTrees_"+tag; system( Form("mkdir -p %s", outputdir.c_str()) ); std::string outfileName = outputdir + "/SingleEleSelAn_" + runName + ".root"; TFile* outfile = TFile::Open( outfileName.c_str(), "RECREATE" ); TTree* outTree = new TTree("singleEleSelTree","singleEleSelTree"); outTree->Branch( "run", &runNumber, "run/i" ); outTree->Branch( "scintFront", &scintFront, "scintFront/F" ); outTree->Branch( "isSingleEle_scintFront", &isSingleEle_scintFront, "isSingleEle_scintFront/O" ); outTree->Branch( "nHodoClustersX", &nHodoClustersX, "nHodoClustersX/I" ); outTree->Branch( "nHodoClustersY", &nHodoClustersY, "nHodoClustersY/I" ); outTree->Branch( "cef3_corr", cef3_corr, "cef3_corr[4]/F" ); outTree->Branch( "bgo_corr", bgo_corr, "bgo_corr[8]/F" ); outTree->Branch( "bgo_corr_ok", &bgo_corr_ok, "bgo_corr_ok/O"); outTree->Branch( "xBeam", &xBeam, "xBeam/F" ); outTree->Branch( "yBeam", &yBeam, "yBeam/F" ); TH1D* h1_cef3_corr_tot = new TH1D("cef3_corr_tot", "", 1500, 0., 15000); for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) { tree->GetEntry(iEntry); if( iEntry % 10000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl; if( cef3_ok ) { std::vector<float> v_cef3_corr; for(unsigned i=0; i<CEF3_CHANNELS; ++i) v_cef3_corr.push_back(cef3_corr[i]); float eTot_corr = sumVector(v_cef3_corr); if( cef3_corr_ok ) { h1_cef3_corr_tot->Fill(eTot_corr); } outTree->Fill(); } } FitResults fr_0 = fitSingleHisto( h1_cef3_corr_tot, 0.,0., 1000., 11500. ); outfile->cd(); h1_cef3_corr_tot->Write(); outTree->Write(); outfile->Close(); std::cout << "-> Histograms saved in: " << outfile->GetName() << std::endl; return 0; }
void makeMuDstQA(TString InputFileList, Int_t nFiles, Int_t nEvents, TString OutputDir ) { // Load libraries for CINT mode #ifdef __CINT__ gROOT -> Macro("loadMuDst.C"); #endif // List of member links in the chain StChain* chain = new StChain ; StMuDstMaker* muDstMaker = new StMuDstMaker(0,0,"",InputFileList,"MuDst",nFiles) ; // ---------------- modify here according to your QA purpose -------------------------- // Turn off everything but Primary tracks in order to speed up the analysis and eliminate IO muDstMaker -> SetStatus("*",0) ; // Turn off all branches muDstMaker -> SetStatus("MuEvent",1) ; // Turn on the Event data (esp. Event number) muDstMaker -> SetStatus("PrimaryVertices",1) ; // Turn on the primary track data muDstMaker -> SetStatus("PrimaryTracks",1) ; // Turn on the primary track data muDstMaker -> SetStatus("GlobalTracks",1) ; // Turn on the global track data muDstMaker -> SetStatus("CovGlobTrack",1); // to fix the refmult in Run14!!! muDstMaker -> SetStatus("BTofHeader",1) ; // Turn on the btof data muDstMaker -> SetDebug(0) ; // Turn off Debug information if ( nEvents == 0 ) nEvents = 10000000 ; // Take all events in nFiles if nEvents = 0 // ---------------- modify here according to your QA purpose -------------------------- //book histograms or trees if you need TString oFile(muDstMaker->GetFile()); TString oChopFile; int fileBeginIndex = oFile.Index("st_",0); oFile.Remove(0,fileBeginIndex); short indx1 = oFile.First('.'); short indx2 = oFile.Last('.'); if (indx1!=indx2) oFile.Remove(indx1+1,(indx2-indx1)); oChopFile=oFile; oFile.Insert(indx1+1,"moretags."); oFile.Prepend(OutputDir); oChopFile.Insert(indx1+1,"chopper."); oChopFile.ReplaceAll("root","txt"); oChopFile.Prepend(OutputDir); ofstream chop_output(oChopFile); TFile *tags_output = new TFile( oFile, "recreate" ) ; tags_output->cd(); //TH1F *hPhi = new TH1F("hPhi","Phi of proton",200,-TMath::Pi(),TMath::Pi()); //TH2F *hPhiFirstZ = new TH2F("hPhiFirstZ","Phi vs. FirstZ",200,-150,150,200,-TMath::Pi(),TMath::Pi()); //Prepare the output tree Int_t mRunId, mEvtId; Int_t mnRefMult, mngRefMult, mnTofMatch; Float_t mVX, mVY, mVZ; Float_t mVpdVz; Float_t mPVRank; TTree *mMoreTagsTree = new TTree("MoreTags","MoreTags"); mMoreTagsTree->Branch("RunId",&mRunId,"RunId/I"); mMoreTagsTree->Branch("EvtId",&mEvtId,"EvtId/I"); mMoreTagsTree->Branch("nRefMult",&mnRefMult,"nRefMult/I"); mMoreTagsTree->Branch("ngRefMult",&mngRefMult,"ngRefMult/I"); mMoreTagsTree->Branch("nTofMatch",&mnTofMatch,"nTofMatch/I"); mMoreTagsTree->Branch("VX",&mVX,"VX/F"); mMoreTagsTree->Branch("VY",&mVY,"VY/F"); mMoreTagsTree->Branch("VZ",&mVZ,"VZ/F"); mMoreTagsTree->Branch("VpdVz",&mVpdVz,"VpdVz/F"); mMoreTagsTree->Branch("PVRank",&mPVRank,"PVRank/F"); mMoreTagsTree->SetAutoSave(10000000); // ---------------- end of histogram and tree booking -------------------------------- // Loop over the links in the chain Int_t iInit = chain -> Init() ; if (iInit) chain->FatalErr(iInit,"on init"); // chain -> EventLoop(1,nEvents) ; //will output lots of useless debugging info. Int_t istat = 0, i = 1; while (i <= nEvents && istat != 2) { if(i%10==0)cout << endl << "== Event " << i << " start ==" << endl; chain->Clear(); istat = chain->Make(i); if (istat == 2) cout << "Last event processed. Status = " << istat << endl; if (istat == 3) cout << "Error event processed. Status = " << istat << endl; i++; if(istat != kStOK)continue; //skip those suspectible events // ---------------- modify here according to your QA purpose -------------------------- //let's do the QA here... //start with event cutting... //cout<<"In event #. "<<i-1<<" Maker status "<<istat<<endl; StMuDst* mMuDst = muDstMaker->muDst(); if(!mMuDst) { LOG_WARN << " No MuDst " << endm; continue; } StMuEvent* mMuEvent = mMuDst->event(); if(!mMuEvent) { LOG_WARN << " No MuEvent " << endm; continue; } //vzVpd StBTofHeader const* mBTofHeader = mMuDst->btofHeader(); Float_t vzVpd=-999; if (mBTofHeader) vzVpd = mBTofHeader->vpdVz(); /* //Run14 vertex selection ////////////////////////////////////// // select the right vertex using VPD ///////////////////////////////////// for(unsigned int i=0;i<mMuDst->numberOfPrimaryVertices();i++) { StMuPrimaryVertex *vtx = mMuDst->primaryVertex(i); if(!vtx) continue; Float_t vz = vtx->position().z(); if(fabs(vzVpd)<100 && fabs(vzVpd-vz)<3.) { mMuDst->setVertexIndex(i); break; } } ///////////////////////////////////// */ /* //Run16 vertex selection //////////////////////////////////////////////////////////////// if (fabs(vzVpd) < 200) { for (unsigned int iVtx = 0; iVtx < mMuDst->numberOfPrimaryVertices(); ++iVtx) { StMuPrimaryVertex* vtx = mMuDst->primaryVertex(iVtx); if (!vtx) continue; if (fabs(vzVpd - vtx->position().z()) < 3.) { mMuDst->setVertexIndex(iVtx); break; } } } //////////////////////////////////////////////////////////////// */ /* //Run15 pAu & Run16 dAu vertex selection int index = 0; const double mTpcVpdVzDiffCut = 6; if (mBTofHeader && fabs(vzVpd) < 200) { for (unsigned int iVtx = 0; iVtx < mMuDst->numberOfPrimaryVertices(); ++iVtx) { StMuPrimaryVertex* vtx = mMuDst->primaryVertex(iVtx); if (!vtx) continue; if (fabs(vzVpd - vtx->position().z()) < mTpcVpdVzDiffCut) { index = iVtx; break; } } } if(index>=0) mMuDst->setVertexIndex(index); */ mRunId = mMuEvent->runNumber(); mEvtId = mMuEvent->eventNumber(); mnRefMult = mMuEvent->refMult(); Int_t nTofMatPrTrack = 0; TObjArray* prtracks = muDstMaker->muDst()->primaryTracks() ; // Create a TObject array containing the global tracks TObjArrayIter GetPrTracks(prtracks) ; // Create an iterator to step through the tracks StMuTrack* prtrack ; // Pointer to a track while ( ( prtrack = (StMuTrack*)GetPrTracks.Next() ) ) // Main loop for Iterating over tracks { if(prtrack->btofPidTraits().matchFlag()) nTofMatPrTrack ++; } mnTofMatch = nTofMatPrTrack; mVX = mMuEvent->primaryVertexPosition().x(); mVY = mMuEvent->primaryVertexPosition().y(); mVZ = mMuEvent->primaryVertexPosition().z(); mVpdVz = vzVpd; if(mMuDst->primaryVertex())mPVRank = mMuDst->primaryVertex()->ranking(); else mPVRank = -1e9; Int_t nGlTrack = 0; TObjArray* gltracks = muDstMaker->muDst()->globalTracks() ; // Create a TObject array containing the global tracks TObjArrayIter GetGlTracks(gltracks) ; // Create an iterator to step through the tracks StMuTrack* gltrack ; // Pointer to a track while ( ( gltrack = (StMuTrack*)GetGlTracks.Next() ) ) // Main loop for Iterating over tracks { if(fabs(gltrack->eta())>=0.5)continue; if(gltrack->nHitsFit()<10)continue; if(gltrack->dca().mag()>=3.0)continue; nGlTrack++ ; } mngRefMult = nGlTrack; mMoreTagsTree->Fill(); //Event info (for debug) //cout<<"Run#: "<<mMuEvent->runNumber()<<endl; //cout<<"Evt#: "<<mMuEvent->eventNumber()<<endl; //cout<<muDstMaker->muDst()->currentVertexIndex()<<endl; //cout<<"refmult: "<<mMuEvent->refMult()<<endl; //Event cuts (NO EVENT CUTS TILL HERE!) //trigger if ( ! mMuEvent->triggerIdCollection().nominal().isTrigger(410008) && ! mMuEvent->triggerIdCollection().nominal().isTrigger(410005) ) continue; //Vz if ( fabs(mMuEvent->primaryVertexPosition().z()) > 30.0 ) continue ; //Vr //if ( mMuEvent->primaryVertexPosition().perp() > 100.0 ) continue ; //VF failed (for some old dataset) //if ( fabs(mMuEvent->primaryVertexPosition().x()) < 1e-5 && fabs(mMuEvent->primaryVertexPosition().y()) < 1e-5 && fabs(mMuEvent->primaryVertexPosition().z()) < 1e-5 ) continue; chop_output<<mRunId<<'\t'<<mEvtId<<endl; /* //fill Event QA histograms TObjArray* tracks = muDstMaker->muDst()->primaryTracks() ; TObjArrayIter GetTracks(tracks) ; StMuTrack* gtrack ; while ( ( gtrack = (StMuTrack*)GetTracks.Next() ) ) { //const StMuTrack * gtrack = track->globalTrack(); if(gtrack->nHits()<=15)continue; if(gtrack->flag()<=0)continue; if(abs(gtrack->charge())!=1) continue; if(gtrack->pt()>0.5) continue; if(fabs(gtrack->nSigmaProton())>2)continue; hPhi->Fill(gtrack->phi()); hPhiFirstZ->Fill(gtrack->firstPoint().z(),gtrack->phi()); } //end of the filling */ } if (nEvents > 1) chain -> Finish() ; if(tags_output!=NULL) tags_output -> Write() ; if(tags_output!=NULL) tags_output -> Close() ; //flush(tags_output); delete tags_output; chop_output.close(); // Cleanup delete chain ; }
//for hands on exercise void reconstruction(){ // Open the raw data file unsigned int events(-9999); unsigned int run(-9999); unsigned int tdcPhase(9999); std::vector<int> *hits_S0 = 0; std::vector<int> *hits_S1 = 0; std::vector<int> *hits_S2 = 0; std::vector<int> *hits_S3 = 0; TFile *dutFile = TFile::Open("MyInputFile.root"); TTree *duttree = (TTree *) dutFile->Get("tree"); duttree->SetBranchAddress("event", &events); duttree->SetBranchAddress("run", &run); duttree->SetBranchAddress("dut0_row", &hits_S0); duttree->SetBranchAddress("dut1_row", &hits_S1); duttree->SetBranchAddress("dut2_row", &hits_S2); duttree->SetBranchAddress("dut3_row", &hits_S3); duttree->SetBranchAddress("tdcPhase", &tdcPhase); // Book all histograms: TH1F *hitmap_S0 = new TH1F("hitmap_S0","hitmap_S0", 256, 0. , 256.); TH1F *hitmap_S1 = new TH1F("hitmap_S1","hitmap_S1", 256, 0. , 256.); TH1F *hitmap_S2 = new TH1F("hitmap_S2","hitmap_S2", 256, 0. , 256.); TH1F *hitmap_S3 = new TH1F("hitmap_S3","hitmap_S3", 256, 0. , 256.); TH1F *hitmap_S0_masked = new TH1F("hitmap_S0_masked","hitmap_S0_masked", 256, 0. , 256.); TH1F *hitmap_S1_masked = new TH1F("hitmap_S1_masked","hitmap_S1_masked", 256, 0. , 256.); TH1F *hitmap_S2_masked = new TH1F("hitmap_S2_masked","hitmap_S2_masked", 256, 0. , 256.); TH1F *hitmap_S3_masked = new TH1F("hitmap_S3_masked","hitmap_S3_masked", 256, 0. , 256.); TH1F *h_clusters_S2 = new TH1F("clusters_S2","clusters_S2", 256, 0. , 256.); TH1F *h_clusters_S3 = new TH1F("clusters_S3","clusters_S3", 256, 0. , 256.); // Prepare output Reco ROOT Tree: std::vector<int> clusterwidth_S0; std::vector<double> clusterposition_S0; std::vector<int> clusterwidth_S1; std::vector<double> clusterposition_S1; std::vector<int> clusterwidth_S2; std::vector<double> clusterposition_S2; std::vector<int> clusterwidth_S3; std::vector<double> clusterposition_S3; std::vector<double> stubs_M1; std::vector<double> stubs_M2; std::vector<int> hits_valid_S0; std::vector<int> hits_valid_S1; std::vector<int> hits_valid_S2; std::vector<int> hits_valid_S3; TFile *recofile = new TFile("MyOutFile.root","RECREATE"); TTree *recotree = new TTree("recotree","reconstructed"); recotree->Branch("events" , &events ); recotree->Branch("run" , &run ); recotree->Branch("row_S0", &hits_S0); recotree->Branch("row_S1", &hits_S1); recotree->Branch("row_S2", &hits_S2); recotree->Branch("row_S3", &hits_S3); recotree->Branch("row_S0_masked", &hits_valid_S0); recotree->Branch("row_S1_masked", &hits_valid_S1); recotree->Branch("row_S2_masked", &hits_valid_S2); recotree->Branch("row_S3_masked", &hits_valid_S3); recotree->Branch("clusters_S0", &clusterposition_S0); recotree->Branch("clusters_S1", &clusterposition_S1); recotree->Branch("clusters_S2", &clusterposition_S2); recotree->Branch("clusters_S3", &clusterposition_S3); recotree->Branch("clusterwidth_S0", &clusterwidth_S0); recotree->Branch("clusterwidth_S1", &clusterwidth_S1); recotree->Branch("clusterwidth_S2", &clusterwidth_S2); recotree->Branch("clusterwidth_S3", &clusterwidth_S3); recotree->Branch("stubs_module_1",&stubs_M1); recotree->Branch("stubs_module_2",&stubs_M2); recotree->Branch("tdc", &tdcPhase); // The main events loop: for (int i = 0; i < duttree->GetEntries(); i++) { // Some printout to see where we are: if(i%1000 == 0) std::cout << "Processing event " << i << std::endl; duttree->GetEntry(i); // Masking noisy strips // If a strip is "noisy" can be read from the hit map histograms // and results in a hardcoded cut on strip numbers. for(size_t hit = 0 ; hit < hits_S0->size(); hit++) hitmap_S0->Fill(hits_S0->at(hit)); // ... // Hint: S0 and S1 have 254 strips each, S2, S3 have 256 strips each. // Store all strips which are fine in vectors for further analyses // hits_valid_S0; // Clustering // On each sensor, cluster all strips which belong together. // The most simple solution is to just add all up which are next to each other // storing the first and last strip. std::vector<int> cluster_firstStrip_S0; std::vector<int> cluster_lastStrip_S0; std::vector<int> cluster_firstStrip_S1; std::vector<int> cluster_lastStrip_S1; std::vector<int> cluster_firstStrip_S2; std::vector<int> cluster_lastStrip_S2; std::vector<int> cluster_firstStripS_S3; std::vector<int> cluster_lastStrip_S3; // Run over all strips on every module to connect them: for(size_t k = 0; k < hits_valid_S0.size(); ++k){ // ... } // Some extra cross check that we didn't mess things up: if(cluster_firstStrip_S0.size() != cluster_lastStrip_S0.size()){ std::cerr << "Error in vector size cluster/S0 for first/last strip.\n"; exit; } //Calculate the cluster width and position for all sensors: for(size_t strip = 0; strip < cluster_firstStrip_S0.size(); ++strip) { // ... // clusterwidth_S0 // clusterposition_S0 } // ... // Produce the stubs for the two modules // Stubs are defined between sensors S0 and S1 (module 1) and S2/S3 (module 2). // Stubs Module 1: // (restricting to one-cluster events) if(clusterposition_S0.size() == 1 && clusterposition_S1.size() == 1) { stubs_M1.push_back(clusterposition_S1.front() - clusterposition_S0.front()); } // ... recotree->Fill(); clusterposition_S0.clear(); clusterposition_S1.clear(); clusterposition_S2.clear(); clusterposition_S3.clear(); clusterwidth_S0.clear(); clusterwidth_S1.clear(); clusterwidth_S2.clear(); clusterwidth_S3.clear(); stubs_M1.clear(); stubs_M2.clear(); hits_valid_S0.clear(); hits_valid_S1.clear(); hits_valid_S2.clear(); hits_valid_S3.clear(); } //end of events loop recofile->cd(); hitmap_S0->Write(); hitmap_S1->Write(); hitmap_S2->Write(); hitmap_S3->Write(); hitmap_S0_masked->Write(); hitmap_S1_masked->Write(); hitmap_S2_masked->Write(); hitmap_S3_masked->Write(); h_clusters_S2->Write(); h_clusters_S3->Write(); recotree->Write(); recofile->Close(); //h_position->Draw(); }
//void MakeFullBigRIPSTree(char *outfile="bigrips.root"){ void MakeFullBigRIPSTree(char *infile, char *outfile="bigrips.root"){ // signal(SIGINT,stop_interrupt); // CTRL + C , interrupt gSystem->Load("libXMLParser.so"); gSystem->Load("libanaroot.so"); TArtStoreManager * sman = TArtStoreManager::Instance(); TArtEventStore *estore = new TArtEventStore(); estore->SetInterrupt(&stoploop); estore->Open(infile); // estore->Open(2); // bigrips online TArtBigRIPSParameters *para = TArtBigRIPSParameters::Instance(); para->LoadParameter("db/BigRIPSPPAC.xml"); para->LoadParameter("db/BigRIPSPlastic.xml"); para->LoadParameter("db/BigRIPSIC.xml"); para->LoadParameter("db/FocalPlane.xml"); TArtCalibPID *brcalib = new TArtCalibPID(); TArtCalibCoin *calcoin= new TArtCalibCoin(); TArtRecoPID *brreco = new TArtRecoPID(); // setting up rips parameters TArtRIPS * rips3to5 = brreco->DefineNewRIPS(3,5,"matrix/mat1.mat",7.5715); // f3 - f5 TArtRIPS * rips5to7 = brreco->DefineNewRIPS(5,7,"matrix/mat2.mat",7.0675); // f5 - f7 // setting up tof TArtTOF * tof3to7 = brreco->DefineNewTOF("F3pl","F7pl",242.513,5); // setting up beam id devices // TArtBeam *beam35 = brreco->DefineNewBeam(rips3to5,tof3to7,"F7IC"); // TArtBeam *beam57 = brreco->DefineNewBeam(rips5to7,tof3to7,"F7IC"); // TArtBeam *beam35ic11 = brreco->DefineNewBeam(rips3to5,tof3to7,"F11IC"); //TArtBeam *beam57ic11 = brreco->DefineNewBeam(rips5to7,tof3to7,"F11IC"); TArtBeam *beam37ic7 = brreco->DefineNewBeam(rips3to5,rips5to7,tof3to7,"F11IC"); // TArtBeam *beam37ic11 = brreco->DefineNewBeam(rips3to5,rips5to7,tof3to7,"F11IC"); TFile *fout = new TFile(outfile,"RECREATE"); TTree *tree = new TTree("tree","tree"); Int_t maxbit; tree->Branch("maxbit",&maxbit,"maxbit/I"); // define data nodes which are supposed to be dumped to tree TClonesArray * info_array = (TClonesArray *)sman->FindDataContainer("EventInfo"); tree->Branch(info_array->GetName(),&info_array); TClonesArray * ppac_array = (TClonesArray *)sman->FindDataContainer("BigRIPSPPAC"); tree->Branch(ppac_array->GetName(),&ppac_array); TClonesArray * pla_array = (TClonesArray *)sman->FindDataContainer("BigRIPSPlastic"); tree->Branch(pla_array->GetName(),&pla_array); TClonesArray * ic_array = (TClonesArray *)sman->FindDataContainer("BigRIPSIC"); tree->Branch(ic_array->GetName(),&ic_array); TClonesArray * fpl_array = (TClonesArray *)sman->FindDataContainer("BigRIPSFocalPlane"); tree->Branch(fpl_array->GetName(),&fpl_array); TClonesArray * tof_array = (TClonesArray *)sman->FindDataContainer("BigRIPSTOF"); tree->Branch(tof_array->GetName(),&tof_array); TClonesArray * rips_array = (TClonesArray *)sman->FindDataContainer("BigRIPSRIPS"); tree->Branch(rips_array->GetName(),&rips_array); TClonesArray * beam_array = (TClonesArray *)sman->FindDataContainer("BigRIPSBeam"); tree->Branch(beam_array->GetName(),&beam_array); TArtBeam *beam = (TArtBeam*)beam_array->At(0); int neve = 0; while(estore->GetNextEvent()){ maxbit = 0; if(neve%1000==0) cout << "event: " << neve << endl; calcoin->ClearData(); calcoin->LoadData(); brcalib->ClearData(); brcalib->ReconstructData(); brreco->ClearData(); brreco->ReconstructData(); // beam->SetAoQ(beam->GetAoQ()-0.042); Int_t tbit = ((TArtEventInfo*)info_array->At(0))->GetTriggerBit(); for(int i=1;;i++){ if(tbit%2 == 1) maxbit = i; else break; tbit = tbit/2; } tree->Fill(); neve ++; } fout->Write(); fout->Close(); }
//Make pull plots from the output of a toy study void ResultFormatter::WriteFlatNtuple( const string FileName, const FitResultVector* ToyResult, const vector<string> inputXML, const vector<string> runtimeArgs, const string XMLForProjections, const string XMLForToys ) { TFile * rootFile = TFile::Open( FileName.c_str(), "RECREATE" ); rootFile->SetCompressionLevel( 9 ); //cout << "Storing Fit Result Vector" << endl; // Important! // The output from this is typically run through the RapidPlot file // For sake of backwards compatibility the RapidPlot tool makes use of the ability to look for the 'first' TTree in a ROOT file for some of it's internal logic // KEEP THIS TREE AS THE FIRST TREE CREATED AND WRITTEN TO THE FILE TO BE ABLE TO KEEP USING THIS TOOL!!! TTree* outputTree = new TTree( "RapidFitResult", "RapidFitResult" ); ResultParameterSet* resultSet = ToyResult->GetFitResult( 0 )->GetResultParameterSet(); vector<string> allNames = resultSet->GetAllNames(); for( unsigned int param_i=0; param_i< allNames.size(); ++param_i ) { string thisParamName( allNames[param_i] ); vector<double> ParameterValues, ParameterErrors, ParameterOriginalValues; vector<double> ParameterPulls, ParameterStepSizes; vector<double> ParameterErrorsHigh, ParameterErrorsLow; vector<double> ParameterMinimums, ParameterMaximums; vector<int> ParameterScanStatus, ParameterFixedStatus; for( unsigned int resultNum=0; resultNum< (unsigned)ToyResult->NumberResults(); ++resultNum ) { ResultParameter* thisParam = ToyResult->GetFitResult( (unsigned)resultNum )->GetResultParameterSet()->GetResultParameter( thisParamName ); ParameterValues.push_back( thisParam->GetValue() ); ParameterErrors.push_back( thisParam->GetError() ); ParameterPulls.push_back( thisParam->GetPull() ); ParameterMinimums.push_back( thisParam->GetMinimum() ); ParameterMaximums.push_back( thisParam->GetMaximum() ); ParameterOriginalValues.push_back( thisParam->GetOriginalValue() ); if( thisParam->GetType() == "Fixed" ) { ParameterFixedStatus.push_back( 1 ); } else { ParameterFixedStatus.push_back( 0 ); } //if( thisParam->GetScanStatus() ) cout << "Scanned: " << string(thisParamName) << endl; if( thisParam->GetScanStatus() ) { ParameterScanStatus.push_back( 1 ); } else { ParameterScanStatus.push_back( 0 ); } if( thisParam->GetAssym() ) { ParameterErrorsHigh.push_back( thisParam->GetErrHi() ); ParameterErrorsLow.push_back( thisParam->GetErrLow() ); } else { ParameterErrorsHigh.push_back( 0. ); ParameterErrorsLow.push_back( 0. ); } ParameterStepSizes.push_back( thisParam->GetStepSize() ); } string BranchName=allNames[param_i]; ResultFormatter::AddBranch( outputTree, BranchName+"_value", ParameterValues ); bool fixed_param = ToyResult->GetFitResult(0)->GetResultParameterSet()->GetResultParameter(thisParamName)->GetType() == "Fixed"; bool scanned_param = ToyResult->GetFitResult(0)->GetResultParameterSet()->GetResultParameter(thisParamName)->GetScanStatus(); if( (!fixed_param) || (scanned_param) ) { ResultFormatter::AddBranch( outputTree, BranchName+"_error", ParameterErrors ); ResultFormatter::AddBranch( outputTree, BranchName+"_gen", ParameterOriginalValues ); ResultFormatter::AddBranch( outputTree, BranchName+"_pull", ParameterPulls ); ResultFormatter::AddBranch( outputTree, BranchName+"_max", ParameterMaximums ); ResultFormatter::AddBranch( outputTree, BranchName+"_min", ParameterMinimums ); ResultFormatter::AddBranch( outputTree, BranchName+"_step", ParameterStepSizes ); ResultFormatter::AddBranch( outputTree, BranchName+"_errHi", ParameterErrorsHigh ); ResultFormatter::AddBranch( outputTree, BranchName+"_errLo", ParameterErrorsLow ); } ResultFormatter::AddBranch( outputTree, BranchName+"_scan", ParameterScanStatus ); ResultFormatter::AddBranch( outputTree, BranchName+"_fix", ParameterFixedStatus ); } //cout << "Stored Parameters" << endl; ResultFormatter::AddBranch( outputTree, "Fit_RealTime", ToyResult->GetAllRealTimes() ); ResultFormatter::AddBranch( outputTree, "Fit_CPUTime", ToyResult->GetAllCPUTimes() ); ResultFormatter::AddBranch( outputTree, "Fit_GLTime", ToyResult->GetAllGLTimes() ); vector<int> fitStatus; vector<double> NLL_Values, RealTimes, CPUTimes; for( unsigned int i=0; i< (unsigned) ToyResult->NumberResults(); ++i ) { fitStatus.push_back( ToyResult->GetFitResult( (int)i )->GetFitStatus() ); NLL_Values.push_back( ToyResult->GetFitResult( (int)i )->GetMinimumValue() ); } ResultFormatter::AddBranch( outputTree, "Fit_Status", fitStatus ); ResultFormatter::AddBranch( outputTree, "NLL", NLL_Values ); outputTree->Write("",TObject::kOverwrite); //ResultFormatter::AddBranch( outputTree, "Fit_RealTime", RealTimes ); //ResultFormatter::AddBranch( outputTree, "Fit_CPUTime", CPUTimes ); // Ntuples are 'stupid' objects in ROOT and the basic one can only handle float type objects /*TNtuple * parameterNTuple; parameterNTuple = new TNtuple("RapidFitResult", "RapidFitResult", ToyResult->GetFlatResultHeader()); Float_t * resultArr; for( int resultIndex = 0; resultIndex < ToyResult->NumberResults(); ++resultIndex ) { vector<double> result = ToyResult->GetFlatResult(resultIndex); resultArr = new Float_t [result.size()]; copy( result.begin(), result.end(), resultArr); parameterNTuple->Fill( resultArr ); delete [] resultArr; }*/ //cout << "Storing Correlation Matrix" << endl; if( ToyResult->GetFitResult(0)->GetResultParameterSet() != NULL ) { if( !ToyResult->GetFitResult(0)->GetResultParameterSet()->GetAllFloatNames().empty() ) { vector<double> MatrixElements; vector<string> MatrixNames; TTree * tree = new TTree("corr_matrix", "Elements from Correlation Matricies"); tree->Branch("MartrixElements", "std::vector<double>", &MatrixElements ); tree->Branch("MartrixNames", "std::vector<string>", &MatrixNames ); for( int resultIndex = 0; resultIndex < ToyResult->NumberResults(); ++resultIndex ) { TMatrixDSym* thisMatrix = ToyResult->GetFitResult(resultIndex)->GetCovarianceMatrix()->thisMatrix; if( thisMatrix == NULL ) continue; MatrixNames = ToyResult->GetFitResult(resultIndex)->GetCovarianceMatrix()->theseParameters; if( MatrixNames.empty() ) continue; double* MatrixArray = thisMatrix->GetMatrixArray(); if( MatrixArray == NULL ) continue; MatrixElements.clear(); for( unsigned int i=0; i< (unsigned) thisMatrix->GetNoElements(); ++i ) { MatrixElements.push_back( MatrixArray[i] ); } if( thisMatrix->GetNoElements() > 0 ) tree->Fill(); } tree->Write("",TObject::kOverwrite); } } //cout << "Saving XML and runtime" << endl; if( !inputXML.empty() ) { TTree* XMLTree = new TTree( "FittingXML", "FittingXML" ); vector<string> thisXML = inputXML; XMLTree->Branch( "FittingXML", "std::vector<string>", &thisXML ); XMLTree->Fill(); XMLTree->Write("",TObject::kOverwrite); } if( !runtimeArgs.empty() ) { TTree* RuntimeTree = new TTree( "RuntimeArgs", "RuntimeArgs" ); vector<string> thisRuntime = runtimeArgs; RuntimeTree->Branch( "RuntimeArgs", "std::vector<string>", &thisRuntime ); RuntimeTree->Fill(); RuntimeTree->Write("",TObject::kOverwrite); } if( !XMLForProjections.empty() ) { TTree* ProjectionXML = new TTree( "XMLForProjections", "XMLForProjections" ); string thisXML = XMLForProjections; ProjectionXML->Branch( "ProjectionXML", "std::string", &thisXML ); ProjectionXML->Fill(); ProjectionXML->Write("",TObject::kOverwrite); } if( !XMLForToys.empty() ) { TTree* ToyXML = new TTree( "XMLForToys", "XMLForToys" ); string thisXML = XMLForToys; ToyXML->Branch( "ToyXML", "std::string", &thisXML ); ToyXML->Fill(); ToyXML->Write("",TObject::kOverwrite); } rootFile->Write("",TObject::kOverwrite); rootFile->Close(); // THIS SHOULD BE SAFE... BUT THIS IS ROOT so 'of course' it isn't... //delete parameterNTuple; //delete rootFile; }
int main(int argc, char **argv) { struct DanssEventStruct4 DanssEvent; struct DanssCmStruct DanssCm; struct DanssEventStruct4 SavedEvent; struct DanssInfoStruct4 DanssInfo; struct DanssInfoStruct SumInfo; TChain *EventChain; TChain *InfoChain; TTree *tOut; TTree *InfoOut; TFile *fOut; FILE *fList; char str[1024]; long long iEvt, nEvt; long long lastgTime, lastVeto; int CmCnt; int i; char *ptr; int nCnt; if (argc < 3) { printf("Usage: ./cmbuilder list_file.txt output_file.root\n"); printf("Will process files in the list_file and create root-file\n"); return 10; } fOut = new TFile(argv[2], "RECREATE"); if (!fOut->IsOpen()) { printf("Can not open the output file %s: %m\n", argv[2]); return -10; } tOut = new TTree("DanssCm", "Time Correlated events"); tOut->Branch("Cm", &DanssCm, "number[10]/L:" // event numbers in the file "unixTime/I:" // linux time, seconds "N/I:" // number of neutrons + 1 "SiPmCleanEnergy[10]/F:" // Full Clean energy SiPm "PmtCleanEnergy[10]/F:" // Full Clean energy Pmt // "neutron" parameters "Hits[10]/I:" // SiPm clean hits // "NeutronHits[10]/I:" // number of hits considered as neutron capture gammas "NeutronEnergy[10]/F:" // Energy sum of above (SiPM) "NeutronX[10][3]/F:" // center of gammas position "PositronX[10][3]/F:" // maximum hit clusters // "NeutronGammaEnergy[10][5]/F:" // sorted list of the 5 most energetic gammas // "NeutronGammaDistance[10][5]/F:" // distances for the gammas above to the "neutron" center "PositronEnergy[10]/F:" // maximum hit clusters "NeutronRadius[10]/F:" // average distance between hits and the center // Pair parameters "gtDiff[10]/F:" // time difference in us (from 125 MHz clock) "Distance[10]/F:" // distance between neutron and positron, cm "DistanceZ[10]/F" // in Z, cm ); InfoOut = new TTree("SumInfo", "Summary information"); InfoOut->Branch("Info", &SumInfo, "gTime/L:" // running time in terms of 125 MHz "startTime/I:" // linux start time, seconds "stopTime/I:" // linux stop time, seconds "events/I" // number of events ); memset(&SumInfo, 0, sizeof(struct DanssInfoStruct4)); memset(&DanssCm, 0, sizeof(struct DanssCmStruct)); EventChain = new TChain("DanssEvent"); EventChain->SetBranchAddress("Data", &DanssEvent); InfoChain = new TChain("DanssInfo"); InfoChain->SetBranchAddress("Info", &DanssInfo); fList = fopen(argv[1], "rt"); if (!fList) { printf("Can not open list of files %s: %m\n", argv[1]); goto fin; } for(;;) { if (!fgets(str, sizeof(str), fList)) break; ptr = strchr(str, '\n'); if (ptr) *ptr = '\0'; EventChain->Add(str); InfoChain->Add(str); } fclose(fList); nEvt = EventChain->GetEntries(); CmCnt = 0; nCnt = 0; lastVeto = lastgTime = -GLOBALFREQ; for (iEvt =0; iEvt < nEvt; iEvt++) { EventChain->GetEntry(iEvt); if (IsVeto(&DanssEvent)) { lastVeto = DanssEvent.globalTime; lastgTime = -GLOBALFREQ; nCnt = 0; } if (DanssEvent.globalTime - lastVeto < VETOBLK * GFREQ2US) { continue; // Veto is active } if (DanssEvent.globalTime - lastgTime < MAXTDIFF * GFREQ2US) { Add2Cm(&DanssEvent, &DanssCm, nCnt, lastgTime); nCnt++; continue; } else { if (nCnt) { DanssCm.N = nCnt; tOut->Fill(); if (nCnt > 0) CmCnt++; nCnt = 0; memset(&DanssCm, 0, sizeof(struct DanssCmStruct)); } if (IsFission(&DanssEvent)) { lastgTime = DanssEvent.globalTime; Add2Cm(&DanssEvent, &DanssCm, nCnt, lastgTime); nCnt++; } } } for(i=0; i<InfoChain->GetEntries(); i++) { InfoChain->GetEntry(i); SumInfo.upTime += DanssInfo.upTime; SumInfo.stopTime = DanssInfo.stopTime; SumInfo.events += DanssInfo.events; if (!i) SumInfo.startTime = DanssInfo.startTime; } InfoOut->Fill(); printf("%Ld events processed - %d fissions found. Aquired time %f7.0 s\n", iEvt, CmCnt, SumInfo.upTime / GLOBALFREQ); printf("Trigger freq = %7.1f Hz\n", 1.0 * iEvt * GLOBALFREQ / SumInfo.upTime); printf("Fission freq = %7.1f Hz\n", 1.0 * CmCnt * GLOBALFREQ / SumInfo.upTime); fin: delete EventChain; delete InfoChain; InfoOut->Write(); tOut->Write(); fOut->Close(); return 0; }
void RecoSAMURAI(char * finname="calib.root", char * foutname="reco.root", Int_t nevents = 99999999, Int_t starteventn = 0 ){ Double_t samurai_center_brho = 7.2751; // Tm Double_t hodpos_offset = 246.44; // mm Double_t hodtof_offset = 146.5; // ns Double_t dist_pla2target = 2824.; // mm TFile *fin = new TFile(finname,"READ"); gROOT->cd(); TTree *itree = (TTree*)fin->Get("sm"); TArtStoreManager * sman = TArtStoreManager::Instance(); sman->LoadDataFromTree(itree); TArtRecoFragment * recofrag = new TArtRecoFragment; recofrag->SetCenterBrho(samurai_center_brho); recofrag->SetTOFOffSet(hodtof_offset); recofrag->SetPla2TargetLength(dist_pla2target); std::cout << "getting data containers" << std::endl; TClonesArray *fragments = (TClonesArray *)sman->FindDataContainer("SAMURAIFragment"); Double_t fragdelta, fragbrho, fragtof, fragbeta, fragaoq; Double_t trchi2, trpos[3], trl2hod; Int_t trstatus, trnhit; TFile *fout = new TFile(foutname,"RECREATE"); TTree *otree = itree->CloneTree(0); /* TObjArray *branchArray = itree->GetListOfBranches(); for (Int_t i=0; i<(size_t)(branchArray->GetEntriesFast()); i++) { TBranch *branch = (TBranch *) ((*branchArray)[i]); otree->Branch(branch->GetName(),&branch); } */ otree->Branch("fragdelta",&fragdelta,"fragdelta/D"); otree->Branch("fragbrho",&fragbrho,"fragbrho/D"); otree->Branch("fragtof",&fragtof,"fragtof/D"); otree->Branch("fragbeta",&fragbeta,"fragbeta/D"); otree->Branch("fragaoq",&fragaoq,"fragaoq/D"); otree->Branch("trstatus",&trstatus,"trstatus/I"); otree->Branch("trchi2",&trchi2,"trchi2/D"); otree->Branch("trnhit",&trnhit,"trnhit/I"); otree->Branch("trpos",trpos,"trpos[3]/D"); otree->Branch("trl2hod",&trl2hod,"trl2hod/D"); int nentries = itree->GetEntries(); int neve = starteventn; std::cout << "entries in input tree: " << nentries << std::endl; std::cout << "start to scan from event" << neve << std::endl; while(neve<nevents+starteventn && neve < nentries){ itree->GetEntry(neve); recofrag->ClearData(); recofrag->ReconstructData(); if(fragments){ if(fragments->GetEntriesFast()>0){ TArtFragment *f= (TArtFragment*)fragments->At(0); fragdelta = f->GetDelta(); fragbrho = f->GetBrho(); // std::cout << fragbrho << std::endl; fragtof = f->GetTOF(); fragbeta = f->GetBeta(); fragaoq = f->GetAoQ(); trchi2 = f->GetChi2(); trpos[0] = f->GetPrimaryPosition().X(); trpos[1] = f->GetPrimaryPosition().Y(); trpos[2] = f->GetPrimaryPosition().Z(); trl2hod = f->GetPathLengthToHOD(); trstatus = f->GetRKtraceStatus() ? 1 : 0; trnhit = f->GetNHit(); } else{ fragdelta = -9999; fragbrho = -9999; fragtof = -9999; fragbeta = -9999; fragaoq = -9999; trchi2 = -9999; for(int i=0;i<3;i++) trpos[i] = -9999; trl2hod = -9999; trstatus = 0; trnhit = -1; } } else{ fragdelta = -9999; fragbrho = -9999; fragtof = -9999; fragbeta = -9999; fragaoq = -9999; trchi2 = -9999; for(int i=0;i<3;i++) trpos[i] = -9999; trl2hod = -9999; trstatus = 0; trnhit = -1; } otree->Fill(); neve ++; } std::cout << "finish to scan" << std::endl; fout->Write(); fout->Close(); }
void ZJetsToLL_App( TString myMethodList = "" ) { #ifdef __CINT__ gROOT->ProcessLine( ".O0" ); // turn off optimization in CINT #endif //--------------------------------------------------------------- // This loads the library TMVA::Tools::Instance(); // Default MVA methods to be trained + tested std::map<std::string,int> Use; // --- Cut optimisation Use["Cuts"] = 0; Use["CutsD"] = 0; Use["CutsPCA"] = 0; Use["CutsGA"] = 0; Use["CutsSA"] = 0; // // --- 1-dimensional likelihood ("naive Bayes estimator") Use["Likelihood"] = 0; Use["LikelihoodD"] = 0; // the "D" extension indicates decorrelated input variables (see option strings) Use["LikelihoodPCA"] = 0; // the "PCA" extension indicates PCA-transformed input variables (see option strings) Use["LikelihoodKDE"] = 0; Use["LikelihoodMIX"] = 0; // // --- Mutidimensional likelihood and Nearest-Neighbour methods Use["PDERS"] = 0; Use["PDERSD"] = 0; Use["PDERSPCA"] = 0; Use["PDEFoam"] = 0; Use["PDEFoamBoost"] = 0; // uses generalised MVA method boosting Use["KNN"] = 0; // k-nearest neighbour method // // --- Linear Discriminant Analysis Use["LD"] = 0; // Linear Discriminant identical to Fisher Use["Fisher"] = 0; Use["FisherG"] = 0; Use["BoostedFisher"] = 0; // uses generalised MVA method boosting Use["HMatrix"] = 0; // // --- Function Discriminant analysis Use["FDA_GA"] = 0; // minimisation of user-defined function using Genetics Algorithm Use["FDA_SA"] = 0; Use["FDA_MC"] = 0; Use["FDA_MT"] = 0; Use["FDA_GAMT"] = 0; Use["FDA_MCMT"] = 0; // // --- Neural Networks (all are feed-forward Multilayer Perceptrons) Use["MLP"] = 0; // Recommended ANN Use["MLPBFGS"] = 0; // Recommended ANN with optional training method Use["MLPBNN"] = 0; // Recommended ANN with BFGS training method and bayesian regulator Use["CFMlpANN"] = 0; // Depreciated ANN from ALEPH Use["TMlpANN"] = 0; // ROOT's own ANN // // --- Support Vector Machine Use["SVM"] = 0; // // --- Boosted Decision Trees using this Use["BDT"] = 1; // uses Adaptive Boost Use["BDTG"] = 0; // uses Gradient Boost Use["BDTB"] = 0; // uses Bagging Use["BDTD"] = 0; // decorrelation + Adaptive Boost // // --- Friedman's RuleFit method, ie, an optimised series of cuts ("rules") Use["RuleFit"] = 0; // --------------------------------------------------------------- Use["Plugin"] = 0; Use["Category"] = 0; Use["SVM_Gauss"] = 0; Use["SVM_Poly"] = 0; Use["SVM_Lin"] = 0; std::cout << std::endl; std::cout << "==> Start ZJetsToLL_App" << std::endl; // Select methods (don't look at this code - not of interest) if (myMethodList != "") { for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0; std::vector<TString> mlist = gTools().SplitString( myMethodList, ',' ); for (UInt_t i=0; i<mlist.size(); i++) { std::string regMethod(mlist[i]); if (Use.find(regMethod) == Use.end()) { std::cout << "Method \"" << regMethod << "\" not known in TMVA under this name. Choose among the following:" << std::endl; for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) { std::cout << it->first << " "; } std::cout << std::endl; return; } Use[regMethod] = 1; } } // -------------------------------------------------------------------------------------------------- // --- Create the Reader object TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" ); // Create a set of variables and declare them to the reader // - the variable names MUST corresponds in name and type to those given in the weight file(s) used Float_t Hmass, Zmass; Float_t Hpt, Zpt; Float_t CSV0, CSV1; Float_t DeltaPhiHV, DetaJJ; Int_t nJets, eventFlavor; Float_t Naj, nSV; Float_t BDTvalue, Trigweight, B2011PUweight, btag2CSF, MET; Float_t alpha_j, qtb1, jetPhi0, jetPhi1, jetEta0, jetEta1, Zphi, Hphi; Float_t Ht, EvntShpCircularity, jetCHF0, jetCHF1; Float_t EtaStandDev, muonPFiso0, muonPFiso1, EvntShpIsotropy; Float_t mu0pt, mu1pt, UnweightedEta, DphiJJ, RMS_eta, EvntShpSphericity; Float_t PtbalZH, EventPt, Angle, Centrality, EvntShpAplanarity; reader->AddVariable( "Hmass", &Hmass ); // reader->AddVariable( "Zmass", &Zmass ); reader->AddVariable( "Hpt", &Hpt ); reader->AddVariable( "CSV0", &CSV0 ); reader->AddVariable( "CSV1", &CSV1 ); reader->AddVariable( "Zpt", &Zpt ); reader->AddVariable( "DeltaPhiHV:= abs(deltaPhi(Hphi,Zphi))", &DeltaPhiHV ); reader->AddVariable( "DetaJJ:= abs(jetEta1-jetEta0)", &DetaJJ ); reader->AddVariable( "Naj", &Naj); reader->AddVariable( "UnweightedEta", &UnweightedEta ); reader->AddVariable( "EvntShpCircularity", &EvntShpCircularity ); reader->AddVariable( "alpha_j", &alpha_j ); reader->AddVariable( "qtb1", &qtb1 ); reader->AddVariable( "nSV", &nSV ); reader->AddVariable( "mu0pt", &mu0pt ); reader->AddVariable( "mu1pt", &mu1pt ); reader->AddVariable( "PtbalZH", &PtbalZH ); reader->AddVariable( "Angle", &Angle ); reader->AddVariable( "Centrality", &Centrality ); reader->AddVariable( "MET", &MET ); reader->AddVariable( "EvntShpAplanarity", &EvntShpAplanarity ); // Spectator variables declared in the training have to be added to the reader, too Float_t UnweightedEta, mu0pt; // reader->AddSpectator( "UnweightedEta", &UnweightedEta ); // reader->AddSpectator( "mu0pt", &mu0pt ); /* Float_t Category_cat1, Category_cat2, Category_cat3; if (Use["Category"]){ // Add artificial spectators for distinguishing categories reader->AddSpectator( "Category_cat1 := var3<=0", &Category_cat1 ); reader->AddSpectator( "Category_cat2 := (var3>0)&&(var4<0)", &Category_cat2 ); reader->AddSpectator( "Category_cat3 := (var3>0)&&(var4>=0)", &Category_cat3 ); } */ // --- Book the MVA methods TString dir = "weights/"; TString prefix = "TMVAClassification"; // Book method(s) for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) { if (it->second) { TString methodName = TString(it->first) + TString(" method"); TString weightfile = dir + prefix + TString("_") + TString(it->first) + TString(".weights.xml"); reader->BookMVA( methodName, weightfile ); } } // Book output histograms TH1F* hCHFb0_OpenSelection= new TH1F ("hCHFb0_OpenSelection", "charged Hadron Energy Fraction b1", 40, 0.0, 1.2); TH1F* hCHFb1_OpenSelection= new TH1F ("hCHFb1_OpenSelection", "charged Hadron Energy Fraction b2", 40, 0.0, 1.2); TH1F* hPtjj_OpenSelection= new TH1F ("hPtjj_OpenSelection","Pt of two b jets with highest CSV ", 50, 0.0, 400); TH1F* hPtmumu_OpenSelection= new TH1F ("hPtmumu_OpenSelection","Pt of two muons with highest pt ", 50, 0.0, 400); TH1F* hPtbalZH_OpenSelection= new TH1F ("hPtbalZH_OpenSelection", "Pt balance of Z and H", 40, -80, 80); TH1F* hPtmu0_OpenSelection= new TH1F ("hPtmu0_OpenSelection","Pt of muon with highest pt ", 30, 0.0, 300); TH1F* hPtmu1_OpenSelection= new TH1F ("hPtmu1_OpenSelection","Pt of muon with second highest pt ", 30, 0.0, 300); TH1F* hPFRelIsomu0_OpenSelection= new TH1F ("hPFRelIsomu0_OpenSelection", "PF Rel Iso of muon with highest Pt", 40, 0., 0.2); TH1F* hPFRelIsomu1_OpenSelection= new TH1F ("hPFRelIsomu1_OpenSelection", "PF Rel Iso of muon with second highest Pt", 40, 0., 0.2); TH1F* hCSV0_OpenSelection= new TH1F ("hCSV0_OpenSelection","Jet with highest CSV ", 40, 0, 1.5); TH1F* hCSV1_OpenSelection= new TH1F ("hCSV1_OpenSelection","Jet with second highest CSV ", 40, 0, 1.5); TH1F* hdphiVH_OpenSelection= new TH1F ("hdphiVH_OpenSelection","Delta phi between Z and Higgs ", 50, -0.1, 4.5); TH1F* hdetaJJ_OpenSelection= new TH1F ("hdetaJJ_OpenSelection","Delta eta between two jets ", 60, -4, 4); TH1F* hNjets_OpenSelection= new TH1F ("hNjets_OpenSelection", "Number of Jets", 13, -2.5, 10.5); TH1F* hMjj_OpenSelection = new TH1F ("hMjj_OpenSelection", "Invariant Mass of two Jets ", 50, 0, 300); TH1F* hMmumu_OpenSelection = new TH1F ("hMmumu_OpenSelection", "Invariant Mass of two muons ", 75, 0, 200); TH1F* hRMSeta_OpenSelection= new TH1F ("hRMSeta_OpenSelection", "RMS Eta", 30, 0, 3); TH1F* hStaDeveta_OpenSelection= new TH1F ("hStaDeveta_OpenSelection", "Standard Deviation Eta", 30, 0, 3); TH1F* hUnweightedEta_OpenSelection= new TH1F ("hUnweightedEta_OpenSelection", "Unweighted Eta ", 50, 0, 15); TH1F* hdphiJJ_vect_OpenSelection= new TH1F ("hdphiJJ_vect_OpenSelection", "Delta phi between two jets", 30, -3.5, 4); TH1F* hCircularity_OpenSelection= new TH1F("hCircularity_OpenSelection","EventShapeVariables circularity", 30, 0.0, 1.2); TH1F* hHt_OpenSelection= new TH1F("hHt_OpenSelection","scalar sum of pt of four particles", 50, 0.0, 500); TH1F* hCentrality_OpenSelection= new TH1F ("hCentrality_OpenSelection", "Centrality", 40, 0.0, 0.8); TH1F* hEventPt_OpenSelection= new TH1F ("hEventPt_OpenSelection", "Pt of HV system", 50, 0.0, 100); TH1F* hAngle_OpenSelection= new TH1F ("hAngle_OpenSelection", "Angle between H and Z", 45, 0, 4.5); TH1F* hSphericity_OpenSelection= new TH1F ("hSphericity_OpenSelection", "EventShapeVariables sphericity", 50, 0.0, 1); TH1F* hAplanarity_OpenSelection= new TH1F ("hAplanarity_OpenSelection", "EventShapeVariables Aplanarity", 50, -0.1, .4); TH1F* hIsotropy_OpenSelection= new TH1F ("hIsotropy_OpenSelection", "EventShapeVariables isotropy", 30, 0.0, 1.3); TH2F* hDphiDetajj_OpenSelection= new TH2F ("hDphiDetajj_OpenSelection", "#Delta#phi vs #Delta#eta JJ", 25, -5, 5, 25, -5, 5); TTree *treeWithBDT = new TTree("treeWithBDT","Tree wiht BDT output"); treeWithBDT->SetDirectory(0); treeWithBDT->Branch("nJets",&nJets, "nJets/I"); treeWithBDT->Branch("Naj",&Naj, "Naj/F"); treeWithBDT->Branch("eventFlavor",&eventFlavor, "eventFlavor/I"); treeWithBDT->Branch("CSV0",&CSV0, "CSV0/F"); treeWithBDT->Branch("CSV1",&CSV1, "CSV1/F"); treeWithBDT->Branch("Zmass",&Zmass, "Zmass/F"); treeWithBDT->Branch("Hmass",&Hmass, "Hmass/F"); treeWithBDT->Branch("DeltaPhiHV",&DeltaPhiHV, "DeltaPhiHV/F"); treeWithBDT->Branch("Hpt",&Hpt, "Hpt/F"); treeWithBDT->Branch("Zpt",&Zpt, "Zpt/F"); treeWithBDT->Branch("mu0pt",&mu0pt, "mu0pt/F"); treeWithBDT->Branch("Ht",&Ht, "Ht/F"); treeWithBDT->Branch("EtaStandDev",&EtaStandDev, "EtaStandDev/F"); treeWithBDT->Branch("UnweightedEta",&UnweightedEta, "UnweightedEta/F"); treeWithBDT->Branch("EvntShpCircularity",&EvntShpCircularity, "EvntShpCircularity/F"); treeWithBDT->Branch("alpha_j",&alpha_j, "alpha_j/F"); treeWithBDT->Branch("qtb1",&qtb1, "qtb1/F"); treeWithBDT->Branch("nSV",&nSV, "nSV/F"); treeWithBDT->Branch("Trigweight",&Trigweight, "Trigweight/F"); treeWithBDT->Branch("B2011PUweight",&B2011PUweight, "B2011PUweight/F"); treeWithBDT->Branch("btag2CSF",&btag2CSF, "btag2CSF/F"); treeWithBDT->Branch("DetaJJ",&DetaJJ, "DetaJJ/F"); treeWithBDT->Branch("jetCHF0",&jetCHF0, "jetCHF0/F"); treeWithBDT->Branch("jetCHF1",&jetCHF1, "jetCHF1/F"); treeWithBDT->Branch("jetPhi0",&jetPhi0, "jetPhi0/F"); treeWithBDT->Branch("jetPhi1",&jetPhi1, "jetPhi1/F"); treeWithBDT->Branch("jetEta0",&jetEta0, "jetEta0/F"); treeWithBDT->Branch("jetEta1",&jetEta1, "jetEta1/F"); treeWithBDT->Branch("mu1pt",&mu1pt, "mu1pt/F"); treeWithBDT->Branch("muonPFiso0",&muonPFiso0, "muonPFiso0/F"); treeWithBDT->Branch("muonPFiso1",&muonPFiso1, "muonPFiso1/F"); treeWithBDT->Branch("DphiJJ",&DphiJJ, "DphiJJ/F"); treeWithBDT->Branch("RMS_eta",&RMS_eta, "RMS_eta/F"); treeWithBDT->Branch("PtbalZH",&PtbalZH, "PtbalZH/F"); treeWithBDT->Branch("EventPt",&EventPt, "EventPt/F"); treeWithBDT->Branch("Angle",&Angle, "Angle/F"); treeWithBDT->Branch("Centrality",&Centrality, "Centrality/F"); treeWithBDT->Branch("MET",&MET, "MET/F"); treeWithBDT->Branch("EvntShpAplanarity",&EvntShpAplanarity, "EvntShpAplanarity/F"); treeWithBDT->Branch("EvntShpSphericity",&EvntShpSphericity, "EvntShpSphericity/F"); treeWithBDT->Branch("EvntShpIsotropy",&EvntShpIsotropy, "EvntShpIsotropy/F"); treeWithBDT->Branch("Zphi",&Zphi, "Zphi/F"); treeWithBDT->Branch("Hphi",&Hphi, "Hphi/F"); treeWithBDT->Branch("BDTvalue",&BDTvalue, "BDTvalue/F"); UInt_t nbin = 15; TH1F *histLk(0), *histLkD(0), *histLkPCA(0), *histLkKDE(0), *histLkMIX(0), *histPD(0), *histPDD(0); TH1F *histPDPCA(0), *histPDEFoam(0), *histPDEFoamErr(0), *histPDEFoamSig(0), *histKNN(0), *histHm(0); TH1F *histFi(0), *histFiG(0), *histFiB(0), *histLD(0), *histNn(0),*histNnbfgs(0),*histNnbnn(0); TH1F *histNnC(0), *histNnT(0), *histBdt(0), *histBdtG(0), *histBdtD(0), *histRf(0), *histSVMG(0); TH1F *histSVMP(0), *histSVML(0), *histFDAMT(0), *histFDAGA(0), *histCat(0), *histPBdt(0); if (Use["Likelihood"]) histLk = new TH1F( "MVA_Likelihood", "MVA_Likelihood", nbin, -1, 1 ); if (Use["LikelihoodD"]) histLkD = new TH1F( "MVA_LikelihoodD", "MVA_LikelihoodD", nbin, -1, 0.9999 ); if (Use["LikelihoodPCA"]) histLkPCA = new TH1F( "MVA_LikelihoodPCA", "MVA_LikelihoodPCA", nbin, -1, 1 ); if (Use["LikelihoodKDE"]) histLkKDE = new TH1F( "MVA_LikelihoodKDE", "MVA_LikelihoodKDE", nbin, -0.00001, 0.99999 ); if (Use["LikelihoodMIX"]) histLkMIX = new TH1F( "MVA_LikelihoodMIX", "MVA_LikelihoodMIX", nbin, 0, 1 ); if (Use["PDERS"]) histPD = new TH1F( "MVA_PDERS", "MVA_PDERS", nbin, 0, 1 ); if (Use["PDERSD"]) histPDD = new TH1F( "MVA_PDERSD", "MVA_PDERSD", nbin, 0, 1 ); if (Use["PDERSPCA"]) histPDPCA = new TH1F( "MVA_PDERSPCA", "MVA_PDERSPCA", nbin, 0, 1 ); if (Use["KNN"]) histKNN = new TH1F( "MVA_KNN", "MVA_KNN", nbin, 0, 1 ); if (Use["HMatrix"]) histHm = new TH1F( "MVA_HMatrix", "MVA_HMatrix", nbin, -0.95, 1.55 ); if (Use["Fisher"]) histFi = new TH1F( "MVA_Fisher", "MVA_Fisher", nbin, -4, 4 ); if (Use["FisherG"]) histFiG = new TH1F( "MVA_FisherG", "MVA_FisherG", nbin, -1, 1 ); if (Use["BoostedFisher"]) histFiB = new TH1F( "MVA_BoostedFisher", "MVA_BoostedFisher", nbin, -2, 2 ); if (Use["LD"]) histLD = new TH1F( "MVA_LD", "MVA_LD", nbin, -2, 2 ); if (Use["MLP"]) histNn = new TH1F( "MVA_MLP", "MVA_MLP", nbin, -1.25, 1.5 ); if (Use["MLPBFGS"]) histNnbfgs = new TH1F( "MVA_MLPBFGS", "MVA_MLPBFGS", nbin, -1.25, 1.5 ); if (Use["MLPBNN"]) histNnbnn = new TH1F( "MVA_MLPBNN", "MVA_MLPBNN", nbin, -1.25, 1.5 ); if (Use["CFMlpANN"]) histNnC = new TH1F( "MVA_CFMlpANN", "MVA_CFMlpANN", nbin, 0, 1 ); if (Use["TMlpANN"]) histNnT = new TH1F( "MVA_TMlpANN", "MVA_TMlpANN", nbin, -1.3, 1.3 ); if (Use["BDT"]) { histMattBdt = new TH1F( "Matt_BDT", "Matt_BDT", 15, -1.1, 0.35 ); histTMVABdt = new TH1F( "TMVA_BDT", "TMVA_BDT", 88, -1.0, 0.1 ); } if (Use["BDTD"]) histBdtD = new TH1F( "MVA_BDTD", "MVA_BDTD", nbin, -0.8, 0.8 ); if (Use["BDTG"]) histBdtG = new TH1F( "MVA_BDTG", "MVA_BDTG", nbin, -1.0, 1.0 ); if (Use["RuleFit"]) histRf = new TH1F( "MVA_RuleFit", "MVA_RuleFit", nbin, -2.0, 2.0 ); if (Use["SVM_Gauss"]) histSVMG = new TH1F( "MVA_SVM_Gauss", "MVA_SVM_Gauss", nbin, 0.0, 1.0 ); if (Use["SVM_Poly"]) histSVMP = new TH1F( "MVA_SVM_Poly", "MVA_SVM_Poly", nbin, 0.0, 1.0 ); if (Use["SVM_Lin"]) histSVML = new TH1F( "MVA_SVM_Lin", "MVA_SVM_Lin", nbin, 0.0, 1.0 ); if (Use["FDA_MT"]) histFDAMT = new TH1F( "MVA_FDA_MT", "MVA_FDA_MT", nbin, -2.0, 3.0 ); if (Use["FDA_GA"]) histFDAGA = new TH1F( "MVA_FDA_GA", "MVA_FDA_GA", nbin, -2.0, 3.0 ); if (Use["Category"]) histCat = new TH1F( "MVA_Category", "MVA_Category", nbin, -2., 2. ); if (Use["Plugin"]) histPBdt = new TH1F( "MVA_PBDT", "MVA_BDT", nbin, -0.8, 0.8 ); // PDEFoam also returns per-event error, fill in histogram, and also fill significance if (Use["PDEFoam"]) { histPDEFoam = new TH1F( "MVA_PDEFoam", "MVA_PDEFoam", nbin, 0, 1 ); histPDEFoamErr = new TH1F( "MVA_PDEFoamErr", "MVA_PDEFoam error", nbin, 0, 1 ); histPDEFoamSig = new TH1F( "MVA_PDEFoamSig", "MVA_PDEFoam significance", nbin, 0, 10 ); } // Book example histogram for probability (the other methods are done similarly) TH1F *probHistFi(0), *rarityHistFi(0); if (Use["Fisher"]) { probHistFi = new TH1F( "MVA_Fisher_Proba", "MVA_Fisher_Proba", nbin, 0, 1 ); rarityHistFi = new TH1F( "MVA_Fisher_Rarity", "MVA_Fisher_Rarity", nbin, 0, 1 ); } // Prepare input tree (this must be replaced by your data source) // in this example, there is a toy tree with signal and one with background events // we'll later on use only the "signal" events for the test in this example. // TFile *input(0); TString fname = "/home/hep/wilken/Weights/CMSSW_4_2_8_patch3/src/UserCode/wilken/CSVShapeCorr/ZJetsToLL.root"; double lumi = 100.0; Double_t ZJetsToLL_weight = lumi/((2349387.0/80*1000)/2.0); //ZJetsToLL_Pt-100_7TeV-herwigpp //ZJetsToLL_weight = ZJetsToLL_weight*(76684/85684.0); if (!gSystem->AccessPathName( fname )) input = TFile::Open( fname ); // check if file in local directory exists else input = TFile::Open( "http://root.cern.ch/files/tmva_class_example.root" ); // if not: download from ROOT server if (!input) { std::cout << "ERROR: could not open data file" << std::endl; exit(1); } std::cout << "--- TMVAClassificationApp : Using input file: " << input->GetName() << std::endl; // --- Event loop // Prepare the event tree // - here the variable names have to corresponds to your tree // - you can use the same variables as above which is slightly faster, // but of course you can use different ones and copy the values inside the event loop // std::cout << "--- Select signal sample" << std::endl; TTree* theTree = (TTree*)input->Get("BDT_tree"); theTree->SetBranchAddress( "Hmass", &Hmass ); theTree->SetBranchAddress( "Zmass", &Zmass ); theTree->SetBranchAddress( "Hpt", &Hpt ); theTree->SetBranchAddress( "Zpt", &Zpt ); theTree->SetBranchAddress( "CSV0", &CSV0 ); theTree->SetBranchAddress( "CSV1", &CSV1 ); theTree->SetBranchAddress( "DeltaPhiHV", &DeltaPhiHV ); theTree->SetBranchAddress( "DetaJJ", &DetaJJ ); theTree->SetBranchAddress( "UnweightedEta", &UnweightedEta ); theTree->SetBranchAddress( "mu0pt", &mu0pt ); theTree->SetBranchAddress( "Ht", &Ht ); theTree->SetBranchAddress( "EvntShpCircularity", &EvntShpCircularity ); theTree->SetBranchAddress( "nJets", &nJets ); theTree->SetBranchAddress( "Naj", &Naj ); theTree->SetBranchAddress( "mu1pt", &mu1pt ); theTree->SetBranchAddress( "mu0pt", &mu0pt ); theTree->SetBranchAddress( "EtaStandDev", &EtaStandDev ); theTree->SetBranchAddress( "UnweightedEta", &UnweightedEta ); theTree->SetBranchAddress( "jetCHF0", &jetCHF0 ); theTree->SetBranchAddress( "jetCHF1", &jetCHF1 ); theTree->SetBranchAddress( "muonPFiso0", &muonPFiso0 ); theTree->SetBranchAddress( "muonPFiso1", &muonPFiso1 ); theTree->SetBranchAddress( "DphiJJ", &DphiJJ ); theTree->SetBranchAddress( "RMS_eta", &RMS_eta ); theTree->SetBranchAddress( "PtbalZH", &PtbalZH ); theTree->SetBranchAddress( "EventPt", &EventPt ); theTree->SetBranchAddress( "Angle", &Angle ); theTree->SetBranchAddress( "Centrality", &Centrality ); theTree->SetBranchAddress( "EvntShpAplanarity", &EvntShpAplanarity ); theTree->SetBranchAddress( "EvntShpSphericity", &EvntShpSphericity ); theTree->SetBranchAddress( "EvntShpIsotropy", &EvntShpIsotropy ); theTree->SetBranchAddress( "Trigweight", &Trigweight ); theTree->SetBranchAddress( "B2011PUweight", &B2011PUweight ); theTree->SetBranchAddress( "btag2CSF", &btag2CSF ); theTree->SetBranchAddress( "MET", &MET ); theTree->SetBranchAddress( "eventFlavor", &eventFlavor ); // Efficiency calculator for cut method Int_t nSelCutsGA = 0; Double_t effS = 0.7; TTree* TMVATree = (TTree*)input->Get("TMVA_tree"); int NumInTree = theTree->GetEntries(); int NumberTMVAtree = TMVATree->GetEntries(); ZJetsToLL_weight = ZJetsToLL_weight* ( NumInTree /float(NumberTMVAtree)) ; std::vector<Float_t> vecVar(4); // vector for EvaluateMVA tests std::cout << "--- Processing: " << theTree->GetEntries() << " events" << std::endl; TStopwatch sw; sw.Start(); for (Long64_t ievt=0; ievt<NumInTree;ievt++) { if (ievt%1000 == 0) std::cout << "--- ... Processing event: " << ievt << std::endl; theTree->GetEntry(ievt); // var1 = userVar1 + userVar2; // var2 = userVar1 - userVar2; // --- Return the MVA outputs and fill into histograms if (Use["CutsGA"]) { // Cuts is a special case: give the desired signal efficienciy Bool_t passed = reader->EvaluateMVA( "CutsGA method", effS ); if (passed) nSelCutsGA++; } if (Use["Likelihood" ]) histLk ->Fill( reader->EvaluateMVA( "Likelihood method" ) ); if (Use["LikelihoodD" ]) histLkD ->Fill( reader->EvaluateMVA( "LikelihoodD method" ) ); if (Use["LikelihoodPCA"]) histLkPCA ->Fill( reader->EvaluateMVA( "LikelihoodPCA method" ) ); if (Use["LikelihoodKDE"]) histLkKDE ->Fill( reader->EvaluateMVA( "LikelihoodKDE method" ) ); if (Use["LikelihoodMIX"]) histLkMIX ->Fill( reader->EvaluateMVA( "LikelihoodMIX method" ) ); if (Use["PDERS" ]) histPD ->Fill( reader->EvaluateMVA( "PDERS method" ) ); if (Use["PDERSD" ]) histPDD ->Fill( reader->EvaluateMVA( "PDERSD method" ) ); if (Use["PDERSPCA" ]) histPDPCA ->Fill( reader->EvaluateMVA( "PDERSPCA method" ) ); if (Use["KNN" ]) histKNN ->Fill( reader->EvaluateMVA( "KNN method" ) ); if (Use["HMatrix" ]) histHm ->Fill( reader->EvaluateMVA( "HMatrix method" ) ); if (Use["Fisher" ]) histFi ->Fill( reader->EvaluateMVA( "Fisher method" ) ); if (Use["FisherG" ]) histFiG ->Fill( reader->EvaluateMVA( "FisherG method" ) ); if (Use["BoostedFisher"]) histFiB ->Fill( reader->EvaluateMVA( "BoostedFisher method" ) ); if (Use["LD" ]) histLD ->Fill( reader->EvaluateMVA( "LD method" ) ); if (Use["MLP" ]) histNn ->Fill( reader->EvaluateMVA( "MLP method" ) ); if (Use["MLPBFGS" ]) histNnbfgs ->Fill( reader->EvaluateMVA( "MLPBFGS method" ) ); if (Use["MLPBNN" ]) histNnbnn ->Fill( reader->EvaluateMVA( "MLPBNN method" ) ); if (Use["CFMlpANN" ]) histNnC ->Fill( reader->EvaluateMVA( "CFMlpANN method" ) ); if (Use["TMlpANN" ]) histNnT ->Fill( reader->EvaluateMVA( "TMlpANN method" ) ); if (Use["BDT" ]) { BDTvalue = reader->EvaluateMVA( "BDT method" ); } if (Use["BDTD" ]) histBdtD ->Fill( reader->EvaluateMVA( "BDTD method" ) ); if (Use["BDTG" ]) histBdtG ->Fill( reader->EvaluateMVA( "BDTG method" ) ); if (Use["RuleFit" ]) histRf ->Fill( reader->EvaluateMVA( "RuleFit method" ) ); if (Use["SVM_Gauss" ]) histSVMG ->Fill( reader->EvaluateMVA( "SVM_Gauss method" ) ); if (Use["SVM_Poly" ]) histSVMP ->Fill( reader->EvaluateMVA( "SVM_Poly method" ) ); if (Use["SVM_Lin" ]) histSVML ->Fill( reader->EvaluateMVA( "SVM_Lin method" ) ); if (Use["FDA_MT" ]) histFDAMT ->Fill( reader->EvaluateMVA( "FDA_MT method" ) ); if (Use["FDA_GA" ]) histFDAGA ->Fill( reader->EvaluateMVA( "FDA_GA method" ) ); if (Use["Category" ]) histCat ->Fill( reader->EvaluateMVA( "Category method" ) ); if (Use["Plugin" ]) histPBdt ->Fill( reader->EvaluateMVA( "P_BDT method" ) ); // Retrieve also per-event error if (Use["PDEFoam"]) { Double_t val = reader->EvaluateMVA( "PDEFoam method" ); Double_t err = reader->GetMVAError(); histPDEFoam ->Fill( val ); histPDEFoamErr->Fill( err ); if (err>1.e-50) histPDEFoamSig->Fill( val/err ); } // Retrieve probability instead of MVA output if (Use["Fisher"]) { probHistFi ->Fill( reader->GetProba ( "Fisher method" ) ); rarityHistFi->Fill( reader->GetRarity( "Fisher method" ) ); } // std::cout << "Ht is "<< Ht << endl; if (eventFlavor == 5 ) { histMattBdt ->Fill( BDTvalue,ZJetsToLL_weight ); histTMVABdt ->Fill( BDTvalue,ZJetsToLL_weight ); hMjj_OpenSelection->Fill(Hmass,ZJetsToLL_weight); hMmumu_OpenSelection->Fill(Zmass,ZJetsToLL_weight); hPtjj_OpenSelection->Fill(Hpt,ZJetsToLL_weight); hPtmumu_OpenSelection->Fill(Zpt,ZJetsToLL_weight); hCSV0_OpenSelection->Fill(CSV0,ZJetsToLL_weight); hCSV1_OpenSelection->Fill(CSV1,ZJetsToLL_weight); hdphiVH_OpenSelection->Fill(DeltaPhiHV,ZJetsToLL_weight); hdetaJJ_OpenSelection->Fill(DetaJJ,ZJetsToLL_weight); hUnweightedEta_OpenSelection->Fill(UnweightedEta,ZJetsToLL_weight); hPtmu0_OpenSelection->Fill(mu0pt,ZJetsToLL_weight); hHt_OpenSelection->Fill(Ht,ZJetsToLL_weight); hCircularity_OpenSelection->Fill(EvntShpCircularity,ZJetsToLL_weight); hCHFb0_OpenSelection->Fill(jetCHF0, ZJetsToLL_weight); hCHFb1_OpenSelection->Fill(jetCHF1, ZJetsToLL_weight); hPtbalZH_OpenSelection->Fill(PtbalZH, ZJetsToLL_weight); hPtmu1_OpenSelection->Fill(mu1pt, ZJetsToLL_weight); hPFRelIsomu0_OpenSelection->Fill(muonPFiso0, ZJetsToLL_weight); hPFRelIsomu1_OpenSelection->Fill(muonPFiso1, ZJetsToLL_weight); hNjets_OpenSelection->Fill(nJets, ZJetsToLL_weight); hRMSeta_OpenSelection->Fill(RMS_eta, ZJetsToLL_weight); hStaDeveta_OpenSelection->Fill(EtaStandDev, ZJetsToLL_weight); hdphiJJ_vect_OpenSelection->Fill(DphiJJ, ZJetsToLL_weight); hCentrality_OpenSelection->Fill(Centrality, ZJetsToLL_weight); hEventPt_OpenSelection->Fill(EventPt, ZJetsToLL_weight); hAngle_OpenSelection->Fill(Angle, ZJetsToLL_weight); hSphericity_OpenSelection->Fill(EvntShpSphericity, ZJetsToLL_weight); hAplanarity_OpenSelection->Fill(EvntShpAplanarity, ZJetsToLL_weight); hIsotropy_OpenSelection->Fill(EvntShpIsotropy, ZJetsToLL_weight); hDphiDetajj_OpenSelection->Fill(DphiJJ, DetaJJ, ZJetsToLL_weight); }//only fill if b quark treeWithBDT->Fill(); }//end event loop // Get elapsed time sw.Stop(); std::cout << "--- End of event loop: "; sw.Print(); // Get efficiency for cuts classifier if (Use["CutsGA"]) std::cout << "--- Efficiency for CutsGA method: " << double(nSelCutsGA)/theTree->GetEntries() << " (for a required signal efficiency of " << effS << ")" << std::endl; if (Use["CutsGA"]) { // test: retrieve cuts for particular signal efficiency // CINT ignores dynamic_casts so we have to use a cuts-secific Reader function to acces the pointer TMVA::MethodCuts* mcuts = reader->FindCutsMVA( "CutsGA method" ) ; if (mcuts) { std::vector<Double_t> cutsMin; std::vector<Double_t> cutsMax; mcuts->GetCuts( 0.7, cutsMin, cutsMax ); std::cout << "--- -------------------------------------------------------------" << std::endl; std::cout << "--- Retrieve cut values for signal efficiency of 0.7 from Reader" << std::endl; for (UInt_t ivar=0; ivar<cutsMin.size(); ivar++) { std::cout << "... Cut: " << cutsMin[ivar] << " < \"" << mcuts->GetInputVar(ivar) << "\" <= " << cutsMax[ivar] << std::endl; } std::cout << "--- -------------------------------------------------------------" << std::endl; } } // --- Write histograms TFile *target = new TFile( "TMVApp_ZJetsToLL.root","RECREATE" ); if (Use["Likelihood" ]) histLk ->Write(); if (Use["LikelihoodD" ]) histLkD ->Write(); if (Use["LikelihoodPCA"]) histLkPCA ->Write(); if (Use["LikelihoodKDE"]) histLkKDE ->Write(); if (Use["LikelihoodMIX"]) histLkMIX ->Write(); if (Use["PDERS" ]) histPD ->Write(); if (Use["PDERSD" ]) histPDD ->Write(); if (Use["PDERSPCA" ]) histPDPCA ->Write(); if (Use["KNN" ]) histKNN ->Write(); if (Use["HMatrix" ]) histHm ->Write(); if (Use["Fisher" ]) histFi ->Write(); if (Use["FisherG" ]) histFiG ->Write(); if (Use["BoostedFisher"]) histFiB ->Write(); if (Use["LD" ]) histLD ->Write(); if (Use["MLP" ]) histNn ->Write(); if (Use["MLPBFGS" ]) histNnbfgs ->Write(); if (Use["MLPBNN" ]) histNnbnn ->Write(); if (Use["CFMlpANN" ]) histNnC ->Write(); if (Use["TMlpANN" ]) histNnT ->Write(); if (Use["BDT" ]) { histMattBdt ->Write(); histTMVABdt ->Write(); } if (Use["BDTD" ]) histBdtD ->Write(); if (Use["BDTG" ]) histBdtG ->Write(); if (Use["RuleFit" ]) histRf ->Write(); if (Use["SVM_Gauss" ]) histSVMG ->Write(); if (Use["SVM_Poly" ]) histSVMP ->Write(); if (Use["SVM_Lin" ]) histSVML ->Write(); if (Use["FDA_MT" ]) histFDAMT ->Write(); if (Use["FDA_GA" ]) histFDAGA ->Write(); if (Use["Category" ]) histCat ->Write(); if (Use["Plugin" ]) histPBdt ->Write(); // Write also error and significance histos if (Use["PDEFoam"]) { histPDEFoam->Write(); histPDEFoamErr->Write(); histPDEFoamSig->Write(); } // Write also probability hists if (Use["Fisher"]) { if (probHistFi != 0) probHistFi->Write(); if (rarityHistFi != 0) rarityHistFi->Write(); } hCHFb0_OpenSelection->Write(); hCHFb1_OpenSelection->Write(); hPtbalZH_OpenSelection->Write(); hPtmu1_OpenSelection->Write(); hPFRelIsomu0_OpenSelection->Write(); hPFRelIsomu1_OpenSelection->Write(); hMjj_OpenSelection->Write(); hMmumu_OpenSelection->Write(); hPtjj_OpenSelection->Write(); hPtmumu_OpenSelection->Write(); hCSV0_OpenSelection->Write(); hCSV1_OpenSelection->Write(); hdphiVH_OpenSelection->Write(); hdetaJJ_OpenSelection->Write(); hUnweightedEta_OpenSelection->Write(); hPtmu0_OpenSelection->Write(); hCircularity_OpenSelection->Write(); hHt_OpenSelection->Write(); hNjets_OpenSelection->Write(); hRMSeta_OpenSelection->Write(); hStaDeveta_OpenSelection->Write(); hdphiJJ_vect_OpenSelection->Write(); hCentrality_OpenSelection->Write(); hEventPt_OpenSelection->Write(); hAngle_OpenSelection->Write(); hSphericity_OpenSelection->Write(); hAplanarity_OpenSelection->Write(); hIsotropy_OpenSelection->Write(); hDphiDetajj_OpenSelection->Write(); treeWithBDT->Write(); target->Close(); delete reader; hCHFb0_OpenSelection->Delete(); hCHFb1_OpenSelection->Delete(); hPtbalZH_OpenSelection->Delete(); hPtmu1_OpenSelection->Delete(); hPFRelIsomu0_OpenSelection->Delete(); hPFRelIsomu1_OpenSelection->Delete(); hMjj_OpenSelection->Delete(); hMmumu_OpenSelection->Delete(); hPtjj_OpenSelection->Delete(); hPtmumu_OpenSelection->Delete(); hCSV0_OpenSelection->Delete(); hCSV1_OpenSelection->Delete(); hdphiVH_OpenSelection->Delete(); hdetaJJ_OpenSelection->Delete(); hUnweightedEta_OpenSelection->Delete(); hPtmu0_OpenSelection->Delete(); hCircularity_OpenSelection->Delete(); hHt_OpenSelection->Delete(); hNjets_OpenSelection->Delete(); hRMSeta_OpenSelection->Delete(); hStaDeveta_OpenSelection->Delete(); hdphiJJ_vect_OpenSelection->Delete(); hCentrality_OpenSelection->Delete(); hEventPt_OpenSelection->Delete(); hAngle_OpenSelection->Delete(); hSphericity_OpenSelection->Delete(); hAplanarity_OpenSelection->Delete(); hIsotropy_OpenSelection->Delete(); hDphiDetajj_OpenSelection->Delete(); treeWithBDT->Delete(); if (Use["BDT" ]) { histMattBdt ->Delete(); histTMVABdt ->Delete(); } std::cout << "==> ZJetsToLL_App is done!" << endl << std::endl; gROOT->ProcessLine(".q"); }
void selectZee(const TString conf="zee.conf", // input file const TString outputDir=".", // output directory const Bool_t doScaleCorr=0 // apply energy scale corrections? ) { gBenchmark->Start("selectZee"); //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== const Double_t MASS_LOW = 40; const Double_t MASS_HIGH = 200; const Double_t PT_CUT = 22; const Double_t ETA_CUT = 2.5; const Double_t ELE_MASS = 0.000511; const Double_t ECAL_GAP_LOW = 1.4442; const Double_t ECAL_GAP_HIGH = 1.566; const Double_t escaleNbins = 2; const Double_t escaleEta[] = { 1.4442, 2.5 }; const Double_t escaleCorr[] = { 0.992, 1.009 }; const Int_t BOSON_ID = 23; const Int_t LEPTON_ID = 11; // load trigger menu const baconhep::TTrigger triggerMenu("../../BaconAna/DataFormats/data/HLT_50nsGRun"); // load pileup reweighting file TFile *f_rw = TFile::Open("../Tools/pileup_rw_baconDY.root", "read"); // for systematics we need 3 TH1D *h_rw = (TH1D*) f_rw->Get("h_rw_golden"); TH1D *h_rw_up = (TH1D*) f_rw->Get("h_rw_up_golden"); TH1D *h_rw_down = (TH1D*) f_rw->Get("h_rw_down_golden"); if (h_rw==NULL) cout<<"WARNIG h_rw == NULL"<<endl; if (h_rw_up==NULL) cout<<"WARNIG h_rw == NULL"<<endl; if (h_rw_down==NULL) cout<<"WARNIG h_rw == NULL"<<endl; //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== enum { eEleEle2HLT=1, eEleEle1HLT1L1, eEleEle1HLT, eEleEleNoSel, eEleSC }; // event category enum vector<TString> snamev; // sample name (for output files) vector<CSample*> samplev; // data/MC samples // // parse .conf file // confParse(conf, snamev, samplev); const Bool_t hasData = (samplev[0]->fnamev.size()>0); // Create output directory gSystem->mkdir(outputDir,kTRUE); const TString ntupDir = outputDir + TString("/ntuples"); gSystem->mkdir(ntupDir,kTRUE); // // Declare output ntuple variables // UInt_t runNum, lumiSec, evtNum; UInt_t matchGen; UInt_t category; UInt_t npv, npu; UInt_t id_1, id_2; Double_t x_1, x_2, xPDF_1, xPDF_2; Double_t scalePDF, weightPDF; TLorentzVector *genV=0; Float_t genVPt, genVPhi, genVy, genVMass; Float_t genWeight, PUWeight; Float_t scale1fb,scale1fbUp,scale1fbDown; Float_t met, metPhi, sumEt, u1, u2; Float_t tkMet, tkMetPhi, tkSumEt, tkU1, tkU2; Float_t mvaMet, mvaMetPhi, mvaSumEt, mvaU1, mvaU2; Float_t puppiMet, puppiMetPhi, puppiSumEt, puppiU1, puppiU2; Int_t q1, q2; TLorentzVector *dilep=0, *lep1=0, *lep2=0; ///// electron specific ///// Float_t trkIso1, emIso1, hadIso1, trkIso2, emIso2, hadIso2; Float_t pfChIso1, pfGamIso1, pfNeuIso1, pfCombIso1, pfChIso2, pfGamIso2, pfNeuIso2, pfCombIso2; Float_t sigieie1, hovere1, eoverp1, fbrem1, ecalE1, sigieie2, hovere2, eoverp2, fbrem2, ecalE2; Float_t dphi1, deta1, dphi2, deta2; Float_t d01, dz1, d02, dz2; Float_t r91,r92; UInt_t isConv1, nexphits1, typeBits1, isConv2, nexphits2, typeBits2; TLorentzVector *sc1=0, *sc2=0; // Data structures to store info from TTrees baconhep::TEventInfo *info = new baconhep::TEventInfo(); baconhep::TGenEventInfo *gen = new baconhep::TGenEventInfo(); TClonesArray *genPartArr = new TClonesArray("baconhep::TGenParticle"); TClonesArray *electronArr = new TClonesArray("baconhep::TElectron"); TClonesArray *scArr = new TClonesArray("baconhep::TPhoton"); TClonesArray *vertexArr = new TClonesArray("baconhep::TVertex"); TFile *infile=0; TTree *eventTree=0; // // loop over samples // for(UInt_t isam=0; isam<samplev.size(); isam++) { // Assume data sample is first sample in .conf file // If sample is empty (i.e. contains no ntuple files), skip to next sample Bool_t isData=kFALSE; if(isam==0 && !hasData) continue; else if (isam==0) isData=kTRUE; // Assume signal sample is given name "zee" - flag to store GEN Z kinematics Bool_t isSignal = (snamev[isam].CompareTo("zee",TString::kIgnoreCase)==0); // flag to reject Z->ee events when selecting at wrong-flavor background events Bool_t isWrongFlavor = (snamev[isam].CompareTo("zxx",TString::kIgnoreCase)==0); CSample* samp = samplev[isam]; // // Set up output ntuple // TString outfilename = ntupDir + TString("/") + snamev[isam] + TString("_select.root"); if(isam!=0 && !doScaleCorr) outfilename = ntupDir + TString("/") + snamev[isam] + TString("_select.raw.root"); TFile *outFile = new TFile(outfilename,"RECREATE"); TTree *outTree = new TTree("Events","Events"); outTree->Branch("runNum", &runNum, "runNum/i"); // event run number outTree->Branch("lumiSec", &lumiSec, "lumiSec/i"); // event lumi section outTree->Branch("evtNum", &evtNum, "evtNum/i"); // event number outTree->Branch("matchGen", &matchGen, "matchGen/i"); // event has both leptons matched to MC Z->ll outTree->Branch("category", &category, "category/i"); // dilepton category outTree->Branch("id_1", &id_1, "id_1/i"); // PDF info -- parton ID for parton 1 outTree->Branch("id_2", &id_2, "id_2/i"); // PDF info -- parton ID for parton 2 outTree->Branch("x_1", &x_1, "x_1/d"); // PDF info -- x for parton 1 outTree->Branch("x_2", &x_2, "x_2/d"); // PDF info -- x for parton 2 outTree->Branch("xPDF_1", &xPDF_1, "xPDF_1/d"); // PDF info -- x*F for parton 1 outTree->Branch("xPDF_2", &xPDF_2, "xPDF_2/d"); // PDF info -- x*F for parton 2 outTree->Branch("scalePDF", &scalePDF, "scalePDF/d"); // PDF info -- energy scale of parton interaction outTree->Branch("weightPDF", &weightPDF, "weightPDF/d"); // PDF info -- PDF weight outTree->Branch("npv", &npv, "npv/i"); // number of primary vertices outTree->Branch("npu", &npu, "npu/i"); // number of in-time PU events (MC) outTree->Branch("genV", "TLorentzVector", &genV); // GEN boson 4-vector outTree->Branch("genVPt", &genVPt, "genVPt/F"); // GEN boson pT (signal MC) outTree->Branch("genVPhi", &genVPhi, "genVPhi/F"); // GEN boson phi (signal MC) outTree->Branch("genVy", &genVy, "genVy/F"); // GEN boson rapidity (signal MC) outTree->Branch("genVMass", &genVMass, "genVMass/F"); // GEN boson mass (signal MC) outTree->Branch("genWeight", &genWeight, "genWeight/F"); outTree->Branch("PUWeight", &PUWeight, "PUWeight/F"); outTree->Branch("scale1fb", &scale1fb, "scale1fb/F"); // event weight per 1/fb (MC) outTree->Branch("scale1fbUp", &scale1fbUp, "scale1fbUp/F"); // event weight per 1/fb (MC) outTree->Branch("scale1fbDown", &scale1fbDown, "scale1fbDown/F"); // event weight per 1/fb (MC) outTree->Branch("met", &met, "met/F"); // MET outTree->Branch("metPhi", &metPhi, "metPhi/F"); // phi(MET) outTree->Branch("sumEt", &sumEt, "sumEt/F"); // Sum ET outTree->Branch("u1", &u1, "u1/F"); // parallel component of recoil outTree->Branch("u2", &u2, "u2/F"); // perpendicular component of recoil outTree->Branch("tkMet", &tkMet, "tkMet/F"); // MET (track MET) outTree->Branch("tkMetPhi", &tkMetPhi, "tkMetPhi/F"); // phi(MET) (track MET) outTree->Branch("tkSumEt", &tkSumEt, "tkSumEt/F"); // Sum ET (track MET) outTree->Branch("tkU1", &tkU1, "tkU1/F"); // parallel component of recoil (track MET) outTree->Branch("tkU2", &tkU2, "tkU2/F"); // perpendicular component of recoil (track MET) outTree->Branch("mvaMet", &mvaMet, "mvaMet/F"); // MVA MET outTree->Branch("mvaMetPhi", &mvaMetPhi, "mvaMetPhi/F"); // phi(MVA MET) outTree->Branch("mvaSumEt", &mvaSumEt, "mvaSumEt/F"); // Sum ET (mva MET) outTree->Branch("mvaU1", &mvaU1, "mvaU1/F"); // parallel component of recoil (mva MET) outTree->Branch("mvaU2", &mvaU2, "mvaU2/F"); // perpendicular component of recoil (mva MET) outTree->Branch("puppiMet", &puppiMet, "puppiMet/F"); // Puppi MET outTree->Branch("puppiMetPhi", &puppiMetPhi,"puppiMetPhi/F"); // phi(Puppi MET) outTree->Branch("puppiSumEt", &puppiSumEt, "puppiSumEt/F"); // Sum ET (Puppi MET) outTree->Branch("puppiU1", &puppiU1, "puppiU1/F"); // parallel component of recoil (Puppi MET) outTree->Branch("puppiU2", &puppiU2, "puppiU2/F"); // perpendicular component of recoil (Puppi MET) outTree->Branch("q1", &q1, "q1/I"); // charge of tag lepton outTree->Branch("q2", &q2, "q2/I"); // charge of probe lepton outTree->Branch("dilep", "TLorentzVector", &dilep); // di-lepton 4-vector outTree->Branch("lep1", "TLorentzVector", &lep1); // tag lepton 4-vector outTree->Branch("lep2", "TLorentzVector", &lep2); // probe lepton 4-vector ///// electron specific ///// outTree->Branch("trkIso1", &trkIso1, "trkIso1/F"); // track isolation of tag lepton outTree->Branch("trkIso2", &trkIso2, "trkIso2/F"); // track isolation of probe lepton outTree->Branch("emIso1", &emIso1, "emIso1/F"); // ECAL isolation of tag lepton outTree->Branch("emIso2", &emIso2, "emIso2/F"); // ECAL isolation of probe lepton outTree->Branch("hadIso1", &hadIso1, "hadIso1/F"); // HCAL isolation of tag lepton outTree->Branch("hadIso2", &hadIso2, "hadIso2/F"); // HCAL isolation of probe lepton outTree->Branch("pfChIso1", &pfChIso1, "pfChIso1/F"); // PF charged hadron isolation of tag lepton outTree->Branch("pfChIso2", &pfChIso2, "pfChIso2/F"); // PF charged hadron isolation of probe lepton outTree->Branch("pfGamIso1", &pfGamIso1, "pfGamIso1/F"); // PF photon isolation of tag lepton outTree->Branch("pfGamIso2", &pfGamIso2, "pfGamIso2/F"); // PF photon isolation of probe lepton outTree->Branch("pfNeuIso1", &pfNeuIso1, "pfNeuIso1/F"); // PF neutral hadron isolation of tag lepton outTree->Branch("pfNeuIso2", &pfNeuIso2, "pfNeuIso2/F"); // PF neutral hadron isolation of probe lepton outTree->Branch("pfCombIso1", &pfCombIso1, "pfCombIso1/F"); // PF combine isolation of tag lepton outTree->Branch("pfCombIso2", &pfCombIso2, "pfCombIso2/F"); // PF combined isolation of probe lepton outTree->Branch("sigieie1", &sigieie1, "sigieie1/F"); // sigma-ieta-ieta of tag outTree->Branch("sigieie2", &sigieie2, "sigieie2/F"); // sigma-ieta-ieta of probe outTree->Branch("hovere1", &hovere1, "hovere1/F"); // H/E of tag outTree->Branch("hovere2", &hovere2, "hovere2/F"); // H/E of probe outTree->Branch("eoverp1", &eoverp1, "eoverp1/F"); // E/p of tag outTree->Branch("eoverp2", &eoverp2, "eoverp2/F"); // E/p of probe outTree->Branch("fbrem1", &fbrem1, "fbrem1/F"); // brem fraction of tag outTree->Branch("fbrem2", &fbrem2, "fbrem2/F"); // brem fraction of probe outTree->Branch("dphi1", &dphi1, "dphi1/F"); // GSF track - ECAL dphi of tag outTree->Branch("dphi2", &dphi2, "dphi2/F"); // GSF track - ECAL dphi of probe outTree->Branch("deta1", &deta1, "deta1/F"); // GSF track - ECAL deta of tag outTree->Branch("deta2", &deta2, "deta2/F"); // GSF track - ECAL deta of probe outTree->Branch("ecalE1", &ecalE1, "ecalE1/F"); // ECAL energy of tag outTree->Branch("ecalE2", &ecalE2, "ecalE2/F"); // ECAL energy of probe outTree->Branch("d01", &d01, "d01/F"); // transverse impact parameter of tag outTree->Branch("d02", &d02, "d02/F"); // transverse impact parameter of probe outTree->Branch("dz1", &dz1, "dz1/F"); // longitudinal impact parameter of tag outTree->Branch("dz2", &dz2, "dz2/F"); // longitudinal impact parameter of probe outTree->Branch("isConv1", &isConv1, "isConv1/i"); // conversion filter flag of tag lepton outTree->Branch("isConv2", &isConv2, "isConv2/i"); // conversion filter flag of probe lepton outTree->Branch("nexphits1", &nexphits1, "nexphits1/i"); // number of missing expected inner hits of tag lepton outTree->Branch("nexphits2", &nexphits2, "nexphits2/i"); // number of missing expected inner hits of probe lepton outTree->Branch("typeBits1", &typeBits1, "typeBits1/i"); // electron type of tag lepton outTree->Branch("typeBits2", &typeBits2, "typeBits2/i"); // electron type of probe lepton outTree->Branch("sc1", "TLorentzVector", &sc1); // tag supercluster 4-vector outTree->Branch("sc2", "TLorentzVector", &sc2); // probe supercluster 4-vector outTree->Branch("r91", &r91, "r91/F"); // transverse impact parameter of tag outTree->Branch("r92", &r92, "r92/F"); // transverse impact parameter of probe // // loop through files // const UInt_t nfiles = samp->fnamev.size(); for(UInt_t ifile=0; ifile<nfiles; ifile++) { // Read input file and get the TTrees cout << "Processing " << samp->fnamev[ifile] << " [xsec = " << samp->xsecv[ifile] << " pb] ... " << endl; cout.flush(); infile = TFile::Open(samp->fnamev[ifile]); assert(infile); Bool_t hasJSON = kFALSE; baconhep::RunLumiRangeMap rlrm; if(samp->jsonv[ifile].CompareTo("NONE")!=0) { hasJSON = kTRUE; rlrm.addJSONFile(samp->jsonv[ifile].Data()); } eventTree = (TTree*)infile->Get("Events"); assert(eventTree); eventTree->SetBranchAddress("Info", &info); TBranch *infoBr = eventTree->GetBranch("Info"); eventTree->SetBranchAddress("Electron", &electronArr); TBranch *electronBr = eventTree->GetBranch("Electron"); eventTree->SetBranchAddress("Photon", &scArr); TBranch *scBr = eventTree->GetBranch("Photon"); eventTree->SetBranchAddress("PV", &vertexArr); TBranch *vertexBr = eventTree->GetBranch("PV"); Bool_t hasGen = eventTree->GetBranchStatus("GenEvtInfo"); TBranch *genBr=0, *genPartBr=0; if(hasGen) { eventTree->SetBranchAddress("GenEvtInfo", &gen); genBr = eventTree->GetBranch("GenEvtInfo"); eventTree->SetBranchAddress("GenParticle",&genPartArr); genPartBr = eventTree->GetBranch("GenParticle"); } // Compute MC event weight per 1/fb const Double_t xsec = samp->xsecv[ifile]; Double_t totalWeight=0; Double_t totalWeightUp=0; Double_t totalWeightDown=0; Double_t puWeight=0; Double_t puWeightUp=0; Double_t puWeightDown=0; if (hasGen) { for(UInt_t ientry=0; ientry<eventTree->GetEntries(); ientry++) { infoBr->GetEntry(ientry); genBr->GetEntry(ientry); puWeight = h_rw->GetBinContent(h_rw->FindBin(info->nPUmean)); puWeightUp = h_rw_up->GetBinContent(h_rw_up->FindBin(info->nPUmean)); puWeightDown = h_rw_down->GetBinContent(h_rw_down->FindBin(info->nPUmean)); totalWeight+=gen->weight*puWeight; totalWeightUp+=gen->weight*puWeightUp; totalWeightDown+=gen->weight*puWeightDown; } } else if (not isData){ for(UInt_t ientry=0; ientry<eventTree->GetEntries(); ientry++) { puWeight = h_rw->GetBinContent(h_rw->FindBin(info->nPUmean)); puWeightUp = h_rw_up->GetBinContent(h_rw_up->FindBin(info->nPUmean)); puWeightDown = h_rw_down->GetBinContent(h_rw_down->FindBin(info->nPUmean)); totalWeight+= 1.0*puWeight; totalWeightUp+= 1.0*puWeightUp; totalWeightDown+= 1.0*puWeightDown; } } // // loop over events // Double_t nsel=0, nselvar=0; for(UInt_t ientry=0; ientry<eventTree->GetEntries(); ientry++) { infoBr->GetEntry(ientry); if(ientry%1000000==0) cout << "Processing event " << ientry << ". " << (double)ientry/(double)eventTree->GetEntries()*100 << " percent done with this file." << endl; Double_t weight=1; Double_t weightUp=1; Double_t weightDown=1; if(xsec>0 && totalWeight>0) weight = xsec/totalWeight; if(xsec>0 && totalWeightUp>0) weightUp = xsec/totalWeightUp; if(xsec>0 && totalWeightDown>0) weightDown = xsec/totalWeightDown; if(hasGen) { genPartArr->Clear(); genBr->GetEntry(ientry); genPartBr->GetEntry(ientry); puWeight = h_rw->GetBinContent(h_rw->FindBin(info->nPUmean)); puWeightUp = h_rw_up->GetBinContent(h_rw_up->FindBin(info->nPUmean)); puWeightDown = h_rw_down->GetBinContent(h_rw_down->FindBin(info->nPUmean)); weight*=gen->weight*puWeight; weightUp*=gen->weight*puWeightUp; weightDown*=gen->weight*puWeightDown; } // veto z -> xx decays for signal and z -> ee for bacground samples (needed for inclusive DYToLL sample) if (isWrongFlavor && hasGen && fabs(toolbox::flavor(genPartArr, BOSON_ID))==LEPTON_ID) continue; else if (isSignal && hasGen && fabs(toolbox::flavor(genPartArr, BOSON_ID))!=LEPTON_ID) continue; // check for certified lumi (if applicable) baconhep::RunLumiRangeMap::RunLumiPairType rl(info->runNum, info->lumiSec); if(hasJSON && !rlrm.hasRunLumi(rl)) continue; // trigger requirement if (!isEleTrigger(triggerMenu, info->triggerBits, isData)) continue; // good vertex requirement if(!(info->hasGoodPV)) continue; electronArr->Clear(); electronBr->GetEntry(ientry); scArr->Clear(); scBr->GetEntry(ientry); TLorentzVector vTag(0,0,0,0); TLorentzVector vTagSC(0,0,0,0); Double_t tagPt=0; Double_t Pt1=0; Double_t Pt2=0; Int_t itag=-1; Int_t tagscID=-1; for(Int_t i1=0; i1<electronArr->GetEntriesFast(); i1++) { const baconhep::TElectron *tag = (baconhep::TElectron*)((*electronArr)[i1]); // check ECAL gap if(fabs(tag->scEta)>=ECAL_GAP_LOW && fabs(tag->scEta)<=ECAL_GAP_HIGH) continue; // apply scale and resolution corrections to MC Double_t tagscEt_corr = tag->scEt; if(doScaleCorr && snamev[isam].CompareTo("data",TString::kIgnoreCase)!=0) tagscEt_corr = gRandom->Gaus(tag->scEt*getEleScaleCorr(tag->scEta,0),getEleResCorr(tag->scEta,0)); if(tagscEt_corr < PT_CUT) continue; // lepton pT cut if(fabs(tag->scEta) > ETA_CUT) continue; // lepton |eta| cut if(!passEleID(tag,info->rhoIso)) continue; // lepton selection double El_Pt=0; if(doScaleCorr) { El_Pt=gRandom->Gaus(tag->pt*getEleScaleCorr(tag->scEta,0),getEleResCorr(tag->scEta,0)); } else { El_Pt=tag->pt; } if(El_Pt>Pt1) { Pt2=Pt1; Pt1=El_Pt; } else if(El_Pt>Pt2&&El_Pt<Pt1) { Pt2=El_Pt; } if(!isEleTriggerObj(triggerMenu, tag->hltMatchBits, kFALSE, isData)) continue; if(El_Pt<tagPt) continue; tagPt=El_Pt; itag=i1; tagscID=tag->scID; // apply scale and resolution corrections to MC if(doScaleCorr && snamev[isam].CompareTo("data",TString::kIgnoreCase)!=0) { vTag.SetPtEtaPhiM(El_Pt, tag->eta, tag->phi, ELE_MASS); vTagSC.SetPtEtaPhiM(tagscEt_corr, tag->scEta, tag->scPhi, ELE_MASS); } else { vTag.SetPtEtaPhiM(tag->pt, tag->eta, tag->phi, ELE_MASS); vTagSC.SetPtEtaPhiM(tag->scEt, tag->scEta, tag->scPhi, ELE_MASS); } trkIso1 = tag->trkIso; emIso1 = tag->ecalIso; hadIso1 = tag->hcalIso; pfChIso1 = tag->chHadIso; pfGamIso1 = tag->gammaIso; pfNeuIso1 = tag->neuHadIso; pfCombIso1 = tag->chHadIso + TMath::Max(tag->neuHadIso + tag->gammaIso - (info->rhoIso)*getEffAreaEl(tag->scEta), 0.); sigieie1 = tag->sieie; hovere1 = tag->hovere; eoverp1 = tag->eoverp; fbrem1 = tag->fbrem; dphi1 = tag->dPhiIn; deta1 = tag->dEtaIn; ecalE1 = tag->ecalEnergy; d01 = tag->d0; dz1 = tag->dz; isConv1 = tag->isConv; nexphits1 = tag->nMissingHits; typeBits1 = tag->typeBits; q1 = tag->q; r91 = tag->r9; } if(tagPt<Pt2) continue; TLorentzVector vProbe(0,0,0,0); TLorentzVector vProbeSC(0,0,0,0); Double_t probePt=0; Int_t iprobe=-1; Int_t passID=false; UInt_t icat=0; const baconhep::TElectron *eleProbe=0; for(Int_t j=0; j<scArr->GetEntriesFast(); j++) { const baconhep::TPhoton *scProbe = (baconhep::TPhoton*)((*scArr)[j]); if(scProbe->scID == tagscID) continue; // check ECAL gap if(fabs(scProbe->eta)>=ECAL_GAP_LOW && fabs(scProbe->eta)<=ECAL_GAP_HIGH) continue; // apply scale and resolution corrections to MC Double_t scProbept_corr = scProbe->pt; if(doScaleCorr && snamev[isam].CompareTo("data",TString::kIgnoreCase)!=0) scProbept_corr = gRandom->Gaus(scProbe->pt*getEleScaleCorr(scProbe->eta,0),getEleResCorr(scProbe->eta,0)); if(scProbept_corr < PT_CUT) continue; // Supercluster ET cut ("pt" = corrected by PV position) if(fabs(scProbe->eta) > ETA_CUT) continue; // Supercluster |eta| cuts for(Int_t i2=0; i2<electronArr->GetEntriesFast(); i2++) { if(itag==i2) continue; const baconhep::TElectron *ele = (baconhep::TElectron*)((*electronArr)[i2]); if(!(ele->typeBits & baconhep::EEleType::kEcalDriven)) continue; if(scProbe->scID==ele->scID) { eleProbe = ele; iprobe = i2; break; } } double El_Pt=0; if(doScaleCorr&&eleProbe) { El_Pt=gRandom->Gaus(eleProbe->pt*getEleScaleCorr(scProbe->eta,0),getEleResCorr(scProbe->eta,0)); } else if(!doScaleCorr&&eleProbe) { El_Pt=eleProbe->pt; } else { El_Pt=scProbept_corr; } if(passID&&eleProbe&&passEleID(eleProbe,info->rhoIso)&&El_Pt<probePt) continue; if(passID&&eleProbe&&!passEleID(eleProbe,info->rhoIso)) continue; if(passID&&!eleProbe) continue; if(!passID&&eleProbe&&!passEleID(eleProbe,info->rhoIso)&&El_Pt<probePt) continue; if(!passID&&!eleProbe&&El_Pt<probePt) continue; if(!passID&&eleProbe&&passEleID(eleProbe,info->rhoIso)) passID=true; probePt=El_Pt; // apply scale and resolution corrections to MC if(doScaleCorr && snamev[isam].CompareTo("data",TString::kIgnoreCase)!=0) { vProbe.SetPtEtaPhiM((eleProbe) ? gRandom->Gaus(eleProbe->pt*getEleScaleCorr(scProbe->eta,0),getEleResCorr(scProbe->eta,0)) : scProbept_corr, (eleProbe) ? eleProbe->eta : scProbe->eta, (eleProbe) ? eleProbe->phi : scProbe->phi, ELE_MASS); vProbeSC.SetPtEtaPhiM((eleProbe) ? gRandom->Gaus(eleProbe->scEt*getEleScaleCorr(scProbe->eta,0),getEleResCorr(scProbe->eta,0)) : gRandom->Gaus(scProbe->pt*getEleScaleCorr(scProbe->eta,0),getEleResCorr(scProbe->eta,0)), scProbe->eta, scProbe->phi, ELE_MASS); } else { vProbe.SetPtEtaPhiM((eleProbe) ? eleProbe->pt : scProbe->pt, (eleProbe) ? eleProbe->eta : scProbe->eta, (eleProbe) ? eleProbe->phi : scProbe->phi, ELE_MASS); vProbeSC.SetPtEtaPhiM((eleProbe) ? eleProbe->scEt : scProbe->pt, scProbe->eta, scProbe->phi, ELE_MASS); } trkIso2 = (eleProbe) ? eleProbe->trkIso : -1; emIso2 = (eleProbe) ? eleProbe->ecalIso : -1; hadIso2 = (eleProbe) ? eleProbe->hcalIso : -1; pfChIso2 = (eleProbe) ? eleProbe->chHadIso : -1; pfGamIso2 = (eleProbe) ? eleProbe->gammaIso : -1; pfNeuIso2 = (eleProbe) ? eleProbe->neuHadIso : -1; pfCombIso2 = (eleProbe) ? eleProbe->chHadIso + TMath::Max(eleProbe->neuHadIso + eleProbe->gammaIso - (info->rhoIso)*getEffAreaEl(eleProbe->scEta), 0.) : -1; sigieie2 = (eleProbe) ? eleProbe->sieie : scProbe->sieie; hovere2 = (eleProbe) ? eleProbe->hovere : scProbe->hovere; eoverp2 = (eleProbe) ? eleProbe->eoverp : -1; fbrem2 = (eleProbe) ? eleProbe->fbrem : -1; dphi2 = (eleProbe) ? eleProbe->dPhiIn : -999; deta2 = (eleProbe) ? eleProbe->dEtaIn : -999; ecalE2 = (eleProbe) ? eleProbe->ecalEnergy : -999; d02 = (eleProbe) ? eleProbe->d0 : -999; r92 = (eleProbe) ? eleProbe->r9 : -999; dz2 = (eleProbe) ? eleProbe->dz : -999; isConv2 = (eleProbe) ? eleProbe->isConv : 0; nexphits2 = (eleProbe) ? eleProbe->nMissingHits : 0; typeBits2 = (eleProbe) ? eleProbe->typeBits : 0; q2 = (eleProbe) ? eleProbe->q : -q1; // determine event category if(eleProbe) { if(passEleID(eleProbe,info->rhoIso)) { if(isEleTriggerObj(triggerMenu, eleProbe->hltMatchBits, kFALSE, isData)) { icat=eEleEle2HLT; } else if(isEleTriggerObj(triggerMenu, eleProbe->hltMatchBits, kTRUE, isData)) { icat=eEleEle1HLT1L1; } else { icat=eEleEle1HLT; } } else { icat=eEleEleNoSel; } } else { icat=eEleSC; } } if(q1 == q2) continue; // opposite charge requirement // mass window TLorentzVector vDilep = vTag + vProbe; if((vDilep.M()<MASS_LOW) || (vDilep.M()>MASS_HIGH)) continue; if(icat==0) continue; //******** We have a Z candidate! HURRAY! ******** nsel+=weight; nselvar+=weight*weight; // Perform matching of dileptons to GEN leptons from Z decay Int_t glepq1=-99; Int_t glepq2=-99; TLorentzVector *gvec=new TLorentzVector(0,0,0,0); TLorentzVector *glep1=new TLorentzVector(0,0,0,0); TLorentzVector *glep2=new TLorentzVector(0,0,0,0); TLorentzVector *gph=new TLorentzVector(0,0,0,0); Bool_t hasGenMatch = kFALSE; if(isSignal && hasGen) { toolbox::fillGen(genPartArr, BOSON_ID, gvec, glep1, glep2,&glepq1,&glepq2,1); Bool_t match1 = ( ((glep1) && toolbox::deltaR(vTag.Eta(), vTag.Phi(), glep1->Eta(), glep1->Phi())<0.3) || ((glep2) && toolbox::deltaR(vTag.Eta(), vTag.Phi(), glep2->Eta(), glep2->Phi())<0.3) ); Bool_t match2 = ( ((glep1) && toolbox::deltaR(vProbe.Eta(), vProbe.Phi(), glep1->Eta(), glep1->Phi())<0.3) || ((glep2) && toolbox::deltaR(vProbe.Eta(), vProbe.Phi(), glep2->Eta(), glep2->Phi())<0.3) ); if(match1 && match2) { hasGenMatch = kTRUE; if (gvec!=0) { genV=new TLorentzVector(0,0,0,0); genV->SetPtEtaPhiM(gvec->Pt(), gvec->Eta(), gvec->Phi(), gvec->M()); genVPt = gvec->Pt(); genVPhi = gvec->Phi(); genVy = gvec->Rapidity(); genVMass = gvec->M(); } else { TLorentzVector tvec=*glep1+*glep2; genV=new TLorentzVector(0,0,0,0); genV->SetPtEtaPhiM(tvec.Pt(), tvec.Eta(), tvec.Phi(), tvec.M()); genVPt = tvec.Pt(); genVPhi = tvec.Phi(); genVy = tvec.Rapidity(); genVMass = tvec.M(); } delete gvec; delete glep1; delete glep2; glep1=0; glep2=0; gvec=0; } else { genV = new TLorentzVector(0,0,0,0); genVPt = -999; genVPhi = -999; genVy = -999; genVMass = -999; } } if (hasGen) { id_1 = gen->id_1; id_2 = gen->id_2; x_1 = gen->x_1; x_2 = gen->x_2; xPDF_1 = gen->xPDF_1; xPDF_2 = gen->xPDF_2; scalePDF = gen->scalePDF; weightPDF = gen->weight; } else { id_1 = -999; id_2 = -999; x_1 = -999; x_2 = -999; xPDF_1 = -999; xPDF_2 = -999; scalePDF = -999; weightPDF = -999; } // // Fill tree // runNum = info->runNum; lumiSec = info->lumiSec; evtNum = info->evtNum; if (hasGenMatch) matchGen=1; else matchGen=0; category = icat; vertexArr->Clear(); vertexBr->GetEntry(ientry); npv = vertexArr->GetEntries(); npu = info->nPUmean; genWeight= hasGen ? gen->weight: 1.; PUWeight = puWeight; scale1fb = weight; scale1fbUp = weightUp; scale1fbDown = weightDown; met = info->pfMETC; metPhi = info->pfMETCphi; sumEt = 0; tkMet = info->trkMET; tkMetPhi = info->trkMETphi; tkSumEt = 0; mvaMet = info->mvaMET; mvaMetPhi = info->mvaMETphi; mvaSumEt = 0; TVector2 vZPt((vDilep.Pt())*cos(vDilep.Phi()),(vDilep.Pt())*sin(vDilep.Phi())); puppiMet = info->puppET; puppiMetPhi = info->puppETphi; puppiSumEt = 0; lep1 = &vTag; lep2 = &vProbe; dilep = &vDilep; sc1 = &vTagSC; sc2 = &vProbeSC; TVector2 vMet((info->pfMETC)*cos(info->pfMETCphi), (info->pfMETC)*sin(info->pfMETCphi)); TVector2 vU = -1.0*(vMet+vZPt); u1 = ((vDilep.Px())*(vU.Px()) + (vDilep.Py())*(vU.Py()))/(vDilep.Pt()); // u1 = (pT . u)/|pT| u2 = ((vDilep.Px())*(vU.Py()) - (vDilep.Py())*(vU.Px()))/(vDilep.Pt()); // u2 = (pT x u)/|pT| TVector2 vTkMet((info->trkMET)*cos(info->trkMETphi), (info->trkMET)*sin(info->trkMETphi)); TVector2 vTkU = -1.0*(vTkMet+vZPt); tkU1 = ((vDilep.Px())*(vTkU.Px()) + (vDilep.Py())*(vTkU.Py()))/(vDilep.Pt()); // u1 = (pT . u)/|pT| tkU2 = ((vDilep.Px())*(vTkU.Py()) - (vDilep.Py())*(vTkU.Px()))/(vDilep.Pt()); // u2 = (pT x u)/|pT| TVector2 vMvaMet((info->mvaMET)*cos(info->mvaMETphi), (info->mvaMET)*sin(info->mvaMETphi)); TVector2 vMvaU = -1.0*(vMvaMet+vZPt); mvaU1 = ((vDilep.Px())*(vMvaU.Px()) + (vDilep.Py())*(vMvaU.Py()))/(vDilep.Pt()); // u1 = (pT . u)/|pT| mvaU2 = ((vDilep.Px())*(vMvaU.Py()) - (vDilep.Py())*(vMvaU.Px()))/(vDilep.Pt()); // u2 = (pT x u)/|pT| TVector2 vPuppiMet((info->puppET)*cos(info->puppETphi), (info->puppET)*sin(info->puppETphi)); TVector2 vPuppiU = -1.0*(vPuppiMet+vZPt); puppiU1 = ((vDilep.Px())*(vPuppiU.Px()) + (vDilep.Py())*(vPuppiU.Py()))/(vDilep.Pt()); // u1 = (pT . u)/|pT| puppiU2 = ((vDilep.Px())*(vPuppiU.Py()) - (vDilep.Py())*(vPuppiU.Px()))/(vDilep.Pt()); // u2 = (pT x u)/|pT| outTree->Fill(); delete genV; genV=0, dilep=0, lep1=0, lep2=0, sc1=0, sc2=0; } delete infile; infile=0, eventTree=0; cout << nsel << " +/- " << sqrt(nselvar); if(!isData) cout << " per 1/fb"; cout << endl; } outFile->Write(); outFile->Close(); } delete h_rw; delete f_rw; delete info; delete gen; delete genPartArr; delete electronArr; delete scArr; delete vertexArr; //-------------------------------------------------------------------------------------------------------------- // Output //============================================================================================================== cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; cout << " Z -> e e" << endl; cout << " Mass window: [" << MASS_LOW << ", " << MASS_HIGH << "]" << endl; cout << " pT > " << PT_CUT << endl; cout << " |eta| < " << ETA_CUT << endl; cout << endl; cout << endl; cout << " <> Output saved in " << outputDir << "/" << endl; cout << endl; gBenchmark->Show("selectZee"); }
void AddDetectorEffects(TString infile,TString outfile) { InitExterns(); const int kMaxTrack = 10; // maximal number of particles in a single event. int evt = -999; int nPhoton = 0; float photonPt[kMaxTrack]; float photonEta[kMaxTrack]; float photonPhi[kMaxTrack]; int nElectron = 0; float electronPt[kMaxTrack]; float electronEta[kMaxTrack]; float electronPhi[kMaxTrack]; int electronQ[kMaxTrack]; int electronTag[kMaxTrack]; float electronCal02[kMaxTrack]; float electronCal03[kMaxTrack]; float electronCal04[kMaxTrack]; float electronTrk02[kMaxTrack]; float electronTrk03[kMaxTrack]; float electronTrk04[kMaxTrack]; float electronSign[kMaxTrack]; int nMuon = 0; float muonPt[kMaxTrack]; float muonEta[kMaxTrack]; float muonPhi[kMaxTrack]; int muonQ[kMaxTrack]; int muonTag[kMaxTrack]; float muonCal02[kMaxTrack]; float muonCal03[kMaxTrack]; float muonCal04[kMaxTrack]; float muonTrk02[kMaxTrack]; float muonTrk03[kMaxTrack]; float muonTrk04[kMaxTrack]; float muonSign[kMaxTrack]; int nTau = 0; float tauPt[kMaxTrack]; float tauEta[kMaxTrack]; float tauPhi[kMaxTrack]; int tauQ[kMaxTrack]; int tauTag[kMaxTrack]; float tauCal02[kMaxTrack]; float tauCal03[kMaxTrack]; float tauCal04[kMaxTrack]; float tauTrk02[kMaxTrack]; float tauTrk03[kMaxTrack]; float tauTrk04[kMaxTrack]; float tauSign[kMaxTrack]; int nJet = 0; float jetPt[kMaxTrack]; float jetEta[kMaxTrack]; float jetPhi[kMaxTrack]; int jetQ[kMaxTrack]; int jetTag[kMaxTrack]; float jetCal02[kMaxTrack]; float jetCal03[kMaxTrack]; float jetCal04[kMaxTrack]; float jetTrk02[kMaxTrack]; float jetTrk03[kMaxTrack]; float jetTrk04[kMaxTrack]; float metPt = -999.; float metEta = -999.; float metPhi = -999.; float sf_mu_reco_eff[kMaxTrack]; // scale factor muon reco efficiency float sf_el_reco_eff[kMaxTrack]; // scale factor electron reco efficiency TFile f(outfile,"recreate"); // the file and tree TTree *t = new TTree("t","Reconst ntuple"); // adding branches: // t->Branch(Branch name in the browser, pointer to the variable, variable name) t->Branch("evt",&evt,"evt/I"); t->Branch("nPhoton",&nPhoton,"nPhoton/I"); t->Branch("photonPt",photonPt,"photonPt[nPhoton]/F"); t->Branch("photonEta",photonEta,"photonEta[nPhoton]/F"); t->Branch("photonPhi",photonPhi,"photonPhi[nPhoton]/F"); t->Branch("nElectron",&nElectron,"nElectron/I"); t->Branch("electronPt",electronPt,"electronPt[nElectron]/F"); t->Branch("electronEta",electronEta,"electronEta[nElectron]/F"); t->Branch("electronPhi",electronPhi,"electronPhi[nElectron]/F"); t->Branch("electronQ",electronQ,"electronQ[nElectron]/I"); t->Branch("electronTag",electronTag,"electronTag[nElectron]/I"); t->Branch("electronCal02",electronCal02,"electronCal02[nElectron]/F"); t->Branch("electronCal03",electronCal03,"electronCal03[nElectron]/F"); t->Branch("electronCal04",electronCal04,"electronCal04[nElectron]/F"); t->Branch("electronTrk02",electronTrk02,"electronTrk02[nElectron]/F"); t->Branch("electronTrk03",electronTrk03,"electronTrk03[nElectron]/F"); t->Branch("electronTrk04",electronTrk04,"electronTrk04[nElectron]/F"); t->Branch("electronSign",electronSign,"electronSign[nElectron]/F"); t->Branch("nMuon",&nMuon,"nMuon/I"); t->Branch("muonPt",muonPt,"muonPt[nMuon]/F"); t->Branch("muonEta",muonEta,"muonEta[nMuon]/F"); t->Branch("muonPhi",muonPhi,"muonPhi[nMuon]/F"); t->Branch("muonQ",muonQ,"muonQ[nMuon]/I"); t->Branch("muonTag",muonTag,"muonTag[nMuon]/I"); t->Branch("muonCal02",muonCal02,"muonCal02[nMuon]/F"); t->Branch("muonCal03",muonCal03,"muonCal03[nMuon]/F"); t->Branch("muonCal04",muonCal04,"muonCal04[nMuon]/F"); t->Branch("muonTrk02",muonTrk02,"muonTrk02[nMuon]/F"); t->Branch("muonTrk03",muonTrk03,"muonTrk03[nMuon]/F"); t->Branch("muonTrk04",muonTrk04,"muonTrk04[nMuon]/F"); t->Branch("muonSign",muonSign,"muonSign[nMuon]/F"); t->Branch("nTau",&nTau,"nTau/I"); t->Branch("tauPt",tauPt,"tauPt[nTau]/F"); t->Branch("tauEta",tauEta,"tauEta[nTau]/F"); t->Branch("tauPhi",tauPhi,"tauPhi[nTau]/F"); t->Branch("tauQ",tauQ,"tauQ[nTau]/I"); t->Branch("tauTag",tauTag,"tauTag[nTau]/I"); t->Branch("tauCal02",tauCal02,"tauCal02[nTau]/F"); t->Branch("tauCal03",tauCal03,"tauCal03[nTau]/F"); t->Branch("tauCal04",tauCal04,"tauCal04[nTau]/F"); t->Branch("tauTrk02",tauTrk02,"tauTrk02[nTau]/F"); t->Branch("tauTrk03",tauTrk03,"tauTrk03[nTau]/F"); t->Branch("tauTrk04",tauTrk04,"tauTrk04[nTau]/F"); t->Branch("tauSign",tauSign,"tauSign[nTau]/F"); t->Branch("nJet",&nJet,"nJet/I"); t->Branch("jetPt",jetPt,"jetPt[nJet]/F"); t->Branch("jetEta",jetEta,"jetEta[nJet]/F"); t->Branch("jetPhi",jetPhi,"jetPhi[nJet]/F"); t->Branch("jetQ",jetQ,"jetQ[nJet]/I"); t->Branch("jetTag",jetTag,"jetTag[nJet]/I"); t->Branch("jetCal02",jetCal02,"jetCal02[nJet]/F"); t->Branch("jetCal03",jetCal03,"jetCal03[nJet]/F"); t->Branch("jetCal04",jetCal04,"jetCal04[nJet]/F"); t->Branch("jetTrk02",jetTrk02,"jetTrk02[nJet]/F"); t->Branch("jetTrk03",jetTrk03,"jetTrk03[nJet]/F"); t->Branch("jetTrk04",jetTrk04,"jetTrk04[nJet]/F"); t->Branch("metPt",&metPt,"metPt/F"); t->Branch("metEta",&metEta,"metEta/F"); t->Branch("metPhi",&metPhi,"metPhi/F"); t->Branch("sf_mu_reco_eff",sf_mu_reco_eff,"sf_mu_reco_eff[nMuon]/F"); // my branches t->Branch("sf_el_reco_eff",sf_el_reco_eff,"sf_el_reco_eff[nElectron]/F"); // This next part is taken from looper. TChain* chain = new TChain("t"); chain->Add("../run/"+infile+"/t"); TTree* tree = chain; SimData* data = new SimData(tree); if(data->fChain == 0) { cout << " fchain is empty" << endl; } Int_t nentries = Int_t(data->fChain->GetEntries()); cout << " Reading data ..." << nentries << " in physics tree" << endl; Int_t nTen = nentries/10; Int_t nbytes = 0, nb = 0; for (Int_t jentry=0; jentry<nentries; jentry++) { Int_t ientry = data->LoadTree(jentry); if (ientry < 0) break; nb = data->fChain->GetEntry(jentry); nbytes += nb; if (nTen!=0) if (jentry%nTen==0) cout << " " << 10*(jentry/nTen) << "%-" <<flush; // printf("evt %d: nPhoton %d, nElectron %d, nMuon %d, nTau %d, nJet %d \n", // data->evt,data->nPhoton,data->nElectron,data->nMuon,data->nTau,data->nJet); evt = data->evt; nPhoton = data->nPhoton; nElectron = data->nElectron; nMuon = data->nMuon; nTau = data->nTau; nJet = data->nJet; for (int i = 0; i < kMaxTrack; i++) { photonPt[i] = data->photonPt[i]; photonEta[i] = data->photonEta[i]; photonPhi[i] = data->photonPhi[i]; electronPt[i] = data->electronPt[i]; electronEta[i] = data->electronEta[i]; electronPhi[i] = data->electronPhi[i]; electronQ[i] = data->electronQ[i]; // electronTag[i] = data->electronTag[i]; // electronCal02[i] = data->electronCal02[i]; // electronCal03[i] = data->electronCal03[i]; // electronCal04[i] = data->electronCal04[i]; // electronTrk02[i] = data->electronTrk02[i]; // electronTrk03[i] = data->electronTrk03[i]; // electronTrk04[i] = data->electronTrk04[i]; // electronSign[i] = data->electronSign[i]; muonPt[i] = data->muonPt[i]; muonEta[i] = data->muonEta[i]; muonPhi[i] = data->muonPhi[i]; muonQ[i] = data->muonQ[i]; // muonTag[i] = data->muonTag[i]; // muonCal02[i] = data->muonCal02[i]; // muonCal03[i] = data->muonCal03[i]; // muonCal04[i] = data->muonCal04[i]; // muonTrk02[i] = data->muonTrk02[i]; // muonTrk03[i] = data->muonTrk03[i]; // muonTrk04[i] = data->muonTrk04[i]; // muonSign[i] = data->muonSign[i]; tauPt[i] = data->tauPt[i]; tauEta[i] = data->tauEta[i]; tauPhi[i] = data->tauPhi[i]; tauQ[i] = data->tauQ[i]; // tauTag[i] = data->tauTag[i]; // tauCal02[i] = data->tauCal02[i]; // tauCal03[i] = data->tauCal03[i]; // tauCal04[i] = data->tauCal04[i]; // tauTrk02[i] = data->tauTrk02[i]; // tauTrk03[i] = data->tauTrk03[i]; // tauTrk04[i] = data->tauTrk04[i]; // tauSign[i] = data->tauSign[i]; jetPt[i] = data->jetPt[i]; jetEta[i] = data->jetEta[i]; jetPhi[i] = data->jetPhi[i]; jetQ[i] = data->jetQ[i]; // jetTag[i] = data->jetTag[i]; // jetCal02[i] = data->jetCal02[i]; // jetCal03[i] = data->jetCal03[i]; // jetCal04[i] = data->jetCal04[i]; // jetTrk02[i] = data->jetTrk02[i]; // jetTrk03[i] = data->jetTrk03[i]; // jetTrk04[i] = data->jetTrk04[i]; } metPt = data->metPt; metEta = data->metEta; metPhi = data->metPhi; // smearing and efficiency for electrons // for (int i = 0; i < nElectron; i++) { // // float mean = data->electronPt[i]; // float sd = DeviationForParameter("electronPt",mean); // // Box-Muller method: // electronPt[i] = mean + sd * sqrt(-2*log(float(rand())/RAND_MAX))*cos(2*M_PI*float(rand())/RAND_MAX); // // sf_el_reco_eff[i] = EfficiencyForParticle("electron", electronPt[i], electronEta[i], electronPhi[i]); // } // smearing and efficiency for muons // for (int i = 0; i < nMuon; i++) { // // float mean = data->muonPt[i]; // float sd = DeviationForParameter("muonPt",mean); // muonPt[i] = mean + sd * sqrt(-2*log(float(rand())/RAND_MAX))*cos(2*M_PI*float(rand())/RAND_MAX); // // sf_mu_reco_eff[i] = EfficiencyForParticle("muon", muonPt[i], muonEta[i], muonPhi[i]); // } // effective smearing for met. // I say effective because the met is calculated from the particles, but we "delete" some of them... float mean = data->metPt; float sd = DeviationForParameter("metPt",mean); // TRandom r; r.SetSeed(12); metPt = RAND.Gaus(mean,sd); if (metPt<0){metPt=0;} //sqrt(-2*log(float(rand())/RAND_MAX))*cos(2*M_PI*float(rand())/RAND_MAX); t->Fill(); } f.cd(); t->Write("",TObject::kOverwrite); delete data; }
int main(int argc, char**argv){ if(argc != 2){ std::cerr << " >>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } std::string configFileName = argv[1]; boost::shared_ptr<edm::ParameterSet> parameterSet = edm::readConfig(configFileName); edm::ParameterSet Options = parameterSet -> getParameter<edm::ParameterSet>("AddRegressionWeight"); parameterSet.reset(); std::string treeNameDATA = Options.getParameter<std::string>("treeNameDATA"); std::string UseMethodFlag = Options.getParameter<std::string>("UseMethodFlag"); std::string FilemethodXML_EB_E = Options.getParameter<std::string>("FilemethodXML_EB_E"); std::string FilemethodXML_EB_P = Options.getParameter<std::string>("FilemethodXML_EB_P"); std::string FilemethodXML_EE_E = Options.getParameter<std::string>("FilemethodXML_EE_E"); std::string FilemethodXML_EE_P = Options.getParameter<std::string>("FilemethodXML_EE_P"); std::string RegionOfTraining = Options.getParameter<std::string>("RegionOfTraining"); std::string inputFile = Options.getParameter<std::string>("inputFile"); bool useW = Options.getParameter<bool>("useW"); bool isMC = Options.getParameter<bool>("isMC"); TFile *File = new TFile(inputFile.c_str(),"UPDATE"); TTree* treeDATA = (TTree*) File->Get(treeNameDATA.c_str()); float input_variables_1[1000]; float input_variables_2[1000]; double MVA_ValueZ_1,MVA_ValueZ_2, MVA_ValueW_1,MVA_ValueW_2; float targetW_1,targetZ_1,targetW_2,targetZ_2; TBranch *weightBranchW_1 = new TBranch(); TBranch *weightBranchW_2 = new TBranch(); TBranch *weightBranchZ_1 = new TBranch(); TBranch *weightBranchZ_2 = new TBranch(); TBranch *btargetW_1 = new TBranch(); TBranch *btargetZ_1 = new TBranch(); TBranch *btargetW_2 = new TBranch(); TBranch *btargetZ_2 = new TBranch(); if(RegionOfTraining=="EB"){ TMVA::Reader *TMVAreader_1 = new TMVA::Reader( "!Color:!Silent" ); TMVA::Reader *TMVAreader_2 = new TMVA::Reader( "!Color:!Silent" ); int ele1_isEB,isW; float ele1_eRegrInput_nPV,ele1_eRegrInput_r9,ele1_fbrem,ele1_eta,ele1_DphiIn,ele1_DetaIn,ele1_sigmaIetaIeta, ele1_E_true, ele1_scE, ele1_tkP,ele1_eRegrInput_etaW,ele1_eRegrInput_phiW,ele1_scERaw; TMVAreader_1->AddVariable("ele1_scE/ele1_scERaw",&input_variables_1[0]); TMVAreader_1->AddVariable("ele1_eRegrInput_nPV",&input_variables_1[1]); TMVAreader_1->AddVariable("ele1_eRegrInput_r9",&input_variables_1[2]); TMVAreader_1->AddVariable("ele1_fbrem",&input_variables_1[3]); TMVAreader_1->AddVariable("ele1_eta",&input_variables_1[4]); TMVAreader_1->AddVariable("ele1_DphiIn",&input_variables_1[5]); TMVAreader_1->AddVariable("ele1_DetaIn",&input_variables_1[6]); TMVAreader_1->AddVariable("ele1_sigmaIetaIeta", &input_variables_1[7]); TMVAreader_1->AddVariable("ele1_eRegrInput_etaW",&input_variables_1[8]); TMVAreader_1->AddVariable("ele1_eRegrInput_phiW", &input_variables_1[9]); TMVAreader_2->AddVariable("ele1_scE/ele1_scERaw",&input_variables_2[0]); TMVAreader_2->AddVariable("ele1_eRegrInput_nPV",&input_variables_2[1]); TMVAreader_2->AddVariable("ele1_eRegrInput_r9",&input_variables_2[2]); TMVAreader_2->AddVariable("ele1_fbrem",&input_variables_2[3]); TMVAreader_2->AddVariable("ele1_eta",&input_variables_2[4]); TMVAreader_2->AddVariable("ele1_DphiIn",&input_variables_2[5]); TMVAreader_2->AddVariable("ele1_DetaIn",&input_variables_2[6]); TMVAreader_2->AddVariable("ele1_sigmaIetaIeta", &input_variables_2[7]); TMVAreader_2->AddVariable("ele1_eRegrInput_etaW",&input_variables_2[8]); TMVAreader_2->AddVariable("ele1_eRegrInput_phiW", &input_variables_2[9]); treeDATA -> SetBranchAddress("ele1_isEB", &ele1_isEB); treeDATA -> SetBranchAddress("isW", &isW); treeDATA -> SetBranchAddress("ele1_scE", &ele1_scE); treeDATA -> SetBranchAddress("ele1_scERaw", &ele1_scERaw); treeDATA -> SetBranchAddress("ele1_tkP", &ele1_tkP); treeDATA -> SetBranchAddress("ele1_eRegrInput_nPV", &ele1_eRegrInput_nPV); treeDATA -> SetBranchAddress("ele1_eRegrInput_r9", &ele1_eRegrInput_r9); treeDATA -> SetBranchAddress("ele1_fbrem", &ele1_fbrem); treeDATA -> SetBranchAddress("ele1_eta", &ele1_eta); treeDATA -> SetBranchAddress("ele1_DphiIn", &ele1_DphiIn); treeDATA -> SetBranchAddress("ele1_DetaIn", &ele1_DetaIn); treeDATA -> SetBranchAddress("ele1_sigmaIetaIeta", &ele1_sigmaIetaIeta); treeDATA -> SetBranchAddress("ele1_eRegrInput_etaW", &ele1_eRegrInput_etaW); treeDATA -> SetBranchAddress("ele1_eRegrInput_phiW", &ele1_eRegrInput_phiW); if(isMC == true) treeDATA -> SetBranchAddress("ele1_E_true", &ele1_E_true); float ele1_eRegrInput_bCE_Over_sCE,ele1_eRegrInput_sigietaieta_bC1,ele1_eRegrInput_sigiphiiphi_bC1,ele1_eRegrInput_sigietaiphi_bC1,ele1_eRegrInput_e3x3_Over_bCE,ele1_eRegrInput_Deta_bC_sC,ele1_eRegrInput_Dphi_bC_sC,ele1_eRegrInput_bEMax_Over_bCE; TMVAreader_1->AddVariable("ele1_eRegrInput_bCE_Over_sCE",&input_variables_1[10]); TMVAreader_1->AddVariable("ele1_eRegrInput_sigietaieta_bC1",&input_variables_1[11]); TMVAreader_1->AddVariable("ele1_eRegrInput_sigiphiiphi_bC1",&input_variables_1[12]); TMVAreader_1->AddVariable("ele1_eRegrInput_sigietaiphi_bC1",&input_variables_1[13]); TMVAreader_1->AddVariable("ele1_eRegrInput_e3x3_Over_bCE", &input_variables_1[14]); TMVAreader_1->AddVariable("ele1_eRegrInput_Deta_bC_sC", &input_variables_1[15]); TMVAreader_1->AddVariable("ele1_eRegrInput_Dphi_bC_sC", &input_variables_1[16]); TMVAreader_1->AddVariable("ele1_eRegrInput_bEMax_Over_bCE", &input_variables_1[17]); TMVAreader_2->AddVariable("ele1_eRegrInput_bCE_Over_sCE",&input_variables_2[10]); TMVAreader_2->AddVariable("ele1_eRegrInput_sigietaieta_bC1",&input_variables_2[11]); TMVAreader_2->AddVariable("ele1_eRegrInput_sigiphiiphi_bC1",&input_variables_2[12]); TMVAreader_2->AddVariable("ele1_eRegrInput_sigietaiphi_bC1",&input_variables_2[13]); TMVAreader_2->AddVariable("ele1_eRegrInput_e3x3_Over_bCE", &input_variables_2[14]); TMVAreader_2->AddVariable("ele1_eRegrInput_Deta_bC_sC", &input_variables_2[15]); TMVAreader_2->AddVariable("ele1_eRegrInput_Dphi_bC_sC", &input_variables_2[16]); TMVAreader_2->AddVariable("ele1_eRegrInput_bEMax_Over_bCE", &input_variables_2[17]); treeDATA -> SetBranchAddress("ele1_eRegrInput_bCE_Over_sCE", &ele1_eRegrInput_bCE_Over_sCE); treeDATA -> SetBranchAddress("ele1_eRegrInput_sigietaieta_bC1", &ele1_eRegrInput_sigietaieta_bC1); treeDATA -> SetBranchAddress("ele1_eRegrInput_sigiphiiphi_bC1", &ele1_eRegrInput_sigiphiiphi_bC1); treeDATA -> SetBranchAddress("ele1_eRegrInput_sigietaiphi_bC1", &ele1_eRegrInput_sigietaiphi_bC1); treeDATA -> SetBranchAddress("ele1_eRegrInput_e3x3_Over_bCE", &ele1_eRegrInput_e3x3_Over_bCE); treeDATA -> SetBranchAddress("ele1_eRegrInput_Deta_bC_sC", &ele1_eRegrInput_Deta_bC_sC); treeDATA -> SetBranchAddress("ele1_eRegrInput_Dphi_bC_sC", &ele1_eRegrInput_Dphi_bC_sC); treeDATA -> SetBranchAddress("ele1_eRegrInput_bEMax_Over_bCE", &ele1_eRegrInput_bEMax_Over_bCE); float ele1_dxy_PV,ele1_dz_PV,ele1_sigmaP; TMVAreader_1->AddVariable( "ele1_dxy_PV" , &input_variables_1[18]); TMVAreader_1->AddVariable( "ele1_dz_PV" , &input_variables_1[19]); TMVAreader_1->AddVariable( "ele1_sigmaP/ele1_tkP" , &input_variables_1[20]); TMVAreader_2->AddVariable( "ele1_dxy_PV" , &input_variables_2[18]); TMVAreader_2->AddVariable( "ele1_dz_PV" , &input_variables_2[19]); TMVAreader_2->AddVariable( "ele1_sigmaP/ele1_tkP" , &input_variables_2[20]); treeDATA -> SetBranchAddress("ele1_dxy_PV", &ele1_dxy_PV); treeDATA -> SetBranchAddress("ele1_dz_PV", &ele1_dz_PV); treeDATA -> SetBranchAddress("ele1_sigmaP", &ele1_sigmaP); float ele1_eRegrInput_bCELow_Over_sCE,ele1_eRegrInput_sigietaieta_bCLow,ele1_eRegrInput_sigiphiiphi_bCLow,ele1_eRegrInput_sigietaiphi_bCLow,ele1_eRegrInput_e3x3_Over_bCELow,ele1_eRegrInput_Deta_bCLow_sC,ele1_eRegrInput_Dphi_bCLow_sC; TMVAreader_1->AddVariable("ele1_eRegrInput_bCELow_Over_sCE",&input_variables_1[21]); TMVAreader_1->AddVariable("ele1_eRegrInput_e3x3_Over_bCELow", &input_variables_1[22]); TMVAreader_1->AddVariable("ele1_eRegrInput_Deta_bCLow_sC", &input_variables_1[23]); TMVAreader_1->AddVariable("ele1_eRegrInput_Dphi_bCLow_sC", &input_variables_1[24]); TMVAreader_2->AddVariable("ele1_eRegrInput_bCELow_Over_sCE",&input_variables_2[21]); TMVAreader_2->AddVariable("ele1_eRegrInput_e3x3_Over_bCELow", &input_variables_2[22]); TMVAreader_2->AddVariable("ele1_eRegrInput_Deta_bCLow_sC", &input_variables_2[23]); TMVAreader_2->AddVariable("ele1_eRegrInput_Dphi_bCLow_sC", &input_variables_2[24]); treeDATA -> SetBranchAddress("ele1_eRegrInput_bCELow_Over_sCE", &ele1_eRegrInput_bCELow_Over_sCE); treeDATA -> SetBranchAddress("ele1_eRegrInput_e3x3_Over_bCELow", &ele1_eRegrInput_e3x3_Over_bCELow); treeDATA -> SetBranchAddress("ele1_eRegrInput_sigietaieta_bCLow", &ele1_eRegrInput_sigietaieta_bCLow); treeDATA -> SetBranchAddress("ele1_eRegrInput_sigiphiiphi_bCLow", &ele1_eRegrInput_sigiphiiphi_bCLow); treeDATA -> SetBranchAddress("ele1_eRegrInput_sigietaiphi_bCLow", &ele1_eRegrInput_sigietaiphi_bCLow); treeDATA -> SetBranchAddress("ele1_eRegrInput_Deta_bCLow_sC", &ele1_eRegrInput_Deta_bCLow_sC); treeDATA -> SetBranchAddress("ele1_eRegrInput_Dphi_bCLow_sC", &ele1_eRegrInput_Dphi_bCLow_sC); float ele1_eRegrInput_seedbC_etacry,ele1_eRegrInput_seedbC_phicry; TMVAreader_1->AddVariable("ele1_eRegrInput_seedbC_etacry", &input_variables_1[25]); TMVAreader_1->AddVariable("ele1_eRegrInput_seedbC_phicry", &input_variables_1[26]); TMVAreader_2->AddVariable("ele1_eRegrInput_seedbC_etacry", &input_variables_2[25]); TMVAreader_2->AddVariable("ele1_eRegrInput_seedbC_phicry", &input_variables_2[26]); treeDATA -> SetBranchAddress("ele1_eRegrInput_seedbC_etacry", &ele1_eRegrInput_seedbC_etacry); treeDATA -> SetBranchAddress("ele1_eRegrInput_seedbC_phicry", &ele1_eRegrInput_seedbC_phicry); ///==== add new branches ==== TString weightfile_1 = FilemethodXML_EB_E; TString weightfile_2 = FilemethodXML_EB_P; std::cout<<" UseMethodFlag "<<UseMethodFlag<<" weightfile"<<weightfile_1<<" : "<<weightfile_1<<std::endl; TMVAreader_1->BookMVA( UseMethodFlag, weightfile_1 ); TMVAreader_2->BookMVA( UseMethodFlag, weightfile_2 ); TString methodName4TreeW_1 = Form ("%s_weightEB_W_1",UseMethodFlag.c_str()); TString methodName4TreeZ_1 = Form ("%s_weightEB_Z_1",UseMethodFlag.c_str()); TString methodName4TreeW_1_ = Form ("%s_weightEB_W_1/D",UseMethodFlag.c_str()); TString methodName4TreeZ_1_ = Form ("%s_weightEB_Z_1/D",UseMethodFlag.c_str()); TString methodName4TreeW_2 = Form ("%s_weightEB_W_2",UseMethodFlag.c_str()); TString methodName4TreeZ_2 = Form ("%s_weightEB_Z_2",UseMethodFlag.c_str()); TString methodName4TreeW_2_ = Form ("%s_weightEB_W_2/D",UseMethodFlag.c_str()); TString methodName4TreeZ_2_ = Form ("%s_weightEB_Z_2/D",UseMethodFlag.c_str()); TString methodtargetW_1; TString methodtargetZ_1; TString methodtargetW_1_; TString methodtargetZ_1_; TString methodtargetW_2; TString methodtargetZ_2; TString methodtargetW_2_; TString methodtargetZ_2_; if(isMC == true){ methodtargetW_1 = Form ("%s_targetEB_W_1",UseMethodFlag.c_str()); methodtargetZ_1 = Form ("%s_targetEB_Z_1",UseMethodFlag.c_str()); methodtargetW_1_= Form ("%s_targetEB_W_1/F",UseMethodFlag.c_str()); methodtargetZ_1_= Form ("%s_targetEB_Z_1/F",UseMethodFlag.c_str()); methodtargetW_2 = Form ("%s_targetEB_W_2",UseMethodFlag.c_str()); methodtargetZ_2 = Form ("%s_targetEB_Z_2",UseMethodFlag.c_str()); methodtargetW_2_= Form ("%s_targetEB_W_2/F",UseMethodFlag.c_str()); methodtargetZ_2_= Form ("%s_targetEB_Z_2/F",UseMethodFlag.c_str()); } if(useW) { weightBranchW_1 = treeDATA->Branch(methodName4TreeW_1,&MVA_ValueW_1,methodName4TreeW_1_); weightBranchW_2 = treeDATA->Branch(methodName4TreeW_2,&MVA_ValueW_2,methodName4TreeW_2_); if(isMC == true){ btargetW_1 = treeDATA->Branch(methodtargetW_1,&targetW_1,methodtargetW_1); btargetW_2 = treeDATA->Branch(methodtargetW_2,&targetW_2,methodtargetW_2); } } if(!useW){ weightBranchZ_1 = treeDATA->Branch(methodName4TreeZ_1,&MVA_ValueZ_1,methodName4TreeZ_1); weightBranchZ_2 = treeDATA->Branch(methodName4TreeZ_2,&MVA_ValueZ_2,methodName4TreeZ_2); if(isMC == true){ btargetZ_1 = treeDATA->Branch(methodtargetZ_1,&targetZ_1,methodtargetZ_1); btargetZ_2 = treeDATA->Branch(methodtargetZ_2,&targetZ_2,methodtargetZ_2); } } ///==== loop ==== Long64_t nentries = treeDATA->GetEntries(); for (Long64_t iEntry = 0; iEntry < nentries; iEntry++){ if((iEntry%100000) == 0) std::cout << ">>>>> analysis::GetEntry " << iEntry << " : " << nentries << std::endl; treeDATA->GetEntry(iEntry); if(ele1_isEB==1 && ele1_sigmaP/ele1_tkP<0.4 && ele1_fbrem>0. && abs(ele1_dxy_PV)<0.05 && abs(ele1_dz_PV)<0.05 && ele1_eRegrInput_etaW > 0.006 && ele1_eRegrInput_phiW<0.08 && ele1_eRegrInput_sigietaieta_bC1>0.006 && ele1_eRegrInput_sigiphiiphi_bC1>0.008 && abs(ele1_eRegrInput_Deta_bC_sC)<0.004 && abs(ele1_eRegrInput_Dphi_bC_sC)<0.04 && abs(ele1_eRegrInput_seedbC_etacry)<0.6 && abs(ele1_eRegrInput_seedbC_phicry)<0.6 && ele1_scE/ele1_scERaw<1.2){ input_variables_1[0] = static_cast<float>(ele1_scE/ele1_scERaw); input_variables_1[1] = static_cast<float>(ele1_eRegrInput_nPV); input_variables_1[2] = static_cast<float>(ele1_eRegrInput_r9); input_variables_1[3] = static_cast<float>(ele1_fbrem); input_variables_1[4] = static_cast<float>(ele1_eta); input_variables_1[5] = static_cast<float>(ele1_DphiIn); input_variables_1[6] = static_cast<float>(ele1_DetaIn); input_variables_1[7] = static_cast<float>(ele1_sigmaIetaIeta); input_variables_1[8] = static_cast<float>(ele1_eRegrInput_etaW); input_variables_1[9] = static_cast<float>(ele1_eRegrInput_phiW); input_variables_1[10] = static_cast<float>(ele1_eRegrInput_bCE_Over_sCE); input_variables_1[11] = static_cast<float>(ele1_eRegrInput_sigietaieta_bC1); input_variables_1[12] = static_cast<float>(ele1_eRegrInput_sigiphiiphi_bC1); input_variables_1[13] = static_cast<float>(ele1_eRegrInput_sigietaiphi_bC1); input_variables_1[14] = static_cast<float>(ele1_eRegrInput_e3x3_Over_bCE); input_variables_1[15] = static_cast<float>(ele1_eRegrInput_Deta_bC_sC); input_variables_1[16] = static_cast<float>(ele1_eRegrInput_Dphi_bC_sC); input_variables_1[17] = static_cast<float>(ele1_eRegrInput_bEMax_Over_bCE); input_variables_1[18] = static_cast<float>(ele1_dxy_PV); input_variables_1[19] = static_cast<float>(ele1_dz_PV); input_variables_1[29] = static_cast<float>(ele1_sigmaP/ele1_tkP); input_variables_1[21] = static_cast<float>(ele1_eRegrInput_bCELow_Over_sCE); input_variables_1[22] = static_cast<float>(ele1_eRegrInput_e3x3_Over_bCELow); input_variables_1[23] = static_cast<float>(ele1_eRegrInput_Deta_bCLow_sC); input_variables_1[24] = static_cast<float>(ele1_eRegrInput_Dphi_bCLow_sC); input_variables_1[25] = static_cast<float>(ele1_eRegrInput_seedbC_etacry); input_variables_1[26] = static_cast<float>(ele1_eRegrInput_seedbC_phicry); input_variables_2[0] = static_cast<float>(ele1_scE/ele1_scERaw); input_variables_2[1] = static_cast<float>(ele1_eRegrInput_nPV); input_variables_2[2] = static_cast<float>(ele1_eRegrInput_r9); input_variables_2[3] = static_cast<float>(ele1_fbrem); input_variables_2[4] = static_cast<float>(ele1_eta); input_variables_2[5] = static_cast<float>(ele1_DphiIn); input_variables_2[6] = static_cast<float>(ele1_DetaIn); input_variables_2[7] = static_cast<float>(ele1_sigmaIetaIeta); input_variables_2[8] = static_cast<float>(ele1_eRegrInput_etaW); input_variables_2[9] = static_cast<float>(ele1_eRegrInput_phiW); input_variables_2[10] = static_cast<float>(ele1_eRegrInput_bCE_Over_sCE); input_variables_2[11] = static_cast<float>(ele1_eRegrInput_sigietaieta_bC1); input_variables_2[12] = static_cast<float>(ele1_eRegrInput_sigiphiiphi_bC1); input_variables_2[13] = static_cast<float>(ele1_eRegrInput_sigietaiphi_bC1); input_variables_2[14] = static_cast<float>(ele1_eRegrInput_e3x3_Over_bCE); input_variables_2[15] = static_cast<float>(ele1_eRegrInput_Deta_bC_sC); input_variables_2[16] = static_cast<float>(ele1_eRegrInput_Dphi_bC_sC); input_variables_2[17] = static_cast<float>(ele1_eRegrInput_bEMax_Over_bCE); input_variables_2[18] = static_cast<float>(ele1_dxy_PV); input_variables_2[19] = static_cast<float>(ele1_dz_PV); input_variables_2[29] = static_cast<float>(ele1_sigmaP/ele1_tkP); input_variables_2[21] = static_cast<float>(ele1_eRegrInput_bCELow_Over_sCE); input_variables_2[22] = static_cast<float>(ele1_eRegrInput_e3x3_Over_bCELow); input_variables_2[23] = static_cast<float>(ele1_eRegrInput_Deta_bCLow_sC); input_variables_2[24] = static_cast<float>(ele1_eRegrInput_Dphi_bCLow_sC); input_variables_2[25] = static_cast<float>(ele1_eRegrInput_seedbC_etacry); input_variables_2[26] = static_cast<float>(ele1_eRegrInput_seedbC_phicry); if(useW){ MVA_ValueW_1 = TMVAreader_1->EvaluateRegression(0,UseMethodFlag); MVA_ValueW_2 = TMVAreader_2->EvaluateRegression(0,UseMethodFlag); if(isMC == true) { targetW_1 = ele1_scE/ele1_E_true; targetW_2 = ele1_tkP/ele1_E_true; btargetW_1 -> Fill(); btargetW_2 -> Fill(); } weightBranchW_1 -> Fill(); weightBranchW_2 -> Fill(); } if(!useW){ MVA_ValueZ_1 = TMVAreader_1->EvaluateRegression(0,UseMethodFlag); MVA_ValueZ_2 = TMVAreader_2->EvaluateRegression(0,UseMethodFlag); if(isMC == true) { targetZ_1 = ele1_scE/ele1_E_true; targetZ_2 = ele1_tkP/ele1_E_true; btargetZ_1 -> Fill(); btargetZ_2 -> Fill(); } weightBranchZ_1 -> Fill(); weightBranchZ_2 -> Fill(); } } else{ if( useW == true){ MVA_ValueW_1 = -99. ; MVA_ValueW_2 = -99.; if(isMC == true) { targetW_1 = -99. ; targetW_2=-99. ; btargetW_1 -> Fill(); btargetW_2 -> Fill(); } weightBranchW_1 -> Fill(); weightBranchW_2 -> Fill(); } if( useW == false){ MVA_ValueZ_1 = -99.; MVA_ValueZ_2 = -99.; if(isMC == true) { targetZ_1 = -99. ; targetZ_2=-99. ; btargetZ_1 -> Fill(); btargetZ_2 -> Fill(); } weightBranchZ_1 -> Fill(); weightBranchZ_2 -> Fill(); } } } } if(RegionOfTraining=="EE"){ TMVA::Reader *TMVAreader_1 = new TMVA::Reader( "!Color:!Silent" ); TMVA::Reader *TMVAreader_2 = new TMVA::Reader( "!Color:!Silent" ); int ele1_isEB,isW; float ele1_eRegrInput_nPV,ele1_eRegrInput_r9,ele1_fbrem,ele1_eta,ele1_DphiIn,ele1_DetaIn,ele1_sigmaIetaIeta, ele1_E_true, ele1_scE, ele1_tkP,ele1_eRegrInput_etaW,ele1_eRegrInput_phiW,ele1_scERaw; TMVAreader_1->AddVariable("ele1_scE/ele1_scERaw",&input_variables_1[0]); TMVAreader_1->AddVariable("ele1_eRegrInput_nPV",&input_variables_1[1]); TMVAreader_1->AddVariable("ele1_eRegrInput_r9",&input_variables_1[2]); TMVAreader_1->AddVariable("ele1_fbrem",&input_variables_1[3]); TMVAreader_1->AddVariable("ele1_eta",&input_variables_1[4]); TMVAreader_1->AddVariable("ele1_DphiIn",&input_variables_1[5]); TMVAreader_1->AddVariable("ele1_DetaIn",&input_variables_1[6]); TMVAreader_1->AddVariable("ele1_sigmaIetaIeta", &input_variables_1[7]); TMVAreader_1->AddVariable("ele1_eRegrInput_etaW",&input_variables_1[8]); TMVAreader_1->AddVariable("ele1_eRegrInput_phiW", &input_variables_1[9]); TMVAreader_2->AddVariable("ele1_scE/ele1_scERaw",&input_variables_2[0]); TMVAreader_2->AddVariable("ele1_eRegrInput_nPV",&input_variables_2[1]); TMVAreader_2->AddVariable("ele1_eRegrInput_r9",&input_variables_2[2]); TMVAreader_2->AddVariable("ele1_fbrem",&input_variables_2[3]); TMVAreader_2->AddVariable("ele1_eta",&input_variables_2[4]); TMVAreader_2->AddVariable("ele1_DphiIn",&input_variables_2[5]); TMVAreader_2->AddVariable("ele1_DetaIn",&input_variables_2[6]); TMVAreader_2->AddVariable("ele1_sigmaIetaIeta", &input_variables_2[7]); TMVAreader_2->AddVariable("ele1_eRegrInput_etaW",&input_variables_2[8]); TMVAreader_2->AddVariable("ele1_eRegrInput_phiW", &input_variables_2[9]); treeDATA -> SetBranchAddress("ele1_isEB", &ele1_isEB); treeDATA -> SetBranchAddress("isW", &isW); if(isMC == true) treeDATA -> SetBranchAddress("ele1_E_true", &ele1_E_true); treeDATA -> SetBranchAddress("ele1_scE", &ele1_scE); treeDATA -> SetBranchAddress("ele1_scERaw", &ele1_scERaw); treeDATA -> SetBranchAddress("ele1_tkP", &ele1_tkP); treeDATA -> SetBranchAddress("ele1_eRegrInput_nPV", &ele1_eRegrInput_nPV); treeDATA -> SetBranchAddress("ele1_eRegrInput_r9", &ele1_eRegrInput_r9); treeDATA -> SetBranchAddress("ele1_fbrem", &ele1_fbrem); treeDATA -> SetBranchAddress("ele1_eta", &ele1_eta); treeDATA -> SetBranchAddress("ele1_DphiIn", &ele1_DphiIn); treeDATA -> SetBranchAddress("ele1_DetaIn", &ele1_DetaIn); treeDATA -> SetBranchAddress("ele1_sigmaIetaIeta", &ele1_sigmaIetaIeta); treeDATA -> SetBranchAddress("ele1_eRegrInput_etaW", &ele1_eRegrInput_etaW); treeDATA -> SetBranchAddress("ele1_eRegrInput_phiW", &ele1_eRegrInput_phiW); float ele1_dxy_PV,ele1_dz_PV,ele1_sigmaP; TMVAreader_1->AddVariable( "ele1_dxy_PV" , &input_variables_1[18]); TMVAreader_1->AddVariable( "ele1_dz_PV" , &input_variables_1[19]); TMVAreader_1->AddVariable( "ele1_sigmaP/ele1_tkP" , &input_variables_1[20]); TMVAreader_2->AddVariable( "ele1_dxy_PV" , &input_variables_2[18]); TMVAreader_2->AddVariable( "ele1_dz_PV" , &input_variables_2[19]); TMVAreader_2->AddVariable( "ele1_sigmaP/ele1_tkP" , &input_variables_2[20]); treeDATA -> SetBranchAddress("ele1_dxy_PV", &ele1_dxy_PV); treeDATA -> SetBranchAddress("ele1_dz_PV", &ele1_dz_PV); treeDATA -> SetBranchAddress("ele1_sigmaP", &ele1_sigmaP); ///==== add new branches ==== TString weightfile_1 = FilemethodXML_EE_E; TString weightfile_2 = FilemethodXML_EE_P; std::cout<<" UseMethodFlag "<<UseMethodFlag<<" weightfile"<<weightfile_1<<" : "<<weightfile_2<<std::endl; TMVAreader_1->BookMVA( UseMethodFlag, weightfile_1 ); TMVAreader_2->BookMVA( UseMethodFlag, weightfile_2 ); TString methodName4TreeW_1 = Form ("%s_weightEE_W_1",UseMethodFlag.c_str()); TString methodName4TreeZ_1 = Form ("%s_weightEE_Z_1",UseMethodFlag.c_str()); TString methodName4TreeW_1_ = Form ("%s_weightEE_W_1/D",UseMethodFlag.c_str()); TString methodName4TreeZ_1_ = Form ("%s_weightEE_Z_1/D",UseMethodFlag.c_str()); TString methodName4TreeW_2 = Form ("%s_weightEE_W_2",UseMethodFlag.c_str()); TString methodName4TreeZ_2 = Form ("%s_weightEE_Z_2",UseMethodFlag.c_str()); TString methodName4TreeW_2_ = Form ("%s_weightEE_W_2/D",UseMethodFlag.c_str()); TString methodName4TreeZ_2_ = Form ("%s_weightEE_Z_2/D",UseMethodFlag.c_str()); TString methodtargetW_1; TString methodtargetZ_1; TString methodtargetW_1_; TString methodtargetZ_1_; TString methodtargetW_2; TString methodtargetZ_2; TString methodtargetW_2_; TString methodtargetZ_2_; if(isMC == true){ methodtargetW_1 = Form ("%s_targetEE_W_1",UseMethodFlag.c_str()); methodtargetZ_1 = Form ("%s_targetEE_Z_1",UseMethodFlag.c_str()); methodtargetW_1_= Form ("%s_targetEE_W_1/F",UseMethodFlag.c_str()); methodtargetZ_1_= Form ("%s_targetEE_Z_1/F",UseMethodFlag.c_str()); methodtargetW_2 = Form ("%s_targetEE_W_2",UseMethodFlag.c_str()); methodtargetZ_2 = Form ("%s_targetEE_Z_2",UseMethodFlag.c_str()); methodtargetW_2_= Form ("%s_targetEE_W_2/F",UseMethodFlag.c_str()); methodtargetZ_2_= Form ("%s_targetEE_Z_2/F",UseMethodFlag.c_str()); } if(useW) { weightBranchW_1 = treeDATA->Branch(methodName4TreeW_1,&MVA_ValueW_1,methodName4TreeW_1_); weightBranchW_2 = treeDATA->Branch(methodName4TreeW_2,&MVA_ValueW_2,methodName4TreeW_2_); if(isMC==true){ btargetW_1 = treeDATA->Branch(methodtargetW_1,&targetW_1,methodtargetW_1); btargetW_2 = treeDATA->Branch(methodtargetW_2,&targetW_2,methodtargetW_2);} } if(!useW){ weightBranchZ_1 = treeDATA->Branch(methodName4TreeZ_1,&MVA_ValueZ_1,methodName4TreeZ_1); weightBranchZ_2 = treeDATA->Branch(methodName4TreeZ_2,&MVA_ValueZ_2,methodName4TreeZ_2); if(isMC==true){ btargetZ_1 = treeDATA->Branch(methodtargetZ_1,&targetZ_1,methodtargetZ_1); btargetZ_2 = treeDATA->Branch(methodtargetZ_2,&targetZ_2,methodtargetZ_2);} } ///==== loop ==== Long64_t nentries = treeDATA->GetEntries(); for (Long64_t iEntry = 0; iEntry < nentries; iEntry++){ if((iEntry%100000) == 0) std::cout << ">>>>> analysis::GetEntry " << iEntry << " : " << nentries << std::endl; treeDATA->GetEntry(iEntry); if(ele1_isEB==0 && ele1_sigmaP/ele1_tkP<0.4 && ele1_fbrem>0 && abs(ele1_dxy_PV)<0.05 && abs(ele1_dz_PV)<0.05){ input_variables_1[0] = static_cast<float>(ele1_scE/ele1_scERaw); input_variables_1[1] = static_cast<float>(ele1_eRegrInput_nPV); input_variables_1[2] = static_cast<float>(ele1_eRegrInput_r9); input_variables_1[3] = static_cast<float>(ele1_fbrem); input_variables_1[4] = static_cast<float>(ele1_eta); input_variables_1[5] = static_cast<float>(ele1_DphiIn); input_variables_1[6] = static_cast<float>(ele1_DetaIn); input_variables_1[7] = static_cast<float>(ele1_sigmaIetaIeta); input_variables_1[8] = static_cast<float>(ele1_eRegrInput_etaW); input_variables_1[9] = static_cast<float>(ele1_eRegrInput_phiW); input_variables_1[10] = static_cast<float>(ele1_dxy_PV); input_variables_1[11] = static_cast<float>(ele1_dz_PV); input_variables_1[12] = static_cast<float>(ele1_sigmaP/ele1_tkP); input_variables_2[0] = static_cast<float>(ele1_scE/ele1_scERaw); input_variables_2[1] = static_cast<float>(ele1_eRegrInput_nPV); input_variables_2[2] = static_cast<float>(ele1_eRegrInput_r9); input_variables_2[3] = static_cast<float>(ele1_fbrem); input_variables_2[4] = static_cast<float>(ele1_eta); input_variables_2[5] = static_cast<float>(ele1_DphiIn); input_variables_2[6] = static_cast<float>(ele1_DetaIn); input_variables_2[7] = static_cast<float>(ele1_sigmaIetaIeta); input_variables_2[8] = static_cast<float>(ele1_eRegrInput_etaW); input_variables_2[9] = static_cast<float>(ele1_eRegrInput_phiW); input_variables_2[10] = static_cast<float>(ele1_dxy_PV); input_variables_2[11] = static_cast<float>(ele1_dz_PV); input_variables_2[12] = static_cast<float>(ele1_sigmaP/ele1_tkP); if(useW){ MVA_ValueW_1 = TMVAreader_1->EvaluateRegression(0,UseMethodFlag) ; MVA_ValueW_2 = TMVAreader_2->EvaluateRegression(0,UseMethodFlag) ; if(isMC== true){ targetW_1 = ele1_scE/ele1_E_true; targetW_2 = ele1_tkP/ele1_E_true; btargetW_1 -> Fill(); btargetW_2 -> Fill(); } weightBranchW_1 -> Fill(); weightBranchW_2 -> Fill(); } if(!useW){ MVA_ValueZ_1 = TMVAreader_1->EvaluateRegression(0,UseMethodFlag) ; MVA_ValueZ_2 = TMVAreader_2->EvaluateRegression(0,UseMethodFlag) ; if(isMC== true){ targetZ_1 = ele1_scE/ele1_E_true; targetZ_2 = ele1_tkP/ele1_E_true; btargetZ_1 -> Fill(); btargetZ_2 -> Fill(); } weightBranchZ_1 -> Fill(); weightBranchZ_2 -> Fill(); } } else{ if( useW == true){ MVA_ValueW_1 = -99. ; MVA_ValueW_2 = -99.; if(isMC== true){ targetW_1 = -99. ; targetW_2=-99. ; btargetW_1 -> Fill(); btargetW_2 -> Fill(); } weightBranchW_1 -> Fill(); weightBranchW_2 -> Fill(); } if( useW == false){ MVA_ValueZ_1 = -99.; MVA_ValueZ_2 = -99.; if(isMC == true){ targetZ_1 = -99. ; targetZ_2=-99. ; btargetZ_1 -> Fill(); btargetZ_2 -> Fill(); } weightBranchZ_1 -> Fill(); weightBranchZ_2 -> Fill(); } } } } // save only the new version of the tree treeDATA->Write("", TObject::kOverwrite); return 0; }
int main( int argc, const char* argv[] ){ // List of arguments: // 0: The executable itself // 1: The number of times JetMET is smeared (not smeared if equal to 1) // 2: The scale and type of JES shift (if fabs(x) < 0.5, shift by eta, else absolute // fixme: Depracated float JES_JetMET = 1.0; string xmlFileName = string ("./MyMassAnalysis.xml"); for (int i=1;i<argc;++i) { if (strncmp(argv[i],"-c",2)==0) xmlFileName = string(argv[i+1]); if (strncmp(argv[i],"-h",2)==0) { cout << " -c xm_config_file\n"; exit(1); } } cout<<"#########################"<<endl; cout<<"Beginning of the program"<<endl; cout<<"#########################"<<endl; ////////////////////// //Global variables ////////////////////// // GEN TH1F * histoGenTopRapidity1 = new TH1F("GenTopRapidity1", "GenTopRapidity1", 100, -5, 5); TH1F * histoGenTopRapidity2 = new TH1F("GenTopRapidity2", "GenTopRapidity2", 100, -5, 5); TH1F * histoGenTopMass1 = new TH1F("GenTopMass1", "GenTopMass1", 200, 0, 200); TH1F * histoGenTopMass2 = new TH1F("GenTopMass2", "GenTopMass2", 200, 0, 200); TH2F * histoGenTopMass1VsTopMass2 = new TH2F("GenTopMass1VsTopMass2", "GenTopMass1VsTopMass2", 200, 0, 200, 200, 0, 200); TH1F * histoGenDelta_y = new TH1F("GenDelta_y", "GenDelta_y", 400, -2, 2); TH1F * histoGenTTRapidity = new TH1F("GenTTRapidity", "GenTTRapidity", 500, -2.5, 2.5); TH1F * histoGenTTPt = new TH1F("GenTTPt", "GenTTPt", 250, 0, 250); TH1F * histoGenTTMass = new TH1F("GenTTMass", "GenTTMass", 100, 0, 1000); TH2F * histoGenDelta_yVsTTRapidity = new TH2F("GenDelta_yVsTTRapidity", "GenDelta_yVsTTRapidity", 10, -2, 2, 5, -2.5, 2.5); TH2F * histoGenDelta_yVsTTPt = new TH2F("GenDelta_yVsTTPt", "GenDelta_yVsTTPt", 10, -2, 2, 5, 0, 250); TH2F * histoGenDelta_yVsTTMass = new TH2F("GenDelta_yVsTTMass", "GenDelta_yVsTTMass", 10, -2, 2, 5, 0, 1000); TH1F * histoGenN_plusTTRapidity = new TH1F("GenN_plusTTRapidity", "GenN_plusTTRapidity", 20, -2.5, 2.5); histoGenN_plusTTRapidity->Sumw2(); TH1F * histoGenN_plusTTPt = new TH1F("GenN_plusTTPt", "GenN_plusTTPt", 20, 0, 250); histoGenN_plusTTPt->Sumw2(); TH1F * histoGenN_plusTTMass = new TH1F("GenN_plusTTMass", "GenN_plusTTMass", 20, 0, 1000); histoGenN_plusTTMass->Sumw2(); TH1F * histoGenN_minusTTRapidity = new TH1F("GenN_minusTTRapidity", "GenN_minusTTRapidity", 20, -2.5, 2.5); histoGenN_minusTTRapidity->Sumw2(); TH1F * histoGenN_minusTTPt = new TH1F("GenN_minusTTPt", "GenN_minusTTPt", 20, 0, 250); histoGenN_minusTTPt->Sumw2(); TH1F * histoGenN_minusTTMass = new TH1F("GenN_minusTTMass", "GenN_minusTTMass", 20, 0, 1000); histoGenN_minusTTMass->Sumw2(); TH1F * histoGenN_plusMinusN_minusTTRapidity = new TH1F("GenN_plusMinusN_minusTTRapidity", "GenN_plusMinusN_minusTTRapidity", 20, -2.5, 2.5); histoGenN_plusMinusN_minusTTRapidity->Sumw2(); TH1F * histoGenN_plusPlusN_minusTTRapidity = new TH1F("GenN_plusPlusN_minusTTRapidity", "GenN_plusPlusN_minusTTRapidity", 20, -2.5, 2.5); histoGenN_plusPlusN_minusTTRapidity->Sumw2(); TH1F * histoGenN_plusMinusN_minusTTPt = new TH1F("GenN_plusMinusN_minusTTPt", "GenN_plusMinusN_minusTTPt", 20, 0, 250); histoGenN_plusMinusN_minusTTPt->Sumw2(); TH1F * histoGenN_plusPlusN_minusTTPt = new TH1F("GenN_plusPlusN_minusTTPt", "GenN_plusPlusN_minusTTPt", 20, 0, 250); histoGenN_plusPlusN_minusTTPt->Sumw2(); TH1F * histoGenN_plusMinusN_minusTTMass = new TH1F("GenN_plusMinusN_minusTTMass", "GenN_plusMinusN_minusTTMass", 20, 0, 1000); histoGenN_plusMinusN_minusTTMass->Sumw2(); TH1F * histoGenN_plusPlusN_minusTTMass = new TH1F("GenN_plusPlusN_minusTTMass", "GenN_plusPlusN_minusTTMass", 20, 0, 1000); histoGenN_plusPlusN_minusTTMass->Sumw2(); TH1F * histoGenA_cTTRapidity = new TH1F("GenA_cTTRapidity", "GenA_cTTRapidity", 20, -2.5, 2.5); histoGenA_cTTRapidity->Sumw2(); TH1F * histoGenA_cTTPt = new TH1F("GenA_cTTPt", "GenA_cTTPt", 20, 0, 250); histoGenA_cTTPt->Sumw2(); TH1F * histoGenA_cTTMass = new TH1F("GenA_cTTMass", "GenA_cTTMass", 20, 0, 1000); histoGenA_cTTMass->Sumw2(); // Fine binning TH2F * histoFineBinning_GenDelta_yVsTTRapidity = new TH2F("FineBinning_GenDelta_yVsTTRapidity", "FineBinning_GenDelta_yVsTTRapidity", 200, -2, 2, 500, -2.5, 2.5); TH2F * histoFineBinning_GenDelta_yVsTTPt = new TH2F("FineBinning_GenDelta_yVsTTPt", "FineBinning_GenDelta_yVsTTPt", 200, -2, 2, 250, 0, 250); TH2F * histoFineBinning_GenDelta_yVsTTMass = new TH2F("FineBinning_GenDelta_yVsTTMass", "FineBinning_GenDelta_yVsTTMass", 200, -2, 2, 100, 0, 1000); TH1F * histoFineBinning_GenN_plusTTRapidity = new TH1F("FineBinning_GenN_plusTTRapidity", "FineBinning_GenN_plusTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenN_plusTTRapidity->Sumw2(); TH1F * histoFineBinning_GenN_plusTTPt = new TH1F("FineBinning_GenN_plusTTPt", "FineBinning_GenN_plusTTPt", 250, 0, 250); histoFineBinning_GenN_plusTTPt->Sumw2(); TH1F * histoFineBinning_GenN_plusTTMass = new TH1F("FineBinning_GenN_plusTTMass", "FineBinning_GenN_plusTTMass", 100, 0, 1000); histoFineBinning_GenN_plusTTMass->Sumw2(); TH1F * histoFineBinning_GenN_minusTTRapidity = new TH1F("FineBinning_GenN_minusTTRapidity", "FineBinning_GenN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_GenN_minusTTPt = new TH1F("FineBinning_GenN_minusTTPt", "FineBinning_GenN_minusTTPt", 250, 0, 250); histoFineBinning_GenN_minusTTPt->Sumw2(); TH1F * histoFineBinning_GenN_minusTTMass = new TH1F("FineBinning_GenN_minusTTMass", "FineBinning_GenN_minusTTMass", 100, 0, 1000); histoFineBinning_GenN_minusTTMass->Sumw2(); TH1F * histoFineBinning_GenN_plusMinusN_minusTTRapidity = new TH1F("FineBinning_GenN_plusMinusN_minusTTRapidity", "FineBinning_GenN_plusMinusN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenN_plusMinusN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_GenN_plusPlusN_minusTTRapidity = new TH1F("FineBinning_GenN_plusPlusN_minusTTRapidity", "FineBinning_GenN_plusPlusN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenN_plusPlusN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_GenN_plusMinusN_minusTTPt = new TH1F("FineBinning_GenN_plusMinusN_minusTTPt", "FineBinning_GenN_plusMinusN_minusTTPt", 250, 0, 250); histoFineBinning_GenN_plusMinusN_minusTTPt->Sumw2(); TH1F * histoFineBinning_GenN_plusPlusN_minusTTPt = new TH1F("FineBinning_GenN_plusPlusN_minusTTPt", "FineBinning_GenN_plusPlusN_minusTTPt", 250, 0, 250); histoFineBinning_GenN_plusPlusN_minusTTPt->Sumw2(); TH1F * histoFineBinning_GenN_plusMinusN_minusTTMass = new TH1F("FineBinning_GenN_plusMinusN_minusTTMass", "FineBinning_GenN_plusMinusN_minusTTMass", 100, 0, 1000); histoFineBinning_GenN_plusMinusN_minusTTMass->Sumw2(); TH1F * histoFineBinning_GenN_plusPlusN_minusTTMass = new TH1F("FineBinning_GenN_plusPlusN_minusTTMass", "FineBinning_GenN_plusPlusN_minusTTMass", 100, 0, 1000); histoFineBinning_GenN_plusPlusN_minusTTMass->Sumw2(); TH1F * histoFineBinning_GenA_cTTRapidity = new TH1F("FineBinning_GenA_cTTRapidity", "FineBinning_GenA_cTTRapidity", 500, -2.5, 2.5); histoFineBinning_GenA_cTTRapidity->Sumw2(); TH1F * histoFineBinning_GenA_cTTPt = new TH1F("FineBinning_GenA_cTTPt", "FineBinning_GenA_cTTPt", 250, 0, 250); histoFineBinning_GenA_cTTPt->Sumw2(); TH1F * histoFineBinning_GenA_cTTMass = new TH1F("FineBinning_GenA_cTTMass", "FineBinning_GenA_cTTMass", 100, 0, 1000); histoFineBinning_GenA_cTTMass->Sumw2(); // RECO TH1F * histoRecoTopRapidity1 = new TH1F("RecoTopRapidity1", "RecoTopRapidity1", 100, -5, 5); TH1F * histoRecoTopRapidity2 = new TH1F("RecoTopRapidity2", "RecoTopRapidity2", 100, -5, 5); TH1F * histoRecoLeptonRapidity1 = new TH1F("RecoLeptonRapidity1", "RecoLeptonRapidity1", 100, -5, 5); TH1F * histoRecoLeptonRapidity2 = new TH1F("RecoLeptonRapidity2", "RecoLeptonRapidity2", 100, -5, 5); TH1F * histoRecoTopMass1 = new TH1F("RecoTopMass1", "RecoTopMass1", 300, 0, 300); TH1F * histoRecoTopMass2 = new TH1F("RecoTopMass2", "RecoTopMass2", 300, 0, 300); TH2F * histoRecoTopMass1VsTopMass2 = new TH2F("RecoTopMass1VsTopMass2", "RecoTopMass1VsTopMass2", 300, 0, 300, 300, 0, 300); TH1F * histoRecoDelta_y = new TH1F("RecoDelta_y", "RecoDelta_y", 400, -2, 2); TH1F * histoRecoTTRapidity = new TH1F("RecoTTRapidity", "RecoTTRapidity", 500, -2.5, 2.5); TH1F * histoRecoTTPt = new TH1F("RecoTTPt", "RecoTTPt", 250, 0, 250); TH1F * histoRecoTTMass = new TH1F("RecoTTMass", "RecoTTMass", 100, 0, 1000); TH2F * histoRecoDelta_yVsTTRapidity = new TH2F("RecoDelta_yVsTTRapidity", "RecoDelta_yVsTTRapidity", 10, -2, 2, 5, -2.5, 2.5); TH2F * histoRecoDelta_yVsTTPt = new TH2F("RecoDelta_yVsTTPt", "RecoDelta_yVsTTPt", 10, -2, 2, 5, 0, 250); TH2F * histoRecoDelta_yVsTTMass = new TH2F("RecoDelta_yVsTTMass", "RecoDelta_yVsTTMass", 10, -2, 2, 5, 0, 1000); TH1F * histoRecoN_plusTTRapidity = new TH1F("RecoN_plusTTRapidity", "RecoN_plusTTRapidity", 20, -2.5, 2.5); histoRecoN_plusTTRapidity->Sumw2(); TH1F * histoRecoN_plusTTPt = new TH1F("RecoN_plusTTPt", "RecoN_plusTTPt", 20, 0, 250); histoRecoN_plusTTPt->Sumw2(); TH1F * histoRecoN_plusTTMass = new TH1F("RecoN_plusTTMass", "RecoN_plusTTMass", 20, 0, 1000); histoRecoN_plusTTMass->Sumw2(); TH1F * histoRecoN_minusTTRapidity = new TH1F("RecoN_minusTTRapidity", "RecoN_minusTTRapidity", 20, -2.5, 2.5); histoRecoN_minusTTRapidity->Sumw2(); TH1F * histoRecoN_minusTTPt = new TH1F("RecoN_minusTTPt", "RecoN_minusTTPt", 20, 0, 250); histoRecoN_minusTTPt->Sumw2(); TH1F * histoRecoN_minusTTMass = new TH1F("RecoN_minusTTMass", "RecoN_minusTTMass", 20, 0, 1000); histoRecoN_minusTTMass->Sumw2(); TH1F * histoRecoN_plusMinusN_minusTTRapidity = new TH1F("RecoN_plusMinusN_minusTTRapidity", "RecoN_plusMinusN_minusTTRapidity", 20, -2.5, 2.5); histoRecoN_plusMinusN_minusTTRapidity->Sumw2(); TH1F * histoRecoN_plusPlusN_minusTTRapidity = new TH1F("RecoN_plusPlusN_minusTTRapidity", "RecoN_plusPlusN_minusTTRapidity", 20, -2.5, 2.5); histoRecoN_plusPlusN_minusTTRapidity->Sumw2(); TH1F * histoRecoN_plusMinusN_minusTTPt = new TH1F("RecoN_plusMinusN_minusTTPt", "RecoN_plusMinusN_minusTTPt", 20, 0, 250); histoRecoN_plusMinusN_minusTTPt->Sumw2(); TH1F * histoRecoN_plusPlusN_minusTTPt = new TH1F("RecoN_plusPlusN_minusTTPt", "RecoN_plusPlusN_minusTTPt", 20, 0, 250); histoRecoN_plusPlusN_minusTTPt->Sumw2(); TH1F * histoRecoN_plusMinusN_minusTTMass = new TH1F("RecoN_plusMinusN_minusTTMass", "RecoN_plusMinusN_minusTTMass", 20, 0, 1000); histoRecoN_plusMinusN_minusTTMass->Sumw2(); TH1F * histoRecoN_plusPlusN_minusTTMass = new TH1F("RecoN_plusPlusN_minusTTMass", "RecoN_plusPlusN_minusTTMass", 20, 0, 1000); histoRecoN_plusPlusN_minusTTMass->Sumw2(); TH1F * histoRecoA_cTTRapidity = new TH1F("RecoA_cTTRapidity", "RecoA_cTTRapidity", 20, -2.5, 2.5); histoRecoA_cTTRapidity->Sumw2(); TH1F * histoRecoA_cTTPt = new TH1F("RecoA_cTTPt", "RecoA_cTTPt", 20, 0, 250); histoRecoA_cTTPt->Sumw2(); TH1F * histoRecoA_cTTMass = new TH1F("RecoA_cTTMass", "RecoA_cTTMass", 20, 0, 1000); histoRecoA_cTTMass->Sumw2(); // Fine binning TH2F * histoFineBinning_RecoDelta_yVsTTRapidity = new TH2F("FineBinning_RecoDelta_yVsTTRapidity", "FineBinning_RecoDelta_yVsTTRapidity", 200, -2, 2, 500, -2.5, 2.5); TH2F * histoFineBinning_RecoDelta_yVsTTPt = new TH2F("FineBinning_RecoDelta_yVsTTPt", "FineBinning_RecoDelta_yVsTTPt", 200, -2, 2, 250, 0, 250); TH2F * histoFineBinning_RecoDelta_yVsTTMass = new TH2F("FineBinning_RecoDelta_yVsTTMass", "FineBinning_RecoDelta_yVsTTMass", 200, -2, 2, 100, 0, 1000); TH1F * histoFineBinning_RecoN_plusTTRapidity = new TH1F("FineBinning_RecoN_plusTTRapidity", "FineBinning_RecoN_plusTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoN_plusTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoN_plusTTPt = new TH1F("FineBinning_RecoN_plusTTPt", "FineBinning_RecoN_plusTTPt", 250, 0, 250); histoFineBinning_RecoN_plusTTPt->Sumw2(); TH1F * histoFineBinning_RecoN_plusTTMass = new TH1F("FineBinning_RecoN_plusTTMass", "FineBinning_RecoN_plusTTMass", 100, 0, 1000); histoFineBinning_RecoN_plusTTMass->Sumw2(); TH1F * histoFineBinning_RecoN_minusTTRapidity = new TH1F("FineBinning_RecoN_minusTTRapidity", "FineBinning_RecoN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoN_minusTTPt = new TH1F("FineBinning_RecoN_minusTTPt", "FineBinning_RecoN_minusTTPt", 250, 0, 250); histoFineBinning_RecoN_minusTTPt->Sumw2(); TH1F * histoFineBinning_RecoN_minusTTMass = new TH1F("FineBinning_RecoN_minusTTMass", "FineBinning_RecoN_minusTTMass", 100, 0, 1000); histoFineBinning_RecoN_minusTTMass->Sumw2(); TH1F * histoFineBinning_RecoN_plusMinusN_minusTTRapidity = new TH1F("FineBinning_RecoN_plusMinusN_minusTTRapidity", "FineBinning_RecoN_plusMinusN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoN_plusPlusN_minusTTRapidity = new TH1F("FineBinning_RecoN_plusPlusN_minusTTRapidity", "FineBinning_RecoN_plusPlusN_minusTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoN_plusMinusN_minusTTPt = new TH1F("FineBinning_RecoN_plusMinusN_minusTTPt", "FineBinning_RecoN_plusMinusN_minusTTPt", 250, 0, 250); histoFineBinning_RecoN_plusMinusN_minusTTPt->Sumw2(); TH1F * histoFineBinning_RecoN_plusPlusN_minusTTPt = new TH1F("FineBinning_RecoN_plusPlusN_minusTTPt", "FineBinning_RecoN_plusPlusN_minusTTPt", 250, 0, 250); histoFineBinning_RecoN_plusPlusN_minusTTPt->Sumw2(); TH1F * histoFineBinning_RecoN_plusMinusN_minusTTMass = new TH1F("FineBinning_RecoN_plusMinusN_minusTTMass", "FineBinning_RecoN_plusMinusN_minusTTMass", 100, 0, 1000); histoFineBinning_RecoN_plusMinusN_minusTTMass->Sumw2(); TH1F * histoFineBinning_RecoN_plusPlusN_minusTTMass = new TH1F("FineBinning_RecoN_plusPlusN_minusTTMass", "FineBinning_RecoN_plusPlusN_minusTTMass", 100, 0, 1000); histoFineBinning_RecoN_plusPlusN_minusTTMass->Sumw2(); TH1F * histoFineBinning_RecoA_cTTRapidity = new TH1F("FineBinning_RecoA_cTTRapidity", "FineBinning_RecoA_cTTRapidity", 500, -2.5, 2.5); histoFineBinning_RecoA_cTTRapidity->Sumw2(); TH1F * histoFineBinning_RecoA_cTTPt = new TH1F("FineBinning_RecoA_cTTPt", "FineBinning_RecoA_cTTPt", 250, 0, 250); histoFineBinning_RecoA_cTTPt->Sumw2(); TH1F * histoFineBinning_RecoA_cTTMass = new TH1F("FineBinning_RecoA_cTTMass", "FineBinning_RecoA_cTTMass", 100, 0, 1000); histoFineBinning_RecoA_cTTMass->Sumw2(); // RECO vs GEN TH2F * histoRecoVsGenTopRapidity1 = new TH2F("RecoVsGenTopRapidity1", "RecoVsGenTopRapidity1", 100, -5, 5, 100, -5, 5); TH2F * histoRecoVsGenTopRapidity2 = new TH2F("RecoVsGenTopRapidity2", "RecoVsGenTopRapidity2", 100, -5, 5, 100, -5, 5); TH2F * histoRecoVsGenTopMass1 = new TH2F("RecoVsGenTopMass1", "RecoVsGenTopMass1", 300, 0, 300, 200, 0, 200); TH2F * histoRecoVsGenTopMass2 = new TH2F("RecoVsGenTopMass2", "RecoVsGenTopMass2", 300, 0, 300, 200, 0, 200); TH1F * histoRecoMinusGenDivGenTopRapidity1 = new TH1F("RecoMinusGenDivGenTopRapidity1", "RecoMinusGenDivGenTopRapidity1", 100, -3, 3); TH1F * histoRecoMinusGenDivGenTopRapidity2 = new TH1F("RecoMinusGenDivGenTopRapidity2", "RecoMinusGenDivGenTopRapidity2", 100, -3, 3); TH1F * histoRecoMinusGenDivGenLeptonRapidity1 = new TH1F("RecoMinusGenDivGenLeptonRapidity1", "RecoMinusGenDivGenLeptonRapidity1", 100, -3, 3); TH1F * histoRecoMinusGenDivGenLeptonRapidity2 = new TH1F("RecoMinusGenDivGenLeptonRapidity2", "RecoMinusGenDivGenLeptonRapidity2", 100, -3, 3); TH1F * histoRecoMinusGenDivGenTopMass1 = new TH1F("RecoMinusGenDivGenTopMass1", "RecoMinusGenDivGenTopMass1", 100, -3, 3); TH1F * histoRecoMinusGenDivGenTopMass2 = new TH1F("RecoMinusGenDivGenTopMass2", "RecoMinusGenDivGenTopMass2", 100, -3, 3); TH2F * histoFineBinning_RecoVsGenDelta_y = new TH2F("FineBinning_RecoVsGenDelta_y", "FineBinning_RecoVsGenDelta_y", 400, -2, 2, 400, -2, 2); // Migration Matrix TH2F * histoRecoVsGenDelta_y = new TH2F("RecoVsGenDelta_y", "RecoVsGenDelta_y", 8, -2, 2, 16, -2, 2); // Migration Matrix TH1F * histoRecoMinusGenDivGenDelta_y = new TH1F("RecoMinusGenDivGenDelta_y", "RecoMinusGenDivGenDelta_y", 100, -3, 3); TH2F * histoRecoVsGenTTRapidity = new TH2F("RecoVsGenTTRapidity", "RecoVsGenTTRapidity", 500, -2.5, 2.5, 500, -2.5, 2.5); TH1F * histoRecoMinusGenDivGenTTRapidity = new TH1F("RecoMinusGenDivGenTTRapidity", "RecoMinusGenDivGenTTRapidity", 100, -3, 3); TH2F * histoRecoVsGenTTPt = new TH2F("RecoVsGenTTPt", "RecoVsGenTTPt", 250, 0, 250, 250, 0, 250); TH1F * histoRecoMinusGenDivGenTTPt = new TH1F("RecoMinusGenDivGenTTPt", "RecoMinusGenDivGenTTPt", 100, -3, 3); TH2F * histoRecoVsGenTTMass = new TH2F("RecoVsGenTTMass", "RecoVsGenTTMass", 100, 0, 1000, 100, 0, 1000); TH1F * histoRecoMinusGenDivGenTTMass = new TH1F("RecoMinusGenDivGenTTMass", "RecoMinusGenDivGenTTMass", 100, -3, 3); TH1F * histoDelta_yEfficiencyN = new TH1F("Delta_yEfficiencyN", "Delta_yEfficiencyN", 10, -2, 2); TH1F * histoDelta_yEfficiencyD = new TH1F("Delta_yEfficiencyD", "Delta_yEfficiencyD", 10, -2, 2); TH1F * histoDelta_yEfficiency = new TH1F("Delta_yEfficiency", "Delta_yEfficiency", 10, -2, 2); TH2F * histoDelta_yVsTTRapidityEfficiency = new TH2F("Delta_yVsTTRapidityEfficiency", "Delta_yVsTTRapidityEfficiency", 10, -2, 2, 5, -2.5, 2.5); TH2F * histoDelta_yVsTTPtEfficiency = new TH2F("Delta_yVsTTPtEfficiency", "Delta_yVsTTPtEfficiency", 10, -2, 2, 5, 0, 250); TH2F * histoDelta_yVsTTMassEfficiency = new TH2F("Delta_yVsTTMassEfficiency", "Delta_yVsTTMassEfficiency", 10, -2, 2, 5, 0, 1000); // Fine binning TH1F * histoFineBinning_Delta_yEfficiencyN = new TH1F("FineBinning_Delta_yEfficiencyN", "FineBinning_Delta_yEfficiencyN", 200, -2, 2); TH1F * histoFineBinning_Delta_yEfficiencyD = new TH1F("FineBinning_Delta_yEfficiencyD", "FineBinning_Delta_yEfficiencyD", 200, -2, 2); TH1F * histoFineBinning_Delta_yEfficiency = new TH1F("FineBinning_Delta_yEfficiency", "FineBinning_Delta_yEfficiency", 200, -2, 2); TH2F * histoFineBinning_Delta_yVsTTRapidityEfficiency = new TH2F("FineBinning_Delta_yVsTTRapidityEfficiency", "FineBinning_Delta_yVsTTRapidityEfficiency", 200, -2, 2, 500, -2.5, 2.5); TH2F * histoFineBinning_Delta_yVsTTPtEfficiency = new TH2F("FineBinning_Delta_yVsTTPtEfficiency", "FineBinning_Delta_yVsTTPtEfficiency", 200, -2, 2, 250, 0, 250); TH2F * histoFineBinning_Delta_yVsTTMassEfficiency = new TH2F("FineBinning_Delta_yVsTTMassEfficiency", "FineBinning_Delta_yVsTTMassEfficiency", 200, -2, 2, 100, 0, 1000); vector < Dataset > datasets; DiLeptonSelection sel; float Luminosity = 0; // 0: MC - 1: Data - 2 Data & MC int DataType = 0; int verbosity = -1; // Analysis variables int step; //4-vectors vector < TLorentzVector > nu1; vector < TLorentzVector > nu2; // TLorentzVector lvTop1_aux; //TLorentzVector lvTop2_aux; ////////////////////// ////////////////////// // Initialisation ////////////////////// AnalysisEnvironmentLoader anaEL (xmlFileName); anaEL.LoadSamples (datasets); // now the list of datasets written in the xml file is known anaEL.LoadDiLeptonSelection (sel); // now the parameters for the selection are given to the selection anaEL.LoadGeneralInfo(DataType, Luminosity, verbosity ); float weight_MC; int nEvents; int firstEvent; int initialEvents; anaEL.LoadAnalysisInfo("Run", "firstEvent", firstEvent); anaEL.LoadAnalysisInfo("Run", "nEvents", nEvents); anaEL.LoadAnalysisInfo("Run", "initialEvents", initialEvents); string channelName; anaEL.LoadAnalysisInfo("MassAnalysis", "ChannelName", channelName); anaEL.LoadWeight (sel); // now the parameters for SFBweight are initialized (for b-tag!) //****************************************** //Load Scale Factors for lepton efficiencies //****************************************** sel.LoadElScaleFactors(); sel.LoadMuScaleFactors(); sel.InitJESUnc(); bool nonskimmed = true; TopTree::NTEvent * event = 0; TFile * TupleFile = new TFile("TupleFileNonSkimmed_TTbarSignalPowheg.root","RECREATE"); float mttbar_rec, mttbar_gen; float diffysquare_rec, diffysquare_gen; float diffabseta_rec, diffabseta_gen; float weight; float pt_ttbar, pt_ttbar_gen; float pz_ttbar, pz_ttbar_gen; float eta_ttbar_rec, eta_ttbar_gen; float y_ttbar_rec, y_ttbar_gen; float diffabsy_rec, diffabsy_gen; TTree *tree = new TTree("Tuple","Tuple"); tree->Branch("mttbar_rec",&mttbar_rec,"mttbar_rec/F"); tree->Branch("mttbar_gen",&mttbar_gen,"mttbar_gen/F"); tree->Branch("diffysquare_rec",&diffysquare_rec,"diffysquare_rec/F"); tree->Branch("diffysquare_gen",&diffysquare_gen,"diffysquare_gen/F"); tree->Branch("diffabseta_rec",&diffabseta_rec,"diffabseta_rec/F"); tree->Branch("diffabseta_gen",&diffabseta_gen,"diffabseta_gen/F"); tree->Branch("weight",&weight,"weight/F"); tree->Branch("pt_ttbar",&pt_ttbar,"pt_ttbar/F"); tree->Branch("pt_ttbar_gen",&pt_ttbar_gen,"pt_ttbar_gen/F"); tree->Branch("pz_ttbar",&pz_ttbar,"pz_ttbar/F"); tree->Branch("pz_ttbar_gen",&pz_ttbar_gen,"pz_ttbar_gen/F"); tree->Branch("eta_ttbar_rec",&eta_ttbar_rec,"eta_ttbar_rec/F"); tree->Branch("eta_ttbar_gen",&eta_ttbar_gen,"eta_ttbar_gen/F"); tree->Branch("y_ttbar_rec",&y_ttbar_rec,"y_ttbar_rec/F"); tree->Branch("y_ttbar_gen",&y_ttbar_gen,"y_ttbar_gen/F"); tree->Branch("diffabsy_rec",&diffabsy_rec,"diffabsy_rec/F"); tree->Branch("diffabsy_gen",&diffabsy_gen,"diffabsy_gen/F"); ////////////////////// //LOOP OVER THE DATASETS ////////////////////// if(verbosity>0) { cout<<"#########################"<<endl; cout<<" Loop over the datasets "<<endl; cout<<"#########################"<<endl; } float num_mttbar_eff = 0.; float den_mttbar_eff = 0.; for (unsigned int d = 0; d < datasets.size (); d++) { weight_MC = datasets[d].NormFactor()*Luminosity; if(datasets[d].isData() == true) weight_MC = 1.; cout << "isDATA" << endl; AMWT amwt(anaEL, datasets[d].isData()); TString sample_name(datasets[d].Name()); bool isData = datasets[d].isData (); datasets[d].eventTree ()->SetBranchAddress ("NTEvent",&event); cout << "Sample : " << sample_name<< endl; cout << "Data : " << isData<< endl; unsigned int nEventsSample = (int) (datasets[d].eventTree ()->GetEntries ()); unsigned int endEventToRun; if (firstEvent>nEventsSample) firstEvent = nEventsSample; if ((nEvents==-1)||((nEvents+firstEvent)>nEventsSample)) endEventToRun = nEventsSample; else endEventToRun = nEvents+firstEvent; cout << "Events to run: number / first / last / all: " << endEventToRun-firstEvent << " / " << firstEvent << " / " << endEventToRun << " / " << nEventsSample << endl; // Standard parameters for doFullSelection: bool applyEEScale = false; float EEScaleParam = 1.; bool applyEEResol = false; float EEResolParam = 1.; bool applyMEScale = false; float MEScaleParam = 1.; bool applyMEResol = false; float MEResolParam = 1.; bool applyMETS = false; float METScale = 1.; bool applyJES = false; float JESParam = 1.; bool applyJER = false; float JERFactor = 0.; ////////////////////// //LOOP OVER THE EVENTS ////////////////////// float N_plus_reco = 0; float N_minus_reco = 0; float N_plus_gen = 0; float N_minus_gen = 0; mttbar_rec = 0; mttbar_gen = 0; diffysquare_rec = 0; diffysquare_gen = 0; diffabseta_rec = 0; diffabseta_gen = 0; weight = weight_MC; pt_ttbar = 0; pt_ttbar_gen = 0; pz_ttbar = 0; pz_ttbar_gen = 0; eta_ttbar_rec = 0; eta_ttbar_gen = 0; y_ttbar_rec = 0; y_ttbar_gen = 0; diffabsy_rec = 0; diffabsy_gen = 0; for (unsigned int ievt = firstEvent; ievt < endEventToRun; ievt++) { // for (unsigned int ievt = 0; ievt < 10; ievt++) { datasets[d].eventTree ()->GetEntry (ievt); if(ievt%1000 == 0) cout << "number of processed events " << ievt << endl; if (verbosity >= 1) cout << "Event : "<< event->runNb<<" , " << event->lumiblock <<" , " << event->eventNb<<endl; if(!(event->TMEME == 2 || event->TMEME == 10101 || event->TMEME == 20200 || event->TMEME == 20 || event->TMEME == 11010 || event->TMEME == 22000|| event->TMEME == 11 || event->TMEME == 11001 || event->TMEME == 10110 || event->TMEME == 21100 )) continue; string candType; vector<NTElectron> candElec; vector<NTMuon> candMuon; //Load event for the selection sel.LoadEvent(event); int finalCut = sel.doFullSelection(&(datasets[d]), channelName, false, /*print*/ verbosity, false, false, -1., -1., applyJES, JESParam, applyEEScale, EEScaleParam, applyEEResol, EEResolParam, applyMEScale, MEScaleParam, applyJER, JERFactor, applyMETS, METScale); TLorentzVector lvTop1_gen; TLorentzVector lvTop2_gen; TLorentzVector lvTop1plusTop2_gen; float yt_gen = 0.; float ytbar_gen = 0.; float Delta_y_gen = 0.; if(datasets[d].Name() == "TTJets_Sig"){ lvTop1_gen = (event->topAndDecays)[0].p4_t_gen; lvTop2_gen = (event->topAndDecays)[1].p4_t_gen; lvTop1plusTop2_gen = lvTop1_gen + lvTop2_gen; ///////////////////////// //// GENERATOR LEVEL //// ///////////////////////// histoGenTopRapidity1->Fill(lvTop1_gen.Rapidity()); histoGenTopRapidity2->Fill(lvTop2_gen.Rapidity()); histoGenTopMass1->Fill(lvTop1_gen.M()); histoGenTopMass2->Fill(lvTop2_gen.M()); histoGenTopMass1VsTopMass2->Fill(lvTop1_gen.M(),lvTop2_gen.M()); yt_gen = lvTop1_gen.Rapidity(); if(yt_gen<0.) yt_gen = (-1)*yt_gen; ytbar_gen = lvTop2_gen.Rapidity(); if(ytbar_gen<0.) ytbar_gen = (-1)*ytbar_gen; Delta_y_gen = yt_gen - ytbar_gen; // cout << "Delta_y_gen:" << Delta_y_gen << endl; histoGenDelta_y->Fill(Delta_y_gen); histoDelta_yEfficiencyD->Fill(Delta_y_gen); histoFineBinning_Delta_yEfficiencyD->Fill(Delta_y_gen); if(Delta_y_gen>0.){ N_plus_gen++; histoGenN_plusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoGenN_plusTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoGenN_plusTTMass->Fill(lvTop1plusTop2_gen.M()); histoFineBinning_GenN_plusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoFineBinning_GenN_plusTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoFineBinning_GenN_plusTTMass->Fill(lvTop1plusTop2_gen.M()); } if(Delta_y_gen<0.){ N_minus_gen++; histoGenN_minusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoGenN_minusTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoGenN_minusTTMass->Fill(lvTop1plusTop2_gen.M()); histoFineBinning_GenN_minusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoFineBinning_GenN_minusTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoFineBinning_GenN_minusTTMass->Fill(lvTop1plusTop2_gen.M()); } histoGenTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity()); histoGenTTPt->Fill(lvTop1plusTop2_gen.Perp()); histoGenTTMass->Fill(lvTop1plusTop2_gen.M()); histoGenDelta_yVsTTRapidity->Fill(Delta_y_gen, lvTop1plusTop2_gen.Rapidity()); histoGenDelta_yVsTTPt->Fill(Delta_y_gen, lvTop1plusTop2_gen.Perp()); histoGenDelta_yVsTTMass->Fill(Delta_y_gen, lvTop1plusTop2_gen.M()); histoFineBinning_GenDelta_yVsTTRapidity->Fill(Delta_y_gen, lvTop1plusTop2_gen.Rapidity()); histoFineBinning_GenDelta_yVsTTPt->Fill(Delta_y_gen, lvTop1plusTop2_gen.Perp()); histoFineBinning_GenDelta_yVsTTMass->Fill(Delta_y_gen, lvTop1plusTop2_gen.M()); if(nonskimmed == true){ mttbar_gen = lvTop1plusTop2_gen.M(); diffysquare_gen = yt_gen*yt_gen - ytbar_gen*ytbar_gen; diffabseta_gen = fabs(lvTop1_gen.Eta()) - fabs(lvTop2_gen.Eta()); pt_ttbar_gen = lvTop1plusTop2_gen.Perp(); pz_ttbar_gen = lvTop1plusTop2_gen.Pz(); eta_ttbar_gen = lvTop1plusTop2_gen.Eta(); y_ttbar_gen = lvTop1plusTop2_gen.Rapidity(); diffabsy_gen = fabs(lvTop1_gen.Rapidity()) - fabs(lvTop2_gen.Rapidity()); } } if (finalCut >6) { if(nonskimmed == false){ if(datasets[d].Name() == "TTJets_Sig"){ mttbar_gen = lvTop1plusTop2_gen.M(); diffysquare_gen = yt_gen*yt_gen - ytbar_gen*ytbar_gen; diffabseta_gen = fabs(lvTop1_gen.Eta()) - fabs(lvTop2_gen.Eta()); pt_ttbar_gen = lvTop1plusTop2_gen.Perp(); pz_ttbar_gen = lvTop1plusTop2_gen.Pz(); eta_ttbar_gen = lvTop1plusTop2_gen.Eta(); y_ttbar_gen = lvTop1plusTop2_gen.Rapidity(); diffabsy_gen = fabs(lvTop1_gen.Rapidity()) - fabs(lvTop2_gen.Rapidity()); } } sel.GetLeptonPair(candMuon, candElec, candType); for(unsigned int i=0; i<candMuon.size(); i++){ if(candMuon[i].Charge == +1) histoRecoLeptonRapidity1->Fill(candMuon[i].p4.Rapidity()); if(candMuon[i].Charge == -1) histoRecoLeptonRapidity2->Fill(candMuon[i].p4.Rapidity()); } for(unsigned int j=0; j<candElec.size(); j++){ if(candElec[j].Charge == +1) histoRecoLeptonRapidity1->Fill(candElec[j].p4.Rapidity()); if(candElec[j].Charge == -1) histoRecoLeptonRapidity2->Fill(candElec[j].p4.Rapidity()); } TLorentzVector lvTop1_reco; TLorentzVector lvTop2_reco; TLorentzVector lvTop1plusTop2_reco; TopMassVariables * tmv = amwt.findMass(sel, lvTop1_reco, lvTop2_reco); lvTop1plusTop2_reco = lvTop1_reco + lvTop2_reco; //////////////////// /// RECO LEVEL ///// //////////////////// histoRecoTopRapidity1->Fill(lvTop1_reco.Rapidity()); histoRecoTopRapidity2->Fill(lvTop2_reco.Rapidity()); histoRecoTopMass1->Fill(lvTop1_reco.M()); histoRecoTopMass2->Fill(lvTop2_reco.M()); histoRecoTopMass1VsTopMass2->Fill(lvTop1_reco.M(),lvTop2_reco.M()); float yt_reco = lvTop1_reco.Rapidity(); if(yt_reco<0.) yt_reco = (-1)*yt_reco; float ytbar_reco = lvTop2_reco.Rapidity(); if(ytbar_reco<0.) ytbar_reco = (-1)*ytbar_reco; float Delta_y_reco = yt_reco - ytbar_reco; // cout << "Delta_y_reco:" << Delta_y_reco << endl; histoRecoDelta_y->Fill(Delta_y_reco); histoDelta_yEfficiencyN->Fill(Delta_y_reco); histoFineBinning_Delta_yEfficiencyN->Fill(Delta_y_reco); if(Delta_y_reco>0.){ N_plus_reco++; histoRecoN_plusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoRecoN_plusTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoRecoN_plusTTMass->Fill(lvTop1plusTop2_reco.M()); histoFineBinning_RecoN_plusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoFineBinning_RecoN_plusTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoFineBinning_RecoN_plusTTMass->Fill(lvTop1plusTop2_reco.M()); } if(Delta_y_reco<0.){ N_minus_reco++; histoRecoN_minusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoRecoN_minusTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoRecoN_minusTTMass->Fill(lvTop1plusTop2_reco.M()); histoFineBinning_RecoN_minusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoFineBinning_RecoN_minusTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoFineBinning_RecoN_minusTTMass->Fill(lvTop1plusTop2_reco.M()); } histoRecoTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity()); histoRecoTTPt->Fill(lvTop1plusTop2_reco.Perp()); histoRecoTTMass->Fill(lvTop1plusTop2_reco.M()); histoRecoDelta_yVsTTRapidity->Fill(Delta_y_reco, lvTop1plusTop2_reco.Rapidity()); histoRecoDelta_yVsTTPt->Fill(Delta_y_reco, lvTop1plusTop2_reco.Perp()); histoRecoDelta_yVsTTMass->Fill(Delta_y_reco, lvTop1plusTop2_reco.M()); histoFineBinning_RecoDelta_yVsTTRapidity->Fill(Delta_y_reco, lvTop1plusTop2_reco.Rapidity()); histoFineBinning_RecoDelta_yVsTTPt->Fill(Delta_y_reco, lvTop1plusTop2_reco.Perp()); histoFineBinning_RecoDelta_yVsTTMass->Fill(Delta_y_reco, lvTop1plusTop2_reco.M()); if(nonskimmed == false){ mttbar_rec = lvTop1plusTop2_reco.M(); diffysquare_rec = yt_reco*yt_reco - ytbar_reco*ytbar_reco; diffabseta_rec = fabs(lvTop1_reco.Eta()) - fabs(lvTop2_reco.Eta()); pt_ttbar = lvTop1plusTop2_reco.Perp(); pz_ttbar = lvTop1plusTop2_reco.Pz(); eta_ttbar_rec = lvTop1plusTop2_reco.Eta(); y_ttbar_rec = lvTop1plusTop2_reco.Rapidity(); diffabsy_rec = fabs(lvTop1_reco.Rapidity()) - fabs(lvTop2_reco.Rapidity()); } //////////////////////// // RECO VS GEN LEVEL /// //////////////////////// if(datasets[d].Name() == "TTJets_Sig"){ histoRecoVsGenTopRapidity1->Fill(lvTop1_reco.Rapidity(), lvTop1_gen.Rapidity()); histoRecoVsGenTopRapidity2->Fill(lvTop2_reco.Rapidity(), lvTop2_gen.Rapidity()); histoRecoVsGenTopMass1->Fill(lvTop1_reco.M(), lvTop1_gen.M()); histoRecoVsGenTopMass2->Fill(lvTop2_reco.M(), lvTop2_gen.M()); histoRecoMinusGenDivGenTopRapidity1->Fill((lvTop1_reco.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity()); histoRecoMinusGenDivGenTopRapidity2->Fill((lvTop2_reco.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity()); for(unsigned int i=0; i<candMuon.size(); i++){ if(candMuon[i].Charge == +1) histoRecoMinusGenDivGenLeptonRapidity1->Fill((candMuon[i].p4.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity()); if(candMuon[i].Charge == -1) histoRecoMinusGenDivGenLeptonRapidity2->Fill((candMuon[i].p4.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity()); } for(unsigned int j=0; j<candElec.size(); j++){ if(candElec[j].Charge == +1) histoRecoMinusGenDivGenLeptonRapidity1->Fill((candElec[j].p4.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity()); if(candElec[j].Charge == -1) histoRecoMinusGenDivGenLeptonRapidity2->Fill((candElec[j].p4.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity()); } histoRecoMinusGenDivGenTopMass1->Fill((lvTop1_reco.M() - lvTop1_gen.M())/lvTop1_gen.M()); histoRecoMinusGenDivGenTopMass2->Fill((lvTop2_reco.M() - lvTop2_gen.M())/lvTop2_gen.M()); histoRecoVsGenDelta_y->Fill(Delta_y_reco, Delta_y_gen); histoFineBinning_RecoVsGenDelta_y->Fill(Delta_y_reco, Delta_y_gen); histoRecoMinusGenDivGenDelta_y->Fill((Delta_y_reco - Delta_y_gen)/Delta_y_gen); histoRecoVsGenTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity(),lvTop1plusTop2_gen.Rapidity()); histoRecoMinusGenDivGenTTRapidity->Fill((lvTop1plusTop2_reco.Rapidity() - lvTop1plusTop2_gen.Rapidity())/lvTop1plusTop2_gen.Rapidity()); histoRecoVsGenTTPt->Fill(lvTop1plusTop2_reco.Perp(),lvTop1plusTop2_gen.Perp()); histoRecoMinusGenDivGenTTPt->Fill((lvTop1plusTop2_reco.Perp() - lvTop1plusTop2_gen.Perp())/lvTop1plusTop2_gen.Perp()); histoRecoVsGenTTMass->Fill(lvTop1plusTop2_reco.M(),lvTop1plusTop2_gen.M()); histoRecoMinusGenDivGenTTMass->Fill((lvTop1plusTop2_reco.M() - lvTop1plusTop2_gen.M())/lvTop1plusTop2_gen.M()); } // tmv->printAll(); delete tmv; if(nonskimmed == false && mttbar_rec > 60.){ tree->Fill(); num_mttbar_eff += weight_MC;} if(nonskimmed == false) den_mttbar_eff += weight_MC; } if(nonskimmed == true) tree->Fill(); } // end of loop over evts float A_C_reco = (N_plus_reco - N_minus_reco)/(N_plus_reco + N_minus_reco); float A_C_gen = (N_plus_gen - N_minus_gen)/(N_plus_gen + N_minus_gen); cout << "A_C_gen:" << A_C_gen << endl; cout << "A_C_reco:" << A_C_reco << endl; histoGenN_plusMinusN_minusTTRapidity->Add(histoGenN_plusTTRapidity); histoGenN_plusMinusN_minusTTRapidity->Add(histoGenN_minusTTRapidity,-1); histoGenN_plusPlusN_minusTTRapidity->Add(histoGenN_plusTTRapidity); histoGenN_plusPlusN_minusTTRapidity->Add(histoGenN_minusTTRapidity); histoGenA_cTTRapidity->Divide(histoGenN_plusMinusN_minusTTRapidity, histoGenN_plusPlusN_minusTTRapidity); histoGenN_plusMinusN_minusTTPt->Add(histoGenN_plusTTPt); histoGenN_plusMinusN_minusTTPt->Add(histoGenN_minusTTPt,-1); histoGenN_plusPlusN_minusTTPt->Add(histoGenN_plusTTPt); histoGenN_plusPlusN_minusTTPt->Add(histoGenN_minusTTPt); histoGenA_cTTPt->Divide(histoGenN_plusMinusN_minusTTPt, histoGenN_plusPlusN_minusTTPt); histoGenN_plusMinusN_minusTTMass->Add(histoGenN_plusTTMass); histoGenN_plusMinusN_minusTTMass->Add(histoGenN_minusTTMass,-1); histoGenN_plusPlusN_minusTTMass->Add(histoGenN_plusTTMass); histoGenN_plusPlusN_minusTTMass->Add(histoGenN_minusTTMass); histoGenA_cTTMass->Divide(histoGenN_plusMinusN_minusTTMass, histoGenN_plusPlusN_minusTTMass); histoRecoN_plusMinusN_minusTTRapidity->Add(histoRecoN_plusTTRapidity); histoRecoN_plusMinusN_minusTTRapidity->Add(histoRecoN_minusTTRapidity,-1); histoRecoN_plusPlusN_minusTTRapidity->Add(histoRecoN_plusTTRapidity); histoRecoN_plusPlusN_minusTTRapidity->Add(histoRecoN_minusTTRapidity); histoRecoA_cTTRapidity->Divide(histoRecoN_plusMinusN_minusTTRapidity, histoRecoN_plusPlusN_minusTTRapidity); histoRecoN_plusMinusN_minusTTPt->Add(histoRecoN_plusTTPt); histoRecoN_plusMinusN_minusTTPt->Add(histoRecoN_minusTTPt,-1); histoRecoN_plusPlusN_minusTTPt->Add(histoRecoN_plusTTPt); histoRecoN_plusPlusN_minusTTPt->Add(histoRecoN_minusTTPt); histoRecoA_cTTPt->Divide(histoRecoN_plusMinusN_minusTTPt, histoRecoN_plusPlusN_minusTTPt); histoRecoN_plusMinusN_minusTTMass->Add(histoRecoN_plusTTMass); histoRecoN_plusMinusN_minusTTMass->Add(histoRecoN_minusTTMass,-1); histoRecoN_plusPlusN_minusTTMass->Add(histoRecoN_plusTTMass); histoRecoN_plusPlusN_minusTTMass->Add(histoRecoN_minusTTMass); histoRecoA_cTTMass->Divide(histoRecoN_plusMinusN_minusTTMass, histoRecoN_plusPlusN_minusTTMass); histoFineBinning_GenN_plusMinusN_minusTTRapidity->Add(histoFineBinning_GenN_plusTTRapidity); histoFineBinning_GenN_plusMinusN_minusTTRapidity->Add(histoFineBinning_GenN_minusTTRapidity,-1); histoFineBinning_GenN_plusPlusN_minusTTRapidity->Add(histoFineBinning_GenN_plusTTRapidity); histoFineBinning_GenN_plusPlusN_minusTTRapidity->Add(histoFineBinning_GenN_minusTTRapidity); histoFineBinning_GenA_cTTRapidity->Divide(histoFineBinning_GenN_plusMinusN_minusTTRapidity, histoFineBinning_GenN_plusPlusN_minusTTRapidity); histoFineBinning_GenN_plusMinusN_minusTTPt->Add(histoFineBinning_GenN_plusTTPt); histoFineBinning_GenN_plusMinusN_minusTTPt->Add(histoFineBinning_GenN_minusTTPt,-1); histoFineBinning_GenN_plusPlusN_minusTTPt->Add(histoFineBinning_GenN_plusTTPt); histoFineBinning_GenN_plusPlusN_minusTTPt->Add(histoFineBinning_GenN_minusTTPt); histoFineBinning_GenA_cTTPt->Divide(histoFineBinning_GenN_plusMinusN_minusTTPt, histoFineBinning_GenN_plusPlusN_minusTTPt); histoFineBinning_GenN_plusMinusN_minusTTMass->Add(histoFineBinning_GenN_plusTTMass); histoFineBinning_GenN_plusMinusN_minusTTMass->Add(histoFineBinning_GenN_minusTTMass,-1); histoFineBinning_GenN_plusPlusN_minusTTMass->Add(histoFineBinning_GenN_plusTTMass); histoFineBinning_GenN_plusPlusN_minusTTMass->Add(histoFineBinning_GenN_minusTTMass); histoFineBinning_GenA_cTTMass->Divide(histoFineBinning_GenN_plusMinusN_minusTTMass, histoFineBinning_GenN_plusPlusN_minusTTMass); histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Add(histoFineBinning_RecoN_plusTTRapidity); histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Add(histoFineBinning_RecoN_minusTTRapidity,-1); histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Add(histoFineBinning_RecoN_plusTTRapidity); histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Add(histoFineBinning_RecoN_minusTTRapidity); histoFineBinning_RecoA_cTTRapidity->Divide(histoFineBinning_RecoN_plusMinusN_minusTTRapidity, histoFineBinning_RecoN_plusPlusN_minusTTRapidity); histoFineBinning_RecoN_plusMinusN_minusTTPt->Add(histoFineBinning_RecoN_plusTTPt); histoFineBinning_RecoN_plusMinusN_minusTTPt->Add(histoFineBinning_RecoN_minusTTPt,-1); histoFineBinning_RecoN_plusPlusN_minusTTPt->Add(histoFineBinning_RecoN_plusTTPt); histoFineBinning_RecoN_plusPlusN_minusTTPt->Add(histoFineBinning_RecoN_minusTTPt); histoFineBinning_RecoA_cTTPt->Divide(histoFineBinning_RecoN_plusMinusN_minusTTPt, histoFineBinning_RecoN_plusPlusN_minusTTPt); histoFineBinning_RecoN_plusMinusN_minusTTMass->Add(histoFineBinning_RecoN_plusTTMass); histoFineBinning_RecoN_plusMinusN_minusTTMass->Add(histoFineBinning_RecoN_minusTTMass,-1); histoFineBinning_RecoN_plusPlusN_minusTTMass->Add(histoFineBinning_RecoN_plusTTMass); histoFineBinning_RecoN_plusPlusN_minusTTMass->Add(histoFineBinning_RecoN_minusTTMass); histoFineBinning_RecoA_cTTMass->Divide(histoFineBinning_RecoN_plusMinusN_minusTTMass, histoFineBinning_RecoN_plusPlusN_minusTTMass); histoDelta_yEfficiency->Divide(histoDelta_yEfficiencyN, histoDelta_yEfficiencyD); histoFineBinning_Delta_yEfficiency->Divide(histoFineBinning_Delta_yEfficiencyN, histoFineBinning_Delta_yEfficiencyD); for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) { for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) { float value = histoRecoDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2); histoDelta_yVsTTRapidityEfficiency->SetBinContent(bin_index1, bin_index2, value); float value_fb = histoFineBinning_RecoDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2); histoFineBinning_Delta_yVsTTRapidityEfficiency->SetBinContent(bin_index1, bin_index2, value_fb); } } for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) { for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) { float value = histoRecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2); histoDelta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value); float value_fb = histoFineBinning_RecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2); histoFineBinning_Delta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value_fb); } } for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) { for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) { float value = histoRecoDelta_yVsTTMass->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTMass->GetBinContent(bin_index1,bin_index2); histoDelta_yVsTTMassEfficiency->SetBinContent(bin_index1, bin_index2, value); float value_fb = histoFineBinning_RecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2); histoFineBinning_Delta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value_fb); } } } // end of loop over the datasets // if(verbosity>0) { cout<<"#########################"<<endl; cout<<" End of the program "<<endl; cout<<"#########################"<<endl; // } tree->Print(); TupleFile->Write(); TupleFile->Close(); TFile * fileCA = new TFile("ChargeAsymmetryResults_NonSkimmed_TTbarSignalPowheg.root","RECREATE"); // fileCA->cd(); // GEN histoGenTopRapidity1->Write(); histoGenTopRapidity2->Write(); histoGenTopMass1->Write(); histoGenTopMass2->Write(); histoGenTopMass1VsTopMass2->Write(); histoGenDelta_y->Write(); histoGenTTRapidity->Write(); histoGenTTPt->Write(); histoGenTTMass->Write(); histoGenDelta_yVsTTRapidity->Write(); histoGenDelta_yVsTTPt->Write(); histoGenDelta_yVsTTMass->Write(); histoGenN_plusTTRapidity->Write(); histoGenN_plusTTPt->Write(); histoGenN_plusTTMass->Write(); histoGenN_minusTTRapidity->Write(); histoGenN_minusTTPt->Write(); histoGenN_minusTTMass->Write(); histoGenN_plusMinusN_minusTTRapidity->Write(); histoGenN_plusPlusN_minusTTRapidity->Write(); histoGenN_plusMinusN_minusTTPt->Write(); histoGenN_plusPlusN_minusTTPt->Write(); histoGenN_plusMinusN_minusTTMass->Write(); histoGenN_plusPlusN_minusTTMass->Write(); histoGenA_cTTRapidity->Write(); histoGenA_cTTPt->Write(); histoGenA_cTTMass->Write(); histoFineBinning_GenDelta_yVsTTRapidity->Write(); histoFineBinning_GenDelta_yVsTTPt->Write(); histoFineBinning_GenDelta_yVsTTMass->Write(); histoFineBinning_GenN_plusTTRapidity->Write(); histoFineBinning_GenN_plusTTPt->Write(); histoFineBinning_GenN_plusTTMass->Write(); histoFineBinning_GenN_minusTTRapidity->Write(); histoFineBinning_GenN_minusTTPt->Write(); histoFineBinning_GenN_minusTTMass->Write(); histoFineBinning_GenN_plusMinusN_minusTTRapidity->Write(); histoFineBinning_GenN_plusPlusN_minusTTRapidity->Write(); histoFineBinning_GenN_plusMinusN_minusTTPt->Write(); histoFineBinning_GenN_plusPlusN_minusTTPt->Write(); histoFineBinning_GenN_plusMinusN_minusTTMass->Write(); histoFineBinning_GenN_plusPlusN_minusTTMass->Write(); histoFineBinning_GenA_cTTRapidity->Write(); histoFineBinning_GenA_cTTPt->Write(); histoFineBinning_GenA_cTTMass->Write(); // RECO histoRecoTopRapidity1->Write(); histoRecoTopRapidity2->Write(); histoRecoLeptonRapidity1->Write(); histoRecoLeptonRapidity2->Write(); histoRecoTopMass1->Write(); histoRecoTopMass2->Write(); histoRecoTopMass1VsTopMass2->Write(); histoRecoDelta_y->Write(); histoRecoTTRapidity->Write(); histoRecoTTPt->Write(); histoRecoTTMass->Write(); histoRecoDelta_yVsTTRapidity->Write(); histoRecoDelta_yVsTTPt->Write(); histoRecoDelta_yVsTTMass->Write(); histoRecoN_plusTTRapidity->Write(); histoRecoN_plusTTPt->Write(); histoRecoN_plusTTMass->Write(); histoRecoN_minusTTRapidity->Write(); histoRecoN_minusTTPt->Write(); histoRecoN_minusTTMass->Write(); histoRecoN_plusMinusN_minusTTRapidity->Write(); histoRecoN_plusPlusN_minusTTRapidity->Write(); histoRecoN_plusMinusN_minusTTPt->Write(); histoRecoN_plusPlusN_minusTTPt->Write(); histoRecoN_plusMinusN_minusTTMass->Write(); histoRecoN_plusPlusN_minusTTMass->Write(); histoRecoA_cTTRapidity->Write(); histoRecoA_cTTPt->Write(); histoRecoA_cTTMass->Write(); histoFineBinning_RecoDelta_yVsTTRapidity->Write(); histoFineBinning_RecoDelta_yVsTTPt->Write(); histoFineBinning_RecoDelta_yVsTTMass->Write(); histoFineBinning_RecoN_plusTTRapidity->Write(); histoFineBinning_RecoN_plusTTPt->Write(); histoFineBinning_RecoN_plusTTMass->Write(); histoFineBinning_RecoN_minusTTRapidity->Write(); histoFineBinning_RecoN_minusTTPt->Write(); histoFineBinning_RecoN_minusTTMass->Write(); histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Write(); histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Write(); histoFineBinning_RecoN_plusMinusN_minusTTPt->Write(); histoFineBinning_RecoN_plusPlusN_minusTTPt->Write(); histoFineBinning_RecoN_plusMinusN_minusTTMass->Write(); histoFineBinning_RecoN_plusPlusN_minusTTMass->Write(); histoFineBinning_RecoA_cTTRapidity->Write(); histoFineBinning_RecoA_cTTPt->Write(); histoFineBinning_RecoA_cTTMass->Write(); // RECO vs GEN histoRecoVsGenTopRapidity1->Write(); histoRecoVsGenTopRapidity2->Write(); histoRecoMinusGenDivGenLeptonRapidity1->Write(); histoRecoMinusGenDivGenLeptonRapidity2->Write(); histoRecoMinusGenDivGenTopRapidity1->Write(); histoRecoMinusGenDivGenTopRapidity2->Write(); histoRecoVsGenTopMass1->Write(); histoRecoVsGenTopMass2->Write(); histoRecoMinusGenDivGenTopMass1->Write(); histoRecoMinusGenDivGenTopMass2->Write(); histoRecoVsGenDelta_y->Write(); histoFineBinning_RecoVsGenDelta_y->Write(); histoRecoMinusGenDivGenDelta_y->Write(); histoRecoVsGenTTRapidity->Write(); histoRecoMinusGenDivGenTTRapidity->Write(); histoRecoVsGenTTPt->Write(); histoRecoMinusGenDivGenTTPt->Write(); histoRecoVsGenTTMass->Write(); histoRecoMinusGenDivGenTTMass->Write(); histoDelta_yEfficiencyN->Write(); histoDelta_yEfficiencyD->Write(); histoDelta_yEfficiency->Write(); histoDelta_yVsTTRapidityEfficiency->Write(); histoDelta_yVsTTPtEfficiency->Write(); histoDelta_yVsTTMassEfficiency->Write(); histoFineBinning_Delta_yEfficiencyN->Write(); histoFineBinning_Delta_yEfficiencyD->Write(); histoFineBinning_Delta_yEfficiency->Write(); histoFineBinning_Delta_yVsTTRapidityEfficiency->Write(); histoFineBinning_Delta_yVsTTPtEfficiency->Write(); histoFineBinning_Delta_yVsTTMassEfficiency->Write(); // fileCA->Write(); fileCA->Close(); delete fileCA; cout << "num_mttbar_eff = " << num_mttbar_eff << endl; cout << "den_mttbar_eff = " << den_mttbar_eff << endl; cout << "mttbar_eff = " << num_mttbar_eff / den_mttbar_eff << endl; return (0); }
void MakeTree_2015(const char* inputOniaTree = "../All_v2.24_Histos_Runs_211739-211831_GlbGlb_woPileUpRej_allPV.root", //miniUpsilon_Histos_Runs_210498-211631_HFvars_paapJune28.root", // const char* runNumber = "211739-211831", // const char* runNumber = "210498-211631",// whole pA run, with wrong alignment // const char* runNumber = "gt210658-211631", const char* runNumber = "HIN-15-001", //const char* runNumber = "a", float newVtxProbCut = 0.01,// default in the input tree is already 0.01 float ptcut = 0., // single muon cut pt int nTriggerBit = 2, // const char* dataSource= "upsiMiniTree_pp276tev_5p41_ptmu4_woPileup_june27", // const char* dataSource= "upsiMiniTree_pA5tev_ptmu4_octb15_chunk1_runGT210658", const char* dataSource= "upsiMiniTree_pp2p76tev_noIDVars_GlbGlb", // const char* dataSource= "upsiMiniTree_pp7tev_dimu0v1_ptmu4", // const char* dataSource= "upsiMiniTree_aa276tevC50100_ppofficial_trktrk_ptmu4", bool isAArereco = false,// only for newly processed AA; old tree is with triger v1,v2 included bool bAllTriggers = false, bool addExtraCentrality = true, bool excludeWrongAlign_pa = false ) { gROOT->Macro("setTDRStyle_modified.C+"); float mass_min = 7.0; float mass_max = 14.0; int nBins = 30; TFile *f = TFile::Open(Form("%s",inputOniaTree)); TTree *t = (TTree*)f->Get("myTree"); Long64_t nentries = t->GetEntries(); cout<<"Got the tree!"<<endl; cout << nentries << endl; const int NMAX=1000000; UInt_t eventNb; UInt_t runNb; Int_t Centrality; Int_t HLTriggers; Int_t Reco_QQ_size; Int_t Reco_QQ_type[NMAX]; Int_t Reco_QQ_sign[NMAX]; Int_t Reco_QQ_NtrkDeltaR03[NMAX]; Int_t Reco_QQ_NtrkDeltaR04[NMAX]; Int_t Reco_QQ_NtrkDeltaR05[NMAX]; Int_t Reco_QQ_NtrkPt04[NMAX]; Int_t Reco_QQ_NtrkPt03[NMAX]; Int_t Reco_QQ_NtrkPt02[NMAX]; Float_t Reco_QQ_ctau[NMAX]; Float_t Reco_QQ_ctauErr[NMAX]; Float_t Reco_QQ_ctauTrue[NMAX]; Float_t Reco_QQ_VtxProb[NMAX]; float Reco_QQ_dca[NMAX]; // new float, unused in upsilon Int_t Reco_QQ_trig[NMAX]; Float_t zVtx; int Reco_QQ_mupl_nTrkHits[NMAX]; float Reco_QQ_mupl_normChi2_inner[NMAX]; float Reco_QQ_mupl_normChi2_global[NMAX]; float Reco_QQ_mupl_dxy[NMAX]; float Reco_QQ_mupl_dxyErr[NMAX]; float Reco_QQ_mupl_dz[NMAX]; float Reco_QQ_mupl_dzErr[NMAX]; Bool_t Reco_QQ_mupl_TrkMuArb[NMAX]; Bool_t Reco_QQ_mupl_TMOneStaTight[NMAX]; // new bool, unused in upsilon(?) int Reco_QQ_mupl_nMuValHits[NMAX]; // new int, unused in upsilon int Reco_QQ_mupl_nPixWMea[NMAX]; // new int, unused in upsilon int Reco_QQ_mupl_nTrkWMea[NMAX]; // new int, unused in upsilon int Reco_QQ_mupl_StationsMatched[NMAX]; // new int, unused in Upsilon float Reco_QQ_mupl_pt_inner[NMAX]; // new float, unused. float Reco_QQ_mupl_pt_global[NMAX]; //new float, unused. float Reco_QQ_mupl_ptErr_inner[NMAX]; // new float, unused. float Reco_QQ_mupl_ptErr_global[NMAX]; //new float, unused. int Reco_QQ_mumi_nTrkHits[NMAX]; float Reco_QQ_mumi_normChi2_inner[NMAX]; float Reco_QQ_mumi_normChi2_global[NMAX]; float Reco_QQ_mumi_dxy[NMAX]; float Reco_QQ_mumi_dxyErr[NMAX]; float Reco_QQ_mumi_dz[NMAX]; float Reco_QQ_mumi_dzErr[NMAX]; Bool_t Reco_QQ_mumi_TrkMuArb[NMAX]; Bool_t Reco_QQ_mumi_TMOneStaTight[NMAX]; // new bool, unused in upsilon(?) int Reco_QQ_mumi_nMuValHits[NMAX]; // new int, unused in upsilon int Reco_QQ_mumi_nPixWMea[NMAX]; // new int, unused in upsilon int Reco_QQ_mumi_nTrkWMea[NMAX]; // new int, unused in upsilon int Reco_QQ_mumi_StationsMatched[NMAX]; // new int, unused in Upsilon float Reco_QQ_mumi_pt_inner[NMAX]; // new float, unused. float Reco_QQ_mumi_pt_global[NMAX]; //new float, unused. float Reco_QQ_mumi_ptErr_inner[NMAX]; // new float, unused. float Reco_QQ_mumi_ptErr_global[NMAX]; //new float, unused. TClonesArray *Reco_QQ_vtx = 0;; TClonesArray *Reco_QQ_4mom = 0; TClonesArray *Reco_QQ_mupl_4mom = 0; TClonesArray *Reco_QQ_mumi_4mom = 0; TClonesArray *Reco_mu_4mom = 0; Int_t Reco_mu_size; Int_t Reco_mu_type[NMAX]; Int_t Reco_mu_charge[NMAX]; int nPlusMu; int nMinusMu; float muPt[NMAX]; float muEta[NMAX]; float muPhi[NMAX]; //Int_t nReco_QQ; Float_t invariantMass; Int_t QQtrig; Int_t QQsign; Int_t QQTrkDr03; Int_t QQTrkDr04; Int_t QQTrkDr05; Int_t QQTrkPt04; Int_t QQTrkPt03; Int_t QQTrkPt02; float weight; float weight2; Float_t upsPt; Float_t upsEta; Float_t upsPhi; Float_t upsRapidity; Float_t vProb; Float_t muPlusPt; Float_t muMinusPt; Float_t muPlusEta; Float_t muMinusEta; Float_t muPlusPhi; Float_t muMinusPhi; Float_t RmuPlusPhi = 0; Float_t RmuMinusPhi = 0; // centrliaty extra stuff Int_t Npix, NpixelTracks,Ntracks; Float_t SumET_HF, SumET_HFplus, SumET_HFminus, SumET_HFplusEta4, SumET_HFminusEta4, SumET_EB, SumET_ET, SumET_EE, SumET_EEplus, SumET_EEminus, SumET_ZDC, SumET_ZDCplus, SumET_ZDCminus; // track extra stuff const int NTRKMAX=100000000; int Reco_trk_size=0; TClonesArray *Reco_trk_vtx = 0; TClonesArray *Reco_trk_4mom = 0; float trkPt[NTRKMAX]; float trkEta[NTRKMAX]; float trkPhi[NTRKMAX]; //--------------------------- TBranch *b_Centrality; //! TBranch *b_eventNb; //! TBranch *b_runNb; //! TBranch *b_HLTriggers; //! TBranch *b_Reco_QQ_size; //! TBranch *b_Reco_QQ_trig; //! TBranch *b_Reco_QQ_type; //! TBranch *b_Reco_QQ_sign; //! TBranch *b_Reco_QQ_VtxProb; //! TBranch *b_Reco_QQ_dca; // new float, unused in upsilon TBranch *b_Reco_QQ_ctau; //! TBranch *b_Reco_QQ_ctauErr; //! TBranch *b_Reco_QQ_ctauTrue; //! TBranch *b_Reco_QQ_4mom; //! TBranch *b_Reco_QQ_vtx; //! TBranch *b_Reco_QQ_mupl_4mom;//! TBranch *b_Reco_QQ_mumi_4mom;//! TBranch *b_Reco_QQ_NtrkDeltaR03;//! TBranch *b_Reco_QQ_NtrkDeltaR04;//! TBranch *b_Reco_QQ_NtrkDeltaR05;//! TBranch *b_Reco_QQ_NtrkPt04;//! TBranch *b_Reco_QQ_NtrkPt03;//! TBranch *b_Reco_QQ_NtrkPt02;//! //------------------------------ TBranch *b_Reco_QQ_mupl_nTrkHits; TBranch *b_Reco_QQ_mupl_normChi2_inner; TBranch *b_Reco_QQ_mupl_normChi2_global; TBranch *b_Reco_QQ_mupl_dxy; TBranch *b_Reco_QQ_mupl_dxyErr; TBranch *b_Reco_QQ_mupl_dz; TBranch *b_Reco_QQ_mupl_dzErr; TBranch *b_Reco_QQ_mupl_TrkMuArb; TBranch *b_Reco_QQ_mupl_TMOneStaTight; // new bool, unused in upsilon(?) TBranch *b_Reco_QQ_mupl_nMuValHits; // new int, unused in upsilon TBranch *b_Reco_QQ_mupl_nPixWMea; // new int, unused in upsilon TBranch *b_Reco_QQ_mupl_nTrkWMea; // new int, unused in upsilon TBranch *b_Reco_QQ_mupl_StationsMatched; // new int, unused in Upsilon TBranch *b_Reco_QQ_mupl_pt_inner; // new float, unused. TBranch *b_Reco_QQ_mupl_pt_global; //new float, unused. TBranch *b_Reco_QQ_mupl_ptErr_inner; // new float, unused. TBranch *b_Reco_QQ_mupl_ptErr_global; //new float, unused. TBranch *b_Reco_QQ_mumi_TMOneStaTight; // new bool, unused in upsilon(?) TBranch *b_Reco_QQ_mumi_nMuValHits; // new int, unused in upsilon TBranch *b_Reco_QQ_mumi_nPixWMea; // new int, unused in upsilon TBranch *b_Reco_QQ_mumi_nTrkWMea; // new int, unused in upsilon TBranch *b_Reco_QQ_mumi_StationsMatched; // new int, unused in Upsilon TBranch *b_Reco_QQ_mumi_pt_inner; // new float, unused. TBranch *b_Reco_QQ_mumi_pt_global; //new float, unused. TBranch *b_Reco_QQ_mumi_ptErr_inner; // new float, unused. TBranch *b_Reco_QQ_mumi_ptErr_global; //new float, unused. TBranch *b_Reco_QQ_mumi_normChi2_inner; TBranch *b_Reco_QQ_mumi_normChi2_global; TBranch *b_Reco_QQ_mumi_dxy; TBranch *b_Reco_QQ_mumi_dxyErr; TBranch *b_Reco_QQ_mumi_dz; TBranch *b_Reco_QQ_mumi_dzErr; TBranch *b_Reco_QQ_mumi_TrkMuArb; TBranch *b_Reco_QQ_mumi_nTrkHits; //------------- //------------- //------------- TBranch *b_Reco_mu_size; //! TBranch *b_Reco_mu_type; //! TBranch *b_Reco_mu_charge;//! TBranch *b_Reco_mu_4mom; //! //------------- //------------- //------------- TBranch *b_zVtx; //! TBranch *b_Npix; //! TBranch *b_NpixelTracks; //! TBranch *b_Ntracks; //! TBranch *b_SumET_HF; //! TBranch *b_SumET_HFplus; //! TBranch *b_SumET_HFminus; //! TBranch *b_SumET_HFplusEta4; //! TBranch *b_SumET_HFminusEta4; //! TBranch *b_SumET_ET; //! TBranch *b_SumET_EE; //! TBranch *b_SumET_EB; //! TBranch *b_SumET_EEplus; //! TBranch *b_SumET_EEminus; //! TBranch *b_SumET_ZDC; //! TBranch *b_SumET_ZDCplus; //! TBranch *b_SumET_ZDCminus; //! //------------------------------ TBranch *b_Reco_trk_size; //! TBranch *b_Reco_trk_4mom; //! TBranch *b_Reco_trk_vtx; //! /// new tree variables Int_t _mupl_nTrkHits; Float_t _mupl_normChi2_inner; Float_t _mupl_normChi2_global; Float_t _mupl_dxy; Float_t _mupl_dxyErr; Float_t _mupl_dz; Float_t _mupl_dzErr; Bool_t _mupl_TrkMuArb; Bool_t _mupl_TMOneStaTight; // new bool, unused in upsilon(?) Int_t _mupl_nMuValHits; // new int, unused in upsilon Int_t _mupl_nPixWMea; // new int, unused in upsilon Int_t _mupl_nTrkWMea; // new int, unused in upsilon Int_t _mupl_StationsMatched; // new int, unused in Upsilon Float_t _mupl_pt_inner; // new float, unused. Float_t _mupl_pt_global; //new float, unused. Float_t _mupl_ptErr_inner; // new float, unused. Float_t _mupl_ptErr_global; //new float, unused. Bool_t _mumi_TMOneStaTight; // new bool, unused in upsilon(?) Int_t _mumi_nMuValHits; // new int, unused in upsilon Int_t _mumi_nPixWMea; // new int, unused in upsilon Int_t _mumi_nTrkWMea; // new int, unused in upsilon Int_t _mumi_StationsMatched; // new int, unused in Upsilon Float_t _mumi_pt_inner; // new float, unused. Float_t _mumi_pt_global; //new float, unused. Float_t _mumi_ptErr_inner; // new float, unused. Float_t _mumi_ptErr_global; //new float, unused. Float_t _mumi_normChi2_inner; Float_t _mumi_normChi2_global; Float_t _mumi_dxy; Float_t _mumi_dxyErr; Float_t _mumi_dz; Float_t _mumi_dzErr; Bool_t _mumi_TrkMuArb; Int_t _mumi_nTrkHits; Float_t _dca; float _ctau; // new float, unused in upsilon float _ctauTrue; // new float, unused in upsilon float _ctauErr; // new float, unused in upsilon float _zVtx; // ###### read input TTree t->SetBranchAddress("Centrality", &Centrality, &b_Centrality); t->SetBranchAddress("eventNb", &eventNb, &b_eventNb); t->SetBranchAddress("runNb", &runNb, &b_runNb); t->SetBranchAddress("HLTriggers", &HLTriggers, &b_HLTriggers); t->SetBranchAddress("Reco_QQ_size", &Reco_QQ_size, &b_Reco_QQ_size); t->SetBranchAddress("Reco_QQ_type", &Reco_QQ_type, &b_Reco_QQ_type); t->SetBranchAddress("Reco_QQ_sign", &Reco_QQ_sign, &b_Reco_QQ_sign); t->SetBranchAddress("Reco_QQ_4mom", &Reco_QQ_4mom, &b_Reco_QQ_4mom); t->SetBranchAddress("Reco_QQ_vtx", &Reco_QQ_vtx, &b_Reco_QQ_vtx); t->SetBranchAddress("Reco_QQ_mupl_4mom", &Reco_QQ_mupl_4mom, &b_Reco_QQ_mupl_4mom); t->SetBranchAddress("Reco_QQ_mumi_4mom", &Reco_QQ_mumi_4mom, &b_Reco_QQ_mumi_4mom); t->SetBranchAddress("Reco_mu_size", &Reco_mu_size, &b_Reco_mu_size); t->SetBranchAddress("Reco_mu_type", &Reco_mu_type, &b_Reco_mu_type); t->SetBranchAddress("Reco_mu_charge",&Reco_mu_charge, &b_Reco_mu_charge); t->SetBranchAddress("Reco_mu_4mom", &Reco_mu_4mom, &b_Reco_mu_4mom); t->SetBranchAddress("Reco_QQ_NtrkDeltaR03", &Reco_QQ_NtrkDeltaR03, &b_Reco_QQ_NtrkDeltaR03); t->SetBranchAddress("Reco_QQ_NtrkDeltaR04", &Reco_QQ_NtrkDeltaR04, &b_Reco_QQ_NtrkDeltaR04); t->SetBranchAddress("Reco_QQ_NtrkDeltaR05", &Reco_QQ_NtrkDeltaR05, &b_Reco_QQ_NtrkDeltaR05); t->SetBranchAddress("Reco_QQ_NtrkPt04", &Reco_QQ_NtrkPt04, &b_Reco_QQ_NtrkPt04); t->SetBranchAddress("Reco_QQ_NtrkPt03", &Reco_QQ_NtrkPt03, &b_Reco_QQ_NtrkPt03); t->SetBranchAddress("Reco_QQ_NtrkPt02", &Reco_QQ_NtrkPt02, &b_Reco_QQ_NtrkPt02); // additional selection //id variables t->SetBranchAddress("Reco_QQ_mupl_nTrkHits", &Reco_QQ_mupl_nTrkHits, &b_Reco_QQ_mupl_nTrkHits); t->SetBranchAddress("Reco_QQ_mupl_normChi2_inner", &Reco_QQ_mupl_normChi2_inner, &b_Reco_QQ_mupl_normChi2_inner); t->SetBranchAddress("Reco_QQ_mupl_normChi2_global", &Reco_QQ_mupl_normChi2_global, &b_Reco_QQ_mupl_normChi2_global); t->SetBranchAddress("Reco_QQ_mupl_dxy", &Reco_QQ_mupl_dxy, &b_Reco_QQ_mupl_dxy); t->SetBranchAddress("Reco_QQ_mupl_dz", &Reco_QQ_mupl_dz, &b_Reco_QQ_mupl_dz); t->SetBranchAddress("Reco_QQ_mupl_dxyErr", &Reco_QQ_mupl_dxyErr, &b_Reco_QQ_mupl_dxyErr); t->SetBranchAddress("Reco_QQ_mupl_dzErr", &Reco_QQ_mupl_dzErr, &b_Reco_QQ_mupl_dzErr); t->SetBranchAddress("Reco_QQ_mupl_TrkMuArb", &Reco_QQ_mupl_TrkMuArb, &b_Reco_QQ_mupl_TrkMuArb); t->SetBranchAddress("Reco_QQ_mupl_StationsMatched",&Reco_QQ_mupl_StationsMatched, &b_Reco_QQ_mupl_StationsMatched); // new int, unused in Upsilon t->SetBranchAddress("Reco_QQ_mupl_TMOneStaTight", &Reco_QQ_mupl_TMOneStaTight, &b_Reco_QQ_mupl_TMOneStaTight); // new bool, unused in upsilon(?) t->SetBranchAddress("Reco_QQ_mupl_nMuValHits", &Reco_QQ_mupl_nMuValHits, &b_Reco_QQ_mupl_nMuValHits); // new int, unused in upsilon t->SetBranchAddress("Reco_QQ_mupl_nPixWMea",&Reco_QQ_mupl_nPixWMea,&b_Reco_QQ_mupl_nPixWMea); // new int, unused in upsilon t->SetBranchAddress("Reco_QQ_mupl_nTrkWMea",&Reco_QQ_mupl_nTrkWMea,&b_Reco_QQ_mupl_nTrkWMea); // new int, unused in upsilon t->SetBranchAddress("Reco_QQ_mupl_pt_inner",&Reco_QQ_mupl_pt_inner,&b_Reco_QQ_mupl_pt_inner); // new float, unused. t->SetBranchAddress("Reco_QQ_mupl_pt_global",&Reco_QQ_mupl_pt_global,&b_Reco_QQ_mupl_pt_global);//new float, unused. t->SetBranchAddress("Reco_QQ_mupl_ptErr_inner",&Reco_QQ_mupl_ptErr_inner,&b_Reco_QQ_mupl_ptErr_inner); // new float, unused. t->SetBranchAddress("Reco_QQ_mupl_ptErr_global",&Reco_QQ_mupl_ptErr_global,&b_Reco_QQ_mupl_ptErr_global);//new float, unused. //muminus t->SetBranchAddress("Reco_QQ_mumi_nTrkHits", &Reco_QQ_mumi_nTrkHits, &b_Reco_QQ_mumi_nTrkHits); t->SetBranchAddress("Reco_QQ_mumi_normChi2_inner", &Reco_QQ_mumi_normChi2_inner, &b_Reco_QQ_mumi_normChi2_inner); t->SetBranchAddress("Reco_QQ_mumi_normChi2_global", &Reco_QQ_mumi_normChi2_global, &b_Reco_QQ_mumi_normChi2_global); t->SetBranchAddress("Reco_QQ_mumi_dxy", &Reco_QQ_mumi_dxy, &b_Reco_QQ_mumi_dxy); t->SetBranchAddress("Reco_QQ_mumi_dz", &Reco_QQ_mumi_dz, &b_Reco_QQ_mumi_dz); t->SetBranchAddress("Reco_QQ_mumi_dxyErr", &Reco_QQ_mumi_dxyErr, &b_Reco_QQ_mumi_dxyErr); t->SetBranchAddress("Reco_QQ_mumi_dzErr", &Reco_QQ_mumi_dzErr, &b_Reco_QQ_mumi_dzErr); t->SetBranchAddress("Reco_QQ_mumi_TrkMuArb", &Reco_QQ_mumi_TrkMuArb, &b_Reco_QQ_mumi_TrkMuArb); t->SetBranchAddress("Reco_QQ_mumi_TMOneStaTight", &Reco_QQ_mumi_TMOneStaTight, &b_Reco_QQ_mumi_TMOneStaTight); // new bool, unused in upsilon(?) t->SetBranchAddress("Reco_QQ_mumi_nMuValHits", &Reco_QQ_mumi_nMuValHits, &b_Reco_QQ_mumi_nMuValHits); // new int, unused in upsilon t->SetBranchAddress("Reco_QQ_mumi_nPixWMea",&Reco_QQ_mumi_nPixWMea,&b_Reco_QQ_mumi_nPixWMea); // new int, unused in upsilon t->SetBranchAddress("Reco_QQ_mumi_nTrkWMea",&Reco_QQ_mumi_nTrkWMea,&b_Reco_QQ_mumi_nTrkWMea); // new int, unused in upsilon t->SetBranchAddress("Reco_QQ_mumi_StationsMatched",&Reco_QQ_mumi_StationsMatched, &b_Reco_QQ_mumi_StationsMatched); // new int, unused in Upsilon t->SetBranchAddress("Reco_QQ_mumi_pt_inner",&Reco_QQ_mumi_pt_inner,&b_Reco_QQ_mumi_pt_inner); // new float, unused. t->SetBranchAddress("Reco_QQ_mumi_pt_global",&Reco_QQ_mumi_pt_global,&b_Reco_QQ_mumi_pt_global);//new float, unused. t->SetBranchAddress("Reco_QQ_mumi_ptErr_inner",&Reco_QQ_mumi_ptErr_inner,&b_Reco_QQ_mumi_ptErr_inner); // new float, unused. t->SetBranchAddress("Reco_QQ_mumi_ptErr_global",&Reco_QQ_mumi_ptErr_global,&b_Reco_QQ_mumi_ptErr_global);//new float, unused. //dimuons t->SetBranchAddress("Reco_QQ_dca", &Reco_QQ_dca, &b_Reco_QQ_dca); t->SetBranchAddress("Reco_QQ_trig", &Reco_QQ_trig, &b_Reco_QQ_trig); t->SetBranchAddress("Reco_QQ_VtxProb", &Reco_QQ_VtxProb, &b_Reco_QQ_VtxProb); t->SetBranchAddress("Reco_QQ_ctau", &Reco_QQ_ctau, &b_Reco_QQ_ctau); t->SetBranchAddress("Reco_QQ_ctauErr", &Reco_QQ_ctauErr, &b_Reco_QQ_ctauErr); t->SetBranchAddress("Reco_QQ_ctauTrue", &Reco_QQ_ctauTrue, &b_Reco_QQ_ctauTrue); t->SetBranchAddress("zVtx", &zVtx, &b_zVtx); // extra centrality variables t->SetBranchAddress("Npix", &Npix, &b_Npix); t->SetBranchAddress("NpixelTracks", &NpixelTracks, &b_NpixelTracks); t->SetBranchAddress("Ntracks", &Ntracks, &b_Ntracks); t->SetBranchAddress("SumET_HF", &SumET_HF, &b_SumET_HF); t->SetBranchAddress("SumET_HFplus", &SumET_HFplus, &b_SumET_HFplus); t->SetBranchAddress("SumET_HFminus", &SumET_HFminus, &b_SumET_HFminus); t->SetBranchAddress("SumET_HFplusEta4", &SumET_HFplusEta4, &b_SumET_HFplusEta4); t->SetBranchAddress("SumET_HFminusEta4",&SumET_HFminusEta4, &b_SumET_HFminusEta4); t->SetBranchAddress("SumET_ET", &SumET_ET, &b_SumET_ET); t->SetBranchAddress("SumET_EE", &SumET_EE, &b_SumET_EE); t->SetBranchAddress("SumET_EB", &SumET_EB, &b_SumET_EB); t->SetBranchAddress("SumET_EEplus", &SumET_EEplus, &b_SumET_EEplus); t->SetBranchAddress("SumET_EEminus", &SumET_EEminus, &b_SumET_EEminus); t->SetBranchAddress("SumET_ZDC" , &SumET_ZDC, &b_SumET_ZDC); t->SetBranchAddress("SumET_ZDCplus", &SumET_ZDCplus, &b_SumET_ZDCplus); t->SetBranchAddress("SumET_ZDCminus", &SumET_ZDCminus, &b_SumET_ZDCminus); // extra track variable t->SetBranchAddress("Reco_trk_size", &Reco_trk_size, &b_Reco_trk_size); t->SetBranchAddress("Reco_trk_4mom", &Reco_trk_4mom, &b_Reco_trk_4mom); t->SetBranchAddress("Reco_trk_vtx", &Reco_trk_vtx, &b_Reco_trk_vtx); // #### define control histograms TH1F *h_QQ_mass = new TH1F("h_QQ_mass","",nBins, mass_min,mass_max); // all OS TH1F *h_QQ_mass_1 = new TH1F("h_QQ_mass_1","",nBins, mass_min,mass_max);// OS in acceptance TH1F *h_QQ_mass_2 = new TH1F("h_QQ_mass_2","",nBins, mass_min, mass_max);// SS // ##### output file TFile *f1 = new TFile(Form("../dimuonTree_%s_Run%s_trigBit%d_allTriggers%d.root",dataSource,runNumber,nTriggerBit,bAllTriggers),"RECREATE"); TTree *MuTree = new TTree("MuTree","MuTree"); TTree *UpsilonTree = new TTree("UpsilonTree","UpsilonTree"); TTree *UpsilonTree_allsign = new TTree("UpsilonTree_allsign","UpsilonTree_allsign"); TTree *UpsilonTree_trkRot = new TTree("UpsilonTree_trkRot","UpsilonTree_trkRot"); MuTree->Branch("Reco_mu_size", &Reco_mu_size, "Reco_mu_size/I"); MuTree->Branch("nPlusMu", &nPlusMu, "nPlusMu/I"); MuTree->Branch("nMinusMu", &nMinusMu, "nMinusMu/I"); MuTree->Branch("muPt", &muPt, "muPt[Reco_mu_size]/F"); MuTree->Branch("muEta", &muEta, "muEta[Reco_mu_size]/F"); MuTree->Branch("muPhi", &muPhi, "muPhi[Reco_mu_size]/F"); MuTree->Branch("Reco_mu_type", &Reco_mu_type, "Reco_mu_type[Reco_mu_size]/I"); MuTree->Branch("Reco_mu_charge", &Reco_mu_charge, "Reco_mu_charge[Reco_mu_size]/I" ); MuTree->Branch("eventNb", &eventNb, "eventNb/I"); MuTree->Branch("runNb", &runNb, "runNb/I"); //UpsilonTree->Branch("nReco_QQ", &nReco_QQ, "nReco_QQ/I"); UpsilonTree->Branch("Centrality", &Centrality, "Centrality/I"); UpsilonTree->Branch("HLTriggers", &HLTriggers, "HLTriggers/I"); UpsilonTree->Branch("QQsign", &QQsign, "QQsign/I"); UpsilonTree->Branch("QQTrkDr03", &QQTrkDr03, "QQTrkDr03/I"); UpsilonTree->Branch("QQTrkDr04", &QQTrkDr04, "QQTrkDr04/I"); UpsilonTree->Branch("QQTrkDr05", &QQTrkDr05, "QQTrkDr05/I"); UpsilonTree->Branch("QQTrkPt02", &QQTrkPt02, "QQTrkPt02/I"); UpsilonTree->Branch("QQTrkPt03", &QQTrkPt03, "QQTrkPt03/I"); UpsilonTree->Branch("QQTrkPt04", &QQTrkPt04, "QQTrkPt04/I"); UpsilonTree->Branch("eventNb", &eventNb, "eventNb/I"); UpsilonTree->Branch("runNb", &runNb, "runNb/I"); UpsilonTree->Branch("invariantMass", &invariantMass, "invariantMass/F"); UpsilonTree->Branch("upsPt", &upsPt, "upsPt/F"); UpsilonTree->Branch("upsEta", &upsEta, "upsEta/F"); UpsilonTree->Branch("upsPhi", &upsPhi, "upsPhi/F"); UpsilonTree->Branch("upsRapidity", &upsRapidity, "upsRapidity/F"); UpsilonTree->Branch("muPlusPt", &muPlusPt, "muPlusPt/F"); UpsilonTree->Branch("muMinusPt", &muMinusPt, "muMinusPt/F"); UpsilonTree->Branch("muPlusEta", &muPlusEta, "muPlusEta/F"); UpsilonTree->Branch("muMinusEta", &muMinusEta, "muMinusEta/F"); UpsilonTree->Branch("muPlusPhi", &muPlusPhi, "muPlusPhi/F"); UpsilonTree->Branch("muMinusPhi", &muMinusPhi, "muMinusPhi/F"); // additional selection // id muplus UpsilonTree->Branch("_mupl_TrkMuArb",&_mupl_TrkMuArb,"_mupl_TrkMuArb/O"); UpsilonTree->Branch("_mupl_TMOneStaTight",&_mupl_TMOneStaTight,"_mupl_TMOneStaTight/O"); // new bool, unused in upsilon(?) UpsilonTree->Branch("_mupl_nMuValHits",&_mupl_nMuValHits,"_mupl_nMuValHits/I"); // new int, unused in upsilon UpsilonTree->Branch("_mupl_nPixWMea",&_mupl_nPixWMea,"_mupl_nPixWMea/I"); // new int, unused in upsilon UpsilonTree->Branch("_mupl_nTrkWMea",&_mupl_nTrkWMea,"_mupl_nTrkWMea/I"); // new int, unused in upsilon UpsilonTree->Branch("_mupl_StationsMatched",&_mupl_StationsMatched,"_mupl_StationsMatched/I"); // new int, unused in Upsilon UpsilonTree->Branch("_mupl_pt_inner",&_mupl_pt_inner,"_mupl_pt_inner/F"); // new float, unused. UpsilonTree->Branch("_mupl_pt_global",&_mupl_pt_global,"_mupl_pt_global/F"); //new float, unused. UpsilonTree->Branch("_mupl_ptErr_inner",&_mupl_ptErr_inner,"_mupl_ptErr_inner/F"); // new float, unused. UpsilonTree->Branch("_mupl_ptErr_global",&_mupl_ptErr_global,"_mupl_ptErr_global/F"); //new float, unused. UpsilonTree->Branch("_mupl_nTrkHits",&_mupl_nTrkHits," _mupl_nTrkHits/I"); UpsilonTree->Branch("_mupl_normChi2_inner", &_mupl_normChi2_inner," _mupl_normChi2_inner/F"); UpsilonTree->Branch("_mupl_normChi2_global",&_mupl_normChi2_global,"_mupl_normChi2_global/F"); UpsilonTree->Branch("_mupl_dxy",&_mupl_dxy,"_mupl_dxy/F"); UpsilonTree->Branch("_mupl_dxyErr",&_mupl_dxyErr,"_mupl_dxyErr/F"); UpsilonTree->Branch("_mupl_dz",&_mupl_dz,"_mupl_dz/F"); UpsilonTree->Branch("_mupl_dzErr",&_mupl_dzErr,"_mupl_dzErr/F"); //id muminus UpsilonTree->Branch("_mumi_TrkMuArb",&_mumi_TrkMuArb,"_mumi_TrkMuArb/O"); UpsilonTree->Branch("_mumi_TMOneStaTight",&_mumi_TMOneStaTight,"_mumi_TMOneStaTight/O"); // new bool, unused in upsilon(?) UpsilonTree->Branch("_mumi_nMuValHits",&_mumi_nMuValHits,"_mumi_nMuValHits/I"); // new int, unused in upsilon UpsilonTree->Branch("_mumi_nPixWMea",&_mumi_nPixWMea,"_mumi_nPixWMea/I"); // new int, unused in upsilon UpsilonTree->Branch("_mumi_nTrkWMea",&_mumi_nTrkWMea,"_mumi_nTrkWMea/I"); // new int, unused in upsilon UpsilonTree->Branch("_mumi_StationsMatched",&_mumi_StationsMatched,"_mumi_StationsMatched/I"); // new int, unused in Upsilon UpsilonTree->Branch("_mumi_pt_inner",&_mumi_pt_inner,"_mumi_pt_inner/F"); // new float, unused. UpsilonTree->Branch("_mumi_pt_global",&_mumi_pt_global,"_mumi_pt_global/F"); //new float, unused. UpsilonTree->Branch("_mumi_ptErr_inner",&_mumi_ptErr_inner,"_mumi_ptErr_inner/F"); // new float, unused. UpsilonTree->Branch("_mumi_ptErr_global",&_mumi_ptErr_global,"_mumi_ptErr_global/F"); //new float, unused. UpsilonTree->Branch("_mumi_nTrkHits",&_mumi_nTrkHits," _mumi_nTrkHits/I"); UpsilonTree->Branch("_mumi_normChi2_inner", &_mumi_normChi2_inner," _mumi_normChi2_inner/F"); UpsilonTree->Branch("_mumi_normChi2_global",&_mumi_normChi2_global,"_mumi_normChi2_global/F"); UpsilonTree->Branch("_mumi_dxy",&_mumi_dxy,"_mumi_dxy/F"); UpsilonTree->Branch("_mumi_dxyErr",&_mumi_dxyErr,"_mumi_dxyErr/F"); UpsilonTree->Branch("_mumi_dz",&_mumi_dz,"_mumi_dz/F"); UpsilonTree->Branch("_mumi_dzErr",&_mumi_dzErr,"_mumi_dzErr/F"); //dimuon variables UpsilonTree->Branch("QQtrig", &QQtrig, "QQtrig/I"); UpsilonTree->Branch("_dca",&_dca,"_dca/F");// new float, unused in upsilon UpsilonTree->Branch("_ctau",&_ctau,"_ctau/F");// new float, unused in upsilon UpsilonTree->Branch("_ctauErr",&_ctauErr,"_ctauErr/F");// new float, unused in upsilon UpsilonTree->Branch("_ctauTrue",&_ctauTrue,"_ctauTrue/F");// new float, unused in upsilon UpsilonTree->Branch("_zVtx", &_zVtx,"_zVtx/F"); UpsilonTree->Branch("vProb", &vProb, "vProb/F"); if(addExtraCentrality) { UpsilonTree->Branch("Npix",&Npix,"Npix/I"); UpsilonTree->Branch("NpixelTracks",&NpixelTracks,"NpixelTracks/I"); UpsilonTree->Branch("Ntracks", &Ntracks, "Ntracks/I"); UpsilonTree->Branch("SumET_HF",&SumET_HF,"SumET_HF/F"); UpsilonTree->Branch("SumET_HFplus",&SumET_HFplus,"SumET_HFplus/F"); UpsilonTree->Branch("SumET_HFminus",&SumET_HFminus,"SumET_HFminus/F"); UpsilonTree->Branch("SumET_HFplusEta4",&SumET_HFplusEta4,"SumET_HFplusEta4/F"); UpsilonTree->Branch("SumET_HFminusEta4",&SumET_HFminusEta4,"SumET_HFminusEta4/F"); UpsilonTree->Branch("SumET_ET",&SumET_ET,"SumET_ET/F"); UpsilonTree->Branch("SumET_EE",&SumET_EE,"SumET_EE/F"); UpsilonTree->Branch("SumET_EB",&SumET_EB,"SumET_EB/F"); UpsilonTree->Branch("SumET_EEplus",&SumET_EEplus,"SumET_EEplus/F"); UpsilonTree->Branch("SumET_EEminus",&SumET_EEminus,"SumET_EEminus/F"); UpsilonTree->Branch("SumET_ZDC",&SumET_ZDC,"SumET_ZDC/F"); UpsilonTree->Branch("SumET_ZDCplus",&SumET_ZDCplus,"SumET_ZDCplus/F"); UpsilonTree->Branch("SumET_ZDCminus",&SumET_ZDCminus,"SumET_ZDCminus/F"); } UpsilonTree_allsign->Branch("Centrality", &Centrality, "Centrality/I"); UpsilonTree_allsign->Branch("HLTriggers", &HLTriggers, "HLTriggers/I"); UpsilonTree_allsign->Branch("QQtrig", &QQtrig, "QQtrig/I"); UpsilonTree_allsign->Branch("QQsign", &QQsign, "QQsign/I"); UpsilonTree_allsign->Branch("QQTrkDr03", &QQTrkDr03, "QQTrkDr03/I"); UpsilonTree_allsign->Branch("QQTrkDr04", &QQTrkDr04, "QQTrkDr04/I"); UpsilonTree_allsign->Branch("QQTrkDr05", &QQTrkDr05, "QQTrkDr05/I"); UpsilonTree_allsign->Branch("QQTrkPt04", &QQTrkPt04, "QQTrkPt04/I"); UpsilonTree_allsign->Branch("QQTrkPt03", &QQTrkPt03, "QQTrkPt03/I"); UpsilonTree_allsign->Branch("QQTrkPt02", &QQTrkPt02, "QQTrkPt02/I"); UpsilonTree_allsign->Branch("weight", &weight, "weight/F"); UpsilonTree_allsign->Branch("weight2", &weight2, "weight2/F"); UpsilonTree_allsign->Branch("vProb", &vProb, "vProb/F"); UpsilonTree_allsign->Branch("eventNb", &eventNb, "eventNb/I"); UpsilonTree_allsign->Branch("runNb", &runNb, "runNb/I"); UpsilonTree_allsign->Branch("invariantMass", &invariantMass, "invariantMass/F"); UpsilonTree_allsign->Branch("upsPt", &upsPt, "upsPt/F"); UpsilonTree_allsign->Branch("upsEta", &upsEta, "upsEta/F"); UpsilonTree_allsign->Branch("upsPhi", &upsPhi, "upsPhi/F"); UpsilonTree_allsign->Branch("upsRapidity",&upsRapidity, "upsRapidity/F"); UpsilonTree_allsign->Branch("muPlusPt", &muPlusPt, "muPlusPt/F"); UpsilonTree_allsign->Branch("muMinusPt", &muMinusPt, "muMinusPt/F"); UpsilonTree_allsign->Branch("muPlusEta", &muPlusEta, "muPlusEta/F"); UpsilonTree_allsign->Branch("muMinusEta", &muMinusEta, "muMinusEta/F"); UpsilonTree_allsign->Branch("muPlusPhi", &muPlusPhi, "muPlusPhi/F"); UpsilonTree_allsign->Branch("muMinusPhi", &muMinusPhi, "muMinusPhi/F"); if(addExtraCentrality) { UpsilonTree_allsign->Branch("Npix",&Npix,"Npix/I"); UpsilonTree_allsign->Branch("NpixelTracks",&NpixelTracks,"NpixelTracks/I"); UpsilonTree_allsign->Branch("Ntracks", &Ntracks, "Ntracks/I"); UpsilonTree_allsign->Branch("SumET_HF",&SumET_HF,"SumET_HF/F"); UpsilonTree_allsign->Branch("SumET_HFplus",&SumET_HFplus,"SumET_HFplus/F"); UpsilonTree_allsign->Branch("SumET_HFminus",&SumET_HFminus,"SumET_HFminus/F"); UpsilonTree_allsign->Branch("SumET_HFplusEta4",&SumET_HFplusEta4,"SumET_HFplusEta4/F"); UpsilonTree_allsign->Branch("SumET_HFminusEta4",&SumET_HFminusEta4,"SumET_HFminusEta4/F"); UpsilonTree_allsign->Branch("SumET_ET",&SumET_ET,"SumET_ET/F"); UpsilonTree_allsign->Branch("SumET_EE",&SumET_EE,"SumET_EE/F"); UpsilonTree_allsign->Branch("SumET_EB",&SumET_EB,"SumET_EB/F"); UpsilonTree_allsign->Branch("SumET_EEplus",&SumET_EEplus,"SumET_EEplus/F"); UpsilonTree_allsign->Branch("SumET_EEminus",&SumET_EEminus,"SumET_EEminus/F"); UpsilonTree_allsign->Branch("SumET_ZDC",&SumET_ZDC,"SumET_ZDC/F"); UpsilonTree_allsign->Branch("SumET_ZDCplus",&SumET_ZDCplus,"SumET_ZDCplus/F"); UpsilonTree_allsign->Branch("SumET_ZDCminus",&SumET_ZDCminus,"SumET_ZDCminus/F"); } UpsilonTree_trkRot->Branch("Centrality", &Centrality, "Centrality/I"); UpsilonTree_trkRot->Branch("HLTriggers", &HLTriggers, "HLTriggers/I"); UpsilonTree_trkRot->Branch("QQtrig", &QQtrig, "QQtrig/I"); UpsilonTree_trkRot->Branch("QQsign", &QQsign, "QQsign/I"); UpsilonTree_trkRot->Branch("QQTrkDr03", &QQTrkDr03, "QQTrkDr03/I"); UpsilonTree_trkRot->Branch("QQTrkDr04", &QQTrkDr04, "QQTrkDr04/I"); UpsilonTree_trkRot->Branch("QQTrkDr05", &QQTrkDr05, "QQTrkDr05/I"); UpsilonTree_trkRot->Branch("QQTrkPt04", &QQTrkPt04, "QQTrkPt04/I"); UpsilonTree_trkRot->Branch("QQTrkPt03", &QQTrkPt03, "QQTrkPt03/I"); UpsilonTree_trkRot->Branch("QQTrkPt02", &QQTrkPt02, "QQTrkPt02/I"); UpsilonTree_trkRot->Branch("weight", &weight, "weight/F"); UpsilonTree_trkRot->Branch("weight2", &weight2, "weight2/F"); UpsilonTree_trkRot->Branch("vProb", &vProb, "vProb/F"); UpsilonTree_trkRot->Branch("eventNb", &eventNb, "eventNb/I"); UpsilonTree_trkRot->Branch("runNb", &runNb, "runNb/I"); UpsilonTree_trkRot->Branch("invariantMass", &invariantMass, "invariantMass/F"); UpsilonTree_trkRot->Branch("upsPt", &upsPt, "upsPt/F"); UpsilonTree_trkRot->Branch("upsEta", &upsEta, "upsEta/F"); UpsilonTree_trkRot->Branch("upsPhi", &upsPhi, "upsPhi/F"); UpsilonTree_trkRot->Branch("upsRapidity",&upsRapidity, "upsRapidity/F"); UpsilonTree_trkRot->Branch("muPlusPt", &muPlusPt, "muPlusPt/F"); UpsilonTree_trkRot->Branch("muMinusPt", &muMinusPt, "muMinusPt/F"); UpsilonTree_trkRot->Branch("muPlusEta", &muPlusEta, "muPlusEta/F"); UpsilonTree_trkRot->Branch("muMinusEta", &muMinusEta, "muMinusEta/F"); UpsilonTree_trkRot->Branch("muPlusPhi", &muPlusPhi, "muPlusPhi/F"); UpsilonTree_trkRot->Branch("muMinusPhi", &muMinusPhi, "muMinusPhi/F"); if(addExtraCentrality) { UpsilonTree_trkRot->Branch("Npix",&Npix,"Npix/I"); UpsilonTree_trkRot->Branch("NpixelTracks",&NpixelTracks,"NpixelTracks/I"); UpsilonTree_trkRot->Branch("Ntracks", &Ntracks, "Ntracks/I"); UpsilonTree_trkRot->Branch("SumET_HF",&SumET_HF,"SumET_HF/F"); UpsilonTree_trkRot->Branch("SumET_HFplus",&SumET_HFplus,"SumET_HFplus/F"); UpsilonTree_trkRot->Branch("SumET_HFminus",&SumET_HFminus,"SumET_HFminus/F"); UpsilonTree_trkRot->Branch("SumET_HFplusEta4",&SumET_HFplusEta4,"SumET_HFplusEta4/F"); UpsilonTree_trkRot->Branch("SumET_HFminusEta4",&SumET_HFminusEta4,"SumET_HFminusEta4/F"); UpsilonTree_trkRot->Branch("SumET_ET",&SumET_ET,"SumET_ET/F"); UpsilonTree_trkRot->Branch("SumET_EE",&SumET_EE,"SumET_EE/F"); UpsilonTree_trkRot->Branch("SumET_EB",&SumET_EB,"SumET_EB/F"); UpsilonTree_trkRot->Branch("SumET_EEplus",&SumET_EEplus,"SumET_EEplus/F"); UpsilonTree_trkRot->Branch("SumET_EEminus",&SumET_EEminus,"SumET_EEminus/F"); UpsilonTree_trkRot->Branch("SumET_ZDC",&SumET_ZDC,"SumET_ZDC/F"); UpsilonTree_trkRot->Branch("SumET_ZDCplus",&SumET_ZDCplus,"SumET_ZDCplus/F"); UpsilonTree_trkRot->Branch("SumET_ZDCminus",&SumET_ZDCminus,"SumET_ZDCminus/F"); } //____________________________________ loop over all events for (int i=0; i<nentries; i++) { t->GetEntry(i); // if(excludeWrongAlign_pa && runNb<=210658) continue; // ##### single muon tree // countng + and - single muons nPlusMu=0; nMinusMu=0; for(int iMu = 0; iMu < Reco_mu_size; iMu++) { if (Reco_mu_charge[iMu] == 1) nPlusMu++; else nMinusMu++; TLorentzVector *Reco_mu = (TLorentzVector *) Reco_mu_4mom->At(iMu); muPt[iMu]=Reco_mu->Pt(); muEta[iMu]=Reco_mu->Eta(); muPhi[iMu]=Reco_mu->Phi(); } MuTree->Fill(); // // ntrk loop // for(int iTrk = 0; iTrk < Reco_trk_size; iTrk++) // { // TLorentzVector *Reco_trk = (TLorentzVector *) Reco_trk_4mom->At(iTrk); // trkPt[iTrk]=Reco_trk->Pt(); // trkEta[iTrk]=Reco_trk->Eta(); // trkPhi[iTrk]=Reco_trk->Phi(); // } //---------------------------------------------------- for(int iQQ = 0; iQQ < Reco_QQ_size; iQQ++) { vProb = Reco_QQ_VtxProb[iQQ]; QQsign = Reco_QQ_sign[iQQ]; QQTrkDr03 = Reco_QQ_NtrkDeltaR03[iQQ]; QQTrkDr04 = Reco_QQ_NtrkDeltaR04[iQQ]; QQTrkDr05 = Reco_QQ_NtrkDeltaR05[iQQ]; QQTrkPt04 = Reco_QQ_NtrkPt04[iQQ]; QQTrkPt03 = Reco_QQ_NtrkPt03[iQQ]; QQTrkPt02 = Reco_QQ_NtrkPt02[iQQ]; // have to red a bit about the weighting Zhen calculates ... if (Reco_QQ_sign[iQQ] == 0) // opposite sign { weight = 1; weight2 = 1; } else // same sign { weight = -1; float likesign_comb = (float)nPlusMu*(nPlusMu-1.0)/2.0+(float)nMinusMu*(nMinusMu-1.0)/2.0; // number of combinatorial pairs C(nplus)^2, C(nminus)^2 float unlikesign_bkgd_comb = (float)nPlusMu*nMinusMu - (nPlusMu>nMinusMu?nMinusMu:nPlusMu); weight2 = -1.0 * unlikesign_bkgd_comb/likesign_comb; } // dimuon variables TLorentzVector *Reco_QQ = (TLorentzVector *) Reco_QQ_4mom->At(iQQ); TLorentzVector *Reco_QQ_mupl = (TLorentzVector *) Reco_QQ_mupl_4mom->At(iQQ); TLorentzVector *Reco_QQ_mumi = (TLorentzVector *) Reco_QQ_mumi_4mom->At(iQQ); invariantMass = Reco_QQ->M(); upsPt = Reco_QQ->Pt(); upsEta = Reco_QQ->Eta(); upsPhi = Reco_QQ->Phi(); upsRapidity = Reco_QQ->Rapidity(); // single muon variables muMinusPt = Reco_QQ_mumi->Pt(); muMinusEta = Reco_QQ_mumi->Eta(); muMinusPhi = Reco_QQ_mumi->Phi(); muPlusPt = Reco_QQ_mupl->Pt(); muPlusEta = Reco_QQ_mupl->Eta(); muPlusPhi = Reco_QQ_mupl->Phi(); // apply extra selection // id muplus _mupl_nTrkHits = Reco_QQ_mupl_nTrkHits[iQQ]; _mupl_normChi2_inner = Reco_QQ_mupl_normChi2_inner[iQQ]; _mupl_normChi2_global= Reco_QQ_mupl_normChi2_global[iQQ]; _mupl_dxy = Reco_QQ_mupl_dxy[iQQ]; _mupl_dxyErr = Reco_QQ_mupl_dxyErr[iQQ]; _mupl_dz = Reco_QQ_mupl_dz[iQQ]; _mupl_dzErr = Reco_QQ_mupl_dzErr[iQQ]; _mupl_TrkMuArb = Reco_QQ_mupl_TrkMuArb[iQQ]; _mupl_TMOneStaTight = Reco_QQ_mupl_TMOneStaTight[iQQ]; _mupl_nMuValHits = Reco_QQ_mupl_nMuValHits[iQQ]; _mupl_nPixWMea = Reco_QQ_mupl_nPixWMea[iQQ]; _mupl_nTrkWMea = Reco_QQ_mupl_nTrkWMea[iQQ]; _mupl_StationsMatched = Reco_QQ_mupl_StationsMatched[iQQ]; _mupl_pt_inner = Reco_QQ_mupl_pt_inner[iQQ]; _mupl_pt_global = Reco_QQ_mupl_pt_global[iQQ]; _mupl_ptErr_inner = Reco_QQ_mupl_ptErr_inner[iQQ]; _mupl_ptErr_global = Reco_QQ_mupl_ptErr_global[iQQ]; // id muminus _mumi_nTrkHits = Reco_QQ_mumi_nTrkHits[iQQ]; _mumi_normChi2_inner = Reco_QQ_mumi_normChi2_inner[iQQ]; _mumi_normChi2_global= Reco_QQ_mumi_normChi2_global[iQQ]; _mumi_dxy = Reco_QQ_mumi_dxy[iQQ]; _mumi_dxyErr = Reco_QQ_mumi_dxyErr[iQQ]; _mumi_dz = Reco_QQ_mumi_dz[iQQ]; _mumi_dzErr = Reco_QQ_mumi_dzErr[iQQ]; _mumi_TrkMuArb = Reco_QQ_mumi_TrkMuArb[iQQ]; _mumi_TMOneStaTight =Reco_QQ_mumi_TMOneStaTight[iQQ]; _mumi_nMuValHits = Reco_QQ_mumi_nMuValHits[iQQ]; _mumi_nPixWMea = Reco_QQ_mumi_nPixWMea[iQQ]; _mumi_nTrkWMea = Reco_QQ_mumi_nTrkWMea[iQQ]; _mumi_StationsMatched = Reco_QQ_mumi_StationsMatched[iQQ]; _mumi_pt_inner = Reco_QQ_mumi_pt_inner[iQQ]; _mumi_pt_global = Reco_QQ_mumi_pt_global[iQQ]; _mumi_ptErr_inner = Reco_QQ_mumi_ptErr_inner[iQQ]; _mumi_ptErr_global = Reco_QQ_mumi_ptErr_global[iQQ]; //dimuon variables QQtrig = Reco_QQ_trig[iQQ]; _ctau = (invariantMass/3.0968)*Reco_QQ_ctau[iQQ]; _ctauTrue = (invariantMass/3.0968)*Reco_QQ_ctauTrue[iQQ]; _ctauErr = (invariantMass/3.0968)*Reco_QQ_ctauErr[iQQ]; _zVtx=zVtx[iQQ]; _dca=Reco_QQ_dca[iQQ]; bool bProcess = false; if(!bAllTriggers) bProcess = ((HLTriggers&nTriggerBit)==nTriggerBit && (Reco_QQ_trig[iQQ]&nTriggerBit)==nTriggerBit && vProb>newVtxProbCut && muMinusPt>ptcut && muPlusPt>ptcut); // for PbPB sample, the v1 and v2 same trigger is in nNtriggerBit=1 and nTriggerBit=2 respectivelly /* if(isAArereco) bProcess = (( ( (HLTriggers&nTriggerBit)==nTriggerBit && (Reco_QQ_trig[iQQ]&nTriggerBit)==nTriggerBit ) || ( (HLTriggers&(nTriggerBit+1))==(nTriggerBit+1) && (Reco_QQ_trig[iQQ]&(nTriggerBit+1))==(nTriggerBit+1) ) ) && vProb>newVtxProbCut && muMinusPt>ptcut && muPlusPt>ptcut);*/ //special case of a new tree in which I match only by filter (I assume this is equivalent as having HLTriggers fired) if(isAArereco) bProcess = (( (Reco_QQ_trig[iQQ]&(nTriggerBit+1))==(nTriggerBit+1) || (Reco_QQ_trig[iQQ]&nTriggerBit)==nTriggerBit )&& vProb>newVtxProbCut && muMinusPt>ptcut && muPlusPt>ptcut ); if (bProcess) { if (i%1000==0) cout << i << endl; UpsilonTree_allsign->Fill();// all sign and all mass if (QQsign==0) // opposite sign { UpsilonTree->Fill();// OS and all mass if (Reco_QQ->M()>mass_min && Reco_QQ->M()<mass_max) { h_QQ_mass->Fill(Reco_QQ->M());// all upsilons in 7->14 } if (Reco_QQ_mupl->Pt()>=ptcut && Reco_QQ_mumi->Pt()>=ptcut && Reco_QQ->M()>mass_min && Reco_QQ->M()<mass_max) { h_QQ_mass_1->Fill(Reco_QQ->M()); // all OS upsilons in 7->14 and pt_mu>4GeV/c } }//opposite sign else // same sign in the acceptance if (Reco_QQ_mupl->Pt()>=ptcut && Reco_QQ_mumi->Pt()>=ptcut && Reco_QQ->M()>mass_min && Reco_QQ->M()<mass_max) { h_QQ_mass_2->Fill(Reco_QQ->M());// all SS upsilons in 7->14 and pt_mu>4GeV/c } //-------------------------------------------------------- // %%%%%%%%%% track rotation: redefine some of the variables, the others remain the same Double_t ran = gRandom->Rndm(); if(ran < 0.5 ) RmuPlusPhi = muPlusPhi + TMath::Pi(); else RmuMinusPhi = muMinusPhi + TMath::Pi(); TLorentzVector mu1; mu1.SetPtEtaPhiM( muPlusPt, muPlusEta, RmuPlusPhi, 0.105); TLorentzVector mu2; mu2.SetPtEtaPhiM( muMinusPt, muMinusEta, RmuMinusPhi, 0.105); TLorentzVector dimuon; dimuon = mu1 + mu2; invariantMass = dimuon.M(); upsPt = dimuon.Pt(); upsEta = dimuon.Eta(); upsRapidity = dimuon.Rapidity(); UpsilonTree_trkRot->Fill(); }// if bProcess }// for each QQ pair }// for each event in the tree // __________________________________________________________________ // ###### plotting TH1 * phMAxis = new TH1D("phMAxis",";m_{#mu#mu} [GeV/c^{2}];Events/(0.1 GeV/c^{2})",1,mass_min,mass_max); phMAxis->SetDirectory(0); phMAxis->SetMinimum(1); phMAxis->SetMaximum(4e4); TCanvas *c1 = new TCanvas("c1","c1"); phMAxis->Draw(); //h_QQ_mass->GetYaxis()->SetRangeUser(0,180); h_QQ_mass->SetMarkerColor(kRed); h_QQ_mass->SetMarkerStyle(22); h_QQ_mass->Draw("PEsame"); h_QQ_mass_1->SetMarkerColor(kBlue); h_QQ_mass_1->SetMarkerStyle(20); h_QQ_mass_1->GetXaxis()->CenterTitle(kTRUE); h_QQ_mass_1->Draw("PEsame"); //h_QQ_mass_2->GetYaxis()->SetRangeUser(0,400); h_QQ_mass_2->SetMarkerColor(kRed); h_QQ_mass_2->SetMarkerStyle(24); h_QQ_mass_2->GetXaxis()->CenterTitle(kTRUE); h_QQ_mass_2->Draw("PEsame"); TLegend *legend = new TLegend(.4,.7,.8,.9); legend->SetTextSize(0.025); legend->AddEntry(h_QQ_mass, Form("OS && M [%.1f,%.1f]GeV: %.0f",mass_min, mass_max,h_QQ_mass->Integral(1,nBins)),"P"); legend->AddEntry(h_QQ_mass_1,Form("OS && M [%.1f,%.1f]GeV && p_{T}>%.1fGeV/c: %.0f",mass_min, mass_max,ptcut,h_QQ_mass_1->Integral(1,nBins)),"P"); legend->AddEntry(h_QQ_mass_2,Form("SS && M [%.1f,%.1f]GeV && p_{T}>%.1fGeV/c:%.0f",mass_min, mass_max,ptcut,h_QQ_mass_2->Integral(1,nBins)),"P"); legend->Draw(); h_QQ_mass->Write(); h_QQ_mass_1->Write(); h_QQ_mass_2->Write(); c1->SaveAs(Form("dimuonDistribution_%s_Run%s_trigBit%d_allTriggers%d.pdf",dataSource,runNumber,nTriggerBit,bAllTriggers)); c1->SaveAs(Form("dimuonDistribution_%s_Run%s_trigBit%d_allTriggers%d.gif",dataSource,runNumber,nTriggerBit,bAllTriggers)); c1->Write(); f1->Write(); }
void splitter() { //read input file TFile input_file("daq_converted.root","READ"); //read input trees TTree *volumetree = (TTree*)input_file.Get("TestVolumeTree"); TTree *input_tree0 = (TTree*)input_file.Get("Mod0Tree"); TTree *input_tree1 = (TTree*)input_file.Get("Mod1Tree"); TTree *input_tree2 = (TTree*)input_file.Get("Mod2Tree"); TTree *input_tree3 = (TTree*)input_file.Get("Mod3Tree"); int nentries0 = input_tree0->GetEntries(); std::clog << " input has " << nentries0 << " entries" << std::endl; //associate branches to input trees double gap; volumetree->SetBranchAddress("Gap",&gap); std::vector<int>HitPinsTop0; input_tree0->SetBranchAddress("HitPinsTop0",&(&HitPinsTop0)); std::vector<int>HitPinsBot0; input_tree0->SetBranchAddress("HitPinsBot0",&(&HitPinsBot0)); std::vector<int>HitPinsTop1; input_tree1->SetBranchAddress("HitPinsTop1",&(&HitPinsTop1)); std::vector<int>HitPinsBot1; input_tree1->SetBranchAddress("HitPinsBot1",&(&HitPinsBot1)); std::vector<int>HitPinsTop2; input_tree2->SetBranchAddress("HitPinsTop2",&(&HitPinsTop2)); std::vector<int>HitPinsBot2; input_tree2->SetBranchAddress("HitPinsBot2",&(&HitPinsBot2)); std:vector<int>HitPinsTop3; input_tree3->SetBranchAddress("HitPinsTop3",&(&HitPinsTop3)); std:vector<int>HitPinsBot3; input_tree3->SetBranchAddress("HitPinsBot3",&(&HitPinsBot3)); //loop over input trees int Nentries = 10000; int Nfiles = floor(nentries0/Nentries + 0.5); for(int iFile = 0; iFile<=Nfiles; iFile++){ // make output file TFile output_file(Form("daq_split_%i.root",iFile),"RECREATE"); // make output trees TTree *modtree0 = new TTree("Mod0Tree","Mod0Tree"); TTree *modtree1 = new TTree("Mod1Tree","Mod1Tree"); TTree *modtree2 = new TTree("Mod2Tree","Mod2Tree"); TTree *modtree3 = new TTree("Mod3Tree","Mod3Tree"); TTree *testvoltree = new TTree("TestVolumeTree","TestVolumeTree"); double gapn = 411; testvoltree->Branch("Gap",&gapn); testvoltree->Fill(); testvoltree->Write(); //create branches for output trees std::vector<int>HitPinsTop0n; modtree0->Branch("HitPinsTop0",&(&HitPinsTop0)); std::vector<int>HitPinsBot0n; modtree0->Branch("HitPinsBot0",&(&HitPinsBot0)); std::vector<int>HitPinsTop1n; modtree1->Branch("HitPinsTop1",&(&HitPinsTop1)); std::vector<int>HitPinsBot1n; modtree1->Branch("HitPinsBot1",&(&HitPinsBot1)); std::vector<int>HitPinsTop2n; modtree2->Branch("HitPinsTop2",&(&HitPinsTop2)); std::vector<int>HitPinsBot2n; modtree2->Branch("HitPinsBot2",&(&HitPinsBot2)); std::vector<int>HitPinsTop3n; modtree3->Branch("HitPinsTop3",&(&HitPinsTop3)); std::vector<int>HitPinsBot3n; modtree3->Branch("HitPinsBot3",&(&HitPinsBot3)); //loop for splitting entries for(int i = 0; i<Nentries; i++){ int ientry = Nentries*iFile + i ; if(ientry<nentries0){ input_tree0->GetEntry(ientry); modtree0->Fill(); input_tree1->GetEntry(ientry); modtree1->Fill(); input_tree2->GetEntry(ientry); modtree2->Fill(); input_tree3->GetEntry(ientry); modtree3->Fill(); }//if statement }//2nd for loop over entries modtree0->Write(); modtree1->Write(); modtree2->Write(); modtree3->Write(); output_file.Close(); }//1st for loop over trees }//end file
void createSpinTree ( //int run1 = 365513, int run2 = 365513//TEST RUN 12 //int run1 = 364822, int run2 = 368798//ALL RUN 12 int run1 = 422070, int run2 = 432008//ALL RUN 15 pp200 // int run1 = 422, int run2 = 425011 ) { int runNum = 0; int filNum = 0; int XingShift = 0; float polB = 0.; float polY = 0.; float polBstat = 0.; float polBsyst = 0.; float polYstat = 0.; float polYsyst = 0.; short spinB[120]; short spinY[120]; short spinB_PHENIX[120]; short spinY_PHENIX[120]; float bbc_in[120]; //float bbc_in_corr[120]; float bbc_out[120]; float zdc_in[120]; float zdc_out[120]; int crossing_PHENIX[120]; int crossing_RHIC[120]; for (int i=0; i<120; i++) { spinB[i] = 0; spinY[i] = 0; spinB_PHENIX[i] = 0; spinY_PHENIX[i] = 0; bbc_in[i] = 0; //bbc_in_corr[i] = 0; bbc_out[i] = 0; zdc_in[i] = 0; zdc_out[i] = 0; } TFile *newF = new TFile(OUTPUT,"recreate"); TTree *newT = new TTree("T","polarization and BBCLL1 data"); newT->Branch("RunNumber", &runNum, "RunNumber/I"); newT->Branch("FillNumber", &filNum, "FillNumber/I"); newT->Branch("XingShift", &XingShift,"XingShift/I"); newT->Branch("PolB", &polB, "PolB/F"); newT->Branch("ePolBstat", &polBstat, "ePolBstat/F"); newT->Branch("ePolBsyst", &polBsyst, "ePolBsyst/F"); newT->Branch("PolY", &polY, "PolY/F"); newT->Branch("ePolYstat", &polYstat, "ePolYstat/F"); newT->Branch("ePolYsyst", &polYsyst, "ePolYsyst/F"); newT->Branch("SpinB_PHENIX", spinB_PHENIX, "SpinB_PHENIX[120]/S"); newT->Branch("SpinY_PHENIX", spinY_PHENIX, "SpinY_PHENIX[120]/S"); newT->Branch("SpinB", spinB, "SpinB[120]/S"); newT->Branch("SpinY", spinY, "SpinY[120]/S"); newT->Branch("BBCin", bbc_in, "BBCin[120]/F"); //newT->Branch("BBCin_corr", bbc_in_corr, "BBCin_corr[120]/F"); newT->Branch("BBCout", bbc_out, "BBCout[120]/F"); newT->Branch("ZDCin", zdc_in, "ZDCin[120]/F"); newT->Branch("ZDCout", zdc_out, "ZDCout[120]/F"); newT->Branch("crossing_PHENIX", crossing_PHENIX, "crossing_PHENIX[120]/I"); newT->Branch("crossing_RHIC", crossing_RHIC, "crossing_RHIC[120]/I"); gSystem->Load("libuspin.so"); SpinDBOutput spin_out("phnxrc"); SpinDBContent spin_cont; //gSystem->Load("/direct/phenix+spin2/chenxu/CVS_PHENIX/install/lib/libScalerCorrection.so"); // ScalerCorrection* scaler = new ScalerCorrection(); cout<<"begin loop"<<endl; int badrunNum = -999; for(int run=run1; run<run2+1; run++) { spin_out.StoreDBContent(run,run); if(spin_out.CheckRunRowStore(run)!=1){continue;} spin_out.GetDBContentStore(spin_cont,run); runNum = spin_cont.GetRunNumber(); filNum = spin_cont.GetFillNumber(); XingShift = spin_cont.GetCrossingShift(); if(runNum==badrunNum)continue; if(XingShift<0) { cout <<"XingShift Error: " <<" runNum: "<<runNum <<" filNum: "<<filNum <<" XingShift: "<<XingShift <<endl; continue; } //Long64_t Scaler_BBC_Residual[120]; //scaler->GetScalerCount(run, "BBC", "Residual", Scaler_BBC_Residual); for(int i=0; i<NCROSS; i++) { double bpol,bpolerr,ypol,ypolerr; int Xing_PHENIX = i; int Xing_RHIC = (i+XingShift)%NCROSS; crossing_PHENIX[i] = Xing_PHENIX; crossing_RHIC[i] = Xing_RHIC; //if(Xing_RHIC<0||Xing_RHIC>=120||Xing_PHENIX<0||Xing_PHENIX>=120) if(XingShift!=5) { if(Xing_PHENIX == 0) { cout <<"XingShift Abnormal: " <<" runNum: "<<runNum <<" filNum: "<<filNum <<" XingShift: "<<XingShift <<" Xing_PHENIX: "<<Xing_PHENIX <<" Xing_RHIC: "<<Xing_RHIC <<endl; } } spinB_PHENIX[Xing_PHENIX] = spin_cont.GetSpinPatternBluePHENIX(Xing_PHENIX); spinY_PHENIX[Xing_PHENIX] = spin_cont.GetSpinPatternYellowPHENIX(Xing_PHENIX); //bbc_in[Xing_PHENIX] = spin_cont.GetScalerBbcVertexCutPHENIX(Xing_PHENIX); //bbc_out[Xing_PHENIX] = spin_cont.GetScalerBbcNoCutPHENIX(Xing_PHENIX); //zdc_in[Xing_PHENIX] = spin_cont.GetScalerZdcNarrowPHENIX(Xing_PHENIX); //zdc_out[Xing_PHENIX] = spin_cont.GetScalerZdcWidePHENIX(Xing_PHENIX); //spin_cont.GetPolarizationBluePHENIX(Xing_PHENIX,bpol,bpolerr); //spin_cont.GetPolarizationYellowPHENIX(Xing_PHENIX,ypol,ypolerr); spinB[Xing_RHIC] = spin_cont.GetSpinPatternBlue(Xing_RHIC); spinY[Xing_RHIC] = spin_cont.GetSpinPatternYellow(Xing_RHIC); bbc_in[Xing_RHIC] = spin_cont.GetScalerBbcVertexCut(Xing_RHIC); //if(Scaler_BBC_Residual[Xing_RHIC]>0) // bbc_in_corr[Xing_RHIC] = Scaler_BBC_Residual[Xing_RHIC]; //else // bbc_in_corr[Xing_RHIC] = bbc_in[Xing_RHIC]; bbc_out[Xing_RHIC] = spin_cont.GetScalerBbcNoCut(Xing_RHIC); zdc_in[Xing_RHIC] = spin_cont.GetScalerZdcNarrow(Xing_RHIC); zdc_out[Xing_RHIC] = spin_cont.GetScalerZdcWide(Xing_RHIC); spin_cont.GetPolarizationBlue(Xing_RHIC,bpol,bpolerr); spin_cont.GetPolarizationYellow(Xing_RHIC,ypol,ypolerr); if(spinB[Xing_RHIC]!=spinB_PHENIX[Xing_PHENIX]) { cout <<"Method Error: " <<" runNum: "<<runNum <<" filNum: "<<filNum <<" spinB[Xing_PHENIX]: "<<Xing_PHENIX<<"\t"<<spinB[Xing_PHENIX] <<" spinB[Xing_RHIC]: "<<Xing_RHIC<<"\t"<<spinB[Xing_RHIC] <<endl; continue; } polB = bpol; polY = ypol; polBstat = bpolerr; polBsyst = 0.; polYstat = ypolerr; polYsyst = 0.; if(runNum!=badrunNum) { if(spinB[Xing_RHIC]<-100) {cout<<"Pattern Error: spinB[Xing_RHIC]<-100 "<<setw(10)<<spinB[Xing_RHIC] <<" "<<"runNum: "<<runNum<<" filNum: "<<filNum<<" Xing_RHIC: "<<Xing_RHIC<<endl; badrunNum = runNum; continue;} if(spinY[Xing_RHIC]<-100) {cout<<"Pattern Error: spinY[Xing_RHIC]<-100 "<<setw(10)<<spinY[Xing_RHIC] <<" "<<"runNum: "<<runNum<<" filNum: "<<filNum<<" Xing_RHIC: "<<Xing_RHIC<<endl; badrunNum = runNum; continue;} if(bbc_in[Xing_RHIC]<0) {cout<<"Scaler Error: bbc_in[Xing_RHIC]<0 "<<setw(10)<<bbc_in[Xing_RHIC] <<" "<<"runNum: "<<runNum<<" filNum: "<<filNum<<" Xing_RHIC: "<<Xing_RHIC<<endl; badrunNum = runNum; continue;} if(bbc_out[Xing_RHIC]<0) {cout<<"Scaler Error: bbc_out[Xing_RHIC]<0 "<<setw(10)<<bbc_out[Xing_RHIC]<<" "<<"runNum: "<<runNum<<" filNum: "<<filNum<<" Xing_RHIC: "<<Xing_RHIC<<endl; badrunNum = runNum; continue;} if(zdc_in[Xing_RHIC]<0) {cout<<"Scaler Error: zdc_in[Xing_RHIC]<0 "<<setw(10)<<zdc_in[Xing_RHIC] <<" "<<"runNum: "<<runNum<<" filNum: "<<filNum<<" Xing_RHIC: "<<Xing_RHIC<<endl; badrunNum = runNum; continue;} if(zdc_out[Xing_RHIC]<0) {cout<<"Scaler Error: zdc_out[Xing_RHIC]<0 "<<setw(10)<<zdc_out[Xing_RHIC]<<" "<<"runNum: "<<runNum<<" filNum: "<<filNum<<" Xing_RHIC: "<<Xing_RHIC<<endl; badrunNum = runNum; continue;} if(XingShift<0) {cout<<"Scaler Error: XingShift[Xing_RHIC]<0 "<<setw(10)<<XingShift <<" "<<"runNum: "<<runNum<<" filNum: "<<filNum<<" Xing_RHIC: "<<Xing_RHIC<<endl; badrunNum = runNum; continue;} } } double tc_x_blue,tc_x_blueerr,tc_y_blue,tc_y_blueerr; double tc_x_yellow,tc_x_yellowerr,tc_y_yellow,tc_y_yellowerr; spin_cont.GetTransCompBlueX(tc_x_blue,tc_x_blueerr); spin_cont.GetTransCompBlueY(tc_y_blue,tc_y_blueerr); spin_cont.GetTransCompYellowX(tc_x_yellow,tc_x_yellowerr); spin_cont.GetTransCompYellowY(tc_y_yellow,tc_y_yellowerr); newT->Fill(); } cout<<"Finished!!"<<endl; newF->cd(); newT->Write(); newF->Close(); }
// Main macro function //-------------------------------------------------------------------------------------------------- void SkimMultipleFiles_fakes(string inputFilename, string outputFilename) { gBenchmark->Start("SkimNtuples"); TTree::SetMaxTreeSize(kMaxLong64); // Don't write TObject part of the objects mithep::TEventInfo::Class()->IgnoreTObjectStreamer(); mithep::TMuon::Class()->IgnoreTObjectStreamer(); mithep::TElectron::Class()->IgnoreTObjectStreamer(); mithep::TJet::Class()->IgnoreTObjectStreamer(); mithep::TPhoton::Class()->IgnoreTObjectStreamer(); // Data structures to store info from TTrees mithep::TEventInfo *info = new mithep::TEventInfo(); TClonesArray *muonArr = new TClonesArray("mithep::TMuon"); TClonesArray *electronArr = new TClonesArray("mithep::TElectron"); TClonesArray *jetArr = new TClonesArray("mithep::TJet"); TClonesArray *photonArr = new TClonesArray("mithep::TPhoton"); UInt_t nInputEvts = 0; UInt_t nPassEvts = 0; UInt_t nEventsTotal = 0; TFile* outfile = new TFile(outputFilename.c_str(), "RECREATE"); // // Initialize data trees and structs // TTree *outEventTree = new TTree("Events","Events"); outEventTree->Branch("Info", &info); outEventTree->Branch("Muon", &muonArr); outEventTree->Branch("Electron", &electronArr); outEventTree->Branch("PFJet", &jetArr); outEventTree->Branch("Photon", &photonArr); // list input ntuple files to be skimmed vector<string> infilenames; ifstream ifs; ifs.open(inputFilename.c_str()); assert(ifs.is_open()); string line; while(getline(ifs,line)) { infilenames.push_back(line); } ifs.close(); for(UInt_t ifile=0; ifile<infilenames.size(); ifile++) { cout << "Skimming " << infilenames[ifile] << "..." << endl; TTree *eventTree = getTreeFromFile(infilenames[ifile].c_str(),"Events"); nEventsTotal += getNEvents(infilenames[ifile].c_str()); assert(eventTree); // Set branch address to structures that will store the info eventTree->SetBranchAddress("Info", &info); TBranch *infoBr = eventTree->GetBranch("Info"); eventTree->SetBranchAddress("Muon", &muonArr); TBranch *muonBr = eventTree->GetBranch("Muon"); eventTree->SetBranchAddress("Electron", &electronArr); TBranch *electronBr = eventTree->GetBranch("Electron"); eventTree->SetBranchAddress("PFJet", &jetArr); TBranch *jetBr = eventTree->GetBranch("PFJet"); eventTree->SetBranchAddress("Photon", &photonArr); TBranch *photonBr = eventTree->GetBranch("Photon"); for(UInt_t ientry=0; ientry<eventTree->GetEntries(); ientry++) { infoBr->GetEntry(ientry); muonArr->Clear(); muonBr->GetEntry(ientry); electronArr->Clear(); electronBr->GetEntry(ientry); jetArr->Clear(); jetBr->GetEntry(ientry); if (ientry % 100000 == 0) cout << "Events: " << ientry << endl; nInputEvts++; //******************************************************** // TcMet //******************************************************** TVector3 met; if(info->tcMEx!=0 || info->tcMEy!=0) { met.SetXYZ(info->tcMEx, info->tcMEy, 0); } Double_t tempLeadingJetPt = 0; for(Int_t i=0; i<jetArr->GetEntries(); i++) { const mithep::TJet *jet = (mithep::TJet*)((*jetArr)[i]); if( jet->pt > tempLeadingJetPt) tempLeadingJetPt = jet->pt; } Bool_t keep = kTRUE; Int_t NRecoMuon = 0; Int_t NDenominatorMuon = 0; Int_t NMuons = 0; for(Int_t i=0; i<muonArr->GetEntries(); i++) { const mithep::TMuon *mu = (mithep::TMuon*)((*muonArr)[i]); if (fabs(mu->eta) < 2.4 && mu->pt > 10.0) { NRecoMuon++; if (passMuonDenominatorCuts(mu)) { NDenominatorMuon++; } } } Int_t NRecoElectrons = 0; Int_t NDenominatorElectrons = 0; for(Int_t i=0; i<electronArr->GetEntries(); i++) { const mithep::TElectron *ele = (mithep::TElectron*)((*electronArr)[i]); if ( fabs(ele->eta) < 2.5 && ele->pt > 10.0 ) { NRecoElectrons++; if (passElectronDenominatorCuts(ele) ) { NDenominatorElectrons++; } } } //Skim Lepton + Jet if (!( (NRecoMuon == 1 || NRecoElectrons == 1) && tempLeadingJetPt > 15.0 && met.Pt() < 20 ) ) { keep = kFALSE; } if(keep) { outEventTree->Fill(); nPassEvts++; } } } outfile->Write(); outfile->Close(); delete info; delete muonArr; delete electronArr; delete jetArr; std::cout << outputFilename << " created!" << std::endl; std::cout << " >>> Total Number of Events: " << nEventsTotal << std::endl; std::cout << " >>> Events processed: " << nInputEvts << std::endl; std::cout << " >>> Events passing: " << nPassEvts << std::endl; gBenchmark->Show("SkimNtuples"); }
void makePairs( string inputFile, string outputFile, string tagIdType ="Pog2015_Tight", // ID used for the tag string tagIsoType ="PFIso", // Iso used for the tag string probeIdType ="Pog2015_Loose", // ID used for selecting probes string probeIsoType ="PFIso", // Iso used for selecting probes string passIdType ="Pog2015_Tight", // ID used to determine whether probe passes or fails the cut string passIsoType ="PFIso" // Iso used to determine whether probe passes or fails the cut ) { //void makePairs() { bool debug=true; double deltaRthreshold=0.001; TFile *inputFileHandler=TFile::Open(inputFile.c_str(),"READ"); //TFile *inputFileHandler = new TFile("/mnt/hscratch/dhsu/Zuu_13TeV_2015-07-22_bitwise.root"); //if(inputFileHandler==0) { // printf("Error opening input file \"%s\"\n",inputFile); // return; //} // define the trees TTree *bitNamesTree=(TTree*)inputFileHandler->Get("BitNames"); TTree *eventsTree=(TTree*)inputFileHandler->Get("Events"); // declare leaf types for bitNamesTree vector<string> *vectorIdNames=0; vector<string> *vectorIsoNames=0; // set branch addresses for bitNamesTree bitNamesTree->SetBranchAddress( "IdNames", &vectorIdNames ); bitNamesTree->SetBranchAddress( "IsoNames", &vectorIsoNames ); bitNamesTree->GetEntry(0); // Loop over bit names to find the Id and Iso bits we want // Throw an error if not found int tagIdKey=-1, tagIsoKey=-1, probeIdKey=-1, probeIsoKey=-1, passIdKey=-1, passIsoKey=-1; unsigned int indexId=0, indexIso=0, indexPass=0; for(std::vector<string>::iterator it = vectorIdNames->begin(); it!=vectorIdNames->end(); ++it) { if(debug) printf("Checking %s Id\n",(*it).c_str()); if(*it == tagIdType) { printf("Found tagIdType \"%s\" in bit names, key is %d\n", tagIdType.c_str(), indexId); tagIdKey=indexId; } if(*it == probeIdType) { printf("Found probeIdType \"%s\" in bit names, key is %d\n", probeIdType.c_str(), indexId); probeIdKey=indexId; } if(*it == passIdType) { printf("Found passIdType \"%s\" in bit names, key is %d\n", passIdType.c_str(), indexId); passIdKey=indexId; } if(tagIdKey > 0 && probeIdKey > 0 && passIdKey > 0) break; indexId++; } if(tagIdKey<0 || probeIdKey<0 || passIdKey<0) { printf("Could not find IdTypes \"%s\", \"%s\", \"%s\" in bit names, exiting", tagIdType.c_str(), probeIdType.c_str(), passIdType.c_str()); return; } for(std::vector<string>::iterator it = vectorIsoNames->begin(); it!=vectorIsoNames->end(); ++it) { if(debug) printf("Checking %s Iso\n",(*it).c_str()); if(*it == tagIsoType) { printf("Found tagIsoType \"%s\" in bit names, key is %d\n", tagIsoType.c_str(), indexIso); tagIsoKey=indexIso; } if(*it == probeIsoType) { printf("Found probeIsoType \"%s\" in bit names, key is %d\n", probeIsoType.c_str(), indexIso); probeIsoKey=indexIso; } if(*it == passIsoType) { printf("Found passIsoType \"%s\" in bit names, key is %d\n", passIsoType.c_str(), indexIso); passIsoKey=indexIso; } if(tagIsoKey > 0 && probeIsoKey > 0 && passIsoKey > 0) break; indexIso++; } if(tagIsoKey<0 || probeIsoKey<0 || passIsoKey<0) { printf("Could not find IsoTypes \"%s\", \"%s\", \"%s\" in bit names, exiting", tagIsoType.c_str(), probeIsoType.c_str(), passIsoType.c_str()); return; } // declare leaf types for eventsTree UInt_t runNum; UInt_t lumiSec; UInt_t evtNum; UInt_t npv; vector<int> *vectorCharge = 0; vector<TLorentzVector*> *vectorFourMomentum = 0; vector<vector<bool> > *vectorIdBits = 0; vector<vector<bool> > *vectorIsoBits = 0; // set branch addresses for eventsTree eventsTree->SetBranchAddress( "runNum", &runNum ); eventsTree->SetBranchAddress( "lumiSec", &lumiSec ); eventsTree->SetBranchAddress( "evtNum", &evtNum ); eventsTree->SetBranchAddress( "npv", &npv ); eventsTree->SetBranchAddress( "charge", &vectorCharge ); eventsTree->SetBranchAddress( "fourMomentum", &vectorFourMomentum ); eventsTree->SetBranchAddress( "IdBits", &vectorIdBits ); eventsTree->SetBranchAddress( "IsoBits", &vectorIsoBits ); // This is the loop skeleton // To read only selected branches, Insert statements like: // eventsTree->SetBranchStatus("*",0); // disable all branches // TTreePlayer->SetBranchStatus("branchname",1); // activate branchname // Output tree branch TFile *outputFileHandler=TFile::Open(outputFile.c_str(),"RECREATE"); outputFileHandler->SetCompressionLevel(9); TTree *pairTree = new TTree("Events", ""); unsigned int pass; // whether probe passes requirements float npu=0; // mean number of expected pileup float scale1fb=1; // event weight per 1/fb float mass; // tag-probe mass int qtag, qprobe; // tag, probe charge TLorentzVector *tagTLV=0, *probeTLV=0; // tag, probe 4-vector pairTree->Branch("runNum", &runNum, "runNum/i" ); pairTree->Branch("lumiSec", &lumiSec, "lumiSec/i" ); pairTree->Branch("evtNum", &evtNum, "evtNum/i" ); pairTree->Branch("npv", &npv, "npv/i" ); pairTree->Branch("pass", &pass, "pass/i" ); pairTree->Branch("npu", &npu, "npu/F" ); pairTree->Branch("scale1fb", &scale1fb, "scale1fb/F" ); pairTree->Branch("mass", &mass, "mass/F" ); pairTree->Branch("qtag", &qtag, "qtag/I" ); pairTree->Branch("qprobe", &qprobe, "qprobe/I" ); pairTree->Branch("tag", "TLorentzVector", &tagTLV ); pairTree->Branch("probe", "TLorentzVector", &probeTLV ); pairTree->SetBranchAddress("runNum", &runNum); pairTree->SetBranchAddress("lumiSec", &lumiSec); pairTree->SetBranchAddress("evtNum", &evtNum); pairTree->SetBranchAddress("npv", &npv); pairTree->SetBranchAddress("pass", &pass); pairTree->SetBranchAddress("npu", &npu); pairTree->SetBranchAddress("scale1fb", &scale1fb); pairTree->SetBranchAddress("mass", &mass); pairTree->SetBranchAddress("qtag", &qtag); pairTree->SetBranchAddress("qprobe", &qprobe); pairTree->SetBranchAddress("tag", &tagTLV); pairTree->SetBranchAddress("probe", &probeTLV); // Data Bookkeeping Long64_t nentries = eventsTree->GetEntries(); Long64_t nbytes = 0; // Loop over events // Within events, loop over tags {j} probes {k} and make pairs for (Long64_t i=0; i<nentries;i++) { //for (Long64_t i=0; i<5;i++) { nbytes += eventsTree->GetEntry(i); // klugey implementation of golden runs list bool isGoodRun=false; switch(runNum) { case 251244: if( ( lumiSec >= 85 && lumiSec <= 86 ) || ( lumiSec >= 88 && lumiSec <= 93 ) || ( lumiSec >= 96 && lumiSec <= 121 ) || ( lumiSec >= 123 && lumiSec <= 156 ) || ( lumiSec >= 158 && lumiSec <= 428 ) || ( lumiSec >= 430 && lumiSec <= 442 ) ) isGoodRun=true; break; case 251251: if( (lumiSec >= 1 && lumiSec <= 31 ) || (lumiSec >= 33 && lumiSec <= 97 ) || (lumiSec >= 99 && lumiSec <= 167 ) ) isGoodRun=true; break; case 251252: if( (lumiSec >= 1 && lumiSec <= 283 ) || (lumiSec >= 285 && lumiSec <= 505 ) || (lumiSec >= 507 && lumiSec <= 554 ) ) isGoodRun=true; break; case 251561: if( (lumiSec >= 1 && lumiSec <= 94) ) isGoodRun=true; break; case 251562: if( (lumiSec >= 1 && lumiSec <= 439 ) || (lumiSec >= 443 && lumiSec <= 691 ) ) isGoodRun=true; break; case 251643: if( (lumiSec >= 1 && lumiSec <= 216 ) || (lumiSec >= 222 && lumiSec <= 606 ) ) isGoodRun=true; break; case 251721: if( lumiSec >= 21 && lumiSec <= 36 ) isGoodRun=true; break; case 251883: if( (lumiSec >= 56 && lumiSec <= 56 ) || (lumiSec >= 58 && lumiSec <= 60 ) || (lumiSec >= 62 && lumiSec <= 144 ) || (lumiSec >= 156 && lumiSec <= 437) ) isGoodRun=true; break; default: break; } if(!isGoodRun) continue; unsigned int j=0; // index for tags for(std::vector<TLorentzVector*>::iterator itTag = vectorFourMomentum->begin(); itTag!=vectorFourMomentum->end(); ++itTag) { // check Id and Iso for the tag candidate if(!( (*vectorIdBits)[j][tagIdKey] && (*vectorIsoBits)[j][tagIsoKey]) ) { //printf("failed cuts on tag\n"); continue; } unsigned int k=0; // index for probes for(std::vector<TLorentzVector*>::iterator itProbe = vectorFourMomentum->begin(); itProbe!=vectorFourMomentum->end(); ++itProbe) { //printf("Looking at pair, tag pT = %f, probe candidate pT = %f\n", (*itTag)->Pt(), (*itProbe)->Pt()); // compute delta-R to see if the tag and probe are the same particle double deltaR = sqrt( pow((*itTag)->Eta() - (*itProbe)->Eta(), 2) + pow((*itTag)->Phi() - (*itProbe)->Phi(), 2) ); if(deltaR < deltaRthreshold) { //printf("delta R cut\n"); continue; } // check Id and Iso for the probe candidate if(!( (*vectorIdBits)[j][probeIdKey] && (*vectorIsoBits)[j][probeIsoKey]) ) { //printf("failed probe requirements\n"); continue; } // pass=0; if( (*vectorIdBits)[j][passIdKey] && (*vectorIsoBits)[j][passIsoKey]) { pass=1; //printf("probe passed tag!\n"); } tagTLV=new TLorentzVector( (*itTag)->Px(), (*itTag)->Py(), (*itTag)->Pz(), (*itTag)->E() ); probeTLV=new TLorentzVector( (*itProbe)->Px(), (*itProbe)->Py(), (*itProbe)->Pz(), (*itProbe)->E() ); qtag = (*vectorCharge)[j]; qprobe = (*vectorCharge)[k]; if(qtag+qprobe!=0) { //printf("total charge is nonzero (%d), continuing\n",qtag+qprobe); continue; } TLorentzVector pairSystemTLV = *probeTLV + *tagTLV; if(pairSystemTLV.Pt() <= 200) { //printf(" system pT is too low (%f GeV), continuing\n", pairSystemTLV.Pt()); continue; } mass = pairSystemTLV.M(); double leadingLeptonPt=max(probeTLV->Pt(), tagTLV->Pt()); if(leadingLeptonPt<30) { printf("killing event with leading lepton pT = %f GeV having M = %f GeV\n", leadingLeptonPt, mass); continue; } //printf("filling event with leading lepton pT = %f GeV having M = %f GeV\n", leadingLeptonPt, mass); //if(fabs(mass-91.1) > 20 ){ // if(probeTLV->Pt() > tagTLV->Pt()) { // if(pass==1) // printf("filling likely background event: leading lepton pT = %f GeV, system M = %f GeV, passed %s, %s\n\trun # %d, LS # %d, evt # %d\n", leadingLeptonPt, mass, passIsoType.c_str(), passIdType.c_str(), runNum, lumiSec, evtNum); // else // printf("filling likely background event: leading lepton pT = %f GeV, system M = %f GeV, passed %s, %s\n\trun # %d, LS # %d, evt # %d\n", leadingLeptonPt, mass, probeIsoType.c_str(), probeIdType.c_str(), runNum, lumiSec, evtNum); // } else { // printf("filling likely background event: leading lepton pT = %f GeV, system M = %f GeV, passed %s, %s\n\trun # %d, LS # %d, evt # %d\n", leadingLeptonPt, mass, tagIsoType.c_str(), tagIdType.c_str(), runNum, lumiSec, evtNum); // } //} pairTree->Fill(); k++; } j++; } } printf("Input tree has %lld entries using %lld bytes\n", nentries,nbytes); printf("Trying to write to file\n"); pairTree->Write(); printf("Wrote %lld entries to file\n", pairTree->GetEntries()); outputFileHandler->Close(); inputFileHandler->Close(); }
void merge(char* prefix,char* mergePrefix,Int_t skip1, Int_t skip2, Int_t skipcalo) { TFile *fgp1 = new TFile(Form("%s_1.root",prefix),"read"); TFile *fgp2 = new TFile(Form("%s_2.root",prefix),"read"); TFile *fcalo = new TFile(Form("%s_calo.root",prefix),"read"); TFile *fmerge = new TFile(Form("%s.root",mergePrefix),"recreate"); TTree *tmerge = new TTree("data","data"); TTree *tgp1 = fgp1->Get("gridpix"); TTree *tgp2 = fgp2->Get("gridpix"); TTree *tcalo = fcalo->Get("calo"); unsigned short x1[512*256],y1[512*256],z1[512*256],x2[512*256],y2[512*256],z2[512*256]; unsigned int hits1,hits2,time1,time2,timecalo; int len = tcalo->GetLeaf("calo_data")->GetLen(); cout << "len" << len << endl; //unsigned short *calo_data = new unsigned short[len]; unsigned short calo_data[1602]; tgp1->SetBranchAddress("hits",&hits1); tgp1->SetBranchAddress("x",x1); tgp1->SetBranchAddress("y",y1); tgp1->SetBranchAddress("z",z1); tgp1->SetBranchAddress("time",&time1); tgp2->SetBranchAddress("hits",&hits2); tgp2->SetBranchAddress("x",x2); tgp2->SetBranchAddress("y",y2); tgp2->SetBranchAddress("z",z2); tgp2->SetBranchAddress("time",&time2); tcalo->SetBranchAddress("calo_data",calo_data); tcalo->SetBranchAddress("time",&timecalo); tmerge->Branch("cam1_hits",&hits1,"cam1_hits/i"); tmerge->Branch("cam1_x",&x1,"cam1_x[cam1_hits]/s"); tmerge->Branch("cam1_y",&y1,"cam1_y[cam1_hits]/s"); tmerge->Branch("cam1_z",&z1,"cam1_z[cam1_hits]/s"); tmerge->Branch("cam1_time",&time1,"cam1_time/i"); tmerge->Branch("cam2_hits",&hits2,"cam2_hits/i"); tmerge->Branch("cam2_x",&x2,"cam2_x[cam2_hits]/s"); tmerge->Branch("cam2_y",&y2,"cam2_y[cam2_hits]/s"); tmerge->Branch("cam2_z",&z2,"cam2_z[cam2_hits]/s"); tmerge->Branch("cam2_time",&time2,"cam2_time/i"); tmerge->Branch("calo_data",&calo_data,Form("calo_data[%i]/s",len)); tmerge->Branch("calo_time",&timecalo,"calo_time/i"); Int_t ev1 = tgp1->GetEntries()-skip1; Int_t ev2 = tgp2->GetEntries()-skip2; Int_t evcalo = tcalo->GetEntries()-skipcalo; for (Int_t i=0;i<min3(ev1,ev2,evcalo);i++){ tgp1->GetEntry(i+skip1); tgp2->GetEntry(i+skip2); tcalo->GetEntry(i+skipcalo); tmerge->Fill(); // cout << i << endl; } fgp1->Close(); fgp2->Close(); fcalo->Close(); fmerge->Write(); fmerge->Close(); }
int Proto2ShowerCalib::Init(PHCompositeNode *topNode) { _ievent = 0; cout << "Proto2ShowerCalib::get_HistoManager - Making PHTFileServer " << _filename << endl; PHTFileServer::get().open(_filename, "RECREATE"); fdata.open(_filename + ".dat", std::fstream::out); Fun4AllHistoManager *hm = get_HistoManager(); assert(hm); TH2F * hCheck_Cherenkov = new TH2F("hCheck_Cherenkov", "hCheck_Cherenkov", 1000, -2000, 2000, 5, .5, 5.5); hCheck_Cherenkov->GetYaxis()->SetBinLabel(1, "C1"); hCheck_Cherenkov->GetYaxis()->SetBinLabel(2, "C2 in"); hCheck_Cherenkov->GetYaxis()->SetBinLabel(3, "C2 out"); hCheck_Cherenkov->GetYaxis()->SetBinLabel(4, "C2 sum"); hm->registerHisto(hCheck_Cherenkov); TH1F * hNormalization = new TH1F("hNormalization", "hNormalization", 10, .5, 10.5); hCheck_Cherenkov->GetXaxis()->SetBinLabel(1, "ALL"); hCheck_Cherenkov->GetXaxis()->SetBinLabel(2, "C2-e"); hCheck_Cherenkov->GetXaxis()->SetBinLabel(3, "trigger_veto_pass"); hCheck_Cherenkov->GetXaxis()->SetBinLabel(4, "valid_hodo_h"); hCheck_Cherenkov->GetXaxis()->SetBinLabel(5, "valid_hodo_v"); hCheck_Cherenkov->GetXaxis()->SetBinLabel(6, "good_e"); hCheck_Cherenkov->GetXaxis()->SetBinLabel(7, "good_data"); hm->registerHisto(hNormalization); hm->registerHisto(new TH1F("hCheck_Veto", "hCheck_Veto", 1000, -500, 500)); hm->registerHisto( new TH1F("hCheck_Hodo_H", "hCheck_Hodo_H", 1000, -500, 500)); hm->registerHisto( new TH1F("hCheck_Hodo_V", "hCheck_Hodo_V", 1000, -500, 500)); hm->registerHisto(new TH1F("hBeam_Mom", "hBeam_Mom", 1200, -120, 120)); hm->registerHisto(new TH2F("hEoP", "hEoP", 1000, 0, 1.5, 120, .5, 120.5)); hm->registerHisto(new TH1F("hTemperature", "hTemperature", 500, 0, 50)); // help index files with TChain TTree * T = new TTree("T", "T"); assert(T); hm->registerHisto(T); T->Branch("info", &_eval_run); T->Branch("clus_3x3_raw", &_eval_3x3_raw); T->Branch("clus_5x5_raw", &_eval_5x5_raw); T->Branch("clus_3x3_prod", &_eval_3x3_prod); T->Branch("clus_5x5_prod", &_eval_5x5_prod); T->Branch("clus_3x3_temp", &_eval_3x3_temp); T->Branch("clus_5x5_temp", &_eval_5x5_temp); T->Branch("clus_3x3_recalib", &_eval_3x3_recalib); T->Branch("clus_5x5_recalib", &_eval_5x5_recalib); return Fun4AllReturnCodes::EVENT_OK; }
/* fill a ttree with the data and store in a binary file. This is not done in helixgui.cpp because it is easiest to keep all the root things together. In order to process in a mode-independent way, all the data we are using is stored in advance in the TEMP directory */ void fill_tree(plot_args args) { cout << "Filling tree" << endl; // get title of the file (remove ambiguity for comparison) string title = ""; if (args.title != "Comparison") title = args.title; else title = args.title + "_" + currentDateTime(); // open file and use correct directory string file_name = title + ".root"; string file_location = "/home/helix/thermo_test/THERM_TESTS/"; TFile ofile(file_name.c_str(), "RECREATE"); // declare tree and branches TTree *tree = new TTree("name", "title"); // todo float time; tree->Branch("Time", &time, "Time/F"); float temps[args.num_channels]; for (int i=0; i<args.num_channels; i++) { string branch_name = "Temps" + to_string(i); tree->Branch(branch_name.c_str(), &temps[i], (branch_name + "/F").c_str()); } // open the files to be read ifstream files[5]; bool adjust_time = false; for (int i=0; i<args.num_channels; i++) if (args.time_shifts[i] != 0 || args.time_cut != 0) adjust_time = true; // if time is adjusted, we will be in the ./TEMP/ directory for either mode if (adjust_time) { for (int i=0; i<args.num_channels; i++) { files[i].open((file_location + "TEMP/temp_ch" + to_string(i)).c_str()); } } else if (args.mode == 0) { for (int i=0; i<args.num_channels; i++) { string temp = file_location + args.projects[0] + "/" + args.projects[0] + "_ch" + to_string(i) + ".txt"; cout << temp << endl; files[i].open(temp.c_str()); } } else if (args.mode == 1) { for (int i=0; i<args.num_channels; i++) { files[i].open((file_location + args.projects[i] + "/" + args.projects[i] + "_ch" + to_string(args.channels[i]) + ".txt").c_str()); } } // open the files and read into the them string line; for (int i=0; i<args.num_channels; i++) { while(getline(files[i], line)) { // get data vector<string> data = split(line, ' '); time = atof(data[0].c_str()); temps[i] = atof(data[1].c_str()); // add time if not there already // write into the tree int status = tree->Fill(); } } // save the tree to the file and close the file. tree->Write(); ofile.Close(); /* by now, there should be a file in the directory of PlotData.cpp called <project>.root. this manually moves the file to the correct directory. there is probably a better way to do this. */ string sys_cmd_tmp = "mv " + file_name + " " + "/home/helix/thermo_test/TTREES/"; const char *sys_cmd = sys_cmd_tmp.c_str(); system(sys_cmd); return; }
void proSTEGvn() { int mult = atoi(getenv("MULT")); int tot_num=50000; //50k events double MeanMult=(double)mult; double RMSMult=10; int ifile = atoi(getenv("IFILE")); //simple toy event generator //TFile f(Form("/lio/lfs/cms/store/user/qixu/flow/NewSTEG/pPbDataV205m%d/vndata_50k_%d.root",mult,ifile), "RECREATE","ROOT file with histograms & tree"); TFile f(Form("/tmp/xuq7/pPbDataV205m%d/vndata_50k_%d.root",mult,ifile), "RECREATE","ROOT file with histograms & tree"); //TFile f(Form("vndata_50k_%d.root",mult,ifile), "RECREATE","ROOT file with histograms & tree"); TTree *tree = new TTree("tree","Event tree with a few branches"); // tree->Branch("npg", &b_npg, "npg/I"); // # of particles; // tree->Branch("phirg", &b_phirg, "phirg/F"); // RP angle; tree->Branch("n", &b_n, "n/I"); // same as npg; tree->Branch("ptg", &b_ptg, "ptg[n]/F"); // ; tree->Branch("etag", &b_etag, "etag[n]/F"); tree->Branch("phig", &b_phig, "phig[n]/F"); TF1 *EtaDistr = new TF1("EtaDistr","exp(-(x-2.1)^2/6.3)+exp(-(x+2.1)^2/6.3)",-2.4,2.4); //TF1 *PhiDistr = new TF1("PhiDistr","1+2*[0]*cos(x)+2*[1]*cos(2*x)+2*[2]*cos(3*x)+2*[3]*cos(4*x)+2*[4]*cos(5*x)+2*[5]*cos(6*x)",0,2.*TMath::Pi()); TF1 *PhiDistr = new TF1("PhiDistr","1+2*[0]*cos(2*x)+2*[1]*cos(3*x)+2*[2]*cos(4*x)+2*[3]*cos(5*x)+2*[4]*cos(6*x)",0,2.*TMath::Pi()); //TF1 *PtDistr = new TF1("PtDistr","exp (-(x/.40))+0.0015*exp (-(x/1.5))", 0.2,10); //V~0.12 //TF1 *PtDistr = new TF1("PtDistr","exp (-(x/0.90))+0.15*exp (-(x/15))", 0.1,10); //V~=0.06 TF1 *PtDistr = new TF1("PtDistr","0.03*(exp (-(x/0.594540))+0.00499506*exp (-(x/1.89391)))", 0.3,6.0); //Real Data // TF1 *PtDistr = new TF1("PtDistr","[0]*x*TMath::Power(1+(sqrt(x*x+[1]*[1])-[1]/[2]),-[3])",0.2,10); //PtDistr->SetParameters(118.836,-0.335972,0.759243,118.836); //Real data fit with Tsallis //TF1 *V1vsEta = new TF1("V1vsEta","-exp(-(x+1)^2)/20-x/30+exp(-(x-1)^2)/20",-2.4,2.4); //TF1 *V2vsPt = new TF1("V2vsPt","((x/3)^1.8/(1+(x/3)^1.8))*(.00005+(1/x)^0.8)",0.2,10); //TF1 *V2vsPt = new TF1("V2vsPt","((x/[0])^[1]/(1+(x/[2])^[3]))*(.00005+(1/x)^[4])",0.1,10); // V2vsPt->SetParameters(4.81159,1.80783,3.69272,3.11889,0.931485); //Real data V~0.05 // V2vsPt->SetParameters(5,1.8,3,1.8,0.8); //V~0.06 TF1 *V2vsPt = new TF1("V2vsPt","((x/3.31699)^2.35142/(1+(x/3.49188)^3.54429))*(.00005+(1/x)^1.50600)",0.3,6.0); TF1 *V3vsPt = new TF1("V3vsPt","((x/3.2)^2.3/(1+(x/3.4)^2.1))*(.00005+(1/x)^1.4)",0.3,6.0); TF1 *V4vsPt = new TF1("V4vsPt","((x/4.8)^2.1/(1+(x/3.4)^2.1))*(.00005+(1/x)^1.4)",0.3,6.0); TF1 *V5vsPt = new TF1("V5vsPt","((x/6.0)^3.2/(1+(x/11.4)^2.1))*(.00005+(1/x)^1.4)",0.3,6.0); TF1 *V6vsPt = new TF1("V6vsPt","((x/5.6)^2.4/(1+(x/4.7)^2.1))*(.00005+(1/x)^1.4)",0.3,6.0); UInt_t iniseed = SetSeedOwn(); gRandom->SetSeed(iniseed); TRandom3 *rnd = new TRandom3(0); double v1, v2, v3, v4, v5, v6, ph, myphi, mypt, myeta, phi0, Psi; int nnf,k; double neta, nphi, npt; int slicept; for(int i=0; i<tot_num; i++){ Psi = rnd->Uniform(0.0,2.*TMath::Pi()); //Psi=0; b_phirg = Psi; b_npg = rnd->Gaus(MeanMult,RMSMult); n = 0; for(int j=0; j<b_npg;j++ ){ mypt = PtDistr->GetRandom(); myeta = EtaDistr->GetRandom(); //v1=V1vsEta->Eval(myeta); v2=V2vsPt->Eval(mypt); v3=V3vsPt->Eval(mypt); v4=V4vsPt->Eval(mypt); v5=V5vsPt->Eval(mypt); v6=V6vsPt->Eval(mypt); b_etag[n] = myeta; b_ptg[n] = mypt; //PhiDistr->SetParameters(v1,v2,v3,v4,v5,v6); PhiDistr->SetParameters(v2,v3,v4,v5,v6); myphi = PhiDistr->GetRandom(); // randon selection dn/dphi myphi = myphi+Psi; // angle in lab frame -- needed for correct cumulant v2 if (myphi>2.*TMath::Pi()) myphi=myphi-2.*TMath::Pi(); // 0 - 2*Pi b_phig[n] = myphi; // save angle in lab frame n++; } // End of loop over particles if (i%10000 == 0) cout << i << " " << "events processed" << endl; b_n = n; tree->Fill(); } // End of loop over events cout << "writing tree" << endl; tree->Write(); cout << "writing to file" << endl; f.Write(); cout << "closing file" << endl; f.Close(); cout << "THE END" << endl; }
int merging() { Long_t NUMBER_OF_ENTRIES = 100; TTree* newResult = new TTree("xxx", "Argument"); static Double_t x, y; newResult->Branch("x", &x, "x/D"); newResult->Branch("y", &y, "y/D"); for(Long_t i=0; i<NUMBER_OF_ENTRIES; ++i) { x = i; y = i*i; //fprintf(stderr,"res %lf %lf %d\n",x,y,i<NUMBER_OF_ENTRIES); newResult->Fill(); }// end of for // newResult->Scan("x:y"); // ====================================== TMessage message(kMESS_OBJECT); message.Reset(); message.SetWriteMode(); message.WriteObject(newResult); message.Reset(); message.SetReadMode(); TTree* readResult = 0; readResult = ((TTree*)message.ReadObject(message.GetClass())); readResult->SetName("yyy"); // ====================================== TTree* result = 0; result = readResult->CloneTree(0); result->SetName("zzz"); result->Print(); result->Show(19); readResult->Print(); readResult->Show(29); cout<< "Result has " << result->GetEntries()<< " entries." << endl; TList newResultCollection; newResultCollection.SetOwner(kFALSE); newResultCollection.Add(readResult); cerr<<"Hello 1\n"; result->Merge(&newResultCollection); cerr<<"Hello 2\n"; cout<<result->GetEntries()<<endl; printf("result entries = %lld\n",result->GetEntries()); // ====================================== newResultCollection.Clear(); delete newResult; delete readResult; return 0; } // end of main
int main(){ float data[1024], x[1024], min, area, energy, timing; int start, cut, count; TFile *fout = TFile::Open("/projects/physics/dmice/Fermilab/Co60_Temp.root", "recreate"); TTree *tree = new TTree("tree", "NaI Detector Data"); tree->Branch("Waveforms", data, "data[1024]/F"); tree->Branch("Height", &min, "min/F"); tree->Branch("Area", &area, "area/F"); tree->Branch("Saturated", &cut, "cut/I"); tree->Branch("Energy", &energy, "energy/F"); tree->Branch("Timing" , &timing, "timing/F"); TChain t("tree"); t.Add("/projects/physics/dmice/Fermilab/sourcedata/Co60raw/Waveforms_0.root"); //t.Add("/projects/physics/dmice/Fermilab/1V_runs/Fermilab_1V_raw.root"); t.SetBranchAddress("Waveforms", data); for(int e = 0; t.GetEntry(e) > 0; e++){ //&& e < 10 Float_t weight=0, avg = 0, y[1024], offavg=0, bin_sum = 0; int minLoc, n0; min = 0; for(int i = 0; i < 200; i++) offavg += data[i]; offavg = offavg/200; for(int i = 0; i < 1024; i++){ y[i] = data[i] - offavg; x[i] = i; if(i < 1021 && cut == 0) if(data[i] == data[i+1] && data[i] == data[i+2] && data[i] < -.2) cut = 1; if(y[i] < min){ min = y[i]; minLoc = i; } } int zero_counter = 0, start, end; bool foundstart = false, foundend = false; for(int i = 2; i < 997; i++){ float local_avg = y[i-2] + y[i-1] + y[i] + y[i+1] + y[i+2]; if(local_avg < -.05 && !foundstart){ start = i-2; foundstart = true; } if(local_avg >= 0 && !foundend && foundstart){ zero_counter++; if(zero_counter == 15){ end = i; foundend = true; } } } //cout <<"Pulse Start: " << start << endl; //cout <<"Pulse End: " << end << endl; // for(inti i = start; i <= end; i++){ // bin_sum += y[i]; // } TGraph gr(1024, x, y); area = gr.Integral(start, end); // area = -bin_sum; energy = (area*69.674)+1.8148; for(int i = minLoc; i > 0; i--){ if(y[i] < min/2) n0 = i; } for(int i = n0; i < (n0+100); i++) { weight += (i-n0)*y[i]; avg += y[i]; if(i == 1023) { weight = 0; avg = 0; break; } } if(avg != 0) timing = (weight/avg)*4; tree->Fill(); //cout << "min: " << min << endl; //cout << "Area: "<< area << endl; //cout << "Saturated: " << cut << endl; //cout << "Meantime: " << timing << endl; //cout << endl; count++; } tree->Write(); tree->Print(); fout ->Close("R"); delete fout; }
void mcs_rawInput_Mall(char* arg) { //Take the arguments and save them into respective strings std::string outfileName; std::string infileName; std::string inF; std::string outF; std::string inPrefix; std::string outPrefix; std::string run; std::string layers; std::istringstream strm(arg); inPrefix = "/home/p180f/Do_Jo_Ol_Ma/Analysis/MainProcedure/testMain/rawTxt/"; outPrefix = "/home/p180f/Do_Jo_Ol_Ma/Analysis/MainProcedure/testMain/rawRoot/"; while (true) { if (std::getline(strm, layers, ' ')) { int runI = 0; while (true) { // run = std::to_string(runI); inF = "run" + run + "_" + layers + "layers.txt"; outF = "run" + run + "_" + layers + "layers.root"; infileName = inPrefix + inF; outfileName = outPrefix + outF; //open the raw data text file (if it is formatted correctly) ifstream fin; fin.open(infileName.c_str()); //if the file can not be opened, fail and tell standard error if (!fin.fail()) { //check that the output data file name ends in '.root' TFile *outfile; outfile = TFile::Open( outfileName.c_str(), "RECREATE" ); //make the file //readout the input and output file names to user std::cout << "inFile: " << inF << " attained\n"; std::cout << "outFile: " << outF << " created\n"; //the width and height of the image frames (in pixels) int width=480; int height=640; //data cuts (based on raw data) int width_cuts_upper=430; int width_cuts_lower=50; int pixel_cuts = 5; //the 2d array which will store each frame of image data. int frame[480][640]={0}; int frame_cuts[480][640]={0}; int frame_four[480][640]={0}; int frame_three[480][640]={0}; //a counter of the order in which the frame was processed int pNum=0; //A counter for the number of pixels/chamber/frame int count[4] = {0}; //the format of the input is: // y x intensity //with 0 0 255 the code for the start of an event int x=-10; int y=-10; int intensity=-10; //Create ROOT Trees TTree *rawT = new TTree("rawTree", "The raw data"); TTree *cutsT = new TTree("cutsTree", "Data after pixel and edge cuts"); TTree *fourChamT = new TTree("fourChamTree", "Frames with four chambers sparking (post-cuts)"); TTree *threeChamT = new TTree("threeChamTree", "Frames with three chambers sparking (post-cuts)"); //Add Branches to the Trees rawT->Branch("pNum", &pNum, "pNum/I"); rawT->Branch("frame", &frame, "frame[480][640]/I"); cutsT->Branch("pNum", &pNum, "pNum/I"); cutsT->Branch("frame", &frame_cuts, "frame[480][640]/I"); fourChamT->Branch("pNum", &pNum, "pNum/I"); fourChamT->Branch("frame", &frame_four, "frame[480][640]/I"); threeChamT->Branch("pNum", &pNum, "pNum/I"); threeChamT->Branch("frame", &frame_three, "frame[480][640]/I"); std::cout << "Beginning data extraction...\n"; std::cout << inF << " --> " << outF << std::endl; while (fin >> y >> x >> intensity){ //swap the axes (there is another transform below) //is this the start of an event? if (x==0 && y==0 && intensity==255){ //if this is the beginning of the second event or after, store to the tree if (pNum>0){ std::cout << "Processing frame number " << pNum << "\r";//this overwrites the line every time //Fill the raw data tree rawT->Fill(); //Check each chamber, and make the pixel cuts if (count[0]<=pixel_cuts) { for (int y=580; y<610; y++) { for (int x=0; x<width; x++) { frame_cuts[x][y] = 0; } } } if (count[1]<=pixel_cuts) { for (int y=400; y<440; y++) { for (int x=0; x<width; x++) { frame_cuts[x][y] = 0; } } } if (count[2]<=pixel_cuts) { for (int y=240; y<280; y++) { for (int x=0; x<width; x++) { frame_cuts[x][y] = 0; } } } if (count[3]<=pixel_cuts) { for (int y=50; y<100; y++) { for (int x=0; x<width; x++) { frame_cuts[x][y] = 0; } } } //Fill the cuts data tree cutsT->Fill(); //Find the number of chambers with legitamite sparks int chamCount = 0; for (int i=0; i<4; i++) { chamCount += (count[i]>pixel_cuts); } //Fill the four and three spark chambers appropriately if (chamCount == 4) { fourChamT->Fill(); } if (chamCount == 3) { threeChamT->Fill(); } } //now incriment the event counter pNum++; //finally, clear the frame arrays for the next entry in the branch for (int i=0; i<width;i++){ for (int j=0;j<height;j++){ frame[i][j] = 0; frame_cuts[i][j] = 0; frame_four[i][j] = 0; frame_three[i][j] = 0; } } //and clear the counter for the pixels for (int i=0; i<4; i++) { count[i] = 0; } } //is the data in range? if so, put the image data in the array // WHY THE WEIRD ASS LOGIC?????? #strict inequalities else if (x>=0 && x <=480 && y>=0 && y<=640 && intensity >=0 && intensity <=256 && (x!=0 && y!=0 && intensity!=255)){ //change from 'image' coordinates to plot coordinate x = 480-x; y = 640-y; frame[x][y] = intensity; if (x>=width_cuts_lower && x <=width_cuts_upper && y>=0 && y<=640 && intensity >=0 && intensity <=256 && (x!=0 && y!=0 && intensity!=255)){ //Load the intensities into the frame arrays frame_cuts[x][y] = intensity; frame_four[x][y] = intensity; frame_three[x][y] = intensity; //Append the pixel count per chamber if (y>580 && y<610) count[0]++; else if (y>400 && y<440) count[1]++; else if (y>240 && y< 280) count[2]++; else if (y>50 && y<100) count[3]++; } } else { std::cout << "Unkonwn data line or data out of bounds" << std::endl; } } std::cout << "Processing complete" << std::endl; std::cout << inF << " --> " << outF << " success\n"; //Close the input file fin.close(); //Write the trees to the ROOT file rawT->Write(); cutsT->Write(); fourChamT->Write(); threeChamT->Write(); std::cout <<"number of entries with 4 chambers: " << fourChamT->GetEntries() << std::endl; //Close the ROOT file outfile->Close(); } else { std::cout << "No more files exist\n"; break; } runI++; }
void DoHipTree( const TString &file, const TString &opt="") { // READ HiPACE MACROPARTICLES OUTPUT FILE * pFile; size_t lSize; double * buffer; size_t result; pFile = fopen (file.Data(),"rb" ); if (pFile==NULL) {fputs ("File error",stderr); exit (1);} // obtain file size: fseek (pFile , 0 , SEEK_END); lSize = ftell (pFile); rewind (pFile); // allocate memory to contain the whole file: buffer = (double*) malloc (lSize); if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);} // copy the file into the buffer: result = fread (buffer,1,lSize,pFile); if (result != lSize) {fputs ("Reading error",stderr); exit (3);} /* the whole file is now loaded in the memory buffer. */ // close file fclose (pFile); TTree *tree = new TTree("HiTree","RAW tree"); const Int_t Nvar = 7; Double_t var[Nvar]; char varname[Nvar][8] = {{"x1"},{"x2"},{"x3"},{"p1"},{"p2"},{"p3"},{"q"}}; for(Int_t i=0;i<Nvar;i++) { char vartype[8]; sprintf(vartype,"%s/D",varname[i]); tree->Branch(varname[i],&var[i],vartype); } Int_t Npart=lSize/(Nvar*sizeof(double)); for(int i_part=0; i_part<Npart; i_part++) { for(Int_t i_var=0; i_var<Nvar; i_var++) { var[i_var]=buffer[i_var+i_part*Nvar]; //cout << Form ("%e ",var[i_var]); } // cout << endl; tree->Fill(); } free (buffer); cout << Form(" %i particles read! " , Npart) << endl; TString fileoutname = file; fileoutname.Remove(fileoutname.Last('.')); fileoutname += ".root"; TFile *fileout = new TFile(fileoutname,"RECREATE"); tree->Write("ptree",TObject::kOverwrite); fileout->Close(); }
void polRec(double rapdilepton_min = 1, double rapdilepton_max = 1, double pTdilepton_min = 1, double pTdilepton_max = 1, double mass_signal_peak = 1, double mass_signal_sigma = 1, double n_sigmas_signal = 1, int nEff=1, int FidCuts=0, Char_t *dirstruct = "ToyDirectory_Default", bool applyFidCuts=false){ gROOT->Reset(); double mass_min = mass_signal_peak - n_sigmas_signal*mass_signal_sigma; double mass_max = mass_signal_peak + n_sigmas_signal*mass_signal_sigma; char filename [500]; // get ntuple of generated data from file sprintf(filename,"%s/genData.root",dirstruct); TFile* genFile = new TFile(filename,"READ"); TTree* genData = (TTree*)genFile->Get("genData"); // create output data file sprintf(filename,"%s/data.root",dirstruct); TFile* dataFile = new TFile(filename, "RECREATE", "dataFile"); // output ntuple TTree* data = new TTree("selectedData","selectedData"); // histograms to be output to the opened file // background distributions const int nbinth = 10; const int nbinph = 10; const int nbinpT = 7; const int nbinrap = 2; const int nbinmass = 7; TH2D* background_costhphiPX = new TH2D( "background_costhphiPHX", "", nbinth, -1., 1., nbinph, 180., 180. ); TH3D* background_pTrapMass = new TH3D( "background_pTrapMass", "", nbinpT, pTdilepton_min, pTdilepton_max, nbinrap, rapdilepton_min, rapdilepton_max, nbinmass, mass_min, mass_max ); TH1D* background_fraction = new TH1D( "background_fraction", "", 1, 0., 1. ); // this is a temporary histogram to calculate BG fraction after acceptence and efficiency cuts TH1D* isBGdistribution = new TH1D( "isBGdistribution", "", 2, 0., 2. ); // structure of input ntuple TLorentzVector* lepP_gen = 0; genData->SetBranchAddress( "lepP", &lepP_gen ); TLorentzVector* lepN_gen = 0; genData->SetBranchAddress( "lepN", &lepN_gen ); double costh_CS; genData->SetBranchAddress( "costh_CS", &costh_CS ); double phi_CS; genData->SetBranchAddress( "phi_CS", &phi_CS ); double phith_CS; genData->SetBranchAddress( "phith_CS", &phith_CS ); double costh_HX; genData->SetBranchAddress( "costh_HX", &costh_HX ); double phi_HX; genData->SetBranchAddress( "phi_HX", &phi_HX ); double phith_HX; genData->SetBranchAddress( "phith_HX", &phith_HX ); double costh_PX; genData->SetBranchAddress( "costh_PX", &costh_PX ); double phi_PX; genData->SetBranchAddress( "phi_PX", &phi_PX ); double phith_PX; genData->SetBranchAddress( "phith_PX", &phith_PX ); double mass; genData->SetBranchAddress( "mass", &mass ); double pT; genData->SetBranchAddress( "pT", &pT ); double rap; genData->SetBranchAddress( "rap", &rap ); int isBG; genData->SetBranchAddress( "isBG", &isBG ); // structure of output ntuple TLorentzVector* lepP = new TLorentzVector(0.,0.,0.,0.); data->Branch( "lepP", "TLorentzVector", &lepP ); TLorentzVector* lepN = new TLorentzVector(0.,0.,0.,0.); data->Branch( "lepN", "TLorentzVector", &lepN ); // loop over events in the input ntuple int numEvts = int( genData->GetEntries() ); cout << endl; cout << "Reading " << numEvts << " dilepton events"<< endl; cout << "------------------------------------------------------------" << endl; cout << "Progress: "<<endl; int n_step = numEvts/5; int n_step_=1; int rejected=0; for ( int evtNumber = 0; evtNumber < numEvts; evtNumber++ ) { if ((evtNumber+1)%n_step == 0) {cout << n_step_*20 <<" % "<<endl; n_step_++;} genData->GetEvent( evtNumber ); // select data in acceptance and apply efficiency double lepP_pT = lepP_gen->Pt(); double lepN_pT = lepN_gen->Pt(); double lepP_eta = lepP_gen->PseudoRapidity(); double lepN_eta = lepN_gen->PseudoRapidity(); bool isEventAccepted = isMuonInAcceptance( FidCuts-1, lepP_pT, lepP_eta ) * isMuonInAcceptance( FidCuts-1, lepN_pT, lepN_eta ); if ( !isEventAccepted ) {rejected++; continue;} double effP = singleLeptonEfficiency( lepP_pT, lepP_eta, nEff); double effN = singleLeptonEfficiency( lepN_pT, lepN_eta, nEff); double rndmeffP = gRandom->Uniform(1.); double rndmeffN = gRandom->Uniform(1.); if ( rndmeffP > effP || rndmeffN > effN ) {rejected++; continue;} // fill background histograms and output ntuple isBGdistribution->Fill( isBG ); if ( isBG ) { background_costhphiPX->Fill( costh_PX, phi_PX ); background_pTrapMass->Fill( pT, TMath::Abs(rap), mass ); } *lepP = *lepP_gen; *lepN = *lepN_gen; data->Fill(); } // end of RD ntuple loop cout << endl << endl; // background fraction double f_BG = isBGdistribution->GetMean(); background_fraction->SetBinContent( 1, f_BG ); double effFrac=(double(numEvts-rejected))/double(numEvts); cout<<"Effective Background Fraction: "<<f_BG<<endl; cout<<"Fraction of Events Surviving Efficiency: "<<effFrac<<endl; cout<<"Surviving Signal Events: "<<isBGdistribution->GetEntries()*(1-f_BG)<<endl; // end genFile->Close(); dataFile->Write(); dataFile->Close(); }
void hbbNN(Int_t ntrain=15) { // Example of a Multi Layer Perceptron // For a Tevatron search for SUSY Higgs in bh->bbb, a neural network // was used to separate the signal from the background passing // some selection cuts. Here is a simplified version of this network, // taking into account only bbb events. //Author: P. Jonsson //Part 1, preparing the inputs //Booking some histograms for signal and background, //Add histograms yourself for the dijet mass (MH[0]) of the leading pT //(=transverse momenta) jets for background and signal TH1F *detas = new TH1F("detas", "detas", 50, .0, 4.); TH1F *detab = new TH1F("detab", "detab", 50, .0, 4.); TH1F *dphis = new TH1F("dphis", "dphis", 50, .0, 3.15); TH1F *dphib = new TH1F("dphib", "dphib", 50, .0, 3.15); TH1F *angles = new TH1F("angles", "angles", 50, .0, 2.); TH1F *angleb = new TH1F("angleb", "angleb", 50, .0, 2.); TH1F *pbalances = new TH1F("pbalances", "pbalances", 50, .0, 1.); TH1F *pbalanceb = new TH1F("pbalanceb", "pbalanceb", 50, .0, 1.); TH1F *etahs = new TH1F("etahs", "etahs", 50, -2.5, 2.5); TH1F *etahb = new TH1F("etahb", "etahb", 50, -2.5, 2.5); TH1F *sphericitys = new TH1F("sphericitys", "sphericitys", 50, .0, 1.); TH1F *sphericityb = new TH1F("sphericityb", "sphericityb", 50, .0, 1.); if (!gROOT->GetClass("TMultiLayerPerceptron")) { gSystem->Load("libMLP"); } // Prepare inputs // The 2 trees are merged into one, and a "type" branch, // equal to 1 for the signal and 0 for the background is added. TChain * signal = new TChain("higgsSearch",""); //Use a Higgs signal at a mass of 110 GeV signal->Add("LHinput-cut_2b25_1j15-Tight-MC_higgs110GeV.root/higgsSearch"); //Use a background of multijet bbb events TChain *background = new TChain("higgsSearch",""); background->Add("LHinput-cut_2b25_1j15-Tight-MC_bbb.root/higgsSearch"); //book combined tree of selected events top use for training TFile *f = new TFile("training.root","recreate"); TTree *simu = new TTree("MonteCarlo", "Filtered Monte Carlo Events"); Double_t nnoutxlm[4], MH[6], dEta[6], dPhi[6], Angle[6], EtaH[6], pBalance[6], Sphericity; Double_t dphi, deta, angle, etah, pbalance, sphericity; Int_t Njets, typeH[6], typeO, nsignal, nbkg; //counters for signal and background events nsignal=0; nbkg=0; // //Set branch addresses to use from signal and background trees //Description of variables inline below. //Draw histograms of these variables for signal and background on top //of eachother in different colors. //Save these plots (you can look up how to save plots to files at root.cern.ch) //Invariant di-jet mass signal->SetBranchAddress("MH", &MH); //Delta eta, difference in pseudorapidity (spatial coodinate used to //describe angle with the beam axis = -ln(tan(theta/2)) signal->SetBranchAddress("dEta", &dEta); //Delta phi, azimuthal angle (going from 0 to 2pi around the beampipe) signal->SetBranchAddress("dPhi", &dPhi); //Angle between the leading jet and the combined jet-pair signal->SetBranchAddress("Eta1mEtaH", &Angle); //Pseudorapidity of the combined jet-pair signal->SetBranchAddress("EtaH", &EtaH); //Which jet-pair comes from the true Higgs decay signal->SetBranchAddress("type", &typeH); //Momentum balance of the jet-pair: p1-p2/p1+p2 signal->SetBranchAddress("pBalance", &pBalance); //Number of jets in the event signal->SetBranchAddress("Njets", &Njets); //Event sphericity (measure of how spherical, round, the event is) signal->SetBranchAddress("FW_H2", &Sphericity); //same for background background->SetBranchAddress("MH", &MH); background->SetBranchAddress("dEta", &dEta); background->SetBranchAddress("dPhi", &dPhi); background->SetBranchAddress("Eta1mEtaH", &Angle); background->SetBranchAddress("EtaH", &EtaH); background->SetBranchAddress("pBalance", &pBalance); background->SetBranchAddress("Njets", &Njets); background->SetBranchAddress("FW_H2", &Sphericity); //Make input branches of variables to use for the training simu->Branch("dEta", &deta, "dEta/D"); simu->Branch("dPhi", &dphi, "dPhi/D"); simu->Branch("Angle", &angle, "Angle/D"); simu->Branch("pBalance", &pbalance, "pBalance/D"); simu->Branch("EtaH", &etah, "EtaH/D"); simu->Branch("Sphericity", &sphericity, "Sphericity/D"); simu->Branch("type", &typeO, "type/I"); //loop over signal and select events to use for training Int_t i; for (i = 0; i < signal->GetEntries(); i++) { signal->GetEntry(i); //only consider events with 3 jets if (Njets==3){ typeO=0; //select only events where the two leading pT jets come from the //Higgs decay (typeH[0]==1), and these two jets are separated by //sqrt(dEta[0]*dEta[0]+dPhi[0]*dPhi[0]) > 1, and the invariant //di-jet mass is greater than 50 GeV if (typeH[0]==1 && sqrt(dEta[0]*dEta[0]+dPhi[0]*dPhi[0]) > 1. && MH[0]>50.){ deta = dEta[0]; dphi =2*acos(0)- dPhi[0]; angle = Angle[0]; pbalance = pBalance[0]; etah = EtaH[0]; sphericity = Sphericity; typeO=1; } //fill selected signal events (type0==1) if (typeO==1){ //fill the histograms like this: detas->Fill(deta); dphis->Fill(dphi); angles->Fill(angle); pbalances->Fill(pbalance); etahs->Fill(etah); sphericitys->Fill(sphericity); //fill the training tree simu->Fill(); nsignal++; } } } cout << nsignal <<endl; //now loop over background events for (i = 0; i < background->GetEntries(); i++) { background->GetEntry(i); if (Njets==3){ typeO=1; //similar for background events if (sqrt(dEta[0]*dEta[0]+dPhi[0]*dPhi[0]) > 1. && MH[0]>50.){ deta = dEta[0]; dphi =2*acos(0)- dPhi[0]; angle = Angle[0]; pbalance = pBalance[0]; etah = EtaH[0]; sphericity = Sphericity; typeO=0; } //fill the selected background events until you have the same //number as signal if (typeO==0 && nbkg<nsignal){ //fill the background histograms here: detab->Fill(deta); dphib->Fill(dphi); angleb->Fill(angle); pbalanceb->Fill(pbalance); etahb->Fill(etah); sphericityb->Fill(sphericity); nbkg++; simu->Fill(); } } } cout << nbkg << endl; /*Plot the simulated and background variable distributions */ TCanvas *c1 = new TCanvas("c2", "Signal and Background Distributions"); c1->Divide(2,3); c1->cd(1); dphis->Draw(); dphib-> SetLineColor(kRed); dphib->Draw("same"); c1->cd(2); detas->Draw(); detab-> SetLineColor(kRed); detab->Draw("same"); c1->cd(3); angles->Draw(); angleb-> SetLineColor(kRed); angleb->Draw("same"); c1->cd(4); pbalances ->Draw(); pbalanceb-> SetLineColor(kRed); pbalanceb ->Draw("same"); c1->cd(5); etahs->Draw(); etahb-> SetLineColor(kRed); etahb->Draw("same"); c1->cd(6); sphericitys->Draw(); sphericityb-> SetLineColor(kRed); sphericityb->Draw("same"); c1->SaveAs("sig_background_distr.pdf"); for(Int_t i = 1; i++; i < 5) { stringstream ss; ss << i*5; TString structure = "@dEta, @dPhi, @EtaH, @pBalance, @Sphericity, @Angle:" + ss.str() + ":1:type";; trainNetwork(simu, structure, 100); } }