00001 #include <iostream>
00002 #include <string>
00003 #include <typeinfo>
00004 #include <iostream>
00005 #include <vector>
00006
00007
00008 #include "Riostream.h"
00009 #include "TRint.h"
00010 #include "TROOT.h"
00011 #include "TStyle.h"
00012 #include "Riostream.h"
00013 #include "TRandom.h"
00014
00015 #include "TH2.h"
00016 #include "TH1.h"
00017 #include "TF1.h"
00018
00019 #include "TGraph.h"
00020 #include "TMultiGraph.h"
00021 #include "TCanvas.h"
00022 #include "TPad.h"
00023 #include "TProfile.h"
00024 #include "TStopwatch.h"
00025
00026 #include "TFile.h"
00027 #include "TTree.h"
00028 #include "TBranch.h"
00029 #include "TMath.h"
00030 #include "TLegend.h"
00031 #include "TLine.h"
00032 #include "TColor.h"
00033 #include "TText.h"
00034 #include "TKey.h"
00035 #include "TLatex.h"
00036 #include "TCanvas.h"
00037
00038 #include "TPrincipal.h"
00039 #include "TMatrix.h"
00040
00041 #include "TRocEvent.h"
00042 #include "roc/Message.h"
00043 #include "TSpadicEvent.h"
00044
00045
00046 #include "TMbsCrateEvent.h"
00047 #include "TBeamMonitorEvent.h"
00048 #include "TCernOct11UnpackEvent.h"
00049
00050
00051
00052 #define NUM_SPADIC_CHA 8
00053 #define SPADIC_TRACE_SIZE 45
00054 #define SPADIC_ADC_MAX 255
00055 #define noBaselineTB 5
00056 Int_t Pi_Ch1_Min, Pi_Ch1_Max, Pi_Ch2_Min, Pi_Ch2_Max, Pi_Pb_Min, Pi_Pb_Max, El_Ch1_Min, El_Ch1_Max, El_Ch2_Min, El_Ch2_Max, El_Pb_Min, El_Pb_Max;
00057 Bool_t isElectron, isPion, isMyon, isOverFlowEvent, isUnderFlowEvent;
00058 TPrincipal* principal = new TPrincipal(NUM_SPADIC_CHA,"ND");
00059
00060 TH1I *clusterSize = new TH1I("clusterSize","clusterSize",NUM_SPADIC_CHA+1,-0.5,NUM_SPADIC_CHA+0.5);
00061
00062 TH1I *signalChDistance = new TH1I("signalChDistance","signalChDistance",2*NUM_SPADIC_CHA+1,-NUM_SPADIC_CHA-0.5,NUM_SPADIC_CHA+0.5);
00063
00064 Int_t pidcuts[18] = {0};
00065
00066 void Statusbar(Int_t i, Int_t n) {
00067 if (int(i * 100 / float(n)) - int((i-1) * 100 / float(n)) >= 1) {
00068 if (int(i * 100 / float(n)) == 1 || i == 1 || i == 0)
00069 cout << "[" << flush;
00070 cout << "-" << flush;
00071 if (int(i * 10 / float(n)) - int((i-1) * 10 / float(n)) >= 1)
00072 cout << "|";
00073 if (int(i * 100 / float(n)) >=99)
00074 cout << "]" <<endl;
00075 }
00076 }
00077
00078 void CalcPionEfficiency(TH1D* hElectronSpectra, TH1D* hPionSpectra, TProfile* hEfficiency, const Int_t nChambers, Bool_t debug){
00079 Bool_t useAntiProbability = false;
00080 TString cHist, cTitle;
00081 TH1D *sLikelihoodPi[nChambers+1];
00082 TH1D *sLikelihoodEl[nChambers+1];
00083 for (Int_t Chamberloop = 1; Chamberloop <= nChambers; Chamberloop++){
00084 cHist.Form("L_Pi_Prob_temp_%i",Chamberloop);
00085 sLikelihoodPi[Chamberloop] = new TH1D(cHist,"e and pi Prob",220,-0.05,1.05);
00086 cHist.Form("L_El_Prob_temp_%i",Chamberloop);
00087 sLikelihoodEl[Chamberloop] = new TH1D(cHist,"e and pi Prob",220,-0.05,1.05);
00088 }
00089 Int_t nEvents = 100000;
00090 TH1D* hElectronProbability = (TH1D*)hElectronSpectra->Clone("ElectronProbability");
00091
00092 TH1D* hPionProbability = (TH1D*)hPionSpectra->Clone("hPionProbability");
00093
00094 TCanvas *cTemp2;
00095 TCanvas *cTemp;
00096 if (debug) {
00097 cTemp2 = new TCanvas("temp2","temp2",800,600);
00098 cTemp2->Divide(1,1);
00099 cTemp = new TCanvas("temp","temp",800,600);
00100 cTemp->Divide(2,2);
00101 cTemp->cd(1);
00102 hElectronSpectra->DrawCopy();
00103 cTemp->cd(2);
00104 hElectronProbability->DrawCopy();
00105 cTemp->cd(3);
00106 hPionSpectra->DrawCopy();
00107 cTemp->cd(4);
00108 hPionProbability->DrawCopy();
00109 cTemp->Update();
00110 }
00111 hEfficiency->Reset();
00112
00113 hEfficiency->GetYaxis()->SetRangeUser(0.01,100.5);
00114 hEfficiency->SetMarkerStyle(20);
00115 hEfficiency->SetXTitle("Number of detector layer");
00116 hEfficiency->SetYTitle("Pion efficiency [%]");
00117
00118 for (Int_t Chamberloop = 1; Chamberloop <= nChambers; Chamberloop++){
00119 cHist.Form("sLikelihoodPi%02d",Chamberloop);
00120 sLikelihoodPi[Chamberloop]->Reset();
00121 sLikelihoodPi[Chamberloop]->SetNameTitle(cHist,cHist);
00122 sLikelihoodPi[Chamberloop]->SetXTitle("Likelihood");
00123 sLikelihoodPi[Chamberloop]->SetYTitle("#");
00124 cHist.Form("sLikelihoodEl%02d",Chamberloop);
00125 sLikelihoodEl[Chamberloop]->Reset();
00126 sLikelihoodEl[Chamberloop]->SetNameTitle(cHist,cHist);
00127 sLikelihoodEl[Chamberloop]->SetXTitle("Likelihood");
00128 sLikelihoodEl[Chamberloop]->SetYTitle("#");
00129
00130 Bool_t lowStatistic = false;
00131 Int_t nElTries(0), nPiTries(0);
00132
00133 for(Int_t iE = 0;iE < nEvents;iE++){
00134 if (debug) Statusbar(iE,nEvents);
00135 Double_t P_e = 1;
00136 Double_t P_pi = 1;
00137
00138 for(int iCh = 1; iCh <= Chamberloop; iCh++){
00139 if (lowStatistic)
00140 break;
00141
00142 Double_t fEl = 0;
00143 Double_t fPi = 0;
00144 while (fEl == 0 || fPi == 0) {
00145 Double_t chEl = hElectronSpectra->GetRandom();
00146 fEl = hElectronProbability->GetBinContent( hElectronProbability->FindBin(chEl));
00147 fPi = hPionProbability->GetBinContent( hPionProbability->FindBin(chEl));
00148 nElTries++;
00149 if (nElTries/Float_t(Chamberloop*nEvents) > 15) {
00150 printf("too low electron statistic\n");
00151 lowStatistic = true;
00152 break;
00153 }
00154
00155 }
00156 P_e = P_e * (fEl * 1e9);
00157 P_pi = P_pi * (fPi * 1e9);
00158
00159 }
00160 Double_t L_e = 0;
00161 if((P_e+P_pi)>0){
00162 L_e = P_e /(P_e+P_pi);
00163 }
00164 sLikelihoodEl[Chamberloop]->Fill(L_e);
00165
00166 P_e = 1;
00167 P_pi = 1;
00168
00169 Double_t L_p = 0;
00170 if (useAntiProbability) {
00171 for(Int_t iCh = 1;iCh<= Chamberloop;iCh++){
00172 if (lowStatistic)
00173 break;
00174
00175 Double_t fEl = 0;
00176 Double_t fPi = 0;
00177 while (fEl == 0 || fPi == 0) {
00178 Double_t chPi = hPionSpectra->GetRandom();
00179 fEl = hPionProbability->GetBinContent( hPionProbability->FindBin(chPi));
00180 fPi = hElectronProbability->GetBinContent( hElectronProbability->FindBin(chPi));
00181 nPiTries++;
00182 if (nPiTries/Float_t(Chamberloop*nEvents) > 15) {
00183 printf("too low pion statistic\n");
00184 lowStatistic = true;
00185 break;
00186 }
00187
00188 }
00189 P_e = P_e * (fEl * 1e9);
00190 P_pi = P_pi * (fPi * 1e9);
00191
00192 }
00193 L_p = 0;
00194 if((P_e+P_pi)>0){
00195 L_p = P_pi /(P_e+P_pi);
00196 }
00197 }
00198 else {
00199 for(Int_t iCh = 1;iCh<= Chamberloop;iCh++){
00200 if (lowStatistic)
00201 break;
00202
00203 Double_t fEl = 0;
00204 Double_t fPi = 0;
00205 while (fEl == 0 || fPi == 0) {
00206 Double_t chPi = hPionSpectra->GetRandom();
00207 fPi = hPionProbability->GetBinContent( hPionProbability->FindBin(chPi));
00208 fEl = hElectronProbability->GetBinContent( hElectronProbability->FindBin(chPi));
00209 nPiTries++;
00210 if (nPiTries/Float_t(Chamberloop*nEvents) > 15) {
00211 printf("too low pion statistic\n");
00212 lowStatistic = true;
00213 break;
00214 }
00215
00216 }
00217 P_e = P_e * (fEl * 1e9);
00218 P_pi = P_pi * (fPi * 1e9);
00219
00220 }
00221 L_p = 0;
00222 if((P_e+P_pi)>0){
00223 L_p = 1. - (P_pi /(P_e+P_pi));
00224 }
00225 }
00226 if (lowStatistic){
00227 printf(" ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! too low statistic\n");
00228 break;
00229 }
00230 else
00231 sLikelihoodPi[Chamberloop]->Fill(L_p);
00232 }
00233 Double_t ElectronIntegral = 0.0;
00234 Double_t PionIntegral = 0.0;
00235 Int_t ElectronBin = 220;
00236 Double_t ElectronIntAll = sLikelihoodEl[Chamberloop]->Integral(0,220);
00237 Double_t PionIntAll = sLikelihoodPi[Chamberloop]->Integral(0,220);
00238
00239 while (ElectronIntegral < 0.90000 && ElectronBin > 0){
00240 ElectronBin -= 1;
00241 ElectronIntegral = (sLikelihoodEl[Chamberloop]->Integral(ElectronBin,220))/ElectronIntAll;
00242 PionIntegral = (sLikelihoodPi[Chamberloop]->Integral(ElectronBin,220))/PionIntAll;
00243 }
00244 if (debug) {
00245 printf(" layer %d\n",Chamberloop);
00246 printf(" Pioneneffizienz : %8.4f Bin %.3f\n",PionIntegral*100,(ElectronBin)/220.);
00247 printf(" remaining Pieff. : %8.4f Bin %.3f\n",PionIntegral*100*PionIntAll/(PionIntegral*PionIntAll+ElectronIntegral*ElectronIntAll),(ElectronBin)/220.);
00248 printf(" Electroneneffizienz : %8.4f Bin %.3f\n\n",ElectronIntegral*100,(ElectronBin)/220.);
00249 }
00250 hEfficiency->Fill(Chamberloop,PionIntegral*100.);
00251 if (debug) {
00252 cTemp2->cd(1)->SetLogy(1);
00253 hEfficiency->DrawCopy();
00254 cTemp2->Update();
00255 }
00256 }
00257
00258 for (Int_t Chamberloop = 1; Chamberloop <= nChambers; Chamberloop++){
00259 delete sLikelihoodPi[Chamberloop];
00260 delete sLikelihoodEl[Chamberloop];
00261 }
00262
00263
00264 if (debug) {
00265 cTemp->Close();
00266 delete cTemp;
00267 cTemp2->Close();
00268 delete cTemp2;
00269 }
00270 }
00271
00272
00273 void GetPidCuts(TString runId)
00274 {
00275
00276 runId.ReplaceAll("Be_run","");
00277
00278 runId.ReplaceAll("Te_run","");
00279
00280 runId.ReplaceAll(".root","");
00281
00282 int runnumber=runId.Atoi();
00283
00284 pidcuts[0] =1;
00285 pidcuts[1] =1;
00286 pidcuts[2] =1;
00287 pidcuts[3] =1;
00288 pidcuts[4] =1;
00289 pidcuts[5] =1;
00290 pidcuts[6] =1;
00291 pidcuts[7] =1;
00292 pidcuts[8] =1;
00293 pidcuts[9] =1;
00294 pidcuts[10]=1;
00295 pidcuts[11]=1;
00296 pidcuts[12]=1;
00297 pidcuts[13]=1;
00298 pidcuts[14]=1;
00299 pidcuts[15]=1;
00300 pidcuts[16]=1;
00301 pidcuts[17]=1;
00302 if (runnumber < 1910000 ) cout << "[WARN] No PID cuts set! Invalid runnumber " << runnumber << endl;
00303 else if (runnumber >= 2010010 && runnumber <= 2410021) {
00304 pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999;
00305 pidcuts[6] = 0; pidcuts[7] = 400; pidcuts[8] = 0; pidcuts[9] = 400; pidcuts[10]= 0; pidcuts[11]= 900;
00306 pidcuts[12]= 1; pidcuts[13]= 1; pidcuts[14]= 1; pidcuts[15]= 1; pidcuts[16]= 1; pidcuts[17]= 1;
00307 }
00308 else if (runnumber > 2410021 && runnumber <= 2510014) {
00309 pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999;
00310 pidcuts[6] = 0; pidcuts[7] = 400; pidcuts[8] = 0; pidcuts[9] = 400; pidcuts[10]= 0; pidcuts[11]=1500;
00311 pidcuts[12]= 1; pidcuts[13]= 1; pidcuts[14]= 1; pidcuts[15]= 1; pidcuts[16]= 1; pidcuts[17]= 1;
00312 }
00313 else if (runnumber > 2510014 && runnumber <= 2610002) {
00314 pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999;
00315 pidcuts[6] = 0; pidcuts[7] = 400; pidcuts[8] = 0; pidcuts[9] = 400; pidcuts[10]= 0; pidcuts[11]=1500;
00316 pidcuts[12]= 1; pidcuts[13]= 1; pidcuts[14]= 1; pidcuts[15]= 1; pidcuts[16]= 1; pidcuts[17]= 1;
00317 }
00318 else if (runnumber > 2610002 && runnumber <= 2610005) {
00319 pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2500; pidcuts[5] =9999;
00320 pidcuts[6] = 0; pidcuts[7] = 400; pidcuts[8] = 0; pidcuts[9] = 400; pidcuts[10]= 0; pidcuts[11]=1500;
00321 pidcuts[12]= 1; pidcuts[13]= 1; pidcuts[14]= 1; pidcuts[15]= 1; pidcuts[16]= 1; pidcuts[17]= 1;
00322 }
00323 else if (runnumber > 2610005 && runnumber <= 3010011) {
00324 pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999;
00325 pidcuts[6] = 0; pidcuts[7] = 400; pidcuts[8] = 0; pidcuts[9] = 400; pidcuts[10]= 0; pidcuts[11]=1500;
00326 pidcuts[12]= 1; pidcuts[13]= 1; pidcuts[14]= 1; pidcuts[15]= 1; pidcuts[16]= 1; pidcuts[17]= 1;
00327 }
00328
00329 else if (runnumber > 3010015 ) cout << "[WARN] No PID cuts set! Invalid runnumber " << runnumber << endl;
00330 else {cout << "[FATAL] Runnumber totaly f**ked up... exiting root NOW! " << endl;}
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 }
00418 void getPID( Float_t ch1, Float_t ch2, Float_t pb)
00419 {
00420
00421
00422
00423
00424 if (ch1 > pidcuts[0] &&
00425 ch1 < pidcuts[1] &&
00426 ch2 > pidcuts[2] &&
00427 ch2 < pidcuts[3] &&
00428 pb > pidcuts[4] &&
00429 pb < pidcuts[5]
00430 )
00431 {
00432 isElectron=true;
00433 }
00434
00435 else if (ch1 > pidcuts[6] &&
00436 ch1 < pidcuts[7] &&
00437 ch2 > pidcuts[8] &&
00438 ch2 < pidcuts[9] &&
00439 pb > pidcuts[10] &&
00440 pb < pidcuts[11]
00441 )
00442 {
00443 isPion=true;
00444 }
00445
00446 else if (ch1 > pidcuts[12] &&
00447 ch1 < pidcuts[13] &&
00448 ch2 > pidcuts[14] &&
00449 ch2 < pidcuts[15] &&
00450 pb > pidcuts[16] &&
00451 pb < pidcuts[17]
00452 )
00453 {
00454 isMyon=true;
00455 }
00456 }
00457
00458 Int_t GetPadMax(TH1D* inPulse[NUM_SPADIC_CHA]) {
00459 Int_t maxCh = -1;
00460 Double_t maxIntegral = 0.0;
00461 Double_t tempIntegral = 0.0;
00462 Double_t Integral[NUM_SPADIC_CHA] = {0.0};
00463 for(Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00464 tempIntegral = 0.0;
00465 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
00466 if (inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin)) > 0.0)
00467 tempIntegral += inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin));
00468 }
00469 Integral[ch] = tempIntegral;
00470 if (tempIntegral > maxIntegral) {
00471 maxCh = ch;
00472 maxIntegral = tempIntegral;
00473 }
00474 }
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486 return maxCh;
00487 }
00488
00489 Double_t Get3PadIntegral(TH1D* inPulse[NUM_SPADIC_CHA])
00490 {
00491 Int_t maxCh = GetPadMax(inPulse);
00492 Double_t signal = inPulse[maxCh]->Integral();
00493 if (maxCh-1 >= 0)
00494 signal += inPulse[maxCh-1]->Integral();
00495 if (maxCh+1 < NUM_SPADIC_CHA)
00496 signal += inPulse[maxCh+1]->Integral();
00497 return signal;
00498 }
00499 Double_t Get3PadPosAmplitude(TH1D* inPulse[NUM_SPADIC_CHA])
00500 {
00501 Int_t maxCh = GetPadMax(inPulse);
00502 Int_t maxBin = inPulse[maxCh]->GetMaximumBin();
00503 Double_t signal;
00504 if (inPulse[maxCh]->GetBinContent(maxBin) > 0)
00505 signal = inPulse[maxCh]->GetBinContent(maxBin);
00506 if (maxCh-1 >= 0 && inPulse[maxCh-1]->GetBinContent(maxBin) > 0)
00507 signal += inPulse[maxCh-1]->GetBinContent(maxBin);
00508 if (maxCh+1 < NUM_SPADIC_CHA && inPulse[maxCh+1]->GetBinContent(maxBin) > 0)
00509 signal += inPulse[maxCh+1]->GetBinContent(maxBin);
00510 return signal;
00511 }
00512 Double_t Get3PadPosIntegral(TH1D* inPulse[NUM_SPADIC_CHA])
00513 {
00514 const Int_t minBin = 0;
00515 const Int_t maxBin = SPADIC_TRACE_SIZE-1;
00516 Int_t maxCh = -1;
00517 Double_t maxIntegral = 0.0;
00518 Double_t tempIntegral = 0.0;
00519 Double_t Integral[NUM_SPADIC_CHA] = {0.0};
00520 for(Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00521 tempIntegral = 0.0;
00522 for (Int_t bin = minBin; bin < maxBin; bin++) {
00523 if (inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin)) > 0.0)
00524 tempIntegral += inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin));
00525 }
00526 Integral[ch] = tempIntegral;
00527 if (tempIntegral > maxIntegral) {
00528 maxCh = ch;
00529 maxIntegral = tempIntegral;
00530 }
00531 }
00532 Double_t signal = Integral[maxCh];
00533 if (maxCh-1 >= 0)
00534 signal += Integral[maxCh-1];
00535 if (maxCh+1 < NUM_SPADIC_CHA)
00536 signal += Integral[maxCh+1];
00537 return signal;
00538 }
00539 Double_t Get3PadPosIntegralCrossTalk(TH1D* inPulse1[NUM_SPADIC_CHA], TH1D* inPulse2[NUM_SPADIC_CHA], Int_t *deltaChMax)
00540 {
00541 const Int_t minBin = 0;
00542 const Int_t maxBin = SPADIC_TRACE_SIZE-1;
00543 Int_t maxCh1(-1), maxCh2(-1);
00544 Double_t maxIntegral1(0.0), maxIntegral2(0.0);
00545 Double_t tempIntegral1(0.0), tempIntegral2(0.0);
00546 Double_t Integral1[NUM_SPADIC_CHA] = {0.0};
00547 Double_t Integral2[NUM_SPADIC_CHA] = {0.0};
00548 for(Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00549 tempIntegral1 = 0.0;
00550 tempIntegral2 = 0.0;
00551 for (Int_t bin = minBin; bin < maxBin; bin++) {
00552 if (inPulse1[ch]->GetBinContent(inPulse1[ch]->FindBin(bin)) > 0.0)
00553 tempIntegral1 += inPulse1[ch]->GetBinContent(inPulse1[ch]->FindBin(bin));
00554 if (inPulse2[ch]->GetBinContent(inPulse2[ch]->FindBin(bin)) > 0.0)
00555 tempIntegral2 += inPulse2[ch]->GetBinContent(inPulse2[ch]->FindBin(bin));
00556 }
00557 Integral1[ch] = tempIntegral1;
00558 Integral2[ch] = tempIntegral2;
00559 if (tempIntegral1 > maxIntegral1) {
00560 maxCh1 = ch;
00561 maxIntegral1 = tempIntegral1;
00562 }
00563 if (tempIntegral2 > maxIntegral2) {
00564 maxCh2 = ch;
00565 maxIntegral2 = tempIntegral2;
00566 }
00567 }
00568 *deltaChMax = fabs(maxCh1 - maxCh2) ;
00569 for(Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00570 Integral1[ch] += Integral2[ch];
00571 }
00572 Double_t signal = Integral1[maxCh1];
00573 if (maxCh1-1 >= 0)
00574 signal += Integral1[maxCh1-1];
00575 if (maxCh1+1 < NUM_SPADIC_CHA)
00576 signal += Integral1[maxCh1+1];
00577 return signal;
00578
00579 }
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603 void CalcPrf(TH1D* inPulse[NUM_SPADIC_CHA], TH2D* prf, TProfile* prfProfile, Double_t padWidth)
00604 {
00605 const Int_t minBin = 0;
00606 const Int_t maxBin = SPADIC_TRACE_SIZE-1;
00607 Int_t maxCh = GetPadMax(inPulse);
00608 Double_t intensCh[NUM_SPADIC_CHA] = {0.0};
00609 if (maxCh >= 1 && maxCh <= NUM_SPADIC_CHA - 1){
00610 for (Int_t ch = maxCh-1; ch <= maxCh+1; ch++){
00611 for (Int_t bin = minBin; bin < maxBin; bin++) {
00612 if (inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin)) > 0.0)
00613 intensCh[ch] += inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin));
00614 }
00615 }
00616 Double_t dxPos = 0.5 * log((intensCh[maxCh+1] / intensCh[maxCh-1])) / log((pow(intensCh[maxCh],2) / (intensCh[maxCh+1] * intensCh[maxCh-1])));
00617
00618 Double_t chargePercent = intensCh[maxCh-1] / (intensCh[maxCh-1] + intensCh[maxCh] + intensCh[maxCh+1]);
00619 prf->Fill((-dxPos-1)*padWidth, chargePercent);
00620 prfProfile->Fill((-dxPos-1)*padWidth ,chargePercent);
00621 chargePercent = intensCh[maxCh] / (intensCh[maxCh-1] + intensCh[maxCh] + intensCh[maxCh+1]);
00622 prf->Fill((dxPos)*padWidth,chargePercent);
00623 prfProfile->Fill((dxPos)*padWidth ,chargePercent);
00624 chargePercent = intensCh[maxCh+1] / (intensCh[maxCh-1] + intensCh[maxCh] + intensCh[maxCh+1]);
00625 prf->Fill((-dxPos+1)*padWidth,chargePercent);
00626 prfProfile->Fill((-dxPos+1)*padWidth ,chargePercent);
00627 }
00628 }
00629 void FillAverageSignal(TH1D* inPulse[NUM_SPADIC_CHA], TProfile* averagePulse)
00630 {
00631 const Int_t minBin = 0;
00632 const Int_t maxBin = SPADIC_TRACE_SIZE-1;
00633 Int_t maxCh = GetPadMax(inPulse);
00634 for (Int_t bin = minBin; bin < maxBin; bin++) {
00635 averagePulse->Fill(bin,inPulse[maxCh]->GetBinContent(inPulse[maxCh]->FindBin(bin)));
00636 }
00637 }
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 Bool_t HitTimeWindow(TH1D* inPulse[NUM_SPADIC_CHA]) {
00678 Int_t maxCh = GetPadMax(inPulse);
00679 if (inPulse[maxCh]->GetMaximumBin() > 13 && inPulse[maxCh]->GetMaximumBin() < 20)
00680 return true;
00681
00682 return false;
00683 }
00684
00685 Bool_t BorderPadMax(TH1D* inPulse[NUM_SPADIC_CHA]) {
00686 Int_t maxCh = GetPadMax(inPulse);
00687 if (maxCh == 0 || maxCh == NUM_SPADIC_CHA-1)
00688 return true;
00689 return false;
00690 }
00691 Bool_t minimumIntegralThreshold(TH1D* inPulse[NUM_SPADIC_CHA]) {
00692 if (Get3PadPosIntegral(inPulse) > 50)
00693 return true;
00694 return false;
00695 }
00696
00697 Bool_t minimumAmplitudeThreshold(TH1D* inPulse[NUM_SPADIC_CHA]) {
00698 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++)
00699 if (inPulse[ch]->GetBinContent(inPulse[ch]->GetMaximumBin()) > 20)
00700 return true;
00701 return false;
00702 }
00703
00704
00705 void BaselineCompensation(TH1D* inPulse[NUM_SPADIC_CHA], TH1D* outPulse[NUM_SPADIC_CHA])
00706 {
00707 Double_t baseline[NUM_SPADIC_CHA] = {0.0};
00708 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00709 outPulse[ch]->Reset();
00710 for (Int_t bin = 0; bin < noBaselineTB; bin++){
00711 baseline[ch] += inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin));
00712 }
00713 baseline[ch] /= noBaselineTB;
00714 }
00715
00716 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00717 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++){
00718 outPulse[ch]->Fill(bin, inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin)) - baseline[ch]);
00719 }
00720 }
00721 }
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740 void CancelNoise_Cova(TH1D* inPulse[NUM_SPADIC_CHA],TH1D* outPulse[NUM_SPADIC_CHA], bool debug=false)
00741 {
00742 const double lowercorthreshold = 0.112;
00743
00744
00745 Double_t cortest[NUM_SPADIC_CHA];
00746 Double_t inputarray[SPADIC_TRACE_SIZE][NUM_SPADIC_CHA] = {{0.0}};
00747 Double_t minIntegral = 265*45;
00748 Double_t tempIntegral = 0.0;
00749 int minch = -1;
00750 for(Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00751 tempIntegral = 0.0;
00752 outPulse[ch]->Reset();
00753 for(Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++){
00754 inputarray[bin][ch] = inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin));
00755 tempIntegral += inputarray[bin][ch];
00756 }
00757 if (tempIntegral < minIntegral){
00758 minIntegral = tempIntegral;
00759 minch = ch;
00760 }
00761 }
00762
00763
00764
00765 int noise_ch_counter=0;
00766
00767 Double_t thisisnoise[SPADIC_TRACE_SIZE] = {0.0};
00768
00769
00770
00771
00772
00773 for(int t=0;t<SPADIC_TRACE_SIZE;t++)
00774 {
00775 principal->AddRow(inputarray[t]);
00776 }
00777
00778 principal->MakePrincipals();
00779
00780 TMatrixD* cova = (TMatrixD*)principal->GetCovarianceMatrix();
00781
00782 Int_t lastSigCh = -1;
00783
00784 for(int ch=0;ch<NUM_SPADIC_CHA;ch++)
00785 {
00786 cortest[ch] = TMatrixDRow (*cova,minch)(ch);
00787 if(cortest[ch]>lowercorthreshold)
00788 {
00789 noise_ch_counter++;
00790
00791 for(Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++){
00792 thisisnoise[bin] += inputarray[bin][ch];
00793 }
00794 }
00795 else {
00796 if (lastSigCh != -1)
00797 signalChDistance->Fill(ch - lastSigCh);
00798 lastSigCh = ch;
00799 }
00800 }
00801
00802 for(Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++){
00803 thisisnoise[bin] /= (double)noise_ch_counter;
00804 }
00805
00806 clusterSize->Fill(NUM_SPADIC_CHA-noise_ch_counter);
00807
00808
00809
00810 for (int ch=0; ch<NUM_SPADIC_CHA; ch++)
00811 {
00812 for (int k=0; k<SPADIC_TRACE_SIZE; k++)
00813 {
00814
00815
00816
00817
00818
00819
00820 outPulse[ch]->Fill(k, inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(k)) - thisisnoise[k]);
00821 }
00822 }
00823
00824 principal->Clear();
00825 }
00826 void CalcDeltaSim(TH1D *delta, TH1D *sim, TH1D *measurement) {
00827 delta->SetYTitle("#frac{measured}{simulated}");
00828 delta->GetXaxis()->SetLabelSize(0.08);
00829 delta->GetYaxis()->SetLabelSize(0.08);
00830 delta->GetXaxis()->SetTitleSize(0.09);
00831 delta->GetYaxis()->SetTitleSize(0.09);
00832 delta->GetYaxis()->SetTitleOffset(0.5);
00833 delta->GetXaxis()->SetTitleOffset(1.0);
00834
00835 delta->Divide(sim);
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847 }
00848
00849 Double_t Calibration(TString file) {
00850 TFile *output = new TFile(file,"READ");
00851 if (output->IsOpen()) {
00852 TH1D* uncalibrated = (TH1D*)output->Get("Uncalibrated_Pions");
00853 TF1 *landau = new TF1("landau","landau",-1000,15000);
00854 uncalibrated->Fit(landau,"0QR");
00855 return landau->GetParameter("MPV")*0.85;
00856 }
00857 else
00858 return 1;
00859 }
00860
00861 void FillUnCalibratedPionSpectrum(TString filename, TString file, Int_t usedSuId, Bool_t amplitude, Bool_t debug) {
00862 printf("---FillUnCalibratedPionSpectrum---\n");
00863 TFile *output = new TFile(file,"UPDATE");
00864 if (output->IsOpen()) {
00865 TH1D* uncalibrated = new TH1D("Uncalibrated_Pions","Uncalibrated Pion Spectrum",200,-1000,15000);
00866 TH1D *rawPulse[NUM_SPADIC_CHA];
00867 TH1D *baselinePulse[NUM_SPADIC_CHA];
00868 TH1D *baselineNoisePulse[NUM_SPADIC_CHA];
00869 TString name;
00870 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
00871 name.Form("Ch%02i",ch);
00872 rawPulse[ch] = new TH1D("rawPulse"+name,"rawPulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00873 baselinePulse[ch] = new TH1D("baselinePulse"+name,"baselinePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00874 baselineNoisePulse[ch] = new TH1D("baselineNoisePulse"+name,"baselineNoisePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00875 }
00876 name = filename;
00877 name.ReplaceAll(".root","");
00878 GetPidCuts(name.ReplaceAll("data2011/TTrees/",""));
00879 TFile inputFile(filename,"READ");
00880 if (inputFile.IsOpen()) {
00881 TTree* theTree=NULL;
00882 TKey* kee=NULL;
00883 TIter iter(inputFile.GetListOfKeys());
00884 while ( ( kee=dynamic_cast<TKey*>(iter()) ) !=0 ) {
00885 theTree = dynamic_cast<TTree*>(kee->ReadObj());
00886 if (theTree)
00887 break;
00888 }
00889 if(theTree==0) {
00890 cout <<"Error: no Tree in file "<< filename.Data() << endl;
00891 return;
00892 }
00893 TCernOct11UnpackEvent* evnt = new TCernOct11UnpackEvent;
00894 TGo4EventElement* theBase=evnt;
00895 evnt->synchronizeWithTree(theTree, &theBase);
00896 Int_t entries = theTree->GetEntries();
00897 printf("%i Events found in TTree\n",entries);
00898 TMbsCrateEvent* fCrateInputEvent;
00899 TSpadicEvent* SpadicInputEvent;
00900 TSpadicData* theSpadic;
00901 Float_t Ch1(0), Ch2(0), Pb(0);
00902 if (debug) entries /= 100;
00903 for(Int_t i=0;i<entries;++i) {
00904 Statusbar(i,entries);
00905 theTree->GetEntry(i);
00906 fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(evnt->GetSubEvent("MBSCRATE"));
00907 SpadicInputEvent=dynamic_cast<TSpadicEvent*>(evnt->GetSubEvent("SPADIC"));
00908 isPion = false;
00909 isElectron = false;
00910 isOverFlowEvent = false;
00911 isUnderFlowEvent = false;
00912 Ch1 = fCrateInputEvent->fData1182[1][0];
00913 Ch2 = fCrateInputEvent->fData1182[0][1];
00914 Pb = fCrateInputEvent->fData1182[1][5];
00915 getPID(Ch1, Ch2, Pb);
00916
00917
00918 theSpadic=dynamic_cast<TSpadicData*>(SpadicInputEvent->getEventElement(usedSuId));
00919 if (isPion){
00920 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
00921 rawPulse[ch]->Reset();
00922 baselinePulse[ch]->Reset();
00923 baselineNoisePulse[ch]->Reset();
00924
00925 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
00926 rawPulse[ch]->Fill(bin, (Double_t)theSpadic->fSpadicPulse[ch][bin]);
00927 }
00928 }
00929
00930 BaselineCompensation(rawPulse, baselinePulse);
00931 CancelNoise_Cova(baselinePulse, baselineNoisePulse, false);
00932
00933 if(amplitude){
00934 if(minimumAmplitudeThreshold(baselineNoisePulse) && !BorderPadMax(baselineNoisePulse) && HitTimeWindow(baselineNoisePulse) && minimumIntegralThreshold(baselineNoisePulse))
00935 uncalibrated->Fill(Get3PadPosAmplitude(baselinePulse));
00936 }
00937 else{
00938 if(minimumAmplitudeThreshold(baselineNoisePulse) && !BorderPadMax(baselineNoisePulse) && HitTimeWindow(baselineNoisePulse) && minimumIntegralThreshold(baselineNoisePulse))
00939 uncalibrated->Fill(Get3PadPosIntegral(baselinePulse));
00940 }
00941 }
00942 }
00943 output->cd();
00944 uncalibrated->Write("", TObject::kOverwrite);
00945 output->Close();
00946 inputFile.Close();
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965 }
00966 else {
00967 printf("ERROR::FillUnCalibratedPionSpectrum: %s not found",filename.Data());
00968 }
00969 }
00970 else {
00971 printf("ERROR::FillUnCalibratedPionSpectrum: %s not found",file.Data());
00972
00973 }
00974 }
00975
00976
00977 void spadic_noise_Analysis(TString filename="data2011/TTrees/Be_run2310004.root",TString radiator = "D", const Int_t suid = 1, Bool_t debug=false, Bool_t simple = false, Bool_t plotFromFile = true)
00978 {
00979 gROOT->Reset();
00980 gROOT->SetStyle("Plain");
00981 gStyle->SetPalette(1,0);
00982 gStyle->SetOptStat(kFALSE);
00983 gStyle->SetOptTitle(kFALSE);
00984 Bool_t amplitude = false;
00985 clusterSize->SetXTitle("cluster width [channels]");
00986 clusterSize->SetYTitle("normalized counts");
00987 signalChDistance->SetXTitle("distance to next signal channel [channels]");
00988 signalChDistance->SetYTitle("normalized counts");
00989 if (suid > 7){
00990 printf("ERROR:: did not find susibo %i\n",suid);
00991 return;
00992 }
00993 const Int_t usedSusibos = 8;
00994 Int_t usedSuId[usedSusibos] = { 2, 12, 6, 18, 4, 5, 16, 17 };
00995 TString usedSuName[usedSusibos] = {"MS336/10","MS336/11","MS444/10","MS444/11","FFM01","FFM02","FFM03","FFM04"};
00996 Double_t padWidth[usedSusibos] = {5,5,8,8,0,0,0,0};
00997 Double_t h[usedSusibos] = {3,3,4,4,0,0,0,0};
00998 Double_t K3 = 0.525;
00999 Double_t par = 1.0;
01000 TString outpic;
01001 TString outfilename;
01002 outpic = filename;
01003 outpic.ReplaceAll("data2011/TTrees/","");
01004 outpic.ReplaceAll(".root","");
01005 outfilename.Form("root/Spectra_%s_Rad_%s_Sus%02i.root",outpic.Data(),radiator.Data(),usedSuId[suid]);
01006 outpic = outfilename;
01007 outpic.ReplaceAll("root/","pics/");
01008 outpic.ReplaceAll(".root","");
01009 Double_t MPV_pion = Calibration(outfilename);
01010 if (MPV_pion == 1) {
01011 FillUnCalibratedPionSpectrum(filename,outfilename, usedSuId[suid], amplitude, debug);
01012 MPV_pion = Calibration(outfilename);
01013 }
01014 printf("MPV_pion: %.3e\n",MPV_pion);
01015 Double_t scaling2keV = 3.65338e+00/MPV_pion;
01016 Int_t nbins(200),lbin(-1000),hbin(15000);
01017
01018 if(amplitude) {
01019 lbin /= 20;
01020 hbin /= 20;
01021 }
01022 else {
01023 nbins = 200;
01024 lbin = 0;
01025 hbin = 100;
01026 }
01027 TFile *output = new TFile(outfilename,"UPDATE");
01028 TH2F* Ch1_Pb;
01029 TH2F* noCh1_Pb;
01030 TH2F* Ch2_Pb;
01031 TH2F* noCh2_Pb;
01032 TH2F* Ch1_Ch2;
01033 TH2F* noCh1_Ch2;
01034
01035 TH2D* prf;
01036 TProfile* prfProfile;
01037
01038 TH1D *preCompPulse[NUM_SPADIC_CHA];
01039 TH1D *preCompBaselinePulse[NUM_SPADIC_CHA];
01040 TH1D *rawPulse[NUM_SPADIC_CHA];
01041 TH1D *baselinePulse[NUM_SPADIC_CHA];
01042 TH1D *noisePulse[NUM_SPADIC_CHA];
01043 TH1D *baselineNoisePulse[NUM_SPADIC_CHA];
01044 TH1D *noiseBaselinePulse[NUM_SPADIC_CHA];
01045 TH1D *lastPulse[NUM_SPADIC_CHA];
01046 TH2I *offSpillPulse[NUM_SPADIC_CHA];
01047
01048 TProfile *averagePulse_e;
01049 TProfile *averagePulse_p;
01050
01051 TH1D *preCompSpectrum;
01052 TH1D *preCompBaselineSpectrum;
01053 TH1D *preCompSpectrumElectron;
01054 TH1D *preCompBaselineSpectrumElectron;
01055 TH1D *rawSpectrum;
01056 TH1D *baselineSpectrum;
01057 TH1D *noiseSpectrum;
01058 TH1D *baselineNoiseSpectrum;
01059 TH1D *baselineNoiseSpectrumWoOWoU;
01060 TH1D *baselineNoiseSpectrumElectron;
01061 TH1D *baselineNoiseSpectrumWoOWoUElectron;
01062 TH1D *noiseBaselineSpectrum;
01063 TH1D *probabilityOverflow;
01064 TH1D *probabilityUnderflow;
01065 TH1D *probabilityOverflowE;
01066 TH1D *probabilityUnderflowE;
01067
01068 TProfile *crossTalk = new TProfile("CrossTalk","CrossTalk",6,-0.5,5.5);
01069
01070 TH1D *baselineNoiseSpectrumCrossTalkE[6];
01071 TH1D *baselineNoiseSpectrumCrossTalkP[6];
01072
01073 TString name;
01074 Int_t color[NUM_SPADIC_CHA] = {1,2,3,4,800,6,7,8};
01075
01076 if (plotFromFile) {
01077 output->cd();
01078 Ch1_Pb = (TH2F*)output->Get("Ch1_Pb");
01079 if (!Ch1_Pb)
01080 cout << "Ch1_Pb" << endl;
01081 noCh1_Pb = (TH2F*)output->Get("noCh1_Pb");
01082 if (!noCh1_Pb)
01083 cout << "noCh1_Pb" << endl;
01084 Ch2_Pb = (TH2F*)output->Get("Ch2_Pb");
01085 if (!Ch2_Pb)
01086 cout << "Ch2_Pb" << endl;
01087 noCh2_Pb = (TH2F*)output->Get("noCh2_Pb");
01088 if (!noCh2_Pb)
01089 cout << "noCh2_Pb" << endl;
01090 Ch1_Ch2 = (TH2F*)output->Get("Ch1_Ch2");
01091 if (!Ch1_Ch2)
01092 cout << "Ch1_Ch2" << endl;
01093 noCh1_Ch2 = (TH2F*)output->Get("noCh1_Ch2");
01094 if (!noCh1_Ch2)
01095 cout << "noCh1_Ch2" << endl;
01096
01097 prf = (TH2D*)output->Get("PRF_2D");
01098 if (!prf)
01099 cout << "PRF_2D" << endl;
01100 prfProfile = (TProfile*)output->Get("PRF");
01101 if (!prfProfile)
01102 cout << "PRF" << endl;
01103
01104 averagePulse_e = (TProfile*)output->Get("averagePulse_e");
01105 if (!averagePulse_e)
01106 cout << "averagePulse_e" << endl;
01107 averagePulse_p = (TProfile*)output->Get("averagePulse_p");
01108 if (!averagePulse_p)
01109 cout << "averagePulse_p" << endl;
01110
01111 preCompSpectrum = (TH1D*)output->Get("preCompSpectrum");
01112 if (!preCompSpectrum)
01113 cout << "preCompSpectrum" << endl;
01114 preCompBaselineSpectrum = (TH1D*)output->Get("preCompBaselineSpectrum");
01115 if (!preCompBaselineSpectrum)
01116 cout << "preCompBaselineSpectrum" << endl;
01117 preCompSpectrumElectron = (TH1D*)output->Get("preCompSpectrumElectron");
01118 if (!preCompSpectrumElectron)
01119 cout << "preCompSpectrumElectron" << endl;
01120 preCompBaselineSpectrumElectron = (TH1D*)output->Get("preCompBaselineSpectrumElectron");
01121 if (!preCompBaselineSpectrumElectron)
01122 cout << "preCompBaselineSpectrumElectron" << endl;
01123 rawSpectrum = (TH1D*)output->Get("rawSpectrum");
01124 if (!rawSpectrum)
01125 cout << "rawSpectrum" << endl;
01126 baselineSpectrum = (TH1D*)output->Get("baselineSpectrum");
01127 if (!baselineSpectrum)
01128 cout << "baselineSpectrum" << endl;
01129 noiseSpectrum = (TH1D*)output->Get("noiseSpectrum");
01130 if (!noiseSpectrum)
01131 cout << "noiseSpectrum" << endl;
01132 baselineNoiseSpectrum = (TH1D*)output->Get("baselineNoiseSpectrum");
01133 if (!baselineNoiseSpectrum)
01134 cout << "baselineNoiseSpectrum" << endl;
01135 baselineNoiseSpectrumWoOWoU = (TH1D*)output->Get("baselineNoiseSpectrumWoOWoU");
01136 if (!baselineNoiseSpectrumWoOWoU)
01137 cout << "baselineNoiseSpectrumWoOWoU" << endl;
01138 baselineNoiseSpectrumElectron = (TH1D*)output->Get("baselineNoiseSpectrumElectron");
01139 if (!baselineNoiseSpectrumElectron)
01140 cout << "baselineNoiseSpectrumElectron" << endl;
01141 baselineNoiseSpectrumWoOWoUElectron = (TH1D*)output->Get("baselineNoiseSpectrumWoOWoUElectron");
01142 if (!baselineNoiseSpectrumWoOWoUElectron)
01143 cout << "baselineNoiseSpectrumWoOWoUElectron" << endl;
01144 noiseBaselineSpectrum = (TH1D*)output->Get("noiseBaselineSpectrum");
01145 if (!noiseBaselineSpectrum)
01146 cout << "noiseBaselineSpectrum" << endl;
01147 probabilityOverflow = (TH1D*)output->Get("probabilityOverflow");
01148 if (!probabilityOverflow)
01149 cout << "probabilityOverflow" << endl;
01150 probabilityUnderflow = (TH1D*)output->Get("probabilityUnderflow");
01151 if (!probabilityUnderflow)
01152 cout << "probabilityUnderflow" << endl;
01153 probabilityOverflowE = (TH1D*)output->Get("probabilityOverflowE");
01154 if (!probabilityOverflowE)
01155 cout << "probabilityOverflowE" << endl;
01156 probabilityUnderflowE = (TH1D*)output->Get("probabilityUnderflowE");
01157 if (!probabilityUnderflowE)
01158 cout << "probabilityUnderflowE" << endl;
01159
01160 crossTalk = (TProfile *)output->Get("CrossTalk");
01161 if (!crossTalk)
01162 cout << "crossTalk" << endl;
01163
01164 for(Int_t delta = 0; delta < 6; delta++) {
01165 name.Form("_delta%02i",delta);
01166 baselineNoiseSpectrumCrossTalkE[delta] = (TH1D*)output->Get("baselineNoiseSpectrumCrossTalkE"+name);
01167 if (!baselineNoiseSpectrumCrossTalkE[delta])
01168 cout << TString("baselineNoiseSpectrumCrossTalkE"+name) << endl;
01169 baselineNoiseSpectrumCrossTalkP[delta] = (TH1D*)output->Get("baselineNoiseSpectrumCrossTalkP"+name);
01170 if (!baselineNoiseSpectrumCrossTalkP[delta])
01171 cout << TString("baselineNoiseSpectrumCrossTalkP"+name) << endl;
01172 }
01173 }
01174 else {
01175 Ch1_Pb = new TH2F("Ch1_Pb","good PID Ch1_Pb",2000,0,4000,2000,0,4000);
01176 Ch1_Pb->SetXTitle("Cherenkov 1 [a.u.]");
01177 Ch1_Pb->SetYTitle("Pb-glass calorimeter [a.u.]");
01178 Ch1_Pb->SetContour(99);
01179
01180 noCh1_Pb = new TH2F("noCh1_Pb","no good PID Ch1_Pb",2000,0,4000,2000,0,4000);
01181 noCh1_Pb->SetXTitle("Cherenkov 1 [a.u.]");
01182 noCh1_Pb->SetYTitle("Pb-glass calorimeter [a.u.]");
01183 noCh1_Pb->SetContour(99);
01184
01185 Ch2_Pb = new TH2F("Ch2_Pb","good PID Ch2_Pb",2000,0,4000,2000,0,4000);
01186 Ch2_Pb->SetXTitle("Cherenkov 2 [a.u.]");
01187 Ch2_Pb->SetYTitle("Pb-glass calorimeter [a.u.]");
01188 Ch2_Pb->SetContour(99);
01189
01190 noCh2_Pb = new TH2F("noCh2_Pb","no good PID Ch2_Pb",2000,0,4000,2000,0,4000);
01191 noCh2_Pb->SetXTitle("Cherenkov 2 [a.u.]");
01192 noCh2_Pb->SetYTitle("Pb-glass calorimeter [a.u.]");
01193 noCh2_Pb->SetContour(99);
01194
01195 Ch1_Ch2 = new TH2F("Ch1_Ch2","good PID Ch1_Ch2",2000,0,4000,2000,0,4000);
01196 Ch1_Ch2->SetXTitle("Cherenkov 1 [a.u.]");
01197 Ch1_Ch2->SetYTitle("Cherenkov 2 [a.u.]");
01198 Ch1_Ch2->SetContour(99);
01199
01200 noCh1_Ch2 = new TH2F("noCh1_Ch2","no good PID Ch1_Ch2",2000,0,4000,2000,0,4000);
01201 noCh1_Ch2->SetXTitle("Cherenkov 1 [a.u.]");
01202 noCh1_Ch2->SetYTitle("Cherenkov 2 [a.u.]");
01203 noCh1_Ch2->SetContour(99);
01204
01205
01206 prf = new TH2D("PRF_2D", "PRF_2D", 30 * padWidth[suid], -1.5 * padWidth[suid] , 1.5 * padWidth[suid], 100, 0, 1);
01207 prf->SetYTitle("relative pad charge");
01208 prf->SetXTitle("reco. hit position [mm]");
01209 prf->SetContour(99);
01210 prfProfile = new TProfile("PRF", "PRF", 6 * padWidth[suid], -1.5 * padWidth[suid], 1.5 * padWidth[suid]);
01211 prfProfile->SetMarkerStyle(24);
01212 prfProfile->SetMarkerColor(1);
01213 prfProfile->SetLineColor(1);
01214 prfProfile->SetYTitle("relative pad charge");
01215 prfProfile->SetXTitle("reco. hit position [mm]");
01216
01217 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01218 name.Form("Ch%02i",ch);
01219 preCompPulse[ch] = new TH1D("preCompPulse"+name,"preCompPulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01220 preCompPulse[ch]->SetLineColor(color[ch]);
01221 preCompPulse[ch]->SetXTitle("time bin []");
01222 preCompPulse[ch]->SetYTitle("ADC value");
01223 preCompBaselinePulse[ch] = new TH1D("preCompBaselinePulse"+name,"preCompBaselinePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01224 preCompBaselinePulse[ch]->SetLineColor(color[ch]);
01225 preCompBaselinePulse[ch]->SetXTitle("time bin []");
01226 preCompBaselinePulse[ch]->SetYTitle("ADC value");
01227 rawPulse[ch] = new TH1D("rawPulse"+name,"rawPulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01228 rawPulse[ch]->SetLineColor(color[ch]);
01229 rawPulse[ch]->SetXTitle("time bin []");
01230 rawPulse[ch]->SetYTitle("ADC value");
01231 baselinePulse[ch] = new TH1D("baselinePulse"+name,"baselinePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01232 baselinePulse[ch]->SetLineColor(color[ch]);
01233 baselinePulse[ch]->SetXTitle("time bin []");
01234 baselinePulse[ch]->SetYTitle("ADC value");
01235 noisePulse[ch] = new TH1D("noisePulse"+name,"noisePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01236 noisePulse[ch]->SetLineColor(color[ch]);
01237 noisePulse[ch]->SetXTitle("time bin []");
01238 noisePulse[ch]->SetYTitle("ADC value");
01239 baselineNoisePulse[ch] = new TH1D("baselineNoisePulse"+name,"baselineNoisePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01240 baselineNoisePulse[ch]->SetLineColor(color[ch]);
01241 baselineNoisePulse[ch]->SetXTitle("time bin []");
01242 baselineNoisePulse[ch]->SetYTitle("ADC value");
01243 noiseBaselinePulse[ch] = new TH1D("noiseBaselinePulse"+name,"noiseBaselinePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01244 noiseBaselinePulse[ch]->SetLineColor(color[ch]);
01245 noiseBaselinePulse[ch]->SetXTitle("time bin []");
01246 noiseBaselinePulse[ch]->SetYTitle("ADC value");
01247 offSpillPulse[ch] = new TH2I("offSpillPulse"+name,"offSpillPulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE,256,0,256);
01248 offSpillPulse[ch]->SetLineColor(color[ch]);
01249 name.Form("Ch%02i",ch);
01250 lastPulse[ch] = new TH1D("lastPulse"+name,"lastPulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01251 }
01252
01253 averagePulse_e = new TProfile("averagePulse_e","averagePulse_e",SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01254 averagePulse_e->SetLineColor(kRed);
01255 averagePulse_e->SetMarkerStyle(20);
01256 averagePulse_e->SetMarkerColor(kRed);
01257 averagePulse_e->SetXTitle("TimeBin");
01258 averagePulse_e->SetYTitle("ADC value");
01259
01260 averagePulse_p = new TProfile("averagePulse_p","averagePulse_p",SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
01261 averagePulse_p->SetLineColor(kBlue);
01262 averagePulse_p->SetMarkerStyle(22);
01263 averagePulse_p->SetMarkerColor(kBlue);
01264 averagePulse_p->SetXTitle("TimeBin");
01265 averagePulse_p->SetYTitle("ADC value");
01266
01267 preCompSpectrum = new TH1D("preCompSpectrum","preCompSpectrum",nbins,lbin,hbin);
01268 preCompSpectrum->SetLineColor(2);
01269 preCompSpectrum->SetXTitle("dE/dx [keV]");
01270 preCompSpectrum->SetYTitle("normalized counts");
01271 preCompBaselineSpectrum = new TH1D("preCompBaselineSpectrum","preCompBaselineSpectrum",nbins,lbin,hbin);
01272 preCompBaselineSpectrum->SetLineColor(7);
01273 preCompBaselineSpectrum->SetXTitle("dE/dx [keV]");
01274 preCompBaselineSpectrum->SetYTitle("normalized counts");
01275 preCompSpectrumElectron = new TH1D("preCompSpectrumElectron","preCompSpectrumElectron",nbins,lbin,hbin);
01276 preCompSpectrumElectron->SetLineColor(2);
01277 preCompSpectrumElectron->SetXTitle("dE/dx [keV]");
01278 preCompSpectrumElectron->SetYTitle("normalized counts");
01279 preCompBaselineSpectrumElectron = new TH1D("preCompBaselineSpectrumElectron","preCompBaselineSpectrumElectron",nbins,lbin,hbin);
01280 preCompBaselineSpectrumElectron->SetLineColor(3);
01281 preCompBaselineSpectrumElectron->SetXTitle("dE/dx [keV]");
01282 preCompBaselineSpectrumElectron->SetYTitle("normalized counts");
01283 rawSpectrum = new TH1D("rawSpectrum","rawSpectrum",nbins,lbin,hbin);
01284 rawSpectrum->SetLineColor(1);
01285 rawSpectrum->SetXTitle("dE/dx [keV]");
01286 rawSpectrum->SetYTitle("normalized counts");
01287 baselineSpectrum = new TH1D("baselineSpectrum","baselineSpectrum",nbins,lbin,hbin);
01288 baselineSpectrum->SetLineColor(2);
01289 baselineSpectrum->SetXTitle("dE/dx [keV]");
01290 baselineSpectrum->SetYTitle("normalized counts");
01291 noiseSpectrum = new TH1D("noiseSpectrum","noiseSpectrum",nbins,lbin,hbin);
01292 noiseSpectrum->SetLineColor(3);
01293 noiseSpectrum->SetXTitle("dE/dx [keV]");
01294 noiseSpectrum->SetYTitle("normalized counts");
01295 baselineNoiseSpectrum = new TH1D("baselineNoiseSpectrum","baselineNoiseSpectrum",nbins,lbin,hbin);
01296 baselineNoiseSpectrum->SetLineColor(4);
01297 baselineNoiseSpectrum->SetXTitle("dE/dx [keV]");
01298 baselineNoiseSpectrum->SetYTitle("normalized counts");
01299 baselineNoiseSpectrumWoOWoU = new TH1D("baselineNoiseSpectrumWoOWoU","baselineNoiseSpectrumWoOWoU",nbins,lbin,hbin);
01300 baselineNoiseSpectrumWoOWoU->SetLineColor(6);
01301 baselineNoiseSpectrumWoOWoU->SetXTitle("dE/dx [keV]");
01302 baselineNoiseSpectrumWoOWoU->SetYTitle("normalized counts");
01303 baselineNoiseSpectrumElectron = new TH1D("baselineNoiseSpectrumElectron","baselineNoiseSpectrumElectron",nbins,lbin,hbin);
01304 baselineNoiseSpectrumElectron->SetLineColor(4);
01305 baselineNoiseSpectrumElectron->SetXTitle("dE/dx [keV]");
01306 baselineNoiseSpectrumElectron->SetYTitle("normalized counts");
01307 baselineNoiseSpectrumWoOWoUElectron = new TH1D("baselineNoiseSpectrumWoOWoUElectron","baselineNoiseSpectrumWoOWoUElectron",nbins,lbin,hbin);
01308 baselineNoiseSpectrumWoOWoUElectron->SetLineColor(6);
01309 baselineNoiseSpectrumWoOWoUElectron->SetLineStyle(1);
01310 baselineNoiseSpectrumWoOWoUElectron->SetXTitle("dE/dx [keV]");
01311 baselineNoiseSpectrumWoOWoUElectron->SetYTitle("normalized counts");
01312 noiseBaselineSpectrum = new TH1D("noiseBaselineSpectrum","noiseBaselineSpectrum",nbins,lbin,hbin);
01313 noiseBaselineSpectrum->SetLineColor(800);
01314 noiseBaselineSpectrum->SetXTitle("dE/dx [keV]");
01315 noiseBaselineSpectrum->SetYTitle("normalized counts");
01316 probabilityOverflow = new TH1D("probabilityOverflow","probabilityOverflow",nbins,lbin,hbin);
01317 probabilityOverflow->SetLineColor(800);
01318 probabilityOverflow->SetFillColor(800);
01319 probabilityOverflow->SetFillStyle(3002);
01320 probabilityUnderflow = new TH1D("probabilityUnderflow","probabilityUnderflow",nbins,lbin,hbin);
01321 probabilityUnderflow->SetLineColor(8);
01322 probabilityUnderflow->SetFillColor(8);
01323 probabilityUnderflow->SetFillStyle(3005);
01324 probabilityOverflowE = new TH1D("probabilityOverflowE","probabilityOverflowE",nbins,lbin,hbin);
01325 probabilityOverflowE->SetLineColor(800);
01326 probabilityOverflowE->SetFillColor(800);
01327 probabilityOverflowE->SetFillStyle(3002);
01328 probabilityUnderflowE = new TH1D("probabilityUnderflowE","probabilityUnderflowE",nbins,lbin,hbin);
01329 probabilityUnderflowE->SetLineColor(8);
01330 probabilityUnderflowE->SetFillColor(8);
01331 probabilityUnderflowE->SetFillStyle(3005);
01332
01333 crossTalk = new TProfile("CrossTalk","CrossTalk",6,-0.5,5.5);
01334
01335 for(Int_t delta = 0; delta < 6; delta++) {
01336 name.Form("_delta%02i",delta);
01337 baselineNoiseSpectrumCrossTalkE[delta] = new TH1D("baselineNoiseSpectrumCrossTalkE"+name,"baselineNoiseSpectrumCrossTalkE"+name,nbins,lbin,hbin);
01338 baselineNoiseSpectrumCrossTalkE[delta]->SetLineColor(12+delta);
01339 baselineNoiseSpectrumCrossTalkE[delta]->SetXTitle("dE/dx [keV]");
01340 baselineNoiseSpectrumCrossTalkE[delta]->SetYTitle("normalized counts");
01341 baselineNoiseSpectrumCrossTalkP[delta] = new TH1D("baselineNoiseSpectrumCrossTalkP"+name,"baselineNoiseSpectrumCrossTalkP"+name,nbins,lbin,hbin);
01342 baselineNoiseSpectrumCrossTalkP[delta]->SetLineColor(12+delta);
01343 baselineNoiseSpectrumCrossTalkP[delta]->SetLineStyle(2);
01344 baselineNoiseSpectrumCrossTalkP[delta]->SetXTitle("dE/dx [keV]");
01345 baselineNoiseSpectrumCrossTalkP[delta]->SetYTitle("normalized counts");
01346 }
01347 }
01348
01349
01350
01351 TString formula;
01352
01353 formula.Form(" -1. / (2. * atan(sqrt(%f))) * (atan(sqrt(%f) *tanh(3.14159265 * (-2. + sqrt(%f) ) * (%f + 2.* x * %f) / (8.* %f) )) + atan(sqrt(%f) * tanh(3.14159265 * (-2. + sqrt(%f) ) * (%f - 2.* x * %f) / (8.* %f) )) )",K3,K3,K3,padWidth[suid],par,h[suid],K3,K3,padWidth[suid],par,h[suid]);
01354 TF1 *mathieson = new TF1("mathieson", formula, -1.5 * padWidth[suid], 1.5 * padWidth[suid]);
01355 formula.Form(" -1. / (2. * atan(sqrt([0]))) * (atan(sqrt([0]) *tanh(3.14159265 * (-2. + sqrt([0]) ) * (%f + 2.* x * %f) / (8.* %f) )) + atan(sqrt([0]) * tanh(3.14159265 * (-2. + sqrt([0]) ) * (%f - 2.* x * %f) / (8.* %f) )) )",padWidth[suid],par,h[suid],padWidth[suid],par,h[suid]);
01356 TF1 *mathiesonFit = new TF1("mathiesonFit", formula, -1.5 * padWidth[suid], 1.5 * padWidth[suid]);
01357 mathiesonFit->SetLineColor(1);
01358 mathiesonFit->SetLineStyle(2);
01359 mathiesonFit->SetLineWidth(1);
01360 mathieson->SetLineColor(1);
01361 mathieson->SetLineStyle(1);
01362 mathieson->SetLineWidth(1);
01363
01364
01365
01366
01367 Int_t nPions = 0;
01368 Int_t nElectrons = 0;
01369 TCanvas *c;
01370 if (!plotFromFile) {
01371 name = filename;
01372
01373 GetPidCuts(name.ReplaceAll("data2011/TTrees/",""));
01374
01375 TFile inputFile(filename,"READ");
01376 TTree* theTree=NULL;
01377 TKey* kee=NULL;
01378 TIter iter(inputFile.GetListOfKeys());
01379 while ( ( kee=dynamic_cast<TKey*>(iter()) ) !=0 ) {
01380 theTree = dynamic_cast<TTree*>(kee->ReadObj());
01381 if (theTree)
01382 break;
01383 }
01384 if(theTree==0) {
01385 cout <<"Error: no Tree in file "<< filename.Data() << endl;
01386 return;
01387 }
01388 TCernOct11UnpackEvent* evnt = new TCernOct11UnpackEvent;
01389 TGo4EventElement* theBase=evnt;
01390 evnt->synchronizeWithTree(theTree, &theBase);
01391 Int_t entries = theTree->GetEntries();
01392 printf("%i Events found in TTree\n",entries);
01393 TMbsCrateEvent* fCrateInputEvent;
01394 TSpadicEvent* SpadicInputEvent;
01395 TSpadicData* theSpadic;
01396 Float_t Ch1(0), Ch2(0), Pb(0);
01397
01398 if (debug) {
01399 c = new TCanvas("c","c",1750,700);
01400 c->Divide(7,2);
01401 }
01402 TCanvas *cDebug;
01403 if (debug) {
01404 cDebug = new TCanvas("cDebug","cDebug",800,600);
01405 cDebug->Divide(2,1);
01406 }
01407
01408
01409
01410
01411 if (debug) entries = 200;
01412
01413 for(Int_t i=0;i<entries;++i) {
01414 Statusbar(i,entries);
01415 theTree->GetEntry(i);
01416 fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(evnt->GetSubEvent("MBSCRATE"));
01417 SpadicInputEvent=dynamic_cast<TSpadicEvent*>(evnt->GetSubEvent("SPADIC"));
01418 isPion = false;
01419 isElectron = false;
01420 isOverFlowEvent = false;
01421 isUnderFlowEvent = false;
01422 Ch1 = fCrateInputEvent->fData1182[1][0];
01423 Ch2 = fCrateInputEvent->fData1182[0][1];
01424 Pb = fCrateInputEvent->fData1182[1][5];
01425 getPID(Ch1, Ch2, Pb);
01426
01427 if (isPion || isElectron) {
01428 Ch1_Pb->Fill(Ch1,Pb);
01429 Ch2_Pb->Fill(Ch2,Pb);
01430 }
01431 if (!isPion && !isElectron) {
01432 noCh1_Pb->Fill(Ch1,Pb);
01433 noCh2_Pb->Fill(Ch2,Pb);
01434 }
01435
01436
01437 theSpadic=dynamic_cast<TSpadicData*>(SpadicInputEvent->getEventElement(usedSuId[suid]));
01438 if (isPion || isElectron) {
01439 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01440 rawPulse[ch]->Reset();
01441 rawPulse[ch]->GetYaxis()->SetRangeUser(-50,256);
01442 baselinePulse[ch]->Reset();
01443 baselinePulse[ch]->GetYaxis()->SetRangeUser(-50,256);
01444 noisePulse[ch]->Reset();
01445 noisePulse[ch]->GetYaxis()->SetRangeUser(-50,256);
01446 baselineNoisePulse[ch]->Reset();
01447 baselineNoisePulse[ch]->GetYaxis()->SetRangeUser(-50,256);
01448 noiseBaselinePulse[ch]->Reset();
01449 noiseBaselinePulse[ch]->GetYaxis()->SetRangeUser(-50,256);
01450 preCompPulse[ch]->Reset();
01451 preCompPulse[ch]->GetYaxis()->SetRangeUser(-50,256);
01452 preCompBaselinePulse[ch]->Reset();
01453 preCompBaselinePulse[ch]->GetYaxis()->SetRangeUser(-50,256);
01454 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
01455 rawPulse[ch]->Fill(bin, (Double_t)theSpadic->fSpadicPulse[ch][bin]);
01456 preCompPulse[ch]->Fill(bin, (Double_t)theSpadic->fSpadicCompensated[ch][bin]);
01457 if ((Int_t)theSpadic->fSpadicPulse[ch][bin] == 0 && bin < SPADIC_TRACE_SIZE-1)
01458 isUnderFlowEvent = true;
01459
01460 if ((Int_t)theSpadic->fSpadicPulse[ch][bin] == 255)
01461 isOverFlowEvent = true;
01462
01463 }
01464 }
01465 BaselineCompensation(preCompPulse, preCompBaselinePulse);
01466 BaselineCompensation(rawPulse, baselinePulse);
01467 CancelNoise_Cova(rawPulse, noisePulse, false);
01468 CancelNoise_Cova(baselinePulse, baselineNoisePulse, false);
01469 BaselineCompensation(noisePulse, noiseBaselinePulse);
01470
01471 if(minimumAmplitudeThreshold(baselineNoisePulse) && !BorderPadMax(baselineNoisePulse) && HitTimeWindow(baselineNoisePulse) && minimumIntegralThreshold(baselineNoisePulse))
01472 CalcPrf(baselineNoisePulse, prf, prfProfile, padWidth[suid]);
01473
01474 Int_t deltaChMax = -1;
01475 Double_t temp = Get3PadPosIntegralCrossTalk(baselineNoisePulse, lastPulse, &deltaChMax);
01476
01477 if (isElectron) {
01478 nElectrons++;
01479 if(amplitude){
01480 if(minimumAmplitudeThreshold(preCompPulse) && !BorderPadMax(preCompPulse) && HitTimeWindow(preCompPulse) && minimumIntegralThreshold(preCompPulse))
01481 preCompSpectrumElectron->Fill(Get3PadPosAmplitude(preCompPulse)*scaling2keV);
01482 if(minimumAmplitudeThreshold(preCompBaselinePulse) && !BorderPadMax(preCompBaselinePulse) && HitTimeWindow(preCompBaselinePulse) && minimumIntegralThreshold(preCompBaselinePulse))
01483 preCompBaselineSpectrumElectron->Fill(Get3PadPosAmplitude(preCompBaselinePulse)*scaling2keV);
01484 if(minimumAmplitudeThreshold(baselineNoisePulse) && !BorderPadMax(baselineNoisePulse) && HitTimeWindow(baselineNoisePulse) && minimumIntegralThreshold(baselineNoisePulse)){
01485 baselineNoiseSpectrumElectron->Fill(Get3PadPosAmplitude(baselineNoisePulse)*scaling2keV);
01486 if (isOverFlowEvent)
01487 probabilityOverflowE->Fill(Get3PadPosAmplitude(baselineNoisePulse));
01488 if(isUnderFlowEvent)
01489 probabilityUnderflowE->Fill(Get3PadPosAmplitude(baselineNoisePulse));
01490 }
01491 }
01492 else{
01493 if(minimumAmplitudeThreshold(preCompPulse) && !BorderPadMax(preCompPulse) && HitTimeWindow(preCompPulse) && minimumIntegralThreshold(preCompPulse))
01494 preCompSpectrumElectron->Fill(Get3PadPosIntegral(preCompPulse)*scaling2keV);
01495 if(minimumAmplitudeThreshold(preCompBaselinePulse) && !BorderPadMax(preCompBaselinePulse) && HitTimeWindow(preCompBaselinePulse) && minimumIntegralThreshold(preCompBaselinePulse))
01496 preCompBaselineSpectrumElectron->Fill(Get3PadPosIntegral(preCompBaselinePulse)*scaling2keV);
01497 if(minimumAmplitudeThreshold(baselineNoisePulse) && !BorderPadMax(baselineNoisePulse) && HitTimeWindow(baselineNoisePulse) && minimumIntegralThreshold(baselineNoisePulse)){
01498 baselineNoiseSpectrumElectron->Fill(Get3PadPosIntegral(baselineNoisePulse)*scaling2keV);
01499 FillAverageSignal(baselineNoisePulse, averagePulse_e);
01500 if (deltaChMax >= 0 && deltaChMax < 6){
01501 if(minimumAmplitudeThreshold(lastPulse) && !BorderPadMax(lastPulse) && HitTimeWindow(lastPulse) && minimumIntegralThreshold(lastPulse)){
01502 baselineNoiseSpectrumCrossTalkE[deltaChMax]->Fill(temp*scaling2keV);
01503
01504 }
01505 }
01506 if (isOverFlowEvent)
01507 probabilityOverflowE->Fill(Get3PadPosIntegral(baselineNoisePulse)*scaling2keV);
01508 if(isUnderFlowEvent)
01509 probabilityUnderflowE->Fill(Get3PadPosIntegral(baselineNoisePulse)*scaling2keV);
01510 if (!isOverFlowEvent && !isUnderFlowEvent){
01511 if(amplitude){
01512 baselineNoiseSpectrumWoOWoUElectron->Fill(Get3PadPosAmplitude(baselineNoisePulse));
01513 }
01514 else{
01515 baselineNoiseSpectrumWoOWoUElectron->Fill(Get3PadPosIntegral(baselineNoisePulse)*scaling2keV);
01516 }
01517 }
01518 }
01519 }
01520 }
01521 if (isPion){
01522 nPions++;
01523 if(minimumAmplitudeThreshold(rawPulse) && !BorderPadMax(rawPulse) && HitTimeWindow(rawPulse) && minimumIntegralThreshold(rawPulse)){
01524 if(amplitude)
01525 rawSpectrum->Fill(Get3PadPosAmplitude(rawPulse));
01526 else
01527 rawSpectrum->Fill(Get3PadPosIntegral(rawPulse)*scaling2keV);
01528 }
01529 if(amplitude){
01530 if(minimumAmplitudeThreshold(baselinePulse) && !BorderPadMax(baselinePulse) && HitTimeWindow(baselinePulse) && minimumIntegralThreshold(baselinePulse))
01531 baselineSpectrum->Fill(Get3PadPosAmplitude(baselinePulse)*scaling2keV);
01532 if(minimumAmplitudeThreshold(noiseBaselinePulse) && !BorderPadMax(noiseBaselinePulse) && HitTimeWindow(noiseBaselinePulse) && minimumIntegralThreshold(noiseBaselinePulse))
01533 noiseBaselineSpectrum->Fill(Get3PadPosAmplitude(noiseBaselinePulse)*scaling2keV);
01534 if(minimumAmplitudeThreshold(noisePulse) && !BorderPadMax(noisePulse) && HitTimeWindow(noisePulse) && minimumIntegralThreshold(noisePulse))
01535 noiseSpectrum->Fill(Get3PadPosAmplitude(noisePulse)*scaling2keV);
01536 if(minimumAmplitudeThreshold(preCompPulse) && !BorderPadMax(preCompPulse) && HitTimeWindow(preCompPulse) && minimumIntegralThreshold(preCompPulse))
01537 preCompSpectrum->Fill(Get3PadPosAmplitude(preCompPulse)*scaling2keV);
01538 if(minimumAmplitudeThreshold(preCompBaselinePulse) && !BorderPadMax(preCompBaselinePulse) && HitTimeWindow(preCompBaselinePulse) && minimumIntegralThreshold(preCompBaselinePulse))
01539 preCompBaselineSpectrum->Fill(Get3PadPosAmplitude(preCompBaselinePulse)*scaling2keV);
01540 if(minimumAmplitudeThreshold(baselineNoisePulse) && !BorderPadMax(baselineNoisePulse) && HitTimeWindow(baselineNoisePulse) && minimumIntegralThreshold(baselineNoisePulse)){
01541 baselineNoiseSpectrum->Fill(Get3PadPosAmplitude(baselineNoisePulse)*scaling2keV);
01542 if (!isOverFlowEvent && !isUnderFlowEvent)
01543 baselineNoiseSpectrumWoOWoU->Fill(Get3PadPosAmplitude(baselineNoisePulse));
01544 if (isOverFlowEvent)
01545 probabilityOverflow->Fill(Get3PadPosAmplitude(baselineNoisePulse));
01546 if(isUnderFlowEvent)
01547 probabilityUnderflow->Fill(Get3PadPosAmplitude(baselineNoisePulse));
01548 }
01549 }
01550 else{
01551 if(minimumAmplitudeThreshold(baselinePulse) && !BorderPadMax(baselinePulse) && HitTimeWindow(baselinePulse) && minimumIntegralThreshold(baselinePulse))
01552 baselineSpectrum->Fill(Get3PadPosIntegral(baselinePulse)*scaling2keV);
01553 if(minimumAmplitudeThreshold(noisePulse) && !BorderPadMax(noisePulse) && HitTimeWindow(noisePulse) && minimumIntegralThreshold(noisePulse))
01554 noiseSpectrum->Fill(Get3PadPosIntegral(noisePulse)*scaling2keV);
01555 if(minimumAmplitudeThreshold(noiseBaselinePulse) && !BorderPadMax(noiseBaselinePulse) && HitTimeWindow(noiseBaselinePulse) && minimumIntegralThreshold(noiseBaselinePulse))
01556 noiseBaselineSpectrum->Fill(Get3PadPosIntegral(noiseBaselinePulse)*scaling2keV);
01557 if(minimumAmplitudeThreshold(preCompPulse) && !BorderPadMax(preCompPulse) && HitTimeWindow(preCompPulse) && minimumIntegralThreshold(preCompPulse))
01558 preCompSpectrum->Fill(Get3PadPosIntegral(preCompPulse)*scaling2keV);
01559 if(minimumAmplitudeThreshold(preCompBaselinePulse) && !BorderPadMax(preCompBaselinePulse) && HitTimeWindow(preCompBaselinePulse) && minimumIntegralThreshold(preCompBaselinePulse))
01560 preCompBaselineSpectrum->Fill(Get3PadPosIntegral(preCompBaselinePulse)*scaling2keV);
01561 if(minimumAmplitudeThreshold(baselineNoisePulse) && !BorderPadMax(baselineNoisePulse) && HitTimeWindow(baselineNoisePulse) && minimumIntegralThreshold(baselineNoisePulse)){
01562 baselineNoiseSpectrum->Fill(Get3PadPosIntegral(baselineNoisePulse)*scaling2keV);
01563 FillAverageSignal(baselineNoisePulse, averagePulse_p);
01564 if (deltaChMax >= 0 && deltaChMax < 6){
01565 if(minimumAmplitudeThreshold(lastPulse) && !BorderPadMax(lastPulse) && HitTimeWindow(lastPulse) && minimumIntegralThreshold(lastPulse)){
01566 baselineNoiseSpectrumCrossTalkP[deltaChMax]->Fill(temp*scaling2keV);
01567 crossTalk->Fill(deltaChMax,(temp*scaling2keV - Get3PadPosIntegral(baselineNoisePulse)*scaling2keV) / (temp*scaling2keV) * 100);
01568 }
01569 }
01570 if (!isOverFlowEvent && !isUnderFlowEvent)
01571 baselineNoiseSpectrumWoOWoU->Fill(Get3PadPosIntegral(baselineNoisePulse)*scaling2keV);
01572 if (isOverFlowEvent)
01573 probabilityOverflow->Fill(Get3PadPosIntegral(baselineNoisePulse)*scaling2keV);
01574 if(isUnderFlowEvent)
01575 probabilityUnderflow->Fill(Get3PadPosIntegral(baselineNoisePulse)*scaling2keV);
01576 }
01577
01578 }
01579 }
01580 if (debug) {
01581 if (i%100000 == 0) {
01582 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01583 c->cd(1);
01584 if(ch==0)
01585 rawPulse[ch]->DrawCopy();
01586 else
01587 rawPulse[ch]->DrawCopy("same");
01588 c->cd(2);
01589 if(ch==0)
01590 baselinePulse[ch]->DrawCopy();
01591 else
01592 baselinePulse[ch]->DrawCopy("same");
01593 c->cd(3);
01594 if(ch==0)
01595 baselineNoisePulse[ch]->DrawCopy();
01596 else
01597 baselineNoisePulse[ch]->DrawCopy("same");
01598 c->cd(4);
01599 if(ch==0)
01600 noisePulse[ch]->DrawCopy();
01601 else
01602 noisePulse[ch]->DrawCopy("same");
01603 c->cd(5);
01604 if(ch==0)
01605 noiseBaselinePulse[ch]->DrawCopy();
01606 else
01607 noiseBaselinePulse[ch]->DrawCopy("same");
01608 c->cd(6);
01609 if(ch==0)
01610 preCompPulse[ch]->DrawCopy();
01611 else
01612 preCompPulse[ch]->DrawCopy("same");
01613 c->cd(7);
01614 if(ch==0)
01615 preCompBaselinePulse[ch]->DrawCopy();
01616 else
01617 preCompBaselinePulse[ch]->DrawCopy("same");
01618
01619 rawPulse[ch]->Reset();
01620 baselinePulse[ch]->Reset();
01621 baselineNoisePulse[ch]->Reset();
01622 }
01623 }
01624 c->cd(8)->SetLogy(1);
01625 rawSpectrum->DrawCopy();
01626 c->cd(9)->SetLogy(1);
01627 baselineSpectrum->DrawCopy();
01628 c->cd(10)->SetLogy(1);
01629 baselineNoiseSpectrum->DrawCopy();
01630 c->cd(11)->SetLogy(1);
01631 noiseSpectrum->DrawCopy();
01632 c->cd(12)->SetLogy(1);
01633 noiseBaselineSpectrum->DrawCopy();
01634 c->cd(13)->SetLogy(1);
01635 preCompSpectrum->DrawCopy();
01636 c->cd(14)->SetLogy(1);
01637 preCompBaselineSpectrum->DrawCopy();
01638 c->Update();
01639 cDebug->cd(1);
01640 clusterSize->DrawCopy();
01641 cDebug->cd(2);
01642 signalChDistance->DrawCopy();
01643 cDebug->Update();
01644 cDebug->SaveAs("pics/Debug.pdf");
01645 }
01646
01647 if(minimumAmplitudeThreshold(baselineNoisePulse) && !BorderPadMax(baselineNoisePulse) && HitTimeWindow(baselineNoisePulse) && minimumIntegralThreshold(baselineNoisePulse)){
01648 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
01649 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
01650 lastPulse[ch]->SetBinContent(lastPulse[ch]->FindBin(bin),baselineNoisePulse[ch]->GetBinContent(baselineNoisePulse[ch]->FindBin(bin)));
01651 }
01652 }
01653 }
01654 }
01655 }
01656 }
01657
01658 TFile *sim = new TFile("root/Sim_xeco20_12mm_03GeV.root","READ");
01659 TH1D* simSpectrum = (TH1D*)sim->Get("hPi");
01660
01661 simSpectrum->SetXTitle("dE/dx [keV]");
01662 simSpectrum->SetYTitle("normalized counts");
01663 simSpectrum->SetStats(false);
01664 simSpectrum->SetLineStyle(1);
01665 simSpectrum->SetLineColor(1);
01666 simSpectrum->Scale(1./(Float_t)simSpectrum->GetEntries());
01667 simSpectrum->GetXaxis()->SetRangeUser(-0.5,70);
01668 if (debug) {
01669 c->SaveAs("pics/Spectra_overview.pdf");
01670 c->Clear();
01671 c->cd(1)->SetLogy(1);
01672 rawSpectrum->GetYaxis()->SetRangeUser(0.5,1e4);
01673 rawSpectrum->DrawCopy();
01674 c->cd(2)->SetLogy(1);
01675 baselineSpectrum->DrawCopy();
01676 c->cd(3)->SetLogy(1);
01677 baselineNoiseSpectrum->DrawCopy();
01678 c->cd(4)->SetLogy(1);
01679 noiseSpectrum->DrawCopy();
01680 c->cd(5)->SetLogy(1);
01681 noiseBaselineSpectrum->DrawCopy();
01682 c->cd(6)->SetLogy(1);
01683 }
01684 TCanvas *cResults = new TCanvas("cResults","cResults",1600,600);
01685
01686 TPad *pad1 = new TPad("pad1","top pad",0,0.35,0.5,1);
01687
01688 pad1->SetBottomMargin(0);
01689 pad1->Draw();
01690
01691 TPad *pad2 = new TPad("pad2","bottom pad",0,0,0.5,0.35);
01692 pad2->SetTopMargin(0);
01693 pad2->SetBottomMargin(0.2);
01694 pad2->Draw();
01695 TPad *pad3 = new TPad("pad3","top pad",0.5,0.35,1,1);
01696
01697 pad3->SetBottomMargin(0);
01698 pad3->Draw();
01699
01700 TPad *pad4 = new TPad("pad4","bottom pad",0.5,0,1,0.35);
01701 pad4->SetTopMargin(0);
01702 pad4->SetBottomMargin(0.2);
01703 pad4->Draw();
01704
01705 pad1->cd()->SetLogy(1);
01706 TLegend *leg = new TLegend(0.15,0.5,0.85,0.85);
01707 leg->SetNColumns(2);
01708 leg->SetFillStyle(0);
01709 leg->SetTextSize(0.035);
01710 leg->SetLineStyle(0);
01711 leg->SetLineColor(0);
01712 leg->SetHeader("#pi^{-} spectra, " + usedSuName[suid] + ", p=3GeV/c, 12mm XeCO_{2}");
01713 leg->AddEntry(simSpectrum,"simulated","l");
01714 leg->AddEntry((TObject*)0, "","");
01715 if (simple) {
01716 leg->AddEntry(baselineNoiseSpectrum,"measured: 1.baseline 2.noise","l");
01717 leg->AddEntry(baselineNoiseSpectrumWoOWoU,"measured: 1.baseline 2.noise(woO && woU)","l");
01718
01719
01720
01721
01722 leg->AddEntry(probabilityOverflow,"overflow probability","f");
01723 leg->AddEntry(probabilityUnderflow,"underflow probability","f");
01724 } else {
01725 leg->AddEntry(baselineNoiseSpectrum,"measured: FFM noise + baseline","l");
01726 leg->AddEntry(baselineNoiseSpectrumWoOWoU,"measured: FFM noise + baseline (woO && woU)","l");
01727 leg->AddEntry(preCompSpectrum,"measured: MS noise","l");
01728 leg->AddEntry(preCompBaselineSpectrum,"measured: MS noise + baseline","l");
01729
01730
01731 leg->AddEntry(probabilityOverflow,"overflow probability","f");
01732 leg->AddEntry(probabilityUnderflow,"underflow probability","f");
01733 }
01734
01735 simSpectrum->GetYaxis()->SetRangeUser(5e-6, 10);
01736 simSpectrum->GetXaxis()->SetLabelSize(0.04);
01737 simSpectrum->GetYaxis()->SetLabelSize(0.04);
01738 simSpectrum->GetXaxis()->SetTitleSize(0.045);
01739 simSpectrum->GetYaxis()->SetTitleSize(0.045);
01740 simSpectrum->GetYaxis()->SetTitleOffset(0.9);
01741 simSpectrum->GetXaxis()->SetTitleOffset(0.5);
01742
01743 simSpectrum->DrawCopy();
01744 if (!plotFromFile){
01745 probabilityOverflow->Scale(1./(Float_t)baselineNoiseSpectrum->GetEntries());
01746 probabilityUnderflow->Scale(1./(Float_t)baselineNoiseSpectrum->GetEntries());
01747 }
01748 probabilityUnderflow->DrawCopy("same");
01749 probabilityOverflow->DrawCopy("same");
01750
01751
01752 if (!plotFromFile)
01753 baselineNoiseSpectrum->Scale(1./(Float_t)baselineNoiseSpectrum->GetEntries());
01754 baselineNoiseSpectrum->DrawCopy("same");
01755 if (!plotFromFile)
01756 baselineNoiseSpectrumWoOWoU->Scale(1./(Float_t)baselineNoiseSpectrumWoOWoU->GetEntries());
01757 baselineNoiseSpectrumWoOWoU->DrawCopy("same");
01758
01759
01760
01761 if (!simple) {
01762 if (!plotFromFile)
01763 preCompSpectrum->Scale(1./(Float_t)preCompSpectrum->GetEntries());
01764 preCompSpectrum->DrawCopy("same");
01765 if (!plotFromFile)
01766 preCompBaselineSpectrum->Scale(1./(Float_t)preCompBaselineSpectrum->GetEntries());
01767 preCompBaselineSpectrum->DrawCopy("same");
01768 }
01769 simSpectrum->DrawCopy("same");
01770 leg->Draw("same");
01771
01772
01773
01774 TH1D *deltaSim = (TH1D*)baselineNoiseSpectrum->Clone("deltaSim");
01775 CalcDeltaSim(deltaSim, simSpectrum, baselineNoiseSpectrum);
01776 deltaSim->SetLineColor(4);
01777 deltaSim->SetLineStyle(1);
01778 deltaSim->SetMarkerStyle(20);
01779 deltaSim->SetMarkerColor(4);
01780
01781
01782
01783 TH1D *deltaSim2 = (TH1D*)baselineNoiseSpectrumWoOWoU->Clone("deltaSim2");
01784 CalcDeltaSim(deltaSim2, simSpectrum, baselineNoiseSpectrumWoOWoU);
01785 deltaSim2->SetLineColor(6);
01786 deltaSim2->SetLineStyle(1);
01787 deltaSim2->SetMarkerStyle(20);
01788 deltaSim2->SetMarkerColor(6);
01789
01790
01791
01792 if (!simple) {
01793 TH1D *deltaSimMS = (TH1D*)preCompSpectrum->Clone("deltaSimMS");
01794 CalcDeltaSim(deltaSimMS, simSpectrum, preCompSpectrum);
01795 deltaSimMS->SetLineColor(2);
01796 deltaSimMS->SetLineStyle(1);
01797 deltaSimMS->SetMarkerStyle(20);
01798 deltaSimMS->SetMarkerColor(2);
01799
01800
01801
01802 TH1D *deltaSimMS2 = (TH1D*)preCompBaselineSpectrum->Clone("deltaSimMS2");
01803 CalcDeltaSim(deltaSimMS2, simSpectrum, preCompBaselineSpectrum);
01804
01805 deltaSimMS2->SetLineColor(7);
01806 deltaSimMS2->SetLineStyle(1);
01807 deltaSimMS2->SetMarkerStyle(20);
01808 deltaSimMS2->SetMarkerColor(7);
01809 pad2->cd();
01810 deltaSimMS->GetYaxis()->SetRangeUser(0.1, 2.1);
01811 deltaSimMS->DrawCopy("same");
01812 deltaSimMS2->GetYaxis()->SetRangeUser(0.1, 2.1);
01813 deltaSimMS2->DrawCopy("same");
01814 }
01815
01816 pad2->cd();
01817 deltaSim->GetXaxis()->SetRangeUser(-0.5,70);
01818 deltaSim->GetYaxis()->SetRangeUser(0.1, 2.1);
01819 deltaSim->DrawCopy("");
01820 deltaSim2->GetYaxis()->SetRangeUser(0.1, 2.1);
01821 deltaSim2->DrawCopy("same");
01822
01823
01824
01825
01826
01827 pad3->cd()->SetLogy(1);
01828
01829 TFile dEdxFile("root/Sim_xeco20_12mm_03GeV.root","READ");
01830 TFile TR_simFile("root/Sim_xeco20_12mm_03GeV_TR.root","READ");
01831 TH1D *hElDedx = (TH1D*)dEdxFile.Get("hElDedx");
01832 TH1D *hElTr;
01833 TH1D *hElTrAbs;
01834 TString radiator2;
01835
01836 TH1D *spectrum;
01837 TH1D* spectrumAbs;
01838 Float_t attenuation = 1.0;
01839 if (radiator == "") {
01840 hElTrAbs = (TH1D*)dEdxFile.Get("hElDedx");
01841 }
01842 else {
01843 if (radiator == "B" || radiator == "C" || radiator == "D" || radiator == "E" || radiator == "F"){
01844 spectrumAbs = (TH1D*)TR_simFile.Get("Absorption_("+radiator+")");
01845 spectrum = (TH1D*)TR_simFile.Get("Production_("+radiator+")");
01846 if (radiator == "B")
01847 attenuation = 0.55;
01848 if (radiator == "C")
01849 attenuation = 0.30;
01850 if (radiator == "D")
01851 attenuation = 0.45;
01852 if (radiator == "E")
01853 attenuation = 0.60;
01854 if (radiator == "F")
01855 attenuation = 0.55;
01856 }
01857 else if (radiator == "A" || radiator == "G10" || radiator == "G20" || radiator == "G30" || radiator == "H" || radiator == "H++" || radiator == "Iu" || radiator == "Ip" || radiator == "J"){
01858 TString irradiator;
01859 if (radiator == "A"){
01860 irradiator = "C";
01861 attenuation = 0.35;
01862 }
01863 if (radiator == "G10"){
01864 irradiator = "C";
01865 attenuation = 0.35;
01866 }
01867 if (radiator == "G20"){
01868 irradiator = "C";
01869 attenuation = 0.50;
01870 }
01871 if (radiator == "G30"){
01872 irradiator = "C";
01873 attenuation = 0.65;
01874 }
01875 if (radiator == "H"){
01876 irradiator = "C";
01877 attenuation = 0.65;
01878 }
01879 if (radiator == "H++"){
01880 irradiator = "C";
01881 attenuation = 0.65;
01882 }
01883 if (radiator == "Ip"){
01884 irradiator = "C";
01885 attenuation = 0.60;
01886 }
01887 if (radiator == "Iu"){
01888 irradiator = "C";
01889 attenuation = 0.55;
01890 }
01891 if (radiator == "J"){
01892 irradiator = "C";
01893 attenuation = 0.20;
01894 }
01895 spectrumAbs = (TH1D*)TR_simFile.Get("Absorption_("+irradiator+")");
01896 spectrum = (TH1D*)TR_simFile.Get("Production_("+irradiator+")");
01897 }
01898 else {
01899 printf("ERROR::Main: no or wrong radiator type");
01900 return;
01901 }
01902
01903 hElTr = (TH1D*)hElDedx->Clone("hElTr_"+TString(spectrum->GetTitle()));
01904 hElTr->Reset();
01905 hElTrAbs = (TH1D*)hElDedx->Clone("hElTrAbs_"+TString(spectrumAbs->GetTitle()));
01906 hElTrAbs->Reset();
01907 TRandom *rEfficiency = new TRandom();
01908
01909
01910
01911 radiator2.Form("%s (%.1f%% attenuation)",radiator.Data(),attenuation*100);
01912 for (Int_t iElec = 0; iElec < 200000; iElec++) {
01913 Int_t nPhot = rEfficiency->Poisson(spectrum->Integral() * spectrum->GetBinWidth(1) * attenuation);
01914 Float_t dEdx = hElDedx->GetRandom();
01915 Float_t Tr = 0;
01916 for (Int_t iPhot = 0; iPhot < nPhot; iPhot++) {
01917 Tr += spectrum->GetRandom();
01918 }
01919 hElTr->Fill(dEdx+Tr);
01920 }
01921 for (Int_t iElec = 0; iElec < 200000; iElec++) {
01922 Int_t nPhot = rEfficiency->Poisson(spectrumAbs->Integral() * spectrumAbs->GetBinWidth(1) * attenuation);
01923 Float_t dEdx = hElDedx->GetRandom();
01924 Float_t Tr = 0;
01925 for (Int_t iPhot = 0; iPhot < nPhot; iPhot++) {
01926 Tr += spectrumAbs->GetRandom();
01927 }
01928 hElTrAbs->Fill(dEdx+Tr);
01929 }
01930 }
01931
01932
01933 TH1D* simSpectrumE = hElTrAbs;
01934 simSpectrumE->SetXTitle("dE/dx [keV]");
01935 simSpectrumE->SetYTitle("normalized counts");
01936 simSpectrumE->SetStats(false);
01937 simSpectrumE->SetLineStyle(1);
01938 simSpectrumE->SetLineColor(1);
01939 simSpectrumE->Scale(1./(Float_t)simSpectrumE->GetEntries());
01940 simSpectrumE->GetXaxis()->SetRangeUser(-0.5,70);
01941 TLegend *legE = new TLegend(0.15,0.5,0.85,0.85);
01942 legE->SetNColumns(2);
01943 legE->SetFillStyle(0);
01944 legE->SetTextSize(0.035);
01945 legE->SetLineStyle(0);
01946 legE->SetLineColor(0);
01947 legE->SetHeader("e^{-} spectra, " + usedSuName[suid] + ", p=3GeV/c, 12mm XeCO_{2}");
01948 legE->AddEntry(simSpectrumE,"simulated radiator: "+radiator2,"l");
01949 legE->AddEntry((TObject*)0, "","");
01950 if (simple) {
01951 legE->AddEntry(baselineNoiseSpectrumElectron,"measured: 1.baseline 2.noise","l");
01952 legE->AddEntry(baselineNoiseSpectrumWoOWoUElectron,"measured: 1.baseline 2.noise(woO && woU)","l");
01953
01954
01955
01956
01957 legE->AddEntry(probabilityOverflowE,"overflow probability","f");
01958 legE->AddEntry(probabilityUnderflowE,"underflow probability","f");
01959 } else {
01960 legE->AddEntry(baselineNoiseSpectrumElectron,"measured: baseline + FFM noise","l");
01961 legE->AddEntry(baselineNoiseSpectrumWoOWoUElectron,"measured: baseline + FFM noise (woO && woU)","l");
01962 legE->AddEntry(preCompSpectrumElectron,"measured: MS noise","l");
01963 legE->AddEntry(preCompBaselineSpectrumElectron,"measured: MS noise + baseline","l");
01964
01965
01966 legE->AddEntry(probabilityOverflowE,"overflow probability","f");
01967 legE->AddEntry(probabilityUnderflowE,"underflow probability","f");
01968 }
01969 simSpectrumE->GetYaxis()->SetRangeUser(5e-6, 10);
01970 simSpectrumE->GetXaxis()->SetLabelSize(0.04);
01971 simSpectrumE->GetYaxis()->SetLabelSize(0.04);
01972 simSpectrumE->GetXaxis()->SetTitleSize(0.045);
01973 simSpectrumE->GetYaxis()->SetTitleSize(0.045);
01974 simSpectrumE->GetYaxis()->SetTitleOffset(0.9);
01975 simSpectrumE->GetXaxis()->SetTitleOffset(0.5);
01976 simSpectrumE->DrawCopy();
01977 if (!plotFromFile){
01978 probabilityOverflowE->Scale(1./(Float_t)baselineNoiseSpectrumElectron->GetEntries());
01979 probabilityUnderflowE->Scale(1./(Float_t)baselineNoiseSpectrumElectron->GetEntries());
01980 }
01981 probabilityUnderflowE->DrawCopy("same");
01982 probabilityOverflowE->DrawCopy("same");
01983 if (!plotFromFile)
01984 baselineNoiseSpectrumElectron->Scale(1./(Float_t)baselineNoiseSpectrumElectron->GetEntries());
01985 baselineNoiseSpectrumElectron->DrawCopy("same");
01986 if (!plotFromFile)
01987 baselineNoiseSpectrumWoOWoUElectron->Scale(1./(Float_t)baselineNoiseSpectrumWoOWoUElectron->GetEntries());
01988 baselineNoiseSpectrumWoOWoUElectron->DrawCopy("same");
01989 if (!simple) {
01990 if (!plotFromFile)
01991 preCompSpectrumElectron->Scale(1./(Float_t)preCompBaselineSpectrumElectron->GetEntries());
01992 preCompSpectrumElectron->DrawCopy("same");
01993 if (!plotFromFile)
01994 preCompBaselineSpectrumElectron->Scale(1./(Float_t)preCompBaselineSpectrumElectron->GetEntries());
01995 preCompBaselineSpectrumElectron->DrawCopy("same");
01996 }
01997 simSpectrumE->DrawCopy("same");
01998 legE->Draw("same");
01999
02000
02001
02002
02003 TH1D *deltaSimE = (TH1D*)baselineNoiseSpectrumElectron->Clone("deltaSimE");
02004 CalcDeltaSim(deltaSimE, simSpectrumE, baselineNoiseSpectrumElectron);
02005 deltaSimE->SetLineColor(4);
02006 deltaSimE->SetLineStyle(1);
02007 deltaSimE->SetMarkerStyle(20);
02008 deltaSimE->SetMarkerColor(4);
02009
02010
02011
02012 TH1D *deltaSimE2 = (TH1D*)baselineNoiseSpectrumWoOWoUElectron->Clone("deltaSimE2");
02013 CalcDeltaSim(deltaSimE2, simSpectrumE, baselineNoiseSpectrumWoOWoUElectron);
02014 deltaSimE2->SetLineColor(6);
02015 deltaSimE2->SetLineStyle(1);
02016 deltaSimE2->SetMarkerStyle(20);
02017 deltaSimE2->SetMarkerColor(6);
02018
02019 if (!simple) {
02020
02021
02022 TH1D *deltaSimMSE = (TH1D*)preCompSpectrumElectron->Clone("deltaSimMSE");
02023 CalcDeltaSim(deltaSimMSE, simSpectrumE, preCompSpectrumElectron);
02024 deltaSimMSE->SetLineColor(2);
02025 deltaSimMSE->SetLineStyle(1);
02026 deltaSimMSE->SetMarkerStyle(20);
02027 deltaSimMSE->SetMarkerColor(2);
02028
02029
02030
02031 TH1D *deltaSimMSE2 = (TH1D*)preCompBaselineSpectrumElectron->Clone("deltaSimMSE2");
02032 CalcDeltaSim(deltaSimMSE2, simSpectrumE, preCompBaselineSpectrumElectron);
02033 deltaSimMSE2->SetLineColor(7);
02034 deltaSimMSE2->SetLineStyle(1);
02035 deltaSimMSE2->SetMarkerStyle(20);
02036 deltaSimMSE2->SetMarkerColor(7);
02037 pad4->cd();
02038 deltaSimMSE->GetYaxis()->SetRangeUser(0.1, 2.1);
02039 deltaSimMSE->DrawCopy("same");
02040 deltaSimMSE2->GetYaxis()->SetRangeUser(0.1, 2.1);
02041 deltaSimMSE2->DrawCopy("same");
02042 }
02043
02044 pad4->cd();
02045 deltaSimE->GetYaxis()->SetRangeUser(0.1, 2.1);
02046 deltaSimE->GetXaxis()->SetRangeUser(-0.5,70);
02047 deltaSimE->DrawCopy("");
02048 deltaSimE2->GetYaxis()->SetRangeUser(0.1, 2.1);
02049 deltaSimE2->DrawCopy("same");
02050
02051 TLine *l2 = new TLine(0,1,70,1);
02052 l2->SetLineStyle(2);
02053 pad4->cd();
02054 l2->Draw("same");
02055 pad2->cd();
02056 l2->Draw("same");
02057
02058
02059
02060
02061 cResults->SaveAs(outpic+".pdf");
02062 cResults->SaveAs(outpic+".png");
02063
02064 TCanvas *cPRF = new TCanvas("cPRF","cPRF",800,600);
02065 TLegend* lPRF = new TLegend(0.65,0.65,0.85,0.85);
02066 lPRF->SetFillStyle(0);
02067 lPRF->SetTextSize(0.025);
02068 lPRF->SetLineStyle(0);
02069 lPRF->SetLineColor(0);
02070 TString values;
02071 lPRF->AddEntry(prfProfile,"average PRF","lp");
02072 lPRF->AddEntry(mathieson,"mathieson formula","l");
02073 lPRF->AddEntry((TObject*)0," K_{3}=0.525","");
02074 prfProfile->Fit("mathiesonFit","QR0");
02075 values.Form(" K_{3}=%.3f",mathiesonFit->GetParameter(0));
02076 lPRF->AddEntry(mathiesonFit,"mathieson fit","l");
02077 lPRF->AddEntry((TObject*)0,values,"");
02078
02079 cPRF->cd()->SetLogz(1);
02080 prf->DrawCopy("colz");
02081 prfProfile->Fit("mathiesonFit","QR0");
02082 mathiesonFit->DrawCopy("same");
02083 mathieson->DrawCopy("same");
02084 prfProfile->DrawCopy("same");
02085
02086 lPRF->Draw("same");
02087 cPRF->SaveAs(outpic+"_PRF.pdf");
02088 cPRF->SaveAs(outpic+"_PRF.png");
02089
02090 const Int_t nChambers = 12;
02091 TCanvas *cEfficiency = new TCanvas("cEfficiency","cEfficiency",800,600);
02092 TProfile* hEfficiency = new TProfile("hEfficiency","hEfficiency",12,0.5,12.5);
02093 TLegend* leg3 = new TLegend(0.15,0.15,0.35,0.35);
02094 leg3->SetFillStyle(0);
02095 leg3->SetTextSize(0.025);
02096 leg3->SetLineStyle(0);
02097 leg3->SetLineColor(0);
02098 leg3->SetHeader(usedSuName[suid] + ", radiator: "+radiator2+", p=3GeV/c, 12mm XeCO_{2}");
02099
02100
02101 output->cd();
02102
02103 hEfficiency->GetXaxis()->SetRangeUser(1e-2,1e2);
02104 CalcPionEfficiency(simSpectrumE, simSpectrum, hEfficiency, nChambers, debug);
02105 hEfficiency->SetMarkerColor(simSpectrumE->GetLineColor());
02106 hEfficiency->SetLineColor(simSpectrumE->GetLineColor());
02107 output->cd();
02108 hEfficiency->Write("Efficiency_simulated", TObject::kOverwrite);
02109 leg3->AddEntry(simSpectrum,"simulated","l");
02110 cEfficiency->cd()->SetLogy(1);
02111 hEfficiency->DrawCopy("P,text0");
02112 CalcPionEfficiency(preCompBaselineSpectrumElectron, preCompBaselineSpectrum, hEfficiency, nChambers, debug);
02113 hEfficiency->SetMarkerColor(preCompBaselineSpectrumElectron->GetLineColor());
02114 hEfficiency->SetLineColor(preCompBaselineSpectrumElectron->GetLineColor());
02115 output->cd();
02116 hEfficiency->Write("Efficiency_measured_MS", TObject::kOverwrite);
02117 leg3->AddEntry(preCompBaselineSpectrumElectron,"measured: MS noise + baseline","l");
02118 cEfficiency->cd();
02119 hEfficiency->DrawCopy("P,text0,same");
02120 CalcPionEfficiency(baselineNoiseSpectrumElectron, baselineNoiseSpectrum, hEfficiency, nChambers, debug);
02121 hEfficiency->SetMarkerColor(baselineNoiseSpectrumElectron->GetLineColor());
02122 hEfficiency->SetLineColor(baselineNoiseSpectrumElectron->GetLineColor());
02123 output->cd();
02124 hEfficiency->Write("Efficiency_measured_FFM", TObject::kOverwrite);
02125 leg3->AddEntry(baselineNoiseSpectrumElectron,"measured: FFM noise + baseline","l");
02126 cEfficiency->cd();
02127 hEfficiency->DrawCopy("P,text0,same");
02128 CalcPionEfficiency(baselineNoiseSpectrumWoOWoUElectron, baselineNoiseSpectrumWoOWoU, hEfficiency, nChambers, debug);
02129 hEfficiency->SetMarkerColor(baselineNoiseSpectrumWoOWoUElectron->GetLineColor());
02130 hEfficiency->SetLineColor(baselineNoiseSpectrumWoOWoUElectron->GetLineColor());
02131 output->cd();
02132 hEfficiency->Write("Efficiency_measured_FFM_WoOWo", TObject::kOverwrite);
02133 leg3->AddEntry(baselineNoiseSpectrumWoOWoUElectron,"measured: FFM noise + baseline (woO && woU)","l");
02134 cEfficiency->cd();
02135 hEfficiency->DrawCopy("P,text0,same");
02136 leg3->Draw("same");
02137 TLine *l1 = new TLine(0.5,1,12.5,1);
02138 l1->SetLineColor(2);
02139 l1->SetLineStyle(2);
02140 l1->Draw("same");
02141 outpic.ReplaceAll("Spectra","Efficiency");
02142 cEfficiency->SaveAs(outpic+".pdf");
02143 cEfficiency->SaveAs(outpic+".png");
02144
02145 TLegend *lShape = new TLegend(0.5,0.75,0.85,0.85);
02146 lShape->SetFillStyle(0);
02147 lShape->SetTextSize(0.025);
02148 lShape->SetLineStyle(0);
02149 lShape->SetLineColor(0);
02150 TCanvas *r = new TCanvas("r","r",800,600);
02151 r->Divide(1,1);
02152 r->cd(1);
02153 averagePulse_e->GetYaxis()->SetRangeUser(-1,256);
02154 averagePulse_e->DrawCopy();
02155 lShape->AddEntry(averagePulse_e,"electrons","lp");
02156 averagePulse_p->DrawCopy("same");
02157 lShape->AddEntry(averagePulse_p,"pions","lp");
02158 lShape->Draw("same");
02159 r->SaveAs(outpic+"PulseShape.pdf");
02160 r->SaveAs(outpic+"PulseShape.png");
02161
02162 TCanvas* cBeamMonitor = new TCanvas("BeamMonitor","Beam Monitor",2*800,600);
02163 cBeamMonitor->Divide(2,1);
02164 cBeamMonitor->cd(1)->SetLogz(1);
02165 Ch1_Pb->DrawCopy("colz");
02166 cBeamMonitor->cd(2)->SetLogz(1);
02167 Ch2_Pb->DrawCopy("colz");
02168
02169
02170
02171
02172 cBeamMonitor->SaveAs(outpic+"Ch_Pb.pdf");
02173 cBeamMonitor->SaveAs(outpic+"Ch_Pb.png");
02174 if (!plotFromFile) {
02175 printf("%i Pion & %i Electron events found\n",nPions,nElectrons);
02176 Ch1_Pb->Write("", TObject::kOverwrite);
02177 noCh1_Pb->Write("", TObject::kOverwrite);
02178 Ch2_Pb->Write("", TObject::kOverwrite);
02179 noCh2_Pb->Write("", TObject::kOverwrite);
02180 Ch1_Ch2->Write("", TObject::kOverwrite);
02181 noCh1_Ch2->Write("", TObject::kOverwrite);
02182 prfProfile->Write("", TObject::kOverwrite);
02183 prf->Write("", TObject::kOverwrite);
02184 mathieson->Write("", TObject::kOverwrite);
02185 mathiesonFit->Write("", TObject::kOverwrite);
02186 cPRF->Write("", TObject::kOverwrite);
02187 cEfficiency->Write("", TObject::kOverwrite);
02188 simSpectrum->Write("", TObject::kOverwrite);
02189 simSpectrumE->Write("", TObject::kOverwrite);
02190 rawSpectrum->Write("", TObject::kOverwrite);
02191 baselineSpectrum->Write("", TObject::kOverwrite);
02192 baselineNoiseSpectrum->Write("", TObject::kOverwrite);
02193 noiseSpectrum->Write("", TObject::kOverwrite);
02194 noiseBaselineSpectrum->Write("", TObject::kOverwrite);
02195 baselineNoiseSpectrumElectron->Write("", TObject::kOverwrite);
02196 baselineNoiseSpectrumWoOWoUElectron->Write("", TObject::kOverwrite);
02197 baselineNoiseSpectrumWoOWoU->Write("", TObject::kOverwrite);
02198 preCompSpectrumElectron->Write("", TObject::kOverwrite);
02199 preCompBaselineSpectrumElectron->Write("", TObject::kOverwrite);
02200 preCompSpectrum->Write("", TObject::kOverwrite);
02201 preCompBaselineSpectrum->Write("", TObject::kOverwrite);
02202 averagePulse_e->Write("", TObject::kOverwrite);
02203 averagePulse_p->Write("", TObject::kOverwrite);
02204 probabilityOverflow->Write("", TObject::kOverwrite);
02205 probabilityUnderflow->Write("", TObject::kOverwrite);
02206 probabilityOverflowE->Write("", TObject::kOverwrite);
02207 probabilityUnderflowE->Write("", TObject::kOverwrite);
02208 for(Int_t delta = 0; delta < 6; delta++) {
02209 baselineNoiseSpectrumCrossTalkE[delta]->Scale(1./(Float_t)baselineNoiseSpectrumCrossTalkE[delta]->GetEntries());
02210 baselineNoiseSpectrumCrossTalkE[delta]->Write("", TObject::kOverwrite);
02211 baselineNoiseSpectrumCrossTalkP[delta]->Scale(1./(Float_t)baselineNoiseSpectrumCrossTalkP[delta]->GetEntries());
02212 baselineNoiseSpectrumCrossTalkP[delta]->Write("", TObject::kOverwrite);
02213 }
02214
02215
02216 crossTalk->Write("", TObject::kOverwrite);
02217 cResults->Write("", TObject::kOverwrite);
02218 }
02219 output->Close();
02220 }