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
SvtRawDataAnaProcessor.cxx
Go to the documentation of this file.
1
7
8#include <iostream>
9
10SvtRawDataAnaProcessor::SvtRawDataAnaProcessor(const std::string& name, Process& process) : Processor(name,process){
11 mmapper_ = new ModuleMapper();
12}
13//TODO CHECK THIS DESTRUCTOR
15
16
18 std::cout << "Configuring SvtRawDataAnaProcessor" << std::endl;
19 try
20 {
21 debug_ = parameters.getInteger("debug");
22 anaName_ = parameters.getString("anaName");
23 svtHitColl_ = parameters.getString("trkrHitColl");
24 histCfgFilename_ = parameters.getString("histCfg");
25 regionSelections_ = parameters.getVString("regionDefinitions");
26 TimeRef_ = parameters.getDouble("timeref");
27 AmpRef_ = parameters.getDouble("ampref");
28 doSample_ = parameters.getInteger("sample");
29 MatchList_ = parameters.getVString("MatchList");
30 baselineFile_ = parameters.getString("baselineFile");
31 timeProfiles_ = parameters.getString("timeProfiles");
32 tphase_ = parameters.getInteger("tphase");
33 }
34 catch (std::runtime_error& error)
35 {
36 std::cout << error.what() << std::endl;
37 }
38
39}
40
50float SvtRawDataAnaProcessor::str_to_float(std::string token){
51 std::string top1=token.substr(0,token.find("."));
52 const char *top=top1.c_str();
53 std::string bot1=token.substr(token.find(".")+1);
54 const char *bottom=bot1.c_str();
55 float base = 0.0;
56 for(int J=0;J<std::strlen(top);J++){
57 base+=((float)((int)top[J]-48))*pow(10.0,(float)(std::strlen(top)-J-1));
58 }
59 for(int J=0;J<std::strlen(bottom);J++){
60 base+=((float)((int)bottom[J]-48))*pow(10.0,-1*((float)J+1.0));
61 }
62 return base;
63}
64
65//float reverseEngineerTime(float ti,IEvent* ievent){
66// return ti-1.0;
67//}
68
69
70float rETime(float ti,long T){
71 bool correctTimeOffset = true;
72 bool subtractTriggerTime = true;
73 bool syncGood = false;
74 bool isMC = false;
75
76 bool correctChanT0 = false;
77 bool correctT0Shift = false;
78
79 //bool subtractTOF = true;
80
81
82 bool useTimestamps = false;
83
84 //sensor=hit.getSensor();
85 long OffsetTime = 35;
86 long OffsetPhase = 4;
87 long trigTimeOffset = 14;
88 //THIS ONE
89 //std::cout<<"Initial Time: "<<ti<<std::endl;
90
91 if (correctTimeOffset) {
92 //if (debug)
93 // System.out.println("subtracting svt time offset " + timingConstants.getOffsetTime());
94 ti=ti-OffsetTime;
95 }
96
97
98 //THIS ONE
99 if (subtractTriggerTime) {
100 //std::cout<<T<<std::endl;
101 //std::cout<<"OffsetPhase Time is "<<((T-4*OffsetPhase)%24)/8<<std::endl;
102 float tt = (float)(((T-4*OffsetPhase)%24)-trigTimeOffset);
103 //std::cout<<tt<<std::endl;
104 if (!syncGood) tt = tt - 8;
105 //std::cout<<tt<<std::endl;
106 if (!syncGood && (((T-4*OffsetPhase)%24)/8 < 1)) {
107 tt = tt + 24;//std::cout<<"I SHIFTED"<<std::endl;
108 }
109 //std::cout<<tt<<std::endl;
110 //else{std::cout<<"I DID NOT SHIFT"<<std::endl;}
111 //if (isMC && ((((int)T - 4 * (int)OffsetPhase) % 24)/8 == 1)) {
112 // tt = tt + 24;
113 //}
114
115 ti=ti-tt;
116 }
117 return ti;
118}
119
120
121/*
122 *
123 *FOUR POLE PULSE FUNCTION AND THE SUM OF TWO OF THEM WITH BASELINES BORROWED FROM ALIC
124 *
125 */
126
127TF1* SvtRawDataAnaProcessor::fourPoleFitFunction(std::string word, int caser){
128 const char *helper = word.data();
129 if(caser==0){
130 TF1* func = new TF1(helper,"(TMath::Max(x-[0],0.0)/(x-[0]))*([3])*(1/ ( exp(-(3*(([1]*([2]^3))^.25))/[1]) - ( exp(-(3*(([1]*([2]^3))^.25))/[2]) * ( ((((([1]-[2])/([1]*[2]))*(3*(([1]*([2]^3))^.25)))^(0))) + ((((([1]-[2])/([1]*[2]))*(3*(([1]*([2]^3))^.25)))^(1))) + ((((([1]-[2])/([1]*[2]))*(3*(([1]*([2]^3))^.25)))^(2))/2) ) ) )) * ( exp(-(x-[0])/[1]) - ( exp(-(x-[0])/[2]) * ( ((((([1]-[2])/([1]*[2]))*(x-[0]))^(0))) + ((((([1]-[2])/([1]*[2]))*(x-[0]))^(1))) + ((((([1]-[2])/([1]*[2]))*(x-[0]))^(2))/2) ) ) )",0.0,150.0);
131 return func;
132 }
133 TF1* func2 = new TF1(helper,"(TMath::Max(x-[0],0.0)/(x-[0]))*([3])*(1/ ( exp(-(3*(([1]*([2]^3))^.25))/[1]) - ( exp(-(3*(([1]*([2]^3))^.25))/[2]) * ( ((((([1]-[2])/([1]*[2]))*(3*(([1]*([2]^3))^.25)))^(0))) + ((((([1]-[2])/([1]*[2]))*(3*(([1]*([2]^3))^.25)))^(1))) + ((((([1]-[2])/([1]*[2]))*(3*(([1]*([2]^3))^.25)))^(2))/2) ) ) )) * ( exp(-(x-[0])/[1]) - ( exp(-(x-[0])/[2]) * ( ((((([1]-[2])/([1]*[2]))*(x-[0]))^(0))) + ((((([1]-[2])/([1]*[2]))*(x-[0]))^(1))) + ((((([1]-[2])/([1]*[2]))*(x-[0]))^(2))/2) ) ) )+(TMath::Max(x-[5],0.0)/(x-[5]))*([8])*(1/ ( exp(-(3*(([6]*([7]^3))^.25))/[6]) - ( exp(-(3*(([6]*([7]^3))^.25))/[7]) * ( ((((([6]-[7])/([6]*[7]))*(3*(([6]*([7]^3))^.25)))^(0))) + ((((([6]-[7])/([6]*[7]))*(3*(([6]*([7]^3))^.25)))^(1))) + ((((([6]-[7])/([6]*[7]))*(3*(([6]*([7]^3))^.25)))^(2))/2) ) ) )) * ( exp(-(x-[5])/[1]) - ( exp(-(x-[5])/[2]) * ( ((((([6]-[7])/([6]*[7]))*(x-[5]))^(0))) + ((((([6]-[7])/([6]*[7]))*(x-[5]))^(1))) + ((((([6]-[7])/([6]*[7]))*(x-[5]))^(2))/2) ) ) ) ",0.0,150.0);
134 return func2;
135}
136
137/*
138 *
139 *PROCESS INITIALIZER. READS IN THE OFFLINE BASELINES INTO LOCAL BASELINE FILES, READs in the PULSE SHAPES, and FINALLLY
140 ESTABLISHES REGIONS WHICH ARE USED ALONG WITH THE REGION SELECTOR CLASS AND CUTS IN ANALYSIS/SELECTION/SVT TO SELECT ON
141 EVENTS FOR WHICH HISTOGRAMS IN RAWSVTHISTO IS FILLED.
142 *
143 *
144 */
145
147 if(doSample_){
148 //Fill in the Background Arrays
149 std::ifstream myfile(baselineFile_.data());
150 std::ifstream myfile2(timeProfiles_.data());
151 std::string s;
152 std::string s2;
153 // std::vector<float [12]> baselines;
154 for(int i=0; i<24576; i++){
155 std::getline(myfile,s);
156 std::getline(myfile2,s2);
157 int feb=0;
158 int hyb=0;
159 int ch=0;
160 if(i>=4096){
161 feb=((i-4096)/2560);
162 hyb=(i-4096-feb*2560)/640;
163 ch=i-4096-feb*2560-hyb*640;
164 }else{
165 feb=i/2048;
166 hyb=(i-feb*2048)/512;
167 ch=i-feb*2048-hyb*512;
168 }
169 for(int I=0;I<5;I++){
170 std::string token=s2.substr(0,s2.find(","));
171 s2=s2.substr(s2.find(",")+1);
172 if(I>=2){
173 if(i<=4096){
174 times1_[feb][hyb][ch][I-2]=str_to_float(token);
175 }else{
176 times2_[feb][hyb][ch][I-2]=str_to_float(token);
177 }
178 }
179 }
180 //if(i<2048){
181 //std::cout<<i<<" "<<feb<<" "<<hyb<<" "<<ch<<std::endl;
182 //std::cout<<s<<std::endl;}
183 for(int I=0;I<13;I++){
184 if(I>0){
185 if(i<=4096){
186 std::string token=s.substr(0,s.find(" "));
187 if(debug_){
188 std::cout<<i<<" "<<feb<<" "<<hyb<<" "<<ch<<std::endl;
189 }
190 baseErr1_[feb][hyb][ch][I-1]=str_to_float(token);
191 //std::cout<<str_to_float(token)<<std::endl;
192 s=s.substr(s.find(" ")+1);
193 }else{
194 std::string token=s.substr(0,s.find(" "));
195 baseErr2_[feb][hyb][ch][I-1]=str_to_float(token);
196 //std::cout<<str_to_float(token)<<std::endl;
197 s=s.substr(s.find(" ")+1);
198 //std::cout<<s<<std::endl;
199 }
200 }else{
201 s=s.substr(s.find(" ")+1);
202 }
203 }
204
205 }
206 myfile.close();
207 myfile2.close();
208 //sleep(2000);
209 }
210
211
212 tree_= tree;
213 // init histos
214 //histos = new RawSvtHitHistos(anaName_.c_str(), mmapper_);
215 //histos->loadHistoConfig(histCfgFilename_);
216 //histos->DefineHistos();
217 //std::cout<<svtHitColl_.c_str()<<std::endl;
219 tree_->SetBranchAddress(svtHitColl_.c_str() , &svtHits_ , &bsvtHits_ );
220 //tree_->SetBranchAddress("VTPBank", &vtpBank_ , &bvtpBank_ );
221 //tree_->SetBranchAddress("TSBank", &tsBank_ , &btsBank_ );
222 //tree_->SetBranchAddress("RecoEcalClusters",&recoClu_,&brecoClu_ );
223 //tree_->SetBranchAddress("KalmanFullTracks",&Trk_,&bTrk_);
224 tree_->SetBranchAddress("FinalStateParticles_KF",&Part_,&bPart_);
225 tree_->SetBranchAddress("EventHeader",&evH_,&bevH_);
226
227 for (unsigned int i_reg = 0; i_reg < regionSelections_.size(); i_reg++)
228 {
229 std::string regname = AnaHelpers::getFileName(regionSelections_[i_reg],false);
230 std::cout << "Setting up region:: " << regname << std::endl;
231 reg_selectors_[regname] = std::make_shared<BaseSelector>(regname, regionSelections_[i_reg]);
232 reg_selectors_[regname]->setDebug(debug_);
233 reg_selectors_[regname]->LoadSelection();
234
235 reg_histos_[regname] = std::make_shared<RawSvtHitHistos>(regname,mmapper_);
236 reg_histos_[regname]->loadHistoConfig(histCfgFilename_);
237 //reg_histos_[regname]->doTrackComparisonPlots(false);
238 reg_histos_[regname]->DefineHistos();
239
240 regions_.push_back(regname);
241 }
242}
243
244/*
245 *
246 *RUNS OVER THE REGION SELECTORS AND CHECKS IF AN EVENT PASSES A SELECTION JSON AND FILLS A RAWSVTHITHISTO
247 IF DO SAMPLE IS ON, IT RUNS SAMPLING.
248 *
249 *
250 */
251
252
254 Float_t TimeRef=-0.0;
255 Float_t AmpRef=1000.0;
256 double weight = 1.;int count1=0;int count2=0;
257 long eventTime = evH_->getEventTime();
258
259 //I AM DOING CLUSTER MATCHING HERE :)
260 //std::cout<<"Here is the eventTime"<<eventTime<<std::endl;
261 //std::cout<<"Here is the TSBank Trigger Time"<<tsBank_->T<<std::endl;
262 bool doClMatch = true;
263
264
265 //if((doClMatch)and(not((tsBank_->prescaled.Single_3_Top==1)or(tsBank_->prescaled.Single_3_Bot==1)))){return true;}
266
267
268 //ONLY POSITRONS, MAY USE FEE's
269 //ONCE I DETERMINE A CLUSTER WHICH IS IN LINE WITH TRIG, I CAN USE ANY CLUSTERS CLOSE IN TIME.
270
271 //std::cout<<"Trigger Time: "<<vtpBank_->singletrigs.at(0).T<<std::endl;
272 int trigPhase = (int)((eventTime%24)/4);
273 if((trigPhase!=tphase_)&&(tphase_!=6)){return true;}
274 for(unsigned int i = 0; i < svtHits_->size(); i++){
275 RawSvtHit * thisHit = svtHits_->at(i);
276 int getNum = thisHit->getFitN();//std::cout<<"I got here 10"<<std::endl;
277 if(doClMatch){
278 bool Continue = true;
279 for(int i = 0; i<Part_->size();i++){
280 if(Part_->at(i)->getPDG()==22){continue;}
281 if(Part_->at(i)->getCluster().getEnergy()<0){continue;}
282 if(not((Part_->at(i)->getCluster().getTime()<=40)and(Part_->at(i)->getCluster().getTime()>=36))){continue;}
283 //std::cout<<"For each Tracker Hit I now print out Raw Hit Info: "<<std::endl;
284 for(int j = 0; j<Part_->at(i)->getTrack().getSvtHits().GetEntries();j++){
285 TrackerHit * tHit = (TrackerHit*)(Part_->at(i)->getTrack().getSvtHits().At(j));
286 //std::cout<<tHit->getTime()<<std::endl;
287 for(int k = 0;k<tHit->getRawHits().GetEntries();k++){
288 RawSvtHit * rHit = (RawSvtHit*)(tHit->getRawHits().At(k));
289 if(rHit->getT0(0)==thisHit->getT0(0)){Continue=false;}
290 //std::cout<<"Raw Hit T0: "<<rHit->getT0(0)<<std::endl;
291 }
292 //std::cout<<" T0: "<<Part_->at(i)->getTrack().getSvtHits().At(j)->getRawHits().At(0).getT0()<<std::endl;
293 }
294 }
295 if(Continue){
296 return true;
297 }
298 }
299 for(unsigned int i_reg = 0; i_reg < regionSelections_.size(); i_reg++){
300 //std::cout<<"\n"<<std::endl;
301 for(unsigned int J=0; J<getNum; J++){
302 //std::cout<<"\ngetNum:"<<getNum<<std::endl;
303 //std::cout<<"region No:"<<regions_[i_reg]<<std::endl;
304
305 //std::cout<<"Which Hit:"<<J<<std::endl;
306 Float_t TimeDiff=-42069.0;
307 Float_t AmpDiff=-42069.0;
308
309 if(!(reg_selectors_[regions_[i_reg]]->passCutEq("getN_et",getNum,weight))){continue;}
310
311 if(getNum==2){
312 TimeDiff=(thisHit->getT0(J))-(thisHit->getT0((J+1)%2));
313 AmpDiff=(thisHit->getT0(J))-(thisHit->getT0((J+1)%2));
314 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("TimeDiff_lt",TimeDiff*TimeDiff,weight))){continue;}
315 }
316 if(!(reg_selectors_[regions_[i_reg]]->passCutEq("getId_lt",J,weight))){continue;}
317 if(!(reg_selectors_[regions_[i_reg]]->passCutEq("getId_gt",J,weight))){continue;}
318 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("chi_lt",thisHit->getChiSq(J),weight))){continue;}
319 if(!(reg_selectors_[regions_[i_reg]]->passCutGt("chi_gt",thisHit->getChiSq(J),weight))){continue;}
320
321
322 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("doing_ft",(((thisHit->getT0(J))-TimeRef)*((thisHit->getT0(J))-TimeRef)<((thisHit->getT0((J+1)%getNum)-TimeRef)*(thisHit->getT0((J+1)%getNum)-TimeRef)+.00001)),weight))){continue;}
323 if(i_reg<regionSelections_.size()-1){
324 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("doing_ct",(((thisHit->getT0(J))-TimeRef)*((thisHit->getT0(J))-TimeRef)>((thisHit->getT0((J+1)%getNum)-TimeRef)*(thisHit->getT0((J+1)%getNum)-TimeRef)+.00001)),weight))){continue;}
325 }else{
326 if(getNum==2){
327 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("doing_ct",(((thisHit->getT0(J))-TimeRef)*((thisHit->getT0(J))-TimeRef)>((thisHit->getT0((J+1)%getNum)-TimeRef)*(thisHit->getT0((J+1)%getNum)-TimeRef)+.00001)),weight))){continue;}
328 }
329 }
330 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("doing_ca",(((thisHit->getAmp(J))-AmpRef)*((thisHit->getAmp(J))-AmpRef)<((thisHit->getAmp((J+1)%getNum)-AmpRef)*(thisHit->getAmp((J+1)%getNum)-AmpRef)+.00001)),weight))){continue;}
331
332 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("doing_fterr",(((thisHit->getT0err(J))-TimeRef)*((thisHit->getT0err(J))-TimeRef)<((thisHit->getT0err((J+1)%getNum)-TimeRef)*(thisHit->getT0err((J+1)%getNum)-TimeRef)+.00001)),weight))){continue;}
333 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("doing_cterr",(((thisHit->getT0err(J))-0.0)*((thisHit->getT0err(J))-0.0)>((thisHit->getT0err((J+1)%getNum)-0.0)*(thisHit->getT0err((J+1)%getNum)-0.0)+.00001)),weight))){continue;}
334
335 //if(!(std::abs((thisHit->getT0(J))-TimeRef)<std::abs(thisHit->getT0((J+1)%2)-TimeRef))){continue;}
336 //if(!(reg_selectors_[regions_[i_reg]]->passCutEq("doing_ca",1.0,weight))){continue;}else{
337 //if(!(std::abs((thisHit->getT0(J))-TimeRef)<std::abs(thisHit->getT0((J+1)%2)-TimeRef))){continue;}
338 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("amp_lt",thisHit->getAmp(0),weight))){continue;}
339 if(!(reg_selectors_[regions_[i_reg]]->passCutGt("amp_gt",thisHit->getAmp(0),weight))){continue;}
340
341 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("time_lt",thisHit->getT0(0),weight))){continue;}
342 if(!(reg_selectors_[regions_[i_reg]]->passCutGt("time_gt",thisHit->getT0(0),weight))){continue;}
343
344 //std::cout<<(float)(thisHit->getT0((J+1)%getNum))<<std::endl;
345 //std::cout<<!(reg_selectors_[regions_[i_reg]]->passCutLt("Otime_lt",(float)(thisHit->getT0((J+1)%getNum)),weight))<<std::endl;
346 //std::cout<<!(reg_selectors_[regions_[i_reg]]->passCutGt("Otime_gt",(float)(thisHit->getT0((J+1)%getNum)),weight))<<std::endl;
347 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("Otime_lt",(float)(thisHit->getT0((J+1)%getNum)),weight))){continue;}
348 if(!(reg_selectors_[regions_[i_reg]]->passCutGt("Otime_gt",(float)(thisHit->getT0((J+1)%getNum)),weight))){continue;}
349
350 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("Stime_lt",(float)(thisHit->getT0((J)%getNum)),weight))){continue;}
351 if(!(reg_selectors_[regions_[i_reg]]->passCutGt("Stime_gt",(float)(thisHit->getT0((J)%getNum)),weight))){continue;}
352
353
354 if(!(reg_selectors_[regions_[i_reg]]->passCutLt("amp2_lt",thisHit->getAmp(0),weight))){continue;}
355 if(!(reg_selectors_[regions_[i_reg]]->passCutEq("channel", (thisHit->getStrip()),weight))){continue;}
356 int * adcs=thisHit->getADCs();
357 int maxx = 0;
358 for(unsigned int K=0; K<6; K++){
359 if(maxx<adcs[K]){maxx=adcs[K];}
360 }
361 if(!(reg_selectors_[regions_[i_reg]]->passCutEq("first_max",adcs[0]-maxx,weight))){continue;}
362
363 //if(!(reg_selectors_[regions_[i_reg]]->passCutEq("time_phase",trigPhase,weight))){continue;}
364
365 bool helper = false;
366 if(doSample_==1){
367 int len=*(&readout+1)-readout;
368 for(int KK=0;KK<len;KK++){
369 if(readout[KK]<200){
370 helper=true;
371 }
372 }
373 }
374 if((doSample_==1)and(helper)){
375 int N = evH_->getEventNumber();
376 //std::cout<<T<<std::endl;
377 //if((regions_[i_reg]=="OneFit")and(feb>=2)){continue;}
378 if((regions_[i_reg]=="CTFit")and((thisHit->getT0(J)<26.0)or(thisHit->getT0(J)>30.0))){continue;}
379 sample(thisHit,regions_[i_reg],ievent,eventTime,N);
380
381 }
382
383 reg_histos_[regions_[i_reg]]->FillHistograms(thisHit,weight,J,i,TimeDiff,AmpDiff);
384 }
385 }
386 }
387 //std::cout<<count1<<std::endl;
388 //std::cout<<count2<<std::endl;
389 return true;
390 }
391
392 /*
393 *
394 *READS IN FROM THE LOCAL BASELINE AND TIME ARRAYS THE PULSE SHAPES AND BASELINES AND PLOTS THEM OVER THE ADC COUNTS
395 THIS ALLOWS US, WHEN ACTIVATED, TO SEE WHAT DECISIONS ARE BEING MADE BY THE FITTING ALGORITHM GIVEN SOME CUT ON OUR PULSES
396 ESTABLISHED BY THE REGION SELECTION IN PROCESS ABOVE.
397 *
398 *
399 */
400
401 void SvtRawDataAnaProcessor::sample(RawSvtHit* thisHit,std::string word, IEvent* ievent,long T,int N){
402 auto mod = std::to_string(thisHit->getModule());
403 auto lay = std::to_string(thisHit->getLayer());
404 //swTag= mmapper_->getStringFromSw("ly"+lay+"_m"+mod);
405 std::string helper = mmapper_->getHwFromSw("ly"+lay+"_m"+mod);
406 //std::cout<<helper<<std::endl;
407 char char_array[helper.length()+1];
408 std::strcpy(char_array,helper.c_str());
409 int feb = (int)char_array[1]-48;
410 int hyb = (int)char_array[3]-48;
411
412
413 if((feb>=2)and(word=="OneFit")){return;}
414 if((feb<2)and(word=="CTFit")){return;}
415 if(thisHit->getChiSq(0)<.85){return;}
416
417
418
419 //std::cout<<"Feb "<<feb<<" ,Hyb "<<hyb<<" ,Baseline Feb<=1: "<<baseErr1_[0][0][(int)thisHit->getStrip()][0]<<" ,Baseline Feb>1: "<<baseErr1_[0][1][(int)thisHit->getStrip()][0]<<" More Baselines "<<baseErr1_[0][2][(int)thisHit->getStrip()][0]<<" ,Baseline Feb>1: "<<baseErr1_[0][3][(int)thisHit->getStrip()][0]<<std::endl;
420 int BigCount = 0;
421 if(feb<=1){
422 BigCount+=feb*2048+hyb*512+(int)(thisHit->getStrip());
423 }else{
424 BigCount+=4096;
425 BigCount+=(feb-2)*2560+hyb*640+(int)(thisHit->getStrip());
426 }
427 //std::cout<<"READ HERE "<<BigCount<<" "<<feb<<" "<<hyb<<" "<<(int)thisHit->getStrip()<<" "<<baseErr1_[feb][hyb][(int)thisHit->getStrip()][0]<<std::endl;
428 int * adcs2=thisHit->getADCs();
429 //std::cout<<regions_[i_reg]<<" "<<readout<<std::endl;
430
431 TF1* fitfunc = fourPoleFitFunction("Pulse 0",0);
432 TF1* fitfunc2 = fourPoleFitFunction("Pulse 1",0);
433 TF1* fitfunc3 = fourPoleFitFunction("Addition",1);
434 //TF1* baseline = new TF1("base","[0]",0.0,150.0);
435 //rETime((float(i))*24.0,T)
436 float TimeShift[2] = {-1*rETime(-(thisHit->getT0(0)),T),-1*rETime(-(thisHit->getT0(1)),T)};
437
438 fitfunc->FixParameter(0,TimeShift[0]);
439 fitfunc->FixParameter(3,thisHit->getAmp(0));
440 if(feb<=1){
441 fitfunc->FixParameter(1,times1_[feb][hyb][(int)thisHit->getStrip()][1]);
442 fitfunc->FixParameter(2,times1_[feb][hyb][(int)thisHit->getStrip()][2]);
443 fitfunc->FixParameter(4,baseErr1_[feb][hyb][(int)thisHit->getStrip()][1]);
444 //baseline->FixParameter(0,baseErr1_[feb][hyb][(int)thisHit->getStrip()][1]);
445 }else{
446 fitfunc->FixParameter(1,times2_[feb-2][hyb][(int)thisHit->getStrip()][1]);
447 fitfunc->FixParameter(2,times2_[feb-2][hyb][(int)thisHit->getStrip()][2]);
448 fitfunc->FixParameter(4,baseErr2_[feb-2][hyb][(int)thisHit->getStrip()][1]);
449 //baseline->FixParameter(0,baseErr2_[feb-2][hyb][(int)thisHit->getStrip()][1]);
450 }
451 if(thisHit->getFitN()==2){
452 fitfunc2->FixParameter(0,TimeShift[1]);
453 fitfunc2->FixParameter(3,thisHit->getAmp(1));
454
455 fitfunc3->FixParameter(0,TimeShift[0]);
456 fitfunc3->FixParameter(3,thisHit->getAmp(0));
457 fitfunc3->FixParameter(5,TimeShift[1]);
458 fitfunc3->FixParameter(8,thisHit->getAmp(1));
459
460 if(feb<=1){
461 fitfunc2->FixParameter(1,times1_[feb][hyb][(int)thisHit->getStrip()][1]);
462 fitfunc2->FixParameter(2,times1_[feb][hyb][(int)thisHit->getStrip()][2]);
463 fitfunc2->FixParameter(4,baseErr1_[feb][hyb][(int)thisHit->getStrip()][1]);
464
465 fitfunc3->FixParameter(1,times1_[feb][hyb][(int)thisHit->getStrip()][1]);
466 fitfunc3->FixParameter(2,times1_[feb][hyb][(int)thisHit->getStrip()][2]);
467 fitfunc3->FixParameter(4,baseErr1_[feb][hyb][(int)thisHit->getStrip()][1]);
468
469 fitfunc3->FixParameter(6,times1_[feb][hyb][(int)thisHit->getStrip()][1]);
470 fitfunc3->FixParameter(7,times1_[feb][hyb][(int)thisHit->getStrip()][2]);
471
472 }else{
473 fitfunc2->FixParameter(1,times2_[feb-2][hyb][(int)thisHit->getStrip()][1]);
474 fitfunc2->FixParameter(2,times2_[feb-2][hyb][(int)thisHit->getStrip()][2]);
475 fitfunc2->FixParameter(4,baseErr2_[feb-2][hyb][(int)thisHit->getStrip()][1]);
476
477 fitfunc3->FixParameter(1,times2_[feb-2][hyb][(int)thisHit->getStrip()][1]);
478 fitfunc3->FixParameter(2,times2_[feb-2][hyb][(int)thisHit->getStrip()][2]);
479 fitfunc3->FixParameter(4,baseErr2_[feb-2][hyb][(int)thisHit->getStrip()][1]);
480
481 fitfunc3->FixParameter(6,times2_[feb-2][hyb][(int)thisHit->getStrip()][1]);
482 fitfunc3->FixParameter(7,times2_[feb-2][hyb][(int)thisHit->getStrip()][2]);
483 }
484 }
485
486 //for(int P=0;P<2;P++){for(int PP=0;PP<4;PP++){ std::cout<<"baseline: "<<baseErr1_[P][PP][(int)thisHit->getStrip()][0]<<std::endl; }}
487
488 //std::cout<<"baseline: "<<baseErr1_[feb][hyb][(int)thisHit->getStrip()][0]<<" "<<baseErr2_[feb-2][hyb][(int)thisHit->getStrip()][0]<<std::endl;
489 //std::cout<<"type for above baseline "<<word<<std::endl;
490 int Length=MatchList_.size();
491 for(int K=0; K<Length;K++){
492 //std::cout<<K<<std::endl;
493 if((word==MatchList_[K])and(readout[K]<200)){
494 //gPad->vRange(0.0,3000.0,150.0,6000.0);
495 readout[K]++;
496 //auto gr = new TGraph();
497 //auto gr2 = new TGraph();
498
499 std::string helper1="Feb: "+std::to_string(feb)+",Hyb: "+std::to_string(hyb)+",ch: "+std::to_string((int)thisHit->getStrip())+", chi_sqr value: "+std::to_string((float)thisHit->getChiSq(0));
500 const char *thing1 = helper1.data();
501 //gr2->SetPoint(0,0.,3000.);gr2->SetPoint(1,0.,6000.);gr2->SetPoint(2,150.0,6000.);
502 //gPad->DrawFrame(0.0,3000.0,150.0,6000.0);
503 TCanvas *c1 = new TCanvas("c");
504 c1->DrawFrame(0.0,3000.0,150.0,7000.0);
505 c1->SetTitle(thing1);
506 //auto gr = new TGraphErrors();
507 //gr->SetName("ADCs");
508 float times[12]; float points[12]; float errors[12]; float zeroes[12];
509 for(int i=0;i<6;i++){
510 //std::cout<<adcs2[i]<<std::endl;
511 //rETime((float(i))*24.0,T)
512 zeroes[i]=0.0;
513 if(feb<=1){
514 times[i]=float(i)*24.0;//-27.0;
515 points[i]=adcs2[i]-baseErr1_[feb][hyb][(int)thisHit->getStrip()][i];
516 errors[i]=baseErr1_[feb][hyb][(int)thisHit->getStrip()][i+6];
517 }else{
518 //std::cout<<(float(i))*24.0-27.0<<" "<<rETime((float(i))*24.0,T)<<std::endl;
519 times[i]=float(i)*24.0;//rETime((float(i))*24.0,T);//(float(i))*24.0-27.0;
520 points[i]=adcs2[i]-baseErr2_[feb-2][hyb][(int)thisHit->getStrip()][i];
521 errors[i]=baseErr2_[feb-2][hyb][(int)thisHit->getStrip()][i+6];
522 }
523 }
524 auto gr = new TGraphErrors(6,times,points,zeroes,errors);
525 gr->SetName("ADCs");
526 gr->SetTitle(thing1);
527 gr->GetYaxis()->SetTitle("ADC Counts");
528 gr->GetXaxis()->SetTitle("ns");
529 gr->GetXaxis()->SetLimits(-10.0,130.);
530 gr->GetHistogram()->SetMaximum(2000.);
531 gr->GetHistogram()->SetMinimum(-500.);
532 //gr2->Draw("");
533 gr->Draw("AL*");
534 //TF1* helper1 = (TF1*)fitfunc->Clone("ff");
535
536 //baseline->SetLineColor(kBlue);
537 //baseline->Draw("same");
538
539 fitfunc->Draw("same");
540 if(thisHit->getFitN()==2){
541 fitfunc2->SetLineColor(kGreen);
542 fitfunc2->Draw("same");
543 fitfunc3->SetLineColor(kOrange);
544 fitfunc3->SetTitle(thing1);
545 fitfunc3->Draw("same");
546
547
548 //TF1 *add = new TF1("ff+gg-base",);
549 //TF1* fitfunc3 = new TF1("ll","ff+gg+base");
550 //TF1* h = new TF1("hh","ff+gg");
551 //add->Draw("same");
552 //auto ADD = new TF1();
553 }
554 //gr->Draw("same");
555 auto legend = new TLegend(0.1,0.7,.48,.9);
556 legend->AddEntry("gr","ADC counts");
557 legend->AddEntry("base","Offline Baselines");
558 legend->AddEntry("Pulse 0","First Pulse");
559 if(thisHit->getFitN()==2){
560 legend->AddEntry("Pulse 1","Second Pulse");
561 legend->AddEntry("Addition","Summed Fit");
562 }
563 legend->Draw("same");
564 std::string helper2=word+std::to_string(readout[K]-1)+".png";
565 const char *thing2 = helper2.data();
566 c1->SaveAs(thing2);
567 //gPad->Clear();
568
569
570 //if(helper2=="OneFit8.png"){
571 //std::cout<<BigCount<<std::endl;
572 //std::cout<<feb<<" "<<hyb<<" "<<(int)thisHit->getStrip()<<std::endl;
573 //std::cout<<adcs2[0]<<" "<<adcs2[1]<<" "<<adcs2[2]<<" "<<adcs2[3]<<" "<<adcs2[4]<<" "<<adcs2[5]<<std::endl;
574 //std::cout<<adcs2[0]-baseErr1_[feb][hyb][(int)thisHit->getStrip()][0]<<" "<<adcs2[1]-baseErr1_[feb][hyb][(int)thisHit->getStrip()][1]<<" "<<adcs2[2]-baseErr1_[feb][hyb][(int)thisHit->getStrip()][2]<<" "<<adcs2[3]-baseErr1_[feb][hyb][(int)thisHit->getStrip()][3]<<" "<<adcs2[4]-baseErr1_[feb][hyb][(int)thisHit->getStrip()][4]<<" "<<adcs2[5]-baseErr1_[feb][hyb][(int)thisHit->getStrip()][5]<<std::endl;
575 //}
576
577
578 //std::cout<<helper2<<std::endl;
579 //std::cout<<N<<std::endl;
580
581
582 //std::cout<<adcs2[0]<<" "<<adcs2[1]<<" "<<adcs2[2]<<" "<<adcs2[3]<<" "<<adcs2[4]<<" "<<adcs2[5]<<" "<<thisHit->getAmp(0)<<" "<<thisHit->getT0(0)<<" "<<BigCount<<" "<<thisHit->getChiSq(0)<<std::endl;
583 }
584 }
585 }
586
587 /*
588 *FILLS IN HISTOGRAMS
589 *
590 */
591
593
594 outF_->cd();
595 for(reg_it it = reg_histos_.begin(); it!=reg_histos_.end(); ++it){
596 std::string dirName = it->first;
597 (it->second)->saveHistos(outF_,dirName);
598 outF_->cd(dirName.c_str());
599 //reg_selectors_[it->first]->getCutFlowHisto()->Scale(.5);
600 //reg_selectors_[it->first]->getCutFlowHisto()->Write();
601 }
602 outF_->Close();
603
604 }
605
#define DECLARE_PROCESSOR(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Definition Processor.h:139
float rETime(float ti, long T)
static std::string getFileName(std::string filePath, bool withExtension)
Definition AnaHelpers.cxx:5
int getEventNumber() const
Definition EventHeader.h:50
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
int getFitN()
Definition RawSvtHit.h:65
double getChiSq(int fitI)
Definition RawSvtHit.h:107
int getStrip()
int getLayer()
Definition RawSvtHit.cxx:88
double getAmp(int fitI)
Definition RawSvtHit.h:101
double getT0(int fitI)
Definition RawSvtHit.h:95
double getT0err(int fitI)
Definition RawSvtHit.h:98
int * getADCs()
Definition RawSvtHit.cxx:76
int getModule()
Definition RawSvtHit.cxx:92
std::vector< std::string > MatchList_
virtual void sample(RawSvtHit *thisHit, std::string word, IEvent *ievent, long t, int i)
float baseErr2_[8][4][640][12]
virtual void configure(const ParameterSet &parameters)
Callback for the Processor to configure itself from the given set of parameters.
virtual void finalize()
Callback for the Processor to take any necessary action when the processing of events finishes,...
std::vector< Particle * > * Part_
std::vector< std::string > regionSelections_
virtual void initialize(TTree *tree)
Callback for the Processor to take any necessary action when the processing of events starts,...
std::map< std::string, std::shared_ptr< RawSvtHitHistos > >::iterator reg_it
float baseErr1_[2][4][512][12]
SvtRawDataAnaProcessor(const std::string &name, Process &process)
std::vector< RawSvtHit * > * svtHits_
virtual float str_to_float(std::string word)
std::map< std::string, std::shared_ptr< RawSvtHitHistos > > reg_histos_
std::map< std::string, std::shared_ptr< BaseSelector > > reg_selectors_
virtual TF1 * fourPoleFitFunction(std::string word, int caser)
std::vector< std::string > regions_
TRefArray getRawHits() const
Definition TrackerHit.h:36