#include "detector.h" #include "../../src/TCalign.h" #include "../../src/TCcluster.h" #include "../../src/TCevent.h" #include "alignment.h" #include #include #include #include #include #include #include #include #include "../../src/ConfigFile.h" #include using namespace std; void failedConf(std::string); class sortDetector{ public: bool operator()(Detector *a1, Detector *a2){ return a1->getZ()getZ(); } }; void Alignment::generateTracks(int amount, double length, double startwidht, double startheight, double endheight, double endwidth) { TRandom3 random(0); for(int i=0;iFindObject("at2"); if(t==NULL){ t=(TTree*)gROOT->FindObject("at_tr"); } int nEvt = t->GetEntries(); TCevent *ev = 0; t->SetBranchAddress("event",&ev); int counter=0; for(int i=0;iGetEntry(i); for(unsigned int j=0;jnTracks();++j){ TCtrack track = *(ev->getTrack(j)); /* Making shure the track has hits in all detector planes Hard coded for the beam telescope */ bool a1 =false; bool a2 =false; bool a3 =false; bool a4 =false; bool a5 =false; bool a6 =false; bool a7 =false; bool a8 =false; for(int j=0;jClose(); } /* Using alignment file to create detector-objects containing alignment information for that detector */ void Alignment::readDetectors(bool simulation_) { TCalign *reader = TCalign::getInstance(infile); reader->clear(); reader->read(infile); cout<<"infile "< ids = reader->getLoadedIDs(); for(unsigned int i=0;i0&&ids[i]<100){ TVector3 trans; TMatrixT rot(3,3); double pitch,res, theta, phi, psi; reader->getConv(ids[i],trans,rot,pitch,theta,phi,psi,res); Detector* detector = new Detector(ids[i], trans.x(), trans.y(), trans.z(), trans.x(),trans.y(),trans.z(), theta,theta, pitch, 0,0,0,0, res); detectors.push_back(detector); } } if(simulation){ cout<<"simrealalign read-----------------------------------------------------***********"<clear(); reader->read("Alignmentfiles/simRealAlign.txt"); assert(reader->getLoadedIDs().size()==ids.size()); for(unsigned int i=0;i rot2(3,3); double pitch2,res2, theta2, phi2, psi2; reader->getConv(ids[i],trans2,rot2,pitch2,theta2,phi2,psi2,res2); cout<<"theta2 "<setErrors(trans2[0],trans2[1],trans2[2],theta2); } } cout<<"before sort"< tok(s); cout<<"fixing u"<::iterator beg=tok.begin();beg!=tok.end();++beg){ std::istringstream istr1(*beg); int number; istr1>>number; cout< tok2(s); cout<<"fixing z"<::iterator beg2=tok2.begin();beg2!=tok2.end();++beg2){ std::istringstream istr1(*beg2); int number; istr1>>number; cout< tok3(s); cout<<"fixing T"<::iterator beg3=tok3.begin();beg3!=tok3.end();++beg3){ std::istringstream istr1(*beg3); int number; istr1>>number; cout< tok4(s); cout<<"fixing P"<::iterator beg4=tok4.begin();beg4!=tok4.end();++beg4){ std::istringstream istr1(*beg4); int number; istr1>>number; cout<getId(); hists_det.push_back(new TH1D(TString::Format("dU_%i",id),TString::Format("dU_%i",id),3000,-10,10)); profiles_det.push_back(new TProfile(TString::Format("dU_vs_U%i",id),TString::Format("dU_vs_U%i",id),1000,10,10,-10,10)); hists_det_testX.push_back(new TH2D(TString::Format("U_vs_X%i",id),TString::Format("Track_x"),200,0,25,200,-5,10)); hists_det_testY.push_back(new TH2D(TString::Format("U_vs_Y%i",id),TString::Format("Track_y"),200,0,25,200,-5,10)); } cout<<"Empty Histograms created"<getId(); if(find(lockedU.begin(),lockedU.end(),detID)!=lockedU.end()){ C_PARSIG(i*NPARPLAN+1,0.0); //!< fix u cout<<"Fixed U for "< hit = detectors[j]->getHitU(tracks_sim[i]); hists_det[j]->Fill(hit.second-hit.first); /*u_rec - u_hit*/ profiles_det[j]->Fill(hit.first,(hit.second-hit.first)); double x=detectors[j]->getX(); double y=detectors[j]->getY(); double z_=detectors[j]->getZ(); double cosT_=detectors[j]->getCosT(); double sinT_=detectors[j]->getSinT(); float sigma_=(float)detectors[j]->getSigma(); float u_hit=(float)hit.first+x*cosT_+y*sinT_ ; // int detID = detectors[j]->getId(); /* calculate local derivatives, ie the derivatives with respect to track parameters. */ double dudx0 = cosT_; //!< /d x0 double dudy0 = sinT_; //!< /d y0 double dudtx = cosT_*z_; //!< /d tx double dudty = sinT_*z_; //!< /d ty //! store std local derivatives derlc[0]= dudx0; derlc[1]= dudtx; derlc[2]= dudy0; derlc[3]= dudty; //! calculate/store global derivatives dergb[NPARPLAN*j]=-1; //!< /d du dergb[NPARPLAN*j+1]= cosT_*tx + sinT_*ty; //!< /d dz dergb[NPARPLAN*j+2]= -sinT_*(x0+tx*(z_)-x) + cosT_*(y0+ty*(z_)-y); //!< /d dtheta dergb[NPARPLAN*j+3]= cosT_*(x0+tx*(z_)-x) + sinT_*(y0+ty*(z_)-y); //!< /d dpitch /* Sending this information to millepede */ equloc_(dergb,derlc,&u_hit,&sigma_); //!< book local/global } /* Doing a local fit inverting submatrices needed for the final fit */ fitloc_(); } cout<<"after loop sim"<getX(); double y=detectors[j]->getY(); double z_=detectors[j]->getZ(); float sigma_=(float)detectors[j]->getSigma(); double cosT_=detectors[j]->getCosT(); double sinT_=detectors[j]->getSinT(); int detID = detectors[j]->getId(); TCcluster hit_cluster = tracks_real[i].getClById(detID,0); float u_hit=(float)hit_cluster.posUVW().x()+x*cosT_+y*sinT_ ; /* cout<<"Detector parameters for detector "<Fill(resid.x()); /*u_rec - u_hit*/ profiles_det[j]->Fill(hit_cluster.posUVW()[0],resid(0)); hists_det_testX[j]->Fill((x0+tx*z_),hit_cluster.posUVW()[0]); hists_det_testY[j]->Fill((y0+ty*z_),hit_cluster.posUVW()[0]); } /* Doing a local fit That means fiting the track parameters and calculating submatrixes of the big matrix that needs to be inverted */ fitloc_(); } } cout<<"Local fits done, doing global fit"<clear(); reader->read(infile); std::vector ids = reader->getLoadedIDs(); for(unsigned int n=0;n rot(3,3); double pitch,res; double theta, phi, psi; cout<getId()<getConv(detectors[n]->getId(),trans,rot,pitch,theta,phi,psi,res); double du, dx, dy,dTheta,dz,dp; du=par[NPARPLAN*n+0]; dz=par[NPARPLAN*n+1]; dTheta=par[NPARPLAN*n+2]; dp=par[NPARPLAN*n+3]; dx = du*cos(theta); dy = du*sin(theta); theta+=dTheta; trans[0]+=dx; trans[1]+=dy; trans[2]+=dz; pitch=pitch*(1-dp); cout<<"dTheta: "<setConv(detectors[n]->getId(),trans,rot,pitch,theta,phi,psi,res); } reader->write(outfile); //open file for histograms TFile* file = new TFile(histogramFile.c_str(),"RECREATE"); for(unsigned int i = 0; iWrite(); profiles_det[i]->Write(); hists_det_testX[i]->Write(); hists_det_testY[i]->Write(); } cout<<"Histograms written to file"<Close(); delete file; for(unsigned int i = 0; iabort" << std::endl; throw; }