int spikes(int nEntries=-1, int iHalf=0, int nHalf=1, int sev_user=3, TString hlt_sel="", TString dirOut="/home/llr/cms/ndaci/SKWork/macro/skEfficiency/tagAndProbe/Spike2011A/CommissioningRun2011A/", TString graph_style="A*", int marker_style=1, TString data="Spikes_Run2011A", TString data_sum="2011A", float spikeCut=8., bool debug=false) { // def output tag according to half ostringstream ossi; TString halftag = "_half_"; ossi.str(""); ossi << iHalf; halftag += ossi.str(); ossi.str(""); ossi << nHalf; halftag += "_" + ossi.str(); // Output Log ofstream outlog(dirOut+"log"+halftag+".txt",ios::out); // Input trees TString dirIn; vector<TString> listTrees; if( data=="Run2011A_EmulReco" ) { listTrees = list_Spikes_EmulRecoNoKill_Run2011A(); } else if( data=="Run2011A_EmulReco_Newkill") { listTrees = list_Spikes_Run2011A_Newkill(); } else if( data=="Run2011B_EmulReco_Newkill") { listTrees = list_Spikes_Run2011B_Newkill(); } /* if(data=="Spikes_Run2011A_HLTEG") { listTrees = list_Spikes_Run2011A_HLTEG(); } else if(data=="Spikes_Run2011B_HLTEG") { listTrees = list_Spikes_Run2011B_HLTEG(); } else if(data=="Spikes_Run2011B_highPU_HLTEG") { listTrees = list_Spikes_highPU_HLTEG(); } else if(data=="Spikes_2011A_HLTEG5") { listTrees = list_Spikes_2011A_HLTEG5(); } else if(data=="Spikes_2011B_HLTEG5") { listTrees = list_Spikes_2011B_PRV1_HLTEG5(); } else if(data=="Spikes_2011AB_HLTEG5") { listTrees = list_Spikes_2011AB(); } else if(data=="Spikes_Run2011A") { listTrees = list_Spikes_Run2011A(); } else if(data=="Spikes2011A_PRV6") { listTrees = list_Spikes_2011A_PromptRecoV6(); } else if(data=="Spikes2011A") { listTrees = list_Spikes_2011A(); } else if(data=="Spikes2011A_PromptRecoV4") { listTrees = list_Spikes_2011A_PromptRecoV4(); } else if(data=="Spikes2011A_1fb") { listTrees = list_Spikes_2011A_1fb(); } else if(data=="Spikes2011A_1fb_try2") { listTrees = list_Spikes_2011A_1fb_try2(); } */ /* else if(data=="Spikes2011A_HLTEG5") { listTrees = list_Spikes_2011A_HLTEG5(); } */ else { cout << "problem of dataset tag" << endl; return 0; } if(listTrees.size()==0) { cout << "tree list empty" << endl; return 0; } if(iHalf<0 || nHalf<1 || iHalf>=nHalf) { cout << "problem with iHalf and nHalf" << endl; return 0; } if(nHalf>listTrees.size()) { cout << "requested more halfes than available trees ; set nHalf to listTrees.size()=" << listTrees.size() << endl; nHalf = listTrees.size(); } int nTrees, nStart, nEnd; nTrees = listTrees.size() / nHalf; if(iHalf < nHalf-1) { nStart = iHalf*nTrees; nEnd = (iHalf + 1)*nTrees; } else if(iHalf==nHalf-1) { nStart = iHalf*nTrees; nEnd = listTrees.size(); } if(debug) cout << "gonna add the trees to the chain" << endl; TChain * myChain = new TChain ("produceNtuple/eIDSimpleTree"); for(int i=nStart ; i<nEnd ; i++) myChain->Add(listTrees[i]); if(debug) cout << "added" << endl; cout << "tree list size : " << listTrees.size() << endl << "nStart=" << nStart << " nEnd=" << nEnd << " nTrees=" << nTrees << endl; //for(int i=nStart ; i<nEnd ; i++) //outlog << listTrees[i] << endl; if(nEntries==-999) { cout << "no tree processing requested ; exiting" << endl; return 0; } // Process the tree if(debug) cout << "process the tree" << endl; TreeToHistos(myChain, data_sum, dirOut, outlog, nEntries, halftag, spikeCut, debug, graph_style,sev_user,hlt_sel); return 1; }
void runMakePhotonBabies(char* prefix , bool isData = true, float kFactor = 1.){ TChain* ch = new TChain("Events"); //----------------------------------------------------------------------------------- if( strcmp( prefix , "data_53X_2012A" ) == 0 ){ //pickSkimIfExists(ch,"PhotonTriggerSkim_slim/DoubleElectron_Run2012A-13Jul2012-v1_AOD/V05-03-18_slim/merged_ntuple_999999_9_1_skim.root"); pickSkimIfExists(ch,"PhotonTriggerSkim_slim/DoubleElectron_Run2012A-13Jul2012-v1_AOD/V05-03-18_slim/merged*root"); pickSkimIfExists(ch,"PhotonTriggerSkim_slim/DoubleElectron_Run2012A-recover-06Aug2012-v1_AOD/V05-03-18_slim/merged*root"); } //----------------------------------------------------------------------------------- else if( strcmp( prefix , "data_53X_2012B" ) == 0 ){ pickSkimIfExists(ch,"PhotonTriggerSkim_slim/DoubleElectron_Run2012B-13Jul2012-v1_AOD/V05-03-18_slim/merged*root"); } //----------------------------------------------------------------------------------- else if( strcmp( prefix , "data_53X_2012C" ) == 0 ){ pickSkimIfExists(ch,"PhotonTriggerSkim_slim/DoubleElectron_Run2012C-24Aug2012-v1_AOD/V05-03-18_slim/merged*root"); pickSkimIfExists(ch,"PhotonTriggerSkim_slim/DoubleElectron_Run2012C-PromptReco-v2_AOD/V05-03-18_slim/merged*root"); } //----------------------------------------------------------------------------------- else if( strcmp( prefix , "data_53X_2012D" ) == 0 ){ pickSkimIfExists(ch,"PhotonTriggerSkim_slim/DoubleElectron_Run2012D-PromptReco-v1_AOD/V05-03-18_slim/merged*root"); } //----------------------------------------------------------------------------------- else if( strcmp( prefix , "Photon" ) == 0 ){ pickSkimIfExists(ch,"/hadoop/cms/store/user/cwelke/CMSSW_5_2_3_patch4_V05-02-27/Photon_Run2012A-PromptReco-v1_AOD/unmerged/store*root"); pickSkimIfExists(ch,"/hadoop/cms/store/user/cwelke/CMSSW_5_2_3_patch4_V05-02-27/SinglePhoton_Run2012B-PromptReco-v1_AOD/unmerged/store*root"); } //----------------------------------------------------------------------------------- else if( strcmp( prefix , "DoubleElectron" ) == 0 ){ pickSkimIfExists(ch,"PhotonTriggerSkim/DoubleElectron_Run2012A-13Jul2012-v1_AOD/V05-03-13/merged*root"); pickSkimIfExists(ch,"PhotonTriggerSkim/DoubleElectron_Run2012A-recover-06Aug2012-v1_AOD/V05-03-13/merged*root"); pickSkimIfExists(ch,"PhotonTriggerSkim/DoubleElectron_Run2012B-13Jul2012-v1_AOD/V05-03-13/merged*root"); pickSkimIfExists(ch,"PhotonTriggerSkim/DoubleElectron_Run2012C-PromptReco-v1_AOD/V05-03-13/merged*root"); pickSkimIfExists(ch,"PhotonTriggerSkim/DoubleElectron_Run2012C-PromptReco-v2_AOD/V05-03-13/merged*root"); } //----------------------------------------------------------------------------------- else if( strcmp( prefix , "DoubleElectron_2012Cv2" ) == 0 ){ pickSkimIfExists(ch,"PhotonTriggerSkim/DoubleElectron_Run2012C-PromptReco-v2_AOD/V05-03-13/merged*root"); } //----------------------------------------------------------------------------------- else{ cout << "ERROR: cannot find sample " << prefix << endl; exit(0); } //----------------------------------------------------------------------------------- bool calculateTCMET = false; //recalculate tcmet on-the-fly? cout << endl; cout << "Checking for corrupt files" << endl; cout << "Entries " << ch->GetEntries() << endl; ch->Draw("evt_run"); cout << endl; makePhotonBabies* myLooper = new makePhotonBabies(); cout << "Running on sample " << prefix << endl; myLooper->ScanChain(ch, prefix, isData, calculateTCMET, -1 ,kFactor); }
// // Fucntions // void skimThisBaby(TString inPath, TString inFileName, TString inTreeName, TString outPath){ // Talk to user cout << " Skimming: "<< endl; cout << " " << inPath+inFileName <<endl; // Load input TChain TChain *ch = new TChain(inTreeName); TString inFile = inPath; inFile += inFileName; ch->Add(inFile); Long64_t nentries = ch->GetEntries(); TTreeCache::SetLearnEntries(10); ch->SetCacheSize(128*1024*1024); // Initialize Branches babyAnalyzer.Init(ch->GetTree()); babyAnalyzer.LoadAllBranches(); // Setup output file name and path TString outFileName = outPath; outFileName += inFileName; outFileName.ReplaceAll("*", ""); outFileName.ReplaceAll(".root", "_skimmed.root"); cout << " Output will be written to: " << endl; cout << " " << outFileName << endl << endl; // Open outputfile and Clone input TTree TFile *newfile = new TFile(outFileName, "recreate"); TTree *newtree = (TTree*)ch->GetTree()->CloneTree(0); if(!newtree) cout << "BAD TTREE CLONE" << endl; TH1D *newCounter=NULL; // Get nEntries unsigned int nEventsTotal = 0; unsigned int nEventsChain = ch->GetEntries(); // Grab list of files TObjArray *listOfFiles = ch->GetListOfFiles(); TIter fileIter(listOfFiles); TFile *currentFile = 0; // File Loop int iFile=0; while ( (currentFile = (TFile*)fileIter.Next()) ) { // Get File Content TFile *file = new TFile( currentFile->GetTitle() ); TTree *tree = (TTree*)file->Get("t"); TTreeCache::SetLearnEntries(10); tree->SetCacheSize(128*1024*1024); babyAnalyzer.Init(tree); if(iFile==0){ TH1D *temp = (TH1D*)file->Get("h_counter"); newCounter = (TH1D*)temp->Clone("h_counter"); newCounter->SetDirectory(newfile); } //else{ //TH1D *temp = (TH1D*)file->Get("h_counter"); //newCounter->Add(temp); //} // Loop over Events in current file if( nEventsTotal >= nEventsChain ) continue; unsigned int nEventsTree = tree->GetEntriesFast(); for( unsigned int event = 0; event < nEventsTree; ++event) { // Progress stop_1l_babyAnalyzer::progress( nEventsTotal, nEventsChain ); // Load Tree tree->LoadTree(event); babyAnalyzer.GetEntry(event); ++nEventsTotal; // Selection if(nvetoleps()<1) continue; if(nvetoleps()<2 && PassTrackVeto_v3() && PassTauVeto()) continue; if(ngoodjets()<2) continue; if(mt_met_lep()<150.0) continue; if(pfmet()<200.0) continue; // Turn on all branches on input babyAnalyzer.LoadAllBranches(); // Fill output tree newtree->Fill(); } // end loop over entries iFile++; } // end loop over files in TChain // Clean up //newtree->Print(); //newtree->AutoSave(); newfile->Write(); newfile->Close(); delete ch; delete newfile; }
int main(int argc, char** argv){ Year year=Twel; //============================== Declare Data Files======================================= DataFile MCResponseA(std::getenv("LBPKETAPPIPIGMCBDTRESPROOT"),MC,year,MagAll,lbpketappipig,"BDTApplied_SampleA"); DataFile MCResponseB(std::getenv("LBPKETAPPIPIGMCBDTRESPROOT"),MC,year,MagAll,lbpketappipig,"BDTApplied_SampleB"); DataFile DataResponseB(std::getenv("LBPKETAPPIPIGDATABDTRESPROOT"),Data,year,MagAll,lbpketappipig,"BDTApplied_SampleB"); DataFile DataResponseA(std::getenv("LBPKETAPPIPIGDATABDTRESPROOT"),Data,year,MagAll,lbpketappipig,"BDTApplied_SampleA"); //================================ Make BKG RooDataSet==================================== std::cout<<DataResponseA.GetFP()<<std::endl; TFile* TFBackgroundA= new TFile((DataResponseA.GetFP()).data()); TFBackgroundA->Print(); TTree* BkgATree=(TTree*)TFBackgroundA->Get("DecayTree"); if(!BkgATree){ std::cout<<"Background A Tree Null"<<std::endl; return 1; } TFile* TFBackgroundB= new TFile((DataResponseB.GetFP()).data()); TTree* BkgBTree=(TTree*)TFBackgroundB->Get("DecayTree"); if(!BkgBTree){ std::cout<<"Background B Tree Null"<<std::endl; return 1; } std::cout<<"Got Trees"<<std::endl; TFile* MinimalFileA = new TFile("MinimalFileA.root","RECREATE"); BkgATree->SetBranchStatus("*",0); BkgATree->SetBranchStatus("Lambda_b0_DTF_MF",1); BkgATree->SetBranchStatus("gamma_CL",1); BkgATree->SetBranchStatus("BDT_response",1); TTree* MinimalTreeA= BkgATree->CloneTree(0); Double_t Lambda_b0_MassA; BkgATree->SetBranchAddress("Lambda_b0_DTF_MF",&Lambda_b0_MassA); Double_t gamma_CLA; BkgATree->SetBranchAddress("gamma_CL",&gamma_CLA); Double_t BDT_responseA;BkgATree->SetBranchAddress("BDT_response",&BDT_responseA); TFile* MinimalFileB = new TFile("MinimalFileB.root","RECREATE"); BkgBTree->SetBranchStatus("*",0); BkgBTree->SetBranchStatus("Lambda_b0_DTF_MF",1); BkgBTree->SetBranchStatus("gamma_CL",1); BkgBTree->SetBranchStatus("BDT_response",1); TTree* MinimalTreeB = BkgBTree->CloneTree(0); Double_t Lambda_b0_MassB; BkgBTree->SetBranchAddress("Lambda_b0_DTF_MF",&Lambda_b0_MassB); Double_t gamma_CLB; BkgBTree->SetBranchAddress("gamma_CL",&gamma_CLB); Double_t BDT_responseB;BkgBTree->SetBranchAddress("BDT_response",&BDT_responseB); LoopTimer LTA(0.05); Long64_t AN=BkgATree->GetEntries(); for(Long64_t i=0;i<AN;++i){ BkgATree->GetEntry(i); LTA.DeclareLoopStart(AN); if(gamma_CLA<0.09)continue; if(Lambda_b0_MassA<5100.0)continue; if(Lambda_b0_MassA>6100.0)continue; MinimalTreeA->Fill(); } LoopTimer LTB(0.05); Long64_t BN=BkgBTree->GetEntries(); for(Long64_t i=0;i<BN;++i){ BkgBTree->GetEntry(i); LTB.DeclareLoopStart(BN); if(gamma_CLB<0.09)continue; if(Lambda_b0_MassB<5100.0)continue; if(Lambda_b0_MassB>6100.0)continue; MinimalTreeB->Fill(); } MinimalTreeA->Write(); MinimalTreeB->Write(); RooRealVar Mass("Lambda_b0_DTF_MF","Lambda_b0_DTF_MF",5200.0,6000.0); RooRealVar GammaCL("gamma_CL","gamma_CL",0.0,1.0); RooRealVar BDTResponse("BDT_response","BDT_response",-1.0,1.0); RooDataSet* Background= new RooDataSet("BackgroundData","BackgroundData",RooArgSet(Mass,GammaCL,BDTResponse),Import(*MinimalTreeA),Cut("gamma_CL>0.1")); std::cout<<"Data file A loaded into Roo DataSet"<<std::endl; RooDataSet* BackgroundB= new RooDataSet("BackgroundDataB","BackgroundDataB",RooArgSet(Mass,GammaCL,BDTResponse),Import(*MinimalTreeB),Cut("gamma_CL>0.1")); std::cout<<"Data File B loaded into RooDataSet"<<std::endl; Background->append(*BackgroundB); RooPlot* massFrame =Mass.frame(Title("Data Import Check"),Bins(50)); Background->plotOn(massFrame); TCanvas C; massFrame->Draw(); C.SaveAs("DataImportCheck.eps"); //================================== Make MC TChain======================================= TFile* TFMCA= new TFile((MCResponseA.GetFP()).data()); TTree* MCATree=(TTree*)TFMCA->Get("DecayTree"); if(!MCATree){ std::cout<<"MC A Tree Null"<<std::endl; return 1; } TFile* TFMCB= new TFile((MCResponseB.GetFP()).data()); TTree* MCBTree=(TTree*)TFMCB->Get("DecayTree"); if(!MCBTree){ std::cout<<"MC B Tree Null"<<std::endl; return 1; } TChain* MCChain = new TChain("DecayTree"); MCChain->Add((MCResponseA.GetFP()).data()); MCChain->Add((MCResponseB.GetFP()).data()); Long64_t N= MCChain->GetEntries(); std::cout<<"Entries In Chain = "<<N<<std::endl; //=============================== Loop over several cuts=============== LoopTimer LP(0.10); //PunziMVACut* TestCut= new PunziMVACut(MCChain,Background,0.2,5); std::vector<PunziMVACut*> Cuts; RooDataSet* Conductor=Background; int nCuts=15; int nFineCuts=25; FillableGraph* FG= new FillableGraph("Punzi FoM Optimisation;BDT Cut;Punzi FoM"); FillableGraph* FGThree = new FillableGraph("Punzi FoM Optimisation Sigma=3;BDT Cut; Punzi FoM"); FillableGraph* FGFour = new FillableGraph("Punzi FoM Optimisation Sigma=4;BDT Cut; Punzi FoM"); FillableGraph* SignalEfficiency= new FillableGraph("Signal Efficiency;BDT Cut;Signal Efficiency"); std::vector<double> CutVals; for(int i=0;i<nCuts;++i){ CutVals.push_back(0.0+(i*0.02)); } for(int f=0;f<nFineCuts;++f){ CutVals.push_back(0.30+(f*0.005)); } //CutVals.push_back(0.20); std::sort(CutVals.begin(),CutVals.end()); //CutVals.push_back(0.20); PunziMVACut* NoCut = new PunziMVACut(MCChain,Background,-1.0,false); for(auto V:CutVals){ LP.DeclareLoopStart(nCuts+nFineCuts); PunziMVACut* ACut= new PunziMVACut(MCChain,Conductor,V); Conductor=ACut->GetCutDataSetPtr(); Cuts.push_back(ACut); FG->Fill(ACut->GetCutValue(),ACut->GetFoM(5),0.0,ACut->GetFoMUncert(5)); FGThree->Fill(ACut->GetCutValue(),ACut->GetFoM(3),0.0,ACut->GetFoMUncert(3)); FGFour->Fill(ACut->GetCutValue(),ACut->GetFoM(4),0.0,ACut->GetFoMUncert(4)); SignalEfficiency->Fill(ACut->GetCutValue(),ACut->GetSignalEfficiency(),0,ACut->GetSignalEfficiencyUncert()); } std::string OutputString="Output_"; OutputString+=((year==Twel)? "12" : "11"); OutputString+=".root"; TFile* OutFile = new TFile(OutputString.data(),"RECREATE"); TCanvas* OutCanvas = new TCanvas("Punzi FoM","Punzi FoM",1200,1000); FG->Draw(); OutCanvas->Write(); FG->Write(); FGThree->Write(); FGFour->Write(); SignalEfficiency->Write(); Cuts.at(1)->GetSidebandHist()->Write(); TH1D* BaseLineHist=NoCut->GetSidebandHist(); TCanvas * SidebandCanvas = new TCanvas("SidebandCanvas","SidebandCanvas",1400,1000); bool first=true; for(int i=0;i<5;++i){ double cut=i*0.05; auto CutOne=std::find(Cuts.begin(),Cuts.end(),new PunziMVACut(cut)); std::cout<<(*CutOne)->GetCutValue()<<std::endl; TH1D* FRH=(*CutOne)->GetFractionRemovedHist(BaseLineHist); FRH->Write(); if(first)FRH->Draw(); else FRH->Draw("SAME"); first=false; } SidebandCanvas->Write(); }
void ProcessingTime(const char *inputFile) { TChain *chain = new TChain("Delphes"); chain->Add(inputFile); TH1F hist("time", "time", 50, 0, 0.01); Int_t i; TDirectory *currentDirectory = gDirectory; // Graphics style parameters to avoid grey background on figures gStyle->SetCanvasColor(kExRootBackgroundColor); gStyle->SetStatColor(kExRootBackgroundColor); // gStyle->SetTitleColor(kExRootBackgroundColor); gStyle->SetPadColor(kExRootBackgroundColor); gStyle->SetPadTopMargin(0.10); gStyle->SetPadRightMargin(0.10); gStyle->SetPadBottomMargin(0.15); gStyle->SetPadLeftMargin(0.15); gStyle->SetStatFont(kExRootFont); gStyle->SetStatFontSize(kExRootFontSize); gStyle->SetTitleFont(kExRootFont, ""); gStyle->SetTitleFont(kExRootFont, "X"); gStyle->SetTitleFont(kExRootFont, "Y"); gStyle->SetTitleFont(kExRootFont, "Z"); gStyle->SetTitleSize(kExRootFontSize, ""); gStyle->SetTitleSize(kExRootFontSize, "X"); gStyle->SetTitleSize(kExRootFontSize, "Y"); gStyle->SetTitleSize(kExRootFontSize, "Z"); gStyle->SetLabelFont(kExRootFont, "X"); gStyle->SetLabelFont(kExRootFont, "Y"); gStyle->SetLabelFont(kExRootFont, "Z"); gStyle->SetLabelSize(kExRootFontSize, "X"); gStyle->SetLabelSize(kExRootFontSize, "Y"); gStyle->SetLabelSize(kExRootFontSize, "Z"); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); gStyle->SetTextFont(kExRootFont); gStyle->SetTextSize(kExRootFontSize); gStyle->SetOptStat(111110); // gStyle->SetOptFit(101); canvas = static_cast<TCanvas*>(gROOT->FindObject("c1")); if(canvas) { canvas->Clear(); canvas->UseCurrentStyle(); canvas->SetWindowSize(800, 650); } else { canvas = new TCanvas("c1", "c1", 800, 650); } canvas->SetGrid(); canvas->SetHighLightColor(kExRootBackgroundColor); currentDirectory->cd(); for(i = 0; i < 9; ++i) { chain->Draw("Event.ProcTime >> time", TString::Format("Jet_size == %d", i+2)); gr.SetPoint(i, i+2, hist.GetMean()*1000); grerr.SetPoint(i, i+2, hist.GetMean()*1000); grerr.SetPointError(i, 0, hist.GetRMS()*1000); } grerr.GetXaxis()->SetLimits(1.0, 11.0); grerr.GetXaxis()->SetTitleOffset(1.5); grerr.GetYaxis()->SetTitleOffset(1.75); grerr.GetXaxis()->SetTitle("jet multiplicity"); grerr.GetYaxis()->SetTitle("processing time per event, ms"); gr.SetMarkerStyle(kFullCircle); gr.SetMarkerColor(kBlack); gr.SetMarkerSize(1); gr.SetLineColor(kBlack); gr.SetLineWidth(2); grerr.SetFillStyle(1001); grerr.SetFillColor(17); grerr.Draw("A3"); gr.Draw("P"); comment.SetTextSize(kExRootFontSize); comment.SetTextFont(kExRootFont); comment.SetTextAlign(22); comment.SetFillColor(kExRootBackgroundColor); comment.SetBorderSize(0); comment.AddText("ttbar + jets events"); comment.Draw(); }
bool dt_RunDrawTest(const char* from, Int_t mode = 0, Int_t verboseLevel = 0) { // This launch a test a TTree::Draw. // The mode currently available are: // 0: Do not load the shared library // 1: Load the shared library before opening the file // 2: Load the shared library after opening the file // 3: Simple TChain test with shared library // 4: Simple Friend test with shared library // The verboseLeve currently available: // 0: As silent as possible, only report errors and overall speed results. // 1: Output 0 + label for the start of each phase // 2: Output 1 + more details on the different phase being done // 3: Output 2 + stop at the first and draw a canvas showing the differences //gDebug = 5; SetVerboseLevel(verboseLevel); if (mode == 1) { if (!TClassTable::GetDict("Event")) { gSystem->Load("Event_cxx"); } gHasLibrary = kTRUE; } TFile *hfile = 0; TTree *tree = 0; if (mode <3) { hfile = new TFile(from); tree = (TTree*)hfile->Get("T"); } if (mode >= 2 && mode <= 4) { if (!TClassTable::GetDict("Event")) { gSystem->Load("Event_cxx"); } else { cerr << "Since libEvent.so has already been loaded, mode 2 can not be tested!"; cerr << endl; } gHasLibrary = kTRUE; } if (mode == 3) { // Test Chains. TChain * chain = new TChain("T"); chain->Add(from); chain->Add(from); tree = chain; } if (mode == 4) { // Test friends. tree = new TTree("T","Base of friendship"); tree->AddFriend("T",from); } TBranch *eb = tree->GetBranch("event"); gBranchStyle = (int) eb->InheritsFrom(TBranchElement::Class()); // cerr << "Branch style is " << gBranchStyle << endl; if (gQuietLevel<2) cout << "Generating histograms from TTree::Draw" << endl; TDirectory* where = GenerateDrawHist(tree,2,gQuietLevel); if (gQuietLevel<2) cout << "Comparing histograms" << endl; if (Compare(where)>0) { cout << "DrawTest: Comparison failed" << endl; return false; } DrawMarks(); if (gQuietLevel<2) cout << "DrawTest: Comparison was successfull" << endl; if (hfile) delete hfile; else delete tree; gROOT->GetList()->Delete(); return true; }
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- int main (int argc, char ** argv) { // check number of inpt parameters if(argc < 2){ cerr<<"Forgot to parse the cfg file --> exit "<<endl; return -1; } // Set Root style from global enviroment path string ROOTStyle; if(getenv ("ROOTStyle")!=NULL){ ROOTStyle = getenv ("ROOTStyle"); gROOT->ProcessLine((".x "+ROOTStyle+"/setTDRStyle.C").c_str()); } gStyle->SetOptStat(0); gStyle->SetPadTopMargin(0.09); gStyle->SetPadLeftMargin(0.13); gStyle->SetErrorX(0.5); // parse config file parameter if (gConfigParser) return 1 ; gConfigParser = new ConfigParser(); TString config ; config.Form("%s",argv[1]); if(!(gConfigParser->init(config))){ cout << ">>> parseConfigFile::Could not open configuration file " << config << endl; return -1; } // import base directory where samples are located and txt file with the directory name + other info string InputBaseDirectory = gConfigParser -> readStringOption("Input::InputBaseDirectory"); // import from cfg file the cross section value for this sample float CrossSection = gConfigParser -> readFloatOption("Input::CrossSection"); // total number of events int maxEventNumber = gConfigParser -> readFloatOption("Input::EventsNumber"); // treeName string treeName = gConfigParser -> readStringOption("Input::TreeName"); // take the cut list string InputCutList = gConfigParser -> readStringOption("Input::InputCutList"); // Read the cut file vector <cutContainer> CutList; if(ReadInputCutFile(InputCutList,CutList) <= 0){ cerr<<" Empty Cut List File or not Exisisting --> Exit "<<endl; return -1;} // take the variable list to be plotted string InputVariableList = gConfigParser -> readStringOption("Input::InputVariableList"); vector<variableContainer> variableList; if(ReadInputVariableFile(InputVariableList,variableList) <= 0 ){ cerr<<" Empty Variable List File or not Exisisting --> Exit "<<endl; return -1;} // take lumi and other parameters float lumi = gConfigParser -> readFloatOption("Option::Lumi"); // fb^(-1) lumi *= 1000. ; // transform into pb^(-1) finalStateString = gConfigParser -> readStringOption("Option::finalStateString"); matchingCone = gConfigParser -> readFloatOption("Option::matchingCone"); minLeptonCleaningPt = gConfigParser -> readFloatOption("Option::minLeptonCleaningPt"); minLeptonCutPt = gConfigParser -> readFloatOption("Option::minLeptonCutPt"); minJetCutPt = gConfigParser -> readFloatOption("Option::minJetCutPt"); usePuppiAsDefault = gConfigParser -> readBoolOption("Option::usePuppiAsDefault"); leptonIsoCut_mu = gConfigParser -> readFloatOption("Option::leptonIsoCutMu"); leptonIsoCut_el = gConfigParser -> readFloatOption("Option::leptonIsoCutEl"); leptonIsoCutLoose = gConfigParser -> readFloatOption("Option::leptonIsoCutLoose"); // output directory string outputPlotDirectory = gConfigParser -> readStringOption("Output::outputPlotDirectory"); system(("mkdir -p output/"+outputPlotDirectory).c_str()); system(("rm -r output/"+outputPlotDirectory+"/*").c_str()); system(("mkdir -p output/"+outputPlotDirectory+"/xs").c_str()); system(("mkdir -p output/"+outputPlotDirectory+"/norm").c_str()); ///// Start the analysis map<string,TH1F*> histoCutEff ; TChain* chain = new TChain (treeName.c_str()) ; chain->Add ((InputBaseDirectory+"/*.root").c_str()) ; int totEvent = chain->GetEntries(); readTree* reader = new readTree((TTree*)(chain)); cout<<"Lumi (fb-1) "<<lumi/1000<<" entries before "<<totEvent<<" cross section "<<CrossSection<<" Nevents before selections "<<lumi*CrossSection<<" weight "<<lumi*CrossSection/float(totEvent)<<endl; float weight = 1.0*lumi*CrossSection/float(totEvent) ; // make the plot container vector<histoContainer> plotVector; for(size_t iCut = 0; iCut < CutList.size(); iCut++){ histoCutEff["WW_EWK_pos_"+to_string(iCut)+"_"+CutList.at(iCut).cutLayerName] = new TH1F(("WW_EWK_pos_"+to_string(iCut)+"_"+CutList.at(iCut).cutLayerName).c_str(),"",15,0,15); for(size_t iVar = 0; iVar < variableList.size(); iVar++){ plotVector.push_back(histoContainer(CutList.at(iCut).cutLayerName,variableList.at(iVar))); } } int passingLHEFilter = 0 ; int maximumEvents = chain->GetEntries () ; if (maxEventNumber > 0 && maxEventNumber < maximumEvents) maximumEvents = maxEventNumber ; // Loop on the events for(int iEvent = 0; iEvent < maximumEvents ; iEvent++){ reader->fChain->GetEntry(iEvent) ; if (iEvent % 100000 == 0) cout << "reading event " << iEvent << "\n" ; // filter LHE level leptons if(TString(finalStateString).Contains("UU")){ if(fabs(reader->leptonLHEpid1) != 13 or fabs(reader->leptonLHEpid2) != 13) continue; } else if(TString(finalStateString).Contains("EE")){ if(fabs(reader->leptonLHEpid1) != 11 or fabs(reader->leptonLHEpid2) != 11) continue; } else if(TString(finalStateString).Contains("EU")){ if(fabs(reader->leptonLHEpid1) != 11 or fabs(reader->leptonLHEpid2) !=13) continue ; } else if(TString(finalStateString).Contains("UE")){ if(fabs(reader->leptonLHEpid1) != 13 or fabs(reader->leptonLHEpid2) !=11) continue ; } else{ cerr<<"problem with lhe level filter definition --> skip event"<<endl; continue; } passingLHEFilter++; // if an event pass the cut, fill the associated map leptonContainer lepton1,lepton2,parton1,parton2,neutrino1,neutrino2,vboson1,vboson2; lepton1.lepton4V_.SetPtEtaPhiM(reader->leptonLHEpt1,reader->leptonLHEeta1,reader->leptonLHEphi1,reader->leptonLHEm1); lepton1.charge_ = reader->leptonLHEch1; lepton1.flavour_ = reader->leptonLHEpid1; lepton2.lepton4V_.SetPtEtaPhiM(reader->leptonLHEpt2,reader->leptonLHEeta2,reader->leptonLHEphi2,reader->leptonLHEm2); lepton2.charge_ = reader->leptonLHEch2; lepton2.flavour_ = reader->leptonLHEpid2; parton1.lepton4V_.SetPtEtaPhiM(reader->jetLHEPartonpt1,reader->jetLHEPartoneta1,reader->jetLHEPartonphi1,0.); parton2.lepton4V_.SetPtEtaPhiM(reader->jetLHEPartonpt2,reader->jetLHEPartoneta2,reader->jetLHEPartonphi2,0.); neutrino1.lepton4V_.SetPtEtaPhiM(reader->neutrinoLHEpt1,reader->neutrinoLHEeta1,reader->neutrinoLHEphi1,0.); neutrino1.charge_ = 0.; neutrino1.flavour_ = reader->neutrinoLHEpid1; neutrino2.lepton4V_.SetPtEtaPhiM(reader->neutrinoLHEpt2,reader->neutrinoLHEeta2,reader->neutrinoLHEphi2,0.); neutrino2.charge_ = 0.; neutrino2.flavour_ = reader->neutrinoLHEpid2; vboson1.lepton4V_.SetPtEtaPhiM(reader->vbosonLHEpt1,reader->vbosonLHEeta1,reader->vbosonLHEphi1,reader->vbosonLHEm1); vboson1.charge_ = reader->vbosonLHEch1; vboson1.flavour_ = reader->vbosonLHEpid1; vboson2.lepton4V_.SetPtEtaPhiM(reader->vbosonLHEpt2,reader->vbosonLHEeta2,reader->vbosonLHEphi2,reader->vbosonLHEm2); vboson2.charge_ = reader->vbosonLHEch2; vboson2.flavour_ = reader->vbosonLHEpid2; float minDR_1 = 999; float minDR_2 = 999; vector<leptonContainer> lepton, neutrino; lepton.push_back(lepton1); lepton.push_back(lepton2); neutrino.push_back(neutrino1); neutrino.push_back(neutrino2); leptonContainer leptFromV1, leptFromV2, neuFromV1, neuFromV2; for(size_t iLep= 0; iLep < lepton.size(); iLep++){ for(size_t iNeu = 0; iNeu < neutrino.size(); iNeu++){ if((lepton.at(iLep).lepton4V_+neutrino.at(iNeu).lepton4V_).DeltaR(vboson1.lepton4V_) < minDR_1 ){ minDR_1 = (lepton.at(iLep).lepton4V_+neutrino.at(iNeu).lepton4V_).DeltaR(vboson1.lepton4V_); leptFromV1 = lepton.at(iLep); neuFromV1 = neutrino.at(iNeu); } if((lepton.at(iLep).lepton4V_+neutrino.at(iNeu).lepton4V_).DeltaR(vboson2.lepton4V_) < minDR_2){ minDR_2 = (lepton.at(iLep).lepton4V_+neutrino.at(iNeu).lepton4V_).DeltaR(vboson2.lepton4V_); leptFromV2 = lepton.at(iLep); neuFromV2 = neutrino.at(iNeu); } } } if(leptFromV1.lepton4V_ == leptFromV2.lepton4V_ or neuFromV1.lepton4V_ == neuFromV2.lepton4V_){ cerr<<" bad matching with gen W "<<endl; continue; } double costheta1 = 0; double costheta2 = 0; double Phi = 0; double costhetastar = 0; double Phi1 = 0; double costheta1_vbf = 0; double costheta2_vbf = 0; double Phi_vbf = 0; double costhetastar_vbf = 0; double Phi1_vbf = 0; TLorentzVector VV = vboson1.lepton4V_ + vboson2.lepton4V_; if(leptFromV1.charge_ > 0 and leptFromV2.charge_ > 0){ computeAnglesResonance(VV,vboson1.lepton4V_,neuFromV1.lepton4V_,leptFromV1.lepton4V_,vboson2.lepton4V_,neuFromV2.lepton4V_,leptFromV2.lepton4V_, costheta1,costheta2,Phi,costhetastar,Phi1); computeAnglesVBF(VV,vboson1.lepton4V_,neuFromV1.lepton4V_,leptFromV1.lepton4V_,vboson2.lepton4V_,neuFromV2.lepton4V_,leptFromV2.lepton4V_,parton1.lepton4V_, parton2.lepton4V_,costheta1_vbf,costheta2_vbf,Phi_vbf,costhetastar_vbf,Phi1_vbf); } else if(leptFromV1.charge_ < 0 and leptFromV2.charge_ < 0){ computeAnglesResonance(VV,vboson1.lepton4V_,leptFromV1.lepton4V_,neuFromV1.lepton4V_,vboson2.lepton4V_,leptFromV2.lepton4V_,neuFromV2.lepton4V_, costheta1,costheta2,Phi,costhetastar,Phi1); computeAnglesVBF(VV,vboson1.lepton4V_,leptFromV1.lepton4V_,neuFromV1.lepton4V_,vboson2.lepton4V_,leptFromV2.lepton4V_,neuFromV2.lepton4V_,parton1.lepton4V_, parton2.lepton4V_,costheta1_vbf,costheta2_vbf,Phi_vbf,costhetastar_vbf,Phi1_vbf); } else if(leptFromV1.charge_ < 0 and leptFromV2.charge_ > 0){ computeAnglesResonance(VV,vboson1.lepton4V_,leptFromV1.lepton4V_,neuFromV1.lepton4V_,vboson2.lepton4V_,neuFromV2.lepton4V_,leptFromV2.lepton4V_, costheta1,costheta2,Phi,costhetastar,Phi1); computeAnglesVBF(VV,vboson1.lepton4V_,leptFromV1.lepton4V_,neuFromV1.lepton4V_,vboson2.lepton4V_,neuFromV2.lepton4V_,leptFromV2.lepton4V_,parton1.lepton4V_, parton2.lepton4V_,costheta1_vbf,costheta2_vbf,Phi_vbf,costhetastar_vbf,Phi1_vbf); } else if(leptFromV1.charge_ > 0 and leptFromV2.charge_ < 0){ computeAnglesResonance(VV,vboson1.lepton4V_,neuFromV1.lepton4V_,leptFromV1.lepton4V_,vboson2.lepton4V_,leptFromV2.lepton4V_,neuFromV2.lepton4V_, costheta1,costheta2,Phi,costhetastar,Phi1); computeAnglesVBF(VV,vboson1.lepton4V_,neuFromV1.lepton4V_,leptFromV1.lepton4V_,vboson2.lepton4V_,leptFromV2.lepton4V_,neuFromV2.lepton4V_,parton1.lepton4V_, parton2.lepton4V_,costheta1_vbf,costheta2_vbf,Phi_vbf,costhetastar_vbf,Phi1_vbf); } else{ cerr<<" wrong charge composition "<<endl; continue; } float mTR = 0; float mR = 0; TLorentzVector L_met ,L_dijet, L_dilepton, L_LLmet; L_met = neutrino1.lepton4V_ + neutrino2.lepton4V_; L_dijet = parton1.lepton4V_ + parton2.lepton4V_; L_dilepton = lepton1.lepton4V_ + lepton2.lepton4V_; L_LLmet = L_dilepton + L_met ; computeRazor(lepton1.lepton4V_,lepton2.lepton4V_,L_met,mTR,mR); if(lepton1.lepton4V_.Pt() < minLeptonCutPt or lepton2.lepton4V_.Pt() < minLeptonCutPt) continue; // Loop on the cut list --> one cut for each polarization for(size_t iCut = 0; iCut < CutList.size(); iCut++){ // cut the events string name = "WW_EWK"; if(!passCutContainerSelection(reader, CutList.at(iCut), name, int(iCut), usePuppiAsDefault, minLeptonCutPt, minLeptonCleaningPt, leptonIsoCut_mu, leptonIsoCut_el, leptonIsoCutLoose, matchingCone, minJetCutPt, histoCutEff, finalStateString)) continue; float asimL = (lepton1.lepton4V_.Pt()-lepton2.lepton4V_.Pt())/(lepton1.lepton4V_.Pt()+lepton2.lepton4V_.Pt()) ; float asimJ = (parton1.lepton4V_.Pt()-parton2.lepton4V_.Pt())/(parton1.lepton4V_.Pt()+parton2.lepton4V_.Pt()) ; float Rvar = (lepton1.lepton4V_.Pt()*lepton2.lepton4V_.Pt())/(parton1.lepton4V_.Pt()*parton2.lepton4V_.Pt()) ; // loop on variables for(size_t iVar = 0; iVar < variableList.size(); iVar++){ histoContainer tmpPlot; tmpPlot.cutName = CutList.at(iCut).cutLayerName; tmpPlot.varName = variableList.at(iVar).variableName; vector<histoContainer>::iterator itVec ; itVec = find(plotVector.begin(),plotVector.end(),tmpPlot); if(itVec == plotVector.end()){ cerr<<"Problem -->plot not found for "<<CutList.at(iCut).cutLayerName<<" "<<variableList.at(iVar).variableName<<endl; continue ; } // vector boson info if(variableList.at(iVar).variableName == "ptV1"){ itVec->histogram->Fill(vboson1.lepton4V_.Pt(),1.*weight) ; } else if(variableList.at(iVar).variableName == "ptV2"){ itVec->histogram->Fill(vboson2.lepton4V_.Pt(),weight) ; } else if(variableList.at(iVar).variableName == "etaV1"){ itVec->histogram->Fill(vboson1.lepton4V_.Eta(),weight) ; } else if(variableList.at(iVar).variableName == "etaV2"){ itVec->histogram->Fill(vboson2.lepton4V_.Eta(),weight) ; } else if(variableList.at(iVar).variableName == "ptVV"){ itVec->histogram->Fill(L_dijet.Pt(),weight) ; } else if(variableList.at(iVar).variableName == "mVV"){ itVec->histogram->Fill(L_dijet.M(),weight) ; } // decay information if(variableList.at(iVar).variableName == "costheta1"){ itVec->histogram->Fill(fabs(costheta1),1.*weight) ; } else if(variableList.at(iVar).variableName == "costheta2"){ itVec->histogram->Fill(fabs(costheta2),weight) ; } if(variableList.at(iVar).variableName == "costheta1_vbf"){ itVec->histogram->Fill(fabs(costheta1_vbf),1.*weight) ; } else if(variableList.at(iVar).variableName == "costheta2_vbf"){ itVec->histogram->Fill(fabs(costheta2_vbf),weight) ; } if(variableList.at(iVar).variableName == "Phi"){ itVec->histogram->Fill(fabs(Phi),1.*weight) ; } else if(variableList.at(iVar).variableName == "Phi1"){ itVec->histogram->Fill(fabs(Phi1),weight) ; } if(variableList.at(iVar).variableName == "Phi_vbf"){ itVec->histogram->Fill(fabs(Phi_vbf),1.*weight) ; } else if(variableList.at(iVar).variableName == "Phi1_vbf"){ itVec->histogram->Fill(fabs(Phi1_vbf),weight) ; } else if(variableList.at(iVar).variableName == "costhetastar"){ itVec->histogram->Fill(fabs(costhetastar),weight) ; } else if(variableList.at(iVar).variableName == "costhetastar_vbf"){ itVec->histogram->Fill(fabs(costhetastar_vbf),weight) ; } else if(variableList.at(iVar).variableName == "mTR"){ itVec->histogram->Fill(mTR,weight) ; } else if(variableList.at(iVar).variableName == "mR"){ itVec->histogram->Fill(mR,weight) ; } // jet info if(variableList.at(iVar).variableName == "ptj1"){ itVec->histogram->Fill(parton1.lepton4V_.Pt(),1.*weight) ; } else if(variableList.at(iVar).variableName == "ptj2"){ itVec->histogram->Fill(parton2.lepton4V_.Pt(),weight) ; } else if(variableList.at(iVar).variableName == "etaj1"){ itVec->histogram->Fill(parton1.lepton4V_.Eta(),weight) ; } else if(variableList.at(iVar).variableName == "etaj2"){ itVec->histogram->Fill(parton2.lepton4V_.Eta(),weight) ; } else if(variableList.at(iVar).variableName == "detajj"){ itVec->histogram->Fill(fabs(parton1.lepton4V_.Eta()-parton2.lepton4V_.Eta()),weight) ; } else if(variableList.at(iVar).variableName == "ptjj"){ itVec->histogram->Fill(L_dijet.Pt(),weight) ; } else if(variableList.at(iVar).variableName == "mjj"){ itVec->histogram->Fill(L_dijet.M(),weight) ; } else if(variableList.at(iVar).variableName == "Asim_j"){ itVec->histogram->Fill(asimJ,weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_JJ"){ itVec->histogram->Fill(fabs(parton1.lepton4V_.DeltaPhi(parton2.lepton4V_)),weight) ; } else if(variableList.at(iVar).variableName == "ptl1"){ itVec->histogram->Fill(lepton1.lepton4V_.Pt(),weight) ; } else if(variableList.at(iVar).variableName == "ptl2"){ itVec->histogram->Fill(lepton2.lepton4V_.Pt(),weight) ; } else if(variableList.at(iVar).variableName == "etal1"){ itVec->histogram->Fill(lepton1.lepton4V_.Eta(),weight) ; } else if(variableList.at(iVar).variableName == "etal2"){ itVec->histogram->Fill(lepton2.lepton4V_.Eta(),weight) ; } else if(variableList.at(iVar).variableName == "mll"){ itVec->histogram->Fill(L_dilepton.M(),weight) ; } else if(variableList.at(iVar).variableName == "ptll"){ itVec->histogram->Fill(L_dilepton.Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_LL"){ itVec->histogram->Fill(fabs(lepton1.lepton4V_.DeltaPhi(lepton2.lepton4V_)),weight) ; } else if(variableList.at(iVar).variableName == "Asim_l"){ itVec->histogram->Fill(asimL,weight) ; } else if(variableList.at(iVar).variableName == "met"){ itVec->histogram->Fill(L_met.Pt(),weight) ; } else if(variableList.at(iVar).variableName == "R"){ itVec->histogram->Fill(Rvar,weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_LMet"){ itVec->histogram->Fill(fabs(lepton1.lepton4V_.DeltaPhi(L_met)),weight) ; } else if(variableList.at(iVar).variableName == "ptLMet"){ itVec->histogram->Fill((lepton1.lepton4V_ + L_met).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_TLMet"){ itVec->histogram->Fill(fabs(lepton1.lepton4V_.DeltaPhi(L_met)),weight) ; } else if(variableList.at(iVar).variableName == "ptTLMet"){ itVec->histogram->Fill((lepton2.lepton4V_ + L_met).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_LLMet"){ itVec->histogram->Fill(fabs(L_dilepton.DeltaPhi(L_met)),weight) ; } else if(variableList.at(iVar).variableName == "ptLLMet"){ itVec->histogram->Fill((L_dilepton + L_met).Pt(),weight) ; } /// else if(variableList.at(iVar).variableName == "DeltaPhi_LJL"){ itVec->histogram->Fill(fabs(lepton1.lepton4V_.DeltaPhi(parton1.lepton4V_)),weight) ; } else if(variableList.at(iVar).variableName == "ptLJL"){ itVec->histogram->Fill((lepton1.lepton4V_+parton1.lepton4V_).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_TJL"){ itVec->histogram->Fill(fabs(lepton1.lepton4V_.DeltaPhi(parton2.lepton4V_)),weight) ; } else if(variableList.at(iVar).variableName == "ptTJL"){ itVec->histogram->Fill((lepton1.lepton4V_+parton2.lepton4V_).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_JJL"){ itVec->histogram->Fill(fabs(lepton1.lepton4V_.DeltaPhi(L_dijet)),weight) ; } else if(variableList.at(iVar).variableName == "ptJJL"){ itVec->histogram->Fill((lepton1.lepton4V_+L_dijet).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_LJTL"){ itVec->histogram->Fill(fabs(lepton2.lepton4V_.DeltaPhi(parton1.lepton4V_)),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_TJTL"){ itVec->histogram->Fill(fabs(lepton2.lepton4V_.DeltaPhi(parton2.lepton4V_)),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_JJTL"){ itVec->histogram->Fill(fabs(lepton2.lepton4V_.DeltaPhi(L_dijet)),weight) ; } else if(variableList.at(iVar).variableName == "ptLJTL"){ itVec->histogram->Fill((lepton2.lepton4V_+parton1.lepton4V_).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "ptTJTL"){ itVec->histogram->Fill((lepton2.lepton4V_+parton2.lepton4V_).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "ptJJTL"){ itVec->histogram->Fill((lepton2.lepton4V_+L_dijet).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_LJLL"){ itVec->histogram->Fill(fabs(L_dilepton.DeltaPhi(parton1.lepton4V_)),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_TJLL"){ itVec->histogram->Fill(fabs(L_dilepton.DeltaPhi(parton2.lepton4V_)),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_JJLL"){ itVec->histogram->Fill(fabs(L_dilepton.DeltaPhi(L_dijet)),weight) ; } else if(variableList.at(iVar).variableName == "ptLJLL"){ itVec->histogram->Fill((L_dilepton+parton1.lepton4V_).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "ptTJLL"){ itVec->histogram->Fill((L_dilepton+parton2.lepton4V_).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "ptJJLL"){ itVec->histogram->Fill((L_dilepton+L_dijet).Pt(),weight) ; } /// else if(variableList.at(iVar).variableName == "DeltaPhi_JJMet"){ itVec->histogram->Fill(fabs(L_dijet.DeltaPhi(L_met)),weight) ; } else if(variableList.at(iVar).variableName == "ptJJMet"){ itVec->histogram->Fill((L_dijet+L_met).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_LJMet"){ itVec->histogram->Fill(fabs(parton1.lepton4V_.DeltaPhi(L_met)),weight) ; } else if(variableList.at(iVar).variableName == "ptLJMet"){ itVec->histogram->Fill((parton1.lepton4V_+L_met).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "DeltaPhi_TJMet"){ itVec->histogram->Fill(fabs(parton2.lepton4V_.DeltaPhi(L_met)),weight) ; } else if(variableList.at(iVar).variableName == "ptTJMet"){ itVec->histogram->Fill((parton2.lepton4V_+L_met).Pt(),weight) ; } else if(variableList.at(iVar).variableName == "mlljj"){ itVec->histogram->Fill((L_dilepton+L_dijet).M(),weight) ; } else if(variableList.at(iVar).variableName == "mlljjmet"){ itVec->histogram->Fill((L_dilepton+L_dijet+L_met).M(),weight) ; } else if(variableList.at(iVar).variableName == "mTH"){ itVec->histogram->Fill(sqrt(2*L_dilepton.Pt()*L_met.Pt()*(1-TMath::Cos(L_dilepton.DeltaPhi(L_met)))),weight) ; } } // loop on variables } // Loop on the cut list } // Loop on the events TFile* outputEfficiency = new TFile(("output/"+outputPlotDirectory+"/outputEfficiency.root").c_str(),"RECREATE"); for(map<string,TH1F*>::const_iterator itMap = histoCutEff.begin(); itMap != histoCutEff.end(); itMap++){ itMap->second->Scale(1./itMap->second->GetBinContent(1)); itMap->second->Write(); } outputEfficiency->Close(); // make the canvas and basic banners TCanvas *cCanvas = new TCanvas("cCanvas","",1,52,550,550); cCanvas->SetTicks(); cCanvas->SetFillColor(0); cCanvas->SetBorderMode(0); cCanvas->SetBorderSize(2); cCanvas->SetTickx(1); cCanvas->SetTicky(1); cCanvas->SetRightMargin(0.05); cCanvas->SetBottomMargin(0.12); cCanvas->SetFrameBorderMode(0); cCanvas->cd(); TPad* upperPad = new TPad("upperPad", "upperPad", .005, .180, .995, .980); TPad* lowerPad = new TPad("lowerPad", "lowerPad", .005, .005, .995, .18); lowerPad->SetGridx(); lowerPad->SetGridy(); upperPad->SetLeftMargin(0.12); upperPad->SetRightMargin(0.1); lowerPad->SetLeftMargin(0.12); lowerPad->SetRightMargin(0.1); lowerPad->SetTopMargin(0.002); lowerPad->Draw(); upperPad->Draw(); TCanvas *cCanvasNorm = new TCanvas("cCanvasNorm","",1,52,550,550); cCanvasNorm->SetTicks(); cCanvasNorm->SetFillColor(0); cCanvasNorm->SetBorderMode(0); cCanvasNorm->SetBorderSize(2); cCanvasNorm->SetTickx(1); cCanvasNorm->SetTicky(1); cCanvasNorm->SetRightMargin(0.05); cCanvasNorm->SetBottomMargin(0.12); cCanvasNorm->SetFrameBorderMode(0); TLatex * tex = new TLatex(0.88,0.92," 14 TeV"); tex->SetNDC(); tex->SetTextAlign(31); tex->SetTextFont(42); tex->SetTextSize(0.045); tex->SetLineWidth(2); TLatex * tex2 = new TLatex(0.14,0.92,"Delphes"); tex2->SetNDC(); tex2->SetTextFont(61); tex2->SetTextSize(0.045); tex2->SetLineWidth(2); TLatex * tex3 = new TLatex(0.295,0.92,"Simulation Preliminary"); tex3->SetNDC(); tex3->SetTextFont(52); tex3->SetTextSize(0.04); tex3->SetLineWidth(2); TLegend* legend = new TLegend(0.55,0.75,0.85,0.89); legend->SetBorderSize(0); legend->SetFillColor(0); legend->SetFillStyle(0); legend->SetTextSize(0.04); legend->SetTextFont(42); legend->SetNColumns (3) ; // make the plot on the same canvas for each variable (legend entry is the cut layer name) vector<TH1F*> numerator ; vector<TH1F*> denominator ; for(size_t iVar = 0; iVar < variableList.size(); iVar++){ // loop on var numerator.clear(); denominator.clear(); for(size_t iCut = 0; iCut < CutList.size(); iCut++){ // loop on cuts histoContainer tmpPlot; tmpPlot.cutName = CutList.at(iCut).cutLayerName; tmpPlot.varName = variableList.at(iVar).variableName; vector<histoContainer>::iterator itVec ; itVec = find(plotVector.begin(),plotVector.end(),tmpPlot); if(itVec == plotVector.end()){ cerr<<"Problem -->plot not found for "<<CutList.at(iCut).cutLayerName<<" "<<variableList.at(iVar).variableName<<endl; } itVec->histogram->GetXaxis()->SetTitleSize(0.04); itVec->histogram->GetXaxis()->SetTitleOffset(1.16); itVec->histogram->GetXaxis()->SetLabelSize(0.04); itVec->histogram->GetYaxis()->SetRangeUser(0.001,itVec->histogram->GetMaximum()*1.25); itVec->histogram->GetYaxis()->SetTitleSize(0.05); itVec->histogram->GetYaxis()->SetTitleOffset(1.20); itVec->histogram->GetYaxis()->SetLabelSize(0.04); itVec->histogram->SetLineColor(iCut+1); if(iCut %2 == 0) itVec->histogram->SetLineStyle(1); else itVec->histogram->SetLineStyle(2); itVec->histogram->SetLineWidth(2); itVec->histogram->GetYaxis()->SetTitle("#sigma x lumi"); upperPad->cd(); if(iCut == 0) itVec->histogram->Draw("hist"); else itVec->histogram->Draw("hist same"); legend->AddEntry(itVec->histogram,CutList.at(iCut).cutLayerName.c_str(),"l"); if(itVec->findCutByLabel("LL")) numerator.push_back(itVec->histogram); denominator.push_back(itVec->histogram); cCanvasNorm->cd(); TH1F* htempNorm = (TH1F*) itVec->histogram->Clone((string(itVec->histogram->GetName())+"_norm").c_str()); htempNorm->Scale(1./itVec->histogram->Integral()); htempNorm->GetYaxis()->SetRangeUser(0.,htempNorm->GetMaximum()*1.5); if(iCut == 0) htempNorm->Draw("hist"); else htempNorm->Draw("hist same"); } // make ratio plot lowerPad->cd(); TH1F* numTotal = 0; TH1F* denTotal = 0; TH1F* ratio = 0; TH1F* ratioW = 0; for(size_t itNum = 0; itNum < numerator.size(); itNum ++){ if(itNum == 0 and ratio == 0) numTotal = (TH1F*) numerator.at(itNum)->Clone(("Num_"+string(numerator.at(itNum)->GetName())).c_str()); else if(ratio !=0) numTotal->Add(numerator.at(itNum)); } for(size_t itDen = 0; itDen < denominator.size(); itDen ++){ if(itDen == 0 and denTotal == 0 ) { denTotal = (TH1F*) denominator.at(itDen)->Clone(("Den_"+string(denominator.at(itDen)->GetName())).c_str()); } else if(denTotal !=0){ denTotal->Add(denominator.at(itDen)); } } ratio = new TH1F(("Ratio_"+string(denominator.at(0)->GetName())).c_str(),"",numTotal->GetNbinsX(),numTotal->GetBinLowEdge(1),numTotal->GetBinLowEdge(numTotal->GetNbinsX()+1)); ratio->GetYaxis()->SetTitle("S/(#sqrt{S+B})"); ratio->SetMarkerSize(1.1); ratioW = new TH1F(("ratioW_"+string(denominator.at(0)->GetName())).c_str(),"",numTotal->GetNbinsX(),numTotal->GetBinLowEdge(1),numTotal->GetBinLowEdge(numTotal->GetNbinsX()+1)); ratioW->GetYaxis()->SetTitle("weighted S/(#sqrt{S+B})"); ratioW->SetMarkerSize(1.1); TString name = "norm_" ; name += denTotal->GetName () ; TH1F * norm_denTotal = (TH1F *) denTotal->Clone (name) ; norm_denTotal->Scale (1. / norm_denTotal->GetMaximum ()) ; // weight the S/sqrt (B) by the shape of the total, // so that only bins with a lot of stats become visibly significant for(int iBin = 0; iBin < ratio->GetNbinsX()+1; iBin++){ if(denTotal->GetBinContent(iBin) !=0){ ratioW->SetBinContent(iBin, norm_denTotal->GetBinContent (iBin) * numTotal->GetBinContent(iBin) / sqrt(denTotal->GetBinContent(iBin))); ratio->SetBinContent(iBin, numTotal->GetBinContent(iBin) / sqrt(denTotal->GetBinContent(iBin))); } else ratio->SetBinContent(iBin,0.); } ratio->GetXaxis()->SetTitle(""); ratio->SetLineColor(kBlue); ratio->SetLineStyle(2); ratio->SetLineWidth(2); ratio->GetXaxis()->SetLabelOffset(999); ratio->GetXaxis()->SetLabelSize(0); ratio->GetYaxis()->SetLabelSize(0.15); ratio->GetYaxis()->SetTitleSize(0.15); ratio->GetYaxis()->SetTitleOffset(0.30); ratio->GetYaxis()->SetNdivisions(504); ratioW->GetXaxis()->SetTitle(""); ratioW->SetLineColor(kBlack); ratioW->SetLineWidth(2); ratioW->GetXaxis()->SetLabelOffset(999); ratioW->GetXaxis()->SetLabelSize(0); ratioW->GetYaxis()->SetLabelSize(0.15); ratioW->GetYaxis()->SetTitleSize(0.15); ratioW->GetYaxis()->SetTitleOffset(0.30); ratioW->GetYaxis()->SetNdivisions(504); ratio->GetYaxis()->SetRange(min(ratio->GetMinimum(),ratioW->GetMinimum())*0.9,max(ratio->GetMaximum(),ratioW->GetMaximum())*1.1); TH1F * frame = lowerPad->DrawFrame (ratio->GetXaxis ()->GetXmin (), 0., ratio->GetXaxis ()->GetXmax (), 2.) ; frame->GetXaxis()->SetTitle (ratio->GetXaxis ()->GetTitle ()) ; frame->GetYaxis()->SetTitle (ratio->GetYaxis ()->GetTitle ()) ; frame->GetXaxis()->SetLabelOffset(999); frame->GetXaxis()->SetLabelSize(0); frame->GetYaxis()->SetLabelSize(0.15); frame->GetYaxis()->SetTitleSize(0.15); frame->GetYaxis()->SetTitleOffset(0.30); frame->GetYaxis()->SetNdivisions(504); ratio->Draw("P"); ratioW->Draw("Lsame"); upperPad->cd(); tex->Draw("same"); tex2->Draw("same"); tex3->Draw("same"); legend->Draw("same"); cCanvas->SaveAs(string("output/"+outputPlotDirectory+"/xs/"+variableList.at(iVar).variableName+".pdf").c_str(),"pdf"); cCanvas->SaveAs(string("output/"+outputPlotDirectory+"/xs/"+variableList.at(iVar).variableName+".png").c_str(),"png"); cCanvas->SaveAs(string("output/"+outputPlotDirectory+"/xs/"+variableList.at(iVar).variableName+".root").c_str(),"root"); cCanvasNorm->cd(); tex->Draw("same"); tex2->Draw("same"); tex3->Draw("same"); legend->Draw("same"); cCanvasNorm->SaveAs(string("output/"+outputPlotDirectory+"/norm/"+variableList.at(iVar).variableName+".pdf").c_str(),"pdf"); cCanvasNorm->SaveAs(string("output/"+outputPlotDirectory+"/norm/"+variableList.at(iVar).variableName+".png").c_str(),"png"); cCanvasNorm->SaveAs(string("output/"+outputPlotDirectory+"/norm/"+variableList.at(iVar).variableName+".root").c_str(),"root"); legend->Clear(); } // loop on var cout<<"LHE filter efficiency : "<<passingLHEFilter<<" totEvent "<<totEvent<<" efficiency "<<float(passingLHEFilter)/float(totEvent)*100<<" % "<<endl; //Normalize histograms for(size_t ihisto = 0; ihisto < plotVector.size(); ihisto++){ if(plotVector.at(ihisto).varName == "DeltaPhi_LL") cout<<"Events Histo "<<plotVector.at(ihisto).histogram->GetName()<<" unweighted "<<plotVector.at(ihisto).histogram->GetEntries()<<" weighted "<<plotVector.at(ihisto).histogram->Integral(0,plotVector.at(ihisto).histogram->GetNbinsX()+1)<<endl; } return 0 ; }
void produce_bgtemplate(){//main // TFile *efile = TFile::Open("plot_elefakepho_test.root","read"); // TTree* etree = (TTree*)efile->Get("FakeRateTree"); TChain *etree = new TChain("BGTree"); etree->Add("../data/plot_bgtemplate_singleMu.root"); // etree->Add("../data/plot_elefakepho_DY_74X.root"); int tracks=0; int nVertex=0; float mass_denmg=0,mass_nummg=0,et_denmg=0,et_nummg=0, rap_denmg=0, rap_nummg=0; etree->SetBranchAddress("tracks",&tracks); etree->SetBranchAddress("nVertex",&nVertex); etree->SetBranchAddress("mass_denmg", &mass_denmg); etree->SetBranchAddress("mass_nummg", &mass_nummg); etree->SetBranchAddress("et_denmg", &et_denmg); etree->SetBranchAddress("et_nummg", &et_nummg); etree->SetBranchAddress("rap_denmg", &rap_denmg); etree->SetBranchAddress("rap_nummg", &rap_nummg); float PtBins[]={25,30,35,40,50,60,70}; //float PtBins[]={25,30,35,40,45,50,60,70,90,110}; float NtrkBins[] = {10,20,30,40,50,60,70,90,120}; float EtaBins[] = {0.0,0.1,0.2,0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3}; float VertexBins[]={0,4,8,10,11,12,13,14,15,16,17,18,20}; unsigned nPtBins = sizeof(PtBins)/sizeof(float); unsigned nNtrkBins = sizeof(NtrkBins)/sizeof(float); unsigned nEtaBins = sizeof(EtaBins)/sizeof(float); unsigned nVertexBins = sizeof(VertexBins)/sizeof(float); TFile *outputfile = TFile::Open("histo_bgtemplate_76X.root","RECREATE"); outputfile->cd(); TH1F* den_mg_pt[nPtBins]; TH1F* den_mg_trk[nNtrkBins]; TH1F* den_mg_eta[nEtaBins]; TH1F* den_mg_vtx[nVertexBins]; TH1F* num_mg_pt[nPtBins]; TH1F* num_mg_trk[nNtrkBins]; TH1F* num_mg_eta[nEtaBins]; TH1F* num_mg_vtx[nVertexBins]; std::ostringstream binname; for(unsigned iPt(0); iPt < nPtBins; iPt++){ binname.str(""); if(iPt != nPtBins-1)binname << "den_mg_pt-" << PtBins[iPt] << "-" << PtBins[iPt+1]; else binname << "den_mg_pt-" << PtBins[iPt] << "-inf"; den_mg_pt[iPt] = new TH1F(binname.str().c_str(), binname.str().c_str(), 60, 60,120); binname.str(""); if(iPt != nPtBins-1)binname << "num_mg_pt-" << PtBins[iPt] << "-" << PtBins[iPt+1]; else binname << "num_mg_pt-" << PtBins[iPt] << "-inf"; num_mg_pt[iPt] = new TH1F(binname.str().c_str(), binname.str().c_str(), 60, 60,120); } for(unsigned iNtrk(0); iNtrk < nNtrkBins; iNtrk++){ binname.str(""); if(iNtrk != nNtrkBins-1)binname << "den_mg_trk-" << NtrkBins[iNtrk] << "-" << NtrkBins[iNtrk+1]; else binname << "den_mg_trk-" << NtrkBins[iNtrk] << "-inf"; den_mg_trk[iNtrk] = new TH1F(binname.str().c_str(), binname.str().c_str(), 60, 60,120); binname.str(""); if(iNtrk != nNtrkBins-1)binname << "num_mg_trk-" << NtrkBins[iNtrk] << "-" << NtrkBins[iNtrk+1]; else binname << "num_mg_trk-" << NtrkBins[iNtrk] << "-inf"; num_mg_trk[iNtrk] = new TH1F(binname.str().c_str(), binname.str().c_str(), 60, 60,120); } for(unsigned iEta(0); iEta < nEtaBins; iEta++){ binname.str(""); if(iEta != nEtaBins-1)binname << "den_mg_eta-" << EtaBins[iEta] << "-" << EtaBins[iEta+1]; else binname << "den_mg_eta-" << EtaBins[iEta] << "-inf"; den_mg_eta[iEta] = new TH1F(binname.str().c_str(), binname.str().c_str(), 60, 60,120); binname.str(""); if(iEta != nEtaBins-1)binname << "num_mg_eta-" << EtaBins[iEta] << "-" << EtaBins[iEta+1]; else binname << "num_mg_eta-" << EtaBins[iEta] << "-inf"; num_mg_eta[iEta] = new TH1F(binname.str().c_str(), binname.str().c_str(), 60, 60,120); } for(unsigned iVertexBins(0); iVertexBins < nVertexBins; iVertexBins++){ binname.str(""); if(iVertexBins != nVertexBins-1)binname << "den_mg_vtx-" << VertexBins[iVertexBins] << "-" << VertexBins[iVertexBins+1]; else binname << "den_mg_vtx-" << VertexBins[iVertexBins] << "-inf"; den_mg_vtx[iVertexBins] = new TH1F(binname.str().c_str(), binname.str().c_str(), 60, 60,120); binname.str(""); if(iVertexBins != nVertexBins-1)binname << "num_mg_vtx-" << VertexBins[iVertexBins] << "-" << VertexBins[iVertexBins+1]; else binname << "num_mg_vtx-" << VertexBins[iVertexBins] << "-inf"; num_mg_vtx[iVertexBins] = new TH1F(binname.str().c_str(), binname.str().c_str(), 60, 60,120); } const unsigned nEvts = etree->GetEntries(); for(unsigned iEvt(0); iEvt < nEvts; iEvt++){ etree->GetEntry(iEvt); if(mass_denmg > 40.0){ den_mg_pt[findIndex(PtBins,et_denmg,nPtBins)]->Fill(mass_denmg); den_mg_trk[findIndex(NtrkBins,tracks,nNtrkBins)]->Fill(mass_denmg); den_mg_eta[findIndex(EtaBins,fabs(rap_denmg),nEtaBins)]->Fill(mass_denmg); den_mg_vtx[findIndex(VertexBins,nVertex, nVertexBins)]->Fill(mass_denmg); } if(mass_nummg > 40.0){ num_mg_pt[findIndex(PtBins,et_nummg,nPtBins)]->Fill(mass_nummg); num_mg_trk[findIndex(NtrkBins,tracks,nNtrkBins)]->Fill(mass_nummg); num_mg_eta[findIndex(EtaBins,fabs(rap_nummg),nEtaBins)]->Fill(mass_nummg); num_mg_vtx[findIndex(VertexBins,nVertex, nVertexBins)]->Fill(mass_nummg); } } outputfile->Write(); outputfile->Close(); }
void srcPositionStudy(Int_t binWidth, TString source, TString geometry) { int numFiles = 200; TString simLocation; TChain *chain = new TChain("anaTree"); if (geometry==TString("2011-2012")) simLocation = TString(getenv("SIM_2011_2012")); else if (geometry==TString("2012-2013")) simLocation = TString(getenv("SIM_2012_2013")); else if (geometry==TString("2012-2013_ISOBUTANE")) simLocation = TString(getenv("SIM_2012_2013_ISOBUTANE")); else { std::cout << "BAD GEOMETRY\n"; exit(0); } for (int i=0; i<numFiles; i++) { chain->AddFile(TString::Format("%s/%s/analyzed_%i.root",simLocation.Data(),source.Data(),i)); } Double_t maxEn = 1500.; Double_t minEn = 0.; Double_t fidMax = 55.; Int_t nHists = (int)(fidMax/binWidth); std::vector <TH1D*> histsE(nHists, 0); std::vector <TH1D*> histsW(nHists, 0); std::vector <Double_t> rmin(nHists,0); std::vector <Double_t> rmax(nHists,0); std::vector <Double_t> rmid(nHists,0); //final means and errors std::vector < Double_t > EastMeans(nHists,0.); std::vector < Double_t > WestMeans(nHists,0.); std::vector < Double_t > EastMeanErrors(nHists,0.); std::vector < Double_t > WestMeanErrors(nHists,0.); for (Int_t i=0; i<nHists; i++) { rmin[i] = i*binWidth; rmax[i] = (i+1)*binWidth; rmid[i] = (double)rmin[i] + (double)binWidth/2.; histsE[i] = new TH1D(TString::Format("his%iE",i), TString::Format("%s %i mm radius bins East", source.Data(),binWidth), 550, 0., 1100.); histsW[i] = new TH1D(TString::Format("his%iW",i), TString::Format("%s %i mm radius bins West", source.Data(),binWidth), 550, 0., 1100.); histsE[i]->SetLineColor(i+1); histsW[i]->SetLineColor(i+1); } Double_t primPos[4]; // Set the addresses of the information read in from the simulation file chain->SetBranchAddress("MWPCEnergy",&mwpcE); chain->SetBranchAddress("time",&Time); chain->SetBranchAddress("Edep",&edep); chain->SetBranchAddress("EdepQ",&edepQ); chain->SetBranchAddress("MWPCPos",&mwpc_pos); chain->SetBranchAddress("ScintPos",&scint_pos); chain->SetBranchAddress("primKE",&primKE); chain->SetBranchAddress("primTheta",&primTheta); chain->SetBranchAddress("primPos",&primPos); //Get total number of events in TChain UInt_t nevents = chain->GetEntries(); cout << "events = " << nevents << endl; for (Int_t i=0; i<nevents; i++) { chain->GetEvent(i); Int_t nBin = primPos[3]*1000./binWidth; if (edepQ.EdepQE>0. && primKE<maxEn && primKE>minEn && mwpcE.MWPCEnergyE>0.1 && primTheta>TMath::Pi()/2.) histsE[nBin]->Fill(edepQ.EdepQE); if (edepQ.EdepQW>0. && primKE<maxEn && primKE>minEn && mwpcE.MWPCEnergyW>0.1 && primTheta<TMath::Pi()/2.) histsW[nBin]->Fill(edepQ.EdepQW); if (i%100000==0) std::cout << "*"; } std::cout << std::endl; TCanvas *c1 = new TCanvas("c1","c1",1600,1200); c1->Divide(2,2); //TCanvas *c2 = new TCanvas("c2"); //histsE[1]->Draw("SAME"); Double_t refMeanE = 0., refMeanW = 0.; //This will hold the mean of the center pixel std::cout << nHists << endl; for (Int_t i=0; i<nHists; i++) { c1->cd(1); histsE[i]->Draw("SAME"); EastMeans[i] = histsE[i]->GetMean(); EastMeanErrors[i] = EastMeans[i]>0. ? EastMeans[i]/sqrt(histsE[i]->GetEntries()) : 0.; //cout << EastMeans[i][0] << " " << EastMeans[i][1] << endl; c1->cd(2); histsW[i]->Draw("SAME"); WestMeans[i] = histsW[i]->GetMean(); WestMeanErrors[i] = WestMeans[i]>0. ? WestMeans[i]/sqrt(histsW[i]->GetEntries()) : 0.; if (i==0) { refMeanE = EastMeans[i], refMeanW = WestMeans[i]; } } //TCanvas *c3 = new TCanvas("c3"); c1->cd(3); std::vector <Double_t> xerr(nHists,0.); TGraphErrors *gEast = new TGraphErrors(11, &rmax[0],&EastMeans[0],&xerr[0],&EastMeanErrors[0]); gEast->SetMarkerStyle(21); gEast->SetTitle(TString::Format("East %s Mean EQ vs. position",source.Data())); gEast->GetXaxis()->SetTitle("Position Bin Edge (mm)"); gEast->GetYaxis()->SetTitle("Energy (keV)"); gEast->Draw("AP"); TLine *eastLine = new TLine(gEast->GetXaxis()->GetXmin(),refMeanE,gEast->GetXaxis()->GetXmax(),refMeanE); eastLine->SetLineStyle(2); eastLine->Draw(); //TCanvas *c4 = new TCanvas("c4"); c1->cd(4); TGraphErrors *gWest = new TGraphErrors(11, &rmax[0],&WestMeans[0],&xerr[0],&WestMeanErrors[0]); gWest->SetMarkerStyle(21); gWest->SetTitle(TString::Format("West %s Mean EQ vs. position",source.Data())); gWest->GetXaxis()->SetTitle("Position Bin Edge (mm)"); gWest->GetYaxis()->SetTitle("Energy (keV)"); gWest->Draw("AP"); TLine *westLine = new TLine(gWest->GetXaxis()->GetXmin(),refMeanW,gWest->GetXaxis()->GetXmax(),refMeanW); westLine->SetLineStyle(2); westLine->Draw(); }
void gep_trigger_analysis_elastic( const char *rootfilename, const char *logicfilename_ecal, const char *logicfilename_hcal, const char *thresholdfilename_ecal, const char *thresholdfilename_hcal, const char *outputfilename, double thetacaldeg=29.0, int pheflag=0, const char *assocfilename="ECAL_HCAL_correlations_nophe.txt", int Q2cut=0 ){ double nominal_threshold_HCAL = 0.5; double nominal_threshold_ECAL = 0.9; double thetacal = thetacaldeg*PI/180.0; TFile *fout = new TFile(outputfilename,"RECREATE"); TChain *C = new TChain("T"); C->Add(rootfilename); gep_tree_elastic *T = new gep_tree_elastic( C ); G4SBSRunData *rd; long ngen = 0; int nfiles = 0; TObjArray *FileList = C->GetListOfFiles(); TIter next(FileList); TChainElement *chEl = 0; set<TString> bad_file_list; while( (chEl=(TChainElement*)next() )){ TFile newfile(chEl->GetTitle()); newfile.GetObject("run_data",rd); if( rd ){ ngen += rd->fNtries; nfiles++; } else { bad_file_list.insert( chEl->GetTitle()); } } cout << "number of generated events = " << ngen << endl; set<int> list_of_nodes_ecal; map<int, set<int> > cells_logic_sums_ecal; //mapping between node numbers and cell numbers map<int, double> logic_mean_ecal; //mean peak positions by node number map<int, double> logic_sigma_ecal; //peak width by node number map<int, double> threshold_ecal; //threshold by node number map<std::pair<int,int>, int > cell_rowcol_ecal; //cell numbers mapped by unique row and column pairs map<int,set<int> > nodes_cells_ecal; //mapping of nodes by cell number: map<int,int> rows_cells_ecal; map<int,int> cols_cells_ecal; map<int,double> xcells_ecal; map<int,double> ycells_ecal; //keep track of min and max x by row number: double ycellmin,ycellmax; map<int,double> ycell_rows; map<int,double> cellsize_rows; map<int,double> xcellmin_rows; map<int,double> xcellmax_rows; int minrow=1000,maxrow=-1; set<int> rows_ecal; map<int,set<int> > columns_rows_ecal; map<int,double> elastic_peak_new_ecal; map<int,double> sigma_new_ecal; map<int,double> threshold_new_ecal; ifstream logicfile_ecal(logicfilename_ecal); //ifstream thresholdfile(thresholdfilename); TString currentline; int current_node = 1; bool first_cell = true; while( currentline.ReadLine( logicfile_ecal ) ){ if( !currentline.BeginsWith( "#" ) ){ TObjArray *tokens = currentline.Tokenize(" "); int ntokens = tokens->GetEntries(); if( ntokens >= 11 ){ cout << currentline.Data() << ", ntokens = " << ntokens << endl; TString snode = ( (TObjString*) (*tokens)[0] )->GetString(); int nodenumber = snode.Atoi(); TString scell = ( (TObjString*) (*tokens)[1] )->GetString(); int cellnumber = scell.Atoi(); TString speakpos = ( (TObjString*) (*tokens)[8] )->GetString(); double mean = speakpos.Atof(); TString ssigma = ( (TObjString*) (*tokens)[9] )->GetString(); double sigma = ssigma.Atof(); TString sthreshold = ( (TObjString*) (*tokens)[10] )->GetString(); double threshold = sthreshold.Atof(); TString srow = ( (TObjString*) (*tokens)[2] )->GetString(); TString scol = ( (TObjString*) (*tokens)[3] )->GetString(); std::pair<int,int> rowcoltemp( srow.Atoi(), scol.Atoi() ); cell_rowcol_ecal[rowcoltemp] = cellnumber; list_of_nodes_ecal.insert( nodenumber ); cells_logic_sums_ecal[nodenumber].insert( cellnumber ); logic_mean_ecal[nodenumber] = mean; logic_sigma_ecal[nodenumber] = sigma; threshold_ecal[nodenumber] = threshold; nodes_cells_ecal[ cellnumber ].insert(nodenumber); TString sxcell = ( (TObjString*) (*tokens)[4] )->GetString(); TString sycell = ( (TObjString*) (*tokens)[5] )->GetString(); cols_cells_ecal[cellnumber] = scol.Atoi(); rows_cells_ecal[cellnumber] = srow.Atoi(); xcells_ecal[cellnumber] = sxcell.Atof()/1000.0; //convert to m ycells_ecal[cellnumber] = sycell.Atof()/1000.0; //convert to m if( ycell_rows.empty() || sycell.Atof()/1000.0 < ycellmin ) ycellmin = sycell.Atof()/1000.0; if( ycell_rows.empty() || sycell.Atof()/1000.0 > ycellmax ) ycellmax = sycell.Atof()/1000.0; ycell_rows[srow.Atoi()] = sycell.Atof()/1000.0; TString ssize = ( (TObjString*) (*tokens)[6] )->GetString(); double size = ssize.Atof(); cellsize_rows[srow.Atoi()] = size/1000.0; if( xcellmin_rows.empty() || sxcell.Atof()/1000.0 < xcellmin_rows[srow.Atoi()] ){ xcellmin_rows[srow.Atoi()] = sxcell.Atof()/1000.0; } if( xcellmax_rows.empty() || sxcell.Atof()/1000.0 > xcellmax_rows[srow.Atoi()] ){ xcellmax_rows[srow.Atoi()] = sxcell.Atof()/1000.0; } } } } set<int> list_of_nodes_hcal; map<int, set<int> > cells_logic_sums_hcal; //mapping between node numbers and cell numbers map<int, double> logic_mean_hcal; //mean peak positions by node number map<int, double> logic_sigma_hcal; //peak width by node number map<int, double> threshold_hcal; //threshold by node number map<std::pair<int,int>, int > cell_rowcol_hcal; //cell numbers mapped by unique row and column pairs map<int,set<int> > nodes_cells_hcal; //mapping of nodes by cell number: ifstream logicfile_hcal(logicfilename_hcal); current_node = 1; // bool first_cell = true; while( currentline.ReadLine(logicfile_hcal) ){ if( !currentline.BeginsWith("#") ){ TObjArray *tokens = currentline.Tokenize(" "); int ntokens = tokens->GetEntries(); if( ntokens >= 11 ){ cout << currentline.Data() << ", ntokens = " << ntokens << endl; TString snode = ( (TObjString*) (*tokens)[0] )->GetString(); int nodenumber = snode.Atoi(); TString scell = ( (TObjString*) (*tokens)[1] )->GetString(); int cellnumber = scell.Atoi(); TString speakpos = ( (TObjString*) (*tokens)[8] )->GetString(); double mean = speakpos.Atof(); TString ssigma = ( (TObjString*) (*tokens)[9] )->GetString(); double sigma = ssigma.Atof(); TString sthreshold = ( (TObjString*) (*tokens)[10] )->GetString(); double threshold = sthreshold.Atof(); TString srow = ( (TObjString*) (*tokens)[2] )->GetString(); TString scol = ( (TObjString*) (*tokens)[3] )->GetString(); std::pair<int,int> rowcoltemp( srow.Atoi(), scol.Atoi() ); cell_rowcol_hcal[rowcoltemp] = cellnumber; list_of_nodes_hcal.insert( nodenumber ); cells_logic_sums_hcal[nodenumber].insert( cellnumber ); logic_mean_hcal[nodenumber] = mean; logic_sigma_hcal[nodenumber] = sigma; threshold_hcal[nodenumber] = threshold; nodes_cells_hcal[ cellnumber ].insert(nodenumber); } } } TH1D::SetDefaultSumw2(); //double PI = TMath::Pi(); //Photoelectron statistics: double phe_per_GeV_ECAL = 1000.0/1.33; //~ 750 pe/GeV double phe_per_GeV_HCAL = 1000.0/0.30; //~ 3,333 pe/GeV (but sampling fraction is small) //read in alternate threshold: ifstream thresholdfile_ecal(thresholdfilename_ecal); if( thresholdfile_ecal ){ int node; double mean,sigma; while( thresholdfile_ecal >> node >> mean >> sigma ){ if( list_of_nodes_ecal.find( node ) != list_of_nodes_ecal.end() ){ logic_mean_ecal[ node ] = mean; logic_sigma_ecal[ node ] = sigma; } } } //read in alternate threshold: ifstream thresholdfile_hcal(thresholdfilename_hcal); if( thresholdfile_hcal ){ int node; double mean,sigma; while( thresholdfile_hcal >> node >> mean >> sigma ){ if( list_of_nodes_hcal.find( node ) != list_of_nodes_hcal.end() ){ logic_mean_hcal[ node ] = mean; logic_sigma_hcal[ node ] = sigma; } } } ifstream assocfile( assocfilename ); bool use_ECAL_HCAL_associations=false; map<int, set<int> > ECAL_nodes_HCAL; if( assocfile ){ while( !assocfile.eof() ){ int hcalnode, N; assocfile >> hcalnode >> N; for( int i=0; i<N; i++ ){ int ecalnode; assocfile >> ecalnode; ECAL_nodes_HCAL[hcalnode].insert(ecalnode); } } } fout->cd(); // TH1D *hrate_vs_threshold_ECAL = new TH1D("hrate_vs_threshold_ECAL","",30,0.0,1.5); // //TH1D *hnum_logic_sums_fired_vs_threshold = new TH1D("hnum_logic_sums_fired_vs_threshold // TH1D *hrate_vs_threshold_HCAL = new TH1D("hrate_vs_threshold_HCAL","",40,0.0,2.0); //TH2D *htrue_coincidence_rate_vs_threshold_ECAL_HCAL = new TH2D("htrue_coincidence_rate_vs_threshold_ECAL_HCAL","",40,0,2.0,30,0,1.5); TH2D *hnphesum_vs_node_ECAL_all = new TH2D("hnphesum_vs_node_ECAL_all","",list_of_nodes_ecal.size(),0.5,list_of_nodes_ecal.size()+0.5,100,0.0,5000.0); TH2D *hnphesum_vs_node_HCAL_all = new TH2D("hnphesum_vs_node_HCAL_all","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); //TH2D *hnphesum_vs_node_ECAL_FTcut = new TH2D("hnphesum_vs_node_ECAL_FTcut","",list_of_nodes_ecal.size(),0.5,list_of_nodes_ecal.size()+0.5,100,0.0,5000.0); TH2D *hnphesum_vs_node_HCAL_FTcut = new TH2D("hnphesum_vs_node_HCAL_FTcut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCAL_FPP1cut = new TH2D("hnphesum_vs_node_HCAL_FPP1cut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCAL_FPP2cut = new TH2D("hnphesum_vs_node_HCAL_FPP2cut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCAL_FPPbothcut = new TH2D("hnphesum_vs_node_HCAL_FPPbothcut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCAL_FPPeithercut = new TH2D("hnphesum_vs_node_HCAL_FPPeithercut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCALmax_all = new TH2D("hnphesum_vs_node_HCALmax_all","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCALmax_FTcut = new TH2D("hnphesum_vs_node_HCALmax_FTcut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCALmax_FPP1cut = new TH2D("hnphesum_vs_node_HCALmax_FPP1cut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCALmax_FPP2cut = new TH2D("hnphesum_vs_node_HCALmax_FPP2cut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCALmax_FPPbothcut = new TH2D("hnphesum_vs_node_HCALmax_FPPbothcut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hnphesum_vs_node_HCALmax_FPPeithercut = new TH2D("hnphesum_vs_node_HCALmax_FPPeithercut","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,100,0.0,3500.0); TH2D *hmaxnode_ECAL_vs_HCAL = new TH2D("hmaxnode_ECAL_vs_HCAL","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,list_of_nodes_ecal.size(),0.5,list_of_nodes_ecal.size()+0.5); TH2D *hallnodes_ECAL_vs_HCAL = new TH2D("hallnodes_ECAL_vs_HCAL","",list_of_nodes_hcal.size(),0.5,list_of_nodes_hcal.size()+0.5,list_of_nodes_ecal.size(),0.5,list_of_nodes_ecal.size()+0.5); TH1D *hshouldhit_vs_threshold_ECAL = new TH1D("hshouldhit_vs_threshold_ECAL","",30,0.025,1.525); TH1D *hefficiency_vs_threshold_ECAL = new TH1D("hefficiency_vs_threshold_ECAL","",30,0.025,1.525); TH1D *hshouldhit_vs_threshold_ECAL_FTcut = new TH1D("hshouldhit_vs_threshold_ECAL_FTcut","",30,0.025,1.525); TH1D *hefficiency_vs_threshold_ECAL_FTcut = new TH1D("hefficiency_vs_threshold_ECAL_FTcut","",30,0.025,1.525); TH1D *hefficiency_vs_threshold_HCAL_FTcut = new TH1D("hefficiency_vs_threshold_HCAL_FTcut","",30,0.025,1.525); TH1D *hefficiency_vs_threshold_HCAL_FPP1cut = new TH1D("hefficiency_vs_threshold_HCAL_FPP1cut","",30,0.025,1.525); TH1D *hefficiency_vs_threshold_HCAL_FPP2cut = new TH1D("hefficiency_vs_threshold_HCAL_FPP2cut","",30,0.025,1.525); TH2D *hefficiency_vs_threshold_ECAL_HCAL_coincidence_FTcut = new TH2D("hefficiency_vs_threshold_ECAL_HCAL_coincidence_FTcut","",30,0.025,1.525,30,0.025,1.525); TH2D *hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FTcut = new TH2D("hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FTcut","",30,0.025,1.525,30,0.025,1.525); TH2D *hefficiency_vs_threshold_ECAL_HCAL_coincidence_FPP1cut = new TH2D("hefficiency_vs_threshold_ECAL_HCAL_coincidence_FPP1cut","",30,0.025,1.525,30,0.025,1.525); TH2D *hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FPP1cut = new TH2D("hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FPP1cut","",30,0.025,1.525,30,0.025,1.525); TH2D *hefficiency_vs_threshold_ECAL_HCAL_coincidence_FPP2cut = new TH2D("hefficiency_vs_threshold_ECAL_HCAL_coincidence_FPP2cut","",30,0.025,1.525,30,0.025,1.525); TH2D *hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FPP2cut = new TH2D("hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FPP2cut","",30,0.025,1.525,30,0.025,1.525); TH1D *hshouldhit_HCAL_FTcut = new TH1D("hshouldhit_HCAL_FTcut","",30,0.025,1.525); TH1D *hshouldhit_HCAL_FPP1cut = new TH1D("hshouldhit_HCAL_FPP1cut","",30,0.025,1.525); TH1D *hshouldhit_HCAL_FPP2cut = new TH1D("hshouldhit_HCAL_FPP2cut","",30,0.025,1.525); TH2D *hnphe_vs_sum_edep_ECAL = new TH2D("hnphe_vs_sum_edep_ECAL","",125,0.0,5.0,125,0.0,5000.0 ); TH2D *hnphe_vs_sum_edep_HCAL = new TH2D("hnphe_vs_sum_edep_HCAL","",125,0.0,0.75,125,0.0,2500.0 ); TH1D *hthetaFPP1 = new TH1D("hthetaFPP1","",120,0.0,12.0); TH1D *hthetaFPP2 = new TH1D("hthetaFPP2","",120,0.0,12.0); TH1D *hthetaFPP1_cointrig = new TH1D("hthetaFPP1_cointrig","",120,0.0,12.0); TH1D *hthetaFPP2_cointrig = new TH1D("hthetaFPP2_cointrig","",120,0.0,12.0); TH1D *hshouldhit_vs_Q2_ECAL_FTcut = new TH1D("hshouldhit_vs_Q2_ECAL_FTcut","",100,8.0,16.0); TH1D *hefficiency_vs_Q2_ECAL_FTcut = new TH1D("hefficiency_vs_Q2_ECAL_FTcut","",100,8.0,16.0); double Ibeam = 75.0e-6; //Amps double Ltarget = 40.0; //cm double e = 1.602e-19; //electron charge; double rho_target = 0.072; //g/cm^3 double N_A = 6.022e23; //atoms/mol: double Mmol_H = 1.008; //g/mol double Lumi = rho_target * Ltarget * N_A / Mmol_H * Ibeam/e; //~ 8e38; TRandom3 num(0); cout << "Entering event loop " << endl; long nevent=0; for( nevent=0; nevent<C->GetEntries(); ++nevent ){ T->GetEntry(nevent); double weight; //cross section is given in mb: 1 mb = 1e-3 * 1e-24 = 1e-27 cm^2 // if (pythia6flag != 0 ){ // weight = Lumi * T->primaries_Sigma * 1.0e-27/ double(ngen); //luminosity times cross section / number of events generated. // } else { weight = T->ev_rate / double(nfiles); if( Q2cut == 0 || (T->ev_Q2 >= 10.5 && T->ev_Q2 <= 14.0) ){ bool FTtrack = false; int itrack_FT=-1; for( int itrack=0; itrack<T->Harm_FT_Track_ntracks; itrack++ ){ if( (*(T->Harm_FT_Track_MID))[itrack] == 0 && (*(T->Harm_FT_Track_PID))[itrack] == 2212 ){ //primary elastically scattered proton track in FT: FTtrack = true; itrack_FT = itrack; } } TVector3 nhat_FT, nhat_FPP1, nhat_FPP2; if( FTtrack ){ nhat_FT.SetXYZ( (*(T->Harm_FT_Track_Xp))[itrack_FT], (*(T->Harm_FT_Track_Yp))[itrack_FT], 1.0 ); nhat_FT = nhat_FT.Unit(); } double thetaFPP1, thetaFPP2, pFPP1, pFPP2; bool FPP1track = false, FPP2track = false; // if( FTtrack ) if( T->Harm_FPP1_Track_ntracks > 0 && FTtrack ){ for( int itrack=0; itrack<T->Harm_FPP1_Track_ntracks; itrack++ ){ if( (*(T->Harm_FPP1_Track_MID))[itrack] == 0 ){ nhat_FPP1.SetXYZ( (*(T->Harm_FPP1_Track_Xp))[itrack], (*(T->Harm_FPP1_Track_Yp))[itrack], 1.0 ); nhat_FPP1 = nhat_FPP1.Unit(); thetaFPP1 = acos( nhat_FPP1.Dot( nhat_FT ) ); pFPP1 = (*(T->Harm_FPP1_Track_P))[itrack]; FPP1track = thetaFPP1 < 12.0*PI/180.0 && pFPP1 >= 0.5*T->ev_np; if( FPP1track ) hthetaFPP1->Fill(thetaFPP1*180.0/PI,weight); } } } if( T->Harm_FPP2_Track_ntracks > 0 && FTtrack && FPP1track){ for( int itrack=0; itrack<T->Harm_FPP2_Track_ntracks; itrack++ ){ if( (*(T->Harm_FPP2_Track_MID))[itrack] == 0 ){ nhat_FPP2.SetXYZ( (*(T->Harm_FPP2_Track_Xp))[itrack], (*(T->Harm_FPP2_Track_Yp))[itrack], 1.0 ); nhat_FPP2 = nhat_FPP2.Unit(); thetaFPP2 = acos( nhat_FPP2.Dot( nhat_FPP1 ) ); pFPP2 = (*(T->Harm_FPP2_Track_P))[itrack]; //FPP2track = thetaFPP2 < 24.0*PI/180.0 && pFPP2/T->ev_np > 0.5; FPP2track = thetaFPP2 < 12.0*PI/180.0 && pFPP2/T->ev_np > 0.5; if( FPP2track ) hthetaFPP2->Fill(thetaFPP2*180.0/PI,weight); } } } double nu = T->ev_Q2 / 2.0 / 0.938272; double pp_elastic = sqrt(pow(nu,2)+2.0*.938272*nu); //} double R = T->gen_dbb; double thetacal = T->gen_thbb; //ECAL is on beam left: TVector3 nhat_e( sin( T->ev_th )*cos( T->ev_ph ), sin(T->ev_th)*sin(T->ev_ph), cos(T->ev_th) ); TVector3 vertex( T->ev_vx, T->ev_vy, T->ev_vz ); TVector3 ecal_z( sin(thetacal), 0, cos(thetacal) ); TVector3 ecal_y(0,1,0); TVector3 ecal_x = (ecal_y.Cross(ecal_z)).Unit(); TVector3 Rcalo = R * ecal_z; //ecal_z dot (vertex + s * nhat_e - Rcalo ) = 0; double s = (Rcalo - vertex).Dot( ecal_z )/ ( nhat_e.Dot( ecal_z ) ); TVector3 pos_calo = vertex + s * nhat_e; double xcalo = (pos_calo - Rcalo).Dot( ecal_x ); double ycalo = (pos_calo - Rcalo).Dot( ecal_y ); // if( (nevent+1) % 1000 == 0 ){ cout << "Event number " << nevent+1 << ", event weight = " << weight << endl; } map<int,double> node_sums; //initialize all node sums to zero: for( set<int>::iterator inode = list_of_nodes_ecal.begin(); inode != list_of_nodes_ecal.end(); ++inode ){ node_sums[ *inode ] = 0.0; } bool should_hit_ECAL = false; if( ycalo >= ycellmin && ycalo <= ycellmax ){ //make an initial guess at which row: (row runs from 1 to N): int closest_row = int( (ycalo - ycellmin)/4.0 ) + 1; map<int,double>::iterator rowguess = ycell_rows.find( closest_row ); while( rowguess != ycell_rows.end() && ycalo > ycell_rows[rowguess->first] + 0.5*cellsize_rows[rowguess->first] ){ ++rowguess; } while( rowguess != ycell_rows.end() && ycalo < ycell_rows[rowguess->first] - 0.5*cellsize_rows[rowguess->first] ){ --rowguess; } if( rowguess != ycell_rows.end() ){ closest_row = rowguess->first; if( xcalo >= xcellmin_rows[closest_row] + 0.5*cellsize_rows[closest_row] && xcalo <= xcellmax_rows[closest_row] - 0.5*cellsize_rows[closest_row] && ycalo >= ycellmin + 0.5*cellsize_rows[closest_row] && ycalo <= ycellmax - 0.5*cellsize_rows[closest_row] ){ should_hit_ECAL = true; } } } int nphe = 0; if( pheflag == 0 ){ for( int ihit = 0; ihit<T->Earm_ECalTF1_hit_nhits; ihit++ ){ int rowhit = ( *(T->Earm_ECalTF1_hit_row))[ihit]+1; int colhit = ( *(T->Earm_ECalTF1_hit_col))[ihit]+1; std::pair<int,int> rowcolhit( rowhit,colhit ); int cellhit = cell_rowcol_ecal[rowcolhit]; //int trigger_group = nodes_cells_ecal[cellhit]; double edep = (*(T->Earm_ECalTF1_hit_sumedep))[ihit]; double mean = 752.2*edep; double sigma = 52.0*sqrt(edep) + 20.76*edep; nphe = TMath::Max(0,TMath::Nint(num.Gaus(mean,sigma))); for( set<int>::iterator inode = nodes_cells_ecal[cellhit].begin(); inode != nodes_cells_ecal[cellhit].end(); ++inode ){ node_sums[ *inode ] += double(nphe); } } } else { for( int ihit = 0; ihit<T->Earm_ECAL_hit_nhits; ihit++){ int rowhit = ( *(T->Earm_ECAL_hit_row))[ihit]+1; int colhit = ( *(T->Earm_ECAL_hit_col))[ihit]+1; std::pair<int,int> rowcolhit( rowhit,colhit ); int cellhit = cell_rowcol_ecal[rowcolhit]; //int trigger_group = nodes_cells_ecal[cellhit]; // double edep = (*(T->Earm_ECalTF1_hit_sumedep))[ihit]; int nphe = (*(T->Earm_ECAL_hit_NumPhotoelectrons))[ihit]; for( set<int>::iterator inode = nodes_cells_ecal[cellhit].begin(); inode != nodes_cells_ecal[cellhit].end(); ++inode ){ node_sums[ *inode ] += double(nphe); } for( int jhit=0; jhit<T->Earm_ECalTF1_hit_nhits; jhit++ ){ if( (*(T->Earm_ECalTF1_hit_row))[jhit]+1 == rowhit && (*(T->Earm_ECalTF1_hit_col))[jhit]+1 == colhit && fabs( (*(T->Earm_ECAL_hit_Time_avg))[ihit]-(*(T->Earm_ECalTF1_hit_tavg))[jhit]-2.5)<=10.0 ){ hnphe_vs_sum_edep_ECAL->Fill( (*(T->Earm_ECalTF1_hit_sumedep))[jhit], nphe ); } } } //node_sums[ trigger_group ] += double(nphe); } vector<int> trigger_nodes_fired(hefficiency_vs_threshold_ECAL->GetNbinsX()); for( int ithr=0; ithr<hefficiency_vs_threshold_ECAL->GetNbinsX(); ithr++ ){ trigger_nodes_fired[ithr] = 0; } int maxnode_ECAL=-1; int maxnode_HCAL=-1; double maxsum_ECAL = 0.0; double maxsum_HCAL = 0.0; bool ECALtrig_nominal = false; int nominal_threshold_bin_HCAL = hefficiency_vs_threshold_HCAL_FTcut->FindBin(nominal_threshold_HCAL); int nominal_threshold_bin_ECAL = hefficiency_vs_threshold_ECAL->FindBin(nominal_threshold_ECAL); for( set<int>::iterator inode = list_of_nodes_ecal.begin(); inode != list_of_nodes_ecal.end(); ++inode ){ for( int bin=1; bin<=hefficiency_vs_threshold_ECAL->GetNbinsX(); bin++ ){ if( node_sums[*inode]/logic_mean_ecal[*inode] > hefficiency_vs_threshold_ECAL->GetBinCenter(bin) ){ //cout << "node above threshold, nphe, peak position = " << node_sums[*inode] << ", " << logic_mean_ecal[*inode] << endl; trigger_nodes_fired[bin-1]++; if( bin == nominal_threshold_bin_ECAL ) ECALtrig_nominal = true; } } if( node_sums[*inode] > maxsum_ECAL ) { maxsum_ECAL = node_sums[*inode]; maxnode_ECAL = *inode; } if( node_sums[*inode] > 0.0 ) hnphesum_vs_node_ECAL_all->Fill( *inode, node_sums[*inode], weight ); } if( should_hit_ECAL ){ for( int ithr=0; ithr<hefficiency_vs_threshold_ECAL->GetNbinsX(); ithr++ ){ hshouldhit_vs_threshold_ECAL->Fill( hefficiency_vs_threshold_ECAL->GetBinCenter(ithr+1), weight ); if( trigger_nodes_fired[ithr] > 0 ){ hefficiency_vs_threshold_ECAL->Fill( hefficiency_vs_threshold_ECAL->GetBinCenter(ithr+1), weight ); } if( FTtrack ){ hshouldhit_vs_threshold_ECAL_FTcut->Fill( hefficiency_vs_threshold_ECAL->GetBinCenter(ithr+1), weight ); if( trigger_nodes_fired[ithr] > 0 ){ hefficiency_vs_threshold_ECAL_FTcut->Fill( hefficiency_vs_threshold_ECAL->GetBinCenter(ithr+1), weight ); } } } } if( FTtrack ){ hshouldhit_vs_Q2_ECAL_FTcut->Fill( T->ev_Q2, weight ); if( ECALtrig_nominal ){ hefficiency_vs_Q2_ECAL_FTcut->Fill( T->ev_Q2, weight ); } } map<int,double> node_sums_hcal; for( set<int>::iterator inode = list_of_nodes_hcal.begin(); inode != list_of_nodes_hcal.end(); ++inode ){ node_sums_hcal[*inode] = 0.0; } //int nphe = 0; if( pheflag == 0 ){ for( int ihit=0; ihit<T->Harm_HCalScint_hit_nhits; ihit++ ){ int rowhit = (*(T->Harm_HCalScint_hit_row))[ihit]+1; int colhit = (*(T->Harm_HCalScint_hit_col))[ihit]+1; std::pair<int,int> rowcolhit(rowhit,colhit); int cellhit = cell_rowcol_hcal[rowcolhit]; //int trigger_group = nodes_cells_hcal[cellhit]; double edep = (*(T->Harm_HCalScint_hit_sumedep))[ihit]; //nphe = num.Poisson( phe_per_GeV_HCAL * edep ); double mean = 2981.0*edep; double sigma = 69.54*sqrt(edep) + 155.3*edep; nphe = TMath::Max(0,TMath::Nint(num.Gaus(mean,sigma))); //cout << "HCAL hit " << ihit+1 << " node, edep, nphe = " << trigger_group << ", " << edep << ", " << nphe << endl; //node_sums_hcal[trigger_group] += double(nphe); for( set<int>::iterator inode = nodes_cells_hcal[cellhit].begin(); inode != nodes_cells_hcal[cellhit].end(); ++inode ){ node_sums_hcal[*inode] += double(nphe); } } } else { for( int jhit=0; jhit<T->Harm_HCal_hit_nhits; jhit++ ){ int rowhit = (*(T->Harm_HCal_hit_row))[jhit]+1; int colhit = (*(T->Harm_HCal_hit_col))[jhit]+1; std::pair<int,int> rowcolhit(rowhit,colhit); int cellhit = cell_rowcol_hcal[rowcolhit]; nphe = (*(T->Harm_HCal_hit_NumPhotoelectrons))[jhit]; for( set<int>::iterator inode = nodes_cells_hcal[cellhit].begin(); inode != nodes_cells_hcal[cellhit].end(); ++inode ){ node_sums_hcal[*inode] += double(nphe); } for( int khit=0; khit<T->Harm_HCalScint_hit_nhits; khit++ ){ if( (*(T->Harm_HCalScint_hit_row))[khit]+1 == rowhit && (*(T->Harm_HCalScint_hit_col))[khit]+1 == colhit && fabs( (*(T->Harm_HCal_hit_Time_avg))[jhit]-(*(T->Harm_HCalScint_hit_tavg))[khit] - 8.6 )<=15.0 ){ hnphe_vs_sum_edep_HCAL->Fill( (*(T->Harm_HCalScint_hit_sumedep))[khit], nphe ); } } } } vector<int> trigger_nodes_fired_hcal(hefficiency_vs_threshold_HCAL_FTcut->GetNbinsX()); for( int ithr=0; ithr<hefficiency_vs_threshold_HCAL_FTcut->GetNbinsX(); ithr++ ){ trigger_nodes_fired_hcal[ithr] = 0; } vector<int> coin_trigger_fired( hefficiency_vs_threshold_HCAL_FTcut->GetNbinsX()*hefficiency_vs_threshold_ECAL->GetNbinsX() ); for( int ithr=0; ithr<coin_trigger_fired.size(); ithr++ ){ coin_trigger_fired[ithr] = 0; } bool cointrig_nominal_threshold = false; for( set<int>::iterator inode = list_of_nodes_hcal.begin(); inode != list_of_nodes_hcal.end(); ++inode ){ for( int bin=1; bin<=hefficiency_vs_threshold_HCAL_FTcut->GetNbinsX(); bin++ ){ if( node_sums_hcal[*inode]/logic_mean_hcal[*inode] > hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(bin) ){ //this HCAL sum fired: trigger_nodes_fired_hcal[bin-1]++; for( set<int>::iterator enode = list_of_nodes_ecal.begin(); enode != list_of_nodes_ecal.end(); ++enode ){ if( ECAL_nodes_HCAL[*inode].find(*enode) != ECAL_nodes_HCAL[*inode].end() ){ //Check associated ECAL trigger sums: for( int ebin=1; ebin<=hefficiency_vs_threshold_ECAL->GetNbinsX(); ebin++ ){ //check ECAL sums: if( node_sums[ *enode ]/logic_mean_ecal[*enode] > hefficiency_vs_threshold_ECAL->GetBinCenter(ebin) ){ //this ECAL sum fired: coin_trigger_fired[ (ebin-1) + (bin-1)*hefficiency_vs_threshold_ECAL->GetNbinsX() ]++; if( ebin == nominal_threshold_bin_ECAL && bin == nominal_threshold_bin_HCAL ){ cointrig_nominal_threshold = true; } } } } } } } if( node_sums_hcal[*inode] > maxsum_HCAL ) { maxsum_HCAL = node_sums_hcal[*inode]; maxnode_HCAL = *inode; } hnphesum_vs_node_HCAL_all->Fill( *inode, node_sums_hcal[*inode], weight ); if( FTtrack ){ hnphesum_vs_node_HCAL_FTcut->Fill( *inode, node_sums_hcal[*inode], weight ); if( FPP1track ) hnphesum_vs_node_HCAL_FPP1cut->Fill( *inode, node_sums_hcal[*inode], weight ); if( FPP2track ) hnphesum_vs_node_HCAL_FPP2cut->Fill( *inode, node_sums_hcal[*inode], weight ); if( FPP1track && FPP2track ) hnphesum_vs_node_HCAL_FPPbothcut->Fill( *inode, node_sums_hcal[*inode], weight ); if( FPP1track || FPP2track ) hnphesum_vs_node_HCAL_FPPeithercut->Fill( *inode, node_sums_hcal[*inode], weight ); } } if( cointrig_nominal_threshold ){ if( FPP1track ) hthetaFPP1_cointrig->Fill(thetaFPP1*180.0/PI,weight); if( FPP2track ) hthetaFPP2_cointrig->Fill(thetaFPP2*180.0/PI,weight); } for( int bin=1; bin<=hefficiency_vs_threshold_HCAL_FTcut->GetNbinsX(); bin++ ){ if( FTtrack ) hshouldhit_HCAL_FTcut->Fill( hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(bin), weight ); if( FTtrack && FPP1track ) hshouldhit_HCAL_FPP1cut->Fill( hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(bin), weight ); if( FTtrack && FPP2track ) hshouldhit_HCAL_FPP2cut->Fill( hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(bin), weight ); if( trigger_nodes_fired_hcal[bin-1] > 0 ){ if( FTtrack ){ hefficiency_vs_threshold_HCAL_FTcut->Fill( hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(bin), weight ); if( FPP1track ) hefficiency_vs_threshold_HCAL_FPP1cut->Fill( hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(bin), weight ); if( FPP2track ) hefficiency_vs_threshold_HCAL_FPP2cut->Fill( hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(bin), weight ); } } } for( int ithr=0; ithr<coin_trigger_fired.size(); ithr++ ){ int bin_e = ithr%(hefficiency_vs_threshold_ECAL->GetNbinsX())+1; int bin_h = ithr/(hefficiency_vs_threshold_HCAL_FTcut->GetNbinsX())+1; double thr_e = hefficiency_vs_threshold_ECAL_HCAL_coincidence_FTcut->GetYaxis()->GetBinCenter(bin_e); double thr_h = hefficiency_vs_threshold_ECAL_HCAL_coincidence_FTcut->GetXaxis()->GetBinCenter(bin_h); if( FTtrack ) hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FTcut->Fill( thr_h, thr_e, weight ); if( FTtrack && FPP1track ) hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FPP1cut->Fill( thr_h, thr_e, weight ); if( FTtrack && FPP2track ) hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FPP2cut->Fill( thr_h, thr_e, weight ); if( coin_trigger_fired[ithr] > 0 ){ if( FTtrack ) hefficiency_vs_threshold_ECAL_HCAL_coincidence_FTcut->Fill( thr_h, thr_e, weight ); if( FTtrack && FPP1track ) hefficiency_vs_threshold_ECAL_HCAL_coincidence_FPP1cut->Fill( thr_h, thr_e, weight ); if( FTtrack && FPP2track ) hefficiency_vs_threshold_ECAL_HCAL_coincidence_FPP2cut->Fill( thr_h, thr_e, weight ); } } hnphesum_vs_node_HCALmax_all->Fill( maxnode_HCAL, node_sums_hcal[maxnode_HCAL], weight ); if( FTtrack ){ hnphesum_vs_node_HCALmax_FTcut->Fill( maxnode_HCAL, node_sums_hcal[maxnode_HCAL], weight ); if( FPP1track ) hnphesum_vs_node_HCALmax_FPP1cut->Fill( maxnode_HCAL, node_sums_hcal[maxnode_HCAL], weight ); if( FPP2track ) hnphesum_vs_node_HCALmax_FPP2cut->Fill( maxnode_HCAL, node_sums_hcal[maxnode_HCAL], weight ); if( FPP1track && FPP2track ) hnphesum_vs_node_HCALmax_FPPbothcut->Fill( maxnode_HCAL, node_sums_hcal[maxnode_HCAL], weight ); if( FPP1track || FPP2track ) hnphesum_vs_node_HCALmax_FPPeithercut->Fill( maxnode_HCAL, node_sums_hcal[maxnode_HCAL], weight ); } // for( int ithr=0; ithr<hefficiency_vs_threshold_HCAL_FTcut->GetNbinsX(); ithr++ ){ // if( trigger_nodes_fired_hcal[ithr] > 0 ) hefficiency_vs_threshold_HCAL_FTcut->Fill( hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(ithr+1),weight ); // for( int jthr=0; jthr<hefficiency_vs_threshold_ECAL->GetNbinsX(); jthr++ ){ // if( trigger_nodes_fired[jthr] > 0 && trigger_nodes_fired_hcal[ithr] > 0 ){ // //htrue_coincidence_rate_vs_threshold_ECAL_HCAL->Fill( hefficiency_vs_threshold_HCAL_FTcut->GetBinCenter(ithr+1),hefficiency_vs_threshold_ECAL->GetBinCenter(jthr+1),weight ); // } // } // } // for( set<int>::iterator inode = list_of_nodes_ecal.begin(); inode != list_of_nodes_ecal.end(); ++inode ){ // for( set<int>::iterator jnode = list_of_nodes_hcal.begin(); jnode != list_of_nodes_hcal.end(); ++jnode ){ // //Fill the correlation histogram for all true coincidence events for which ECAL and HCAL node are both above threshold: // if( node_sums[*inode] >= nominal_threshold_ECAL*logic_mean_ecal[*inode] && node_sums_hcal[*jnode] >= nominal_threshold_HCAL*logic_mean_hcal[*jnode] ){ // hallnodes_ECAL_vs_HCAL->Fill( *jnode, *inode, weight ); // } // } // } //if( maxsum_ECAL >= nominal_threshold_ECAL*logic_mean_ecal[maxnode_ECAL] && maxsum_HCAL >= nominal_threshold_HCAL*logic_mean_hcal[maxnode_HCAL] ){ if( FTtrack && FPP2track) { hmaxnode_ECAL_vs_HCAL->Fill( maxnode_HCAL, maxnode_ECAL, weight ); } //} } } hefficiency_vs_threshold_HCAL_FTcut->Divide( hshouldhit_HCAL_FTcut ); hefficiency_vs_threshold_HCAL_FPP1cut->Divide( hshouldhit_HCAL_FPP1cut ); hefficiency_vs_threshold_HCAL_FPP2cut->Divide( hshouldhit_HCAL_FPP2cut ); hefficiency_vs_threshold_ECAL_HCAL_coincidence_FTcut->Divide( hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FTcut ); hefficiency_vs_threshold_ECAL_HCAL_coincidence_FPP1cut->Divide( hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FPP1cut ); hefficiency_vs_threshold_ECAL_HCAL_coincidence_FPP2cut->Divide( hshouldhit_vs_threshold_ECAL_HCAL_coincidence_FPP2cut ); // TCanvas *c1 = new TCanvas("c1","c1",1200,900); // c1->Divide(2,1); // c1->cd(1)->SetLogy(); // hefficiency_vs_threshold_ECAL->SetMarkerStyle(20); // hefficiency_vs_threshold_ECAL->Draw(); // c1->cd(2)->SetLogy(); // hefficiency_vs_threshold_HCAL_FTcut->SetMarkerStyle(20); // hefficiency_vs_threshold_HCAL_FTcut->Draw(); hefficiency_vs_threshold_ECAL->Divide( hshouldhit_vs_threshold_ECAL ); hefficiency_vs_threshold_ECAL_FTcut->Divide(hshouldhit_vs_threshold_ECAL_FTcut ); hefficiency_vs_threshold_HCAL_FTcut->SetMarkerStyle(20); hefficiency_vs_threshold_ECAL->SetMarkerStyle(20); hefficiency_vs_Q2_ECAL_FTcut->Divide(hshouldhit_vs_Q2_ECAL_FTcut); fout->Write(); fout->Close(); }
void anaFragShape(TString infile="dj_HCPR-GoodTrkAndPixel_CleanEvt1130.root") { TChain * djcalo = new TChain("djcalo/djTree"); djcalo->Add(infile); aliases_dijet(djcalo); TChain * djcalopix = new TChain("djcalo_pxl/djTree"); djcalopix->Add(infile); aliases_dijet(djcalopix); TString evtSel("(cent<10 && nljet>120 && abs(nljeta)<2 && aljet>50 && abs(aljeta)<2 && jdphi>2.5 && Aj>0.24)"); TH1::SetDefaultSumw2(); TCanvas * c0 = new TCanvas("c0","c0",500,500); djcalo->Draw("Aj>>hAj(20,0,1)",evtSel); djcalopix->Draw("Aj",evtSel,"Esame"); TCanvas * c2 = new TCanvas("c2","c2",500,500); TH1D * hJDPhi = new TH1D("hJDPhi","hJDPhi",50,0,3.1416); TH1D * hJDPhi2 = new TH1D("hJDPhi2","hJDPhi",50,0,3.1416); Float_t numDJ = djcalo->Draw("jdphi>>hJDPhi",evtSel); Float_t numDJ2 = djcalopix->Draw("jdphi>>hJDPhi2",evtSel); cout << "num djs: " << numDJ << " djs(pix)" << numDJ2 << endl; TH1D * hPNDRTrk = new TH1D("hPNDRTrk",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2()); TH1D * hPNDRPix = new TH1D("hPNDRPix",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2()); TH1D * hPADRTrk = new TH1D("hPADRTrk",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2()); TH1D * hPADRPix = new TH1D("hPADRPix",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2()); djcalo->Draw("pndr>>hPNDRTrk",Form("(%s&&ppt>=1.2)*(ppt/(TMath::TwoPi()*pndr))",evtSel.Data())); djcalopix->Draw("pndr>>hPNDRPix",Form("(%s&&ppt>=0.3&&ppt<1.2)*(ppt/(TMath::TwoPi()*pndr))",evtSel.Data())); djcalo->Draw("padr>>hPADRTrk",Form("(%s&&ppt>=1.2)*(ppt/(TMath::TwoPi()*padr))",evtSel.Data())); djcalopix->Draw("padr>>hPADRPix",Form("(%s&&ppt>=0.3&&ppt<1.2)*(ppt/(TMath::TwoPi()*padr))",evtSel.Data())); hPNDRTrk->Scale(1./(numDJ*hPNDRTrk->GetBinWidth(1))); hPNDRPix->Scale(1./(numDJ*hPNDRPix->GetBinWidth(1))); hPADRTrk->Scale(1./(numDJ*hPADRTrk->GetBinWidth(1))); hPADRPix->Scale(1./(numDJ*hPADRPix->GetBinWidth(1))); hPNDRPix->SetMinimum(50); hPNDRPix->SetMaximum(100); hPNDRTrk->SetMinimum(10); hPNDRTrk->SetMaximum(2000); hPNDRPix->SetMarkerStyle(kFullCircle); hPNDRTrk->SetMarkerStyle(kFullSquare); hPNDRPix->SetMarkerColor(kRed); hPNDRTrk->SetMarkerColor(kRed); hPADRPix->SetMarkerStyle(kOpenCircle); hPADRTrk->SetMarkerStyle(kOpenSquare); hPADRPix->SetMarkerColor(kBlue); hPADRTrk->SetMarkerColor(kBlue); TCanvas * c3 = new TCanvas("c3","c3",500,500); hPNDRPix->Draw("E"); hPADRPix->Draw("Esame"); TCanvas * c3_2 = new TCanvas("c3_2","c3_2",500,500); c3_2->SetLogy(); hPNDRTrk->Draw("E"); hPADRTrk->Draw("Esame"); }
void tnpScale_IDISO( int leptype = 1, bool printplot = false ) { cout << endl; cout << "-------------------" << endl; if ( leptype == 0 ) cout << "Doing electrons" << endl; else if( leptype == 1 ) cout << "Doing muons" << endl; else{ cout << "ERROR! unrecognized leptype " << leptype << endl; exit(0); } cout << "-------------------" << endl; //---------------------------------------- // Files //---------------------------------------- TChain *chmc = new TChain("leptons"); TChain *chdata = new TChain("leptons"); char* version = (char*) "V00-00-06"; char* suffix = ""; //char* suffix = "_2jets"; //char* suffix = "_probept100"; chmc-> Add(Form("smurf/ZJetsFull_%s/merged%s.root",version,suffix)); if( leptype == 1 ){ chdata->Add(Form("smurf/SingleMu2012AFull_%s/merged_json%s.root",version,suffix)); chdata->Add(Form("smurf/SingleMu2012BFull_%s/merged_json%s.root",version,suffix)); chdata->Add(Form("smurf/SingleMu2012CFull_%s/merged_json%s.root",version,suffix)); chdata->Add(Form("smurf/SingleMu2012DFull_%s/merged_json%s.root",version,suffix)); } else{ chdata->Add(Form("smurf/SingleEl2012AFull_%s/merged_json%s.root",version,suffix)); chdata->Add(Form("smurf/SingleEl2012BFull_%s/merged_json%s.root",version,suffix)); chdata->Add(Form("smurf/SingleEl2012CFull_%s/merged_json%s.root",version,suffix)); chdata->Add(Form("smurf/SingleEl2012DFull_%s/merged_json%s.root",version,suffix)); } //---------------------------------------- // bins //---------------------------------------- // float ptbin[] = {10., 15., 20., 30., 40., 50., 7000.}; // float ptbin[] = { 30. , 40. , 50. , 60. , 80.0 , 100.0 , 120.0 , 150.0 , 7000.}; // float etabin[] = {0, 0.8, 1.5, 2.1}; // int nptbin=8; // int netabin=3; // float ptbin[] = { 20., 30. , 40. , 50. , 60. , 80.0 , 100.0 , 150.0 , 200.0 , 300.0 , 500.0 , 1000.0 , 10000000.0}; // int nptbin = 12; // float etabin[] = {0,2.1}; // int netabin = 1; float ptbin[] = { 20., 30. , 40. , 50. , 60. , 80.0 , 100.0 , 150.0 , 200.0 , 300.0, 10000.0}; int nptbin = 10; float etabin[4]; int netabin = 0; if( leptype == 1 ){ cout << "DOING MUON ETA BINS" << endl; netabin=3; etabin[0] = 0.0; etabin[1] = 0.8; etabin[2] = 1.5; etabin[3] = 2.1; } if( leptype == 0 ){ cout << "DOING ELECTRON ETA BINS" << endl; netabin=2; etabin[0] = 0.0; etabin[1] = 0.8; etabin[2] = 1.4442; // netabin=1; // etabin[0] = 0.0; // etabin[1] = 1.4442; } //deno TH2F *hmcid_deno = new TH2F("hmcid_deno" , "hmcid_deno" , nptbin, ptbin, netabin, etabin); TH2F *hmciso_deno = new TH2F("hmciso_deno" , "hmciso_deno" , nptbin, ptbin, netabin, etabin); TH2F *hdataid_deno = new TH2F("hdataid_deno" , "hdataid_deno" , nptbin, ptbin, netabin, etabin); TH2F *hdataiso_deno = new TH2F("hdataiso_deno", "hdataiso_deno", nptbin, ptbin, netabin, etabin); hmcid_deno->Sumw2(); hmciso_deno->Sumw2(); hdataid_deno->Sumw2(); hdataiso_deno->Sumw2(); //num TH2F *hmcid_num = new TH2F("hmcid_num" , "hmcid_num" , nptbin, ptbin, netabin, etabin); TH2F *hmciso_num = new TH2F("hmciso_num" , "hmciso_num" , nptbin, ptbin, netabin, etabin); TH2F *hdataid_num = new TH2F("hdataid_num" , "hdataid_num" , nptbin, ptbin, netabin, etabin); TH2F *hdataiso_num = new TH2F("hdataiso_num" , "hdataiso_num" , nptbin, ptbin, netabin, etabin); hmcid_num->Sumw2(); hmciso_num->Sumw2(); hdataid_num->Sumw2(); hdataiso_num->Sumw2(); // eff TH2F *hmcid = new TH2F("hmcid" , "hmcid" , nptbin, ptbin, netabin, etabin); TH2F *hmciso = new TH2F("hmciso" , "hmciso" , nptbin, ptbin, netabin, etabin); TH2F *hdataid = new TH2F("hdataid" , "hdataid" , nptbin, ptbin, netabin, etabin); TH2F *hdataiso = new TH2F("hdataiso" , "hdataiso" , nptbin, ptbin, netabin, etabin); hmcid->Sumw2(); hmciso->Sumw2(); hdataid->Sumw2(); hdataiso->Sumw2(); // SF TH2F *hsfid = new TH2F("hsfid" , "hsfid" , nptbin, ptbin, netabin, etabin); TH2F *hsfiso = new TH2F("hsfiso" , "hsfiso", nptbin, ptbin, netabin, etabin); hsfid->Sumw2(); hsfiso->Sumw2(); // TCuts TCut muid ("(leptonSelection&65536)==65536"); // mu id TCut muiso("(leptonSelection&131072)==131072"); // mu iso TCut elid ("(leptonSelection&8)==8"); // ele id TCut eliso("(leptonSelection&16)==16"); // ele iso TCut zmass("abs(tagAndProbeMass-91)<15"); TCut tightzmass("abs(tagAndProbeMass-91)<5"); TCut os("qProbe*qTag<0"); TCut mutnp("(eventSelection&2)==2"); TCut mutnptrig("HLT_IsoMu24_tag > 0"); TCut eltnp("(eventSelection&1)==1"); TCut eltnptrig("HLT_Ele27_WP80_tag > 0"); TCut tag_eta21("abs(tag->eta())<2.1"); TCut tag_eta14("abs(tag->eta())<1.4442"); TCut tag_pt30("tag->pt()>30.0"); TCut probe_eta21("abs(probe->eta())<2.1"); TCut probe_eta14("abs(probe->eta())<1.4442"); TCut mutrk("mutrk==1"); TCut met30("met<30"); TCut nbl0("nbl==0"); TCut njets0("njets>=0"); TCut njets1("njets>=1"); TCut njets2("njets>=2"); TCut njets3("njets>=3"); TCut njets4("njets>=4"); TCut mud0("mud0 < 0.02"); TCut mudz("mudz < 0.5"); // TCut mud0("mud0 < 0.2"); // TCut mudz("mudz < 1.0"); //TCut tnpcut = "abs(tagAndProbeMass-91)<15 && (eventSelection&2)==2 && HLT_IsoMu30_eta2p1_tag>0 && qProbe*qTag<0 && abs(tag->eta())<2.1 && tag->pt()>30.0"; TCut tnpcut; tnpcut += zmass; //tnpcut += tightzmass; tnpcut += os; tnpcut += tag_pt30; tnpcut += met30; tnpcut += nbl0; TCut lepid; TCut lepiso; char* lepchar = ""; if( leptype == 0 ){ tnpcut += tag_eta14; tnpcut += probe_eta14; tnpcut += eltnp; tnpcut += eltnptrig; lepid = TCut(elid); lepiso = TCut(eliso); lepchar = "el"; } else if( leptype == 1 ){ tnpcut += tag_eta21; tnpcut += probe_eta21; //tnpcut += mutrk; //tnpcut += mud0; //tnpcut += mudz; tnpcut += mutnp; tnpcut += mutnptrig; lepid = TCut(muid); lepiso = TCut(muiso); lepchar = "mu"; } //tnpcut += njets2; cout << "Selection : " << tnpcut.GetTitle() << endl; cout << "Ndata : " << chdata->GetEntries(tnpcut) << endl; cout << "NMC : " << chmc->GetEntries(tnpcut) << endl; cout << "ID cut : " << lepid.GetTitle() << endl; cout << "iso cut : " << lepiso.GetTitle() << endl; chmc-> Draw("abs(probe->eta()):probe->pt()>>hmcid_deno", tnpcut+lepiso, "goff"); chmc-> Draw("abs(probe->eta()):probe->pt()>>hmcid_num", tnpcut+lepiso+lepid, "goff"); chmc-> Draw("abs(probe->eta()):probe->pt()>>hmciso_deno", tnpcut+lepid, "goff"); chmc-> Draw("abs(probe->eta()):probe->pt()>>hmciso_num", tnpcut+lepid+lepiso, "goff"); chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_deno", tnpcut+lepiso, "goff"); chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_num", tnpcut+lepiso+lepid, "goff"); chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_deno", tnpcut+lepid, "goff"); chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_num", tnpcut+lepid+lepiso, "goff"); // get efficiencies hmcid->Divide(hmcid_num,hmcid_deno,1,1,"B"); hmciso->Divide(hmciso_num,hmciso_deno,1,1,"B"); hdataid->Divide(hdataid_num,hdataid_deno,1,1,"B"); hdataiso->Divide(hdataiso_num,hdataiso_deno,1,1,"B"); // hmcid->Divide(hmcid_num,hmcid_deno,1,1); // hmciso->Divide(hmciso_num,hmciso_deno,1,1); // hdataid->Divide(hdataid_num,hdataid_deno,1,1); // hdataiso->Divide(hdataiso_num,hdataiso_deno,1,1); // get scale factors hsfid->Divide(hdataid, hmcid, 1, 1); hsfiso->Divide(hdataiso, hmciso, 1, 1); // Draw histograms //hmcid->Draw("text"); printHeader( leptype , "MC ID" ); printline(hmcid); printHeader( leptype , "MC ISO" ); printline(hmciso); printHeader( leptype , "DATA ID" ); printline(hdataid); printHeader( leptype , "DATA ISO" ); printline(hdataiso); printHeader( leptype , "Scale Factor ID" ); printline(hsfid); printHeader( leptype , "Scale Factor ISO" ); printline(hsfiso); cout << "\\hline" << endl << "\\hline" << endl; TCanvas *c_iso[10]; TCanvas *c_id[10]; for( int i = 0 ; i < 1 ; i++ ){ TCut mysel; if ( i==0 ) mysel = TCut(tnpcut+njets0); else if( i==1 ) mysel = TCut(tnpcut+njets1); else if( i==2 ) mysel = TCut(tnpcut+njets2); else if( i==3 ) mysel = TCut(tnpcut+njets3); else if( i==4 ) mysel = TCut(tnpcut+njets4); c_iso[i] = new TCanvas(Form("c_iso_%i",i),Form("c_iso_%i",i),600,600); c_iso[i]->cd(); printHisto( c_iso[i] , chdata , chmc , TCut(lepiso) , TCut(mysel+lepid) , "probe.pt()" , 10 , 0.0 , 340.0 , "lepton p_{T} [GeV]" , "iso efficiency" ); if( printplot ) c_iso[i]->Print(Form("plots/%s_iso_njets%i.pdf",lepchar,i)); c_id[i] = new TCanvas(Form("c_id_%i",i),Form("c_id_%i",i),600,600); c_id[i]->cd(); printHisto( c_id[i] , chdata , chmc , TCut(lepid) , TCut(mysel+lepiso) , "probe.pt()" , 10 , 0.0 , 340.0 , "lepton p_{T} [GeV]" , "ID efficiency" ); if( printplot ) c_id[i]->Print(Form("plots/%s_id_njets%i.pdf",lepchar,i)); } /* //--------------------------- // tag cuts //--------------------------- TCut zmass("abs(tagAndProbeMass-91)<15"); TCut eltnp("(eventSelection&1)==1"); TCut mutnp("(eventSelection&2)==2"); TCut os("qProbe*qTag<0"); TCut tag_eta21("abs(tag->eta())<2.1"); TCut tag_eta25("abs(tag->eta())<2.5"); TCut njets1("njets>=1"); TCut njets2("njets>=2"); TCut njets3("njets>=3"); TCut njets4("njets>=4"); TCut tag_pt30("tag->pt()>30.0"); TCut met30("met<30"); TCut met20("met<20"); TCut nbm0("nbm==0"); TCut nbl0("nbl==0"); TCut mt30("mt<30"); TCut eltnptrig("HLT_TNP_tag > 0 || HLT_TNPel_tag > 0"); TCut mutnptrig("HLT_IsoMu30_eta2p1_tag > 0"); //--------------------------- // tag cuts //--------------------------- TCut mufo = "(leptonSelection&32768)==32768"; // mu fo TCut elfo = "(leptonSelection&4)==4"; // ele fo TCut elid = "(leptonSelection&8)==8"; // ele id TCut eliso = "(leptonSelection&16)==16"; // ele iso TCut probept = "probe->pt()>30"; // probe pt TCut drprobe = "drprobe<0.05"; // dR(probe,pfcandidate) TCut eltnpcut; eltnpcut += zmass; eltnpcut += os; eltnpcut += eltnp; eltnpcut += tag_eta25; //eltnpcut += njets2; eltnpcut += tag_pt30; eltnpcut += eltnptrig; eltnpcut += met30; // eltnpcut += mt30; eltnpcut += nbl0; eltnpcut += elid; eltnpcut += probept; eltnpcut += drprobe; TCut mutnpcut; mutnpcut += zmass; mutnpcut += os; mutnpcut += mutnp; mutnpcut += tag_eta21; //mutnpcut += njets2; mutnpcut += tag_pt30; mutnpcut += mutnptrig; mutnpcut += met30; // mutnpcut += mt30; mutnpcut += nbl0; mutnpcut += muid; mutnpcut += probept; mutnpcut += drprobe; //eltnpcut += njets2; //eltnpcut += njets3; //eltnpcut += nbm0; //eltnpcut += mt30; //eltnpcut += met20; //TCut eltnpcut = "abs(tagAndProbeMass-91)<15 && (eventSelection&1)==1 && qProbe*qTag<0 && abs(tag->eta())<2.5 && njets>=4 && tag->pt()>30.0 && met<30.0 && nbm==0 && mt<30"; //TCut mutnpcut = "abs(tagAndProbeMass-91)<15 && (eventSelection&2)==2 && HLT_IsoMu30_eta2p1_tag>0 && qProbe*qTag<0 && abs(tag->eta())<2.1 && njets>=4 && tag->pt()>30.0"; TCut vtxweight = "vtxweight"; cout << "Electrons:" << endl; cout << "Total MC yields : " << chmc->GetEntries(eltnpcut) << endl; cout << "Total DATA yields : " << chdata->GetEntries(eltnpcut) << endl; cout << "Muons:" << endl; cout << "Total MC yields : " << chmc->GetEntries(mutnpcut) << endl; cout << "Total DATA yields : " << chdata->GetEntries(mutnpcut) << endl; //TCut njets = "njets>=2"; TCut tkisoold = "tkisoold/probe->pt()>0.1"; TCut tkisonew = "tkisonew/probe->pt()>0.1"; //----------------------------------------- // check nvtx data vs. MC //----------------------------------------- TH1F *hnvtx_mc = new TH1F("hnvtx_mc" ,"",30,0,30); TH1F *hnvtx_data = new TH1F("hnvtx_data","",30,0,30); hnvtx_mc->Sumw2(); hnvtx_data->Sumw2(); chdata->Draw("nvtx>>hnvtx_data",(eltnpcut||mutnpcut)); chmc->Draw("nvtx>>hnvtx_mc",(eltnpcut||mutnpcut)*vtxweight); TCanvas *c1 = new TCanvas(); c1->cd(); hnvtx_mc->SetLineColor(2); hnvtx_mc->SetMarkerColor(2); hnvtx_data->SetLineColor(4); hnvtx_data->SetMarkerColor(4); hnvtx_data->GetXaxis()->SetTitle("N_{VTX}"); hnvtx_data->DrawNormalized(); hnvtx_mc->DrawNormalized("same"); TLegend *leg = new TLegend(0.6,0.6,0.8,0.8); leg->AddEntry(hnvtx_data,"data","lp"); leg->AddEntry(hnvtx_mc,"MC","lp"); leg->SetFillColor(0); leg->SetBorderSize(0); leg->Draw(); if( printplot ) c1->Print("plots/nvtx.pdf"); // Fill histograms // // chmc->Draw("abs(probe->eta()):probe->pt()>>hmcid_deno", tnpcut+"&&"+eliso, "goff"); // chmc->Draw("abs(probe->eta()):probe->pt()>>hmcid_num", tnpcut+"&&"+eliso+"&&"+elid, "goff"); // chmc->Draw("abs(probe->eta()):probe->pt()>>hmciso_deno", tnpcut+"&&"+elid, "goff"); // chmc->Draw("abs(probe->eta()):probe->pt()>>hmciso_num", tnpcut+"&&"+elid+"&&"+eliso, "goff"); // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_deno", tnpcut+"&&"+eliso, "goff"); // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataid_num", tnpcut+"&&"+eliso+"&&"+elid, "goff"); // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_deno", tnpcut+"&&"+elid, "goff"); // chdata->Draw("abs(probe->eta()):probe->pt()>>hdataiso_num", tnpcut+"&&"+elid+"&&"+eliso, "goff"); */ }
void sampleComparison(){ gROOT->SetStyle("Plain"); /* TChain *uno = new TChain("sT"); uno->Add("/raid/sguazz/split/MuGun_NomGeo.root"); TString n1("MuGun NomGeo"); TChain *due = new TChain("sT"); due->Add("/raid/sguazz/split/minBias_nH4_v2.root"); TString n2("MinBias"); */ TChain *uno = new TChain("sT"); uno->Add("/raid/sguazz/split/minBias_nH4_v2.root"); TString n1("minBias MC"); TChain *due = new TChain("sT"); due->Add("/raid/sguazz/split/minbias_run2012Cpart1_nH4.root"); TString n2("minBias run2012C"); std::cout << " Sample uno:" << uno->GetEntries() << " due:" << due->GetEntries() << std::endl; TH1F * chi2SplitUno = new TH1F("chi2Split",";#chi^{2}_{SPLIT}/d.o.f.;",40, 0.,20.); TH1F * chi2SplitDue = new TH1F("chi2SplitDue",";#chi^{2}_{SPLIT}/d.o.f.;",40, 0.,20.); TH1F * etaUno = new TH1F("eta",";#eta;",50,-2.5,2.5); TH1F * etaDue = new TH1F("etaDue",";#eta;",50,-2.5,2.5); TH1F * phiUno = new TH1F("phi",";#phi;",50,-M_PI,M_PI); TH1F * phiDue = new TH1F("phiDue",";#phi;",50,-M_PI,M_PI); TH1F * ptUno = new TH1F("pt",";P_{T} [GeV];",50,0.7,1.3); TH1F * ptDue = new TH1F("ptDue",";P_{T} [GeV];",50,0.7,1.3); TH1F * ptNormUno = new TH1F("ptNorm",";P_{T} [GeV];",200,0.9,1.1); TH1F * ptNormDue = new TH1F("ptNormDue",";P_{T} [GeV];",200,0.9,1.1); TH1F * nUno = new TH1F("n",";N_{SPLIT};",7,-0.5,6.5); TH1F * nDue = new TH1F("nDue",";N_{SPLIT};",7,-0.5,6.5); TH1F * dzUno = new TH1F("dz",";dz;",40,-20.,20.); TH1F * dzDue = new TH1F("dzDue",";dz;",40,-20.,20.); TH1F * routUno = new TH1F("rOut",";rOut;",30,100.,115.); TH1F * routDue = new TH1F("rOutDue",";rOut;",30,100.,115.); // MC // TString cut("pt>0.9&&pt<1.1&&chi2<2.&&rIn<8.&&((rOut>100.)||(zOut>260.)||(zOut<-260.))&&pLossSim>0.&&(nHitIna+nHitMis+nHitBad)==0&&dz<5.&&dz>-5.&&maxchi2<4.&&chi2Split>0."); // TString cutNoPt("chi2<2.&&rIn<8.&&((rOut>100.)||(zOut>260.)||(zOut<-260.))&&pLossSim>0.&&(nHitIna+nHitMis+nHitBad)==0&&dz<5.&&dz>-5.&&maxchi2<4.&&chi2Split>0."); // Data TString cut("pt>0.9&&pt<1.1&&chi2<2.&&rIn<8.&&((rOut>100.)||(zOut>260.)||(zOut<-260.))&&(nHitIna+nHitMis+nHitBad)==0&&dz<5.&&dz>-5.&&maxchi2<4.&&(chi2Split/(NSplit-2.))>0.&&(chi2Split/(NSplit-2.))<4."); TString cutROut("pt>0.9&&pt<1.1&&chi2<2.&&rIn<8.&&((rOut>100.)||(zOut>260.)||(zOut<-260.))&&(nHitIna+nHitMis+nHitBad)==0&&dz<5.&&dz>-5.&&maxchi2<4.&&(chi2Split/(NSplit-2.))>0.&&(chi2Split/(NSplit-2.))<4.&&eta<0.9&&eta>-0.9"); TString cutNoDz("pt>0.9&&pt<1.1&&chi2<2.&&rIn<8.&&((rOut>100.)||(zOut>260.)||(zOut<-260.))&&(nHitIna+nHitMis+nHitBad)==0&&maxchi2<4.&&(chi2Split/(NSplit-2.))>0.&&(chi2Split/(NSplit-2.))<4."); TString cutNoChi("pt>0.9&&pt<1.1&&chi2<2.&&rIn<8.&&((rOut>100.)||(zOut>260.)||(zOut<-260.))&&(nHitIna+nHitMis+nHitBad)==0&&dz<5.&&dz>-5.&&maxchi2<4.&&(chi2Split/(NSplit-2.))>0."); TString cutNoPt( "chi2<2.&&rIn<8.&&((rOut>100.)||(zOut>260.)||(zOut<-260.))&&(nHitIna+nHitMis+nHitBad)==0&&dz<5.&&dz>-5.&&maxchi2<4.&&(chi2Split/(NSplit-2.))>0.&&(chi2Split/(NSplit-2.))<4."); TString cutNoSplit("pt>0.9&&pt<1.1&&chi2<2.&&rIn<8.&&((rOut>100.)||(zOut>260.)||(zOut<-260.))&&(nHitIna+nHitMis+nHitBad)==0&&dz<5.&&dz>-5.&&maxchi2<4."); int maxentries = 10000000; //int maxentries = 999999999; //TString assoc("&&pLossSim>0."); TString assoc(""); uno->Draw("(chi2Split/(NSplit-2.))>>chi2Split",cutNoChi+assoc,"goff",maxentries); due->Draw("(chi2Split/(NSplit-2.))>>chi2SplitDue",cutNoChi+assoc,"goff",maxentries); draw(chi2SplitUno, chi2SplitDue, n1, n2); uno->Draw("eta>>eta",cut+assoc,"goff",maxentries); due->Draw("eta>>etaDue",cut+assoc,"goff",maxentries); draw(etaUno, etaDue, n1, n2); uno->Draw("pt>>pt",cutNoPt+assoc,"goff",maxentries); due->Draw("pt>>ptDue",cutNoPt+assoc,"goff",maxentries); draw(ptUno, ptDue, n1, n2); uno->Draw("pt>>pt",cut+assoc,"goff",maxentries); due->Draw("pt>>ptDue",cut+assoc,"goff",maxentries); draw(ptUno, ptDue, n1, n2); uno->Draw("dz>>dz",cutNoDz+assoc,"goff",maxentries); due->Draw("dz>>dzDue",cutNoDz+assoc,"goff",maxentries); draw(dzUno, dzDue, n1, n2); uno->Draw("rOut>>rOut",cutROut+assoc,"goff",maxentries); due->Draw("rOut>>rOutDue",cutROut+assoc,"goff",maxentries); draw(routUno, routDue, n1, n2); uno->Draw("phi>>phi",cut+assoc,"goff",maxentries); due->Draw("phi>>phiDue",cut+assoc,"goff",maxentries); draw(phiUno, phiDue, n1, n2); uno->Draw("NSplit>>n",cutNoSplit+assoc,"goff",maxentries); due->Draw("NSplit>>nDue",cutNoSplit+assoc,"goff",maxentries); draw(nUno, nDue, n1, n2); }
runLooper_electron(){ // gStyle->SetTitleX(0.1f); // gStyle->SetTitleW(0.5f); TChain *Chain = new TChain("Events"); // Chain->Add("/store/disk01/yanjuntu/SingleElectron83055667ceda31da68d5aa532f72919d/preprocessing/ntuple*.root"); //tas03 Chain->Add("/hadoop/cms/store/user/yanjuntu/conversion_sample_cms2-V01-03-01/SingleElectron83055667ceda31da68d5aa532f72919d/preprocessing/ntuple*.root"); //uaf6 //Chain->Add("/store/disk01/yanjuntu/2_2_10/singleElectron_ntuple_v3.root"); TCanvas* c1 = new TCanvas("c1","c1"); TH1F hist_singleElectron("singleElectron", "; Eta", 100,-3,3); Chain->Draw("els_p4.eta() >> singleElectron", susy_baseline_2); c1->SaveAs("~/sample_plots/conversions/3_1_x/singleElectron_ele_eta_susy.eps"); float ntotal = hist_singleElectron.Integral(); TH1F hist_singleElectron("singleElectron", "; Number of valid pixel hits", 16,0,8); Chain->Draw("els_valid_pixelhits >> singleElectron",susy_baseline_2 && forward); c1->SaveAs("~/sample_plots/conversions/3_1_x/singleElectron_ele_valid_pixelhits_susy.eps"); float ntotal_forward = hist_singleElectron.Integral(); float n_removed_pixelhit = hist_singleElectron.GetBinContent(0); TH1F hist_singleElectron("singleElectron", "; DetID", 10,0,5); Chain->Draw("els_layer1_det >> singleElectron", susy_baseline_2 && forward &&"(els_valid_pixelhits==2||els_valid_pixelhits==1)"); c1->SaveAs("~/sample_plots/conversions/3_1_x/singleElectron_ele_layer1_detid_susy.eps"); TH1F hist_singleElectron("singleElectron", "; Layer of the first valid pixel hit (Barrel)", 10,0,5); Chain->Draw("els_layer1_layer >> singleElectron", susy_baseline_2 && forward &&"(els_valid_pixelhits==2||els_valid_pixelhits==1) && els_layer1_det==1"); c1->SaveAs("~/sample_plots/conversions/3_1_x/singleElectron_ele_layer1_layer_barrel_susy.eps"); float n_removed_layer = hist_singleElectron.Integral(hist_singleElectron.FindBin(2),hist_singleElectron.GetNbinsX()+1); TH1F hist_singleElectron("singleElectron", "; Charge of the first valid pixel hit (Disk)", 100,10000,200000); Chain->Draw("els_layer1_charge >> singleElectron", susy_baseline_2 && forward && "(els_valid_pixelhits==2||els_valid_pixelhits==1) &&els_layer1_det==2"); c1->SaveAs("~/sample_plots/conversions/3_1_x/singleElectron_ele_layer1_charge_disk_susy.eps"); float n_removed_charge = hist_singleElectron.Integral(hist_singleElectron.FindBin(40000),hist_singleElectron.GetNbinsX()+1); TH2F hist_Electron("Electron", "; Charge of the first valid pixel hit (Disk); Eta", 100, 10000,100000, 300,1.5,2.8); Chain->Draw("abs(els_p4.eta()):els_layer1_charge >> Electron",susy_baseline_2 && forward && "(els_valid_pixelhits==2||els_valid_pixelhits==1) &&els_layer1_det==2", "box"); c1->SaveAs("~/sample_plots/conversions/3_1_x/singleElectron_ele_layer1_chargeVsEta_disk_susy.eps"); TH1F hist_singleElectron("singleElectron", "; Number of expected inner layers", 16,0,8); Chain->Draw("els_n_inner_layers >> singleElectron", susy_baseline_2 ); c1->SaveAs("~/sample_plots/conversions/3_1_x/singleElectron_ele_ninner_susy.eps"); float n_removed_m2_0 = hist_singleElectron.Integral(hist_singleElectron.FindBin(1),hist_singleElectron.GetNbinsX()+1); float n_removed_m2_1 = hist_singleElectron.Integral(hist_singleElectron.FindBin(2),hist_singleElectron.GetNbinsX()+1); float ineff_forward = (n_removed_pixelhit+n_removed_layer+n_removed_charge)/ntotal_forward; float ineff = (n_removed_pixelhit+n_removed_layer+n_removed_charge)/ntotal; std::cout<< "total electrons = "<<ntotal <<std::endl; std::cout<< "total electrons in the forward region = "<<ntotal_forward <<std::endl; std::cout<< "electrons removed by cutting on the number of pixel hits = "<< n_removed_pixelhit<<std::endl; std::cout<< "electrons removed by cutting on the layer = "<< n_removed_layer<<std::endl; std::cout<< "electrons removed by cutting on the charge = "<< n_removed_charge<<std::endl; std::cout<< "the inefficeincy of prompt electrons in forward region = "<<ineff_forward <<std::endl; std::cout<< "the inefficeincy of prompt electrons = "<<ineff <<std::endl; float ineff_m2_0 = n_removed_m2_0/ntotal; float ineff_m2_1 = n_removed_m2_1/ntotal; std::cout<< "electrons removed by cutting ninner layers (loose) = "<<n_removed_m2_0 <<std::endl; std::cout<< "electrons removed by cutting ninner layers (tight) = "<<n_removed_m2_1 <<std::endl; std::cout<< "method 2 loose cut: the inefficeincy of prompt electrons = "<<ineff_m2_0 <<std::endl; std::cout<< "method 2 tight cut: the inefficeincy of prompt electrons = "<<ineff_m2_1 <<std::endl; }
int main(int argc, char *argv[]) { char appName[] = "root2lhco"; stringstream message; FILE *outputFile = 0; TChain *inputChain = 0; LHCOWriter *writer = 0; ExRootTreeReader *treeReader = 0; Long64_t entry, allEntries; if(argc < 2 || argc > 3) { cerr << " Usage: " << appName << " input_file" << " [output_file]" << endl; cerr << " input_file - input file in ROOT format," << endl; cerr << " output_file - output file in LHCO format," << endl; cerr << " with no output_file, or when output_file is -, write to standard output." << endl; return 1; } signal(SIGINT, SignalHandler); gROOT->SetBatch(); int appargc = 1; char *appargv[] = {appName}; TApplication app(appName, &appargc, appargv); try { cerr << "** Reading " << argv[1] << endl; inputChain = new TChain("Delphes"); inputChain->Add(argv[1]); ExRootTreeReader *treeReader = new ExRootTreeReader(inputChain); if(argc == 2 || strcmp(argv[2], "-") == 0) { outputFile = stdout; } else { outputFile = fopen(argv[2], "w"); if(outputFile == NULL) { message << "can't open " << argv[2]; throw runtime_error(message.str()); } } fprintf(outputFile, " # typ eta phi pt jmas ntrk btag had/em dum1 dum2\n"); allEntries = treeReader->GetEntries(); cerr << "** Input file contains " << allEntries << " events" << endl; if(allEntries > 0) { // Create LHC Olympics converter: writer = new LHCOWriter(treeReader, outputFile); ExRootProgressBar progressBar(allEntries - 1); // Loop over all events for(entry = 0; entry < allEntries && !interrupted; ++entry) { if(!treeReader->ReadEntry(entry)) { cerr << "** ERROR: cannot read event " << entry << endl; break; } writer->ProcessEvent(); progressBar.Update(entry); } progressBar.Finish(); delete writer; } cerr << "** Exiting..." << endl; if(outputFile != stdout) fclose(outputFile); delete treeReader; delete inputChain; return 0; } catch(runtime_error &e) { if(writer) delete writer; if(treeReader) delete treeReader; if(inputChain) delete inputChain; cerr << "** ERROR: " << e.what() << endl; return 1; } }
void analyze(){ int ifiles = 0; bool MC = false; bool correct = true; double drMax = 0.2; double ptMin = 0.3; double ptMax = 15; double jetPtMin = 7.; double jetEtaMax = 2.; double jetEMFMin = 0.01; const int nEtBins = 8; // === input === TChain* tree = new TChain("Events"); tree->Add("/d100/data/MinimumBias-ReReco/Jan29ReReco-v2/bambu/BSCNOBEAMHALO_000_*.root"); //tree->Add("/d100/data/MinimumBias-ReReco/Jan29ReReco-v2/bambu/BSCNOBEAMHALO_000_1.root"); // === ana config === double etBinsArray[nEtBins] = {0,5,10,15,20,30,70,120}; vector<double> etBins(etBinsArray,etBinsArray+nEtBins); string JECLevels = "L2:L3"; //string JECTag = "900GeV_L2Relative_IC5Calo:900GeV_L3Absolute_IC5Calo"; string JECTag = "900GeV_L2Relative_AK5Calo:900GeV_L3Absolute_AK5Calo"; CombinedJetCorrector *JEC = new CombinedJetCorrector(JECLevels,JECTag); // === setup output === char* outname = Form("hists.root",ifiles); TFile* outf = new TFile(outname,"recreate"); TH1::SetDefaultSumw2(); TH1D* hptTr[nEtBins+1]; TH1D* hptGen[nEtBins+1]; TTree * tree_ = new TTree("dijetTree","dijet tree"); TreeDiJetEventData jd_; jd_.SetTree(tree_); jd_.SetBranches(); for(int ih = 0; ih < nEtBins+1; ++ih){ hptTr[ih] = new TH1D(Form("hptTr%d",ih),Form("Tracks in cone |#Delta R| < %f; p_{T}^{track}; N_{track}/N_{jet}",drMax),250,ptMin,ptMax); hptGen[ih] = new TH1D(Form("hptGen%d",ih),Form("Charged Particles in cone |#Delta R| < %f; p_{T}^{chg}; N_{chg}/N_{jet}",drMax),250,ptMin,ptMax); } TH1D* hptJet = new TH1D("hptJet",";p_{T} [GeV];jets",100,0,20); TH2D* hptCor = new TH2D("hptCor",";p_{T}^{raw} [GeV];p_{T}^{corrected} [GeV]",100,0,20,100,0,20); TH1D* hDR = new TH1D("hDR",";#Delta R;tracks",100,0,3.2); TH1D* hFFz = new TH1D("hFFz","",100,0,1.2); TH1D* hXi = new TH1D("hXi","",100,-2,8); TH1D* hFFzGen = new TH1D("hFFzGen","",100,0,1.2); TH1D* hXiGen = new TH1D("hXiGen","",100,-2,8); // === setup branches mithep::Array<mithep::CaloJet> *jets; mithep::Array<mithep::Track> *tracks; mithep::Array<mithep::Vertex> *vertices; mithep::L1TriggerMask *L1T; mithep::L1TriggerMask *L1A; mithep::Array<mithep::MCParticle> *genparticles; mithep::Array<mithep::GenJet> *genjets; mithep::EventHeader *evInfo; //tree->SetBranchAddress("ItrCone5Jets",&jets); tree->SetBranchAddress("AKt5Jets",&jets); tree->SetBranchAddress("Tracks",&tracks); tree->SetBranchAddress("PrimaryVertexes",&vertices); tree->SetBranchAddress("L1TechBitsBeforeMask",&L1T); tree->SetBranchAddress("L1AlgoBitsBeforeMask",&L1A); tree->SetBranchAddress("EventHeader",&evInfo); /* if(MC){ tree->SetBranchAddress("MCParticles",&genparticles); tree->SetBranchAddress("IC5GenJets",&genjets); } */ int nevents = tree->GetEntries(); int nevtrig = 0; double njet[nEtBins] = {0.,0.,0.,0.,0.,0.,0.,0.}; double ngenjet[nEtBins] = {0.,0.,0.,0.,0.,0.,0.,0.}; // nevents = 50; for(int iev = 0; iev < nevents; ++iev){ tree->GetEntry(iev); // clear jet data jd_.ClearCounters(); // trigger info bool A0 = L1A->Get().TestBit(0); // run level UInt_t runNum=evInfo->RunNum(); // - good runs - if (!MC && runNum!=123596 && runNum!=123615 && runNum!=123732 && runNum!=123815 && runNum!=123818 && runNum!=123906 && runNum!=123908 && runNum!=124008 && runNum!=124009 && runNum!=124020 && runNum!=124022 && runNum!=124023 && runNum!=124024 && runNum!=124025 && runNum!=124027 && runNum!=124030 ) continue; // print out info (out of good runs) before any filters cout << "Run #: " << runNum << " Event: " << evInfo->EvtNum() << " Lumi: " << evInfo->LumiSec() << " PhysDeclared?: " << evInfo->IsPhysDec() << " L1A0?: " << A0 << endl; // Filter on phys declared if (!MC && (!evInfo->IsPhysDec() || !A0)) continue; // === Event Level === // if no vertex nothing to do if(vertices->GetEntries() < 1) continue; // there is a vertex const mithep::Vertex * vtx = (Vertex*)vertices->At(0); bool goodVertex = vtx->Ndof()> 4 && TMath::Abs(vtx->Z() < 15.); cout << " EventInfo - nvtx: " << vertices->GetEntries() << " vtxndof: " << vtx->Ndof() << endl; // - save event info jd_.run_ = runNum; jd_.event_ = evInfo->EvtNum(); jd_.vtxdof_ = vtx->Ndof(); jd_.vz_ = vtx->Z(); if(!goodVertex) { tree_->Fill(); continue; } // - got good event vertex - nevtrig++; // === Jet Level === int njets = jets->GetEntries(); int nGoodJets = 0; double awayEtMax=-99; double ptljet[2] = {-99,-99}; for(int i = 0; i < njets; ++i){ CaloJet* jet = (CaloJet*)jets->At(i); jet->DisableCorrections(); double ptjet = jet->Pt(); double etajet = jet->Eta(); double phijet = jet->Phi(); if (ptjet>3) cout << " raw jet "<<i<<": Pt|eta|phi: " << ptjet <<"|"<< etajet << "|" << phijet << endl; double emf = jet->EnergyFractionEm(); bool goodJet = TMath::Abs(etajet) < jetEtaMax && emf > jetEMFMin; if(!goodJet) continue; double energy = jet->E(); int jetbin = getBin(ptjet,etBins)+1; njet[jetbin] += 1.; hptJet->Fill(ptjet); double corpt = ptjet*JEC->getCorrection(ptjet,etajet,energy); hptCor->Fill(ptjet,corpt); if(correct) ptjet = corpt; if(ptjet< jetPtMin) continue; //cout << " jet" << i << " Good . corr"<<correct<<"Pt|eta|phi: " << ptjet <<"|"<< etajet << "|" << phijet << endl; } // === Dijet Ana === if (njets<2) { // nothing to do for dijet ana, fill some inclusive track info int ntracks = tracks->GetEntries(); int nHP = 0; for(int it = 0; it < ntracks; ++it){ Track* track = (Track*)(tracks->At(it)); mithep::TrackQuality& quality = track->Quality(); bool highPurity = quality.QualityMask().TestBit(2); jd_.trkNHits_[it] = track->NHits(); jd_.trkHP_[it] = highPurity; jd_.ppt_[it] = track->Pt(); jd_.peta_[it] = track->Eta(); jd_.pphi_[it] = track->Phi(); if (highPurity) ++nHP; } jd_.evtnp_ = ntracks; jd_.fracHP_ = (double)nHP/(double)ntracks; tree_->Fill(); continue; } // there are 2 jets CaloJet* jet0 = (CaloJet*)jets->At(0); CaloJet* jet1 = (CaloJet*)jets->At(1); // apply corrections jet0->DisableCorrections(); jet1->DisableCorrections(); double ptjet0 = jet0->Pt(); double ptjet1 = jet1->Pt(); double etajet0 = jet0->Eta(); double etajet1 = jet1->Eta(); double phijet0 = jet0->Phi(); double phijet1 = jet1->Phi(); FourVectorM jet0p4 = jet0->RawMom(); FourVectorM jet1p4 = jet1->RawMom(); if(correct) { double scale = JEC->getCorrection(ptjet0,etajet0,jet0->E()); ptjet0 *= scale; jet0p4 *= scale; } if(correct) { double scale = JEC->getCorrection(ptjet1,etajet1,jet1->E()); ptjet1 *= scale; jet1p4 *= scale; } // cut jet //bool goodDiJet = ptjet0>1 && ptjet1>1; //if (!goodDiJet) continue; cout << " jet 0 corr"<<correct<<"Pt|eta|phi: " << ptjet0 <<"|"<< etajet0 << "|" << phijet0 << " p4: " << jet0p4 << endl; cout << " jet 1 corr"<<correct<<"Pt|eta|phi: " << ptjet1 <<"|"<< etajet1 << "|" << phijet1 << " p4: " << jet1p4 << endl; double ljdphi = TMath::Abs(reco::deltaPhi(phijet0,phijet1)); cout << " leading jets dphi: " << ljdphi << endl; // -- Fill jet info -- // fill dijet info jd_.jdphi_ = ljdphi; jd_.mass_ = (jet0p4+jet1p4).M(); // near/away info jd_.nljet_ = ptjet0; jd_.nljeta_ = etajet0; jd_.nljphi_ = phijet0; jd_.nljemf_ = jet0->EnergyFractionEm(); jd_.aljet_ = ptjet1; jd_.aljeta_ = etajet1; jd_.aljphi_ = phijet1; jd_.aljemf_ = jet1->EnergyFractionEm(); // === Track Level === int ntracks = tracks->GetEntries(); int nHP = 0; int selTrkCt = 0; for(int j = 0; j < ntracks; ++j){ Track* track = (Track*)(tracks->At(j)); double pttrack = track->Pt(); double etatrack = track->Eta(); double phitrack = track->Phi(); mithep::TrackQuality& quality = track->Quality(); if(0){ double d0err = track->D0Err(); double sigXY = sqrt(d0err*d0err + 0.04*0.04); double qope = track->QOverPErr(); double lambdaerr = track->LambdaErr(); double pz = track->Pz(); int chg = track->Charge(); } bool highPurity = quality.QualityMask().TestBit(2); //cout << "highPurity?: " << quality.QualityMask().TestBit(2) << endl; bool goodTrack = highPurity; if (highPurity) ++nHP; //if(!goodTrack) continue; //cout << "sel track: " << selTrkCt << " pt eta phi: " << pttrack << "|" << etatrack << "|" << phitrack << endl; // -- Fill Tracks -- // fill frag candidates basic info jd_.trkNHits_[selTrkCt] = track->NHits(); jd_.trkHP_[selTrkCt] = highPurity; jd_.ppt_[selTrkCt] = pttrack; jd_.peta_[selTrkCt] = etatrack; jd_.pphi_[selTrkCt] = phitrack; // Relations to jet jd_.pndphi_[selTrkCt] = TMath::Abs(reco::deltaPhi(phitrack,phijet0)); jd_.pndeta_[selTrkCt] = etatrack - etajet0; jd_.pndr_[selTrkCt] = reco::deltaR(etatrack,phitrack,etajet0,phijet0); jd_.padphi_[selTrkCt] = TMath::Abs(reco::deltaPhi(phitrack,phijet1)); jd_.padeta_[selTrkCt] = etatrack - etajet1; jd_.padr_[selTrkCt] = reco::deltaR(etatrack,phitrack,etajet1,phijet1); // - background variables- jd_.pndrbg_[selTrkCt] = reco::deltaR(etatrack,phitrack,etajet0,phijet0+TMath::Pi()/2); jd_.padrbg_[selTrkCt] = reco::deltaR(etatrack,phitrack,etajet1,phijet1+TMath::Pi()/2); // jet cone info if (pttrack>0.3 && pttrack<60 && highPurity && track->NHits()>=8 && jd_.pndr_[selTrkCt]<0.5) ++jd_.nljCone5NP_; // fragmentation variables jd_.zn_[selTrkCt] = pttrack/ptjet0; jd_.za_[selTrkCt] = pttrack/ptjet1; // save counter ++selTrkCt; /* double dr = reco::deltaR(etatrack,phitrack,etajet,phijet); hDR->Fill(dr); if(dr > drMax) continue; hptTr[0]->Fill(pttrack); hptTr[jetbin]->Fill(pttrack); if(pttrack < ptMin) continue; double ffz = pttrack/ptjet; double xi = -log(ffz); hFFz->Fill(ffz); hXi->Fill(xi); */ } // tracks jd_.evtnp_ = selTrkCt; jd_.fracHP_ = (double)nHP/(double)ntracks; // mc input /* if(MC){ int ngenjets = genjets->GetEntries(); for(int i = 0; i < ngenjets; ++i){ GenJet* jet = (GenJet*)genjets->At(i); double ptjet = jet->Pt(); double etajet = jet->Eta(); double phijet = jet->Phi(); double energy = jet->E(); int jetbin = getBin(ptjet,etBins)+1; ngenjet[jetbin] += 1.; int nparticles = genparticles->GetEntries(); for(int j = 0; j < nparticles; ++j){ MCParticle* p = (MCParticle*)(genparticles->At(j)); int chg = p->Charge(); if(chg == 0 || chg < -10) continue; double ptpar = p->Pt(); double etapar = p->Eta(); double phipar = p->Phi(); double dr = reco::deltaR(etapar,phipar,etapar,phipar); if(dr > drMax) continue; if(ptpar < ptMin) continue; double ffz = ptpar/ptjet; double xi = -log(ffz); hFFzGen->Fill(ffz); hXiGen->Fill(xi); } } } */ // all done! tree_->Fill(); } // event end hptJet->Draw(); TCanvas* c2 = new TCanvas(); hptCor->Draw("colz"); TCanvas* c3 = new TCanvas(); c3->Divide(2,2); c3->cd(1); hDR->Draw(); c3->cd(2); hFFz->Draw(); c3->cd(3); hXi->Draw(); /* if(MC){ TCanvas* c4 = new TCanvas(); c4->Divide(2,2); c4->cd(1); c4->cd(2); hFFzGen->Draw(); c4->cd(3); hXiGen->Draw(); } */ /* for(int is = 0; is < nEtBins; ++is){ hptTr[is]->Write(); hptGen[is]->Write(); } hDR->Write(); hFFz->Write(); hXi->Write(); */ outf->Write(); outf->Close(); cout<<"---------------------------------------"<<endl; cout<<"Total Number of Events used : "<<nevtrig<<endl; cout<<"---------------------------------------"<<endl; }
void plotAngResVsSnr2(){ TChain* cLdb = new TChain("angResTree"); TChain* cSnrLdb = new TChain("snrTree"); TChain* cWais = new TChain("angResTree"); TChain* cSnrWais = new TChain("snrTree"); // cLdb->Add("filterOffs/phaseCenter/generateAngularResolutionTreeVPOLPlots_*"); // cSnrLdb->Add("filterOffs/phaseCenter/generateSignalToNoiseRatioTreeVPOLPlots_*"); // cWais->Add("filterOffs/phaseCenter/generateAngularResolutionTreePlots_*"); // cSnrWais->Add("filterOffs/phaseCenter/generateSignalToNoiseRatioTreePlots_*"); cLdb->Add("extremeFilter/phaseCenter/generateAngularResolutionTreeVPOLPlots_*"); cSnrLdb->Add("extremeFilter/phaseCenter/generateSignalToNoiseRatioTreeVPOLPlots_*"); cWais->Add("filterOns/phaseCenter/generateAngularResolutionTreePlots_*"); cSnrWais->Add("filterOns/phaseCenter/generateSignalToNoiseRatioTreePlots_*"); Double_t deltaPhiDegLdb = 0; cLdb->SetBranchAddress("deltaPhiDeg", &deltaPhiDegLdb); Double_t deltaThetaDegLdb = 0; cLdb->SetBranchAddress("deltaThetaDeg", &deltaThetaDegLdb); UInt_t eventNumber = 0; cLdb->SetBranchAddress("eventNumber", &eventNumber); Double_t phiExpected = 0; cLdb->SetBranchAddress("phiExpected", &phiExpected); Double_t snr0Ldb = 0; cSnrLdb->SetBranchAddress("snr0", &snr0Ldb); Long64_t nEntries = cSnrLdb->GetEntries(); Long64_t maxEntry = 0; //5; //1000; //10000; Long64_t startEntry = 0; if(maxEntry<=0 || maxEntry > nEntries) maxEntry = nEntries; std::cout << "Processing " << maxEntry << " of " << nEntries << " entries." << std::endl; ProgressBar p(maxEntry-startEntry); double dPhi = 0.05; double phiRange = 6; double dTheta = 0.05; double thetaRange = 6; double rebin = 2; const int nBinsPhi = 32; std::vector<double> theSnrBinsLdb = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 21};//, 22, 23, 24, 25}; TH2D* hSnrVsPhiExpectedLdb = new TH2D("hSnrVsPhiExpectedLdb", "SNR vs. #phi_{LDB}; #phi_{LDB} (Degrees); SNR (no units); Events per bin", nBinsPhi, 0, 360, theSnrBinsLdb.size()-1, &theSnrBinsLdb[0]); TH1D* hDeltaPhiLdb = new TH1D("hDeltaPhiLdb", "#delta#phi_{LDB}; #delta#phi (Degrees); Events per bin", phiRange/(dPhi*rebin), -phiRange/2 - dPhi/2, phiRange/2 - dPhi/2); // TH2D* hDeltaPhiLdb2 = new TH2D("hDeltaPhiLdb2", "#delta#phi_{LDB} vs. SNR; SNR (no units); #delta#phi (Degrees); Events per bin", nBinsSnr, minSnr, maxSnr, phiRange/dPhi, -phiRange/2 - dPhi/2, phiRange/2 - dPhi/2); TH2D* hDeltaPhiLdb2 = new TH2D("hDeltaPhiLdb2", "#delta#phi_{LDB} vs. SNR; SNR (no units); #delta#phi (Degrees); Events per bin", theSnrBinsLdb.size()-1, &theSnrBinsLdb[0], phiRange/dPhi, -phiRange/2 - dPhi/2, phiRange/2 - dPhi/2); TH1D* hDeltaThetaLdb = new TH1D("hDeltaThetaLdb", "#delta#theta_{LDB}; #delta#theta (Degrees); Events per bin", thetaRange/dTheta, -thetaRange/2 - dTheta/2, thetaRange/2 - dTheta/2); // TH2D* hDeltaThetaLdb2 = new TH2D("hDeltaThetaLdb2", "#delta#theta_{LDB} vs. SNR; SNR (no units); #delta#theta (Degrees); Events per bin", nBinsSnr, minSnr, maxSnr, thetaRange/dTheta, -thetaRange/2 - dTheta/2, thetaRange/2 - dTheta/2); TH2D* hDeltaThetaLdb2 = new TH2D("hDeltaThetaLdb2", "#delta#theta_{LDB} vs. SNR; SNR (no units); #delta#theta (Degrees); Events per bin", theSnrBinsLdb.size()-1, &theSnrBinsLdb[0], thetaRange/dTheta, -thetaRange/2 - dTheta/2, thetaRange/2 - dTheta/2); double lowestSnr = 9999; double highestSnr = -9999; UInt_t lowEventNumber; UInt_t highEventNumber; const double phiCut = 3; for(Long64_t entry = startEntry; entry < maxEntry; entry++){ cLdb->GetEntry(entry); cSnrLdb->GetEntry(entry); // cLdbOff->GetEntry(entry); if(TMath::Abs(deltaPhiDegLdb) < phiCut){ hSnrVsPhiExpectedLdb->Fill(phiExpected, snr0Ldb); // if(snr0Ldb > 6){ hDeltaPhiLdb->Fill(deltaPhiDegLdb); hDeltaPhiLdb2->Fill(snr0Ldb, deltaPhiDegLdb); hDeltaThetaLdb->Fill(deltaThetaDegLdb); hDeltaThetaLdb2->Fill(snr0Ldb, deltaThetaDegLdb); // } if(snr0Ldb < lowestSnr){ lowestSnr = snr0Ldb; lowEventNumber = eventNumber; } if(snr0Ldb > highestSnr){ highestSnr = snr0Ldb; highEventNumber = eventNumber; } } p.inc(entry, maxEntry); } std::cout << "LDB: " << std::endl; std::cout << lowEventNumber << "\t" << lowestSnr << std::endl; std::cout << highEventNumber << "\t" << highestSnr << std::endl; auto c0 = new TCanvas(); hSnrVsPhiExpectedLdb->Draw("colz"); TObjArray* tArrLdbPhi = new TObjArray(); hDeltaPhiLdb2->FitSlicesY(NULL, 1, hDeltaPhiLdb2->GetNbinsY(), 0, "QNR", tArrLdbPhi); TH1D* hResolutionVsSnrPhiLdb = NULL; for(int i=0; i < tArrLdbPhi->GetEntries(); i++){ auto h = (TH1D*)tArrLdbPhi->At(i); // auto c0 = new TCanvas(); // TString opt = i==0? "" : "same"; // h->Draw(opt); if(i==2){ hResolutionVsSnrPhiLdb = h; hResolutionVsSnrPhiLdb->SetTitle("VPOL #delta#phi_{LDB}"); } new TCanvas(); h->Draw(); } TObjArray* tArrLdbTheta = new TObjArray(); hDeltaThetaLdb2->FitSlicesY(NULL, 1, hDeltaThetaLdb2->GetNbinsY(), 0, "QNR", tArrLdbTheta); TH1D* hResolutionVsSnrThetaLdb = NULL; for(int i=0; i < tArrLdbTheta->GetEntries(); i++){ auto h = (TH1D*)tArrLdbTheta->At(i); // auto c0 = new TCanvas(); // TString opt = i==0? "" : "same"; // h->Draw(opt); if(i==2){ hResolutionVsSnrThetaLdb = h; hResolutionVsSnrThetaLdb->SetTitle("VPOL #delta#theta_{LDB}"); } new TCanvas(); h->Draw(); } Double_t deltaPhiDegWais = 0; cWais->SetBranchAddress("deltaPhiDeg", &deltaPhiDegWais); Double_t deltaThetaDegWais = 0; cWais->SetBranchAddress("deltaThetaDeg", &deltaThetaDegWais); phiExpected = 0; cWais->SetBranchAddress("phiExpected", &phiExpected); Double_t snr0Wais = 0; cSnrWais->SetBranchAddress("snr0", &snr0Wais); std::vector<double> theSnrBinsWais = {0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 18, 21};//, 22, 23, 24, 25}; TH2D* hSnrVsPhiExpectedWais = new TH2D("hSnrVsPhiExpectedWais", "SNR vs. #phi_{WAIS}; #phi_{WAIS} (Degrees); SNR (no units); Events per bin", nBinsPhi, 0, 360, theSnrBinsWais.size()-1, &theSnrBinsWais[0]); TH1D* hDeltaPhiWais = new TH1D("hDeltaPhiWais", "#delta#phi_{WAIS}; #delta#phi (Degrees); Events per bin", phiRange/(dPhi*rebin), -phiRange/2 - dPhi/2, phiRange/2 - dPhi/2); TH2D* hDeltaPhiWais2 = new TH2D("hDeltaPhiWais2", "#delta#phi_{WAIS} vs. SNR; SNR (no units); #delta#phi (Degrees); Events per bin", theSnrBinsWais.size()-1, &theSnrBinsWais[0], phiRange/dPhi, -phiRange/2 - dPhi/2, phiRange/2 - dPhi/2); TH1D* hDeltaThetaWais = new TH1D("hDeltaThetaWais", "#delta#theta_{WAIS}; #delta#theta (Degrees); Events per bin", thetaRange/dTheta, -thetaRange/2 - dTheta/2, thetaRange/2 - dTheta/2); TH2D* hDeltaThetaWais2 = new TH2D("hDeltaThetaWais2", "#delta#theta_{WAIS} vs. SNR; SNR (no units); #delta#theta (Degrees); Events per bin", theSnrBinsWais.size()-1, &theSnrBinsWais[0], thetaRange/dTheta, -thetaRange/2 - dTheta/2, thetaRange/2 - dTheta/2); Long64_t nEntries2 = cSnrWais->GetEntries(); Long64_t maxEntry2 = 0; //5; //1000; //10000; Long64_t startEntry2 = 0; if(maxEntry2<=0 || maxEntry2 > nEntries2) maxEntry2 = nEntries2; std::cout << "Processing " << maxEntry2 << " of " << nEntries2 << " entries." << std::endl; ProgressBar p2(maxEntry2-startEntry2); for(Long64_t entry = startEntry2; entry < maxEntry2; entry++){ cWais->GetEntry(entry); cSnrWais->GetEntry(entry); if(TMath::Abs(deltaPhiDegWais) < phiCut){ hSnrVsPhiExpectedWais->Fill(phiExpected, snr0Wais); hDeltaPhiWais->Fill(deltaPhiDegWais); hDeltaPhiWais2->Fill(snr0Wais, deltaPhiDegWais); hDeltaThetaWais->Fill(deltaThetaDegWais); hDeltaThetaWais2->Fill(snr0Wais, deltaThetaDegWais); } p2.inc(entry, maxEntry2); } TObjArray* tArrWaisPhi = new TObjArray(); hDeltaPhiWais2->FitSlicesY(NULL, 1, hDeltaPhiWais2->GetNbinsY(), 0, "QNR", tArrWaisPhi); TH1D* hResolutionVsSnrPhiWais = NULL; for(int i=0; i < tArrWaisPhi->GetEntries(); i++){ auto h = (TH1D*)tArrWaisPhi->At(i); // auto c0 = new TCanvas(); // TString opt = i==0? "" : "same"; // h->Draw(opt); if(i==2){ hResolutionVsSnrPhiWais = h; hResolutionVsSnrPhiWais->SetTitle("HPOL #delta#phi_{WAIS}"); } new TCanvas(); h->Draw(); } TObjArray* tArrWaisTheta = new TObjArray(); hDeltaThetaWais2->FitSlicesY(NULL, 1, hDeltaThetaWais2->GetNbinsY(), 0, "QNR", tArrWaisTheta); TH1D* hResolutionVsSnrThetaWais = NULL; for(int i=0; i < tArrWaisTheta->GetEntries(); i++){ auto h = (TH1D*)tArrWaisTheta->At(i); // auto c0 = new TCanvas(); // TString opt = i==0? "" : "same"; // h->Draw(opt); if(i==2){ hResolutionVsSnrThetaWais = h; hResolutionVsSnrThetaWais->SetTitle("HPOL #delta#theta_{WAIS}"); } new TCanvas(); h->Draw(); } auto c0a = new TCanvas(); hSnrVsPhiExpectedWais->Draw("colz"); return; auto c1 = new TCanvas(); hDeltaPhiWais2->Draw("colz"); auto c1a = new TCanvas(); hDeltaPhiLdb2->Draw("colz"); auto c2 = new TCanvas(); hDeltaThetaWais2->Draw("colz"); auto c2a = new TCanvas(); hDeltaThetaLdb2->Draw("colz"); // auto c3 = new TCanvas(); // // hResolutionVsSnrPhiLdb->SetLineColor(kRed); // // hResolutionVsSnrThetaLdb->SetLineColor(kBlue); // hResolutionVsSnrPhiLdb->Draw(); // hResolutionVsSnrThetaLdb->Draw("same"); // auto c3a = new TCanvas(); // // hResolutionVsSnrPhiWais->SetLineColor(kRed); // // hResolutionVsSnrThetaWais->SetLineColor(kBlue); // hResolutionVsSnrPhiWais->Draw(); // hResolutionVsSnrThetaWais->Draw("same"); auto c4 = new TCanvas(); hResolutionVsSnrPhiWais->SetLineColor(kRed); hResolutionVsSnrPhiLdb->SetLineColor(kBlue); hResolutionVsSnrThetaWais->SetLineColor(kMagenta); hResolutionVsSnrThetaLdb->SetLineColor(kCyan); hResolutionVsSnrPhiWais->SetMarkerSize(0); hResolutionVsSnrPhiLdb->SetMarkerSize(0); hResolutionVsSnrThetaWais->SetMarkerSize(0); hResolutionVsSnrThetaLdb->SetMarkerSize(0); hResolutionVsSnrPhiLdb->Draw(); hResolutionVsSnrThetaLdb->Draw("same"); hResolutionVsSnrPhiWais->Draw("same"); hResolutionVsSnrThetaWais->Draw("same"); auto l4 = c4->BuildLegend(); // l1->SetNColumns(2); l4->Draw(); // hs[0]->SetMaximum(0.13); hResolutionVsSnrPhiLdb->SetTitle("Angular Resolution vs. SNR; SNR; Angular Resolution (Degrees)"); hResolutionVsSnrPhiLdb->SetMaximum(1); hResolutionVsSnrPhiLdb->SetMinimum(0); //hDeltaPhiDegPhaseLdb->SetTitle("ANITA Angular Resolution Using Fitted Phase Centres; #delta#theta or #delta#phi (Degrees); Fraction of events per bin"); }
TH1F* Read_Tree(std::string runN, TH1F* h_variable, TString variable_name, int start_Event, int end_Event){ std::string inputFolder = "/store/group/upgrade/HGCAL/TimingTB_H2_Apr2016/recoTrees/"; TChain* tree = new TChain("H4treeReco"); tree->Add(("root://eoscms/"+inputFolder+"RECO_"+runN+".root").c_str()); Long64_t nentries = tree->GetEntries(); std::cout << " Tree loaded events = " << nentries << std::endl; double Lbound = start_Event; double Hbound = end_Event; if(end_Event == -1){Hbound = nentries;} int Nbins = Hbound - Lbound; TString h_name = "h_"+ variable_name + "_run_" + runN; h_variable = new TH1F(h_name, h_name, Nbins , Lbound ,Hbound ); //Tree variables UInt_t nwc; Float_t wc_recox[16], wc_recoy[16]; UInt_t maxch; Float_t group[100],ch[100]; Float_t pedestal[100], pedestalRMS[100], pedestalSlope[100]; Float_t wave_max[100], wave_max_aft[100], wave_aroundmax[100][50], time_aroundmax[100][50]; Float_t charge_integ[100], charge_integ_max[100], charge_integ_fix[100]; Float_t charge_integ_smallw[100], charge_integ_smallw_noise[100], charge_integ_largew[100], charge_integ_largew_noise[100]; Float_t t_max[100], t_max_frac30[100], t_max_frac50[100], t_at_threshold[100], t_over_threshold[100]; //Read tree tree->SetBranchAddress("nwc", &nwc); tree->SetBranchAddress("wc_recox", wc_recox); tree->SetBranchAddress("wc_recoy", wc_recoy); tree->SetBranchAddress("maxch", &maxch); tree->SetBranchAddress("group", group); tree->SetBranchAddress("ch", ch); tree->SetBranchAddress("pedestal", pedestal); tree->SetBranchAddress("pedestalRMS", pedestalRMS); tree->SetBranchAddress("pedestalSlope", pedestalSlope); tree->SetBranchAddress("wave_max", wave_max); tree->SetBranchAddress("wave_max_aft", wave_max_aft); tree->SetBranchAddress("wave_aroundmax", wave_aroundmax); tree->SetBranchAddress("time_aroundmax", time_aroundmax); tree->SetBranchAddress("charge_integ", charge_integ); tree->SetBranchAddress("charge_integ_max", charge_integ_max); tree->SetBranchAddress("charge_integ_fix", charge_integ_fix); tree->SetBranchAddress("charge_integ_smallw", charge_integ_smallw); tree->SetBranchAddress("charge_integ_largew", charge_integ_largew); tree->SetBranchAddress("charge_integ_smallw_noise", charge_integ_smallw_noise); tree->SetBranchAddress("charge_integ_largew_noise", charge_integ_largew_noise); tree->SetBranchAddress("t_max", t_max); tree->SetBranchAddress("t_max_frac30", t_max_frac30); tree->SetBranchAddress("t_max_frac50", t_max_frac50); tree->SetBranchAddress("t_at_threshold", t_at_threshold); tree->SetBranchAddress("t_over_threshold", t_over_threshold); // before loop //loop over entries for (Long64_t jentry=0; jentry<nentries; ++jentry){ if(jentry < Lbound )continue; if(jentry > Hbound )break; if (jentry % 5000 == 0) fprintf(stderr, "Processing event %lli of %lli\n", jentry + 1, nentries ); //readout the event tree->GetEntry(jentry); if( variable_name == "Pedestal") { int bin_index = jentry - start_Event+1; h_variable->SetBinContent( bin_index ,pedestal[4] ); h_variable->SetBinError ( bin_index ,pedestalRMS[4] ); } // if(jentry==0)cout<<"jentry=0, pedestal[4] :"<< pedestal[4] << endl; // if(jentry==1)cout<<"jentry=1, pedestal[4] :"<< pedestal[4] << endl; // if(jentry==2)cout<<"jentry=2, pedestal[4] :"<< pedestal[4] << endl; }// end event loop return h_variable; }
void nuint09_qel2(int isample, int include_fsi=0) { cout << " ***** running: QEL.2" << endl; if(include_fsi==0) { cout << "-FSI" << endl; } else if(include_fsi==1) { cout << "+FSI" << endl; } else return; if(isample<0 || isample >= kNSamples) return; const char * label = kLabel[isample]; int A = kA[isample]; int Z = kZ[isample]; int N = A-Z; // get cross section graphs TFile fsig("../sig/splines.root","read"); TDirectory * sig_dir = (TDirectory *) fsig.Get(label); TGraph * sig_graph_qelcc = (TGraph*) sig_dir->Get("qel_cc_n"); // range & spacing const int nKEp = 60; const double KEpmin = 0.01; const double KEpmax = 1.50; // create output stream ostringstream out_filename; if(include_fsi==0) { out_filename << label << ".qel_2.dsig_dKEp.data"; } else { out_filename << label << ".qel_2.dsig_dKEp_withFSI.data"; } ofstream out_stream(out_filename.str().c_str(), ios::out); // write out txt file out_stream << "# [" << label << "]" << endl; out_stream << "# " << endl; out_stream << "# [QEL.2]:" << endl; out_stream << "# Cross section as a function of f/s proton kinetic energy at E_nu= 0.5, 1.0 GeV." << endl; out_stream << "# " << endl; out_stream << "# Note:" << endl; if(include_fsi==1) { out_stream << "# - INCLUDING FSI " << endl; } out_stream << "# - proton energies are _kinetic_ energies " << endl; out_stream << "# - proton kinetic energy KE in GeV, between KEmin = " << KEpmin << " GeV, KEmax = " << KEpmax << " GeV " << endl; out_stream << "# - cross sections in 1E-38 cm^2 / GeV" << endl; out_stream << "# - quoted cross section is nuclear cross section per nucleon contributing in the scattering (eg only neutrons for nu_mu QELCC)" << endl; out_stream << "# Columns:" << endl; out_stream << "# | KE(p) | sig(QELCC; Ev=0.5GeV) | sig(QELCC; Ev=1.0GeV) | " << endl; out_stream << setiosflags(ios::fixed) << setprecision(6); // // load event data // TChain * chain = new TChain("gst"); // loop over CC/NC cases for(int iwkcur=0; iwkcur<kNWCur; iwkcur++) { // loop over energies for(int ie=0; ie<kNEnergies; ie++) { // loop over runs for current case for(int ir=0; ir<kNRunsPerCase; ir++) { // build filename ostringstream filename; int run_number = kRunNu[isample][iwkcur][ie][ir]; filename << "../gst/gntp." << run_number << ".gst.root"; // add to chain cout << "Adding " << filename.str() << " to event chain" << endl; chain->Add(filename.str().c_str()); } } } // // get QELCC cross sections at given energies for normalization purposes // double sig_qelcc_0500MeV = sig_graph_qelcc->Eval(0.5) / N; double sig_qelcc_1000MeV = sig_graph_qelcc->Eval(1.0) / N; // // book histograms // TH1D * hst_dsig_dKEp_qelcc_0500MeV = new TH1D("hst_dsig_dKEp_qelcc_0500MeV","dsig/dKEp, nu_mu QEL CC, Enu=0.5 GeV", nKEp, KEpmin, KEpmax); TH1D * hst_dsig_dKEp_qelcc_1000MeV = new TH1D("hst_dsig_dKEp_qelcc_1000MeV","dsig/dKEp, nu_mu QEL CC, Enu=1.0 GeV", nKEp, KEpmin, KEpmax); // // fill histograms // if(include_fsi==0) { chain->Draw("(Ei-0.938)>>hst_dsig_dKEp_qelcc_0500MeV","qel&&cc&&Ev>0.49&&Ev<0.51&&pdgi==2212","GOFF"); chain->Draw("(Ei-0.938)>>hst_dsig_dKEp_qelcc_1000MeV","qel&&cc&&Ev>0.99&&Ev<1.01&&pdgi==2212","GOFF"); } else { chain->Draw("(Ef-0.938)>>hst_dsig_dKEp_qelcc_0500MeV","qel&&cc&&Ev>0.49&&Ev<0.51&&pdgf==2212","GOFF"); chain->Draw("(Ef-0.938)>>hst_dsig_dKEp_qelcc_1000MeV","qel&&cc&&Ev>0.99&&Ev<1.01&&pdgf==2212","GOFF"); } // // normalize // double norm_qelcc_0500MeV = hst_dsig_dKEp_qelcc_0500MeV -> Integral("width") / sig_qelcc_0500MeV; double norm_qelcc_1000MeV = hst_dsig_dKEp_qelcc_1000MeV -> Integral("width") / sig_qelcc_1000MeV; if (norm_qelcc_0500MeV > 0) hst_dsig_dKEp_qelcc_0500MeV -> Scale(1./norm_qelcc_0500MeV); if (norm_qelcc_1000MeV > 0) hst_dsig_dKEp_qelcc_1000MeV -> Scale(1./norm_qelcc_1000MeV); for(int i = 1; i <= hst_dsig_dKEp_qelcc_1000MeV->GetNbinsX(); i++) { double KEp = hst_dsig_dKEp_qelcc_1000MeV->GetBinCenter(i); double dsig_dKEp_qelcc_0500MeV = hst_dsig_dKEp_qelcc_0500MeV -> GetBinContent(i); double dsig_dKEp_qelcc_1000MeV = hst_dsig_dKEp_qelcc_1000MeV -> GetBinContent(i); dsig_dKEp_qelcc_0500MeV = TMath::Max(0., dsig_dKEp_qelcc_0500MeV); dsig_dKEp_qelcc_1000MeV = TMath::Max(0., dsig_dKEp_qelcc_1000MeV); out_stream << setw(15) << KEp << setw(15) << dsig_dKEp_qelcc_0500MeV << setw(15) << dsig_dKEp_qelcc_1000MeV << endl; } out_stream.close(); delete chain; }
int main(int argc, char** argv) { //Chain TChain* chain = new TChain("MiBiCommonNTTwoPhotons/SimpleNtuple"); // Summer 12 DY sample chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_1_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_2_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_3_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_4_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_5_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_6_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_7_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_8_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_9_*.root"); chain->Add("root://eoscms//eos/cms/store/cmst3/user/malberti/HIGGS/VERTEX/2012/MC/DYJetsToLL_M-50_TuneZ2Star_8TeV-madgraph-tarball_Summer12-PU_S7_START52_V9-v2_AODSIM/MiBiCommonNT_1*_*.root"); treeReader reader((TTree*)(chain)); // histos TH1F *hgen = new TH1F("hgen","hgen",60,0,60); hgen -> GetXaxis()->SetTitle("N_{gen} + 1"); TH1F *hnpumc = new TH1F("hnpumc","hnpumc",60,0,60); hnpumc -> GetXaxis()->SetTitle("N_{gen}"); TH1F *htruenpumc = new TH1F("htruenpumc","htruenpumc",60,0,60); htruenpumc -> GetXaxis()->SetTitle("N_{gen}"); TH2F *hnvtxreco_vs_npugen = new TH2F("hnvtxreco_vs_npugen","hnvtxreco_vs_npugen",60,0,60,60,0,60); hnvtxreco_vs_npugen -> GetXaxis()->SetTitle("N_{gen} + 1"); hnvtxreco_vs_npugen -> GetYaxis()->SetTitle("N_{reco}"); TH2F *hnpugen_vs_nvtxreco = new TH2F("hnpugen_vs_nvtxreco","hnpugen_vs_nvtxreco",60,0,60,60,0,60); hnpugen_vs_nvtxreco -> GetXaxis()->SetTitle("N_{reco}"); hnpugen_vs_nvtxreco -> GetYaxis()->SetTitle("N_{gen} + 1"); int entryMax = reader.GetEntries(); std::cout<< "Total number of entries : " << entryMax << std::endl; // estimate the response curve NPU vs NVXT for (int u = 0; u < entryMax; u++ ) { if(u%10000 == 0) std::cout<<"reading event "<< u <<std::endl; reader.GetEntry(u); std::vector<int>* mc_PUit_NumInteractions = reader.GetInt("mc_PUit_NumInteractions"); int npu = mc_PUit_NumInteractions->at(0); std::vector<float>* mc_PUit_TrueNumInteractions = reader.GetFloat("mc_PUit_TrueNumInteractions"); int truenpu = mc_PUit_TrueNumInteractions->at(0); std::vector<float>* PV_z = reader.GetFloat("PV_z"); int nvtx = PV_z->size(); // number of sim PU vtx hgen->Fill(npu+1); hnpumc->Fill(npu); htruenpumc->Fill(truenpu); hnvtxreco_vs_npugen -> Fill(npu+1,nvtx); hnpugen_vs_nvtxreco -> Fill(nvtx,npu+1); } TFile ff("weights/HistosForPUReweighting_DYJetsToLL_Summer12_S9-v2.root","recreate"); hgen->Write(); hnpumc->Write(); htruenpumc->Write(); hnvtxreco_vs_npugen -> Write(); hnpugen_vs_nvtxreco -> Write(); ff.Close(); return 0; }
void PhxTagDebug(const int MinNjet15=1, const int iPhoType=0, const int debug = 100) { std::cout << "*************************************************************" << std::endl; std::cout << "******** Input parameters for " << __FUNCTION__ << "*********" << std::endl; std::cout << "******** MinNjet15 = " << MinNjet15 << std::endl; std::cout << "******** iPhoType = " << iPhoType << std::endl; std::cout << "******** debug = " << debug << std::endl; std::cout << "*************************************************************" << std::endl; assert (MinNjet15 >= 0 && "MinNjet Cannot be less than 0"); gROOT->ProcessLine(".!date"); gBenchmark->Start("metphoana_time"); TStnAna* ap = NULL; TChain* chain = new TChain("STNTUPLE"); chain->Add("/data/nbay02/b/samantha/STNTUPLES/MC/Pho/pd02b4da.0001exo8"); ap = new TStnAna(chain); /******************************************************/ // define all module here /******************************************************/ bool bSummaryStat = 0; // 1 = no summary //PassFailTree *passFailFile = new PassFailTree; BadPointerChecker *ptChecker = new BadPointerChecker; Filter10 *f10 = new Filter10; TriggerModule* trigMod; trigMod = new TriggerModule; trigMod->SetGoodRunListFile("goodrun_v23_pho_00.txt"); // to p13 trigMod->SetGoodRunBit(1); //1= use good run, 0=do not use it trigMod->SetTriggerBit(1); // 1= require tigger, 0=NO (for MC) trigMod->SetMinVtx(1); trigMod->SetUseVtxZcut(1); //1= require z<60 0=not cut on z trigMod->SetMaxVtx(1000); trigMod->SetSummaryStat(bSummaryStat); //enable/disable endjob summary InitSuperPhotons* myinit = new InitSuperPhotons; myinit->SetSummaryStat(bSummaryStat); //enable/disable endjob summary TagTightPhotons* tagTight = new TagTightPhotons; tagTight->SetSummaryStat(bSummaryStat); //enable/disable endjob summary tagTight->SetDebug(0); TagLoosePhotons* tagLoose = new TagLoosePhotons; tagLoose->SetSummaryStat(bSummaryStat); //enable/disable endjob summary TagElectrons* tagTightEle = new TagElectrons; tagTightEle->SetSummaryStat(bSummaryStat); //enable/disable endjob summary TagLooseElectrons* tagLooseEle = new TagLooseElectrons; tagLooseEle->SetSummaryStat(bSummaryStat); //enable/disable endjob summary PhoEleFilter *peFilter = new PhoEleFilter; peFilter->SetSummaryStat(bSummaryStat); //enable/disable endjob summary int AnalysisMode=2; JetFilterModuleV2 *jf = new JetFilterModuleV2(); //---------- My Vertex Filter Initialization jf->SetDebug(0); jf->SetMinNjet15(MinNjet15); //Jets required to pass (Et>15GeV) jf->SetAnalysisMode(AnalysisMode); TagPMTSpikes* tagPMT = new TagPMTSpikes; tagPMT->SetMode(1); //1= pass only if no spikes found tagPMT->SetSummaryStat(bSummaryStat); //enable/disable endjob summary TagBeamHalo* tagBH = new TagBeamHalo(); tagBH->SetSummaryStat(bSummaryStat); //enable/disable endjob summary TEmTimingModule* EmT = new TEmTimingModule(); SetEmTimes* setEmTime = new SetEmTimes; // set EM time of super photons setEmTime->SetEmTimeCorrectionFile("EmTCEMtable_p13.txt"); setEmTime->SetSummaryStat(bSummaryStat); //enable/disable endjob summary TagPhoenixPhotons* tagPhoenix = new TagPhoenixPhotons; tagPhoenix->SetSummaryStat(bSummaryStat); //enable/disable endjob summary TagConvElectrons* tagConvEle = new TagConvElectrons; tagConvEle->SetSummaryStat(bSummaryStat); //enable/disable endjob summary EventProperties * evtProp = new EventProperties; evtProp->SetSummaryStat(bSummaryStat); //enable/disable endjob summary Pho2JetsTemp *phoSel = new Pho2JetsTemp(); phoSel->SetPhoMinDetEta(0); phoSel->SetPhoMaxDetEta(0.95); phoSel->SetPhoMinEt(30.0); phoSel->SetHaloType(5); phoSel->SetPhotonType(iPhoType); //0=signal, 1=sideband phoSel->SetSummaryStat(bSummaryStat); //1=disable 0=enable endjob summary TPDFReweight *pdf_reweight_all = new TPDFReweight(); pdf_reweight_all->SetMCGenerator("Pythia"); pdf_reweight_all->SetReferencePDF(4,46); pdf_reweight_all->SetReweightedwithPDF("CTEQ6M"); ap->AddModule(trigMod,1); ap->AddModule(myinit,1); ap->AddModule(tagTight,1); ap->AddModule(tagLoose,1); ap->AddModule(tagTightEle,1); ap->AddModule(tagLooseEle,1); ap->AddModule(tagPhoenix,1); ap->AddModule(peFilter,1); ap->AddModule(tagPMT,1); ap->AddModule(tagBH,1); ap->AddModule(EmT,1); ap->AddModule(setEmTime,1); ap->AddModule(tagConvEle,1); //ap->AddModule(evtProp,1); ap->AddModule(pdf_reweight_all,1); ap->AddModule(jf,1); ap->AddModule(phoSel,1); //ap->AddModule(eleSel,1); if (debug) ap->Run(debug); else ap->Run(); std::stringstream filename; filename << "PhxDebug.root"; ap->SaveHist(filename.str().c_str(),2); std::cout << "/************* JOB SUMMARY ******************************/" <<std::endl; std::cout << "::::::::: Created ROOT file => "<< filename << std::endl; gBenchmark->Show("metphoana_time"); gROOT->ProcessLine(".!date"); std::cout << "/********************************************************/" <<std::endl; // gROOT->ProcessLine(".q"); }
void flux(const char *rootfilename, const char *outputfilename){ gStyle->SetMarkerStyle(20); TH1::SetDefaultSumw2(); TChain *C = new TChain("T"); C->Add(rootfilename); G4SBSRunData *rd; long ngen = 0; int nfiles = 0; TObjArray *FileList = C->GetListOfFiles(); TIter next(FileList); TChainElement *chEl = 0; set<TString> bad_file_list; while( (chEl=(TChainElement*)next() )){ TFile newfile(chEl->GetTitle()); newfile.GetObject("run_data",rd); if( rd ){ ngen += rd->fNtries; nfiles++; } else { bad_file_list.insert( chEl->GetTitle()); } //cout << chEl->GetTitle() << endl; } cout << "number of generated events = " << ngen << endl; C16_tree_with_flux *T = new C16_tree_with_flux(C); TFile *fout = new TFile(outputfilename,"RECREATE"); long nevent=0; double cutgamma = 0.05*1.e-3; //energy cutoff in GeV for photons double cutelectron = 5.e-3; //range cutoff in GeV for electrons: TH1D *hphoton_rate_vs_theta = new TH1D("hphoton_rate_vs_theta","",80,0.0,40.0); TH1D *helectron_rate_vs_theta = new TH1D("helectron_rate_vs_theta","",80,0.0,40.0); TH1D *hphoton_rate_vs_theta_Edep = new TH1D("hphoton_rate_vs_theta_Edep","",80,0.0,40.0); TH1D *helectron_rate_vs_theta_Edep = new TH1D("helectron_rate_vs_theta_Edep","",80,0.0,40.0); TH1D *hother_rate_vs_theta = new TH1D("hother_rate_vs_theta","",80,0.0,40.0); TH1D *hother_rate_vs_theta_Edep = new TH1D("hother_rate_vs_theta_Edep","",80,0.0,40.0); TH1D *htotal_rate_vs_theta = new TH1D("htotal_rate_vs_theta","",80,0.0,40.0); TH1D *htotal_rate_vs_theta_Edep = new TH1D("htotal_rate_vs_theta_Edep","",80,0.0,40.0); double PI = TMath::Pi(); double binwidth_theta = 40.0/80.0*PI/180.0; double Ibeam = 20e-6; double e = 1.602e-19; while( T->GetEntry( nevent++ ) ){ TFile *f = ( (TChain*) (T->fChain) )->GetFile(); TString fname = f->GetName(); if( bad_file_list.find( fname ) == bad_file_list.end() ){ if( nevent%1000 == 0 ) { cout << nevent << endl; cout << "Current file = " << f->GetName() << endl; } for( int part=0; part<T->FLUX_npart_CAL; part++ ){ double E = (*(T->FLUX_E))[part]; double px = (*(T->FLUX_px))[part]; double py = (*(T->FLUX_py))[part]; double pz = (*(T->FLUX_pz))[part]; double p = (*(T->FLUX_p))[part]; double theta = acos( pz/p ); double phi = atan2( py, px ); int bintheta = hphoton_rate_vs_theta->FindBin( theta * 180.0/PI ); double dcostheta = cos( PI/180.0*hphoton_rate_vs_theta->GetBinLowEdge(bintheta) ) - cos( PI/180.0*hphoton_rate_vs_theta->GetBinLowEdge(bintheta+1) ); double dOmega = 2.0*PI *dcostheta; double weight = Ibeam/e/double(ngen)/dOmega; int pid = (*(T->FLUX_pid))[part]; htotal_rate_vs_theta->Fill( theta*180.0/PI, weight ); htotal_rate_vs_theta_Edep->Fill( theta*180.0/PI, weight*E ); if( pid == 22 && E >= cutgamma ){//photon hphoton_rate_vs_theta->Fill( theta*180.0/PI, weight ); hphoton_rate_vs_theta_Edep->Fill( theta*180.0/PI, weight*E ); } else if( fabs(pid) == 11 && E >= cutelectron ){ //e+/e- helectron_rate_vs_theta->Fill( theta*180.0/PI, weight ); helectron_rate_vs_theta_Edep->Fill( theta*180.0/PI, weight*E ); } else { //other hother_rate_vs_theta->Fill( theta*180.0/PI, weight ); hother_rate_vs_theta_Edep->Fill( theta*180.0/PI, weight*E ); } } } } hphoton_rate_vs_theta->GetXaxis()->SetTitle("#theta (#circ)"); hphoton_rate_vs_theta->GetYaxis()->SetTitle("#frac{dN_{#gamma}}{dt d#Omega} (Photons/s/sr)"); helectron_rate_vs_theta->GetXaxis()->SetTitle("#theta (#circ)"); helectron_rate_vs_theta->GetYaxis()->SetTitle("#frac{dN_{e}}{dt d#Omega} (Electrons/s/sr)"); hother_rate_vs_theta->GetXaxis()->SetTitle("#theta (#circ)"); hother_rate_vs_theta->GetYaxis()->SetTitle("#frac{dN_{other}}{dt d#Omega} (Particles/s/sr)"); htotal_rate_vs_theta->GetXaxis()->SetTitle("#theta (#circ)"); htotal_rate_vs_theta->GetYaxis()->SetTitle("#frac{dN_{total}}{dt d#Omega} (Particles/s/sr)"); hphoton_rate_vs_theta_Edep->GetXaxis()->SetTitle("#theta (#circ)"); hphoton_rate_vs_theta_Edep->GetYaxis()->SetTitle("#frac{dE}{dt d#Omega} (GeV/s/sr)"); helectron_rate_vs_theta_Edep->GetXaxis()->SetTitle("#theta (#circ)"); helectron_rate_vs_theta_Edep->GetYaxis()->SetTitle("#frac{dE}{dt d#Omega} (GeV/s/sr)"); hother_rate_vs_theta_Edep->GetXaxis()->SetTitle("#theta (#circ)"); hother_rate_vs_theta_Edep->GetYaxis()->SetTitle("#frac{dE}{dt d#Omega} (GeV/s/sr)"); htotal_rate_vs_theta_Edep->GetXaxis()->SetTitle("#theta (#circ)"); htotal_rate_vs_theta_Edep->GetYaxis()->SetTitle("#frac{dE}{dt d#Omega} (GeV/s/sr)"); fout->Write(); }
void checkTrkInputs( TString infrec="nt_djhp_HyUQ110v0_djcalo.root", TString infgen="nt_djhp_HyUQ110v0_djcalo_genp.root", TCut evtCut="cent<30") { //TH1::SetDefaultSumw2(); TChain * trec = new TChain("tjttrk"); trec->Add(infrec); setupAlias(trec); TChain * tgen = new TChain("tjttrk"); tgen->Add(infgen); cout << infrec << " cut " << TString(evtCut) << ": " << trec->GetEntries() << endl; cout << infgen << " cut " << TString(evtCut) << ": " << tgen->GetEntries() << endl; // Correction Histograms TFile * fTrkCorr = new TFile("djtrkhist_hydjetBassv2_djuq110.root"); TString corrModule = "hitrkEffAnalyzer"; TH2F * hrec = (TH2F*)fTrkCorr->Get(Form("%s/hrec",corrModule.Data())); TH1D * hrec_pt = (TH1D*)hrec->ProjectionY(); TH2F * hsim = (TH2F*)fTrkCorr->Get(Form("%s/hsim",corrModule.Data())); TH1D * hsim_pt = (TH1D*)hsim->ProjectionY(); // Frag Histograms //TH1D * hPPtRecRaw = new TH1D("hPPtRecRaw",";p_{T} (GeV/c); count;"); TH1D * hPPtRecRaw = (TH1D*)hrec_pt->Clone("hPPtRecRaw"); hPPtRecRaw->Reset(); TH1D * hPPtGen = (TH1D*)hrec_pt->Clone("hPPtGen"); hPPtGen->Reset(); trec->Project("hPPtRecRaw","ppt",""); tgen->Project("hPPtGen","ppt",""); TH1D * hRecSimRat_pt = (TH1D*)hrec_pt->Clone("hRecSimRat_pt"); hRecSimRat_pt->Sumw2(); hRecSimRat_pt->Divide(hrec_pt,hsim_pt); TH1D * hPPtRat = (TH1D*)hrec_pt->Clone("hPPtRat"); hPPtRat->Sumw2(); hPPtRat->Divide(hPPtRecRaw,hPPtGen); // Normalize normHist(hsim_pt,0,true,1); normHist(hrec_pt,0,true,1); normHist(hPPtGen,0,true,1); normHist(hPPtRecRaw,0,true,1); // Plot hsim_pt->SetAxisRange(0,100,"X"); hsim_pt->SetTitle(";p_{T} (GeV/c); count"); hRecSimRat_pt->SetTitle(";p_{T} (GeV/c); reco/gen ratio"); hsim_pt->SetLineColor(kRed); hPPtGen->SetMarkerColor(kRed); hPPtGen->SetLineColor(kRed); hRecSimRat_pt->SetAxisRange(0,100,"X"); hRecSimRat_pt->SetAxisRange(-0.2,1.2,"Y"); hRecSimRat_pt->SetLineColor(kRed); TCanvas *cRec = new TCanvas("cRec","Rec",500,900); cRec->Divide(1,2); cRec->cd(1); cRec->GetPad(1)->SetLogy(); hsim_pt->Draw("hist"); hPPtGen->Draw("sameE"); hrec_pt->Draw("hist same"); hPPtRecRaw->Draw("sameE"); cRec->cd(2); hRecSimRat_pt->Draw("hist"); hPPtRat->Draw("sameE"); // ==================== TLegend *leg = new TLegend(0.61,0.78,0.91,0.91); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextSize(0.035); }
//________________________________________________________________________________________ int main(int argc, char* argv[]) { // Default options bool isList = false; TString outputdir = "TempOutput/"; int verbose = 0; Long64_t maxEvents = -1; Int_t prescale = 0; // Parse options char ch; while ((ch = getopt(argc, argv, "d:v:n:p:lh?")) != -1 ) { switch (ch) { case 'd': outputdir = TString(optarg); break; case 'v': verbose = atoi(optarg); break; case 'n': maxEvents = atoi(optarg); break; case 'p': prescale = atoi(optarg); break; case 'l': isList = true; break; case '?': case 'h': usage(0); break; default: cerr << "*** Error: unknown option " << optarg << std::endl; usage(-1); } } argc -= optind; argv += optind; // Check arguments if( argc<1 ) { usage(-1); } TChain *theChain = new TChain("analyze/Analysis"); for(int i = 0; i < argc; i++){ if( !isList ){ theChain->Add(argv[i]); printf(" Adding file: %s\n",argv[i]); } else { TString rootFile; ifstream is(argv[i]); while(rootFile.ReadLine(is) && (!rootFile.IsNull())){ if(rootFile[0] == '#') continue; theChain->Add(rootFile); printf(" Adding file: %s\n", rootFile.Data()); } } } Long_t nentries = theChain->GetEntries(); if ( nentries<1 ) { cerr << "ERROR: Couldn't find any entry in files." << endl; cerr << " Check that files exist and URL is correct." << endl; cerr << " e.g.: dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/foo/foo.root" << endl; exit(-1); } cout << "--------------" << endl; cout << "OutputDir is: " << outputdir << endl; cout << "Verbose level is: " << verbose << endl; cout << "Number of events: " << nentries << endl; cout << "--------------" << endl; PhysQCAnalyzer *tA = new PhysQCAnalyzer(theChain); tA->SetOutputDir(outputdir); tA->SetVerbose(verbose); tA->BeginJob(); tA->Loop(maxEvents,prescale); tA->EndJob(); delete tA; return 0; }
// The actual job void backgroundFits_qqzz_1Dw(int channel, int sqrts) { TString schannel; if (channel == 1) schannel = "4mu"; else if (channel == 2) schannel = "4e"; else if (channel == 3) schannel = "2e2mu"; else cout << "Not a valid channel: " << schannel << endl; TString ssqrts = (long) sqrts + TString("TeV"); cout << "schannel = " << schannel << " sqrts = " << sqrts << endl; TString outfile = "CardFragments/qqzzBackgroundFit_" + ssqrts + "_" + schannel + ".txt"; ofstream of(outfile,ios_base::out); of << "### background functions ###" << endl; gSystem->AddIncludePath("-I$ROOFITSYS/include"); gROOT->ProcessLine(".L ../CreateDatacards/include/tdrstyle.cc"); setTDRStyle(false); gStyle->SetPadLeftMargin(0.16); TString filepath; if (sqrts==7) { filepath = filePath7TeV; } else if (sqrts==8) { filepath = filePath8TeV; } TChain* tree = new TChain("SelectedTree"); tree->Add( filepath+ "/" + (schannel=="2e2mu"?"2mu2e":schannel) + "/HZZ4lTree_ZZTo*.root"); RooRealVar* MC_weight = new RooRealVar("MC_weight","MC_weight",0.,2.) ; RooRealVar* ZZMass = new RooRealVar("ZZMass","ZZMass",100.,1000.); RooRealVar* ZZLD = new RooRealVar("ZZLD","ZZLD",0.,1.); char cut[10]; sprintf(cut,"ZZLD>0.5"); //RooDataSet* set = new RooDataSet("set","set",tree,RooArgSet(*ZZMass,*MC_weight,*ZZLD),cut,"MC_weight"); RooDataSet* set = new RooDataSet("set","set",tree,RooArgSet(*ZZMass,*MC_weight),0,"MC_weight"); double totalweight = 0.; double totalweight_z = 0.; for (int i=0 ; i<set->numEntries() ; i++) { //set->get(i) ; RooArgSet* row = set->get(i) ; //row->Print("v"); totalweight += set->weight(); if (row->getRealValue("ZZMass") < 200) totalweight_z += set->weight(); } cout << "nEntries: " << set->numEntries() << ", totalweight: " << totalweight << ", totalweight_z: " << totalweight_z << endl; gSystem->Load("libHiggsAnalysisCombinedLimit.so"); //// --------------------------------------- //Background RooRealVar CMS_qqzzbkg_a0("CMS_qqzzbkg_a0","CMS_qqzzbkg_a0",115.3,0.,200.); RooRealVar CMS_qqzzbkg_a1("CMS_qqzzbkg_a1","CMS_qqzzbkg_a1",21.96,0.,200.); RooRealVar CMS_qqzzbkg_a2("CMS_qqzzbkg_a2","CMS_qqzzbkg_a2",122.8,0.,200.); RooRealVar CMS_qqzzbkg_a3("CMS_qqzzbkg_a3","CMS_qqzzbkg_a3",0.03479,0.,1.); RooRealVar CMS_qqzzbkg_a4("CMS_qqzzbkg_a4","CMS_qqzzbkg_a4",185.5,0.,200.); RooRealVar CMS_qqzzbkg_a5("CMS_qqzzbkg_a5","CMS_qqzzbkg_a5",12.67,0.,200.); RooRealVar CMS_qqzzbkg_a6("CMS_qqzzbkg_a6","CMS_qqzzbkg_a6",34.81,0.,100.); RooRealVar CMS_qqzzbkg_a7("CMS_qqzzbkg_a7","CMS_qqzzbkg_a7",0.1393,0.,1.); RooRealVar CMS_qqzzbkg_a8("CMS_qqzzbkg_a8","CMS_qqzzbkg_a8",66.,0.,200.); RooRealVar CMS_qqzzbkg_a9("CMS_qqzzbkg_a9","CMS_qqzzbkg_a9",0.07191,0.,1.); RooRealVar CMS_qqzzbkg_a10("CMS_qqzzbkg_a10","CMS_qqzzbkg_a10",94.11,0.,200.); RooRealVar CMS_qqzzbkg_a11("CMS_qqzzbkg_a11","CMS_qqzzbkg_a11",-5.111,-100.,100.); RooRealVar CMS_qqzzbkg_a12("CMS_qqzzbkg_a12","CMS_qqzzbkg_a12",4834,0.,10000.); RooRealVar CMS_qqzzbkg_a13("CMS_qqzzbkg_a13","CMS_qqzzbkg_a13",0.2543,0.,1.); if (channel == 1){ ///* 4mu CMS_qqzzbkg_a0.setVal(103.854); CMS_qqzzbkg_a1.setVal(10.0718); CMS_qqzzbkg_a2.setVal(117.551); CMS_qqzzbkg_a3.setVal(0.0450287); CMS_qqzzbkg_a4.setVal(185.262); CMS_qqzzbkg_a5.setVal(7.99428); CMS_qqzzbkg_a6.setVal(39.7813); CMS_qqzzbkg_a7.setVal(0.0986891); CMS_qqzzbkg_a8.setVal(49.1325); CMS_qqzzbkg_a9.setVal(0.0389984); CMS_qqzzbkg_a10.setVal(98.6645); CMS_qqzzbkg_a11.setVal(-7.02043); CMS_qqzzbkg_a12.setVal(5694.66); CMS_qqzzbkg_a13.setVal(0.0774525); //*/ } else if (channel == 2){ ///* 4e CMS_qqzzbkg_a0.setVal(111.165); CMS_qqzzbkg_a1.setVal(19.8178); CMS_qqzzbkg_a2.setVal(120.89); CMS_qqzzbkg_a3.setVal(0.0546639); CMS_qqzzbkg_a4.setVal(184.878); CMS_qqzzbkg_a5.setVal(11.7041); CMS_qqzzbkg_a6.setVal(33.2659); CMS_qqzzbkg_a7.setVal(0.140858); CMS_qqzzbkg_a8.setVal(56.1226); CMS_qqzzbkg_a9.setVal(0.0957699); CMS_qqzzbkg_a10.setVal(98.3662); CMS_qqzzbkg_a11.setVal(-6.98701); CMS_qqzzbkg_a12.setVal(10.0536); CMS_qqzzbkg_a13.setVal(0.110576); //*/ } else if (channel == 3){ ///* 2e2mu CMS_qqzzbkg_a0.setVal(110.293); CMS_qqzzbkg_a1.setVal(11.8334); CMS_qqzzbkg_a2.setVal(116.91); CMS_qqzzbkg_a3.setVal(0.0433151); CMS_qqzzbkg_a4.setVal(185.817); CMS_qqzzbkg_a5.setVal(10.5945); CMS_qqzzbkg_a6.setVal(29.6208); CMS_qqzzbkg_a7.setVal(0.0826); CMS_qqzzbkg_a8.setVal(53.1346); CMS_qqzzbkg_a9.setVal(0.0882081); CMS_qqzzbkg_a10.setVal(85.3776); CMS_qqzzbkg_a11.setVal(-13.3836); CMS_qqzzbkg_a12.setVal(7587.95); CMS_qqzzbkg_a13.setVal(0.325621); //*/ } else { cout << "disaster" << endl; } RooqqZZPdf_v2* bkg_qqzz = new RooqqZZPdf_v2("bkg_qqzz","bkg_qqzz",*ZZMass, CMS_qqzzbkg_a0,CMS_qqzzbkg_a1,CMS_qqzzbkg_a2,CMS_qqzzbkg_a3,CMS_qqzzbkg_a4, CMS_qqzzbkg_a5,CMS_qqzzbkg_a6,CMS_qqzzbkg_a7,CMS_qqzzbkg_a8, CMS_qqzzbkg_a9,CMS_qqzzbkg_a10,CMS_qqzzbkg_a11,CMS_qqzzbkg_a12,CMS_qqzzbkg_a13); RooArgSet myASet(*ZZMass, CMS_qqzzbkg_a0,CMS_qqzzbkg_a1,CMS_qqzzbkg_a2,CMS_qqzzbkg_a3,CMS_qqzzbkg_a4, CMS_qqzzbkg_a5,CMS_qqzzbkg_a6,CMS_qqzzbkg_a7); myASet.add(CMS_qqzzbkg_a8); myASet.add(CMS_qqzzbkg_a9); myASet.add(CMS_qqzzbkg_a10); myASet.add(CMS_qqzzbkg_a11); myASet.add(CMS_qqzzbkg_a12); myASet.add(CMS_qqzzbkg_a13); RooFitResult *r1 = bkg_qqzz->fitTo( *set, Save(kTRUE), SumW2Error(kTRUE) );//, Save(kTRUE), SumW2Error(kTRUE)) ; cout << endl; cout << "------- Parameters for " << schannel << " sqrts=" << sqrts << endl; cout << " a0_bkgd = " << CMS_qqzzbkg_a0.getVal() << endl; cout << " a1_bkgd = " << CMS_qqzzbkg_a1.getVal() << endl; cout << " a2_bkgd = " << CMS_qqzzbkg_a2.getVal() << endl; cout << " a3_bkgd = " << CMS_qqzzbkg_a3.getVal() << endl; cout << " a4_bkgd = " << CMS_qqzzbkg_a4.getVal() << endl; cout << " a5_bkgd = " << CMS_qqzzbkg_a5.getVal() << endl; cout << " a6_bkgd = " << CMS_qqzzbkg_a6.getVal() << endl; cout << " a7_bkgd = " << CMS_qqzzbkg_a7.getVal() << endl; cout << " a8_bkgd = " << CMS_qqzzbkg_a8.getVal() << endl; cout << " a9_bkgd = " << CMS_qqzzbkg_a9.getVal() << endl; cout << " a10_bkgd = " << CMS_qqzzbkg_a10.getVal() << endl; cout << " a11_bkgd = " << CMS_qqzzbkg_a11.getVal() << endl; cout << " a12_bkgd = " << CMS_qqzzbkg_a12.getVal() << endl; cout << " a13_bkgd = " << CMS_qqzzbkg_a13.getVal() << endl; cout << "}" << endl; cout << "---------------------------" << endl; of << "qqZZshape a0_bkgd " << CMS_qqzzbkg_a0.getVal() << endl; of << "qqZZshape a1_bkgd " << CMS_qqzzbkg_a1.getVal() << endl; of << "qqZZshape a2_bkgd " << CMS_qqzzbkg_a2.getVal() << endl; of << "qqZZshape a3_bkgd " << CMS_qqzzbkg_a3.getVal() << endl; of << "qqZZshape a4_bkgd " << CMS_qqzzbkg_a4.getVal() << endl; of << "qqZZshape a5_bkgd " << CMS_qqzzbkg_a5.getVal() << endl; of << "qqZZshape a6_bkgd " << CMS_qqzzbkg_a6.getVal() << endl; of << "qqZZshape a7_bkgd " << CMS_qqzzbkg_a7.getVal() << endl; of << "qqZZshape a8_bkgd " << CMS_qqzzbkg_a8.getVal() << endl; of << "qqZZshape a9_bkgd " << CMS_qqzzbkg_a9.getVal() << endl; of << "qqZZshape a10_bkgd " << CMS_qqzzbkg_a10.getVal() << endl; of << "qqZZshape a11_bkgd " << CMS_qqzzbkg_a11.getVal() << endl; of << "qqZZshape a12_bkgd " << CMS_qqzzbkg_a12.getVal() << endl; of << "qqZZshape a13_bkgd " << CMS_qqzzbkg_a13.getVal() << endl; of << endl << endl; of.close(); cout << endl << "Output written to: " << outfile << endl; double qqzznorm; if (channel == 1) qqzznorm = 20.5836; else if (channel == 2) qqzznorm = 13.8871; else if (channel == 3) qqzznorm = 32.9883; else { cout << "disaster!" << endl; } ZZMass->setRange("fullrange",100.,1000.); ZZMass->setRange("largerange",100.,600.); ZZMass->setRange("zoomrange",100.,200.); double rescale = qqzznorm/totalweight; double rescale_z = qqzznorm/totalweight_z; cout << "rescale: " << rescale << ", rescale_z: " << rescale_z << endl; // Plot m4l and RooPlot* frameM4l = ZZMass->frame(Title("M4L"),Range(100,600),Bins(250)) ; set->plotOn(frameM4l, MarkerStyle(20), Rescale(rescale)) ; //set->plotOn(frameM4l) ; RooPlot* frameM4lz = ZZMass->frame(Title("M4L"),Range(100,200),Bins(100)) ; set->plotOn(frameM4lz, MarkerStyle(20), Rescale(rescale)) ; int iLineColor = 1; string lab = "blah"; if (channel == 1) { iLineColor = 2; lab = "4#mu"; } if (channel == 3) { iLineColor = 4; lab = "2e2#mu"; } if (channel == 2) { iLineColor = 6; lab = "4e"; } bkg_qqzz->plotOn(frameM4l,LineColor(iLineColor),NormRange("largerange")) ; bkg_qqzz->plotOn(frameM4lz,LineColor(iLineColor),NormRange("zoomrange")) ; //second shape to compare with (if previous comparison code unceommented) //bkg_qqzz_bkgd->plotOn(frameM4l,LineColor(1),NormRange("largerange")) ; //bkg_qqzz_bkgd->plotOn(frameM4lz,LineColor(1),NormRange("zoomrange")) ; double normalizationBackground_qqzz = bkg_qqzz->createIntegral( RooArgSet(*ZZMass), Range("fullrange") )->getVal(); cout << "Norm all = " << normalizationBackground_qqzz << endl; frameM4l->GetXaxis()->SetTitle("m_{4l} [GeV]"); frameM4l->GetYaxis()->SetTitle("a.u."); frameM4lz->GetXaxis()->SetTitle("m_{4l} [GeV]"); frameM4lz->GetYaxis()->SetTitle("a.u."); char lname[192]; sprintf(lname,"qq #rightarrow ZZ #rightarrow %s", lab.c_str() ); char lname2[192]; sprintf(lname2,"Shape Model, %s", lab.c_str() ); // dummy! TF1* dummyF = new TF1("dummyF","1",0.,1.); TH1F* dummyH = new TH1F("dummyH","",1, 0.,1.); dummyF->SetLineColor( iLineColor ); dummyF->SetLineWidth( 2 ); dummyH->SetLineColor( kBlue ); TLegend * box2 = new TLegend(0.4,0.70,0.80,0.90); box2->SetFillColor(0); box2->SetBorderSize(0); box2->AddEntry(dummyH,"Simulation (POWHEG+Pythia) ","pe"); box2->AddEntry(dummyH,lname,""); box2->AddEntry(dummyH,"",""); box2->AddEntry(dummyF,lname2,"l"); TPaveText *pt = new TPaveText(0.15,0.955,0.4,0.99,"NDC"); pt->SetFillColor(0); pt->SetBorderSize(0); pt->AddText("CMS Preliminary 2012"); TPaveText *pt2 = new TPaveText(0.84,0.955,0.99,0.99,"NDC"); pt2->SetFillColor(0); pt2->SetBorderSize(0); pt2->AddText("#sqrt{s} = 7 TeV"); TCanvas *c = new TCanvas("c","c",800,600); c->cd(); frameM4l->Draw(); frameM4l->GetYaxis()->SetRangeUser(0,0.4); if(channel == 3)frameM4l->GetYaxis()->SetRangeUser(0,0.6); box2->Draw(); pt->Draw(); pt2->Draw(); TString outputPath = "bkgFigs"; outputPath = outputPath+ (long) sqrts + "TeV/"; outputName = outputPath + "bkgqqzz_" + schannel; c->SaveAs(outputName + ".eps"); c->SaveAs(outputName + ".png"); TCanvas *c2 = new TCanvas("c2","c2",1000,500); c2->Divide(2,1); c2->cd(1); frameM4l->Draw(); box2->Draw("same"); c2->cd(2); frameM4lz->Draw(); box2->Draw("same"); outputName = outputPath + "bkgqqzz_" + schannel + "_z"; c2->SaveAs(outputName + ".eps"); c2->SaveAs(outputName + ".png"); /* TO make the ratio btw 2 shapes, if needed for compairson TCanvas *c3 = new TCanvas("c3","c3",1000,500); if(sqrts==7) sprintf(outputName, "bkgFigs7TeV/bkgqqzz_%s_ratio.eps",schannel.c_str()); else if(sqrts==8) sprintf(outputName, "bkgFigs8TeV/bkgqqzz_%s_ratio.eps",schannel.c_str()); const int nPoints = 501.; double masses[nPoints] ; int j=0; for (int i=100; i<601; i++){ masses[j] = i; j++; } cout<<j<<endl; double effDiff[nPoints]; for (int i = 0; i < nPoints; i++){ ZZMass->setVal(masses[i]); double eval = (bkg_qqzz_bkgd->getVal(otherASet)-bkg_qqzz->getVal(myASet))/(bkg_qqzz->getVal(myASet)); //cout<<bkg_qqzz_bkgd->getVal(otherASet)<<" "<<bkg_qqzz->getVal(myASet)<<" "<<eval<<endl; effDiff[i]=eval; } TGraph* grEffDiff = new TGraph( nPoints, masses, effDiff ); grEffDiff->SetMarkerStyle(20); grEffDiff->Draw("AL"); //c3->SaveAs(outputName); */ outputName = outputPath + "bkgqqzz_" + schannel + "_z.root"; TFile* outF = new TFile(outputName,"RECREATE"); outF->cd(); c2->Write(); frameM4l->Write(); frameM4lz->Write(); outF->Close(); delete c; delete c2; }
void makeMETPlots( bool printplot = false ){ gStyle->SetOptFit(0); TChain *ch = new TChain("T1"); ch->Add("../../output/V00-02-21/wz_summer11_madgraph_gen_baby.root"); vector<TCut> metcuts; vector<float> metcutvals; metcuts.push_back(TCut("pfmet>100")); metcutvals.push_back(100); metcuts.push_back(TCut("pfmet>200")); metcutvals.push_back(200); metcuts.push_back(TCut("pfmet>300")); metcutvals.push_back(300); TCut sel("dilmass>81&&dilmass<101&&njets>=2"); const unsigned int n = metcuts.size(); TH1F* hpass[n]; TH1F* hall[n]; for( unsigned int i = 0 ; i < metcuts.size() ; ++i){ hpass[i] = new TH1F(Form("hpass_%i",i),Form("hpass_%i",i),30,0,600); hall[i] = new TH1F(Form("hall_%i",i), Form("hall_%i",i) ,30,0,600); ch->Draw(Form("genmet>>hpass_%i",i),sel+metcuts.at(i)); ch->Draw(Form("genmet>>hall_%i",i) ,sel); } TCanvas *can = new TCanvas(); can->cd(); gPad->SetGridx(); gPad->SetGridy(); gPad->SetTopMargin(0.08); TGraphAsymmErrors* gr[n]; TLegend *leg = new TLegend(0.6,0.2,0.95,0.4); leg->SetFillColor(0); leg->SetBorderSize(1); leg->SetTextSize(0.035); TF1* erf[n]; for( unsigned int i = 0 ; i < metcuts.size() ; ++i){ //can[i] = new TCanvas(Form("can_%i",i),Form("can_%i",i),600,600); //can[i]->cd(); TF1* efunc = new TF1("efitf", fitf, 0, 600, 3); efunc->SetParameters(1, 100, 10); efunc->SetParNames("norm", "offset", "width"); erf[i] = new TF1("efitf", fitf, 0, 600, 3); erf[i]->SetParameters(1, 100, 10); erf[i]->SetParNames("norm", "offset", "width"); erf[i]->SetLineWidth(2); //erf[i]->FixParameter(0,1); //erf[i] = new TF1(Form("erf_%i",i),mfitf,0,400); //erf[i]->SetParameter(0,100*(i+1)); //erf[i]->SetParameter(1,10); gr[i] = new TGraphAsymmErrors(); if( i==0 ){ erf[i]->SetLineColor(1); } if( i==1 ){ gr[i]->SetLineColor(2); gr[i]->SetMarkerColor(2); gr[i]->SetMarkerStyle(21); erf[i]->SetLineColor(2); } if( i==2 ){ gr[i]->SetLineColor(4); gr[i]->SetMarkerColor(4); gr[i]->SetMarkerStyle(25); erf[i]->SetLineColor(4); } leg->AddEntry(gr[i],Form("E_{T}^{miss}>%.0f GeV",metcutvals.at(i)),"p"); gr[i]->GetXaxis()->SetTitle("generator-level E_{T}^{miss} (GeV)"); gr[i]->GetYaxis()->SetTitle("efficiency"); gr[i]->SetMaximum(1.05); gr[i]->BayesDivide(hpass[i],hall[i]); //gr[i]->Fit(efunc,"R"); gr[i]->Fit(erf[i],"R"); if( i==0 ) gr[i]->Draw("AP"); else gr[i]->Draw("sameP"); gr[i]->GetXaxis()->SetTitle("generator E_{T}^{miss} [GeV]"); gr[i]->GetYaxis()->SetTitle("efficiency"); //erf[i]->Draw("same"); } leg->Draw(); TLatex *t = new TLatex(); t->SetNDC(); t->SetTextSize(0.04); t->DrawLatex(0.28,0.95,"CMS Simulation, #sqrt{s} = 7 TeV"); if (printplot) can->Print("../plots/met_turnon_LM4.pdf"); }
void closure_elefakepho(){//main float DYJet_XS = 5943.2; float DYJet_nevt = 28747969; float TT_XS = 670.3; float TT_nevt = 37459078; float WW_XS = 63.21; float WW_nevt = 993214; TChain *proxytree = new TChain("signalTree"); proxytree->Add("/uscms_data/d3/mengleis/SUSYAnalysisData/data/proxyTree_egMC.root"); const unsigned nEvts = proxytree->GetEntries(); std::ostringstream outputname; outputname << "closure_DYTT.root"; TFile *outputfile = TFile::Open(outputname.str().c_str(),"RECREATE"); outputfile->cd(); //************ Signal Tree **********************// float proxyphoEt(0); float proxyphoEta(0); float proxyphoPhi(0); float proxylepPt(0); float proxylepEta(0); float proxylepPhi(0); float proxysigMT(0); float proxysigMET(0); float proxysigMETPhi(0); float proxydPhiLepMET(0); int proxynVertex(0); float proxydRPhoLep(0); float proxyHT(0); float proxynJet(0); proxytree->SetBranchAddress("phoEt", &proxyphoEt); proxytree->SetBranchAddress("phoEta", &proxyphoEta); proxytree->SetBranchAddress("phoPhi", &proxyphoPhi); proxytree->SetBranchAddress("lepPt", &proxylepPt); proxytree->SetBranchAddress("lepEta", &proxylepEta); proxytree->SetBranchAddress("lepPhi", &proxylepPhi); proxytree->SetBranchAddress("sigMT", &proxysigMT); proxytree->SetBranchAddress("sigMET", &proxysigMET); proxytree->SetBranchAddress("sigMETPhi", &proxysigMETPhi); proxytree->SetBranchAddress("dPhiLepMET",&proxydPhiLepMET); proxytree->SetBranchAddress("nVertex", &proxynVertex); proxytree->SetBranchAddress("dRPhoLep", &proxydRPhoLep); proxytree->SetBranchAddress("HT", &proxyHT); proxytree->SetBranchAddress("nJet", &proxynJet); TChain *proxymctree = new TChain("MCTree"); proxymctree->Add("/uscms_data/d3/mengleis/SUSYAnalysisData/data/proxyTree_egMC.root"); int proxymcType = 0; proxymctree->SetBranchAddress("mcType", &proxymcType); //*********** histo list **********************// TH1F *p_allPhoEt = new TH1F("p_allPhoEt","#gamma E_{T}; E_{T} (GeV)",500,0,1500); TH1F *p_allPhoEta = new TH1F("p_allPhoEta","#gamma #eta; #eta;",60,-3,3); TH1F *p_allMt = new TH1F("p_allMt","M_{T}; M_{T} (GeV);",200,0,400); TH1F *p_alldPhiEleMET = new TH1F("p_alldPhiEleMET","dPhiEleMET",70,-3.5,3.5); TH1F *p_elebkgPhoEt = new TH1F("p_elebkgPhoEt","#gamma E_{T}; E_{T} (GeV)",500,0,1500); TH1F *p_elebkgPhoEta = new TH1F("p_elebkgPhoEta","#gamma #eta; #eta;",60,-3,3); TH1F *p_elebkgMt = new TH1F("p_elebkgMt","M_{T}; M_{T} (GeV);",200,0,400); TH1F *p_eledPhiEleMET = new TH1F("p_eledPhiEleMET","dPhiEleMET",70,-3.5,3.5); TH1F *p_elebkgPhoEtTT = new TH1F("p_elebkgPhoEtTT","#gamma E_{T}; E_{T} (GeV)",500,0,1500); TH1F *p_elebkgPhoEtaTT = new TH1F("p_elebkgPhoEtaTT","#gamma #eta; #eta;",60,-3,3); TH1F *p_elebkgMtTT = new TH1F("p_elebkgMtTT","M_{T}; M_{T} (GeV);",200,0,400); TH1F *p_eledPhiEleMETTT = new TH1F("p_eledPhiEleMETTT","dPhiEleMET",70,-3.5,3.5); for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on entries proxytree->GetEntry(ievt); proxymctree->GetEntry(ievt); double eventweight = 1; if(proxymcType==1)eventweight = 100000.0*DYJet_XS/DYJet_nevt; else if(proxymcType==2)eventweight = 100000.0*TT_XS/TT_nevt; else if(proxymcType==4)eventweight = 100000.0*WW_XS/WW_nevt; double fakerate = pow(0.0293*proxyphoEt+3.37,-3.04); if(proxyphoEt>110.0)fakerate = 0.5*(fakerate + (243.047+48.3986)/(243.047+48.3986+39536.2+23002.2)); double w_ele = fakerate/(1-fakerate)*eventweight; float deltaPhi = proxylepPhi - proxysigMETPhi; if(fabs(deltaPhi) > TMath::Pi()){ if(deltaPhi > 0)deltaPhi = -1.0*(TMath::TwoPi() - fabs(deltaPhi)); else deltaPhi = TMath::TwoPi() - fabs(deltaPhi); } if(proxymcType==1){ p_elebkgPhoEt->Fill(proxyphoEt,w_ele); p_elebkgPhoEta->Fill(proxyphoEta, w_ele); p_elebkgMt->Fill(proxysigMT, w_ele); p_eledPhiEleMET->Fill(deltaPhi, w_ele); } else if(proxymcType==2 || proxymcType==4){ p_elebkgPhoEtTT->Fill(proxyphoEt,w_ele); p_elebkgPhoEtaTT->Fill(proxyphoEta, w_ele); p_elebkgMtTT->Fill(proxysigMT, w_ele); p_eledPhiEleMETTT->Fill(deltaPhi, w_ele); } } //************ Signal Tree **********************// TChain *sigtree = new TChain("signalTree"); sigtree->Add("/uscms_data/d3/mengleis/SUSYAnalysisData/data/resTree_egMC.root"); float sigphoEt(0); float sigphoEta(0); float sigphoPhi(0); float siglepPt(0); float siglepEta(0); float siglepPhi(0); float sigsigMT(0); float sigsigMET(0); float sigsigMETPhi(0); float sigdPhiLepMET(0); int signVertex(0); float sigdRPhoLep(0); float sigHT(0); float signJet(0); sigtree->SetBranchAddress("phoEt", &sigphoEt); sigtree->SetBranchAddress("phoEta", &sigphoEta); sigtree->SetBranchAddress("phoPhi", &sigphoPhi); sigtree->SetBranchAddress("lepPt", &siglepPt); sigtree->SetBranchAddress("lepEta", &siglepEta); sigtree->SetBranchAddress("lepPhi", &siglepPhi); sigtree->SetBranchAddress("sigMT", &sigsigMT); sigtree->SetBranchAddress("sigMET", &sigsigMET); sigtree->SetBranchAddress("sigMETPhi", &sigsigMETPhi); sigtree->SetBranchAddress("dPhiLepMET",&sigdPhiLepMET); sigtree->SetBranchAddress("nVertex", &signVertex); sigtree->SetBranchAddress("dRPhoLep", &sigdRPhoLep); sigtree->SetBranchAddress("HT", &sigHT); sigtree->SetBranchAddress("nJet", &signJet); TChain *mctree = new TChain("MCTree"); mctree->Add("/uscms_data/d3/mengleis/SUSYAnalysisData/data/resTree_egMC.root"); int mcType = 0; std::vector<int> *mcPID=0; std::vector<float> *mcEta=0; std::vector<float> *mcPhi=0; std::vector<float> *mcPt=0; std::vector<int> *mcMomPID=0; mctree->SetBranchAddress("mcType", &mcType); mctree->SetBranchAddress("mcPID", &mcPID); mctree->SetBranchAddress("mcEta", &mcEta); mctree->SetBranchAddress("mcPhi", &mcPhi); mctree->SetBranchAddress("mcPt", &mcPt); mctree->SetBranchAddress("mcMomPID", &mcMomPID); TH1F *p_dRMC = new TH1F("p_dRMC","p_dRMC",30,0,0.3); TH1F *p_dEMC = new TH1F("p_dEMC","p_dEMC",100,0,1); TH1F *p_nMatch = new TH1F("p_nMatch","p_nMatch",10,0,10); for (unsigned ievt(0); ievt<sigtree->GetEntries(); ++ievt){//loop on entries sigtree->GetEntry(ievt); mctree->GetEntry(ievt); double eventweight = 1; if(mcType==1)eventweight = 100000.0*DYJet_XS/DYJet_nevt; else if(mcType==2)eventweight = 100000.0*TT_XS/TT_nevt; else if(mcType==4)eventweight = 100000.0*WW_XS/WW_nevt; double mindR(0.3),deltaE(1); unsigned matchIndex(0); int nMatch(0); int nMatchPho(0); for(unsigned iMC(0); iMC < mcPID->size(); iMC++){ if((*mcPt)[iMC] < 10)continue; double dR = DeltaR((*mcEta)[iMC], (*mcPhi)[iMC], sigphoEta, sigphoPhi); double dE = fabs((*mcPt)[iMC] - sigphoEt)/sigphoEt; if(dR < mindR && dE < 0.5){mindR=dR; matchIndex=iMC;deltaE = dE;} } if(mindR < 0.15 && deltaE < 0.5){ if(((*mcPID)[matchIndex] == 11 || (*mcPID)[matchIndex] == -11)){ float deltaPhi = siglepPt - sigsigMETPhi; if(fabs(deltaPhi) > TMath::Pi()){ if(deltaPhi > 0)deltaPhi = -1.0*(TMath::TwoPi() - fabs(deltaPhi)); else deltaPhi = TMath::TwoPi() - fabs(deltaPhi); } p_allPhoEt->Fill(sigphoEt,eventweight); p_allPhoEta->Fill(sigphoEta, eventweight); p_allMt->Fill(sigsigMT, eventweight); p_alldPhiEleMET->Fill(deltaPhi, eventweight); } } } outputfile->Write(); gStyle->SetOptStat(0); Double_t plotPtBins[]={35,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,90,100,110,120,130,140,200}; TCanvas *c_pt = new TCanvas("Photon_Pt", "Photon P_{T}",600,600); c_pt->cd(); gPad->SetLogy(); TH1 *new_allPhoEt = p_allPhoEt->Rebin(2); TH1 *new_elebkgPhoEt = p_elebkgPhoEt->Rebin(2); TH1 *new_elebkgPhoEtTT = p_elebkgPhoEtTT->Rebin(2); new_allPhoEt->GetXaxis()->SetRangeUser(35,200); new_allPhoEt->Draw(); new_allPhoEt->SetLineColor(kBlack); new_allPhoEt->SetMarkerStyle(20); new_elebkgPhoEt->SetFillStyle(1001); new_elebkgPhoEt->SetLineColor(kRed); new_elebkgPhoEt->SetFillColor(kRed); new_elebkgPhoEt->Draw("hist same"); new_elebkgPhoEtTT->Add(new_elebkgPhoEt); new_elebkgPhoEtTT->SetLineColor(kGreen); new_elebkgPhoEtTT->SetFillStyle(1001); new_elebkgPhoEtTT->SetFillColor(kGreen); new_elebkgPhoEtTT->Draw("hist same"); new_elebkgPhoEt->Draw("hist same"); TLegend *leg = new TLegend(0.6,0.7,0.9,0.9); leg->SetFillStyle(0); gStyle->SetLegendBorderSize(1); gStyle->SetLegendFillColor(0); leg->AddEntry(new_allPhoEt,"observed"); leg->AddEntry(new_elebkgPhoEtTT,"EWK (tt, WW)"); leg->AddEntry(new_elebkgPhoEt,"DY"); leg->Draw("same"); new_allPhoEt->Draw("same"); c_pt->SaveAs("EfakePho_closure.pdf"); TCanvas *c_mt = new TCanvas("MT", "MT",600,600); c_mt->cd(); gPad->SetLogy(); TH1 *new_allMt = p_allMt->Rebin(2); TH1 *new_elebkgMt = p_elebkgMt->Rebin(2); TH1 *new_elebkgMtTT = p_elebkgMtTT->Rebin(2); new_allMt->GetXaxis()->SetRangeUser(35,200); new_allMt->Draw(); new_allMt->SetLineColor(kBlack); new_allMt->SetMarkerStyle(20); new_elebkgMt->SetFillStyle(1001); new_elebkgMt->SetLineColor(kRed); new_elebkgMt->SetFillColor(kRed); new_elebkgMt->Draw("hist same"); new_elebkgMtTT->Add(new_elebkgMt); new_elebkgMtTT->SetLineColor(kGreen); new_elebkgMtTT->SetFillStyle(1001); new_elebkgMtTT->SetFillColor(kGreen); new_elebkgMtTT->Draw("hist same"); new_elebkgMt->Draw("hist same"); TLegend *leg2 = new TLegend(0.6,0.7,0.9,0.9); leg2->SetFillStyle(0); gStyle->SetLegendBorderSize(1); gStyle->SetLegendFillColor(0); leg2->AddEntry(new_allMt,"observed"); leg2->AddEntry(new_elebkgMtTT,"EWK (tt, WW)"); leg2->AddEntry(new_elebkgMt,"DY"); leg2->Draw("same"); new_allMt->Draw("same"); c_mt->SaveAs("EfakeMT_closure.pdf"); }
TChain* CreateAODChain( const char* aDataDir = "AODfiles.txt", Int_t aRuns = 20, Int_t offset = 0, Bool_t addFileName = kFALSE, const char* friends = "", const char* check = 0) { // creates chain of files in a given directory or file containing a list. // In case of directory the structure is expected as: // <aDataDir>/<dir0>/AliAOD.root // <aDataDir>/<dir1>/AliAOD.root // ... // // if addFileName is true the list only needs to contain the directories that contain the AliAODs.root files // if check is != 0 the files that work are written back into the textfile with the name check if (!aDataDir) return 0; Long_t id, size, flags, modtime; if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime)) { printf("%s not found.\n", aDataDir); return 0; } TChain* chain = new TChain("aodTree"); TChain* chainFriend = 0; if (strcmp(friends, "") != 0) chainFriend = new TChain("aodTree"); if (flags & 2) { TString execDir(gSystem->pwd()); TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir); TList* dirList = baseDir->GetListOfFiles(); Int_t nDirs = dirList->GetEntries(); gSystem->cd(execDir); Int_t count = 0; for (Int_t iDir=0; iDir<nDirs; ++iDir) { TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir); if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0) continue; if (offset > 0) { --offset; continue; } if (count++ == aRuns) break; TString presentDirName(aDataDir); presentDirName += "/"; presentDirName += presentDir->GetName(); chain->Add(presentDirName + "/AliAOD.root/aodTree"); if (chainFriend) chainFriend->Add(presentDirName + "/" + friends + "/aodTree"); } } else { // Open the input stream ifstream in; in.open(aDataDir); ofstream outfile; if (check) outfile.open(check); Int_t count = 0; // Read the input list of files and add them to the chain TString line; while (in.good()) { in >> line; if (line.Length() == 0) continue; if (offset > 0) { offset--; continue; } if (count++ == aRuns) break; TString aodFile(line); if (line.EndsWith(".zip")) { aodFile += "#AliAOD.root"; } else if (addFileName) { aodFile += "/AliAOD.root"; } if (check) { TFile* file = TFile::Open(aodFile); if (!file) continue; file->Close(); outfile << line.Data() << endl; printf("%s\n", line.Data()); } // add aod file chain->Add(aodFile); if (chainFriend) { TString friendFileName(aodFile); friendFileName.ReplaceAll("AliAOD.root", friends); chainFriend->Add(friendFileName); } } in.close(); if (check) { outfile.close(); } } if (chainFriend) { chain->AddFriend(chainFriend); } return chain; }
//------------------------------------------------------------------- void Alignment_0(int cluster_length_leftCut = 2,int cluster_length_rightCut = 7,float TotSignal_Cut = 5){ gStyle->SetOptStat(11111111); gStyle->SetOptFit(111111111); //gAnaCombine->LinkBranches(); TH1D *h_ladder_stripID[5][2]; TH1D *h_Refer[5][2]; char name[80]; for(short lid =0;lid<5;++lid){ for(short sid=0;sid<2;++sid){ snprintf(name,80,"ladder_%d-side_%d",lid,sid); h_ladder_stripID[lid][sid] = new TH1D(name,name,500,0,1100); snprintf(name,80,"ladder_%d-side_%d VS ladder 0",lid,sid); h_Refer[lid][sid] = new TH1D(name,name,200,-200,200); } snprintf(name,80,"ladder_%d",lid); h_ladder_stripID[lid][0]->SetTitle(name); snprintf(name,80,"Seed Address ladder_%d",lid); h_Refer[lid][0]->SetTitle(name); } TChain *tree = gAnaCombine->GetTree(); long nEvt = tree->GetEntries(); for(long ievt=0;ievt<nEvt;++ievt){ tree->GetEntry(ievt); short nCluster = gAnaCombine->fEvtAMS->GetEntriesFast(); float Ref[2]={0.,0.}, RefSN[2]={0.,0.}; for(int iclu=0;iclu<nCluster;++iclu){ Cluster *acluster = (Cluster*)gAnaCombine->fEvtAMS->At(iclu); if(acluster->ladder !=0){ continue; } short length = acluster->length; int side = acluster->side; if(acluster->GetTotSN()>RefSN[side] && cluster_length_leftCut<=length && length<=cluster_length_rightCut && acluster->GetTotSig()>TotSignal_Cut){ Ref[side] = acluster->GetSeedAdd(); RefSN[side] = acluster->GetTotSN(); } } for(int iclu=0;iclu<nCluster;++iclu){ Cluster *acluster = (Cluster*)gAnaCombine->fEvtAMS->At(iclu); short length = acluster->length; if(length < cluster_length_leftCut || length>cluster_length_rightCut || acluster->GetTotSig()<TotSignal_Cut || acluster->GetTotSig()<TotSignal_Cut){ continue; } int ladder = acluster->ladder; if(ladder==5){ ladder = 2; }else if(ladder == 4){ ladder = 3; }else if(ladder == 3){ ladder = 4; } int side = acluster->side; h_ladder_stripID[ladder][side]->Fill(acluster->GetSeedAdd()); h_Refer[ladder][side]->Fill(acluster->GetSeedAdd()-Ref[side]); } } snprintf(name,80,"AMS Alignment_0_a: cluster length %d~%d, total signal cut %f",cluster_length_leftCut,cluster_length_rightCut,TotSignal_Cut); TCanvas *c1 = new TCanvas(name,name); c1->Divide(2,3); snprintf(name,80,"AMS Alignment_0_b: cluster length %d~%d, total signal cut %f",cluster_length_leftCut,cluster_length_rightCut,TotSignal_Cut); TCanvas *c2 = new TCanvas(name,name); c2->Divide(2,3); for(short lid=0;lid<5;++lid){ c1->cd(lid+1); h_ladder_stripID[lid][0]->Draw(); h_ladder_stripID[lid][1]->SetLineColor(6); h_ladder_stripID[lid][1]->Draw("same"); c2->cd(lid+1); h_Refer[lid][0]->Draw(); h_Refer[lid][1]->SetLineColor(6); h_Refer[lid][1]->Draw("same"); } }
void nuint09_1pi1(int isample, int single_pion_sources=0, int stage=1) { cout << " ***** running: 1PI.1" << endl; if(isample<0 || isample >= kNSamples) return; if(single_pion_sources<0 || single_pion_sources>2) return; const char * label = kLabel[isample]; int A = kA[isample]; // get cross section graphs TFile fsig("../sig/splines.root","read"); TDirectory * sig_dir = (TDirectory *) fsig.Get(label); TGraph * sig_graph_totcc = (TGraph*) sig_dir->Get("tot_cc"); // range & spacing const int nEnu = 60; const double Enumin = 0.05; const double Enumax = 30.00; // create output stream ostringstream out_filename; out_filename << label; if (single_pion_sources==0) out_filename << ".1pi_1a."; else if (single_pion_sources==1) out_filename << ".1pi_1b."; else if (single_pion_sources==2) out_filename << ".1pi_1c."; if(stage==0) out_filename << "no_FSI."; out_filename << "sig1pi_vs_Enu.data"; ofstream out_stream(out_filename.str().c_str(), ios::out); // write out txt file out_stream << "# [" << label << "]" << endl; out_stream << "# " << endl; out_stream << "# [1PI.1]:" << endl; out_stream << "# Total cross section for 1 pion (pi+ only) production as a function of energy" << endl; if(stage==0) { out_stream << "# ***** NO FSI: The {X pi+} state is a primary hadronic state" << endl; } if(single_pion_sources==0) { out_stream << "# 1pi sources: All" << endl; } else if(single_pion_sources==1) { out_stream << "# 1pi sources: P33(1232) resonance only" << endl; } else if(single_pion_sources==2) { out_stream << "# 1pi sources: All resonances only" << endl; } out_stream << "# " << endl; out_stream << "# Note:" << endl; out_stream << "# - neutrino energy E in GeV, linear spacing between Emin = " << Enumin << " GeV, Emax = " << Enumax << " GeV " << endl; out_stream << "# - cross sections in 1E-38 cm^2 " << endl; out_stream << "# - quoted cross section is nuclear cross section divided with number of nucleons A" << endl; out_stream << "# Columns:" << endl; out_stream << "# | Energy | sig(nu_mu + A -> mu- 1pi+ X) | " << endl; out_stream << setiosflags(ios::fixed) << setprecision(6); // // load event data // TChain * chain = new TChain("gst"); // loop over CC/NC cases for(int iwkcur=0; iwkcur<kNWCur; iwkcur++) { // loop over runs for current case for(int ir=0; ir<kNRunsPerCase; ir++) { // build filename ostringstream filename; int run_number = kRunNu1PI1[isample][iwkcur][ir]; cout << "isample = " << isample << ", iwkcur = " << iwkcur << ", ir = " << ir << ", run = " << run_number << endl; filename << "../gst/gntp." << run_number << ".gst.root"; // add to chain cout << "Adding " << filename.str() << " to event chain" << endl; chain->Add(filename.str().c_str()); } } // // book histograms // TH1D * hst_cc1pip = new TH1D("hst_cc1pip","CC1pi+ events, Enu spectrum", nEnu, Enumin, Enumax); TH1D * hst_allcc = new TH1D("hst_allcc", "all CC events, Enu spectrum", nEnu, Enumin, Enumax); // // fill histograms // chain->Draw("Ev>>hst_allcc", "cc","GOFF"); if(stage==1) { if(single_pion_sources==0) { //all sources chain->Draw("Ev>>hst_cc1pip","cc&&pdgf==211&&nfpip==1&&nfpim==0&&nfpi0==0","GOFF"); } else if(single_pion_sources==1) { //P33(1232) only chain->Draw("Ev>>hst_cc1pip","cc&&resid==0&&res&&pdgf==211&&nfpip==1&&nfpim==0&&nfpi0==0","GOFF"); } else if(single_pion_sources==2) { //all resonances only chain->Draw("Ev>>hst_cc1pip","cc&&res&&pdgf==211&&nfpip==1&&nfpim==0&&nfpi0==0","GOFF"); } } else if(stage==0) { if(single_pion_sources==0) { //all sources chain->Draw("Ev>>hst_cc1pip","cc&&pdgi==211&&nipip==1&&nipim==0&&nipi0==0","GOFF"); } else if(single_pion_sources==1) { //P33(1232) only chain->Draw("Ev>>hst_cc1pip","cc&&resid==0&&res&&pdgi==211&&nipip==1&&nipim==0&&nipi0==0","GOFF"); } else if(single_pion_sources==2) { //all resonances only chain->Draw("Ev>>hst_cc1pip","cc&&res&&pdgi==211&&nipip==1&&nipim==0&&nipi0==0","GOFF"); } } cout << "CC1pi+ nevents: " << hst_cc1pip->GetEntries() << endl; cout << "ALLCC nevents: " << hst_allcc->GetEntries() << endl; // // compute sig(CC1pi+) and write out in txt file expected by NuINT organizers // Also write out root graph in temp file to be re-used at later benchmarking calc // double e[nEnu], sig[nEnu]; for(int i=1; i <= hst_cc1pip->GetNbinsX(); i++) { double Enu = hst_cc1pip->GetBinCenter(i); double Ncc1pip = hst_cc1pip -> GetBinContent(i); double Nallcc = hst_allcc -> GetBinContent(i); double sig_cc1pip=0; if(Nallcc>0) { sig_cc1pip = (Ncc1pip/Nallcc) * sig_graph_totcc->Eval(Enu) / A; } out_stream << setw(15) << Enu << setw(15) << sig_cc1pip << endl; e [i-1] = Enu; sig[i-1] = sig_cc1pip; } out_stream.close(); TFile ftmp("./cc1pip_tmp.root","recreate"); TGraph * grCC1pip = new TGraph(nEnu,e,sig); grCC1pip->Write("CC1pip"); hst_allcc->Write(); hst_cc1pip->Write(); // visual inspection TCanvas * c1 = new TCanvas("c1","",20,20,500,500); grCC1pip->Draw("alp"); c1->Update(); ftmp.Close(); delete chain; }