/* * DBCALClump.cc * * Created by Beni Zihlmann Tue Mar 12 2013 * version 0.1 * */ #include "BCAL/DBCALClump.h" #include #include #include #include DBCALClump::DBCALClump(vector U, vector D){ HitsU = U; HitsD = D; } void DBCALClump::AnalyzeClump(){ // now do some work on the Clumps up stream and down stream // create clump profiles and determine Energy Sums //const DBCALHit *BcalMatrixU[48*4][4]; // Up stream //const DBCALHit *BcalMatrixD[48*4][4]; // Down stream float EU[48*4]; float ED[48*4]; fillArrays(EU,ED); float EmaxU=0.; float EmaxD=0.; // find Maximum of energy in Clump array int MaxU=999; int MaxD=999; for (int i=0;i<48*4;i++){ if ((EU[i]>0) && (ED[i]>0)) { if (EU[i]>EmaxU){ EmaxU = EU[i]; MaxU = i; } if (ED[i]>EmaxD){ EmaxD = ED[i]; MaxD = i; } } } //cout<MaxD){ MaxD = MaxU; } else { MaxU = MaxD; } resetProfiles(); int UCounter=0; int DCounter=0; // set up a shower profile such that the maximum energy of the shower // ends up in bin 20; int CenterOffsetU = 20-MaxU; int CenterOffsetD = 20-MaxD; // create shower profiles for up stream and down stream int n=MaxU; // start from center upwards while (EU[n]>0.){ int idx = n+CenterOffsetU; if (idx<0){ idx += MaxU; } //cout<<"U> "<=60)||(idx<0)){ break; } ProfileU[idx] = EU[n]; // limit shower upper limit UCounter++; // section to get average mean time and average time difference for sector int loc=999; for (unsigned int k=0;k=48*4){ n -= 48*4; } } // now move from center down wards n = MaxU-1; if (n<0){ n += 48*4; } while (EU[n]>0.){ int idx = n+CenterOffsetU; //cout<<"U< "<20){ idx -= (48.*4); } if (idx<0){ break; } ProfileU[idx] = EU[n]; UCounter++; // section to get average mean time and average time difference for sector int loc=999; for (unsigned int k=0;k0.){ int idx = n+CenterOffsetD; //cout<<"D> "<=60)||(idx<0)){ break; } ProfileD[idx] = ED[n]; DCounter++; n++; if (n>=48*4){ n -= 48*4; } } // now move from center down wards n = MaxD-1; while (ED[n]>0.){ int idx = n+CenterOffsetD; //cout<<"D< "<20){ idx -= (48.*4); } if (idx<0){ break; } ProfileD[idx] = ED[n]; DCounter++; n--; if (n<0){ n += 48*4; } } // at this point we have a shower profile for the upstream and down stream Clump if (0){ for (int k=0; k<60; k++){ cout<1){ TGraph* grU = new TGraph(60,x,ProfileU); //grU->Fit("gaus","Q","r",(Double_t)low,(Double_t)high); grU->Fit("gaus","Q","r",15.,25.); TF1 *f1U = grU->GetFunction("gaus"); double chi2U,posU; if (f1U) { chi2U = f1U->GetChisquare(); posU = f1U->GetParameter(1); } else { posU = 20.; chi2U = 999.; } if (TMath::Abs(posU-20.)>2.){ // this shower has a complicated shape f1U->SetParameter(1,20.); f1U->FixParameter(2,1.0); //grU->Fit("gaus","Q","r",(Double_t)low,(Double_t)high); grU->Fit("gaus","Q","r",15.,25.); f1U = grU->GetFunction("gaus"); posU = f1U->GetParameter(1); if (TMath::Abs(posU-20.)>2.){ // still no better result posU = 20.; // fix it. } } } else if (UCounter){ posU = 20.; chi2U = 999; } else { cout<<"Error no data to fit U: this should never happen!!!"<1){ TGraph* grD = new TGraph(60,x,ProfileD); //grD->Fit("gaus","Q","r",(Double_t)low,(Double_t)high); grD->Fit("gaus","Q","r",15.,25.); TF1 *f1D = grD->GetFunction("gaus"); if (f1D){ chi2D = f1D->GetChisquare(); posD = f1D->GetParameter(1); } else { posD = 20.; chi2D = 999.; } if (TMath::Abs(posD-20.)>2.){ // this shower has a complicated shape f1D->SetParameter(1,20.); f1D->FixParameter(2,1.0); //grD->Fit("gaus","Q","r",(Double_t)low,(Double_t)high); grD->Fit("gaus","Q","r",15.,25.); f1D = grD->GetFunction("gaus"); posD = f1D->GetParameter(1); if (TMath::Abs(posD-20.)>2.){ // still no better result posD = 20.; // fix it. } } } else if (DCounter){ posD = 20.; chi2D = 999.; } else { cout<<"Error no data to fit D: this should never happen!!!"<0.){ Position[k] /= Pcnt[k]; err[k] = 2.5; // Hard coded error if (khigh){ high = k; } } } double Pos=0; double cnt = 0; // don't do a fit with only two or less points // fit approach seem to be too instable // do at the moment do only average if ((high-low)<6){ for (int k=0;k<4;k++){ if (Pcnt[k]>0){ Pos += Position[k]; cnt += 1.; } } if (cnt>0){ Pos /= cnt; } //cout<<" "<Fit("pol1","Q","R",low,high); TF1 * lfit = grT->GetFunction("pol1"); double offset = lfit->GetParameter(0); //double slope = lfit->GetParameter(1); //cout<sector-1) + (hit->module-1)*4; EU[idx] += hit->E; } for (unsigned int i=0;isector-1) + (hit->module-1)*4; ED[idx] += hit->E; } } void DBCALClump::resetProfiles(void){ for (int k=0;k<60;k++){ ProfileU[k] = 0.0; ProfileD[k] = 0.0; ProfileMT[k] = 0.0; ProfileTD[k] = 0.0; } }