Skip to content

Commit 53c1ccd

Browse files
authored
Merge pull request #441 from yangtj207/feature/tjyang_geohelper
Add new functions in geometry helper
2 parents 15adbb5 + f7bc1e9 commit 53c1ccd

3 files changed

Lines changed: 173 additions & 0 deletions

File tree

sbndcode/ChannelMaps/TPC/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ art_make(SERVICE_LIBRARIES
1212
art::Persistency_Provenance
1313
messagefacility::MF_MessageLogger
1414
ROOT::Core
15+
MODULE_LIBRARIES
16+
art_root_io::TFileService_service
17+
lardataobj::RawData
18+
larcore::Geometry_Geometry_service
19+
sbndcode_ChannelMaps_TPC_TPCChannelMapService_service
20+
ROOT::Tree
1521
)
22+
23+
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
////////////////////////////////////////////////////////////////////////
2+
// Class: TPCChannelIDAna
3+
// Plugin Type: analyzer
4+
// File: PDSMeanRMSLZ_tool.cc
5+
// Author: tjyang@fnal.gov
6+
//
7+
// Analyze channel ID data
8+
//
9+
////////////////////////////////////////////////////////////////////////
10+
#include "art/Framework/Core/EDAnalyzer.h"
11+
#include "art/Framework/Core/ModuleMacros.h"
12+
#include "art/Framework/Principal/Event.h"
13+
#include "art/Framework/Principal/Handle.h"
14+
#include "art/Framework/Principal/Run.h"
15+
#include "art/Framework/Principal/SubRun.h"
16+
#include "canvas/Utilities/InputTag.h"
17+
#include "fhiclcpp/ParameterSet.h"
18+
#include "messagefacility/MessageLogger/MessageLogger.h"
19+
#include "art_root_io/TFileService.h"
20+
21+
#include "lardataobj/RawData/RawDigit.h"
22+
#include "lardataobj/RawData/raw.h"
23+
#include "larcore/Geometry/Geometry.h"
24+
25+
#include "sbndcode/ChannelMaps/TPC/TPCChannelMapService.h"
26+
27+
#include "TTree.h"
28+
29+
using namespace std;
30+
31+
namespace sbnd {
32+
class TPCChannelIDAna;
33+
}
34+
35+
36+
class sbnd::TPCChannelIDAna : public art::EDAnalyzer {
37+
public:
38+
explicit TPCChannelIDAna(fhicl::ParameterSet const& p);
39+
// The compiler-generated destructor is fine for non-base
40+
// classes without bare pointers or other resource use.
41+
42+
// Plugins should not be copied or assigned.
43+
TPCChannelIDAna(TPCChannelIDAna const&) = delete;
44+
TPCChannelIDAna(TPCChannelIDAna&&) = delete;
45+
TPCChannelIDAna& operator=(TPCChannelIDAna const&) = delete;
46+
TPCChannelIDAna& operator=(TPCChannelIDAna&&) = delete;
47+
48+
// Required functions.
49+
void beginJob() override;
50+
void analyze(art::Event const& e) override;
51+
52+
private:
53+
54+
// Declare member data here.
55+
art::InputTag fRawDigitModuleLabel;
56+
TTree *chs;
57+
int ch; //offline channel
58+
int chid; //measurement from channel ID data
59+
int tpc;
60+
int plane;
61+
int wire;
62+
int wibcrate;
63+
int wib;
64+
int fembonwib;
65+
int fembch;
66+
int fembonwib_fromchid;
67+
int fembch_fromchid;
68+
int femcrate;
69+
int fem;
70+
int femch;
71+
};
72+
73+
74+
sbnd::TPCChannelIDAna::TPCChannelIDAna(fhicl::ParameterSet const& p)
75+
: EDAnalyzer{p}
76+
, fRawDigitModuleLabel{p.get<art::InputTag>("RawDigitModuleLabel")}
77+
// More initializers here.
78+
{
79+
// Call appropriate consumes<>() for any products to be retrieved by this module.
80+
}
81+
82+
void sbnd::TPCChannelIDAna::beginJob(){
83+
art::ServiceHandle<art::TFileService> tfs;
84+
chs = tfs->make<TTree>("chs","Channel information");
85+
chs->Branch("ch", &ch, "ch/I");
86+
chs->Branch("chid", &chid, "chid/I");
87+
chs->Branch("tpc", &tpc, "tpc/I");
88+
chs->Branch("plane", &plane, "plane/I");
89+
chs->Branch("wire", &wire, "wire/I");
90+
chs->Branch("wibcrate", &wibcrate, "wibcrate/I");
91+
chs->Branch("wib", &wib, "wib/I");
92+
chs->Branch("fembonwib", &fembonwib, "fembonwib/I");
93+
chs->Branch("fembch", &fembch, "fembch/I");
94+
chs->Branch("fembonwib_fromchid", &fembonwib_fromchid, "fembonwib_fromchid/I");
95+
chs->Branch("fembch_fromchid", &fembch_fromchid, "fembch_fromchid/I");
96+
chs->Branch("femcrate", &femcrate, "femcrate/I");
97+
chs->Branch("fem", &fem, "fem/I");
98+
chs->Branch("femch", &femch, "femch/I");
99+
}
100+
101+
void sbnd::TPCChannelIDAna::analyze(art::Event const& e)
102+
{
103+
// Implementation of required member function here.
104+
105+
art::ServiceHandle<geo::Geometry> geo;
106+
art::ServiceHandle<SBND::TPCChannelMapService> channelMap;
107+
108+
// Get raw digits
109+
auto const& rawdigts = e.getProduct<std::vector<raw::RawDigit>>(fRawDigitModuleLabel);
110+
for (const auto & rd : rawdigts){
111+
std::vector<short> rawadc; //UNCOMPRESSED ADC VALUES.
112+
rawadc.resize(rd.Samples());
113+
raw::Uncompress(rd.ADCs(), rawadc, rd.GetPedestal(), rd.Compression());
114+
//cout<<rd.Channel()<<" "<<rawadc[0]<<endl;
115+
ch = rd.Channel();
116+
chid = rawadc[0];
117+
auto const & chids = geo->ChannelToWire(ch);
118+
tpc = chids[0].TPC;
119+
plane = chids[0].Plane;
120+
wire = chids[0].Wire;
121+
auto const & chaninfo = channelMap->GetChanInfoFromOfflChan(ch);
122+
wibcrate = chaninfo.WIBCrate;
123+
wib = chaninfo.WIB;
124+
fembonwib = chaninfo.FEMBOnWIB;
125+
fembch = chaninfo.FEMBCh;
126+
femcrate = chaninfo.FEMCrate;
127+
fem = chaninfo.FEM;
128+
femch = chaninfo.FEMCh;
129+
fembonwib_fromchid = chid>>8;
130+
fembch_fromchid = chid&0xFF;
131+
chs->Fill();
132+
}
133+
}
134+
135+
DEFINE_ART_MODULE(sbnd::TPCChannelIDAna)

sbndcode/Utilities/SBNDGeoHelper_module.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ util::SBNDGeoHelper::SBNDGeoHelper(fhicl::ParameterSet const& p)
6363
while (input!=0){
6464
cout<<"0: quit"<<endl;
6565
cout<<"1: convert tpc/plane/wire to offline channel number"<<endl;
66+
cout<<"2: find intersection of two wires"<<endl;
6667
cout<<"Type a number: ";
6768
cin >> input;
6869
if (input == 1){
@@ -90,6 +91,35 @@ util::SBNDGeoHelper::SBNDGeoHelper(fhicl::ParameterSet const& p)
9091
cout<<"FEM (1-16) = "<<chaninfo.FEM<<endl;
9192
cout<<"FEMCh (0-63) = "<<chaninfo.FEMCh<<endl;
9293
}
94+
else if (input == 2){
95+
cout<<"Find wire intersection of two wires"<<endl;
96+
int tpc1, plane1, wire1, tpc2, plane2, wire2;
97+
cout<<"TPC1 number: ";
98+
cin>>tpc1;
99+
cout<<"Plane1 number: ";
100+
cin>>plane1;
101+
cout<<"Wire1 number: ";
102+
cin>>wire1;
103+
cout<<"TPC2 number: ";
104+
cin>>tpc2;
105+
cout<<"Plane2 number: ";
106+
cin>>plane2;
107+
cout<<"Wire2 number: ";
108+
cin>>wire2;
109+
geo::WireID wid1(0,tpc1,plane1,wire1);
110+
geo::WireID wid2(0,tpc2,plane2,wire2);
111+
double y,z;
112+
bool intersect = geo->IntersectionPoint(wid1,wid2,y,z);
113+
cout<<"WireID 1:"<<wid1.toString()<<endl;
114+
cout<<"WireID 2:"<<wid2.toString()<<endl;
115+
cout<<"The intersection point is ("<<y<<","<<z<<")."<<endl;
116+
if (intersect){
117+
cout<<"It is inside the detector."<<endl;
118+
}
119+
else{
120+
cout<<"It is outside the detector."<<endl;
121+
}
122+
}
93123
}
94124

95125
}

0 commit comments

Comments
 (0)