CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
CgemLUTWriter.cxx
Go to the documentation of this file.
1// **************************************************************************/
2// authors: R. Farinelli (INFN Ferrara, Italy)
3//
4
5//include system lib
6#include <iostream>
7#include <iomanip>
8#include <sstream>
9#include <string>
10#include <cmath>
11#include <csignal>
12#include "TFile.h"
13#include "TTree.h"
14#include <iostream>
15#include <fstream>
16#include "stdio.h"
17#include <string>
18#include "TCanvas.h"
19#include "TH2F.h"
20#include "TCut.h"
21#include "TChain.h"
22#include "TF1.h"
23#include <map>
24#include "TSystem.h"
25#include "TStyle.h"
26#include "TMinuit.h"
27#include "TString.h"
28#include "TMath.h"
29
30#include "TSystem.h"
31// Include files
32#include "GaudiKernel/AlgFactory.h"
33#include "GaudiKernel/DataObject.h"
34#include "GaudiKernel/IEventProcessor.h"
35
36#include "GaudiKernel/Incident.h"
37#include "GaudiKernel/IIncidentSvc.h"
38#include "GaudiKernel/Memory.h"
39
40#include <csignal>
41
42#include "GaudiKernel/ISvcLocator.h"
43#include "GaudiKernel/IDataProviderSvc.h"
44#include "GaudiKernel/Bootstrap.h"
45#include "GaudiKernel/RegistryEntry.h"
46#include "GaudiKernel/MsgStream.h"
47
49
50using namespace std;
51//PARAMETERS FOR THE EVENT/HITS SELECTION
52const float TIME_BIN = 6.25; //ns
53const int charge_cut = -40; //fC
54const int charge_max = 70; //fC
55const int signal_time_cut_min = -9300;
56const int signal_time_cut_max = -8800;
57const int noise_time_cut_min_left = -9600;
58const int noise_time_cut_max_left = -9300;
59const int noise_time_cut_min_right = -8600;
60const int noise_time_cut_max_right = -8300;
61const double time_window_signal = ( signal_time_cut_max - signal_time_cut_min ) * 1e-9; //second
63//PARAMETERS FOR THE SELECTION OF BAD CHANNELS -> not used up to now
64const double max_rate = 10000;
65const double max_noise_charge = 8;
66const double max_threshold = 3.;
67const double min_average_efficiency = 0.90;
68const double min_efficiency = 0.80;
69const double failure_rate_efficienct = 0.1;
70const double min_saturation_value = 40;
71//VARIABLE OF THE QAQC
74TChain ch("t1");
75TCanvas *c1 = new TCanvas("c1","c1",800,600);
76int error_counter[N_FEB][N_CHIP]; //0->feb_id 1->chip_id
77bool error_counter_type[N_FEB][N_CHIP][3]; //0->feb_id 1->chip_i 2->noise/thr/eff
79std::fstream outStream;
80double expected_noise_rate = 2000; //Hz
82//OTHERS
83inline double fitfunctionFD(double *x, double *par){ return (par[0]+ par[1]/(1+TMath::Exp(-(x[0]-par[2])/par[3])));}
84int east[11]={2,3,8,9,10,11,17,18,19,20,21};
85int sheet1[32]={23,24,25,26,27,28,29,37,38,39,40,41,42,43,53,54,55,56,57,58,59,60,61,71,72,73,74,75,76,77,78,79};
86
87CgemLUTWriter::CgemLUTWriter(const std::string& name, ISvcLocator* pSvcLocator):
88 Algorithm(name,pSvcLocator){
89 declareProperty("InputFileData" , InputFileData = "ciao.root");
90 declareProperty("InputFileMapping" , InputFileMapping ="mapping.txt");
91 declareProperty("InputFileTiger" , InputFileTiger ="tiger.txt");
92 declareProperty("InputFileHvSetting", InputFileHvSetting="hv_setting.txt");
93 declareProperty("PrintCanvas" , PrintCanvas = false);
94 declareProperty("OutputPdf" , OutputPdf = "Output.pdf");
95 declareProperty("OutputRoot" , OutputRoot = "Output.root");
96 declareProperty("DisableMeasures" , DisableMeasures = false);
97 declareProperty("DisableLowEntries" , DisableLowEntries = false);
98 declareProperty("MinEntries" , MinEntries = 100);
99 declareProperty("Debug" , Debug = false);
100}
101
103
105 MsgStream log(msgSvc(), name());
106 bool print_here = (false || Debug);
107 log << MSG::INFO << "CgemLUTWriter initialize()" << endreq;
108 //
109 //
110 //Define input file
111 inFile_name = InputFileData;
112 std::ifstream inStream(inFile_name, std::ios::binary);
113 //Check the input file ROOT
114 if (!inStream) {
115 std::cerr << "File " << inFile_name << " not found" << std::endl;
116 return StatusCode::FAILURE;
117 }
118 TFile *file1 = new TFile((TString)inFile_name);
119 TTree *tree1 = (TTree*)file1->Get("t1");
120 bool b1(0),b2(0),b3(0);
121 b1=file1->IsOpen();
122 b2=(bool)tree1;
123 if(b2) b3=tree1->IsFolder();
124 if(b1*b2*b3 == 0) {
125 std::cerr <<"ERROR in file "<<inFile_name<<" "<<b1<<" "<<b2<<" "<<b3<<endl;
126 return StatusCode::FAILURE;
127 }
128 //Check the input file Mapping
129 mapping_file.open(InputFileMapping.c_str());
130 if(!mapping_file.is_open()){
131 std::cerr << "File " << InputFileMapping<<" not found"<<endl;
132 return StatusCode::FAILURE;
133 }
134 int nlines_mapping=0;
135 string line_mapping;
136 while(getline(mapping_file,line_mapping)) nlines_mapping++;
137 if(print_here)cout<<"The number of lines in "<<InputFileMapping<<" is: "<<nlines_mapping<<endl;
138 mapping_file.clear();
139 mapping_file.seekg (0, ios_base::beg);
140 getline(mapping_file,line_mapping);
141 //Check the input file Tiger
142 tiger_file.open(InputFileTiger.c_str());
143 if(!tiger_file.is_open()){
144 std::cerr << "File " << InputFileTiger<<" not found"<<endl;
145 return StatusCode::FAILURE;
146 }
147 int nlines_tiger=0;
148 string line_tiger;
149 while(getline(tiger_file,line_tiger)) nlines_tiger++;
150 if(print_here)cout<<"The number of lines in "<<InputFileTiger<<" is: "<<nlines_tiger<<endl;
151 tiger_file.clear();
152 tiger_file.seekg (0, ios_base::beg);
153 getline(tiger_file,line_tiger);
154 //Check the consistency between Tiger and Mapping files
155 if(nlines_tiger!=10241 && nlines_mapping!=10241){
156 std::cerr <<" The number of lines in the files "<<InputFileMapping<<" and "<<InputFileTiger<<" is not correct"<<endl;
157 return StatusCode::FAILURE;
158 }
159 //Check the input file HV Setting
160 hv_file.open(InputFileHvSetting.c_str());
161 if(!hv_file.is_open()){
162 std::cerr << "File " << InputFileHvSetting<<" not found"<<endl;
163 return StatusCode::FAILURE;
164 }
165 string line_hv;
166 int nlines_hv=0;
167 while(getline(hv_file,line_hv)) nlines_hv++;
168 if(print_here)cout<<"The number of lines in "<<InputFileHvSetting<<" is: "<<nlines_hv<<endl;
169 hv_file.clear();
170 hv_file.seekg (0, ios_base::beg);
171 getline(hv_file,line_hv);
172 if(nlines_hv!=2){
173 std::cerr <<" The number of lines in the file "<<InputFileHvSetting<<" is not correct"<<endl;
174 return StatusCode::FAILURE;
175 }
176 //Include the input file to the TChain
177 ch.Add((TString)inFile_name);
178 if(ch.GetEntries()==0){
179 std::cerr << "No entries in the event file "<<inFile_name<<endl;
180 return StatusCode::FAILURE;
181 }
182 //Define the output tree aka LUT
183 Define_TTree();
184 //Define Draw Canvas
185 canvas = new TCanvas("canvas","canvas",800,600);
186 if(PrintCanvas){
187 TString OutputPdf1 = OutputPdf+"[";
188 canvas->Print(OutputPdf1);
189 canvas->Divide(3,2);
190 DrawOption = "";
191 }
192 else{
193 DrawOption = "goff";
194 }
195 //Other TO BE CHECK
196 is_failing=false;
197 expected_noise_per_chip*=ch.GetEntries();
198 //Terminate
199 return StatusCode::SUCCESS;
200}
201
203 MsgStream log(msgSvc(), name());
204 log << MSG::INFO << "CgemLUTWriter execute()" << endreq;
205 Read_HV_Setting();
206 while(mapping_file.peek()!=EOF){
207 Read_Mapping();
208 Read_Tiger();
209 //Measure
210 Measure_Noise();
211 Measure_Threshold();
212 Measure_Signal();
213 //Fill
214 Fill_TTree();
215 //Terminate
216 if(PrintCanvas) canvas->Print((TString)OutputPdf);
217 if(is_failing) return StatusCode::FAILURE;
218 if(FEB_i==79 && chip_i==1 && ch_i==63) return StatusCode::SUCCESS;
219 }
220 return StatusCode::SUCCESS;
221}
222
224 MsgStream log(msgSvc(), name());
225 log << MSG::INFO << "CgemLUTWriter finalize()" << endreq;
226 if(PrintCanvas){
227 TString OutputPdf2 = OutputPdf+"]";
228 canvas->Print(OutputPdf2);
229 }
230 otree->Write();
231 ootree->Fill();
232 ootree->Write();
233 return StatusCode::SUCCESS;
234}
235
236void CgemLUTWriter::Measure_Noise(){
237 bool print_here = (false || Debug);
238 if(print_here) cout<<" --- Start of Measure_Noise ---"<<endl;
239 if(DisableMeasures || (DisableLowEntries && ch.GetEntries(Get_Cut(4))<MinEntries)){
240 LUT_digi_coll[FEB_i][chip_i][ch_i].noise_rate=0;
241 LUT_digi_coll[FEB_i][chip_i][ch_i].noise_charge=0;
242 return;
243 }
244 //time distribution and noise rate
245 canvas->cd(1);
247 TString name_noise_rate = Form("h_noise_rate_%i_%i_%i",FEB_i,chip_i,ch_i);
248 TString command_noise_rate = "GemHit_time>>"+name_noise_rate;
249 TString cut_noise_rate = Get_Cut(4);
250 TH1D *h_noise_rate = new TH1D(name_noise_rate,name_noise_rate,n_bin_noise,noise_time_cut_min_left,noise_time_cut_max_right);
251 if(print_here)cout<<command_noise_rate<<endl;
252 if(print_here)cout<<cut_noise_rate<<endl;
253 ch.Draw(command_noise_rate,cut_noise_rate,DrawOption);
254 double nhitsofnoise = h_noise_rate->GetEntries();
255 double rate = 0;
256 if(ch.GetEntries()) rate = nhitsofnoise/time_window_noise/ch.GetEntries();
257 if(print_here)cout<<ch.GetEntries()<<endl;
258 if(print_here)cout<<nhitsofnoise<<" "<<time_window_noise<<" "<<ch.GetEntries()<<" "<<rate<<endl;
259 //charge distribution and noise charge
260 canvas->cd(2);
261 int n_bin_charge=0.5*(charge_max-charge_cut);
262 TString name_noise_charge = Form("h_noise_charge_%i_%i_%i",FEB_i,chip_i,ch_i);
263 TString command_noise_charge = "GemHit_q>>"+name_noise_charge;
264 TString cut_noise_charge = Get_Cut(4);
265 TH1D *h_noise_charge = new TH1D(name_noise_charge,name_noise_charge,n_bin_charge,charge_cut,charge_max);
266 if(print_here)cout<<command_noise_charge<<endl;
267 if(print_here)cout<<cut_noise_charge<<endl;
268 ch.Draw(command_noise_charge,cut_noise_charge,DrawOption);
269 double noise_charge = h_noise_charge->GetMean();
270 //Terminate
271 LUT_digi_coll[FEB_i][chip_i][ch_i].noise_rate=rate;
272 LUT_digi_coll[FEB_i][chip_i][ch_i].noise_charge=noise_charge;
273 if(print_here){
274 cout<<" --- End of Measure_Noise ---"<<endl;
275 cout<<endl;
276 }
277}
278
279void CgemLUTWriter::Measure_Threshold(){
280 bool print_here = (false || Debug);
281 if(DisableMeasures || (DisableLowEntries && ch.GetEntries(Get_Cut(1))<MinEntries)){
282 LUT_digi_coll[FEB_i][chip_i][ch_i].thr_effective = 0;
283 LUT_digi_coll[FEB_i][chip_i][ch_i].thr_width = 0;
284 return;
285 }
286 if(print_here)cout<<" --- Start of Measure_Threshold ---"<<endl;
287 canvas->cd(3);
288 int min_charge_hist=0; //fC
289 int max_charge_hist=30; //fC
290 double charge_resolution = 1; //fC
291 int n_bin = (max_charge_hist-min_charge_hist)/charge_resolution;
292 TString h_name=Form("h_sginal_charge_thr_fit_%i_%i_%i",FEB_i,chip_i,ch_i);
293 TH1D *h_charge = new TH1D(h_name,h_name,n_bin,min_charge_hist,max_charge_hist);
294 if(print_here) cout<<"Histo: "<<n_bin<<" "<<min_charge_hist<<" "<<max_charge_hist<<endl;
295 TF1 *f_thr = new TF1("f_thr","[0]/(1+exp(-(x-[1])/[2]))",-5,30);
296 TString command_thr = "GemHit_q>>"+h_name;
297 TString cut_thr = Get_Cut(1);
298 if(print_here)cout<<command_thr<<endl;
299 if(print_here)cout<<cut_thr<<endl;
300 ch.Draw(command_thr,cut_thr,DrawOption);
301 double threshold = 0;
302 double thr_wid = 0;
303 if(h_charge->GetEntries()){
304 f_thr->SetParameters(h_charge->GetMaximum(),0.5*h_charge->GetMaximumBin()*charge_resolution,0.2);
305 f_thr->FixParameter(0,h_charge->GetMaximum());
306 f_thr->SetParLimits(1,0,h_charge->GetMaximumBin()*charge_resolution+1);
307 f_thr->SetParLimits(2,0,5);
308 if(print_here){
309 cout<<0<<" "<<0<<" "<<1.5*h_charge->GetMaximum()<<endl;
310 cout<<1<<" "<<0<<" "<<h_charge->GetMaximumBin()*charge_resolution<<endl;
311 cout<<2<<" "<<0<<" "<<2<<endl;
312 cout<<h_charge->GetMaximumBin()<<" "<<h_charge->GetMaximumBin()*charge_resolution<<endl;
313 for(int i=0;i<n_bin;i++)cout<<h_charge->GetBinContent(i+1)<<" ";
314 cout<<endl;
315 }
316 if(print_here){
317 h_charge->Fit("f_thr","W","",-5,h_charge->GetMaximumBin()*charge_resolution+1*charge_resolution);
318 }
319 else{
320 h_charge->Fit("f_thr","WQ","",-5,h_charge->GetMaximumBin()*charge_resolution+1*charge_resolution);
321 }
322 threshold=f_thr->GetParameter(1);
323 thr_wid =f_thr->GetParameter(2);
324 }
325 //Terminate
326 LUT_digi_coll[FEB_i][chip_i][ch_i].thr_effective = threshold;
327 LUT_digi_coll[FEB_i][chip_i][ch_i].thr_width = thr_wid;
328 if(print_here){
329 cout<<" --- End of Measure_Threshold ---"<<endl;
330 cout<<endl;
331 }
332
333}
334
335void CgemLUTWriter::Measure_Signal(){
336 bool print_here = (false || Debug);
337 if(DisableMeasures || (DisableLowEntries && ch.GetEntries(Get_Cut(5))<MinEntries)){
338 LUT_digi_coll[FEB_i][chip_i][ch_i].signal_rate = 0;
339 LUT_digi_coll[FEB_i][chip_i][ch_i].signal_charge_mean = 0;
340 LUT_digi_coll[FEB_i][chip_i][ch_i].signal_charge_saturation = 0;
341 LUT_digi_coll[FEB_i][chip_i][ch_i].signal_saturation_ratio = 0;
342 return;
343 }
344 if(print_here)cout<<" --- Start of Measure_Signal ---"<<endl;
345 //signal mean and max charge
346 canvas->cd(4);
347 int min_charge_hist = -5;
348 int max_charge_hist = 70;
349 int charge_resolution = 2; //0.25; fC
350 int n_bin = (max_charge_hist-min_charge_hist)/charge_resolution;
351 TString h_name2=Form("h_signal_charge_%i_%i_%i",FEB_i,chip_i,ch_i);
352 TH1D *h_charge2 = new TH1D(h_name2,h_name2,n_bin,min_charge_hist,max_charge_hist);
353 TString command_signal_charge = "GemHit_q>>"+h_name2;
354 TString cut_signal_charge = Get_Cut(5);
355 if(print_here)cout<<"Histo2: "<<n_bin<<" "<<min_charge_hist<<" "<<max_charge_hist<<endl;
356 if(print_here)cout<<command_signal_charge<<endl;
357 if(print_here)cout<<cut_signal_charge<<endl;
358 ch.Draw(command_signal_charge,cut_signal_charge,DrawOption);
359 double mean_charge = 0;
360 double max_charge = 0;
361 double saturation_bin_content=0;
362 double maximum_bin_content=-1;
363 if(h_charge2->GetEntries()){
364 mean_charge=h_charge2->GetMean();
365 for(int i=n_bin;i>1;i--){
366 if(h_charge2->GetBinContent(i)>0) {
367 max_charge = h_charge2->GetBinCenter(i);
368 saturation_bin_content=h_charge2->GetBinContent(i);
369 for(int j=i-1;j>1;j--){
370 if(h_charge2->GetBinContent(j)>maximum_bin_content) maximum_bin_content=h_charge2->GetBinContent(j);
371 }
372 break;
373 }
374 }
375 }
376 double rate_sat_max = 0;
377 if(maximum_bin_content) rate_sat_max = saturation_bin_content/maximum_bin_content;
378 //signal rate
379 canvas->cd(5);
380 TString name_rate = Form("h_signal_rate_%i_%i_%i",FEB_i,chip_i,ch_i);
382 TH1D *h_rate = new TH1D(name_rate,name_rate,n_bin_rate,signal_time_cut_min,signal_time_cut_max);
383 TString command_signal_rate = "GemHit_time>>"+name_rate;
384 TString cut_signal_rate = Get_Cut(5);
385 if(print_here)cout<<"Histo3: "<<n_bin_rate<<" "<<signal_time_cut_min<<" "<<signal_time_cut_max<<endl;
386 if(print_here)cout<<command_signal_rate<<endl;
387 if(print_here)cout<<cut_signal_rate<<endl;
388 ch.Draw(command_signal_rate,cut_signal_rate,DrawOption);
389 double nhitsofsignal = h_rate->GetEntries();
390 double sig_rate = 0;
391 if(ch.GetEntries()) sig_rate = nhitsofsignal/time_window_signal/ch.GetEntries();
392 if(print_here)cout<<"Sig Rate: "<<sig_rate<<endl;
393 cout<<"Preparing LUT for FEB: "<<FEB_i<<" \t chip: "<<chip_i<<" \t channel: "<<ch_i<<endl;
394 if(print_here) cout<<sig_rate<<" "<<mean_charge<<" "<<max_charge<<" "<<rate_sat_max<<endl;
395 //Terminate
396 LUT_digi_coll[FEB_i][chip_i][ch_i].signal_rate = sig_rate;
397 LUT_digi_coll[FEB_i][chip_i][ch_i].signal_charge_mean = mean_charge;
398 LUT_digi_coll[FEB_i][chip_i][ch_i].signal_charge_saturation = max_charge;
399 LUT_digi_coll[FEB_i][chip_i][ch_i].signal_saturation_ratio = rate_sat_max;
400 if(print_here){
401 cout<<" --- End of Measure_Signal ---"<<endl;
402 cout<<endl;
403 }
404}
405
406void CgemLUTWriter::Read_Mapping(){
407 bool print_here = (false || Debug);
408 if(print_here)cout<<" --- Start of Read_Mapping ---"<<endl;
409 int layer_ID, channel_ID, gemroc_ID, SW_FEB_ID, FEB_label, HW_FEB_ID, chip_ID;
410 std::string strip;
411 float slope, constant;
412 //Read
413 mapping_file>>layer_ID>>channel_ID>>gemroc_ID>>SW_FEB_ID>>FEB_label>>HW_FEB_ID>>chip_ID>>strip>>slope>>constant;
414 //Set FEB, chip and channel
415 FEB_i = FEB_label;
416 chip_i = chip_ID;
417 ch_i = channel_ID;
418 //Get the strip
419 std::istringstream iss(strip);
420 int strip_i;
421 iss>>strip_i;
422 //Terminate
423 LUT_digi_coll[FEB_i][chip_i][ch_i].layer=layer_ID;
424 LUT_digi_coll[FEB_i][chip_i][ch_i].gemroc=gemroc_ID;
425 LUT_digi_coll[FEB_i][chip_i][ch_i].sw_feb=SW_FEB_ID;
426 LUT_digi_coll[FEB_i][chip_i][ch_i].HW_FEB_ID=HW_FEB_ID;
427 LUT_digi_coll[FEB_i][chip_i][ch_i].qdc_slope=slope;
428 LUT_digi_coll[FEB_i][chip_i][ch_i].qdc_constant=constant;
429 //Terminate side
430 int side=1;
431 for (size_t i = 0; i < sizeof(east) / sizeof(east[0]); ++i){
432 if(east[i]==gemroc_ID) side=-1;
433 }
434 LUT_digi_coll[FEB_i][chip_i][ch_i].side=side;
435 //Terminate sheet
436 int sheet=0;
437 for (size_t i = 0; i < sizeof(sheet1) / sizeof(sheet1[0]); ++i){
438 if(sheet1[i]==FEB_label) sheet=1;
439 }
440 LUT_digi_coll[FEB_i][chip_i][ch_i].sheet=sheet;
441 //Terminate saturation
442 float saturation = 0;
443 if(slope!=0 && constant!=0){
444 saturation=-slope/constant;
445 }
446 LUT_digi_coll[FEB_i][chip_i][ch_i].qdc_saturation=saturation;
447 //Terminate strip
448 if(strip.at(0)=='X'){
449 std::istringstream iss(strip.erase(0,1));
450 int strip_i;
451 iss>>strip_i;
452 //Shift strips
453 if(layer_ID==1 && strip_i>=630) strip_i -= 630;
454 if(layer_ID==2 && strip_i>=832) strip_i -= 832;
455 LUT_digi_coll[FEB_i][chip_i][ch_i].strip_x = strip_i;
456 LUT_digi_coll[FEB_i][chip_i][ch_i].strip_v = -1;
457 }
458 else if(strip.at(0)=='V'){
459 std::istringstream iss(strip.erase(0,1));
460 int strip_i;
461 iss>>strip_i;
462 //Shift strips
463 if(layer_ID==1 && strip_i>=1077) strip_i -= 1077;
464 if(layer_ID==2 && strip_i>=1395) strip_i -= 1395;
465 LUT_digi_coll[FEB_i][chip_i][ch_i].strip_x = -1;
466 LUT_digi_coll[FEB_i][chip_i][ch_i].strip_v = strip_i;
467 }
468 else{
469 LUT_digi_coll[FEB_i][chip_i][ch_i].strip_x = -1;
470 LUT_digi_coll[FEB_i][chip_i][ch_i].strip_v = -1;
471 }
472 if(print_here){
473 cout<<" --- End of Read_Mapping ---"<<endl;
474 cout<<endl;
475 }
476}
477
478void CgemLUTWriter::Read_Tiger(){
479 bool print_here = (false || Debug);
480 if(print_here)cout<<" --- Start of Read_Tiger ---"<<endl;
481 int layer_ID, gemroc_ID, SW_FEB_ID, channel_ID;
482 float baseline_e, baseline_t, vth1, vth2, delta_vth1_baseline, delta_vth2_baseline, thr_t_fC, thr_e_fC;
483 //Read
484 tiger_file>>layer_ID>>gemroc_ID>>SW_FEB_ID>>channel_ID>>baseline_e>>baseline_t>>vth1>>vth2>>delta_vth1_baseline>>delta_vth2_baseline>>thr_t_fC>>thr_e_fC;
485 //Terminate
486 if(LUT_digi_coll[FEB_i][chip_i][ch_i].gemroc==gemroc_ID &&
487 LUT_digi_coll[FEB_i][chip_i][ch_i].sw_feb==SW_FEB_ID &&
488 ch_i==channel_ID)
489 {
490 LUT_digi_coll[FEB_i][chip_i][ch_i].baseline_e=0; //baseline_e;
491 LUT_digi_coll[FEB_i][chip_i][ch_i].baseline_t=0; //baseline_t;
492 LUT_digi_coll[FEB_i][chip_i][ch_i].vth1=thr_t_fC*12.5;
493 LUT_digi_coll[FEB_i][chip_i][ch_i].vth2=thr_e_fC*12.5;
494 LUT_digi_coll[FEB_i][chip_i][ch_i].delta_vth1_baseline=0;//delta_vth1_baseline;
495 LUT_digi_coll[FEB_i][chip_i][ch_i].delta_vth2_baseline=0;//delta_vth2_baseline;
496 LUT_digi_coll[FEB_i][chip_i][ch_i].thr_t_fC=thr_t_fC;
497 LUT_digi_coll[FEB_i][chip_i][ch_i].thr_e_fC=thr_e_fC;
498 }
499 else{
500 cout<<"Mismap mapping-tiger in ROC: "<<LUT_digi_coll[FEB_i][chip_i][ch_i].gemroc<<" "<<gemroc_ID<<endl;
501 cout<<"Mismap mapping-tiger in FEB: "<<LUT_digi_coll[FEB_i][chip_i][ch_i].sw_feb<<" "<<SW_FEB_ID<<endl;
502 cout<<"Mismap mapping-tiger in ch : "<<ch_i<<" "<<channel_ID<<endl;
503 cerr<<"Error while reading Read_Tiger"<<endl;
504 }
505 if(print_here){
506 cout<<" --- End of Read_Tiger ---"<<endl;
507 cout<<endl;
508 }
509
510}
511void CgemLUTWriter::Read_HV_Setting(){
512 bool print_here = (false || Debug);
513 if(print_here)cout<<" --- Start of Read_HV_Setting"<<endl;
514 //Read
515 hv_file>>t_First_RUN>>t_Last_RUN>>t_Integration_time>>t_Energy_mode>>t_HV_L1_G3>>t_HV_L1_G2>>t_HV_L1_G1>>t_HV_L2_G3>>t_HV_L2_G2>>t_HV_L2_G1>>t_HV_L3_G3>>t_HV_L3_G2>>t_HV_L3_G1>>t_HV_L1_Dr>>t_HV_L2_Dr>>t_HV_L3_Dr>>t_HV_L1_T1>>t_HV_L2_T1>>t_HV_L3_T1>>t_HV_L1_T2>>t_HV_L2_T2>>t_HV_L3_T2>>t_HV_L1_In>>t_HV_L2_In>>t_HV_L3_In;
516}
517
518void CgemLUTWriter::Define_TTree(){
519 ofile_name= OutputRoot;
520 ofile = new TFile(ofile_name,"RECREATE");
521 otree = new TTree("tree","tree");
522 //General info
523 otree->Branch("ROC" ,&t_roc ,"ROC/I");
524 otree->Branch("SW_FEB" ,&t_sw_feb ,"SW_FEB/I");
525 otree->Branch("FEB" ,&t_feb ,"FEB/I");
526 otree->Branch("chip" ,&t_chip ,"chip/I");
527 otree->Branch("channel" ,&t_ch ,"channel/I");
528 otree->Branch("layer" ,&t_layer ,"layer/I");
529 otree->Branch("side" ,&t_side ,"side/I");
530 otree->Branch("sheet" ,&t_sheet ,"sheet/I");
531 //Mapping
532 otree->Branch("strip_x_graal" ,&t_strip_x_graal ,"strip_x_graal/I");
533 otree->Branch("strip_v_graal" ,&t_strip_v_graal ,"strip_v_graal/I");
534 otree->Branch("strip_x_boss" ,&t_strip_x_boss ,"strip_x_boss/I");
535 otree->Branch("strip_v_boss" ,&t_strip_v_boss ,"strip_v_boss/I");
536 //Threshold
537 otree->Branch("calib_QDC_slope" ,&t_qdc_slope ,"calib_QDC_slope/F");
538 otree->Branch("calib_QDC_const" ,&t_qdc_constant ,"calib_QDC_const/F");
539 otree->Branch("calib_QDC_saturation" ,&t_qdc_saturation,"calib_QDC_saturation/F");
540 otree->Branch("baseline_T_mV" ,&t_baseline_e ,"baseline_T_mV/F");
541 otree->Branch("baseline_E_mV" ,&t_baseline_t ,"baseline_E_mV/F");
542 otree->Branch("delta_vth1_baseline" ,&t_delta_vth1_baseline ,"delta_vth1_baseline/F");
543 otree->Branch("delta_vth2_baseline" ,&t_delta_vth2_baseline ,"delta_vth2_baseline/F");
544 otree->Branch("v_thr_T_mV" ,&t_vth1 ,"v_thr_T_mV/F");
545 otree->Branch("v_thr_E_mV" ,&t_vth2 ,"v_thr_E_mV/F");
546 otree->Branch("thr_T_fC" ,&t_thr_t_fC ,"thr_T_fC/F");
547 otree->Branch("thr_E_fC" ,&t_thr_e_fC ,"thr_E_fC/F");
548 otree->Branch("thr_fC" ,&t_thr ,"thr_fC/F");
549 otree->Branch("thr_width_fC" ,&t_thr_wid ,"thr_width_fC/F");
550 //Noise
551 otree->Branch("noise_rate_Hz" ,&t_noise_Hz ,"noise_rate_Hz/F");
552 otree->Branch("noise_meanQ_fC" ,&t_noise_Q ,"noise_meanQ_fC/F");
553 //Signal
554 otree->Branch("signal_meanQ_fC" ,&t_sig_meanQ ,"signal_meanQ_fC/F");
555 otree->Branch("signal_maxQ_fC" ,&t_sig_maxQ ,"signal_maxQ_fC/F");
556 otree->Branch("signal_rate_Hz" ,&t_sig_Hz ,"signal_rate_Hz/F");
557 otree->Branch("ratio_satutaion" ,&t_rate_sat_max ,"ratio_satutaion/F");
558 //Time
559 otree->Branch("signal_startTime_ns" ,&t_time_start ,"signal_startTime_ns/F");
560 otree->Branch("signal_stopTime_ns" ,&t_time_stop ,"signal_stopTime_ns/F");
561 otree->Branch("signal_sigmaTime_ns" ,&t_time_sigma ,"signal_sigmaTime_ns/F");
562 otree->Branch("signal_FEBstartTime_ns" ,&t_time_startFEB ,"signal_FEBstartTime_ns/F");
563 otree->Branch("signal_FEBstopTime_ns" ,&t_time_stopFEB ,"signal_FEBstopTime_ns/F");
564 otree->Branch("signal_FEBsigmaTime_ns" ,&t_time_sigmaFEB ,"signal_FEBsigmaTime_ns/F");
565 //Quality
566 otree->Branch("quality" ,&t_quality ,"quality/I");
567 //
568 //
569 ootree = new TTree("general","general");
570 ootree->Branch("First_RUN" ,&t_First_RUN ,"First_RUN/I");
571 ootree->Branch("Last_RUN" ,&t_Last_RUN ,"Last_RUN/I");
572 ootree->Branch("Integration_time",&t_Integration_time,"Integration_time/I");
573 ootree->Branch("Energy_mode" ,&t_Energy_mode ,"Energy_mode/I");
574 ootree->Branch("HV_L1_G3" ,&t_HV_L1_G3 ,"HV_L1_G3/I");
575 ootree->Branch("HV_L2_G3" ,&t_HV_L2_G3 ,"HV_L2_G3/I");
576 ootree->Branch("HV_L3_G3" ,&t_HV_L3_G3 ,"HV_L3_G3/I");
577 ootree->Branch("HV_L1_G2" ,&t_HV_L1_G2 ,"HV_L1_G2/I");
578 ootree->Branch("HV_L2_G2" ,&t_HV_L2_G2 ,"HV_L2_G2/I");
579 ootree->Branch("HV_L3_G2" ,&t_HV_L3_G2 ,"HV_L3_G2/I");
580 ootree->Branch("HV_L1_G1" ,&t_HV_L1_G1 ,"HV_L1_G1/I");
581 ootree->Branch("HV_L2_G1" ,&t_HV_L2_G1 ,"HV_L2_G1/I");
582 ootree->Branch("HV_L3_G1" ,&t_HV_L3_G1 ,"HV_L3_G1/I");
583 ootree->Branch("HV_L1_In" ,&t_HV_L1_In ,"HV_L1_In/I");
584 ootree->Branch("HV_L2_In" ,&t_HV_L2_In ,"HV_L2_In/I");
585 ootree->Branch("HV_L3_In" ,&t_HV_L3_In ,"HV_L3_In/I");
586 ootree->Branch("HV_L1_T2" ,&t_HV_L1_T2 ,"HV_L1_T2/I");
587 ootree->Branch("HV_L2_T2" ,&t_HV_L2_T2 ,"HV_L2_T2/I");
588 ootree->Branch("HV_L3_T2" ,&t_HV_L3_T2 ,"HV_L3_T2/I");
589 ootree->Branch("HV_L1_T1" ,&t_HV_L1_T1 ,"HV_L1_T1/I");
590 ootree->Branch("HV_L2_T1" ,&t_HV_L2_T1 ,"HV_L2_T1/I");
591 ootree->Branch("HV_L3_T1" ,&t_HV_L3_T1 ,"HV_L3_T1/I");
592 ootree->Branch("HV_L1_Dr" ,&t_HV_L1_Dr ,"HV_L1_Dr/I");
593 ootree->Branch("HV_L2_Dr" ,&t_HV_L2_Dr ,"HV_L2_Dr/I");
594 ootree->Branch("HV_L3_Dr" ,&t_HV_L3_Dr ,"HV_L3_Dr/I");
595
596
597}
598
599void CgemLUTWriter::Fill_TTree(){
600 bool print_here = (false || Debug);
601 if(print_here)cout<<" --- Start of Fill_TTree ---"<<endl;
602 t_roc =LUT_digi_coll[FEB_i][chip_i][ch_i].gemroc;
603 t_sw_feb=LUT_digi_coll[FEB_i][chip_i][ch_i].sw_feb;
604 t_feb=FEB_i;
605 t_chip=chip_i;
606 t_ch=ch_i;
607 t_layer=LUT_digi_coll[FEB_i][chip_i][ch_i].layer;
608 t_side=LUT_digi_coll[FEB_i][chip_i][ch_i].side;
609 t_sheet=LUT_digi_coll[FEB_i][chip_i][ch_i].sheet;
610 t_strip_x_graal=-1;
611 t_strip_v_graal=-1;
612 t_strip_x_boss=LUT_digi_coll[FEB_i][chip_i][ch_i].strip_x;
613 t_strip_v_boss=LUT_digi_coll[FEB_i][chip_i][ch_i].strip_v;
614 t_qdc_slope=LUT_digi_coll[FEB_i][chip_i][ch_i].qdc_slope;
615 t_qdc_constant=LUT_digi_coll[FEB_i][chip_i][ch_i].qdc_constant;
616 t_qdc_saturation=LUT_digi_coll[FEB_i][chip_i][ch_i].qdc_saturation;
617 t_baseline_e=LUT_digi_coll[FEB_i][chip_i][ch_i].baseline_e;
618 t_baseline_t=LUT_digi_coll[FEB_i][chip_i][ch_i].baseline_t;
619 t_delta_vth1_baseline=LUT_digi_coll[FEB_i][chip_i][ch_i].delta_vth1_baseline;
620 t_delta_vth2_baseline=LUT_digi_coll[FEB_i][chip_i][ch_i].delta_vth2_baseline;
621 t_vth1=LUT_digi_coll[FEB_i][chip_i][ch_i].vth1;
622 t_vth2=LUT_digi_coll[FEB_i][chip_i][ch_i].vth2;
623 t_thr_t_fC=LUT_digi_coll[FEB_i][chip_i][ch_i].thr_t_fC;
624 t_thr_e_fC=LUT_digi_coll[FEB_i][chip_i][ch_i].thr_e_fC;
625 t_thr=LUT_digi_coll[FEB_i][chip_i][ch_i].thr_effective;
626 t_thr_wid=LUT_digi_coll[FEB_i][chip_i][ch_i].thr_width;
627 t_noise_Hz=LUT_digi_coll[FEB_i][chip_i][ch_i].noise_rate;
628 t_noise_Q=LUT_digi_coll[FEB_i][chip_i][ch_i].noise_charge;
629 t_sig_meanQ=LUT_digi_coll[FEB_i][chip_i][ch_i].signal_charge_mean;
630 t_sig_maxQ=LUT_digi_coll[FEB_i][chip_i][ch_i].signal_charge_saturation;
631 t_sig_Hz=LUT_digi_coll[FEB_i][chip_i][ch_i].signal_rate;
632 t_rate_sat_max=LUT_digi_coll[FEB_i][chip_i][ch_i].signal_saturation_ratio;
633 t_time_start=0;
634 t_time_stop=0;
635 t_time_sigma=0;
636 t_time_startFEB=0;
637 t_time_stopFEB=0;
638 t_time_sigmaFEB=0;
639 t_quality=0;
640 otree->Fill();
641 if(print_here){
642 cout<<" --- End of Fill_TTree ---"<<endl;
643 cout<<endl;
644 }
645
646}
647
648TString CgemLUTWriter::Get_Cut(int cut){
649 bool print_cuts = (false || Debug);
650 TString CUT;
651 TString cut_tiger = Form("GemHit_FEB==%d && GemHit_chip==%d && GemHit_q>%d",FEB_i,chip_i,charge_cut);
652 TString cut_channel = cut_tiger + Form(" && GemHit_channel==%d",ch_i);
653 TString cut_out_of_time = Form(" && ((GemHit_time>=%d && GemHit_time<%d)|| (GemHit_time>=%d && GemHit_time<%d))",noise_time_cut_min_left,noise_time_cut_max_left,noise_time_cut_min_right,noise_time_cut_max_right);
654 TString cut_in_time = Form(" && GemHit_time>=%d && GemHit_time<%d",signal_time_cut_min,signal_time_cut_max);
655 TString cut_tiger_noise_out_of_time = cut_tiger + cut_out_of_time;
656 TString cut_tiger_signal_in_time = cut_tiger + cut_in_time;
657 TString cut_channel_noise_out_of_time = cut_channel + cut_out_of_time;
658 TString cut_channel_signal_in_time = cut_channel + cut_in_time;
659 if(print_cuts){
660 cout<<"N° entries: "<<ch.GetEntries()<<endl;
661 cout<<cut_tiger_noise_out_of_time<<endl;
662 cout<<cut_tiger_signal_in_time<<endl;
663 cout<<cut_channel_noise_out_of_time<<endl;
664 cout<<cut_channel_signal_in_time<<endl;
665 cout<<cut_channel<<endl;
666 }
667 switch(cut){
668 case 0: return cut_tiger;
669 case 1: return cut_channel;
670 case 2: return cut_tiger_noise_out_of_time;
671 case 3: return cut_tiger_signal_in_time;
672 case 4: return cut_channel_noise_out_of_time;
673 case 5: return cut_channel_signal_in_time;
674 }
675 return CUT;
676}
const double min_saturation_value
const int charge_max
double expected_noise_rate
bool error_counter_type[N_FEB][N_CHIP][3]
const int noise_time_cut_min_left
const int signal_time_cut_min
const double max_rate
const int noise_time_cut_max_left
const double min_average_efficiency
TCanvas * c1
int err_comunication(2)
const double min_efficiency
const int charge_cut
int error_counter[N_FEB][N_CHIP]
std::fstream outStream
const int noise_time_cut_max_right
int east[11]
int err_noise(0)
TString outFile
const int signal_time_cut_max
int err_charge(1)
const double failure_rate_efficienct
const double time_window_noise
TString inFileTP
const double time_window_signal
const double max_noise_charge
TString inFile_name
const float TIME_BIN
int sheet1[32]
double expected_noise_per_chip
const int noise_time_cut_min_right
double fitfunctionFD(double *x, double *par)
TChain ch("t1")
const double max_threshold
#define N_CHANNEL
#define N_FEB
#define N_CHIP
Double_t x[10]
*********Class see also m_nmax DOUBLE PRECISION m_MasPhot DOUBLE PRECISION m_phsu DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_r2 DOUBLE PRECISION m_WtMass INTEGER m_nmax INTEGER m_Nevgen INTEGER m_IsFSR INTEGER m_MarTot *COMMON c_KarFin $ !Output file $ !Event serial number $ !alpha QED at Thomson limit $ !minimum energy at CMS for remooval $ !infrared cut
Definition KarFin.h:27
IMessageSvc * msgSvc()
StatusCode finalize()
StatusCode initialize()
StatusCode execute()
CgemLUTWriter(const std::string &name, ISvcLocator *pSvcLocator)