Diana Software
MTimeEnergy.cc
Go to the documentation of this file.
1 #include "MTimeEnergy.hh"
2 #include "QCountPulsesData.hh"
3 #include <string>
4 #include <TFile.h>
5 #include <TTree.h>
6 #include <math.h>
7 #include <TH1D.h>
8 #include <TF1.h>
9 
11 using namespace std;
12 
13 // constructor
15 {
16 }
17 
18 // destructor
20 {
21 }
22 
23 // init method, here I set my variables to zero
25 {
26  fMultiple= new QMultiple();
27  fFineTime= new QFineTime();
28  string outputFilename = GetString("OutputFilename", "multiple.root");
29  fOutputFile = new TFile(outputFilename.c_str(), "recreate");
30  fTree = new TTree("MultipleTree", "Multiple Events");
31  fTree->Branch("multiple_event_branch.", "Diana::QMultiple", &fMultiple);
32  fCounter=0;
33  fTotalCount=0;
34  fLastTime=0;
35  fSaturated=0;
36  fOutput.open ("Rates.txt", ios::out | ios::app);
37  fMuonFile.open("Muons.txt", ios::out);
38  fDeltaT.open("DeltaT.txt", ios::out);
39  fRun=0;
40  for (int A1=1;A1<69;A1++)
41  {
42  PMCount[A1]=0.0;
43  AMCount[A1]=0.0;
44  MTime[A1]=0;
45  AMTime[A1]=0;
46  TimeHolder[A1]=0;
47  }
48 }
49 
50 
51 
52 
53 
54 
55 
56 // resetting muon scan parameters
57 
59 {
60  for (int A1=1;A1<69;A1++)
61  {
62  if (MTime[A1]!=0)
63  {
64  fOutput << A1 << "\t" << PMCount[A1] << "\t" << MTime[A1] << "\t" << AMCount[A1] << "\t" << fLastTime << "\t" << AMTime[A1] << "\n";
65  }
66  }
67  for (int A1=1;A1<69;A1++)
68  {
69  PMCount[A1]=0.0;
70  AMCount[A1]=0.0;
71  MTime[A1]=0;
72  AMTime[A1]=0;
73  TimeHolder[A1]=0;
74  }
75  fRun=run;
76 }
77 
78 // doit method
80  const QRawEvent& CurrentRawEvent = ev->GetRawEvent();
81 
82 // Adding an energy gate, perhaps odd features are caused by noise.
83  double CurrentEnergy = ev->GetCalib().GetEnergy();
84 
85 // Channel #
86  unsigned long long CurrentChannel = CurrentRawEvent.GetPulse().GetChannelId();
87 
88 // Only allow properly triggered events to be involved in the system
89  int Trigger = CurrentRawEvent.GetPulse().GetIsHeater();
90 
91 // Multiple pulse events in the same crystal are likely to be very poorly resolved in terms
92 // of energy. They are possible multiple candidates, but should be ignored for now.
93 // Also ignoring all events without proper triggers
94  int Pulses = ev->GetCountPulses().GetNumberOfPulses();
95 
96 
97 // default time for unwanted events, and so CurrentTime is set
98  unsigned long long CurrentTime = CurrentRawEvent.GetTime().GetFromStartRunNs();
99 
100 // Use time correction routine for events which will be considered for inclusion.
101  if (Pulses==1&&Trigger==0&&CurrentEnergy>=200&&CurrentChannel!=3)
102  {
103  CurrentTime = fFineTime->GetCrossingTime(ev);
104  }
105 
106 // Time corection due to varying position of ideal pulse triggers due to typical pulse rise times in channels
107 // CurrentTime -= fFineTime->GetCorrection(CurrentChannel);
108  CurrentTime += (unsigned long long) fFineTime->GetCorrection(CurrentChannel);
109 
110  if (fRun==0)
111  {
112  fRun=CurrentRawEvent.GetRun();
113  }
114  else if (fRun!=CurrentRawEvent.GetRun()) {CallReset(CurrentRawEvent.GetRun());}
115 
116  float Allowed = 20e6;
117 
118 
119 
120 // Time correction due to changing trigger time with increasing energy
121 // Should no longer be necessary with better time correction from cfd
122 // CurrentTime += 4.096*1e9*(ev->GetOB().GetStartTimeOffset())/512;
123 
124 
125 
126 // Try to use the 'average' time of a multiple rather than the earliest detected time
127  fLastTime = (unsigned long long) ( (CurrentTime + fLastTime*1.0*fMultiple->GetMultiplicity())/(1+1.0*fMultiple->GetMultiplicity()) );
128 
129 // Check that new average time is consistent with other events
130  int TimeCheck = fMultiple->Consistancy(fLastTime,Allowed);
131  unsigned long long DeltaT = fLastTime-CurrentTime;
132 
133 
134 // Demand a good pulse
135  if (Pulses==1&&Trigger==0&&CurrentEnergy>=200&&CurrentChannel!=3)
136  {
137  if (ev->GetPreProcess().GetIsSaturatedHigh()==1) {fSaturated++;}
138  if (fCounter==50)
139  {
140  fDeltaT << CurrentTime-TimeHolder[CurrentChannel] << "\n";
141  }
142  TimeHolder[CurrentChannel]=CurrentTime;
143 
144  DeltaT*=DeltaT;
145  DeltaT= (unsigned long long) pow(DeltaT,0.5);
146 // no data in active multiple (first event), no check, add current event
147  if (fMultiple->GetMultiplicity() == 0)
148  {
149  fLastTime=CurrentTime;
150  fMultiple->AddEvent(ev,CurrentTime);
151  fTotalCount++;
152  }
153 // multiple member check, if succuss, add current event to new multiple
154 // also recording the total time splitting in the event with AccumulateTime()
155 // although typical time splitting for simultaneous low energy events has been
156 // reduced to 2 ms, at higher energies the pulse shapes and pulse fitting is
157 // not so well known, and thus time finding is less accurate. This also checks
158 // that the current time is acceptable to the other members of the multiple
159  else if (DeltaT<Allowed&&DeltaT>-Allowed&&TimeCheck==1)
160  {
161  fMultiple->AddEvent(ev,CurrentTime);
162  fTotalCount++;
163  fMultiple->AccumulateTime(DeltaT);
164  }
165 // failed check, end current multiple, start new multiple with current event
166 // check current multiple for muonlike status
167  else
168  {
169 // checks for total energy, and presence of saturated peaks
170  if (fMultiple->GetTotalEnergy()>30000&&fSaturated>0)
171  {
172  fMultiple->SetMuon();
173  for (int A2=0;A2<fMultiple->GetMultiplicity();A2++)
174  {
175  int TaggedChannel = fMultiple->GetEventChannelID(A2);
176  // only count earliest tag, avoids confusion over count.
177  if (MTime[TaggedChannel]==0) {MTime[TaggedChannel]=CurrentTime;}
178  }
179  const QBaseRawEventR* HolderRawEvent = fMultiple->GetEvent(0).GetBaseRawEvent();
180  fMuonFile << MTime[fMultiple->GetEventChannelID(0)] << "\t" << HolderRawEvent->GetRun() << "\t" << fMultiple->GetMultiplicity() << "\t";
181  for (int A2=0;A2<fMultiple->GetMultiplicity();A2++)
182  {
183  fMuonFile << fMultiple->GetEventChannelID(A2) << "\t";
184  }
185  fMuonFile << "\n";
186  }
187 
188 // checks for presence of events from poor channels/runs/times in the multiple and flags the multiple if they are present.
189  fMultiple->CheckFailures();
190 
191 // erasing current multiple and starting a new one
192  fMultiple->EliminateSize();
193  fTree->Fill();
194  delete fMultiple;
195  fMultiple = new QMultiple();
196  fMultiple->AddEvent(ev,CurrentTime);
197  fTotalCount++;
198  fLastTime=CurrentTime;
199  if (MTime[CurrentChannel]==0)
200  {
201  PMCount[CurrentChannel]++;
202  }
203  else if (CurrentTime-MTime[CurrentChannel]<1e12)
204  {
205  AMCount[CurrentChannel]++;
206  if (AMCount[CurrentChannel]==1)
207  {
208  AMTime[CurrentChannel]=CurrentTime-MTime[CurrentChannel];
209  }
210  }
211  fSaturated=0;
212  fCounter++;
213  if (fCounter>51)
214  {
215  cout << ev->GetReadNumber() << "\t" << fTotalCount << "\n";
216  fCounter =0;
217  }
218  }
219  }
220  return ev;
221 }
222 
223 // done method
225 {
226  for (int A1=1;A1<69;A1++)
227  {
228  if (MTime[A1]!=0)
229  {
230  fOutput << A1 << "\t" << PMCount[A1] << "\t" << MTime[A1] << "\t" << AMCount[A1] << "\t" << fLastTime << "\t" << AMTime[A1] << "\n";
231  }
232  }
233  fOutputFile = fTree->GetCurrentFile();
234  fOutputFile->Write();
235  fOutputFile->Close();
236 }
237 
Diana::QComplex pow(const Diana::QComplex &z, double a)
Raise a complex number to a real power.
Definition: QComplex.cc:246
#define REGISTER_MODULE(clazz)
Definition: QDriver.hh:133
ofstream fMuonFile
Definition: MTimeEnergy.hh:102
MTimeEnergy(QSequence *s)
Definition: MTimeEnergy.cc:14
virtual void Init()
Definition: MTimeEnergy.cc:24
virtual QEvent * Do(QEvent *ev)
Definition: MTimeEnergy.cc:79
virtual void CallReset(int run)
Definition: MTimeEnergy.cc:58
virtual ~MTimeEnergy()
Definition: MTimeEnergy.cc:19
ofstream fOutput
Definition: MTimeEnergy.hh:101
double PMCount[69]
Definition: MTimeEnergy.hh:104
TFile * fOutputFile
Definition: MTimeEnergy.hh:99
unsigned long long MTime[69]
Definition: MTimeEnergy.hh:106
unsigned long long AMTime[69]
Definition: MTimeEnergy.hh:107
virtual void Done()
Done method is called after event loop.
Definition: MTimeEnergy.cc:224
QMultiple * fMultiple
Definition: MTimeEnergy.hh:97
unsigned long long fLastTime
Definition: MTimeEnergy.hh:92
unsigned long long TimeHolder[69]
Definition: MTimeEnergy.hh:108
double AMCount[69]
Definition: MTimeEnergy.hh:105
ofstream fDeltaT
Definition: MTimeEnergy.hh:103
QFineTime * fFineTime
Definition: MTimeEnergy.hh:98
TTree * fTree
Definition: MTimeEnergy.hh:100
const std::string & GetString(const std::string &parname, const std::string &defVal, bool warnCfg=true) const
Get a string parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:297
diana event
Definition: QEvent.hh:46
unsigned int GetReadNumber() const
return the event number as read by the current reader.
Definition: QEvent.hh:60
Base class for diana modules.
Definition: QModule.hh:54
Diana Reconstruction program.
Definition: QSequence.hh:40