• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

beamtime/cern-oct11/go4/AnalysisMacros/readtree_spadic.cxx (r4864/r3051)

Go to the documentation of this file.
00001 // Test script to retrieve complete composite event from Go4 written ROOT Tree
00002 // May be used as template for user analysis in root
00003 // v0.1 16-Jun-2011 J.Adamczewski-Musch, GSI - initial version
00004 // v0.2 22-Jun-2011 S.Linev, GSI - reading of complete event
00005 // v0.3 7-Nov-2011 JAM - show how to access single spadic data from beamtime event
00006 
00007 // Test file can be easily produced by analysis of old lmd files (from CERN beamtime in Nov 2010)
00008 // [shell]  go4analysis -file nov20_run44_0000.lmd -store test.root
00009 
00011 // NOTE; you need to run this script with ACLIC and set include path!
00012 // The following does not work?
00013 
00014 //#ifndef __CINT__
00015 
00016 #include <iostream>
00017 #include <string>
00018 #include <typeinfo>
00019 #include <iostream>
00020 #include <vector>
00021 
00022 
00023 #include "Riostream.h"
00024 #include "TRint.h"
00025 #include "TROOT.h"
00026 #include "TStyle.h"
00027 #include "Riostream.h"
00028 
00029 
00030 #include "TH2.h"
00031 #include "TH1.h"
00032 #include "TF1.h"
00033 
00034 #include "TGraph.h"
00035 #include "TMultiGraph.h"
00036 #include "TCanvas.h"
00037 #include "TProfile.h"
00038 #include "TStopwatch.h"
00039 
00040 #include "TFile.h"
00041 #include "TTree.h"
00042 #include "TBranch.h"
00043 #include "TMath.h"
00044 #include "TLegend.h"
00045 #include "TColor.h"
00046 #include "TText.h"
00047 #include "TKey.h"
00048 #include "TLatex.h"
00049 #include "TCanvas.h"
00050 #include "TPrincipal.h"
00051 #include "TMatrix.h"
00052 
00053 #include "TRocEvent.h"
00054 #include "roc/Message.h"
00055 #include "TSpadicEvent.h"
00056 
00057 
00058 #include "TMbsCrateEvent.h"
00059 #include "TBeamMonitorEvent.h"
00060 #include "TCernOct11UnpackEvent.h"
00061 
00062 //#include "langaus.C"
00063 
00064 //#endif
00065 
00066 // this is workaround for interpreter mode:
00067 #define NUM_SPADIC_CHA             8
00068 #define SPADIC_TRACE_SIZE         45
00069 #define SPADIC_ADC_MAX           255
00070 #define noBaselineTB               5 
00071 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;
00072 Bool_t isElectron, isPion, isMyon;
00073 TPrincipal* principal = new TPrincipal(NUM_SPADIC_CHA,"ND");
00074 Int_t pidcuts[18] = {0};
00075 using namespace std;
00076 
00077 class MFSpadicEvent
00078 {
00079 public:
00080   Float_t rawPulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE];
00081   Float_t cleanPulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE];
00082 
00083   Bool_t signalCH[NUM_SPADIC_CHA];
00084 
00085   Bool_t underFlowEv;
00086   Bool_t underFlowCH[NUM_SPADIC_CHA];
00087   Bool_t underFlowTB[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE];
00088 
00089   Bool_t overFlowEv;
00090   Bool_t overFlowCH[NUM_SPADIC_CHA];
00091   Bool_t overFlowTB[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE];
00092 
00093 
00094   MFSpadicEvent() {
00095     for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
00096       for (Int_t tb = 0; tb < SPADIC_TRACE_SIZE; tb++) {
00097         rawPulse[ch][tb] = 0.0;
00098         cleanPulse[ch][tb] = 0.0;
00099         underFlowTB[ch][tb] = kFALSE;
00100         overFlowTB[ch][tb] = kFALSE;
00101       }
00102       signalCH[ch] = kFALSE;
00103       underFlowCH[ch] = kFALSE;
00104       overFlowCH[ch] = kFALSE;
00105     }
00106     underFlowEv = kFALSE;
00107     overFlowEv = kFALSE;
00108     /*
00109       rawPulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {0.0};
00110       cleanPulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {0.0};
00111       signalCH[NUM_SPADIC_CHA] = {kFALSE};
00112       underFlowEv = kFALSE;
00113       underFlowCH[NUM_SPADIC_CHA] = {kFALSE};
00114       underFlowTB[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {kFALSE};
00115       overFlowEv = kFALSE;
00116       overFlowCH[NUM_SPADIC_CHA] = {kFALSE};
00117       overFlowTB[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {kFALSE};
00118     */
00119   }
00120 
00121 private:
00122 
00123 };
00124 
00125 void Statusbar(Int_t i, Int_t n) {
00126   if (int(i * 100 / float(n)) - int((i-1) * 100 / float(n)) >= 1) {
00127     if (int(i * 100 / float(n)) == 1 || i == 1 || i == 0) 
00128       cout << "[" << flush;
00129     cout << "-" << flush;
00130     if (int(i * 10 / float(n)) - int((i-1) * 10 / float(n)) >= 1) 
00131       cout << "|";
00132     if (int(i * 100 / float(n)) >=99) 
00133       cout << "]" <<endl;
00134   }
00135 }
00136 
00137 void Clusterizer(Double_t pulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE],Int_t nSpadicSignalCh, Bool_t SignalChannel[NUM_SPADIC_CHA], Int_t maxch, Int_t maxT[NUM_SPADIC_CHA], Double_t maxA[NUM_SPADIC_CHA]) {
00138   Bool_t Run_TimeClustering(0), Run_AmplitudeClustering(0);
00139   nSpadicSignalCh = 0;
00140   /*
00141   if (Run_TimeClustering) {
00142     for (UInt_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00143       if (maxT[ch] >= maxT[maxch] - 5 && maxT[ch] <= maxT[maxch] + 5){ // if signal is correlated in time domain
00144         //spdata->fSpadicSignalCh[ch] = true;
00145         SignalChannel[ch] = true;
00146         nSpadicSignalCh++;
00147       }
00148       else {
00149         SignalChannel[ch] = false;
00150       }
00151     }
00152   }
00153   if (Run_AmplitudeClustering) {
00154     for (UInt_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00155       if (maxA[ch] > 15 + pulse[ch][0]){                               //   if signal is above a minimum threshold with respect to the first time bin of this channel
00156         //spdata->fSpadicSignalCh[ch] = true;
00157         SignalChannel[ch] = true;
00158         nSpadicSignalCh++;        
00159       }
00160       else {
00161         SignalChannel[ch] = false;
00162       }
00163     }
00164   }
00165   fSpadic_ClusterWidth[sid]->Fill(nSpadicSignalCh);  
00166   */
00167 }
00168 
00169 void NoiseReduction(TH1D* inPulse[NUM_SPADIC_CHA], TH1D* outPulse[NUM_SPADIC_CHA], Bool_t SignalChannel[NUM_SPADIC_CHA]) {
00170   const double lowercorthreshold = 0.112;
00171   const double uppercorthreshold = 0.112;
00172   const double nosignalcorthreshold = 0.1;
00173   Double_t cortest[NUM_SPADIC_CHA];
00174   Double_t inputarray[SPADIC_TRACE_SIZE][NUM_SPADIC_CHA] = {{0.0}};
00175   Double_t minIntegral = 265*45;
00176   Double_t tempIntegral = 0.0;
00177   int minch = -1;//GetMinimumChannel(input);
00178   for(Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00179     tempIntegral = 0.0;
00180     for(Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++){  
00181       inputarray[bin][ch] = inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin));
00182       tempIntegral += inputarray[bin][ch];
00183     }
00184     if (tempIntegral < minIntegral){
00185       minIntegral = tempIntegral;
00186       minch = ch;
00187     }
00188   }
00189 
00190   int noise_ch_counter=0;
00191 
00192   Double_t thisisnoise[SPADIC_TRACE_SIZE] = {0.0};
00193 
00194   double val_in=0;
00195   double val_noise=0;
00196 
00197 
00198   for(int t=0;t<SPADIC_TRACE_SIZE;t++)
00199     {
00200       principal->AddRow(inputarray[t]);
00201     }
00202   
00203   principal->MakePrincipals();
00204   //TMatrixD* cova = new TMatrixD(NUM_SPADIC_CHA,NUM_SPADIC_CHA);
00205   TMatrixD* cova = (TMatrixD*)principal->GetCovarianceMatrix();
00206   
00207   Int_t lastSigCh = -1;
00208 
00209   for(int ch=0;ch<NUM_SPADIC_CHA;ch++)
00210     {
00211       cortest[ch] = TMatrixDRow (*cova,minch)(ch);
00212       if(cortest[ch]>lowercorthreshold)
00213         {
00214           SignalChannel[ch] = false;
00215           noise_ch_counter++;
00216           //thisisnoise->Add(input[ch]);
00217           for(Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++){
00218             thisisnoise[bin] += inputarray[bin][ch];
00219           }
00220         }
00221       else { 
00222         SignalChannel[ch] = true;
00223       } 
00224     }
00225   //thisisnoise->Scale(1./(double)noise_ch_counter);
00226   for(Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++){
00227     thisisnoise[bin] /= (double)noise_ch_counter;
00228   }
00229  
00230   for (int ch=0; ch<NUM_SPADIC_CHA; ch++)
00231     {
00232       for (int k=0; k<SPADIC_TRACE_SIZE; k++)
00233         {
00234           /*
00235             val_in=input[ch]->GetBinContent(k);
00236             val_noise=thisisnoise->GetBinContent(k);
00237             input[ch]->SetBinContent(k, val_in-val_noise);
00238           */
00239           //outPulse[ch][k] = inPulse[ch][k] - thisisnoise[k];
00240           outPulse[ch]->Fill(k, inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(k)) - thisisnoise[k]);
00241         }
00242     }
00243 
00244   principal->Clear();
00245 
00246   /*
00247     Double_t AverTrace[SPADIC_TRACE_SIZE] = {0.0};
00248     for (UInt_t bin = 0; bin < SPADIC_TRACE_SIZE-1; bin++){ 
00249     AverTrace[bin] = 0.0;  
00250     for (UInt_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00251     if (!SignalChannel[ch]){
00252     AverTrace[bin] += rawPulse[ch]bin];
00253     }
00254   
00255     if(nSpadicSignalCh<NUM_SPADIC_CHA) // Debug check validity of array? JAM
00256     {
00257     AverTrace[bin] /= (NUM_SPADIC_CHA - nSpadicSignalCh);
00258     }
00259     else
00260     {
00261     //cout <<"WWWWWWWWWW arning: nSpadicSignalCh="<<nSpadicSignalCh<<" exceeds NUM_SPADIC_CHA "<<NUM_SPADIC_CHA << endl;
00262     }
00263 
00264     for (UInt_t ch = 0; ch < NUM_SPADIC_CHA; ch++){ 
00265     cleanPulse[ch][bin] = rawPulse[ch]bin] - AverTrace[bin];
00266     }
00267   */
00268 }
00269 void BaselineCompensation(TH1D* inPulse[NUM_SPADIC_CHA], TH1D* outPulse[NUM_SPADIC_CHA])
00270 {
00271   Double_t baseline[NUM_SPADIC_CHA] = {0.0};
00272   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00273     for (Int_t bin = 0; bin < noBaselineTB; bin++){
00274       baseline[ch] += inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin));
00275     }
00276     baseline[ch] /= noBaselineTB;
00277   }
00278 
00279   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++){
00280     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++){
00281       outPulse[ch]->Fill(bin, inPulse[ch]->GetBinContent(inPulse[ch]->FindBin(bin)) - baseline[ch]);
00282     }
00283   }
00284 }
00285 
00286 
00287 void BaselineCorrection(Double_t pulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE]) {
00288   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
00289     //cout << endl;
00290     Float_t baseline(0);        
00291     for (Int_t bin = 0; bin < noBaselineTB; bin++) {    
00292         baseline += pulse[ch][bin];
00293     }
00294     baseline /= Float_t(noBaselineTB);
00295     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {       
00296       pulse[ch][bin] -= baseline;
00297     }
00298   }
00299 }
00300 /*
00301 void CopyData(Double_t pulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE], TSpadicData* theSpadicA) {
00302   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {       
00303     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {       
00304       pulse[ch][bin] = theSpadicA->fSpadicCompensated[ch][bin];
00305     }
00306   }
00307   BaselineCorrection(pulse);
00308 }
00309 void MergeData(Double_t pulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE], TSpadicData* theSpadicA, TSpadicData* theSpadicB) {
00310   Double_t pulseA[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {{0.0}};
00311   Double_t pulseB[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {{0.0}};
00312   CopyData(pulseA, theSpadicA);
00313   CopyData(pulseB, theSpadicB);
00314   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {       
00315     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
00316       pulse[ch][bin] = pulseA[ch][bin] + pulseB[7-ch][bin];
00317     }
00318   }
00319 }
00320 */
00321 /*
00322 void get_Pb_Ch_Cut(TString fname) {
00323   ifstream cutLib;
00324   cutLib.open("cutConditions.txt");
00325   TString run;
00326   string line;
00327   Bool_t found = false;
00328   if (cutLib.is_open()) {
00329     getline (cutLib, line);
00330     while (run != fname && cutLib.good()){
00331       cutLib >> run >> 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;
00332       //printf("%s\n",run.Data());
00333       if(run == fname){
00334         printf("          run                  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\n          %s %11i %11i %11i %11i %11i %11i %11i %11i %11i %11i %11i %11i\n",run.Data(), 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);
00335         found = true;
00336       }
00337     }
00338     if (!found) printf("did not found pid cut conditions for %s\n",fname.Data());
00339   }
00340   cutLib.close();
00341 }
00342 */
00343 
00344 
00345 
00346 
00347 void GetPidCuts(TString runId)
00348 {
00349   Bool_t MS_Pid = true;
00350   Bool_t FFM_Pid = false;
00351   //cout << runId << endl;
00352   runId.ReplaceAll("Be_run","");
00353   //cout << runId << endl;
00354   runId.ReplaceAll("Te_run","");
00355   //cout << runId << endl;
00356   runId.ReplaceAll(".root","");
00357   //cout << runId << endl;
00358   int runnumber=runId.Atoi();
00359   //Int_t pidcuts[18];
00360   pidcuts[0] =1; // // El Ch1 min
00361   pidcuts[1] =1; // // El Ch1 max
00362   pidcuts[2] =1; // // El Ch2 min
00363   pidcuts[3] =1; // // El Ch2 max
00364   pidcuts[4] =1; // // El Pb min
00365   pidcuts[5] =1; // // El Pb max
00366   pidcuts[6] =1; // // Pi Ch1 min
00367   pidcuts[7] =1; // // Pi Ch1 max
00368   pidcuts[8] =1; // // Pi Ch2 min
00369   pidcuts[9] =1; // // Pi Ch2 max
00370   pidcuts[10]=1; // // Pi Pb min
00371   pidcuts[11]=1; // // Pi Pb max
00372   pidcuts[12]=1; // // Mu Ch1 min
00373   pidcuts[13]=1; // // Mu Ch1 max
00374   pidcuts[14]=1; // // Mu Ch2 min
00375   pidcuts[15]=1; // // Mu Ch2 max
00376   pidcuts[16]=1; // // Mu Pb min
00377   pidcuts[17]=1; // // Mu Pb max
00378   if (MS_Pid) {
00379     if (runnumber < 1910000 )       cout << "[WARN] No PID cuts set! Invalid runnumber " << runnumber << endl;
00380     else if (runnumber >= 2010010 && runnumber <= 2410021) {//3GeV
00381       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00382       pidcuts[6] =  0; pidcuts[7] = 400; pidcuts[8] =  0; pidcuts[9] = 400; pidcuts[10]=   0; pidcuts[11]= 900; 
00383       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00384     }
00385     else if (runnumber > 2410021 && runnumber <= 2510014) {//3GeV
00386       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00387       pidcuts[6] =  0; pidcuts[7] = 400; pidcuts[8] =  0; pidcuts[9] = 400; pidcuts[10]=   0; pidcuts[11]=1500; 
00388       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00389     }
00390     else if (runnumber > 2510014 && runnumber <= 2610002) {//3GeV
00391       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00392       pidcuts[6] =  0; pidcuts[7] = 400; pidcuts[8] =  0; pidcuts[9] = 400; pidcuts[10]=   0; pidcuts[11]=1500; 
00393       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00394     }
00395     else if (runnumber > 2610002 && runnumber <= 2610005) {//3GeV
00396       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2500; pidcuts[5] =9999; 
00397       pidcuts[6] =  0; pidcuts[7] = 400; pidcuts[8] =  0; pidcuts[9] = 400; pidcuts[10]=   0; pidcuts[11]=1500; 
00398       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00399     }
00400     else if (runnumber > 2610005 && runnumber <= 3010011) {//3GeV
00401       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00402       pidcuts[6] =  0; pidcuts[7] = 400; pidcuts[8] =  0; pidcuts[9] = 400; pidcuts[10]=   0; pidcuts[11]=1500; 
00403       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00404     }
00405  
00406     else if (runnumber > 3010015 )  cout << "[WARN] No PID cuts set! Invalid runnumber " << runnumber << endl;
00407     else                           {cout << "[FATAL] Runnumber totaly f**ked up... exiting root NOW! " << endl;}
00408   }
00409   if (FFM_Pid){
00410   
00411     if (runnumber < 1910000 )       cout << "[WARN] No PID cuts set! Invalid runnumber " << runnumber << endl;
00412     else if (runnumber >= 2010000 && runnumber <= 2010008) {//3GeV
00413       pidcuts[0] =600; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =1100; pidcuts[5] =9999; 
00414       pidcuts[6] =305; pidcuts[7] = 318; pidcuts[8] =335; pidcuts[9] = 350; pidcuts[10]= 400; pidcuts[11]=9999; 
00415       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00416     }
00417     else if (runnumber > 2110008 && runnumber <= 2110015) {//3GeV
00418       pidcuts[0] =600; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =1100; pidcuts[5] =9999; 
00419       pidcuts[6] =305; pidcuts[7] = 318; pidcuts[8] =335; pidcuts[9] = 350; pidcuts[10]= 400; pidcuts[11]=9999; 
00420       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00421     }
00422     else if (runnumber > 2110015 && runnumber <= 2110020) {//3GeV
00423       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00424       pidcuts[6] =290; pidcuts[7] = 320; pidcuts[8] =330; pidcuts[9] = 350; pidcuts[10]=   1; pidcuts[11]=9999; 
00425       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00426     }
00427     else if (runnumber > 2110020 && runnumber <= 2210000) {//3GeV
00428       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00429       pidcuts[6] =303; pidcuts[7] = 323; pidcuts[8] =328; pidcuts[9] = 346; pidcuts[10]=   1; pidcuts[11]=9999; 
00430       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00431     }
00432     else if (runnumber > 2210000 && runnumber <= 2210009) {//3GeV
00433       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00434       pidcuts[6] =305; pidcuts[7] = 325; pidcuts[8] =325; pidcuts[9] = 349; pidcuts[10]=   1; pidcuts[11]=9999; 
00435       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00436     }
00437     else if (runnumber > 2210009 && runnumber <= 2210011) {//3GeV
00438       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00439       pidcuts[6] =303; pidcuts[7] = 323; pidcuts[8] =325; pidcuts[9] = 348; pidcuts[10]=   1; pidcuts[11]=9999; 
00440       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00441     }
00442     else if (runnumber > 2210011 && runnumber <= 2210012) {//3GeV
00443       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00444       pidcuts[6] =303; pidcuts[7] = 323; pidcuts[8] =325; pidcuts[9] = 348; pidcuts[10]=   1; pidcuts[11]=9999; 
00445       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00446     } 
00447     else if (runnumber > 2210012 && runnumber <= 2310000) {//3GeV
00448       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00449       pidcuts[6] =300; pidcuts[7] = 325; pidcuts[8] =325; pidcuts[9] = 348; pidcuts[10]=   1; pidcuts[11]=9999; 
00450       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00451     }
00452     else if (runnumber > 2310001 && runnumber <= 2310001) {//3GeV
00453       pidcuts[0] =600; pidcuts[1] =1500; pidcuts[2] =550; pidcuts[3] =1500; pidcuts[4] =1100; pidcuts[5] =1500; 
00454       pidcuts[6] =305; pidcuts[7] = 318; pidcuts[8] =335; pidcuts[9] = 350; pidcuts[10]= 400; pidcuts[11]=1000; 
00455       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00456     }
00457     else if (runnumber > 2310001 && runnumber <= 2310004) {//3GeV
00458       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00459       pidcuts[6] =310; pidcuts[7] = 330; pidcuts[8] =325; pidcuts[9] = 355; pidcuts[10]=   1; pidcuts[11]=9999; 
00460       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00461     }  
00462     else if (runnumber > 2310004 && runnumber <= 2310008) {//3GeV
00463       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00464       pidcuts[6] =310; pidcuts[7] = 330; pidcuts[8] =325; pidcuts[9] = 355; pidcuts[10]=   1; pidcuts[11]=9999; 
00465       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00466     }
00467     else if (runnumber > 2310008 && runnumber <= 2410010) {//3GeV
00468       pidcuts[0] = 500; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00469       pidcuts[6] = 300; pidcuts[7] = 340; pidcuts[8] =315; pidcuts[9] = 375; pidcuts[10]=   1; pidcuts[11]=9999; 
00470       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00471     }
00472     else if (runnumber > 2410010 && runnumber <= 2410020) {//2GeV
00473       pidcuts[0] = 500; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00474       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00475       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00476     }
00477     else if (runnumber > 2410020 && runnumber <= 2510003) {//4GeV
00478       pidcuts[0] = 600; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00479       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00480       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00481     }
00482     else if (runnumber > 2510003 && runnumber <= 2510012) {//6GeV
00483       pidcuts[0] = 500; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00484       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00485       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00486     }
00487     else if (runnumber == 2510013) {//10GeV
00488       pidcuts[0] = 400; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00489       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00490       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00491     }
00492     else if (runnumber > 2510014 && runnumber <= 2610005) {//8GeV
00493       pidcuts[0] = 500; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00494       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00495       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00496     }
00497     else if (runnumber > 2610005 && runnumber <= 2710019) {//4GeV
00498       pidcuts[0] = 500; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00499       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00500       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00501     }
00502     else if (runnumber > 2710019 && runnumber <= 2810003) {//2GeV
00503       pidcuts[0] =1000; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00504       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00505       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00506     }
00507     else if (runnumber > 2810003 && runnumber <= 2910013) {//4GeV
00508       pidcuts[0] =1000; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00509       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00510       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00511     }
00512     else if (runnumber > 2910016 && runnumber <= 3010015) {//2GeV
00513       pidcuts[0] =1000; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00514       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00515       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00516     }
00517     else if (runnumber > 2910013 && runnumber <= 3010015) {
00518       pidcuts[0] =1000; pidcuts[1] =2000; pidcuts[2] =650; pidcuts[3] =1500; pidcuts[4] =2000; pidcuts[5] =9999; 
00519       pidcuts[6] = 290; pidcuts[7] = 320; pidcuts[8] =325; pidcuts[9] = 360; pidcuts[10]= 400; pidcuts[11]= 800; 
00520       pidcuts[12]=   1; pidcuts[13]=9999; pidcuts[14]=  1; pidcuts[15]=9999; pidcuts[16]= 850; pidcuts[17]=1100;
00521     }
00522     else if (runnumber > 3010015 )  cout << "[WARN] No PID cuts set! Invalid runnumber " << runnumber << endl;
00523     else                           {cout << "[FATAL] Runnumber totaly f**ked up... exiting root NOW! " << endl;}
00524     
00525   
00526   
00527     //  else if (runnumber == 2210011) {pidcuts[0]=600; pidcuts[1]=1050; pidcuts[2]=550; pidcuts[3]=850; pidcuts[4]=1100; pidcuts[5]=1500; pidcuts[6]=305; pidcuts[7]=318; pidcuts[8]=335; pidcuts[9]=350; pidcuts[10]=400; pidcuts[11]=1000; pidcuts[12]=1; pidcuts[13]=1; pidcuts[14]=1; pidcuts[15]=1; pidcuts[16]=1; pidcuts[17]=1;}
00528     /*
00529       else if (runnumber > 2110000 && runnumber <= 2110015) {
00530       pidcuts[0] =600; pidcuts[1] =1050; pidcuts[2] =550; pidcuts[3] = 850; pidcuts[4] =1100; pidcuts[5] =1500; 
00531       pidcuts[6] =305; pidcuts[7] = 318; pidcuts[8] =335; pidcuts[9] = 350; pidcuts[10]= 400; pidcuts[11]=1000; 
00532       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00533       }
00534       else if (runnumber > 2110015 && runnumber <= 2110020) {
00535       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =500; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00536       pidcuts[6] =290; pidcuts[7] = 320; pidcuts[8] =330; pidcuts[9] = 350; pidcuts[10]=   1; pidcuts[11]=9999; 
00537       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00538       }
00539       else if (runnumber > 2110020 && runnumber <= 2210000) {
00540       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00541       pidcuts[6] =303; pidcuts[7] = 323; pidcuts[8] =328; pidcuts[9] = 346; pidcuts[10]=   1; pidcuts[11]=9999; 
00542       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00543       }
00544       else if (runnumber > 2210000 && runnumber <= 2210009) {
00545       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00546       pidcuts[6] =305; pidcuts[7] = 325; pidcuts[8] =325; pidcuts[9] = 349; pidcuts[10]=   1; pidcuts[11]=9999; 
00547       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00548       }
00549       else if (runnumber > 2210009 && runnumber <= 2210011) {
00550       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00551       pidcuts[6] =303; pidcuts[7] = 323; pidcuts[8] =325; pidcuts[9] = 348; pidcuts[10]=   1; pidcuts[11]=9999; 
00552       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00553       }
00554       else if (runnumber > 2210011 && runnumber <= 2210012) {
00555       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00556       pidcuts[6] =303; pidcuts[7] = 323; pidcuts[8] =325; pidcuts[9] = 348; pidcuts[10]=   1; pidcuts[11]=9999; 
00557       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00558       } 
00559       else if (runnumber > 2210012 && runnumber <= 2310001) {
00560       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00561       pidcuts[6] =300; pidcuts[7] = 325; pidcuts[8] =325; pidcuts[9] = 348; pidcuts[10]=   1; pidcuts[11]=9999; 
00562       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00563       }
00564       else if (runnumber > 2310001 && runnumber <= 2310001) {
00565       pidcuts[0] =600; pidcuts[1] =1050; pidcuts[2] =550; pidcuts[3] =850; pidcuts[4] =1100; pidcuts[5] =1500; 
00566       pidcuts[6] =305; pidcuts[7] = 318; pidcuts[8] =335; pidcuts[9] =350; pidcuts[10]= 400; pidcuts[11]=1000; 
00567       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=  1; pidcuts[16]=   1; pidcuts[17]=   1;
00568       }
00569       else if (runnumber > 2310001 && runnumber <= 2310004) {
00570       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00571       pidcuts[6] =310; pidcuts[7] = 330; pidcuts[8] =325; pidcuts[9] = 355; pidcuts[10]=   1; pidcuts[11]=9999; 
00572       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00573       }  
00574       else if (runnumber > 2310004 && runnumber <= 2310008) {
00575       pidcuts[0] =500; pidcuts[1] =9999; pidcuts[2] =520; pidcuts[3] =9999; pidcuts[4] =1000; pidcuts[5] =9999; 
00576       pidcuts[6] =310; pidcuts[7] = 330; pidcuts[8] =325; pidcuts[9] = 355; pidcuts[10]=   1; pidcuts[11]=9999; 
00577       pidcuts[12]=  1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00578       }
00579       else if (runnumber > 2310008 && runnumber <= 2710001) {
00580       pidcuts[0] =1000; pidcuts[1] =9999; pidcuts[2] =550; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00581       pidcuts[6] = 308; pidcuts[7] = 328; pidcuts[8] =350; pidcuts[9] = 374; pidcuts[10]=   1; pidcuts[11]=9999; 
00582       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00583       }
00584       else if (runnumber > 2710001 && runnumber <= 2910006) {
00585       pidcuts[0] =1000; pidcuts[1] =9999; pidcuts[2] =600; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00586       pidcuts[6] = 315; pidcuts[7] = 330; pidcuts[8] =355; pidcuts[9] = 380; pidcuts[10]=   1; pidcuts[11]=9999; 
00587       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00588       }
00589       else if (runnumber > 2710006 && runnumber <= 2910010) {
00590       pidcuts[0] =1000; pidcuts[1] =9999; pidcuts[2] =600; pidcuts[3] =9999; pidcuts[4] =2000; pidcuts[5] =9999; 
00591       pidcuts[6] = 300; pidcuts[7] = 320; pidcuts[8] =330; pidcuts[9] = 360; pidcuts[10]=   1; pidcuts[11]=9999; 
00592       pidcuts[12]=   1; pidcuts[13]=   1; pidcuts[14]=  1; pidcuts[15]=   1; pidcuts[16]=   1; pidcuts[17]=   1;
00593       }
00594     
00595     else if (runnumber > 2910010 && runnumber <= 3010015) {
00596       pidcuts[0] =1000; pidcuts[1] =2000; pidcuts[2] =650; pidcuts[3] =1500; pidcuts[4] =2000; pidcuts[5] =3500; 
00597       pidcuts[6] = 290; pidcuts[7] = 320; pidcuts[8] =325; pidcuts[9] = 360; pidcuts[10]= 400; pidcuts[11]=800; 
00598       pidcuts[12]=   1; pidcuts[13]=9999; pidcuts[14]=  1; pidcuts[15]=9999; pidcuts[16]= 850; pidcuts[17]=1100;
00599     }
00600     else if (runnumber > 3010015 )  cout << "[WARN] No PID cuts set! Invalid runnumber " << runnumber << endl;
00601     else                           {cout << "[FATAL] Runnumber totaly f**ked up... exiting root NOW! " << endl;}
00602     */
00603   }
00604   
00605 }
00606 void getPID(/*TMbsCrateEvent* input, TString runId*/ Float_t ch1, Float_t ch2, Float_t pb)
00607 {
00608   //int *pidcuts = GetPidCuts(runId);
00609   
00610   //cout << "test: " << pidcuts[7] << endl;
00611 
00612   if (ch1 > pidcuts[0]  && // ELECTRON
00613       ch1 < pidcuts[1] &&
00614       ch2 > pidcuts[2]  &&
00615       ch2 < pidcuts[3]  &&
00616       pb  > pidcuts[4] &&
00617       pb  < pidcuts[5]
00618       ) 
00619     {
00620       isElectron=true;
00621     }
00622   
00623   else if (ch1 > pidcuts[6]  && // PION
00624            ch1 < pidcuts[7]  &&
00625            ch2 > pidcuts[8]  &&  // was 340
00626            ch2 < pidcuts[9]  &&  // was 348
00627            pb  > pidcuts[10] &&
00628            pb  < pidcuts[11]
00629            ) 
00630     {
00631       isPion=true;
00632     }
00633      
00634   else if (ch1 > pidcuts[12] && // MUON
00635            ch1 < pidcuts[13] &&
00636            ch2 > pidcuts[14] &&
00637            ch2 < pidcuts[15] &&
00638            pb  > pidcuts[16] &&
00639            pb  < pidcuts[17]
00640            ) 
00641     {
00642       isMyon=true;
00643     }  
00644 }
00645 /*
00646 void getPID(Float_t Ch1, Float_t Ch2, Float_t Pb) {
00647   if (Ch1 < Pi_Ch1_Max && Ch1 > Pi_Ch1_Min)
00648     if (Ch2 < Pi_Ch2_Max && Ch2 > Pi_Ch2_Min)
00649       if (Pb < Pi_Pb_Max && Pb > Pi_Pb_Min)
00650         isPion = true;
00651   if (Ch1 < El_Ch1_Max && Ch1 > El_Ch1_Min)
00652     if (Ch2 < El_Ch2_Max && Ch2 > El_Ch2_Min)
00653       if (Pb < El_Pb_Max && Pb > El_Pb_Min)
00654         isElectron = true;
00655 }
00656 */
00657 /*
00658 void Distance2Track(Double_t xPos[4], Double_t distance[4]) {
00659   Double_t zMean(0.0), xMean(0.0), m(0.0), b(0.0), SUMzx(0.0), SUMzz(0.0);
00660   //Least squares: x = m * z + b
00661   Double_t zPos[4] = {0, 320, 638, 958};
00662   for (Int_t j = 0; j < 4; j++) {
00663     for (Int_t i = 0; i < 4; i++) {
00664       if (i != j) {
00665         zMean += zPos[i];
00666         xMean += xPos[i];
00667       }
00668     }
00669     zMean /= 3.;
00670     xMean /= 3.;
00671     for (Int_t i = 0; i < 4; i++) {
00672       if (i != j) {
00673         SUMzx += (zPos[i] - zMean) * (xPos[i] - xMean);
00674         SUMzz += (zPos[i] - zMean) * (zPos[i] - zMean);
00675       }
00676     }
00677     m = SUMzx / SUMzz;
00678     b = xMean - m * zMean;
00679     distance[j] = xPos[j] - (m * zPos[j] + b);
00680   }
00681 }
00682 */
00683 Bool_t Distance2TrackFFM(Double_t x[8], Double_t distance[8]/*, Double_t mAlig[8][8], Double_t bAlig[8][8] /*, Bool_t MS = true*/) {
00684   //Alignment correction
00685   // use suid = 0 as fixed reference
00686   Double_t xPos[8] = {0.0};
00687   Int_t nPos = 0;
00688   for (Int_t i = 4; i< 8; i++) {
00689     xPos[i] = x[i];
00690     if (xPos[i] != 0.0) nPos++;
00691   }
00692   if (nPos < 4) return false;
00693   
00694   Double_t zMean(0.0), xMean(0.0), m(0.0), b(0.0), SUMzx(0.0), SUMzz(0.0);
00695   //Least squares fit: x = m * z + b
00696   //                  MS  Ms   Ms   MS  F    F    F    F
00697   Double_t zPos[8] = {0, 320, 638, 958, 0, 320, 638, 958};
00698   for (Int_t j = 4; j < 8; j++) {
00699     Int_t count = 0;
00700     for (Int_t i = 4; i < 8; i++) {
00701       if (i != j && x[i] != 0.0) {
00702         zMean += zPos[i];
00703         xMean += xPos[i];
00704         count++;
00705       }
00706     }
00707     //if (count < 2) return false;
00708     zMean /= count;
00709     xMean /= count;
00710     for (Int_t i = 4; i < 8; i++) {
00711       if (i != j && x[i] != 0.0) {
00712         SUMzx += (zPos[i] - zMean) * (xPos[i] - xMean);
00713         SUMzz += (zPos[i] - zMean) * (zPos[i] - zMean);
00714       }
00715     }
00716     m = SUMzx / SUMzz;
00717     b = xMean - m * zMean;
00718     distance[j] = xPos[j] - (m * zPos[j] + b);
00719   }
00720   return true;
00721 }
00722 Bool_t Distance2TrackMS(Double_t x[8], Double_t distance[8]/*, Double_t mAlig[8][8], Double_t bAlig[8][8] /*, Bool_t MS = true*/) {
00723   //Alignment correction
00724   // use suid = 0 as fixed reference
00725   Double_t xPos[4] = {0.0};
00726   Int_t nPos = 0;
00727   for (Int_t i = 0; i< 4; i++) {
00728     xPos[i] = x[i];
00729     if (xPos[i] != 0.0) nPos++;
00730   }
00731   if (nPos < 4) return false;
00732  
00733   Double_t zMean(0.0), xMean(0.0), m(0.0), b(0.0), SUMzx(0.0), SUMzz(0.0);
00734   //Least squares fit: x = m * z + b
00735 
00736   Double_t zPos[4] = {0, 320, 638, 958};
00737   for (Int_t j = 0; j < 4; j++) {
00738     Int_t count = 0;
00739     for (Int_t i = 0; i < 4; i++) {
00740       if (i != j && x[i] != 0.0) {
00741         zMean += zPos[i];
00742         xMean += xPos[i];
00743         count++;
00744       }
00745     }
00746     //if (count < 2) return false;
00747     zMean /= count;
00748     xMean /= count;
00749     for (Int_t i = 0; i < 4; i++) {
00750       if (i != j && x[i] != 0.0) {
00751         SUMzx += (zPos[i] - zMean) * (xPos[i] - xMean);
00752         SUMzz += (zPos[i] - zMean) * (zPos[i] - zMean);
00753       }
00754     }
00755     m = SUMzx / SUMzz;
00756     b = xMean - m * zMean;
00757     distance[j] = xPos[j] - (m * zPos[j] + b);
00758   }
00759   return true;
00760 }
00761 
00762 
00763 void readtree_spadic(TString nameFileSet, Bool_t debug=0) {
00764 
00765   Bool_t raw = true;
00766   Bool_t msMerge = false;
00767 
00768   ifstream fileSet;
00769   fileSet.open(nameFileSet.Data());
00770 
00771   if (fileSet.is_open()) {
00772     TString ofname = "data2011/Analysis/" + TString(nameFileSet(0,nameFileSet.Sizeof()-5)).Append(".root");
00773     TFile outputFile(ofname,"RECREATE","output of readtree_spadic.cxx");
00774     TString mergeName[2] = {"NotMerged","Merged"};
00775     TString filterName[4] = {"wOwU","woOwU","woOwoU","wOwoU"}; // w == with; wo == without; O == overflow; U == undershoot
00776     TString folder = "data2011/TTrees/";
00777     TString picEx = ".pdf";
00778     const Int_t usedSusibos = 8;
00779     const Int_t recoSets = 9;
00780     const Int_t nMerge = 2;
00781     const Int_t nFilter = 4;
00782     //const Int_t noBaselineTB = 5;
00783     Int_t topSuId[4]            = {         1,         11,        3,        15};
00784     Int_t usedSuId[usedSusibos] = {         2,         12,        6,        18,         4,         5,        16,        17  };
00785     Float_t padWidth[usedSusibos] = {       5,          5,        8,         8,         5,         5,         5,         5  };
00786     TString recoSetName[recoSets] = {"ClusterInteg","3PadInteg","1PadInteg","ClusterIntegWindow","3PadIntegWindow","1PadIntegWindow","ClusterAmpl","3PadAmpl","1PadAmpl"};
00787     Int_t allPion[usedSusibos][nMerge] = {{0}};
00788     Int_t allElectron[usedSusibos][nMerge] = {{0}};
00789     Int_t allGoodEvent[usedSusibos][nMerge] = {{0}};
00790     Int_t allEvents = 0;
00791     TString formula;
00792     //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) )) )"
00793     //,K3,K3,K3,W[a],par,h[b],K3,K3,W[a],par,h[b]);
00794 
00795     TF1 *mathiesonMS336 = new TF1("mathieson",
00796                                   " -1. / (2. * atan(sqrt([0]))) * (atan(sqrt([0]) *tanh(3.14159265 * (-2. + sqrt([0]) ) * (5.0 + 2.* x * 1.0) / (8.* 3.0) )) +  atan(sqrt([0]) *  tanh(3.14159265 * (-2. + sqrt([0]) ) * (5.0 - 2.* x * 1.0) / (8.* 3.0) )) )"
00797                                   ,-10,10);
00798     mathiesonMS336->SetLineStyle(2);
00799     mathiesonMS336->SetLineColor(3);
00800     TF1 *mathiesonMS444 = new TF1("mathieson",
00801                                   " -1. / (2. * atan(sqrt([0]))) * (atan(sqrt([0]) *tanh(3.14159265 * (-2. + sqrt([0]) ) * (8.0 + 2.* x * 1.0) / (8.* 4.0) )) +  atan(sqrt([0]) *  tanh(3.14159265 * (-2. + sqrt([0]) ) * (8.0 - 2.* x * 1.0) / (8.* 4.0) )) )"
00802                                   ,-10,10);
00803     mathiesonMS444->SetLineStyle(2);
00804     mathiesonMS444->SetLineColor(3);
00805     TF1 *gausFit = new TF1("gausFit","gaus",20,50);
00806     TF1 *sigmaFit = new TF1("sigmaFit","gaus",-10,10);
00807     TF1 *alignmentFit= new TF1("alignmentFit","[0]*x+[1]",0,60);
00808     // Histogramms
00809     TString name, title;
00810 
00811     //TH1D* hCompensatedAll[usedSusibos];
00812     TH2F* Ch1_Pb = new TH2F("Ch1_Pb","good PID Ch1_Pb",2000,0,4000,2000,0,4000);
00813     Ch1_Pb->SetXTitle("Cherenkov 1 [a.u.]");
00814     Ch1_Pb->SetYTitle("Pb-glass calorimeter [a.u.]");
00815     Ch1_Pb->SetContour(99);
00816 
00817     TH2F* noCh1_Pb = new TH2F("noCh1_Pb","no good PID Ch1_Pb",2000,0,4000,2000,0,4000);
00818     noCh1_Pb->SetXTitle("Cherenkov 1 [a.u.]");
00819     noCh1_Pb->SetYTitle("Pb-glass calorimeter [a.u.]");
00820     noCh1_Pb->SetContour(99);
00821 
00822     TH2F* Ch2_Pb = new TH2F("Ch2_Pb","good PID Ch2_Pb",2000,0,4000,2000,0,4000);
00823     Ch2_Pb->SetXTitle("Cherenkov 2 [a.u.]");
00824     Ch2_Pb->SetYTitle("Pb-glass calorimeter [a.u.]");
00825     Ch2_Pb->SetContour(99);
00826 
00827     TH2F* noCh2_Pb = new TH2F("noCh2_Pb","no good PID Ch2_Pb",2000,0,4000,2000,0,4000);
00828     noCh2_Pb->SetXTitle("Cherenkov 2 [a.u.]");
00829     noCh2_Pb->SetYTitle("Pb-glass calorimeter [a.u.]");
00830     noCh2_Pb->SetContour(99);
00831 
00832     TH2F* Ch1_Ch2 = new TH2F("Ch1_Ch2","good PID Ch1_Ch2",2000,0,4000,2000,0,4000);
00833     Ch1_Ch2->SetXTitle("Cherenkov 1 [a.u.]");
00834     Ch1_Ch2->SetYTitle("Cherenkov 2 [a.u.]");
00835     Ch1_Ch2->SetContour(99);
00836 
00837     TH2F* noCh1_Ch2 = new TH2F("noCh1_Ch2","no good PID Ch1_Ch2",2000,0,4000,2000,0,4000);
00838     noCh1_Ch2->SetXTitle("Cherenkov 1 [a.u.]");
00839     noCh1_Ch2->SetYTitle("Cherenkov 2 [a.u.]");
00840     noCh1_Ch2->SetContour(99);
00841 
00842     TH1D* preCompSpectraEl[usedSusibos][recoSets][nMerge][nFilter];
00843     TH1D* preCompSpectraPi[usedSusibos][recoSets][nMerge][nFilter];
00844     TH1I* hitTimeEl[usedSusibos];
00845     TH1I* hitTimePi[usedSusibos];
00846 
00847     TH2I* amplitudeCorr[usedSusibos][usedSusibos];
00848 
00849     TH1I* amplitudeSpectra[usedSusibos];
00850 
00851     TH1F* chaGain[usedSusibos];
00852 
00853     TProfile* pulseShapeEl[usedSusibos];
00854     TProfile* pulseShapePi[usedSusibos];
00855 
00856     TH1I* beamProfile[usedSusibos];
00857     TProfile* chamberAlignment[usedSusibos][usedSusibos]; 
00858 
00859     TH2D* prf[usedSusibos];
00860     TProfile* prfProfile[usedSusibos];
00861 
00862     TH1I *chaGainCalibSpectra[usedSusibos][NUM_SPADIC_CHA];
00863 
00864     for (Int_t suid = 0; suid < usedSusibos; suid++) {
00865       for (Int_t rs = 0; rs < recoSets; rs++) {
00866         for (Int_t imerge = 0; imerge < nMerge; imerge++) {
00867           for (Int_t ifilter = 0; ifilter < nFilter; ifilter++) {
00868             title.Form("preCompSpectra%sEl_%i_%s_%s",recoSetName[rs].Data(),usedSuId[suid],mergeName[imerge].Data(),filterName[ifilter].Data());
00869             name.Form("pre cleaned go4 output (%s) electron Sus%i (%s %s)",recoSetName[rs].Data(),usedSuId[suid],mergeName[imerge].Data(),filterName[ifilter].Data());
00870             preCompSpectraEl[suid][rs][imerge][ifilter] = new TH1D(title, name, NUM_SPADIC_CHA*SPADIC_TRACE_SIZE*SPADIC_ADC_MAX,0,NUM_SPADIC_CHA*SPADIC_TRACE_SIZE*SPADIC_ADC_MAX);
00871             preCompSpectraEl[suid][rs][imerge][ifilter]->SetXTitle("charge [a.u.]");
00872             preCompSpectraEl[suid][rs][imerge][ifilter]->SetYTitle("normalized counts");
00873             preCompSpectraEl[suid][rs][imerge][ifilter]->SetLineColor(2);
00874 
00875             title.Form("preCompSpectra%sPi_%i_%s_%s",recoSetName[rs].Data(),usedSuId[suid],mergeName[imerge].Data(),filterName[ifilter].Data());
00876             name.Form("pre cleaned go4 output (%s) pion Sus%i (%s %s)",recoSetName[rs].Data(),usedSuId[suid],mergeName[imerge].Data(),filterName[ifilter].Data());
00877             preCompSpectraPi[suid][rs][imerge][ifilter] = new TH1D(title, name, NUM_SPADIC_CHA*SPADIC_TRACE_SIZE*SPADIC_ADC_MAX,0,NUM_SPADIC_CHA*SPADIC_TRACE_SIZE*SPADIC_ADC_MAX);
00878             preCompSpectraPi[suid][rs][imerge][ifilter]->SetXTitle("charge [a.u.]");
00879             preCompSpectraPi[suid][rs][imerge][ifilter]->SetYTitle("normalized counts");
00880           }
00881         }
00882       }
00883       for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
00884         title.Form("chaGainCalibSpectraCh%i_%i",ch,usedSuId[suid]);
00885         name.Form("Channel Spectra Ch%i Sus%i",ch,usedSuId[suid]);
00886         chaGainCalibSpectra[suid][ch] = new TH1I(title, name, SPADIC_TRACE_SIZE*SPADIC_ADC_MAX+50,-50,SPADIC_TRACE_SIZE*SPADIC_ADC_MAX);
00887         chaGainCalibSpectra[suid][ch]->SetLineColor(ch+1);
00888       }
00889       for (Int_t suid2 = 0; suid2 < usedSusibos; suid2++) {
00890         title.Form("amplitudeCorr_%i_%i",usedSuId[suid],usedSuId[suid2]);
00891         name.Form("max amplitude correlation (Sus%i,Sus%i)",usedSuId[suid],usedSuId[suid2]);
00892         amplitudeCorr[suid][suid2] = new TH2I(title, name, SPADIC_ADC_MAX+50,-50,SPADIC_ADC_MAX, SPADIC_ADC_MAX+50,-50,SPADIC_ADC_MAX);
00893         amplitudeCorr[suid][suid2]->SetContour(99); 
00894 
00895         title.Form("chamberAlignment_%i_%i",usedSuId[suid],usedSuId[suid2]);
00896         name.Form("chamber alignment Sus%i Sus%i",usedSuId[suid],usedSuId[suid2]);
00897         chamberAlignment[suid][suid2] = new TProfile(title, name, NUM_SPADIC_CHA*padWidth[suid], 0-0.5, NUM_SPADIC_CHA*padWidth[suid]-0.5*padWidth[suid]);
00898         chamberAlignment[suid][suid2]->GetYaxis()->SetRangeUser(-(NUM_SPADIC_CHA-0.5)*padWidth[suid2],(NUM_SPADIC_CHA-0.5)*padWidth[suid2]);
00899       }
00900       title.Form("beamProfile_%i",usedSuId[suid]);
00901       name.Form("pad max distribution (beam profile) Sus%i",usedSuId[suid]);
00902       beamProfile[suid] = new TH1I(title, name, NUM_SPADIC_CHA, 0-0.5, NUM_SPADIC_CHA-0.5);
00903       beamProfile[suid]->SetXTitle("pad with maximum Q");
00904       beamProfile[suid]->SetYTitle("#");
00905       /*
00906         if (suid == usedSusibos-1) {
00907         title.Form("chamberAlignment_%i_%i",usedSuId[suid],usedSuId[0]);
00908         name.Form("chamber alignment Sus%i Sus%i",usedSuId[suid],usedSuId[0]);
00909         }
00910         else {
00911         title.Form("chamberAlignment_%i_%i",usedSuId[suid],usedSuId[suid+1]);
00912         name.Form("chamber alignment Sus%i Sus%i",usedSuId[suid],usedSuId[suid+1]);
00913         }
00914         chamberAlignment[suid] = new TProfile(title, name, NUM_SPADIC_CHA*padWidth[suid], 0-0.5, NUM_SPADIC_CHA*padWidth[suid]-0.5*padWidth[suid]);
00915         //printf("%f  %f  %f\n", NUM_SPADIC_CHA*padWidth[suid], 0-0.5, NUM_SPADIC_CHA*padWidth[suid]-0.5*padWidth[suid]);
00916         */
00917       title.Form("chaGain_%i",usedSuId[suid]);
00918       name.Form("channel gain pad max Sus%i",usedSuId[suid]);
00919       chaGain[suid] = new TH1F(title, name, NUM_SPADIC_CHA, 0-0.5, NUM_SPADIC_CHA-0.5);
00920 
00921       title.Form("amplitudeSpectra_%i",usedSuId[suid]);
00922       name.Form("amplitude spectra pad max Sus%i",usedSuId[suid]);
00923       amplitudeSpectra[suid] = new TH1I(title, name, SPADIC_ADC_MAX+50,-50,SPADIC_ADC_MAX);
00924 
00925       title.Form("hitTimeEl_%i",usedSuId[suid]);
00926       name.Form("hit time electron Sus%i",usedSuId[suid]);
00927       hitTimeEl[suid] = new TH1I(title, name, SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00928       hitTimeEl[suid]->SetXTitle("time-bin of maximum amplitude");
00929       hitTimeEl[suid]->SetYTitle("#");
00930       hitTimeEl[suid]->SetLineColor(2);
00931 
00932       title.Form("hitTimePi_%i",usedSuId[suid]);
00933       name.Form("hit time pion Sus%i",usedSuId[suid]);
00934       hitTimePi[suid] = new TH1I(title, name, SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00935       hitTimePi[suid]->SetXTitle("time-bin of maximum amplitude");
00936       hitTimePi[suid]->SetYTitle("#");
00937 
00938       title.Form("pulseShapeEl_%i",usedSuId[suid]);
00939       name.Form("pulse shape electron Sus%i",usedSuId[suid]);
00940       pulseShapeEl[suid] = new TProfile(title, name, SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00941       pulseShapeEl[suid]->SetLineColor(2);
00942       pulseShapeEl[suid]->GetYaxis()->SetRangeUser(-20,256);
00943       pulseShapeEl[suid]->SetXTitle("time-bin");
00944       pulseShapeEl[suid]->SetYTitle("average ADC-value");
00945 
00946       title.Form("pulseShapePi_%i",usedSuId[suid]);
00947       name.Form("pulse shape pion Sus%i",usedSuId[suid]);
00948       pulseShapePi[suid] = new TProfile(title, name, SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00949       pulseShapePi[suid]->GetYaxis()->SetRangeUser(-20,256);
00950       pulseShapePi[suid]->SetXTitle("time-bin");
00951       pulseShapePi[suid]->SetYTitle("average ADC-value");
00952 
00953       title.Form("PRF_%i",usedSuId[suid]);
00954       name.Form("PRF Sus%i",usedSuId[suid]);
00955       prf[suid] = new TH2D(title, name, 300, -1.5, 1.5, 100, 0, 1);
00956       prf[suid]->SetXTitle("relative pad charge");
00957       prf[suid]->SetYTitle("reco. hit position [pad units]");
00958       prf[suid]->SetContour(99); 
00959 
00960       title.Form("PRF_Profile%i",usedSuId[suid]);
00961       name.Form("PRF Profile Sus%i",usedSuId[suid]);
00962       prfProfile[suid] = new TProfile(title, name, 30 * padWidth[suid], -1.5 * padWidth[suid], 1.5 * padWidth[suid]);
00963       prfProfile[suid]->SetXTitle("relative pad charge");
00964       prfProfile[suid]->SetYTitle("reco. hit position [mm]");
00965     }
00966     TH1D *rawPulseA[NUM_SPADIC_CHA];
00967     TH1D *rawPulseB[NUM_SPADIC_CHA];
00968     TH1D *rawPulse[NUM_SPADIC_CHA];
00969     TH1D *baselinePulse[NUM_SPADIC_CHA];
00970     TH1D *baselinePulseA[NUM_SPADIC_CHA];
00971     TH1D *baselinePulseB[NUM_SPADIC_CHA];
00972     TH1D *baselineNoisePulse[NUM_SPADIC_CHA];
00973     TH1D *baselineNoisePulseA[NUM_SPADIC_CHA];
00974     TH1D *baselineNoisePulseB[NUM_SPADIC_CHA];
00975     //TString name;
00976     for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {     
00977       name.Form("Ch%02i",ch);
00978       rawPulseA[ch] = new TH1D("rawPulseA"+name,"rawPulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE); 
00979       rawPulseB[ch] = new TH1D("rawPulseB"+name,"rawPulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00980       rawPulse[ch] = new TH1D("rawPulse"+name,"rawPulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00981       baselinePulseA[ch] = new TH1D("baselinePulseA"+name,"baselinePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00982       baselinePulseB[ch] = new TH1D("baselinePulseB"+name,"baselinePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00983       baselinePulse[ch] = new TH1D("baselinePulse"+name,"baselinePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00984       baselineNoisePulseA[ch] = new TH1D("baselineNoisePulseA"+name,"baselineNoisePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00985       baselineNoisePulseB[ch] = new TH1D("baselineNoisePulseB"+name,"baselineNoisePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00986       baselineNoisePulse[ch] = new TH1D("baselineNoisePulse"+name,"baselineNoisePulse"+name,SPADIC_TRACE_SIZE,0,SPADIC_TRACE_SIZE);
00987     }
00988     while (fileSet.good()) {
00989       TString filename;
00990       fileSet >> filename;
00991       printf("  %s\n",filename.Data());
00992       if (filename.Sizeof() > 5) {
00993         TString ifname = filename;
00994         if(!ifname.EndsWith(".root")) ifname.Append(".root");
00995         //get_Pb_Ch_Cut(ifname);
00996  
00997         /*
00998           hCompensatedAll->GetYaxis()->SetRangeUser(-20,256);
00999           myc->cd();
01000           hCompensatedAll->Draw();
01001         */
01002         ifname = folder + filename;
01003         if(!ifname.EndsWith(".root")) ifname.Append(".root");
01004         TFile inputFile(ifname,"READ");
01005    
01006         TTree* theTree=0;
01007         TKey* kee=0;
01008         TIter iter(inputFile.GetListOfKeys());
01009         while ( ( kee=dynamic_cast<TKey*>(iter()) ) !=0 ) {
01010           theTree = dynamic_cast<TTree*>(kee->ReadObj());
01011           if (theTree)
01012             break; // we take first Tree in file, disregarding its name...
01013         }
01014         if(theTree==0) {
01015           cout <<"Error: no Tree in file "<< ifname.Data() << endl;
01016           return;
01017         }
01018   
01019 
01020 
01021         // Thresholds
01022         Double_t minAmplitude[usedSusibos] =      {        15,        15,        15,        15,        15,        15,        15,       15   };
01023         Int_t HitTimeWindow[usedSusibos][2] =     {   {13,20},   {13,20},   {13,20},   {13,20},   {13,20},   {13,20},   {13,20},   {13,20}  };
01024         Int_t IntegrationWindow[usedSusibos][2] = {   {14,22},   {14,22},   {14,22},   {14,22},   {14,22},   {14,22},   {14,22},   {14,22}  };
01025 
01026         Double_t dxPosmm[usedSusibos] = {0.0};
01027  
01028 
01029         TCernOct11UnpackEvent* evnt = new TCernOct11UnpackEvent;
01030         TGo4EventElement* theBase=evnt;
01031         evnt->synchronizeWithTree(theTree, &theBase);
01032         //evnt->synchronizeWithTree(theTree, &evnt);
01033 
01034         // with go4 4.4.x:
01035 
01036         // evnt->synchronizeWithTree(theTree);
01037         // theTree->SetBranchAddress(theTree->GetListOfBranches()->First()->GetName(), &evnt);
01038 
01039         Int_t entries = theTree->GetEntries();
01040         allEvents += entries;
01041         Int_t nPion[usedSusibos][nMerge] = {{0}};
01042         Int_t nElectron[usedSusibos][nMerge] = {{0}};
01043         Int_t nGoodEvents[usedSusibos][nMerge] = {{0}};
01044 
01045         TMbsCrateEvent* fCrateInputEvent;
01046         TSpadicEvent* SpadicInputEvent;
01047         TSpadicData* theSpadic;
01048         TSpadicData* theSpadicA;
01049         TSpadicData* theSpadicB;
01050         //MFSpadicEvent* theMFSpadic = new MFSpadicEvent();
01051         Float_t Ch1(0), Ch2(0), Pb(0);
01052         cout << "   " << entries << " Entries" << endl;
01053         if (debug) 
01054           entries = 10000;
01055         GetPidCuts(filename);
01056 
01057         for(Int_t i=0;i<entries;++i) {
01058           Statusbar(i,entries);
01059           theTree->GetEntry(i);
01060           fCrateInputEvent=dynamic_cast<TMbsCrateEvent*>(evnt->GetSubEvent("MBSCRATE"));    
01061           SpadicInputEvent=dynamic_cast<TSpadicEvent*>(evnt->GetSubEvent("SPADIC"));
01062           //int sid=2; // example: get spadic of id 1
01063   
01064           isPion = false;
01065           isElectron = false;
01066           isMyon = false;
01067 
01068           Ch1 = fCrateInputEvent->fData1182[1][0];
01069           Ch2 = fCrateInputEvent->fData1182[0][1];
01070           Pb  = fCrateInputEvent->fData1182[1][5];
01071           getPID( Ch1, Ch2, Pb);
01072           
01073           if (isPion || isElectron) {
01074             Ch1_Pb->Fill(Ch1,Pb);
01075             Ch2_Pb->Fill(Ch2,Pb);
01076           }
01077           if (!isPion && !isElectron) {
01078             noCh1_Pb->Fill(Ch1,Pb);
01079             noCh2_Pb->Fill(Ch2,Pb);
01080           }
01081           Double_t maxAmplitudeCorr[usedSusibos] = {0.0};
01082           for (Int_t suid = 0; suid < usedSusibos; suid++){
01083    
01084             theSpadic=dynamic_cast<TSpadicData*>(SpadicInputEvent->getEventElement(usedSuId[suid]));
01085             Double_t pulse[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {{0.0}};
01086             Bool_t signalChannel[NUM_SPADIC_CHA] = {false};
01087             Bool_t overFlow = theSpadic->fSpadicOverFlowEvent;//false;
01088             Bool_t underShoot = theSpadic->fSpadicUndershootsEvent;
01089             maxAmplitudeCorr[suid] = -40.0;
01090             dxPosmm[suid] = 0.0;
01091 
01092             for (Int_t imerge = 0; imerge < nMerge; imerge++) {
01093               msMerge = Bool_t(imerge);
01094               if (raw) {
01095                 if((suid < 4) && (msMerge)) {
01096                   theSpadicA = dynamic_cast<TSpadicData*>(SpadicInputEvent->getEventElement(usedSuId[suid]));
01097                   if(theSpadicA==0) continue; // skip not configured ones
01098                   if(!theSpadicA->IsValid()) continue; // required to suppress empty spadic data!
01099 
01100                   theSpadicB = dynamic_cast<TSpadicData*>(SpadicInputEvent->getEventElement(topSuId[suid]));
01101                   if(theSpadicB==0) continue; // skip not configured ones
01102                   if(!theSpadicB->IsValid()) continue; // required to suppress empty spadic data!
01103 
01104                   if (theSpadicA->fSpadicOverFlowEvent || theSpadicB->fSpadicOverFlowEvent) overFlow = true;
01105                   if (theSpadicA->fSpadicUndershootsEvent || theSpadicB->fSpadicUndershootsEvent) underShoot = true;
01106                   //MergeData(pulse, theSpadicA, theSpadicB);
01107 
01108                   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01109                     rawPulseA[ch]->Reset();
01110                     rawPulseB[ch]->Reset();
01111                     baselinePulseA[ch]->Reset();
01112                     baselinePulseB[ch]->Reset();
01113                     baselineNoisePulseA[ch]->Reset();
01114                     baselineNoisePulseB[ch]->Reset();
01115                     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {       
01116                       rawPulseA[ch]->Fill(bin, (Double_t)theSpadicA->fSpadicPulse[ch][bin]);
01117                       rawPulseB[ch]->Fill(bin, (Double_t)theSpadicB->fSpadicPulse[ch][bin]);
01118                       //pulseA[ch][bin] = theSpadicA->fSpadicPulse[ch][bin];
01119                       //pulseB[ch][bin] = theSpadicB->fSpadicPulse[ch][bin];
01120                     }
01121                   }
01122 
01123                   BaselineCompensation(rawPulseA, baselinePulseA);
01124                   NoiseReduction(baselinePulseA, baselineNoisePulseA, signalChannel);
01125 
01126                   BaselineCompensation(rawPulseB, baselinePulseB);
01127                   NoiseReduction(baselinePulseB, baselineNoisePulseB, signalChannel);
01128 
01129                   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {       
01130                     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
01131                       if (baselineNoisePulseA[ch]->GetBinContent(baselineNoisePulseA[ch]->FindBin(bin)) > 0)
01132                         pulse[ch][bin] = baselineNoisePulseA[ch]->GetBinContent(baselineNoisePulseA[ch]->FindBin(bin));//pulseA[ch][bin];
01133                       if (baselineNoisePulseB[7-ch]->GetBinContent(baselineNoisePulseB[7-ch]->FindBin(bin))) // channel remaping for MS top spadics
01134                         pulse[ch][bin] += baselineNoisePulseB[7-ch]->GetBinContent(baselineNoisePulseB[7-ch]->FindBin(bin));//pulseB[7-ch][bin];
01135                     }
01136                   }
01137                 }
01138                 else {
01139                   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01140                     rawPulse[ch]->Reset();
01141                     baselinePulse[ch]->Reset();
01142                     baselineNoisePulse[ch]->Reset();
01143                     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {       
01144                       rawPulse[ch]->Fill(bin, (Double_t)theSpadicA->fSpadicPulse[ch][bin]);// = theSpadic->fSpadicPulse[ch][bin];
01145                     }
01146                   }
01147                   BaselineCompensation(rawPulse, baselinePulse);
01148                   NoiseReduction(baselinePulse, baselineNoisePulse, signalChannel);
01149                   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {       
01150                     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {       
01151                       pulse[ch][bin] = baselineNoisePulse[ch]->GetBinContent(baselineNoisePulse[ch]->FindBin(bin));
01152                     }
01153                   }
01154                 }
01155               } 
01156               else {
01157                 if((suid < 4) && (msMerge)) {
01158                   theSpadicA = dynamic_cast<TSpadicData*>(SpadicInputEvent->getEventElement(usedSuId[suid]));
01159                   if(theSpadicA==0) continue; // skip not configured ones
01160                   if(!theSpadicA->IsValid()) continue; // required to suppress empty spadic data!
01161 
01162                   theSpadicB = dynamic_cast<TSpadicData*>(SpadicInputEvent->getEventElement(topSuId[suid]));
01163                   if(theSpadicB==0) continue; // skip not configured ones
01164                   if(!theSpadicB->IsValid()) continue; // required to suppress empty spadic data!
01165 
01166                   if (theSpadicA->fSpadicOverFlowEvent || theSpadicB->fSpadicOverFlowEvent) overFlow = true;
01167                   if (theSpadicA->fSpadicUndershootsEvent || theSpadicB->fSpadicUndershootsEvent) underShoot = true;
01168                   //MergeData(pulse, theSpadicA, theSpadicB);
01169                   Double_t pulseA[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {{0.0}};
01170                   Double_t pulseB[NUM_SPADIC_CHA][SPADIC_TRACE_SIZE] = {{0.0}};
01171         
01172                   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {       
01173                     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {       
01174                       pulseA[ch][bin] = theSpadicA->fSpadicCompensated[ch][bin];
01175                       pulseB[ch][bin] = theSpadicB->fSpadicCompensated[ch][bin];
01176                       if (theSpadicA->fSpadicSignalCh[ch] || theSpadicB->fSpadicSignalCh[ch])
01177                         signalChannel[ch] = true;;
01178                     }
01179                   }
01180                   BaselineCorrection(pulseA);
01181                   BaselineCorrection(pulseB);
01182                   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {       
01183                     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
01184                       if (pulseA[ch][bin] > 0)
01185                         pulse[ch][bin] = pulseA[ch][bin];
01186                       if (pulseB[7-ch][bin] > 0) // channel remaping for MS top spadics
01187                         pulse[ch][bin] += pulseB[7-ch][bin];
01188                     }
01189                   }          
01190                 }
01191                 else{
01192                   //CopyData(pulse, theSpadic);
01193                   for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {       
01194                     for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {       
01195                       pulse[ch][bin] = theSpadic->fSpadicCompensated[ch][bin];
01196                       signalChannel[ch] = theSpadic->fSpadicSignalCh[ch];
01197                     }
01198                   }
01199                   BaselineCorrection(pulse);
01200                 }
01201               }
01202 
01203               if(theSpadic==0) continue; // skip not configured ones
01204               if(!theSpadic->IsValid()) continue; // required to suppress empty spadic data!
01205 
01206 
01207               //if (overFlow || underShoot) continue; // skip fragmented signals
01208 
01209               // Find pad with maximum signal
01210               Double_t maxAmplitude = 0.0;
01211               Double_t maxAmplitudeCh[NUM_SPADIC_CHA] = {0.0};
01212               Int_t maxCh = -1;
01213               Int_t maxTB[NUM_SPADIC_CHA] = {-1};
01214 
01215               //cout << " - - - - - - - - " << endl;
01216               /*
01217                 for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01218                 //cout << endl;
01219                 Float_t baseline(0);    
01220                 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {   
01221                 pulse[ch][bin] = theSpadic->fSpadicCompensated[ch][bin];
01222                 //cout << pulse[ch][bin] << " ";
01223                 if (bin < noBaselineTB)
01224                 baseline += pulse[ch][bin];
01225                 }
01226                 baseline /= Float_t(noBaselineTB);
01227                 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {   
01228                 pulse[ch][bin] -= baseline;
01229                 }
01230                 }
01231               */
01232 
01233               for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {   
01234                 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
01235                   if (theSpadic->fSpadicOverflows[ch][bin])
01236                     overFlow = true;
01237                   if (pulse[ch][bin] > maxAmplitudeCh[ch]){
01238                     maxAmplitudeCh[ch] = pulse[ch][bin];
01239                     maxTB[ch] = bin;
01240                   }
01241                 }
01242                 if(maxAmplitudeCh[ch] > maxAmplitude){
01243                   maxAmplitude = maxAmplitudeCh[ch];
01244                   maxCh = ch;
01245                 }
01246               }
01247               if (!msMerge){
01248                 if (maxCh != -1) {
01249                   maxAmplitudeCorr[suid] = pulse[maxCh][maxTB[maxCh]];
01250                   amplitudeSpectra[suid]->Fill(pulse[maxCh][maxTB[maxCh]]);
01251                   chaGainCalibSpectra[suid][maxCh]->Fill(pulse[maxCh][maxTB[maxCh]]);
01252                   //for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {     
01253                   //  chaGainCalibSpectra[suid][ch]->Fill(pulse[ch][maxTB[maxCh]]);
01254                   //}
01255                 }
01256                 else {
01257                   if (debug) printf("\n    <<<<< found no pad max\n");
01258                 }
01259               }
01260               if (isElectron){
01261                 hitTimeEl[suid]->Fill(maxTB[maxCh]);
01262               }
01263               if (isPion){
01264                 hitTimePi[suid]->Fill(maxTB[maxCh]);
01265               }
01266               if (debug) {
01267                 if (overFlow != theSpadic->fSpadicOverFlowEvent)
01268                   cout << "wrong overflow" << endl;
01269             
01270                 if (maxCh != theSpadic->fSpadicHighestChannel)
01271                   cout << "online: " << theSpadic->fSpadicHighestChannel <<  "  maxA: " << maxAmplitudeCh[theSpadic->fSpadicHighestChannel]<< "  offline: " << maxCh <<  "  maxA: " << maxAmplitudeCh[maxCh] << endl;
01272               }
01273               if (maxCh < 1 || maxCh > 6)  continue; // skip fragmented signals
01274 
01275               // calc signal integral
01276               Double_t amplCluster(0), ampl3Pad(0), ampl1Pad(0);
01277               Double_t intensCluster(0), intens3Pad(0), intens1Pad(0), intensClusterTBW(0), intens3PadTBW(0), intens1PadTBW(0);
01278               Double_t intensCh[NUM_SPADIC_CHA] = {0.0};
01279               for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01280                 for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
01281                   if (pulse[ch][bin] > 0.0) {
01282                     intensCh[ch] +=  pulse[ch][bin];
01283                     if(signalChannel[ch]/*theSpadic->fSpadicSignalCh[ch]*/){
01284                       intensCluster += pulse[ch][bin];
01285                       if (bin > IntegrationWindow[suid][0] && bin < IntegrationWindow[suid][1])
01286                         intensClusterTBW += pulse[ch][bin];
01287                     }
01288                     if (ch == maxCh){
01289                       intens1Pad += pulse[ch][bin];
01290                       if (bin > IntegrationWindow[suid][0] && bin < IntegrationWindow[suid][1])
01291                         intens3PadTBW += pulse[ch][bin];
01292                     }
01293                     if (ch <= maxCh+1 && ch >= maxCh-1){
01294                       intens3Pad += pulse[ch][bin];
01295                       if (bin > IntegrationWindow[suid][0] && bin < IntegrationWindow[suid][1])
01296                         intens1PadTBW += pulse[ch][bin];
01297                     }
01298                   }
01299                 }
01300                 if (pulse[ch][maxTB[maxCh]] > 0.0) {
01301                   if(signalChannel[ch]/*theSpadic->fSpadicSignalCh[ch]*/)
01302                     amplCluster += pulse[ch][maxTB[maxCh]];
01303                   if (ch == maxCh)
01304                     ampl1Pad += pulse[ch][maxTB[maxCh]];
01305                   if (ch <= maxCh+1 && ch >= maxCh-1)
01306                     ampl3Pad += pulse[ch][maxTB[maxCh]];
01307                   /*
01308                     if(theSpadic->fSpadicSignalCh[ch])
01309                     amplCluster += maxAmplitudeCh[ch];
01310                     if (ch == maxCh)
01311                     ampl1Pad += maxAmplitudeCh[ch];
01312                     if (ch <= maxCh+1 && ch >= maxCh-1)
01313                     ampl3Pad += maxAmplitudeCh[ch];
01314                   */
01315                 }               
01316               }
01317               // fill histos after cuts
01318               if (maxTB[maxCh] > HitTimeWindow[suid][0] && maxTB[maxCh] < HitTimeWindow[suid][1]){
01319                 if (maxAmplitude > minAmplitude[suid]) {
01320 
01321                   if (imerge == 0) {
01322                     beamProfile[suid]->Fill(maxCh);
01323                     if (maxCh >= 1 && maxCh <= NUM_SPADIC_CHA - 1){
01324                       if (intensCh[maxCh-1] > 0.0 && intensCh[maxCh] > 0.0 && intensCh[maxCh+1] > 0.0) {
01325                         Double_t dxPos = 0.5 * log((intensCh[maxCh+1] / intensCh[maxCh-1])) / log((pow(intensCh[maxCh],2) / (intensCh[maxCh+1] * intensCh[maxCh-1])));
01326                         dxPosmm[suid] = dxPos * padWidth[suid] + maxCh * padWidth[suid];
01327                         Double_t chargePercent = intensCh[maxCh-1] / (intensCh[maxCh-1] + intensCh[maxCh] + intensCh[maxCh+1]);
01328                         prf[suid]->Fill(-dxPos-1,chargePercent);
01329                         prfProfile[suid]->Fill((-dxPos-1) * padWidth[suid],chargePercent);
01330                         chargePercent = intensCh[maxCh] / (intensCh[maxCh-1] + intensCh[maxCh] + intensCh[maxCh+1]);
01331                         prf[suid]->Fill(dxPos,chargePercent);
01332                         prfProfile[suid]->Fill(dxPos * padWidth[suid],chargePercent);
01333                         chargePercent = intensCh[maxCh+1] / (intensCh[maxCh-1] + intensCh[maxCh] + intensCh[maxCh+1]);
01334                         prf[suid]->Fill(-dxPos+1,chargePercent);
01335                         prfProfile[suid]->Fill((-dxPos+1) * padWidth[suid],chargePercent);
01336                       }
01337                     } 
01338                   }
01339 
01340                   for (Int_t bin = 0; bin < SPADIC_TRACE_SIZE; bin++) {
01341                     if (isElectron){
01342                       pulseShapeEl[suid]->Fill(bin,pulse[maxCh][bin]);
01343                     }
01344                     if (isPion){
01345                       pulseShapePi[suid]->Fill(bin,pulse[maxCh][bin]);
01346                     }
01347                   }
01348                   for (Int_t ifilter = 0; ifilter < nFilter; ifilter++) { //{"wOwU","woOwU","woOwoU","wOwoU"}
01349                     if ((ifilter == 0 ) ||
01350                         (ifilter == 1 && !overFlow) ||
01351                         (ifilter == 2 && !overFlow && !underShoot) ||
01352                         (ifilter == 3 && !underShoot)
01353                         ) {
01354                       if (ifilter == 0 )
01355                         nGoodEvents[suid][imerge]++;
01356                       if (isElectron){
01357                         preCompSpectraEl[suid][0][imerge][ifilter]->Fill(intensCluster);
01358                         preCompSpectraEl[suid][1][imerge][ifilter]->Fill(intens3Pad);
01359                         preCompSpectraEl[suid][2][imerge][ifilter]->Fill(intens1Pad);
01360                         preCompSpectraEl[suid][3][imerge][ifilter]->Fill(intensClusterTBW);
01361                         preCompSpectraEl[suid][4][imerge][ifilter]->Fill(intens3PadTBW);
01362                         preCompSpectraEl[suid][5][imerge][ifilter]->Fill(intens1PadTBW);                  
01363                         preCompSpectraEl[suid][6][imerge][ifilter]->Fill(amplCluster);
01364                         preCompSpectraEl[suid][7][imerge][ifilter]->Fill(ampl3Pad);
01365                         preCompSpectraEl[suid][8][imerge][ifilter]->Fill(ampl1Pad);
01366                         if (ifilter == 0 )
01367                           nElectron[suid][imerge]++;
01368                       }
01369                       if (isPion){
01370                         preCompSpectraPi[suid][0][imerge][ifilter]->Fill(intensCluster);
01371                         preCompSpectraPi[suid][1][imerge][ifilter]->Fill(intens3Pad);
01372                         preCompSpectraPi[suid][2][imerge][ifilter]->Fill(intens1Pad);
01373                         preCompSpectraPi[suid][3][imerge][ifilter]->Fill(intensClusterTBW);
01374                         preCompSpectraPi[suid][4][imerge][ifilter]->Fill(intens3PadTBW);
01375                         preCompSpectraPi[suid][5][imerge][ifilter]->Fill(intens1PadTBW);
01376                         preCompSpectraPi[suid][6][imerge][ifilter]->Fill(amplCluster);
01377                         preCompSpectraPi[suid][7][imerge][ifilter]->Fill(ampl3Pad);
01378                         preCompSpectraPi[suid][8][imerge][ifilter]->Fill(ampl1Pad);
01379                         if (ifilter == 0 )
01380                           nPion[suid][imerge]++;
01381                       }
01382                     }
01383                   }
01384                 } // if minimum amplitude threshold
01385               } // if hit time window
01386             } // for merge
01387           } // for suid
01388 
01389           Double_t distance[usedSusibos] = {0.0};
01390           //Distance2Track(dxPosmm, distance);
01391 
01392           Bool_t trackfoundMS = Distance2TrackMS(dxPosmm, distance/*, m, b*/);
01393           Bool_t trackfoundFFM = Distance2TrackFFM(dxPosmm, distance/*, m, b*/);
01394 
01395           Int_t MShitCount(0), FFMhitCount(0);
01396           for (Int_t suid = 0; suid < usedSusibos; suid++) {
01397             if (dxPosmm[suid] != 0.0){
01398               if (suid < 4)
01399                 MShitCount++;
01400               else
01401                 FFMhitCount++;
01402             }
01403           }
01404           for (Int_t suid = 0; suid < usedSusibos; suid++) {
01405             /*
01406               if (suid == usedSusibos-1) {
01407               chamberAlignment[suid]->Fill(dxPosmm[suid],dxPosmm[suid]-dxPosmm[suid]);
01408               //chamberAlignment2D[suid]->Fill(dxPosmm[suid],dxPosmm[suid]-dxPosmm[0]);
01409               }
01410               else {
01411               chamberAlignment[suid]->Fill(dxPosmm[suid],dxPosmm[suid]-dxPosmm[suid+1]);
01412               //chamberAlignment2D[suid]->Fill(dxPosmm[suid],dxPosmm[suid]-dxPosmm[suid+1]);
01413               }
01414             */
01415             for (Int_t suid2 = 0; suid2 < usedSusibos; suid2++) {
01416               if (dxPosmm[suid] > 0.0 && dxPosmm[suid2] > 0.0) {
01417                 if (suid == suid2) {    
01418                   //if (debug) printf("%i   %.4f \n",suid,distance[suid]);
01419                   if(suid < 4){
01420                     if (trackfoundMS) {
01421                       chamberAlignment[suid][suid2]->Fill(dxPosmm[suid],distance[suid]);
01422                     }
01423                   }
01424                   else {
01425                     if (trackfoundFFM) {
01426                       chamberAlignment[suid][suid2]->Fill(dxPosmm[suid],distance[suid]);
01427                     }
01428                   }
01429                 }
01430                 else {
01431                   //if (suid < 4 && suid2 < 4){
01432                   //if (hitCount == 4){
01433                   chamberAlignment[suid][suid2]->Fill(dxPosmm[suid],dxPosmm[suid]-dxPosmm[suid2]);
01434                   //}
01435                   //}
01436                   //else {
01437                   //chamberAlignment[suid][suid2]->Fill(dxPosmm[suid],dxPosmm[suid]-dxPosmm[suid2]);
01438                   //}
01439                   if (debug) printf("  %.2f  %.2f  %.2f\n",dxPosmm[suid],dxPosmm[suid2],dxPosmm[suid]-dxPosmm[suid2]);
01440                 }
01441               }
01442               amplitudeCorr[suid][suid2]->Fill(maxAmplitudeCorr[suid],maxAmplitudeCorr[suid2]);
01443             }
01444           }
01445 
01446 
01447         } // for tree entries
01448 
01449         for (Int_t suid = 0; suid < usedSusibos; suid++){
01450           printf("   Susibo%3i    %6i [%6i] electrons (%4.1f%%) [(%4.1f%%)]   %6i [%6i] pions (%4.1f%%) [(%4.1f%%)]   %6i [%6i] good events (%4.1f%%) [(%4.1f%%)]\n"
01451                  ,usedSuId[suid]
01452                  ,nElectron[suid][0],nElectron[suid][1],Float_t(nElectron[suid][0]*100)/entries,Float_t(nElectron[suid][1]*100)/entries
01453                  ,nPion[suid][0],nPion[suid][1],Float_t(nPion[suid][0]*100)/entries,Float_t(nPion[suid][1]*100)/entries
01454                  ,nElectron[suid][0]+nPion[suid][0],nElectron[suid][1]+nPion[suid][1],Float_t((nGoodEvents[suid][0])*100)/entries,Float_t((nGoodEvents[suid][1])*100)/entries
01455                  );
01456           for (Int_t imerge = 0; imerge < nMerge; imerge++) {
01457             allElectron[suid][imerge] += nElectron[suid][imerge];
01458             allPion[suid][imerge] += nPion[suid][imerge];
01459             allGoodEvent[suid][imerge] += nGoodEvents[suid][imerge];
01460           }
01461         }
01462         cout <<"*** DONE."<< endl;
01463  
01464         inputFile.Close();
01465       }
01466     } // while dataset is open
01467     
01468     Int_t c_x(1680*4), c_y(1050*4);
01469     if (debug){
01470       c_x /= 2;
01471       c_y /= 2;
01472     }
01473 
01474     TCanvas* cSpectra = new TCanvas("Spectra","Spectra",c_x,c_y);
01475     TCanvas* cRest = new TCanvas("Rest","Rest",c_x,c_x);
01476     TCanvas* cBeamMonitor = new TCanvas("BeamMonitor","Beam Monitor",c_x/8,c_y/8);
01477     TCanvas* cACorr = new TCanvas("cACorr","cACorr",c_x,c_y);
01478     TCanvas* cPCorr = new TCanvas("cPCorr","cPCorr",c_x,c_y);
01479 
01480     cSpectra->Divide(usedSusibos,recoSets);
01481     cRest->Divide(usedSusibos,12);
01482     cBeamMonitor->Divide(2,2);
01483     cACorr->Divide(usedSusibos,usedSusibos);
01484     cPCorr->Divide(usedSusibos,usedSusibos);
01485 
01486     cBeamMonitor->cd(1);
01487     Ch1_Pb->DrawCopy("colz");
01488     cBeamMonitor->cd(3);
01489     Ch2_Pb->DrawCopy("colz");
01490     cBeamMonitor->cd(2);
01491     noCh1_Pb->DrawCopy("colz");
01492     cBeamMonitor->cd(4);
01493     noCh2_Pb->DrawCopy("colz");  
01494     cBeamMonitor->Update();
01495 
01496     for (Int_t suid = 0; suid < usedSusibos; suid++) {
01497       for (Int_t suid2 = 0; suid2 < usedSusibos; suid2++) {
01498         cACorr->cd(suid2*usedSusibos+suid+1)->SetLogz(1);
01499         amplitudeCorr[suid][suid2]->DrawCopy("colz");
01500         outputFile.cd();
01501         amplitudeCorr[suid][suid2]->Write("", TObject::kOverwrite);
01502 
01503         cPCorr->cd(suid2*usedSusibos+suid+1);
01504         chamberAlignment[suid][suid2]->DrawCopy();
01505         chamberAlignment[suid][suid2]->Fit("alignmentFit","Q","0",0.25*NUM_SPADIC_CHA*padWidth[suid],0.75*NUM_SPADIC_CHA*padWidth[suid]);
01506         alignmentFit->SetLineColor(2);
01507         alignmentFit->DrawCopy("same");
01508         chamberAlignment[suid][suid2]->DrawCopy("same");
01509         chamberAlignment[suid][suid2]->Write("", TObject::kOverwrite);
01510       }
01511     }
01512 
01513     outputFile.cd();
01514     Ch1_Pb->Write("", TObject::kOverwrite);
01515     noCh1_Pb->Write("", TObject::kOverwrite);
01516     Ch2_Pb->Write("", TObject::kOverwrite);
01517     noCh2_Pb->Write("", TObject::kOverwrite);
01518     cBeamMonitor->Write("", TObject::kOverwrite);
01519     cACorr->Write("", TObject::kOverwrite);
01520     cPCorr->Write("", TObject::kOverwrite);
01521 
01522     Double_t MeanElectronSpectra(0), MeanPionSpectra(0);
01523     TLatex EP_Ratio;
01524     TString EP_temp;
01525     EP_Ratio.SetTextSize(0.04);
01526     TLegend* leg[usedSusibos][recoSets][nMerge][nFilter];
01527     Int_t x_max = 15000;
01528     Int_t rBin = 1;
01529     //Float_t x_pos(0.5), y_pos(0.75);
01530     for (Int_t imerge = 0; imerge < nMerge; imerge++) {
01531       for (Int_t ifilter = 0; ifilter < nFilter; ifilter++) {
01532         for (Int_t suid = 0; suid < usedSusibos; suid++){  
01533           for (Int_t rs = 0; rs < recoSets; rs++) {  
01534             if (rs > 5 && rs < recoSets){
01535               x_max = 1000;
01536               //rBin = 2;
01537             }
01538             else
01539               {
01540                 x_max = 15000;
01541                 //rBin = 17;
01542               }
01543             leg[suid][rs][imerge][ifilter] = new TLegend(0.5,0.6,0.85,0.85);
01544             leg[suid][rs][imerge][ifilter]->SetLineColor(0);
01545             leg[suid][rs][imerge][ifilter]->SetLineStyle(0);
01546             leg[suid][rs][imerge][ifilter]->SetFillColor(0);
01547             leg[suid][rs][imerge][ifilter]->SetFillStyle(0);
01548             leg[suid][rs][imerge][ifilter]->SetTextSize(0.035);
01549 
01550             preCompSpectraEl[suid][rs][imerge][ifilter]->Scale(1./Float_t(preCompSpectraEl[suid][rs][imerge][ifilter]->GetEntries()));
01551             preCompSpectraEl[suid][rs][imerge][ifilter]->Rebin(rBin);
01552             if (preCompSpectraEl[suid][rs][imerge][ifilter]->GetEntries() > 0)
01553               MeanElectronSpectra = preCompSpectraEl[suid][rs][imerge][ifilter]->GetMean(1);
01554 
01555             preCompSpectraPi[suid][rs][imerge][ifilter]->Scale(1./Float_t(preCompSpectraPi[suid][rs][imerge][ifilter]->GetEntries()));
01556             preCompSpectraPi[suid][rs][imerge][ifilter]->Rebin(rBin);
01557             if (preCompSpectraPi[suid][rs][imerge][ifilter]->GetEntries() > 0)
01558               MeanPionSpectra = preCompSpectraPi[suid][rs][imerge][ifilter]->GetMean(1);
01559 
01560             preCompSpectraEl[suid][rs][imerge][ifilter]->GetXaxis()->SetRangeUser(1,x_max);
01561             preCompSpectraPi[suid][rs][imerge][ifilter]->GetXaxis()->SetRangeUser(1,x_max);
01562             EP_temp.Form("#LTe^{-}#GT = %.3f",MeanElectronSpectra);
01563             leg[suid][rs][imerge][ifilter]->AddEntry(preCompSpectraEl[suid][rs][imerge][ifilter],EP_temp,"l");
01564             EP_temp.Form("#LT#pi^{-}#GT = %.3f",MeanPionSpectra);
01565             leg[suid][rs][imerge][ifilter]->AddEntry(preCompSpectraPi[suid][rs][imerge][ifilter],EP_temp,"l");
01566             if (MeanPionSpectra != 0)
01567               EP_temp.Form("#LTe^{-}#GT/#LT#pi^{-}#GT = %.3f",MeanElectronSpectra/MeanPionSpectra);
01568             else
01569               EP_temp.Form("#LTe^{-}#GT/#LT#pi^{-}#GT = %.3f",0.0);
01570             leg[suid][rs][imerge][ifilter]->AddEntry((TObject*)0,EP_temp,"");
01571             if (debug) printf("        %s  %s\n",recoSetName[rs].Data(),EP_temp.Data());
01572             if (preCompSpectraEl[suid][rs][imerge][ifilter]->GetEntries() > 0 &&  preCompSpectraPi[suid][rs][imerge][ifilter]->GetEntries() > 0) {
01573               cSpectra->cd(rs * usedSusibos + suid + 1);
01574               preCompSpectraPi[suid][rs][imerge][ifilter]->DrawCopy();
01575               preCompSpectraEl[suid][rs][imerge][ifilter]->DrawCopy("same");
01576               leg[suid][rs][imerge][ifilter]->Draw("same");
01577             }
01578           }
01579         }
01580         cSpectra->Update();
01581         cSpectra->SaveAs("data2011/Analysis/Pics/Spectra_" + TString(nameFileSet(0,nameFileSet.Sizeof()-5)) + "_" + mergeName[imerge] + "_" + filterName[ifilter] + /*picEx*/".png");
01582         cSpectra->Write(TString("Spectra_" + TString(nameFileSet(0,nameFileSet.Sizeof()-5)) + "_" + mergeName[imerge] + "_" + filterName[ifilter]), TObject::kOverwrite);
01583       }
01584     }
01585     TLegend *lPRF[usedSusibos];
01586     for (Int_t suid = 0; suid < usedSusibos; suid++){  
01587       lPRF[suid] = new TLegend(0.5,0.7,0.95,0.95);
01588       cRest->cd(1+suid);
01589       pulseShapeEl[suid]->DrawCopy();
01590       pulseShapePi[suid]->DrawCopy("same");
01591       cRest->cd(9+suid);
01592       hitTimePi[suid]->DrawCopy();
01593       hitTimeEl[suid]->DrawCopy("same");
01594       cRest->cd(17+suid)->SetLogy(1);
01595       amplitudeSpectra[suid]->DrawCopy();
01596       cRest->cd(25+suid);
01597       prf[suid]->DrawCopy("colz");
01598       cRest->cd(33+suid);
01599       prfProfile[suid]->GetYaxis()->SetRangeUser(0,1);
01600       prfProfile[suid]->DrawCopy();
01601       prfProfile[suid]->Fit("sigmaFit","RQ0");
01602       TString sl;
01603       sl.Form("#sigma = %f",sigmaFit->GetParameter(2));
01604       lPRF[suid]->AddEntry(sigmaFit,sl,"lep");
01605       if (suid >= 0 && suid < 2) {
01606         prfProfile[suid]->Fit("mathiesonMS336","RQ0");
01607         sl.Form("K_{3} = %f",mathiesonMS336->GetParameter(0));
01608       }
01609       if (suid >= 2 && suid < 4) {
01610         prfProfile[suid]->Fit("mathiesonMS444","RQ0");
01611         sl.Form("K_{3} = %f",mathiesonMS444->GetParameter(0));
01612       }      
01613       lPRF[suid]->AddEntry(prfProfile[suid],sl,"lep");
01614       sigmaFit->SetLineColor(2);
01615       sigmaFit->DrawCopy("same");
01616       if (suid < 4)
01617         prfProfile[suid]->DrawCopy("same");
01618       prfProfile[suid]->DrawCopy("same");
01619       lPRF[suid]->Draw("same");
01620       cRest->cd(41+suid);
01621       Int_t suid2min;     
01622       if (suid < 4) {
01623         suid2min = 0;
01624       }
01625       else {
01626         suid2min = 4;
01627       }
01628       Int_t suid2max = suid2min + 4;
01629       for (Int_t suid2 = suid2min; suid2 < suid2max; suid2++){
01630         preCompSpectraPi[suid2][1][0][0]->SetLineColor(suid2+1);
01631         preCompSpectraPi[suid2][1][0][0]->GetXaxis()->SetRangeUser(0,6000);
01632         if (suid == suid2)
01633           preCompSpectraPi[suid2][1][0][0]->SetLineStyle(2);
01634         if (suid2 == 0)
01635           preCompSpectraPi[suid2][1][0][0]->DrawCopy();
01636         else 
01637           preCompSpectraPi[suid2][1][0][0]->DrawCopy("same");
01638         preCompSpectraPi[suid2][1][0][0]->SetLineColor(1);
01639         preCompSpectraPi[suid2][1][0][0]->SetLineStyle(1);
01640         preCompSpectraPi[suid2][1][0][0]->GetXaxis()->SetRangeUser(1,x_max);
01641       }
01642       cRest->cd(49+suid)->SetLogy(1);
01643       for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01644         chaGainCalibSpectra[suid][ch]->GetXaxis()->SetRangeUser(-50,255);
01645         if (ch == 0)
01646           chaGainCalibSpectra[suid][ch]->DrawCopy();
01647         else
01648           chaGainCalibSpectra[suid][ch]->DrawCopy("same");
01649 
01650         chaGainCalibSpectra[suid][ch]->Fit("gausFit","RQ0");
01651         gausFit->DrawCopy("same");
01652         chaGain[suid]->Fill(ch, gausFit->GetParameter(1));
01653       }
01654       cRest->cd(57+suid);
01655       chaGain[suid]->DrawCopy();
01656   
01657       cRest->cd(65+suid);
01658       beamProfile[suid]->DrawCopy();
01659 
01660       cRest->cd(73+suid);
01661       /*
01662         chamberAlignment[suid]->DrawCopy();
01663         chamberAlignment[suid]->Fit("alignmentFit","RQ0");
01664         alignmentFit->DrawCopy("same");
01665       */
01666       cRest->Update();      
01667     
01668 
01669       //-------------------------------------------------------------------------------  write to file
01670       outputFile.cd();
01671 
01672       for (Int_t ch = 0; ch < NUM_SPADIC_CHA; ch++) {
01673         chaGainCalibSpectra[suid][ch]->Write("", TObject::kOverwrite);
01674       }
01675    
01676       for (Int_t rs = 0; rs < recoSets; rs++) {
01677         for (Int_t imerge = 0; imerge < nMerge; imerge++) {
01678           for (Int_t ifilter = 0; ifilter < nFilter; ifilter++) {
01679             preCompSpectraEl[suid][rs][imerge][ifilter]->Write("", TObject::kOverwrite);
01680             preCompSpectraPi[suid][rs][imerge][ifilter]->Write("", TObject::kOverwrite);   
01681           }
01682         }
01683       }
01684     
01685 
01686       beamProfile[suid]->Write("", TObject::kOverwrite);
01687 
01688       chaGain[suid]->Write("", TObject::kOverwrite);
01689 
01690       amplitudeSpectra[suid]->Write("", TObject::kOverwrite);
01691 
01692       pulseShapeEl[suid]->Write("", TObject::kOverwrite);
01693       pulseShapePi[suid]->Write("", TObject::kOverwrite);
01694 
01695       hitTimeEl[suid]->Write("", TObject::kOverwrite);
01696       hitTimePi[suid]->Write("", TObject::kOverwrite);
01697 
01698       prf[suid]->Write("", TObject::kOverwrite);
01699       prfProfile[suid]->Write("", TObject::kOverwrite);
01700       cRest->Write("", TObject::kOverwrite);
01701       
01702       printf("         Susibo%3i    %6i [%6i] electrons (%4.1f%%) [(%4.1f%%)]   %6i [%6i] pions (%4.1f%%) [(%4.1f%%)]   %6i [%6i] good events (%4.1f%%) [(%4.1f%%)]\n"
01703              ,usedSuId[suid]
01704              ,allElectron[suid][0],allElectron[suid][1],Float_t(allElectron[suid][0]*100)/allEvents,Float_t(allElectron[suid][1]*100)/allEvents
01705              ,allPion[suid][0],allPion[suid][1],Float_t(allPion[suid][0]*100)/allEvents,Float_t(allPion[suid][1]*100)/allEvents
01706              ,allPion[suid][0]+allElectron[suid][0],allPion[suid][1]+allElectron[suid][1],Float_t((allGoodEvent[suid][0])*100)/allEvents,Float_t((allGoodEvent[suid][1])*100)/allEvents
01707              );
01708 
01709      
01710       
01711     } // for suid
01712     
01713       //------------------------------------------------------------------------------- save figures
01714     cBeamMonitor->SaveAs("data2011/Analysis/Pics/BeamMonitor_" + TString(nameFileSet(0,nameFileSet.Sizeof()-5)) + picEx);
01715   
01716     cRest->SaveAs("data2011/Analysis/Pics/Rest_" + TString(nameFileSet(0,nameFileSet.Sizeof()-5)) + /*picEx*/".png");
01717 
01718     cACorr->SaveAs("data2011/Analysis/Pics/ACorr_" + TString(nameFileSet(0,nameFileSet.Sizeof()-5)) + /*picEx*/".png");
01719 
01720     cPCorr->SaveAs("data2011/Analysis/Pics/PR/PCorr_" + TString(nameFileSet(0,nameFileSet.Sizeof()-5)) + /*picEx*/".png");
01721 
01722     //cChaGainCal->SaveAs("data2011/Analysis/Pics/Gain_" + TString(nameFileSet(0,nameFileSet.Sizeof()-5)) + picEx);
01723     outputFile.Close();
01724     /*
01725       for (Int_t suid = 0; suid < usedSusibos; suid++){
01726       for (Int_t rs = 0; rs < recoSets; rs++) {
01727       for (Int_t imerge = 0; imerge < nMerge; imerge++) {
01728       for (Int_t ifilter = 0; ifilter < nFilter; ifilter++) {
01729       delete preCompSpectraEl[suid][rs][imerge][ifilter];
01730       delete preCompSpectraPi[suid][rs][imerge][ifilter];
01731       delete leg[suid][rs][imerge][ifilter];
01732       }
01733       }
01734       }
01735     
01736       delete hitTimeEl[suid];
01737       delete hitTimePi[suid];
01738       delete pulseShapeEl[suid];
01739       delete pulseShapePi[suid];
01740       delete prf[suid];
01741       }
01742     
01743       delete cBeamMonitor;
01744       delete cSpectra;
01745       delete cRest;
01746       delete Ch1_Pb;
01747       delete noCh1_Pb;
01748       delete Ch2_Pb;
01749       delete noCh2_Pb;
01750     */
01751   } // if dataset is open
01752   else {
01753     printf("no input file list in %s",nameFileSet.Data());
01754     return;
01755   }
01756 }

Generated on Tue Dec 10 2013 04:52:16 for ROCsoft by  doxygen 1.7.1