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// Register this subsystem with the factory
32
33/**
34 * Load the channel map
35 * @param mapfile Map file
36 * @return Zero if successful
37 */
38
40{
41 TString varname, varvalue;
42 TString modtype, dettype, name, keyword;
43 Int_t modnum, channum;
44 Int_t wordsofar = 0;
45 Int_t currentsubbankindex = -1;
46
47 QwParameterFile mapstr(mapfile.Data()); // Open the file
48 fDetectorMapsNames.push_back(mapstr.GetParamFilename());
49 while (mapstr.ReadNextLine()) {
50 mapstr.TrimComment('!'); // Remove everything after a '!' character.
51 mapstr.TrimWhitespace(); // Get rid of leading and trailing whitespace (spaces or tabs).
52 if (mapstr.LineIsEmpty()) continue;
53
54 if (mapstr.HasVariablePair("=", varname, varvalue)) {
55 // This is a declaration line. Decode it.
56
57 varname.ToLower();
58
60 if(currentsubbankindex != GetSubbankIndex(fCurrentROC_ID,fCurrentBank_ID)){
61 currentsubbankindex = GetSubbankIndex(fCurrentROC_ID,fCurrentBank_ID);
62 }
63 } else {
64 Bool_t lineok = kTRUE;
65
66 // Break this line into tokens to process it.
67 modtype = mapstr.GetTypedNextToken<TString>();
68 modnum = mapstr.GetTypedNextToken<Int_t>();
69 channum = mapstr.GetTypedNextToken<Int_t>();
70 dettype = mapstr.GetTypedNextToken<TString>();
71 name = mapstr.GetTypedNextToken<TString>();
72 dettype.ToLower();
73 name.ToLower();
74
75 QwMollerChannelID newChannelID;
76 newChannelID.fModuleType = modtype;
77 newChannelID.fModuleNumber = modnum;
78 newChannelID.fChannelName = name;
79 newChannelID.fDetectorType = dettype;
80 newChannelID.fChannelNumber = channum;
81 newChannelID.fWordInSubbank = wordsofar;
82
83 if (modtype == "SIS3801"){
84 wordsofar += 1;
85 }else if(modtype == "SIS7200"){
86 wordsofar += 1;
87 }else if(modtype == "VQWK"){
88 wordsofar += 6;
89 }else {
90 std::cerr << "Unknown module type: " << modtype << ". Skipping channel " << name << '.' << std::endl;
91 lineok = kFALSE;
92 }
93
94 if (name.Length() == 0){
95 lineok = kFALSE;
96 }
97
98// add new modules until current number (modnum) is reached
99 std::size_t chan_size;
100 chan_size = fSTR7200_Channel.size();
101 while ((Int_t) chan_size <= modnum) {
102 std::vector<QwSTR7200_Channel> new_module;
103 fSTR7200_Channel.push_back(new_module);
104 }
105
106 //change this line if names are supposed to be exclusive, as of now,
107 newChannelID.fIndex = -1; // GetChannelIndex(name, modnum);
108
109 if (newChannelID.fIndex == -1 && lineok){
110 QwSTR7200_Channel localSTR7200_Channel(newChannelID.fChannelName);
111 fSTR7200_Channel[modnum].push_back(localSTR7200_Channel);
112// fSTR7200_Channel[modnum][fMollerChannelID.size() - 1].SetDefaultSampleSize(fSample_size);
113 newChannelID.fIndex = fSTR7200_Channel[modnum].size() - 1;
114 //std::cout << name << ':' << newChannelID.fIndex << ':' << wordsofar << '\n';
115 }
116
117 // Push a new record into the element array
118 if(lineok){
119 fMollerChannelID.push_back(newChannelID);
120 }
121 }
122 } // end looping over parameter file
123
125
126// for (size_t i = 0; i < fMollerChannelID.size(); i++){
127// std::cout << i << ": " << fMollerChannelID[i].fChannelName << ' ' << fMollerChannelID[i].fChannelNumber << ' ' << fMollerChannelID[i].fIndex << std::endl;
128// }
129
130 return 0;
131}
132
136
137
138Int_t QwMollerDetector::ProcessConfigurationBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words)
139{
140 return 0;
141}
142
143Int_t QwMollerDetector::ProcessConfigurationBuffer(UInt_t ev_type, const ROCID_t roc_id, const BankID_t bank_id, UInt_t* buffer, UInt_t num_words)
144{
145 return 0;
146}
147
148Int_t QwMollerDetector::ProcessEvBuffer(UInt_t ev_type, const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
149{
150 return ProcessEvBuffer(roc_id, bank_id, buffer, num_words);
151}
152
153Int_t QwMollerDetector::ProcessEvBuffer(const ROCID_t roc_id, const BankID_t bank_id, UInt_t *buffer, UInt_t num_words)
154{
155 Int_t index = 0; // GetSubbankIndex(roc_id, bank_id);
156
157 if (index >= 0 && num_words > 0){
158 //we want to process this ROC
159
160 //Loop through all the channels as defined in map file.. should be 96 in standard 3 module, 32 channel Moller configuration
161 for(size_t i = 0; i < fMollerChannelID.size(); i++){
162
163 Int_t wordsLeft = num_words - fMollerChannelID[i].fWordInSubbank;
164
165// 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;
166
167 UInt_t mod_index = fMollerChannelID[i].fModuleNumber;
168 Int_t chan_index = fMollerChannelID[i].fIndex;
169// char *junk = new char[2];
170 if (mod_index < fSTR7200_Channel.size()) {
171 //mod_index should be less than 3, next_module is reference to vector where the Channel should be located
172 // std::cout << std::hex << buffer[fMollerChannelID[i].fWordInSubbank] << '\n';
173 //std::cin.getline(junk, 1);
174// std::cout << '(' << mod_index << ',' << chan_index << ')' << buffer[fMollerChannelID[i].fWordInSubbank] - fSTR7200_Channel[mod_index][chan_index].GetValue() << ' ' << std::endl;
175
176 fSTR7200_Channel[mod_index][chan_index].ProcessEvBuffer(&(buffer[fMollerChannelID[i].fWordInSubbank]), wordsLeft);
177 } else {
178 std::cout << "Problem reading buffer, incorrect structure of map file?" << std::endl;
179 }
180
181 }
182 }
183// std::cout << fSTR7200_Channel[2][0].GetValue() << std::endl;
184// print();
185 return 0;
186}
187
188
189
191{
192 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
193 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
194 fSTR7200_Channel[i][j].ProcessEvent();
195 QwSTR7200_Channel tempscaler(fSTR7200_Channel[i][j]);
196 tempscaler = fSTR7200_Channel[i][j];
198 fPrevious_STR7200_Channel[i][j] = tempscaler;
199 // Store a temporary copy of this channel's raw value as a scaler channel
200 // Subtract the corresponding fPrevious_STR7200_Channel from this scaler channel
201 // Put the temporary copy into the fPrevious_STR7200_Channel
202 }
203 }
204}
205
206
207void QwMollerDetector::ConstructHistograms(TDirectory* folder, TString& prefix){
208 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
209 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
210 fSTR7200_Channel[i][j].ConstructHistograms(folder, prefix);
211 }
212 }
213}
214
216 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
217 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
218 fSTR7200_Channel[i][j].FillHistograms();
219 }
220 }
221}
222
223void QwMollerDetector::ConstructBranchAndVector(TTree *tree, TString & prefix, QwRootTreeBranchVector &values){
224 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
225 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
226 fSTR7200_Channel[i][j].ConstructBranchAndVector(tree, prefix, values);
227 }
228 }
229}
230
232 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
233 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
234 fSTR7200_Channel[i][j].FillTreeVector(values);
235 }
236 }
237}
238
239#ifdef HAS_RNTUPLE_SUPPORT
240void QwMollerDetector::ConstructNTupleAndVector(std::unique_ptr<ROOT::RNTupleModel>& model, TString& prefix, std::vector<Double_t>& values, std::vector<std::shared_ptr<Double_t>>& fieldPtrs)
241{
242 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
243 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
244 fSTR7200_Channel[i][j].ConstructNTupleAndVector(model, prefix, values, fieldPtrs);
245 }
246 }
247}
248
249void QwMollerDetector::FillNTupleVector(std::vector<Double_t>& values) const
250{
251 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
252 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
253 fSTR7200_Channel[i][j].FillNTupleVector(values);
254 }
255 }
256}
257#endif // HAS_RNTUPLE_SUPPORT
258
260 // std::cout << "QwMollerDetector assignment (operator=)" << std::endl;
261 if(this != value && Compare(value)){
262 //VQwSubsystem::operator=(value);
263 QwMollerDetector* input = dynamic_cast<QwMollerDetector *> (value);
264 for(size_t i = 0; i < input->fSTR7200_Channel.size(); i++){
265 for(size_t j = 0; j < input->fSTR7200_Channel[i].size(); j++){
266 this->fSTR7200_Channel[i][j] = input->fSTR7200_Channel[i][j];
267 }
268 }
269 }
270 return *this;
271}
272
274 //std::cout << "QwMollerDetector addition assignment (operator+=)" << std::endl;
275 if(Compare(value)){
276 QwMollerDetector* input = dynamic_cast<QwMollerDetector *> (value);
277 for(size_t i = 0; i < input->fSTR7200_Channel.size(); i++){
278 for(size_t j = 0; j < input->fSTR7200_Channel[i].size(); j++){
279 this->fSTR7200_Channel[i][j] += input->fSTR7200_Channel[i][j];
280 //std::cout << "+= " << this->fSTR7200_Channel[i][j].GetValue() << std::endl;
281 }
282 }
283 }
284 return *this;
285}
286
288 //std::cout << "QwMollerDetector subtraction assignment (operator-=)" << std::endl;
289 if(Compare(value)){
290 QwMollerDetector* input = dynamic_cast<QwMollerDetector *> (value);
291 for(size_t i = 0; i < input->fSTR7200_Channel.size(); i++){
292 for(size_t j = 0; j < input->fSTR7200_Channel[i].size(); j++){
293 this->fSTR7200_Channel[i][j] -= input->fSTR7200_Channel[i][j];
294 }
295 }
296 }
297 return *this;
298}
299
301 if (Compare(value1) && Compare(value2)) {
302 QwMollerDetector* v1 = dynamic_cast<QwMollerDetector *> (value1);
303 QwMollerDetector* v2 = dynamic_cast<QwMollerDetector *> (value2);
304
305 for(size_t i = 0; i < v1->fSTR7200_Channel.size(); i++){
306 for(size_t j = 0; j < v1->fSTR7200_Channel[i].size(); j++){
307 fSTR7200_Channel[i][j].Ratio(v1->fSTR7200_Channel[i][j],v2->fSTR7200_Channel[i][j]);
308 }
309 }
310 }
311 return;
312}
313
314void QwMollerDetector::Scale(Double_t factor){
315 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
316 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
317 fSTR7200_Channel[i][j].Scale(factor);
318 }
319 }
320}
321
322void QwMollerDetector::AccumulateRunningSum(VQwSubsystem* value, Int_t count, Int_t ErrorMask){
323 if (Compare(value)) {
324 QwMollerDetector* v = dynamic_cast<QwMollerDetector*>(value);
325
326 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
327 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
328 fSTR7200_Channel[i][j].AccumulateRunningSum(v->fSTR7200_Channel[i][j], count, ErrorMask);
329 }
330 }
331
332 }
333}
334
336 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
337 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
338 fSTR7200_Channel[i][j].CalculateRunningAverage();
339 }
340 }
341}
342
343Int_t QwMollerDetector::LoadEventCuts(TString filename){return 0;}
344
346 std::cout << "QwMoller::ApplySingleEventCuts() ";
347 Bool_t test = kTRUE, test_1 = kTRUE;
348
349 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
350 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
351 test_1 = fSTR7200_Channel[i][j].ApplySingleEventCuts();
352 test &= test_1;
353 if(!test_1 && bDEBUG){
354 std::cout << "***** QwMoller::SingleEventCuts()->Channel[" << i << "][" << j << "]:" << fSTR7200_Channel[i][j].GetElementName() << std::endl;
355 }
356 }
357 }
358 return test;
359}
360
362 std::cout << "***************QwMoller Error Summary****************" << std::endl;
363 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
364 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
365 fSTR7200_Channel[i][j].PrintErrorCounters();
366 }
367 }
368 std::cout << "total failed events: " << fQwMollerErrorCount << std::endl;
369 std::cout << "************End QwMoller Error Summary***************" << std::endl;
370}
371
373 return 0;
374}
375
377 size_t len = 0;
378 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
379 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
380 len++;
381 }
382 }
383 float *result = new float[len];
384
385 //float result[96];
386
387 int n = 0;
388 for (size_t i = 0; i < fSTR7200_Channel.size(); i++){
389 for (size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
390 result[n+j] = fSTR7200_Channel[i][j].GetValue();
391 }
392 n=fSTR7200_Channel[i].size();
393 }
394
395 return result;
396}
397
398Int_t QwMollerDetector::GetChannelIndex(TString channelName, UInt_t module_number)
399{
400 Bool_t ldebug=kFALSE;
401
402 channelName.ToLower();
403
404 if (ldebug){
405 std::cout << "QwMollerDetector::GetDetectorIndex" << std::endl;
406 std::cout << "module_number: " << module_number << " name=" << channelName << std::endl;
407 }
408
409 Int_t result = -1;
410 for(size_t i = 0; i < fMollerChannelID.size(); i++){
411 QwMollerChannelID *nextChannel = &fMollerChannelID[i];
412 //std::cout << ' '<< nextChannel->fChannelName << '=' << channelName << ':' << (nextChannel->fChannelName == channelName) << std::endl;
413 if (nextChannel->fChannelName == channelName && nextChannel->fModuleNumber == module_number){
414 result = nextChannel->fIndex;
415 break;
416 }
417 }
418
419 return result;
420}
421
422
424 //std::cout << "Beginning QwMollerDetector::Compare" << std::endl;
425
426 if (source == 0) return kFALSE;
427
428 Bool_t result = kTRUE;
429 if(typeid(*source) != typeid(*this)){
430 result = kFALSE;
431 std::cout << " Type mismatch! This is bypassed for now but should be fixed eventually." << std::endl;
432 } else { //same type, test for # of modules
433 QwMollerDetector* input = dynamic_cast<QwMollerDetector*>(source);
434 if(input->fSTR7200_Channel.size() != fSTR7200_Channel.size()){
435 result = kFALSE;
436 std::cout << " Not the same number of Modules" << std::endl;
437 }else { //same # modules, loop through and make sure each one has same amount of channels
438 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
439 if(input->fSTR7200_Channel[i].size() != fSTR7200_Channel[i].size()){
440 result = kFALSE;
441 std::cout << " Different number of channels in module " << i << std::endl;
442 }
443 }
444 }
445 }
446 return result;
447}
448
450 std::cout << " " << fSTR7200_Channel.size() << std::endl;
451 UInt_t max = 0;
452 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
453 UInt_t next = fSTR7200_Channel[i].size();
454 if (next > max){
455 max = next;
456 }
457 }
458
459 for(size_t i = 0; i < max; i++){
460 std::cout << fMollerChannelID[i].fChannelName << ":\t" << (fMollerChannelID[i].fChannelName.Length() < 14 ? "\t" : "");
461 for(size_t j = 0; j < fSTR7200_Channel.size(); j++){
462
463 if ( i < fSTR7200_Channel[j].size()){
464 std::cout << "0x" << std::hex << (int)fSTR7200_Channel[j][i].GetValue() << std::dec;
465 } else {
466 std::cout << " ";
467 }
468 std::cout << "\t\t";
469 }
470 std::cout << std::endl;
471 }
472
473}
474
476 for(size_t i = 0; i < fSTR7200_Channel.size(); i++){
477 for(size_t j = 0; j < fSTR7200_Channel[i].size(); j++){
478 fSTR7200_Channel[i][j].PrintValue();
479 }
480 }
481}
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.
#define REGISTER_SUBSYSTEM_FACTORY(A)
Definition QwFactory.h:270
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:53
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.
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.
Subsystem for analyzing Moller detector readout.
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