JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwMollerDetector.cc
Go to the documentation of this file.
1/**
2 * \file QwMollerDetector.cc
3 *
4 * \brief Implementation of the analysis of Moller data
5 *
6 * \author Andrew Kubera
7 * \date 2010-06-07
8 * \ingroup QwMoller
9 *
10 *
11 */
12
13#include "QwMollerDetector.h"
14
15// System headers
16#include <stdexcept>
17#include <iomanip>
18
19// ROOT headers
20#ifdef HAS_RNTUPLE_SUPPORT
21#include "ROOT/RNTupleModel.hxx"
22#include "ROOT/RField.hxx"
23#endif // HAS_RNTUPLE_SUPPORT
24
25// Qweak headers
26#include "QwLog.h"
27#include "QwParameterFile.h"
28#include "QwScaler_Channel.h"
29
30/**
31 * Load the channel map
32 * @param mapfile Map file
33 * @return Zero if successful
34 */
35
37{
38 TString varname, varvalue;
39 TString modtype, dettype, name, keyword;
40 Int_t modnum, channum;
41 Int_t wordsofar = 0;
42 Int_t currentsubbankindex = -1;
43
44 QwParameterFile mapstr(mapfile.Data()); // Open the file
45 fDetectorMapsNames.push_back(mapstr.GetParamFilename());
46 while (mapstr.ReadNextLine()) {
47 mapstr.TrimComment('!'); // Remove everything after a '!' character.
48 mapstr.TrimWhitespace(); // Get rid of leading and trailing whitespace (spaces or tabs).
49 if (mapstr.LineIsEmpty()) continue;
50
51 if (mapstr.HasVariablePair("=", varname, varvalue)) {
52 // This is a declaration line. Decode it.
53
54 varname.ToLower();
55
57 if(currentsubbankindex != GetSubbankIndex(fCurrentROC_ID,fCurrentBank_ID)){
58 currentsubbankindex = GetSubbankIndex(fCurrentROC_ID,fCurrentBank_ID);
59 }
60 } else {
61 Bool_t lineok = kTRUE;
62
63 // Break this line into tokens to process it.
64 modtype = mapstr.GetTypedNextToken<TString>();
65 modnum = mapstr.GetTypedNextToken<Int_t>();
66 channum = mapstr.GetTypedNextToken<Int_t>();
67 dettype = mapstr.GetTypedNextToken<TString>();
68 name = mapstr.GetTypedNextToken<TString>();
69 dettype.ToLower();
70 name.ToLower();
71
72 QwMollerChannelID newChannelID;
73 newChannelID.fModuleType = modtype;
74 newChannelID.fModuleNumber = modnum;
75 newChannelID.fChannelName = name;
76 newChannelID.fDetectorType = dettype;
77 newChannelID.fChannelNumber = channum;
78 newChannelID.fWordInSubbank = wordsofar;
79
80 if (modtype == "SIS3801"){
81 wordsofar += 1;
82 }else if(modtype == "SIS7200"){
83 wordsofar += 1;
84 }else if(modtype == "VQWK"){
85 wordsofar += 6;
86 }else {
87 std::cerr << "Unknown module type: " << modtype << ". Skipping channel " << name << '.' << std::endl;
88 lineok = kFALSE;
89 }
90
91 if (name.Length() == 0){
92 lineok = kFALSE;
93 }
94
95// add new modules until current number (modnum) is reached
96 std::size_t chan_size;
97 chan_size = fSTR7200_Channel.size();
98 while ((Int_t) chan_size <= modnum) {
99 std::vector<QwSTR7200_Channel> new_module;
100 fSTR7200_Channel.push_back(new_module);
101 }
102
103 //change this line if names are supposed to be exclusive, as of now,
104 newChannelID.fIndex = -1; // GetChannelIndex(name, modnum);
105
106 if (newChannelID.fIndex == -1 && lineok){
107 QwSTR7200_Channel localSTR7200_Channel(newChannelID.fChannelName);
108 fSTR7200_Channel[modnum].push_back(localSTR7200_Channel);
109// fSTR7200_Channel[modnum][fMollerChannelID.size() - 1].SetDefaultSampleSize(fSample_size);
110 newChannelID.fIndex = fSTR7200_Channel[modnum].size() - 1;
111 //std::cout << name << ':' << newChannelID.fIndex << ':' << wordsofar << '\n';
112 }
113
114 // Push a new record into the element array
115 if(lineok){
116 fMollerChannelID.push_back(newChannelID);
117 }
118 }
119 } // end looping over parameter file
120
122
123// for (size_t i = 0; i < fMollerChannelID.size(); i++){
124// std::cout << i << ": " << fMollerChannelID[i].fChannelName << ' ' << fMollerChannelID[i].fChannelNumber << ' ' << fMollerChannelID[i].fIndex << std::endl;
125// }
126
127 return 0;
128}
129
133
134
135Int_t QwMollerDetector::ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words)
136{
137 return 0;
138}
139
140Int_t QwMollerDetector::ProcessConfigurationBuffer(UInt_t ev_type, const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words)
141{
142 return 0;
143}
144
145Int_t QwMollerDetector::ProcessEvBuffer(UInt_t ev_type, const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
146{
147 return ProcessEvBuffer(roc_id, bank_id, buffer, num_words);
148}
149
150Int_t QwMollerDetector::ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
151{
152 Int_t index = 0; // GetSubbankIndex(roc_id, bank_id);
153
154 if (index >= 0 && num_words > 0){
155 //we want to process this ROC
156
157 //Loop through all the channels as defined in map file.. should be 96 in standard 3 module, 32 channel Moller configuration
158 for(size_t i = 0; i < fMollerChannelID.size(); i++){
159
160 Int_t wordsLeft = num_words - fMollerChannelID[i].fWordInSubbank;
161
162// std::cout << std::dec << fMollerChannelID[i].fChannelName << ' ' << fMollerChannelID[i].fIndex << " in module " << fMollerChannelID[i].fModuleNumber << " has data " << std::hex << buffer[fMollerChannelID[i].fWordInSubbank] << std::dec << std::endl;
163
164 UInt_t mod_index = fMollerChannelID[i].fModuleNumber;
165 Int_t chan_index = fMollerChannelID[i].fIndex;
166// char *junk = new char[2];
167 if (mod_index < fSTR7200_Channel.size()) {
168 //mod_index should be less than 3, next_module is reference to vector where the Channel should be located
169 // std::cout << std::hex << buffer[fMollerChannelID[i].fWordInSubbank] << '\n';
170 //std::cin.getline(junk, 1);
171// std::cout << '(' << mod_index << ',' << chan_index << ')' << buffer[fMollerChannelID[i].fWordInSubbank] - fSTR7200_Channel[mod_index][chan_index].GetValue() << ' ' << std::endl;
172
173 fSTR7200_Channel[mod_index][chan_index].ProcessEvBuffer(&(buffer[fMollerChannelID[i].fWordInSubbank]), wordsLeft);
174 } else {
175 std::cout << "Problem reading buffer, incorrect structure of map file?" << std::endl;
176 }
177
178 }
179 }
180// std::cout << fSTR7200_Channel[2][0].GetValue() << std::endl;
181// print();
182 return 0;
183}
184
185
186
188{
189 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
190 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
191 fSTR7200_Channel[i][j].ProcessEvent();
192 QwSTR7200_Channel tempscaler(fSTR7200_Channel[i][j]);
193 tempscaler = fSTR7200_Channel[i][j];
195 fPrevious_STR7200_Channel[i][j] = tempscaler;
196 // Store a temporary copy of this channel's raw value as a scaler channel
197 // Subtract the corresponding fPrevious_STR7200_Channel from this scaler channel
198 // Put the temporary copy into the fPrevious_STR7200_Channel
199 }
200 }
201}
202
203
204void QwMollerDetector::ConstructHistograms(TDirectory* folder, TString& prefix){
205 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
206 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
207 fSTR7200_Channel[i][j].ConstructHistograms(folder, prefix);
208 }
209 }
210}
211
213 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
214 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
215 fSTR7200_Channel[i][j].FillHistograms();
216 }
217 }
218}
219
220void QwMollerDetector::ConstructBranchAndVector(TTree *tree, TString & prefix, QwRootTreeBranchVector &values){
221 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
222 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
223 fSTR7200_Channel[i][j].ConstructBranchAndVector(tree, prefix, values);
224 }
225 }
226}
227
229 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
230 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
231 fSTR7200_Channel[i][j].FillTreeVector(values);
232 }
233 }
234}
235
236#ifdef HAS_RNTUPLE_SUPPORT
237void QwMollerDetector::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
238{
239 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
240 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
241 fSTR7200_Channel[i][j].ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
242 }
243 }
244}
245
246void QwMollerDetector::FillNTupleVector(std::vector<Double_t>& values) const
247{
248 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
249 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
250 fSTR7200_Channel[i][j].FillNTupleVector(values);
251 }
252 }
253}
254#endif // HAS_RNTUPLE_SUPPORT
255
257 // std::cout << "QwMollerDetector assignment (operator=)" << std::endl;
258 if(this != value && Compare(value)){
260 QwMollerDetector* input = dynamic_cast<QwMollerDetector *> (value);
261 for(size_t i = 0; i < input->fSTR7200_Channel.size(); i++){
262 for(size_t j = 0; j < input->fSTR7200_Channel[i].size(); j++){
263 this->fSTR7200_Channel[i][j] = input->fSTR7200_Channel[i][j];
264 }
265 }
266 }
267 return *this;
268}
269
271 //std::cout << "QwMollerDetector addition assignment (operator+=)" << std::endl;
272 if(Compare(value)){
273 QwMollerDetector* input = dynamic_cast<QwMollerDetector *> (value);
274 for(size_t i = 0; i < input->fSTR7200_Channel.size(); i++){
275 for(size_t j = 0; j < input->fSTR7200_Channel[i].size(); j++){
276 this->fSTR7200_Channel[i][j] += input->fSTR7200_Channel[i][j];
277 //std::cout << "+= " << this->fSTR7200_Channel[i][j].GetValue() << std::endl;
278 }
279 }
280 }
281 return *this;
282}
283
285 //std::cout << "QwMollerDetector subtraction assignment (operator-=)" << std::endl;
286 if(Compare(value)){
287 QwMollerDetector* input = dynamic_cast<QwMollerDetector *> (value);
288 for(size_t i = 0; i < input->fSTR7200_Channel.size(); i++){
289 for(size_t j = 0; j < input->fSTR7200_Channel[i].size(); j++){
290 this->fSTR7200_Channel[i][j] -= input->fSTR7200_Channel[i][j];
291 }
292 }
293 }
294 return *this;
295}
296
298 if (Compare(value1) && Compare(value2)) {
299 QwMollerDetector* v1 = dynamic_cast<QwMollerDetector *> (value1);
300 QwMollerDetector* v2 = dynamic_cast<QwMollerDetector *> (value2);
301
302 for(size_t i = 0; i < v1->fSTR7200_Channel.size(); i++){
303 for(size_t j = 0; j < v1->fSTR7200_Channel[i].size(); j++){
304 fSTR7200_Channel[i][j].Ratio(v1->fSTR7200_Channel[i][j],v2->fSTR7200_Channel[i][j]);
305 }
306 }
307 }
308 return;
309}
310
311void QwMollerDetector::Scale(Double_t factor){
312 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
313 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
314 fSTR7200_Channel[i][j].Scale(factor);
315 }
316 }
317}
318
319void QwMollerDetector::AccumulateRunningSum(VQwSubsystem* value, Int_t count, Int_t ErrorMask){
320 if (Compare(value)) {
321 QwMollerDetector* v = dynamic_cast<QwMollerDetector*>(value);
322
323 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
324 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
325 fSTR7200_Channel[i][j].AccumulateRunningSum(v->fSTR7200_Channel[i][j], count, ErrorMask);
326 }
327 }
328
329 }
330}
331
333 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
334 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
335 fSTR7200_Channel[i][j].CalculateRunningAverage();
336 }
337 }
338}
339
340Int_t QwMollerDetector::LoadEventCuts(TString filename){return 0;}
341
343 std::cout << "QwMoller::ApplySingleEventCuts() ";
344 Bool_t test = kTRUE, test_1 = kTRUE;
345
346 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
347 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
348 test_1 = fSTR7200_Channel[i][j].ApplySingleEventCuts();
349 test &= test_1;
350 if(!test_1 && bDEBUG){
351 std::cout << "***** QwMoller::SingleEventCuts()->Channel[" << i << "][" << j << "]:" << fSTR7200_Channel[i][j].GetElementName() << std::endl;
352 }
353 }
354 }
355 return test;
356}
357
359 std::cout << "***************QwMoller Error Summary****************" << std::endl;
360 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
361 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
362 fSTR7200_Channel[i][j].PrintErrorCounters();
363 }
364 }
365 std::cout << "total failed events: " << fQwMollerErrorCount << std::endl;
366 std::cout << "************End QwMoller Error Summary***************" << std::endl;
367}
368
370 return 0;
371}
372
374 size_t len = 0;
375 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
376 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
377 len++;
378 }
379 }
380 float *result = new float[len];
381
382 //float result[96];
383
384 int n = 0;
385 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
386 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
387 result[n+j] = fSTR7200_Channel[i][j].GetValue();
388 }
389 n=fSTR7200_Channel[i].size();
390 }
391
392 return result;
393}
394
395Int_t QwMollerDetector::GetChannelIndex(TString channelName, UInt_t module_number)
396{
397 Bool_t ldebug=kFALSE;
398
399 channelName.ToLower();
400
401 if (ldebug){
402 std::cout << "QwMollerDetector::GetDetectorIndex" << std::endl;
403 std::cout << "module_number: " << module_number << " name=" << channelName << std::endl;
404 }
405
406 Int_t result = -1;
407 for(size_t i = 0; i < fMollerChannelID.size(); i++){
408 QwMollerChannelID *nextChannel = &fMollerChannelID[i];
409 //std::cout << ' '<< nextChannel->fChannelName << '=' << channelName << ':' << (nextChannel->fChannelName == channelName) << std::endl;
410 if (nextChannel->fChannelName == channelName && nextChannel->fModuleNumber == module_number){
411 result = nextChannel->fIndex;
412 break;
413 }
414 }
415
416 return result;
417}
418
419
421 //std::cout << "Beginning QwMollerDetector::Compare" << std::endl;
422
423 if (source == 0) return kFALSE;
424
425 Bool_t result = kTRUE;
426 if(typeid(*source) != typeid(*this)){
427 result = kFALSE;
428 std::cout << " Type mismatch! This is bypassed for now but should be fixed eventually." << std::endl;
429 } else { //same type, test for # of modules
430 QwMollerDetector* input = dynamic_cast<QwMollerDetector*>(source);
431 if(input->fSTR7200_Channel.size() != fSTR7200_Channel.size()){
432 result = kFALSE;
433 std::cout << " Not the same number of Modules" << std::endl;
434 }else { //same # modules, loop through and make sure each one has same amount of channels
435 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
436 if(input->fSTR7200_Channel[i].size() != fSTR7200_Channel[i].size()){
437 result = kFALSE;
438 std::cout << " Different number of channels in module " << i << std::endl;
439 }
440 }
441 }
442 }
443 return result;
444}
445
447 std::cout << " " << fSTR7200_Channel.size() << std::endl;
448 UInt_t max = 0;
449 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
450 UInt_t next = fSTR7200_Channel[i].size();
451 if (next > max){
452 max = next;
453 }
454 }
455
456 for(size_t i = 0; i < max; i++){
457 std::cout << fMollerChannelID[i].fChannelName << ":\t" << (fMollerChannelID[i].fChannelName.Length() < 14 ? "\t" : "");
458 for(size_t j = 0; j < fSTR7200_Channel.size(); j++){
459
460 if ( i < fSTR7200_Channel[j].size()){
461 std::cout << "0x" << std::hex << (int)fSTR7200_Channel[j][i].GetValue() << std::dec;
462 } else {
463 std::cout << " ";
464 }
465 std::cout << "\t\t";
466 }
467 std::cout << std::endl;
468 }
469
470}
471
473 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
474 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
475 fSTR7200_Channel[i][j].PrintValue();
476 }
477 }
478}
Base and derived classes for scaler channel data handling.
class QwScaler_Channel< 0xffffffff, 0 > QwSTR7200_Channel
A logfile class, based on an identical class in the Hermes analyzer.
Parameter file parsing and management.
ULong64_t BankID_t
Definition QwTypes.h:21
UInt_t ROCID_t
Definition QwTypes.h:20
Moller detector analysis implementation.
Command-line and configuration file options processor.
Definition QwOptions.h:141
Configuration file parser with flexible tokenization and search capabilities.
const TString GetParamFilename()
T GetTypedNextToken()
Get next token into specific type.
void TrimWhitespace(TString::EStripType head_tail=TString::kBoth)
Bool_t HasVariablePair(const std::string &separatorchars, std::string &varname, std::string &varvalue)
void TrimComment(const char commentchar)
A helper class to manage a vector of branch entries for ROOT trees.
Definition QwRootFile.h:55
BankID_t fCurrentBank_ID
Bank ID (and Marker word) that is currently being processed;.
Int_t GetSubbankIndex() const
std::vector< TString > fDetectorMapsNames
Names of loaded detector map files.
virtual VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
void RegisterRocBankMarker(QwParameterFile &mapstr)
VQwSubsystem(const TString &name)
Constructor with name.
ROCID_t fCurrentROC_ID
ROC ID that is currently being processed.
Mapping info for Moller detector channels.
std::vector< std::vector< QwSTR7200_Channel > > fPrevious_STR7200_Channel
void FillHistograms() override
Fill the histograms for this subsystem.
Int_t ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware v...
std::vector< std::vector< QwSTR7200_Channel > > fSTR7200_Channel
void CalculateRunningAverage() override
Calculate the average for all good events.
void ProcessOptions(QwOptions &options) override
Process the command line options.
static const Bool_t bDEBUG
VQwSubsystem & operator-=(VQwSubsystem *value) override
void Ratio(VQwSubsystem *value1, VQwSubsystem *value2) override
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Bool_t Compare(VQwSubsystem *source)
UInt_t GetEventcutErrorFlag() override
Return the error flag to the top level routines related to stability checks and ErrorFlag updates.
void PrintValue() const override
Print values of all channels.
void ProcessEvent() override
void PrintErrorCounters() const override
VQwSubsystem & operator=(VQwSubsystem *value) override
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
Int_t ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words) override
Int_t LoadEventCuts(TString &filename)
void AccumulateRunningSum(VQwSubsystem *value, Int_t count=0, Int_t ErrorMask=0xFFFFFFF) override
Update the running sums for devices.
Int_t LoadInputParameters(TString pedestalfile) override
Mandatory parameter file definition.
Bool_t ApplySingleEventCuts() override
Apply the single event cuts.
void ConstructBranchAndVector(TTree *, TString &, QwRootTreeBranchVector &) override
Construct the branch and tree vector.
void Scale(Double_t) override
VQwSubsystem & operator+=(VQwSubsystem *value) override
Int_t LoadChannelMap(TString mapfile) override
void ClearEventData() override
QwMollerDetector()
Private default constructor (not implemented, will throw linker error on use)
Int_t GetChannelIndex(TString channelName, UInt_t module_number)
void FillTreeVector(QwRootTreeBranchVector &values) const override
Fill the tree vector.
std::vector< QwMollerChannelID > fMollerChannelID