Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:22

0001 #include <TCanvas.h>
0002 #include <TCut.h>
0003 #include <TFile.h>
0004 #include <TH1F.h>
0005 #include <TH2F.h>
0006 #include <TMath.h>
0007 #include <TObjString.h>
0008 #include <TRandom3.h>
0009 #include <TTree.h>
0010 #include <TTreeIndex.h>
0011 
0012 #include <fstream>
0013 #include <iostream>
0014 #include <sstream>
0015 #include <string>
0016 #include <vector>
0017 
0018 int main(int argc, char *argv[])
0019 {
0020     if (argc != 3)
0021     {
0022         std::cout << "Usage: ./plotTrkrHit [infilename (ntuple)] [outfilename (histogram)]" << std::endl;
0023         return 0;
0024     }
0025 
0026     for (int i = 0; i < argc; i++)
0027     {
0028         std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
0029     }
0030 
0031     TString infilename = TString(argv[1]);
0032     TString outfilename = TString(argv[2]);
0033 
0034     int z_offset[4] = {5, 0, 13, 21};
0035     int layer_offset[4] = {0, 12, 24, 40};
0036     int layerhitset_offset[4] = {0, 48, 96, 160};
0037 
0038     TH2F *hM_hitmap_RowColumnFlatten_unwei = new TH2F("hM_hitmap_RowColumnFlatten_unwei", "hM_hitmap_RowColumnFlatten_unwei", 4 * 32, 0, 4 * 32, 360 * 16, 0, 360 * 16);
0039     TH2F *hM_hitmap_RowColumnFlatten_weiADC = new TH2F("hM_hitmap_RowColumnFlatten_weiADC", "hM_hitmap_RowColumnFlatten_weiADC", 4 * 32, 0, 4 * 32, 360 * 16, 0, 360 * 16);
0040 
0041     TFile *f = new TFile(infilename, "READ");
0042     TTree *t = (TTree *)f->Get("EventTree");
0043     int NTrkrhits;
0044     std::vector<uint16_t> *TrkrHitRow = 0, *TrkrHitColumn = 0, *TrkrHitADC = 0;
0045     std::vector<uint8_t> *TrkrHitLadderZId = 0, *TrkrHitLadderPhiId = 0, *TrkrHitLayer = 0;
0046     t->SetBranchAddress("NTrkrhits", &NTrkrhits);
0047     t->SetBranchAddress("TrkrHitRow", &TrkrHitRow);
0048     t->SetBranchAddress("TrkrHitColumn", &TrkrHitColumn);
0049     t->SetBranchAddress("TrkrHitADC", &TrkrHitADC);
0050     t->SetBranchAddress("TrkrHitLadderZId", &TrkrHitLadderZId);
0051     t->SetBranchAddress("TrkrHitLadderPhiId", &TrkrHitLadderPhiId);
0052     t->SetBranchAddress("TrkrHitLayer", &TrkrHitLayer);
0053 
0054     for (int ev = 0; ev < t->GetEntriesFast(); ev++)
0055     {
0056         t->GetEntry(ev);
0057 
0058         for (int i = 0; i < NTrkrhits; i++)
0059         {
0060             int flat_x = TrkrHitColumn->at(i) + z_offset[TrkrHitLadderZId->at(i)] + 32 * (TrkrHitLayer->at(i) - 3);
0061             int flat_y = TrkrHitRow->at(i) + 360 * TrkrHitLadderPhiId->at(i);
0062 
0063             hM_hitmap_RowColumnFlatten_unwei->Fill(flat_x, flat_y);
0064             hM_hitmap_RowColumnFlatten_weiADC->Fill(flat_x, flat_y, TrkrHitADC->at(i) + 1);
0065         }
0066     }
0067 
0068     TFile *fout = new TFile(outfilename, "RECREATE");
0069     fout->cd();
0070     hM_hitmap_RowColumnFlatten_unwei->Write();
0071     hM_hitmap_RowColumnFlatten_weiADC->Write();
0072     fout->Close();
0073 }