Ejemplo n.º 1
0
/*
=================
CG_AdjustFontSize

Returns a modified textScale value, the bigger the inserted
value, the smaller is the output

@author suburb
=================
*/
float CG_AdjustFontSize(float textScale, int valueToPrint, int border) {
	if (valueToPrint >= border) {
		float textScaleFactor = 0.02f * GetDigits(valueToPrint) - 0.08f;
		textScale -= textScaleFactor;
	}
	return textScale;
}
Ejemplo n.º 2
0
TRISTATE CTextParser::GetInteger(unsigned long long int* pulli, int* piSign, int* piNumDigits, BOOL bSkipWhiteSpace)
{
	TRISTATE	tResult;

	PushPosition();

	if (bSkipWhiteSpace)
	{
		SkipWhiteSpace();
	}

	//Make sure we're not off the end of the file.
	if (mbOutsideText)
	{
		PopPosition();
		SetErrorEndOfFile();
		return TRIERROR;
	}

	tResult  = GetDigits(pulli, piSign, piNumDigits, bSkipWhiteSpace);
	if (tResult == TRITRUE)
	{
		//Make sure there are no decimals.
		if (mszParserPos[0] == '.')
		{
			PopPosition();
			return TRIFALSE;
		}

		PassPosition();
		return TRITRUE;
	}
	PopPosition();
	return tResult;
}
Ejemplo n.º 3
0
			EXPORT_OUT bool
				Object::ParseRepetition(char ** ParseAt, size_t & MinRep, size_t & MaxRep)
			{
				bool						Results = false;

				if (isdigit(**ParseAt) || **ParseAt == '*') {
					Results = true;

					if (isdigit(**ParseAt)) {
						char			*	TheDigits = GetDigits(ParseAt);

						/* default to '<a>element' */
						MinRep = atoi(TheDigits);
						MaxRep = MinRep;

						// GetDigits has skipped any digits.
						// 
						if (**ParseAt == '*') {
							MoveForward(ParseAt, 1);
							if (isdigit(**ParseAt)) {
								/* is '<a>*<b>element' */
								TheDigits = GetDigits(ParseAt);
								MaxRep = atoi(TheDigits);
							} else {
								/* is '<a>*element */
								MaxRep = 0;
							}
						}
					} else {
						/* is '*element' */
						MinRep = 0;
						MaxRep = 0;
						MoveForward(ParseAt, 1);
					}				
				}

				return(Results);
			}
void Getyc(int yyyy, int& y, int& c)
{
	auto digits = GetDigits(yyyy);
	
	y = 0; // last 2-digits
	c = 0; // first 2-digits

	while (digits.size() < 4)
	{
		digits.push_back(0);
	}

	c = digits[3] * 10 + digits[2];
	y = digits[1] * 10 + digits[0];
}
Ejemplo n.º 5
0
int main()
{
	long long N = 1000000;
	long long result = 0;
	for (long long i = 2; i < N; ++i)
	{
		std::vector<unsigned> digits = GetDigits(i);
		long long sum = 0;
		for (auto it = digits.begin(); it != digits.end(); ++it)
		{
			sum += pow(*it, 5);
		}
		if (sum == i)
		{
			std::cout << sum << std::endl;
			result += i;
		}
	}

	std::cout << "result: " << result << std::endl;
	return 0;
}
Ejemplo n.º 6
0
int main()
{
	int i;
	int n;
	int a[200];
	int sum[200];
	char buffer[1000];

	gets(buffer);
	sscanf(buffer, "%d", &n);
	for(i = 0; i < n; i++)
	{
		gets(buffer);
		memset(a, 0, 200 * sizeof(int));
		memset(sum, 0, 200 * sizeof(int));
		while(1)
		{
			gets(buffer);
			if(strcmp(buffer, "0") == 0)
			{
				break;
			}
			else
			{
				GetDigits(a, buffer, 150);
				AddDigits(sum, a, 150);
			}
		}
		PrintDigits(sum, 150);
		puts("");
		if(i != n - 1)
		{
			puts("");
		}
	}

	return 0;
}
Ejemplo n.º 7
0
void ME_PreviewActiveTake (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd)
{
	if (MediaItem_Take* take = MIDIEditor_GetTake(MIDIEditor_GetActive()))
	{
		MediaItem* item = GetMediaItemTake_Item(take);

		vector<int> options = GetDigits((int)ct->user);
		int toggle   = options[0];
		int type     = options[1];
		int selNotes = options[2];
		int pause    = options[3];

		MediaTrack* track     = GetMediaItem_Track(item);
		double      volume    = GetMediaItemInfo_Value(item, "D_VOL");
		double      start     = 0;
		double      measure   = (type  == 3) ? 1 : 0;
		bool        pausePlay = (pause == 2) ? true : false;

		if (type == 2)
		{
			double mousePosition = ME_PositionAtMouseCursor(true, true);
			if (mousePosition != -1)
				start = mousePosition - GetMediaItemInfo_Value(item, "D_POSITION");
			else
				return;
		}

		vector<int> muteState;
		if (selNotes == 2 && !AreAllNotesUnselected(take))
			muteState = MuteSelectedNotes(take);

		MidiTakePreview(toggle, take, track, volume, start, measure, pausePlay);

		if (muteState.size() > 0)
			SetMutedNotes(take, muteState);
	}
}
Ejemplo n.º 8
0
TRISTATE CTextParser::GetFloat(double* pf)
{
	unsigned long long int	ulliLeft;
	unsigned long long int	ulliRight;
	TRISTATE				tReturn;
	int						iNumDecimals;
	double					fLeft;
	double					fRight;
	double					fTemp;
	BOOL					bLeft;
	int						iSign;

	PushPosition();
	SkipWhiteSpace();

	*pf = 0.0f;
	if (!mbOutsideText)
	{
		//Try and get the mantissa.
		tReturn = GetDigits(&ulliLeft, &iSign, NULL);
		bLeft = TRUE;

		//Just return on errors an non-numbers.
		if (tReturn == TRIFALSE)
		{
			//There may still be a decimal point...
			ulliLeft = 0;
			bLeft = FALSE;
		}
		else if (tReturn == TRIERROR)
		{
			PopPosition();
			SetErrorSyntaxError();
			return TRIERROR;
		}

		fLeft = ((double)ulliLeft) * iSign;
		tReturn = GetExactCharacter('.', FALSE);
		if (tReturn == TRITRUE)
		{
			tReturn = GetDigits(&ulliRight, &iSign, &iNumDecimals);
			if (tReturn == TRITRUE)
			{
				if (iSign <= 0)
				{
					//Cant have: 34.-342 but -34.342 would be fine.
					PopPosition();
					SetErrorSyntaxError();
					return TRIERROR;
				}

				fRight = (double)ulliRight;
				fTemp = pow(10.0L, -iNumDecimals);
				fRight *= fTemp;

				if (fLeft >= 0)
				{
					*pf = fLeft + fRight;
				}
				else
				{
					*pf = fLeft - fRight;
				}
				PassPosition();
				return TRITRUE;
			}
			else
			{
				//A decimal point must be followed by a number.
				PopPosition();
				SetErrorSyntaxError();
				return TRIERROR;
			}
		}
		else
		{
			//No decimal point...
			if (!bLeft)
			{
				//No digits and no point...
				PopPosition();
				return TRIFALSE;
			}
			else
			{
				*pf = fLeft;
				PassPosition();
				return TRITRUE;
			}
		}
	}
	else
	{
		PopPosition();
		SetErrorEndOfFile();
		return TRIERROR;
	}
}
Ejemplo n.º 9
0
static void GenArcName(wchar *ArcName,const wchar *GenerateMask,uint ArcNumber,bool &ArcNumPresent)
{
  bool Prefix=false;
  if (*GenerateMask=='+')
  {
    Prefix=true;    // Add the time string before the archive name.
    GenerateMask++; // Skip '+' in the beginning of time mask.
  }

  wchar Mask[MAX_GENERATE_MASK];
  wcsncpyz(Mask,*GenerateMask!=0 ? GenerateMask:L"yyyymmddhhmmss",ASIZE(Mask));

  bool QuoteMode=false,Hours=false;
  for (uint I=0;Mask[I]!=0;I++)
  {
    if (Mask[I]=='{' || Mask[I]=='}')
    {
      QuoteMode=(Mask[I]=='{');
      continue;
    }
    if (QuoteMode)
      continue;
    int CurChar=toupperw(Mask[I]);
    if (CurChar=='H')
      Hours=true;

    if (Hours && CurChar=='M')
    {
      // Replace minutes with 'I'. We use 'M' both for months and minutes,
      // so we treat as minutes only those 'M' which are found after hours.
      Mask[I]='I';
    }
    if (CurChar=='N')
    {
      uint Digits=GetDigits(ArcNumber);
      uint NCount=0;
      while (toupperw(Mask[I+NCount])=='N')
        NCount++;

      // Here we ensure that we have enough 'N' characters to fit all digits
      // of archive number. We'll replace them by actual number later
      // in this function.
      if (NCount<Digits)
      {
        wmemmove(Mask+I+Digits,Mask+I+NCount,wcslen(Mask+I+NCount)+1);
        wmemset(Mask+I,'N',Digits);
      }
      I+=Max(Digits,NCount)-1;
      ArcNumPresent=true;
      continue;
    }
  }

  RarTime CurTime;
  CurTime.SetCurrentTime();
  RarLocalTime rlt;
  CurTime.GetLocal(&rlt);

  wchar Ext[NM],*Dot=GetExt(ArcName);
  *Ext=0;
  if (Dot==NULL)
    wcscpy(Ext,*PointToName(ArcName)==0 ? L".rar":L"");
  else
  {
    wcsncpyz(Ext,Dot,ASIZE(Ext));
    *Dot=0;
  }

  int WeekDay=rlt.wDay==0 ? 6:rlt.wDay-1;
  int StartWeekDay=rlt.yDay-WeekDay;
  if (StartWeekDay<0)
    if (StartWeekDay<=-4)
      StartWeekDay+=IsLeapYear(rlt.Year-1) ? 366:365;
    else
      StartWeekDay=0;
  int CurWeek=StartWeekDay/7+1;
  if (StartWeekDay%7>=4)
    CurWeek++;

  char Field[10][6];

  sprintf(Field[0],"%04d",rlt.Year);
  sprintf(Field[1],"%02d",rlt.Month);
  sprintf(Field[2],"%02d",rlt.Day);
  sprintf(Field[3],"%02d",rlt.Hour);
  sprintf(Field[4],"%02d",rlt.Minute);
  sprintf(Field[5],"%02d",rlt.Second);
  sprintf(Field[6],"%02d",CurWeek);
  sprintf(Field[7],"%d",WeekDay+1);
  sprintf(Field[8],"%03d",rlt.yDay+1);
  sprintf(Field[9],"%05d",ArcNumber);

  const wchar *MaskChars=L"YMDHISWAEN";

  int CField[sizeof(Field)/sizeof(Field[0])];
  memset(CField,0,sizeof(CField));
  QuoteMode=false;
  for (int I=0;Mask[I]!=0;I++)
  {
    if (Mask[I]=='{' || Mask[I]=='}')
    {
      QuoteMode=(Mask[I]=='{');
      continue;
    }
    if (QuoteMode)
      continue;
    const wchar *ChPtr=wcschr(MaskChars,toupperw(Mask[I]));
    if (ChPtr!=NULL)
      CField[ChPtr-MaskChars]++;
   }

  wchar DateText[MAX_GENERATE_MASK];
  *DateText=0;
  QuoteMode=false;
  for (size_t I=0,J=0;Mask[I]!=0 && J<ASIZE(DateText)-1;I++)
  {
    if (Mask[I]=='{' || Mask[I]=='}')
    {
      QuoteMode=(Mask[I]=='{');
      continue;
    }
    const wchar *ChPtr=wcschr(MaskChars,toupperw(Mask[I]));
    if (ChPtr==NULL || QuoteMode)
    {
      DateText[J]=Mask[I];
#ifdef _WIN_ALL
      // We do not allow ':' in Windows because of NTFS streams.
      // Users had problems after specifying hh:mm mask.
      if (DateText[J]==':')
        DateText[J]='_';
#endif
    }
    else
    {
      size_t FieldPos=ChPtr-MaskChars;
      int CharPos=(int)strlen(Field[FieldPos])-CField[FieldPos]--;
      if (FieldPos==1 && toupperw(Mask[I+1])=='M' && toupperw(Mask[I+2])=='M')
      {
        wcsncpyz(DateText+J,GetMonthName(rlt.Month-1),ASIZE(DateText)-J);
        J=wcslen(DateText);
        I+=2;
        continue;
      }
      if (CharPos<0)
        DateText[J]=Mask[I];
      else
        DateText[J]=Field[FieldPos][CharPos];
    }
    DateText[++J]=0;
  }

  if (Prefix)
  {
    wchar NewName[NM];
    GetFilePath(ArcName,NewName,ASIZE(NewName));
    AddEndSlash(NewName,ASIZE(NewName));
    wcsncatz(NewName,DateText,ASIZE(NewName));
    wcsncatz(NewName,PointToName(ArcName),ASIZE(NewName));
    wcscpy(ArcName,NewName);
  }
  else
    wcscat(ArcName,DateText);
  wcscat(ArcName,Ext);
}
Ejemplo n.º 10
0
void ME_PreviewActiveTake (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd)
{
	HWND midiEditor = MIDIEditor_GetActive();
	if (MediaItem_Take* take = MIDIEditor_GetTake(midiEditor))
	{
		MediaItem* item = GetMediaItemTake_Item(take);

		vector<int> options = GetDigits((int)ct->user);
		int toggle   = options[0];
		int type     = options[1];
		int selNotes = options[2];
		int pause    = options[3];

		MediaTrack* track     = GetMediaItem_Track(item);
		double      volume    = GetMediaItemInfo_Value(item, "D_VOL");
		double      start     = 0;
		double      measure   = (type  == 3) ? 1 : 0;
		bool        pausePlay = (pause == 2) ? true : false;

		if (type == 2)
		{
			double mousePosition = ME_PositionAtMouseCursor(true, true);
			if (mousePosition != -1)
			{
				if (GetToggleCommandState2(SectionFromUniqueID(SECTION_MIDI_EDITOR), 40470) > 0) // Timebase: Beats(source)
					start = mousePosition - MIDI_GetProjTimeFromPPQPos(take, 0);
				else
					start = mousePosition - GetMediaItemInfo_Value(item, "D_POSITION");
			}
			else
				return;
		}

		vector<int> muteState;
		if (selNotes == 2)
		{
			if (!AreAllNotesUnselected(take))
			{
				muteState = MuteUnselectedNotes(take);
				if (type != 2)
				{
					BR_MidiEditor editor(midiEditor);
					double time;
					MIDI_GetNote(take, FindFirstSelectedNote(take, &editor), NULL, NULL, &time, NULL, NULL, NULL, NULL);
					start = MIDI_GetProjTimeFromPPQPos(take, time) - GetMediaItemInfo_Value(item, "D_POSITION");
					if (start < 0) start = 0;
				}
			}
			else if (type != 2)
			{
				BR_MidiEditor editor(midiEditor);
				int id = FindFirstNote(take, &editor);
				if (id != -1)
				{
					double time;
					MIDI_GetNote(take, id, NULL, NULL, &time, NULL, NULL, NULL, NULL);
					start = MIDI_GetProjTimeFromPPQPos(take, time) - GetMediaItemInfo_Value(item, "D_POSITION");
					if (start < 0) start = 0;
				}
			}
		}
		MidiTakePreview(toggle, take, track, volume, start, measure, pausePlay);

		if (muteState.size() > 0)
			SetMutedNotes(take, muteState);
	}
}
Ejemplo n.º 11
0
Int_t IlcTARGETGeoPlot (Int_t evesel=0, char *opt="All+ClustersV2", char *filename="gilc.root", Int_t isfastpoints = 0) {
  /*******************************************************************
   *  This macro displays geometrical information related to the
   *  hits, digits and rec points (or V2 clusters) in TARGET.
   *  There are histograms that are not displayed (i.e. energy
   *  deposition) but that are saved onto a file (see below)
   *
   *  INPUT arguments:
   *
   *  Int_t evesel:  the selected event number. It's =0 by default
   *
   *  Options: Any combination of:
   *    1) subdetector name:  "SPD", "SDD", "SSD", "All" (default)
   *    2) Printouts:        "Verbose" Almost everything is printed out: 
   *                          it is wise to redirect the output onto a file
   *                    e.g.: .x IlcTARGETGeoPlot.C("All+Verbose") > out.log 
   *    3) Rec Points option: "Rec"   ---> Uses Rec. Points (default)
   * 
   *    4) ClustersV2 option: "ClustersV2" ---->Uses ClustersV2
   *                           otherwise ---->uses hits and digits only
   *    Examples:
   *       .x IlcTARGETGeoPlot();  (All subdetectors; no-verbose; no-recpoints)
   *       .x IlcTARGETGeoPlot("SPD+SSD+Verbose+Rec"); 
   *   
   *    filename:   It's "gilc.root" by default. 
   *    isfastpoints: integer. It is set to 0 by defaults. This means that
   *                slow reconstruction is assumed. If fast recpoint are in
   *                in use, isfastpoints must be set =1.
   *
   *  OUTPUT: It produces a root file with a list of histograms
   *    
   *  WARNING: spatial information for SSD/DIGTARGET is obtained by pairing
   *          digits on p and n side originating from the same track, when
   *          possible. This (mis)use of DIGTARGET is tolerated for debugging 
   *          purposes only !!!!  The pairing in real life should be done
   *          starting from info really available... 
   * 
   *  COMPILATION: this macro can be compiled. 
   *      1)       You need to set your include path with
   * gSystem->SetIncludePath("-I- -I$ILC_ROOT/include -I$ILC_ROOT/TARGET -g");
   *      3)       If you are using root instead of ilcroot you need to
   *               execute the macro loadlibs.C in advance
   *      4)       To compile this macro from root (or ilcroot):
   *                 ---  .L IlcTARGETGeoPlot.C++
   *                 ---  IlcTARGETGeoPlot();
   *     
   *  M.Masera  14/05/2001 18:30
   *  Last rev. 31/05/2004 14:00 (Clusters V2 added)  E.C.          
   ********************************************************************/

  //Options
  TString choice(opt);
  Bool_t All = choice.Contains("All");
  Bool_t verbose=choice.Contains("Verbose");
  Bool_t userec=choice.Contains("Rec");
  Bool_t useclustersv2=choice.Contains("ClustersV2");
  Int_t retcode=1; //return code
 
  if (gClassTable->GetID("IlcRun") < 0) {
    gInterpreter->ExecuteMacro("loadlibs.C");
  }
  else { 
    if(gIlc){
      delete gIlc->GetRunLoader();
      delete gIlc;
      gIlc=0;
    }
  }
 
  IlcRunLoader* rl = IlcRunLoader::Open(filename);
  if (rl == 0x0){
    cerr<<"IlcTARGETGeoPlot.C : Can not open session RL=NULL"<< endl;
    return -1;
  }
  Int_t retval = rl->LoadgIlc();
  if (retval){
    cerr<<"IlcTARGETGeoPlot.C : LoadgIlc returned error"<<endl;
    return -1;
  }
  gIlc=rl->GetIlcRun();

  retval = rl->LoadHeader();
  if (retval){
    cerr<<"IlcTARGETGeoPlot.C : LoadHeader returned error"<<endl;
    return -1;
  }

  IlcTARGETLoader* TARGETloader =  (IlcTARGETLoader*) rl->GetLoader("TARGETLoader");

  if(!TARGETloader){
    cerr<<"IlcTARGETGeoPlot.C :  TARGET loader not found"<<endl;
    return -1;
  }

  TARGETloader->LoadHits("read");
  TARGETloader->LoadDigits("read");
  if(isfastpoints==1)TARGETloader->SetRecPointsFileName("TARGET.FastRecPoints.root");
  TARGETloader->LoadRecPoints("read");
  rl->GetEvent(evesel);
  Int_t nparticles = rl->GetHeader()->GetNtrack();
  IlcTARGET *TARGET  = (IlcTARGET*)gIlc->GetModule("TARGET");
  TARGET->SetTreeAddress();
  if(verbose) {
    cout<<" "<<endl<<" "<<endl;
    cout<<"******* Event processing started   *******"<<endl;
    cout<<"In the following, hits with 'StatusEntering' flag active"<<endl;
    cout<<"will not be processed"<<endl; 
    cout << "Number of particles=  " << nparticles <<endl;
  }

  // HTARGET
  TTree *TH = TARGETloader->TreeH();
  Stat_t ntracks = TH->GetEntries();
  if(verbose)cout<<"Number of primary tracks= "<<ntracks<<endl;

  // TARGET
  Int_t nmodules;
  TARGET->InitModules(-1,nmodules);
  cout<<"Number of TARGET modules= "<<nmodules<<endl;
  cout<<"Filling modules... It takes a while, now. Please be patient"<<endl;
  TARGET->FillModules(0,0,nmodules," "," ");
  cout<<"TARGET modules .... DONE!"<<endl;
  
  IlcTARGETDetTypeRec* detTypeRec = new IlcTARGETDetTypeRec(TARGETloader);
  detTypeRec->SetDefaults();
  // DIGTARGET
  TTree *TD = TARGETloader->TreeD();

  //RECPOINTS (V2 clusters)
  TTree *TR = TARGETloader->TreeR();
  TClonesArray *TARGETrec  = detTypeRec->RecPoints();
  TBranch *branch = 0;
  if(userec && TR && TARGETrec){
    if(isfastpoints==1){
      branch = TARGETloader->TreeR()->GetBranch("TARGETRecPointsF");
      cout<<"using fast points\n";
    }
    else {
      branch = TARGETloader->TreeR()->GetBranch("TARGETRecPoints");
    }
    if(branch)branch->SetAddress(&TARGETrec);
  }

  if(userec && (!TR || !TARGETrec || !branch)){
    userec = kFALSE;
    cout<<"\n ======================================================= \n";
    cout<<"WARNING: there are no RECPOINTS on this file ! \n";
    cout<<"======================================================= \n \n";
  }
  if(useclustersv2 && TR && TARGETrec){
    branch = TARGETloader->TreeR()->GetBranch("TARGETRecPoints");
    if(branch)branch->SetAddress(&TARGETrec);
  }

  if(useclustersv2 && (!TR || !TARGETrec || !branch)){
    useclustersv2 = kFALSE;
    cout<<"\n ======================================================= \n";
    cout<<"WARNING: there are no CLUSTERSV2 on this file ! \n";
    cout<<"======================================================= \n \n";
  }


  //local variables
  Int_t mod;   //module number
  Int_t nbytes = 0; 
  Double_t pos[3];  // Global position of the current module
  Float_t ragdet; // Radius of detector (x y plane)
  Int_t first; // first module
  Int_t last; // last module
  Int_t nrecp; //number of RecPoints for a given module

  //List of histograms
  TObjArray histos(26,0);  // contains the pointers to the histograms
  // Book histograms SPD
  TH2F *rspd = new TH2F("rspd","Radii of digits - SPD",50,-10.,10.,50,-10.,10.);
  TH2F *rhspd = new TH2F("rhspd","Radii of hits - SPD",50,-10.,10.,50,-10.,10.);
  TH2F *rmspd = new TH2F("rmspd","Radii of SPD modules",50,-10.,10.,50,-10.,10.);
  TH1F *zspd = new TH1F("zspd","Z of digits - SPD",100,-30.,30.);
  TH1F *zhspd = new TH1F("zhspd","Z of hits - SPD",100,-30.,30.);
  TH1F *zmspd = new TH1F("zmspd","Z of SPD modules",100,-30,30.);

  Char_t title1[50]="";
  Char_t title2[50]="";
  if(userec){ 
    sprintf(title1,"Radii of recpoints - %s","SPD");
    sprintf(title2,"Z of recpoints - %s","SPD");
  }
  if(useclustersv2){
    sprintf(title1,"Radii of clustersV2 - %s","SPD");
    sprintf(title2,"Z of clustersV2 - %s","SPD");
  }
  TH2F *rrspd = new TH2F("rrspd",title1,50,-10.,10.,50,-10.,10.);
  TH1F *zrspd = new TH1F("zrspd",title2,100,-30.,30.);
  TH1F *enespd = new TH1F("enespd","Energy deposition SPD (KeV)",100,0.,1000.);
  histos.AddLast(rspd);  // 0
  histos.AddLast(rhspd); // 1
  histos.AddLast(rmspd); // 2
  histos.AddLast(zspd);  // 3
  histos.AddLast(zhspd); // 4
  histos.AddLast(zmspd); // 5
  histos.AddLast(rrspd); // 6
  histos.AddLast(zrspd); // 7
  histos.AddLast(enespd); // 8
  // Book histograms SDD
  TH2F *rsdd = new TH2F("rsdd","Radii of digits - SDD",50,-40.,40.,50,-40.,40.);
  TH2F *rhsdd = new TH2F("rhsdd","Radii of hits - SDD",50,-40.,40.,50,-40.,40.);
  TH2F *rmsdd = new TH2F("rmsdd","Radii of SDD modules",50,-40.,40.,50,-40.,40.);
  TH1F *zsdd = new TH1F("zsdd","Z of digits - SDD",100,-40.,40.);
  TH1F *zhsdd = new TH1F("zhsdd","Z of hits - SDD",100,-40.,40.);
  TH1F *zmsdd = new TH1F("zmsdd","Z of SDD modules",100,-40,40.);
  Char_t title3[50];
  Char_t title4[50];
  if(userec){ 
    sprintf(title3,"Radii of recpoints - %s","SDD");
    sprintf(title4,"Z of recpoints - %s","SDD");
  }
  if(useclustersv2){
    sprintf(title3,"Radii of clustersV2 - %s","SDD");
    sprintf(title4,"Z of clustersV2 - %s","SDD");
  }
  TH2F *rrsdd = new TH2F("rrsdd",title3,50,-40.,40.,50,-40.,40.);   
  TH1F *zrsdd = new TH1F("zrsdd",title4,100,-40.,40.);
  TH1F *enesdd = new TH1F("enesdd","Energy deposition SDD (KeV)",100,0.,1000.);
  histos.AddLast(rsdd);  // 9
  histos.AddLast(rhsdd); // 10
  histos.AddLast(rmsdd); // 11
  histos.AddLast(zsdd);  // 12
  histos.AddLast(zhsdd); // 13
  histos.AddLast(zmsdd); // 14
  histos.AddLast(rrsdd); // 15
  histos.AddLast(zrsdd); // 16
  histos.AddLast(enesdd); // 17
  // Book histogram SSD
  TH2F *rssd = new TH2F("rssd","Radii of digits - SSD",50,-50.,50.,50,-50.,50.);
  TH2F *rhssd = new TH2F("rhssd","Radii of hits - SSD",50,-50.,50.,50,-50.,50.);
  TH2F *rmssd = new TH2F("rmssd","Radii of SSD modules",50,-50.,50.,50,-50.,50.);
  TH1F *zssd = new TH1F("zssd","Z of digits - SSD",100,-70.,70.);
  TH1F *zhssd = new TH1F("zhssd","Z of hits - SSD",100,-70.,70.);
  TH1F *zmssd = new TH1F("zmssd","Z of SSD modules",100,-70,70.);
  Char_t title5[50];
  Char_t title6[50];
  if(userec){ 
    sprintf(title5,"Radii of recpoints - %s","SSD");
    sprintf(title6,"Z of recpoints - %s","SSD");
  }
  if(useclustersv2){
    sprintf(title5,"Radii of clustersV2 - %s","SSD");
    sprintf(title6,"Z of clustersV2 - %s","SSD");
  }

  TH2F *rrssd = new TH2F("rrssd",title5,50,-50.,50.,50,-50.,50.);
  TH1F *zrssd = new TH1F("zrssd",title6,100,-70.,70.);
  TH1F *enessd = new TH1F("enessd","Energy deposition SSD (KeV)",100,0.,1000.);
  histos.AddLast(rssd);  // 18
  histos.AddLast(rhssd); // 19
  histos.AddLast(rmssd); // 20
  histos.AddLast(zssd);  // 21
  histos.AddLast(zhssd); // 22
  histos.AddLast(zmssd); // 23
  histos.AddLast(rrssd); // 24
  histos.AddLast(zrssd); // 25
  histos.AddLast(enessd); // 26
  //
  // Loop on subdetectors
  // 
  IlcTARGETgeom *geom = TARGET->GetTARGETgeom();
  TString detna; // subdetector name
  for(Int_t subd=0;subd<3;subd++){
    if(All || (choice.Contains("SPD") && subd==0) || (choice.Contains("SDD") && subd==1) || (choice.Contains("SSD") && subd==2)){
      // Prepare array for the digits
      TClonesArray *TARGETdigits  = TARGET->DigitsAddress(subd);
      Bool_t usedigits = kTRUE;
      if(!TARGETdigits){
        usedigits = kFALSE;
        cout<<"\n ======================================================= \n";
        cout<<"WARNING: there are no DIGTARGET on this file ! \n";
        cout<<"======================================================= \n \n";
      }
      // Get segmentation model
      if(subd==0)detna="SPD";
      if(subd==1)detna="SDD";
      if(subd==2)detna="SSD";
      IlcTARGETsegmentation *seg=(IlcTARGETsegmentation*)detTypeRec->GetSegmentationModel(subd);
      // Loop on modules
      first = geom->GetStartDet(subd);
      last = geom->GetLastDet(subd);
      if(verbose){
        cout<<"     "<<endl<<"-------------------------------------"<<endl;
        cout<<"Start processing subdetector "<<detna<<endl;
        cout<<detna<<" first module "<<first<<endl;
        cout<<detna<<" last module "<<last<<endl;
        cout<<" "<<endl<<" "<<endl;
      }
      for (mod=first; mod<=last; mod++){
        geom->GetTrans(mod,pos);  // position of the module in the MRS
        ragdet=sqrt(pos[0]*pos[0]+pos[1]*pos[1]);
        // The following 2 histos are a check of the geometry
        TH2F *bidi = (TH2F*)histos.At(2+subd*9);
        TH1F *uni = (TH1F*)histos.At(5+subd*9);
        bidi->Fill(pos[0],pos[1]);
        uni->Fill(pos[2]);
        if(verbose){
          cout<<"=========================================================\n";
          cout<<detna<<" module="<<mod<<endl;
          cout<<"Mod. coordinates: "<<pos[0]<<", "<<pos[1]<<", ";
          cout<<pos[2]<<" Radius "<<ragdet<<endl;
        }

        // Hits
        GetHitsCoor(TARGET,mod,histos,subd,verbose);

        //RecPoints     
        if(userec){
          detTypeRec->ResetRecPoints();
          branch->GetEvent(mod);
          TH2F *bidi=(TH2F*)histos.At(6+subd*9);
          TH1F *uni=(TH1F*)histos.At(7+subd*9);
          nrecp=GetRecCoor(geom,TARGETrec,mod,bidi,uni,verbose);
        }
        if(useclustersv2){
          detTypeRec->ResetRecPoints();
          branch->GetEvent(mod);
          TH2F *bidi=(TH2F*)histos.At(6+subd*9);
          TH1F *uni=(TH1F*)histos.At(7+subd*9);
          nrecp=GetClusCoor(geom,TARGETrec,mod,bidi,uni,verbose);
	  
        }
     
        // Digits
        if(usedigits){
          detTypeRec->ResetDigits();
          nbytes += TD->GetEvent(mod);
          GetDigits(seg,geom,TARGETdigits,subd,mod,verbose,histos);
        }

      } // End of loop on the modules
      TH1F *h1tmp;
      TH2F *h2tmp;
      //  Plot the histograms
      TCanvas *current=0; // current Canvas (1--> SPD, 2---> SDD, 3---> SSD)
      if(subd==0){
        // Prepare canvas 1
        TCanvas *c1 = new TCanvas("c1","SPD",10,10,600,900);
        c1->Divide(2,3);
        current=c1;
      }
      if(subd==1){
        // Prepare canvas 2
        TCanvas *c2 = new TCanvas("c2","SDD",40,40,600,900);
        c2->Divide(2,3);
        current=c2;
      }
      if(subd==2){
        // Prepare canvas 3
        TCanvas *c3 = new TCanvas("c3","SSD",70,70,600,900);
        c3->Divide(2,3);
        current=c3;
      }
      current->cd(1);
      h2tmp = (TH2F*)histos.At(9*subd);
      h2tmp->Draw();
      current->cd(2);
      h1tmp=(TH1F*)histos.At(3+subd*9);
      h1tmp->Draw();
      current->cd(3);
      h2tmp=(TH2F*)histos.At(1+9*subd);
      h2tmp->Draw();
      current->cd(4);
      h1tmp=(TH1F*)histos.At(4+subd*9);
      h1tmp->Draw();
   
      if(userec || useclustersv2){
        current->cd(5);
        h2tmp=(TH2F*)histos.At(6+9*subd);
        h2tmp->Draw();
        current->cd(6);
        h1tmp=(TH1F*)histos.At(7+subd*9);
        h1tmp->Draw();
      }
  
      else {
        current->cd(5);
        h2tmp=(TH2F*)histos.At(2+9*subd);
        h2tmp->Draw();
        current->cd(6);
        h2tmp=(TH2F*)histos.At(5+9*subd);
        h2tmp->Draw();
      }
    } // if(All.....
  } // end of loop on subdetectors
  // Save the histograms
  TFile *fh = new TFile("IlcTARGETGeoPlot.root","recreate");
  // The list is written to file as a single entry
  TList *lihi = new TList();
  // copy the pointers to the histograms to a TList object.
  // The histograms concerning recpoints are not copied if
  // 'userec' is false.
  for(Int_t i=0;i<histos.GetEntriesFast();i++){
    if(choice.Contains("All") || (choice.Contains("SPD") && i<8) || (choice.Contains("SDD") && i>7 && i<16) || (choice.Contains("SSD") && i>15)){
      if(!(!userec && ((i+2)%9==0 || (i+1)%9==0)))lihi->Add(histos.At(i));
    }
  }
  lihi->Write("Histograms TARGET hits+digits+recpoints",TObject::kSingleKey);
  fh->Close();

  return retcode;
}
Ejemplo n.º 12
0
// -----------------------------------------------------------------------------
// CAknKeyRotatorImpl::GetKeyRotatorCompensationL
// Parses wsini.ini to read key rotator compensation value.
// -----------------------------------------------------------------------------
//
TInt CAknKeyRotatorImpl::GetKeyRotatorCompensationL()
    {
    TInt result = 0;
    HBufC* wsiniText = GetWsiniLC();
    
    // Now look for keyword
    const TInt pos = wsiniText->Find( KAknKeyRotatorKey );
    if ( pos != KErrNotFound )
        {        
        // Keyword was found. Check that it is the beginning of line.
        // Three cases:
        // 1. Keyword could be at the beginning of the file.
        // 2. Keyword could be at the beginning of the file 
        //    after byte ordering marker.
        // 3. Previous character can be end of line marker.
        const TInt previousPos = pos - 1;
        if ( previousPos < 0 || 
             ( !previousPos && 
               IsByteOrderingMarker( (*wsiniText)[ previousPos ] ) ) || 
             IsEndOfLine( (*wsiniText)[ previousPos ] ) )
            {
            TLex text( wsiniText->Mid( pos + KAknKeyRotatorKey().Length() ) );
            
            // First, there must be at least a space after keyword.
            TBool fail = !( SkipSpaces( text ) & EAknWasSpace );
           
            // Case 1: Disabled
            TBool wasDisabled = EFalse;
            if ( !fail )
                {
                wasDisabled = 
                    !text.Remainder().Left( KAknKeyRotatorDisabled().Length() ).
                    CompareF( KAknKeyRotatorDisabled );

                if ( wasDisabled )
                    {
                    // wasDisabled == True, KAknKeyRotatorDisabled was prefix
                    // of text. So skip over it
                    text.Inc( KAknKeyRotatorDisabled().Length() );
                    }
                }
            
            // Case 2: Then follows a sequence of digits, optionally preceded by '-'.
            if ( !wasDisabled && !fail )
                {
                // Check optional -
                TBool negate = EFalse;
                if ( !text.Eos() && text.Peek() == '-' )
                    {
                    negate = ETrue;
                    text.Inc();
                    }
                    
                // Get digit sequence and convert to integer value.
                TPtrC token = GetDigits( text );
                fail = !token.Length() || 
                       ( TLex( token ).Val( result ) != KErrNone );
                
                // Handle negation
                if ( !fail && negate )
                    {
                    result = -result;
                    }
                }

            // That sequence of digits is followed by sequence of spaces until
            // end of line or end of file.
            fail = fail || ( SkipSpaces( text ) & EAknWasCharacter );
            
            if ( !wasDisabled )
                {
                // Finally, that sequence of digits must represent
                // one valid decimal value of the following: 
                // -270, -180, -90, 0, 90, 180, 270.
                fail = fail || !CheckCompensationValue( result );
                }
                
            // If any of above checks failed, use default value 0.
            if ( fail )
                {
                result = 0;
                }
            else
                {
                if ( wasDisabled )
                    {
                    result = KMaxTInt;
                    }
                }
            }
        }
        
    CleanupStack::PopAndDestroy( wsiniText );   
    return result;
    }