Exemple #1
0
void
IpVerify::fill_table(PermTypeEntry * pentry, char * list, bool allow)
{
    assert(pentry);

	NetStringList * whichHostList = new NetStringList();
    UserHash_t * whichUserHash = new UserHash_t(1024, compute_host_hash);

    StringList slist(list);
	char *entry, * host, * user;
	slist.rewind();
	while ( (entry=slist.next()) ) {
		if (!*entry) {
			// empty string?
			slist.deleteCurrent();
			continue;
		}
		split_entry(entry, &host, &user);
		ASSERT( host );
		ASSERT( user );

			// If this is a hostname, get all IP addresses for it and
			// add them to the list.  This ensures that if we are given
			// a cname, we do the right thing later when trying to match
			// this record with the official hostname.
		StringList host_addrs;
		ExpandHostAddresses(host,&host_addrs);
		host_addrs.rewind();

		char const *host_addr;
		while( (host_addr=host_addrs.next()) ) {
			MyString hostString(host_addr);
			StringList * userList = 0;
				// add user to user hash, host to host list
			if (whichUserHash->lookup(hostString, userList) == -1) {
				whichUserHash->insert(hostString, new StringList(user)); 
				whichHostList->append(hostString.Value());
			}
			else {
				userList->append(user);
			}
		}

		free(host);
		free(user);
	}

    if (allow) {
        pentry->allow_hosts = whichHostList;
        pentry->allow_users  = whichUserHash;
    }
    else {
        pentry->deny_hosts = whichHostList;
        pentry->deny_users = whichUserHash;
    }
}
NS_IMETHODIMP
nsStrictTransportSecurityService::IsStsHost(const char* aHost, bool* aResult)
{
  // Should be called on the main thread (or via proxy) since the permission
  // manager is used and it's not threadsafe.
  NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_UNEXPECTED);

  nsCOMPtr<nsIURI> uri;
  nsDependentCString hostString(aHost);
  nsresult rv = NS_NewURI(getter_AddRefs(uri),
                          NS_LITERAL_CSTRING("https://") + hostString);
  NS_ENSURE_SUCCESS(rv, rv);
  return IsStsURI(uri, aResult);
}
nsresult
ProxyAutoConfig::GetProxyForURI(const nsCString &aTestURI,
                                const nsCString &aTestHost,
                                nsACString &result)
{
  if (mJSNeedsSetup)
    SetupJS();

  if (!mJSRuntime || !mJSRuntime->IsOK())
    return NS_ERROR_NOT_AVAILABLE;

  JSContext *cx = mJSRuntime->Context();
  JSAutoRequest ar(cx);
  JSAutoCompartment ac(cx, mJSRuntime->Global());

  // the sRunning flag keeps a new PAC file from being installed
  // while the event loop is spinning on a DNS function. Don't early return.
  sRunning = this;
  mRunningHost = aTestHost;

  nsresult rv = NS_ERROR_FAILURE;
  JS::RootedString uriString(cx, JS_NewStringCopyZ(cx, aTestURI.get()));
  JS::RootedString hostString(cx, JS_NewStringCopyZ(cx, aTestHost.get()));

  if (uriString && hostString) {
    JS::AutoValueArray<2> args(cx);
    args[0].setString(uriString);
    args[1].setString(hostString);

    JS::Rooted<JS::Value> rval(cx);
    bool ok = JS_CallFunctionName(cx, mJSRuntime->Global(),
                                  "FindProxyForURL", args, rval.address());

    if (ok && rval.isString()) {
      nsDependentJSString pacString;
      if (pacString.init(cx, rval.toString())) {
        CopyUTF16toUTF8(pacString, result);
        rv = NS_OK;
      }
    }
  }

  mRunningHost.Truncate();
  sRunning = nullptr;
  return rv;
}
nsresult
ProxyAutoConfig::GetProxyForURI(const nsCString &aTestURI,
                                const nsCString &aTestHost,
                                nsACString &result)
{
  if (mJSNeedsSetup)
    SetupJS();

  if (!mJSRuntime || !mJSRuntime->IsOK())
    return NS_ERROR_NOT_AVAILABLE;

  JSContext *cx = mJSRuntime->Context();
  JSAutoRequest ar(cx);

  // the sRunning flag keeps a new PAC file from being installed
  // while the event loop is spinning on a DNS function. Don't early return.
  sRunning = this;
  mRunningHost = aTestHost;

  nsresult rv = NS_ERROR_FAILURE;
  js::RootedString uriString(cx, JS_NewStringCopyZ(cx, aTestURI.get()));
  js::RootedString hostString(cx, JS_NewStringCopyZ(cx, aTestHost.get()));

  if (uriString && hostString) {
    js::RootedValue uriValue(cx, STRING_TO_JSVAL(uriString));
    js::RootedValue hostValue(cx, STRING_TO_JSVAL(hostString));

    jsval argv[2] = { uriValue, hostValue };
    jsval rval;
    JSBool ok = JS_CallFunctionName(cx, mJSRuntime->Global(),
                                    "FindProxyForURL", 2, argv, &rval);

    if (ok && rval.isString()) {
      nsDependentJSString pacString;
      if (pacString.init(cx, rval.toString())) {
        CopyUTF16toUTF8(pacString, result);
        rv = NS_OK;
      }
    }
  }

  mRunningHost.Truncate();
  sRunning = nullptr;
  return rv;
}
Exemple #5
0
int main( int argc, char* argv[] ) {

  DrawTools::setStyle();

  TFile *inputFile;

   std::string runName = "";

  if( argc>1 ) {
     std::string runName_str(argv[1]);
     runName = runName_str;
     
     std::string filename_str = "dcap://t3se01.psi.ch:22125//pnfs/psi.ch/cms/trivcat/store/user/micheli/rawData/output_run" + runName + ".root";
     char* hostName = getenv ("HOSTNAME");
     TString hostString(hostName);
     bool isLxplus = hostString.Contains("lxplus");
     if(isLxplus) filename_str = "xroot://t3se01.psi.ch:1094//store/user/micheli/rawData/output_run" + runName + ".root"; 

     inputFile=TFile::Open(filename_str.c_str());
    
    if( inputFile==0 ) {
      std::cout << "ERROR! Din't find file " << filename_str << std::endl;
      std::cout << "Exiting." << std::endl;
      exit(11);
    }
    
    
  }


  TTree* inputTree=(TTree*)inputFile->Get("outputTree");

  WaveformUtil t(inputTree);
  t.Loop();


  return 0;

}
NS_IMETHODIMP
nsSiteSecurityService::IsSecureHost(uint32_t aType, const char* aHost,
                                    uint32_t aFlags, bool* aResult)
{
  // Should be called on the main thread (or via proxy) since the permission
  // manager is used and it's not threadsafe.
  NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_UNEXPECTED);
  // Only HSTS is supported at the moment.
  NS_ENSURE_TRUE(aType == nsISiteSecurityService::HEADER_HSTS,
                 NS_ERROR_NOT_IMPLEMENTED);

  /* An IP address never qualifies as a secure URI. */
  if (HostIsIPAddress(aHost)) {
    *aResult = false;
    return NS_OK;
  }

  nsCOMPtr<nsIURI> uri;
  nsDependentCString hostString(aHost);
  nsresult rv = NS_NewURI(getter_AddRefs(uri),
                          NS_LITERAL_CSTRING("https://") + hostString);
  NS_ENSURE_SUCCESS(rv, rv);
  return IsSecureURI(aType, uri, aFlags, aResult);
}
status_t
BNetworkAddressResolver::SetTo(int family, const char* host,
	const char* service, uint32 flags)
{
	Unset();

	// Check if the address contains a port

	BString hostString(host);

	BString portString;
	if (!strip_port(hostString, portString) && service != NULL)
		portString = service;

	// Resolve address

	addrinfo hint = {0};
	hint.ai_family = family;
	if ((flags & B_NO_ADDRESS_RESOLUTION) != 0)
		hint.ai_flags |= AI_NUMERICHOST;
	else if ((flags & B_UNCONFIGURED_ADDRESS_FAMILIES) == 0)
		hint.ai_flags |= AI_ADDRCONFIG;

	if (host == NULL && portString.Length() == 0) {
		portString = "0";
		hint.ai_flags |= AI_PASSIVE;
	}

	int status = getaddrinfo(host != NULL ? hostString.String() : NULL,
		portString.Length() != 0 ? portString.String() : NULL, &hint, &fInfo);
	if (status == 0)
		return fStatus = B_OK;

	// Map errors
	// TODO: improve error reporting, maybe add specific error codes?

	switch (status) {
		case EAI_ADDRFAMILY:
		case EAI_BADFLAGS:
		case EAI_PROTOCOL:
		case EAI_BADHINTS:
		case EAI_SOCKTYPE:
		case EAI_SERVICE:
		case EAI_NONAME:
		case EAI_FAMILY:
			fStatus = B_BAD_VALUE;
			break;

		case EAI_SYSTEM:
			fStatus = errno;
			break;

		case EAI_OVERFLOW:
		case EAI_MEMORY:
			fStatus = B_NO_MEMORY;
			break;

		case EAI_AGAIN:
			// TODO: better error code to denote temporary failure?
			fStatus = B_TIMED_OUT;
			break;

		default:
			fStatus = B_ERROR;
			break;
	}

	return fStatus;
}
Exemple #8
0
int main( int argc, char* argv[] ) {


  DrawTools::setStyle();
  TGaxis::SetMaxDigits(3);

  std::string tag="V0";
  std::string runName = "";
  if( argc<3 ) {
    std::cout << "USAGE: ./alignTracking [startTag] [run]" << std::endl;
    exit(11);
  } else if(argc>1) {
    std::string tag_str(argv[1]);
    tag = tag_str;
    if(argc>2){
     std::string runName_str(argv[2]);
     runName = runName_str;
    }
  }
    // this is the dir in which the offsets will be saved:
  std::string constDirName = "Alignment";
  system(Form("mkdir -p %s", constDirName.c_str()));


  std::string constFileName = constDirName+"/offsets_"+tag+".txt";
  AlignmentOfficer alignOfficer(constFileName);


  //  TFile* file = TFile::Open("data/run_487.root");
  // TFile* file = TFile::Open("data/run_428.root"); //200 GeV
  //  TFile* file = TFile::Open("data/run_407.root"); //150 GeV
  //  TFile* file = TFile::Open("data/run_418.root"); //100 GeV  
//TFile* file = TFile::Open("data/run_398.root"); //50 GeV
  // TFile* file = TFile::Open("data/run_455.root"); //20 GeV
  // TFile* file = TFile::Open("data/run_508.root"); //20 GeV seems to be better than run 455
  //  TFile* file = TFile::Open("data/run_457.root"); //15 GeV
  //TFile* file = TFile::Open("data/run_431.root"); //10 GeV
  //  TFile* file = TFile::Open("data/run_273.root");
  std::string fileName="dcap://t3se01.psi.ch:22125//pnfs/psi.ch/cms/trivcat/store/user/micheli/rawData/output_run"+runName+".root";
  char* hostName = getenv ("HOSTNAME");
  TString hostString(hostName);
  bool isLxplus = hostString.Contains("lxplus");
  if(isLxplus) fileName= "xroot://t3se01.psi.ch:1094//store/user/micheli/rawData/output_run" + runName + ".root"; 


  TFile* file = TFile::Open(fileName.c_str());
  TTree* tree = (TTree*)file->Get("outputTree");
  std::cout<<"Reading run:"<<runName<<std::endl;

  // Declaration of leaf types
   UInt_t          runNumber;
   UInt_t          spillNumber;
   UInt_t          evtNumber;
   std::vector<float>   *BGOvalues;
   std::vector<float>   *SCINTvalues;
   std::vector<float>   *TDCreco;
   std::vector<float>   *digi_charge_integrated;
   std::vector<float>   *digi_max_amplitude;
   std::vector<float>   *digi_pedestal;
   std::vector<float>   *digi_pedestal_rms;
   std::vector<float>   *digi_time_at_frac30;
   std::vector<float>   *digi_time_at_frac50;
   std::vector<float>   *digi_time_at_max;
   std::vector<bool>    *HODOX1;
   std::vector<bool>    *HODOX2;
   std::vector<bool>    *HODOY1;
   std::vector<bool>    *HODOY2;
   std::vector<float>   *HODOSMALLvalues;
   Float_t         TableX;
   Float_t         TableY;
   Float_t         CeF3HV;
   Float_t         BGOHV;
   Float_t         BeamEnergy;
   Float_t         BeamTilt;
   Int_t           IsPhysics;
   std::vector<int>     *nTdcHits;
   std::vector<float>   *digi_charge_integrated_sub;
   std::vector<float>   *digi_max_amplitude_sub;
   std::vector<float>   *digi_pedestal_sub;
   std::vector<float>   *digi_pedestal_rms_sub;
   std::vector<float>   *digi_charge_integrated_corr2;
   std::vector<float>   *digi_max_amplitude_corr2;

  // List of branches
   TBranch        *b_runNumber;   //!
   TBranch        *b_spillNumber;   //!
   TBranch        *b_evtNumber;   //!
   TBranch        *b_BGOvalues;   //!
   TBranch        *b_SCINTvalues;   //!
   TBranch        *b_HODOSMALLvalues;   //!
   TBranch        *b_TDCreco;   //!
   TBranch        *b_digi_charge_integrated;   //!
   TBranch        *b_digi_max_amplitude;   //!
   TBranch        *b_digi_pedestal;   //!
   TBranch        *b_digi_pedestal_rms;   //!
   TBranch        *b_digi_time_at_frac30;   //!
   TBranch        *b_digi_time_at_frac50;   //!
   TBranch        *b_digi_time_at_max;   //!
   TBranch        *b_HODOX1;   //!
   TBranch        *b_HODOX2;   //!
   TBranch        *b_HODOY1;   //!
   TBranch        *b_HODOY2;   //!
   TBranch        *b_TableX;   //!
   TBranch        *b_TableY;   //!
   TBranch        *b_CeF3HV;   //!
   TBranch        *b_BGOHV;   //!
   TBranch        *b_BeamEnergy;   //!
   TBranch        *b_BeamTilt;   //!
   TBranch        *b_IsPhysics;   //!
   TBranch        *b_nTdcHits;   //!
   TBranch        *b_digi_charge_integrated_sub;   //!
   TBranch        *b_digi_max_amplitude_sub;   //!
   TBranch        *b_digi_pedestal_sub;   //!
   TBranch        *b_digi_pedestal_rms_sub;   //!
   TBranch        *b_digi_charge_integrated_corr2;   //!
   TBranch        *b_digi_max_amplitude_corr2;   //!

  // Set object pointer
   BGOvalues = 0;
   SCINTvalues = 0;
   TDCreco = 0;
   HODOSMALLvalues = 0;
   digi_charge_integrated = 0;
   digi_max_amplitude = 0;
   digi_pedestal = 0;
   digi_pedestal_rms = 0;
   digi_time_at_frac30 = 0;
   digi_time_at_frac50 = 0;
   digi_time_at_max = 0;
   HODOX1 = 0;
   HODOX2 = 0;
   HODOY1 = 0;
   HODOY2 = 0;
   nTdcHits = 0;
   digi_charge_integrated_sub = 0;
   digi_max_amplitude_sub = 0;
   digi_pedestal_sub = 0;
   digi_pedestal_rms_sub = 0;
   digi_charge_integrated_corr2 = 0;
   digi_max_amplitude_corr2 = 0;


   //Set Branch Adresses and branch pointers 
   tree->SetBranchAddress("runNumber", &runNumber, &b_runNumber);
   tree->SetBranchAddress("spillNumber", &spillNumber, &b_spillNumber);
   tree->SetBranchAddress("evtNumber", &evtNumber, &b_evtNumber);
   tree->SetBranchAddress("BGOvalues", &BGOvalues, &b_BGOvalues);
   tree->SetBranchAddress("SCINTvalues", &SCINTvalues, &b_SCINTvalues);
   tree->SetBranchAddress("HODOSMALLvalues", &HODOSMALLvalues, &b_HODOSMALLvalues);
   tree->SetBranchAddress("TDCreco", &TDCreco, &b_TDCreco);
   tree->SetBranchAddress("digi_charge_integrated", &digi_charge_integrated, &b_digi_charge_integrated);
   tree->SetBranchAddress("digi_max_amplitude", &digi_max_amplitude, &b_digi_max_amplitude);
   tree->SetBranchAddress("digi_pedestal", &digi_pedestal, &b_digi_pedestal);
   tree->SetBranchAddress("digi_pedestal_rms", &digi_pedestal_rms, &b_digi_pedestal_rms);
   tree->SetBranchAddress("digi_time_at_frac30", &digi_time_at_frac30, &b_digi_time_at_frac30);
   tree->SetBranchAddress("digi_time_at_frac50", &digi_time_at_frac50, &b_digi_time_at_frac50);
   tree->SetBranchAddress("digi_time_at_max", &digi_time_at_max, &b_digi_time_at_max);
   tree->SetBranchAddress("HODOX1", &HODOX1, &b_HODOX1);
   tree->SetBranchAddress("HODOX2", &HODOX2, &b_HODOX2);
   tree->SetBranchAddress("HODOY1", &HODOY1, &b_HODOY1);
   tree->SetBranchAddress("HODOY2", &HODOY2, &b_HODOY2);
   tree->SetBranchAddress("TableX", &TableX, &b_TableX);
   tree->SetBranchAddress("TableY", &TableY, &b_TableY);
   tree->SetBranchAddress("CeF3HV", &CeF3HV, &b_CeF3HV);
   tree->SetBranchAddress("BGOHV", &BGOHV, &b_BGOHV);
   tree->SetBranchAddress("BeamEnergy", &BeamEnergy, &b_BeamEnergy);
   tree->SetBranchAddress("BeamTilt", &BeamTilt, &b_BeamTilt);
   tree->SetBranchAddress("IsPhysics", &IsPhysics, &b_IsPhysics);
   tree->SetBranchAddress("nTdcHits", &nTdcHits, &b_nTdcHits);
   tree->SetBranchAddress("digi_charge_integrated_sub", &digi_charge_integrated_sub, &b_digi_charge_integrated_sub);
   tree->SetBranchAddress("digi_max_amplitude_sub", &digi_max_amplitude_sub, &b_digi_max_amplitude_sub);
   tree->SetBranchAddress("digi_pedestal_sub", &digi_pedestal_sub, &b_digi_pedestal_sub);
   tree->SetBranchAddress("digi_pedestal_rms_sub", &digi_pedestal_rms_sub, &b_digi_pedestal_rms_sub);
   tree->SetBranchAddress("digi_charge_integrated_corr2", &digi_charge_integrated_corr2, &b_digi_charge_integrated_corr2);
   tree->SetBranchAddress("digi_max_amplitude_corr2", &digi_max_amplitude_corr2, &b_digi_max_amplitude_corr2);


  int nClusters_hodoX1;
  int nFibres_hodoX1[HODOX1_CHANNELS];
  float pos_hodoX1[HODOX1_CHANNELS];
  int nClusters_hodoY1;
  int nFibres_hodoY1[HODOY1_CHANNELS];
  float pos_hodoY1[HODOY1_CHANNELS];

  int nClusters_hodoX2;
  int nFibres_hodoX2[HODOX2_CHANNELS];
  float pos_hodoX2[HODOX2_CHANNELS];
  int nClusters_hodoY2;
  int nFibres_hodoY2[HODOY2_CHANNELS];
  float pos_hodoY2[HODOY2_CHANNELS];

  float wc_x;
  float wc_y;


  //int nBins = 80*2*2*2*2;
  int nBins = 80;
  //   int nBinsWC = 40*5;
  int nBinsWC = 80;
  float xMin = -20.;
  float xMax =  20.;

  TH1F* h1_wc_y_low = new TH1F("wc_y_low", "", nBinsWC, xMin, xMax);
  TH1F* h1_wc_y_hi  = new TH1F("wc_y_hi" , "", nBinsWC, xMin, xMax);
  TH1F* h1_wc_x_low = new TH1F("wc_x_low", "", nBinsWC, xMin, xMax);
  TH1F* h1_wc_x_hi  = new TH1F("wc_x_hi" , "", nBinsWC, xMin, xMax);

  TH1F* h1_hodoY1_low = new TH1F("hodoY1_low", "", nBins, xMin, xMax);
  TH1F* h1_hodoY1_hi  = new TH1F("hodoY1_hi" , "", nBins, xMin, xMax);
  TH1F* h1_hodoX1_low = new TH1F("hodoX1_low", "", nBins, xMin, xMax);
  TH1F* h1_hodoX1_hi  = new TH1F("hodoX1_hi" , "", nBins, xMin, xMax);

  TH1F* h1_hodoY2_low = new TH1F("hodoY2_low", "", nBins, xMin, xMax);
  TH1F* h1_hodoY2_hi  = new TH1F("hodoY2_hi" , "", nBins, xMin, xMax);
  TH1F* h1_hodoX2_low = new TH1F("hodoX2_low", "", nBins, xMin, xMax);
  TH1F* h1_hodoX2_hi  = new TH1F("hodoX2_hi" , "", nBins, xMin, xMax);


  int nentries = tree->GetEntries();
  if(nentries>10000)  nentries=10000;
  for( unsigned iEntry=0; iEntry<nentries; ++iEntry ) {

    tree->GetEntry(iEntry);

     if( iEntry %  10000 == 0 ) std::cout << "Entry: " << iEntry << " / " << nentries << std::endl;

     std::vector<bool> hodoX1_values(HODOX1_CHANNELS, -1.);
     std::vector<bool> hodoY1_values(HODOY1_CHANNELS, -1.);
     assignValuesBool( hodoX1_values, *HODOX1, 0. );
     assignValuesBool( hodoY1_values, *HODOY1, 0. );


     std::vector<bool> hodoX2_values(HODOX2_CHANNELS, -1.);
     std::vector<bool> hodoY2_values(HODOY2_CHANNELS, -1.);
     assignValuesBool( hodoX2_values, *HODOX2, 0 );
     assignValuesBool( hodoY2_values, *HODOY2, 0 );


     std::vector<float> hodoSmallX_values(HODOSMALLX_CHANNELS, -1.);
     std::vector<float> hodoSmallY_values(HODOSMALLY_CHANNELS, -1.);
     assignValues( hodoSmallY_values, *HODOSMALLvalues, 0 );
     assignValues( hodoSmallX_values, *HODOSMALLvalues, 4 );

     // hodo cluster reconstruction
     int clusterMaxFibres = 4;
     doHodoReconstructionBool( hodoX1_values    , nClusters_hodoX1    , nFibres_hodoX1    , pos_hodoX1    , 0.5, clusterMaxFibres, 0.  );
     doHodoReconstructionBool( hodoY1_values    , nClusters_hodoY1    , nFibres_hodoY1    , pos_hodoY1    , 0.5, clusterMaxFibres, 0.  );
     doHodoReconstructionBool( hodoX2_values    , nClusters_hodoX2    , nFibres_hodoX2    , pos_hodoX2    , 0.5, clusterMaxFibres, 0.  );
     doHodoReconstructionBool( hodoY2_values    , nClusters_hodoY2    , nFibres_hodoY2    , pos_hodoY2    , 0.5, clusterMaxFibres, 0.  );

     alignOfficer.fix("hodoX1", nClusters_hodoX1, pos_hodoX1);
     alignOfficer.fix("hodoY1", nClusters_hodoY1, pos_hodoY1);
     alignOfficer.fix("hodoX2", nClusters_hodoX2, pos_hodoX2);
     alignOfficer.fix("hodoY2", nClusters_hodoY2, pos_hodoY2);

     wc_x = TDCreco->at(0);
     wc_y = TDCreco->at(1);
     if( runNumber>=170 ) wc_y = -wc_y; // temporary fix

     wc_x += alignOfficer.getOffset("wc_x");
     wc_y += alignOfficer.getOffset("wc_y");

//     float hodoSmallY_low = digi_max_amplitude->at(6);
//     float hodoSmallY_hi  = digi_max_amplitude->at(7);
////     //float hodoSmallX_low = digi_max_amplitude->at(5);
////     //float hodoSmallX_hi  = digi_max_amplitude->at(4);
//     float hodoSmallX_low = digi_max_amplitude->at(4);
//     float hodoSmallX_hi  = digi_max_amplitude->at(5);

     bool isOctober2015Run=  (runNumber > 3900. && runNumber<4600);

     float hodoSmallY_low = HODOSMALLvalues->at(1);
     float hodoSmallY_hi  = HODOSMALLvalues->at(2);
     float hodoSmallX_low = HODOSMALLvalues->at(5);
     float hodoSmallX_hi  = HODOSMALLvalues->at(6);

     if (isOctober2015Run){
       hodoSmallY_low = HODOSMALLvalues->at(0);
       hodoSmallY_hi  = HODOSMALLvalues->at(1);
       hodoSmallX_low = HODOSMALLvalues->at(2);
       hodoSmallX_hi  = HODOSMALLvalues->at(3);
     }

     //     std::cout<< hodoSmallY_low<<" "<<hodoSmallY_hi<<" "<<hodoSmallX_low<<" "<<hodoSmallX_hi<<std::endl;
     std::vector<float> pedMeanX,pedMeanY, pedSigmaX, pedSigmaY;
     if(!isOctober2015Run){
       pedMeanY.push_back(141.30);
       pedMeanY.push_back(152.90);
       pedMeanX.push_back(139.89);
       pedMeanX.push_back(151.73);
       
       pedSigmaY.push_back(1.25);
       pedSigmaY.push_back(1.60);
       pedSigmaX.push_back(1.32);
       pedSigmaX.push_back(1.31);
     }else{//ped value for october 2015 run
       pedMeanY.push_back(212.5);
       pedMeanY.push_back(202.0);
       pedMeanX.push_back(218.6);//this channels are not working in these runs....
       pedMeanX.push_back(208.0);
       
       pedSigmaY.push_back(1.51);
       pedSigmaY.push_back(1.67);
       pedSigmaX.push_back(2.04);
       pedSigmaX.push_back(1.83);

     }

  // y low
     if( hodoSmallY_low>pedMeanY[0]+5*pedSigmaY[0] ) {

     int posOf2FibClustY1Low = 0;
    int   posOf2FibClustY2Low=0;

     int nrOf2FibreClustersY1Low = 0;
       for( int i=0; i<nClusters_hodoY1; ++i ) {
         if( nFibres_hodoY1[i]==2  )  {  
	   ++nrOf2FibreClustersY1Low;
	   posOf2FibClustY1Low= i ;} 
       }
 
	  //And for Y2 LOW:
     int nrOf2FibreClustersY2Low = 0;
       for( int i=0; i<nClusters_hodoY2; ++i ) {
         if( nFibres_hodoY2[i]==2  )  {  
	   ++nrOf2FibreClustersY2Low;
	   posOf2FibClustY2Low=i;  } 
       }

       if((nrOf2FibreClustersY2Low==1||nClusters_hodoY2==1)&& (nrOf2FibreClustersY1Low==1 || nClusters_hodoY1==1) && abs(wc_y) <200 && nTdcHits->at(2)>0 && nTdcHits->at(3)>0 &&  nTdcHits->at(2)<3 && nTdcHits->at(3)<3 && ( nTdcHits->at(2) + nTdcHits->at(3))<4){
	 h1_wc_y_low->Fill( wc_y );
	 h1_hodoY1_low->Fill( pos_hodoY1[posOf2FibClustY1Low] );
	 h1_hodoY2_low->Fill( pos_hodoY2[posOf2FibClustY2Low] );     
     }
     }

   // y hi
     if( hodoSmallY_hi>pedMeanY[1]+5*pedSigmaY[1] ) {

     int posOf2FibClustY1Hi = 0;
    int   posOf2FibClustY2Hi=0;

     int nrOf2FibreClustersY1Hi = 0;
       for( int i=0; i<nClusters_hodoY1; ++i ) {
         if( nFibres_hodoY1[i]==2  )  {  
	   ++nrOf2FibreClustersY1Hi;
	   posOf2FibClustY1Hi= i ;} 
       }
 
	  //And for Y2 HI:
     int nrOf2FibreClustersY2Hi = 0;
       for( int i=0; i<nClusters_hodoY2; ++i ) {
         if( nFibres_hodoY2[i]==2  )  {  
	   ++nrOf2FibreClustersY2Hi;
	   posOf2FibClustY2Hi=i;  } 
       }

       if((nrOf2FibreClustersY2Hi==1||nClusters_hodoY2==1)&& (nrOf2FibreClustersY1Hi==1 || nClusters_hodoY1==1) && abs(wc_y) <200 && nTdcHits->at(2)>0 && nTdcHits->at(3)>0 &&  nTdcHits->at(2)<3 && nTdcHits->at(3)<3 && ( nTdcHits->at(2) + nTdcHits->at(3))<4){
	 h1_wc_y_hi->Fill( wc_y );
	 h1_hodoY1_hi->Fill( pos_hodoY1[ posOf2FibClustY1Hi] );
	 h1_hodoY2_hi->Fill( pos_hodoY2[posOf2FibClustY2Hi] );     
     }
     }


  // x low
     if( hodoSmallX_low>pedMeanX[0]+5*pedSigmaX[0] ) {

     int posOf2FibClustX1Low = 0;
    int   posOf2FibClustX2Low=0;

     int nrOf2FibreClustersX1Low = 0;
       for( int i=0; i<nClusters_hodoX1; ++i ) {
         if( nFibres_hodoX1[i]==2  )  {  
	   ++nrOf2FibreClustersX1Low;
	   posOf2FibClustX1Low= i ;} 
       }
 
	  //And for X2 LOW:
     int nrOf2FibreClustersX2Low = 0;
       for( int i=0; i<nClusters_hodoX2; ++i ) {
         if( nFibres_hodoX2[i]==2  )  {  
	   ++nrOf2FibreClustersX2Low;
	   posOf2FibClustX2Low=i;  } 
       }

       if((nrOf2FibreClustersX2Low==1||nClusters_hodoX2==1)&& (nrOf2FibreClustersX1Low==1 || nClusters_hodoX1==1) &&  abs(wc_x)<200 && nTdcHits->at(0)>0 && nTdcHits->at(1)>0 && nTdcHits->at(0)<3 && nTdcHits->at(1)<3 &&  ( nTdcHits->at(0) + nTdcHits->at(1) )<4){
	 h1_wc_x_low->Fill( wc_x );
	 h1_hodoX1_low->Fill( pos_hodoX1[ posOf2FibClustX1Low] );
	 h1_hodoX2_low->Fill( pos_hodoX2[posOf2FibClustX2Low] );     
     }
     }

   // x hi
     if( hodoSmallX_hi>pedMeanX[1]+5*pedSigmaX[1] ) {

     int posOf2FibClustX1Hi = 0;
    int   posOf2FibClustX2Hi=0;

     int nrOf2FibreClustersX1Hi = 0;
       for( int i=0; i<nClusters_hodoX1; ++i ) {
         if( nFibres_hodoX1[i]==2  )  {  
	   ++nrOf2FibreClustersX1Hi;
	   posOf2FibClustX1Hi= i ;} 
       }
 
	  //And for X2 HI:
     int nrOf2FibreClustersX2Hi = 0;
       for( int i=0; i<nClusters_hodoX2; ++i ) {
         if( nFibres_hodoX2[i]==2  )  {  
	   ++nrOf2FibreClustersX2Hi;
	   posOf2FibClustX2Hi=i;  } 
       }

       if((nrOf2FibreClustersX2Hi==1||nClusters_hodoX2==1)&& (nrOf2FibreClustersX1Hi==1 || nClusters_hodoX1==1) && abs(wc_x) <200 && nTdcHits->at(0)>0 && nTdcHits->at(1)>0 &&  nTdcHits->at(0)<3 && nTdcHits->at(1)<3 && ( nTdcHits->at(0) + nTdcHits->at(1) )<4){
	 h1_wc_x_hi->Fill( wc_x );
	 h1_hodoX1_hi->Fill( pos_hodoX1[ posOf2FibClustX1Hi] );
	 h1_hodoX2_hi->Fill( pos_hodoX2[posOf2FibClustX2Hi] );     
     }
     }




  } // for entries


  std::string outputdir = "AlignmentPlots_"+tag;
  system( Form("mkdir -p %s", outputdir.c_str()));

  float offset_wc_y_low = fitAndDraw( outputdir, h1_wc_y_low );
  float offset_wc_y_hi  = fitAndDraw( outputdir, h1_wc_y_hi );
  float offset_wc_x_low = fitAndDraw( outputdir, h1_wc_x_low );
  float offset_wc_x_hi  = fitAndDraw( outputdir, h1_wc_x_hi );
  float offset_hodoY1_low = fitAndDraw( outputdir, h1_hodoY1_low );
  float offset_hodoY1_hi  = fitAndDraw( outputdir, h1_hodoY1_hi );
  float offset_hodoX1_low = fitAndDraw( outputdir, h1_hodoX1_low );
  float offset_hodoX1_hi  = fitAndDraw( outputdir, h1_hodoX1_hi );
  float offset_hodoY2_low = fitAndDraw( outputdir, h1_hodoY2_low );
  float offset_hodoY2_hi  = fitAndDraw( outputdir, h1_hodoY2_hi );
  float offset_hodoX2_low = fitAndDraw( outputdir, h1_hodoX2_low );
  float offset_hodoX2_hi  = fitAndDraw( outputdir, h1_hodoX2_hi );

  float offset_wc_y   = 0.5*(offset_wc_y_low  +offset_wc_y_hi);
  float offset_wc_x   = 0.5*(offset_wc_x_low  +offset_wc_x_hi);
  float offset_hodoY1 = 0.5*(offset_hodoY1_low+offset_hodoY1_hi);
  float offset_hodoX1 = 0.5*(offset_hodoX1_low+offset_hodoX1_hi);
  float offset_hodoY2 = 0.5*(offset_hodoY2_low+offset_hodoY2_hi);
  float offset_hodoX2 = 0.5*(offset_hodoX2_low+offset_hodoX2_hi);

  std::cout << "offset_wc_y: "   <<  offset_wc_y << std::endl;
  std::cout << "offset_wc_x: "   <<  offset_wc_x << std::endl;
  std::cout << "offset_hodoY1: " <<  offset_hodoY1 << std::endl;
  std::cout << "offset_hodoX1: " <<  offset_hodoX1 << std::endl;
  std::cout << "offset_hodoY2: " <<  offset_hodoY2 << std::endl;
  std::cout << "offset_hodoX2: " <<  offset_hodoX2 << std::endl;

  
  std::string ofsName = constDirName + "/offsets_new.txt";
  ofstream ofs(ofsName.c_str());
  ofs << "wc_y "   << -offset_wc_y << std::endl;
  ofs << "wc_x "   << -offset_wc_x << std::endl;
  ofs << "hodoY1 " << -offset_hodoY1 << std::endl;
  ofs << "hodoX1 " << -offset_hodoX1 << std::endl;
  ofs << "hodoY2 " << -offset_hodoY2 << std::endl;
  ofs << "hodoX2 " << -offset_hodoX2 << std::endl;
  ofs.close();

  std::cout << "-> Saved offsets in: " << ofsName << std::endl;

  return 0;

}