#include #include #include // #include #include #include #include #include #include #include // #include #include // using namespace std; // extern Bool_t MATRIX; extern Bool_t FULL; extern Bool_t SIMU; extern Bool_t CRIG; extern Bool_t SRIG; CaloFranzini *cf; Int_t nbin; Float_t rig[18]; Float_t rmean[17]; Int_t ntot[17]; //Float_t qqplane[17][43]; //Int_t nnqplane[17][43]; TArrayF *qplane[17]; TArrayI *nqplane[17]; TMatrixD *matrix[17]; TMatrixD *nmat[17]; TMatrixD *fqplane[17]; TMatrixD *fnqplane[17]; TMatrixF *fmatrix[17]; TMatrixF *fnmat[17]; //=============================================================================== bool Select( PamLevel2* event ){ //--------------------------------------------------------- // single track //--------------------------------------------------------- if( event->GetTrkLevel2()->GetNTracks()!=1 ) return false; PamTrack *track = event->GetTrack(0); if(!track)return false; //------------------------------------------------------------------ // tracker pre-selection //------------------------------------------------------------------ TrkTrack *trk = track->GetTrkTrack(); float rigidity = trk->GetRigidity(); if ( CRIG ) rigidity = event->GetCaloLevel2()->qtot/260.; if ( SRIG ) rigidity = event->GetGPamela()->P0; bool TRACK__OK = false; if( trk->chi2 >0 && trk->GetNX()>=4 && trk->GetNY()>=3 && trk->GetLeverArmX()>=5 && true ) TRACK__OK = true; if( !TRACK__OK )return false; //------------------------------------------------------------------ // TOF pre-selection //------------------------------------------------------------------ bool TOF__OK = false; if( event->GetToFLevel2()->GetNHitPaddles(0) == 1 && event->GetToFLevel2()->GetNHitPaddles(1) == 1 && event->GetToFLevel2()->GetNHitPaddles(2) == 1 && event->GetToFLevel2()->GetNHitPaddles(3) == 1 && event->GetToFLevel2()->GetNHitPaddles(4) >= 1 && event->GetToFLevel2()->GetNHitPaddles(5) >= 1 && event->GetToFLevel2()->npmt() <= 18 && !event->GetAcLevel2()->CARDhit() && !event->GetAcLevel2()->CAThit() && true ) TOF__OK = true; if( !TOF__OK && !SIMU)return false; //------------------------------------------------------ // no albedo //------------------------------------------------------ if( !SIMU && (track->GetToFTrack()->beta[12]<=0.2 || track->GetToFTrack()->beta[12] >= 1.5) ) return false; //------------------------------------------------------ bool CUT1 = false; if( trk->nstep<100 && rigidity<400. && rigidity>0.1 && trk->resx[0]<0.001 && trk->resx[5]<0.001 && track->IsSolved() && trk->IsInsideCavity() && true ) CUT1 = true; //------------------------------------------------------ if( !CUT1 )return false; if ( trk->GetDeflection()>0. && !SIMU ) return false; // // ELENA'S CUT // // // lever-arm 6 //==================================================== bool LX6=false; if( track->GetTrkTrack()->GetLeverArmX()==6 && !track->GetTrkTrack()->IsBad(0,0) && !track->GetTrkTrack()->IsBad(5,0) && track->GetTrkTrack()->resx[0]<0.001 && track->GetTrkTrack()->resx[5]<0.001 && track->GetTrkTrack()->IsInsideCavity() && true ) LX6 = true; //==================================================== // lever-arm 5 //==================================================== bool LX5=false; if( track->GetTrkTrack()->GetLeverArmX()==5 && true ){ if( track->GetTrkTrack()->XGood(0) && track->GetTrkTrack()->XGood(4) ){ if( !track->GetTrkTrack()->IsBad(0,0) && !track->GetTrkTrack()->IsBad(4,0) && track->GetTrkTrack()->resx[0]<0.001 && track->GetTrkTrack()->resx[4]<0.001 && track->GetTrkTrack()->IsInsideCavity() && true) LX5 = true; }else if ( track->GetTrkTrack()->XGood(1) && track->GetTrkTrack()->XGood(5) ){ if( !track->GetTrkTrack()->IsBad(1,0) && !track->GetTrkTrack()->IsBad(5,0) && track->GetTrkTrack()->resx[1]<0.001 && track->GetTrkTrack()->resx[5]<0.001 && track->GetTrkTrack()->IsInsideCavity() && true) LX5 = true; } } if ( !LX5 && !LX6 ) return false; Float_t defl = trk->GetDeflection(); float p0 = 1.111588e+00; float p1 = 1.707656e+00; float p2 = 1.489693e-01; float chi2m025 = p0 + fabs(defl)*p1 + defl*defl*p2; float def_0 = 0.07; float chi2m025_0 = p0 + fabs(def_0)*p1 + def_0*def_0*p2; // int nchi2cut=5; float chi2cut=3.; float chi2m = pow( chi2m025-chi2m025_0+pow(chi2cut,0.25), 4.); bool CUT2 = false; if( track->GetTrkTrack()->chi2 < chi2m && true ) CUT2 = true; if ( !CUT2 ) return false; float dedxtrk = trk->GetDEDX(); // float zcutn = 9. + 20./(rigidity*rigidity); float zcut2 = 3. + 4.3/(rigidity*rigidity); float zcut1 = 0.52 + 0.455/(rigidity*rigidity); Bool_t Z1 = false; if(dedxtrk > zcut1 && dedxtrk < zcut2){ Z1=true; } if ( !Z1 && !SIMU ) return false; //------------------------------------------------------ // // energy momentum match // Float_t qtotimp = event->GetCaloLevel2()->qtot / trk->GetRigidity(); Float_t qcut2 = (-0.5 * trk->GetRigidity() + 150.) * 1.1; if ( qcut2 < 55. ) qcut2 = 55.; if ( qtotimp <= qcut2 ) return false; // for (Int_t i=0; i < 22; i++){ if ( track->GetCaloTrack()->tibar[i][1] < 0 || track->GetCaloTrack()->tibar[i][0] < 0 ){ return false; }; }; // if ( event->GetCaloLevel2()->qtot == 0. ) return false; if ( rigidity>5. && track->GetCaloTrack()->qtrack/event->GetCaloLevel2()->qtot < 0.4 ) return false; if ( rigidity<1. && track->GetToFTrack()->beta[12] < 0.8 ) return false; if ( rigidity>50. ){ if ( trk->GetNX()<5 && trk->GetNY()<4 ) return false; // Bool_t sphit = false; for ( Int_t plane = 0; plane < 6; plane++){ if ( !trk->XGood(plane) ){ for (Int_t sing = 0; sing < event->GetTrkLevel2()->nclsx(); sing++){ TClonesArray &t = *(event->GetTrkLevel2()->SingletX); TrkSinglet *singlet = (TrkSinglet*)t[sing]; if ( (singlet->plane-1) == plane ){ Float_t x = (singlet->coord[0]+singlet->coord[1])/2.; if ( fabs(track->GetTrkTrack()->xv[plane] - x) < 1. ) sphit = true; }; }; }; if ( !trk->YGood(plane) ){ for (Int_t sing = 0; sing < event->GetTrkLevel2()->nclsy(); sing++){ TClonesArray &t = *(event->GetTrkLevel2()->SingletY); TrkSinglet *singlet = (TrkSinglet*)t[sing]; if ( (singlet->plane-1) == plane ){ Float_t x1 = (singlet->coord[0]); Float_t x2 = (singlet->coord[1]); if ( fabs(track->GetTrkTrack()->yv[plane] - x1) < 1. ) sphit = true; if ( fabs(track->GetTrkTrack()->yv[plane] - x2) < 1. ) sphit = true; }; }; }; }; if ( sphit ) return false; // spurious hit along the track }; // Int_t ti0 = track->GetCaloTrack()->tibar[0][1]-1; Int_t view = 0; Int_t plane = 0; Int_t strip = 0; Float_t mip = 0.; // for ( Int_t i=0; iGetCaloLevel1()->istrip; i++ ){ // mip = event->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); if ( view == 1 && plane == 0 && strip == ti0 && mip > 4.) return false; if ( view == 1 && (plane >0 || strip > ti0) ) break; }; // if ( event->GetCaloLevel1()->qtotpl(0) > 7. ) return false; // return true; } //=============================================================== // Create histograms // // // // // //=============================================================== void CreateHistos( PamLevel2* event , TString file){ cf = new CaloFranzini(event); // if ( MATRIX ){ cf->UpdateMatrixFile(file.Data()); cf->LoadBin(); if ( !FULL ){ cf->LoadLong(); } else { cf->LoadFull(); }; } else { cf->CreateMatrixFile(file.Data()); }; // // nbin = 18; rig[0] = 0.1; rig[1] = 0.5; rig[2] = 1.; rig[3] = 1.5; rig[4] = 2.2; rig[5] = 3.; rig[6] = 4.; rig[7] = 5.; rig[8] = 6.; rig[9] = 8.; rig[10] = 10.; rig[11] = 15.; rig[12] = 25.; rig[13] = 35.; rig[14] = 50.; rig[15] = 100.; rig[16] = 200.; rig[17] = 400.; // memset(rmean, 0, 17*sizeof(Float_t)); memset(ntot, 0, 17*sizeof(Int_t)); // for (Int_t i=0; i < 17 ; i++){ if ( !FULL ){ matrix[i] = new TMatrixD(43,43); qplane[i] = new TArrayF(43); nqplane[i] = new TArrayI(43); nmat[i] = new TMatrixD(43,43); } else { if ( MATRIX ){ fmatrix[i] = new TMatrixF(4128,4128); fnmat[i] = new TMatrixF(4128,4128); //fnmat[i] = new TMatrixI(8213,8213); } else { fqplane[i] = new TMatrixD(43,191); // 43 planes x 191 strip (= 1 + 95 x 2, one strip is the one transversed by the track that could be on the extreme right or left) fnqplane[i] = new TMatrixD(43,191);// }; }; }; // } //=============================================================== void FindAverage( PamLevel2* L2, int iev ){ // Float_t erig = L2->GetTrack(0)->GetTrkTrack()->GetRigidity(); if ( SRIG ) erig = L2->GetGPamela()->P0; if ( CRIG ) erig = L2->GetCaloLevel2()->qtot/260.; // Int_t rbi = 0; for (Int_t i = 0; i=rig[i] && erig < rig[i+1] ){ rbi = i; break; }; }; // if ( erig < rig[0] ) return; if ( erig >= rig[nbin-1] ) return; // rmean[rbi] += erig; ntot[rbi]++; // if (!FULL ){ Int_t dgf = 43; // for (Int_t i=0; iGetCaloLevel1()->istrip; i++ ){ // mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); // nplane = 1 - view + 2 * plane; if ( erig > 4. && nplane == 0 && mip > 15. ) printf(" IEV %i erig %f OBT %u pkt %u file %s \n",iev,erig,L2->GetOrbitalInfo()->OBT,L2->GetOrbitalInfo()->pkt_num,L2->GetPamTree()->GetFile()->GetName()); //printf(" IEV %i OBT %u pkt %u file %s \n",iev,L2->GetOrbitalInfo()->OBT,L2->GetOrbitalInfo()->pkt_num,L2->GetPamTree()->GetFile()->GetName()); if ( nplane > 37 ) nplane--; if ( nplane < dgf ){ (*qplane[rbi])[nplane] += mip; }; // }; } else { // // FULL CALORIMETER // CaloTrkVar *ct = L2->GetTrack(0)->GetCaloTrack(); // Int_t nplane = 0; Int_t view = 0; Int_t plane = 0; Int_t strip = 0; Float_t mip = 0.; // Int_t cs = 0; Int_t cd = 0; Int_t mstrip = 0; // for (Int_t j=0; j<2; j++){ for (Int_t i=0; i<21; i++){ nplane = 1 - j + 2*i; if ( nplane > 37 ) nplane--; // cs = ct->tibar[i][j] - 1; // cd = 95 - cs; // for (Int_t k=0; k<191; k++){ mstrip = cd + k; if ( mstrip < (191-cs) ) (*fnqplane[rbi])[nplane][mstrip] += 1.; }; }; }; // // for ( Int_t i=0; iGetCaloLevel1()->istrip; i++ ){ // mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); // nplane = 1 - view + 2 * plane; if ( nplane > 37 ) nplane--; // cs = ct->tibar[plane][view] - 1; // cd = 95 - cs; // mstrip = cd + strip; // (*fqplane[rbi])[nplane][mstrip] += mip; // }; // }; } void CalculateAverage(){ // if ( !FULL ){ for (Int_t i=0; i 0 ) rmean[i] /= (Float_t)(*nqplane[i])[0]; for (Int_t j=0; j<43 ; j++){ if ( (*nqplane[i])[j] > 0 ){ (*qplane[i])[j] /= (Float_t)(*nqplane[i])[j]; } else { (*qplane[i])[j] = 0.; }; printf(" BIN %i plane %i average energy %f qplane %f nqplane %i \n",i,j,rmean[i],(*qplane[i])[j],(*nqplane[i])[j]); }; }; for (Int_t i=0; iWriteLongMean(qplane[i], i); // }; } else { for (Int_t i=0; i 0 ) rmean[i] /= (Float_t)(ntot[i]); // for (Int_t j=0; j<43 ; j++){ for (Int_t k=0; k<191; k++){ if ( (*fnqplane[i])[j][k] > 0 ){ (*fqplane[i])[j][k] /= (Float_t)(*fnqplane[i])[j][k]; } else { (*fqplane[i])[j][k] = 0.; }; printf(" BIN %i plane %i strip %i average energy %f qplane %f nqplane %f \n",i,j,k,rmean[i],(*fqplane[i])[j][k],(*fnqplane[i])[j][k]); }; }; }; for (Int_t i=0; iWriteFullMean(fqplane[i], i); // }; }; // cf->WriteNumBin(nbin); // TArrayF *rigbin = new TArrayF(18, rig); cf->WriteRigBin(rigbin); // TArrayF *rmeanbin = new TArrayF(17, rmean); TFile *file = cf->GetFile(); file->cd(); file->WriteObject(&(*rmeanbin), "binrigmean"); // // } //=============================================================== void FindMatrix( PamLevel2* L2, int iev ){ // Float_t erig = L2->GetTrack(0)->GetTrkTrack()->GetRigidity(); if ( SRIG ) erig = L2->GetGPamela()->P0; if ( CRIG ) erig = L2->GetCaloLevel2()->qtot/260.; // Int_t rbi = 0; for (Int_t i = 0; i=rig[i] && erig < rig[i+1] ){ rbi = i; break; }; }; // if ( erig < rig[0] ) return; if ( erig >= rig[nbin-1] ) return; // if ( !FULL ){ Int_t dgf = 43; // for (Int_t i=0; iGetCaloLevel1()->istrip; i++ ){ // mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); // nplane = 1 - view + 2 * plane; if ( nplane > 37 ) nplane--; if ( nplane < dgf ){ hpl[nplane] += mip; }; // }; // for (Int_t i=0; iGetAverageAt(i,erig)) * (hpl[j] - cf->GetAverageAt(j,erig)); }; }; } else { // // FULL CALORIMETER // CaloTrkVar *ct = L2->GetTrack(0)->GetCaloTrack(); // Int_t nplane = 0; Int_t view = 0; Int_t plane = 0; Int_t strip = 0; Float_t mip = 0.; // Int_t mindgf = 48; Int_t dgf = 143; Int_t cs = 0; Int_t cd = 0; Int_t mstrip = 0; // Float_t mipv[43][191]; memset(mipv,0,43*191*sizeof(Float_t)); // for ( Int_t i=0; iGetCaloLevel1()->istrip; i++ ){ // mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip); // nplane = 1 - view + 2 * plane; if ( nplane > 37 ) nplane--; // cs = ct->tibar[plane][view] - 1; // cd = 95 - cs; // mstrip = cd + strip; // mipv[nplane][mstrip] = mip; // }; // Float_t mip1; Int_t cs1; Int_t cd1; Float_t mip2; Int_t cs2; Int_t cd2; Int_t mi = -1; Int_t mj = -1; Int_t nn1 = 0; Int_t pl1 = 0; Int_t vi1 = 0; Int_t nn2 = 0; Int_t pl2 = 0; Int_t vi2 = 0; Int_t mstrip1min = 0; Int_t mstrip1max = 0; Int_t mstrip2min = 0; Int_t mstrip2max = 0; // for (Int_t nplane1=0; nplane1<43; nplane1++){ for (Int_t mstrip1=0; mstrip1<191; mstrip1++){ mj = -1; // if ( nplane1 >= 37 ) nn1 = nplane1 + 1; vi1 = 1; if ( nn1%2 ) vi1 = 0; pl1 = (nn1 - 1 + vi1)/2; // cs1 = ct->tibar[pl1][vi1] - 1; // convertire nplane in pl1 e vi1 // cd1 = 95 - cs1; // mstrip1min = cd1 + 0; mstrip1max = cd1 + 95; mip1 = mipv[nplane1][mstrip1]; // if ( mstrip1 >= mindgf && mstrip1 <= dgf ){ mi++; // for (Int_t nplane2=0; nplane2<43; nplane2++){ for (Int_t mstrip2=0; mstrip2<191; mstrip2++){ // if ( nplane2 >= 37 ) nn2 = nplane2 + 1; vi2 = 1; if ( nn2%2 ) vi2 = 0; pl1 = (nn2 - 1 + vi2)/2; // cs2 = ct->tibar[pl2][vi2] - 1; // cd2 = 95 - cs2; // mstrip2min = cd2 + 0; mstrip2max = cd2 + 95; // mip2 = mipv[nplane2][mstrip2]; // if ( mstrip2 >= mindgf && mstrip2 <= dgf ){ mj++; (*fmatrix[rbi])[mi][mj] += (mipv[nplane1][mstrip1] - cf->GetFullAverageAt(nplane1,mstrip1,erig)) * (mipv[nplane2][mstrip2] - cf->GetFullAverageAt(nplane2,mstrip2,erig)); if ( mstrip1 >= mstrip1min && mstrip1 <= mstrip1max && mstrip2 >= mstrip2min && mstrip2 <= mstrip2max){ (*fnmat[rbi])[mi][mj] += 1.; }; }; }; }; }; }; }; // }; } //=============================================================== // Save histograms // // // // // //=============================================================== void SaveHistos(){ // if ( MATRIX ){ // printf("Finished, calculating average and inverting matrices\n"); // if ( !FULL ){ for (Int_t i=0; i 0. ){ (*matrix[i])[ii][j] /= (*nmat[i])[ii][j]; } else { (*matrix[i])[ii][j] = 0.; }; }; }; // cf->WriteLongMatrix(matrix[i],i); // if ( matrix[i]->Determinant() == 0. ){ printf("\n"); for (Int_t ii=0; ii<43; ii++){ for (Int_t j=0; j<43; j++){ printf(" %.f",(*matrix[i])[ii][j]); }; printf("\n"); }; printf("\n"); printf(" ERROR: the matrix at bin %i is singular, determinant = 0., it cannot be inverted! \n",i); } else { Double_t det = 0.; TMatrixD invmatrix = (TMatrixD)(matrix[i]->Invert(&det)); printf(" Bin %i determinant is %f \n",i,det); cf->WriteInvertedLongMatrix((TMatrixD)invmatrix,i); }; }; } else { // // FULL // for (Int_t i=0; i 0. ){ (*fmatrix[i])[ii][j] /= (*fnmat[i])[ii][j]; } else { (*fmatrix[i])[ii][j] = 0.; }; }; }; // cf->WriteFullMatrix(fmatrix[i],i); // if ( fmatrix[i]->Determinant() == 0. ){ printf(" ERROR: the matrix at bin %i is singular, determinant = 0., it cannot be inverted! \n",i); } else { Double_t det = 0.; TMatrixF invmatrix = (TMatrixF)(fmatrix[i]->Invert(&det)); printf(" Bin %i determinant is %f \n",i,det); cf->WriteInvertedFullMatrix((TMatrixF)invmatrix,i); }; }; }; // printf(" done, closing file and exiting\n"); // }; // cf->CloseMatrixFile(); // cf->Delete(); // }