Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
std::set<PixelType>::iterator it;
for (it = local_wrongdetids.begin(); it != local_wrongdetids.end(); ++it){
PixelType tmpid = *it;
this->wrongdetids.insert(*it);
// 1. Create class map entry if not there
size_t mindex = 0;
std::map<PixelType, size_t>::iterator git = this->wrongdetidmap.find(tmpid);
if (git == this->wrongdetidmap.end()){
// create entry
size_t newindex = this->wrongdetid_abstimes.size();
this->wrongdetidmap[tmpid] = newindex;
std::vector<int64_t> temptimes;
this->wrongdetid_abstimes.push_back(temptimes);
mindex = newindex;
} else {
mindex = git->second;
}
// 2. Find local
std::map<PixelType, size_t>::iterator lit = local_pidindexmap.find(tmpid);
size_t localindex= lit->second;
// g_log.notice() << "Pixel " << tmpid << " Global index = " << mindex << " Local Index = " << localindex << std::endl;
// 3. Sort and merge
std::sort(local_abstimes[localindex].begin(), local_abstimes[localindex].end());
for (size_t iv = 0; iv < local_abstimes[localindex].size(); iv ++){
this->wrongdetid_abstimes[mindex].push_back(local_abstimes[localindex][iv]);
}
// std::sort(this->wrongdetid_abstimes[mindex].begin(), this->wrongdetid_abstimes[mindex].end());
}
if (local_shortest_tof < shortest_tof)
shortest_tof = local_shortest_tof;
if (local_longest_tof > longest_tof)
longest_tof = local_longest_tof;
}
}
//-----------------------------------------------------------------------------
/// Comparator for sorting dasevent lists
bool vzintermediatePixelIDComp(IntermediateEvent x, IntermediateEvent y)
{
return (x.pid < y.pid);
}
//-----------------------------------------------------------------------------
/**
* Add a sample environment log for the proton chage (charge of the pulse in picoCoulombs)
* and set the scalar value (total proton charge, microAmps*hours, on the sample)
*
* @param workspace :: Event workspace to set the proton charge on
*/
void LoadEventPreNexus2::setProtonCharge(DataObjects::EventWorkspace_sptr & workspace)
{
if (this->proton_charge.empty()) // nothing to do
return;
Run& run = workspace->mutableRun();
//Add the proton charge entries.
TimeSeriesProperty<double>* log = new TimeSeriesProperty<double>("proton_charge");
log->setUnits("picoCoulombs");
//Add the time and associated charge to the log
log->addValues(this->pulsetimes, this->proton_charge);
/// TODO set the units for the log
run.addLogData(log);
double integ = run.integrateProtonCharge();
//run.setProtonCharge(this->proton_charge_tot); //This is now redundant
this->g_log.information() << "Total proton charge of " << integ << " microAmp*hours found by integrating.\n";
}
//-----------------------------------------------------------------------------
/** Load a pixel mapping file
* @param filename :: Path to file.
*/
void LoadEventPreNexus2::loadPixelMap(const std::string &filename)
{
this->using_mapping_file = false;
this->pixelmap.clear();
// check that there is a mapping file
if (filename.empty()) {
this->g_log.information("NOT using a mapping file");
return;
}
// actually deal with the file
this->g_log.debug("Using mapping file \"" + filename + "\"");
//Open the file; will throw if there is any problem
BinaryFile<PixelType> pixelmapFile(filename);
PixelType max_pid = static_cast<PixelType>(pixelmapFile.getNumElements());
//Load all the data
pixelmapFile.loadAllInto( this->pixelmap );
//Check for funky file
if (std::find_if(pixelmap.begin(), pixelmap.end(), std::bind2nd(std::greater<PixelType>(), max_pid))
!= pixelmap.end())
{
this->g_log.warning("Pixel id in mapping file was out of bounds. Loading without mapping file");
this->numpixel = 0;
this->pixelmap.clear();
this->using_mapping_file = false;
return;
}
//If we got here, the mapping file was loaded correctly and we'll use it
this->using_mapping_file = true;
//Let's assume that the # of pixels in the instrument matches the mapping file length.
this->numpixel = static_cast<uint32_t>(pixelmapFile.getNumElements());
}
//-----------------------------------------------------------------------------
/** Open an event file
* @param filename :: file to open.
*/
void LoadEventPreNexus2::openEventFile(const std::string &filename)
{
//Open the file
eventfile = new BinaryFile<DasEvent>(filename);
num_events = eventfile->getNumElements();
g_log.debug() << "File contains " << num_events << " event records.\n";
// Check if we are only loading part of the event file
const int chunk = getProperty("ChunkNumber");
if ( isEmpty(chunk) ) // We are loading the whole file
{
first_event = 0;
max_events = num_events;
}
else // We are loading part - work out the event number range
{
const int totalChunks = getProperty("TotalChunks");
max_events = num_events/totalChunks;
first_event = (chunk - 1) * max_events;
// Need to add any remainder to the final chunk
if ( chunk == totalChunks ) max_events += num_events%totalChunks;
}
g_log.information()<< "Reading " << max_events << " event records\n";
}
//-----------------------------------------------------------------------------
/** Read a pulse ID file
* @param filename :: file to load.
* @param throwError :: Flag to trigger error throwing instead of just logging
*/
void LoadEventPreNexus2::readPulseidFile(const std::string &filename, const bool throwError)
{
this->proton_charge_tot = 0.;
this->num_pulses = 0;
// jump out early if there isn't a filename
if (filename.empty()) {
this->g_log.information("NOT using a pulseid file");
return;
}
std::vector<Pulse> * pulses;
// set up for reading
//Open the file; will throw if there is any problem
try {
BinaryFile<Pulse> pulseFile(filename);
//Get the # of pulse
this->num_pulses = pulseFile.getNumElements();
this->g_log.information() << "Using pulseid file \"" << filename << "\", with " << num_pulses
<< " pulses.\n";
//Load all the data
pulses = pulseFile.loadAll();
} catch (runtime_error &e) {
if (throwError)
{
throw;
}
else
{
this->g_log.information() << "Encountered error in pulseidfile (ignoring file): " << e.what() << "\n";
return;
}
}
double temp;
if (num_pulses > 0)
{
this->pulsetimes.reserve(num_pulses);
for (size_t i=0; i < num_pulses; i++)
{
Pulse & it = (*pulses)[i];
this->pulsetimes.push_back( DateAndTime( (int64_t) it.seconds, (int64_t) it.nanoseconds) );
this->event_indices.push_back(it.event_index);
temp = it.pCurrent;
this->proton_charge.push_back(temp);
if (temp < 0.)
this->g_log.warning("Individual proton charge < 0 being ignored");
else
this->proton_charge_tot += temp;
}
}
this->proton_charge_tot = this->proton_charge_tot * CURRENT_CONVERSION;
//Clear the vector
delete pulses;
}
} // namespace DataHandling
} // namespace Mantid