|
| 1 | +/* |
| 2 | +This program for calculating the power on the collimator 1,2,4,5 for MOLLER |
| 3 | +experiment |
| 4 | +Chandan Ghosh |
| 5 | +part of this is taken from Rakitha's code coll_scan.cc |
| 6 | +*/ |
| 7 | +#include <vector> |
| 8 | +#include <iostream> |
| 9 | + |
| 10 | +#include "remolltypes.hh" |
| 11 | + |
| 12 | +#include <TTree.h> |
| 13 | +#include <TFile.h> |
| 14 | +#include <TChain.h> |
| 15 | + |
| 16 | +void test_power (const TString& inputdir = ".", const TString& inputname = "remollout") |
| 17 | +{ |
| 18 | + // Input files |
| 19 | + TChain* T = new TChain("T"); |
| 20 | + T->Add(inputdir + "/" + inputname + ".root"); |
| 21 | + |
| 22 | + // Output files |
| 23 | + TString outputdir = inputdir + "/" + "analysis"; |
| 24 | + TFile file(outputdir + "/" + inputname + ".root","RECREATE"); |
| 25 | + |
| 26 | + // Collimators and particles to track |
| 27 | + std::vector<Int_t> collimators = {2001, 2006, 2002, 2004, 2005}; |
| 28 | + std::vector<Int_t> particles = {11, -11, 22, 2112}; |
| 29 | + |
| 30 | + // Energy vectors |
| 31 | + std::vector<Double_t> esum(collimators.size(), 0.0); |
| 32 | + std::vector<std::vector<Double_t>> esum2(collimators.size(), std::vector<Double_t>(particles.size(), 0.0)); |
| 33 | + |
| 34 | + // Connect to tree |
| 35 | + std::vector<remollGenericDetectorSum_t>* fGenDetSum = 0; |
| 36 | + T->SetBranchAddress("sum",&fGenDetSum); |
| 37 | + |
| 38 | + // Event loop |
| 39 | + Int_t nentries = T->GetEntries(); |
| 40 | + std::cout << "Number of entries in TChain " << nentries << std::endl; |
| 41 | + for (int ev = 0; ev < T->GetEntries(); ev++) { |
| 42 | + |
| 43 | + T->GetEntry(ev); |
| 44 | + |
| 45 | + for (size_t isum = 0; isum < fGenDetSum->size(); isum++) { |
| 46 | + |
| 47 | + Int_t volume = fGenDetSum->at(isum).det; |
| 48 | + Double_t edep = fGenDetSum->at(isum).edep; |
| 49 | + |
| 50 | + for (size_t coll = 0; coll < collimators.size(); coll++) { |
| 51 | + |
| 52 | + if (volume == collimators[coll]) { |
| 53 | + |
| 54 | + esum[coll] += edep; |
| 55 | + |
| 56 | + std::vector<remollGenericDetectorSumByPID_t> sumbypid = fGenDetSum->at(isum).by_pid; |
| 57 | + |
| 58 | + for (size_t isum2 = 0; isum2 < sumbypid.size(); isum2++) { |
| 59 | + |
| 60 | + Double_t edep = sumbypid.at(isum2).edep; |
| 61 | + Int_t pid = sumbypid.at(isum2).pid; |
| 62 | + |
| 63 | + for (size_t part = 0; part < particles.size(); part++) { |
| 64 | + if (pid == particles[part]) |
| 65 | + esum2[coll][part] += edep; |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + for (size_t coll = 0; coll < collimators.size(); coll++) { |
| 74 | + std::cout << "Collimator " << collimators[coll] << std::endl; |
| 75 | + std::vector<Double_t> esum_pid(collimators.size(), 0.0); |
| 76 | + std::cout << "Deposited energy (from sum.edep) " << std::setw(8) << esum[coll]*85./nentries << " W/85uA" << std::endl; |
| 77 | + for (size_t part = 0; part < particles.size(); part++) { |
| 78 | + std::cout << "particle " << std::setw(5) << particles[part] << " energy deposited (from by_pid) " << std::setw(6) << esum2[coll][part]*85./nentries << " W/85uA" << std::endl; |
| 79 | + esum_pid[coll] += esum2[coll][part]; |
| 80 | + } |
| 81 | + std::cout << "By pid sum edep (from by_pid) " << esum_pid[coll]*85./nentries << " W/85uA" << std::endl; |
| 82 | + } |
| 83 | + std::cout << "Total energy deposited inside collimator (from sum.edep) " << esum[0]*85./nentries + esum[1]*85./nentries << " W/85uA" <<std::endl; |
| 84 | + |
| 85 | + // Cleanup |
| 86 | + delete T; |
| 87 | +} |
| 88 | + |
0 commit comments