Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:28:07

0001 #define NtupleHelper_cc
0002 #include "NtupleHelper.h"
0003 #include <TH2.h>
0004 #include <TStyle.h>
0005 #include <TCanvas.h>
0006 #include <TMath.h>
0007 
0008 ClassImp(NtupleHelper);
0009 
0010 void NtupleHelper::Book() {
0011   hvxy = new TH2F("vxy", "x vers. y vertex", 100, -0.01, 0.01, 100, -0.01, 0.01);
0012   hvxyz = new TH3F("vxyz", "x y z vertex", 100, -0.01, 0.01, 200, -40., 40., 100, -0.01, 0.01);
0013   hdphi = new TH2F("dphi", "d vers phi", 100, -0., 6.283, 100, -0.2, 0.2);
0014   hd = new TH2F("d", "d vers. z ", 100, -40., 40., 100, -0.01, 0.01);
0015   hvxz = new TH2F("vxz", "x vers. z vertex", 100, -40., 40., 100, -0.01, 0.01);
0016   hsigma = new TH1F("sigma", "sigma d ", 100, 0., 0.01);
0017   hsx = new TH1F("sx", "sigma vers. z", 50, -40., 40.);
0018   hpt = new TH1F("pt", "pt", 100, 0., 20.);
0019   hsx->Sumw2();
0020   hsd = new TH1F("sd", "d0 vers. z", 50, -40., 40.);
0021   hsd->Sumw2();
0022   hsw = new TH1F("sw", "sigma weight vers. z", 50, -40., 40.);
0023   hsw->Sumw2();
0024 }
0025 zData NtupleHelper::Loop(int maxEvents) {
0026   //   In a ROOT session, you can do:
0027   //      Root > .L NtupleHelper.C
0028   //      Root > NtupleHelper t
0029   //      Root > t.GetEntry(12); // Fill t data members with entry number 12
0030   //      Root > t.Show();       // Show values of entry 12
0031   //      Root > t.Show(16);     // Read and show values of entry 16
0032   //      Root > t.Loop();       // Loop on all entries
0033   //
0034 
0035   //     This is the loop skeleton where:
0036   //    jentry is the global entry number in the chain
0037   //    ientry is the entry number in the current Tree
0038   //  Note that the argument to GetEntry must be:
0039   //    jentry for TChain::GetEntry
0040   //    ientry for TTree::GetEntry and TBranch::GetEntry
0041   //
0042   //       To read only selected branches, Insert statements like:
0043   // METHOD1:
0044   //    fChain->SetBranchStatus("*",0);  // disable all branches
0045   //    fChain->SetBranchStatus("branchname",1);  // activate branchname
0046   // METHOD2: replace line
0047   //    fChain->GetEntry(jentry);       //read all branches
0048   //by  b_branchname->GetEntry(ientry); //read only this branch
0049   //   TH2F *hvxy = new TH2F("vxy","x vers. y vertex",100,-0.4,0.4,100,-0.4,0.4);
0050 
0051   std::cout << "  loop over entries" << std::endl;
0052   std::cout << "  maximum number of entries: " << maxEvents << std::endl;
0053   zData zvector;
0054   if (fChain == 0)
0055     return zvector;
0056   zvector.erase(zvector.begin(), zvector.end());
0057   Long64_t nentries = fChain->GetEntriesFast();
0058 
0059   std::cout << " total number of entries: " << fChain->GetEntries() << std::endl;
0060 
0061   Int_t nbytes = 0, nb = 0;
0062   int theevent = 0;
0063   for (Long64_t jentry = 0; jentry < nentries; jentry++) {
0064     Long64_t ientry = LoadTree(jentry);
0065     if (ientry < 0)
0066       break;
0067     nb = fChain->GetEntry(jentry);
0068     nbytes += nb;
0069     //      if (sigmaD <0.05&&pt>4.0)
0070     //  {
0071 
0072     //if (z0>-20. && z0<20. && pt>4 ) {
0073     //if (pt>2 ) {
0074     //if (pt>5 && sigmaD<0.02) { //it was pt>5
0075     if (true) {
0076       if (maxEvents > 0 && maxEvents == theevent) {
0077         std::cout << " reached maximum number of tracks, continue" << std::endl;
0078         break;
0079       }
0080       hvxy->Fill(x, y);
0081       hvxyz->Fill(x, z0, y);
0082       hdphi->Fill(phi, d0);
0083       hvxz->Fill(z0, x);
0084       hsd->Fill(z0, fabs(d0));
0085       hd->Fill(z0, d0);
0086       hsx->Fill(z0, fabs(x));
0087       hpt->Fill(pt, 1.0);
0088       hsw->Fill(z0, 1.0);
0089       hsigma->Fill(sigmaD);
0090 
0091       // for reco ntuples:
0092       if (pt > 1.2 && TMath::Abs(eta) < 2.4 && TMath::Abs(d0) < 5 && TMath::Abs(z0) < 60 && nPixelLayerMeas >= 3 &&
0093           nTotLayerMeas >= 11 && normchi2 < 2 && quality && algo) {
0094         //TMath::Abs(d0)<0.06 ) {
0095         //(chi2/ndof)<5 && TMath::Prob(chi2, (int)ndof)>0.02 && TMath::Abs(eta)<2.2 ) {
0096         zvector.push_back(data(z0, sigmaz0, d0, sigmaD, phi, pt, 1.));
0097         theevent++;
0098       }
0099     }
0100     // if (Cut(ientry) < 0) continue;
0101     //  }
0102   }
0103   std::cout << zvector.size() << " selected tracks read in.\n";
0104   hsx->Divide(hsw);
0105   hsd->Divide(hsw);
0106   return zvector;
0107 }