--- calo/flight/CaloEnergy/src/CaloEnergy.cpp 2009/07/29 12:58:27 1.4 +++ calo/flight/CaloEnergy/src/CaloEnergy.cpp 2009/08/11 13:28:27 1.5 @@ -39,7 +39,7 @@ // // use the presampler setting forcefitmode to 1000 means to force the DV routine to find the track inside the calorimeter using the "shower" approach developed for electrons // - cp = new CaloPreSampler(L2); + if ( !cp ) cp = new CaloPreSampler(L2); cp->SplitInto(0,22); cp->SetForceFitMode(1000); // cp->UseTracker(false); @@ -48,6 +48,18 @@ // cp->Process(); } + +void CaloEnergy::UseLongFit(){ + fPl = 0; + fLong = true; + if ( !clong ){ + clong = new CaloLong(L2); + if ( cp ) clong->SetCaloLevel2Pointer(cp->GetLevel2Pointer()); + clong->SplitInto(0,22); + }; + // +} + void CaloEnergy::Set(){ // // set default values, NB default conversion factor for energy is just very approximated! @@ -70,6 +82,8 @@ fPl = 1; fRad = -1; cp = NULL; + clong = NULL; + x0max = -1.; // this->DefineGeometry(); fXosel =true; @@ -139,15 +153,37 @@ return(-1); } +Float_t CaloEnergy::GetEnergyAtMaxplane(TString section){ + section.ToUpper(); + if ( section.Contains("XO") ) return xomax_en; + if ( section.Contains("XE") ) return xemax_en; + if ( section.Contains("YO") ) return yomax_en; + if ( section.Contains("YE") ) return yemax_en; + return(-1); +} + Float_t CaloEnergy::GetMaxEnergy(TString section){ section.ToUpper(); - if ( section.Contains("XO") ) return fXOen_maxplane; - if ( section.Contains("XE") ) return fXEen_maxplane; - if ( section.Contains("YO") ) return fYOen_maxplane; - if ( section.Contains("YE") ) return fYEen_maxplane; + if ( fLong ){ + this->Process(section); + return fXOen_maxplane; + } else { + if ( section.Contains("XO") ) return fXOen_maxplane; + if ( section.Contains("XE") ) return fXEen_maxplane; + if ( section.Contains("YO") ) return fYOen_maxplane; + if ( section.Contains("YE") ) return fYEen_maxplane; + }; return(-1); } +Float_t CaloEnergy::GetMaxEnergy(){ + if ( fLong ){ + if ( debug ) printf(" oh! call process! with asntr %s and sntr %s \n",asntr.Data(),sntr.Data()); + this->Process(asntr); + }; + return((fXEen_maxplane+fYOen_maxplane+fYEen_maxplane+fXOen_maxplane)); +} + void CaloEnergy::DefineGeometry(){ // // Use CaloStrip to determine once the position of border strips for each section @@ -272,8 +308,13 @@ fMax_planexo = 0; fMax_planexe = 0; fMax_planeyo = 0; - fMax_planeye = 0; - memset(enstrip,0,2*22*96*(sizeof(Float_t))); + fMax_planeye = 0; + xomax_en= 0.; + xemax_en= 0.; + yomax_en= 0.; + yemax_en= 0.; + // + memset(enstrip,0,2*22*96*(sizeof(Float_t))); en = 0.; view = 0; plane = 0; @@ -336,6 +377,7 @@ printf(" energyxo:.............. %f \n",energyxo); printf(" energyye:.............. %f \n",energyye); printf(" energyyo:.............. %f \n",energyyo); + printf(" x0max :.............. %f \n",x0max); printf(" debug :.............. %i \n",debug); printf("========================================================================\n"); @@ -421,16 +463,16 @@ // en_xep[i] += enstrip[1][2*i][strip]; en_yop[i] += enstrip[0][2*i][strip]; - en_xop[i] += enstrip[1][2*i+1][strip]; - en_yep[i] += enstrip[0][2*i+1][strip]; + en_xop[i] += enstrip[1][(2*i)+1][strip]; + en_yep[i] += enstrip[0][(2*i)+1][strip]; } else { // // use only the strips inside a cylinder of given radius fRad // if ( strip >= cl2->cibar[2*i][1]-1-fRad && strip <= cl2->cibar[2*i][1]-1+fRad ) en_xep[i] += enstrip[1][2*i][strip]; if ( strip >= cl2->cibar[2*i][0]-1-fRad && strip <= cl2->cibar[2*i][0]-1+fRad ) en_yop[i] += enstrip[0][2*i][strip]; - if ( strip >= cl2->cibar[2*i+1][1]-1-fRad && strip <= cl2->cibar[2*i+1][1]-1+fRad ) en_xop[i] += enstrip[1][2*i+1][strip]; - if ( strip >= cl2->cibar[2*i+1][0]-1-fRad && strip <= cl2->cibar[2*i+1][0]-1+fRad ) en_yep[i] += enstrip[0][2*i+1][strip]; + if ( strip >= cl2->cibar[(2*i)+1][1]-1-fRad && strip <= cl2->cibar[(2*i)+1][1]-1+fRad ) en_xop[i] += enstrip[1][(2*i)+1][strip]; + if ( strip >= cl2->cibar[(2*i)+1][0]-1-fRad && strip <= cl2->cibar[(2*i)+1][0]-1+fRad ) en_yep[i] += enstrip[0][(2*i)+1][strip]; }; }; energyxe += en_xep[i]; @@ -441,11 +483,6 @@ // // Find the plane of maximum for each section // - Float_t xomax_en= 0.; - Float_t xemax_en= 0.; - Float_t yomax_en= 0.; - Float_t yemax_en= 0.; - // // Int_t xen = 0; Int_t yon = 0; @@ -494,6 +531,47 @@ }; }; // + // the maximum is given externally as X0, convert it to plane and section + // + if ( x0max > 0. ){ + if ( debug ) printf(" CALCULATE MAX PLANE GIVEN X0 ASSUMING PERPENDICULAR TRACK \n"); + Int_t wpl = (Int_t)roundf(x0max/0.76); + Bool_t isY = false; + if ( ((x0max/0.76)-(Float_t)wpl) > 0. ) isY = true; + if ( !(wpl%2) ){ + // 0, 2, 4, ... + if ( isY ){ + yomax_en = 1000.; + xemax_en = 500.; + fMax_planeyo=wpl/2; + fMax_planexe=wpl/2; + } else { + yomax_en = 500.; + xemax_en = 1000.; + fMax_planeyo=wpl/2; + fMax_planexe=wpl/2; + }; + xomax_en = 0.; + yemax_en = 0.; + } else { + // 1, 3, 5, ... + if ( isY ){ + yemax_en = 1000.; + xomax_en = 500.; + fMax_planeye=(wpl-1)/2; + fMax_planexo=(wpl-1)/2; + } else { + yemax_en = 500.; + xomax_en = 1000.; + fMax_planeye=(wpl-1)/2; + fMax_planexo=(wpl-1)/2; + }; + xemax_en = 0.; + yomax_en = 0.; + }; + if ( debug ) printf(" x0max %f wpl %i isY %i yomax_en %f xemax_en %f yemax_en %f xomax_en %f fMaxplane %i %i %i %i\n",x0max,wpl,isY,yomax_en,xemax_en,yemax_en,xomax_en,fMax_planeyo,fMax_planexe,fMax_planeye,fMax_planexo); + }; + // Int_t nPl = fPl; // // Set the maximum in case of coherent mode was selected @@ -588,32 +666,32 @@ for (Int_t i=0; i<11; i++) { if ( - (((track_coordx[2*i+1][1]>=(-12.054+fM))&& - (track_coordx[2*i+1][1]<=(-4.246-fM)))&& - (((cl2->cbar[2*i+1][1]>=xo1 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo2 - fM1 ))|| - ((cl2->cbar[2*i+1][1]>=xo3 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo4 - fM1 ))|| - ((cl2->cbar[2*i+1][1]>=xo5 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo6 - fM1 ))))|| + (((track_coordx[(2*i)+1][1]>=(-12.054+fM))&& + (track_coordx[(2*i)+1][1]<=(-4.246-fM)))&& + (((cl2->cbar[(2*i)+1][1]>=xo1 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo2 - fM1 ))|| + ((cl2->cbar[(2*i)+1][1]>=xo3 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo4 - fM1 ))|| + ((cl2->cbar[(2*i)+1][1]>=xo5 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo6 - fM1 ))))|| - (((track_coordx[2*i+1][1]>=(-4.004+fM))&& - (track_coordx[2*i+1][1]<=(3.804-fM)))&& - (((cl2->cbar[2*i+1][1]>=xo1 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo2 - fM1 ))|| - ((cl2->cbar[2*i+1][1]>=xo3 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo4 - fM1))|| - ((cl2->cbar[2*i+1][1]>=xo5 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo6 - fM1 ))))|| + (((track_coordx[(2*i)+1][1]>=(-4.004+fM))&& + (track_coordx[(2*i)+1][1]<=(3.804-fM)))&& + (((cl2->cbar[(2*i)+1][1]>=xo1 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo2 - fM1 ))|| + ((cl2->cbar[(2*i)+1][1]>=xo3 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo4 - fM1))|| + ((cl2->cbar[(2*i)+1][1]>=xo5 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo6 - fM1 ))))|| - (((track_coordx[2*i+1][1]>=(4.046+fM))&& - (track_coordx[2*i+1][1]<=(11.854-fM)))&& - (((cl2->cbar[2*i+1][1]>=xo1 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo2 - fM1))|| - ((cl2->cbar[2*i+1][1]>=xo3 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo4 - fM1 ))|| - ((cl2->cbar[2*i+1][1]>=xo5 + fM1)&& - (cl2->cbar[2*i+1][1]<=xo6 - fM1 )))) + (((track_coordx[(2*i)+1][1]>=(4.046+fM))&& + (track_coordx[(2*i)+1][1]<=(11.854-fM)))&& + (((cl2->cbar[(2*i)+1][1]>=xo1 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo2 - fM1))|| + ((cl2->cbar[(2*i)+1][1]>=xo3 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo4 - fM1 ))|| + ((cl2->cbar[(2*i)+1][1]>=xo5 + fM1)&& + (cl2->cbar[(2*i)+1][1]<=xo6 - fM1 )))) ){ fXosel = true; fXoout = i; @@ -692,32 +770,32 @@ for (Int_t i=0; i<11; i++) { if ( - (((track_coordy[2*i+1][0]>=(-12.154+fM))&& - (track_coordy[2*i+1][0]<=(-4.346-fM)))&& - (((cl2->cbar[2*i+1][0]>=ye1 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye2 - fM1 ))|| - ((cl2->cbar[2*i+1][0]>=ye3 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye4 - fM1 ))|| - ((cl2->cbar[2*i+1][0]>=ye5 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye6 - fM1 ))))|| + (((track_coordy[(2*i)+1][0]>=(-12.154+fM))&& + (track_coordy[(2*i)+1][0]<=(-4.346-fM)))&& + (((cl2->cbar[(2*i)+1][0]>=ye1 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye2 - fM1 ))|| + ((cl2->cbar[(2*i)+1][0]>=ye3 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye4 - fM1 ))|| + ((cl2->cbar[(2*i)+1][0]>=ye5 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye6 - fM1 ))))|| - (((track_coordy[2*i+1][0]>=(-4.104+fM))&& - (track_coordy[2*i+1][0]<=(3.704-fM)))&& - (((cl2->cbar[2*i+1][0]>=ye1 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye2 - fM1 ))|| - ((cl2->cbar[2*i+1][0]>=ye3 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye4 - fM1))|| - ((cl2->cbar[2*i+1][0]>=ye5 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye6 - fM1 ))))|| + (((track_coordy[(2*i)+1][0]>=(-4.104+fM))&& + (track_coordy[(2*i)+1][0]<=(3.704-fM)))&& + (((cl2->cbar[(2*i)+1][0]>=ye1 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye2 - fM1 ))|| + ((cl2->cbar[(2*i)+1][0]>=ye3 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye4 - fM1))|| + ((cl2->cbar[(2*i)+1][0]>=ye5 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye6 - fM1 ))))|| - (((track_coordy[2*i+1][0]>=(3.946+fM))&& - (track_coordy[2*i+1][0]<=(11.754-fM)))&& - (((cl2->cbar[2*i+1][0]>=ye1 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye2 - fM1))|| - ((cl2->cbar[2*i+1][0]>=ye3 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye4 - fM1 ))|| - ((cl2->cbar[2*i+1][0]>=ye5 + fM1)&& - (cl2->cbar[2*i+1][0]<=ye6 - fM1 )))) + (((track_coordy[(2*i)+1][0]>=(3.946+fM))&& + (track_coordy[(2*i)+1][0]<=(11.754-fM)))&& + (((cl2->cbar[(2*i)+1][0]>=ye1 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye2 - fM1))|| + ((cl2->cbar[(2*i)+1][0]>=ye3 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye4 - fM1 ))|| + ((cl2->cbar[(2*i)+1][0]>=ye5 + fM1)&& + (cl2->cbar[(2*i)+1][0]<=ye6 - fM1 )))) ){ fYesel = true; fYeout = i; @@ -791,7 +869,6 @@ // Count the number of sections in which the event is contained // fCount = (Float_t)((Int_t)fXesel+(Int_t)fXosel+(Int_t)fYesel+(Int_t)fYosel); - if ( debug ) printf(" IsInside XE %i XO %i YE %i YO %i => SEL %i \n",fXesel,fXosel,fYesel,fYosel,fSel); // if ( indep ){ // @@ -814,6 +891,7 @@ }; // if ( debug ) printf("sel %i indep %i fMax_plane %f conv_r %f en_maxplane %f encalo %f \n",fSel,indep,fMax_plane,fConv_rxo,fXOen_maxplane,fEnergy); + if ( debug ) printf(" IsInside XE %i XO %i YE %i YO %i => SEL %i \n",fXesel,fXosel,fYesel,fYosel,fSel); // // finish exit // @@ -865,8 +943,50 @@ if ( (fM1+0.122-0.244*(Float_t)fRad) < 0. ) printf("Error: (fM1+0.122-0.244*(Float_t)fRad) < 0. fM1 %f fRad %i %f \n",fM1,fRad,(fM1+0.122-0.244*(Float_t)fRad)); // if ( fLong ){ + if ( debug ) printf(" ==================================================================> LONGITUDINAL FIT! \n"); // - // use long fit to measure energy NOT IMPLEMENTED YET + // use long fit to measure energy + // + if ( this->IsInsideAcceptance(section) ){ + // + if ( debug ) printf(" ==================================================================> LONG INSIDE! \n"); + // + Float_t myene[2][22]; + memset(myene,0,(sizeof(Float_t))*2*22); + for (Int_t j=0; j<11; j++){ + if ( section.Contains("XE") ) myene[1][2*j] = en_xep[j]; + if ( section.Contains("YO") ) myene[0][2*j] = en_yop[j]; + if ( section.Contains("XO") ) myene[1][(2*j)+1] = en_xop[j]; + if ( section.Contains("YE") ) myene[0][(2*j)+1] = en_yep[j]; + }; + clong->UnMaskSections(); + if ( !(section.Contains("YE")) ) clong->MaskSection("YE"); + if ( !(section.Contains("YO")) ) clong->MaskSection("YO"); + if ( !(section.Contains("XO")) ) clong->MaskSection("XO"); + if ( !(section.Contains("XE")) ) clong->MaskSection("XE"); + clong->ForceNextFit(); + clong->SetEnergies(myene); + if ( debug ){ + clong->Fit(true); + } else { + clong->Fit(); + }; + fXOen_maxplane = clong->Get_E0(); + fYOen_maxplane = 0.; + fYEen_maxplane = 0.; + fXEen_maxplane = 0.; + fEnergy=fXOen_maxplane/fConv_rxo; + if ( fEnergy != fEnergy || clong->Get_fitresult() != 0 ) fEnergy = -1.; + // if ( fEnergy != fEnergy ) fEnergy = 1.; + // + } else { + // + // if the event is not in the acceptance, return a negative energy. + // + if ( debug ) printf(" Outside acceptance \n"); + fEnergy *= -1.; + // + }; // } else { //