void spectra_mw(const char *prefix = "pt/PhiNsigma_KTPCnsig30_STD2010_00_DEFAULT_00") { TGraphErrors *g = ReadMWGraph(Form("%s/mass", prefix), 1); g->Draw("ACP"); TLatex latex; latex.SetTextFont(42); latex.SetTextAlign(12); latex.SetTextSize(0.03); latex.SetTextColor(kBlue+1); latex.DrawLatex(1.2, 1.01877, "MC generated"); latex.SetTextColor(kGreen+1); latex.DrawLatex(1.2, 1.01877-0.00015, "MC reconstructed"); latex.SetTextColor(kRed+1); latex.DrawLatex(1.2, 1.01877-2*0.000155, "Real data (uncorrected)"); latex.SetTextColor(kBlack); latex.DrawLatex(1.2, 1.01877-3*0.00016, "Real data (corrected)"); gPad->Print(Form("%s.pdf", g->GetName())); gPad->Clear(); gPad->SetLogy(0); TGraphErrors *g = ReadMWGraph(Form("%s/mass", prefix), 3); g->Draw("AP"); latex.SetTextAlign(22); latex.SetTextSize(0.04); latex.SetTextColor(kBlack); latex.DrawLatex(2.0, 1.0207, "pp @ #sqrt{s} = 2.76 TeV"); latex.DrawLatex(2.0, 1.0205, "TPC 3.0 #sigma"); latex.DrawLatex(2.0, 1.0202, "#phi #rightarrow K^{ +} K^{ -}"); latex.SetTextSize(0.035); latex.DrawLatex(1.7, 1.0182, "uncertainties: stat. (bars) & syst. (boxes)"); gPad->Print(Form("%s.pdf", g->GetName())); gPad->Clear(); TGraphErrors *g = ReadMWGraph(Form("%s/width", prefix), 2); g->Draw("AP"); TLatex latex; latex.SetTextAlign(22); latex.SetTextSize(0.04); latex.SetTextColor(kBlack); latex.DrawLatex(1.7, 0.0090, "pp @ #sqrt{s} = 2.76 TeV"); latex.DrawLatex(1.7, 0.0085, "TPC 3.0 #sigma"); latex.DrawLatex(1.7, 0.0077, "#phi #rightarrow K^{ +} K^{ -}"); latex.SetTextSize(0.035); latex.DrawLatex(1.7, 0.0007, "uncertainties: stat. (bars) & syst. (boxes)"); gPad->Print(Form("%s.pdf", g->GetName())); // gPad->Clear(); // gPad->SetLogy(); // TGraphErrors *g = ReadPtGraphSys("pt/out.txt"); // if (!g) return; // g->Draw("AP"); // gPad->Print(Form("%s.pdf", g->GetName())); }
map<int,vector<double> > RPCChambersCluster::getReconstructedHits(vector<unsigned> vectorOfReferenceChambers, const int & timeWindow,const int & timeReference,bool & isVerticalTrack,map<int,double> & scintilatorsCoordinates,const bool & keepRecoTrack,TFile * fileForRecoTracks,const int & eventNum,const double & correlationFactor, const ESiteFileType & fileType){ // map<int,vector<double> > mapOfHits; // // the default value for Chi2goodness is 20 //double best_chi2goodnes_value = Chi2goodness+10 ; // this variable is used as reference so that it holds the best chi2 found for a track, so its used only a track with better chi2 to be accepted double currentBestCorrFact = -2; int lastFitPoint = 0; for (int i = 0 ; i < this->getNumberOfChambers() ; i++){ this->getChamberNumber(i+1)->findAllClustersForTriggerTimeReferenceAndTimeWindow(timeReference,timeWindow,5); //cout << "Chamber is " << i+1 << endl; } vector<vector<int> > vectorOfClusterNumberCombinations; if (fileType == kIsCERNrawFile ){ assert(vectorOfReferenceChambers.size() == 3 ); lastFitPoint = 9; for ( int i = 0 ; i < this->getChamberNumber(vectorOfReferenceChambers[0])->getNumberOfClusters() ; i++ ){ for( int j = 0 ; j < this->getChamberNumber(vectorOfReferenceChambers[1])->getNumberOfClusters() ; j++ ){ for( int k = 0 ; k < this->getChamberNumber(vectorOfReferenceChambers[vectorOfReferenceChambers.size()-1])->getNumberOfClusters() ; k++ ){ vector<int> singleCombination; singleCombination.push_back(i+1); singleCombination.push_back(j+1); singleCombination.push_back(k+1); for (int f = 0 ; f < singleCombination.size() ; f++){ if(this->getChamberNumber(vectorOfReferenceChambers[f])->getSizeOfCluster(singleCombination.at(f)) > 5 ) continue; // don't insert combination if there is too big cluster. } vectorOfClusterNumberCombinations.push_back(singleCombination); } } } } if (fileType == kIsBARCrawFile || fileType == kIsGENTrawFile ){ // add implementation for BARC and Ghent stand . lastFitPoint = 5; assert(vectorOfReferenceChambers.size() == 2); for ( int i = 0 ; i < this->getChamberNumber(vectorOfReferenceChambers[0])->getNumberOfClusters() ; i++ ){ for( int j = 0 ; j < this->getChamberNumber(vectorOfReferenceChambers[1])->getNumberOfClusters() ; j++ ){ vector<int> singleCombination; singleCombination.push_back(i+1); singleCombination.push_back(j+1); for (int f = 0 ; f < singleCombination.size() ; f++){ if(this->getChamberNumber(vectorOfReferenceChambers[f])->getSizeOfCluster(singleCombination.at(f)) > 5 ) continue; // don't insert combination if there is too big cluster. } vectorOfClusterNumberCombinations.push_back(singleCombination); } } } string topScintToString, botScintToString; for (int combinationsVectorElement = 0 ; combinationsVectorElement < vectorOfClusterNumberCombinations.size() ; combinationsVectorElement ++){ // the partition logic start here - track could pass more than one partition int direction = 0 ; // direction should describe how the partition changes from one reference chamber to another. It vector<int> RefChamberClusterPartition; bool positive = false; bool negative = false; int partitionPenetrated = 1; // the Y coordinate is the partition number (1 2 or 3 - A B or C) vector<int> clusterNum = vectorOfClusterNumberCombinations.at(combinationsVectorElement); for (int ii = 0; ii < clusterNum.size() ; ii++){ RefChamberClusterPartition.push_back(this->getChamberNumber(vectorOfReferenceChambers[ii])->getXYCoordinatesOfCluster(clusterNum.at(ii)).at(1)); } isVerticalTrack = true; for ( int ii = 0; ii < RefChamberClusterPartition.size() - 1 ; ii++ ){ direction = (RefChamberClusterPartition.at(ii) - RefChamberClusterPartition.at(ii+1)); if (direction != 0) { direction = direction/abs(direction); partitionPenetrated++; } // get only the sign ( +1 or -1) if (direction && direction == -1) { positive = true; isVerticalTrack = false; } if (direction && direction == 1 ) { negative = true; isVerticalTrack = false; } } if ( positive && negative ) continue; // cannot have a track that goes in both direction /* TH1F * histXZ = new TH1F("fitHistogram","XZ plane",110,0,11); histXZ->GetYaxis()->SetRangeUser(-20,52); histXZ->SetMarkerColor(kBlue); histXZ->SetMarkerStyle(kCircle); histXZ->GetXaxis()->SetTitle("Shelf number"); histXZ->GetYaxis()->SetTitle("Channel number"); */ TF1 * fitfunc = new TF1("FitTrack","[0]+x*[1]",0,lastFitPoint+1); TGraphErrors * graphXZ = new TGraphErrors(); graphXZ->GetXaxis()->SetTitle("Shelf number"); graphXZ->GetYaxis()->SetTitle("Channel number"); //graphXZ->SetLineColor(0); graphXZ->SetMarkerColor(kBlack); graphXZ->SetMarkerStyle(kFullCircle); graphXZ->SetName("fit graph"); graphXZ->SetTitle("XZ plane"); graphXZ->GetXaxis()->SetTitle("Muon station"); graphXZ->GetYaxis()->SetTitle("Channel number"); fitfunc->SetLineColor(kBlue); vector<double> coordinates; double xCoordinate = 0; int yCoordinate = 0; int zCoorinate = 0; for (int ii=0 ; ii < vectorOfReferenceChambers.size() ; ii++){ coordinates = this->getChamberNumber(vectorOfReferenceChambers[ii])->getXYCoordinatesOfCluster(clusterNum[ii]); xCoordinate = coordinates.at(0); yCoordinate = coordinates.at(1); zCoorinate = 10*vectorOfReferenceChambers[ii]; Double_t errorValue = this->getChamberNumber(vectorOfReferenceChambers[ii])->getSizeOfCluster(clusterNum[ii]); // histXZ->SetBinContent(zCoorinate,xCoordinate); // histXZ->SetBinError(zCoorinate,errorValue/2); //cout << xCoordinate << " " << yCoordinate << endl; graphXZ->SetPoint(ii,vectorOfReferenceChambers[ii],xCoordinate); graphXZ->SetPointError(ii,0,errorValue/2); } Double_t params[2]; graphXZ->Fit(fitfunc,"RFQ"); fitfunc->GetParameters(params); //cout << "par1 " << params[0] << " par2 " << params[1] << " chi2 " << fitfunc->GetChisquare() << endl; // The resudials - difference between estimated fit value and the middle of the nearest cluster int prevReference = 0 , nextReference = 0 , prevReferencePartition = 0 , nextReferencePartition = 0; bool currentChamberIsReference = false; int startCounter = 0, endCounter = 0; if ( abs(graphXZ->GetCorrelationFactor()) >= correlationFactor && abs(graphXZ->GetCorrelationFactor()) > currentBestCorrFact ) { // in case of only one partition, get the partition number of the first reference point currentBestCorrFact = abs(graphXZ->GetCorrelationFactor()); int referenceChambersIncrementor = 0; bool negativeChannelNumberIsFound = false; // --------- for ( int currentChNumber = 0 ; currentChNumber < this->getNumberOfChambers() ; currentChNumber++ ) { // check where the chamber is according to the reference chambers vector<double> vectorOfpartitionsAndHit; double channelNum = fitfunc->Eval(currentChNumber+1); /** four cases 1. the chamber is before the first reference 2. the chamber is after the last reference 3. the chamber is between two references 4. the chamber is a reference */ for(int refCheck = 0 ; refCheck < vectorOfReferenceChambers.size(); refCheck++){ // find the surounding references if (currentChNumber+1 == vectorOfReferenceChambers.at(refCheck)){ currentChamberIsReference = true; break; } if ( vectorOfReferenceChambers.at(refCheck) > currentChNumber+1 && refCheck == 0 ){ // its before the first reference chamber nextReference = vectorOfReferenceChambers.at(refCheck); nextReferencePartition = this->getChamberNumber(nextReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1); break; } if ( vectorOfReferenceChambers.at(refCheck) < currentChNumber+1 && refCheck == vectorOfReferenceChambers.size() - 1 ){ // its after the last chamber prevReference = vectorOfReferenceChambers.at(refCheck); prevReferencePartition = this->getChamberNumber(prevReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1); break; } if ( vectorOfReferenceChambers.at(refCheck) < currentChNumber+1 && vectorOfReferenceChambers.at(refCheck+1) > currentChNumber+1 ){ // its between two references prevReference = vectorOfReferenceChambers.at(refCheck) ; nextReference = vectorOfReferenceChambers.at(refCheck+1); prevReferencePartition = this->getChamberNumber(prevReference)->getXYCoordinatesOfCluster(clusterNum[refCheck]).at(1); nextReferencePartition = this->getChamberNumber(nextReference)->getXYCoordinatesOfCluster(clusterNum[refCheck+1]).at(1); break; } } // end of partition possibilities if(!currentChamberIsReference){ if (nextReference && prevReference == 0){ if (positive){ prevReferencePartition = 1; } if(negative){ prevReferencePartition = this->getChamberNumber(1)->getClones(); } } if (prevReferencePartition && nextReferencePartition == 0){ if (positive){ nextReferencePartition = this->getChamberNumber(1)->getClones(); } if(negative){ nextReferencePartition = 1; } } if (partitionPenetrated == 1 ){ prevReferencePartition = yCoordinate; nextReferencePartition = yCoordinate; int firstRef = vectorOfReferenceChambers.at(0); int lastRef = vectorOfReferenceChambers.at(vectorOfReferenceChambers.size() - 1); int ccham = currentChNumber+1; if(! (lastRef > ccham && firstRef < ccham) ){ // all partitions are possible, chambers are out of the reference scope prevReferencePartition = this->getChamberNumber(1)->getClones(); nextReferencePartition = 1; // 3 in case of ecap chamber } } if (positive){ startCounter = prevReferencePartition; endCounter = nextReferencePartition; } else { startCounter = nextReferencePartition ; endCounter = prevReferencePartition ; } for (int currentCounter = startCounter ; currentCounter <= endCounter; currentCounter ++ ){ assert(currentCounter > 0 && currentCounter < 4); vectorOfpartitionsAndHit.push_back(currentCounter); } } else{ vectorOfpartitionsAndHit.push_back(this->getChamberNumber(currentChNumber+1)->getXYCoordinatesOfCluster(clusterNum[referenceChambersIncrementor]).at(1)); referenceChambersIncrementor ++; } prevReference = 0 ; nextReference = 0 ; prevReferencePartition = 0 ; nextReferencePartition = 0; currentChamberIsReference = false; //cout << "Chamber " << l+1 << " " << coordinates.at(1) << " " << fitfunc->Eval(l+1) << " " << endl; int channelNumberToStore = channelNum; if (channelNumberToStore < 96/this->getChamberNumber(1)->getClones()){ channelNumberToStore += 1; } // add one to represent the fired channel, or none if the channel is on the right border vectorOfpartitionsAndHit.push_back(channelNumberToStore); // the last element is the number of the channel // Debug lines /** cout << "Chamber is " << currentChNumber+1 << " partitions " ; for (int thesize = 0 ; thesize < vectorOfpartitionsAndHit.size() - 1; thesize++){ cout << vectorOfpartitionsAndHit.at(thesize) << " " ; } cout << "channel " << vectorOfpartitionsAndHit.at(vectorOfpartitionsAndHit.size()-1) << endl; */ mapOfHits[currentChNumber+1] = vectorOfpartitionsAndHit; } // ---------- scintilators coordinates estimate for (int scintNum = 0 ; scintNum < 31 ; scintNum++){ if(this->getTriggerObjectNumber(1)->getChannel(scintNum+1)->hasHit() && vectorOfClusterNumberCombinations.size() == 1 ) { if (scintNum < 10) { scintilatorsCoordinates[scintNum+1] = graphXZ->Eval(0); topScintToString = boost::lexical_cast<string>(scintNum+1); } else { scintilatorsCoordinates[scintNum+1] = graphXZ->Eval(lastFitPoint+1); botScintToString = boost::lexical_cast<string>(scintNum+1); } } } } // get only vertical tracks from the A partition if there are only two scint hits if (keepRecoTrack && isVerticalTrack && !mapOfHits.empty() && scintilatorsCoordinates.size() == 2){ graphXZ->SetName(boost::lexical_cast<string>(eventNum).c_str()); string partition; if (mapOfHits.find(vectorOfReferenceChambers.at(0))->second.at(0) == 1) partition = "A"; else if (mapOfHits.find(vectorOfReferenceChambers.at(0))->second.at(0) == 2) partition = "B"; else partition = "C"; graphXZ->SetTitle(("Correlation factor is "+boost::lexical_cast<string>(graphXZ->GetCorrelationFactor()) + " trigger channels top: " + topScintToString + " bottom: " + botScintToString ).c_str()); if(abs(graphXZ->GetCorrelationFactor()) >= correlationFactor) { string scintCombination="_"+topScintToString+"_"+botScintToString+"_"+partition; TDirectory * dir = fileForRecoTracks->GetDirectory(scintCombination.c_str(),true); if(!dir) { //fileForRecoTracks->ls(); fileForRecoTracks->mkdir(scintCombination.c_str()) ; fileForRecoTracks->cd(""); } fileForRecoTracks->cd(scintCombination.c_str()); //cout << fileForRecoTracks->GetPath() << endl; } else{ fileForRecoTracks->cd("") ; fileForRecoTracks->cd("badTracks") ; } graphXZ->Write(graphXZ->GetName(),TObject::kOverwrite); fileForRecoTracks->cd(""); //fileForRecoTracks->Write(graphXZ->GetName(),TObject::kOverwrite); } fitfunc->Delete(); //histXZ->Delete(); graphXZ->Delete(); } return mapOfHits; }
//======================================================================== void joingraphsX(const char* myname, const char* g1 , int autocolors=1 ){ TMultiGraph *mg; TString myname2=myname; myname2.ReplaceAll(".","_"); myname2.ReplaceAll(" ","_"); myname2.ReplaceAll("_mysql_dat","_mysql_MG"); if ( ( gROOT->GetListOfSpecials()->FindObject(myname2.Data()) ) || ((gPad!=NULL)&&(gPad->FindObject(myname2.Data()) )) ){ mg=(TMultiGraph*)gROOT->GetListOfSpecials()->FindObject( myname2.Data() ); if (mg==NULL){mg=(TMultiGraph*)gPad->FindObject( myname2.Data() );} printf("JG...TMultiGraph %s found...\n",myname2.Data() ); }else{ printf("JG...TMultiGraph %s created\n",myname2.Data() ); mg=new TMultiGraph(); mg->SetNameTitle(myname2.Data(),myname2.Data()); gROOT->GetListOfSpecials()->Add( mg ); } TGraphErrors *o; o=(TGraphErrors*)gROOT->GetListOfSpecials()->FindObject( g1 ); if (o==NULL){ o=(TGraphErrors*)gDirectory->FindObject( g1 ); } if (o==NULL){ printf("JG...graph %ld NOT found...\n", (int64_t)g1 ); }else{ int ent=0; if ( mg->GetListOfGraphs()!=NULL){ ent=mg->GetListOfGraphs()->GetEntries(); } // ent=1; printf("JG...multigraph entries =%d\n", ent); // if (mg->GetListOfGraphs()->FindObject(o->GetTitle())==NULL){ TGraphErrors *grexi=NULL; TList *glog= mg->GetListOfGraphs(); if (glog!=NULL){grexi=(TGraphErrors*)glog->FindObject(o->GetName()) ;} printf("JG...TEST1 Graph name %s ---------------\n", o->GetName() ); if (grexi!=NULL){ int col=grexi->GetLineColor(); printf("JG...Graph name %s exists, color=%d doing nothing\n", o->GetName() , col ); printf("%s\n","JG removing"); mg->RecursiveRemove(grexi); printf("%s\n","JG adding"); mg->Add( (TGraphErrors*)o , "PL" ) ; o->SetLineColor(col); o->SetMarkerColor(col); }else{ // printf("TEST2 Graph name %s not yet in MG\n",o->GetName() ); if (autocolors==1){ // for new // printf("setting autocolor %d\n", ent); o->SetLineColor(ent+1); o->SetMarkerColor(ent+1); }else{ // printf("NO autocolor (graphs=%d)\n", ent); } // char oname[100]; // sprintf(oname,"%s",o->GetName()); // printf("%s /%s/\n", "JG... looking for duplicity", oname ); // TObject *dupl=NULL; // if ( (o!=NULL)&&(mg->GetListOfGraphs()!=NULL)){ dupl=(TObject*)mg->GetListOfGraphs()->FindObject( oname ); } // printf("%s\n", "JG... looking for duplicity" ); // if (dupl!=NULL){ // printf("%s\n", "JG... duplicite found" ); // for (int i=0;i<mg->GetListOfGraphs()->GetEntries();i++){ // if (mg->GetListOfGraphs()->At(i)==dupl){ // mg->GetListOfGraphs()->RemoveAt(i); // break; // } // } // } printf("%s\n", "JG... adding the object" ); mg->Add( (TGraphErrors*)o , "PL" ) ; }//=========else NEW double ttmax=0.,ttmin=0.; for (int i=0;i<mg->GetListOfGraphs()->GetEntries();i++){ printf("JG... %d. %10s, total=%d\n", i, mg->GetListOfGraphs()->At(i)->GetName(),mg->GetListOfGraphs()->GetEntries() ); TGraphErrors *ge=(TGraphErrors*)mg->GetListOfGraphs()->At(i); int n = ge->GetN(); double* x = ge->GetX(); int locmin = TMath::LocMin(n,x); double tmin = x[locmin]; int locmax = TMath::LocMax(n,x); double tmax = x[locmax]; if (ttmin==ttmax){ttmax=tmax;ttmin=tmin;} // printf("%f - %f\n", tmin, tmax); if (ttmax<tmax){ttmax=tmax;} if (ttmin>tmin){ttmin=tmin;} // printf("%d. %s\n", i, mg->GetListOfGraphs()->At(i)->GetTitle() ); }// for all graphs if (mg->GetXaxis()!=NULL){ // if not drawn, no possibility to change-refresh! mg->GetXaxis()->SetLimits( ttmin,ttmax ); mg->GetXaxis()->SetTimeDisplay(1); mg->GetXaxis()->SetTimeFormat("#splitline{%d.%m}{%H:%M}"); } // printf("Graph title %s added, exists=%d\n", o->GetTitle(), grexi ); // }else{ // mg->RecursiveRemove( (TGraphErrors*)o ) ; // } }//graph found? // gROOT->GetListOfSpecials()->Add( gROOT->GetListOfSpecials()->FindObject( g1 ) ); //// for (int i=0;i<imax;i++){ mg->Add( gg[i],"lp"); } }////========== void joingraphsX(const char* myname, const char* g1 ){ ================
void AnalyzeWaveforms(char *WaveformsFile = "Waveforms.root", const int nAddedChannels = 5) { //try to access waveforms file and in case of failure return if(gSystem->AccessPathName(WaveformsFile,kFileExists)) { cout << "Error: file " << WaveformsFile << " does not exsist. Run .x WaveformsFileMaker.C to create it" << endl; return; } // gStyle->SetOptFit(111); // gStyle->SetStatFormat("1.3E"); // gStyle->SetFitFormat("1.3E"); // fetch the list of trees contained in the waveforms file // for every tree generate a waveform graph TFile *f = TFile::Open(WaveformsFile); TList *listOfKeys = f->GetListOfKeys(); Int_t numberOfKeys = listOfKeys->GetEntries(); TList *listOfGraphs = new TList(); // if the waveform file name begins with the string "comparator" it goes in this list TList *listOfCompWaves = new TList(); // if the waveform file name begins with the string "sum output" it goes in this list TList *listOfAdderWaves = new TList(); for(Int_t i = 0; i < numberOfKeys; i++) { TString *keyName = new TString(listOfKeys->At(i)->GetName()); TTree *tree = (TTree*)f->Get(keyName->Data()); Float_t x = 0; Float_t y = 0; tree->SetBranchAddress("x",&x); tree->SetBranchAddress("y",&y); Int_t nentries = tree->GetEntries(); TString *gName = new TString(keyName->Data()); gName->Append(" graph"); TGraphErrors *gWave = new TGraphErrors(nentries); gWave->SetName(gName->Data()); gWave->SetTitle(gName->Data()); gWave->GetXaxis()->SetTitle("Time"); gWave->GetYaxis()->SetTitle("Voltage"); // gWave->SetBit(TH1::kCanRebin); for (Int_t j = 0; j < nentries; j++) { tree->GetEntry(j); gWave->SetPoint(j,x,y); } listOfGraphs->Add(gWave); if(keyName->BeginsWith("comparator")) listOfCompWaves->Add(gWave); if(keyName->BeginsWith("sum output")) listOfAdderWaves->Add(gWave); /* TString *cName = new TString(keyName->Data()); cName->Append(" canvas"); TCanvas *cy = new TCanvas(cName->Data(),cName->Data(),800,600); gWave->Draw("AL"); */ } cout << listOfAdderWaves->GetEntries() << endl; // analysis for waves with no delay // global variables Double_t xMin,xMax,yStart,yEnd; Int_t graphPoints; Double_t step; // comparator outputs waves sum TGraphErrors *gFirstCompWave = (TGraphErrors *)listOfCompWaves->First(); graphPoints = gFirstCompWave->GetN(); gFirstCompWave->GetPoint(0,xMin,yStart); gFirstCompWave->GetPoint(graphPoints - 1,xMax,yEnd); step = (xMax - xMin)/graphPoints; cout << gFirstCompWave->GetName() << endl; cout << "xMin = " << xMin << " xMax = " << xMax << " graphPoints = " << graphPoints << endl; TGraphErrors *gCompSum = new TGraphErrors(graphPoints); gCompSum->SetLineColor(kBlue); gCompSum->SetLineWidth(2); gCompSum->SetName("Comparator Outputs Sum"); gCompSum->SetTitle("Comparator Outputs Sum"); Int_t nCompWaves = listOfCompWaves->GetEntries(); Float_t gx,gy = 0; // Alpha coefficiens are now written "hard coded" here Float_t alphaArray[3] = {0.199,0.201,0.197}; // Deleays coming from the multiplexer are written "hard coded" here Float_t muxDelayArray[3] = {0,77.14E-12,192.01E-12}; for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nCompWaves; j++) { TGraphErrors *gCompWave = (TGraphErrors *)listOfCompWaves->At(j); gy += (gCompWave->Eval(xMin + i*step + muxDelayArray[j]))*alphaArray[j]; } gCompSum->SetPoint(i,xMin + i*step,gy); gy = 0; } // note that there is a manual correction on the x axis for the comparator waves sum to compare them better in the multigraph Double_t *xArray = gCompSum->GetX(); for(Int_t i = 0; i < graphPoints; i++) { xArray[i] += 5.6E-9; } // TCanvas *cCompSum = new TCanvas("cCompSum","Comparator Outputs Sum",800,600); // gCompSum->Draw("AL"); // adder outputs waves sum // THE ANALYSIS FOR THE ADDER OUTPUT WITH NOT DELAY AND 3 CHANNELS ADDED IS DEPRECATED. // THERE WAS A MISTAKE IN THE DATA TAKING // I'LL KEEP THE CODE HERE FOR FURTHER REFERENCE /* TGraphErrors *gFirstAdderWave = (TGraphErrors *)listOfAdderWaves->First(); graphPoints = gFirstAdderWave->GetN(); gFirstAdderWave->GetPoint(0,xMin,yStart); gFirstAdderWave->GetPoint(graphPoints - 1,xMax,yEnd); step = (xMax - xMin)/graphPoints; cout << gFirstAdderWave->GetName() << endl; cout << "xMin : " << xMin << " xMax : " << xMax << endl; TGraphErrors *gAdderSum = new TGraphErrors(graphPoints); gAdderSum->SetLineWidth(2); // gAdderSum->SetLineColor(kGreen); gAdderSum->SetLineStyle(9); gAdderSum->SetName("Sum of the adder outputs with no delay"); gAdderSum->SetTitle("Sum of the adder outputs with no delay"); Int_t nAdderWaves = listOfAdderWaves->GetEntries(); gy = 0; for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nAdderWaves; j++) { TGraphErrors *gAdderWave = (TGraphErrors *)listOfAdderWaves->At(j); gy += gAdderWave->Eval(xMin + i*step); } gAdderSum->SetPoint(i,xMin + i*step,gy); gy = 0; } // TCanvas *cAdderSum = new TCanvas("cAdderSum","Sum of the adder outputs",800,600); // gAdderSum->Draw("AL"); TGraphErrors *g3ChannelsSumNoDelay = listOfGraphs->FindObject("sum_output_3_channels_(3) graph"); g3ChannelsSumNoDelay->SetLineColor(kRed); g3ChannelsSumNoDelay->SetLineWidth(2); // note that there is a manual correction on the x axis for the adder output to compare it better in the multigraph Double_t *xArray = g3ChannelsSumNoDelay->GetX(); graphPoints = g3ChannelsSumNoDelay->GetN(); for(Int_t i = 0; i < graphPoints; i++) { xArray[i] -= 600E-12; } // comparison among the computed adder output ,the real one and the sum of the comparator outputs with alpha coefficients correction TMultiGraph *mgSumNoDelay = new TMultiGraph(); mgSumNoDelay->Add(g3ChannelsSumNoDelay); mgSumNoDelay->Add(gAdderSum); mgSumNoDelay->Add(gCompSum); mgSumNoDelay->SetTitle("Collection of graphs for 3 channels sum with no delay"); TCanvas *cmgSumNoDelay = new TCanvas("cmgSumNoDelay", "Collection of graphs for 3 channels sum with no delay", 1200,800); cmgSumNoDelay->Update(); mgSumNoDelay->Draw("AL"); legend = new TLegend(0.6,0.78,0.99,0.99); legend->AddEntry(g3ChannelsSumNoDelay, "Actual sum done by the adder", "lp"); legend->AddEntry(gAdderSum, "Sum of the adder outputs", "lp"); legend->AddEntry(gCompSum, "Sum of the comparator outputs","lp"); legend->Draw(); mgSumNoDelay->GetXaxis()->SetTitle("Seconds"); mgSumNoDelay->GetYaxis()->SetTitle("Volts"); TPaveText *title = (TPaveText*)cmgSumNoDelay->GetPrimitive("title"); title->SetX1NDC(0.009); title->SetY1NDC(0.94); title->SetX2NDC(0.56); title->SetY2NDC(0.99); cmgSumNoDelay->Modified(); */ // analysis for delayed adder outputs Int_t nAdderWaves = listOfAdderWaves->GetEntries(); TGraphErrors *g3ChannelsSumDelay = listOfGraphs->FindObject("sum_output_3_channels_(1-1-1) graph"); g3ChannelsSumDelay->SetLineColor(kRed); g3ChannelsSumDelay->SetLineWidth(2); // Delay coming from cables are written "hard coded" here Float_t cablesDelayArray[3] = {0,1.45E-9,3.21E-9}; graphPoints = g3ChannelsSumDelay->GetN(); //g3ChannelsSumDelay->GetPoint(0,xMin,yStart); //g3ChannelsSumDelay->GetPoint(graphPoints - 1,xMax,yEnd); xMin = 6E-9; xMax = 16E-9; step = (xMax - xMin)/graphPoints; cout << "Sum of the adder outputs with delay" << endl; cout << "xMin : " << xMin << " xMax : " << xMax << endl; TGraphErrors *gAdderSumDelay = new TGraphErrors(graphPoints); gAdderSumDelay->SetLineColor(kBlue); gAdderSumDelay->SetLineWidth(2); gAdderSumDelay->SetName("Sum of the adder outputs with delay"); gAdderSumDelay->SetTitle("Sum of the adder outputs with delay"); gy = 0; // note that there is a manual correction on the delay of 500E-12 to compare the adder output better in the multigraph for(Int_t i = 0; i < graphPoints; i++) { for(Int_t j = 0; j < nAdderWaves; j++) { TGraphErrors *gAdderWave = (TGraphErrors *)listOfAdderWaves->At(j); gy += gAdderWave->Eval(xMin + i*step + cablesDelayArray[j] - 500E-12); } gAdderSumDelay->SetPoint(i,xMin + i*step,gy); gy = 0; } // TCanvas *cSumSumDelay = new TCanvas("cSumSumDelay","Sum of the sum outputs with delay",800,600); // gAdderSumDelay->Draw("APEL"); TMultiGraph *mg3ChannelsSumDelay = new TMultiGraph(); mg3ChannelsSumDelay->Add(gAdderSumDelay); mg3ChannelsSumDelay->Add(g3ChannelsSumDelay); mg3ChannelsSumDelay->SetTitle("Collection of graphs for 3 channels sum with delay"); TCanvas *cmg3ChannelsSumDelay = new TCanvas("cmg3ChannelsSumDelay", "Collection of graphs for 3 channels sum with delay", 1200, 800); cmg3ChannelsSumDelay->Update(); legend = new TLegend(0.6,0.78,0.99,0.99); legend->AddEntry(g3ChannelsSumDelay, "Actual sum done by the adder", "lp"); legend->AddEntry(gAdderSumDelay, "Sum of the delayed adder outputs", "lp"); mg3ChannelsSumDelay->Draw("AL"); legend->Draw(); mg3ChannelsSumDelay->GetXaxis()->SetTitle("Seconds"); mg3ChannelsSumDelay->GetYaxis()->SetTitle("Volts"); TPaveText *title = (TPaveText*)cmg3ChannelsSumDelay->GetPrimitive("title"); title->SetX1NDC(0.009); title->SetY1NDC(0.94); title->SetX2NDC(0.56); title->SetY2NDC(0.99); cmg3ChannelsSumDelay->Modified(); /* // delay test just to try a different method TMultiGraph *mgDelayTest = new TMultiGraph(); Double_t gxTest,gyTest; TGraphErrors *gDelayTest0 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(0))->GetN()); for(Int_t j = 0; j < gDelayTest0->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(0))->GetPoint(j,gxTest,gyTest); gDelayTest0->SetPoint(j,gxTest - cablesDelayArray[0],gyTest); } mgDelayTest->Add(gDelayTest0); TGraphErrors *gDelayTest1 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(1))->GetN()); for(Int_t j = 0; j < gDelayTest1->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(1))->GetPoint(j,gxTest,gyTest); gDelayTest1->SetPoint(j,gxTest - cablesDelayArray[1],gyTest); } mgDelayTest->Add(gDelayTest1); TGraphErrors *gDelayTest2 = new TGraphErrors(((TGraphErrors *)listOfAdderWaves->At(2))->GetN()); for(Int_t j = 0; j < gDelayTest2->GetN(); j++) { ((TGraphErrors *)listOfAdderWaves->At(2))->GetPoint(j,gxTest,gyTest); gDelayTest2->SetPoint(j,gxTest - cablesDelayArray[2],gyTest); } mgDelayTest->Add(gDelayTest2); // TCanvas *cmgDelayTest = new TCanvas("cmgDelayTest", "cmgDelayTest", 800,600); // mgDelayTest->Draw("APEL"); graphPoints = 12000; xMin = 2E-9; xMax = 22E-9; step = (xMax - xMin)/graphPoints; cout << "xMin : " << xMin << " xMax : " << xMax << endl; Double_t delayTest0xMin,delayTest0xMax,delayTest1xMin,delayTest1xMax,delayTest2xMin,delayTest2xMax; gDelayTest0->GetPoint(0,delayTest0xMin,gyTest); gDelayTest0->GetPoint(gDelayTest0->GetN() - 1,delayTest0xMax,gyTest); gDelayTest1->GetPoint(0,delayTest1xMin,gyTest); gDelayTest1->GetPoint(gDelayTest1->GetN() - 1,delayTest1xMax,gyTest); gDelayTest2->GetPoint(0,delayTest2xMin,gyTest); gDelayTest2->GetPoint(gDelayTest2->GetN() - 1,delayTest2xMax,gyTest); cout << delayTest0xMin << endl; TGraphErrors *gAdderSumDelayV2 = new TGraphErrors(graphPoints); for(Int_t i = 0; i < graphPoints; i++) { gyTest = gDelayTest0->Eval(xMin + i*step); gyTest += gDelayTest1->Eval(xMin + i*step); gyTest += gDelayTest2->Eval(xMin + i*step); gAdderSumDelayV2->SetPoint(i,xMin + i*step+ 500E-12,gyTest); } gAdderSumDelayV2->SetLineColor(kGreen); gAdderSumDelayV2->SetLineWidth(2); mg3ChannelsSumDelay->Add(gAdderSumDelayV2); c3ChannelsSumDelay->Modified(); TCanvas *cAdderSumDelayV2 = new TCanvas("cAdderSumDelayV2","cAdderSumDelayV2",800,600); gAdderSumDelayV2->Draw("APL"); */ // List of waves representing the adder output with 5,4,3,2,1 channels in input TGraphErrors *gAdder5Channels = listOfGraphs->FindObject("adder output 5 channels v2 graph"); TGraphErrors *gAdder4Channels = listOfGraphs->FindObject("adder output 4 channels v2 graph"); TGraphErrors *gAdder3Channels = listOfGraphs->FindObject("adder output 3 channels v2 graph"); TGraphErrors *gAdder2Channels = listOfGraphs->FindObject("adder output 2 channels v2 graph"); TGraphErrors *gAdder1Channel = listOfGraphs->FindObject("adder output 1 channel v2 graph"); TGraphErrors *gAdderSingleCh0 = listOfGraphs->FindObject("single sum output ch 0 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh1 = listOfGraphs->FindObject("single sum output ch 1 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh4 = listOfGraphs->FindObject("single sum output ch 4 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh5 = listOfGraphs->FindObject("single sum output ch 5 input 500 mV DT 100 mV graph"); TGraphErrors *gAdderSingleCh7 = listOfGraphs->FindObject("single sum output ch 7 input 500 mV DT 100 mV graph"); TMultiGraph *mgAdder54321Channels = new TMultiGraph(); mgAdder54321Channels->SetTitle("Collection of graphs for different numbers of added channels"); mgAdder54321Channels->Add(gAdder5Channels); mgAdder54321Channels->Add(gAdder4Channels); mgAdder54321Channels->Add(gAdder3Channels); mgAdder54321Channels->Add(gAdder2Channels); mgAdder54321Channels->Add(gAdder1Channel); TCanvas *cmgAdder54321Channels = new TCanvas("cmgAdder54321Channels", "Collection of graphs for different numbers of added channels",1200,800); mgAdder54321Channels->Draw("AL"); cmgAdder54321Channels->Update(); mgAdder54321Channels->GetXaxis()->SetTitle("seconds"); mgAdder54321Channels->GetYaxis()->SetTitle("Volts"); cmgAdder54321Channels->Modified(); // analysis of the linearity of the adder Double_t addedVMax[nAddedChannels]; addedVMax[0] = TMath::MaxElement(gAdder1Channel->GetN(), gAdder1Channel->GetY()); addedVMax[1] = TMath::MaxElement(gAdder2Channels->GetN(), gAdder2Channels->GetY()); addedVMax[2] = TMath::MaxElement(gAdder3Channels->GetN(), gAdder3Channels->GetY()); addedVMax[3] = TMath::MaxElement(gAdder4Channels->GetN(), gAdder4Channels->GetY()); addedVMax[4] = TMath::MaxElement(gAdder5Channels->GetN(), gAdder5Channels->GetY()); Double_t singleVMax[nAddedChannels]; singleVMax[0] = TMath::MaxElement(gAdderSingleCh0->GetN(), gAdderSingleCh0->GetY()); singleVMax[1] = TMath::MaxElement(gAdderSingleCh1->GetN(), gAdderSingleCh1->GetY()); singleVMax[2] = TMath::MaxElement(gAdderSingleCh4->GetN(), gAdderSingleCh4->GetY()); singleVMax[3] = TMath::MaxElement(gAdderSingleCh5->GetN(), gAdderSingleCh5->GetY()); singleVMax[4] = TMath::MaxElement(gAdderSingleCh7->GetN(), gAdderSingleCh7->GetY()); vector<double> expectedVMax(nAddedChannels); Double_t previousVmax = 0; for(Int_t i = 0; i < expectedVMax.size(); i++) { expectedVMax[i] = singleVMax[i] + previousVmax; previousVmax = expectedVMax[i]; cout << "singleVMax[" <<i <<"] = " << singleVMax[i] << endl; cout << "addedVMax[" <<i <<"] = " << addedVMax[i] << endl; cout << "expectedVMax[" <<i <<"] = " << expectedVMax[i] << endl; } TGraph *gAdderLinearity = new TGraph(expectedVMax.size(),&expectedVMax[0],addedVMax); gAdderLinearity->SetTitle("Linearity of the adder"); gAdderLinearity->GetXaxis()->SetTitle("Expected amplitude value (V)"); gAdderLinearity->GetYaxis()->SetTitle("Actual amplitude value (V)"); gAdderLinearity->GetYaxis()->SetTitleOffset(1.3); TCanvas *cgAdderLinearity = new TCanvas("cgAdderLinearity","Linearity of the adder",800,600); cgAdderLinearity->SetGrid(); cgAdderLinearity->Update(); gAdderLinearity->SetMarkerStyle(20); gAdderLinearity->SetMarkerSize(0.8); //gAdderLinearity->Fit("pol1","Q+","",expectedVMax[0],expectedVMax[2]); TF1 *line = new TF1("line","x",expectedVMax.back(),expectedVMax.front()); gAdderLinearity->Draw("APEL"); line->Draw("SAME"); //gAdderLinearity->GetFunction("pol1")->SetRange(expectedVMax.back(),expectedVMax.front());; cgAdderLinearity->SetLeftMargin(0.13); cgAdderLinearity->Modified(); f->Close(); }