er  dev
ERDigiCleaner.h
1 /********************************************************************************
2  * Copyright (C) Joint Institute for Nuclear Research *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #ifndef ERDigiCleaner_H
9 #define ERDigiCleaner_H
10 
11 #include <list>
12 #include <map>
13 #include <unordered_map>
14 #include <string>
15 
16 #include "TClonesArray.h"
17 #include "TString.h"
18 #include "TMatrixD.h"
19 #include "TCutG.h"
20 
21 #include "ERTask.h"
22 #include "ERBeamTimeEventHeader.h"
23 #include "ERBeamTimeCommon.h"
24 
25 class ERDigiCleaner : public ERTask {
26  using MultiplicityRange = std::pair<ushort, ushort>;
27 
28  public:
29 
31  TString fDetectorName;
32  TString fStationName;
33  TMatrixD* fPreviousTimeCalibration = nullptr;
34  TMatrixD* fTimeCalibration = nullptr;
35  TMatrixD* fPreviousAmpCalibration = nullptr;
36  TMatrixD* fAmpCalibration = nullptr;
37  TMatrixD* fPreviousTACCalibration = nullptr;
38  TMatrixD* fTACCalibration = nullptr;
39  ChannelMapping* fSim2RawChannelMapping = nullptr;
40  RecalibrationTask(const TString& detectorName, const TString& stationName,
41  TMatrixD* previousTimeCalibration, TMatrixD* timeCalibration,
42  TMatrixD* previousAmpCalibration, TMatrixD* ampCalibration,
43  TMatrixD* previousTACCalibration = nullptr, TMatrixD* TACCalibration = nullptr,
44  ChannelMapping* raw2SimChannelMapping = nullptr);
45  RecalibrationTask() = default;
46  };
47 
48  struct StationCuts {
49  TString fDetectorName;
50  TString fStationName;
51  std::map<ERChannel, TCutG*> fChannelGCuts;
52  std::map<ERChannel, Double_t> fChannelMinAmp;
53  std::map<ERChannel, Double_t> fChannelMaxAmp;
54  std::map<ERChannel, Double_t> fChannelMinTime;
55  std::map<ERChannel, Double_t> fChannelMaxTime;
56  ChannelMapping* fSim2RawChannelMapping = nullptr;
57  StationCuts(const TString& detectorName, const TString& stationName,
58  const std::map<ERChannel, TCutG*>& channelGCuts,
59  const std::map<ERChannel, Double_t>& channelMinAmp,
60  const std::map<ERChannel, Double_t>& channelMaxAmp,
61  const std::map<ERChannel, Double_t>& channelMinTime,
62  const std::map<ERChannel, Double_t>& channelMaxTime,
63  const ChannelMapping* raw2SimChannelMapping = nullptr);
64  StationCuts() = default;
65  };
66 
68  ERDigiCleaner();
69 
71  ~ERDigiCleaner() = default;
72 
74  virtual InitStatus Init();
75 
77  virtual void Exec(Option_t* opt);
78 
80  virtual void Reset();
81 
82  void Recalibrate(const TString& detectorName, const TString& stationName,
83  const TString& previousTimeCalFile, const TString& timeCalFile,
84  const TString& previousAmpCalFile, const TString& ampCalFile,
85  ChannelMapping* raw2SimChannelMapping = nullptr);
86  void RecalibrateWithTAC(const TString& detectorName, const TString& stationName,
87  const TString& previousTimeCalFile, const TString& timeCalFile,
88  const TString& previousAmpCalFile, const TString& ampCalFile,
89  const TString& previousTACCalFile, const TString& TACCalFile,
90  ChannelMapping* raw2SimChannelMapping = nullptr);
91  void SetLonelyMWPCClusterCondition() { fLonelyMWPCClusterCondition = true; }
92  void SetStationMultiplicity(const TString& detectorName, const TString& stationName,
93  ushort minMultiplicity, ushort maxMultiplicity) {
94  fStationsMultiplicities[std::make_pair(detectorName, stationName)] = std::make_pair(minMultiplicity, maxMultiplicity);
95  }
96  void SetChannelCuts(const TString& detectorName, const TString& stationName,
97  const std::map<ERChannel, TCutG*>& GCuts,
98  const std::map<ERChannel, Double_t>& MinAmp,
99  const std::map<ERChannel, Double_t>& MaxAmp,
100  const std::map<ERChannel, Double_t>& MinTime,
101  const std::map<ERChannel, Double_t>& MaxTime,
102  const ChannelMapping* raw2SimChannelMapping = nullptr);
103  protected:
104  bool AreFewClustersInMWPC();
105  void Recalibration();
106  void ApplyChannelCuts();
107  void ApplyStationMultiplicities();
108  void CopyEventHeader();
109  std::pair<std::string, TClonesArray*> GetBranchNameAndDigis(
110  const TString& detectorName, const TString& stationName);
111 
112  std::list<RecalibrationTask> fStationsRecalibrations;
113  std::list<StationCuts> fStationsCuts;
114  std::map<std::pair<TString, TString>, MultiplicityRange> fStationsMultiplicities;
115  bool fLonelyMWPCClusterCondition = false;
116 
117  std::unordered_map<std::string, TClonesArray*> fInputDigis;
118  ERBeamTimeEventHeader* fInputHeader = nullptr;
119 
120  private:
121  ClassDef(ERDigiCleaner,1)
122 };
123 
124 #endif
virtual void Exec(Option_t *opt)
virtual void Reset()
~ERDigiCleaner()=default
virtual InitStatus Init()
Base abstract class for all tasks in er.
Definition: ERTask.h:27