hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Apv25RoXtalkAnaProcessor.cxx
Go to the documentation of this file.
1
7#include <iostream>
8#include <fstream>
9
10Apv25RoXtalkAnaProcessor::Apv25RoXtalkAnaProcessor(const std::string& name, Process& process) : Processor(name,process){}
11
13
14
16 std::cout << "Configuring Apv25RoXtalkAnaProcessor" << std::endl;
17 try
18 {
19 debug_ = parameters.getInteger("debug");
20 anaName_ = parameters.getString("anaName");
21 rawHitColl_ = parameters.getString("rawHitColl");
22 syncPhase_ = parameters.getInteger("syncPhase");
24 trigDel_ = parameters.getInteger("trigDel");
25 histCfgFilename_ = parameters.getString("histCfg");
26 }
27 catch (std::runtime_error& error)
28 {
29 std::cout << error.what() << std::endl;
30 }
31
32}
33
35 tree_= tree;
36 modMap_ = new ModuleMapper(2019);
37
38 // init TTree
39 tree_->SetBranchAddress(rawHitColl_.c_str() , &rawHits_ , &brawHits_ );
40 tree_->SetBranchAddress("EventHeader" , &evth_ , &bevth_ );
41 for (int i = 0; i < 210; i++)
42 {
44 //hFEBrms[i] = 0.0;
45 sps[i] = 0.0;
46 }
47
48}
49
51
52 //std::cout << "[Apv25RoXtalkAnaProcessor] Event Time: " << evth_->getEventTime() << std::endl;
53 //std::cout << "[Apv25RoXtalkAnaProcessor] Event Hit Multi: " << rawHits_->size() << std::endl;
54 //std::cout << "[Apv25RoXtalkAnaProcessor] ModMap Test: " << modMap_->getStringFromHw("F1H2") << std::endl;
55
56 eventTimes.push_back(evth_->getEventTime());
57 hitMultis.push_back(rawHits_->size());
58 int lFEBMulti = 0;
59 int hFEBMulti = 0;
60 for (int i = 0; i < rawHits_->size(); i++)
61 {
62 int lay = rawHits_->at(i)->getLayer();
63 int mod = rawHits_->at(i)->getModule();
64 int feb = std::atoi(&modMap_->getHwFromSw(
65 "ly"+std::to_string(lay)+"_m"+std::to_string(mod)).at(1) );
66 if (feb > 4) hFEBMulti++;
67 else lFEBMulti++;
68 }
69 lFEBMultis.push_back(lFEBMulti);
70 hFEBMultis.push_back(hFEBMulti);
71
72 return true;
73}
74
76
77 std::cout << "[Apv25RoXtalkAnaProcessor] Finalizing" << std::endl;
78 TH1D * hitN_h = new TH1D("hitN_h", "hitN_h;Raw SVT Hit Multi;Events/10", 500, 0, 5000);
79 TH1D * lFEBN_h = new TH1D("lFEBN_h", "lFEBN_h;Raw SVT Hit Multi;Events/10", 500, 0, 5000);
80 TH1D * hFEBN_h = new TH1D("hFEBN_h", "hFEBN_h;Raw SVT Hit Multi;Events/10", 500, 0, 5000);
81 TH2D * FEBN_hh = new TH2D("FEBN_hh", "FEBN_hh", 500, 0, 2000, 500, 0, 2000);
82 for (int i = 0; i < hitMultis.size(); i++)
83 {
84 hitN_h->Fill(hitMultis[i]);
85 lFEBN_h->Fill(lFEBMultis[i]);
86 hFEBN_h->Fill(hFEBMultis[i]);
87 FEBN_hh->Fill(hFEBMultis[i], lFEBMultis[i]);
88 }
89 outF_->cd();
90 hitN_h->Write();
91 lFEBN_h->Write();
92 hFEBN_h->Write();
93 FEBN_hh->Write();
94 for(int sp = 0; sp < 840; sp += 4)
95 {
97 }
98
99 TGraph lFEBreadRms_g(210, sps, lFEBrms);
100 lFEBreadRms_g.SetName("lFEBreadRms_g");
101 lFEBreadRms_g.SetTitle("lFEBreadRms_g;syncPhase;RMS(Read Time minus Event Time)");
102 lFEBreadRms_g.Write();
103
104 TGraph hFEBreadRms_g(210, sps, hFEBrms);
105 hFEBreadRms_g.SetName("hFEBreadRms_g");
106 hFEBreadRms_g.SetTitle("hFEBreadRms_g;syncPhase;RMS(Read Time minus Event Time)");
107 hFEBreadRms_g.Write();
108
109 int lFEBminI = -1;
110 double lFEBmin = 10000.0;
111 int hFEBminI = -1;
112 double hFEBmin = 10000.0;
113 for(int i = 0; i < 210; i++)
114 {
115 if (lFEBrms[i] < lFEBmin)
116 {
117 lFEBmin = lFEBrms[i];
118 lFEBminI = i;
119 }
120 if (hFEBrms[i] < hFEBmin)
121 {
122 hFEBmin = hFEBrms[i];
123 hFEBminI = i;
124 }
125 }
126
127 std::cout << "lFEBmin: " << lFEBminI*4 << std::endl;
128 emulateApv25Buff(lFEBminI*4);
129 int phase0 = (int)lFEBminI*4;
130 int cut0L = (int)lLowCut;
131 int cut0H = (int)lHighCut;
132 std::cout << "lLowCut: " << lLowCut << " lHighCut: " << lHighCut << std::endl;
133
134 std::cout << "hFEBmin: " << hFEBminI*4 << std::endl;
135 emulateApv25Buff(hFEBminI*4);
136 int phase1 = (int)hFEBminI*4;
137 int cut1L = (int)hLowCut;
138 int cut1H = (int)hHighCut;
139 std::cout << "hLowCut: " << hLowCut << " hHighCut: " << hHighCut << std::endl;
140
141 std::ofstream calFile("calApvXtalk.txt");
142 calFile << "trigDel,phase0,phase1,cut0L,cut0H,cut1L,cut1H\n";
143 calFile << trigDel_ << ",";
144 calFile << phase0 << ",";
145 calFile << phase1 << ",";
146 calFile << cut0L << ",";
147 calFile << cut0H << ",";
148 calFile << cut1L << ",";
149 calFile << cut1H << std::endl;
150 calFile.close();
151
152}
153
155 reads.clear();
156 readEvs.clear();
157 TH1D readN_h(Form("readN_iter%i_h", buffIter), Form("readN_iter%i_h", buffIter), 21, -0.5, 20.5);
158 TH2D lFEBread_hh(Form("lFEBread_iter%i_hh", buffIter), ";Read Time minus Event Time [ns];Read Event Time mod 840", 500, -2000.0, 14000.0, 210, 0, 35*24);
159 TH1D lFEBread_h(Form("lFEBread_iter%i_h", buffIter), ";Read Time minus Event Time [ns];Events / 8 ns", 500, -2000.0, 2000.0);
160 TH2D hFEBread_hh(Form("hFEBread_iter%i_hh", buffIter), ";Read Time minus Event Time [ns];Read Event Time mod 840", 500, -2000.0, 14000.0, 210, 0, 35*24);
161 TH1D hFEBread_h(Form("hFEBread_iter%i_h", buffIter), ";Read Time minus Event Time [ns];Events / 8 ns", 500, -2000.0, 2000.0);
162 syncPhase_ = buffIter;
164 for (int iEv = 0; iEv < hitMultis.size(); iEv++)
165 {
166 // Calculate the relevant times wrt this event
167 long evTime = eventTimes[iEv];
168 long trigArrT = evTime + trigDel_ + (24 - (evTime+trigPhase_)%24);
169 long trigSyncTime = trigArrT + (35*24 - (trigArrT+syncPhase_)%(35*24));
170
171 // Remove reads from buffer which are in the past wrt this event
172 for (int ir = reads.size() - 1; ir >= 0; ir--)
173 {
174 if ( reads[ir] < evTime - 840 )
175 {
176 reads.erase(reads.begin() + ir);
177 readEvs.erase(readEvs.begin() + ir);
178 }
179 }
180 int buffNstart = reads.size();
181 //std::cout << "reads before adding: " << reads.size() << std::endl;
182 for (int ss = 0; ss < 6; ss++)
183 {
184 if (ss > 0)
185 {
186 reads.push_back(reads[reads.size()-1] + 3360);
187 readEvs.push_back(evTime);
188 }
189 else
190 {
191 if (buffNstart == 0)
192 {
193 reads.push_back(trigSyncTime);
194 readEvs.push_back(evTime);
195 }
196 else if (reads[reads.size()-1] + 3360 > trigSyncTime)
197 {
198 reads.push_back(reads[reads.size()-1] + 3360);
199 readEvs.push_back(evTime);
200 }
201 else
202 {
203 reads.push_back(trigSyncTime);
204 readEvs.push_back(evTime);
205 }
206 }
207 }
208 //std::cout << "reads after adding: " << reads.size() << std::endl;
209 //readN_h.Fill((double)reads.size());
210 if (lFEBMultis[iEv] > 700)
211 {
212 lFEBread_h.Fill( reads[0] - evTime);
213 lFEBread_hh.Fill( reads[0] - evTime, readEvs[0]%(24*35) );
214 }
215 if (hFEBMultis[iEv] > 300)
216 {
217 hFEBread_h.Fill( reads[0] - evTime);
218 hFEBread_hh.Fill( reads[0] - evTime, readEvs[0]%(24*35) );
219 }
220 }
221 lFEBrms[buffIter/4] = lFEBread_h.GetRMS();
222 lLowCut = lFEBread_h.GetXaxis()->GetBinCenter(lFEBread_h.FindFirstBinAbove(5.0)) - 28.0;
223 lHighCut = lFEBread_h.GetXaxis()->GetBinCenter(lFEBread_h.FindLastBinAbove(5.0)) + 28.0;
224 hFEBrms[buffIter/4] = hFEBread_h.GetRMS();
225 hLowCut = hFEBread_h.GetXaxis()->GetBinCenter(hFEBread_h.FindFirstBinAbove(5.0)) - 12.0;
226 hHighCut = hFEBread_h.GetXaxis()->GetBinCenter(hFEBread_h.FindLastBinAbove(5.0)) + 12.0;
227 sps[buffIter/4] = (double)buffIter;
228 readN_h.Write();
229 lFEBread_h.Write();
230 lFEBread_hh.Write();
231 hFEBread_h.Write();
232 hFEBread_hh.Write();
233}
234
#define DECLARE_PROCESSOR(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Definition Processor.h:139
Insert description here. more details.
std::string rawHitColl_
description
std::string anaName_
description
std::vector< int > hitMultis
description
virtual void configure(const ParameterSet &parameters)
Configure using given parameters.
virtual void finalize()
description
std::vector< RawSvtHit * > * rawHits_
description
virtual void initialize(TTree *tree)
description
std::vector< long > eventTimes
description
std::vector< long > readEvs
description
std::vector< int > lFEBMultis
description
EventHeader * evth_
description
std::string histCfgFilename_
description
void emulateApv25Buff(int buffIter)
description
std::vector< long > reads
description
std::vector< int > hFEBMultis
description
Apv25RoXtalkAnaProcessor(const std::string &name, Process &process)
Constructor.
ModuleMapper * modMap_
description
long getEventTime() const
Definition EventHeader.h:61
Definition IEvent.h:7
std::string getHwFromSw(const std::string &key)
Get the Hw From Sw.
description
Base class for all event processing components.
Definition Processor.h:34
TFile * outF_
Definition Processor.h:125
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95