Re: Compare TGeoShape

From: Jason Webb <jwebb_at_rcf.rhic.bnl.gov>
Date: Thu, 15 Jul 2010 13:08:32 -0400


Hi Andrei,

I have a factory class which is responsible for creating a related set of volumes within a detector's main volume. That class is supposed to return

+ An existing volume, if the requested shape and medium match the user's specifications

  or

+ A new volume, if the shape or medium does not match any of the existing volumes

One solution is to create the user's requested shape, loop over all volumes and test if the shapes are equal.

The preferred solution would be if I had access to the shape parameters in a flat array. Then I could simply loop over them to make my decision thus

for ( i=0;i<N;i++ ) {
if (shape->GetParam(i)!=user[i]) return new TGeoVolume(..); }

Jason

p.s. My workaround will be to keep a list of parameters in parallel with my volume list.

Andrei Gheata wrote:

> Hi Jason,
> 
> I fully agree that this can be done, but finally why would you need such 
> a check ? The idea in geometry is to replicate whatever you can rather 
> that create shapes with exactly same parameters. If you follow this , 
> the comparison is just a trivial pointer comparison...
> 
> Cheers,
> Andrei
> 
> 
> 
> On 07/15/2010 05:10 PM, Jason Webb wrote:

>> Hi Andrei,
>>
>> Thanks for the reply. I will proceed with my (ugly, error prone,
>> difficult to maintain) work around.
>>
>> However, I think that you are overestimating the effort it would take to
>> implement this functionality. If TGeoShape stored a dynamic array of
>> parameters then the equality method becomes trivial. Just loop over the
>> two arrays and check equality of elements.
>>
>> Such an array could be created and filled with modest effort. 20 shapes,
>> averaging 10 parameters per shape. To store these parameters would take
>> approximately 20 x 10 = 200 lines of code. Double for overhead, 400
>> lines of code. (pcon and pgon being exceptions, but easily handled).
>>
>> Composite shapes should also be easy to handle. Check that the
>> expressions are the same, and if so, check that each of the named shapes
>> are equal.
>>
>> Cheers,
>> Jason
>>
>> Andrei Gheata wrote:
>>> Hi Jason,
>>>
>>> This comparison is not implemented and not in the plan. The reason is
>>> that there are ~20 different shapes and this makes the implementation
>>> effort too big and not scaling with the limited use cases. Besides,
>>> this cannot be implemented for Boolean composite shapes that can be of
>>> infinite variety.
>>>
>>> Best,
>>> Andrei
>>>
>>> On 07/14/2010 11:03 PM, Jason Webb wrote:
>>>> Hi ROOTers,
>>>>
>>>> Is there a simple way to compare two TGeoShapes to each other?
>>>> Specifically I am interested in functionality like
>>>>
>>>> TGeoShape *shape1 = ...
>>>> TGeoShape *shape2 = ...
>>>>
>>>> if ( shape1->IsEqualTo(shape2) )
>>>> {
>>>> std::cout << "same"<<std::endl;
>>>> }
>>>>
>>>> where shape1 and shape2 are any of the TGeo shapes, and the 'IsEqualTo'
>>>> function would return true if they are of the same class and have the
>>>> same parameters.
>>>>
>>>> Thanks,
>>>> Jason
>>>>
>>
Received on Thu Jul 15 2010 - 19:08:58 CEST

This archive was generated by hypermail 2.2.0 : Thu Jul 15 2010 - 23:50:01 CEST