Skip to content

Commit 445cc92

Browse files
authored
Merge pull request #38 from marc1uk/addWCSimDemo
Add WCSimDemo tool showing use of LoadWCSim for truth analysis
2 parents 5663435 + c43cabc commit 445cc92

11 files changed

+289
-0
lines changed

UserTools/Factory/Factory.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ if (tool=="LoadANNIEEvent") ret=new LoadANNIEEvent;
4343
if (tool=="PhaseITreeMaker") ret=new PhaseITreeMaker;
4444
//if (tool=="MrdPaddlePlot") ret=new MrdPaddlePlot;
4545
if (tool=="LoadWCSimLAPPD") ret=new LoadWCSimLAPPD;
46+
if (tool=="WCSimDemo") ret=new WCSimDemo;
4647
return ret;
4748
}

UserTools/Unity.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@
4747
//#include "MrdPaddlePlot/MrdPaddlePlot.cpp"
4848
#include "LoadWCSimLAPPD/LoadWCSimLAPPD.cpp"
4949
#include "LoadWCSimLAPPD/LAPPDTree.cpp"
50+
#include "WCSimDemo/WCSimDemo.cpp"

UserTools/WCSimDemo/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# WCSimDemo
2+
3+
WCSimDemo
4+
5+
## Data
6+
7+
Describe any data formats WCSimDemo creates, destroys, changes, or analyzes. E.G.
8+
9+
**RawLAPPDData** `map<Geometry, vector<Waveform<double>>>`
10+
* Takes this data from the `ANNIEEvent` store and finds the number of peaks
11+
12+
## Configuration
13+
14+
Describe any configuration variables for WCSimDemo.
15+
16+
```
17+
param1 value1
18+
param2 value2
19+
```

UserTools/WCSimDemo/WCSimDemo.cpp

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/* vim:set noexpandtab tabstop=4 wrap */
2+
#include "WCSimDemo.h"
3+
4+
WCSimDemo::WCSimDemo():Tool(){}
5+
6+
7+
bool WCSimDemo::Initialise(std::string configfile, DataModel &data){
8+
9+
/////////////////// Usefull header ///////////////////////
10+
//loading config file
11+
if(configfile!="") m_variables.Initialise(configfile);
12+
//m_variables.Print();
13+
14+
//assign transient data pointer
15+
m_data= &data;
16+
17+
// Get the Tool configuration variables
18+
m_variables.Get("verbosity",verbosity);
19+
20+
Log("Initializing Tool WCSimDemo",v_message,verbosity);
21+
return true;
22+
}
23+
24+
25+
bool WCSimDemo::Execute(){
26+
Log("WCSimDemo Tool: Executing",v_debug,verbosity);
27+
get_ok = m_data->Stores.count("ANNIEEvent");
28+
if(!get_ok){
29+
Log("WCSimDemo Tool: No ANNIEEvent store!",v_error,verbosity);
30+
return false;
31+
};
32+
33+
// First, see if this is a delayed trigger in the event
34+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("MCTriggernum",MCTriggernum);
35+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving MCTriggernum from ANNIEEvent!",v_error,verbosity); return false; }
36+
// if so, truth analysis is probably not interested in this trigger. Primary muon will not be in the listed tracks.
37+
if(MCTriggernum>0){ Log("WCSimDemo Tool: Skipping delayed trigger",v_debug,verbosity); return true;}
38+
39+
// Retrieve the info from the ANNIEEvent
40+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("MCFile",MCFile);
41+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving MCFile from ANNIEEvent!",v_error,verbosity); return false; }
42+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("MCEventNum",MCEventNum);
43+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving MCEventNum from ANNIEEvent!",v_error,verbosity); return false; }
44+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("EventNumber",EventNumber);
45+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving EventNumber from ANNIEEvent!",v_error,verbosity); return false; }
46+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("MCParticles",MCParticles);
47+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving MCParticles,true from ANNIEEvent!",v_error,verbosity); return false; }
48+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("MCHits",MCHits);
49+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving MCHits,true from ANNIEEvent!",v_error,verbosity); return false; }
50+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("MCLAPPDHits",MCLAPPDHits);
51+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving MCLAPPDHits,true from ANNIEEvent!",v_error,verbosity); return false; }
52+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("TDCData",TDCData);
53+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving TDCData,true from ANNIEEvent!",v_error,verbosity); return false; }
54+
get_ok = m_data->Stores.at("ANNIEEvent")->Get("EventTime",EventTime);
55+
if(not get_ok){ Log("WCSimDemo Tool: Error retrieving EventTime,true from ANNIEEvent!",v_error,verbosity); return false; }
56+
57+
// Print the information. Jingbo, do what you do here. :)
58+
logmessage = "WCSimDemo Tool: Processing truth tracks and digits for "+MCFile
59+
+", MCEvent "+to_string(MCEventNum)+", MCTrigger "+to_string(MCTriggernum);
60+
Log(logmessage,v_debug,verbosity);
61+
62+
// loop over the MCParticles to find the highest enery primary muon
63+
// MCParticles is a std::vector<MCParticle>
64+
MCParticle primarymuon; // primary muon
65+
bool mufound=false;
66+
if(MCParticles){
67+
Log("WCSimDemo Tool: Num MCParticles = "+to_string(MCParticles->size()),v_message,verbosity);
68+
for(int particlei=0; particlei<MCParticles->size(); particlei++){
69+
MCParticle aparticle = MCParticles->at(particlei);
70+
//if(v_debug<verbosity) aparticle.Print(); // print if we're being *really* verbose
71+
if(aparticle.GetParentPdg()!=0) continue; // not a primary particle
72+
if(aparticle.GetPdgCode()!=13) continue; // not a muon
73+
primarymuon = aparticle; // note the particle
74+
mufound=true; // note that we found it
75+
break; // won't have more than one primary muon
76+
}
77+
} else {
78+
Log("WCSimDemo Tool: No MCParticles in the event!",v_error,verbosity);
79+
}
80+
if(not mufound){
81+
Log("WCSimDemo Tool: No muon in this event",v_warning,verbosity);
82+
return true;
83+
}
84+
85+
// retrieve desired information from the particle
86+
const Position neutrinovtx = primarymuon.GetStartVertex(); // only true if the muon is primary
87+
const Direction muondirection = primarymuon.GetStartDirection();
88+
double muonenergy = primarymuon.GetStartEnergy();
89+
logmessage = "WCSimDemo Tool: Interaction Vertex is at ("+to_string(neutrinovtx.X())
90+
+", "+to_string(neutrinovtx.Y())+", "+to_string(neutrinovtx.Z())+")\n"
91+
+"Primary muon has energy "+to_string(muonenergy)+"GeV and direction ("
92+
+to_string(muondirection.X())+", "+to_string(muondirection.Y())+", "+to_string(muondirection.Z())+")";
93+
Log(logmessage,v_debug,verbosity);
94+
// see Particle.h for other information in the MCParticle class
95+
96+
// now move to digit retrieval
97+
// MCHits is a std::map<ChannelKey,std::vector<Hit>>
98+
if(MCHits){
99+
Log("WCSimDemo Tool: Num PMT Digits = "+to_string(MCHits->size()),v_message,verbosity);
100+
// iterate over the map of sensors with a measurement
101+
for(std::pair<ChannelKey,std::vector<Hit>>&& apair : *MCHits){
102+
ChannelKey chankey = apair.first;
103+
// a ChannelKey is a detector descriptor, containing 2 elements:
104+
// a 'subdetector' (enum class), with types ADC, LAPPD, TDC
105+
// and a DetectorElementIndex, i.e. the ID of the detector of that type
106+
107+
if(chankey.GetSubDetectorType()==subdetector::ADC){
108+
std::vector<Hit>& hits = apair.second;
109+
for(Hit& ahit : hits){
110+
//if(v_message<verbosity) ahit.Print(); // << VERY verbose
111+
// a Hit has tubeid, charge and time
112+
}
113+
}
114+
} // end loop over MCHits
115+
} else {
116+
cout<<"No MCHits"<<endl;
117+
}
118+
119+
// repeat for LAPPD hits
120+
// MCLAPPDHits is a std::map<ChannelKey,std::vector<LAPPDHit>>
121+
if(MCLAPPDHits){
122+
Log("WCSimDemo Tool: Num LAPPD Digits = "+to_string(MCLAPPDHits->size()),v_message,verbosity);
123+
// iterate over the map of sensors with a measurement
124+
for(std::pair<ChannelKey,std::vector<LAPPDHit>>&& apair : *MCLAPPDHits){
125+
ChannelKey chankey = apair.first;
126+
if(chankey.GetSubDetectorType()==subdetector::LAPPD){ // redundant
127+
std::vector<LAPPDHit>& hits = apair.second;
128+
for(LAPPDHit& ahit : hits){
129+
//if(v_message<verbosity) ahit.Print(); // << VERY verbose
130+
// an LAPPDHit has adds (global x-y-z) position, (in-tile x-y) local position
131+
// and time psecs
132+
}
133+
}
134+
} // end loop over MCLAPPDHits
135+
} else {
136+
cout<<"No MCLAPPDHits"<<endl;
137+
}
138+
139+
return true;
140+
}
141+
142+
143+
bool WCSimDemo::Finalise(){
144+
145+
return true;
146+
}

UserTools/WCSimDemo/WCSimDemo.h

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* vim:set noexpandtab tabstop=4 wrap */
2+
#ifndef WCSimDemo_H
3+
#define WCSimDemo_H
4+
5+
#include <string>
6+
#include <iostream>
7+
#include <sstream>
8+
9+
#include "Tool.h"
10+
#include "ChannelKey.h"
11+
#include "Particle.h"
12+
#include "Hit.h"
13+
#include "LAPPDHit.h"
14+
#include "TriggerClass.h"
15+
#include "TimeClass.h"
16+
17+
class WCSimDemo: public Tool {
18+
19+
public:
20+
21+
WCSimDemo();
22+
bool Initialise(std::string configfile,DataModel &data);
23+
bool Execute();
24+
bool Finalise();
25+
26+
private:
27+
28+
int verbosity=0;
29+
std::string inputfile;
30+
unsigned long NumEvents;
31+
32+
// contents of ANNIEEvent filled by LoadWCSim and LoadWCSimLAPPD
33+
std::string MCFile;
34+
uint32_t RunNumber; // retrieved from MC file but simulations tend to only ever be run 0.
35+
uint32_t SubrunNumber; // MC has no 'subrun', always 0
36+
uint32_t EventNumber; // flattens the 'event -> trigger' MC hierarchy
37+
uint64_t MCEventNum; // event number in MC file
38+
uint16_t MCTriggernum; // trigger number in MC file
39+
40+
std::vector<MCParticle>* MCParticles=nullptr; // truth tracks
41+
std::map<ChannelKey,std::vector<Hit>>* MCHits=nullptr; // PMT hits
42+
std::map<ChannelKey,std::vector<LAPPDHit>>* MCLAPPDHits=nullptr; // LAPPD hits
43+
std::map<ChannelKey,std::vector<Hit>>* TDCData=nullptr; // MRD & veto hits
44+
TimeClass* EventTime=nullptr; // NDigits trigger time in ns from when the particles were generated
45+
46+
// verbosity levels: if 'verbosity' < this level, the message type will be logged.
47+
int v_error=0;
48+
int v_warning=1;
49+
int v_message=2;
50+
int v_debug=3;
51+
std::string logmessage;
52+
int get_ok;
53+
54+
};
55+
56+
57+
#endif

configfiles/WCSimDemo/LoadWCSimConfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#LoadWCSim Config File
2+
# all variables retrieved with m_variables.Get() must be defined here!
3+
4+
verbose 1
5+
InputFile /pnfs/annie/persistent/users/moflaher/wcsim/lappd/tankonly/wcsim_lappd_tankonly_24-09-17_BNB_Water_10k_22-05-17/wcsim_0.0.0.root
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#LoadWCSimLAPPD Config File
2+
# all variables retrieved with m_variables.Get() must be defined here!
3+
4+
verbose 1
5+
InputFile /pnfs/annie/persistent/users/moflaher/wcsim/lappd/tankonly/wcsim_lappd_tankonly_24-09-17_BNB_Water_10k_22-05-17/wcsim_lappd_0.0.0.root
6+
# octagonal inner structure radius in cm (from drawings 106.64")
7+
InnerStructureRadius 135.45
8+
HistoricTriggeroffset 950

configfiles/WCSimDemo/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Configure files
2+
3+
***********************
4+
#Description
5+
**********************
6+
7+
This toolchain demonstrates loading and reading WCSim events. It loads WCSim hits from PMTs and LAPPDs (using LoadWCSim and LoadWCSimLAPPD tools), then retrieve hits from the ANNIEEvent in the WCSimDemo tool and prints some event information.
8+
9+
10+
************************
11+
#Useage
12+
************************
13+
14+
The LoadWCSimConfig file must be given the path to a WCSim file, usually named with the form "wcsim_0.XXX.YYY.root".
15+
16+
The LoadWCSimLAPPDConfig file must be given the path to a WCSim LAPPD file, usually named with the form "wcsim_lappd_0.XXX.YYY.root"
17+
18+
# on naming conventions:
19+
XXX is the grid job number, and will match the file number for upstream genie and dirt propagated files
20+
e.g. "wcsim_0.4500.root" would be generated from genie file "gntp.4500.ghep.root", with corresponding dirt propagated file annie_tank_flux.4500.root.
21+
YYY is a further splitting added for later jobs using some of Vincent's genie files, as the time taken for WCSim to process each genie file would take too long on the grid. In this case the upstream job number is divided into ten - the genie file "gntp.4500.ghep.root" would generate 10 wcsim files named "wcsim_0.450.0.root - wcsim_0.450.9.root"

configfiles/WCSimDemo/ToolChainConfig

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ToolChain dynamic setup file
2+
3+
##### Runtime Paramiters #####
4+
verbose 1 ## Verbosity level of ToolChain
5+
error_level 0 # 0= do not exit, 1= exit on unhandeled errors only, 2= exit on unhandeled errors and handeled errors
6+
attempt_recover 1 ## 1= will attempt to finalise if an execute fails
7+
8+
###### Logging #####
9+
log_mode Interactive # Interactive=cout , Remote= remote logging system "serservice_name Remote_Logging" , Local = local file log;
10+
log_local_path ./log
11+
log_service LogStore
12+
13+
###### Service discovery ##### Ignore these settings for local analysis
14+
service_publish_sec -1
15+
service_kick_sec -1
16+
17+
##### Tools To Add #####
18+
Tools_File configfiles/WCSimDemo/ToolsConfig ## list of tools to run and their config files
19+
20+
##### Run Type #####
21+
Inline -1 ## number of Execute steps in program, -1 infinite loop that is ended by user
22+
Interactive 0 ## set to 1 if you want to run the code interactively
23+

configfiles/WCSimDemo/ToolsConfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
myLoadWCSim LoadWCSim ./configfiles/WCSimDemo/LoadWCSimConfig
2+
myLoadWCSimLAPPD LoadWCSimLAPPD ./configfiles/WCSimDemo/LoadWCSimLAPPDConfig
3+
myWCSimDemo WCSimDemo ./configfiles/WCSimDemo/WCSimDemoConfig
4+
#myPrintANNIEEvent PrintANNIEEvent ./configfiles/WCSimDemo/PrintANNIEEventConfig
5+

configfiles/WCSimDemo/WCSimDemoConfig

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# WCSimDemo config file
2+
3+
verbosity 3

0 commit comments

Comments
 (0)