1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
18
#include "Utils/CppErrorHandler.hh"
19
#include "Utils/JsonWrapper.hh"
20
#include "Utils/TOFChannelMap.hh"
21
#include "Utils/DAQChannelMap.hh"
22
#include "Interface/Squeal.hh"
23
#include "Interface/dataCards.hh"
25
#include "src/map/MapCppTOFDigits/MapCppTOFDigits.hh"
27
bool MapCppTOFDigits::birth(std::string argJsonConfigDocument) {
28
// Check if the JSON document can be parsed, else return error only
29
_classname = "MapCppTOFDigits";
30
StationKeys.push_back("tof0");
31
StationKeys.push_back("tof1");
32
StationKeys.push_back("tof2");
34
if( SetConfiguration(argJsonConfigDocument) )
35
return true; // Sucessful completion
41
bool MapCppTOFDigits::death() { return true;}
43
std::string MapCppTOFDigits::process( std::string document ) {
46
Json::FastWriter writer;
48
// Check if the JSON document can be parsed, else return error only
49
Json::Value root = JsonWrapper::StringToJson( document );
50
Json::Value xEventType = JsonWrapper::GetProperty( root, "daq_event_type", JsonWrapper::stringValue );
52
if(xEventType=="physics_event" || xEventType=="calibration_event" ) {
53
Json::Value xDaqData = JsonWrapper::GetProperty( root, "daq_data", JsonWrapper::objectValue );
55
Json::Value xDocTrigReq = JsonWrapper::GetProperty( xDaqData,
57
JsonWrapper::arrayValue);
59
Json::Value xDocTrig = JsonWrapper::GetProperty( xDaqData,
60
"trigger", // CHECK THIS
61
JsonWrapper::arrayValue);
63
for(unsigned int n_station = 0; n_station < StationKeys.size(); n_station++ ) {
64
Json::Value xDocDetectorData = JsonWrapper::GetProperty( xDaqData,
65
StationKeys[n_station],
66
JsonWrapper::arrayValue);
68
Json::Value xDocDigits = makeDigits( xDocDetectorData, xDocTrigReq, xDocTrig );
69
root["digits"][StationKeys[n_station]] = xDocDigits;
73
//std::cout<<root["digits"]<<std::endl;
74
return writer.write(root);
77
bool MapCppTOFDigits::SetConfiguration(std::string json_configuration) {
79
Json::Value configJSON = JsonWrapper::StringToJson(json_configuration); // this will contain the configuration
81
Json::Value map_file_name = JsonWrapper::GetProperty( configJSON, "TOF_cabling_file", JsonWrapper::stringValue);
82
char* pMAUS_ROOT_DIR = getenv("MAUS_ROOT_DIR");
85
Squeak::mout(Squeak::error) << "Could not find the $MAUS_ROOT_DIR environmental variable." << std::endl;
86
Squeak::mout(Squeak::error) << "Did you try running: source env.sh ?" << std::endl;
89
std::string xMapFile = std::string(pMAUS_ROOT_DIR) + map_file_name.asString();
90
bool loaded = _map.InitFromFile(xMapFile);
97
Json::Value MapCppTOFDigits::makeDigits( Json::Value xDocDetData,
98
Json::Value xDocTrigReq,
99
Json::Value xDocTrig) {
100
Json::Value xDocDigits;
102
if( xDocDetData.isArray() ) {
103
int n_part_events = xDocDetData.size();
104
for ( int PartEvent = 0; PartEvent < n_part_events; PartEvent++ ) {
105
// Get the data, trigger and trigger request for this particle event.
106
Json::Value xDocPartEvent_data = JsonWrapper::GetItem( xDocDetData, PartEvent, JsonWrapper::anyValue );
107
Json::Value xDocPartEvent_trigger = JsonWrapper::GetItem( xDocTrig, PartEvent, JsonWrapper::anyValue );
108
Json::Value xDocPartEvent_triggerReq = JsonWrapper::GetItem( xDocTrigReq, PartEvent, JsonWrapper::anyValue );
110
if (xDocPartEvent_data.isMember("V1290") && xDocPartEvent_data.isMember("V1724")) {
111
Json::Value xDocTdc = JsonWrapper::GetProperty(xDocPartEvent_data,
113
JsonWrapper::arrayValue );
115
Json::Value xDocfAdc = JsonWrapper::GetProperty(xDocPartEvent_data,
117
JsonWrapper::arrayValue );
119
int n_tdc_hits = xDocTdc.size();
120
Json::Value xDocPmtHits;
121
for ( int TdcHitCount = 0; TdcHitCount < n_tdc_hits; TdcHitCount++ ) {
122
// Get the Tdc info from the particle event. This must be done before getting
123
// info from any other equipment.
124
Json::Value xDocTheDigit = getTdc(xDocTdc[TdcHitCount]);
126
// Get flash ADC info and appent it to the digit. The info from the Tdc is
127
// passed as well in order to find the ascosiated adc values.
128
getAdc(xDocfAdc, xDocTdc[TdcHitCount], xDocTheDigit);
130
// Get the trigger leading and trailing times and add them to the digit.
131
getTrig(xDocPartEvent_trigger, xDocTdc[TdcHitCount], xDocTheDigit);
133
// Get the trigger request leading and trailing times and add them to the digit.
134
getTrigReq(xDocPartEvent_triggerReq, xDocTdc[TdcHitCount], xDocTheDigit);
136
xDocPmtHits.append(xDocTheDigit);
138
xDocDigits[PartEvent] = xDocPmtHits;
145
Json::Value MapCppTOFDigits::getTdc(Json::Value xDocTdcHit){
146
std::stringstream xConv;
147
Json::Value xDocInfo;
149
DAQChannelKey xTdcDaqKey;
151
std::string xDaqKey_tdc_str = JsonWrapper::GetProperty( xDocTdcHit,
153
JsonWrapper::stringValue).asString();
155
xConv << xDaqKey_tdc_str;
158
TOFChannelKey* xTofTdcKey = _map.find(&xTdcDaqKey);
161
xDocInfo["tof_key"] = xTofTdcKey->str();
162
xDocInfo["station"] = xTofTdcKey->station();
163
xDocInfo["plane"] = xTofTdcKey->plane();
164
xDocInfo["slab"] = xTofTdcKey->slab();
165
xDocInfo["pmt"] = xTofTdcKey->pmt();
167
xDocInfo["part_event_number"] = JsonWrapper::GetProperty( xDocTdcHit,
169
JsonWrapper::intValue );
171
xDocInfo["phys_event_number"] = JsonWrapper::GetProperty( xDocTdcHit,
173
JsonWrapper::intValue );
175
xDocInfo["leading_time"] = JsonWrapper::GetProperty( xDocTdcHit,
177
JsonWrapper::intValue );
179
xDocInfo["trailing_time"] = JsonWrapper::GetProperty( xDocTdcHit,
181
JsonWrapper::intValue );
183
xDocInfo["trigger_time_tag"] = JsonWrapper::GetProperty( xDocTdcHit,
185
JsonWrapper::intValue );
187
xDocInfo["time_stamp"] = JsonWrapper::GetProperty( xDocTdcHit,
189
JsonWrapper::intValue );
191
//std::cout << xDocInfo << std::endl;
195
bool MapCppTOFDigits::getAdc(Json::Value xDocfAdc, Json::Value xDocTdcHit, Json::Value &xDocDigit) {
197
int n_Adc_hits = xDocfAdc.size();
198
std::string xTofKey_str = JsonWrapper::GetProperty( xDocDigit,
200
JsonWrapper::stringValue).asString();
202
TOFChannelKey xTdcTofKey(xTofKey_str);
204
for ( int AdcHitCount = 0; AdcHitCount < n_Adc_hits; AdcHitCount++ ) {
205
std::string xDaqKey_adc_str = JsonWrapper::GetProperty( xDocfAdc[AdcHitCount],
207
JsonWrapper::stringValue).asString();
209
DAQChannelKey xAdcDaqKey(xDaqKey_adc_str);
210
TOFChannelKey* xAdcTofKey = _map.find(&xAdcDaqKey);
212
if ( xTdcTofKey == *xAdcTofKey ){
213
xDocDigit["charge_mm"] = JsonWrapper::GetProperty( xDocfAdc[AdcHitCount],
215
JsonWrapper::intValue );
216
xDocDigit["charge_pm"] = JsonWrapper::GetProperty( xDocfAdc[AdcHitCount],
218
JsonWrapper::intValue );
226
bool MapCppTOFDigits::getTrig( Json::Value xDocTrig, Json::Value xDocTdcHit, Json::Value &xDocDigit ) {
227
Json::Value xDocT = JsonWrapper::GetProperty( xDocTrig, "V1290", JsonWrapper::arrayValue);
228
int HitGeo = JsonWrapper::GetProperty(xDocTdcHit , "geo", JsonWrapper::intValue).asInt();
229
int n_count = xDocT.size();
230
//loop over all of the triggers for this particle event.
231
for ( int TrigCount = 0; TrigCount < n_count; TrigCount++ ){
232
Json::Value Trig = JsonWrapper::GetItem( xDocT, TrigCount, JsonWrapper::objectValue);
234
int TrGeo = JsonWrapper::GetProperty(Trig, "geo", JsonWrapper::intValue).asInt();
235
// If the Geo number of the trigger request matches the Geo number for the TDC then add the
236
// trigger information to the digit.
237
if ( TrGeo == HitGeo ){
238
xDocDigit["trigger_leading_time"] = JsonWrapper::GetProperty( Trig,
240
JsonWrapper::intValue);
241
xDocDigit["trigger_trailing_time"] = JsonWrapper::GetProperty( Trig,
243
JsonWrapper::intValue);
245
return true; // will break the loop and return truewhen it finds the first trigger that matches.
252
bool MapCppTOFDigits::getTrigReq( Json::Value xDocTrigReq, Json::Value xDocTdcHit, Json::Value &xDocDigit ) {
253
Json::Value xDocTR = JsonWrapper::GetProperty( xDocTrigReq, "V1290", JsonWrapper::arrayValue);
254
int HitGeo = JsonWrapper::GetProperty(xDocTdcHit , "geo", JsonWrapper::intValue).asInt();
255
int n_req_count = xDocTR.size();
257
//loop over all of the trigger requests for this particle event.
258
for ( int TrigReqCount = 0; TrigReqCount < n_req_count; TrigReqCount++ ){
259
Json::Value TrigReq = JsonWrapper::GetItem( xDocTR, TrigReqCount, JsonWrapper::objectValue);
261
int TrReqGeo = JsonWrapper::GetProperty(TrigReq, "geo", JsonWrapper::intValue).asInt();
262
// If the Geo number of the trigger request matches the Geo number for the TDC then add the
263
// trigger request information to the digit.
264
if ( TrReqGeo == HitGeo ){
265
xDocDigit["trigger_request_leading_time"] = JsonWrapper::GetProperty( TrigReq,
267
JsonWrapper::intValue);
269
xDocDigit["trigger_request_trailing_time"] = JsonWrapper::GetProperty( TrigReq,
271
JsonWrapper::intValue);
272
return true; // will break the loop when it finds the first request that matches. there may be
273
// multiple requests per board but for now we only get the first one.