DAQQuickClustering_module.h
Go to the documentation of this file.
1 #ifndef DAQQUICKCLUSTERING_H
2 #define DAQQUICKCLUSTERING_H
3 // C++ includes
4 
5 // ROOT includes
6 #include "TH1I.h"
7 #include "TH1F.h"
8 #include "TH2F.h"
9 #include "TTree.h"
10 #include "TGraph.h"
11 #include "TStopwatch.h"
12 
13 // Framework includes
17 #include "lardataobj/RawData/raw.h"
21 
25 
32 #include "art_root_io/TFileDirectory.h"
33 #include "art_root_io/TFileService.h"
36 #include "canvas/Persistency/Common/FindMany.h"
37 #include "canvas/Persistency/Common/FindManyP.h"
38 #include "fhiclcpp/ParameterSet.h"
41 
43 
44 const int nMaxHits=100000;
45 
46 class recoHit
47 {
48  public:
49  recoHit(int cEvent, int cHitView, int cGenType, int cHitChan,
50  float cHitTime, float cHitSADC, float cHitRMS):fEvent (cEvent ),
51  fHitView(cHitView),
52  fGenType(cGenType),
53  fHitChan(cHitChan),
54  fHitSADC(cHitSADC),
55  fHitRMS (cHitRMS ),
56  fHitTime(cHitTime)
57  {
58  };
59  friend bool operator<(recoHit lhs, recoHit rhs);
60 
61  int getEvent () const { return fEvent ; };
62  int getHitView() const { return fHitView; };
63  int getGenType() const { return fGenType; };
64  int getHitChan() const { return fHitChan; };
65  float getHitTime() const { return fHitTime; };
66  float getHitSADC() const { return fHitSADC; };
67  float getHitRMS () const { return fHitRMS; };
68  void Print () const
69  {
70  std::cout << "fHitView " << fHitView
71  << ", fGenType " << fGenType
72  << ", fHitChan " << fHitChan
73  << ", fHitSADC " << fHitSADC
74  << ", fHitRMS " << fHitRMS
75  << ", fHitTime " << fHitTime
76  << std::endl;
77  };
78 
79  private:
80  int fEvent = 0;
81  int fHitView = 0;
82  int fGenType = 0;
83  int fHitChan = 0;
84  float fHitSADC = 0;
85  float fHitRMS = 0;
86  float fHitTime = 0;
87 
88 };
89 
90 bool operator<(recoHit lhs, recoHit rhs){
91  if(lhs.fHitTime<rhs.fHitTime)
92  return true;
93  return false;
94 }
95 
96 class cluster
97 {
98  public:
99  cluster(int cEvent, std::vector<recoHit> cHitVector);
100  cluster();
101 
102  int getEvent () const { return fEvent ; };
103  int getStartChan () const { return fStartChan ; };
104  int getEndChan () const { return fEndChan ; };
105  int getNChan () const { return fNChan ; };
106  int getChanWidth () const { return fChanWidth ; };
107  int getNHits () const { return fNHits ; };
108  int getType () const { return fType ; };
109  int getTriggerFlag () const { return fTriggerFlag ; };
110  float getHitSADC () const { return fHitSADC ; };
111  float getFirstTimeHit() const { return fFirstHitTime; };
112  float getLastTimeHit () const { return fLastHitTime ; };
113  float getTimeWidth () const { return fTimeWidth ; };
114  double getMC_EnergyNu () const { return fMC_EnergyNu ; };
115  double getMC_EnergyLep() const { return fMC_EnergyLep; };
116  double getMC_MarlTime () const { return fMC_MarlTime ; };
117 
118  std::vector<recoHit> getHits() const { return fHitVector; };
119 
120  void setHitSADC (float cHitSADC ) { fHitSADC = cHitSADC ; };
121  void setTriggerFlag (int cTriggerFlag ) { fTriggerFlag = cTriggerFlag ; };
122  void setMC_EnergyNu (double cMC_EnergyNu ) { fMC_EnergyNu = cMC_EnergyNu ; };
123  void setMC_EnergyLep(double cMC_EnergyLep) { fMC_EnergyLep = cMC_EnergyLep; };
124  void setMC_MarlTime (double cMC_Marltime ) { fMC_MarlTime = cMC_Marltime ; };
125 
126  void printCluster() const
127  {
128  std::cout << "*********************" << std::endl;
129  std::cout << "Event " << fEvent << std::endl;
130  std::cout << "StartChan " << fStartChan << std::endl;
131  std::cout << "EndChan " << fEndChan << std::endl;
132  std::cout << "NChan " << fNChan << std::endl;
133  std::cout << "ChanWidth " << fChanWidth << std::endl;
134  std::cout << "NHits " << fNHits << std::endl;
135  std::cout << "Type " << fType << std::endl;
136  std::cout << "TriggerFlag " << fTriggerFlag << std::endl;
137  std::cout << "HitSADC " << fHitSADC << std::endl;
138  std::cout << "FirstHitTime " << fFirstHitTime << std::endl;
139  std::cout << "LastHitTime " << fLastHitTime << std::endl;
140  std::cout << "TimeWidth " << fTimeWidth << std::endl;
141  std::cout << "MC_EnergyNu " << fMC_EnergyNu << std::endl;
142  std::cout << "MC_EnergyLep " << fMC_EnergyLep << std::endl;
143  std::cout << "MC_MarlTime " << fMC_MarlTime << std::endl;
144  for(int i = 0; i < fNHits; i++)
145  fHitVector.at(i).Print();
146  std::cout << "*********************" << std::endl;
147 
148  };
149 
150 
151  private:
152  int fEvent = 0;
153  int fStartChan = 0;
154  int fEndChan = 0;
155  int fNChan = 0;
156  int fChanWidth = 0;
157  int fNHits = 0;
158  int fType = 0;
159  int fTriggerFlag = 0;
160  float fHitSADC = 0;
161  float fFirstHitTime = 0;
162  float fLastHitTime = 0;
163  float fTimeWidth = 0;
164  double fMC_EnergyNu = 0;
165  double fMC_EnergyLep = 0;
166  double fMC_MarlTime = 0;
167  std::vector<recoHit> fHitVector;
168 };
169 
171 {
172  public:
173  ClusterHitsInTime(double TimeWindow): fNClusters(0),
174  fTimeWindow(TimeWindow),
175  fHitVector(),
176  fVecClusters(){};
177 
178  void DoIt(std::vector<recoHit> cHitVector);
179  double GetTimeWindow() const { return fTimeWindow; };
180  int getNClusters() const { return fNClusters; };
181  std::vector<cluster> getClusterVector() const { return fVecClusters; };
182 
183  void SetTimeWindow(double inTimeWindow=1) { fTimeWindow = inTimeWindow; };
184 
185 private:
186  int fNClusters = 0;
187  double fTimeWindow = 0;
188  std::vector<recoHit> fHitVector;
189  std::vector<cluster> fVecClusters;
190 };
191 
192 
194 public:
195  explicit DAQQuickClustering(fhicl::ParameterSet const & p);
196 
197  // Plugins should not be copied or assigned.
198  DAQQuickClustering(DAQQuickClustering const &) = delete;
200  DAQQuickClustering & operator = (DAQQuickClustering const &) = delete;
201  DAQQuickClustering & operator = (DAQQuickClustering &&) = delete;
202 
203  // The main guts...
204  void analyze(art::Event const & evt) override;
205 
206  void reconfigure(fhicl::ParameterSet const & p);
207 
208  void beginJob() override;
209 
210  void endJob() override;
211 
212 private:
213 
214  void ResetVariables();
215 
216  void trigger(std::vector<cluster> &vec_Clusters, unsigned int const &config);
217  void clusterCut(std::vector<cluster> &vec_Clusters, unsigned int const &config);
218  void clusterChannels(std::vector<recoHit> &vec_Hits, std::vector<ClusterHitsInTime> &vec_ChannelCluster, unsigned int const &config);
219  void makeConfigGraph();
220  void FillMyMaps(std::map<int,simb::MCParticle> &MyMap, art::FindManyP<simb::MCParticle> Assn,
221  art::ValidHandle<std::vector<simb::MCTruth> > Hand);
222  PType WhichParType( int TrID );
223  bool InMyMap( int TrID, std::map< int, simb::MCParticle> ParMap );
224 
225  std::vector<int> cut_AdjChanTolerance;
226  std::vector<int> cut_HitsInWindow;
227  std::vector<int> cut_MinChannels;
228  std::vector<int> cut_MinChanWidth;
229  std::vector<float> cut_TimeWindowSize;
230  std::vector<float> cut_TotalADC;
231 
235 
239  std::string fMARLLabel ; std::map< int, simb::MCParticle > MarlParts;
240  std::string fAPALabel ; std::map< int, simb::MCParticle > APAParts ;
241  std::string fCPALabel ; std::map< int, simb::MCParticle > CPAParts ;
242  std::string fAr39Label ; std::map< int, simb::MCParticle > Ar39Parts;
243  std::string fNeutLabel ; std::map< int, simb::MCParticle > NeutParts;
244  std::string fKrypLabel ; std::map< int, simb::MCParticle > KrypParts;
245  std::string fPlonLabel ; std::map< int, simb::MCParticle > PlonParts;
246  std::string fRdonLabel ; std::map< int, simb::MCParticle > RdonParts;
247  std::string fAr42Label ; std::map< int, simb::MCParticle > Ar42Parts;
248 
249  // Mapping from track ID to particle type, for use in WhichParType()
250  std::map<int, PType> trkIDToPType;
251 
252  unsigned int NConfigs;
253  unsigned int NCuts;
254 
256 
257  int Run ;
258  int SubRun;
259  int Event ;
260 
261  std::map<int,std::vector<double>> map_EventToMC;
262 
263 
264 
267 
268  TH1D* h_ENu_MC;
271  //OUTPUT VARIABLES
279  int out_Type;
281  float out_SumADC;
285  double out_ENu;
286  double out_ENu_Lep;
287  double out_MarlTime;
288  std::vector<int> out_HitView;
289  std::vector<int> out_GenType;
290  std::vector<int> out_HitChan;
291  std::vector<double> out_HitTime;
292  std::vector<double> out_HitSADC;
293  std::vector<double> out_HitRMS;
294 
295  int NTotHits;
296  int NColHits;
297  int NIndHits;
299  int HitView[nMaxHits];
300  int HitSize[nMaxHits];
301  int HitTPC [nMaxHits];
302  int HitChan[nMaxHits];
303  float HitTime[nMaxHits];
304  float HitRMS [nMaxHits];
305  float HitSADC[nMaxHits];
306  float HitInt [nMaxHits];
307  float HitPeak[nMaxHits];
308  int GenType[nMaxHits];
309  float Hit_X[nMaxHits];
310  float Hit_Y[nMaxHits];
311  float Hit_Z[nMaxHits];
312  float Hit_Energy[nMaxHits];
313  float Hit_NumElectrons[nMaxHits];
314  int NCorrespondingIDEs[nMaxHits];
324 
326  int Nu_Type;
328  int Mode;
329  int CCNC;
331  int Target;
332  std::vector<int> MarlSample;
333  std::vector<double> MarlTime;
334  std::vector<double> MarlWeight;
335  double ENu;
336  double ENu_Lep;
337  double VertX;
338  double VertY;
339  double VertZ;
340  double VertexT;
341  double Px;
342  double Py;
343  double Pz;
344 
348 
349 
350 
351 };
352 #endif
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:69
std::vector< int > MarlSample
int getHitChan() const
void setTriggerFlag(int cTriggerFlag)
std::vector< int > cut_HitsInWindow
std::map< int, simb::MCParticle > NeutParts
std::vector< int > cut_MinChannels
std::map< int, PType > trkIDToPType
void cluster(In first, In last, Out result, Pred *pred)
Definition: NNClusters.h:41
float getLastTimeHit() const
void setMC_EnergyNu(double cMC_EnergyNu)
void setMC_MarlTime(double cMC_Marltime)
int getType() const
std::string string
Definition: nybbler.cc:12
std::vector< int > cut_MinChanWidth
float getTimeWidth() const
void setHitSADC(float cHitSADC)
art::ServiceHandle< cheat::ParticleInventoryService > pi_serv
std::vector< double > MarlTime
void SetTimeWindow(double inTimeWindow=1)
float getHitSADC() const
std::vector< double > out_HitTime
Cluster finding and building.
int getTriggerFlag() const
std::map< int, std::vector< double > > map_EventToMC
std::vector< double > MarlWeight
art framework interface to geometry description
double getMC_EnergyLep() const
std::vector< recoHit > getHits() const
friend bool operator<(recoHit lhs, recoHit rhs)
float getHitRMS() const
std::vector< double > out_HitRMS
std::vector< int > cut_AdjChanTolerance
void beginJob()
Definition: Breakpoints.cc:14
virtual void reconfigure(fhicl::ParameterSet const &pset)
static Config * config
Definition: config.cpp:1054
std::vector< float > cut_TimeWindowSize
std::map< int, simb::MCParticle > MarlParts
int getNHits() const
int getChanWidth() const
p
Definition: test.py:223
float getHitSADC() const
double getMC_MarlTime() const
float getHitTime() const
int getGenType() const
int getNChan() const
Declaration of signal hit object.
int getEvent() const
std::vector< float > cut_TotalADC
void printCluster() const
std::vector< int > out_HitView
void setMC_EnergyLep(double cMC_EnergyLep)
Stores extra MC truth information that is recorded when generating events using a time-dependent supe...
int getHitView() const
ClusterHitsInTime(double TimeWindow)
int getEvent() const
std::vector< cluster > fVecClusters
std::vector< recoHit > fHitVector
void Print() const
std::map< int, simb::MCParticle > PlonParts
const int nMaxHits
art::ServiceHandle< cheat::BackTrackerService > bt_serv
Tools and modules for checking out the basics of the Monte Carlo.
TCEvent evt
Definition: DataStructs.cxx:7
std::map< int, simb::MCParticle > RdonParts
int getStartChan() const
double getMC_EnergyNu() const
std::vector< double > out_HitSADC
std::vector< cluster > getClusterVector() const
float getFirstTimeHit() const
art::ServiceHandle< geo::Geometry > geo
int getEndChan() const
std::vector< int > out_GenType
QTextStream & endl(QTextStream &s)
std::map< int, simb::MCParticle > KrypParts
std::vector< int > out_HitChan
recoHit(int cEvent, int cHitView, int cGenType, int cHitChan, float cHitTime, float cHitSADC, float cHitRMS)
std::vector< recoHit > fHitVector