Esempio n. 1
0
int main (int argc, char *argv[]) {

          
	if (argc < PDB_INDEX+1) 
	{
	cout <<"Usage:"<<argv[0]<<" monomer.ruf.pstrm\n";
	exit(1);
	}//end of if
	
	coord_struct  asa;
	int    i,j;
	char p_n[20];
	vector<char> chain;
        vector<aa> w_c, w_c2;	

        vector<aa_asa> std_asa; 
        vector<naa2>w_c4;
        vector<naa>w_c3;

        vector<residue>a_w_c;
	
        vector<protein_rou> proteins_rou;	
	
	char *c_a;
	c_a=new char[1];
	

         vector<protein> whole_protein;
         vector<aa> wc_c_aa2,wc_t_aa2;
         vector<naa> wc_c_aa3,wc_t_aa3;
	
        
	 ifstream protein_file("monomer_u.txt",ios::in);

         char *file_name;
         file_name=new char[10];

         while(protein_file>>file_name)
        {

	read_asa_file(w_c,asa,file_name);
        cal_tot_asa_of_res(w_c4,w_c);

        // cout<<setiosflags(ios::left)<<setw(15)<<file_name<<setiosflags(ios::left)<<setw(10)<<w_c.size()<<endl;
        // w_c.clear();

        //geo_cen_of_res(wc_c_aa3,wc_c_aa2,a_w_c,w_c);
          //res_alpha_atom(wc_c_aa3,wc_c_aa2,a_w_c,w_c);
        
        //cout<<whole_protein.size()<<endl; 
           

            
	geo_cen_of_side_chain2(wc_c_aa3,wc_c_aa2,w_c);
	ter_atom_of_side_chain2(wc_t_aa3,wc_t_aa2,w_c);
 

	for(i=0;i<wc_c_aa3.size();i++)
        {
           wc_c_aa3[i].angle_t=1000;
	}

	
	for(i=0;i<wc_c_aa3.size();i++)
        {
         for(j=0;j<wc_t_aa3.size();j++)
         {
         if(wc_c_aa3[i].res_num==wc_t_aa3[j].res_num&&wc_c_aa3[i].chain_type==wc_t_aa3[j].chain_type&&
            (strncmp(wc_c_aa3[i].res_id,wc_t_aa3[j].res_id,3)==0))
          {
           wc_c_aa3[i].angle_t=wc_t_aa3[j].angle;
          }//end of if
         }//end of for
        }// end of for
        
	for(i=0;i<wc_c_aa3.size();i++)
        {
         for(j=0;j<w_c4.size();j++)
         {
         if(wc_c_aa3[i].res_num==w_c4[j].res_num&&wc_c_aa3[i].chain_type==w_c4[j].chain_type&&
            (strncmp(wc_c_aa3[i].res_id,w_c4[j].res_id,3)==0))
          {
           wc_c_aa3[i].asa=w_c4[j].tot_atom_asa;
          }//end of if
         }//end of for
        }// end of for
/*
	cout<<setiosflags(ios::left)<<setw(8)<<"res_num"
        <<setiosflags(ios::left)<<setw(8)<<"res_id"
        <<setiosflags(ios::left)<<setw(8)<<"ch_type"
        <<setiosflags(ios::left)<<setw(8)<<"an_c_c"
        <<setiosflags(ios::left)<<setw(8)<<"an_c_t"
	<<setiosflags(ios::left)<<setw(8)<<"asa"<<endl;
	
	for(i=0;i<wc_c_aa3.size();i++)
	{
	cout<<setiosflags(ios::left)<<setw(8)<<wc_c_aa3[i].res_num
        <<setiosflags(ios::left)<<setw(8)<<wc_c_aa3[i].res_id
        <<setiosflags(ios::left)<<setw(8)<<wc_c_aa3[i].chain_type
        <<setiosflags(ios::fixed)
        <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<wc_c_aa3[i].angle
        <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<wc_c_aa3[i].angle_t
 	<<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<wc_c_aa3[i].asa<<endl;
	}//end of for
  */
        
        
        residue one_residue;
        one_residue.res_id=new char[5];

        
        protein one_protein;
        one_protein.protein_name=new char[10];

        strcpy(one_protein.protein_name,strtok(file_name,"."));

        for(i=0;i<wc_c_aa3.size();i++)
        {
          one_residue.res_id=wc_c_aa3[i].res_id;
          one_residue.res_num=wc_c_aa3[i].res_num;
          one_residue.chain_type=wc_c_aa3[i].chain_type;
          one_residue.angle=wc_c_aa3[i].angle;
          one_residue.asa=wc_c_aa3[i].asa;
          one_protein.residue_str.push_back(one_residue); 
        }
        whole_protein.push_back(one_protein);

        one_protein.residue_str.clear();
        wc_c_aa2.clear();
        wc_t_aa2.clear();
        wc_c_aa3.clear();
        wc_t_aa3.clear();
        w_c4.clear();
        w_c.clear();  
         
        }//end of while 

        //these two functions are in read_dimer.cpp file     
	read_pdb_file(proteins_rou,argv[PDB_INDEX]);
        calculate_roughness_of_residue(proteins_rou);   
	
	 ofstream output("results3_asa.txt",ios::out);
         int m,n,tt;

	for(i=0;i<whole_protein.size();i++)
         {
          for(m=0;m<whole_protein[i].residue_str.size();m++)
           {whole_protein[i].residue_str[m].roughness=-100;}
         }

          for(j=0;j<proteins_rou.size();j++)
            {
             for(n=0;n<proteins_rou[j].w_c_rou.size();n++)
              {
              proteins_rou[j].w_c_rou[n].asa=0;  
              }
            }               
       

         tt=0;    
	for(i=0;i<whole_protein.size();i++)
	{
          for(j=0;j<proteins_rou.size();j++)
           {
            if(strcmp(whole_protein[i].protein_name,strtok(proteins_rou[j].protein_rou_id,"."))==0) 
           {
        	for(m=0;m<whole_protein[i].residue_str.size();m++)
        	{
                  for(n=0;n<proteins_rou[j].w_c_rou.size();n++)
                   {
                     if(whole_protein[i].residue_str[m].res_num==proteins_rou[j].w_c_rou[n].res_num&&
                       *whole_protein[i].residue_str[m].res_id==*proteins_rou[j].w_c_rou[n].res_id&&
                        whole_protein[i].residue_str[m].chain_type==*proteins_rou[j].w_c_rou[n].chain_type&&
                        whole_protein[i].residue_str[m].asa>5&&
                        proteins_rou[j].w_c_rou[n].roughness>0
                       )
                     {

                     output<<setiosflags(ios::left)<<setw(10)<<whole_protein[i].protein_name
                           <<setiosflags(ios::left)<<setw(6)<<whole_protein[i].residue_str[m].res_num
                           <<setiosflags(ios::left)<<setw(4)<<whole_protein[i].residue_str[m].res_id
                           <<setiosflags(ios::left)<<setw(3)<<whole_protein[i].residue_str[m].chain_type
                           <<setiosflags(ios::left)<<setw(10)<<proteins_rou[j].protein_rou_id
                           <<setiosflags(ios::left)<<setw(6)<<proteins_rou[j].w_c_rou[n].res_num
                           <<setiosflags(ios::left)<<setw(4)<<proteins_rou[j].w_c_rou[n].res_id
                           <<setiosflags(ios::left)<<setw(3)<<proteins_rou[j].w_c_rou[n].chain_type
                           <<setiosflags(ios::fixed)
        	     <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<whole_protein[i].residue_str[m].angle
        	     <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<whole_protein[i].residue_str[m].asa
                     <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<proteins_rou[j].w_c_rou[n].roughness<<endl;
                     whole_protein[i].residue_str[m].roughness=proteins_rou[j].w_c_rou[n].roughness;
                     proteins_rou[j].w_c_rou[n].asa=whole_protein[i].residue_str[m].asa;
                     tt=tt+1; 
                     }//end if
                   }//end for
 	        }//end of for
            }//end of if
           }//end of for 
        }//end of for
	 
         ofstream output1("results3_asa1.txt",ios::out);

	for(i=0;i<whole_protein.size();i++)
         {
          for(m=0;m<whole_protein[i].residue_str.size();m++)
           {
            if(whole_protein[i].residue_str[m].roughness>0)
            {
                     output1<<setiosflags(ios::left)<<setw(10)<<whole_protein[i].protein_name
                           <<setiosflags(ios::left)<<setw(6)<<whole_protein[i].residue_str[m].res_num
                           <<setiosflags(ios::left)<<setw(4)<<whole_protein[i].residue_str[m].res_id
                           <<setiosflags(ios::left)<<setw(3)<<whole_protein[i].residue_str[m].chain_type
                           <<setiosflags(ios::fixed)
        	     <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<whole_protein[i].residue_str[m].angle
        	     <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<whole_protein[i].residue_str[m].asa
                     <<whole_protein[i].residue_str[m].roughness<<endl;
            } 
           }
         }
 
         ofstream output2("results3_asa2.txt",ios::out);

          for(j=0;j<proteins_rou.size();j++)
            {
             for(n=0;n<proteins_rou[j].w_c_rou.size();n++)
              {
               if(proteins_rou[j].w_c_rou[n].asa>5)
                 {                
                     output2<<setiosflags(ios::left)<<setw(10)<<proteins_rou[j].protein_rou_id
                           <<setiosflags(ios::left)<<setw(6)<<proteins_rou[j].w_c_rou[n].res_num
                           <<setiosflags(ios::left)<<setw(4)<<proteins_rou[j].w_c_rou[n].res_id
                           <<setiosflags(ios::left)<<setw(3)<<proteins_rou[j].w_c_rou[n].chain_type
                           <<setiosflags(ios::fixed)
                           <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<proteins_rou[j].w_c_rou[n].roughness
                           <<setiosflags(ios::left)<<setprecision(2)<<setw(8)<<proteins_rou[j].w_c_rou[n].asa<<endl;
                 }         
              }
            }               

         sum_and_output(whole_protein);
         sum_and_output3(whole_protein); 
         sum_and_output5(whole_protein); 
      
         cout<<"total surface residue(asa>5 and roughness>0) is:"<<tt<<endl;
         protein_file.close(); 
      
     
        return(0);
     }//end of main
Esempio n. 2
0
/** OnConnectionCleared callback function is called upon the dropping of an established
  * H323 connection. 
  */
void MyH323EndPoint::OnConnectionCleared(H323Connection & connection, const PString & clearedCallToken)
{
	PString remoteName;
	call_details_t cd;
        PIPSocket::Address Ip;
	WORD sourcePort;

	remoteName = connection.GetRemotePartyName();

	cd.call_reference = connection.GetCallReference();
	cd.call_token = strdup((const char *)clearedCallToken);
	cd.call_source_aliases = strdup((const char *)connection.GetRemotePartyName());
	
  	connection.GetSignallingChannel()->GetRemoteAddress().GetIpAndPort(Ip, sourcePort);
	cd.sourceIp = strdup((const char *)Ip.AsString());
	
	/* Convert complex strings */
	char *s;
	if ((s = strchr(cd.call_source_aliases, ' ')) != NULL)
		*s = '\0';

	switch (connection.GetCallEndReason()) {
		case H323Connection::EndedByCallForwarded :
			if (h323debug)
				cout << " -- " << remoteName << " has forwarded the call" << endl;
			break;
		case H323Connection::EndedByRemoteUser :
			if (h323debug)
				cout << " -- " << remoteName << " has cleared the call" << endl;
			break;
		case H323Connection::EndedByCallerAbort :
			if (h323debug)
				cout << " -- " << remoteName << " has stopped calling" << endl;
			break;
		case H323Connection::EndedByRefusal :
			if (h323debug)
				cout << " -- " << remoteName << " did not accept your call" << endl;
			break;
		case H323Connection::EndedByRemoteBusy :
			if (h323debug)
			cout << " -- " << remoteName << " was busy" << endl;
			break;
		case H323Connection::EndedByRemoteCongestion :
			if (h323debug)
				cout << " -- Congested link to " << remoteName << endl;
			break;
		case H323Connection::EndedByNoAnswer :
			if (h323debug)
				cout << " -- " << remoteName << " did not answer your call" << endl;
			break;
		case H323Connection::EndedByTransportFail :
			if (h323debug)
				cout << " -- Call with " << remoteName << " ended abnormally" << endl;
			break;
		case H323Connection::EndedByCapabilityExchange :
			if (h323debug)
				cout << " -- Could not find common codec with " << remoteName << endl;
			break;
		case H323Connection::EndedByNoAccept :
			if (h323debug)
				cout << " -- Did not accept incoming call from " << remoteName << endl;
			break;
		case H323Connection::EndedByAnswerDenied :
			if (h323debug)
				cout << " -- Refused incoming call from " << remoteName << endl;
			break;
		case H323Connection::EndedByNoUser :
			if (h323debug)
				cout << " -- Remote endpoint could not find user: "******" -- Call to " << remoteName << " aborted, insufficient bandwidth." << endl;
			break;
		case H323Connection::EndedByUnreachable :
			if (h323debug)
				cout << " -- " << remoteName << " could not be reached." << endl;
			break;
		case H323Connection::EndedByHostOffline :
			if (h323debug)
				cout << " -- " << remoteName << " is not online." << endl;
			break;
		case H323Connection::EndedByNoEndPoint :
			if (h323debug)
				cout << " -- No phone running for " << remoteName << endl;
			break;
		case H323Connection::EndedByConnectFail :
			if (h323debug)
				cout << " -- Transport error calling " << remoteName << endl;
			break;
		default :
			if (h323debug)
				cout << " -- Call with " << remoteName << " completed (" << connection.GetCallEndReason() << ")" << endl;

	}

	if(connection.IsEstablished()) 
		if (h323debug)
			cout << "	 -- Call duration " << setprecision(0) << setw(5) << (PTime() - connection.GetConnectionStartTime()) << endl;

	/* Invoke the PBX application registered callback */
	on_connection_cleared(cd);

	return;
}
Esempio n. 3
0
/**
 * Add capability to the capability table of the end point. 
 */
int h323_set_capability(int cap, int dtmfMode)
{
	H323Capabilities oldcaps;
	PStringArray codecs;
	int g711Frames = 30;
	int gsmFrames  = 4;

	if (!h323_end_point_exist()) {
		cout << " ERROR: [h323_set_capablity] No Endpoint, this is bad" << endl;
		return 1;
	}

	/* clean up old capabilities list before changing */
	oldcaps = endPoint->GetCapabilities();
	for (PINDEX i=0; i< oldcaps.GetSize(); i++) {
                 codecs.AppendString(oldcaps[i].GetFormatName());
         }
         endPoint->RemoveCapabilities(codecs);

	mode = dtmfMode;
	if (dtmfMode == H323_DTMF_INBAND) {
	    endPoint->SetSendUserInputMode(H323Connection::SendUserInputAsTone);
	} else {
		endPoint->SetSendUserInputMode(H323Connection::SendUserInputAsInlineRFC2833);
	}
	if (cap & AST_FORMAT_SPEEX) {
		/* Not real sure if Asterisk acutally supports all
		   of the various different bit rates so add them 
		   all and figure it out later*/

		endPoint->SetCapability(0, 0, new SpeexNarrow2AudioCapability());
		endPoint->SetCapability(0, 0, new SpeexNarrow3AudioCapability());
		endPoint->SetCapability(0, 0, new SpeexNarrow4AudioCapability());
		endPoint->SetCapability(0, 0, new SpeexNarrow5AudioCapability());
		endPoint->SetCapability(0, 0, new SpeexNarrow6AudioCapability());
	}

	if (cap & AST_FORMAT_G729A) {
		AST_G729ACapability *g729aCap;
		AST_G729Capability *g729Cap;
		endPoint->SetCapability(0, 0, g729aCap = new AST_G729ACapability);
		endPoint->SetCapability(0, 0, g729Cap = new AST_G729Capability);
	}
	
	if (cap & AST_FORMAT_G723_1) {
		H323_G7231Capability *g7231Cap;
		endPoint->SetCapability(0, 0, g7231Cap = new H323_G7231Capability);
	} 

	if (cap & AST_FORMAT_GSM) {
		H323_GSM0610Capability *gsmCap;
	    	endPoint->SetCapability(0, 0, gsmCap = new H323_GSM0610Capability);
	    	gsmCap->SetTxFramesInPacket(gsmFrames);
	} 

	if (cap & AST_FORMAT_ULAW) {
		H323_G711Capability *g711uCap;
	    	endPoint->SetCapability(0, 0, g711uCap = new H323_G711Capability(H323_G711Capability::muLaw));
		g711uCap->SetTxFramesInPacket(g711Frames);
	} 

	if (cap & AST_FORMAT_ALAW) {
		H323_G711Capability *g711aCap;
		endPoint->SetCapability(0, 0, g711aCap = new H323_G711Capability(H323_G711Capability::ALaw));
		g711aCap->SetTxFramesInPacket(g711Frames);
	} 

	if (h323debug) {
		cout <<  "Allowed Codecs:\n\t" << setprecision(2) << endPoint->GetCapabilities() << endl;
	}
	return 0;
}
Esempio n. 4
0
void h323_show_tokens(void)
{
	cout << "Current call tokens: " << setprecision(2) << endPoint->GetAllConnections() << endl;
}
Esempio n. 5
0
int h323_show_codec(int fd, int argc, char *argv[])
{
	cout <<  "Allowed Codecs:\n\t" << setprecision(2) << endPoint->GetCapabilities() << endl;
	return 0;
}
Esempio n. 6
0
File: getResV.C Progetto: XuQiao/HI
void getResV(){

//------------------------Deal with the number and get the output stored in txt files and root files
	
        double Vmax[nbin], eps[nbin];
        for(int ibin=0; ibin<nbin ;ibin++){
            Vmax[ibin]=0.065*(trkbin[ibin]+30);
            eps[ibin]=0.00025*(trkbin[ibin]+30);
        }
	ofstream  fstrV;
	double theta[ntheta];
	TVectorD Gmod2[nbin][ntheta];
	TVectorD sigma2[nbin],deltaV[nbin];
	TVectorD r[nbin];
	TVectorD r0[nbin], r01[nbin], V[nbin], chi[nbin];
	TVectorD GRe[nbin][ntheta]; TVectorD* GRe_t[nbin][ntheta];
	TVectorD GIm[nbin][ntheta]; TVectorD* GIm_t[nbin][ntheta];
	TComplex G[nbin][ntheta][nstepr];
	if(isSum)	fstrV.open("V_Sum.txt");
	else	fstrV.open("V_Prod.txt"); 
	TFile *f[nFileAll];

        for(int ibin=0; ibin<nbin; ibin++){
		    r[ibin].ResizeTo(nstepr);
                    for(int ir=0; ir<nstepr; ir++){
                        if(isSimple==0)  r[ibin][ir]=j01/(Vmax[ibin]-eps[ibin]*ir);	
	                else		 r[ibin][ir]=0.00025*1*(ir+1);
		    }
        }
                
	TVectorD Nevent;	Nevent.ResizeTo(nbin);  Nevent.Zero();
        TVectorD totmultall;	totmultall.ResizeTo(nbin);      totmultall.Zero();
        TVectorD avgmultall;	avgmultall.ResizeTo(nbin);      avgmultall.Zero();
        TVectorD tottrk;	tottrk.ResizeTo(nbin);      tottrk.Zero();
	TVectorD totptall;      totptall.ResizeTo(nbin);    totptall.Zero();
	TVectorD totetaall;      totetaall.ResizeTo(nbin);    totetaall.Zero();
        TVectorD avgtrk;	avgtrk.ResizeTo(nbin);      avgtrk.Zero();
	TVectorD avgmult;       avgmult.ResizeTo(nbin);
        TVectorD deltaVmean;    deltaVmean.ResizeTo(nbin);	
        TVectorD Vmean;         Vmean.ResizeTo(nbin);
        TVectorD avgpt;         avgpt.ResizeTo(nbin);
        TVectorD avgeta;         avgeta.ResizeTo(nbin);
        TVectorD Qx1;           Qx1.ResizeTo(nbin); Qx1.Zero();
        TVectorD Qy1;           Qy1.ResizeTo(nbin); Qy1.Zero();
        TVectorD Q2;           Q2.ResizeTo(nbin); Q2.Zero();
        TVectorD sigma2_;       sigma2_.ResizeTo(nbin); sigma2_.Zero();
        TVectorD chi_;           chi_.ResizeTo(nbin); chi_.Zero();
	
	for(int itheta=0;itheta<ntheta;itheta++)
        	theta[itheta]=itheta*TMath::Pi()/ntheta/nn;

	for(int ibin=0;ibin<nbin;ibin++){
			r0[ibin].ResizeTo(ntheta);
			r01[ibin].ResizeTo(ntheta);
			sigma2[ibin].ResizeTo(ntheta);
			V[ibin].ResizeTo(ntheta);
			deltaV[ibin].ResizeTo(ntheta);
			chi[ibin].ResizeTo(ntheta);
                        for(int itheta=0;itheta<ntheta;itheta++){
				Gmod2[ibin][itheta].ResizeTo(nstepr);
				GRe[ibin][itheta].ResizeTo(nstepr);
				GRe[ibin][itheta].Zero();
				GIm[ibin][itheta].ResizeTo(nstepr);
				GIm[ibin][itheta].Zero();
			}
	}

        for(int ifile=0; ifile<nFileAll; ifile++){
		if(isSum) f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/pPbDataV200m120/AnaV_Sum_%d.root",ifile));
		else f[ifile] = TFile::Open(Form("/scratch/xuq7/flow/pbsjoboutput/pPbDataV200m120/AnaV_Prod_%d.root",ifile));
		TVectorD* Nevent_t =  (TVectorD*)f[ifile]->Get(Form("Nevent"));
		TVectorD* totmultall_t =  (TVectorD*)f[ifile]->Get(Form("totmultall"));
		TVectorD* tottrk_t =  (TVectorD*)f[ifile]->Get(Form("tottrk"));
		TVectorD* totptall_t =  (TVectorD*)f[ifile]->Get(Form("totptall"));
		TVectorD* totetaall_t =  (TVectorD*)f[ifile]->Get(Form("totetaall"));
		TVectorD* Qx1_t =  (TVectorD*)f[ifile]->Get(Form("Qx1"));
	        TVectorD* Qy1_t =  (TVectorD*)f[ifile]->Get(Form("Qy1"));
		TVectorD* Q2_t =  (TVectorD*)f[ifile]->Get(Form("Q2"));
		for(int ibin=0;ibin<nbin;ibin++){
				for(int itheta=0;itheta<ntheta;itheta++){
				    GRe_t[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("GRe_%d_%d",ibin,itheta));
				    GIm_t[ibin][itheta] = (TVectorD*)f[ifile]->Get(Form("GIm_%d_%d",ibin,itheta));
				    for(ir=0; ir<nstepr; ir++){
				        GRe[ibin][itheta][ir] += (*GRe_t[ibin][itheta])[ir];
					GIm[ibin][itheta][ir] += (*GIm_t[ibin][itheta])[ir];
				    }
			}
				Qx1[ibin] += (*Qx1_t)[ibin];
				Qy1[ibin] += (*Qy1_t)[ibin];
				Q2[ibin] += (*Q2_t)[ibin];
				totptall[ibin] += (*totptall_t)[ibin];
				totetaall[ibin] += (*totetaall_t)[ibin];
			        Nevent[ibin] += (*Nevent_t)[ibin];
			        totmultall[ibin] += (*totmultall_t)[ibin];	
			        tottrk[ibin] += (*tottrk_t)[ibin];	
		}
		f[ifile]->Close();
	}
	
	fstrV<<setprecision(4)<<fixed;
	fstrV<<"ibin"<<"\t"<<"itheta"<<"\t"<<"r0"<<"\t"<<"V"<<"\t"<<"sigma2"<<"\t"<<"chi"<<"\t"<<"Vn Errors"<<endl;
	for(int ibin=0;ibin<nbin;ibin++){
		avgmultall[ibin]=totmultall[ibin]/Nevent[ibin];
		avgtrk[ibin]=tottrk[ibin]/Nevent[ibin];
			for(int itheta=0;itheta<ntheta;itheta++){
				for(ir=0; ir<nstepr; ir++){
					G[ibin][itheta][ir]=TComplex(GRe[ibin][itheta][ir],GIm[ibin][itheta][ir]);	
					G[ibin][itheta][ir]/=Nevent[ibin];
					Gmod2[ibin][itheta][ir]=TMath::Power(TComplex::Abs(G[ibin][itheta][ir]),2);
				}
				for(ir=0; ir<nstepr-1; ir++)
					if(ir!=0 && Gmod2[ibin][itheta][ir]<=Gmod2[ibin][itheta][ir-1] && Gmod2[ibin][itheta][ir]<=Gmod2[ibin][itheta][ir+1]) break;
				if(ir!=0 && ir<nstepr-1)	r01[ibin][itheta]=r[ibin][ir];
				else if(ir==0)	{cout<<"ibin="<<ibin<<"\t"<<"itheta="<<itheta<<"\tminimum lies on ir = 0, please select proper range!"<<endl;	continue;}
				else 	{cout<<"ibin="<<ibin<<"\t"<<"itheta="<<itheta<<"\tminimum lies on ir = maximum "<<nstepr-1<<", please select proper range!"<<endl;	continue;}
				avgmult[ibin]=1.0*totmultall[ibin]/Nevent[ibin];
				avgpt[ibin]=1.0*totptall[ibin]/totmultall[ibin];
				avgeta[ibin]=1.0*totetaall[ibin]/totmultall[ibin];
				if(isSimple==0)	V[ibin][itheta]=Vmax[ibin]-ir*eps[ibin]+eps[ibin]*(Gmod2[ibin][itheta][ir+1]-Gmod2[ibin][itheta][ir-1])/2./(Gmod2[ibin][itheta][ir-1]-2*Gmod2[ibin][itheta][ir]+Gmod2[ibin][itheta][ir+1]);
				else V[ibin][itheta]=j01/r01[ibin][itheta]; //simple method
				r0[ibin][itheta]=j01/V[ibin][itheta];
				V[ibin][itheta]/=avgmult[ibin];
				sigma2[ibin][itheta]=Q2[ibin]/Nevent[ibin]-(Qx1[ibin]/Nevent[ibin])*(Qx1[ibin]/Nevent[ibin])-(Qy1[ibin]/Nevent[ibin])*(Qy1[ibin]/Nevent[ibin]);
				sigma2_[ibin]+=sigma2[ibin][itheta];
				Vmean[ibin]+=V[ibin][itheta];
				chi[ibin][itheta]=V[ibin][itheta]*avgmult[ibin]/TMath::Sqrt(sigma2[ibin][itheta]);
				}
			//deltaVmean[ibin]+=TMath::Exp(j01*j01/2./chi[ibin][itheta]/chi[ibin][itheta]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Exp(-j01*j01/2./chi[ibin][itheta]/chi[ibin][itheta]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.));
			sigma2_[ibin]/=ntheta;
                        Vmean[ibin]/=ntheta;
                        sigma2_[ibin]-=TMath::Power(Vmean[ibin]*avgmult[ibin],2);
                        chi_[ibin]=Vmean[ibin]*avgmult[ibin]/TMath::Sqrt(sigma2_[ibin]);
                        for(int itheta=0;itheta<ntheta;itheta++){
				deltaV[ibin][itheta]=V[ibin][itheta]/j01/TMath::BesselJ1(j01)*TMath::Sqrt((TMath::Exp(j01*j01/2./chi_[ibin]/chi_[ibin])+TMath::Exp(-j01*j01/2./chi_[ibin]/chi_[ibin])*TMath::BesselJ0(2*j01))/2./Nevent[ibin]);
                        	deltaVmean[ibin]+=TMath::Exp(j01*j01/2./chi_[ibin]/chi_[ibin]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Sin(nn*theta[itheta]/2.))+TMath::Exp(-j01*j01/2./chi_[ibin]/chi_[ibin]*TMath::Cos(nn*theta[itheta]))*TMath::BesselJ0(2*j01*TMath::Cos(nn*theta[itheta]/2.));
	        	  fstrV <<ibin<<"\t"<<itheta<<"\t"<<r0[ibin][itheta]<<"\t"<<V[ibin][itheta]<<"\t"<<sigma2[ibin][itheta]<<"\t"<<chi[ibin][itheta]<<"\t"<<deltaV[ibin][itheta]<<endl;
			}
                        fstrV<<"\t\t\t\t\t"<<sigma2_[ibin]<<"\t"<<chi_[ibin]<<endl;
			deltaVmean[ibin]=Vmean[ibin]/j01/TMath::BesselJ1(j01)*TMath::Sqrt(deltaVmean[ibin]/ntheta/2./Nevent[ibin]);
		fstrV<<endl;
	}

	fstrV<<"ibin"<<"\t"<<"avgmult"<<"\t"<<"avgpt"<<"\t"<<"avgeta"<<"\t"<<"Vn mean"<<"\t"<<"Vn mean Error"<<endl;
	for(int ibin=0;ibin<nbin;ibin++){
			fstrV<<ibin<<"\t"<<avgmult[ibin]<<"\t"<<avgpt[ibin]<<"\t"<<avgeta[ibin]<<"\t"<<Vmean[ibin]<<"\t"<<deltaVmean[ibin]<<endl;
		fstrV<<endl;
	}
	
	fstrV<<"ibin"<<"\t"<<"Nevent"<<"\t"<<"totmultall"<<"\t"<<"avgmultall"<<"\t"<<"avgtrk"<<endl;
	for(int ibin=0;ibin<nbin;ibin++){
		fstrV<<ibin<<"\t"<<Nevent[ibin]<<"\t"<<totmultall[ibin]<<"\t"<<avgmultall[ibin]<<"\t"<<avgtrk[ibin]<<endl;		
		fstrV<<endl;
	}

	if(isSum)	TString outname = "mergedV_Sum.root";
	else 	TString outname="mergedV_Prod.root";
	TFile *outf = new TFile(outname,"Recreate");
        Nevent.Write("Nevent");
       	totmultall.Write("totmultall");
       	avgmultall.Write("avgmultall");
       	tottrk.Write("tottrk");
       	avgtrk.Write("avgtrk");
	Qx1.Write("Qx1");
        Qy1.Write("Qy1");
        Q2.Write("Q2");
        avgmult.Write("avgmult");
        avgpt.Write("avgpt");
        avgeta.Write("avgeta");
        Vmean.Write("Vmean");
        deltaVmean.Write("deltaVmean");
        chi_.Write("chi");
        sigma2_.Write("sigma2");
        
	for(int ibin=0;ibin<nbin;ibin++){
                TDirectory *dir0 = outf->mkdir(Form("D_%d",ibin));dir0->cd();
		r[ibin].Write("r");
		sigma2[ibin].Write("sigma2");	chi[ibin].Write("chi0");	deltaV[ibin].Write("deltaV");
		r0[ibin].Write("r0");	r01[ibin].Write("r01");	V[ibin].Write("V");

        		for(int itheta=0;itheta<ntheta;itheta++){
                        	TDirectory *dir1 = dir0->mkdir(Form("D_%d",itheta));dir1->cd();
                        	GRe[ibin][itheta].Write(Form("GRe"));
                        	GIm[ibin][itheta].Write(Form("GIm"));
                        	Gmod2[ibin][itheta].Write(Form("G2"));
                	}
        	}
	outf->Close();
}
Esempio n. 7
0
void pp (Point *p)
{
  PV2 pp = p->getP();
  cerr << setprecision(16) << "(" << pp.x.mid() << " " 
       << pp.y.mid() << ")" << endl;
}
int main()

{

std::cout<<setprecision(15)<<"Setting output precision to 15"<<std::endl;

    /// Setting the Celestial Body class ///


//    // First test

//    celestialBody Mars;

    // Second test

//    const std::string planet = "Mars";
//    const std::string planet = "Venus";

    celestialBody Mars;

//    const double adiabeticIndex = Mars.adiabeticIndex();
//    const double specificGasConstant = Mars.specificGasConstant();
//    const double standardGravitationalParameter = Mars.standardGravitationalParameter();
    const double rotationalVelocity = Mars.rotationalVelocity();
    const double primeMeridianAngle = Mars.primeMeridianAngle();
    const double inertialFrameTime = Mars.inertialFrameTime();

   const double bodyReferenceRadius = Mars.bodyReferenceRadius();

//    celestialBody Mars(planet);
//    Mars.setPlanet(planet);  // Does not exist in the class anymore!


    /// Setting the vehicle class ///

    MarsAscentVehicle MAV;



  /// Initial conditions ///

    // Launch site characteristics

//    const double initialAltitude = -0.6e3;             // Starting altitude [m MOLA]
    const double initialAltitude = -0.6;                 // Starting altitude [km MOLA]
    const double initialLatitudeDeg = 21;               // Starting latitude [deg]
    const double initialLongitudeDeg = 74.5;            // Starting longitude [deg]

//    const double initialLatitude = initialLatitudeDeg*tudat::mathematical_constants::LONG_PI/180;       // Starting latitude [rad]
//    const double initialLongitude = initialLongitudeDeg*tudat::mathematical_constants::LONG_PI/180;     // Starting longitude [rad]

    const double initialLatitude = deg2rad(initialLatitudeDeg);       // Starting latitude [rad]
    const double initialLongitude = deg2rad(initialLongitudeDeg);     // Starting longitude [rad]

    const double initialRadius = bodyReferenceRadius+initialAltitude;               // Starting radius in km
//        const double initialRadius = bodyReferenceRadius+initialAltitude;               // Starting radius in m

        // Converting the initial spherical position to cartesian position using the standard convertSphericalToCartesian function of Tudat
        // Please note that this function requires the zenith angle as input which is pi/2-latitude!

    Eigen::Vector3d initialCartesianPositionRotationalFrame = Eigen::Vector3d::Zero(3);

      initialCartesianPositionRotationalFrame(0) = initialRadius*cos(initialLatitude)*cos(initialLongitude); // x_R
      initialCartesianPositionRotationalFrame(1) = initialRadius*cos(initialLatitude)*sin(initialLongitude); // y_R
      initialCartesianPositionRotationalFrame(2) = initialRadius*sin(initialLatitude); // z_R

    const Eigen::Vector3d initialCartesianPositionInertialFrame = tudat::reference_frames::getRotatingPlanetocentricToInertialFrameTransformationMatrix(rotationalVelocity*inertialFrameTime-primeMeridianAngle)*initialCartesianPositionRotationalFrame;


    // Compute initial velocity in y-direction as seen from the launch site in the inertial frame

    const Eigen::Vector3d initialVelocityLaunchSite = Eigen::Vector3d(0,(rotationalVelocity*initialRadius*cos(initialLatitude)),0);

    const Eigen::Vector3d initialVelocityInertialFrame = tudat::reference_frames::getRotatingPlanetocentricToInertialFrameTransformationMatrix(rotationalVelocity*inertialFrameTime-primeMeridianAngle+initialLongitude)*initialVelocityLaunchSite;

    /// Setting StateAndTime class using modified vector ///

    tudat::basic_mathematics::Vector7d aState;

    aState(0) = initialCartesianPositionInertialFrame(0);
    aState(1) = initialCartesianPositionInertialFrame(1);
    aState(2) = initialCartesianPositionInertialFrame(2);
    aState(3) = initialVelocityInertialFrame(0);
    aState(4) = initialVelocityInertialFrame(1);
    aState(5) = initialVelocityInertialFrame(2);
    aState(6) = 227;  // Mass [kg] from literature study

    StateAndTime currentStateAndTime(aState);        // Creating the current state class using the namespace and class directly

//////////////////////////////////////////////////////////////////////////////////
/*////////////////////// Testing the Taylor series integrator //////////////////////
//////////////////////////////////////////////////////////////////////////////////

/// Setting the data collection file for TSI and inserting the first values ///

    // Set directory where output files will be stored. THIS REQUIRES THE COMPLETE PATH IN ORDER TO WORK!!
    const std::string outputDirectory = "/home/stachap/Documents/Thesis/03. Tudat/tudatBundle/tudatApplications/thesisProject/01.integrationResults/TSI/";


    // Set output format for matrix output.
    Eigen::IOFormat csvFormat( 15, 0, ", ", "\n" );

    // Set absolute path to file containing the Taylor Series Coefficients.
    std::string dataAbsolutePath = outputDirectory + "test2TSIstateAndTime.csv";

    // Create a row vector for the storing of the data
    Eigen::MatrixXd outputVector = Eigen::MatrixXd::Zero(1,8); // Create a row vector for the storing of the data

    // Getting the initial conditions for storage
    const tudat::basic_mathematics::Vector7d initialState = currentStateAndTime.getCurrentState();

    // Filling the output vector
    outputVector(0,0) = currentStateAndTime.getCurrentTime();   // Storing the initial time
    outputVector(0,1) = initialState(0);   // Storing the initial x position
    outputVector(0,2) = initialState(1);   // Storing the initial y position
    outputVector(0,3) = initialState(2);   // Storing the initial z position
    outputVector(0,4) = initialState(3);   // Storing the initial x velocity
    outputVector(0,5) = initialState(4);   // Storing the initial y velocity
    outputVector(0,6) = initialState(5);   // Storing the initial z velocity
    outputVector(0,7) = initialState(6);   // Storing the initial MAV mass

    // Storing the data

    std::ifstream ifile(dataAbsolutePath.c_str()); // Check it as an input file

    bool fexists = false;   // Set the default to "It does not exist"

    if (ifile){         // Attempt to open the file


       fexists = true;      // If the file can be opened it must exist

       ifile.close();   // Close the file

    }


    // If so: error and create temporary file, if not: create new file and put data in

    if (fexists == true){


        /// Get time ///

        time_t rawtime;
        struct tm * timeinfo;

        time ( &rawtime );
        timeinfo = localtime ( &rawtime );
//        printf ( "Current local time and date: %s", asctime (timeinfo) );         // (from stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c and from stackoverflow.com/questions/1442116/how-to-get-date-and-time-value-in-c-program)
//        std::cout<<"time = "<<time ( &rawtime )<<std::endl;
//        std::cout<< (timeinfo->tm_year+1900) << "-"
//                 << (timeinfo->tm_mon + 1) << "-"
//                 << timeinfo->tm_mday << " "
//                 << timeinfo->tm_hour << ":"
//                 << timeinfo->tm_min << ":"
//                 << timeinfo->tm_sec <<std::endl;

        ostringstream ConvertHour;
        ConvertHour << timeinfo->tm_hour;
        std::string currentHour = ConvertHour.str();

//        std::cout<<"currentHour = "<<currentHour<<std::endl;

        ostringstream ConvertMin;
        ConvertMin << timeinfo->tm_min;
        std::string currentMin = ConvertMin.str();

//        std::cout<<"currentMin = "<<currentMin<<std::endl;

        ostringstream ConvertSec;
        ConvertSec << timeinfo->tm_sec;
        std::string currentSec = ConvertSec.str();

//        std::cout<<"currentSec = "<<currentSec<<std::endl;



//        std::string currentRealTime = timeinfo->tm_hour + ";" + timeinfo->tm_min + ":" + timeinfo->tm_sec;

//        std::cout<<"currentRealTime = "<<currentRealTime<<std::endl;

        /// Get time end ///

//        const double currentComputerTime = 11;   // The current CPU time used to make a new file if file already exists (code from stackoverflow.com/questions/17432502/how-can-i-measure-cpu-time-and-wall-clock-time-on-both-linux-windows)

//        std::string ComputerTimeString;      // Creating a string to hold the CPU time

//        ostringstream convert;          // Stream used for the conversion (as by www.cplusplus.com/articles/D9j2Nwbp/ )

//        convert << currentComputerTime;      // Input the number to be converted

//        ComputerTimeString = convert.str();  // Convert to string and store

        if(currentSec.size() == 1){
            currentSec = "0" + currentSec;
        }

        if (currentMin.size() == 1){
            currentMin = "0" + currentMin;
        }

        if (currentHour.size() == 1){
            currentHour = "0" + currentHour;
        }


//        std::cout<<"The length of currentSec = "<<currentSec.size()<<" and the value = "<<currentSec<<std::endl;

        std::string ComputerTimeString = currentHour + ":" + currentMin + ":" + currentSec;  // Convert to string and store

        std::string newFileName = "backupTSIFileAtTime_" + ComputerTimeString + ".csv";

    std::cerr<<"The file name that you have chosen already exists, a new file with name "<<newFileName<<" will be created to store the data for now"<<std::endl;

    // Set new absolute path to file containing the data.
    dataAbsolutePath = outputDirectory + newFileName;

    // Export the data.
    std::ofstream exportFile1( dataAbsolutePath.c_str( ) ); // Make the new file
    std::cout<<"New file called "<<dataAbsolutePath<<" has been created"<<std::endl;
    exportFile1 << outputVector.format( csvFormat );          // Store the new values
    exportFile1.close( );   // Close the file


}
        else{

        // Export the data.
        std::ofstream exportFile1( dataAbsolutePath.c_str( ) ); // Make the new file
        std::cout<<"New file called "<<dataAbsolutePath<<" has been created"<<std::endl;
        exportFile1 << outputVector.format( csvFormat );          // Store the new values
        exportFile1.close( );   // Close the file
    };



/// Defining the order and initializing the StepSize class ///

    const int maxOrder = 20;

        StepSize stepSize; // Initializing the stepSize class. THIS SHOULD BE DONE BEFORE THE START OF THE INTEGRATION!!!!!

//        const double currentStepSize = stepSize.getCurrentStepSize();

//        std::cout<<"The current stepSize = "<<currentStepSize<<std::endl;

/// Performing the actual TSI integration ///



        Eigen::VectorXd updatedStateAndTimeVector = performTaylorSeriesIntegrationStep(Mars, MAV, currentStateAndTime, stepSize, maxOrder);
        // This function has the output: updated position, updated velocity, updated mass and updated time

        std::cout<<"updatedStateAndTimeVector = "<<updatedStateAndTimeVector<<std::endl;


        // Check to see if the class has been updated from within the TSI function
//        const double nextStepSize = stepSize.getCurrentStepSize();

//        std::cout<<"The next stepSize = "<<nextStepSize<<std::endl;

/// Storing the values ///

        outputVector = Eigen::MatrixXd::Zero(1,8); // Setting the output vector to zero again to be sure.

        // Filling the output vector
        outputVector(0,0) = updatedStateAndTimeVector(7);   // Storing the updated time
        outputVector(0,1) = updatedStateAndTimeVector(0);   // Storing the updated x position
        outputVector(0,2) = updatedStateAndTimeVector(1);   // Storing the updated y position
        outputVector(0,3) = updatedStateAndTimeVector(2);   // Storing the updated z position
        outputVector(0,4) = updatedStateAndTimeVector(3);   // Storing the updated x velocity
        outputVector(0,5) = updatedStateAndTimeVector(4);   // Storing the updated y velocity
        outputVector(0,6) = updatedStateAndTimeVector(5);   // Storing the updated z velocity
        outputVector(0,7) = updatedStateAndTimeVector(6);   // Storing the updated MAV mass


        // Check if the file already exists.


        std::ifstream ifile2(dataAbsolutePath.c_str()); // Check it as an input file

        fexists = false;   // Set the default to "It does not exist"

        if (ifile2){         // Attempt to open the file


           fexists = true;      // If the file can be opened it must exist

           ifile2.close();   // Close the file

        }


        // If so: append, if not: create new file and put data in

        if (fexists == true){

            // Export the Taylor Series Coefficients matrix.
            std::ofstream exportFile1;                          // Define the file as an output file


            exportFile1.open(dataAbsolutePath.c_str(),std::ios_base::app);      // Open the file in append mode

            exportFile1 << "\n";                                            // Make sure the new matrix start on a new line

            exportFile1 << outputVector.format( csvFormat ); // Add the new values

            std::cout<<"The file called "<<dataAbsolutePath<<" has been appended"<<std::endl;


            exportFile1.close( );   // Close the file
}
            else{

            std::cerr<<"Error: values could not be stored because storage file does not exist"<<std::endl;
        };

//*/





    return 0;
}
Esempio n. 9
0
void AudioOutPanel::update()
{
    SoundDevices* devices       = editor_->getDevices();
    DeviceInfoList& deviceInfos = devices->deviceInfos_;
    DeviceInfo* deviceInfo      = devices->getAudioOutDevice();
    INT16 deviceId              = deviceInfo ? deviceInfo->id : -1;
    
    // update asio
    cbAsio_->setState( devices->getAudioPort() == RtAudio::WINDOWS_ASIO );
    cbRun_->setState( editor_->getOptions()->audioRun_ );

    // update port
    SelectBoxList deviceList;
    deviceList.push_back( "[not connected]" );

    for( UINT16 i=0; i<deviceInfos.size(); i++ ) {
        deviceList.push_back( deviceInfos.at( i ).name );
    }
    sbDevice_->setList( deviceList, 4 );
    sbDevice_->setIndex( deviceId + 1 );

    // update the rest
    bool visible = deviceInfo != NULL && deviceInfo->outputChannels > 0;

    sbChannel_->setVisible( visible );
    sbBuffer_->setVisible( visible );
    lbBuffer_->setVisible( visible );
    lbRate_->setVisible( visible );
    sbRate_->setVisible( visible );
    lbLatency_->setVisible( visible );

    if( visible )
    {
        // update channel
        if( devices->getAudioPort() == RtAudio::WINDOWS_ASIO )
        {
            SelectBoxList channelList;
            vector<string>& outChannelNames = deviceInfo->outChannelNames;
            for( UINT16 i=0; i<outChannelNames.size()-1 && outChannelNames.size()>0; i+=2 ) 
            {
                string name = outChannelNames[i] + " / " + outChannelNames[i+1];
                channelList.push_back( name );
            }
            sbChannel_->setList( channelList, 4 );
            sbChannel_->setIndex( devices->getAudioOutChannel() );
        }
        else if( devices->getAudioPort() == RtAudio::WINDOWS_DS ) {     // DS: only two channels
            sbChannel_->setVisible( false );
        }

        // update buffersize
        SelectBoxList bufferList;
        UINT16 selectedBuffer = 0;
        vector<unsigned int>& bufferSizes = deviceInfo->bufferSizes;
        for( UINT16 i=0; i<bufferSizes.size(); i++ ) 
        {
            ostringstream os;
            os << bufferSizes[i];
            bufferList.push_back( os.str() );
            if( bufferSizes[i] == devices->getBufferSize() ) 
                selectedBuffer = i;
        }
        sbBuffer_->setList( bufferList, 4 );
        sbBuffer_->setIndex( selectedBuffer );

        // update samplerate
        SelectBoxList rateList;
        UINT16 selectedRate = 0;
        vector<unsigned int>& rates = deviceInfo->sampleRates;
        for( UINT16 i=0; i<rates.size(); i++ ) 
        {
            ostringstream os;
            os << rates[i];
            rateList.push_back( os.str() );
            if( rates[i] == devices->getSampleRate() ) 
                selectedRate = i;
        }
        sbRate_->setList( rateList, 4 );
        sbRate_->setIndex( selectedRate );

        // update latency
        ostringstream os;
        os << setprecision( 2 ) << fixed << devices->getLatency() / 44.1;
        lbLatency_->setText( "Latency: " + os.str() + " ms" );
        lbLatency_->setVisible( devices->getLatency() > 0 && editor_->getOptions()->audioRun_ );
    }
    editor_->checkAppState();
    invalid();
}
Esempio n. 10
0
void plotcnbbccsouth_sys(string t_ = "ptccentc"){
gStyle->SetLegendFillColor(0);
gStyle->SetLegendBorderSize(0);
TString type = t_.c_str();
double psize = 1.4;
if(type.Contains("pt") && type != "ptccentc"){
const int ncent = 8;
double centbin[ncent+1] = {0,1,5,10,20,30,40,60,100}; 
double centmidp[ncent] = {50.3333,41.8333,34.3,24,19.6667,12.66667,7.66667,2.8}; //mb
if(type=="ptIn"){//1.0-3.0
const int npt = 1;
double ptbin[npt+1] = {1.0,3.0};
double ptmean[npt] = {1.36878};
}
else if(type=="ptIn25_4"){
const int npt = 1;
double ptbin[npt+1] = {2.5,4.0};
double ptmean[npt] = {2.92489};
}
else if(type=="ptcoarser"){
const int npt = 4;
double ptbin[npt+1] = {0.2,1.0,2.0,3.0,5.0};
const double ptmean[npt] = {0.519639, 1.29345, 2.32523, 3.51803};
}
else if(type=="ptfiner"){
const int npt = 10;
const double ptbin[npt+1] = {0.2,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0};
const double ptmean[npt] = {0.360943, 0.691833, 1.1911, 1.69654, 2.20117, 2.70571, 3.2097, 3.71372, 4.21814, 4.72014};
}
}
else if(type=="centIn"){
const int ncent = 1;
const double centbin[ncent+1] = {0,100};
const double centmidp[ncent] = {50};
const int npt = 10;
const double ptbin[npt+1] = {0.2,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0};
const double ptmean[npt] = {0.360943, 0.691833, 1.1911, 1.69654, 2.20117, 2.70571, 3.2097, 3.71372, 4.21814, 4.72014};
}
else if(type=="ptccentc"){
const int ncent = 2;
const double centbin[ncent+1] = {0,5,20};
const double centmidp[ncent] = {2.5,12.5};
const int npt = 5;
const int npt = 10;
const double ptbin[npt+1] = {0.2,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0};
const double ptmean[npt] = {0.360943, 0.691833, 1.1911, 1.69654, 2.20117, 2.70571, 3.2097, 3.71372, 4.21814, 4.72014};
}
TCanvas *c1 = new TCanvas();
TCanvas *c2 = new TCanvas();
TCanvas *c3 = new TCanvas();
TCanvas *c4 = new TCanvas();
TCanvas *c5 = new TCanvas();
TCanvas *c6 = new TCanvas();
TCanvas *c7 = new TCanvas();
TCanvas *c8 = new TCanvas("c8","",800,400);
c8->Divide(2,1);
TCanvas *c9 = new TCanvas();
TCanvas *c10 = new TCanvas("c10","",800,400);
c10->Divide(2,1);
TCanvas *c11 = new TCanvas();
TCanvas *c12 = new TCanvas();
TLegend *leg1 = new TLegend(0.62,0.82-npt*0.03,0.82,0.88);
TLegend *leg2 = new TLegend(0.62,0.82-npt*0.03,0.82,0.88);
TLegend *leg3 = new TLegend(0.22,0.82-npt*0.03,0.42,0.88);
TLegend *leg4 = new TLegend(0.22,0.82-npt*0.03,0.42,0.88);
TLegend *leg5 = new TLegend(0.62,0.82-npt*0.03,0.82,0.88);
TLegend *leg6 = new TLegend(0.62,0.82-npt*0.03,0.82,0.88);
TLegend *leg7 = new TLegend(0.22,0.82-ncent*0.03,0.42,0.88);
TLegend *leg8 = new TLegend(0.22,0.82-ncent*0.03,0.42,0.88);
TLegend *leg9 = new TLegend(0.22,0.82-ncent*0.03,0.42,0.88);
TLegend *leg10 = new TLegend(0.22,0.82-ncent*0.03,0.42,0.88);
TLegend *leg11 = new TLegend(0.22,0.82-ncent*0.03,0.42,0.88);
TLegend *leg12 = new TLegend(0.22,0.82-ncent*0.03,0.42,0.88);
    TLegend *leg101 = new TLegend(0.22,0.82-ncent*0.03,0.42,0.88);
    TLegend *leg102 = new TLegend(0.22,0.82-ncent*0.03,0.42,0.88);
TString str = "EW";
if(str=="PC3"){
TString sysstring[3]={"","_PC3Sigma2","_PC3Sigma2ratio"};
TString drawstring[3]={"AP","Psame","AP"};
const int color[10] = {1,2,2,2,4,8,6,2,1,7};
const int style[10] = {20,25,25,25,24,33,34,31,22,21};
int nsys = 3;
int ndiv = 2;
}
if(str=="PU"){
TString sysstring[5]={"","_PUlow","_PUhigh","_PUlowratio","_PUhighratio"};
TString drawstring[5]={"AP","Psame","Psame","AP","Psame"};
const int color[10] = {1,2,4,2,4,8,6,2,1,7};
const int style[10] = {20,25,24,25,24,33,34,31,22,21};
int nsys=5;
int ndiv = 3;
}
if(str=="EW"){
//TString sysstring[5]={"","_East","_West","_Eastratio","_Westratio"};
TString sysstring[5]={"","_east_123corrbs","_west_123corr","_Eastratio","_Westratio"};
TString drawstring[5]={"AP","Psame","Psame","AP","Psame"};
const int color[10] = {1,2,4,2,4,8,6,2,1,7};
const int style[10] = {20,25,24,25,24,33,34,31,22,21};
int nsys=5;
int ndiv = 3;
}

for(int isys=0;isys<nsys;isys++){
double c1north[ncent][npt];
double c1south[ncent][npt];
double c1northerr[ncent][npt];
double c1southerr[ncent][npt];
double c2north[ncent][npt];
double c2south[ncent][npt];
double c2northerr[ncent][npt];
double c2southerr[ncent][npt];
double c3north[ncent][npt];
double c3south[ncent][npt];
double c3northerr[ncent][npt];
double c3southerr[ncent][npt];
double c1north_[npt][ncent];
double c1south_[npt][ncent];
double c1northerr_[npt][ncent];
double c1southerr_[npt][ncent];
double c2north_[npt][ncent];
double c2south_[npt][ncent];
double c2northerr_[npt][ncent];
double c2southerr_[npt][ncent];
double c3north_[npt][ncent];
double c3south_[npt][ncent];
double c3northerr_[npt][ncent];
double c3southerr_[npt][ncent];
ifstream fnorth;
ifstream fsouth;
fnorth.open(Form("c1_c2%s_central_ptfiner_north.dat",sysstring[isys].Data(),type.Data()));
fsouth.open(Form("c1_c2%s_central_ptfiner_south.dat",sysstring[isys].Data(),type.Data()));
for(int icent=0;icent<ncent;icent++){
for(int ipt=0;ipt<npt;ipt++){
fnorth>>c1north[icent][ipt];
fnorth>>c1northerr[icent][ipt];
fnorth>>c2north[icent][ipt];
fnorth>>c2northerr[icent][ipt];
fnorth>>c3north[icent][ipt];
fnorth>>c3northerr[icent][ipt];
c1north_[ipt][icent] = c1north[icent][ipt];
c1northerr_[ipt][icent] = c1northerr[icent][ipt];
c2north_[ipt][icent] = c2north[icent][ipt];
c2northerr_[ipt][icent] = c2northerr[icent][ipt];
c3north_[ipt][icent] = c3north[icent][ipt];
c3northerr_[ipt][icent] = c3northerr[icent][ipt];
fsouth>>c1south[icent][ipt];
fsouth>>c1southerr[icent][ipt];
fsouth>>c2south[icent][ipt];
fsouth>>c2southerr[icent][ipt];
fsouth>>c3south[icent][ipt];
fsouth>>c3southerr[icent][ipt];
c1south_[ipt][icent] = c1south[icent][ipt];
c1southerr_[ipt][icent] = c1southerr[icent][ipt];
c2south_[ipt][icent] = c2south[icent][ipt];
c2southerr_[ipt][icent] = c2southerr[icent][ipt];
c3south_[ipt][icent] = c3south[icent][ipt];
c3southerr_[ipt][icent] = c3southerr[icent][ipt];
}
}

TGraphErrors *gr1north[npt>ncent?npt:ncent];
TGraphErrors *gr1south[npt>ncent?npt:ncent];
TGraphErrors *gr2north[npt>ncent?npt:ncent];
TGraphErrors *gr2south[npt>ncent?npt:ncent];
TGraphErrors *gr3north[npt>ncent?npt:ncent];
TGraphErrors *gr3south[npt>ncent?npt:ncent];
TLatex t;
t.SetNDC();
t.SetTextSize(0.04);
for(int ipt = 0;ipt<npt; ipt++){
gr1north[ipt] = new TGraphErrors(ncent,centmidp,c1north_[ipt],0,c1northerr_[ipt]);
gr1south[ipt] = new TGraphErrors(ncent,centmidp,c1south_[ipt],0,c1southerr_[ipt]);
gr2north[ipt] = new TGraphErrors(ncent,centmidp,c2north_[ipt],0,c2northerr_[ipt]);
gr2south[ipt] = new TGraphErrors(ncent,centmidp,c2south_[ipt],0,c2southerr_[ipt]);
gr3north[ipt] = new TGraphErrors(ncent,centmidp,c3north_[ipt],0,c3northerr_[ipt]);
gr3south[ipt] = new TGraphErrors(ncent,centmidp,c3south_[ipt],0,c3southerr_[ipt]);
SetStyle(*gr1north[ipt],psize,color[ipt],style[ipt],0,0);
SetStyle(*gr1south[ipt],psize,color[ipt],style[ipt],0,0);
SetStyle(*gr2north[ipt],psize,color[ipt],style[ipt],0,0);
SetStyle(*gr2south[ipt],psize,color[ipt],style[ipt],0,0);
SetStyle(*gr3north[ipt],psize,color[ipt],style[ipt],0,0);
SetStyle(*gr3south[ipt],psize,color[ipt],style[ipt],0,0);
SetRange(*gr1north[ipt],centbin[0],-0.10,centbin[ncent],0.001);
SetRange(*gr1south[ipt],centbin[0],-0.10,centbin[ncent],0.001);
SetRange(*gr2north[ipt],centbin[0],-0.001,centbin[ncent],0.02);
SetRange(*gr2south[ipt],centbin[0],-0.001,centbin[ncent],0.02);
SetRange(*gr3north[ipt],centbin[0],-0.015,centbin[ncent],0.015);
SetRange(*gr3south[ipt],centbin[0],-0.015,centbin[ncent],0.015);
gr1north[ipt]->SetTitle("");
gr1north[ipt]->GetXaxis()->SetTitle("mean bbc charge south");
gr1north[ipt]->GetYaxis()->SetTitle("c_{1}");
gr1south[ipt]->SetTitle("");
gr1south[ipt]->GetXaxis()->SetTitle("mean bbc charge south");
gr1south[ipt]->GetYaxis()->SetTitle("c_{1}");
gr2north[ipt]->SetTitle("");
gr2north[ipt]->GetXaxis()->SetTitle("mean bbc charge south");
gr2north[ipt]->GetYaxis()->SetTitle("c_{2}");
gr2south[ipt]->SetTitle("");
gr2south[ipt]->GetXaxis()->SetTitle("mean bbc charge south");
gr2south[ipt]->GetYaxis()->SetTitle("c_{2}");
gr3north[ipt]->SetTitle("");
gr3north[ipt]->GetXaxis()->SetTitle("mean bbc charge south");
gr3north[ipt]->GetYaxis()->SetTitle("c_{3}");
gr3south[ipt]->SetTitle("");
gr3south[ipt]->GetXaxis()->SetTitle("mean bbc charge south");
gr3south[ipt]->GetYaxis()->SetTitle("c_{3}");
leg1->SetFillColor(0);
leg1->SetTextSize(0.04);
leg2->SetFillColor(0);
leg2->SetTextSize(0.04);
leg3->SetFillColor(0);
leg3->SetTextSize(0.04);
leg4->SetFillColor(0);
leg4->SetTextSize(0.04);
leg5->SetFillColor(0);
leg5->SetTextSize(0.04);
leg6->SetFillColor(0);
leg6->SetTextSize(0.04);
leg1->AddEntry(gr1north[ipt],Form("%.1f<p_{T, trig}<%.1f",ptbin[ipt],ptbin[ipt+1]),"lp");
leg2->AddEntry(gr1south[ipt],Form("%.1f<p_{T, trig}<%.1f",ptbin[ipt],ptbin[ipt+1]),"lp");
leg3->AddEntry(gr2north[ipt],Form("%.1f<p_{T, trig}<%.1f",ptbin[ipt],ptbin[ipt+1]),"lp");
leg4->AddEntry(gr2south[ipt],Form("%.1f<p_{T, trig}<%.1f",ptbin[ipt],ptbin[ipt+1]),"lp");
leg5->AddEntry(gr3north[ipt],Form("%.1f<p_{T, trig}<%.1f",ptbin[ipt],ptbin[ipt+1]),"lp");
leg6->AddEntry(gr3south[ipt],Form("%.1f<p_{T, trig}<%.1f",ptbin[ipt],ptbin[ipt+1]),"lp");
c1->cd();
if(ipt==0){gr1north[ipt]->Draw(drawstring[isys].Data());leg1->Draw("same");t.DrawLatex(0.2,0.2,"c_{1} 1.5<|#eta_{asso}|<3.0");}
else gr1north[ipt]->Draw("Psame");

c2->cd();
if(ipt==0) {gr1south[ipt]->Draw(drawstring[isys].Data());leg2->Draw("same");t.DrawLatex(0.2,0.2,"c_{1} 1.0<|#eta_{asso}|<3.0");}
else gr1south[ipt]->Draw("Psame");

c3->cd();
if(ipt==0){gr2north[ipt]->Draw(drawstring[isys].Data());leg3->Draw("same");t.DrawLatex(0.2,0.2,"c_{2} 1.5<|#eta_{asso}|<3.0");}
else gr2north[ipt]->Draw("Psame");
	
c4->cd();
if(ipt==0) {gr2south[ipt]->Draw(drawstring[isys].Data());leg4->Draw("same");t.DrawLatex(0.2,0.2,"c_{2} 1.0<|#eta_{asso}|<3.0");}
else gr2south[ipt]->Draw("Psame");

c5->cd();
if(ipt==0){gr3north[ipt]->Draw(drawstring[isys].Data());leg5->Draw("same");t.DrawLatex(0.2,0.2,"c_{3} 1.5<|#eta_{asso}|<3.0");}
else gr3north[ipt]->Draw("Psame");

c6->cd();
if(ipt==0) {gr3south[ipt]->Draw(drawstring[isys].Data());leg6->Draw("same");t.DrawLatex(0.2,0.2,"c_{3} 1.0<|#eta_{asso}|<3.0");}
else gr3south[ipt]->Draw("Psame");
}

for(int icent = 0;icent<1; icent++){
gr1north[icent] = new TGraphErrors(npt,ptmean,c1north[icent],0,c1northerr[icent]);
//gr1south[icent] = new TGraphErrors(npt,ptmean,c1south[icent],0,c1southerr[icent]);
gr2north[icent] = new TGraphErrors(npt,ptmean,c2north[icent],0,c2northerr[icent]);
if(isys>=ndiv){
gr2south[icent] = new TGraphErrors(npt,ptmean,c2south[icent],0,0);//ca2southerr[icent]);
gr1south[icent] = new TGraphErrors(npt,ptmean,c1south[icent],0,0);//ca2southerr[icent]);
}
else{
gr2south[icent] = new TGraphErrors(npt,ptmean,c2south[icent],0,c2southerr[icent]);
gr1south[icent] = new TGraphErrors(npt,ptmean,c1south[icent],0,c1southerr[icent]);
}
gr3north[icent] = new TGraphErrors(npt,ptmean,c3north[icent],0,c3northerr[icent]);
gr3south[icent] = new TGraphErrors(npt,ptmean,c3south[icent],0,c3southerr[icent]);
SetStyle(*gr1north[icent],psize,color[icent],style[icent],0,0);
SetStyle(*gr1south[icent],psize,color[icent+isys],style[icent+isys],0,0);
SetStyle(*gr2north[icent],psize,color[icent],style[icent],0,0);
SetStyle(*gr2south[icent],psize,color[icent+isys],style[icent+isys],0,0);
SetStyle(*gr3north[icent],psize,color[icent],style[icent],0,0);
SetStyle(*gr3south[icent],psize,color[icent],style[icent],0,0);
SetRange(*gr1north[icent],ptbin[0],-0.07,ptbin[npt-4],0.001);
SetRange(*gr1south[icent],ptbin[0],-0.01,ptbin[npt-4],0.001);
SetRange(*gr2north[icent],ptbin[0],-0.001,ptbin[npt-4],0.02);
SetRange(*gr2south[icent],ptbin[0],-0.001,ptbin[npt-4],0.006);
if(isys==ndiv){
SetRange(*gr1south[icent],ptbin[0],0.7,ptbin[npt-4],1.3);
SetRange(*gr2south[icent],ptbin[0],0.8,ptbin[npt-4],1.2);
}
SetRange(*gr3north[icent],ptbin[0],-0.015,ptbin[npt-4],0.015);
SetRange(*gr3south[icent],ptbin[0],-0.015,ptbin[npt-4],0.015);
gr1north[icent]->SetTitle("");
gr1north[icent]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
gr1north[icent]->GetYaxis()->SetTitle("c_{1}");
gr1south[icent]->SetTitle("");
gr1south[icent]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
gr1south[icent]->GetYaxis()->SetTitle("c_{1}");
gr2north[icent]->SetTitle("");
gr2north[icent]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
gr2north[icent]->GetYaxis()->SetTitle("c_{2}");
gr2south[icent]->SetTitle("");
gr2south[icent]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
gr2south[icent]->GetYaxis()->SetTitle("c_{2}");
if(isys==ndiv){
//gr2south[icent]->GetYaxis()->SetTitle("ratio PC3matching #sigma=2/Default");
gr2south[icent]->GetYaxis()->SetTitle("c_{2} ratio");
gr1south[icent]->GetYaxis()->SetTitle("c_{1} ratio");
}
gr3north[icent]->SetTitle("");
gr3north[icent]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
gr3north[icent]->GetYaxis()->SetTitle("c_{3}");
gr3south[icent]->SetTitle("");
gr3south[icent]->GetXaxis()->SetTitle("p_{T} (GeV/c)");
gr3south[icent]->GetYaxis()->SetTitle("c_{3}");
leg7->SetFillColor(0);
leg7->SetTextSize(0.04);
leg8->SetFillColor(0);
leg8->SetTextSize(0.04);
leg9->SetFillColor(0);
leg9->SetTextSize(0.04);
leg10->SetFillColor(0);
leg10->SetTextSize(0.04);
leg11->SetFillColor(0);
leg11->SetTextSize(0.04);
leg12->SetFillColor(0);
leg12->SetTextSize(0.04);
leg7->AddEntry(gr1north[icent],Form("%.f<=centrality<%.f",centbin[icent],centbin[icent+1]),"lp");
leg8->AddEntry(gr1south[icent],Form("%.f<=centrality<%.f",centbin[icent],centbin[icent+1]),"lp");
leg9->AddEntry(gr2north[icent],Form("%.f<=centrality<%.f",centbin[icent],centbin[icent+1]),"lp");
//leg4->AddEntry(gr2south[icent],Form("%.f<=centrality<%.f",centbin[icent],centbin[icent+1]),"lp");
if(isys==0){
    if(str=="PC3")
leg10->AddEntry(gr2south[icent],Form("Default:PC3Matching #sigma = 3"),"lp");
    if(str=="PU")
leg10->AddEntry(gr2south[icent],Form("Default:All lumis"),"lp");
}
else if(isys==1){
    if(str=="PC3")
leg10->AddEntry(gr2south[icent],Form("PC3Matching #sigma = 2"),"lp");
    if(str=="PU")
leg10->AddEntry(gr2south[icent],Form("low lumi: rate<150kHz"),"lp");
    if(str=="EW")
leg10->AddEntry(gr2south[icent],Form("East Arm"),"lp");
}
else if(str=="PU" && isys==2)
leg10->AddEntry(gr2south[icent],Form("high lumi: rate>150kHz"),"lp");
else if(str=="EW" && isys==2)
leg10->AddEntry(gr2south[icent],Form("West Arm"),"lp");
leg11->AddEntry(gr3north[icent],Form("%.f<=centrality<%.f",centbin[icent],centbin[icent+1]),"lp");
leg12->AddEntry(gr3south[icent],Form("%.f<=centrality<%.f",centbin[icent],centbin[icent+1]),"lp");
c7->cd();
if(icent==0){gr1north[icent]->Draw(drawstring[isys].Data());leg7->Draw("same");t.DrawLatex(0.2,0.2,"c_{1} 1.5<|#eta_{asso}|<3.0");}
else gr1north[icent]->Draw("Psame");

if(isys<ndiv){
c8->cd(1);
if(icent==0) {
    gr1south[icent]->Draw(drawstring[isys].Data());leg10->Draw("same");
    }
    else {
    gr1south[icent]->Draw("Psame");
    }
}
else{
    c8->cd(2);
    if(icent==0) {
    TF1 *f1 = new TF1("f1","pol0",0.2,3.);
    if(isys==ndiv){
    gr1south[icent]->Fit("f1","R");
    cout<<setprecision(2);
    cout<<100*fabs(f1->Eval(0.75)-1)<<"\t"<<100*fabs(f1->Eval(2.5)-1)<<endl;
    }
    gr1south[icent]->Draw(drawstring[isys].Data());
    leg101->SetFillColor(0);
    leg101->SetTextSize(0.04);
if(isys==ndiv){
    if(str=="PC3")
leg101->AddEntry(gr1south[icent],Form("PC3Matching #sigma = 2/#sigma = 3"),"lp");
    if(str=="PU")
leg101->AddEntry(gr1south[icent],Form("low lumi: rate<150kHz/All lumis"),"lp");
    if(str=="EW")
leg101->AddEntry(gr1south[icent],Form("East/Total"),"lp");
}
else if(str=="PU" && isys==ndiv+1)
leg101->AddEntry(gr1south[icent],Form("high lumi: rate>150kHz/All lumis"),"lp");
else if(str=="EW" && isys==ndiv+1)
leg101->AddEntry(gr1south[icent],Form("West/Total"),"lp");
    leg101->Draw("same");
    TLine *l = new TLine(ptbin[0],1.0,ptbin[npt-4],1.);
    l->SetLineStyle(2);
    l->Draw("same");
    }
    else{
    gr1south[icent]->Draw("Psame");
    }
}

c9->cd();
if(icent==0){gr2north[icent]->Draw(drawstring[isys].Data());leg9->Draw("same");t.DrawLatex(0.2,0.2,"c_{2} 1.5<|#eta_{asso}|<3.0");}
else gr2north[icent]->Draw("Psame");

if(isys<ndiv){
c10->cd(1);
if(icent==0) {
    gr2south[icent]->Draw(drawstring[isys].Data());leg10->Draw("same");
    }
    else {
    gr2south[icent]->Draw("Psame");
    }
}
else{
    c10->cd(2);
    if(icent==0) {
    TF1 *f1 = new TF1("f1","pol0",0.2,3.);
    if(isys==ndiv){
    gr2south[icent]->Fit("f1","R");
    cout<<setprecision(2);
    cout<<100*fabs(f1->Eval(0.75)-1)<<"\t"<<100*fabs(f1->Eval(2.5)-1)<<endl;
    }
    gr2south[icent]->Draw(drawstring[isys].Data());
    leg102->SetFillColor(0);
    leg102->SetTextSize(0.04);
if(isys==ndiv){
    if(str=="PC3")
leg102->AddEntry(gr2south[icent],Form("PC3Matching #sigma = 2/#sigma = 3"),"lp");
    if(str=="PU")
leg102->AddEntry(gr2south[icent],Form("low lumi: rate<150kHz/All lumis"),"lp");
    if(str=="EW")
leg102->AddEntry(gr2south[icent],Form("East/Total"),"lp");
}
else if(str=="PU" && isys==ndiv+1)
leg102->AddEntry(gr2south[icent],Form("high lumi: rate>150kHz/All lumis"),"lp");
else if(str=="EW" && isys==ndiv+1)
leg102->AddEntry(gr2south[icent],Form("West/Total"),"lp");
    leg102->Draw("same");
    TLine *l = new TLine(ptbin[0],1.0,ptbin[npt-4],1.);
    l->SetLineStyle(2);
    l->Draw("same");
    }
    else{
    gr2south[icent]->Draw("Psame");
    }
}


c11->cd();
if(icent==0){gr3north[icent]->Draw(drawstring[isys].Data());leg11->Draw("same");t.DrawLatex(0.2,0.2,"c_{3} 1.5<|#eta_{asso}|<3.0");}
else gr3north[icent]->Draw("Psame");

c12->cd();
if(icent==0) {gr3south[icent]->Draw(drawstring[isys].Data());leg12->Draw("same");t.DrawLatex(0.2,0.2,"c_{3} 1.0<|#eta_{asso}|<3.0");}
else gr3south[icent]->Draw("Psame");
}

}
/*
c1->Print(Form("fig/c1north_cent_%s_%ssys.pdf",type.Data(),str.Data()));
c2->Print(Form("fig/c1south_cent_%s_%ssys.pdf",type.Data(),str.Data()));
c3->Print(Form("fig/c2north_cent_%s_%ssys.pdf",type.Data(),str.Data()));
c4->Print(Form("fig/c2south_cent_%s_%ssys.pdf",type.Data(),str.Data()));
c5->Print(Form("fig/c3north_cent_%s_%ssys.pdf",type.Data(),str.Data()));
c6->Print(Form("fig/c3south_cent_%s_%ssys.pdf",type.Data(),str.Data()));

c7->Print(Form("fig/c1north_pt_%s_%ssys.pdf",type.Data(),str.Data()));
*/
//c8->Print(Form("fig/c1south_123corr_pt_%s_%ssys.pdf",type.Data(),str.Data()));
//c9->Print(Form("fig/c2north_pt_%s_%ssys.pdf",type.Data(),str.Data()));

//c10->Print(Form("fig/c2south_PC3Sigma2_pt_%s_%ssys.pdf",type.Data(),str.Data()));
/*
c11->Print(Form("fig/c3north_pt_%s_%ssys.pdf",type.Data(),str.Data()));
c12->Print(Form("fig/c3south_pt_%s_%ssys.pdf",type.Data(),str.Data()));
	
c1->Print(Form("fig/c1north_cent_%s_%ssys.png",type.Data(),str.Data()));
c2->Print(Form("fig/c1south_cent_%s_%ssys.png",type.Data(),str.Data()));
c3->Print(Form("fig/c2north_cent_%s_%ssys.png",type.Data(),str.Data()));
c4->Print(Form("fig/c2south_cent_%s_%ssys.png",type.Data(),str.Data()));
c5->Print(Form("fig/c3north_cent_%s_%ssys.png",type.Data(),str.Data()));
c6->Print(Form("fig/c3south_cent_%s_%ssys.png",type.Data(),str.Data()));

c7->Print(Form("fig/c1north_pt_%s_%ssys.png",type.Data(),str.Data()));
*/
c8->Print(Form("fig/c1south_123corrbs_pt_%s_%ssys.png",type.Data(),str.Data()));
//c9->Print(Form("fig/c2north_pt_%s_%ssys.png",type.Data(),str.Data()));

c10->Print(Form("fig/c2south_123corrbs_pt_%s_%ssys.png",type.Data(),str.Data()));
/*
c11->Print(Form("fig/c3north_pt_%s_%ssys.png",type.Data(),str.Data()));
c12->Print(Form("fig/c3south_pt_%s_%ssys.png",type.Data(),str.Data()));
*/
}
Esempio n. 11
0
void cMiniBench::OutputSeconds(double adoubleResult, string aOutputMessage )
{
//   string lstrResult;
//   lstrResult. setNum( adoubleResult / 1000, 'g', 4 );
   cout << aOutputMessage << " (s): " <<  setw( 6 ) << setiosflags(ios::fixed) << setprecision(3)  << adoubleResult << endl;
}
Esempio n. 12
0
bool                              // returns true if success
processMultiGraphSection(FILE *fp,
			 string& theline,
			 bool& new_section)
{
  vector<string> v_tokens;
  TString  title;
  string   *gid  = NULL;
  TVectorD vx,vy,vz,exl,exh,eyl,eyh;
  float xoffset=0.0,yoffset=0.0, yscale=1.0;
  float xmin=0.,xmax=0.,ymin=0.,ymax=0.,zmin=0.,zmax=0.;
  bool asymerrors = false;
  wGraph_t *wg = NULL;

  char xheader[80],yheader[80];
  xheader[0]=0;
  yheader[0]=0;

  if (gl_verbose) cout << "Processing multigraph section" << endl;

  new_section=false;

  while (getLine(fp,theline,"multigraph")) {
    if (!theline.size()) continue;
    if (theline[0] == '#') continue; // comments are welcome

    if (theline[0] == '[') {
      new_section=true;
      break;
    }

    string key, value;
    if (!getKeyValue(theline,key,value)) continue;

    //--------------------
    if (key == "id") {
    //--------------------
      if (gid != NULL) {
	cerr << "no more than one id per section allowed " << value << endl;
	break;
      }

      gid = new string(value);

    //------------------------------
    } else if (key == "graphs") {
    //------------------------------
      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }

      Tokenize(value,v_tokens,","); 

      for (size_t i=0; i<v_tokens.size(); i++) {
	map<string,wGraph_t *>::const_iterator it = glmap_id2graph.find(v_tokens[i]);
	if( it == glmap_id2graph.end() ) {
	  cerr << "Graph ID " << v_tokens[i] << " not found,";
	  cerr << "graphs must be defined before multigraph section" << endl;
	  break;
	}
	wg  = new wGraph_t(*(it->second),*gid);
	
      }
      if (wg) {
	cerr << "graph already defined" << endl; continue;
      }
      if (inSet<string>(glset_graphFilesReadIn,path)) {
	cerr << "vector file " << path << " already read in" << endl; break;
      }

      wg = new wGraph_t();

      if (asymerrors)
	loadVectorsFromFile(path.c_str(),scanspec.c_str(),vx,vy,exl,exh,eyl,eyh);
      else
	loadVectorsFromFile(path.c_str(),scanspec.c_str(),vx,vy,xheader,yheader);

      if (strlen(xheader)) wg->xax->SetTitle(xheader);
      if (strlen(yheader)) wg->yax->SetTitle(yheader);

    //------------------------------
    } else if (key == "vectorfile2d") {
    //------------------------------
      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      string path = value;
      if (wg) {
	cerr << "graph already defined" << endl; continue;
      }
      if (inSet<string>(glset_graphFilesReadIn,path)) {
	cerr << "vector file " << path << " already read in" << endl; break;
      }

      wg = new wGraph_t();

      wg->gr2d = new TGraph2D(path.c_str());

      if (wg->gr2d->IsZombie()) {
	cerr << "Unable to make Graph2D from file " << path << endl;
	exit(-1);
      }
      wg->gr2d->SetName(gid->c_str());

    //------------------------------
    } else if (key == "path") {
    //------------------------------

      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (wg) {
	cerr << "graph already defined" << endl; continue;
      }
      wg = new wGraph_t();
      wg->gr  = getGraphFromSpec(*gid,value);
      if (!wg->gr) continue;

    //------------------------------
    } else if (key == "clone") {
    //------------------------------

      if (!gid) {
	cerr << "id key must be defined first in the section" << endl; continue;
      }
      if (wg) {
	cerr << "graph already defined" << endl; continue;
      }
      map<string,wGraph_t *>::const_iterator it = glmap_id2graph.find(value);
      if( it == glmap_id2graph.end() ) {
	cerr << "Graph ID " << value << " not found,";
	cerr << "clone must be defined after the clonee" << endl;
	break;
      }
      wg  = new wGraph_t(*(it->second),*gid);

    //------------------------------
    } else if (key == "bayesdiv") {
    //------------------------------

      Tokenize(value,v_tokens,",/"); // either comma-separated or using '/'
      if (v_tokens.size() != 2) {
	cerr << "expect comma-separated list of exactly two histo specs to divide! ";
	cerr << theline << endl;
	continue;
      }

      TH1 *tmph1 = (TH1 *)findHisto(v_tokens[0]); if (!tmph1) exit(-1);
      TH1 *tmph2 = (TH1 *)findHisto(v_tokens[1]); if (!tmph2) exit(-1);

      cout << tmph1->GetNbinsX() << " " << tmph2->GetNbinsX() << endl;

      wg = new wGraph_t();

      // equivalent to BayesDivide
      //
      if (gl_verbose) wg->gr = new TGraphAsymmErrors(tmph1,tmph2,"debug");
      else            wg->gr = new TGraphAsymmErrors(tmph1,tmph2,"");
      //if (gl_verbose) wg->gr = new TGraphAsymmErrors(tmph1,tmph2,"cl=0.683 b(1,1) mode v");
      //else            wg->gr = new TGraphAsymmErrors(tmph1,tmph2,"cl=0.683 b(1,1) mode");
      if (!wg->gr) {
	cerr << "BayesDivide didn't work! wonder why..." << endl;
	continue;
      } else if (gl_verbose) {
	cout << wg->gr->GetN() << " points in the graph" << endl;
      }

    } else if (!wg) {
      cerr<<"One of keys path,clone,vectorfile,vectorfile2d or bayesdiv must be defined before key..."<<key<<endl;
    } else {
      if     ( key == "xoffset" )      xoffset   = str2flt(value);
      else if( key == "yoffset" )      yoffset   = str2flt(value);
      else if( key == "yscale" )       yscale    = str2flt(value);
      else if( key == "title"  )       title     = TString(value);
      else if( key == "xtitle" )       wg->xax->SetTitle(value.c_str());
      else if( key == "ytitle" )       wg->yax->SetTitle(value.c_str());
      else if( key == "ztitle" )       wg->zax->SetTitle(value.c_str());
      else if( key == "xtitleoffset" ) wg->xax->SetTitleOffset(str2flt(value));
      else if( key == "ytitleoffset" ) wg->yax->SetTitleOffset(str2flt(value));
      else if( key == "ztitleoffset" ) wg->zax->SetTitleOffset(str2flt(value));
      else if( key == "xmin" )         xmin      = str2flt(value);
      else if( key == "xmax" )         xmax      = str2flt(value);
      else if( key == "ymin" )         ymin      = str2flt(value);
      else if( key == "ymax" )         ymax      = str2flt(value);
      else if( key == "zmin" )         zmin      = str2flt(value);
      else if( key == "zmax" )         zmax      = str2flt(value);
      else if( key == "linecolor" )    wg->lcolor  = str2int(value);
      else if( key == "linestyle" )    wg->lstyle  = str2int(value);
      else if( key == "linewidth" )    wg->lwidth  = str2int(value);
      else if( key == "markercolor" )  wg->mcolor  = str2int(value);
      else if( key == "markerstyle" )  wg->mstyle  = str2int(value);
      else if( key == "markersize"  )  wg->msize   = str2int(value);
      else if( key == "fillcolor" )    wg->fcolor  = str2int(value);
      else if( key == "fillstyle" )    wg->fstyle  = str2int(value);
      else if( key == "xndiv" )        wg->xax->SetNdivisions(str2int(value));
      else if( key == "yndiv" )        wg->yax->SetNdivisions(str2int(value));
      else if( key == "asymerrors" )   asymerrors  = (bool)str2int(value);
      else if( key == "leglabel" )     wg->leglabel   = value;
      else if( key == "draw" )         wg->drawopt    = value;
      else if( key == "legdraw" )      wg->legdrawopt = value;
      else if( key == "setprecision" ) cout << setprecision(str2int(value));
      else if( key == "printvecs2file") printVectorsToFile(wg); // ,value);
      else if( key == "fittf1" ) {
	TF1 *tf1 = findTF1(value);
	if( !tf1 ) {
	  cerr << "TF1 " << value << " must be defined first" << endl;
	  continue;
	}
	string funcnewname = value+(*gid);
	wg->fitfn = new TF1(*tf1);
	wg->fitfn->SetName(funcnewname.c_str());
      }
      else if ( key == "contours" ) {
	Tokenize(value,v_tokens,",");
	wg->contours = new TVectorD(v_tokens.size());
	for (size_t i=0; i<v_tokens.size(); i++)
	  wg->contours[i] = str2flt(v_tokens[i]);
      }
      else {
	cerr << "unknown key " << key << endl;
      }
#if 0
      processCommonHistoParams(key,value,*wh);
#endif
    }
  }

  //cout << title << endl;
  if (wg->gr2d) {
    wg->gr2d->SetTitle(title);
    wg->gr2d->SetLineStyle   (wg->lstyle);
    wg->gr2d->SetLineColor   (wg->lcolor);
    wg->gr2d->SetLineWidth   (wg->lwidth);
    wg->gr2d->SetMarkerColor (wg->mcolor);
    wg->gr2d->SetMarkerStyle (wg->mstyle);
    wg->gr2d->SetMarkerSize  (wg->msize);
    wg->gr2d->SetFillStyle   (wg->fstyle);
    wg->gr2d->SetFillColor   (wg->fcolor);
    if (zmax>zmin)  
      wg->zax->SetLimits(zmin,zmax);
  } else {
    if (vx.GetNoElements()) { // load utility guarantees the same size for both
      if (yscale  != 1.0) vy *= yscale;
      if (xoffset != 0.0) vx += xoffset;
      if (yoffset != 0.0) vy += yoffset;
      if (asymerrors) 
	wg->gr = new TGraphAsymmErrors(vx,vy,exl,exh,eyl,eyh);
      else
	wg->gr = new TGraph(vx,vy);
    }
    wg->gr->UseCurrentStyle();
    wg->gr->SetTitle(title);
    wg->gr->SetLineStyle   (wg->lstyle);
    wg->gr->SetLineColor   (wg->lcolor);
    wg->gr->SetLineWidth   (wg->lwidth);
    wg->gr->SetMarkerColor (wg->mcolor);
    wg->gr->SetMarkerStyle (wg->mstyle);
    wg->gr->SetMarkerSize  (wg->msize);
    wg->gr->SetFillStyle   (wg->fstyle);
    wg->gr->SetFillColor   (wg->fcolor);

    if (xmax>xmin) wg->xax->SetLimits(xmin,xmax);
    if (ymax>ymin) wg->yax->SetLimits(ymin,ymax);
  }

  glmap_id2graph.insert(pair<string,wGraph_t *>(*gid,wg));

  return (wg != NULL);
}                                                 // processGraphSection
Esempio n. 13
0
void sum_and_output4(vector<aa_rou> proteins2, vector<aa_rou> proteins1, vector<aa_rou> proteins)
{
            int i,j,k; 

            char  *temp;

            string residue1[19];
            string temp1;
  
           
            //double angle_total_value,angle_average_value;
            double  angle_total_num,angle_total_num1,angle_total_num2;

            //angle_total_value=0;
            angle_total_num=0;
            angle_total_num1=0;
            angle_total_num2=0;
   
            residue1[0]="ALA";
            residue1[1]="VAL";
            residue1[2]="PHE";
            residue1[3]="PRO";
            residue1[4]="MET";
            residue1[5]="ILE";
            residue1[6]="LEU";
            residue1[7]="ASP";
            residue1[8]="GLU";
            residue1[9]="LYS";
            residue1[10]="ARG";
            residue1[11]="SER";
            residue1[12]="THR";
            residue1[13]="TYR";
            residue1[14]="HIS";
            residue1[15]="CYS";
            residue1[16]="ASN";
            residue1[17]="GLN";
            residue1[18]="TRP";

            temp=new char[20];
                
            double  num_of_aa[19], num_of_aa1[19],num_of_aa2[19];
            double angle_total_value[19],angle_total_value1[19],angle_total_value2[19];
            double angle_average_value[19],angle_average_value1[19],angle_average_value2[19];

  
       //for patch_0_1 
       for(k=0;k<19;k++)
       {  
          angle_total_value[k]=0; 
          num_of_aa[k]=0;
          angle_average_value[k]=0;

          temp1=residue1[k]+".patch_0_1";
          strcpy(temp,temp1.c_str()); 
          cout<<temp1<<endl;
	  ofstream file(temp,ios::out|ios::app);
	  file<<setiosflags(ios::left)<<setw(10)<<"angle"<<"\t"<<"type"<<endl;

	  for(i=0;i<proteins.size();i++)
	  {
	    if(strncmp(proteins[i].res_id,temp,3)==0)
            {
               angle_total_value[k]=angle_total_value[k]+proteins[i].angle;
               angle_total_num=angle_total_num+1;
               num_of_aa[k]=num_of_aa[k]+1;
               file<<setiosflags(ios::left)<<setw(10)<<proteins[i].angle<<"\t"<<proteins[i].res_id<<endl;  
            }//end if
          } //end for

           angle_average_value[k]=angle_total_value[k]/num_of_aa[k];

        file.close();
      } // end of for k=0

        //for patch_1_10  
       for(k=0;k<19;k++)
       {  

          angle_total_value1[k]=0; 
          num_of_aa1[k]=0;
          angle_average_value1[k]=0;
 
          temp1=residue1[k]+".patch_1_10";
          strcpy(temp,temp1.c_str()); 
          cout<<temp1<<endl;
	  ofstream file(temp,ios::out|ios::app);
	  file<<setiosflags(ios::left)<<setw(10)<<"angle"<<"\t"<<"type"<<endl;
	  for(i=0;i<proteins1.size();i++)
	  {
	    if(strncmp(proteins1[i].res_id,temp,3)==0)
            {
               angle_total_value1[k]=angle_total_value1[k]+proteins1[i].angle;
               angle_total_num1=angle_total_num1+1;
               num_of_aa1[k]=num_of_aa1[k]+1;
 
               file<<setiosflags(ios::left)<<setw(10)<<proteins1[i].angle<<"\t"<<proteins1[i].res_id<<endl;  
            }//end if
          }//end for

           angle_average_value1[k]=angle_total_value1[k]/num_of_aa1[k];

        file.close();
      } // end of for k=0

       //for patch_>_10
       for(k=0;k<19;k++)
       {  
          angle_total_value2[k]=0; 
          num_of_aa2[k]=0;
          angle_average_value2[k]=0;
           
          temp1=residue1[k]+".patch_>_10";
          strcpy(temp,temp1.c_str()); 
          cout<<temp1<<endl;
	  ofstream file(temp,ios::out|ios::app);
	  file<<setiosflags(ios::left)<<setw(10)<<"angle"<<"\t"<<"type"<<endl;
	  for(i=0;i<proteins2.size();i++)
	  {
	    if(strncmp(proteins2[i].res_id,temp,3)==0)
            {
               angle_total_value2[k]=angle_total_value2[k]+proteins2[i].angle;
               angle_total_num2=angle_total_num2+1;
               num_of_aa2[k]=num_of_aa2[k]+1;
 
               file<<setiosflags(ios::left)<<setw(10)<<proteins2[i].angle<<"\t"<<proteins2[i].res_id<<endl;  
            }
          }

           angle_average_value2[k]=angle_total_value2[k]/num_of_aa2[k];

        file.close();
      } // end of for k=0

          double pro_aa[19],pro_aa1[19],pro_aa2[19];
          double t;
             
              t=0;

           for(i=0;i<19;i++)
           { 
            pro_aa[i]=0;
            pro_aa1[i]=0;
            pro_aa2[i]=0;
  
            t=num_of_aa[i]/angle_total_num*100;
            pro_aa[i]=t;

            t=num_of_aa1[i]/angle_total_num1*100;
            pro_aa1[i]=t;

            t=num_of_aa2[i]/angle_total_num2*100;
            pro_aa2[i]=t;

           }

          ofstream file1("aa.txt",ios::out|ios::app);
          file1<<"0_1_patch "<<"\t"<<angle_total_num<<"\t"
               <<"1_10_patch"<<"\t"<<angle_total_num1<<"\t"
               <<"10_patch  "<<"\t"<<angle_total_num2<<endl;
          
          
         for(i=0;i<19;i++)
          { 
	  file1<<setiosflags(ios::left)<<setw(10)<<residue1[i]<<setiosflags(ios::fixed)
               <<setiosflags(ios::left)<<setprecision(2)<<setw(5)<<pro_aa[i]
               <<setiosflags(ios::left)<<setprecision(2)<<setw(5)<<pro_aa1[i]
               <<setiosflags(ios::left)<<setprecision(2)<<setw(5)<<pro_aa2[i]
               <<endl;
          }

          ofstream file2("omega.txt",ios::out|ios::app);
          file2<<"0_1_patch "<<"\t"<<angle_total_num<<"\t"
               <<"1_10_patch"<<"\t"<<angle_total_num1<<"\t"
               <<"10_patch  "<<"\t"<<angle_total_num2<<endl;
          
          
         for(i=0;i<19;i++)
          { 
	  file2<<setiosflags(ios::left)<<setw(10)<<residue1[i]<<setiosflags(ios::fixed)
               <<setiosflags(ios::left)<<setprecision(2)<<setw(10)<<angle_average_value[i]
               <<setiosflags(ios::left)<<setprecision(2)<<setw(10)<<angle_average_value1[i]
               <<setiosflags(ios::left)<<setprecision(2)<<setw(10)<<angle_average_value2[i]
               <<endl;
          }

          file1.close(); 

          file2.close(); 
        
}// end of function sum_and_output4
Esempio n. 14
0
int main(int argc, char *argv[]){
  
  char DFin_location[256];
  DFin_location = argv[1] ;
  char DFout_location[256] argv[2];
  char AnaFile[256] = argv[3] ;
  char SimFile[256] = argv[4] ;
  int TriggerBucket = atoi(argv[5]);
  int RUN = atoi(argv[5]);

  std::cout << argv[1] << std::endl;  
  std::cout << DFin_location << std::endl;

  return;



  //here goes the first file
  TChain * DFinput = new TChain("Telescope");
  DFinput->Add(DFin_location);

  unsigned int Event_in;
  int roc_in;
  int col_in,row_in,vcal_in;
  float flux_in;
  double pulseHeight_in;
  std::cout << roc_in << std::endl;

  DFinput->SetBranchStatus("*",false);

  DFinput->SetBranchStatus("Event",true);
  DFinput->SetBranchStatus("roc",true);
  DFinput->SetBranchStatus("pulseHeight",true);
  DFinput->SetBranchStatus("vcal",true);
  DFinput->SetBranchStatus("col",true);
  DFinput->SetBranchStatus("row",true);
  DFinput->SetBranchStatus("flux",true);

  DFinput->SetBranchAddress("Event",&Event_in);
  DFinput->SetBranchAddress("roc",&roc_in);
  DFinput->SetBranchAddress("row",&row_in);
  DFinput->SetBranchAddress("col",&col_in);
  DFinput->SetBranchAddress("vcal",&vcal_in);
  DFinput->SetBranchAddress("flux",&flux_in);
  DFinput->SetBranchAddress("pulseHeight",&pulseHeight_in);

  std::cout << "Loaded DF input file from: " << DFin_location << std::endl;


  //here goes the second file
  TChain * DFoutput = new TChain("hitTree");
  DFoutput->Add(DFout_location);

  unsigned int event_number;
  int roc_out,col_out,row_out,vcal_out;
  double pulseHeight_out;
  long TS_out;


  DFoutput->SetBranchStatus("*",false);

  DFoutput->SetBranchStatus("event_number",true);
  DFoutput->SetBranchStatus("TS",true);
  DFoutput->SetBranchStatus("roc",true);
  DFoutput->SetBranchStatus("col",true);
  DFoutput->SetBranchStatus("row",true);
  DFoutput->SetBranchStatus("vcal",true);
  DFoutput->SetBranchStatus("pulseHeight",true);


  DFoutput->SetBranchAddress("event_number",&event_number);
  DFoutput->SetBranchAddress("TS",&TS_out);
  DFoutput->SetBranchAddress("roc",&roc_out);
  DFoutput->SetBranchAddress("col",&col_out);
  DFoutput->SetBranchAddress("row",&row_out);
  DFoutput->SetBranchAddress("vcal",&vcal_out);
  DFoutput->SetBranchAddress("pulseHeight",&pulseHeight_out);

  std::cout << "Loaded DF output file from: " << DFout_location << std::endl;

  //here come the analysis files
  //comes later


  //here come the original run data files



  //Now we make some histograms we want to compare


  TCanvas * c1 = new TCanvas("Comparison","Comparison",1200,1200);
  // gStyle->SetOptStat(0);
  c1->Divide(2,2);

  c1->cd(1);



  TH1I * Pixels_per_Event_in = new TH1I("Pixels per Event", "DataFlow input",20,0,20);
  unsigned int temp_evtn=-1;

  int ROC_DUT = 3;
  int nhits = 0;
  std::cout << "Total Entries input : " <<  DFinput->GetEntries() << std::endl;
  std::cout << "Total Entries output: " <<  DFoutput->GetEntries() << std::endl;
  long int maxEntries = DFinput->GetEntries();
  for(int i = 0; i < maxEntries; ++i)
    //for(int i = 0; i < 5000000; ++i)
    {
      DFinput->GetEntry(i);
      if(i%100000 == 0) std::cout << setprecision(2) << "Entry: " << i << "    " << (double)(i*100)/maxEntries << "%" << std::endl;
      //std::cout << "Entry: " << i << "Event " << Event_in << "ROC " << roc_in << " " << row_in << "|" << col_in << std::endl;
      temp_evtn = Event_in;
      if(Event_in%588 == TriggerBucket)
	{
	  if(roc_in == -1)
	    {
	      Pixels_per_Event_in->Fill(0);
	      continue;
	    }
	  else
	    {
	      while(Event_in == temp_evtn)
		{
		  // std::cout << "I'm in the loop. ROC " << roc_in << std::endl;
		  if(roc_in == ROC_DUT)
		    {
		      ++nhits;
		    }
		  ++i;
		  if(i == maxEntries) break;
		  DFinput->GetEntry(i);
		  //	      std::cout << "Entry: " << i << "Event " << Event_in << "ROC " << roc_in <<   std::endl;
		}
	    }
	  --i;
	  Pixels_per_Event_in->Fill(nhits);
	  //	  std::cout << "Found event with " << nhits << "Hits on ROC " << ROC_DUT << std::endl;
	  nhits = 0;
	}
    }

    
  Pixels_per_Event_in->Draw();
  c1->Update();
  //second histogram
  std::cout << "Second histogramm" << std::endl;

  TH1I * Pixels_per_Event_out = new TH1I("Pixels per Event","DataFlow output",20,0,20);
  for(int i = 0; i < DFoutput->GetEntries();++i)
    {
      DFoutput->GetEntry(i);
      //if(i%100 == 0) std::cout << "Entry: " << i << "Event " << event_number << "ROC " << roc_out <<   std::endl;
      //      std::cout << "Entry: " << i << "Event " << event_number << "ROC " << roc_out <<   std::endl;
      temp_evtn = event_number;
      if(roc_out == -1)
	{
	  nhits = 0;
	 Pixels_per_Event_out->Fill(nhits);
	  continue;
	}
      else
	{
	  while(event_number == temp_evtn)
	    {
	      // std::cout << "I'm in the loop. ROC " << roc_in << std::endl;
	      if(roc_out == ROC_DUT)
		{
		  ++nhits;
		}
	      ++i;
	      if(i == DFoutput->GetEntries()) break;
	      DFoutput->GetEntry(i);
	      // std::cout << "Entry: " << i << "Event " << event_number << "ROC " << roc_out <<   std::endl;

	    }

	  --i;
	  Pixels_per_Event_out->Fill(nhits);
	  //	  std::cout << "Found event with " << nhits << "Hits on ROC " << ROC_DUT << std::endl;
	  nhits = 0;

	}

    }

  c1->cd(2);
  Pixels_per_Event_out->Draw();
  c1->Update();

  //picking up the 3rd histogram
  TFile * simAnaFile = new TFile(SimFile,"READ");
  if ( simAnaFile->IsOpen()) printf("File opened successfully\n");				    
  
				    
  char histname[256];
  sprintf(histname,"MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d%i",ROC_DUT);

  std::cout << histname << std::endl;

  TH1I * Hits_per_Event_sim;

  Hits_per_Event_sim=(TH1I*)simAnaFile->Get("MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d3");
  
  c1->cd(3);
 
  Hits_per_Event_sim->GetXaxis()->SetRangeUser(0,20);
 
  Hits_per_Event_sim->SetTitle("Analysis of simulated data");
 
  Hits_per_Event_sim->Draw();

  c1->Update();


  //pick up the last "original" histogram

  TFile * realAnaFile = new TFile(AnaFile,"READ");
  if ( realAnaFile->IsOpen()) printf("File opened successfully\n");				    
  
				    
  sprintf(histname,"MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d%i",ROC_DUT);

  TH1I * Hits_per_Event_ana;


  Hits_per_Event_ana=(TH1I*)realAnaFile->Get("MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d3");
  
  c1->cd(4);
  Hits_per_Event_ana->GetXaxis()->SetRangeUser(0,20);
  Hits_per_Event_ana->SetTitle("Analysis of measured data");
  Hits_per_Event_ana->Draw();

  c1->Update();

  char txt[256];
  sprintf(txt,"RUN%i_PixelsPerEvent.pdf",RUN);
  c1->SaveAs(txt);

  ///now for future references I'll try everything in one plot

  TCanvas * c2 = new TCanvas("c2","c2",600,600);
  c2->cd();
  //  gStyle->SetOptStat(0);

  double norm = 100.;
  std::cout << Pixels_per_Event_in->Integral() << std::endl;
  //Pixels_per_Event_out->GetXaxis()->SetLimits(0, norm);
  Pixels_per_Event_out->Scale(norm/Pixels_per_Event_out->Integral());
  Pixels_per_Event_out->SetMaximum(100);
  Pixels_per_Event_out->SetLineColor(2);
  Pixels_per_Event_out->SetLineWidth(3);
  Pixels_per_Event_out->Draw("SAME");

  Hits_per_Event_sim->Scale(norm/Hits_per_Event_sim->Integral());
  Hits_per_Event_sim->SetMaximum(100);
  Hits_per_Event_sim->SetLineColor(3);
  Hits_per_Event_sim->SetLineWidth(3);
  Hits_per_Event_sim->Draw("SAME");

  Hits_per_Event_ana->Scale(norm/Hits_per_Event_ana->Integral());
  Hits_per_Event_ana->SetMaximum(100);
  Hits_per_Event_ana->SetLineColor(4);
  Hits_per_Event_ana->SetLineWidth(3);
  Hits_per_Event_ana->Draw("SAME");

  Pixels_per_Event_in->Scale(norm/Pixels_per_Event_in->Integral());
  Pixels_per_Event_in->SetMaximum(100);
  Pixels_per_Event_in->SetLineColor(1);
  Pixels_per_Event_in->SetLineWidth(3);
  Pixels_per_Event_in->Draw("SAME");

  TLegend * leg1 = new TLegend(0.75,0.9,0.35,0.75);
  leg1->AddEntry(Pixels_per_Event_in,"DataFlow input","L");
  leg1->AddEntry(Pixels_per_Event_out,"DataFlow output","L");
  leg1->AddEntry(Hits_per_Event_sim,"Analysis of simulated data","L");
  leg1->AddEntry(Hits_per_Event_ana,"Analysis of measured data","L");


  leg1->Draw();


  c2->Update();


  sprintf(txt,"RUN%i_PixelsPerEventNorm.pdf",RUN);
  c2->SaveAs(txt);

  /*
   *  Now some more plots
   */

  //hit map
  //simulated data
  TCanvas * c3 = new TCanvas("c3","c3",1200,600);
  c3->Divide(2,1);
  c3->cd(1);
  
  sprintf(histname,"MyCMSPixelClusteringProcessor/detector_3/pixelPerEvent_d%i",ROC_DUT);

  std::cout << histname << std::endl;

  TH2D * Hit_Map_sim;


  Hit_Map_sim=(TH2D*)simAnaFile->Get("MyCMSPixelClusteringProcessor/detector_3/hitMap_d3");
  

  Hit_Map_sim->SetTitle("Analysis of simulated data");
  Hit_Map_sim->Draw("COLZ");
  Hit_Map_sim->SetStats(0);
  c3->Update();

  //measured data

  c3->cd(2);

  TH2D * Hit_Map_ana;
  

  Hit_Map_ana=(TH2D*)realAnaFile->Get("MyCMSPixelClusteringProcessor/detector_3/hitMap_d3");
  
 
  Hit_Map_ana->GetXaxis()->SetRangeUser(1,50);
  Hit_Map_ana->GetYaxis()->SetRangeUser(1,78);
  Hit_Map_ana->SetTitle("Analysis of measured data");
  Hit_Map_ana->Draw("COLZ");
  Hit_Map_ana->SetStats(0);

  char txt[256];
  sprintf(txt,"RUN%i_HitMap.pdf",RUN);
  c3->SaveAs(txt);


  /*
   *cluster size
   */

  //simulated data 
  TCanvas * c4 = new TCanvas("c4","c4",1200,600);
  c4->Divide(2,1);
  c4->cd(1);
  c4->SetLogy(1);

  sprintf(histname,"MyCMSPixelClusteringProcessor/detector_%i/clustersize_d%i",ROC_DUT,ROC_DUT);

  std::cout << histname << std::endl;

  TH1I * Clustersize_sim;


  Clustersize_sim=(TH1I*)simAnaFile->Get(histname);
  
 
  Clustersize_sim->GetXaxis()->SetRangeUser(0,20);
  Clustersize_sim->SetTitle("Analysis of simulated data");
  Clustersize_sim->Draw();
  c4->Update();

  //measured data
  c4->cd(2);
  c4->SetLogy(1);

  TH1I * Clustersize_ana;
  Clustersize_ana=(TH1I*)realAnaFile->Get(histname);
  
  Clustersize_ana->GetXaxis()->SetRangeUser(0,20);
  Clustersize_ana->SetTitle("Analysis of measured data");
  Clustersize_ana->Draw();
  c4->Update();

  sprintf(txt,"RUN%i_ClusterSize.pdf",RUN);
  c4->SaveAs(txt);
  
  /*
   *number of tracks
   */

  string simTrackFileName(SimFile);
  simTrackFileName = simTrackFileName.replace(simTrackFileName.find("clustering"), sizeof("clustering")-1,"tracks");
 
  char * filename = simTrackFileName.c_str();

  std::cout << filename << std::endl;

  TFile * simTrackFile = new TFile(filename,"READ");
  if ( simTrackFile->IsOpen()) printf("Track file opened successfully\n");				    

  TCanvas * c5 = new TCanvas("c5","c5",1200,600);
  c5->Divide(2,1);
  c5->SetLogy(1);
  c5->cd(1);
  sprintf(histname,"MyEUTelTestFitter/nTrack");
 
  std::cout << histname << std::endl;

  TH1D * NTracks_sim;
  NTracks_sim=(TH1D*)simTrackFile->Get(histname);
  NTracks_sim->SetTitle("Analysis of simulated data");
  NTracks_sim->Draw();
  c5->Update();

  string anaTrackFileName(AnaFile);
  anaTrackFileName = anaTrackFileName.replace(anaTrackFileName.find("clustering"), sizeof("clustering")-1,"tracks");
  char * filename2 = anaTrackFileName.c_str();

  TFile * anaTrackFile = new TFile(filename2,"READ");
  if ( anaTrackFile->IsOpen()) printf("Analysis track file opened successfully\n");				    

  c5->cd(2);
  c5->SetLogy(1);

  TH1D * NTracks_ana;
  NTracks_ana=(TH1D*)anaTrackFile->Get(histname);
  NTracks_ana->SetTitle("Analysis of measured data");
  NTracks_ana->Draw();
  c5->Update();

  sprintf(txt,"RUN%i_NumberOfTracks.pdf",RUN);
  c5->SaveAs(txt);



}//comparison()